• Stars
    star
    455
  • Rank 96,175 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 1 year ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Uses ChatGPT API, Bard API, and Llama2, Python-Nmap, DNS Recon, PCAP and JWT recon modules and uses the GPT3 model to create vulnerability reports based on Nmap scan data, and DNS scan information. It can also perform subdomain enumeration to a great extent

GPT_Vuln-analyzer

This is a Proof Of Concept application that demostrates how AI can be used to generate accurate results for vulnerability analysis and also allows further utilization of the already super useful ChatGPT made using openai-api, python-nmap, dnsresolver python modules and also use customtkinter and tkinter for the GUI version of the code. This project also has a CLI and a GUI interface, It is capable of doing network vulnerability analysis, DNS enumeration and also subdomain enumeration.

Requirements

  • Python 3.10
  • All the packages mentioned in the requirements.txt file
  • OpenAI api
  • IPGeolocation API

Usage Package

Import packages

cd package && pip3/pip install .

Simple import any of the 3 packages and then add define the variables accordingly

from GVA import scanner
from GVA import dns_recon
from GVA import subdomain
from GVA import geo
from GVA import gui
from dotenv import load_dotenv()

load_dotenv()
openai_key = os.getenv('OPENAI_API_KEY')
geoIP_key = os.getenv('GEOIP_API_KEY')

sub_domain_list = ['admin', 'whateveryouwant']

# scanner(target: str, profile: int, api_key: str)
# dns_recon(target: str, api_key: str)
# domain(target: str, domain_list: List[str)
# geo(api_key: str, target: str)

print(scanner.scanner('127.0.0.1', 1, openai_key))
print(dns_recon.dns_recon('127.0.0.1', openai_key))
print(subdomain.domain('127.0.0.1', sub_domain_list))
print(geo.geo(geoIP_key, '127.0.0.1'))
gui.application()

Usage CLI

  • First Change the "APIKEY__" part of the code with OpenAI api key and the IPGeolocation API key in the .env file
GEOIP_API_KEY = ''
OPENAI_API_KEY = ''
  • second install the packages
pip3 install -r requirements.txt
or
pip install -r requirements.txt
  • run the code python3 gpt_vuln.py
# Regular Help Menu
python gpt_vuln.py --help

# Rich Help Menu
python gpt_vuln.py --r help

# Specify target with the attack
python gpt_vuln.py --target <IP> --attack dns/nmap

# Specify target and profile for nmap
python gpt_vuln.py --target <IP> --attack nmap --profile <1-5>
(Default:1)

# Specify target for DNS no profile needed
python gpt_vuln.py --target <IP or HOSTNAME> --attack dns

# Specify target for Subdomain Enumeration no profile needed
python gpt_vuln.py --target <HOSTNAME> --attack sub

# Specify target for geolocation lookup
python gpt_vuln.py --target <IP> --attack geo

Supported in both windows and linux

Understanding the code

Profiles:

Parameter Return data Description Nmap Command
p1 json Effective Scan -Pn -sV -T4 -O -F
p2 json Simple Scan -Pn -T4 -A -v
p3 json Low Power Scan -Pn -sS -sU -T4 -A -v
p4 json Partial Intense Scan -Pn -p- -T4 -A -v
p5 json Complete Intense Scan -Pn -sS -sU -T4 -A -PE -PP -PY -g 53 --script=vuln

The profile is the type of scan that will be executed by the nmap subprocess. The Ip or target will be provided via argparse. At first the custom nmap scan is run which has all the curcial arguments for the scan to continue. Next, the scan data is extracted from the huge pile of data driven by nmap. the "scan" object has a list of sub-data under "tcp" each labled according to the ports opened. once the data is extracted the data is sent to openai API davenci model via a prompt. the prompt specifically asks for a JSON output and the data also to be used in a certain manner.

The entire structure of request that has to be sent to the openai API is designed in the completion section of the Program.

def scanner(ip: Optional[str], profile: int, key: str) -> str:
    if key is not None:
        pass
    else:
        raise ValueError("KeyNotFound: Key Not Provided")
    # Handle the None case
    profile_argument = ""
    # The port profiles or scan types user can choose
    if profile == 1:
        profile_argument = '-Pn -sV -T4 -O -F'
    elif profile == 2:
        profile_argument = '-Pn -T4 -A -v'
    elif profile == 3:
        profile_argument = '-Pn -sS -sU -T4 -A -v'
    elif profile == 4:
        profile_argument = '-Pn -p- -T4 -A -v'
    elif profile == 5:
        profile_argument = '-Pn -sS -sU -T4 -A -PE -PP -PS80,443 -PA3389 -PU40125 -PY -g 53 --script=vuln'
    else:
        raise ValueError(f"Invalid Argument: {profile}")
    # The scanner with GPT Implemented
    nm.scan('{}'.format(ip), arguments='{}'.format(profile_argument))
    json_data = nm.analyse_nmap_xml_scan()
    analyze = json_data["scan"]
    try:
        response = PortAI(key, analyze)
    except KeyboardInterrupt:
        print("Bye")
        quit()
    return str(response)

Regex

We use Regex to extract only the important information from the custom prompt provided this reduces the total amount of unwanted data

def extract_data(json_string):
    # 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 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.

        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
        completion = openai.Completion.create(
            engine=model_engine,
            prompt=prompt,
            max_tokens=1024,
            n=1,
            stop=None,
        )
        response = completion.choices[0].text
        return extract_data(str(response))
    except KeyboardInterrupt:
        print("Bye")
        quit()

The AI code defines an output format and commands the AI to follow a few pre dertermined rules to increase accuracy.

The regex extraction code does the extraction and further the main function arranges them into tables.

Output

nmap output:

┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Elements           ┃ Results                                             ┃
┑━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
β”‚ critical score     β”‚ High                                                β”‚
β”‚ os information     β”‚ Microsoft Windows 11 21H2                           β”‚
β”‚ open ports         β”‚ 80, 22, 445, 902, 912                               β”‚
β”‚ open services      β”‚ http, ssh, microsoft-ds, vmware-auth, vmware-auth   β”‚
β”‚ vulnerable service β”‚ OpenSSH                                             β”‚
β”‚ found cve          β”‚ CVE-2023-28531                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

DNS Output: target is jainuniversity.ac.in

┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Elements ┃ Results                                                                                                           ┃
┑━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
β”‚ A        β”‚ 172.67.147.95", "104.21.41.132                                                                                    β”‚
β”‚ AAA      β”‚                                                                                                                   β”‚
β”‚ NS       β”‚ mia.ns.cloudflare.com.","paul.ns.cloudflare.com.                                                                  β”‚
β”‚ MX       β”‚ 30 aspmx5.googlemail.com.","30 aspmx4.googlemail.com.","20 alt2.aspmx.l.google.com.","30                          β”‚
β”‚          β”‚ aspmx3.googlemail.com.","30 aspmx2.googlemail.com.","20 alt1.aspmx.l.google.com.","10 aspmx.l.google.com.         β”‚
β”‚ PTR      β”‚                                                                                                                   β”‚
β”‚ SOA      β”‚ mia.ns.cloudflare.com. dns.cloudflare.com. 2309618668 10000 2400 604800 3600                                      β”‚
β”‚ TXT      β”‚ atlassian-sending-domain-verification=5b358ce4-5ad3-404d-b4b4-005bf933603b","include:_spf.atlassian.net           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

GEO Location output:

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Identifiers                 ┃ Data                                                                    ┃
┑━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
β”‚ ip                          β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                                                           β”‚
β”‚ continent_code              β”‚ AS                                                                      β”‚
β”‚ continent_name              β”‚ Asia                                                                    β”‚
β”‚ country_code2               β”‚ IN                                                                      β”‚
β”‚ country_code3               β”‚ IND                                                                     β”‚
β”‚ country_name                β”‚ India                                                                   β”‚
β”‚ country_capital             β”‚ New Delhi                                                               β”‚
β”‚ state_prov                  β”‚ Haryana                                                                 β”‚
β”‚ state_code                  β”‚ IN-HR                                                                   β”‚
β”‚ district                    β”‚                                                                         β”‚
β”‚ city                        β”‚ Gurugram                                                                β”‚
β”‚ zipcode                     β”‚ 122003                                                                  β”‚
β”‚ latitude                    β”‚ 28.44324                                                                β”‚
β”‚ longitude                   β”‚ 77.05501                                                                β”‚
β”‚ is_eu                       β”‚ False                                                                   β”‚
β”‚ calling_code                β”‚ +91                                                                     β”‚
β”‚ country_tld                 β”‚ .in                                                                     β”‚
β”‚ languages                   β”‚ en-IN,hi,bn,te,mr,ta,ur,gu,kn,ml,or,pa,as,bh,sat,ks,ne,sd,kok,doi,mni,… β”‚
β”‚ country_flag                β”‚ https://ipgeolocation.io/static/flags/in_64.png                         β”‚
β”‚ geoname_id                  β”‚ 9148991                                                                 β”‚
β”‚ isp                         β”‚ Bharti Airtel Limited                                                   β”‚
β”‚ connection_type             β”‚                                                                         β”‚
β”‚ organization                β”‚ Bharti Airtel Limited                                                   β”‚
β”‚ currency.code               β”‚ INR                                                                     β”‚
β”‚ currency.name               β”‚ Indian Rupee                                                            β”‚
β”‚ currency.symbol             β”‚ β‚Ή                                                                       β”‚
β”‚ time_zone.name              β”‚ Asia/Kolkata                                                            β”‚
β”‚ time_zone.offset            β”‚ 5.5                                                                     β”‚
β”‚ time_zone.current_time      β”‚ 2023-07-11 17:08:35.057+0530                                            β”‚
β”‚ time_zone.current_time_unix β”‚ 1689075515.057                                                          β”‚
β”‚ time_zone.is_dst            β”‚ False                                                                   β”‚
β”‚ time_zone.dst_savings       β”‚ 0                                                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Usage GUI

The GUI uses customtkinter for the running of the code. The interface is straight forward the only thing required to remember is:

  • When using dns attack dont specify the profile
python GVA_gui.py

main window

main

output_DNS

dns_output

output_nmap

nmap_output

oytput_geo

GEO_output

Advantage

  • Can be used in developing a more advanced systems completly made of the API and scanner combination
  • Has the capability to analize DNS information and reslove Mustiple records it a more better format.
  • Can increase the effectiveness of the final system
  • Can also perform subdomain enumeration
  • Highly productive when working with models such as GPT3

More Repositories

1

QuadraInspect

QuadraInspect is an Android framework that integrates AndroPass, APKUtil, and MobFS, providing a powerful tool for analyzing the security of Android applications.
Python
307
star
2

HackBot

AI-powered cybersecurity chatbot designed to provide helpful and accurate answers to your cybersecurity-related queries and also do code analysis and scan analysis.
Python
223
star
3

Nmap-API

Uses python3.10, Debian, python-Nmap, OpenaAI, and flask framework to create a Nmap API that can do scans with a good speed online and is easy to deploy. This is a implementation for our college PCL project which is still under development and constantly updating.
HTML
74
star
4

WinFiHack

A windows Wifi Brute forcing utility which is an extremely old method but still works without the requirement of external dependencies.
Python
46
star
5

CVE-llm_dataset

This is a dataset intended to train a LLM model for a completely CVE focused input and output.
29
star
6

Brute-Hacking-Framework-SourceCode

hacking framework complete source-code for web, wifi, url, sql-injection and doing a complete web scan for starters.
Batchfile
23
star
7

passinfo.cmd

contains a bruteforcer wifi hacker an batch to exe converter contains a n verity of usefull tools
Batchfile
22
star
8

Brute-Hacking-Framework

complete windows hacker's kit with all required configurations and a completely open-source toolkit
Batchfile
9
star
9

prank.batchfile

prank can be modified and do some serious damage be carefull
Batchfile
5
star
10

installer_update_brute

_b framework
Shell
5
star
11

nvim-config

Nvim Personal config for windows and WSL
Vim Script
5
star
12

AutoRat

An Android Payload Generation tool
Shell
4
star
13

nikto

web pentest app for windows ready to use
Perl
3
star
14

esp_nat_rout

C
3
star
15

Brute-Hacking-Framework-update

first update
3
star
16

wifi-esp32

C
3
star
17

morpheuslord

3
star
18

hash-generator-

contains a bruteforcer wifi hacker an batch to exe converter contains a n verity of usefull tools in python and can be converted to exe by using pyinstaller
Python
3
star
19

PCBench

PCBench is a versatile Python-based system performance benchmarking tool designed to empower users with insights into their hardware's capabilities. Whether you're a tech enthusiast, a PC gamer, or a developer optimizing your code, PCBench provides comprehensive benchmarking for both CPUs and GPUs.
Python
3
star
20

ESP-WEBSITE

My simple IoT project on coding a web page into my ESP-WROOM-32 Micro Processor.
C++
2
star
21

ZERO_W_RNDIS_DRIVERS

RNDIS Drivers for Zero w 1.1
2
star
22

C2C-Server

This is a C2C server example nothing super complecated.
Python
2
star
23

hacktool

all of these are taken and put together from a number of github users for better use thank u all for ur support and for ur effort i could not contact u all for permission so sorry for that and thinking u will consider my request and thank u
2
star
24

OSINT-TOOLS

Exe version of some osint investigation tools
1
star
25

API-Demo

HTML
1
star
26

tor-

HTML
1
star
27

Startup-SBOM

A tool to reverse engineer and inspect the RPM and APT databases to list all the packages along with executables, service and versions.
Python
1
star
28

cve-llama-trainer

1
star
29

GTA-San_savefiles

GTA San Andriese definitive editions save file.
1
star
30

Cyborg_test

a test for my cyborg vuln scanner
1
star
31

Nmap-API-GPT

Nmap API POC with openai integration for vulnerability report generation
HTML
1
star
32

payloads

1
star
33

archive

HTML
1
star
34

Encrypt_demo

Simple Demo on file encryption
Python
1
star