{%hackmd HJHcLwna2 %}
{%hackmd BJnaHZvT6 %}
***picoCTF***
* [<font color="#ff0000">p</font>icoCTF](https://picoctf.org/)
---
[TOC]
---
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
## GET aHEAD
**Description**
Find the flag being held on this server to get ahead of the competition
**HINT**
1. Maybe you have more than 2 choices
2. Check out tools like Burpsuite to modify your requests and look at the responses
<br>
``` HTML
<div class="col-md-6">
<div class="panel panel-primary" style="margin-top:50px">
<div class="panel-heading">
<h3 class="panel-title" style="color:red">Red</h3>
</div>
<div class="panel-body">
<form action="index.php" method="GET">
<input type="submit" value="Choose Red"/>
</form>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-primary" style="margin-top:50px">
<div class="panel-heading">
<h3 class="panel-title" style="color:blue">Blue</h3>
</div>
<div class="panel-body">
<form action="index.php" method="POST">
<input type="submit" value="Choose Blue"/>
</form>
</div>
</div>
</div>
```
<br>
Method 只有 GET 與 POST,而標題提示 Head ,因此使用 Head 方法。
HEAD 方法與 GET 方法相似,但不返回實際內容,只返回標頭信息。
```
curl -I -i http://mercury.picoctf.net:47967/index.php
```
1. `curl`: cURL 工具的啟動命令。
2. `-I`: 發送 HEAD 請求,這表示只檢索網頁的標頭信息,而不下載實際內容。這通常用於獲取目標資源的元數據,例如檢查連接是否正常。
3. `-i`: 在輸出中包括 HTTP 響應的標頭信息。這將顯示伺服器返回的標頭,包括狀態碼、日期、服務器類型等。
**Flag**: picoCTF{r3j3ct_th3_du4l1ty_cca66bd3}
**REF**: https://ctftime.org/writeup/27020
<br>
<br>
## ☄️Cookies
**Description**
Who doesn't love cookies? Try to figure out the best one.
**方法一:**
下載 Cookie-Editor 瀏覽器擴充。

一直嘗試值到18。
**方法二:**
Burp -> Proxy -> Intrcept -> Open browser -> 貼Link載入頁面
-> Intercept -> Intercept is off
-> browser -> 輸入snickerdoodle -> Search
-> Proxy -> HTTP history
看到 /check 它關於Cookies,並且檢查Response為我們要的。

選取要改變數字按右鍵send to Intruder

Burp -> Intruder -> Payloads
Payload type: Number

隨意點選查看Response

**Flag**:picoCTF{3v3ry1_l0v3s_c00k135_064663be}
**REF**:https://medium.com/@11035032_19538/ctf-cookies-3f998ea3da44
<br>
<br>
## Insp3ct0r
**Description**
Kishor Balan tipped us off that the following code may need inspection
**HINT**
1. How do you inspect web code on a browser?
2. There's 3 parts
F12 四處找關鍵Flag。



**Flag**:picoCTF{tru3_d3t3ct1ve_0r_ju5t_lucky?832b0699}
<br>
<br>
## ☄️Scavenger Hunt
**Description**
There is some interesting information hidden around this site.
Can you find it?
**HINT**
You should have enough hints to find the files, don't run a brute forcer.



根據提示,如何防止再Google網站編入索引,尋找robot.txt檔案,
因此在網站後面加入 `/robots.txt`。然後就會遇到。

I think this is an apache server.改為`/.htaccess`。

I can Store a lot of information there.改為`.DS_Store`。

**Flag**:picoCTF{th4ts_4_l0t_0f_pl4c3s_2_lO0k_f7ce8828}
**REF**:https://ctftime.org/writeup/26981
<br>
<br>
## Some Assembly Required 1
**Description**
為PicoCTF提供網址

**Flag**:picoCTF{8857462f9e30faae4d037e5e25fee1ce}
<br>
<br>
## ☄️More Cookies
**Description**
I forgot Cookies can Be modified Client-side, so now I decided to encrypt them!
**HINT**
1. https://en.wikipedia.org/wiki/Homomorphic_encryption
2. The search endpoint is only helpful for telling you if you are admin or not, you won't be able to guess the flag name
同態加密(英語:Homomorphic encryption)是一種加密形式,它允許人們對密文進行特定形式的代數運算得到仍然是加密的結果,將其解密所得到的結果與對明文進行同樣的運算結果一樣。換言之,這項技術令人們可以在加密的資料中進行諸如檢索、比較等操作,得出正確的結果,而在整個處理過程中無需對資料進行解密。其意義在於,真正從根本上解決將資料及其操作委託給第三方時的保密問題,例如對於各種雲端運算的應用。
題目描述中`Cookies can Be modified Client-side`為大寫CBC,提示使用BlockChain中的 Cipher Block Chaining (CBC)。在CBC模式中,明文被分成固定大小的區塊,然後這些區塊進行連鎖加密。每一個明文區塊在加密之前都會與前一個密文區塊進行XOR(異或)運算。這樣可以確保同樣的明文區塊在不同的加密中會產生不同的密文,增加了加密的安全性。
``` python
import requests
import base64
s=requests.Session()
s.get("http://mercury.picoctf.net:15614/")
cookie=s.cookies["auth_name"]
print(cookie)
unb64=base64.b64decode(cookie)
print(unb64)
unb64b=base64.b64decode(unb64)
for i in range (0,128):
pos=i//8
guessdec = unb64b[0:pos] + ((unb64b[pos] ^ (1 << (i % 8))).to_bytes(1, 'big')) + unb64b[pos+1:]
guess=base64.b64encode(base64.b64encode(guessdec)).decode()
r=requests.get("http://mercury.picoctf.net:15614/",cookies={"auth_name": guess})
if "pico" in r.text:
print(r.text)
break
```
**為什麼要base64.b64decode()兩次?**
原始的 base64 編碼的 cookie 被解碼,得到一個新的二進制數據 (unb64),代表該 cookie 的解碼版本。unb64 的二進制數據被再次解碼,得到更進一步解碼的版本 (unb64b)。這可能是由於 cookie 中包含了嵌套的 base64 編碼,即一個 base64 編碼的結果作為另一個 base64 編碼的輸入。
**位元翻轉攻擊"(bit-flipping attack)的操作**
透過迴圈遍歷不同的位元位置,程式對原始 base64 解碼後的資料進行位元翻轉,生成新的解碼版本。`((unb64b[pos] ^ (1 << (i % 8))).to_bytes(1, 'big'))` 保證在 8 位的範圍內循環,即每個字節的位置。對位元進行 XOR 運算,即進行位元翻轉。將 XOR 運算的結果轉換回一個字節的二進位,使用 to_bytes 方法。
**Flag**:picoCTF{cO0ki3s_yum_a9a19fa6}
**REF**:https://ctftime.org/writeup/27021
https://ithelp.ithome.com.tw/m/articles/10243581
<br>
<br>
## where are the robots
**Description**
Can you find the robots?
**HINT**
What part of the website could tell you where the creator doesn't want you to look?
Link後面加入/robots.txt

再依造提示後面改成/477ce.html

**Flag**:picoCTF{ca1cu1at1ng_Mach1n3s_477ce}
<br>
<br>
## logon
**Description**
The factory is hiding things from all of its users. Can you login as Joe and find what they've been looking at?
**HINT**
Hmm it doesn't seem to check anyone's password, except for Joe's?
Joe的登不進去,所以用萬用密碼admin/admin。

看不出來有什麼用,但他的cookie...


**Flag**:picoCTF{th3_c0nsp1r4cy_l1v3s_d1c24fef}
**REF**:https://ctftime.org/writeup/19131
<br>
<br>
## dont-use-client-side
**Description**
Can you break into this super secure portal?
**HINT**
Never trust the client.

**Flag**:picoCTF{no_clients_plz_1a3c89}
<br>
<br>
## It is my Birthday
**Description**
I sent out 2 invitations to all of my friends for my birthday! I'll know if they get stolen because the two invites look similar, and they even have the same md5 hash, but they are slightly different! You wouldn't believe how long it took me to find a collision. Anyway, see if you're invited by submitting 2 PDFs to my website.
**HINT**:
1. Look at the category of this problem.
2. How may a PHP site check the rules in the description?
哈希函數所需的屬性之一是它是不可逆的,
但是 MD5 是脆弱的,會被碰撞。顯然地,
這個我們沒辦法自己完成。因此需要依靠:
https://www.mscs.dal.ca/~selinger/md5collision/
從此網站下載exe檔名加入.pdf。MD5 Collision Demo。
補充:http://www.unixwiz.net/techtips/iguide-crypto-hashes.html


下載了 hello. 與 erase.,
然後重新命名加入.pdf。上傳。
**Flag**:picoCTF{c0ngr4ts_u_r_1nv1t3d_73b0c8ad}
**REF**:https://ctftime.org/writeup/26974
https://github.com/vivian-dai/PicoCTF2021-Writeup/blob/main/Web%20Exploitation/It%20is%20my%20Birthday/It%20is%20my%20Birthday.md
<br>
<br>
## ☄️Who are you?
**Description**
Let me in. Let me iiiiiiinnnnnnnnnnnnnnnnnnnn
**HINT**
It ain't much, but it's an RFC https://tools.ietf.org/html/rfc2616

加入`User-Agent:PicoBrowser`。

加入`Referer:http://mercury.picoctf.net:38322/`。
Referer 是 HTTP 標頭的一個字段,記錄了當前請求的來源網頁的 URL 地址。用途包括來源追蹤,分析 Referer 了解用戶行為和流量來源。

加入`Date:2018`。

加入`DNT:1`。DNT 是 HTTP 標頭中的字段,它代表 "Do Not Track",意味著用戶不希望被追蹤。這是一種設計來尊重用戶隱私的標準,當用戶在瀏覽器中啟用 "Do Not Track" 選項時,瀏覽器會向網站發送包含 DNT: 1 的 HTTP 標頭,表示用戶不希望被追蹤。

`X-Forwarded-For:102.177.146.1`。
本網站僅供瑞典人使用,隨便[Google](https://lite.ip2location.com/sweden-ip-address-ranges)一個 IP。

`Accept-Language:SV`。

**Flag**:picoCTF{http_h34d3rs_v3ry_c0Ol_much_w0w_b22d773c}
**REF**:https://ctftime.org/writeup/26905
https://github.com/ZeroDayTea/PicoCTF-2021-Killer-Queen-Writeups/blob/main/WebExploitation/WhoAreYou.md
<br>
<br>
## login
**Description**
My dog-sitter's brother made this website but I can't get in; can you help?

看起來很怪,直接base64 decode
**Flag**:picoCTF{53rv3r_53rv3r_53rv3r_53rv3r_53rv3r}