User Controls

What's wrong with my class.

  1. #21
    Oh top kek, typos ruining my life.
    We all do it :) Is it working now?
  2. #22
    Sophie Pedophile Tech Support
    We all do it :) Is it working now?

    Even with that changed, and the code you provided i still get the same error :( I do appreciate your efforts in trying to help me out though, so thank you regardless.
  3. #23
    Even with that changed, and the code you provided i still get the same error :( I do appreciate your efforts in trying to help me out though, so thank you regardless.


    try the quoted code? you'll need to change the subnet to fix that
  4. #24
    Sophie Pedophile Tech Support
    try the quoted code? you'll need to change the subnet to fix that

    I did bro, i tried the code fixed the subnet. still the same.
  5. #25
    I did bro, i tried the code fixed the subnet. still the same.


    fuck :( what error you getting now? :(
  6. #26
    Sophie Pedophile Tech Support
    fuck :( what error you getting now? :(

    Same as before lol.

    C:\Implant\Black Hat Python>test2.py
    Traceback (most recent call last):
    File "C:\Implant\Black Hat Python\test2.py", line 90, in <module>
    ip_header = IP(raw_buffer[0:20])
    TypeError: an integer is required
  7. #27
    -SpectraL coward [the spuriously bluish-lilac bushman]
    formatting's gone to fuck, sorry. use a beautifier and test it.

    You have to "paste as plain text".
  8. #28
    mmQ Lisa Turtle
    "What's wrong with my class?"

    "Don't use classes."

    *awkward*
  9. #29
    Sophie Pedophile Tech Support
    "What's wrong with my class?"

    "Don't use classes."

    *awkward*

    I could use a function... But if i mess up the syntax it ain't gonna' make a difference lol.
  10. #30
    Lanny Bird of Courage
    So I'm not _really_ sure how this needs to work but I'm pretty sure you need to unpack that byte array (represented as a string) before passing it to the constructor. Your IP class has room for 20 bytes of data (hence the len 20 slice) but you have to unpack the string into fields to make it work.

    Instead of `ip_header = IP(raw_buffer[0:20])` try:


    import struct
    unpacked = struct.unpack('!BBHHHBBHII', raw_buffer[1:20])
    unpacked = (unpacked[0] & 0xF, unpacked[0] >> 4) + unpacked[1:]

    ip_header = IP(*unpacked)


    I don't really know if that's going to work or not but give it a whirl. What we're doing here is splitting the byte string up into component parts ("unpacking" it) before feeding it to the IP class
  11. #31
    Sophie Pedophile Tech Support
    This is how i added it.


    try:

    while True:



    # Read in a packet
    raw_buffer = sniffer.recvfrom(65565)[0]
    # Create an IP header from the first 20 bytes of the buffer
    unpacked = struct.unpack('!BBHHHBBHII', raw_buffer[1:20])
    unpacked = (unpacked[0] & 0xF, unpacked[0] >> 4) + unpacked[1:]

    ip_header = IP(*unpacked)
    # ip_header = IP(raw_buffer[0:20])

    # Print out the protocol that was detected and the hosts
    print "Protocol: %s %s -> %s" % (ip_header.protocol, ip_header.src_address, ip_header.dst_address)

    print "ICMP -> Type: %d Code: %d" % (icmp_header.type, icmp_header.code)

    # Now check for type 3 and code
    if icmp_header.code == 3 and icmp_header.type == 3:

    # Make sure host is in target subnet
    if IPAddress(ip_header.src_address) in IPNetwork(subnet):

    # Make sure it has our magic message
    if raw_buffer[len(raw_buffer)-len(magic_message):] == magic_message:
    print "Host up: %s" % ip_header.src_address

    # Handle CTRL+C
    except KeyboardInterrupt:
    # If we're using Windows turn off promisuous mode
    if os.name == "nt":
    sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)



    This is my new error message.

    Traceback (most recent call last):
    File "C:\Implant\Black Hat Python\sniffer.py", line 93, in <module>
    unpacked = struct.unpack('!BBHHHBBHII', raw_buffer[1:20])
    struct.error: unpack requires a string argument of length 20
  12. #32
    Lanny Bird of Courage
    Ooops, my bad, replace `unpacked = struct.unpack('!BBHHHBBHII', raw_buffer[1:20])` with `unpacked = struct.unpack('!BHHHBBHII', raw_buffer[1:20])` (one less B at the beginning). I was including those two nibbles at the start in the format string.
  13. #33
    Sophie Pedophile Tech Support
    Ooops, my bad, replace `unpacked = struct.unpack('!BBHHHBBHII', raw_buffer[1:20])` with `unpacked = struct.unpack('!BHHHBBHII', raw_buffer[1:20])` (one less B at the beginning). I was including those two nibbles at the start in the format string.

    Ok that fixed the unpacking issue now i'm getting this.

    C:\Implant\Black Hat Python>sniffer.py
    Traceback (most recent call last):
    File "C:\Implant\Black Hat Python\sniffer.py", line 100, in <module>
    print "Protocol: %s %s -> %s" % (ip_header.protocol, ip_header.src_address,
    ip_header.dst_address)
    AttributeError: 'IP' object has no attribute 'protocol'
  14. #34
    Lanny Bird of Courage
    Hmm, so it looks like your `_init_` method isn't getting called (worth sticking a print in there to make sure though). I assumed the _init_ was part of cooperative subclassing but that might be wrong. Are you sure `_init_` isn't supposed to be `__init__` (two underscores instead of one)? Same thing with `_new_`. __init__ and __new__ are special method names in python, the constructor and the, uhh, proto-constructor(?) respectively. If you're not sure try reversing my unpack changes and using the double underscore names and see if that makes a difference.
  15. #35
    Sophie Pedophile Tech Support
    Hmm, so it looks like your `_init_` method isn't getting called (worth sticking a print in there to make sure though). I assumed the _init_ was part of cooperative subclassing but that might be wrong. Are you sure `_init_` isn't supposed to be `__init__` (two underscores instead of one)? Same thing with `_new_`. __init__ and __new__ are special method names in python, the constructor and the, uhh, proto-constructor(?) respectively. If you're not sure try reversing my unpack changes and using the double underscore names and see if that makes a difference.

    That might be it, i'll have a look in a bit.
Jump to Top