Tips & theory

libc database. local에서 사용해보자.

wyv3rn 2023. 1. 7. 22:39
728x90
반응형

서론

사실 매번 

libc-database

 

libc-database

 

libc.rip

에서 검색해서 사용했는데, local에서 사용할 수 있는 방법이 있다.

 

예전부터 알고 있었는데 사실 그냥 귀찮아서 자세히 찾아보지 않았었고,

그닥 필요 없을거라 생각해서 안썼는데,

CTF를 뛰다 ld 파일을 구하기가 힘들어서 사용하게 되었다.

 

설치

github를 통해 다운로드 가능하다.

GitHub - niklasb/libc-database: Build a database of libc offsets to simplify exploitation

 

GitHub - niklasb/libc-database: Build a database of libc offsets to simplify exploitation

Build a database of libc offsets to simplify exploitation - GitHub - niklasb/libc-database: Build a database of libc offsets to simplify exploitation

github.com

 

또는 아래 명령어로 다운로드 하면 된다.

$ git clone https://github.com/niklasb/libc-database

 

설치 후 다운로드된 폴더에 들어가서

$ ./get ubuntu

와 같이 원하는 os에 따라 libc를 다운로드 해줘야한다.

지원되는 os는 아래와 같고

Please specify libc categories to download:
        * ubuntu
        * debian
        * rpm
        * centos
        * arch                                                  
        * alpine
        * kali
        * parrotsec
        * launchpad

all 또는 원하는 부분만 다운로드 가능하다.

$ ./get ubuntu rpm arch
$ ./get all

 

만일 ./get 을 하였는데, 뭔가 다운로드 되지 않는다면(다운로드 하는데 한참 걸림.)

requirement를 충족시키지 못했기 때문이다.

os에 따라 아래 프로그램들이 설치되어있는지 확인해서 누락되었다면 추가로 설치해주자

### General

To run these scripts, you will need following command on your PATH:

* readelf
* objdump
* strings
* perl
* find
* grep
* md5sum
* sha1sum
* sha256sum
* file


### Debian-based (Ubuntu, Debian, Kali Linux, ParrotSec)

* mktemp
* perl
* wget
* ar
* tar
* grep
* zstd


### RPM-based (category 'rpm')

* mktemp
* perl
* wget
* rpm2cpio
* cpio
* grep


### CentOS-based

In addition to the RPM-Based requirements, you will need:

* wget
* gzip
* grep


### Pacman-based

* mktemp
* perl
* grep
* sed
* cat
* wget
* zstd
* xz-utils
* tar


### APK Based

* mktemp
* perl
* wget
* tar
* gzip
* grep


### Launchpad-based

In addition to the Debian-based requirements, you will need:

* jq


### Install everything

To install everything on Debian 10, run these commands:

```sh
apt-get update
apt-get install -y \
  binutils file \
  wget \
  rpm2cpio cpio \
  zstd jq
```

 

사용법

./get 명령어를 통해 libc를 다운로드 받았다면 아래와 같이 사용 가능하다.

 

custom libc 추가하기

$ ./add /usr/lib/libc-2.21.so

 

libc 찾기

$ ./find printf 260 puts f30
    archive-glibc (libc6_2.19-10ubuntu2_i386)
$ ./find __libc_start_main_ret a83
    ubuntu-trusty-i386-libc6 (libc6_2.19-0ubuntu6.6_i386)
    archive-eglibc (libc6_2.19-0ubuntu6_i386)
    ubuntu-utopic-i386-libc6 (libc6_2.19-10ubuntu2.3_i386)
    archive-glibc (libc6_2.19-10ubuntu2_i386)
    archive-glibc (libc6_2.19-15ubuntu2_i386)

 

libc로부터 주요 offset 가져오기

$ ./dump libc6_2.19-0ubuntu6.6_i386
    offset___libc_start_main_ret = 0x19a83
    offset_system = 0x00040190
    offset_dup2 = 0x000db590
    offset_recv = 0x000ed2d0
    offset_str_bin_sh = 0x160a24

 

hash로 libc 찾기

$ ./identify bid=ebeabf5f7039f53748e996fc976b4da2d486a626
    libc6_2.17-93ubuntu4_i386
$ ./identify md5=af7c40da33c685d67cdb166bd6ab7ac0
    libc6_2.17-93ubuntu4_i386
$ ./identify sha1=9054f5cb7969056b6816b1e2572f2506370940c4
    libc6_2.17-93ubuntu4_i386
$ ./identify sha256=8dc102c06c50512d1e5142ce93a6faf4ec8b6f5d9e33d2e1b45311aef683d9b2
    libc6_2.17-93ubuntu4_i386

 

libc & ld download

사실 이게 필요했다 ㅋ

    $ ./download libc6_2.23-0ubuntu10_amd64
    Getting libc6_2.23-0ubuntu10_amd64
        -> Location: http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6_2.23-0ubuntu10_amd64.deb
        -> Downloading package
        -> Extracting package
        -> Package saved to libs/libc6_2.23-0ubuntu10_amd64
    $ ls libs/libc6_2.23-0ubuntu10_amd64
    ld-2.23.so ... libc.so.6 ... libpthread.so.0 ...

 

728x90
반응형