Profile

머리정리하는곳

c2w2m2

[Insomni' hack] Vulnshop

<?php if(isset($_GET['hl'])){ highlight_file(__FILE__); exit; } 
    
error_reporting(0); session_start();  
    
// Anti XSS filter 
    
$_REQUEST array_map("strip_tags"$_REQUEST); 
    
// For later, when we will store infos about visitors. 
    
chdir("tmp"); 
?> 
<!DOCTYPE html> 
<html> 
    <head> 
        <title>Work in progress...</title> 
        <meta charset="utf-8" /> 
        <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
        <style> 
            body { 
                background-color: #aaa; 
                color:#fff; 
            } 
             
            .page { 
                width: 50%; 
                margin: 0 auto; 
                margin-top: 75px; 
            } 
             
             
            .menu ul li { 
                display:inline-block; 
                vertical-align:top; 
                margin-right: 30px; 
                 
            } 
        </style> 
    </head> 
    <body> 
        <div class="page"> 
            <div class="menu"> 
                <ul> 
                    <li><a href="?page=default">Home</a></li> 
                    <li><a href="?page=introduction">Introduction</a></li> 
                    <li><a href="?page=privacy">Privacy</a></li> 
                    <li><a href="?page=contactus">Contact</a></li> 
                </ul> 
            </div> 
             
            <div class="content"> 
                <?php 
                        
switch($_GET['page']) { 
                            case 
'default'
                            default: 
                                echo 
"<p>Welcome to our website about infosec. It's still under construction, but you can begin to browse some pages!</p>"
                                break; 
                            case 
'introduction'
                                echo 
"<p>Our website will introduce some new vulnerabilities. Let's check it out later!</p>"
                                break; 
                            case 
'privacy'
                                echo 
"<p>This website is unbreakable, so don't worry when contacting us about some new vulnerabilities!</p>"
                                break; 
                            case 
'contactus'
                                echo 
"<p>You can't contact us for the moment, but it will be available later.</p>"
                                
$_SESSION['challenge'] = rand(100000,999999); 
                                break; 
                            case 
'captcha'
                                if(isset(
$_SESSION['challenge'])) echo $_SESSION['challenge']; 
                                
// Will make an image later 
                
touch($_SESSION['challenge']); 
                                break; 
                            case 
'captcha-verify'
                
// verification functions take a file for later, when we'll provide more way of verification 
                                
function verifyFromString($file$response) { 
                                    if(
$_SESSION['challenge'] === $response) return true
                                    else return 
false
                                } 
                                 
                                
// Captcha from math op 
                                
function verifyFromMath($file$response) { 
                                    if(eval(
"return ".$_SESSION['challenge']." ;") === $response) return true
                                    else return 
false
                                } 
                                if(isset(
$_REQUEST['answer']) && isset($_REQUEST['method']) && function_exists($_REQUEST['method'])){ 
                                    
$_REQUEST['method']("./".$_SESSION['challenge'], $_REQUEST['answer']); 
                                } 
                                break; 

                        } 
                
?> 
            </div> 
        </div> 
        <p><a href="/?hl">View code source of the file, to be sure we're secure!</a></p> 
        <p><a href="/phpinfo.php">Show our configurations</a></p> 
    </body> 
</html> 

웹문제 입니당. 정작 맨날하던 포너블은 못풀고 웹 푼...


쨋든 소스를 보면 contactus 에서 session 생성이 가능하고, captcha 에서 session 을 확인 할 수 있고, captcha-verify 가 중요한데


여기서는 if 만 통과하면 원하는 함수의 실행이 가능합니다. 근데 인자가 고정...


이인자 고정에다가



이 함수들을 제외한 함수로 해야합니당..


처음 생각한건 session 을 바꿔내서 Code Injection 하는 건데, 이게 바로 먹혔습니당 ㅎㅎ


사실 저 disalbe_fuinctions 도 문제 풀고 나서 알았습니다 ㅠㅠ


쩃든 막 노가다 해서 file_put_contents, copy, readfile, print 같은 함수는 쓸수 있다. 정도만 알고 더 찾고 있었는데,


갑자기 걍 file_put_contents 로 넣고, copy 로다가 session 파일 조작하면 session 이 바뀌겠다 해가지고 해봤는데


되더래요.


그래서 


저런 코드를 짜놓고 막 system(\"ls\") 같은거 해보는데 1도 안되는 겁니다.... disable function 에 있더라고요 나중에 보니까


쨋든 여기서도 노가다 했는데 scandir 이라는게 먹혀서 


 python exp.py "print_r(scandir(\"/var/www/html\"))" 


이런걸로 저기를 읽었는데도 없고, 저안에 tmp 도 읽었는데도 없어서


/ 읽어보니  



ㅋㅋㅋ.....


python exp.py "print_r(readfile(\"/flag\"))" 로 읽으면



(grin)


'Web' 카테고리의 다른 글

Webhacking.kr writeup  (0) 2018.07.13
Webhacking.kr 올클  (1) 2018.07.07
[ch4n3 world] mailbox  (0) 2018.01.05
[Root-me] sqli - numberic  (0) 2017.09.24
[Root-me] sqli - string  (0) 2017.09.24