From e3e5a28894e16d92b70a74a3761cd32fee2da73b Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 13 Jan 2005 15:26:55 +0000 Subject: [PATCH] * lmt.lv captcha cracker. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@459 92316355-f0b4-4df1-b90c-862c8a59935f --- share/Makefile.am | 18 +++++ share/font_freesans_24_09AZ.bmp | Bin 0 -> 33078 bytes src/Makefile.am | 1 + src/lmt.c | 127 ++++++++++++++++++++++++++++++++ src/main.c | 7 ++ 5 files changed, 153 insertions(+) create mode 100644 share/font_freesans_24_09AZ.bmp create mode 100644 src/lmt.c diff --git a/share/Makefile.am b/share/Makefile.am index 41c9824..a1da097 100644 --- a/share/Makefile.am +++ b/share/Makefile.am @@ -1,8 +1,26 @@ NULL = EXTRA_DIST = \ + font_authimage.png \ font_linuxfr.png \ font_phpbb.png \ font_slashdot.png \ font_vbulletin.png \ + font_freesans_24_09AZ.bmp \ + font_comic_24_az_messed.bmp \ + font_comic_32_az.bmp \ + font_freemonobold_24_az.bmp \ + font_freemonobold_32_az.bmp \ + font_freesans_24_09AZ.bmp \ + font_freesansbold_32_az.bmp \ + font_freesansbold_36_az_messed.bmp \ + font_stencil_23_AZ.bmp \ + font_stencil_24_AZ.bmp \ + x_font_comic_24_az_messed.bmp \ + x_font_comic_32_az.bmp \ + x_font_freemonobold_24_az.bmp \ + x_font_freemonobold_32_az.bmp \ + x_font_freesansbold_32_az.bmp \ + x_font_freesansbold_36_az_messed.bmp \ $(NULL) + diff --git a/share/font_freesans_24_09AZ.bmp b/share/font_freesans_24_09AZ.bmp new file mode 100644 index 0000000000000000000000000000000000000000..87d83baef1256ac6d0e2ac7684a07022d93ffb11 GIT binary patch literal 33078 zcmeHPcUV({R-Ha3=Cy?RA2U%sRlFJ92|=g%o7CWf9pdqz*6 zKBegBXnOMG2}MOk(c{OD>CvM{^zh+Bdhp-@-M@dIA|oT|-o1Nt_wHS~bLS34L`2Z- z+qWq^Je+Rbx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?xQ{6iBPF*c-$jQCIGQa^WZgKG@}EB?UApB7B)(mw`5%bA42Hw zwJF9Pd#J6@I#IoCFYK>&h`W+<^+9&cS&M8Gd4>-)rA#oiKm*wwbSb6jP-Fsk6(+kL zvquw4{i`ccBbOFfVv-l9mYj!4F^0l@uV{yeB{bcYf*!fr5BJ?Oudl(tV zl*)F?%+1VU7mj%=BH=0wdnO|tVN1zT*jUb?2sslJ+g50!s={k*v2->{=9f3)Etc^; zix?}|CdHtiPn_H~)_Cd@Aj^l0^DAT&AEve=WmWVlfjvs+GAd`+r3cO&TH3`hn~u4^rNH^3V?q(yZX#W91)AfsZV;zQ1ay;K2_!CN4Ec|1+OtREf#p_!vs#^%utXR=v(Y9Y)##jbu?Y6Rn zXs~IiOOVTW%jcSipU@)?My=A!O$(S7FfCwOz_fsA0n-Ae1xyQ=7BDSfTEMh`X#vv$ mrUgt3m=-WCU|PVmfN25K0;UB_3z!x#Enr%}w7~yU3;YL#wB3mS literal 0 HcmV?d00001 diff --git a/src/Makefile.am b/src/Makefile.am index bd4edc0..6596534 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,6 +10,7 @@ pwntcha_SOURCES = \ authimage.c \ clubic.c \ linuxfr.c \ + lmt.c \ paypal.c \ phpbb.c \ scode.c \ diff --git a/src/lmt.c b/src/lmt.c new file mode 100644 index 0000000..7aea16a --- /dev/null +++ b/src/lmt.c @@ -0,0 +1,127 @@ +/* + * lmt.c: decode lmt.lv captchas + * $Id$ + * + * Copyright: (c) 2005 Sam Hocevar + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Do What The Fuck You Want To + * Public License as published by Banlu Kemiyatorn. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#include +#include +#include +#include + +#include "config.h" +#include "common.h" + +static void find_glyphs(struct image *img); + +/* Our macros */ +char *result; + +/* Main function */ +char *decode_lmt(struct image *img) +{ + struct image *tmp; + + /* lmt captchas have 3 characters */ + result = malloc(4 * sizeof(char)); + strcpy(result, " "); + + tmp = image_dup(img); + filter_contrast(tmp); + filter_black_stuff(tmp); + find_glyphs(tmp); + + image_free(tmp); + + return result; +} + +static void find_glyphs(struct image *img) +{ +#define DELTA 2 + static struct font *font; + int x, y, i = 0; + int r, g, b; + int xmin, xmax, ymin, ymax, startx = 0, cur = 0; + int bestdist, bestx, besty, bestch; + + if(!font) + { + font = font_load_variable("font_freesans_24_09AZ.bmp", + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + if(!font) + exit(1); + } + + while(cur < 3) + { + /* Try to find 1st letter */ + bestdist = INT_MAX; + for(i = 0; i < font->size; i++) + { + int localmin = INT_MAX, localx, localy; + xmin = font->glyphs[i].xmin - DELTA; + ymin = font->glyphs[i].ymin; + xmax = font->glyphs[i].xmax + DELTA; + ymax = font->glyphs[i].ymax; + for(y = -5; y < 5; y++) + { + for(x = startx; x < startx + 15; x++) + { + int z, t, dist; + dist = 0; + for(t = 0; t < ymax - ymin; t++) + for(z = 0; z < xmax - xmin; z++) + { + int r2; + getgray(font->img, xmin + z, ymin + t, &r); + getgray(img, x + z, y + t, &r2); + dist += (r - r2) * (r - r2); + } + dist = dist / (xmax - xmin - 2 * DELTA); + if(dist < localmin) + { + localmin = dist; + localx = x; + localy = y; + } + } + } + if(localmin < bestdist) + { + bestdist = localmin; + bestx = localx; + besty = localy; + bestch = i; + } + } + + /* Print min glyph */ +#if 0 + xmin = font->glyphs[bestch].xmin - DELTA; + ymin = font->glyphs[bestch].ymin; + xmax = font->glyphs[bestch].xmax + DELTA; + ymax = font->glyphs[bestch].ymax; + for(y = 0; y < ymax - ymin; y++) + for(x = 0; x < xmax - xmin; x++) + { + getpixel(font->img, xmin + x, ymin + y, &r, &g, &b); + if(r > 128) + { + getpixel(img, bestx + x, besty + y, &r, &g, &b); + r = 255; + } + setpixel(img, bestx + x, besty + y, r, g, b); + } +#endif + + startx = bestx + font->glyphs[bestch].xmax - font->glyphs[bestch].xmin; + result[cur++] = font->glyphs[bestch].c; + } +} + diff --git a/src/main.c b/src/main.c index 684ec75..30035e6 100644 --- a/src/main.c +++ b/src/main.c @@ -138,6 +138,8 @@ int main(int argc, char *argv[]) result = decode_clubic(img); else if(!strcmp(mode, "linuxfr")) result = decode_linuxfr(img); + else if(!strcmp(mode, "lmt")) + result = decode_lmt(img); else if(!strcmp(mode, "paypal")) result = decode_paypal(img); else if(!strcmp(mode, "phpbb")) @@ -162,6 +164,11 @@ int main(int argc, char *argv[]) dprintf("autodetected linuxfr captcha\n"); result = decode_linuxfr(img); } + else if(img->width == 69 && img->height == 35) + { + dprintf("autodetected lmt.lv captcha\n"); + result = decode_lmt(img); + } else if(img->width == 208 && img->height == 26) { dprintf("autodetected Paypal captcha\n");