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

  1. description = [[
  2. Tries to log into a POP3 account by guessing usernames and passwords.
  3. ]]
  4.  
  5. ---
  6. -- @args pop3loginmethod The login method to use: <code>"USER"</code>
  7. -- (default), <code>"SASL-PLAIN"</code>, <code>"SASL-LOGIN"</code>,
  8. -- <code>"SASL-CRAM-MD5"</code>, or <code>"APOP"</code>.
  9.  
  10. author = "Philip Pickering <pgpickering@gmail.com>"
  11. license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
  12.  
  13. categories = {"intrusive", "auth"}
  14.  
  15. require 'pop3'
  16. require 'shortport'
  17. require 'unpwdb'
  18.  
  19. portrule = shortport.port_or_service({110}, "pop3")
  20.  
  21. action = function(host, port)
  22.    local pMeth = nmap.registry.args.pop3loginmethod
  23.    if (not pMeth) then pMeth = nmap.registry.pop3loginmethod end
  24.    if (not pMeth) then pMeth = method end
  25.    if (not pMeth) then pMeth = "USER" end
  26.  
  27.    local login
  28.    local additional
  29.  
  30.    local stat = pop3.stat
  31.  
  32.    if (pMeth == "USER") then 
  33.       login = pop3.login_user
  34.    elseif (pMeth == "SASL-PLAIN") then 
  35.       login = pop3.login_sasl_plain
  36.    elseif (pMeth == "SASL-LOGIN") then 
  37.       login = login_sasl_login
  38.    elseif (pMeth == "SASL-CRAM-MD5") then
  39.       login = login_sasl_crammd5
  40.    elseif (pMeth == "APOP") then 
  41.       login = login_apop     
  42.    end
  43.  
  44.  
  45.    local status
  46.    local line
  47.    local socket = nmap.new_socket()
  48.  
  49.    if not socket:connect(host.ip, port.number) then return end -- no connection
  50.    
  51.    status, line = socket:receive_lines(1)
  52.    if not stat(line) then return end -- no pop-connection
  53.  
  54.    local apopChallenge = string.match(line, "<[%p%w]+>") 
  55.    
  56.    if pMeth == "APOP" then 
  57.       additional = apopChallenge 
  58.    end
  59.    
  60.    local getUser
  61.  
  62.    status, getUser = unpwdb.usernames()
  63.    if (not status) then return end
  64.  
  65.    local currUser = getUser()
  66.    while currUser do
  67.       local getPW
  68.       status, getPW = unpwdb.passwords()
  69.       if (not status) then return end
  70.  
  71.       local currPw = getPW()
  72.  
  73.       while currPw do
  74.      local pstatus
  75.      local perror
  76.  
  77.      pstatus, perror = login(socket, currUser, currPw, additional)
  78.      
  79.      if (pstatus) then 
  80.         return currUser .. " : " .. currPw
  81.      elseif (perror == pop3.err.pwError) then
  82.         currPw = getPW()
  83.      elseif (perror == pop3.err.userError) then
  84.         currPw = nil
  85.      else
  86.         return
  87.      end
  88.       end
  89.       currUser = getUser()
  90.       getPW("reset")
  91.    end
  92.    return -- "wrong pw" 
  93.  
  94. end
  95.