Interactive Chat Tutorial
Learn how to use Alprina’s conversational AI assistant for security scanning and vulnerability analysis.
What You’ll Learn
- Starting and using the chat interface
- Performing security scans conversationally
- Analyzing vulnerabilities with AI assistance
- Getting personalized mitigation strategies
- Best practices for productive conversations
Prerequisites
- Alprina CLI installed
- API key configured (Anthropic or OpenAI)
- Basic understanding of security concepts (helpful but not required)
Tutorial Steps
Step 1: Start Your First Chat
Open a terminal and start the chat interface:
alprina chatYou should see:
╭─────────────────────────────────────────────────────────────╮
│ Alprina AI Assistant │
│ │
│ Type your security questions or requests. │
│ Use /help for special commands. │
│ Press Ctrl+C or type /exit to quit. │
╰─────────────────────────────────────────────────────────────╯
You:Step 2: Ask Your First Question
Try asking a general security question:
You: What are the most common web vulnerabilities?Alprina will respond with a comprehensive answer about OWASP Top 10 and common attack vectors.
Step 3: Request a Security Scan
Now let’s scan some actual code. Ask Alprina to scan a directory:
You: Can you scan my web application in ./src for security issues?Alprina will:
- Understand your request
- Run the appropriate scan profile
- Analyze the results
- Present findings in a conversational format
Example response:
Alprina: I'll scan your web application directory...
✓ Scan completed!
I found 8 security issues in your application:
🔴 HIGH (2 findings):
- SQL Injection in user authentication (login.py:45)
- Hardcoded credentials in config (config.py:12)
🟡 MEDIUM (4 findings):
- Missing CSRF protection on forms
- Weak password requirements
- Unvalidated redirects
- Sensitive data in logs
🟢 LOW (2 findings):
- Missing security headers
- Verbose error messages
Would you like me to explain any of these findings in detail?Step 4: Deep Dive into Findings
Ask Alprina to explain a specific vulnerability:
You: Tell me more about the SQL injection issueAlprina provides detailed analysis:
Alprina: Let me explain the SQL injection vulnerability I found in login.py...
**Location:** login.py, line 45
**Code:**
```python
query = f"SELECT * FROM users WHERE username='{username}' AND password='{password}'"
cursor.execute(query)The Problem: This code constructs an SQL query using string formatting with user input. An attacker could input: username=’ OR ‘1’=‘1 to bypass authentication.
Example Attack:
Username: admin' --
Password: anythingThis would produce:
SELECT * FROM users WHERE username='admin' --' AND password='anything'The — comments out the password check, allowing login as admin.
Severity: HIGH This could allow complete database compromise.
Would you like me to show you how to fix this?
### Step 5: Get Mitigation Guidance
Request a fix:
You: Yes, show me how to fix it properly
Alprina provides step-by-step mitigation:
Alprina: Here’s how to fix the SQL injection vulnerability:
1. Use Parameterized Queries (Immediate Fix)
Replace the vulnerable code with:
query = "SELECT * FROM users WHERE username=? AND password=?"
cursor.execute(query, (username, password))2. Additional Security Measures
Add input validation:
import re
def validate_username(username):
if not re.match("^[a-zA-Z0-9_]{3,20}$", username):
raise ValueError("Invalid username format")
return username
# In your login function:
username = validate_username(request.form['username'])3. Use Password Hashing
Never store plain passwords:
import bcrypt
# During registration:
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
# During login:
if bcrypt.checkpw(password.encode(), stored_hash):
# Authentication successful4. Consider Using an ORM
For even better protection:
from sqlalchemy import create_engine, select
from models import User
user = session.query(User).filter_by(username=username).first()
if user and user.check_password(password):
# Authentication successfulWould you like me to generate a complete secure login function?
### Step 6: Use Special Commands
Explore special commands for efficiency:
You: /help
Alprina shows available commands:
Alprina: Available Commands:
/scan <target> - Run security scan /explain <id> - Explain specific finding /fix <id> - Get mitigation for finding /report - Generate security report /clear - Clear conversation history /stats - Show session statistics /save <path> - Save conversation /exit - Exit chat
You can also just talk to me naturally!
Try a direct scan command:
You: /scan https://api.example.com
### Step 7: Generate a Report
After your analysis, create a report:
You: Can you generate a security report with all findings?
Or use the command:
You: /report
Alprina will generate and save a comprehensive report.
### Step 8: Save Your Session
Save important conversations:
You: /save ~/Documents/security-review-2024-11-03.json
Alprina: ✓ Conversation saved to ~/Documents/security-review-2024-11-03.json
Session Summary:
- 24 messages exchanged
- 8 findings discussed
- 2 scans performed
- Duration: 18 minutes
## Advanced Techniques
### Load Previous Scan Results
Start chat with existing scan data:
```bash
# First, run a scan
alprina scan ./src --output scan-results.json
# Then load it in chat
alprina chat --load scan-results.jsonNow Alprina has full context:
You: What's the most critical issue?
Alprina: Based on the scan results I have loaded, the most critical
issue is the SQL injection vulnerability in login.py (HIGH-001).
This should be your top priority because...Chain Multiple Scans
Perform comparative analysis:
You: Scan my API endpoints at ./api
Alprina: [performs scan]
You: Now scan my authentication module in ./auth
Alprina: [performs second scan]
You: Which area has more security issues?
Alprina: Based on both scans:
API endpoints: 5 issues (1 HIGH, 3 MEDIUM, 1 LOW)
Auth module: 8 issues (2 HIGH, 4 MEDIUM, 2 LOW)
Your authentication module needs more attention...Ask for Learning Resources
You: Can you explain XSS attacks and recommend resources to learn more?
Alprina: [Provides explanation and curated learning resources]Request Code Examples
You: Show me examples of secure session management in Python Flask
Alprina: [Provides complete code examples with explanations]Best Practices
1. Be Specific
❌ Vague: “Check my code” ✅ Specific: “Scan my Python Flask API in ./src/api for authentication vulnerabilities”
2. Provide Context
❌ No context: “Fix this” ✅ With context: “I’m using Django 4.2. How do I fix the CSRF vulnerability in my forms?“
3. Ask Follow-up Questions
Build on previous responses:
You: Scan my code for SQL injection
Alprina: [finds issues]
You: Which one is most critical?
Alprina: [explains]
You: Show me how to fix that one first
Alprina: [provides solution]
You: Are there any testing tools I should use?
Alprina: [recommends tools]4. Use Commands for Speed
For repetitive tasks, use special commands:
/scan ./src
/explain HIGH-001
/fix HIGH-001
/report5. Save Important Sessions
Document your security reviews:
/save security-review-$(date +%Y-%m-%d).jsonCommon Patterns
Pattern 1: Discovery → Analysis → Remediation
1. You: Scan my application
2. [Review findings]
3. You: Explain the authentication issues
4. [Understand problem]
5. You: How do I fix them?
6. [Implement solutions]
7. You: Generate a reportPattern 2: Targeted Investigation
1. You: I'm worried about SQL injection. Check my database queries.
2. [Focused scan]
3. You: Show me every instance
4. [Detailed analysis]
5. You: Provide secure alternatives
6. [Implementation guidance]Pattern 3: Learning Session
1. You: What are OWASP Top 10 vulnerabilities?
2. You: Explain each one with examples
3. You: Scan my code for these issues
4. You: How do I prevent them in the future?Troubleshooting
Chat Not Starting
Issue: No API key found
Solution:
export ANTHROPIC_API_KEY=your_key_here
alprina chatSlow Responses
Try:
-
Use a faster model:
alprina chat --model claude-3-haiku-20240307 -
Disable streaming:
alprina chat --no-streaming
Context Not Loading
Issue: Previous scan results not available
Solution:
# Verify file exists
ls -la scan-results.json
# Load explicitly
alprina chat --load scan-results.jsonNext Steps
Now that you’ve mastered the chat interface:
- Practice regularly: Use chat for daily security reviews
- Explore commands: Try all special commands
- Read the guide: Security Scanning Guide
- Join community: Share tips on Discord
- Automate: Integrate with CI/CD pipelines
Real-World Examples
Example 1: New Project Security Review
You: I'm starting a new Django e-commerce project.
What security measures should I implement from day one?
Alprina: [Provides comprehensive security checklist]
You: Can you create a security policy file for my project?
Alprina: [Generates .alprina/policy.yaml with best practices]
You: Scan my initial code
Alprina: [Performs initial scan, provides baseline]Example 2: Pre-Deployment Check
You: I'm about to deploy to production.
Can you do a final security check on ./src?
Alprina: [Runs comprehensive scan]
You: Any blockers for production?
Alprina: [Identifies critical issues that must be fixed]
You: Help me fix the critical ones
Alprina: [Guides through fixes]
You: Rescan to confirm
Alprina: [Verifies fixes, gives go/no-go recommendation]Example 3: Incident Investigation
You: We detected unusual database activity.
Scan our query handlers in ./db
Alprina: [Identifies potential SQL injection]
You: Show me all places where this pattern appears
Alprina: [Lists all vulnerable locations]
You: Generate emergency patch instructions
Alprina: [Provides prioritized remediation steps]Summary
You’ve learned how to:
- ✅ Start and use the chat interface
- ✅ Perform security scans conversationally
- ✅ Analyze vulnerabilities in depth
- ✅ Get personalized mitigation guidance
- ✅ Use special commands effectively
- ✅ Save and load conversation context
- ✅ Apply best practices
Ready to dive deeper?
- CLI Reference - Complete command documentation
- Security Guide - Advanced scanning techniques
- API Reference - Programmatic access
- Examples - More real-world scenarios
Questions?
- Check our FAQ
- Visit Discord community
- Email support@alprina.ai