home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Networking / nmap-5.00-setup.exe / scripts / ftp-anon.nse < prev    next >
Text File  |  2009-07-06  |  1KB  |  49 lines

  1. description = [[
  2. Checks if an FTP server allows anonymous logins.
  3. ]]
  4.  
  5. ---
  6. -- @output
  7. -- |_ ftp-anon: Anonymous FTP login allowed
  8.  
  9. author = "Eddie Bell <ejlbell@gmail.com>"
  10. license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
  11. categories = {"default", "auth", "safe"}
  12.  
  13. require "shortport"
  14.  
  15. portrule = shortport.port_or_service(21, "ftp")
  16.  
  17. --- Connects to the FTP server and checks if the server allows anonymous logins.
  18. action = function(host, port)
  19.     local socket = nmap.new_socket()
  20.     local result
  21.     local status = true
  22.     local isAnon = false
  23.  
  24.     local err_catch = function()
  25.         socket:close()
  26.     end
  27.  
  28.     local try = nmap.new_try(err_catch)
  29.  
  30.     socket:set_timeout(5000)
  31.     try(socket:connect(host.ip, port.number, port.protocol))
  32.     try(socket:send("USER anonymous\r\n"))
  33.     try(socket:send("PASS IEUser@\r\n"))
  34.  
  35.         while status do
  36.         status, result = socket:receive_lines(1);
  37.         if string.match(result, "^230") then
  38.             isAnon = true
  39.             break
  40.         end
  41.     end
  42.  
  43.     socket:close()
  44.  
  45.     if(isAnon) then
  46.         return "Anonymous FTP login allowed"
  47.     end
  48. end
  49.