felmoltor

RSmangle leet enhancement - https://twitter.com/felmoltor

Sep 17th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.51 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. # encoding: utf-8
  3. # == RSMangler: Take a wordlist and mangle it
  4. #
  5. # RSMangler will take a wordlist and perform various manipulations on it similar to
  6. # those done by John the Ripper with a few extras, the main one being permutations mode
  7. # which takes each word in the list and combines it with the others to produce all
  8. # possible permutations (not combinations, order matters).
  9. #
  10. # See the README for full information
  11. #
  12. # Author:: Robin Wood (robin.wood@randomstorm.com)
  13. # Version:: 1.2
  14. # Copyright:: Copyright(c) 2010, RandomStorm Limited - www.randomstorm.com
  15. # Licence:: Creative Commons Attribution-Share Alike 2.0
  16. #
  17.  
  18. require 'date'
  19. require 'getoptlong'
  20.  
  21. opts = GetoptLong.new(
  22.     [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
  23.     [ '--file', '-f', GetoptLong::REQUIRED_ARGUMENT ],
  24.     [ '--perms', '-p', GetoptLong::NO_ARGUMENT ],
  25.     [ '--double', '-d', GetoptLong::NO_ARGUMENT ],
  26.     [ '--reverse', '-r', GetoptLong::NO_ARGUMENT ],
  27.     [ '--leet', '-t', GetoptLong::NO_ARGUMENT ],
  28.     [ '--full-leet', '-T', GetoptLong::NO_ARGUMENT ],
  29.     [ '--capital', '-c', GetoptLong::NO_ARGUMENT ],
  30.     [ '--upper', '-u', GetoptLong::NO_ARGUMENT ],
  31.     [ '--lower', '-l', GetoptLong::NO_ARGUMENT ],
  32.     [ '--swap', '-s', GetoptLong::NO_ARGUMENT ],
  33.     [ '--ed', '-e', GetoptLong::NO_ARGUMENT ],
  34.     [ '--ing', '-i', GetoptLong::NO_ARGUMENT ],
  35.     [ '--punctuation', GetoptLong::NO_ARGUMENT ],
  36.     [ '--years', "-y", GetoptLong::NO_ARGUMENT ],
  37.     [ '--acronym', "-a",  GetoptLong::NO_ARGUMENT ],
  38.     [ '--common', "-C",  GetoptLong::NO_ARGUMENT ],
  39.     [ '--pnb',  GetoptLong::NO_ARGUMENT ],
  40.     [ '--pna',  GetoptLong::NO_ARGUMENT ],
  41.     [ '--nb', GetoptLong::NO_ARGUMENT ],
  42.     [ '--na', GetoptLong::NO_ARGUMENT ],
  43.     [ '--force', GetoptLong::NO_ARGUMENT ],
  44.     [ "-v" , GetoptLong::NO_ARGUMENT ]
  45. )
  46.  
  47. def good_call
  48.     puts
  49.     puts "Good call, either reduce the size of your word list or use the --perms option to disable permutations"
  50.     puts
  51.     exit
  52. end
  53.  
  54. # fmt <
  55. def binaryincrement(binarray)
  56.     index = binarray.size-1
  57.     incremented = false
  58.      while !incremented and index>=0
  59.         if (binarray[index]==0)
  60.             binarray[index] = 1
  61.             incremented = true
  62.             break
  63.         else
  64.             binarray[index]=0
  65.         end
  66.         index -= 1
  67.     end
  68.     return binarray
  69. end
  70.  
  71.  
  72. def leetvariations(word)
  73.     count = word.count("e")+word.count("a")+word.count("o")+word.count("i")+word.count("l")
  74.     variation = Array.new(count,0)
  75.     leetletterpos = Array.new(count,0)
  76.     variationarr = []
  77.     # Save the indexes where the leet letters can be substituted
  78.     pos = 0
  79.     iter = 0
  80.     tmpword = word.dup
  81.     while (!(pos=tmpword.index("a")).nil?)
  82.         leetletterpos[iter] = pos
  83.         tmpword[pos]="$"
  84.         iter += 1
  85.     end
  86.     pos = 0
  87.     while (!(pos=tmpword.index("e")).nil?)
  88.         leetletterpos[iter] = pos
  89.         tmpword[pos]="$"
  90.         iter += 1
  91.     end
  92.     pos = 0
  93.     while (!(pos=tmpword.index("i")).nil?)
  94.         leetletterpos[iter] = pos
  95.         tmpword[pos]="$"
  96.         iter += 1
  97.     end
  98.     pos = 0
  99.     while (!(pos=tmpword.index("o")).nil?)
  100.         leetletterpos[iter] = pos
  101.         tmpword[pos]="$"
  102.         iter += 1
  103.     end
  104.     pos = 0
  105.     while (!(pos=tmpword.index("l")).nil?)
  106.         leetletterpos[iter] = pos
  107.         tmpword[pos]="$"
  108.         iter += 1
  109.     end
  110.     # Create all posible combinations of subtitutions
  111.     begin
  112.         tmpword = word.dup
  113.         variation = binaryincrement(variation)
  114.         idx = 0
  115.         variation.each{|changeletter|
  116.             if (changeletter==1)
  117.                 case tmpword[leetletterpos[idx],1]
  118.                     when "a" then tmpword[leetletterpos[idx],1] = "4"
  119.                     when "e" then tmpword[leetletterpos[idx],1] = "3"
  120.                     when "i" then tmpword[leetletterpos[idx],1] = "1"
  121.                     when "o" then tmpword[leetletterpos[idx],1] = "0"
  122.                     when "l" then tmpword[leetletterpos[idx],1] = "1"
  123.                 end
  124.             end
  125.             idx += 1
  126.         }
  127.         variationarr << tmpword
  128.     end while (variation != Array.new(count,1))
  129.     return variationarr
  130. end
  131. # > fmt
  132.  
  133. # Display the usage
  134. def usage
  135.     puts "rsmangler v 1.2 Robin Wood (robin.wood@randomstorm.com) <www.randomstorm.com> (modified by fmt)
  136.  
  137. To pass the initial words in on standard in do:
  138.  
  139. cat wordlist.txt | ./rsmangler.rb > new_wordlist.rb
  140.  
  141. All options are ON by default, these parameters turn them OFF
  142.  
  143. Usage: rsmangler.rb [OPTION]
  144.     --help, -h: show help
  145.     --file, -f: the input file, use - for STDIN
  146.     --perms, -p: permutate all the words
  147.     --double, -d: double each word
  148.     --reverse, -r: reverser the word
  149.     --leet, -t: l33t speak the word
  150.     --full-leet, -T: all posibilities l33t
  151.     --capital, -c: capitalise the word
  152.     --upper, -u: uppercase the word
  153.     --lower, -l: lowercase the word
  154.     --swap, -s: swap the case of the word
  155.     --ed, -e: add ed to the end of the word
  156.     --ing, -i: add ing to the end of the word
  157.     --punctuation: add common punctuation to the end of the word
  158.     --years, -y: add all years from 1990 to current year to start and end
  159.     --acronym, -a: create an acronym based on all the words entered in order and add to word list
  160.     --common, -c: add the following words to start and end: admin, sys, pw, pwd
  161.     --pna: add 01 - 09 to the end of the word
  162.     --pnb: add 01 - 09 to the beginning of the word
  163.     --na: add 1 - 123 to the end of the word
  164.     --nb: add 1 - 123 to the beginning of the word
  165.     --force - don't check ooutput size
  166.  
  167. "
  168.     exit
  169. end
  170.  
  171. verbose=false
  172. leet=true
  173. full_leet=true
  174. perms=true
  175. double=true
  176. reverse=true
  177. capital=true
  178. upper=true
  179. lower=true
  180. swap=true
  181. ed=true
  182. ing=true
  183. punctuation=true
  184. years=true
  185. acronym=true
  186. common=true
  187. pna=true
  188. pnb=true
  189. na=true
  190. nb=true
  191. force=false
  192. file_handle = nil
  193.  
  194. begin
  195.     opts.each do |opt, arg|
  196.         case opt
  197.         when '--help'
  198.             usage
  199.         when '--file'
  200.             if arg == "-"
  201.                 file_handle = STDIN
  202.             else
  203.                 if File.exist? arg
  204.                     file_handle = File.new(arg, "r")
  205.                 else
  206.                     puts "The specified file does not exist"
  207.                     exit
  208.                 end
  209.             end
  210.         when "--leet"
  211.             leet = false
  212.         when "--full-leet"
  213.             full_leet = false
  214.         when "--perms"
  215.             perms = false
  216.         when "--double"
  217.             double = false
  218.         when "--reverse"
  219.             reverse = false
  220.         when "--capital"
  221.             capital = false
  222.         when "--upper"
  223.             upper = false
  224.         when "--lower"
  225.             lower = false
  226.         when "--swap"
  227.             swap = false
  228.         when "--ed"
  229.             ed = false
  230.         when "--ing"
  231.             ing = false
  232.         when "--common"
  233.             common = false
  234.         when "--acronym"
  235.             acronym = false
  236.         when "--years"
  237.             years = false
  238.         when "--punctuation"
  239.             punctuation = false
  240.         when "--pna"
  241.             pna = false
  242.         when "--pnb"
  243.             pnb = false
  244.         when "--na"
  245.             na = false
  246.         when "--nb"
  247.             nb = false
  248.         when "--force"
  249.             force = true
  250.         when '-v'
  251.             verbose=true
  252.         end
  253.     end
  254. rescue => e
  255.     puts e
  256.     usage
  257. end
  258.  
  259. if file_handle.nil?
  260.     puts "No input file specified"
  261.     puts
  262.     usage
  263.     exit
  264. end
  265.  
  266. file_words = []
  267. while (x = file_handle.gets)
  268.     x.chomp!
  269.     file_words << x
  270. end
  271.  
  272. file_handle.close
  273.  
  274. if !force and perms and file_words.length > 5
  275.     puts "5 words in a start list creates a dictionary of nearly 100,000 words."
  276.     puts "You have " + file_words.length.to_s + " words in your list, are you sure you wish to continue?"
  277.     puts "Hit ctrl-c to abort"
  278.     puts
  279.  
  280.     interrupted = false
  281.     trap("INT") { interrupted = true }
  282.  
  283.     5.downto(1) { |i|
  284.         print i.to_s + " "
  285.         STDOUT.flush
  286.         sleep 1
  287.  
  288.         if interrupted
  289.             good_call
  290.         end
  291.     }
  292.  
  293.     if interrupted
  294.         good_call
  295.     end
  296. end
  297.  
  298. wordlist = []
  299.  
  300. if perms
  301.     for i in (1..file_words.length)
  302.         file_words.permutation(i) { |c| wordlist << c.to_s}
  303.     end
  304. else
  305.     wordlist = file_words
  306. end
  307.  
  308. acro = nil
  309.  
  310. if acronym
  311.     acro = ""
  312.     file_words.each { |c|
  313.         acro += c[0, 1]
  314.     }
  315.     wordlist << acro
  316. end
  317.  
  318. results = []
  319.  
  320. wordlist.each { |x|
  321.     results << x
  322.  
  323.     results << x+x if double
  324.     results << x.reverse if reverse
  325.     results << x.capitalize if capital
  326.     results << x.downcase if lower
  327.     results << x.upcase if upper
  328.     results << x.swapcase if swap
  329.     results << x + "ed" if ed
  330.     results << x + "ing" if ing
  331.  
  332.     if common
  333.         results << "pw" + x
  334.         results << "pwd" + x
  335.         results << "admin" + x
  336.         results << "sys" + x
  337.         results << x + "pw"
  338.         results << x + "pwd"
  339.         results << x + "admin"
  340.         results << x + "sys"
  341.     end
  342.    
  343.     results << x.gsub(/e/, "3").gsub(/a/, "4").gsub(/o/, "0").gsub(/i/, "1").gsub(/l/, "1") if leet
  344.     # fmt <
  345.     if full_leet
  346.         leetarr = leetvariations(x)
  347.         leetarr.each{|leetvar|
  348.             results << leetvar 
  349.         }
  350.     end
  351.     # > fmt
  352.  
  353.     if punctuation
  354.         for i in ("!@£$%^&*()".scan(/./))
  355.             results << x + i.to_s
  356.         end
  357.     end
  358.  
  359.     if years
  360.         for i in (1990..Date.today.year)
  361.             results << i.to_s + x
  362.             results << x + i.to_s
  363.         end
  364.     end
  365.  
  366.     if (pna or pnb)
  367.         for i in (1..9)
  368.             results << "0" + i.to_s + x if pnb
  369.             results << x + "0" + i.to_s if pna
  370.         end
  371.     end
  372.  
  373.     if (na or nb)
  374.         for i in (1..123)
  375.             results << i.to_s + x if nb
  376.             results << x + i.to_s if na
  377.         end
  378.     end
  379. }
  380.  
  381. results.uniq!
  382.  
  383. puts results
Add Comment
Please, Sign In to add comment