前言(Telebot)
在服务器的日常维护和蓝队的日常监控中,经常需要对服务器出现的各种问题进行及时的预警推送。国外的服务器推荐使用telebot
,python的简单用法如下:
import telebot
bot = telebot.TeleBot(token="522xxxx:xxxxxxxxxOY0")
bot.send_message(chat_id="xxxxxx",text="haha123")
走代理跑
proxychains4 python3 telebot.py
对于境外vps来说,telebot是最好不过的预警推送方式。但是由于国内复杂的网络环境,这显然是不合理的。
因此这里尝试使用bark
进行预警推送,虽然其功能较telebot
异常的简陋,但起到基础的消息推送功能还是没有问题的(更何况bark
还是免费开源的,相较telebot
配置更简单更无脑)。
正文(BARK)
先来看bark
的用法
bark用起来异常的简单,他会给每个账号提供私有ID,GET方式请求 加上一定量参数即可
如:
import requests
url = "https://api.day.app/6cPxxxxxxxxxxxF4/" #此处填入私有ID
def sendMessage(title,text,icon=""):
requests.get(f'{url+title}/{text}?icon={icon}')
sendMessage(title='Warning',text='Your server has been invaded',icon="https://th.bing.com/th/id/OIP.PnLgsfgLeK-s0mUrQOeonwAAAA?w=176&h=180&c=7&r=0&o=5&dpr=1.8&pid=1.7")
写个shell脚本,让每次终端连接时都执行,放到/etc/profile.d
中
#!/bin/bash
message="主机名:$(hostname) 时间:$(TZ=UTC-8 date) 登陆用户:$(whoami) 当前所有登陆用户:$(who) 其他信息:$(w|awk 'BEGIN{OFS=" "}{print $1,$8}')"
curl "https://api.day.app/6cxxxxxxxxxF4/警告/$(echo $message | sed 's/ /%20/g')?icon=https://th.bing.com/th/id/OIP.PnLgsfgLeK-s0mUrQOeonwAAAA?w=176&h=180&c=7&r=0&o=5&dpr=1.8&pid=1.7" &>/dev/null
这样,当某一个用户被远程登录连接时我们的手机就会收到实时的预警推送。通过魔改shell脚本可以实现各种很骚的操作