KOS脚本开源代码:Kangle数据库Mysql违禁关键词扫描
该脚本是通过扫描导出的MySql文件来确定某个数据库是否存在违规内容,保证网站不存在违法违规内容的关键词。
解析
该脚本需要输入MySql的密码,来导出数据库文件,随后再进行违规关键词检测。如果运行会提示输入MySql密码,可放心输入。
启动
提前在目录 /root/kos_gjc_mysql/ 创建文件 chenk_main_GJC.txt 并将需要检测的违规词一行一行输入
结语
最终检测结果界面是通过grep命令显示违禁关键词内容,展示界面比较粗糙。如果你对该脚本感兴趣,可以自行修改和优化其内容,来做到更加完善!
rm -rf /root/kos_gjc_mysql echo -e "\n*检查Mysql内容是否违规需要输入Mysql密码*\n" read -p "是否继续检查Mysql数据库(y/N):" jxjc if [[ $jxjc == N ]];then echo "你选择不检查Mysql违规内容,KOS工具箱退出!" exit; else echo -e "你选择继续检查Mysql...\n" while true do read -p "请输入Mysql数据库密码,并回车:" mysqlpasswd host="localhost";port="3306";userName="root";dbname="mysql";dbset="--default-character-set=utf8 -A";mysql -h${host} -u${userName} -p${mysqlpasswd} ${dbname} -P${port} -e "${cmd}" if [ $? == 0 ];then echo -e "请稍后,正在提取数据库副本到巡检环境..." break else echo "密码错误,请重新输入!" fi done fi mkdir /root/kos_gjc_mysql mkdir /root/kos_gjc_mysql/mysql_list ls -F /var/lib/mysql | grep "/$" > /root/kos_gjc_mysql/mysql-list.txt sed -i "s/\///g" /root/kos_gjc_mysql/mysql-list.txt for kos_mysql_name in `cat /root/kos_gjc_mysql/mysql-list.txt` do mysqldump -uroot -p${mysqlpasswd} ${kos_mysql_name} > /root/kos_gjc_mysql/mysql_list/${kos_mysql_name}.sql done echo "KOS工具箱提醒你:Mysql巡检任务开始..." echo "" for GuanJianCi in `cat /root/kos_gjc_mysql/chenk_main_GJC.txt` do grep -s "$GuanJianCi" /root/kos_gjc_mysql/mysql_list/* >> /root/kos_gjc_mysql/wei_jing_over.txt done echo "" echo "Mysql违禁关键词,检查完毕!" echo "" read -p "查看结果(y/N):" hehe if [ $hehe == N ];then rm -rf /root/kos_gjc_mysql echo "你选择退出!如需查看。请重新运行检查!" exit else wenjiandaxiao=` ls -l /root/kos_gjc_mysql/wei_jing_over.txt | awk '{print $5}' ` if (( 0 < $wenjiandaxiao ));then nl /root/kos_gjc_mysql/wei_jing_over.txt echo -e "\n\033[31m 1. 违规内容结果以“行”展示,每行前有行号;\n 2. 每行分为xxx:xxx结构;\n “:”的左边abcde.sql,代表主机用户名;\n “:”的右边是[违规内容]前后相关的内容;\n 3. 疑问加KOS工具箱QQ群:825099477 \033[0m \nMysql违规内容巡检已结束!" rm -rf /root/kos_gjc_mysql exit; else echo -e "巡检已结束!\n恭喜,没有查到违禁关键词!请记得定时检查!" rm -rf /root/kos_gjc_mysql exit fi fi