Wednesday, July 21, 2010

SUID ဆိုတာ

Linux / Unix system ေတြအေၾကာင္းေလ့လာရင္ SUID / SGID ဆိုတယ့္ အသုံးအႏွုန္းမ်ိဳး ေတြ႕ရတတ္ပါတယ္ ။ SUID ဆိုတာ Set User ID ကို အတိုေခၚတာပါ။ Executable file ေတြရဲ့ permission မွာ ေပးေလ့ရွိပါတယ္ ။ SUID ေပးရတယ့္ ရည္ရြယ္ခ်က္က executable permission ရွိတယ့္ ဘယ္ user ကပဲ execute လုပ္လုပ္ ၊ ဒီ command / file ကို file owner ရဲ့ identity နဲ႕ run လိုက္ပါတယ္။ ဆိုလိုတာကေတာ့ root user ရဲ့ file တစ္ခုကို everyone executable ေပးထားမယ္၊ ဒါေပမဲ့ SUID set ထားရင္ ဘယ္ user ကပဲ run run ဒီ file က root user အေနနဲ႕ run ပါမယ္။ အနီးစပ္ဆုံး လို႕ ထင္တယ့္ windows ဥပမာကေတာ့ run as administrator နဲ႕ run သလိုေပါ့။ ( သိပ္ေတာ့မတူသလိုပါပဲ။ Run as administrator ကိုေသခ်ာမသိလို႕ မေျပာႏိုင္ပါဘူး)

Linux / Unix မွာ file permission ကို rwx ( Read, Write, Execute) ဆိုျပီး သတ္မွတ္ပါတယ္။ SGID / SUID ေပးထားရင္ေတာ့ s ဆိုတာေလးေတြ႕ရေလ့ရွိပါတယ္။ဥပမာေလး ေျပာရေအာင္ ။

User တိုင္းကို cd တို႕ ls တို႕လို command မ်ိဳးကိုေတာ့ ေပးသုံးရပါတယ္။ အဲလို command တစ္ခုရဲ့ permission ကိုၾကည့္ရင္
$ ls -l /bin/ls
-rwxr-xr-x 1 root root 116688 2010-04-28 23:56 /bin/ls


File ရဲ့ owner က root ျဖစ္ျပီး other users ( Everyone ေပါ့ဗ်ာ Windows မွာေတာ့) ကို Executable permission ေပးထားတာေတြ႕ပါလိမ့္မယ္ ။ Linux File permission ( rwx တို႕ ၊ 700 တို႕ 777 တို႕ )အေၾကာင္းသိျပီးသား လို႕ ယူစလို႕ ဒါကိုမရွင္းေတာ့ပါဘူး။ ls command ကို User တိုင္းက အသုံးျပဳႏိုင္တယ္။ ေနာက္ထပ္ User တိုင္း သုံး လို႕ရတယ့္ command ေလးတစ္ခုကိုၾကည့္ရေအာင္။ Password change တယ့္ passwd command ပါ။
ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 25836 2009-09-14 20:14 /usr/bin/passwd


သူလည္း everyone executable ေပးထားတယ္ ဒါေပမယ့္ တတိယအလုံးမွာ x မဟုတ္ပဲ s ျဖစ္ေနတယ္။ ဒါ SUID set ထားတယ္လို႕ ေဖာ္ျပတာပါ။ ls command တုန္းကလိုပဲ သူ႕မွာလည္း ေနာက္ဆုံးအလုံးက 'x' ၊ ဒါဆို others မွာ executable permission ေပးထားတာေပါ့။ ကြာတာက ၊ ေရွ႕မွာ 's' ျဖစ္ေနတယ္။ ls command တုန္းကလိုပဲ User တိုင္းကသုံးႏိုင္တယ္။ ဒါေပမဲ့ ဒီ passwd command ကို သုံးျပီး လုပ္သမွ်အလုပ္တိုင္းကိုေတာ့ root အေနနဲ႕ လုပ္သြားမွာျဖစ္ပါတယ္။ SUID ကို security consideration တစ္ခုအေနနဲ႕ သတ္မွတ္ၾကေလ့ရွိပါတယ္။ Command တိုင္း file တိုင္းကို အားတိုင္း SUID set မလုပ္ဖို႕ အျပင္းအထန္ ကန္႕ကြက္ပါတယ္။ ဘာလို႕လည္း ?

ခုနက passwd command ေလးကိုပဲ ၾကည့္ရေအာင္။ User တစ္ေယာက္ရဲ့ password ဟာ /etc/shadow ဆိုတယ့္ file ထဲမွာ hash အေနနဲ႕ ရွိပါတယ္။ တကယ္လို႕သာ ဒီ hash ေတြကို ရရင္ rainbow table ေတြဘာေတြနဲ႕ decipher လုပ္ႏိုင္ေကာင္းလုပ္ႏိုင္ပါတယ္။ Root user ရဲ့ password လည္း hash အေနနဲ႕ ရွိပါတယ္။ အဲေတာ့ ဒီ /etc/shadow file ထဲက data က အရမ္းအေရးၾကီးတယ့္ sensitive data ပါ။ ျဖစ္ႏိုင္ရင္ ဘယ္ user ကိုမွ ေပးမၾကည့္သင့္ဖူးေပါ့။ ဒီ /etc/shadow file ရဲ့ owner က default အေနနဲ႕ root ျဖစ္ျပီး permission က 700 ( Owner သာလွ်င္ rwx ရွိျပီး က်န္တယ့္လူေတြ read ေတာင္လုပ္လို႕မရတယ့္ permission) ေပးထားေလ့ရွိပါတယ္။

အဲမွာ စတာပါပဲ ၊ User တစ္ေယာက္က password change ရင္ passwd command ရဲ့ process တစ္ခုအေနနဲ႕ password အသစ္ကို hash ေျပာင္းျပီး ဒီ /etc/shadow file ထဲမွာရွိတယ့္ သူ႕ရဲ့ password hash ကို ျပင္ရပါမယ္။ ဒါမွ password အသစ္ျဖစ္မွာကိုး။ ဒါေပမယ့္ root user ကပဲ ဒီ file ကို edit လို႕ရတယ္။ ဒါဆို password change တိုင္း root ကိုလွမ္း change ခိုင္းရမွာလား ။ ဒါဆိုလည္း မဟုတ္ေသးဘူး။ ဒါေတြေၾကာင့္ password change ရာမွာသုံးတယ့္ passwd command ကို root အေနနဲ႕ SUID set ထားလိုက္ပါတယ္။ passwd command က လုပ္တယ့္ အလုပ္မွန္သမွ် ၊ /etc/shadow မွာ hash update လုပ္တာအပါအဝင္၊ အားလုံးကို ဒီ file ရဲ့ owner ျဖစ္တယ့္ root user အေနနဲ႕ လုပ္သြားလိုက္တယ္။ /etc/shadow ကို everyone editable ေပးရတာထက္ အမ်ားၾကီးေကာင္းတာေပါ့။ ဒီေလာက္ဆိုရင္ SUID ဆိုတာ ဘာလုပ္တယ္၊ ဘယ္လိုဆိုတာ သိေလာက္ပါျပီ။

အေပၚမွာ ေျပာခဲ့သလိုပဲ SUID set ရင္ အလြန္သတိထားရပါတယ္။ ဒီ executable file က ဘာေတြလုပ္သလည္းဆိုတာရယ္ သူ႕ source ရယ္ကို သိသင့္ပါတယ္။ SGID set ထားတယ့္ file တစ္ခုက တစ္ျခား user ကို write permission မေပးရပါဘူး။ Edit လုပ္ျပီး သူလိုခ်င္တယ့္ command ေတြေျပာင္းသြားရင္ ကိုယ္ပဲ ျပသနာျဖစ္ပါမယ္။ Shell script လိုဟာမ်ိဳး ၊ source file လိုဟာမ်ိဳးကို SUID မေပးသင့္ပါဘူး။ Content ကိုျမင္ေနရလို႕ Buffer Over Flow(BOF) flaw ရွိတာတို႕ဘာတို႕ ျဖစ္ႏိုင္ပါတယ္။ ျဖစ္ႏိုင္ရင္ Compiled binary ကိုပဲ SUID ေပးသင့္ပါတယ္။ ဒါေတာင္ safe လို႕ေျပာလို႕မရပါဘူး။

ခုတစ္ေလာ စာမေရးျဖစ္တာၾကာလို႕ Clonezilla ေလးနဲ႕ server တစ္ခုကို image အျဖစ္ေျပာင္းေနတာ ထိုင္ေစာင့္ရင္း ဒီ post ကိုေရးလိုက္ပါတယ္။ SGID ေတာ့ ေနာက္မွေပါ့ ။ ဘာေရးရမွန္းမသိသလို စာစီမရတာလည္းၾကာျပီ ။ :D


Regards
Divinity

2 comments:

Zero Divided by Zero is Zero (Brahmagupta Rule) said...

ညီေလး ..

ရြဲ႕တာလားဟင္ ...
အခု ညီေလးမေရးဘူးဆိုျပီး Spring Framework ေရးျပီးတင္လုိက္ေတာ႔မွ SUID ဆိုျပီးတက္လာတယ္ ..။

:)

လခတိုးသူမ်ား လုိက္ေကြ်းၾကပါ ...လုိက္ေကြ်းၾကပါ။

I owed you one more cup of coffee :) Sigh!!!

Divinity said...

က်ေနာ္လည္း post ေရးတုန္းကမရွိဘူး၊ တင္ေတာ့မွ ေအာက္က post ေရာက္ေနတာေတြ႕တာ ဟီးဟီး

Inseption သြားၾကည့္မယ္ ၊ လီယိုနာဒိုဒါဗင္ခ်ီ ရဲ့ ေနာက္ဆုံးကားပဲ :D စီစဥ္လိုက္ေလ coffee ေလးဘာေလး ေသာက္ရင္းနဲ႕ေပါ့ ဟဲဟဲ