---
# System prepended metadata

title: Network Forensics

---

Network Forensics
====

# Freshman 2023 Free Flag
Description: This is a warmup challenge so I give everyone a free flag! Easy peasy lemon squeezy! 
Link download: https://actvneduvn-my.sharepoint.com/:u:/g/personal/ct06n0127_actvn_edu_vn/Ed5o8S6RUF1EnoGwfxyjKlgBYpOveyXz2os5lUi-sVmx2A?e=49O2mX 

File pcap -> mở wireshark

![image](https://hackmd.io/_uploads/ByQ7darDR.png)

-> analyze -> follow -> TCP stream, mình thu được các session sau:

Stream 0:

![image](https://hackmd.io/_uploads/H1EvOprPR.png)

Stream 1:

![image](https://hackmd.io/_uploads/HJyR_aBP0.png)


Stream 2:

![image](https://hackmd.io/_uploads/B1qytpBDA.png)

Stream 5:

![image](https://hackmd.io/_uploads/B1dZFTHDA.png)


Stream 6:

![image](https://hackmd.io/_uploads/H1wSF6SvR.png)

Stream 9:

![image](https://hackmd.io/_uploads/SkIdYTrwR.png)


Stream 10:

![image](https://hackmd.io/_uploads/Sys9YTHv0.png)

Ta có source code sau:

```python!
import base64

BANNER = """ ___       __   ________  ________   ________   ________  ___       __     _____  ________      
|\  \     |\  \|\   __  \|\   ___  \|\   ___  \|\   __  \|\  \     |\  \  / __  \|\   ___  \    
\ \  \    \ \  \ \  \|\  \ \  \\\ \  \ \  \\\ \  \ \  \|\  \ \  \    \ \  \|\/_|\  \ \  \\\ \  \   
 \ \  \  __\ \  \ \   __  \ \  \\\ \  \ \  \\\ \  \ \   __  \ \  \  __\ \  \|/ \ \  \ \  \\\ \  \  
  \ \  \|\__\_\  \ \  \ \  \ \  \\\ \  \ \  \\\ \  \ \  \ \  \ \  \|\__\_\  \   \ \  \ \  \\\ \  \ 
   \ \____________\ \__\ \__\ \__\\\ \__\ \__\\\ \__\ \__\ \__\ \____________\   \ \__\ \__\\\ \__\\
    \|____________|\|__|\|__|\|__| \|__|\|__| \|__|\|__|\|__|\|____________|    \|__|\|__| \|__|
"""

KEY = bytes.fromhex('deadbeef')

def encryptSecret(secret):
    lst_byte = []
    for i in range(len(secret)):
        enc_byte = ord(secret[i]) ^ KEY[i % len(KEY)]
        lst_byte.append(enc_byte.to_bytes(1, 'big'))
    
    return base64.b64encode(b''.join([_ for _ in lst_byte])).decode()

if __name__=='__main__':
    print(BANNER)
    secret = input("> Please give me your secret: ")
    print("\n> Here is your encrypted secret:", encryptSecret(secret))
```
Nói chung hàm encryptSecret xor sau đó đổi qua bytes rồi encode base64, vì có key rồi nên mình dễ dàng decrypt được bằng cách decode base64 rồi xor với key.
```python!
import base64
from pwn import xor
key = bytes.fromhex('deadbeef')
enc_msg = 'iZzFsKme0oOdndOqgdnxsKmZ0KG/2o+hgdA='
dec_msg = base64.b64decode(enc_msg)
print(xor(key, dec_msg))
# b'W1{_w3llC0mE_tO_w4nNaw1N_}'
```
=> W1{_w3llC0mE_tO_w4nNaw1N_}
# KMACTF 2023 Chaos
Link download: https://actvneduvn-my.sharepoint.com/:u:/g/personal/ct06n0127_actvn_edu_vn/EXTboNzH_ldDvXeXGsH2anABNvql-qOQBEpP7HltRm91wg?e=8xGgeT

Mở file sau đó sắp xếp thời gian tăng dần, mình sẽ thấy phần text trong data của mỗi gói tin như sau:

![image](https://hackmd.io/_uploads/H1nbPlvw0.png)

Ghép hết lại là ra flag.
=> KMACTF{C0d3\_cun9\_du0c\_t0Ol\_Cun9\_DuOc\_nHun9\_h1\_v0n9\_b4n\_kh0n9\_l@m\_m0t\_c4cH\_tHu_C0nG}

# Viblo CTF - Netlab Warmup
https://ctf.viblo.asia/puzzles/netlab-warmup-vg104c0hpc7
Bài này mình làm như câu Free flag ở trên.

![image](https://hackmd.io/_uploads/HyYdueDwA.png)

Synt{ArgYno0_SGC_1f_a0g_f3pHe3333} -> decode mã caesar key = 13 
=> Flag{NetLab0\_FTP\_1s\_n0t\_s3cUr3333}
# Viblo CTF - Netlab1: Sharing
https://ctf.viblo.asia/puzzles/netlab1-sharing-7ftcbkfnovy
A protocol that looks a bit strange. Do you know how to deal with it?

![image](https://hackmd.io/_uploads/Sy28INdPR.png)

Requests sử dụng giao thức SMB -> vào file -> Export objects -> SMB

![image](https://hackmd.io/_uploads/ByPnIEODC.png)

Tải 2 file đáng ngờ là password.txt và netlab1.7z về, file netlab1.7z cần pass để giải nén, ta giải nén bằng mật khẩu trong file password ra một file database là netlab1.db.
Mở file netlab1.db để check mình thấy sử dụng SQLite:

![image](https://hackmd.io/_uploads/HkOZoNODR.png)


Với file database này mình hay mở bằng DB Browser for SQLite, sau khi mở mình thấy bảng Flag.

![image](https://hackmd.io/_uploads/rktucNOwR.png)

Thực hiện truy vấn SQLite để lấy dữ liệu ra từ bảng flag.
```
SELECT group_concat(BillingCity, "") from flag

```
![image](https://hackmd.io/_uploads/H1tP9VdDR.png)

=> Flag{NetLab1_N0w_y0u_kn0w_SMB??}


















