def do_help(self, key): if key in help_dict: print(cool.orange(help_dict[key])) elif key == 'desc': for k in help_dict.keys(): print(cool.orange(help_dict[k])) else: self.do_cls('') print(cool.green(pydictor_art_text)) print(helpmsg)
def uniqify_enter(original_file_path): storepath = os.path.join( get_result_store_path(), "%s_%s%s" % (tool_fun_str[1].upper(), get_buildtime(), filextension)) with open(original_file_path) as o_f: with open(storepath, 'a') as s_f: for _ in fast_uniqify(o_f.readlines()): s_f.write(_) print("[+] Start : {0:10} lines".format( cool.orange(finishcounter(original_file_path)))) print("[+] Current : {0:10} lines".format( cool.orange(finishcounter(storepath)))) print("[+] Cost : {0:} seconds".format( cool.orange(str(time.time() - start)[:6]))) print("[+] Store in: {0}".format(cool.orange(storepath)))
def shreder_dir(directory, rewritecounts=dir_rewrite_count): filepaths = [] dirpaths = [] print(CRLF + "[+] Shredding '%s' ..." % cool.orange(directory)) try: newdirectoryname = os.path.join( os.path.dirname(directory), "".join( chr(random.randint(97, 122)) for _ in range_compatible(1, 6))) os.rename(directory, newdirectoryname) directory = newdirectoryname except: traceback.print_exc() exit(CRLF + cool.red( "[-] Error: cannot rename root directory name, Please check permissions" )) for rootpath, subdirsname, filenames in os.walk(directory): # get all directories dirpaths.extend( [os.path.abspath(os.path.join(rootpath, _)) for _ in subdirsname]) # get all absolute file path filepaths.extend( [os.path.abspath(os.path.join(rootpath, _)) for _ in filenames]) for filepath in filepaths: try: os.chmod(filepath, stat.S_IREAD | stat.S_IWRITE) except: pass for _ in range_compatible(0, rewritecounts): print("[+] Rewrite count: %d" % (_ + 1)) for filepath in filepaths: rewrite(filepath) for filepath in filepaths: truncating(filepath) for filepath in filepaths: renamefile(filepath) renamedir(dirpaths) os.chdir(os.path.join(directory, "..")) try: shutil.rmtree(directory) except OSError as ex: print( cool.fuchsia("[!] Error: Cannot removing directory: '%s' " % directory)) traceback.print_exc() print(cool.orange("[+] Completely!"))
def init_extend(extend_choice, rmself): # no if extend_choice == cli_no_extend: print(cool.white("[+] Use extend mode: %s" % cli_no_extend)) # other elif extend_choice.isdigit() and int(extend_choice) > 0: if extend_choice == cli_net_extend: print(cool.white("[+] Use extend mode: /24")) tmp1 = [] rm1 = [] for _ in targets_pool: rm1.append(_) e_split = _.split(".") for e in range(0, 256): tmp1.append("{0}.{1}.{2}.{3}".format(e_split[0], e_split[1], e_split[2], str(e))) targets_pool.extend(tmp1) if rmself == 'true': rmlistself(rm1, targets_pool) elif 1 <= int(extend_choice) <= 255: print(cool.orange("[+] Use extend mode: +/- %s" % extend_choice)) tmp2 = [] rm2 = [] for _ in targets_pool: rm2.append(_) e_split = _.split(".") for e in range(min(int(e_split[3]) - int(extend_choice), int(e_split[3]) - 1) if int(e_split[3]) - int(extend_choice) >= 0 else 0, min(int(e_split[3]) + int(extend_choice) + 1, 256)): tmp2.append("{0}.{1}.{2}.{3}".format(e_split[0], e_split[1], e_split[2], str(e))) targets_pool.extend(tmp2) if rmself == 'true': rmlistself(rm2, targets_pool)
def init_port(port_choice): # port choice # file if os.path.isfile(port_choice): port_use_file(port_choice) # all port elif port_choice == cli_all_port: set_port_string("0-65535") for _ in range(0, 65536): ports_pool.append(str(_)) # other else: specify_ports = port_choice.split(',') for portchunk in specify_ports: # range portchunk = portchunk.strip() if "-" in portchunk: port_split = portchunk.split("-") if not (len(port_split) == 2 and port_split[0].isdigit() and port_split[1].isdigit() and int(port_split[0]) <= int(port_split[1])): exit(cool.red("[-] Port range error\n")) else: for _ in range(int(port_split[0]), int(port_split[1]) + 1): ports_pool.append(str(_)) # single or multi elif str(portchunk).isdigit() and 0 <= int(portchunk) <= 65535: ports_pool.append(portchunk) else: exit(cool.red("[-] Specify port error\n")) set_port_string(port_choice.strip()) if len(ports_pool) != 0: print(cool.orange("[+] Load: {0} ports".format(len(ports_pool)))) else: exit(cool.red("[-] Cannot find port"))
def counter_operator(original_file_path, justsave, justview, encodeflag, head, tail, view_count=default_view_items): items = Counter( open(original_file_path, 'r').read().replace( string.punctuation, "").split(counter_split)).most_common(view_count) items_length = len(items) storepath = os.path.join( get_result_store_path(), "%s_%s%s" % (COUNTER_prefix, get_buildtime(), filextension)) if view_count > view_counter_switcher: exit(CRLF + cool.fuchsia("[!] view items should Leq {0}".format( view_counter_switcher))) elif items_length < view_count: exit(CRLF + cool.fuchsia("[!] max items is {0}".format(items_length))) print("{0}Welcome to the COUNTER tool".format(" " * 8)) if justsave: with open(storepath, "a") as f: for _ in items: f.write(operator.get(encodeflag)(head + _[0] + tail) + CRLF) finishprinter(finishcounter(storepath), storepath) elif justview: print(CRLF * 2) for item in items: print("{0}Word:{2:20} -> {1:10} times".format( " " * 5, cool.orange(item[1]), cool.orange(item[0]))) print("[+] Cost:{} seconds".format( cool.orange(str(time.time() - startime)[:6]))) else: print(CRLF * 2) for item in items: print("{0}Word:{2:20} -> {1:10} times".format( " " * 5, cool.orange(item[1]), cool.orange(item[0]))) print(CRLF) with open(storepath, 'a') as f: for _ in items: f.write(operator.get(encodeflag)(head + _[0] + tail) + CRLF) finishprinter(finishcounter(storepath), storepath)
def shreder_file(filepath, rewritecounts=file_rewrite_count): try: os.chmod(filepath, stat.S_IREAD | stat.S_IWRITE) except: pass for _ in range_compatible(0, rewritecounts): rewrite(filepath) truncating(filepath) newname = renamefile(filepath) os.remove(newname) print("[+] Shredded %s Completely!" % cool.orange(filepath))
def init(target_choice, port_choice, extend_choice, rmself): print(cool.green("[+] Init ...")) print(cool.white("[+] Threads: {0}".format(str(get_threads())))) check_cmd_status() init_target(target_choice) init_port(port_choice) auto_choose_start() init_extend(extend_choice, rmself=rmself) print(cool.orange("[+] Load: {0} targets".format(len(unique(targets_pool))))) if len(unique(targets_pool)) > 0: create_output_file() print(cool.green("[+] Init sucess\n"))
def select_by_port(original_path, port_num): save_path = get_select_result_path(port_num) with open(save_path, 'a') as s: with open(original_path, 'r') as f: for line in f.readlines(): chunk = line.strip().split(',') for status in port_selection: if len(chunk) == 5 and chunk[1] == port_num and chunk[ 3] == status: print(cool.white("[+] %s" % chunk[0])) s.write(chunk[0] + '\n') if os.path.getsize(save_path) > 0: print(cool.orange("\n[+] Store in: %s" % save_path)) else: os.remove(save_path) exit(cool.fuchsia("\n[!] Select nothing"))
def shredder_enter(*args): fnum = 0 _ = "".join(args) if _ and os.path.isdir(_): shreder_dir(_) elif _ and os.path.isfile(_): shreder_file(_) elif _ and _.upper() in prefix_range: for filename in os.listdir(get_result_store_path()): if _.upper() in str(filename[0:10]).upper(): fnum += 1 shreder_file(os.path.join(get_result_store_path(), filename)) if fnum == 0: exit(CRLF + cool.orange("[+] prefix %s files has been clean" % _.upper())) else: exit(CRLF + cool.red("[-] invalid shredder path_or_dir arguments"))
elif os.path.isfile(args.conf): set_conf_path(args.conf) build_conf_dic() else: exit(CRLF + cool.red("[-] Please specify the exists configuration file")) elif args.tool: if len(args.tool) >= 1: if args.tool[0] in tool_range: # shredder if args.tool[0] == tool_range[0]: if len(args.tool) == 1 and os.listdir( get_result_store_path()): shredder_enter(get_result_store_path()) elif len(args.tool) == 1: exit(CRLF + cool.orange("[+] %s has been clean" % get_result_store_path())) elif len(args.tool) == 2: shredder_enter(args.tool[1]) else: exit(CRLF + cool.red("[-] %s arguments wrong" % tool_range[0])) print("[+] Cost :{} seconds".format( cool.orange(str(time.time() - startime)[:6]))) # uniqifer elif len(args.tool) == 2 and args.tool[0] == tool_range[1]: if os.path.isfile(args.tool[1]): uniqifer_enter(args.tool[1]) else: exit(CRLF + "[-] Please specify the exists file for %s" % cool.red(tool_range[1]))
build_conf_dic() else: exit( CRLF + cool.red("[-] Please specified the exists configuration file")) if args.tool: if len(args.tool) >= 1: if args.tool[0] in tool_fun_str: # shredder if args.tool[0] == tool_fun_str[0]: if len(args.tool) == 1 and os.listdir( get_result_store_path()): cleaner(get_result_store_path()) elif len(args.tool) == 1: exit(CRLF + cool.orange("[+] %s has been clean" % get_result_store_path())) elif len(args.tool) == 2: cleaner(args.tool[1]) else: exit(CRLF + cool.red("[-] %s arguments wrong" % tool_fun_str[0])) # uniqify elif len( args.tool ) == 2 and args.tool[0] == tool_fun_str[1] and os.path.isfile( args.tool[1]): uniqify_enter(args.tool[1]) elif len(args.tool) == 1: exit(CRLF + cool.red("[-] need other extra arguments")) else: exit(CRLF +
{1} ----------------------------------[ {2} ]------------------------------------ [+]help desc (View the description) | [+]show name (Show current settings) [+]cls/clear (Clean the screen) | [+]quit/exit (Quit the progress) [+]run (Build the dictionary) | | Usage Exp :show (Show all of settings) | help desc (view all of descriptions) -------------------------------[ {3} ]-------------------------------- [+]{4} [+]{5} [+]{6} | [+]{7} [+]{8} [+]{9} [+]{10} [+]{11} [+]{12} | [+]{13} [+]{14} [+]{15} [+]{16} [+]{17} [+]{18} | | Usage Exp :sname zhang wei zw zwell | * Each setting supports multiple values '''.format( cool.orange("Social Engineering Dictionary Builder"), cool.green("Build by LandGrey"), cool.yellow("command"), cool.yellow("setting options"), sedb_range[0], sedb_range[1], sedb_range[2], sedb_range[3], sedb_range[4], sedb_range[5], sedb_range[6], sedb_range[7], sedb_range[8], sedb_range[9], sedb_range[10], sedb_range[11],
from lib.fun import cool if __name__ == "__main__": start_time = time.time() print("{}".format(cool.green(shakala_art_text))) arg = parse_args() if str(arg.threads).isdigit() and int(arg.threads) >= 1: set_threads(int(arg.threads)) if arg.analyse != '': if os.path.exists(arg.analyse): result_handler(arg.analyse, result_file_path) if os.path.getsize(result_file_path) > 0: print( cool.orange( "\n[+] Store in: {0}".format(result_file_path))) else: try: os.remove(result_file_path) except: pass print(cool.fuchsia("\n[!] analyse output nothing")) print( cool.orange("[+] Cost : {0:.6} seconds".format(time.time() - start_time))) else: exit(cool.red("[-] Directory:%s don't exists" % arg.analyse)) elif arg.select[0] != '': if os.path.isfile(arg.select[0]): if str(arg.select[1]).isdigit(): select_by_port(arg.select[0], arg.select[1])
def parse_args(): parser = argparse.ArgumentParser( prog='shakala', formatter_class=argparse.RawTextHelpFormatter, description=cool.green( '*[+] A tiny batch multi-ports scanner base on nmap. [+]*\n') + cool.green(' [+] Build by LandGrey email:[email protected]\n'), usage=cool.orange(''' shakala.py [options] -t target -p port -e extend -a dir -s file port | service --rmself will remove itself --threads threads'''.format(cli_all_port, cli_no_extend, cli_net_extend))) parser.add_argument('-t', dest='target', metavar='target', type=str, default="", help=cool.yellow(''' specify www.example.com,192.168.1.11,192.168.1-10.1-10 dir use all files in specify directory path use single file''')) parser.add_argument('-p', dest='port', metavar='port', type=str, default=port_list_file_path, help=cool.yellow(''' specify 80-89,888,8080-8088 {0:8} use all ports: 0-65535 path (default): {1}'''.format(cli_all_port, port_list_file_path))) parser.add_argument('-e', dest='extend', metavar='mode', type=str, default=cli_no_extend, help=cool.yellow(''' numbers increase or decrease numbers target in /24 range {0:8} extend whole network address: /24 {1:8} (default)'''.format(cli_net_extend, cli_no_extend))) parser.add_argument('-a', dest='analyse', metavar='dir', type=str, default='', help=cool.yellow(''' dir analyse the result use directory''')) # original_path, service parser.add_argument('-s', dest='select', metavar='select', type=str, nargs=2, default=('', ''), help=cool.yellow(''' file_path port_or_service file must be shakala 'result_' prefix file''')) parser.add_argument('--rmself', dest='rmself', action="store_true", default='default', help=cool.yellow(''' provide for '-e extend' ''')) parser.add_argument('--threads', dest='threads', metavar='threads', type=str, default=get_threads(), help=cool.yellow(''' threads default:{0}'''.format(get_threads()))) if len(sys.argv) == 1: sys.argv.append('-h') args = parser.parse_args() return args