fix some code styling issues

This commit is contained in:
Christian Mehlmauer
2015-06-21 10:59:57 +02:00
parent e03f7691f2
commit f4f1390b67
24 changed files with 439 additions and 439 deletions

View File

@@ -23,7 +23,7 @@ end
html = open(html_path).read html = open(html_path).read
examples = html.match(/(\d+) examples/)[0].to_i rescue 0 examples = html.match(/(\d+) examples/)[0].to_i rescue 0
errors = html.match(/(\d+) errors/)[0].to_i rescue 0 errors = html.match(/(\d+) errors/)[0].to_i rescue 0
if errors == 0 then if errors == 0
errors = html.match(/(\d+) failure/)[0].to_i rescue 0 errors = html.match(/(\d+) failure/)[0].to_i rescue 0
end end
pending = html.match(/(\d+) pending/)[0].to_i rescue 0 pending = html.match(/(\d+) pending/)[0].to_i rescue 0

View File

@@ -14,7 +14,7 @@ class WpItems < Array
self.wp_target = wp_target self.wp_target = wp_target
end end
# @param [String] argv # @param [String] args
# #
# @return [ void ] # @return [ void ]
def add(*args) def add(*args)

View File

@@ -32,7 +32,7 @@ class WpItems < Array
progress_bar.progress += 1 if options[:show_progression] progress_bar.progress += 1 if options[:show_progression]
if target_item.exists?(exist_options, response) if target_item.exists?(exist_options, response)
if !results.include?(target_item) unless results.include?(target_item)
if !options[:only_vulnerable] || options[:only_vulnerable] && target_item.vulnerable? if !options[:only_vulnerable] || options[:only_vulnerable] && target_item.vulnerable?
results << target_item results << target_item
end end

View File

@@ -41,7 +41,7 @@ $LOAD_PATH.unshift(MODELS_LIB_DIR)
def kali_linux? def kali_linux?
begin begin
File.readlines("/etc/debian_version").grep(/^kali/i).any? File.readlines('/etc/debian_version').grep(/^kali/i).any?
rescue rescue
false false
end end
@@ -54,7 +54,7 @@ def require_files_from_directory(absolute_dir_path, files_pattern = '*.rb')
files = Dir[File.join(absolute_dir_path, files_pattern)] files = Dir[File.join(absolute_dir_path, files_pattern)]
# Files in the root dir are loaded first, then those in the subdirectories # Files in the root dir are loaded first, then those in the subdirectories
files.sort_by { |file| [file.count("/"), file] }.each do |f| files.sort_by { |file| [file.count('/'), file] }.each do |f|
f = File.expand_path(f) f = File.expand_path(f)
#puts "require #{f}" # Used for debug #puts "require #{f}" # Used for debug
require f require f
@@ -82,7 +82,7 @@ end
def update_required? def update_required?
return true unless File.exist?(LAST_UPDATE_FILE) return true unless File.exist?(LAST_UPDATE_FILE)
content = File.read(LAST_UPDATE_FILE) content = File.read(LAST_UPDATE_FILE)
date = Time.parse(content) rescue Time.parse("2000-01-01") date = Time.parse(content) rescue Time.parse('2000-01-01')
return date < 5.days.ago return date < 5.days.ago
end end

View File

@@ -3,7 +3,7 @@
class HttpError < StandardError class HttpError < StandardError
attr_reader :response attr_reader :response
# @param [ Typhoeus::Response ] res # @param [ Typhoeus::Response ] response
def initialize(response) def initialize(response)
@response = response @response = response
end end

View File

@@ -78,7 +78,7 @@ module Terminal
class Style class Style
@@defaults = { @@defaults = {
:border_x => "-", :border_y => "|", :border_i => "+", :border_x => '-', :border_y => '|', :border_i => '+',
:padding_left => 1, :padding_right => 1, :padding_left => 1, :padding_right => 1,
:margin_left => '', :margin_left => '',
:width => nil, :alignment => nil :width => nil, :alignment => nil
@@ -102,7 +102,7 @@ class Numeric
def bytes_to_human def bytes_to_human
units = %w{B KB MB GB TB} units = %w{B KB MB GB TB}
e = (Math.log(self)/Math.log(1024)).floor e = (Math.log(self)/Math.log(1024)).floor
s = "%.3f" % (to_f / 1024**e) s = '%.3f' % (to_f / 1024**e)
s.sub(/\.?0*$/, ' ' + units[e]) s.sub(/\.?0*$/, ' ' + units[e])
end end
end end

View File

@@ -15,8 +15,8 @@ class Vulnerability
puts " Reference: #{url}" if url puts " Reference: #{url}" if url
end end
end end
if !fixed_in.nil? unless fixed_in.nil?
puts notice("Fixed in: #{fixed_in}") puts notice("Fixed in: #{fixed_in}")
end end
end end
end end

View File

@@ -22,7 +22,7 @@ class WpItem
# @return [ String ] # @return [ String ]
def to_s def to_s
item_version = self.version item_version = self.version
"#@name#{' - v' + item_version.strip if item_version}" "#{@name}#{' - v' + item_version.strip if item_version}"
end end
# Extracts the version number from a given string/body # Extracts the version number from a given string/body

View File

@@ -14,7 +14,7 @@ class WpTheme < WpItem
def get_parent_theme_style_url def get_parent_theme_style_url
if is_child_theme? if is_child_theme?
return style_url.sub("/#{name}/style.css", "/#@theme_template/style.css") return style_url.sub("/#{name}/style.css", "/#{@theme_template}/style.css")
end end
nil nil
end end

View File

@@ -10,16 +10,16 @@ class WpTheme
theme_desc = verbose ? @theme_description : truncate(@theme_description, 100) theme_desc = verbose ? @theme_description : truncate(@theme_description, 100)
puts " | Style URL: #{style_url}" puts " | Style URL: #{style_url}"
puts " | Referenced style.css: #{referenced_url}" if referenced_url && referenced_url != style_url puts " | Referenced style.css: #{referenced_url}" if referenced_url && referenced_url != style_url
puts " | Theme Name: #@theme_name" if @theme_name puts " | Theme Name: #{@theme_name}" if @theme_name
puts " | Theme URI: #@theme_uri" if @theme_uri puts " | Theme URI: #{@theme_uri}" if @theme_uri
puts " | Description: #{theme_desc}" puts " | Description: #{theme_desc}"
puts " | Author: #@theme_author" if @theme_author puts " | Author: #{@theme_author}" if @theme_author
puts " | Author URI: #@theme_author_uri" if @theme_author_uri puts " | Author URI: #{@theme_author_uri}" if @theme_author_uri
puts " | Template: #@theme_template" if @theme_template and verbose puts " | Template: #{@theme_template}" if @theme_template and verbose
puts " | License: #@theme_license" if @theme_license and verbose puts " | License: #{@theme_license}" if @theme_license and verbose
puts " | License URI: #@theme_license_uri" if @theme_license_uri and verbose puts " | License URI: #{@theme_license_uri}" if @theme_license_uri and verbose
puts " | Tags: #@theme_tags" if @theme_tags and verbose puts " | Tags: #{@theme_tags}" if @theme_tags and verbose
puts " | Text Domain: #@theme_text_domain" if @theme_text_domain and verbose puts " | Text Domain: #{@theme_text_domain}" if @theme_text_domain and verbose
end end
end end

View File

@@ -15,7 +15,7 @@ class WpTimthumb < WpItem
end end
def check_rce_132 def check_rce_132
return rce_132_vuln unless VersionCompare.lesser_or_equal?('1.33', version) rce_132_vuln unless VersionCompare.lesser_or_equal?('1.33', version)
end end
# Vulnerable versions : > 1.35 (or >= 2.0) and < 2.8.14 # Vulnerable versions : > 1.35 (or >= 2.0) and < 2.8.14
@@ -24,7 +24,7 @@ class WpTimthumb < WpItem
response = Browser.get(uri.merge('?webshot=1&src=http://' + default_allowed_domains.sample)) response = Browser.get(uri.merge('?webshot=1&src=http://' + default_allowed_domains.sample))
return rce_webshot_vuln unless response.body =~ /WEBSHOT_ENABLED == true/ rce_webshot_vuln unless response.body =~ /WEBSHOT_ENABLED == true/
end end
# @return [ Array<String> ] The default allowed domains (between the 2.0 and 2.8.13) # @return [ Array<String> ] The default allowed domains (between the 2.0 and 2.8.13)

View File

@@ -15,7 +15,7 @@ class WpUser < WpItem
# @return [ URI ] The uri to the author page # @return [ URI ] The uri to the author page
def uri def uri
if id if id
return @uri.merge("?author=#{id}") @uri.merge("?author=#{id}")
else else
raise 'The id is nil' raise 'The id is nil'
end end

View File

@@ -34,7 +34,7 @@ class WpUser < WpItem
# Generate a random one on each request # Generate a random one on each request
unless redirect_url unless redirect_url
random = (0...8).map { 65.+(rand(26)).chr }.join random = (0...8).map { 65.+(rand(26)).chr }.join
redirect_url = "#@uri#{random}/" redirect_url = "#{@uri}#{random}/"
end end
request = login_request(password, redirect_url) request = login_request(password, redirect_url)
@@ -66,7 +66,7 @@ class WpUser < WpItem
puts if options[:show_progression] # mandatory to avoid the output of the progressbar to be overriden puts if options[:show_progression] # mandatory to avoid the output of the progressbar to be overriden
end end
# @param [ Integer ] targets_size # @param [ Integer ] passwords_size
# @param [ Hash ] options # @param [ Hash ] options
# #
# @return [ ProgressBar ] # @return [ ProgressBar ]

View File

@@ -7,13 +7,13 @@ class WpTarget < WebSite
# #
# @return [ Boolean ] # @return [ Boolean ]
def has_full_path_disclosure? def has_full_path_disclosure?
response = Browser.get(full_path_disclosure_url()) response = Browser.get(full_path_disclosure_url)
response.body[%r{Fatal error}i] ? true : false response.body[%r{Fatal error}i] ? true : false
end end
def full_path_disclosure_data def full_path_disclosure_data
return nil unless has_full_path_disclosure? return nil unless has_full_path_disclosure?
Browser.get(full_path_disclosure_url()).body[%r{<b>([^<]+\.php)</b>}, 1] Browser.get(full_path_disclosure_url).body[%r{<b>([^<]+\.php)</b>}, 1]
end end
# @return [ String ] # @return [ String ]

View File

@@ -8,7 +8,7 @@ class WpTarget < WebSite
@login_protection_plugin = nil @login_protection_plugin = nil
def has_login_protection? def has_login_protection?
!login_protection_plugin().nil? !login_protection_plugin.nil?
end end
# Checks if a login protection plugin is enabled # Checks if a login protection plugin is enabled
@@ -74,7 +74,7 @@ class WpTarget < WebSite
# http://wordpress.org/extend/plugins/login-security-solution/ # http://wordpress.org/extend/plugins/login-security-solution/
def has_login_security_solution_protection? def has_login_security_solution_protection?
Browser.get(login_security_solution_url()).code != 404 Browser.get(login_security_solution_url).code != 404
end end
def login_security_solution_url def login_security_solution_url

View File

@@ -10,7 +10,7 @@ class WpTarget < WebSite
# #
# @return [ Boolean ] # @return [ Boolean ]
def has_readme? def has_readme?
response = Browser.get(readme_url()) response = Browser.get(readme_url)
unless response.code == 404 unless response.code == 404
return response.body =~ %r{wordpress}i ? true : false return response.body =~ %r{wordpress}i ? true : false

View File

@@ -64,7 +64,7 @@ describe Browser do
it 'raises an error' do it 'raises an error' do
File.symlink('./testfile', config_file) File.symlink('./testfile', config_file)
expect { browser.load_config(config_file) }.to raise_error("[ERROR] Config file is a symlink.") expect { browser.load_config(config_file) }.to raise_error('[ERROR] Config file is a symlink.')
File.unlink(config_file) File.unlink(config_file)
end end
end end

View File

@@ -92,7 +92,7 @@ describe CacheFileStore do
it 'should create a unique storage dir' do it 'should create a unique storage dir' do
storage_dirs = [] storage_dirs = []
(1..5).each do |i| (1..5).each do |_|
storage_dirs << CacheFileStore.new(cache_dir).storage_path storage_dirs << CacheFileStore.new(cache_dir).storage_path
end end

View File

@@ -121,7 +121,7 @@ describe 'WpTheme::Findable' do
end end
end end
stub_all_to_nil() stub_all_to_nil
expect { WpTheme.find(uri) }.to_not raise_error expect { WpTheme.find(uri) }.to_not raise_error
end end
@@ -129,7 +129,7 @@ describe 'WpTheme::Findable' do
context 'when the theme is not found' do context 'when the theme is not found' do
it 'returns nil' do it 'returns nil' do
stub_all_to_nil() stub_all_to_nil
expect(WpTheme.find(uri)).to be_nil expect(WpTheme.find(uri)).to be_nil
end end
@@ -137,7 +137,7 @@ describe 'WpTheme::Findable' do
context 'when the theme is found' do context 'when the theme is found' do
it 'returns it, with the :found_from set' do it 'returns it, with the :found_from set' do
stub_all_to_nil() stub_all_to_nil
stub_request(:get, /.+\/the-oracle\/style.css$/).to_return(status: 200) stub_request(:get, /.+\/the-oracle\/style.css$/).to_return(status: 200)
expected = WpTheme.new(uri, name: 'the-oracle') expected = WpTheme.new(uri, name: 'the-oracle')

View File

@@ -178,7 +178,7 @@ describe 'WpVersion::Findable' do
context 'when no version found' do context 'when no version found' do
it 'returns nil' do it 'returns nil' do
stub_all_to_nil() stub_all_to_nil
@expected = nil @expected = nil
end end
end end
@@ -188,8 +188,8 @@ describe 'WpVersion::Findable' do
found_from = method[/^find_from_(.*)/, 1].sub('_', ' ') found_from = method[/^find_from_(.*)/, 1].sub('_', ' ')
context "when found from #{found_from}" do context "when found from #{found_from}" do
it "returns the correct WpVersion" do it 'returns the correct WpVersion' do
stub_all_to_nil() stub_all_to_nil
allow(WpVersion).to receive(method).and_return(number) allow(WpVersion).to receive(method).and_return(number)

View File

@@ -17,7 +17,7 @@ describe 'WebSite' do
) )
end end
describe "#new" do describe '#new' do
its(:url) { is_expected.to be === 'http://example.localhost/' } its(:url) { is_expected.to be === 'http://example.localhost/' }
end end
@@ -68,14 +68,14 @@ describe 'WebSite' do
describe '#xml_rpc_url' do describe '#xml_rpc_url' do
it 'returns the xmlrpc url' do it 'returns the xmlrpc url' do
expect(web_site.xml_rpc_url).to be === "http://example.localhost/xmlrpc.php" expect(web_site.xml_rpc_url).to be === 'http://example.localhost/xmlrpc.php'
end end
end end
describe '#has_xml_rpc?' do describe '#has_xml_rpc?' do
it 'returns true' do it 'returns true' do
stub_request(:get, web_site.xml_rpc_url). stub_request(:get, web_site.xml_rpc_url).
to_return(status: 200, body: "XML-RPC server accepts POST requests only") to_return(status: 200, body: 'XML-RPC server accepts POST requests only')
expect(web_site).to have_xml_rpc expect(web_site).to have_xml_rpc
end end

View File

@@ -149,7 +149,7 @@ describe WpTarget do
after :each do after :each do
allow(wp_target).to receive_messages(wp_content_dir: 'wp-content') allow(wp_target).to receive_messages(wp_content_dir: 'wp-content')
stub_request_to_fixture(url: wp_target.debug_log_url(), fixture: @fixture) stub_request_to_fixture(url: wp_target.debug_log_url, fixture: @fixture)
expect(wp_target.has_debug_log?).to be === @expected expect(wp_target.has_debug_log?).to be === @expected
end end

View File

@@ -40,7 +40,7 @@ shared_examples 'WpTarget::WpRegistrable' do
end end
it 'returns true' do it 'returns true' do
@stub = { status: 200, body: %{<form id="setupform" method="post" action="wp-signup.php">} } @stub = { status: 200, body: '<form id="setupform" method="post" action="wp-signup.php">'}
@expected = true @expected = true
end end
end end
@@ -54,7 +54,7 @@ shared_examples 'WpTarget::WpRegistrable' do
end end
it 'returns true' do it 'returns true' do
@stub = { status: 200, body: %{<form name="registerform" id="registerform" action="wp-login.php"} } @stub = { status: 200, body: '<form name="registerform" id="registerform" action="wp-login.php"'}
@expected = true @expected = true
end end

View File

@@ -10,11 +10,11 @@ describe 'wpscan main checks' do
end end
it 'should check for valid syntax' do it 'should check for valid syntax' do
result = "" result = ''
Dir.glob("**/*.rb") do |file| Dir.glob('**/*.rb') do |file|
res = %x{#{RbConfig.ruby} -c #{ROOT_DIR}/#{file} 2>&1}.split("\n") res = %x{#{RbConfig.ruby} -c #{ROOT_DIR}/#{file} 2>&1}.split("\n")
ok = res.select {|msg| msg =~ /Syntax OK/} ok = res.select {|msg| msg =~ /Syntax OK/}
result << ("####################\nSyntax error in #{file}:\n#{res.join("\n").strip()}\n") if ok.size != 1 result << ("####################\nSyntax error in #{file}:\n#{res.join("\n").strip}\n") if ok.size != 1
end end
fail(result) unless result.empty? fail(result) unless result.empty?
end end