AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
100/100
Scores the file, not the repository.Length
1,093 words
35 headings · 6 code blocksRepository
9.7k
— · pushed 10 days agoLast changed
2 days ago
First indexed 2 days ago.1# AGENTS.md23This file provides guidance to AI coding agents when working with code in this repository.45## Project Overview67WPScan is a WordPress security scanner written in Ruby. It provides WordPress-specific scanning capabilities including vulnerability detection, enumeration, and password attacks.89**Key characteristics:**10- Ruby gem with CLI tool11- Architecture based on Controllers, Finders, and Models (MVC-like pattern)12- Uses local database (in `$XDG_CACHE_HOME/wpscan/db` or `~/.cache/wpscan/db`, or `~/.wpscan/db` for existing installations) that syncs with WPScan API13- Scanner framework lives in `lib/wpscan/` (Target, Browser, Controller::Base, Scan, Finders, Formatter, etc.) alongside the WordPress-specific code14- Supports WordPress-specific security scanning features1516## Development Best Practices1718### Code Style19- **Always run rubocop after making changes** to ensure code style compliance20- Run `bundle exec rubocop -a` to auto-fix issues21- For specific files: `bundle exec rubocop -a file1.rb file2.rb`22- The project uses RuboCop for Ruby style enforcement2324## Development Commands2526### Setup27```bash28bundle install29```3031### Running Tests32```bash33# Run all tests except slow ones (default for PRs)34bundle exec rspec --tag ~slow3536# Run full test suite (includes slow tests, only runs on master)37bundle exec rspec3839# Run specific test file40bundle exec rspec spec/path/to/file_spec.rb4142# Run with coverage43bundle exec rspec # Coverage enabled by default via .simplecov44```4546### Code Quality47```bash48# Run rubocop49bundle exec rubocop5051# Auto-fix rubocop issues52bundle exec rubocop -a5354# IMPORTANT: Always run rubocop after making code changes55# Run on specific files being modified:56bundle exec rubocop -a path/to/file1.rb path/to/file2.rb57```5859### Building60```bash61# Build the gem (runs rubocop & rspec automatically)62bundle exec rake build6364# Install gem locally65gem install pkg/wpscan-*.gem66```6768### Running WPScan Locally69```bash70# From source (outside git repo to avoid load path conflicts)71ruby -Ilib bin/wpscan --url https://example.com7273# Or after installing as gem74wpscan --url https://example.com75```7677### Database Operations78```bash79# Update local database80wpscan --update8182# The database is stored in $XDG_CACHE_HOME/wpscan/db or ~/.cache/wpscan/db (new installations)83# or ~/.wpscan/db (existing installations)84```8586## Architecture8788### Core Components8990**Entry Point:**91- `bin/wpscan` - CLI executable that chains controllers together92- Controllers are chained using `<<` operator and executed in order9394**Controllers (app/controllers/):**95Controllers orchestrate the scanning process. The `Core` controller (app/controllers/core.rb) is implicitly handled by the scanner framework via `WPScan::Scan.new` and runs before the explicitly chained controllers. The explicit chain in bin/wpscan executes in this order:961. `VulnApi` - API token setup for vulnerability data972. `CustomDirectories` - Custom wp-content/plugins directory detection983. `InterestingFindings` - Header analysis, robots.txt, readme files994. `WpVersion` - WordPress version detection1005. `MainTheme` - Active theme detection1016. `Enumeration` - Plugins, themes, users, etc (see CLI options)1027. `PasswordAttack` - Brute force attacks1038. `Aliases` - Handle legacy CLI options104105Note: The `Core` controller handles database updates, WordPress detection, and banner display during the `before_scan` phase.106107**Finders (app/finders/):**108Finders implement detection strategies for various WordPress components. Each finder type has multiple strategies (passive, aggressive, mixed):109- `WpVersion` - Detects WordPress version110- `MainTheme` - Detects active theme111- `Plugins` - Plugin enumeration strategies112- `Themes` - Theme enumeration strategies113- `Users` - User enumeration (author ID brute forcing, API endpoints, etc)114- `InterestingFindings` - Backup files, debug logs, etc115- `ConfigBackups` - Config backup file detection (wp-config.php backups)116- `DbExports` - Database export file detection117- `Medias` - Media/attachment enumeration via brute forcing118- `Timthumbs` - Timthumb script detection at known locations119- `Passwords` - Authentication mechanisms (wp-login, XML-RPC)120121**Models (app/models/):**122Domain objects representing WordPress components:123- `WpItem` - Base class for plugins/themes124- `Plugin`, `Theme` - Specific WordPress items125- `WpVersion` - WordPress version with vulnerability info126- `InterestingFinding` - Security-relevant findings127- `ConfigBackup` - Detected wp-config.php backup files128- `DbExport` - Detected database export files129- `Media` - Media attachments found on the site130- `Timthumb` - Timthumb script instances131- `XMLRPC` - XML-RPC interface details132133**Database (lib/wpscan/db/):**134- `Updater` - Syncs local database with WPScan API135- `VulnApi` - API client for vulnerability data136- `DynamicFinders` - Auto-generated finders from database metadata137- `Fingerprints` - Version detection fingerprints138- Database stored in `$XDG_CACHE_HOME/wpscan/db/` or `~/.cache/wpscan/db/` (new installations) or `~/.wpscan/db/` (existing installations) by default (overridden in specs to `spec/fixtures/db/`)139140### Important Patterns141142**Scanner framework:**143The scanner framework lives under `WPScan::` alongside the WordPress-specific code. Core framework classes — `WPScan::Target`, `WPScan::Browser`, `WPScan::Controller::{Base,Core}`, `WPScan::ParsedCli`, `WPScan::Vulnerability`, `WPScan::Model::{InterestingFinding,XMLRPC}`, etc. — are single unified classes, not split across framework/WordPress layers. WordPress-specific behavior is mixed in via modules (e.g. `WPScan::Target::Platform::WordPress` is included into `WPScan::Target`). Option parsing delegates to the external `opt_parse_validator` gem.144145**Dynamic Finders:**146Finders can be dynamically generated from database metadata (see `lib/wpscan/db/dynamic_finders/`). This allows version detection strategies to be data-driven.147148**Slug Classification:**149WordPress slugs (plugin/theme names) are converted to Ruby class names via `classify_slug` helper (lib/wpscan/helper.rb). Handles edge cases:150- Slugs starting with digits get prefixed with `D_` (e.g., `123-plugin` becomes `D_123Plugin`)151- Special characters are converted to underscores152- Slugs with all non-latin characters become `HexSlug_` followed by hex-encoded bytes153154**API Requests Tracking:**155The codebase tracks API requests via `WPScan.api_requests` class variable to monitor usage against API limits.156157## Testing158159### Test Structure160- Tests use RSpec with WebMock for HTTP stubbing161- Fixtures in `spec/fixtures/`162- Shared examples in `spec/shared_examples/`163- Coverage via SimpleCov (configured in `.simplecov`)164165### Key Testing Helpers (spec/spec_helper.rb)166- `rspec_parsed_options(args)` - Parse CLI arguments167- `df_expected_all` - Dynamic finder test expectations168- `vuln_api_data_for(path)` - Load vulnerability API fixtures169- `redefine_constant(constant, value)` - Override WPScan constants for testing170171### Test Tags172- `--tag ~slow` - Excludes slow tests (default for CI on PRs)173- Full suite runs only on master pushes174175## Common Gotchas176177**Active Support Must Be First:**178`active_support/all` must be required before other gems to avoid encoding issues with JSON (see lib/wpscan.rb:4-6).179180**Running Outside Git Repo:**181When using `wpscan` from source, run it outside the git repo to avoid load path conflicts.182183**Database Location:**184Tests override `DB_DIR` to `spec/fixtures/db/`. Production uses `$XDG_CACHE_HOME/wpscan/db` or `~/.cache/wpscan/db` (new installations) or `~/.wpscan/db` (existing installations).185186**Port Normalization:**187WebMock adapter has custom port normalization for Typhoeus (spec/spec_helper.rb:63-96) to handle default ports.188189## API Integration190191**WPScan API:**192- Requires API token (via `--api-token` or `WPSCAN_API_TOKEN` env var or config file)193- Free tier: 25 requests/day194- One request per WordPress version, plugin, and theme detected195- Response tracking via `Typhoeus.on_complete` hook in lib/wpscan.rb196197**Configuration Files:**198WPScan loads options from (in order):1991. `$XDG_CONFIG_HOME/wpscan/scan.json` or `$XDG_CONFIG_HOME/wpscan/scan.yml` (if `XDG_CONFIG_HOME` is set)2002. `~/.config/wpscan/scan.json` or `~/.config/wpscan/scan.yml` (if `XDG_CONFIG_HOME` is not set)2013. `~/.wpscan/scan.json` or `~/.wpscan/scan.yml`2024. `pwd/.wpscan/scan.json` or `pwd/.wpscan/scan.yml`203204Use snake_case for CLI options in config (e.g., `api_token`, `max_threads`).205
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| ethereum/go-ethereumAGENTS.md · 51k | AGENTS.md | buildtestlint-formatgit+1 | 100/100 | 3 days ago | |
| rails/railsAGENTS.md · 59k | AGENTS.md | teststylearchgit+4 | 100/100 | 3 days ago | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-frontend/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| bagisto/bagistoAGENTS.md · 28k | AGENTS.md | setupbuildteststyle+7 | 100/100 | 3 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| netdata/netdatasrc/go/plugin/ibm.d/AGENTS.md · 80k | AGENTS.md | buildtestlint-formatarch+3 | 99/100 | 3 days ago | |
| react/react-nativepackages/react-native-compatibility-check/AGENTS.md · 126k | AGENTS.md | testlint-formatstylearch+4 | 99/100 | 3 days ago | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-query-engine/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+5 | 98/100 | 2 days ago |
