# Enhance!

Sau khi mở file thì mình nhận được một ảnh như này

Như thường lệ thì mình dùng command ```strings drawing.flag.svg ```
Và mình thấy rằng ở mỗi biến id thì nó có một số kí tự trông giống như flag

**Flag :** picoCTF{3nh4nc3d_aab729dd}
# File types

Dựa trên đề bài thì mình sẽ xem file pdf này là loại file gì

"Shell archive text" là một dạng tập tin đặc biệt, thường xuất hiện với đuôi .shar , loại file này sẽ chứa các tệp và thư mục khác bên trong nó.
``` $ sh Flag.pdf ```

Sau khi extract thì mình có thêm một file flag

``` $ binwalk --extract flag ```

Sau khi extract thì mình có được file 64 và đây là gzip compressed data.

``` $ binwalk --extract 64 ```

Bên trong lại chứa file flag (lzip compressed data).

```$ lzip -d -k flag```

Sau khi extract thì mình có một file flag.out thuộc type LZ4.

Tiếp tục extract file flag.out và output đầu ra là file flag1.out với type LZMA.

Để có thể extract được file flag1.out thì mình cần đổi tên nó thành flag1.lzma
``` lzma -d flag1.lzma ```
Sau khi extract thì mình thu được file flag một với type lzop.

Mình tiếp tục extract và đổi tên file cũng như định dạng để tránh nhầm lẫn. Kết quả là file flag3 với type lzip.

``` $ lzip -d flag3.out ```

File flag3.out là một file XZ nên mình tiếp tục extract nó.

Kết quả là một file với định dạng ASCII, giờ mình unhex nữa là xong

**Flag :** picoCTF{f1len@m3_m@n1pul@t10n_f0r_0b2cur17y_79b01c26}
# Lookey here

Mình nghĩ bài này không có gì để giải thích thêm, đọc đề bài là hiểu được vấn đề .

**Flag :** picoCTF{gr3p_15_@w3s0m3_58f5c024}
# Packets Primer

Đề bài cho mình một file pcap, Mình dùng Wireshark để đọc từng gói tin và cũng dễ dàng tìm thấy flag .

**Flag :** picoCTF{p4ck37_5h4rk_b9d53765}
# Redaction gone wrong

Sau khi mở file thì mình nhận thấy những thông tin trong tệp đã bị tô đen lại, cách đơn giản nhất là mình ctrl C + ctrl V ra tệp notepad để có thể đọc được những thông tin bị che.

**Flag :** picoCTF{C4n_Y0u_S33_m3_fully}
# Sleuthkit Intro

Như cái tên bài thì bài này sẽ liên quan đến bộ công cụ [sleuthkit](https://en.wikipedia.org/wiki/The_Sleuth_Kit) và trong bài này có chỉ rõ mình sẽ dùng mmls để phân tích tệp image. Tệp image ở đây là bản sao của một thiết bị lưu trữ nào đó ví dụ như ổ cứng, ổ đĩa ...
``` $ mmls disk.img ```
Phần length chính là phần mình cần tìm : 202752
Sau đó trả lời câu hỏi và nhận được flag.

**Flag :** picoCTF{mm15_f7w!}
# Sleuthkit Apprentice

Đề bài cho mình một file .image và không giải thích gì thêm :>>
Ở đây mình sẽ dùng tool FTK Imager, đây là 1 tool giúp mình phân tích ổ đĩa một cách trực quan và dễ hiểu.

Mình đã tìm thấy flag ở partition 3 root/root/my_folder/flag.uni.txt
**Flag :** picoCTF{by73_5urf3r_2f22df38}
# Eavesdrop

Bài này cho mình một file pcap

Sau khi follow TCP stream thì mình thấy một đoạn hội thoại giữa hai người về vấn đề decrypt file

Và đây là command dùng để decrypt cái file đó
```openssl des3 -d -salt -in file.des3 -out file.txt -k supersecretpassword123```
Dựa vào command thì file này đã bị encrypt openssl des3 và nó sẽ bắt đầu bằng kí tự Salt , từ đây mình suy ra hex của nó sẽ là 53 61 6c 74, dựa vào đây thì mình có thể tìm được file encrypt trong đoạn hội thoại trên .

Mình sẽ export file này ra file.des3 và tiến hành decrypt

**Flag :** picoCTF{nc_73115_411_dd54ab67}
# Operation Oni

Đề bài yêu cầu mình tìm key để ssh vào remote machine, đối với những bài có tệp .img thì mình sẽ dùng FTK Imager để mở file.

Ở Partition 2 root/root/.ssh thì mình tìm thấy một file id_ed25519, file này có định dạng của một file pem nên mình sẽ export nó ra thử xem.

Mình sẽ đổi tên cho nó trùng với câu lệnh ban đầu và ssh với quyền admin ( tại để nguyên câu lệnh thì nó xuất hiện lỗi về quyền truy cập ).
```$ sudo ssh -i key_file -p 64731 ctf-player@saturn.picoctf.net```

**Flag :** picoCTF{k3y_5l3u7h_af277f77}
# St3g0

Theo như đề bài thì mình nghĩ là thông tin sẽ được giấu ở bên trong cái ảnh này. Đây được gọi là Steganography, Steganography là một kỹ thuật ẩn thông tin trong một hình ảnh, âm thanh, văn bản hoặc phương tiện truyền thông khác mà thông tin này không dễ dàng nhận thấy bởi người khác. Mục tiêu chính của steganography là che giấu sự tồn tại của thông tin bí mật thay vì chỉ mã hóa nó. Trong trường hợp giấu tin trong ảnh thì sẽ thay đổi các bit thấp nhất của các mẫu màu trong một hình ảnh.

Và một trong những công cụ đắc lực nhất đối với mấy bài Stego CTF chính là zsteg.
```$ zsteg -a -v pico.flag.png | grep pico```

b1,rgb,lsb,xy có nghĩa là bit thứ nhất của các giá trị màu (R, G, B) của mỗi pixel sẽ được sử dụng để chứa thông tin, LBS là các bit ít quan trọng nên việc thay đổi các bit này không ảnh hưởng đáng kể đến hình ảnh và xy chính là tọa độ pixel trong hình ảnh.
**Flag :** picoCTF{k3y_5l3u7h_af277f77}
# Operation Orchid

Vẫn tiếp tục dùng FTK Imager để phân tích file .img, mình phát hiện hai tệp khả nghỉ ở Partition 3 root/root/

Dễ dàng nhận thấy rằng file flag.txt.enc đã bị encrypt bằng aes256 với password là ```unbreakablepassword1234567```
Mình sẽ export file flag.txt.enc và tiến hành decrypt nó

**Flag :** picoCTF{h4un71ng_p457_5113beab}
# SideChannel

Đề bài cho mình một chương trình pin_checker và yêu cầu mình tìm mã pin để trả lời câu hỏi khi connect tới server

Mình nghĩ bài này sẽ áp dụng [Timing Attack](https://en.wikipedia.org/wiki/Timing_attack), nói dễ hiểu sẽ là dựa vào thời gian mà chương trình kiểm tra input mà mình nhập, nếu mình nhập sai thì thời gian kiểm tra ngắn, còn nếu mình nhập đúng thì thời gian kiểm tra dài hơn. Từ đó mình sẽ đoán được cái input đúng mà mình cần nhập, cách này nó sẽ tiết kiệm thời gian hơn so với cách brute-force thông thường.
Trước tiên thì mình cần viết một đoạn script để đo lường thời gian mà chương trình kiểm tra cái input mà mình nhập:
```python=
from pwn import *
import time
import sys
io = process(['./pin_checker'])
context.arch = 'amd64'
gs = '''
continue
'''
pin = str(sys.argv[1])
io.sendline(pin)
io.recvline()
io.recvline()
io.recvline()
start = time.time()
recevied = io.recvline()
stop = time.time()
time_taken = stop - start
log.info(f"Time : {time_taken}")
log.info(f"Received4: {recevied}")
log.info(f"Guess: {pin}")
sys.exit()
```
Và mình cần viết thêm một đoạn shell script để cho việc kiểm tra nhanh chóng hơn . Vì mã pin có 8 kí tự (0-9) nên mỗi lần đoán kí tự ở vị trí i thì mình sẽ có tới 10 trường hơp.
```shell=
#!/bin/bash
python3 script.py 00000000
python3 script.py 10000000
python3 script.py 20000000
python3 script.py 30000000
python3 script.py 40000000
python3 script.py 50000000
python3 script.py 60000000
python3 script.py 70000000
python3 script.py 80000000
python3 script.py 90000000
```
Và mỗi lần chạy mình lại thay đổi các số ở trong đoạn shell script này
```$ ./auto.sh```
```
[*] Time taken: 0.12044525146484375
[*] Received4: b'Access denied.\n'
[*] Guess: 00000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10196)
[+] Starting local process './pin_checker': pid 10208
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.12306904792785645
[*] Received4: b'Access denied.\n'
[*] Guess: 10000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10208)
[+] Starting local process './pin_checker': pid 10212
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.12475323677062988
[*] Received4: b'Access denied.\n'
[*] Guess: 20000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10212)
[+] Starting local process './pin_checker': pid 10216
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.12650036811828613
[*] Received4: b'Access denied.\n'
[*] Guess: 30000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10216)
[+] Starting local process './pin_checker': pid 10220
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.2407236099243164
[*] Received4: b'Access denied.\n'
[*] Guess: 40000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10220)
[+] Starting local process './pin_checker': pid 10232
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.13192200660705566
[*] Received4: b'Access denied.\n'
[*] Guess: 50000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10232)
[+] Starting local process './pin_checker': pid 10236
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.12395715713500977
[*] Received4: b'Access denied.\n'
[*] Guess: 60000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10236)
[+] Starting local process './pin_checker': pid 10240
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.12417197227478027
[*] Received4: b'Access denied.\n'
[*] Guess: 70000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10240)
[+] Starting local process './pin_checker': pid 10252
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.12289929389953613
[*] Received4: b'Access denied.\n'
[*] Guess: 80000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10252)
[+] Starting local process './pin_checker': pid 10256
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.12371659278869629
[*] Received4: b'Access denied.\n'
[*] Guess: 90000000
[*] Process './pin_checker' stopped with exit code 1 (pid 10256)
```
Dựa vào kết quả trên thì khi mình nhập kí tự đầu tiên là '4' thì thời gian kiểm tra sẽ lâu hơn đồng nghĩa đó chính là kí tự đúng trong dãy mã pin 8 kí tự .
Mình tiếp tục sửa lại file auto.sh vì lúc này kí tự mình cần check chính là kí tự ở vị trí thứ 2.
```shell=
#!/bin/bash
python3 script.py 40000000
python3 script.py 41000000
python3 script.py 42000000
python3 script.py 43000000
python3 script.py 44000000
python3 script.py 45000000
python3 script.py 46000000
python3 script.py 47000000
python3 script.py 48000000
python3 script.py 49000000
```
```$ ./auto.sh ```
```
[*] Time taken: 0.24190759658813477
[*] Received4: b'Access denied.\n'
[*] Guess: 40000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13913)
[+] Starting local process './pin_checker': pid 13925
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.24641060829162598
[*] Received4: b'Access denied.\n'
[*] Guess: 41000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13925)
[+] Starting local process './pin_checker': pid 13929
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.24631500244140625
[*] Received4: b'Access denied.\n'
[*] Guess: 42000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13929)
[+] Starting local process './pin_checker': pid 13941
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.24820375442504883
[*] Received4: b'Access denied.\n'
[*] Guess: 43000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13941)
[+] Starting local process './pin_checker': pid 13945
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.24724340438842773
[*] Received4: b'Access denied.\n'
[*] Guess: 44000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13945)
[+] Starting local process './pin_checker': pid 13949
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.24649810791015625
[*] Received4: b'Access denied.\n'
[*] Guess: 45000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13949)
[+] Starting local process './pin_checker': pid 13961
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.24638915061950684
[*] Received4: b'Access denied.\n'
[*] Guess: 46000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13961)
[+] Starting local process './pin_checker': pid 13965
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.24695372581481934
[*] Received4: b'Access denied.\n'
[*] Guess: 47000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13965)
[+] Starting local process './pin_checker': pid 13977
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.36307501792907715
[*] Received4: b'Access denied.\n'
[*] Guess: 48000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13977)
[+] Starting local process './pin_checker': pid 13981
/home/kali/Downloads/script.py:11: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
io.sendline(pin)
[*] Time taken: 0.2459404468536377
[*] Received4: b'Access denied.\n'
[*] Guess: 49000000
[*] Process './pin_checker' stopped with exit code 1 (pid 13981)
```
Lần này thì kí tự '8' có thời gian kiểm tra lâu nhất nên nó sẽ là kí tự đúng tiếp theo.
Giờ mình chỉ cần lặp đi lặp lại việc chỉnh đoạn shell script là tìm ra kí tự có thời gian kiểm tra lâu nhất là được. Và mã PIN đúng chính là 48390513

**Flag :** picoCTF{t1m1ng_4tt4ck_9803bd25}
# Torrent Analyze

Đề bài yêu cầu mình xác định tên của file được download bằng torrent.Torrent download là một phương pháp tải xuống tập tin hoặc dữ liệu thông qua việc chia nhỏ thành các phần nhỏ và tải từ nhiều nguồn khác nhau đồng thời. Phương pháp này sử dụng một loạt các máy tính tham gia vào việc chia sẻ tập tin, gọi là "peers" (đồng ngang), và một máy tính chủ điều khiển quá trình tải xuống, gọi là "seed" (hạt giống).
Bước đầu tiên mình cần enable BitTorrent protocol ```Analyze -> Enabled Protocols```

Mà các file khi download bằng torrent sẽ chứa hash_info, hash_info là một phần quan trọng trong quá trình xác định và xác minh tính toàn vẹn của tập tin được tải xuống. Nên mình chuyển 'hash_info' sang hex (68 61 73 68 ) để tìm tất cả các packet có chứa đoạn hash_info.
Và Packet đầu tiên có chứa hash_info là packet 79:
```17d62de1495d4404f6fb385bdfd7ead5c897ea22 ```

Nhưng search mãi thì nó vẫn không cho ra kết quả là file iso như đề yêu cầu nên mình bỏ qua nó.
Mình cứ tiếp tục lấy hash_info rồi tra trên google, tới packet 51080 thì có kết quả là file iso

Lấy tên file nộp thử thì nó đúng , cách làm của mình hơi thủ công nhưng hiện tại thì vẫn chưa tìm ra cách làm nhanh hơn :<
**Flag :** picoCTF{ubuntu-19.10-desktop-amd64.iso}