Webhook 是一种消息发送方式,表示如果发生了某个事件就往特定地址发送特定请求。借助这个特性可以实现诸如:
xray 使用选项 --webhook-output
可以关联 webhook
其中xray统一的响应格式为:
{
"type": "xxx",
"data": {}
}
漏洞信息
{
"type": "web_vuln",
"data": {
"create_time": 1604736253090,
"detail": {
"addr": "http://127.0.0.1:9000/xss/example1.php?name=hacker",
"extra": {
"param": {
"key": "name",
"position": "query",
"value": "pkbnekwkjhwzabxnfjwh"
}
},
"payload": "",
"snapshot": [
[
"GET /xxx",
"HTTP/1.1 200 OK"
]
]
},
"plugin": "xss/reflected/default",
"target": {
"params": [],
"url": "http://127.0.0.1:9000/xss/example1.php"
}
}
}
统计信息
{
"type": "web_statistic",
"data": {
"num_found_urls": 1,
"num_scanned_urls": 1,
"num_sent_http_requests": 3,
"average_response_time": 0,
"ratio_failed_http_requests": 0,
}
}
子域名消息格式
{
"type": "subdomain",
"data": {
"cname": [],
"domain": "example.com",
"extra": "",
"ip": [
{
"asn": "EDGECAST (ASN15133)",
"country": "北美洲 美国",
"ip": "93.184.216.34"
},
{
"asn": "EDGECAST (ASN15133)",
"country": "北美洲 美国",
"ip": "2606:2800:220:1:248:1893:25c8:1946"
}
],
"parent": "example.com",
"verbose_name": "initial",
"web": [
{
"link": "http://example.com/",
"server": "ECS (sjc/4FB8)",
"status": 200,
"title": "Example Domain"
},
{
"link": "https://example.com/",
"server": "ECS (sjc/4E8D)",
"status": 200,
"title": "Example Domain"
}
]
}
}
xray的文档中给出了一个简洁的webhook代码,借助于 Python 的 flask 框架,搭建web服务器
from flask import Flask, request
import requests
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def xray_webhook():
print(request.json)
return 'ok'
if __name__ == '__main__':
app.run()
使用
xray webscan --url http://testphp.vulnweb.com/listproducts.php?cat=1 --webhook-output http://127.0.0.1:5000/webhook
可以在终端看到扫描结果的json回显
下面是官网使用server酱的一个例子,其他平台的只要修改push_ftqq()函数中的内容,主要就是接口参数的不同
from flask import Flask, request
import requests
import datetime
import logging
app = Flask(__name__)
def push_ftqq(content):
resp = requests.post("https://sctapi.ftqq.com/{SECKEY}.send",
data={"text": "xray vuln alarm", "desp": content})
if resp.json()["data"]["errno"] != 0:
raise ValueError("push ftqq failed, %s" % resp.text)
@app.route('/webhook', methods=['POST'])
def xray_webhook():
data = request.json
typed = data["type"]
if typed == "web_statistic":
return 'ok'
vuln = data["data"]
content = """## xray find new vuln
url: {url}
plugin: {plugin}
create_time: {create_time}
""".format(url=vuln["detail"]["addr"], plugin=vuln["plugin"],
create_time=str(datetime.datetime.fromtimestamp(vuln["create_time"] / 1000)))
try:
push_ftqq(content)
except Exception as e:
logging.exception(e)
return 'ok'
if __name__ == '__main__':
app.run()
思考:1、xray的扫描数据都是以json数据形式传输,将json数据发送到webhook平台;2、webhook平台(server酱,gotify,机器人等等),收到请求后,解析json参数中的内容,然后进行消息的通知)
官网:https://gotify.net/
推荐docker安装
docker run -p 80:80 -v /var/gotify/data:/app/data gotify/server
或者下载可执行文件安装,github/releases
安装完成后,访问 http://ip:port/
可以访问到webui界面,账号密码 admin / admin
添加一个application,token后面要用
gotify 是C/S架构,这里安装的是server端,客户端是apk应用程序,安卓下载登录,url填server的url地址。