-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.py
307 lines (289 loc) · 10.1 KB
/
new.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
from flask import Flask, request, render_template_string
import requests
import json
from bs4 import BeautifulSoup
import socket
app = Flask(__name__)
# NVD API URL
NVD_API_URL = "https://services.nvd.nist.gov/rest/json/cves/2.0"
# Define functions
def check_cves_via_nvd_api(tech_name):
params = {
'keyword': tech_name,
'resultsPerPage': 5
}
try:
response = requests.get(NVD_API_URL, params=params)
if response.status_code == 200:
data = response.json()
cves = []
if 'vulnerabilities' in data and data['vulnerabilities']:
for item in data['vulnerabilities']:
cve = item.get('cve', {}).get('id')
description = item.get('cve', {}).get('descriptions', [{}])[0].get('value')
cves.append({'cve_id': cve, 'description': description})
return cves
else:
return None
else:
return None
except Exception:
return None
def detect_basic_technologies(domain):
tech_info = []
try:
response = requests.get(f'http://{domain}', timeout=10)
if 'x-powered-by' in response.headers:
tech_info.append(response.headers['x-powered-by'])
if 'server' in response.headers:
tech_info.append(response.headers['server'])
soup = BeautifulSoup(response.content, 'html.parser')
meta_generator = soup.find('meta', {'name': 'generator'})
if meta_generator:
tech_info.append(meta_generator.get('content'))
except Exception:
return tech_info
return tech_info
def find_subdomains(domain):
try:
response = requests.get(f'https://crt.sh/?q=%25.{domain}&output=json')
if response.status_code == 200:
json_data = response.json()
subdomains = set(item['name_value'] for item in json_data)
return list(subdomains)
else:
return []
except Exception:
return []
def simple_port_scan(domain):
open_ports = []
for port in range(1, 1025): # Scanning the first 1024 ports
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1) # 1 second timeout
result = sock.connect_ex((domain, port))
if result == 0:
open_ports.append(port)
sock.close()
return open_ports
def run_dirsearch(domain):
dirsearch_results = []
try:
dirsearch_cmd = f"dirsearch -u http://{domain} -e php,html,js,txt"
process = subprocess.Popen(dirsearch_cmd, shell=True, stdout=subprocess.PIPE)
for line in process.stdout:
decoded_line = line.decode('utf-8').strip()
if "200" in decoded_line or "301" in decoded_line:
dirsearch_results.append(decoded_line)
return dirsearch_results
except Exception:
return []
def find_login_pages(domain):
login_pages_found = []
login_paths = [
"/login", "/admin", "/administrator", "/user/login", "/wp-login.php", "/wp-admin", "/signin", "/account/login"
]
for path in login_paths:
url = f"http://{domain}{path}"
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
login_pages_found.append(url)
except requests.ConnectionError:
pass
except Exception:
pass
return login_pages_found
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
domain = request.form['domain']
result = {
'domain': domain,
'subdomains': [],
'technologies': [],
'dirsearch': [],
'login_pages': [],
'cves': {},
'open_ports': []
}
# Detect basic technologies and check CVEs
tech_info = detect_basic_technologies(domain)
result['technologies'] = tech_info
if tech_info:
for tech in tech_info:
cves = check_cves_via_nvd_api(tech)
if cves:
result['cves'][tech] = cves
# Find subdomains
subdomains = find_subdomains(domain)
result['subdomains'] = subdomains
# Simple port scan
open_ports = simple_port_scan(domain)
result['open_ports'] = open_ports
# Run directory brute-forcing using Dirsearch
dirsearch_results = run_dirsearch(domain)
result['dirsearch'] = dirsearch_results
# Find potential login pages
login_pages = find_login_pages(domain)
result['login_pages'] = login_pages
return render_template_string("""
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 20px;
}
h1 {
color: #0056b3;
text-align: center;
font-size: 36px;
margin-bottom: 20px;
}
h2 {
color: #007bff;
border-bottom: 2px solid #007bff;
padding-bottom: 10px;
margin-bottom: 10px;
}
pre {
background-color: #333;
color: #fff;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
}
ul {
list-style-type: none;
padding: 0;
}
ul li {
background-color: #fff;
margin: 5px 0;
padding: 10px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.header {
text-align: center;
margin-bottom: 30px;
}
.header h1 {
font-size: 48px;
color: #ff5722;
}
</style>
</head>
<body>
<div class="header">
<h1>SecureSpectra-X</h1>
</div>
<h1>Security Check Results for {{ result.domain }}</h1>
<h2>Technologies Detected</h2>
<ul>
{% for tech in result.technologies %}
<li>{{ tech }}</li>
{% endfor %}
</ul>
<h2>CVEs Detected</h2>
<ul>
{% for tech, cves in result.cves.items() %}
<li>{{ tech }}
<ul>
{% for cve in cves %}
<li><strong>{{ cve.cve_id }}</strong>: {{ cve.description }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
<h2>Subdomains</h2>
<ul>
{% for subdomain in result.subdomains %}
<li>{{ subdomain }}</li>
{% endfor %}
</ul>
<h2>Open Ports</h2>
<ul>
{% for port in result.open_ports %}
<li>Port {{ port }}: Open</li>
{% endfor %}
</ul>
<h2>Directory Brute-Forcing Results</h2>
<ul>
{% for result in result.dirsearch %}
<li>{{ result }}</li>
{% endfor %}
</ul>
<h2>Login Pages</h2>
<ul>
{% for page in result.login_pages %}
<li><a href="{{ page }}" target="_blank">{{ page }}</a></li>
{% endfor %}
</ul>
<a href="/">Back</a>
</body>
</html>
""", result=result)
return '''
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 20px;
}
h1 {
color: #0056b3;
text-align: center;
font-size: 36px;
margin-bottom: 20px;
}
form {
text-align: center;
}
input[type="text"] {
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: #fff;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h1>SecureSpectra-X</h1>
<form method="post">
<label for="domain">Enter the domain:</label>
<input type="text" id="domain" name="domain" required>
<button type="submit">Submit</button>
</form>
</body>
</html>
'''
if __name__ == "__main__":
app.run(debug=True)