KOS脚本开源代码:Kangle主机违禁关键词扫描
该工具是为了一键检查Kangle主机系统中的网站,是否存在违禁违法关键词内容。是一个正能量、保证干净和符合社会主义价值观的脚本。
解析
第一段脚本通过将txt违禁词文档载入,通过for循环,利用grpe命令来检测Kangle目录/home/ftp/下的主机文件内容是否存在违禁词。该脚本会开启5个后台线程进行检测。每个线程对应不同的主机文件路径(越来越深入)。
第二段循环是检测上述5个线程是否已经检查结束,如果检查到结束文件,则创建该线程的结束标记。
第三段则是检测上述5个线程标记是否齐全,如果5个标签都存在,则代表检测完成。提示是否查看结果
启动
1. 提前创建文件 /root/chenk_main_GJC.txt 并将需要检测的违规词一行一行输入
2. 将脚本第2行数字改成违禁词的总数。假如写了10个违禁词在chenk_main_GJC.txt文件中,则该处写10
结语
最终检测结果界面是通过grep命令显示违禁关键词内容,展示界面比较粗糙。如果你对该脚本感兴趣,可以自行修改和优化其内容,来做到更加完善!
rm -rf /root/kos_gjc gjc_num=34 #关键词总数 mkdir /root/kos_gjc touch /root/wei_jing_over.txt echo "KOS工具箱提醒你:巡检1级目录,任务1开始..." touch /root/kos_gjc/gjc_1 for GuanJianCi in `cat /root/chenk_main_GJC.txt` do echo "[任务1]>>正在巡检关键词“*涉及敏感,已隐藏*”..." grep -s "$GuanJianCi" /home/ftp/*/*/* >> /root/kos_gjc/wei_jing_over.txt echo "正在巡检关键词“$GuanJianCi”..." >> /root/kos_gjc/gjc_1 done & echo "KOS工具箱提醒你:巡检2级目录,任务2开始..." touch /root/kos_gjc/gjc_2 for GuanJianCi in `cat /root/chenk_main_GJC.txt` do echo "[任务2]>>正在巡检关键词“*涉及敏感,已隐藏*”..." grep -s "$GuanJianCi" /home/ftp/*/*/*/* >> /root/kos_gjc/wei_jing_over.txt echo "正在巡检关键词“$GuanJianCi”..." >> /root/kos_gjc/gjc_2 done & echo "KOS工具箱提醒你:巡检3级目录,任务3开始..." touch /root/kos_gjc/gjc_3 for GuanJianCi in `cat /root/chenk_main_GJC.txt` do echo "[任务3]>>正在巡检关键词“*涉及敏感,已隐藏*”..." grep -s "$GuanJianCi" /home/ftp/*/*/*/*/* >> /root/kos_gjc/wei_jing_over.txt echo "正在巡检关键词“$GuanJianCi”..." >> /root/kos_gjc/gjc_3 done & echo "KOS工具箱提醒你:巡检4级目录,任务4开始..." touch /root/kos_gjc/gjc_4 for GuanJianCi in `cat /root/chenk_main_GJC.txt` do echo "[任务4]>>正在巡检关键词“*涉及敏感,已隐藏*”..." grep -s "$GuanJianCi" /home/ftp/*/*/*/*/*/* >> /root/kos_gjc/wei_jing_over.txt echo "正在巡检关键词“$GuanJianCi”..." >> /root/kos_gjc/gjc_4 done & echo "KOS工具箱提醒你:巡检5级目录,任务5开始..." echo "" touch /root/kos_gjc/gjc_5 for GuanJianCi in `cat /root/chenk_main_GJC.txt` do echo "[任务5]>>正在巡检关键词“*涉及敏感,已隐藏*”..." grep -s "$GuanJianCi" /home/ftp/*/*/*/*/*/*/* >> /root/kos_gjc/wei_jing_over.txt echo "正在巡检关键词“$GuanJianCi”..." >> /root/kos_gjc/gjc_5 done & #监控任务线程 touch /root/kos_gjc/over while true do gjc_1=` awk 'END{print NR}' /root/kos_gjc/gjc_1 ` if [[ $gjc_1 == $gjc_num ]];then echo "gjc_1=ok" >> /root/kos_gjc/over break fi sleep 3s done & while true do gjc_2=` awk 'END{print NR}' /root/kos_gjc/gjc_2 ` if [[ $gjc_2 == $gjc_num ]];then echo "gjc_2=ok" >> /root/kos_gjc/over break fi sleep 3s done & while true do gjc_3=` awk 'END{print NR}' /root/kos_gjc/gjc_3 ` if [[ $gjc_3 == $gjc_num ]];then echo "gjc_3=ok" >> /root/kos_gjc/over break fi sleep 3s done & while true do gjc_4=` awk 'END{print NR}' /root/kos_gjc/gjc_4 ` if [[ $gjc_4 == $gjc_num ]];then echo "gjc_4=ok" >> /root/kos_gjc/over break fi sleep 3s done & while true do gjc_5=` awk 'END{print NR}' /root/kos_gjc/gjc_5 ` if [[ $gjc_5 == $gjc_num ]];then echo "gjc_5=ok" >> /root/kos_gjc/over break fi sleep 3s done & #最终over检查 while true do gjc_over=` awk 'END{print NR}' /root/kos_gjc/over ` if [ $gjc_over == 5 ];then echo "违禁关键词,检查完毕!" echo "" read -p "查看结果(y/N):" hehe if [ $hehe == N ];then rm -rf /root/kos_gjc rm -rf /root/chenk_main_GJC.txt rm -rf /root/wei_jing_over.txt echo "你选择退出!如需查看。请重新运行检查!" exit else wenjiandaxiao=` ls -l /root/kos_gjc/wei_jing_over.txt | awk '{print $5}' ` if (( 0 < $wenjiandaxiao ));then sed -i "/Binary file/d" /root/kos_gjc/wei_jing_over.txt nl /root/kos_gjc/wei_jing_over.txt echo -e "\n\033[31m 1. 违规内容结果以“行”展示,每行前有行号;\n 2. 每行分为xxx:xxx结构;\n “:”的左边为文件路径&主机用户名;\n “:”的右边是[违规内容]前后相关的内容;\n 3. 疑问加KOS工具箱QQ群:825099477 \033[0m \n巡检已结束!" rm -rf /root/kos_gjc rm -rf /root/chenk_main_GJC.txt rm -rf /root/wei_jing_over.txt else echo "恭喜,没有查到违禁关键词!请记得定时检查!" rm -rf /root/kos_gjc rm -rf /root/chenk_main_GJC.txt rm -rf /root/wei_jing_over.txt exit fi fi break fi sleep 3s done