Coder Social home page Coder Social logo

Comments (4)

sander1234567890 avatar sander1234567890 commented on May 24, 2024

Hmm it seems it's not looking at the first 4 bytes of the pcap, for this run i got:
bad magic: b'T\xe8\xc2\xdb'

While the pcap has:
00000000h: A1 B2 C3 D4 00 02 00 04 00 00 00 00 00 00 00 00 ; ¡²ÃÔ............
00000010h: 00 00 FF FF 00 00 00 7F 54 E8 C2 DB 00 01 24 6A ; ..ÿÿ...�TèÂÛ..$j

What happens is that in: scapy/utils.py:537 RawPcapReader()
It does this:
try:
self.f = gzip.open(filename,"rb")
magic = self.f.read(4)
except IOError:
self.f = open(filename,"rb")
magic = self.f.read(4)

Problem is that gzip.open, to detect if it is actually a gzip, consumes what it expects to be the header.
Since i'm trying to read from a pipe/stream, it's not seekable .. so the consumed header is gone .. and the next 4 bytes are read from the next part of the stream.

Edit:
However the python2 scapy code seems to be the same ..

from kamene.

sander1234567890 avatar sander1234567890 commented on May 24, 2024

Whoops accidently closed it .. sorry

from kamene.

phaethon avatar phaethon commented on May 24, 2024

On python2.7 gzip.open when reading from named pipe generates different exception even before reading 4 bytes:

Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/gzip.py", line 261, in read
self._read(readsize)
File "/usr/lib/python2.7/gzip.py", line 288, in _read
pos = self.fileobj.tell() # Save current position
IOError: [Errno 29] Illegal seek

from kamene.

phaethon avatar phaethon commented on May 24, 2024

I changed utils.py code to:
try:
if not stat.S_ISREG(os.stat(filename).st_mode):
raise IOError("GZIP detection works only for regular files")
self.f = gzip.open(filename,"rb")
magic = self.f.read(4)
except IOError:
self.f = open(filename,"rb")
magic = self.f.read(4)
It should work now for your case. You should check it using latest code from git.
Possible future improvement would be reading gzip over pipe, but I did not have any good ideas how to do it in a nice way.

from kamene.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.