Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login redirection issue #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 79 additions & 122 deletions www/login1.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,137 +3,94 @@
session_start();
include("db_config.php");
ini_set('display_errors', 1);
?>

<!-- Enable debug using ?debug=true" -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Page 1 - SQL Injection Training App</title>

<link href="./css/htmlstyles.css" rel="stylesheet">
</head>
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$login_msg = '1';
$username = $_POST['uid'];
$password = $_POST['password'];

<body>
<div class="container-narrow">

<div class="jumbotron">
<p class="lead" style="color:white">
Login Page 1 - Simple Login Bypass
<?php
if (!empty($_REQUEST['msg'])){
if ($_REQUEST['msg']==="1"){
$_SESSION['next']='searchproducts.php';
echo "<br />Please login to continue to Search Products";
}elseif ($_REQUEST['msg']==="2"){
$_SESSION['next']='blindsqli.php';
echo "<br />Please login to continue to Blind SQL Injection Page";
}elseif ($_REQUEST['msg']==="3"){
$_SESSION['next']='os_sqli.php';
echo "<br />Please login to continue to OS Command Injection Page";
}else{
$_SESSION['next']='searchproducts.php';
}
}
?>
</p>
</div>

<div class="response">
<form method="POST" autocomplete="off">
<p style="color:white">
Username: <input type="text" id="uid" name="uid"><br /></br />
Password: <input type="password" id="password" name="password">
</p>
<br />
<p>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</p>
</form>
</div>


<br />

<div class="row marketing">
<div class="col-lg-6">
// SQL Injection vulnerability is still here (concatenation of user input)
$q = "SELECT * FROM users WHERE username='" . $username . "' AND password='" . md5($password) . "'";

<?php
//echo md5("pa55w0rd");
if (isset($_GET['debug']) && $_GET['debug'] == "true") {
$msg = "<div style='border:1px solid #4CAF50; padding: 10px'>" . $q . "</div><br />";
}

if (!empty($_REQUEST['uid'])) {
$username = ($_REQUEST['uid']);
$pass = $_REQUEST['password'];
$result = mysqli_query($con, $q);

$q = "SELECT * FROM users where username='".$username."' AND password = '".md5($pass)."'" ;
if ($result && $row = mysqli_fetch_assoc($result)) {
$_SESSION["username"] = $row["username"];
$_SESSION["name"] = $row["name"];

if (isset($_GET['debug']))
{
if ($_GET['debug']=="true")
{
$msg="<div style=\"border:1px solid #4CAF50; padding: 10px\">".$q."</div><br />";
echo $msg;
}
// Keep session fixation vulnerability
$redirect_page = isset($_SESSION['next']) ? $_SESSION['next'] : 'searchproducts.php';
header("Location: " . $redirect_page);
exit();
} else {
$login_msg = "<font style='color:#FF0000'>Invalid username or password!</font>";
}
}

if (!mysqli_query($con,$q))
{
echo 'Error: ' . mysqli_error($con);
}else{

$result = mysqli_query($con,$q);

// if (!$result) {
// printf("%s\n", mysqli_error($con));
// echo "error";
// }

if (mysqli_warning_count($con)) {
$e = mysqli_get_warnings($con);
if ($e){
do {
echo "Warning: $e->errno: $e->message\n";
} while ($e->next()); }
}

echo "<br /><br />";
$row = mysqli_fetch_array($result);


if ($row){
//$_SESSION["id"] = $row[0];
$_SESSION["username"] = $row[1];
$_SESSION["name"] = $row[3];
//ob_clean();

if ($_SESSION['next']=="searchproducts.php"){
header('Location: searchproducts.php');
}elseif ($_SESSION['next']=="blindsqli.php"){
header('Location: blindsqli.php?user='.$_SESSION["username"]);
}elseif ($_SESSION['next']=="os_sqli.php"){
header('Location: os_sqli.php?user='.$_SESSION["username"]);
}

}
else{
echo "<font style=\"color:#FF0000\">Invalid password!</font\>";
}
}
}

//}
?>

</div>
</div>

<div class="footer">
<p><h4><a href="index.php">Home</a><h4></p>
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Page 1 - SQL Injection Training App</title>
<link href="./css/htmlstyles.css" rel="stylesheet">
</head>
<body>
<div class="container-narrow">
<div class="jumbotron">
<p class="lead" style="color:white">
Login Page 1 - Simple Login Bypass
<?php
if (!empty($_REQUEST['msg'])) {
if ($_REQUEST['msg'] === "1") {
$_SESSION['next'] = 'searchproducts.php';
echo "<br />Please login to continue to Search Products";
} elseif ($_REQUEST['msg'] === "2") {
$_SESSION['next'] = 'blindsqli.php';
echo "<br />Please login to continue to Blind SQL Injection Page";
} elseif ($_REQUEST['msg'] === "3") {
$_SESSION['next'] = 'os_sqli.php';
echo "<br />Please login to continue to OS Command Injection Page";
} else {
$_SESSION['next'] = 'searchproducts.php';
}
}
?>
</p>
</div>

<div class="footer">
<p><a href="https://appsecco.com">Appsecco</a> | Riyaz Walikar | <a href="https://twitter.com/riyazwalikar">@riyazwalikar</a></p>
<div class="response">
<form method="POST" autocomplete="off">
<p style="color:white">
Username: <input type="text" name="uid"><br /><br />
Password: <input type="password" name="password">
</p>
<br />
<p>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</p>
</form>

</div>
<div>
<?php
if (isset($_GET['debug']) && !is_null($msg)) {
echo $msg;
};
if (!is_null($login_msg) && !$login_msg == "1") {
echo $login_msg;
};
?>
</div>

<div class="footer">
<h4><a href="index.php">Home</a></h4>
</div>
</div>
</div> <!-- /container -->

</body>
</html>
</html>