Skip to content

Commit 493e476

Browse files
committed
Land rapid7#6243, check nil for sock.read
2 parents 5654b6b + 0cda20c commit 493e476

File tree

8 files changed

+54
-24
lines changed

8 files changed

+54
-24
lines changed

modules/auxiliary/scanner/db2/discovery.rb

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,37 @@ def run_host(ip)
3232

3333
connect_udp
3434
udp_sock.put(pkt)
35-
res = udp_sock.read(1024).split(/\x00/)
36-
37-
if (res)
38-
report_note(
39-
:host => ip,
40-
:proto => 'udp',
41-
:port => datastore['RPORT'],
42-
:type => 'SERVICE_INFO',
43-
:data => res[2] + "_" + res[1]
44-
)
45-
report_service(
46-
:host => ip,
47-
:port => datastore['RPORT'],
48-
:proto => 'udp',
49-
:name => "ibm-db2",
50-
:info => res[2] + "_" + res[1]
51-
)
52-
print_status("Host #{ip} node name is " + res[2] + " with a product id of " + res[1] )
53-
else
35+
res = udp_sock.read(1024)
36+
37+
unless res
5438
print_error("Unable to determine version info for #{ip}")
39+
return
5540
end
5641

57-
disconnect_udp
42+
res = res.split(/\x00/)
43+
44+
report_note(
45+
:host => ip,
46+
:proto => 'udp',
47+
:port => datastore['RPORT'],
48+
:type => 'SERVICE_INFO',
49+
:data => "#{res[2]}_#{res[1]}"
50+
)
51+
52+
report_service(
53+
:host => ip,
54+
:port => datastore['RPORT'],
55+
:proto => 'udp',
56+
:name => "ibm-db2",
57+
:info => "#{res[2]}_#{res[1]}"
58+
)
59+
60+
print_status("Host #{ip} node name is " + res[2] + " with a product id of " + res[1] )
5861

5962
rescue ::Rex::ConnectionError
6063
rescue ::Errno::EPIPE
61-
64+
ensure
65+
disconnect_udp
6266
end
6367

6468
end

modules/auxiliary/scanner/ftp/bison_ftp_traversal.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ def run_host(target_host)
7171
# read the file data from the socket that we opened
7272
response_data = sock.read(1024)
7373

74+
unless response_data
75+
print_error("#{file} not found")
76+
return
77+
end
78+
7479
if response_data.length == 0
7580
print_status("File (#{file_path})from #{peer} is empty...")
7681
return

modules/auxiliary/scanner/ftp/pcman_ftp_traversal.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def run_host(target_host)
7070
# read the file data from the socket that we opened
7171
response_data = sock.read(1024)
7272

73+
unless response_data
74+
print_error("#{file_path} not found")
75+
return
76+
end
77+
7378
if response_data.length == 0 or ! (res =~ /^150/ )
7479
print_status("File (#{file_path})from #{peer} is empty...")
7580
return

modules/auxiliary/scanner/motorola/timbuktu_udp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def run_host(ip)
5252
else
5353
print_error("Unable to determine info for #{ip}...")
5454
end
55+
ensure
5556
disconnect_udp
56-
rescue ::Errno::EPIPE, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionRefused
5757
end
5858
end
5959
end

modules/auxiliary/scanner/oracle/tnspoison_checker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def run_host(ip)
4242
send_packet = tns_packet("(CONNECT_DATA=(COMMAND=service_register_NSGR))")
4343
sock.put(send_packet)
4444
packet = sock.read(100)
45-
find_packet = packet.include? "(ERROR_STACK=(ERROR="
45+
find_packet = /\(ERROR_STACK=\(ERROR=/ === packet
4646
find_packet == true ? print_error("#{ip}:#{rport} is not vulnerable ") : print_good("#{ip}:#{rport} is vulnerable")
4747
# TODO: Module should report_vuln if this finding is solid.
4848
rescue ::Rex::ConnectionError, ::Errno::EPIPE

modules/auxiliary/scanner/sap/sap_router_info_request.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ def run_host(ip)
109109
print_good("#{host_port} - Connected to saprouter")
110110
print_good("#{host_port} - Sending ROUTER_ADM packet info request")
111111
sock.put(ni_packet)
112-
packet_len = sock.read(4).unpack('H*')[0].to_i 16
112+
sock_res = sock.read(4)
113+
unless sock_res
114+
fail_with(Failure::Unknown, 'Unable to get the packet length')
115+
end
116+
packet_len = sock_res.unpack('H*')[0].to_i 16
113117
print_good("#{host_port} - Got INFO response")
114118
while packet_len !=0
115119
count += 1

modules/post/windows/gather/forensics/nbd_server.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ def run
7676

7777
while true
7878
request = rsock.read(28)
79+
80+
unless request
81+
print_error("No data received")
82+
break
83+
end
84+
7985
magic, request, nbd_handle, offset_n, length = request.unpack("NNa8a8N")
8086

8187
if magic != 0x25609513

modules/post/windows/manage/nbd_server.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def run
7474

7575
while true
7676
request = rsock.read(28)
77+
78+
unless request
79+
print_error("No data received")
80+
break
81+
end
82+
7783
magic, request, nbd_handle, offset_n, length = request.unpack("NNa8a8N")
7884

7985
if magic != 0x25609513

0 commit comments

Comments
 (0)