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


    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))
            
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
  • 相关阅读:
    小程序项目如何创建
    SpringBoot定时任务的动态配置处理(动态获取数据库配置的定时任务)
    conda pack迁移环境
    赛轮集团SAILUN方程式赛车轮胎震撼登场,开启新篇章
    基于二叉树的高效IP检索格式MMDB
    电子招标采购系统源码项目说明+开发类型+解决方案+功能描述
    真·Redis缓存优化—97%的优化率你见过嘛? | 京东云技术团队
    ~/.bashrc配置文件说明
    如何使用 LeiaPix 让照片动起来
    纯电动汽车杂谈
  • 原文地址:https://blog.csdn.net/u010418732/article/details/126339585