Search results for 'before I die'

  1. 2009.03.17 -- ABI (Application Binary Interface)
  2. 2009.03.17 -- Nefif_rx
  3. 2009.03.11 -- ftz.hackerschool.org
  4. 2009.02.11 -- some instruction
  5. 2009.01.28 -- bypassing isDebuggerPresent WITHOUT changing mem
  6. 2009.01.08 -- usleep에 대해서
  7. 2008.09.29 -- strtok_r
  8. 2008.08.21 -- this is RAM
  9. 2008.07.17 -- nit_if.h
  10. 2008.07.15 -- about ftp

ABI (Application Binary Interface)

2009. 3. 17. 17:13

*      ABI(Application Binary Interface)

 

ABI는 응용 프로그램과 운영체제, 또는 응용 프로그램과 라이브러리 사이에 필요한 저 수준 인터페이스를 정의한다. API(Application Programing Interface)와 비슷하지만 ABI는 바이너리 호환성을 가능하게 하고 API는 소스코드 호환성을 제공한다. 예를 들어 POSIX 표준은 API는 일반 산술함수가 여러 다른 시스템에서 작동하게 쓰여질 수 있는 것을 허락한다고 정의한다. 그러나 API의 사용은 각각의 플랫폼에서 재편집(리컴파일)을 요구한다. 반면에 호환성 있는 ABI는 컴파일된 오브젝트 코드가 어떤 수정 없이도 작동하는 것을 가능하게 한다. ABI는 함수의 인자들과 리턴값이 어떻게 넘겨지고 반환되는지를 다루는 호출 규약(Calling Convention)을 자세하게 다룬다.

 

< C source >

#include <stdio.h>

 

int add(int a, int b, int c, int d, int e, int f);

 

int main(void)

{

 

   int result = add(1, 2, 3, 4, 5, 6);

 

   printf("\n%d\n",result);

   return 0;

}

 

 

int add(int a, int b, int c, int d, int e, int f)

{

        int x;

        x = a + b + c+ d + e + f;

        return x;

}

< ASM source >

0x080483b4 <main+0>:    push   %ebp              프롤로그 : 이전 FP를 스택에 푸쉬

0x080483b5 <main+1>:    mov    %esp,%ebp       현재 esp FP

0x080483b7 <main+3>:    sub    $0x28,%esp       지역변수를 위한 공간확보

0x080483ba <main+6>:    and    $0xfffffff0,%esp   스택을 16bit boundry에 맞춘다

0x080483bd <main+9>:    mov    $0x0,%eax

0x080483c2 <main+14>:   add    $0xf,%eax

0x080483c5 <main+ni17>:   add    $0xf,%eax

0x080483c8 <main+20>:   shr    $0x4,%eax

0x080483cb <main+23>:   shl    $0x4,%eax

0x080483ce <main+26>:   sub    %eax,%esp

0x080483d0 <main+28>:   movl   $0x6,0x14(%esp)          우측부터 파라미터를 스택에 저장

0x080483d8 <main+36>:   movl   $0x5,0x10(%esp)         

0x080483e0 <main+44>:   movl   $0x4,0xc(%esp)

0x080483e8 <main+52>:   movl   $0x3,0x8(%esp)

0x080483f0 <main+60>:   movl   $0x2,0x4(%esp)

0x080483f8 <main+68>:   movl   $0x1,(%esp)

0x080483ff <main+75>:    call   0x8048421 <add>          add 함수 호출

                                                                     (호출 전 stack ret addr 집어넣는다)

 

0x08048404 <main+80>:   mov    %eax,0xfffffffc(%ebp)  리턴값을 ebp-4 (지역변수)에 저장

0x08048407 <main+83>:   mov    0xfffffffc(%ebp),%eax

0x0804840a <main+86>:   mov    %eax,0x4(%esp)      

0x0804840e <main+90>:   movl   $0x8048508,(%esp)

0x08048415 <main+97>:   call   0x80482d8 <printf@plt>

0x0804841a <main+102>:  mov    $0x0,%eax

0x0804841f <main+107>:  leave   에필로그(스택정리)        Leave :  mov ebp, esp

pop ebp

                                                    esp값을 현재의 ebp 가 있는 
        곳으로 이동시킨 후, stp pop해서 
        ebp
에 저장한다

0x08048420 <main+108>:  ret

 

Function add:

0x0804844c <add+0>:     push   %ebp                          프롤로그

0x0804844d <add+1>:     mov    %esp,%ebp

0x0804844f <add+3>:     sub    $0x4,%esp                    지역변수를 위한 공간할당

0x08048452 <add+6>:     mov    0xc(%ebp),%eax            

0x08048455 <add+9>:     add    0x8(%ebp),%eax            파라미터들을 더함

0x08048458 <add+12>:    add    0x10(%ebp),%eax

0x0804845b <add+15>:    add    0x14(%ebp),%eax

0x0804845e <add+18>:    add    0x18(%ebp),%eax

0x08048461 <add+21>:    add    0x1c(%ebp),%eax

0x08048464 <add+24>:    mov    %eax,0xfffffffc(%ebp)    더한값을 지역변수에 저장

0x08048467 <add+27>:    mov    0xfffffffc(%ebp),%eax

0x0804846a <add+30>:    leave

0x0804846b <add+31>:    ret

 
이걸 테스트한 환경이 기억나질 않네.. 헐..

'Sabzil' 카테고리의 다른 글

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
6회 kisa 해킹방어대회 6번  (0) 2009.07.09
Nefif_rx  (0) 2009.03.17
usleep에 대해서  (0) 2009.01.08
strtok_r  (0) 2008.09.29
this is RAM  (0) 2008.08.21
nit_if.h  (0) 2008.07.17

badcob Sabzil

Nefif_rx

2009. 3. 17. 17:06

*Netif_rx*

 

네트워크로부터 디바이스가 패킷을 수신했을 경우 커널에게 이를 알려주어야 한다. 패킷을 수신 하면 인터럽트가 발생하며 이 처리는 디바이스 드라이버가 맡는다. 드라이버는 지정된 커널 영역 메모리에 패킷을 복사한 후 커널로 처리과정을 넘기게 된다.

 

int netif_rx(struct sk_buff *skb)

{

        struct softnet_data *queue; //수신되는 패킷들을 저장해두는 큐로 사용, cpu에 하나씩

        unsigned long flags;

 

        /* if netpoll wants it, pretend we never saw it */

        if (netpoll_rx(skb))  // ??

                return NET_RX_DROP;

 

        if (!skb->tstamp.off_sec)

                net_timestamp(skb);

 

local_irq_save(flags);

/*인터럽트가 발생하지 않도록 파라미터로 들어가는 flags변수에 현재 인터럽트 관련 플래그가 저장된 IF 레지스터 정보를 저장한다,*/

        queue = &__get_cpu_var(softnet_data);

           // 받은 패킷들을 저장할 각각의 CPU에 큐를 배정

/ /cpu별 변수(per-CPU variable) get_cpu_var : 커널선점기능을 금지하며 cpu당 배열에서          //지역 cpu의 요소를 선택한다

 


   __get_cpu_var(netdev_rx_stat).total++;  //
cpu에 수신된 총 패킷수 증가

        if (queue->input_pkt_queue.qlen <= netdev_max_backlog) {

                if (queue->input_pkt_queue.qlen) {

           //큐에 있는 패킷의 길이가 네트워크 패킷의 전체갯수보다 작거나 같고

        //큐에 패킷이 있다면

enqueue:    

                        dev_hold(skb->dev);

                        __skb_queue_tail(&queue->input_pkt_queue, skb);

//queue의 끝에 패킷을 집어 넣는다

                        local_irq_restore(flags);

// local_irq_save 전의 인터럽트 관련 세팅 상태로 원상복귀

                        return NET_RX_SUCCESS; //cpu 상태 반환 : no congestion

                }

 

                netif_rx_schedule(&queue->backlog_dev);

                goto enqueue;

        }

 

        __get_cpu_var(netdev_rx_stat).dropped++; //드랍된 패킷카운트 증가

        local_irq_restore(flags);

 

        kfree_skb(skb);  //리소스해제

        return NET_RX_DROP;

}

 

static inline void netif_rx_schedule(struct net_device *dev)

{

        if (netif_rx_schedule_prep(dev))

                __netif_rx_schedule(dev);

}

 

static inline void __netif_rx_schedule(struct net_device *dev)

{

        unsigned long flags;

 

        local_irq_save(flags);

        dev_hold(dev);

        list_add_tail(&dev->poll_list, &__get_cpu_var(softnet_data).poll_list);

        if (dev->quota < 0)

                dev->quota += dev->weight;

        else

                dev->quota = dev->weight;

        __raise_softirq_irqoff(NET_RX_SOFTIRQ); //네트워크카드에서 패킷을 수신

/*cpu softirq NET_RX_SOFTIRQ만큼 raise(pending)시킨 후 cpu local irqbottom

half의 카운트가 모두 0일 경우 softirq daemon을 활성화 시킨다 */

        local_irq_restore(flags);

}

'Sabzil' 카테고리의 다른 글

Shellcode site  (0) 2009.09.29
hey JJAAPPPHH ~  (4) 2009.08.17
hey JaPH  (1) 2009.08.12
6회 kisa 해킹방어대회 6번  (0) 2009.07.09
ABI (Application Binary Interface)  (0) 2009.03.17
usleep에 대해서  (0) 2009.01.08
strtok_r  (0) 2008.09.29
this is RAM  (0) 2008.08.21
nit_if.h  (0) 2008.07.17
about ftp  (0) 2008.07.15

badcob Sabzil

ftz.hackerschool.org

2009. 3. 11. 18:11
level1         hacker or cracker
level2         can you fly?
level3         suck my brain
level4         what is your name?
level5         what the hell
level6         come together
level7        break the world
level8        apple
level9        interesting to hack!               
level10       what!@#$
level11       it is like this   
level12       have no clue
level13       what that nigga want?
level14       guestt what
level15       about to cause mass
level16       king poetic
level17       why did you do it
level18       swimming in pink
level19       we are just regular guys
level20

머리속에서 겉돌기만하던 개념들이 어느순간에 깨끗하게 정리되는 느낌이 들었.. 풉..
format string 은 일단 패스

badcob War game/ftz.hackerschool.org

some instruction

2009. 2. 11. 15:39
맨날 헷갈리는 test!

test
http://faydoc.tripod.com/cpu/test.htm
Computes the bit-wise logical AND of first operand (source 1 operand) and the second operand (source 2 operand) and sets the SF, ZF, and PF status flags according to the result. The result is then discarded.

test a, a a null인지 Check 하는 명령어. test a,b a&b 같이 AND 연산을 의미한다. 이후에 jxx 연산을 하여 a값이 null이 아닐 경우에 looping 돌고, null이면 해당 loop에서 빠져나간다. 




lodsb

http://faydoc.tripod.com/cpu/lodsb.htm
Loads a byte, word, or doubleword from the source operand into the AL, AX, or EAX register, respectively. The source operand is a memory location, the address of which is read from the DS:EDI or the DS:SI registers (depending on the address-size attribute of the instruction, 32 or 16, respectively). The DS segment may be overridden with a segment override prefix.

LODSB : LODS BYTE
[LODSB] 명령은 DS:SI에 입력된 주소의 한 바이트를  AL 레지스터로 전달.
그 후 SI를 하나 증가시켜 SI로 지정된 주소의 다음 내용을 읽을 준비를 함 Stores a byte, word, or doubleword from the AL, AX, or EAX register, respectively, into the destination operand. The destination operand is a memory location, the address of which is read from either the ES:EDI or the ES:DI registers (depending on the address-size attribute of the instruction, 32 or 16, respectively).

process environment structure
http://baeg.tistory.com/entry/Windows-Heap-Overflows-using-the-Process-Environment-Block-PEB

'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
Reversing for Newbies (written by Lena)  (0) 2009.03.27
bypassing isDebuggerPresent WITHOUT changing mem  (0) 2009.01.28

badcob Reversing

bypassing isDebuggerPresent WITHOUT changing mem

2009. 1. 28. 16:38
If you change the JE, you are modding the program code, and it no doubt detects this with a CRC routine of some sort. Also, if you wait until the code returns, and then change the value in eax, you are once again "modding" the code in a way because you are setting a breakpoint in the code.

The safest and most effective way to modify IsDebuggerPresent detection is to edit the Program's thread block. This is easy in OllyDbg. You can do this before the program even starts to run, after Olly loads it.

NOTE THIS example works for Windows 2000 / XP.

Open your program in OllyDbg. Note the value of the FS register. On my 2000 system, it's 7FFDE000. Go to the hex dump window in Olly (at the bottom) and right click and say Go To->Expression and type in this value.

Now, at FS[30], which would be 7FFDE030 on my machine (30 bytes in ) there is another address, this points to the program's thread environment block (TEB). Select this address in the window by clicking and selecting it, then right click and say "Follow DWORD in dump". This address by the way in my 2000 system is 7FFDF000.

Now, 3 bytes in you will see a 01. This is telling windows the program is being debugged. Change it to a zero by selecting it, and just start typing in zero, zero. Olly brings up the memory edit window, after entering the zeros just push ok and now you are hidden from the IsDebuggerPresent detector, and you didn't modify or edit any program memory or API memory. In fact, the program hasn't even started yet.

-nt20

- 출처 - http://www.woodmann.com/forum/archive/index.php/t-5875.html 

'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
Reversing for Newbies (written by Lena)  (0) 2009.03.27
some instruction  (0) 2009.02.11

badcob Reversing

usleep에 대해서

2009. 1. 8. 10:30

cpu 점유율을 낮추기 위해서 쓰레드에서 usleep 함수를 써봤는데 난 문제가 없었지만 종종 segmentation fault 를 일으키며 프로그램이 죽는 현상이 있다는 글을 보고 select 함수를 써서 같은 기능을 구현하였다.

nanosleep 이라는 함수도 있던데 cpu 점유율을 낮추기 위해 이를 쓰는것은 때때로 select를 쓰는것보다 성능을 떨어뜨릴수 있다는 글을 봐서 사용하지 않았다.

'Sabzil' 카테고리의 다른 글

hey JJAAPPPHH ~  (4) 2009.08.17
hey JaPH  (1) 2009.08.12
6회 kisa 해킹방어대회 6번  (0) 2009.07.09
ABI (Application Binary Interface)  (0) 2009.03.17
Nefif_rx  (0) 2009.03.17
strtok_r  (0) 2008.09.29
this is RAM  (0) 2008.08.21
nit_if.h  (0) 2008.07.17
about ftp  (0) 2008.07.15
amd64 and x86 endian order  (0) 2008.06.23

badcob Sabzil

strtok_r

2008. 9. 29. 18:59

strtok strtok_r 함수 관련


 

이름

strtok, strtok_r - 문자열에서 토큰들을 뽑아낸다.  

사용법

#include <string.h>

 

char *strtok(char *s, const char *delim);

 

char *strtok_r(char *s, const char *delim, char **ptrptr);

 

설명

`토큰`이란 문자열 delim에 속하지 않는 문자들로 이루어진 비어 있지 않은 문자열이며 \0이나 delim에 있는 문자가 뒤따른다.

strtok() 함수는 문자열 s를 토큰으로 파싱하기 위해 사용된다. strtok()의 첫번째 인자로 s를 주면, 가장 앞에 있는 토큰을 구하고, 그 문자열안의 다음 토큰을 구하고자 할 때에는 첫번째 인자를 NULL로 설정하여야 한다. 각 호출은 다음 토큰에 대한 포인터를 반환하거나 더이상 토큰이 발견되지 않는다면 NULL을 반환한다.

 

토큰이 구분자로 끝난다면, 이 구분자는 \0로 겹쳐 쓰여지며 다음 문자에 대한 포인터가 strtok()에 대한 다음 호출을 위해 저장된다. 구분 문자열 delim는 각 호출시 다를수 있다.

 

strtok_r() 함수는 strtok() 와 동일하게 작동한다. 그러나 정적 버퍼를 사용하는 대신에 이 함수는 char * 포인터로 할당된 유저에 대한 포인터를 사용한다. 이 포인터, ptrptr 파라미터는 같은 문자열을 파싱하는 동안 같아야만 한다.  

 

버그

이 함수를 사용해서는 안된다. 만일 사용해야 한다면, 다음을 주의하라:

 

이 함수는 처음 인자를 수정한다.

구분자의 원본은 잃게 된다.

 

이 함수는 상수 문자열에서는 사용해서는 안된다.

 

strtok () 함수는 파싱하는 동안 정적 버퍼를 사용한다. 그래서 thread safe가 아니다. 만일 이것이 문제라면 strtok_r () 를 사용해라.

 

 

반환값

strtok() 함수는 다음 토큰에 대한 포인터를 반환하거나 만일 더 이상 토큰이 없다면 NULL을 반환한다.

'Sabzil' 카테고리의 다른 글

hey JaPH  (1) 2009.08.12
6회 kisa 해킹방어대회 6번  (0) 2009.07.09
ABI (Application Binary Interface)  (0) 2009.03.17
Nefif_rx  (0) 2009.03.17
usleep에 대해서  (0) 2009.01.08
this is RAM  (0) 2008.08.21
nit_if.h  (0) 2008.07.17
about ftp  (0) 2008.07.15
amd64 and x86 endian order  (0) 2008.06.23
glibc-2.5/elf/dl-runtime.c 코드 분석을 통한 lazy binding 재배치 방식 분석  (0) 2008.06.23

badcob Sabzil

this is RAM

2008. 8. 21. 13:42

DRAM PC 워크스테이션에 사용되는 가장 일반적인 종류의 램이다. 메모리는 컴퓨터가 데이터를 빠르게 액세스할 있게 0 1 형태로 저장할 있도록 전기적으로 충전된 점들의 네트웍이다. 랜덤 액세스라는 말은 프로세서가 어떤 시작 위치로부터 차례로 진행해야 하는 것이 아니라, 메모리 또는 데이터 저장공간의 어떤 부분이라도 직접 액세스 있다는 의미를 갖는다. DRAM SRAM과는 달리 주기적으로 밀리초 마다 한번씩 새로운 전하를 가함으로써 메모리 셀을 재생시켜 주어야한다. SRAM 메모리 셀이 전하를 제자리에 붙잡고 있는 대신에 전류가 하나의 방향으로 전환되며 움직이는 원리로 동작하기 때문에 재생회로가 필요치 않다. SRAM 일반적으로 DRAM보다 빨리 액세스할 있는 캐시 메모리에 사용된다.”

 

CAS(column address strobe), DRAM 칩에 액세스 하는데 사용되는 중요 시그널 중 하나이다. CAS 관련된 주소를 알려주기 위해 DRAM 보내지는 신호이다. DRAM 데이터 비트는 주소와 주소의 교점에 위치하는 하나의 안에 저장된다. 주소를 확인하기 위해서는 RAS 신호가 사용된다.

 

SDRAM

Syncronous DRAM으로 외부 Clock에 동기되어 동작하므로 SDRAM 이라고 하며 ClockRising Edge에 동기되어 동작한다 SDRAM의 어드레싱 기본원리는 column address, row address, bank address가 바로 (x,y,z)가 되어 직육면체의 어느 한 곳(=한바이트)를 지정하게 된다

 

SDRAM 액세스 동작의 순서는 nCS RAS(Row Address Strobe)신호를 활성화 시켜서 Row Address 주소버스에 실어준다. 다음 RAS 비활성화 시키고 CAS(Column Address
Strobe)
신호를 활성화 시키고, 읽기나 쓰기 동작에 따라서 nWE신호를 주면 되는 것이다.


결국 원하는 특정주소를 지정하고 나면, 거기서부터 Column Address 하나씩 증가시켜 가며 데이터를 버스트하게 액세스하는 것이다. 모든 동작은 CLK이라는 클럭에 positive edge 동기되어 동작한다. 여기서 CAS latency 라는 용어가 대두되는데, read 커맨드와 첫번째 유효한 데이타 사이의 딜레이이다. 단위는 clock cycle이고, 보통 2,3 값을 갖는다. , 2,3 클럭 사이클 이후에 실제 데이터가 데이타버스에 실린다는 뜻이다.


SDRAM
read, write 액세스 동작은 버스트(burst) 지향적이다. 말은 특정 어드레스의
데이타를 액세스할때, 바이트만을 하는게 아니라 한번에 여러 바이트를 액세스한다는 의미이다.  burst length 칩마다 다른데 보통 1,2,4,8, full page 정도이다.

[참고자료]
http://www.parkoz.com/zboard/view.php?id=overclock_tech&no=314


'Sabzil' 카테고리의 다른 글

6회 kisa 해킹방어대회 6번  (0) 2009.07.09
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
nit_if.h  (0) 2008.07.17
about ftp  (0) 2008.07.15
amd64 and x86 endian order  (0) 2008.06.23
glibc-2.5/elf/dl-runtime.c 코드 분석을 통한 lazy binding 재배치 방식 분석  (0) 2008.06.23
xss in 엠파스 게시판  (0) 2008.06.22

badcob Sabzil

nit_if.h

2008. 7. 17. 13:04

'Sabzil' 카테고리의 다른 글

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
about ftp  (0) 2008.07.15
amd64 and x86 endian order  (0) 2008.06.23
glibc-2.5/elf/dl-runtime.c 코드 분석을 통한 lazy binding 재배치 방식 분석  (0) 2008.06.23
xss in 엠파스 게시판  (0) 2008.06.22
sk_buff 구조체  (0) 2008.06.17

badcob Sabzil

about ftp

2008. 7. 15. 17:32

'Sabzil' 카테고리의 다른 글

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
nit_if.h  (0) 2008.07.17
amd64 and x86 endian order  (0) 2008.06.23
glibc-2.5/elf/dl-runtime.c 코드 분석을 통한 lazy binding 재배치 방식 분석  (0) 2008.06.23
xss in 엠파스 게시판  (0) 2008.06.22
sk_buff 구조체  (0) 2008.06.17

badcob Sabzil