def SaveTx(self, rawpkt, lif): if rawpkt is None: return logger.info("Saving TX Packet of Length:%d on Lif:%s to PCAP" %\ (len(rawpkt), lif.GID())) key = lif.GID() self.__init_db_entry(key) spobj = scapyfactory.Parse(rawpkt) self.pktsdb[key].append(spobj.GetScapyPacket()) return
def __init__(self, pktid, rawpkt, ports = None): self.ports = ports self.rawpkt = rawpkt self.pktlen = len(rawpkt) self.hdrs = [] self.hdrnames = [] self.spktobj = scapyfactory.Parse(rawpkt) self.spkt = self.spktobj.spkt self.pktid = pktid self.__build_hdr_stack() self.nhdrs = len(self.hdrs) return
def Read(self): """ Reads a Buffer from Host Memory :return: """ if not self._mem: return self.data logger.info("Read %s" % self) self.data = self.hostmemmgr.read(self._mem, self.size) logger.info("=" * 30, "READ BUFFER", "=" * 30) scapyfactory.Parse(self.data).Show() logger.info("=" * 30, "END READ BUFFER", "=" * 30) return self.data
def Write(self): """ Writes the buffer to Host Memory :return: """ if not self._mem: return logger.info("Writing %s" % self) if self.data is None: self.hostmemmgr.zero(self._mem, self.size) else: logger.info("=" * 30, "WRITING BUFFER", "=" * 30) scapyfactory.Parse(self.data).Show() self.hostmemmgr.write(self._mem, bytes(self.data)) logger.info("=" * 30, "END WRITING BUFFER", "=" * 30)
import infra.engine.comparators as crs import infra.factory.scapyfactory as scapyfactory from infra.penscapy.penscapy import * from infra.common.logging import logger logger.SetLoggingLevel(7) rawbytes = [1] * 32 dolbytes = [0xFF] * 20 bnr = '-' * 20 pd = PENDOL() crc = CRC() #apkt = Ether()/IP()/TCP()/Raw(bytes(rawbytes)) apkt = Ether() / IP() / TCP() apbytes = bytes(apkt) print("%s ORIGINAL PACKET %s" % (bnr, bnr)) parsed_apkt = scapyfactory.Parse(apbytes) parsed_apkt.Show(logger) crc.crc = binascii.crc32(apbytes + bytes(pd)) print("%s WIRE PACKET %s" % (bnr, bnr)) #pdbytes = bytes(pd) + (crc.crc).to_bytes(4) pdbytes = bytes(pd) + struct.pack("I", crc.crc) (crc.crc).to_bytes(4, byteorder='little') allbytes = apbytes + pdbytes epkt = scapyfactory.Parse(allbytes) epkt.Show(logger)