Crypto
===
## Lab 0x0
- [Base64 Decoder](https://www.convertstring.com/zh_TW/EncodeDecode/Base64Decode)
<!--79°58'39.25"S 81°57'32.21"W-->
### Lab 0x1
- 摩斯密碼
- cyberchef -> From Morse Code
<!--NISRA{7948'39.25"S7957'30.21"W}-->
### Lab 0x2
- 密碼棒
- [Decoder](http://www.atoolbox.net/Tool.php?Id=915)
- 面數 = 13
<!-- NISRA{amysteriouscellardeepintheforest} -->
### Lab 0x3
- Playfair
- [Decoder](http://www.atoolbox.net/Tool.php?Id=912)
<!--
NISRA{thelakeisdreamlikeandbeautifulandthesurfaceofthewaterreflectsthelightoftheauroralikeamagicmirror}
-->
### Lab 0x4
- 維吉尼亞
- [Decoder](http://www.metools.info/code/c71.html)
<!--
NISRA{Come find me in the snow}
-->
### Lab 0x5
- Cyberchef
- From Binary
<!--
NISRA{HI}
-->
### Lab 0x6
### Lab 0x7
- 希爾密碼
- [Decoder](http://www.metools.info/code/hillcipher243.html)
- 第一堂社課 : 20230919
```
把數字拆成 20 23 09 19
然後拿進去 decode
x 是補字 要拿掉
```
<!--
NISRA{areyouready}
-->
### qqqqq
- 字頻分析
- [Decoder](https://www.quipqiup.com/)
<!--
NISRA{quipquip is g00d.}
-->
### change
- QRcode + cyberchef
```
先將 QRcode 轉成 Base 64
然後去 cyberchef 分別插入
From Base64
From Morse code
From hex
```
<!--
NISRA{change_to_change}
-->
Misc
===
## Jack 的 Flag
- Word 的隱寫術
```
第一種解法:
去 檔案 > 選項 > 顯示 > 隱藏文字
打開之後就看的到了
第二種解法:
將檔案強制解壓縮
Jack > word > document.xml
Ctrl + F 搜尋 NISRA
```
<!--NISRA{Word'$_h1Dden_7eXT_reVEaLed}-->
## 404
- [Wayback machine](https://archive.org/web/)
```
進到網站後,發現進不了編輯模式
解法 1
把上面的 bar 關掉
編輯模式中的備註就是 flag
解法 2
```
<!--
NISRA{W4y84ck_mAChINe_7r4ciNg_wEB'5_p@5t}
-->
## FFD9
- file Signature
```
將檔案用文字編輯器(sublime)或是 010editor 打開
以FF D9結尾 > 應該是jpg檔
jpg 的 file signatures 應該是FF D8
改完之後將副檔名改成 jpg
```
<!--
NISRA{Jp6_fFd8}
-->
## LSB
- Stegslove
```
打開之後使用 analyse > Data Extract
因為是 LSB 所以 Red = 0 Blue = 0 Grean = 0
然後選擇 LSB First
下面選擇 BGR
flag 在最上面
記得把空白鍵移掉
```

<!--
NISRA{ThI5_iS_the_f14G_Of_L5B}
-->
## Exiftool
```
直接點屬性看不到東西 > exiftool Flag.jpg
exiftool 下載
sudo apt-get update
sudo apt install libimage-exiftool-perl
```
:::spoiler 其他解法
1. 丟到 010-Editor 找metadata
2. strings Flag.jpg |grep -i NISRA
:::
<!-- NISRA{FInD_CoPYr19hT_wITH_ex1F7oOl} -->
## IHDR
- 當我們把它丟進010Editor > CRC檢查碼錯誤 > 圖片的寬高可能被修改了

- 題目說他是正方形圖片 > 邊長可能等於 0x200 或 0x258

- 修改照片的高度通常不會導致照片模糊,所以應該修改照片寬度

:::spoiler 另解
- 因為題目說是 IHDR ,而且是正方形的

- 將它改成 600 x 600 並存檔

:::
<!-- NISRA{Png_1HdRrRR} -->
## FindPassword
zip裡面有兩份檔案 : flag.docx / pwd.jpg
Hint 裡面寫了 binwalk
那我們來用binwalk看看pwd.jpg

裡面有一個zip檔
提取zip binwalk -e pwd.jpg

出現資料夾 > 點進去 > 解壓縮裡面的 zip > 發現 pwd.docx

將裡面的密碼輸進 flag.docx
<!-- NISRA{EXp1oRIng_d@T@_wI7h_8INWA1k} -->
## robots.txt
- 先去根目錄的 robots.txt > 發現有兩個檔案

- 先去 username.html 查看

- 拿去 [cyberchef](https://gchq.github.io/CyberChef/) 轉 base64
```
username=admin password=nisra
```
- 再去 login.html

有一個登入界面,但沒有按鈕
- 看看 F12 中有一個 flag.php

- 他是以GET的方式傳到flag.php的
- 用URL登入flag.php
> http://chall2.nisra.net:41014/flag.php?username=admin&password=nisra
<!-- NISRA{Th1s_is_p@ss_BY_G3T} -->
## No Passphrase
- StegHide 是一個工具
> sudo apt-get install steghide
- 先看看圖片

- 因為這題題目說 No passphrase > 直接 Enter 就好

- 發現有一個 flag.txt ,將它提取出來

- 然後打開它
<!-- NISRA{uSe_stE9HIde} -->
## Pixel

題目說每個Pixel的RGB可以組成那格Pixel的顏色,那我們可以先來分析一下每個Pixel的RGB
```python
from PIL import Image
img = Image.open("flag.png")
pixels = []
for row in range(8): # 8 rows
for col in range(8): # 8 columns
r, g, b = img.getpixel((row * 64 + 1, col * 64 + 1)) # each grid: 64 x 64
pixels.append((r, g, b))
print(pixels)
```
結果:

可以發現除了白色的地方,其他RGB的值都沒有超過ASCII的範圍
那我們把白色以外的地方轉成字元試試
結果:

好像有料
我們把字連起來看看
```python
from PIL import Image
img = Image.open("flag.png")
pixels = []
for row in range(8): # 8 rows
for col in range(8): # 8 columns
r, g, b = img.getpixel((row * 64 + 1, col * 64 + 1)) # each grid: 64 x 64
if r == 255 and g == 255 and b == 255:
break
else:
pixels.append((chr(r), chr(g), chr(b)))
if r == 255 and g == 255 and b == 255:
break
flag = ""
for r, g, b in pixels:
flag += r + g + b
print(flag)
```
結果:

有==,試試Base64

flag 格式出來了,丟凱薩

<!-- NISRA{A_rAs7ER_6R4PH1C_rEpREsENt$_A_Tw0-D1M3ns10n41_pictuRe_As_4_rEcTan6U1AR_Ma7rix_or_grId_oF_SqU@rE_PIXels} -->
# Python
## Try it
- 發現每個字都是轉成數字,然後和 100 做 xor 再轉成 binary
- 再做一次 xor 就可以回到原本的字元,再轉成字元輸出
```python=
s = [0b101010, 0b101101 ,0b110111 ,0b110110 ,0b100101 ,0b11111 ,0b111 ,0b10110 ,0b11101 ,0b10100 ,0b10000 ,0b1010100 ,0b111011, 0b1010101, 0b10111 ,0b111011 ,0b111 ,0b1011 ,0b1001 ,0b1001 ,0b1101 ,0b1010 ,0b11 ,0b11001]
for i in s:
print(chr(i^100),end='')
```
<!-- NISRA{crypt0_1s_comming} -->
## Magic Function
- 跟 format 字串串接與 Magic Function 有關
- https://hacktricks.boitatech.com.br/misc/basic-python/magic-methods

- 發現有一個 class 叫 Secret
- 原始 code 中 Secret 有一個 flag
- 直接把它 call 出來

<!-- NISRA{Ma9ic_pY3h0n_!!???} -->
# OS
## OS
- 帳號密碼都是 nisra
- 發現有一個 CTF 的資料夾
- 改變權限後進去

- 暴力解法

- 正常解法
- 修改所有權
- 修改權限
- 開啟檔案
<!-- NISRA{Th1s_1s_fiNaL_CTF_flAG} -->
# Web I
## 0x0 Welcome
- 直接 f12 爆開來

<!-- NISRA{Y0u_F1Nd_Th3_FL3GGGGG} -->
## 0x1 Cat
- hint 是 flag.jpg
- 直接將一張圖片改成 flag.jpg
- 然後取決螢幕的好壞,好一點的就看到

<!-- NISRA{93wr4nq5} -->
## 0x2
- f12 後,在 all.js 中發現一個function flag
- 爆開解
- 在 Console 中輸入 Flag()

- 用 onclick

<!-- NISRA{H3r3_i5_a_s3cr3t_5pac3} -->
# Web II
## you are not admin
- f12 去找 cookie

- value 改成 admin

- 然後對網址列重新 enter

<!-- NISRA{Ch4n9e_y0U_C00kI3s} -->
## easy xss
- 暴力解
- 直接在 console 下 alert()

- 一般解
- 用圖片製造 error 然後 onerror = alert()
- 先隨便輸入一個數字 (1 ~ 4) 除外

- 然後加上 onerror = "alert()"

<!-- NISRA{X55_1s_50_c0o0o01!} -->
## easy sqli
- 看到一個可以輸入帳號密碼的地方
- 嘗試使用 Sql injection
- 輸入 'OR 1=1-\-
