Skip to content

Commit

Permalink
add some TFC CTF crypto (#42)
Browse files Browse the repository at this point in the history
- sort CTFs
- Optimize images
- add some TFC CTF crypto
- add Tools section for reverse
  • Loading branch information
mheidari98 authored Aug 16, 2024
1 parent 7efee6f commit 72f4316
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 48 deletions.
Binary file modified docs/crypto/source/Secret History The Story of Cryptology.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/crypto/writeups/2024/TFCCTF/CCCCC.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions docs/crypto/writeups/2024/TFCCTF/CCCCC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
tags:
- TFC CTF
- TFC CTF 2024
- Crypto
---

# چالش CCCCC

<center>
![CCCCC](CCCCC.PNG)
</center>

## آشنایی با مساله

در این سوال به ما فایل `ccccc.txt` داده شده است. بیایید نگاهی به محتویاتش بندازیم:


```plain title="ccccc.txt" linenums="1"
5c4c4c6c4c3c4c3c5c4c4c6c7cbc6c3c7c3c6c8c6cfc7c5c7c4c5cfc6c3c6cfc7c5c7c4c5cfc6c3c7c4c3c0c5cfc6c3c6cdc7c9c5cfc6c3c6c2c3c0c7c9c5cfc6c3c3c4c6cec6c4c5cfc6c3c6cdc7c9c5cfc6c3c6c4c6cfc6c7c5cfc6c3c6c1c6cec6c4c5cfc6c3c6cdc7c9c5cfc6c3c6c3c3c4c3c7c7cdc0ca\n
```


## راه حل


در نگاه اول کلی حرف `c` تو فایل داده شده به چشممون میخوره مانند اسم سوال
در ادامه ما میدانیم فرمت فلگ با `TFCCTF` شروع میشود و داریم
```py
print( b'TFCCTF'.hex() )
# 544643435446
```

با توجه به مقدار هگز حروف آغازین فلگ و فایل داده شده، پی میبریم کافیست `c` های اضافی را حذف کنیم تا به فلگ برسیم:

```py
print(bytes.fromhex(s[::2]))
```



---
??? success "FLAG :triangular_flag_on_post:"
<div dir="ltr">`TFCCTF{cshout_cout_ct0_cmy_cb0y_c4nd_cmy_cdog_cand_cmy_cc47}`</div>


!!! نویسنده
[mheidari98](https://github.com/mheidari98)

Binary file added docs/crypto/writeups/2024/TFCCTF/CONWAY.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions docs/crypto/writeups/2024/TFCCTF/CONWAY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
tags:
- TFC CTF
- TFC CTF 2024
- Crypto
- Integer Sequences
---

# چالش CONWAY

<center>
![CONWAY](CONWAY.PNG)
</center>

## آشنایی با مساله

در این سوال به ما دو فایل `main.py` و `output.txt` داده شده است که در ادامه محتویات این دو فایل رو مشاهده میکنید:
=== "main.py"
```python title="main.py" linenums="1"
from secret import generate_next_key, flag
import hashlib
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad

initial = 11131221131211131231121113112221121321132132211331222113112211

initial = generate_next_key(initial)
print(initial)

initial = generate_next_key(initial)
h = hashlib.sha256()
h.update(str(initial).encode())
key = h.digest()

cipher = AES.new(key, AES.MODE_ECB)
print(cipher.encrypt(pad(flag.encode(),16)).hex())
```

=== "output.txt"
```plain title="output.txt" linenums="1"
311311222113111231131112132112311321322112111312211312111322212311322113212221
f143845f3c4d9ad024ac8f76592352127651ff4d8c35e48ca9337422a0d7f20ec0c2baf530695c150efff20bbc17ca4c
```

ظاهرا تو این سوال باید با استفاده از `initial` و مقدار پرینت شده، بیایم تابع `generate_next_key` رو پیاده سازی کنیم و سپس با داشتن کلید بسادگی میتوان متن را رمزگشایی کرد و به فلگ رسید.

## راه حل

!!! Tip "توصیه"
قرار نیست ما همیشه همه چیز رو بدونیم و اینکه تو مسابقاتمون از هوش مصنوعی ها در راستا افزایش کاراییمون به‌درستی کمک بگیریم، کار هوشمندانه‌ای هستش.

برای حل این مساله ابتدا با
[chatgpt](https://chatgpt.com)
مشورت کردم و خوشبختانه ایشون تونست این تابع رو برای من پیاده سازی کنه و بخش سخت مساله رو برا من انجام داد و در ادامه بسادگی میتوان کلید `aes` را بدست بیاوریم و بعد از رمزگشایی به فلگ میرسیم.

!!! Note ""
همچنین میتوانستیم از
[این سایت](https://oeis.org/A005150)
نیز جهت حل این مساله کمک بگیریم


```py
import hashlib
from Crypto.Cipher import AES

def generate_next_key(s):
result = ""
i = 0
while i < len(s):
count = 1
while i + 1 < len(s) and s[i] == s[i + 1]:
i += 1
count += 1
result += f"{count}{s[i]}"
i += 1
return result

initial = "11131221131211131231121113112221121321132132211331222113112211"
enc = 'f143845f3c4d9ad024ac8f76592352127651ff4d8c35e48ca9337422a0d7f20ec0c2baf530695c150efff20bbc17ca4c'

initial = generate_next_key( generate_next_key(initial) )
key = hashlib.sha256(initial.encode()).digest()
AES.new(key, AES.MODE_ECB).decrypt( bytes.fromhex(enc) )
```

---
??? success "FLAG :triangular_flag_on_post:"
<div dir="ltr">`TFCCTF{c0nway's_g4me_0f_sequences?}`</div>


!!! نویسنده
[mheidari98](https://github.com/mheidari98)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/crypto/writeups/2024/TFCCTF/GENETICS.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions docs/crypto/writeups/2024/TFCCTF/GENETICS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
tags:
- TFC CTF
- TFC CTF 2024
- Crypto
- Genetic Code
---

# چالش GENETICS

<center>
![GENETICS](GENETICS.PNG)
</center>

## آشنایی با مساله

تو این سوال رشته زیر به ما داده شده است و ما باید به طریقی فلگو بدست بیاریم

```
CCCA CACG CAAT CAAT CCCA CACG CTGT ATAC CCTT CTCT ATAC CGTA CGTA CCTT CGCT ATAT CTCA CCTT CTCA CGGA ATAC CTAT CCTT ATCA CTAT CCTT ATCA CCTT CTCA ATCA CTCA CTCA ATAA ATAA CCTT CCCG ATAT CTAG CTGC CCTT CTAT ATAA ATAA CGTG CTTC
```



## راه حل

برای حل این مساله ابتدا با کلید واژه های استخراج شده از سوال (`Genetic Code CTF`) تو گوگل سرچ کردم تا ببینم انکدینگی با این نام از قبل وجود داره یا یک انکدینگ ابداع طراح سوال هستش
که به نتایج خوبی نظیر
[این سایت ](https://www.dcode.fr/codons-genetic-code)
رسیدم، ولی متاسفانه این سایت قادر به دیکد متن داده شده نشد

در ادامه با مطالعه بیشتر پی بردم که که هر کدام از حروف `A`, `C`, `T`, `G` نمایانگر یک عدد دوبیتی هستند(**مبنا 4**)
با دونستن حروف ابتدایی فلگ (`TFCCTF`) میتوانیم بسادگی تشخیص بدهیم هر حرف نمایانگر چه عددی هستش

<center>
![GENETICS-Table](GENETICS-Table.png)
</center>

جدول نهایی ما بصورت زیر خواهد بود:

<center>
![GENETICS-coding](GENETICS-coding.jpg){ width=300 }
</center>


در ادامه کد حل مساله قرار گرفته است:

```py
s = "CCCA CACG CAAT CAAT CCCA CACG CTGT ATAC CCTT CTCT ATAC CGTA CGTA CCTT CGCT ATAT CTCA CCTT CTCA CGGA ATAC CTAT CCTT ATCA CTAT CCTT ATCA CCTT CTCA ATCA CTCA CTCA ATAA ATAA CCTT CCCG ATAT CTAG CTGC CCTT CTAT ATAA ATAA CGTG CTTC"
s4 = s.replace("A", "0").replace("C", "1").replace("G", "2").replace("T", "3")
print( ''.join(chr(int(c, 4)) for c in s4.split()) )
```

---
??? success "FLAG :triangular_flag_on_post:"
<div dir="ltr">`TFCCTF{1_w1ll_g3t_th1s_4s_4_t4tt00_V3ry_s00n}`</div>


!!! نویسنده
[mheidari98](https://github.com/mheidari98)

Binary file modified docs/getStarted/beginners-guide/forensic_repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/reverse/Tools/binja-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/reverse/Tools/ghidra.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/reverse/Tools/ida_pro.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions docs/reverse/Tools/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# ابزارهای جامع مهندسی معکوس

## دیکامپایلرها و دیس‌اسمبلرها

دیکامپایلرها و دیس‌اسمبلرها ابزارهای اساسی در مهندسی معکوس هستند که کد ماشین را به زبان‌های سطح بالاتر یا اسمبلی تبدیل می‌کنند.

### دیکامپایلرها




1. **[🌟IDA Pro](https://hex-rays.com/ida-free)**
<div markdown>
![ida_pro](ida_pro.jpg){ align=left width="80" }
- یکی از پیشرفته‌ترین دیکامپایلرهای تجاری
- پشتیبانی از طیف گسترده‌ای از معماری‌ها و فرمت‌های فایل
- قابلیت اسکریپت‌نویسی با Python و IDC
</div>

2. **[🌟Ghidra](https://ghidra-sre.org)**
<div markdown>
![ghidra](ghidra.jpg){ align=left width="100" }
- دیکامپایلر متن‌باز و رایگان از NSA
- قابلیت تحلیل پیشرفته و ویژگی‌های همکاری تیمی
- پشتیبانی از اسکریپت‌نویسی Java و Python
</div>

3. **[Binary Ninja](https://binary.ninja)**
![Binary Ninja](binja-logo.jpg){ align=left width="80" }
- پلتفرم تحلیل باینری با API قدرتمند
- قابلیت تحلیل در سه سطح: Low Level IL، Medium Level IL و High Level IL

4. **[Hopper](https://www.hopperapp.com)**
- مناسب برای سیستم‌عامل‌های macOS، Linux و Windows
- رابط کاربری بصری و قابلیت دیباگ

5. **[JEB](https://www.pnfsoftware.com)**
- تخصص در دیکامپایل اندروید و تحلیل بدافزار
- پشتیبانی از پلاگین‌های Python

6. **[🌟Cutter](https://cutter.re)**
- دیکامپایلر خفنیه🔥



## دیباگرها

دیباگرها به محققان اجازه می‌دهند تا اجرای برنامه را در زمان واقعی بررسی و کنترل کنند.

1. **[🌟GDB (GNU Debugger)](https://www.sourceware.org/gdb)**
- دیباگر متن‌باز و چند پلتفرمی
- پشتیبانی از اکثر زبان‌های برنامه‌نویسی

2. **[WinDbg](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger)**
- دیباگر قدرتمند برای ویندوز
- مناسب برای دیباگ درایورها و تحلیل دامپ حافظه

3. **[x64dbg](https://x64dbg.com)**
- دیباگر متن‌باز برای ویندوز
- رابط کاربری گرافیکی و قابلیت اسکریپت‌نویسی

4. **[LLDB](https://lldb.llvm.org)**
- بخشی از پروژه LLVM
- یکپارچه با Xcode برای توسعه‌دهندگان Apple

## ابزارهای تحلیل دینامیک

این ابزارها برای بررسی رفتار برنامه در حین اجرا استفاده می‌شوند.

1. **[🌟frida](https://frida.re)**
- فریم‌ورک تزریق کد دینامیک
- قابلیت هوک کردن توابع و دستکاری رفتار برنامه

2. **[DynamoRIO](https://dynamorio.org)**
- فریم‌ورک دستکاری باینری در زمان اجرا
- مناسب برای ابزارسازی و تحلیل کد


## ابزارهای تحلیل استاتیک و سیمبولیک

این ابزارها برای تحلیل کد بدون اجرای آن و یا با استفاده از تکنیک‌های تحلیل سیمبولیک استفاده می‌شوند.

1. **[🌟Z3](https://github.com/Z3Prover/z3)**
- حل‌کننده محدودیت و اثبات‌کننده قضیه از Microsoft Research
- کاربرد در حل چالش‌های CTF و تحلیل برنامه

2. **[🌟angr](https://angr.io)**
- فریم‌ورک تحلیل باینری با قابلیت‌های تحلیل سیمبولیک
- مناسب برای تحلیل‌های پیچیده امنیتی و CTF

3. **[🌟Radare2](https://rada.re/n/radare2.html)**
- مجموعه ابزار متن‌باز برای مهندسی معکوس
- شامل دیس‌اسمبلر، دیباگر و تحلیلگر

4. **[🌟JADX](https://github.com/skylot/jadx)**
- دیکامپایلر برای فایل‌های APK و DEX اندروید
- تولید کد Java از باینری‌های اندروید


## پلتفرم‌های آنلاین

1. **[🌟dogbolt](https://dogbolt.org)**
- ابزار آنلاین برای مقایسه خروجی دیکامپایلرهای مختلف
- مفید برای یادگیری و مقایسه عملکرد دیکامپایلرها

2. **[ANY.RUN](https://app.any.run)**
- سندباکس آنلاین برای تحلیل دینامیک بدافزار
- ارائه گزارش‌های تعاملی و ویدیویی از رفتار نمونه


---

!!! نویسنده
[تیم فلگ موتوری](https://github.com/flagmotori)

Loading

0 comments on commit 72f4316

Please sign in to comment.