|
1 | | -# Examples |
| 1 | +# SecNode API |
2 | 2 |
|
3 | | -This directory contains usage examples and sample schema-driven scan flows. |
| 3 | +[](https://github.com/SecNode/API-PENTESTER/actions/workflows/secnode-pentest.yml) |
| 4 | +[](https://www.python.org/downloads/) |
| 5 | +[](./LICENSE) |
4 | 6 |
|
5 | | -Example command: |
| 7 | +AI-augmented, schema-driven API penetration testing from OpenAPI/Swagger specs, with asynchronous execution and structured reporting. |
| 8 | + |
| 9 | +## Why SecNode API |
| 10 | + |
| 11 | +SecNode API helps security engineers and backend teams run repeatable API risk assessments in staging and CI without writing one-off test scripts for every target. |
| 12 | + |
| 13 | +- Ingests local or remote OpenAPI/Swagger schema files |
| 14 | +- Uses an LLM to understand API behavior and generate adversarial test cases |
| 15 | +- Executes tests concurrently with optional proxy routing |
| 16 | +- Supports autonomous agent mode with request budgets and iterative replanning |
| 17 | +- Produces both human-readable and machine-readable findings |
| 18 | + |
| 19 | +## What It Is and Is Not |
| 20 | + |
| 21 | +SecNode API is a practical automation layer for API security testing. |
| 22 | + |
| 23 | +- It is useful for fast risk triage, regression checks, and structured analyst review |
| 24 | +- It does not replace manual penetration testing or threat modeling |
| 25 | +- It can still produce false positives or miss undocumented behavior |
| 26 | + |
| 27 | +## Installation |
| 28 | + |
| 29 | +### Requirements |
| 30 | + |
| 31 | +- Python 3.9+ |
| 32 | +- Access to an LLM provider key (OpenAI or Anthropic) |
| 33 | + |
| 34 | +### Install from source |
| 35 | + |
| 36 | +```bash |
| 37 | +python -m venv .venv |
| 38 | +source .venv/bin/activate |
| 39 | +pip install -r requirements.txt |
| 40 | +pip install -e .[dev] |
| 41 | +``` |
| 42 | + |
| 43 | +### Install with uv (recommended) |
| 44 | + |
| 45 | +```bash |
| 46 | +uv sync --extra dev |
| 47 | +``` |
| 48 | + |
| 49 | +On Windows (PowerShell): |
| 50 | + |
| 51 | +```powershell |
| 52 | +python -m venv .venv |
| 53 | +.venv\Scripts\Activate.ps1 |
| 54 | +pip install -r requirements.txt |
| 55 | +pip install -e .[dev] |
| 56 | +``` |
| 57 | + |
| 58 | +On Windows (PowerShell) with uv: |
| 59 | + |
| 60 | +```powershell |
| 61 | +uv sync --extra dev |
| 62 | +``` |
| 63 | + |
| 64 | +## Configuration |
| 65 | + |
| 66 | +Set the model and provider credentials before running scans: |
| 67 | + |
| 68 | +```bash |
| 69 | +export SECNODE_LLM="openai/gpt-4o" |
| 70 | +export OPENAI_API_KEY="your-api-key" |
| 71 | +``` |
| 72 | + |
| 73 | +Or with Anthropic: |
6 | 74 |
|
7 | 75 | ```bash |
8 | | -secnodeapi --target ./examples/openapi.yaml --dry-run --dry-run-output ./results/tests.json |
| 76 | +export SECNODE_LLM="anthropic/claude-3-5-sonnet-20241022" |
| 77 | +export ANTHROPIC_API_KEY="your-anthropic-key" |
9 | 78 | ``` |
| 79 | + |
| 80 | +Or with Ollama: |
| 81 | + |
| 82 | +```bash |
| 83 | +export SECNODE_LLM="ollama/llama3.1" |
| 84 | +export OLLAMA_API_BASE="http://localhost:11434" # optional, defaults to localhost if omitted |
| 85 | +``` |
| 86 | + |
| 87 | +Provider credentials are model-specific. `openai/*` requires `OPENAI_API_KEY`, `anthropic/*` |
| 88 | +requires `ANTHROPIC_API_KEY`, and `ollama/*` can run locally without cloud API keys. |
| 89 | +See [LiteLLM providers](https://docs.litellm.ai/docs/providers). |
| 90 | + |
| 91 | +## Quick Start |
| 92 | + |
| 93 | +Run against a remote schema: |
| 94 | + |
| 95 | +```bash |
| 96 | +secnodeapi --target https://api.example.com/swagger.json |
| 97 | +``` |
| 98 | + |
| 99 | +Run against a local schema file: |
| 100 | + |
| 101 | +```bash |
| 102 | +secnodeapi --target ./openapi.yaml |
| 103 | +``` |
| 104 | + |
| 105 | +Reports are written to `results/<target_or_local_schema>_<timestamp>/`. |
| 106 | + |
| 107 | +## CLI Usage |
| 108 | + |
| 109 | +```bash |
| 110 | +secnodeapi --target ./openapi.yaml --schema-only |
| 111 | +secnodeapi --target https://api.example.com/swagger.json --dry-run --dry-run-output ./results/tests.json |
| 112 | +secnodeapi --target https://api.example.com/swagger.json --auth-header "Authorization: Bearer <token>" |
| 113 | +secnodeapi --target https://api.example.com/swagger.json --proxy http://127.0.0.1:8080 --insecure |
| 114 | +secnodeapi --target https://api.example.com/swagger.json --mode agent --request-budget 500 --max-iterations 6 |
| 115 | +``` |
| 116 | + |
| 117 | +### Key options |
| 118 | + |
| 119 | +- `--target` URL or local path to OpenAPI schema (required) |
| 120 | +- `--mode` `agent` (default) or `legacy` execution pipeline |
| 121 | +- `--concurrency` concurrent request workers |
| 122 | +- `--auth-header` single inline auth header |
| 123 | +- `--auth-file` JSON file of auth headers |
| 124 | +- `--identities-file` JSON identities for differential auth testing |
| 125 | +- `--schema-only` output normalized API structure and exit |
| 126 | +- `--dry-run` generate tests without executing |
| 127 | +- `--dry-run-output` write generated tests to JSON (requires `--dry-run`) |
| 128 | +- `--request-budget` max request count in agent mode |
| 129 | +- `--per-endpoint-budget` max attempts per endpoint in agent mode |
| 130 | +- `--max-iterations` max plan/execute loops in agent mode |
| 131 | +- `--proxy` route traffic via proxy |
| 132 | +- `--insecure` disable TLS verification for controlled environments |
| 133 | + |
| 134 | +## Output |
| 135 | + |
| 136 | +Each run generates an output directory containing: |
| 137 | + |
| 138 | +- `report.md` with executive summary, severity overview, and evidence sections |
| 139 | +- `findings.json` for machine processing and pipeline integration |
| 140 | + |
| 141 | +## Development |
| 142 | + |
| 143 | +```bash |
| 144 | +make install-dev |
| 145 | +make lint |
| 146 | +make test |
| 147 | +make test-cov |
| 148 | +make build |
| 149 | +``` |
| 150 | + |
| 151 | +Using uv-native targets: |
| 152 | + |
| 153 | +```bash |
| 154 | +make install-dev-uv |
| 155 | +make lint-uv |
| 156 | +make test-uv |
| 157 | +make test-cov-uv |
| 158 | +make build-uv |
| 159 | +``` |
| 160 | + |
| 161 | +## CI |
| 162 | + |
| 163 | +GitHub Actions workflow runs: |
| 164 | + |
| 165 | +- lint checks |
| 166 | +- test suite with coverage thresholds |
| 167 | +- package build |
| 168 | +- scan job template for staging targets |
| 169 | + |
| 170 | +## Security and Responsible Use |
| 171 | + |
| 172 | +Only test systems you own or are explicitly authorized to assess. |
| 173 | + |
| 174 | +- Read the disclosure process in [SECURITY.md](./SECURITY.md) |
| 175 | +- Follow community expectations in [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) |
| 176 | + |
| 177 | +## Contributing |
| 178 | + |
| 179 | +Contributions are welcome. For setup and PR expectations, see [CONTRIBUTING.md](./CONTRIBUTING.md). |
| 180 | + |
| 181 | +## License |
| 182 | + |
| 183 | +Apache 2.0. See [LICENSE](./LICENSE). |
0 commit comments