Created
May 31, 2024 16:09
-
-
Save suuhm/f84413a1260fa7ae9d16ea2add2984ae to your computer and use it in GitHub Desktop.
UDP Hole Punching PoC for bash
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
#!/bin/bash | |
# | |
# UDP PUNCH-OUT! UDP-HOLE PUNCHING | |
# --------------------------------- | |
# | |
# local send: From: 1.1.1.1:13337 -> remote-ip:RANDOM | |
# remote send: From: remote-ip:RANDOM -> 1.1.1.1:13337 | |
# | |
_use_udp_hp() | |
{ | |
#SPORT= port to open local | |
#DPORT= Random UDP ports on remote (shouln't be in use) | |
SPORT=13337 | |
RANGE=$((64000-4097)) | |
DPORT=$(($(($RANDOM%$RANGE))+4097)) | |
if [ "$1" == "local-bhfw" ]; then | |
REMOTEHOST=$2 | |
#Local | |
#get_remoteIP() | |
LRIP=$(curl -s http://ifconfig.co) | |
echo;echo "[*] User on Remote side, ExtIP: $LRIP $DPORT" | |
#set hping3 (-2 UDP packets) | |
# hping3 -c 1 -2 -s $SPORT -p $DPORT $REMOTEHOST | |
nping --udp -c 1 --source-port $SPORT --dest-port $DPORT $REMOTEHOST | |
#set nc on localside: | |
nc -u -l -p $SPORT | |
elif [ "$1" == "remote-nofw" ]; then | |
PUNCHPORT=$3 | |
LRIP=$2 | |
#set on remote side (openports UDP) | |
echo; echo "Got the punch in ur face" | nc -p $PUNCHPORT -u $LRIP $SPORT | |
else | |
echo; echo "[!] Error no input , exit now.." | |
exit 1 | |
fi | |
} | |
echo "^------------------------------------^" | |
echo "^ UDP PUNCH-OUT v0.1 (c) 2022 suuhm ^" | |
echo "^------------------------------------^" | |
echo | |
echo "Usage: $0 local-bhfw <REMOTE_IP>|remote-nofw <LO_EXT_IP> <PUNCH_PORT>" | |
echo | |
echo "!!! Needs netcat and / or hping , nping (nmap suite) !!!" | |
echo "!!! ----------------------------------------------------------------- !!!" | |
echo "!!! Run the script 1st on localhost with NAT fw, later than on remote !!!" | |
echo; sleep 1 | |
_use_udp_hp $1 $2 $3 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment