GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — REST API REST API
Miroslav Stampar edited this page
sqlmap can be controlled through an HTTP REST API by using The API server manages scan tasks. A client creates a task, sets sqlmap options, starts a scan, then retrieves status, logs, data and output files.
Start the REST API server with python sqlmapapi.py -s --username sqlmap --password sqlmap By default, the server listens on Common server options: python sqlmapapi.py -s \ -H 127.0.0.1 \ -p 8775 \ --username sqlmap \ --password sqlmap Available API-specific command line options:
When using The API uses HTTP Basic authentication. With curl -u sqlmap:sqlmap http://127.0.0.1:8775/version For the examples below, it is convenient to define the API address and credentials first: API="http://127.0.0.1:8775" AUTH="sqlmap:sqlmap" Then requests can be written as: curl -u "$AUTH" "$API/version" A typical API workflow is:
Example: API="http://127.0.0.1:8775" AUTH="sqlmap:sqlmap" taskid=$(curl -s -u "$AUTH" "$API/task/new" | grep -o '[a-f0-9]\{16\}') curl -u "$AUTH" \ -H "Content-Type: application/json" \ -X POST \ -d '{"url":"https://sekumart.sekuripy.hr/product.php?id=1"}' \ "$API/scan/$taskid/start" curl -u "$AUTH" "$API/scan/$taskid/status" curl -u "$AUTH" "$API/scan/$taskid/log" curl -u "$AUTH" "$API/scan/$taskid/data" The JSON options used with Most API responses are JSON objects containing a Successful response example: {
"success": true,
"taskid": "1a2b3c4d5e6f7890"
}Error response example: {
"success": false,
"message": "Invalid task ID"
}Some API-level errors are returned with HTTP status Returns the sqlmap version and the API contract version exposed by the server.
Example: curl -u "$AUTH" "$API/version" Response: {
"success": true,
"version": "1.10.7.176#dev",
"api_version": 2
}A task represents one sqlmap scan context. Options are stored per task, and scans are started against a task ID. Creates a new task. Example: curl -u "$AUTH" "$API/task/new" Response: {
"success": true,
"taskid": "1a2b3c4d5e6f7890"
}Save the task ID for later requests: taskid=$(curl -s -u "$AUTH" "$API/task/new" | grep -o '[a-f0-9]\{16\}') echo "$taskid" Deletes an existing task and kills its scan process if it is still running. Example: curl -u "$AUTH" "$API/task/$taskid/delete" Response: {
"success": true
}Options can be set separately before starting a scan, or passed directly to Lists current task options. Example: curl -u "$AUTH" "$API/option/$taskid/list" Response excerpt: {
"success": true,
"options": {
"url": null,
"data": null,
"cookie": null,
"level": 1,
"risk": 1,
"batch": true
}
}Retrieves selected option values. Example: curl -u "$AUTH" \ -H "Content-Type: application/json" \ -X POST \ -d '["url", "level", "risk"]' \ "$API/option/$taskid/get" Response: {
"success": true,
"options": {
"url": null,
"level": 1,
"risk": 1
}
}Unknown option example: {
"success": false,
"message": "Unknown option 'doesNotExist'"
}Sets one or more task options. Example: curl -u "$AUTH" \ -H "Content-Type: application/json" \ -X POST \ -d '{"url":"https://sekumart.sekuripy.hr/product.php?id=1","level":2,"risk":1}' \ "$API/option/$taskid/set" Response: {
"success": true
}Unsupported, read-only and unknown options are rejected. An unknown (e.g. misspelled) option is rejected with an {
"success": false,
"message": "Unknown option 'doesNotExist'"
}A handful of interactive/CLI-only options cannot be driven over the API and are rejected as unsupported ( Read-only API-controlled options include Starts a scan for an existing task. The request body contains sqlmap options in JSON form. Example: curl -u "$AUTH" \ -H "Content-Type: application/json" \ -X POST \ -d '{"url":"https://sekumart.sekuripy.hr/product.php?id=1"}' \ "$API/scan/$taskid/start" Response: {
"success": true,
"engineid": 12345
}You can also pass more sqlmap options: curl -u "$AUTH" \ -H "Content-Type: application/json" \ -X POST \ -d '{"url":"https://sekumart.sekuripy.hr/product.php?id=1","batch":true,"level":2,"risk":1,"technique":"BEUSTQ"}' \ "$API/scan/$taskid/start" If a scan is already running for that task, the API returns: {
"success": false,
"message": "Scan already running"
}Returns scan status. Example: curl -u "$AUTH" "$API/scan/$taskid/status" Response while running: {
"success": true,
"status": "running",
"returncode": null
}Possible status values are:
Stops a running scan by terminating the scan process. Example: curl -u "$AUTH" "$API/scan/$taskid/stop" Response: {
"success": true
}Kills a running scan process. Example: curl -u "$AUTH" "$API/scan/$taskid/kill" Response: {
"success": true
}Retrieves all log messages for a task. Example: curl -u "$AUTH" "$API/scan/$taskid/log" Response: {
"success": true,
"log": [
{
"time": "12:34:56",
"level": "INFO",
"message": "testing connection to the target URL"
}
]
}Retrieves a subset of log messages by numeric row range. Example: curl -u "$AUTH" "$API/scan/$taskid/log/1/20" Response: {
"success": true,
"log": [
{
"time": "12:34:56",
"level": "INFO",
"message": "testing connection to the target URL"
}
]
}Invalid range example: {
"success": false,
"message": "Invalid start or end value, must be digits"
}Retrieves structured scan data and errors. Example: curl -u "$AUTH" "$API/scan/$taskid/data" Response: {
"success": true,
"data": [
{
"status": 1,
"type": 2,
"type_name": "DBMS_FINGERPRINT",
"value": "back-end DBMS: MySQL >= 5.1"
},
{
"status": 1,
"type": 4,
"type_name": "CURRENT_USER",
"value": "root@%"
}
],
"error": []
}Each item has a numeric The shape of
Downloads a file from sqlmap's output directory. The response contains Base64-encoded file content. Example: curl -u "$AUTH" "$API/download/$taskid/sekumart.sekuripy.hr/log" Response: {
"success": true,
"file": "YmFzZTY0LWVuY29kZWQgZmlsZSBjb250ZW50"
}The If the file does not exist: {
"success": false,
"message": "File does not exist"
}The server prints an admin token when started: Admin endpoints can be called with or without the token. Without the admin token, list and flush operations are limited to tasks created from the same remote address. With the admin token, they apply to the whole task pool. Lists visible tasks. Example: curl -u "$AUTH" "$API/admin/list" Response: {
"success": true,
"tasks": {
"1a2b3c4d5e6f7890": "running"
},
"tasks_num": 1
}Lists all tasks when a valid admin token is supplied. Example: ADMIN_TOKEN="0123456789abcdef0123456789abcdef" curl -u "$AUTH" "$API/admin/$ADMIN_TOKEN/list" Response: {
"success": true,
"tasks": {
"1a2b3c4d5e6f7890": "running"
},
"tasks_num": 1
}Deletes visible tasks and kills their scan processes. Example: curl -u "$AUTH" "$API/admin/flush" Response: {
"success": true
}Deletes all tasks when a valid admin token is supplied. Example: curl -u "$AUTH" "$API/admin/$ADMIN_TOKEN/flush" Response: {
"success": true
}sqlmap also includes an interactive API client: python sqlmapapi.py -c --username sqlmap --password sqlmap To connect to a non-default server address: python sqlmapapi.py -c \ -H 127.0.0.1 \ -p 8775 \ --username sqlmap \ --password sqlmap Useful client commands include:
Example: The REST API can also be described with the OpenAPI specification file: That file can be used by API documentation tools, client generators and API testing tools. Validate the specification with Redocly: npm install -g @redocly/cli redocly lint sqlmapapi.yaml Postman can import an OpenAPI specification directly. Import A standalone Postman collection can also be generated from the OpenAPI file: npm install -g openapi-to-postmanv2 openapi2postmanv2 \ -s sqlmapapi.yaml \ -o sqlmapapi.postman_collection.json \ -p \ -O folderStrategy=Tags,includeAuthInfoInExample=true The OpenAPI file should be treated as the canonical machine-readable API description. A generated Postman collection is only a convenience artifact. The REST API is intended to be used by trusted clients and trusted integrations. Important notes for integrators:
API="http://127.0.0.1:8775" AUTH="sqlmap:sqlmap" # Create a task taskid=$(curl -s -u "$AUTH" "$API/task/new" | grep -o '[a-f0-9]\{16\}') echo "Task ID: $taskid" # Start a scan curl -u "$AUTH" \ -H "Content-Type: application/json" \ -X POST \ -d '{"url":"https://sekumart.sekuripy.hr/product.php?id=1","batch":true}' \ "$API/scan/$taskid/start" # Poll status curl -u "$AUTH" "$API/scan/$taskid/status" # Retrieve logs curl -u "$AUTH" "$API/scan/$taskid/log" # Retrieve data curl -u "$AUTH" "$API/scan/$taskid/data" # Delete task curl -u "$AUTH" "$API/task/$taskid/delete"
Clone this wiki locally | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |