User Controls
What's wrong with my class.
-
2015-09-23 at 10:58 PM UTC
Oh top kek, typos ruining my life.
We all do it :) Is it working now? -
2015-09-23 at 11:08 PM UTC
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. -
2015-09-23 at 11:13 PM UTC
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 -
2015-09-23 at 11:17 PM UTC
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. -
2015-09-23 at 11:18 PM UTC
I did bro, i tried the code fixed the subnet. still the same.
fuck :( what error you getting now? :( -
2015-09-23 at 11:19 PM UTC
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 -
2015-09-24 at 12:16 AM UTC
formatting's gone to fuck, sorry. use a beautifier and test it.
You have to "paste as plain text".
-
2015-09-24 at 12:23 AM UTC"What's wrong with my class?"
"Don't use classes."
*awkward* -
2015-09-24 at 2:03 AM UTC
"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. -
2015-09-24 at 6:06 AM UTCSo 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 -
2015-09-24 at 6:24 AM UTCThis 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
-
2015-09-24 at 6:29 AM UTCOoops, 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.
-
2015-09-24 at 7:09 AM UTC
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' -
2015-09-25 at 5:05 AM UTCHmm, 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.
-
2015-09-25 at 1:54 PM UTC
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.