Python スクリプトの libpcap ファイルから Web ページを再構築しようとしています。私はすべてのパケットを持っているので、目標は入力としてlibpcapファイルを持ち、必要なすべてのパケットを見つけて、そのページからのすべての写真とデータを含むWebページファイルを出力することだと思います。誰かが私を正しい方向に始めさせることができますか? dkpt や scaPY が必要になると思います。
更新 1: コードは以下のとおりです。 Pythonでこれまでに思いついたコードは次のとおりです。SYN フラグと ACK フラグが 1 に設定されたパケットで始まり、FIN フラグが 1 に設定されたパケットで終わる単一の HTTP セッションから、最初のパケット セットを取得することを想定しています。
パケット キャプチャ中に訪問した Web サイトが 1 つだけであると仮定すると、このコードは、訪問した Web ページを再構築するために必要なすべてのパケットを追加しますか?
必要なパケットがすべて揃っていると仮定して、Web ページを再構築するにはどうすればよいですか?
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