This project is read-only.

ARP request : total recon

Nov 8, 2011 at 7:33 PM

Hello =) A question about ARP packet building: how do I exactly build a package and send it over PacketDevice?

For example:

Firstly, I should select a device which to open:

private LivePacketDevice currentDevice;
/* something */
IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
/* something */
currentDevice = allDevices[SomeComboBoxWithDevicesListed.SelectedIndex];

Secondly, I should obtain an senderMAC:
private MacAddress senderMac = MacAddress.Zero;
/* something */
senderMAC = LivePacketDeviceExtensions.GetMacAddress(currentDevice);

Thirdly, I should obtain an senderIP:
private IpV4Address senderIP = IpV4Address.Zero;
/* something */
if (currentDevice.Addresses.Count > 0) SomeLabelWithSenderIP.Text = device.Addresses[0].Address.ToString();
/* something */
char[] digits = {'0', '1', '2'};
if (!string.IsNullOrEmpty(SomeLabelWithSenderIP.Text)) { 
	// using  string.Substring () function because the specified IP looks like "internet" or smth like that 
	senderIP = new IpV4Address(SomeLabel.Text.Substring(SomeLabel.Text.IndexOfAny(digits), SomeLabel.Text.Length - SomeLabel.Text.IndexOfAny(digits)));  

Ok, I have to set targetMAC and targetIP in similar way:
private IpV4Address targetIP = IpV4Address.Zero;
private MacAddress targetMac = MacAddress.Zero;
/* something */
targetIP = new IpV4Address(SomeLabelWithTargetIP.Text);
targetMAC = new MacAddress("ff:ff:ff:ff:ff:ff");

After this I should create a new instance of ArpLayer:
var arplayer = new ArpLayer {
	Operation = ArpOperation.Request, 
	ProtocolType = EthernetType.Arp

And then? How do I exactly convert senderMAC to SenderHardwareAddress (MacAddress to ReadOnlyCollection<byte>) and senderIP to SenderProtocolAddress (IpV4Address to ReadOnlyCollection<byte>)? Are there any functions to do that in PCap .NET library? 

After convertion being done, I guess, I should perform similar operations with TargetHardwareAddress and TargetProtocolAddress. Can you please show me how to convert? Give me an example of code, or function prototypes or anything that will allow me to send a custom ARP request?

After successful building a packet with PacketBuilder, apparently, I should open selected device, receive of PacketCommunicator class, and send the packet using function from the specified class?

Packet packet = PacketBuilder.Build (DateTime.Now, ethlayer, arplayer);
if (packet.IsValid) { 
	PacketCommunicator communicator = currentadapter.Open();
	//some try-catch here 

Something like that?

Nov 8, 2011 at 10:01 PM

Now I found the answer =)

Excuse me & my English =)