{"id":50,"date":"2022-07-17T22:03:45","date_gmt":"2022-07-17T22:03:45","guid":{"rendered":"http:\/\/moveax.me\/?p=50"},"modified":"2022-08-31T19:01:56","modified_gmt":"2022-08-31T19:01:56","slug":"nebula-level09-a-newbies-approach","status":"publish","type":"post","link":"https:\/\/giga-rapid.com\/esites\/moveaxme\/nebula-level09-a-newbies-approach\/","title":{"rendered":"Nebula Level09: A Newbie\u2019s Approach"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">So far, we have dealt with bash, Perl and C programming languages. In level09 challenge, we have a small PHP piece of code to analyze and exploit.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What you\u2019ll need to know\u2026<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>PHP<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Level09<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By looking at the files under the \/home\/flag09 folder you can identify the SUID program and a file with PHP code, which is the same presented on the&nbsp;<a href=\"\">challenge\u2019s page<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/06\/files.png\" alt=\"Files\" class=\"wp-image-678\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">First of all, the markup function is our \u201cpoint of entrance\u201d in the code. This function takes two arguments, which means the flag09 SUID program also takes two arguments. Let\u2019s ignore the second argument and feed something random.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, taking a look at the code, is possible to identify some calls to the preg_replace, whose function is to replace content in a string based on a regular expression. The first preg_replace will basically replace all the \u201c.\u201d by \u201cdot\u201d and all the \u201c@\u201d by \u201cAT\u201d. The last two preg_replace will replace the square brackets by the angle quotes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you feed some file to this program, flag09 will analyze and replace all \u201c@\u201d and \u201c.\u201d symbols. At the end, will print to the command line the entire file sanitized.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, the following image contains the output of running flag09 with some file containing \u201c[email moveaxme@moveax.me]\u201d.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/06\/test.png\" alt=\"test\" class=\"wp-image-679\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">In order to get a shell, we can place in the file \u201c[email {${system(sh)}}]\u201d instead of the last string. We use the system function because it\u2019ll show the output immediately and not at the end.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we will have a shell under the flag09 user. From here, we can run the getflag command and solve the level09 challenge. Let\u2019s see.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/06\/solution_level09.png\" alt=\"Solution Level09\" class=\"wp-image-681\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Challenges completed: 10\/20<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Mitigation<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So, as mitigation to this level09 we have the same advises I gave to&nbsp;<a href=\"nebula-level00\/\">level0<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s always good to remember that all the input provided by the user (or some program) should always be sanitized.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Walkthrough<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Nebula Level 5-9\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/ICeUE6c7SoM?start=394&#038;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Further Reading<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.acunetix.com\/blog\/articles\/web-shells-101-using-php-introduction-web-shells-part-2\/\">Web-shells 101 using PHP \u2013 Introduction to Web Shells<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>So far, we have dealt with bash, Perl and C programming languages. In level09 challenge, we have a small PHP piece of code to analyze&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/giga-rapid.com\/esites\/moveaxme\/nebula-level09-a-newbies-approach\/\">Continue reading<span class=\"screen-reader-text\">Nebula Level09: A Newbie\u2019s Approach<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-nebula","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":2,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/50\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}