diff --git a/examples/advanced/02_NetworkScanner/NetworkScanner.pow b/examples/advanced/02_NetworkScanner/NetworkScanner.pow new file mode 100755 index 0000000..27b563c --- /dev/null +++ b/examples/advanced/02_NetworkScanner/NetworkScanner.pow @@ -0,0 +1,27 @@ +kapow route add -X POST '/scan' - <<-'EOF' + PORTS=$(kapow get /request/form/ports) + IP=$(kapow get /request/form/ip) + WEBHOOK=$(kapow get /request/form/webhook) + JOBID=$(uuidgen | tr -d '\n') + + (nmap -Pn -n -p "${PORTS:-8080}" -oX "${JOBID}.running.xml" -- "${IP:-127.0.0.1}"; + mv "${JOBID}.running.xml" "${JOBID}.done.xml"; + [ ! -z "$WEBHOOK" ] && curl -s -F "data=@${JOBID}.done.xml" -F "jobid=${JOBID}" "$WEBHOOK"; + ) & + + kapow set /response/headers/Content-Type application/json + jq -n --arg jobid "$JOBID" '{"job": $jobid}' | kapow set /response/body +EOF + +kapow route add -X GET '/scan/{jobid}' - <<-'EOF' + JOBID=$(kapow get /request/matches/jobid) + [ -f "${JOBID}.running.xml" ] && kapow set /response/status 202 && exit 0 + if [ -f "${JOBID}.done.xml" ]; then + kapow set /response/headers/Content-Type application/xml + kapow set /response/body < "${JOBID}.done.xml" + else + kapow set /response/status 404 + kapow set /response/body "Scan $JOBID not found" + fi +EOF + diff --git a/examples/advanced/02_NetworkScanner/README.md b/examples/advanced/02_NetworkScanner/README.md new file mode 100644 index 0000000..7b3c2ff --- /dev/null +++ b/examples/advanced/02_NetworkScanner/README.md @@ -0,0 +1,59 @@ +# Network Scanner (nmap) as a Service + +Run a long network scan in background with support for webhook on completion. + +* The user can define the destination IP and port(s). +* The service answers immediately with a `jobid`. +* If a webhook url is defined it will be called on completion with the result and the jobid. +* At any moment the user can request the status of the scan at /scan/{jobid} + +## How to run it + +``` +$ kapow server NetworkScanner.pow +``` + + +## How to consume it + +* Scan your own host +``` +$ curl --data 'ports=1-65535&ip=127.0.0.1' http://localhost:8080/scan +{ + "job": "dba2edbc-527d-453a-9c25-0608bb8f06da" +} +``` + +* Grab the result + +``` +$ curl -v http://localhost:8080/scan/dba2edbc-527d-453a-9c25-0608bb8f06da + + + + + + + + + +
+ + + + + + + + + + + + + + + + +``` + +*If you receive a 202 it means the scan is still on progress*