MAJOR=4 MINOR=23 DEVNAME=tty23 7 ˆl–ßi~”Ji?u8 ]¸'.¥1hß‘äÇò 8à@øÔn:ÓÏà ƒh¹Ê¿Ç 0000007c 7 ˆl–Ðz¾” ŠeJeAà™¸ËêbÑ¿�þDèäY¹Dã­ÆGŠñüÿÄ „Û¿ËÀÈ'­ local ipOps = require "ipOps" local math = require "math" local nmap = require "nmap" local packet = require "packet" local stdnse = require "stdnse" local string = require "string" local table = require "table" description = [[ Performs simple Path MTU Discovery to target hosts. TCP or UDP packets are sent to the host with the DF (don't fragment) bit set and with varying amounts of data. If an ICMP Fragmentation Needed is received, or no reply is received after retransmissions, the amount of data is lowered and another packet is sent. This continues until (assuming no errors occur) a reply from the final host is received, indicating the packet reached the host without being fragmented. Not all MTUs are attempted so as to not expend too much time or network resources. Currently the relatively short list of MTUs to try contains the plateau values from Table 7-1 in RFC 1191, "Path MTU Discovery". Using these values significantly cuts down the MTU search space. On top of that, this list is rarely traversed in whole because: * the MTU of the outgoing interface is used as a starting point, and * we can jump down the list when an intermediate router sending a "can't fragment" message includes its next hop MTU (as described in RFC 1191 and required by RFC 1812) ]] --- -- @usage -- nmap --script path-mtu target -- -- @output -- Host script results: -- |_path-mtu: 1492 <= PMTU < 1500 -- -- Host script results: -- |_path-mtu: PMTU == 1006 author = "Kris Katterjohn" license = "Same as Nmap--See https://nmap.org/book/man-legal.html" categories = {"safe", "discovery"} local IPPROTO_ICMP = packet.IPPROTO_ICMP local IPPROTO_TCP = packet.IPPROTO_TCP local IPPROTO_UDP = packet.IPPROTO_UDP -- Number of times to retransmit for no reply before dropping to -- another MTU value local RETRIES = 1 -- RFC 1191, Table 7-1: Plateaus. Even the massive MTU values are -- here since we skip down the list based on the outgoing interface -- so its no harm. local MTUS = { 65535, 32000, 17914, 8166, 4352, 2002, 1492, 1006, 508, 296, 68 } -- Find the index in MTUS{} to use based on the MTU +new+. If +new+ is in -- between values in MTUS, then insert it into the table appropriately. local searchmtu = function(cidx, new) if new == 0 then return cidx end while cidx <= #MTUS do if new >= MTUS[cidx] then if new ~= MTUS[cidx] then table.insert(MTUS, cidx, new) end return cidx end cidx = cidx + 1 end return cidx end local dport = function(ip) if ip.ip_p == IPPROTO_TCP then return ip.tcp_dport elseif ip.ip_p == IPPROTO_UDP then return ip.udp_dport end end local sport = function(ip) if ip.ip_p == IPPROTO_TCP then return ip.tcp_sport elseif ip.ip_p == IPPROTO_UDP then return ip.udp_sport end end -- Checks how we should react to this packet local checkpkt = function(reply, orig) local ip = packet.Packet:new(reply, reply:len()) if ip.ip_p == IPPROTO_ICMP then if ip.icmp_type ~= 3 then return "recap" end -- Port Unreachable if ip.icmp_code == 3 then local is = ip.buf:sub(ip.icmp_offset + 9) local ip2 = packet.Packet:new(is, is:len()) -- Check sent packet against ICMP payload if ip2.ip_p ~= IPPROTO_UDP or ip2.ip_p ~= orig.ip_p or ip2.ip_bin_src ~= orig.ip_bin_src or ip2.ip_bin_dst ~= orig.ip_bin_dst or sport(ip2) ~= sport(orig) or dport(ip2) ~= dport(orig) then return "recap" end return "gotreply" end -- Frag needed, DF set if ip.icmp_code == 4 then local val = ip:u16(ip.icmp_offset + 6) return "nextmtu", val end return "recap" end if ip.ip_p ~= orig.ip_p or ip.ip_bin_src ~= orig.ip_bin_dst or ip.ip_bin_dst ~= orig.ip_bin_src or dport(ip) ~= sport(orig) or sport(ip) ~= dport(orig) then