使用Ruby的OptParse

时间:2016-12-28 19:39:31

标签: ruby argv optparse

由于程序的大小,我将无法发布所有内容,请参阅最新推文here

我有一个程序,里面有大约15个选项标记:

ARGV << '-h' if ARGV.empty? # Display help dialog if no flags are passed
OptionParser.new do |opt|
  opt.banner = banner_message
  opt.on('-f FILE', '--file FILE', 'Pass a filename to scan for vulnerabilities')         { |o| OPTIONS[:file]    = o }
  opt.on('-s URL', '--spider URL', 'Spider a web page and save all the URLS')             { |o| OPTIONS[:spider]  = o }
  opt.on('-p IP:PORT', '--proxy IP:PORT', 'Configure to run with a proxy, must use ":"')  { |o| OPTIONS[:proxy]   = o }
  opt.on('-x NUM', '--run-x NUM', 'Run the specified amount of dry runs')                 { |o| OPTIONS[:run]     = o }
  opt.on('-D DORK', '--dork DORK', 'Use your own dork to do the searching')               { |o| OPTIONS[:dork]    = o } # Issue #32 https://github.com/Ekultek/whitewidow/issues/32
  opt.on('-c NAME', '--column NAME', 'Specify a column name to be run for union SQLi')    { |o| OPTIONS[:cols]    = o }
  opt.on('-d', '--default', 'Run in default mode, scrape Google')                         { |o| OPTIONS[:default] = o }
  opt.on('-l', '--legal', 'Show the legal information and the TOS')                       { |o| OPTIONS[:legal]   = o }
  opt.on('-b', '--banner', 'Hide the banner')                                             { |o| OPTIONS[:banner]  = o }
  opt.on('-v', '--version', 'Display the version number and exit')                        { |o| OPTIONS[:version] = o }
  opt.on('-u', '--update', 'Update whitewidow with the newest version')                   { |o| OPTIONS[:update]  = o }
  opt.on('--dry-run', 'Run a dry run (no checking for vulnerability with prompt)')        { |o| OPTIONS[:dry]     = o }
  opt.on('--batch', 'No prompts, used in conjunction with the dry run')                   { |o| OPTIONS[:batch]   = o }
  opt.on('--beep', 'Make a beep when the program finds a vulnerability')                  { |o| OPTIONS[:beep]    = o }
  opt.on('--rand-agent', 'Use a random user agent')                                       { |o| OPTIONS[:agent]   = o }
  opt.on('--sqlmap', 'Run sqlmap through the SQL_VULN.LOG file as a bulk file')           { |o| OPTIONS[:sqlmap]  = o }
  opt.on('--test', 'Used mostly for development use')                                     { |o| OPTIONS[:test]    = o }
  opt.on('-h', '--help', 'Display this help dialog and exit') do
    usage_page
    puts opt
  end
end.parse!

最新的选项是-c标志,我要做的是从-c标志获取信息并将其用作信息的提取点,但是,当我运行时标志,它只会从默认文件中提取信息:

#
# Decide whether to use random column names, or a specific one
#
def random_col_name?
  if OPTIONS[:cols]
    OPTIONS[:cols]
  else
    File.readlines("#{PATH}/lib/lists/common_columns.txt").sample
  end
end

例如: ruby program.rb -d -c test -D php?id=http://www.bible-history.com/subcat.php?id=2拉出来是正确的,从那里放入应该将-c标志中的信息添加到其末尾,如下所示:http://www.bible-history.com/subcat.php?id=2 test。但它所做的只是添加文件中的信息:http://www.bible-history.com/subcat.php?id=2 clave。我的问题是,为什么当我尝试从标志中提取信息时,它不接受ARGV并且只读取文件,我可以创建的选项数量是否有限制? / p>

0 个答案:

没有答案