Page cover

🔑Credential Hunting en recursos compartidos

Casi todos los entornos corporativos incluyen recursos compartidos de red que los empleados utilizan para almacenar y compartir archivos entre equipos. Si bien estas carpetas compartidas son esenciales, pueden convertirse involuntariamente en una mina de oro para los atacantes, especialmente cuando se olvidan datos confidenciales como credenciales de texto plano o archivos de configuración. En esta sección, exploraremos cómo buscar credenciales en recursos compartidos de red de sistemas Windows y Linux mediante herramientas comunes, junto con técnicas generales que los atacantes utilizan para descubrir secretos ocultos.

Patrones de credenciales comunes

Antes de profundizar en herramientas especializadas, es importante comprender los tipos de patrones y formatos de archivo que suelen revelar información confidencial. Esto se abordó en secciones anteriores, por lo que no lo repetiremos en detalle aquí. Sin embargo, a modo de recordatorio rápido, aquí hay algunos consejos generales:

  • Busque palabras clave dentro de archivos como passw, user, token, key, y secret.

  • Busque archivos con extensiones comúnmente asociadas con credenciales almacenadas, como .ini, .cfg, .env, .xlsx, .ps1, y .bat.

  • Esté atento a los archivos con nombres "interesantes" que incluyan términos como config, user, passw, cred, o initial.

  • Si está intentando localizar credenciales dentro del INLANEFREIGHT.LOCALdominio, puede ser útil buscar archivos que contengan la cadena INLANEFREIGHT\.

  • Las palabras clave deben localizarse en función del objetivo; si estás atacando a una empresa alemana, es más probable que hagan referencia a un "Benutzer"que a un "User".

  • Presta atención a las acciones que estás considerando y sé estratégico. Si escaneas diez acciones con miles de archivos cada una, te llevará mucho tiempo. Las acciones utilizadas por otros IT employeespodrían ser un objetivo más valioso que las utilizadas para fotos de empresas.

Con todo esto en mente, puede que le convenga comenzar con búsquedas básicas en la línea de comandos (p. ej., Get-ChildItem -Recurse -Include *.ext \\Server\Share | Select-String -Pattern ...) antes de ampliar a herramientas más avanzadas. Veamos cómo podemos usar MANSPIDER, Snaffler, SnafflePyy NetExecpara automatizar y mejorar este proceso de búsqueda de credenciales.


Credential Hunting desde Windows

Snaffler

La primera herramienta que abordaremos es Snaffler . Se trata de un programa en C# que, al ejecutarse en una domain-joinedmáquina, identifica automáticamente los recursos compartidos de red accesibles y busca archivos interesantes. El READMEarchivo del repositorio de Github describe las numerosas opciones de configuración con gran detalle; sin embargo, se puede realizar una búsqueda básica de la siguiente manera:

c:\Users\Public> Snaffler.exe -s

 .::::::.:::.    :::.  :::.    .-:::::'.-:::::':::    .,:::::: :::::::..
;;;`    ``;;;;,  `;;;  ;;`;;   ;;;'''' ;;;'''' ;;;    ;;;;'''' ;;;;``;;;;
'[==/[[[[, [[[[[. '[[ ,[[ '[[, [[[,,== [[[,,== [[[     [[cccc   [[[,/[[['
  '''    $ $$$ 'Y$c$$c$$$cc$$$c`$$$'`` `$$$'`` $$'     $$""   $$$$$$c
 88b    dP 888    Y88 888   888,888     888   o88oo,.__888oo,__ 888b '88bo,
  'YMmMY'  MMM     YM YMM   ''` 'MM,    'MM,  ''''YUMMM''''YUMMMMMMM   'W'
                         by l0ss and Sh3r4 - github.com/SnaffCon/Snaffler


[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:42Z [Info] Parsing args...
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Parsed args successfully.
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Invoking DFS Discovery because no ComputerTargets or PathTargets were specified
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Getting DFS paths from AD.
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Found 0 DFS Shares in 0 namespaces.
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Invoking full domain computer discovery.
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Getting computers from AD.
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Got 1 computers from AD.
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Starting to look for readable shares...
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Info] Created all sharefinder tasks.
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Black}<\\DC01.inlanefreight.local\ADMIN$>()
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\ADMIN$>(R) Remote Admin
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Black}<\\DC01.inlanefreight.local\C$>()
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\C$>(R) Default share
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\Company>(R)
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\Finance>(R)
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\HR>(R)
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\IT>(R)
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\Marketing>(R)
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\NETLOGON>(R) Logon server share
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\Sales>(R)
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:43Z [Share] {Green}<\\DC01.inlanefreight.local\SYSVOL>(R) Logon server share
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:51Z [File] {Red}<KeepPassOrKeyInCode|R|passw?o?r?d?>\s*[^\s<]+\s*<|2.3kB|2025-05-01 05:22:48Z>(\\DC01.inlanefreight.local\ADMIN$\Panther\unattend.xml) 5"\ language="neutral"\ versionScope="nonSxS"\ xmlns:wcm="http://schemas\.microsoft\.com/WMIConfig/2002/State"\ xmlns:xsi="http://www\.w3\.org/2001/XMLSchema-instance">\n\t\t\ \ <UserAccounts>\n\t\t\ \ \ \ <AdministratorPassword>\*SENSITIVE\*DATA\*DELETED\*</AdministratorPassword>\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ </UserAccounts>\n\ \ \ \ \ \ \ \ \ \ \ \ <OOBE>\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <HideEULAPage>true</HideEULAPage>\n\ \ \ \ \ \ \ \ \ \ \ \ </OOBE>\n\ \ \ \ \ \ \ \ </component
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:53Z [File] {Yellow}<KeepDeployImageByExtension|R|^\.wim$|29.2MB|2022-02-25 16:36:53Z>(\\DC01.inlanefreight.local\ADMIN$\Containers\serviced\WindowsDefenderApplicationGuard.wim) .wim
[INLANEFREIGHT\jbader@DC01] 2025-05-01 17:41:58Z [File] {Red}<KeepPassOrKeyInCode|R|passw?o?r?d?>\s*[^\s<]+\s*<|2.3kB|2025-05-01 05:22:48Z>(\\DC01.inlanefreight.local\C$\Windows\Panther\unattend.xml) 5"\ language="neutral"\ versionScope="nonSxS"\ xmlns:wcm="http://schemas\.microsoft\.com/WMIConfig/2002/State"\ xmlns:xsi="http://www\.w3\.org/2001/XMLSchema-instance">\n\t\t\ \ <UserAccounts>\n\t\t\ \ \ \ <AdministratorPassword>\*SENSITIVE\*DATA\*DELETED\*</AdministratorPassword>\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ </UserAccounts>\n\ \ \ \ \ \ \ \ \ \ \ \ <OOBE>\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <HideEULAPage>true</HideEULAPage>\n\ \ \ \ \ \ \ \ \ \ \ \ </OOBE>\n\ \ \ \ \ \ \ \ </component
<SNIP>

Todas las herramientas de esta sección generan una gran cantidad de información. Si bien facilitan la automatización, suele requerirse una revisión manual considerable, ya que muchas coincidencias pueden resultar ser "false positives". Dos parámetros útiles que pueden ayudar a refinar el proceso de búsqueda de Snaffler son:

  • -u recupera una lista de usuarios de Active Directory y busca referencias a ellos en archivos

  • -i y -n te permitirá especificar qué acciones deben incluirse en la búsqueda

PowerHuntShares

Otra herramienta que se puede utilizar es PowerHuntShares , un script de PowerShell que no necesita ejecutarse necesariamente en una máquina unida a un dominio. Una de sus funciones más útiles es que genera un mensaje reporte en HTML al finalizar, lo que proporciona una interfaz de usuario intuitiva para revisar los resultados:

Podemos ejecutar un escaneo básico de PowerHuntShares de la siguiente manera:

# Bypass de execution policy restrictions
Set-ExecutionPolicy -Scope Process Bypass

# Importar el módulo
Import-Module .\PowerHuntShares.psm1
PS C:\Users\Public\PowerHuntShares> Invoke-HuntSMBShares -Threads 100 -OutputDirectory c:\Users\Public

 ===============================================================
 INVOKE-HUNTSMBSHARES
 ===============================================================
  This function automates the following tasks:

  o Determine current computer's domain
  o Enumerate domain computers
  o Check if computers respond to ping requests
  o Filter for computers that have TCP 445 open and accessible
  o Enumerate SMB shares
  o Enumerate SMB share permissions
  o Identify shares with potentially excessive privileges
  o Identify shares that provide read or write access
  o Identify shares thare are high risk
  o Identify common share owners, names, & directory listings
  o Generate last written & last accessed timelines
  o Generate html summary report and detailed csv files

  Note: This can take hours to run in large environments.
 ---------------------------------------------------------------
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ---------------------------------------------------------------
 SHARE DISCOVERY
 ---------------------------------------------------------------
 [*][05/01/2025 12:51] Scan Start
 [*][05/01/2025 12:51] Output Directory: c:\Users\Public\SmbShareHunt-05012025125123
 [*][05/01/2025 12:51] Successful connection to domain controller: DC01.inlanefreight.local
 [*][05/01/2025 12:51] Performing LDAP query for computers associated with the inlanefreight.local domain
 [*][05/01/2025 12:51] -  computers found
 [*][05/01/2025 12:51] - 0 subnets found
 [*][05/01/2025 12:51] Pinging  computers
 [*][05/01/2025 12:51] -  computers responded to ping requests.
 [*][05/01/2025 12:51] Checking if TCP Port 445 is open on  computers
 [*][05/01/2025 12:51] - 1 computers have TCP port 445 open.
 [*][05/01/2025 12:51] Getting a list of SMB shares from 1 computers
 [*][05/01/2025 12:51] - 11 SMB shares were found.
 [*][05/01/2025 12:51] Getting share permissions from 11 SMB shares
<SNIP>

Credential Hunting desde Linux

Manspider

Si no tenemos acceso a un equipo unido al dominio, o simplemente preferimos buscar archivos de forma remota, herramientas como MANSPIDER nos permiten escanear recursos compartidos SMB desde Linux. Es recomendable ejecutarlo usando el contenedor Docker oficial para evitar problemas de dependencias. Al igual que otras herramientas, MANSPIDER ofrece numerosos parámetros configurables para afinar la búsqueda. Un escaneo básico de archivos que contengan la cadena passw se puede ejecutar de la siguiente manera:

afsh4ck@kali$ docker run --rm -v ./manspider:/root/.manspider blacklanternsecurity/manspider 10.129.234.121 -c 'passw' -u 'mendres' -p 'Inlanefreight2025!'

[+] MANSPIDER command executed: /usr/local/bin/manspider 10.129.234.121 -c passw -u mendres -p Inlanefreight2025!
[+] Skipping files larger than 10.00MB
[+] Using 5 threads
[+] Searching by file content: "passw"
[+] Matching files will be downloaded to /root/.manspider/loot
[+] 10.129.234.121: Successful login as "mendres"
[+] 10.129.234.121: Successful login as "mendres"
<SNIP>

NetExec

Además de sus muchos otros usos, NetExec también se puede usar para buscar en recursos compartidos de red con esta opción --spider. Esta función se describe detalladamente en la wiki oficial . Se puede ejecutar un análisis básico de los recursos compartidos de red en busca de archivos que contengan la cadena "passw" de la siguiente manera:

Búsqueda de credenciales en recursos compartidos de red

afsh4ck@kali$ nxc smb 10.129.234.121 -u mendres -p 'Inlanefreight2025!' --spider IT --content --pattern "passw"

SMB         10.129.234.121  445    DC01             [*] Windows 10 / Server 2019 Build 17763 x64 (name:DC01) (domain:inlanefreight.local) (signing:True) (SMBv1:False)
SMB         10.129.234.121  445    DC01             [+] inlanefreight.local\mendres:Inlanefreight2025! 
SMB         10.129.234.121  445    DC01             [*] Started spidering
SMB         10.129.234.121  445    DC01             [*] Spidering .

Caso práctico

Objetivo: 10.129.234.173

RDP con el usuario "mendres" y la contraseña "Inlanefreight2025!"

Utilice las credenciales mendres:Inlanefreight2025! para conectarse al objetivo, ya sea mediante RDP o WinRM, y luego use las herramientas y técnicas enseñadas en esta sección para responder las preguntas a continuación. Para su conveniencia, Snaffler y PowerHuntShares se encuentran en C:\Users\Public.

Pregunta 1

Uno de los recursos compartidos a los que Mendres tiene acceso contiene credenciales válidas de otro usuario del dominio. ¿Cuál es su contraseña?

Nos conectamos por RDP al objetivo:

xfreerdp /v:10.129.234.173 /u:mendres /p:Inlanefreight2025! /drive:home,"/home/kali/Escritorio/hack-tools/WINDOWS"

Una vez dentro si abrimos una Powershell y vamos a la ruta C:\Users\Public veremos las herramientas Snaffler y PowerHuntShares:

PS C:\Users\public> ls

    Directory: C:\Users\public

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-r---         5/1/2025  12:36 PM                Documents
d-r---         5/1/2025  12:36 PM                Music
d-r---         5/1/2025  12:36 PM                Pictures
d-----         5/1/2025  11:37 AM                PowerHuntShares
d-r---         5/1/2025  12:36 PM                Videos
-a----         5/1/2025  11:36 AM         491520 Snaffler.exe

Ejecutaremos Snaffler a ver que encuentra:

PS C:\Users\public> ./Snaffler.exe -s

Eso nos genera una gran cantidad de información, por lo que usaremos otras técnicas para facilitarnos el análisis:

PowerHuntShares

# Bypass de execution policy restrictions
Set-ExecutionPolicy -Scope Process Bypass

# Importar el módulo
Import-Module .\PowerHuntShares.psm1

PS C:\Users\public\PowerHuntShares> Invoke-HuntSMBShares -Threads 100 -OutputDirectory c:\Users\Public
 
 ===============================================================
 INVOKE-HUNTSMBSHARES
 ===============================================================
  This function automates the following tasks:

  o Determine current computer's domain
  o Enumerate domain computers
  o Check if computers respond to ping requests
  o Filter for computers that have TCP 445 open and accessible
  o Enumerate SMB shares
  o Enumerate SMB share permissions
  o Identify shares with potentially excessive privileges
  o Identify shares that provide read or write access
  o Identify shares thare are high risk
  o Identify common share owners, names, & directory listings
  o Generate last written & last accessed timelines
  o Generate html summary report and detailed csv files

  Note: This can take hours to run in large environments.
 ---------------------------------------------------------------
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ---------------------------------------------------------------
 SHARE DISCOVERY
 ---------------------------------------------------------------
 [*][07/24/2025 14:53] Scan Start
 [*][07/24/2025 14:53] Output Directory: c:\Users\Public\SmbShareHunt-07242025145315
 [*][07/24/2025 14:53] Successful connection to domain controller: DC01.inlanefreight.local
 [*][07/24/2025 14:53] Performing LDAP query for computers associated with the inlanefreight.local domain
 [*][07/24/2025 14:53] -  computers found
 [*][07/24/2025 14:53] - 0 subnets found
 [*][07/24/2025 14:53] Pinging  computers
 [*][07/24/2025 14:53] -  computers responded to ping requests.
 [*][07/24/2025 14:53] Checking if TCP Port 445 is open on  computers
 [*][07/24/2025 14:53] - 1 computers have TCP port 445 open.
 [*][07/24/2025 14:53] Getting a list of SMB shares from 1 computers
 [*][07/24/2025 14:53] - 11 SMB shares were found.
 [*][07/24/2025 14:53] Getting share permissions from 11 SMB shares
 [*][07/24/2025 14:53] - 51 share permissions were enumerated.
 [*][07/24/2025 14:53] Identifying potentially excessive share permissions
 [*][07/24/2025 14:53] - 7 potentially excessive privileges were found on 4 shares across 1 systems.
 [*][07/24/2025 14:53] Getting directory listings from 4 SMB shares
 [*][07/24/2025 14:53] - Targeting up to 3 nested directory levels
 [*][07/24/2025 14:53] - 400 files and folders were enumerated.
 [*][07/24/2025 14:53] Scan Complete
 ---------------------------------------------------------------
 SHARE ANALYSIS
 ---------------------------------------------------------------
 [*][07/24/2025 14:53] Analysis Start
 [*][07/24/2025 14:53] - 4 shares can be read across 1 systems.
 [*][07/24/2025 14:53] - 1 shares can be written to across 1 systems.
 [*][07/24/2025 14:53] - 7 shares are considered non-default across 1 systems.
 [*][07/24/2025 14:53] - 2 shares are considered high risk across 1 systems.
 [*][07/24/2025 14:53] - Identified top 200 owners of excessive shares.
 [*][07/24/2025 14:53] - Identified top 200 share groups.
 [*][07/24/2025 14:53] - Identified top 200 share names.
 <-----SNIP----->

Eso nos genera el reporte en HTML, que podemos abrir con Firefox:

Análisis desde Kali Linux

Usaremos Manspider para intentar enumerar archivos que puedan contener credenciales por SMB:

pip install pipx
pipx install git+https://github.com/blacklanternsecurity/MANSPIDER
manspider 10.129.234.121 -f 'passw user admin account network login logon cred' -u 'mendres' -p 'Inlanefreight2025!'

Pregunta 2

Como usuario, busque entre los recursos compartidos adicionales a los que tiene acceso e identifique la contraseña de un administrador de dominio. ¿Qué es?

Última actualización

¿Te fue útil?