#!/usr/bin/python from structx.packetlib import Byte, StringSZ, Enum, ShortBE, BasePacketClass, AttrList,\ Int, DynamicAttrClass, ArrayAttr, Short, IntBE, Flags, Quad import random from warnings import warn import struct class MacAddr(StringSZ): size=6 def _init_new(self,data): if len(data)!=6: data=''.join([chr(int(x,16)) for x in data.split(':')]) StringSZ._init_new(self,data) def _repr(self): return ':'.join(["%02x"%(ord(x)) for x in self.value]) IPProto=Enum.mk("IP ICMP IGMP", Byte, TCP=6, UDP=17, IPV6=41, IPV6Route=43, IPV6Frag=44, ESP=50, AH=51, IPV6ICMP=58) class IPAddr(StringSZ): size=4 def _init_new(self,data): if len(data)!=4: data=''.join([chr(int(x)) for x in data.split('.')]) StringSZ._init_new(self,data) def _repr(self): return '.'.join(["%d"%(ord(x)) for x in self.value]) ArpOp=Enum.mk("? REQ REPL",ShortBE,"ArpOp") EType=Enum.mk("",ShortBE,"EType",ARP=0x806,IP=0x800, VLanQ=0x8100) class ARP(BasePacketClass): _fields_=AttrList( ('hwtype',ShortBE),("prottype",EType), ("hwsize",Byte),("protsize",Byte), ("opcode",ArpOp),
#!/usr/bin/python from structx.packetlib import BasePacketClass, AttrList, ShortBE, StringSZ, Enum, Byte, cached_property, ArrayAttr AJPDataType = Enum.mk("? ? Req RespBody RespHdr RespEnd", Byte, "AJPDataType") AJPMethod = Enum.mk("? ? GET", Byte, "AJPMethod") AJPHeaderType = Enum.mk("Unknown", ShortBE, Authorization=0xA005, UserAgent=0xA00E, Host=0xA00B, Accept=0xA001) class AJPShortString(BasePacketClass): _fields_ = AttrList(("data_size", Byte), ("data", StringSZ), "\x00") class AJPString(StringSZ): def _init_new(self, data): if data is not None: self.value = data def _init_parse(self, data, data_offset, data_size): self.vsize = ShortBE(data, data_offset) if self.vsize.value == 0xFFFF: return if data_size is not None and self.vsize.value > (data_size - 3): raise ValueError("Data size mismatch: %d+3 > %d" % (self.vsize.value, data_size)) if data[data_offset + self.vsize.value + 2] != "\x00": raise ValueError("Data does not terminate with null byte") self.value = data[data_offset + 2 : data_offset + 2 + self.vsize.value] def __len__(self): try: val = self.value