Class: Rex::Proto::Http::ClientRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/http/client_request.rb

Constant Summary collapse

DefaultUserAgent =
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
DefaultConfig =
{
  #
  # Regular HTTP stuff
  #
  'agent'                  => DefaultUserAgent,
  'cgi'                    => true,
  'cookie'                 => nil,
  'data'                   => '',
  'headers'                => nil,
  'raw_headers'            => '',
  'method'                 => 'GET',
  'path_info'              => '',
  'port'                   => 80,
  'proto'                  => 'HTTP',
  'query'                  => '',
  'ssl'                    => false,
  'uri'                    => '/',
  'vars_get'               => {},
  'vars_post'              => {},
  'version'                => '1.1',
  'vhost'                  => nil,

  #
  # Evasion options
  #
  'encode_params'          => true,
  'encode'                 => false,
  'uri_encode_mode'        => 'hex-normal', # hex-all, hex-random, u-normal, u-random, u-all
  'uri_encode_count'       => 1,       # integer
  '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
  'pad_get_params'         => false,   # bool
  'pad_get_params_count'   => 8,       # integer
  'pad_post_params'        => false,   # bool
  'pad_post_params_count'  => 8,       # integer
  'uri_fake_end'           => false,   # bool
  'uri_fake_params_start'  => false,   # bool
  'header_folding'         => false,   # bool
  'chunked_size'           => 0,        # integer

  #
  # NTLM Options
  #
  'usentlm2_session' => true,
  'use_ntlmv2'       => true,
  'send_lm'         => true,
  'send_ntlm'       => true,
  'SendSPN'  => true,
  'UseLMKey' => false,
  'domain' => 'WORKSTATION',
  #
  # Digest Options
  #
  'DigestAuthIIS' => true
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ClientRequest


88
89
90
91
# File 'lib/rex/proto/http/client_request.rb', line 88

def initialize(opts={})
  @opts = DefaultConfig.merge(opts)
  @opts['headers'] ||= {}
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts


86
87
88
# File 'lib/rex/proto/http/client_request.rb', line 86

def opts
  @opts
end

Instance Method Details

#to_sObject


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/rex/proto/http/client_request.rb', line 93

def to_s

  # Start GET query string
  qstr = opts['query'] ? opts['query'].dup : ""

  # Start POST data string
  pstr = opts['data'] ? opts['data'].dup : ""

  if opts['cgi']
    uri_str = set_uri

    if (opts['pad_get_params'])
      1.upto(opts['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 << '='
        qstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
      end
    end

    opts['vars_get'].each_pair do |var,val|
      var = var.to_s
      val = val.to_s

      qstr << '&' if qstr.length > 0
      qstr << (opts['encode_params'] ? set_encode_uri(var) : var)
      qstr << '='
      qstr << (opts['encode_params'] ? set_encode_uri(val) : val)
    end

    if (opts['pad_post_params'])
      1.upto(opts['pad_post_params_count'].to_i) do |i|
        rand_var = Rex::Text.rand_text_alphanumeric(rand(32)+1)
        rand_val = Rex::Text.rand_text_alphanumeric(rand(32)+1)
        pstr << '&' if pstr.length > 0
        pstr << (opts['encode_params'] ? set_encode_uri(rand_var) : rand_var)
        pstr << '='
        pstr << (opts['encode_params'] ? set_encode_uri(rand_val) : rand_val)
      end
    end

    opts['vars_post'].each_pair do |var,val|
      var = var.to_s
      val = val.to_s

      pstr << '&' if pstr.length > 0
      pstr << (opts['encode_params'] ? set_encode_uri(var) : var)
      pstr << '='
      pstr << (opts['encode_params'] ? set_encode_uri(val) : val)
    end
  else
    if opts['encode']
      qstr = set_encode_uri(qstr)
    end
    uri_str = set_uri
  end

  req = ''
  req << set_method
  req << set_method_uri_spacer()
  req << set_uri_prepend()

  if opts['encode']
    req << set_encode_uri(uri_str)
  else
    req << uri_str
  end


  if (qstr.length > 0)
    req << '?'
    req << qstr
  end

  req << set_path_info
  req << set_uri_append()
  req << set_uri_version_spacer()
  req << set_version
  req << set_host_header

  # If an explicit User-Agent header is set, then use that instead of
  # the default
  unless opts['headers'] and opts['headers'].keys.map{|x| x.downcase }.include?('user-agent')
    req << set_agent_header
  end

  # Similar to user-agent, only add an automatic auth header if a
  # manual one hasn't been provided
  unless opts['headers'] and opts['headers'].keys.map{|x| x.downcase }.include?('authorization')
    req << set_auth_header
  end

  req << set_cookie_header
  req << set_connection_header
  req << set_extra_headers

  req << set_content_type_header
  req << set_content_len_header(pstr.length)
  req << set_chunked_header()
  req << opts['raw_headers']
  req << set_body(pstr)
end