コード例 #1
0
ファイル: __init__.py プロジェクト: Averroes/mhn
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': path.abspath('../scripts/deploy_conpot.sh'),
            'Ubuntu - Dionaea': path.abspath('../scripts/deploy_dionaea.sh'),
            'Ubuntu - Snort': path.abspath('../scripts/deploy_snort.sh'),
            'Ubuntu - Kippo': path.abspath('../scripts/deploy_kippo.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 - Shockpot': path.abspath('../scripts/deploy_shockpot.sh'),
            'Raspberry Pi - Dionaea': path.abspath('../scripts/deploy_raspberrypi.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()
            fetch_sources()
コード例 #2
0
ファイル: views.py プロジェクト: raum01/mhn
def create_script():
    missing = Script.check_required(request.json)
    if missing:
        return error_response(errors.API_FIELDS_MISSING.format(missing), 400)
    else:
        script = Script(**request.json)
        script.user = current_user
        db.session.add(script)
        db.session.commit()
        return jsonify(script.to_dict())
コード例 #3
0
ファイル: views.py プロジェクト: robinlennox/CHN-Server
def create_script():
    missing = Script.check_required(request.json)
    if missing:
        return error_response(errors.API_FIELDS_MISSING.format(missing), 400)
    else:
        script = Script(**request.json)
        script.user = current_user
        db.session.add(script)
        db.session.commit()
        return jsonify(script.to_dict())
コード例 #4
0
ファイル: __init__.py プロジェクト: Cyberwatch/mhn
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='')

        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
        deployscripts = {
            'Conpot': path.abspath('../scripts/deploy_conpot.sh'),
            'Dionaea': path.abspath('../scripts/deploy_dionaea.sh'),
            'Snort': path.abspath('../scripts/deploy_snort.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 = 'Ubuntu 12.04 {}'.format(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()
コード例 #5
0
ファイル: views.py プロジェクト: Cyberwatch/mhn
def update_script():
    script = Script.query.get(request.json.get('id'))
    script.user = current_user
    for editable in Script.editable_fields():
        if editable in request.json:
            setattr(script, editable, request.json[editable])
    db.session.add(script)
    db.session.commit()
    return jsonify(script.to_dict())
コード例 #6
0
ファイル: views.py プロジェクト: robinlennox/CHN-Server
def update_script():
    script = Script.query.get(request.json.get('id'))
    script.user = current_user
    for editable in Script.editable_fields():
        if editable in request.json:
            setattr(script, editable, request.json[editable])
    db.session.add(script)
    db.session.commit()
    return jsonify(script.to_dict())
コード例 #7
0
def reload_scripts():
    from os import path
    from mhn.api.models import DeployScript

    superuser = user_datastore.get_user(mhn.config.get('SUPERUSER_EMAIL'))

    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'),
    }

    db.session.query(DeployScript).delete()
    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)
            db.session.commit()
コード例 #8
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()
コード例 #9
0
def reload_scripts():
    from mhn.api.models import DeployScript

    superuser = user_datastore.get_user(mhn.config.get('SUPERUSER_EMAIL'))
    custom_path = './custom_scripts/'

    deployscripts = {
        'Default - Conpot':
        os.path.abspath('./scripts/deploy_conpot.sh'),
        'Default - Dionaea':
        os.path.abspath('./scripts/deploy_dionaea.sh'),
        'Default - Cowrie':
        os.path.abspath('./scripts/deploy_cowrie.sh'),
        'Default - RDPHoney':
        os.path.abspath('./scripts/deploy_rdphoney.sh'),
        'Default - UHP':
        os.path.abspath('./scripts/deploy_uhp.sh'),
        'Default - Elasticpot':
        os.path.abspath('./scripts/deploy_elasticpot.sh'),
        'Default - BigHP':
        os.path.abspath('./scripts/deploy_big-hp.sh'),
        'Default - ssh-auth-logger':
        os.path.abspath('./scripts/deploy_ssh-auth-logger.sh'),
        'Default - Honeydb-Agent':
        os.path.abspath('./scripts/deploy_honeydb-agent.sh')
    }

    f = []
    for (dirpath, dirnames, filenames) in os.walk(custom_path):
        f.extend(filenames)
        break
    for fname in f:
        p = os.path.abspath(custom_path + fname)
        if os.path.isfile(p):
            n = pretty_name(os.path.basename(p))
            deployscripts[n] = p

    db.session.query(DeployScript).delete()
    for honeypot, deploypath in sorted(deployscripts.items()):
        with open(deploypath, 'r') as deployfile:
            initdeploy = DeployScript()
            initdeploy.script = deployfile.read()
            initdeploy.notes = 'Vanilla deploy script for {}'.format(honeypot)
            initdeploy.user = superuser
            initdeploy.name = honeypot
            db.session.add(initdeploy)
            db.session.commit()
コード例 #10
0
def create_clean_db():
    """
    Use from a python shell to create a fresh database.
    """
    with mhn.test_request_context():
        db.create_all()
        superuser = create_superuser_entry()

        from mhn.api.models import DeployScript
        # Creating a initial deploy scripts.
        deployscripts = {
            'Default - Conpot':
            os.path.abspath('./scripts/deploy_conpot.sh'),
            'Default - Dionaea':
            os.path.abspath('./scripts/deploy_dionaea.sh'),
            'Default - Cowrie':
            os.path.abspath('./scripts/deploy_cowrie.sh'),
            'Default - RDPHoney':
            os.path.abspath('./scripts/deploy_rdphoney.sh'),
            'Default - UHP':
            os.path.abspath('./scripts/deploy_uhp.sh'),
            'Default - Elasticpot':
            os.path.abspath('./scripts/deploy_elasticpot.sh'),
            'Default - BigHP':
            os.path.abspath('./scripts/deploy_big-hp.sh'),
            'Default - ssh-auth-logger':
            os.path.abspath('./scripts/deploy_ssh-auth-logger.sh'),
            'Default - Honeydb-Agent':
            os.path.abspath('./scripts/deploy_honeydb-agent.sh')
        }
        for honeypot, deploypath in sorted(deployscripts.items()):
            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)

        db.session.commit()
コード例 #11
0
ファイル: __init__.py プロジェクト: evkapsal/CHN-Server
def reload_scripts():
    from mhn.api.models import DeployScript

    superuser = user_datastore.get_user(mhn.config.get('SUPERUSER_EMAIL'))
    custom_path = './custom_scripts/'

    deployscripts = {
        'Ubuntu - Conpot': os.path.abspath('./scripts/deploy_conpot.sh'),
        'Ubuntu - Dionaea': os.path.abspath('./scripts/deploy_dionaea.sh'),
        'Ubuntu - Cowrie': os.path.abspath('./scripts/deploy_cowrie.sh'),
        'Ubuntu - Amun': os.path.abspath('./scripts/deploy_amun.sh'),
        'Ubuntu - Glastopf': os.path.abspath('./scripts/deploy_glastopf.sh'),
        'Ubuntu - Wordpot': os.path.abspath('./scripts/deploy_wordpot.sh'),
        'Ubuntu - RDPHoney': os.path.abspath('./scripts/deploy_rdphoney.sh'),
        'Ubuntu - UHP': os.path.abspath('./scripts/deploy_uhp.sh'),
    }

    f = []
    for (dirpath, dirnames, filenames) in os.walk(custom_path):
        f.extend(filenames)
        break
    for fname in f:
        p = os.path.abspath(custom_path + fname)
        if os.path.isfile(p):
            n = pretty_name(os.path.basename(p))
            deployscripts[n] = p

    db.session.query(DeployScript).delete()
    for honeypot, deploypath in sorted(deployscripts.items()):
        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)
            db.session.commit()
コード例 #12
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()