Add random-agent

This commit is contained in:
FireFart
2014-03-01 09:01:52 +01:00
parent bbce082ec2
commit c4ca7e471a
9 changed files with 75 additions and 12 deletions

View File

@@ -12,7 +12,7 @@ class Browser
:basic_auth,
:cache_ttl,
:max_threads,
:useragent,
:user_agent,
:proxy,
:proxy_auth,
:request_timeout,
@@ -66,7 +66,7 @@ class Browser
@cache_ttl = 600 # 10 minutes, at this time the cache is cleaned before each scan. If this value is set to 0, the cache will be disabled
@request_timeout = 2000 # 2s
@connect_timeout = 1000 # 1s
@useragent = "WPScan v#{WPSCAN_VERSION} (http://wpscan.org)"
@user_agent = "WPScan v#{WPSCAN_VERSION} (http://wpscan.org)"
end
# @param [ String ] url
@@ -84,7 +84,7 @@ class Browser
params = Browser.append_params_header_field(
params,
'User-Agent',
@useragent
@user_agent
)
if @proxy

View File

@@ -5,7 +5,7 @@ class Browser
attr_accessor :cache_ttl, :request_timeout, :connect_timeout
attr_reader :basic_auth, :proxy, :proxy_auth
attr_writer :useragent
attr_writer :user_agent
# Sets the Basic Authentification credentials
# Accepted format:

View File

@@ -32,6 +32,7 @@ LOCAL_FILES_FILE = DATA_DIR + '/local_vulnerable_files.xml'
VULNS_XSD = DATA_DIR + '/vuln.xsd'
WP_VERSIONS_XSD = DATA_DIR + '/wp_versions.xsd'
LOCAL_FILES_XSD = DATA_DIR + '/local_vulnerable_files.xsd'
USER_AGENTS_FILE = DATA_DIR + '/user-agents.txt'
WPSCAN_VERSION = '2.3'
@@ -187,3 +188,19 @@ def truncate(input, size, trailing = '...')
trailing.length >= input.length or size-trailing.length-1 >= input.length
return "#{input[0..size-trailing.length-1]}#{trailing}"
end
# Gets a random User-Agent
#
# @return [ String ] A random user-agent from data/user-agents.txt
def get_random_user_agent
user_agents = []
f = File.open(USER_AGENTS_FILE, 'r')
f.each_line do |line|
# ignore comments
next if line.empty? or line =~ /^\s*(#|\/\/)/
user_agents << line.strip
end
f.close
# return ransom user-agent
user_agents.sample
end