-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_remnants.py
More file actions
56 lines (49 loc) · 2.35 KB
/
check_remnants.py
File metadata and controls
56 lines (49 loc) · 2.35 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
###########################################################################################################
# check if installation files from a CMS are still present on the webserver
# filenames to check are read from remnants.txt
# 20240521
###########################################################################################################
import os
import requests
def check_remnants(website, url, outfile, logger, myheaders, rlff):
"""
Args:
website (str): The website being checked.
url (str): The URL to check.
outfile (file object): The file to write output to.
logger (function pointer): Function to print debug information.
myheaders (dict): The headers to send with the request.
rlff (function pointer): Function to read lines from file
"""
logger(f"=== check_remnants")
outfile.write("\n===========Check for installation files left behind\n")
found_files = []
filenames = rlff('remnants.txt')
if filenames is None:
return 0
random_file = "iu87h8hkhkgigy" # Replace this with your own random string
file_url = os.path.join(url, random_file)
response = requests.get(file_url, headers = myheaders, timeout=5)
if response.status_code == 200:
logger("This web server returns a HTTP code of 200 on everything, skipping checks")
outfile.write("This web server returns a HTTP code of 200 on everything, skipping checks")
return 1 # web server will pretend any file is present, so let's stop here
for file in filenames:
file_url = os.path.join(url, file)
try:
response = requests.get(file_url, headers = myheaders, timeout=5)
if response.status_code == 200:
found_files.append(file_url)
except requests.exceptions.RequestException as e:
logger(f"Error checking file '{file}': {e}")
if found_files:
logger(f"The following files gave a 200 response from {website}:")
outfile.write(f"The following files gave a 200 response from {website}:")
for file in found_files:
logger(f"- {file}")
outfile.write(f"- {file}\n")
return 0
else:
logger(f"No files from remnants.txt were found in the web server root of {url}.")
outfile.write(f"No files from remnants.txt were found in the web server root of {url}.")
return 1