【CTF机器人】文件头字节查询(Nonebot2+CQHTTP)

12 篇文章 0 订阅
5 篇文章 1 订阅
import requests
from bs4 import BeautifulSoup
from nonebot import on, on_command
from nonebot.rule import to_me
from nonebot.matcher import Matcher
from nonebot.adapters import Message
from nonebot.params import Arg, CommandArg, ArgPlainText
from nonebot.adapters.onebot.v11 import Message, MessageSegment
import asyncio
headers = {
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  'Cache-Control': 'max-age=0',
  'Connection': 'keep-alive',
  'Cookie': 'PHPSESSID=lj0tsuf8poheud74qbbgp8o4c4',
  'Sec-Fetch-Dest': 'document',
  'Sec-Fetch-Mode': 'navigate',
  'Sec-Fetch-Site': 'none',
  'Sec-Fetch-User': '?1',
  'Upgrade-Insecure-Requests': '1',
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53',
  'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="101", "Microsoft Edge";v="101"',
  'sec-ch-ua-mobile': '?0',
  'sec-ch-ua-platform': '"Windows"'
}
payload = {}
searchfileform = on_command('searchfileform', aliases={'查询文件头', '文件头'}, priority=5)
@searchfileform.handle()
async def searchfileform_(matcher: Matcher, args: Message = CommandArg()):
    houzhuiming = args.extract_plain_text()
    if houzhuiming:
        try:
            url = "https://filesignatures.net/index.php?page=search&search={0}&mode=EXT".format(houzhuiming)
            response = requests.request("GET", url, headers=headers, data=payload)
            soup = BeautifulSoup(response.text, 'html.parser')
            selector = soup.select('#results > a')
            text = "[+] 查询成功!"+Message('[CQ:face,id=324]')+"\n[+] 文件后缀为:"+selector[0].get_text()+"\n[+] 文件头为:"+selector[1].get_text()
            await matcher.send(text)
        except Exception as e:
            await matcher.send("[-] 查询失败!"+Message('[CQ:face,id=173]')+"\n[-] "+str(e))

re_searchfileform = on_command('re_searchfileform', aliases={'反查文件头'}, priority=5)
@re_searchfileform.handle()
async def re_searchfileform_(matcher: Matcher, args: Message = CommandArg()):
    qianzhui = args.extract_plain_text()
    url = "https://filesignatures.net/index.php?search={0}&mode=SIG".format(qianzhui.strip(' '))
    if qianzhui:
        try :
            response = requests.request("GET", url, headers=headers, data=payload)
            soup = BeautifulSoup(response.text, 'html.parser')
            selector = soup.select('#results > a')
            #只打印奇数位
            text = ''
            for i in range(0,len(selector),2):
                #text逗号分割
                text = text+selector[i].get_text()+","   
            if text:
                text = text[:-1]
                text = "[+] 查询成功!"+Message('[CQ:face,id=324]')+"\n[+] 可能的文件类型为:\n"+text    
                await matcher.send(text)
            else:
                await matcher.send("[-] 查询失败!"+Message('[CQ:face,id=173]'))
        except Exception as e:
            await matcher.send("[-] 查询失败!"+Message('[CQ:face,id=173]')+"\n[-] "+str(e))
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值