Skip to content

Commit 0b0ac14

Browse files
committed
Merge remote-tracking branch 'upstream/master' into extapi_service_post
Conflicts: test/modules/post/test/services.rb
2 parents 42b6c54 + db36789 commit 0b0ac14

File tree

31 files changed

+753
-230
lines changed

31 files changed

+753
-230
lines changed

lib/metasploit/framework/login_scanner/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ module Base
5757
inclusion: { in: [true, false] }
5858

5959
validates :bruteforce_speed,
60-
presence: false,
6160
numericality: {
61+
allow_nil: true,
6262
only_integer: true,
6363
greater_than_or_equal_to: 0,
6464
less_than_or_equal_to: 5

lib/msf/core/db_manager/ip_address.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ def ipv6_validator(addr)
1313
end
1414

1515
def rfc3330_reserved(ip)
16-
case ip.class.to_s
17-
when "PacketFu::Octets"
16+
case ip
17+
when PacketFu::Octets
1818
ip_x = ip.to_x
1919
ip_i = ip.to_i
20-
when "String"
20+
when String
2121
if ipv46_validator(ip)
2222
ip_x = ip
2323
ip_i = Rex::Socket.addr_atoi(ip)
2424
else
2525
raise ArgumentError, "Invalid IP address: #{ip.inspect}"
2626
end
27-
when "Fixnum"
27+
when Fixnum
2828
if (0..2**32-1).include? ip
2929
ip_x = Rex::Socket.addr_itoa(ip)
3030
ip_i = ip
@@ -58,4 +58,4 @@ def validate_ips(ips)
5858
end
5959
return ret
6060
end
61-
end
61+
end

lib/msf/core/exploit/cmdstager.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ def select_flavor(opts = {})
224224
def guess_flavor
225225
# First try to guess a compatible flavor based on the module & target information.
226226
unless target_flavor.nil?
227-
case target_flavor.class.to_s
228-
when 'Array'
227+
case target_flavor
228+
when Array
229229
return target_flavor[0].to_sym
230-
when 'String'
230+
when String
231231
return target_flavor.to_sym
232-
when 'Symbol'
232+
when Symbol
233233
return target_flavor
234234
end
235235
end
@@ -283,12 +283,12 @@ def target_flavor
283283
# @return [Boolean] true if compatible, false otherwise.
284284
def compatible_flavor?(f)
285285
return true if target_flavor.nil?
286-
case target_flavor.class.to_s
287-
when 'String'
286+
case target_flavor
287+
when String
288288
return true if target_flavor == f.to_s
289-
when 'Array'
289+
when Array
290290
target_flavor.each { |tr| return true if tr.to_sym == f }
291-
when 'Symbol'
291+
when Symbol
292292
return true if target_flavor == f
293293
end
294294
false

lib/msf/core/exploit/java.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def compile(classnames, codez, compile_options=nil)
8787
raise RuntimeError, "Could not load rjb and/or the JVM: " + @java_error.to_s
8888
end
8989

90-
if compile_options.class.to_s != "Array" && compile_options
90+
if !compile_options.is_a?(Array) && compile_options
9191
raise RuntimeError, "Compiler options must be of type Array."
9292
end
9393

lib/msf/core/exploit/local/windows_kernel.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def token_stealing_shellcode(target, backup_token = nil, arch = nil)
123123
arch = target.opts['Arch'] if arch.nil? && target && target.opts['Arch']
124124
if arch.nil? && module_info['Arch']
125125
arch = module_info['Arch']
126-
arch = arch[0] if arch.class.to_s == 'Array' and arch.length == 1
126+
arch = arch[0] if arch.is_a?(Array) and arch.length == 1
127127
end
128128
if arch.nil?
129129
print_error('Can not determine the target architecture')

lib/msf/core/exploit/pdf.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(info = {})
3030
#Original Filters
3131
##
3232

33-
def ASCIIHexWhitespaceEncode(str)
33+
def ascii_hex_whitespace_encode(str)
3434
return str if not datastore['PDF::Obfuscate']
3535
result = ""
3636
whitespace = ""
@@ -44,7 +44,7 @@ def ASCIIHexWhitespaceEncode(str)
4444
##
4545
#Filters from Origami parser
4646
##
47-
def RunLengthEncode(stream)
47+
def run_length_encode(stream)
4848
eod = 128
4949
result = ""
5050
i = 0
@@ -85,15 +85,15 @@ def RunLengthEncode(stream)
8585
result << eod.chr
8686
end
8787

88-
def RandomNonASCIIString(count)
88+
def random_non_ascii_string(count)
8989
result = ""
9090
count.times do
9191
result << (rand(128) + 128).chr
9292
end
9393
result
9494
end
9595

96-
def ASCII85Encode(stream)
96+
def ascii85_encode(stream)
9797
eod = "~>"
9898
i = 0
9999
code = ""
@@ -130,7 +130,7 @@ def ASCII85Encode(stream)
130130
end
131131

132132
# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
133-
def nObfu(str)
133+
def nobfu(str)
134134
return str if not datastore['PDF::Obfuscate']
135135

136136
result = ""
@@ -149,13 +149,13 @@ def nObfu(str)
149149
##
150150
def header(version = '1.5')
151151
hdr = "%PDF-#{version}" << eol
152-
hdr << "%" << RandomNonASCIIString(4) << eol
152+
hdr << "%" << random_non_ascii_string(4) << eol
153153
hdr
154154
end
155155

156156
def add_object(num, data)
157157
@xref[num] = @pdf.length
158-
@pdf << ioDef(num)
158+
@pdf << io_def(num)
159159
@pdf << data
160160
@pdf << endobj
161161
end
@@ -186,7 +186,7 @@ def xref_table
186186
end
187187

188188
def trailer(root_obj)
189-
ret = "trailer" << nObfu("<</Size %d/Root " % (@xref.length + 1)) << ioRef(root_obj) << ">>" << eol
189+
ret = "trailer" << nobfu("<</Size %d/Root " % (@xref.length + 1)) << io_ref(root_obj) << ">>" << eol
190190
ret
191191
end
192192

@@ -209,18 +209,18 @@ def endobj
209209
"endobj" << eol
210210
end
211211

212-
def ioDef(id)
212+
def io_def(id)
213213
"%d 0 obj" % id
214214
end
215215

216-
def ioRef(id)
216+
def io_ref(id)
217217
"%d 0 R" % id
218218
end
219219

220220
##
221221
#Controller funtion, should be entrypoint for pdf exploits
222222
##
223-
def CreatePDF(js)
223+
def create_pdf(js)
224224
strFilter = ""
225225
arrResults = []
226226
numIterations = 0
@@ -233,10 +233,10 @@ def CreatePDF(js)
233233
end
234234
for i in (0..numIterations-1)
235235
if i == 0
236-
arrResults = SelectEncoder(js,arrEncodings[i],strFilter)
236+
arrResults = select_encoder(js,arrEncodings[i],strFilter)
237237
next
238238
end
239-
arrResults = SelectEncoder(arrResults[0],arrEncodings[i],arrResults[1])
239+
arrResults = select_encoder(arrResults[0],arrEncodings[i],arrResults[1])
240240
end
241241
case datastore['PDF::Method']
242242
when 'PAGE'
@@ -251,19 +251,19 @@ def CreatePDF(js)
251251
##
252252
#Select an encoder and build a filter specification
253253
##
254-
def SelectEncoder(js,strEncode,strFilter)
254+
def select_encoder(js,strEncode,strFilter)
255255
case strEncode
256256
when 'ASCII85'
257-
js = ASCII85Encode(js)
257+
js = ascii85_encode(js)
258258
strFilter = "/ASCII85Decode"<<strFilter
259259
when 'ASCIIHEX'
260-
js = ASCIIHexWhitespaceEncode(js)
260+
js = ascii_hex_whitespace_encode(js)
261261
strFilter = "/ASCIIHexDecode"<<strFilter
262262
when 'FLATE'
263263
js = Zlib::Deflate.deflate(js)
264264
strFilter = "/FlateDecode"<<strFilter
265265
when 'RUN'
266-
js = RunLengthEncode(js)
266+
js = run_length_encode(js)
267267
strFilter = "/RunLengthDecode"<<strFilter
268268
end
269269
return js,strFilter
@@ -277,10 +277,10 @@ def pdf_with_page_exploit(js,strFilter)
277277
@pdf = ''
278278
279279
@pdf << header
280-
add_object(1, nObfu("<</Type/Catalog/Outlines ") << ioRef(2) << nObfu("/Pages ") << ioRef(3) << ">>")
281-
add_object(2, nObfu("<</Type/Outlines/Count 0>>"))
282-
add_object(3, nObfu("<</Type/Pages/Kids[") << ioRef(4) << nObfu("]/Count 1>>"))
283-
add_object(4, nObfu("<</Type/Page/Parent ") << ioRef(3) << nObfu("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nObfu(" /AA << /O << /JS ") << ioRef(5) << nObfu("/S /JavaScript >>>>>>"))
280+
add_object(1, nobfu("<</Type/Catalog/Outlines ") << io_ref(2) << nobfu("/Pages ") << io_ref(3) << ">>")
281+
add_object(2, nobfu("<</Type/Outlines/Count 0>>"))
282+
add_object(3, nobfu("<</Type/Pages/Kids[") << io_ref(4) << nobfu("]/Count 1>>"))
283+
add_object(4, nobfu("<</Type/Page/Parent ") << io_ref(3) << nobfu("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nobfu(" /AA << /O << /JS ") << io_ref(5) << nobfu("/S /JavaScript >>>>>>"))
284284
compressed = js
285285
stream = "<</Length %s/Filter[" % compressed.length << strFilter << "]>>" << eol
286286
stream << "stream" << eol
@@ -301,10 +301,10 @@ def pdf_with_openaction_js(js,strFilter)
301301
302302
@pdf << header
303303
304-
add_object(1, nObfu("<</Type/Catalog/Outlines ") << ioRef(2) << nObfu("/Pages ") << ioRef(3) << ">>")
305-
add_object(2, nObfu("<</Type/Outlines/Count 0>>"))
306-
add_object(3, nObfu("<</Type/Pages/Kids[") << ioRef(4) << nObfu("]/Count 1>>"))
307-
add_object(4, nObfu("<</Type/Page/Parent ") << ioRef(3) << nObfu("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nObfu(" /AA << /O << /JS ") << ioRef(5) << nObfu("/S /JavaScript >>>>>>"))
304+
add_object(1, nobfu("<</Type/Catalog/Outlines ") << io_ref(2) << nobfu("/Pages ") << io_ref(3) << ">>")
305+
add_object(2, nobfu("<</Type/Outlines/Count 0>>"))
306+
add_object(3, nobfu("<</Type/Pages/Kids[") << io_ref(4) << nobfu("]/Count 1>>"))
307+
add_object(4, nobfu("<</Type/Page/Parent ") << io_ref(3) << nobfu("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nobfu(" /AA << /O << /JS ") << io_ref(5) << nobfu("/S /JavaScript >>>>>>"))
308308
compressed = js
309309
stream = "<</Length %s/Filter[" % compressed.length << strFilter << "]>>" << eol
310310
stream << "stream" << eol
@@ -324,11 +324,11 @@ def pdf_with_annot_js(js,strFilter)
324324
325325
@pdf << header
326326
327-
add_object(1, nObfu("<</Type/Catalog/Outlines ") << ioRef(2) << nObfu("/Pages ") << ioRef(3) << ">>")
328-
add_object(2, nObfu("<</Type/Outlines/Count 0>>"))
329-
add_object(3, nObfu("<</Type/Pages/Kids[") << ioRef(4) << nObfu("]/Count 1>>"))
330-
add_object(4, nObfu("<</Type/Page/Parent ") << ioRef(3) << nObfu("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nObfu(" /Annots [") << ioRef(5) << nObfu("]>>"))
331-
add_object(5, nObfu("<</Type/Annot /Subtype /Screen /Rect [%s %s %s %s] /AA << /PO << /JS " % [rand(200),rand(200),rand(300),rand(300)]) << ioRef(6) << nObfu("/S /JavaScript >>>>>>"))
327+
add_object(1, nobfu("<</Type/Catalog/Outlines ") << io_ref(2) << nobfu("/Pages ") << io_ref(3) << ">>")
328+
add_object(2, nobfu("<</Type/Outlines/Count 0>>"))
329+
add_object(3, nobfu("<</Type/Pages/Kids[") << io_ref(4) << nobfu("]/Count 1>>"))
330+
add_object(4, nobfu("<</Type/Page/Parent ") << io_ref(3) << nobfu("/MediaBox[%s %s %s %s] " % [rand(200),rand(200),rand(300),rand(300)]) << nobfu(" /Annots [") << io_ref(5) << nobfu("]>>"))
331+
add_object(5, nobfu("<</Type/Annot /Subtype /Screen /Rect [%s %s %s %s] /AA << /PO << /JS " % [rand(200),rand(200),rand(300),rand(300)]) << io_ref(6) << nobfu("/S /JavaScript >>>>>>"))
332332
compressed = js
333333
stream = "<</Length %s/Filter[" % compressed.length << strFilter << "]>>" << eol
334334
stream << "stream" << eol

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,73 +2834,72 @@ def option_values_dispatch(o, str, words)
28342834
res = []
28352835
res << o.default.to_s if o.default
28362836

2837-
case o.class.to_s
2838-
2839-
when 'Msf::OptAddress'
2840-
case o.name.upcase
2841-
when 'RHOST'
2842-
option_values_target_addrs().each do |addr|
2843-
res << addr
2844-
end
2845-
when 'LHOST'
2846-
rh = self.active_module.datastore["RHOST"]
2847-
if rh and not rh.empty?
2848-
res << Rex::Socket.source_address(rh)
2849-
else
2850-
res << Rex::Socket.source_address()
2851-
end
2852-
else
2837+
case o
2838+
when Msf::OptAddress
2839+
case o.name.upcase
2840+
when 'RHOST'
2841+
option_values_target_addrs().each do |addr|
2842+
res << addr
28532843
end
2854-
2855-
when 'Msf::OptAddressRange'
2856-
case str
2857-
when /^file:(.*)/
2858-
files = tab_complete_filenames($1, words)
2859-
res += files.map { |f| "file:" + f } if files
2860-
when /\/$/
2861-
res << str+'32'
2862-
res << str+'24'
2863-
res << str+'16'
2864-
when /\-$/
2865-
res << str+str[0, str.length - 1]
2866-
else
2867-
option_values_target_addrs().each do |addr|
2868-
res << addr+'/32'
2869-
res << addr+'/24'
2870-
res << addr+'/16'
2871-
end
2844+
when 'LHOST'
2845+
rh = self.active_module.datastore["RHOST"]
2846+
if rh and not rh.empty?
2847+
res << Rex::Socket.source_address(rh)
2848+
else
2849+
res << Rex::Socket.source_address()
28722850
end
2851+
else
2852+
end
28732853

2874-
when 'Msf::OptPort'
2875-
case o.name.upcase
2876-
when 'RPORT'
2877-
option_values_target_ports().each do |port|
2878-
res << port
2879-
end
2854+
when Msf::OptAddressRange
2855+
case str
2856+
when /^file:(.*)/
2857+
files = tab_complete_filenames($1, words)
2858+
res += files.map { |f| "file:" + f } if files
2859+
when /\/$/
2860+
res << str+'32'
2861+
res << str+'24'
2862+
res << str+'16'
2863+
when /\-$/
2864+
res << str+str[0, str.length - 1]
2865+
else
2866+
option_values_target_addrs().each do |addr|
2867+
res << addr+'/32'
2868+
res << addr+'/24'
2869+
res << addr+'/16'
28802870
end
2871+
end
28812872

2882-
if (res.empty?)
2883-
res << (rand(65534)+1).to_s
2873+
when Msf::OptPort
2874+
case o.name.upcase
2875+
when 'RPORT'
2876+
option_values_target_ports().each do |port|
2877+
res << port
28842878
end
2879+
end
28852880

2886-
when 'Msf::OptEnum'
2887-
o.enums.each do |val|
2888-
res << val
2889-
end
2881+
if (res.empty?)
2882+
res << (rand(65534)+1).to_s
2883+
end
28902884

2891-
when 'Msf::OptPath'
2892-
files = tab_complete_filenames(str, words)
2893-
res += files if files
2885+
when Msf::OptEnum
2886+
o.enums.each do |val|
2887+
res << val
2888+
end
28942889

2895-
when 'Msf::OptBool'
2896-
res << 'true'
2897-
res << 'false'
2890+
when Msf::OptPath
2891+
files = tab_complete_filenames(str, words)
2892+
res += files if files
28982893

2899-
when 'Msf::OptString'
2900-
if (str =~ /^file:(.*)/)
2901-
files = tab_complete_filenames($1, words)
2902-
res += files.map { |f| "file:" + f } if files
2903-
end
2894+
when Msf::OptBool
2895+
res << 'true'
2896+
res << 'false'
2897+
2898+
when Msf::OptString
2899+
if (str =~ /^file:(.*)/)
2900+
files = tab_complete_filenames($1, words)
2901+
res += files.map { |f| "file:" + f } if files
2902+
end
29042903
end
29052904

29062905
return res

0 commit comments

Comments
 (0)