Skip to content

Commit 0d4d06f

Browse files
committed
Print table for all scans, add preview size option
1 parent f593c7d commit 0d4d06f

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

modules/auxiliary/gather/memcached_extractor.rb

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def initialize(info = {})
3434

3535
register_advanced_options(
3636
[
37-
OptInt.new('MAXKEYS', [true, 'Maximum number of keys to be pulled from a slab', 100])
37+
OptInt.new('MAXKEYS', [true, 'Maximum number of keys to be pulled from each slab', 100]),
38+
OptInt.new('PRINTKEYS', [true, 'Number of keys shown in preview table for each instance', 10])
3839
], self.class
3940
)
4041
end
@@ -43,6 +44,14 @@ def max_keys
4344
datastore['MAXKEYS'].to_i
4445
end
4546

47+
def print_keys
48+
datastore['PRINTKEYS'].to_i
49+
end
50+
51+
def localhost?(ip)
52+
%w(localhost 127.0.0.1).include?(ip)
53+
end
54+
4655
# Returns array of keys for all slabs
4756
def enumerate_keys
4857
keys = []
@@ -107,13 +116,15 @@ def run_host(ip)
107116
connect
108117
if (version = determine_version)
109118
vprint_good("#{peer} - Connected to memcached version #{version}")
110-
report_service(
111-
host: ip,
112-
name: 'memcached',
113-
port: rport,
114-
proto: 'tcp',
115-
info: version
116-
)
119+
unless localhost?(ip)
120+
report_service(
121+
host: ip,
122+
name: 'memcached',
123+
port: rport,
124+
proto: 'tcp',
125+
info: version
126+
)
127+
end
117128
else
118129
print_error("#{peer} - unable to determine memcached protocol version")
119130
return
@@ -123,18 +134,17 @@ def run_host(ip)
123134
return if keys.size == 0
124135

125136
data = data_for_keys(keys)
126-
if %w(localhost 127.0.0.1).include?(ip)
127-
result_table = Rex::Ui::Text::Table.new(
128-
'Header' => "Keys/Values Found for #{ip}:#{rport}",
129-
'Indent' => 1,
130-
'Columns' => [ 'Key', 'Value' ]
131-
)
132-
data.take(10).each { |r| result_table << r }
133-
print_line
134-
print_line("#{result_table}")
135-
else
137+
result_table = Rex::Ui::Text::Table.new(
138+
'Header' => "Keys/Values Found for #{peer}",
139+
'Indent' => 1,
140+
'Columns' => [ 'Key', 'Value' ]
141+
)
142+
data.take(print_keys).each { |r| result_table << r }
143+
print_line
144+
print_line("#{result_table}")
145+
unless localhost?(ip)
136146
path = store_loot('memcached.dump', 'text/plain', ip, data, 'memcached.txt', 'Memcached extractor')
137-
print_good("#{peer} - memcached loot stored as #{path}")
147+
print_good("#{peer} - memcached loot stored at #{path}")
138148
end
139149
rescue Rex::ConnectionRefused, Rex::ConnectionTimeout
140150
vprint_error("#{peer} - Could not connect to memcached server!")

0 commit comments

Comments
 (0)