44
55import psutil
66
7+ import lib .output
78
9+
10+ HOST_FILE = "{}/hosts.txt" .format (os .getcwd ())
811START_POSTGRESQL_PATH = "{}/etc/scripts/start_postgre.sh" .format (os .getcwd ())
912START_APACHE_PATH = "{}/etc/scripts/start_apache.sh" .format (os .getcwd ())
1013PLATFORM_PROMPT = "\n {}@\033 [36mPLATFORM\033 [0m$ " .format (getpass .getuser ())
1114AUTOSPLOIT_PROMPT = "\n \033 [31m{}\033 [0m@\033 [36mautosploit\033 [0m# " .format (getpass .getuser ())
15+ API_URLS = {
16+ "shodan" : "https://api.shodan.io/shodan/host/search?key={token}&query={query}" ,
17+ "censys" : "https://censys.io/api/v1/search/ipv4" ,
18+ "zoomeye" : (
19+ "https://api.zoomeye.org/user/login" ,
20+ "https://api.zoomeye.org/web/search"
21+ )
22+ }
1223AUTOSPLOIT_TERM_OPTS = {
1324 1 : "usage and legal" , 2 : "gather hosts" , 3 : "custom hosts" ,
1425 4 : "add single host" , 5 : "view gathered hosts" , 6 : "exploit gathered hosts" ,
1728
1829
1930def validate_ip_addr (provided ):
31+ """
32+ validate an IP address to see if it is real or not
33+ """
2034 try :
2135 socket .inet_aton (provided )
2236 return True
@@ -25,11 +39,37 @@ def validate_ip_addr(provided):
2539
2640
2741def check_services (service_name ):
42+ """
43+ check to see if certain services ar started
44+ """
2845 all_processes = set ()
2946 for pid in psutil .pids ():
3047 running_proc = psutil .Process (pid )
3148 all_processes .add (" " .join (running_proc .cmdline ()).strip ())
3249 for proc in list (all_processes ):
3350 if service_name in proc :
3451 return True
35- return False
52+ return False
53+
54+
55+ def write_to_file (data_to_write , filename , mode = "a+" ):
56+ """
57+ write data to a specified file, if it exists, ask to overwrite
58+ """
59+ if os .path .exists (filename ):
60+ is_append = lib .output .prompt ("would you like to (a)ppend or (o)verwrite the file" )
61+ if is_append == "o" :
62+ mode = "w"
63+ elif is_append == "a" :
64+ mode = "a+"
65+ else :
66+ lib .output .warning ("invalid input provided ('{}'), appending to file" .format (is_append ))
67+ mode = "a+"
68+ with open (filename , mode ) as log :
69+ if isinstance (data_to_write , (tuple , set , list )):
70+ for item in list (data_to_write ):
71+ log .write ("{}{}" .format (item .strip (), os .linesep ))
72+ else :
73+ log .write (data_to_write )
74+ lib .output .info ("successfully wrote info to '{}'" .format (filename ))
75+ return filename
0 commit comments