php mit gdb starten....

hallo,
ich lese mich gerade in serialize ein.
Ziel der Geschichte ist:
Ich lasse eine test.php mit folgendem inhalt ausführen:
PHP:
class obj implements Serializable {
    private $data;
    public function __construct() {
        $this->data = "Meine private-Daten";
    }
    public function serialize() {
        return serialize($this->data);
    }
    public function unserialize($data) {
        $this->data = unserialize($data);
    }
    public function getData() {
        return $this->data;
    }
}

$obj = new obj;
$ser = serialize($obj);

var_dump($ser);

$newobj = unserialize($ser);

var_dump($newobj->getData());

Jetzt möchte ich den Speicher mit gdb untersuchen und den inhalt:Meine private-Daten wieder finden. Leider bekomme ich es nicht gebacken die php5 mit gdb zustarten.
 
Bitte beschreibe genauer, wo dein Problem liegt:

Code:
bitmuncher@ktsSN ~ $ gdb --args /usr/bin/php /home/bitmuncher/test.php
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i586-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/php /home/bitmuncher/test.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/i686/cmov/libthread_db.so.1".
[New Thread 0xf5583b40 (LWP 16158)]
class obj implements Serializable {
    private $data;
    public function __construct() {
        $this->data = "Meine private-Daten";
    }
    public function serialize() {
        return serialize($this->data);
    }
    public function unserialize($data) {
        $this->data = unserialize($data);
    }
    public function getData() {
        return $this->data;
    }
}

$obj = new obj;
$ser = serialize($obj);

var_dump($ser);

$newobj = unserialize($ser);

var_dump($newobj->getData());
[Thread 0xf5583b40 (LWP 16158) exited]
[Inferior 1 (process 16119) exited normally]
(gdb)

oder mit Übergabe des Parameters/Skripts im GDB:

Code:
bitmuncher@ktsSN ~ $ gdb /usr/bin/php
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i586-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.
(gdb) run test.php
Starting program: /usr/bin/php test.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/i686/cmov/libthread_db.so.1".
[New Thread 0xf5583b40 (LWP 15929)]
class obj implements Serializable {
    private $data;
    public function __construct() {
        $this->data = "Meine private-Daten";
    }
    public function serialize() {
        return serialize($this->data);
    }
    public function unserialize($data) {
        $this->data = unserialize($data);
    }
    public function getData() {
        return $this->data;
    }
}

$obj = new obj;
$ser = serialize($obj);

var_dump($ser);

$newobj = unserialize($ser);

var_dump($newobj->getData());
[Thread 0xf5583b40 (LWP 15929) exited]
[Inferior 1 (process 15925) exited normally]

Natürlich müsstest du entsprechende Breakpoints setzen um den Speicher an der gewünschten Stelle zu untersuchen.

Wobei bei PHP eigentlich auch ltrace ausreichend sollte, da das Skript sowieso per write() auf eine FD geschrieben wird:

Code:
...
fopen64("/home/bitmuncher/test.php", "rb")       = 0x9ac36c8
...
memcpy(0xf6b9d836, "text/html; charset=UTF-8\0", 25) = 0xf6b9d836
write(1, "class obj implements Serializabl"..., 497class obj implements Serializable {
    private $data;
    public function __construct() {
        $this->data = "Meine private-Daten";
    }
    public function serialize() {
        return serialize($this->data);
    }
    public function unserialize($data) {
        $this->data = unserialize($data);
    }
    public function getData() {
        return $this->data;
    }
}

$obj = new obj;
$ser = serialize($obj);

var_dump($ser);

$newobj = unserialize($ser);

var_dump($newobj->getData());
) = 497
fflush(0xf6dc6ac0)                               = 0
free(0x99d0d90)                                  = <void>
...
 
Ich glaube du schießt über das Ziel hinaus.
Du willst nicht den Interpreter debuggen sondern das Skript.
d.h. sollte xdebug das Mittel deiner Wahl sein.
LG

Fluffy
 
PHP: debug_backtrace - Manual könnte auch interessant für dich sein.

Mit einem Programm wie in C kannst du das nicht wirklich vergleichen da PHP eine echte Interpretersprache ist.
So gesehen könnte man sagen dass ein PHP Skript die Konfiguration darstellt, die das Programm (Interpreter) verarbeitet.

Vermutlich ist aber var_dump das, was du wirklich suchst. Und wenn du es unbedingt willst, kannste das ja auch in HEX ausgeben (warum auch immer).
 
ok,
ich glaube ich habe mich vielleicht falsch ausgedrückt.
Das ist mein Ziel:
INulledMyself: Exploiting memory corruption bugs in PHP (CVE-2014-8142 and CVE-2015-0231) Part 1: Local Exploitation: Security for mere mortals

ich habe ubuntu 15,04

1.ten:aus dem link geht vor:
gdb /usr/bin/ndphp/bin/./php

ndphp ?

2.ten: laut link setze ich einen break in var_unserializer.c:337
ich habe php als online installiert verwendet, ich brauche jetzt den offline installier?

3.ten:
was ist cphp?


HTML:
root@tomycat-OptiPlex-GX620:~# gdb /usr/bin/php
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.
(gdb) b var_unserializer.c:337
Es ist keine Symboltabelle geladen. Benutzen Sie den »file«-Befehl.
Make breakpoint pending on future shared library load? (y or [n]) y
Haltepunkt 1 (var_unserializer.c:337) anstehend.
(gdb) Quit
(gdb) Quit
(gdb)
 
1.ten:aus dem link geht vor:
gdb /usr/bin/ndphp/bin/./php

3.ten:
was ist cphp?

Möglicherweise hat er sich PHP Versionen gebaut mit irgendwelchen Modifikationen/Prints ..

Aber wieso fragst du ihn nicht einfach statt uns?

Reading symbols from /usr/bin/php...(no debugging symbols found)...done.
Du musst dein PHP Interpreter schon selber bauen (code laden, compilieren) - mit Debuginformationen (Compileroptionen)..
 
thx,
ich wollte ihm gerne eine mail schreiben, er gibt aber keine an. In wie fern selber bauen? Den Quellcode abändern oder php offline installieren mit make.
 
Den Quellcode abändern oder php offline installieren mit make.
Wenn du dich ans debuggen von solchen Dingern machst, musst du in jedem Fall hier und dort mal im Code herumfummeln. Alleine schon um ueberall irgendwas auszuprinten.
Also Quellcode laden und dann (offline ..) Makefile anpassen und selbst bauen.
Debug-Infos gibt's mit "-g".



ich wollte ihm gerne eine mail schreiben, er gibt aber keine an.
Noch nie was von WHOIS gehört?
Er benutzt offenbar den google Privacy Service: krtpbq21cln9@contactprivacy.emailAnsonsten ist unter seinem Beitrag ein unübersehbares Kommentarformular..
 
Zurück
Oben