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
|
import subprocess
import tempfile
import os
from sploit.log import log
class Comm:
def __init__(self, backend):
self.back = backend
def __del__(self):
for line in self.back.stdin:
log(line)
def read(self, size):
data = self.back.stdin.read(size)
log(data)
return data
def readline(self):
data = self.back.stdin.readline()
log(data)
return data
def write(self, data):
self.back.stdout.write(data)
self.back.stdout.flush()
def writeline(self, data):
self.write(data + b'\n')
class Process:
def __init__(self, args):
print(f"Running: {' '.join(args)}")
self.proc = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
print(f"PID: {self.proc.pid}")
self.stdin = self.proc.stdout
self.stdout = self.proc.stdin
def __del__(self):
self.proc.wait()
class Pipes:
def __init__(self,tmp=None):
if(tmp == None):
self.dir = tempfile.TemporaryDirectory()
dirname = self.dir.name
else:
dirname = os.path.join("/tmp",tmp)
self.pathin = os.path.join(dirname,"in")
self.pathout = os.path.join(dirname,"out")
os.mkfifo(self.pathin)
os.mkfifo(self.pathout)
print("Waiting on Target to Connect...")
print("<"+self.pathin+" >"+self.pathout)
self.stdout = open(self.pathin,"wb")
self.stdin = open(self.pathout, "rb")
print("Connected!")
def __del__(self):
self.stdout.close()
self.stdin.close()
os.unlink(self.pathin)
os.unlink(self.pathout)
|