当前位置:   article > 正文

ctfer的web日常:给你shell (ctfshow)_easyshell ctf

easyshell ctf

目录

前期准备:

代码审计(1):

行动:

代码审计(2):

大佬:


前期准备:

进入页面,发现没有什么信息:

查看源码,发现“/?view_source”路由:

访问此页面:

代码审计(1):

  1. <?php
  2. //It's no need to use scanner. Of course if you want, but u will find nothing.
  3. error_reporting(0);
  4. include "config.php";
  5. if (isset($_GET['view_source'])) {
  6. show_source(__FILE__); // 当参数为view_source即访问/?view_source时,展示__FILE__即我们看到的代码
  7. die;
  8. }
  9. function checkCookie($s) {
  10. $arr = explode(':', $s); // 以“:”进行分组,并将每一个部分存到数组arr
  11. if ($arr[0] === '{"secret"' && preg_match('/^[\"0-9A-Z]*}$/', $arr[1]) && count($arr) === 2 ) {
  12. return true; # arr[0] === {"secret" 且 $arr[1]必须包含数字字母至少一种
  13. } else {
  14. if ( !theFirstTimeSetCookie() ) setcookie('secret', '', time()-1);
  15. return false;
  16. }
  17. }
  18. function haveFun($_f_g) { // 对$_f_g进行MD5加密并转为大写字母,最后将每一位字符的ascii码值进行与运算
  19. $_g_r = 32;
  20. $_m_u = md5($_f_g);
  21. $_h_p = strtoupper($_m_u);
  22. for ($i = 0; $i < $_g_r; $i++) {
  23. $_i = substr($_h_p, $i, 1);
  24. $_i = ord($_i);
  25. print_r($_i & 0xC0);
  26. }
  27. die;
  28. }
  29. isset($_COOKIE['secret']) ? $json = $_COOKIE['secret'] : setcookie('secret', '{"secret":"' . strtoupper(md5('y1ng')) . '"}', time()+7200 );
  30. checkCookie($json) ? $obj = @json_decode($json, true) : die('no');
  31. // 判断有无secret
  32. // 通过secret赋值给$json,再通过$json建立$obj
  33. // json_decode() 将json格式的数据转换为对象,数组,转换为数组要加true
  34. // json的secret需要满足 checkCookie($s) 里面的条件
  35. if ($obj && isset($_GET['give_me_shell'])) {
  36. ($obj['secret'] != $flag_md5 ) ? haveFun($flag) : echo "here is your webshell: $shell_path";
  37. }
  38. /*要让传入的secret为 $flag_md5,这里就存在漏洞了,利用php的弱类型比较,但是这里又有个问题,在json_decode()返回""里面的内
  39. 容是字符串,就不能进行弱类型比较了,但是如果里面的内容,比如数字,没有被""括起来,返回的就是个int整数,所以注意把""删去,也
  40. 就是{"secret":123},这里开始没注意到还被坑了,一直没有爆破出来
  41. */
  42. die;

行动:

因为数字与0xC0为0;所有可以得知$flag_md5前3位为数字;再根据php弱类型比较的特性,如111 == ‘111adf’,用bp进行爆破:

故secret = 115满足$obj['secret'] != $flag_md5;

修改访问得:

访问w3b5HeLLlll123.php:

代码审计(2):

  1. <?php
  2. error_reporting(0);
  3. session_start();
  4. //there are some secret waf that you will never know, fuzz me if you can
  5. require "hidden_filter.php";
  6. if (!$_SESSION['login'])
  7. die('<script>location.href=\'./index.php\'</script>');
  8. if (!isset($_GET['code'])) {
  9. show_source(__FILE__);
  10. exit();
  11. } else {
  12. $code = $_GET['code'];
  13. if (!preg_match($secret_waf, $code)) {
  14. //清空session 从头再来
  15. eval("\$_SESSION[" . $code . "]=false;"); //you know, here is your webshell, an eval() without any disabled_function. However, eval() for $_SESSION only XDDD you noob hacker
  16. } else die('hacker');
  17. }
  18. /*
  19. * When you feel that you are lost, do not give up, fight and move on.
  20. * Being a hacker is not easy, it requires effort and sacrifice.
  21. * But remember … we are legion!
  22. * ————Deep CTF 2020
  23. */

fuzzing:

发现好多东西都被禁了;

大佬:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/807635
推荐阅读
相关标签
  

闽ICP备14008679号