Dark Mode

Settings

Capec-77 Detail

Manipulating User-Controlled Variables

Standard Software Likelihood: High Typical Severity: Very High

Parents: 22

Children: 13 162

Threats: T271 T293

Description

This attack targets user controlled variables (DEBUG=1, PHP Globals, and So Forth). An adversary can override variables leveraging user-supplied, untrusted query variables directly used on the application server without any data sanitization. In extreme cases, the adversary can change variables controlling the business logic of the application. For instance, in languages like PHP, a number of poorly set default configurations may allow the user to override variables.

Not present

External ID Source Link Description
CAPEC-77 capec https://capec.mitre.org/data/definitions/77.html
CWE-15 cwe http://cwe.mitre.org/data/definitions/15.html
CWE-94 cwe http://cwe.mitre.org/data/definitions/94.html
CWE-96 cwe http://cwe.mitre.org/data/definitions/96.html
CWE-285 cwe http://cwe.mitre.org/data/definitions/285.html
CWE-302 cwe http://cwe.mitre.org/data/definitions/302.html
CWE-473 cwe http://cwe.mitre.org/data/definitions/473.html
CWE-1321 cwe http://cwe.mitre.org/data/definitions/1321.html
REF-1 reference_from_CAPEC G. Hoglund, G. McGraw, Exploiting Software: How to Break Code, 2004--02, Addison-Wesley
REF-520 reference_from_CAPEC http://www.securityfocus.com/infocus/1706 Artur Maj, Securing PHP: Step-by-Step, 2003--06---22, Security Focus
REF-521 reference_from_CAPEC Clancy Malcolm, Ten Security Checks for PHP, Part 1, 2003--03---20
REF-522 reference_from_CAPEC http://www.php.net/manual/en/security.globals.php PHP Manual, The PHP Group
Explore
  1. Probe target application: The adversary first probes the target application to determine important information about the target. This information could include types software used, software versions, what user input the application consumes, and so on.

Experiment
  1. Find user-controlled variables: Using the information found by probing the application, the adversary attempts to manipulate many user-controlled variables and observes the effects on the application. If the adversary notices any significant changes to the application, they will know that a certain variable is useful to the application.

  2. Techniques
    Adversaries will try to alter many common variable names such as "count", "tempFile", "i", etc. The hope is that they can alter the flow of the application without knowing the inner-workings.
    Adversaries will try to alter known environment variables.
Exploit
  1. Manipulate user-controlled variables: Once the adversary has found a user-controller variable(s) that is important to the application, they will manipulate it to change the normal behavior in a way that benefits the adversary.

  1. A variable consumed by the application server is exposed to the client.
  2. A variable consumed by the application server can be overwritten by the user.
  3. The application server trusts user supplied data to compute business logic.
  4. The application server does not perform proper input validation.

Not present

Low Medium
The malicious user can easily try some well-known global variables and find one which matches.
The adversary can use automated tools to probe for variables that they can control.
Integrity Availability Authorization Access Control Confidentiality
Modify Data Execute Unauthorized Commands (Run Arbitrary Code) Gain Privileges Gain Privileges Execute Unauthorized Commands (Run Arbitrary Code)
Execute Unauthorized Commands (Run Arbitrary Code) Read Data
Gain Privileges
  1. PHP is a study in bad security. The main idea pervading PHP is "ease of use," and the mantra "don't make the developer go to any extra work to get stuff done" applies in all cases. This is accomplished in PHP by removing formalism from the language, allowing declaration of variables on first use, initializing everything with preset values, and taking every meaningful variable from a transaction and making it available. In cases of collision with something more technical, the simple almost always dominates in PHP. One consequence of all this is that PHP allows users of a Web application to override environment variables with user-supplied, untrusted query variables. Thus, critical values such as the CWD and the search path can be overwritten and directly controlled by a remote anonymous user. Another similar consequence is that variables can be directly controlled and assigned from the user-controlled values supplied in GET and POST request fields. So seemingly normal code like this, does bizarre things: while($count < 10){// Do something$count++;} Normally, this loop will execute its body ten times. The first iteration will be an undefined zero, and further trips though the loop will result in an increment of the variable $count. The problem is that the coder does not initialize the variable to zero before entering the loop. This is fine because PHP initializes the variable on declaration. The result is code that seems to function, regardless of badness. The problem is that a user of the Web application can supply a request such as GET /login.php?count=9 and cause $count to start out at the value 9, resulting in only one trip through the loop. Yerg. Depending on the configuration, PHP may accept user-supplied variables in place of environment variables. PHP initializes global variables for all process environment variables, such as $PATH and $HOSTNAME. These variables are of critical importance because they may be used in file or network operations. If an adversary can supply a new $PATH variable (such as PATH='/var'), the program may be exploitable. PHP may also take field tags supplied in GET/POST requests and transform them into global variables. This is the case with the $count variable we explored in our previous example. Consider another example of this problem in which a program defines a variable called $tempfile. An adversary can supply a new temp file such as $tempfile = "/etc/passwd". Then the temp file may get erased later via a call to unlink($tempfile);. Now the passwd file has been erased--a bad thing indeed on most OSs. Also consider that the use of include() and require() first search $PATH, and that using calls to the shell may execute crucial programs such as ls. In this way, ls may be "Trojaned" (the adversary can modify $PATH to cause a Trojan copy of ls to be loaded). This type of attack could also apply to loadable libraries if $LD_LIBRARY_PATH is modified. Finally, some versions of PHP may pass user data to syslog as a format string, thus exposing the application to a format string buffer overflow.See also: File upload allows arbitrary file read by setting hidden form variables to match internal variable names (CVE-2000-0860)