限制可以挽救的错误数量



我有一个程序,我正在使用它作为测试工具,我正在发现网站是否存在SQL漏洞,并遇到了Timeout::Error。现在我已经尝试挽救这个错误,但还有一些其他错误也需要挽救。所以我的问题是,在一个救援区块内可以挽救的错误数量有限制吗?如果不是,为什么这个Timeout没有得到拯救?

来源:

def get_urls
  info("Searching for possible SQL vulnerable sites.")
  @agent = Mechanize.new
  page = @agent.get('http://www.google.com/')
  google_form = page.form('f')
  google_form.q = "#{SEARCH}"
  url = @agent.submit(google_form, google_form.buttons.first)
  url.links.each do |link|
    if link.href.to_s =~ /url.q/
      str = link.href.to_s
      str_list = str.split(%r{=|&})
      urls = str_list[1]
      next if str_list[1].split('/')[2] == "webcache.googleusercontent.com"
      urls_to_log = urls.gsub("%3F", '?').gsub("%3D", '=')
      success("Site found: #{urls_to_log}")
      File.open("#{PATH}/temp/SQL_sites_to_check.txt", "a+") {|s| s.puts("#{urls_to_log}'")}
    end
  end
  info("Possible vulnerable sites dumped into #{PATH}/temp/SQL_sites.txt")
end
def check_if_vulnerable
  info("Checking if sites are vulnerable.")
  IO.read("#{PATH}/temp/SQL_sites_to_check.txt").each_line do |parse|
    Timeout::timeout(5) do
      begin
        @parsing = Nokogiri::HTML(RestClient.get("#{parse.chomp}")) 
      rescue Timeout::Error, RestClient::ResourceNotFound, RestClient::SSLCertificateNotVerified
        if RestClient::ResourceNotFound
          warn("URL: #{parse.chomp} returned 404 error, URL dumped into 404 bin")
          File.open("#{PATH}/lib/404_bin.txt", "a+"){|s| s.puts(parse)}
        elsif RestClient::SSLCertificateNotVerified
          err("URL: #{parse.chomp} requires SSL cert, url dumped into SSL bin")
          File.open("#{PATH}/lib/SSL_bin.txt", "a+"){|s| s.puts(parse)}
        elsif Timeout::Error
          warn("URL: #{parse.chomp} failed to load resulting in time out after 10 seconds. URL dumped into TIMEOUT bin")
          File.open("#{PATH}/lib/TIMEOUT_bin.txt", "a+"){|s| s.puts(parse)}
        end
      end
    end
  end
end

错误:

C:/Ruby22/lib/ruby/2.2.0/net/http.rb:892:in `new': execution expired (Timeout::E
rror)
        from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:892:in `connect'
        from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
        from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:852:in `start'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0-x86-mingw32/li
b/restclient/request.rb:413:in `transmit'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0-x86-mingw32/li
b/restclient/request.rb:176:in `execute'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0-x86-mingw32/li
b/restclient/request.rb:41:in `execute'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0-x86-mingw32/li
b/restclient.rb:65:in `get'
        from whitewidow.rb:94:in `block (2 levels) in check_if_vulnerable'
        from C:/Ruby22/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout'
        from C:/Ruby22/lib/ruby/2.2.0/timeout.rb:32:in `block in catch'
        from C:/Ruby22/lib/ruby/2.2.0/timeout.rb:32:in `catch'
        from C:/Ruby22/lib/ruby/2.2.0/timeout.rb:32:in `catch'
        from C:/Ruby22/lib/ruby/2.2.0/timeout.rb:103:in `timeout'
        from whitewidow.rb:92:in `block in check_if_vulnerable'
        from whitewidow.rb:91:in `each_line'
        from whitewidow.rb:91:in `check_if_vulnerable'
        from whitewidow.rb:113:in `<main>'

正如您在check_vulns方法中看到的那样,我已经挽救了Timeout::Error。那么,是什么原因导致它在没有移动到下一个URL的情况下超时呢?我已经尝试添加next进行救援,但仍然不起作用,请帮忙?

只需移动Timeout,我就可以挽救错误

def check_if_vulnerable
  info("Checking if sites are vulnerable.")
  IO.read("#{PATH}/temp/SQL_sites_to_check.txt").each_line do |parse|
      begin
        Timeout::timeout(5) do
          @parsing = Nokogiri::HTML(RestClient.get("#{parse.chomp}")) 
        end
      rescue Timeout::Error, RestClient::ResourceNotFound, RestClient::SSLCertificateNotVerified
        if RestClient::ResourceNotFound
          warn("URL: #{parse.chomp} returned 404 error, URL dumped into 404 bin")
          File.open("#{PATH}/lib/404_bin.txt", "a+"){|s| s.puts(parse)}
        elsif RestClient::SSLCertificateNotVerified
          err("URL: #{parse.chomp} requires SSL cert, url dumped into SSL bin")
          File.open("#{PATH}/lib/SSL_bin.txt", "a+"){|s| s.puts(parse)}
        elsif Timeout::Error
          warn("URL: #{parse.chomp} failed to load resulting in time out after 10 seconds. URL dumped into TIMEOUT bin")
          File.open("#{PATH}/lib/TIMEOUT_bin.txt", "a+"){|s| s.puts(parse)}
        end
      end
    end
  end
end

相关内容

  • 没有找到相关文章

最新更新