xray + docker + Mac notification + Other

admin 2023年5月29日09:04:26评论21 views字数 4770阅读15分54秒阅读模式

内容多且杂,具体做了下面几个事情:

  1. 编写dockerfile将xray和一些脚本放入了docker中

  2. 为xray的Web Vulnerabilities页面加上了401认证

  3. xray扫到漏洞时,mac右上角会有通知

编写Dockerfile

FROM arm64v8/ubuntu:20.04
ADD sources.list /etc/apt
RUN apt-get update
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN apt-get install -y vim
RUN python3 -m pip install --upgrade pip
RUN pip3 install Flask flask-httpauth passlib requests

WORKDIR /app

VOLUME /app/data

COPY . .

RUN chmod +x /app/xray_linux_arm64
RUN chmod +x /app/sh.sh
EXPOSE 5000
EXPOSE 65532

CMD python3 app.py & /app/sh.sh

这里暴露了5000和65532,前者为flask的服务端口,用来访问xray的结果,后者为xray的监听端口。

sh.sh文件

#!/bin/bash

ARCH=$(uname -m)

if [ "$ARCH" = "aarch64" ]; then
    # 当系统架构是 aarch64 时运行 xxx
    TIMESTAMP=$(date +%s)
    echo $TIMESTAMP
    /app/xray_linux_arm64 ws webscan --listen 0.0.0.0:65532 --webhook-output http://127.0.0.1:5000/webhook --html-output ./vuln/$TIMESTAMP.html 
elif [ "$ARCH" = "x86_64" ]; then
    # 当系统架构是 amd64 时运行 999
    TIMESTAMP=$(date +%s)
    /app/xray_linux_amd64 ws webscan --listen 0.0.0.0:65532 --webhook-output http://127.0.0.1:5000/webhook --html-output ./vuln/$TIMESTAMP.html 
else
    # 其它情况下输出错误信息
    echo "Unsupported architecture: $ARCH"
fi

app.py

from flask import Flask, request, Response, send_from_directory, render_template
from functools import wraps
import os,datetime,requests,json

app = Flask(__name__)
app.config['BASIC_AUTH_USERNAME'] = 'user'
app.config['BASIC_AUTH_PASSWORD'] = 'pass'

def check_auth(username, password):
    return username == app.config['BASIC_AUTH_USERNAME'and password == app.config['BASIC_AUTH_PASSWORD']

def authenticate():
    return Response(
        'Please enter your username and password to access this page.'
        401
        {'WWW-Authenticate''Basic realm="Login Required"'}
    )

def requires_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            return authenticate()
        return f(*args, **kwargs)
    return decorated


@app.route('/html_files')
@requires_auth
def list_html_files():
    # 获取当前路径
    current_path = os.getcwd()

    # 获取当前路径下的所有文件名
    files = os.listdir(current_path + "/vuln/")

    # 获取所有的 HTML 文件
    html_files = 

    # 渲染 HTML 模板并返回
    return render_template('html_files.html', html_files=html_files)

@app.route('/read_file/<filename>')
@requires_auth
def read_file(filename):
    # 获取当前路径
    current_path = os.getcwd()

    files = os.listdir(current_path + "/vuln/")
    html_files = 

    for x in html_files:
        file_path = os.path.join(current_path + "/vuln/", filename)

        # 打开文件并读取内容
        with open(file_path, 'r'as f:
            content = f.read()

        # 返回文件内容
        return content

    return 'GUN!'

def push_notion(content):
    headers = {"Content-Type""application/json"}
    resp = requests.post("http://物理机IP:65000/notify",data=json.dumps({"text""xray vuln alarm""desp": content}), headers=headers)

@app.route('/webhook', methods=['POST'])
def xray_webhook():
    data = request.json
    vuln = data["data"]
    if "ratio_progress" in vuln:
        return "ok"
    elif "sensitive/server-error" in vuln["plugin"]:
        return "ok"
    elif "baseline" in vuln["plugin"]:
        return "ok"
    content = """
url: {url}
poc/vuln: {plugin}
time: {create_time}
"""
.format(url=vuln["target"]["url"], plugin=vuln["plugin"], create_time=str(datetime.datetime.fromtimestamp(vuln["create_time"] / 1000)))
    #print(vuln["target"]["url"])
    try:
        push_notion(content)
        print("send-end")
    except Exception as e:
        print(e)
    return 'ok'

if __name__ == '__main__':
    app.run(host="0.0.0.0",port=5000)

这个脚本进行了如下操作:

  1. 列当前文件夹内所有html文件

  2. 读取文件

  3. 发送消息

  4. 为某些接口增加了401认证

mac的通知

import requests
import objc
from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
from flask import Flask, request,jsonify
# 发送任务完成通知
def send_notification(title, subtitle, message):
    notification = NSUserNotification.alloc().init()
    notification.setTitle_(title)
    notification.setSubtitle_(subtitle)
    notification.setInformativeText_(message)
    notification.setSoundName_("NSUserNotificationDefaultSoundName")

    center = NSUserNotificationCenter.defaultUserNotificationCenter()
    center.deliverNotification_(notification)

# 获取网页响应内容
app = Flask(__name__)

@app.route('/notify', methods=['POST'])
def receive_notification():
    try:
        data = request.get_json()
        send_notification(data['text'], "", data['desp'])
        return jsonify({'success'True})
    except Exception as e:
        print(e)
        return e

if __name__ == '__main__':
    app.run(host="0.0.0.0",port=65000)

跑起来看看

docker

xray + docker + Mac notification + Other

401 认证

xray + docker + Mac notification + Other

漏洞目录

xray + docker + Mac notification + Other

读文件

xray + docker + Mac notification + Other

mac 通知

xray + docker + Mac notification + Other

代码可能存在问题,斟酌使用。


原文始发于微信公众号(Right or wr0ng):xray + docker + Mac notification + Other

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年5月29日09:04:26
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   xray + docker + Mac notification + Otherhttps://cn-sec.com/archives/1767093.html

发表评论

匿名网友 填写信息