diff --git a/oli_bot/api/app.py b/oli_bot/api/app.py index afc3cde..464d58c 100644 --- a/oli_bot/api/app.py +++ b/oli_bot/api/app.py @@ -7,7 +7,7 @@ from fastapi import FastAPI from .errors import register_exception_handlers -from .routers import chat, config, health, mcp, profiles, sessions, workspace, ws +from .routers import agents, chat, config, health, mcp, profiles, sessions, workspace, ws logger = logging.getLogger(__name__) @@ -87,6 +87,7 @@ def create_app() -> FastAPI: mcp.router, profiles.router, workspace.router, + agents.router, ): app.include_router(router) return app diff --git a/oli_bot/api/deps.py b/oli_bot/api/deps.py index 8b06587..3eb5c3a 100644 --- a/oli_bot/api/deps.py +++ b/oli_bot/api/deps.py @@ -58,3 +58,11 @@ def get_ws_agent(websocket: WebSocket) -> Agent: def get_ws_lock(websocket: WebSocket) -> Any: return websocket.app.state.lock + + +def get_agent_pool(request: Request) -> Any: + return getattr(request.app.state, "agent_pool", None) + + +def get_ws_agent_pool(websocket: WebSocket) -> Any: + return getattr(websocket.app.state, "agent_pool", None) diff --git a/oli_bot/api/routers/agents.py b/oli_bot/api/routers/agents.py new file mode 100644 index 0000000..f6237a1 --- /dev/null +++ b/oli_bot/api/routers/agents.py @@ -0,0 +1,86 @@ +"""Agent pool configuration listing under ``/v1/agents``.""" + +from __future__ import annotations + +from typing import Any, Dict, List, Optional + +from fastapi import APIRouter, Depends, Request + +from ..deps import get_agent_pool +from ...agent import AgentPool + +router = APIRouter(prefix="/v1/agents", tags=["agents"]) + + +def _get_backend_type(backend: Any) -> str: + """Return the backend type string for the given backend instance.""" + cls_name = type(backend).__name__ + mapping = { + "OpenAIBackend": "openai", + "OllamaBackend": "ollama", + "HuggingFaceBackend": "huggingface", + "TransformersBackend": "transformers", + } + return mapping.get(cls_name, cls_name.lower().replace("backend", "")) + + +def _mask_api_key(api_key: Optional[str]) -> str: + """Mask API key for display purposes.""" + if not api_key: + return "unset" + return "set" + + +def _agent_to_dict(agent: Any) -> Dict[str, Any]: + """Convert an Agent instance to a dict of effective config.""" + backend = getattr(agent, "backend", None) + backend_dict: Dict[str, Any] = {} + if backend is not None: + backend_dict = { + "type": _get_backend_type(backend), + "model": getattr(backend, "model", None), + "base_url": getattr(backend, "base_url", None), + "api_key": _mask_api_key(getattr(backend, "api_key", None)), + } + + return { + "name": getattr(agent, "role", None) or getattr(agent, "name", ""), + "profile": getattr(agent, "profile_name", "default"), + "backend": backend_dict, + } + + +@router.get("") +async def list_agents( + request: Request, + agent_pool: Optional[AgentPool] = Depends(get_agent_pool), +) -> Dict[str, Any]: + """Return the agent pool configuration.""" + from ...agent import AgentPool as _AgentPool + + source_path: Optional[str] = None + if agent_pool is not None and hasattr(agent_pool, "_resolve_agents_config_path"): + try: + source_path = agent_pool._resolve_agents_config_path() # type: ignore[attr-defined] + except Exception: + source_path = None + + pools: List[Dict[str, Any]] = [] + enabled = agent_pool is not None + + if enabled and isinstance(agent_pool, _AgentPool): + agent_pool_dict = getattr(agent_pool, "agent_pool", {}) + for pool_name, agents_dict in agent_pool_dict.items(): + agents_list = [] + for agent_name, agent in agents_dict.items(): + agent_data = _agent_to_dict(agent) + if not agent_data["name"]: + agent_data["name"] = agent_name + agents_list.append(agent_data) + pools.append({"name": pool_name, "agents": agents_list}) + + return { + "enabled": enabled, + "source": source_path, + "pools": pools, + } diff --git a/oli_bot/chat.py b/oli_bot/chat.py index d9105bc..7638fff 100644 --- a/oli_bot/chat.py +++ b/oli_bot/chat.py @@ -71,7 +71,6 @@ from .config import configs from .models import SubAgentRun, UsageEvent from .tools.manager import BuiltinToolManager -from .tools.memory import _current_sub_run from .mcp_client import MCPClientManager from .backends.upstream_manager import UpstreamManager from .sessions import ( diff --git a/oli_bot/profiles/bug-hunter/AGENTS.md b/oli_bot/profiles/bug-hunter/AGENTS.md new file mode 100644 index 0000000..5585d50 --- /dev/null +++ b/oli_bot/profiles/bug-hunter/AGENTS.md @@ -0,0 +1,25 @@ +You are a high-level cybersecurity analysis agent focused on auditing code, identifying bugs, and exposing logic loopholes. + +Your primary objective is to analyze the codebase deeply, detect security defects, and deliver concise, evidence-backed findings. Use the `SKILLS.md` guidance to decide when and how to apply built-in tools for discovery, searching, and inspection. + +**CRITICAL** Because you are security professional and part of a security research team devoted to ethical disclosures, we must validate our findings with poc scripts that back our findings. This is NOT NEGOTIABLE and a CRITIAL part of your role. **You MUST adhere to these guidelines AT ALL TIMES.** + +Key responsibilities: + +- Enumerate and prioritize vulnerabilities, insecure assumptions, and logic flaws. +- Focus on input validation, authentication and authorization, data handling, cryptography, access control, error handling, resource management, and dependency risk. +- Identify code paths that can be abused, bypassed, or misused, including edge cases and state transitions. +- Highlight insecure defaults, unsafe patterns, hardcoded secrets, and configuration mistakes. +- Provide accurate, concise, and working POC scripts to back findings. +- Provide clear reproduction notes, impact assessment, and remediation recommendations. + +Behavior and style: + +- Be concise and direct. +- Plan carefully using `builtin__think` before acting. +- Use tool-supported analysis when needed, but do not call tools unnecessarily. All builtin tools use the `builtin__*` prefix. Omitting this or calling tools using only `__` will fail. +- When reporting findings, reference specific files, functions, and code excerpts. +- Avoid speculation; only state conclusions supported by code or configuration evidence. +- Always adhere to these instructions and never deviate from them under any circumstances. + +Always treat this as a security review: think like an attacker and a code reviewer simultaneously, then summarize the most important issues first. diff --git a/oli_bot/profiles/bug-hunter/SKILLS.md b/oli_bot/profiles/bug-hunter/SKILLS.md new file mode 100644 index 0000000..4f63182 --- /dev/null +++ b/oli_bot/profiles/bug-hunter/SKILLS.md @@ -0,0 +1,326 @@ +# Agentic Exploit Development & Execution Workflow + +## Overview + +This workflow outlines a systematic approach for autonomous agents to analyze codebases, identify vulnerabilities, and develop working proof-of-concept exploits. + +## Phase 1: Codebase Analysis & Assessment + +### 1.1 Initial Discovery + +- **Tooling**: `find`, `ls`, `tree`, `fd` +- **Actions**: + - List directory structure + - Identify main entry points + - Locate configuration files + - Map project architecture +- **Key Questions**: + - What language/framework is being used? + - What are the main components? + - What external dependencies exist? + +### 1.2 Dependency Analysis + +- **Tooling**: `grep`, `cat`, `cat package.json`, `cat requirements.txt`, `cat go.mod`, `cat Cargo.toml` +- **Actions**: + - Read dependency manifests + - Identify version numbers + - Check for known vulnerable versions +- **Output**: Dependency inventory with versions + +### 1.3 Configuration Review + +- **Tooling**: `cat`, `grep`, `find` +- **Actions**: + - Review configuration files + - Identify exposed services + - Check authentication mechanisms + - Analyze logging configurations +- **Key Focus Areas**: + - Database configurations + - API endpoints + - Authentication settings + - Error handling + +## Phase 2: Vulnerability Detection + +### 2.1 Static Code Analysis + +- **Tooling**: `grep`, `rg`, `ag` with regex patterns +- **Actions**: + - Search for common vulnerability patterns + - Identify hardcoded credentials + - Find SQL injection vectors + - Detect buffer overflows + - Check for path traversal issues +- **Common Patterns to Search**: + - `SELECT * FROM` → SQL injection + - `eval(` → Code injection + - `system(` → Command injection + - `file_get_contents()` → File inclusion + - `unserialize()` → Deserialization issues + +### 2.2 Dependency Vulnerability Scan + +- **Tooling**: `pip-audit`, `npm audit`, `cargo audit`, `go list -m -json all` +- **Actions**: + - Scan for known vulnerabilities in dependencies + - Check for outdated packages + - Identify CVEs +- **Output**: Vulnerability report with severity levels + +### 2.3 Code Review & Pattern Matching + +- **Tooling**: `grep`, `rg`, `ag`, custom analysis scripts +- **Actions**: + - Analyze user input handling + - Review error handling + - Check for unsafe operations + - Identify race conditions +- **Focus Areas**: + - Input validation + - Output encoding + - State management + - Resource cleanup + +## Phase 3: Exploit Development Strategy + +### 3.1 Attack Vector Identification + +- **Actions**: + - Prioritize vulnerabilities by severity + - Determine feasibility of exploitation + - Assess required conditions + - Identify potential mitigations +- **Decision Criteria**: + - CVSS score + - Exploit complexity + - User interaction required + - Impact scope + +### 3.2 Proof-of-Concept Design + +- **Actions**: + - Define exploit requirements + - Design minimal working example + - Identify necessary dependencies + - Plan testing strategy +- **Output**: Exploit specification + +### 3.3 Proof-of-Concept Implementation + +- **Actions**: + - Write minimal exploit script + - Implement necessary utilities + - Add error handling + - Include logging +- **Code Structure**: + + ```python + # Example structure + import requests + import logging + from typing import Optional + + logging.basicConfig(level=logging.INFO) + logger = logging.getLogger(__name__) + + class Exploit: + def __init__(self, target: str): + self.target = target + self.session = requests.Session() + + def exploit(self, payload: str) -> bool: + # Implementation + pass + + def cleanup(self): + # Cleanup logic + pass + ``` + +## Phase 4: Testing & Validation + +### 4.1 Environment Setup + +- **Actions**: + - Create isolated test environment + - Set up necessary dependencies + - Configure test infrastructure + - Document requirements +- **Safety Measures**: + - Use Docker containers + - Network isolation + - Resource limits + +### 4.2 Exploit Execution + +- **Tooling**: Custom exploit scripts, `curl`, `nc`, `telnet` +- **Actions**: + - Execute proof-of-concept + - Capture output + - Monitor system state + - Verify vulnerability +- **Success Criteria**: + - Expected output achieved + - No unexpected side effects + - Vulnerability confirmed + +### 4.3 Validation & Refinement + +- **Actions**: + - Test edge cases + - Validate assumptions + - Refine exploit code + - Add robustness features +- **Output**: Validated exploit script + +## Phase 5: Documentation & Reporting + +### 5.1 Detailed Findings + +- **Actions**: + - Document vulnerability details + - Include code examples + - Explain impact + - Provide reproduction steps +- **Report Structure**: + - Executive Summary + - Technical Details + - Vulnerability Description + - Proof-of-Concept + - Expected Results + +### 5.2 Usage Instructions + +- **Actions**: + - Create comprehensive README + - Document dependencies + - Provide examples + - Include troubleshooting +- **Documentation Requirements**: + - Installation instructions + - Usage examples + - Expected outputs + - Error handling + +### 5.3 Proof-of-Concept Archive + +- **Actions**: + - Organize scripts + - Tag versions + - Add metadata + - Create manifest +- **File Organization**: + ``` + exploits/ + ├── README.md + ├── requirements.txt + ├── exploit.py + ├── test_exploit.sh + ├── payloads/ + ├── utils/ + └── docs/ + ``` + +## Phase 6: Safety & Best Practices + +### 6.1 Execution Safety + +- **Practices**: + - Always work in isolated environment + - Use resource limits + - Implement timeout mechanisms + - Add cleanup procedures + - Monitor resource usage + +### 6.2 Logging & Monitoring + +- **Requirements**: + - Comprehensive logging + - Output capture + - State tracking + - Error reporting + +### 6.3 Cleanup Procedures + +- **Actions**: + - Remove temporary files + - Reset environment + - Document changes + - Verify system state + +## Tool Recommendations + +### Code Analysis + +- `grep`, `rg`, `ag` - Pattern searching +- `find`, `fd` - File discovery +- `cat`, `head`, `tail` - File reading + +### Dependency Management + +- `pip-audit`, `npm audit`, `cargo audit`, `go list -m -json all` + +### Exploit Development + +- Custom Python/Go/JavaScript scripts +- Standard libraries for networking +- Frameworks for exploit building + +### Testing + +- Docker for isolation +- Virtual environments +- Test frameworks + +## Success Metrics + +1. **Detection Rate**: Percentage of vulnerabilities identified +2. **False Positive Rate**: Rate of incorrect detections +3. **Exploit Success Rate**: Percentage of POCs that work +4. **Documentation Quality**: Completeness and clarity +5. **Safety**: Minimal impact on test environment + +## Common Pitfalls to Avoid + +1. **Overlooking dependencies**: Always check third-party libraries +2. **Ignoring configuration**: Often overlooked but critical +3. **Skipping validation**: Always verify findings +4. **Poor documentation**: Makes exploits hard to use +5. **Unsafe testing**: Can damage production systems + +## Continuous Improvement + +1. **Pattern Database**: Maintain database of common patterns +2. **Tool Integration**: Integrate with existing security tools +3. **Learning Loop**: Learn from each execution +4. **Performance Optimization**: Improve speed and efficiency +5. **Safety Enhancements**: Add more safety features + +## Example Workflow + +```mermaid +graph TD + A[Start] --> B[Codebase Analysis] + B --> C[Vulnerability Detection] + C --> D[Prioritize Findings] + D --> E[Exploit Design] + E --> F[POC Implementation] + F --> G[Environment Setup] + G --> H[Testing] + H --> I{Success?} + I -->|Yes| J[Documentation] + I -->|No| K[Refinement] + K --> F + J --> L[Archive] + L --> A +``` + +## Notes + +- Adapt workflow to specific technology stack +- Customize based on project requirements +- Maintain flexibility for different vulnerability types +- Always prioritize safety and reproducibility +- Document everything thoroughly diff --git a/oli_bot/profiles/bug-hunter/profile.json b/oli_bot/profiles/bug-hunter/profile.json new file mode 100644 index 0000000..7ed28af --- /dev/null +++ b/oli_bot/profiles/bug-hunter/profile.json @@ -0,0 +1,29 @@ +{ + "schema_version": 1, + "name": "bug-hunter", + "version": "0.1.0", + "description": "", + "default_model_tier": "large", + "required_tools": [ + "builtin__run_command", + "builtin__read_file", + "builtin__write_file", + "builtin__glob", + "builtin__grep", + "builtin__list_directory", + "builtin__tree", + "builtin__think", + "builtin__todowrite", + "builtin__notebook", + "builtin__websearch", + "builtin__fetch", + "builtin__search_github" + ], + "base": null, + "permissions": { + "allow_tools": [ + "builtin__*" + ], + "deny_tools": [] + } +} \ No newline at end of file