Skip to content

Add --list-backups allowing enumerating databases backups on MSSQL#1258

Open
Dfte wants to merge 6 commits into
Pennyw0rth:mainfrom
Dfte:add_mssql_database_listing
Open

Add --list-backups allowing enumerating databases backups on MSSQL#1258
Dfte wants to merge 6 commits into
Pennyw0rth:mainfrom
Dfte:add_mssql_database_listing

Conversation

@Dfte

@Dfte Dfte commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds the --list-backups option allowing finding databases backups location.

Type of change

Insert an "x" inside the brackets for relevant items (do not delete options)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Deprecation of feature or functionality
  • This change requires a documentation update
  • This requires a third party update (such as Impacket, Dploot, lsassy, etc)
  • This PR was created with the assistance of AI (list what type of assistance, tool(s)/model(s) in the description)

Setup guide for the review

Run:

First create a database then run the following query:

DECLARE @db_name sysname;
DECLARE @path nvarchar(500);

DECLARE db_cursor CURSOR FOR
SELECT name FROM sys.databases
WHERE name NOT IN ('master','model','msdb','tempdb')
AND state_desc = 'ONLINE';

OPEN db_cursor;
FETCH NEXT FROM db_cursor INTO @db_name;

WHILE @@FETCH_STATUS = 0
BEGIN
    SET @path = 'C:\Windows\Temp\' + @db_name + '_' + 
        REPLACE(CONVERT(varchar, GETDATE(), 112), '-', '') + '.bak';
    
    BACKUP DATABASE @db_name
    TO DISK = @path;
    
    FETCH NEXT FROM db_cursor INTO @db_name;
END;

CLOSE db_cursor;
DEALLOCATE db_cursor;

That is going to go through all databases and backup them on c:\windows\temp. These files, .bak, are the the actual zipped like databases with their content.

nxc mssql  IP -u USER -p PASS  --backups

From there an attacker could see if he has got access to these directories and may be exfiltrate sensitive data. That's mostly a recon option.

Screenshots (if appropriate):

image

Checklist:

Insert an "x" inside the brackets for completed and relevant items (do not delete options)

  • I have ran Ruff against my changes (poetry: poetry run ruff check ., use --fix to automatically fix what it can)
  • I have added or updated the tests/e2e_commands.txt file if necessary (new modules or features are required to be added to the e2e tests)
  • If reliant on changes of third party dependencies, such as Impacket, dploot, lsassy, etc, I have linked the relevant PRs in those projects
  • I have linked relevant sources that describes the added technique (blog posts, documentation, etc)
  • I have performed a self-review of my own code (not an AI review)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (PR here: https://github.com/Pennyw0rth/NetExec-Wiki)

@Dfte Dfte changed the title Add --backups Add --backups allowing enumerating databases backups on MSSQL Jun 1, 2026
@Dfte Dfte changed the title Add --backups allowing enumerating databases backups on MSSQL Add list---backups allowing enumerating databases backups on MSSQL Jun 2, 2026
@Dfte Dfte changed the title Add list---backups allowing enumerating databases backups on MSSQL Add --list-backups allowing enumerating databases backups on MSSQL Jun 2, 2026
@NeffIsBack

Copy link
Copy Markdown
Member

Very nice, thanks!

Can you include the settings that need to be configured so I get output in the setup guide? What kind of file is that backup file?

We should probably also describe how this can be (ab)used in the wiki then.

@NeffIsBack NeffIsBack added the enhancement New feature or request label Jun 2, 2026
@Dfte

Dfte commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Very nice, thanks!

Can you include the settings that need to be configured so I get output in the setup guide? What kind of file is that backup file?

We should probably also describe how this can be (ab)used in the wiki then.

Done :P
And yeah, I'll add all these PR's in the Wiki!

@Dfte

Dfte commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Last commit adds the encryption status of the backups:

image

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants