Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- # encoding: utf-8
- # == RSMangler: Take a wordlist and mangle it
- #
- # RSMangler will take a wordlist and perform various manipulations on it similar to
- # those done by John the Ripper with a few extras, the main one being permutations mode
- # which takes each word in the list and combines it with the others to produce all
- # possible permutations (not combinations, order matters).
- #
- # See the README for full information
- #
- # Author:: Robin Wood (robin.wood@randomstorm.com)
- # Version:: 1.2
- # Copyright:: Copyright(c) 2010, RandomStorm Limited - www.randomstorm.com
- # Licence:: Creative Commons Attribution-Share Alike 2.0
- #
- require 'date'
- require 'getoptlong'
- opts = GetoptLong.new(
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
- [ '--file', '-f', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--perms', '-p', GetoptLong::NO_ARGUMENT ],
- [ '--double', '-d', GetoptLong::NO_ARGUMENT ],
- [ '--reverse', '-r', GetoptLong::NO_ARGUMENT ],
- [ '--leet', '-t', GetoptLong::NO_ARGUMENT ],
- [ '--full-leet', '-T', GetoptLong::NO_ARGUMENT ],
- [ '--capital', '-c', GetoptLong::NO_ARGUMENT ],
- [ '--upper', '-u', GetoptLong::NO_ARGUMENT ],
- [ '--lower', '-l', GetoptLong::NO_ARGUMENT ],
- [ '--swap', '-s', GetoptLong::NO_ARGUMENT ],
- [ '--ed', '-e', GetoptLong::NO_ARGUMENT ],
- [ '--ing', '-i', GetoptLong::NO_ARGUMENT ],
- [ '--punctuation', GetoptLong::NO_ARGUMENT ],
- [ '--years', "-y", GetoptLong::NO_ARGUMENT ],
- [ '--acronym', "-a", GetoptLong::NO_ARGUMENT ],
- [ '--common', "-C", GetoptLong::NO_ARGUMENT ],
- [ '--pnb', GetoptLong::NO_ARGUMENT ],
- [ '--pna', GetoptLong::NO_ARGUMENT ],
- [ '--nb', GetoptLong::NO_ARGUMENT ],
- [ '--na', GetoptLong::NO_ARGUMENT ],
- [ '--force', GetoptLong::NO_ARGUMENT ],
- [ "-v" , GetoptLong::NO_ARGUMENT ]
- )
- def good_call
- puts
- puts "Good call, either reduce the size of your word list or use the --perms option to disable permutations"
- puts
- exit
- end
- # fmt <
- def binaryincrement(binarray)
- index = binarray.size-1
- incremented = false
- while !incremented and index>=0
- if (binarray[index]==0)
- binarray[index] = 1
- incremented = true
- break
- else
- binarray[index]=0
- end
- index -= 1
- end
- return binarray
- end
- def leetvariations(word)
- count = word.count("e")+word.count("a")+word.count("o")+word.count("i")+word.count("l")
- variation = Array.new(count,0)
- leetletterpos = Array.new(count,0)
- variationarr = []
- # Save the indexes where the leet letters can be substituted
- pos = 0
- iter = 0
- tmpword = word.dup
- while (!(pos=tmpword.index("a")).nil?)
- leetletterpos[iter] = pos
- tmpword[pos]="$"
- iter += 1
- end
- pos = 0
- while (!(pos=tmpword.index("e")).nil?)
- leetletterpos[iter] = pos
- tmpword[pos]="$"
- iter += 1
- end
- pos = 0
- while (!(pos=tmpword.index("i")).nil?)
- leetletterpos[iter] = pos
- tmpword[pos]="$"
- iter += 1
- end
- pos = 0
- while (!(pos=tmpword.index("o")).nil?)
- leetletterpos[iter] = pos
- tmpword[pos]="$"
- iter += 1
- end
- pos = 0
- while (!(pos=tmpword.index("l")).nil?)
- leetletterpos[iter] = pos
- tmpword[pos]="$"
- iter += 1
- end
- # Create all posible combinations of subtitutions
- begin
- tmpword = word.dup
- variation = binaryincrement(variation)
- idx = 0
- variation.each{|changeletter|
- if (changeletter==1)
- case tmpword[leetletterpos[idx],1]
- when "a" then tmpword[leetletterpos[idx],1] = "4"
- when "e" then tmpword[leetletterpos[idx],1] = "3"
- when "i" then tmpword[leetletterpos[idx],1] = "1"
- when "o" then tmpword[leetletterpos[idx],1] = "0"
- when "l" then tmpword[leetletterpos[idx],1] = "1"
- end
- end
- idx += 1
- }
- variationarr << tmpword
- end while (variation != Array.new(count,1))
- return variationarr
- end
- # > fmt
- # Display the usage
- def usage
- puts "rsmangler v 1.2 Robin Wood (robin.wood@randomstorm.com) <www.randomstorm.com> (modified by fmt)
- To pass the initial words in on standard in do:
- cat wordlist.txt | ./rsmangler.rb > new_wordlist.rb
- All options are ON by default, these parameters turn them OFF
- Usage: rsmangler.rb [OPTION]
- --help, -h: show help
- --file, -f: the input file, use - for STDIN
- --perms, -p: permutate all the words
- --double, -d: double each word
- --reverse, -r: reverser the word
- --leet, -t: l33t speak the word
- --full-leet, -T: all posibilities l33t
- --capital, -c: capitalise the word
- --upper, -u: uppercase the word
- --lower, -l: lowercase the word
- --swap, -s: swap the case of the word
- --ed, -e: add ed to the end of the word
- --ing, -i: add ing to the end of the word
- --punctuation: add common punctuation to the end of the word
- --years, -y: add all years from 1990 to current year to start and end
- --acronym, -a: create an acronym based on all the words entered in order and add to word list
- --common, -c: add the following words to start and end: admin, sys, pw, pwd
- --pna: add 01 - 09 to the end of the word
- --pnb: add 01 - 09 to the beginning of the word
- --na: add 1 - 123 to the end of the word
- --nb: add 1 - 123 to the beginning of the word
- --force - don't check ooutput size
- "
- exit
- end
- verbose=false
- leet=true
- full_leet=true
- perms=true
- double=true
- reverse=true
- capital=true
- upper=true
- lower=true
- swap=true
- ed=true
- ing=true
- punctuation=true
- years=true
- acronym=true
- common=true
- pna=true
- pnb=true
- na=true
- nb=true
- force=false
- file_handle = nil
- begin
- opts.each do |opt, arg|
- case opt
- when '--help'
- usage
- when '--file'
- if arg == "-"
- file_handle = STDIN
- else
- if File.exist? arg
- file_handle = File.new(arg, "r")
- else
- puts "The specified file does not exist"
- exit
- end
- end
- when "--leet"
- leet = false
- when "--full-leet"
- full_leet = false
- when "--perms"
- perms = false
- when "--double"
- double = false
- when "--reverse"
- reverse = false
- when "--capital"
- capital = false
- when "--upper"
- upper = false
- when "--lower"
- lower = false
- when "--swap"
- swap = false
- when "--ed"
- ed = false
- when "--ing"
- ing = false
- when "--common"
- common = false
- when "--acronym"
- acronym = false
- when "--years"
- years = false
- when "--punctuation"
- punctuation = false
- when "--pna"
- pna = false
- when "--pnb"
- pnb = false
- when "--na"
- na = false
- when "--nb"
- nb = false
- when "--force"
- force = true
- when '-v'
- verbose=true
- end
- end
- rescue => e
- puts e
- usage
- end
- if file_handle.nil?
- puts "No input file specified"
- puts
- usage
- exit
- end
- file_words = []
- while (x = file_handle.gets)
- x.chomp!
- file_words << x
- end
- file_handle.close
- if !force and perms and file_words.length > 5
- puts "5 words in a start list creates a dictionary of nearly 100,000 words."
- puts "You have " + file_words.length.to_s + " words in your list, are you sure you wish to continue?"
- puts "Hit ctrl-c to abort"
- puts
- interrupted = false
- trap("INT") { interrupted = true }
- 5.downto(1) { |i|
- print i.to_s + " "
- STDOUT.flush
- sleep 1
- if interrupted
- good_call
- end
- }
- if interrupted
- good_call
- end
- end
- wordlist = []
- if perms
- for i in (1..file_words.length)
- file_words.permutation(i) { |c| wordlist << c.to_s}
- end
- else
- wordlist = file_words
- end
- acro = nil
- if acronym
- acro = ""
- file_words.each { |c|
- acro += c[0, 1]
- }
- wordlist << acro
- end
- results = []
- wordlist.each { |x|
- results << x
- results << x+x if double
- results << x.reverse if reverse
- results << x.capitalize if capital
- results << x.downcase if lower
- results << x.upcase if upper
- results << x.swapcase if swap
- results << x + "ed" if ed
- results << x + "ing" if ing
- if common
- results << "pw" + x
- results << "pwd" + x
- results << "admin" + x
- results << "sys" + x
- results << x + "pw"
- results << x + "pwd"
- results << x + "admin"
- results << x + "sys"
- end
- results << x.gsub(/e/, "3").gsub(/a/, "4").gsub(/o/, "0").gsub(/i/, "1").gsub(/l/, "1") if leet
- # fmt <
- if full_leet
- leetarr = leetvariations(x)
- leetarr.each{|leetvar|
- results << leetvar
- }
- end
- # > fmt
- if punctuation
- for i in ("!@£$%^&*()".scan(/./))
- results << x + i.to_s
- end
- end
- if years
- for i in (1990..Date.today.year)
- results << i.to_s + x
- results << x + i.to_s
- end
- end
- if (pna or pnb)
- for i in (1..9)
- results << "0" + i.to_s + x if pnb
- results << x + "0" + i.to_s if pna
- end
- end
- if (na or nb)
- for i in (1..123)
- results << i.to_s + x if nb
- results << x + i.to_s if na
- end
- end
- }
- results.uniq!
- puts results
Add Comment
Please, Sign In to add comment