What direction should I go in(libraries, documents)?
UPDATE
Can someone illustrate how to use winpcap to do the job?
UPDATE 2
How do I verify whether a packet is an HTTP one?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If by “hijack” you meant sniff the packets then what you should do to do it with WinPcap is the following:
Find the device you want to use – See WinPcap tutorial.
Open a device using
pcap_openUse a function that reads packets from the descriptor like
pcap_loopThis will loop until something wrong has happened or the loop was broken using a special method call. It will call the functionPointer for each packet.
In the function pointed implement something that parses the packets, it should look like a
pcap_handler:Now all you have left is to parse the packets that their buffer is in the
const u_char*and their length is in thepcap_pkthdrstructurecaplenfield.Assuming you have HTTP GET over TCP over IPv4 over Ethernet packets, you can:
The rest of the packet should be the HTTP text. The text between the first and second space should be the URI. If it’s too long you might need to do some TCP reconstruction, but most URIs are small enough to fit in one packet.
UPDATE: In code this would look like that (I wrote it without testing it):
You can also filter only HTTP traffic by using creating and setting a BPF. See WinPcap tutorial. You should probably use the filter
"tcp and dst port 80"which would only give you the request your computer sends to the server.If you don’t mind using C#, you can try using Pcap.Net, which would do all that for you much more easily, including the parsing of Ethernet, IPv4 and TCP parts of the packet.