cloudflare / boringtun

Userspace WireGuard® Implementation in Rust
BSD 3-Clause "New" or "Revised" License
5.92k stars 397 forks source link

The wireguard_write encryption result is different from the official one #353

Open zxcvbnmkl112 opened 11 months ago

zxcvbnmkl112 commented 11 months ago

Hi!

client: windows 10 server : centos 9

I used wireguard.exe and the allowed IP is 8.8.8.8.When I ping 8.8.8.8, I find that the original ICMP packet size is 60bit. 64bit after being encrypted by wireguard.

企业微信截图_16899020368439 企业微信截图_16899018169422 When I use wireguard_write, I find that it is still 60bit after encryption, and my server is not responding to the package. 企业微信截图_16899037372229

My IP packet processing flow: 1.use windivert to get the IP package (60bit)

  1. changed the sending address of the IP packet to 10.66.66.2 and recalculated the checksum
  2. use wireguard_write to encrypt
  3. udp socket send the result of step 3. Is there anything else I need to do?
zxcvbnmkl112 commented 11 months ago

This is my code about the handshake: 企业微信截图_16899041984883 企业微信截图_16899042328973

企业微信截图_16899042452466 企业微信截图_16899042768453

zxcvbnmkl112 commented 11 months ago

i follow this step . https://www.ntkernel.com/boringtun-based-wireguard-client-for-windows/

alanesmizi commented 11 months ago

It could be related to the size of the packet not being 100% Wireguard spec:

https://github.com/cloudflare/boringtun/blob/18eaf59c9c9718850c63e1c82ba933e09224d3dd/boringtun/src/noise/mod.rs#L141

encrypted_static: &src[40..88], // SIZE u8;32, 88-40 = 48 bytes, seems too big for the spec (32) encrypted_timestamp: &src[88..116], // SIZE u8;12, 116-88 = 28 bytes, seems too big for the spec (12)

zxcvbnmkl112 commented 11 months ago

It could be related to the size of the packet not being 100% Wireguard spec:

https://github.com/cloudflare/boringtun/blob/18eaf59c9c9718850c63e1c82ba933e09224d3dd/boringtun/src/noise/mod.rs#L141

encrypted_static: &src[40..88], // SIZE u8;32, 88-40 = 48 bytes, seems too big for the spec (32) encrypted_timestamp: &src[88..116], // SIZE u8;12, 116-88 = 28 bytes, seems too big for the spec (12)

Is there something wrong with my handshake data? How do I deal with this? Thank you for your reply。 企业微信截图_16901664847924 企业微信截图_16901664951175

alanesmizi commented 11 months ago

I am afraid you need to do the analysis yourself. It may be related to handshake field length, but this is for you to find out...