Skip to content

Refactor smb spider #729

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
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

haytechy
Copy link
Contributor

@haytechy haytechy commented Jun 10, 2025

Description

Showing the SMB Spider option some love as I wanted to add some quality of life changes. This should hopefully make searching for files and directories in shares using Netexec a lot nicer.

Type of change

  • Enhancement
  • This change requires a documentation update

Setup guide for the review

Run using poetry on the following system

PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"

All tests uses the following HTB Academy Lab setup to test the spider module

Screenshots and Code Snippets

Pattern Searching

By default it searches for all files and directories within the share if you don't specify a specific pattern or regex.

image`

Only-Folder or Only-Files option

Can now search for either files or folder using the only-folder and only-files option

image

Ignore . and .. folders

These significantly reduce the amount of unnecessary output especially on shares with an abundance of folders.

New spider-all option

Previously, you had to use --spider "*" to search for the all the shares which wasn't obvious until you looked at the code.

Changed the arguments to include a --spider-all option if a user wants to spider all the shares.

Exclude Folder

Can now exclude multiple folder. I changed the name of this option to exclude-folders out of personal preference but happy to revert to exclude-dirs

image

Fixed bug with Depth option

The depth option did not seem to work with the current version of Spider. I've fixed it so now it now works.

image

Various Code Improvements

The most notable changes:

  • Using f strings instead of string format when displaying the shares.
  • Tidied up how Spider is called in nxc/protocols/smb.py.
  • Changed how the class is initialised, setting all the required attributes when creating the SMBSpider Object.
  • Removed the silent option. Not too sure why it was implemented in the first place as SMBSpider does not save any results to a file.
  • Tidied up some conditionals and string manipulation.
  • Fixed error with using --content on $IPC share. It now catches the Netbios Error

Checklist:

  • I have ran Ruff against my changes (via poetry: poetry run python -m ruff check . --preview, use --fix to automatically fix what it can)
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (see: minor tweaks to SMB Spider NetExec-Wiki#51)

@NeffIsBack
Copy link
Member

Thanks for the PR! Gonna take a look at it when i find the time :)

@NeffIsBack NeffIsBack added the enhancement New feature or request label Jun 12, 2025
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