CWE-732: Incorrect Permission Assignment for Critical Resource

Export to Word

Description

The product specifies permissions for a security-critical resource in a way that allows that resource to be read or modified by unintended actors.

Extended Description

When a resource is given a permission setting that provides access to a wider range of actors than required, it could lead to the exposure of sensitive information, or the modification of that resource by unintended parties. This is especially dangerous when the resource is related to program configuration, execution, or sensitive user data. For example, consider a misconfigured storage account for the cloud that can be read or written by a public or anonymous user.


ThreatScore

Threat Mapped score: 3.25

Industry: Finiancial

Threat priority: P2 - Serious (High)


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)


Attack TTPs

Malware

APTs (Intrusion Sets)

Modes of Introduction

Phase Note
Architecture and Design N/A
Implementation REALIZATION: This weakness is caused during implementation of an architectural security tactic. The developer might make certain assumptions about the environment in which the product operates - e.g., that the software is running on a single-user system, or the software is only accessible to trusted administrators. When the software is running in a different environment, the permissions become a problem.
Installation The developer may set loose permissions in order to minimize problems when the user first runs the program, then create documentation stating that permissions should be tightened. Since system administrators and users do not always read the documentation, this can result in insecure permissions being left unchanged.
Operation N/A

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: The following code sets the umask of the process to 0 before creating a file and writing "Hello world" into the file.

Body: After running this program on a UNIX system, running the "ls -l" command might return the following output:

#define OUTFILE "hello.out" umask(0); FILE *out; /* Ignore link following (CWE-59) for brevity */ out = fopen(OUTFILE, "w"); if (out) { fprintf(out, "hello world!\n"); fclose(out); }

Intro: This code creates a home directory for a new user, and makes that user the owner of the directory. If the new directory cannot be owned by the user, the directory is deleted.

Body: Because the optional "mode" argument is omitted from the call to mkdir(), the directory is created with the default permissions 0777. Simply setting the new user as the owner of the directory does not explicitly change the permissions of the directory, leaving it with the default. This default allows any user to read and write to the directory, allowing an attack on the user's files. The code also fails to change the owner group of the directory, which may result in access by unexpected groups.

function createUserDir($username){ $path = '/home/'.$username; if(!mkdir($path)){ return false; } if(!chown($path,$username)){ rmdir($path); return false; } return true; }

Intro: The following code snippet might be used as a monitor to periodically record whether a web site is alive. To ensure that the file can always be modified, the code uses chmod() to make the file world-writable.

Body: The first time the program runs, it might create a new file that inherits the permissions from its environment. A file listing might look like:

$fileName = "secretFile.out"; if (-e $fileName) { chmod 0777, $fileName; } my $outFH; if (! open($outFH, ">>$fileName")) { ExitError("Couldn't append to $fileName: $!"); } my $dateString = FormatCurrentTime(); my $status = IsHostAlive("cwe.mitre.org"); print $outFH "$dateString cwe status: $status!\n"; close($outFH);

Intro: This program creates and reads from an admin file to determine privilege information.

Body: If the admin file doesn't exist, the program will create one. In order to create the file, the program must have write privileges to write to the file. After the file is created, the permissions need to be changed to read only.

const adminFile = "/etc/admin-users" func createAdminFileIfNotExists() error { file, err := os.Create(adminFile) if err != nil { return err } return nil } func changeModeOfAdminFile() error { fileMode := os.FileMode(0440) if err := os.Chmod(adminFile, fileMode); err != nil { return err } return nil }

Intro: The following command recursively sets world-readable permissions for a directory and all of its children:

Body: If this command is run from a program, the person calling the program might not expect that all the files under the directory will be world-readable. If the directory is expected to contain private data, this could become a security problem.

chmod -R ugo+r DIRNAME

Intro: The following Azure command updates the settings for a storage account:

Body: However, "Allow Blob Public Access" is set to true, meaning that anonymous/public users can access blobs.

az storage account update --name <storage-account> --resource-group <resource-group> --allow-blob-public-access true

Intro: The following Google Cloud Storage command gets the settings for a storage account named 'BUCKET_NAME':

Body: Suppose the command returns the following result:

gsutil iam get gs://BUCKET_NAME

Notes

← Back to CWE list