'Guesses the header and footer based on two responses and an expected
result that should be in body_a.
:param body_a: The response body for the request with the expected
result. For example, in local file read vulnerabilities
this should be the result of requesting
file.php?f=/etc/passwd
:param body_b: The response body for the request with an invalid
resource. For example, in local file read vulnerabilities
this should be the result of requesting
file.php?f=/does/not/exist
:param expected_result: The expected result that should be found in
body_a. For example, in local file read
vulnerabilities this should look like:
root:x:0:0:root:/root:/bin/bash
:return: True if the cut could be defined'

def _guess_cut(self, body_a, body_b, expected_result):

    if (expected_result not in body_a):
        return False
    if (body_a == body_b):
        return False
    sequence_matcher = difflib.SequenceMatcher((lambda x: (len(x) < 3)), body_a, body_b)
    body_a_len = len(body_a)
    body_b_len = len(body_b)
    longest_match = sequence_matcher.find_longest_match(0, body_a_len, 0, body_b_len)
    longest_match_a = longest_match[0]
    longest_match_b = longest_match[1]
    longest_match_size = longest_match[2]
    if ((float(longest_match_size) == body_b_len == 0) or ((float(longest_match_size) / body_b_len) < 0.01)):
        self._footer_length = 0
        self._header_length = 0
    elif ((longest_match_a + longest_match_size) == body_a_len):
        self._footer_length = longest_match_size
        longest_match_header = sequence_matcher.find_longest_match(0, longest_match_a, 0, longest_match_b)
        longest_match_header_size = longest_match_header[2]
        if ((float(longest_match_header_size) / (body_b_len - longest_match_a)) < 0.1):
            self._header_length = 0
        else:
            self._header_length = longest_match_header_size
    else:
        self._header_length = longest_match_size
        body_a_reverse = body_a[::(-1)]
        body_b_reverse = body_b[::(-1)]
        sequence_matcher = difflib.SequenceMatcher((lambda x: (len(x) < 3)), body_a_reverse, body_b_reverse)
        longest_match_footer = sequence_matcher.find_longest_match(0, (body_a_len - self._header_length), 0, (body_b_len - self._header_length))
        longest_match_footer_size = longest_match_footer[2]
        if ((float(longest_match_footer_size) / (body_b_len - longest_match_a)) < 0.01):
            self._footer_length = 0
        else:
            self._footer_length = longest_match_footer_size
    return True
