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()
def create_rule_source(): missing = RuleSource.check_required(request.json) if missing: return error_response(errors.API_FIELDS_MISSING.format(missing), 400) else: rsource = RuleSource(**request.json) try: db.session.add(rsource) db.session.commit() except IntegrityError: return error_response( errors.API_SOURCE_EXISTS.format(request.json['uri']), 400) else: return jsonify(rsource.to_dict())
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()