Skip to content

Commit a199dc3

Browse files
committed
used the recvfrom timeout
1 parent 999006e commit a199dc3

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

modules/auxiliary/scanner/chargen/chargen_probe.rb

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,28 @@ def initialize
4545
deregister_options('RHOST')
4646
end
4747

48-
def to
49-
return 5 if datastore['TIMEOUT'].to_i.zero?
50-
datastore['TIMEOUT'].to_i
51-
end
52-
5348
def run_host(rhost)
5449
begin
55-
::Timeout.timeout(to) do
56-
connect_udp
57-
pkt = Rex::Text.rand_text_alpha_lower(1)
58-
req = udp_sock.write(pkt)
50+
connect_udp
51+
pkt = Rex::Text.rand_text_alpha_lower(1)
52+
req = udp_sock.write(pkt)
5953

60-
while ((res = udp_sock.recvfrom(65535,0.1)) && (res[1]))
54+
while ((res = udp_sock.recvfrom(65535,0.1)) && (res[1]))
6155

62-
vprint_status("#{rhost}:#{rport} - Response: #{res[0].to_s}")
56+
vprint_status("#{rhost}:#{rport} - Response: #{res[0].to_s}")
6357

64-
res = res[0].to_s.strip
65-
if (res.match(/ABCDEFGHIJKLMNOPQRSTUVWXYZ/i) || res.match(/0123456789/))
66-
print_good("#{rhost}:#{rport} answers with #{res.length} bytes (headers + UDP payload)")
67-
report_service(:host => rhost, :port => rport, :name => "chargen", :info => res.length)
68-
end
58+
res = res[0].to_s.strip
59+
if (res.match(/ABCDEFGHIJKLMNOPQRSTUVWXYZ/i) || res.match(/0123456789/))
60+
print_good("#{rhost}:#{rport} answers with #{res.length} bytes (headers + UDP payload)")
61+
report_service(:host => rhost, :port => rport, :name => "chargen", :info => res.length)
6962
end
63+
end
7064

71-
disconnect_udp
72-
end
73-
rescue ::Rex::ConnectionError
74-
rescue Timeout::Error
75-
vprint_error("#{rhost}:#{rport} server timed out after #{to} seconds. Skipping.")
76-
rescue ::Exception => e
77-
vprint_error("#{e} #{e.backtrace}")
65+
disconnect_udp
66+
rescue ::Interrupt
67+
raise $!
68+
rescue ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionRefused
69+
nil
7870
end
7971
end
8072
end

0 commit comments

Comments
 (0)