elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Prototipo "Lanzador Exploit"
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Prototipo "Lanzador Exploit"  (Leído 1,322 veces)
Vaagish


Desconectado Desconectado

Mensajes: 875



Ver Perfil
Prototipo "Lanzador Exploit"
« en: 16 Diciembre 2014, 04:24 am »

Hola, estoy con este programa y quería (ademas de compartirlo) tener una opinión extra, puede que no este super prolijo, y que algunas cosas se puedan optimizar,, (y probablemente lo haga), pero me gustaría tener una opinión fresca,, que tal el código, el método usado, etc..

El programa abre un archivo que yo guardo como por ej: "Exploit.bin", y puedo elegir enviarlo por un puerto X, a una direccion X por protocolo TCP o UDP (O sea, lanzar un exploit, no?), por otro lado, se puede abrir un programa y pasarle como parametro el exploit,,

Bueno, sin mas.. ahi el code:

Código
  1. #define WIN32_LEAN_AND_MEAN
  2.  
  3. #include <Windows.h>
  4. #include <iostream>
  5. #include <fstream>
  6. #include "Sockets.h"
  7. #include "Strings.h"
  8. using namespace std;
  9.  
  10. int OpenExploit(char * path);
  11. int OpenAndSend(char * LOCAL, char * Exploit);
  12. void ShowHelp(char * Me);
  13.  
  14. char * DstBuf;
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18.  
  19. cout << endl;
  20.  
  21. if (argc < 2) { ShowHelp(argv[0]); return EXIT_FAILURE; }
  22.  
  23. char PROTO[5] = "\0",
  24. IP[16] = "\0",
  25. PORT[5] = "\0",
  26. LOCAL[MAX_PATH] = "\0",
  27. EXPIT[MAX_PATH] = "\0";
  28.  
  29. char ptrOpt[MAX_PATH] = "\0";
  30.  
  31. for (int i = 1; i < argc; i++)
  32. {
  33. strcpy_s(ptrOpt, MAX_PATH, argv[i]);
  34.  
  35. if (strncmp(ptrOpt, "-", 1) == 0 || strncmp(ptrOpt, "/", 1) == 0)
  36. {
  37. // ------------------------------------------------- //
  38. if (strstr(ptrOpt, "R") || strstr(ptrOpt, "r")) { // REMOTE EXPLOIT
  39. char * STmp = strtok(argv[i + 1], ":");
  40. if (STmp != NULL) strcpy_s(IP, 15, STmp); // IP
  41. else { ShowHelp(argv[0]); return EXIT_FAILURE; }
  42. STmp = strtok(NULL, ":");
  43. if (STmp != NULL) strcpy_s(PORT, 5, STmp); // PORT
  44. else { ShowHelp(argv[0]); return EXIT_FAILURE; }}
  45. // ------------------------------------------------- //
  46.  
  47. if (strstr(ptrOpt, "P") || strstr(ptrOpt, "p")) // PROTOCOL
  48. strcpy_s(PROTO, 5, argv[i + 1]);
  49. if (strstr(ptrOpt, "L") || strstr(ptrOpt, "l")) // LOCAL EXPLOIT
  50. strcpy_s(LOCAL, MAX_PATH - 1, argv[i + 1]);
  51. if (strstr(ptrOpt, "X") || strstr(ptrOpt, "x")) // EXPLOIT
  52. strcpy_s(EXPIT, MAX_PATH - 1, argv[i + 1]);
  53. if (strstr(ptrOpt, "H") || strstr(ptrOpt, "h")) // HELP!
  54. { ShowHelp(argv[0]); return EXIT_SUCCESS; }
  55. }
  56. }
  57.  
  58. // =============================================================================================================================================
  59.  
  60. // *********************************
  61. // * REMOTE EXPLOIT PARAMETERS *
  62. // *********************************
  63. if (strcmp(LOCAL, "\0") == 0 && strcmp(IP, "\0") != 0 && strcmp(PORT, "\0") != 0 && strcmp(PROTO, "\0") != 0 && strcmp(EXPIT, "\0") != 0) {
  64.  
  65. if (strcmp(PROTO, "tcp") == 0 || strcmp(PROTO, "TCP") == 0) {
  66. cout << "\tConnect : TCP" << endl;
  67. } else if (strcmp(PROTO, "udp") == 0 || strcmp(PROTO, "UDP") == 0) {
  68. cout << "\tConnect : UDP" << endl;
  69. } else {
  70. ShowHelp(argv[0]);
  71. return EXIT_FAILURE;
  72. }
  73.  
  74. cout << "\tIP      : " << IP << endl;
  75. cout << "\tPort    : " << PORT << endl;
  76. cout << "\tExploit : " << EXPIT << endl;
  77.  
  78. if (OpenExploit(EXPIT) == EXIT_SUCCESS) {
  79. if (ConectAndSend(IP, strtoul(PORT, NULL, 0), PROTO, DstBuf) == EXIT_SUCCESS) {
  80. cout << endl << "\tExploit Send!" << endl;
  81. delete[] DstBuf;
  82. }
  83. }
  84.  
  85.  
  86. // *********************************
  87. // * LOCAL EXPLOIT PARAMETERS *
  88. // *********************************
  89. } else if (strcmp(LOCAL, "\0") != 0 && strcmp(IP, "\0") == 0 && strcmp(PORT, "\0") == 0 && strcmp(PROTO, "\0") == 0 && strcmp(EXPIT, "\0") != 0) {
  90.  
  91. cout << "\tLocal   : " << LOCAL << endl;
  92. cout << "\tExploit : " << EXPIT << endl;
  93.  
  94. if (OpenExploit(EXPIT) == EXIT_SUCCESS) {
  95. if (OpenAndSend(LOCAL, DstBuf) == EXIT_SUCCESS) {
  96. cout << endl << "\tExploit Send" << endl;
  97. delete[] DstBuf;
  98. }
  99. }
  100.  
  101. // *************
  102. // * ERROR *
  103. // *************
  104. } else { ShowHelp(argv[0]); return EXIT_FAILURE; }
  105.  
  106.  
  107. return EXIT_SUCCESS;
  108. }
  109.  
  110. int OpenExploit(char *path)
  111. {
  112.  
  113. ifstream Exploit;
  114.  
  115. Exploit.open(path, ios::in | ios::binary | ios::ate);
  116.  
  117. if (Exploit.is_open())
  118. {
  119. streampos size = Exploit.tellg();
  120. DstBuf = new char[size];
  121. Exploit.seekg(0, ios::beg);
  122. Exploit.read(DstBuf, size);
  123. cout << endl << "\tExploit Ready! Size: " << size << endl;
  124. if (Exploit.is_open()) Exploit.close();
  125. return EXIT_SUCCESS;
  126. } else {
  127. cout << endl << "\tError Opening Exploit" << endl;
  128. return EXIT_FAILURE;
  129. }
  130. }
  131.  
  132. int ConectAndSend(char *IP, DWORD PUERTO, char *PROTO, char *Exploit)
  133. {
  134.  
  135. int rtn = 0;
  136.  
  137. WSADATA WSA; //--> ESTRUCTURA WSADATA;
  138. SOCKET Socket; //--> VARIABLE DE TIPO SOCKET
  139. SOCKADDR_IN Server; //--> ESTRUCTURA SOCKADDR_IN
  140.  
  141. cout << endl;
  142.  
  143. if ((rtn = WSAStartup(MAKEWORD(2, 2), &WSA)) != 0) {
  144. cout << "\tError WSAStartup: " << rtn << endl;
  145. return EXIT_FAILURE;
  146. }
  147.  
  148. // TCP!
  149. if (strcmp(PROTO, "tcp") == 0 || strcmp(PROTO, "TCP") == 0) {
  150.  
  151. if ((Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == SOCKET_ERROR) {
  152. cout << "\tError en socket: " << WSAGetLastError() << endl;
  153. WSACleanup();
  154. return EXIT_FAILURE;
  155. }
  156. Server.sin_family = AF_INET;
  157. Server.sin_addr.S_un.S_addr = inet_addr(IP);
  158. Server.sin_port = htons(PUERTO);
  159. if ((rtn = connect(Socket, (struct sockaddr*) &Server, sizeof(Server))) == SOCKET_ERROR) {
  160. cout << "\tError en connect: " << WSAGetLastError() << endl;
  161. closesocket(Socket);
  162. WSACleanup();
  163. return EXIT_FAILURE;
  164. }
  165. if (send(Socket, Exploit, strlen(Exploit), 0) < 0) {
  166. cout << "\tError en Send" << endl;
  167. closesocket(Socket);
  168. WSACleanup();
  169. return EXIT_FAILURE;
  170. }
  171.  
  172. // UDP!
  173. } else if (strcmp(PROTO, "UDP") == 0 || strcmp(PROTO, "udp") == 0) {
  174.  
  175. int slen = sizeof(Server);
  176.  
  177. if ((Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR) {
  178. cout << "\tError en socket: " << WSAGetLastError() << endl;
  179. WSACleanup();
  180. return EXIT_FAILURE;
  181. }
  182. Server.sin_family = AF_INET;
  183. Server.sin_addr.S_un.S_addr = inet_addr(IP);
  184. Server.sin_port = htons(PUERTO);
  185. if (sendto(Socket, Exploit, strlen(Exploit), 0, (struct sockaddr *) &Server, slen) == SOCKET_ERROR) {
  186. cout << "\tError en Sendto" << endl;
  187. closesocket(Socket);
  188. WSACleanup();
  189. return EXIT_FAILURE;
  190. }
  191.  
  192. }
  193.  
  194. closesocket(Socket);
  195. WSACleanup();
  196. return EXIT_SUCCESS;
  197. }
  198.  
  199. int OpenAndSend(char *LOCAL, char *Exploit)
  200. {
  201.  
  202. cout << endl << "\t";
  203.  
  204. STARTUPINFO lpStartupInfo;
  205. PROCESS_INFORMATION lpProcessInformation;
  206.  
  207. ZeroMemory(&lpStartupInfo, sizeof(lpStartupInfo));
  208. lpStartupInfo.cb = sizeof(lpStartupInfo);
  209. ZeroMemory(&lpProcessInformation, sizeof(lpProcessInformation));
  210.  
  211. if (!CreateProcess(LOCAL, Exploit, NULL, NULL, FALSE, 0, NULL, NULL, &lpStartupInfo, &lpProcessInformation))
  212. {
  213. cout << endl << "\tError CreateProcess: " << GetLastError() << endl;
  214. return EXIT_FAILURE;
  215. }
  216.  
  217. WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);
  218. CloseHandle(lpProcessInformation.hProcess);
  219. CloseHandle(lpProcessInformation.hThread);
  220.  
  221. return EXIT_SUCCESS;
  222. }
  223.  
  224. void ShowHelp(char * Me)
  225. {
  226. cout << " USAGE: " << Me << endl << Help << Me << EXAMPLE << endl;
  227. }

Saludos!


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines