HimanshuGoyal2004 commited on
Commit
af59553
Β·
1 Parent(s): 380d02f

hf_token taken as input now, cleaner ui

Browse files
Files changed (2) hide show
  1. README.md +80 -8
  2. app.py +62 -22
README.md CHANGED
@@ -12,16 +12,88 @@ license: mit
12
 
13
  # πŸ›‘οΈ AI-Powered GitHub Vulnerability Scanner
14
 
15
- An intelligent security analysis tool that scans GitHub repositories for vulnerabilities using AI agents and Model Context Protocol (MCP) integration. This tool provides comprehensive security assessments with detailed reports and remediation guidance.
16
 
17
- ## ✨ Features
18
 
19
- - **πŸ€– AI-Powered Analysis**: Uses advanced AI agents to intelligently analyze code patterns
20
- - **πŸ” Comprehensive Scanning**: Detects multiple vulnerability types across various programming languages
21
- - **πŸ“Š Detailed Reports**: Generates professional security reports with severity ratings
22
- - **🌐 Web Interface**: Easy-to-use Gradio interface for repository analysis
 
 
23
  - **πŸ”— GitHub Integration**: Direct integration with GitHub repositories via MCP tools
24
 
25
- ## ⚠️ Disclaimer
26
 
27
- This tool is for educational and security research purposes. Always ensure you have proper authorization before scanning repositories. The results should be used as a starting point for security analysis, not as a definitive security assessment.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # πŸ›‘οΈ AI-Powered GitHub Vulnerability Scanner
14
 
15
+ An advanced security analysis tool that leverages cutting-edge AI agents and Model Context Protocol (MCP) tools to perform comprehensive security analysis of GitHub repositories and individual files. This intelligent scanner provides detailed vulnerability assessments with actionable remediation guidance.
16
 
17
+ ## ✨ Key Features
18
 
19
+ - **πŸ€– AI-Powered Detection**: Uses advanced language models to understand code context and identify complex security issues
20
+ - **οΏ½ Dumal Analysis Mode**: Analyze entire repositories or focus on specific files
21
+ - **οΏ½ Deeap Code Analysis**: Scans for common security vulnerabilities including SQL injection, XSS, command injection, and more
22
+ - **πŸ“Š Comprehensive Reports**: Generates detailed security reports with severity levels, line numbers, and remediation suggestions
23
+ - **🌐 Modern Web Interface**: Enhanced Gradio interface with improved user experience
24
+ - **πŸ”‘ Secure API Integration**: User-provided Hugging Face tokens for secure AI model access
25
  - **πŸ”— GitHub Integration**: Direct integration with GitHub repositories via MCP tools
26
 
27
+ ## 🎯 Vulnerability Detection Capabilities
28
 
29
+ The scanner identifies various security vulnerabilities including:
30
+
31
+ - **Command Injection** - OS command execution flaws (os.system, exec, eval)
32
+ - **Input Validation Issues** - Unvalidated user inputs and missing parameter checks
33
+ - **Error Handling Flaws** - Unhandled exceptions and information disclosure
34
+ - **Hardcoded Secrets** - API keys, passwords, database credentials
35
+ - **Unsafe Operations** - File operations and deserialization without validation
36
+ - **SQL Injection** - Database query vulnerabilities
37
+ - **Cross-Site Scripting (XSS)** - Web application security issues
38
+ - **Path Traversal** - File system access vulnerabilities
39
+
40
+ ## πŸš€ Getting Started
41
+
42
+ ### Prerequisites
43
+
44
+ - Python 3.11+
45
+ - Hugging Face API Token (free account required)
46
+
47
+ ### Usage
48
+
49
+ 1. **Get a Hugging Face API Key**:
50
+ - Visit [Hugging Face Settings](https://huggingface.co/settings/tokens)
51
+ - Create a free account if needed
52
+ - Generate a new API token
53
+
54
+ 2. **Configure the Scanner**:
55
+ - Enter your Hugging Face API key in the provided field
56
+ - The key is used securely and never stored
57
+
58
+ 3. **Start Analysis**:
59
+ - Paste a GitHub repository URL or specific file URL in the chat interface
60
+ - Wait for the AI agent to analyze and generate a security report
61
+
62
+
63
+ ## πŸ› οΈ Technical Architecture
64
+
65
+ - **Frontend**: Enhanced Gradio web interface with modern theming
66
+ - **AI Engine**: Hugging Face Inference API with smolagents framework
67
+ - **GitHub Integration**: Custom MCP server for GitHub API access
68
+ - **URL Parsing**: Smart GitHub URL parser supporting both repositories and individual files
69
+ - **Analysis Engine**: Context-aware vulnerability detection with line-by-line analysis
70
+ - **Report Generation**: Structured security assessment with severity classification
71
+
72
+
73
+ ## πŸ“‹ Dependencies
74
+
75
+ - `gradio[oauth,mcp]` - Web interface framework with MCP support
76
+ - `smolagents` - AI agent framework for intelligent code analysis
77
+ - `requests` - HTTP client library
78
+ - `fastapi` & `uvicorn` - API framework and server
79
+ - `mcp` - Model Context Protocol client
80
+ - `pydantic` - Data validation
81
+
82
+ ## πŸ”’ Security & Privacy
83
+
84
+ - **API Key Security**: Your Hugging Face tokens are used securely and never stored
85
+ - **Public Repository Access**: Analyzes only publicly accessible GitHub repositories
86
+ - **Responsible Use**: Designed for legitimate security research and vulnerability assessment
87
+ - **No Data Storage**: Analysis results are not stored or logged
88
+
89
+ ## ⚠️ Important Disclaimer
90
+
91
+ This tool is designed for legitimate security research and vulnerability assessment purposes only.
92
+
93
+ **Do NOT use this scanner for:**
94
+ - Malicious activities
95
+ - Unauthorized access attempts
96
+ - Any illegal purposes
97
+ - Scanning repositories without proper authorization
98
+
99
+ Always ensure you have proper authorization before scanning repositories that don't belong to you. The results should be used as a starting point for security analysis, not as a definitive security assessment.
app.py CHANGED
@@ -1,10 +1,5 @@
1
  import gradio as gr
2
- import os
3
  from smolagents import InferenceClientModel, CodeAgent, MCPClient
4
- from dotenv import load_dotenv
5
-
6
- # Load environment variables
7
- load_dotenv()
8
 
9
  # MCP Server URL for GitHub tools
10
  MCP_SERVER_URL = "https://himanshugoyal2004-github-mcp-server.hf.space/gradio_api/mcp/"
@@ -27,17 +22,24 @@ def parse_github_url(url):
27
 
28
  return None, None, None
29
 
30
- def analyze_vulnerabilities(message, history):
 
31
  """Analyze GitHub repository or specific file for vulnerabilities using AI agent"""
 
 
 
 
 
32
  try:
 
33
  mcp_client = MCPClient({
34
  "url": MCP_SERVER_URL,
35
  "timeout": 120
36
  })
37
  tools = mcp_client.get_tools()
38
 
39
- # Initialize AI model
40
- model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
41
 
42
  # Create AI agent with GitHub MCP tools
43
  agent = CodeAgent(
@@ -55,7 +57,6 @@ def analyze_vulnerabilities(message, history):
55
 
56
  # Generate different prompts based on whether it's a file or repository
57
  if file_path:
58
- # Single file analysis
59
  enhanced_prompt = f"""
60
  You are a cybersecurity expert. Analyze the specific GitHub file for security vulnerabilities.
61
 
@@ -82,7 +83,6 @@ Please:
82
  Use simple string operations and avoid complex regex patterns. Focus on clear, actionable security findings.
83
  """
84
  else:
85
- # Full repository analysis
86
  enhanced_prompt = f"""
87
  You are a cybersecurity expert. Analyze the GitHub repository for security vulnerabilities.
88
 
@@ -117,18 +117,58 @@ Use simple string operations and focus on the most critical security issues. Lim
117
  return str(result)
118
 
119
  except Exception as e:
120
- return f"❌ Error analyzing repository: {str(e)}\n\nPlease ensure:\nβ€’ Valid GitHub repository URL\nβ€’ HF_TOKEN environment variable is set\nβ€’ Repository is accessible"
121
-
122
- # Create Gradio interface
123
- demo = gr.ChatInterface(
124
- fn=analyze_vulnerabilities,
125
- type="messages",
126
- examples=[
127
- "https://github.com/banno-0720/documentation-agent/blob/main/code.py"
128
- ],
129
- title="πŸ›‘οΈ AI-Powered GitHub Vulnerability Scanner",
130
- description="Paste a GitHub repository URL to scan the entire repo, or paste a specific file URL to analyze just that file for security vulnerabilities using AI agents with MCP tools. The AI will intelligently analyze code and provide detailed security reports.",
131
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  if __name__ == "__main__":
134
  demo.launch()
 
1
  import gradio as gr
 
2
  from smolagents import InferenceClientModel, CodeAgent, MCPClient
 
 
 
 
3
 
4
  # MCP Server URL for GitHub tools
5
  MCP_SERVER_URL = "https://himanshugoyal2004-github-mcp-server.hf.space/gradio_api/mcp/"
 
22
 
23
  return None, None, None
24
 
25
+
26
+ def analyze_vulnerabilities(message, history, hf_token):
27
  """Analyze GitHub repository or specific file for vulnerabilities using AI agent"""
28
+
29
+ # Validate HF token input
30
+ if not hf_token.strip():
31
+ return "❌ Please provide a Hugging Face API key. Get one from [Hugging Face](https://huggingface.co/settings/tokens)"
32
+
33
  try:
34
+ # Connect to MCP server
35
  mcp_client = MCPClient({
36
  "url": MCP_SERVER_URL,
37
  "timeout": 120
38
  })
39
  tools = mcp_client.get_tools()
40
 
41
+ # Initialize AI model with user's token
42
+ model = InferenceClientModel(token=hf_token.strip())
43
 
44
  # Create AI agent with GitHub MCP tools
45
  agent = CodeAgent(
 
57
 
58
  # Generate different prompts based on whether it's a file or repository
59
  if file_path:
 
60
  enhanced_prompt = f"""
61
  You are a cybersecurity expert. Analyze the specific GitHub file for security vulnerabilities.
62
 
 
83
  Use simple string operations and avoid complex regex patterns. Focus on clear, actionable security findings.
84
  """
85
  else:
 
86
  enhanced_prompt = f"""
87
  You are a cybersecurity expert. Analyze the GitHub repository for security vulnerabilities.
88
 
 
117
  return str(result)
118
 
119
  except Exception as e:
120
+ return f"❌ Error analyzing repository: {str(e)}\n\nPlease ensure:\nβ€’ Valid GitHub repository URL\nβ€’ Hugging Face token is correct\nβ€’ Repository is accessible"
121
+
122
+
123
+ # Gradio UI
124
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
125
+ gr.Markdown("## πŸ›‘οΈ AI-Powered GitHub Vulnerability Scanner")
126
+ gr.Markdown("""
127
+ **Advanced Security Analysis Tool for GitHub Repositories**
128
+
129
+ This intelligent vulnerability scanner leverages cutting-edge AI agents and Model Context Protocol (MCP) tools to perform comprehensive security analysis of GitHub repositories and individual files.
130
+
131
+ **Key Features:**
132
+ - **Deep Code Analysis**: Scans for common security vulnerabilities including SQL injection, XSS, command injection, and more
133
+ - **AI-Powered Detection**: Uses advanced language models to understand code context and identify complex security issues
134
+ - **Repository & File Support**: Analyze entire repositories or focus on specific files
135
+ - **Detailed Reports**: Get comprehensive security reports with severity levels, line numbers, and remediation suggestions
136
+ - **Secure Processing**: Your API keys are used securely and never stored
137
+
138
+ **Project Links:**
139
+ - πŸ“‚ **Source Code**: [GitHub Repository](https://github.com/banno-0720/vulnerability-scanner)
140
+ - πŸ”§ **MCP Server**: [Hugging Face Space](https://huggingface.co/spaces/HimanshuGoyal2004/github-mcp-server)
141
+
142
+ ⚠️ **Important Notice**: This tool is designed for legitimate security research and vulnerability assessment purposes only. Do not use this scanner for malicious activities, unauthorized access, or any illegal purposes. Always ensure you have proper authorization before scanning repositories that don't belong to you.
143
+ """)
144
+ gr.Markdown("---")
145
+
146
+ # API Configuration Section
147
+ with gr.Row():
148
+ with gr.Column(scale=1):
149
+ gr.Markdown("### πŸ”‘ API Configuration")
150
+ hf_token_box = gr.Textbox(
151
+ label="πŸ€— Hugging Face API Key",
152
+ placeholder="Enter your Hugging Face API key for AI model access",
153
+ type="password",
154
+ info="πŸ”— Get your free key: https://huggingface.co/settings/tokens"
155
+ )
156
+
157
+ gr.Markdown("---")
158
+ gr.Markdown("### πŸ’¬ Security Analysis Chat")
159
+ gr.Markdown("Paste any GitHub repository or file URL below to start the security analysis.")
160
+
161
+ # Chatbot Interface
162
+ chatbot = gr.ChatInterface(
163
+ fn=lambda msg, hist, hf_token: analyze_vulnerabilities(msg, hist, hf_token),
164
+ additional_inputs=[hf_token_box],
165
+ type="messages",
166
+ examples=[
167
+ ["https://github.com/ayushmittal62/vunreability_scanner_testing", ""],
168
+ ["https://github.com/ayushmittal62/vunreability_scanner_testing/blob/master/database/schema.sql", ""],
169
+ ["https://github.com/ayushmittal62/vunreability_scanner_testing/blob/master/python/database.py", ""]
170
+ ],
171
+ )
172
 
173
  if __name__ == "__main__":
174
  demo.launch()