PATH:
usr
/
share
/
nmap
/
nselib
--- -- This library implements the basics of NAT-PMP as described in the -- NAT Port Mapping Protocol (NAT-PMP) draft: -- o http://tools.ietf.org/html/draft-cheshire-nat-pmp-03 -- -- -- @author "Patrik Karlsson <patrik@cqure.net>" -- local bin = require "bin" local ipOps = require "ipOps" local nmap = require "nmap" local stdnse = require "stdnse" _ENV = stdnse.module("natpmp", stdnse.seeall) local ResultCode = { SUCCESS = 0, UNSUPPORTED_VERSION = 1, NOT_AUTHORIZED = 2, NETWORK_FAILURE = 3, OUT_OF_RESOURCES = 4, UNSUPPORTED_OPCODE = 5, } local ErrorMessage = { [ResultCode.UNSUPPORTED_VERSION] = "The device did not support the protocol version", [ResultCode.NOT_AUTHORIZED] = "The operation was not authorized", [ResultCode.NETWORK_FAILURE] = "Network failure", [ResultCode.OUT_OF_RESOURCES] = "The device is out of resources", [ResultCode.UNSUPPORTED_OPCODE] = "The requested operation was not supported", } Request = { GetWANIP = { new = function(self) local o = { version = 0, op = 0 } setmetatable(o, self) self.__index = self return o end, __tostring = function(self) return bin.pack(">CC", self.version, self.op) end, }, MapPort = { new = function(self, pubport, privport, proto, lifetime) assert(proto == "udp" or proto == "tcp", "Unsupported protocol") local o = { version = 0, pubport = pubport, privport = privport, proto = proto, lifetime = lifetime or 3600 } setmetatable(o, self) self.__index = self return o end, __tostring = function(self) return bin.pack(">CCSSSI", self.version, (self.proto=="udp" and 1 or 2), 0, -- reserved self.privport, self.pubport, self.lifetime) end, } } Response = { GetWANIP = { new = function(self, data) local o = { data = data } setmetatable(o, self) self.__index = self if ( o:parse() ) then return o end end, parse = function(self) if ( #self.data ~= 12 ) then return end local pos pos, self.version, self.op, self.rescode = bin.unpack("<CCS", self.data) if ( self.rescode ~= ResultCode.SUCCESS or self.op ~= 128 ) then return end pos, self.time, self.ip = bin.unpack("<II", self.data, pos) self.ip = ipOps.fromdword(self.ip) self.time = stdnse.format_timestamp(self.time) return true end, }, MapPort = { new = function(self, data) local o = { data = data } setmetatable(o, self) self.__index = self if ( o:parse() ) then return o end end, parse = function(self) if ( #self.data ~= 16 ) then return end local pos pos, self.version, self.op, self.rescode = bin.unpack("<CCS", self.data) if ( self.rescode ~= ResultCode.SUCCESS ) then return end pos, self.time, self.privport, self.pubport, self.lifetime = bin.unpack(">ISSI", self.data, pos) return true end, } } Helper = { new = function(self, host, port) local o = { host = host, port = port } setmetatable(o, self) self.__index = self return o end, exchPacket = function(self, data) local socket = nmap.new_socket("udp") socket:set_timeout(5000) local status = socket:sendto(self.host, self.port, data) if ( not(status) ) then socket:close() return false, "Failed to send request to device" end local response status, response = socket:receive() socket:close() if ( not(status) ) then return false, "Failed to receive response from router" end return true, response end, --- Gets the WAN ip of the router getWANIP = function(self) local packet = Request.GetWANIP:new() local status, response = self:exchPacket(tostring(packet)) if ( not(status) ) then return status, response end response = Response.GetWANIP:new(response) if ( not(response) ) then return false, "Failed to parse response from router" end return true, response end, --- Maps a public port to a private port -- @param pubport number containing the public external port to map -- @param privport number containing the private internal port to map -- @param protocol string containing the protocol to map (udp|tcp) -- @param lifetime [optional] number containing the lifetime in seconds mapPort = function(self, pubport, privport, protocol, lifetime) local packet = Request.MapPort:new(pubport, privport, protocol, lifetime) local status, response = self:exchPacket(tostring(packet)) if ( not(status) ) then return status, response end response = Response.MapPort:new(response) if ( not(response) ) then return false, "Failed to parse response from router" end return true, response end, unmapPort = function(self, pubport, privport) return self:mapPort(pubport, privport, 0) end, unmapAllPorts = function(self) return self.mapPort(0, 0, 0) end, } return _ENV;
[-] iscsi.lua
[edit]
[-] httpspider.lua
[edit]
[-] rmi.lua
[edit]
[-] socks.lua
[edit]
[-] dhcp6.lua
[edit]
[-] sasl.lua
[edit]
[-] drda.lua
[edit]
[+]
data
[-] dhcp.lua
[edit]
[-] omp2.lua
[edit]
[-] ospf.lua
[edit]
[-] ipp.lua
[edit]
[-] pop3.lua
[edit]
[-] netbios.lua
[edit]
[-] pgsql.lua
[edit]
[-] packet.lua
[edit]
[-] rpc.lua
[edit]
[-] xdmcp.lua
[edit]
[-] msrpc.lua
[edit]
[+]
..
[-] eigrp.lua
[edit]
[-] giop.lua
[edit]
[-] afp.lua
[edit]
[-] bjnp.lua
[edit]
[-] match.lua
[edit]
[-] iax2.lua
[edit]
[-] smtp.lua
[edit]
[-] msrpctypes.lua
[edit]
[-] cvs.lua
[edit]
[-] natpmp.lua
[edit]
[-] bitcoin.lua
[edit]
[-] snmp.lua
[edit]
[-] rsync.lua
[edit]
[-] mssql.lua
[edit]
[-] base64.lua
[edit]
[-] ncp.lua
[edit]
[-] base32.lua
[edit]
[-] sip.lua
[edit]
[-] http.lua
[edit]
[-] asn1.lua
[edit]
[-] stun.lua
[edit]
[-] citrixxml.lua
[edit]
[-] nrpc.lua
[edit]
[-] proxy.lua
[edit]
[-] pppoe.lua
[edit]
[-] amqp.lua
[edit]
[-] dns.lua
[edit]
[-] informix.lua
[edit]
[-] tftp.lua
[edit]
[-] sslcert.lua
[edit]
[-] strbuf.lua
[edit]
[-] unpwdb.lua
[edit]
[-] strict.lua
[edit]
[-] vulns.lua
[edit]
[-] jdwp.lua
[edit]
[-] stdnse.lua
[edit]
[-] dnssd.lua
[edit]
[-] mysql.lua
[edit]
[-] rdp.lua
[edit]
[-] mongodb.lua
[edit]
[-] ndmp.lua
[edit]
[-] isns.lua
[edit]
[-] ldap.lua
[edit]
[-] creds.lua
[edit]
[-] tab.lua
[edit]
[-] ftp.lua
[edit]
[-] brute.lua
[edit]
[-] comm.lua
[edit]
[-] ipOps.lua
[edit]
[-] mobileme.lua
[edit]
[-] target.lua
[edit]
[-] rpcap.lua
[edit]
[-] eap.lua
[edit]
[-] cassandra.lua
[edit]
[-] ssh1.lua
[edit]
[-] url.lua
[edit]
[-] datafiles.lua
[edit]
[-] ajp.lua
[edit]
[-] vuzedht.lua
[edit]
[-] nsedebug.lua
[edit]
[-] rtsp.lua
[edit]
[-] shortport.lua
[edit]
[-] bittorrent.lua
[edit]
[-] ssh2.lua
[edit]
[-] msrpcperformance.lua
[edit]
[-] listop.lua
[edit]
[-] dnsbl.lua
[edit]
[-] json.lua
[edit]
[-] redis.lua
[edit]
[-] wsdd.lua
[edit]
[-] tns.lua
[edit]
[-] ike.lua
[edit]
[-] gps.lua
[edit]
[-] versant.lua
[edit]
[-] imap.lua
[edit]
[-] smb.lua
[edit]
[-] smbauth.lua
[edit]
[-] xmpp.lua
[edit]
[-] upnp.lua
[edit]
[-] membase.lua
[edit]
[-] vnc.lua
[edit]
[-] srvloc.lua
[edit]