Class: Rex::Proto::Http::Client

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

Overview

Acts as a client to an HTTP server, sending requests and receiving responses.

See the RFC: www.w3.org/Protocols/rfc2616/rfc2616.html

Constant Summary collapse

DefaultUserAgent =
ClientRequest::DefaultUserAgent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 80, context = {}, ssl = nil, ssl_version = nil, proxies = nil, username = '', password = '') ⇒ Client

Creates a new client instance



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rex/proto/http/client.rb', line 27

def initialize(host, port = 80, context = {}, ssl = nil, ssl_version = nil, proxies = nil, username = '', password = '')
  self.hostname = host
  self.port     = port.to_i
  self.context  = context
  self.ssl      = ssl
  self.ssl_version = ssl_version
  self.proxies  = proxies
  self.username = username
  self.password = password

  # Take ClientRequest's defaults, but override with our own
  self.config = Http::ClientRequest::DefaultConfig.merge({
    'read_max_data'   => (1024*1024*1),
    'vhost'           => self.hostname,
  })

  # XXX: This info should all be controlled by ClientRequest
  self.config_types = {
    'uri_encode_mode'        => ['hex-normal', 'hex-all', 'hex-random', 'u-normal', 'u-random', 'u-all'],
    'uri_encode_count'       => 'integer',
    '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',
    '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',
    'header_folding'         => 'bool',
    'chunked_size'           => 'integer',
    'partial'                => 'bool'
  }


end

Instance Attribute Details

#configObject

The client request configuration



654
655
656
# File 'lib/rex/proto/http/client.rb', line 654

def config
  @config
end

#config_typesObject

The client request configuration classes



658
659
660
# File 'lib/rex/proto/http/client.rb', line 658

def config_types
  @config_types
end

#connObject

The underlying connection.



674
675
676
# File 'lib/rex/proto/http/client.rb', line 674

def conn
  @conn
end

#contextObject

The calling context to pass to the socket



678
679
680
# File 'lib/rex/proto/http/client.rb', line 678

def context
  @context
end

#hostnameObject (protected)

:nodoc:



695
696
697
# File 'lib/rex/proto/http/client.rb', line 695

def hostname
  @hostname
end

#junk_pipelineObject

When parsing the request, thunk off the first response from the server, since junk



688
689
690
# File 'lib/rex/proto/http/client.rb', line 688

def junk_pipeline
  @junk_pipeline
end

#local_hostObject

The local host of the client.



666
667
668
# File 'lib/rex/proto/http/client.rb', line 666

def local_host
  @local_host
end

#local_portObject

The local port of the client.



670
671
672
# File 'lib/rex/proto/http/client.rb', line 670

def local_port
  @local_port
end

#passwordObject

Auth



685
686
687
# File 'lib/rex/proto/http/client.rb', line 685

def password
  @password
end

#pipelineObject

Whether or not pipelining is in use.



662
663
664
# File 'lib/rex/proto/http/client.rb', line 662

def pipeline
  @pipeline
end

#portObject (protected)

:nodoc:



695
696
697
# File 'lib/rex/proto/http/client.rb', line 695

def port
  @port
end

#proxiesObject

The proxy list



682
683
684
# File 'lib/rex/proto/http/client.rb', line 682

def proxies
  @proxies
end

#sslObject (protected)

https



693
694
695
# File 'lib/rex/proto/http/client.rb', line 693

def ssl
  @ssl
end

#ssl_versionObject (protected)

https



693
694
695
# File 'lib/rex/proto/http/client.rb', line 693

def ssl_version
  @ssl_version
end

#usernameObject

Auth



685
686
687
# File 'lib/rex/proto/http/client.rb', line 685

def username
  @username
end

Instance Method Details

#_send_recv(req, t = -1,, persist = false) ⇒ Response

Transmit an HTTP request and receive the response

If persist is set, then the request will attempt to reuse an existing connection.

Call this directly instead of #send_recv if you don't want automatic authentication handling.

Returns:



228
229
230
231
232
233
234
235
# File 'lib/rex/proto/http/client.rb', line 228

def _send_recv(req, t = -1, persist = false)
  @pipeline = persist
  send_request(req, t)
  res = read_response(t)
  res.request = req.to_s if res
  res.peerinfo = peerinfo if res
  res
end

#basic_auth_header(username, password) ⇒ String

Converts username and password into the HTTP Basic authorization string.

Returns:

  • (String)

    A value suitable for use as an Authorization header



310
311
312
313
# File 'lib/rex/proto/http/client.rb', line 310

def basic_auth_header(username,password)
  auth_str = username.to_s + ":" + password.to_s
  auth_str = "Basic " + Rex::Text.encode_base64(auth_str)
end

#closeObject

Closes the connection to the remote server.



194
195
196
197
198
199
200
201
# File 'lib/rex/proto/http/client.rb', line 194

def close
  if self.conn && !self.conn.closed?
    self.conn.shutdown
    self.conn.close
  end

  self.conn = nil
end

#conn?Boolean

Returns whether or not the conn is valid.

Returns:

  • (Boolean)


624
625
626
# File 'lib/rex/proto/http/client.rb', line 624

def conn?
  conn != nil
end

#connect(t = -1)) ⇒ Rex::Socket::Tcp

Connects to the remote server if possible.

Parameters:

  • t (Integer) (defaults to: -1))

    Timeout

Returns:

  • (Rex::Socket::Tcp)

See Also:

  • Socket::Tcp.create


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/rex/proto/http/client.rb', line 166

def connect(t = -1)
  # If we already have a connection and we aren't pipelining, close it.
  if (self.conn)
    if !pipelining?
      close
    else
      return self.conn
    end
  end

  timeout = (t.nil? or t == -1) ? 0 : t

  self.conn = Rex::Socket::Tcp.create(
    'PeerHost'   => self.hostname,
    'PeerPort'   => self.port.to_i,
    'LocalHost'  => self.local_host,
    'LocalPort'  => self.local_port,
    'Context'    => self.context,
    'SSL'        => self.ssl,
    'SSLVersion' => self.ssl_version,
    'Proxies'    => self.proxies,
    'Timeout'    => timeout
  )
end

#digest_auth(opts = {}) ⇒ Response

Send a series of requests to complete Digest Authentication

Parameters:

  • opts (Hash) (defaults to: {})

    the options used to build an HTTP request

Returns:

  • (Response)

    the last valid HTTP response we received



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'lib/rex/proto/http/client.rb', line 324

def digest_auth(opts={})
  cnonce = make_cnonce
  nonce_count = 0

  to = opts['timeout'] || 20

  digest_user = opts['username'] || ""
  digest_password =  opts['password'] || ""

  method = opts['method']
  path = opts['uri']
  iis = true
  if (opts['DigestAuthIIS'] == false or self.config['DigestAuthIIS'] == false)
    iis = false
  end

  begin
  nonce_count += 1

  resp = opts['response']

  if not resp
    # Get authentication-challenge from server, and read out parameters required
    r = request_cgi(opts.merge({
        'uri' => path,
        'method' => method }))
    resp = _send_recv(r, to)
    unless resp.kind_of? Rex::Proto::Http::Response
      return nil
    end

    if resp.code != 401
      return resp
    end
    return resp unless resp.headers['WWW-Authenticate']
  end

  # Don't anchor this regex to the beginning of string because header
  # folding makes it appear later when the server presents multiple
  # WWW-Authentication options (such as is the case with IIS configured
  # for Digest or NTLM).
  resp['www-authenticate'] =~ /Digest (.*)/

  parameters = {}
  $1.split(/,[[:space:]]*/).each do |p|
    k, v = p.split("=", 2)
    parameters[k] = v.gsub('"', '')
  end

  qop = parameters['qop']

  if parameters['algorithm'] =~ /(.*?)(-sess)?$/
    algorithm = case $1
    when 'MD5' then Digest::MD5
    when 'SHA1' then Digest::SHA1
    when 'SHA2' then Digest::SHA2
    when 'SHA256' then Digest::SHA256
    when 'SHA384' then Digest::SHA384
    when 'SHA512' then Digest::SHA512
    when 'RMD160' then Digest::RMD160
    else raise Error, "unknown algorithm \"#{$1}\""
    end
    algstr = parameters["algorithm"]
    sess = $2
  else
    algorithm = Digest::MD5
    algstr = "MD5"
    sess = false
  end

  a1 = if sess then
    [
      algorithm.hexdigest("#{digest_user}:#{parameters['realm']}:#{digest_password}"),
      parameters['nonce'],
      cnonce
    ].join ':'
  else
    "#{digest_user}:#{parameters['realm']}:#{digest_password}"
  end

  ha1 = algorithm.hexdigest(a1)
  ha2 = algorithm.hexdigest("#{method}:#{path}")

  request_digest = [ha1, parameters['nonce']]
  request_digest.push(('%08x' % nonce_count), cnonce, qop) if qop
  request_digest << ha2
  request_digest = request_digest.join ':'

  # Same order as IE7
  auth = [
    "Digest username=\"#{digest_user}\"",
    "realm=\"#{parameters['realm']}\"",
    "nonce=\"#{parameters['nonce']}\"",
    "uri=\"#{path}\"",
    "cnonce=\"#{cnonce}\"",
    "nc=#{'%08x' % nonce_count}",
    "algorithm=#{algstr}",
    "response=\"#{algorithm.hexdigest(request_digest)[0, 32]}\"",
    # The spec says the qop value shouldn't be enclosed in quotes, but
    # some versions of IIS require it and Apache accepts it.  Chrome
    # and Firefox both send it without quotes but IE does it this way.
    # Use the non-compliant-but-everybody-does-it to be as compatible
    # as possible by default.  The user can override if they don't like
    # it.
    if qop.nil? then
    elsif iis then
      "qop=\"#{qop}\""
    else
      "qop=#{qop}"
    end,
    if parameters.key? 'opaque' then
      "opaque=\"#{parameters['opaque']}\""
    end
  ].compact

  headers ={ 'Authorization' => auth.join(', ') }
  headers.merge!(opts['headers']) if opts['headers']

  # Send main request with authentication
  r = request_cgi(opts.merge({
    'uri' => path,
    'method' => method,
    'headers' => headers }))
  resp = _send_recv(r, to, true)
  unless resp.kind_of? Rex::Proto::Http::Response
    return nil
  end

  return resp

  rescue ::Errno::EPIPE, ::Timeout::Error
  end
end

#make_cnonceObject



316
317
318
# File 'lib/rex/proto/http/client.rb', line 316

def make_cnonce
  Digest::MD5.hexdigest "%x" % (Time.now.to_i + rand(65535))
end

#negotiate_auth(opts = {}) ⇒ Response

Builds a series of requests to complete Negotiate Auth. Works essentially the same way as Digest auth. Same pipelining concerns exist.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • provider ("Negotiate", "NTLM")

    What Negotiate provider to use

Returns:

  • (Response)

    the last valid HTTP response we received



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/rex/proto/http/client.rb', line 466

def negotiate_auth(opts={})

  to = opts['timeout'] || 20
  opts['username'] ||= ''
  opts['password'] ||= ''

  if opts['provider'] and opts['provider'].include? 'Negotiate'
    provider = "Negotiate "
  else
    provider = "NTLM "
  end

  opts['method']||= 'GET'
  opts['headers']||= {}

  workstation_name = Rex::Text.rand_text_alpha(rand(8)+6)
  domain_name = self.config['domain']

  ntlm_client = ::Net::NTLM::Client.new(
    opts['username'],
    opts['password'],
    workstation: workstation_name,
    domain: domain_name,
  )
  type1 = ntlm_client.init_context

  begin
    # First request to get the challenge
    opts['headers']['Authorization'] = provider + type1.encode64

    r = request_cgi(opts)
    resp = _send_recv(r, to)
    unless resp.kind_of? Rex::Proto::Http::Response
      return nil
    end

    return resp unless resp.code == 401 && resp.headers['WWW-Authenticate']

    # Get the challenge and craft the response
    ntlm_challenge = resp.headers['WWW-Authenticate'].scan(/#{provider}([A-Z0-9\x2b\x2f=]+)/ni).flatten[0]
    return resp unless ntlm_challenge

    ntlm_message_3 = ntlm_client.init_context(ntlm_challenge)

    # Send the response
    opts['headers']['Authorization'] = "#{provider}#{ntlm_message_3.encode64}"
    r = request_cgi(opts)
    resp = _send_recv(r, to, true)
    unless resp.kind_of? Rex::Proto::Http::Response
      return nil
    end
    return resp

  rescue ::Errno::EPIPE, ::Timeout::Error
    return nil
  end
end

#peerinfoObject

Target host addr and port for this connection



638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/rex/proto/http/client.rb', line 638

def peerinfo
  if self.conn
    pi = self.conn.peerinfo || nil
    if pi
      return {
        'addr' => pi.split(':')[0],
        'port' => pi.split(':')[1].to_i
      }
    end
  end
  nil
end

#pipelining?Boolean

Whether or not connections should be pipelined.

Returns:

  • (Boolean)


631
632
633
# File 'lib/rex/proto/http/client.rb', line 631

def pipelining?
  pipeline
end

#read_response(t = -1,, opts = {}) ⇒ Response

Read a response from the server

Wait at most t seconds for the full response to be read in. If t is specified as a negative value, it indicates an indefinite wait cycle. If t is specified as nil or 0, it indicates no response parsing is required.

Returns:



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/rex/proto/http/client.rb', line 532

def read_response(t = -1, opts = {})
  # Return a nil response if timeout is nil or 0
  return if t.nil? || t == 0

  resp = Response.new
  resp.max_data = config['read_max_data']

  Timeout.timeout((t < 0) ? nil : t) do

    rv = nil
    while (
             not conn.closed? and
             rv != Packet::ParseCode::Completed and
             rv != Packet::ParseCode::Error
            )

      begin

        buff = conn.get_once(resp.max_data, 1)
        rv   = resp.parse(buff || '')

      # Handle unexpected disconnects
      rescue ::Errno::EPIPE, ::EOFError, ::IOError
        case resp.state
        when Packet::ParseState::ProcessingHeader
          resp = nil
        when Packet::ParseState::ProcessingBody
          # truncated request, good enough
          resp.error = :truncated
        end
        break
      end

      # 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
          # XXX: This doesn't deal with chunked encoding or "Content-type: text/html; charset=..."
          while tries < 1000 and resp.headers["Content-Type"]== "text/html" and rblob !~ /<\/html>/i
            buff = conn.get_once(-1, 0.05)
            break if not buff
            rblob += buff
            tries += 1
          end
        rescue ::Errno::EPIPE, ::EOFError, ::IOError
        end

        resp.bufq = ""
        resp.body = rblob
      end
    end
  end

  return resp if not resp

  # As a last minute hack, we check to see if we're dealing with a 100 Continue here.
  # Most of the time this is handled by the parser via check_100()
  if resp.proto == '1.1' and resp.code == 100 and not opts[:skip_100]
    # Read the real response from the body if we found one
    # If so, our real response became the body, so we re-parse it.
    if resp.body.to_s =~ /^HTTP/
      body = resp.body
      resp = Response.new
      resp.max_data = config['read_max_data']
      rv = resp.parse(body)
    # We found a 100 Continue but didn't read the real reply yet
    # Otherwise reread the reply, but don't try this hack again
    else
      resp = read_response(t, :skip_100 => true)
    end
  end

  resp
rescue Timeout::Error
  # Allow partial response due to timeout
  resp if config['partial']
end

#request_cgi(opts = {}) ⇒ ClientRequest

Create a CGI compatible request

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • Content-Type ('ctype'String)

    header value, default: application/x-www-form-urlencoded

  • URI ('encode_params'Bool)

    encode the GET or POST variables (names and values), default: true

  • GET ('vars_get'Hash)

    variables as a hash to be translated into a query string

  • POST ('vars_post'Hash)

    variables as a hash to be translated into POST data

  • User-Agent ('agent'String)

    header value

  • Connection ('connection'String)

    header value

  • Cookie ('cookie'String)

    header value

  • HTTP ('data'String)

    data (only useful with some methods, see rfc2616)

  • URI ('encode'Bool)

    encode the supplied URI, default: false

  • HTTP ('headers'Hash)

    headers, e.g. { "X-MyHeader" => "value" }

  • HTTP ('method'String)

    method to use in the request, not limited to standard methods defined by rfc2616, default: GET

  • protocol, ('proto'String)

    default: HTTP

  • raw ('query'String)

    query string

  • Raw ('raw_headers'String)

    HTTP headers

  • the ('uri'String)

    URI to request

  • version ('version'String)

    of the protocol, default: 1.1

  • Host ('vhost'String)

    header value

Returns:



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/rex/proto/http/client.rb', line 148

def request_cgi(opts={})
  opts = self.config.merge(opts)

  opts['ctype']       ||= 'application/x-www-form-urlencoded'
  opts['ssl']         = self.ssl
  opts['cgi']         = true
  opts['port']        = self.port

  req = ClientRequest.new(opts)
  req
end

#request_raw(opts = {}) ⇒ ClientRequest

Create an arbitrary HTTP request

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • User-Agent ('agent'String)

    header value

  • Connection ('connection'String)

    header value

  • Cookie ('cookie'String)

    header value

  • HTTP ('data'String)

    data (only useful with some methods, see rfc2616)

  • URI ('encode'Bool)

    encode the supplied URI, default: false

  • HTTP ('headers'Hash)

    headers, e.g. { "X-MyHeader" => "value" }

  • HTTP ('method'String)

    method to use in the request, not limited to standard methods defined by rfc2616, default: GET

  • protocol, ('proto'String)

    default: HTTP

  • raw ('query'String)

    query string

  • Raw ('raw_headers'String)

    HTTP headers

  • the ('uri'String)

    URI to request

  • version ('version'String)

    of the protocol, default: 1.1

  • Host ('vhost'String)

    header value

Returns:



126
127
128
129
130
131
132
133
134
# File 'lib/rex/proto/http/client.rb', line 126

def request_raw(opts={})
  opts = self.config.merge(opts)

  opts['ssl']         = self.ssl
  opts['cgi']         = false
  opts['port']        = self.port

  req = ClientRequest.new(opts)
end

#send_auth(res, opts, t, persist) ⇒ Response

Resends an HTTP Request with the propper authentcation headers set. If we do not support the authentication type the server requires we return the original response object

Parameters:

  • res (Response)

    the HTTP Response object

  • opts (Hash)

    the options used to generate the original HTTP request

  • t (Integer)

    the timeout for the request in seconds

  • persist (Boolean)

    whether or not to persist the TCP connection (pipelining)

Returns:

  • (Response)

    the last valid HTTP response object we received



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/rex/proto/http/client.rb', line 259

def send_auth(res, opts, t, persist)
  if opts['username'].nil? or opts['username'] == ''
    if self.username and not (self.username == '')
      opts['username'] = self.username
      opts['password'] = self.password
    else
      opts['username'] = nil
      opts['password'] = nil
    end
  end

  return res if opts['username'].nil? or opts['username'] == ''
  supported_auths = res.headers['WWW-Authenticate']

  # if several providers are available, the client may want one in particular
  preferred_auth = opts['preferred_auth']

  if supported_auths.include?('Basic') && (preferred_auth.nil? || preferred_auth == 'Basic')
    opts['headers'] ||= {}
    opts['headers']['Authorization'] = basic_auth_header(opts['username'],opts['password'] )
    req = request_cgi(opts)
    res = _send_recv(req,t,persist)
    return res
  elsif supported_auths.include?('Digest') && (preferred_auth.nil? || preferred_auth == 'Digest')
    temp_response = digest_auth(opts)
    if temp_response.kind_of? Rex::Proto::Http::Response
      res = temp_response
    end
    return res
  elsif supported_auths.include?('NTLM') && (preferred_auth.nil? || preferred_auth == 'NTLM')
    opts['provider'] = 'NTLM'
    temp_response = negotiate_auth(opts)
    if temp_response.kind_of? Rex::Proto::Http::Response
      res = temp_response
    end
    return res
  elsif supported_auths.include?('Negotiate') && (preferred_auth.nil? || preferred_auth == 'Negotiate')
    opts['provider'] = 'Negotiate'
    temp_response = negotiate_auth(opts)
    if temp_response.kind_of? Rex::Proto::Http::Response
      res = temp_response
    end
    return res
  end
  return res
end

#send_recv(req, t = -1,, persist = false) ⇒ Response

Sends a request and gets a response back

If the request is a 401, and we have creds, it will attempt to complete authentication and return the final response

Returns:



210
211
212
213
214
215
216
# File 'lib/rex/proto/http/client.rb', line 210

def send_recv(req, t = -1, persist = false)
  res = _send_recv(req, t, persist)
  if res and res.code == 401 and res.headers['WWW-Authenticate']
    res = send_auth(res, req.opts, t, persist)
  end
  res
end

#send_request(req, t = -1)) ⇒ void

This method returns an undefined value.

Send an HTTP request to the server

Parameters:

  • req (Request, ClientRequest, #to_s)

    The request to send

  • t (Integer) (defaults to: -1))

    Timeout



244
245
246
247
# File 'lib/rex/proto/http/client.rb', line 244

def send_request(req, t = -1)
  connect(t)
  conn.put(req.to_s)
end

#set_config(opts = {}) ⇒ Object

Set configuration options



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rex/proto/http/client.rb', line 79

def set_config(opts = {})
  opts.each_pair do |var,val|
    # Default type is string
    typ = self.config_types[var] || 'string'

    # These are enum types
    if typ.is_a?(Array)
      if not typ.include?(val)
        raise RuntimeError, "The specified value for #{var} is not one of the valid choices"
      end
    end

    # The caller should have converted these to proper ruby types, but
    # take care of the case where they didn't before setting the
    # config.

    if(typ == 'bool')
      val = (val =~ /^(t|y|1)/i ? true : false || val === true)
    end

    if(typ == 'integer')
      val = val.to_i
    end

    self.config[var]=val
  end
end

#stopObject

Cleans up any outstanding connections and other resources.



617
618
619
# File 'lib/rex/proto/http/client.rb', line 617

def stop
  close
end