Skip to content

Sujaicodes/Vulnerability_Finder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vulnerability Finder: Attack Path Discovery & Mitigation Agent

A goal-based AI agent for identifying critical vulnerability chains in enterprise networks

Python License

Overview

Vulnerability Finder is an intelligent cybersecurity tool that discovers the most dangerous attack paths through enterprise networks using A search algorithm*. It analyzes Exploit-Dependency Graphs (EDGs) to identify critical vulnerability chains and recommends optimal mitigation strategies.

Key Features:

  • 🔍 Intelligent Path Discovery – Uses A* algorithm with CVSS-based heuristics to find optimal attack paths
  • 🌐 Real-time CVE Integration – Fetches live vulnerability data from the NVD (National Vulnerability Database)
  • 🎯 Multi-Mode Analysis – Live mode for custom networks or pre-built sample scenarios
  • 📊 Comprehensive Reporting – Generates visual attack paths and mitigation recommendations
  • Test Coverage – Extensive unit tests for core algorithms

How It Works

The agent models an enterprise network as a directed AND/OR attack graph where:

  • Nodes represent vulnerabilities (CVEs) or network states
  • Edges represent access gained by exploiting vulnerabilities
  • A Search* finds the minimum-cost path from external entry point → target core asset

A* Algorithm: f(n) = g(n) + h(n)

Component Definition
g(n) Cumulative cost to reach node n (actual exploit difficulty)
h(n) Estimated remaining cost (CVSS exploitability score)
f(n) Total estimated path cost

This ensures the algorithm finds the fastest attack path while being computationally efficient.


Installation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)

Setup Steps

# Clone the repository
git clone https://github.com/Sujaicodes/Vulnerability_Finder
cd Vulnerability_Finder

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate          # macOS/Linux
# OR
venv\Scripts\activate              # Windows

# Install dependencies
pip install -r requirements.txt

Dependencies

  • networkx – Graph operations and algorithms
  • requests – HTTP requests for NVD API
  • colorama – Terminal color output
  • beautifulsoup4 – HTML parsing (for NVD data)

Usage

Quick Start

python main.py

The tool presents two operational modes:

Mode 1: Live Mode 📡

  • Enter custom CVEs and network topology manually
  • Fetches real-time vulnerability data from NIST NVD API
  • Analyzes your specific attack surface
  • Best for: Testing specific networks or threat scenarios

Mode 2: Sample Mode 📚

  • Pre-built enterprise scenarios with known vulnerability chains
  • Available scenarios:
    • Enterprise network – Log4Shell vulnerability exploitation chain
    • Web application stack – Spring4Shell vulnerability exploitation chain
  • No external API calls required
  • Best for: Learning, demos, and testing

Example: Analyzing an Attack Path

$ python main.py

┌─────────────────────────────────────────────────────────┐
│  VULNERABILITY FINDER: Attack Graph Explorer            │
└─────────────────────────────────────────────────────────┘

Choose mode:
  1. Live (enter custom CVEs)
  2. Sample scenarios
> 2

Select a scenario:
  1. Enterprise network (Log4Shell chain)
  2. Web application stack (Spring4Shell chain)
> 1

[Running A* search: EXTERNAL → CORE_ASSET]
✓ Critical path found! Total attacker cost: 3.2
[Attack Path Visualization and Recommendations]

Testing

Run the full test suite to validate core components:

# Run all tests with verbose output
pytest tests/ -v

# Run specific test file
pytest tests/test_astar.py -v

# Run with coverage report
pytest tests/ --cov=src

Test Coverage

Module Tests
A Search* Pathfinding, admissibility verification
Graph Builder Node/edge creation, AND/OR logic
Heuristic CVSS calculation, admissibility
Graph Analysis Connectivity, vulnerabilities

Project Structure

Vulnerability_Finder/
├── main.py                          # Entry point
├── requirements.txt                 # Project dependencies
├── README.md                        # This file
├── LICENSE                          # MIT License
│
├── src/
│   ├── core/                        # Core algorithms
│   │   ├── astar.py                # A* search implementation
│   │   ├── graph_builder.py        # Build attack graphs
│   │   ├── heuristic.py            # CVSS-based heuristic
│   │   └── path_analyzer.py        # Path analysis & recommendations
│   │
│   ├── models/                      # Data structures
│   │   ├── network.py              # Network topology model
│   │   ├── vulnerability.py        # Vulnerability model
│   │   └── attack_graph.py         # Attack graph model
│   │
│   ├── utils/                       # Utilities
│   │   ├── cvss_calculator.py      # CVSS score computation
│   │   ├── logger.py               # Logging/formatting
│   │   ├── nvd_client.py           # NVD API client
│   │   └── visualizer.py           # Output formatting
│   │
│   └── demo/                        # Demo & UI
│       ├── demo_runner.py          # Interactive demos
│       └── sample_networks.py      # Pre-built scenarios
│
├── tests/                           # Unit tests
│   ├── test_astar.py               # A* algorithm tests
│   ├── test_graph_builder.py       # Graph building tests
│   ├── test_heuristic.py           # Heuristic validation
│   └── test_admissibility.py       # Admissibility checks
│
└── data/                            # Sample data
    ├── sample_topology.json        # Network topology
    ├── sample_vulnerabilities.json # Vulnerability data
    └── scenarios/
        ├── enterprise_network.json # Enterprise scenario
        └── web_app_stack.json      # Web app scenario

Core Components

📍 A* Search (src/core/astar.py)

  • Optimal pathfinding algorithm for attack graphs
  • Guarantees shortest cost path when heuristic is admissible
  • Handles AND/OR nodes for complex attack scenarios

🔗 Graph Builder (src/core/graph_builder.py)

  • Constructs attack graphs from vulnerability data
  • Models attack dependencies and preconditions
  • Supports dynamic edge creation

📊 Heuristic (src/core/heuristic.py)

  • Computes CVSS-based admissible heuristics
  • Ensures A* optimality
  • Highly efficient for large graphs

💊 Path Analyzer (src/core/path_analyzer.py)

  • Analyzes critical attack paths
  • Generates mitigation recommendations
  • Ranks vulnerabilities by impact

📈 Data Models (src/models/)

  • Vulnerability – CVE information, CVSS scores, descriptions
  • Network – Node topology, asset definitions
  • AttackGraph – Multi-node structures with attack semantics

API Reference

Running Analysis Programmatically

from src.core.graph_builder import build_attack_graph
from src.core.astar import astar_search
from src.core.path_analyzer import recommend_mitigation

# Build attack graph
G = build_attack_graph(nodes, edges)

# Find optimal attack path
path = astar_search(G, start="EXTERNAL", goal="CORE_ASSET")

# Get mitigation recommendations
if path:
    recommendations = recommend_mitigation(G, path)
    for rec in recommendations:
        print(f"Patch: {rec['cve']} (Impact: {rec['impact']})")

Key Classes

AttackGraph

graph = AttackGraph()
graph.add_node(node_id, cvss_score=7.5, cve="CVE-2021-44228")
graph.add_edge(source, target, dependency_type="OR")

Vulnerability

vuln = Vulnerability(
    cve_id="CVE-2021-44228",
    cvss_score=10.0,
    description="Log4j RCE",
    exploitability=3.9
)

Configuration

NVD API

The tool uses the NIST NVD API for real-time CVE data. Visit nvd.nist.gov for API documentation.

Custom Scenarios

Add new attack scenarios in data/scenarios/ as JSON files:

{
  "nodes": [
    {"id": "EXTERNAL", "type": "entry_point"},
    {"id": "CVE-2021-44228", "type": "vulnerability", "cvss": 10.0}
  ],
  "edges": [
    {"source": "EXTERNAL", "target": "CVE-2021-44228"}
  ]
}

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Add tests for new functionality
  4. Commit changes (git commit -m 'Add amazing feature')
  5. Push to branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Development Guidelines

  • Maintain test coverage above 80%
  • Follow PEP 8 style guidelines
  • Document new functions with docstrings
  • Update README for significant changes

Performance Considerations

  • Graph Size: Efficiently handles networks with 500+ nodes
  • Search Time: Typically <1s for moderate networks due to A* pruning
  • Memory: Linear scaling with graph size
  • NVD API: Cached queries to minimize API rate limiting

Known Limitations

  • AND/OR graph evaluation requires exponential worst-case time
  • NVD API has rate limits (~5 requests/30 seconds)
  • Heuristic quality depends on CVSS data accuracy

Troubleshooting

NVD API Connection Fails

# Verify internet connection and NVD API status
curl https://services.nvd.nist.gov/rest/json/cves/1.0

Tests Fail

  • Ensure all dependencies installed: pip install -r requirements.txt
  • Clear Python cache: find . -type d -name __pycache__ -exec rm -r {} +

Memory Issues with Large Graphs

  • Reduce graph size in sample data
  • Consider breaking analysis into smaller subgraphs

References


License

This project is licensed under the MIT License – see LICENSE file for details.


Support

For issues, questions, or suggestions:


Made with ❤️ for cybersecurity research and defense

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages