-
-
Save jvns/552e6d5e6fec6c3ddf2fcd4ccdab45d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sets up a tun/tap device on Linux | |
sudo ip tuntap add name tun0 mode tun user $USER | |
sudo ip link set tun0 up | |
sudo ip addr add 192.0.2.1 peer 192.0.2.2 dev tun0 | |
sudo iptables -t nat -A POSTROUTING -s 192.0.2.2 -j MASQUERADE | |
sudo iptables -A FORWARD -i tun0 -s 192.0.2.2 -j ACCEPT | |
sudo iptables -A FORWARD -o tun0 -d 192.0.2.2 -j ACCEPT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sends a SYN packet to `example.com` | |
import struct | |
from fcntl import ioctl | |
def openTun(tunName): | |
tun = open("/dev/net/tun", "r+b", buffering=0) | |
LINUX_IFF_TUN = 0x0001 | |
LINUX_IFF_NO_PI = 0x1000 | |
LINUX_TUNSETIFF = 0x400454CA | |
flags = LINUX_IFF_TUN | LINUX_IFF_NO_PI | |
ifs = struct.pack("16sH22s", tunName, flags, b"") | |
ioctl(tun, LINUX_TUNSETIFF, ifs) | |
return tun | |
syn = b'E\x00\x00,\x00\x01\x00\x00@\x06\x00\xc4\xc0\x00\x02\x02"\xc2\x95Cx\x0c\x00P\xf4p\x98\x8b\x00\x00\x00\x00`\x02\xff\xff\x18\xc6\x00\x00\x02\x04\x05\xb4' | |
tun = openTun(b"tun0") | |
tun.write(syn) | |
reply = tun.read(1024) | |
print(repr(reply)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment