44import time
55import pickle
66import threading
7- import subprocess
8- import json
7+
98import requests
9+
1010import autosploit
11- from blessings import Terminal
11+ from lib .settings import PLATFORM_PROMPT
12+ from lib .output import (
13+ info ,
14+ error ,
15+ )
1216
13- t = Terminal ()
1417
1518def censysTargets (clobber = True , hostLimit = - 1 ):
1619 """Function to gather target host(s) from Censys."""
@@ -24,67 +27,63 @@ def censysTargets(clobber=True, hostLimit=-1):
2427 autosploit .logo ()
2528
2629 if not os .path .isfile ("uid.p" ):
27- print ( "[{}] Please provide your Censys API ID.". format ( t . green ( "+" )) )
30+ info ( " Please provide your Censys API ID." )
2831
2932 UID = raw_input ("API ID: " )
3033 pickle .dump (UID , open ("uid.p" , "wb" ))
3134 path = os .path .abspath ("uid.p" )
32- print ( "[{}] \n Your API ID has been saved to {}" .format (t . green ( "+" ), path ))
35+ info ( "Your API ID has been saved to {}" .format (path ))
3336
3437 else :
3538 try :
3639 UID = pickle .load (open ("uid.p" , "rb" ))
3740 except IOError as e :
38- print ("\n [{}]Critical. An IO error was raised while attempting to read API data.\n {}" .format (
39- t .red ("!" ), e ))
41+ error ("Critical. An IO error was raised while attempting to read API data.{}" .format (str (e )))
4042
4143 path = os .path .abspath ("uid.p" )
42- print ( " \n [{}] Your API ID was loaded from {}" .format (t . green ( "+" ), path ))
44+ info ( " Your API ID was loaded from {}" .format (path ))
4345
4446 if not os .path .isfile ("secret.p" ):
45- print ( "[{}] Please provide your Censys Secret key.". format ( t . green ( "+" )) )
47+ info ( " Please provide your Censys Secret key." )
4648
4749 SECRET = raw_input ("Secret key: " )
4850 pickle .dump (UID , open ("secret.p" , "wb" ))
4951 path = os .path .abspath ("secret.p" )
50- print ( "[{}] \n Your Secret key has been saved to {}" .format (t . green ( "+" ), path ))
52+ info ( "Your Secret key has been saved to {}" .format (path ))
5153
5254 else :
5355 try :
5456 SECRET = pickle .load (open ("secret.p" , "rb" ))
5557 except IOError as e :
56- print ("\n [{}]Critical. An IO error was raised while attempting to read Secret key data.\n {}" .format (
57- t .red ("!" ), e ))
58+ error ("Critical. An IO error was raised while attempting to read Secret key data.{}" .format (e ))
5859
5960 path = os .path .abspath ("secret.p" )
60- print ( " \n [{}] Your Secret key was loaded from {}" .format (t . green ( "+" ), path ))
61+ info ( " Your Secret key was loaded from {}" .format (path ))
6162
62- print ("[{}]Please provide your platform specific search query." .format (t .green ("+" )))
63- print ("[{}]I.E. 'IIS' will return a list of IPs belonging to IIS servers." .format (
64- t .green ("+" )))
63+ info ("Please provide your platform specific search query." )
64+ info ("I.E. 'IIS' will return a list of IPs belonging to IIS servers." )
6565
6666 while True :
67- query = raw_input (" \n <" + t . cyan ( "PLATFORM" ) + ">$ " )
67+ query = raw_input (PLATFORM_PROMPT )
6868 if query == "" :
69- print ( "[{}] Query cannot be null.". format ( t . red ( "!" )) )
69+ error ( " Query cannot be null." )
7070 else :
7171 break
72- params = {'query' : query }
73- print ("[{}]Please stand by while results are being collected...\n \n \n " .format (
74- t .green ("+" )))
72+ params = {'query' : query }
73+ info ("Please stand by while results are being collected..." )
7574 time .sleep (1 )
7675
7776 try :
7877 response = requests .post (API_URL , json = params , auth = (UID , SECRET ))
7978 except Exception as e :
80- print ("\n [{}]Critical. An error was raised with the following error message.\n " .format (t .red ("!" )))
79+ error ("Critical. An error was raised with the following error message. '{}'" .format (str (e )))
80+
81+ result = response .json ()
8182
8283 if response .status_code != 200 :
8384 print (result .json ()["error" ])
8485 sys .exit (1 )
8586
86- result = response .json ()
87-
8887 thread = threading .Thread (target = autosploit .animation , args = ("collecting results" , ))
8988 thread .daemon = True
9089 thread .start ()
@@ -103,8 +102,8 @@ def censysTargets(clobber=True, hostLimit=-1):
103102 break
104103 autosploit .hostpath = os .path .abspath ("hosts.txt" )
105104 autosploit .stop_animation = True
106- print ( " \n \n \n [{}] Done.". format ( t . green ( "+" )) )
107- print ( "[{}] Host list saved to {}" .format (t . green ( "+" ), autosploit .hostpath ))
105+ info ( " Done." )
106+ info ( " Host list saved to {}" .format (autosploit .hostpath ))
108107 else :
109108 with open ("hosts.txt" , "ab" ) as log :
110109 for i in xrange (autosploit .toolbar_width ):
@@ -117,5 +116,5 @@ def censysTargets(clobber=True, hostLimit=-1):
117116 break
118117 autosploit .hostpath = os .path .abspath ("hosts.txt" )
119118 autosploit .stop_animation = True
120- print ( " \n \n \n [{}] Done.". format ( t . green ( "+" )) )
121- print ( "[{}] Hosts appended to list at " .format (t . green ( "+" ), autosploit .hostpath ))
119+ info ( " Done." )
120+ info ( " Hosts appended to list at {} " .format (autosploit .hostpath ))
0 commit comments