检测日志敏感信息脚本-shell版
#!/bin/bash
#date:2021-09-24
#author:xxx
#定义变量
PATH=$PATH
#emailUrl="http://ip:8080/MailService/sendMail"
#sysEncoding=$(expr match $LANG '.*\.\([^@]\+\).*$')ip
#timestamp=$(date '+%s%3N')
#email_title='测试环境日志敏感信息排查'
IP=`ifconfig eth0|awk -F '[ :]+' 'NR==2{print $3}'`
Appid=`curl -s http://ip:8080/api/node/?search=$IP|sed -r 's#(.*"appid":)(.*)(,"zone".*)#\2#g'|tr -d '"'`
#打印当前时间
echo "#######################当前时间:$(date +%F\ %T)#######################"
#引用函数库
[ -f /etc/init.d/functions ] && source /etc/init.d/functions
#检查日志敏感信息
Chklog() {
#检查是否有手机号信息
#Phonechk=(`tail -5000 $ChkFile|sed -rn 's#(.*[^0-9])(1[3-9][0-9]{9})([^0-9].*)#\2#gp'|grep -Eo '1[3-9][0-9]{9}'`)
Phonechk=(`tail -5000 $ChkFile|grep -Eo '[^0-9]1[3-9][0-9]{9}[^0-9]'|sed -rn 's#(.*[^0-9])(1[3-9][0-9]{9})([^0-9].*)#\2#gp'`)
PhoneCont=`tail -5000 $ChkFile|grep -Enw "${Phonechk[0]}"|head -1`
#检查是否有身份证号信息
#IDchk=(`tail -5000 $ChkFile|sed -rn 's#(.*[^0-9])([1-9][0-9]{17}|[1-9][0-9]{16}[Xx])([^0-9].*)#\2#gp'|grep -Eo '[1-9][0-9]{17}|[1-9][0-9]{16}[Xx]'`)
IDchk=(`tail -5000 $ChkFile|grep -Eo '[^0-9][1-9][0-9]{17}[^0-9]|[^0-9][1-9][0-9]{16}[Xx][^0-9]'|sed -rn 's#(.*[^0-9])([1-9][0-9]{17}|[1-9][0-9]{16}[Xx])([^0-9].*)#\2#gp'`)
IDCont=`tail -5000 $ChkFile|grep -Enw "${IDchk[0]}"|head -1`
}
Postmsg() {
if [ -f $ChkFile ];then
Chklog
if [ -z "$Phonechk" -a -z "$IDchk" ];then
echo ''
else
msg_json='{"appid": "'$Appid'","ip": "'$IP'","filename": "'$ChkFile'","idnum": "'${IDchk[0]}'", "phone": "'${Phonechk[0]}'", "phoneinfo":"'$PhoneCont'","idinfo":"'$IDCont'"}'
curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: b5a360a8-38c7-466b-601a-584395b3c6a5" -d $msg_json \
"http://ip:8080/api/sensitive/"
fi
fi
}
func() {
ps -ef |grep java |grep 'weblogic'|grep -v 'auto' &>/dev/null
if [ $? -eq 0 ];then
web_file=$(/usr/sbin/lsof -p $(ps -ef|grep [w]eblogic|awk '/bloan/{print $2}')|awk '/out/{print $NF}'|head -1)
web_Array=('/wls/applogs/rtlog/app/rcpm.log' "$web_file" '/wls/applogs/rtlog/app/rcpm-common.log')
for ChkFile in ${web_Array[@]}
do
#echo $ChkFile
Postmsg
done
fi
Filepath='/wls/applogs/rtlog/rcpm_taskLog'
if [ -d $Filepath ];then
ls $Filepath/{*.out,*[^0-9].log}
if [ $? -eq 0 ];then
for ChkFile in `ls $Filepath/{*.out,*[^0-9].log}`
do
#echo $ChkFile
Postmsg
done
fi
fi
pafa_Array=('/bankapp/deploy/work/logs/app/pafa.log' '/bankapp/deploy/work/logs/app/console.log' '/bankapp/applogs/elastic-job/elastic-rcpm-job-worker/elastic-rcpm-job-worker.out')
for ChkFile in ${pafa_Array[@]}
do
#echo $ChkFile
Postmsg
done
}
func
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现