希望可以上调WAF拦截记录中每一页显示的上限

比如上调到每页显示1000条

目前在用脚本批量拉黑,上调到每页显示数量后可以减少接口请求次数,效率更高

脚本附后:

import base64
import requests
from tqdm import tqdm

HOST = "127.0.0.1:12345"   # ip:post 或者域名
ENTRANCECODE = ""     # 安全入口
USERNAME = ""         # 用户名
PASSWORD = ""         # 密码
HEADERS = {}

def login():
    global HEADERS
    url = f"http://{HOST}/api/v1/auth/login"
    payload = {
        "name": USERNAME,
        "password": PASSWORD,
        "ignoreCaptcha": True,
        "authMethod": "session",
        "language": "zh"
    }
    headers = {
        "EntranceCode": base64.b64encode(ENTRANCECODE.encode()).decode(),
        "content-type": "application/json"
    }
    response = requests.post(url, json=payload, headers=headers)
    HEADERS = {"Cookie": f"psession={response.cookies['psession']}","content-type": "application/json"}

def get_waf_log():
    url = f"http://{HOST}/api/v1/waf/log/search"
    payload = {"page": 1,"pageSize": 100,"total": 0,"ip": "","url": "","websiteKey": "","execRules": []}
    response = requests.post(url, json=payload, headers=HEADERS)
    total = response.json()['data']['total']
    total_page = int(total/100 if total%100 == 0 else (total/100)+1)

    black_list = []
    for page in tqdm(range(1, total_page+1), desc="正在读取拦截记录", unit = " 页"):
        payload['page'] = page
        response = requests.post(url, json=payload, headers=HEADERS)
        items = response.json()['data']['items']
        for item in items:
            if item['isBlack'] == False:
                black_list.append(item['ip'])
    return list(set(black_list))

def add_black_list(black_list):
    url = f"http://{HOST}/api/v1/waf/ip/default"
    payload = {"ip": "","type": "black"}
    line = 1
    msg = ""
    for ip in tqdm(black_list, desc=f"正在添加黑名单"):
        payload['ip'] = ip
        response = requests.post(url, json=payload, headers=HEADERS)
        msg += f"添加黑名单 {ip} {response.json()['message']}\n"
        print(f"{msg}{'\033[F' * (line+1)}\r", end="")
        line += 1
    print(f'{"\n" * ((line - 3) if line > 3 else 0)}')

def main():
    login()
    black_list = get_waf_log()
    add_black_list(black_list)

if __name__ == "__main__":main()