Skip to content

Commit fd00801

Browse files
committed
Updates node-js/challenge-2.md
Auto commit by GitBook Editor
1 parent 71a38af commit fd00801

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109

110110
* [Challenge 1](node-js/challenge-1.md)
111111
* [Challenge 2](node-js/challenge-2.md)
112+
* [Challenge 3](node-js/challenge-3.md)
112113

113114
## PERL
114115

node-js/challenge-2.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Challenge
2+
23
```js
34
#!/usr/bin/node
45

@@ -90,7 +91,7 @@ app.all("/*", (req, res, next) => {
9091
} else {
9192
var sql = `SELECT ?,?,?`;
9293
}
93-
94+
9495
return pool.query(sql, [ip, payload, payload], (err, rows) => {
9596
var sql = `SELECT * FROM blacklists WHERE ip=?`;
9697
return pool.query(sql, [ip], (err,rows) => {
@@ -99,7 +100,7 @@ app.all("/*", (req, res, next) => {
99100
} else {
100101
return res.end("Shame on you");
101102
}
102-
103+
103104
});
104105
});
105106

@@ -144,4 +145,8 @@ app.listen(31337, () => {
144145
```
145146

146147
# Refference
147-
+ hitcon ctf 2017 SQL so Hard
148+
149+
* hitcon ctf 2017 SQL so Hard
150+
151+
152+

node-js/challenge-3.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Challenge
2+
```js
3+
var express = require('express')
4+
var app = express()
5+
6+
var bodyParser = require('body-parser')
7+
app.use(bodyParser.urlencoded({}));
8+
9+
var path = require("path");
10+
var moment = require('moment');
11+
var MongoClient = require('mongodb').MongoClient;
12+
var url = "mongodb://localhost:27017/";
13+
14+
MongoClient.connect(url, function(err, db) {
15+
if (err) throw err;
16+
dbo = db.db("test_db");
17+
var collection_name = "users";
18+
var password_column = "password_"+Math.random().toString(36).slice(2)
19+
var password = "XXXXXXXXXXXXXXXXXXXXXX";
20+
// flag is flag{password}
21+
var myobj = { "username": "admin", "last_access": moment().format('YYYY-MM-DD HH:mm:ss Z')};
22+
myobj[password_column] = password;
23+
dbo.collection(collection_name).remove({});
24+
dbo.collection(collection_name).update(
25+
{ name: myobj.name },
26+
myobj,
27+
{ upsert: true }
28+
);
29+
30+
app.get('/', function (req, res) {
31+
res.sendFile(path.join(__dirname,'index.html'));
32+
})
33+
app.post('/check', function (req, res) {
34+
var check_function = 'if(this.username == #username# && #username# == "admin" && hex_md5(#password#) == this.'+password_column+'){\nreturn 1;\n}else{\nreturn 0;}';
35+
36+
for(var k in req.body){
37+
var valid = ['#','(',')'].every((x)=>{return req.body[k].indexOf(x) == -1});
38+
if(!valid) res.send('Nope');
39+
check_function = check_function.replace(
40+
new RegExp('#'+k+'#','gm')
41+
,JSON.stringify(req.body[k]))
42+
}
43+
var query = {"$where" : check_function};
44+
var newvalue = {$set : {last_access: moment().format('YYYY-MM-DD HH:mm:ss Z')}}
45+
dbo.collection(collection_name).updateOne(query,newvalue,function (e,r){
46+
if(e) throw e;
47+
res.send('ok');
48+
// ... implementing, plz dont release this.
49+
});
50+
})
51+
app.listen(8081)
52+
53+
});
54+
```
55+
56+
57+
# Refference
58+
+ [0ctf 2018 Loginme]

0 commit comments

Comments
 (0)