自制Python三方库API (钉钉消息推送接口)
字数 888 2025-08-11 00:55:05
Python三方库MAPI使用详解:钉钉消息推送与网络安全工具集
1. 概述
MAPI (Martin's API) 是一个多功能Python三方库,由maptnh开发,集成了多种实用功能,包括钉钉消息推送接口、爬虫工具、XSS攻击构造、Git操作等。本文档将详细介绍该库的各项功能及使用方法。
2. 安装与导入
安装方式
pip install MAPI
导入方式
# 导入整个库
import MAPI
# 或按需导入特定模块
from DingTalkPush import DingTalk
from Crawling_Spider_Collection import Crawling_Spider_Collection
from XSS_Construction import XSS_Construction
3. 钉钉消息推送接口(DingTalkPush)
3.1 初始化配置
from DingTalkPush import DingTalk
# 初始化(True开启回显,False关闭回显)
TK = DingTalk(True)
# 设置Token和Secret
TK.set_token('your_dingtalk_token') # 替换为你的钉钉机器人Token
TK.set_secret('your_dingtalk_secret') # 替换为你的钉钉机器人Secret
3.2 发送文本消息
TK.send_text('hello world') # 发送简单文本消息
3.3 发送带图片的文本消息
TK.send_pic(
message='Hello', # 消息内容
picture='https://example.com/image.png', # 图片URL
title='maptnh', # 标题
link='https://www.freebuf.com' # 超链接地址
)
4. 爬虫接口(Crawling_Spider_Collection)
4.1 基本用法
from Crawling_Spider_Collection import Crawling_Spider_Collection
Crawling_Spider = Crawling_Spider_Collection()
# 示例:爬取电影票房数据
for i1 in range(2,4):
for i2 in range(1,13):
print(Crawling_Spider.draw(
f'https://www.48971.com/category-2_{i1}.html',
f'/html/body/div[1]/div[2]/div/div[2]/div/ul/li[{i2}]/div[2]/a'
)[-1])
5. XSS攻击构造接口(XSS_Construction)
5.1 URL_Method方法(Location.hash攻击)
from XSS_Construction import XSS_Construction
XSS = XSS_Construction()
url, hand, auto = XSS.URL_Method(
'http://127.0.0.1/index.php',
'window.location.href = \'http://www.baidu.com\';'
)
print("手动触发URL地址:" + url)
print("手动触发Payload:" + hand)
print("自动触发Payload:" + auto)
5.2 Fake_Method方法(data伪协议)
print(XSS.Fake_Method("<script>alert('Martin')</script>"))
5.3 图片劫持方法
paylaod, path = XSS.Image_hijacking_Method(
'http://192.168.101.128/cat/cat/61.147.171.105_55557/index.php',
"./hk.gif"
)
print("XSS-Payload:" + paylaod)
print("path:" + path)
6. Git操作接口(GitAction)
6.1 基本用法
from GitAction import GitAction
git = GitAction() # GitAction(False)可关闭回显
# 推送代码到远程仓库
git.push(
remotegit='https://github.com/xxxxxxx/xxxxxxxx.git', # 远程仓库地址
path='G:\\Github\\xxxx', # 本地路径
token='github_pat_xxxxx', # GitHub Token
branch='master', # 分支名
commit='helki' # 提交信息
)
6.2 获取GitHub Token
- 登录GitHub帐户
- 点击个人资料照片 → "Settings"
- 左侧导航选择"Developer settings"
- 选择"Personal access tokens" → "Generate new token"
- 为token命名并选择权限(建议全部设为"Read and Write")
- 生成并复制token
7. 随机User-Agent接口
from Random_User_Agent import Random_User_Agent
rand = Random_User_Agent()
print(rand.Random_UA()) # 获取随机User-Agent
8. 请求报文处理接口
from Processing_messages import Processing_messages
Header = '''GET /api.php?key=free&appid=0&msg=<Martin>&_=1681129500299 HTTP/1.1
Host: api.qingyunke.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Connection: keep-alive
Referer: http://api.qingyunke.com/'''
pag = Processing_messages()
url, stat, message, header = pag.Main('http', Header, '<Martin>', '你好')
print(f"URL[{stat}]:{url}\nComment:{message}\nRespon_Header:{header}")
9. 注意事项
- 使用API类前必须导入该包
- 爬虫接口目前只能爬取服务端渲染后的数据
- XSS构造工具仅限合法授权测试使用
- 钉钉机器人需要正确配置Token和Secret才能正常工作
- GitHub操作需要有效的Personal Access Token
10. 资源链接
- GitHub仓库: https://github.com/MartinxMax/MAPI
- GitPush工具下载: https://github.com/MartinxMax/GitPush
- GitPush教程: http://t.csdn.cn/dPdSm