{"id":213,"date":"2019-01-17T04:45:59","date_gmt":"2019-01-17T04:45:59","guid":{"rendered":"https:\/\/mrjsec.co.uk\/blog\/?p=213"},"modified":"2019-01-17T04:46:06","modified_gmt":"2019-01-17T04:46:06","slug":"sugarplum-mary-python-escape-from-la-cranberry-pi-terminal","status":"publish","type":"post","link":"https:\/\/mrjsec.co.uk\/blog\/sugarplum-mary-python-escape-from-la-cranberry-pi-terminal\/","title":{"rendered":"<center>SugarPlum Mary &#8211; Python Escape from LA Cranberry Pi terminal<\/center>"},"content":{"rendered":"\n<p style=\"text-align:center\">As we speak to SugarPlum Mary, we find out she has somehow locked her terminal within a Python interpreter &#8220;Can you please help me by escaping from the Python interpreter?&#8221;<\/p>\n\n\n\n<p style=\"text-align:center\">Sounds simple enough, we need to escape python and run .\/i_escaped.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"577\" height=\"738\" data-attachment-id=\"214\" data-permalink=\"https:\/\/mrjsec.co.uk\/blog\/sugarplum-mary-python-escape-from-la-cranberry-pi-terminal\/pythonescapefrom1\/\" data-orig-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom1.png?fit=577%2C738&amp;ssl=1\" data-orig-size=\"577,738\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"PythonEscapefrom1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom1.png?fit=577%2C738&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom1.png?resize=577%2C738&#038;ssl=1\" alt=\"\" class=\"wp-image-214\" srcset=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom1.png?w=577&amp;ssl=1 577w, https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom1.png?resize=235%2C300&amp;ssl=1 235w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/figure><\/div>\n\n\n\n<p style=\"text-align:center\">So let&#8217;s &#8220;exit()&#8221; and get our badge!\u2026\u2026\u2026.. Well, It seems if we exit the terminal crashes and nothing happens. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"335\" height=\"285\" data-attachment-id=\"215\" data-permalink=\"https:\/\/mrjsec.co.uk\/blog\/sugarplum-mary-python-escape-from-la-cranberry-pi-terminal\/pythonescapefrom2\/\" data-orig-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom2.png?fit=335%2C285&amp;ssl=1\" data-orig-size=\"335,285\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"PythonEscapefrom2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom2.png?fit=335%2C285&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom2.png?resize=335%2C285&#038;ssl=1\" alt=\"\" class=\"wp-image-215\" srcset=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom2.png?w=335&amp;ssl=1 335w, https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom2.png?resize=300%2C255&amp;ssl=1 300w\" sizes=\"auto, (max-width: 335px) 100vw, 335px\" \/><\/figure><\/div>\n\n\n\n<p style=\"text-align:center\">I also tried sys.exit(), quit(), and other Python interpreter commands to leave, sadly they all did the same thing, that was crashing.<\/p>\n\n\n\n<p style=\"text-align:center\">New plan of action, so the goal is to escape python and run .\/i_escaped. So why don&#8217;t we &#8220;cheat&#8221; and run i_escaped from within the Python interpreter ;)\u2026 I&#8217;m sure SugarPlum Mary won&#8217;t notice! <\/p>\n\n\n\n<p style=\"text-align:center\">However, now we have new issues, and that is some commands are filtered, for example, I can&#8217;t use &#8220;import&#8221; and other such stuff.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"473\" height=\"151\" data-attachment-id=\"217\" data-permalink=\"https:\/\/mrjsec.co.uk\/blog\/sugarplum-mary-python-escape-from-la-cranberry-pi-terminal\/pythonescapefrom3-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom3-1.png?fit=473%2C151&amp;ssl=1\" data-orig-size=\"473,151\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"PythonEscapefrom3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom3-1.png?fit=473%2C151&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom3-1.png?resize=473%2C151&#038;ssl=1\" alt=\"\" class=\"wp-image-217\" srcset=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom3-1.png?w=473&amp;ssl=1 473w, https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom3-1.png?resize=300%2C96&amp;ssl=1 300w\" sizes=\"auto, (max-width: 473px) 100vw, 473px\" \/><\/figure><\/div>\n\n\n\n<p style=\"text-align:center\">Let&#8217;s look at the hint given by SugarPlum Mary &#8220;Check out Mark Baggett&#8217;s talk upstairs&#8221; Or you can find it on YouTube Here.<\/p>\n\n\n\n<p style=\"text-align:center\">In the video Mark Baggett, explains about many methods of escaping python from within the shell, the part that works for me is <a href=\"https:\/\/www.youtube.com\/watch?v=ZVx2Sxl3B9c&amp;feature=youtu.be&amp;t=516\">&#8220;evel&#8221; which is at 8:37<\/a> within the video, However, I would HIGHLY recommend watching the whole video, in fact, I urge you to view all the KringleCon talks on there YouTube! (It&#8217;s great stuff).<\/p>\n\n\n\n<p style=\"text-align:center\">Following the video, it still seems it&#8217;s getting filtered, but it&#8217;s only filtering words, i.e. &#8220;os&#8221; &#8220;system&#8221; and so on.<br> <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"55\" data-attachment-id=\"218\" data-permalink=\"https:\/\/mrjsec.co.uk\/blog\/sugarplum-mary-python-escape-from-la-cranberry-pi-terminal\/pythonescapefrom4\/\" data-orig-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom4.png?fit=496%2C55&amp;ssl=1\" data-orig-size=\"496,55\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"PythonEscapefrom4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom4.png?fit=496%2C55&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom4.png?resize=496%2C55&#038;ssl=1\" alt=\"\" class=\"wp-image-218\" srcset=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom4.png?w=496&amp;ssl=1 496w, https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom4.png?resize=300%2C33&amp;ssl=1 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/figure><\/div>\n\n\n\n<p style=\"text-align:center\">But what if we change them exmaple os becomes os1.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>os1 = eval('__im' + 'port__(\"os\")')<\/code><\/pre>\n\n\n\n<p style=\"text-align:center\">Now if we use os1 and not os and some magic(well not really)! We get our commands working outside of the filtering!<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"88\" data-attachment-id=\"219\" data-permalink=\"https:\/\/mrjsec.co.uk\/blog\/sugarplum-mary-python-escape-from-la-cranberry-pi-terminal\/pythonescapefrom5\/\" data-orig-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom5.png?fit=360%2C88&amp;ssl=1\" data-orig-size=\"360,88\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"PythonEscapefrom5\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom5.png?fit=360%2C88&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom5.png?resize=360%2C88&#038;ssl=1\" alt=\"\" class=\"wp-image-219\" srcset=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom5.png?w=360&amp;ssl=1 360w, https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom5.png?resize=300%2C73&amp;ssl=1 300w\" sizes=\"auto, (max-width: 360px) 100vw, 360px\" \/><\/figure><\/div>\n\n\n\n<p style=\"text-align:center\">Now I can use the newest os1 to run commands and bypass the filter, using &#8220;os1.listdir&#8221; here to find where the i_escaped located.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"419\" height=\"88\" data-attachment-id=\"220\" data-permalink=\"https:\/\/mrjsec.co.uk\/blog\/sugarplum-mary-python-escape-from-la-cranberry-pi-terminal\/pythonescapefrom6\/\" data-orig-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom6.png?fit=419%2C88&amp;ssl=1\" data-orig-size=\"419,88\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"PythonEscapefrom6\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom6.png?fit=419%2C88&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom6.png?resize=419%2C88&#038;ssl=1\" alt=\"\" class=\"wp-image-220\" srcset=\"https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom6.png?w=419&amp;ssl=1 419w, https:\/\/i0.wp.com\/mrjsec.co.uk\/blog\/wp-content\/uploads\/2019\/01\/PythonEscapefrom6.png?resize=300%2C63&amp;ssl=1 300w\" sizes=\"auto, (max-width: 419px) 100vw, 419px\" \/><\/figure><\/div>\n\n\n\n<p style=\"text-align:center\">And now we just need to run .\/i_escaped to complete this challenge.<br>\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>os1.system(\"\/home\/elf\/.\/i_escaped\")<\/code><\/pre>\n\n\n\n<p style=\"text-align:center\">So that&#8217;s it, another one completed!<\/p>\n\n\n\n<p style=\"text-align:center\">The funny thing is, once you run i_escaped, you get told you have completed this challenge. However, you&#8217;re still in the Python interpreter, ah SugarPlum Mary no hating please, you know I love you\u2026 However, my job here done. Maybe you could try turning it off and on again SugarPlum Mary!<\/p>\n\n\n\n<p style=\"text-align:center\">References:<br> https:\/\/www.youtube.com\/watch?v=ZVx2Sxl3B9c<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we speak to SugarPlum Mary, we find out she has somehow locked her terminal within a Python interpreter &#8220;Can you please help me by escaping from the Python interpreter?&#8221; Sounds simple enough, we need&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[10],"tags":[13,14,12],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-kringlecon-2018","tag-13","tag-ctf","tag-kringlecon"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paD3U6-3r","_links":{"self":[{"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":1,"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions\/221"}],"wp:attachment":[{"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mrjsec.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}