def add(form):
    check_form(form, required_fields)

    mitm_certificate, sys_certificates, user_certificates = _get_scenario_certificates(
        form)

    scenario = ScenarioSettings(
        num_activities_limit=form.get('num_activities_limit') or None,
        user=current_user,
        name=form['name'],
        vuln_type=VulnType(form['vuln_type']),
        mitm_certificate=mitm_certificate,
        sys_certificates=sys_certificates,
        # user_certificates=user_certificates,
        info_message=form.get('info_message'),
        is_default=False,
        enabled='enabled' in form,
        report_http='report_http' in form,
        strace='strace' in form,
        add_upstream_certs='add_upstream_certs' in form,
        only_exported_activities='only_exported_activities' in form)

    db.session.add(scenario)
    db.session.commit()

    return scenario
def edit(id, form):
    scenario = ScenarioSettings.query.get(id)

    if scenario:
        check_form(form, required_fields)

        mitm_certificate, sys_certificates, user_certificates = _get_scenario_certificates(
            form)

        scenario.enabled = 'enabled' in form
        scenario.num_activities_limit = form.get(
            'num_activities_limit') or None
        scenario.name = form['name']
        scenario.vuln_type = VulnType(form['vuln_type'])
        scenario.mitm_certificate = mitm_certificate
        scenario.sys_certificates = sys_certificates
        # scenario.user_certificates = user_certificates
        scenario.info_message = form.get('info_message')
        scenario.report_http = 'report_http' in form
        scenario.strace = 'strace' in form
        scenario.add_upstream_certs = 'add_upstream_certs' in form
        scenario.only_exported_activities = 'only_exported_activities' in form

    db.session.commit()

    return scenario
示例#3
0
def login(form):
    check_form(form, required_fields)

    user = user_loader(form['username'])
    if not user or not bcrypt.checkpw(form['password'].encode('utf-8'), user.password):
        raise LoginError()

    user.is_authenticated = True
    db.session.add(user)
    db.session.commit()
    login_user(user, remember=True)
示例#4
0
def add(form):
    check_form(form, required_fields)

    if user_loader(form['username']):
        raise FieldExistsError('User', 'username')

    hashed_password = bcrypt.hashpw(form['password'].encode('utf-8'), bcrypt.gensalt())
    user = User(username=form['username'], password=hashed_password, is_authenticated=True)  # login on registration
    db.session.add(user)
    db.session.commit()
    login_user(user, remember=True)  # login on registration

    add_default_settings(user)  # add default settings for user
示例#5
0
def edit(id, form):
    check_form(form, required_fields)

    certificate = Certificate.query.get(id)

    if certificate:
        certificate.name = form['name']
        certificate.description = form.get('description')
        certificate.custom_cert_domain = form.get('custom_cert_domain')
        certificate.custom_cert = form.get('custom_cert')
        certificate.custom_ca = form.get('custom_ca')

        db.session.commit()

    return certificate
示例#6
0
def add(form):
    check_form(form, required_fields)

    certificate = Certificate(
        user=current_user,
        name=form['name'],
        description=form.get('description'),
        custom_cert_domain=form.get('custom_cert_domain'),
        custom_cert=form.get('custom_cert'),
        custom_ca=form.get('custom_ca'),
        is_default=False)

    db.session.add(certificate)
    db.session.commit()

    return certificate