Skip to main content

Memory leakage in 2-tier applications

The 2-tier applications use front-end to directly communicate to DB. There's no separate business logic tier. All the business logic are at client side. Thick client applications (mostly) are classic examples of that. Applications developed in .Net and Java could be found in big nos. inside any organization. Sometimes it's difficult to straightaway move to 3-tier architecture. Businesses are reluctant to accept this approach due to:
- Moving towards 3-tier involves a great amount of coding efforts and  money.
- Sometimes the applications are almost end of life and are not being retired just because of there;s no good reason to do so. 
- Most of the above applications are Intranet applications. Business claims that being an internal application, this is less susceptible to attack.

But they forget one very big risk under these claims- sensitive information in memory dumps. 

The application being 2-tier connects to DB while constructing the connection string using DB credentials, server name, DB name, port no. etc. These are at risk of being exposed when the client wants to connect to DB. 

But how an attacker can get the dump? He needs to have physical access to the victim's machine. So it's impossible. But we are not talking about an external attacker, we are talking about if the valid user of the application himself turns malicious. He can take the memory dump and find grab the sensitive information such as DB connection string. The soul of an application, ie, DB is compromised, bypassing the business layer. The business doesn't understand this.

So, any fix? There's no fix! As long as the app is 2-tier, there's no fix. However there are compensating controls- make it hard to grab the info from memory. 
- SecureString class- https://msdn.microsoft.com/en-/library/system.security.securestring(v=vs.110).aspx 
But only supported for .Net 4.5 and above. Represents text that should be kept confidential, such as by deleting it from computer memory when no longer needed. This class cannot be inherited.

- Write own code to overwrite the memory location- garbage collection. I saw a code by one developer which does it, to avoid password being exposed in memory. But you have to construct the connectionstring at some point of time, even momentarily, so that the app will connect to the DB and then quickly overwrite that. This reduces the attack window by a large extent- but not fixes it.

There's no real fix than moving to 3-tier architecture.For  2-tier we have to accept the risk.

Comments

Popular posts from this blog

Ardilla- New tool for finding SQL Injection and XSS

Three Researchers -- MIT's Adam Kiezun , Stanford's Philip Guo , and Syracuse University's Karthick Jayaraman -- has developed a new tool ' Ardilla ' that automatically finds and exploits SQL injection and cross-site scripting vulnerabilities in Web applications. It creates inputs that pinpoint bugs in Web applications and then generates SQL injection and XSS attacks. But for now Ardilla is for PHP -based Web app only. The researchers say Ardilla found 68 never-before found vulnerabilities in five different PHP applications using the tool -- 23 SQL injection and 45 XSS flaws. More information is awaited. For their attack generation techniques refer to their document at: http://www.cs.washington.edu/homes/mernst/pubs/create-attacks-tr054.pdf

File Upload through Null Byte Injection

Sometimes, during file upload we come across situation wherein there would be check on the file extension at the client side as well as server side too. If the application does allow only .jpeg extension to be uploaded, the client side java script checks for the extension of the file before passing the request. We all know that how easily this can be defeated. Some applications, checks for the extension at the server side also. That's not easy to bypass. However there are some ways with which it still can be bypassed. Most of server side scripts are written in high level languages such as Php, Java etc who still use some C/C++ libraries to read the file name and contents. That leads to the problem. In C/C++ a line ends with /00 or which is called Null Byte. So whenever the interpreter sees a null byte at the end of the a string, it stops reading thinking it has reached at the end of the string. This can be used for the bypass. It works for many servers, specially php servers. T

Combining power of Fiddler with Burp

Both are pretty powerful tools when it comes to intercept and modify http communications. But at some point of time, they become even more powerful combo if tied with each other. They complement each other. In a recent pentest I came across a similar situation where in Burp was not able to intercept a specific kind of traffic and Fiddler came to rescue. The application was designed to upload video. The initial communication was straight forward, I mean logging into application, filling up the video details etc. And all these were easily captured by Burp except the point where you hit the Upload Video and it connects to a different server and surprisingly it was not captured by Burp, not sure why, even after repeated attempts. So, I fired Fiddler to see if the it sees this request. But it's a;ways to play with requests using Burp due to it's various functionalities like, Intruder, Repeaters etc. But it was necessary to capture this request in Burp. So the below steps can be