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

  1. description = [[
  2. Tries to get FTP login credentials by guessing usernames and passwords.
  3. ]]
  4.  
  5. ---
  6. -- @output
  7. -- 21/tcp open  ftp
  8. -- |_ ftp-auth: Login success with u/p: nobody/xampp
  9. --
  10. -- 2008-11-06 Vlatko Kosturjak <kost@linux.hr>
  11. -- Modified xampp-default-auth script to generic ftp-brute script
  12.  
  13. author = "Diman Todorov <diman.todorov@gmail.com>"
  14.  
  15. license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
  16.  
  17. categories = {"auth", "intrusive"}
  18.  
  19. require "shortport"
  20.  
  21. portrule = shortport.port_or_service(21, "ftp")
  22.  
  23. login = function(socket, user, pass)
  24.     local status, err
  25.     local res = ""
  26.     status, err = socket:send("USER " .. user .. "\n")
  27.     status, err = socket:send("PASS " .. pass .. "\n")
  28.  
  29.     -- consume the banner and stuff
  30.     while true do
  31.         status, res = socket:receive_lines(1)
  32.         if 
  33.             not string.match(res, "^220") 
  34.             and not string.match(res, "^331 ") 
  35.         then
  36.             break
  37.         end
  38.     end
  39.  
  40.     -- are we logged in?
  41.     if string.match(res, "^230") then
  42.         return "Login success with u/p: " .. user .. "/" .. pass
  43.     end
  44. end
  45.  
  46. action = function(host, port)
  47.     local res
  48.     local socket = nmap.new_socket()
  49.     local authcombinations = { 
  50.         {user="nobody", password="xampp"}, --- XAMPP default ftp
  51.     }
  52.  
  53.     for _, combination in pairs (authcombinations) do
  54.         socket:connect(host.ip, port.number)
  55.         res = login(socket, combination.user, combination.password)
  56.         socket:close()
  57.     end
  58.     
  59.     return  res
  60. end
  61.  
  62.