File size: 24,231 Bytes
5e0ca0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
import json
import re
from typing import Any
from typing import Optional
import openai
import requests
model_engine = "gpt-3.5-turbo-0613"


class DNS_AI_MODEL():
    @staticmethod
    def BardAI(key: str, data: Any) -> str:
        prompt = f"""
            Do a DNS analysis on the provided DNS scan information
            The DNS output must return in a JSON format accorging to the provided
            output format. The data must be accurate in regards towards a pentest report.
            The data must follow the following rules:
            1) The DNS scans must be done from a pentester point of view
            2) The final output must be minimal according to the format given
            3) The final output must be kept to a minimal

            The output format:
            {{
                "A": [""],
                "AAA": [""],
                "NS": [""],
                "MX": [""],
                "PTR": [""],
                "SOA": [""],
                "TXT": [""]
            }}
            DNS Data to be analyzed: {data}
            """

        url = "https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=" + key

        headers = {
            "Content-Type": "application/json"
        }

        data = {
            "prompt": {
                "text": prompt
            }
        }

        response = requests.post(url, json=data, headers=headers)

        if response.status_code == 200:
            generated_text = response.json()
            data = dns_ai_data_regex(str(generated_text))
            print(data)
            return dns_ai_data_regex(str(generated_text))
        else:
            print("Error: Unable to generate text. Status Code:", response.status_code)
            return "None"

    @staticmethod
    def llama_AI(self, data: str, mode: str, lkey, lendpoint):
        api_url = 'http://localhost:5000/api/chatbot'

        user_instruction = """
            Do a DNS scan analysis on the provided DNS scan information. The DNS output must return in a asked format accorging to the provided output format. The data must be accurate in regards towards a pentest report.
            The data must follow the following rules:
            1) The DNS scans must be done from a pentester point of view
            2) The final output must be minimal according to the format given
            3) The final output must be kept to a minimal
            4) So the analysis and provide your view according to the given format
            5) Remember to provide views as a security engineer or an security analyst.
            The output format:
            "A":
            - List the A records and security views on them
            "AAA":
            - List the AAA records and security views on them
            "NS":
            - List the NS records and security views on them
            "MX":
            - List the MX records and security views on them
            "PTR":
            - List the PTR records and security views on them
            "SOA":
            - List the SOA records and security views on them
            "TXT":
            - List the TXT records and security views on them
        """
        user_message = f"""
            DNS Data to be analyzed: {data}
        """

        model_name = "TheBloke/Llama-2-7B-Chat-GGML"
        file_name = "llama-2-7b-chat.ggmlv3.q4_K_M.bin"
        if mode == "local":
            bot_response = self.chat_with_api(api_url, user_message, user_instruction, model_name, file_name)
        elif mode == "runpod":
            prompt = f"[INST] <<SYS>> {user_instruction}<</SYS>> NMAP Data to be analyzed: {user_message} [/INST]"
            bot_response = self.llama_runpod_api(prompt, lkey, lendpoint)
        bot_response = self.chat_with_api(api_url, user_message, user_instruction, model_name, file_name)
        print("test")
        if bot_response:
            return bot_response

    @staticmethod
    def gpt_ai(analyze: str, key: Optional[str]) -> str:
        openai.api_key = key
        prompt = f"""
        Do a DNS analysis on the provided DNS scan information
        The DNS output must return in a JSON format accorging to the provided
        output format. The data must be accurate in regards towards a pentest report.
        The data must follow the following rules:
        1) The DNS scans must be done from a pentester point of view
        2) The final output must be minimal according to the format given
        3) The final output must be kept to a minimal

        The output format:
        {{
            "A": [""],
            "AAA": [""],
            "NS": [""],
            "MX": [""],
            "PTR": [""],
            "SOA": [""],
            "TXT": [""]
        }}

        DNS Data to be analyzed: {analyze}
        """
        try:
            # A structure for the request
            messages = [{"content": prompt, "role": "user"}]
            # A structure for the request
            response = openai.ChatCompletion.create(
                model=model_engine,
                messages=messages,
                max_tokens=1024,
                n=1,
                stop=None,
            )
            response = response['choices'][0]['message']['content']
            return dns_ai_data_regex(str(response))
        except KeyboardInterrupt:
            print("Bye")
            quit()


class NMAP_AI_MODEL():
    @staticmethod
    def BardAI(key: str, data: Any) -> str:
        prompt = f"""
            Do a NMAP scan analysis on the provided NMAP scan information
            The NMAP output must return in a JSON format accorging to the provided
            output format. The data must be accurate in regards towards a pentest report.
            The data must follow the following rules:
            1) The NMAP scans must be done from a pentester point of view
            2) The final output must be minimal according to the format given.
            3) The final output must be kept to a minimal.
            4) If a value not found in the scan just mention an empty string.
            5) Analyze everything even the smallest of data.
            6) Completely analyze the data provided and give a confirm answer using the output format.

            The output format:
            {{
                "critical score": [""],
                "os information": [""],
                "open ports": [""],
                "open services": [""],
                "vulnerable service": [""],
                "found cve": [""]
            }}

            NMAP Data to be analyzed: {data}
            """

        url = "https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=" + key

        headers = {
            "Content-Type": "application/json"
        }

        data = {
            "prompt": {
                "text": prompt
            }
        }

        response = requests.post(url, json=data, headers=headers)

        if response.status_code == 200:
            generated_text = response.json()
            return nmap_ai_data_regex(str(generated_text))
        else:
            print("Error: Unable to generate text. Status Code:", response.status_code)
            return "None"

    @staticmethod
    def Llama_AI(data: str, mode: str, lkey: str, lendpoint: str) -> Any:
        api_url = 'http://localhost:5000/api/chatbot'

        user_instruction = """
        Do a NMAP scan analysis on the provided NMAP scan information. The NMAP output must return in a asked format accorging to the provided output format. The data must be accurate in regards towards a pentest report.
        The data must follow the following rules:
        1) The NMAP scans must be done from a pentester point of view
        2) The final output must be minimal according to the format given.
        3) The final output must be kept to a minimal.
        4) If a value not found in the scan just mention an empty string.
        5) Analyze everything even the smallest of data.
        6) Completely analyze the data provided and give a confirm answer using the output format.
        7) mention all the data you found in the output format provided so that regex can be used on it.
        8) avoid unnecessary explaination.
        9) the critical score must be calculated based on the CVE if present or by the nature of the services open
        10) the os information must contain the OS used my the target.
        11) the open ports must include all the open ports listed in the data[tcp] and varifying if it by checking its states value.  you should not negect even one open port.
        12) the vulnerable services can be determined via speculation of the service nature or by analyzing the CVE's found.
        The output format:
            critical score:
            - Give info on the criticality
            "os information":
            - List out the OS information
            "open ports and services":
            - List open ports
            - List open ports services
            "vulnerable service":
            - Based on CVEs or nature of the ports opened list the vulnerable services
            "found cve":
            - List the CVE's found and list the main issues.
        """
        user_message = f"""
            NMAP Data to be analyzed: {data}
        """
        model_name = "TheBloke/Llama-2-7B-Chat-GGML"
        file_name = "llama-2-7b-chat.ggmlv3.q4_K_M.bin"
        if mode == "local":
            bot_response = chat_with_api(api_url, user_message, user_instruction, model_name, file_name)
        elif mode == "runpod":
            prompt = f"[INST] <<SYS>> {user_instruction}<</SYS>> NMAP Data to be analyzed: {user_message} [/INST]"
            bot_response = llama_runpod_api(prompt, lkey, lendpoint)
        if bot_response:
            return bot_response

    @staticmethod
    def GPT_AI(key: str, data: Any) -> str:
        openai.api_key = key
        try:
            prompt = f"""
            Do a NMAP scan analysis on the provided NMAP scan information
            The NMAP output must return in a JSON format accorging to the provided
            output format. The data must be accurate in regards towards a pentest report.
            The data must follow the following rules:
            1) The NMAP scans must be done from a pentester point of view
            2) The final output must be minimal according to the format given.
            3) The final output must be kept to a minimal.
            4) If a value not found in the scan just mention an empty string.
            5) Analyze everything even the smallest of data.
            6) Completely analyze the data provided and give a confirm answer using the output format.

            The output format:
            {{
                "critical score": [""],
                "os information": [""],
                "open ports": [""],
                "open services": [""],
                "vulnerable service": [""],
                "found cve": [""]
            }}

            NMAP Data to be analyzed: {data}
            """
            # A structure for the request
            messages = [{"content": prompt, "role": "assistant"}]
            # A structure for the request
            response = openai.ChatCompletion.create(
                model=model_engine,
                messages=messages,
                max_tokens=2500,
                n=1,
                stop=None,
            )
            response = response['choices'][0]['message']['content']
            rsp = str(response)
            return str(nmap_ai_data_regex(rsp))
        except KeyboardInterrupt:
            print("Bye")
            quit()


class JWT_AI_MODEL():
    @staticmethod
    def BardAI(key: str, jwt_data: Any) -> str:
        prompt = f"""
        Perform a comprehensive analysis on the provided JWT token. The analysis output must be in a JSON format according to the provided output structure. Ensure accuracy for inclusion in a penetration testing report.
        Follow these guidelines:
        1) Analyze the JWT token from a pentester's perspective
        2) Keep the final output minimal while adhering to the given format
        3) Highlight JWT-specific details and enumerate possible attacks and vulnerabilities
        5) For the output "Algorithm Used" value use the Algorithm value from the JWT data.
        6) For the output "Header" value use the Header value from the JWT data.
        7) For the "Payload" Use the decoded payloads as a reference and then analyze any attack endpoints.
        8) For "Signature" mention the signatures discovered.
        9) List a few endpoints you feel are vulnerable for "VulnerableEndpoints"

        The output format:
        {{
            "Algorithm Used": "",
            "Header": "",
            "Payload": "",
            "Signature": "",
            "PossibleAttacks": "",
            "VulnerableEndpoints": ""
        }}

        JWT Token Data to be analyzed: {jwt_data}
        """

        url = "https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=" + key

        headers = {
            "Content-Type": "application/json"
        }

        data = {
            "prompt": {
                "text": prompt
            }
        }

        response = requests.post(url, json=data, headers=headers)

        if response.status_code == 200:
            generated_text = response.json()
            jwt_analysis_data = jwt_ai_data_regex(str(generated_text))
            print(jwt_analysis_data)
            return jwt_analysis_data
        else:
            print("Error: Unable to generate text. Status Code:", response.status_code)
            return "None"

    @staticmethod
    def llama_AI(self, jwt_data: str, mode: str, lkey, lendpoint):
        api_url = 'http://localhost:5000/api/chatbot'

        user_instruction = """
            Perform a comprehensive analysis on the provided JWT token. The JWT analysis output must be in a asked format according to the provided output structure. Ensure accuracy for inclusion in a penetration testing report.
            Follow these guidelines:
            1) Analyze the JWT token from a pentester's perspective
            2) Keep the final output minimal while adhering to the given format
            3) Highlight JWT-specific details and enumerate possible attacks

            The output format:
            "Header":
            - List the JWT header details and security views on them
            "Payload":
            - List the JWT payload details and security views on them
            "Signature":
            - Provide insights on the JWT signature
            "PossibleAttacks":
            - List possible JWT exploits and attacks
        """
        user_message = f"""
            JWT Token Data to be analyzed: {jwt_data}
        """

        model_name = "TheBloke/Llama-2-7B-Chat-GGML"
        file_name = "llama-2-7b-chat.ggmlv3.q4_K_M.bin"
        if mode == "local":
            bot_response = self.chat_with_api(api_url, user_message, user_instruction, model_name, file_name)
        elif mode == "runpod":
            prompt = f"[INST] <<SYS>> {user_instruction}<</SYS>> JWT Token Data to be analyzed: {user_message} [/INST]"
            bot_response = self.llama_runpod_api(prompt, lkey, lendpoint)
        bot_response = self.chat_with_api(api_url, user_message, user_instruction, model_name, file_name)
        print("test")
        if bot_response:
            return bot_response

    @staticmethod
    def gpt_ai(analyze: str, api_key: Optional[str]) -> str:
        openai.api_key = api_key
        prompt = f"""
        Perform a comprehensive analysis on the provided JWT token. The analysis output must be in a JSON format according to the provided output structure. Ensure accuracy for inclusion in a penetration testing report.
        Follow these guidelines:
        1) Analyze the JWT token from a pentester's perspective
        2) Keep the final output minimal while adhering to the given format
        3) Highlight JWT-specific details and enumerate possible attacks and vulnerabilities
        5) For the output "Algorithm Used" value use the Algorithm value from the JWT data.
        6) For the output "Header" value use the Header value from the JWT data.
        7) For the "Payload" Use the decoded payloads as a reference and then analyze any attack endpoints.
        8) For "Signature" mention the signatures discovered.
        9) List a few endpoints you feel are vulnerable for "VulnerableEndpoints"

        The output format:
        {{
            "Algorithm Used": "",
            "Header": "",
            "Payload": "",
            "Signature": "",
            "PossibleAttacks": "",
            "VulnerableEndpoints": ""
        }}

        JWT Token Data to be analyzed: {analyze}
        """
        try:
            messages = [{"content": prompt, "role": "user"}]
            response = openai.ChatCompletion.create(
                model=model_engine,
                messages=messages,
                max_tokens=1024,
                n=1,
                stop=None,
            )
            response = response['choices'][0]['message']['content']
            rsp = str(response)
            return rsp
        except KeyboardInterrupt:
            print("Bye")
            quit()


def chat_with_api(api_url: str, user_message: str, user_instruction: str, model_name: str, file_name: str = None) -> Any:
    # Prepare the request data in JSON format
    data = {
        'user_message': user_message,
        'model_name': model_name,
        'file_name': file_name,
        'user_instruction': user_instruction
    }

    # Send the POST request to the API
    response = requests.post(api_url, json=data)

    # Check if the request was successful (status code 200)
    if response.status_code == 200:
        return response.json()['bot_response']
    else:
        # If there was an error, print the error message
        print(f"Error: {response.status_code} - {response.text}")
        return None


def llama_runpod_api(prompt: str, lkey: str, lendpoint: str) -> Any:
    url = f"https://api.runpod.ai/v2/{lendpoint}/runsync"
    payload = json.dumps({
        "input": {
            "prompt": prompt,
            "max_new_tokens": 4500,
            "temperature": 0.9,
            "top_k": 50,
            "top_p": 0.7,
            "repetition_penalty": 1.2,
            "batch_size": 8,
            "stop": [
                "</s>"
            ]
        }
    })
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {lkey}',
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    response_t = json.loads(response.text)
    return response_t["output"]


def dns_ai_data_regex(json_string: str) -> Any:
    # Define the regular expression patterns for individual values
    A_pattern = r'"A": \["(.*?)"\]'
    AAA_pattern = r'"AAA: \["(.*?)"\]'
    NS_pattern = r'"NS": \["(.*?)"\]'
    MX_pattern = r'"MX": \["(.*?)"\]'
    PTR_pattern = r'"PTR": \["(.*?)"\]'
    SOA_pattern = r'"SOA": \["(.*?)"\]'
    TXT_pattern = r'"TXT": \["(.*?)"\]'

    # Initialize variables for extracted data
    A = None
    AAA = None
    NS = None
    MX = None
    PTR = None
    SOA = None
    TXT = None

    # Extract individual values using patterns
    match = re.search(A_pattern, json_string)
    if match:
        A = match.group(1)
        match = re.search(AAA_pattern, json_string)
    if match:
        AAA = match.group(1)
        match = re.search(NS_pattern, json_string)
    if match:
        NS = match.group(1)
        match = re.search(MX_pattern, json_string)
    if match:
        MX = match.group(1)
        match = re.search(PTR_pattern, json_string)
    if match:
        PTR = match.group(1)
        match = re.search(SOA_pattern, json_string)
    if match:
        SOA = match.group(1)
        match = re.search(TXT_pattern, json_string)
    if match:
        TXT = match.group(1)

        # Create a dictionary to store the extracted data
    data = {
        "A": A,
        "AAA": AAA,
        "NS": NS,
        "MX": MX,
        "PTR": PTR,
        "SOA": SOA,
        "TXT": TXT
    }

    # Convert the dictionary to JSON format
    json_output = json.dumps(data)

    return json_output


def nmap_ai_data_regex(json_string: str) -> Any:
    # Define the regular expression patterns for individual values
    critical_score_pattern = r'"critical score": \["(.*?)"\]'
    os_information_pattern = r'"os information": \["(.*?)"\]'
    open_ports_pattern = r'"open ports": \["(.*?)"\]'
    open_services_pattern = r'"open services": \["(.*?)"\]'
    vulnerable_service_pattern = r'"vulnerable service": \["(.*?)"\]'
    found_cve_pattern = r'"found cve": \["(.*?)"\]'
    # Initialize variables for extracted data
    critical_score = None
    os_information = None
    open_ports = None
    open_services = None
    vulnerable_service = None
    found_cve = None

    # Extract individual values using patterns
    match = re.search(critical_score_pattern, json_string)
    if match:
        critical_score = match.group(1)

    match = re.search(os_information_pattern, json_string)
    if match:
        os_information = match.group(1)
    match = re.search(open_ports_pattern, json_string)
    if match:
        open_ports = match.group(1)
    match = re.search(open_services_pattern, json_string)
    if match:
        open_services = match.group(1)

    match = re.search(vulnerable_service_pattern, json_string)
    if match:
        vulnerable_service = match.group(1)

    match = re.search(found_cve_pattern, json_string)
    if match:
        found_cve = match.group(1)

    # Create a dictionary to store the extracted data
    data = {
        "critical score": critical_score,
        "os information": os_information,
        "open ports": open_ports,
        "open services": open_services,
        "vulnerable service": vulnerable_service,
        "found cve": found_cve
    }

    # Convert the dictionary to JSON format
    json_output = json.dumps(data)

    return json_output


def jwt_ai_data_regex(json_string: str) -> Any:
    # Define the regular expression patterns for individual values
    header_pattern = r'"Header": \{\s*"alg": "(.*?)",\s*"typ": "(.*?)"\s*\}'
    payload_pattern = r'"Payload": \{\s*"iss": "(.*?)",\s*"sub": "(.*?)",\s*"aud": "(.*?)",\s*"exp": "(.*?)",\s*"nbf": "(.*?)",\s*"iat": "(.*?)"\s*\}'
    signature_pattern = r'"Signature": "(.*?)"'
    possible_attacks_pattern = r'"PossibleAttacks": "(.*?)"'
    vulnerable_endpoints_pattern = r'"VulnerableEndpoints": "(.*?)"'

    # Initialize variables for extracted data
    header = {}
    payload = {}
    signature = ""
    possible_attacks = ""
    vulnerable_endpoints = ""

    # Extract individual values using patterns
    match_header = re.search(header_pattern, json_string)
    if match_header:
        header = {"alg": match_header.group(1), "typ": match_header.group(2)}

    match_payload = re.search(payload_pattern, json_string)
    if match_payload:
        payload = {
            "iss": match_payload.group(1),
            "sub": match_payload.group(2),
            "aud": match_payload.group(3),
            "exp": match_payload.group(4),
            "nbf": match_payload.group(5),
            "iat": match_payload.group(6)
        }

    match_signature = re.search(signature_pattern, json_string)
    if match_signature:
        signature = match_signature.group(1)

    match_attacks = re.search(possible_attacks_pattern, json_string)
    if match_attacks:
        possible_attacks = match_attacks.group(1)

    match_endpoints = re.search(vulnerable_endpoints_pattern, json_string)
    if match_endpoints:
        vulnerable_endpoints = match_endpoints.group(1)

    # Create a dictionary to store the extracted data
    data = {
        "Header": header,
        "Payload": payload,
        "Signature": signature,
        "PossibleAttacks": possible_attacks,
        "VulnerableEndpoints": vulnerable_endpoints
    }

    # Convert the dictionary to JSON format
    json_output = json.dumps(data)

    return json_output