A command-line tool that scans a source code file for security vulnerabilities using Google's Gemini API. Point it at a file, and it sends the code to Gemini 2.5 Flash with a security-review prompt, then prints the findings back to the terminal — sorted by severity and color-coded for quick scanning.
- AI-powered vulnerability analysis via the Gemini API (
gemini-2.5-flash) - Findings sorted by severity (Critical → High → Medium → Low)
- Color-coded terminal output per severity level (via
colorama) - Single-file, single-command usage — no config beyond an API key
- Works on any source file that can be read as text (not limited to Python)
- Language: Python
- AI model: Google Gemini (
gemini-2.5-flash) via thegoogle-genaiSDK - CLI/output:
coloramafor colored terminal text - Config:
python-dotenvfor loading the API key from a.envfile
.
├── scanner.py # Main CLI: reads a file, queries Gemini, prints sorted/colored findings
├── vulnerable.py # Sample file with intentionally vulnerable code, for testing the scanner
├── images/demo.png # Screenshot used in this README
└── .env # Local Gemini API key (not committed with a real key)
- Python 3.10+
- A Google Gemini API key (Google AI Studio)
git clone https://github.com/levibmackay/SecurityScanner.git
cd SecurityScannerMac/Linux:
python3 -m venv venv
source venv/bin/activateWindows:
python -m venv venv
venv\Scripts\activatepip install google-genai python-dotenv coloramaCreate a .env file in the project root:
GOOGLE_API_KEY=your_api_key_herescanner.py exits with an error if GOOGLE_API_KEY isn't set.
python scanner.py <path_to_file>Example, using the included sample file:
python scanner.py vulnerable.pySeverity: Critical
Vulnerability: SQL Injection
Why: User input is directly concatenated into a SQL query.
Impact: Attackers can execute arbitrary SQL commands.
Fix: Use parameterized queries.
--------------------------------------------------
Severity: High
Vulnerability: Command Injection
Why: User input is passed directly to a shell command via os.system.
Impact: Attackers may execute arbitrary shell commands.
Fix: Avoid shell execution; validate and sanitize input.
vulnerable.py is a deliberately insecure file for exercising the scanner. It contains:
- SQL injection (unsanitized string interpolation into a query)
- Command injection (
os.systemwith unsanitized input) - Weak password hashing (MD5)
- Hardcoded credentials and an API secret in source
- Reads the target file's contents as text.
- Fills a fixed security-review prompt with that code and sends it to Gemini 2.5 Flash.
- Splits the response into individual findings (separated by
---) and sorts them by severity, based on keyword matching in each block. - Prints each finding to the terminal, colored by severity (red for critical, light red for high, yellow for medium, green for low).
- Severity sorting and coloring rely on keyword matching against the response text, not structured output from the model — a finding whose
Why/Impacttext happens to mention a different severity word than its ownSeverity:line can be misclassified. - No error handling for a missing/unreadable input file path; an invalid path raises an unhandled exception instead of a clean error message.
- The security-review prompt and model name are hardcoded in
scanner.py; there is no way to point at a different model or customize the prompt without editing source. - No automated test suite.
Last updated: July 22, 2026
Last reviewed: 2026-07-20 19:33 MDT
Last updated: 2026-08-11 06:03 MDT
Maintained by Levi Mackay
