[鹤城杯 2021]EasyP

打印 上一主题 下一主题

主题 867|帖子 867|积分 2601

  1. <?php
  2. include 'utils.php';
  3. if (isset($_POST['guess'])) {
  4.     $guess = (string) $_POST['guess'];
  5.     if ($guess === $secret) {
  6.         $message = 'Congratulations! The flag is: ' . $flag;
  7.     } else {
  8.         $message = 'Wrong. Try Again';
  9.     }
  10. }
  11. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  12.     exit("hacker :)");
  13. }
  14. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  15.     exit("hacker :)");
  16. }
  17. if (isset($_GET['show_source'])) {
  18.     highlight_file(basename($_SERVER['PHP_SELF']));
  19.     exit();
  20. }else{
  21.     show_source(__FILE__);
  22. }
  23. ?>
复制代码
 这个题目出现了$_SERVER['PHP_SELF']
这个是你调用的脚本的路径
比如说这个题目它的值就是/index.php
如果你访问的是
http://1.14.71.254:28189/index.php/utils.php
那么它的值就会是/index.php/utils.php
而$_SEVER['REQUEST_URL']
它的值这个时候和$_SERVER['PHP_SELF']的值是一样的,
区别在于,如果你用get传参的时候$_SEVER['REQUEST_URL']是会加上那个参数的,而$_SERVER['PHP_SELF']不会。
 
然后是basename这个函数。
这个函数是返回最后面一个/后面的名字。

 
这个函数有一个可以利用的地方就是,如果传入的参数中出现了非ascii字符则会把它给丢弃。
 
最后是讲绕过正则
  1. if<?php
  2. include 'utils.php';
  3. if (isset($_POST['guess'])) {
  4.     $guess = (string) $_POST['guess'];
  5.     if ($guess === $secret) {
  6.         $message = 'Congratulations! The flag is: ' . $flag;
  7.     } else {
  8.         $message = 'Wrong. Try Again';
  9.     }
  10. }
  11. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  12.     exit("hacker :)");
  13. }
  14. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  15.     exit("hacker :)");
  16. }
  17. if (isset($_GET['show_source'])) {
  18.     highlight_file(basename($_SERVER['PHP_SELF']));
  19.     exit();
  20. }else{
  21.     show_source(__FILE__);
  22. }
  23. ?> (preg_match('/show_source/',<?php
  24. include 'utils.php';
  25. if (isset($_POST['guess'])) {
  26.     $guess = (string) $_POST['guess'];
  27.     if ($guess === $secret) {
  28.         $message = 'Congratulations! The flag is: ' . $flag;
  29.     } else {
  30.         $message = 'Wrong. Try Again';
  31.     }
  32. }
  33. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  34.     exit("hacker :)");
  35. }
  36. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  37.     exit("hacker :)");
  38. }
  39. if (isset($_GET['show_source'])) {
  40.     highlight_file(basename($_SERVER['PHP_SELF']));
  41.     exit();
  42. }else{
  43.     show_source(__FILE__);
  44. }
  45. ?> $_SERVER['REQUEST_URI'])){<?php
  46. include 'utils.php';
  47. if (isset($_POST['guess'])) {
  48.     $guess = (string) $_POST['guess'];
  49.     if ($guess === $secret) {
  50.         $message = 'Congratulations! The flag is: ' . $flag;
  51.     } else {
  52.         $message = 'Wrong. Try Again';
  53.     }
  54. }
  55. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  56.     exit("hacker :)");
  57. }
  58. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  59.     exit("hacker :)");
  60. }
  61. if (isset($_GET['show_source'])) {
  62.     highlight_file(basename($_SERVER['PHP_SELF']));
  63.     exit();
  64. }else{
  65.     show_source(__FILE__);
  66. }
  67. ?> <?php
  68. include 'utils.php';
  69. if (isset($_POST['guess'])) {
  70.     $guess = (string) $_POST['guess'];
  71.     if ($guess === $secret) {
  72.         $message = 'Congratulations! The flag is: ' . $flag;
  73.     } else {
  74.         $message = 'Wrong. Try Again';
  75.     }
  76. }
  77. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  78.     exit("hacker :)");
  79. }
  80. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  81.     exit("hacker :)");
  82. }
  83. if (isset($_GET['show_source'])) {
  84.     highlight_file(basename($_SERVER['PHP_SELF']));
  85.     exit();
  86. }else{
  87.     show_source(__FILE__);
  88. }
  89. ?> <?php
  90. include 'utils.php';
  91. if (isset($_POST['guess'])) {
  92.     $guess = (string) $_POST['guess'];
  93.     if ($guess === $secret) {
  94.         $message = 'Congratulations! The flag is: ' . $flag;
  95.     } else {
  96.         $message = 'Wrong. Try Again';
  97.     }
  98. }
  99. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  100.     exit("hacker :)");
  101. }
  102. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  103.     exit("hacker :)");
  104. }
  105. if (isset($_GET['show_source'])) {
  106.     highlight_file(basename($_SERVER['PHP_SELF']));
  107.     exit();
  108. }else{
  109.     show_source(__FILE__);
  110. }
  111. ?> <?php
  112. include 'utils.php';
  113. if (isset($_POST['guess'])) {
  114.     $guess = (string) $_POST['guess'];
  115.     if ($guess === $secret) {
  116.         $message = 'Congratulations! The flag is: ' . $flag;
  117.     } else {
  118.         $message = 'Wrong. Try Again';
  119.     }
  120. }
  121. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  122.     exit("hacker :)");
  123. }
  124. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  125.     exit("hacker :)");
  126. }
  127. if (isset($_GET['show_source'])) {
  128.     highlight_file(basename($_SERVER['PHP_SELF']));
  129.     exit();
  130. }else{
  131.     show_source(__FILE__);
  132. }
  133. ?> exit("hacker<?php
  134. include 'utils.php';
  135. if (isset($_POST['guess'])) {
  136.     $guess = (string) $_POST['guess'];
  137.     if ($guess === $secret) {
  138.         $message = 'Congratulations! The flag is: ' . $flag;
  139.     } else {
  140.         $message = 'Wrong. Try Again';
  141.     }
  142. }
  143. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  144.     exit("hacker :)");
  145. }
  146. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  147.     exit("hacker :)");
  148. }
  149. if (isset($_GET['show_source'])) {
  150.     highlight_file(basename($_SERVER['PHP_SELF']));
  151.     exit();
  152. }else{
  153.     show_source(__FILE__);
  154. }
  155. ?> :)");}
复制代码
 
 这个正则的绕过方法就是利用特性来绕过,可以用
 [
 <?php
include 'utils.php';

if (isset($_POST['guess'])) {
    $guess = (string) $_POST['guess'];
    if ($guess === $secret) {
        $message = 'Congratulations! The flag is: ' . $flag;
    } else {
        $message = 'Wrong. Try Again';
    }
}

if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
    exit("hacker :)");
}

if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
    exit("hacker :)");
}

if (isset($_GET['show_source'])) {
    highlight_file(basename($_SERVER['PHP_SELF']));
    exit();
}else{
    show_source(__FILE__);
}
?> (空格)
 +<?php
include 'utils.php';

if (isset($_POST['guess'])) {
    $guess = (string) $_POST['guess'];
    if ($guess === $secret) {
        $message = 'Congratulations! The flag is: ' . $flag;
    } else {
        $message = 'Wrong. Try Again';
    }
}

if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
    exit("hacker :)");
}

if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
    exit("hacker :)");
}

if (isset($_GET['show_source'])) {
    highlight_file(basename($_SERVER['PHP_SELF']));
    exit();
}else{
    show_source(__FILE__);
}
?>  
 .
上面那几个字符任何一个都行,都可以被处理成_
  1. if<?php
  2. include 'utils.php';
  3. if (isset($_POST['guess'])) {
  4.     $guess = (string) $_POST['guess'];
  5.     if ($guess === $secret) {
  6.         $message = 'Congratulations! The flag is: ' . $flag;
  7.     } else {
  8.         $message = 'Wrong. Try Again';
  9.     }
  10. }
  11. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  12.     exit("hacker :)");
  13. }
  14. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  15.     exit("hacker :)");
  16. }
  17. if (isset($_GET['show_source'])) {
  18.     highlight_file(basename($_SERVER['PHP_SELF']));
  19.     exit();
  20. }else{
  21.     show_source(__FILE__);
  22. }
  23. ?> (preg_match('/utils\.php\/*$/i',<?php
  24. include 'utils.php';
  25. if (isset($_POST['guess'])) {
  26.     $guess = (string) $_POST['guess'];
  27.     if ($guess === $secret) {
  28.         $message = 'Congratulations! The flag is: ' . $flag;
  29.     } else {
  30.         $message = 'Wrong. Try Again';
  31.     }
  32. }
  33. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  34.     exit("hacker :)");
  35. }
  36. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  37.     exit("hacker :)");
  38. }
  39. if (isset($_GET['show_source'])) {
  40.     highlight_file(basename($_SERVER['PHP_SELF']));
  41.     exit();
  42. }else{
  43.     show_source(__FILE__);
  44. }
  45. ?> $_SERVER['PHP_SELF']))<?php
  46. include 'utils.php';
  47. if (isset($_POST['guess'])) {
  48.     $guess = (string) $_POST['guess'];
  49.     if ($guess === $secret) {
  50.         $message = 'Congratulations! The flag is: ' . $flag;
  51.     } else {
  52.         $message = 'Wrong. Try Again';
  53.     }
  54. }
  55. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  56.     exit("hacker :)");
  57. }
  58. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  59.     exit("hacker :)");
  60. }
  61. if (isset($_GET['show_source'])) {
  62.     highlight_file(basename($_SERVER['PHP_SELF']));
  63.     exit();
  64. }else{
  65.     show_source(__FILE__);
  66. }
  67. ?> {<?php
  68. include 'utils.php';
  69. if (isset($_POST['guess'])) {
  70.     $guess = (string) $_POST['guess'];
  71.     if ($guess === $secret) {
  72.         $message = 'Congratulations! The flag is: ' . $flag;
  73.     } else {
  74.         $message = 'Wrong. Try Again';
  75.     }
  76. }
  77. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  78.     exit("hacker :)");
  79. }
  80. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  81.     exit("hacker :)");
  82. }
  83. if (isset($_GET['show_source'])) {
  84.     highlight_file(basename($_SERVER['PHP_SELF']));
  85.     exit();
  86. }else{
  87.     show_source(__FILE__);
  88. }
  89. ?> <?php
  90. include 'utils.php';
  91. if (isset($_POST['guess'])) {
  92.     $guess = (string) $_POST['guess'];
  93.     if ($guess === $secret) {
  94.         $message = 'Congratulations! The flag is: ' . $flag;
  95.     } else {
  96.         $message = 'Wrong. Try Again';
  97.     }
  98. }
  99. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  100.     exit("hacker :)");
  101. }
  102. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  103.     exit("hacker :)");
  104. }
  105. if (isset($_GET['show_source'])) {
  106.     highlight_file(basename($_SERVER['PHP_SELF']));
  107.     exit();
  108. }else{
  109.     show_source(__FILE__);
  110. }
  111. ?> <?php
  112. include 'utils.php';
  113. if (isset($_POST['guess'])) {
  114.     $guess = (string) $_POST['guess'];
  115.     if ($guess === $secret) {
  116.         $message = 'Congratulations! The flag is: ' . $flag;
  117.     } else {
  118.         $message = 'Wrong. Try Again';
  119.     }
  120. }
  121. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  122.     exit("hacker :)");
  123. }
  124. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  125.     exit("hacker :)");
  126. }
  127. if (isset($_GET['show_source'])) {
  128.     highlight_file(basename($_SERVER['PHP_SELF']));
  129.     exit();
  130. }else{
  131.     show_source(__FILE__);
  132. }
  133. ?> <?php
  134. include 'utils.php';
  135. if (isset($_POST['guess'])) {
  136.     $guess = (string) $_POST['guess'];
  137.     if ($guess === $secret) {
  138.         $message = 'Congratulations! The flag is: ' . $flag;
  139.     } else {
  140.         $message = 'Wrong. Try Again';
  141.     }
  142. }
  143. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  144.     exit("hacker :)");
  145. }
  146. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  147.     exit("hacker :)");
  148. }
  149. if (isset($_GET['show_source'])) {
  150.     highlight_file(basename($_SERVER['PHP_SELF']));
  151.     exit();
  152. }else{
  153.     show_source(__FILE__);
  154. }
  155. ?> exit("hacker<?php
  156. include 'utils.php';
  157. if (isset($_POST['guess'])) {
  158.     $guess = (string) $_POST['guess'];
  159.     if ($guess === $secret) {
  160.         $message = 'Congratulations! The flag is: ' . $flag;
  161.     } else {
  162.         $message = 'Wrong. Try Again';
  163.     }
  164. }
  165. if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  166.     exit("hacker :)");
  167. }
  168. if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
  169.     exit("hacker :)");
  170. }
  171. if (isset($_GET['show_source'])) {
  172.     highlight_file(basename($_SERVER['PHP_SELF']));
  173.     exit();
  174. }else{
  175.     show_source(__FILE__);
  176. }
  177. ?> :)");}
复制代码
 
这个正则是匹配末尾有没有utils.php/
绕过办法很简单
因为后面要调用basename,所以可以利用中文来绕过,中文不属于ascii编码中的,所以可以payload

 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

天空闲话

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表