Skip to content

Instantly share code, notes, and snippets.

@bradkrane
Created October 5, 2022 03:07
Show Gist options
  • Save bradkrane/5101a1afcdc3f02a1ead0119f0cf046f to your computer and use it in GitHub Desktop.
Save bradkrane/5101a1afcdc3f02a1ead0119f0cf046f to your computer and use it in GitHub Desktop.
Quick script to select subset of password list
#!/usr/bin/ruby
# ruby this.rb <wordlist> <command> <param> [cmd]
# Ex. C:\Users\Brad Krane\Documents\src\pwd>ruby pwd.rb 10-million-password-list-top-1000000.txt letters 5 "echo Weak PWD"
#Weak password
#Weak qwerty
#Weak dragon
#Weak baseball
#Weak football
throw ArgumentError.new "Invalid aruments: #{ARGV}\nruby this.rb <wordlist> <command> <param> [cmd]" if ARGV.length > 4 || ARGV.length < 3
FILE=ARGV.shift
CMD=ARGV.shift.downcase
PARAM=ARGV.shift.to_i
SHCMD=ARGV.shift
pwds = File.readlines(FILE,chomp:true)
selected = case CMD
when 'random'
pwds.shuffle[0..PARAM-1]
when 'length'
pwds.select { |pwd| pwd.length == PARAM }
when 'first'
pwds[0..PARAM-1]
when 'last'
pwds[-PARAM..-1]
when 'letters'
pwds.select { |pwd|
begin
pwd.gsub(/[a-z]/i,'') == ''
rescue => e
false
end
}[0..PARAM-1]
when 'numbers'
pwds.select { |pwd|
begin
pwd.gsub(/[0-9]/i,'') == ''
rescue => e
false
end
}[0..PARAM-1]
when 'lessthan'
pwds.select { |pwd| pwd.length < PARAM }
when 'greaterthan'
pwds.select { |pwd| pwd.length > PARAM }
else
throw ArgumentError.new "Unknown command: #{CMD}"
end
if SHCMD == nil
selected.each { |pwd| print "#{pwd}\n" }
else
selected.each { |pwd| system "#{SHCMD.sub('PWD', pwd)}\n" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment