exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

javamail_dir_travers.txt

javamail_dir_travers.txt
Posted Apr 18, 2005
Authored by Rafael San Miguel Carrasco | Site dvc.es

JavaMail is vulnerable to a directory-traversal attack where files can be written to an arbitrary location within the filesystem, by specifying a Content-Disposition header which contains a relative path.

tags | advisory, arbitrary
SHA-256 | 0d8d9c543b406aa12fb6d97ffbe7d720e1c2adf4a994ee527ee49219e237ba7f

javamail_dir_travers.txt

Change Mirror Download

1. INTRODUCTION

The JavaMail API provides a platform-independent and
protocol-independent framework to build mail and messaging applications.
The JavaMail API is implemented as a Java platform optional package and
is also available as part of the Java 2 platform, Enterprise Edition.


2. SYNOPSIS

MimeBodyPart.getFileName () method in the JavaMail API doesn't properly
validate filename attribute in Content-Disposition header, what makes it
vulnerable to directory traversal attacks. Successful exploitation of
this vulnerability allows writing arbitrary content in any directory
accessible to the servlet running JavaMail.


3. AFFECTED VERSIONS

This vulnerability has been checked in current release, JavaMail 1.3.2.
It may be present in all previous versions.


4. EXPLOITATION PROCEDURE

Send an email with the following filename attribute in
Content-Disposition header:

../../../file.ext

This will write attachment three directories backward from expected
location, as long as the servlet processing the email has writeable
access to that directory.


5. EXAMPLE SCENARIO

This method uses getFileName () method to save the first attachment into
a file:

protected void saveMailAttachment (javax.mail.internet.MimeMultipart mp) {
try {
int n = mp.getCount();
javax.mail.Part p = mp.getBodyPart (0);
String disposition = p.getDisposition ();

if (disposition != null &&
(disposition.equalsIgnoreCase (javax.mail.Part.ATTACHMENT)
|| disposition.equalsIgnoreCase (javax.mail.Part.INLINE) ) ) {

String filename = p.getFileName ();
File f = new File (filename);
OutputStream os = new BufferedOutputStream (new FileOutputStream (f) );
InputStream is = p.getInputStream ();
int c;
while ( (c = is.read () ) != -1)
os.write (c);
os.close ();
}
} catch (Exception e) { }
}


6. API DOCUMENTATION

getFileName

public java.lang.String getFileName() throws MessagingException

Get the filename associated with this part, if possible. Useful if this
part represents an "attachment" that was loaded from a file. The
filename will usually be a simple name, not including directory components.

Returns: Filename to associate with this part


7. VULNERABLE SOURCE CODE

The following code has been obtained by decompiling JavaMail
MimeBodyPart class file. Although JavaMail source code is available from
Sun’s site, checking this vulnerability over binaries is somewhat more
reliable.

MimeBodyPart.java:

public String getFileName () throws MessagingException {
return getFileName ( ( (MimePart) (this) ) );
}

static String getFileName (MimePart mimepart) throws MessagingException {

String s = null;
String s1 = mimepart.getHeader ("Content-Disposition", null);

if (s1 != null) {
ContentDisposition contentdisposition = new ContentDisposition (s1);
s = contentdisposition.getParameter("filename");
}

if (s == null) {
String s2 = mimepart.getHeader ("Content-Type", null);
if (s2 != null)
try {
ContentType contenttype = new ContentType (s2);
s = contenttype.getParameter ("name");
} catch (ParseException _ex) { }
}

if (decodeFileName && s != null) {
try {
s = MimeUtility.decodeText(s);
} catch(UnsupportedEncodingException unsupportedencodingexception) {
throw new MessagingException
("Can't decode filename", unsupportedencodingexception);
}
}

return s;
}

Not that no check for directory traversal patterns is performed.


8. CURRENT WORKAROUND

Input validation mechanism should be enforced in the servlet being
developed. No patches are available for this issue.


9. MORE INFORMATION

http://java.sun.com/products/javamail/

-------------------------------
Rafael San Miguel Carrasco
Security Consultant
rafael.sanmiguel@dvc.es
+ 34 660 856 647
+ 34 902 464 546
Davinci Consulting - www.dvc.es
Oficina Madrid - Parque empresarial Alvento
Via de los Poblados 1 Edificio A 6ยช planta
28033 Madrid
-------------------------------

Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    28 Files
  • 7
    May 7th
    3 Files
  • 8
    May 8th
    4 Files
  • 9
    May 9th
    54 Files
  • 10
    May 10th
    12 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    17 Files
  • 14
    May 14th
    11 Files
  • 15
    May 15th
    17 Files
  • 16
    May 16th
    13 Files
  • 17
    May 17th
    22 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    0 Files
  • 21
    May 21st
    0 Files
  • 22
    May 22nd
    0 Files
  • 23
    May 23rd
    0 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close