You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

276 lines
8.4 KiB

  1. /*
  2. * main.c: main function
  3. * $Id$
  4. *
  5. * Copyright: (c) 2004 Sam Hocevar <sam@zoy.org>
  6. * This program is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What The Fuck You Want
  9. * To Public License, Version 2, as published by Sam Hocevar. See
  10. * http://sam.zoy.org/wtfpl/COPYING for more details.
  11. */
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <getopt.h>
  16. #include <stdarg.h>
  17. #include "config.h"
  18. #include "common.h"
  19. #ifdef HAVE_GETOPT_LONG
  20. # define MOREINFO "Try `%s --help' for more information.\n"
  21. #else
  22. # define MOREINFO "Try `%s -h' for more information.\n"
  23. #endif
  24. /* Used for the debug messages */
  25. char *argv0 = NULL;
  26. char *share = NULL;
  27. int debug = 1;
  28. int main(int argc, char *argv[])
  29. {
  30. char *mode = "auto";
  31. int c;
  32. int digit_optind = 0;
  33. argv0 = argv[0];
  34. share = "share";
  35. for(;;)
  36. {
  37. int this_option_optind = optind ? optind : 1;
  38. #ifdef HAVE_GETOPT_LONG
  39. int option_index = 0;
  40. static struct option long_options[] =
  41. {
  42. { "help", 0, 0, 'h' },
  43. { "mode", 1, 0, 'm' },
  44. { "share", 1, 0, 's' },
  45. { "quiet", 0, 0, 'q' },
  46. { "version", 0, 0, 'v' },
  47. { 0, 0, 0, 0 }
  48. };
  49. c = getopt_long(argc, argv, "hm:s:qv", long_options, &option_index);
  50. #else
  51. c = getopt(argc, argv, "hm:s:qv");
  52. #endif
  53. if(c == -1)
  54. break;
  55. switch(c)
  56. {
  57. case 'h': /* --help */
  58. printf("Usage: %s [OPTION]... IMAGE...\n", argv[0]);
  59. #ifdef HAVE_GETOPT_LONG
  60. printf(" -m, --mode <mode> force operating mode\n");
  61. printf(" -s, --share <dir> specify shared dir\n");
  62. printf(" -q, --quiet do not print information messages\n");
  63. printf(" -h, --help display this help and exit\n");
  64. printf(" -v, --version output version information and exit\n");
  65. #else
  66. printf(" -m <mode> force operating mode\n");
  67. printf(" -s <dir> specify shared dir\n");
  68. printf(" -q do not print information messages\n");
  69. printf(" -h display this help and exit\n");
  70. printf(" -v output version information and exit\n");
  71. #endif
  72. return 0;
  73. case 'm': /* --mode */
  74. mode = optarg;
  75. break;
  76. case 'q': /* --quiet */
  77. debug = 0;
  78. break;
  79. case 's': /* --quiet */
  80. share = optarg;
  81. break;
  82. case 'v': /* --version */
  83. printf("pwntcha (captcha decoder) %s\n", PACKAGE_VERSION);
  84. printf("Written by Sam Hocevar.\n");
  85. printf("\n");
  86. printf("Copyright (C) 2004-2005 Sam Hocevar <sam@zoy.org>\n");
  87. printf("This is free software; see the source for copying conditions. There is NO\n");
  88. printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
  89. return 0;
  90. case '?':
  91. printf(MOREINFO, argv[0]);
  92. return 1;
  93. default:
  94. printf("%s: invalid option -- %i\n", argv[0], c);
  95. printf(MOREINFO, argv[0]);
  96. return 1;
  97. }
  98. }
  99. if(optind >= argc)
  100. {
  101. printf("%s: too few arguments\n", argv[0]);
  102. printf(MOREINFO, argv[0]);
  103. return 1;
  104. }
  105. for(; optind < argc; optind++)
  106. {
  107. char *input = argv[optind], *result;
  108. struct image *img;
  109. int count;
  110. img = image_load(argv[optind]);
  111. if(!img)
  112. {
  113. pwnprint("cannot load %s\n", input);
  114. printf("\n");
  115. continue;
  116. }
  117. count = filter_count(img);
  118. pwnprint("image size %ix%i, %i colours\n",
  119. img->width, img->height, count);
  120. if(!strcmp(mode, "test"))
  121. result = decode_test(img);
  122. else if(!strcmp(mode, "authimage"))
  123. result = decode_authimage(img);
  124. else if(!strcmp(mode, "clubic"))
  125. result = decode_clubic(img);
  126. else if(!strcmp(mode, "java"))
  127. result = decode_java(img);
  128. else if(!strcmp(mode, "linuxfr"))
  129. result = decode_linuxfr(img);
  130. else if(!strcmp(mode, "livejournal"))
  131. result = decode_livejournal(img);
  132. else if(!strcmp(mode, "lmt"))
  133. result = decode_lmt(img);
  134. else if(!strcmp(mode, "paypal"))
  135. result = decode_paypal(img);
  136. else if(!strcmp(mode, "phpbb"))
  137. result = decode_phpbb(img);
  138. else if(!strcmp(mode, "scode"))
  139. result = decode_scode(img);
  140. else if(!strcmp(mode, "slashdot"))
  141. result = decode_slashdot(img);
  142. else if(!strcmp(mode, "vbulletin"))
  143. result = decode_vbulletin(img);
  144. else if(!strcmp(mode, "xanga"))
  145. result = decode_xanga(img);
  146. else
  147. {
  148. if(img->width == 155 && img->height == 50)
  149. {
  150. pwnprint("probably an authimage captcha\n");
  151. result = decode_authimage(img);
  152. }
  153. else if(img->width == 175 && img->height == 35)
  154. {
  155. pwnprint("probably a livejournal captcha\n");
  156. result = decode_livejournal(img);
  157. }
  158. else if(img->width == 100 && img->height == 40 && count < 6)
  159. {
  160. pwnprint("probably a linuxfr captcha\n");
  161. result = decode_linuxfr(img);
  162. }
  163. else if(img->width == 69 && img->height == 35)
  164. {
  165. pwnprint("probably a lmt.lv captcha\n");
  166. result = decode_lmt(img);
  167. }
  168. else if(img->width == 208 && img->height == 26)
  169. {
  170. pwnprint("probably a Paypal captcha\n");
  171. result = decode_paypal(img);
  172. }
  173. else if(img->width == 320 && img->height == 50)
  174. {
  175. pwnprint("probably a phpBB captcha\n");
  176. result = decode_phpbb(img);
  177. }
  178. else if(img->width == 170 && img->height == 50)
  179. {
  180. pwnprint("probably a Xanga captcha\n");
  181. result = decode_xanga(img);
  182. }
  183. else if(img->height <= 40 && count < 10)
  184. {
  185. pwnprint("probably a scode/trencaspammers captcha\n");
  186. result = decode_scode(img);
  187. }
  188. else if(img->height <= 30 && count < 100)
  189. {
  190. pwnprint("probably a clubic captcha\n");
  191. result = decode_clubic(img);
  192. }
  193. else if(img->height == 69)
  194. {
  195. pwnprint("probably a slashdot captcha\n");
  196. result = decode_slashdot(img);
  197. }
  198. else if(img->width == 200 && img->height == 100)
  199. {
  200. pwnprint("probably a java captcha\n");
  201. result = decode_java(img);
  202. }
  203. else if(img->width == 290 && img->height == 80)
  204. {
  205. pwnprint("probably a ticketmaster captcha\n");
  206. result = decode_ticketmaster(img);
  207. }
  208. else if(img->width == 200 && img->height == 40)
  209. {
  210. pwnprint("probably a tickets.com captcha\n");
  211. result = decode_tickets(img);
  212. }
  213. else if(img->height == 61)
  214. {
  215. pwnprint("probably a vbulletin captcha\n");
  216. result = decode_vbulletin(img);
  217. }
  218. else if(img->width == 480 && img->height == 360 && count == 253)
  219. {
  220. pwnprint("probably not a captcha\n");
  221. result = decode_easter_eggs(img);
  222. }
  223. else
  224. {
  225. pwnprint("could not guess captcha type\n");
  226. printf("\n");
  227. image_free(img);
  228. continue;
  229. }
  230. }
  231. image_free(img);
  232. if(!result)
  233. {
  234. pwnprint("sorry, decoding failed\n");
  235. printf("\n");
  236. continue;
  237. }
  238. printf("%s\n", result);
  239. fflush(stdout);
  240. free(result);
  241. }
  242. return 0;
  243. }
  244. void pwnprint(const char *fmt, ...)
  245. {
  246. va_list args;
  247. if(!debug)
  248. return;
  249. va_start(args, fmt);
  250. fprintf(stderr, "%s: ", argv0);
  251. vfprintf(stderr, fmt, args);
  252. va_end(args);
  253. }