<?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 Jagadish Jasti on Medium]]></title>
        <description><![CDATA[Stories by Jagadish Jasti on Medium]]></description>
        <link>https://medium.com/@jastijagadishbabu?source=rss-7271a4380cc5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mbO8IVDd7XaMhFI4</url>
            <title>Stories by Jagadish Jasti on Medium</title>
            <link>https://medium.com/@jastijagadishbabu?source=rss-7271a4380cc5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:21:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jastijagadishbabu/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[Ditching Paid APIs: Building a Custom, Context-Aware AI Shell Assistant in Parrot OS using Google…]]></title>
            <link>https://medium.com/@jastijagadishbabu/ditching-paid-apis-building-a-custom-context-aware-ai-shell-assistant-in-parrot-os-using-google-97940ac2ce8b?source=rss-7271a4380cc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/97940ac2ce8b</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[parrotos]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Jagadish Jasti]]></dc:creator>
            <pubDate>Sun, 31 May 2026 16:30:25 GMT</pubDate>
            <atom:updated>2026-05-31T16:30:25.756Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ditching Paid APIs: Building a Custom, Context-Aware AI Shell Assistant in Parrot OS using Google GenAI</h3><h3>Executive Summary</h3><p>In modern penetration testing and security auditing, speed and command accuracy are paramount. Artificial intelligence has rapidly integrated into the command-line interface (CLI) via tools like ShellGPT (sgpt), helping operators instantly recall complex syntax for tools like Nmap, Gobuster, or Hydra. However, relying on commercial, paid API keys with strict rate limits introduces unnecessary friction into a security workflow.</p><p>This write-up details the architecture, implementation, and deployment of <strong>gemini_shell.py</strong>, a custom-built, interactive AI terminal assistant engineered natively within Parrot OS. Leveraging the newly released google-genai SDK and its robust free tier, this tool mirrors advanced offensive assistant capabilities—such as automated shell generation, code compilation, and session tracking—while fixing critical execution issues like terminal hanging and improper signal handling.</p><h3>The Architectural Problem: Shell Assistants &amp; The CLI Trap</h3><p>Standard command-line AI assistants operate on a basic request-response pattern: the user passes a prompt, the AI returns a command, and the script executes it. However, open-source utilities often suffer from two operational flaws:</p><ol><li><strong>Improper Signal Handling:</strong> When an AI-generated network command hangs or takes too long to execute, hitting Ctrl+C (KeyboardInterrupt) frequently kills the parent Python script entirely, dumping the operator out of the assistant environment and generating unsightly traceback errors.</li><li><strong>Lack of Granular Control:</strong> Standard implementations force a binary choice — either automatically execute the AI’s output or copy-paste it manually. A secure workflow requires a distinct validation gateway before code touches the kernel.</li></ol><h3>Environment Isolation on Parrot OS</h3><p>To protect the core dependencies of Parrot OS, the assistant is isolated inside a dedicated Python virtual environment. This keeps our automated pentesting scripts completely separate from system packages.</p><pre># Create a dedicated directory for custom AI tools<br>mkdir -p ~/ai_tools/chats<br><br># Initialize and activate the virtual environment<br>python3 -m venv ~/ai_tools/gemini_env<br>source ~/ai_tools/gemini_env/bin/activate<br><br># Install the official Google GenAI SDK<br>pip install google-genai</pre><h3>Key Engineering Enhancements</h3><h3>1. System Instruction Engineering</h3><p>By manipulating the GenerateContentConfig object, we strictly enforce output formats. When the --shell flag is toggled, the model acts as an API backend rather than a conversational bot, completely eliminating conversational text:</p><pre>sys_inst = &quot;You are a Linux terminal assistant. Output ONLY the raw, executable bash command. No markdown formatting, no backticks, and absolutely no explanations.&quot;</pre><h3>2. The KeyboardInterrupt Sandbox (The Python Shield)</h3><p>In native script execution, hitting Ctrl+C sends a SIGINT signal that bubbles to the top, breaking the runtime loop. By wrapping the execution context inside a targeted try/except block, we gracefully consume the exception:</p><pre>try:<br>    subprocess.run(command, shell=True)<br>except KeyboardInterrupt:<br>    print(&quot;\n[!] Process interrupted safely by operator (Ctrl+C). Returning to prompt.&quot;)</pre><p>This isolates the execution environment. If a heavy network tool freezes, the operator can safely kill it without losing the state or context of the active terminal session.</p><h3>Practical Demonstration &amp; Technical Walkthrough</h3><h3>1. Troubleshooting Nmap Syntax Traps</h3><p>To test the automation capabilities of the script, we ran an aggressive scan script against a target pool. The model initially generated a silent scan with an optimized verbosity parameter:</p><pre>nmap -iL victims.txt -A -v0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kL7A0Y4PWsxp1oI8fdc1cg.png" /></figure><p><strong>The Technical Analysis:</strong> The generated command utilized -v0 (Verbosity Level 0), forcing Nmap to suppress all real-time terminal output. Because an aggressive scan (-A) executes deep operating system fingerprinting and intense script engine checks, it runs in an instant. To an operator, this mirrors a no output.</p><p>By utilizing the interactive <strong>[Ch]ange</strong> option built directly into our gateway, we can modify the command on the fly to activate standard verbosity levels and prepend root authentication:</p><pre>sudo nmap -iL victims.txt -A -v</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4MlTO4ORkpfytVeOox9Jw.png" /></figure><h3>Reviewing Multi-Session Chat Data</h3><p>The custom logging system tracks individual operation sessions. By utilizing the --list and --show parameters, an auditor can instantly verify historical context or pull down past commands used during a continuous assessment.</p><pre># Lists all local JSON session profiles<br>gemini --list<br><br># Extracts and prints formatted transcript outputs directly into the console<br>gemini --chat internal_audit --show</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*5dxk9tk6mZlNazzwiONitw.png" /></figure><h3><strong>Defensive Engineering &amp; Remediation</strong></h3><p>While building utilities that speed up command generation enhances productivity, engineers must recognize the severe risks of running automated shell tools:</p><ul><li><strong>Command Injection Vulnerabilities:</strong> If an assistant accepts raw text files or external web variables and injects them blindly into subprocess.run(..., shell=True), an attacker could manipulate the inputs to execute arbitrary code with the system context of the operator.</li><li><strong>Mitigation Strategy:</strong> Never run an AI terminal assistant blindly or fully autonomously without a human validation gate. The implementation of the <strong>[E]xecute / [D]escribe / [Ch]ange</strong> terminal loop acts as an essential security control, ensuring that code is manually reviewed and edited before it passes into system execution.</li></ul><h3>Conclusion</h3><p>Building custom integrations with the google-genai SDK allows engineers to craft lightweight, resilient, and specialized tooling tailored directly to their preferred distributions. By handling raw Linux signals safely, isolating development dependencies via localized virtual environments, and strictly enforcing prompt constraints, gemini_shell.py proves that we can create robust alternatives to commercial command assistants while maximizing processing speed and maintaining complete structural control.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97940ac2ce8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>