Nmap coap-resources NSE Script


This page contains detailed information about how to use the coap-resources NSE script. For list of all NSE scripts, visit the Nmap NSE Library.

Select:
Overview
Error Messages

Script Overview


Script source code: https://github.com/nmap/nmap/tree/master/scripts/coap-resources.nse
Script categories: safe, discovery
Target service / protocol: coap, udp
Target network port(s): 5683
List of CVEs: -

Script Description


The coap-resources.nse script dumps list of available resources from CoAP endpoints.

This script establishes a connection to a CoAP endpoint and performs a GET request on a resource. The default resource for our request is /.well-known/core, which should contain a list of resources provided by the endpoint.

For additional information:

Coap-resources NSE Script Arguments


This is a full list of arguments supported by the coap-resources.nse script:

coap-resources.uri

URI to request via the GET method, /.well-known/core by default.

- - -
To use this script argument, add it to Nmap command line like in this example:

nmap --script=coap-resources --script-args coap-resources.uri=value <target>

Coap-resources NSE Script Example Usage


Here's an example of how to use the coap-resources.nse script:

nmap -p U:5683 -sU --script coap-resources <target>

Coap-resources NSE Script Example Output


Here's a sample output from the coap-resources.nse script:

PORT     STATE SERVICE REASON
5683/udp open  coap    udp-response ttl 36
| coap-resources:
|   /large:
|     rt: block
|     sz: 1280
|     title: Large resource
|   /large-update:
|     ct: 0
|     rt: block
|     sz: 55
|     title: Large resource that can be updated using PUT method
|   /link1:
|     if: If1
|     rt: Type1 Type2
|_    title: Link test resource

Coap-resources NSE Script Example XML Output


Here's a sample XML output from the coap-resources.nse script produced by providing the -oX <file> Nmap option:

 <table key="/">
   <elem key="ct">0</elem>
   <elem key="title">General Info</elem>
 </table>
 <table key="/ft">
   <elem key="ct">0</elem>
   <elem key="title">Faults Reporting</elem>
 </table>
 <table key="/mn">
   <elem key="ct">0</elem>
   <elem key="title">Monitor Reporting</elem>
 </table>
 <table key="/st">
   <elem key="ct">0</elem>
   <elem key="title">Status Reporting</elem>
 </table>
 <table key="/time">
   <elem key="ct">0</elem>
   <elem key="obs,&lt;/devices/block&gt;;title">Devices Block</elem>
   <elem key="title">Internal Clock</elem>
 </table>
 <table key="/wn">
   <elem key="ct">0</elem>
   <elem key="title">Warnings Reporting</elem>
 </table>

Author


References


See Also


Visit Nmap NSE Library for more scripts.

The coap-resources.nse script may fail with the following error messages. Check for the possible causes by using the code snippets highlighted below found in the script source code. This can often times help in identifying the root cause of the problem.

Response did not contain a payload.


Here is a relevant code snippet related to the "Response did not contain a payload." error message:

177:	    if not status then
178:	      return false, response
179:	    end
180:	
181:	    if not response.payload then
182:	      return false, "Response did not contain a payload."
183:	    end
184:	
185:	    -- Check for the presence of the block2 option, and if it's
186:	    -- missing then we're going to stop.
187:	    b2opt = coap.COAP.header.find_option(response, "block2")

Server responded with '%s' code where 'content' was expected.


Here is a relevant code snippet related to the "Server responded with '%s' code where 'content' was expected." error message:

263:	      stdnse.debug1("The target reports that the resource '%s' was not found.", options.uri)
264:	      return nil
265:	    end
266:	
267:	    -- Otherwise, we assume that we're getting a legitimate CoAP response.
268:	    output.ERROR = ("Server responded with '%s' code where 'content' was expected."):format(response.code)
269:	    return output, output.ERROR
270:	  end
271:	
272:	  local result = response.payload
273:	  if not result then

Payload for initial response was not part of the packet.


Here is a relevant code snippet related to the "Payload for initial response was not part of the packet." error message:

269:	    return output, output.ERROR
270:	  end
271:	
272:	  local result = response.payload
273:	  if not result then
274:	    output.ERROR = "Payload for initial response was not part of the packet."
275:	    return output, output.ERROR
276:	  end
277:	
278:	  -- Check for the presence of the block2 option, which indicates that
279:	  -- we'll need to perform more requests.

Failed to parse payload: %s


Here is a relevant code snippet related to the "Failed to parse payload: %s" error message:

290:	    result = result .. payload
291:	
292:	    -- Parse the payload.
293:	    local status, parsed = coap.COAP.payload.parse(response, result)
294:	    if not status then
295:	      stdnse.debug1("Failed to parse payload: %s", parsed)
296:	      stdnse.debug1("Falling back to returning raw payload as last resort.")
297:	      output["Raw CoAP response"] = result
298:	      return output, stdnse.format_output(true, output)
299:	    end
300:	

Version


This page has been created based on Nmap version 7.92.

Go back to menu.