Advertisement
Guest User

Untitled

a guest
Oct 20th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. /* Brute-force tripcode finder, for 2channel boards.
  2. * Will work with restrictions on Wakaba/Wakaba-ZERO/Kareha/Shiichan/Futallaby/Futaba/Electron/Etc.
  3. * Tripcode output containing <>"'!#,& may not work.
  4. *
  5. * To build: build.sh
  6. *
  7. * Output:
  8. * #blah !XXXXXXXXXX
  9. * Append #blah to your name when posting to get the printed tripcode.
  10. * Todo:
  11. * check higher-ascii/SJIS tripcode inputs
  12. * $Id$ Alexander Strange, astrange@ithinksw.com, http://astrange.ithinksw.net/
  13. * Shiichan: http://shii.org/shiichan
  14. * Kareha: http://wakaba.c3.cx/
  15. */
  16. #define crypt notmycrypt
  17. #include <unistd.h>
  18. #undef crypt
  19. #include <strings.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <stdlib.h>
  24. #include <signal.h>
  25.  
  26. #ifdef SHIICHAN4K
  27. #include <arpa/inet.h>
  28. #include "sha1.c"
  29. #include "base64.c"
  30. #define OUTPUT_LEN 11
  31. #elif WAKABARC4
  32. #include "rc4.c"
  33. #include "base64.c"
  34. #define OUTPUT_LEN 8
  35. #else
  36. #include "crypt.c"
  37. #define OUTPUT_LEN 10
  38. #endif
  39.  
  40. #ifdef __GNUC__
  41. #define likely(x) __builtin_expect(x,1)
  42. #define unlikely(x) __builtin_expect(x,0)
  43. #define always_inline __attribute__((always_inline))
  44. #else
  45. #define likely(x) (x)
  46. #define unlikely(x) (x)
  47. #define always_inline inline
  48. #endif
  49.  
  50. #ifdef CASE_SENSITIVE
  51. #define ceq(a,b) ((a)==(b))
  52. #else
  53. static inline unsigned char sc(unsigned char x) {return ((x >= 'A') && (x <= 'Z')) ? (x+('a'-'A')) : ((x >= 'a') && (x <= 'z')) ? (x-('a'-'A')) : x;} // switch case
  54. static inline unsigned char ceq(unsigned char a, unsigned char b) {unsigned char r = unlikely(a==b); return r ? r : a == sc(b);}
  55. #endif
  56.  
  57. static inline unsigned char strcontainsstr(const unsigned char * big,const char * small, unsigned char len, unsigned char slen)
  58. {
  59. unsigned char i=0, i2=0;
  60. if (slen == 0) return 1;
  61. redo_from_start:
  62. for (; i < len; i++) if (ceq(big[i],small[0])) goto more_tries;
  63. return 0;
  64. more_tries:
  65. i2 = 1;
  66. for (i++; i < len; i++,i2++) {
  67. if (!ceq(big[i],small[i2])) {
  68. if (slen == i2) return 1;
  69. else if (ceq(big[i],small[0])) goto more_tries;
  70. else goto redo_from_start;
  71. }
  72. }
  73. return 0;
  74. }
  75.  
  76. #ifndef SHIICHAN4K
  77. #ifndef WAKABARC4
  78. static unsigned char
  79. tripsaltclean(unsigned char i)
  80. {
  81. if ((i < '.') || (i > 'z'))
  82. i = '.';
  83. if ((i >= ':') && (i <= '@'))
  84. i += 'A' - ':';
  85. else if ((i >= '[') && (i <= '`'))
  86. i += 'a' - '[';
  87. return i;
  88. }
  89.  
  90. static inline unsigned char *
  91. tripcode_2ch(unsigned char *input, unsigned int ilen)
  92. {
  93. char salt[2];
  94.  
  95. if ((ilen >= 2)) {
  96. salt[0] = tripsaltclean(input[1]);
  97. salt[1] = (ilen > 2)? tripsaltclean(input[2]):'H';
  98. } else {salt[0] = 'H'; salt[1] = '.';}
  99.  
  100. return (unsigned char*)crypt((char*)input, salt) + 3;
  101. }
  102. #else
  103. static inline void
  104. tripcode_wakaba(unsigned char *input,unsigned char *buffer, unsigned int ilen)
  105. {
  106. unsigned char hash[6];
  107. rc4(input,hash,ilen);
  108. b64rc4(hash,buffer);
  109. }
  110. #endif
  111. #else
  112. static inline void
  113. tripcode_shiichan(unsigned char *input,unsigned char *buffer, unsigned int ilen)
  114. {
  115. unsigned int hash[5];
  116. sha1(input,ilen,hash);
  117. b64sha((unsigned char*)hash,buffer);
  118. }
  119. #endif
  120.  
  121. static const unsigned char tripcode_inputs[94] = " \"$%&'()*+,-.!/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  122.  
  123. static inline int htmlspecialchars(unsigned char *tripindexes, unsigned char *htmled, unsigned char ilen)
  124. {
  125. int i=0, i2=0;
  126. for (;i < ilen; i++) {
  127. unsigned char c = tripcode_inputs[tripindexes[i]];
  128. switch (c) {
  129. case '<':
  130. htmled[i2] = '&';
  131. htmled[i2+1] = 'l';
  132. htmled[i2+2] = 't';
  133. htmled[i2+3] = ';';
  134. i2+=4;
  135. break;
  136. case '>':
  137. htmled[i2] = '&';
  138. htmled[i2+1] = 'g';
  139. htmled[i2+2] = 't';
  140. htmled[i2+3] = ';';
  141. i2+=4;
  142. break;
  143. case '&':
  144. htmled[i2] = '&';
  145. htmled[i2+1] = 'a';
  146. htmled[i2+2] = 'm';
  147. htmled[i2+3] = 'p';
  148. htmled[i2+4] = ';';
  149. i2+=5;
  150. break;
  151. case '"':
  152. htmled[i2] = '&';
  153. htmled[i2+1] = 'q';
  154. htmled[i2+2] = 'u';
  155. htmled[i2+3] = 'o';
  156. htmled[i2+4] = 't';
  157. htmled[i2+5] = ';';
  158. i2+=6;
  159. break;
  160. case '\'':
  161. htmled[i2] = '&';
  162. htmled[i2+1] = '#';
  163. htmled[i2+2] = '0';
  164. htmled[i2+3] = '3';
  165. htmled[i2+4] = '9';
  166. htmled[i2+5] = ';';
  167. i2+=6;
  168. break;
  169. default: htmled[i2] = c; i2++;
  170. }
  171. }
  172. return i2;
  173. }
  174.  
  175. static inline void fill_count(unsigned char *count, unsigned len, unsigned step) {
  176. int i = len;
  177. while (i-- >= 0) {
  178. count[i] = step % 94;
  179. step /= 94;
  180. }
  181. }
  182.  
  183. static inline unsigned trips_per_len(unsigned len) {
  184. // trips = 94**len
  185. unsigned mul=1;
  186. while (len--) mul *= 94;
  187. return mul;
  188. }
  189.  
  190. static always_inline void
  191. testeverytripoflength(unsigned char len,const char * search, unsigned char searchlen, unsigned char *workspace,const char * salt, unsigned int saltlen)
  192. {
  193. unsigned int trips = trips_per_len(len), i;
  194.  
  195. for (i = 0; i < trips; i++) {
  196. unsigned char count[8];
  197. unsigned char len2;
  198. fill_count(count, len, i);
  199. #ifdef SHIICHAN4K
  200. unsigned char buffer[12];
  201. len2 = htmlspecialchars(count, workspace, len);
  202. memcpy(workspace+len2,salt,saltlen);
  203. tripcode_shiichan(workspace, buffer, len2+saltlen);
  204. #elif WAKABARC4
  205. unsigned char buffer[10];
  206. len2 = htmlspecialchars(count, workspace+1, len);
  207. memcpy(workspace+1+len2,salt,saltlen);
  208. tripcode_wakaba(workspace, buffer, 1+len2+saltlen);
  209. #else
  210. unsigned char *buffer;
  211. len2 = htmlspecialchars(count, workspace,len);
  212. workspace[len2]='\0';
  213. buffer = tripcode_2ch(workspace, len2);
  214. #endif
  215. if (strcontainsstr(buffer, search, OUTPUT_LEN, searchlen)) {
  216. unsigned char tripin[9],j;
  217. for (j=0; j < len; j++) tripin[j] = tripcode_inputs[count[j]];
  218. buffer[OUTPUT_LEN] = tripin[len]='\0';
  219. printf(
  220. #if 1
  221. #if defined(SHIICHAN4K) || defined(WAKABARC4)
  222. "##%s !%s\n"
  223. #else
  224. "#%s !%s\n"
  225. #endif
  226. #else
  227. ""
  228. #endif
  229. , tripin, buffer);
  230. }
  231. }// while (!advance(count, len));
  232. }
  233.  
  234. static void terminatehandle(int unused)
  235. {
  236. printf("Exiting...\n");
  237. exit(0);
  238. }
  239.  
  240. int
  241. main(int argc, const char *argv[])
  242. {
  243. int i; int searchlen;const char *salt; unsigned saltlen;
  244. signal(SIGPIPE,terminatehandle);
  245. signal(SIGTERM,terminatehandle);
  246. signal(SIGINT,terminatehandle);
  247. setlinebuf(stdout);
  248. #ifdef SHIICHAN4K
  249. #define shaworklen (8*6+448)
  250. if (argc<3) return 1;
  251. unsigned char salta[448]; salt=(char*)salta;
  252. unsigned char work[shaworklen + (64 - (shaworklen%64))]; saltlen=448;
  253. int f = open(argv[2],O_RDONLY); if (f==-1) {perror("salt read failed"); exit(1);} read(f,salta,448); close(f);
  254. #elif WAKABARC4
  255. if (argc<3) return 1;
  256. saltlen = strlen(argv[2]);
  257. unsigned char work[1+8*6+saltlen];
  258. work[0] = 't';
  259. salt = argv[2];
  260. #else
  261. if (argc<2) return 1;
  262. unsigned char work[8*6];
  263. init_des(); salt=NULL; saltlen = 0;
  264. #endif
  265. searchlen = strlen(argv[1]);
  266. for (i = 1; i <= 8; i++)
  267. testeverytripoflength(i, argv[1], searchlen, work, salt, saltlen);
  268. return 0;
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement