예제 #1
0
def main():
    lib.print_title("""
    _________________________________________
    [                                       ]
    [                                       ]
    [           Welcome to BinBot           ]
    [            Made by Mili-NT            ]
    [                                       ]
    [_______________________________________]
    """)
    while True:
        configchoice = lib.print_input("Load config file? [y]/[n]")
        if configchoice.lower() not in ['y', 'n', 'yes', 'no']:
            lib.print_error("Invalid Input.")
            continue
        elif configchoice.lower() in ['y', 'yes']:
            vars_dict = load_config()
            break
        elif configchoice.lower() in ['no', 'n']:
            vars_dict = manual_setup()
            break
    try:
        Non_API_Search(vars_dict)
    except KeyboardInterrupt:
        lib.print_status(f"Operation cancelled...")
예제 #2
0
def load_config():
    parser = ConfigParser()
    while True:
        configpath = lib.print_input('Enter the full path of the config file')
        if path.isfile(configpath) is True:
            parser.read(configpath, encoding='utf-8-sig')
            workpath = parser.get('initial_vars', 'workpath')
            stop_input = parser.get('initial_vars', 'stop_input')
            if stop_input == str('True'):
                stop_input = True
            else:
                stop_input = int(stop_input)
            limiter = int(parser.get('initial_vars', 'limiter'))
            cooldown = int(parser.get('initial_vars', 'cooldown'))
            yara_scanning = parser.getboolean('initial_vars', 'yara_scanning')
            if yara_scanning is True:
                yara_dir = f"{syspath[0]}/yara_rules"
                search_rules = yara.compile(
                    filepaths={
                        f.replace(".yar", ""): path.join(
                            f'{yara_dir}/general_rules/', f)
                        for f in listdir(f'{yara_dir}/general_rules/') if
                        path.isfile(path.join(f'{yara_dir}/general_rules/', f))
                        and f.endswith(".yar")
                    })
                binary_rules = yara.compile(
                    filepaths={
                        f.replace(".yar", ""): path.join(
                            f'{yara_dir}/binary_rules/', f)
                        for f in listdir(f'{yara_dir}/binary_rules/') if
                        path.isfile(path.join(f'{yara_dir}/binary_rules/', f))
                        and f.endswith(".yar")
                    })
            else:
                search_rules = []
                binary_rules = []
            break
        else:
            lib.print_error("No such file found")
            continue
    vars_dict = {
        'workpath': workpath,
        'stop_input': stop_input,
        'limiter': limiter,
        'cooldown': cooldown,
        'yara_scanning': yara_scanning,
        'search_rules': search_rules,
        'binary_rules': binary_rules,
    }
    try:
        print("\n")
        for x in vars_dict.keys():
            if x != 'search_rules' and x != 'binary_rules':
                print(f"\x1b[94m[{x}]\x1b[0m: " +
                      f"\x1b[1;32;40m{str(vars_dict[x])}\x1b[0m")
                print("\x1b[94m---------------------\x1b[0m")
    finally:
        print("\n")
    return vars_dict
예제 #3
0
def manual_setup():
    # Save path
    while True:
        workpath = lib.print_input("Enter the path you wish to save text documents to (enter curdir for current directory)")
        if workpath.lower() == 'curdir':
            if name.lower() == 'nt':
                workpath = getcwd()
            else:
                workpath = syspath[0]
        if path.isdir(workpath):
            lib.print_success("Valid Path...")
            if workpath.endswith('\\') or workpath.endswith('/'):
                pass
            else:
                if name.lower == 'nt':
                    workpath = workpath + str('\\')
                else:
                    workpath = workpath + str('/')
            break
        else:
            lib.print_error("Invalid path, check input...")
            continue
    # Looping
    while True:
        try:
            stopinput_input = lib.print_input("Run in a constant loop? [y]/[n]")
            if stopinput_input.lower() == 'y':
                stop_input = True
            elif stopinput_input.lower() == 'n':
                stop_input = int(lib.print_input("Enter the amount of successful pulls you wish to make (enter 0 for infinite)"))
            # Limiter and Cooldown
            try: limiter = int(lib.print_input("Enter the request limit you wish to use (recommended: 5)"))
            except: limiter = 5
            try: cooldown = int(lib.print_input("Enter the cooldown between IP bans/Archive scrapes (recommended: 1200)"))
            except: cooldown = 1200
            break
        except ValueError:
            lib.print_error("Invalid Input.")
            continue
    while True:
        yara_choice = lib.print_input("Enable scanning documents using YARA rules? [y/n]")
        if yara_choice.lower() not in ['y', 'n', 'yes', 'no']:
            lib.print_error("Invalid Input.")
            continue
        elif yara_choice.lower() in ['y', 'yes']:
            yara_scanning = True
            break
        elif yara_choice.lower() in ['n', 'no']:
            yara_scanning = False
            break
    # Yara Compiling
    if yara_scanning is True:
        yara_dir = f"{getcwd()}/yara_rules"
        search_rules = yara.compile(
            filepaths={f.replace(".yar", ""): path.join(f'{yara_dir}/general_rules/', f) for f in listdir(f'{yara_dir}/general_rules/') if
                       path.isfile(path.join(yara_dir, f)) and f.endswith(".yar")})
        binary_rules = yara.compile(
            filepaths={f.replace(".yar", ""): path.join(f'{yara_dir}/binary_rules/', f) for f in listdir(f'{yara_dir}/binary_rules/') if
                       path.isfile(path.join(yara_dir, f)) and f.endswith(".yar")})
    else:
        search_rules = []
        binary_rules = []
    # Saving
    while True:
        savechoice = lib.print_input('Save configuration to file for repeated use? [y]/[n]')
        if savechoice.lower() == 'n':
            break
        elif savechoice.lower() == 'y':
            configname = lib.print_input("Enter the config name (no extension)")
            try:
                with open(configname + '.ini', 'w+') as cfile:
                    cfile.write(
f"""[initial_vars]
workpath = {workpath}
stop_input = {stop_input}
limiter = {limiter}
cooldown = {cooldown}
yara_scanning = {yara_scanning}""")
                    break
            except Exception as e:
                print(f"{e}")
                break
    vars_dict = {
        'workpath': workpath,
        'stop_input': stop_input,
        'limiter': limiter,
        'cooldown': cooldown,
        'yara_scanning': yara_scanning,
        'search_rules': search_rules,
        'binary_rules': binary_rules,
    }
    try:
        print("\n")
        for x in vars_dict.keys():
            if x != 'search_rules' and x != 'binary_rules':
                if name == 'nt':
                    print(f"{x}]: {str(vars_dict[x])}")
                    print("---------------------")
                else:
                    print(f"\x1b[94m[{x}]\x1b[0m: " + f"\x1b[1;32;40m{str(vars_dict[x])}\x1b[0m")
                    print("\x1b[94m---------------------\x1b[0m")
    finally:
        print("\n")
    return vars_dict
예제 #4
0
파일: BinBot.py 프로젝트: scodx/BinBot
def config(configpath):
    """
    :param configpath: path to config file, if it is blank or non-existent, it runs manual setup
    :return: vars_dict, a dictionary containing all the variables needed to run the main functions
    """
    # Manual Setup:
    if path.isfile(configpath) is False:
        # Saving options (workpath and saveall):
        while True:
            workpath = lib.print_input(
                "Enter the path you wish to save text documents to (enter curdir for current directory)"
            )
            workpath = syspath[0] if workpath.lower() == 'curdir' else workpath
            if path.isdir(workpath):
                lib.print_success("Valid Path...")
                workpath = workpath if any(
                    [workpath.endswith('\\'),
                     workpath.endswith('/')]) else f'{workpath}/'
            else:
                lib.print_error("Invalid path, check input...")
                continue
            savechoice = input(
                "Save all documents (Enter N to only save matched documents)? [y/n]: "
            )
            saveall = True if savechoice.lower() in ['y', 'yes'] else False
            break
        # Services to Enable (services):
        while True:
            for x in collectors.service_names.keys():
                lib.print_status(f"[{x}]: {collectors.service_names[x]}")
            service_choice = lib.print_input(
                "Enter the number(s) of the services you wish to scrape, "
                "separated by a comma").replace(" ", '').split(',')
            services = [
                collectors.service_names[int(x)] for x in service_choice
                if int(x) in collectors.service_names.keys()
            ]
            services = list(collectors.service_names.values()
                            ) if services == [] else services
            break
        # Looping, Limiter, and Cooldown Input (stop_input, limiter, cooldown):
        while True:
            loop_input = lib.print_input("Run in a constant loop? [y]/[n]")
            if loop_input.lower() == 'y':
                stop_input = True
            else:
                stop_input = int(
                    lib.print_input(
                        "Enter the amount of times you want to fetch the archives: "
                    ))
                # If they enter 0 or below pastes to fetch, run in an infinite loop:
                stop_input = True if stop_input <= 0 else stop_input
            # Limiter and Cooldown
            limiter = int(
                lib.print_input(
                    "Enter the request limit you wish to use (recommended: 5)")
            )
            cooldown = int(
                lib.print_input(
                    "Enter the cooldown between IP bans/Archive scrapes (recommended: 600)"
                ))
            # If no values are entered, select the recommended
            limiter = 5 if any(
                [limiter <= 0, isinstance(limiter, int) is False]) else limiter
            cooldown = 600 if any(
                [cooldown <= 0,
                 isinstance(cooldown, int) is False]) else cooldown
            break
        # YARA (yara_scanning)
        while True:
            yara_choice = lib.print_input(
                "Enable scanning documents using YARA rules? [y/n]")
            if yara_choice.lower() not in ['y', 'n', 'yes', 'no']:
                lib.print_error("Invalid Input.")
                continue
            elif yara_choice.lower() in ['y', 'yes']:
                yara_scanning = True
            elif yara_choice.lower() in ['n', 'no']:
                yara_scanning = False
            break
        # Building Settings Dict:
        vars_dict = {
            'workpath': workpath,
            'stop_input': stop_input,
            'limiter': limiter,
            'cooldown': cooldown,
            'yara_scanning': yara_scanning,
            'services': services,
            'saveall': saveall,
        }
        # Saving
        savechoice = lib.print_input(
            'Save configuration to file for repeated use? [y]/[n]')
        if savechoice.lower() == 'y':
            configname = lib.print_input(
                "Enter the config name (no extension)")
            configname = configname.split(
                ".")[0] if '.json' in configname else configname
            json.dump(vars_dict, open(f"{configname}.json", 'w'))
    # Loading Config:
    else:
        vars_dict = json.load(open(configpath))
    # YARA Compilation:
    # YARA rules aren't written to files because they cant be serialized
    if vars_dict['yara_scanning']:
        vars_dict['search_rules'] = yara.compile(
            filepaths={
                f.split('.')[0]: path.join(
                    f'{syspath[0]}/yara_rules/general_rules/', f)
                for f in listdir(f'{syspath[0]}/yara_rules/general_rules/')
                if path.isfile(
                    path.join(f'{syspath[0]}/yara_rules/general_rules/', f))
                and f.endswith(".yar") or f.endswith(".yara")
            })
        vars_dict['binary_rules'] = yara.compile(
            filepaths={
                f.split('.')[0]: path.join(
                    f'{syspath[0]}/yara_rules/binary_rules/', f)
                for f in listdir(f'{syspath[0]}/yara_rules/binary_rules/')
                if path.isfile(
                    path.join(f'{syspath[0]}/yara_rules/binary_rules/', f))
                and f.endswith(".yar") or f.endswith(".yara")
            })
    # Display and Return:
    try:
        print("\n")
        for x in vars_dict.keys():
            if x != 'search_rules' and x != 'binary_rules':
                print(f"\x1b[94m[{x}]\x1b[0m: " +
                      f"\x1b[1;32;40m{str(vars_dict[x])}\x1b[0m")
                print("\x1b[94m---------------------\x1b[0m")
    finally:
        print("\n")
        return vars_dict