DHCPShock icon indicating copy to clipboard operation
DHCPShock copied to clipboard

This line is giving "TypeError: sequence item 0: expected a bytes-like object, str found" and "TypeError: encoding without a string argument" error in python 3.6.8. Could you please check it?

Open shamiul94 opened this issue 5 years ago • 1 comments

https://github.com/byt3bl33d3r/DHCPShock/blob/b2bb59dd525b146d693571daec037922e34a1f65/dhcpshock.py#L60

The error goes like this.

[*] Got dhcp REQUEST from: a4:50:46:7c:12:91 xid: 0x84d40287
[*] Sending ACK...
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/scapy/compat.py", line 117, in raw
    return bytes(x)
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 441, in __bytes__
    return self.build()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 556, in build
    p = self.do_build()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 541, in do_build
    pay = self.do_build_payload()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 528, in do_build_payload
    return self.payload.do_build()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 541, in do_build
    pay = self.do_build_payload()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 528, in do_build_payload
    return self.payload.do_build()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 541, in do_build
    pay = self.do_build_payload()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 528, in do_build_payload
    return self.payload.do_build()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 541, in do_build
    pay = self.do_build_payload()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 528, in do_build_payload
    return self.payload.do_build()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 538, in do_build
    pkt = self.self_build()
  File "/usr/local/lib/python3.6/dist-packages/scapy/packet.py", line 519, in self_build
    p = f.addfield(self, p, val)
  File "/usr/local/lib/python3.6/dist-packages/scapy/fields.py", line 905, in addfield
    return s + self.i2m(pkt, val)
  File "/usr/local/lib/python3.6/dist-packages/scapy/layers/dhcp.py", line 307, in i2m
    onum, oval = name, b"".join(lval)
TypeError: sequence item 0: expected a bytes-like object, str found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "dhcp_listener.py", line 214, in <module>
    sniff(iface="wlo1", filter="udp and (port 67 or 68)", prn=handle_dhcp_packet)
  File "/usr/local/lib/python3.6/dist-packages/scapy/sendrecv.py", line 886, in sniff
    r = prn(p)
  File "dhcp_listener.py", line 164, in handle_dhcp_packet
    sendp(new_packet, iface="wlo1")
  File "/usr/local/lib/python3.6/dist-packages/scapy/sendrecv.py", line 328, in sendp
    verbose=verbose, realtime=realtime, return_packets=return_packets)  # noqa: E501
  File "/usr/local/lib/python3.6/dist-packages/scapy/sendrecv.py", line 287, in __gen_send
    s.send(p)
  File "/usr/local/lib/python3.6/dist-packages/scapy/arch/linux.py", line 494, in send
    return SuperSocket.send(self, x)
  File "/usr/local/lib/python3.6/dist-packages/scapy/supersocket.py", line 47, in send
    sx = raw(x)
  File "/usr/local/lib/python3.6/dist-packages/scapy/compat.py", line 119, in raw
    return bytes(x, encoding="utf8")
TypeError: encoding without a string argument

I can't figure out the problem here. If I remove that particular line from the dhcp_ack() function, it runs. I don't know if it's specific to the format of DHCP ACK packets or not. I can't understand the purpose of this line. Could you please let me know? Thank you.

shamiul94 avatar Aug 03 '19 13:08 shamiul94

Update: If I change the line to this -

(114, b"() { ignored;}; " + b"{command}")

then it runs. I still don't know if it's ruining the format of DHCP ACK packets inside. It would be a great help if you could clear it. I am a newbie, so my question might look stupid. Sorry for that.

shamiul94 avatar Aug 03 '19 13:08 shamiul94