-
Notifications
You must be signed in to change notification settings - Fork 1
/
webchosounder.py
executable file
·218 lines (179 loc) · 7.43 KB
/
webchosounder.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python3
from flask import Flask, jsonify, render_template, request
from typing import List
import json
from importlib import import_module
## verification d'import des modules
listmodules = [('ipaddress', 'ipaddress'),
('scapy', 'scapy'),
('impacket', 'impacket'),
('nmap', 'nmap'),
('echosounder', 'echosounder'),
]
listmoduleserror = []
for name, short in listmodules:
try:
lib = import_module(name)
except Exception as e:
listmoduleserror.append({name:"Le module n'a pas été importé, problème de dépendance python ?"})
print(e)
else:
globals()[short] = lib
if(not any('scapy' in x for x in listmoduleserror)):
from scapy.arch import get_if_addr
from scapy.config import conf
LOCAL_IP = get_if_addr(conf.iface)
else:
LOCAL_IP = "127.0.0.1"
app = Flask(__name__, template_folder='templates')
app.config["CACHE_TYPE"] = "null"
@app.route('/')
def index():
return render_template("index.html")
@app.route('/json/health')
def health():
return jsonify(status='ok')
@app.route('/json/health/nmap')
def health_nmap():
return jsonify(nmap=echosounder.check_nmap_exist())
@app.route('/json/health/dependencies')
def health_dependencies():
return jsonify(dependencies=listmoduleserror)
@app.route('/json/address_family')
def get_address_family():
return jsonify(echosounder.get_address_family())
@app.route('/json/ipcidr', methods=['POST'])
def get_ip_cidr():
data = request.json['ip']+'/'+request.json['cidr']
print(data)
return jsonify(ipcidr=echosounder.from_ipnetmask_get_ipcidr(data))
@app.route('/json/interfaces')
def get_interfaces():
return jsonify(echosounder.get_interfaces())
@app.route('/json/interface/<interface>')
def get_interface_info(interface):
return jsonify(echosounder.get_interface_info(interface))
@app.route('/json/arp_scan', methods=['POST'])
def scan_arp():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
local_ip_mac_and_gateway: dict = echosounder.get_host_and_gateway()
local_ip_mac: List[dict] = echosounder.data_creation_arp_scan(request.json['cible'])
return jsonify(local_data=local_ip_mac_and_gateway, scan=local_ip_mac, vlan=request.json['cible'])
@app.route('/json/fast_scan', methods=['POST'])
def scan_rapide():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
local_ip_mac_and_gateway: dict = echosounder.get_host_and_gateway()
ip_mac_os: List[dict] = echosounder.data_creation_fast_ping(request.json['cible'])
return jsonify(local_data=local_ip_mac_and_gateway, scan=ip_mac_os, vlan=request.json['cible'])
@app.route('/json/trace_scan', methods=['GET'])
def scan_trace_fuzzing():
trace: List[dict] = echosounder.traceroute_scan()
return jsonify(scan=trace)
@app.route('/json/trace_scan', methods=['POST'])
def scan_trace():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
trace: List[dict] = echosounder.traceroute_scan(request.json['cible'])
return jsonify(scan=trace)
@app.route('/json/trace_cidr_scan', methods=['POST'])
def scan_trace_cidr():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
trace: List[List[dict]] = echosounder.traceroute_cidr_scan(request.json['cible'])
return jsonify(scan=trace)
@app.route('/json/dhcp_cidr_scan', methods=['POST'])
def scan_dhcp_cidr():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
dhcp_ip: List[List[dict]] = echosounder.scan_dhcp_discover(request.json['cible'])
return jsonify(scan=dhcp_ip)
@app.route('/json/profiling_scan', methods=['POST'])
def scan_profiling():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.creation_data_nmap(request.json['cible']))
@app.route('/json/services_scan', methods=['POST'])
def scan_services():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
elif("port_start" not in request.json):
return jsonify(scan=echosounder.data_creation_services_discovery(request.json['cible']))
else:
return jsonify(scan=echosounder.data_creation_services_discovery(request.json['cible'], port_start=request.json['port_start'], port_end=request.json['port_end']))
@app.route('/json/services_fast_scan', methods=['POST'])
def scan_fast_services():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.retrieve_top_services(request.json['cible']))
@app.route('/json/reverse_ptr_scan', methods=['POST'])
def scan_reverse_ptr():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.reverse_ptr_local_scan(request.json['cible']))
@app.route('/json/fingerpting_ssh_scan', methods=['POST'])
def scan_fingerprint_ssh():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.fingerprint_ssh(request.json['cible']))
@app.route('/json/scan_info_smb', methods=['POST'])
def scan_info_smb():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.null_session_smb_enumeration(request.json['cible']))
@app.route('/json/scan_snmp_info', methods=['POST'])
def scan_snmp_info():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.scan_snmp_info(request.json['cible']))
@app.route('/json/scan_snmp_netstat', methods=['POST'])
def scan_snmp_netstat():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.scan_snmp_netstat(request.json['cible']))
@app.route('/json/scan_snmp_processes', methods=['POST'])
def scan_snmp_processes():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.scan_snmp_processes(request.json['cible']))
@app.route('/json/scan_ntp', methods=['POST'])
def scan_ntp_info():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.scan_ntp_info(request.json['cible']))
@app.route('/json/scan_rdp_info', methods=['POST'])
def scan_rdp_info():
if not if_contain_cible(request.json):
return {'error': "malformed request"}
else:
return jsonify(scan=echosounder.scan_rdp_info(request.json['cible']))
@app.route('/json/ip_to_as/<ip>', methods=['GET'])
def ip_to_as(ip):
ip = ipaddress.IPv4Address(ip)
as_retrieved = None
with app.open_resource('asinfo/routeviews-prefix2as-latest.json', 'r') as listcidr:
listipcidr = [ [ipaddress.IPv4Network(i[0]), i[1]] for i in json.loads(listcidr.read())]
listcidr.close()
for i in listipcidr:
if(ip in i[0]):
return jsonify(as_number=i[1], as_cidr=str(i[0]))
return {'error': "no AS match"}
def if_contain_cible(test_target) -> bool:
return 'cible' in test_target
if __name__ == "__main__":
app.run(host=LOCAL_IP, port=5042, debug=True)