Esempio n. 1
0
def edit_responses(operation, resp_id=None):
    if request.method == 'POST':
        form = CommandForm(request.form)

        if not form.validate_on_submit():
            flash(form.errors)

        if operation == 'new':
            resp = MacroResponse(form.command.data, form.response.data)
            db.session.add(resp)
            db.session.commit()

        if operation == 'edit':
            resp = MacroResponse.query.filter_by(id=resp_id).first()
            resp.trigger = form['command'].data
            resp.response = form['response'].data
            db.session.commit()

    if (request.method == 'GET') and (resp_id):

        if operation == 'delete':
            MacroResponse.query.filter_by(id=resp_id).delete()
            db.session.commit()

    return redirect(url_for('macros.responses'))
Esempio n. 2
0
def edit_macros(operation, macro_id=None):
    if request.method == 'POST':
        form = CommandForm(request.form)

        if not form.validate_on_submit():
            flash(form.errors)

        if operation == 'new':
            macro = Macro(form.command.data, form.response.data, 1)
            db.session.add(macro)
            db.session.commit()

        if operation == 'edit':
            macro = Macro.query.filter_by(id=macro_id).first()
            macro.command = form['command'].data
            macro.response = form['response'].data
            macro.modified_flag = 1
            db.session.commit()

    if (request.method == 'GET') and (macro_id):

        if operation == 'delete':
            Macro.query.filter_by(id=macro_id).delete()
            db.session.commit()

    return redirect(url_for('macros.macros'))
Esempio n. 3
0
def run_cmd(cmd=None):
    print(cmd)
    form = CommandForm()
    if form.validate_on_submit():
        response = json.dumps(bettercap.run_command(form.cmd.data),
                              sort_keys=True,
                              indent=4,
                              separators=(',', ': '))
        return render_template('cmd.html',
                               header='Run Command',
                               response=response,
                               form=form)
    return render_template('cmd.html',
                           header='Run Command',
                           new_cmd=True,
                           form=form)
Esempio n. 4
0
def index():
    user = {'username': current_user.username.capitalize()}
    username = user['username']
    form = CommandForm(request.args, meta={'csrf': False})
    if request.args.get('submit', False):
        command = form.name.data
        if not command:
            logger.debug('Route /index was called without a command.')
            return render_template('index.html', title='Command', form=form,
                                   errors=['This field is required.'],
                                   user=username)
        ex_command = [] if command.startswith('host') else ['host']
        ex_command.extend([quote(x) for x in command.split()])
        if not validate_input(ex_command):
            flash(f'Invalid input.')
            logger.error(f'Regex did not match at /index call.')
            return render_template('index.html', title='Command', form=form,
                                   errors=['Invalid input.'], user=username)
        try:
            output = check_output(ex_command, stderr=STDOUT).decode()
        except Exception as e:
            flash(f'Invalid input.')
            logger.error(f'Route /index was called with error {e}')
            return render_template('index.html', title='Command', form=form,
                                   errors=['Invalid input.'], user=username)

        ansi_escaped = ansi_escape(output)
        htmlified = ansi_escaped.replace('\n', '<br>')
        logger.debug('Route /index was called and returned htmlified data.')

        return render_template('index.html', title='Command', form=form,
                               output=htmlified, user=username)

    return render_template('index.html', title='Command', form=form,
                           user=username)
Esempio n. 5
0
def macros(macro_id=None):
    form = CommandForm(request.form)
    macros = Macro.query.all()

    if macro_id:
        macro = Macro.query.filter_by(id=macro_id).first()
        return render_template('macros/macros.html',
                               macros=macros,
                               form=form,
                               current_macro=macro)
    else:
        return render_template('macros/macros.html', macros=macros, form=form)
Esempio n. 6
0
def run_cmd(cmd=None):
    print(cmd)
    form = CommandForm()
    if form.validate_on_submit():
        url = str('{}/api/session'.format(bettercap_url))
        cmd = {"cmd": form.cmd.data}
        r = requests.post(url,
                          data=json.dumps(cmd),
                          auth=(username, password),
                          verify=False)
        response = json.dumps(r.json(),
                              sort_keys=True,
                              indent=4,
                              separators=(',', ': '))
        return render_template('cmd.html',
                               header='Run Command',
                               response=response,
                               form=form)
    return render_template('cmd.html',
                           header='Run Command',
                           new_cmd=True,
                           form=form)
Esempio n. 7
0
def command(port):
    form = CommandForm()
    id = Posts.query.filter_by(content=port).first().id
    if form.validate_on_submit():
        if current_user.is_authenticated:
            u = current_user._get_current_object()
            p = Posts(content=form.content.data, user=u, rid=id)
            db.session.add(p)
            return redirect(url_for('main.command', port=port))
        else:
            flash('登录后才能评论')
            return redirect('user.login')

    page = request.args.get('page', 1, type=int)
    pagination = Posts.query.filter_by(rid=id).order_by(
        Posts.timestamp.desc()).paginate(page, per_page=3, error_out=False)
    posts = pagination.items
    return render_template('main/command.html',
                           form=form,
                           posts=posts,
                           pagination=pagination,
                           port=port)
Esempio n. 8
0
def responses(resp_id=None):
    form = CommandForm(request.form)
    response_list = MacroResponse.query.all()

    if resp_id:
        resp = MacroResponse.query.filter_by(id=resp_id).first()
        return render_template('macros/responses.html',
                               responses=response_list,
                               form=form,
                               current_resp=resp)
    else:
        return render_template('macros/responses.html',
                               responses=response_list,
                               form=form)
Esempio n. 9
0
def reactions(react_id=None):
    form = CommandForm(request.form)
    reaction_list = MacroReaction.query.all()

    if react_id:
        reaction = MacroReaction.query.filter_by(id=react_id).first()
        return render_template('macros/reactions.html',
                               reactions=reaction_list,
                               form=form,
                               current_react=reaction)
    else:
        return render_template('macros/reactions.html',
                               reactions=reaction_list,
                               form=form)