nemo의 이야기

시스템 콜(System call) 본문

Information security/System security

시스템 콜(System call)

nemojjong 2017. 8. 16. 14:09
시스템 콜을 이용하는 목적

  - 커널 메모리에 접근이 불가능해서 interface 메모리를 이용해서 커널에 접근하기 위해서 이다.


C언어에서는 시스템 콜에 대해 라이브러리 형태로 제공한다.


어셈블리어는 eax, ebx, ecx, edx를 이용해서 write, read와 같은 함수를 사용할 수 있다.


시스템 콜에 대한 참고 사이트 :  http://www.lxhp.in-berlin.de/lhpsyscal.html


ex) exit(0)

  

  mov    eax,    1

  mov    ebx,    0

  int      0x80


형태로 eax, ebx에 값으로 어떤 종류 함수인지 인자 값을 넣는다.


마지막 int 0x80으로 마쳐 system call을 호출한다. 


연습으로 표준입력으로 명령어를 입력받아서 입력받은 명령어를 실행하는 어셈블 프로그램을 작성해보자



segment         .text

global          _start


_start

        push    ebp

        mov     ebp,    esp

        sub     esp,    1036    ;argv[2] = 8byte


        mov     ecx,    256

        xor     eax,    eax

        lea     edi,    [ebp-1024]

        rep     stosd


        mov     dword [ebp-1028],       0

        mov     dword [ebp-1032],       0

        mov     dword [ebp-1036],       0


        mov     eax,    3

        mov     ebx,    0

        lea     ecx,    [ebp-1024]

        mov     edx,    1024

        int     0x80


while_len:

        mov     eax,    [ebp-1036]

        lea     ebx,    [ebp-1024]


        cmp     dword [eax+ebx],        0

        je      while_end               ;escape

        inc     dword [ebp-1036]

        jmp     while_len               ;while loop

while_end:

        mov     eax,    [ebp-1036]

        lea     ebx,    [ebp-1024]


        mov     byte [ebx+eax-1], 0


        lea     eax,    [ebp-1024]      ;file

        mov     dword[ebp-1032],        eax    ;argv[0] = file

        mov     dword[ebp-1028],        0 ;argv[1] = NULL


        mov     eax,    11 ;execve

        lea     ebx,    [ebp-1024]

        lea     ecx,    [ebp-1032]

        mov     edx,    0

        int     0x80


        mov     eax,    1

        mov     ebx,    0


결과




'Information security > System security' 카테고리의 다른 글

워 게임(overthewire) leviathan0  (0) 2017.08.21
gdb 기초  (0) 2017.08.20
argc, argv에 이해  (0) 2017.08.14
어셈블리 함수  (0) 2017.08.12
메모리 구조  (0) 2017.08.11
Comments