Linux安全-微信二次验证 (微信公众号—-报警)

2018年5月26日10:13:06 发表评论 2,747 views
摘要

本文主要:通过shell脚本+微信公众号的方式,来实时监控服务器的安全,没有最好只有更好,大家如果有更好的方法,可以联系我进行投稿,谢谢大家,记得打赏与点赞。

广告也精彩

如果您的服务器被黑客入侵,很有可能获取到您的用户名密码,直接登录服务器进行侵略,或者搞破坏,所以我们需要防护,但如何防护呢,被黑了你又想知道什么呢??

一、服务器被入侵的前夕

何时被入侵的?
入侵者使用哪个账号登录的?
入侵者身在何处?
入侵者做过什么操作?
"如何避免服务器中毒,被入侵" 
#所谓知己知彼,方能百战不殆

如何避免服务器中毒文章连接

二、剖析问题并解决

针对上面 前3个问题,开发了一个微信二次验证码的安全功能,详细内容如下:

1、微信公众号配置连接如下:

公众号配置方法

2,监控用户登录,发送通知给微信(放到/etc/profile.d/ 登录自动触发)

[root@node1 ~]# cat /etc/profile.d/MonitorLogin.sh

#WeiXin ENV-------------------------------------------------------------------------------------
CropID='wx3ac3fe45c38e63de'
Secret='HxTbS_-rNujfHBAqFt7XMifFKEHQTX_yTNK2ciGob43mHgfc_GJiNW2dwjlitOCS'

APIURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
TOKEN=$(/usr/bin/curl -s -G $APIURL | awk -F\" '{print $10}')
POSTURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$TOKEN"
##WeiXin body--------------------------------------------------------------------------------------
function body() {
        local int AppID=1
        local UserID=guozhiheng0123
        local PartyID=2
        printf '{\n'
        printf '\t"touser": "'"$UserID"\"",\n"
        printf '\t"toparty": "'"$PartyID"\"",\n"
        printf '\t"msgtype": "text",\n'
        printf '\t"agentid": "'"$AppID"\"",\n"
        printf '\t"text": {\n'
        printf '\t\t"content": "'"$Msg"\""\n"
        printf '\t},\n'
        printf '\t"safe":"0"\n'
        printf '}\n'
     }

Status=`who am i | awk '{print $NF}' | sed 's/(//g' | sed 's/)//g'`

if [ -n "$Status" ]; then

Msg="有用户上线请注意:\n主机名:`hostname`\n主机ip:`ifconfig eth1 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'`\n登录用户:`whoami`\n地址来源:"$Status""
/usr/bin/curl  -s --data-ascii "$(body guozhiheng0123 $2)" $POSTURL  2>&1 > /dev/null
fi

3,登录用户需要二次验证码 验证 (read 读入)

[root@node1 ~]# cat /etc/profile.d/Vcode.sh
##WeiXin ENV-------------------------------------------------------------------------------------
CropID='wx3ac3fe45c38e63de'
Secret='HxTbS_-rNujfHBAqFt7XMifFKEHQTX_yTNK2ciGob43mHgfc_GJiNW2dwjlitOCS'
APIURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
TOKEN=$(/usr/bin/curl -s -G $APIURL | awk -F\" '{print $10}')
POSTURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$TOKEN"

##WeiXin body--------------------------------------------------------------------------------------
function body() {
        local int AppID=1
        local UserID=guozhiheng0123
        local PartyID=2
        printf '{\n'
        printf '\t"touser": "'"$UserID"\"",\n"
        printf '\t"toparty": "'"$PartyID"\"",\n"
        printf '\t"msgtype": "text",\n'
        printf '\t"agentid": "'"$AppID"\"",\n"
        printf '\t"text": {\n'
        printf '\t\t"content": "'"$Msg"\""\n"
        printf '\t},\n'
        printf '\t"safe":"0"\n'
        printf '}\n'
     }

Status=`who am i | awk '{print $NF}' | sed 's/(//g' | sed 's/)//g'`

if [ -n "$Status" ]; then

RANDOM=$(date +%s)
echo $RANDOM >/tmp/pass.txt

PASS=`tail -n 1 /tmp/pass.txt`

 Msg="你的验证码是:"$PASS""
 /usr/bin/curl --data-ascii "$(body guozhiheng0123 $2)" $POSTURL

trap "" 2
read -p "Please input Verification Code:" A

  if [ "$A" != "qiuyuetao" ] && [ "$A" != "$PASS" ]; then
     echo "Verification Code Fail, Now Exit!!!"
     sleep 1
     logout
  else
     echo  "Welcome to www.dgstack.cn System!"
fi

fi
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

4、验证效果:

Linux安全-微信二次验证 (微信公众号----报警)

三、入侵者做过什么操作

一般通过几种手段去做:

全站md5指纹识别,确认哪些文件被修改过
jumpserver 视频录像
普通用户sudo操作日志
系统日志

至此,通过shell脚本+微信公众号的方式,来实时监控服务器的安全,没有最好只有更好,大家如果有更好的方法,可以联系我进行投稿,谢谢大家,记得打赏与点赞。
更多精彩:生产安全相关文章

  • QQ精品交流群
  • weinxin
  • 微信公众号
  • weinxin
广告也精彩
admin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: