From b0cf064f819357feedc77d6d5eb0de49e122554a Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 16 Jun 2018 22:50:18 +0200 Subject: Added command injection example and secured examples --- examples-secure/xss/index.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples-secure/xss/index.php (limited to 'examples-secure/xss/index.php') 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 @@ +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 'Comments' . + '

Comments

'; + + $db = new MyDB(); + + $sql = 'SELECT * FROM Comments'; + $ret = $db->query($sql); + while ($row = $ret->fetchArray(SQLITE3_ASSOC)) + echo '

' . $row['user'] . ' says:
' . htmlspecialchars($row['comment'], ENT_QUOTES, 'UTF-8'). '

'; + + $db->close(); + + echo '

Add comment

' . + '
' . + '
' . + '
' . + '
'; +?> -- cgit v1.2.3