4
4
##
5
5
6
6
require 'msf/core'
7
+ require 'recog'
7
8
8
9
class Metasploit3 < Msf ::Auxiliary
9
10
include Msf ::Exploit ::Remote ::Tcp
@@ -36,10 +37,15 @@ def initialize
36
37
)
37
38
end
38
39
40
+ def peer
41
+ "#{ rhost } :#{ rport } "
42
+ end
43
+
39
44
def timeout
40
45
datastore [ 'TIMEOUT' ] <= 0 ? DEFAULT_TIMEOUT : datastore [ 'TIMEOUT' ]
41
46
end
42
47
48
+
43
49
def run_host ( target_host )
44
50
begin
45
51
::Timeout . timeout ( timeout ) do
@@ -48,19 +54,25 @@ def run_host(target_host)
48
54
resp = sock . get_once ( -1 , timeout )
49
55
50
56
if resp
51
- if resp =~ /^SSH/
52
- ver , msg = resp . split ( /[\r \n ]+/ )
57
+ ident , first_message = resp . split ( /[\r \n ]+/ )
58
+ if /^SSH-\d +\. \d +-(?<banner>.*)$/ =~ ident
59
+ if recog_match = Recog ::Nizer . match ( 'ssh.banner' , banner )
60
+ info = recog_match . to_s
61
+ else
62
+ info = 'UNKNOWN'
63
+ print_warning ( "#{ peer } unknown SSH banner: #{ banner } " )
64
+ end
53
65
# Check to see if this is Kippo, which sends a premature
54
66
# key init exchange right on top of the SSH version without
55
67
# waiting for the required client identification string.
56
- if msg && msg . size >= 5
57
- extra = msg . unpack ( "NCCA*" ) # sz, pad_sz, code, data
68
+ if first_message && first_message . size >= 5
69
+ extra = first_message . unpack ( "NCCA*" ) # sz, pad_sz, code, data
58
70
if ( extra . last . size + 2 == extra [ 0 ] ) && extra [ 2 ] == 20
59
- ver << " (Kippo Honeypot)"
71
+ info << " (Kippo Honeypot)"
60
72
end
61
73
end
62
- print_status ( "#{ target_host } :#{ rport } , SSH server version: #{ ver } " )
63
- report_service ( host : rhost , port : rport , name : 'ssh' , proto : 'tcp' , info : ver )
74
+ print_status ( "#{ target_host } :#{ rport } , SSH server version: #{ ident } " )
75
+ report_service ( host : rhost , port : rport , name : 'ssh' , proto : 'tcp' , info : info )
64
76
else
65
77
vprint_warning ( "#{ target_host } :#{ rport } was not SSH --" \
66
78
" #{ resp . size } bytes beginning with #{ resp [ 0 , 12 ] } " )
0 commit comments