Nmap example
This commit is contained in:
+27
@@ -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
|
||||||
|
|
||||||
@@ -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
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE nmaprun>
|
||||||
|
<?xml-stylesheet href="file:///usr/bin/../share/nmap/nmap.xsl" type="text/xsl"?>
|
||||||
|
<!-- Nmap 7.80 scan initiated Mon Jan 27 20:01:42 2020 as: nmap -Pn -n -p 1-65535 -oX dba2edbc-527d-453a-9c25-0608bb8f06da.running.xml -- 127.0.0.1 -->
|
||||||
|
<nmaprun scanner="nmap" args="nmap -Pn -n -p 1-65535 -oX dba2edbc-527d-453a-9c25-0608bb8f06da.running.xml -- 127.0.0.1" start="1580151702" startstr="Mon Jan 27 20:01:42 2020" version="7.80" xmloutputversion="1.04">
|
||||||
|
<scaninfo type="connect" protocol="tcp" numservices="65535" services="1-65535"/>
|
||||||
|
<verbose level="0"/>
|
||||||
|
<debugging level="0"/>
|
||||||
|
<host starttime="1580151702" endtime="1580151704"><status state="up" reason="user-set" reason_ttl="0"/>
|
||||||
|
<address addr="127.0.0.1" addrtype="ipv4"/>
|
||||||
|
<hostnames>
|
||||||
|
</hostnames>
|
||||||
|
<ports><extraports state="closed" count="65531">
|
||||||
|
<extrareasons reason="conn-refused" count="65531"/>
|
||||||
|
</extraports>
|
||||||
|
<port protocol="tcp" portid="631"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="ipp" method="table" conf="3"/></port>
|
||||||
|
<port protocol="tcp" portid="8080"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="http-proxy" method="table" conf="3"/></port>
|
||||||
|
<port protocol="tcp" portid="8081"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="blackice-icecap" method="table" conf="3"/></port>
|
||||||
|
<port protocol="tcp" portid="8082"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="blackice-alerts" method="table" conf="3"/></port>
|
||||||
|
</ports>
|
||||||
|
<times srtt="78" rttvar="70" to="100000"/>
|
||||||
|
</host>
|
||||||
|
<runstats><finished time="1580151704" timestr="Mon Jan 27 20:01:44 2020" elapsed="1.91" summary="Nmap done at Mon Jan 27 20:01:44 2020; 1 IP address (1 host up) scanned in 1.91 seconds" exit="success"/><hosts up="1" down="0" total="1"/>
|
||||||
|
</runstats>
|
||||||
|
</nmaprun>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
*If you receive a 202 it means the scan is still on progress*
|
||||||
Reference in New Issue
Block a user