-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (44 loc) · 1.07 KB
/
index.js
File metadata and controls
49 lines (44 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express = require('express')
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database(':memory:');
const app = express()
const port = 3000
app.set('view engine', 'ejs')
db.serialize(() => {
db.run(`
create table if not exists users (
id integer primary key autoincrement,
name text,
email text,
password text
)`
);
db.run(`
insert into users (name, email, password) values (
"Joe Citizen", "joe@example.com", "hunter2"
)
`);
db.run(`
insert into users (name, email, password) values (
"Jane Doe", "jane@example.com", "sekritz"
);
`);
})
app.get('/', (req, res) => {
res.render('index')
})
app.get('/search', (req, res) => {
var results = [];
db.all(`select * from users where email = '${req.query.q}'`, (err, rows) => {
if (err) {
res.status(400);
res.send("bad request");
} else {
console.log(rows);
res.render('results', { results: rows});
}
})
})
app.listen(port, () => {
console.log(`This application is vulnerable to SQLI! ${port}`)
})