User Contributed - Captcha Breaking W/ PHPBB2 Example
This is a fantastic guest post by Harry over at DarkSEO Programming. His blog has some AWESOME code examples and tutorials along with an even deeper explanation of this post so definitely check it out and subscribe so he’ll continue blogging.
This post is a practical explanation of how to crack phpBB2 easily. You need to know some basic programming but 90% of the code is written for you in free software.
Programs you Need
C++/Visual C++ express edition - On Linux everything should compile simply. On windows everything should compile simply, but it doesn’t always (normally?). Anyway the best tool I found to compile on windows is Visual C++ express edition. Download
GOCR - this program takes care of the character recognition. Also splits the characters up for us
. It’s pretty easy to do that manually but hey. Download
ImageMagick - this comes with Linux. ImageMagick lets us edit images very easily from C++, php etc. Install this with the development headers and libraries. Download from here
A (modified) phpbb2 install - phpBB2 will lock you out after a number of registration attempts so we need to change a line in it for testing purposes. After you have it all working you should have a good success rate and it will be unlikely to lock you out. Find this section of code: (it’s in includes/usercp_register.php)
if ($row = $db->sql_fetchrow($result))
{
if ($row['attempts'] > 3)
{
message_die(GENERAL_MESSAGE, $lang['Too_many_registers']);
}
}
$db->sql_freeresult($result);
Make it this: if ($row = $db->sql_fetchrow($result))
{
//if ($row[’attempts’] > 3)
//{
// message_die(GENERAL_MESSAGE, $lang[’Too_many_registers’]);
//}
}
$db->sql_freeresult($result);
Possibly a version of php and maybe apache web server on your desktop PC. I used php to automate the downloading of the captcha because it’s very good at interpreting strings and downloading static web pages.
Getting C++ Working First
The problem on windows is there is a vast number of C++ compilers, and they all need setting up differently. However I wrote the programs in C++ because it seemed the easiest language to quickly edit images with ImageMagick. I wanted to use ImageMagick because it allows us to apply a lot of effects to the image if we need to remove different types of backgrounds from the captcha.
Once you’ve installed Visual C++ 2008 express (not C#, I honestly don’t know if C# will work) you need to create a Win32 Application. In the project properties set the include path to something like (depending on your imagemagick installation) C:\Program Files\ImageMagick-6.3.7-Q16\include and the library path to C:\Program Files\ImageMagick-6.3.7-Q16\lib. Then add these to your additional library dependencies CORE_RL_magick_.lib CORE_RL_Magick++_.lib CORE_RL_wand_.lib. You can now begin typing the programs below.
If that all sounds complicated don’t worry about it. This post covers the theory of cracking phpBB2 as well. I just try to include as much code as possible so that you can see it in action. As long as you understand the theory you can code this in php, perl, C or any other language. I’ve compiled a working program at the bottom of this post so you don’t need to get it all working straight away to play with things.
Getting started
Ok this is a phpBB2 captcha:
It won’t immediately be interpreted by GOCR because GOCR can’t work out where the letters start and end. Here’s the weakness though. The background is lighter than the text so we can exclude it by getting rid of the lighter colors. With ImageMagick we can do this in a few lines of C++. Type the program below and compile/run it and it will remove the background. I’ll explain it below.
using namespace Magick;
int main( int /*argc*/, char ** argv)
{
// Initialize ImageMagick install location for Windows
InitializeMagick(*argv);
// load in the unedited image
Image phpBB("test.png");
// remove noise
phpBB.threshold(34000);
// save image
phpBB.write("convert.pnm");
return(1);
}
All this does is loads in the image, and then calls the function threshold attached to the image. Threshold filters out any pixels below a certain darkness. On linux you have to save the image as a .png however on windows GOCR will only read .pnm files so on linux we have to put the line instead:
// save image
phpBB.write("convert.png");

The background removed.
Ok that’s one part sorted. Problem 2. We now have another image that GOCR won’t be able to tell where letters start and end. It’s too grainy. What we notice though is that each unjoined dot in a letter that is surrounded by dots 3 pixels away should probably be connected together. So I add a piece of code onto the above program that looks 3 pixels to the right and 3 pixels below. If it finds any black dots it fills in the gaps. We now have chunky letters. GOCR can now identify where each letter starts and ends
. We’re pretty much nearly done.
using namespace Magick;
void fill_holes(PixelPacket * pixels, int cur_pixel, int size_x, int size_y)
{
int max_pixel, found;
///////////// pixels to right /////////////////////
found = 0;
max_pixel = cur_pixel+3; // the furthest we want to search
// set a limit so that we can't go over the end of the picture and crash
if(max_pixel>=size_x*size_y)
max_pixel = size_x*size_y-1;
// first of all are we a black pixel, no point if we are not
if(*(pixels+cur_pixel)==Color("black"))
{
// start searching from the right backwards
for(int index=max_pixel; index>cur_pixel; index--)
{
// should we be coloring?
if(found)
*(pixels+index)=Color("black");
if(*(pixels+index)==Color("black"))
found=1;
}
}
///////////// pixels to bottom /////////////////////
found = 0;
max_pixel = cur_pixel+(size_x*3);
if(max_pixel>=size_x*size_y)
max_pixel = size_x*size_y-1;
if(*(pixels+cur_pixel)==Color("black"))
{
for(int index=max_pixel; index>cur_pixel; index-=size_x)
{
// should we be coloring?
if(found)
*(pixels+index)=Color("black");
if(*(pixels+index)==Color("black"))
found=1;
}
}
}
int main( int /*argc*/, char ** argv)
{
// Initialize ImageMagick install location for Windows
InitializeMagick(*argv);
// load in the unedited image
Image phpBB("test.png");
// remove noise
phpBB.threshold(34000);
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Beef up "holey" parts
/////////////////////////////////////////////////////////////////////////////////////////////////////
phpBB.modifyImage(); // Ensure that there is only one reference to
// underlying image; if this is not done, then the
// image pixels *may* remain unmodified. [???]
Pixels my_pixel_cache(phpBB); // allocate an image pixel cache associated with my_image
PixelPacket* pixels; // 'pixels' is a pointer to a PixelPacket array
// define the view area that will be accessed via the image pixel cache
// literally below we are selecting the entire picture
int start_x = 0;
int start_y = 0;
int size_x = phpBB.columns();
int size_y = phpBB.rows();
// return a pointer to the pixels of the defined pixel cache
pixels = my_pixel_cache.get(start_x, start_y, size_x, size_y);
// go through each pixel and if it is black and has black neighbors fill in the gaps
// this calls the function fill_holes from above
for(int index=0; index
// now that the operations on my_pixel_cache have been finalized
// ensure that the pixel cache is transferred back to my_image
my_pixel_cache.sync();
// save image
phpBB.write("convert.pnm");
return(1);
}
I admit this looks complicated on first view. However you definitely don’t have to do this in C++ though if you can find an easier way to perform the same task. All it does is remove the background and join close dots together.
I’ve given the C++ source code because that’s what was easier for me, however the syntax can be quite confusing if you’re new to C++. Especially the code that accesses blocks of memory to edit the pixels. This is more a study of how to crack the captcha, but in case you want to code it in another language here’s the general idea of the algorithm that fills in the holes in the letters:
1. Go through each pixel in the picture. Remember where we are in a variable called cur_pixel
2. Start three pixels to the right of cur_pixel. If it’s black color the pixels between this position and cur_pixel black.
3. Work backwards one by one until we reach cur_pixel again. If any pixels we land on are black then color the space in between them and cur_pixel black.
4. Go back to step 1 until we’ve been through every pixel in the picture
NOTE: Just make sure you don’t let any variables go over the edge of the image otherwise you might crash your program.
I used the same algorithm but modified it slightly so that it also looked 3 pixels below, however the steps were exactly the same.
Training GOCR
The font we’re left with is not recognized natively by GOCR so we have to train it. It’s not recognized partly because it’s a bit jagged.

Assuming our cleaned up picture is called convert.pnm and our training data is going to be stored in a directory call data/ we’d type this.
gocr -p ./data/ -m 256 -m 130 convert.pnm
Just make sure the directory data/ exists (and is empty). I should point out that you need to open up a command prompt to do this from. It doesn’t have nice windows. Which is good because it makes it easier to integrate into php at a later date.
Any letters it doesn’t recognize it will ask you what they are. Just make sure you type the right answer. -m 256 means use a user defined database for character recognition. -m 130 means learn new letters.
You can find my data/ directory in the zip at the end of this post. It just saves you the time of going through checking each letter and makes it all work instantly.
Speeding it up
Downloading, converting, and training for each phpbb2 captcha takes a little while. It can be sped up with a simple bit of php code but I don’t want to make this post much longer. You’ll find my script at the end in my code package. The php code runs from the command prompt though by typing “php filename.php”. It’s sort of conceptual in the sense that it works, but it’s not perfect.
Done
Ok once GOCR starts getting 90% of the letters right we can reduce the required accuracy so that it guesses the letters it doesn’t know.
Below I’ve reduced the accuracy requirement to 25% using -a 25. Otherwise GOCR prints the default underscore character even for slightly different looking characters that have already been entered. -m 2 means don’t use the default letter database. I probably could have used this earlier but didn’t. Ah well, it doesn’t do a whole lot.
gocr -p ./data/ -m 256 -m 2 -a 25 convert.pnm
We can get the output of gocr in php using:
echo exec(”/full/path/gocr -p ./data/ -m 256 -m 2 -a 25 convert.pnm”);
Alternatives
In some instances you may not have access to GOCR or you don’t want to use it. Although it should be usable if you have access to a dedicated server. In this case I would separate the letters out manually and resize them all to the same size. I would then put them through a php neural network which can be downloaded from here FANN download
It would take a bit of work but it should hopefully be as good as using GOCR. I don’t know how well each one reacts to letters which are rotated though. Neural networks simply memorize patterns. I haven’t checked the inner workings of GOCR. It looks complicated.
My code
All the code can be found here to crack phpBB2 captcha.
In conclusion to this tutorial it’s a nightmare trying to port over all my code from linux to windows unless it’s written in Java
. If only Java was small and quick as well.
It’s worth stating that phpbb2 was easy to crack because the letters didn’t touch or overlap. If they had touched or overlapped it would probably have been very hard to crack.
I plan to look at that line and square captcha that comes with phpBB3 over on my site and document how secure it is.
Thanks for the awesome guest post Harry.
gmail captchas have been broken by spammers,
heise.de reports. They have detection rates of 20-30%!
How do they archive that?
Nice Post
yep nice. thx for the guest post.
best regards
Hi, I was working on GOCR and Java but I never finish my project, I’m new in Java and C++.
You said your program is writen in Java, could you please show source code ? Here, mail, anything …
If don’t want to, or you can’t, can you at least explain how you process image with GOCR from your program ?
How you call/use GOCR from Java ?
It was only a matter of time till someone made the captcha child’s play. Great tutorial. I will begin working on this to create a perl version of it and see if we can crack more captcha systems.
really nice post, great information. cheers!
In Soviet Russia, Captcha Cracks You!!!!!
I am sure that more and more captchas will be broken soon. This one, gmail, heise.de - all are examples
Great guest article Eli & Harry,
Thanks for breaking down the basics of captcha busting. I’m fluent in photoshop and could easily see how one could use actions to automate the process of removing the background and sharpening up the letters, but to see this in code was just awesome.
Several months ago I wrote a script that does math captcha in an animated gif format. I didn’t pixelize the background or distort the letters as I wanted it to be the simpliest captcha to read.
Obviously, animated gif type captcha would be quite easy to break as long as GOCR can read frames and then process the letters/numbers in each picture. Is there anything (flash, avi, etc) that can be done to deter a programmer worth his weight in herb?
Thanks again for a kick ass article .. Eli, bring on SEOempire II
Nice work Harry, you guys take this stuff to another level. I take my (white) hat off to you !
It would be nice to have a repository of captcha cracking programs with source code and with description what they can do and which web sites captchas they can crack.
Do you know any such software repository?
this is another great piece of code. thanks!
Another informative post.
I don’t really know what to think about this. This is cool for those who spam blog comments (maybe some day I will do it too), but I’m getting frustrated if my blog comments are full of spam. On the other hand, capcha kinda sucks really bad… nah, I don’t care. Great post, whatever.
nice post, I do it with java and irfanview, gocr can block the whole program though (sometimes it blocks the bufferedreader of a thread and there’s no way to kill the thread). Doing it with php isn’t a great idea because you cannot do multithreading in php (too slow for me).
Hope someone will post a fully native java code
This is definitely the best CAPTCHA breaking post I’ve ever seen. I love that you went through and explained the logic behind each step, complete with pictures.
thanks for the great information…
Regarding your comment “if Java would be only…” - have a look at Groovy. It runs in the JVM (thus as a normal java application) and “feels” like PHP or other nice scripting languages.
And you get the power of the whole Java API, third party libraries and so on.
After all, thanks for your informative post!
Another informative post.
Fight it and make it more secure…
Very interesting post. Its too late right now but will go through it again.
I think the Blue has got a little darker in this Post
Hello guys! Its me, mario!
I just want to say that your site is amazing!
Good luck!
Yes, your site simply most сool. The kiss author gently gently
The rumour has it Google captcha has been cracked. Do you think this is true? It looked like Google had one of the strongest captchas around. They should have went for something logical though.
Live within your income, even if you have to borrow to do so.
– Josh Billings
—————————————————————————————————-
http://earnestschultzcm.easyjournal.com
Great Job! Dude, it’s awesome! Oh my god you are best captcha-cracker!
Hi everyone. My name is Ray, from Utica, NY. I will be visiting Poland soon, and I am hoping to meet my Polish relatives. I also hope some people from here may help me in contacting my relatives before my visit. Thanks and looking forward to meeting some great people on here!
Well, goodluck on your trip and wish you have a great time with your realtives.
Hey, I’ve been lurking here for a few months, and decided to create an account today. Just figured I’d drop in and say hi
Wow, this is sick. How dark is that blue hat of yours?
Hello,
I’m newer here and stopping in to say hi.
I hope everyone has a good day.
Jaeric
My boyfriend and I want to go on a spectuacular vacation soon. We were looking for advice. Anyone have any fantastic spots? A way to save some cash would be nice as well. Traveling is expensive these days.
As someone seriously concerned about this whole matter, I consider this post a sad commentary on our world.
Hope there would be less hackers in the world.
“Getting Super High Quality, One Way Links Has Never Been Easier! Submit Unlimited Articles To A Whopping 374 Article Directories!”
http://nesebar.bryxen7.hop.clickbank.net/
Harry you’re brilliant. Thanks so much for this captcha breaking tip.
Awesome post, thanks very much!
How its going?
New poster here!
Great site.
I am just now poking around and looking at everything.
I have to say i appreciate the opportunity to share and post feedback here.
Thanks, best of luck moving forward.
CanoSpinach
I would like to know as to which, according to you are the most difficult captchas to crack?
I’ve recently joined and wanted to introduce myself
well, the image example the code is based on is very easy to clean up
nice one
test
tnx for delete this post!
Nice article about captchas but some captchas are really difficult to crack..what you say about it?
________________
Naruto Ninja
Very well!!!
Awesome post, thanks very much !
Hi,
I think its a gread stuff.
Thanks for the good tutorial.
By,
Holger
It is the not-too-distant future. Thousands of satellites scan, observe and monitor our every move. Much of the planet is a war zone; the rest, a collection of wretched way stations, teeming megalopolises, and vast wastelands punctuated by areas left radioactive from nuclear meltdowns. It is a world made for hardened warriors, one of whom, a mercenary known only as Toorop, lives by a simple survivor’s code: kill or be killed. His latest assignment has him smuggling a young woman named Aurora from a convent in Kazakhstan to New York City. Toorop, his new young charge Aurora and Aurora’s guardian Sister Rebeka embark on a 6,000-mile journey that takes them from Eastern Europe, through a refugee camp in “New Russia,” across the Bering Straight in a pilfered submarine, then through the frozen tundra of Alaska and Canada, and finally to New York.
Good Day
Just wanted to share my new experience.
If your system denies to run due to an error corresponding to missing HAL.DLL, invalid Boot.ini or any other important system boot files you can repair this by using the XP installation CD. Just boot from your XP Setup CD and enter the Recovery Console. Then run “attrib -H -R -S” on the C:\Boot.ini file and remove it. Launch “Bootcfg /Rebuild” and then Fixboot
Cheers,
Carl
I began this thread to evaluate public usable web proxies:
Which are really anonymous?
Which can be used with facebook, myspace etc, in other words: are fresh ?
Which can you recommend?
Thanks for your help,
Dschibut
P.S.: In my country, the freedom of speech is somehow constrained, please give me a hint, if you are not sure about your recommendation.
Does anyone else think the Refer-a-Friend bonuses being given out are (in-part) a means to get low level players leveled up in time for WotLK? Get them into the fray, more addicted and increasing the longevity of their subscription?
Hi webmaster. Nice Work!
lol
I know this is a little off-topic but this video is truly relevant to anyone in the civilized world who has money, a home or any form of business.employment:
http://www.squidoo.com/keating-economics
How has this information not come to light before? I hope the media gives this the attention it deserves!
My boyfriend and I want to go on a awesome long vacation soon. We were looking for ideas. Anyone have any great locations? A way to save some money would be nice too. Traveling is expensive these days.
Hi Guys,
A long time lurker thought i would finally say Hi
sorry if this is the wrong section mods!
Hi!
I want to extend my SQL knowledge.
I red really many SQL resources and want to
read more about SQL for my occupation as oracle database manager.
What can you recommend?
Thanks,
Werutz
Hello
I hve been hearing lately about credit repairing companies ande the amount of work they get in their business . One of my sister is running a creditt repair business, I have talked to him about the business but. I need mor information on this so that I can start my own credit repair business .
Please do sugest your views on this!
Chudi
elcuidado deagual asian hardcore sex eltron p310
I have a question for you or anyone else who wants to address this: I know of several folks who have decided to stop contributing to their 401k’s and other retirement accounts and start putting that money towards paying down their mortgage. Right now I put $250/paycheck into my retirement fund, and yet my balance is less than it was six months ago. Is it smarter to just keep with the traditional wisdom of investing the same amount no matter how the market is going, or is a diversion into debt reduction a smart move? FYI I’m about 15 miles out from retirement.
What do you think?
www.moneyning.com
Laura Kauffmann
“Seven Oceans Investments Club”
I think you had a wonder knowledge in programming language. May be you can help me lot of people with your programs who are not familiar with this one… think it of again. Thanks for the post
Реально суперское место, мне тут понравилось, правда…
Столько всего суперского и позновательного, я тут задержусь на долго.
Test message
Sorry me noob…
This is a great piece of code.
There was this guy see.
He wasn’t very bright and he reached his adult life without ever having learned “the facts”.
Somehow, it gets to be his wedding day.
While he is walking down the isle, his father tugs his sleeve and says,
“Son, when you get to the hotel room…Call me”
Hours later he gets to the hotel room with his beautiful blushing bride and he calls his father,
“Dad, we are the hotel, what do I do?”
“O.K. Son, listen up, take off your clothes and get in the bed, then she should take off her clothes and get in the bed, if not help her. Then either way, ah, call me”
A few moments later…
“Dad we took off our clothes and we are in the bed, what do I do?”
O.K. Son, listen up. Move real close to her and she should move real close to you, and then… Ah, call me.”
A few moments later…
“DAD! WE TOOK OFF OUR CLOTHES, GOT IN THE BED AND MOVED REAL CLOSE, WHAT DO I DO???”
“O.K. Son, Listen up, this is the most important part. Stick the long part of your body into the place where she goes to the bathroom.”
A few moments later…
“Dad, I’ve got my foot in the toilet, what do I do?”
check out this all new online application , it lets you create your own online id……. http://digg.com/people/Announce_Yourself_Your_Personal_Web_ID
came across it yesterday and instantly became a fan of it……..
very easy to use and there is so much we can do with it……check it out yourself , its awesome…
A short prospectus on New York Institute of Technology, C.C.A., and D.S.U.
[b]Institute of Technology in New York[/b]
The NYIT is a exclusive coeducational institution of higher learning. Founded in the 1950’s, the college enrolls Over 9,000 students at its two campuses. The NYIT is accredited by the Middle States Association of Colleges and Schools. Specific program recognition include: National Architectural Accrediting Board, Foundation for Interior Design Education Research, American Culinary Federation Educational Institute, and a number of others. The institute offers applicant undergraduate and graduate academically-oriented programs leading to A.A.S, B.A., and M.S. degrees.
[b] California Arts College[/b]
Founded to promote liberal studies, the California College of the Arts (CCA) offers a procedural approach to collaborative education, enabling students in a broad range of majors in liberal arts, counseling, English, and Creative Writing.
With an college population of around 1,550, the institute provides leading edge systems and organizations in a close-knit, one-on-one institutional environment. Students learn from an established selection of focused practitioners in small lectures, with an mode of 16 per class. Staff assessors, educated in allowing puils in finding their university experience, are part of a highly respected first-semester program.
[b]Drake State University of Rockford, Illinois[/b]
Drake was started through the multitute of community outreach efforts. A diverse, collaborating focus is an important area of many degree programs at Drake State University. Founded to engage academic enrichment and advancement, central to the ideals of Drake is its one of a kind means to accommodate a great many of styles of study through credential evaluation, collaborative study and on-line organization. Throughout its network the student will find a learning area that is lively with world class technology, educational outreach and professional enrichment tools. DSU encourages the value of close-knit relationships which are often established amongst students and faculty. As a direct result, a great number of students deploy the perfect programs of study whch enables them to enable the mantra of a Drake diplome to propel them toward their professional goals.
DSU is operated by a notable committe of Directors, each of whom promotes a special field of expertise that can help guide the academic outlook and expanding of the college. In a often competitive work market, Drake State University has evolved to enable the success of a rapidly growing number of students and applicants across a number of disciplines. Its graduates have experienced subsequent accomplishment in the workforce, strengthening its reputation in industry and business.
I have a flash site
i’m looking for the script who of google ads on flash.
where can i get it?
This is a really excellent piece of code.
I was looking for a captcha of this style, it is very good ! Thank you
True,this is a really cool site. I agree with what you said.
This blog is excellent, im glad I checked out this blog
sextir.com is a free porn site - We provide the world with free: porn videos,porn movie,xxx free movie
Mike Mossberg, I know you reading this forum, please contact me, because I can’t find your contact details.
Hello Id Like to bid you this far-out liquidate !
How with injunction instructions to we try something a impecunious momentous this later ?
perchance something like this ?
http://www.mudglue3.com
To save your captcha from spammers just replace code
Problema ultimi driver nvidia?allora ho un portatiel acer travelmate 2490. e ho comprato il modem sitecom 54g turbo perche quelll delalice che avevo non aveva il wifi.
quando cerco di conneterlo mi dice stato connesso la velociota 54mgps
e i byte ricevuti e inviati ma quando cerco di conneterlo dice connesione a miniport wan fallita. il modem ha la luce del wi/fi lampeggia e di cloore arancione. quando provo a conneterlo con il cavo ethernet non mi si collega. quando lo collego con il modem del alice vado alla pagina che inizia con 192 e mi chiede la nick e la pas io mett admin come ce scritto nel manuale e non funzia.
10 punti al migliore
[img]http://www.chatt-gratis.net/javachat/immagini/roll-eyes.gif[/img]
Well said! You have excellent writing skills! Bookmarked!
Hi I’m a working for last 20 years as a Sales professional across various verticals like pharma, fmcg, construction & telecom.
Can somebody suggest some good company/website where I can get assistance for professional services in executive job search?
Thanks
thank you
sextir.com is a free porn site - We provide the world with free: porn videos,porn movies,xxx free movies,free porn,free sex.
Best porn hub and tube on the web
Haworth is a complete seating system for createing a cohesive look throughout workspaces, the line includes a mid-back task, high-back executive, sled-base guest and a seminar chair withnesting storage capability.
Good script and its fun