forked from JMousqueton/ransomware.live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathransom_notes.py
113 lines (92 loc) Β· 4.63 KB
/
ransom_notes.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
import os
import shutil
import json
from datetime import datetime as dt
NowTime=dt.now()
source_dir = './docs/ransomware_notes'
target_dir = './docs/notes'
print(
'''
_______________ |*\_/*|________
| ___________ | ||_/-\_|______ |
| | | | | | | |
| | 0 0 | | | | 0 0 | |
| | - | | | | - | |
| | \___/ | | | | \___/ | |
| |___ ___| | | |___________| |
|_____|\_/|_____| |_______________|
_|__|/ \|_|_.............π.............._|________|_
/ ********** \ / ********** \
/ ************ \ ransomwhat? / ************ \
-------------------- --------------------
'''
)
with open('groups.json', 'r') as groupsjson:
# Load the JSON data
data = json.load(groupsjson)
# Iterate over the subdirectories in the source directory
for subdir in os.listdir(source_dir):
subdir_path = os.path.join(source_dir, subdir)
# Check if it is a directory
if os.path.isdir(subdir_path):
# Create a file with the name of the subdirectory in the target directory
file_path = os.path.join(target_dir, subdir + '.md')
# Open the file in write mode and write the name of the directory
with open(file_path, 'w', encoding='utf-8') as file:
file.write('# π° _Ransom notes for group_ '+ subdir + '\n')
for group in data:
if subdir.lower() in group['name']:
file.write('> π ['+ subdir + '](group/' + subdir.lower() + ')\n')
header = "\n\n"
header += "> [!TIP]"
header += "> Ransomware notes are provided by [Zscaler ThreatLabz](https://github.com/threatlabz/ransomware_notes) under MIT License\n"
header += "> \n"
header += "\n\n"
# Iterate over the files in the subdirectory
for filename in os.listdir(subdir_path):
file_path_source = os.path.join(subdir_path, filename)
# Check if it is a file
if os.path.isfile(file_path_source):
# Append the content of each file to the corresponding target file
with open(file_path_source, 'r', encoding='latin-1') as source_file:
content = source_file.read()
with open(file_path, 'a', encoding='utf-8') as target_file:
target_file.write('* **[' + os.path.basename(file_path_source) + '](https://ransomware.live/ransomware_notes/' + subdir + '/' + os.path.basename(file_path_source).replace(' ','%20') + ')**\n')
target_file.write('\n```\n')
target_file.write(content)
target_file.write('\n```\n')
with open(file_path, 'a', encoding='utf-8') as target_file:
target_file.write(header)
target_file.write('\n\nLast update : _'+ NowTime.strftime('%A %d/%m/%Y %H.%M') + ' (UTC)_\n\n')
# Get a list of all directories in the specified directory, excluding .git
directories = [d for d in os.listdir(source_dir) if os.path.isdir(os.path.join(source_dir, d)) and d != ".git"]
# Sort the directories alphabetically
directories = sorted(directories, key=lambda x: x.lower())
header = "\n"
header += "# π° All ransomware notes by groups"
header += "\n\n"
header += "> [!INFO]"
header += "> Ransomware notes are provided by [Zscaler ThreatLabz](https://github.com/threatlabz/ransomware_notes) under MIT License\n"
header += "> \n"
header += "\n\n"
# Prepare the Markdown table header
header += "| | | | | | | | | | |\n" # Empty header row
header += "|:------------:|:------------:|:------------:|:------------:|:------------:|:------------:|:------------:|:------------:|:------------:|:------------:|\n" # Table formatting
# Prepare the Markdown table rows
rows = ""
for i in range(0, len(directories), 10):
row = "|"
for j in range(10):
if i + j < len(directories):
row += f" [{directories[i + j]}](notes/{directories[i + j]})|"
else:
row += " |"
rows += row + "\n"
# Generate the Markdown file content
markdown_content = f"{header}{rows}"
# Write the content to a file
output_file = "./docs/ransomnotes.md"
with open(output_file, "w") as file:
file.write(markdown_content)
file.write('\n\nLast update : _'+ NowTime.strftime('%A %d/%m/%Y %H.%M') + ' (UTC)_\n\n')
print(f"Ransom Notes index file generated successfully.")