diff --git a/scripts/anonFTP.nse b/scripts/anonFTP.nse index 6a683bbbe..84aa8c836 100644 --- a/scripts/anonFTP.nse +++ b/scripts/anonFTP.nse @@ -2,15 +2,15 @@ id="Anonymous FTP" description="Checks to see if a FTP server allows anonymous logins" -author = "ejlb " +author = "Eddie Bell " license = "See nmaps COPYING for licence" categories = {"intrusive"} portrule = function(host, port) - if port.number == 21 - and port.service == "ftp" + if (port.number == 21 + or port.service == "ftp") and port.protocol == "tcp" and port.state == "open" then @@ -22,23 +22,30 @@ end action = function(host, port) local socket = nmap.new_socket() - local result; + local result local status = true local isAnon = false - socket:connect(host.ip, port.number, port.protocol) - socket:send("USER anonymous\r\n") - socket:send("PASS IEUser@\r\n") + local err_catch = function() + socket:close() + end + + local try = nmap.new_try(err_catch()) + + socket:set_timeout(5000) + try(socket:connect(host.ip, port.number, port.protocol)) + try(socket:send("USER anonymous\n\r")) + try(socket:send("PASS IEUser@\n\r")) while status do status, result = socket:receive_lines(1); if string.match(result, "^230") then - isAnon = true; - break; + isAnon = true + break end end - socket:close(); + socket:close() if(isAnon) then return "FTP: Anonymous login allowed"