I have a basic script that I am using to fuzz vulnserver as part of a cyber security course.
I have an issue when my script goes to send the payload, A * 100
to the target server. I get an error as below:
TypeError: a bytes-like object is required, not 'str'
.
There are similar questions already on SO but they seem to deal with reading from files rather than sending requests via sockets.
While I am debugging the script I have added the try/except
with the print()
function as seen below but this is normally wrapped in the calling method.I was just trying to tie down exactly where the exception was happening.
I have tried using encode()
in several places but this doesn't seem to have any effect.
The parent method is at the bottom and full solution is on Github
#!/usr/bin/python3
import socket
import sys
class Send:
def __init__(self, target):
self.ip = target.ip
self.port = target.port
self.path = target.path
def send_payload(self, payload):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
s.connect((self.ip, self.port))
s.recv(1024)
s.send((self.path + payload))
s.close()
except Exception as e:
print(f"Exception In send: {e}")
sys.exit()
Called from here...
#!/usr/bin/python3
from time import sleep
from send_request import Send
import sys
def find_crash(target):
buffer = "A" * 100
s = Send(target)
while True:
try:
s.send_payload(buffer)
sleep(1)
buffer = buffer + "A" * 100
except Exception as e:
print("Exception: " + str(e))
return len(buffer)