2005-07-24 20:53:54 +00:00
|
|
|
require 'rex/socket'
|
|
|
|
require 'rex/proto/http'
|
2006-12-19 07:11:55 +00:00
|
|
|
require 'rex/text'
|
2005-07-24 20:53:54 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Proto
|
|
|
|
module Http
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
2010-09-11 17:31:26 +00:00
|
|
|
# Acts as a client to an HTTP server, sending requests and receiving responses.
|
|
|
|
#
|
|
|
|
# See the RFC: http://www.w3.org/Protocols/rfc2616/rfc2616.html
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
|
|
|
###
|
|
|
|
class Client
|
|
|
|
|
2011-07-28 22:57:47 +00:00
|
|
|
DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
|
|
|
|
|
2005-12-08 05:55:44 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
# Creates a new client instance
|
2005-12-08 05:55:44 +00:00
|
|
|
#
|
2009-10-26 19:48:15 +00:00
|
|
|
def initialize(host, port = 80, context = {}, ssl = nil, ssl_version = nil, proxies = nil)
|
2005-07-24 20:53:54 +00:00
|
|
|
self.hostname = host
|
|
|
|
self.port = port.to_i
|
2006-01-17 04:35:44 +00:00
|
|
|
self.context = context
|
2006-01-20 18:59:24 +00:00
|
|
|
self.ssl = ssl
|
2009-10-26 19:48:15 +00:00
|
|
|
self.ssl_version = ssl_version
|
2007-09-24 04:44:44 +00:00
|
|
|
self.proxies = proxies
|
2006-12-19 07:11:55 +00:00
|
|
|
self.config = {
|
|
|
|
'read_max_data' => (1024*1024*1),
|
|
|
|
'vhost' => self.hostname,
|
|
|
|
'version' => '1.1',
|
2011-07-28 22:57:47 +00:00
|
|
|
'agent' => DefaultUserAgent,
|
2007-02-18 22:35:07 +00:00
|
|
|
#
|
|
|
|
# Evasion options
|
|
|
|
#
|
|
|
|
'uri_encode_mode' => 'hex-normal', # hex-all, hex-random, u-normal, u-random, u-all
|
2007-05-06 22:33:21 +00:00
|
|
|
'uri_encode_count' => 1, # integer
|
2007-02-18 22:35:07 +00:00
|
|
|
'uri_full_url' => false, # bool
|
|
|
|
'pad_method_uri_count' => 1, # integer
|
|
|
|
'pad_uri_version_count' => 1, # integer
|
|
|
|
'pad_method_uri_type' => 'space', # space, tab, apache
|
|
|
|
'pad_uri_version_type' => 'space', # space, tab, apache
|
|
|
|
'method_random_valid' => false, # bool
|
|
|
|
'method_random_invalid' => false, # bool
|
|
|
|
'method_random_case' => false, # bool
|
|
|
|
'version_random_valid' => false, # bool
|
|
|
|
'version_random_invalid' => false, # bool
|
|
|
|
'version_random_case' => false, # bool
|
|
|
|
'uri_dir_self_reference' => false, # bool
|
|
|
|
'uri_dir_fake_relative' => false, # bool
|
|
|
|
'uri_use_backslashes' => false, # bool
|
|
|
|
'pad_fake_headers' => false, # bool
|
|
|
|
'pad_fake_headers_count' => 16, # integer
|
2007-03-08 14:08:41 +00:00
|
|
|
'pad_get_params' => false, # bool
|
|
|
|
'pad_get_params_count' => 8, # integer
|
|
|
|
'pad_post_params' => false, # bool
|
2007-03-10 05:58:14 +00:00
|
|
|
'pad_post_params_count' => 8, # integer
|
|
|
|
'uri_fake_end' => false, # bool
|
|
|
|
'uri_fake_params_start' => false, # bool
|
2009-11-02 18:14:57 +00:00
|
|
|
'header_folding' => false, # bool
|
2007-04-26 21:08:22 +00:00
|
|
|
'chunked_size' => 0 # integer
|
2005-09-15 23:37:38 +00:00
|
|
|
}
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-03-17 20:10:57 +00:00
|
|
|
# This is not used right now...
|
|
|
|
self.config_types = {
|
|
|
|
'uri_encode_mode' => ['hex-normal', 'hex-all', 'hex-random', 'u-normal', 'u-random', 'u-all'],
|
2007-05-04 15:17:25 +00:00
|
|
|
'uri_encode_count' => 'integer',
|
2007-03-17 20:10:57 +00:00
|
|
|
'uri_full_url' => 'bool',
|
|
|
|
'pad_method_uri_count' => 'integer',
|
|
|
|
'pad_uri_version_count' => 'integer',
|
|
|
|
'pad_method_uri_type' => ['space', 'tab', 'apache'],
|
|
|
|
'pad_uri_version_type' => ['space', 'tab', 'apache'],
|
|
|
|
'method_random_valid' => 'bool',
|
|
|
|
'method_random_invalid' => 'bool',
|
|
|
|
'method_random_case' => 'bool',
|
|
|
|
'version_random_valid' => 'bool',
|
|
|
|
'version_random_invalid' => 'bool',
|
|
|
|
'version_random_case' => 'bool',
|
|
|
|
'uri_dir_self_reference' => 'bool',
|
|
|
|
'uri_dir_fake_relative' => 'bool',
|
|
|
|
'uri_use_backslashes' => 'bool',
|
|
|
|
'pad_fake_headers' => 'bool',
|
|
|
|
'pad_fake_headers_count' => 'integer',
|
|
|
|
'pad_get_params' => 'bool',
|
|
|
|
'pad_get_params_count' => 'integer',
|
|
|
|
'pad_post_params' => 'bool',
|
|
|
|
'pad_post_params_count' => 'integer',
|
|
|
|
'uri_fake_end' => 'bool',
|
|
|
|
'uri_fake_params_start' => 'bool',
|
2007-04-26 21:08:22 +00:00
|
|
|
'header_folding' => 'bool',
|
|
|
|
'chunked_size' => 'integer'
|
2007-03-17 20:10:57 +00:00
|
|
|
}
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2005-09-15 23:37:38 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
# Set configuration options
|
2005-09-15 23:37:38 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
def set_config(opts = {})
|
|
|
|
opts.each_pair do |var,val|
|
2012-01-07 03:05:29 +00:00
|
|
|
# Default type is string
|
2009-11-30 21:15:06 +00:00
|
|
|
typ = self.config_types[var] || 'string'
|
|
|
|
|
2012-01-07 03:05:29 +00:00
|
|
|
# These are enum types
|
2009-11-30 21:15:06 +00:00
|
|
|
if(typ.class.to_s == 'Array')
|
|
|
|
if not typ.include?(val)
|
|
|
|
raise RuntimeError, "The specified value for #{var} is not one of the valid choices"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-07 03:05:29 +00:00
|
|
|
# The caller should have converted these to proper ruby types, but
|
|
|
|
# take care of the case where they didn't before setting the
|
|
|
|
# config.
|
|
|
|
|
2009-11-30 21:15:06 +00:00
|
|
|
if(typ == 'bool')
|
2012-01-07 03:05:29 +00:00
|
|
|
val = (val =~ /^(t|y|1)$/i ? true : false || val === true)
|
2009-11-30 21:15:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if(typ == 'integer')
|
|
|
|
val = val.to_i
|
|
|
|
end
|
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
self.config[var]=val
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-30 21:15:06 +00:00
|
|
|
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2005-09-15 23:37:38 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
# Create an arbitrary HTTP request
|
|
|
|
#
|
|
|
|
def request_raw(opts={})
|
|
|
|
c_enc = opts['encode'] || false
|
|
|
|
c_uri = opts['uri'] || '/'
|
2006-12-28 23:42:54 +00:00
|
|
|
c_body = opts['data'] || ''
|
2006-12-19 07:11:55 +00:00
|
|
|
c_meth = opts['method'] || 'GET'
|
2009-11-02 18:14:57 +00:00
|
|
|
c_prot = opts['proto'] || 'HTTP'
|
2006-12-19 07:11:55 +00:00
|
|
|
c_vers = opts['version'] || config['version'] || '1.1'
|
|
|
|
c_qs = opts['query']
|
|
|
|
c_ag = opts['agent'] || config['agent']
|
|
|
|
c_cook = opts['cookie'] || config['cookie']
|
2009-12-03 01:36:17 +00:00
|
|
|
c_host = opts['vhost'] || config['vhost'] || self.hostname
|
2007-03-11 16:28:13 +00:00
|
|
|
c_head = opts['headers'] || config['headers'] || {}
|
2009-11-02 18:14:57 +00:00
|
|
|
c_rawh = opts['raw_headers']|| config['raw_headers'] || ''
|
|
|
|
c_conn = opts['connection']
|
2007-04-23 22:48:22 +00:00
|
|
|
c_auth = opts['basic_auth'] || config['basic_auth'] || ''
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
uri = set_uri(c_uri)
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
req = ''
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_method(c_meth)
|
|
|
|
req << set_method_uri_spacer()
|
|
|
|
req << set_uri_prepend()
|
|
|
|
req << (c_enc ? set_encode_uri(uri) : uri)
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
if (c_qs)
|
2009-03-08 07:55:47 +00:00
|
|
|
req << '?'
|
|
|
|
req << (c_enc ? set_encode_qs(c_qs) : c_qs)
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_uri_append()
|
|
|
|
req << set_uri_version_spacer()
|
|
|
|
req << set_version(c_prot, c_vers)
|
|
|
|
req << set_host_header(c_host)
|
|
|
|
req << set_agent_header(c_ag)
|
2007-04-23 22:48:22 +00:00
|
|
|
|
|
|
|
if (c_auth.length > 0)
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_basic_auth_header(c_auth)
|
2007-04-23 22:48:22 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_cookie_header(c_cook)
|
|
|
|
req << set_connection_header(c_conn)
|
|
|
|
req << set_extra_headers(c_head)
|
2009-11-02 18:14:57 +00:00
|
|
|
req << set_raw_headers(c_rawh)
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_body(c_body)
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
req
|
|
|
|
end
|
|
|
|
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Create a CGI compatible request
|
|
|
|
#
|
2010-09-11 17:31:26 +00:00
|
|
|
# Options:
|
|
|
|
# - agent: User-Agent header value
|
|
|
|
# - basic_auth: Basic-Auth header value
|
|
|
|
# - connection: Connection header value
|
|
|
|
# - cookie: Cookie header value
|
|
|
|
# - ctype: Content-Type header value, default: +application/x-www-form-urlencoded+
|
|
|
|
# - data: HTTP data (only useful with some methods, see rfc2616)
|
|
|
|
# - encode: URI encode the supplied URI
|
|
|
|
# - headers: HTTP headers as a hash, e.g. <code>{ "X-MyHeader" => "value" }</code>
|
|
|
|
# - method: HTTP method to use in the request, not limited to standard methods defined by rfc2616, default: GET
|
|
|
|
# - proto: protocol, default: HTTP
|
|
|
|
# - query: raw query string
|
|
|
|
# - raw_headers: HTTP headers as a hash
|
|
|
|
# - uri: the URI to request
|
|
|
|
# - vars_get: GET variables as a hash to be translated into a query string
|
|
|
|
# - vars_post: POST variables as a hash to be translated into POST data
|
|
|
|
# - version: version of the protocol, default: 1.1
|
|
|
|
# - vhost: Host header value
|
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
def request_cgi(opts={})
|
|
|
|
c_enc = opts['encode'] || false
|
2006-12-28 23:42:54 +00:00
|
|
|
c_cgi = opts['uri'] || '/'
|
|
|
|
c_body = opts['data'] || ''
|
2006-12-19 07:11:55 +00:00
|
|
|
c_meth = opts['method'] || 'GET'
|
2006-12-28 23:42:54 +00:00
|
|
|
c_prot = opts['proto'] || 'HTTP'
|
2006-12-19 07:11:55 +00:00
|
|
|
c_vers = opts['version'] || config['version'] || '1.1'
|
|
|
|
c_qs = opts['query'] || ''
|
|
|
|
c_varg = opts['vars_get'] || {}
|
|
|
|
c_varp = opts['vars_post'] || {}
|
|
|
|
c_head = opts['headers'] || config['headers'] || {}
|
2007-03-11 16:28:13 +00:00
|
|
|
c_rawh = opts['raw_headers']|| config['raw_headers'] || ''
|
2006-12-19 07:11:55 +00:00
|
|
|
c_type = opts['ctype'] || 'application/x-www-form-urlencoded'
|
|
|
|
c_ag = opts['agent'] || config['agent']
|
|
|
|
c_cook = opts['cookie'] || config['cookie']
|
|
|
|
c_host = opts['vhost'] || config['vhost']
|
|
|
|
c_conn = opts['connection']
|
2007-04-23 22:48:22 +00:00
|
|
|
c_path = opts['path_info']
|
|
|
|
c_auth = opts['basic_auth'] || config['basic_auth'] || ''
|
2007-04-26 21:08:22 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
uri = set_cgi(c_cgi)
|
|
|
|
qstr = c_qs
|
|
|
|
pstr = c_body
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-03-08 14:08:41 +00:00
|
|
|
if (config['pad_get_params'])
|
|
|
|
1.upto(config['pad_get_params_count'].to_i) do |i|
|
|
|
|
qstr << '&' if qstr.length > 0
|
|
|
|
qstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
|
|
|
|
qstr << '='
|
2009-11-02 18:14:57 +00:00
|
|
|
qstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
|
2007-03-08 14:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
c_varg.each_pair do |var,val|
|
|
|
|
qstr << '&' if qstr.length > 0
|
|
|
|
qstr << set_encode_uri(var)
|
|
|
|
qstr << '='
|
|
|
|
qstr << set_encode_uri(val)
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2006-10-11 08:31:54 +00:00
|
|
|
|
2007-03-08 14:08:41 +00:00
|
|
|
if (config['pad_post_params'])
|
|
|
|
1.upto(config['pad_post_params_count'].to_i) do |i|
|
|
|
|
pstr << '&' if qstr.length > 0
|
|
|
|
pstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
|
|
|
|
pstr << '='
|
2009-11-02 18:14:57 +00:00
|
|
|
pstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
|
2007-03-08 14:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
c_varp.each_pair do |var,val|
|
|
|
|
pstr << '&' if pstr.length > 0
|
|
|
|
pstr << set_encode_uri(var)
|
|
|
|
pstr << '='
|
|
|
|
pstr << set_encode_uri(val)
|
2006-10-11 08:31:54 +00:00
|
|
|
end
|
2007-01-30 04:48:35 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
req = ''
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_method(c_meth)
|
|
|
|
req << set_method_uri_spacer()
|
|
|
|
req << set_uri_prepend()
|
2009-04-29 04:04:40 +00:00
|
|
|
req << (c_enc ? set_encode_uri(uri):uri)
|
2006-12-19 07:11:55 +00:00
|
|
|
|
|
|
|
if (qstr.length > 0)
|
2009-03-08 07:55:47 +00:00
|
|
|
req << '?'
|
|
|
|
req << qstr
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_path_info(c_path)
|
|
|
|
req << set_uri_append()
|
|
|
|
req << set_uri_version_spacer()
|
|
|
|
req << set_version(c_prot, c_vers)
|
|
|
|
req << set_host_header(c_host)
|
|
|
|
req << set_agent_header(c_ag)
|
2007-04-23 22:48:22 +00:00
|
|
|
|
|
|
|
if (c_auth.length > 0)
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_basic_auth_header(c_auth)
|
2007-04-23 22:48:22 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_cookie_header(c_cook)
|
2009-11-02 18:14:57 +00:00
|
|
|
req << set_connection_header(c_conn)
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_extra_headers(c_head)
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
req << set_content_type_header(c_type)
|
|
|
|
req << set_content_len_header(pstr.length)
|
|
|
|
req << set_chunked_header()
|
|
|
|
req << set_raw_headers(c_rawh)
|
|
|
|
req << set_body(pstr)
|
2007-03-08 14:08:41 +00:00
|
|
|
|
2009-11-02 18:14:57 +00:00
|
|
|
req
|
|
|
|
end
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
|
|
|
# Connects to the remote server if possible.
|
|
|
|
#
|
2011-10-21 15:41:37 +00:00
|
|
|
def connect(t = -1)
|
2005-07-24 20:53:54 +00:00
|
|
|
# If we already have a connection and we aren't pipelining, close it.
|
* add junk pipelined request support
* fix socket creation on pipelined requests
* when a server says that the connection should be closed (Connection: closed), then close the connection, since its going to regardless, and we don't want to loose our state
* support non-standard line termination in headers. ie \n instead of \r\n
* add junk headers (X-rand: rand)
* add header folding (for evasion)
* add parse_header_re (still leaving parse_header around, though its dead code ATM) that does the right thing on non-standard line endings
* move 'gzip' to a 'compression' option
* add 'deflate' compression option (really, just raw zlib, and only firefox does deflate right)
* fix a bunch of TE:chunked decoding bugs based based on the fact that Apache doesn't always close chunks appropriately
* modify parse_body to not return state, since it doesn't always do that, and the return isn't used... self.state is.
* add TE:chunked request support
* normalize URIs in requests before saving them
* Move params out of the URI, but when the uri is requested, and the method is GET, and there are params, return a URI that has the params that are approrpiately encoded (needed for junk_params, see below)
* move request.to_s support of params to use the request params array when a POST, allows use of junk params support (see below). NOTE: If the body is provided, use the body instead of params, in case you want to hardcode the params in a POST request, eg: php_xmlrpc_eval.rb
* Add junk params when building a param list, eg: a=b becomes asdfasdf=asdrt32a&asdfad=okhgasd&a=b&hjklasdf=hkasgd
* add URI junk slash support (eg: /////foo.html)
* param splitting now supports both '&', and ';', which CGI.pm and PHP both allow
* add URI junk directory support, eg: /asdf/../foo.html
* add param encoding support, eg: param A with value '=' is A=%3d
* add URI junk self referring directory support, eg: /././foo.html
git-svn-id: file:///home/svn/incoming/trunk@3457 4d416f70-5f16-0410-b530-b9f4589650da
2006-01-27 21:57:44 +00:00
|
|
|
if (self.conn)
|
|
|
|
if !pipelining?
|
|
|
|
close
|
|
|
|
else
|
|
|
|
return self.conn
|
|
|
|
end
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
2011-10-21 15:41:37 +00:00
|
|
|
timeout = (t.nil? or t == -1) ? 0 : t
|
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
self.conn = Rex::Socket::Tcp.create(
|
|
|
|
'PeerHost' => self.hostname,
|
|
|
|
'PeerPort' => self.port.to_i,
|
|
|
|
'LocalHost' => self.local_host,
|
2006-01-17 04:35:44 +00:00
|
|
|
'LocalPort' => self.local_port,
|
2006-01-20 18:59:24 +00:00
|
|
|
'Context' => self.context,
|
2007-09-24 04:44:44 +00:00
|
|
|
'SSL' => self.ssl,
|
2009-10-26 19:48:15 +00:00
|
|
|
'SSLVersion'=> self.ssl_version,
|
2011-10-21 15:41:37 +00:00
|
|
|
'Proxies' => self.proxies,
|
|
|
|
'Timeout' => timeout
|
2006-01-17 04:35:44 +00:00
|
|
|
)
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Closes the connection to the remote server.
|
|
|
|
#
|
|
|
|
def close
|
2005-09-22 03:24:32 +00:00
|
|
|
if (self.conn)
|
|
|
|
self.conn.shutdown
|
2009-11-02 18:14:57 +00:00
|
|
|
self.conn.close
|
2005-09-22 03:24:32 +00:00
|
|
|
end
|
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
self.conn = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2010-06-11 16:12:05 +00:00
|
|
|
# Transmit an HTTP request and receive the response
|
2010-05-22 17:58:01 +00:00
|
|
|
# If persist is set, then the request will attempt
|
|
|
|
# to reuse an existing connection.
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
2010-05-22 17:58:01 +00:00
|
|
|
def send_recv(req, t = -1, persist=false)
|
|
|
|
@pipeline = persist
|
2011-10-21 15:41:37 +00:00
|
|
|
send_request(req, t)
|
2010-11-13 05:25:39 +00:00
|
|
|
res = read_response(t)
|
2010-12-01 16:32:40 +00:00
|
|
|
res.request = req.to_s if res
|
2010-11-13 05:25:39 +00:00
|
|
|
res
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2010-06-11 16:12:05 +00:00
|
|
|
# Send an HTTP request to the server
|
2009-11-30 21:15:06 +00:00
|
|
|
#
|
2011-10-21 15:41:37 +00:00
|
|
|
def send_request(req, t = -1)
|
|
|
|
connect(t)
|
2009-11-30 21:15:06 +00:00
|
|
|
conn.put(req.to_s)
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Read a response from the server
|
|
|
|
#
|
|
|
|
def read_response(t = -1)
|
2007-02-22 07:33:00 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
resp = Response.new
|
|
|
|
resp.max_data = config['read_max_data']
|
2005-07-24 20:53:54 +00:00
|
|
|
|
|
|
|
# Wait at most t seconds for the full response to be read in. We only
|
|
|
|
# do this if t was specified as a negative value indicating an infinite
|
|
|
|
# wait cycle. If t were specified as nil it would indicate that no
|
|
|
|
# response parsing is required.
|
* add junk pipelined request support
* fix socket creation on pipelined requests
* when a server says that the connection should be closed (Connection: closed), then close the connection, since its going to regardless, and we don't want to loose our state
* support non-standard line termination in headers. ie \n instead of \r\n
* add junk headers (X-rand: rand)
* add header folding (for evasion)
* add parse_header_re (still leaving parse_header around, though its dead code ATM) that does the right thing on non-standard line endings
* move 'gzip' to a 'compression' option
* add 'deflate' compression option (really, just raw zlib, and only firefox does deflate right)
* fix a bunch of TE:chunked decoding bugs based based on the fact that Apache doesn't always close chunks appropriately
* modify parse_body to not return state, since it doesn't always do that, and the return isn't used... self.state is.
* add TE:chunked request support
* normalize URIs in requests before saving them
* Move params out of the URI, but when the uri is requested, and the method is GET, and there are params, return a URI that has the params that are approrpiately encoded (needed for junk_params, see below)
* move request.to_s support of params to use the request params array when a POST, allows use of junk params support (see below). NOTE: If the body is provided, use the body instead of params, in case you want to hardcode the params in a POST request, eg: php_xmlrpc_eval.rb
* Add junk params when building a param list, eg: a=b becomes asdfasdf=asdrt32a&asdfad=okhgasd&a=b&hjklasdf=hkasgd
* add URI junk slash support (eg: /////foo.html)
* param splitting now supports both '&', and ';', which CGI.pm and PHP both allow
* add URI junk directory support, eg: /asdf/../foo.html
* add param encoding support, eg: param A with value '=' is A=%3d
* add URI junk self referring directory support, eg: /././foo.html
git-svn-id: file:///home/svn/incoming/trunk@3457 4d416f70-5f16-0410-b530-b9f4589650da
2006-01-27 21:57:44 +00:00
|
|
|
|
2009-11-30 21:15:06 +00:00
|
|
|
return resp if not t
|
|
|
|
|
|
|
|
Timeout.timeout((t < 0) ? nil : t) do
|
|
|
|
|
|
|
|
rv = nil
|
|
|
|
while (
|
|
|
|
rv != Packet::ParseCode::Completed and
|
|
|
|
rv != Packet::ParseCode::Error
|
|
|
|
)
|
2010-12-11 06:19:36 +00:00
|
|
|
|
2009-11-30 21:15:06 +00:00
|
|
|
begin
|
|
|
|
|
2010-12-11 07:37:09 +00:00
|
|
|
buff = conn.get_once(-1, 1)
|
2010-12-11 06:19:36 +00:00
|
|
|
rv = resp.parse( buff || '' )
|
|
|
|
|
2010-08-18 22:41:07 +00:00
|
|
|
##########################################################################
|
|
|
|
# XXX: NOTE: BUG: get_once currently (as of r10042) rescues "Exception"
|
|
|
|
# As such, the following rescue block will ever be reached. -jjd
|
|
|
|
##########################################################################
|
|
|
|
|
2009-11-30 21:15:06 +00:00
|
|
|
# Handle unexpected disconnects
|
|
|
|
rescue ::Errno::EPIPE, ::EOFError, ::IOError
|
|
|
|
case resp.state
|
|
|
|
when Packet::ParseState::ProcessingHeader
|
2009-12-10 16:54:27 +00:00
|
|
|
resp = nil
|
|
|
|
when Packet::ParseState::ProcessingBody
|
|
|
|
# truncated request, good enough
|
|
|
|
resp.error = :truncated
|
|
|
|
end
|
|
|
|
break
|
|
|
|
end
|
2010-03-25 21:35:37 +00:00
|
|
|
|
|
|
|
# This is a dirty hack for broken HTTP servers
|
|
|
|
if rv == Packet::ParseCode::Completed
|
|
|
|
rbody = resp.body
|
|
|
|
rbufq = resp.bufq
|
|
|
|
|
|
|
|
rblob = rbody.to_s + rbufq.to_s
|
|
|
|
tries = 0
|
|
|
|
begin
|
2010-11-05 16:20:13 +00:00
|
|
|
# XXX: This doesn't deal with chunked encoding or "Content-type: text/html; charset=..."
|
2010-07-06 23:08:28 +00:00
|
|
|
while tries < 1000 and resp.headers["Content-Type"]== "text/html" and rblob !~ /<\/html>/i
|
2010-03-25 21:35:37 +00:00
|
|
|
buff = conn.get_once(-1, 0.05)
|
|
|
|
break if not buff
|
|
|
|
rblob += buff
|
2010-06-07 23:56:35 +00:00
|
|
|
tries += 1
|
2010-03-25 21:35:37 +00:00
|
|
|
end
|
|
|
|
rescue ::Errno::EPIPE, ::EOFError, ::IOError
|
|
|
|
end
|
|
|
|
|
|
|
|
resp.bufq = ""
|
|
|
|
resp.body = rblob
|
|
|
|
end
|
2009-12-10 16:54:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-05 16:20:13 +00:00
|
|
|
return resp if not resp
|
|
|
|
|
|
|
|
# As a last minute hack, we check to see if we're dealing with a 100 Continue here.
|
|
|
|
if resp.proto == '1.1' and resp.code == 100
|
|
|
|
# If so, our real response becaome the body, so we re-parse it.
|
|
|
|
body = resp.body
|
|
|
|
resp = Response.new
|
|
|
|
resp.max_data = config['read_max_data']
|
|
|
|
rv = resp.parse(body)
|
|
|
|
# XXX: At some point, this may benefit from processing post-completion code
|
|
|
|
# as seen above.
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2010-11-05 16:20:13 +00:00
|
|
|
|
2009-11-30 21:15:06 +00:00
|
|
|
resp
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Cleans up any outstanding connections and other resources.
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
|
|
|
def stop
|
|
|
|
close
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns whether or not the conn is valid.
|
|
|
|
#
|
|
|
|
def conn?
|
|
|
|
conn != nil
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Whether or not connections should be pipelined.
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
|
|
|
def pipelining?
|
|
|
|
pipeline
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return the encoded URI
|
|
|
|
# ['none','hex-normal', 'hex-all', 'u-normal', 'u-all']
|
2009-11-02 18:14:57 +00:00
|
|
|
def set_encode_uri(uri)
|
2007-05-04 15:17:25 +00:00
|
|
|
a = uri
|
|
|
|
self.config['uri_encode_count'].times {
|
|
|
|
a = Rex::Text.uri_encode(a, self.config['uri_encode_mode'])
|
|
|
|
}
|
|
|
|
return a
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return the encoded query string
|
|
|
|
#
|
|
|
|
def set_encode_qs(qs)
|
2009-11-02 18:14:57 +00:00
|
|
|
a = qs
|
2007-05-04 15:17:25 +00:00
|
|
|
self.config['uri_encode_count'].times {
|
|
|
|
a = Rex::Text.uri_encode(a, self.config['uri_encode_mode'])
|
|
|
|
}
|
|
|
|
return a
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return the uri
|
|
|
|
#
|
|
|
|
def set_uri(uri)
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['uri_dir_self_reference'])
|
|
|
|
uri.gsub!('/', '/./')
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['uri_dir_fake_relative'])
|
|
|
|
buf = ""
|
|
|
|
uri.split('/').each do |part|
|
|
|
|
cnt = rand(8)+2
|
|
|
|
1.upto(cnt) { |idx|
|
2009-03-08 07:55:47 +00:00
|
|
|
buf << "/" + Rex::Text.rand_text_alphanumeric(rand(32)+1)
|
2007-02-18 22:35:07 +00:00
|
|
|
}
|
2009-03-08 07:55:47 +00:00
|
|
|
buf << ("/.." * cnt)
|
|
|
|
buf << "/" + part
|
2007-02-18 22:35:07 +00:00
|
|
|
end
|
|
|
|
uri = buf
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
if (self.config['uri_full_url'])
|
|
|
|
url = self.ssl ? "https" : "http"
|
2009-03-08 07:55:47 +00:00
|
|
|
url << self.config['vhost']
|
2009-11-30 21:15:06 +00:00
|
|
|
url << ((self.port == 80) ? "" : ":#{self.port}")
|
2009-03-08 07:55:47 +00:00
|
|
|
url << uri
|
2006-12-19 07:11:55 +00:00
|
|
|
url
|
|
|
|
else
|
|
|
|
uri
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the cgi
|
2007-02-18 22:35:07 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
def set_cgi(uri)
|
2007-02-18 22:35:07 +00:00
|
|
|
|
|
|
|
if (self.config['uri_dir_self_reference'])
|
|
|
|
uri.gsub!('/', '/./')
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['uri_dir_fake_relative'])
|
|
|
|
buf = ""
|
|
|
|
uri.split('/').each do |part|
|
|
|
|
cnt = rand(8)+2
|
|
|
|
1.upto(cnt) { |idx|
|
2009-03-08 07:55:47 +00:00
|
|
|
buf << "/" + Rex::Text.rand_text_alphanumeric(rand(32)+1)
|
2007-02-18 22:35:07 +00:00
|
|
|
}
|
2009-03-08 07:55:47 +00:00
|
|
|
buf << ("/.." * cnt)
|
|
|
|
buf << "/" + part
|
2007-02-18 22:35:07 +00:00
|
|
|
end
|
|
|
|
uri = buf
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
url = uri
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
if (self.config['uri_full_url'])
|
|
|
|
url = self.ssl ? "https" : "http"
|
2009-03-08 07:55:47 +00:00
|
|
|
url << self.config['vhost']
|
|
|
|
url << (self.port == 80) ? "" : ":#{self.port}"
|
|
|
|
url << uri
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
url
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return the HTTP method string
|
|
|
|
#
|
|
|
|
def set_method(method)
|
2007-02-18 22:35:07 +00:00
|
|
|
ret = method
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['method_random_valid'])
|
|
|
|
ret = ['GET', 'POST', 'HEAD'][rand(3)]
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['method_random_invalid'])
|
|
|
|
ret = Rex::Text.rand_text_alpha(rand(20)+1)
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['method_random_case'])
|
2007-03-08 14:08:41 +00:00
|
|
|
ret = Rex::Text.to_rand_case(ret)
|
2007-02-18 22:35:07 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-22 07:33:00 +00:00
|
|
|
ret
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP version string
|
|
|
|
#
|
2006-12-28 23:42:54 +00:00
|
|
|
def set_version(protocol, version)
|
2007-02-18 22:35:07 +00:00
|
|
|
ret = protocol + "/" + version
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['version_random_valid'])
|
|
|
|
ret = protocol + "/" + ['1.0', '1.1'][rand(2)]
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['version_random_invalid'])
|
|
|
|
ret = Rex::Text.rand_text_alphanumeric(rand(20)+1)
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['version_random_case'])
|
2007-03-08 14:08:41 +00:00
|
|
|
ret = Rex::Text.to_rand_case(ret)
|
2007-02-18 22:35:07 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
ret << "\r\n"
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP seperator and body string
|
|
|
|
#
|
|
|
|
def set_body(data)
|
2007-04-26 21:08:22 +00:00
|
|
|
return "\r\n" + data if self.config['chunked_size'] == 0
|
|
|
|
str = data.dup
|
|
|
|
chunked = ''
|
|
|
|
while str.size > 0
|
|
|
|
chunk = str.slice!(0,rand(self.config['chunked_size']) + 1)
|
2009-03-08 07:55:47 +00:00
|
|
|
chunked << sprintf("%x", chunk.size) + "\r\n" + chunk + "\r\n"
|
2007-04-26 21:08:22 +00:00
|
|
|
end
|
|
|
|
"\r\n" + chunked + "0\r\n\r\n"
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return the HTTP path info
|
|
|
|
# TODO:
|
|
|
|
# * Encode path information
|
|
|
|
def set_path_info(path)
|
|
|
|
path ? path : ''
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return the spacing between the method and uri
|
|
|
|
#
|
|
|
|
def set_method_uri_spacer
|
2007-03-08 14:08:41 +00:00
|
|
|
len = self.config['pad_method_uri_count'].to_i
|
2007-02-18 22:35:07 +00:00
|
|
|
set = " "
|
|
|
|
buf = ""
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
case self.config['pad_method_uri_type']
|
|
|
|
when 'tab'
|
|
|
|
set = "\t"
|
|
|
|
when 'apache'
|
|
|
|
set = "\t \x0b\x0c\x0d"
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
while(buf.length < len)
|
|
|
|
buf << set[ rand(set.length) ]
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
return buf
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the spacing between the uri and the version
|
|
|
|
#
|
|
|
|
def set_uri_version_spacer
|
2007-03-08 14:08:41 +00:00
|
|
|
len = self.config['pad_uri_version_count'].to_i
|
2007-02-18 22:35:07 +00:00
|
|
|
set = " "
|
|
|
|
buf = ""
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
case self.config['pad_uri_version_type']
|
|
|
|
when 'tab'
|
|
|
|
set = "\t"
|
|
|
|
when 'apache'
|
|
|
|
set = "\t \x0b\x0c\x0d"
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
while(buf.length < len)
|
|
|
|
buf << set[ rand(set.length) ]
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
return buf
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the padding to place before the uri
|
|
|
|
#
|
|
|
|
def set_uri_prepend
|
2007-03-10 05:58:14 +00:00
|
|
|
prefix = ""
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-03-10 05:58:14 +00:00
|
|
|
if (self.config['uri_fake_params_start'])
|
|
|
|
prefix << '/%3fa=b/../'
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-03-10 05:58:14 +00:00
|
|
|
if (self.config['uri_fake_end'])
|
|
|
|
prefix << '/%20HTTP/1.0/../../'
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2007-03-10 05:58:14 +00:00
|
|
|
prefix
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the padding to place before the uri
|
|
|
|
#
|
|
|
|
def set_uri_append
|
|
|
|
# TODO:
|
|
|
|
# * Support different padding types
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP Host header
|
|
|
|
#
|
2011-12-10 13:33:57 +00:00
|
|
|
def set_host_header(host=nil)
|
2006-12-19 07:11:55 +00:00
|
|
|
return "" if self.config['uri_full_url']
|
|
|
|
host ||= self.config['vhost']
|
2011-12-10 13:33:57 +00:00
|
|
|
|
|
|
|
# IPv6 addresses must be placed in brackets
|
|
|
|
if Rex::Socket.is_ipv6?(host)
|
|
|
|
host = "[#{host}]"
|
|
|
|
end
|
|
|
|
|
|
|
|
# The port should be appended if non-standard
|
|
|
|
if not [80,443].include?(self.port)
|
|
|
|
host = host + ":#{port}"
|
|
|
|
end
|
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
set_formatted_header("Host", host)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP agent header
|
|
|
|
#
|
2009-11-02 18:14:57 +00:00
|
|
|
def set_agent_header(agent)
|
2006-12-19 07:11:55 +00:00
|
|
|
agent ? set_formatted_header("User-Agent", agent) : ""
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP cookie header
|
|
|
|
#
|
|
|
|
def set_cookie_header(cookie)
|
|
|
|
cookie ? set_formatted_header("Cookie", cookie) : ""
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP connection header
|
|
|
|
#
|
|
|
|
def set_connection_header(conn)
|
2009-11-02 18:14:57 +00:00
|
|
|
conn ? set_formatted_header("Connection", conn) : ""
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return the content type header
|
|
|
|
#
|
|
|
|
def set_content_type_header(ctype)
|
|
|
|
set_formatted_header("Content-Type", ctype)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the content length header
|
|
|
|
def set_content_len_header(clen)
|
2007-04-26 21:08:22 +00:00
|
|
|
return "" if self.config['chunked_size'] > 0
|
2006-12-19 07:11:55 +00:00
|
|
|
set_formatted_header("Content-Length", clen)
|
|
|
|
end
|
2007-04-23 22:48:22 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Return the Authorization basic-auth header
|
|
|
|
#
|
|
|
|
def set_basic_auth_header(auth)
|
|
|
|
auth ? set_formatted_header("Authorization", "Basic " + Rex::Text.encode_base64(auth)) : ""
|
|
|
|
end
|
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return a string of formatted extra headers
|
2007-03-11 16:28:13 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
def set_extra_headers(headers)
|
|
|
|
buf = ''
|
|
|
|
|
2007-02-18 22:35:07 +00:00
|
|
|
if (self.config['pad_fake_headers'])
|
2007-03-08 14:08:41 +00:00
|
|
|
1.upto(self.config['pad_fake_headers_count'].to_i) do |i|
|
2009-03-08 07:55:47 +00:00
|
|
|
buf << set_formatted_header(
|
2009-11-02 18:14:57 +00:00
|
|
|
Rex::Text.rand_text_alphanumeric(rand(32)+1),
|
2007-02-18 22:35:07 +00:00
|
|
|
Rex::Text.rand_text_alphanumeric(rand(32)+1)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
headers.each_pair do |var,val|
|
2009-03-08 07:55:47 +00:00
|
|
|
buf << set_formatted_header(var, val)
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
buf
|
|
|
|
end
|
2007-04-26 21:08:22 +00:00
|
|
|
|
|
|
|
def set_chunked_header()
|
|
|
|
return "" if self.config['chunked_size'] == 0
|
|
|
|
set_formatted_header('Transfer-Encoding', 'chunked')
|
|
|
|
end
|
|
|
|
|
2007-03-11 16:28:13 +00:00
|
|
|
#
|
|
|
|
# Return a string of raw header data
|
|
|
|
#
|
|
|
|
def set_raw_headers(data)
|
|
|
|
data
|
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
#
|
|
|
|
# Return a formatted header string
|
2007-03-10 05:58:14 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
def set_formatted_header(var, val)
|
2007-03-10 05:58:14 +00:00
|
|
|
if (self.config['header_folding'])
|
|
|
|
"#{var}:\r\n\t#{val}\r\n"
|
|
|
|
else
|
|
|
|
"#{var}: #{val}\r\n"
|
|
|
|
end
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# The client request configuration
|
|
|
|
#
|
|
|
|
attr_accessor :config
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
2007-03-17 20:10:57 +00:00
|
|
|
# The client request configuration classes
|
|
|
|
#
|
|
|
|
attr_accessor :config_types
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Whether or not pipelining is in use.
|
|
|
|
#
|
2005-07-24 20:53:54 +00:00
|
|
|
attr_accessor :pipeline
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# The local host of the client.
|
|
|
|
#
|
2005-07-24 20:53:54 +00:00
|
|
|
attr_accessor :local_host
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# The local port of the client.
|
|
|
|
#
|
2005-07-24 20:53:54 +00:00
|
|
|
attr_accessor :local_port
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# The underlying connection.
|
|
|
|
#
|
2005-09-22 03:24:32 +00:00
|
|
|
attr_accessor :conn
|
2006-01-17 04:35:44 +00:00
|
|
|
#
|
|
|
|
# The calling context to pass to the socket
|
|
|
|
#
|
|
|
|
attr_accessor :context
|
2007-09-24 04:44:44 +00:00
|
|
|
#
|
|
|
|
# The proxy list
|
|
|
|
#
|
|
|
|
attr_accessor :proxies
|
2009-11-02 18:14:57 +00:00
|
|
|
|
* add junk pipelined request support
* fix socket creation on pipelined requests
* when a server says that the connection should be closed (Connection: closed), then close the connection, since its going to regardless, and we don't want to loose our state
* support non-standard line termination in headers. ie \n instead of \r\n
* add junk headers (X-rand: rand)
* add header folding (for evasion)
* add parse_header_re (still leaving parse_header around, though its dead code ATM) that does the right thing on non-standard line endings
* move 'gzip' to a 'compression' option
* add 'deflate' compression option (really, just raw zlib, and only firefox does deflate right)
* fix a bunch of TE:chunked decoding bugs based based on the fact that Apache doesn't always close chunks appropriately
* modify parse_body to not return state, since it doesn't always do that, and the return isn't used... self.state is.
* add TE:chunked request support
* normalize URIs in requests before saving them
* Move params out of the URI, but when the uri is requested, and the method is GET, and there are params, return a URI that has the params that are approrpiately encoded (needed for junk_params, see below)
* move request.to_s support of params to use the request params array when a POST, allows use of junk params support (see below). NOTE: If the body is provided, use the body instead of params, in case you want to hardcode the params in a POST request, eg: php_xmlrpc_eval.rb
* Add junk params when building a param list, eg: a=b becomes asdfasdf=asdrt32a&asdfad=okhgasd&a=b&hjklasdf=hkasgd
* add URI junk slash support (eg: /////foo.html)
* param splitting now supports both '&', and ';', which CGI.pm and PHP both allow
* add URI junk directory support, eg: /asdf/../foo.html
* add param encoding support, eg: param A with value '=' is A=%3d
* add URI junk self referring directory support, eg: /././foo.html
git-svn-id: file:///home/svn/incoming/trunk@3457 4d416f70-5f16-0410-b530-b9f4589650da
2006-01-27 21:57:44 +00:00
|
|
|
|
|
|
|
# When parsing the request, thunk off the first response from the server, since junk
|
|
|
|
attr_accessor :junk_pipeline
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
protected
|
|
|
|
|
2006-01-27 05:33:08 +00:00
|
|
|
# https
|
2009-10-26 19:48:15 +00:00
|
|
|
attr_accessor :ssl, :ssl_version # :nodoc:
|
2006-01-20 18:59:24 +00:00
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
attr_accessor :hostname, :port # :nodoc:
|
2006-12-19 07:11:55 +00:00
|
|
|
|
2009-11-02 18:14:57 +00:00
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2009-03-08 07:55:47 +00:00
|
|
|
end
|
2009-11-02 18:14:57 +00:00
|
|
|
|