Reputation: 355
i try to implement an DHCP Server in scapy. I sniff with iface="Local Area Connection 3" for udp sport 67 and dport 68 for DHCP Discovers and then sending DHCP Offer with sendp command. I can't see in Wireshark my packet, and DHCP Clinet don`t receive either, it contiunes to send DHCP Discovers.
On wireshark i only see DHCP Discovers from client.
Here is the code:
def sniff_DHCP_discovers():
sniff(filter='port 67 or port 68', prn=startThread, iface="Local Area Connection 3")
def startThread(pkt):
thread = threading.Thread(target=process_DHCP_discover, args=(pkt,))
thread.deamon = True
thread.start()
def process_DHCP_discover(pkt):
print 'Process ', ls(pkt)
if DHCP in pkt:
if pkt[DHCP].options[0][1]==1:
print '\tDetected DHCP Discover from client: ', pkt[Ether].src
#Create DHCP Offer
Ethernet = Ether(src="00:50:B6:0E:FE:36", dst=pkt[Ether].src)
IPo = IP(src="192.168.0.100", dst="255.255.255.255")
UDPo = UDP(sport=67, dport=68)
BOOTPo = BOOTP(op=2, yiaddr="192.168.0.1", siaddr="192.168.0.100", giaddr='0.0.0.0', xid=pkt[BOOTP].xid)
DHCPo = DHCP(options=[('message-type', 'offer'),('subnet_mask',IPv4_ConfigParam.SUBNET_MASK),('server_id', "192.168.0.100"), ('lease_time', 1800),('end')])
pkt_Offer = Ethernet/IPo/UDPo/BOOTPo/DHCPo
sendp(pkt_Offer, iface="Local Area Connection 3")
print 'DHCP Offer sent: ', ls(pkt_Offer)
Upvotes: 2
Views: 2297
Reputation: 355
Managed to view packets in Wireshark. I used srp1() instead, not sendp().
Found another problem now. When i want to simulate an DHCP server, and send DHCP Offer, if i send the offer with BOOTP.op = 2 as it should be, the packet is not sent. I can't see it o wireshark and my DHCP Client don't make any request. If i send DHCP Offer with BOOTP.op = 1, i see the packet on Wireshark, but this is not correct(op=1 is BOOTREQUEST, and op=2 is BOOTREPLY)
Upvotes: 1
Reputation: 6237
Have you tried to simply send packets and see if it works for a start? Is it working? Even with iface="Local Area Connection 3"
?
Anyway, to do what you want, you should use an AnsweringMachine
. Scapy already comes with an implementation, BOOTP_am
, you might want to look at the code; you can use it directly with the Scapy function bootpd()
.
For a start you can just use the bootpd()
with no parameter; the options you can use after (when/if it works) are (with their default values, taken from https://bitbucket.org/secdev/scapy/src/1d36e8fd9df8dfddbb5e9b3819910ace5e21e233/scapy/layers/dhcp.py?at=default#cl-300):
pool=Net("192.168.1.128/25")
network="192.168.1.0/24",gw="192.168.1.1"
domain="localnet"
Upvotes: 2