我有一个方法,扫描包含错误的网站的URL:
def begin_vulnerability_check
info("Checking if sites are vulnerable.")
IO.read("#{PATH}/temp/SQL_sites_to_check.txt").each_line do |parse|
Timeout::timeout(10) do
parsing = Nokogiri::HTML(RestClient.get("#{parse.chomp}"))
info("Parsing page for SQL syntax error: #{parse.chomp}")
if parsing.css('html')[0].to_s[/You have an error in your SQL syntax/]
successful = parse
success("URL: #{parse.chomp} returned SQL syntax error, dumped to SQL_VULN.txt")
File.open("#{PATH}/lib/SQL_VULN.txt", "a+"){|s| s.puts(parse)}
sleep(1)
else
err("URL: #{parse.chomp} returned and error, dumped to non_exploitable.txt")
File.open("#{PATH}/lib/non_exploitable.txt", "a+"){|s| s.puts(parse)}
sleep(1)
end
end
end
end
在测试过程中,我扫描了以下URL列表:
http://www.bible.com/subcat.php?id=2'
http://www.cidko.com/pro_con.php?id=3'
http://www.slavsandtars.com/about.php?id=25'
http://www.police.gov/content.php?id=275'
http://www.icdprague.org/index.php?id=10'
http://huawei.com/en/plugin.php?id=hwdownload'
https://huawei.com/en/plugin.php?id=unlock'
https://facebook.com/profile.php?id'
http://www.footballclub.com.au/index.php?id=43'
http://www.mesrs.gouv/index.php?id=1525'
我还有一个救援块,它假设捕获异常Timeout::Error
并移动到列表中的下一个URL:
begin
begin_vulnerability_check
rescue Timeout::Error
if Timeout::Error
warn("Page timed out, this is usually cause by the page returning a white page, or being non-existent, skipping.")
next
end
end
然而,当我试图运行这个程序时,我得到了以下错误:
whitewidow.rb:130: Invalid next
whitewidow.rb: compile error (SyntaxError)
第130行:
rescue Timeout::Error
if Timeout::Error
warn("Page timed out, this is usually cause by the page returning a white page, or being non-existent, skipping.")
next #<= HERE
end
end
我的问题是,我是否在错误的意义上使用了next
?在我看来,下一步应该是,如果这发生了,转到下一行,我这样想是不是错了?我如何重构它才能工作?
1条答案
按热度按时间hs1rzwqc1#
您可以使用
next
从块返回。你不能像你想的那样在街区外使用。但是您甚至不需要
next
,因为当您挽救超时错误时,迭代将自动继续下一行。您只需将rescue
移动到each_line
迭代中。你的代码应该是这样的: