Security

แฮ็กเกอร์ king cope ซึ่งรู้จักกันดีว่าเป็นนักปล่อยช่องโหว่ประเภท 0-day สู่สาธารณะตัวยงได้ออกมาเปิดเผยช่องโหว่ระดับร้ายแรงของ PHP 5.x ที่รันบน Apache ซึ่งอาจส่งผลให้แฮ็กเกอร์ที่ใช้ช่องโหว่นี้สามารถรันคำสั่งอันตรายไปยังเป้าหมายจากระยะไกลได้

จากซอร์สโค้ดที่ใช้ในการโจมตีช่องโหว่นี้ได้อธิบายว่า ช่องโหว่นี้เกิดขึ้นจาก php5-cgi ซึ่งเป็นแพ็คเกตที่ถูกติดตั้งบน Debain/Ubuntu มาแต่แรก โดยปกตินั้นหากมีการเข้าถึงไบนารีของ php-cgi โดยตรง ฟังก์ชัน security check จะทำการบล็อคและไม่ทำการเอ็กซีคิวต์ไบนารีนั้น แต่หากมีการแก้ไขค่าของ cgi.force_redirect และ cgi.redirect_status_env ในไฟล์ php.ini แล้วก็จะสามารถเอ็กซีคิวต์ไบนารีนั้นได้

สำหรับเวอร์ชันของ PHP ที่ได้รับผลกระทบจากการทดสอบนี้จะเป็นเวอร์ชันที่ต่ำกว่า 5.3.12 และต่ำกว่า 5.4.2

ที่มา - Full Disclosure

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand

icez Thu, 31/10/2013 - 17:42

This is a code execution bug in the combination of Apache and PHP.
On Debian and Ubuntu the vulnerability is present in the default install
of the php5-cgi package.

เอ่อ รั่วแค่ default installation ของ package php5-cgi บน debian/ubuntu นะครับ

สำหรับท่านเจ้าของ Host ตรวจสอบเบื้องต้นได้โดยการเรียก

http://YOURDOMAIN/cgi-bin/php
http://YOURDOMAIN/cgi-bin/php5
http://YOURDOMAIN/cgi-bin/php4
http://YOURDOMAIN/cgi-bin/php-cgi
http://YOURDOMAIN/cgi-bin/php.cgi

ถ้าเรียกได้ไม่ 404 แปลว่ามีลุ้นครับ แต่เอกสารส่วนใหญ่จะแนะนำลงเป็น mod_php หมดแล้ว (หลังๆ เป็น fpm) ผลกระทบน่าจะไม่มากเท่าไหร่

แต่หากมีการแก้ไขค่าของ cgi.force_redirect และ cgi.redirect_status_env ในไฟล์ php.ini แล้วก็จะสามารถเอ็กซีคิวต์ไบนารีนั้นได้

จากข่าว ผมเข้าใจว่า ถ้าหากไม่ตั้งสองค่านี้เองก็ไม่เป็นไร เพราะปกติมันปิดอยู่แล้ว แต่เท่าที่ดูจากซอสโค้ดมันยิงบักไปให้รันได้แม้การตั้งค่าสองอันนี้เปิดอยู่ครับผม

โดยช่องโหว่นี้เกิดจากการเช็คความปลอดภัยสองอย่างนี้เกิดขึ้น "หลัง" จากมีการเรียก getopt เพื่อประมวลผลพารามิเตอร์ ทำใหเแฮกเกอร์สามารถยิงคำสั่งปลอมเข้าไปใน getopt เพื่อใช้สวิตช์ -d ของ php เพื่อปิดการทำงานสอง โดยยิงเข้าไปทาง query string ธรรมดาเลย (น่าจะเป็นบักเดียวกับ ?-s ของก่อนหน้านี้)

ไม่ต้องตื่นเต้นครับ ... นี้คือบัคเดิมตั้งแต่ปี 2012

บัคนี้ เป็นบัคที่มี ใน metasploit ตั้งนานแระ
[ไปค้น CVE-2012-1823 ดู]

(บัคนี้จริงๆ แค่เอา ?-s ไปต่อท้ายไฟล์ .php ก็จะ view source ได้ - -''
ถ้าเอา ?-d ไปต่อท้าย ก็จะแก้ไขค่าใน php.ini ได้
ซึ่งเช่นแก้ allow_url_include ให้ เรียกไฟล์จาก url ได้ ก็จะทำ RFI ได้ .. หรือแก้มุขอื่นอีกก็แฮกได้อีก [ตรูกั๊ก คิคิ])

======
= เพิ่มเติม
ถ้าจำไม่ผิดบัคนี้หลุดออกมาครั้งแรก
เพราะมีคนใช้ผ่าน CTF ของใครซักที่ (ที่จ่อยเล่นมั้ง)
แล้วก็พบว่า มันมีฝังมากับ php มานานแล้ว

ซึ่งตัวของ king cope นี่เพิ่มวิธี bypass
โดยใช้ cgi.redirect_status_env เพื่อ ให้ทำงานได้ใน php หลายๆ version

======
= คำแนะนำ
ใครอยากรู้ว่า "ทำงานยังไง" อ่านเรื่อง php-cgi
แต่ถ้าจะแค่ อวดว่าก็แฮกได้เว้ย ... ก็โหลดไป compile โลด

======
= log ส่วนหนึ่งจากใน irc

[16:56:36] ตอบเกี่ยวกับ php exploit ในนี้ จะเรียกคนเปล่าหว่า
[16:57:38] https://github.com/php/php-src/blob/47cff264dfc9b117c7fc1904da852c92f1db3260/sapi/cgi/cgi_main.c#L1890
[16:57:54] อ่าน c รู้เรื่องก็จะเข้าใจ

======
= lab .iso เอาไว้ลอง exploit
https://pentesterlab.com/exercises/cve-2012-1823/

ตอบซ้ำอีกที จาก กลุ่ม FB : https://www.facebook.com/groups/2600Thailand/permalink/228286533998049/?comment_id=228288303997872&offset=0&total_comments=5