<?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>Bonsai - Information Security Blog &#187; hacking</title>
	<atom:link href="http://www.bonsai-sec.com/blog/index.php/tag/hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bonsai-sec.com/blog</link>
	<description>Information security news from the small tree</description>
	<lastBuildDate>Tue, 12 Jul 2011 00:39:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Breaking Weak CAPTCHA in 26 Lines of Code</title>
		<link>http://www.bonsai-sec.com/blog/index.php/breaking-weak-captcha-in-26-lines-of-code/</link>
		<comments>http://www.bonsai-sec.com/blog/index.php/breaking-weak-captcha-in-26-lines-of-code/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 14:30:23 +0000</pubDate>
		<dc:creator>andres.riancho</dc:creator>
				<category><![CDATA[bonsai]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[breaking]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Web Application Security]]></category>

		<guid isPermaLink="false">http://www.bonsai-sec.com/blog/?p=258</guid>
		<description><![CDATA[During one of our latest engagements we found a weak CAPTCHA implementation being used in the target Web application. The assessment was being performed on-site, and after identifying this vulnerability we started to talk with the CSO about how easy it would be to break it.

The general consensus of course was &#8220;very easy&#8221;. The problem [...]]]></description>
			<content:encoded><![CDATA[<p>During one of our latest engagements we found a <em><strong>weak CAPTCHA implementation</strong></em> being used in the target Web application. The assessment was being performed on-site, and after identifying this vulnerability we started to talk with the CSO about how easy it would be to break it.</p>
<p><img class="size-full wp-image-268 alignleft" title="jxt9" src="http://www.bonsai-sec.com/blog/wp-content/uploads/jxt9.gif" alt="jxt9" width="58" height="28" /><img class="size-full wp-image-267 alignleft" title="e4ya" src="http://www.bonsai-sec.com/blog/wp-content/uploads/e4ya.gif" alt="e4ya" width="58" height="28" /><img class="size-full wp-image-266 alignleft" title="9ko0" src="http://www.bonsai-sec.com/blog/wp-content/uploads/9ko03.gif" alt="9ko0" width="58" height="28" /></p>
<p>The general consensus of course was <strong><em>&#8220;very easy&#8221;</em></strong>. The problem was that we were unable to find any good CAPTCHA breaking software that average joe could download and run on his computer; so I spent some minutes creating a simple Python script that  returns the CAPTCHA solution for this particular implementation.</p>
<p>Before we dig into the script, lets analyze why this CAPTCHA is weak (might not be obvious for some readers):</p>
<ol>
<li>The letters are not rotated</li>
<li>All letters have the same height</li>
<li>All letters have the exact same color</li>
<li>The letters are not deformed in any way</li>
<li>The background noise color is the same for the whole image</li>
</ol>
<p>Now, lets see the code that breaks this CAPTCHA:</p>
<pre class="brush:python">from PIL import Image

img = Image.open('input.gif')
img = img.convert("RGBA")

pixdata = img.load()

# Clean the background noise, if color != black, then set to white.
for y in xrange(img.size[1]):
    for x in xrange(img.size[0]):
        if pixdata[x, y] != (0, 0, 0, 255):
            pixdata[x, y] = (255, 255, 255, 255)

img.save("input-black.gif", "GIF")

#   Make the image bigger (needed for OCR)
im_orig = Image.open('input-black.gif')
big = im_orig.resize((116, 56), Image.NEAREST)

ext = ".tif"
big.save("input-NEAREST" + ext)

#   Perform OCR using pytesser library
from pytesser import *
image = Image.open('input-NEAREST.tif')
print image_to_string(image)</pre>
<p>This simple script works with ~ 90% of the CAPTCHA images created using this specific implementation. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonsai-sec.com/blog/index.php/breaking-weak-captcha-in-26-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>77</slash:comments>
		</item>
	</channel>
</rss>

