⛷️微信群黑产舆情采集实践
2024-7-21
| 2024-8-11
532  |  阅读时长 2 分钟
type
date
status
slug
summary
tags
category
password
icon
👀
工作需要对各类薅羊毛信息、黄牛动态进行捕捉,例如热门商品价格舆情,营销活动被攻击信息。而这类一手消息往往在各类社群中,特别是微信群。那么就需要实现对微信群信息进行采集、数据清洗、分析,设置预警。
本文简单记录下采集这一步的技术实现,对微信机器人等一番搜索并实践,发现共有两种方式可以完成信息采集,1是通过wechaty来实现,2是通过DLL注入PC端微信实现。效果演示,仅供参考:
notion image
notion image

一、Wechaty(长期使用不推荐,容易封号)

Wechaty 是一个开源的的对话机器人 SDK,支持 个人号 微信。它是一个使用Typescript 构建的Node.js 应用。
直接上代码,核心是index.js文件,通过nodejs运行生成登陆二维码,微信扫描授权即可接收个人消息与群聊消息,这里我只实现了群聊消息监听并自动转发至HttpServer进行后续处理。
// 初始化项目 init project // 新建一个文件夹,在这个文件夹的终端中,执行 `npm init -y` 生成 `package.json` 文件 // 新建 `index.js` 文件 // npm i wechaty 安装依赖 // npm i qrcode-terminal 生成二维码要用的包 // npm i axios const { WechatyBuilder } = require('wechaty'); const qrcode = require('qrcode-terminal'); const axios = require('axios'); class WeChaty { bot = null constructor() { this.bot = WechatyBuilder.build(); this.bot.on('scan', code => { qrcode.generate(code, { small: true }); }); this.bot.on('message', this.onMessage.bind(this)); } // 群聊信息测试 async onMessage(message) { // 添加 async 关键字 const contact = message.talker(); const text = message.text(); const room = message.room(); if (room) { // 若是群聊 const topic = await room.topic(); // 正确使用 await console.log(`Room: ${topic} Contact: ${contact.name()} Text: ${text}`); // 请求网址 http://127.0.0.1:5000 try { const response = await axios.post('http://127.0.0.1:5000/postmsg', { message: text, // 可根据实际情况调整发送的内容 timeout: 5000 // 设置超时时间为5000ms }); console.log('Message sent successfully', response.data); } catch (error) { console.error('Failed to send message', error); if (error.code === 'ECONNABORTED') { console.error('请求超时'); } else { console.error('请求失败', error); } } } else { console.log(`Contact: ${contact.name()} Text: ${text}`); contact.say('文本消息') } } // 单人信息测试 // const talker = message.talker(); // if(!talker.payload.friend || message.payload.roomId || talker.payload.type != 1) { // return; // } // if(message.payload.type != 7) { // talker.say("我只能处理文字消息,请发送文字内容"); // return; // } // const content = message.text(); // talker.say(`你好, 我收到了您发的消息 [${content}]`); // } run() { this.bot.start(); } } new WeChaty().run();
JavaScript

二、WeChatFerry

支持发送文本消息、图片、文件、XML、表情等,可以接收好友申请、添加群成员等功能,提供了RPC通信和间谍模块来实现微信消息的转发。
要注意版本与微信要一致,否则会失败,长期运行可以采购一台windows云服务器。
转发所有接受到的微信群消息到我搭建的flask服务端处理,代码如下:
from queue import Empty from threading import Thread import requests import json from wcferry import Wcf, WxMsg wcf = Wcf() print(wcf.get_user_info()) def processMsg(msg: WxMsg): if msg.from_group(): print(msg.roomid) print(msg.content) if msg.roomid == '442190051xx@chatroom': send_message_to_server(msg.roomid,msg.content) def send_message_to_server(roomid, content): url = 'http://127.0.0.1:5000/postmsg' # 修改为你的Flask服务器URL headers = {'Content-Type': 'application/json'} data = { 'roomid': roomid, 'content': content } response = requests.post(url, headers=headers, data=json.dumps(data)) if response.status_code == 200: print("Message sent successfully!") print("Response:", response.json()) else: print("Failed to send message. Status code:", response.status_code) print("Response:", response.text) def enableReceivingMsg(): def innerWcFerryProcessMsg(): while wcf.is_receiving_msg(): try: msg = wcf.get_msg() processMsg(msg) except Empty: continue except Exception as e: print(f"ERROR: {e}") wcf.enable_receiving_msg() Thread(target=innerWcFerryProcessMsg, name="ListenMessageThread", daemon=True).start() enableReceivingMsg() wcf.keep_running()
Python
因为微信群的消息都是杂乱的非结构化数据,所以接下来使用大模型数据清洗后存入数据库。或者直接将消息通过正则匹配关键词,结合公司内部IM产品或者飞书/钉钉/企微等机器人能力进行预警。
 
  • 瞎折腾
  • 风控
  • 如何找到被CDN隐藏的网站真实IP支付宝APP&小程序抓包方案
    Loading...
    目录