Пример #1
0
async def check_command(request, user, ptype, cmd):
    status = {'status': 'success'}
    try:
        payload_type = await db_objects.get(PayloadType, ptype=ptype)
    except Exception as e:
        print(e)
        return json({'status': 'error', 'error': 'failed to get payload type'})
    try:
        command = await db_objects.get(Command,
                                       cmd=cmd,
                                       payload_type=payload_type)
        params = await db_objects.execute(CommandParameters.select().where(
            CommandParameters.command == command))
        status = {
            **status,
            **command.to_json(), "params": [p.to_json() for p in params]
        }
    except Exception as e:
        # the command doesn't exist yet, which is good
        pass
    # now check to see if the file exists
    try:
        file = open("./app/payloads/{}/{}".format(payload_type.ptype, cmd),
                    'rb')
        encoded = base64.b64encode(file.read()).decode("UTF-8")
        status = {**status, 'code': encoded}
    except Exception as e:
        # file didn't exist so just continue on
        pass
    return json(status)
Пример #2
0
async def check_command(request, user, ptype, cmd):
    if user['auth'] not in ['access_token', 'apitoken']:
        abort(status_code=403, message="Cannot access via Cookies. Use CLI or access via JS in browser")
    status = {'status': 'success'}
    try:
        query = await db_model.payloadtype_query()
        payload_type = await db_objects.get(query, ptype=ptype)
    except Exception as e:
        print(e)
        return json({'status': 'error', 'error': 'failed to get payload type'})
    try:
        query = await db_model.command_query()
        command = await db_objects.get(query, cmd=cmd, payload_type=payload_type)
        query = await db_model.commandparameters_query()
        params = await db_objects.execute(query.where(CommandParameters.command == command))
        query = await db_model.attackcommand_query()
        attacks = await db_objects.execute(query.where(ATTACKCommand.command == command))
        query = await db_model.artifacttemplate_query()
        artifacts = await db_objects.execute(query.where( (ArtifactTemplate.command == command) & (ArtifactTemplate.deleted == False)))
        query = await db_model.commandtransform_query()
        transforms = await db_objects.execute(query.where(CommandTransform.command == command))
        status = {**status, **command.to_json(), "params": [p.to_json() for p in params], "attack": [a.to_json() for a in attacks],
                  "artifacts": [a.to_json() for a in artifacts], 'transforms': [t.to_json() for t in transforms]}
    except Exception as e:
        # the command doesn't exist yet, which is good
        pass
    # now check to see if the file exists
    try:
        file = open("./app/payloads/{}/commands/{}".format(payload_type.ptype, cmd), 'rb')
        encoded = base64.b64encode(file.read()).decode("UTF-8")
        status = {**status, 'code': encoded}
    except Exception as e:
        # file didn't exist so just continue on
        pass
    return json(status)
Пример #3
0
def get_file_content(static_file_directory, file_name):
    """The content of the static file to check"""
    with open(os.path.join(static_file_directory, file_name), 'rb') as file:
        return file.read()
Пример #4
0
def get_file_content(static_file_directory, file_name):
    """The content of the static file to check"""
    with open(os.path.join(static_file_directory, file_name), 'rb') as file:
        return file.read()