Browse Source

* vbulletin captcha support.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@414 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 20 years ago
parent
commit
9a3687249d
6 changed files with 151 additions and 0 deletions
  1. +1
    -0
      Makefile.am
  2. BIN
      share/font_vbulletin.png
  3. +1
    -0
      src/Makefile.am
  4. +1
    -0
      src/common.h
  5. +7
    -0
      src/main.c
  6. +141
    -0
      src/vbulletin.c

+ 1
- 0
Makefile.am View File

@@ -8,6 +8,7 @@ EXTRA_DIST = \
ChangeLog \
share/font_slashdot.png \
share/font_phpbb.png \
share/font_vbulletin.png \
$(NULL)

AUTOMAKE_OPTIONS = dist-bzip2


BIN
share/font_vbulletin.png View File

Before After
Width: 323  |  Height: 30  |  Size: 777 B

+ 1
- 0
src/Makefile.am View File

@@ -11,6 +11,7 @@ pwntcha_SOURCES = \
phpbb.c \
scode.c \
slashdot.c \
vbulletin.c \
test.c

if USE_SDL


+ 1
- 0
src/common.h View File

@@ -24,6 +24,7 @@ void dprintf(const char *fmt, ...);
char *decode_phpbb(struct image *img);
char *decode_scode(struct image *img);
char *decode_slashdot(struct image *img);
char *decode_vbulletin(struct image *img);
char *decode_test(struct image *img);

/* image operations */


+ 7
- 0
src/main.c View File

@@ -130,6 +130,8 @@ int main(int argc, char *argv[])
result = decode_scode(img);
else if(!strcmp(mode, "slashdot"))
result = decode_slashdot(img);
else if(!strcmp(mode, "vbulletin"))
result = decode_vbulletin(img);
else
{
if(img->width == 320 && img->height == 50)
@@ -148,6 +150,11 @@ int main(int argc, char *argv[])
dprintf("autodetected slashdot captcha\n");
result = decode_slashdot(img);
}
else if(img->height == 61)
{
dprintf("autodetected vbulletin captcha\n");
result = decode_vbulletin(img);
}
else
{
dprintf("could not guess captcha type\n");


+ 141
- 0
src/vbulletin.c View File

@@ -0,0 +1,141 @@
/*
* vbulletin.c: decode vbulletin captchas
* $Id$
*
* Copyright: (c) 2005 Sam Hocevar <sam@zoy.org>
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#include "config.h"
#include "common.h"

#define FONTNAME "share/font_vbulletin.png"

/* Main function */
char *decode_vbulletin(struct image *img)
{
char all[] = "2346789ABCDEFGHJKLMNPRTWXYZ";
char *result;
struct image *tmp1, *tmp2, *tmp3, *font;
int limits[6] = { 26, 53, 80, 107, 134, 160 };
int x, y, r, g, b, i, j;

font = image_load(FONTNAME);
if(!font)
{
fprintf(stderr, "cannot load font %s\n", FONTNAME);
exit(-1);
}

/* vBulletin captchas have 6 characters */
result = malloc(7 * sizeof(char));
strcpy(result, " ");

/* half the captchas are inverse video; we set them back to normal */
getpixel(img, 0, 0, &r, &g, &b);
if(r < 50)
tmp1 = filter_equalize(img, 128);
else
tmp1 = filter_equalize(img, -128);

/* Remove garbage around the cells */
for(x = 0; x < img->width; x++)
{
for(y = 0; y < 15; y++)
setpixel(tmp1, x, y, 255, 255, 255);
for(y = 45; y < img->height; y++)
setpixel(tmp1, x, y, 255, 255, 255);
}

for(x = 0; x < img->width; x++)
{
for(i = 0; i < 6; i++)
if(x == limits[i])
break;
if(i == 6)
for(y = 15; y < 45; y++)
setpixel(tmp1, x, y, 255, 255, 255);
else
x += 11;
}

tmp2 = filter_black_stuff(tmp1);
tmp3 = filter_black_stuff(tmp2);

/* Fill letters in gray */
for(x = 26; x < 172; x++)
{
getpixel(tmp3, x, 15, &r, &g, &b);
if(r == 0)
filter_flood_fill(tmp3, x, 15, 127, 0, 255);
}

/* Find remaining black parts and remove them */
for(x = 26; x < 172; x++)
for(y = 15; y < 45; y++)
{
getpixel(tmp3, x, y, &r, &g, &b);
if(r == 0)
filter_flood_fill(tmp3, x, y, 255, 255, 255);
}

/* Fill letters in black */
for(x = 26; x < 172; x++)
{
getpixel(tmp3, x, 44, &r, &g, &b);
if(r == 127)
filter_flood_fill(tmp3, x, 44, 0, 0, 0);
}

/* Find remaining gray parts and remove them */
for(x = 26; x < 172; x++)
for(y = 15; y < 45; y++)
{
getpixel(tmp3, x, y, &r, &g, &b);
if(r == 127)
filter_flood_fill(tmp3, x, y, 255, 255, 255);
}

/* Guess all glyphs */
for(i = 0; i < 6; i++)
{
struct image *new;
int mindist = INT_MAX, min = -1;
new = filter_crop(tmp3, limits[i], 15, limits[i] + 11, 45);
for(j = 0; j < 27; j++)
{
int dist = 0;
for(y = 0; y < new->height; y++)
for(x = 0; x < new->width; x++)
{
int r2, g2, b2;
getpixel(font, 12 * j + x, y, &r, &g, &b);
getpixel(new, x, y, &r2, &g2, &b2);
dist += (r - r2) * (r - r2);
}
if(dist < mindist)
{
mindist = dist;
min = j;
}
}
image_free(new);
result[i] = all[min];
}

image_free(tmp1);
image_free(tmp2);
image_free(tmp3);
image_free(font);

return result;
}


Loading…
Cancel
Save