Resending packets

Jan 26, 2011 at 5:24 PM
Edited Jan 26, 2011 at 5:26 PM

Hey Boaz

Im triying to make a man-in-the-middle application but im having a lot of troubles, the only thing that i did fine was sending the arp reply to the target i certanly the target sent to my pc all his packets so the next step is just change the destination mac  and send them again but i think im not sendig well or at least to late = (   

i dont know pretty well witch would be the best methods to recive the packets  and to sendign again, here is my code:

i have this variables correctly assigned:

MacAdress GatewayMac
MacAdress VictimsMac
MacAdress MyDeviceMac

PacketCommunicator cm = Device.Open(LivePacketDevice.DefaultSnapshotLength, PacketDeviceOpenAttributes.Promiscuous, 10)


i set this on the constructor->

cm.SetFilter("ether src " & VictimsMac.ToString & " and ether dst " & MyDeviceMac.ToString)

Cap = new Thread(Recive);
Cap.Priority = ThreadPriority.AboveNormal;

private void Recive()
Packet p;

while (true) {
if (cm.ReceivePacket(p) == PacketCommunicatorReceiveResult.Ok) {
Packet newpacket;
EthernetLayer ELay;
ILayer rest;

ELay = p.Ethernet.ExtractLayer;
ELay.Destination = GatewayMac;
rest = p.Ethernet.Payload.ExtractLayer;
newpacket = PacketBuilder.Build(p.Timestamp, ELay, rest);


i send pings to the gateway from the victims pc and all the packets get lost =(

plz helpp

Jan 28, 2011 at 10:31 AM

Hi  adum

i am having problem to get the arp reply packet   would you share me how u got it

Please share me if you do not mind.

Jan 28, 2011 at 4:00 PM

Hi Adum_264,


First of all, I guess the code isn't C#.

Second, have you checked which part makes the packet get lost? Have you checked that the expected packets are received using Wireshark?

Third, I'm not sure I understand the scenario. Where does the Pcap.Net application sits? Where do you send the packets? Which packets? How are the computers connected?



Jan 31, 2011 at 1:32 AM

Hi wendisa

well i made a class called ArpCatcher that runs in a thread so the application doesn't freeze

the filter of the comunicator is this :    "arp and ether dst  he:re:yo:ur:mac" so on an infinite cycle  and every packet that arrives with that filter is an arp reply  after that i save them on a internal collection i explain you this because my code is a bit extense and is on vb = (  but if you preffer it instead of my explanation  here it is :


   Public Structure ArpEntry
            Dim Ip As IpV4Address
            Dim Mac As MacAddress
  End Structure


Public Class ArpCatcher

        Private Disposed As Boolean = False
        Private Reciver As PacketReciver
        Public ArpEntrys As New List(Of ArpEntry)       

Public Sub New(ByRef Device As OnlineDevice)
            Reciver = New PacketReciver(Device.CreateCommunicator(), New PacketReciveCallback(AddressOf OnRecive), "arp and ether dst " & Device.DeviceMac.ToString)
        End Sub

        Private Sub OnRecive(ByVal paqtes As Queue(Of Packet), ByRef tag As Object)
            Dim tmpPacket As Packet
            Dim Ent As ArpEntry

            While paqtes.Count > 0
                tmpPacket = paqtes.Dequeue
                Ent = New ArpEntry(tmpPacket.Ethernet.Arp.SenderProtocolIpV4Address, tmpPacket.Ethernet.Source)
                For Each p As ArpEntry In ArpEntrys
                    If p.Ip.ToString = Ent.Ip.ToString Then p.Mac = New MacAddress(Ent.Mac.ToString) : Continue While
            End While

        End Sub


    Public Class PacketReciver
        Private Disposed As Boolean = False

        Private qeuquedPackets As New Queue(Of Packet)
        Private Bridge As LivePacketCommunicator
        Private Tread As Threading.Thread
        Private dummyinteger As Integer
        Private handlePacket As HandlePacket
        Private handleRecive As PacketReciveCallback
        Private tag As Object

        Public Sub New(ByRef Bridge As LivePacketCommunicator, ByRef onRecive As PacketReciveCallback, Optional ByVal filter As String = Nothing, Optional ByRef tag As Object = Nothing)
            If ((Bridge Is Nothing) Or (onRecive Is Nothing)) Then Throw New NullReferenceException("Null Arguments are not permited")
            If Not IsNothing(tag) Then Me.tag = tag
            Me.Bridge = Bridge
            If filter IsNot Nothing Then Bridge.SetFilter(filter)
            handleRecive = onRecive
            Tread = New Threading.Thread(AddressOf Recive)
            handlePacket = New HandlePacket(AddressOf ManagePacket)
        End Sub

        Public Sub StartReciving()
        End Sub
        Public Function IsReciving() As Boolean
            Return Tread.IsAlive
        End Function

        Public Sub Recive()
            Bridge.ReceiveSomePackets(dummyinteger, -1, handlePacket)
            If qeuquedPackets.Count > 0 Then handleRecive.Invoke(New Queue(Of Packet)(qeuquedPackets), tag) : qeuquedPackets.Clear()
        End Sub
        Private Sub ManagePacket(ByVal p As Packet)
        End Sub

        Protected Overrides Sub Finalize()
            If Not Disposed Then
                If Tread.IsAlive Then Tread.Abort()
                Disposed = True
            End If
        End Sub

        Public Sub Dispose()
            If Not Disposed Then Finalize()
        End Sub

    End Class






Feb 4, 2011 at 8:14 PM

Hi Adum_264,


I'm sorry, but I still don't understand.

Do you just try to put Arp Entries in you collection?

What exactly doesn't work for you?

Have you tried isolating the problems you're having?



Feb 4, 2011 at 8:27 PM

I forgot to said that i've already resolved this issue , that code was to show wendissa how to do it