コード例 #1
0
ファイル: views.py プロジェクト: smallfish01/mhn
def create_user():
    missing = User.check_required(request.json)
    if missing:
        return error_response(apierrors.API_FIELDS_MISSING.format(missing),
                              400)
    else:
        user = get_datastore().create_user(email=request.json.get('email'),
                                           password=encrypt_password(
                                               request.json.get('password')))
        userrole = user_datastore.find_role('admin')
        user_datastore.add_role_to_user(user, userrole)

        try:
            db.session.add(user)
            db.session.flush()

            apikey = ApiKey(user_id=user.id,
                            api_key=str(uuid.uuid4()).replace("-", ""))
            db.session.add(apikey)

            db.session.commit()
        except IntegrityError:
            return error_response(errors.AUTH_USERNAME_EXISTS, 400)
        else:
            return jsonify(user.to_dict())
コード例 #2
0
def create_clean_db():
    """
    Use from a python shell to create a fresh database.
    """
    with mhn.test_request_context():
        db.create_all()
        # Creating superuser entry.
        superuser = user_datastore.create_user(
            email=mhn.config.get('SUPERUSER_EMAIL'),
            password=hash(mhn.config.get('SUPERUSER_ONETIME_PASSWORD')))
        adminrole = user_datastore.create_role(name='admin', description='')
        user_datastore.add_role_to_user(superuser, adminrole)
        user_datastore.create_role(name='user', description='')
        db.session.flush()

        apikey = ApiKey(user_id=superuser.id,
                        api_key=str(uuid.uuid4()).replace("-", ""))
        db.session.add(apikey)
        db.session.flush()

        from os import path

        from mhn.api.models import DeployScript, RuleSource
        from mhn.tasks.rules import fetch_sources
        # Creating a initial deploy scripts.
        # Reading initial deploy script should be: ../../scripts/
        #|-- deploy_conpot.sh
        #|-- deploy_dionaea.sh
        #|-- deploy_snort.sh
        #|-- deploy_kippo.sh
        deployscripts = {
            'Ubuntu - Conpot': path.abspath('./scripts/deploy_conpot.sh'),
            'Ubuntu - Dionaea': path.abspath('./scripts/deploy_dionaea.sh'),
            'Ubuntu - Cowrie': path.abspath('./scripts/deploy_cowrie.sh'),
            'Ubuntu - Amun': path.abspath('./scripts/deploy_amun.sh'),
            'Ubuntu - Glastopf': path.abspath('./scripts/deploy_glastopf.sh'),
            'Ubuntu - Wordpot': path.abspath('./scripts/deploy_wordpot.sh'),
            'Ubuntu - RDPHoney': path.abspath('./scripts/deploy_rdphoney.sh'),
            'Ubuntu - UHP': path.abspath('./scripts/deploy_uhp.sh'),
        }
        for honeypot, deploypath in deployscripts.iteritems():
            with open(deploypath, 'r') as deployfile:
                initdeploy = DeployScript()
                initdeploy.script = deployfile.read()
                initdeploy.notes = 'Initial deploy script for {}'.format(
                    honeypot)
                initdeploy.user = superuser
                initdeploy.name = honeypot
                db.session.add(initdeploy)

        # Creating an initial rule source.
        rules_source = mhn.config.get('SNORT_RULES_SOURCE')
        if not mhn.config.get('TESTING'):
            rulesrc = RuleSource()
            rulesrc.name = rules_source['name']
            rulesrc.uri = rules_source['uri']
            rulesrc.name = 'Default rules source'
            db.session.add(rulesrc)
            db.session.commit()
コード例 #3
0
def create_superuser_entry():
    # Creating superuser entry.
    superuser = user_datastore.create_user(
        email=mhn.config.get('SUPERUSER_EMAIL'),
        password=hash(mhn.config.get('SUPERUSER_ONETIME_PASSWORD')))
    adminrole = user_datastore.create_role(name='admin', description='')
    user_datastore.add_role_to_user(superuser, adminrole)
    user_datastore.create_role(name='user', description='')
    db.session.flush()

    apikey = ApiKey(user_id=superuser.id,
                    api_key=str(uuid.uuid4()).replace("-", ""))
    db.session.add(apikey)
    db.session.flush()

    return superuser
コード例 #4
0
def create_clean_db():
    """
    Use from a python shell to create a fresh database.
    """
    with mhn.test_request_context():
        db.create_all()
        # Creating superuser entry.
        superuser = user_datastore.create_user(
            email=mhn.config.get('SUPERUSER_EMAIL'),
            password=encrypt(mhn.config.get('SUPERUSER_PASSWORD')))
        adminrole = user_datastore.create_role(name='admin', description='')
        user_datastore.add_role_to_user(superuser, adminrole)
        user_datastore.create_role(name='user', description='')
        db.session.flush()

        apikey = ApiKey(user_id=superuser.id,
                        api_key=str(uuid.uuid4()).replace("-", ""))
        db.session.add(apikey)
        db.session.flush()

        from os import path

        from mhn.api.models import DeployScript, RuleSource
        from mhn.tasks.rules import fetch_sources
        # Creating a initial deploy scripts.
        # Reading initial deploy script should be: ../../scripts/
        #|-- deploy_conpot.sh
        #|-- deploy_dionaea.sh
        #|-- deploy_snort.sh
        #|-- deploy_kippo.sh
        deployscripts = [
            ['Ubuntu - Conpot', '../scripts/deploy_conpot.sh'],
            ['Ubuntu - Drupot', '../scripts/deploy_drupot.sh'],
            ['Ubuntu - Wordpot', '../scripts/deploy_wordpot.sh'],
            ['Ubuntu - Shockpot', '../scripts/deploy_shockpot.sh'],
            ['Ubuntu - p0f', '../scripts/deploy_p0f.sh'],
            ['Ubuntu - Suricata', '../scripts/deploy_suricata.sh'],
            ['Ubuntu - Glastopf', '../scripts/deploy_glastopf.sh'],
            ['Ubuntu - ElasticHoney', '../scripts/deploy_elastichoney.sh'],
            ['Ubuntu - Amun', '../scripts/deploy_amun.sh'],
            ['Ubuntu - Snort', '../scripts/deploy_snort.sh'],
            ['Ubuntu - Cowrie', '../scripts/deploy_cowrie.sh'],
            [
                'Ubuntu 14.04/Centos 7 - Dionaea',
                '../scripts/deploy_dionaea.sh'
            ],
            ['Raspberry Pi - Dionaea', '../scripts/deploy_raspberrypi.sh'],
            [
                'Ubuntu - Dionaea with HTTP',
                '../scripts/deploy_dionaea_http.sh'
            ],
            [
                'Ubuntu - Shockpot Sinkhole',
                '../scripts/deploy_shockpot_sinkhole.sh'
            ],
        ]
        for honeypot, deploypath in reversed(deployscripts):

            with open(path.abspath(deploypath), 'r') as deployfile:
                initdeploy = DeployScript()
                initdeploy.script = deployfile.read()
                initdeploy.notes = 'Initial deploy script for {}'.format(
                    honeypot)
                initdeploy.user = superuser
                initdeploy.name = honeypot
                db.session.add(initdeploy)

        # Creating an initial rule source.
        rules_source = mhn.config.get('SNORT_RULES_SOURCE')
        if not mhn.config.get('TESTING'):
            rulesrc = RuleSource()
            rulesrc.name = rules_source['name']
            rulesrc.uri = rules_source['uri']
            rulesrc.name = 'Default rules source'
            db.session.add(rulesrc)
            db.session.commit()
            fetch_sources()