Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php]unserialize
kyloren
post 19.09.2020, 07:29:47
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 19.09.2020

Ostrzeżenie: (0%)
-----


Moj kod wyklada tak:
  1. <?php
  2. class User
  3. {
  4. public $username;
  5. public $isAdmin;
  6.  
  7. public function PrintData(){
  8. if ($this->IsAdmin){
  9. echo $this->username . " is an admin\n";
  10. }
  11. else {
  12. echo $this->username . " is not an admin\n";
  13. }
  14. }
  15. }
  16. //$obj = new User();
  17. //$obj->username='Pawel';
  18. //$obj->IsAdmin=True;
  19. //$obj->PrintData();
  20. //echo serialize($obj);
  21. $obj=unserialize($_POST['serial']);
  22. //var_dump($obj);
  23. $obj->PrintData();
  24.  
  25. ?>

Przy wyslaniu zadania do serwera: curl -XPOST -d "serial=O:4:"User":2:{s:8:"username";O:8:"ReadFile":1:{s:8:"filename";s:11:"/etc/passwd";}s:7:"IsAdmin";b:1;}" 127.0.0.1/unserialize.php
dostaje blad:
[Sat Sep 19 08:09:52 2020] PHP Notice: unserialize(): Error at offset 0 of 89 bytes in /home/sysagent/php/unserialize.php on line 21
[Sat Sep 19 08:09:52 2020] PHP Fatal error: Uncaught Error: Call to a member function PrintData() on bool in /home/sysagent/php/unserialize.php:23
Stack trace:
#0 {main}
thrown in /home/sysagent/php/unserialize.php on line 23
[Sat Sep 19 08:09:52 2020] 127.0.0.1:43500 [500]: POST /unserialize.php - Uncaught Error: Call to a member function PrintData() on bool in /home/sysagent/php/unserialize.php:23
Stack trace:
#0 {main}
thrown in /home/sysagent/php/unserialize.php on line 23
[Sat Sep 19 08:09:52 2020] 127.0.0.1:43500 Closing

Gdzie lezy blad w moim kodzie?
Go to the top of the page
+Quote Post
viking
post 19.09.2020, 07:41:45
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


https://www.php.net/manual/en/class.serializable.php


--------------------
Go to the top of the page
+Quote Post
kyloren
post 19.09.2020, 07:57:29
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 19.09.2020

Ostrzeżenie: (0%)
-----


Cytat(viking @ 19.09.2020, 08:41:45 ) *


Dziekuje, ale chyba dalej nie rozumiem w czym polega problem.
Go to the top of the page
+Quote Post
viking
post 19.09.2020, 10:48:37
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


W pliku w którym robisz unserialize masz zdefiniowaną klasę User? Ogólnie to unserilize z post jest niebezpieczne.


--------------------
Go to the top of the page
+Quote Post
kyloren
post 19.09.2020, 18:29:55
Post #5





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 19.09.2020

Ostrzeżenie: (0%)
-----


Cytat(viking @ 19.09.2020, 11:48:37 ) *
W pliku w którym robisz unserialize masz zdefiniowaną klasę User? Ogólnie to unserilize z post jest niebezpieczne.


Wydaje mi sie w POSTcie wysylam obiekt "User"
curl -XPOST -d "serial=O:4:"User":2:{s:8:"username";O:8:"ReadFile":1:{s:8:"filename";s:11:"/etc/passwd";}s:7:"IsAdmin";b:1;}" 127.0.0.1/unserialize.php
Tak wiem ze to nie jest niebezpieczne. Chce przetestowac konsekwencje

Ten post edytował kyloren 19.09.2020, 18:30:22
Go to the top of the page
+Quote Post
viking
post 19.09.2020, 19:02:18
Post #6





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


No tak. Ale wysyłasz properties. Metod nie i nie da się. Żeby odtworzyć php musi wiedzieć jak wygląda te klasa więc musi np być dostępna dla autoloadera.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 16.04.2024 - 16:59