As part of the Imperva Research Labs we have the opportunity to examine various security scenarios. In this post, we will consider database security on SQL Server.
One standard method that security practitioners use to protect databases is deploying honeypots and waiting for hackers to take the bait. Honeypots are very useful because they enable us to analyze various attacks and get more insights about the methods and techniques that bad actors use to attack databases.
Here we provide a glimpse into todays Database Attack Landscape. This is a follow-up to Imperva Research Labs research done in 2018 on SQL Server. To see those findings, check out A Deep Dive into Database Attacks [Part II]. In that piece, you can see how little the attack landscape has changed in the past 3 years.
We will explore the methods and techniques attackers use to deploy malware, gain persistence, and take over the system to join the server into massive botnets, or escalate privileges in order to infiltrate an organizations network.
While other articles concentrate on the malware itself, we are going to focus on the database side of the attack, the dangerous functions, and the power that is stored inside the SQL Server to interact with other components of the Windows OS called COM objects. Some examples are processes like WMI, XML, HTTP, WScript, VBScripts and more.
Hackers use attack methods that will have the most chance to succeed. Core features that are defined in multiple versions are the ultimate target. This is one reason why we see hackers using the same methods with slight changes over the years; exploits recycling is very common. The database attack landscape hasnt changed a lot over the years and exploitation techniques are being reused over the years.
SQL Server OLE Automation is one example of such a target as it is a built-in feature for many SQL Server versions. We will inspect some of the techniques in depth and explain the ways to prevent similar attacks on your SQL Server in the future.
Before we dive into the depth of the attacks, we need to understand some Windows terms, Specifically the OLE and COM objects.
OLE stands for Object Linking and Embedding. It is a technology developed by Microsoft that allows one application to link objects into another application. Later, the OLE evolved and reimplemented on top of COM. Component Object Model (COM) is a binary-interface standard for software components. Simply put, COM allows for one application to expose its functionality to other applications.
SQL Server OLE Automation Procedures enables the SQL Server to leverage OLE to interact with other COM objects. Data security-wise, this increases the attack surface.
There are excellent examples out there for leveraging COM objects to perform lateral movement.
All of this power is granted simply by enabling a small but dangerous database configuration, the OLE Automation Procedures. In addition, SQL Server provides multiple extended procedures to link and interact with the COM objects.
Extended Procedure simply means the ability to execute code from external sources. The OLE Automation Procedures use odsole70.dll to interact with COM objects.
The below procedures contain everything we need to carry out a highly sophisticated attack interact with other COM objects:
sp_OACreate Creates an instance of an OLE object.sp_OAMethod Calls a method of an OLE object.sp_OAGetProperty Gets a property value of an OLE object.sp_OASetProperty Sets a property of an OLE object to a new value.sp_OADestroy Destroys a created OLE object.sp_OAGetErrorInfo Obtains OLE Automation error information.sp_OAStop Stops the server-wide OLE Automation stored procedure execution environment.
Here are a couple of examples for practical usage of attacks using the OLE Automation.
In A Deep Dive into Database Attacks [Part II], we saw how it is possible to write files by interacting with the filesystemobject.
But the filesystemobject COM object allows us to do much more than that, we can copy files, manage drives, and much more.
For the full list of the filesystemobject methods from Microsoft documentation click here.
The below example describes a method used by the attacker to copy executables in different names and locations in order to avoid detection. This technique allows the attacker to stay under the radar in the case that there is a security policy in place. Also, it makes the post mortem analysis more complicated:
Figure 1: copy http://ftp.exe and cacls.exe executables with different name and location.
ScriptControl allows us to actually run a scripting language such as VBScript or JavaScript from within our SQL Server. This is one of the strongest abilities of the COM objects.
More information about the ScriptControl COM object, methods and properties can be found here.
Here are two practical examples of using the ScriptControl method. The first to create an account and the second is to download malware:
In the example below, the attacker uses JavaScript to create an account, change its password and add the new account to the administrators group:
Figure 2: Attacker creates a Windows account, changes its password and adds it to the administrators group.
The next example shows how to download malware from a remote server, save it to a file, and execute it:
Figure 3: Attacker downloads malware from remote server.
Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems.
In the next example, the attacker allows full access to everyone to use Windows Script Host, which allows them to execute scripts in a variety of languages.
Note that since this action is performed from inside the SQL Server process, the action will have the SQL Server security context.
The steps taken by the attacker to achieve full access:
The description of the SE_DACL_PRESENT permission from msdn:Indicates an SD that has a DACL. If this flag is not set, or if this flag is set and the DACL is NULL, the SD allows full access to everyone.
In this case the DACL is not set on creation, therefore the security descriptor will allow full access on wscript.exe to everyone.
Figure 4: Attacker leverages WMI to set permission on executable.
For more information about the SWbemLocator, SWbemServices and SecurityDescriptor.
It is recommended to disable the option to use those SQL Server abilities:
Figure 5: Disable the OLE Automation features of SQL Server.
Another method to make sure that those powerful procedures are not being used is just dropping them:
Figure 6: Revoke EXECUTE permission on dangerous functions of SQL Server.
Since OLE Automation is a built-in feature, there is no actual way to prevent the activation of the feature. It is recommended to add monitoring for the events of re-enabling the configuration & recreating the extended procedures and granting execution on the procedures.
Once an attacker gains access to the database it wont necessarily stop there.
Many known cases are published where after exfiltrating data from one database the attackers decided to become residents inside the organization network, make a lateral movement and exfiltrate data from more than just one database. Learn more about attacker types and data breaches in my blog Know your enemy! The four types of cyber attackers trying to breach your security today and the white paper Lessons Learned From Analysis of 100 Data Breaches.
We saw how the attacker was able to change the executables permission on the OS, copy and manipulate OS files to stay undetected and finally deploy malware and execute scripts on the victim server. The attacker made everything from inside the SQL Server service without actually having access to the OS, but still had a deep impact on the underlying OS configuration.
The OLE Automation is a very powerful feature, which makes it very dangerous. If you are not using OLE Automation, it needs to be disabled. Disabling unnecessary features in the database will reduce the attack surface.
Imperva offers different products to help our customers to protect against database attacks, for on-premises and cloud services. For more information visit the following link.
The post How to Exploit SQL Server Using OLE Automation appeared first on Blog.
*** This is a Security Bloggers Network syndicated blog from Blog authored by Ofir Shaty. Read the original post at: https://www.imperva.com/blog/how-to-exploit-sql-server-using-ole-automation/
See more here:
How to Exploit SQL Server Using OLE Automation - Security Boulevard
- Automation Personnel Services - Temporary Staffing ... [Last Updated On: March 25th, 2016] [Originally Added On: March 25th, 2016]
- Automation | Define Automation at Dictionary.com [Last Updated On: March 25th, 2016] [Originally Added On: March 25th, 2016]
- Automation | Definition of automation by Merriam-Webster [Last Updated On: March 25th, 2016] [Originally Added On: March 25th, 2016]
- Automation | The Car Company Tycoon Game [Last Updated On: March 25th, 2016] [Originally Added On: March 25th, 2016]
- Automation - Wikipedia, the free encyclopedia [Last Updated On: March 25th, 2016] [Originally Added On: March 25th, 2016]
- Automation - Cloud process & workflow automation | Microsoft ... [Last Updated On: June 29th, 2016] [Originally Added On: June 29th, 2016]
- Riverside Automation - Machine Controls [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- Automation: The Car Company Tycoon Game Windows - Mod DB [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- System Integration | Industrial Automation [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- WinAutomation - Smart Macro Recorder, Web Automation ... [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- Automation Solutions - Home [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- The Automation Conference [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- Rohtek Automation [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- JL Automation, LLC | Home Automation, A/V Automation [Last Updated On: July 3rd, 2016] [Originally Added On: July 3rd, 2016]
- Four fundamentals of workplace automation | McKinsey & Company [Last Updated On: August 27th, 2016] [Originally Added On: August 27th, 2016]
- Leviton Security & Home Automation [Last Updated On: August 27th, 2016] [Originally Added On: August 27th, 2016]
- EVA Automation [Last Updated On: September 6th, 2016] [Originally Added On: September 6th, 2016]
- News | Automation | The Car Company Tycoon Game [Last Updated On: September 6th, 2016] [Originally Added On: September 6th, 2016]
- Automation - The Car Company Tycoon Game on Steam [Last Updated On: September 6th, 2016] [Originally Added On: September 6th, 2016]
- Test automation - Wikipedia, the free encyclopedia [Last Updated On: September 6th, 2016] [Originally Added On: September 6th, 2016]
- Job Seekers - Automation Personnel Services [Last Updated On: October 8th, 2016] [Originally Added On: October 8th, 2016]
- Custom Automation & Machine Design | Automation GT [Last Updated On: October 31st, 2016] [Originally Added On: October 31st, 2016]
- iAutomation [Last Updated On: October 31st, 2016] [Originally Added On: October 31st, 2016]
- Test automation - Wikipedia [Last Updated On: November 16th, 2016] [Originally Added On: November 16th, 2016]
- Automation - Official Site [Last Updated On: November 19th, 2016] [Originally Added On: November 19th, 2016]
- Beckhoff Automation - Wikipedia [Last Updated On: November 21st, 2016] [Originally Added On: November 21st, 2016]
- Automation - Security Hyperstore [Last Updated On: November 21st, 2016] [Originally Added On: November 21st, 2016]
- IT Automation - BMC [Last Updated On: November 29th, 2016] [Originally Added On: November 29th, 2016]
- ID Automation [Last Updated On: November 29th, 2016] [Originally Added On: November 29th, 2016]
- The Best Home Automation Systems of 2016 | Top Ten Reviews [Last Updated On: December 24th, 2016] [Originally Added On: December 24th, 2016]
- What is Home Automation? | Home Automation Systems [Last Updated On: December 24th, 2016] [Originally Added On: December 24th, 2016]
- Beyond Automation - hbr.org [Last Updated On: December 25th, 2016] [Originally Added On: December 25th, 2016]
- Build automation - Wikipedia [Last Updated On: December 26th, 2016] [Originally Added On: December 26th, 2016]
- Home automation - Wikipedia [Last Updated On: January 10th, 2017] [Originally Added On: January 10th, 2017]
- Automation | Food Engineering [Last Updated On: January 13th, 2017] [Originally Added On: January 13th, 2017]
- Home Automation - Enerwave Home Automation [Last Updated On: January 14th, 2017] [Originally Added On: January 14th, 2017]
- Automation - DESHAZO [Last Updated On: January 14th, 2017] [Originally Added On: January 14th, 2017]
- Robots, Automation, EOAT, Grippers, Conveyors, Guarding [Last Updated On: January 26th, 2017] [Originally Added On: January 26th, 2017]
- Werner Electric | Automation [Last Updated On: January 28th, 2017] [Originally Added On: January 28th, 2017]
- Automationtechies | Automation Engineering Recruiting [Last Updated On: January 28th, 2017] [Originally Added On: January 28th, 2017]
- Automation - Mazak Corporation [Last Updated On: January 28th, 2017] [Originally Added On: January 28th, 2017]
- Automation | Technologies | Systems | Integrator ... [Last Updated On: January 28th, 2017] [Originally Added On: January 28th, 2017]
- Test Automation Services for Development of Regression ... [Last Updated On: January 28th, 2017] [Originally Added On: January 28th, 2017]
- Carlo Gavazzi Automation Components [Last Updated On: January 30th, 2017] [Originally Added On: January 30th, 2017]
- UI Automation Overview - msdn.microsoft.com [Last Updated On: February 5th, 2017] [Originally Added On: February 5th, 2017]
- New telecom transformation goals require service automation - TechTarget [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Global Hazardous Waste Handling Automation Market: By Products ... - Business Wire (press release) [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- 2M Automation wins IoT support from Schneider - Electronics EETimes (registration) [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Futures Shaped by Automation and Catastrophe: Peter Frase on Capitalism's Endgame - Truth-Out [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Automation expected to displace insurance underwriters, real estate brokers - CIO Dive [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Automation, robots could replace 250000 public sector workers in the next 15 years - Computer Business Review [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Design Automation Conference - Business Wire (press release) [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- The Perks Of Automation And The Risks: Why To Think Twice About Getting Into That Driverless Uber - Forbes [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Lib Dems Should Embrace Automation of the Workforce - Liberal Democrat Voice [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- Voices Reinventing enterprise finance by overhauling AP automation - Accounting Today [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- How Accountants Can Use Automation Their Advantage - Accountingweb.com (blog) [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- DFLabs Launches the First Security Automation and Orchestration Platform based Upon Supervised Active Intelligence - Business Wire (press release) [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- QAD Automation Solutions is Honda Approved - Yahoo Finance [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- VIDEO: Going Big on Automation in a Small Footprint Facility - ENGINEERING.com [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- Building a better model of human-automation interaction - Phys.Org [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- AlixPartners examines automation in manufacturing and logistics management - Logistics Management [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- Report: Test automation is increasing - SD Times - SDTimes.com [Last Updated On: February 9th, 2017] [Originally Added On: February 9th, 2017]
- Automation is the unavoidable future of the economy - The Daily Cougar [Last Updated On: February 9th, 2017] [Originally Added On: February 9th, 2017]
- GM's Cruise Automation Is Testing An App to Order Self-Driving ... - Fortune [Last Updated On: February 9th, 2017] [Originally Added On: February 9th, 2017]
- Speeders beware: Legislation would allow automation crackdown ... - SFGate [Last Updated On: February 9th, 2017] [Originally Added On: February 9th, 2017]
- Orbita Ingenieria: New Age Terminal Automation - Port Technology International [Last Updated On: February 10th, 2017] [Originally Added On: February 10th, 2017]
- A Sharper Focus on the Edge - Automation World [Last Updated On: February 10th, 2017] [Originally Added On: February 10th, 2017]
- Rockwell Automation Surged 10% in January as Growth Picked Up Steam - Motley Fool [Last Updated On: February 10th, 2017] [Originally Added On: February 10th, 2017]
- Most people are optimistic about workplace automation, social data suggests - ZDNet [Last Updated On: February 10th, 2017] [Originally Added On: February 10th, 2017]
- Improving Behavior Through Automation of Vehicle Systems - School Transportation News (blog) [Last Updated On: February 11th, 2017] [Originally Added On: February 11th, 2017]
- 'We employ insane levels of automation' Kris Canekeratne - Times of India [Last Updated On: February 11th, 2017] [Originally Added On: February 11th, 2017]
- Why Don't We See More Automation in Federal Networks? - Nextgov [Last Updated On: February 11th, 2017] [Originally Added On: February 11th, 2017]
- Technobabble: Automation and the modern worker - CIO Dive [Last Updated On: February 11th, 2017] [Originally Added On: February 11th, 2017]
- Readers Write (Feb. 12): The moose population; jobs, start-ups and automation; diversity in the funny pages - Minneapolis Star Tribune [Last Updated On: February 12th, 2017] [Originally Added On: February 12th, 2017]
- Automation Nightmare: Philosopher Warns We Are Creating a World Without Consciousness - Big Think [Last Updated On: February 12th, 2017] [Originally Added On: February 12th, 2017]
- Automation can replace bureaucrats and save taxpayers money - Hot Air [Last Updated On: February 12th, 2017] [Originally Added On: February 12th, 2017]
- Automation can revitalize the US workforce - Fox News [Last Updated On: February 12th, 2017] [Originally Added On: February 12th, 2017]
- TigerStop hopes to ride automation to new heights - The Columbian [Last Updated On: February 13th, 2017] [Originally Added On: February 13th, 2017]
- Hexadite Unveils Custom Playbooks Following One Millionth Automated Cybersecurity Investigation - Yahoo Finance [Last Updated On: February 13th, 2017] [Originally Added On: February 13th, 2017]
- NEC updates postal automation system for Hongkong Post - ETCIO.com [Last Updated On: February 13th, 2017] [Originally Added On: February 13th, 2017]