I've tried to solve the following "hacking" challenge in order to get experience with web vulnerabilities.
The service is programmed in node.js and is accessible as http://lbs-course.askarov.net:3030:
app.post ("/reset/", function (req, res) {
var user = req.body.username;
if (!user) {
res.send("no username provided");
} else {
db.get (
"select * from users where username='" + user + "'",
function (err, row) {
// ...
if (row) {
// ... send email because we have a real response
}
res.send("password reset email has been queued");
})
}
})
The details for sending emails are irrelevant and are commented out (as in the challenge).
The data is stored in a simple SQLite 3 database. The users tables used by the service is created using the following SQL create query:
CREATE TABLE users(username text, passwordhash text, key text)
There exists at least one user in the database, with username admin
.
Goal:
Obtain the private key for user admin
.
My attempt:
I've tried SQL injection, e.g. with user
set to ' OR ''='
, however nothing happens... Also, I've read articles about MS SQL supporting the EXECUTE()
function, but I cannot find the equivalent in SQLite. With such a function, I could in principle execute shell commands like nslookup
.
It is obvious that the only point where this service is vulnerable is the db.get()
call, and since the details for sending emails are irrelevant, then I must somehow make the database send the private key for admin
(reason for EXECUTE()
call).
I'm stuck in this challenge after spending lots of hours, so I think it's time to ask the community for help.
EXECUTE()
? The string is valid?