พบช่องโหว่ FabricScape ทำให้ผู้โจมตีสามารถเข้าควมคุม Fabric Nodes ทุกตัวใน cluster ได้

นักวิจัยจาก Palo Alto Unit 42 พบช่องโหว่ FabricScape (CVE-2022-30137) บน Service Fabric ของ Microsoft ที่มักถูกใช้งานบน Azure ซึ่งทำให้ผู้โจมตีสามารถยกระดับสิทธิ์บน Linux containers เพื่อเพิ่มสิทธิ์ของ user เป็น root และเข้าควบคุม Fabric Nodes ทุกตัวใน cluster ได้โดยที่เงื่อนไขในการโจมตีช่องโหว่นี้จำเป็นต้องมีการตั้งค่าเปิด Fabric runtime access ซึ่งถูกเปิดเป็น default ใน container ทุกตัว

ข้อมูลจาก Microsoft พบว่า Service Fabric ถูกใช้งานบนแอปพลิเคชันจำนวนมาก เช่น Azure Service Fabric, Azure SQL Database และ Azure CosmosDB รวมถึงผลิตภัณฑ์อื่นๆ ของ Microsoft อย่าง Cortana และ Microsoft Power BI

Service Fabric Architecture

เพื่อให้เข้าความรุนแรงของช่องโหว่ FabricScape จำเป็นที่จะต้องเข้าใจสถาปัตยกรรมเบื้องต้นของ Service Fabric ก่อน   โดยในหนึ่ง Service Fabric Cluster จะประกอบไปด้วย Node หลายตัว โดยที่ Node แต่ละตัวจะ run container engine คอยจัดการกับ containers คล้ายๆ กับ Kubernetes. เวลา Deploy application ไปใน Service Fabric cluster, Service Fabric จะ Deploy application เป็น containers ตามที่ถูกตั้งค่าไว้ใน application manifest  โดยที่แต่ละ Node จะมี components หลายตัวทำงานอยู่ข้างในทำให้ Node หลายตัวทำงานร่วมกันได้

ช่องโหว่ที่เกิดขึ้น

ในระหว่างที่ Container ใน Service Fabric กำลังเริ่มต้นการทำงาน log directory (/mnt/sfroot/log/Containers) จะถูกสร้างขึ้นมาใน Node และถูก mount เข้าใน container โดยที่ container มีสิทธ์ในการอ่านหรือเขียนไฟล์ใน directories

หนึ่งใน Node component คือ Data Collection Agent (DCA) ทำหน้าที่เก็บ log จาก log directories แล้วนำมา process ทีหลัง เพื่อที่ Data Collection Agent จะสามารถอ่าน file logs ได้จึงจำเป็นจะต้องใช้สิทธ์ Root ในการทำงาน

log file ที่ถูก process แล้วจะมี format ที่คล้ายกับ linux environment variables

ในระหว่างที่ DCA กำลัง process log file ผู้โจมตีสามารถสร้าง symbolic link ทับ log file เดิมเพื่อให้ DCA ไปเขียน log file ที่ถูก process แล้วไปที่ path ใดก็ใน file system ของ Node

REC Node

นักวิจัยเลือกวิธีการโจมตีโดยใช้เทคนิค dynamic linker hijacking ดังนี้

  1. เขียน shared object ที่จะทำการ reverse shell เมื่อถูก load เก็บไว้ใน log directory
  2. ใช้ช่องโหว่ DCA overwrite ไฟล์ /etc/environment เขียนตัวแปร LD_PRELOAD ชี้ไปที่ shared object
  3. Linux task scheduler (cron) จะ import /etc/environment ทุกครั้งที่มี job ทำงาน
  4. ที่ Node จะมี job หนึ่งตัวที่ทำงานทุกๆ ชั่วโมงด้วยสิทธิ์ root เมื่อ job ทำงานตัวโปรแกรมจะไป load shard object และ reverse shell ไปหา container ทำให้นักวิจัยได้ shell ของเครื่อง Node

Cluster Takeover

นักวิจัยพบ directory /var/lib/waagent/ ของเครื่อง Node มี certificate ที่ใช้ควมคุม Cluster ถูกฝังอยู่ จึงทำให้นักวิจัยสามารถส่ง REST API โดยใช้ certificate ควมคุมการทำงานของ Service Fabric cluster ได้

Mitigations

อัพเดท Service Fabric เป็น version 9.0 Cumulative Update 1.0

ที่มา : unit42.paloaltonetworks