Beispiel #1
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': 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()
Beispiel #2
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()
Beispiel #3
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()
Beispiel #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='')

        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()
Beispiel #5
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()
Beispiel #6
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()
Beispiel #7
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 = {
        '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()
Beispiel #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=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()