Exemplo n.º 1
0
def accountsMan():
    if request.method == 'POST':
        return redirect("api/v2/resources/group", code=307)
    users = DatabaseHandler.find('users', None)
    groups = DatabaseHandler.find('groups', None)
    return render_template('accountsMan.html', username='******', group_num='2', users_group='4', group_id='1',
                           users=users, groups=groups)
Exemplo n.º 2
0
    def get():

        json_data = request.args.to_dict()
        if not json_data:
            return {'message': 'No input data provided'}, 400
        data, errors = platform_get_request_schema.load(json_data)
        if errors:
            return errors, 422
        results = {"success: false"}
        if "all" in data:
            if data["all"]:
                from Database.database_handler import DatabaseHandler
                return DatabaseHandler.find_all("platforms")
            else:
                results = PlatformAPI.platform_interface.getAvailablePlugins()
                if results is None:
                    results = {"success": False}
        elif "status" in data:
            results = PlatformAPI.platform_interface.getPlatformStatus(
                data["platform_ID"])
        elif "alias" in data:
            from Database.database_handler import DatabaseHandler
            results = DatabaseHandler.find("platforms", data["platform_ID"])
            if results:
                results = results["main"]["alias"]
        return results
Exemplo n.º 3
0
 def get():
     json_data = request.get_json(force=True)
     if not json_data:
         return {'message': 'No input data provided'}, 400
     from Database.database_handler import DatabaseHandler
     results = DatabaseHandler.find(json_data["collection_name"],
                                    json_data["document_id"])
     if results is None:
         return {"success": False}, 404
     return results
Exemplo n.º 4
0
 def get():
     json_data = request.args.to_dict()
     # if not json_data:
     #     return {'message': 'No input data provided'}, 400
     data, errors = user_get_request_schema.load(json_data)
     if errors:
         return errors, 422
     from Database.database_handler import DatabaseHandler
     if "username" in data:
         results = DatabaseHandler.find('users', data["username"])
         if results is None or not results:
             return {"success": False}, 404
         return user_schema.dump(User(**results))
     else:
         results = DatabaseHandler.find_all('users')
         formatted_results = []
         for result in results:
             r = user_schema.dump(User(**result))
             formatted_results.append(r[0])
         return formatted_results
Exemplo n.º 5
0
 def delete():
     json_data = request.get_json(force=True)
     if not json_data:
         return {'message': 'No input data provided'}, 400
     from Database.database_handler import DatabaseHandler
     collection_name = json_data["collection_name"]
     document_id = json_data["document_id"]
     results = DatabaseHandler.delete(collection_name, document_id)
     if results:
         return user_response_schema.dump({"success": results})
     else:
         return {"success": results}, 404
Exemplo n.º 6
0
def login():
    error = None
    if request.method == 'POST':
        user = DatabaseHandler.find('users', request.form['username'])
        if user is None or user['password'] != request.form['password']:
            error = 'Invalid Credentials. Please try again.'
        else:
            session['username'] = request.form['username']
            session['group_id'] = user['group_id']
            session['remote_ip'] = user['remote_ip']
            session['logged_in'] = True
            return redirect(url_for('home'))
    return render_template('login.html', error=error)
Exemplo n.º 7
0
    def get():
        json_data = request.args.to_dict()
        # if not json_data:
        #     return {'message': 'No input data provided'}, 400
        data, errors = group_get_request_schema.load(json_data)
        if errors:
            return errors, 422
        from Database.database_handler import DatabaseHandler
        if "group_id" in data:
            results = DatabaseHandler.find('groups', data["group_id"])
            if results is None or not results:
                return {"success": False}, 404
            return group_schema.dump(Group(**results))
        else:
            results = DatabaseHandler.find_all('groups')
            formatted_results = []
            for result in results:
                if 'platforms' not in result:
                    result['platforms'] = []
                if 'note' not in result:
                    result['note'] = ""
                if 'alias' not in result:
                    result['alias'] = ""
                formatted_platforms = []
                for platform in result['platforms']:
                    from Database.database_handler import DatabaseHandler
                    platform_object = DatabaseHandler.find(
                        "platforms", platform)
                    if platform_object:
                        alias = platform_object["main"]["alias"]
                        name = platform_object["main"]["name"]
                        formatted_platform = alias + " ID: " + str(
                            platform) + " Type: " + name
                        formatted_platforms.append(formatted_platform)
                r = group_schema.dump(Group(**result))
                r[0]['platforms'] = formatted_platforms
                formatted_results.append(r[0])

            return formatted_results
Exemplo n.º 8
0
 def put():
     json_data = request.get_json(force=True)
     if not json_data:
         return {'message': 'No input data provided'}, 400
     # data, errors = database_modify_schema.load(json_data)
     # if errors:
     #     print(errors)
     #     return errors, 422
     from Database.database_handler import DatabaseHandler
     collection_name = json_data["collection_name"]
     document_id = json_data["document_id"]
     document = json_data["document"]
     results = DatabaseHandler.update(collection_name, document_id,
                                      document)
     if results:
         return user_response_schema.dump({"success": results})
     else:
         return {"success": results}, 404
Exemplo n.º 9
0
def home():
    if session.get('logged_in') is None:
        return redirect(url_for('login'))
    username = session['username']
    group_id = session['group_id']
    remote_ip = session['remote_ip']

    group_info = DatabaseHandler.find('groups', group_id)
    print(group_info)

    platforms = group_info['platforms']
    print(platforms)
    team = group_info['members']
    print(team)

    return render_template('index.html',
                           username=username,
                           platforms=platforms,
                           remote_ip=remote_ip,
                           team=team,
                           re=re)
Exemplo n.º 10
0
    def put():
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400

        data, errors = group_update_request_schema.load(json_data)

        if errors:
            return errors, 422
        from AccountManager.account_manager import AccountManager

        results = False
        if "command" in data and "platform_ids" in data:
            if data["command"] == "attach":
                for plat in data["platform_ids"]:
                    results = AccountManager.attach_platform(
                        data["group_id"], plat)
                    if not results:
                        print("Failed to attach {} to group {}".format(
                            plat, data["group_id"]))
                        continue

                    plat_info = DatabaseHandler.find('platforms', plat)
                    for current in plat_info['subplatforms']:
                        if 'Rocketchat' == current['name']:
                            platform_man = PlatformManagerInstance.get_instance(
                            )
                            # running = platform_man.getPlatformStatus(plat_info['main']['id'], current['id'])
                            running = True
                            if not running:
                                platform_man.platform_interface.startPlatform(
                                    plat_info['main']['id'], current['id'])

                            group_info = DatabaseHandler.find(
                                'groups', data["group_id"])
                            command = {'command': 'registerUser', 'param': {}}
                            for user in group_info['members']:
                                command['param']['username'] = user
                                command['param'][
                                    'email'] = user + "@citsystem.com"
                                user_info = DatabaseHandler.find('users', user)
                                command['param']['password'] = user_info[
                                    'password']
                                success, user_id = platform_man.platform_interface.requestHandler(
                                    plat_info['main']['id'], current['id'],
                                    command)
                                if not success:
                                    print("ERROR: Unable to register user: "******"command"] == "detach":
                results = AccountManager.detach_platform(data["platform_id"])
        else:
            results = AccountManager.update_group(data["group_id"],
                                                  data["updated_group"])

        if results:
            return group_response_schema.dump({"success": results})
        else:
            return {"success": False}, 409
Exemplo n.º 11
0
def home():
    if session.get('logged_in') is None:
        return redirect(url_for('login'))

    username = session['username']
    group_id = session['group_id']
    remote_ip = session['remote_ip']

    group_info = DatabaseHandler.find('groups', group_id)
    print ('Group Info -> {}'.format(group_info))

    try:
        platforms = group_info['platforms']
    except KeyError as e:
        print("No platform for user: "******"https://searchengineland.com/guide/how-to-use-google-to-search">[email protected]</a> >.<'
    print('Group platforms available -> {}'.format(platforms))

    # platform_data = DatabaseHandler.find('platforms', platforms[0])
    # print('Subplatforms from database -> {}'.format(platform_data))

    ogList = []

    authTokens = {}
    for p in platforms:
        platform_data = DatabaseHandler.find('platforms', p)
        subplats = platform_data['subplatforms']
        p = platform_data['main']['name']
        result = {p: []}
        for plat in subplats:
            result[p].append([plat['name'], plat['ip_port'], plat['id']])
            if plat['name'] == "Rocketchat":
                platform_interface = PlatformManagerInstance.get_instance().platform_interface
                token = platform_interface.rocketChatLoginUser(platform_data['main']['id'], plat['id'], username, session['password'])
                session['authToken'] = token['Auth_Token']
                authTokens[plat['id']] = token
                session['authToken'] = token['Auth_Token']
        # print(result)

        ogList.append(result)


    pprint(ogList)
    print("^^^ogList")
    """
    [
        {
          'Hackathon':
                [
                    ['chat', '129.108.7.17:3000],
                    ['wiki', '129.108.7.17:8085],
                    ['File Upload']
                ]    
        },
        {
          'Rapid Cyber Challenge':

        }
    ]
    """
    team = group_info['members']
    # print(team)

    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            print('No file part')
            return redirect(request.url)

        # Gets the file and renames it to "Data_Time_GroupId.extensionType
        file = request.files['file']
        user_file = file.filename
        temp = user_file.split('.')
        currentDT = datetime.datetime.now()
        file.filename = str(session['group_id']) + currentDT.strftime("_%Y-%m-%d_%H-%M-%S") + "." + temp[len(temp)-1]

        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            send_from_directory(app.config['UPLOAD_FOLDER'], filename)
            session['filename'] = file.filename[:-5] + "txt"
            return redirect(url_for('home'))


    #read_directory = 'Download_Files'
    #downloadable_files = get_downloadable_files(read_directory)
    #os.chdir('../../')

    # Test the test_get_downloadables method
    main_directory = 'Download_Files'
    downloadable_files = test_get_downloadables(main_directory)

    platform_names = []
    for plat in platforms:
        platform_names.append(DatabaseHandler.find('platforms', plat)['main']['name'])

    try:
        tmp = session['filename']
    except KeyError:
        session['filename'] = 'thatonefile.txt'
    return render_template('index.html', username=username, platforms=platform_names, main_directory=main_directory,
                           downloadable_files=downloadable_files, ogList=ogList, remote_ip=remote_ip, team=team,
                           time=time, platforms_id=platforms, filename=session['filename'])
Exemplo n.º 12
0
    short_names = args.short_names
    logging.info(f"short_names = {short_names}")
    executor_class = args.executor_class
    logging.info(f"executor_class = {args.executor_class}")
    wait_time = args.wait_time
    logging.info(f"wait_time = {args.wait_time}")
    logging.info("Arguments parsed.")

    # Executor Factory
    executorFactory = ExecutorFactory()

    with (DatabaseEngine(database_type='sqlite',
                         path_to_database_file=db_path)) as database_engine:
        if do_build_dictionaries:
            logging.info("Creating all dictionaries for database...")
            with DatabaseHandler(
                    database_engine.get_engine()) as database_session:
                database_session.build_all_dictionaries()
            logging.info("All dictionaries for database created.")
            try:

                while True:
                    executorFactory.do_job(
                        executor_class,
                        DatabaseHandler(database_engine.get_engine()),
                        short_names)
                    logging.info("Finished check...")
                    logging.info("New check starting in 5 seconds...")
                    time.sleep(wait_time)
            except KeyboardInterrupt:
                logging.info("Finishing program after CTRL+C...")
            finally:
Exemplo n.º 13
0
def home():
    if session.get('logged_in') is None:
        return redirect(url_for('login'))

    username = session['username']
    group_id = session['group_id']
    remote_ip = session['remote_ip']

    group_info = DatabaseHandler.find('groups', group_id)
    #print ('Group Info -> {}'.format(group_info))

    try:
        platforms = group_info['platforms']
    except KeyError as e:
        print("No platform for user: "******"You currently don't have access to any platforms bruh. Please contact us at [email protected] >.<"
    #print('Group platforms available -> {}'.format(platforms))

    #platform_data = DatabaseHandler.find('platforms', platforms[0])
    #print('Subplatforms from database -> {}'.format(platform_data))

    ogList = []

    for p in platforms:
        platform_data = DatabaseHandler.find('platforms', p)
        subplats = platform_data['subplatforms']
        p = platform_data['main']['name']
        result = {p: []}
        for plat in subplats:
            result[p].append([plat['name'], plat['ip_port']])
        # print(result)

        ogList.append(result)

    from pprint import pprint
    pprint(ogList)
    print("^^^ogList")
    """
    [
        {
          'Hackathon':
                [
                    ['chat', '129.108.7.17:3000],
                    ['wiki', '129.108.7.17:8085],
                    ['File Upload']
                ]    
        },
        {
          'Rapid Cyber Challenge':
                
        }
    ]
    """
    team = group_info['members']
    # print(team)

    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            print('No file part')
            return redirect(request.url)
        file = request.files['file']
        print(file)
        print(file.filename)
        UserFile = file.filename
        file.filename = str(session['group_id']) + UserFile
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            send_from_directory(app.config['UPLOAD_FOLDER'], filename)
            return redirect(url_for('home'))

    # print(os.getcwd())
    read_directory = 'Download_Files'
    downloadable_files = get_downloadable_files(read_directory)
    os.chdir('../../')

    platform_names = []
    for plat in platforms:
        platform_names.append(
            DatabaseHandler.find('platforms', plat)['main']['name'])

    return render_template('index.html',
                           username=username,
                           platforms=platform_names,
                           read_directory=read_directory,
                           downloadable_files=downloadable_files,
                           ogList=ogList,
                           remote_ip=remote_ip,
                           team=team,
                           time=time)