Apr 29, 2014 at 2:07 PM
Edited Apr 29, 2014 at 2:32 PM
First I'm using Visual Studio 2012 with C# and the Pcap.Net Library.
I try to to forward packets which I captured before.
What I try to do:
- Spoof ARP-Table of my phone.
- Redirect the traffic which normally goes to the gateway to my computer.
- Log the packets.
- Forward them to the gateway.
What I did:
- Spoofing ARP-Table -> works fine.
- Redirect traffic to my PC -> works fine (logically).
- Log the packets to a dumpfile (.pcap) as shown in the tutorial on this site -> works fine (I can open it and read it with wireshark and it looks good).
- Forward the packets to the gateway. -> does not work.
I would like to forward them fluently. So what I did was use the "sendBuffer()" function as shown in the tutorial. So I just read in the .pcap file where all the packet information is saved and try to resend it with this "sendBuffer()" function.
And of course I use the same adapter to do it.
When I capture the traffic with wireshark I can see that my packets don't even get sent.
(I'm also not sure if it works at the same time while I capture the data to the file. Because the code which should forward them need to read the packets from the file.
Isn't there another way?
My code to forward the packets from the .pcap file (the IDE doesn't give me any error):
It's approximately my code, I don't have it available cause I'm not at home. But should be right.
IList<LivePacketDevice> devices = LivePacketDevice.AllLocalMachine;
PacketDevice selectedOutputDevice = devices;
long capLength = new FileInfo(@"E:\CSharp\Pcap\dumpFile.pcap").Length;
bool isSync = true;
OfflinePacketDevice selectedInputDevice = new OfflinePacketDevice(@"E:\CSharp\Pcap\dumpFile.pcap");
using (PacketCommunicator inputCommunicator = selectedInputDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
using (PacketCommunicator outputCommunicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000))
if (inputCommunicator.DataLink != outputCommunicator.DataLink)
tB_Log.Text = tB_Log.Text + Environement.NewLine + "ERROR: Different Datalinks!";
using (PacketSendBuffer sendBuffer = new PacketSendBuffer((uint)capLength))
while (inputCommunicator.ReceivePacket(out packet) == PacketCommunicatorReceiveResult.Ok)
Thank you very much for helping!