Closed namyunz closed 10 years ago
Packet Reassembling - Wireshark
처음 GET Request의 Ack Number를 Sequence Number로 하여서 데이터를 전송받는다. 전송 받는 패킷 중에 HTTP 패킷의 헤더를 가지는 첫번째 패킷의 Sequence Number는 Ack Number와 0차이를 가진다. 이 성격을 이용해서 첫번째 패킷을 알아낼 수 있다. GET Request는 Flag가 PSH, ACK로 설정되어 있다. 따라서 전송받은 패킷 중에서 PSH와 ACK가 True인 패킷의 Ack값을 일정한 리스트에 저장해놓아 전송받는 패킷의 Seq Num과의 차이를 비교한 후에 위 조건을 만족하는지 확인한다.
foreach (uint element in seqNumbers)
{
if (packet.SequenceNumber - element == 0)
{
return true;
}
}
From Stackoverflow Answer
To extract the HTTP packet from TCP:
You need to collect the tcp packets of the connection as they come in and if the data is fragmented (greater than 1500 bytes) you need to re-assemble the parts in memory. To discover which parts go in what order you need to carefully track the sequence/acknowledgement numbers.
This is a non-trivial thing to accomplish with SharpPcap because you're working with a much lower part of the stack and re-assembling the connection manually.
Wireshark has an interesting article on how to accomplish this in C.
As of right now, SharpPcap doesn't support TCP payload parsing.