This project is read-only.

Resending packets

Jan 26, 2011 at 6:24 PM
Edited Jan 26, 2011 at 6: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;
Cap.Start();

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);

cm.SendPacket(newpacket);
}
}
}

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

plz helpp


Jan 28, 2011 at 11: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.

Coordinator
Jan 28, 2011 at 5: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?

 

Boaz.

Jan 31, 2011 at 2: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)
            Reciver.StartReciving()
        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
                Next
                ArpEntrys.Add(Ent)
            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()
            Tread.Start()
        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()
            Recive()
        End Sub
        Private Sub ManagePacket(ByVal p As Packet)
            qeuquedPackets.Enqueue(p)
        End Sub

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

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

    End Class

 

 

 

 

 

Coordinator
Feb 4, 2011 at 9: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?

 

Boaz.

Feb 4, 2011 at 9:27 PM

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