Check Mates


Check Mates22 Mar 2008 10:54 pm

Here ya go. This is the del.icio.us captcha busted in Python.
376623524.png


#!/usr/bin/python
import Image,time,random,glob,re,os,sys

##$$$$
train = raw_input("train? (y/n)")
if(train == "y") : train= True
else: train = False
##
fileName = ''.join(sys.argv[1:])
def getNeighbourhood(i,width,height,pixels):
	results = []
	try:
		if(pixels[i+1] != 0): results.append(i+1)
		if(pixels[i-1] != 0): results.append(i-1)
		if(pixels[i-width] != 0): results.append(i-width)
		if(pixels[i+width] != 0): results.append(i+width)
		if(pixels[i-width+1] != 0): results.append(i-width+1)
		if(pixels[i+width+1] != 0): results.append(i+width+1)
		if(pixels[i-width-1] != 0): results.append(i-width-1)
		if(pixels[i+width-1] != 0): results.append(i+width-1)
	except:pass
	return results
now = time.time()
captcha = Image.open(fileName)
(width,height) = captcha.size
pixels = list(captcha.getdata())
i=0
for pixel in pixels:
	if (pixel == 2): pixels[i] = 0
	i+=1
toclean = []
for i in xrange(len(pixels)):
	neighbourhood = getNeighbourhood(i,width,height,pixels)
	if (len(neighbourhood) < 4) : 	pixels[i] = 0

captcha.putdata(pixels)
started=False
lowestY,highestY,count = 0,10000,0
captchas = []
slant = 15
for x in xrange(width):
	hasBlack = False
	for y in xrange(height):
		thisPixel = captcha.getpixel((x,y))
		if(thisPixel != 0):
			if(started == False):
				started=True
				firstX = x
				firstY = y
			else:
				lastX = x
			if(y > lowestY): lowestY = y
			if(y< highestY): highestY = y
			hasBlack = True
	if((hasBlack == False) and (started==True)):
		if((lowestY - highestY) > 4):
			croppingBox = (firstX,highestY,lastX,lowestY)
			newCaptcha = captcha.crop(croppingBox)
			if(train):
				text = raw_input(”char:n”)
				try: os.mkdir(”/home/dbyte/deliciousImages/” + text)
				except:pass
				text__ = “/home/dbyte/deliciousImages/” + text + “/” + str(random.randint(1,100000)) + “-.png”
				newCaptcha.resize((20,30)).save(text__)
				text_ = “/home/dbyte/deliciousImages/” + text + “/” + str(random.randint(1,100000)) + “-.png”
				newCaptcha.resize((20,30)).rotate(slant).save(text_)
				text_ = “/home/dbyte/deliciousImages/” + text + “/” + str(random.randint(1,100000)) + “-.png”
				newCaptcha.resize((20,30)).rotate(360 - slant).save(text_)
				captchas.append(Image.open(text__))
			else:
				#text = str(count)
				#text = “tmp-delicious-” + text + “.png”
				#newCaptcha.save(text)
				captchas.append(newCaptcha.resize((20,30)))

			started=False
			lowestY,highestY = 0,10000
			count +=1
if(train == False):

	imageFolders = os.listdir(”/home/dbyte/deliciousImages/”)
	images =[]
	for imageFolder in imageFolders:
		imageFiles = glob.glob(”/home/dbyte/deliciousImages/” + imageFolder + “/*.png”)
		for imageFile in imageFiles:
			pixels = list(Image.open(imageFile).getdata())
			for i in xrange(len(pixels)):
				if pixels[i] != 0: pixels[i] = 1
			images.append((pixels,imageFolder))

	crackedString = “”
	for captcha in captchas:
		bestSum,bestChar = 0,”"
		captchaPixels = list(captcha.getdata())
		for i in xrange(len(captchaPixels)):
			if captchaPixels[i] != 0: captchaPixels[i] = 1
		for imageAll in images:
			thisSum = 0
			pixels = imageAll[0]
			for i in xrange(len(captchaPixels)):
				try:
					if(captchaPixels[i] == pixels[i]): thisSum+=1
				except: pass
			if(thisSum > bestSum):
				bestSum = thisSum
				bestChar = imageAll[1]
		crackedString += bestChar
	print crackedString
	#print “time taken: ” + str(time.time() - now)
Random Thoughts and Check Mates17 Mar 2008 11:03 pm

Guess what I’m in the mood to talk about? You guessed it. Captchas! In fact I feel like dedicating a whole week, maybe more depending on if any downtime occurs. :) to talking about nothing but captcha breaking. We’ll break every captcha in the book and even by the end of this post the captchas that haven’t been created yet. Furthermore, for this week only I am accepting any and all captcha related guest posts. So if you got a captcha solved or want to discuss techniques to breaking them feel free to write up a guest post and email it to ELI at BLUEHATSEO.COM in html form. You can stay anonymous and not only will I put it up but I’m also willing to put up any ad you’d like. Pick any text or banner ad you’d like to put up with your post and I’ll include it. With as many readers as this place has I’m sure it’ll get clicked. Also be sure to include your paypal address. If I really like your guest post I may even send you a $100 as a thank you. Also, all you bloggers are welcome to repost any of the captcha related posts on this blog. I now declare any captcha related posts on this blog public domain and republishable under full rights. For some odd reason I feel like blowing the captcha breaking industry the fuck up. Like my favorite saying goes, if you’re going to wreck a room you might as well WRECK it. Lets begin by visiting one of my first captcha related posts; the Army Of Captcha Typers.

The Army of Captcha Typers is a great technique because it doesn’t require loads of programming and is 100% adaptable to any captcha. I suggest you go back and reread it, but in interest of keeping this short here’s a quick summary.

You use a service, I used a proxy site as an example, to get the users to type in the captchas for you. It records what the user typed in as the solution to the captcha and you use that to solve it. The more pageviews the service provides per user the more effective it is to breaking captchas. Why pay Indians or tediously code it yourself?

Normally I like to leave most of the code and creative portion out of the written technique in interest of not ruining the technique and to help the methods be more effective through use of spins and unique code. I don’t write this blog to ruin techniques, and those people who claim I do are just insecure and like to claim they already know everything. As common sense as most of the stuff I post is, I haven’t met a person yet who hasn’t in some way learned something from this blog. That truth brags a lot louder than most SEO blogs I’ve seen. But! If we’re going to wreck something lets wreck it. In that spirit I see no reason why every newbie on the planet shouldn’t be able to easily throw up their own web proxy site that solves captchas for them so here’s the script to do it.

Captcha Solving Web Proxy

This a modified version of CGIPROXY that I mentioned in the post. Basically you install it following the included instructions (README file). Then you setup your web proxy site. Target a niche such as kids behind a school proxy or something similar. There is an extra file included called captcha.cgi. Upload it to the cgi-bin in the same folder as the nph-proxy.cgi and give it 755 chmod permissions. Make a folder one directory below your cgi-bin called captchas. Give it read/write permissions (777 should work all else fails). Then anytime you got a captcha to solve upload it to that directory with a unique filename. This can be done automatically with whatever script you’re using to spam a captcha protected site. On the very next pageview the webproxy will require the person to type in the captcha and disguise it as a human check to prevent abuse. Any captcha works. Once it gets their response it’ll delete the captcha from the folder and write out the solution along with the filename to a new file called solved.txt. Format: characters|image.jpg\n . Remember to make some kind of reminder or code for the filename so you know which image is which when you go to use the solutions. Get enough users to your webproxy (which is very easy) and you can solve any captcha in moments.

Enjoy!

Check Mates13 Apr 2007 07:05 pm

Perfectly Optimized Google Image Code
<td>Keyword<br>
<p><img s rc=”images/keyword.jpg” alt=”keyword” />
keyword</p>
</td>

Top Determined Factors
1) Keyword in same table cell as image.
2) Keyword below or above image in DIV or floating DIV.
3) Keyword in ALT tag.
4) Keyword in image name and image meta file summary.
5) Keyword in same paragraph as image.

Acceptable Code
<div style=”float:right”><img s rc=”image/keyword.jpg” /><br>keyword in more than 4 words and less than 10.</div>
<p>text blah blah</p>

Factors In Order Of Apparent Importance
1) Factors 2 and 5 equal
2) Factor 1
3) Factor 4
4) Factor 3
*Factor 3 assumed because it showed no distinguishable results in controlled tests.

Automatically Remove The Google Frame
<script language=”JavaScript1.1″ type=”text/JavaScript”>
if (parent.frames.length > 0) top.location.replace(document.location);</script>

Perfect Sizes
Small: 150×150 or smaller.
Medium: Larger than 150 x 150 and smaller than 500 x 500.
Large: 500 x 500 and larger.

Google Image Traffic Redirection
.HTACCESS File

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http:\/\/images\.google\. [NC]
RewriteRule .*\.$ cgi-bin/redirect.cgi [R,NC]
*If google images is sending you traffic you don’t want, you can use this code to redirect to a targeted advertiser. I have an affiliate site that sells lingerie. It gets tons of porn related traffic from Google images. They usually just realize it’s not a porn site and they quickly leave. So I looked at the most popular keywords used in Google Images traffic they send me and found a related porn sponsor and started redirecting all the users to my affiliate link. What do you know? Conversions!

*Check Mate*

Update: I didn’t even realize this, but there is a great write up by EMP over at Blind Ape SEO. Worth checking out.