Adding more information

In this section, we'll continue adding features to our BruteForcer in order to improve detection and to facilitate filtering.

First, we're going to add the code that will detect whether there was a redirection, then we're going to add the time it took for the request response transaction and the MD5 hash of the response. Finally, we're going to test the improved script.

Currently, the requests library returns a 200 status code for resources that follow the redirection as it is returning the status code from the last resource in the redirection chain. If we want to know whether there was a redirection, we need to check the history of requests:

  1. Let's go back to the Atom editor and open the file forzaBruta-3.py. We need to add this code in order to improve the redirection detection.
  2. After line 48, we get the request response. This code will check whether there was a redirection and it will update the code with the first redirection code:
            if r.history != []:
first = r.history[0]
code = str(first.status_code)

For the request time, we can do the following:

  1. Take the time before the request and the time after the request, and then subtract the start time from the elapsed time.

In order to do this, we're going to use the time library. We'll add the import library at the beginning, as shown in the following code:

import requests
from threading import Thread
import sys
import time
import getopt
import re

import md5
from termcolor import colored
  1. Then, we add the following line before the request in order to capture the time at that moment and we do the same after the request is performed:
            start = time.time()
  1. Then, we subtract the start time from the elapsed time, and we get the time it took for the response to arrive:
            r = requests.get(self.url)
elaptime = time.time()
totaltime = str(elaptime - start)
lines = str(r.content.count(" "))
chars = str(len(r._content))
words = str(len(re.findall("S+", r.content)))
code = str(r.status_code)
hash = md5.new(r.content).hexdigest()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.184.90