remangle.cgi.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. HTML manglizer
  3. --------------
  4. Copyright (C) 2004 by Michal Zalewski <lcamtuf@coredump.cx>
  5. Fault reproduction utility.
  6. */
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #include "tags.h"
  13. #define R(x) (rand() % (x))
  14. #define MAXTCOUNT 100
  15. #define MAXPCOUNT 20
  16. #define MAXSTR2 80
  17. void make_up_value(void) {
  18. char c=R(2);
  19. if (c) putchar('"');
  20. switch (R(31)) {
  21. case 0: printf("javascript:"); make_up_value(); break;
  22. // case 1: printf("jar:"); make_up_value(); break;
  23. case 2: printf("mk:"); make_up_value(); break;
  24. case 3: printf("file:"); make_up_value(); break;
  25. case 4: printf("http:"); make_up_value(); break;
  26. case 5: printf("about:"); make_up_value(); break;
  27. case 6: printf("_blank"); break;
  28. case 7: printf("_self"); break;
  29. case 8: printf("top"); break;
  30. case 9: printf("left"); break;
  31. case 10: putchar('&'); make_up_value(); putchar(';'); break;
  32. case 11: make_up_value(); make_up_value(); break;
  33. case 12 ... 20: {
  34. int c = R(10) ? R(10) : (1 + R(MAXSTR2) * R(MAXSTR2));
  35. char* x = malloc(c);
  36. memset(x,R(256),c);
  37. fwrite(x,c,1,stdout);
  38. free(x);
  39. break;
  40. }
  41. case 21: printf("%s","%n%n%n%n%n%n"); break;
  42. case 22: putchar('#'); break;
  43. case 23: putchar('*'); break;
  44. default: if (R(2)) putchar('-'); printf("%d",rand()); break;
  45. }
  46. if (c) putchar('"');
  47. }
  48. void random_tag(void) {
  49. int tn, tc;
  50. do tn = R(MAXTAGS); while (!tags[tn][0]);
  51. tc = R(MAXPCOUNT) + 1;
  52. putchar('<');
  53. switch (R(10)) {
  54. case 0: putchar(R(256)); break;
  55. case 1: putchar('/');
  56. }
  57. printf("%s", tags[tn][0]);
  58. while (tc--) {
  59. int pn;
  60. switch (R(32)) {
  61. case 0: putchar(R(256));
  62. case 1: break;
  63. default: putchar(' ');
  64. }
  65. do pn = R(MAXPARS-1) + 1; while (!tags[tn][pn]);
  66. printf("%s", tags[tn][pn]);
  67. switch (R(32)) {
  68. case 0: putchar(R(256));
  69. case 1: break;
  70. default: putchar('=');
  71. }
  72. make_up_value();
  73. }
  74. putchar('>');
  75. }
  76. int main(int argc,char** argv) {
  77. int tc,seed;
  78. char* x = getenv("QUERY_STRING");
  79. if (!x || sscanf(x,"%x",&seed) != 1) {
  80. printf("Content-type: text/plain\n\nMissing or invalid parameter.\n");
  81. exit(1);
  82. }
  83. printf("Content-Type: text/html;charset=utf-8\nRefresh: 0;URL=remangle.cgi?0x%08x\n\n", seed);
  84. printf("<HTML><HEAD><META HTTP-EQUIV=\"Refresh\" content=\"0;URL=remangle.cgi?0x%08x\">\n", seed);
  85. printf("<script language=\"javascript\">setTimeout('window.location=\"remangle.cgi?0x%08x\"', 1000);</script>\n", seed);
  86. srand(seed);
  87. tc = R(MAXTCOUNT) + 1;
  88. while (tc--) random_tag();
  89. fflush(0);
  90. return 0;
  91. }