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
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Acts as a client to an HTTP server, sending requests and receiving
|
2006-12-19 07:11:55 +00:00
|
|
|
# responses.
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
|
|
|
###
|
|
|
|
class Client
|
|
|
|
|
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
|
|
|
#
|
2006-01-20 18:59:24 +00:00
|
|
|
def initialize(host, port = 80, context = {}, ssl = 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
|
2006-12-19 07:11:55 +00:00
|
|
|
self.config = {
|
|
|
|
'read_max_data' => (1024*1024*1),
|
|
|
|
'vhost' => self.hostname,
|
|
|
|
'version' => '1.1',
|
|
|
|
'agent' => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
|
|
|
|
'uri_encode_mode' => 'hex-normal',
|
|
|
|
'uri_full_url' => false
|
2005-09-15 23:37:38 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
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|
|
|
|
|
config[var]=val
|
|
|
|
end
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
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'
|
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_ag = opts['agent'] || config['agent']
|
|
|
|
c_cook = opts['cookie'] || config['cookie']
|
|
|
|
c_host = opts['vhost'] || config['vhost']
|
|
|
|
c_head = opts['headers'] || config['headers'] || {}
|
|
|
|
c_conn = opts['connection']
|
|
|
|
uri = set_uri(c_uri)
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
req = ''
|
|
|
|
req += set_method(c_meth)
|
|
|
|
req += set_method_uri_spacer()
|
|
|
|
req += set_uri_prepend()
|
|
|
|
req += (c_enc ? set_encode_uri(uri) : uri)
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
if (c_qs)
|
|
|
|
req += '?'
|
|
|
|
req += (c_enc ? set_encode_qs(c_qs) : c_qs)
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2006-12-19 07:11:55 +00:00
|
|
|
|
|
|
|
req += set_uri_append()
|
|
|
|
req += set_uri_version_spacer()
|
2006-12-28 23:42:54 +00:00
|
|
|
req += set_version(c_prot, c_vers)
|
2006-12-19 07:11:55 +00:00
|
|
|
req += set_host_header(c_host)
|
|
|
|
req += set_agent_header(c_ag)
|
|
|
|
req += set_cookie_header(c_cook)
|
|
|
|
req += set_connection_header(c_conn)
|
|
|
|
req += set_extra_headers(c_head)
|
|
|
|
req += set_body(c_body)
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
req
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Create a CGI compatible request
|
|
|
|
#
|
|
|
|
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'] || {}
|
|
|
|
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']
|
|
|
|
c_path = opts['path_info']
|
|
|
|
uri = set_cgi(c_cgi)
|
|
|
|
qstr = c_qs
|
|
|
|
pstr = c_body
|
2005-09-15 23:37:38 +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
|
|
|
|
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
|
2006-12-19 07:11:55 +00:00
|
|
|
|
|
|
|
req = ''
|
|
|
|
req += set_method(c_meth)
|
|
|
|
req += set_method_uri_spacer()
|
|
|
|
req += set_uri_prepend()
|
|
|
|
req += set_encode_uri(uri)
|
|
|
|
|
|
|
|
if (qstr.length > 0)
|
|
|
|
req += '?'
|
|
|
|
req += qstr
|
2005-09-15 23:37:38 +00:00
|
|
|
end
|
2006-12-19 07:11:55 +00:00
|
|
|
|
|
|
|
req += set_path_info(c_path)
|
|
|
|
req += set_uri_append()
|
|
|
|
req += set_uri_version_spacer()
|
2006-12-28 23:42:54 +00:00
|
|
|
req += set_version(c_prot, c_vers)
|
2006-12-19 07:11:55 +00:00
|
|
|
req += set_host_header(c_host)
|
|
|
|
req += set_agent_header(c_ag)
|
|
|
|
req += set_cookie_header(c_cook)
|
|
|
|
req += set_connection_header(c_conn)
|
|
|
|
req += set_extra_headers(c_head)
|
|
|
|
|
|
|
|
# TODO:
|
|
|
|
# * Implement chunked transfer
|
|
|
|
|
|
|
|
req += set_content_type_header(c_type)
|
|
|
|
req += set_content_len_header(pstr.length)
|
|
|
|
req += set_body(pstr)
|
|
|
|
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
def connect
|
|
|
|
# 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
|
|
|
|
|
|
|
|
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,
|
|
|
|
'SSL' => self.ssl
|
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
|
|
|
|
self.conn.close
|
|
|
|
end
|
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
self.conn = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
# Transmit a HTTP request and receive the response
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
def send_recv(req, t = -1)
|
|
|
|
send_request(req)
|
|
|
|
read_response(t)
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
# Send a HTTP request to the server
|
|
|
|
# TODO:
|
|
|
|
# * Handle junk pipeline requests
|
|
|
|
def send_request(req)
|
2005-07-24 20:53:54 +00:00
|
|
|
# Connect to the server
|
|
|
|
connect
|
|
|
|
|
* 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
|
|
|
# build the request
|
|
|
|
req_string = req.to_s
|
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
# Send it on over
|
2006-12-19 07:11:55 +00:00
|
|
|
ret = conn.put(req)
|
|
|
|
|
|
|
|
# Tell the remote side if we aren't pipelining
|
|
|
|
conn.shutdown(::Socket::SHUT_WR) if (!pipelining?)
|
|
|
|
|
|
|
|
ret
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Read a response from the server
|
|
|
|
#
|
|
|
|
def read_response(t = -1)
|
|
|
|
resp = Response.new
|
|
|
|
resp.max_data = config['read_max_data']
|
2005-07-24 20:53:54 +00:00
|
|
|
|
|
|
|
# Tell the remote side if we aren't pipelining
|
|
|
|
conn.shutdown(::Socket::SHUT_WR) if (!pipelining?)
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
timeout((t < 0) ? nil : t) {
|
|
|
|
# Now, read in the response until we're good to go.
|
|
|
|
begin
|
* 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.junk_pipeline
|
|
|
|
i = 0
|
|
|
|
self.junk_pipeline.times {
|
|
|
|
i += 1
|
|
|
|
rv = nil
|
|
|
|
|
|
|
|
while rv != Packet::ParseCode::Completed
|
|
|
|
if (rv == Packet::ParseCode::Error)
|
|
|
|
warn "ERR : #{resp.error}"
|
|
|
|
raise RuntimeError, resp.error, caller
|
|
|
|
end
|
|
|
|
|
|
|
|
if resp.bufq.length > 0
|
|
|
|
rv = resp.parse('')
|
|
|
|
else
|
|
|
|
rv = resp.parse(conn.get)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if resp['Connection'] == 'close'
|
|
|
|
raise RuntimeError, "junk pipelined request ##{i} caused the server to close the connection", caller
|
|
|
|
end
|
|
|
|
|
|
|
|
buf = resp.bufq
|
|
|
|
resp.reset
|
|
|
|
resp.bufq = buf
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
rv = nil
|
|
|
|
if resp.bufq.length > 0
|
|
|
|
rv = resp.parse('')
|
|
|
|
end
|
|
|
|
|
|
|
|
if rv != Packet::ParseCode::Completed
|
|
|
|
# Keep running until we finish parsing or EOF is reached
|
|
|
|
while ((rv = resp.parse(conn.get)) != Packet::ParseCode::Completed)
|
|
|
|
# Parsing error? Raise an exception, our job is done.
|
|
|
|
if (rv == Packet::ParseCode::Error)
|
|
|
|
raise RuntimeError, resp.error, caller
|
|
|
|
end
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue EOFError
|
|
|
|
end
|
|
|
|
} if (t)
|
|
|
|
|
|
|
|
# Close our side if we aren't pipelining
|
|
|
|
close if (!pipelining?)
|
|
|
|
|
* 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 the server said stop pipelining, we listen...
|
|
|
|
if resp['Connection'] == 'close'
|
|
|
|
close
|
|
|
|
end
|
|
|
|
|
2005-09-15 23:37:38 +00:00
|
|
|
# XXX - How should we handle this?
|
|
|
|
if (not resp.completed?)
|
|
|
|
# raise RuntimeError, resp.error, caller
|
|
|
|
end
|
|
|
|
|
|
|
|
# Always return the Response object back to the client
|
|
|
|
return 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
|
2006-12-19 07:11:55 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Return the encoded URI
|
|
|
|
# ['none','hex-normal', 'hex-all', 'u-normal', 'u-all']
|
|
|
|
def set_encode_uri(uri)
|
|
|
|
Rex::Text.uri_encode(uri, self.config['uri_encode_mode'])
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the encoded query string
|
|
|
|
#
|
|
|
|
def set_encode_qs(qs)
|
|
|
|
Rex::Text.uri_encode(uri, self.config['uri_encode_mode'])
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the uri
|
|
|
|
#
|
|
|
|
def set_uri(uri)
|
|
|
|
if (self.config['uri_full_url'])
|
|
|
|
url = self.ssl ? "https" : "http"
|
|
|
|
url += self.config['vhost']
|
|
|
|
url += (self.port == 80) ? "" : ":#{self.port}"
|
|
|
|
url += uri
|
|
|
|
url
|
|
|
|
else
|
|
|
|
uri
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the cgi
|
|
|
|
# TODO:
|
|
|
|
# * Implement self-referential directories
|
|
|
|
# * Implement bogus relative directories
|
|
|
|
def set_cgi(uri)
|
|
|
|
|
|
|
|
url = uri
|
|
|
|
|
|
|
|
if (self.config['uri_full_url'])
|
|
|
|
url = self.ssl ? "https" : "http"
|
|
|
|
url += self.config['vhost']
|
|
|
|
url += (self.port == 80) ? "" : ":#{self.port}"
|
|
|
|
url += uri
|
|
|
|
end
|
|
|
|
|
|
|
|
url
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP method string
|
|
|
|
#
|
|
|
|
def set_method(method)
|
|
|
|
# TODO:
|
|
|
|
# * Randomize case
|
|
|
|
# * Replace with random valid method
|
|
|
|
# * Replace with random invalid method
|
|
|
|
method
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP version string
|
|
|
|
#
|
2006-12-28 23:42:54 +00:00
|
|
|
def set_version(protocol, version)
|
2006-12-19 07:11:55 +00:00
|
|
|
# TODO:
|
|
|
|
# * Randomize case
|
|
|
|
# * Replace with random valid versions
|
|
|
|
# * Replace with random invalid versions
|
2006-12-28 23:42:54 +00:00
|
|
|
protocol + "/" + version + "\r\n"
|
2006-12-19 07:11:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP seperator and body string
|
|
|
|
#
|
|
|
|
def set_body(data)
|
|
|
|
"\r\n" + data
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP path info
|
|
|
|
# TODO:
|
|
|
|
# * Encode path information
|
|
|
|
def set_path_info(path)
|
|
|
|
path ? path : ''
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the spacing between the method and uri
|
|
|
|
#
|
|
|
|
def set_method_uri_spacer
|
|
|
|
# TODO:
|
|
|
|
# * Support different space types
|
|
|
|
" "
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the spacing between the uri and the version
|
|
|
|
#
|
|
|
|
def set_uri_version_spacer
|
|
|
|
# TODO:
|
|
|
|
# * Support different space types
|
|
|
|
" "
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the padding to place before the uri
|
|
|
|
#
|
|
|
|
def set_uri_prepend
|
|
|
|
# TODO:
|
|
|
|
# * Support different padding types
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the padding to place before the uri
|
|
|
|
#
|
|
|
|
def set_uri_append
|
|
|
|
# TODO:
|
|
|
|
# * Support different padding types
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP Host header
|
|
|
|
#
|
|
|
|
def set_host_header(host)
|
|
|
|
return "" if self.config['uri_full_url']
|
|
|
|
host ||= self.config['vhost']
|
|
|
|
set_formatted_header("Host", host)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the HTTP agent header
|
|
|
|
#
|
|
|
|
def set_agent_header(agent)
|
|
|
|
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)
|
|
|
|
conn ? set_formatted_header("Connection", conn) : ""
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the content type header
|
|
|
|
#
|
|
|
|
def set_content_type_header(ctype)
|
|
|
|
set_formatted_header("Content-Type", ctype)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the content length header
|
|
|
|
# TODO:
|
|
|
|
# * Ignore this if chunked encoding is set
|
|
|
|
def set_content_len_header(clen)
|
|
|
|
set_formatted_header("Content-Length", clen)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return a string of formatted extra headers
|
|
|
|
# TODO:
|
|
|
|
# * Implement junk header stuffing
|
|
|
|
def set_extra_headers(headers)
|
|
|
|
buf = ''
|
|
|
|
|
|
|
|
headers.each_pair do |var,val|
|
|
|
|
buf += set_formatted_header(var, val)
|
|
|
|
end
|
|
|
|
|
|
|
|
buf
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return a formatted header string
|
|
|
|
# TODO:
|
|
|
|
# * Implement header folder
|
|
|
|
def set_formatted_header(var, val)
|
|
|
|
"#{var}: #{val}\r\n"
|
|
|
|
end
|
|
|
|
|
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
|
|
|
#
|
|
|
|
# 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
|
* 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
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
protected
|
|
|
|
|
2006-01-27 05:33:08 +00:00
|
|
|
# https
|
2006-01-20 18:59:24 +00:00
|
|
|
attr_accessor :ssl
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
attr_accessor :hostname, :port # :nodoc:
|
2006-12-19 07:11:55 +00:00
|
|
|
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|