Skip to Content
Alprina is in active development. Join us in building the future of security scanning.
TutorialsTutorial: Your First Security Scan

Tutorial: Your First Security Scan

Time: 10 minutes
Level: Beginner

Learn how to run your first security scan with Alprina.

What You’ll Learn

  • Installing Alprina CLI
  • Running a security scan
  • Understanding scan results
  • Generating reports
  • Getting fix suggestions

Prerequisites

  • Python 3.8 or higher
  • pip package manager
  • A code project to scan

Step 1: Install Alprina

Open your terminal and install Alprina:

pip install alprina-cli

Verify the installation:

alprina --version

Step 2: Create Test Files

Let’s create some files to scan. Create a new directory:

mkdir alprina-demo cd alprina-demo

Create a vulnerable Python file:

app.py
# Vulnerable code example import os # 🚨 Hardcoded secret API_KEY = "sk-1234567890abcdef" def get_user(username): # 🚨 SQL injection vulnerability query = f"SELECT * FROM users WHERE name = '{username}'" return db.execute(query) # 🚨 Debug mode enabled DEBUG = True if __name__ == "__main__": app.run(debug=DEBUG)

Step 3: Run Your First Scan

Scan the file:

alprina scan app.py

You should see output like:

πŸ” Starting scan on: app.py ⚠ Found 3 issues ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Severity ┃ Type ┃ Description ┃ ┑━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩ β”‚ HIGH β”‚ Hardcoded Secretβ”‚ API key in source code β”‚ β”‚ HIGH β”‚ SQL Injection β”‚ Unsanitized user input β”‚ β”‚ MEDIUM β”‚ Debug Mode β”‚ Debug enabled β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Step 4: Generate a Report

Create a detailed HTML report:

alprina report --format html

The report will open automatically in your browser showing:

  • All vulnerabilities found
  • Severity ratings
  • Code locations
  • Fix recommendations

Step 5: Get Fix Suggestions

Get AI-powered mitigation advice:

alprina mitigate

Alprina will suggest fixes like:

πŸ› οΈ Mitigation Suggestions 1. Hardcoded Secret (HIGH) Location: app.py:5 Fix: Store secrets in environment variables # Instead of: API_KEY = "sk-1234567890abcdef" # Use: API_KEY = os.getenv("API_KEY") 2. SQL Injection (HIGH) Location: app.py:9 Fix: Use parameterized queries # Instead of: query = f"SELECT * FROM users WHERE name = '{username}'" # Use: query = "SELECT * FROM users WHERE name = ?" cursor.execute(query, (username,))

Step 6: Fix the Issues

Update your code based on the suggestions:

app.py
# Fixed code import os # βœ… Secret from environment API_KEY = os.getenv("API_KEY") def get_user(username): # βœ… Parameterized query query = "SELECT * FROM users WHERE name = ?" return db.execute(query, (username,)) # βœ… Debug from environment DEBUG = os.getenv("DEBUG", "False") == "True" if __name__ == "__main__": app.run(debug=DEBUG)

Step 7: Verify the Fixes

Run the scan again:

alprina scan app.py

You should now see:

πŸ” Starting scan on: app.py βœ… No issues found!

Congratulations!

You’ve successfully:

  • βœ… Installed Alprina
  • βœ… Run a security scan
  • βœ… Understood the results
  • βœ… Generated a report
  • βœ… Fixed vulnerabilities

Next Steps


πŸ›‘οΈ Build fast. Guard faster.

Last updated on