logo       


Re: Don't allow newlines in URLs to end up in FTP commands: msg#00040

Subject: Re: Don't allow newlines in URLs to end up in FTP commands
Hrvoje Niksic <hniksic@xxxxxxxxxx> writes:

> A fix that applies to 1.9.1 follows in a separate mail.
> Distributors of Wget will probably want to make sure to include the
> appropriate patch.

Here is that fix.

2005-05-07  Hrvoje Niksic  <hniksic@xxxxxxxxxx>

        * ftp-basic.c (ftp_request): Prevent newlines in VALUE causing
        inadvertent sending of multiple FTP commands.

--- wget-1.9.1.pristine/src/ftp-basic.c 2003-11-08 20:17:55.000000000 +0100
+++ wget-1.9.1/src/ftp-basic.c  2005-05-07 03:08:02.306330903 +0200
@@ -116,9 +116,30 @@
 static char *
 ftp_request (const char *command, const char *value)
 {
-  char *res = (char *)xmalloc (strlen (command)
-                               + (value ? (1 + strlen (value)) : 0)
-                               + 2 + 1);
+  char *res;
+
+  /* Check for newlines in VALUE (possibly injected by the %0A URL
+     escape) making the callers inadvertently send multiple FTP
+     commands at once.  Without this check an attacker could
+     intentionally redirect to ftp://server/fakedir%0Acommand.../ and
+     execute arbitrary FTP command on a remote FTP server.  */
+  if (value && strpbrk (value, "\r\n"))
+    {
+      /* Copy VALUE to the stack and modify CR/LF to space. */
+      char *defanged, *p;
+      STRDUP_ALLOCA (defanged, value);
+      for (p = defanged; *p; p++)
+       if (*p == '\r' || *p == '\n')
+         *p = ' ';
+      DEBUGP (("\nDetected newlines in %s \"%s\"; changing to %s \"%s\"\n",
+              command, value, command, defanged));
+      /* Make VALUE point to the defanged copy of the string. */
+      value = defanged;
+    }
+
+  res = (char *)xmalloc (strlen (command)
+                        + (value ? (1 + strlen (value)) : 0)
+                        + 2 + 1);
   sprintf (res, "%s%s%s\r\n", command, value ? " " : "", value ? value : "");
   if (opt.server_response)
     {



Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosting, windows, cisco ...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe