-
Notifications
You must be signed in to change notification settings - Fork 15k
Fix analyze_db size bypass for dynamic payloads #21743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keyanskv
wants to merge
5
commits into
rapid7:master
Choose a base branch
from
keyanskv:fix-analyze-db-dynamic-payload-size
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+350
−62
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5b5d022
Fix analyze_db size bypass for dynamic payloads
keyanskv 7149eab
Merge branch 'rapid7:master' into fix-analyze-db-dynamic-payload-size
keyanskv 9f47f99
Fix review feedback for cached payload size
keyanskv 010b857
Fix analyze_db size bypass for dynamic payloads
keyanskv 12c5fcc
Fix flaky test by using dynamic host_ip in json_rpc_spec
keyanskv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe Msf::Exploit do | ||
| let(:framework) { instance_double(Msf::Framework) } | ||
| let(:payloads) { double('Payloads') } | ||
| let(:subject) do | ||
| mod = Class.new(Msf::Exploit).new | ||
| allow(mod).to receive(:framework).and_return(framework) | ||
| allow(mod).to receive(:payload_space).and_return(2000) | ||
| allow(mod).to receive(:compatible?).and_return(true) | ||
| allow(mod).to receive(:privileged).and_return(true) | ||
| mod | ||
| end | ||
|
|
||
| before do | ||
| allow(framework).to receive(:payloads).and_return(payloads) | ||
| end | ||
|
|
||
| describe '#is_payload_compatible?' do | ||
| let(:payload_name) { 'test/payload' } | ||
| let(:payload_class) { double('PayloadClass', refname: payload_name) } | ||
| let(:payload_instance) { double('PayloadInstance', privileged: true) } | ||
|
|
||
| before do | ||
| allow(payloads).to receive(:[]).with(payload_name).and_return(payload_class) | ||
| allow(payload_class).to receive(:new).and_return(payload_instance) | ||
| end | ||
|
|
||
| context 'when payload cached_size is present' do | ||
| it 'returns false if cached_size is greater than payload_space' do | ||
| allow(payload_class).to receive(:cached_size).and_return(3000) | ||
| expect(subject.is_payload_compatible?(payload_name)).to be_falsey | ||
| end | ||
|
|
||
| it 'returns true if cached_size is less than or equal to payload_space' do | ||
| allow(payload_class).to receive(:cached_size).and_return(1000) | ||
| expect(subject.is_payload_compatible?(payload_name)).to be_truthy | ||
| end | ||
| end | ||
|
|
||
| context 'when payload cached_size is nil (e.g. dynamic)' do | ||
| before do | ||
| allow(payload_class).to receive(:cached_size).and_return(nil) | ||
| end | ||
|
|
||
| context 'and cache contains payload_cached_size' do | ||
| let(:cache_instance) { instance_double(Msf::Modules::Metadata::Cache) } | ||
| let(:meta) { double('Metadata', payload_cached_size: 2500) } | ||
|
|
||
| before do | ||
| allow(Msf::Modules::Metadata::Cache).to receive(:instance).and_return(cache_instance) | ||
| allow(cache_instance).to receive(:get_module_reference).with(type: Msf::MODULE_PAYLOAD, reference_name: payload_name).and_return(meta) | ||
| end | ||
|
|
||
| it 'returns false if metadata payload_cached_size is greater than payload_space' do | ||
| expect(subject.is_payload_compatible?(payload_name)).to be_falsey | ||
| end | ||
|
|
||
| it 'returns true if metadata payload_cached_size is less than payload_space' do | ||
| allow(meta).to receive(:payload_cached_size).and_return(1000) | ||
| expect(subject.is_payload_compatible?(payload_name)).to be_truthy | ||
| end | ||
| end | ||
|
|
||
| context 'and cache does not contain payload_cached_size' do | ||
| let(:cache_instance) { instance_double(Msf::Modules::Metadata::Cache) } | ||
|
|
||
| before do | ||
| allow(Msf::Modules::Metadata::Cache).to receive(:instance).and_return(cache_instance) | ||
| allow(cache_instance).to receive(:get_module_reference).with(type: Msf::MODULE_PAYLOAD, reference_name: payload_name).and_return(nil) | ||
| end | ||
|
|
||
| it 'returns true (bypasses size check)' do | ||
| expect(subject.is_payload_compatible?(payload_name)).to be_truthy | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.