forked from NORMA-Inc/AtEar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
153 lines (135 loc) · 5.39 KB
/
run.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
# -*- coding: utf-8 -*-
from flask import Flask, request, render_template, Response
import json
import time
from module import airodump
from module.fake_ap import APCreate
import pickle
from module.wids import Wireless_IDS
from module.pentest_open import auto_pentest
from multiprocessing import Process
import ast
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
class PythonObjectEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, (list, dict, str, unicode, int, float, bool, type(None))):
return json.JSONEncoder.default(self, obj)
return {'_python_object': pickle.dumps(obj)}
def as_python_object(dct):
if '_python_object' in dct:
return pickle.loads(str(dct['_python_object']))
return dct
class main_app():
def __init__(self):
self.app = Flask(__name__)
self.run = False
self.scanner = False
self.fake_ap = False
self.pentesting = False
self.scan_iface = 'atear_dump'
self.pent_iface = 'atear_pentest'
self.ap_iface = 'atear_ap'
self.app.add_url_rule('/', 'index', self.index)
self.app.add_url_rule('/tpl/<name>', 'load_tpl', self.load_tpl)
self.app.add_url_rule('/app', 'app_view', self.app_view)
self.app.add_url_rule('/api/scanstatus', 'scanstatus', self.scanstatus, methods=['POST', 'GET'])
self.app.add_url_rule('/api/fakeap', 'fakeap', self.fakeap, methods=['POST', 'GET', 'DELETE'])
self.app.add_url_rule('/api/wids', 'wids', self.wids, methods=['GET'])
self.app.add_url_rule('/api/pentest', 'pentest', self.pentest, methods=['GET', 'POST'])
self.app.add_url_rule('/api/hidden/<wids_option>', 'hidden', self.hidden, methods=['GET'])
self.app.run('0.0.0.0', port=8080, debug=False)
def index(self):
return render_template('main.html')
def load_tpl(self, name):
return render_template(name+'.html')
def app_view(self):
return render_template('index.html')
def scanstatus(self):
if request.method == 'GET':
if not self.scanner:
self.scanner = airodump.Scanner(self.scan_iface)
self.scanner.run()
time.sleep(2)
return "[]", 200
else:
try:
return Response(json.dumps(self.scanner.get_value(), cls=PythonObjectEncoder, ensure_ascii=False),
mimetype='application/json')
except:
return "[]", 200
elif request.method == 'POST':
self.scanner.stop()
self.scanner = False
return '', 200
return '', 200
def fakeap(self):
if request.method == 'POST':
options = request.get_json()
self.fake_ap = APCreate(self.ap_iface, options['enc'], options['ssid'], options['password'])
self.fake_ap.run()
return '', 200
elif request.method == 'GET':
if self.fake_ap:
try:
connstation = self.fake_ap.get_values_connect()
connstation = connstation.replace('\\', '').replace('\"', '').replace(', ]', ']')
loginstation = self.fake_ap.get_values_login()
loginstation = loginstation.replace('\\', '').replace('\"', '').replace(', ]', ']')
return json.dumps({"connstation": connstation, "loginstation": loginstation})
except:
return json.dumps({"connstation": '', "loginstation": ''})
else:
return json.dumps({"connstation": '', "loginstation": ''})
elif request.method == 'DELETE':
self.fake_ap.stop()
self.fake_ap = False
return '', 200
return '', 200
def wids(self):
if request.method == 'GET':
try:
return_value = ast.literal_eval(wids.get_values())
return json.dumps(return_value)
except:
return json.dumps([{}])
def pentest(self):
if request.method == 'POST':
options = request.get_json()
self.pentesting = auto_pentest(self.pent_iface, options)
self.pentesting.run()
return '', 200
elif request.method == 'GET':
try:
return_values = ast.literal_eval(self.pentesting.get_values())
return json.dumps(return_values)
except:
return json.dumps([{}])
return '', 200
def hidden(self, wids_option):
if request.method == 'GET':
if wids_option == '1':
recent_val = wids.get_recent_values()
try:
recent_val = ast.literal_eval(recent_val)
return json.dumps({"message": recent_val})
except:
return json.dumps({"message": []})
elif wids_option == '0':
wids.stop()
return json.dumps({"message": []})
return '', 200
if __name__ == '__main__':
from module.network import auto_monitor, stop_monitor
try:
stop_monitor()
auto_monitor()
wids = Wireless_IDS('atear_wids')
wids_process = Process(target=wids.run)
wids_process.start()
main_app()
# Stop Signal
except KeyboardInterrupt:
stop_monitor()
wids_process.terminate()