Web Hacking

image.png

코드 공부하기

<aside> 💡

게시판 구동 방법

  1. my_simple_board로 이동 (리눅스에서 파일다운하고)
  2. docker compose up 명령어
  3. 웹브라우저를 통해 8000포트로 접속

image.png

</aside>

Reverse Engineering == Reversing

#include <stdio.h>

int enc[17] = {75, 104, 111, 111, 114, 35, 71, 117, 104, 100, 112, 107, 100, 102, 110, 36, 3};

int main(){

    int key = 0;
    int dec[17];

    for(int i=0; i<17; i++){
        printf("%c", enc[i]);
    }

    printf("\\nYour input: ");
    scanf("%d", &key);

    for(int i=0; i<17; i++){
        dec[i] = enc[i] - key;
        printf("%c", dec[i]);
    }
    printf("\\n");

    return 0;
}
Dump of assembler code for function main:
   0x00005555555551a9 <+0>:     endbr64 
   0x00005555555551ad <+4>:     push   rbp
   0x00005555555551ae <+5>:     mov    rbp,rsp
   0x00005555555551b1 <+8>:     sub    rsp,0x60
   0x00005555555551b5 <+12>:    mov    rax,QWORD PTR fs:0x28
   0x00005555555551be <+21>:    mov    QWORD PTR [rbp-0x8],rax
   0x00005555555551c2 <+25>:    xor    eax,eax
   0x00005555555551c4 <+27>:    mov    DWORD PTR [rbp-0x5c],0x0
   0x00005555555551cb <+34>:    mov    DWORD PTR [rbp-0x58],0x0
   0x00005555555551d2 <+41>:    jmp    0x5555555551f6 <main+77>
   0x00005555555551d4 <+43>:    mov    eax,DWORD PTR [rbp-0x58]
   0x00005555555551d7 <+46>:    cdqe   
   0x00005555555551d9 <+48>:    lea    rdx,[rax*4+0x0]
   0x00005555555551e1 <+56>:    lea    rax,[rip+0x2e38]        # 0x555555558020 <enc>
   0x00005555555551e8 <+63>:    mov    eax,DWORD PTR [rdx+rax*1]
   0x00005555555551eb <+66>:    mov    edi,eax
   0x00005555555551ed <+68>:    call   0x555555555080 <putchar@plt>
   0x00005555555551f2 <+73>:    add    DWORD PTR [rbp-0x58],0x1
   0x00005555555551f6 <+77>:    cmp    DWORD PTR [rbp-0x58],0x10
   0x00005555555551fa <+81>:    jle    0x5555555551d4 <main+43>
   0x00005555555551fc <+83>:    lea    rax,[rip+0xe01]        # 0x555555556004
   0x0000555555555203 <+90>:    mov    rdi,rax
   0x0000555555555206 <+93>:    mov    eax,0x0
   0x000055555555520b <+98>:    call   0x5555555550a0 <printf@plt>
   0x0000555555555210 <+103>:   lea    rax,[rbp-0x5c]
   0x0000555555555214 <+107>:   mov    rsi,rax
   0x0000555555555217 <+110>:   lea    rax,[rip+0xdf4]        # 0x555555556012
   0x000055555555521e <+117>:   mov    rdi,rax
   0x0000555555555221 <+120>:   mov    eax,0x0
   0x0000555555555226 <+125>:   call   0x5555555550b0 <__isoc99_scanf@plt>
   0x000055555555522b <+130>:   mov    DWORD PTR [rbp-0x54],0x0
   0x0000555555555232 <+137>:   jmp    0x55555555526f <main+198>
   0x0000555555555234 <+139>:   mov    eax,DWORD PTR [rbp-0x54]
   0x0000555555555237 <+142>:   cdqe   
   0x0000555555555239 <+144>:   lea    rdx,[rax*4+0x0]
   0x0000555555555241 <+152>:   lea    rax,[rip+0x2dd8]        # 0x555555558020 <enc>
   0x0000555555555248 <+159>:   mov    eax,DWORD PTR [rdx+rax*1]
   0x000055555555524b <+162>:   mov    ecx,DWORD PTR [rbp-0x5c]
   0x000055555555524e <+165>:   sub    eax,ecx
   0x0000555555555250 <+167>:   mov    edx,eax
   0x0000555555555252 <+169>:   mov    eax,DWORD PTR [rbp-0x54]
   0x0000555555555255 <+172>:   cdqe   
   0x0000555555555257 <+174>:   mov    DWORD PTR [rbp+rax*4-0x50],edx
   0x000055555555525b <+178>:   mov    eax,DWORD PTR [rbp-0x54]
   0x000055555555525e <+181>:   cdqe   
   0x0000555555555260 <+183>:   mov    eax,DWORD PTR [rbp+rax*4-0x50]
   0x0000555555555264 <+187>:   mov    edi,eax
   0x0000555555555266 <+189>:   call   0x555555555080 <putchar@plt>
   0x000055555555526b <+194>:   add    DWORD PTR [rbp-0x54],0x1
   0x000055555555526f <+198>:   cmp    DWORD PTR [rbp-0x54],0x10
   0x0000555555555273 <+202>:   jle    0x555555555234 <main+139>
   0x0000555555555275 <+204>:   mov    edi,0xa
   0x000055555555527a <+209>:   call   0x555555555080 <putchar@plt>
   0x000055555555527f <+214>:   mov    eax,0x0
   0x0000555555555284 <+219>:   mov    rdx,QWORD PTR [rbp-0x8]
   0x0000555555555288 <+223>:   sub    rdx,QWORD PTR fs:0x28
   0x0000555555555291 <+232>:   je     0x555555555298 <main+239>
   0x0000555555555293 <+234>:   call   0x555555555090 <__stack_chk_fail@plt>
   0x0000555555555298 <+239>:   leave  
   0x0000555555555299 <+240>:   ret    
End of assembler dump.

image.png

System Hacking

💡 원격 환경의 공격자가 타겟 서버에서 운영체제의 명령어를 실행할 수 있는 공격을 원격 코드 실행(Remote Code Execution; RCE)

#include <stdio.h>

void fun (int x, int y)
{
	int z;	
	char buf[100];
	
	z = x;
	read (0, buf, y);

	printf ("x is %d\\n", x);
	//printf (“z is %d\\n”, z);
}

int main (int argc, char* argv[])
{
	int a, b;
	a = 30;
	b = 300;

	fun (a,b);
}

image.png