refactoring

This commit is contained in:
Christian Mehlmauer
2012-09-21 23:37:31 +02:00
parent 3590f5ed2f
commit 082235abb5
14 changed files with 47 additions and 56 deletions

View File

@@ -18,7 +18,7 @@
class Browser class Browser
@@instance = nil @@instance = nil
@@user_agent_modes = ["static", "semi-static", "random"] @@user_agent_modes = %w{ static semi-static random }
ACCESSOR_OPTIONS = [ ACCESSOR_OPTIONS = [
:user_agent, :user_agent,
@@ -80,12 +80,12 @@ class Browser
# return the user agent, according to the user_agent_mode # return the user agent, according to the user_agent_mode
def user_agent def user_agent
case @user_agent_mode case @user_agent_mode
when "semi-static" when "semi-static"
unless @user_agent unless @user_agent
@user_agent = @available_user_agents.sample
end
when "random"
@user_agent = @available_user_agents.sample @user_agent = @available_user_agents.sample
end
when "random"
@user_agent = @available_user_agents.sample
end end
@user_agent @user_agent
end end
@@ -149,11 +149,11 @@ class Browser
params = params.merge(:proxy => @proxy) params = params.merge(:proxy => @proxy)
end end
if !params.has_key?(:disable_ssl_host_verification) unless params.has_key?(:disable_ssl_host_verification)
params = params.merge(:disable_ssl_host_verification => true) params = params.merge(:disable_ssl_host_verification => true)
end end
if !params.has_key?(:disable_ssl_peer_verification) unless params.has_key?(:disable_ssl_peer_verification)
params = params.merge(:disable_ssl_peer_verification => true) params = params.merge(:disable_ssl_peer_verification => true)
end end
@@ -164,7 +164,7 @@ class Browser
end end
# Used to enable the cache system if :cache_timeout > 0 # Used to enable the cache system if :cache_timeout > 0
if !params.has_key?(:cache_timeout) unless params.has_key?(:cache_timeout)
params = params.merge(:cache_timeout => @cache_timeout) params = params.merge(:cache_timeout => @cache_timeout)
end end

View File

@@ -36,7 +36,7 @@ class CacheFileStore
@serializer = serializer @serializer = serializer
# File.directory? for ruby <= 1.9 otherwise, it makes more sense to do Dir.exist? :/ # File.directory? for ruby <= 1.9 otherwise, it makes more sense to do Dir.exist? :/
if !File.directory?(@storage_path) unless File.directory?(@storage_path)
Dir.mkdir(@storage_path) Dir.mkdir(@storage_path)
end end
end end
@@ -56,7 +56,7 @@ class CacheFileStore
end end
def write_entry(key, data_to_store, cache_timeout) def write_entry(key, data_to_store, cache_timeout)
if (cache_timeout > 0) if cache_timeout > 0
File.open(get_entry_file_path(key), 'w') do |f| File.open(get_entry_file_path(key), 'w') do |f|
f.write(@serializer.dump(data_to_store)) f.write(@serializer.dump(data_to_store))
end end

View File

@@ -74,7 +74,7 @@ class Exploit
session_spawn_timer = Time.new session_spawn_timer = Time.new
while sessions.nil? or sessions.empty? while sessions.nil? or sessions.empty?
# wait for a session to spawn with a timeout of 1 minute # wait for a session to spawn with a timeout of 1 minute
if (Time.now - session_spawn_timer > 60) if Time.now - session_spawn_timer > 60
puts "[ERROR] Session was not created... exiting." puts "[ERROR] Session was not created... exiting."
return false return false
end end

View File

@@ -54,6 +54,7 @@ module WebSite
# see if the remote url returns 30x redirect # see if the remote url returns 30x redirect
# return a string with the redirection or nil # return a string with the redirection or nil
def redirection(url = nil) def redirection(url = nil)
redirection = nil
url ||= @uri.to_s url ||= @uri.to_s
response = Browser.instance.get(url) response = Browser.instance.get(url)

View File

@@ -47,10 +47,11 @@ module WpConfigBackup
# @return Array # @return Array
def self.config_backup_files def self.config_backup_files
[ %w{
'wp-config.php~','#wp-config.php#','wp-config.php.save','wp-config.php.swp','wp-config.php.swo','wp-config.php_bak', wp-config.php~ #wp-config.php# wp-config.php.save wp-config.php.swp wp-config.php.swo wp-config.php_bak
'wp-config.bak', 'wp-config.php.bak', 'wp-config.save' wp-config.bak wp-config.php.bak wp-config.save wp-config.old wp-config.php.old wp-config.php.orig
] # thanks to Feross.org for these wp-config.org wp-config.php.original wp-config.original
} # thanks to Feross.org for these
end end
end end

View File

@@ -18,7 +18,7 @@
module WpLoginProtection module WpLoginProtection
@@login_protection_method_pattern = /^has_(.*)_protection\?/i LOGIN_PROTECTION_METHOD_PATTERN = /^has_(.*)_protection\?/i
# Used as cache # Used as cache
@login_protection_plugin = nil @login_protection_plugin = nil
@@ -31,10 +31,10 @@ module WpLoginProtection
# return a WpPlugin object or nil if no one is found # return a WpPlugin object or nil if no one is found
def login_protection_plugin def login_protection_plugin
unless @login_protection_plugin unless @login_protection_plugin
protected_methods.grep(@@login_protection_method_pattern).each do |symbol_to_call| protected_methods.grep(LOGIN_PROTECTION_METHOD_PATTERN).each do |symbol_to_call|
if send(symbol_to_call) if send(symbol_to_call)
plugin_name = symbol_to_call[@@login_protection_method_pattern, 1].gsub('_', '-') plugin_name = symbol_to_call[LOGIN_PROTECTION_METHOD_PATTERN, 1].gsub('_', '-')
return @login_protection_plugin = WpPlugin.new( return @login_protection_plugin = WpPlugin.new(
:name => plugin_name, :name => plugin_name,

View File

@@ -71,84 +71,73 @@ class RpcClient
def get_exploit_info(name) def get_exploit_info(name)
authenticate() authenticate()
result = @server.call('module.info', @auth_token, 'exploit', name) @server.call('module.info', @auth_token, 'exploit', name)
return result
end end
# retrieve exploit options # retrieve exploit options
def get_options(name) def get_options(name)
authenticate() authenticate()
result = @server.call('module.options', @auth_token, 'exploit',name) @server.call('module.options', @auth_token, 'exploit',name)
return result
end end
# retrieve the exploit payloads # retrieve the exploit payloads
def get_payloads(name) def get_payloads(name)
authenticate() authenticate()
result = @server.call('module.compatible_payloads', @auth_token, name) @server.call('module.compatible_payloads', @auth_token, name)
return result
end end
# execute exploit # execute exploit
def exploit(name, opts) def exploit(name, opts)
authenticate() authenticate()
result = @server.call('module.execute', @auth_token, 'exploit', name, opts) @server.call('module.execute', @auth_token, 'exploit', name, opts)
return result
end end
# list msf jobs # list msf jobs
def jobs() def jobs()
authenticate() authenticate()
result = @server.call('job.list', @auth_token) @server.call('job.list', @auth_token)
return result
end end
# list msf sessions # list msf sessions
def sessions() def sessions()
authenticate() authenticate()
result = @server.call('session.list', @auth_token) @server.call('session.list', @auth_token)
return result
end end
# kill msf session # kill msf session
def kill_session(id) def kill_session(id)
authenticate() authenticate()
result = @server.call('session.stop', @auth_token, id) @server.call('session.stop', @auth_token, id)
return result
end end
# reads any pending output from session # reads any pending output from session
def read_shell(id) def read_shell(id)
authenticate() authenticate()
result = @server.call('session.shell_read', @auth_token, id) @server.call('session.shell_read', @auth_token, id)
return result
end end
# writes the specified input into the session # writes the specified input into the session
def write_shell(id, data) def write_shell(id, data)
authenticate() authenticate()
result = @server.call('session.shell_write', @auth_token, id, data) @server.call('session.shell_write', @auth_token, id, data)
return result
end end
def meterpreter_read(id) def meterpreter_read(id)
authenticate() authenticate()
result = @server.call('session.meterpreter_read', @auth_token, id) @server.call('session.meterpreter_read', @auth_token, id)
return result
end end
def meterpreter_write(id, data) def meterpreter_write(id, data)
authenticate() authenticate()
result = @server.call('session.meterpreter_write', @auth_token, id, data) @server.call('session.meterpreter_write', @auth_token, id, data)
return result
end end
end end

View File

@@ -36,7 +36,7 @@ class WpDetector
break break
end end
end end
if not already_present unless already_present
result << enum_result result << enum_result
end end
end end

View File

@@ -94,7 +94,7 @@ class WpEnumerator
type = options[:type] type = options[:type]
targets_url = [] targets_url = []
if only_vulnerable == false unless only_vulnerable
# Open and parse the 'most popular' plugin list... # Open and parse the 'most popular' plugin list...
File.open(file, 'r') do |f| File.open(file, 'r') do |f|
f.readlines.collect do |line| f.readlines.collect do |line|

View File

@@ -58,7 +58,8 @@ class WpTheme < WpItem
def self.find_from_css_link(target_uri) def self.find_from_css_link(target_uri)
response = Browser.instance.get(target_uri.to_s, { :follow_location => true, :max_redirects => 2 }) response = Browser.instance.get(target_uri.to_s, { :follow_location => true, :max_redirects => 2 })
if matches = %r{https?://[^"']+/themes/([^"']+)/style.css}i.match(response.body) matches = %r{https?://[^"']+/themes/([^"']+)/style.css}i.match(response.body)
if matches
style_url = matches[0] style_url = matches[0]
theme_name = matches[1] theme_name = matches[1]
@@ -76,7 +77,8 @@ class WpTheme < WpItem
body = Browser.instance.get(target_uri.to_s).body body = Browser.instance.get(target_uri.to_s).body
regexp = %r{<meta name="generator" content="([^\s"]+)\s?([^"]+)?" />\s+<meta name="generator" content="WooFramework\s?([^"]+)?" />} regexp = %r{<meta name="generator" content="([^\s"]+)\s?([^"]+)?" />\s+<meta name="generator" content="WooFramework\s?([^"]+)?" />}
if matches = regexp.match(body) matches = regexp.match(body)
if matches
woo_theme_name = matches[1] woo_theme_name = matches[1]
woo_theme_version = matches[2] woo_theme_version = matches[2]
woo_framework_version = matches[3] # Not used at this time woo_framework_version = matches[3] # Not used at this time

View File

@@ -176,7 +176,8 @@ class WpscanOptions
if value =~ /u/ if value =~ /u/
@enumerate_usernames = true @enumerate_usernames = true
# Check for usernames range # Check for usernames range
if matches = %r{\[([\d]+)-([\d]+)\]}.match(value) matches = %r{\[([\d]+)-([\d]+)\]}.match(value)
if matches
@enumerate_usernames_range = (matches[1].to_i..matches[2].to_i) @enumerate_usernames_range = (matches[1].to_i..matches[2].to_i)
end end
end end

View File

@@ -92,8 +92,7 @@ class Generate_List
@hydra.run @hydra.run
found_items.sort! found_items.sort!
found_items.uniq! found_items.uniq
return found_items
end end
# Save the file # Save the file

View File

@@ -36,8 +36,7 @@ class Svn_Parser
dirs = get_root_directories dirs = get_root_directories
end end
urls = get_svn_project_urls(dirs) urls = get_svn_project_urls(dirs)
entries = get_svn_file_entries(urls) get_svn_file_entries(urls)
return entries
end end
#Private methods start here #Private methods start here
@@ -51,8 +50,7 @@ class Svn_Parser
dirs << dir[0] dirs << dir[0]
end end
dirs.sort! dirs.sort!
dirs.uniq! dirs.uniq
return dirs
end end
def get_svn_project_urls(dirs) def get_svn_project_urls(dirs)
@@ -89,7 +87,7 @@ class Svn_Parser
end end
end end
@svn_hydra.run @svn_hydra.run
return urls urls
end end
# Get a file in each directory # Get a file in each directory
@@ -124,7 +122,7 @@ class Svn_Parser
end end
end end
@svn_hydra.run @svn_hydra.run
return entries entries
end end
def contains_trunk(body) def contains_trunk(body)
@@ -132,6 +130,6 @@ class Svn_Parser
if !!(body =~ %r[<li><a href="trunk/">trunk/</a></li>]i) if !!(body =~ %r[<li><a href="trunk/">trunk/</a></li>]i)
contains = true contains = true
end end
return contains contains
end end
end end

View File

@@ -35,7 +35,7 @@ shared_examples_for "WpLoginProtection" do
# there is not false positive : for example the login-lock must not be detected as login-lockdown # there is not false positive : for example the login-lock must not be detected as login-lockdown
describe "#has_.*_protection?" do describe "#has_.*_protection?" do
pattern = WpLoginProtection.class_variable_get(:@@login_protection_method_pattern) pattern = WpLoginProtection::LOGIN_PROTECTION_METHOD_PATTERN
fixtures = fixtures =
%w{ %w{
wp-login-clean.php wp-login-login_lockdown.php wp-login-login_lock.php wp-login-clean.php wp-login-login_lockdown.php wp-login-login_lock.php