์ข์ ์๊ฐ!
์ด ๊ธ์์๋ ์ ๊ฐ ์ด๋ป๊ฒ ๊ตฌํํ๋์ง ์๋ ค๋๋ฆฌ๊ณ ์ถ์ต๋๋ค.
์ฐ๊ฒฐ ์ค์ ์ ์ฌ๋ฌ ๋จ๊ณ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค.
- ๋ ธ๋๋ฅผ ์์ํ๊ณ ์๊ฒฉ ๋ ธ๋๊ฐ ์ค๋น๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฝ๋๋ค.
- ์ธ๋ถ IP ์ฃผ์์ UDP ํฌํธ๋ฅผ ๊ฒฐ์ ํฉ๋๋ค.
- ์ธ๋ถ IP ์ฃผ์์ UDP ํฌํธ๋ฅผ ์๊ฒฉ ํธ์คํธ๋ก ์ ์กํฉ๋๋ค.
- ์๊ฒฉ ํธ์คํธ๋ก๋ถํฐ ์ธ๋ถ IP ์ฃผ์์ UDP ํฌํธ๋ฅผ ์ป์ต๋๋ค.
- IPIP ํฐ๋ ๊ตฌ์ฑ
- ์ฐ๊ฒฐ ๋ชจ๋ํฐ๋ง;
- ์ฐ๊ฒฐ์ด ๋์ด์ง๋ฉด IPIP ํฐ๋์ ์ญ์ ํ์ธ์.
์ค๋ซ๋์ ์๊ฐํ์ง๋ง ๋ ธ๋ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๊ตํํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ ๊ฒ์ด ํ์ฌ๋ก์๋ ๊ฐ์ฅ ๊ฐ๋จํ๊ณ ๋น ๋ฅธ ๊ฒ์ด Yandex.disk๋ฅผ ํตํด ์์ ํ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
- ์ฒซ์งธ, ์ฌ์ฉํ๊ธฐ ์ฝ์ต๋๋ค. ์์ฑ, ์ฝ๊ธฐ, ์ญ์ ์ 3๊ฐ์ง ์์
์ด ํ์ํฉ๋๋ค. ์ปฌ์ ์ฌ์ฉํ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์ฐฝ์กฐํ๋ค:curl -s -X MKCOL --user "$usename:$password" https://webdav.yandex.ru/$folder
์ฝ๋ค:
curl -s --user "$usename:$password" -X PROPFIND -H "Depth: 1" https://webdav.yandex.ru/$folder
์ญ์ :
curl -s -X DELETE --user "$usename:$password" https://webdav.yandex.ru/$folder
- ๋์งธ, ์ค์น๊ฐ ์ฝ์ต๋๋ค.
apt install curl
์ธ๋ถ IP ์ฃผ์์ UDP ํฌํธ๋ฅผ ํ์ธํ๋ ค๋ฉด stun-client ๋ช ๋ น์ ์ฌ์ฉํ์ญ์์ค.
stun stun.sipnet.ru -v -p $1 2>&1 | grep "MappedAddress"
๋ช ๋ น์ผ๋ก ์ค์น:
apt install stun-client
ํฐ๋์ ๊ตฌ์ฑํ๋ ค๋ฉด iproute2 ํจํค์ง์ ํ์ค OS ๋๊ตฌ๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. ์กด์ฌํ๋ค
โ FOU ๋ชจ๋์ ๋ก๋ํฉ๋๋ค:
modprobe fou
โ ๋ก์ปฌ ํฌํธ๋ฅผ ์์ ํฉ๋๋ค.
ip fou add port $localport ipproto 4
โ ํฐ๋์ ์์ฑํฉ๋๋ค:
ip link add name fou$name type ipip remote $remoteip local $localip encap fou encap-sport $localport encap-dport $remoteport
โ ํฐ๋ ์ธํฐํ์ด์ค๋ฅผ ์ฌ๋ฆฝ๋๋ค.
ip link set up dev fou$name
โ ํฐ๋์ ๋ด๋ถ ๋ก์ปฌ ๋ฐ ๋ด๋ถ ์๊ฒฉ IP ์ฃผ์๋ฅผ ํ ๋นํฉ๋๋ค.
ip addr add $intIP peer $peerip dev fou$name
ํฐ๋ ์ญ์ :
ip link del dev fou$name
ip fou del port $localport
๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ์๊ฒฉ ๋ ธ๋ ํฐ๋์ ๋ด๋ถ IP ์ฃผ์๋ฅผ ์ฃผ๊ธฐ์ ์ผ๋ก pingํ์ฌ ํฐ๋ ์ํ๋ฅผ ๋ชจ๋ํฐ๋งํฉ๋๋ค.
ping -c 1 $peerip -s 0
์ฃผ๋ก ์ฑ๋์ ์ ์งํ๋ ค๋ฉด ์ ๊ธฐ์ ์ธ ping์ด ํ์ํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ํฐ๋์ด ์ ํด ์ํ์ผ ๋ ๋ผ์ฐํฐ์ NAT ํ ์ด๋ธ์ด ์ง์์ง๊ณ ์ฐ๊ฒฐ์ด ๋์ด์ง ์ ์์ต๋๋ค.
ํ์ด ์ฌ๋ผ์ง๋ฉด IPIP ํฐ๋์ด ์ญ์ ๋๊ณ ์๊ฒฉ ํธ์คํธ๊ฐ ์ค๋น๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฝ๋๋ค.
์คํฌ๋ฆฝํธ ์์ฒด:
#!/bin/bash
username="[email protected]"
password="password"
folder="vpnid"
intip="10.0.0.1"
localport=`shuf -i 10000-65000 -n 1`
cid=`shuf -i 10000-99999 -n 1`
tid=`shuf -i 10-99 -n 1`
function yaread {
curl -s --user "$1:$2" -X PROPFIND -H "Depth: 1" https://webdav.yandex.ru/$3 | sed 's/></>n</g' | grep "displayname" | sed 's/<d:displayname>//g' | sed 's/</d:displayname>//g' | grep -v $3 | grep -v $4 | sort -r
}
function yacreate {
curl -s -X MKCOL --user "$1:$2" https://webdav.yandex.ru/$3
}
function yadelete {
curl -s -X DELETE --user "$1:$2" https://webdav.yandex.ru/$3
}
function myipport {
stun stun.sipnet.ru -v -p $1 2>&1 | grep "MappedAddress" | sort | uniq | awk '{print $3}' | head -n1
}
function tunnel-up {
modprobe fou
ip fou add port $4 ipproto 4
ip link add name fou$7 type ipip remote $1 local $3 encap fou encap-sport $4 encap-dport $2
ip link set up dev fou$7
ip addr add $6 peer $5 dev fou$7
}
function tunnel-check {
sleep 10
pings=0
until [[ $pings == 4 ]]; do
if ping -c 1 $1 -s 0 &>/dev/null;
then echo -n .; n=0
else echo -n !; ((pings++))
fi
sleep 15
done
}
function tunnel-down {
ip link del dev fou$1
ip fou del port $2
}
trap 'echo -e "nDisconnecting..." && yadelete $username $password $folder; tunnel-down $tunnelid $localport; echo "IPIP tunnel disconnected!"; exit 1' 1 2 3 8 9 14 15
until [[ -n $end ]]; do
yacreate $username $password $folder
until [[ -n $ip ]]; do
mydate=`date +%s`
timeout="60"
list=`yaread $username $password $folder $cid | head -n1`
yacreate $username $password $folder/$mydate:$cid
for l in $list; do
if [ `echo $l | sed 's/:/ /g' | awk {'print $1'}` -ge $(($mydate-65)) ]; then
#echo $list
myipport=`myipport $localport`
yacreate $username $password $folder/$mydate:$cid:$myipport:$intip:$tid
timeout=$(( $timeout + `echo $l | sed 's/:/ /g' | awk {'print $1'}` - $mydate + 3 ))
ip=`echo $l | sed 's/:/ /g' | awk '{print $3}'`
port=`echo $l | sed 's/:/ /g' | awk '{print $4}'`
peerip=`echo $l | sed 's/:/ /g' | awk '{print $5}'`
peerid=`echo $l | sed 's/:/ /g' | awk '{print $6}'`
if [[ -n $peerid ]]; then tunnelid=$(($peerid*$tid)); fi
fi
done
if ( [[ -z "$ip" ]] && [ "$timeout" -gt 0 ] ) ; then
echo -n "!"
sleep $timeout
fi
done
localip=`ip route get $ip | head -n1 | sed 's|.*src ||' | cut -d' ' -f1`
tunnel-up $ip $port $localip $localport $peerip $intip $tunnelid
tunnel-check $peerip
tunnel-down $tunnelid $localport
yadelete $username $password $folder
unset ip port myipport
done
exit 0
๋ณ์๋ค ์ฌ์ฉ์ ์ด๋ฆ, ์ํธ ะธ ํด๋ ์์ชฝ์ด ๋์ผํด์ผ ํ์ง๋ง ์ธํ - ๋ค๋ฆ ๋๋ค(์: 10.0.0.1 ๋ฐ 10.0.0.2). ๋ ธ๋์ ์๊ฐ์ ๋๊ธฐํ๋์ด์ผ ํฉ๋๋ค. ๋ค์๊ณผ ๊ฐ์ด ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ ์ ์์ต๋๋ค.
nohup script.sh &
ํธ๋ํฝ์ด ์ํธํ๋์ง ์๋๋ค๋ ์ ์์ IPIP ํฐ๋์ ์์ ํ์ง ์๋ค๋ ์ ์ ์๋ ค๋๋ฆฌ๊ณ ์ถ์ง๋ง ์ด๋ IPsec over๋ฅผ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ํด๊ฒฐํ ์ ์์ต๋๋ค.
์ ๋ ์ด ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋ช ์ฃผ ๋์ ์ ๋ฌด์ฉ PC์ ์ฐ๊ฒฐํด ์์ง๋ง ์๋ฌด๋ฐ ๋ฌธ์ ๋ ๋ฐ๊ฒฌํ์ง ๋ชปํ์ต๋๋ค. ์ค์ ํ๊ณ ์์ด๋ฒ๋ฆฌ๋ ์ ์์ ํธ๋ฆฌํฉ๋๋ค.
์๋ง๋ ๋น์ ์ ์๊ฒฌ๊ณผ ์ ์์ ๊ฐ์ง๊ณ ์์ ๊ฒ์ ๋๋ค. ๋๋ ๊ธฐ๊บผ์ด ๋ฃ๊ฒ ์ต๋๋ค.
๊ฐ์ฌํฉ๋๋ค!
์ถ์ฒ : habr.com