生命在于学习——初识pocsuite3框架

在这里插入图片描述
本篇文章记录的是pocsuite3框架,仅用于学习记录交流,不得用作其他用途。

一、pocsuite3介绍

1、pocsuite3是什么?

pocsuite3 是由Knownsec 404 团队开发的开源远程漏洞测试和概念验证开发框架。它配备了强大的概念验证引擎,为终极渗透测试人员和安全研究人员提供了许多不错的功能。并且该工具被kali收录到系统自带工具

2、为什么要使用它

按照框架的开发规范编写的poc更加的标准
pocsuite3内部帮助我们解决了并发的问题 , 支持多线程检测 , 就不用自己考虑线程的问题了
pocsuite3集合了常见的网络测绘引擎的api , 更方便我们批量检测 , 可以直接和fofa语句联动

特点:

PoC 脚本可以在 verify, attack, shell 模式下以不同的方式运行
插件生态系统
从任何地方(本地文件、redis、数据库、Seebug ...)动态加载 PoC 脚本
从任何地方加载多目标(CIDR、本地文件、redis、数据库、Zoomeye、Shodan fofa ...)
结果可以轻松导出
动态补丁和钩子请求
命令行工具和python包导入都可以使用
IPV6 支持
全球 HTTP/HTTPS/SOCKS 代理支持
用于 PoC 脚本的简单蜘蛛 API
与Seebug集成(用于从 Seebug 网站加载 PoC)
与ZoomEye集成(用于从 ZoomEye 加载目标Dork)
与Shodan集成(用于从 Shodan 加载目标Dork)
与Ceye集成(用于验证盲 DNS 和 HTTP 请求)
与Interactsh集成(用于验证盲 DNS 和 HTTP 请求)
与 Fofa 集成(用于从 Fofa 加载目标Dork)
使用 IDE 的友好调试 PoC 脚本

3、pocsuite3如何使用?

下载
安装
常见参数详情
常见使用示例
源码阅读
简单的二开

二、下载安装和卸载

项目地址:https://github.com/knownsec/pocsuite3
环境:
Python 3.7+
Works on Linux, Windows, Mac OSX, BSD, etc.
pip安装

pip3 install pocsuite3

# use other pypi mirror
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pocsuite3

安装好的测试:
在这里插入图片描述
卸载
如果是pip3安装:pip3 uninstall pocsuite3
如果是git clone安装:pip3 uninstall pocsuite3

三、使用参考

官方文档:
https://github.com/knownsec/pocsuite3/blob/master/docs/USAGE.md

D:\pocsuite -h

,------.                        ,--. ,--.       ,----.   {1.9.2-nongit-20220415}
|  .--. ',---. ,---.,---.,--.,--`--,-'  '-.,---.'.-.  |
|  '--' | .-. | .--(  .-'|  ||  ,--'-.  .-| .-. : .' <
|  | --'' '-' \ `--.-'  `'  ''  |  | |  | \   --/'-'  |
`--'     `---' `---`----' `----'`--' `--'  `----`----'   https://pocsuite.org
usage: pocsuite [options]

optional arguments:
  -h, --help            # 查看帮助信息
  --version             # 查看版本
  --update             # 更新pocsuite3版本
  -v {0,1,2,3,4,5,6}    Verbosity level: 0-6 (default 1)

Target: # 目标
  At least one of these options has to be provided to define the target(s)

  -u URL [URL ...], --url URL [URL ...]   # 单个目标 
                        Target URL (e.g. "http://www.site.com/vuln.php?id=1")
  -f URL_FILE, --file URL_FILE   # 批量检测目标 , 每一行是一个url, 即一个目标
                        Scan multiple targets given in a textual file
  -r POC [POC ...]         # 加载poc文件 , 可以是本地或者远程的seebug
  -k POC_KEYWORD    Filter PoC by keyword, e.g. ecshop    # 按照poc关键字筛选
  -c CONFIGFILE         Load options from a configuration INI file  # 从配置INI文件加载选项

Mode: # 模式
  Pocsuite running mode options

  --verify              Run poc with verify mode      # poc验证模式
  --attack              Run poc with attack mode    # poc攻击模式
  --shell               Run poc with shell mode        # poc反弹shell模式

Request:  # 请求
  Network request options  # 网络请求选项 , 检测的本质也是发请求, 可以自定义一些请求头

  --cookie COOKIE       HTTP Cookie header value  
  --host HOST           HTTP Host header value
  --referer REFERER     HTTP Referer header value
  --user-agent AGENT    HTTP User-Agent header value (default random)
  --proxy PROXY         Use a proxy to connect to the target URL
  --proxy-cred PROXY_CRED
                        Proxy authentication credentials (name:password)   # 代理需要认证
  --timeout TIMEOUT     Seconds to wait before timeout connection (default 30)
  --retry RETRY         Time out retrials times # 超时, 重试次数
  --delay DELAY         Delay between two request of one thread   # 一个线程的两个请求之间的延迟
  --headers HEADERS     Extra headers (e.g. "key1: value1\nkey2: value2")  # 请求头

Account: # 账号
  Telnet404, Shodan, CEye, Fofa account options

  --login-user LOGIN_USER   # 404账号
                        Telnet404 login user
  --login-pass LOGIN_PASS  # 404密码
                        Telnet404 login password
  --shodan-token SHODAN_TOKEN  # 撒旦账号的token
                        Shodan token
  --fofa-user FOFA_USER     # fofa账号
                        fofa user
  --fofa-token FOFA_TOKEN  # fofa 账号的token
                        fofa token
  --quake-token QUAKE_TOKEN # quake账号的token
                        quake token
  --censys-uid CENSYS_UID # censys 账号的uid
                        Censys uid
  --censys-secret CENSYS_SECRET  # censys 账号的secret
                        Censys secret

Modules: # 模块 , 可以直接结合网络空间测绘引擎的语句直接批量检测
  Modules(Seebug, Zoomeye, CEye, Fofa, Quake, Listener) options

  --dork DORK           Zoomeye dork used for search   # 默认钟馗之眼的语句
  --dork-zoomeye DORK_ZOOMEYE
                        Zoomeye dork used for search
  --dork-shodan DORK_SHODAN
                        Shodan dork used for search
  --dork-censys DORK_CENSYS
                        Censys dork used for search
  --dork-fofa DORK_FOFA
                        Fofa dork used for search
  --dork-quake DORK_QUAKE
                        Quake dork used for search
  --max-page MAX_PAGE   Max page used in search API  # 最大的页数 , 不好使
  --search-type SEARCH_TYPE
                        search type used in ZoomEye API, web or host   # 搜索类型
  --vul-keyword VUL_KEYWORD
                        Seebug keyword used for search      # 使用Seebug漏洞关键字搜索
  --ssv-id SSVID        Seebug SSVID number for target PoC  # 使用 ssv-id搜索对应的poc
  --lhost CONNECT_BACK_HOST
                        Connect back host for target PoC in shell mode  # shell模式下的反弹ip
  --lport CONNECT_BACK_PORT
                        Connect back port for target PoC in shell mode    # shell模式下的反弹port
  --tls                 Enable TLS listener in shell mode
  --comparison          Compare popular web search engines   # 使用比较流行的搜索引擎搜索
  --dork-b64            Whether dork is in base64 format         # 语句的base64格式

Optimization: # 选项
  Optimization options

  --plugins PLUGINS     Load plugins to execute   # 加载插件执行
  --pocs-path POCS_PATH  
                        User defined poc scripts path    # 用户定义的poc脚本路径
  --threads THREADS     Max number of concurrent network requests (default 1)  # 线程数
  --batch BATCH         Automatically choose defaut choice without asking    # 自动选择默认的询问
  --requires            Check install_requires    # 检查安装要求
  --quiet               Activate quiet mode, working without logger   # 安静模式, 终端不输出日志
  --ppt                 Hiden sensitive information when published to the network # 在发布到网络时隐藏敏感信										                                               息
  --pcap                use scapy capture flow  # 使用scapy捕获流
  --rule                export suricata rules, default export reqeust and response  # 导出suricata规则、默认导出请求和响应
  --rule-req            only export request rule  # 只导出请求规则
  --rule-filename RULE_FILENAME   
                        Specify the name of the export rule file   # 指定导出规则的文件名

Poc options:  # poc 选项
  definition options for PoC

  --options             Show all definition options   # 显示默认选项值

1、单个url

单个url使用验证模式运行poc,poc将仅用于漏洞扫描

pocsuite -r pocs/poc_example.py -u http://www.example.com/ --verify
                       poc文件的路径                  待检测的url
                       
pocsuite -r pocs/thinkphp_rce_myself.py  -u http://192.168.1.159:8080 --verify

2、批量检测

扫描文本文件中给定的多个目标

pocsuite -r pocs/poc_example.py -f url.txt --verify

3、使用Seebug SSVID

POCFILE 可以是文件或 Seebug SSVID。pocsuite 插件可以从任何地方加载 poc 代码

pocsuite -r ssvid-97343 -u http://www.example.com --shell

4、验证模式

–verify 使用验证模式运行 poc。PoC(s) 将仅用于漏洞扫描

pocsuite -r pocs/poc_example.py -u http://www.example.com/ --verify

5、攻击模式

–attack 以攻击模式运行 poc,PoC(s) 将被利用,它可能允许黑客/研究人员闯入实验室

pocsuite -r pocs/poc_example.py -u http://www.example.com/ --attack
pocsuite -r pocs/thinkphp_rce2.py  -u http://192.168.6.29:8080/ --attack

6、shell模式

–shell 以 shell 模式运行 poc,PoC 将可被利用,当 PoC shellcode 成功执行时,pocsuite3 将进入交互式 shell

pocsuite -r pocs/poc_example.py -u http://www.example.com --shell

7、线程数

使用多线程,默认线程数为1
pocsuite -r pocs/poc_example.py -f url.txt --verify --threads 10

8、fofa语句

如果是fofa用户,可以使用fofa语句进行批量查询

pocsuite -r pocs/thinkphp_rce2.py --dork-fofa 'body=\"thinkphp\"' --search-type web --thread 20

四、POC编写

官方文档:
https://github.com/knownsec/pocsuite3/blob/master/docs/CODING.md
模版路径:
D:\software\python3\Lib\site-packages\pocsuite3\pocs\demo_poc.py
模版分析:


```python
from collections import OrderedDict
from pocsuite3.api import (
    Output,
    POCBase,
    POC_CATEGORY,
    register_poc,
    requests,
    VUL_TYPE,
    get_listener_ip,
    get_listener_port,
)
from pocsuite3.lib.core.interpreter_option import (
    OptString,
    OptDict,
    OptIP,
    OptPort,
    OptBool,
    OptInteger,
    OptFloat,
    OptItems,
)
from pocsuite3.modules.listener import REVERSE_PAYLOAD

# 以上就是各种导入模块而已 , 有的用了 , 有的灰色的就是没有使用模块中的内容

class DemoPOC(POCBase):
    vulID = "1571"  # ssvid ID 如果是提交漏洞的同时提交 PoC,则写成 0
    version = "1"  # 默认为1
    author = "seebug"  # PoC作者的大名
    vulDate = "2014-10-16"  # 漏洞公开的时间,不知道就写今天
    createDate = "2014-10-16"  # 编写 PoC 的日期
    updateDate = "2014-10-16"  # PoC 更新的时间,默认和编写时间一样
    references = ["https://xxx.xx.com.cn"]  # 漏洞地址来源,0day不用写
    name = "XXXX SQL注入漏洞 PoC"  # PoC 名称
    appPowerLink = "https://www.drupal.org/"  # 漏洞厂商主页地址
    appName = "Drupal"  # 漏洞应用名称
    appVersion = "7.x"  # 漏洞影响版本
    vulType = VUL_TYPE.UNAUTHORIZED_ACCESS  # 漏洞类型,类型参考见 漏洞类型规范表
    category = POC_CATEGORY.EXPLOITS.WEBAPP
    samples = []  # 测试样列,就是用 PoC 测试成功的网站
    install_requires = []  # PoC 第三方模块依赖,请尽量不要使用第三方模块,必要时请参考《PoC第三方模块依赖说明》填写
    desc = """
            Drupal 在处理 IN 语句时,展开数组时 key 带入 SQL 语句导致 SQL 注入,
            可以添加管理员、造成信息泄露。
        """  # 漏洞简要描述
    pocDesc = """
            poc的用法描述
        """  # POC用法描述
    # 各种变量的定义 , 关于poc的描述

    def _options(self):
        """如果poc需要登录,这个是登录函数模板"""
        opt = OrderedDict()  # value = self.get_option('key')
        opt["string"] = OptString("", description="这个poc需要用户登录,请输入登录账号", require=True)
        opt["integer"] = OptInteger(
            "", description="这个poc需要用户密码,请输出用户密码", require=False
        )
        return opt

    def _verify(self):
        # 重点是这个验证代码
        output = Output(self)
        # 验证代码
        result = {
            # 不管是验证模式或者攻击模式,返回结果 result 中的 key 值必须按照下面的规范来写
            # [ PoC结果返回规范 ]( https://github.com/knownsec/pocsuite3/blob/master/docs/CODING.md#resultstandard )
            "Result": {
                "DBInfo": {
                    "Username": "xxx",
                    "Password": "xxx",
                    "Salt": "xxx",
                    "Uid": "xxx",
                    "Groupid": "xxx",
                },
                "ShellInfo": {"URL": "xxx", "Content": "xxx"},
                "FileInfo": {"Filename": "xxx", "Content": "xxx"},
                "XSSInfo": {"URL": "xxx", "Payload": "xxx"},
                "AdminInfo": {"Uid": "xxx", "Username": "xxx", "Password": "xxx"},
                "Database": {
                    "Hostname": "xxx",
                    "Username": "xxx",
                    "Password": "xxx",
                    "DBname": "xxx",
                },
                "VerifyInfo": {"URL": "xxx", "Postdata": "xxx", "Path": "xxx"},
                "SiteAttr": {"Process": "xxx"},
                "Stdout": "result output string",
            }
        }
        if result:  # result是返回结果
            output.success(result)
        else:
            output.fail("target is not vulnerable")
        return output

    def _attack(self):
        output = Output(self)
        result = {}
        # 攻击代码
        pass

    def _shell(self):
        """
        shell模式下,只能运行单个PoC脚本,控制台会进入shell交互模式执行命令及输出
        """
        cmd = REVERSE_PAYLOAD.BASH.format(get_listener_ip(), get_listener_port())
        # 攻击代码 execute cmd
        pass


def other_fuc():
    pass


def other_utils_func():
    pass


# 注册 DemoPOC 类
register_poc(DemoPOC)
可以根据自己想法修改。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值