Index: brute.lua
===================================================================
--- brute.lua	(revision 33885)
+++ brute.lua	(working copy)
@@ -497,7 +497,7 @@
         end
 
         local msg = ( retries ~= self.options.max_retries ) and "Re-trying" or "Trying"
-        stdnse.debug2("%s %s against %s:%d", msg, c, self.host.ip, self.port.number )
+        stdnse.debug("%s %s against %s:%d", msg, c, self.host.ip, self.port.number )
         status, response = driver:login( username, password )
 
         driver:disconnect()
@@ -621,7 +621,7 @@
     end
 
     local mode = self.options.mode or stdnse.get_script_args("brute.mode")
-
+    local mangling_rules = stdnse.get_script_args("brute.mangling-rule") or "all"
     -- if no mode was given, but a credfile is present, assume creds mode
     if ( not(mode) and stdnse.get_script_args("brute.credfile") ) then
       if ( stdnse.get_script_args("userdb") or
@@ -657,6 +657,8 @@
       self.iterator = self.iterator or Iterators.user_pw_iterator( usernames, passwords )
     elseif( mode and mode == 'pass' ) then
       self.iterator = self.iterator or Iterators.pw_user_iterator( usernames, passwords )
+    elseif( mode and mode == 'pass-mangling' ) then
+      self.iterator = self.iterator or Iterators.pw_mangling_iterator( usernames, passwords, mangling_rules )
     elseif ( mode ) then
       return false, ("Unsupported mode: %s"):format(mode)
       -- Default to the pw_user_iterator in case no iterator was specified
@@ -839,7 +841,65 @@
     end
     return coroutine.wrap( next_credential )
   end,
+  pw_mangling_iterator = function( users, passwords, rule)
+    local function next_credential ()
+      for user, pass in Iterators.account_iterator(users, passwords, "pass") do
+        if rule == 'digits' or rule == 'all' then
+          -- Current year, next year, 5 years back...
+          local year = tonumber(os.date("%Y"))
+          coroutine.yield( user, pass..year )
+          coroutine.yield( user, pass..year+1 )
+          for i = year, year-5, -1 do
+            coroutine.yield( user, pass..i )
+          end
 
+          -- Digits from 0 to 9
+          for i = 0, 9 do
+            coroutine.yield( user, pass..i )
+          end 
+          -- Digits from 00 to 99
+          for i = 0, 9 do
+            for x = 0, 9 do
+              coroutine.yield( user, pass..i..x )
+            end
+          end
+
+          -- Common digit combos
+          coroutine.yield( user, pass.."123" )
+          coroutine.yield( user, pass.."1234" )
+          coroutine.yield( user, pass.."12345" )
+        end
+        if rule == 'strings' or rule == 'all' then
+          -- Basic string stuff like uppercase, 
+          -- reverse, camelization and repetition
+          local leetify = {["a"] = '4',
+                           ["e"] = '3',
+                           ["i"] = '1',
+                           ["o"] = '0'}
+          local leetified_pass = pass:gsub("%a", leetify) 
+          coroutine.yield( user, leetified_pass )
+          coroutine.yield( user, pass:upper() )
+          coroutine.yield( user, leetified_pass:upper() )
+          coroutine.yield( user, pass:lower() )
+          coroutine.yield( user, pass:reverse() )
+          coroutine.yield( user, pass:sub(1,1):upper()..pass:sub(2) )
+          coroutine.yield( user, leetified_pass:sub(1,1):upper()..leetified_pass:sub(2) )
+          coroutine.yield( user, pass:rep(2) )
+          coroutine.yield( user, pass:rep(3) )
+        end
+        if rule == 'special' or rule == 'all' then
+          -- Common special characters like $,#,!
+          coroutine.yield( user, pass..'$' )
+          coroutine.yield( user, pass..'#' )
+          coroutine.yield( user, pass..'!' )
+          coroutine.yield( user, pass..'.' )
+          coroutine.yield( user, pass..'@' )
+        end
+      end
+      while true do coroutine.yield(nil, nil) end
+    end
+    return coroutine.wrap( next_credential )
+  end,
   --- An iterator that returns the username and uppercase password
   --
   -- @param users table containing list of users
