<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mukarram Ali on Medium]]></title>
        <description><![CDATA[Stories by Mukarram Ali on Medium]]></description>
        <link>https://medium.com/@mukarramali_63849?source=rss-527d8ab0f82b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QtV_ewo4qAY6M3Np.</url>
            <title>Stories by Mukarram Ali on Medium</title>
            <link>https://medium.com/@mukarramali_63849?source=rss-527d8ab0f82b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:14:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mukarramali_63849/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating HexStrike AI with Local Ollama for Privacy-Focused Pentesting (WSL + Kali)]]></title>
            <link>https://medium.com/@mukarramali_63849/running-hexstrike-ai-with-a-local-ollama-backend-wsl-kali-7f30f32cb5af?source=rss-527d8ab0f82b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f30f32cb5af</guid>
            <category><![CDATA[kali-linux]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Mukarram Ali]]></dc:creator>
            <pubDate>Mon, 29 Dec 2025 18:31:50 GMT</pubDate>
            <atom:updated>2026-01-02T00:48:04.467Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Is HexStrike AI?</h3><p>HexStrike AI is an MCP (Model Context Protocol) server that bridges AI agents with 150+ cybersecurity tools through both MCP protocol and REST API interfaces. While it’s commonly used with cloud-based AI agents like Claude and GPT via the MCP protocol, this article demonstrates an alternative approach: directly integrating HexStrike’s REST API with Ollama, a local LLM running on WSL. This setup creates a fully privacy-focused, AI-assisted pentesting workflow where a local language model orchestrates reconnaissance, analyzes results, and makes intelligent testing decisions , all without sending sensitive data to external services. By combining HexStrike’s tool execution capabilities with local AI intelligence, this approach provides the automation benefits of AI-assisted security testing while maintaining complete operational security and data privacy.</p><p>HexStrike AI project repository:<br>https://github.com/0x4m4/hexstrike-ai</p><h3><strong>Why HexStrike + Local LLMs Matter</strong></h3><p>Modern penetration testing generates <strong>high-risk data by default</strong>: internal hostnames, API tokens, session cookies, source code paths, exploit primitives, and client-specific business logic.</p><p>Sending this information to cloud-hosted LLMs introduces unnecessary risk, even when vendors claim data isolation.</p><p>Running <strong>HexStrike AI with a fully local LLM</strong> changes the trust model entirely:</p><ul><li>Zero data exfiltration — prompts and responses never leave your infrastructure</li><li>Regulatory compatibility — suitable for internal testing and restricted environments</li><li>Deterministic behavior — no silent model changes, throttling, or quotas</li><li>Operational realism — mirrors how serious offensive tooling is deployed in practice.</li></ul><p>This setup is not about novelty or hype. It is about <strong>control, auditability, and trust</strong>.</p><h3>Architecture Overview</h3><ul><li><strong>Windows 11 host</strong></li><li>NVIDIA GPU + WSL2</li><li>Acts as the controlled network boundary</li><li><strong>WSL2 (Ubuntu)</strong></li><li>Ollama runs here and exposes an OpenAI-compatible API</li><li><strong>Kali Linux (VM or bare metal)</strong></li><li>Hexstrike AI consumes Ollama API</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*O1gZAIeBWGamWci5P7TFXA.png" /></figure><p>Traffic flow:</p><p>Hexstrike (Kali) → Windows Host IP:11434 → Port Proxy → WSL Ollama :11434</p><p>No cloud LLMs. No external data exposure.</p><h3>Install WSL + NVIDIA GPU Support</h3><p><strong>Enable WSL + Virtual Machine Platform (Windows PowerShell Admin)</strong></p><p>(Right-click PowerShell → Run as Administrator)</p><pre>dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all <br>dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all</pre><p>Reboot your PC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OvNArpcS05RjKzYdNRoN7A.png" /></figure><h3>Install WSL (latest version)</h3><p>After reboot, open PowerShell (normal):</p><pre>wsl --install</pre><p>This will automatically:</p><p>install WSL2</p><p>install Ubuntu (default)</p><p>configure the Linux kernel</p><p>set WSL2 as the default backend</p><p>Reboot your system again after this step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2DtmWCkXblHD4zifLxpPA.png" /></figure><p>Set the username and strong password for your new WSL user. Switch to your home directory by cd ~</p><p>Inside Ubuntu run:</p><pre>sudo apt update &amp;&amp; sudo apt upgrade -y</pre><p>Install Required Tools (Git, Build Tools, etc.)</p><pre>sudo apt install -y git curl wget build-essential</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fi6SGCxVE1bG-0DDydP5Mg.png" /></figure><p>Before proceeding, enable GPU support in WSL. This requires having the correct Windows GPU driver installed so your Ubuntu environment can access the GPU for local LLM inference.</p><h3>Optional: Install NVIDIA CUDA Toolkit</h3><pre>sudo apt install -y nvidia-cuda-toolkit</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wf5S4OKYhqdaT_Jd6Xh_Jw.png" /></figure><p>Verify GPU Support in WSL (Optional but Recommended)</p><p>On <strong>Windows</strong>, ensure you have a recent NVIDIA driver with WSL support.</p><p>Inside <strong>WSL</strong>, verify GPU visibility:</p><pre>nvidia-smi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zvjxk0SBdxCBTzaBXez-8A.png" /></figure><h3>Install and Run Ollama in WSL</h3><p>Install Ollama inside WSL (Ubuntu)</p><pre>curl -fsSL https://ollama.com/install.sh | sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tyMgcJOp9FWeS2meO8FVA.png" /></figure><p>Note: Do not rely solely on systemctl to start Ollama, unless you explicitly enabled systemd in WSL. The secondary approach is to run Ollama manually. If systemctl fails in WSL, use ollama serve instead.</p><p>Start Ollama service</p><pre>sudo systemctl enable ollama<br>sudo systemctl start ollama</pre><p>Verify it’s running:</p><pre>systemctl status ollama</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yRgPryUGjCgIIb4xtbhzXA.png" /></figure><p>Alternatively, you can start Ollama by running the command below and keep this terminal open.</p><pre>ollama serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SWjILj7B1nF-PDLjEG7GAA.png" /></figure><p>Pull Required Models</p><pre>ollama pull qwen2.5:7b<br>ollama pull llama3.1:8b</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L-xEBbqU4exJY-wlTV-mFQ.png" /></figure><p>I am using llama3.1:8b — Meta’s 8-billion parameter model that balances <br>performance with efficiency. It offers strong reasoning capabilities <br>perfect for AI-powered security tools. You can also try llama3.2:3b <br>(faster, lighter) or qwen2.5:7b (better for complex coding tasks).</p><p>Verify models are available:</p><pre>ollama list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CwFWSAyj3ZzgKN7K53gOmw.png" /></figure><p>Verify Ollama API (Local):</p><p>Open another WSL tab and run a quick check by running the following command to verify that your Ollama API is running and to confirm which local LLM models are installed.</p><pre>curl http://localhost:11434/api/tags</pre><p>This endpoint is used to validate that Ollama is running and reachable. Hexstrike itself communicates with Ollama via the OpenAI-compatible /v1 API.</p><p>This API endpoint returns a JSON response that shows your installed models, their quantization levels, model sizes, modified dates, and file formats (such as GGUF). Seeing this output confirms that the Ollama service is running correctly, the API port <strong>11434</strong> is reachable, your models were downloaded successfully, and WSL is correctly using your local LLM models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjcW8itObGJQwjBH69is8w.png" /></figure><h3>Expose Ollama to the Windows Host</h3><p>Ollama binds to WSL only by default. We expose it safely using Windows port forwarding.</p><p>Get the WSL IP by running the hostname -I command(run inside WSL)</p><pre>hostname -I<br>Example: 172.26.245.138</pre><p><strong>Note:</strong> The WSL IP address changes on reboot. You’ll need to update the port proxy rules if your WSL IP changes.</p><p>Configure Windows Port Proxy (Run PowerShell as Administrator)</p><pre>netsh interface portproxy add v4tov4 `<br>  listenaddress=0.0.0.0 `<br>  listenport=11434 `<br>  connectaddress=172.26.245.138 `<br>  connectport=11434</pre><p>Configure Windows Firewall</p><p>Allow inbound TCP traffic on port 11434:</p><pre>New-NetFirewallRule `<br>  -DisplayName &quot;Allow Ollama 11434&quot; `<br>  -Direction Inbound `<br>  -Protocol TCP `<br>  -LocalPort 11434 `<br>  -Action Allow</pre><p>Verify:</p><pre>netsh interface portproxy show all<br>netstat -ano | findstr 11434</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*lNuZ8TrVl_aSWDNgomuR2Q.png" /></figure><p>(Optional) Restrict to Kali IP later if desired.</p><p>Verify Access from Kali</p><pre>curl [http://192.168.2.151:11434/api/tags](http://192.168.2.151:11434/api/tags)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZFDDhpKQBMkqgUJ44_q4HA.png" /></figure><p>If models are returned, networking is correct.</p><h3>Configure Hexstrike AI</h3><p>Prepare Kali dependencies</p><pre>sudo apt update -y<br>sudo apt install -y git python3 python3-venv python3-pip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BEYPfP6ANSzR4BFgbQoTWQ.png" /></figure><p>Then <strong>inside the Hexstrike virtual environment</strong>:</p><pre>python3 -m venv hexstrike-env<br>source hexstrike-env/bin/activate<br><br>pip install selenium beautifulsoup4 mitmproxy aiohttp requests psutil</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycDoXpF4g-y3xtC640NjVg.png" /></figure><p>Hexstrike AI relies on several Python libraries that must be installed inside a virtual environment. Installing dependencies in a virtual environment avoids polluting the system Python and prevents version conflicts. Depending on enabled features, some modules (e.g., Selenium or mitmproxy) may be optional.</p><p>Clone and install Hexstrike AI on Kali:</p><pre>git clone https://github.com/0x4m4/Hexstrike-ai.git<br>cd Hexstrike-ai<br>python3 -m venv venv<br>source venv/bin/activate<br>pip install -r requirements.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mmt6JP42z7waiXrxX2x05Q.png" /></figure><p>Create a .env file in the Hexstrike directory:</p><pre>nano .env</pre><p>Paste the following</p><pre>OPENAI_API_BASE=http://&lt;WINDOWS-HOST-IP&gt;:11434/v1<br>OPENAI_API_KEY=ollama<br>OPENAI_MODEL=qwen2.5:7b</pre><p>Notes:</p><p>/v1 is Ollama’s OpenAI-compatible API.</p><p>The API key is a placeholder (Ollama does not require authentication).</p><h3>Create a Simple Start Script (Recommended) to start the Hexstrike</h3><p>This step avoids forgetting to export variables.</p><p>Create the script:</p><pre>nano start_Hexstrike.sh</pre><pre>#!/usr/bin/env bash<br>set -euo pipefail<br><br><br>cd &quot;$(dirname &quot;$0&quot;)&quot;<br><br><br># Load .env into environment<br>set -a<br>source .env<br>set +a<br><br><br>echo &quot;[+] Starting Hexstrike with:&quot;<br>echo &quot; OPENAI_API_BASE=$OPENAI_API_BASE&quot;<br>echo &quot; OPENAI_API_KEY=$OPENAI_API_KEY&quot;<br>echo &quot; OPENAI_MODEL=$OPENAI_MODEL&quot;<br><br><br>exec python3 Hexstrike_server.py --port 8888</pre><p>Make it executable and start Hexstrike</p><pre>chmod +x start_Hexstrike.sh<br><br>./start_Hexstrike.sh<br></pre><p>If Hexstrike starts successfully, it will bind locally on Kali at port 8888 (as configured above).</p><p>Notes:</p><p>/v1 is Ollama’s OpenAI‑compatible API</p><p>The API key is a placeholder (Ollama does not require authentication)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5319TrcQ8wPYpKlN8HBSbw.png" /></figure><h3>Proving Hexstrike Is Actually Using the LLM (Critical)</h3><p>create a small script <strong>test_Hexstrike_ollama.py</strong></p><pre>#!/usr/bin/env python3<br>&quot;&quot;&quot;<br>Hexstrike-Ollama Connection Test<br>&quot;&quot;&quot;<br>import requests<br>import json<br>import sys<br><br># Configuration<br>Hexstrike_URL = &quot;http://192.168.2.154:8888&quot;  # Change if needed<br>OLLAMA_URL = &quot;http://192.168.2.151:11434&quot;     # Ollama on same machine or WSL<br><br>def test_Hexstrike():<br>    &quot;&quot;&quot;Test Hexstrike server connection&quot;&quot;&quot;<br>    print(&quot;\n[*] Testing Hexstrike connection...&quot;)<br>    try:<br>        response = requests.get(f&quot;{Hexstrike_URL}/health&quot;, timeout=5)<br>        if response.status_code == 200:<br>            print(&quot;✓ Hexstrike is running!&quot;)<br>            print(f&quot;  Response: {response.json()}&quot;)<br>            return True<br>        else:<br>            print(f&quot;✗ Hexstrike returned status: {response.status_code}&quot;)<br>            return False<br>    except requests.exceptions.ConnectionError:<br>        print(&quot;✗ Cannot connect to Hexstrike&quot;)<br>        print(&quot;  Make sure it&#39;s running: python3 Hexstrike_server.py&quot;)<br>        return False<br>    except Exception as e:<br>        print(f&quot;✗ Error: {e}&quot;)<br>        return False<br><br>def test_ollama():<br>    &quot;&quot;&quot;Test Ollama connection&quot;&quot;&quot;<br>    print(&quot;\n[*] Testing Ollama connection...&quot;)<br>    try:<br>        response = requests.get(f&quot;{OLLAMA_URL}/api/tags&quot;, timeout=5)<br>        if response.status_code == 200:<br>            models = response.json().get(&#39;models&#39;, [])<br>            print(&quot;✓ Ollama is running!&quot;)<br>            print(f&quot;  Available models: {[m[&#39;name&#39;] for m in models]}&quot;)<br>            return True<br>        else:<br>            print(f&quot;✗ Ollama returned status: {response.status_code}&quot;)<br>            return False<br>    except requests.exceptions.ConnectionError:<br>        print(&quot;✗ Cannot connect to Ollama&quot;)<br>        print(&quot;  Make sure it&#39;s running: ollama serve&quot;)<br>        return False<br>    except Exception as e:<br>        print(f&quot;✗ Error: {e}&quot;)<br>        return False<br><br>def test_Hexstrike_tools():<br>    &quot;&quot;&quot;Test Hexstrike tool listing&quot;&quot;&quot;<br>    print(&quot;\n[*] Testing Hexstrike tools...&quot;)<br>    try:<br>        response = requests.get(f&quot;{Hexstrike_URL}/api/tools/list&quot;, timeout=10)<br>        if response.status_code == 200:<br>            tools = response.json()<br>            print(f&quot;✓ Found {len(tools)} tools&quot;)<br>            print(f&quot;  Sample tools: {tools[:5]}&quot;)<br>            return True<br>        else:<br>            print(f&quot;✗ Failed to get tools: {response.status_code}&quot;)<br>            return False<br>    except Exception as e:<br>        print(f&quot;✗ Error: {e}&quot;)<br>        return False<br><br>def main():<br>    print(&quot;=&quot;*60)<br>    print(&quot;Hexstrike + Ollama Connection Test&quot;)<br>    print(&quot;=&quot;*60)<br>    <br>    Hexstrike_ok = test_Hexstrike()<br>    ollama_ok = test_ollama()<br>    <br>    if Hexstrike_ok:<br>        test_Hexstrike_tools()<br>    <br>    print(&quot;\n&quot; + &quot;=&quot;*60)<br>    print(&quot;Summary:&quot;)<br>    print(f&quot;  Hexstrike: {&#39;✓ Ready&#39; if Hexstrike_ok else &#39;✗ Not running&#39;}&quot;)<br>    print(f&quot;  Ollama:    {&#39;✓ Ready&#39; if ollama_ok else &#39;✗ Not running&#39;}&quot;)<br>    print(&quot;=&quot;*60)<br>    <br>    if Hexstrike_ok and ollama_ok:<br>        print(&quot;\n✓ Both systems are ready! You can start pentesting.&quot;)<br>        return 0<br>    else:<br>        print(&quot;\n✗ Fix the issues above before proceeding.&quot;)<br>        return 1<br><br>if __name__ == &quot;__main__&quot;:<br>    sys.exit(main())</pre><p>Make it executable and run the script</p><pre>chmod +x test_Hexstrike_ollama.py<br><br>python3 test_Hexstrike_ollama.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gwRTnnf2R0h4ppOC4xZ72Q.png" /></figure><h3>Optional — AI‑Guided Pentest Script</h3><p>This script demonstrates the real power of combining HexStrike <br>with a local LLM: autonomous, AI-driven penetration testing. Instead of <br>manually running commands, the AI analyzes results in real-time, decides <br>the next testing steps, and adapts its strategy based on findings.</p><p>The script includes:<br>- Built-in scope management to prevent testing out-of-scope targets<br>- AI-powered decision making for test strategy and tool selection<br>- Automatic vulnerability prioritization and remediation recommendations<br>- JSON report generation for documentation</p><p>This is where local LLMs shine in security work — your sensitive recon data <br>and findings never leave your infrastructure, while still benefiting from <br>AI-assisted analysis and decision-making.</p><p>Create an AI-Guided Pentest script ai_pentest_scoped.py to use with <br>HexStrike AI, and define your scope inside the file:</p><pre>nano ai_pentest_scoped.py</pre><p>Paste the following script</p><pre>#!/usr/bin/env python3<br>&quot;&quot;&quot;<br>AI-Guided Penetration Testing with Scope Management<br>Combines Ollama AI decision-making with Hexstrike tools<br>&quot;&quot;&quot;<br>import requests<br>import json<br>import time<br>from datetime import datetime<br><br># Configuration<br>Hexstrike = &quot;http://192.168.2.154:8888&quot;<br>OLLAMA = &quot;http://192.168.2.151:11434&quot;<br>OLLAMA_MODEL = &quot;llama3.1:8b&quot;  # or &quot;qwen2.5:7b&quot;<br><br># ============= SCOPE DEFINITION =============<br>SCOPE = {<br>    &quot;target&quot;: &quot;example.com&quot;,  # Main target<br>    &quot;target_type&quot;: &quot;web_application&quot;,  # Options: web_application, network, api, mobile<br>    <br>    # In-scope items<br>    &quot;in_scope&quot;: [<br>        &quot;example.com&quot;,<br>        &quot;*.example.com&quot;,  # All subdomains<br>        # Add more in-scope targets<br>    ],<br>    <br>    # Out-of-scope items (will be blocked)<br>    &quot;out_of_scope&quot;: [<br>        &quot;admin.example.com&quot;,  # Example: admin panel<br>        # Add sensitive areas<br>    ],<br>    <br>    # Testing constraints<br>    &quot;constraints&quot;: {<br>        &quot;max_threads&quot;: 10,<br>        &quot;rate_limit&quot;: &quot;100/minute&quot;,  # Requests per minute<br>        &quot;time_limit&quot;: 3600,  # Max test duration in seconds (1 hour)<br>        &quot;allowed_tools&quot;: [  # Restrict which tools can be used<br>            &quot;nmap&quot;, &quot;subfinder&quot;, &quot;whatweb&quot;, &quot;nuclei&quot;, <br>            &quot;httpx&quot;, &quot;nikto&quot;, &quot;sqlmap&quot;, &quot;gobuster&quot;<br>        ],<br>        &quot;forbidden_tools&quot;: [  # Never use these<br>            &quot;metasploit&quot;, &quot;hydra&quot;, &quot;medusa&quot;  # No brute forcing<br>        ]<br>    },<br>    <br>    # Test objectives<br>    &quot;objectives&quot;: [<br>        &quot;subdomain_discovery&quot;,<br>        &quot;technology_detection&quot;, <br>        &quot;vulnerability_scanning&quot;,<br>        &quot;security_headers_check&quot;<br>    ],<br>    <br>    # Sensitivity level<br>    &quot;sensitivity&quot;: &quot;moderate&quot;,  # Options: passive, moderate, aggressive<br>    <br>    # Authorization details<br>    &quot;authorization&quot;: {<br>        &quot;authorized_by&quot;: &quot;Security Team&quot;,<br>        &quot;authorization_date&quot;: &quot;2024-01-15&quot;,<br>        &quot;engagement_type&quot;: &quot;authorized_pentest&quot;  # or &quot;bug_bounty&quot;, &quot;ctf&quot;<br>    }<br>}<br># ============================================<br><br>def check_scope(target):<br>    &quot;&quot;&quot;Verify target is within scope&quot;&quot;&quot;<br>    # Check if target is in out_of_scope<br>    for out in SCOPE[&#39;out_of_scope&#39;]:<br>        if out in target:<br>            return False, f&quot;Target &#39;{target}&#39; is OUT OF SCOPE&quot;<br>    <br>    # Check if target matches in_scope patterns<br>    for in_scope in SCOPE[&#39;in_scope&#39;]:<br>        if &#39;*&#39; in in_scope:<br>            # Wildcard matching<br>            pattern = in_scope.replace(&#39;*.&#39;, &#39;&#39;)<br>            if pattern in target:<br>                return True, f&quot;Target &#39;{target}&#39; is IN SCOPE&quot;<br>        elif in_scope in target:<br>            return True, f&quot;Target &#39;{target}&#39; is IN SCOPE&quot;<br>    <br>    return False, f&quot;Target &#39;{target}&#39; not found in scope definition&quot;<br><br>def check_tool_allowed(tool):<br>    &quot;&quot;&quot;Check if tool is allowed in scope&quot;&quot;&quot;<br>    if tool in SCOPE[&#39;constraints&#39;][&#39;forbidden_tools&#39;]:<br>        return False, f&quot;Tool &#39;{tool}&#39; is FORBIDDEN by scope&quot;<br>    <br>    if SCOPE[&#39;constraints&#39;][&#39;allowed_tools&#39;] and \<br>       tool not in SCOPE[&#39;constraints&#39;][&#39;allowed_tools&#39;]:<br>        return False, f&quot;Tool &#39;{tool}&#39; is NOT in allowed list&quot;<br>    <br>    return True, f&quot;Tool &#39;{tool}&#39; is allowed&quot;<br><br>def ask_ollama(question, context=&quot;&quot;):<br>    &quot;&quot;&quot;Ask Ollama for pentesting advice&quot;&quot;&quot;<br>    full_prompt = f&quot;&quot;&quot;{context}<br><br>{question}<br><br>Remember: You are a professional penetration tester. Be specific and technical.&quot;&quot;&quot;<br>    <br>    try:<br>        response = requests.post(f&quot;{OLLAMA}/api/generate&quot;, json={<br>            &quot;model&quot;: OLLAMA_MODEL,<br>            &quot;prompt&quot;: full_prompt,<br>            &quot;stream&quot;: False,<br>            &quot;options&quot;: {<br>                &quot;temperature&quot;: 0.7,<br>                &quot;top_p&quot;: 0.9<br>            }<br>        }, timeout=60)<br>        <br>        if response.status_code == 200:<br>            return response.json()[&#39;response&#39;]<br>        else:<br>            return f&quot;Error: Ollama returned {response.status_code}&quot;<br>    except Exception as e:<br>        return f&quot;Error communicating with Ollama: {e}&quot;<br><br>def execute_Hexstrike_command(cmd, description=&quot;&quot;):<br>    &quot;&quot;&quot;Execute command via Hexstrike with error handling&quot;&quot;&quot;<br>    print(f&quot;[+] {description}&quot;)<br>    print(f&quot;    Command: {cmd}&quot;)<br>    <br>    try:<br>        response = requests.post(f&quot;{Hexstrike}/api/command&quot;, <br>                                json={&quot;command&quot;: cmd}, <br>                                timeout=300)  # 5 min timeout<br>        <br>        if response.status_code == 200:<br>            result = response.json()<br>            output = result.get(&#39;output&#39;, &#39;No output&#39;)<br>            return True, output<br>        else:<br>            return False, f&quot;HTTP Error {response.status_code}&quot;<br>    except Exception as e:<br>        return False, f&quot;Error: {e}&quot;<br><br>def print_scope_summary():<br>    &quot;&quot;&quot;Display scope information&quot;&quot;&quot;<br>    print(&quot;\n&quot; + &quot;=&quot;*70)<br>    print(&quot;PENETRATION TEST SCOPE&quot;)<br>    print(&quot;=&quot;*70)<br>    print(f&quot;Target:          {SCOPE[&#39;target&#39;]}&quot;)<br>    print(f&quot;Type:            {SCOPE[&#39;target_type&#39;]}&quot;)<br>    print(f&quot;Sensitivity:     {SCOPE[&#39;sensitivity&#39;]}&quot;)<br>    print(f&quot;Authorized by:   {SCOPE[&#39;authorization&#39;][&#39;authorized_by&#39;]}&quot;)<br>    print(f&quot;Date:            {SCOPE[&#39;authorization&#39;][&#39;authorization_date&#39;]}&quot;)<br>    print(f&quot;\nIn Scope:&quot;)<br>    for item in SCOPE[&#39;in_scope&#39;]:<br>        print(f&quot;  ✓ {item}&quot;)<br>    print(f&quot;\nOut of Scope:&quot;)<br>    for item in SCOPE[&#39;out_of_scope&#39;]:<br>        print(f&quot;  ✗ {item}&quot;)<br>    print(f&quot;\nObjectives:&quot;)<br>    for obj in SCOPE[&#39;objectives&#39;]:<br>        print(f&quot;  → {obj}&quot;)<br>    print(&quot;=&quot;*70 + &quot;\n&quot;)<br><br>def ai_guided_pentest():<br>    &quot;&quot;&quot;Main AI-guided penetration testing function&quot;&quot;&quot;<br>    <br>    # Display scope<br>    print_scope_summary()<br>    <br>    # Verify scope<br>    in_scope, msg = check_scope(SCOPE[&#39;target&#39;])<br>    if not in_scope:<br>        print(f&quot;❌ {msg}&quot;)<br>        print(&quot;Aborting test - target not in scope!&quot;)<br>        return<br>    <br>    print(f&quot;✓ {msg}\n&quot;)<br>    <br>    # Initialize report<br>    report = {<br>        &quot;target&quot;: SCOPE[&#39;target&#39;],<br>        &quot;start_time&quot;: datetime.now().isoformat(),<br>        &quot;scope&quot;: SCOPE,<br>        &quot;phases&quot;: []<br>    }<br>    <br>    target = SCOPE[&#39;target&#39;]<br>    <br>    # Phase 1: AI Strategy Planning<br>    print(&quot;\n&quot; + &quot;=&quot;*70)<br>    print(&quot;PHASE 1: AI STRATEGY PLANNING&quot;)<br>    print(&quot;=&quot;*70 + &quot;\n&quot;)<br>    <br>    planning_prompt = f&quot;&quot;&quot;As a penetration testing expert, create a testing strategy for:<br><br>Target: {target}<br>Type: {SCOPE[&#39;target_type&#39;]}<br>Sensitivity: {SCOPE[&#39;sensitivity&#39;]}<br><br>Available tools: {&#39;, &#39;.join(SCOPE[&#39;constraints&#39;][&#39;allowed_tools&#39;])}<br><br>Objectives:<br>{chr(10).join(&#39;- &#39; + obj for obj in SCOPE[&#39;objectives&#39;])}<br><br>Provide EXACTLY 4 specific testing steps. Format each as:<br>Step X: [tool_name] - [specific_command_flags] - [reason]<br><br>Example:<br>Step 1: whatweb - -a 3 {target} - Identify web technologies and frameworks<br>Step 2: subfinder - -d {target} -silent - Discover subdomains<br><br>Be concise and specific.&quot;&quot;&quot;<br><br>    print(&quot;[AI] 🤖 Planning reconnaissance strategy...&quot;)<br>    strategy = ask_ollama(planning_prompt)<br>    print(f&quot;\n[AI] Strategy:\n{&#39;-&#39;*70}\n{strategy}\n{&#39;-&#39;*70}\n&quot;)<br>    <br>    report[&#39;phases&#39;].append({<br>        &quot;phase&quot;: &quot;planning&quot;,<br>        &quot;strategy&quot;: strategy,<br>        &quot;timestamp&quot;: datetime.now().isoformat()<br>    })<br>    <br>    # Parse strategy to extract steps<br>    steps = []<br>    for line in strategy.split(&#39;\n&#39;):<br>        if line.strip().startswith((&#39;Step&#39;, &#39;1.&#39;, &#39;2.&#39;, &#39;3.&#39;, &#39;4.&#39;)):<br>            steps.append(line.strip())<br>    <br>    print(f&quot;[*] Identified {len(steps)} testing steps\n&quot;)<br>    <br>    # Phase 2: Execute Reconnaissance<br>    print(&quot;\n&quot; + &quot;=&quot;*70)<br>    print(&quot;PHASE 2: RECONNAISSANCE&quot;)<br>    print(&quot;=&quot;*70 + &quot;\n&quot;)<br>    <br>    phase_results = []<br>    <br>    # Execute first few commands<br>    commands_to_run = [<br>        (&quot;whatweb&quot;, f&quot;whatweb https://{target} -a 3&quot;, &quot;Technology Detection&quot;),<br>        (&quot;httpx&quot;, f&quot;echo https://{target} | httpx -status-code -tech-detect -title&quot;, &quot;HTTP Probe&quot;),<br>        (&quot;subfinder&quot;, f&quot;subfinder -d {target} -silent&quot;, &quot;Subdomain Discovery&quot;),<br>    ]<br>    <br>    for tool, cmd, desc in commands_to_run:<br>        # Check if tool is allowed<br>        allowed, msg = check_tool_allowed(tool)<br>        if not allowed:<br>            print(f&quot;⚠️  Skipping: {msg}\n&quot;)<br>            continue<br>        <br>        success, output = execute_Hexstrike_command(cmd, desc)<br>        <br>        if success:<br>            print(f&quot;✓ Success (first 500 chars):&quot;)<br>            print(f&quot;{output[:500]}\n&quot;)<br>            phase_results.append({<br>                &quot;tool&quot;: tool,<br>                &quot;command&quot;: cmd,<br>                &quot;success&quot;: True,<br>                &quot;output&quot;: output[:1000]  # Store first 1000 chars<br>            })<br>        else:<br>            print(f&quot;✗ Failed: {output}\n&quot;)<br>            phase_results.append({<br>                &quot;tool&quot;: tool,<br>                &quot;command&quot;: cmd,<br>                &quot;success&quot;: False,<br>                &quot;error&quot;: output<br>            })<br>        <br>        time.sleep(2)  # Rate limiting<br>    <br>    report[&#39;phases&#39;].append({<br>        &quot;phase&quot;: &quot;reconnaissance&quot;,<br>        &quot;results&quot;: phase_results,<br>        &quot;timestamp&quot;: datetime.now().isoformat()<br>    })<br>    <br>    # Phase 3: AI Analysis &amp; Recommendations<br>    print(&quot;\n&quot; + &quot;=&quot;*70)<br>    print(&quot;PHASE 3: AI ANALYSIS&quot;)<br>    print(&quot;=&quot;*70 + &quot;\n&quot;)<br>    <br>    # Combine results for AI analysis<br>    results_summary = &quot;\n&quot;.join([<br>        f&quot;{r[&#39;tool&#39;]}: {&#39;Success&#39; if r[&#39;success&#39;] else &#39;Failed&#39;}\n{r.get(&#39;output&#39;, r.get(&#39;error&#39;, &#39;&#39;))[:300]}&quot;<br>        for r in phase_results<br>    ])<br>    <br>    analysis_prompt = f&quot;&quot;&quot;Analyze these penetration test results:<br><br>{results_summary}<br><br>Based on the findings:<br>1. Identify 2-3 key security findings<br>2. Recommend the next 2 testing actions (be specific with tools and targets)<br>3. Rate overall security posture (Low/Medium/High risk)<br><br>Be concise and actionable.&quot;&quot;&quot;<br><br>    print(&quot;[AI] 🤖 Analyzing results...&quot;)<br>    analysis = ask_ollama(analysis_prompt, context=&quot;You are analyzing real penetration test results.&quot;)<br>    print(f&quot;\n[AI] Analysis:\n{&#39;-&#39;*70}\n{analysis}\n{&#39;-&#39;*70}\n&quot;)<br>    <br>    report[&#39;phases&#39;].append({<br>        &quot;phase&quot;: &quot;analysis&quot;,<br>        &quot;analysis&quot;: analysis,<br>        &quot;timestamp&quot;: datetime.now().isoformat()<br>    })<br>    <br>    # Phase 4: Vulnerability Scanning (if in objectives)<br>    if &quot;vulnerability_scanning&quot; in SCOPE[&#39;objectives&#39;]:<br>        print(&quot;\n&quot; + &quot;=&quot;*70)<br>        print(&quot;PHASE 4: VULNERABILITY SCANNING&quot;)<br>        print(&quot;=&quot;*70 + &quot;\n&quot;)<br>        <br>        vuln_cmd = f&quot;nuclei -u https://{target} -severity critical,high,medium -silent&quot;<br>        success, output = execute_Hexstrike_command(vuln_cmd, &quot;Nuclei Vulnerability Scan&quot;)<br>        <br>        if success and output.strip():<br>            print(f&quot;⚠️  Vulnerabilities Found:\n{output[:800]}\n&quot;)<br>            <br>            # Ask AI to prioritize vulnerabilities<br>            vuln_analysis_prompt = f&quot;&quot;&quot;Analyze these vulnerability scan results:<br><br>{output[:1000]}<br><br>Provide:<br>1. Top 3 most critical findings<br>2. Exploitation difficulty for each<br>3. Recommended remediation priority<br><br>Be specific and practical.&quot;&quot;&quot;<br>            <br>            print(&quot;[AI] 🤖 Prioritizing vulnerabilities...&quot;)<br>            vuln_analysis = ask_ollama(vuln_analysis_prompt)<br>            print(f&quot;\n[AI] Vulnerability Analysis:\n{&#39;-&#39;*70}\n{vuln_analysis}\n{&#39;-&#39;*70}\n&quot;)<br>            <br>            report[&#39;phases&#39;].append({<br>                &quot;phase&quot;: &quot;vulnerability_scanning&quot;,<br>                &quot;raw_output&quot;: output[:2000],<br>                &quot;ai_analysis&quot;: vuln_analysis,<br>                &quot;timestamp&quot;: datetime.now().isoformat()<br>            })<br>        else:<br>            print(&quot;✓ No critical/high/medium vulnerabilities detected\n&quot;)<br>    <br>    # Final Report<br>    report[&#39;end_time&#39;] = datetime.now().isoformat()<br>    report[&#39;status&#39;] = &#39;completed&#39;<br>    <br>    # Save report<br>    filename = f&quot;pentest_report_{SCOPE[&#39;target&#39;].replace(&#39;.&#39;, &#39;_&#39;)}_{datetime.now().strftime(&#39;%Y%m%d_%H%M%S&#39;)}.json&quot;<br>    with open(filename, &#39;w&#39;) as f:<br>        json.dump(report, f, indent=2)<br>    <br>    print(&quot;\n&quot; + &quot;=&quot;*70)<br>    print(&quot;PENETRATION TEST COMPLETE&quot;)<br>    print(&quot;=&quot;*70)<br>    print(f&quot;✓ Report saved: {filename}&quot;)<br>    print(f&quot;✓ Duration: {report[&#39;end_time&#39;]}&quot;)<br>    print(&quot;\nAI-powered penetration test completed successfully! 🎉&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    try:<br>        ai_guided_pentest()<br>    except KeyboardInterrupt:<br>        print(&quot;\n\n⚠️  Test interrupted by user&quot;)<br>    except Exception as e:<br>        print(f&quot;\n❌ Error: {e}&quot;)<br>        import traceback<br>        traceback.print_exc()</pre><p>Understanding the Script Flow:</p><p>1. Scope Validation: Checks target against defined in-scope/out-of-scope lists<br>2. AI Planning: LLM creates a custom testing strategy based on target type<br>3. Tool Execution: Runs reconnaissance tools (whatweb, subfinder, httpx)<br>4. Real-time Analysis: AI interprets results and identifies security findings<br>5. Adaptive Actions: Based on findings, AI recommends next testing phases<br>6. Vulnerability Scanning: Executes nuclei with AI-powered prioritization<br>7. Report Generation: Saves comprehensive JSON report with AI analysis</p><p>The script includes extensive safety controls , forbidden tools, rate <br>limiting, and authorization tracking, demonstrating production-ready <br>AI-assisted security automation.</p><p>Now, first run the Hexstrike:</p><pre>./start_Hexstrike.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMje7d3C6gTWMGbwy8wlDw.png" /></figure><p>Open another tab on your Kali and run the script we created earlier</p><pre>python3 ai_pentest_scoped.py </pre><p>You can rename the script whatever you want, and this is just a test/sample pentest script. You have open choices on how you want to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0n1Lm-5hiFiFXSjnCGA6sA.png" /></figure><p>Ollama/WSL screenshot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWh0tqxVGyaT3iAGjatpLQ.png" /></figure><h3>Common Issues &amp; Solutions:</h3><p>1. Ollama won’t start in WSL<br> → Try: ollama serve instead of systemctl</p><p>2. Can’t connect from Kali to Windows<br> → Verify: Windows Firewall rule is active<br> → Check: WSL IP hasn’t changed (reboot changes it)</p><p>3. Model download is slow<br> → This is normal — the 8B model is ~4.7GB</p><p>4. “Connection refused” errors<br> → Ensure: Port 11434 is open on both systems<br> → Verify: Port proxy is configured correctly</p><h3>Disclaimer</h3><p>This article is published for <strong>educational and research purposes only</strong>. All examples, targets, and configurations are intended for <strong>authorized testing environments</strong> such as labs, deliberately vulnerable applications, or systems you explicitly own or have permission to assess.</p><p>Do <strong>not</strong> use the techniques described here against systems without proper authorization. The author assumes no responsibility for misuse.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f30f32cb5af" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>