Module: Watobo::Mixin::Parser::Web10

Defined in:
lib/watobo/mixins/httpparser.rb

Constant Summary

Constants included from Constants

Constants::AC_GROUP_APACHE, Constants::AC_GROUP_DOMINO, Constants::AC_GROUP_ENUMERATION, Constants::AC_GROUP_FILE_INCLUSION, Constants::AC_GROUP_FLASH, Constants::AC_GROUP_GENERIC, Constants::AC_GROUP_JBOSS, Constants::AC_GROUP_JOOMLA, Constants::AC_GROUP_SAP, Constants::AC_GROUP_SQL, Constants::AC_GROUP_TYPO3, Constants::AC_GROUP_XSS, Constants::AUTH_TYPE_BASIC, Constants::AUTH_TYPE_DIGEST, Constants::AUTH_TYPE_NONE, Constants::AUTH_TYPE_NTLM, Constants::CHAT_SOURCE_AUTO_SCAN, Constants::CHAT_SOURCE_FUZZER, Constants::CHAT_SOURCE_INTERCEPT, Constants::CHAT_SOURCE_MANUAL, Constants::CHAT_SOURCE_MANUAL_SCAN, Constants::CHAT_SOURCE_PROXY, Constants::CHAT_SOURCE_UNDEF, Constants::DEFAULT_PORT_HTTP, Constants::DEFAULT_PORT_HTTPS, Constants::FINDING_TYPE_HINT, Constants::FINDING_TYPE_INFO, Constants::FINDING_TYPE_UNDEFINED, Constants::FINDING_TYPE_VULN, Constants::FIRST_TIME_FILE, Constants::GUI_REGULAR_FONT_SIZE, Constants::GUI_SMALL_FONT_SIZE, Constants::ICON_PATH, Constants::LOG_DEBUG, Constants::LOG_INFO, Constants::SCAN_CANCELED, Constants::SCAN_FINISHED, Constants::SCAN_PAUSED, Constants::SCAN_STARTED, Constants::TE_CHUNKED, Constants::TE_COMPRESS, Constants::TE_DEFLATE, Constants::TE_GZIP, Constants::TE_IDENTITY, Constants::TE_NONE, Constants::VULN_RATING_CRITICAL, Constants::VULN_RATING_HIGH, Constants::VULN_RATING_INFO, Constants::VULN_RATING_LOW, Constants::VULN_RATING_MEDIUM, Constants::VULN_RATING_UNDEFINED

Instance Method Summary collapse

Instance Method Details

#bodyObject


605
606
607
608
609
610
611
612
# File 'lib/watobo/mixins/httpparser.rb', line 605

def body
  begin
    return nil if self.nil? or self.length < 3
    return self.last if self[-2].strip.empty?
  rescue
    return nil
  end
end

#body_encodedObject


625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/watobo/mixins/httpparser.rb', line 625

def body_encoded
  b = self.body
  cs = self.charset
  return nil if b.nil?
  return b.unpack("C*").pack("C*") if cs.nil?
  begin
      return  b.encode(cs, :invalid => :replace, :undef => :replace, :replace => '').unpack("C*").pack("C*")
  rescue => bang
    puts bang
    puts bang.backtrace if $DEBUG
    return b.unpack("C*").pack("C*")
  end
end

#body_is_text?Boolean

Returns:

  • (Boolean)

614
615
616
617
618
619
620
621
622
623
# File 'lib/watobo/mixins/httpparser.rb', line 614

def body_is_text?
  ct = self.content_type(nil) 
  if ct.nil?
    return true if self.body_encoded.ascii_only?
    return false
  else
    return true if ct =~ /text/
    return false
  end
end

#charsetObject


679
680
681
682
683
684
685
686
687
688
689
# File 'lib/watobo/mixins/httpparser.rb', line 679

def charset
  cs = nil
  self.each do |line|
    break if line.strip.empty?
    if line =~ /^Content-Type: .*charset=([^;]*)/i then
      cs = $1
      break
    end
  end
  return cs
end

#content_encodingObject


502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/watobo/mixins/httpparser.rb', line 502

def content_encoding
  te = TE_NONE
  self.each do |line|
    break if line.strip.empty?
    if line =~ /^Content-Encoding: (.*)/i then
      dummy = $1.strip
      puts "Content-Encoding => #{dummy}"
      te = case dummy
      when /chunked/i
        TE_CHUNKED
      when /compress/i
        TE_COMPRESS
      when /zip/i
        TE_GZIP
      when /deflate/i
        TE_DEFLATE
      when /identity/i
        TE_IDENTITY
      else
        TE_NONE
      end
      break
    end
  end
  return te
end

#content_lengthObject


488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/watobo/mixins/httpparser.rb', line 488

def content_length
  # Note: Calculate Chunk-Encoded Content-Length
  # this is only possible if the whole body is loaded???
  ct = -1
  self.each do |line|
    break if line.strip.empty?
    if line =~ /^Content-Length: (.*)/i then
      ct = $1.to_i
      break
    end
  end
  return ct
end

#content_type(default_ct = 'undefined') ⇒ Object


464
465
466
467
468
469
470
471
472
473
474
# File 'lib/watobo/mixins/httpparser.rb', line 464

def content_type(default_ct='undefined')
  ct = default_ct
  self.each do |line|
    break if line.strip.empty?
    if line =~ /^Content-Type: ([^;]*);?/i then
      ct = $1
      break
    end
  end
  return ct.strip
end

#content_type_ex(default_ct = 'undefined') ⇒ Object


476
477
478
479
480
481
482
483
484
485
486
# File 'lib/watobo/mixins/httpparser.rb', line 476

def content_type_ex(default_ct='undefined')
  ct = default_ct
  self.each do |line|
    break if line.strip.empty?
    if line =~ /^Content-Type: (.*)/i then
      ct = $1.strip
      break
    end
  end
  return ct.strip
end

#contentMD5Object


558
559
560
561
562
# File 'lib/watobo/mixins/httpparser.rb', line 558

def contentMD5
  b = self.body.nil? ? "" : self.body
  hash = Digest::MD5.hexdigest(b)
  return hash
end

#cookiesObject


719
720
721
722
723
724
725
726
727
728
729
730
731
732
# File 'lib/watobo/mixins/httpparser.rb', line 719

def cookies
  cookie_list=[]
  self.headers.each do |line|
    if line =~ /Cookie2?: (.*)/i then
      clist = $1.split(";")
      clist.each do |c|
        # c.gsub!(/^[ ]+/,"")
        # c.chomp!
        cookie_list.push c.strip
      end
    end
  end
  return cookie_list
end

#data_UNUSEDObject


734
735
736
737
# File 'lib/watobo/mixins/httpparser.rb', line 734

def data_UNUSED
  return self.last.strip if self.last =~ /\=.*\&?/i
  return ""
end

#has_body?Boolean

Returns:

  • (Boolean)

593
594
595
# File 'lib/watobo/mixins/httpparser.rb', line 593

def has_body?
  self.body.nil? ? false : true
end

#has_header?(name) ⇒ Boolean

Returns:

  • (Boolean)

597
598
599
600
601
602
603
# File 'lib/watobo/mixins/httpparser.rb', line 597

def has_header?(name)
  self.each do |l|
    return false if l.strip.empty?
    return true if l =~ /^#{name}:/i
  end
  return false
end

#header_value(header_name) ⇒ Object

end


446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/watobo/mixins/httpparser.rb', line 446

def header_value(header_name)
  header_values =[]
  self.headers.each do |header|
    begin
    if header =~ /^#{header_name}/i then
      dummy = header.split(/:/)
      value=dummy[1]
      value.gsub!(/^[ ]*/,"")
      header_values.push value
    end
    rescue => bang
      puts bang
      puts bang.backtrace if $DEBUG
    end
  end
  return header_values
end

#headers(filter = nil, &b) ⇒ Object


691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
# File 'lib/watobo/mixins/httpparser.rb', line 691

def headers(filter=nil, &b)
  begin
  header_list=[]
  self.each do |line|
    cl = line.unpack("C*").pack("C*")
    return header_list if cl.strip.empty?
    unless filter.nil?
      if cl =~ /#{filter}/
      yield line if block_given?
      header_list.push line
      end
    else
      yield line if block_given?
      header_list.push line
    end
  end
  return header_list
  rescue => bang
    puts "! no headers available !".upcase
    puts bang
    if $DEBUG
      puts bang.backtrace
      puts self.to_yaml
    end
    return nil
  end
end

#new_cookies(&b) ⇒ Object

returns array of new cookies Set-Cookie: mycookie=b41dc9e55d6163f78321996b10c940edcec1b4e55a76464c4e9d25e160ac0ec5b769806b; Path=/


649
650
651
652
653
654
655
656
657
# File 'lib/watobo/mixins/httpparser.rb', line 649

def new_cookies(&b)
  nc = []
  headers("Set-Cookie") do |h|
    cookie = Watobo::Cookie.new(h)
    yield cookie if block_given?
    nc << cookie
  end
  nc
end

#parm_namesObject


396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/watobo/mixins/httpparser.rb', line 396

def parm_names
  parm_names=[]
  parmlist=[]
  parmlist.concat(get_parms)
  parmlist.concat(post_parms)
  parmlist.each do |p|
    p.gsub!(/=.*/,'')
    parm_names.push p
  end

  return parm_names

end

#parmsObject


388
389
390
391
392
393
394
# File 'lib/watobo/mixins/httpparser.rb', line 388

def parms
  parmlist=[]
  parmlist.concat(get_parms)
  parmlist.concat(post_parms)

  return parmlist
end

#post_parm_names(&block) ⇒ Object


410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/watobo/mixins/httpparser.rb', line 410

def post_parm_names(&block)

  parm_names=[]
  parmlist=[]

  parmlist.concat(post_parms)
  parmlist.each do |p|
    if p then
      p.gsub!(/=.*/,'')
      p.strip!
      yield p if block_given?
      parm_names << p
    end
  end

  return parm_names

end

#post_parm_value(parm_name) ⇒ Object

def get_parm_value(parm_name)

  parm_value = ""
  self.get_parms.each do |parm|
    if parm =~ /^#{Regexp.quote(parm_name)}=/i then
      dummy = parm.split(/=/)
      if dummy.length > 1 then
        #  parm_value=dummy[1].gsub(/^[ ]*/,"")
        parm_value=dummy[1].strip
      end
    end
  end
  return parm_value
end

578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/watobo/mixins/httpparser.rb', line 578

def post_parm_value(parm_name)
  parm_value=""
  self.post_parms.each do |parm|
    if parm =~ /#{Regexp.quote(parm_name)}/i then
      dummy = parm.split(/=/)
      if dummy.length > 1 then
        parm_value = dummy[1].strip
      else
        # puts "Uhhhh ... need parameter value from '#{parm}''"
      end
    end
  end
  return parm_value
end

#post_parmsObject


370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/watobo/mixins/httpparser.rb', line 370

def post_parms
  parmlist=[]
  return parmlist unless has_body?
  begin
  if self.last =~ /\=.*\&?/i
    parmlist = self.last.split(/\&/)
  end
  rescue => bang
    # puts self.last.unpack("C*").pack("C*").gsub(/[^[:print:]]/,".")
    if $DEBUG
      puts bang
    puts bang.backtrace 
   
    end
  end
  return parmlist
end

#responseCodeObject


639
640
641
642
643
644
645
# File 'lib/watobo/mixins/httpparser.rb', line 639

def responseCode
  if self.first =~ /^HTTP\/... (\d+) /
    return $1
  else
    return nil
  end
end

#statusObject


659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/watobo/mixins/httpparser.rb', line 659

def status
  begin
  # Filter bad utf-8 chars
  dummy = self.first.unpack("C*").pack("C*")

  if dummy =~ /^HTTP\/1\.\d{1,2} (.*)/i then
    return $1.chomp
  else
    return ''
  end
  rescue => bang
    if $DEBUG
    puts "! No Status Available !".upcase
    puts bang
    puts bang.backtrace
    end 
    return nil
  end
end

#transferEncodingObject Also known as: transfer_encoding


529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/watobo/mixins/httpparser.rb', line 529

def transferEncoding
  te = TE_NONE
  self.each do |line|
    break if line.strip.empty?
    if line =~ /^Transfer-Encoding: (.*)/i then
      dummy = $1.strip
     # puts dummy
      te = case dummy
      when 'chunked'
        TE_CHUNKED
      when 'compress'
        TE_COMPRESS
      when 'zip'
        TE_GZIP
      when 'deflate'
        TE_DEFLATE
      when 'identity'
        TE_IDENTITY
      else
        TE_NONE
      end
      break
    end
  end
  return te
end