2025-03-30 22:49:37 +08:00
|
|
|
|
import base64
|
|
|
|
|
|
import json
|
|
|
|
|
|
import os.path
|
|
|
|
|
|
import random
|
2025-04-03 22:44:22 +08:00
|
|
|
|
import threading
|
2025-03-30 22:49:37 +08:00
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
from loguru import logger
|
|
|
|
|
|
from sqlmodel import Session, select
|
|
|
|
|
|
|
2025-03-28 18:23:30 +08:00
|
|
|
|
from .base import BaseReporter
|
2025-03-30 22:49:37 +08:00
|
|
|
|
from ...config.config import AppCtx
|
|
|
|
|
|
from ...models.report_urls import ReportUrlModel
|
|
|
|
|
|
from ...utils.common import get_proxies, get_all_cookies, md5
|
2025-04-01 22:53:32 +08:00
|
|
|
|
from ...utils.gen_cookie import GenCookie
|
2025-03-30 22:49:37 +08:00
|
|
|
|
from ...utils.ua import random_ua
|
|
|
|
|
|
|
2025-03-28 18:23:30 +08:00
|
|
|
|
|
|
|
|
|
|
class WapReporter(BaseReporter):
|
|
|
|
|
|
def __init__(self):
|
2025-03-30 22:49:37 +08:00
|
|
|
|
|
|
|
|
|
|
self.engine_name = "WAP_REPORTER"
|
2025-04-03 22:44:22 +08:00
|
|
|
|
self.status = 1
|
|
|
|
|
|
self.ev = threading.Event()
|
2025-03-30 22:49:37 +08:00
|
|
|
|
|
|
|
|
|
|
self.report_url = "https://ufosdk.baidu.com/api?m=Client&a=postMsg"
|
|
|
|
|
|
self.request = requests.session()
|
|
|
|
|
|
self.proxies = get_proxies()
|
|
|
|
|
|
self.headers = {
|
|
|
|
|
|
'Sec-Fetch-Dest': 'empty',
|
|
|
|
|
|
'Sec-Fetch-Mode': 'cors',
|
|
|
|
|
|
'Sec-Fetch-Site': 'same-origin',
|
|
|
|
|
|
'User-Agent': random_ua(is_wap=True),
|
|
|
|
|
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
|
|
|
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7,zh-TW;q=0.6',
|
|
|
|
|
|
'sec-ch-ua_wap': '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
|
|
|
|
|
|
'sec-ch-ua_wap-mobile': '?0',
|
|
|
|
|
|
'sec-ch-ua_wap-platform': '"Windows"',
|
|
|
|
|
|
"Cookie": "",
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self.database = AppCtx.g_db_engine
|
|
|
|
|
|
self.all_cookies = get_all_cookies()
|
2025-03-28 18:23:30 +08:00
|
|
|
|
|
2025-04-03 22:44:22 +08:00
|
|
|
|
def stop(self):
|
|
|
|
|
|
self.status = 0
|
|
|
|
|
|
self.ev.set()
|
2025-04-04 17:29:50 +08:00
|
|
|
|
logger.warning(f"{self.engine_name} 收到退出消息,等待当前任务完成后退出")
|
2025-04-03 22:44:22 +08:00
|
|
|
|
|
2025-03-28 18:23:30 +08:00
|
|
|
|
def run(self):
|
|
|
|
|
|
"""实现 WAP 端的举报逻辑"""
|
2025-03-30 22:49:37 +08:00
|
|
|
|
with Session(self.database) as session:
|
|
|
|
|
|
stmt = select(ReportUrlModel).where(ReportUrlModel.is_report_by_wap == False)
|
|
|
|
|
|
rows: list[ReportUrlModel] = session.exec(stmt).all()
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug(f"[{self.engine_name}] 共找到 {len(rows)} 条待举报记录")
|
|
|
|
|
|
|
|
|
|
|
|
for row in rows:
|
|
|
|
|
|
|
2025-04-03 22:44:22 +08:00
|
|
|
|
if not self.status:
|
|
|
|
|
|
break
|
|
|
|
|
|
|
2025-03-30 22:49:37 +08:00
|
|
|
|
# 选个 cookie
|
|
|
|
|
|
report_cookie = random.choice(get_all_cookies())
|
2025-04-01 22:53:32 +08:00
|
|
|
|
report_site_cookie = GenCookie.run(report_cookie)
|
|
|
|
|
|
self.headers["Cookie"] = report_site_cookie
|
|
|
|
|
|
self.headers["User-Agent"] = random_ua()
|
2025-03-30 22:49:37 +08:00
|
|
|
|
logger.debug(f"{report_cookie=}")
|
|
|
|
|
|
|
|
|
|
|
|
# 获取用户信息
|
|
|
|
|
|
userinfo = self.get_user_info()
|
|
|
|
|
|
if not userinfo:
|
|
|
|
|
|
logger.warning(f"[{self.engine_name}] 跳过 {row.surl} 的举报,userinfo 获取失败")
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
# 举报
|
|
|
|
|
|
img_path = f"./imgs/{row.domain}/{md5(row.surl)}.png"
|
|
|
|
|
|
if not os.path.exists(img_path):
|
|
|
|
|
|
logger.error(f"截图文件 {img_path} 不存在")
|
|
|
|
|
|
continue
|
|
|
|
|
|
result = self.do_report(userinfo, img_path, row.surl, row.q)
|
|
|
|
|
|
if result:
|
|
|
|
|
|
row.is_report_by_wap = True
|
|
|
|
|
|
session.add(row)
|
|
|
|
|
|
session.commit()
|
|
|
|
|
|
|
2025-04-03 22:44:22 +08:00
|
|
|
|
self.ev.wait(5)
|
2025-03-30 22:49:37 +08:00
|
|
|
|
|
|
|
|
|
|
def get_user_info(self):
|
|
|
|
|
|
try:
|
|
|
|
|
|
userinfo = {}
|
|
|
|
|
|
# wapUserAgent = random.choice(self.wapUserAgent)
|
|
|
|
|
|
response = self.request.get(
|
|
|
|
|
|
"https://ufosdk.baidu.com/api?m=Web&a=getUserInfo&appid=293852",
|
2025-04-01 22:53:32 +08:00
|
|
|
|
headers=self.headers, proxies=self.proxies, allow_redirects=False, timeout=10, verify=False
|
2025-03-30 22:49:37 +08:00
|
|
|
|
)
|
|
|
|
|
|
json_data = response.json()
|
2025-04-07 10:11:22 +08:00
|
|
|
|
logger.debug(f"{self.engine_name} get_user_info response: {json_data}")
|
2025-03-30 22:49:37 +08:00
|
|
|
|
uid = json_data['result']['uid']
|
|
|
|
|
|
un = json_data['result']['un']
|
|
|
|
|
|
userinfo["uid"] = uid
|
|
|
|
|
|
userinfo["un"] = un
|
2025-04-01 22:53:32 +08:00
|
|
|
|
logger.debug(f"{userinfo=}")
|
2025-03-30 22:49:37 +08:00
|
|
|
|
return userinfo
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"[{self.engine_name}]获取用户信息错误: {e}")
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def do_report(self, userinfo: dict, img_path: str, fb_url: str, extend_query: str):
|
|
|
|
|
|
|
|
|
|
|
|
# 组装 extra 数据
|
|
|
|
|
|
with open(img_path, "rb") as fp:
|
|
|
|
|
|
img_data = fp.read()
|
|
|
|
|
|
img_data = base64.b64encode(img_data).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
extra_string_data = {
|
|
|
|
|
|
"ufo_app_version": "3.0",
|
|
|
|
|
|
"feedback_position": "0",
|
|
|
|
|
|
"extend_query": extend_query,
|
|
|
|
|
|
"resource_id": "1599",
|
|
|
|
|
|
"feedback_source": "其他",
|
|
|
|
|
|
"feedback_source_text": "其他",
|
|
|
|
|
|
"extend_url": f"https://wap.baidu.com/s?word=url:{fb_url}",
|
|
|
|
|
|
"fb_url": fb_url,
|
|
|
|
|
|
"extend_feedback_channel": "36923",
|
|
|
|
|
|
"relation_words": "",
|
|
|
|
|
|
"industry_one": "30",
|
|
|
|
|
|
"industry_two": "197",
|
|
|
|
|
|
"user": userinfo["un"],
|
|
|
|
|
|
"baiducuid": ""
|
|
|
|
|
|
}
|
2025-03-28 18:23:30 +08:00
|
|
|
|
|
2025-03-30 22:49:37 +08:00
|
|
|
|
post_data = {
|
|
|
|
|
|
"appid": "293852",
|
|
|
|
|
|
"content": f"{fb_url} 存在大量色情淫秽信息",
|
|
|
|
|
|
"uid": userinfo["uid"],
|
|
|
|
|
|
"uname": userinfo["un"],
|
|
|
|
|
|
"ajax": "1",
|
|
|
|
|
|
"submit_type": "1",
|
|
|
|
|
|
"extend_feedback_channel": "0",
|
|
|
|
|
|
"baiducuid": "",
|
|
|
|
|
|
"extend_url": "",
|
|
|
|
|
|
"extrastring": json.dumps(extra_string_data, ensure_ascii=False),
|
|
|
|
|
|
"screenshot[]": f"data:image/png;base64,{img_data}"
|
|
|
|
|
|
}
|
2025-03-28 18:23:30 +08:00
|
|
|
|
|
2025-03-30 22:49:37 +08:00
|
|
|
|
response = self.request.post(
|
|
|
|
|
|
self.report_url,
|
|
|
|
|
|
data=post_data,
|
|
|
|
|
|
headers=self.headers,
|
|
|
|
|
|
proxies=self.proxies,
|
|
|
|
|
|
allow_redirects=False,
|
2025-04-01 22:53:32 +08:00
|
|
|
|
timeout=10,
|
|
|
|
|
|
verify=False
|
2025-03-30 22:49:37 +08:00
|
|
|
|
)
|
|
|
|
|
|
# logger.debug(req.json())
|
|
|
|
|
|
logger.debug(response.json())
|
|
|
|
|
|
if response.json()['errno'] == 0:
|
|
|
|
|
|
logger.success(f"[{self.engine_name}] {fb_url} 举报成功")
|
|
|
|
|
|
return True
|
|
|
|
|
|
return False
|