diff options
author | marcinzelent <zelent.marcin@gmail.com> | 2018-06-16 22:50:18 +0200 |
---|---|---|
committer | marcinzelent <zelent.marcin@gmail.com> | 2018-06-16 22:50:18 +0200 |
commit | b0cf064f819357feedc77d6d5eb0de49e122554a (patch) | |
tree | 2ba0defb81576326dbc25736174100bfd43f677c /examples-secure/xss/index.php | |
parent | 7d93b9b60f0923b0f895d63b2d456b279a6ab774 (diff) |
Added command injection example and secured examples
Diffstat (limited to 'examples-secure/xss/index.php')
-rw-r--r-- | examples-secure/xss/index.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples-secure/xss/index.php b/examples-secure/xss/index.php new file mode 100644 index 0000000..7bc3d45 --- /dev/null +++ b/examples-secure/xss/index.php @@ -0,0 +1,36 @@ +<?php + class MyDB extends SQLite3 { + function __construct() { + $this->open('comments.db'); + } + } + + if (isset($_POST['user'], $_POST['comment'])) { + $user = $_POST['user']; + $comment = $_POST['comment']; + + $db = new MyDB(); + + $sql = 'INSERT INTO Comments VALUES(\'' . $user . '\',\'' . $comment . '\')'; + $ret = $db->exec($sql); + $db->close(); + } + + echo '<!DOCTYPE HTML><html><head><title>Comments</title>' . + '<meta charset="utf-8"></head><body><h1>Comments</h1>'; + + $db = new MyDB(); + + $sql = 'SELECT * FROM Comments'; + $ret = $db->query($sql); + while ($row = $ret->fetchArray(SQLITE3_ASSOC)) + echo '<p><b>' . $row['user'] . '</b> says:<br>' . htmlspecialchars($row['comment'], ENT_QUOTES, 'UTF-8'). '</p>'; + + $db->close(); + + echo '<h2>Add comment</h1><form action="index.php" method="post">' . + '<input type="text" name="user" placeholder="User name"><br>' . + '<input type="text" name="comment" placeholder="Comment"><br>' . + '<input type="submit" value="Add"><br>' . + '</form></body></html>'; +?> |