-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThinRPC.py
executable file
·53 lines (42 loc) · 1.16 KB
/
ThinRPC.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
# !/usr/bin/python2
import tempfile
import urllib
import sys
import subprocess
import os
from LoggerRPC import logger
def reverse_tunnel(*args):
port = args[0]
logger.info("Received command : %s" % data)
process = subprocess.Popen(["ssh", "-f", "-N", "-T", "-R%s:localhost:22" % port, "tunnel@command.mobiusstrip.eu"])
return process
cmds = {
"reverse_tunnel": reverse_tunnel
}
data = ""
try:
data = urllib.urlopen('http://command.mobiusstrip.eu/command.txt').read().strip()
temporaryFile = os.path.join(tempfile.gettempdir(), 'thinrpc.tmp')
write_cmd = False
if os.path.exists(temporaryFile):
ff = open(temporaryFile, 'rb')
ffdata = ff.read()
ff.close()
if ffdata == data:
logger.info("Command already ran")
sys.exit(0)
else:
write_cmd = True
else:
write_cmd = True
if write_cmd:
ff = open(temporaryFile, 'wb')
ff.write(data)
ff.close()
data = data.split()
if not data[0] in cmds:
sys.exit(0)
logger.info(cmds[data[0]](*data[1:]).communicate())
except Exception as e:
logger.warning(e)
sys.exit(0)