Skip to content

Commit a9a8ac7

Browse files
committed
Adds validation for arch values
1 parent bbcac72 commit a9a8ac7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

spec/module_validation_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
file_path: 'modules/exploits/windows/smb/cve_2020_0796_smbghost.rb',
2626
type: 'exploit',
2727
platform: Msf::Module::PlatformList.new(Msf::Module::Platform::Windows),
28+
arch: [Rex::Arch::ARCH_X86],
2829
targets: [Msf::Module::Target.new('Windows 10 v1903-1909 x64', { 'Platform' => 'win', 'Arch' => ['x64'] })],
2930
description: %q{
3031
A vulnerability exists within the Microsoft Server Message Block 3.1.1 (SMBv3) protocol that can be leveraged to
@@ -234,6 +235,22 @@
234235
end
235236
end
236237

238+
context 'when the arch array contains a valid value' do
239+
it 'has no errors' do
240+
expect(subject.errors.full_messages).to be_empty
241+
end
242+
end
243+
244+
context 'when the arch array contains an invalid value' do
245+
let(:mod_options) do
246+
super().merge(arch: ["Rex::Arch::ARCH_X86"])
247+
end
248+
249+
it 'has errors' do
250+
expect(subject.errors.full_messages).to eq ["Arch contains invalid values [\"Rex::Arch::ARCH_X86\"] - only [\"x86\", \"x86_64\", \"x64\", \"mips\", \"mipsle\", \"mipsbe\", \"mips64\", \"mips64le\", \"ppc\", \"ppce500v2\", \"ppc64\", \"ppc64le\", \"cbea\", \"cbea64\", \"sparc\", \"sparc64\", \"armle\", \"armbe\", \"aarch64\", \"cmd\", \"php\", \"tty\", \"java\", \"ruby\", \"dalvik\", \"python\", \"nodejs\", \"firefox\", \"zarch\", \"r\", \"riscv32be\", \"riscv32le\", \"riscv64be\", \"riscv64le\", \"loongarch64\"] is allowed"]
251+
end
252+
end
253+
237254
context 'when the platform is missing and targets does not contain platform values' do
238255
let(:mod_options) do
239256
super().merge(platform: nil, targets: [Msf::Module::Target.new('Windows 10 v1903-1909 x64', { 'Arch' => ['x64'] })])
@@ -279,7 +296,7 @@
279296
super().merge(new_module_options, rank: Msf::GreatRanking, rank_to_s: 'great')
280297
end
281298

282-
it 'has no errors' do
299+
it 'has errors' do
283300
expect(subject.errors.full_messages).to eq [
284301
"Stability contains invalid values [[\"unknown-stability\"]] - only [\"crash-safe\", \"crash-service-restarts\", \"crash-service-down\", \"crash-os-restarts\", \"crash-os-down\", \"service-resource-loss\", \"os-resource-loss\"] is allowed",
285302
"Side effects contains invalid values [[\"unknown-side-effects\"]] - only [\"artifacts-on-disk\", \"config-changes\", \"ioc-in-logs\", \"account-lockouts\", \"account-logout\", \"screen-effects\", \"audio-effects\", \"physical-effects\"] is allowed",

spec/support/lib/module_validation.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def validate_each(record, attribute, value)
99
return
1010
end
1111

12+
# Special cases for modules/exploits/bsd/finger/morris_fingerd_bof.rb which has a one-off architecture defined in
13+
# the module itself, and that value is not included in the valid list of architectures.
14+
# https://github.com/rapid7/metasploit-framework/blob/389d84cbf0d7c58727846466d9a9f6a468f32c61/modules/exploits/bsd/finger/morris_fingerd_bof.rb#L11
15+
return if attribute == :arch && value == ["vax"] && record.fullname == "exploit/bsd/finger/morris_fingerd_bof"
1216
return if value == options[:sentinel_value]
1317

1418
invalid_options = value - options[:in]
@@ -187,6 +191,9 @@ def validate_name_does_not_contain_non_printable_chars
187191
'module_validation/array_inclusion': { in: VALID_RELIABILITY_VALUES, sentinel_value: Msf::UNKNOWN_RELIABILITY }
188192
end
189193

194+
validates :arch,
195+
'module_validation/array_inclusion': { in: Rex::Arch::ARCH_TYPES }
196+
190197
validates :license,
191198
presence: true,
192199
inclusion: { in: LICENSES, message: 'must include a valid license' }

0 commit comments

Comments
 (0)