[root-me.org] ELF x86 - Format string bug basic 2 Write-Up
두비니
·2019. 11. 5. 00:29
::Login::
Host | challenge02.root-me.org |
Protocol | SSH |
Port | 2222 |
SSH access | ssh -p 2222 app-systeme-ch14@challenge02.root-me.org WebSSH |
Username | app-systeme-ch14 |
Password | app-systeme-ch14 |
::Code::
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main( int argc, char ** argv )
{
int var;
int check = 0x04030201;
char fmt[128];
if (argc <2)
exit(0);
memset( fmt, 0, sizeof(fmt) );
printf( "check at 0x%x\n", &check );
printf( "argv[1] = [%s]\n", argv[1] );
snprintf( fmt, sizeof(fmt), argv[1] ); //vuln
if ((check != 0x04030201) && (check != 0xdeadbeef))
printf ("\nYou are on the right way !\n");
printf( "fmt=[%s]\n", fmt );
printf( "check=0x%x\n", check );
if (check==0xdeadbeef)
{
printf("Yeah dude ! You win !\n");
setreuid(geteuid(), geteuid());
system("/bin/bash");
}
}
보면 format string bug가 발생한다는 것을 알 수 있다.
이를 이용하여 check의 값을 변경시켜야하는데,
9번째 %8x에서 AAAA가 출력되는 것을 확인할 수 있고, 그 뒤에는 바로 fmt가 있는것 또한 확인 할 수 있다.
따라서 우리의 exploit plan은 다음과 같이 계획할 수 있다.
0. check +2 에는 0xdead(57005), check에는 0xbeef(48879)를 넣을 것이다.
- %8x를 7번 하여 esp를 check앞으로 끌고온다.
- %48811c%n출력(0xbeef)
- %8126c%n(0xdead)
즉 payload는 (beef주소) + (dummy) + (dead주소) + %8x*7 + (%48811c%n%8126c%n)
다음과 같이 대입하면
check의 주소가 바뀌었기 때문에 풀리지 않습니다. 왜냐하면 stack의 주소는 argument의 길이에 따라서 바뀌거든요. 따라서 주소만 잘 바꾸어주면
풀립니다!
fomat string bug는 너무 어렵네요...
++) 혹시 애초에 풀이가 printf가 %s로 형식지정자로 선언되어있는데 왜 format string bug가 일어나냐고 묻는다면 snprintf에대해서 공부해봅시다.
snprintf에대해서는 다음 링크 참조
https://www.ibm.com/support/knowledgecenter/ko/ssw_ibm_i_73/rtref/snprintf.htm
'War Games > root-me.org' 카테고리의 다른 글
[root-me.org] ELF x86 - Race condition Write-Up (0) | 2019.11.05 |
---|---|
[root-me.org] ELF x64 - Stack buffer overflow - basic Write-Up (0) | 2019.11.03 |
[root-me.org] ELF x86 - Format string bug basic 1 Write-Up (0) | 2019.11.02 |
[root-me.org] ELF x86 - Stack buffer overflow basic 2 Write-Up (0) | 2019.11.02 |
[root-me.org] ELF x86 - Stack buffer overflow basic 1 write-up (0) | 2019.11.01 |