@@ -445,28 +445,28 @@ def proxies
445
445
# destination host and port. This method falls back to using the old
446
446
# service.info field to represent the HTTP Server header.
447
447
#
448
- # Options:
449
- # @option opts [String] :uri An HTTP URI to request in order to generate a fingerprint
450
- # @option opts [String] :method An HTTP method to use in the fingerprint request
451
- #
448
+ # @option opts [String] :uri ('/') An HTTP URI to request in order to generate
449
+ # a fingerprint
450
+ # @option opts [String] :method ('GET') An HTTP method to use in the fingerprint
451
+ # request
452
452
def lookup_http_fingerprints ( opts = { } )
453
453
uri = opts [ :uri ] || '/'
454
454
method = opts [ :method ] || 'GET'
455
455
fprints = [ ]
456
-
456
+
457
457
return fprints unless framework . db . active
458
-
458
+
459
459
::ActiveRecord ::Base . connection_pool . with_connection {
460
460
wspace = datastore [ 'WORKSPACE' ] ?
461
461
framework . db . find_workspace ( datastore [ 'WORKSPACE' ] ) : framework . db . workspace
462
462
463
463
service = framework . db . get_service ( wspace , rhost , 'tcp' , rport )
464
464
return fprints unless service
465
-
465
+
466
466
# Order by note_id descending so the first value is the most recent
467
467
service . notes . where ( :ntype => 'http.fingerprint' ) . order ( "notes.id DESC" ) . each do |n |
468
- next unless n . data and n . data . kind_of? ( ::Hash )
469
- next unless n . data [ :uri ] == uri and n . data [ :method ] == method
468
+ next unless n . data && n . data . kind_of? ( ::Hash )
469
+ next unless n . data [ :uri ] == uri && n . data [ :method ] == method
470
470
# Append additional fingerprints to the results as found
471
471
fprints . unshift n . data . dup
472
472
end
@@ -481,14 +481,18 @@ def lookup_http_fingerprints(opts={})
481
481
# will use it directly, otherwise it will check the database for a previous
482
482
# fingerprint. Failing that, it will make a request for /.
483
483
#
484
- # Options:
485
- # :response an Http::Packet as returned from any of the send_* methods
486
- # :uri an HTTP URI to request in order to generate a fingerprint
487
- # :method an HTTP method to use in the fingerprint request
488
- # :full request the full HTTP fingerprint, not just the signature
484
+ # Other options are passed directly to {#connect} if :response is not given
489
485
#
490
- # Other options are passed directly to +connect+ if :response is not given
486
+ # @option opts [Rex::Proto::Http::Packet] :response The return value from any
487
+ # of the send_* methods
488
+ # @option opts [String] :uri ('/') An HTTP URI to request in order to generate
489
+ # a fingerprint
490
+ # @option opts [String] :method ('GET') An HTTP method to use in the fingerprint
491
+ # request
492
+ # @option opts [Boolean] :full (false) Request the full HTTP fingerprint, not
493
+ # just the signature
491
494
#
495
+ # @return [String]
492
496
def http_fingerprint ( opts = { } )
493
497
res = nil
494
498
uri = opts [ :uri ] || '/'
@@ -502,7 +506,7 @@ def http_fingerprint(opts={})
502
506
fprints = lookup_http_fingerprints ( opts )
503
507
504
508
if fprints . length > 0
505
-
509
+
506
510
# Grab the most recent fingerprint available for this service, uri, and method
507
511
fprint = fprints . last
508
512
@@ -528,9 +532,9 @@ def http_fingerprint(opts={})
528
532
# This section handles a few simple cases of pattern matching and service
529
533
# classification. This logic should be deprecated in favor of Recog-based
530
534
# fingerprint databases, but has been left in place for backward compat.
531
-
535
+
532
536
extras = [ ]
533
-
537
+
534
538
if res . headers [ 'Set-Cookie' ] =~ /^vmware_soap_session/
535
539
extras << "VMWare Web Services"
536
540
end
@@ -601,8 +605,8 @@ def http_fingerprint(opts={})
601
605
info << " ( #{ extras . join ( ", " ) } )" if extras . length > 0
602
606
603
607
# Create a new fingerprint structure to track this response
604
- fprint = {
605
- :uri => uri , :method => method ,
608
+ fprint = {
609
+ :uri => uri , :method => method ,
606
610
:code => res . code . to_s , :message => res . message . to_s ,
607
611
:signature => info
608
612
}
@@ -614,7 +618,7 @@ def http_fingerprint(opts={})
614
618
# Set-Cookie > :header_set_cookie => JSESSIONID=AAASD23423452
615
619
# Server > :header_server => Apache/1.3.37
616
620
# WWW-Authenticate > :header_www_authenticate => basic realm='www'
617
-
621
+
618
622
fprint [ "header_#{ hname } " . intern ] = v
619
623
end
620
624
@@ -623,22 +627,22 @@ def http_fingerprint(opts={})
623
627
624
628
# Report a new http.fingerprint note
625
629
report_note (
626
- :host => rhost ,
627
- :port => rport ,
628
- :proto => 'tcp' ,
629
- :ntype => 'http.fingerprint' ,
630
+ :host => rhost ,
631
+ :port => rport ,
632
+ :proto => 'tcp' ,
633
+ :ntype => 'http.fingerprint' ,
630
634
:data => fprint ,
631
- # Limit reporting to one stored note per host/service combination
635
+ # Limit reporting to one stored note per host/service combination
632
636
:update => :unique
633
637
)
634
638
635
639
# Report here even if info is empty since the fact that we didn't
636
640
# return early means we at least got a connection and the service is up
637
641
report_web_site ( :host => rhost , :port => rport , :ssl => ssl , :vhost => vhost , :info => info . dup )
638
-
642
+
639
643
# Return the full HTTP fingerprint if requested by the caller
640
644
return fprint if opts [ :full ]
641
-
645
+
642
646
# Otherwise just return the signature string for compatibility
643
647
fprint [ :signature ]
644
648
end
0 commit comments