19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 19 n Finding Vulnerabilities in Source Code 713<br />

Table 19-2: APIs Used to Interact with <strong>the</strong> User’s Session on <strong>the</strong> Java Platform<br />

API<br />

setAttribute<br />

DESCRIPTION<br />

Used to store data within <strong>the</strong> current session.<br />

putValue<br />

getAttribute<br />

Used to query data stored within <strong>the</strong> current session.<br />

getValue<br />

getAttributeNames<br />

getValueNames<br />

Potentially Dangerous APIs<br />

This section describes some common Java APIs that can introduce security<br />

vulnerabilities if used in an unsafe manner.<br />

File Access<br />

The main class used to access files and directories in Java is java.io.File.<br />

From a security perspective, <strong>the</strong> most interesting uses of this class are calls to<br />

its constructor, which may take a parent directory and filename, or simply a<br />

pathname.<br />

Whichever form of <strong>the</strong> constructor is used, path traversal vulnerabilities<br />

may exist if user-controllable data is passed as <strong>the</strong> filename parameter without<br />

checking for dot-dot-slash sequences. For example, <strong>the</strong> following code opens a<br />

file in <strong>the</strong> root of <strong>the</strong> C:\ drive on Windows:<br />

String userinput = “..\\boot.ini”;<br />

File f = new File(“C:\\temp”, userinput);<br />

The classes most commonly used for reading and writing file contents in<br />

Java are:<br />

n java.io.FileInputStream<br />

n java.io.FileOutputStream<br />

n java.io.FileReader<br />

n java.io.FileWriter<br />

These classes take a File object in <strong>the</strong>ir constructors or may open a file<br />

<strong>the</strong>mselves via a filename string, which may again introduce path traversal<br />

vulnerabilities if user-controllable data is passed as this parameter. For example:<br />

String userinput = “..\\boot.ini”;<br />

FileInputStream fis = new FileInputStream(“C:\\temp\\” + userinput);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!