-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Autosploit automation #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
0b1f569
30ae78f
2250e6c
8647b29
205f8ed
53cad49
698fa22
4a323b3
fbf7af3
ae2c1be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,11 @@ def optparser(): | |
| help="use shodan.io as the search engine to gather hosts") | ||
| se.add_argument("-a", "--all", action="store_true", dest="searchAll", | ||
| help="search all available search engines to gather hosts") | ||
| save_results_args = se.add_mutually_exclusive_group(required=False) | ||
| save_results_args.add_argument("--overwrite", action="store_true", dest="overwriteHosts", | ||
| help="When specified, start from scratch by overwriting the host file with new search results.") | ||
| save_results_args.add_argument("--append", action="store_true", dest="appendHosts", | ||
| help="When specified, append discovered hosts to the host file.") | ||
|
|
||
| req = parser.add_argument_group("requests", "arguments to edit your requests") | ||
| req.add_argument("--proxy", metavar="PROTO://IP:PORT", dest="proxyConfig", | ||
|
|
@@ -59,6 +64,10 @@ def optparser(): | |
| help="set the configuration for MSF (IE -C default 127.0.0.1 8080)") | ||
| exploit.add_argument("-e", "--exploit", action="store_true", dest="startExploit", | ||
| help="start exploiting the already gathered hosts") | ||
| exploit.add_argument("-d", "--dry-run", action="store_true", dest="dryRun", | ||
| help="Do not launch metasploit's exploits. Do everything else. msfconsole is never called.") | ||
| exploit.add_argument("-f", "--exploit-file-to-use", metavar="PATH", dest="exploitFile", | ||
| help="Run AutoSploit with provided exploit JSON file.") | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! That's perfect thank you |
||
| misc = parser.add_argument_group("misc arguments", "arguments that don't fit anywhere else") | ||
| misc.add_argument("--ruby-exec", action="store_true", dest="rubyExecutableNeeded", | ||
|
|
@@ -134,32 +143,49 @@ def single_run_args(opt, keys, loaded_modules): | |
| lib.output.error("caught IOError '{}' check the file path and try again".format(str(e))) | ||
| sys.exit(0) | ||
|
|
||
| search_save_mode = None | ||
| if opt.overwriteHosts: | ||
| # Create a new empty file, overwriting the previous one. | ||
| # Set the mode to append afterwards | ||
| # This way, successive searches will start clean without | ||
| # overriding each others. | ||
| open(lib.settings.HOST_FILE, mode="w").close() | ||
| search_save_mode = "a" | ||
| elif opt.appendHosts: | ||
| search_save_mode = "a" | ||
|
|
||
| if opt.searchCensys: | ||
| lib.output.info(single_search_msg.format("Censys")) | ||
| api_searches[2]( | ||
| keys["censys"][1], keys["censys"][0], | ||
| opt.searchQuery, proxy=headers[0], agent=headers[1] | ||
| opt.searchQuery, proxy=headers[0], agent=headers[1], | ||
| save_mode=search_save_mode | ||
| ).censys() | ||
| if opt.searchZoomeye: | ||
| lib.output.info(single_search_msg.format("Zoomeye")) | ||
| api_searches[0]( | ||
| opt.searchQuery, proxy=headers[0], agent=headers[1] | ||
| opt.searchQuery, proxy=headers[0], agent=headers[1], | ||
| save_mode=search_save_mode | ||
| ).zoomeye() | ||
| if opt.searchShodan: | ||
| lib.output.info(single_search_msg.format("Shodan")) | ||
| api_searches[1]( | ||
| keys["shodan"][0], opt.searchQuery, proxy=headers[0], agent=headers[1] | ||
| keys["shodan"][0], opt.searchQuery, proxy=headers[0], agent=headers[1], | ||
| save_mode=search_save_mode | ||
| ).shodan() | ||
| if opt.searchAll: | ||
| lib.output.info("searching all search engines in order") | ||
| api_searches[0]( | ||
| opt.searchQuery, proxy=headers[0], agent=headers[1] | ||
| opt.searchQuery, proxy=headers[0], agent=headers[1], | ||
| save_mode=search_save_mode | ||
| ).zoomeye() | ||
| api_searches[1]( | ||
| keys["shodan"][0], opt.searchQuery, proxy=headers[0], agent=headers[1] | ||
| keys["shodan"][0], opt.searchQuery, proxy=headers[0], agent=headers[1], | ||
| save_mode=search_save_mode | ||
| ).shodan() | ||
| api_searches[2]( | ||
| keys["censys"][1], keys["censys"][0], opt.searchQuery, proxy=headers[0], agent=headers[1] | ||
| keys["censys"][1], keys["censys"][0], opt.searchQuery, proxy=headers[0], agent=headers[1], | ||
| save_mode=search_save_mode | ||
| ).censys() | ||
| if opt.startExploit: | ||
| hosts = open(lib.settings.HOST_FILE).readlines() | ||
|
|
@@ -170,5 +196,6 @@ def single_run_args(opt, keys, loaded_modules): | |
| loaded_modules, | ||
| hosts, | ||
| ruby_exec=opt.rubyExecutableNeeded, | ||
| msf_path=opt.pathToFramework | ||
| msf_path=opt.pathToFramework, | ||
| dryRun=opt.dryRun | ||
| ).start_exploit() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,20 +108,33 @@ def check_services(service_name): | |
| return True | ||
|
|
||
|
|
||
|
|
||
| def write_to_file(data_to_write, filename, mode="a+"): | ||
| def write_to_file(data_to_write, filename, mode=None): | ||
| """ | ||
| write data to a specified file, if it exists, ask to overwrite | ||
| """ | ||
| global stop_animation | ||
|
|
||
| if os.path.exists(filename): | ||
| stop_animation = True | ||
| is_append = lib.output.prompt("would you like to (a)ppend or (o)verwrite the file") | ||
| if is_append == "o": | ||
| mode = "w" | ||
| elif is_append != "a": | ||
| lib.output.warning("invalid input provided ('{}'), appending to file".format(is_append)) | ||
| if not mode: | ||
| stop_animation = True | ||
| is_append = lib.output.prompt("would you like to (a)ppend or (o)verwrite the file") | ||
| if is_append.lower() == "o": | ||
| mode = "w" | ||
| elif is_append.lower() == "a": | ||
| mode = "a+" | ||
| else: | ||
| lib.output.error("invalid input provided ('{}'), appending to file".format(is_append)) | ||
| lib.output.error("Search results NOT SAVED!") | ||
|
|
||
| if mode == "w": | ||
| lib.output.warning("Overwriting to {}".format(filename)) | ||
| if mode == "a": | ||
| lib.output.info("Appending to {}".format(filename)) | ||
|
|
||
| else: | ||
| # File does not exists, mode does not matter | ||
| mode = "w" | ||
|
|
||
| with open(filename, mode) as log: | ||
| if isinstance(data_to_write, (tuple, set, list)): | ||
| for item in list(data_to_write): | ||
|
|
@@ -132,7 +145,7 @@ def write_to_file(data_to_write, filename, mode="a+"): | |
| return filename | ||
|
|
||
|
|
||
| def load_api_keys(path="{}/etc/tokens".format(CUR_DIR)): | ||
| def load_api_keys(unattended=False, path="{}/etc/tokens".format(CUR_DIR)): | ||
|
|
||
| """ | ||
| load the API keys from their .key files | ||
|
|
@@ -156,8 +169,8 @@ def load_api_keys(path="{}/etc/tokens".format(CUR_DIR)): | |
| else: | ||
| lib.output.info("{} API token loaded from {}".format(key.title(), API_KEYS[key][0])) | ||
| api_tokens = { | ||
| "censys": (open(API_KEYS["censys"][0]).read(), open(API_KEYS["censys"][1]).read()), | ||
| "shodan": (open(API_KEYS["shodan"][0]).read(), ) | ||
| "censys": (open(API_KEYS["censys"][0]).read().rstrip(), open(API_KEYS["censys"][1]).read().rstrip()), | ||
| "shodan": (open(API_KEYS["shodan"][0]).read().rstrip(), ) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question, why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No particular reasons. I had problems with copy-pasta and dangling spaces / CR-LF vs LF endings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay that makes sense. Thought there was some magic I didn't know about lol. |
||
| return api_tokens | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't have shorthands