HimanshuGoyal2004 commited on
Commit
913f056
·
1 Parent(s): 46ba31e
Files changed (3) hide show
  1. README.md +15 -1
  2. app.py +93 -0
  3. requirements.txt +8 -0
README.md CHANGED
@@ -10,4 +10,18 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  license: mit
11
  ---
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.
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/"
11
+
12
+ def analyze_vulnerabilities(message, history):
13
+ """Analyze GitHub repository for vulnerabilities using AI agent"""
14
+ try:
15
+ # Connect to MCP server and get GitHub tools
16
+ mcp_client = MCPClient({"url": MCP_SERVER_URL})
17
+ tools = mcp_client.get_tools()
18
+
19
+ # Initialize AI model
20
+ model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
21
+
22
+ # Create AI agent with GitHub MCP tools
23
+ agent = CodeAgent(
24
+ tools=[*tools],
25
+ model=model,
26
+ additional_authorized_imports=["json", "ast", "urllib", "base64", "re"]
27
+ )
28
+
29
+ # Enhanced prompt for vulnerability analysis
30
+ enhanced_prompt = f"""
31
+ You are a cybersecurity expert. Analyze the GitHub repository for security vulnerabilities.
32
+
33
+ Repository: {message}
34
+
35
+ Please:
36
+ 1. First, get repository information to verify it exists
37
+ 2. Scan the repository for code files (.py, .js, .ts, .php, .java, .cpp, .c, .cs, .go, .rb, .rs, .swift, .kt, .scala, .sh, .bash, .ps1, .ipynb, .sql, .xml, .yaml, .yml, .json, .config, .ini, .env)
38
+ 3. For each code file found, get its content and analyze for security vulnerabilities
39
+ 4. Focus on detecting:
40
+ - SQL injection vulnerabilities
41
+ - Command injection (os.system, exec, eval)
42
+ - Cross-site scripting (XSS)
43
+ - Path traversal attacks
44
+ - Hardcoded secrets/credentials
45
+ - Insecure deserialization
46
+ - Weak cryptography
47
+ - Authentication/authorization flaws
48
+ - Input validation issues
49
+ - Unsafe file operations
50
+
51
+ 5. Generate a comprehensive security report with:
52
+ - Repository overview
53
+ - Total files analyzed
54
+ - Vulnerability count by severity (Critical/High/Medium/Low)
55
+ - Detailed findings with:
56
+ - File path and line number
57
+ - Vulnerability type
58
+ - Code snippet
59
+ - Security impact
60
+ - Remediation advice
61
+ - Related CVE examples when applicable
62
+
63
+ Format the report professionally with emojis and clear sections.
64
+ """
65
+
66
+ # Run the AI agent analysis
67
+ result = agent.run(enhanced_prompt)
68
+
69
+ # Disconnect MCP client
70
+ mcp_client.disconnect()
71
+
72
+ return str(result)
73
+
74
+ except Exception as e:
75
+ 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"
76
+
77
+ # Create Gradio interface
78
+ demo = gr.ChatInterface(
79
+ fn=analyze_vulnerabilities,
80
+ type="messages",
81
+ examples=[
82
+ "https://github.com/WebGoat/WebGoat",
83
+ "https://github.com/OWASP/NodeGoat",
84
+ "https://github.com/digininja/DVWA",
85
+ "https://github.com/juice-shop/juice-shop",
86
+ "https://github.com/vulhub/vulhub"
87
+ ],
88
+ title="🛡️ AI-Powered GitHub Vulnerability Scanner",
89
+ description="Paste a GitHub repository URL to scan for security vulnerabilities using AI agents with MCP tools. The AI will intelligently analyze code and provide detailed security reports.",
90
+ )
91
+
92
+ if __name__ == "__main__":
93
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ gradio[oauth,mcp]==5.45.0
2
+ fastapi==0.115.2
3
+ uvicorn==0.24.0
4
+ mcp==1.10.1
5
+ smolagents>=0.1.0
6
+ requests>=2.28.0
7
+ python-dotenv>=1.0.0
8
+ pydantic>=2.11,<2.12