Path Traversal, URL Traversal သို့မဟုတ် Path Disclosure စသည်ဖြင့် သိကြတဲ့ Website/Web Application တွေမှာ ဖြစ်တတ်တဲ့ Misconfiguration လေးကို အမြန်ဆုံး Hotfix လုပ်နိုင်တဲ့အကြောင်းအရာလေး တင်ပေးလိုက်ပါတယ်။
Path Traversal ပေါက်နေတယ်ဆိုရင်တော့ သက်ဆိုင်ရာ URL Path လမ်းကြောင်းထဲက File တွေကို Website ကိုကြည့်ရှုတဲ့သူဟာ အတိုင်းသား မြင်နေရမှာပါ။ Website ထဲက File တွေရဲ့ တည်ဆောက်ပုံ၊ ဘယ်နေရာမှာ ဘယ် File ရှိတယ်ဆိုတာကို လုံးစေ့ပတ်စေ့ သိသွားတဲ့ Attacker တစ်ယောက်အတွက်တော့ နောက်ထပ် ဆင့်ကဲ Attacking တွေအတွက် အများကြီး အထောက်အကူ ဖြစ်သွားနိုင်ပါတယ်။
အထူးသဖြင့် Backend Path တွေမှာ အဖြစ်များလေ့ရှိပါတယ်။ သို့မဟုတ် Image တွေသိမ်းတဲ့နေရာတွေ CSS/JS စတဲ့ Script တွေသိမ်းတဲ့နေရာတွေ Include လုပ်မယ့် Script သိမ်းတဲ့နေရာတွေကို မေ့လျော့ပြီး index page လေးတွေ မခံခဲ့ရင်တော့ ဒီ Path Traversal ပေါက်နေမှာပါပဲ။
အလွယ်ကူဆုံးနဲ့ အမြန်ဆုံး Hotfix ကတော့ သက်ဆိုင်ရာ Path တစ်ခုချင်းစီအောက်မှာ “index.html” File လေးတွေ လိုက်ဆောက်ပေးရုံပါပဲ။ Folder တွေအများကြီး ရှိနေလို့လည်း စိတ်မပူပါနဲ့။ အောက်က Command လေးတစ်ကြောင်းသာ Run လိုက်မယ်ဆိုရင် ကာကွယ်ပြီးသားဖြစ်သွားမှာပါ။
Condition
WordPress Site တစ်ခုကို Deploy လုပ်တော့မယ်ဆိုပါစို့။ WordPress ရဲ့ Directory Structure ထဲမှာပါတဲ့ “wp-includes” Folder ထဲမှာကော သူ့အောက်က Sub Directory တွေ အားလုံးမှာ Path Traversal ကို ကာကွယ်ထားတာ ခုချိန်ထိ မပါဝင်သေးပါဘူး။ ဒါကြောင့် အဲဒီ SubDirectory တစ်ခုချင်းစီဟာ Path Traversal ပေါက်နေပါတယ်။ အောက်က Command ကတော့ Download လုပ်ပြီးခါစ WordPress Archive ကို ဖြည်ချပြီး index.html နဲ့ index.php ဆိုတဲ့ File တွေကို wp-includes Folder ထဲမှာ ရှာကြည့်တာပါ။ မတွေ့ပါဘူး။
[root@lab wp-includes]# ls
admin-bar.php class-wp-embed.php class-wp-user.php ms-deprecated.php
atomlib.php class-wp-error.php class-wp-user-query.php ms-files.php
author-template.php class-wp-feed-cache.php class-wp-walker.php ms-functions.php
blocks class-wp-feed-cache-transient.php class-wp-widget-factory.php ms-load.php
blocks.php class-wp-hook.php class-wp-widget.php ms-settings.php
bookmark.php class-wp-http-cookie.php class-wp-xmlrpc-server.php nav-menu.php
bookmark-template.php class-wp-http-curl.php comment.php nav-menu-template.php
cache.php class-wp-http-encoding.php comment-template.php option.php
canonical.php class-wp-http-ixr-client.php compat.php pluggable-deprecated.php
capabilities.php class-wp-http-proxy.php cron.php pluggable.php
category.php class-wp-http-requests-hooks.php css plugin.php
category-template.php class-wp-http-requests-response.php customize pomo
certificates class-wp-http-response.php date.php post-formats.php
class-feed.php class-wp-http-streams.php default-constants.php post.php
class-http.php class-wp-image-editor-gd.php default-filters.php post-template.php
class-IXR.php class-wp-image-editor-imagick.php default-widgets.php post-thumbnail-template.php
class-json.php class-wp-image-editor.php deprecated.php query.php
class-oembed.php class-wp-list-util.php embed.php random_compat
class-phpass.php class-wp-locale.php embed-template.php registration-functions.php
class-phpmailer.php class-wp-locale-switcher.php feed-atom-comments.php registration.php
class-pop3.php class-wp-matchesmapregex.php feed-atom.php Requests
class-requests.php class-wp-metadata-lazyloader.php feed.php rest-api
class-simplepie.php class-wp-meta-query.php feed-rdf.php rest-api.php
class-smtp.php class-wp-network.php feed-rss2-comments.php revision.php
class-snoopy.php class-wp-network-query.php feed-rss2.php rewrite.php
class-walker-category-dropdown.php class-wp-oembed-controller.php feed-rss.php rss-functions.php
class-walker-category.php class-wp.php fonts rss.php
class-walker-comment.php class-wp-post.php formatting.php script-loader.php
class-walker-nav-menu.php class-wp-post-type.php functions.php session.php
class-walker-page-dropdown.php class-wp-query.php functions.wp-scripts.php shortcodes.php
class-walker-page.php class-wp-rewrite.php functions.wp-styles.php SimplePie
class-wp-admin-bar.php class-wp-role.php general-template.php spl-autoload-compat.php
class-wp-ajax-response.php class-wp-roles.php http.php taxonomy.php
class-wp-block-parser.php class.wp-scripts.php ID3 template-loader.php
class-wp-block-type.php class-wp-session-tokens.php images template.php
class-wp-block-type-registry.php class-wp-simplepie-file.php IXR Text
class-wp-comment.php class-wp-simplepie-sanitize-kses.php js theme-compat
class-wp-comment-query.php class-wp-site.php kses.php theme.php
class-wp-customize-control.php class-wp-site-query.php l10n.php update.php
class-wp-customize-manager.php class.wp-styles.php link-template.php user.php
class-wp-customize-nav-menus.php class-wp-taxonomy.php load.php vars.php
class-wp-customize-panel.php class-wp-tax-query.php locale.php version.php
class-wp-customize-section.php class-wp-term.php media.php widgets
class-wp-customize-setting.php class-wp-term-query.php media-template.php widgets.php
class-wp-customize-widgets.php class-wp-text-diff-renderer-inline.php meta.php wlwmanifest.xml
class.wp-dependencies.php class-wp-text-diff-renderer-table.php ms-blogs.php wp-db.php
class-wp-dependency.php class-wp-theme.php ms-default-constants.php wp-diff.php
class-wp-editor.php class-wp-user-meta-session-tokens.php ms-default-filters.php
[root@lab wp-includes]# find . -name index.html
[root@lab wp-includes]# find . -name index.php
[root@lab wp-includes]#
Solution #1 with .htaccess
index.html ကော index.php ကော DirectoryIndex တွေမတွေ့တဲ့အတွက် .htaccess နဲ့သာ မခံထားရင် URL Traversal ပေါက်နေမှာပါပဲ။ ဒါကြောင့် ဒီ “wp-includes” ဆိုတဲ့ Folder ထဲမှာ အောက်က Command လေးတွေ ရိုက်ထည့်ပြီး URL Traversal/Path Disclosure ကို ကာကွယ်နိုင်ပါတယ်။
[root@lab wp-includes]# echo "Options -Indexes" > .htaccess
ဒါဆိုရင်တော့ ဒီ “wp-includes” Folder အောက်မှာ DirectoryIndex (index.html or index.php) မရှိတဲ့ SubFolder တွေအတွက် 403 Forbidden Error တက်ပြီး Path တွေထဲက File/Folder တွေကို ကြည့်ရှုသူတွေ မြင်ရတော့မှာမဟုတ်ပါဘူး။
Solution #2 with bash script
တကယ်လို့အကြောင်းအမျိုးမျိုးနဲ့ .htaccess ကို အသုံးပြုလို့မရရင်တော့ SubFolder တိုင်းမှာ DirectoryIndex (index.html or index.php) လေးတွေ လိုက်ဆောက်ပေးရမှာပါ။ SubFolder တွေ အများကြီးဖြစ်နေတယ်ဆိုရင်လည်း စိတ်မပူပါနဲ့ အောက်က Command တစ်ကြောင်းပဲ လိုအပ်ပါတယ်။
SubFolder တွေမှာ index.html တွေ ဆောက်ချင်ရင်တော့ ဒီ Command ဖြစ်ပါတယ်။
for i in $(find . -type d); do touch $i/index.html; done
SubFolder တွေမှာ index.php တွေ ဆောက်ချင်ရင်တော့ ဒီ Command ဖြစ်ပါတယ်။
for i in $(find . -type d); do touch $i/index.php; done
Demonstration
[root@lab wp-includes]# find . -name index.html
[root@lab wp-includes]# for i in $(find . -type d); do touch $i/index.html; done
[root@training wp-includes]# find . -name index.html
./images/media/index.html
./images/smilies/index.html
./images/wlw/index.html
./images/crystal/index.html
./images/index.html
./theme-compat/index.html
./SimplePie/Decode/HTML/index.html
./SimplePie/Decode/index.html
./SimplePie/Parse/index.html
./SimplePie/Content/Type/index.html
./SimplePie/Content/index.html
./SimplePie/XML/Declaration/index.html
./SimplePie/XML/index.html
./SimplePie/Cache/index.html
./SimplePie/Net/index.html
./SimplePie/HTTP/index.html
./SimplePie/index.html
./Requests/Transport/index.html
./Requests/Cookie/index.html
./Requests/Exception/Transport/index.html
./Requests/Exception/HTTP/index.html
./Requests/Exception/index.html
./Requests/Utility/index.html
./Requests/Response/index.html
./Requests/Auth/index.html
./Requests/Proxy/index.html
./Requests/index.html
./css/dist/block-library/index.html
./css/dist/format-library/index.html
./css/dist/edit-post/index.html
./css/dist/editor/index.html
./css/dist/nux/index.html
./css/dist/list-reusable-blocks/index.html
./css/dist/components/index.html
./css/dist/index.html
./css/index.html
./Text/Diff/Renderer/index.html
./Text/Diff/Engine/index.html
./Text/Diff/index.html
./Text/index.html
./certificates/index.html
./ID3/index.html
./blocks/index.html
./pomo/index.html
./customize/index.html
./widgets/index.html
./fonts/index.html
./rest-api/endpoints/index.html
./rest-api/search/index.html
./rest-api/fields/index.html
./rest-api/index.html
./IXR/index.html
./js/dist/vendor/index.html
./js/dist/index.html
./js/tinymce/langs/index.html
./js/tinymce/skins/wordpress/images/index.html
./js/tinymce/skins/wordpress/index.html
./js/tinymce/skins/lightgray/img/index.html
./js/tinymce/skins/lightgray/fonts/index.html
./js/tinymce/skins/lightgray/index.html
./js/tinymce/skins/index.html
./js/tinymce/themes/inlite/index.html
./js/tinymce/themes/modern/index.html
./js/tinymce/themes/index.html
./js/tinymce/plugins/fullscreen/index.html
./js/tinymce/plugins/wplink/index.html
./js/tinymce/plugins/wpemoji/index.html
./js/tinymce/plugins/media/index.html
./js/tinymce/plugins/wptextpattern/index.html
./js/tinymce/plugins/wpdialogs/index.html
./js/tinymce/plugins/wpview/index.html
./js/tinymce/plugins/wordpress/index.html
./js/tinymce/plugins/wpautoresize/index.html
./js/tinymce/plugins/paste/index.html
./js/tinymce/plugins/colorpicker/index.html
./js/tinymce/plugins/hr/index.html
./js/tinymce/plugins/lists/index.html
./js/tinymce/plugins/tabfocus/index.html
./js/tinymce/plugins/compat3x/css/index.html
./js/tinymce/plugins/compat3x/index.html
./js/tinymce/plugins/wpeditimage/index.html
./js/tinymce/plugins/link/index.html
./js/tinymce/plugins/directionality/index.html
./js/tinymce/plugins/textcolor/index.html
./js/tinymce/plugins/wpgallery/index.html
./js/tinymce/plugins/image/index.html
./js/tinymce/plugins/charmap/index.html
./js/tinymce/plugins/index.html
./js/tinymce/utils/index.html
./js/tinymce/index.html
./js/imgareaselect/index.html
./js/jquery/ui/index.html
./js/jquery/index.html
./js/crop/index.html
./js/thickbox/index.html
./js/mediaelement/renderers/index.html
./js/mediaelement/index.html
./js/swfupload/index.html
./js/codemirror/index.html
./js/plupload/index.html
./js/jcrop/index.html
./js/index.html
./random_compat/index.html
./index.html
[root@lab wp-includes]#
ဒီပုံစံအတိုင်း မည်သည့် Website/Web Application တွေကိုမဆို URL Traversal မပေါက်အောင် အခြေခံအားဖြင့် ကာကွယ်ထားနိုင်ပါတယ်။ ဘာမှမပြောပလောက်တဲ့ကိစ္စလေးဆိုပေမယ့် အကျိုးဆက်တွေက များတဲ့အတွက် ဂရုစိုက်ဖို့လိုအပ်ပါတယ်။
With love,
Yan Naing Myint