Insecure Deserialization of PHP Object
CWE-502: Deserialization of Untrusted Data
User.php
class User{
public $username = "";
public $role = "";
public function displayRole() {
echo $this->role;
}
}
login.php
//Create object User
$user = new User;
$user->username = $username;
$user->role = $role;
//PHP object serialization
$data = base64_encode(serialize($user));
//Redirect with PHP object serialization
header('Location: profile.php?data='.$data);
Access is denied for user "test" |
profile.php
$data = $_GET['data'];
$data = base64_decode($data);
$data = unserialize($data);
$username = $data->username;
$role = $data->role;
if($role == "admin"){
//action here
}
Decode base64 for value in "data" parameter |
Modify the value of role from "user" to "admin", also the number of characters from 4 to 5 |
Replace the value with new generated base64 value |
No comments:
Post a Comment