-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMISC
73 lines (56 loc) · 2.09 KB
/
MISC
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
First I opened notepad, and searched for SICTF and flag, and found a file flag.txt
and then i tried these 2 codes(with help of chat gpt):
1.
import os
import sys
import time
def delete_old_files(root_folder, max_depth, max_age_days):
try:
current_time = time.time()
for root, dirs, files in os.walk(root_folder):
depth = root.count(os.sep)
if depth > max_depth:
continue # Skip folders beyond the maximum depth
for file in files:
file_path = os.path.join(root, file)
file_age = (current_time - os.path.getmtime(file_path)) / (60 * 60 * 24)
if file_age > max_age_days:
print(f"Deleting file: {file_path} (age: {file_age:.2f} days)")
os.remove(file_path)
except PermissionError as e:
print(f"Permission denied: {e}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python script.py root_folder max_depth max_age_days")
sys.exit(1)
root_folder = sys.argv[1]
max_depth = int(sys.argv[2])
max_age_days = int(sys.argv[3])
delete_old_files(root_folder, max_depth, max_age_days)
2.
import os
import time
import zipfile
while True:
# Check if a file named "flag.zip" exists
if os.path.exists("flag.zip"):
print("Found 'flag.zip'. Stopping the script.")
break
# Query the current directory for zip files
zip_files = [file for file in os.listdir(".") if file.endswith(".zip")]
if zip_files:
zip_file = zip_files[0]
print(f"Processing {zip_file}...")
# Unzip the zip file
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
zip_ref.extractall()
# Delete the first zip file and keep the others
os.remove(zip_file)
print(f"Deleted {zip_file}.")
else:
print("No zip files found in the directory!")
break
# Sleep for a while (0.5 seconds for this case)
time.sleep(0.5)