Skip to content

Instantly share code, notes, and snippets.

@jezman
Created February 13, 2018 14:18
Show Gist options
  • Save jezman/8789adb1ddf3d72d25426fe9f03951ee to your computer and use it in GitHub Desktop.
Save jezman/8789adb1ddf3d72d25426fe9f03951ee to your computer and use it in GitHub Desktop.
Brute forcing directories.
#!/usr/bin/ruby
require 'find'
require 'optparse'
options = {brute: nil, scan: nil, users: nil, dir_wl: 'wordlist.txt', log: nil, verbose: true}
def chech_exist(o, file, opts)
if File.exist?(file)
o = file
else
puts "Error: wordlist not found."
puts "\n"
puts opts
exit 1
end
end
OptionParser.new do |opt|
opt.program_name = "Brutedir."
opt.banner = 'Usage: ruby brutedir.rb [options]'
opt.on('-b', '--brute PATH', 'Bruteforce directory') { |path| options[:brute]=path }
opt.on('-s', '--scan PATH', 'Recursive list all files on directory') { |path| options[:scan]=path }
opt.on('-f', '--file PATH', 'Save output to file') { |log| options[:log]=log }
opt.on('-u', '--users arg1,arg2,arg3...', String, 'Users wordlist') { |usr| options[:users]=usr.split(',') }
opt.on('-w', '--wordlist PATH', 'Directory wordlist ') { |wl| chech_exist(options[:dir_wl], wl, opt) }
opt.on('-q', '--quiet', 'Don\'t print messages to stdout') { options[:verbose]=false }
opt.on('-v', '--verbose', 'Print messages to stdout') { options[:verbose]=true }
opt.on('-h', '--help', 'Displays Help') do
puts opt
puts "EXAMPLES:"
puts "\truby brutedir.rb -b /etc"
puts "\truby brutedir.rb -b /home -u jezman,freezer,oliver -w /tmp/dir_wordlist.txt"
puts "\truby brutedir.rb -s /home/jezman -f /tmp/report.log -v"
exit
end
end.parse!
def scan(options)
Find.find(options[:scan]) do |file|
if options[:log]
f = File.open(options[:log], 'a')
f.puts file
f.close
puts file if verb
else
puts file
end
end
end
def brute(options)
unless options[:brute].end_with?('/')
options[:brute] = options[:brute]+'/'
end
if options[:users]
options[:users].each do |usr|
usr = usr+'/'
dirs = File.open(options[:dir_wl], 'r')
dirs.each do |dir|
if Dir.exist?(options[:brute]+usr+dir.chomp)
if options[:log]
f = File.open(options[:log], 'a')
f.puts options[:brute]+usr+dir
f.close
puts options[:brute]+usr+dir if options[:verbose]
else
puts options[:brute]+usr+dir
end
end
end
end
else
dirs = File.open(options[:dir_wl], 'r')
dirs.each do |dir|
if Dir.exist?(options[:brute]+dir.chomp)
if options[:log]
f = File.open(options[:log], 'a')
f.puts options[:brute]+dir
f.close
puts options[:brute]+dir if options[:verbose]
else
puts options[:brute]+dir
end
end
end
dirs.close
end
end
brute(options) if options[:brute]
scan(options) if options[:scan]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment