I build a hidden directory Brute Force. I want to add a timer to the script. I used threading to achieve this goal. The program is working properly but the issue is the printing is not proper.
The image shows The output of my code.
I have used a timer in my code. the problem is the time is not printing in a static line. I mean time is getting appended to the URL found in the above image. I don't want that to be done.
The expected output is this:
time: 16 --> # static line shouldn't move from here.
URL Found --> http://10.0.2.5/.hta [Status: Forbidden]
URL Found --> http://10.0.2.5/.htaccess [Status: Forbidden]
URL Found --> http://10.0.2.5/.htpasswd [Status: Forbidden]
URL Found --> http://10.0.2.5/cgi-bin/ [Status: Forbidden]
URL Found --> http://10.0.2.5/dav [Status: Open]
URL Found --> http://10.0.2.5/index [Status: Open]
URL Found --> http://10.0.2.5/index.php [Status: Open]
URL Found --> http://10.0.2.5/phpinfo [Status: Open]
URL Found --> http://10.0.2.5/phpinfo.php [Status: Open]
URL Found --> http://10.0.2.5/phpMyAdmin [Status: Open]
URL Found --> http://10.0.2.5/server-status [Status: Forbidden]
URL Found --> http://10.0.2.5/test [Status: Open]
URL Found --> http://10.0.2.5/twiki [Status: Open] ```
The code I am using is this:
class HiddenDirs:
def __init__(self):
self.execution = True
parser = optparse.OptionParser()
parser.add_option('-w', '--wordlist', dest='word_list', help='Enter Wordlist')
parser.add_option('-u', '--url', dest='url', help='Enter URL')
options, arguments = parser.parse_args()
word_list = options.word_list
self.url = options.url
if word_list is None:
word_list = 'hidden_paths.txt'
with open(word_list, 'r') as word_list:
self.words = word_list.read().split()
@staticmethod
def responses(url):
try:
response = requests.get(url)
return response
except requests.exceptions.ConnectionError:
pass
def first_half_links(self):
for word in self.words:
link = 'http://' + self.url + '/' + word
response = self.responses(link)
code = response.status_code
if code == 403:
result = f'URL Found --> {colored(link, "green")} [Status: {colored("Forbidden", "red")}]'
print(result)
elif code == 200:
result = f'URL Found --> {colored(link, "red")} [Status: {colored("Open", "red")}]'
print(result)
elif code == 301:
result = f'URL Found --> {colored(link, "red")} [Status: {colored("Open", "red")}]'
print(result)
self.execution = False
def timer(self):
sec_count = 0
while self.execution is True:
time.sleep(1)
sec_count = sec_count + 1
print(f"\rtime: {sec_count}", end="")
def start(self):
t1 = threading.Thread(target=self.timer)
t2 = threading.Thread(target=self.first_half_links)
t1.start()
t2.start()