我正在尝试从 python 脚本的 libpcap 文件重建网页。我有所有的数据包,所以我想目标是有一个 libpcap 文件作为输入,然后你会找到所有必要的数据包,并以某种方式有一个网页文件作为输出,其中包含该页面的所有图片和数据。谁能让我朝着正确的方向开始。我想我需要 dkpt 和/或 scaPY。
更新1:代码如下! 这是迄今为止我在 Python 中提出的代码。假设从单个 HTTP 会话中获取第一组数据包,该会话以 SYN 和 ACK 标志设置为 1 的数据包开始,并以 FIN 标志设置为 1 的数据包结束。
假设在数据包捕获期间只访问了一个网站,此代码是否会附加重建访问网页所需的所有必要数据包?
假设我拥有所有必要的数据包,我该如何重建网页?
import scaPy
pktList = list() #create a list to store the packets we want to keep
pcap = rdpcap('myCapture.pcap') #returns a packet list with every packet in the pcap
count = 0 #will store the index of the syn-ack packet in pcap
for pkt in pcap: #loops through packet list named pcap one packet at a time
count = count + 1 #increments by 1
if pkt[TCP].flags == 0x12 and pkt[TCP].sport == 80: #if it is a SYN-ACK packet session has been initiated as http
break #breaks out of the for loop
currentPkt = count #loop from here
while pcap[currentPkt].flags&0x01 != 0x01: #while the FIN bit is set to 0 keep loops stop when it is a 1
if pcap[currentPkt].sport == 80 and pcap[currentPkt].dport == pcap[count].dport and pcap[currentPkt].src == pcap[count].src and pcap[currentPkt].dst == pcap[count].dst:
#if the src, dst ports and IP's are the same as the SYN-ACK packet then the http packets belong to this session and we want to keep them
pktList.append(pcap[currentPkt])
#once the loop exits we have hit the packet with the FIN flag set and now we need to reconstruct the packets from this list.
currentPkt = currentPkt + 1