Skip to content

Commit

Permalink
Merge branch 'feature/dhcp' of https://github.com/c0d3z3r0/impacket i…
Browse files Browse the repository at this point in the history
…nto c0d3z3r0-feature/dhcp
  • Loading branch information
martinuy committed Jan 12, 2017
2 parents 0ff281f + c8aabf2 commit 9879f1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
34 changes: 30 additions & 4 deletions impacket/ImpactDecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import IP6_Extension_Headers
from cdp import CDP
from Dot11Crypto import RC4
from impacket import wps, eap
from impacket import wps, eap, dhcp
from impacket.dot11 import Dot11WEPData
from impacket import LOG

Expand Down Expand Up @@ -282,8 +282,12 @@ def decode(self, aBuffer):
u = ImpactPacket.UDP(aBuffer)
self.set_decoded_protocol( u )
off = u.get_header_size()
self.data_decoder = DataDecoder()
packet = self.data_decoder.decode(aBuffer[off:])
if u.get_uh_dport() in (67, 68) and u.get_uh_sport() in (67, 68):
self.bootp_decoder = BootpDecoder()
packet = self.bootp_decoder.decode(aBuffer[off:])
else:
self.data_decoder = DataDecoder()
packet = self.data_decoder.decode(aBuffer[off:])
u.contains(packet)
return u

Expand Down Expand Up @@ -975,4 +979,26 @@ class EAPOLDecoder(BaseDecoder):
}
klass = eap.EAPOL
child_key = lambda s, p: p.get_packet_type()


class BootpDecoder(Decoder):
def __init__(self):
pass

def decode(self, aBuffer):
d = dhcp.BootpPacket(aBuffer)
self.set_decoded_protocol( d )
off = len(d.getData())
if dhcp.DhcpPacket(aBuffer[off:])['cookie'] == dhcp.DhcpPacket.MAGIC_NUMBER:
self.data_decoder = DHCPDecoder()
packet = self.data_decoder.decode(aBuffer[off:])
d.contains(packet)
return d

class DHCPDecoder(Decoder):
def __init__(self):
pass

def decode(self, aBuffer):
d = dhcp.DhcpPacket(aBuffer)
self.set_decoded_protocol( d )
return d
18 changes: 9 additions & 9 deletions impacket/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#

from impacket import structure
from impacket.ImpactPacket import ProtocolPacket


class BootpPacket(structure.Structure):
class BootpPacket(ProtocolPacket, structure.Structure):
commonHdr = (
('op','b'),
('htype','b=1'), # 1 = Ether
Expand All @@ -26,13 +26,14 @@ class BootpPacket(structure.Structure):
('sname','64s=""'),
('file','128s=""'))

#def __init__(self, data = None, alignment = 0):
# structure.Structure.__init__(self, data, alignment)
class DhcpPacket(BootpPacket):
def __init__(self, data = None, alignment = 0):
structure.Structure.__init__(self, data, alignment)

class DhcpPacket(ProtocolPacket, structure.Structure):
# DHCP: http://www.faqs.org/rfcs/rfc2131.html
# DHCP Options: http://www.faqs.org/rfcs/rfc1533.html
# good list of options: http://www.networksorcery.com/enp/protocol/bootp/options.htm
MAGIC_NUMBER = 0x63825363
BOOTREQUEST = 1
BOOTREPLY = 2

Expand Down Expand Up @@ -140,10 +141,9 @@ class DhcpPacket(BootpPacket):
('cookie','!L'),
('_options',':=self.packOptions(options)'),
('options','_','self.unpackOptions(_options)'))


#def __init__(self, data = None, alignment = 0):
# BootpPacket.__init__(self, data, alignment)
def __init__(self, data = None, alignment = 0):
structure.Structure.__init__(self, data, alignment)

def packOptions(self, options):
# options is an array of tuples: ('name',value)
Expand Down

0 comments on commit 9879f1b

Please sign in to comment.