Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- README.md +52 -5
- app.py +17 -0
- bug_bounty_chatbot.py +438 -0
- model_config.py +105 -0
- requirements.txt +31 -0
README.md
CHANGED
|
@@ -1,12 +1,59 @@
|
|
| 1 |
---
|
| 2 |
-
title: Bug Bounty Chatbot
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Bug Bounty Security Chatbot
|
| 3 |
+
emoji: 🛡️
|
| 4 |
+
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.0.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: AI-powered bug bounty chatbot with CodeGemma 7B
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# 🛡️ Bug Bounty Security Chatbot
|
| 15 |
+
|
| 16 |
+
An AI-powered chatbot specialized in **network security** and **web application testing** for bug bounty hunters and security professionals.
|
| 17 |
+
|
| 18 |
+
**Powered by CodeGemma 7B LoRA fine-tuned model** for advanced security analysis and code generation.
|
| 19 |
+
|
| 20 |
+
## Features
|
| 21 |
+
|
| 22 |
+
- 🔍 **Reconnaissance Techniques**: Guidance on information gathering and target analysis
|
| 23 |
+
- 🌐 **Web Application Security**: OWASP Top 10 testing methodologies
|
| 24 |
+
- 🔗 **Network Security**: Port scanning, traffic analysis, and network testing
|
| 25 |
+
- ⚡ **Vulnerability Assessment**: Identification and exploitation techniques
|
| 26 |
+
- 🛠️ **Tool Recommendations**: Security tools and their usage
|
| 27 |
+
- 📚 **Educational Content**: Step-by-step security testing guides
|
| 28 |
+
- 🤖 **AI-Powered Analysis**: Advanced security insights using fine-tuned CodeGemma 7B
|
| 29 |
+
|
| 30 |
+
## Usage
|
| 31 |
+
|
| 32 |
+
Simply ask questions about:
|
| 33 |
+
- Security testing methodologies
|
| 34 |
+
- Vulnerability assessment techniques
|
| 35 |
+
- Tool recommendations
|
| 36 |
+
- Attack vectors and exploitation
|
| 37 |
+
- Bug bounty hunting strategies
|
| 38 |
+
|
| 39 |
+
## Examples
|
| 40 |
+
|
| 41 |
+
- "How to test for SQL injection vulnerabilities?"
|
| 42 |
+
- "What tools should I use for network reconnaissance?"
|
| 43 |
+
- "How to perform web application security testing?"
|
| 44 |
+
- "What are common authentication bypass techniques?"
|
| 45 |
+
|
| 46 |
+
## Disclaimer
|
| 47 |
+
|
| 48 |
+
⚠️ This tool is for **educational and authorized testing purposes only**. Always ensure you have proper authorization before testing any systems.
|
| 49 |
+
|
| 50 |
+
## Model Information
|
| 51 |
+
|
| 52 |
+
This chatbot can work with various fine-tuned models:
|
| 53 |
+
- DistilBERT models for classification tasks
|
| 54 |
+
- CodeGemma models for code analysis and generation
|
| 55 |
+
- Custom fine-tuned models for specific security domains
|
| 56 |
+
|
| 57 |
+
## Contributing
|
| 58 |
+
|
| 59 |
+
Feel free to contribute improvements, additional security methodologies, or new features!
|
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Bug Bounty Security Chatbot - Hugging Face Spaces Entry Point
|
| 3 |
+
Now with CodeGemma 7B LoRA model integration
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from bug_bounty_chatbot import create_chatbot_interface
|
| 7 |
+
|
| 8 |
+
# Create and launch the interface
|
| 9 |
+
interface = create_chatbot_interface()
|
| 10 |
+
|
| 11 |
+
if __name__ == "__main__":
|
| 12 |
+
interface.launch(
|
| 13 |
+
server_name="0.0.0.0",
|
| 14 |
+
server_port=7860,
|
| 15 |
+
share=False, # HF Spaces handles sharing
|
| 16 |
+
show_error=True
|
| 17 |
+
)
|
bug_bounty_chatbot.py
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ty Security Chatbot
|
| 4 |
+
Specialized in Network Security and Web Application Testing
|
| 5 |
+
Uses fine-tuned language models for security analysis and guidance
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import torch
|
| 10 |
+
from transformers import (
|
| 11 |
+
AutoTokenizer,
|
| 12 |
+
AutoModelForSequenceClassification,
|
| 13 |
+
AutoModelForCausalLM,
|
| 14 |
+
pipeline,
|
| 15 |
+
BitsAndBytesConfig
|
| 16 |
+
)
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import os
|
| 20 |
+
from typing import List, Dict, Optional, Tuple
|
| 21 |
+
import logging
|
| 22 |
+
|
| 23 |
+
# Configure logging
|
| 24 |
+
logging.basicConfig(level=logging.INFO)
|
| 25 |
+
logger = logging.getLogger(__name__)
|
| 26 |
+
|
| 27 |
+
class BugBountyChatbot:
|
| 28 |
+
def __init__(self, model_path: str = None, model_type: str = "classification"):
|
| 29 |
+
"""
|
| 30 |
+
Initialize the Bug Bounty Chatbot
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
model_path: Path to the fine-tuned model
|
| 34 |
+
model_type: Type of model ("classification" or "generation")
|
| 35 |
+
"""
|
| 36 |
+
self.model_path = model_path
|
| 37 |
+
self.model_type = model_type
|
| 38 |
+
self.tokenizer = None
|
| 39 |
+
self.model = None
|
| 40 |
+
self.pipeline = None
|
| 41 |
+
|
| 42 |
+
# Security testing categories and methodologies
|
| 43 |
+
self.security_categories = {
|
| 44 |
+
"web_app": [
|
| 45 |
+
"SQL Injection", "XSS (Cross-Site Scripting)", "CSRF (Cross-Site Request Forgery)",
|
| 46 |
+
"Authentication Bypass", "Authorization Flaws", "File Upload Vulnerabilities",
|
| 47 |
+
"Directory Traversal", "Server-Side Request Forgery (SSRF)", "XML External Entity (XXE)",
|
| 48 |
+
"Insecure Direct Object References", "Security Misconfiguration"
|
| 49 |
+
],
|
| 50 |
+
"network": [
|
| 51 |
+
"Port Scanning", "Service Enumeration", "Network Sniffing", "Man-in-the-Middle",
|
| 52 |
+
"DNS Spoofing", "ARP Poisoning", "Network Segmentation Bypass",
|
| 53 |
+
"Wireless Security Testing", "VPN Vulnerabilities", "Firewall Bypass"
|
| 54 |
+
],
|
| 55 |
+
"infrastructure": [
|
| 56 |
+
"Server Misconfiguration", "Default Credentials", "Privilege Escalation",
|
| 57 |
+
"Container Security", "Cloud Security", "API Security", "Database Security"
|
| 58 |
+
]
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
# Common tools and techniques
|
| 62 |
+
self.security_tools = {
|
| 63 |
+
"reconnaissance": ["nmap", "masscan", "sublist3r", "amass", "theHarvester"],
|
| 64 |
+
"web_testing": ["burp_suite", "owasp_zap", "sqlmap", "nikto", "dirb"],
|
| 65 |
+
"network_testing": ["wireshark", "tcpdump", "netcat", "metasploit", "nmap"],
|
| 66 |
+
"exploitation": ["metasploit", "exploit_db", "custom_scripts", "burp_suite"]
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
# Load model if path is provided
|
| 70 |
+
if model_path and os.path.exists(model_path):
|
| 71 |
+
self.load_model()
|
| 72 |
+
|
| 73 |
+
def load_model(self):
|
| 74 |
+
"""Load the fine-tuned model and tokenizer"""
|
| 75 |
+
try:
|
| 76 |
+
logger.info(f"Loading model from {self.model_path}")
|
| 77 |
+
|
| 78 |
+
if self.model_type == "classification":
|
| 79 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_path)
|
| 80 |
+
self.model = AutoModelForSequenceClassification.from_pretrained(
|
| 81 |
+
self.model_path,
|
| 82 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 83 |
+
)
|
| 84 |
+
self.pipeline = pipeline(
|
| 85 |
+
"text-classification",
|
| 86 |
+
model=self.model,
|
| 87 |
+
tokenizer=self.tokenizer,
|
| 88 |
+
device=0 if torch.cuda.is_available() else -1
|
| 89 |
+
)
|
| 90 |
+
else:
|
| 91 |
+
# For generation models (like CodeGemma)
|
| 92 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_path)
|
| 93 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
| 94 |
+
self.model_path,
|
| 95 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 96 |
+
device_map="auto" if torch.cuda.is_available() else None
|
| 97 |
+
)
|
| 98 |
+
self.pipeline = pipeline(
|
| 99 |
+
"text-generation",
|
| 100 |
+
model=self.model,
|
| 101 |
+
tokenizer=self.tokenizer,
|
| 102 |
+
device=0 if torch.cuda.is_available() else -1
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
logger.info("Model loaded successfully")
|
| 106 |
+
|
| 107 |
+
except Exception as e:
|
| 108 |
+
logger.error(f"Error loading model: {e}")
|
| 109 |
+
self.model = None
|
| 110 |
+
self.tokenizer = None
|
| 111 |
+
self.pipeline = None
|
| 112 |
+
|
| 113 |
+
def analyze_security_query(self, query: str) -> Dict:
|
| 114 |
+
"""
|
| 115 |
+
Analyze a security-related query and provide structured response
|
| 116 |
+
|
| 117 |
+
Args:
|
| 118 |
+
query: User's security question or request
|
| 119 |
+
|
| 120 |
+
Returns:
|
| 121 |
+
Dictionary with analysis results
|
| 122 |
+
"""
|
| 123 |
+
analysis = {
|
| 124 |
+
"category": "general",
|
| 125 |
+
"vulnerability_types": [],
|
| 126 |
+
"tools_suggested": [],
|
| 127 |
+
"methodology": [],
|
| 128 |
+
"risk_level": "medium",
|
| 129 |
+
"response": ""
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
query_lower = query.lower()
|
| 133 |
+
|
| 134 |
+
# Categorize the query
|
| 135 |
+
if any(term in query_lower for term in ["web", "website", "application", "app", "http", "https"]):
|
| 136 |
+
analysis["category"] = "web_app"
|
| 137 |
+
analysis["vulnerability_types"] = self.security_categories["web_app"]
|
| 138 |
+
analysis["tools_suggested"] = self.security_tools["web_testing"]
|
| 139 |
+
elif any(term in query_lower for term in ["network", "port", "scan", "tcp", "udp", "ip"]):
|
| 140 |
+
analysis["category"] = "network"
|
| 141 |
+
analysis["vulnerability_types"] = self.security_categories["network"]
|
| 142 |
+
analysis["tools_suggested"] = self.security_tools["network_testing"]
|
| 143 |
+
elif any(term in query_lower for term in ["server", "infrastructure", "cloud", "container"]):
|
| 144 |
+
analysis["category"] = "infrastructure"
|
| 145 |
+
analysis["vulnerability_types"] = self.security_categories["infrastructure"]
|
| 146 |
+
analysis["tools_suggested"] = self.security_tools["exploitation"]
|
| 147 |
+
|
| 148 |
+
# Determine risk level based on keywords
|
| 149 |
+
high_risk_terms = ["exploit", "bypass", "injection", "privilege", "escalation"]
|
| 150 |
+
if any(term in query_lower for term in high_risk_terms):
|
| 151 |
+
analysis["risk_level"] = "high"
|
| 152 |
+
|
| 153 |
+
return analysis
|
| 154 |
+
|
| 155 |
+
def generate_security_response(self, query: str, analysis: Dict) -> str:
|
| 156 |
+
"""
|
| 157 |
+
Generate a comprehensive security response based on analysis
|
| 158 |
+
|
| 159 |
+
Args:
|
| 160 |
+
query: Original user query
|
| 161 |
+
analysis: Analysis results from analyze_security_query
|
| 162 |
+
|
| 163 |
+
Returns:
|
| 164 |
+
Formatted response string
|
| 165 |
+
"""
|
| 166 |
+
response_parts = []
|
| 167 |
+
|
| 168 |
+
# Header with category and risk level
|
| 169 |
+
risk_emoji = {"low": "🟢", "medium": "🟡", "high": "🔴"}
|
| 170 |
+
response_parts.append(
|
| 171 |
+
f"## {risk_emoji.get(analysis['risk_level'], '🟡')} Security Analysis - {analysis['category'].title()}"
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
# Main response based on query type
|
| 175 |
+
if "how to" in query.lower() or "method" in query.lower():
|
| 176 |
+
response_parts.append("### Methodology:")
|
| 177 |
+
response_parts.append("1. **Reconnaissance Phase**")
|
| 178 |
+
response_parts.append(" - Gather information about the target")
|
| 179 |
+
response_parts.append(" - Identify attack surface")
|
| 180 |
+
response_parts.append(" - Map network topology")
|
| 181 |
+
|
| 182 |
+
response_parts.append("\n2. **Scanning Phase**")
|
| 183 |
+
response_parts.append(" - Port scanning and service enumeration")
|
| 184 |
+
response_parts.append(" - Vulnerability scanning")
|
| 185 |
+
response_parts.append(" - Web application scanning")
|
| 186 |
+
|
| 187 |
+
response_parts.append("\n3. **Exploitation Phase**")
|
| 188 |
+
response_parts.append(" - Attempt to exploit identified vulnerabilities")
|
| 189 |
+
response_parts.append(" - Document findings")
|
| 190 |
+
response_parts.append(" - Maintain access if required")
|
| 191 |
+
|
| 192 |
+
elif "tool" in query.lower() or "scan" in query.lower():
|
| 193 |
+
response_parts.append("### Recommended Tools:")
|
| 194 |
+
for tool in analysis["tools_suggested"][:5]: # Limit to top 5
|
| 195 |
+
response_parts.append(f"- **{tool.replace('_', ' ').title()}**")
|
| 196 |
+
|
| 197 |
+
elif "vulnerability" in query.lower() or "exploit" in query.lower():
|
| 198 |
+
response_parts.append("### Common Vulnerabilities:")
|
| 199 |
+
for vuln in analysis["vulnerability_types"][:5]: # Limit to top 5
|
| 200 |
+
response_parts.append(f"- {vuln}")
|
| 201 |
+
|
| 202 |
+
else:
|
| 203 |
+
# General security guidance
|
| 204 |
+
response_parts.append("### Security Guidance:")
|
| 205 |
+
response_parts.append("Based on your query, here are key security considerations:")
|
| 206 |
+
|
| 207 |
+
if analysis["category"] == "web_app":
|
| 208 |
+
response_parts.append("- Focus on OWASP Top 10 vulnerabilities")
|
| 209 |
+
response_parts.append("- Test authentication and authorization mechanisms")
|
| 210 |
+
response_parts.append("- Validate all input parameters")
|
| 211 |
+
response_parts.append("- Check for insecure direct object references")
|
| 212 |
+
|
| 213 |
+
elif analysis["category"] == "network":
|
| 214 |
+
response_parts.append("- Perform comprehensive port scanning")
|
| 215 |
+
response_parts.append("- Analyze network traffic patterns")
|
| 216 |
+
response_parts.append("- Test network segmentation")
|
| 217 |
+
response_parts.append("- Verify firewall rules and configurations")
|
| 218 |
+
|
| 219 |
+
elif analysis["category"] == "infrastructure":
|
| 220 |
+
response_parts.append("- Review server configurations")
|
| 221 |
+
response_parts.append("- Check for default credentials")
|
| 222 |
+
response_parts.append("- Analyze privilege levels")
|
| 223 |
+
response_parts.append("- Test container and cloud security")
|
| 224 |
+
|
| 225 |
+
# Add model-based response if available
|
| 226 |
+
if self.pipeline and self.model_type == "generation":
|
| 227 |
+
try:
|
| 228 |
+
# Create a prompt for the model
|
| 229 |
+
prompt = f"""<|system|>
|
| 230 |
+
You are a cybersecurity expert specializing in bug bounty hunting and penetration testing.
|
| 231 |
+
Provide detailed, actionable security guidance.
|
| 232 |
+
<|user|>
|
| 233 |
+
{query}
|
| 234 |
+
<|assistant|>"""
|
| 235 |
+
|
| 236 |
+
model_response = self.pipeline(
|
| 237 |
+
prompt,
|
| 238 |
+
max_length=512,
|
| 239 |
+
num_return_sequences=1,
|
| 240 |
+
temperature=0.7,
|
| 241 |
+
do_sample=True,
|
| 242 |
+
pad_token_id=self.tokenizer.eos_token_id
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
if model_response and len(model_response) > 0:
|
| 246 |
+
generated_text = model_response[0]['generated_text']
|
| 247 |
+
# Extract only the assistant's response
|
| 248 |
+
if "<|assistant|>" in generated_text:
|
| 249 |
+
assistant_response = generated_text.split("<|assistant|>")[-1].strip()
|
| 250 |
+
response_parts.append(f"\n### AI-Generated Insights:\n{assistant_response}")
|
| 251 |
+
|
| 252 |
+
except Exception as e:
|
| 253 |
+
logger.error(f"Error generating model response: {e}")
|
| 254 |
+
|
| 255 |
+
# Add disclaimer
|
| 256 |
+
response_parts.append("\n---")
|
| 257 |
+
response_parts.append("⚠️ **Disclaimer**: This information is for educational and authorized testing purposes only.")
|
| 258 |
+
response_parts.append("Always ensure you have proper authorization before testing any systems.")
|
| 259 |
+
|
| 260 |
+
return "\n".join(response_parts)
|
| 261 |
+
|
| 262 |
+
def chat(self, message: str, history: List[List[str]]) -> Tuple[str, List[List[str]]]:
|
| 263 |
+
"""
|
| 264 |
+
Main chat function for Gradio interface
|
| 265 |
+
|
| 266 |
+
Args:
|
| 267 |
+
message: User's message
|
| 268 |
+
history: Chat history
|
| 269 |
+
|
| 270 |
+
Returns:
|
| 271 |
+
Tuple of (response, updated_history)
|
| 272 |
+
"""
|
| 273 |
+
if not message.strip():
|
| 274 |
+
return "Please enter a security-related question or request.", history
|
| 275 |
+
|
| 276 |
+
# Analyze the query
|
| 277 |
+
analysis = self.analyze_security_query(message)
|
| 278 |
+
|
| 279 |
+
# Generate response
|
| 280 |
+
response = self.generate_security_response(message, analysis)
|
| 281 |
+
|
| 282 |
+
# Update history
|
| 283 |
+
history.append([message, response])
|
| 284 |
+
|
| 285 |
+
return "", history
|
| 286 |
+
|
| 287 |
+
def create_chatbot_interface():
|
| 288 |
+
"""Create and configure the Gradio interface"""
|
| 289 |
+
|
| 290 |
+
# Initialize chatbot with CodeGemma 7B model from Hugging Face Hub
|
| 291 |
+
chatbot = BugBountyChatbot(
|
| 292 |
+
model_path="BenjaminKaindu0506/codegemma-7b-bugbounty",
|
| 293 |
+
model_type="generation",
|
| 294 |
+
base_model="unsloth/codegemma-7b"
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
# Custom CSS for better styling
|
| 298 |
+
css = """
|
| 299 |
+
.gradio-container {
|
| 300 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 301 |
+
}
|
| 302 |
+
.chat-message {
|
| 303 |
+
padding: 10px;
|
| 304 |
+
margin: 5px 0;
|
| 305 |
+
border-radius: 10px;
|
| 306 |
+
}
|
| 307 |
+
.user-message {
|
| 308 |
+
background-color: #e3f2fd;
|
| 309 |
+
margin-left: 20%;
|
| 310 |
+
}
|
| 311 |
+
.bot-message {
|
| 312 |
+
background-color: #f5f5f5;
|
| 313 |
+
margin-right: 20%;
|
| 314 |
+
}
|
| 315 |
+
"""
|
| 316 |
+
|
| 317 |
+
# Create Gradio interface
|
| 318 |
+
with gr.Blocks(css=css, title="Bug Bounty Security Chatbot") as interface:
|
| 319 |
+
gr.Markdown("""
|
| 320 |
+
# 🛡️ Bug Bounty Security Chatbot
|
| 321 |
+
|
| 322 |
+
**Specialized in Network Security and Web Application Testing**
|
| 323 |
+
|
| 324 |
+
This AI-powered chatbot provides expert guidance on:
|
| 325 |
+
- 🔍 **Reconnaissance techniques**
|
| 326 |
+
- 🌐 **Web application security testing**
|
| 327 |
+
- 🔗 **Network security analysis**
|
| 328 |
+
- ⚡ **Vulnerability assessment**
|
| 329 |
+
- 🛠️ **Security tool recommendations**
|
| 330 |
+
|
| 331 |
+
Ask me about security testing methodologies, tools, vulnerabilities, or specific attack techniques!
|
| 332 |
+
""")
|
| 333 |
+
|
| 334 |
+
with gr.Row():
|
| 335 |
+
with gr.Column(scale=3):
|
| 336 |
+
chatbot_interface = gr.Chatbot(
|
| 337 |
+
label="Security Chat",
|
| 338 |
+
height=600,
|
| 339 |
+
show_label=True,
|
| 340 |
+
container=True,
|
| 341 |
+
bubble_full_width=False
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
with gr.Row():
|
| 345 |
+
msg_input = gr.Textbox(
|
| 346 |
+
placeholder="Ask about security testing, vulnerabilities, tools, or methodologies...",
|
| 347 |
+
label="Your Security Question",
|
| 348 |
+
lines=2,
|
| 349 |
+
scale=4
|
| 350 |
+
)
|
| 351 |
+
send_btn = gr.Button("Send", variant="primary", scale=1)
|
| 352 |
+
|
| 353 |
+
with gr.Row():
|
| 354 |
+
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
| 355 |
+
example_btn = gr.Button("Load Examples", variant="secondary")
|
| 356 |
+
|
| 357 |
+
with gr.Column(scale=1):
|
| 358 |
+
gr.Markdown("### 🎯 Quick Examples")
|
| 359 |
+
|
| 360 |
+
examples = [
|
| 361 |
+
"How to test for SQL injection vulnerabilities?",
|
| 362 |
+
"What tools should I use for network reconnaissance?",
|
| 363 |
+
"How to perform web application security testing?",
|
| 364 |
+
"What are common authentication bypass techniques?",
|
| 365 |
+
"How to scan for open ports and services?",
|
| 366 |
+
"What is the OWASP Top 10 and how to test for them?",
|
| 367 |
+
"How to perform privilege escalation testing?",
|
| 368 |
+
"What are the steps for a complete penetration test?"
|
| 369 |
+
]
|
| 370 |
+
|
| 371 |
+
example_buttons = []
|
| 372 |
+
for example in examples:
|
| 373 |
+
btn = gr.Button(example, size="sm", variant="outline")
|
| 374 |
+
example_buttons.append(btn)
|
| 375 |
+
|
| 376 |
+
gr.Markdown("### 🔧 Security Categories")
|
| 377 |
+
gr.Markdown("""
|
| 378 |
+
- **Web Applications**: XSS, SQLi, CSRF, Auth bypass
|
| 379 |
+
- **Network Security**: Port scanning, traffic analysis
|
| 380 |
+
- **Infrastructure**: Server configs, privilege escalation
|
| 381 |
+
- **Cloud Security**: Container security, API testing
|
| 382 |
+
""")
|
| 383 |
+
|
| 384 |
+
# Event handlers
|
| 385 |
+
def user_input(message, history):
|
| 386 |
+
return chatbot.chat(message, history)
|
| 387 |
+
|
| 388 |
+
def load_examples():
|
| 389 |
+
return examples
|
| 390 |
+
|
| 391 |
+
# Connect events
|
| 392 |
+
send_btn.click(
|
| 393 |
+
user_input,
|
| 394 |
+
inputs=[msg_input, chatbot_interface],
|
| 395 |
+
outputs=[msg_input, chatbot_interface]
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
msg_input.submit(
|
| 399 |
+
user_input,
|
| 400 |
+
inputs=[msg_input, chatbot_interface],
|
| 401 |
+
outputs=[msg_input, chatbot_interface]
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
clear_btn.click(
|
| 405 |
+
lambda: ([], ""),
|
| 406 |
+
outputs=[chatbot_interface, msg_input]
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
# Example button clicks
|
| 410 |
+
for i, btn in enumerate(example_buttons):
|
| 411 |
+
btn.click(
|
| 412 |
+
lambda x=examples[i]: (x, ""),
|
| 413 |
+
outputs=[msg_input, chatbot_interface]
|
| 414 |
+
).then(
|
| 415 |
+
user_input,
|
| 416 |
+
inputs=[msg_input, chatbot_interface],
|
| 417 |
+
outputs=[msg_input, chatbot_interface]
|
| 418 |
+
)
|
| 419 |
+
|
| 420 |
+
return interface
|
| 421 |
+
|
| 422 |
+
def main():
|
| 423 |
+
"""Main function to run the chatbot"""
|
| 424 |
+
print("🛡️ Initializing Bug Bounty Security Chatbot...")
|
| 425 |
+
|
| 426 |
+
# Create and launch the interface
|
| 427 |
+
interface = create_chatbot_interface()
|
| 428 |
+
|
| 429 |
+
print("🚀 Starting chatbot interface...")
|
| 430 |
+
interface.launch(
|
| 431 |
+
server_name="0.0.0.0",
|
| 432 |
+
server_port=7860,
|
| 433 |
+
share=True, # Enable public sharing for Hugging Face Spaces
|
| 434 |
+
show_error=True
|
| 435 |
+
)
|
| 436 |
+
|
| 437 |
+
if __name__ == "__main__":
|
| 438 |
+
main()
|
model_config.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Model Configuration for Bug Bounty Chatbot
|
| 3 |
+
This file contains configuration settings for different model types and sizes
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from typing import Dict, Any
|
| 8 |
+
|
| 9 |
+
# Model configurations
|
| 10 |
+
MODEL_CONFIGS = {
|
| 11 |
+
"distilbert_classification": {
|
| 12 |
+
"model_type": "classification",
|
| 13 |
+
"max_length": 512,
|
| 14 |
+
"batch_size": 16,
|
| 15 |
+
"device": "auto",
|
| 16 |
+
"description": "Fine-tuned DistilBERT for security classification tasks"
|
| 17 |
+
},
|
| 18 |
+
"codegemma_2b": {
|
| 19 |
+
"model_type": "generation",
|
| 20 |
+
"max_length": 2048,
|
| 21 |
+
"batch_size": 8,
|
| 22 |
+
"device": "auto",
|
| 23 |
+
"description": "CodeGemma 2B fine-tuned for security code analysis"
|
| 24 |
+
},
|
| 25 |
+
"codegemma_7b": {
|
| 26 |
+
"model_type": "generation",
|
| 27 |
+
"max_length": 4096,
|
| 28 |
+
"batch_size": 4,
|
| 29 |
+
"device": "gpu", # Requires GPU for 7B model
|
| 30 |
+
"description": "CodeGemma 7B fine-tuned for advanced security analysis"
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
# Default model paths (update these with your actual model paths)
|
| 35 |
+
DEFAULT_MODEL_PATHS = {
|
| 36 |
+
"distilbert": "/Users/macbook/Downloads/finetuned_model",
|
| 37 |
+
"distilbert_2": "/Users/macbook/Downloads/finetuned_model 2",
|
| 38 |
+
"codegemma_2b": None, # Update when you have CodeGemma models
|
| 39 |
+
"codegemma_7b": None # Update when you have CodeGemma models
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
# Security testing prompts and templates
|
| 43 |
+
SECURITY_PROMPTS = {
|
| 44 |
+
"vulnerability_analysis": """
|
| 45 |
+
<|system|>
|
| 46 |
+
You are a cybersecurity expert specializing in bug bounty hunting and penetration testing.
|
| 47 |
+
Analyze the following security scenario and provide detailed guidance.
|
| 48 |
+
<|user|>
|
| 49 |
+
{query}
|
| 50 |
+
<|assistant|>
|
| 51 |
+
""",
|
| 52 |
+
|
| 53 |
+
"code_review": """
|
| 54 |
+
<|system|>
|
| 55 |
+
You are a security code reviewer. Analyze the following code for security vulnerabilities.
|
| 56 |
+
<|user|>
|
| 57 |
+
Review this code for security issues:
|
| 58 |
+
{code}
|
| 59 |
+
<|assistant|>
|
| 60 |
+
""",
|
| 61 |
+
|
| 62 |
+
"methodology": """
|
| 63 |
+
<|system|>
|
| 64 |
+
You are a penetration testing methodology expert. Provide step-by-step guidance for security testing.
|
| 65 |
+
<|user|>
|
| 66 |
+
{query}
|
| 67 |
+
<|assistant|>
|
| 68 |
+
"""
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
# Security categories and their associated keywords
|
| 72 |
+
SECURITY_KEYWORDS = {
|
| 73 |
+
"web_app": [
|
| 74 |
+
"sql injection", "xss", "csrf", "authentication", "authorization",
|
| 75 |
+
"file upload", "directory traversal", "ssrf", "xxe", "idor"
|
| 76 |
+
],
|
| 77 |
+
"network": [
|
| 78 |
+
"port scan", "network", "tcp", "udp", "sniffing", "mitm",
|
| 79 |
+
"dns", "arp", "wireless", "vpn", "firewall"
|
| 80 |
+
],
|
| 81 |
+
"infrastructure": [
|
| 82 |
+
"server", "privilege escalation", "container", "cloud", "api",
|
| 83 |
+
"database", "misconfiguration", "default credentials"
|
| 84 |
+
]
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
def get_model_config(model_name: str) -> Dict[str, Any]:
|
| 88 |
+
"""Get configuration for a specific model"""
|
| 89 |
+
return MODEL_CONFIGS.get(model_name, MODEL_CONFIGS["distilbert_classification"])
|
| 90 |
+
|
| 91 |
+
def get_model_path(model_name: str) -> str:
|
| 92 |
+
"""Get the path for a specific model"""
|
| 93 |
+
return DEFAULT_MODEL_PATHS.get(model_name, "")
|
| 94 |
+
|
| 95 |
+
def validate_model_path(model_path: str) -> bool:
|
| 96 |
+
"""Validate if model path exists and contains required files"""
|
| 97 |
+
if not model_path or not os.path.exists(model_path):
|
| 98 |
+
return False
|
| 99 |
+
|
| 100 |
+
required_files = ["config.json", "tokenizer.json"]
|
| 101 |
+
for file in required_files:
|
| 102 |
+
if not os.path.exists(os.path.join(model_path, file)):
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
return True
|
requirements.txt
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Bug Bounty Security Chatbot Dependencies
|
| 2 |
+
# Core ML and NLP libraries
|
| 3 |
+
torch>=2.0.0
|
| 4 |
+
transformers>=4.30.0
|
| 5 |
+
tokenizers>=0.13.0
|
| 6 |
+
accelerate>=0.20.0
|
| 7 |
+
bitsandbytes>=0.39.0
|
| 8 |
+
|
| 9 |
+
# UI and Web Framework
|
| 10 |
+
gradio>=4.0.0
|
| 11 |
+
|
| 12 |
+
# Data processing and utilities
|
| 13 |
+
numpy>=1.24.0
|
| 14 |
+
pandas>=2.0.0
|
| 15 |
+
scikit-learn>=1.3.0
|
| 16 |
+
|
| 17 |
+
# Security and networking utilities
|
| 18 |
+
requests>=2.31.0
|
| 19 |
+
urllib3>=2.0.0
|
| 20 |
+
|
| 21 |
+
# Optional: For model quantization and optimization
|
| 22 |
+
# peft>=0.4.0 # Parameter Efficient Fine-Tuning
|
| 23 |
+
# datasets>=2.14.0 # For dataset handling
|
| 24 |
+
|
| 25 |
+
# Development and debugging
|
| 26 |
+
tqdm>=4.65.0
|
| 27 |
+
logging>=0.4.9.6
|
| 28 |
+
|
| 29 |
+
# For Hugging Face Spaces deployment
|
| 30 |
+
huggingface_hub>=0.16.0
|
| 31 |
+
safetensors>=0.3.0
|