<?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>lab.lonerunners.net &#187; Blog</title>
	<atom:link href="http://lab.lonerunners.net/category/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://lab.lonerunners.net</link>
	<description>Information security pills and drugs</description>
	<lastBuildDate>Thu, 01 Jul 2010 13:20:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Follow Secdocs on Twitter</title>
		<link>http://lab.lonerunners.net/blog/follow-secdocs-on-twitter</link>
		<comments>http://lab.lonerunners.net/blog/follow-secdocs-on-twitter#comments</comments>
		<pubDate>Thu, 02 Jul 2009 23:05:54 +0000</pubDate>
		<dc:creator>jekil</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[secdocs]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://lab.lonerunners.net/?p=81</guid>
		<description><![CDATA[photo credit: tashmahal You can follow SecDocs updates on Twitter now! With few lines of ruby code and twitter4r gem now each new document added to SecDocs is posted as twitter status update. So if you prefer twitter to RSS feed subscribe to @secdocs updates.]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://www.flickr.com/photos/25642587@N00/2724175411/" title="Twitter Bird" target="_blank"><img src="http://farm4.static.flickr.com/3158/2724175411_74293899db.jpg" alt="Twitter Bird" border="0" /></a><br /><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://lab.lonerunners.net/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/25642587@N00/2724175411/" title="tashmahal" target="_blank">tashmahal</a></p>
<p>You can follow <a href="http://secdocs.lonerunners.net">SecDocs</a> updates on <a href="http://twitter.com/secdocs">Twitter</a> now! With few lines of ruby code and <a href="http://twitter4r.rubyforge.org">twitter4r</a> gem now each new document added to <a href="http://secdocs.lonerunners.net">SecDocs</a> is posted as twitter status update.<br />
So if you prefer twitter to <a href="http://secdocs.lonerunners.net/feed">RSS feed</a> subscribe to @<a href="http://twitter.com/secdocs">secdocs</a> updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.lonerunners.net/blog/follow-secdocs-on-twitter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binary data fetching through SQLi</title>
		<link>http://lab.lonerunners.net/blog/binary-data-fetching-through-sqli</link>
		<comments>http://lab.lonerunners.net/blog/binary-data-fetching-through-sqli#comments</comments>
		<pubDate>Mon, 23 Feb 2009 20:45:23 +0000</pubDate>
		<dc:creator>jekil</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Paper]]></category>
		<category><![CDATA[binary data]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[data casting]]></category>
		<category><![CDATA[SQL Injection]]></category>

		<guid isPermaLink="false">http://lab.lonerunners.net/?p=18</guid>
		<description><![CDATA[photo credit: spdorsey Table of contents 1. Introduction 2. How BLOB storage works 3. Casting binary data 3.1 MySQL 3.2 PostgreSQL 3.3 SQL Server 4. References 1. Introduction Exploiting a SQL injection flaw in a web application can give the attacker full control of the remote DBMS. One of the major consequences of exploiting consists [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img src="http://farm4.static.flickr.com/3250/2920925776_2b18b82344.jpg" border="0" alt="10" /></p>
<p style="text-align: right;"><a title="Attribution-NoDerivs License" href="http://creativecommons.org/licenses/by-nd/2.0/" target="_blank"><img src="http://lab.lonerunners.net/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a title="spdorsey" href="http://www.flickr.com/photos/47082206@N00/2920925776/" target="_blank">spdorsey</a></p>
<h2>Table of contents</h2>
<p>1. Introduction<br />
2. How BLOB storage works<br />
3. Casting binary data<br />
3.1 MySQL<br />
3.2 PostgreSQL<br />
3.3 SQL Server<br />
4. References</p>
<h2>1. Introduction</h2>
<p>Exploiting a SQL injection flaw in a web application can give the attacker full control of the remote DBMS. One of the major consequences of exploiting consists in fetching all or part of the data stored in the database.</p>
<p>In several cases, like a web application that stores images on the database, the attacker has to deal with binary data.</p>
<p>Follows some techniques to fetch binary data via a SQL injection flaw.</p>
<h2>2. How BLOB storage works</h2>
<p>According to Wikipedia a BLOB[1] is:</p>
<blockquote><p>A binary large object, also known as a blob, is a collection of binary data stored as a single entity in a database management system. Blobs are typically images, audio or other multimedia objects, though sometimes binary executable code is stored as a blob. Database support for blobs is not universal.</p>
<p>Blobs were originally just amorphous chunks of data invented by Jim Starkey at DEC, who describes them as &#8220;the thing that ate Cincinnati, Cleveland, or whatever&#8221;. Later, Terry McKiever, a marketing person for Apollo felt that it needed to be an acronym and invented the backronym Basic Large Object. Then Informix invented an alternative backronym, Binary Large Object. Today many people believe that blob was originally intended as an acronym for something.</p></blockquote>
<p>The BLOB data can be stored in the DBMS tables or as usual file system files linked by a pointer in the data table.  The BLOB storage engine  is built with one or a combination of these techniques to get the best performances.</p>
<p>The BLOB storage is handled by the DBMS engine that provides high level SQL statement to the user.</p>
<h2>3. Casting Binary data</h2>
<p>The idea behind the hack is to cast the BLOB data to another data-type that can be fetched via SQLi. For example: cast a BLOB to a string containing the BLOB encoded in base64, so we can use a string representation of binary object that acts as middleware to fetch data over any type of SQL injection.</p>
<p>As far as I know there are no public automatic SQL injection tools that can fetch binary data from a vulnerable web application.</p>
<h2>3.1 MySQL</h2>
<p>In MySQL SQL syntax the function HEX()[2] can be used to get the hexadecimal value of one field of any data-type. The function HEX(`foo`) returns a string representation of the hexadecimal value of foo, where foo is a binary large object (BLOB). So we can cast a binary data-type to a string data-type.</p>
<p>For example the following SQL statement returns the hexadecimal value of the binary object stored in the field named blob:</p>
<blockquote><p>SELECT HEX(`blob`) FROM footable;</p></blockquote>
<p>Now we can use the hexadecimal BLOB representation to fetch data from binary (BLOB) fields using the standard techniques to fetch data via SQL injection or blind SQL injection.</p>
<p>Using HEX() we can deal a BLOB as a text string and use the common techniques and tools.</p>
<p>Once we have fetched the binary data encoded as hexadecimal, we have to restore the original binary data out of it. We can use the SQL UNHEX() function, that get a hexadecimal string and outputs a BLOB object, a command line utility or a few lines in you favorite programming language can do the trick.</p>
<p>This is the easy way to get a textual representation of BLOB under MySQL, the HEX() function is supported from MySQL 4.1.</p>
<h2>4.2 PostgreSQL</h2>
<p>PostgreSQL can not store values of more than several thousands bytes within any data-type except large objects, nor can binary data be easily entered within single quotes. Instead, large objects (BLOB) are used to store very large values and binary data.</p>
<p>BLOB permits storage of any operating system file, including images or large text files, directly into the database.</p>
<p>As you can see in the DBMS data-type comparison sheet[3] PostgreSQL stores BLOB data in a data-type called OID that acts like a pointer to the stored object on the file system.</p>
<p>For example using the psql client from command line you can load the file into the database using lo_import(), and retrieve it from the database using lo_export() which works only for local files[4].</p>
<blockquote><p>postgres=# CREATE TABLE foo (image OID);<br />
CREATE TABLE<br />
postgres=# INSERT INTO foo VALUES (lo_import(&#8216;/tmp/bar.jpg&#8217;));<br />
INSERT 0 1</p></blockquote>
<p>The lo_import() function stores /tmp/bar.jpg into the database. The function call returns an OID that is used to refer the imported large object. This value is stored in foo.image as an integer.</p>
<p>If you want to read the foo.image value the lo_export() function uses the OID value to find the large object stored in the database, then places the exported file into the output file.</p>
<p>Full path names must be used with large objects because the database server runs in a different directory than the psql client. Files are imported and exported by the postgres user, so postgres must have permission to read the file for lo_import() and directory write permission for lo_export().</p>
<p>There are others functions to manage large objects (BLOB) available under PostreSQL[5].</p>
<p>Because large objects uses the local filesystem, users connecting over a network can not use lo_import() or lo_export(). They can, however, use psql&#8217;s \lo_import and \lo_export commands.</p>
<p>If we are exploiting a SQL injection in a web application we can&#8217;t use the functions lo_import() and lo_export() but we need a way to get the juice data on the vulnerable server.</p>
<p>From PostgreSQL documentation &#8220;String Functions and Operators&#8221;[6] we catch the function ENCODE(data bytea, type text).</p>
<p>This function encodes binary data to an ASCII-only representation. The supported types are: base64, hex, escape.</p>
<p>Now we have the function to convert a bytea data-type into a base64 or hex string. We need only to convert the BLOB OID in a bytea.</p>
<p>The fastest way to do this is a two step recipe: first get the number of OID that you need and after quering the system table pg_largeobject.</p>
<blockquote><p>postgres=# SELECT image FROM foo;<br />
image<br />
&#8212;&#8212;-<br />
16387<br />
(1 row)<br />
postgres=# SELECT ENCODE(data, &#8216;base64&#8242;) FROM pg_largeobject WHERE LOID=16387;<br />
encode<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;<br />
JVBERi0xLjINJeLjz9MNCjIwOSAwIG9iag08PCANL0xpbmVhcml6ZWQgMSAN<br />
IDYyOCA4NTEgXSANL0wgMjU4NDYxOCANL0UgMTI5NDg1IA0vTiAxNiANL<br />
DWVuZG9iag0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC<br />
[snip..]<br />
M2I4MWJkNTdlOTNjNWVmNj5dDT4+DXN0YXJ0eHJlZg0xNzMNJSVFT0YN<br />
(1263 rows)</p></blockquote>
<p>Now you get your goal and you can fetch a BLOB on PostgreSQL with only two queries.</p>
<p>For further details on PostgreSQL BLOB functions you can refer to &#8220;SQLi: Writing files to disk under PostgreSQL&#8221;[7].</p>
<h2>3.3 SQL Server</h2>
<p>SQL Server stores binary data in the following data-types: BINARY, VARBINARY, IMAGE.</p>
<p>You can create a demo table for your test with:</p>
<blockquote><p>CREATE TABLE dbo.foo<br />
(<br />
image image NULL<br />
)  ON [PRIMARY]<br />
TEXTIMAGE_ON [PRIMARY]<br />
GO</p></blockquote>
<p>You can insert the file foo.bmp with the following:</p>
<blockquote><p>INSERT INTO [tempdb].[dbo].[foo]<br />
([image])<br />
SELECT * FROM<br />
OPENROWSET(BULK N&#8217;C:\foo.bmp&#8217;, SINGLE_BLOB) AS i<br />
GO</p></blockquote>
<p>The binary data can be converted to a hex string injecting a stored procedure in SQL Server. This is described in Microsoft kb104829[8].</p>
<blockquote><p>create procedure sp_hexadecimal<br />
@binvalue varbinary(255)<br />
as<br />
declare @charvalue varchar(255)<br />
declare @i int<br />
declare @length int<br />
declare @hexstring char(16)</p>
<p>select @charvalue = &#8217;0x&#8217;<br />
select @i = 1<br />
select @length = datalength(@binvalue)<br />
select @hexstring = &#8220;0123456789abcdef&#8221;</p>
<p>while (@i &lt;= @length)<br />
begin</p>
<p>declare @tempint int<br />
declare @firstint int<br />
declare @secondint int</p>
<p>select @tempint = convert(int, substring(@binvalue,@i,1))<br />
select @firstint = floor(@tempint/16)<br />
select @secondint = @tempint &#8211; (@firstint*16)</p>
<p>select @charvalue = @charvalue +<br />
substring(@hexstring, @firstint+1, 1) +<br />
substring(@hexstring, @secondint+1, 1)</p>
<p>select @i = @i + 1</p>
<p>end</p>
<p>select &#8216;sp_hexadecimal&#8217;=@charvalue</p></blockquote>
<h2>3.4 Other DBMS</h2>
<p>The same technique can be used in any other DBMS like Oracle, DB2, Informix that have casting functions or BLOB conversion functions.</p>
<h2>4. References</h2>
<p>[1] <a href="http://en.wikipedia.org/wiki/Binary_large_object">http://en.wikipedia.org/wiki/Binary_large_object</a><br />
[2] <a href="http://dev.mysql.com/doc/mysql/en/String_functions.html">http://dev.mysql.com/doc/mysql/en/String_functions.html</a><br />
[3] <a href="http://www.lonerunners.net/1246-database-datatype-comparison-sheet.html">http://www.lonerunners.net/1246-database-datatype-comparison-sheet.html</a><br />
[4]  <a href="http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html">http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html</a><br />
[5] <a href="http://www.postgresql.org/docs/8.3/interactive/largeobjects.html">http://www.postgresql.org/docs/8.3/interactive/largeobjects.html</a><br />
[6] <a href="http://www.postgresql.org/docs/8.1/interactive/functions-string.html">http://www.postgresql.org/docs/8.1/interactive/functions-string.html</a><br />
[7] <a href="http://lab.lonerunners.net/blog/sqli-writing-files-to-disk-under-postgresql">http://lab.lonerunners.net/blog/sqli-writing-files-to-disk-under-postgresql</a><br />
[8] <a href="http://support.microsoft.com/kb/104829">http://support.microsoft.com/kb/104829</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lab.lonerunners.net/blog/binary-data-fetching-through-sqli/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtual host and DNS names enumeration techniques</title>
		<link>http://lab.lonerunners.net/blog/virtual-host-and-dns-names-enumeration-techniques</link>
		<comments>http://lab.lonerunners.net/blog/virtual-host-and-dns-names-enumeration-techniques#comments</comments>
		<pubDate>Sat, 24 Jan 2009 17:36:52 +0000</pubDate>
		<dc:creator>jekil</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Paper]]></category>
		<category><![CDATA[discovery]]></category>
		<category><![CDATA[dns alias]]></category>
		<category><![CDATA[dns name]]></category>
		<category><![CDATA[enumeration]]></category>
		<category><![CDATA[hostmap]]></category>
		<category><![CDATA[virtual host]]></category>

		<guid isPermaLink="false">http://lab.lonerunners.net/?p=39</guid>
		<description><![CDATA[photo credit: Hey Paul Table of Contents 1. Why you need to enumerate 2. Techniques 2.1 DNS enumeration techniques 2.2 Banner grabbing 2.3 SSL/TLS Protocol enumeration techniques 2.4 HTTP Protocol enumeration techniques 2.5 Passive web enumeration techniques 2.6 Active web enumeration techniques 1. Why you need to enumerate The host name discovery phase is an [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Culture Tubes" href="http://www.flickr.com/photos/10775233@N00/107326169/" target="_blank"></a></p>
<p style="text-align: center;"><img src="http://farm1.static.flickr.com/41/107326169_8b4e8afd1f.jpg" border="0" alt="Culture Tubes" /></p>
<p style="text-align: right;"><a title="Attribution License" href="http://creativecommons.org/licenses/by/2.0/" target="_blank"><img src="http://lab.lonerunners.net/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a title="Hey Paul" href="http://www.flickr.com/photos/10775233@N00/107326169/" target="_blank">Hey Paul</a></p>
<h2>Table of Contents</h2>
<p>1. Why you need to enumerate<br />
2. Techniques<br />
2.1 DNS enumeration techniques<br />
2.2 Banner grabbing<br />
2.3 SSL/TLS Protocol enumeration techniques<br />
2.4 HTTP Protocol enumeration techniques<br />
2.5 Passive web enumeration techniques<br />
2.6 Active web enumeration techniques</p>
<h2>1. Why you need to enumerate</h2>
<p>The host name  discovery phase is an information gathering act to get a complete and detailed view of target resources and attack points.</p>
<p>During an attack or a penetration test, the attacker needs to known <span style="font-size: small;"> as much information as possible about the entry</span> points to attack. An entry point can be identified with an IP address, a service port, and some application level information, like the virtual host name in the case of a web server hosting several sites.</p>
<h2>2. Techniques</h2>
<p>There are several techniques that can be used to discover host names and virtual hosts associated with a IP address.</p>
<p>Some techniques described here are implemented (and the others will be implemented soon)  in hostmap, a tool that I wrote to discover virtual hosts and DNS names of a given IP address. <span style="font-size: small;">As of today, the tool is private (it does not depend on me)</span> but I hope to release it to the public domain soon.</p>
<h2>2.1 DNS enumeration techniques</h2>
<p>The following enumeration techniques are based on the DNS protocol and are:</p>
<p>•<strong> Reverse DNS lookup</strong>: Performs a PTR request to get the host name from IP address.</p>
<p>• <strong>Name servers record lookup</strong>: Get the authoritative name server for the target host.</p>
<p>• <strong>Mail exchange record lookup</strong>: Get the MX records for the target host domain.</p>
<p>• <strong>DNS AXFR zone transfer</strong>: The name server that serve the target machine&#8217;s domain zone can be prone to a zone transfer attack. This allows an attacker to perform <span style="font-size: small;">an AXFR DNS request to retrieve all of the DNS records served.</span></p>
<p>• <strong>Host name brute forcing</strong>: Using a brute-forcing <span style="font-size: small;">technique to guess a hos</span>t name on the enumerated domain that resolve as the target ip address.</p>
<h2>2.2 Banner grabbing</h2>
<p>The services exposed by the target host can disclose a host name in the response banner. You need to simply telnet in all open ports and wait for a response banner (or negotiate the application protocol). For example this is the response banner of a SMTP server running Postfix:</p>
<pre>$ telnet 10.0.0.1 25
Trying 10.0.0.1...
Connected to 10.0.0.1.
Escape character is '^]'.
220 mail.example.lan ESMTP Postfix</pre>
<p>As you can see in the response banner you get the host name.</p>
<h2>2.3 SSL/TLS Protocol enumeration techniques</h2>
<p>The following enumeration techniques are based on the SSL/TLS protocol and is:</p>
<p>•<strong> X.509 Certificate</strong>: <span style="font-size: small;">Often the target machine exposes an HTTP over SSL service</span>. A connection is tried to the common HTTP service ports and is tried to negotiate an SSL/TLS connection, if the remote server supply a X.509 certificate the host name is taken from the Common Name (CN) field.</p>
<h2>2.4 HTTP Protocol enumeration techniques</h2>
<ul>
<li><strong>Virtual host brute-forcing</strong>: The web server can be brute-forced to guess a website served by the target host.</li>
<li><strong>Following redirects</strong>: It is possible to guess another website served by the target host following redirects (HTTP code 301 and 302).</li>
<li><strong>With error pages</strong>: If you try to get an error page (code 500) sometimes you can get an error page showing a banner with the host name.</li>
</ul>
<h2>2.5 Passive web enumeration techniques</h2>
<p>The following enumeration techniques are based on third party web sites and are:</p>
<p>• <strong>Search engines</strong>: The following search engines can be used and queried using the target IP address:</p>
<p>– Microsoft Live (with the dork &#8220;ip:&#8221;): [<a href="http://search.msn.com">http://search.msn.com</a>]</p>
<p>• <strong>GPG/PGP key databases</strong>: The following public databases can be used:</p>
<p>– MIT gpg key server: [<a href="http://pgp.mit.edu:11371">http://pgp.mit.edu:11371</a>]</p>
<p>• <strong>DNS/WHOIS databases</strong>: Public whois information databases like RIPE, or DNS snapshot database can be used to passively enumerate host name and track his history.</p>
<p>The following is a partial list of  public databases that can be used:</p>
<p>– Domainsdb: [<a href="http://www.domainsdb.net/">http://www.domainsdb.net/</a>]</p>
<p>– Fbk.de: [<a href="http://www.bfk.de/">http://www.bfk.de/</a>]</p>
<p>– Gigablast: [<a href="http://www.gigablast.com">http://www.gigablast.com</a>]</p>
<p>– Netcraft: [<a href="http://searchdns.netcraft.com">http://searchdns.netcraft.com</a>]</p>
<p>– Robtex: [<a href="http://www.robtex.com">http://www.robtex.com</a>]</p>
<p>– Tomdns: [<a href="http://www.tomdns.net">http://www.tomdns.net</a>]</p>
<p>– Web hosting: [<a href="http://whois.webhosting.info/">http://whois.webhosting.info/</a>]</p>
<p>– Web-max: [<a href="http://www.web-max.ca">http://www.web-max.ca</a>]</p>
<h2>2.6 Active web enumeration techniques</h2>
<ul>
<li><strong>Crawling</strong>: All published websites can be crawled for links to other sites and checked (if they resolve as the target IP address) to get other sites hosted on the target. This technique is very time consuming.</li>
</ul>
<p><span style="color: #ff0000;"><strong>UPDATE</strong></span>: hostmap is a free, automatic, hostnames and virtual hosts discovery tool written in Python. hostmap has been released in may and you can get it at <a href="http://hostmap.sourceforge.net/">http://hostmap.sourceforge.net/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lab.lonerunners.net/blog/virtual-host-and-dns-names-enumeration-techniques/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Wikipedia as brute forcing dictionary</title>
		<link>http://lab.lonerunners.net/blog/using-wikipedia-as-brute-forcing-dictionary</link>
		<comments>http://lab.lonerunners.net/blog/using-wikipedia-as-brute-forcing-dictionary#comments</comments>
		<pubDate>Thu, 08 Jan 2009 02:23:42 +0000</pubDate>
		<dc:creator>jekil</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[brute forcer]]></category>
		<category><![CDATA[brute forcing]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[wikipedia]]></category>
		<category><![CDATA[words]]></category>

		<guid isPermaLink="false">http://lab.lonerunners.net/?p=32</guid>
		<description><![CDATA[photo credit: ElektraCute The success and the time elapsed in a brute forcing attack depends by the number of discovered brute forcing points, the quality of the tool used (like THC-hydra, brutus or medusa) and the quality of the dictionary used. Sometimes using a incremental dictionary is a waste of time, a good dictionary can [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: right;"><a title="Why do we need a dictionary when we have wireless?" href="http://www.flickr.com/photos/88903556@N00/119058236/" target="_blank"><img class="aligncenter" src="http://farm1.static.flickr.com/37/119058236_445839c2db.jpg" border="0" alt="Why do we need a dictionary when we have wireless?" /></a><br />
<a title="Attribution License" href="http://creativecommons.org/licenses/by/2.0/" target="_blank"><img src="http://lab.lonerunners.net/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a title="ElektraCute" href="http://www.flickr.com/photos/88903556@N00/119058236/" target="_blank">ElektraCute</a></p>
<p>The success and the time elapsed in a <a href="http://en.wikipedia.org/wiki/Brute_force_attack">brute forcing attack</a> depends by the number of discovered brute forcing points, the quality of the tool used (like <a href="http://freeworld.thc.org/thc-hydra/">THC-hydra</a>, <a href="http://www.hoobie.net/brutus/">brutus</a> or <a href="http://www.foofus.net/jmk/medusa/medusa.html">medusa</a>) and the quality of the dictionary used.</p>
<p>Sometimes using a incremental dictionary is a waste of time, a good dictionary can be the success key to a fast brute forcing attack. Get a dictionary of common words and keep it updated is an hard work.</p>
<p><a href="http://www.wikipedia.org">Wikipedia</a> is a free multilingual encyclopedia, it currently contains <a title="Special:Statistics" href="http://en.wikipedia.org/wiki/Special:Statistics">2,683,099</a> articles. This is a really good database to generate a dictionary of common words.</p>
<p><a href="http://www.wikipedia.org">Wikipedia</a> offers free copies of all available content to interested users. These databases can be used for <a title="Wikipedia:Mirrors and forks" href="http://en.wikipedia.org/wiki/Wikipedia:Mirrors_and_forks">mirroring</a>, personal use, informal backups, or database queries. All text content is licensed under the <a class="mw-redirect" title="Wikipedia:Text of the GFDL" href="http://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GFDL">GNU Free Documentation License</a> (GFDL). Images and other files are available under <a class="mw-redirect" title="Wikipedia:ICT" href="http://en.wikipedia.org/wiki/Wikipedia:ICT">different terms</a>, as detailed on their description pages.</p>
<p>The Wikipedia database download page is available here: <a href="http://en.wikipedia.org/wiki/Wikipedia_database">http://en.wikipedia.org/wiki/Wikipedia_database</a> and the database dumps atre available here: <a href="http://download.wikimedia.org/backup-index.html">http://download.wikimedia.org/backup-index.html</a></p>
<p>A good dictionary must contains the most common terms used in a current language and also common words that can be used as password, an example is &#8220;foo&#8221;, &#8220;bar&#8221;, &#8220;1234&#8243;, &#8220;antani&#8221;, etc.</p>
<p>We can create two types of dictionary, a dictionary contining all the words inside wikipedia, a dictionary containing all article titles, a dictionary containing all the words in the article titles.</p>
<p>After downloading a bunch of gigs we get the wikipedia database dump in XML, the fields that we need to create our dictionay are &lt;title&gt; and &lt;text&gt;.</p>
<p>Now you can create all the types of dictionary that you need: words, titles, case sensitive or case insensitive.</p>
<p>To achieve better performances I used simple bash scripting for parsing because using a DOM or SAX parser is too slow with these very big XMLs.</p>
<p>This dictionary contains all the article titles, so you can guess password like names, cities, etc.</p>
<p>To create it you can use the following or you can edit it to fit your needs, it&#8217;s not beautiful but works:</p>
<p>grep -E &#8216;&lt;title&gt;(.*?)&lt;/title&gt;&#8217; itwiki-20081206-pages-meta-current.xml | cut -d &#8216;&gt;&#8217; -f2| cut -d &#8216;&lt;&#8217; -f1 | grep -v : | sed s/\(.*\)//g| sort | uniq</p>
<p>Word dictionary contains all the words in the wikipedia articles, you can create it with a command similar to the above, I left it for your homework <img src='http://lab.lonerunners.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Happy brute forcing!</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.lonerunners.net/blog/using-wikipedia-as-brute-forcing-dictionary/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLi: Writing files to disk under PostgreSQL</title>
		<link>http://lab.lonerunners.net/blog/sqli-writing-files-to-disk-under-postgresql</link>
		<comments>http://lab.lonerunners.net/blog/sqli-writing-files-to-disk-under-postgresql#comments</comments>
		<pubDate>Sun, 21 Dec 2008 13:03:54 +0000</pubDate>
		<dc:creator>jekil</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Paper]]></category>
		<category><![CDATA[exploiting]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[SQLi]]></category>
		<category><![CDATA[writing file]]></category>

		<guid isPermaLink="false">http://lab.lonerunners.net/?p=17</guid>
		<description><![CDATA[photo credit: Paul Worthington Table of Contents 1. Introduction 2. Default configuration 3. COPY Function 3.1 COPY function abusing 4. BLOB functions 4.1 BLOB functions abusing 5. User defined functions 5.1 User defined functions abusing 6. Conclusions 7. References 1. Introduction The following examples assume access to the database has been achieved through SQL Injection [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img src="http://farm1.static.flickr.com/38/82648702_800bccf11e.jpg" border="0" alt="Pencils and Moleskines 04" /></p>
<h2 style="text-align: right;"><small><a title="Attribution License" href="http://creativecommons.org/licenses/by/2.0/" target="_blank"><img src="http://lab.lonerunners.net/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a title="Paul Worthington" href="http://www.flickr.com/photos/33586091@N00/82648702/" target="_blank">Paul Worthington</a></small></h2>
<h2>Table of Contents</h2>
<p>1. Introduction<br />
2. Default configuration<br />
3. COPY Function<br />
3.1 COPY function abusing<br />
4.  BLOB functions<br />
4.1 BLOB functions abusing<br />
5. User defined functions<br />
5.1 User defined functions abusing<br />
6. Conclusions<br />
7. References</p>
<h2>1. Introduction</h2>
<p>The following examples assume access to the database has been achieved through SQL Injection vulnerability in a web application.</p>
<p>Sometimes, against best practice, the application has connected to the database using superuser credentials.</p>
<h2>2. Default configuration</h2>
<p>In some systems the configuration files of PostgreSQL are owned by the user used to run the PostgreSQL process.</p>
<p>For example in my Ubuntu laptop the PostgreSQL configuration file are owned by postgres by default, as you can see:</p>
<pre>$ ls -al /etc/postgresql/8.3/main/
total 44
drwxr-xr-x 2 root     root      4096 2008-05-14 00:20 .
drwxr-xr-x 3 root     root      4096 2008-04-12 15:19 ..
-rw-r--r-- 1 root     root       316 2008-04-12 15:20 environment
-rw-r----- 1 postgres postgres  3845 2008-05-13 23:07 pg_hba.conf
-rw-r----- 1 postgres postgres  1460 2008-04-12 15:20 pg_ident.conf
-rw-r--r-- 1 postgres postgres 16682 2008-04-12 15:20 postgresql.conf
-rw-r--r-- 1 root     root       378 2008-04-12 15:20 start.conf</pre>
<p>All the configuration files are owned by postgres user which can write these.</p>
<p>So anyone that can execute a SQL statement that write files to disk can try to overwrite a configuration file and do all evil things.</p>
<h2>3. COPY Function</h2>
<p>The COPY statement transfers data between PostgreSQL tables and standard file system files.</p>
<p>COPY TO statement copies the contents of a table to a file, while COPY FROM copies data from a file to a table (appending the data to whatever is in the table already).</p>
<p>It can export data as text or PostgreSQL&#8217;s own binary format, which contains a header.</p>
<p>Using COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the server. When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.</p>
<p>In PostgreSQL 8.0 and later the database file locations can be determined querying system table pg_settings:</p>
<pre>postgres=# SELECT setting FROM pg_settings WHERE name='data_directory';
setting
------------------------------
/var/lib/postgresql/8.3/main
(1 row)</pre>
<h2>3.1 COPY function abusing</h2>
<p>The files are accessed under the operating system user privilege that the database runs as and it&#8217;s available only to database superusers.</p>
<p>The COPY command does not accept relative paths to prevent the overwriting of a database file, more explanation of this can be found in copy.c source file.</p>
<p>So an attacker can use ~ to write in PostgreSQL home directory and must write files in already known path or a well known directory like /tmp.</p>
<p>The caveat is that the file cannot contain a null byte (0&#215;00) otherwise proceeding bytes will not be written out.</p>
<h2>4.  BLOB functions</h2>
<p>PostgreSQL uses large objects, also called Binary Large Objects, to store very large values and binary data. Large objects permit storage of any operating system file, including images or large text files, directly into the database.</p>
<p>It has provided support for BLOB, also called Large Objects, since version 4.2. From version 7.2 organized the three large object interfaces such that all large objects are now placed in the system table pg_largeobject.</p>
<p>According to the Database Data Type Comparison Sheet[3] there are two data types used by PostgreSQL to store BLOB:</p>
<p>• BYTEA: used to store small amount of binary data that are stored in the data table</p>
<p>• OID: used to store very large amount of binary data in form of file in the filesystem</p>
<h2>4.1 BLOB functions abusing</h2>
<p>The file is loaded into the database using lo_import(), and is retrieved from the database using lo_export(). These functions take a path as argument that is the path of file to load or the path where export the data in the BLOB field.</p>
<p>In detail[2] to export a large object into an operating system file, call the lo_export() function, with argument that specifies the operating system name of the file.</p>
<p>Note that the file is written by the client interface library, not by the server. Returns 1 on success, -1 on failure.</p>
<p>Reading PostgreSQL documentation in the BLOB section[1] there is the following:</p>
<pre>Files are imported and exported by the postgres user, so postgres must have
permission to read the file for lo_import() and directory write permission for
lo_export().</pre>
<p>So this function can write a file to disk and abusing it we can overwrite the PostgreSQL configuration files.</p>
<p>First of all we need to create a temporary table (if your user have right permissions) to store our evil data:</p>
<pre>postgres=# CREATE TABLE foo (
postgres(# bar oid,
postgres(# id int4,
postgres(# CONSTRAINT id PRIMARY KEY (id) ) WITHOUT OIDS;
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "id" for table "foo"
CREATE TABLE</pre>
<p>The easiest way to load a file is using lo_import() that imports a file from the local file system but if you want to use this you must have a way to store a file on target system.</p>
<pre>postgres=# INSERT INTO foo VALUES (lo_import('/tmp/bar.bin'), 1);
INSERT 0 1</pre>
<p>Now you can try to abuse of lo_export() to overwrite a PostgreSQL configuration file.</p>
<p>If the web application connects to PostgreSQL using a user with superuser permission you can overwrite any configuration file owned by postgres, here we overwrite pg_hba.conf:</p>
<pre>postgres=# SELECT lo_export(bar, '/etc/postgresql/8.3/main/pg_hba.conf') FROM
postgres+# foo WHERE id=1;
lo_export
-----------
1
(1 row)</pre>
<p>If the web application runs as a non-superuser user you can get the following error message:</p>
<pre>Query failed: ERROR: must be superuser to use server-side lo_export() HINT:
Anyone can use the client-side lo_export() provided by libpq.</pre>
<p>If you are exploiting a SQL injection you can&#8217;t use lo_import() because it needs to write files in the local system the pg_largeobject table can be queried and updated directly, it&#8217;s &#8220;data&#8221; column is the equivalent to the BLOB data type found in other DBMS and is of type BYTEA.</p>
<p>Remember that when writing BYTEA data all non printable characters must be represented in octal syntax like 00 and the \ must be escaped if you use it inside a string.</p>
<p>For example 00 becomes 0 inside a string.</p>
<p>A trick is to transfer data encoded in hex or base64 and then decode it in the database, but remember that this cause an overhead, for example of 34% of the file size using base64.</p>
<p>Using direct access to pg_largeobject we can transfer an arbitrary file and then exporting it via lo_export().</p>
<p>First of all you must create a new entry in pg_largeobject.</p>
<pre>postgres=# SELECT lo_create(-1);
lo_create
----------
24586
(1 row)</pre>
<p>And now load your file encoded in base64 (also hex encoding can be used).</p>
<pre>postgres=# UPDATE pg_largeobject SET data = (DECODE('YW50YW5p', 'base64'))
postgres+# WHERE LOID = 24586;
UPDATE 1</pre>
<p>Your file is loaded in the target DBMS, now you can write it to disk using lo_export().</p>
<pre>postgres=# SELECT lo_export(24586, '/etc/postgresql/8.3/main/pg_hba.conf');
lo_export
-----------
1
(1 row)</pre>
<h2>5. User defined functions</h2>
<p>The PostgreSQL functionalities can be extended user-defined functions, data types, triggers, etc[6] written in C or other languages.</p>
<p>By default only superuser can create new functions using language C.</p>
<h2>5.1 User defined functions abusing</h2>
<p>Using a user-defined function is possible to define function to open, create and write files.</p>
<p>The code is not too short and described by Nico Leidecker[5] and also is the author of pgshell[7], a tool to automatize the exploitation process.</p>
<h2>6. Conclusions</h2>
<p>Exploiting a SQL injection to write files in to the attacked system disk can be done in three ways but as you can see in the following comparison table you can do it only if the database user is a superuser.</p>
<pre>+-------------------------------+-------------+------+
|                               | Super user  | User |
+-------------------------------+-------------+------+
+-------------------------------+-------------+------+
|    Write files with COPY      |    YES      |  NO  |
+-------------------------------+-------------+------+
| Write files with lo_export()  |    YES      |  NO  |
+-------------------------------+-------------+------+
|   Write file via extension    |    YES      |  NO  |
+-------------------------------+-------------+------+</pre>
<p>So in the case we aren&#8217;t superuser a privilege escalation vulnerability can be user to upload files.<br />
If you achieve the capability to upload files you can overwrite the PostgreSQL configuration files.</p>
<p><strong>7. References</strong></p>
<p>[1] <a href="http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html">http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html</a><br />
[2] <a href="http://www.postgresql.org/docs/8.3/interactive/lo-interfaces.html">http://www.postgresql.org/docs/8.3/interactive/lo-interfaces.html</a><br />
[3] <a href="http://www.lonerunners.net/1246-database-datatype-comparison-sheet.html">http://www.lonerunners.net/1246-database-datatype-comparison-sheet.html</a><br />
[4] <a href="http://www.postgresql.org/docs/8.1/interactive/sql-copy.html">http://www.postgresql.org/docs/8.1/interactive/sql-copy.html</a><br />
[5] <a href="http://labs.portcullis.co.uk/download/Having_Fun_With_PostgreSQL.pdf">http://labs.portcullis.co.uk/download/Having_Fun_With_PostgreSQL.pdf</a><br />
[6] <a href="http://www.postgresql.org/docs/8.3/interactive/server-programming.html">http://www.postgresql.org/docs/8.3/interactive/server-programming.html</a><br />
[7] <a href="http://www.leidecker.info/projects/pgshell.shtml">http://www.leidecker.info/projects/pgshell.shtml</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lab.lonerunners.net/blog/sqli-writing-files-to-disk-under-postgresql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evolution</title>
		<link>http://lab.lonerunners.net/blog/evolution</link>
		<comments>http://lab.lonerunners.net/blog/evolution#comments</comments>
		<pubDate>Sun, 02 Nov 2008 15:12:33 +0000</pubDate>
		<dc:creator>jekil</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[lonerunners.net]]></category>

		<guid isPermaLink="false">http://lab.lonerunners.net/?p=11</guid>
		<description><![CDATA[photo credit: nattu lonerunners.net is a blog composed by all kind of my crap, cinema, personal facts, technology news and IT security posts, some in italian and others in english. Now all research and information security posts are published here, in english, lab.lonerunners.net wanna be a place for IT security  pills,  hacking drugs, and reserch [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: right;"><a title="It takes a long time to grow young." href="http://www.flickr.com/photos/33345813@N00/1115248583/" target="_blank"><img class="aligncenter" src="http://farm2.static.flickr.com/1192/1115248583_eb1bfd3eb8.jpg" border="0" alt="It takes a long time to grow young." /></a><br />
<a title="Attribution License" href="http://creativecommons.org/licenses/by/2.0/" target="_blank"><img src="http://lab.lonerunners.net/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a title="nattu" href="http://www.flickr.com/photos/33345813@N00/1115248583/" target="_blank">nattu</a><a title="James Jordan" href="http://www.flickr.com/photos/69826987@N00/814863362/" target="_blank"></a></p>
<p><a href="http://www.lonerunners.net">lonerunners.net</a> is a blog composed by all kind of my crap, cinema, personal facts, technology news and IT security posts, some in italian and others in english.</p>
<p>Now all research and information security posts are published here, in english, <a href="http://lab.lonerunners.net">lab.lonerunners.net</a> wanna be a place for IT security  pills,  hacking drugs, and reserch news.</p>
<p>So <a href="http://lab.lonerunners.net/feed">subscibe</a> to our <a href="http://lab.lonerunners.net/feed">RSS feed</a> to keep updated about cutting edge security pills.</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.lonerunners.net/blog/evolution/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
