CWE-379: Creation of Temporary File in Directory with Insecure Permissions
Description
The product creates a temporary file in a directory whose permissions allow unintended actors to determine the file's existence or otherwise access that file.
Submission Date :
July 19, 2006, midnight
Modification Date :
2023-10-26 00:00:00+00:00
Organization :
MITRE
Extended Description
On some operating systems, the fact that the temporary file exists may be apparent to any user with sufficient privileges to access that directory. Since the file is visible, the application that is using the temporary file could be known. If one has access to list the processes on the system, the attacker has gained information about what the user is doing at that time. By correlating this with the applications the user is running, an attacker could potentially discover what a user's actions are. From this, higher levels of security could be breached.
Example - 1
In the following code examples a temporary file is created and written to. After using the temporary file, the file is closed and deleted from the file system. However, within this C/C++ code the method tmpfile() is used to create and open the temp file. The tmpfile() method works the same way as the fopen() method would with read/write permission, allowing attackers to read potentially sensitive information contained in the temp file or modify the contents of the file. Similarly, the createTempFile() method used in the Java code creates a temp file that may be readable and writable to all users. Additionally both methods used above place the file into a default directory. On UNIX systems the default directory is usually "/tmp" or "/var/tmp" and on Windows systems the default directory is usually "C:\\Windows\\Temp", which may be easily accessible to attackers, possibly enabling them to read and modify the contents of the temp file.
perror("Could not open new temporary file\n");return (-1);
// // write data to tmp file//
FILE *stream;if( (stream = tmpfile()) == NULL ) {}...// remove tmp filermtmp();
File temp = File.createTempFile("pattern", ".suffix");temp.deleteOnExit();BufferedWriter out = new BufferedWriter(new FileWriter(temp));out.write("aString");out.close();
try {}catch (IOException e) {}
Related Weaknesses
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.
Visit http://cwe.mitre.org/ for more details.