L28 - Security 1
L28 - Security 1
L28 - Security 1
SQL Injections, Cross Site Scripting, Request Forgery, and Cookie Stealing
COS216
AVINASH SINGH
DEPARTMENT OF COMPUTER SCIENCE
UNIVERSITY OF PRETORIA
Website Attacks
$statement = $connection->prepare(
"INSERT INTO student (firstname, lastname) VALUES (?, ?)");
$statement->bind_param("ss", $firstname, $lastname);
$firstname = "Jacob";
$lastname = "Zuma";
$statement->execute();
$firstname = "Mmusi";
$lastname = "Maimane";
$statement->execute();
Malicious user enters JavaScript code into an HTML input (eg: comment box)
The JS code is saved as a string on the server
Other users who visit the site also see the posted comment which now has
embedded hidden malicious JavaScript code
The malicious code can be used to do pretty much anything (eg: stealing cookies, making
external GET/POST requests, creating annoying popups, etc)
Script Injections
You can write a malicious website that accessed the information stored in cookies by
other websites
You can use the session ID in cookies in order to make authenticated requests on that
site (this is actually cross site request forgery)
Cookie Stealing
Due to modern browser’s Same Origin Policy you cannot access a cookie from
another domain
Only the domain that created the cookie can later read it
Also applies to subdomains: one subdomain cannot access the cookies from another
subdomain, even if they are both part of the same main domain
This could be due to multiple problems or issues with the way authentication is done.
Here are the most common ways this happens:
URL contains the session ID or adds the session when getting external sources (AJAX)
No password encryption or hashing
Session IDs might be predictable (e.g. if session IDs are not complex and are sequential)
No SSL, not implementing timeouts for sessions
Security Misconfiguration
Typically this is the most important step when securing your website/server, some of
the common misconfigurations include:
Running debug mode
Enabling Directory listing
Running outdated software with vulnerabilities (WordPress, etc)
Not Changing DEFALT keys and passwords
Revealing Error/Exception information (tracebacks)