linux下rm命令屏蔽脚本

post by rocdk890 / 2016-1-9 21:45 Saturday linux技术
  今天发现了个不错的东西,Linux之劫持rm命令实现安全删除和屏蔽删除/、/*,发给群里居然还有人因为不会用而说不好,让我很是不爽,下面分享给大家,怎么使用请自己摸索,简单的东西就不想当保姆教了.
下载地址:
wget http://www.dwhd.org/script/securityremove.sh
或者
wget http://download.slogra.com/soft_shell/securityremove.sh

securityremove脚本内容:
#!/bin/bash
#########################################################################
# File Name: securityremove.sh
# Author: LookBack
# Email: admin#dwhd.org
# Version:
# Created Time: 2015年08月16日 星期日 01时47分37秒
#########################################################################
 
wget -q http://www.dwhd.org/script/securityremove -O /bin/securityremove
chmod 755 /bin/securityremove
[ -f /etc/bash.bashrc ] && (sed -i "/securityremove/d" /etc/bash.bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bash.bashrc && . /etc/bash.bashrc)
[ -f /etc/bashrc ] && (sed -i "/securityremove/d" /etc/bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bashrc && . /etc/bashrc)
[ -f /root/.bashrc ] && (sed -i "/alias rm/d" /root/.bashrc && echo 'alias rm="/bin/securityremove"' >> /root/.bashrc && . /root/.bashrc)
[[ -f "~/.bashrc" && "$USER" != "root" ]] &&(sed -i "/alias rm/d" ~/.bashrc && echo 'alias rm="/bin/securityremove"' >> ~/.bashrc && . ~/.bashrc)


securityremove核心源码:
#!/bin/bash
#########################################################################
# File Name: securityremove.sh
# Author: LookBack
# Email: admin#dwhd.org
# Version:
# Created Time: 2015年08月16日 星期日 01时47分37秒
#########################################################################
 
RMARGS="${@}"
RMPATH="/bin/rm"
sys1dir=$(ls / | sed 's/^/\//' | tr "\n" " " | sed 's/.$//')
[ "${RMARGS}" == "" ] && ${RMPATH} && exit
 
SBRUN() {
        echo -ne "\033[41;37mWhy run this command\033[0m\n"
        exit 255
}
 
if grep "$sys1dir" <<< $RMARGS >/dev/null 2>&1; then SBRUN;fi
for i in ${@};do [ "$i" = "/" ] && SBRUN ;done
 
if [ "${RMARGS}" == '-h' ] || [ "${RMARGS}" == '--help' ];then
        ${RMPATH} ${RMARGS}
else
        while [ "${confirm}" != "yes" ] && [ "${confirm}" != "no" ]; do
                echo -ne "You are going to execute \"${RMPATH} \033[41;37m${RMARGS}\033[0m\",please confirm (yes or no):"
                read confirm
        done
        [ "${confirm}" == "yes" ] && ${RMPATH} ${RMARGS} || exit
fi


使用效果截图:
点击查看原图

ps:http://www.dwhd.org/20150816_015727.html
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-624.html

标签: linux shell 脚本 保护 rm 劫持

评论: