使用 scapy 進行流量監控。html
python3 -m pip install scapy
#!/usr/bin/env python
# _*_ Coding: UTF-8 _*_
from scapy.all import *
def capture(x):
if b'HTTP/' in x.lastlayer().original and x.lastlayer().original[0:4] != b'HTTP':
print('dst ip:', x.payload.dst)
print('request body:', x.lastlayer().original)
def main():
sniff(filter="tcp", prn=lambda x: capture(x))
if __name__ == '__main__':
main()
複製代碼
sniff(filter="tcp", prn=lambda x: capture(x))
python
count
捕獲數量, 設置爲 0
時則持續捕獲store
數據包處理:1
保存, 0
丟棄offline
從 pcap 文件中讀取數據包, 而不進行嗅探, 默認爲 None
prn
回調函數filter
過濾規則, 使用 winreshark 語法L2socket
使用給定的 L2socket
timeout
在給定的事件後中止嗅探, 默認爲 None
opened_socket
對指定的對象使用 .recv
進行讀取stop_filter
定義捕獲到指定數據的中止函數iface
指定抓包的網卡, 默認表明全部網卡capture(x)
web
x
對象是一個 scapy.layers.l2.Ether
的實例對象if
語句中使用了字符判斷的釋放過濾了 HTTP
的請求dst ip: 192.168.1.1
request body: b'GET / HTTP/1.1\r\nHost: 192.168.1.1\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: zh-CN,zh;q=0.9\r\nCookie: ysrc_token=a0acd4c5f569632400e36c677fc9b0f9; csrftoken=tfxBYYQZGqw7HockaN93cGEVtN9zoJlJq5nYemwSlBi2CJvpuZ7UAJ8c81Nm46CD; auth=Z3Vlc3Q6Z3Vlc3Q%3D; m=34e2:|c01:t\r\nIf-None-Match: "5ee84cf2-1fe"\r\nIf-Modified-Since: Tue, 16 Jun 2020 04:39:14 GMT\r\n\r\n'
複製代碼
今天你進步了嗎?windows