close
Skip to content

Fix db_import crash#21557

Merged
adfoster-r7 merged 1 commit into
rapid7:masterfrom
adfoster-r7:add-additional-import-tests
Jun 11, 2026
Merged

Fix db_import crash#21557
adfoster-r7 merged 1 commit into
rapid7:masterfrom
adfoster-r7:add-additional-import-tests

Conversation

@adfoster-r7

@adfoster-r7 adfoster-r7 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Fixes a db_import crash when importing zip files

Verification

  • Ensure CI passes
  • Open msfconsole: `db_export -f xml
  • Add to zip: zip new_archive.zip test_export.xml
  • in msfconsole import it: db_import new_archive.zip

Master:

msf > db_import new_archive.zip
[*] Importing 'Metasploit Zip Export' data
[-] Error while running command db_import: No such file or directory @ rb_sysopen - /Users/user/Documents/code/metasploit-framework/var/folders/wp/fp12h8q13kq7mvf4mll72c140000gq/T/msf/imp_1QUr/new_archive/test_export.xml

Call stack:
/Users/user/.rvm/gems/ruby-3.3.8@metasploit-framework/gems/rubyzip-3.3.0/lib/zip/entry.rb:757:in `initialize'

This branch:

bundle exec ruby ./msfconsole -q
msf > db_import new_archive.zip
[*] Importing 'Metasploit Zip Export' data
[*] Importing 'Metasploit XML' data
[*] Importing host 127.0.0.1
[*] Importing host 192.168.123.198
...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands coverage around Metasploit Framework ZIP imports and adjusts the ZIP extraction implementation used by Msf::DBManager to better handle (and test for) unsafe ZIP entry paths.

Changes:

  • Adds shared RSpec examples that exercise #import_msf_zip extraction behavior (including a zip-slip/path traversal scenario).
  • Updates import_msf_zip ZIP entry extraction logic in the importer implementation.

Impact Analysis:

  • Blast radius: medium — affects Msf::DBManager ZIP import path for Metasploit ZIP exports and any callers that rely on that importer.
  • Data and contract effects: no schema/DB contract changes; does change filesystem extraction behavior and traversal mitigation semantics.
  • Rollback and test focus: focus on importing a normal MSF ZIP export (loot/tasks present) and malicious ZIPs with traversal/prefix-bypass entry names; rollback is straightforward (single-method change) but reintroduces traversal risk.

Reviewed changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

File Description
spec/support/shared/examples/msf/db_manager/import/metasploit_framework/zip.rb Adds new shared examples to validate ZIP extraction and traversal protections.
lib/msf/core/db_manager/import/metasploit_framework/zip.rb Modifies how ZIP entries are extracted during MSF ZIP import.

Comment on lines +5 to +8
describe '#import_msf_zip' do
let(:zip_tmp_root) { Dir.mktmpdir('msf-zip-import-test') }

after { FileUtils.rm_rf(zip_tmp_root) }
Comment on lines +52 to +70
it 'extracts zip entries to the temporary directory' do
subject.import_msf_zip(
data: File.binread(zip_path),
workspace: subject.workspace
)

extracted_tmp = subject.instance_variable_get(:@import_filedata)[:zip_tmp]
expect(extracted_tmp).not_to be_nil
expect(File.exist?(File.join(extracted_tmp, 'test_export.xml'))).to be true
expect(File.exist?(File.join(extracted_tmp, 'loot/file1.bin'))).to be true
expect(File.exist?(File.join(extracted_tmp, 'tasks/task1.log'))).to be true
expect(File.read(File.join(extracted_tmp, 'loot/file1.bin'))).to eq('loot content here')
end

it 'identifies the XML export file for subsequent import' do
subject.import_msf_zip(
data: File.binread(zip_path),
workspace: subject.workspace
)
@adfoster-r7
adfoster-r7 force-pushed the add-additional-import-tests branch 2 times, most recently from 4397084 to c4c0721 Compare June 10, 2026 14:11
@adfoster-r7
adfoster-r7 force-pushed the add-additional-import-tests branch 3 times, most recently from 236f4e8 to 997766c Compare June 10, 2026 15:35
@adfoster-r7 adfoster-r7 added the rn-fix release notes fix label Jun 10, 2026
@adfoster-r7 adfoster-r7 changed the title Add additional import tests Fix db_impor tcrash Jun 10, 2026
@adfoster-r7
adfoster-r7 requested a review from Copilot June 10, 2026 17:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread spec/support/shared/examples/msf/db_manager/import/metasploit_framework/zip.rb Outdated
@adfoster-r7
adfoster-r7 force-pushed the add-additional-import-tests branch from 997766c to 40a6474 Compare June 10, 2026 17:43
@adfoster-r7 adfoster-r7 changed the title Fix db_impor tcrash Fix db_import crash Jun 10, 2026
@adfoster-r7
adfoster-r7 force-pushed the add-additional-import-tests branch from 40a6474 to cf67b7f Compare June 10, 2026 21:17
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Metasploit Kanban Jun 11, 2026
@adfoster-r7
adfoster-r7 merged commit 3e8e87e into rapid7:master Jun 11, 2026
67 of 69 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metasploit Kanban Jun 11, 2026
@adfoster-r7
adfoster-r7 deleted the add-additional-import-tests branch June 11, 2026 08:56
@adfoster-r7

Copy link
Copy Markdown
Contributor Author

Release Notes

Fixes a db_import crash when importing zip files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rn-fix release notes fix tests

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants