Beispiel #1
0
def _cli_start(commands):
    command_check = {
        'help': False,
        'sample': False,
        'version': False,
        'about': False,
        'update': False,
        'show-payloads': False,
        'shell-storm': False,
        'select-payload': False,
        'input': False,
        'assembly': False,
        'output': False,
    }
    n = 0
    for arg in sys.argv:
        if arg == '-h' or arg == '--help':
            command_check['help'] = n
        elif arg == '-e' or arg == '--samples-cmd':
            command_check['sample'] = n
        elif arg == '-v' or arg == '--version':
            command_check['version'] = n
        elif arg == '-a' or arg == '--about':
            command_check['about'] = n
        elif arg == '-u' or arg == '--update':
            command_check['update'] = n
        elif arg == '-l' or arg == '--show-payloads':
            command_check['show-payloads'] = n
        elif arg == '-s' or arg == '--shell-storm':
            command_check['shell-storm'] = n
        elif arg == '-p' or arg == '--payload':
            command_check['select-payload'] = n
        elif arg == '-i' or arg == '--input':
            command_check['input'] = n
        elif arg == '-c' or arg == '--assembly-code':
            command_check['assembly'] = n
        elif arg == '-o' or arg == '--output':
            command_check['output'] = n
        n += 1
    if len(sys.argv) is 2:
        if command_check['help'] is not False:
            _help_cli(help_cli)
        elif command_check['about'] is not False:
            about()
        elif command_check['update'] is not False:
            _update(__version__)
        elif command_check['version'] is not False:
            _version()
        elif command_check['show-payloads'] is not False:
            warn(
                'Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n'
            )
            warn(
                'Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n'
            )
            _show_payloads(commands, False)
        elif command_check['sample'] is not False:
            _show_samples(cmd_samples)
        else:
            warn('command not found!\n')
            _help_cli(help_cli)
        sys.exit(0)
    if len(sys.argv) is 3:
        if command_check['show-payloads'] is not False and command_check[
                'shell-storm'] is False:
            try:
                content = sys.argv[command_check['show-payloads'] + 1]
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            search_flag = 0
            if content[0] == '*' and content[-1] == '*':
                search_flag = 1
                content = content[1:-1]
            elif content[0] == '*':
                search_flag = 2
                content = content[1:]
            elif content[-1] == '*':
                search_flag = 3
                content = content[:-1]
            elif '*' in content and content[0] != '*' and content[
                    -1] != 0 and len(content) >= 3 and content.count('*') is 1:
                search_flag = 4
                c1 = content.rsplit('*')[0]
                c2 = content.rsplit('*')[1]
            payloads = _show_payloads(commands, True)
            if len(payloads) >= 1:
                warn(
                    'Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n'
                )
                warn(
                    'Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n'
                )
                for payload in payloads:
                    if search_flag is 0:
                        if str(content) == payload.rsplit('/')[0]:
                            info(payload + '\n')
                    elif search_flag is 1:
                        if str(content) in payload:
                            info(payload + '\n')
                    elif search_flag is 2:
                        if str(content) == payload[-len(content):]:
                            info(payload + '\n')
                    elif search_flag is 3:
                        if str(content) == payload[:len(content)]:
                            info(payload + '\n')
                    elif search_flag is 4:
                        if str(c1) == payload[:len(c1)] and str(
                                c2) == payload[-len(c2):]:
                            info(payload + '\n')
            else:
                warn(
                    'no payload find for your platform, to show all of payloads please use only "--show-payloads" switch\n'
                )
                sys.exit(0)
        elif command_check['show-payloads'] is not False and command_check[
                'shell-storm'] is not False:
            warn(
                'Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n'
            )
            warn(
                'Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n'
            )
            _show_payloads(commands, False)
            warn('shell-storm shellcodes:\n')
            _grab_all()
        elif command_check['select-payload'] is not False:
            try:
                mypayload = sys.argv[command_check['select-payload'] + 1]
                os = mypayload.rsplit('/')[0]
                func = mypayload.rsplit('/')[1]
                encode = mypayload.rsplit('/')[2]
                encode_tmp = sys.argv[2].rsplit('/')[2][:3]
                encodes = commands['shellcode'][1]['generate'][os][func]['']
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            payload_tmp = os + '/' + func + '/' + encode_tmp
            payload_flag = False
            for _ in _show_payloads(commands, True):
                if payload_tmp in _:
                    payload_flag = True
            if payload_flag is True:
                run = getattr(
                    __import__('lib.generator.%s.%s' % (os, func),
                               fromlist=['run']), 'run')
                shellcode = run('')
                info('Generated shellcode is:\n\n' +
                     op(encode_process(encode, shellcode, os, func), os) +
                     '\n\n')
        else:
            warn('command not found!\n')
            _help_cli(help_cli)
        sys.exit(0)
    elif len(sys.argv) is 4:
        if command_check['shell-storm'] is not False and command_check[
                'show-payloads'] is False:
            if sys.argv[2] == 'search':
                _search_shellcode(True, sys.argv[3])
            elif sys.argv[2] == 'download':
                _download_shellcode(True, sys.argv[3], '')
            else:
                warn('command not found!\n')
                _help_cli(help_cli)
        elif command_check['shell-storm'] is not False and command_check[
                'show-payloads'] is not False:
            try:
                content = sys.argv[command_check['show-payloads'] + 2]
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            search_flag = 0
            if content[0] == '*' and content[-1] == '*':
                search_flag = 1
                content = content[1:-1]
            elif content[0] == '*':
                search_flag = 2
                content = content[1:]
            elif content[-1] == '*':
                search_flag = 3
                content = content[:-1]
            elif '*' in content and content[0] != '*' and content[
                    -1] != 0 and len(content) >= 3 and content.count('*') is 1:
                search_flag = 4
                c1 = content.rsplit('*')[0]
                c2 = content.rsplit('*')[1]
            payloads = _show_payloads(commands, True)
            if len(payloads) >= 1:
                warn(
                    'Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n'
                )
                warn(
                    'Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n'
                )
                for payload in payloads:
                    if search_flag is 0:
                        if str(content) == payload.rsplit('/')[0]:
                            info(payload + '\n')
                    elif search_flag is 1:
                        if str(content) in payload:
                            info(payload + '\n')
                    elif search_flag is 2:
                        if str(content) == payload[-len(content):]:
                            info(payload + '\n')
                    elif search_flag is 3:
                        if str(content) == payload[:len(content)]:
                            info(payload + '\n')
                    elif search_flag is 4:
                        if str(c1) == payload[:len(c1)] and str(
                                c2) == payload[-len(c2):]:
                            info(payload + '\n')
            else:
                warn(
                    'no payload find for your platform, to show all of payloads please use only "--show-payloads" switch\n'
                )
                sys.exit(0)

            _search_shellcode(True, content)
        elif command_check['select-payload'] is not False and command_check[
                'assembly'] is not False:
            try:
                mypayload = sys.argv[command_check['select-payload'] + 1]
                os = mypayload.rsplit('/')[0]
                func = mypayload.rsplit('/')[1]
                encode = mypayload.rsplit('/')[2]
                encode_tmp = sys.argv[2].rsplit('/')[2][:3]
                encodes = commands['shellcode'][1]['generate'][os][func]['']
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            payload_tmp = os + '/' + func + '/' + encode_tmp
            payload_flag = False
            for _ in _show_payloads(commands, True):
                if payload_tmp in _:
                    payload_flag = True
            if payload_flag is True:
                run = getattr(
                    __import__('lib.generator.%s.%s' % (os, func),
                               fromlist=['run']), 'run')
                shellcode = run('')
                info('Generated shellcode(Assembly) is:\n\n' +
                     encode_process(encode, shellcode, os, func) + '\n\n')
        else:
            warn('command not found!\n')
            _help_cli(help_cli)
        sys.exit(0)
    elif len(sys.argv) is 5:
        if command_check['select-payload'] is not False and command_check[
                'input'] is not False:
            try:
                mypayload = sys.argv[command_check['select-payload'] + 1]
                myinput = sys.argv[command_check['input'] + 1]
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            if len(mypayload.rsplit('/')) is 2:
                if mypayload in _show_payloads(commands, True):
                    filename = myinput
                    language = mypayload.rsplit('/')[0]
                    encode = mypayload.rsplit('/')[1]
                    try:
                        content = open(filename, 'rb').read()
                    except:
                        warn('sorry, cann\'t find file\n')
                        sys.exit(0)
                    obf_code(language, encode, filename, content, True)
            if len(mypayload.rsplit('/')) is 3:
                os = mypayload.rsplit('/')[0]
                func = mypayload.rsplit('/')[1]
                encode = mypayload.rsplit('/')[2]
                encode_tmp = mypayload.rsplit('/')[2][:3]
                data = myinput.rsplit('~~~')
                payload_tmp = os + '/' + func + '/' + encode_tmp
                payload_flag = False
                for _ in _show_payloads(commands, True):
                    if payload_tmp in _:
                        payload_flag = True
                if payload_flag is True:
                    run = getattr(
                        __import__('lib.generator.%s.%s' % (os, func),
                                   fromlist=['run']), 'run')
                    shellcode = run(data)
                    info('Generated shellcode is:\n\n' +
                         op(encode_process(encode, shellcode, os, func), os) +
                         '\n\n')
                else:
                    warn(
                        'no payload find, to show all of payloads please use "--show-payloads" switch\n'
                    )
                    sys.exit(0)
            else:
                warn(
                    'no payload find, to show all of payloads please use "--show-payloads" switch\n'
                )
                sys.exit(0)
        elif command_check['select-payload'] is not False and command_check[
                'output'] is not False:

            try:
                mypayload = sys.argv[command_check['select-payload'] + 1]
                myoutput = sys.argv[command_check['output'] + 1]
                os = mypayload.rsplit('/')[0]
                func = mypayload.rsplit('/')[1]
                encode = mypayload.rsplit('/')[2]
                encode_tmp = sys.argv[2].rsplit('/')[2][:3]
                encodes = commands['shellcode'][1]['generate'][os][func]['']
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            payload_tmp = os + '/' + func + '/' + encode_tmp
            payload_flag = False
            for _ in _show_payloads(commands, True):
                if payload_tmp in _:
                    payload_flag = True
            if payload_flag is True:
                run = getattr(
                    __import__('lib.generator.%s.%s' % (os, func),
                               fromlist=['run']), 'run')
                shellcode = run('')
                shellcode_asm = encode_process(encode, shellcode, os, func)
                shellcode_op = op(encode_process(encode, shellcode, os, func),
                                  os)
                info('Generated shellcode is:\n\n' + shellcode_op + '\n\n')
                file_output(myoutput, func, '', os, encode, shellcode_asm,
                            shellcode_op)
            else:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
        else:
            warn('command not found!\n')
            _help_cli(help_cli)
        sys.exit(0)
    elif len(sys.argv) is 6:

        if command_check['shell-storm'] is not False and command_check[
                'output'] is not False:
            try:
                id = sys.argv[command_check['shell-storm'] + 2]
                name = sys.argv[command_check['output'] + 1]
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            if sys.argv[2] == 'download':
                _download_shellcode(True, sys.argv[3], sys.argv[5])
            else:
                warn('command not found!\n')
                _help_cli(help_cli)
        elif command_check['select-payload'] is not False and command_check[
                'input'] is not False and command_check[
                    'assembly'] is not False:
            try:
                myinput = sys.argv[command_check['input'] + 1]
                mypayload = sys.argv[command_check['select-payload'] + 1]
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            if len(mypayload.rsplit('/')) is 2:
                if mypayload in _show_payloads(commands, True):
                    filename = myinput
                    language = mypayload.rsplit('/')[0]
                    encode = mypayload.rsplit('/')[1]
                    try:
                        content = open(filename, 'rb').read()
                    except:
                        warn('sorry, cann\'t find file\n')
                        sys.exit(0)
                    obf_code(language, encode, filename, content, True)
            if len(mypayload.rsplit('/')) is 3:
                os = mypayload.rsplit('/')[0]
                func = mypayload.rsplit('/')[1]
                encode = mypayload.rsplit('/')[2]
                encode_tmp = mypayload.rsplit('/')[2][:3]
                data = myinput.rsplit('~~~')
                payload_tmp = os + '/' + func + '/' + encode_tmp
                payload_flag = False
                for _ in _show_payloads(commands, True):
                    if payload_tmp in _:
                        payload_flag = True
                if payload_flag is True:
                    run = getattr(
                        __import__('lib.generator.%s.%s' % (os, func),
                                   fromlist=['run']), 'run')
                    shellcode = run(data)
                    info('Generated shellcode(Assembly) is:\n\n' +
                         encode_process(encode, shellcode, os, func) + '\n\n')
                else:
                    warn(
                        'no payload find, to show all of payloads please use "--show-payloads" switch\n'
                    )
                    sys.exit(0)
            else:
                warn(
                    'no payload find, to show all of payloads please use "--show-payloads" switch\n'
                )
                sys.exit(0)
        else:
            warn('command not found!\n')
            _help_cli(help_cli)
        sys.exit(0)

    elif len(sys.argv) is 7:
        if command_check['select-payload'] is not False and command_check[
                'input'] is not False and command_check['output'] is not False:
            try:
                mypayload = sys.argv[command_check['select-payload'] + 1]
                myinput = sys.argv[command_check['input'] + 1]
                myoutput = sys.argv[command_check['output'] + 1]
            except:
                warn('command not found!\n')
                _help_cli(help_cli)
                sys.exit(0)
            if len(mypayload.rsplit('/')) is 2:
                if mypayload in _show_payloads(commands, True):
                    filename = myinput
                    language = mypayload.rsplit('/')[0]
                    encode = mypayload.rsplit('/')[1]
                    try:
                        content = open(filename, 'rb').read()
                    except:
                        warn('sorry, cann\'t find file\n')
                        sys.exit(0)
                    obf_code(language, encode, filename, content, True)
                    warn(
                        'you can\'t define output for obfuscating module, file replaced!\n'
                    )
            elif len(mypayload.rsplit('/')) is 3:
                os = mypayload.rsplit('/')[0]
                func = mypayload.rsplit('/')[1]
                encode = mypayload.rsplit('/')[2]
                encode_tmp = mypayload.rsplit('/')[2][:3]
                data = myinput.rsplit('~~~')
                payload_tmp = os + '/' + func + '/' + encode_tmp
                payload_flag = False
                for _ in _show_payloads(commands, True):
                    if payload_tmp in _:
                        payload_flag = True
                if payload_flag is True:
                    run = getattr(
                        __import__('lib.generator.%s.%s' % (os, func),
                                   fromlist=['run']), 'run')
                    shellcode = run(data)
                    shellcode_asm = encode_process(encode, shellcode, os, func)
                    shellcode_op = op(
                        encode_process(encode, shellcode, os, func), os)
                    info('Generated shellcode is:\n\n' + shellcode_op + '\n\n')
                    file_output(myoutput, func, data, os, encode,
                                shellcode_asm, shellcode_op)
                else:
                    warn(
                        'no payload find, to show all of payloads please use "--show-payloads" switch\n'
                    )
                    sys.exit(0)
            else:
                warn(
                    'no payload find, to show all of payloads please use "--show-payloads" switch\n'
                )
                sys.exit(0)
        else:
            warn('command not found!\n')
            _help_cli(help_cli)
        sys.exit(0)
    else:
        warn('command not found!\n')
        _help_cli(help_cli)
    sys.exit(0)
Beispiel #2
0
def getcommand(commands):
    exit_counter = 0
    backup_commands = commands
    crawler = 0
    command_path = ["zsc"]
    command = ""
    while True:
        try:
            command = _input("/".join(command_path), "any", False)
            if command is None:
                _lets_error
        except:
            command = ""
            warn('\nplease use "exit" or "quit" to exit software.\n')
            exit_counter += 1
        if exit_counter is 3:
            error("\nExit\n")
            sys.exit(0)
        check = True
        for option in commands:
            if command == option:
                crawler += 1
                if crawler is 1:
                    commands = commands[option][1]
                    command_path.append(option)
                if crawler is 2:
                    if command == "search":
                        _search_shellcode()
                        exec(_reset)
                    elif command == "download":
                        _download_shellcode()
                        exec(_reset)
                    elif command == "generate":
                        exec(_option_replace)
                    else:
                        while True:
                            filename = _input("filename", "any", True)
                            try:
                                content = open(filename, "rb").read()
                                break
                            except:
                                warn("sorry, cann't find file\n")
                        exec(_option_replace)
                        exec(_refresh)
                        t = True
                        while t:
                            encode = _input("encode", "any", True)
                            for en in commands:
                                if encode == en:
                                    t = False
                            if t is True:
                                warn("please enter a valid encode name\n")
                        obf_code(option, encode, filename, content)
                        exec(_reset)
                if crawler is 3:
                    os = option
                    exec(_option_replace)
                if crawler is 4:
                    func = option
                    exec(_option_replace)
                if crawler is 5:
                    data = []
                    backup_option = option
                    options = option.rsplit("&&")
                    for o in options:
                        if version() is 2:
                            data.append(raw_input("%s:" % o))
                        if version() is 3:
                            data.append(input("%s:" % o))
                    n = 0
                    write("\n")
                    for o in options:
                        info('%s set to "%s"\n' % (o, data[n]))
                        n += 1
                    run = getattr(__import__("lib.generator.%s.%s" % (os, func), fromlist=["run"]), "run")
                    shellcode = run(data)
                    write("\n")
                    for encode in backup_commands["shellcode"][1]["generate"][os][func][backup_option]:
                        info(encode + "\n")
                    write("\n\n")
                    info("enter encode type\n")
                    completer = autocomplete(backup_commands["shellcode"][1]["generate"][os][func][backup_option])
                    readline.set_completer(completer.complete)
                    readline.parse_and_bind("tab: complete")
                    try:
                        encode = _input("zsc", "any", False)
                        if encode is None:
                            _lets_error
                    except:
                        encode = "none"
                        warn('\n"none" encode selected\nplease use "exit" or "quit" to exit software.\n')
                        exit_counter += 1
                    if assembly_code is False:
                        write("\n" + op(encode_process(encode, shellcode, os, func), os) + "\n\n")
                    elif assembly_code is True:
                        write("\n" + encode_process(encode, shellcode, os, func) + "\n\n")
                    exec(_reset)
                exec(_refresh)
                check = False
        if command == "exit":
            write(color.color("reset"))
            sys.exit("Exit")
        elif command == "update":
            _update(__version__)
            exec(_reset)
        elif command == "help":
            exit_counter = 0
            help_(help)
            exec(_reset)
        elif command == "restart":
            exec(_reset)
        elif command == "about":
            about()
            exec(_reset)
        elif command == "version":
            _version()
            exec(_reset)
        else:
            if command != "" and check is True:
                exit_counter = 0
                info("Command not found!\n")
Beispiel #3
0
                    payload_flag = True
            if payload_flag is True:
                run = getattr(
                    __import__('lib.generator.%s.%s' % (os, func),
                               fromlist=['run']), 'run')
                shellcode = run(data)
                try:
                    asm_code = int(asm_code)
                except:
                    asm_code = 'nop'
                if asm_code == 1:
                    info('Generated shellcode(Assembly) is:\n\n' +
                         encode_process(encode, shellcode, os, func) + '\n\n')
                else:
                    info('Generated shellcode is:\n\n' +
                         op(encode_process(encode, shellcode, os, func), os) +
                         '\n\n')
    elif mypayload == 'show_all':
        limit = form.getvalue("limit")
        if limit is not None:
            for _ in _show_payloads(commands, True):
                if limit in _:
                    print('[+]'), _
        if limit is None:
            _show_payloads(commands, False)
        sys.exit(0)
    else:
        print('''please be sure you send all required fields!''')
        sys.exit(0)
else:
    print('''api not found!''')
Beispiel #4
0
def getcommand(commands):

	backup_commands = commands
	crawler = 0
	command_path = ['zsc']
	command = ''
	while True:
		try:
			command = _input('/'.join(command_path), 'any', False)
			if command is None:
				_lets_error
		except:
			warn('interrupted by user!\nExit\n')
			sys.exit(0)
		check = True

		if command.startswith('#'): # allows for comments
			continue

		inContext = ['clear', 'help', 'about', 'version', 'back']
		for option in commands:
			if command == option and command not in inContext:
				crawler += 1
				if crawler is 1:
					commands = commands[option][1]
					command_path.append(option)
				if crawler is 2:
					if command == 'search':
						_search_shellcode(False,0)
						commands = backup_commands
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						crawler = 0
						command_path = ['zsc']
					elif command == 'download':
						_download_shellcode(False,0,'')
						commands = backup_commands
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						crawler = 0
						command_path = ['zsc']
					elif command == 'shell_storm_list':
						_grab_all()
						commands = backup_commands
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						crawler = 0
						command_path = ['zsc']
					elif command == 'generate':
						commands = commands[option]
						command_path.append(option)
					else:
						while True:
							f = []
							import os as OS
							for (dirpath, dirnames, filenames) in OS.walk('.'):
								f.extend(filenames)
								break
							completer = autocomplete(f)
							readline.set_completer(completer.complete)
							filename = _input('filename', 'any', True)
							completer = autocomplete(commands)
							readline.set_completer(completer.complete)
							try:
								content = open(filename, 'rb').read()
								break
							except:
								warn('sorry, cann\'t find file\n')
						commands = commands[option]
						command_path.append(option)
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						t = True
						while t:
							encode = _input('encode', 'any', True)
							for en in commands:
								if encode == en:
									t = False
							if t is True:
								warn('please enter a valid encode name\n')
						obf_code(option, encode, filename, content,False)
						commands = backup_commands
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						crawler = 0
						command_path = ['zsc']
				if crawler is 3:
					os = option
					commands = commands[option]
					command_path.append(option)
				if crawler is 4:
					func = option
					commands = commands[option]
					command_path.append(option)
				if crawler is 5:
					data = []
					backup_option = option
					if option != '':
						options = option.rsplit('&&')
						for o in options:
							data.append(_input(o,'any',True))
						n = 0
						write('\n')
						for o in options:
							info('%s set to "%s"\n' % (o, data[n]))
							n += 1
					run = getattr(
						__import__('lib.generator.%s.%s' % (os, func),
								   fromlist=['run']),
						'run')
					shellcode = run(data)
					write('\n')
					for encode in backup_commands['shellcode'][1]['generate'][
							os][func][backup_option]:
						info(encode + '\n')
					write('\n\n')
					info('enter encode type\n')
					completer = autocomplete(backup_commands['shellcode'][1][
						'generate'][os][func][backup_option])
					readline.set_completer(completer.complete)
					readline.parse_and_bind('tab: complete')
					try:
						encode = _input('/'.join(command_path) + "/encode_type", 'any', False)
						if encode is None:
							_lets_error
					except:
						encode = 'none'
						warn(
							'\n"none" encode selected\n')
					write('\n')
					assembly_code_or_not = _input(
						'Output assembly code?(y or n)', 'any', True)
					if assembly_code_or_not == 'y':
						assembly_code = True
					else:
						assembly_code = False
					if assembly_code is True:
						write('\n'+encode_process(encode, shellcode, os, func) + '\n\n')
					output_shellcode = _input('Output shellcode to screen?(y or n)', 'any', True)
					shellcode_op = op( encode_process(encode, shellcode, os, func), os)
					if output_shellcode == 'y':
						info('Generated shellcode is:\n' + shellcode_op +'\n\n')
					file_or_not = _input('Shellcode output to a .c file?(y or n)', 'any', True)
					if file_or_not == 'y':
						target = _input('Target .c file?', 'any', True)
						file_output(target, func, data, os, encode, shellcode, shellcode_op)
					commands = backup_commands
					completer = autocomplete(commands)
					readline.set_completer(completer.complete)
					readline.parse_and_bind('tab: complete')
					crawler = 0
					command_path = ['zsc']
				completer = autocomplete(commands)
				readline.set_completer(completer.complete)
				readline.parse_and_bind('tab: complete')
				check = False
		if command == 'exit' or command == 'quit':
			write(color.color('reset'))
			sys.exit('Exit')
		elif command == 'update':
			_update(__version__)
			commands = backup_commands
			completer = autocomplete(commands)
			readline.set_completer(completer.complete)
			readline.parse_and_bind('tab: complete')
			crawler = 0
			command_path = ['zsc']
		elif command == 'help':
			_help(help)
		elif command == 'restart':
			commands = backup_commands
			completer = autocomplete(commands)
			readline.set_completer(completer.complete)
			readline.parse_and_bind('tab: complete')
			crawler = 0
			command_path = ['zsc']
		elif command == 'about':
			about()
		elif command == 'version':
			_version()
		elif command == 'clear':
			_clear()
		elif command == 'back':
			if len(command_path) > 1:
				command_path.pop()
				commands = backup_commands
				for option in command_path:
					if option == 'zsc':
						pass
					elif option == command_path[1]:
						commands = commands[option][1]
					else:
						commands = commands[option]
				completer = autocomplete(commands)
				readline.set_completer(completer.complete)
				readline.parse_and_bind('tab: complete')
				crawler -= 1
			else:
				info('Can\'t go back from here!\n')
		else:
			if command != '' and check is True:
				info('Command not found!\n')
Beispiel #5
0
def _cli_start(commands):
	command_check = {
	'help' : False,
	'sample' : False,
	'version' : False,
	'about' : False,
	'update' : False,
	'show-payloads' : False,
	'shell-storm' : False,
	'select-payload' : False,
	'input' : False,
	'assembly' : False,
	'output' : False,
	}
	n = 0
	for arg in sys.argv:
		if arg == '-h' or arg == '--help':
			command_check['help'] = n
		elif arg == '-e' or arg == '--samples-cmd':
			command_check['sample'] = n
		elif arg == '-v' or arg == '--version':
			command_check['version'] = n
		elif arg == '-a' or arg == '--about':
			command_check['about'] = n
		elif arg == '-u' or arg == '--update':
			command_check['update'] = n
		elif arg == '-l' or arg == '--show-payloads':
			command_check['show-payloads'] = n
		elif arg == '-s' or arg == '--shell-storm':
			command_check['shell-storm'] = n
		elif arg == '-p' or arg == '--payload':
			command_check['select-payload'] = n
		elif arg == '-i' or arg == '--input':
			command_check['input'] = n
		elif arg == '-c' or arg == '--assembly-code':
			command_check['assembly'] = n
		elif arg == '-o' or arg == '--output':
			command_check['output'] = n			
		n += 1
	if len(sys.argv) is 2:
		if command_check['help'] is not False:
			_help_cli(help_cli)
		elif command_check['about'] is not False:
			about()
		elif command_check['update'] is not False:
			_update(__version__)
		elif command_check['version'] is not False:
			_version()
		elif command_check['show-payloads'] is not False:
			warn('Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n')
			warn('Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n')
			_show_payloads(commands,False)
		elif command_check['sample'] is not False:
			_show_samples(cmd_samples)
		else:
			warn('command not found!\n')
			_help_cli(help_cli)
		sys.exit(0)
	if len(sys.argv) is 3:
		if command_check['show-payloads'] is not False and command_check['shell-storm'] is False:
			try:
				content = sys.argv[command_check['show-payloads']+1]
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)
			search_flag = 0
			if content[0] == '*' and content[-1] == '*':
				search_flag = 1
				content = content[1:-1]
			elif content[0] == '*':
				search_flag = 2
				content = content[1:]
			elif content[-1] == '*':
				search_flag = 3
				content = content[:-1]
			elif '*' in content and content[0] != '*' and content[-1] != 0 and len(content) >= 3 and content.count('*') is 1:
				search_flag = 4
				c1 = content.rsplit('*')[0]
				c2 = content.rsplit('*')[1]
			payloads = _show_payloads(commands,True)
			if len(payloads) >= 1:
				warn('Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n')
				warn('Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n')
				for payload in payloads:
					if search_flag is 0:
						if str(content) == payload.rsplit('/')[0]:
							info(payload+'\n')
					elif search_flag is 1:
						if str(content) in payload:
							info(payload+'\n')
					elif search_flag is 2:						
						if str(content) == payload[-len(content):]:
							info(payload+'\n')
					elif search_flag is 3:
						if str(content) == payload[:len(content)]:
							info(payload+'\n')
					elif search_flag is 4:
						if str(c1) == payload[:len(c1)] and str(c2) == payload[-len(c2):]:
							info(payload+'\n')
			else:
				warn('no payload find for your platform, to show all of payloads please use only "--show-payloads" switch\n')
				sys.exit(0)
		elif command_check['show-payloads'] is not False and command_check['shell-storm'] is not False:
			warn('Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n')
			warn('Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n')
			_show_payloads(commands,False)
			warn('shell-storm shellcodes:\n')
			_grab_all()
		elif command_check['select-payload'] is not False:
			try:
				mypayload = sys.argv[command_check['select-payload']+1]
				os = mypayload.rsplit('/')[0]
				func = mypayload.rsplit('/')[1]
				encode = mypayload.rsplit('/')[2] 
				encode_tmp = sys.argv[2].rsplit('/')[2][:3]
				encodes = commands['shellcode'][1]['generate'][os][func]['']
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)
			payload_tmp = os+'/'+func+'/'+encode_tmp
			payload_flag = False
			for _ in _show_payloads(commands,True):
				if payload_tmp in _:
					payload_flag = True
			if payload_flag is True:
				run = getattr(
					__import__('lib.generator.%s.%s' % (os, func),
							   fromlist=['run']),
					'run')
				shellcode = run('')
				info('Generated shellcode is:\n\n' +op(encode_process(encode, shellcode, os, func),os) +
							 '\n\n')
		else:
			warn('command not found!\n')
			_help_cli(help_cli)
		sys.exit(0)
	elif len(sys.argv) is 4:
		if command_check['shell-storm'] is not False and command_check['show-payloads'] is False:
			if sys.argv[2] == 'search':
				_search_shellcode(True,sys.argv[3])
			elif sys.argv[2] == 'download':
				_download_shellcode(True,sys.argv[3],'')
			else:
				warn('command not found!\n')
				_help_cli(help_cli)
		elif command_check['shell-storm'] is not False and command_check['show-payloads'] is not False:
			try:
				content = sys.argv[command_check['show-payloads']+2]
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)
			search_flag = 0
			if content[0] == '*' and content[-1] == '*':
				search_flag = 1
				content = content[1:-1]
			elif content[0] == '*':
				search_flag = 2
				content = content[1:]
			elif content[-1] == '*':
				search_flag = 3
				content = content[:-1]
			elif '*' in content and content[0] != '*' and content[-1] != 0 and len(content) >= 3 and content.count('*') is 1:
				search_flag = 4
				c1 = content.rsplit('*')[0]
				c2 = content.rsplit('*')[1]
			payloads = _show_payloads(commands,True)
			if len(payloads) >= 1:
				warn('Note: Shellcode Payloads Sorted By OperatingSystem_Architecture/Function_Name/Encode_Name\n')
				warn('Note: Programming Languages Payloads Sorted By ProgrammingLanguagesName/Encode_Name\n')
				for payload in payloads:
					if search_flag is 0:
						if str(content) == payload.rsplit('/')[0]:
							info(payload+'\n')
					elif search_flag is 1:
						if str(content) in payload:
							info(payload+'\n')
					elif search_flag is 2:						
						if str(content) == payload[-len(content):]:
							info(payload+'\n')
					elif search_flag is 3:
						if str(content) == payload[:len(content)]:
							info(payload+'\n')
					elif search_flag is 4:
						if str(c1) == payload[:len(c1)] and str(c2) == payload[-len(c2):]:
							info(payload+'\n')
			else:
				warn('no payload find for your platform, to show all of payloads please use only "--show-payloads" switch\n')
				sys.exit(0)
		
			_search_shellcode(True,content)
		elif command_check['select-payload'] is not False and command_check['assembly'] is not False:
			try:
				mypayload = sys.argv[command_check['select-payload']+1]
				os = mypayload.rsplit('/')[0]
				func = mypayload.rsplit('/')[1]
				encode = mypayload.rsplit('/')[2] 
				encode_tmp = sys.argv[2].rsplit('/')[2][:3]
				encodes = commands['shellcode'][1]['generate'][os][func]['']
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)
			payload_tmp = os+'/'+func+'/'+encode_tmp
			payload_flag = False
			for _ in _show_payloads(commands,True):
				if payload_tmp in _:
					payload_flag = True
			if payload_flag is True:
				run = getattr(
					__import__('lib.generator.%s.%s' % (os, func),
							   fromlist=['run']),
					'run')
				shellcode = run('')
				info('Generated shellcode(Assembly) is:\n\n' +encode_process(encode, shellcode, os, func) +
							 '\n\n')
		else:
			warn('command not found!\n')
			_help_cli(help_cli)
		sys.exit(0)
	elif len(sys.argv) is 5:
		if command_check['select-payload'] is not False and command_check['input'] is not False:
			try:
				mypayload = sys.argv[command_check['select-payload']+1] 
				myinput = sys.argv[command_check['input']+1]
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)
			if len(mypayload.rsplit('/')) is 2:	
				if mypayload in _show_payloads(commands,True):
					filename = myinput
					language = mypayload.rsplit('/')[0]
					encode = mypayload.rsplit('/')[1]
					try:
						content = open(filename, 'rb').read()
					except:
						warn('sorry, cann\'t find file\n')
						sys.exit(0)
					obf_code(language, encode, filename, content,True)
			if len(mypayload.rsplit('/')) is 3:
				os = mypayload.rsplit('/')[0]
				func = mypayload.rsplit('/')[1]
				encode = mypayload.rsplit('/')[2]
				encode_tmp = mypayload.rsplit('/')[2][:3]
				data = myinput.rsplit('~~~')
				payload_tmp = os+'/'+func+'/'+encode_tmp
				payload_flag = False
				for _ in _show_payloads(commands,True):
					if payload_tmp in _:
						payload_flag = True
				if payload_flag is True:
					run = getattr(
						__import__('lib.generator.%s.%s' % (os, func),
								   fromlist=['run']),
						'run')
					shellcode = run(data)
					info('Generated shellcode is:\n\n' +op(encode_process(encode, shellcode, os, func),os) +
								 '\n\n')
				else:
					warn('no payload find, to show all of payloads please use "--show-payloads" switch\n')
					sys.exit(0)
			else:
				warn('no payload find, to show all of payloads please use "--show-payloads" switch\n')
				sys.exit(0)
		elif command_check['select-payload'] is not False and command_check['output'] is not False:
			
			try:
				mypayload = sys.argv[command_check['select-payload']+1]
				myoutput = sys.argv[command_check['output']+1]
				os = mypayload.rsplit('/')[0]
				func = mypayload.rsplit('/')[1]
				encode = mypayload.rsplit('/')[2] 
				encode_tmp = sys.argv[2].rsplit('/')[2][:3]
				encodes = commands['shellcode'][1]['generate'][os][func]['']
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)
			payload_tmp = os+'/'+func+'/'+encode_tmp
			payload_flag = False
			for _ in _show_payloads(commands,True):
				if payload_tmp in _:
					payload_flag = True
			if payload_flag is True:
				run = getattr(
					__import__('lib.generator.%s.%s' % (os, func),
							   fromlist=['run']),
					'run')
				shellcode = run('')
				shellcode_asm = encode_process(encode, shellcode, os, func)
				shellcode_op = op(encode_process(encode, shellcode, os, func),os) 
				info('Generated shellcode is:\n\n' + shellcode_op +
								 '\n\n')
				file_output(myoutput, func, '', os, encode,
										shellcode_asm, shellcode_op)		
			else:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)	
		else:
			warn('command not found!\n')
			_help_cli(help_cli)
		sys.exit(0)	
	elif len(sys.argv) is 6:
		
		if command_check['shell-storm'] is not False and command_check['output'] is not False:
			try:
				id = sys.argv[command_check['shell-storm']+2]
				name = sys.argv[command_check['output']+1] 
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)	
			if sys.argv[2] == 'download':
				_download_shellcode(True,sys.argv[3],sys.argv[5])
			else:
				warn('command not found!\n')
				_help_cli(help_cli)
		elif command_check['select-payload'] is not False and command_check['input'] is not False and command_check['assembly'] is not False:
			try:
				myinput = sys.argv[command_check['input']+1]
				mypayload = sys.argv[command_check['select-payload']+1]
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)	
			if len(mypayload.rsplit('/')) is 2:
				if mypayload in _show_payloads(commands,True):
					filename = myinput
					language = mypayload.rsplit('/')[0]
					encode = mypayload.rsplit('/')[1]
					try:
						content = open(filename, 'rb').read()
					except:
						warn('sorry, cann\'t find file\n')
						sys.exit(0)
					obf_code(language, encode, filename, content,True)
			if len(mypayload.rsplit('/')) is 3:
				os = mypayload.rsplit('/')[0]
				func = mypayload.rsplit('/')[1]
				encode = mypayload.rsplit('/')[2]
				encode_tmp = mypayload.rsplit('/')[2][:3]
				data = myinput.rsplit('~~~')
				payload_tmp = os+'/'+func+'/'+encode_tmp
				payload_flag = False
				for _ in _show_payloads(commands,True):
					if payload_tmp in _:
						payload_flag = True
				if payload_flag is True:
					run = getattr(
						__import__('lib.generator.%s.%s' % (os, func),
								   fromlist=['run']),
						'run')
					shellcode = run(data)
					info('Generated shellcode(Assembly) is:\n\n' +encode_process(encode, shellcode, os, func) +
								 '\n\n')
				else:
					warn('no payload find, to show all of payloads please use "--show-payloads" switch\n')
					sys.exit(0)
			else:
				warn('no payload find, to show all of payloads please use "--show-payloads" switch\n')
				sys.exit(0)
		else:
			warn('command not found!\n')
			_help_cli(help_cli)
		sys.exit(0)

	elif len(sys.argv) is 7:
		if command_check['select-payload'] is not False and command_check['input'] is not False and command_check['output'] is not False:
			try:
				mypayload = sys.argv[command_check['select-payload']+1]
				myinput = sys.argv[command_check['input']+1]
				myoutput = sys.argv[command_check['output']+1]
			except:
				warn('command not found!\n')
				_help_cli(help_cli)
				sys.exit(0)
			if len(mypayload.rsplit('/')) is 2:	
				if mypayload in _show_payloads(commands,True):
					filename = myinput
					language = mypayload.rsplit('/')[0]
					encode = mypayload.rsplit('/')[1]
					try:
						content = open(filename, 'rb').read()
					except:
						warn('sorry, cann\'t find file\n')
						sys.exit(0)
					obf_code(language, encode, filename, content,True)
					warn('you can\'t define output for obfuscating module, file replaced!\n')
			elif len(mypayload.rsplit('/')) is 3:
				os = mypayload.rsplit('/')[0]
				func = mypayload.rsplit('/')[1]
				encode = mypayload.rsplit('/')[2]
				encode_tmp = mypayload.rsplit('/')[2][:3]
				data = myinput.rsplit('~~~')
				payload_tmp = os+'/'+func+'/'+encode_tmp
				payload_flag = False
				for _ in _show_payloads(commands,True):
					if payload_tmp in _:
						payload_flag = True
				if payload_flag is True:
					run = getattr(
						__import__('lib.generator.%s.%s' % (os, func),
								   fromlist=['run']),
						'run')
					shellcode = run(data)
					shellcode_asm = encode_process(encode, shellcode, os, func)
					shellcode_op = op(encode_process(encode, shellcode, os, func),os)
					info('Generated shellcode is:\n\n' + shellcode_op +
								 '\n\n')
					file_output(myoutput, func, data, os, encode,
										shellcode_asm, shellcode_op)
				else:
					warn('no payload find, to show all of payloads please use "--show-payloads" switch\n')
					sys.exit(0)
			else:
				warn('no payload find, to show all of payloads please use "--show-payloads" switch\n')
				sys.exit(0)
		else:
			warn('command not found!\n')
			_help_cli(help_cli)
		sys.exit(0)
	else:
		warn('command not found!\n')
		_help_cli(help_cli)
	sys.exit(0)
		
Beispiel #6
0
def getcommand(commands):
	exit_counter = 0
	backup_commands = commands
	crawler = 0
	command_path = ['zsc']
	command = ''
	while True:
		try:
			command = _input('/'.join(command_path),'any',False)
			if command is None:
				_lets_error
		except:
			command = ''
			warn('\nplease use "exit" or "quit" to exit software.\n')
			exit_counter += 1
		if exit_counter is 3:
			error('\nExit\n')
			sys.exit(0)
		check = True
		for option in commands:
			if command == option:
				crawler += 1
				if crawler is 1:
					commands = commands[option][1]
					command_path.append(option)
				if crawler is 2:
					if command == 'search':
						_search_shellcode()
						commands = backup_commands
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						crawler = 0
						command_path = ['zsc']
					elif command == 'download':
						_download_shellcode()
						commands = backup_commands
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						crawler = 0
						command_path = ['zsc']
					elif command == 'generate':
						commands = commands[option]
						command_path.append(option)
					else:
						while True:
							f = []
							import os as OS
							for (dirpath, dirnames, filenames) in OS.walk('.'):
								f.extend(filenames)
								break
							completer = autocomplete(f)
							readline.set_completer(completer.complete)
							filename = _input('filename','any',True)
							completer = autocomplete(commands)
							readline.set_completer(completer.complete)
							try:
								content = open(filename,'rb').read()
								break
							except:
								warn('sorry, cann\'t find file\n')
						commands = commands[option]
						command_path.append(option)
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						t = True
						while t:
							encode = _input('encode','any',True)
							for en in commands:
								if encode == en:
									t = False
							if t is True:
								warn('please enter a valid encode name\n')
						obf_code(option,encode,filename,content)
						commands = backup_commands
						completer = autocomplete(commands)
						readline.set_completer(completer.complete)
						readline.parse_and_bind('tab: complete')
						crawler = 0
						command_path = ['zsc']
				if crawler is 3:
					os = option
					commands = commands[option]
					command_path.append(option)
				if crawler is 4:
					func = option
					commands = commands[option]
					command_path.append(option)
				if crawler is 5:
					data = []
					backup_option = option
					options = option.rsplit('&&')
					for o in options:
						if version() is 2:
							data.append(raw_input('%s:'%o))
						if version() is 3:
							data.append(input('%s:'%o))
					n = 0
					write('\n')
					for o in options:
						info('%s set to "%s"\n'%(o,data[n]))
						n+=1
					run = getattr(__import__('lib.generator.%s.%s'%(os,func), fromlist=['run']), 'run')
					shellcode = run(data)
					write('\n')
					for encode in backup_commands['shellcode'][1]['generate'][os][func][backup_option]:
						info(encode+'\n')
					write('\n\n')
					info('enter encode type\n')
					completer = autocomplete(backup_commands['shellcode'][1]['generate'][os][func][backup_option])
					readline.set_completer(completer.complete)
					readline.parse_and_bind('tab: complete')
					try:
						encode = _input('zsc','any',False)
						if encode is None:
							_lets_error
					except:
						encode = 'none'
						warn('\n"none" encode selected\nplease use "exit" or "quit" to exit software.\n')
						exit_counter += 1
					if assembly_code is False:
						write('\n'+op(encode_process(encode,shellcode,os,func),os)+'\n\n')
					elif assembly_code is True:
						write('\n'+encode_process(encode,shellcode,os,func)+'\n\n')
					commands = backup_commands
					completer = autocomplete(commands)
					readline.set_completer(completer.complete)
					readline.parse_and_bind('tab: complete')
					crawler = 0
					command_path = ['zsc']
				completer = autocomplete(commands)
				readline.set_completer(completer.complete)
				readline.parse_and_bind('tab: complete')
				check = False
		if command == 'exit':
			write(color.color('reset'))
			sys.exit('Exit')
		elif command == 'update':
			_update(__version__)
			commands = backup_commands
			completer = autocomplete(commands)
			readline.set_completer(completer.complete)
			readline.parse_and_bind('tab: complete')
			crawler = 0
			command_path = ['zsc']
		elif command == 'help':
			exit_counter = 0
			_help(help)
			commands = backup_commands
			completer = autocomplete(commands)
			readline.set_completer(completer.complete)
			readline.parse_and_bind('tab: complete')
			crawler = 0
			command_path = ['zsc']
		elif command == 'restart':
			commands = backup_commands
			completer = autocomplete(commands)
			readline.set_completer(completer.complete)
			readline.parse_and_bind('tab: complete')
			crawler = 0
			command_path = ['zsc']
		elif command == 'about':
			about()
			commands = backup_commands
			completer = autocomplete(commands)
			readline.set_completer(completer.complete)
			readline.parse_and_bind('tab: complete')
			crawler = 0
			command_path = ['zsc']
		elif command == 'version':
			_version()
			commands = backup_commands
			completer = autocomplete(commands)
			readline.set_completer(completer.complete)
			readline.parse_and_bind('tab: complete')
			crawler = 0
			command_path = ['zsc']
		else:
			if command != '' and check is True:
				exit_counter = 0
				info('Command not found!\n')
Beispiel #7
0
					payload_flag = True
			if payload_flag is True:
				run = getattr(
					__import__('lib.generator.%s.%s' % (os, func),
							   fromlist=['run']),
					'run')
				shellcode = run(data)
				try:
					asm_code = int(asm_code)
				except:
					asm_code = 'nop'
				if asm_code == 1:
					info('Generated shellcode(Assembly) is:\n\n' +encode_process(encode, shellcode, os, func)+
							 '\n\n')
				else:
					info('Generated shellcode is:\n\n' +op(encode_process(encode, shellcode, os, func),os) +
							 '\n\n')	
	elif mypayload == 'show_all':
		limit = form.getvalue("limit")
		if limit is not None:
			for _ in _show_payloads(commands,True):
				if limit in _:
					print '[+]',_
		if limit is None:
			_show_payloads(commands,False)
		sys.exit(0)
	else:
		print '''please be sure you send all required fields!'''
		sys.exit(0)
else:
	print '''api not found!'''