Nmap nat-pmp-mapport NSE Script


This page contains detailed information about how to use the nat-pmp-mapport 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/nat-pmp-mapport.nse
Script categories: discovery, safe
Target service / protocol: nat-pmp, udp
Target network port(s): 5351
List of CVEs: -

Script Description


The nat-pmp-mapport.nse script maps a WAN port on the router to a local port on the client using the NAT Port Mapping Protocol (NAT-PMP). It supports the following operations:

  • map - maps a new external port on the router to an internal port of the requesting IP
  • unmap - unmaps a previously mapped port for the requesting IP
  • unmapall - unmaps all previously mapped ports for the requesting IP

Nat-pmp-mapport NSE Script Arguments


This is a full list of arguments supported by the nat-pmp-mapport.nse script:

nat-pmp-mapport.lifetime

The lifetime of the mapping in seconds (default: 3600)

nat-pmp-mapport.op

Operation, can be either map, unmap or unmap all o map allows you to map an external port to an internal port of the calling IP o unmap removes the external port mapping for the specified ports and protocol o unmapall removes all mappings for the specified protocol and calling IP

nat-pmp-mapport.privport

The internal port of the calling IP to map requests to. This port will receive all requests coming in to the external port on the router.

nat-pmp-mapport.protocol

The protocol to map, can be either tcp or udp.

nat-pmp-mapport.pubport

The external port to map on the router. The specified port is treated as the requested port. If the port is available it will be allocated to the caller, otherwise the router will simply choose another port, create the mapping and return the resulting port.

- - -
To use these script arguments, add them to the Nmap command line using the --script-args arg1=value,[arg2=value,..] syntax. For example:

nmap --script=nat-pmp-mapport --script-args nat-pmp-mapport.lifetime=value,nat-pmp-mapport.op=value <target>

Nat-pmp-mapport NSE Script Example Usage


Here's an example of how to use the nat-pmp-mapport.nse script:

nmap -sU -p 5351 <ip> --script nat-pmp-mapport --script-args='op=map,pubport=8080,privport=8080,protocol=tcp'

nmap -sU -p 5351 <ip> --script nat-pmp-mapport --script-args='op=unmap,pubport=8080,privport=8080,protocol=tcp'

nmap -sU -p 5351 <ip> --script nat-pmp-mapport --script-args='op=unmapall,protocol=tcp'

Nat-pmp-mapport NSE Script Example Output


Here's a sample output from the nat-pmp-mapport.nse script:

PORT     STATE SERVICE
5351/udp open  nat-pmp
| nat-pmp-mapport:
|_  Successfully mapped tcp 1.2.3.4:8080 -> 192.168.0.100:80

Nat-pmp-mapport NSE Script Example XML Output


There is no sample XML output for this module. However, by providing the -oX <file> option, Nmap will produce a XML output and save it in the file.xml file.

Author


  • Patrik Karlsson

References


See Also


Related NSE scripts to the nat-pmp-mapport.nse script:

Visit Nmap NSE Library for more scripts.

The nat-pmp-mapport.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.

Operation must be either "map", "unmap" or "unmapall"


Here is a relevant code snippet related to the "Operation must be either "map", "unmap" or "unmapall"" error message:

61:	action = function(host, port)
62:	
63:	  local op = arg_op:lower()
64:	
65:	  if ( "map" ~= op and "unmap" ~= op and "unmapall" ~= op ) then
66:	    return fail("Operation must be either "map", "unmap" or "unmapall"")
67:	  end
68:	
69:	  if ( ("map" == op or "unmap" == op ) and
70:	    ( not(arg_pubport) or not(arg_privport) or not(arg_protocol) ) ) then
71:	    return fail("The arguments pubport, privport and protocol are required")

The arguments pubport, privport and protocol are required


Here is a relevant code snippet related to the "The arguments pubport, privport and protocol are required" error message:

66:	    return fail("Operation must be either "map", "unmap" or "unmapall"")
67:	  end
68:	
69:	  if ( ("map" == op or "unmap" == op ) and
70:	    ( not(arg_pubport) or not(arg_privport) or not(arg_protocol) ) ) then
71:	    return fail("The arguments pubport, privport and protocol are required")
72:	  elseif ( "unmapall" == op and not(arg_protocol) ) then
73:	    return fail("The argument protocol is required")
74:	  end
75:	
76:	  local helper = natpmp.Helper:new(host, port)

The argument protocol is required


Here is a relevant code snippet related to the "The argument protocol is required" error message:

68:	
69:	  if ( ("map" == op or "unmap" == op ) and
70:	    ( not(arg_pubport) or not(arg_privport) or not(arg_protocol) ) ) then
71:	    return fail("The arguments pubport, privport and protocol are required")
72:	  elseif ( "unmapall" == op and not(arg_protocol) ) then
73:	    return fail("The argument protocol is required")
74:	  end
75:	
76:	  local helper = natpmp.Helper:new(host, port)
77:	
78:	  if ( "unmap" == op or "unmapall" == op ) then

Failed to retrieve WAN IP


Here is a relevant code snippet related to the "Failed to retrieve WAN IP" error message:

82:	    arg_pubport, arg_privport = 0, 0
83:	  end
84:	
85:	  local status, response = helper:getWANIP()
86:	  if ( not(status) ) then
87:	    return fail("Failed to retrieve WAN IP")
88:	  end
89:	
90:	  local wan_ip = response.ip
91:	  local lan_ip = (nmap.get_interface_info(host.interface)).address
92:	

WARNING: Requested public port could not be allocated


Here is a relevant code snippet related to the "WARNING: Requested public port could not be allocated" error message:

106:	    output = ("Successfully mapped %s %s:%d -> %s:%d"):format(
107:	      arg_protocol, wan_ip, response.pubport, lan_ip, response.privport )
108:	
109:	    if ( tonumber(arg_pubport) ~= tonumber(response.pubport) ) then
110:	      output = { output }
111:	      table.insert(output, "WARNING: Requested public port could not be allocated")
112:	    end
113:	  end
114:	
115:	  return stdnse.format_output(true, output)
116:	

Version


This page has been created based on Nmap version 7.92.

Go back to menu.