You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the latest version 0.12.0, but still have the same issue, here is the code I am using
import struct
from impacket import ImpactDecoder
from impacket import dhcp
import socket
dhcp_packet = b'\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
dhcp_decoder = ImpactDecoder.BootpDecoder()
dhcp_packet_decoded = dhcp_decoder.decode(dhcp_packet)
print(dhcp_packet_decoded)
def construct_dhcp_discover_packet():
# Define the magic cookie and the DHCP options for the packet
magic_cookie = 0x63825363 # Standard DHCP magic cookie
dhcp_options = [
('message-type', 1), # DHCP Discover (message type 1)
('requested-ip', 0xc0a80164), # Requested IP address (192.168.1.100)
]
# Create a DhcpPacket object
dhcp_packet = dhcp.DhcpPacket()
# Set the magic cookie
dhcp_packet.fields['cookie'] = magic_cookie
# Set and pack the DHCP options
dhcp_packet.fields['options'] = dhcp_packet.packOptions(dhcp_options)
# Return the packed packet
return dhcp_packet.fields['options']
# Example usage
packed_dhcp_discover = construct_dhcp_discover_packet()
print(f"Packed DHCP Discover: {packed_dhcp_discover}")
Traceback (most recent call last):
File "/home/youwei/XDiff/Impacket/DHCPOption.py", line 36, in <module>
dhcp_packet_decoded = dhcp_decoder.decode(dhcp_packet)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/ImpactDecoder.py", line 966, in decode
d = dhcp.BootpPacket(aBuffer)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/dhcp.py", line 34, in __init__
structure.Structure.__init__(self, data, alignment)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/structure.py", line 91, in __init__
self.fromString(data)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/structure.py", line 156, in fromString
self[field[0]] = self.unpack(field[1], data[:size], dataClassOrCode = dataClassOrCode, field = field[0])
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/structure.py", line 330, in unpack
return self.unpack(two[0],data)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/structure.py", line 389, in unpack
return unpack(format, data)[0]
struct.error: ('unpack requires a buffer of 128 bytes', 'When unpacking field \'file | 128s="" | b\'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\'[:128]\'')
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/home/youwei/XDiff/Impacket/impacket/tests/ImpactPacket/test_DHCP.py", line 33, in <module>
dhcp_packet_decoded = dhcp_decoder.decode(dhcp_packet)
File "/home/youwei/XDiff/Impacket/impacket/impacket/ImpactDecoder.py", line 966, in decode
d = dhcp.BootpPacket(aBuffer)
File "/home/youwei/XDiff/Impacket/impacket/impacket/dhcp.py", line 34, in __init__
structure.Structure.__init__(self, data, alignment)
File "/home/youwei/XDiff/Impacket/impacket/impacket/structure.py", line 91, in __init__
self.fromString(data)
File "/home/youwei/XDiff/Impacket/impacket/impacket/structure.py", line 156, in fromString
self[field[0]] = self.unpack(field[1], data[:size], dataClassOrCode = dataClassOrCode, field = field[0])
File "/home/youwei/XDiff/Impacket/impacket/impacket/structure.py", line 330, in unpack
return self.unpack(two[0],data)
File "/home/youwei/XDiff/Impacket/impacket/impacket/structure.py", line 389, in unpack
return unpack(format, data)[0]
struct.error: ('unpack requires a buffer of 128 bytes', 'When unpacking field \'file | 128s="" | b\'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\'[:128]\'')
Originally posted by @zmw12306 in #1821
The text was updated successfully, but these errors were encountered: