정보보안(구버전)/DVWA 2019. 3. 10. 12:02

DVWA - 09. Source Code Disclosure(PHP-CGI) 공격 패턴 분석 및 스노트 룰 설정

 

 

본 내용은 DVWA를 이용한 OWASP Top10 취약점 진단 및 웹-해킹 내용이 아니라, Snort를 이용한 DVWA 취약점 및 공격 패턴을 진단하는 실습 환경입니다.

 

 

1. Using Known Vulnerable Components

 

 - OWASP Top10 A9 - 알려진 취약점이 있는 구성 요소 사용

 - 슈퍼유저 권한으로 운영되는 취약한 라이브러리/프레임워크, 기타 SW 모듈로 인한 데이터 유실 및 서버 권한 획득이

   가능한 취약점이다.

 

 

 

2. CGI

 

 - CGI : Common Gateway Interface

 - 서버가 클라이언트로부터 요청을 수신하면, 이 요청이 어플리케이션에서 처리되어야 할 경우, 서버가 어플리케이션을

   실행시키고 이에 대한 응답을 받는 기능을 수행한다.

 - Ex) 브라우저가 서버를 경유하여 DB 서버에 질의를 내는 웹페이지를 작성할 때 사용함

 

 

 

 

 

3. PHP CGI Remote Code Execution

 

 - PHP가 CGI 기반으로 동작할때 CGI 스크립트가 질의 문자열을 제대로 처리하지 못하여 발생하는 취약점이다.

 - CVE 2012-1823 취약점 : https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2012-1823

 

 

 

 

'php' 도움말 확인

root@kim-virtual-machine:/etc/nsm/rules# php -h
Usage: php [options] [-f] <file> [--] [args...]
   php [options] -r <code> [--] [args...]
   php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
   php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
   php [options] -S <addr>:<port> [-t docroot]
   php [options] -- [args...]
   php [options] -a

  -a               Run interactively
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used   // php.ini 파일을 사용하지 않음
  -d foo[=bar]     Define INI entry foo with value 'bar'   // php.ini에 정의된 설정 내용을 임의로 설정함
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse and execute <file>.
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -r <code>        Run PHP <code> without using script tags <?..?>
  -B <begin_code>  Run PHP <begin_code> before processing input lines
  -R <code>        Run PHP <code> for every input line
  -F <file>        Parse and execute <file> for every input line
  -E <end_code>    Run PHP <end_code> after processing all input lines
  -H               Hide any passed arguments from external tools.
  -S <addr>:<port> Run with built-in web server.
  -t <docroot>     Specify document root <docroot> for built-in web server.
  -s               Output HTML syntax highlighted source.   // 소스코드를 클라이언트 브라우저에서 확인 가능
  -v               Version number
  -w               Output source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.

  args...          Arguments passed to script. Use -- args when first argument
                   starts with - or script is read from stdin

  --ini            Show configuration file names

  --rf <name>      Show information about function <name>.
  --rc <name>      Show information about class <name>.
  --re <name>      Show information about extension <name>.
  --rz <name>      Show information about Zend extension <name>.
  --ri <name>      Show configuration for extension <name>.

 

 

[참고] php-cgi 취약점 테스트 명령어


allow_url_fopen=1                   외부의 URL로부터 파일을 읽어옴
allow_url_include= 1                외부의 파일을 incoud, includ_once, require, require_once와 같은 파일로 include 허용함
auto_prepend_file=php://input  HTTP Request Body로부터 데이터를 갖고와 실행함

 

 

 

4. Source Code Disclosure(PHP-CGI) 공격 패턴 분석

 

9-0. Source Code Disclosure(PHP-CGI).log

9-1. Source Code Disclosure(PHP-CGI) 공격 패턴.txt

 

 

 

5. Snort 룰 설정

 

9-2. Source Code Disclosure(PHP-CGI) 스노트 설정.txt

 

root@kim-virtual-machine:~# cd /etc/nsm/rules
root@kim-virtual-machine:/etc/nsm/rules#
root@kim-virtual-machine:/etc/nsm/rules# vi local.rules

# 8. Remote Execution Shellshock
alert tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"9. Source Code Disclosure(PHP-CGI)"; priority:1; flow:established,to_server; content:"?"; http_uri; content:"-"; fast_pattern; http_uri; content:!"="; http_raw_uri; pcre:"/(?:\/(?:php)?|\.php)\?[\s\+]*\-[A-Za-z]/Ui"; sid:3000091; rev:1;)

 

:wq! 

 

 

pcre 내용-1

pcre

내용 

(?:\/(?:php)?|\.php)\?[\s\+]*\-[A-Za-z]

 

/?-s

/? -s

/?   -s

 /php?-s

 /php? -s

 /php?   -s

 .php?-s

 .php? -s

 .php?   -s

 

 

 

pcre 내용-2

 pcre

 내용

 (?:\/(?:php)?|\.php)

 /

 /php

 .php

 ?: 

 |(OR)이 있기 때문에 그룹화 안에 있는거 중에 하나만 있어도 매칭함

 /(?:php)?

 /만 있거나, /php만 있거나 (?:는 없어도 됨)

 |

 OR

 \.php

 .php

 

 

pcre 내용-3

 pcre

 내용

 \?[\s\+]*\-[A-Za-z]

?-s

 ? -s

?   -s

 \? 

?

\s

 공백

\+

공백

 [\s\+]*

공백이 0번 이상 반복

 \-

 -

 [A-Za-z] 

 A~Z, a~z 중 한글자

 

 

root@kim-virtual-machine:/etc/nsm/rules# rule-update

 

 

'rule-update' 에러가 발생하면, 'local.rules' 파일을 수정한 이후 실시함

root@kim-virtual-machine:/etc/nsm/rules# nsm --sensor --restart --only-snort-alert 


 

 

6. DVWA 'Source Code Disclosure(PHP-CGI)'  취약점 진단 실시

 

dvwa 우클릭 -> 공격 -> 'Active Scan' 클릭

 

 

 

Policy 선택 -> 'Start Scan' 버튼 클릭

 

 

 

7. Snort 탐지 결과 확인 및 분석

 

 

Snort -> 'Show Packet Data' & 'Show Rule'를 체크하여 스노트 탐지 분석 실시

 

 

 

8. Snort 룰 삭제 또는 주석 처리 실시

 

 

[유튜브] 동영상 강의 링크 (구독! 좋아요!!!)

 

DVWA - 09. Source Code Disclosure(PHP-CGI) 공격 패턴 분석 및 스노트 룰 설정   https://youtu.be/7RQSZEPzQ4s

Posted by 김정우 강사(카카오톡 : kim10322)
,


Q