-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetection_functions.py
More file actions
212 lines (183 loc) · 7.07 KB
/
Copy pathdetection_functions.py
File metadata and controls
212 lines (183 loc) · 7.07 KB
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
import sys
import requests
import re
from urllib.parse import urlparse
def is_php_used(website_url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
try:
response = requests.get(website_url, headers=headers, timeout=10)
indicators = []
parsed_url = urlparse(response.url)
if parsed_url.path.endswith(('.php', '.phtml')):
# indicators.append("PHP file extension in URL")
return True
if 'X-Powered-By' in response.headers and 'php' in response.headers['X-Powered-By'].lower():
# indicators.append(f"PHP header: {response.headers['X-Powered-By']}")
return True
php_frameworks = ['wordpress', 'wp-content', 'laravel', 'symfony', 'drupal', 'moodle']
for framework in php_frameworks:
if framework in response.text.lower():
# indicators.append(f"PHP framework detected: {framework}")
return True
# if re.search(r'href=["\'][^"\']*\.php', response.text):
# indicators.append("PHP links found in HTML")
# if response.status_code == 200:
except Exception as e:
print(e)
sys.exit()
return False
def php_version_from_header(website_url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
try:
response = requests.get(website_url, headers=headers, timeout=10)
if 'X-Powered-By' in response.headers:
header_value = response.headers['X-Powered-By'].lower()
if 'php' in header_value:
php_version_match = re.search(r'php/?([0-9]+\.[0-9]+\.?[0-9]*)', header_value, re.IGNORECASE)
if php_version_match:
return php_version_match.group(1)
php_info_paths = ['/phpinfo.php', '/info.php', '/php_info.php', '/test.php', '/i.php']
for path in php_info_paths:
try:
info_url = f"{website_url.rstrip('/')}{path}"
info_response = requests.get(info_url, headers=headers, timeout=5)
if 'phpinfo()' in info_response.text:
php_version_match = re.search(r'PHP Version ([0-9]+\.[0-9]+\.?[0-9]*)', info_response.text)
if php_version_match:
return php_version_match.group(1)
except Exception as e:
print(e)
continue
try:
error_url = f"{website_url}/?error_trigger=1'\"<"
error_response = requests.get(error_url, headers=headers, timeout=5)
php_version_match = re.search(r'PHP (?:Version )?([0-9]+\.[0-9]+\.?[0-9]*)', error_response.text)
if php_version_match:
return php_version_match.group(1)
except Exception as e:
print(e)
except Exception as e:
print(e)
sys.exit()
return None
def is_wordpress_used(website_url):
print()
# def detect_os(website_url):
# headers = {
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
# }
#
# try:
# response = requests.get(website_url, headers=headers, timeout=10)
#
# # Method 1: Check Server header
# if 'Server' in response.headers:
# server_header = response.headers['Server'].lower()
#
# # Windows indicators
# if any(win_term in server_header for win_term in ['win', 'microsoft', 'iis']):
# return "Windows"
#
# # Linux distributions
# if 'debian' in server_header:
# return "Debian Linux"
# if 'ubuntu' in server_header:
# return "Ubuntu Linux"
# if 'centos' in server_header:
# return "CentOS Linux"
# if 'fedora' in server_header:
# return "Fedora Linux"
# if 'red hat' in server_header or 'redhat' in server_header:
# return "Red Hat Linux"
# if 'linux' in server_header:
# return "Linux"
#
# # Other Unix-like systems
# if 'freebsd' in server_header:
# return "FreeBSD"
# if 'openbsd' in server_header:
# return "OpenBSD"
# if 'unix' in server_header:
# return "Unix"
# if 'darwin' in server_header or 'mac' in server_header:
# return "macOS"
#
# # Method 2: Check X-Powered-By header
# if 'X-Powered-By' in response.headers:
# powered_by = response.headers['X-Powered-By'].lower()
# if 'asp.net' in powered_by:
# return "Windows"
#
# # Method 3: Try to trigger error page for additional info
# try:
# error_url = f"{website_url}/non_existent_page_for_os_detection_{hash(website_url)}"
# error_response = requests.get(error_url, headers=headers, timeout=5)
#
# error_text = error_response.text.lower()
#
# if any(win_term in error_text for win_term in ['iis', 'microsoft', 'windows']):
# return "Windows"
#
# if 'apache' in error_text:
# if 'debian' in error_text:
# return "Debian Linux"
# if 'ubuntu' in error_text:
# return "Ubuntu Linux"
# if 'centos' in error_text:
# return "CentOS Linux"
# if 'fedora' in error_text:
# return "Fedora Linux"
# if 'linux' in error_text:
# return "Linux"
# except Exception:
# pass
#
# # Method 4: Use server software as a hint
# if 'Server' in response.headers:
# server = response.headers['Server']
#
# if 'nginx' in server.lower() and not any(
# win_term in server.lower() for win_term in ['win', 'microsoft', 'iis']):
# return "Linux (likely)"
#
# if 'apache' in server.lower() and not any(
# win_term in server.lower() for win_term in ['win', 'microsoft', 'iis']):
# return "Linux (likely)"
#
# if 'iis' in server.lower():
# return "Windows"
#
# return None
#
# except Exception as e:
# print(e)
# return None
def detect_wordpress_used(website_url):
try:
response = requests.get(website_url, timeout=10)
text = response.text.lower()
if "wp-content" in text or "wp-includes" in text or "wordpress" in text:
return True
except Exception as e:
print(e)
return False
def is_givewp_present(website_url):
try:
response = requests.get(website_url, timeout=10)
text = response.text.lower()
indicators = [
'givewp',
'give-form-id',
'give_init',
'wp-content/plugins/give',
'give-checkout',
'give-api',
]
return any(indicator in text for indicator in indicators)
except Exception as e:
print(e)
return False