Python Forum
Python 2.7 RAW sockets: missing and wrong fields in ARP header
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 2.7 RAW sockets: missing and wrong fields in ARP header
#1
Hello, at the beggining I would like to say that I didn't have any experiences with sockets earlier. I am trying to create response ARP packet in python 2.7. I have almost done it, but there's a problem: when I was looking at the packet in wireshark i found out that ARP header is missing sender & target mac and sender & target ip fields. Harware size and protocol size fields are wrong as well. What am I doing wrong? Do I pack data wrongly? Here is source code of the program:

import socket
import struct
import binascii


def formatMAC(mac):
    return mac.lower().replace(':', '')

def sendPacket(packet):
    s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
    s.bind(("wlan0", 0))
    return s.send(packet)

eth_src = formatMAC('A0:88:B4:0A:A5:A8')
eth_dst = formatMAC("18:A6:F7:CF:51:B6")
eth_prt = '0806'

arp_hw_type = '0001'
arp_prt_type = '0800'
arp_hw_size = '0006'
arp_prt_size = "0004"
arp_opcode = '0002'
arp_mac_src = formatMAC('A0:88:B4:0A:A5:A8')
arp_ip_src = '192.168.0.134'
arp_mac_dst = formatMAC('18:A6:F7:CF:51:B6')
arp_ip_dst = '192.168.0.1'

eth_pack = struct.pack("!6s6s2s", binascii.unhexlify(eth_dst), binascii.unhexlify(eth_src), binascii.unhexlify(eth_prt))
arp_pack = struct.pack("2s2s1s1s2s6s4s6s4s",
         binascii.unhexlify(arp_hw_type), 
         binascii.unhexlify(arp_prt_type),
         binascii.unhexlify(arp_hw_size),
         binascii.unhexlify(arp_prt_size),
         binascii.unhexlify(arp_opcode),
         binascii.unhexlify(arp_mac_src),
         socket.inet_aton(arp_ip_src), 
         binascii.unhexlify(arp_mac_dst),
         socket.inet_aton(arp_ip_dst)
         )

packet = eth_pack + arp_pack
print(sendPacket(packet))
Wireshark:
[Image: 8u9el.png]

Thanks.
Reply
#2
See Scapy. You can craft whatever packet you want.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sockets interferring with USB ? epif18 0 2,636 Mar-19-2021, 07:45 PM
Last Post: epif18
  Just learning sockets etc... floatingshed 2 2,335 May-06-2020, 09:37 PM
Last Post: floatingshed
  Quick sockets question... ptrivino 2 2,223 Sep-26-2019, 08:51 PM
Last Post: ptrivino
  Sockets and Sendmail taintedsushi 2 2,339 Sep-02-2019, 12:51 PM
Last Post: venquessa
  Script Conversion 2.7 to 3 (sockets) Pumpernickel 1 2,538 Apr-10-2019, 04:26 PM
Last Post: Pumpernickel
  recive post request from client(browser) python sockets kunz 1 2,791 Dec-13-2018, 12:53 AM
Last Post: kunz
  What sort of things can I write to learn about sockets marienbad 2 2,697 Oct-16-2018, 04:02 PM
Last Post: buran
  unix domain sockets Skaperen 8 4,947 Sep-02-2018, 07:02 PM
Last Post: Skaperen
  file transfer with sockets sinister88 1 6,450 Nov-11-2017, 03:29 PM
Last Post: heiner55
  Trouble with sending raw sockets IronReign 2 4,199 Jun-01-2017, 08:26 AM
Last Post: camp0

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020