Lab - Introduction to OWASP ZAP
Week5/authcheck.php
Session Data "; echo " "; echo "| Username |
| " . $_SESSION['appusername'] . " |
| " . $_SESSION['appemail']. " |
Week5/dbconnect.php
<?php error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE ); if(!mysql_connect("localhost","root","")) { die('oops connection problem ! --> '.mysql_error()); } if(!mysql_select_db("dbtest")) { die('oops database selection problem ! --> '.mysql_error()); } ?>
Week5/dbtest.sql
-- phpMyAdmin SQL Dump -- version 4.1.14 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Jan 04, 2016 at 06:35 PM -- Server version: 5.6.17 -- PHP Version: 5.5.12 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `dbtest` -- -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(5) NOT NULL AUTO_INCREMENT, `user_name` varchar(25) NOT NULL, `user_email` varchar(35) NOT NULL, `user_pass` varchar(255) NOT NULL, PRIMARY KEY (`user_id`), UNIQUE KEY `user_email` (`user_email`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `users` -- INSERT INTO `users` (`user_id`, `user_name`, `user_email`, `user_pass`) VALUES (1, 'test', '[email protected]', '202cb962ac59075b964b07152d234b70'); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Week5/home.php
<?php session_start(); include_once 'dbconnect.php'; if(!isset($_SESSION['user'])) { header("Location: index.php"); } $res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']); $userRow=mysql_fetch_array($res); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome - <?php echo $userRow['user_email']; ?></title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div id="header"> <div id="left"> <label>Coding Cage</label> </div> <div id="right"> <div id="content"> hi' <?php echo $userRow['user_name']; ?> <a href="logout.php?logout">Sign Out</a> </div> </div> </div> <div id="body"> <a href="http://www.codingcage.com/">Coding Cage - Programming Blog</a><br /><br /> <p>Focuses on PHP, MySQL, Ajax, jQuery, Web Design and more...</p> </div> </body> </html>
Week5/index.php
<?php session_start(); include_once 'dbconnect.php'; if(isset($_SESSION['user'])!="") { header("Location: home.php"); } if(isset($_POST['btn-login'])) { $email = mysql_real_escape_string($_POST['email']); $upass = mysql_real_escape_string($_POST['pass']); $email = trim($email); $upass = trim($upass); $res=mysql_query("SELECT user_id, user_name, user_pass FROM users WHERE user_email='$email'"); $row=mysql_fetch_array($res); $count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row if($count == 1 && $row['user_pass']==md5($upass)) { $_SESSION['user'] = $row['user_id']; header("Location: home.php"); } else { ?> <script>alert('Username / Password Seems Wrong !');</script> <?php } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Coding Cage - Login & Registration System</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <center> <div id="login-form"> <form method="post"> <table align="center" width="30%" border="0"> <tr> <td><input type="text" name="email" placeholder="Your Email" required /></td> </tr> <tr> <td><input type="password" name="pass" placeholder="Your Password" required /></td> </tr> <tr> <td><button type="submit" name="btn-login">Sign In</button></td> </tr> <tr> <td><a href="register.php">Sign Up Here</a></td> </tr> </table> </form> </div> </center> </body> </html>
Week5/loginAuth.html
Enter your Username and Email Address to continue |
|
| username: | |
| Email Address: | |
Week5/logout.php
<?php session_start(); if(!isset($_SESSION['user'])) { header("Location: index.php"); } else if(isset($_SESSION['user'])!="") { header("Location: home.php"); } if(isset($_GET['logout'])) { session_destroy(); unset($_SESSION['user']); header("Location: index.php"); } ?>
Week5/register.php
<?php session_start(); if(isset($_SESSION['user'])!="") { header("Location: home.php"); } include_once 'dbconnect.php'; if(isset($_POST['btn-signup'])) { $uname = mysql_real_escape_string($_POST['uname']); $email = mysql_real_escape_string($_POST['email']); $upass = md5(mysql_real_escape_string($_POST['pass'])); $uname = trim($uname); $email = trim($email); $upass = trim($upass); // email exist or not $query = "SELECT user_email FROM users WHERE user_email='$email'"; $result = mysql_query($query); $count = mysql_num_rows($result); // if email not found then register if($count == 0){ if(mysql_query("INSERT INTO users(user_name,user_email,user_pass) VALUES('$uname','$email','$upass')")) { ?> <script>alert('successfully registered ');</script> <?php } else { ?> <script>alert('error while registering you...');</script> <?php } } else{ ?> <script>alert('Sorry Email ID already taken ...');</script> <?php } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Coding Cage - Login & Registration System</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <center> <div id="login-form"> <form method="post"> <table align="center" width="30%" border="0"> <tr> <td><input type="text" name="uname" placeholder="User Name" required /></td> </tr> <tr> <td><input type="email" name="email" placeholder="Your Email" required /></td> </tr> <tr> <td><input type="password" name="pass" placeholder="Your Password" required /></td> </tr> <tr> <td><button type="submit" name="btn-signup">Sign Me Up</button></td> </tr> <tr> <td><a href="index.php">Sign In Here</a></td> </tr> </table> </form> </div> </center> </body> </html>