CSS Expt 10 - 250406 - 110304
CSS Expt 10 - 250406 - 110304
EXPERIMENT NO - 10
ROLL NO:-
DATE:-
f an attacker enters ' OR 1=1 -- into the username field and leaves the password field blank, the
resulting query would become:
SELECT * FROM users WHERE username = '' OR 1=1 --' AND password = '';
Implementation:
This is a little demonstration of a SQL injection in a simple login application. In our example, a
database as been provisionned with an admin user. Their credentials are:
username: admin
password: admin123
In theory it should only be possible to login in the application using this credential, but if the
application is not safely programmed, it is possible to penetrate in the system as an admin user without
knowing the admin password.
2
DEPARTMENT OF COMPUTER ENGINEERING
Once you have played a bit with the login application and tried to used valid and invalid credential,
use the following values
username: admin
password: unknown' or '1'='1
app.js:
// {
var express = require('express');
var bodyParser = require('body-parser');
var sqlite3 = require('sqlite3').verbose();
if(err) {
console.log('ERROR', err);
res.redirect("/index.html#error");
} else if (!row) {
res.redirect("/index.html#unauthorized");
} else {
res.send('Hello <b>' + row.name + '</b><br /><a href="/index.html">Go back to login</a>');
}
});
});
app.listen(3000);
3
DEPARTMENT OF COMPUTER ENGINEERING
index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form action="/login" method="post">
<div class="container">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="username" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<button type="submit">Login</button>
</div>
<script>
if(document.location.hash === '#unauthorized') {
document.write('<div class="unauthorized">Invalid Username or Password</div>');
} else if(document.location.hash === '#error') {
document.write('<div class="error">An error has occured</div>');
}
</script>
</form>
</body>
</html>
style.css:
form {
border: 3px solid #f1f1f1;
}
input[type=text], input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
4
DEPARTMENT OF COMPUTER ENGINEERING
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.cancelbtn {
width: auto;
padding: 10px 18px;
background-color: #f44336;
}
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}
img.avatar {
width: 40%;
border-radius: 50%;
}
.container {
padding: 16px;
}
span.psw {
float: right;
padding-top: 16px;
}
.unauthorized {
background-color: orange;
}
.error {
5
DEPARTMENT OF COMPUTER ENGINEERING
background-color: red;
}
/* Change styles for span and cancel button on extra small screens */
@media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
Output:
6
DEPARTMENT OF COMPUTER ENGINEERING